[Picante-commits] r239 - pkg pkg/R pkg/man www

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 2 02:33:04 CEST 2012


Author: skembel
Date: 2012-10-02 02:33:03 +0200 (Tue, 02 Oct 2012)
New Revision: 239

Added:
   pkg/R/expected.pd.R
   pkg/man/expected.pd.Rd
Modified:
   pkg/DESCRIPTION
   pkg/man/picante-package.Rd
   www/index.php
Log:
Adding expected.pd and ead functions

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-09-24 18:54:50 UTC (rev 238)
+++ pkg/DESCRIPTION	2012-10-02 00:33:03 UTC (rev 239)
@@ -1,8 +1,8 @@
 Package: picante
 Type: Package
 Title: R tools for integrating phylogenies and ecology
-Version: 1.4-2
-Date: 2012-9-21
+Version: 1.5-1
+Date: 2012-10-1
 Author: Steven W. Kembel <skembel at uoregon.edu>, David D. Ackerly <dackerly at berkeley.edu>, Simon P. Blomberg <s.blomberg1 at uq.edu.au>, Will K. Cornwell <cornwell at zoology.ubc.ca>, Peter D. Cowan <pdc at berkeley.edu>, Matthew R. Helmus <mrhelmus at wisc.edu>, Helene Morlon <morlon.helene at gmail.com>, Campbell O. Webb <cwebb at oeb.harvard.edu>
 Maintainer: Steven W. Kembel <skembel at uoregon.edu>
 Depends: ape, vegan, nlme

Added: pkg/R/expected.pd.R
===================================================================
--- pkg/R/expected.pd.R	                        (rev 0)
+++ pkg/R/expected.pd.R	2012-10-02 00:33:03 UTC (rev 239)
@@ -0,0 +1,99 @@
+# calculate expected PD for all subsets of a phylogeny
+expected.pd <- function(phy) {
+  ead <- ead(phy)
+  epd <- vector(mode="numeric", length=Ntip(phy))
+  for(n in 1:Ntip(phy)){
+    epd[n] <- sum(ead$edge.length * (1 - dbinom(0, ead$num.children, n/Ntip(phy))))
+  }
+  return(data.frame(n=1:Ntip(phy),expected.pd=epd))
+}
+
+# calculate the edge abundance distribution (EAD)
+ead <- function(phy) {
+  phy <- reorder(phy)
+  Nedges <- length(phy$edge.length)
+  edgelen <- vector(mode = "numeric", length=Nedges)
+  children <- vector(mode = "numeric", length=Nedges)
+  for (i in 1:Nedges) {
+    edgelen[i] <- phy$edge.length[i]
+    descnode <- phy$edge[i,2]
+    if (descnode <= Ntip(phy)) {
+      children[i] <- 1
+    }
+    else
+    {
+      children[i] <- Ntip(.extract.clade.noreord(phy, descnode))
+    }
+  }
+  rawdata <- data.frame(num.children=children, edge.length=edgelen)
+  byclass <- aggregate(rawdata$edge.length, by=list(num.children=rawdata$num.children), sum)
+  colnames(byclass)[2] <- "edge.length"
+  return(byclass)
+}
+
+# utility function - modified from ape's extract.clade function
+.extract.clade.noreord <- function (phy, node, root.edge = 0, interactive = FALSE) 
+{
+  Ntip <- length(phy$tip.label)
+  ROOT <- Ntip + 1
+  Nedge <- dim(phy$edge)[1]
+  wbl <- !is.null(phy$edge.length)
+  if (interactive) 
+    node <- identify(phy)$nodes
+  else {
+    if (length(node) > 1) {
+      node <- node[1]
+      warning("only the first value of 'node' has been considered")
+    }
+    if (is.character(node)) {
+      if (is.null(phy$node.label)) 
+        stop("the tree has no node labels")
+      node <- which(phy$node.label %in% node) + Ntip
+    }
+    if (node <= Ntip) 
+      stop("node number must be greater than the number of tips")
+  }
+  if (node == ROOT) 
+    return(phy)
+  # phy <- reorder(phy)
+  root.node <- which(phy$edge[, 2] == node)
+  start <- root.node + 1
+  anc <- phy$edge[root.node, 1]
+  next.anc <- which(phy$edge[-(1:start), 1] <= anc)
+  keep <- if (length(next.anc)) 
+    start + 0:(next.anc[1] - 1)
+  else start:Nedge
+  if (root.edge) {
+    NewRootEdge <- phy$edge.length[root.node]
+    root.edge <- root.edge - 1
+    while (root.edge) {
+      if (anc == ROOT) 
+        break
+      i <- which(phy$edge[, 2] == anc)
+      NewRootEdge <- NewRootEdge + phy$edge.length[i]
+      root.edge <- root.edge - 1
+      anc <- phy$edge[i, 1]
+    }
+    if (root.edge && !is.null(phy$root.edge)) 
+      NewRootEdge <- NewRootEdge + phy$root.edge
+    phy$root.edge <- NewRootEdge
+  }
+  phy$edge <- phy$edge[keep, ]
+  if (wbl) 
+    phy$edge.length <- phy$edge.length[keep]
+  TIPS <- phy$edge[, 2] <= Ntip
+  tip <- phy$edge[TIPS, 2]
+  phy$tip.label <- phy$tip.label[sort(tip)]
+  phy$edge[TIPS, 2] <- order(tip)
+  if (!is.null(phy$node.label)) 
+    phy$node.label <- phy$node.label[sort(unique(phy$edge[,1])) - Ntip]
+  Ntip <- length(phy$tip.label)
+  phy$Nnode <- dim(phy$edge)[1] - Ntip + 1L
+  newNb <- integer(Ntip + phy$Nnode)
+  newNb[node] <- Ntip + 1L
+  sndcol <- phy$edge[, 2] > Ntip
+  phy$edge[sndcol, 2] <- newNb[phy$edge[sndcol, 2]] <- (Ntip + 
+    2):(Ntip + phy$Nnode)
+  phy$edge[, 1] <- newNb[phy$edge[, 1]]
+  phy
+}
\ No newline at end of file

