[Phylobase-devl] path between two tips

François Michonneau francois.michonneau at gmail.com
Fri Nov 21 00:35:24 CET 2008


  I agree that this option doesn't do much but it seems to me that it's
something that can be done often enough that it could be useful to don't
have to write a separate line of code. Using the function ancestors
would also allow you to have consistent output as you can provide nodes
names and/or indices to the function. (ie. you don't have to write
c(getnodes(t1, x), ancestors(t1, x, which="all") )

  However, if the majority of people think it's superfluous I don't mind
reverting to the previous version.

  Cheers,
   - François

  

On Thu, 2008-11-20 at 18:06 -0500, Hilmar Lapp wrote:
> Isn't it easy enough for the caller to prepend (or append, depending  
> on the order in which ancestors() returns nodes, assuming that it does  
> return them ordered) the node to the array?
> 
> I.e., does having to do
> 
> 	ALLancestors <- c(t1, ancestors(x, t1, which="all"))
> 
> really warrant an extra option to ancestors()?
> 
> I'm probably missing something obvious here, so feel free to set me  
> straight if I'm off track.
> 
> 	-hilmar
> 
> On Nov 20, 2008, at 5:35 PM, François Michonneau wrote:
> 
> > 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.
> >>
> >
> > _______________________________________________
> > Phylobase-devl mailing list
> > Phylobase-devl at lists.r-forge.r-project.org
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/phylobase-devl
> 



More information about the Phylobase-devl mailing list