#NEWLINE# def chrom_iterator( gff3_iterator ) : #NEWLINE# #INDENT# ' takes a an iterator and returns an iterator over iterators,\n    with a new instance every time a new chromosome is found ' #NEWLINE# seen = set ( ) #NEWLINE# for chrom_set in itertools . groupby ( chrom_set , ( lambda x : x . contig ) ) : #NEWLINE# #INDENT# if ( chrom_set [ 0 ] in seen ) : #NEWLINE# #INDENT# raise ValueError ( "File doesn't appear to be chromosome sorted" ) #NEWLINE# #UNINDENT# seen . add ( chrom_set [ 0 ] ) #NEWLINE# ( yield chrom_set [ 1 ] )