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