]> git.donarmstrong.com Git - ape.git/blobdiff - R/DNA.R
bug fixing in read.nexus() + Others....
[ape.git] / R / DNA.R
diff --git a/R/DNA.R b/R/DNA.R
index 722f7b4b9c9cabe100f3a7cd30deed790ff354cb..e71f14224450301526daec4b3621ad61451a5e96 100644 (file)
--- a/R/DNA.R
+++ b/R/DNA.R
@@ -1,8 +1,8 @@
-## DNA.R (2010-10-19)
+## DNA.R (2011-02-18)
 
 ##   Manipulations and Comparisons of DNA Sequences
 
-## Copyright 2002-2010 Emmanuel Paradis
+## Copyright 2002-2011 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -281,13 +281,20 @@ as.character.DNAbin <- function(x, ...)
     if (is.list(x)) lapply(x, f) else f(x)
 }
 
-base.freq <- function(x, freq = FALSE)
+base.freq <- function(x, freq = FALSE, all = FALSE)
 {
     if (is.list(x)) x <- unlist(x)
     n <- length(x)
-    BF <- .C("BaseProportion", x, n, double(4), freq,
-             DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[3]]
-    names(BF) <- letters[c(1, 3, 7, 20)]
+    BF <-.C("BaseProportion", x, n, double(17),
+            DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[3]]
+    names(BF) <- c("a", "c", "g", "t", "r", "m", "w", "s",
+                   "k", "y", "v", "h", "d", "b", "n", "-", "?")
+    if (all) {
+        if (!freq) BF <- BF / n
+    } else {
+        BF <- BF[1:4]
+        if (!freq) BF <- BF / sum(BF)
+    }
     BF
 }