diff htseq_count_render.R @ 5:aacd5f53ac99 draft

v2.0.0
author mingchen0919
date Wed, 18 Apr 2018 13:17:28 -0400
parents 0fdb0d5f53ce
children 7c54fd452b8e
line wrap: on
line diff
--- a/htseq_count_render.R	Wed Mar 07 01:37:59 2018 -0500
+++ b/htseq_count_render.R	Wed Apr 18 13:17:28 2018 -0400
@@ -1,63 +1,44 @@
 ##============ Sink warnings and errors to a file ==============
 ## use the sink() function to wrap all code within it.
 ##==============================================================
-zz = file('warnings_and_errors.txt')
+zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt'))
 sink(zz)
 sink(zz, type = 'message')
 
-#------------import libraries--------------------
+#-------------------preparation -----------------
 options(stringsAsFactors = FALSE)
-
+# import libraries
 library(getopt)
 library(rmarkdown)
 library(htmltools)
+# load helper functions
+source(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/helper.R'))
+# import getopt specification matrix from a csv file
+opt = getopt(getopt_specification_matrix('getopt_specification.csv', 
+                                         tool_dir=Sys.getenv('TOOL_INSTALL_DIR')))
+# define a unix variable versions for all input values. this is useful when we 
+# want to use input values by other programming language in r markdown
+do.call(Sys.setenv, opt[-1])
 #------------------------------------------------
 
 
-#------------get arguments into R--------------------
-# library(dplyr)
-# getopt_specification_matrix(extract_short_flags('htseq_count.xml')) %>%
-#   write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
+#-----------------render Rmd files --------------
+# NOTICE: 
+#       we should copy all rmarkdown files from tool install directory to REPORT_FILES_PATH directory.
+#       and render rmarkdown files in the REPORT_FILES_PATH directory.
+file.copy(from = paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/vakata-jstree-3.3.5'),
+          to = Sys.getenv('REPORT_FILES_PATH'), recursive = TRUE)
+system(command = 'cp -r ${TOOL_INSTALL_DIR}/*.Rmd ${REPORT_FILES_PATH}')
+# render Rmd files in order
+render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/htseq_count.Rmd'))
+# add more lines below if there are more Rmd files to be rendered
+
+#------------------------------------------
 
 
-spec_matrix = as.matrix(
-  data.frame(stringsAsFactors=FALSE,
-              long_flags = c("X_e", "X_o", "X_d", "X_s", "X_t", "X_A", "X_B", "X_G",
-                             "X_f", "X_r", "X_S", "X_a", "X_T", "X_i", "X_m", "X_c", "X_O"),
-             short_flags = c("e", "o", "d", "s", "t", "A", "B", "G", "f", "r", "S",
-                             "a", "T", "i", "m", "c", "O"),
-     argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
-                             1L, 1L, 1L, 1L),
-         data_type_flags = c("character", "character", "character", "character",
-                             "character", "character", "character", "character",
-                             "character", "character", "character", "character",
-                             "character", "character", "character", "character",
-                             "character")
-  )
-)
-opt = getopt(spec_matrix)
-#----------------------------------------------------
-
-
-#-----------using passed arguments in R 
-#           to define system environment variables---
-do.call(Sys.setenv, opt[-1])
-#----------------------------------------------------
-
-#---------- often used variables ----------------
-# OUTPUT_DIR: path to the output associated directory, which stores all outputs
-# TOOL_DIR: path to the tool installation directory
-OUTPUT_DIR = opt$X_d
-TOOL_DIR =   opt$X_t
-RMD_NAME = 'htseq_count.Rmd'
-OUTPUT_REPORT = opt$X_o
-
-# create the output associated directory to store all outputs
-dir.create(OUTPUT_DIR, recursive = TRUE)
-
-#-----------------render Rmd--------------
-render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
-#------------------------------------------
+#---------------- copy the output html to REPORT ----
+system(command = 'cp ${REPORT_FILES_PATH}/htseq_count.html ${REPORT}')
+# add more lines below if there are more output html files
 
 #==============the end==============