Newer
Older

Malte Nyhuis
committed
from snakemake.utils import validate
from snakemake.utils import Paramspace
import pandas as pd
from ntrfc.database.case_templates.case_templates import CASE_TEMPLATES

Malte Nyhuis
committed
configfile : "casesettings.yaml"
TEMPLATE = CASE_TEMPLATES[config["case_params"]["case_type"]]
PARAMS = pd.read_csv("caseparams.tsv",sep="\t")
def validate_configuration(config):
validate(config,"config.schema.yaml")
# todo: the next line is not working. currently TEMPLATE.schema does not have the right format
validate(PARAMS, TEMPLATE.schema)
paramspace = Paramspace(PARAMS)
return paramspace, config
paramspace, config = validate_configuration(config)

Malte Nyhuis
committed
rule all:
input:
# Aggregate over entire parameter space (or a subset thereof if needed)
# of course, something like this can happen anywhere in the workflow (not
# only at the end).
*[f"01_Simulations/{instance_pattern}/{file}" for instance_pattern in paramspace.instance_patterns for file in TEMPLATE.files]

Malte Nyhuis
committed
[f"{TEMPLATE.path}/{file}" for file in TEMPLATE.files]

Malte Nyhuis
committed
output:
# format a wildcard pattern like "alpha~{alpha}/beta~{beta}/gamma~{gamma}"
# into a file path, with alpha, beta, gamma being the columns of the data frame
*[f"01_Simulations/{paramspace.wildcard_pattern}/{file}" for file in TEMPLATE.files]

Malte Nyhuis
committed
params:
case_type = config["case_params"]["case_type"],
# automatically translate the wildcard values into an instance of the param space
# in the form of a dict (here: {"alpha": ..., "beta": ..., "gamma": ...})
simparams = paramspace.instance

Malte Nyhuis
committed
run:
from ntrfc.preprocessing.case_creation.create_case import create_case
from ntrfc.utils.dictionaries.dict_utils import merge
print(params["simparams"])
print(config["case_options"])
simconfig = merge(params["simparams"],config["case_options"])
create_case(input,output,params["case_type"],simconfig)