-
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.
This PR makes sure Phlorest phylogenies can be read by several common R packages. closes #36
- Loading branch information
Showing
9 changed files
with
115 additions
and
15 deletions.
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
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
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,58 @@ | ||
# install.packages('ape') | ||
# if (!require("BiocManager", quietly = TRUE)) | ||
# install.packages("BiocManager") | ||
# BiocManager::install("treeio") | ||
# install.packages('rncl') | ||
# remotes::install_github("ropensci/tracerer") | ||
# install.packages('testthat') | ||
|
||
library(ape) # APE: the standard package, no annotations | ||
suppressMessages(library(treeio)) # treeio: considered the 'newer' and 'better' package for trees | ||
library(rncl) # rncl: based on nexus class library, so should be fast but no annotations. | ||
library(tracerer) # tracerer: loads BEAST annotations | ||
|
||
library(testthat) | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
treefile <- args[1] | ||
ntrees <- strtoi(args[2]) | ||
res <- 0 | ||
|
||
readers <- list( | ||
"ape" = function(x) ape::read.nexus(x, force.multi = TRUE), | ||
"treeio" = function(x) treeio::read.beast(x), | ||
"rncl" = function(x) { | ||
trees <- rncl::read_nexus_phylo(x) | ||
# We force multi "by hand": | ||
if (class(trees) != 'multiPhylo'){ | ||
trees <- list(c(trees)) | ||
class(trees) <- "multiPhylo" | ||
} | ||
trees | ||
}, | ||
"tracerer" = function(x) tracerer::parse_beast_trees(x) | ||
) | ||
|
||
for (rdr in names(readers)) { | ||
# Only use tracerer with files with multiple trees, because it requires tree names to start | ||
# with STATE_ ... | ||
if (!(ntrees == 1 && rdr == 'tracerer')) { | ||
cat(sprintf("READER: %s -- %s\n", rdr, treefile)) | ||
tryCatch( | ||
expr = { | ||
t <- readers[[rdr]](treefile) | ||
# Make sure we read the correct number of trees: | ||
testthat::expect_equal(length(t), ntrees) | ||
cat('OK\n') | ||
}, | ||
error = function(e) { | ||
res <<- 1 | ||
print(e) | ||
}, | ||
warning = function(w) { | ||
print(w) | ||
} | ||
) | ||
} | ||
} | ||
quit(status=res) |
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
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