nodes: 0, module; 1, function_definition; 2, function_name:launch_workflow; 3, parameters; 4, block; 5, identifier:seqs_fp; 6, identifier:working_dir; 7, identifier:mean_error; 8, identifier:error_dist; 9, identifier:indel_prob; 10, identifier:indel_max; 11, identifier:trim_length; 12, identifier:left_trim_length; 13, identifier:min_size; 14, identifier:ref_fp; 15, identifier:ref_db_fp; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, comment:# Step 1: Trim sequences to specified length; 24, expression_statement; 25, with_statement; 26, comment:# Step 2: Dereplicate sequences; 27, expression_statement; 28, expression_statement; 29, comment:# Step 3: Remove artifacts; 30, expression_statement; 31, if_statement; 32, comment:# Step 4: Multiple sequence alignment; 33, if_statement; 34, comment:# Step 5: Launch deblur; 35, expression_statement; 36, with_statement; 37, comment:# Step 6: Chimera removal; 38, expression_statement; 39, expression_statement; 40, return_statement; 41, identifier:threads_per_sample; 42, integer:1; 43, identifier:sim_thresh; 44, None; 45, identifier:coverage_thresh; 46, None; 47, comment:"""Launch full deblur workflow for a single post split-libraries fasta file
  
      Parameters
      ----------
      seqs_fp: string
          a post split library fasta file for debluring
      working_dir: string
          working directory path
      mean_error: float
          mean error for original sequence estimate
      error_dist: list
          list of error probabilities for each hamming distance
      indel_prob: float
          insertion/deletion (indel) probability
      indel_max: integer
          maximal indel number
      trim_length: integer
          sequence trim length
      left_trim_length: integer
          trim the first n reads
      min_size: integer
          upper limit on sequence abundance (discard sequences below limit)
      ref_fp: tuple
          filepath(s) to FASTA reference database for artifact removal
      ref_db_fp: tuple
          filepath(s) to SortMeRNA indexed database for artifact removal
      threads_per_sample: integer, optional
          number of threads to use for SortMeRNA/mafft/vsearch
          (0 for max available)
      sim_thresh: float, optional
          the minimal similarity for a sequence to the database.
          if None, take the defaults (0.65 for negate=False,
          0.95 for negate=True)
      coverage_thresh: float, optional
          the minimal coverage for alignment of a sequence to the database.
          if None, take the defaults (0.3 for negate=False, 0.95 for negate=True)
  
      Return
      ------
      output_no_chimers_fp : string
          filepath to fasta file with no chimeras of None if error encountered
      """; 48, assignment; 49, call; 50, call; 51, assignment; 52, with_clause; 53, block; 54, assignment; 55, call; 56, assignment; 57, not_operator; 58, block; 59, comparison_operator:num_seqs_left > 1; 60, block; 61, elif_clause; 62, else_clause; 63, assignment; 64, with_clause; 65, block; 66, assignment; 67, call; 68, identifier:output_no_chimeras_fp; 69, identifier:logger; 70, call; 71, attribute; 72, argument_list; 73, attribute; 74, argument_list; 75, identifier:output_trim_fp; 76, call; 77, with_item; 78, for_statement; 79, identifier:output_derep_fp; 80, call; 81, identifier:dereplicate_seqs; 82, argument_list; 83, pattern_list; 84, call; 85, identifier:output_artif_fp; 86, expression_statement; 87, expression_statement; 88, return_statement; 89, identifier:num_seqs_left; 90, integer:1; 91, expression_statement; 92, expression_statement; 93, if_statement; 94, comparison_operator:num_seqs_left == 1; 95, comment:# only one sequence after remove artifacts (but could be many reads); 96, comment:# no need to run MSA - just use the pre-msa file as input for next step; 97, block; 98, block; 99, identifier:output_deblur_fp; 100, call; 101, with_item; 102, expression_statement; 103, if_statement; 104, for_statement; 105, identifier:output_no_chimeras_fp; 106, call; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, identifier:logger; 112, identifier:info; 113, string; 114, identifier:logger; 115, identifier:info; 116, binary_operator:'launch_workflow for file %s' % seqs_fp; 117, identifier:join; 118, argument_list; 119, as_pattern; 120, pattern_list; 121, call; 122, block; 123, identifier:join; 124, argument_list; 125, keyword_argument; 126, keyword_argument; 127, keyword_argument; 128, keyword_argument; 129, identifier:output_artif_fp; 130, identifier:num_seqs_left; 131, identifier:_; 132, identifier:remove_artifacts_seqs; 133, argument_list; 134, call; 135, call; 136, None; 137, assignment; 138, assignment; 139, not_operator; 140, block; 141, identifier:num_seqs_left; 142, integer:1; 143, expression_statement; 144, expression_statement; 145, expression_statement; 146, expression_statement; 147, return_statement; 148, identifier:join; 149, argument_list; 150, as_pattern; 151, assignment; 152, comparison_operator:seqs is None; 153, block; 154, identifier:s; 155, identifier:seqs; 156, comment:# remove '-' from aligned sequences; 157, block; 158, identifier:remove_chimeras_denovo_from_seqs; 159, argument_list; 160, identifier:logger; 161, identifier:info; 162, string; 163, identifier:logging; 164, identifier:getLogger; 165, identifier:__name__; 166, string_content:--------------------------------------------------------; 167, string; 168, identifier:seqs_fp; 169, identifier:working_dir; 170, binary_operator:"%s.trim" % basename(seqs_fp); 171, call; 172, as_pattern_target; 173, identifier:label; 174, identifier:seq; 175, identifier:trim_seqs; 176, argument_list; 177, expression_statement; 178, identifier:working_dir; 179, binary_operator:"%s.derep" % basename(output_trim_fp); 180, identifier:seqs_fp; 181, identifier:output_trim_fp; 182, identifier:output_fp; 183, identifier:output_derep_fp; 184, identifier:min_size; 185, identifier:min_size; 186, identifier:threads; 187, identifier:threads_per_sample; 188, keyword_argument; 189, keyword_argument; 190, keyword_argument; 191, keyword_argument; 192, keyword_argument; 193, keyword_argument; 194, keyword_argument; 195, attribute; 196, argument_list; 197, attribute; 198, argument_list; 199, identifier:output_msa_fp; 200, call; 201, identifier:alignment; 202, call; 203, identifier:alignment; 204, expression_statement; 205, expression_statement; 206, return_statement; 207, assignment; 208, assignment; 209, call; 210, call; 211, None; 212, identifier:working_dir; 213, binary_operator:"%s.deblur" % basename(output_msa_fp); 214, call; 215, as_pattern_target; 216, identifier:seqs; 217, call; 218, identifier:seqs; 219, None; 220, expression_statement; 221, expression_statement; 222, return_statement; 223, expression_statement; 224, expression_statement; 225, identifier:output_deblur_fp; 226, identifier:working_dir; 227, keyword_argument; 228, string_content:finished processing file; 229, string_content:launch_workflow for file %s; 230, string:"%s.trim"; 231, call; 232, identifier:open; 233, argument_list; 234, identifier:out_f; 235, keyword_argument; 236, keyword_argument; 237, keyword_argument; 238, call; 239, string:"%s.derep"; 240, call; 241, identifier:seqs_fp; 242, identifier:output_derep_fp; 243, identifier:ref_fp; 244, identifier:ref_fp; 245, identifier:working_dir; 246, identifier:working_dir; 247, identifier:ref_db_fp; 248, identifier:ref_db_fp; 249, identifier:negate; 250, True; 251, identifier:threads; 252, identifier:threads_per_sample; 253, identifier:sim_thresh; 254, identifier:sim_thresh; 255, identifier:warnings; 256, identifier:warn; 257, binary_operator:'Problem removing artifacts from file %s' %
                        seqs_fp; 258, identifier:UserWarning; 259, identifier:logger; 260, identifier:warning; 261, string; 262, identifier:join; 263, argument_list; 264, identifier:multiple_sequence_alignment; 265, argument_list; 266, call; 267, call; 268, None; 269, identifier:output_msa_fp; 270, identifier:output_artif_fp; 271, identifier:err_msg; 272, parenthesized_expression; 273, attribute; 274, argument_list; 275, attribute; 276, argument_list; 277, string:"%s.deblur"; 278, call; 279, identifier:open; 280, argument_list; 281, identifier:f; 282, identifier:deblur; 283, argument_list; 284, call; 285, call; 286, None; 287, assignment; 288, call; 289, identifier:threads; 290, identifier:threads_per_sample; 291, identifier:basename; 292, argument_list; 293, identifier:output_trim_fp; 294, string; 295, identifier:input_seqs; 296, call; 297, identifier:trim_len; 298, identifier:trim_length; 299, identifier:left_trim_len; 300, identifier:left_trim_length; 301, attribute; 302, argument_list; 303, identifier:basename; 304, argument_list; 305, string; 306, identifier:seqs_fp; 307, string_content:remove artifacts failed, aborting; 308, identifier:working_dir; 309, binary_operator:"%s.msa" % basename(output_artif_fp); 310, keyword_argument; 311, keyword_argument; 312, attribute; 313, argument_list; 314, attribute; 315, argument_list; 316, binary_operator:'No sequences left after artifact removal in '
                     'file %s' % seqs_fp; 317, identifier:warnings; 318, identifier:warn; 319, identifier:err_msg; 320, identifier:UserWarning; 321, identifier:logger; 322, identifier:warning; 323, identifier:err_msg; 324, identifier:basename; 325, argument_list; 326, identifier:output_deblur_fp; 327, string; 328, call; 329, identifier:mean_error; 330, identifier:error_dist; 331, identifier:indel_prob; 332, identifier:indel_max; 333, attribute; 334, argument_list; 335, attribute; 336, argument_list; 337, attribute; 338, call; 339, attribute; 340, argument_list; 341, identifier:seqs_fp; 342, string_content:w; 343, identifier:sequence_generator; 344, argument_list; 345, identifier:out_f; 346, identifier:write; 347, binary_operator:">%s\n%s\n" % (label, seq); 348, identifier:output_trim_fp; 349, string_content:Problem removing artifacts from file %s; 350, string:"%s.msa"; 351, call; 352, identifier:seqs_fp; 353, identifier:output_artif_fp; 354, identifier:threads; 355, identifier:threads_per_sample; 356, identifier:warnings; 357, identifier:warn; 358, binary_operator:'Problem performing multiple sequence alignment '
                            'on file %s' % seqs_fp; 359, identifier:UserWarning; 360, identifier:logger; 361, identifier:warning; 362, string; 363, concatenated_string; 364, identifier:seqs_fp; 365, identifier:output_msa_fp; 366, string_content:w; 367, identifier:sequence_generator; 368, argument_list; 369, identifier:warnings; 370, identifier:warn; 371, binary_operator:'multiple sequence alignment file %s contains '
                            'no sequences' % output_msa_fp; 372, identifier:UserWarning; 373, identifier:logger; 374, identifier:warn; 375, binary_operator:'no sequences returned from deblur for file %s' %
                          output_msa_fp; 376, identifier:s; 377, identifier:sequence; 378, attribute; 379, argument_list; 380, identifier:f; 381, identifier:write; 382, call; 383, identifier:seqs_fp; 384, string:">%s\n%s\n"; 385, tuple; 386, identifier:basename; 387, argument_list; 388, concatenated_string; 389, identifier:seqs_fp; 390, string_content:msa failed. aborting; 391, string; 392, string; 393, identifier:output_msa_fp; 394, concatenated_string; 395, identifier:output_msa_fp; 396, string; 397, identifier:output_msa_fp; 398, attribute; 399, identifier:replace; 400, string; 401, string; 402, attribute; 403, argument_list; 404, identifier:label; 405, identifier:seq; 406, identifier:output_artif_fp; 407, string; 408, string; 409, string_content:No sequences left after artifact removal in; 410, string_content:file %s; 411, string; 412, string; 413, string_content:no sequences returned from deblur for file %s; 414, identifier:s; 415, identifier:sequence; 416, string_content:-; 417, identifier:s; 418, identifier:to_fasta; 419, string_content:Problem performing multiple sequence alignment; 420, string_content:on file %s; 421, string_content:multiple sequence alignment file %s contains; 422, string_content:no sequences
code: def launch_workflow(seqs_fp, working_dir, mean_error, error_dist,
                      indel_prob, indel_max, trim_length, left_trim_length,
                      min_size, ref_fp, ref_db_fp, threads_per_sample=1,
                      sim_thresh=None, coverage_thresh=None):
      """Launch full deblur workflow for a single post split-libraries fasta file
  
      Parameters
      ----------
      seqs_fp: string
          a post split library fasta file for debluring
      working_dir: string
          working directory path
      mean_error: float
          mean error for original sequence estimate
      error_dist: list
          list of error probabilities for each hamming distance
      indel_prob: float
          insertion/deletion (indel) probability
      indel_max: integer
          maximal indel number
      trim_length: integer
          sequence trim length
      left_trim_length: integer
          trim the first n reads
      min_size: integer
          upper limit on sequence abundance (discard sequences below limit)
      ref_fp: tuple
          filepath(s) to FASTA reference database for artifact removal
      ref_db_fp: tuple
          filepath(s) to SortMeRNA indexed database for artifact removal
      threads_per_sample: integer, optional
          number of threads to use for SortMeRNA/mafft/vsearch
          (0 for max available)
      sim_thresh: float, optional
          the minimal similarity for a sequence to the database.
          if None, take the defaults (0.65 for negate=False,
          0.95 for negate=True)
      coverage_thresh: float, optional
          the minimal coverage for alignment of a sequence to the database.
          if None, take the defaults (0.3 for negate=False, 0.95 for negate=True)
  
      Return
      ------
      output_no_chimers_fp : string
          filepath to fasta file with no chimeras of None if error encountered
      """
      logger = logging.getLogger(__name__)
      logger.info('--------------------------------------------------------')
      logger.info('launch_workflow for file %s' % seqs_fp)
  
      # Step 1: Trim sequences to specified length
      output_trim_fp = join(working_dir, "%s.trim" % basename(seqs_fp))
      with open(output_trim_fp, 'w') as out_f:
          for label, seq in trim_seqs(
                  input_seqs=sequence_generator(seqs_fp),
                  trim_len=trim_length,
                  left_trim_len=left_trim_length):
              out_f.write(">%s\n%s\n" % (label, seq))
      # Step 2: Dereplicate sequences
      output_derep_fp = join(working_dir,
                             "%s.derep" % basename(output_trim_fp))
      dereplicate_seqs(seqs_fp=output_trim_fp,
                       output_fp=output_derep_fp,
                       min_size=min_size, threads=threads_per_sample)
      # Step 3: Remove artifacts
      output_artif_fp, num_seqs_left, _ = remove_artifacts_seqs(seqs_fp=output_derep_fp,
                                                                ref_fp=ref_fp,
                                                                working_dir=working_dir,
                                                                ref_db_fp=ref_db_fp,
                                                                negate=True,
                                                                threads=threads_per_sample,
                                                                sim_thresh=sim_thresh)
      if not output_artif_fp:
          warnings.warn('Problem removing artifacts from file %s' %
                        seqs_fp, UserWarning)
          logger.warning('remove artifacts failed, aborting')
          return None
      # Step 4: Multiple sequence alignment
      if num_seqs_left > 1:
          output_msa_fp = join(working_dir,
                               "%s.msa" % basename(output_artif_fp))
          alignment = multiple_sequence_alignment(seqs_fp=output_artif_fp,
                                                  threads=threads_per_sample)
          if not alignment:
              warnings.warn('Problem performing multiple sequence alignment '
                            'on file %s' % seqs_fp, UserWarning)
              logger.warning('msa failed. aborting')
              return None
      elif num_seqs_left == 1:
          # only one sequence after remove artifacts (but could be many reads)
          # no need to run MSA - just use the pre-msa file as input for next step
          output_msa_fp = output_artif_fp
      else:
          err_msg = ('No sequences left after artifact removal in '
                     'file %s' % seqs_fp)
          warnings.warn(err_msg, UserWarning)
          logger.warning(err_msg)
          return None
      # Step 5: Launch deblur
      output_deblur_fp = join(working_dir,
                              "%s.deblur" % basename(output_msa_fp))
      with open(output_deblur_fp, 'w') as f:
          seqs = deblur(sequence_generator(output_msa_fp), mean_error,
                        error_dist, indel_prob, indel_max)
          if seqs is None:
              warnings.warn('multiple sequence alignment file %s contains '
                            'no sequences' % output_msa_fp, UserWarning)
              logger.warn('no sequences returned from deblur for file %s' %
                          output_msa_fp)
              return None
          for s in seqs:
              # remove '-' from aligned sequences
              s.sequence = s.sequence.replace('-', '')
              f.write(s.to_fasta())
      # Step 6: Chimera removal
      output_no_chimeras_fp = remove_chimeras_denovo_from_seqs(
          output_deblur_fp, working_dir, threads=threads_per_sample)
      logger.info('finished processing file')
      return output_no_chimeras_fp