annotate DESeq_results_render.R @ 7:466053167103 draft

update deseq2
author mingchen0919
date Tue, 07 Nov 2017 13:51:10 -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(DESeq2)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
6 library(pheatmap)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
7 library(genefilter)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
8 library(DT)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
9 library(stringi)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
10 library(RColorBrewer)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
11 library(ggplot2)
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
12
6
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
13 ##============ Sink warnings and errors to a file ==============
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
14 ## use the sink() function to wrap all code within it.
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
15 ##==============================================================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
16 zz = file('warnings_and_errors.txt')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
17 sink(zz)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
18 sink(zz, type = 'message')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
19 ##---------below is the code for rendering .Rmd templates-----
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
20
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
21 ##=============STEP 1: handle command line arguments==========
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
22 ##
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
23 ##============================================================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
24 # column 1: the long flag name
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
25 # column 2: the short flag alias. A SINGLE character string
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
26 # column 3: argument mask
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
27 # 0: no argument
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
28 # 1: argument required
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
29 # 2: argument is optional
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
30 # column 4: date type to which the flag's argument shall be cast.
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
31 # possible values: logical, integer, double, complex, character.
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
32 #-------------------------------------------------------------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
33 #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
34 # 1. short flag alias should match the flag in the command section in the XML file.
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
35 # 2. long flag name can be any legal R variable names
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
36 # 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
37 # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems.
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
38 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
39 args_list=list()
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
40 ##------- 1. input data ---------------------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
41 args_list$ECHO = c('echo', 'e', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
42 args_list$DESEQ_WORKSPACE = c('deseq_workspace', 'W', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
43 args_list$CONTRAST_FACTOR = c('contrast_factor', 'C', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
44 args_list$TREATMENT_LEVEL = c('treatment_level', 'T', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
45 args_list$CONDITION_LEVEL = c('condition_level', 'K', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
46 args_list$CLUSTERING_FACTORS = c('clustering_factors', 'M', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
47 ##--------2. output report and outputs --------------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
48 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
49 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
50 args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
51 args_list$DESEQ_RESULTS = c('deseq_results', 'R', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
52 ##--------3. .Rmd templates in the tool directory ----------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
53 args_list$deseq_results_RMD = c('deseq_results_rmd', 't', '1', 'character')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
54 ##-----------------------------------------------------------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
55 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
56
7231d7e8d3ed planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_deseq2 commit 9285c2b8ad41a486dde2a87600a6b8267841c8b5-dirty
mingchen0919
parents:
diff changeset
57
6
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
58
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
59 ##=======STEP 2: create report directory (optional)==========
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
60 ##
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
61 ##===========================================================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
62 dir.create(opt$report_dir)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
63
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
64 ##=STEP 3: replace placeholders in .Rmd with argument values=
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
65 ##
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
66 ##===========================================================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
67 #++ need to replace placeholders with args values one by one+
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
68 readLines(opt$deseq_results_rmd) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
69 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
70 gsub('ECHO', opt$echo, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
71 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
72 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
73 gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
74 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
75 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
76 gsub('CONTRAST_FACTOR', opt$contrast_factor, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
77 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
78 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
79 gsub('TREATMENT_LEVEL', opt$treatment_level, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
80 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
81 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
82 gsub('CONDITION_LEVEL', opt$condition_level, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
83 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
84 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
85 gsub('CLUSTERING_FACTORS', opt$clustering_factors, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
86 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
87 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
88 gsub('REPORT_DIR', opt$report_dir, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
89 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
90 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
91 gsub('DESEQ_RESULTS', opt$deseq_results, x)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
92 }) %>%
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
93 (function(x) {
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
94 fileConn = file('deseq_results.Rmd')
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
95 writeLines(x, con=fileConn)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
96 close(fileConn)
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
97 })
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
98
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
99
6
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
100 ##=============STEP 4: render .Rmd templates=================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
101 ##
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
102 ##===========================================================
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
103 render('deseq_results.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
104
7231d7e8d3ed planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_deseq2 commit 9285c2b8ad41a486dde2a87600a6b8267841c8b5-dirty
mingchen0919
parents:
diff changeset
105
6
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
106 ##--------end of code rendering .Rmd templates----------------
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
107 sink()
2f8ddef8d545 update deseq2
mingchen0919
parents: 0
diff changeset
108 ##=========== End of sinking output=============================