#NEWLINE# def joined_iterator( gff_iterator , group_field = None ) : #NEWLINE# #INDENT# 'iterate over the contents of a gff file.\n\n    return a list of entries with the same group id.\n    Note: the entries have to be consecutive in\n    the file.\n    ' #NEWLINE# last_group_id = None #NEWLINE# matches = [ ] #NEWLINE# if ( group_field is None ) : #NEWLINE# #INDENT# group_function = ( lambda x : x . attributes ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( group_field == 'gene_id' ) : #NEWLINE# #INDENT# group_function = ( lambda x : x . gene_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( group_field == 'transcript_id' ) : #NEWLINE# #INDENT# group_function = ( lambda x : x . transcript_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# group_function = ( lambda x : x [ group_field ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for gff in gff_iterator : #NEWLINE# #INDENT# group_id = group_function ( gff ) #NEWLINE# if ( last_group_id != group_id ) : #NEWLINE# #INDENT# if last_group_id : #NEWLINE# #INDENT# ( yield matches ) #NEWLINE# #UNINDENT# matches = [ ] #NEWLINE# last_group_id = group_id #NEWLINE# #UNINDENT# matches . append ( gff ) #NEWLINE# #UNINDENT# if last_group_id : #NEWLINE# #INDENT# ( yield matches )