nodes: 0, module; 1, function_definition; 2, function_name:build_database_sortmerna; 3, parameters; 4, block; 5, identifier:fasta_path; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, comment:# Instantiate the object; 17, expression_statement; 18, comment:# The parameter --ref STRING must follow the format where; 19, comment:# STRING = /path/to/ref.fasta,/path/to/ref.idx; 20, expression_statement; 21, comment:# Set temporary directory; 22, expression_statement; 23, comment:# Override --max_pos parameter; 24, if_statement; 25, comment:# Run indexdb_rna; 26, expression_statement; 27, comment:# Return all output files (by indexdb_rna) as a list,; 28, comment:# first however remove the StdErr and StdOut filepaths; 29, comment:# as they files will be destroyed at the exit from; 30, comment:# this function (IndexDB is a local instance); 31, expression_statement; 32, return_statement; 33, identifier:max_pos; 34, None; 35, identifier:output_dir; 36, None; 37, identifier:temp_dir; 38, call; 39, identifier:HALT_EXEC; 40, False; 41, comment:""" Build sortmerna db from fasta_path; return db name
          and list of files created
  
          Parameters
          ----------
          fasta_path : string
              path to fasta file of sequences to build database.
          max_pos : integer, optional
              maximum positions to store per seed in index
              [default: 10000].
          output_dir : string, optional
              directory where output should be written
              [default: same directory as fasta_path]
          HALT_EXEC : boolean, optional
              halt just before running the indexdb_rna command
              and print the command -- useful for debugging
              [default: False].
  
          Return
          ------
          db_name : string
              filepath to indexed database.
          db_filepaths : list
              output files by indexdb_rna
      """; 42, comparison_operator:fasta_path is None; 43, block; 44, assignment; 45, not_operator; 46, block; 47, assignment; 48, assignment; 49, assignment; 50, call; 51, call; 52, comparison_operator:max_pos is not None; 53, block; 54, assignment; 55, assignment; 56, expression_list; 57, attribute; 58, argument_list; 59, identifier:fasta_path; 60, None; 61, raise_statement; 62, pattern_list; 63, call; 64, identifier:output_dir; 65, expression_statement; 66, comment:# Will cd to this directory, so just pass the filename; 67, comment:# so the app is not confused by relative paths; 68, expression_statement; 69, identifier:index_basename; 70, subscript; 71, identifier:db_name; 72, call; 73, identifier:sdb; 74, call; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, identifier:max_pos; 80, None; 81, expression_statement; 82, identifier:app_result; 83, call; 84, identifier:db_filepaths; 85, list_comprehension; 86, identifier:db_name; 87, identifier:db_filepaths; 88, identifier:tempfile; 89, identifier:gettempdir; 90, call; 91, identifier:fasta_dir; 92, identifier:fasta_filename; 93, identifier:split; 94, argument_list; 95, assignment; 96, assignment; 97, call; 98, integer:0; 99, identifier:join; 100, argument_list; 101, identifier:IndexDB; 102, argument_list; 103, subscript; 104, identifier:on; 105, binary_operator:"%s,%s" % (fasta_path, db_name); 106, subscript; 107, identifier:on; 108, identifier:temp_dir; 109, call; 110, identifier:sdb; 111, argument_list; 112, attribute; 113, for_in_clause; 114, if_clause; 115, identifier:ValueError; 116, argument_list; 117, identifier:fasta_path; 118, identifier:output_dir; 119, boolean_operator; 120, identifier:fasta_path; 121, identifier:fasta_filename; 122, identifier:splitext; 123, argument_list; 124, identifier:output_dir; 125, identifier:index_basename; 126, keyword_argument; 127, keyword_argument; 128, attribute; 129, string; 130, string:"%s,%s"; 131, tuple; 132, attribute; 133, string; 134, attribute; 135, argument_list; 136, identifier:v; 137, identifier:name; 138, pattern_list; 139, call; 140, boolean_operator; 141, concatenated_string; 142, identifier:fasta_dir; 143, string; 144, identifier:fasta_filename; 145, identifier:WorkingDir; 146, identifier:output_dir; 147, identifier:HALT_EXEC; 148, identifier:HALT_EXEC; 149, identifier:sdb; 150, identifier:Parameters; 151, string_content:--ref; 152, identifier:fasta_path; 153, identifier:db_name; 154, identifier:sdb; 155, identifier:Parameters; 156, string_content:--tmpdir; 157, subscript; 158, identifier:on; 159, identifier:max_pos; 160, identifier:k; 161, identifier:v; 162, attribute; 163, argument_list; 164, comparison_operator:k not in {'StdErr', 'StdOut'}; 165, call; 166, string:"Error: path to fasta reference "; 167, string:"sequences must exist."; 168, string_content:.; 169, attribute; 170, string; 171, identifier:app_result; 172, identifier:items; 173, identifier:k; 174, set; 175, identifier:hasattr; 176, argument_list; 177, identifier:sdb; 178, identifier:Parameters; 179, string_content:--max_pos; 180, string; 181, string; 182, identifier:v; 183, string; 184, string_content:StdErr; 185, string_content:StdOut; 186, string_content:name
code: def build_database_sortmerna(fasta_path,
                               max_pos=None,
                               output_dir=None,
                               temp_dir=tempfile.gettempdir(),
                               HALT_EXEC=False):
      """ Build sortmerna db from fasta_path; return db name
          and list of files created
  
          Parameters
          ----------
          fasta_path : string
              path to fasta file of sequences to build database.
          max_pos : integer, optional
              maximum positions to store per seed in index
              [default: 10000].
          output_dir : string, optional
              directory where output should be written
              [default: same directory as fasta_path]
          HALT_EXEC : boolean, optional
              halt just before running the indexdb_rna command
              and print the command -- useful for debugging
              [default: False].
  
          Return
          ------
          db_name : string
              filepath to indexed database.
          db_filepaths : list
              output files by indexdb_rna
      """
  
      if fasta_path is None:
          raise ValueError("Error: path to fasta reference "
                           "sequences must exist.")
  
      fasta_dir, fasta_filename = split(fasta_path)
      if not output_dir:
          output_dir = fasta_dir or '.'
          # Will cd to this directory, so just pass the filename
          # so the app is not confused by relative paths
          fasta_path = fasta_filename
  
      index_basename = splitext(fasta_filename)[0]
  
      db_name = join(output_dir, index_basename)
  
      # Instantiate the object
      sdb = IndexDB(WorkingDir=output_dir, HALT_EXEC=HALT_EXEC)
  
      # The parameter --ref STRING must follow the format where
      # STRING = /path/to/ref.fasta,/path/to/ref.idx
      sdb.Parameters['--ref'].on("%s,%s" % (fasta_path, db_name))
  
      # Set temporary directory
      sdb.Parameters['--tmpdir'].on(temp_dir)
  
      # Override --max_pos parameter
      if max_pos is not None:
          sdb.Parameters['--max_pos'].on(max_pos)
  
      # Run indexdb_rna
      app_result = sdb()
  
      # Return all output files (by indexdb_rna) as a list,
      # first however remove the StdErr and StdOut filepaths
      # as they files will be destroyed at the exit from
      # this function (IndexDB is a local instance)
      db_filepaths = [v.name for k, v in app_result.items()
                      if k not in {'StdErr', 'StdOut'} and hasattr(v, 'name')]
  
      return db_name, db_filepaths