Recently, a phytools user correctly reported a
bug
in the phytools function reroot
to re-root a tree along an
edge when the input tree contained node labels. I thought I had identified
it's cause and fixed it (details
here).
Specifically, the problem is caused by the fact that the function
drop.tip(...,trim.internal=FALSE)
will leave behind
"NA"
as a tip label for the trimmed clade when node
labels are absent; however it will instead use the node labels if
they are present. I fixed the (primarily internal) phytools function
splitTree
for this issue; however I failed to realize
that I also needed to update the function
drop.clade
.
I have now done this and posted the updated code
here.
Let's try it with the old version & the new one:
library(phytools)
set.seed(1) ## set seed for reproducibility
tree<-rtree(n=26)
tree$tip.label<-LETTERS
plotTree(tree)
node<-37
position=0.5*tree$edge.length[which(tree$edge[,2]==node)]
plotTree(reroot(tree,node,position)) ## works fine
## now try with node labels
tree$node.label<-paste("n",1:tree$Nnode,sep="")
rerooted.tree<-reroot(tree,node,position) ## breaks
## Error in if (newroot == ROOT) {: argument is of length zero
Now let's update to the latest phytools version (not on CRAN) and re-attempt:
detach("package:phytools",unload=TRUE)
install.packages("phytools_0.4-48.tar.gz",type="source",repos=NULL)
## Installing package into 'C:/Users/Liam/Documents/R/win-library/3.1'
## (as 'lib' is unspecified)
library(phytools)
rerooted.tree<-reroot(tree,node,position)
plotTree(rerooted.tree)
nodelabels(rerooted.tree$node.label)
The most recent working version of phytools can always be downloaded here.
That's it.
No comments:
Post a Comment
Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.