Mercurial > repos > mingchen0919 > elastic_expose_data
changeset 3:5838300fc1aa draft
add expose individuals
author | mingchen0919 |
---|---|
date | Mon, 02 Apr 2018 00:32:04 -0400 |
parents | 391394c022b8 |
children | 9ff33a3631fa |
files | elastic_expose_individuals.xml elastic_expose_to_list_collection.xml elastic_expose_to_list_paired_collection.xml elastic_expose_to_paired_collection.xml individuals.Rmd individuals_render.R paired.Rmd paired_render.R |
diffstat | 8 files changed, 166 insertions(+), 158 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/elastic_expose_individuals.xml Mon Apr 02 00:32:04 2018 -0400 @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="elastic_expose_individuals" name="expose data (individuals)" version="1.0.1"> + <macros> + <import>elastic_tool_wrappers_macros.xml</import> + </macros> + <description/> + <requirements> + <expand macro="rmarkdown_requirements"/> + </requirements> + <expand macro="stdio"/> + <command><![CDATA[ + + ############ first, create a directory to store all files + mkdir -p $report.files_path && + + + ############ save the tool installation directory to an environment variable + export TOOL_INSTALL_DIR='${__tool_directory__}' && + + + ######################### + ## + ## save user input option/argument pairs into a file + ## + ######################### + + ## first line will be the header + echo 'tool_output_dir|relative_path' > '$report.files_path/options_and_arguments.txt' && + + + + #################################################### + ## loop through repeats to get option/argument pairs + #################################################### + + + ############ option_argument_path_relative_to_a_tool + #for i in $option_argument_path_relative_to_a_tool_repeat: + #set $item = str($i.a_tool_output_dir) + "|" + str($i.value) + echo '$item' >> '$report.files_path/options_and_arguments.txt' && + #end for + + + ############ output_set + ## '$report' + ## '$report.files_path' + ####################### + export REPORT='$report' && + export TOOL_LOG='$tool_log' && + export REPORT_FILES_PATH='$report.files_path' && + + + ############ run render R script to render R markdowns + Rscript '${__tool_directory__}/paired_render.R' + + ]]></command> + <inputs> + <repeat name="option_argument_path_relative_to_a_tool_repeat" title="INPUT DATA PATH: relative to a tool output directory" min="1" default="1"> + <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="relative path"/> + </repeat> + </inputs> + <outputs> + <data format="html" name="report" label="${tool.name} report"/> + <data format="txt" name="tool_log" label="${tool.name} log"/> + <data name="individual_outputs"> + <discover_datasets pattern="__designation_and_ext__" directory="individual_outputs" visible="true"/> + </data> + </outputs> + <citations> + <expand macro="citations"/> + </citations> +</tool>
--- a/elastic_expose_to_list_collection.xml Sat Mar 31 21:32:17 2018 -0400 +++ b/elastic_expose_to_list_collection.xml Mon Apr 02 00:32:04 2018 -0400 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tool id="elastic_expose_to_list_collection" name="expose data (list)" version="1.0.0"> +<tool id="elastic_expose_to_list_collection" name="expose data (list)" version="1.0.1"> <macros> <import>elastic_tool_wrappers_macros.xml</import> </macros>
--- a/elastic_expose_to_list_paired_collection.xml Sat Mar 31 21:32:17 2018 -0400 +++ b/elastic_expose_to_list_paired_collection.xml Mon Apr 02 00:32:04 2018 -0400 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tool id="elastic_expose_to_paired_collection" name="expose data (list:paired)" version="1.0.0"> +<tool id="elastic_expose_to_list_paired_collection" name="expose data (list:paired)" version="1.0.1"> <macros> <import>elastic_tool_wrappers_macros.xml</import> </macros>
--- a/elastic_expose_to_paired_collection.xml Sat Mar 31 21:32:17 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<tool id="elastic_expose_list_paired_collection" name="expose data (paired)" version="1.0.0"> - <macros> - <import>elastic_tool_wrappers_macros.xml</import> - </macros> - <description/> - <requirements> - <expand macro="rmarkdown_requirements"/> - </requirements> - <expand macro="stdio"/> - <command><![CDATA[ - - ############ first, create a directory to store all files - mkdir -p $report.files_path && - - - ############ save the tool installation directory to an environment variable - export TOOL_INSTALL_DIR='${__tool_directory__}' && - - - ######################### - ## - ## save user input option/argument pairs into a file - ## - ######################### - - ## first line will be the header - echo 'tool_output_dir|relative_path' > '$report.files_path/options_and_arguments.txt' && - - - - #################################################### - ## loop through repeats to get option/argument pairs - #################################################### - - - ############ option_argument_path_relative_to_a_tool - #for i in $option_argument_path_relative_to_a_tool_repeat: - #set $item = str($i.a_tool_output_dir) + "|" + str($i.value) - echo '$item' >> '$report.files_path/options_and_arguments.txt' && - #end for - - - ############ output_set - ## '$report' - ## '$report.files_path' - ####################### - export REPORT='$report' && - export TOOL_LOG='$tool_log' && - export REPORT_FILES_PATH='$report.files_path' && - - - ############ run render R script to render R markdowns - Rscript '${__tool_directory__}/paired_render.R' - - ]]></command> - <inputs> - <repeat name="option_argument_path_relative_to_a_tool_repeat" title="INPUT DATA PATH: relative to a tool output directory" min="2" default="2" max="2"> - <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="relative path"/> - </repeat> - </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="paired_collection"> - <discover_datasets pattern="__name_and_ext__" directory="paired" /> - </collection> - </outputs> - <citations> - <expand macro="citations"/> - </citations> -</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/individuals.Rmd Mon Apr 02 00:32:04 2018 -0400 @@ -0,0 +1,53 @@ +--- +title: 'Expose data (paired)' +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, echo=FALSE} +# 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']) + if (dir.exists(full_path)) { + from_files = list.files(full_path, full.names = TRUE) + to_files = paste0(Sys.getenv('individual_outputs/'), list.files(full_path)) + file.copy(from = from_files, to = to_files) + } + if (file.exists(full_path)) { + file.copy(from = full_path, to = paste0(Sys.getenv('individual_outputs/'), 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')) + } +} +``` + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/individuals_render.R Mon Apr 02 00:32:04 2018 -0400 @@ -0,0 +1,38 @@ +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file(Sys.getenv('TOOL_LOG')) +sink(zz) +sink(zz, type = 'message') + +#------------import libraries-------------------- +options(stringsAsFactors = FALSE) + +library(rmarkdown) +#------------------------------------------------ + +#------------------------------------------------ +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('individual_outputs') + +#-----------------render Rmd-------------- +# copy R markdown file to working directory and render it within the working directory. +render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/paired.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 +# in the render function can cause empty report file when the tool runs in batch mode. +# 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') +#------------------------------------------ + + +##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file
--- a/paired.Rmd Sat Mar 31 21:32:17 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ ---- -title: 'Expose data (paired)' -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, echo=FALSE} -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')) - } -} -``` - -
--- a/paired_render.R Sat Mar 31 21:32:17 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -##============ Sink warnings and errors to a file ============== -## use the sink() function to wrap all code within it. -##============================================================== -zz = file(Sys.getenv('TOOL_LOG')) -sink(zz) -sink(zz, type = 'message') - -#------------import libraries-------------------- -options(stringsAsFactors = FALSE) - -library(rmarkdown) -#------------------------------------------------ - -#------------------------------------------------ -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('paired') - -#-----------------render Rmd-------------- -# copy R markdown file to working directory and render it within the working directory. -render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/paired.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 -# in the render function can cause empty report file when the tool runs in batch mode. -# 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') -#------------------------------------------ - - -##--------end of code rendering .Rmd templates---------------- -sink() -##=========== End of sinking output============================= \ No newline at end of file