[Ecopd-commits] r80 - in branches/single-tree: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Nov 18 07:31:42 CET 2009
Author: regetz
Date: 2009-11-18 07:31:42 +0100 (Wed, 18 Nov 2009)
New Revision: 80
Added:
branches/single-tree/R/genera.R
Modified:
branches/single-tree/DESCRIPTION
branches/single-tree/R/utilities.R
branches/single-tree/man/genera.Rd
Log:
rewrote genera function as set of methods for phylo4 and phylo4com
objects; updated documentation accordingly
Modified: branches/single-tree/DESCRIPTION
===================================================================
--- branches/single-tree/DESCRIPTION 2009-11-18 06:27:58 UTC (rev 79)
+++ branches/single-tree/DESCRIPTION 2009-11-18 06:31:42 UTC (rev 80)
@@ -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 coerce.R utilities.R community.R pd.R aed.R iac.R pae.R simpson.R indices.R plots.R
+Collate: phylo4com.R coerce.R genera.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/genera.R
===================================================================
--- branches/single-tree/R/genera.R (rev 0)
+++ branches/single-tree/R/genera.R 2009-11-18 06:31:42 UTC (rev 80)
@@ -0,0 +1,24 @@
+setGeneric("genera", function(x, ...) {
+ standardGeneric("genera")
+})
+
+setMethod("genera", c("phylo4"),
+ function(x) {
+ # From taxa names in tree, remove "_" and species name after
+ gsub("_.*$", "", tipLabels(x))
+})
+
+setMethod("genera", c("phylo4com"),
+ function(x, community) {
+ if (missing(community)) {
+ community <- communities(x)
+ }
+ doNotExist <- !community %in% communities(x)
+ if (any(doNotExist)) {
+ stop("one or more communities not found in x: ",
+ paste(community[doNotExist], collapse=", "))
+ }
+ g <- lapply(getSubtrees(x, community), genera)
+ names(g) <- community
+ return(g)
+})
Property changes on: branches/single-tree/R/genera.R
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: branches/single-tree/R/utilities.R
===================================================================
--- branches/single-tree/R/utilities.R 2009-11-18 06:27:58 UTC (rev 79)
+++ branches/single-tree/R/utilities.R 2009-11-18 06:31:42 UTC (rev 80)
@@ -110,25 +110,6 @@
return(phy)
}
-##TODO method-ize this, adding method for phylo4, then calling that
-##method from this more complex phylo4com method
-# genera extractor
-genera <- function(phy, comm) {
- if (missing(comm)) {
- comm <- communities(phy)
- }
- doNotExist <- !comm %in% communities(phy)
- if (any(doNotExist)) {
- stop("one or more communities not found in phy: ",
- paste(comm[doNotExist], collapse=", "))
- }
- # From taxa names in tree, remove "_" and species name after
- g <- lapply(phy at subtrees[phy at metadata$comms[comm]], function(x)
- gsub("_.*$", "", tipLabels(x)))
- names(g) <- comm
- return(g)
-}
-
# community labels extractor
communities <- function(phy) {
names(phy at metadata$comms)
Modified: branches/single-tree/man/genera.Rd
===================================================================
--- branches/single-tree/man/genera.Rd 2009-11-18 06:27:58 UTC (rev 79)
+++ branches/single-tree/man/genera.Rd 2009-11-18 06:31:42 UTC (rev 80)
@@ -1,5 +1,9 @@
\name{genera}
+\docType{methods}
\alias{genera}
+\alias{genera-methods}
+\alias{genera,phylo4-method}
+\alias{genera,phylo4com-method}
\title{Extract genus names}
\description{
Helper function to extract the genus names from phylogeny tip labels
@@ -7,11 +11,12 @@
nomenclature.
}
\usage{
- genera(phy, comm)
+ \S4method{genera}{phylo4}(x)
+ \S4method{genera}{phylo4com}(x, community)
}
\arguments{
- \item{phy}{a \code{phylo4com} object}
- \item{comm}{a vector of community labels; if missing, all communities}
+ \item{x}{a \code{phylo4com} object}
+ \item{community}{a vector of community labels; if missing, all communities}
}
\details{
This is a simple function that assumes the tip labels of phylogeny
@@ -19,13 +24,15 @@
whatsoever to check whether this is in fact the case.
}
\value{
- A list of character vectors, one per community, containing the genus
- portion of the tip labels, with element names corresponding to the
- numeric tip node ID.
+ For \code{phylo4}, a character vector containing the genus portion of
+ the tip labels, with element names corresponding to the numeric tip
+ node ID. For \code{phylo4com}, a list of such vectors, one per
+ community.
}
\author{Jim Regetz (regetz at nceas.ucsb.edu)}
\examples{
data(weeds)
+ genera(weeds)
genera(weeds, "A")
- genera(weeds)
+ genera(phylo4(weeds))
}
More information about the Ecopd-commits
mailing list