]> git.donarmstrong.com Git - ape.git/commitdiff
final warp for ape 3.0-2
authorparadis <paradis@6e262413-ae40-0410-9e79-b911bd7a66b7>
Thu, 5 Apr 2012 05:27:15 +0000 (05:27 +0000)
committerparadis <paradis@6e262413-ae40-0410-9e79-b911bd7a66b7>
Thu, 5 Apr 2012 05:27:15 +0000 (05:27 +0000)
git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@185 6e262413-ae40-0410-9e79-b911bd7a66b7

DESCRIPTION
NEWS
R/dist.gene.R
man/dist.gene.Rd
man/triangMtd.Rd
src/mvr.c

index db205a7954f00e1a584568439ad02b04362588f1..a9eed554c5d4e05560fb6eb7b4dee7644ed14bce 100644 (file)
@@ -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 <Emmanuel.Paradis@ird.fr>
diff --git a/NEWS b/NEWS
index 409322ffca7ce6e5d1d2348ab4e75e76a0f3b51b..18485974832ad5157a9c413d79334e09afdce807 100644 (file)
--- 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
index bee883c9b3e266e9bdda1c8bb4b23526812f31ed..516812a94e1d617088003f688c1670f458ec5553 100644 (file)
@@ -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
 }
index 11d6d2e79a123e46e150fd677dedf6ebe7359136..6d5ccb3d1c84b894a001f0673cdd4b330b8f4e56 100644 (file)
@@ -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.}
index af58c51bcb3db025c98db590758db9ac018c336a..5a6f28dc56e5e1016ccf909e8b63e79e5368d400 100644 (file)
@@ -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}
index f27298265a706dbbbf09ad7c2728f4b78fc6e527..f400775718c22dcda6f3fbaf6a87e97d647fbb17 100644 (file)
--- 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;