Skip to content

Commit dde9b25

Browse files
committed
Documentation: update Sphinx 'conf.py' to use 'RstSimpleTable'.
Updated to use the 'RstSimpleTable' class from the 'docs' module to generate the tables of QC and Fastq generation protocols.
1 parent 89bfa01 commit dde9b25

1 file changed

Lines changed: 27 additions & 61 deletions

File tree

docs/source/conf.py

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -254,47 +254,37 @@
254254

255255
# -- Automatic content generation ---------------------------------------------
256256

257+
# Utilities for making auto-generated content
258+
from auto_process_ngs.docs import RstSimpleTable
259+
257260
# Directory for auto-generated content
258-
auto_content_dir = os.path.join("using","auto")
261+
auto_content_dir = os.path.join("using", "auto")
259262
if not os.path.exists(auto_content_dir):
260263
os.makedirs(auto_content_dir)
261264

262265
# -- Make table with QC protocols ---------------------------------------------
263266

264-
# Get list of QC protocol instances
267+
# Table appears in the "using/qc_protocols.rst" page and has columns
268+
269+
265270
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"])))
292280

293281
# -- Make table with Fastq generation protocols -----------------------------------
294282

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+
296286
from auto_process_ngs.bcl2fastq.protocols import PROTOCOLS as FQ_PROTOCOLS
297-
fq_protocols = []
287+
fq_protocols_data = []
298288
for p in FQ_PROTOCOLS:
299289
name = p
300290
description = FQ_PROTOCOLS[p]["description"]
@@ -304,37 +294,13 @@
304294
reads.append(str(FQ_PROTOCOLS[p][r]))
305295
except KeyError:
306296
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)"])))
338304

339305
# -- Make example plot images for QC report -----------------------------------
340306

0 commit comments

Comments
 (0)