Skip to content

What is Nextflow

Nextflow runs analysis steps and tracks the data that connects them. You define each step once, and Nextflow creates a task for each input item. An executor runs those tasks locally, on a cluster, or in the cloud.

The example below counts sequences in three small FASTA files and combines the counts into one table. It needs no sequencing software, reference genome, cloud account, or container image. The same process and channel syntax appears in the larger pipelines maintained by nf-core.

A typical RNA-seq analysis runs FastQC, trims adapters, aligns reads, quantifies transcripts, and merges counts. Thirty samples mean hundreds of commands. You can chain them in a bash script. Many people do. They break in predictable ways:

  • A step fails silently and the next step runs on corrupted input.
  • You cannot easily restart from a failed step without rerunning everything.
  • Scaling from 4 samples to 40 means rewriting your parallelisation logic.
  • Moving from your laptop to a cluster or cloud means rewriting how jobs are submitted.

Workflow managers solve these. They track dependencies, parallelise automatically, cache completed work, and separate analysis logic from execution environment.

In a shell script, command order usually determines execution order. In Nextflow, the connections between process inputs and outputs determine which tasks can start.

A process defines a command and its input and output requirements. A channel carries values or file paths between processes. A task is one execution of a process with a particular set of inputs.

If three files arrive on an input channel, a process with one file input creates three tasks. Those tasks can run independently. A downstream task starts when its own inputs are available, even if unrelated tasks are still active.

Task count and concurrent task count differ. Available resources, executor limits, and process settings determine how many tasks run at once.

Term What it is
Process One step of the pipeline. Has inputs, outputs, and a script block.
Channel A queue or stream of items flowing into or out of a process.
Workflow The block that wires processes and channels together.
Task One execution of a process with a set of inputs. One task can produce several files.
Work directory Where each task runs. One subdirectory per task.
Profile A named configuration bundle for a target environment (laptop, cluster, AWS).
Executor The backend that runs tasks. Local processes, SLURM, AWS Batch, etc.

This example uses Nextflow DSL2 and was checked with Nextflow 25.10.2 on Linux. It uses Bash, grep, cat, printf, and sort from the local environment. Current Nextflow releases require Java 17 or later within the supported range. See the installation documentation for your release.

Check the two executables before you continue. The installation section below explains how to obtain Nextflow.

Terminal window
java -version
nextflow -version

Create an empty directory for the example and enter it.

Terminal window
mkdir nextflow_example
cd nextflow_example

Save this script as create_inputs.sh, then run bash create_inputs.sh once. Each FASTA record begins with a header line that starts with >.

create_inputs.sh
mkdir -p data
cat > data/sample_a.fa <<'EOF'
>a_1
ACGT
>a_2
GGTT
EOF
cat > data/sample_b.fa <<'EOF'
>b_1
AAAA
>b_2
CCCC
>b_3
TTTT
EOF
cat > data/sample_c.fa <<'EOF'
>c_1
ACAC
EOF

The files contain two, three, and one sequences. These are invented inputs for the example, not experimental observations.

Save this complete pipeline as main.nf in the same directory.

main.nf
params.input = 'data/*.fa'
params.outdir = 'results'
process COUNT_SEQUENCES {
tag "${fasta.simpleName}"
input:
path fasta
output:
path "${fasta.simpleName}.count.tsv"
script:
"""
printf '%s\\t' '${fasta.simpleName}' > ${fasta.simpleName}.count.tsv
grep -c '^>' "${fasta}" >> ${fasta.simpleName}.count.tsv
"""
}
process SUMMARIZE {
publishDir params.outdir, mode: 'copy', overwrite: true
input:
path count_files
output:
path 'sequence_counts.tsv'
script:
"""
printf 'sample\\tsequences\\n' > sequence_counts.tsv
cat ${count_files} | LC_ALL=C sort >> sequence_counts.tsv
"""
}
workflow {
fasta_ch = channel.fromPath(params.input, checkIfExists: true)
COUNT_SEQUENCES(fasta_ch)
SUMMARIZE(COUNT_SEQUENCES.out.collect())
}

COUNT_SEQUENCES counts header lines in each input file. It writes one TSV row with the sample name and count. This command counts records; it does not validate FASTA syntax. An input without a header makes grep return an error, which stops the task.

SUMMARIZE receives the count files and writes a header followed by their rows. The sort makes row order independent of task completion order. The example uses unique filenames without spaces or shell metacharacters because it expands the file list into a shell command.

