This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can I execute a snakemake rule only once?

Hello fellas,

I hope everyone is doing good!

I have another snakemake question.

I am trying to incorporate tools like kraken2 and GTDB-TK in my pipeline. The issue with these two is that before they actually perform the analysis they have to download/build a database.

So what I was thinking of creating a rule to run the downloading/building database separately from the kraken2/GTDB-TK analysis and, more importantly, only once.

Is that possible? Can I create a rule that will be executed only once in my pipeline? If yes, how can I do this?

Thanking you in advance.

snakemake gtdb-tk kraken2

1 answer

Sure you can. A rule that only creates one output file will run only once. You don't have to specify it in any special way. For example:

rule download_kraken_db:
    output: "kraken.db"
    shell: "kraken download -o kraken.db"

rule run_kraken:
    input:
        db="kraken.db",
        fq="{sample}.fq"
    output: "{sample}_clean.fq"
    shell: "kraken run {input.db} {input.fq} > {output}"

No matter how many times the rule run_kraken needs to run, download_kraken_db will still run only once.

Hello there!

Your reply worked!

Thank you very much

Log in to answer this question.