Mercurial > repos > mingchen0919 > dynamic_star
annotate 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 |
| rev | line source |
|---|---|
| 0 | 1 --- |
| 2 title: 'Dynamic tool' | |
| 3 output: html_document | |
| 4 --- | |
| 5 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
6 <style> |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
7 pre code, pre, code { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
8 white-space: pre !important; |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
9 overflow-x: scroll !important; |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
10 word-break: keep-all !important; |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
11 word-wrap: initial !important; |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
12 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
13 </style> |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
14 |
| 0 | 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 ##-------- build script files ----------- | |
| 23 | |
| 24 # build script file: script.sh | |
| 25 df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), | |
| 26 sep = '|', header = TRUE) | |
| 27 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
28 # prepend A_TOOL_OUTPUT_PATH |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
29 if (nrow(df[df$type == 'path_relative_to_a_tool', ]) > 0) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
30 for (i in 1:nrow(df[df$type == 'path_relative_to_a_tool', ])) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
31 root_path = readLines(df[df$type == 'path_relative_to_a_tool', ][i, 'path_type'])[1] |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
32 df[df$type == 'path_relative_to_a_tool', ][i, 'value'] = paste(root_path, |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
33 df[df$type == 'path_relative_to_a_tool', ][i, 'value'], |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
34 sep = '/') |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
35 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
36 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
37 |
| 0 | 38 # get tool name |
| 39 tool_name = df[df$type == 'tool_name', 'value'] | |
| 40 # build script for displaying help messages (this probably should be tool specific) | |
| 41 write(paste0(tool_name, ' -h'), | |
| 42 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh')) | |
| 43 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
44 knitr::kable(df) |
| 0 | 45 |
| 46 # if the number of option/argument pairs is larger than 0, build script file | |
| 47 df2 = df[df$type != 'tool_name', ] | |
| 48 if (nrow(df2) > 0) { | |
| 49 # write tool name as the first line of the script.sh | |
| 50 # before running the job, cd into the ${REPORT_FILES_PATH} directory | |
| 51 write(paste0(tool_name, ' \\'), | |
| 52 paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) | |
| 53 df2 = df[df$type != 'tool_name', ] | |
| 54 write(paste(' ', df2$flag, df2$value, '\\', sep = ' '), | |
| 55 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), | |
| 56 append = TRUE ) | |
| 57 # remember that after writing option/argument lines to the script.sh, the last line | |
| 58 # has an extra newline character '\' which causes a problem. We can either remove that extra | |
| 59 # '\' or add a new line to the end. We choose to add a new line. | |
| 60 | |
| 61 # add an extra line to the end to redirect stdout to stdout.txt and stderr to stderr.txt | |
| 62 write(' > ${REPORT_FILES_PATH}/stdout.txt 2>${REPORT_FILES_PATH}/stderr.txt', | |
| 63 paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), append = TRUE) | |
| 64 } else { | |
| 65 # if no option/argument input, simply display the help message | |
| 66 write(paste0(tool_name, ' -h'), | |
| 67 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) | |
| 68 } | |
| 69 | |
| 70 ``` | |
| 71 | |
| 72 | |
| 73 ```{bash, echo=FALSE} | |
| 74 ## code to open help documentation | |
| 75 sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC} | |
| 76 ``` | |
| 77 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
78 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
79 ```{r, echo=FALSE} |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
80 # create paths before running the job script |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
81 df_paths = df[df$type == 'path_relative_to_this_tool', ] |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
82 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
83 if (nrow(df_paths) > 0) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
84 for (i in 1:nrow(df_paths)) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
85 path = paste0(Sys.getenv('REPORT_FILES_PATH'), '/', df_paths[i, 'value']) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
86 path_type = df_paths[i, 'path_type'] |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
87 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
88 # create file paths |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
89 if ((path_type == 'file_path') & !file.exists(path)) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
90 dir_path = paste(head(strsplit(path, '/')[[1]], -1), collapse = '/' ) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
91 if (!dir.exists(dir_path)) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
92 dir.create(dir_path, recursive = TRUE) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
93 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
94 file.create(path) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
95 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
96 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
97 # create dir paths |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
98 if ((path_type == 'dir_path') & !dir.exists(path)) { |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
99 dir.create(path, recursive = TRUE) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
100 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
101 } |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
102 } |
| 0 | 103 ``` |
| 104 | |
| 105 | |
| 106 ```{bash, echo=FALSE} | |
| 107 # run job script | |
| 108 # it's important to run the job within the REPORT_FILES_PATH | |
| 109 cd ${REPORT_FILES_PATH} && sh script.sh | |
| 110 ``` | |
| 111 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
112 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
113 |
| 0 | 114 ```{bash, results='asis', echo=FALSE} |
| 115 echo '## Job script' | |
| 116 echo '' | |
| 117 echo '' | |
| 118 echo '```bash' | |
| 119 cat ${REPORT_FILES_PATH}/script.sh | |
| 120 echo '```' | |
| 121 ``` | |
| 122 | |
| 123 | |
|
2
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
124 ```{r, echo=FALSE} |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
125 ## obtain REPORT_FILES_PAHT and save it to a galaxy output. |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
126 database_root = paste(head(strsplit(Sys.getenv('TOOL_LOG'), '/')[[1]], -1), collapse = '/') |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
127 tool_output_dir_id = tail(strsplit(Sys.getenv('REPORT_FILES_PATH'), '/')[[1]], 1) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
128 tool_output_dir = paste0(database_root, '/', tool_output_dir_id) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
129 write(tool_output_dir, Sys.getenv('TOOL_OUTPUT_DIR')) |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
130 ``` |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
131 |
|
a9579c344a90
planemo upload commit 8f84e3911c6ff4103c0ad5fb8dd774f80d9b2559
mingchen0919
parents:
0
diff
changeset
|
132 |
| 0 | 133 ```{r, results='asis', echo=FALSE} |
| 134 cat('##All output files') | |
| 135 cat('\n\n') | |
| 136 all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'), | |
| 137 full.names = TRUE, | |
| 138 recursive = TRUE) | |
| 139 | |
| 140 for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) { | |
| 141 cat('* [', f, '](', f, ')\n') | |
| 142 } | |
| 143 cat('\n') | |
| 144 ``` | |
| 145 |
