[Picante-commits] r198 - in branches/will: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 19 01:26:45 CET 2009


Author: will_cornwell
Date: 2009-11-19 01:26:45 +0100 (Thu, 19 Nov 2009)
New Revision: 198

Added:
   branches/will/R/get.nodes.R
   branches/will/man/evol.distinct.Rd
   branches/will/man/get.nodes.Rd
Modified:
   branches/will/DESCRIPTION
   branches/will/R/evol.distinct.R
Log:
added function get.nodes

Modified: branches/will/DESCRIPTION
===================================================================
--- branches/will/DESCRIPTION	2009-11-18 23:42:07 UTC (rev 197)
+++ branches/will/DESCRIPTION	2009-11-19 00:26:45 UTC (rev 198)
@@ -5,7 +5,7 @@
 Date: 2009-3-18
 Author: Steven Kembel <skembel at uoregon.edu>, David Ackerly <dackerly at berkeley.edu>, Simon Blomberg <s.blomberg1 at uq.edu.au>, Peter Cowan <pdc at berkeley.edu>, Matthew Helmus <mrhelmus at wisc.edu>, Helene Morlon  <morlon.helene at gmail.com>, Campbell Webb <cwebb at oeb.harvard.edu>
 Maintainer: Steven Kembel <skembel at uoregon.edu>
-Depends: ape, vegan, nlme
+Depends: ape, vegan, nlme, geiger
 Suggests: brglm, circular
 Description: Phylocom integration, community analyses, null-models, traits and evolution in R
 License: GPL-2

Modified: branches/will/R/evol.distinct.R
===================================================================
--- branches/will/R/evol.distinct.R	2009-11-18 23:42:07 UTC (rev 197)
+++ branches/will/R/evol.distinct.R	2009-11-19 00:26:45 UTC (rev 198)
@@ -4,7 +4,7 @@
 #The scale option refers to whether or not the phylogeny should be scaled to a depth of 1 or, in the case of an ultrametric tree,  scaled such that branch lengths are relative.
 #If use.branch.lengths=FALSE, then all branch lengths are changed to 1.
 
