# Importing Taxonomy Tables from dada2

**URL:** https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609
**Category:** User Support
**Tags:** taxonomy, dada2, pending-development, import
**Created:** [March 29, 2018, 11:16pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609 "2018-03-29T23:16:27Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![ChristianEdwardson](https://forum.qiime2.org/user_avatar/forum.qiime2.org/christianedwardson/32/4215_2.png) [@ChristianEdwardson](https://forum.qiime2.org/u/ChristianEdwardson)
#### Post date: [March 29, 2018, 11:16pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/1 "2018-03-29T23:16:27Z")

</div>

Is it possible to import a dada2 (and/or phyloseq) format taxonomy table into qiime2 directly?

In this case, each level of the taxonomy is tab-separated, rather than one column for taxonomic assignment.

---

<div class="post-metadata">

### Author: ![colinbrislawn](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinbrislawn/32/6221_2.png) [@colinbrislawn](https://forum.qiime2.org/u/colinbrislawn)
#### Post date: [March 29, 2018, 11:37pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/2 "2018-03-29T23:37:35Z")

</div>

Hello Christian,

Directly? Nope. Taxonomy is never even mentioned on the [importing page](https://docs.qiime2.org/2018.2/tutorials/importing/), presumably because taxonomy is already inside the .biom file that being imported.

But importing from a `otu_table_w_tax.biom` should work great. The main idea is to add the taxonomy to a .biom file [like this](http://biom-format.org/documentation/adding_metadata.html), then [import that .biom file](https://docs.qiime2.org/2018.2/tutorials/importing/#feature-table-data) into Qiime 2.

Sounds like your taxonomy table is not quite in the format that Qiime wants (too many tabs!)

If you could post the first few lines of it, I can build a `sed` command to convert it into the right format.

Colin

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [March 30, 2018, 2:22pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/3 "2018-03-30T14:22:13Z")

</div>



---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 2, 2018, 6:48pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/4 "2018-04-02T18:48:35Z")

</div>

Thanks @colinbrislawn! Just to clarify, the Importing guide you link to is not an exhaustive guide to importing, there are many (dozens?) of formats not covered in the docs anywhere just yet. There are, however, many examples of importing taxonomy floating around here on the forum! With that said, @ChristianEdwardson - the taxonomy format in QIIME 2 expects the entire taxon value to be encoded in one single column (semicolon delimited between taxonomic levels). Additional columns are supported, but aren't parsed as taxonomic information (a good example is feature classification confidence). As well, @colinbrislawn is discussing a _feature table_ with taxonomic annotations, but I understood from your initial post that this isn't a feature table (samples by features), but if I misunderstood please let us know!. To second @colinbrislawn's request - a few lines of the file wouldn't hurt! Thanks! 🦖

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 2, 2018, 6:48pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/5 "2018-04-02T18:48:36Z")

</div>



---

<div class="post-metadata">

### Author: ![ChristianEdwardson](https://forum.qiime2.org/user_avatar/forum.qiime2.org/christianedwardson/32/4215_2.png) [@ChristianEdwardson](https://forum.qiime2.org/u/ChristianEdwardson)
#### Post date: [April 6, 2018, 9:08pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/6 "2018-04-06T21:08:10Z")

</div>

This may be of limited interest or value to others, as I'm assuming most people will run the dada2 pipeline within QIIME2, but say I already have my data processed in R and I want to use the QIIME 2 downstream analyses, I need a taxonomy table (FeatureData[Taxonomy]). The taxonomy table produced by dada2 in R is a matrix with rownames = exact sequence (feature), and one column for each taxonomy level, Kingdom to Genus. I can export the matrix however I want - for example I can create a semicolon-separated file or a tab-separated file, but then I would have to change the first instance of a semicolon to a tab or with sed or awk. My question was more along the lines of if QIIME2 would be able to parse taxonomy data in multiple formats?

[taxa\_example.txt](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/flex002/uploads/qiime21/original/2X/6/649aef7fc4889682102b8446b78d24a29083588f.txt) (2.1 KB)

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 9, 2018, 2:28pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/7 "2018-04-09T14:28:00Z")

</div>



---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 10, 2018, 3:31pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/8 "2018-04-10T15:31:05Z")

</div>

