[Phylobase-commits] r825 - in pkg: . R inst/unitTests man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 9 21:20:01 CET 2011


Author: francois
Date: 2011-02-09 21:20:01 +0100 (Wed, 09 Feb 2011)
New Revision: 825

Modified:
   pkg/NAMESPACE
   pkg/R/methods-phylo4.R
   pkg/R/phylo4.R
   pkg/inst/unitTests/runit.methods-phylo4.R
   pkg/man/phylo4-accessors.Rd
Log:
new method: depthTips, gives distance from tips to root

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2011-02-09 20:18:44 UTC (rev 824)
+++ pkg/NAMESPACE	2011-02-09 20:20:01 UTC (rev 825)
@@ -22,7 +22,7 @@
 exportMethods(phylo4, phylo4d)
 
 # counting methods
-exportMethods(nTips, nNodes, nEdges)
+exportMethods(nTips, nNodes, nEdges, depthTips)
 
 # edge methods
 exportMethods(edges, edgeId, hasEdgeLength, edgeLength, "edgeLength<-",

Modified: pkg/R/methods-phylo4.R
===================================================================
--- pkg/R/methods-phylo4.R	2011-02-09 20:18:44 UTC (rev 824)
+++ pkg/R/methods-phylo4.R	2011-02-09 20:20:01 UTC (rev 825)
@@ -3,6 +3,7 @@
 
 ### 1. Tip accessors
 ###  1.1. nTips()
+###  1.2. depthTips()
 
 ### 2. Node accessors
 ###  2.1. nNodes()
@@ -74,6 +75,16 @@
      Ntip(x)
 })
 
+setMethod("depthTips", signature(x="phylo4"), function(x) {
+  if (!hasEdgeLength(x)) {
+    return(NULL)
+  }
+  else {
+    sapply(1:nTips(x), function(i)
+           sumEdgeLength(x, ancestors(x, i, "ALL")))
+  }
+})
+
 #########################################################
 ### Node accessors
 #########################################################

Modified: pkg/R/phylo4.R
===================================================================
--- pkg/R/phylo4.R	2011-02-09 20:18:44 UTC (rev 824)
+++ pkg/R/phylo4.R	2011-02-09 20:20:01 UTC (rev 825)
@@ -5,6 +5,11 @@
     standardGeneric("nTips")
 })
 
+## depthTips
+setGeneric("depthTips", function(x) {
+  standardGeneric("depthTips")
+})
+
 ## nNodes
 setGeneric("nNodes", function(x) {
     standardGeneric("nNodes")

Modified: pkg/inst/unitTests/runit.methods-phylo4.R
===================================================================
--- pkg/inst/unitTests/runit.methods-phylo4.R	2011-02-09 20:18:44 UTC (rev 824)
+++ pkg/inst/unitTests/runit.methods-phylo4.R	2011-02-09 20:20:01 UTC (rev 825)
@@ -45,6 +45,14 @@
   checkEquals(nTips(phy.alt), length(nid.tip))
 }
 
+test.depthTips.phylo4 <- function() {
+  edgeLengthVec <- c(1.2, 1.8, 1.8, 2.1, 2.3)
+  checkEquals(depthTips(phy.alt), edgeLengthVec)
+  tmpPhy <- phy.alt
+  edgeLength(tmpPhy) <- NA
+  checkTrue(is.null(depthTips(tmpPhy)))
+}
+
 test.nTips.ANY <- function() {
   # nTips phylo
   checkEquals(nTips(tr), 5)

Modified: pkg/man/phylo4-accessors.Rd
===================================================================
--- pkg/man/phylo4-accessors.Rd	2011-02-09 20:18:44 UTC (rev 824)
+++ pkg/man/phylo4-accessors.Rd	2011-02-09 20:20:01 UTC (rev 825)
@@ -7,6 +7,10 @@
 \alias{nTips-methods}
 \alias{nTips,phylo4-method}
 \alias{nTips,phylo-method}
+\alias{depthTips}
+\alias{depthTips-methods}
+\alias{depthTips,phylo4-method}
+\alias{depthTips,phylo4d-method}
 \alias{edges}
 \alias{edges-methods}
 \alias{edges,phylo4-method}
@@ -44,6 +48,9 @@
 \section{Methods}{
 \describe{
   \item{nTips}{\code{signature(object="phylo4")}: number of tips}
+
+  \item{depthTips}{\code{signature(object="phylo4")}: distance between
+  the tips and the root}
   
   \item{nNodes}{\code{signature(object="phylo4")}: number of internal nodes}
   
@@ -78,6 +85,7 @@
 % https://stat.ethz.ch/pipermail/r-devel/2008-May/049653.html
 \S4method{nNodes}{phylo4}(x)
 \S4method{nTips}{phylo4}(x)
+\S4method{depthTips}{phylo4}(x)
 \S4method{edges}{phylo4}(x, drop.root=FALSE, \dots)
 \S4method{nEdges}{phylo4}(x)
 \S4method{edgeOrder}{phylo4}(x, \dots)
@@ -93,7 +101,7 @@
 
 \arguments{
   \item{x}{a phylo4/phylo4d object}
-  \item{node}{which edge lengths to extract (indexed by descendant
+  \item{node}{which edge to extract (indexed by descendant
     node)} 
   \item{value}{a vector of edge lengths or a node number}
   \item{use.names}{Should the names of \code{value} be used to match
@@ -104,9 +112,9 @@
 
 \examples{
 data(geospiza)
-edgeLength(geospiza,5)
-edgeLength(geospiza,"olivacea")
-edgeLength(geospiza,5:7)
+edgeLength(geospiza, 5)
+edgeLength(geospiza, "olivacea")
+edgeLength(geospiza, 5:7)
 }
 
 \keyword{methods}



More information about the Phylobase-commits mailing list