Thursday, November 26, 2015

Getting the matrix for MRP supertree estimation from a set of trees

A phytools user requested the following:

“I am attempting to use your mrp.supertree command to produce an MRP matrix of three cluster dendrograms derived from some morphometric data. Good news is that it works, however I'd like to extract the actual MRP matrix to pass to a colleague to use in a cladistic analysis. Is this possible?”

This was not possible; however it was quite straightforward to pull out the code that performs the computation of the matrix representations of the tree, and this is now part also part of the namespace of phytools.

Here is an extremely quick demo:

library(phytools)
packageVersion("phytools")
## [1] '0.5.7'
tree<-rtree(n=10,tip.label=LETTERS[1:10],root=FALSE)
plot(tree,type="unrooted",no.margin=TRUE,use.edge.length=FALSE,
    edge.width=2,cex=1.2)

plot of chunk unnamed-chunk-1

trees<-list()
for(i in 1:4) trees[[i]]<-drop.tip(tree,sample(tree$tip.label,5))
class(trees)<-"multiPhylo"
print(trees,details=TRUE)
## 4 phylogenetic trees
## tree 1 : 5 tips
## tree 2 : 5 tips
## tree 3 : 5 tips
## tree 4 : 5 tips
mrp.tree<-mrp.supertree(trees)
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## [1] "Best pscore so far: 10"
## The MRP supertree, optimized via pratchet(),
## has a parsimony score of 10 (minimum 10)
plot(mrp.tree,type="unrooted",no.margin=TRUE,use.edge.length=FALSE,
    edge.width=2,cex=1.2)

plot of chunk unnamed-chunk-1

library(phangorn)
RF.dist(drop.tip(tree,setdiff(tree$tip.label,mrp.tree$tip.label)),
    mrp.tree)
## [1] 8

And if we just want the matrix:

obj<-compute.mr(trees)
obj
## 9 sequences with 10 character and 10 different site patterns.
## The states are 0 1
obj<-compute.mr(trees,type="matrix")
obj
##   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## A "1"  "0"  "1"  "1"  "?"  "?"  "?"  "1"  "1"  "0"  
## H "1"  "1"  "?"  "?"  "1"  "1"  "1"  "?"  "?"  "?"  
## I "1"  "1"  "?"  "?"  "1"  "1"  "1"  "?"  "?"  "?"  
## F "0"  "0"  "0"  "0"  "?"  "?"  "?"  "?"  "?"  "?"  
## B "0"  "0"  "0"  "0"  "?"  "?"  "?"  "0"  "0"  "0"  
## D "?"  "?"  "1"  "0"  "?"  "?"  "?"  "1"  "0"  "0"  
## C "?"  "?"  "1"  "1"  "1"  "0"  "0"  "1"  "1"  "1"  
## E "?"  "?"  "?"  "?"  "1"  "1"  "0"  "1"  "1"  "1"  
## J "?"  "?"  "?"  "?"  "0"  "0"  "0"  "?"  "?"  "?"

That's really it!

This phytools development version can be installed from GitHub as follows:

library(devtools)
intall_github("liamrevell/phytools")

No comments:

Post a Comment