X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fwrite.dna.R;h=3f53cb91d3e44ed82e7fda200add179bda13f1c3;hb=0d2caf41f13f7a3e8a313274cf819147940eac69;hp=59712eafb182d1be4410d582fce08c4a99a5f160;hpb=a1b67d97d7bf71af111e8675588c78dfc41a0bed;p=ape.git diff --git a/R/write.dna.R b/R/write.dna.R index 59712ea..3f53cb9 100644 --- a/R/write.dna.R +++ b/R/write.dna.R @@ -1,8 +1,8 @@ -## write.dna.R (2008-07-03) +## write.dna.R (2012-06-22) ## Write DNA Sequences in a File -## Copyright 2003-2008 Emmanuel Paradis +## Copyright 2003-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -13,7 +13,7 @@ write.dna <- function(x, file, format = "interleaved", append = FALSE, { format <- match.arg(format, c("interleaved", "sequential", "fasta")) phylip <- if (format %in% c("interleaved", "sequential")) TRUE else FALSE - if (class(x) == "DNAbin") x <- as.character(x) + if (inherits(x, "DNAbin")) x <- as.character(x) aligned <- TRUE if (is.matrix(x)) { N <- dim(x) @@ -62,13 +62,11 @@ write.dna <- function(x, file, format = "interleaved", append = FALSE, } ## Prepare the names so that they all have the same nb of chars max.nc <- max(nchar(names(x))) - ## in case all names are 10 char long or less, sequences are - ## always started on the 11th column of the file - if (max.nc < 11) max.nc <- 9 + ## always put a space between the sequences and the taxa names fmt <- paste("%-", max.nc + 1, "s", sep = "") names(x) <- sprintf(fmt, names(x)) } - if (format == "interleaved") { + switch(format, "interleaved" = { ## Write the first block with the taxon names colsel <- if (nb.block == 1) 1:totalcol else 1:nbcol for (i in 1:N) { @@ -89,8 +87,7 @@ write.dna <- function(x, file, format = "interleaved", append = FALSE, } } - } - if (format == "sequential") { + }, "sequential" = { if (nb.block == 1) { for (i in 1:N) { cat(names(x)[i], file = zz) @@ -110,10 +107,9 @@ write.dna <- function(x, file, format = "interleaved", append = FALSE, } } } - } - if (format == "fasta") { + }, "fasta" = { for (i in 1:N) { - cat(">", names(x)[i], file = zz) + cat(">", names(x)[i], file = zz, sep = "") cat("\n", file = zz) X <- paste(x[[i]], collapse = "") S <- length(x[[i]]) @@ -131,5 +127,5 @@ write.dna <- function(x, file, format = "interleaved", append = FALSE, cat("\n", file = zz) } } - } + }) }