Zubair Khalid

Virologist/Molecular Biologist | Veterinarian | Bioinformatician

Conventional & Molecular Virology • Vaccine Development • Computational Biology

Dr. Zubair Khalid is a veterinarian and virologist specializing in conventional and molecular virology, vaccine development, and computational biology. Dedicated to advancing animal health through innovative research and multi-omics approaches.

Dr. Zubair Khalid - Veterinarian, Virologist, and Vaccine Development Researcher specializing in Computational Biology, Multi-omics, Animal Health, and Infectious Disease Research

Category: Guides

Rna Seq Deseq2 Tutorial

This guide explains how to analyze RNA sequencing (RNA-seq) data for differential gene expression using the DESeq2 package from Bioconductor. You will learn a step by step framework that covers core concepts, decision points, a practical workflow, quality checks, common mistakes, and interpretation limits. This tutorial is intended for life science researchers and bioinformatics practitioners who have basic familiarity with R, the command line, and next generation sequencing, no prior experience with DESeq2 is required. The workflow assumes you have already obtained read counts, either from a tool like featureCounts, htseq count, or Salmon. For authoritative background on RNA-seq analysis, refer to the EMBL EBI Training resources that cover experimental design and quality control.

RNA-seq differential expression analysis is a multi step process. DESeq2, developed by Love, Huber, and Anders (2014), uses a negative binomial generalized linear model to model count data. It handles normalization, dispersion estimation, and statistical testing in a single integrated framework. For an excellent practical introduction to building an RNA-seq pipeline, the Galaxy Training Network offers interactive tutorials that complement this guide.

At a Glance

Aspect Details
Purpose Identify differentially expressed genes (DEGs) between experimental conditions
Input A count matrix (genes x samples) and a sample metadata table
Key software DESeq2 package (R/Bioconductor), R (version >=4.0)
Normalization Median of ratios (default) for library size and composition differences
Statistical model Negative binomial generalized linear model with shrunken dispersion estimates
Output List of genes with log2 fold changes, p values, and adjusted p values
Minimum samples At least 3 biological replicates per condition (2 can work with caution)

Core Concepts and Decision Points

DESeq2 infers differential expression by modeling the variance of read counts across replicates. The core challenge is that genes with low counts have higher variability. The package uses an empirical Bayes approach to shrink dispersion estimates toward a fitted trend, improving power and reducing false positives. Key decisions before you run DESeq2 include:

  • Experimental design. Specify a design formula that captures biological variation (e.g., ~ condition or ~ batch + condition). Always include variables that affect expression, such as batch or treatment. Failing to account for known covariates will reduce statistical accuracy. The NCBI Bookshelf offers a chapter on designing biological experiments that explains the importance of balanced replicates.

  • Count matrix generation. DESeq2 expects integer counts. Use tools like featureCounts or Salmon with tximport to produce a matrix. Do not normalize counts before DESeq2. The package requires raw counts because it accounts for library size internally. For a walkthrough on generating count tables from BAM files, see the Bioconductor documentation for the Rsubread or GenomicAlignments packages.

  • Choice of contrast. After fitting the model, you define the contrast to compare two groups (e.g., treated vs control). DESeq2 automatically returns log2 fold changes and tests whether the fold change equals zero.

  • Multiple testing correction. DESeq2 uses the Benjamini Hochberg procedure to control the false discovery rate (FDR). Common thresholds are adjusted p value (padj) < 0.05.

Practical Workflow for DESeq2 Analysis

The following steps assume you have R installed and have already installed DESeq2 (from Bioconductor) and the ggplot2 and pheatmap packages for visualization.

Step 1: Prepare Input Data

Create a count matrix (genes as rows, samples as columns) and a metadata data frame with sample names and conditions. The row names of the metadata must match the column names of the count matrix exactly. Example R code:

counts <- read.csv("counts.csv", row.names = 1)
metadata <- read.csv("metadata.csv", row.names = 1)

Step 2: Create a DESeqDataSet Object

Use DESeqDataSetFromMatrix():

dds <- DESeqDataSetFromMatrix(countData = counts,
                              colData = metadata,
                              design = ~ condition)

Replace condition with the name of your experimental variable. The Galaxy Training Network provides an alternative point and click workflow for those less comfortable with R.

Step 3: Pre filtering

Remove rows with very low counts to reduce memory and speed computation. A common rule: keep genes with at least 10 reads total across all samples.

keep <- rowSums(counts(dds)) >= 10
dds <- dds[keep, ]

Step 4: Run the Differential Expression Analysis

A single call to DESeq() performs normalization, dispersion estimation, and testing:

dds <- DESeq(dds)

Step 5: Extract Results

Use results() to obtain the comparison for a specific contrast. For a two group comparison:

