def iterate_locus(infile):
    '''parse .loci output file from cuffcompare

    returns iterator with list of loci.
    '''

    for line in infile:
        data = line[:-1].split("\t")
        locus_id, pos = data[:2]

        contig, strand, start, end = re.match(
            "(\S+)\[(\S*)\](\d+)-(\d+)", pos).groups()
        start, end = map(int, (start, end))

        # some [] contains the 0 byte, convert to empty field
        if strand not in "+-":
            strand = ""
        transcripts = []
        for c in data[2:]:
            if c == "-":
                transcripts.append(())
            else:
                transcripts.append(c.split(","))

        yield Locus._make((locus_id, contig, strand, start, end, transcripts[1], transcripts[1:]))
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Tophat.py/iterate_locus/original