Added: pkg/man/expected.pd.Rd
===================================================================
--- pkg/man/expected.pd.Rd	                        (rev 0)
+++ pkg/man/expected.pd.Rd	2012-10-02 00:33:03 UTC (rev 239)
@@ -0,0 +1,40 @@
+\name{expected.pd}
+\alias{expected.pd}
+\alias{ead}
+
+\title{ Expected PD and Edge Abundance Distribution of a phylogeny }
+
+\description{ Calculates the expected phylogenetic diversity (Faith's PD) under binomial sampling with a fixed probability of each tip being sampled, and the Edge-length Abundance Distribution of a phylogeny. }
+
+\usage{
+expected.pd(phy)
+ead(phy)
+}
+
+\arguments{
+  \item{phy}{ phylo object }
+}
+
+\value{
+  \item{n}{ Expected Number of tips sampled }
+  \item{expected.pd}{ Expected PD for a given n }
+  \item{num.children}{ Number of tips descended from an edge }
+  \item{edge.length}{ Total phylogenetic edge length for a given number of tips descended from an edge }      
+}
+
+\details{The function \code{expected.pd} calculates the expected phylogenetic diversity (Faith's PD - total branch length) for all subsets of a phylogeny, based on an analytic solution for expected PD.
+
+The function \code{ead} calculates the edge abundance distribution (EAD), the length of edges with different numbers of descendant tips.
+}
+
+\references{ O'Dwyer, Kembel, and Green. 2012. Phylogenetic diversity theory sheds light on the structure of microbial communities. }
+
+\author{ Steven Kembel <skembel at uoregon.edu> and James O'Dwyer <jodwyer at santafe.edu> }
+
+\seealso{ \code{\link{pd}} }
+
+\examples{
+randtree <- rcoal(100)
+plot(expected.pd(randtree), xlab="Number of tips", ylab="Expected PD", type="l")
+}
+\keyword{univar}

Modified: pkg/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd	2012-09-24 18:54:50 UTC (rev 238)
+++ pkg/man/picante-package.Rd	2012-10-02 00:33:03 UTC (rev 239)
@@ -12,8 +12,8 @@
 \tabular{ll}{
 Package: \tab picante\cr
 Type: \tab Package\cr
-Version: \tab 1.4-2\cr
-Date: \tab 2012-9-21\cr
+Version: \tab 1.5-1\cr
+Date: \tab 2012-10-1\cr
 License: \tab GPL-2\cr
 }
 }

Modified: www/index.php
===================================================================
--- www/index.php	2012-09-24 18:54:50 UTC (rev 238)
+++ www/index.php	2012-10-02 00:33:03 UTC (rev 239)
@@ -41,10 +41,11 @@
 <h2>News</h2>
 <ul>
 <li>A manuscript describing Picante has been published in Bioinformatics.</li>
-<li>Picante 1.4 has been released
+<li>Picante 1.5 has been released
 <ul>
-<li>The phylogenetic generalized linear mixed models of Ives and Helmus (2011) are now included in function pglmm</li>
+<li>The phylogenetic generalized linear mixed models of Ives and Helmus (2011) are now included in function <code>pglmm</code></li>
 <li>The function <code>pic.circular</code> has been deprecated until further testing can be performed.</li>
+<li>Code for rapid estimation of expected phylogenetic diversity and the edge abundance distribution (O'Dwyer et al. 2012) is now included in functions <code>expected.pd</code> and <code>ead</code>.
 </ul>
 </li>
 <li>Lots of changes and new features since version 1.0
@@ -61,7 +62,7 @@
 <ul>
 <li>Community phylogenetic and trait diversity</li>
     <ul>
-    <li>Faith's PD (phylogenetic diversity) and standardized effect size of PD.</li>
+    <li>Faith's PD (phylogenetic diversity), standardized effect size of PD, expected PD of subsets of a phylogenetic tree.</li>
     <li>Webb's NRI/NTI and related measures of standardized effect size of community phylogenetic structure.</li>
     <li>Mean pairwise distance and mean distance to nearest taxon among co-occurring species (can be used with any interspecific distance measure). Distances can be calculated based on presence or abundance in samples.</li>
     <li>Rao's quadratic entropy, a measure of diversity within and among communities optionally taking phylogenetic distinctiveness into account.</li>
@@ -92,7 +93,7 @@
 
 <h2>Obtaining picante</h2>
 <ul>
-<li>Version 1.4-2 is available on <a href="http://cran.r-project.org/">CRAN</a>. Simply type <strong><code>install.packages("picante")</code></strong> from within R.</li>
+<li>Version 1.5-0 is available on <a href="http://cran.r-project.org/">CRAN</a>. Simply type <strong><code>install.packages("picante")</code></strong> from within R.</li>
 <li>You can grab the latest nightly build <a href="http://r-forge.r-project.org/R/?group_id=134">here</a>, or by typing <strong><code>install.packages("picante",repos="http://R-Forge.R-project.org")</code></strong> from within R.</li>
 </ul>
 
@@ -109,6 +110,7 @@
 
 <h2>Release history</h2>
 <p><ul>
+<li>Version 1.5: Add expected.pd and ead functions to estimate expected phylogenetic diversity and edge abundance distribution (O'Dwyer et al. 2012).</li>
 <li>Version 1.4: Add pglmm methods from Ives & Helmus (2011). Correct typos in vignette and documentation. Remove pic.circular function until further testing can be performed.</li>
 <li>Version 1.3: Add function pcd. Fix single-community error in pse.</li>
 <li>Version 1.2: Bugfix release. Fix to evol.distinct function. Kcalc now behaves better with non-ultrametric trees.</li>



More information about the Picante-commits mailing list