nodes: 0, module; 1, function_definition; 2, function_name:numBlast_sort; 3, parameters; 4, block; 5, identifier:blast; 6, identifier:numHits; 7, identifier:evalueT; 8, identifier:bitT; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, for_statement; 16, comment:"""
      parse b6 output with sorting
      """; 17, assignment; 18, yield; 19, assignment; 20, identifier:line; 21, identifier:blast; 22, block; 23, assignment; 24, pattern_list; 25, call; 26, block; 27, identifier:header; 28, list; 29, identifier:header; 30, identifier:hmm; 31, dictionary_comprehension; 32, if_statement; 33, expression_statement; 34, comment:# Evalue and Bitscore thresholds; 35, expression_statement; 36, expression_statement; 37, if_statement; 38, if_statement; 39, for_statement; 40, identifier:hmm; 41, call; 42, identifier:query; 43, identifier:df; 44, attribute; 45, argument_list; 46, expression_statement; 47, for_statement; 48, string; 49, string; 50, string; 51, string; 52, string; 53, string; 54, string; 55, string; 56, string; 57, string; 58, string; 59, string; 60, pair; 61, for_in_clause; 62, call; 63, block; 64, assignment; 65, assignment; 66, assignment; 67, boolean_operator; 68, block; 69, boolean_operator; 70, block; 71, pattern_list; 72, call; 73, block; 74, attribute; 75, argument_list; 76, identifier:hmm; 77, identifier:groupby; 78, keyword_argument; 79, assignment; 80, identifier:hit; 81, subscript; 82, block; 83, string_content:#query; 84, string_content:target; 85, string_content:pident; 86, string_content:alen; 87, string_content:mismatch; 88, string_content:gapopen; 89, string_content:qstart; 90, string_content:qend; 91, string_content:tstart; 92, string_content:tend; 93, string_content:evalue; 94, string_content:bitscore; 95, identifier:h; 96, list; 97, identifier:h; 98, identifier:header; 99, attribute; 100, argument_list; 101, continue_statement; 102, identifier:line; 103, call; 104, pattern_list; 105, expression_list; 106, pattern_list; 107, expression_list; 108, comparison_operator:evalueT is not False; 109, comparison_operator:evalue > evalueT; 110, continue_statement; 111, comparison_operator:bitT is not False; 112, comparison_operator:bit < bitT; 113, continue_statement; 114, identifier:i; 115, identifier:h; 116, identifier:zip; 117, argument_list; 118, expression_statement; 119, identifier:pd; 120, identifier:DataFrame; 121, identifier:hmm; 122, identifier:by; 123, list; 124, identifier:df; 125, call; 126, attribute; 127, slice; 128, expression_statement; 129, identifier:line; 130, identifier:startswith; 131, string; 132, attribute; 133, argument_list; 134, subscript; 135, subscript; 136, call; 137, call; 138, identifier:evalue; 139, identifier:bit; 140, subscript; 141, subscript; 142, identifier:evalueT; 143, False; 144, identifier:evalue; 145, identifier:evalueT; 146, identifier:bitT; 147, False; 148, identifier:bit; 149, identifier:bitT; 150, identifier:line; 151, identifier:header; 152, call; 153, string; 154, attribute; 155, argument_list; 156, subscript; 157, identifier:values; 158, integer:0; 159, identifier:numHits; 160, yield; 161, string_content:#; 162, call; 163, identifier:split; 164, string; 165, identifier:line; 166, integer:10; 167, identifier:line; 168, integer:11; 169, identifier:float; 170, argument_list; 171, identifier:float; 172, argument_list; 173, identifier:line; 174, integer:10; 175, identifier:line; 176, integer:11; 177, attribute; 178, argument_list; 179, string_content:#query; 180, identifier:df; 181, identifier:sort_values; 182, keyword_argument; 183, keyword_argument; 184, identifier:df; 185, identifier:header; 186, identifier:hit; 187, attribute; 188, argument_list; 189, string_content; 190, subscript; 191, subscript; 192, subscript; 193, identifier:append; 194, identifier:i; 195, identifier:by; 196, list; 197, identifier:ascending; 198, False; 199, identifier:line; 200, identifier:strip; 201, escape_sequence:\t; 202, identifier:line; 203, integer:10; 204, identifier:line; 205, integer:11; 206, identifier:hmm; 207, identifier:h; 208, string; 209, string_content:bitscore
code: def numBlast_sort(blast, numHits, evalueT, bitT):
      """
      parse b6 output with sorting
      """
      header = ['#query', 'target', 'pident', 'alen', 'mismatch', 'gapopen',
                'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore']
      yield header
      hmm = {h:[] for h in header}
      for line in blast:
          if line.startswith('#'):
              continue
          line = line.strip().split('\t')
          # Evalue and Bitscore thresholds
          line[10], line[11] = float(line[10]), float(line[11])
          evalue, bit = line[10], line[11]
          if evalueT is not False and evalue > evalueT:
              continue
          if bitT is not False and bit < bitT:
              continue
          for i, h in zip(line, header):
              hmm[h].append(i)
      hmm = pd.DataFrame(hmm)
      for query, df in hmm.groupby(by = ['#query']):
          df = df.sort_values(by = ['bitscore'], ascending = False)
          for hit in df[header].values[0:numHits]:
              yield hit