comparison 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
comparison
equal deleted inserted replaced
4:0fdb0d5f53ce 5:aacd5f53ac99
1 ##============ Sink warnings and errors to a file ============== 1 ##============ Sink warnings and errors to a file ==============
2 ## use the sink() function to wrap all code within it. 2 ## use the sink() function to wrap all code within it.
3 ##============================================================== 3 ##==============================================================
4 zz = file('warnings_and_errors.txt') 4 zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt'))
5 sink(zz) 5 sink(zz)
6 sink(zz, type = 'message') 6 sink(zz, type = 'message')
7 7
8 #------------import libraries-------------------- 8 #-------------------preparation -----------------
9 options(stringsAsFactors = FALSE) 9 options(stringsAsFactors = FALSE)
10 10 # import libraries
11 library(getopt) 11 library(getopt)
12 library(rmarkdown) 12 library(rmarkdown)
13 library(htmltools) 13 library(htmltools)
14 # load helper functions
15 source(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/helper.R'))
16 # import getopt specification matrix from a csv file
17 opt = getopt(getopt_specification_matrix('getopt_specification.csv',
18 tool_dir=Sys.getenv('TOOL_INSTALL_DIR')))
19 # define a unix variable versions for all input values. this is useful when we
20 # want to use input values by other programming language in r markdown
21 do.call(Sys.setenv, opt[-1])
14 #------------------------------------------------ 22 #------------------------------------------------
15 23
16 24
17 #------------get arguments into R-------------------- 25 #-----------------render Rmd files --------------
18 # library(dplyr) 26 # NOTICE:
19 # getopt_specification_matrix(extract_short_flags('htseq_count.xml')) %>% 27 # we should copy all rmarkdown files from tool install directory to REPORT_FILES_PATH directory.
20 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE) 28 # and render rmarkdown files in the REPORT_FILES_PATH directory.
29 file.copy(from = paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/vakata-jstree-3.3.5'),
30 to = Sys.getenv('REPORT_FILES_PATH'), recursive = TRUE)
31 system(command = 'cp -r ${TOOL_INSTALL_DIR}/*.Rmd ${REPORT_FILES_PATH}')
32 # render Rmd files in order
33 render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/htseq_count.Rmd'))
34 # add more lines below if there are more Rmd files to be rendered
35
36 #------------------------------------------
21 37
22 38
23 spec_matrix = as.matrix( 39 #---------------- copy the output html to REPORT ----
24 data.frame(stringsAsFactors=FALSE, 40 system(command = 'cp ${REPORT_FILES_PATH}/htseq_count.html ${REPORT}')
25 long_flags = c("X_e", "X_o", "X_d", "X_s", "X_t", "X_A", "X_B", "X_G", 41 # add more lines below if there are more output html files
26 "X_f", "X_r", "X_S", "X_a", "X_T", "X_i", "X_m", "X_c", "X_O"),
27 short_flags = c("e", "o", "d", "s", "t", "A", "B", "G", "f", "r", "S",
28 "a", "T", "i", "m", "c", "O"),
29 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
30 1L, 1L, 1L, 1L),
31 data_type_flags = c("character", "character", "character", "character",
32 "character", "character", "character", "character",
33 "character", "character", "character", "character",
34 "character", "character", "character", "character",
35 "character")
36 )
37 )
38 opt = getopt(spec_matrix)
39 #----------------------------------------------------
40
41
42 #-----------using passed arguments in R
43 # to define system environment variables---
44 do.call(Sys.setenv, opt[-1])
45 #----------------------------------------------------
46
47 #---------- often used variables ----------------
48 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
49 # TOOL_DIR: path to the tool installation directory
50 OUTPUT_DIR = opt$X_d
51 TOOL_DIR = opt$X_t
52 RMD_NAME = 'htseq_count.Rmd'
53 OUTPUT_REPORT = opt$X_o
54
55 # create the output associated directory to store all outputs
56 dir.create(OUTPUT_DIR, recursive = TRUE)
57
58 #-----------------render Rmd--------------
59 render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
60 #------------------------------------------
61 42
62 #==============the end============== 43 #==============the end==============
63 44
64 45
65 ##--------end of code rendering .Rmd templates---------------- 46 ##--------end of code rendering .Rmd templates----------------