[英]How to subset phyloseq object to show overlapping ASVs from two sample types
我有一个叫做“共享”的 phyloseq object
phyloseq-class experiment-level object
otu_table() OTU Table: [ 3823 taxa and 64 samples ]
sample_data() Sample Data: [ 64 samples by 17 sample variables ]
tax_table() Taxonomy Table: [ 3823 taxa by 12 taxonomic ranks ]
我正在尝试通过两种样本类型之间共享 ASV 的交互来制作新的 phyoloseq object。
基本上,我想要这个维恩图绿色部分的 phyloseq object。
维恩图。
我从“MicEco”package 制作了这个 plot,但还没有找到从它那里获得兴趣的方法。
library("MicEco")
venn<-ps_venn(shared,"sample_type", quantities = list(type=c("percent","counts"), font = 2), labels = list(cex = 2), col = "black", fill = c("red","yellow","green"))
venn
假设存在称为 1 和 2 的 OTU 1,但只有第一个出现在样本组 BL 和 SC 中。 然后,您可以创建一个 phyloseq object,其中仅包含选定的 OTU 及其在所有样本中的丰度,如下所示:
library(phyloseq)
#> Creating a generic function for 'nrow' from package 'base' in package 'biomformat'
#> Creating a generic function for 'ncol' from package 'base' in package 'biomformat'
#> Creating a generic function for 'rownames' from package 'base' in package 'biomformat'
#> Creating a generic function for 'colnames' from package 'base' in package 'biomformat'
library(tidyverse)
otus <- tribble(
~otu_id, ~s1, ~s2, ~s3,
1, 10, 10, 20,
2, 5, 5, 0
)
samples <- tribble(
~sample_id, ~group,
"s1", "BL",
"s2", "BL",
"s3", "SC"
)
selected_otus <-
otus %>%
pivot_longer(-otu_id, names_to = "sample_id", values_to = "abundance") %>%
left_join(samples) %>%
group_by(otu_id, group) %>%
summarise(abundance = sum(abundance)) %>%
pivot_wider(names_from = group, values_from = abundance) %>%
# must be found in both sample groups
filter(BL > 0 & SC > 0) %>%
pull(otu_id) %>%
unique()
#> Joining, by = "sample_id"
#> `summarise()` has grouped output by 'otu_id'. You can override using the `.groups` argument.
selected_otus
#> [1] 1
phy <- phyloseq(
otus %>%
filter(otu_id %in% selected_otus) %>%
column_to_rownames("otu_id") %>%
otu_table(taxa_are_rows = TRUE),
samples %>%
column_to_rownames("sample_id") %>%
sample_data()
)
phy
#> phyloseq-class experiment-level object
#> otu_table() OTU Table: [ 1 taxa and 3 samples ]
#> sample_data() Sample Data: [ 3 samples by 1 sample variables ]
由代表 package (v2.0.1) 于 2021 年 12 月 16 日创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.