Glossary · Reproducibility and Workflows
Snakemake
The workflow engine that turns a folder of one-off scripts into a DAG that only reruns what actually changed.
By Ming "Tommy" Tang, Director of Bioinformatics in Big Pharma · Reviewed September 2026 · 2 min read
Definition
Snakemake is a Python-based workflow management system that builds a directed acyclic graph (DAG) of jobs from a set of rules, where each rule declares the input files, output files, and shell or script command needed to turn one into the other. It infers execution order by matching filenames against the DAG, not by the order rules appear in the Snakefile, and it reruns a rule only when its output is missing or older than its input. Wildcards, variables written as {sample}, let one rule generalize across an arbitrary number of samples instead of duplicating the rule per file. The same Snakefile runs unmodified on a laptop or submits jobs to a cluster scheduler like SLURM or SGE.
You meet Snakemake the moment a bash for loop chaining FastQC, fastp, STAR, and featureCounts across 40 samples breaks halfway through, and you realize you can't safely rerun it without either redoing everything or hand-tracking which samples finished. That's the exact failure mode it's built to remove: instead of a script that executes top to bottom, you write rules that declare inputs, outputs, and the command that connects them, and Snakemake works backward from the file you actually want to figure out what needs to run.
This matters for a decision you'll make early in any project: hardcode a pipeline as a shell script, or invest an afternoon writing it as rules. The shell script is faster today. The Snakemake version is the one that still works when a collaborator reruns it on their cluster six months later, or when sample 43 of 96 fails and you need to fix just that one.
Why it matters
Get this right and a failed sample costs you minutes; get it wrong and it costs you the whole pipeline. A QC pipeline built to validate FASTQ files before alignment across 96 RNA-seq samples hit one sample with a truncated file from a failed sequencing run. Because the pipeline was written as Snakemake rules keyed on wildcards, fixing that one sample and rerunning snakemake only recomputed the steps downstream of it, not the other 95 already-finished samples. A bash script written as a flat sequence of commands has no such notion of "already done": you either rerun everything or hand-track completion state yourself, and at 96 samples that bookkeeping is where real analysis time disappears.
Where people get it wrong
New users write Snakemake rules like a linear script and expect them to execute in the order they appear in the Snakefile. They don't: Snakemake starts from the target output file you ask for (or the rule all inputs) and works backward, matching filenames to figure out which rule produces which file. This causes two specific failures. First, "ambiguous rule" errors when two rules can produce the same output pattern, because Snakemake genuinely doesn't know which one you meant. Second, false confidence that a rerun redid the analysis: if you edit the logic inside a rule's shell command but its input files haven't changed, Snakemake may see the existing output as still up to date and skip it, silently leaving stale results in place unless you explicitly force a rerun of that rule.
A concrete example
A minimal Snakefile that runs FastQC on every sample by matching the {sample} wildcard against files in fastq/, then a dry run followed by a real 4-core run.
# Snakefile
SAMPLES = ["sample1", "sample2", "sample3"]
rule all:
input:
expand("qc/{sample}_fastqc.html", sample=SAMPLES)
rule fastqc:
input:
"fastq/{sample}.fastq.gz"
output:
"qc/{sample}_fastqc.html"
threads: 2
shell:
"fastqc {input} -o qc/"
# Preview what would run, without running it
snakemake -n
# Actually run it on up to 4 cores
snakemake -j 4Related terms
Questions people ask
- What is Snakemake used for in bioinformatics?
It automates multi-step command-line pipelines, RNA-seq QC through quantification, ChIP-seq alignment through peak calling, by chaining tool outputs to inputs automatically. It's most valuable wherever you'd otherwise write a bash loop over dozens or hundreds of samples.
- Snakemake vs Nextflow: which should I use?
Snakemake's rule syntax is plain Python, so it's the more natural pick if you already write Python and want to move fast on a single-lab pipeline. Nextflow's Groovy DSL and native container/cloud-executor model has become the default for production pipelines meant to run across institutions, which is why most nf-core pipelines are Nextflow. Neither is objectively better; the choice tracks your team's language comfort and whether the pipeline needs to leave your cluster.
- How do I rerun only the failed steps in a Snakemake pipeline?
Just run
snakemakeagain with the same target. It checks which output files are missing or older than their inputs and reruns only those rules and their downstream dependents, leaving completed samples untouched.- Does Snakemake require a compute cluster?
No. The same Snakefile runs on a single laptop with
snakemake -j 4or submits to a scheduler like SLURM withsnakemake --jobs 10 --cluster "sbatch". You don't rewrite the workflow to scale it, you just change the execution flags.- What is a wildcard in Snakemake?
A wildcard is a placeholder in curly braces, like
{sample}, inside an input or output filename. It lets one rule apply to every sample by pattern-matching the requested output file, instead of you writing a separate rule per sample.
Related pages
Related reading on the blog
Sources
- Snakemake, a scalable bioinformatics workflow engine — DAG construction, scaling from workstation to cluster, and CPU scheduling as a 0/1-knapsack problem
- Snakemake Official Documentation — Current version, installation requirements, and rule/wildcard syntax
- Building Bioinformatics Pipelines with Snakemake, M. tuberculosis Workshop — Applied walkthrough of a real genomics pipeline built as Snakemake rules
- Snakemake Workflow Catalog — Source of pre-built, shareable Snakemake pipelines to start from instead of writing rules from scratch