Skip to content

Commit

Permalink
add option to specify additional HTMLs in docs
Browse files Browse the repository at this point in the history
You can now specify an `add_htmls_to_docs` variable in your `Snakefile`
that specifies additional files to include in the docs, like this:

    # add extra HTML to docs
    add_htmls_to_docs = {
        "Additional files": {
            "Example HTML file": "results/extra_htmls/example_html.html",
        },
    }

Also, `snakemake` was upgraded to 8.5.4.
  • Loading branch information
jbloom committed Mar 7, 2024
1 parent 2e80ff8 commit 7522de2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

### version 2.2.0
- Add the `add_htmls_to_docs` option, which can be specified in `Snakefile` to add additional HTML documentation to pipeline.
- Update to `snakemake` 8.5.4.

### version 2.1.0
- Add an option to specify `miscellaneous_plates` which are plates that just have their barcodes counted (addresses [this issue](https://github.com/jbloomlab/seqneut-pipeline/issues/26)).

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ Looking at this documentation is a good way to QC the data and understand the re

The documentation for the test example for this pipeline is at [https://jbloomlab.github.io/seqneut-pipeline/](https://jbloomlab.github.io/seqneut-pipeline/).

If you want to add additional HTML files to the docs, specify a dict in the top-level `Snakefile` with the name `add_htmls_to_docs` like this:
```
add_htmls_to_docs = {
"Additional files": {
"Example HTML file": "results/extra_htmls/example_html.html",
<other keys specifying file names and their paths>
},
<other nested dicts with a heading and then name: file key-value pairs>
}
```

## Test example and testing via GitHub Actions
The [./test_example](test_example) subdirectory contains a small test example that illustrates use of the pipeline.

Expand Down
6 changes: 6 additions & 0 deletions docs/example_html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<body>
Example HTML file
</body>
</html>
5 changes: 4 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h1 id="test-example-for-seqneut-pipeline">Test example for <a href="https://git
<li><a href="#per-serum-neutralization-titers">Per-serum neutralization titers</a></li>
<li><a href="#per-plate-counts-and-curve-fits">Per-plate counts and curve fits</a></li>
<li><a href="#summary-of-data-dropped-during-quality-control">Summary of data dropped during quality control</a></li>
<li><a href="#additional-files">Additional files</a></li>
</ul>
</div>
<h2 id="titers-for-all-sera">Titers for all sera</h2>
Expand All @@ -26,4 +27,6 @@ <h2 id="per-plate-counts-and-curve-fits">Per-plate counts and curve fits</h2>
<li><a href="process_plate11.html">plate11</a></li>
</ul>
<h2 id="summary-of-data-dropped-during-quality-control">Summary of data dropped during quality control</h2>
<p><a href="aggregate_qc_drops.html">Notebook summarizing QC drops</a></p>
<p><a href="aggregate_qc_drops.html">Notebook summarizing QC drops</a></p>
<h2 id="additional-files">Additional files</h2>
<p><a href="example_html.html">Example HTML file</a></p>
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- python=3.11
- ruamel.yaml=0.18.5
- snakefmt
- snakemake=8.0.1
- snakemake=8.5.4
- ruff
- pip:
- dms_variants==1.5.0
Expand Down
5 changes: 5 additions & 0 deletions scripts/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
f"[Notebook summarizing QC drops]({os.path.basename(copied_files[snakemake.input.qc_drops_html])})",
]

for heading, heading_d in snakemake.params.add_htmls_to_docs.items():
md_text += ["", f"## {heading}"]
for name, fname in heading_d.items():
md_text.append(f"[{name}]({os.path.basename(copied_files[fname])})")

md_text = "\n".join(md_text)

print(f"Rendering the following markdown text:\n\n{md_text}\n\n")
Expand Down
11 changes: 11 additions & 0 deletions seqneut-pipeline.smk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ if "miscellaneous_plates" in config:
else:
miscellaneous_plates = {}

# define `add_htmls_to_docs` if not already defined.
try:
add_htmls_to_docs
except NameError: # if not defined
add_htmls_to_docs = {}


# --- Snakemake rules -------------------------------------------------------------------

Expand Down Expand Up @@ -228,6 +234,7 @@ rule notebook_to_html:
rule build_docs:
"""Build the HTML documentation."""
input:
lambda wc: [f for d in add_htmls_to_docs.values() for f in d.values()],
titers_chart=rules.aggregate_titers.output.titers_chart,
serum_titers_htmls=lambda wc: expand(
"results/sera/{serum}/{serum}_titers.html",
Expand All @@ -244,6 +251,10 @@ rule build_docs:
description=config["description"],
sera=lambda wc: list(sera_plates()),
plates=list(plates),
add_htmls_to_docs=lambda wc: {
key: {key2: str(val2) for (key2, val2) in val.items()}
for (key, val) in add_htmls_to_docs.items()
},
conda:
"environment.yml"
log:
Expand Down
31 changes: 31 additions & 0 deletions test_example/Snakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Top-level ``snakemake`` file that runs analysis."""

import os
import textwrap


configfile: "config.yml"
Expand All @@ -12,3 +13,33 @@ include: os.path.join(config["seqneut-pipeline"], "seqneut-pipeline.smk")
rule all:
input:
seqneut_pipeline_outputs,


rule make_extra_html_for_docs:
"""Write example HTML for docs."""
output:
html="results/extra_htmls/example_html.html",
log:
"results/logs/make_extra_html_for_docs.txt",
run:
with open(output.html, "w") as f:
f.write(
textwrap.dedent(
"""\
<!DOCTYPE html>
<html lang="en">
<body>
Example HTML file
</body>
</html>
"""
)
)


# add extra HTML to docs
add_htmls_to_docs = {
"Additional files": {
"Example HTML file": "results/extra_htmls/example_html.html",
},
}

0 comments on commit 7522de2

Please sign in to comment.