我想使用 cutree() 函数将系统发育树聚类成指定数量的进化枝。然而,phylo 对象(一个无根的系统发育树)不是 unltrametric 的,因此在使用 as.hclust.phylo() 时会返回错误。目标是在保持最大多样性的同时对树的尖端进行子采样,因此希望通过指定数量的进化枝进行聚类(然后从每个进化枝中随机采样一个)。这将针对具有不同数量的所需样本的许多树完成。将无根树强制转换为 hclust 对象的任何帮助,或关于将树(phylo 对象)系统地折叠为预定义数量的进化枝的不同方法的建议将不胜感激。
library("ape")
library("ade4")
tree <- rtree(n = 32)
tree.hclust <- as.hclust.phylo(tree)
返回:“as.hclust.phylo(tree) 中的错误:树不是超度量的”
如果我制作所有节点之间的分支长度的距离矩阵,我可以使用 hclust 生成集群,然后将 cutree 转换为所需数量的集群:
dm <- cophenetic.phylo(tree)
single <- hclust(as.dist(dm), method="single")
cutSingle <- as.data.frame(cutree(single, k=10))
color <- cutSingle[match(tree$tip.label, rownames(cutSingle)), 'cutree(single, k = 10)']
plot.phylo(tree, tip.color=color)
然而,结果并不理想,因为非常基础的分支聚集在一起。基于树结构的聚类,或者从尖端到根的距离将是更可取的。
任何建议表示赞赏!