Chapter 3: Processes, Directives & Script Blocks
Tested Stacks:
GATK 4.6.1
Samtools 1.21
Nextflow 24.10
Seurat v5.1
Python 3.12
Prerequisites: Basic Linux CLI & Sequencing Formats
📚 Chapter 3 of 13
0% Course Completed
Chapter 3: Processes, Directives & Script Blocks
A Process is the fundamental unit of execution in Nextflow. Each process runs in its own isolated temporary working directory (e.g. work/ab/c123.../), executing command-line scripts inside specified environments or containers.
The Four Main Blocks of a Nextflow Process
directives: Configuration properties controlling CPUs, memory, execution tags, and output saving.input:: Defines channel data consumed by the process.output:: Defines files and values emitted back into channels.script:(orshell:): The raw bash, Python, or R script executed by the system.
1. Complete Anatomy of a Production Process
process FASTQC {
tag "FastQC on ${sample_id}"
label 'process_low'
publishDir "results/fastqc", mode: 'copy', overwrite: true
cpus 4
memory '8 GB'
time '2h'
container 'quay.io/biocontainers/fastqc:0.12.1--hdfd78af_0'
input:
tuple val(sample_id), path(reads)
output:
tuple val(sample_id), path("*.html"), emit: html
tuple val(sample_id), path("*.zip") , emit: zip
path "versions.yml" , emit: versions
when:
task.ext.when == null || task.ext.when
script:
"""
fastqc --threads ${task.cpus} --quiet ${reads}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
fastqc: \$(fastqc --version | sed -e "s/FastQC v//g")
END_VERSIONS
"""
}2. Critical Directives Explained
publishDir: By default, Nextflow saves task outputs in isolatedwork/scratch directories.publishDircreates symlinks or copies final deliverables into an organized results folder.tag: Displays clean human-readable identifiers in the Nextflow console terminal logs.emit:: Labels output channels with explicit names, enabling clean referencing in workflows (e.g.FASTQC.out.html).
3. Script vs. Shell Blocks (Bash Variable Escaping)
In standard script: blocks, Nextflow interpolates variables starting with $ as Nextflow variables. To reference an underlying Bash variable, you must escape it with a backslash (\${BASH_VAR}). Alternatively, use the shell: block with !{nextflow_var} syntax to preserve raw Bash syntax untouched.
⚠️
Common Pitfalls & Troubleshooting Checklist
- Java Heap Exhaustion (GATK / Picard): If processes terminate with
java.lang.OutOfMemoryError, set your environment variable explicitly:export _JAVA_OPTIONS="-Xmx16g -Djava.io.tmpdir=/tmp". - Index Timestamp Mismatch: If tools complain that a BAM index is missing or out of date, regenerate with
samtools index -@ 4 sample.bam. - Conda Channel Conflicts: Avoid ABI incompatibilities between bioconda and conda-forge by setting strict priority:
conda config --set channel_priority strict. - Chromosome Naming Contamination: Always verify whether reference FASTA headers use
chr1or1; divergent naming causes silent alignment drops.
Was this guide helpful to your research?
Help us maintain 100% accurate, peer-reviewed bioinformatics standards.