omics.co.in logo omics.co.in

9: Bulk RNA-Seq Analysis with DESeq2

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 9 of 13 0% Course Completed
📊 Downloadable Lesson R Script 4.8 KB

r09_rnaseq_deseq2_pipeline.R

Full RNA-seq pipeline: Median-of-Ratios size factor normalization, negative binomial dispersion estimation, Wald differential test, and sample PCA variance projection.

$ Rscript r09_rnaseq_deseq2_pipeline.R

Chapter 9: Bulk RNA-Seq Analysis: Differential Expression with DESeq2

DESeq2 is the gold standard package for differential gene expression analysis of RNA-seq data. It fits negative binomial generalized linear models (GLMs) with dispersion shrinkage to account for biological variability across replicates.

1. Experimental Design & DESeqDataSet Construction

library(DESeq2)

# Construct DESeqDataSet object
dds <- DESeqDataSetFromMatrix(
    countData = counts_matrix,
    colData   = col_data,
    design    = ~ Batch + Condition
)

2. Library Size Normalization (Median of Ratios)

DESeq2 calculates size factors by taking the median ratio of each sample's counts to the geometric mean across all samples:

dds <- estimateSizeFactors(dds)
print(sizeFactors(dds))

3. Running Differential Analysis & Results Extraction

# Run full DESeq pipeline
dds <- DESeq(dds)

# Extract differential results (Treated vs Control)
res <- results(dds, contrast = c("Condition", "Treated", "Control"), alpha = 0.05)
summary(res)

# Filter for significantly upregulated genes
sig_up <- subset(res, padj < 0.05 & log2FoldChange > 1.5)
head(sig_up[order(sig_up$padj), ])

4. Exploratory Data Analysis: PCA Projection

Visualizing sample clustering on variance-stabilized transformed (VST) counts:

vsd <- vst(dds, blind = FALSE)
plotPCA(vsd, intgroup = c("Condition", "Batch"))
⚠️

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 chr1 or 1; divergent naming causes silent alignment drops.
Was this guide helpful to your research?
Help us maintain 100% accurate, peer-reviewed bioinformatics standards.
📝 Propose Edit on GitHub ↗