Using modules in Snakemake

Viewed 139

I have a Snakefile which I want to use rules from another Snakefile as a module. The problem is, the first rule doesn't get it's input modified and Snakemake throws a MissingInputException

Here's my master Snakefile:

from snakemake.utils import min_version
min_version("6.0")

container: "docker://condaforge/mambaforge:4.12.0-0"
pepfile: "pep/config.yaml"
include: "modules/import/Snakefile"

module velocity:
    snakefile: "modules/velocity/Snakefile"


use rule * from velocity as velocity_*

use rule preprocessing from velocity as velocity_preprocessing with:
    input:
        filtered = "results/preprocessing/{pat}.h5ad"

And everything runs correctly when the module Snakefile looks like this:

rule preprocessing:
    input:
        filtered = "results/preprocessing/{pat}.h5ad"
    output:
        processed = "results/velocity/processed/{pat}.h5ad"
    conda: "envs/velocity.yml"
    script: "python/velocity_preprocessing.py"

but not when the input is set to filtered = "in" where I get the following Exception:

Building DAG of jobs...
MissingInputException in line 1 of [My Directory]/workflow/modules/velocity/Snakefile:
Missing input files for rule velocity_preprocessing:
    output: results/velocity/processed/PAWAMB.h5ad
    wildcards: pat=PAWAMB
    affected files:
        in

even when the use rule ... from ... as ... with: chunk is present. Am I doing something wrong? I would expect both to build the same DAG.

2 Answers

By setting filtered = "in", Snakemake expects a file named "in" to be present in the directory from which the Snakemake is executed. Is this the expected behaviour for your workflow?

When you run use rule * from velocity as velocity_*, it imports and defines the rules. The later call use rule preprocessing from velocity as velocity_preprocessing with: also imports and defines the rules, but it comes later in the Snakefile.

One recommendation is to change/remove the line:

use rule * from velocity as velocity_*
Related