Is it possible to access a snakemake wildcards outside of a rule ?
Is it possible to access a snakemake wildcards outside of a rule ?
The wildcard is a variable that has a meaning inside of a rule only. This allows the rule to be generic, and the actual value of the wildcard is being assigned when the rule is executed.
In your code you are trying to use wildcard outside of any rule. You don't need any wildcard there:
if samples_dict.loc[wildcards.sample]['Sequencing_type'] == "SE":
rule test_SE :
input : '{sample}.txt'
output : '{sample}_done.txt'
conda :
'test.yaml'
shell :
"somecommand -i {input} -o {output} ;"
elif samples_dict.loc[wildcards.sample]['Sequencing_type'] == "PE":
rule test_PE :
input :
input1="input1",
input2="input2"
output :
output1="output1",
output2="output2"
conda :
'test.yaml'
shell :
"somecommand -i1 {input.input1} -i2 {input.input2} -o1 {output.output1} -o2 {output.output2} ;"
else:
rule test_fail :
output :
'{sample}.txt'
conda :
'test.yaml'
shell :
'echo "Use PE or SE in Sequencing_type column" > {output};'
This however opens another question: why do you even need to have these conditional rules? These rules produce different outputs, and should have no conflicts. Try to remove all if/elif/else, as this is not an idiomatic way to use Snakemake.