#NEWLINE# def best_alignment_iterator( query_iterator ) : #NEWLINE# #INDENT# '\n    return stats for best alignment - best is determined\n    by highest bit score. If there are multiple alignments\n    with the same score return a random one\n    ' #NEWLINE# for alignments in query_iterator : #NEWLINE# #INDENT# scores = [ ] #NEWLINE# for alignment in alignments : #NEWLINE# #INDENT# scores . append ( alignment . score ) #NEWLINE# #UNINDENT# best = max ( scores ) #NEWLINE# best_alignments = [ x for x in alignments if ( best_alignment . score == best ) ] #NEWLINE# if ( len ( best_alignments ) > 1 ) : #NEWLINE# #INDENT# best_alignments = random . sample ( best_alignments , 1 ) #NEWLINE# #UNINDENT# best_alignment = best_alignments [ 0 ] #NEWLINE# ( yield best_alignment )