The script block is a string that Nextflow prepares before Bash executes it. Nextflow substitutes expressions such as ${fasta} with the task’s input filename. The doubled backslashes preserve \t and \n for printf, which writes tabs and newlines.

Run this command from the directory that contains main.nf and data/.

run_example.sh
nextflow run main.nf \
--input 'data/*.fa' \
--outdir results \
-with-trace trace.tsv

The quotes keep the shell from expanding data/*.fa before Nextflow receives it. Options with one dash, such as -with-trace, belong to Nextflow. Options with two dashes, such as --input, set pipeline parameters.

After the run completes, read the published table.

Terminal window
cat results/sequence_counts.tsv
sequence_counts.tsv
sample sequences
sample_a 2
sample_b 3
sample_c 1

The run creates three COUNT_SEQUENCES tasks and one SUMMARIZE task. The trace records all four tasks. Hashes and completion order vary between runs.

The connections in workflow define this dependency graph.

sample_a.fa -> COUNT_SEQUENCES -> sample_a.count.tsv --+
sample_b.fa -> COUNT_SEQUENCES -> sample_b.count.tsv --+-> collect()
sample_c.fa -> COUNT_SEQUENCES -> sample_c.count.tsv --+ |
v
SUMMARIZE
|
v
sequence_counts.tsv
  1. channel.fromPath emits a file path for each matching FASTA file. checkIfExists: true reports an error when the pattern matches nothing.
  2. COUNT_SEQUENCES accepts one path per task. Its tag puts the sample name in the task display.
  3. The task writes its declared output. Nextflow sends that file path through COUNT_SEQUENCES.out.
  4. collect() waits until the output channel closes. It emits one list containing all three count files.
  5. SUMMARIZE receives that list as one input and runs once.

Without collect(), SUMMARIZE(COUNT_SEQUENCES.out) would create one summary task per incoming count file. Each task would contain only one sample. Each would also publish the same filename, so the copies could overwrite each other.

collect() creates a deliberate synchronization point. Use it when a task needs the complete set of results, such as a combined report. A step that processes each sample separately should receive individual items instead.

A channel carries items; it does not run the analysis command. Operators such as collect() transform those items within Nextflow without submitting a separate task.

Expression Items supplied to the next step
channel.fromPath('data/*.fa') One file path per match
channel.of('sample_a', 'sample_b') Two separate text values
channel.value('GRCh38') One reusable value
COUNT_SEQUENCES.out.collect() One reusable list after all counts arrive

A queue channel supplies each item once to a connected process invocation. A value channel can supply its value repeatedly. For example, many sample tasks can share one reference file passed as a value.

DSL2 also permits two process calls to consume the same channel. Each receives the items. Calling FASTQC(reads_ch) and TRIM(reads_ch) makes independent branches; neither branch waits for the other. To express a dependency, connect an output to an input, such as ALIGN(TRIM.out).

For paired FASTQ files, one sample should usually travel as one item that contains an identifier and both paths. The channel factory reference documents channel.fromFilePairs for this purpose.

For example, files named sample_a_R1.fastq.gz and sample_a_R2.fastq.gz match the pattern data/*_R{1,2}.fastq.gz. The resulting item has this structure. The paths below illustrate the structure; they are not output from the FASTA example.

[sample_a, [sample_a_R1.fastq.gz, sample_a_R2.fastq.gz]]

A process can receive this item with tuple val(sample_id), path(reads). val carries the identifier as a value. path tells Nextflow to make the files available in the task directory. A string containing a filename, passed through val, does not request that file operation.

Keep the identifier attached to outputs when later steps must match results by sample. Do not connect separate sample channels and assume arrival order identifies matching samples. Parallel tasks can finish in a different order. Use an explicit sample key for a join, or keep related data in one tuple.

For a study with lanes, replicates, or clinical metadata, an explicit samplesheet usually makes sample relationships clearer than a filename pattern.

The example leaves several directories and files beside main.nf.

Path Purpose
data/ The original input files
work/ Task directories, intermediate outputs, and command logs
.nextflow/ Local run history and task cache metadata
.nextflow.log The workflow execution log
results/sequence_counts.tsv The published copy of the final table
trace.tsv One record per task for this run

Each task runs in its own directory under work/. With the default local setup, Nextflow stages input files as symbolic links. The relative input name in .command.sh therefore refers to a file inside that task directory, not the launch directory.

The output: path declaration tells Nextflow which files a successful task must produce. It does not create those files. If the command exits successfully but a declared file is missing, Nextflow reports a task error.

publishDir copies the declared final output to results/. Downstream processes must use output channels, because publication happens asynchronously. The overwrite: true setting lets a later run replace the example’s published table. Use separate output directories when you need to retain results from multiple runs.

The process documentation explains input staging and output declarations in more detail.

Run the unchanged pipeline again from the same directory.

resume_example.sh
nextflow run main.nf -resume -with-trace trace_resume.tsv

All four tasks are reused. Their trace status is CACHED. Nextflow still evaluates the workflow and checks the cache; the flag does not bypass those checks.

Now append one FASTA record to sample_b.fa.

change_input.sh
printf '>b_4\nGGGG\n' >> data/sample_b.fa
nextflow run main.nf -resume -with-trace trace_changed.tsv

The count for sample_b becomes four. Its count task and the summary task run again. The count tasks for sample_a and sample_c remain cached.

Change Effect on this example
No change, with -resume All four tasks use cached results.
Append the record to sample_b.fa One count task and the summary task execute again.
Change only the summary command Count tasks remain eligible for reuse; the summary executes again.
Remove a required cached output Nextflow must execute the affected task again.

The local cache needs both metadata in .nextflow/cache/ and the required files in work/. A copy in results/ is insufficient. Keep both cache locations while you need resume.

By default, file cache checks use the path, size, and modification time. They do not compare every byte of every input. Task scripts and execution settings also contribute to task hashes. The cache documentation describes the complete hash inputs and alternative cache modes.

Larger pipelines keep process definitions in separate module files. DSL2 imports those definitions with include. This excerpt shows the connections only; it requires the three named modules and their software.

include { FASTQC } from './modules/fastqc'
include { TRIM } from './modules/trim'
include { ALIGN } from './modules/align'
workflow {
reads_ch = Channel.fromPath(params.input)
FASTQC(reads_ch)
TRIM(reads_ch)
ALIGN(TRIM.out)
}

Here, FastQC and trimming receive the original reads independently. Alignment receives trimmed reads, so each alignment task waits for its corresponding trimmed output. This workflow has no collect() barrier between trimming and alignment.

The nf-core/modules repository supplies reusable tool modules. Pipeline maintainers install specific module revisions and update them explicitly. A fix in that repository does not automatically change every released pipeline.

A process can declare CPU, memory, and runtime requirements. This excerpt shows resource syntax; the STAR command is incomplete and is not part of the runnable FASTA example.

process ALIGN {
cpus 8
memory '32 GB'
time '4h'
input:
path reads
output:
path "*.bam"
script:
"""
STAR --runThreadN $task.cpus --readFilesIn $reads ...
"""
}

The local executor uses CPU and memory requests to decide which tasks can run together. It does not enforce those limits on an ordinary host process. Container engines and cluster schedulers have their own enforcement behavior. The executor documentation describes the distinction.

cpus 8 does not make STAR use eight threads by itself. The command must pass ${task.cpus} to STAR’s thread option. Resource requests and tool arguments must agree.

Save this configuration as nextflow.config beside main.nf. Nextflow reads it automatically on the next run.

nextflow.config
profiles {
local {
process.executor = 'local'
process.cpus = 1
process.memory = '512 MB'
process {
withName: COUNT_SEQUENCES {
maxForks = 2
}
}
}
}

Run nextflow run main.nf -profile local to select this profile. It allows at most two COUNT_SEQUENCES tasks at once. That limit does not change the total number of tasks. The summary still waits for all three count files.

The value local is a profile name defined here. Profile names such as podman, apptainer, or aws work only when the pipeline or supplied configuration defines them.

Add three flags and Nextflow produces an HTML report, a TSV trace, and a timeline.

Terminal window
nextflow run main.nf -resume \
-with-report report.html \
-with-trace trace.txt \
-with-timeline timeline.html

The report summarizes execution and available resource measurements. The trace records task states and timings. The timeline shows task start times and durations. Give each run distinct report filenames when you need to retain several reports.

Nextflow separates analysis commands from the configuration that selects an executor and software environment. This permits the same process definitions to run on different systems when the dependencies and storage requirements are satisfied.

Terminal window
# Pipeline with a defined Podman profile
nextflow run my_pipeline.nf -profile podman
# HPC with Singularity
nextflow run my_pipeline.nf -profile singularity
# Pipeline with a supplied AWS Batch configuration
nextflow run my_pipeline.nf -c aws.config

These commands illustrate other pipelines; the FASTA example defines only local. A container supplies the software environment. An executor decides where a task runs. A container does not supply a missing reference genome, cluster account, or cloud permission.

Nextflow reads configuration files in this order, from lowest to highest priority.

  1. The user configuration at $NXF_HOME/config, normally $HOME/.nextflow/config.
  2. The project directory’s nextflow.config.
  3. The launch directory’s nextflow.config, if that directory differs.
  4. Files supplied with -c.

Pipeline parameters also accept a YAML or JSON file through -params-file. Command-line parameters such as --input override that file. Executor settings belong in configuration, not the parameter file. See the configuration reference for the full precedence rules.

Pipelines fail. Your task is to find which task failed and why. The Nextflow output tells you both.

When a task errors, Nextflow prints the failing process name and the path to its work directory:

ERROR ~ Error executing process > 'FASTQC (sample_3)'
Caused by:
Process `FASTQC (sample_3)` terminated with an error exit status (127)
Command executed:
fastqc sample_3.fastq.gz
Work dir:
/scratch/work/8a/3f72c1...

cd into that work directory and look at the diagnostic files Nextflow stages there:

File Contains
.command.sh The generated task command. It requires the original software environment.
.command.err What the tool wrote to stderr. The actual error message lives here.
.command.log Combined stdout and stderr.
.command.run The wrapper Nextflow used. Useful for debugging the executor.
.exitcode The exit code.

Read .command.err, .command.log, and .nextflow.log before changing the pipeline. A missing executable, a missing output, and a scheduler rejection require different fixes. After you correct the cause, use -resume to reuse successful tasks whose cache entries remain valid.

For the FASTA example, an unmatched --input pattern fails before task execution. A file without a FASTA header fails inside COUNT_SEQUENCES. This distinction tells you whether to inspect the input pattern or a task directory.

nf-core maintains community Nextflow pipelines and shared development tools. A pipeline supplies the analysis steps, software versions, input requirements, and configuration that Nextflow executes.

For a real analysis, read the selected release’s usage and output documentation. Record its release number, parameters, reference data, and software configuration with your results. A container version alone does not record all these choices.

Clone any nf-core pipeline and you see the same structure:

nf-core-rnaseq/
├── main.nf # workflow entry point
├── nextflow.config # default parameters and profiles
├── nextflow_schema.json # parameter schema for the launcher UI
├── conf/
│ ├── base.config # default resource requests
│ ├── modules.config # per-module overrides
│ └── test.config # tiny dataset for CI
├── modules/ # per-tool process definitions
├── workflows/ # composition of modules into the pipeline
├── subworkflows/ # smaller reusable composites
├── assets/
│ └── samplesheet_schema.json
├── docs/
└── README.md

When something is unclear, the answer is usually in conf/, modules.config, or the docs.

The modules/ directory holds one process per tool. nf-core pipelines do not write these from scratch. They install them from the shared nf-core/modules repo using the nf-core CLI:

Terminal window
nf-core modules install samtools/sort
nf-core modules install fastqc
nf-core modules update samtools/sort

Each module is a small folder with a main.nf (the process), a meta.yml (input/output schema), and tests. Versioning is per-module, so you can update FastQC without touching anything else.

Why this matters as a user: when you read an nf-core pipeline and want to know what FastQC version it runs, you look at modules/nf-core/fastqc/main.nf in the pipeline, then cross-reference the same file in nf-core/modules to see if it has been updated since.

Config files: where you actually customise

Section titled “Config files: where you actually customise”

nf-core pipelines are deeply configurable without editing the pipeline itself. Three layers of config files do the work:

The pipeline’s nextflow.config contains configuration defaults and profile definitions. Its parameter schema and release documentation describe the supported pipeline parameters.

The file conf/base.config sets default resources for process labels such as process_low and process_high. Put site-specific overrides in your own configuration file so the pipeline source remains unchanged.

The file conf/modules.config contains settings for individual processes. Two directives commonly appear here.

  • publishDir decides which output files end up in your --outdir, where, and how they are named.
  • ext.args injects extra command-line flags into the tool. So if nf-core/rnaseq calls STAR with default arguments and you want to add --alignIntronMax 100000, you do it here without touching the module.
process {
withName: 'STAR_ALIGN' {
ext.args = '--alignIntronMax 100000 --twopassMode Basic'
publishDir = [
path: "${params.outdir}/star",
mode: 'copy',
pattern: '*.bam'
]
}
}

Place an override in your own custom.config and supply it with -c custom.config. Check the process name and existing arguments in your selected release first. This example is illustrative; a selector that matches no process will not configure the intended task. Replacing ext.args can also remove arguments supplied by the pipeline.

The nf-core/configs repository holds configuration files for participating institutions. Use your institution’s profile only on the infrastructure it describes. For example, a Crick user can select the crick profile.

Terminal window
nextflow run nf-core/rnaseq -profile crick --input samplesheet.csv --outdir results

The institution’s config sets the executor (SLURM, LSF), queue names, scratch paths, container cache locations, and resource limits that match its hardware. You stop reinventing those settings.

If your institution is not in nf-core/configs you can write a minimal local profile and submit a PR to share it with everyone else who works there.

Many nf-core pipelines accept a samplesheet. For nf-core/rnaseq, the release usage documentation describes these four input columns.

sample,fastq_1,fastq_2,strandedness
TREATED_REP1,/data/treated_rep1_R1.fastq.gz,/data/treated_rep1_R2.fastq.gz,auto
TREATED_REP2,/data/treated_rep2_R1.fastq.gz,/data/treated_rep2_R2.fastq.gz,auto
CONTROL_REP1,/data/control_rep1_R1.fastq.gz,/data/control_rep1_R2.fastq.gz,auto
CONTROL_REP2,/data/control_rep2_R1.fastq.gz,/data/control_rep2_R2.fastq.gz,auto

The exact columns differ by pipeline and release. Use the schema and example associated with the release you run. The paths above are placeholders and must identify your actual reads.

nf-core maintains over 100 pipelines covering most areas of genomics:

Pipeline Purpose
nf-core/rnaseq Bulk RNA-seq quantification
nf-core/differentialabundance Differential expression analysis
nf-core/scrnaseq Single-cell RNA-seq processing
nf-core/sarek Variant calling from DNA-seq
nf-core/taxprofiler Metagenomic taxonomic profiling
nf-core/chipseq ChIP-seq peak calling
nf-core/fetchngs Download from SRA/ENA
nf-core/airrflow BCR/TCR repertoire analysis

Browse the full list at nf-co.re/pipelines.

Nextflow needs a compatible Java installation and Bash. A container engine is optional for the FASTA example because its commands run on the host. For Java setup, follow the official installation instructions.

Run these commands in a new directory to download the installer and place Nextflow in your user executable directory.

Terminal window
curl --fail --silent --show-error --location \
https://get.nextflow.io --output install_nextflow.sh
bash install_nextflow.sh
mkdir -p "$HOME/.local/bin"
mv nextflow "$HOME/.local/bin/"
export PATH="$HOME/.local/bin:$PATH"

Check the installed version. Record this version with your pipeline results.

Terminal window
nextflow -version

The PATH change applies to the current shell. Add the same export to your shell configuration if this directory is not already on your PATH.

Bioinformatics pipelines commonly need a container engine such as Podman or Apptainer. Use an engine supported by the pipeline and the compute environment.

The nf-core/rnaseq test profile provides a small dataset. With Podman installed, this command selects a specific pipeline release and its test configuration.

Terminal window
nextflow run nf-core/rnaseq -r 3.22.2 \
-profile test,podman --outdir test_results

This command downloads pipeline code, containers, and test data. It is separate from the locally verified FASTA example above. Check the release’s resource requirements before you run it. The -r option fixes the pipeline revision; it does not select the Nextflow runtime version.

Seqera Platform provides a web interface for workflow runs and compute environments. It is optional. The command-line example on this page does not require a Platform account.

Nextflow and Snakemake solve the same problem with different philosophies. Nextflow is dataflow-first and built around containers. Snakemake is rule-based and Python-native, popular on HPC clusters. The Why Reproducibility Matters page has a side-by-side comparison and guidance on when to pick which.

Choose the compute environment from the pipeline’s memory, storage, and CPU requirements. A small analysis can run locally. Larger inputs may fit an institutional cluster or a cloud service.

Available resources Where to continue
A local computer with enough memory and storage Repeat the local FASTA example and inspect its outputs before you change the inputs.
An institutional cluster Ask your support team for its Nextflow profile, container runtime, and data storage rules.
An AWS account with approved data access and a budget Continue to Setting Up AWS and the AWS Batch guide.

The AWS pages describe one deployment option. You do not need a cloud account to learn Nextflow.

Di Tommaso and colleagues, 2017 describe Nextflow and its model for reproducible computational workflows.

Ewels and colleagues, 2020 describe nf-core and its community-curated bioinformatics pipelines, which include nf-core/rnaseq.

The Nextflow channel reference defines file discovery and paired-read identities. Read it alongside the FASTA channel to separate the values a channel emits from the tasks that consume them.

The cache and resume guide defines task hashes and retained work files. The configuration guide explains configuration precedence. Together they explain which changes can alter a repeated run.