annotate rmarkdown_deseq2_count_matrix_render.R @ 2:8ceda5896765 draft default tip

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