def writeSets(outfile, list_of_sets, labels=None):
    '''output a list of sets as a tab-separated file.

    This method build a list of all items contained across all sets
    and outputs a matrix of 0's and 1's denoting set membership. The
    items are in the table rows and the sets are in the table columns.

    Arguments
    ---------
    outfile : File
        File to write to
    list_of_sets : list
        The list of sets to output
    labels : list
        List of labels(column names)

    '''

    all_ids = list_of_sets[0].union(*list_of_sets[1:])
    if not labels:
        labels = range(len(list_of_sets))

    outfile.write("id\t%s\n" % "\t".join(map(str, labels)))

    for i in sorted(list(all_ids)):
        outfile.write("%s\t%s\n" % (
            i,
            "\t".join(map(str, [[0, 1][i in x] for x in list_of_sets]))))
dataset/ETHPy150Open CGATOxford/cgat/CGAT/SetTools.py/writeSets/original