def chrom_iterator(gff3_iterator):

    seen = set()

    for chrom_set in itertools.groupby(gff3_iterator, lambda x: x.contig):

        if chrom_set[0] in seen:
            raise ValueError("File doesn't appear to be chromosome sorted")

        seen.add(chrom_set[0])

        yield chrom_set[1]
takes a an iterator and returns an iterator over iterators,
dataset/ETHPy150Open CGATOxford/cgat/CGAT/GFF3.py/chrom_iterator