Friday, July 5, 2019

Re-rooting a tree along all edges

This morning I received the following message:

“I am trying to write a program that reroots a phylogenetic tree at every edge(branch) of the tree and saves each rerooted tree. I am using reroot under phytools. When I run for a single specified branch I am able to get a rerooted tree but when I run for all branches in a tree, I am getting… (Ed. an error).”

I'm not sure the user ran into difficulties, but the following is a simple function to re-root a tree along all edges that uses phytools::reroot internally:

    if(unroot) tree<-unroot(tree)
    } else edge.lengths<-TRUE
    for(i in 1:nrow(tree$edge)){
        if(!edge.lengths) trees[[i]]$edge.length<-NULL

Let's try it:

## Loading required package: ape
## Loading required package: maps
## 49 phylogenetic trees

plot of chunk unnamed-chunk-2

It works!

Thursday, June 27, 2019

Some of the updates in the new CRAN version of phytools (0.6-99)

I recently put a new version of phytools on CRAN (phytools 0.6-99).

The last CRAN phytools release was 28 September 2018, so naturally there were quite a few updates.

The following is a non-comprehensive list:

  1. An update to the function dotTree to include column labels.

  2. A totally new function fitmultiMk to fit a multi-rate Mk model to discrete character data on the tree (here).

  3. The MCCR test for Pybus & Harvey's γ statistic when taxon sampling is incomplete (1, 2). This used to be in Dan Rabosky's package laser, but since laser is no longer available I thought I'd implement it in phytools.

  4. Another totally new function, fitpolyMk, to fit an Mk model to discrete character data with polymorphism.

  5. A new S3 plot method for fitpolyMk.

  6. A new function for phylogenetic imputation with multivariate continuous trait data (phylo.impute).

  7. An update to to permit more than one observation per tip in the tree. (Also see: 1, 2, 3).

  8. A simple user-requested update to fancyTree for type="extinction" (here).

  9. A small fix to the function plotTree.wBars for fan-style trees.

  10. Various updates to the phytools function mcmcMk for Bayesian MCMC analysis of the Mk model of evolution for discete character traits.

  11. A new multi2di registered S3 method for the "simmap" object class (as well as di2multi and multi2di methods for other object classes too - such as "contMap" and "densityMap" object: here).

  12. Several new S3 methods for the "evol.rate.mcmc" object class.

  13. Updates to the 'phylogenetic scatterplot matrix' method of fancyTree (and also separation of the method to its own function: phyloScattergram).

  14. Some useful updates & fixes to the function geo.legend, as well as an entirely new function, geo.palette. (Also here.)

  15. Various updates to ltt95.

  16. Finally, a small but non-trivial update to cophylo to permit co-phylogenetic plotting when one or both trees have duplicate tip labels.

For all updates, check out a complete list of commits on the phytools GitHub page. This list is long & include lots of things that haven't been mentioned above, such as new object classes and methods.

Here's an example of plotting species distributions with a "" object:

## Object of class "" containing:
## (1) A phylogenetic tree with 8 tips and 7 internal nodes.
## (2) A geographic map with range:
##      -33.75N, 5.27N
##      -74.01W, -29.36W.
## (3) A table containing 65 geographic coordinates (may include
##     more than one set per species).
## If optimized, tree nodes have been rotated to maximize alignment
## with the map when the tree is plotted in a rightwards direction.
for(i in 1:Ntip(obj$tree)){

plot of chunk unnamed-chunk-1