|
254 | 254 |
|
255 | 255 | # -- Automatic content generation --------------------------------------------- |
256 | 256 |
|
| 257 | +# Utilities for making auto-generated content |
| 258 | +from auto_process_ngs.docs import RstSimpleTable |
| 259 | + |
257 | 260 | # Directory for auto-generated content |
258 | | -auto_content_dir = os.path.join("using","auto") |
| 261 | +auto_content_dir = os.path.join("using", "auto") |
259 | 262 | if not os.path.exists(auto_content_dir): |
260 | 263 | os.makedirs(auto_content_dir) |
261 | 264 |
|
262 | 265 | # -- Make table with QC protocols --------------------------------------------- |
263 | 266 |
|
264 | | -# Get list of QC protocol instances |
| 267 | +# Table appears in the "using/qc_protocols.rst" page and has columns |
| 268 | + |
| 269 | + |
265 | 270 | from auto_process_ngs.qc import protocols |
266 | | -qc_protocols = [] |
267 | | -for p in protocols.QC_PROTOCOLS: |
268 | | - qc_protocols.append(protocols.fetch_protocol_definition(p)) |
269 | | -# Get width for protocol name column |
270 | | -pr_width = max([len(p.name)+4 for p in qc_protocols]) |
271 | | -ds_width = 26 |
272 | | -# Generate file with table of protocol names and descriptions |
273 | | -qc_protocols_tbl = os.path.join(auto_content_dir,"qc_protocols.rst") |
274 | | -with open(qc_protocols_tbl,'wt') as fp: |
275 | | - # Write table header |
276 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}}\n".format( |
277 | | - x='',pr_width=pr_width,ds_width=ds_width)) |
278 | | - fp.write("{name: <{pr_width}} {desc}\n".format(name="QC protocol", |
279 | | - desc="Description", |
280 | | - pr_width=pr_width)) |
281 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}}\n".format( |
282 | | - x='',pr_width=pr_width,ds_width=ds_width)) |
283 | | - # Write protocol information |
284 | | - for p in qc_protocols: |
285 | | - fp.write("{name: <{pr_width}} {description}\n".format( |
286 | | - name="``{name}``".format(name=p.name), |
287 | | - description=p.description, |
288 | | - pr_width=pr_width)) |
289 | | - # Write table footer |
290 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}}\n".format( |
291 | | - x='',pr_width=pr_width,ds_width=ds_width)) |
| 271 | +qc_protocols_data = [] |
| 272 | +for qc_protocol in protocols.QC_PROTOCOLS: |
| 273 | + p = protocols.fetch_protocol_definition(qc_protocol) |
| 274 | + qc_protocols_data.append([f"``{p.name}``", p.description]) |
| 275 | +tbl = RstSimpleTable(qc_protocols_data) |
| 276 | +qc_protocols_rst = os.path.join(auto_content_dir,"qc_protocols.rst") |
| 277 | +with open(qc_protocols_rst, "wt") as fp: |
| 278 | + fp.write("\n".join(tbl.construct_table( |
| 279 | + header=["QC protocol", "Description"]))) |
292 | 280 |
|
293 | 281 | # -- Make table with Fastq generation protocols ----------------------------------- |
294 | 282 |
|
295 | | -# Get list of Fastq generation protocols |
| 283 | +# Table appears in the "using/make_fastqs.rst" page and has columns |
| 284 | +# with protocol name, description and read lengths |
| 285 | + |
296 | 286 | from auto_process_ngs.bcl2fastq.protocols import PROTOCOLS as FQ_PROTOCOLS |
297 | | -fq_protocols = [] |
| 287 | +fq_protocols_data = [] |
298 | 288 | for p in FQ_PROTOCOLS: |
299 | 289 | name = p |
300 | 290 | description = FQ_PROTOCOLS[p]["description"] |
|
304 | 294 | reads.append(str(FQ_PROTOCOLS[p][r])) |
305 | 295 | except KeyError: |
306 | 296 | pass |
307 | | - fq_protocols.append((p, description, " | ".join(reads))) |
308 | | -fq_protocols = sorted(fq_protocols, key=lambda p: p[0]) |
309 | | -# Get width for protocol name column |
310 | | -pr_width = max([len(p[0])+4 for p in fq_protocols]) |
311 | | -ds_width = max([len(p[1]) for p in fq_protocols]) |
312 | | -rd_width = 12 |
313 | | -# Generate file with table of protocol names and descriptions |
314 | | -fq_protocols_tbl = os.path.join(auto_content_dir, "fq_protocols.rst") |
315 | | -with open(fq_protocols_tbl, "wt") as fp: |
316 | | - # Write table header |
317 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}} {x:=<{rd_width}}\n".format( |
318 | | - x='', pr_width=pr_width, ds_width=ds_width, rd_width=rd_width)) |
319 | | - fp.write("{name: <{pr_width}} {desc: <{ds_width}} {reads}\n".format( |
320 | | - name="Protocol", |
321 | | - desc="Description", |
322 | | - reads="Read lengths (R1 | R2 | R3)", |
323 | | - pr_width=pr_width, |
324 | | - ds_width=ds_width)) |
325 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}} {x:=<{rd_width}}\n".format( |
326 | | - x='', pr_width=pr_width, ds_width=ds_width, rd_width=rd_width)) |
327 | | - # Write protocol information |
328 | | - for p in fq_protocols: |
329 | | - fp.write("{name: <{pr_width}} {description: <{ds_width}} {reads}\n".format( |
330 | | - name="``{name}``".format(name=p[0]), |
331 | | - description=p[1], |
332 | | - reads=p[2], |
333 | | - pr_width=pr_width, |
334 | | - ds_width=ds_width)) |
335 | | - # Write table footer |
336 | | - fp.write("{x:=<{pr_width}} {x:=<{ds_width}} {x:=<{rd_width}}\n".format( |
337 | | - x='', pr_width=pr_width, ds_width=ds_width, rd_width=rd_width)) |
| 297 | + fq_protocols_data.append([f"``{p}``", description, " | ".join(reads)]) |
| 298 | +fq_protocols_data = sorted(fq_protocols_data, key=lambda p: p[0]) |
| 299 | +tbl = RstSimpleTable(fq_protocols_data) |
| 300 | +fq_protocols_rst = os.path.join(auto_content_dir, "fq_protocols.rst") |
| 301 | +with open(fq_protocols_rst, "wt") as fp: |
| 302 | + fp.write("\n".join(tbl.construct_table( |
| 303 | + header=["Protocol", "Description", "Read lengths (R1 | R2 | R3)"]))) |
338 | 304 |
|
339 | 305 | # -- Make example plot images for QC report ----------------------------------- |
340 | 306 |
|
|
0 commit comments