Chapter 6: Building an End-to-End RNA-Seq Pipeline in Nextflow DSL2
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 6 of 13
0% Course Completed
Chapter 6: Building an End-to-End RNA-Seq Pipeline in Nextflow DSL2
In this chapter, we assemble a complete, production-grade Nextflow DSL2 bulk RNA-Seq pipeline from raw paired-end reads to a unified MultiQC summary report.
Pipeline Architecture Overview
Data flows through 5 modular stages: FASTQC → FASTP (adapter trimming) → STAR_ALIGN (splice-aware alignment) → FEATURECOUNTS (gene quantification) → MULTIQC (quality report aggregation).
1. Complete main.nf Pipeline Script
nextflow.enable.dsl = 2
// Include modular subworkflows or processes
include { FASTQC } from './modules/fastqc.nf'
include { FASTP } from './modules/fastp.nf'
include { STAR_ALIGN } from './modules/star_align.nf'
include { FEATURECOUNTS} from './modules/featurecounts.nf'
include { MULTIQC } from './modules/multiqc.nf'
workflow {
// 1. Validate inputs
params.input = 'samplesheet.csv'
params.genome_dir = '/ref/star_index'
params.gtf = '/ref/genes.gtf'
params.outdir = 'results'
// 2. Parse sample sheet
ch_samples = Channel.fromPath(params.input)
| splitCsv(header: true)
| map { row -> tuple(row.sample, [file(row.fastq_1), file(row.fastq_2)]) }
// 3. Raw read QC
FASTQC(ch_samples)
// 4. Trimming with Fastp
FASTP(ch_samples)
// 5. Alignment with STAR
ch_star_index = Channel.value(file(params.genome_dir))
STAR_ALIGN(FASTP.out.reads, ch_star_index)
// 6. Gene Quantification
ch_gtf = Channel.value(file(params.gtf))
FEATURECOUNTS(STAR_ALIGN.out.bam, ch_gtf)
// 7. MultiQC Summary Report
ch_multiqc_files = FASTQC.out.zip
.mix(FASTP.out.json)
.mix(STAR_ALIGN.out.log)
.mix(FEATURECOUNTS.out.summary)
.collect()
MULTIQC(ch_multiqc_files)
}2. Executing the Pipeline
# Run locally with Docker container profile
nextflow run main.nf \
--input samplesheet.csv \
--genome_dir /ref/star_index \
--gtf /ref/genes.gtf \
-profile docker \
-resume
⚠️
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.