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)
|
|
13 #------------------------------------------------
|
|
14
|
|
15
|
|
16 #------------get arguments into R--------------------
|
|
17 # library(dplyr)
|
|
18 # getopt_specification_matrix(extract_short_flags('')) %>%
|
|
19 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
|
|
20
|
|
21
|
|
22 spec_matrix = as.matrix(
|
|
23 data.frame(stringsAsFactors=FALSE,
|
|
24 long_flags = c("X_e", "X_o", "X_d", "X_s", "X_t", "X_A", "X_B", "X_G",
|
|
25 "X_f", "X_r", "X_S", "X_a", "X_T", "X_i", "X_m", "X_c", "X_O"),
|
|
26 short_flags = c("e", "o", "d", "s", "t", "A", "B", "G", "f", "r", "S",
|
|
27 "a", "T", "i", "m", "c", "O"),
|
|
28 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
|
|
29 1L, 1L, 1L, 1L),
|
|
30 data_type_flags = c("character", "character", "character", "character",
|
|
31 "character", "character", "character", "character",
|
|
32 "character", "character", "character", "character",
|
|
33 "character", "character", "character", "character",
|
|
34 "character")
|
|
35 )
|
|
36 )
|
|
37 opt = getopt(spec_matrix)
|
|
38 #----------------------------------------------------
|
|
39
|
|
40
|
|
41 #-----------using passed arguments in R
|
|
42 # to define system environment variables---
|
|
43 do.call(Sys.setenv, opt[-1])
|
|
44 #----------------------------------------------------
|
|
45
|
|
46 #---------- often used variables ----------------
|
|
47 # OUTPUT_REPORT: path to galaxy output report
|
|
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 OUTPUT_REPORT = opt$X_o
|
|
53
|
|
54
|
|
55 # create the output associated directory to store all outputs
|
|
56 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
57
|
|
58 #-----------------render site--------------
|
|
59 # copy site generating materials into OUTPUT_DIR
|
|
60 dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
|
|
61 system(paste0('cp -r ', TOOL_DIR, '/htseq_count.Rmd ', OUTPUT_DIR, '/site_generator/htseq_count.Rmdd'))
|
|
62 system(paste0('cp -r ', TOOL_DIR, '/htseq_count_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml'))
|
|
63 system(paste0('cp -r ', TOOL_DIR, '/htseq_count_index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd'))
|
|
64 # render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file
|
|
65 render_site(input = paste0(OUTPUT_DIR, '/site_generator'))
|
|
66 # remove site generating materials from output associated directory
|
|
67 unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
|
|
68 # move _site/* into output associated directory
|
|
69 move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR)
|
|
70 system(move_cmd)
|
|
71 #------------------------------------------
|
|
72
|
|
73 #-----link index.html to output-----
|
|
74 cp_index = paste0('cp ', OUTPUT_DIR, '/index.html ', OUTPUT_REPORT)
|
|
75 system(cp_index)
|
|
76 #-----------------------------------
|
|
77
|
|
78 #==============the end==============
|
|
79
|
|
80
|
|
81 ##--------end of code rendering .Rmd templates----------------
|
|
82 sink()
|
|
83 ##=========== End of sinking output============================= |