nodes: 0, module; 1, function_definition; 2, function_name:sortmerna_ref_cluster; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, expression_statement; 17, comment:# Instantiate the object; 18, expression_statement; 19, comment:# Set input query sequences path; 20, if_statement; 21, comment:# Set the input reference sequence + indexed database path; 22, if_statement; 23, if_statement; 24, comment:# Set output results path (for Blast alignments, clusters and failures); 25, expression_statement; 26, if_statement; 27, comment:# Set E-value threshold; 28, if_statement; 29, comment:# Set similarity threshold; 30, if_statement; 31, comment:# Set query coverage threshold; 32, if_statement; 33, comment:# Set number of best alignments to output; 34, if_statement; 35, comment:# Set Blast tabular output; 36, comment:# The option --blast 3 represents an; 37, comment:# m8 blast tabular output + two extra; 38, comment:# columns containing the CIGAR string; 39, comment:# and the query coverage; 40, if_statement; 41, comment:# Set number of threads; 42, if_statement; 43, comment:# Run sortmerna; 44, expression_statement; 45, comment:# Put clusters into a map of lists; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, comment:# Put failures into a list; 50, expression_statement; 51, expression_statement; 52, comment:# remove the aligned FASTA file and failures FASTA file; 53, comment:# (currently these are re-constructed using pick_rep_set.py; 54, comment:# further in the OTU-picking pipeline); 55, expression_statement; 56, return_statement; 57, identifier:seq_path; 58, None; 59, identifier:sortmerna_db; 60, None; 61, identifier:refseqs_fp; 62, None; 63, identifier:result_path; 64, None; 65, identifier:tabular; 66, False; 67, identifier:max_e_value; 68, integer:1; 69, identifier:similarity; 70, float:0.97; 71, identifier:coverage; 72, float:0.97; 73, identifier:threads; 74, integer:1; 75, identifier:best; 76, integer:1; 77, identifier:HALT_EXEC; 78, False; 79, comment:"""Launch sortmerna OTU picker
  
          Parameters
          ----------
          seq_path : str
              filepath to query sequences.
          sortmerna_db : str
              indexed reference database.
          refseqs_fp : str
              filepath of reference sequences.
          result_path : str
              filepath to output OTU map.
          max_e_value : float, optional
              E-value threshold [default: 1].
          similarity : float, optional
              similarity %id threshold [default: 0.97].
          coverage : float, optional
              query coverage % threshold [default: 0.97].
          threads : int, optional
              number of threads to use (OpenMP) [default: 1].
          tabular : bool, optional
              output BLAST tabular alignments [default: False].
          best : int, optional
              number of best alignments to output per read
              [default: 1].
  
          Returns
          -------
          clusters : dict of lists
              OTU ids and reads mapping to them
  
          failures : list
              reads which did not align
      """; 80, assignment; 81, comparison_operator:seq_path is not None; 82, block; 83, else_clause; 84, comparison_operator:sortmerna_db is not None; 85, block; 86, else_clause; 87, comparison_operator:result_path is None; 88, block; 89, assignment; 90, comparison_operator:output_dir is not None; 91, block; 92, comparison_operator:max_e_value is not None; 93, block; 94, comparison_operator:similarity is not None; 95, block; 96, comparison_operator:coverage is not None; 97, block; 98, comparison_operator:best is not None; 99, block; 100, identifier:tabular; 101, block; 102, comparison_operator:threads is not None; 103, block; 104, assignment; 105, assignment; 106, assignment; 107, assignment; 108, assignment; 109, assignment; 110, assignment; 111, expression_list; 112, identifier:smr; 113, call; 114, identifier:seq_path; 115, None; 116, expression_statement; 117, block; 118, identifier:sortmerna_db; 119, None; 120, expression_statement; 121, block; 122, identifier:result_path; 123, None; 124, raise_statement; 125, identifier:output_dir; 126, call; 127, identifier:output_dir; 128, None; 129, expression_statement; 130, expression_statement; 131, identifier:max_e_value; 132, None; 133, expression_statement; 134, identifier:similarity; 135, None; 136, expression_statement; 137, identifier:coverage; 138, None; 139, expression_statement; 140, identifier:best; 141, None; 142, expression_statement; 143, expression_statement; 144, identifier:threads; 145, None; 146, expression_statement; 147, identifier:app_result; 148, call; 149, identifier:f_otumap; 150, subscript; 151, identifier:rows; 152, generator_expression; 153, identifier:clusters; 154, dictionary_comprehension; 155, identifier:f_failure; 156, subscript; 157, identifier:failures; 158, list_comprehension; 159, identifier:smr_files_to_remove; 160, list; 161, identifier:clusters; 162, identifier:failures; 163, identifier:smr_files_to_remove; 164, identifier:Sortmerna; 165, argument_list; 166, call; 167, raise_statement; 168, call; 169, raise_statement; 170, call; 171, identifier:dirname; 172, argument_list; 173, assignment; 174, call; 175, call; 176, call; 177, call; 178, call; 179, call; 180, call; 181, identifier:smr; 182, argument_list; 183, identifier:app_result; 184, string; 185, call; 186, for_in_clause; 187, pair; 188, for_in_clause; 189, identifier:app_result; 190, string; 191, subscript; 192, for_in_clause; 193, attribute; 194, attribute; 195, attribute; 196, keyword_argument; 197, attribute; 198, argument_list; 199, call; 200, attribute; 201, argument_list; 202, call; 203, identifier:ValueError; 204, argument_list; 205, identifier:result_path; 206, identifier:output_file; 207, call; 208, attribute; 209, argument_list; 210, attribute; 211, argument_list; 212, attribute; 213, argument_list; 214, attribute; 215, argument_list; 216, attribute; 217, argument_list; 218, attribute; 219, argument_list; 220, attribute; 221, argument_list; 222, string_content:OtuMap; 223, attribute; 224, argument_list; 225, identifier:line; 226, identifier:f_otumap; 227, subscript; 228, subscript; 229, identifier:r; 230, identifier:rows; 231, string_content:FastaForDenovo; 232, call; 233, integer:0; 234, pattern_list; 235, call; 236, subscript; 237, identifier:name; 238, subscript; 239, identifier:name; 240, subscript; 241, identifier:name; 242, identifier:HALT_EXEC; 243, identifier:HALT_EXEC; 244, subscript; 245, identifier:on; 246, identifier:seq_path; 247, identifier:ValueError; 248, argument_list; 249, subscript; 250, identifier:on; 251, binary_operator:"%s,%s" % (refseqs_fp, sortmerna_db); 252, identifier:ValueError; 253, argument_list; 254, string:"Error: the result path must be set."; 255, identifier:join; 256, argument_list; 257, subscript; 258, identifier:on; 259, identifier:output_file; 260, subscript; 261, identifier:on; 262, identifier:max_e_value; 263, subscript; 264, identifier:on; 265, identifier:similarity; 266, subscript; 267, identifier:on; 268, identifier:coverage; 269, subscript; 270, identifier:on; 271, identifier:best; 272, subscript; 273, identifier:on; 274, string:"3"; 275, subscript; 276, identifier:on; 277, identifier:threads; 278, call; 279, identifier:split; 280, string; 281, identifier:r; 282, integer:0; 283, identifier:r; 284, slice; 285, attribute; 286, argument_list; 287, identifier:label; 288, identifier:seq; 289, identifier:parse_fasta; 290, argument_list; 291, identifier:app_result; 292, string; 293, identifier:app_result; 294, string; 295, identifier:app_result; 296, string; 297, attribute; 298, string; 299, string:"Error: a read file is mandatory input."; 300, attribute; 301, string; 302, string:"%s,%s"; 303, tuple; 304, binary_operator:"Error: an indexed database for reference set %s must"
                           " already exist.\nUse indexdb_rna to index the"
                           " database." % refseqs_fp; 305, identifier:output_dir; 306, string:"sortmerna_otus"; 307, attribute; 308, string; 309, attribute; 310, string; 311, attribute; 312, string; 313, attribute; 314, string; 315, attribute; 316, string; 317, attribute; 318, string; 319, attribute; 320, string; 321, attribute; 322, argument_list; 323, string_content; 324, integer:1; 325, identifier:re; 326, identifier:split; 327, string; 328, identifier:label; 329, identifier:f_failure; 330, string_content:FastaForDenovo; 331, string_content:FastaMatches; 332, string_content:OtuMap; 333, identifier:smr; 334, identifier:Parameters; 335, string_content:--reads; 336, identifier:smr; 337, identifier:Parameters; 338, string_content:--ref; 339, identifier:refseqs_fp; 340, identifier:sortmerna_db; 341, concatenated_string; 342, identifier:refseqs_fp; 343, identifier:smr; 344, identifier:Parameters; 345, string_content:--aligned; 346, identifier:smr; 347, identifier:Parameters; 348, string_content:-e; 349, identifier:smr; 350, identifier:Parameters; 351, string_content:--id; 352, identifier:smr; 353, identifier:Parameters; 354, string_content:--coverage; 355, identifier:smr; 356, identifier:Parameters; 357, string_content:--best; 358, identifier:smr; 359, identifier:Parameters; 360, string_content:--blast; 361, identifier:smr; 362, identifier:Parameters; 363, string_content:-a; 364, identifier:line; 365, identifier:strip; 366, escape_sequence:\t; 367, string_content:>|; 368, string:"Error: an indexed database for reference set %s must"; 369, string:" already exist.\nUse indexdb_rna to index the"; 370, string:" database."
code: def sortmerna_ref_cluster(seq_path=None,
                            sortmerna_db=None,
                            refseqs_fp=None,
                            result_path=None,
                            tabular=False,
                            max_e_value=1,
                            similarity=0.97,
                            coverage=0.97,
                            threads=1,
                            best=1,
                            HALT_EXEC=False
                            ):
      """Launch sortmerna OTU picker
  
          Parameters
          ----------
          seq_path : str
              filepath to query sequences.
          sortmerna_db : str
              indexed reference database.
          refseqs_fp : str
              filepath of reference sequences.
          result_path : str
              filepath to output OTU map.
          max_e_value : float, optional
              E-value threshold [default: 1].
          similarity : float, optional
              similarity %id threshold [default: 0.97].
          coverage : float, optional
              query coverage % threshold [default: 0.97].
          threads : int, optional
              number of threads to use (OpenMP) [default: 1].
          tabular : bool, optional
              output BLAST tabular alignments [default: False].
          best : int, optional
              number of best alignments to output per read
              [default: 1].
  
          Returns
          -------
          clusters : dict of lists
              OTU ids and reads mapping to them
  
          failures : list
              reads which did not align
      """
  
      # Instantiate the object
      smr = Sortmerna(HALT_EXEC=HALT_EXEC)
  
      # Set input query sequences path
      if seq_path is not None:
          smr.Parameters['--reads'].on(seq_path)
      else:
          raise ValueError("Error: a read file is mandatory input.")
  
      # Set the input reference sequence + indexed database path
      if sortmerna_db is not None:
          smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db))
      else:
          raise ValueError("Error: an indexed database for reference set %s must"
                           " already exist.\nUse indexdb_rna to index the"
                           " database." % refseqs_fp)
  
      if result_path is None:
          raise ValueError("Error: the result path must be set.")
  
      # Set output results path (for Blast alignments, clusters and failures)
      output_dir = dirname(result_path)
      if output_dir is not None:
          output_file = join(output_dir, "sortmerna_otus")
          smr.Parameters['--aligned'].on(output_file)
  
      # Set E-value threshold
      if max_e_value is not None:
          smr.Parameters['-e'].on(max_e_value)
  
      # Set similarity threshold
      if similarity is not None:
          smr.Parameters['--id'].on(similarity)
  
      # Set query coverage threshold
      if coverage is not None:
          smr.Parameters['--coverage'].on(coverage)
  
      # Set number of best alignments to output
      if best is not None:
          smr.Parameters['--best'].on(best)
  
      # Set Blast tabular output
      # The option --blast 3 represents an
      # m8 blast tabular output + two extra
      # columns containing the CIGAR string
      # and the query coverage
      if tabular:
          smr.Parameters['--blast'].on("3")
  
      # Set number of threads
      if threads is not None:
          smr.Parameters['-a'].on(threads)
  
      # Run sortmerna
      app_result = smr()
  
      # Put clusters into a map of lists
      f_otumap = app_result['OtuMap']
      rows = (line.strip().split('\t') for line in f_otumap)
      clusters = {r[0]: r[1:] for r in rows}
  
      # Put failures into a list
      f_failure = app_result['FastaForDenovo']
      failures = [re.split('>| ', label)[0]
                  for label, seq in parse_fasta(f_failure)]
  
      # remove the aligned FASTA file and failures FASTA file
      # (currently these are re-constructed using pick_rep_set.py
      # further in the OTU-picking pipeline)
      smr_files_to_remove = [app_result['FastaForDenovo'].name,
                             app_result['FastaMatches'].name,
                             app_result['OtuMap'].name]
  
      return clusters, failures, smr_files_to_remove