[Adephylo-commits] r30 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 25 18:55:45 CET 2008
Author: jombart
Date: 2008-11-25 18:55:45 +0100 (Tue, 25 Nov 2008)
New Revision: 30
Modified:
pkg/R/distances.R
pkg/R/utils.R
pkg/man/distTips.Rd
Log:
Fixes for distTips.
Modified: pkg/R/distances.R
===================================================================
--- pkg/R/distances.R 2008-11-25 17:16:37 UTC (rev 29)
+++ pkg/R/distances.R 2008-11-25 17:55:45 UTC (rev 30)
@@ -9,9 +9,10 @@
## handle arguments
x <- as(x, "phylo4")
method <- match.arg(method)
+ N <- nTips(x)
+ if(tips[1]=="all") { tips <- 1:N }
tips <- getnodes(x, tips)
- N <- nTips(x)
- if(tips=="all") { tips <- 1:N }
+ tips.names <- names(tips)
## some checks
if (is.character(checkval <- check_phylo4(x))) stop(checkval)
@@ -54,12 +55,10 @@
edge.idx <- lapply(allPath, function(e) getedges(x, e) ) # list of indices of edges
allEdgeLength <- edgeLength(x)
res <- lapply(edge.idx, function(idx) sum(allEdgeLength[idx], na.rm=TRUE) )
- return(res)
} # end brlength
if(method=="nNodes"){
res <- lapply(allPath, length)
- return(res)
} # end nNodes
if(method=="Abouheif"){
@@ -69,7 +68,6 @@
return(prod(temp))
}
res <- lapply(allPath, f1)
- return(res)
} # end Abouheif
if(method=="sumDD"){
@@ -79,18 +77,23 @@
return(sum(temp))
}
res <- lapply(allPath, f1)
- return(res)
-
} # end sumDD
+ ## convert res to a dist object
+ res <- unlist(res)
+ class(res) <- "dist"
+ attr(res, "Size") <- length(res)
+ attr(res, "Diag") <- FALSE
+ attr(res, "Upper") <- FALSE
+ attr(res, "method") <- paste("Phylogenetic: ",method,sep="")
+ attr(res, "call") <- match.call()
+ attr(res, "Labels") <- tips.names
+
+ return(res)
+
} # end distNodes
-## examples
-# source("/home/master/dev/adephylo/pkg/R/distances.R")
- x <- as(rtree(10),"phylo4")
- plot(x, show.node=TRUE)
- axisPhylo()
Modified: pkg/R/utils.R
===================================================================
--- pkg/R/utils.R 2008-11-25 17:16:37 UTC (rev 29)
+++ pkg/R/utils.R 2008-11-25 17:55:45 UTC (rev 30)
@@ -102,14 +102,14 @@
# examples
# source("/home/master/dev/adephylo/pkg/R/utils.R")
#phy <- as(rtree(15),"phylo4")
-plot(phy,show.n=T)
-tip1 <- "t1"
-tip2 <- "t2"
+## plot(phy,show.n=T)
+## tip1 <- "t1"
+## tip2 <- "t2"
-sp.tips(phy, "t1", "t2")
-sp.tips(phy, rep(1,15), 1:15)
-sp.tips(phy, rep(1, 15), 1:15, TRUE)
+## sp.tips(phy, "t1", "t2")
+## sp.tips(phy, rep(1,15), 1:15)
+## sp.tips(phy, rep(1, 15), 1:15, TRUE)
## heavier tree
# x <- as(rtree(1000), "phylo4")
Modified: pkg/man/distTips.Rd
===================================================================
--- pkg/man/distTips.Rd 2008-11-25 17:16:37 UTC (rev 29)
+++ pkg/man/distTips.Rd 2008-11-25 17:55:45 UTC (rev 30)
@@ -1,14 +1,14 @@
-\name{distNodes}
-\alias{distNodes}
+\name{distTips}
+\alias{distTips}
\title{Compute some phylogenetic distance between two nodes}
\description{
- The function \code{distNodes} computes a given distance between two
- nodes of a phylogeny. This distance corresponds to the shortest path
- between the two nodes. Several distances can be used, defaulting to the
+ The function \code{distTips} computes a given distance between a set
+ of tips of a phylogeny. This distance is computed from the shortest path
+ between the nodes. Several distances can be used, defaulting to the
sum of branch lengths (see argument \code{method}).
}
\usage{
-distNodes(x, node1, node2, method=c("brlength","nNodes","Abouheif","sumDD"))
+distTips(x, tips, method=c("brlength","nNodes","Abouheif","sumDD"))
}
\arguments{
\item{x}{a tree of class \code{\link[pkg:ape]{phylo}},
@@ -54,10 +54,10 @@
plot(x, show.node=TRUE)
axisPhylo()
## compute different distances
-distNodes(x, "t1", "t2")
-distNodes(x, "t1", "t2", "nNodes")
-distNodes(x, "t1", "t2", "Abouheif")
-distNodes(x, "t1", "t2", "sumDD")
+distTips(x, 1:3)
+distTips(x, 1:3, "nNodes")
+distTips(x, 1:3, "Abouheif")
+distTips(x, 1:3, "sumDD")
}
}
\keyword{manip}
More information about the Adephylo-commits
mailing list