|
0
|
1 ##============ Sink warnings and errors to a file ==============
|
|
|
2 ## use the sink() function to wrap all code within it.
|
|
|
3 ##==============================================================
|
|
|
4 zz = file('warnings_and_errors.txt')
|
|
|
5 sink(zz)
|
|
|
6 sink(zz, type = 'message')
|
|
|
7
|
|
|
8 #------------import libraries--------------------
|
|
|
9 options(stringsAsFactors = FALSE)
|
|
|
10
|
|
|
11 library(getopt)
|
|
|
12 library(rmarkdown)
|
|
1
|
13 library(htmltools)
|
|
0
|
14 #------------------------------------------------
|
|
|
15
|
|
|
16
|
|
|
17 #------------get arguments into R--------------------
|
|
|
18 # load helper function
|
|
|
19 source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R'))
|
|
|
20 # import getopt specification matrix from a csv file
|
|
1
|
21 opt = getopt(getopt_specification_matrix(specification_file = '/getopt_specification.csv',
|
|
0
|
22 tool_dir = Sys.getenv('TOOL_DIR')))
|
|
|
23 opt$X_t = Sys.getenv('TOOL_DIR')
|
|
|
24 #----------------------------------------------------
|
|
|
25
|
|
|
26
|
|
|
27 #-----------using passed arguments in R
|
|
|
28 # to define system environment variables---
|
|
|
29 do.call(Sys.setenv, opt[-1])
|
|
|
30 #----------------------------------------------------
|
|
|
31
|
|
|
32 #---------- often used variables ----------------
|
|
|
33 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
|
|
|
34 # TOOL_DIR: path to the tool installation directory
|
|
|
35 OUTPUT_DIR = opt$X_d
|
|
|
36 TOOL_DIR = opt$X_t
|
|
|
37 OUTPUT_REPORT = opt$X_o
|
|
|
38 RMD_NAME = 'interproscan.Rmd'
|
|
|
39
|
|
|
40 # create the output associated directory to store all outputs
|
|
|
41 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
|
42
|
|
|
43 #-----------------render Rmd--------------
|
|
|
44 # for some unknow reason, directly using REPORT as the input value for output_file parameter
|
|
|
45 # in the render function can cause empty report file when the tool runs in batch mode.
|
|
|
46 # the solution is to render the rmarkdown to a explicitly specified file and then copy the
|
|
|
47 # file to ${REPORT}
|
|
|
48 render(paste0(TOOL_DIR, '/', RMD_NAME),
|
|
1
|
49 output_file = paste0(OUTPUT_DIR, '/report.html'))
|
|
|
50 system(command = 'cp ${X_d}/report.html ${X_o}')
|
|
0
|
51 #------------------------------------------
|
|
|
52
|
|
|
53 #==============the end==============
|
|
|
54
|
|
|
55
|
|
|
56 ##--------end of code rendering .Rmd templates----------------
|
|
|
57 sink()
|
|
|
58 ##=========== End of sinking output============================= |