|
9
|
1 ---
|
|
|
2 title: 'Tool Report'
|
|
|
3 output: html_document
|
|
|
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>
|
|
|
14
|
|
|
15 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
|
|
|
16 knitr::opts_chunk$set(error = TRUE)
|
|
|
17 ```
|
|
|
18
|
|
|
19 ## User input
|
|
|
20
|
|
|
21 ```{r, echo=FALSE}
|
|
|
22 knitr::kable(arguments)
|
|
|
23 ```
|
|
|
24
|
|
|
25
|
|
|
26 ```{r, echo=FALSE}
|
|
|
27 # each tool execution runs one or multiple chained functions but generate only one single object.
|
|
|
28 # we save this object to an rdata file and output this file to galaxy history so that it can be used by other tools
|
|
|
29 # we can use this rdata output file's dataset id as the variable name of the saved object.
|
|
|
30 job_script_path = paste0(Sys.getenv('REPORT_FILES_PATH'), '/job-script.R')
|
|
|
31 tool_rdata_output = Sys.getenv('TOOL_RDATA_OUTPUT')
|
|
|
32 dataset_id = tail(strsplit(tool_rdata_output, '/')[[1]], 1)
|
|
|
33 dataset_num = gsub("(.+_)([0-9]+)\\.dat", "\\2", dataset_id)
|
|
|
34 rdata_id = paste0('rdata_', dataset_num)
|
|
|
35
|
|
|
36 ## build script
|
|
|
37 # the first line of the job script is 'rdata_NUM = ', where 'NUM' is the dataset number of the output rdata.
|
|
|
38 write(paste0(rdata_id, ' = '), file = job_script_path)
|
|
|
39 # loop through argument data frame to build up the job script.
|
|
|
40 for (i in 1: (nrow(arguments)-1)) {
|
|
|
41 row_type = arguments[i, 'row_type']
|
|
|
42 switch (row_type,
|
|
|
43 # if it's a function row, the line has format 'function_name('
|
|
|
44 func = write(paste0(arguments[i, 'function_name'], '('),
|
|
|
45 file = job_script_path,
|
|
|
46 append = TRUE ),
|
|
|
47
|
|
|
48
|
|
|
49 argument = {
|
|
|
50 # if it's an argument row and the next row is not an operator row,
|
|
|
51 # the line has format ' argument_name=argument_value,'
|
|
|
52 if (arguments[i+1, 'operator'] == "") {
|
|
|
53 write(paste0(' ', arguments[i, 'argument_name'], '=', arguments[i, 'argument_value'], ','),
|
|
|
54 file = job_script_path,
|
|
|
55 append = TRUE )
|
|
|
56 } else {
|
|
|
57 # if it's an argument row and the next row IS an operator row,
|
|
|
58 # the line has format ' argument_name=argument_value'. note that there is not comma at the end.
|
|
|
59 write(paste0(' ', arguments[i, 'argument_name'], '=', arguments[i, 'argument_value']),
|
|
|
60 file = job_script_path,
|
|
|
61 append = TRUE )
|
|
|
62 }
|
|
|
63 },
|
|
|
64
|
|
|
65 # if it is an operator row, the line has format ') operator'
|
|
|
66 operator = write(paste0(') ', arguments[i, 'operator']),
|
|
|
67 file = job_script_path,
|
|
|
68 append = TRUE )
|
|
|
69 )
|
|
|
70 }
|
|
|
71
|
|
|
72 # the last line is missing a ')'
|
|
|
73 write(')', file = job_script_path, append = TRUE)
|
|
|
74 ```
|
|
|
75
|
|
|
76
|
|
|
77 ```{bash, 'display script', results='asis', echo=FALSE}
|
|
|
78 echo '## Job script'
|
|
|
79 echo ''
|
|
|
80 echo ''
|
|
|
81 echo '```r'
|
|
|
82 cat ${REPORT_FILES_PATH}/job-script.R
|
|
|
83 echo '```'
|
|
|
84 ```
|
|
|
85
|
|
|
86
|
|
|
87 ## Result
|
|
|
88
|
|
|
89 ```{r, 'run job script', echo=FALSE}
|
|
|
90 source(job_script_path)
|
|
|
91 # display result.
|
|
|
92 eval(parse(text = rdata_id))
|
|
|
93 ```
|
|
|
94
|
|
|
95
|
|
|
96 ```{r, 'display output directory contents', results='asis', echo=FALSE}
|
|
|
97 ## after the job is done, we list all files from the output directory.
|
|
|
98 ## full relative path to the output directory needs to be displayed.
|
|
|
99
|
|
|
100 cat('##All output files')
|
|
|
101 cat('\n\n')
|
|
|
102 all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'),
|
|
|
103 full.names = TRUE,
|
|
|
104 recursive = TRUE)
|
|
|
105
|
|
|
106 for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) {
|
|
|
107 cat('* [', f, '](', f, ')\n')
|
|
|
108 }
|
|
|
109 cat('\n')
|
|
|
110 ``` |