Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Colons are now used instead of commas to separate SNP alleles in microhap alleles (#192).
- Implemented Python 3.12 support by integrating happer package and increasing minimum version of MicroHapDB dependency (#193).
- Updated working directory organization to provide additional structure (#194).
- Snakemake is now invoked using its new Python API, requiring a minimum version of 8.0 and Python 3.11+ (#195).

### Fixed
- Bug with handling marker vs. locus identifiers when running `mhpl8r seq` (#190).
Expand Down
41 changes: 26 additions & 15 deletions microhapulator/cli/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from os import cpu_count, symlink
from pathlib import Path
from shutil import copy
from snakemake import snakemake
from snakemake.api import SnakemakeApi as smk_api
from snakemake.exceptions import WorkflowError
from snakemake.settings import types as smk_types
import sys


Expand All @@ -29,10 +31,10 @@ def main(args):
config = dict(
samples=samples,
readfiles=workingfiles,
mhrefr=Path(args.markerrefr).resolve(),
mhdefn=Path(args.markerdefn).resolve(),
hg38path=Path(args.hg38).resolve(),
hg38index=Path(args.hg38idx).resolve(),
mhrefr=str(Path(args.markerrefr).resolve()),
mhdefn=str(Path(args.markerdefn).resolve()),
hg38path=str(Path(args.hg38).resolve()),
hg38index=str(Path(args.hg38idx).resolve()),
Comment on lines +34 to +37
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing paths here also caused an issue with newer versions of Snakemake where they didn't with version 7. 🤷‍♂️

thresh_static=args.static,
thresh_dynamic=args.dynamic,
thresh_file=args.config,
Expand All @@ -43,19 +45,28 @@ def main(args):
thresh_gap_alert=args.gap_alert,
hspace=args.hspace,
)
snakefile = files("microhapulator") / "workflows" / "analysis.smk"
success = snakemake(
snakefile,
cores=args.threads,
printshellcmds=True,
dryrun=args.dryrun,
config=config,
workdir=args.workdir,
)
if not success:
try:
run_snakemake(config, args.workdir, cores=args.threads, dryrun=args.dryrun)
return 0
except WorkflowError:
return 1


def run_snakemake(config, workdir, cores=1, dryrun=False):
outcfg = smk_types.OutputSettings(printshellcmds=True)
with smk_api(outcfg) as smk:
workflow = smk.workflow(
config_settings=smk_types.ConfigSettings(config=config),
storage_settings=smk_types.StorageSettings(),
resource_settings=smk_types.ResourceSettings(cores=cores),
snakefile=files("microhapulator") / "workflows" / "analysis.smk",
workdir=Path(workdir),
)
dag = workflow.dag(smk_types.DAGSettings(targets=["report"]))
mode = "dryrun" if dryrun else "local"
dag.execute_workflow(executor=mode)
Comment on lines +55 to +67
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is close to the minimal code required to replicate the flags I commonly used with the snakemake.snakemake command in version 7 and below.



def validate_panel_config(markerseqs, markerdefn):
print("[MicroHapulator] validating panel configuration", file=sys.stderr)
index = MicrohapIndex.from_files(markerdefn, markerseqs)
Expand Down
6 changes: 4 additions & 2 deletions microhapulator/workflows/analysis.smk
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ rule apply_filters:
params:
static=f"--static {config['thresh_static']}",
dynamic=f"--dynamic {config['thresh_dynamic']}",
threshfile="" if config["thresh_file"] == "" else f"--config {config['thresh_file']}",
threshfile=(
"" if config["thresh_file"] in ("", None) else f"--config {config['thresh_file']}"
),
Comment on lines -214 to +216
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the newer versions of Snakemake were converting the empty string in the config dictionary into None, so this change just accounts for both.

shell:
"mhpl8r filter {input} --out {output} {params.static} {params.dynamic} {params.threshfile}"

Expand Down Expand Up @@ -270,7 +272,7 @@ rule plot_haplotype_calls:
result = TypingResult(fromfile=input.result)
mhapi.plot_haplotype_calls(
result,
"analysis/{}/03typing/callplots".format(wildcards.sample),
f"analysis/{wildcards.sample}/03typing/callplots",
Comment on lines -273 to +275
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reinstating f-strings since they don't break Python 3.12 in Snakemake 9.

sample=wildcards.sample,
)

Expand Down
3 changes: 1 addition & 2 deletions microhapulator/workflows/preproc-paired.smk
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ rule fastqc:
outfiles = sorted(Path(params.outdir).glob("*.html"))
for end, outfile in enumerate(outfiles, 1):
outfile = Path(outfile)
# Snakemake f-strings break with Python 3.12: https://github.com/snakemake/snakemake/issues/2648
linkfile = "{}/R{}-fastqc.html".format(params.outdir, end)
linkfile = f"{params.outdir}/R{end}-fastqc.html"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reinstated f-string.

symlink(outfile.name, linkfile)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"pulp==2.3.1",
"scipy>=1.7",
"seaborn>=0.13.2",
"snakemake>=7.15.2,<8.0",
"snakemake>=8",
"termgraph>=0.5",
"tqdm>=4.0",
],
Expand Down