X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2FDNA.R;h=d1b3625f0da247fe8da35377d3762a81575add2b;hb=be6a044200152fd83d0b72f348012a0adc2593c5;hp=1d0ce795037c98faf042197af5f572bb1de4d5fa;hpb=dff741171e7afe3f9aaa2d9cb19c2f91995e8623;p=ape.git diff --git a/R/DNA.R b/R/DNA.R index 1d0ce79..d1b3625 100644 --- a/R/DNA.R +++ b/R/DNA.R @@ -1,4 +1,4 @@ -## DNA.R (2012-11-28) +## DNA.R (2012-12-27) ## Manipulations and Comparisons of DNA Sequences @@ -58,21 +58,8 @@ as.alignment <- function(x) "[.DNAbin" <- function(x, i, j, drop = FALSE) { - oc <- oldClass(x) - class(x) <- NULL - if (is.matrix(x)) { - if (nargs() == 2 && !missing(i)) ans <- x[i] - else { - nd <- dim(x) - if (missing(i)) i <- 1:nd[1] - if (missing(j)) j <- 1:nd[2] - ans <- x[i, j, drop = drop] - } - } else { - if (missing(i)) i <- 1:length(x) - ans <- x[i] - } - class(ans) <- oc + ans <- NextMethod("[", drop = drop) + class(ans) <- "DNAbin" ans } @@ -293,10 +280,19 @@ as.character.DNAbin <- function(x, ...) base.freq <- function(x, freq = FALSE, all = FALSE) { - if (is.list(x)) x <- unlist(x) - n <- length(x) - BF <-.C("BaseProportion", x, as.integer(n), double(17), - DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[3]] + f <- function(x) + .C("BaseProportion", x, as.integer(length(x)), double(17), + DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[3]] + + if (is.list(x)) { + BF <- rowSums(sapply(x, f)) + n <- sum(sapply(x, length)) + } else { + n <- length(x) + BF <-.C("BaseProportion", x, as.integer(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) { @@ -481,7 +477,7 @@ where <- function(x, pattern) s <- as.integer(length(x)) if (s < p) stop("sequence shorter than the pattern") ans <- .C("where", x, pat, s, p, integer(s), 0L, - DUP = FALSE, NAOK = TRUE, PACKAGE = "apex") + DUP = FALSE, NAOK = TRUE, PACKAGE = "ape") n <- ans[[6]] if (n) ans[[5]][seq_len(n)] - p + 2L else integer() }