If the expression has attempt snakemake will evaluate it.
https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#dynamic-resources
Hey everyone,
I am looking for a way to set dynamic resources without having access to the rules itself. This workflow uses snakedeploy. So you only have the main and pretty simple Snakefile locally, but the other rules get downloaded on the fly from the GitHub repo.
I often set my resources dynamically with funtions like this:
def bwa_mem_mem(wildcards, attempt):
possibilities = [16384, 32768, 65536, 131072, 262144, 524288]
return possibilities[attempt - 1]
However, with the snakedeploy routine, I don't have direct access to the rules, but I assign the resources using a workflow-profile, which is a YAML file.
...
set-resources:
bwa_mem:
mem: 16384
...
Does anyone know, how I can define a function within a workflow profile, so I don't have to clone or fork the whole repo to change the rules itself?
That might also work, but I prefer it less "hard coded". However, it seems you can simply quote the functions and they are still evaluated by Snakemake. This did work and also set the correct resources:
mem_mb: "(lambda x: x[min(attempt - 1, len(x) - 1)])([44000, 66000])"
If the expression has attempt snakemake will evaluate it.
https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#dynamic-resources
Log in to answer this question.
Seems like I can just to
Sorry, haven't thought of that (or didn't know).
The following will prevent index errors after 6 retries, limiting max memory to
524288for further attempts.Do you need the quotes here?
No, it was a formatting issue.
I tried a lambda function but this didn't work:
This failed, because it couldn't be parsed. I guess due to the ":". Any ideas about that?
EDIT: Also this didn't work:
due to this
EDIT2: Even this didn't work:
due to the same error:
The following expression should compute the memory limit for the respective attempt.
The
:works as a key value separator in a YAML file, and the parser will fail. Check the following doc for more details:https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#snakefiles-dynamic-resources
Yes, but that's just an example. This time I want 44000MB in the first and 66000MB in the second attempt. That's just easier to accomplish with list indexing. I also tried escaping the : and [] with backslashes, but that didn't help, right now I try quotes, but I fear these will be fowarded as string and not as function to snakemake, but let's see.
Can you try this in the workflow profile?