Mercurial > repos > mingchen0919 > dynamic_star
comparison dynamic_tool.Rmd @ 2:a9579c344a90 draft default tip
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
| author | mingchen0919 |
|---|---|
| date | Fri, 23 Mar 2018 21:50:16 -0400 |
| parents | d79569f269c7 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:ddc3c3527f49 | 2:a9579c344a90 |
|---|---|
| 1 --- | 1 --- |
| 2 title: 'Dynamic tool' | 2 title: 'Dynamic tool' |
| 3 output: html_document | 3 output: html_document |
| 4 --- | 4 --- |
| 5 | |
| 6 <style> | |
| 7 pre code, pre, code { | |
| 8 white-space: pre !important; | |
| 9 overflow-x: scroll !important; | |
| 10 word-break: keep-all !important; | |
| 11 word-wrap: initial !important; | |
| 12 } | |
| 13 </style> | |
| 5 | 14 |
| 6 ```{r setup, include=FALSE, warning=FALSE, message=FALSE} | 15 ```{r setup, include=FALSE, warning=FALSE, message=FALSE} |
| 7 knitr::opts_chunk$set(error = TRUE) | 16 knitr::opts_chunk$set(error = TRUE) |
| 8 ``` | 17 ``` |
| 9 | 18 |
| 14 | 23 |
| 15 # build script file: script.sh | 24 # build script file: script.sh |
| 16 df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), | 25 df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), |
| 17 sep = '|', header = TRUE) | 26 sep = '|', header = TRUE) |
| 18 | 27 |
| 28 # prepend A_TOOL_OUTPUT_PATH | |
| 29 if (nrow(df[df$type == 'path_relative_to_a_tool', ]) > 0) { | |
| 30 for (i in 1:nrow(df[df$type == 'path_relative_to_a_tool', ])) { | |
| 31 root_path = readLines(df[df$type == 'path_relative_to_a_tool', ][i, 'path_type'])[1] | |
| 32 df[df$type == 'path_relative_to_a_tool', ][i, 'value'] = paste(root_path, | |
| 33 df[df$type == 'path_relative_to_a_tool', ][i, 'value'], | |
| 34 sep = '/') | |
| 35 } | |
| 36 } | |
| 37 | |
| 19 # get tool name | 38 # get tool name |
| 20 tool_name = df[df$type == 'tool_name', 'value'] | 39 tool_name = df[df$type == 'tool_name', 'value'] |
| 21 # build script for displaying help messages (this probably should be tool specific) | 40 # build script for displaying help messages (this probably should be tool specific) |
| 22 write(paste0(tool_name, ' -h'), | 41 write(paste0(tool_name, ' -h'), |
| 23 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh')) | 42 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh')) |
| 24 | 43 |
| 25 knitr::kable(df[, c('flag', 'value')]) | 44 knitr::kable(df) |
| 26 | 45 |
| 27 # if the number of option/argument pairs is larger than 0, build script file | 46 # if the number of option/argument pairs is larger than 0, build script file |
| 28 df2 = df[df$type != 'tool_name', ] | 47 df2 = df[df$type != 'tool_name', ] |
| 29 if (nrow(df2) > 0) { | 48 if (nrow(df2) > 0) { |
| 30 # write tool name as the first line of the script.sh | 49 # write tool name as the first line of the script.sh |
| 54 ```{bash, echo=FALSE} | 73 ```{bash, echo=FALSE} |
| 55 ## code to open help documentation | 74 ## code to open help documentation |
| 56 sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC} | 75 sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC} |
| 57 ``` | 76 ``` |
| 58 | 77 |
| 59 ```{bash, results='asis', echo=FALSE} | 78 |
| 60 echo '## Show help documentation' | 79 ```{r, echo=FALSE} |
| 61 echo '' | 80 # create paths before running the job script |
| 62 echo '' | 81 df_paths = df[df$type == 'path_relative_to_this_tool', ] |
| 63 echo '```bash' | 82 |
| 64 cat ${REPORT_FILES_PATH}/help.sh | 83 if (nrow(df_paths) > 0) { |
| 65 echo '```' | 84 for (i in 1:nrow(df_paths)) { |
| 85 path = paste0(Sys.getenv('REPORT_FILES_PATH'), '/', df_paths[i, 'value']) | |
| 86 path_type = df_paths[i, 'path_type'] | |
| 87 | |
| 88 # create file paths | |
| 89 if ((path_type == 'file_path') & !file.exists(path)) { | |
| 90 dir_path = paste(head(strsplit(path, '/')[[1]], -1), collapse = '/' ) | |
| 91 if (!dir.exists(dir_path)) { | |
| 92 dir.create(dir_path, recursive = TRUE) | |
| 93 } | |
| 94 file.create(path) | |
| 95 } | |
| 96 | |
| 97 # create dir paths | |
| 98 if ((path_type == 'dir_path') & !dir.exists(path)) { | |
| 99 dir.create(path, recursive = TRUE) | |
| 100 } | |
| 101 } | |
| 102 } | |
| 66 ``` | 103 ``` |
| 67 | 104 |
| 68 | 105 |
| 69 ```{bash, echo=FALSE} | 106 ```{bash, echo=FALSE} |
| 70 # run job script | 107 # run job script |
| 71 # it's important to run the job within the REPORT_FILES_PATH | 108 # it's important to run the job within the REPORT_FILES_PATH |
| 72 cd ${REPORT_FILES_PATH} && sh script.sh | 109 cd ${REPORT_FILES_PATH} && sh script.sh |
| 73 ``` | 110 ``` |
| 74 | 111 |
| 112 | |
| 113 | |
| 75 ```{bash, results='asis', echo=FALSE} | 114 ```{bash, results='asis', echo=FALSE} |
| 76 echo '## Job script' | 115 echo '## Job script' |
| 77 echo '' | 116 echo '' |
| 78 echo '' | 117 echo '' |
| 79 echo '```bash' | 118 echo '```bash' |
| 80 cat ${REPORT_FILES_PATH}/script.sh | 119 cat ${REPORT_FILES_PATH}/script.sh |
| 81 echo '```' | 120 echo '```' |
| 121 ``` | |
| 122 | |
| 123 | |
| 124 ```{r, echo=FALSE} | |
| 125 ## obtain REPORT_FILES_PAHT and save it to a galaxy output. | |
| 126 database_root = paste(head(strsplit(Sys.getenv('TOOL_LOG'), '/')[[1]], -1), collapse = '/') | |
| 127 tool_output_dir_id = tail(strsplit(Sys.getenv('REPORT_FILES_PATH'), '/')[[1]], 1) | |
| 128 tool_output_dir = paste0(database_root, '/', tool_output_dir_id) | |
| 129 write(tool_output_dir, Sys.getenv('TOOL_OUTPUT_DIR')) | |
| 82 ``` | 130 ``` |
| 83 | 131 |
| 84 | 132 |
| 85 ```{r, results='asis', echo=FALSE} | 133 ```{r, results='asis', echo=FALSE} |
| 86 cat('##All output files') | 134 cat('##All output files') |
