-## read.dna.R (2008-07-03)
+## read.dna.R (2011-02-01)
## Read DNA Sequences in a File
-## Copyright 2003-2008 Emmanuel Paradis
+## Copyright 2003-2011 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
read.dna <- function(file, format = "interleaved", skip = 0,
nlines = 0, comment.char = "#", seq.names = NULL,
- as.character = FALSE)
+ as.character = FALSE, as.matrix = NULL)
{
getTaxaNames <- function(x) {
x <- sub("^['\" ]+", "", x) # remove the leading quotes and spaces
} else {
names(obj) <- seq.names
obj <- lapply(obj, tolower)
+ LENGTHS <- unique(unlist(lapply(obj, length)))
+ allSameLength <- length(LENGTHS) == 1
+ if (is.logical(as.matrix)) {
+ if (as.matrix && !allSameLength)
+ stop("sequences in FASTA file not of the same length")
+ } else {
+ as.matrix <- allSameLength
+ }
+ if (as.matrix) {
+ obj <- matrix(unlist(obj), ncol = LENGTHS, byrow = TRUE)
+ rownames(obj) <- seq.names
+ }
}
if (!as.character) obj <- as.DNAbin(obj)
obj