-## 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.
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, ...)
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),