Saturday, December 12, 2015

Apparent bug in the important ape function root

Here is a quick demo of an apparent bug in the ape function root. The bug seems to affect the branch lengths of the rerooted tree. (Specifically, one of the branch lengths is too long!)

This may affect any function in phytools that uses root internally, such as fastAnc and functions that depend on fastAnc.

library(ape)
tree<-read.tree(text="((A:1,B:1):1,C:1);")
plot(tree,type="unrooted")

plot of chunk unnamed-chunk-1

unroot(tree)$edge.length
## [1] 1 1 2
rerooted<-root(tree,node=5)
plot(rerooted,type="unrooted")

plot of chunk unnamed-chunk-1

unroot(rerooted)$edge.length
## [1] 1 1 3
packageVersion("ape")
## [1] '3.4'
sessionInfo()
## R version 3.2.2 (2015-08-14)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 8 x64 (build 9200)
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ape_3.4    knitr_1.11
## 
## loaded via a namespace (and not attached):
## [1] magrittr_1.5    tools_3.2.2     stringi_1.0-1   nlme_3.1-122   
## [5] grid_3.2.2      stringr_1.0.0   lattice_0.20-33 evaluate_0.8

1 comment:

  1. This bug cannot be reproduced with ape 3.1.4 on my laptop. Most probably it appeared in a release between 3.1.4 and 3.4.

    ReplyDelete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.