Entering edit mode
4.7 years ago
mrmrwinter
▴
30
Hi
im currently trying to write an if loop to use in a snakemake rule
The code for the rule is as follows:
rule empty_fasta_workaround:
input:
"results/02_trimmed/{library}/{sample}.merged.tmp.derep.fasta"
output:
denoise = "results/02_trimmed/{library}/{sample}.merged.derep.fasta",
rerep = "results/rereplicated/{library}/{sample}.fasta"
priority:
50
run:
"""
if [wc -l {input}] -gt 0
then
mv {input} {output.denoise}
else
mv {input} {output.rerep}
fi
"""
Some files in results/02_trimmed/{library}/{sample}.merged.tmp.derep.fasta
are empty.
I want this loop to count lines in these files and move files with >0 lines to output denoise
and files with no lines to output rerep
.
The second issue is that another rule also has the output results/rereplicated/{library}/{sample}.fasta
This is throwing an error for Ambiguity.
Can i fix this with RuleOrder or RuleDependencies?
Or some other way?
Many thanks
Sounds like you want a "checkpoint".
To help the OP: https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution
Great, thank you both
On a related note, calling an if statement a "loop" is a pet peeve of mine. It's a conditional statement, not a loop. Loops run the same piece of code multiple times, conditional statements execute a particular block of code based on a condition.
Ok, thanks. Still new to the terminology
for second issue, just the change the name of the rule
Hi, this doesnt work; the rules already have different names
The problem is that the outputs of two rules are the same wildcard/file,
results/rereplicated/{library}/{sample}.fasta
, and this raises an ambiguity errorThink about it, even if you don't use snakemake you can not have two files with the same filename in the same folder...
Maybe im not explaining it well enough.
"the outputs of two rules are the same wildcard/file, results/rereplicated/{library}/{sample}.fasta, and this raises an ambiguity error"
It is not trying to have two files with the same filename in the same folder, the wildcards will be different.
Ie,
results/rereplicated/{library}/{sample}.fasta
becomes
results/rereplicated/lib1/sample1.fasta
from output of rule Aresults/rereplicated/lib1/sample2.fasta
from output of rule BThe problem is that snakemake wont let me have two outputs of different rules the same. It's not complaining about trying to make the same file twice.
As above, checkpoints are probably the way forward