|
0
|
1 ---
|
|
|
2 title: 'Dynamic tool'
|
|
|
3 output: html_document
|
|
|
4 ---
|
|
|
5
|
|
|
6 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
|
|
|
7 knitr::opts_chunk$set(error = TRUE)
|
|
|
8 ```
|
|
|
9
|
|
|
10 ## User input
|
|
|
11
|
|
|
12 ```{r, echo=FALSE}
|
|
|
13 ##-------- build script files -----------
|
|
|
14
|
|
|
15 # build script file: script.sh
|
|
|
16 df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'),
|
|
|
17 sep = '|', header = TRUE)
|
|
|
18
|
|
|
19 # get tool name
|
|
|
20 tool_name = df[df$type == 'tool_name', 'value']
|
|
|
21 # build script for displaying help messages (this probably should be tool specific)
|
|
|
22 write(paste0(tool_name, ' -h'),
|
|
|
23 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh'))
|
|
|
24
|
|
|
25 knitr::kable(df[, c('flag', 'value')])
|
|
|
26
|
|
|
27 # if the number of option/argument pairs is larger than 0, build script file
|
|
|
28 df2 = df[df$type != 'tool_name', ]
|
|
|
29 if (nrow(df2) > 0) {
|
|
|
30 # write tool name as the first line of the script.sh
|
|
|
31 # before running the job, cd into the ${REPORT_FILES_PATH} directory
|
|
|
32 write(paste0(tool_name, ' \\'),
|
|
|
33 paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
|
|
|
34 df2 = df[df$type != 'tool_name', ]
|
|
|
35 write(paste(' ', df2$flag, df2$value, '\\', sep = ' '),
|
|
|
36 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'),
|
|
|
37 append = TRUE )
|
|
|
38 # remember that after writing option/argument lines to the script.sh, the last line
|
|
|
39 # has an extra newline character '\' which causes a problem. We can either remove that extra
|
|
|
40 # '\' or add a new line to the end. We choose to add a new line.
|
|
|
41
|
|
|
42 # add an extra line to the end to redirect stdout to stdout.txt and stderr to stderr.txt
|
|
|
43 write(' > ${REPORT_FILES_PATH}/stdout.txt 2>${REPORT_FILES_PATH}/stderr.txt',
|
|
|
44 paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), append = TRUE)
|
|
|
45 } else {
|
|
|
46 # if no option/argument input, simply display the help message
|
|
|
47 write(paste0(tool_name, ' -h'),
|
|
|
48 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
|
|
|
49 }
|
|
|
50
|
|
|
51 ```
|
|
|
52
|
|
|
53
|
|
|
54 ```{bash, echo=FALSE}
|
|
|
55 ## code to open help documentation
|
|
|
56 sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC}
|
|
|
57 ```
|
|
|
58
|
|
|
59 ```{bash, results='asis', echo=FALSE}
|
|
|
60 echo '## Show help documentation'
|
|
|
61 echo ''
|
|
|
62 echo ''
|
|
|
63 echo '```bash'
|
|
|
64 cat ${REPORT_FILES_PATH}/help.sh
|
|
|
65 echo '```'
|
|
|
66 ```
|
|
|
67
|
|
|
68
|
|
|
69 ```{bash, echo=FALSE}
|
|
|
70 # run job script
|
|
|
71 # it's important to run the job within the REPORT_FILES_PATH
|
|
|
72 cd ${REPORT_FILES_PATH} && sh script.sh
|
|
|
73 ```
|
|
|
74
|
|
|
75 ```{bash, results='asis', echo=FALSE}
|
|
|
76 echo '## Job script'
|
|
|
77 echo ''
|
|
|
78 echo ''
|
|
|
79 echo '```bash'
|
|
|
80 cat ${REPORT_FILES_PATH}/script.sh
|
|
|
81 echo '```'
|
|
|
82 ```
|
|
|
83
|
|
|
84
|
|
|
85 ```{r, results='asis', echo=FALSE}
|
|
|
86 cat('##All output files')
|
|
|
87 cat('\n\n')
|
|
|
88 all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'),
|
|
|
89 full.names = TRUE,
|
|
|
90 recursive = TRUE)
|
|
|
91
|
|
|
92 for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) {
|
|
|
93 cat('* [', f, '](', f, ')\n')
|
|
|
94 }
|
|
|
95 cat('\n')
|
|
|
96 ```
|
|
|
97
|