I am working with Snakemake and I can't find a way to access to the current-rule's name.
For instance, is there a way to have an access like this:
rule job1:
input: check_inputs(rules.current.name)
output: ...
This can be very helpful when the check_inputs
function is more or less the same for each rules.
For sure, I made this and it works:
rule job1:
input: check_inputs("job1")
output: ...
However, I was wondering that if a more "Snakemaker way" to get the current-rule's name exists to avoid writing / hardcoding the rule's name each time.
Any kind of help or suggestion will be highly appreciated.
--- EDIT1 ---
The rule name is accessible via {rules.myrule.name}
only when the input
and output
statements are parsed by snakemake. So the use of {rules.myrule.name}
is not possible in input
/output
definition.
The idea is to have a quick access to the current rule's name {rules.current}
for instance, because {rules.myrule.name}
is also repetitive.
-R selects the one rule (and all its dependent rules also!), -n does a "dry run", it just prints what it would do without -n.
Snakefiles are Python code. Completing the Pipeline. Resources and parallelism. Make your workflow portable and reduce duplication. Scaling a pipeline across a cluster.
(Edit: Proposed a workaround)
{rule}
can be used for rulename during shell:/run: directives. As op stated, this does not work in input/output:
. However the current template is a work-araound
myrule = "foo"
rule foo:
output: touch(myrule + ".ok")
shell:
'echo "I am {rule}, making {output}"'
In the example above, introducing the variable myrule
is unnecessary since it is used only once. But it makes more sense when you want to use the rule-name several times in the various snakemake directives. And it also facilitates rule-templating.
I thought rule.name
should work, but it looks like it's just rule
, which however can't be used in all contexts: See https://bitbucket.org/snakemake/snakemake/issues/199/rule-name-cant-be-accessed-by-rule-in
Andreas
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With