-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added table2nexus for a general conversion from data table into nexus. …
…Closes #6 and raises minor number
- Loading branch information
1 parent
d7c86a5
commit 6cef4e9
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: tbea | ||
Title: Tools for Pre- and Post-processing in Bayesian Evolutionary Analyses | ||
Version: 1.2.1 | ||
Version: 1.3.0 | ||
Authors@R: c(person("Gustavo A.", "Ballen", email = "[email protected]", role = c("aut", "cre")), | ||
person("Sandra", "Reinales", email = "[email protected]", role = c("aut"))) | ||
Description: Package for bayesian inference in phylogenetics and evolution. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#' table2nexus: Read a data matrix in delimited format and convert | ||
#' into a data matrix in nexus format | ||
#' | ||
#' @param path a character vector of length 1 with the path to the table | ||
#' file. | ||
#' | ||
#' @param datatype a character vector of length 1 with the desired datatype. | ||
#' Possible values are STANDARD, DNA, RNA, or PROTEIN. | ||
#' Multicharacter types such as continuous or nucleotide are not supported. | ||
#' | ||
#' @param header a logical vector of length 1 indicating whether the table file | ||
#' has a header. Defaults to FALSE. | ||
#' | ||
#' @param sep a character vector of length 1 telling the kind of separator in | ||
#' the table file. Defaults to comma ",". | ||
#' | ||
#' @param con the connection to which the matrix should be returned. Defaults | ||
#' to stdout(), that is, return the text to the console. If writing to a file, | ||
#' then this should be the path to the output file. | ||
#' | ||
#' @return This function writes to the connected required a matrix in nexus | ||
#' format for a morphological dataset (that is, datatype=standard). | ||
#' | ||
#' @author Gustavo A. Ballen | ||
#' | ||
#' @details This function will concatenate matrices in nexus format (mandatory) and write to the disk the output and summary information on the partitions. It requires that the input matrices all share the same taxa in the same positions. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # this will return the matrix to the console rather than to a file | ||
#' table2nexus(path="../prototipos/morpho.csv", datatype="standard", header=FALSE, sep=",") | ||
#' } | ||
#' @export | ||
#' @importFrom utils read.delim | ||
|
||
table2nexus <- function(path, datatype = c("standard", "dna", "rna", "protein"), header = FALSE, sep=",", con=stdout()) { | ||
DATATYPE <- toupper(match.arg(datatype)) | ||
df <- read.delim(path, sep=sep, header=header) | ||
if (header) { | ||
colnames(df) <- NULL | ||
} | ||
taxa <- df[[1]] | ||
NTAX <- length(taxa) | ||
df <- df[, -1] | ||
NCHAR <- ncol(df) | ||
chars <- apply(X=df, MARGIN=1, FUN=function(x) paste(x, collapse="")) | ||
NEXUSheader <- c("#NEXUS", | ||
"[Data written by table2nexus, _TIMESTAMP]", | ||
"BEGIN DATA;", | ||
" DIMENSIONS NTAX=_NTAX NCHAR=_NCHAR", | ||
" FORMAT DATATYPE=_DATATYPE MISSING=? GAP=- INTERLEAVE=NO;", | ||
" MATRIX") | ||
NEXUSheader <- gsub(pattern="_TIMESTAMP", replacement=Sys.time(), x=NEXUSheader) | ||
NEXUSheader <- gsub(pattern="_DATATYPE", replacement=DATATYPE, x=NEXUSheader) | ||
NEXUSheader <- gsub(pattern="_NTAX", replacement=NTAX, x=NEXUSheader) | ||
NEXUSheader <- gsub(pattern="_NCHAR", replacement=NCHAR, x=NEXUSheader) | ||
DATA <- paste(" ", taxa, " ", chars, sep="") | ||
OUTPUT <- c(NEXUSheader, DATA, " ;", "END;") | ||
writeLines(OUTPUT) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.