Mercurial > repos > mingchen0919 > rmarkdown_fastqc_site
comparison fastqc_site_render.R @ 0:d732d4526c6d draft
planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastqc_site commit ddb1f6aca7619aea2e660b1729367841b56ba4c9-dirty
author | mingchen0919 |
---|---|
date | Tue, 08 Aug 2017 10:14:46 -0400 |
parents | |
children | 58f3c3128fdd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d732d4526c6d |
---|---|
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(Kmisc) | |
74 library(plotly) | |
75 library(formattable) | |
76 library(htmltools) | |
77 | |
78 | |
79 #----- 1. create the report directory ------------------------ | |
80 paste0('mkdir -p ', opt$fastqc_site_dir) %>% | |
81 system() | |
82 | |
83 #----- 2. generate Rmd files with Rmd templates -------------- | |
84 # a. templates without placeholder variables: | |
85 # copy templates from tool directory to the working directory. | |
86 # b. templates with placeholder variables: | |
87 # substitute variables with user input values and place them in the working directory. | |
88 | |
89 | |
90 #----- Copy index.Rmd and _site.yml files to job working direcotry ----- | |
91 file.copy(opt$index_rmd, 'index.Rmd', recursive=TRUE) | |
92 file.copy(opt$site_yml, '_site.yml', recursive=TRUE) | |
93 #--------------------------------------------------------- | |
94 | |
95 #----- 01_evaluation_overview.Rmd ----------------------- | |
96 readLines(opt$x01_evaluation_overview) %>% | |
97 (function(x) { | |
98 gsub('ECHO', opt$echo, x) | |
99 }) %>% | |
100 (function(x) { | |
101 gsub('READS', opt$reads, x) | |
102 }) %>% | |
103 (function(x) { | |
104 gsub('REPORT_OUTPUT_DIR', opt$fastqc_site_dir, x) | |
105 }) %>% | |
106 (function(x) { | |
107 fileConn = file('01_evaluation_overview.Rmd') | |
108 writeLines(x, con=fileConn) | |
109 close(fileConn) | |
110 }) | |
111 | |
112 #----- 1_per_base_quality_scores.Rmd -------------------- | |
113 readLines(opt$x1_per_base_quality_scores) %>% | |
114 (function(x) { | |
115 gsub('ECHO', opt$echo, x) | |
116 }) %>% | |
117 (function(x) { | |
118 fileConn = file('1_per_base_quality_scores.Rmd') | |
119 writeLines(x, con=fileConn) | |
120 close(fileConn) | |
121 }) | |
122 | |
123 #----- 2_per_base_N_content.Rmd ------------------------- | |
124 readLines(opt$x2_per_base_N_content) %>% | |
125 (function(x) { | |
126 gsub('ECHO', opt$echo, x) | |
127 }) %>% | |
128 (function(x) { | |
129 fileConn = file('2_per_base_N_content.Rmd') | |
130 writeLines(x, con=fileConn) | |
131 close(fileConn) | |
132 }) | |
133 | |
134 #----- 3_per_sequence_quality_scores.Rmd ---------------- | |
135 readLines(opt$x3_per_sequence_quality_scores) %>% | |
136 (function(x) { | |
137 gsub('ECHO', opt$echo, x) | |
138 }) %>% | |
139 (function(x) { | |
140 fileConn = file('3_per_sequence_quality_scores.Rmd') | |
141 writeLines(x, con=fileConn) | |
142 close(fileConn) | |
143 }) | |
144 | |
145 | |
146 #----- 4_per_sequence_GC_content.Rmd -------------------- | |
147 readLines(opt$x4_per_sequence_GC_content) %>% | |
148 (function(x) { | |
149 gsub('ECHO', opt$echo, x) | |
150 }) %>% | |
151 (function(x) { | |
152 fileConn = file('4_per_sequence_GC_content.Rmd') | |
153 writeLines(x, con=fileConn) | |
154 close(fileConn) | |
155 }) | |
156 | |
157 | |
158 #----- 5_per_base_sequence_content.Rmd ------------------ | |
159 readLines(opt$x5_per_base_sequence_content) %>% | |
160 (function(x) { | |
161 gsub('ECHO', opt$echo, x) | |
162 }) %>% | |
163 (function(x) { | |
164 fileConn = file('5_per_base_sequence_content.Rmd') | |
165 writeLines(x, con=fileConn) | |
166 close(fileConn) | |
167 }) | |
168 | |
169 #----- 02_fastqc_original_reports.Rmd ------------------- | |
170 readLines(opt$x02_fastqc_original_reports) %>% | |
171 (function(x) { | |
172 gsub('ECHO', opt$echo, x) | |
173 }) %>% | |
174 (function(x) { | |
175 gsub('REPORT_OUTPUT_DIR', opt$fastqc_site_dir, x) | |
176 }) %>% | |
177 (function(x) { | |
178 fileConn = file('02_fastqc_original_reports.Rmd') | |
179 writeLines(x, con=fileConn) | |
180 close(fileConn) | |
181 }) | |
182 | |
183 | |
184 | |
185 #------ 3. render all Rmd files with render_site() -------- | |
186 render_site() | |
187 | |
188 | |
189 #-------4. manipulate outputs ----------------------------- | |
190 # a. copy index.html to the report output path | |
191 # b. copy all files in 'my_site' to the report output directory | |
192 file.copy('my_site/index.html', opt$fastqc_site, recursive=TRUE) | |
193 paste0('cp -r my_site/* ', opt$fastqc_site_dir) %>% | |
194 system() | |
195 | |
196 |