1818from os import cpu_count , symlink
1919from pathlib import Path
2020from shutil import copy
21- from snakemake import snakemake
21+ from snakemake .api import SnakemakeApi as smk_api
22+ from snakemake .exceptions import WorkflowError
23+ from snakemake .settings import types as smk_types
2224import sys
2325
2426
@@ -29,10 +31,10 @@ def main(args):
2931 config = dict (
3032 samples = samples ,
3133 readfiles = workingfiles ,
32- mhrefr = Path (args .markerrefr ).resolve (),
33- mhdefn = Path (args .markerdefn ).resolve (),
34- hg38path = Path (args .hg38 ).resolve (),
35- hg38index = Path (args .hg38idx ).resolve (),
34+ mhrefr = str ( Path (args .markerrefr ).resolve () ),
35+ mhdefn = str ( Path (args .markerdefn ).resolve () ),
36+ hg38path = str ( Path (args .hg38 ).resolve () ),
37+ hg38index = str ( Path (args .hg38idx ).resolve () ),
3638 thresh_static = args .static ,
3739 thresh_dynamic = args .dynamic ,
3840 thresh_file = args .config ,
@@ -43,19 +45,28 @@ def main(args):
4345 thresh_gap_alert = args .gap_alert ,
4446 hspace = args .hspace ,
4547 )
46- snakefile = files ("microhapulator" ) / "workflows" / "analysis.smk"
47- success = snakemake (
48- snakefile ,
49- cores = args .threads ,
50- printshellcmds = True ,
51- dryrun = args .dryrun ,
52- config = config ,
53- workdir = args .workdir ,
54- )
55- if not success :
48+ try :
49+ run_snakemake (config , args .workdir , cores = args .threads , dryrun = args .dryrun )
50+ return 0
51+ except WorkflowError :
5652 return 1
5753
5854
55+ def run_snakemake (config , workdir , cores = 1 , dryrun = False ):
56+ outcfg = smk_types .OutputSettings (printshellcmds = True )
57+ with smk_api (outcfg ) as smk :
58+ workflow = smk .workflow (
59+ config_settings = smk_types .ConfigSettings (config = config ),
60+ storage_settings = smk_types .StorageSettings (),
61+ resource_settings = smk_types .ResourceSettings (cores = cores ),
62+ snakefile = files ("microhapulator" ) / "workflows" / "analysis.smk" ,
63+ workdir = Path (workdir ),
64+ )
65+ dag = workflow .dag (smk_types .DAGSettings (targets = ["report" ]))
66+ mode = "dryrun" if dryrun else "local"
67+ dag .execute_workflow (executor = mode )
68+
69+
5970def validate_panel_config (markerseqs , markerdefn ):
6071 print ("[MicroHapulator] validating panel configuration" , file = sys .stderr )
6172 index = MicrohapIndex .from_files (markerdefn , markerseqs )
0 commit comments