|
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 library(getopt)
|
|
|
9 library(rmarkdown)
|
|
|
10 library(htmltools)
|
|
|
11 library(plyr)
|
|
|
12 library(dplyr)
|
|
|
13 library(stringr)
|
|
|
14 library(DT)
|
|
|
15 library(reshape2)
|
|
|
16 library(plotly)
|
|
|
17 options(stringsAsFactors = FALSE)
|
|
|
18
|
|
|
19 # getopt_specification_matrix(extract_short_flags('fastqc_report.xml')) %>%
|
|
|
20 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
|
|
|
21
|
|
1
|
22
|
|
|
23 # get arguments into R
|
|
0
|
24 spec_matrix = as.matrix(
|
|
|
25 data.frame(stringsAsFactors=FALSE,
|
|
|
26 long_flags = c("X_e", "X_r", "X_n", "X_R", "X_N", "X_c", "X_l",
|
|
1
|
27 "X_o", "X_d", "X_s", "X_t"),
|
|
0
|
28 short_flags = c("e", "r", "n", "R", "N", "c", "l", "o", "d", "s",
|
|
1
|
29 "t"),
|
|
0
|
30 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
|
|
|
31 data_type_flags = c("character", "character", "character", "character",
|
|
|
32 "character", "character", "character",
|
|
|
33 "character", "character", "character", "character")
|
|
|
34 )
|
|
|
35 )
|
|
|
36 opt = getopt(spec_matrix)
|
|
4
|
37 #----------------------------------------------------
|
|
1
|
38
|
|
4
|
39
|
|
|
40 #-----------using passed arguments in R
|
|
|
41 # to define system environment variables---
|
|
0
|
42 do.call(Sys.setenv, opt[-1])
|
|
4
|
43 #----------------------------------------------------
|
|
|
44
|
|
|
45 #---------- often used variables ----------------
|
|
|
46 # OUTPUT_REPORT: path to galaxy output report
|
|
|
47 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
|
|
|
48 # TOOL_DIR: path to the tool installation directory
|
|
|
49 OUTPUT_DIR = opt$X_d
|
|
|
50 TOOL_DIR = opt$X_t
|
|
|
51 OUTPUT_REPORT = opt$X_o
|
|
|
52
|
|
0
|
53
|
|
1
|
54 # create the output associated directory to store all outputs
|
|
4
|
55 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
1
|
56
|
|
4
|
57 # copy site generating materials into OUTPUT_DIR
|
|
|
58 dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
|
|
|
59 system(paste0('cp -r ', TOOL_DIR, '/*.Rmd ', OUTPUT_DIR, '/site_generator/'))
|
|
|
60 system(paste0('cp -r ', TOOL_DIR, '/_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml'))
|
|
|
61 system(paste0('cp -r ', TOOL_DIR, '/index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd'))
|
|
|
62 # render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file
|
|
|
63 render_site(input = paste0(OUTPUT_DIR, '/site_generator'))
|
|
1
|
64 # remove site generating materials from output associated directory
|
|
4
|
65 unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
|
|
1
|
66 # move _site/* into output associated directory
|
|
4
|
67 move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR)
|
|
1
|
68 system(move_cmd)
|
|
|
69 #------------------------------------------
|
|
|
70
|
|
|
71 #-----link index.html to output-----
|
|
|
72 cp_index = paste0('cp ', opt$X_d, '/index.html ', opt$X_o)
|
|
|
73 system(cp_index)
|
|
|
74 #-----------------------------------
|
|
|
75
|
|
|
76 #==============the end==============
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80 # file.copy(paste0(opt$X_d, '/index.html'), opt$X_o, recursive = TRUE)
|
|
0
|
81
|
|
|
82 ##--------end of code rendering .Rmd templates----------------
|
|
|
83 sink()
|
|
|
84 ##=========== End of sinking output============================= |