Mercurial > repos > mingchen0919 > rmarkdown_fastqc_site
comparison fastqc_site_render.R @ 7:d820be692d74 draft
planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastqc_site commit d91f269e8bc09a488ed2e005122bbb4a521f44a0-dirty
author | mingchen0919 |
---|---|
date | Tue, 08 Aug 2017 12:36:13 -0400 |
parents | |
children | 507eec497730 |
comparison
equal
deleted
inserted
replaced
6:2f4df2be0572 | 7:d820be692d74 |
---|---|
1 ##======= Handle arguments from command line ======== | |
2 # setup R error handline to go to stderr | |
3 options(show.error.messages=FALSE, | |
4 error=function(){ | |
5 cat(geterrmessage(), file=stderr()) | |
6 quit("no", 1, F) | |
7 }) | |
8 | |
9 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
10 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
11 | |
12 # suppress warning | |
13 options(warn = -1) | |
14 | |
15 options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) | |
16 args = commandArgs(trailingOnly=TRUE) | |
17 | |
18 suppressPackageStartupMessages({ | |
19 library(getopt) | |
20 library(tools) | |
21 }) | |
22 | |
23 # column 1: the long flag name | |
24 # column 2: the short flag alias. A SINGLE character string | |
25 # column 3: argument mask | |
26 # 0: no argument | |
27 # 1: argument required | |
28 # 2: argument is optional | |
29 # column 4: date type to which the flag's argument shall be cast. | |
30 # possible values: logical, integer, double, complex, character. | |
31 spec_list=list() | |
32 | |
33 ##------- 1. input data --------------------- | |
34 spec_list$READS = c('reads', 'r', '1', 'character') | |
35 spec_list$ECHO = c('echo', 'e', '1', 'character') | |
36 | |
37 ##--------2. output report and report site directory -------------- | |
38 spec_list$FASTQC_SITE = c('fastqc_site', 'o', '1', 'character') | |
39 spec_list$FASTQC_SITE_DIR = c('fastqc_site_dir', 'd', '1', 'character') | |
40 | |
41 ##--------3. Rmd templates sitting in the tool directory ---------- | |
42 | |
43 ## _site.yml and index.Rmd files | |
44 spec_list$SITE_YML = c('site_yml', 's', 1, 'character') | |
45 spec_list$INDEX_Rmd = c('index_rmd', 'i', 1, 'character') | |
46 | |
47 ## other Rmd body template files | |
48 spec_list$x01 = c('x01_evaluation_overview', 'p', '1', 'character') | |
49 spec_list$x02 = c('x02_fastqc_original_reports', 'a', '1', 'character') | |
50 spec_list$x1 = c('x1_per_base_quality_scores', 'b', '1', 'character') | |
51 spec_list$x2 = c('x2_per_base_N_content', 'c', '1', 'character') | |
52 spec_list$x3 = c('x3_per_sequence_quality_scores', 'f', '1', 'character') | |
53 spec_list$x4 = c('x4_per_sequence_GC_content', 'g', '1', 'character') | |
54 spec_list$x5 = c('x5_per_base_sequence_content', 'h', '1', 'character') | |
55 | |
56 ##------------------------------------------------------------------ | |
57 | |
58 spec = t(as.data.frame(spec_list)) | |
59 opt = getopt(spec) | |
60 # arguments are accessed by long flag name (the first column in the spec matrix) | |
61 # NOT by element name in the spec_list | |
62 # example: opt$help, opt$expression_file | |
63 ##====== End of arguments handling ========== | |
64 | |
65 #------ Load libraries --------- | |
66 library(rmarkdown) | |
67 library(plyr) | |
68 library(stringr) | |
69 library(dplyr) | |
70 library(highcharter) | |
71 library(DT) | |
72 library(reshape2) | |
73 library(plotly) | |
74 library(formattable) | |
75 library(htmltools) | |
76 | |
77 | |
78 #----- 1. create the report directory ------------------------ | |
79 paste0('mkdir -p ', opt$fastqc_site_dir) %>% | |
80 system() | |
81 | |
82 #----- 2. generate Rmd files with Rmd templates -------------- | |
83 # a. templates without placeholder variables: | |
84 # copy templates from tool directory to the working directory. | |
85 # b. templates with placeholder variables: | |
86 # substitute variables with user input values and place them in the working directory. | |
87 | |
88 | |
89 #----- Copy index.Rmd and _site.yml files to job working direcotry ----- | |
90 file.copy(opt$index_rmd, 'index.Rmd', recursive=TRUE) | |
91 file.copy(opt$site_yml, '_site.yml', recursive=TRUE) | |
92 #--------------------------------------------------------- | |
93 | |
94 #----- 01_evaluation_overview.Rmd ----------------------- | |
95 readLines(opt$x01_evaluation_overview) %>% | |
96 (function(x) { | |
97 gsub('ECHO', opt$echo, x) | |
98 }) %>% | |
99 (function(x) { | |
100 gsub('READS', opt$reads, x) | |
101 }) %>% | |
102 (function(x) { | |
103 gsub('REPORT_OUTPUT_DIR', opt$fastqc_site_dir, x) | |
104 }) %>% | |
105 (function(x) { | |
106 fileConn = file('01_evaluation_overview.Rmd') | |
107 writeLines(x, con=fileConn) | |
108 close(fileConn) | |
109 }) | |
110 | |
111 #----- 1_per_base_quality_scores.Rmd -------------------- | |
112 readLines(opt$x1_per_base_quality_scores) %>% | |
113 (function(x) { | |
114 gsub('ECHO', opt$echo, x) | |
115 }) %>% | |
116 (function(x) { | |
117 fileConn = file('1_per_base_quality_scores.Rmd') | |
118 writeLines(x, con=fileConn) | |
119 close(fileConn) | |
120 }) | |
121 | |
122 #----- 2_per_base_N_content.Rmd ------------------------- | |
123 readLines(opt$x2_per_base_N_content) %>% | |
124 (function(x) { | |
125 gsub('ECHO', opt$echo, x) | |
126 }) %>% | |
127 (function(x) { | |
128 fileConn = file('2_per_base_N_content.Rmd') | |
129 writeLines(x, con=fileConn) | |
130 close(fileConn) | |
131 }) | |
132 | |
133 #----- 3_per_sequence_quality_scores.Rmd ---------------- | |
134 readLines(opt$x3_per_sequence_quality_scores) %>% | |
135 (function(x) { | |
136 gsub('ECHO', opt$echo, x) | |
137 }) %>% | |
138 (function(x) { | |
139 fileConn = file('3_per_sequence_quality_scores.Rmd') | |
140 writeLines(x, con=fileConn) | |
141 close(fileConn) | |
142 }) | |
143 | |
144 | |
145 #----- 4_per_sequence_GC_content.Rmd -------------------- | |
146 readLines(opt$x4_per_sequence_GC_content) %>% | |
147 (function(x) { | |
148 gsub('ECHO', opt$echo, x) | |
149 }) %>% | |
150 (function(x) { | |
151 fileConn = file('4_per_sequence_GC_content.Rmd') | |
152 writeLines(x, con=fileConn) | |
153 close(fileConn) | |
154 }) | |
155 | |
156 | |
157 #----- 5_per_base_sequence_content.Rmd ------------------ | |
158 readLines(opt$x5_per_base_sequence_content) %>% | |
159 (function(x) { | |
160 gsub('ECHO', opt$echo, x) | |
161 }) %>% | |
162 (function(x) { | |
163 fileConn = file('5_per_base_sequence_content.Rmd') | |
164 writeLines(x, con=fileConn) | |
165 close(fileConn) | |
166 }) | |
167 | |
168 #----- 02_fastqc_original_reports.Rmd ------------------- | |
169 readLines(opt$x02_fastqc_original_reports) %>% | |
170 (function(x) { | |
171 gsub('ECHO', opt$echo, x) | |
172 }) %>% | |
173 (function(x) { | |
174 gsub('REPORT_OUTPUT_DIR', opt$fastqc_site_dir, x) | |
175 }) %>% | |
176 (function(x) { | |
177 fileConn = file('02_fastqc_original_reports.Rmd') | |
178 writeLines(x, con=fileConn) | |
179 close(fileConn) | |
180 }) | |
181 | |
182 | |
183 | |
184 #------ 3. render all Rmd files with render_site() -------- | |
185 render_site() | |
186 | |
187 | |
188 #-------4. manipulate outputs ----------------------------- | |
189 # a. copy index.html to the report output path | |
190 # b. copy all files in 'my_site' to the report output directory | |
191 file.copy('my_site/index.html', opt$fastqc_site, recursive=TRUE) | |
192 paste0('cp -r my_site/* ', opt$fastqc_site_dir) %>% | |
193 system() | |
194 | |
195 |