微生物多样性qiime2分析流程(8) phyloseq整合已有OTU数据进行分析

前面一系列文章介绍了如何通过qiime2处理原始数据,进行聚类注释及可视化分析,但是现实中小伙伴们已经得到了处理好的OTU表及注释文件,那怎么基于此来进行后续分析呢?由于qiime2提供的是.qza的压缩文件,而我们手中的是文本文件,那就需要进行格式转换及整合,最终转化成phyloseq对象.

这次我们通过phyloseq包来转化格式

1.安装phyloseq

注:目前所安装包均基于R 4.0 (请及时更新R版本)

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("phyloseq")

2. 处理OTU表格式

le otu_taxa.table.xls|sed 's/ //g'| \
awk 'BEGIN{OFS=FS="\t"}{print $1,$NF}'|sed '1d'| \
sed '1i OTU,domain,phylum,class,order,family,genus,species'| \
sed 's/,/\t/g'|sed 's/;/\t/g' |sed 's/[a-z]__//g'> otu_taxa.xls

le otu_taxa_table.xls|awk 'BEGIN{OFS=FS="\t"};NF{NF-=1};1' > otu_table.xls

注:otu_taxa.table.xls 中包含OTU丰度信息及注释信息
通过以上处理得到了OTU表及OTU注释信息,接下来让我们通过phyloseq包将其与样本信息整合。

3. phyloseq整合数据

pacman::p_load(tidyverse,phyloseq,MicrobiotaProcess,ape)
otu_mat <- read.delim2("otu_table.xls",header=T,
                       sep="\t",check.names = F,row.names = 1) %>% as.matrix()
tax_mat <- read.delim("otu_taxa.xls",header=T,row.names = 1,
                      sep="\t",check.names = F) %>% as.matrix()
samples_df <- read.delim("group.txt",header = T,
                         sep="\t",check.names = F,row.names = 1)
tree <- read.tree("rep_set.tre")

OTU = otu_table(otu_mat, taxa_are_rows =T)
TAX = tax_table(tax_mat)
samples = sample_data(samples_df)

ps <- phyloseq(OTU, TAX, samples,tree)
ps
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 3365 taxa and 41 samples ]
sample_data() Sample Data:       [ 41 samples by 2 sample variables ]
tax_table()   Taxonomy Table:    [ 3365 taxa by 7 taxonomic ranks ]
phy_tree()    Phylogenetic Tree: [ 3365 tips and 3363 internal nodes ]

经过以上处理我们就得到了可直接用于可视化分析的数据,之后参考可视化教程对其直接进行分析

4. 基础可视化操作

phytax <- get_taxadf(obj=ps, taxlevel=2)
phybar <- ggbartax(obj=phytax,facetNames="Group", count=FALSE) +
  xlab(NULL) + ylab("relative abundance (%)")+
  theme(axis.text.x=element_text(face="plain",
                                 color="black",hjust=0.8,vjust=0.6,
                                 size=9, angle=90))+
  theme(strip.text.x = element_text(size=8, color="black",
                                    face="plain"))+
  theme(legend.position="right")
phybar

bar.jpeg

参考:https://vaulot.github.io/tutorials/Phyloseq_tutorial.html

你可能感兴趣的:(微生物多样性qiime2分析流程(8) phyloseq整合已有OTU数据进行分析)