Sunday, May 20, 2018

When a phylogeny fails is.binary but is not fixed with multi2di

A phytools user recently posted about an odd case in which a tree read from file failed is.binary, but then after running multi2di still failed. How could this be? Though it seems paradoxical, it isn't. is.binary checks whether all nodes have two & only two descendants. (That is, it checks if all nodes except the root node are of order 3.) multi2di randomly (by default) resolves all multifurcating nodes. If the tree has edge lengths it will do so by adding new internal edges of zero length. What this doesn't consider is the possibility that some nodes (other than the root) may be of order 2: that is, with one & only one descendant. This tree would fail is.binary (because it is not binary - some nodes are unary), but has no polytomies to resolve!

Here is the tree (stripped of its original labels):


It would seem to read & plot fine, as follows:


plot of chunk unnamed-chunk-2

But, as promised, the tree fails is.binary & multi2di fails to resolve this:

## [1] FALSE
## [1] FALSE

As mentioned above, this is due to the presence of singletons: nodes, other than the root, of order 2. We can see the singleton nodes using plotTree.singletons. There are a bunch of them!


plot of chunk unnamed-chunk-4

Fortunately, this too can be resolved using the handy ape function


plot of chunk unnamed-chunk-5

(There's a good chance we don't really want the root edge, in which case we could just set root.edge=FALSE, the default, in the code above.)

Where do all these singleton nodes come from? Since this has come up before, my suspicion is that it is due to some software external to R prunes edges & clades from a tree but leaves intact the original nodes. In fact, this can be emulated using ape::drop.tip(...,, e.g.:


plot of chunk unnamed-chunk-6

That's all.

1 comment:

  1. Hello Liam,

    Thanks a lot for responding my question. I really appreciate the time you took to do it.



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