Monday, October 12, 2015

Small update to the small phytools function to fix malconformed trees

I just made a small update to the phytools function untangle, which basically tries to 'fix' malconformed "phylo" class objects that occasionally result from certain types of tree manipulation.

The update basically allows the returned "phylo" object to inherit the attributes of the input tree (except the ones that change in the fix) - which it otherwise may not depending on the method that is used to fix the malconformation.

Here's a quick demo:

library(phytools)
print(anole.trees,details=TRUE)
## 9 phylogenetic trees
## tree 1 : 18 tips
## tree 2 : 21 tips
## tree 3 : 11 tips
## tree 4 : 29 tips
## tree 5 : 26 tips
## tree 6 : 28 tips
## tree 7 : 17 tips
## tree 8 : 26 tips
## tree 9 : 19 tips
## estimate an MRP super tree
super.tree<-mrp.supertree(anole.trees)
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## [1] "Best pscore so far: 174"
## The MRP supertree, optimized via pratchet(),
## has a parsimony score of 174 (minimum 174)
super.tree<-root(super.tree,outgroup="Iguana_iguana",resolve.root=TRUE) ## fails
## Warning in newNb[phy$edge[sndcol, 2]] <- n + 2:phy$Nnode: number of items
## to replace is not a multiple of replacement length
## Error in phy$edge[sndcol, 2] <- newNb[phy$edge[sndcol, 2]] <- n + 2:phy$Nnode: number of items to replace is not a multiple of replacement length
attributes(super.tree)
## $names
## [1] "edge"      "Nnode"     "tip.label"
## 
## $class
## [1] "phylo"
## 
## $order
## [1] "postorder"
## 
## $pscore
## [1] 174
super.tree<-untangle(super.tree,method="read.tree")
attributes(super.tree)
## $names
## [1] "edge"      "tip.label" "Nnode"    
## 
## $class
## [1] "phylo"
## 
## $order
## [1] "cladewise"
## 
## $pscore
## [1] 174
super.tree<-root(super.tree,outgroup="Iguana_iguana",resolve.root=TRUE) ## works
plotTree(super.tree,ftype="i",fsize=0.7)

plot of chunk unnamed-chunk-1

That's it.

No comments:

Post a Comment