Mercurial > repos > mingchen0919 > rmarkdown_deseq2
annotate DESeq_render.R @ 8:5f7665898fd9 draft
fix citation error
author | mingchen0919 |
---|---|
date | Tue, 07 Nov 2017 14:27:38 -0500 |
parents | 2f8ddef8d545 |
children |
rev | line source |
---|---|
6 | 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 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 | 11 ##============ Sink warnings and errors to a file ============== |
12 ## use the sink() function to wrap all code within it. | |
13 ##============================================================== | |
14 zz = file('warnings_and_errors.txt') | |
15 sink(zz) | |
16 sink(zz, type = 'message') | |
17 ##---------below is the code for rendering .Rmd templates----- | |
18 | |
19 ##=============STEP 1: handle command line arguments========== | |
20 ## | |
21 ##============================================================ | |
22 # column 1: the long flag name | |
23 # column 2: the short flag alias. A SINGLE character string | |
24 # column 3: argument mask | |
25 # 0: no argument | |
26 # 1: argument required | |
27 # 2: argument is optional | |
28 # column 4: date type to which the flag's argument shall be cast. | |
29 # possible values: logical, integer, double, complex, character. | |
30 #------------------------------------------------------------- | |
31 #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++ | |
32 # 1. short flag alias should match the flag in the command section in the XML file. | |
33 # 2. long flag name can be any legal R variable names | |
34 # 3. two names in args_list can have common string but one name should not be a part of another name. | |
35 # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems. | |
36 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
37 args_list=list() | |
38 ##------- 1. input data --------------------- | |
39 args_list$ECHO = c('echo', 'e', '1', 'character') | |
40 args_list$COUNT_FILE_PATHS = c('count_file_paths', 'P', '1', 'character') | |
41 args_list$COUNT_FILE_NAMES = c('count_file_names', 'N', '1', 'character') | |
42 args_list$SAMPLE_TABLE = c('sample_table', 'S', '1', 'character') | |
43 args_list$DESIGN_FORMULA = c('design_formula', 'p', '1', 'character') | |
44 ##--------2. output report and outputs -------------- | |
45 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character') | |
46 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character') | |
47 args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character') | |
48 args_list$WORKSPACE = c('deseq_workspace', 'w', '1', 'character') | |
49 ##--------3. .Rmd templates in the tool directory ---------- | |
50 args_list$deseq_RMD = c('deseq_rmd', 't', '1', 'character') | |
51 ##----------------------------------------------------------- | |
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 | 55 |
56 ##=======STEP 2: create report directory (optional)========== | |
57 ## | |
58 ##=========================================================== | |
59 dir.create(opt$report_dir) | |
60 | |
61 ##=STEP 3: replace placeholders in .Rmd with argument values= | |
62 ## | |
63 ##=========================================================== | |
64 #++ need to replace placeholders with args values one by one+ | |
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 | 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 | 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 | 79 fileConn = file('deseq.Rmd') |
80 writeLines(x, con=fileConn) | |
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 | 83 |
84 | |
85 ##=============STEP 4: render .Rmd templates================= | |
86 ## | |
87 ##=========================================================== | |
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 | 91 ##--------end of code rendering .Rmd templates---------------- |
92 sink() | |
93 ##=========== End of sinking output============================= |