6
6
__copyright__ = "Copyright 2011, The QIIME Project"
7
7
__credits__ = ["Rob Knight","Justin Kuczynski","Greg Caporaso"]
10
10
__maintainer__ = "Daniel McDonald"
11
11
__email__ = "wasade@gmail.com"
12
12
__status__ = "Release"
15
from qiime.util import parse_command_line_parameters
16
from qiime.util import make_option
17
from biom.parse import parse_biom_table
18
from qiime.parse import parse_taxonomy_to_otu_metadata
19
from qiime.format import format_biom_table
22
script_info['brief_description']="""Add taxa to OTU table"""
23
script_info['script_description']="""This script adds taxa to a biom-formatted OTU table."""
24
script_info['script_usage']=[]
26
script_info['script_usage'].append(("""Example:""","""Given an input otu table with no metadata (otu_table_no_tax.biom) and a tab-separated text file mapping OTU ids to taxonomic assignments and scores associated with those assignments (tax.txt), generate a new otu table that includes taxonomic assignments (otu_table_w_tax.biom).""","""%prog -i otu_table_no_tax.biom -o otu_table_w_tax.biom -t tax.txt"""))
28
script_info['script_usage'].append(("""Example:""","""Given an input otu table with no metadata (otu_table_no_tax.biom) and a tab-separated text file mapping OTU ids to taxonomic assignments and scores associated with those assignments (tax.txt), generate a new otu table that includes taxonomic assignments (otu_table_w_tax.biom) with alternate metadata identifiers.""","""%prog -i otu_table_no_tax.biom -o otu_table_w_alt_labeled_tax.biom -t tax.txt -l "Consensus Lineage,Score" """))
30
script_info['script_usage'].append(("""Example:""","""Given an input otu table with no metadata (otu_table_no_tax.biom) and a tab-separated text file mapping OTU ids to some value, generate a new otu table that includes that metadata category labeled as "Score" (otu_table_w_score.biom).""","""%prog -i otu_table_no_tax.biom -o otu_table_w_score.biom -t score_only.txt -l "Score" --all_strings"""))
32
script_info['output_description']="""An OTU table in biom format is written to the file specified as -o."""
33
script_info['required_options']=[\
34
make_option('-i','--input_fp',type='existing_filepath',
35
help='path to input otu table file in biom format'),
36
make_option('-o','--output_fp',type='new_filepath',
37
help='path to output file in biom format'),
38
make_option('-t','--taxonomy_fp',type='existing_filepath',
39
help='path to input taxonomy file (e.g., as generated by assign_taxonomy.py)'),
42
script_info['optional_options']=[
43
make_option('-l','--labels',type='string',default='taxonomy,score',
44
help='labels to be assigned to metadata in taxonomy_fp'),
45
make_option('--all_strings',action='store_true',default=False,
46
help='treat all metadata as strings, rather than casting to lists/floats (useful with --labels for adding arbitrary observation metadata) [default:%default]')]
47
script_info['version'] = __version__
50
option_parser, opts, args = parse_command_line_parameters(**script_info)
52
labels = opts.labels.split(',')
54
process_fs = [str] * len(labels)
55
observation_metadata = parse_taxonomy_to_otu_metadata(\
56
open(opts.taxonomy_fp,'U'),labels=labels,process_fs=process_fs)
58
observation_metadata = parse_taxonomy_to_otu_metadata(\
59
open(opts.taxonomy_fp,'U'),labels=labels)
62
otu_table = parse_biom_table(open(opts.input_fp,'U'))
64
if otu_table.ObservationMetadata != None:
65
# if there is already metadata associated with the
66
# observations, confirm that none of the metadata names
68
existing_keys = otu_table.ObservationMetadata[0].keys()
70
if label in existing_keys:
72
"%s is already an observation metadata field."
73
" Can't add it, so nothing is being added." % label)
75
otu_table.addObservationMetadata(observation_metadata)
77
output_f = open(opts.output_fp,'w')
78
output_f.write(format_biom_table(otu_table))
84
if __name__ == "__main__":
14
print "\nThis script has been deprecated in favor of the more general add_metadata.py script. add_metadata.py is part of the biom-format package, a dependency of QIIME. For more details, call:\n\nadd_metadata.py -h\n"
b'\\ No newline at end of file'