comparison DESeq_render.R @ 0:61c184384d02 draft default tip

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_deseq2
author mingchen0919
date Tue, 07 Nov 2017 10:02:57 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:61c184384d02
1 library(getopt)
2 library(rmarkdown)
3 library(htmltools)
4 library(dplyr)
5 library(stringi)
6 library(DESeq2)
7 library(pheatmap)
8 library(RColorBrewer)
9
10 ##============ Sink warnings and errors to a file ==============
11 ## use the sink() function to wrap all code within it.
12 ##==============================================================
13 zz = file('warnings_and_errors.txt')
14 sink(zz)
15 sink(zz, type = 'message')
16 ##---------below is the code for rendering .Rmd templates-----
17
18 ##=============STEP 1: handle command line arguments==========
19 ##
20 ##============================================================
21 # column 1: the long flag name
22 # column 2: the short flag alias. A SINGLE character string
23 # column 3: argument mask
24 # 0: no argument
25 # 1: argument required
26 # 2: argument is optional
27 # column 4: date type to which the flag's argument shall be cast.
28 # possible values: logical, integer, double, complex, character.
29 #-------------------------------------------------------------
30 #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++
31 # 1. short flag alias should match the flag in the command section in the XML file.
32 # 2. long flag name can be any legal R variable names
33 # 3. two names in args_list can have common string but one name should not be a part of another name.
34 # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems.
35 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36 args_list=list()
37 ##------- 1. input data ---------------------
38 args_list$ECHO = c('echo', 'e', '1', 'character')
39 args_list$COUNT_FILES = c('count_files', 'c', '1', 'character')
40 args_list$SAMPLE_TABLE = c('sample_table', 'S', '1', 'character')
41 args_list$DESIGN_FORMULA = c('design_formula', 'p', '1', 'character')
42 ##--------2. output report and outputs --------------
43 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character')
44 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character')
45 args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character')
46 args_list$WORKSPACE = c('deseq_workspace', 'w', '1', 'character')
47 ##--------3. .Rmd templates in the tool directory ----------
48 args_list$deseq_RMD = c('deseq_rmd', 't', '1', 'character')
49 ##-----------------------------------------------------------
50 opt = getopt(t(as.data.frame(args_list)))
51
52
53
54 ##=======STEP 2: create report directory (optional)==========
55 ##
56 ##===========================================================
57 dir.create(opt$report_dir)
58
59 ##=STEP 3: replace placeholders in .Rmd with argument values=
60 ##
61 ##===========================================================
62 #++ need to replace placeholders with args values one by one+
63 readLines(opt$deseq_rmd) %>%
64 (function(x) {
65 gsub('ECHO', opt$echo, x)
66 }) %>%
67 (function(x) {
68 gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x)
69 }) %>%
70 (function(x) {
71 gsub('DESIGN_FORMULA', opt$design_formula, x)
72 }) %>%
73 (function(x) {
74 gsub('REPORT_DIR', opt$output_dir, x)
75 }) %>%
76 (function(x) {
77 fileConn = file('deseq.Rmd')
78 writeLines(x, con=fileConn)
79 close(fileConn)
80 })
81
82
83 ##=============STEP 4: render .Rmd templates=================
84 ##
85 ##===========================================================
86 render('deseq.Rmd', output_file = opt$report_html)
87
88
89 ##--------end of code rendering .Rmd templates----------------
90 sink()
91 ##=========== End of sinking output=============================