Skip to content

Commit

Permalink
enable configfile for mock_snakemake
Browse files Browse the repository at this point in the history
  • Loading branch information
yerbol-akhmetov committed Oct 9, 2024
1 parent b64623d commit d9ee113
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def get_aggregation_strategies(aggregation_strategies):
return bus_strategies, generator_strategies


def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
def mock_snakemake(rulename, root_dir=None, submodule_dir=None, configfile=None, **wildcards):
"""
This function is expected to be executed from the "scripts"-directory of "
the snakemake project. It returns a snakemake.script.Snakemake object,
Expand All @@ -534,6 +534,8 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
----------
rulename: str
name of the rule for which the snakemake object should be generated
configfile: str
path to config file to be used in mock_snakemake
wildcards:
keyword arguments fixing the wildcards. Only necessary if wildcards are
needed.
Expand Down Expand Up @@ -566,9 +568,17 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
if os.path.exists(p):
snakefile = p
break

if isinstance(configfile, str):
with open(configfile, 'r') as file:
configfile = yaml.safe_load(file)
else:
configfile = None

workflow = sm.Workflow(
snakefile, overwrite_configfiles=[], rerun_triggers=[]
) # overwrite_config=config
snakefile, overwrite_configfiles=[], rerun_triggers=[],
overwrite_config=configfile
)
workflow.include(snakefile)
workflow.global_resources = {}
try:
Expand Down

0 comments on commit d9ee113

Please sign in to comment.