From 40eeb40e48bccc220826860ce0ada4521cbc0148 Mon Sep 17 00:00:00 2001 From: paradis Date: Thu, 5 Apr 2012 05:27:15 +0000 Subject: [PATCH] final warp for ape 3.0-2 git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@185 6e262413-ae40-0410-9e79-b911bd7a66b7 --- DESCRIPTION | 2 +- NEWS | 4 ++++ R/dist.gene.R | 18 ++++++++++-------- man/dist.gene.Rd | 2 +- man/triangMtd.Rd | 5 +++++ src/mvr.c | 4 ++-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index db205a7..a9eed55 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 3.0-2 -Date: 2012-04-02 +Date: 2012-04-05 Title: Analyses of Phylogenetics and Evolution Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Andrei-Alin Popescu, Klaus Schliep, Korbinian Strimmer, Damien de Vienne Maintainer: Emmanuel Paradis diff --git a/NEWS b/NEWS index 409322f..1848597 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,10 @@ OTHER CHANGES triangMtds.c have been improved which should fix some bugs in the corresponding functions. + o dist.gene() now coerces input data frame as matrix resulting in + much faster calculations (thanks to a suggestion by Markus + Schlegel). + CHANGES IN APE VERSION 3.0-1 diff --git a/R/dist.gene.R b/R/dist.gene.R index bee883c..516812a 100644 --- a/R/dist.gene.R +++ b/R/dist.gene.R @@ -1,8 +1,8 @@ -## dist.gene.R (2009-04-01) +## dist.gene.R (2012-04-02) ## Pairwise Distances from Genetic Data -## Copyright 2002-2009 Emmanuel Paradis +## Copyright 2002-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -11,8 +11,10 @@ dist.gene <- function(x, method = "pairwise", pairwise.deletion = FALSE, variance = FALSE) { - if (!is.data.frame(x) && !is.matrix(x)) - stop("'x' should be a matrix or a data.frame") + if (is.data.frame(x)) x <- as.matrix(x) else { # suggestion by Markus Schlegel + if (!is.matrix(x)) + stop("'x' should be a matrix or a data.frame") + } method <- match.arg(method, c("pairwise", "percentage")) if (!pairwise.deletion) { @@ -23,15 +25,15 @@ dist.gene <- n <- dim(x) L <- n[2] n <- n[1] - D <- double(n*(n - 1)/2) + D <- double(n * (n - 1)/2) if (pairwise.deletion) L <- D - k <- 1 + k <- 1L for (i in 1:(n - 1)) { for (j in (i + 1):n) { y <- x[i, ] != x[j, ] if (pairwise.deletion) L[k] <- sum(!is.na(y)) D[k] <- sum(y, na.rm = TRUE) - k <- k + 1 + k <- k + 1L } } ## L is either a single integer value if pairwise.deletion = FALSE, @@ -48,7 +50,7 @@ dist.gene <- if (variance) { y <- if (method == "pairwise") L else 1 - attr(D, "variance") <- D*(y - D)/L + attr(D, "variance") <- D * (y - D)/L } D } diff --git a/man/dist.gene.Rd b/man/dist.gene.Rd index 11d6d2e..6d5ccb3 100644 --- a/man/dist.gene.Rd +++ b/man/dist.gene.Rd @@ -6,7 +6,7 @@ dist.gene(x, method = "pairwise", pairwise.deletion = FALSE, variance = FALSE) } \arguments{ - \item{x}{a matrix or a data frame.} + \item{x}{a matrix or a data frame (will be coerced as a matrix).} \item{method}{a character string specifying the method used to compute the distances; two choices are available: \code{"pairwise"} and \code{"percentage"}, or any unambiguous abbreviation of these.} diff --git a/man/triangMtd.Rd b/man/triangMtd.Rd index af58c51..5a6f28d 100644 --- a/man/triangMtd.Rd +++ b/man/triangMtd.Rd @@ -24,4 +24,9 @@ triangMtds(X) \code{\link{nj}}, \code{\link{bionj}}, \code{\link{fastme}}, \code{\link{njs}}, \code{\link{mvrs}}, \code{\link{SDM}} } +\examples{ +data(woodmouse) +tr <- triangMtd(dist.dna(woodmouse)) +plot(tr) +} \keyword{models} diff --git a/src/mvr.c b/src/mvr.c index f272982..f400775 100644 --- a/src/mvr.c +++ b/src/mvr.c @@ -1,4 +1,4 @@ -/* mvr.c 2012-04-02 */ +/* mvr.c 2012-05-02 */ /* Copyright 2011-2012 Andrei-Alin Popescu */ @@ -133,7 +133,7 @@ void mvr(double *D, double* v,int *N, int *edge1, int *edge2, double *edge_lengt eLenSum+=wi*(D[give_index(i,OTU2,n)]-D[give_index(i,OTU1,n)]); }*/ - edge_length[k+1]=D[give_index(OTU1,OTU2,n)]/2 - edge_length[k]; + edge_length[k+1]=D[give_index(OTU1,OTU2,n)] - edge_length[k]; A = D[smallest]; ij = 0; -- 2.39.2