-## read.dna.R (2012-12-27)
+## read.dna.R (2013-01-04)
## Read DNA Sequences in a File
} else {
X <- scan(file = file, what = "", sep = "\n", quiet = TRUE,
skip = skip, nlines = nlines, comment.char = comment.char)
-
if (format %in% formats[1:2]) {
## need to remove the possible leading spaces and/or tabs in the first line
fl <- gsub("^[[:blank:]]+", "", X[1])
for (i in 2:n)
obj[i, ] <- getNucleotide(X[seq(i, nl, n + 1)])
})
-
+ }
if (format != "fasta") {
rownames(obj) <- taxa
+ if (!as.character) obj <- as.DNAbin(obj)
} else {
LENGTHS <- unique(unlist(lapply(obj, length)))
allSameLength <- length(LENGTHS) == 1
as.matrix <- allSameLength
}
if (as.matrix) {
- obj <- matrix(unlist(obj), ncol = LENGTHS, byrow = TRUE)
+ taxa <- names(obj)
+ n <- length(obj)
+ y <- matrix(as.raw(0), n, LENGTHS)
+ for (i in seq_len(n)) y[i, ] <- obj[[i]]
+ obj <- y
rownames(obj) <- taxa
+ class(obj) <- "DNAbin"
}
+ if (as.character) obj <- as.character(obj)
}
- if (!as.character) obj <- as.DNAbin(obj)
obj
}