Closed ixxmu closed 1 month ago
❝本节来介绍如何使用qiime2R包整合qiime2分析结果并将qza格式导出,使用起来非常的方便。数据来源为qiime2R官方数据,仅做过程展示使用整个过程仅供参考,更多详细内容请参考官方文档
❝https://github.com/jbisanz/qiime2R?tab=readme-ov-file
library(tidyverse)
library(phyloseq)
install.packages("remotes")
remotes::install_github("jbisanz/qiime2R",force = T)
library(qiime2R)
library(ape)
library(vegan)
download.file("https://docs.qiime2.org/2018.4/data/tutorials/moving-pictures/table.qza", "table.qza")
download.file("https://docs.qiime2.org/2018.4/data/tutorials/moving-pictures/rooted-tree.qza", "rooted-tree.qza")
download.file("https://docs.qiime2.org/2018.4/data/tutorials/moving-pictures/taxonomy.qza", "taxonomy.qza")
download.file("https://data.qiime2.org/2018.4/tutorials/moving-pictures/sample_metadata.tsv", "sample_metadata.tsv")
physeq <- qza_to_phyloseq(
features="table.qza",
tree="rooted-tree.qza",
taxonomy="taxonomy.qza",
metadata = "sample_metadata.tsv")
> physeq
phyloseq-class experiment-level object
otu_table() OTU Table: [ 759 taxa and 34 samples ]
sample_data() Sample Data: [ 34 samples by 10 sample variables ]
tax_table() Taxonomy Table: [ 759 taxa by 7 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 759 tips and 757 internal nodes ]
由于qiime2生成的一般为qza格式,实际使用过程中将其导出为文本文件则比较直观
# 导出丰度表
qiime2R::read_qza("table.qza")$data %>%
as.data.frame() %>%
write.table(file="asv_data.tsv",row.names = T,col.names = NA,sep="\t",quote = F)
# 导出注释表
qiime2R::read_qza("taxonomy.qza")$data %>%
qiime2R::parse_taxonomy() %>%
write.table(file="taxonomy.tsv",row.names = T,col.names = NA,sep="\t",quote = F)
# 导出树文件
tmp_tre <- qiime2R::read_qza("rooted-tree.qza")$data %>%
ape::multi2di()
write.tree(tmp_tre,"rooted_tree.nwk")
asv <- read_tsv("asv_data.tsv") %>% column_to_rownames(var="...1")
colSums(asv)
#抽平并把结果赋值给“asv_Flattening”
asv_Flattening <- as.data.frame(t(rrarefy(t(asv),min(colSums(asv)))))
colSums(asv_Flattening)
write.table(asv_Flattening, file="asv_Results.tsv",row.names =TRUE,sep="\t",quote = F,col.names = NA)
❝实际数据分析中很少使用phyloseq对象,通常使用较为广泛的还是本地文本文件,有了丰度表+注释表+树文件后期就可使用ggplot2及其对应扩展包来自定义进行下游的数据分析。
❝本节介绍到此结束,有需要学习R数据可视化的朋友,欢迎到淘宝店铺:R语言数据分析指南,购买小编的R语言可视化文档(2024版),购买将赠送2023年的绘图文档内容。目前(2023+2024)已经更新上传约200案例内容,每个案例都附有相应的数据和代码,2024年更新的绘图内容会在交流群内同步更新。
2024更新的绘图内容将同时包含数据+代码+注释文档+文档清单,小编只分享案例文档,不额外回答问题,无答疑服务。 注:2023文档无清单文件
https://mp.weixin.qq.com/s/ogzFvkazVy3SR2iWnUeZDw