nodes: 0, module; 1, function_definition; 2, function_name:get_clusters_from_fasta_filepath; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, identifier:original_fasta_path; 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, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, default_parameter; 21, default_parameter; 22, default_parameter; 23, default_parameter; 24, expression_statement; 25, comment:# Create readable intermediate filenames if they are to be kept; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, if_statement; 30, if_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, comment:# Error check in case any app controller fails; 35, expression_statement; 36, try_statement; 37, comment:# Get list of lists for each cluster; 38, expression_statement; 39, comment:# Remove temp files unless user specifies output filepath; 40, if_statement; 41, if_statement; 42, identifier:percent_ID; 43, float:0.97; 44, identifier:max_accepts; 45, integer:1; 46, identifier:max_rejects; 47, integer:8; 48, identifier:stepwords; 49, integer:8; 50, identifier:word_length; 51, integer:8; 52, identifier:optimal; 53, False; 54, identifier:exact; 55, False; 56, identifier:suppress_sort; 57, False; 58, identifier:output_dir; 59, None; 60, identifier:enable_rev_strand_matching; 61, False; 62, identifier:subject_fasta_filepath; 63, None; 64, identifier:suppress_new_clusters; 65, False; 66, identifier:return_cluster_maps; 67, False; 68, identifier:stable_sort; 69, False; 70, identifier:tmp_dir; 71, call; 72, identifier:save_uc_files; 73, True; 74, identifier:HALT_EXEC; 75, False; 76, comment:""" Main convenience wrapper for using uclust to generate cluster files
  
      A source fasta file is required for the fasta_filepath.  This will be
      sorted to be in order of longest to shortest length sequences.  Following
      this, the sorted fasta file is used to generate a cluster file in the
      uclust (.uc) format.  Next the .uc file is converted to cd-hit format
      (.clstr).  Finally this file is parsed and returned as a list of lists,
      where each sublist a cluster of sequences.  If an output_dir is
      specified, the intermediate files will be preserved, otherwise all
      files created are temporary and will be deleted at the end of this
      function
  
      The percent_ID parameter specifies the percent identity for a clusters,
      i.e., if 99% were the parameter, all sequences that were 99% identical
      would be grouped as a cluster.
      """; 77, assignment; 78, assignment; 79, assignment; 80, boolean_operator; 81, block; 82, identifier:save_uc_files; 83, block; 84, else_clause; 85, assignment; 86, assignment; 87, assignment; 88, assignment; 89, block; 90, except_clause; 91, except_clause; 92, assignment; 93, not_operator; 94, block; 95, identifier:return_cluster_maps; 96, block; 97, else_clause; 98, identifier:gettempdir; 99, argument_list; 100, identifier:fasta_output_filepath; 101, None; 102, identifier:uc_output_filepath; 103, None; 104, identifier:cd_hit_filepath; 105, None; 106, identifier:output_dir; 107, not_operator; 108, expression_statement; 109, expression_statement; 110, block; 111, identifier:sorted_fasta_filepath; 112, string:""; 113, identifier:uc_filepath; 114, string:""; 115, identifier:clstr_filepath; 116, string:""; 117, identifier:files_to_remove; 118, list; 119, if_statement; 120, comment:# Generate uclust cluster file (.uc format); 121, expression_statement; 122, comment:# Get cluster file name from application wrapper; 123, expression_statement; 124, identifier:ApplicationError; 125, block; 126, identifier:ApplicationNotFoundError; 127, block; 128, pattern_list; 129, line_continuation:\; 130, call; 131, identifier:save_uc_files; 132, expression_statement; 133, return_statement; 134, block; 135, call; 136, augmented_assignment; 137, assignment; 138, expression_statement; 139, not_operator; 140, comment:# Sort fasta input file from largest to smallest sequence; 141, block; 142, else_clause; 143, assignment; 144, call; 145, expression_statement; 146, raise_statement; 147, expression_statement; 148, raise_statement; 149, identifier:clusters; 150, identifier:failures; 151, identifier:seeds; 152, identifier:clusters_from_uc_file; 153, argument_list; 154, call; 155, expression_list; 156, return_statement; 157, attribute; 158, argument_list; 159, identifier:output_dir; 160, string; 161, identifier:uc_save_filepath; 162, call; 163, assignment; 164, identifier:suppress_sort; 165, expression_statement; 166, comment:# Get sorted fasta name from application wrapper; 167, expression_statement; 168, expression_statement; 169, block; 170, identifier:uclust_cluster; 171, call; 172, identifier:remove_files; 173, argument_list; 174, call; 175, call; 176, call; 177, call; 178, subscript; 179, attribute; 180, argument_list; 181, identifier:clusters; 182, identifier:failures; 183, identifier:seeds; 184, expression_list; 185, identifier:output_dir; 186, identifier:endswith; 187, string; 188, string_content:/; 189, identifier:get_output_filepaths; 190, argument_list; 191, identifier:uc_save_filepath; 192, None; 193, assignment; 194, assignment; 195, call; 196, expression_statement; 197, expression_statement; 198, identifier:uclust_cluster_from_sorted_fasta_filepath; 199, argument_list; 200, identifier:files_to_remove; 201, identifier:remove_files; 202, argument_list; 203, identifier:ApplicationError; 204, argument_list; 205, identifier:remove_files; 206, argument_list; 207, identifier:ApplicationNotFoundError; 208, argument_list; 209, identifier:uclust_cluster; 210, string; 211, identifier:uclust_cluster; 212, identifier:cleanUp; 213, call; 214, identifier:failures; 215, identifier:seeds; 216, string_content:/; 217, identifier:output_dir; 218, identifier:original_fasta_path; 219, identifier:sort_fasta; 220, call; 221, identifier:sorted_fasta_filepath; 222, attribute; 223, attribute; 224, argument_list; 225, assignment; 226, assignment; 227, identifier:sorted_fasta_filepath; 228, identifier:uc_save_filepath; 229, keyword_argument; 230, keyword_argument; 231, keyword_argument; 232, keyword_argument; 233, keyword_argument; 234, keyword_argument; 235, keyword_argument; 236, keyword_argument; 237, keyword_argument; 238, keyword_argument; 239, keyword_argument; 240, keyword_argument; 241, keyword_argument; 242, keyword_argument; 243, identifier:files_to_remove; 244, concatenated_string; 245, identifier:files_to_remove; 246, binary_operator:'uclust not found, is it properly ' +
                                         'installed?'; 247, string_content:ClusterFile; 248, attribute; 249, argument_list; 250, identifier:uclust_fasta_sort_from_filepath; 251, argument_list; 252, subscript; 253, identifier:name; 254, identifier:files_to_remove; 255, identifier:append; 256, identifier:sorted_fasta_filepath; 257, identifier:sort_fasta; 258, None; 259, identifier:sorted_fasta_filepath; 260, identifier:fasta_filepath; 261, identifier:percent_ID; 262, identifier:percent_ID; 263, identifier:max_accepts; 264, identifier:max_accepts; 265, identifier:max_rejects; 266, identifier:max_rejects; 267, identifier:stepwords; 268, identifier:stepwords; 269, identifier:word_length; 270, identifier:word_length; 271, identifier:optimal; 272, identifier:optimal; 273, identifier:exact; 274, identifier:exact; 275, identifier:suppress_sort; 276, identifier:suppress_sort; 277, identifier:enable_rev_strand_matching; 278, identifier:enable_rev_strand_matching; 279, identifier:subject_fasta_filepath; 280, identifier:subject_fasta_filepath; 281, identifier:suppress_new_clusters; 282, identifier:suppress_new_clusters; 283, identifier:stable_sort; 284, identifier:stable_sort; 285, identifier:tmp_dir; 286, identifier:tmp_dir; 287, identifier:HALT_EXEC; 288, identifier:HALT_EXEC; 289, string; 290, string; 291, string; 292, string; 293, string; 294, identifier:clusters; 295, identifier:values; 296, identifier:fasta_filepath; 297, keyword_argument; 298, identifier:sort_fasta; 299, string; 300, string_content:Error running uclust. Possible causes are; 301, string_content:unsupported version (current supported version is v1.2.22) is installed or; 302, string_content:improperly formatted input file was provided; 303, string_content:uclust not found, is it properly; 304, string_content:installed?; 305, identifier:output_filepath; 306, identifier:fasta_output_filepath; 307, string_content:Output
code: def get_clusters_from_fasta_filepath(
          fasta_filepath,
          original_fasta_path,
          percent_ID=0.97,
          max_accepts=1,
          max_rejects=8,
          stepwords=8,
          word_length=8,
          optimal=False,
          exact=False,
          suppress_sort=False,
          output_dir=None,
          enable_rev_strand_matching=False,
          subject_fasta_filepath=None,
          suppress_new_clusters=False,
          return_cluster_maps=False,
          stable_sort=False,
          tmp_dir=gettempdir(),
          save_uc_files=True,
          HALT_EXEC=False):
      """ Main convenience wrapper for using uclust to generate cluster files
  
      A source fasta file is required for the fasta_filepath.  This will be
      sorted to be in order of longest to shortest length sequences.  Following
      this, the sorted fasta file is used to generate a cluster file in the
      uclust (.uc) format.  Next the .uc file is converted to cd-hit format
      (.clstr).  Finally this file is parsed and returned as a list of lists,
      where each sublist a cluster of sequences.  If an output_dir is
      specified, the intermediate files will be preserved, otherwise all
      files created are temporary and will be deleted at the end of this
      function
  
      The percent_ID parameter specifies the percent identity for a clusters,
      i.e., if 99% were the parameter, all sequences that were 99% identical
      would be grouped as a cluster.
      """
  
      # Create readable intermediate filenames if they are to be kept
      fasta_output_filepath = None
      uc_output_filepath = None
      cd_hit_filepath = None
  
      if output_dir and not output_dir.endswith('/'):
          output_dir += '/'
  
      if save_uc_files:
          uc_save_filepath = get_output_filepaths(
              output_dir,
              original_fasta_path)
      else:
          uc_save_filepath = None
  
      sorted_fasta_filepath = ""
      uc_filepath = ""
      clstr_filepath = ""
  
      # Error check in case any app controller fails
      files_to_remove = []
      try:
          if not suppress_sort:
              # Sort fasta input file from largest to smallest sequence
              sort_fasta = uclust_fasta_sort_from_filepath(fasta_filepath,
                                                           output_filepath=fasta_output_filepath)
  
              # Get sorted fasta name from application wrapper
              sorted_fasta_filepath = sort_fasta['Output'].name
              files_to_remove.append(sorted_fasta_filepath)
  
          else:
              sort_fasta = None
              sorted_fasta_filepath = fasta_filepath
  
          # Generate uclust cluster file (.uc format)
          uclust_cluster = uclust_cluster_from_sorted_fasta_filepath(
              sorted_fasta_filepath,
              uc_save_filepath,
              percent_ID=percent_ID,
              max_accepts=max_accepts,
              max_rejects=max_rejects,
              stepwords=stepwords,
              word_length=word_length,
              optimal=optimal,
              exact=exact,
              suppress_sort=suppress_sort,
              enable_rev_strand_matching=enable_rev_strand_matching,
              subject_fasta_filepath=subject_fasta_filepath,
              suppress_new_clusters=suppress_new_clusters,
              stable_sort=stable_sort,
              tmp_dir=tmp_dir,
              HALT_EXEC=HALT_EXEC)
          # Get cluster file name from application wrapper
          remove_files(files_to_remove)
      except ApplicationError:
          remove_files(files_to_remove)
          raise ApplicationError('Error running uclust. Possible causes are '
                                 'unsupported version (current supported version is v1.2.22) is installed or '
                                 'improperly formatted input file was provided')
      except ApplicationNotFoundError:
          remove_files(files_to_remove)
          raise ApplicationNotFoundError('uclust not found, is it properly ' +
                                         'installed?')
  
      # Get list of lists for each cluster
      clusters, failures, seeds = \
          clusters_from_uc_file(uclust_cluster['ClusterFile'])
  
      # Remove temp files unless user specifies output filepath
      if not save_uc_files:
          uclust_cluster.cleanUp()
  
      if return_cluster_maps:
          return clusters, failures, seeds
      else:
          return clusters.values(), failures, seeds