Carlo Ponzi
Carlo Ponzi

Reputation: 13

How to write a Snakemake rule with no output?

My Snakefile has a print_to_screen rule with no explicit output file. The following is a simplified example:

rule all:
    placeholder_output  # What should I put here?

rule create_file:
    output:
        "file.txt"
    shell:
        "echo Hello World! > {output}"

rule print_to_screen:   # This rule has no output
    input:
        "file.txt"
    shell:
        "cat {input}"

How can I write the print_to_screen rule so that it triggers other rules, meaning that:

Upvotes: 1

Views: 897

Answers (1)

Dmitry Kuzminov
Dmitry Kuzminov

Reputation: 6584

The output section of the rule is optional, but you need to make it the first rule (define it the first in your Snakefile) to take any effect:

rule print_to_screen:
    input:
        "file.txt"
    shell:
        "cat {input}"

rule create_file:
    output:
        "file.txt"
    shell:
        "echo Hello World! > {output}"

If you need some flexibility (for example you have several rules like that) you should use flags.

Upvotes: 1

Related Questions