phyloseq 到 csv,并选择行和列?

问题描述 投票:0回答:1

对于 r 包 SRS 的输入,我需要一个 csv 文件,其中每列都是样本,行是分类单元。我已经能够使用 psmelt 做出类似的输出,但它包含所有元数据,并且分类单元不在行中。

glom <- tax_glom(ps, taxrank='genus')

otus <- tax_table(glom)

dataexport <- psmelt(glom)

这些导出中的另一个问题是每个域、门等都有一个带有值的列,而 SRS 希望域、门等在一列中作为分类单元名称。

有谁知道如何从 phyloseq 对象中选择您想要的行和列?或者如何将所有分类单元融合成一串?

非常感谢。

ps

otu_table()   OTU Table:         [ 4282 taxa and 172 samples ]
sample_data() Sample Data:       [ 172 samples by 5 sample variables ]
tax_table()   Taxonomy Table:    [ 4282 taxa by 7 taxonomic ranks ]
refseq()      DNAStringSet:      [ 4282 reference sequences ]```
r export-to-csv phyloseq
1个回答
0
投票

从文档中,SRS 输入:

数据框(物种计数或OTU表),其中列是样本 行是物种或 OTU 的计数。仅接受整数 作为数据。

我的猜测是使用

abundances(ps)
来获取所需的格式,例如使用示例“dietswap”数据集:

# BiocManager::install("microbiome")
library(microbiome)
#> 
#>  Copyright (C) 2011-2022 Leo Lahti, 
#>     Sudarshan Shetty et al.
#> 
#> Attaching package: 'microbiome'
#> The following object is masked from 'package:ggplot2':
#> 
#>     alpha
#> The following object is masked from 'package:base':
#> 
#>     transform

data(dietswap)
ps <- dietswap
df <- as.data.frame(abundances(ps))
df
#>                                       Sample-1 Sample-2 Sample-3 Sample-4
#> Actinomycetaceae                             0        1        0        1
#> Aerococcus                                   0        0        0        0
#> Aeromonas                                    0        0        0        0
#> Akkermansia                                 18       97       67      256
#> Alcaligenes faecalis et rel.                 1        2        3        2
#> Allistipes et rel.                         336       63       36       96
#> Anaerobiospirillum                           0        0        0        0
#> Anaerofustis                                 0        1        0        0
#> Anaerostipes caccae et rel.                244      137       27       36
#> Anaerotruncus colihominis et rel.           12      108      203       68
#> Anaerovorax odorimutans et rel.              6       73       30       60
#> ...
#> Xanthomonadaceae                             1        1        1        3
#> Yersinia et rel.                             2        2        3        5

write.csv(df, "ps_abundances.csv")

创建于 2024-01-18,使用 reprex v2.1.0

这能解决你的问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.