[Phylobase-devl] path between two tips

François Michonneau francois.michonneau at gmail.com
Thu Nov 20 23:35:14 CET 2008


The modification of MRCA I committed a couple of month ago indeed fixes
the bug reported by Brian.

However, what Thibault describes in the email below is another bug.
Oddly enough, fixing it is easy if the other idea I suggested in my
first email today is implemented. Indeed, if the function 'ancestors'
also returns the node originally called, then MRCA returns the correct
ancestors in the case described by Thibault.

I am not sure how to call this option. I chose "ALL" but if someone has
a better idea, please let me know.

Cheers,
  - François



On Thu, 2008-11-20 at 20:54 +0100, Thibaut Jombart wrote:
> Peter Cowan wrote:
> > There is a function for calculating the MRCA.  Line 101 of the 
> > treewalk.R file.  Perhaps this is helpful.
> >
> > Peter
> Yes, it is. I used it in the function:
> 
> shortestPath <- function(x, node1, node2){
>     if(!require(phylobase)) stop("phylobase package is not installed")
> 
>     ## conversion from phylo, phylo4 and phylo4d
>     x <- as(x, "phylo4")
> 
>     ## check phylo4 object
>     if (is.character(checkval <- check_phylo4(x))) stop(checkval)
> 
>     ## main computations
>     t1 <- getnodes(x, node1)
>     t2 <- getnodes(x, node2)
> 
>     comAnc <- MRCA(x, t1, t2) # common ancestor
>     desComAnc <- descendants(x, comAnc, which="all")
>     ancT1 <- ancestors(x, t1, which="all")
>     path1 <- intersect(desComAnc, ancT1) # path: common anc -> t1
> 
>     ancT2 <- ancestors(x, t2, which="all")
>     path2 <- intersect(desComAnc, ancT2) # path: common anc -> t2
> 
>     res <- union(path1, path2) # union of the path
>     res <- c(comAnc,res) # add the common ancestor
>     res <- getnodes(x, res)
> 
>     return(res)
> } # end shortestPath
> 
> Example:
> ##
> tr=as(rtree(20),"phylo4")
> plot(tr, show.node=T)
> shortestPath(tr,"t1","t2")
> ##
> 
> It works for tips, but some pb occur with internal nodes.
> The pb seems to come from MRCA. For instance:
> ##
> data(geospiza)
> plot(as(geospiza,"phylo4"), show.node=T)
> shortestPath(geospiza, "N02","N05")
> MRCA(geospiza, "N02","N05")
> ##
> 
> MRCA returns N01 (the root) instead of N02.
> 
> 
> Best,
> 
> Thibaut.
> 



More information about the Phylobase-devl mailing list