res <- results(dds, contrast = c("condition", "treated", "control"))

Order by adjusted p value:

res <- res[order(res$padj), ]

View a summary of results:

summary(res)

Step 6: Write Results to a CSV File

write.csv(as.data.frame(res), file = "deseq2_results.csv")

Quality Checks and Diagnostics

After running DESeq(), examine diagnostic plots to assess the quality of your analysis.

  • PCA plot. Use plotPCA() on the variance stabilized transformed (VST) counts. This reveals whether samples cluster by condition and whether any batch effects are apparent. The EMBL EBI Training material on RNA QC includes guidance on interpreting PCA plots.

  • Dispersion plot. Use plotDispEsts(dds). This shows the per gene dispersion estimates (black dots), the fitted trend (red line), and the shrunken estimates (blue diamonds). Large deviations from the trend may indicate outliers or data issues.

  • MA plot. After extracting results, use plotMA(res, ylim = c(-2,2)). This shows the log2 fold change versus the mean of normalized counts. Points in red are genes with padj < 0.1.

  • Independent filtering. DESeq2 automatically performs independent filtering on the mean of normalized counts to optimize the number of genes with padj < 0.1. Check that the filtering did not discard too many low count genes that might be biologically important.

Common Mistakes

  • Using normalized counts for input. Never provide TPM, FPKM, or other normalized values to DESeq2. The package expects raw integer counts and will produce incorrect results if you feed it pre normalized data.

  • Ignoring batch effects. If your samples were processed on different days, by different technicians, or in separate sequencing runs, include a batch variable in the design formula. The Bioconductor documentation has a section on adding batch effects to the model.

  • Too few replicates. DESeq2 can work with two replicates per group, but the dispersion estimates will be unreliable. Three or more biological replicates per condition is strongly recommended to achieve robust detection.

  • Using a factorial design without interaction terms. If you have multiple factors (e.g., treatment and time), think carefully about the model. An additive model (~ treatment + time) assumes effects are independent. An interaction model (~ treatment * time) allows the effect of treatment to vary by time. Choose based on your biological question.

  • Over interpreting very small fold changes. A gene with a padj of 0.001 but a log2 fold change of 0.2 may not be biologically meaningful. Apply a fold change cutoff (e.g., |log2FC| > 1) if that suits your hypothesis, but always report the unfiltered results as well for transparency.

Limits of Interpretation

DESeq2 analysis provides statistical associations, not causal proof. Several factors limit what you can conclude:

  • Sequencing depth and library complexity. Insufficient sequencing depth will fail to detect lowly expressed genes. The minimum depth depends on the genome size and expression distribution. The NCBI Sequence Read Archive offers experimental design guidelines from deposited studies.

  • Biological vs technical noise. Even with many replicates, biological variability can obscure small but real changes. DESeq2 assumes that most genes are not differentially expressed (the basis for median of ratios normalization). If this assumption is violated (e.g., global expression shift in a mutant), normalization may be biased.

  • Isoform level inference. DESeq2 analyzes genes by default. To analyze transcripts or isoforms, you need to use count matrices derived from transcript level quantification (e.g., Salmon) and then pass them to DESeq2 via tximport. Be aware that transcript level analysis has higher uncertainty due to multi mapping reads.

  • Fold change shrinkage. DESeq2 applies logarithmic fold change (LFC) shrinkage to low count and high dispersion genes. The shrunken LFC values are more conservative and should be used for ranking, not as absolute effect sizes. Use the lfcShrink() function to obtain shrunken values for visualization.

  • Generalizability. Results from a single experiment may not reproduce in different cell types, tissues, or conditions. Always validate key DEGs with an orthogonal method like RT qPCR.

Frequently Asked Questions

1. Can I use DESeq2 if I only have two replicates per condition? Yes, but with caution. DESeq2 can estimate dispersion using a fitted trend when individual gene dispersion cannot be reliably computed from two replicates. The results will be less powerful. You should increase to at least three replicates for any experiment where possible.

2. How do I include a continuous variable in the design, such as age or dosage? Use the continuous variable directly in the design formula, for example design = ~ age + condition. DESeq2 will treat it as a numeric covariate. Ensure the variable is numeric and not a factor.

3. What is the difference between results() and lfcShrink()? results() returns raw log2 fold changes from the model. lfcShrink() applies a shrinkage estimator that reduces extreme changes from low count genes. Use shrunken values for sorting genes and creating volcano plots, but report both in supplementary files.

4. My PCA plot shows samples clustering by batch rather than condition. What should I do? Include batch in the design formula (e.g., design = ~ batch + condition). Then rerun DESeq(). If batch explains most variance, the differential expression analysis will adjust for it. You can also use limma::removeBatchEffect on transformed counts for visualization, but do not use batch corrected counts as input for DESeq2.

