[Adephylo-commits] r10 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 20 19:39:11 CET 2008
Author: jombart
Date: 2008-11-20 19:39:10 +0100 (Thu, 20 Nov 2008)
New Revision: 10
Modified:
pkg/R/partition.R
Log:
Added a distRoot function.
Modified: pkg/R/partition.R
===================================================================
--- pkg/R/partition.R 2008-11-20 18:25:52 UTC (rev 9)
+++ pkg/R/partition.R 2008-11-20 18:39:10 UTC (rev 10)
@@ -119,7 +119,7 @@
res <- getnodes(res)
return(res)
-}
+} # end path2tips
@@ -130,14 +130,24 @@
###########
distRoot <- function(x, tip){
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
- tip <- getnodes(tip)
-
-}
+ tip <- getnodes(x, tip)
+ root <- getnodes(x, nTips(x)+1)
+ ancTip <- ancestors(x, tip, which="all")
+
+ pathNodes <- setdiff(ancTip, root) # only internal nodes, without root
+ pathNodes <- c(tip, pathNodes)
+
+ pathNodes <- getnodes(x, pathNodes)
+
+ res <- sumEdgeLength(x, pathNodes)
+
+ return(res)
+} # end distRoot
More information about the Adephylo-commits
mailing list