Sunday, July 26, 2015

New version of phytools with co-phylogenetic plotting function, ltt methods, and bug-fix for plotSimmap (plus, how to install a source package directly from a URL)

I just posted a new version of phytools (phytools_0.4-61). This version has a few updates over the previous phytools version posted to CRAN - most especially, the addition of the function cophylo for plotting 'co-phylogenetic' trees - that is, trees in which associated tips can be rotated to maximize vertical alignment and then linked. So, for instance, from a recent demo of the function:

library(phytools)
## Loading required package: ape
## Loading required package: maps
packageVersion("phytools")
## [1] '0.4.61'
tr1<-rtree(n=40)
tr2<-rtree(n=26,tip.label=LETTERS)
assoc<-cbind(sample(tr1$tip.label,20),sample(LETTERS,20))
assoc
##       [,1]  [,2]
##  [1,] "t14" "Y" 
##  [2,] "t19" "I" 
##  [3,] "t26" "B" 
##  [4,] "t17" "D" 
##  [5,] "t39" "J" 
##  [6,] "t29" "P" 
##  [7,] "t13" "W" 
##  [8,] "t37" "V" 
##  [9,] "t36" "R" 
## [10,] "t10" "X" 
## [11,] "t1"  "Q" 
## [12,] "t28" "S" 
## [13,] "t3"  "M" 
## [14,] "t23" "K" 
## [15,] "t21" "C" 
## [16,] "t11" "H" 
## [17,] "t33" "U" 
## [18,] "t31" "E" 
## [19,] "t34" "O" 
## [20,] "t25" "G"
obj<-cophylo(tr1,tr2,assoc=assoc,rotate=TRUE)
## Rotating nodes to optimize matching...
## Done.
obj
## Object of class "cophylo" containing:
## 
## (1) 2 (possibly rotated) phylogenetic trees in an object of class "multiPhylo".
## 
## (2) A table of associations between the tips of both trees.
plot(obj)

plot of chunk unnamed-chunk-1

The function also fixes a 'bug' (or arguably, 'feature') of the function plot.ltt which caused plot(obj,log.lineages=FALSE,log="y",show.tree=TRUE) to space the tips of the plotted tree on a log-scale. This is no longer an issue:

tree<-pbtree(n=40,scale=10)
obj<-ltt(tree,plot=FALSE)
plot(obj,log.lineages=FALSE,log="y",show.tree=TRUE)

plot of chunk unnamed-chunk-2

Finally, the function fixes a weird bug in plotSimmap for objects of class "multiPhylo" which was basically due to not all the arguments being correctly passed to internal calls of plotSimmap for all loops corresponding to each tree in the list. This meant that a call of plotSimmap on an object of class "multiPhylo" basically just didn't work.

The updated package can be downloaded from the phytools page and installed from source - or you can just copy & execute the following lines:

detach("package:phytools",unload=TRUE) ## if phytools is loaded
install.packages("http://www.phytools.org/nonstatic/phytools_0.4-61.tar.gz",
    type="source",repos=NULL)
## Installing package into 'C:/Users/Liam/Documents/R/win-library/3.2'
## (as 'lib' is unspecified)

2 comments:

  1. Dear Liam,

    I've been looking for a way to compare two trees while minimizing overlap, so I was glad to see this! I successfully used the cophylo function with two non-ultrametric trees, but when plotting it continues to plot only the horizontal branches of the left tree and then give me this:

    Error in xy.coords(x, y) : 'x' and 'y' lengths differ

    The two trees are made from the same strains so they are identical in tip labels and number of tips (84 tips, 82 nodes). I'm not really sure why it's giving me the error, any idea what might be causing it?

    Thank you,
    Rachel

    ReplyDelete
    Replies
    1. Hi Rachel.

      Thanks for catching this bug. I have addressed it here.

      All the best, Liam

      Delete