-## write.nexus.R (2011-03-26)
+## write.nexus.R (2012-02-09)
## Write Tree File in Nexus Format
-## Copyright 2003-2011 Emmanuel Paradis
+## Copyright 2003-2012 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
-write.nexus <- function(..., file = "", translate = TRUE, original.data = TRUE)
+write.nexus <- function(..., file = "", translate = TRUE, original.data = NULL)
{
obj <- list(...)
## We insure that all trees are in a list, even if there is a single one:
cat("#NEXUS\n", file = file)
cat(paste("[R-package APE, ", date(), "]\n\n", sep = ""),
file = file, append = TRUE)
- if (original.data) {
- if (!is.null(attr(obj[[1]], "origin"))) {
- if (!file.exists(attr(obj[[1]], "origin"))) {
- warning(paste("the file", attr(obj[[1]], "origin"),
- "cannot be found,
-the original data won't be written with the tree."))
- original.data <- FALSE
- }
- else {
- ORI <- scan(file = attr(obj[[1]], "origin"), what = character(),
- sep = "\n", skip = 1)
- start <- grep("BEGIN TAXA;", ORI)
- ORI <- ORI[-(1:(start - 1))]
- ORI <- gsub("ENDBLOCK;", "END;", ORI)
- endblock <- grep("END;", ORI)
- start <- grep("BEGIN TREES;", ORI)
- end <- endblock[endblock > start][1]
- cat(ORI[1:(start - 1)], file = file, append = TRUE, sep = "\n")
- ORI <- ORI[-(1:end)]
- }
- }
- else original.data <- FALSE
- }
+
+ if (!is.null(original.data))
+ warning("the option 'original.data' is deprecated and will be removed soon. Please update your code.")
+
N <- length(obj[[1]]$tip.label)
- if (!original.data) {
- cat("BEGIN TAXA;\n", file = file, append = TRUE)
- cat(paste("\tDIMENSIONS NTAX = ", N, ";\n", sep = ""),
- file = file, append = TRUE)
- cat("\tTAXLABELS\n", file = file, append = TRUE)
- cat(paste("\t\t", obj[[1]]$tip.label, sep = ""),
- sep = "\n", file = file, append = TRUE)
- cat("\t;\n", file = file, append = TRUE)
- cat("END;\n", file = file, append = TRUE)
- }
+
+ cat("BEGIN TAXA;\n", file = file, append = TRUE)
+ cat(paste("\tDIMENSIONS NTAX = ", N, ";\n", sep = ""),
+ file = file, append = TRUE)
+ cat("\tTAXLABELS\n", file = file, append = TRUE)
+ cat(paste("\t\t", obj[[1]]$tip.label, sep = ""),
+ sep = "\n", file = file, append = TRUE)
+ cat("\t;\n", file = file, append = TRUE)
+ cat("END;\n", file = file, append = TRUE)
+
cat("BEGIN TREES;\n", file = file, append = TRUE)
if (translate) {
cat("\tTRANSLATE\n", file = file, append = TRUE)
"\n", sep = "", file = file, append = TRUE)
}
cat("END;\n", file = file, append = TRUE)
- if(original.data) cat(ORI, file = file, append = TRUE, sep = "\n")
}