简体   繁体   English

在 R(ape 库)中根植基于简约的树时出错

[英]Error while rooting a parsimony-based tree in R (ape library)

I am performing bootstrap analysis in R using maximum parsimony algorithm (pratchet() in ape library).我正在使用最大简约算法(ape 库中的 pratchet())在 R 中执行引导程序分析。 When I run the analysis on unrooted trees (produced using pratchet() function), the bootstrapping runs fine.当我对无根树(使用 pratchet() 函数生成)运行分析时,引导运行正常。 But when I want to root each bootstrapped tree before finding bootstrap support, I get error in rooting randomely at any of 100 trees.但是,当我想在找到引导程序支持之前对每个引导树进行 root 时,我在 100 棵树中的任何一棵树上随机生根时都会出错。 Note that this occurs before calling any code for computing bipartitions or clade support.请注意,这是在调用任何用于计算双分区或进化枝支持的代码之前发生的。

If I use neighbor joining algorithm (nj() in ape), there is no problem in rooting at all or in downstream bootstrapping, but apparently it occurs (randomly) while rooting parsimony-based trees using an outgroup.如果我使用邻居加入算法(ape 中的 nj()),则在生根或下游引导中都没有问题,但显然它在使用外群生根基于简约的树时(随机)发生。 The strange thing I observed is that if I write the unrooted trees to file before rooting them (in case error occurs while rooting) and later want to root them, it works perfectly fine.我观察到的奇怪的事情是,如果我在生根之前将无根树写入文件(以防在生根时发生错误),然后想要将它们生根,它就可以正常工作。

Here is the code, I am using for analysis.这是代码,我用于分析。

performBootstraping = function(charMatrix, bsIterations) {
    # charMatrix is a DNA alignment matrix
    # bsIteration are number of bootstrap iterations.

    library(phangorn)

    phySeq = phyDat(charMatrix)

    treeMPRooted = getRootedParsimonyTree(charMatrix)

    bValuesMP = boot.phylo(treeMPRooted, charMatrix, FUN=function(xx) {tt = getRootedParsimonyTree(xx); return(tt) }, 
    B = bsIterations, trees=T, rooted=T)

   # convert to percentage
   bValues = bValuesMP$BP/bsIterations * 100;

   plot(treeMPRooted, use.edge.length = F); 
   title('Max Parsimony tree with bootstrap percentage')
    nodelabels(bValues, frame = 'rect')

    # write the tree as newick 
    write.tree(treeMPRooted, paste0(outDir,'/rooted_MP.tree'))
    return(bValuesMP)
}

getRootedParsimonyTree = function(cMatrix) {
    phySeq = phyDat(cMatrix);
    treeMP = pratchet(phySeq)
    treeMPRooted = root(treeMP, outgroup='Germline', resolve.root=T)

    return(treeMPRooted)
}

Here is the stack trace and the error这是堆栈跟踪和错误

 Error in phy$edge[sndcol, 2] <- newNb[phy$edge[sndcol, 2]] <- n + 2:phy$Nnode : 
  number of items to replace is not a multiple of replacement length 
6 root(treeMP, outgroup = "Germline", resolve.root = T) at libaryFunctions.R#105
5 getRootedParsimonyTree(xx) at libaryFunctions.R#32
4 FUN(x[, boot.samp]) 
3 boot.phylo(treeMPRooted, t.vaf, FUN = function(xx) {
    tt = getRootedParsimonyTree(xx)
    return(tt)
}, B = bstrapCount, trees = T, rooted = T) at libaryFunctions.R#32
2 performBootstraping(vaf, outDir, i, bsIterations) at runAllSitesBootstrapForAllPatients.R#15
1 runAllSitesBootstrapForAllPatients(ccfFileDir = ccfDir, outDirPref = outDir) 
In addition: Warning message:
In newNb[phy$edge[sndcol, 2]] <- n + 2:phy$Nnode :
  number of items to replace is not a multiple of replacement length

I got frustrated with the 'root' function so edited the ape source code to create a function that roots a tree without throwing errors.我对“根”函数感到沮丧,因此编辑了 ape 源代码以创建一个函数,该函数可以根植树而不会引发错误。 It's included in the package 'TreeTools' as functionRootTree() , which also implements a few other options for setting the root.它作为函数RootTree()包含在包“TreeTools”中,它还实现了一些其他用于设置根的选项。

Install it to R using:使用以下命令将其安装到 R:

install.packages('TreeTools')
RootTree(tree, outgroup)

It doesn't support edge lengths, I'm afraid.恐怕它不支持边长。

look at the examples of the function bootstrap.phyDat and plotBS in phangorn, should simplify your function.看看 phangorn 中函数 bootstrap.phyDat 和 plotBS 的例子,应该可以简化你的函数。 Furthermore you don't need to root the individual bootstrap trees, just the tree you want to draw.此外,您不需要根植单个引导树,只需根植您要绘制的树即可。 This should solve your problem.这应该可以解决您的问题。

Regards Klaus问候克劳斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM