-
Notifications
You must be signed in to change notification settings - Fork 1
Snakemake version 8+ support #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
||
|
|
@@ -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()), | ||
| thresh_static=args.static, | ||
| thresh_dynamic=args.dynamic, | ||
| thresh_file=args.config, | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
|
|
||
| def validate_panel_config(markerseqs, markerdefn): | ||
| print("[MicroHapulator] validating panel configuration", file=sys.stderr) | ||
| index = MicrohapIndex.from_files(markerdefn, markerseqs) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| shell: | ||
| "mhpl8r filter {input} --out {output} {params.static} {params.dynamic} {params.threshfile}" | ||
|
|
||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another reinstated f-string. |
||
| symlink(outfile.name, linkfile) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
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. 🤷♂️