[Phylobase-commits] r143 - in pkg: R inst/doc man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 6 17:32:35 CET 2008


Author: bbolker
Date: 2008-03-06 17:32:35 +0100 (Thu, 06 Mar 2008)
New Revision: 143

Modified:
   pkg/R/treewalk.R
   pkg/inst/doc/phylobase.Rnw
   pkg/man/treewalk.Rd
Log:
  fixed descendants(...,which="all")
  fixed vignette (up-to-date, still not complete)
  updated treewalk documentation



Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R	2008-03-06 11:33:24 UTC (rev 142)
+++ pkg/R/treewalk.R	2008-03-06 16:32:35 UTC (rev 143)
@@ -54,10 +54,10 @@
 
 ## get descendants [recursively]
 descendants <- function (phy, node, which=c("tips","all"))
+##                         self=FALSE)
 {
-    ## FIXME: allow vector of nodes?
+    ## FIXME: allow vector of nodes? (or just let people lapply?)
     which <- match.arg(which)
-    if (which=="all") stop('which="all" not yet working')
     node <- getnodes(phy,node)
     if (is.na(node)) stop("node ",node," not found in tree")
     n <- nTips(phy)
@@ -67,16 +67,19 @@
     for (j in d) {
         if (j <= n)
           l <- c(l,j)
-        else if (which=="all") l <- c(l,node,descendants(phy,j,which="all"))
-        else l <- c(l, descendants(phy,j))
-##           l <- c(l, labels(phy,"tips")[as.numeric(j)])
-##         else if (which=="all") l <- c(l, names(node),
-##                    names(descendants(phy, j, which="all")))
-##         else l <- c(l, names(descendants(phy, j)))
+        else if (which=="all") l <- c(l,j,
+                   descendants(phy,j,which="all"))
+        else l <- c(l, descendants(phy,j,which=which))
     }
     return(getnodes(phy,l))
 }
 
+siblings <- function(phy, node, include.self=FALSE) {
+    v <- children(phy,parent(phy,node))
+    if (!include.self) v <- v[v!=getnodes(phy,node)]
+    v
+}
+    
 ## get ancestors (all nodes)
 ancestors <- function (phy, node) 
 {

Modified: pkg/inst/doc/phylobase.Rnw
===================================================================
--- pkg/inst/doc/phylobase.Rnw	2008-03-06 11:33:24 UTC (rev 142)
+++ pkg/inst/doc/phylobase.Rnw	2008-03-06 16:32:35 UTC (rev 143)
@@ -231,7 +231,7 @@
 <<results=hide>>=
 subset(g2,tips.exclude=c("fuliginosa","fortis","magnirostris",
             "conirostris","scandens"))
-subset(g2,tips.exclude=allDescend(g2,MRCA(g2,c("difficilis","fortis"))))
+subset(g2,tips.exclude=names(descendants(g2,MRCA(g2,c("difficilis","fortis")))))
 @ 
 
 Another approach is to pick the subtree graphically, by plotting the tree and using \code{identify}, which returns the identify of the node you click on with the mouse.
@@ -244,10 +244,14 @@
 
 \section{Tree-walking}
 
-\code{getDescend}, \code{getAncest},
-\code{allDescend}, \code{allAncest},
-\code{getNodeByLabel}, \code{getLabelByNode}:
-not sure about the names or functionality of these (how much do we work in terms of labels and how much in terms of internal numbers?)
+\code{getnodes},
+\code{children}, \code{parent},
+\code{descendants}, \code{ancestors},
+\code{siblings},
+\code{MRCA} \ldots
+generally take a \code{phylo4} object, a node
+(specified by number or name) and return a named
+vector of node numbers.
 
 \section{multiPhylo classes}
 

Modified: pkg/man/treewalk.Rd
===================================================================
--- pkg/man/treewalk.Rd	2008-03-06 11:33:24 UTC (rev 142)
+++ pkg/man/treewalk.Rd	2008-03-06 16:32:35 UTC (rev 143)
@@ -3,6 +3,7 @@
 \alias{children}
 \alias{descendants}
 \alias{ancestors}
+\alias{siblings}
 \alias{MRCA}
 \alias{getnodes}
 \title{tree traversal and utility functions}
@@ -13,6 +14,7 @@
 \usage{
 getnodes(phy,node)
 parent(phy, node)
+siblings(phy,node,include.self=FALSE)
 children(phy, node)
 descendants(phy, node, which=c("tips","all"))
 ancestors(phy, node)
@@ -23,20 +25,24 @@
     \code{phylo4}, e.g. a \code{phylo4d} object)
   }
   \item{node}{a node number (or name)}
-  \item{which}{whether to return all descendant nodes, or just tips
-    (which="all" is not yet implemented)}
+  \item{which}{whether to return all descendant nodes, or just tips}
+  \item{include.self}{whether to include self in list of siblings}
   \item{\dots}{a list of node numbers or names,
-  or a vector of node numbers or names}
+    or a vector of node numbers or names}
 }
 \value{
-  \code{getNodeByLabel} takes character strings corresponding to tip or
-  node labels and returns the corresponding node number;
-  \code{getLabelByNode} does the opposite.
-  \code{parent} and \code{children} return the numbers of the
+  \code{getnodes} takes character strings corresponding to tip or
+  node labels, or node numbers; it returns a named
+  vector of node numbers.
+  \code{parent} and \code{children} return named vectors
+  giving the
   immediate ancestors or descendants of a node; \code{descendants}
-  returns the \emph{names} of all of the descendants (tips only) of a
-  node; \code{ancestors} returns the numbers of all of the ancestors of
-  a node.  \code{mrca} returns the most recent common ancestor of two or
+  returns all of the descendants (including internal nodes
+  if which="all", otherwise tips only) of a
+  node; \code{ancestors} returns all of the ancestors of
+  a node; \code{siblings} returns sibling nodes (children
+  of the same parent).
+  \code{mrca} returns the most recent common ancestor of two or
   more nodes.
 }
 \note{\code{MRCA} is uppercase to avoid conflict with \code{mrca}



More information about the Phylobase-commits mailing list