无法找到签名“"phylo"”的函数“UniFrac”的继承方法

unable to find an inherited method for function ‘UniFrac’ for signature ‘"phylo"’

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)

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

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)