CBIO7501 · Lesson 09
As a project grows, or just ages, it gets hard to remember which step made which file, from what, with which settings.
A workflow manager keeps track for you, and lets you scale up in complexity (more steps) and in size (more samples).
Figure: NBIS, Tools for Reproducible Research, CC BY 4.0
Figure: NBIS, Tools for Reproducible Research, CC BY 4.0
Most used
Also around
From the Snakemake documentation:
A Snakemake workflow is defined by specifying rules in a Snakefile.
Rules decompose the workflow into small steps.
Snakemake automatically determines the dependencies between the rules by matching file names.
Ask for results/vcf/SRR2584866_final_variants.vcf: Snakemake finds the rules whose outputs match, all the way back to the raw reads.
all:rule bwa_mem:
input:
genome=GENOME,
index=rules.bwa_index.output,
r1=lambda wc: SAMPLES[wc.sample]["fastq_1"],
r2=lambda wc: SAMPLES[wc.sample]["fastq_2"],
output:
temp("results/sam/{sample}.aligned.sam"),
log:
"results/logs/bwa_mem/{sample}.log",
threads: 4
params:
extra=config["bwa_extra"] or "",
shell:
"bwa mem -t {threads} {params.extra} "
"{input.genome} {input.r1} {input.r2} "
"> {output} 2> {log}"{sample} wildcardtemp(): deleted once no longer neededresources:: what a job may useWe run every rule in one Pixi environment. Snakemake can also give each rule its own:
Useful when two tools cannot share one environment.
| Trigger | Example |
|---|---|
| output missing | you deleted results/vcf/ |
| input newer than output (mtime) | new FASTQ |
params changed |
min_depth: 2 → 10 in the config |
rule code changed |
edited the shell: command |
| software environment changed | (per-rule conda:/container:) |
snakemake -n shows the plan and the reason for every job.
| Command | Does |
|---|---|
snakemake -n -p |
dry run: the plan, with the shell commands |
snakemake -c 4 |
run, with up to 4 cores |
snakemake -c 4 results/vcf/SRR2584866_final_variants.vcf |
build one target only |
snakemake --configfile other.yaml -c 4 |
another settings file |
snakemake --rulegraph |
the graph of rules, for Graphviz |
In this course, prefix them with pixi run -e pipeline.
3 minutes. You change min_depth from 2 to 10. Which of the 40 jobs will Snakemake rerun? Which would the shell script rerun?
bwa mem with 4 threads and no -K: 4 records differ for one sampleReproducible ≠ automatic: know your tools’ sources of variation.
snakemake -n do? (a) runs with n cores (b) shows the plan without running (c) deletes outputsconfig/config.yaml (c) in the sample sheet-n shows why)pixi run snakemakeNow: tutorial 09.
snakemake --rulegraph, drawn left to right), CC BY 4.0.Text and slides CC BY 4.0 unless marked otherwise. Full list: Sources and credits.
CBIO7501: The Art of Reproducible Research - CC BY 4.0