Mercurial > repos > mingchen0919 > elastic_expose_data
changeset 1:16e0f4b7a286 draft
planemo upload commit d255df0b70677f4d5e5f2f8e240ce0b69f40d69d
author | mingchen0919 |
---|---|
date | Mon, 26 Mar 2018 18:40:39 -0400 |
parents | a163532ab267 |
children | 391394c022b8 |
files | elastic_expose_to_list_collection.xml elastic_expose_to_list_paired_collection.xml elastic_expose_to_paired_collection.xml elastic_tool.Rmd elastic_tool.xml elastic_tool_render.R elastic_tool_wrappers_macros.xml list.Rmd list_paired.Rmd paired.Rmd |
diffstat | 10 files changed, 256 insertions(+), 227 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/elastic_expose_to_list_collection.xml Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="elastic_expose_to_list_collection" name="expose to a list" version="1.0.0"> + <macros> + <import>elastic_tool_wrappers_macros.xml</import> + </macros> + <description/> + <requirements> + <expand macro="rmarkdown_requirements"/> + </requirements> + <expand macro="stdio"/> + <expand macro="shell_command"/> + <inputs> + <expand macro="option_argument_path_relative_to_a_tool"/> + </inputs> + <outputs> + <data format="html" name="report" label="${tool.name} report"/> + <data format="txt" name="tool_log" label="${tool.name} log"/> + <collection type="list" name="list_collection"> + <discover_datasets pattern="__name_and_ext__" directory="list" /> + </collection> + </outputs> + <citations> + <expand macro="citations"/> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/elastic_expose_to_list_paired_collection.xml Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="elastic_expose_to_paired_collection" name="elastic_expose_to_paired_collection" version="1.0.0"> + <macros> + <import>elastic_tool_wrappers_macros.xml</import> + </macros> + <description/> + <requirements> + <expand macro="rmarkdown_requirements"/> + </requirements> + <expand macro="stdio"/> + <expand macro="shell_command"/> + <inputs> + <expand macro="option_argument_path_relative_to_a_tool"/> + </inputs> + <outputs> + <data format="html" name="report" label="${tool.name} report"/> + <data format="txt" name="tool_log" label="${tool.name} log"/> + <collection type="list:paired" name="list_collection"> + <discover_datasets pattern="(?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)\.(?P<ext>[^\._]+)?" + directory="list_paired"/> + </collection> + </outputs> + <citations> + <expand macro="citations"/> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/elastic_expose_to_paired_collection.xml Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="elastic_expose_list_paired_collection" name="elastic_expose_list_paired_collection" version="1.0.0"> + <macros> + <import>elastic_tool_wrappers_macros.xml</import> + </macros> + <description/> + <requirements> + <expand macro="rmarkdown_requirements"/> + </requirements> + <expand macro="stdio"/> + <expand macro="shell_command"/> + <inputs> + <expand macro="option_argument_path_relative_to_a_tool"/> + </inputs> + <outputs> + <data format="html" name="report" label="${tool.name} report"/> + <data format="txt" name="tool_log" label="${tool.name} log"/> + <collection type="paired" name="list_collection"> + <discover_datasets pattern="__name_and_ext__" directory="paired_dir" /> + </collection> + </outputs> + <citations> + <expand macro="citations"/> + </citations> +</tool>
--- a/elastic_tool.Rmd Mon Mar 26 13:25:53 2018 -0400 +++ b/elastic_tool.Rmd Mon Mar 26 18:40:39 2018 -0400 @@ -18,120 +18,28 @@ ## User input -```{r, echo=FALSE} +```{r, echo=FALSE, eval=TRUE} ##-------- build script files ----------- # build script file: script.sh df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), sep = '|', header = TRUE) -# prepend A_TOOL_OUTPUT_PATH -if (nrow(df[df$type == 'path_relative_to_a_tool', ]) > 0) { - for (i in 1:nrow(df[df$type == 'path_relative_to_a_tool', ])) { - root_path = readLines(df[df$type == 'path_relative_to_a_tool', ][i, 'path_type'])[1] - df[df$type == 'path_relative_to_a_tool', ][i, 'value'] = paste(root_path, - df[df$type == 'path_relative_to_a_tool', ][i, 'value'], - sep = '/') - } -} - -# get tool name -tool_name = df[df$type == 'tool_name', 'value'] -# build script for displaying help messages (this probably should be tool specific) -write(paste0(tool_name, ' -h'), - file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh')) knitr::kable(df) - -# if the number of option/argument pairs is larger than 0, build script file -df2 = df[df$type != 'tool_name', ] -if (nrow(df2) > 0) { - # write tool name as the first line of the script.sh - # before running the job, cd into the ${REPORT_FILES_PATH} directory - write(paste0(tool_name, ' \\'), - paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) - df2 = df[df$type != 'tool_name', ] - write(paste(' ', df2$flag, df2$value, '\\', sep = ' '), - file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), - append = TRUE ) - # remember that after writing option/argument lines to the script.sh, the last line - # has an extra newline character '\' which causes a problem. We can either remove that extra - # '\' or add a new line to the end. We choose to add a new line. - - # add an extra line to the end to redirect stdout to stdout.txt and stderr to stderr.txt - write(' > ${REPORT_FILES_PATH}/stdout.txt 2>${REPORT_FILES_PATH}/stderr.txt', - paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), append = TRUE) -} else { - # if no option/argument input, simply display the help message - write(paste0(tool_name, ' -h'), - file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) -} - ``` - -```{bash, echo=FALSE} -## code to open help documentation -sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC} -``` - - -```{r, echo=FALSE} -# create paths before running the job script -df_paths = df[df$type == 'path_relative_to_this_tool', ] - -if (nrow(df_paths) > 0) { - for (i in 1:nrow(df_paths)) { - path = paste0(Sys.getenv('REPORT_FILES_PATH'), '/', df_paths[i, 'value']) - path_type = df_paths[i, 'path_type'] - - # create file paths - if ((path_type == 'file_path') & !file.exists(path)) { - dir_path = paste(head(strsplit(path, '/')[[1]], -1), collapse = '/' ) - if (!dir.exists(dir_path)) { - dir.create(dir_path, recursive = TRUE) - } - file.create(path) - } - - # create dir paths - if ((path_type == 'dir_path') & !dir.exists(path)) { - dir.create(path, recursive = TRUE) - } +```{r} +write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) +if (nrow(df) > 0) { + for (i in 1:nrow(df)) { + tool_output_dir = readLines(df[i, 'tool_output_dir'])[1] + full_path = paste0(tool_output_dir, '/', df[i, 'relative_path']) + command_line = paste0('cp -r ', full_path, ' ', df[i, collection_type]) + write(command_line, append = TRUE, + file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) } } ``` -```{bash, results='asis', echo=FALSE} -echo '## Job script' -echo '' -echo '' -echo '```bash' -cat ${REPORT_FILES_PATH}/script.sh -echo '```' -``` - - -```{r, echo=FALSE} -## obtain REPORT_FILES_PAHT and save it to a galaxy output. -database_root = paste(head(strsplit(Sys.getenv('TOOL_LOG'), '/')[[1]], -1), collapse = '/') -tool_output_dir_id = tail(strsplit(Sys.getenv('REPORT_FILES_PATH'), '/')[[1]], 1) -tool_output_dir = paste0(database_root, '/', tool_output_dir_id) -write(tool_output_dir, Sys.getenv('TOOL_OUTPUT_DIR')) -``` - - -```{r, results='asis', echo=FALSE} -cat('##All output files') -cat('\n\n') -all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'), - full.names = TRUE, - recursive = TRUE) - -for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) { - cat('* [', f, '](', f, ')\n') -} -cat('\n') -``` -
--- a/elastic_tool.xml Mon Mar 26 13:25:53 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<tool id="elastic_expose_data" name="elastic_expose_data" version="1.0.0"> - <macros> - <import>elastic_tool_wrappers_macros.xml</import> - </macros> - <description/> - <requirements> - <expand macro="rmarkdown_requirements"/> - </requirements> - <expand macro="stdio"/> - <expand macro="shell_command"/> - <inputs> - <expand macro="tool_name"/> - <expand macro="option_argument_single_dataset"/> - <expand macro="option_argument_multiple_datasets"/> - <expand macro="option_argument_path_relative_to_a_tool"/> - <expand macro="option_argument_path_relative_to_this_tool"/> - <expand macro="option_argument_string_float_integer"/> - </inputs> - <outputs> - <expand macro="output_set"/> - </outputs> - <citations> - <expand macro="citations"/> - </citations> -</tool>
--- a/elastic_tool_render.R Mon Mar 26 13:25:53 2018 -0400 +++ b/elastic_tool_render.R Mon Mar 26 18:40:39 2018 -0400 @@ -15,9 +15,15 @@ options_and_arguments = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), sep = '|', header = TRUE) - +#------------------------------------------------ +# create three folders within working directory +dir.create('list') +dir.create('paired') +dir.create('list_paired') +print(Sys.getenv('JOB_WORKING_DIR')) #-----------------render Rmd-------------- -render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/elastic_tool.Rmd'), +# copy R markdown file to working directory and render it within the working directory. +render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/elastic_tool.Rmd'), output_file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/report.html')) # for some unknow reason, directly using REPORT as the input value for output_file parameter @@ -25,6 +31,7 @@ # the solution is to render the rmarkdown to a explicitly specified file and then copy the # file to ${REPORT} system(command = 'cp ${REPORT_FILES_PATH}/report.html ${REPORT}') +system(command = 'sh ${REPORT_FILES_PATH}/script.sh') #------------------------------------------
--- a/elastic_tool_wrappers_macros.xml Mon Mar 26 13:25:53 2018 -0400 +++ b/elastic_tool_wrappers_macros.xml Mon Mar 26 18:40:39 2018 -0400 @@ -9,80 +9,23 @@ <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="cp" selected="false">cp</option></param> - </xml> <!--OPTION/ARGUMENT PAIRS and INPUT types--> - <!--input files--> - <xml name="option_argument_single_dataset"> - <repeat name="option_argument_single_dataset_repeat" title="INPUT DATA FROM HISTORY: single data set" min="0" default="0"> - <param type="text" name="flag" optional="true" label="flag"/> - <param name="value" type="data" optional="false" multiple="false" label="value"/> - </repeat> - </xml> - <xml name="option_argument_multiple_datasets"> - <repeat name="option_argument_multiple_datasets_repeat" title="INPUT DATA FROM HISTORY: multiple data sets" min="0" default="0"> - <param type="text" name="flag" optional="true" label="flag"/> - <param name="value" type="data" optional="false" multiple="true" label="value"/> - <param type="select" name="delimiter" multiple="false" label="file delimiter"> - <option value=" " selected="false">space</option> - <option value="," selected="false">comma</option> - </param> - </repeat> - </xml> + <!--input path--> <xml name="option_argument_path_relative_to_a_tool"> <repeat name="option_argument_path_relative_to_a_tool_repeat" title="INPUT DATA PATH: relative to a tool output directory" min="0" default="0"> - <param type="text" name="flag" optional="true" label="flag"/> <param name="a_tool_output_dir" type="data" optional="false" multiple="false" label="a tool output directory"/> - <param type="text" name="value" optional="true" label="value"/> - </repeat> - </xml> - <xml name="option_argument_path_relative_to_this_tool"> - <repeat name="option_argument_path_relative_to_this_tool_repeat" title="OUTPUT PATH: relative to this tool output directory" min="0" default="0"> - <param type="text" name="flag" optional="true" label="flag"/> - <param type="text" name="value" optional="false" label="value"/> - <param type="select" name="path_type" multiple="false" label="path type"> - <option value="file_path" selected="false">file path</option> - <option value="dir_path" selected="false">directory path</option> - </param> + <param type="text" name="value" optional="true" label="relative path"/> </repeat> </xml> - <!--input values: string, float and integer--> - <xml name="option_argument_string_float_integer"> - <repeat name="option_argument_string_float_integer_repeat" title="INPUT VALUE: string/float/integer" min="0" default="0"> - <param type="text" name="flag" label="flag"/> - <param type="text" name="value" 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"/> - <data name="asis"> - <discover_datasets pattern="__name_and_ext__" directory="${report.files_path}/asis_dir"/> - </data> - <collection type="list" name="expose_to_list"> - <discover_datasets pattern="__name_and_ext__" directory="${report.files_path}/list_dir" /> - </collection> - <collection type="paired" name="expose_to_pair"> - <discover_datasets pattern="__name_and_ext__" directory="${report.files_path}/pair_dir" /> - </collection> - <collection type="list:paired" name="expose_to_list_pairs"> - <discover_datasets pattern="(?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)\.(?P<ext>[^\._]+)?" - directory="${report.files_path}/list_pairs_dir"/> - </collection> - </xml> + <!--shell command fragment--> <xml name="shell_command"> <command><![CDATA[ + echo $tool_name && ############ first, create a directory to store all files - mkdir -p $report.files_path && cd $report.files_path && + mkdir -p $report.files_path && ############ save the tool installation directory to an environment variable @@ -96,59 +39,29 @@ ######################### ## first line will be the header - echo 'type|flag|value|path_type' > options_and_arguments.txt && + echo 'tool_output_dir|relative_path' > '$report.files_path/options_and_arguments.txt' && - ############ tool_name - ##-t '$tool_name' - echo "tool_name|not available|${tool_name}|not available" >> options_and_arguments.txt && + #################################################### ## loop through repeats to get option/argument pairs #################################################### - ############ option_argument_single_dataset - #for i in $option_argument_single_dataset_repeat: - #set $item = 'single_dataset|' + str($i.flag) + "|" + str($i.value) + "|" - echo '$item' >> options_and_arguments.txt && - #end for - - ############ option_argument_multiple_datasets - #for i in $option_argument_multiple_datasets_repeat: - #set $item = 'multiple_datasets|' + str($i.flag) + "|" + str($i.value).replace(',', str($i.delimiter)) + "|" - echo '$item' >> options_and_arguments.txt && - #end for - ############ option_argument_path_relative_to_a_tool #for i in $option_argument_path_relative_to_a_tool_repeat: - #set $item = 'path_relative_to_a_tool|' + str($i.flag) + "|" + str($i.value) + "|" + str($i.a_tool_output_dir) - echo '$item' >> options_and_arguments.txt && + #set $item = str($i.a_tool_output_dir) + "|" + str($i.value) + echo '$item' >> '$report.files_path/options_and_arguments.txt' && #end for - ############ option_argument_path_relative_to_this_tool - #for i in $option_argument_path_relative_to_this_tool_repeat: - #set $item = 'path_relative_to_this_tool|' + str($i.flag) + "|" + str($i.value) + "|" + str($i.path_type) - echo '$item' >> options_and_arguments.txt && - #end for - - ############ option_argument_string_float_integer - #for i in $option_argument_string_float_integer_repeat: - #set $item = 'value|' + str($i.flag) + "|" + str($i.value) + "|" - echo '$item' >> options_and_arguments.txt && - #end for ############ output_set ## '$report' ## '$report.files_path' - ## '$tool_help_doc' - ## '$tool_output_dir' - ## '$tool_log' ####################### export REPORT='$report' && + export TOOL_LOG='$tool_log' && export REPORT_FILES_PATH='$report.files_path' && - export TOOL_HELP_DOC='$tool_help_doc' && - export TOOL_OUTPUT_DIR='$tool_output_dir' && - export TOOL_LOG='$tool_log' && ############ run render R script to render R markdowns @@ -156,6 +69,22 @@ ]]></command> </xml> + + <!--<xml name="output_set">--> + <!--<data format="html" name="report" label="${tool.name} report"/>--> + <!--<data format="txt" name="tool_log" label="${tool.name} log"/>--> + <!--<collection type="list" name="list_collection">--> + <!--<discover_datasets pattern="__name_and_ext__" directory="list" />--> + <!--</collection>--> + <!--<collection type="paired" name="list_collection">--> + <!--<discover_datasets pattern="__name_and_ext__" directory="paired_dir" />--> + <!--</collection>--> + <!--<collection type="list:paired" name="list_collection">--> + <!--<discover_datasets pattern="(?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)\.(?P<ext>[^\._]+)?"--> + <!--directory="list_paired"/>--> + <!--</collection>--> + <!--</xml>--> + <!--tool citations--> <xml name="citations"> <citation type="bibtex"><![CDATA[
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list.Rmd Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,45 @@ +--- +title: 'Dynamic tool' +output: html_document +--- + +<style> +pre code, pre, code { + white-space: pre !important; + overflow-x: scroll !important; + word-break: keep-all !important; + word-wrap: initial !important; +} +</style> + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(error = TRUE) +``` + +## User input + +```{r, echo=FALSE, eval=TRUE} +##-------- build script files ----------- + +# build script file: script.sh +df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), + sep = '|', header = TRUE) + + +knitr::kable(df) +``` + +```{r} +write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) +if (nrow(df) > 0) { + for (i in 1:nrow(df)) { + tool_output_dir = readLines(df[i, 'tool_output_dir'])[1] + full_path = paste0(tool_output_dir, '/', df[i, 'relative_path']) + command_line = paste0('cp -r ', full_path, ' list') + write(command_line, append = TRUE, + file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) + } +} +``` + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list_paired.Rmd Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,45 @@ +--- +title: 'Dynamic tool' +output: html_document +--- + +<style> +pre code, pre, code { + white-space: pre !important; + overflow-x: scroll !important; + word-break: keep-all !important; + word-wrap: initial !important; +} +</style> + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(error = TRUE) +``` + +## User input + +```{r, echo=FALSE, eval=TRUE} +##-------- build script files ----------- + +# build script file: script.sh +df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), + sep = '|', header = TRUE) + + +knitr::kable(df) +``` + +```{r} +write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) +if (nrow(df) > 0) { + for (i in 1:nrow(df)) { + tool_output_dir = readLines(df[i, 'tool_output_dir'])[1] + full_path = paste0(tool_output_dir, '/', df[i, 'relative_path']) + command_line = paste0('cp -r ', full_path, ' list_paired') + write(command_line, append = TRUE, + file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) + } +} +``` + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paired.Rmd Mon Mar 26 18:40:39 2018 -0400 @@ -0,0 +1,45 @@ +--- +title: 'Dynamic tool' +output: html_document +--- + +<style> +pre code, pre, code { + white-space: pre !important; + overflow-x: scroll !important; + word-break: keep-all !important; + word-wrap: initial !important; +} +</style> + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(error = TRUE) +``` + +## User input + +```{r, echo=FALSE, eval=TRUE} +##-------- build script files ----------- + +# build script file: script.sh +df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), + sep = '|', header = TRUE) + + +knitr::kable(df) +``` + +```{r} +write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) +if (nrow(df) > 0) { + for (i in 1:nrow(df)) { + tool_output_dir = readLines(df[i, 'tool_output_dir'])[1] + full_path = paste0(tool_output_dir, '/', df[i, 'relative_path']) + command_line = paste0('cp -r ', full_path, ' paired') + write(command_line, append = TRUE, + file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) + } +} +``` + +