References and Further Reading

Alright, references: use Bioconductor for DESeq2 page, Galaxy Training for tutorial, EMBL EBI Training, NCBI Bookshelf, NCBI SRA. That's five, need 6-10. I can have multiple links per source: e.g., Bioconductor DESeq2 page, Bioconductor workshop PDF, NCBI Bookshelf chapter, NCBI SRA submission guidelines, EMBL EBI RNA seq training, Galaxy training. That's 6. Add the DESeq2 paper link from Bioconductor? It's part of Bioconductor page. I'll write as:

That gives 7. Good.

Now Related Articles: must include exactly the five supplied links. They are:

  • Somatic Cell: /blog/guides/somatic-cell
  • Phases In Cell Cycle: /blog/guides/phases-in-cell-cycle
  • Endoplasmic Reticulum Cell Function: /blog/guides/endoplasmic-reticulum-cell-function
  • Stages Of Cell Cycles: /blog/guides/stages-of-cell-cycles
  • Pcr Test: /blog/guides/pcr-test

Write as a list under Related Articles H2.

Ensure first two paragraphs have source links. Already did: first paragraph EMBL EBI, second Galaxy Training.

Now structure. Keep H2 sections: Core Concepts and Decision Points, Practical Workflow, Quality Checks, Common Mistakes, Limits, FAQ, References, Related Articles.

Word count: aim for around 1800. Write concisely.

Make sure no semicolons, em dashes, en dashes. Use periods and commas. No AI/SEO prompts.

Let's write final markdown.# Rna Seq Deseq2 Tutorial

This guide explains how to analyze RNA sequencing (RNA-seq) data for differential gene expression using the DESeq2 package from Bioconductor. You will learn a step by step framework that covers core concepts, decision points, a practical workflow, quality checks, common mistakes, and interpretation limits. This tutorial is intended for life science researchers and bioinformatics practitioners who have basic familiarity with R, the command line, and next generation sequencing, no prior experience with DESeq2 is required. The workflow assumes you have already obtained read counts, either from a tool like featureCounts, htseq count, or Salmon. For authoritative background on RNA-seq analysis, refer to the EMBL EBI Training resources that cover experimental design and quality control.

RNA-seq differential expression analysis is a multi step process. DESeq2, developed by Love, Huber, and Anders (2014), uses a negative binomial generalized linear model to model count data. It handles normalization, dispersion estimation, and statistical testing in a single integrated framework. For an excellent practical introduction to building an RNA-seq pipeline, the Galaxy Training Network offers interactive tutorials that complement this guide.

At a Glance

Aspect Details
Purpose Identify differentially expressed genes (DEGs) between experimental conditions
Input A count matrix (genes x samples) and a sample metadata table
Key software DESeq2 package (R/Bioconductor), R (version >=4.0)
Normalization Median of ratios (default) for library size and composition differences
Statistical model Negative binomial generalized linear model with shrunken dispersion estimates
Output List of genes with log2 fold changes, p values, and adjusted p values
Minimum samples At least 3 biological replicates per condition (2 can work with caution)

Core Concepts and Decision Points

DESeq2 infers differential expression by modeling the variance of read counts across replicates. The core challenge is that genes with low counts have higher variability. The package uses an empirical Bayes approach to shrink dispersion estimates toward a fitted trend, improving power and reducing false positives. Key decisions before you run DESeq2 include:

  • Experimental design. Specify a design formula that captures biological variation (e.g., ~ condition or ~ batch + condition). Always include variables that affect expression, such as batch or treatment. Failing to account for known covariates will reduce statistical accuracy. The NCBI Bookshelf offers a chapter on designing biological experiments that explains the importance of balanced replicates.

  • Count matrix generation. DESeq2 expects integer counts. Use tools like featureCounts or Salmon with tximport to produce a matrix. Do not normalize counts before DESeq2. The package requires raw counts because it accounts for library size internally. For a walkthrough on generating count tables from BAM files, see the Bioconductor documentation for the Rsubread or GenomicAlignments packages.

  • Choice of contrast. After fitting the model, you define the contrast to compare two groups (e.g., treated vs control). DESeq2 automatically returns log2 fold changes and tests whether the fold change equals zero.

  • Multiple testing correction. DESeq2 uses the Benjamini Hochberg procedure to control the false discovery rate (FDR). Common thresholds are adjusted p value (padj) < 0.05.

Practical Workflow for DESeq2 Analysis

The following steps assume you have R installed and have already installed DESeq2 (from Bioconductor) and the ggplot2 and pheatmap packages for visualization.

Step 1: Prepare Input Data

Create a count matrix (genes as rows, samples as columns) and a metadata data frame with sample names and conditions. The row