I am wondering if it is possible to combine both helper functions and wildcards using snakemake's expand().
This is not what I want, but it works:
report = lambda wildcards: expand("{sample_directory}/{sample}.A.report.html", zip, sample_directory=config["sample_directory"], sample=config["sample"])
This works with the helper function zip()
to tie the {sample_directory}
and {sample}
together into something like this:
sample_1/sample_1.A.report.html
Here's the issue: I want to keep {sample_directory}
and {sample}
zipped together for this output, but the letter A (hardcoded above) should actually be a wildcard itself like so:
report = lambda wildcards: expand("{sample_directory}/{sample}.{ABCDE}.report.html", zip, sample_directory=config["sample_directory"], sample=config["sample"])
Where an example of outputs would be:
- sample_1/sample_1.A.report.html
- sample_1/sample_1.B.report.html
- sample_1/sample_1.C.report.html ...
Can expand()
do something like this where there are some wildcards with a function applied and others without in the same expand()? I have tried masking the {ABCDE} wildcard like so {{ABCDE}}, but it doesn't work...
lambda wildcards are for lookups, like when you have a dictionary and need to use a function to get the value. Where is your lookup function?
I agree with Jeremy that your question lacks context. You should provide at least the full rule in which the statement is to appear, including input and output. Otherwise, if you have single scalar values, you can just use python string concatenation with '+'. Also, in the beginning, one tends to overcomplicate things. More often than not there is an easier way than using lambda functions and simple problems should be rather addressed with rule logic.
Not totally sure I'm right about your use case (are those config entries lists of strings, which is why you need to zip them?) but, you can nest multiple calls to
expand
, and if you combine that with doubled-up braces in the string andzip
in one of the two calls, I think it could do what you're looking for.