r-如何对phyloseq对象进行子集划分,以显示来自两个样本类型的重叠ASV



我有一个名为";共享的";

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对象。

基本上,我想要一个维恩图中绿色部分的类星体。

维恩图。

我根据";MicEco";

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

让OTU 1被称为1和2,但只有第一个出现在BL和SC两个样本组中。然后你可以创建一个只包含所选OTU及其在所有样本中丰度的phyloseq对象,如下所示:

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 ]

创建于2021-12-16由reprex包(v2.0.1(

最新更新