微生物组数据分析利器——Phyloseq学习笔记(二)
# 去除宿主及按分类水平汇总特征表本次使用到的包
```
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))
tax_table(ps_tax_Kingdom)
Taxonomy Table: :
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)))
}
# 此处计算需要一些时间
```
运行结束后即可获得不同分类水平的文件
也太厉害了
页:
[1]