0

我根据表型特征做了一棵树,例如:species1 2102102 species2 1101210,其中数字是特征的表示。我计算了汉明距离,然后将它们归一化。接下来,我创建了一个 NJ 树,然后使用了这个函数:https://augix.github.io/wiki/Make%20trees%20in%20R,%20test%20its%20stability%20by%20bootstrapping.html 这是输出:新泽西树 在此处输入图像描述

现在我想使用ggtree,但我不知道如何根据我的距离将这些引导值添加到正常的 NJ 树中。boot.tree问题是当函数的输出只有 9 个数字时,有 20 个节点。代码:

#creating tree from matrix of normalized hamming distances
 seed_NJ <-NJ(final_matrix2)
 plot(seed_NJ, main="Neighbor Joining")

#https://augix.github.io/wiki/Make%20trees%20in%20R,%20test%20its%20stability%20by%20bootstrapping.html
 boot.tree <- function(data, B = 10000, tree = "upgma") {
   func <- function(x) upgma(dist(x, method = "euclidean"), method="average")
   if (tree == "nj") {
     func <- function(x) nj(dist(x, method = "euclidean"))
   }
   if (tree == "hclust") {
     func <- function(x) {
       tr = hclust(dist(x, method = "euclidean"))
       tr = as.phylo(tr)
       return(tr)
     }
   }
   tr_real = func(data)
   plot(tr_real)
   library(ape)
   bp <- boot.phylo(tr_real, data, FUN=func, B=B)
   bp <- bp/B
   bp <-round(bp, digits=2)
   bp <- bp*100
   nodelabels(bp)
   print(bp)
   return(bp)
 }
 data = (final_matrix2)
#bootstrap
my_tree <- boot.tree(data, tree='nj')
#trying to add bootstrap here, but the number of nodes is 20, while I have 9 bootstrap values
library(ggtree)
plottree <- ggtree(seed_NJ) + theme_tree2()+ geom_tiplab(size=3, color="purple")+ geom_text(aes(label=node), hjust=-.3)
4

0 回答 0