def load_snakemake_params(): global is_snakemake_child if PARAMETER_PASSING_ENVVAR not in os.environ: return is_snakemake_child = lambda: True import json, collections from snakemake.io import Namedlist import builtins options = json.load(open(os.environ[PARAMETER_PASSING_ENVVAR])) # Unset the parameter file var not to pass to children. del os.environ[PARAMETER_PASSING_ENVVAR] for varname, value in options.items(): if not isinstance(value, int): nl = Namedlist() for k, v in value: nl.append(v) if k is not None: nl.add_name(k) value = nl setattr(builtins, varname, value)
def recursive_format(ruleinfo): """Expand wildcards within ruleinfo This is not fully implemented! At this time, only `input` and `output` are expanded within `params`. """ args = {} for name in ['input', 'output']: attr = getattr(ruleinfo, name) if attr is None: continue nlist = Namedlist() for item in flatten(attr[0]): nlist.append(item) for key, item in attr[1].items(): nlist.append(item) nlist.add_name(key) args[name] = nlist for key, value in ruleinfo.params[1].items(): if not isinstance(value, str): continue value = partial_format(value, **args) ruleinfo.params[1][key] = value