Mercurial > repos > mingchen0919 > elastic_expose_data
comparison elastic_tool.Rmd @ 1:16e0f4b7a286 draft
planemo upload commit d255df0b70677f4d5e5f2f8e240ce0b69f40d69d
author | mingchen0919 |
---|---|
date | Mon, 26 Mar 2018 18:40:39 -0400 |
parents | a163532ab267 |
children |
comparison
equal
deleted
inserted
replaced
0:a163532ab267 | 1:16e0f4b7a286 |
---|---|
16 knitr::opts_chunk$set(error = TRUE) | 16 knitr::opts_chunk$set(error = TRUE) |
17 ``` | 17 ``` |
18 | 18 |
19 ## User input | 19 ## User input |
20 | 20 |
21 ```{r, echo=FALSE} | 21 ```{r, echo=FALSE, eval=TRUE} |
22 ##-------- build script files ----------- | 22 ##-------- build script files ----------- |
23 | 23 |
24 # build script file: script.sh | 24 # build script file: script.sh |
25 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'), |
26 sep = '|', header = TRUE) | 26 sep = '|', header = TRUE) |
27 | 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 | |
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 | 28 |
44 knitr::kable(df) | 29 knitr::kable(df) |
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 ``` | 30 ``` |
71 | 31 |
72 | 32 ```{r} |
73 ```{bash, echo=FALSE} | 33 write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) |
74 ## code to open help documentation | 34 if (nrow(df) > 0) { |
75 sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC} | 35 for (i in 1:nrow(df)) { |
76 ``` | 36 tool_output_dir = readLines(df[i, 'tool_output_dir'])[1] |
77 | 37 full_path = paste0(tool_output_dir, '/', df[i, 'relative_path']) |
78 | 38 command_line = paste0('cp -r ', full_path, ' ', df[i, collection_type]) |
79 ```{r, echo=FALSE} | 39 write(command_line, append = TRUE, |
80 # create paths before running the job script | 40 file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh')) |
81 df_paths = df[df$type == 'path_relative_to_this_tool', ] | |
82 | |
83 if (nrow(df_paths) > 0) { | |
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 } | 41 } |
102 } | 42 } |
103 ``` | 43 ``` |
104 | 44 |
105 | 45 |
106 ```{bash, results='asis', echo=FALSE} | |
107 echo '## Job script' | |
108 echo '' | |
109 echo '' | |
110 echo '```bash' | |
111 cat ${REPORT_FILES_PATH}/script.sh | |
112 echo '```' | |
113 ``` | |
114 | |
115 | |
116 ```{r, echo=FALSE} | |
117 ## obtain REPORT_FILES_PAHT and save it to a galaxy output. | |
118 database_root = paste(head(strsplit(Sys.getenv('TOOL_LOG'), '/')[[1]], -1), collapse = '/') | |
119 tool_output_dir_id = tail(strsplit(Sys.getenv('REPORT_FILES_PATH'), '/')[[1]], 1) | |
120 tool_output_dir = paste0(database_root, '/', tool_output_dir_id) | |
121 write(tool_output_dir, Sys.getenv('TOOL_OUTPUT_DIR')) | |
122 ``` | |
123 | |
124 | |
125 ```{r, results='asis', echo=FALSE} | |
126 cat('##All output files') | |
127 cat('\n\n') | |
128 all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'), | |
129 full.names = TRUE, | |
130 recursive = TRUE) | |
131 | |
132 for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) { | |
133 cat('* [', f, '](', f, ')\n') | |
134 } | |
135 cat('\n') | |
136 ``` | |
137 |