[Phylobase-commits] r291 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 20 23:36:38 CET 2008
Author: francois
Date: 2008-11-20 23:36:38 +0100 (Thu, 20 Nov 2008)
New Revision: 291
Modified:
pkg/R/treewalk.R
Log:
added new option for 'ancestors' which fixes bug in MRCA
Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R 2008-11-20 17:47:17 UTC (rev 290)
+++ pkg/R/treewalk.R 2008-11-20 22:36:38 UTC (rev 291)
@@ -81,11 +81,11 @@
}
## get ancestors (all nodes)
-ancestors <- function (phy, node, which=c("all","parent"))
+ancestors <- function (phy, node, which=c("all","parent","ALL"))
{
which <- match.arg(which)
if (which=="parent") return(ancestor(phy,node))
- node <- getnodes(phy,node)
+ oNode <- node <- getnodes(phy,node)
if (is.na(node)) stop("node ",node," not found in tree")
res <- numeric(0)
n <- nTips(phy)
@@ -95,6 +95,7 @@
node <- anc
if (anc==n+1) break
}
+ if(which == "ALL") res <- c(oNode, res)
return(getnodes(phy,res))
}
@@ -112,7 +113,7 @@
uniqueNodes[[1]]
}
else {
- ancests <- lapply(nodes,ancestors,phy=phy)
- getnodes(phy,max(Reduce(intersect,ancests)))
+ ancests <- lapply(nodes, ancestors, phy=phy, which="ALL")
+ getnodes(phy, max(Reduce(intersect, ancests)))
}
}
More information about the Phylobase-commits
mailing list