I have two snakemake rules one for tool-a and another for tool-b. Each time I specify which tool I need to run in my config.yml before executing snakemake. For this, I defined a conditional loop in snakefile. However, while executing the snakefile it is ignoring this condition.
For example here are my tool.smk looks like: saved as in rules (rules/tools.smk)
rule tool-a:
input:
counts=config['general']['paths']["count_matrix"]
output:
os.path.join(config['general']['paths']['outdir'], 'diff','tool-a', 'tool-a.tsv')
params:
result_dir=os.path.join(config['general']['paths']['outdir'], 'diff','tool-a')
shell:
"""
mkdir -p {params.result_dir}
Rscript {GENE_TEST_DIFF_SCRIPT} {input.counts} {params.result_dir}
"""
rule tool-b:
input:
counts=config['general']['paths']["count_matrix"]
output:
os.path.join(config['general']['paths']['outdir'], 'diff','tool-b', 'tool-b.tsv')
params:
result_dir=os.path.join(config['general']['paths']['outdir'], 'diff','tool-b')
shell:
"""
mkdir -p {params.result_dir}
Rscript {GENE_TEST_DIFF_SCRIPT} {input.counts}
"""
in snakefile it looks like this,
import pandas as pd
from snakemake.utils import min_version
import itertools
### set min snakemake requirement
min_version("5.4.1")
### load config
configfile: "config.yaml"
### load sample data
DIFF_METH = config['general']['method']
Tool_a = config['general']['paths']['tool_a-script']
Tool_b = config['general']['paths']['tool_b-script']
if DIFF_METH == "tool-a":
GENE_TEST_DIFF_SCRIPT = Tool_a
elif DIFF_METH == "tool-b":
GENE_TEST_DIFF_SCRIPT = Tool_b
else:
sys.exit("Invalid value for 'method', possible choices are: 'tool-a' and 'tool-b'")
onstart:
sys.stderr.write("GENE_DIFF_METH = " + GENE_DIFF_METH + "\n")
return []
### define rules not to be executed on the cluster
localrules: all
### define target rules
rule all:
input:
expand(os.path.join(config['general']['paths']['outdir'], 'diff','tool-a','tool-a.tsv')),
expand(os.path.join(config['general']['paths']['outdir'], 'diff','tool-b','tool-b.tsv'))
include: "rules/tools.smk"
And the config.yaml file looks like:
general:
gene_diff_method: 'tool-b'
tool_a-script: '/home/script/tool_a.R'
tool_b-script: '/home/script/tool_b.R'
However, if I definetool-b in yml it starts with the rule for tool-a and runs everything again, even though there are results in the result folder. For some reason, snakemake is ignoring my if the condition defined in snakefile. Any suggestions would be appreciated.
Aucun commentaire:
Enregistrer un commentaire