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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 25 18:16:37 CET 2008


Author: jombart
Date: 2008-11-25 18:16:37 +0100 (Tue, 25 Nov 2008)
New Revision: 29

Added:
   pkg/man/distTips.Rd
Removed:
   pkg/man/distNodes.Rd
Modified:
   pkg/R/distances.R
Log:
renamed distTip doc.


Modified: pkg/R/distances.R
===================================================================
--- pkg/R/distances.R	2008-11-25 17:06:09 UTC (rev 28)
+++ pkg/R/distances.R	2008-11-25 17:16:37 UTC (rev 29)
@@ -11,7 +11,7 @@
     method <- match.arg(method)
     tips <- getnodes(x, tips)
     N <- nTips(x)
-    if(tips="all") { tips <- 1:N }
+    if(tips=="all") { tips <- 1:N }
 
     ## some checks
     if (is.character(checkval <- check_phylo4(x))) stop(checkval)
@@ -45,44 +45,57 @@
     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)
         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) )
+        edge.idx <- lapply(allPath, function(e) getedges(x, e) ) # list of indices of edges
         allEdgeLength <- edgeLength(x)
         res <- lapply(edge.idx, function(idx) sum(allEdgeLength[idx], na.rm=TRUE) )
         return(res)
     } # end brlength
 
     if(method=="nNodes"){
-        res <- length(allPath)
+        res <- lapply(allPath, length)
         return(res)
     } # end nNodes
 
     if(method=="Abouheif"){
         E <- x at edge
-        temp <- table(E[,1])[as.character(allPath)] # number of dd per node
-        res <- prod(temp)
+        f1 <- function(onePath){ # computes product of dd for one path
+            temp <- table(E[,1])[as.character(onePath)] # number of dd per node
+            return(prod(temp))
+        }
+        res <- lapply(allPath, f1)
         return(res)
     } # end Abouheif
 
     if(method=="sumDD"){
         E <- x at edge
-        temp <- table(E[,1])[as.character(allPath)] # number of dd per node
-        res <- sum(temp)
+        f1 <- function(onePath){ # computes sum of dd for one path
+            temp <- table(E[,1])[as.character(onePath)] # number of dd per node
+            return(sum(temp))
+        }
+        res <- lapply(allPath, f1)
         return(res)
- } # end sumDD
 
+    } # end sumDD
+
 } # end distNodes
 
 
+## examples
+# source("/home/master/dev/adephylo/pkg/R/distances.R")
+ x <- as(rtree(10),"phylo4")
+     plot(x, show.node=TRUE)
+     axisPhylo()
 
 
 
+
+
 ###########
 # distRoot
 ###########

Deleted: pkg/man/distNodes.Rd
===================================================================
--- pkg/man/distNodes.Rd	2008-11-25 17:06:09 UTC (rev 28)
+++ pkg/man/distNodes.Rd	2008-11-25 17:16:37 UTC (rev 29)
@@ -1,63 +0,0 @@
-\name{distNodes}
-\alias{distNodes}
-\title{Compute some phylogenetic distance between two nodes}
-\description{
-  The function \code{distNodes} computes a given distance between two
-  nodes of a phylogeny. This distance corresponds to the shortest path
-  between the two nodes. Several distances can be used, defaulting to the
-  sum of branch lengths (see argument \code{method}).
-}
-\usage{
-distNodes(x, node1, node2, method=c("brlength","nNodes","Abouheif","sumDD"))
-}
-\arguments{
-  \item{x}{a tree of  class \code{\link[pkg:ape]{phylo}},
-    \linkS4class{phylo4} or \linkS4class{phylo4d}.}
-  \item{method}{a character string (full or abbreviated without
-    ambiguity) specifying the method used to compute distances ;
-    possible values are:\cr
-    - \code{brlength}: branch length \cr
-    - \code{nNodes}: number of nodes on the path between the nodes \cr
-    - \code{Abouheif}: Abouheif's distance (see details) \cr
-    - \code{sumDD}: sum of direct descendants of all nodes on the path
-    (see details) \cr
-   }
-}
-\value{
-  A numeric vector containing one distance value for each tip.
-}
-\details{
-  \code{Abouheif} distance refers to the phylogenetic distance
-  underlying the test of Abouheif (see references). Let P be the set of
-  all the nodes in the path going from \code{node1} to \code{node2}. Let
-  DDP be the number of direct descendants from each node in P. Then, the
-  so-called 'Abouheif' distance is the product of all terms in DDP.\cr
-
-   \code{sumDD} refers to a phylogenetic distance quite similar to that
-  of Abouheif. We consider the same sets P and DDP. But instead of
-  computing the product of all terms in DDP, this distance computes the
-  sum of all terms in DDP.
-}
-\author{ Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr} }
-\seealso{\code{\link{distTips}} which computes several phylogenetic
-  distances between tips.
-}
-\references{
-  Pavoine, S.; Ollier, S.; Pontier, D. & Chessel, D. (2008) Testing for
-  phylogenetic signal in life history variable: Abouheif's test
-  revisited. \emph{Theoretical Population Biology}: \bold{73}, 79-91.
-}
-\examples{
-if(require(ape) & require(phylobase)){
-## make a tree
-x <- as(rtree(10),"phylo4")
-plot(x, show.node=TRUE)
-axisPhylo()
-## compute different distances
-distNodes(x, "t1", "t2")
-distNodes(x, "t1", "t2", "nNodes")
-distNodes(x, "t1", "t2", "Abouheif")
-distNodes(x, "t1", "t2", "sumDD")
-}
-}
-\keyword{manip}

