def flat_gene_iterator(gff_iterator, strict=True):

    last = Entry()
    matches = []
    found = set()
    for gff in gff_iterator:

        if last.gene_id != gff.gene_id or last.contig != gff.contig:
            if matches:
                yield matches
            matches = []
            last = gff
            if strict:
                assert last.gene_id not in found, \
                    "duplicate entry %s" % last.gene_id
                found.add(last.gene_id)
        matches.append(gff)

    if matches:
        yield matches
iterate over the contents of a gtf file.
dataset/ETHPy150Open CGATOxford/cgat/CGAT/GTF.py/flat_gene_iterator