Reputation: 11
I am trying to use snakemake to copy a file to multiple directories, and I need to be able to use a wildcard for part of the name of the target. Previously I had tried this with 'dirs' specified in the Snakefile (this is an example, the actual application has 15 directories).
dirs=['k_1','k2_10']
rule all:
input:
expand("{f}/practice_phased_reversed.vcf",f=dirs)
rule r1:
input:
"practice_phased_reversed.vcf"
output:
"{f}/{input}"
shell:
"cp {input} {output}"
This copies the file as desired. However the filename must be given in rule all. How can I change this so that I can specify a target on the command line using a wildcard for part of the name?
I then tried this (below), with the command "snakemake practice_phased_reversed.vcf", but it gave an error : "MissingRuleException: No rule to produce practice_phased_reversed.vcf"
dirs=['k_1','k2_10']
rule all:
input:
expand("{f}/{{base}}_phased_reversed.vcf",f=dirs)
rule r1:
input:
"{base}_phased_reversed.vcf"
output:
"{f}/{input}"
shell:
"cp {input} {output}"
Is there a way to fix this so I can use the command line and a wildcard. Thanks for any help.
Upvotes: 0
Views: 213
Reputation: 2079
I'd suggest a few changes. Your second snakefile won't be able to resolve the rule all since it still includes a wildcard base
. You would need to provide that in the config file or via command line.
However, if you just want to express targets by the command line, you don't need to worry about the rule all. In rule r1, you probably want to expand output; I don't think referencing input
works and I'm surprised it's not an error...
So:
rule r1:
input:
"{base}_phased_reversed.vcf"
output:
"{f}/{base}_phased_reversed.vcf"
shell:
"cp {input} {output}"
snakemake ./test_phased_reversed.vcf
will still be an error because it's trying to make a file as the input and output of the same rule. I agree the error isn't very informative as the input file does exist. Maybe under the hood snakemake eliminates rule r1 from consideration due to the matching inputs/outputs? snakemake test/test_phased_reversed.vcf
gives a copy in the subdirectory.
Hope that's clear. I don't quite get what you're trying to accomplish though!
Upvotes: 1