Search code examples
snakemake

How to use include directives with specific config files in snakemake?


How can we define specific config files for includes in snakemake workflows?

I have a pipeline with the following structure.

The main entrypoint of the pipeline:

workflow/Snakefile

Other smk files:

workflow/rules/Snakefile_0.smk
workflow/rules/Snakefile_1.smk
workflow/rules/Snakefile_2.smk

Inside Snakefile, I include them using

include: "rules/Snakefile_0.smk"
include: "rules/Snakefile_1.smk"
include: "rules/Snakefile_2.smk"

I access and use the config file within these smk files, too. How can I specify config files for each smk file I include?


Solution

  • Snakemake does not support different configfiles for different rules or rule files if they are within the same main Snakefile. All rules of the include: *.smk files have access to the same configfile and config dict.

    If you want to use different config-files for each .smk file, you can use the following workaround: Instead of using the include directive, import the rules of the .smk files as module. You can specify a different configfile for each module imported.