#' Builds all input files and an script to run all analyses in Galax for comparisons between partitions according to the ontology structure
#' represented as a semantic similarity dendrogram or another type of reference dendrogram (e.g., based on phylogenetic dissonance).
#'
#' @param struc list, the output from the ontostructure function.
#' @param ids data.frame, matches between characters and anatomical entities.
#' The first column should provide character ids in the same order as presented in the character matrix.
#' The second column should provide the respective ontology ids referring to the anatomical entities.
#' The third column should provide the respective ontology terms referring to the anatomical entities.
#' See examples provided in the data folder (data1.csv and data2.csv).
#' @param runs integer, the number of independent runs of mcmc used in the MrBayes commands block. Default is set to 2.
#' @param burnin integer, the absolute number of trees as the burn-in used in the mcmc. Default is set to 251.
#' @param OS character, sets the operational system to produce batch files for. Options are "windows" and "unix". Default is set to "windows".
#' @param filename character, name of the output file.
#'
#' @return All necessary input files, organized in subfolders inside the GALAX/INPUT/structure folder,
#' and an script to run all Galax analyses.
#'
#' @examples
#' \dontrun{
#' # HAO example #
#' # Create ID object #
#' ID <- as.data.frame(cbind(paste0("C", 1:40),
#' c(rep("HAO:0000506",5), rep("HAO:0000513",5), rep("HAO:0000453",5), rep("HAO:0000234",5),
#' rep("HAO:0001003",5), rep("HAO:0000874",5), rep("HAO:0000583",5), rep("HAO:0000630",5)),
#' c(rep("mandible",5), rep("maxilla",5), rep("labium",5), rep("cranium",5)
#' , rep("tentorium",5), rep("prothorax",5), rep("mesothorax",5), rep("metathorax",5))))
#'
#' # Import and visualize results from pairwise comparisons of terms #
#' pp <- bayesinfo_pairwise(ids = ID, runs = 2, profile = F, cluster = T)
#'
#' # Get hierarchical structure based on dissonance dendrogram #
#' hstruc1 <- ontostructure(dsm = pp, manual = T, plot = F)
#'
#' # Files to run analyses based on the dissonance dendrogram #
#' galaxscript_structure(struc = hstruc1, ids = ID, runs = 2, burnin = 251, OS = "windows", filename = "galaxstr1")
#'
#' # UBERON example #
#' # Create ID object #
#' ID <- as.data.frame(cbind(paste0("C", 1:40),
#' c(rep("UBERON_0002244",5), rep("UBERON_0002397",5), rep("UBERON_0004742",5), rep("UBERON_2000658",5),
#' rep("UBERON_2000488",5), rep("UBERON_0000151",5), rep("UBERON_0000152",5), rep("UBERON_0003097",5)),
#' c(rep("premaxilla",5), rep("maxilla",5), rep("dentary",5), rep("epibranchial bone",5)
#' , rep("ceratobranchial bone",5), rep("pectoral fin",5), rep("pelvic fin",5), rep("dorsal fin",5))))
#'
#' # Get hierarchical structure based on semantic similarity dendrogram #
#' hstruc2 <- ontostructure(ids = ID, manual = F, plot = F, similarity = "jaccard")
#'
#' # Files to run analyses based on the semantic similarity dendrogram #
#' galaxscript_structure(struc = hstruc2, ids = ID, runs = 2, burnin = 251, OS = "windows", filename = "galaxstr2")
#' }
#'
#' @export
galaxscript_structure <- function(struc = struc, ids = ids, runs = 2, burnin = 251, OS = "windows", filename = "galaxscript")
{
# Create input and output folders for Galax #
dir.create(file.path("GALAX", "INPUT", "structure"), recursive = T)
dir.create(file.path("GALAX", "OUTPUT", "structure"), recursive = T)
# Adjust ontology term names #
ids <- unique(ids[,3])
ids <- gsub(ids, pattern = " ", replacement = "_")
ids <- gsub(ids, pattern = "/", replacement = "-")
# Get all paths to tree files #
if(OS == "windows"){
paths <- paste0("NEXUS\\ALL_PART\\", paste0(1:length(ids), "_", ids), "\\", ids, ".nex.run")
}
if(OS == "unix"){
paths <- paste0("NEXUS/ALL_PART/", paste0(1:length(ids), "_", ids), "/", ids, ".nex.run")
}
# Build a correspondence table #
x <- cbind(ids, paths)
# Get all nodes corresponding to subtrees from the structure tree #
nodes <- names(struc)
# Create a block to store some variables #
block <- character()
for(i in 1:length(nodes)){
# Get all paths for terms included in a given subtree #
z <- x[x[,1] %in% struc[[i]],2]
for(j in 1:runs){
# Write among-partitions files for each group and run #
write(paste0(z, j, '.t'), file = paste0("./GALAX/INPUT/structure/", nodes[i], "_run", j, ".txt"))
if(OS == "windows"){
# Write all lines of galax commands for the bat file #
v <- paste0("galax -l GALAX\\INPUT\\structure\\", nodes[i], "_run", j,".txt", " -s ",
burnin, " -g 1 -o GALAX\\OUTPUT\\structure\\", "galax_", nodes[i], "_run", j)
block <- c(block, v)
}
if(OS == "unix"){
# Write all lines of galax commands for the sh file #
v <- paste0("galax --listfile GALAX/INPUT/structure/", nodes[i], "_run", j, ".txt", " --skip ",
burnin, " --outgroup 1 --outfile GALAX/OUTPUT/structure/", "galax_", nodes[i], "_run", j)
block <- c(block, v)
}
}
}
if(OS == "windows"){
# Create the headings for the bat file #
headline <- paste(
"@echo off",
"set PATH=bin;%PATH%",
"galax.exe %*",
sep = "\n")
# Write bat file for Windows #
write(c(headline, block), file = paste0(filename, ".bat"))
}
if(OS == "unix"){
# Create the headings for the sh file #
headline <- "#!/bin/bash"
# Write sh file for Unix #
write(c(headline, block), file = paste0(filename, ".sh"))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.