1
library(tidyverse)
library(ape)
library(phyloseq)

unifrac_unweighted <- UniFrac(tree, weighted = F)

Fehler in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘UniFrac’ for signature ‘"phylo"’
3.
stop(gettextf("unable to find an inherited method for function %s for signature %s", sQuote(fdef@generic), sQuote(cnames)), domain = NA)
2.
(function (classes, fdef, mtable) { methods <- .findInheritedMethods(classes, fdef, mtable) if (length(methods) == 1L) ...
1.
UniFrac(tree_BLS, weighted = T)

树是系统发育树(用 证明class(tree))。我已经尝试重新安装 phyloseq,但它没有帮助。如何避免这个错误?

4

1 回答 1

1

UniFrac函数需要一个phyloseq对象:

physeq: (Required). ‘phyloseq-class’, containing at minimum a
          phylogenetic tree (‘phylo-class’) and contingency table
          (‘otu_table-class’). See examples below for coercions that
          might be necessary

不太确定这对您是否有意义,但不妨考虑以下示例。关键是要正确构造 phyloseq 对象,我不确定的部分是如何构造 otu_table,我设置taxa_are_row=FALSE

#you get a tree
sample_tree = rtree(20,tip.label=letters[1:20])

# there are counts associated with each sample in tree
sample_counts = matrix(rnbinom(100*20,mu=20,size=1),
ncol=20,dimnames=list(1:100,letters[1:20]))

x1 = phyloseq(
otu_table(sample_counts,taxa_are_row=FALSE), 
sample_tree)

UniFrac(x1)
于 2020-04-10T13:47:47.720 回答