[Adephylo-commits] r33 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 26 11:46:36 CET 2008


Author: jombart
Date: 2008-11-26 11:46:36 +0100 (Wed, 26 Nov 2008)
New Revision: 33

Added:
   pkg/man/miscUtils.Rd
Modified:
   pkg/R/utils.R
   pkg/TODO
   pkg/man/distRoot.Rd
Log:
Externalized tipToRoot to .tipToRoot (will be used by other functions than sp.tips). Added doc for it and possibly other misc utils.
Made decision to use hidden axuil functions, going fast but without checks, to be called by other functions.


Modified: pkg/R/utils.R
===================================================================
--- pkg/R/utils.R	2008-11-26 10:19:15 UTC (rev 32)
+++ pkg/R/utils.R	2008-11-26 10:46:36 UTC (rev 33)
@@ -1,3 +1,40 @@
+##
+## SEVERAL UTILS FUNCTIONS
+## =======================
+##
+## Hidden functions are intended to go fast, and thus make no validity test.
+## >.tipToRoot< is an hidden function return path to the root for a tip
+## >sp.tips< computes the shortest path between two tips
+##
+##
+
+
+#############
+# .tipToRoot
+#############
+##
+## x: a phylo4/phylo4d
+## tip: an integer identifying a tip by its number
+## root: to root node; could be computed inside the function,
+## but will often be computed outside, once and for all.
+##
+.tipToRoot <- function(x, tip, root){
+    E <- x$edge
+    path <- NULL
+    curNode <- tip
+    while(curNode != root){
+        curNode <- E[(curNode==E[,2]),1] # one node <- its ancestor
+        path <- c(path, curNode)
+    } # end while
+
+    path <- getnodes(x, path)
+    return(path)
+} # end tipToRoot
+
+
+
+
+
 ##########
 # sp.tips
 ##########
@@ -34,18 +71,18 @@
     allTips <- unique(c(t1,t2))
 
 
-    ## function tipToRoot
-    tipToRoot <- function(E, tip){
-        path <- NULL
-        curNode <- tip
-        while(curNode != root){
-            curNode <- E[(curNode==E[,2]),1] # one node <- its ancestor
-            path <- c(path, curNode)
-        } # end while
+    ##   ## tipToRoot -> call to .tipToRoot
+    ##     tipToRoot <- function(E, tip){
+    ##         path <- NULL
+    ##         curNode <- tip
+    ##         while(curNode != root){
+    ##             curNode <- E[(curNode==E[,2]),1] # one node <- its ancestor
+    ##             path <- c(path, curNode)
+    ##         } # end while
 
-        path <- getnodes(x, path)
-        return(path)
-    } # end tipToRoot
+    ##         path <- getnodes(x, path)
+    ##         return(path)
+    ##     } # end tipToRoot
 
 
     ## function pathTwoTips (takes two path-to-root as args)
@@ -72,7 +109,7 @@
 
 
     ## main computations
-    allPathToRoot <- lapply(allTips, function(i) tipToRoot(E, i))
+    allPathToRoot <- lapply(allTips, function(i) .tipToRoot(x, i, root))
     names(allPathToRoot) <- allTips
 
     allPath1 <- allPathToRoot[as.character(t1)]

Modified: pkg/TODO
===================================================================
--- pkg/TODO	2008-11-26 10:19:15 UTC (rev 32)
+++ pkg/TODO	2008-11-26 10:46:36 UTC (rev 33)
@@ -26,7 +26,7 @@
 
 # CODE ISSUES:
 ==============
-* 
+* make a working package that passes the check
 
 # DOCUMENTATION ISSUES:
 =======================

Modified: pkg/man/distRoot.Rd
===================================================================
--- pkg/man/distRoot.Rd	2008-11-26 10:19:15 UTC (rev 32)
+++ pkg/man/distRoot.Rd	2008-11-26 10:46:36 UTC (rev 33)
@@ -23,7 +23,7 @@
   A numeric vector containing one distance value for each tip.
 }
 \author{ Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr} }
-\seealso{\code{\link{distPhylo4}} which computes several phylogenetic
+\seealso{\code{\link{distTips}} which computes several phylogenetic
   distances between tips.
 }
 \examples{

Added: pkg/man/miscUtils.Rd
===================================================================
--- pkg/man/miscUtils.Rd	                        (rev 0)
+++ pkg/man/miscUtils.Rd	2008-11-26 10:46:36 UTC (rev 33)
@@ -0,0 +1,39 @@
+\name{Misc utils}
+\alias{.tipToRoot}
+\title{Low-level auxiliary functions for adephylo}
+\description{
+  These hidden functions are utils for adephylo, used by other
+  functions. Regular users can use them as well, but no validity checks
+  are performed for the arguments: speed is here favored over safety.
+  Most of these functions handle trees inheriting \linkS4class{phylo4}
+  class .\cr
+
+  \code{.tipToRoot} finds the set of nodes between a tip and the root of
+  a tree.\cr
+
+}
+\usage{
+.tipToRoot(x, tip, root)
+}
+\arguments{
+  \item{x}{A valid tree of  class \linkS4class{phylo4}.}
+  \item{tip}{An integer identifying a tip by its numbers.}
+  \item{root}{An integer identifying the root of the tree by its numbers.}
+}
+\value{
+  \code{.tipToRoot}: a vector of named integers identifying nodes.\cr
+}
+\author{ Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr} }
+\examples{
+if(require(ape) & require(phylobase)){
+## make a tree
+x <- as(rtree(20),"phylo4")
+plot(x,show.node=TRUE)
+
+## .tipToRoot
+root <- rootNode(x)
+.tipToRoot(x, 1, root)
+lapply(1:nTips(x), function(i) .tipToRoot(x, i, root))
+}
+}
+\keyword{manip}



More information about the Adephylo-commits mailing list