微生物组数据分析利器——Phyloseq学习笔记(二)

微生物组 微生物组 676 人阅读 | 1 人回复 | 2024-05-22

去除宿主及按分类水平汇总特征表

本次使用到的包

library(phyloseq)
library(tidyverse)

剔除OTU表中的叶绿体、线粒体及未注释到的OTU,只保留细菌界

physeq <-physeq %>%
  phyloseq::subset_taxa(Order != "Chloroplast") %>%
  phyloseq::subset_taxa(Family != "Mitochondria") %>%
  phyloseq::subset_taxa(Kingdom == "Bacteria") %>%
  phyloseq::subset_taxa(Phylum != "Unclassified ")

# 剔除前
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 10992 taxa and 120 samples ]
sample_data() Sample Data:       [ 120 samples by 6 sample variables ]
tax_table()   Taxonomy Table:    [ 10992 taxa by 7 taxonomic ranks ]
refseq()      DNAStringSet:      [ 10992 reference sequences ]

# 剔除后
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 10978 taxa and 120 samples ]
sample_data() Sample Data:       [ 120 samples by 6 sample variables ]
tax_table()   Taxonomy Table:    [ 10978 taxa by 7 taxonomic ranks ]
refseq()      DNAStringSet:      [ 10978 reference sequences ]我们

为方便后续分析,首先根据注释信息汇总不同分类水平的OTU表。 以界为例:

ps_tax_Kingdom <- physeq %>% 
  tax_glom(taxrank=rank_names(physeq)[1]) 

tax_table(ps_tax_Kingdom)

Taxonomy Table:     [1 taxa by 7 taxonomic ranks]:
      Kingdom    Phylum Class Order Family Genus Species
ASV_1 "Bacteria" NA     NA    NA    NA     NA    NA

此时相当于将所有OTU加在一起,注释信息中仅剩“Bacteria”一个物种。 以此类比,将门至属水平的OTU表分别进行汇总。

for (i in 2:6) {
  var_name <- paste0("ps_tax_", i)
  assign(var_name, tax_glom(physeq, taxrank = rank_names(physeq)[i]))
}
# 此处计算需要一些时间

运行结束后即可获得不同分类水平的文件

微信扫一扫分享文章

+10
无需登陆也可“点赞”支持作者
分享到:
评论

使用道具 举报

评论|共 1 个

admin

发表于 2024-5-23 15:03:10 | 显示全部楼层

也太厉害了
3 积分
3 主题
+ 关注
热门推荐