[Ecopd-commits] r79 - in branches/single-tree: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 18 07:27:58 CET 2009


Author: regetz
Date: 2009-11-18 07:27:58 +0100 (Wed, 18 Nov 2009)
New Revision: 79

Added:
   branches/single-tree/R/coerce.R
   branches/single-tree/man/coerce.Rd
Modified:
   branches/single-tree/DESCRIPTION
Log:
added coerce methods to extract phylo4 and phylo4d trees from a
phylo4com object; added corresponding skeleton documentation


Modified: branches/single-tree/DESCRIPTION
===================================================================
--- branches/single-tree/DESCRIPTION	2009-11-18 00:08:14 UTC (rev 78)
+++ branches/single-tree/DESCRIPTION	2009-11-18 06:27:58 UTC (rev 79)
@@ -8,6 +8,6 @@
 Depends: methods, phylobase
 Description: A set of metrics and functions for combining ecological and phylogenetic information
 License: GPL
-Collate: phylo4com.R utilities.R community.R pd.R aed.R iac.R pae.R simpson.R indices.R plots.R
+Collate: phylo4com.R coerce.R utilities.R community.R pd.R aed.R iac.R pae.R simpson.R indices.R plots.R
 LazyLoad: yes
 LazyData: yes

Added: branches/single-tree/R/coerce.R
===================================================================
--- branches/single-tree/R/coerce.R	                        (rev 0)
+++ branches/single-tree/R/coerce.R	2009-11-18 06:27:58 UTC (rev 79)
@@ -0,0 +1,48 @@
+setMethod("phylo4d", c("phylo4com"),
+  function(x, community) {
+    if (missing(community)) {
+        return(as(x, "phylo4d"))
+    }
+    if (length(community)!=1) {
+        stop("a single community label must be provided")
+    }
+
+    ## get the tree
+    tree <- phylo4(x, community)
+
+    ## get abundance values, and drop species with zero abundance
+    N <- abundance(x, community)
+    N <- N[N[[community]]!=0, , drop=FALSE]
+
+    ## combine and return phylo4d object
+    phylo4d(tree, tip.data=N)
+})
+
+setMethod("phylo4", c("phylo4com"),
+  function(x, community) {
+    if (missing(community)) {
+        return(as(x, "phylo4"))
+    }
+    if (length(community)!=1) {
+        stop("a single community label must be provided")
+    }
+    getSubtrees(x, community)[[1]]
+})
+
+## internal helper function for extracting a list of the subtrees
+## associated with each communities
+getSubtrees <- function(x, community) {
+    communities <- x at metadata$comms
+    if (missing(community)) {
+        community <- names(communities)
+    }
+    doNotExist <- !community %in% names(communities)
+    if (any(doNotExist)) {
+        stop("one or more communities not found in x: ",
+            paste(community[doNotExist], collapse=", "))
+    }
+    res <- x at subtrees[communities[names(communities) %in% community]]
+    names(res) <- community
+    return(res)
+}
+    


Property changes on: branches/single-tree/R/coerce.R
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/single-tree/man/coerce.Rd
===================================================================
--- branches/single-tree/man/coerce.Rd	                        (rev 0)
+++ branches/single-tree/man/coerce.Rd	2009-11-18 06:27:58 UTC (rev 79)
@@ -0,0 +1,31 @@
+\name{coerce}
+\docType{methods}
+\alias{phylo4,phylo4com-method}
+\alias{phylo4d,phylo4com-method}
+\title{Extract phylo4com phylogenies}
+\description{
+  Methods to extract phylo4 and phylo4d trees from phylo4com objects.
+}
+\usage{
+  \S4method{phylo4}{phylo4com}(x, community)
+  \S4method{phylo4d}{phylo4com}(x, community)
+}
+\arguments{
+  \item{x}{a \code{phylo4com} object}
+  \item{community}{an optional single valued character vector indicating
+    which community tree to return; if missing, the full
+    (across-communities) tree is returned}
+}
+\details{
+  TODO
+}
+\value{
+  A \code{phylo4} or \code{phylo4d} object.
+}
+\author{Jim Regetz (regetz at nceas.ucsb.edu)}
+\examples{
+  phylo4(weeds)
+  phylo4(weeds, "A")
+  phylo4d(weeds, "A")
+}
+\keyword{methods}


Property changes on: branches/single-tree/man/coerce.Rd
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Ecopd-commits mailing list