# HG changeset patch
# User mingchen0919
# Date 1521856216 14400
# Node ID a9579c344a90f56c12dff91e66985590b2f0ae4e
# Parent ddc3c3527f49149e38fbb1bff9f0867aa5ba4cad
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
diff -r ddc3c3527f49 -r a9579c344a90 dynamic_tool.Rmd
--- a/dynamic_tool.Rmd Fri Mar 23 02:01:52 2018 -0400
+++ b/dynamic_tool.Rmd Fri Mar 23 21:50:16 2018 -0400
@@ -3,6 +3,15 @@
output: html_document
---
+
+
```{r setup, include=FALSE, warning=FALSE, message=FALSE}
knitr::opts_chunk$set(error = TRUE)
```
@@ -16,13 +25,23 @@
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[, c('flag', 'value')])
+knitr::kable(df)
# if the number of option/argument pairs is larger than 0, build script file
df2 = df[df$type != 'tool_name', ]
@@ -56,13 +75,31 @@
sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC}
```
-```{bash, results='asis', echo=FALSE}
-echo '## Show help documentation'
-echo ''
-echo ''
-echo '```bash'
-cat ${REPORT_FILES_PATH}/help.sh
-echo '```'
+
+```{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)
+ }
+ }
+}
```
@@ -72,6 +109,8 @@
cd ${REPORT_FILES_PATH} && sh script.sh
```
+
+
```{bash, results='asis', echo=FALSE}
echo '## Job script'
echo ''
@@ -82,6 +121,15 @@
```
+```{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')
diff -r ddc3c3527f49 -r a9579c344a90 dynamic_tool.xml
--- a/dynamic_tool.xml Fri Mar 23 02:01:52 2018 -0400
+++ b/dynamic_tool.xml Fri Mar 23 21:50:16 2018 -0400
@@ -10,12 +10,11 @@
-
+
-
-
-
-
+
+
+
diff -r ddc3c3527f49 -r a9579c344a90 dynamic_tool_render.R
--- a/dynamic_tool_render.R Fri Mar 23 02:01:52 2018 -0400
+++ b/dynamic_tool_render.R Fri Mar 23 21:50:16 2018 -0400
@@ -8,7 +8,6 @@
#------------import libraries--------------------
options(stringsAsFactors = FALSE)
-library(getopt)
library(rmarkdown)
#------------------------------------------------
@@ -18,8 +17,14 @@
#-----------------render Rmd--------------
-render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/dynamic_tool.Rmd'),
- output_file = Sys.getenv('REPORT'))
+render(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/dynamic_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
+# 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}')
#------------------------------------------
diff -r ddc3c3527f49 -r a9579c344a90 dynamic_tool_wrappers_macros.xml
--- a/dynamic_tool_wrappers_macros.xml Fri Mar 23 02:01:52 2018 -0400
+++ b/dynamic_tool_wrappers_macros.xml Fri Mar 23 21:50:16 2018 -0400
@@ -22,41 +22,46 @@
-
-
+
+
-
+
+
-
+
-
+
+
+
+
+
-
-
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
@@ -90,54 +95,47 @@
#########################
## first line will be the header
- echo 'type|flag|value' > options_and_arguments.txt &&
+ echo 'type|flag|value|path_type' > options_and_arguments.txt &&
############ tool_name
##-t '$tool_name'
- echo "tool_name|tool_flag|${tool_name}" >> options_and_arguments.txt &&
+ echo "tool_name|not available|${tool_name}|not available" >> options_and_arguments.txt &&
####################################################
## loop through repeats to get option/argument pairs
####################################################
- ############ option_argument_one_dataset
- #for i in $option_argument_one_dataset_repeat:
- #set $item = 'one_dataset|' + str($i.flag) + "|" + str($i.value)
+ ############ 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)
+ #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_upstream_tool
- #for i in $option_argument_path_relative_to_upstream_tool_repeat:
- #set $item = 'path_relative_to_upstream_tool|' + str($i.flag) + "|" + str($i.value)
+
+ ############ 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 &&
#end for
- ############ option_argument_string
- #for i in $option_argument_string_repeat:
- #set $item = 'string|' + str($i.flag) + "|" + str($i.value)
+ ############ 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_float
- #for i in $option_argument_float_repeat:
- #set $item = 'float|' + str($i.flag) + "|" + str($i.value)
+ ############ 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
-
- ############ option_argument_integer
- #for i in $option_argument_integer_repeat:
- #set $item = 'integer|' + str($i.flag) + "|" + str($i.value)
- echo '$item' >> options_and_arguments.txt &&
- #end for
-
-
############ output_set
## '$report'
## '$report.files_path'
@@ -152,9 +150,6 @@
export TOOL_LOG='$tool_log' &&
- ############ save tool files path to a tool output so that it can be accessed from galaxy history
- echo '$report.files_path' > $tool_output_dir &&
-
############ run render R script to render R markdowns
Rscript '${__tool_directory__}/dynamic_tool_render.R'