[Phylobase-devl] path between two tips

Ben Bolker bolker at ufl.edu
Thu Nov 20 20:58:45 CET 2008


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.
> 

  I think Brian O'Meara already filed this as a bug report
(which doesn't help you, but at least it's less surprising).

  To all: I'm very excited to see some conversations about
phylobase happening again.  I have a whole pile of thoughts
and ideas about phylobase (and hopefully fixes for some of
the outstanding irritations), but I have had no time since
returning from visiting/torturing Thibaut in Lyon.  Hopefully
this weekend.

  cheers
   Ben



More information about the Phylobase-devl mailing list