I would like to use the cutree () function to group a phylogenetic tree into a specific number of treasures. However, the phylo object (non-rooted phylogenetic tree) is not critical and thus returns an error when using as.hclust.phylo (). The goal is to pick up the tips of the tree, while preserving the maximum variety, therefore, the desire to cluster a certain number of treasures (and then randomly select one from each treasure). This will be done for several trees with varying numbers of desired patterns. Any help would be gratefully accepted in forcing a tree, not connected with the root, into an hclust object, or a proposal for another method for the systematic collapse of trees (filo objects) into a predetermined number of treasures.
library("ape")
library("ade4")
tree <- rtree(n = 32)
tree.hclust <- as.hclust.phylo(tree)
Returns: "Error in as.hclust.phylo (tree): the tree is not ultrametric"
If I make a matrix of distances between shoulder lengths between all nodes, I can use hclust to generate clusters, and then cutree to the desired number of clusters:
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)
However, the results are undesirable because very basal branches are grouped together. It would be more desirable to use clustering on a tree structure or the distance from the top to the root.
Any suggestions are welcome!
source
share