> [@ChristianEdwardson](#):
>
> My question was more along the lines of if QIIME2 would be able to parse taxonomy data in multiple formats?

Ah, sorry for misunderstanding! While not specific to this particular format, we do support importing multiple formats for any particular _Semantic Type_ of data - for example, check out the [Importing Feature Table Data tutorial](https://docs.qiime2.org/2018.2/tutorials/importing/#feature-table-data) - we have multiple _formats_ specified in QIIME 2 - one for the BIOM v1.0.0 format, and one for the BIOM v2.1.0 format --- both can be imported as the same type, there is just some additional machinery defined in the format and/or transformers to do the conversions along the way (stay tuned for developer docs, I would've linked to them here if I had some to share!). Hope that answers your question. Thanks! 🦖

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 10, 2018, 3:31pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/9 "2018-04-10T15:31:19Z")

</div>



---

<div class="post-metadata">

### Author: ![ChristianEdwardson](https://forum.qiime2.org/user_avatar/forum.qiime2.org/christianedwardson/32/4215_2.png) [@ChristianEdwardson](https://forum.qiime2.org/u/ChristianEdwardson)
#### Post date: [April 17, 2018, 11:56pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/10 "2018-04-17T23:56:35Z")

</div>

Thanks @colinbrislawn and @thermokarst for the suggestions, as well as [this post](https://forum.qiime2.org/t/exporting-dada2-r-package-results-to-work-with-qiime2/2573/5).

I have figured out how to get the taxonomy from dada2/phyloseq in the correct format to be added to both biom files correctly and qiime2. Posting the code here for anyone else that might be having troubles.  
One note: I needed to install the latest github version of [biomformat](https://github.com/joey711/biomformat) for R (version 1.7.0)

Starting in R with a phyloseq object (ps):

Format the taxonomy table:

> tax\<-as(tax\_table(ps),"matrix")  
> tax\_cols \<- c("Kingdom", "Phylum", "Class","Order","Family","Genus")  
> tax\<-as.data.frame(tax)  
> tax$taxonomy\<-do.call(paste, c(tax[tax\_cols], sep=";"))  
> for(co in tax\_cols) tax[co]\<-NULL  
> write.table(tax, "tax.txt", quote=FALSE, col.names=FALSE, sep="\t")

Make an biomformat OTU table:

> otu\<-t(as(otu\_table(ps),"matrix"))  
> otu\_biom\<-make\_biom(data=otu)  
> write\_biom(otu\_biom,"otu\_biom.biom")

Optional: In qiime2 to make a biom OTU table with taxonomy:  
(this step is not necessary for qiime2, as the taxonomy table is not imported from the biom file)

> biom convert -i otu\_biom.biom -o otu\_biom\_HDF5.biom --to-hdf5  
> biom add-metadata -i otu\_biom\_HDF5.biom -o otu\_wTax.biom --observation-metadata-fp tax.txt --observation-header OTUID,taxonomy --sc-separated taxonomy

Import the OTU table (feature table) to qiime2:

> qiime tools import \  
> --input-path otu\_wTax.biom \  
> --type 'FeatureTable[Frequency]' \  
> --source-format BIOMV210Format \  
> --output-path feature-table.qza

Finally, import the taxonomy table:

> qiime tools import \  
> --type 'FeatureData[Taxonomy]' \  
> --source-format HeaderlessTSVTaxonomyFormat \  
> --input-path tax.txt \  
> --output-path taxonomy.qza

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [April 18, 2018, 12:24am UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/11 "2018-04-18T00:24:48Z")

</div>

This is great @ChristianEdwardson - would you be up for moving this over to [Community Tutorials](https://forum.qiime2.org/c/community-contributions/community-tutorials)? I suspect this will come in handy for many others! Thanks! 🦖

---

<div class="post-metadata">

### Author: ![ChristianEdwardson](https://forum.qiime2.org/user_avatar/forum.qiime2.org/christianedwardson/32/4215_2.png) [@ChristianEdwardson](https://forum.qiime2.org/u/ChristianEdwardson)
#### Post date: [April 27, 2018, 10:15pm UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/12 "2018-04-27T22:15:46Z")

</div>

This could definitely go over to the Community Tutorials. Do I just need to copy this to a new topic over there?

---

<div class="post-metadata">

### Author: ![colinbrislawn](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinbrislawn/32/6221_2.png) [@colinbrislawn](https://forum.qiime2.org/u/colinbrislawn)
#### Post date: [April 28, 2018, 3:50am UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/13 "2018-04-28T03:50:42Z")

</div>

Good afternoon,

I would love to see this as a community tutorial. Then we could point to your rock-solid example, without having folks track down all the pages you had to find.

While you could just copy/paste these commands, a little more legwork will make this tutorial much more useful for future users. Here's what is suggested:

> [@About the Tutorials category](https://forum.qiime2.org/t/about-the-tutorials-category/933/1):
>
> Community Tutorials should include a description of why a reader would be interested in the tutorial, a small test dataset that can be downloaded by the reader, the commands to be run on the dataset with a description of what each command is doing, and guidelines for interpreting the results. Running all of the commands in your tutorial should be quick (e.g., a few minutes of compute time).

So combining the strengths of your post with @Jaroslaw_Grzadziel's [post](https://forum.qiime2.org/t/exporting-dada2-r-package-results-to-work-with-qiime2/2573/5) is a perfect start. Adding a toy data set (or a small but real data set!) with an intro paragraph just to set the scene would make for a very good tutorial.

Colin  
P.S. The [canonical biom-format package](https://github.com/biocore/biom-format) should have an R package that **just works**. Installing github software in R requires lots of dependencies, so maybe while you build this tutorial, we can get that up and running.

PPS. Thanks.

PPPS. #openscience

---

<div class="post-metadata">

### Author: ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)
#### Post date: [May 29, 2018, 9:50am UTC](https://forum.qiime2.org/t/importing-taxonomy-tables-from-dada2/3609/14 "2018-05-29T09:50:44Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
