Exporting and modifying BIOM tables (e.g. adding taxonomy annotations)

Creating a TSV BIOM table

The following is based on a post by @gregcaporaso.

$ qiime tools export table.qza --output-dir ./
$ biom convert -i feature-table.biom -o feature-table.tsv --to-tsv
$ biom head -i feature-table.tsv
# Constructed from biom file
#OTU ID	L1S105	L1S140	L1S208	L1S257	L1S281
4b5eeb300368260019c1fbc7a3c718fc	2222.0	0.0	0.0	0.0	0.0
fe30ff0f71a38a39cf1717ec2be3a2fc	5.0	0.0	0.0	0.0	0.0
d29fe3c70564fc0f69f2c03e0d1e5561	0.0	0.0	0.0	0.0	0.0
868528ca947bc57b69ffdf83e6b73bae	0.0	2276.0	2156.0	1205.0	1772.0
154709e160e8cada6bfb21115acc80f5	812.0	1176.0	713.0	407.0	242.0 

Creating a BIOM table with taxonomy annotations

The following is based on a post by @jairideout.

qiime tools export --input-path table.qza --output-path exported
qiime tools export --input-path taxonomy.qza --output-path exported

Next, we'll need to modify the exported taxonomy file's header before using it with BIOM software. Before modifying that file, make a copy:

cp exported/taxonomy.tsv biom-taxonomy.tsv

The first few lines in biom-taxonomy.tsv should look something like this (the actual data will differ):

Feature ID	Taxon	Confidence
0204aa97a655fab087a6f6902be35eb6	k__Bacteria; p__Bacteroidetes; c__Sphingobacteriia; o__Sphingobacteriales; f__Sphingobacteriaceae; g__Sphingobacterium; s__faecium	-1.0
5cfeeb662c643e512cbfc724c984f53d	k__Bacteria; p__Firmicutes; c__Bacilli; o__Lactobacillales; f__Lactobacillaceae; g__Lactobacillus; s__	-1.0
4dc10ad4afd35b9803d853e819d3cec5	k__Bacteria; p__Firmicutes; c__Clostridia; o__Clostridiales; f__Lachnospiraceae; g__; s__	-1.0
...

Change the first line of biom-taxonomy.tsv (i.e. the header) to this:

#OTUID	taxonomy	confidence

Note that you'll need to use tab characters in the header since this is a TSV file.

Your biom-taxonomy.tsv file should now look something like this (the actual data will differ):

#OTUID	taxonomy	confidence
0204aa97a655fab087a6f6902be35eb6	k__Bacteria; p__Bacteroidetes; c__Sphingobacteriia; o__Sphingobacteriales; f__Sphingobacteriaceae; g__Sphingobacterium; s__faecium	-1.0
5cfeeb662c643e512cbfc724c984f53d	k__Bacteria; p__Firmicutes; c__Bacilli; o__Lactobacillales; f__Lactobacillaceae; g__Lactobacillus; s__	-1.0
4dc10ad4afd35b9803d853e819d3cec5	k__Bacteria; p__Firmicutes; c__Clostridia; o__Clostridiales; f__Lachnospiraceae; g__; s__	-1.0
...

Finally, add the taxonomy data to your .biom file:

biom add-metadata -i exported/feature-table.biom -o table-with-taxonomy.biom --observation-metadata-fp biom-taxonomy.tsv --sc-separated taxonomy
36 Likes

An off-topic reply has been split into a new topic: Exporting feature table and adding taxonomy and converting to tsv

Please keep replies on-topic in the future.

An off-topic reply has been split into a new topic: biom.exception.BiomParseException: No header line was found in mapping file

Please keep replies on-topic in the future.

An off-topic reply has been split into a new topic: Change header names from Feature ID to OTUID in exported TSVTaxonomyDirectoryFormat file

Please keep replies on-topic in the future.

–output-dir no longer works, in case anyone is wondering, instead, use:

–output-path

1 Like

Updated the post, thanks @willwcb!

Ah, and you also have to have --input-path before the input file:

qiime tools export --input-path table.qza --output-path exported

1 Like

An off-topic reply has been split into a new topic: How to get taxonomy annotations in biom file?

Please keep replies on-topic in the future.

An off-topic reply has been split into a new topic: Export to “classic” biom

Please keep replies on-topic in the future.

An off-topic reply has been split into a new topic: How to include confidence in taxonomy-annotated BIOM file?

Please keep replies on-topic in the future.

A post was split to a new topic: Operation not permitted while exporting

A post was split to a new topic: Why it is so not intuitive?

A post was split to a new topic: Output counts and taxonomy to biom

A post was split to a new topic: Help merging metadata with biom file

A post was merged into an existing topic: Problem with Biom add metadata

A post was split to a new topic: Error exporting and modifying biom

An off-topic reply has been split into a new topic: i got no taxonomic annotations, why?

Please keep replies on-topic in the future.