CBIO7501 · Lesson 10 (40-minute introduction)
Snakemake: pull
“I want results/vcf/X.vcf. Which rules make it, from what?”
Files connect rules.
Nextflow: push
“Here are three samples. Send each through these steps.”
Channels connect processes.
process ALIGN {
tag "${sample}"
cpus 4
input:
tuple val(sample), path(reads)
tuple path(genome), path(index)
val bwa_extra
output:
tuple val(sample),
path("${sample}.aligned.sorted.bam"),
path("${sample}.aligned.sorted.bam.bai")
script:
"""
bwa mem -t ${task.cpus} ${bwa_extra} ...
samtools sort ...
"""
}cpus, memory, tag; also conda or container for per-process softwareworkflow {
main:
ch_samples = channel.fromPath(params.samples)
.splitCsv(header: true, sep: '\t')
.map { row -> tuple(row.sample, [file(row.fastq_1), file(row.fastq_2)]) }
ch_fastqc = FASTQC(ch_samples)
ch_multiqc = MULTIQC(ch_fastqc.zip.collect()) // wait for all, then one task
ch_bam = ALIGN(ch_samples, PREPARE_REFERENCE(params.reference_gz), params.bwa_extra)
...
publish:
final_variants = ch_final // copied to results/nextflow/vcf
}Processes are called like functions; their outputs are channels for the next.
work/3f/9a2c1.../ .command.sh .command.err SRR2584866_variants.vcf → (link)
work/b7/02d4e.../ ...
-resume: only changed tasks rerunSRR2584863_final_variants.vcf: identical (25 variants)
SRR2584866_final_variants.vcf: identical (775 variants)
SRR2589044_final_variants.vcf: identical (10 variants)
| Command | Does |
|---|---|
nextflow run main.nf |
run the workflow |
nextflow run main.nf -resume |
reuse cached tasks, rerun only what changed |
nextflow run main.nf -params-file config/config.yaml |
settings from a file (we share Snakemake’s) |
nextflow run main.nf --min_depth 10 |
change one parameter |
nextflow run main.nf -profile slurm |
a profile from nextflow.config, e.g. for a cluster |
nextflow run main.nf -with-docker |
run each process in a container |
| Snakemake | Nextflow | |
|---|---|---|
| language | Python | Nextflow (Groovy-based) |
| connects steps by | file names (“pull”) | channels (“push”) |
| data | files | files and values |
| runs jobs in | the project folder | one folder per task, in work/ |
| plan before running | -n lists every job and why |
-preview checks the script only |
Which is best? Both work: on our pipeline they give identical results. Pick the one your field and your collaborators use.
nextflow run nf-core/demo -r 1.2.0 -profile test,docker3 minutes. For your own project: Pixi tasks only, Snakemake, Nextflow, or an nf-core pipeline? Why?
-resume do? (a) restart from scratch (b) reuse cached tasks, rerun only what changed (c) resume a paused laptopworkflow/nextflow/ and get “does not exist”. Why? (a) Nextflow bug (b) relative paths are resolved from the launch folderwork/; -resume reuses themText and slides CC BY 4.0 unless marked otherwise. Full list: Sources and credits.
CBIO7501: The Art of Reproducible Research - CC BY 4.0