Monday, August 2, 2021

Old & new function to read NEXUS tree file with certain annotation

Recently a phytools user contacted me because he was having difficulty reading a tree with bootstrap values as node labels (saved in NEXUS format from the software RAxML) into R.

The ape function reads in a NEXUS tree file, but doesn't handle node annotation.

The phytools function read.simmap can read in a particular type of annotation created by the software SIMMAP.

The packages ips and treeio also read in specially formatted tree files, but I've forgotten how to use them, and so I wasn't able to help him get these to work.

I did suddenly remember that I'd written some code many* years ago (not kidding – 8 years, if you can believe it) to try and read a MrBayes annotated tree in NEXUS format from file. I never finished that code, but realized that I could re-purpose it to read in our RAxML tree.

I just added this to phytools in the form of readNexus. Let's give it a try using the phytools user's originally tree, but with tip labels hidden.

## [1] '0.7.84'

Now let's plot our tree:


plot of chunk unnamed-chunk-3

That's pretty hard to read. Let's first ladderize the tree and the show our bootstrap values using pie-charts instead of numbers. To do that, I will also need to convert my node labels to numeric mode, because they are currently stored as characters.

legend(5,0.35,c("0% bootstrap","100% bootstrap"),

plot of chunk unnamed-chunk-4

That's OK, right?

1 comment:

  1. Thank you Liam!! This labeling issue was driving me nuts. When I first read in my tree file with and tried to plot bootstrap values, R would still plot node labels, but they didn't correspond to any numbers I could find in my nexus file. Any idea where it was pulling those numbers from? It's not too important but I was just puzzled, and curious.


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