[Phylobase-commits] r295 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 21 15:24:12 CET 2008
Author: jombart
Date: 2008-11-21 15:24:12 +0100 (Fri, 21 Nov 2008)
New Revision: 295
Modified:
pkg/R/treewalk.R
pkg/man/treewalk.Rd
Log:
Added a getedges function. It identifies the number of an edge given the number / label of its terminal node.
Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R 2008-11-21 10:28:41 UTC (rev 294)
+++ pkg/R/treewalk.R 2008-11-21 14:24:12 UTC (rev 295)
@@ -139,7 +139,7 @@
# shortestPath
###############
shortestPath <- function(phy, node1, node2){
- if(!require(phylobase)) stop("phylobase package is not installed")
+ ## if(!require(phylobase)) stop("phylobase package is not installed")
## conversion from phylo, phylo4 and phylo4d
x <- as(phy, "phylo4")
@@ -170,3 +170,30 @@
return(res)
} # end shortestPath
+
+
+
+
+
+###########
+# getedges
+###########
+getedges <- function(phy, node){
+
+ ## conversion from phylo, phylo4 and phylo4d
+ x <- as(phy, "phylo4")
+
+ ## come checks
+ if (is.character(checkval <- check_phylo4(x))) stop(checkval)
+ node <- getnodes(x, node)
+ if(any(is.na(node))) stop("wrong node specified")
+ root <- rootNode(x)
+ node[node==root] <- NA
+
+ ## main computations
+ E <- x at edge
+ res <- match(node, E[,2])
+ names(res) <- names(node)
+
+ return(res)
+} # end getedges
Modified: pkg/man/treewalk.Rd
===================================================================
--- pkg/man/treewalk.Rd 2008-11-21 10:28:41 UTC (rev 294)
+++ pkg/man/treewalk.Rd 2008-11-21 14:24:12 UTC (rev 295)
@@ -6,6 +6,7 @@
\alias{siblings}
\alias{MRCA}
\alias{getnodes}
+\alias{getedges}
\alias{shortestPath}
\title{tree traversal and utility functions}
\description{
@@ -42,6 +43,9 @@
\code{getnodes} takes character strings corresponding to tip or
node labels, or node numbers; it returns a named
vector of node numbers.
+ \code{getedges} takes character strings naming terminal
+ node of edges, or the corresponding node numbers; it returns a named
+ vector of edge numbers.
\code{ancestors} and \code{descendants}
return named vectors of the ancestors and descendants of
a node; \code{ancestor} is a synonym for
@@ -74,7 +78,12 @@
ancestors(geospiza,"N11")
MRCA(geospiza,"conirostris","difficilis","fuliginosa")
MRCA(geospiza,"olivacea","conirostris")
+ ## shortest path between 2 nodes
shortestPath(geospiza, "fortis","fuliginosa")
shortestPath(geospiza, "N02","N05")
+ ## identifying an edge fron its terminal node
+ getedges(geospiza,c("olivacea","N02","fortis"))
+ getnodes(geospiza, c("olivacea","N02","fortis"))
+ geospiza$edge[c(26,1,11),]
}
\keyword{misc}
More information about the Phylobase-commits
mailing list