[Adephylo-commits] r28 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 25 18:06:09 CET 2008


Author: jombart
Date: 2008-11-25 18:06:09 +0100 (Tue, 25 Nov 2008)
New Revision: 28

Modified:
   pkg/R/distances.R
   pkg/man/sp.tips.Rd
Log:
Updated doc for sp.tips (new arg include.mrca). Progress in distances.R


Modified: pkg/R/distances.R
===================================================================
--- pkg/R/distances.R	2008-11-25 16:45:31 UTC (rev 27)
+++ pkg/R/distances.R	2008-11-25 17:06:09 UTC (rev 28)
@@ -9,7 +9,7 @@
     ## handle arguments
     x <- as(x, "phylo4")
     method <- match.arg(method)
-    tips <- getnodes(x, tip1)
+    tips <- getnodes(x, tips)
     N <- nTips(x)
     if(tips="all") { tips <- 1:N }
 
@@ -35,18 +35,26 @@
     allPairs <- findAllPairs(tips) # this contains all possible pairs of tips
 
     ## get the shortest path between all pairs of tips
-    allPath <- sp.tips(x, allPairs$i, allPairs$j, useTipNames=TRUE, quiet=TRUE)
+    if(method != "brlength") {
+        allPath <- sp.tips(x, allPairs$i, allPairs$j, useTipNames=TRUE, quiet=TRUE)
+    } else {
+        allPath <- sp.tips(x, allPairs$i, allPairs$j, useTipNames=TRUE, quiet=TRUE, include.mrca=FALSE)
+    }
 
     ## compute distances
     if(method=="brlength"){
         if(!hasEdgeLength(x)) stop("x does not have branch length")
         ## add tip1 and tip2 to the paths, so that these edges are counted
-        allPath <- as.data.frame
-        
-        allPath <- lapply(allPath, c, (node1, node2, allPath)
-        allPath <- allPath[allPath != MRCA(x, node1, node2)]
-        edge.idx <- getedges(x, allPath)
-        res <- sum(edgeLength(x)[edge.idx], na.rm=TRUE)
+        allPath <- as.data.frame(allPath)
+        tip1 <- allPairs$i
+        tip2 <- allPairs$j
+        for(i in 1:length(allPath)){
+            allPath[[i]] <- c(allPath[[i]], tip1, tip2)
+        }
+
+        edge.idx <- lapply(allPath, function(e) getedges(x, e) )
+        allEdgeLength <- edgeLength(x)
+        res <- lapply(edge.idx, function(idx) sum(allEdgeLength[idx], na.rm=TRUE) )
         return(res)
     } # end brlength
 

Modified: pkg/man/sp.tips.Rd
===================================================================
--- pkg/man/sp.tips.Rd	2008-11-25 16:45:31 UTC (rev 27)
+++ pkg/man/sp.tips.Rd	2008-11-25 17:06:09 UTC (rev 28)
@@ -22,6 +22,8 @@
     of \code{tip1} and \code{tip2} will be used.}
   \item{quiet}{a logical stating whether a warning must be issued when
     tip1==tip2, or not (see details).}
+  \item{include.mrca}{a logical stating whether the most recent common
+    ancestor shall be included in the returned path (TRUE, default) or not (FALSE).}
 }
 \value{
   A list whose components are vectors of named nodes forming the



More information about the Adephylo-commits mailing list