[英]Error while rooting a parsimony-based tree in R (ape library)
我正在使用最大簡約算法(ape 庫中的 pratchet())在 R 中執行引導程序分析。 當我對無根樹(使用 pratchet() 函數生成)運行分析時,引導運行正常。 但是,當我想在找到引導程序支持之前對每個引導樹進行 root 時,我在 100 棵樹中的任何一棵樹上隨機生根時都會出錯。 請注意,這是在調用任何用於計算雙分區或進化枝支持的代碼之前發生的。
如果我使用鄰居加入算法(ape 中的 nj()),則在生根或下游引導中都沒有問題,但顯然它在使用外群生根基於簡約的樹時(隨機)發生。 我觀察到的奇怪的事情是,如果我在生根之前將無根樹寫入文件(以防在生根時發生錯誤),然后想要將它們生根,它就可以正常工作。
這是代碼,我用於分析。
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)
}
這是堆棧跟蹤和錯誤
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
我對“根”函數感到沮喪,因此編輯了 ape 源代碼以創建一個函數,該函數可以根植樹而不會引發錯誤。 它作為函數RootTree()
包含在包“TreeTools”中,它還實現了一些其他用於設置根的選項。
使用以下命令將其安裝到 R:
install.packages('TreeTools')
RootTree(tree, outgroup)
恐怕它不支持邊長。
看看 phangorn 中函數 bootstrap.phyDat 和 plotBS 的例子,應該可以簡化你的函數。 此外,您不需要根植單個引導樹,只需根植您要繪制的樹即可。 這應該可以解決您的問題。
問候克勞斯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.