Qiime2r & phyloseq questions

Hi Jordan,

Thank you for the tutorial. It is very useful. I have a question about how to use the info here to make barplots in phyloseq. You showed here how to create a phyloseq object from qiime artifacts. I made that object but I was only able to make a barplot that is black and general. When I try to fill based on different taxonomy levels, it is not successful because the levels are not separated in the taxonomy file. Can you show us how to make a barplot that is filled at different levels using the phy file?

Thanks

1 Like

You need to parse up your taxonomy string into the different levels for the taxonomy object so that each level has its own column. What the delimiter is might change a little, but if it is something like:

Feature \t Taxon
hashedID \t `Bacteria;Actinobacteria;Coriobacteriia;Eggerthellacae;Eggerthella;lenta`

You could use the split on the semicolon like this:
taxonomy<-taxonomy %>% separate(Taxon, c("Kingdom","Phylum","Class","Order","Family","Genus","Species"), sep=";")

3 Likes

Hi Jordan,

Thank you for your reply. I understand that part but how is that part of the tutorial linked to this next part when we read in the files again?

phy<-qza_to_phyloseq(“v3v4-20190304-table-dada2-p-Phylum-only.qza”, “rooted-tree-v3v4-20190304-rep-seqs-dada2-p-Phylum-only.qza”, “V3V4-20190304-taxonomy.qza”, “20190304-sample-metadata-v3v4_nNC.txt”)

Here we are reading the table, the tree, the taxonomy, and the metadata in and convert it to a phyloseq object. Later, we use plot_bar(phy) to make the barplot. So I don’t understand how splitting using the code you wrote would affect phy since phy is acquired through reading the original files in and not the the split taxonomy file. That part was confusing to me.

So here’s what I did:

metadata<-read.delim(“20190304-sample-metadata-v3v4_nNC.txt”)

SVs<-read_qza(“v3v4-20190304-table-dada2-p-Phylum-only.qza”)

taxonomy<-read_qza(“V3V4-20190304-taxonomy.qza”)
taxtable<-taxonomy$data %>% as_tibble() %>% separate(Taxon, sep=";", c(“Kingdom”,“Phylum”,“Class”,“Order”,“Family”,“Genus”,“Species”))

tree<-read_qza(“rooted-tree-v3v4-20190304-rep-seqs-dada2-p-Phylum-only.qza”)

and then:

phy<-qza_to_phyloseq(“v3v4-20190304-table-dada2-p-Phylum-only.qza”, “rooted-tree-v3v4-20190304-rep-seqs-dada2-p-Phylum-only.qza”, “V3V4-20190304-taxonomy.qza”, “20190304-sample-metadata-v3v4_nNC.txt”)

but these two sets of codes seem separate since with phy, we seem to be reading the files in again and we are not using the taxonomy files that was made using:

taxonomy<-read_qza(“V3V4-20190304-taxonomy.qza”)
taxtable<-taxonomy$data %>% as_tibble() %>% separate(Taxon, sep=";", c(“Kingdom”,“Phylum”,“Class”,“Order”,“Family”,“Genus”,“Species”))

I am not sure how to link these two sets of codes to be able to include the split taxonomy file in my phy file.

1 Like

I keep getting the error that Phylum is not found when I try to fill at this level and same for any other level which shows the taxonomy file is not split.

To be clear here is the last code I tried:

physeq<-phyloseq(
otu_table(SVs$data, taxa_are_rows = T),
phy_tree(tree$data),
tax_table(as.data.frame(taxtable) %>% column_to_rownames(“Feature.ID”) %>% as.matrix()), #moving the taxonomy to the way phyloseq wants it
sample_data(metadata %>% as.data.frame() %>% column_to_rownames(“SampleID”)))

plot_bar(physeq, “sample_Species”, fill = Phylum)

Even though the taxonomy file is taxtable which was split before using the code below, still Phylum cannot be found when I try to make a barplot.

taxonomy<-read_qza(“V3V4-20190304-taxonomy.qza”)
taxtable<-taxonomy$data %>% as_tibble() %>% separate(Taxon, sep=";", c(“Kingdom”,“Phylum”,“Class”,“Order”,“Family”,“Genus”,“Species”))

1 Like

I think one of two things are happening, either the output of the 4th line tax_table(… does not have Phylum as a column, or… more likely, since there are not quotations around Phylum in fill=Phylum it is looking for an object/variable called Phylum which does not exist. Try fill="Phylum" and I suspect it may work. If you look at the documentation for the function, you will see they have used quotations on the taxonomic level.

1 Like

Yes, the quotation worked like a charm! Thank you!

1 Like

A post was split to a new topic: how to remove taxonomic rank prefixes in R?