Added: pkg/man/distTips.Rd
===================================================================
--- pkg/man/distTips.Rd	                        (rev 0)
+++ pkg/man/distTips.Rd	2008-11-25 17:16:37 UTC (rev 29)
@@ -0,0 +1,63 @@
+\name{distNodes}
+\alias{distNodes}
+\title{Compute some phylogenetic distance between two nodes}
+\description{
+  The function \code{distNodes} computes a given distance between two
+  nodes of a phylogeny. This distance corresponds to the shortest path
+  between the two nodes. Several distances can be used, defaulting to the
+  sum of branch lengths (see argument \code{method}).
+}
+\usage{
+distNodes(x, node1, node2, method=c("brlength","nNodes","Abouheif","sumDD"))
+}
+\arguments{
+  \item{x}{a tree of  class \code{\link[pkg:ape]{phylo}},
+    \linkS4class{phylo4} or \linkS4class{phylo4d}.}
+  \item{method}{a character string (full or abbreviated without
+    ambiguity) specifying the method used to compute distances ;
+    possible values are:\cr
+    - \code{brlength}: branch length \cr
+    - \code{nNodes}: number of nodes on the path between the nodes \cr
+    - \code{Abouheif}: Abouheif's distance (see details) \cr
+    - \code{sumDD}: sum of direct descendants of all nodes on the path
+    (see details) \cr
+   }
+}
+\value{
+  A numeric vector containing one distance value for each tip.
+}
+\details{
+  \code{Abouheif} distance refers to the phylogenetic distance
+  underlying the test of Abouheif (see references). Let P be the set of
+  all the nodes in the path going from \code{node1} to \code{node2}. Let
+  DDP be the number of direct descendants from each node in P. Then, the
+  so-called 'Abouheif' distance is the product of all terms in DDP.\cr
+
+   \code{sumDD} refers to a phylogenetic distance quite similar to that
+  of Abouheif. We consider the same sets P and DDP. But instead of
+  computing the product of all terms in DDP, this distance computes the
+  sum of all terms in DDP.
+}
+\author{ Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr} }
+\seealso{\code{\link{distTips}} which computes several phylogenetic
+  distances between tips.
+}
+\references{
+  Pavoine, S.; Ollier, S.; Pontier, D. & Chessel, D. (2008) Testing for
+  phylogenetic signal in life history variable: Abouheif's test
+  revisited. \emph{Theoretical Population Biology}: \bold{73}, 79-91.
+}
+\examples{
+if(require(ape) & require(phylobase)){
+## make a tree
+x <- as(rtree(10),"phylo4")
+plot(x, show.node=TRUE)
+axisPhylo()
+## compute different distances
+distNodes(x, "t1", "t2")
+distNodes(x, "t1", "t2", "nNodes")
+distNodes(x, "t1", "t2", "Abouheif")
+distNodes(x, "t1", "t2", "sumDD")
+}
+}
+\keyword{manip}



More information about the Adephylo-commits mailing list