# HG changeset patch # User mingchen0919 # Date 1521667587 14400 # Node ID b49e227ec73842de8c67544e0a63a375b509dbf3 planemo upload commit fe1408d418f7f1354a736f73ece704219baa3190 diff -r 000000000000 -r b49e227ec738 LICENSE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Staton Laboratory + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff -r 000000000000 -r b49e227ec738 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,1 @@ +# Dynamic Galaxy Tool wrappers diff -r 000000000000 -r b49e227ec738 dynamic_tool.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamic_tool.Rmd Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,14 @@ +--- +title: 'Dynamic tool' +output: html_document +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(error = TRUE) +``` + +# Dynamic tools + +```{r} +opt +``` diff -r 000000000000 -r b49e227ec738 dynamic_tool.csv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamic_tool.csv Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,13 @@ +short flag,argument mask,data type,variable name,galaxy input type,description +t,1,character,tool_name, +o,1,character,one_dataset_itmes, +m,1,character,multiple_dataset_items, +u,1,character,path_relative_to_upstream_tool_items, +s,1,character,string_items, +f,1,character,float_items, +i,1,character,integer_items, +R,1,character,report, +D,1,character,report.files_path, +H,1,character,tool_help_doc, +O,1,character,tool_output_dir, +L,1,character,tool_log, diff -r 000000000000 -r b49e227ec738 dynamic_tool.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamic_tool.xml Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,27 @@ + + + dynamic_tool_wrappers_macros.xml + + + + + fastqc + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r b49e227ec738 dynamic_tool_render.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamic_tool_render.R Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,50 @@ +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file('tool_log.txt') +sink(zz) +sink(zz, type = 'message') + +#------------import libraries-------------------- +options(stringsAsFactors = FALSE) + +library(getopt) +library(rmarkdown) +#------------------------------------------------ + + +#------------get arguments into R-------------------- +# load helper function +source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R')) +# import getopt specification matrix from a csv file +opt = getopt(getopt_specification_matrix('/dynamic_tool.csv')) +opt$X_T = Sys.getenv('TOOL_DIR') +#---------------------------------------------------- + + +#-----------using passed arguments in R +# to define system environment variables--- +do.call(Sys.setenv, opt[-1]) +#---------------------------------------------------- + +#---------- often used variables ---------------- +# OUTPUT_DIR: path to the output associated directory, which stores all outputs +# TOOL_DIR: path to the tool installation directory +OUTPUT_REPORT = opt$X_R +OUTPUT_DIR = opt$X_D +TOOL_DIR = opt$X_T +RMD_NAME = 'dynamic_tool.Rmd' + +# create the output associated directory to store all outputs +dir.create(OUTPUT_DIR, recursive = TRUE) + +#-----------------render Rmd-------------- +render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT) +#------------------------------------------ + +#==============the end============== + + +##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file diff -r 000000000000 -r b49e227ec738 dynamic_tool_wrappers_macros.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamic_tool_wrappers_macros.xml Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,189 @@ + + + + pandoc + r-getopt + r-rmarkdown + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r b49e227ec738 helper.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helper.R Wed Mar 21 17:26:27 2018 -0400 @@ -0,0 +1,28 @@ +#' \code{getopt_specification_matrix} returns a getopt specification matrix. +#' +#' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data. +#' The first column are short flags, the second column are argument masks, the third column +#' is data types. The fourth column are variable names used in the tool XML. These three columns are required. +#' @param gtg_name the name of a running GTG. +getopt_specification_matrix = function(specification_file, gtg_name = 'gtg', tool_dir = Sys.getenv('TOOL_DIR')) { + df = read.csv(paste0(tool_dir, specification_file), + header = TRUE, stringsAsFactors = FALSE) + # check if there are duplicated short flags + short_flags = df[, 1] + if (length(unique(short_flags)) < length(short_flags)) { + cat('----Duplicated short flags found ----\n') + cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n') + stop('Duplicated short flags are not allowed.') + } + + # use short flags to generate long flags + long_flags = paste0('X_', df[, 1]) + + # specification matrix + df2 = data.frame(long_flags = long_flags, + short_flags = df[, 1], + argument_mask = df[, 2], + data_type = df[, 3]) + + as.matrix(df2) +} \ No newline at end of file