annotate rmarkdown_deseq2_count_matrix_render.R @ 0:c1f718dd6c7a draft

planemo upload
author mingchen0919
date Sat, 30 Dec 2017 00:25:38 -0500
parents
children 629323b5fc0c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
1 library(getopt)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
2 library(rmarkdown)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
3 library(htmltools)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
4 library(dplyr)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
5
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
6 ##============ Sink warnings and errors to a file ==============
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
7 ## use the sink() function to wrap all code within it.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
8 ##==============================================================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
9 zz = file('warnings_and_errors.txt')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
10 sink(zz)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
11 sink(zz, type = 'message')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
12 ##---------below is the code for rendering .Rmd templates-----
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
13
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
14 ##=============STEP 1: handle command line arguments==========
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
15 ##
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
16 ##============================================================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
17 # column 1: the long flag name
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
18 # column 2: the short flag alias. A SINGLE character string
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
19 # column 3: argument mask
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
20 # 0: no argument
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
21 # 1: argument required
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
22 # 2: argument is optional
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
23 # column 4: date type to which the flag's argument shall be cast.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
24 # possible values: logical, integer, double, complex, character.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
25 #-------------------------------------------------------------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
26 #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
27 # 1. short flag alias should match the flag in the command section in the XML file.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
28 # 2. long flag name can be any legal R variable names
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
29 # 3. two names in args_list can have common string but one name should not be a part of another name.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
30 # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems.
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
31 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
32 args_list=list()
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
33 ##------- 1. input data ---------------------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
34 args_list$ECHO = c('echo', 'e', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
35 args_list$c = c('count_data', 'c', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
36 args_list$C = c('col_data', 'C', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
37 args_list$D = c('design_formula', 'D', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
38 args_list$k = c('contrast_condition', 'k', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
39 args_list$T = c('treatment', 'T', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
40 args_list$K = c('control', 'K', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
41 ##--------2. output report and outputs --------------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
42 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
43 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
44 args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
45 ##--------3. .Rmd templates in the tool directory ----------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
46 args_list$TOOL_TEMPLATE_RMD = c('tool_template_rmd', 't', '1', 'character')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
47 ##-----------------------------------------------------------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
48 opt = getopt(t(as.data.frame(args_list)))
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
49
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
50
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
51
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
52 ##=======STEP 2: create report directory (optional)==========
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
53 ##
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
54 ##===========================================================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
55 dir.create(opt$report_dir)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
56
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
57 ##=STEP 3: replace placeholders in .Rmd with argument values=
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
58 ##
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
59 ##===========================================================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
60 #++ need to replace placeholders with args values one by one+
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
61 readLines(opt$tool_template_rmd) %>%
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
62 # (function(x) {
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
63 # gsub('ECHO', opt$echo, x)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
64 # }) %>%
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
65 # (function(x) {
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
66 # gsub('REPORT_DIR', opt$report_dir, x)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
67 # }) %>%
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
68 (function(x) {
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
69 fileConn = file('tool_template.Rmd')
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
70 writeLines(x, con=fileConn)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
71 close(fileConn)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
72 })
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
73
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
74
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
75 ##=============STEP 4: render .Rmd templates=================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
76 ##
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
77 ##===========================================================
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
78 render('tool_template.Rmd', output_file = opt$report_html)
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
79
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
80
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
81 ##--------end of code rendering .Rmd templates----------------
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
82 sink()
c1f718dd6c7a planemo upload
mingchen0919
parents:
diff changeset
83 ##=========== End of sinking output=============================