def split_otu_table_on_taxonomy_to_files(otu_table_fp, level, output_dir, md_identifier='taxonomy', md_processor=process_md_as_list):
 results = []
 otu_table = load_table(otu_table_fp)
 create_dir(output_dir)
 def split_f(id_, obs_md):
  try:
   result = md_processor(obs_md, md_identifier, level)
  except KeyError:
   raise KeyError(('Metadata identifier (%s) is not associated with all (or any) observerations. You can modify the key with the md_identifier parameter.' % md_identifier))
  except TypeError:
   raise TypeError("Can't correctly process the metadata string. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_as_string.")
  except AttributeError:
   raise AttributeError('Metadata category not found. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_identifier "Consensus Lineage".')
  return result
 for (bin, sub_otu_table) in otu_table.partition(split_f, axis='observation'):
  output_fp = ('%s/otu_table_%s.biom' % (output_dir, bin))
  write_biom_table(sub_otu_table, output_fp)
  results.append(output_fp)
 return results

def split_otu_table_on_taxonomy_to_files ( otu_table_fp , level , output_dir , md_identifier = 'taxonomy' , md_processor = process_md_as_list ) : results = [ ] otu_table = load_table ( otu_table_fp ) create_dir ( output_dir ) def split_f ( id_ , obs_md ) : try : result = md_processor ( obs_md , md_identifier , level ) except KeyError : raise KeyError ( ( 'Metadata identifier (%s) is not associated with all (or any) observerations. You can modify the key with the md_identifier parameter.' % md_identifier ) ) except TypeError : raise TypeError ( "Can't correctly process the metadata string. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_as_string." ) except AttributeError : raise AttributeError ( 'Metadata category not found. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_identifier "Consensus Lineage".' ) return result for ( bin , sub_otu_table ) in otu_table . partition ( split_f , axis = 'observation' ) : output_fp = ( '%s/otu_table_%s.biom' % ( output_dir , bin ) ) write_biom_table ( sub_otu_table , output_fp ) results . append ( output_fp ) return results
split otu table by taxonomic level .