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