annotate DESeq_render.R @ 8:5f7665898fd9 draft

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