diff elastic_tool.Rmd @ 1:16e0f4b7a286 draft

planemo upload commit d255df0b70677f4d5e5f2f8e240ce0b69f40d69d
author mingchen0919
date Mon, 26 Mar 2018 18:40:39 -0400
parents a163532ab267
children
line wrap: on
line diff
--- a/elastic_tool.Rmd	Mon Mar 26 13:25:53 2018 -0400
+++ b/elastic_tool.Rmd	Mon Mar 26 18:40:39 2018 -0400
@@ -18,120 +18,28 @@
 
 ## User input
 
-```{r, echo=FALSE}
+```{r, echo=FALSE, eval=TRUE}
 ##-------- build script files -----------
 
 # build script file: script.sh
 df = read.table(paste0(Sys.getenv('REPORT_FILES_PATH'), '/options_and_arguments.txt'), 
                 sep = '|', header = TRUE)
 
-# prepend A_TOOL_OUTPUT_PATH
-if (nrow(df[df$type == 'path_relative_to_a_tool', ]) > 0) {
-  for (i in 1:nrow(df[df$type == 'path_relative_to_a_tool', ])) {
-    root_path = readLines(df[df$type == 'path_relative_to_a_tool', ][i, 'path_type'])[1]
-    df[df$type == 'path_relative_to_a_tool', ][i, 'value'] = paste(root_path, 
-                                                                   df[df$type == 'path_relative_to_a_tool', ][i, 'value'], 
-                                                                   sep = '/')
-  }
-}
-
-# get tool name
-tool_name = df[df$type == 'tool_name', 'value']
-# build script for displaying help messages (this probably should be tool specific)
-write(paste0(tool_name, ' -h'), 
-        file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/help.sh'))
 
 knitr::kable(df)
-
-# if the number of option/argument pairs is larger than 0, build script file
-df2 = df[df$type != 'tool_name', ]
-if (nrow(df2) > 0) {
-  # write tool name as the first line of the script.sh
-  # before running the job, cd into the ${REPORT_FILES_PATH} directory
-  write(paste0(tool_name, ' \\'), 
-        paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
-  df2 = df[df$type != 'tool_name', ]
-  write(paste(' ', df2$flag, df2$value, '\\', sep = ' '), 
-        file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), 
-        append = TRUE )
-  # remember that after writing option/argument lines to the script.sh, the last line
-  # has an extra newline character '\' which causes a problem. We can either remove that extra
-  # '\' or add a new line to the end. We choose to add a new line.
-  
-  # add an extra line to the end to redirect stdout to stdout.txt and stderr to stderr.txt
-  write('  > ${REPORT_FILES_PATH}/stdout.txt 2>${REPORT_FILES_PATH}/stderr.txt', 
-        paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'), append = TRUE)
-} else {
-  # if no option/argument input, simply display the help message
-  write(paste0(tool_name, ' -h'), 
-        file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
-}
-
 ```
 
-
-```{bash, echo=FALSE}
-## code to open help documentation
-sh ${REPORT_FILES_PATH}/help.sh > ${TOOL_HELP_DOC}
-```
-
-
-```{r, echo=FALSE}
-# create paths before running the job script
-df_paths = df[df$type == 'path_relative_to_this_tool', ]
-
-if (nrow(df_paths) > 0) {
-  for (i in 1:nrow(df_paths)) {
-    path = paste0(Sys.getenv('REPORT_FILES_PATH'), '/', df_paths[i, 'value'])
-    path_type = df_paths[i, 'path_type']
-  
-    # create file paths
-    if ((path_type == 'file_path') & !file.exists(path)) {
-      dir_path = paste(head(strsplit(path, '/')[[1]], -1), collapse = '/' )
-      if (!dir.exists(dir_path)) {
-        dir.create(dir_path, recursive = TRUE)
-      }
-      file.create(path)
-    }
-    
-    # create dir paths
-    if ((path_type == 'dir_path') & !dir.exists(path)) {
-      dir.create(path, recursive = TRUE)
-    }
+```{r}
+write('', file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
+if (nrow(df) > 0) {
+  for (i in 1:nrow(df)) {
+    tool_output_dir = readLines(df[i, 'tool_output_dir'])[1]
+    full_path = paste0(tool_output_dir, '/', df[i, 'relative_path'])
+    command_line = paste0('cp -r ', full_path, ' ', df[i, collection_type])
+    write(command_line, append = TRUE, 
+          file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/script.sh'))
   }
 }
 ```
 
 
-```{bash, results='asis', echo=FALSE}
-echo '## Job script'
-echo ''
-echo ''
-echo '```bash'
-cat ${REPORT_FILES_PATH}/script.sh
-echo '```'
-```
-
-
-```{r, echo=FALSE}
-## obtain REPORT_FILES_PAHT and save it to a galaxy output.
-database_root = paste(head(strsplit(Sys.getenv('TOOL_LOG'), '/')[[1]], -1), collapse = '/')
-tool_output_dir_id = tail(strsplit(Sys.getenv('REPORT_FILES_PATH'), '/')[[1]], 1)
-tool_output_dir = paste0(database_root, '/', tool_output_dir_id)
-write(tool_output_dir, Sys.getenv('TOOL_OUTPUT_DIR'))
-```
-
-
-```{r, results='asis', echo=FALSE}
-cat('##All output files')
-cat('\n\n')
-all_files = list.files(path = Sys.getenv('REPORT_FILES_PATH'), 
-                       full.names = TRUE, 
-                       recursive = TRUE)
-
-for (f in sub(Sys.getenv('REPORT_FILES_PATH'), '.', all_files) ) {
-  cat('* [', f, '](', f, ')\n')
-}
-cat('\n')
-```
-