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.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Liam,
    I am trying to run a correlation test using PIC on a tree and my tree was not binary as it had polytomies (4 branch-lengths of zero). I used

    dichotomousphylogeny <- multi2di(spider.tree, random = FALSE)

    to make it dichotomous, which seemed to work until I tried to do my PIC:

    > size<-setNames(obj[,"Size"],rownames(obj))
    > clutch.size<-setNames(obj[,"Clutch.Size"],rownames(obj))
    > pic.s<-pic(Size,dichotomousphylogeny)

    and got this error:
    Error in pic(Size, dichotomousphylogeny) :
    your tree has no branch lengths

    I was hoping you may have advice on why this is happening and how I could fix it? Thank you so much!

    ReplyDelete

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