|
2
|
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)
|
|
|
13 library(ggplot2)
|
|
|
14 library(plotly)
|
|
|
15 library(htmltools)
|
|
|
16 #------------------------------------------------
|
|
|
17
|
|
|
18
|
|
|
19 #------------get arguments into R--------------------
|
|
3
|
20 # library(dplyr)
|
|
|
21 # getopt_specification_matrix(extract_short_flags('deseq2.xml')) %>%
|
|
|
22 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
|
|
2
|
23
|
|
|
24
|
|
3
|
25 spec_matrix = as.matrix(
|
|
|
26 data.frame(stringsAsFactors=FALSE,
|
|
|
27 long_flags = c("X_e", "X_o", "X_d", "X_s", "X_t", "X_A", "X_B",
|
|
|
28 "X_C", "X_D", "X_E", "X_F", "X_G", "X_H", "X_I"),
|
|
|
29 short_flags = c("e", "o", "d", "s", "t", "A", "B", "C", "D", "E",
|
|
|
30 "F", "G", "H", "I", "J"),
|
|
|
31 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
|
|
|
32 1L, 1L),
|
|
|
33 data_type_flags = c("character", "character", "character", "character",
|
|
|
34 "character", "character", "character", "character",
|
|
|
35 "character", "character", "character", "character",
|
|
|
36 "character", "character", "character")
|
|
|
37 )
|
|
|
38 )
|
|
2
|
39 opt = getopt(spec_matrix)
|
|
|
40 #----------------------------------------------------
|
|
|
41
|
|
|
42
|
|
|
43 #-----------using passed arguments in R
|
|
|
44 # to define system environment variables---
|
|
|
45 do.call(Sys.setenv, opt[-1])
|
|
|
46 #----------------------------------------------------
|
|
|
47
|
|
|
48 #---------- often used variables ----------------
|
|
|
49 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
|
|
|
50 # TOOL_DIR: path to the tool installation directory
|
|
3
|
51 OUTPUT_DIR = opt$X_d
|
|
|
52 TOOL_DIR = opt$X_t
|
|
|
53 RMD_NAME = 'deseq2.Rmd'
|
|
2
|
54 OUTPUT_REPORT = opt$X_o
|
|
|
55
|
|
|
56 # create the output associated directory to store all outputs
|
|
|
57 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
|
58
|
|
|
59 #-----------------render Rmd--------------
|
|
3
|
60 render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
|
|
2
|
61 #------------------------------------------
|
|
|
62
|
|
|
63 #==============the end==============
|
|
|
64
|
|
|
65
|
|
|
66 ##--------end of code rendering .Rmd templates----------------
|
|
|
67 sink()
|
|
|
68 ##=========== End of sinking output============================= |