#NEWLINE# def gene_iterator( gff_iterator , strict = True ) : #NEWLINE# #INDENT# 'iterate over the contents of a gtf file.\n\n    return a list of transcripts with the same gene id.\n\n    Note: the entries have to be consecutive in the file, i.e,\n    first sorted by transcript and then by gene id.\n\n    Genes with the same name on different contigs are resolved\n    separately in *strict* = False.\n    ' #NEWLINE# last = Entry ( ) #NEWLINE# matches = [ ] #NEWLINE# found = set ( ) #NEWLINE# for gffs in transcript_iterator ( gff_iterator , strict ) : #NEWLINE# #INDENT# if ( ( last . gene_id != gffs [ 0 ] . gene_id ) or ( last . contig != gffs [ 0 ] . contig ) ) : #NEWLINE# #INDENT# if matches : #NEWLINE# #INDENT# ( yield matches ) #NEWLINE# #UNINDENT# matches = [ ] #NEWLINE# last = gffs [ 0 ] #NEWLINE# assert ( ( not strict ) or ( last . gene_id not in found ) ) , ( 'duplicate entry %s' % last ) #NEWLINE# found . add ( last . gene_id ) #NEWLINE# #UNINDENT# matches . append ( gffs ) #NEWLINE# #UNINDENT# if matches : #NEWLINE# #INDENT# ( yield matches )