omics.co.in logo omics.co.in

10: Advanced Omics Heatmaps & Clustering

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

r10_complexheatmaps_clustering.R

Row-wise Z-score normalization, hierarchical clustering (Pearson/Ward.D2), multi-track clinical column annotations (Subtypes, Stages), and publication-ready export.

$ Rscript r10_complexheatmaps_clustering.R

Chapter 10: Advanced Omics Heatmaps & Clustering with ComplexHeatmap

Heatmaps are indispensable for visualizing multi-sample transcriptomic, epigenomic, and proteomic matrices. ComplexHeatmap enables publication-grade clustered heatmaps with multi-track clinical annotations, row splitting, and dendrogram pruning.

1. Row-wise Z-Score Standardization

Standardizing expression values ($Z = \frac{x - \mu}{\sigma}$) centers gene profiles around zero for direct pattern comparison:

mat_z <- t(scale(t(counts_matrix)))

2. Multi-Track Clustered Heatmap

library(ComplexHeatmap)
library(circlize)

col_fun <- colorRamp2(c(-2, 0, 2), c("#2563EB", "#FFFFFF", "#DC2626"))

ha_top <- HeatmapAnnotation(
    Subtype  = sample_anno$Subtype,
    Response = sample_anno$Response,
    col = list(
        Subtype  = c("Basal-like" = "#E11D48", "Luminal A" = "#059669", "HER2+" = "#7C3AED"),
        Response = c("Responder" = "#10B981", "Non-Responder" = "#64748B")
    )
)

Heatmap(
    mat_z,
    name = "Z-Score",
    col = col_fun,
    top_annotation = ha_top,
    clustering_distance_rows = "pearson",
    clustering_method_rows = "ward.D2",
    column_title = "Oncogenic Transcriptomic Profile"
)
⚠️

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 ↗