X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2FDNA.R;h=48e605484f877964815eef05fe055bbe51a69587;hb=c488b74490ee3d9d200de0e471881f002a18fe4f;hp=d1b3625f0da247fe8da35377d3762a81575add2b;hpb=be6a044200152fd83d0b72f348012a0adc2593c5;p=ape.git diff --git a/R/DNA.R b/R/DNA.R index d1b3625..48e6054 100644 --- a/R/DNA.R +++ b/R/DNA.R @@ -1,8 +1,8 @@ -## DNA.R (2012-12-27) +## DNA.R (2013-01-04) ## Manipulations and Comparisons of DNA Sequences -## Copyright 2002-2012 Emmanuel Paradis +## Copyright 2002-2013 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -65,17 +65,21 @@ as.alignment <- function(x) as.matrix.DNAbin <- function(x, ...) { - if (is.list(x)) { - if (length(unique(unlist(lapply(x, length)))) != 1) - stop("DNA sequences in list not of the same length.") - nms <- names(x) - n <- length(x) - s <- length(x[[1]]) - x <- matrix(unlist(x), n, s, byrow = TRUE) - rownames(x) <- nms - class(x) <- "DNAbin" + if (is.matrix(x)) return(x) + if (is.vector(x)) { + dim(x) <- c(1, length(x)) + return(x) } - x + s <- unique(unlist(lapply(x, length))) + if (length(s) != 1) + stop("DNA sequences in list not of the same length.") + nms <- names(x) + n <- length(x) + y <- matrix(as.raw(0), n, s) + for (i in seq_len(n)) y[i, ] <- x[[i]] + rownames(y) <- nms + class(y) <- "DNAbin" + y } as.list.DNAbin <- function(x, ...) @@ -392,7 +396,10 @@ dist.dna <- function(x, model = "K80", variance = FALSE, gamma = FALSE, Ndist <- if (imod == 11) n*n else n*(n - 1)/2 var <- if (variance) double(Ndist) else 0 if (!gamma) gamma <- alpha <- 0 - else alpha <- gamma <- 1 + else { + alpha <- gamma + gamma <- 1 + } d <- .C("dist_dna", x, as.integer(n), as.integer(s), imod, double(Ndist), BF, as.integer(pairwise.deletion), as.integer(variance), var, as.integer(gamma),