Tuesday, August 13, 2013

New function to strip all the leaves (i.e., tips) off a tree

I today responded to an R-SIG-phylo request for a function that would strip all the leaves (i.e., tips) from a phylogenetic tree - leaving only the internal structure. This can almost be done with drop.tip(...,trim.internal=FALSE); however drop.tip does not allow all tips to be dropped.

I quickly wrote a function that does. Code is here and it is in a new build of phytools (phytools 0.3-22).

Here is a demo of what it does:

> require(phytools)
Loading required package: phytools
> packageVersion("phytools")
[1] ‘0.3.32’
> tree<-pbtree(n=20)
> plotTree(tree,node.numbers=T)
> dt<-drop.leaves(tree)
> plotTree(dt)

No comments:

Post a Comment

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