0

我有一个名为“共享”的 phyloseq 对象

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

基本上,我想要这个维恩图绿色部分的 phyloseq 对象。

维恩图

我从“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
4

1 回答 1

0

假设存在称为 1 和 2 的 OTU 1,但只有第一个出现在样本组 BL 和 SC 中。然后您可以创建一个 phyloseq 对象,该对象仅包含选定的 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 ]

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

于 2021-12-16T10:17:57.427 回答