如何附加集群的引导值';在R中使用NEWICK格式的s(树)节点

如何附加集群的引导值';在R中使用NEWICK格式的s(树)节点,r,tree,cluster-analysis,dendrogram,pvclust,R,Tree,Cluster Analysis,Dendrogram,Pvclust,我想使用(iTOL)创建一个树(集群)。该工具使用的输入文件(或字符串)是一种使用括号和逗号表示边长度的图论树的方法。除此之外,还可能支持其他信息,例如集群节点的引导值 例如,在这里,我使用clusterGenerationpackage为聚类分析创建了数据集: library(clusterGeneration) set.seed(1) tmp1 <- genRandomClust(numClust=3, sepVal=0.3, numNonNoisy=5, nu

我想使用(iTOL)创建一个树(集群)。该工具使用的输入文件(或字符串)是一种使用括号和逗号表示边长度的图论树的方法。除此之外,还可能支持其他信息,例如集群节点的引导值

例如,在这里,我使用
clusterGeneration
package为聚类分析创建了数据集:

library(clusterGeneration)
set.seed(1)    
tmp1 <- genRandomClust(numClust=3, sepVal=0.3, numNonNoisy=5,
        numNoisy=3, numOutlier=5, numReplicate=2, fileName="chk1")
data <- tmp1$datList[[2]]
set.seed(2)    
y <- pvclust(data=data,method.hclust="average",method.dist="correlation",nboot=100)
plot(y)  
library(ape)
yy<-as.phylo(y$hclust)
write.tree(yy,digits=2)
以下是集群和引导值:

为了制作一个Newick文件,我使用了
ape
package:

library(clusterGeneration)
set.seed(1)    
tmp1 <- genRandomClust(numClust=3, sepVal=0.3, numNonNoisy=5,
        numNoisy=3, numOutlier=5, numReplicate=2, fileName="chk1")
data <- tmp1$datList[[2]]
set.seed(2)    
y <- pvclust(data=data,method.hclust="average",method.dist="correlation",nboot=100)
plot(y)  
library(ape)
yy<-as.phylo(y$hclust)
write.tree(yy,digits=2)
用于形成Newick文件的分支长度可通过以下方式获得:

yy$edge.length
我试着找出
write.tree
函数在调试后是如何工作的。然而,我注意到它在内部调用函数
.write.tree2
,我不知道如何有效地更改原始代码并在Newick文件的适当位置获取引导值


欢迎您提出任何建议。

这里有一个解决方案:类
phylo
的对象有一个名为
node的可用插槽。label
适当地为您提供节点的标签。您可以使用它来存储引导值。将在您的Newick文件中的适当位置写入,如您在
的代码中所见。write.tree2

> .write.tree2
function (phy, digits = 10, tree.prefix = "") 
{
    brl <- !is.null(phy$edge.length)
    nodelab <- !is.null(phy$node.label)

...

    if (is.null(phy$root.edge)) {
        cp(")")
        if (nodelab) 
            cp(phy$node.label[1])
        cp(";")
    }
    else {
        cp(")")
        if (nodelab) 
            cp(phy$node.label[1])
        cp(":")
        cp(sprintf(f.d, phy$root.edge))
        cp(";")
    }

...
这意味着我们可以使用
nodenames
参数将自己的
设置为.phylo.hclust
,只要它与
hclust
对象中的节点顺序相同(在您的示例中就是这种情况,因为
pvclust
在内部保持一致的顺序,即hclust中节点的顺序与您在其中拾取引导的表中的顺序相同):

#注意:在下面的函数定义中,我只修改了注释行

as.phylo.hclust.with.nodenames非常感谢您快速而详细的回答!!!干得好!我会尽快在我自己的集群上尝试。
bootstraps <- (round(y$edges,2)*100)[,1:2]
yy<-as.phylo.hclust.with.nodenames(y$hclust, nodenames=bootstraps[,2])
write.tree(yy,tree.names=TRUE,digits=2)
[1] "((x5:0.27,x8:0.27)100:0.24,((x7:0.25,(x4:0.14,(x1:0.13,x3:0.13)61:0.014)99:0.11)100:0.23,(x2:0.46,x6:0.46)56:0.022)61:0.027)100;"
#See the bootstraps    ^^^ here for instance
plot(yy,show.node.label=TRUE) #To show that the order is correct
plot(y) #To compare with (here I used the yellow value)