Qiime2R: Codes Needed for Drawing Some Taxaonomy Barplot.

Hi,

I am looking for some codes for Qiime2R package in R to do:

-Isolate bacteria and archaea domains from each other.
-draw a taxonomy barplot only for phylum rank.
-draw a taxonomy barplot only for family rank.
-keep only major taxa in phylum level.
-keep only major taxa in family level.

Anybody can share the codes with me?
I did not find them by googling and here.

By the way, could you please tell me what is the treatment argument in this page? Or what can I use instead of treatment from my data files?

My barplot in Qiime2:

I used this code; type is one of column names in the metadata file. It gave an error.

taxa_barplot(Tables, metadata, "type")
Error in nrow(features) : object 'Merged' not found

Thanks a lot

Hello @TurboQiimer, I think this tutorial may help it out…!

I have checked it out already. I mentioned the tutorial above. anyway, thanks.

1 Like

I had another error:

library(qiime2R)
library(tidyverse)
meta<- read_q2metadata("metadata.tsv")
AVs<-read_qza("Table.qza")
taxa<-read_qza("taxonomy.qza")
taxa<-read_qza("taxonomy.qza")$data %>%parse_taxonomy()
taxa_barplot(AVs, taxa)$Genus

Error in if (missing(ntoplot) & nrow(features) > 10) { :
argument is of length zero

library(qiime2R)
library(tidyverse)
meta<- read_q2metadata("metadata.tsv")
AVs<-read_qza("Table.qza")
taxa<-read_qza("taxonomy.qza")
taxa<-read_qza("taxonomy.qza")$data %>%parse_taxonomy()
taxasums<- summarize_taxa(AVs,taxa)

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 1, 3, 2

I believe what you are looking for is described in the github readme as below:

library(tidyverse)
library(qiime2R)

metadata<-read_q2metadata("sample-metadata.tsv")
SVs<-read_qza("table.qza")$data
taxonomy<-read_qza("taxonomy.qza")$data %>% parse_taxonomy()

taxasums<-summarize_taxa(SVs, taxonomy)$Genus

taxa_barplot(taxasums, metadata, "body-site")

ggsave("barplot.pdf", height=4, width=8, device="pdf") # save a PDF 4 inches by 8 inches

The summarize_taxa() function will aggregate the counts based on your taxonomy table and returns a list at each phylogenetic level so you would switch $Phylum for $Genus on the 8th line if that is what you want. If you read the documentation for the barplot (?taxa_barplot), you will see that the category and ntoplot functions allow you to control the grouping (ie the variable to separate the bars by) and the number of major taxons to include in the plot (the rest go into the remainder grouping) respectively.

5 Likes

Thanks, sir. I followed the steps as you mentioned and are in the documentation but I got the error bekwo. I shared the codes plus the error with $Phylum rank. The last code makes an error sadly. I was unable to solve this and I do not know what is the origin of it.

library(qiime2R)
library(tidyverse)
meta<- read_q2metadata("metadata.tsv")
AVs<-read_qza("Table.qza")
taxa<-read_qza("taxonomy.qza")
taxa<-read_qza("taxonomy.qza")$data %>%parse_taxonomy()
taxasums<- summarize_taxa(AVs,taxa)$Phylum

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 1, 3, 2

You have made an error on the 4th line when you rewrote the code. Remember that that read_qza() reads the entire artifact including its associated provenance. If you want to extract the ASV table from it you need to add $data like the code in the example.

Sorry, I faced another error with this step.

taxasums<- summarize_taxa(AVs,taxa)$Phylum
Error in summarize_taxa(AVs, taxa) :
Taxonomy does not contain expected columns containing Kingdom,Phylum,Class,Order,Family,Genus,Species.

How to solve this?