]> git.donarmstrong.com Git - ape.git/blobdiff - R/DNA.R
bug fix in root()
[ape.git] / R / DNA.R
diff --git a/R/DNA.R b/R/DNA.R
index e8e2260486503f666486be1791a084a5961f3e3e..e51f252eb7b77421fad835d13ae7671ddae32d00 100644 (file)
--- a/R/DNA.R
+++ b/R/DNA.R
@@ -1,4 +1,4 @@
-## DNA.R (2008-03-10)
+## DNA.R (2008-06-08)
 
 ##   Manipulations and Comparisons of DNA Sequences
 
@@ -7,6 +7,27 @@
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
 
+del.gaps <- function(x)
+{
+    deleteGaps <- function(x) {
+        i <- which(x == 4)
+        x[-i]
+    }
+
+    if (class(x) != "DNAbin") x <- as.DNAbin(x)
+    if (is.matrix(x)) {
+        n <- dim(x)[1]
+        y <- vector("list", n)
+        for (i in 1:n) y[[i]] <- x[i, ]
+        x <- y
+        rm(y)
+    }
+    if (!is.list(x)) return(deleteGaps(x))
+    x <- lapply(x, deleteGaps)
+    class(x) <- "DNAbin"
+    x
+}
+
 as.alignment <- function(x)
 {
     if (is.list(x)) n <- length(x)
@@ -215,14 +236,11 @@ base.freq <- function(x)
     BF
 }
 
-GC.content <- function(x)
-{
-    BF <- base.freq(x)
-    sum(BF[2:3])
-}
+GC.content <- function(x) sum(base.freq(x)[2:3])
 
 seg.sites <- function(x)
 {
+    if (is.list(x)) x <- as.matrix(x)
     n <- dim(x)
     s <- n[2]
     n <- n[1]