查看原文
其他

如何构造ggClusterNet需要的phyloseq对象

文涛聊科研 微生信生物 2023-08-18

写在前面

使用正常otu表格,注释文件和map分组文件可以构建phyloseq对象。这里我们给出一个例子,这些文件在下面服务器上都有备份,并且在微生信生物公众号下面回复:数据,也都可以得到。大家只需要有这几张表格即可形成phyloseq对象。

基础理解

phyloseq其实就是封装了三个数据,然后他们共荣辱,一个变化,一起变化,otu表格和物种注释文件都是需要将数据框转化为矩阵作为输入,而map文件直接是数据框即可。

# 从文件读取
metadata = read.table("http://210.75.224.110/github/EasyAmplicon/data/metadata.tsv", header=T, row.names=1, sep="\t", comment.char="", stringsAsFactors = F)
otutab = read.table("http://210.75.224.110/github/EasyAmplicon/data/otutab.txt", header=T, row.names=1, sep="\t", comment.char="", stringsAsFactors = F)
taxonomy = read.table("http://210.75.224.110/github/EasyAmplicon/data/taxonomy.txt", header=T, row.names=1, sep="\t", comment.char="", stringsAsFactors = F)

# 提取两个表中共有的ID
# Extract only those ID in common between the two tables
idx = rownames(otutab) %in% rownames(taxonomy)
otutab = otutab[idx,]
taxonomy = taxonomy[rownames(otutab),]

# 使用amplicon包内置数据
# data("metadata")
# data(otutab)

# 导入phyloseq(ps)对象
ps = phyloseq(sample_data(metadata),otu_table(as.matrix(otutab), taxa_are_rows=TRUE), tax_table(as.matrix(taxonomy)))


添加主编微信 加入群聊

关于微生信生物 你想要的都在这里


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存