Hello, first I would thank @jbisanz for the wonderful package. The ability to transfer data between qiime2 and phyloseq is amazing.
While I was following the tutorial (Tutorial: Integrating QIIME2 and R for data visualization and analysis using qiime2R - #26). I have encountered 2 problems, the first one seems to be fixed but I was wondering if we can have a better way to do that.
The second problem is that when I important qiime2 output into phyloseq objects as the tutorial suggested. I realized that my tax table only has a kingdom name, the phylum to genus was missing.
attached is my R code pretty much the same with the tutorial. and some of the output files that I have used.
Try to connect qiime2 workflow with my R flow. following (Tutorial: Integrating QIIME2 and R for data visualization and analysis using qiime2R)
# get package qiime2R
if (!requireNamespace("devtools", quietly = TRUE)){install.packages("devtools")}
devtools::install_github("jbisanz/qiime2R") # current version is 0.99.20
library(qiime2R)
library(ggplot2)
We will start be reading in a table of sequence variants (SVs):
SVs <- read_qza("/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/SBCB-table.qza")
names(SVs)
#To access the actual data stored within the object, access the data as below:
SVs$data[1:5,1:5] #show first 5 samples and first 5 taxa
We can also look at the unique identifier for this object:
SVs$uuid
We can see the type of artifact:
SVs$type
We can also print the providence; however, it is probably easier to use the q2view tool for a graphical aid in its interpretation.
print_provenance(SVs)
Reading Metadata
If you are using a qiime2 metadata file (outlined here 3), you can use the supplied function read_q2metadata() as below. If using a standard tsv or csv file, you can use read.table(), readr::read_tsv(), or readr::csv().
metadata<-read_q2metadata("/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/SBCB_METADATA_alt3.tsv")
head(metadata) # show top lines of metadata
Reading Taxonomy
Note, when taxonomy is imported, a single string is returned along with a confidence score. For many analysis we will want to break up this string and for that purpose the parse_taxonomy() function is provided:
taxonomy<-read_qza("/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/taxonomy.qza")
head(taxonomy$data)
Creating a Phyloseq Object
A wrapper function called qza_to_phyloseq() is provided which links multiple read_qza() calls together to create a phyloseq object for subsequent analysis as per the phyloseq tutorials 59. An example usage is shown below:
# the issue you have has nothing to do with your taxonomy table, but a mismatch between your metadata and feature table (SVs or your favourite term here for denoised sequences). (https://forum.qiime2.org/t/qiime2r-missing-sample/8681)
# it seems that the phyloseq was not right, because my Sample ID does not match with the colnames in SVs$data
table<-SVs$data
metadata$SampleID <- colnames(table)
all(metadata$SampleID %in% colnames(table)) # has to be true.
write.csv(metadata, file = "metadata_try.csv")
# and then I copied and pasted the SampleID in this csv to googlesheet my metadata, and downloaded as a new metadata for the qza_to_phyloseq to read.
physeq<-qza_to_phyloseq(
features="/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/SBCB-table.qza",
tree="/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/SBCB-rooted_tree.qza",
"/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/taxonomy.qza",
metadata = "/Users/Cheng.Clay.Li/EAGCB/SBdata/Qiime2SBCB/SBCB_METADATA_rename.tsv"
)
physeq
# the taxatable looks so werid.
library(phyloseq)
Taxtab.q2 <- as(tax_table(physeq), "matrix")
OTU.q2 = as(otu_table(physeq), "matrix")
write.csv(Taxtab.q2, file = "taxtab_q2.csv")
write.csv(OTU.q2, file = "OTU_q2.csv")
SBCB_METADATA.tsv (1.7 KB) SBCB-rooted_tree.qza (272.5 KB) SBCB-table.qza (241.3 KB) taxonomy.qza (353.2 KB) OTU_q2.csv (516.0 KB) taxtab_q2.csv (1.1 MB)