← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-workflow-management-nextflow-pipelines / references / usage-guide.md

Nextflow Pipelines - Usage Guide

Overview

Nextflow is a reactive-dataflow workflow engine: processes are wired together by asynchronous channels, each channel item is a future, and a task fires the instant its inputs are ready, so execution order is not guaranteed. This is the opposite of pull/goal-oriented engines (Snakemake/CWL/WDL) that reason backward from a target file. The payoff is reproducibility, resumable caching, and executor portability (the same code moves from a laptop to SLURM to AWS Batch by swapping a profile). The trap to internalize first is that the DAG buys reproducibility of workflow LOGIC only; a pipeline over unpinned tools is not reproducible, so the software environment (container by digest, conda by lockfile), reference data, and thread/locale/arch leaks must be pinned by hand. Most of the field's day-to-day pain (only the first sample ran; -resume re-ran everything) traces directly back to the dataflow model and to unpinned or nondeterministic inputs.

Prerequisites

# Install Nextflow (requires a Java 17+ JVM)
conda install -c bioconda nextflow

# Or via conda
conda install -c bioconda nextflow

# A container runtime for reproducible per-process software:
#   Docker (local/cloud) or Singularity/Apptainer (HPC, rootless)

Inputs: a main.nf (DSL2), an optional nextflow.config with profiles, per-process containers pinned by immutable tag or digest, and read/reference paths supplied via params or a samplesheet.

Quick Start

Tell your AI agent what you want to do: - "Author a Nextflow DSL2 pipeline for paired-end RNA-seq quantification" - "Fix my pipeline so it processes every sample, not just the first" - "Diagnose why my -resume keeps re-running everything on the cluster" - "Add dynamic memory retry escalation to my alignment process" - "Make my pipeline portable across local, SLURM, and AWS Batch with profiles"

Example Prompts

Authoring a Pipeline

"Build a Nextflow DSL2 pipeline with FASTQC, fastp trimming, Salmon quantification, and MultiQC, using per-process containers pinned by tag and a meta-map convention for sample identity."

"Refactor my monolithic main.nf into DSL2 modules and a QC subworkflow with take/main/emit."

Channels and Dataflow

"My pipeline only processes the first sample and exits cleanly with no error - explain why and fix it."

"Set up channels to join per-sample BAMs with their metadata by sample key without silently dropping unmatched samples."

Resume and Caching

"My -resume works locally but misses the cache on our Lustre cluster and re-runs everything - diagnose and fix it."

"Use -dump-hashes and nextflow log to find which task's hash changed between two runs."

Resources and Portability

"Add exit-status-conditional retry with memory escalation to my OOM-prone process."

"Configure profiles so the same pipeline runs on local Docker, SLURM with Singularity, and AWS Batch."

What the Agent Will Do

  1. Author a main.nf in DSL2 with processes wired through channels, and split reusable tools into modules with take/main/emit subworkflows.
  2. Choose queue vs value channels correctly, using .first() (or Channel.value) for any shared reference so every sample fires, not just the first.
  3. Select operators with their traps in mind (groupTuple size hint, join remainder to avoid silent drops).
  4. Pin per-process containers by immutable tag or digest and set the software runtime and executor in profiles, never in pipeline code.
  5. Add dynamic retry escalation (memory { 8.GB * task.attempt }) with exit-status-conditional errorStrategy.
  6. Diagnose -resume cache misses (nondeterministic ordering, mtime, mutable tags) with cache 'lenient', -dump-hashes, and nextflow log.
  7. Recommend adopting an nf-core community pipeline when the analysis is mainstream, reserving authoring for genuinely novel logic.

Tips