def outputSpikes(df, id_column, indices, tracks_map, groups,
                 method, spike_type,
                 min_cbin, width_cbin, min_ibin, width_ibin,
                 min_sbin, width_sbin):

    def printHeader(keep_columns, groups):
        header = keep_columns
        header.extend(tracks_map[groups[0]])
        header.extend(tracks_map[groups[1]])
        sys.stdout.write("\t".join(map(str, header)) % "%s\n")
        return header

    if spike_type == "row":
        keep_cols = printHeader([id_column], groups)
    elif spike_type == "cluster":
        keep_cols = printHeader(["contig", "position"], groups)

    if method == "append":
        df = df.ix[:, keep_cols]
        df.to_csv(sys.stdout, index=False, header=False, sep="\t",
                  dtype={'position': int})

    def getInitialChangeSize(key, width_ibin, min_ibin, width_cbin, min_cbin,
                             width_s_bin, min_s_bin):
        initial_bin, change_bin, size_bin = key
        # initial and change values are the center of the bin
        initial = ((initial_bin*width_ibin) + min_ibin - (width_ibin*0.5))
        change = ((change_bin*width_cbin) + min_cbin - (width_cbin*0.5))
        size = ((size_bin*width_sbin) + min_sbin - 1)
        return initial, change, size

    def getInitialChange(key, width_ibin, min_ibin, width_cbin, min_cbin):
        initial_bin, change_bin = key
        # initial and change values are the center of the bin
        initial = ((initial_bin*width_ibin) + min_ibin - (width_ibin*0.5))
        change = ((change_bin*width_cbin) + min_cbin - (width_cbin*0.5))
        return initial, change

    n = 0
    if spike_type == "row":
        for key in indices:
            for pair in indices[key]:
                initial, change = getInitialChange(key, width_ibin, min_ibin,
                                                   width_cbin, min_cbin)
                row = ["_".join(map(str,
                                    ("spike-in", initial, change, n)))]
                row.extend(df.ix[pair[0], tracks_map[groups[0]]])
                row.extend(df.ix[pair[1], tracks_map[groups[1]]])
                sys.stdout.write("%s\n" % "\t".join(map(str, row)))
                n += 1

    elif spike_type == "cluster":
        for key in indices.keys():
            initial, change, size = getInitialChangeSize(
                key, width_ibin, min_ibin, width_cbin,
                min_cbin, width_sbin, min_sbin)
            for values in indices[key]:
                (c1s, c1e, c2s, c2e, c1rs, c1re,
                 c2rs, c2re) = values
                cluster_id = "_".join(map(str, ("spike-in", initial,
                                                change, size, c1rs-c1s, n)))
                temp_cluster_df = df.ix[c1s:c1e, keep_cols]
                temp_cluster_df['contig'] = cluster_id
                temp_cluster_swap = df.ix[c2rs:c2re, tracks_map[groups[1]]]
                temp_cluster_swap.set_index(df.ix[c1rs:c1re].index,
                                            drop=True,  inplace=True)
                temp_cluster_df.ix[c1rs:c1re, tracks_map[
                    groups[1]]] = temp_cluster_swap
                temp_cluster_df.to_csv(sys.stdout, index=False,
                                       header=False, sep="\t",
                                       dtype={'position': int})
                n += 1
dataset/ETHPy150Open CGATOxford/cgat/scripts/data2spike.py/outputSpikes/swapped operands of `%`