Nextflow
Nextflow is a reactive workflow framework and a programming DSL that eases writing computational pipelines with complex data Nextflow Homepage
Available Modules¶
module load Nextflow/25.10.0
See Snakemake and Cylc for other possible choices.
Methods for running Nextflow with REANNZ¶
There are three suggested methods for running Nextflow pipelines on our system:
- Running Nextflow in an interactive Slurm session
- This method is best for setting up or debugging pipeline executions as the pipeline will end as soon as the interactive session ends.
- Submitting a Nextflow workflow as a batch job
- This method will run all sub-processes in the same Slurm job. This is best if your workflow would spawn a large number of short jobs.
- Submitting a Nextflow workflow via a head job
- This method requires submitting a low resource but long running batch job which will control the Nextflow workflow and all processes will be submitted by Nextflow as separate jobs to Slurm. This method is useful for workflows with lots of variation in their computational needs and which comprise mostly long running processes.
The differences in these methods is largely controlled by configuration/profile settings. The examples below use the REANNZ configuration file provided in the Configurations section.
Running Nextflow in an interactive Slurm session¶
Running Nextflow in an interactive session can be especially helpful when setting up or debugging a pipeline. To do so, request an interactive session with appropriate resources for the pipeline:
srun --account nesi12345 --job-name "InteractiveJob" --cpus-per-task 16 --mem-per-cpu 24000 --time 24:00:00 --pty bash
Once your interactive session has launched, load the Nextflow module with module load Nextflow/25.10.1 (or your required version) and proceed. Parallelization of Nextflow processes will occur within this job.
There are several environmental variables that can be helpful to avoid loading containers and plugins into your persistent project space:
export NXF_APPTAINER_CACHEDIR=/nesi/nobackup/nesi12345/apptainer_cache
export NXF_PLUGINS_DIR=/nesi/project/nesi12345/.nextflow/plugins
You can confirm that Nextflow is loaded and ready using the nextflow run hello command to test Nextflow's Hello World pipeline.
Submitting a Nextflow workflow as a batch job¶
The following sbatch will submit a Nextflow workflow as a Slurm job. All of the Nextflow processes will run on the same compute node, so request enough resources to run the most intensive process in the workflow and enough time for the entire workflow to complete.
#!/bin/bash -e
#SBATCH --job-name nextflow-workflow
#SBATCH --account nesi12345
#SBATCH --time 12:00:00
#SBATCH --mem 24G
#SBATCH --cpus-per-task 16
# load Nextflow and set environmental variables
module load Nextflow/25.10.0
export NXF_APPTAINER_CACHEDIR=/nesi/nobackup/nesi12345/apptainer_cache
export NXF_OFFLINE='true'
export NXF_PLUGINS_DIR=/nesi/project/nesi12345/.nextflow/plugins
# run nextflow
nextflow run NEXTFLOW_WORKFLOW \
-profile local,apptainer \
--outdir /nesi/project/nesi12345/NEXTFLOW_WORKFLOW/out \
-w /nesi/nobackup/nesi12345/NEXTFLOW_WORKFLOW/work
Submitting a Nextflow workflow via a head job¶
The following sbatch script will request the resources to run a Nextflow head job which will then submit processes to Slurm as separate tasks. Beyond the resources requested for this job, the only difference between this script and the previous one is the change in the -profile tag from local,apptainer to slurm,apptainer.
#!/bin/bash -e
#SBATCH --job-name nextflow-head
#SBATCH --account nesi12345
#SBATCH --time 12:00:00
#SBATCH --mem 4G
#SBATCH --cpus-per-task 4
# load Nextflow and set environmental variables
module load Nextflow/25.10.0
export NXF_APPTAINER_CACHEDIR=/nesi/nobackup/nesi12345/apptainer_cache
export NXF_OFFLINE='true'
export NXF_PLUGINS_DIR=/nesi/project/nesi12345/.nextflow/plugins
# run nextflow
nextflow run NEXTFLOW_WORKFLOW \
-profile slurm,apptainer \
--outdir /nesi/project/nesi12345/NEXTFLOW_WORKFLOW/out \
-w /nesi/nobackup/nesi12345/NEXTFLOW_WORKFLOW/work
Avoid many short jobs
This will put a major burden on the Slurm scheduler for no improvement in your computational speed. Do not use the Nextflow slurm executor for jobs which take less than 30 minutes to complete.