-spp.evol.history<- function(tree, type=c("equal.splits", "fair.proportion"), scale=F, use.branch.lengths=TRUE){
+evol.distinct<- function(tree, type=c("equal.splits", "fair.proportion"), scale=F, use.branch.lengths=TRUE){
 
 if(is.rooted(tree)==FALSE)
 warning("A rooted phylogeny is required for meaningful output of this function", call.=FALSE)

Added: branches/will/R/get.nodes.R
===================================================================
--- branches/will/R/get.nodes.R	                        (rev 0)
+++ branches/will/R/get.nodes.R	2009-11-19 00:26:45 UTC (rev 198)
@@ -0,0 +1,15 @@
+#GET.NODES FUNCTION
+#Get a vector of the nodes that are along the path from the root to spp x.  This may then be used to determine the number of nodes between the root and the tip (see node.number function) or the length of this path.
+
+
+get.nodes<- function(tree, spp){
+	edge<- which.edge(tree, spp)
+	nodes<- tree$edge[edge,1] 
+	root.edge<- which(tree$edge[,1]==(length(tree$tip.label)+1))
+while(!(edge %in% root.edge)){
+	edge<- which.edge(tree, tree$edge[edge,1])
+	next.node<- tree$edge[edge,1]
+	nodes<- c(nodes, next.node)
+	}
+	nodes
+	}
\ No newline at end of file

Added: branches/will/man/evol.distinct.Rd
===================================================================
--- branches/will/man/evol.distinct.Rd	                        (rev 0)
+++ branches/will/man/evol.distinct.Rd	2009-11-19 00:26:45 UTC (rev 198)
@@ -0,0 +1,118 @@
+\name{evol.distinct}
+\Rdversion{1.1}
+\alias{evol.distinct}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+Species' evolutionary distinctiveness
+}
+\description{
+Evolutionary distinctiveness measures for a suite of species by: a) equal splits (Redding and Mooers 2006) b) fair proportions (Isaac et al., 2007). Returns a vector of species scores.
+}
+\usage{
+spp.evol.history(tree, type = c("equal.splits", "fair.proportion"), scale = F, use.branch.lengths = TRUE)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{tree}{
+a .phylo "APE" tree}
+  \item{type}{
+a) equal splits (Redding and Mooers 2006) or b) fair proportions (Isaac et al., 2007)
+}
+  \item{scale}{
+%%     The scale option refers to whether or not the phylogeny should be scaled to a depth of 1 or, in the case of an ultrametric tree,  scaled such that branch lengths are relative.
+}
+  \item{use.branch.lengths}{
+If use.branch.lengths=FALSE, then all branch lengths are changed to 1.
+}
+}
+\details{
+%%  ~~ If necessary, more details than the description above ~~
+}
+\value{
+%%  ~Describe the value returned
+%%  If it is a LIST, use
+%%  \item{comp1 }{Description of 'comp1'}
+%%  \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+Redding, D.W. and Mooers, A.O. (2006). Incorporating evolutionary measures into conservation
+prioritisation. Conservation Biology, 20, 1670-1678.
+
+Isaac, N.J.B., Turvey, S.T., Collen, B., Waterman, C. and Baillie, J.E.M. (2007). Mammals on
+the EDGE: conservation priorities based on threat and phylogeny. PLoS ONE, 2, e296.
+}
+\author{
+Karen Magnuson-Ford 
+Will Cornwell
+Arne Mooers
+Mark Vellend}
+\note{
+This function will return a vector of evolutionary distinctivenss for every species in the given tree.
+If only a subset of values are needed there are two, concetually distinct options: either prune the tree first and then pass the tree in or subset the resulting vector.  These two options
+will provide very different outputs.  
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+}
+\examples{
+##---- Should be DIRECTLY executable !! ----
+##-- ==>  Define data, use random,
+##--	or do  help(data=index)  for the standard data sets.
+
+## The function is currently defined as
+function(tree, type=c("equal.splits", "fair.proportion"), scale=F, use.branch.lengths=TRUE){
+
+if(is.rooted(tree)==FALSE)
+warning("A rooted phylogeny is required for meaningful output of this function", call.=FALSE)
+
+if(scale==TRUE){
+#Scale tree to have unit depth (for an ultrametric tree) or scale all branches to unit length (for an additive tree)
+
+if(is.ultrametric(tree)==TRUE)
+tree<- rescaleTree(tree, 1) else 
+tree$edge.length<- tree$edge.length/sum(tree$edge.length)
+  }
+
+if(use.branch.lengths==FALSE)
+tree<- speciationalTree(tree)
+
+for(i in 1:length(tree$tip.label)){
+	spp<- tree$tip.label[i]
+	nodes<- get.nodes(tree, spp)
+	#get rid of root node
+	nodes<- nodes[1:(length(nodes)-1)]
+	
+	internal.brlen<- tree$edge.length[which(tree$edge[,2] \%in\% nodes)]
+
+#apportion internal branch lengths appropriately
+if(length(internal.brlen)!=0){
+internal.brlen<- internal.brlen*switch(type,
+	"equal.splits"=	sort(rep(.5,length(internal.brlen))^c(1:length(internal.brlen))),
+	"fair.proportion"= 1/for(j in 1:length(nodes)){
+		n.descendents<- length(node.leaves(tree, nodes[j]))
+		if(j==1)
+		portion<- n.descendents else
+		portion<- c(n.descendents, portion)
+		})}
+	
+	#sum internal branch lengths with the pendant edge
+	ED<- sum(internal.brlen, tree$edge.length[which.edge(tree, spp)])
+	
+	if(i==1)
+	w<- ED else
+	w<- c(w, ED)
+	}
+results<- cbind(tree$tip.label, as.data.frame(w))
+names(results)<- c("Species", "w")
+results
+	
+	}
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line

Added: branches/will/man/get.nodes.Rd
===================================================================
--- branches/will/man/get.nodes.Rd	                        (rev 0)
+++ branches/will/man/get.nodes.Rd	2009-11-19 00:26:45 UTC (rev 198)
@@ -0,0 +1,57 @@
+\name{get.nodes}
+\Rdversion{1.1}
+\alias{get.nodes}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+gets nodes along the evolutionary path to a given species
+}
+\description{
+Get a vector of the nodes that are along the path from the root to spp x.  Used in other functions.
+}
+\usage{
+get.nodes(tree, spp)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{tree}{
+APP tree
+}
+  \item{spp}{
+specific species; same format as which.edge in the APE library
+}
+}
+
+
+\author{
+Karen Magnuson-Ford 
+Will Cornwell
+Arne Mooers
+Mark Vellend
+}
+
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+
+\examples{
+##---- Should be DIRECTLY executable !! ----
+##-- ==>  Define data, use random,
+##--	or do  help(data=index)  for the standard data sets.
+
+## The function is currently defined as
+function(tree, spp){
+	edge<- which.edge(tree, spp)
+	nodes<- tree$edge[edge,1] 
+	root.edge<- which(tree$edge[,1]==(length(tree$tip.label)+1))
+while(!(edge \%in\% root.edge)){
+	edge<- which.edge(tree, tree$edge[edge,1])
+	next.node<- tree$edge[edge,1]
+	nodes<- c(nodes, next.node)
+	}
+	nodes
+	}
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line



More information about the Picante-commits mailing list