]> git.donarmstrong.com Git - ape.git/commitdiff
bug fix in seg.sites + new option in base.freq
authorparadis <paradis@6e262413-ae40-0410-9e79-b911bd7a66b7>
Wed, 16 Sep 2009 13:02:36 +0000 (13:02 +0000)
committerparadis <paradis@6e262413-ae40-0410-9e79-b911bd7a66b7>
Wed, 16 Sep 2009 13:02:36 +0000 (13:02 +0000)
git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@89 6e262413-ae40-0410-9e79-b911bd7a66b7

ChangeLog
DESCRIPTION
R/DNA.R
man/base.freq.Rd
man/seg.sites.Rd
src/dist_dna.c

index 5028e760afe10da2418ce224643490dad9d12b39..b9e9e593c7a87c84907d54373e79ec8d8c867c26 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+               CHANGES IN APE VERSION 2.3-4
+
+
+NEW FEATURES
+
+    o base.freq() has a new option 'freq' to return the counts; the
+      default is still to return the proportions.
+
+
+BUG FIXES
+
+    o seg.sites() did not handle ambiguous nucleotides correctly: they are
+      now ignored.
+
+
                CHANGES IN APE VERSION 2.3-3
 
 
index 85aee0b9d4241fbf64514294947b17494508aebd..4aa608cbe7624e9a7e0cc3d081a61f908be2a95d 100644 (file)
@@ -1,6 +1,6 @@
 Package: ape
-Version: 2.3-3
-Date: 2009-09-09
+Version: 2.3-4
+Date: 2009-09-16
 Title: Analyses of Phylogenetics and Evolution
 Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Gangolf Jobb, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Korbinian Strimmer, Damien de Vienne
 Maintainer: Emmanuel Paradis <Emmanuel.Paradis@ird.fr>
diff --git a/R/DNA.R b/R/DNA.R
index dd9c60bb63ace9abfe1350c73664e365ed91ac36..919f0ecd88912e69ff85b2ee04181d122936eb7b 100644 (file)
--- a/R/DNA.R
+++ b/R/DNA.R
@@ -259,11 +259,11 @@ as.character.DNAbin <- function(x, ...)
     if (is.list(x)) lapply(x, f) else f(x)
 }
 
-base.freq <- function(x)
+base.freq <- function(x, freq = FALSE)
 {
     if (is.list(x)) x <- unlist(x)
     n <- length(x)
-    BF <- .C("BaseProportion", x, n, double(4),
+    BF <- .C("BaseProportion", x, n, double(4), freq,
              DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[3]]
     names(BF) <- letters[c(1, 3, 7, 20)]
     BF
index 3847d9cf20c522fc1893048815fd00a76dfe7059..96414a5f2e6234c32dfbc1cfbb493f4f28960e1d 100644 (file)
@@ -2,14 +2,16 @@
 \alias{base.freq}
 \title{Base frequencies from DNA Sequences}
 \usage{
-base.freq(x)
+base.freq(x, freq = FALSE)
 }
 \arguments{
   \item{x}{a vector, a matrix, or a list which contains the DNA
     sequences.}
+  \item{freq}{a logical specifying whether to return the proportions
+    (the default) or the absolute frequencies (counts).}
 }
 \description{
-  This function computes the relative frequencies (i.e. percentages) of
+  This function computes the relative frequencies (i.e. proportions) of
   the four DNA bases (adenine, cytosine, guanine, and thymidine) from a
   sample of sequences.
 }
@@ -19,7 +21,7 @@ base.freq(x)
   computations.
 }
 \value{
-  A numeric vector stoting the relative frequencies with names
+  A numeric vector storing the relative frequencies with names
   \code{c("a", "c", "g", "t")}.
 }
 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}}
index 19efd2b1b31d7d51da2b0034ad21f2dd75894823..8f97c52ec16e6b98c70da739059b1f9d29748d5f 100644 (file)
@@ -15,10 +15,11 @@ seg.sites(x)
 }
 \details{
   If the sequences are in a list, all the sequences must be of the same
-  length.
+  length. Ambiguous nucleotides are ignored.
 }
 \value{
-  A numeric vector giving the indices of the segregating sites.
+  A numeric (integer) vector giving the indices of the segregating
+  sites.
 }
 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}}
 \note{
index d56c794334beee45f113cef278d5c38dea5a5147..2aa6da6be9531dd1c24ba7d5c90e66c9afe27cc1 100644 (file)
@@ -1,4 +1,4 @@
-/* dist_dna.c       2008-12-22 */
+/* dist_dna.c       2009-09-16 */
 
 /* Copyright 2005-2008 Emmanuel Paradis
 
@@ -12,7 +12,7 @@
 #define LN4 1.386294361119890572454
 
 /* returns 8 if the base is known surely, 0 otherwise */
-#define KnownBase(a) a & 8
+#define KnownBase(a) (a & 8)
 
 /* returns 1 if the base is adenine surely, 0 otherwise */
 #define IsAdenine(a) a == 136
@@ -951,7 +951,7 @@ void distDNA_ParaLin_pairdel(unsigned char *x, int *n, int *s, double *d,
     }
 }
 
-void BaseProportion(unsigned char *x, int *n, double *BF)
+void BaseProportion(unsigned char *x, int *n, double *BF, int *freq)
 {
     int i, m;
 
@@ -967,7 +967,7 @@ void BaseProportion(unsigned char *x, int *n, double *BF)
            }
        }
     }
-    for (i = 0; i < 4; i++) BF[i] /= m;
+    if (! *freq) for (i = 0; i < 4; i++) BF[i] /= m;
 }
 
 void SegSites(unsigned char *x, int *n, int *s, int *seg)
@@ -981,7 +981,7 @@ void SegSites(unsigned char *x, int *n, int *s, int *seg)
        basis = x[i];
        i++;
        while (i < *n * (j + 1)) {
-           if (x[i] == basis) i++;
+           if (!KnownBase(x[i]) || x[i] == basis) i++;
            else {
                seg[j] = 1;
                break;