How to reference the output of a rule in snakemake

Viewed 168

I was wondering if it is possible to use the output of a rule directly as the input of the next rule, without having to specify the path again.

I thought maybe something like this would work, but it does not in my tests:

rule A:
    input:
         in_file = "path/to/in_file"

    output:
          out_file = "path/to/out_file"
    shell:
       "...."

rule B:
    input:
         in_file = A.output.out_file # reference the output of rule A doesnt work like this
         # in_file = "path/to/out_file" -> this works but is less elegant i think

    output:
          out_file = "path/to/out_file"
    shell:
       "...."

Any help or insights are appreciated!

Cheers!

1 Answers

Maybe this is the syntax you are looking for:

rule B:
    input:
         in_file = rules.A.output.out_file,
    ...

Although I prefer to hardcode the filenames since it makes the script more readable.

Related