Mercurial > repos > mingchen0919 > dynamic_tool_test
changeset 0:b49e227ec738 draft default tip
planemo upload commit fe1408d418f7f1354a736f73ece704219baa3190
author | mingchen0919 |
---|---|
date | Wed, 21 Mar 2018 17:26:27 -0400 |
parents | |
children | |
files | LICENSE README.md dynamic_tool.Rmd dynamic_tool.csv dynamic_tool.xml dynamic_tool_render.R dynamic_tool_wrappers_macros.xml helper.R |
diffstat | 8 files changed, 343 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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.
--- /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
--- /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 +```
--- /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,
--- /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 @@ +<tool id="dynamic_tool" name="dynamic tool" version="1.0.0"> + <macros> + <import>dynamic_tool_wrappers_macros.xml</import> + </macros> + <description></description> + <requirements> + <expand macro="rmarkdown_requirements" /> + <requirement type="package" version="0.11.7">fastqc</requirement> + </requirements> + <expand macro="stdio" /> + <expand macro="shell_command" /> + <inputs> + <expand macro="tool_name" /> + <expand macro="option_argument_one_dataset" /> + <expand macro="option_argument_multiple_datasets" /> + <expand macro="option_argument_path_relative_to_upstream_tool" /> + <expand macro="option_argument_string" /> + <expand macro="option_argument_float" /> + <expand macro="option_argument_integer" /> + </inputs> + <outputs> + <expand macro="output_set" /> + </outputs> + <citations> + <expand macro="citations" /> + </citations> +</tool>
--- /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
--- /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 @@ +<macros> + + <xml name="rmarkdown_requirements"> + <requirement type="package" version="1.15.0.6-0">pandoc</requirement> + <requirement type="package" version="1.20.0">r-getopt</requirement> + <requirement type="package" version="1.6">r-rmarkdown</requirement> + </xml> + + <xml name="stdio"> + <stdio> + <regex match="XXX" source="stderr" level="warning" + description="Check the tool log output file for more details."/> + </stdio> + </xml> + + <!--Tool name--> + <xml name="tool_name"> + <param type="select" name="tool_name" multiple="false" label="Tool name"> + <option value="fastqc" selected="false">fastqc</option> + </param> + </xml> + + <!--OPTION/ARGUMENT PAIRS and INPUT types--> + <!--input files--> + <xml name="option_argument_one_dataset"> + <repeat name="option_argument_one_dataset_repeat" title="OPTION and ARGUMENT: input one dataset" min="0" default="0"> + <param type="text" name="flag" optional="true" label="flag" /> + <param name="one_dataset" type="data" optional="true" multiple="false" label="value"/> + </repeat> + </xml> + <xml name="option_argument_multiple_datasets"> + <repeat name="option_argument_multiple_datasets_repeat" title="OPTION and ARGUMENT: input multiple datasets" min="0" default="0"> + <param type="text" name="flag" optional="true" label="flag" /> + <param name="multiple_datasets" type="data" optional="true" multiple="true" label="value" /> + </repeat> + </xml> + <xml name="option_argument_path_relative_to_upstream_tool"> + <repeat name="option_argument_path_relative_to_upstream_tool_repeat" title="OPTION and ARGUMENT: path relative to upstream tool" min="0" default="0"> + <param type="text" name="flag" optional="true" label="flag" /> + <param name="upstream_tool_output_dir" type="data" optional="true" multiple="false" label="upstream tool output directory"/> + <param type="text" name="option_argument_path" optional="true" label="value" /> + </repeat> + </xml> + + <!--input values: string, float and integer--> + <xml name="option_argument_string"> + <repeat name="option_argument_string_repeat" title="OPTION and ARGUMENT: input string" min="0" default="0"> + <param type="text" name="flag" label="flag" /> + <param type="text" name="option_argument_string" label="value" /> + </repeat> + </xml> + <xml name="option_argument_float"> + <repeat name="option_argument_float_repeat" title="OPTION and ARGUMENT: input float" min="0" default="0"> + <param type="text" name="flag" label="flag" /> + <param type="text" name="option_argument_float" label="value" /> + </repeat> + </xml> + <xml name="option_argument_integer"> + <repeat name="option_argument_integer_repeat" title="OPTION and ARGUMENT: input integer" min="0" default="0"> + <param type="text" name="flag" label="flag" /> + <param type="text" name="option_argument_integer" label="value" /> + </repeat> + </xml> + + <!--output set--> + <xml name="output_set"> + <data format="html" name="report" label="${tool.name} report"/> + <data format="txt" name="tool_help_doc" label="${tool.name} help doc"/> + <data format="txt" name="tool_output_dir" label="${tool.name} output directory"/> + <data format="txt" name="tool_log" label="${tool.name} log" from_work_dir="tool_log.txt"/> + </xml> + + + <!--shell command fragment--> + <xml name="shell_command"> + <command><![CDATA[ + export TOOL_DIR='${__tool_directory__}' && + + Rscript '${__tool_directory__}/dynamic_tool_render.R' + + ############ tool_name + -t '$tool_name' + + ############ option_argument_one_dataset + #set sep = '' + #set one_dataset_items = '' + #for i in $option_argument_one_dataset_repeat: + #set one_dataset_items += $sep + $option_argument_one_dataset_repeat.flag + " " + $option_argument_one_dataset_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -o '$one_dataset_items' + + + + ############ option_argument_multiple_datasets + #set sep = '' + #set multiple_datasets_items = '' + #for i in $option_argument_multiple_datasets_repeat: + #set multiple_datasets_items += $sep + $option_argument_multiple_datasets_repeat.flag + " " + $option_argument_multiple_datasets_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -m '$multiple_datasets_items' + + + ############ option_argument_path_relative_to_upstream_tool + #set sep = '' + #set path_relative_to_upstream_tool_items = '' + #for i in $option_argument_path_relative_to_upstream_tool_repeat: + #set path_relative_to_upstream_tool_items += $sep + $option_argument_path_relative_to_upstream_tool_repeat.flag + " " + $option_argument_path_relative_to_upstream_tool_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -u '$path_relative_to_upstream_tool_items' + + + + ############ option_argument_string + #set sep = '' + #set string_items = '' + #for i in $option_argument_string_repeat: + #set string_items += $sep + $option_argument_string_repeat.flag + " " + $option_argument_string_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -s '$string_items' + + + ############ option_argument_float + #set sep = '' + #set float_items = '' + #for i in $option_argument_float_repeat: + #set float_items += $sep + $option_argument_float_repeat.flag + " " + $option_argument_float_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -f '$float_items' + + ############ option_argument_integer + #set sep = '' + #set integer_items = '' + #for i in $option_argument_integer_repeat: + #set integer_items += $sep + $option_argument_integer_repeat.flag + " " + $option_argument_integer_repeat.value + "'" + #### separate values set by repeat + $set sep = '|' + #end for + + -i '$integer_items' + + + ############ output_set + -R '$report' + -D '$report.files_path' + -H '$tool_help_doc' + -O '$tool_output_dir' + -L '$tool_log' + + ]]></command> + </xml> + + <!--tool citations--> + <xml name="citations"> + <citation type="bibtex"><![CDATA[ + @article{allaire2016rmarkdown, + title={rmarkdown: Dynamic Documents for R, 2016}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff + and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + journal={R package version 0.9}, + volume={6}, + year={2016} + } + ]]></citation> + <citation type="bibtex"><![CDATA[ + @book{xie2015dynamic, + title={Dynamic Documents with R and knitr}, + author={Xie, Yihui}, + volume={29}, + year={2015}, + publisher={CRC Press} + } + ]]></citation> + </xml> +</macros> \ No newline at end of file
--- /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