| 
1
 | 
     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(stringr)
 | 
| 
 | 
    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
 | 
| 
 | 
    21 opt = getopt(getopt_specification_matrix('getopt_specification.csv'))
 | 
| 
 | 
    22 opt$X_t = Sys.getenv('TOOL_DIR')
 | 
| 
 | 
    23 working_dir = getwd()
 | 
| 
 | 
    24 Sys.setenv(WORKING_DIR = working_dir)
 | 
| 
 | 
    25 #----------------------------------------------------
 | 
| 
 | 
    26 
 | 
| 
 | 
    27 
 | 
| 
 | 
    28 #-----------using passed arguments in R 
 | 
| 
 | 
    29 #           to define system environment variables---
 | 
| 
 | 
    30 do.call(Sys.setenv, opt[-1])
 | 
| 
 | 
    31 #----------------------------------------------------
 | 
| 
 | 
    32 
 | 
| 
 | 
    33 #---------- often used variables ----------------
 | 
| 
 | 
    34 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
 | 
| 
 | 
    35 # TOOL_DIR: path to the tool installation directory
 | 
| 
 | 
    36 OUTPUT_DIR = opt$X_d
 | 
| 
 | 
    37 TOOL_DIR =   opt$X_t
 | 
| 
 | 
    38 OUTPUT_REPORT = opt$X_o
 | 
| 
 | 
    39 RMD_NAME = 'fastq_dump.Rmd'
 | 
| 
 | 
    40 
 | 
| 
 | 
    41 
 | 
| 
 | 
    42 # create the output associated directory to store all outputs
 | 
| 
 | 
    43 dir.create(OUTPUT_DIR, recursive = TRUE)
 | 
| 
 | 
    44 
 | 
| 
 | 
    45 #-----------------render Rmd--------------
 | 
| 
 | 
    46 render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
 | 
| 
 | 
    47 #------------------------------------------
 | 
| 
 | 
    48 
 | 
| 
 | 
    49 #==============the end==============
 | 
| 
 | 
    50 
 | 
| 
 | 
    51 
 | 
| 
 | 
    52 ##--------end of code rendering .Rmd templates----------------
 | 
| 
 | 
    53 sink()
 | 
| 
 | 
    54 ##=========== End of sinking output============================= |