Reputation:
Here is a short example from the advanced section of snakemake tutorial:
rule bwa_map:
input:
"data/genome.fa",
lambda wildcards: config["samples"][wildcards.sample]
output:
"mapped_reads/{sample}.bam"
threads: 8
shell:
"bwa mem -t {threads} {input} | samtools view -Sb - > {output}"
Now lets say that I wrote this rule months ago and I don't remember the output file name. My understanding is that I cannot run snakemake by invoking the rule name because this would lead to an error:
$ snakemake bwa_map
InputFunctionException in line 9 of Snakefile:
AttributeError: 'Wildcards' object has no attribute 'sample'
Wildcards:
$
First, I don't understand why snakemake cannot use the lambda function to deduce input files from the configuration file as it is quite clear that I refer to the "samples" section.
Second, is there a workaround to this? Because it is very easy to do with good old Makefile to just use an old Makefile and run the same bwa_map rule by typing something like
$ make bwa_map INPUT=data/samples/A.fastq
Thanks in advance for your help. Benoist
Upvotes: 4
Views: 2244
Reputation: 1947
If you specify a rule name as a target and that rule contains wildcards, Snakemake can't know what values to use for the wildcards. This can only be determined from a concrete output file in this case. This output file can come from a downstream rule, e.g. a real ´all´ target at the top of the Snakefile, or by providing it directly at the command line.
However if you have a proper target rule at the top of the Snakefile, there is the --until flag, which allows you to execute your workflow only until a given rule.
Regarding your make example, I am not aware of this functionality. Can you point me to the docs about this? I might add something similar to Snakemake as well.
Please also note that I just improved the error message for this case in the development version of Snakemake. It is now more informative and explains the issue.
Upvotes: 1