Skip to main content

Python port of the R ComplexHeatmap package on a grid_py backend (tracks R ComplexHeatmap 2.25.3)

Project description

ComplexHeatmap-python

A Python port of the R ComplexHeatmap package (v2.25.3), built on grid_py — a pure-Python reimplementation of R's grid graphics system.

No matplotlib dependency. The entire rendering pipeline uses grid_py's Cairo backend, producing publication-quality output identical to R's grid device.

Features

  • Heatmap with row/column clustering, splitting (k-means, factor), dendrograms, and custom color mapping
  • HeatmapList for combining multiple heatmaps horizontally (+) or vertically (%), with synchronized row/column ordering and cross-heatmap body alignment
  • 20 annotation functions: anno_barplot, anno_points, anno_lines, anno_mark, anno_text, anno_boxplot, anno_histogram, anno_density, anno_block, anno_image, and more
  • HeatmapAnnotation with flexible sizing, gap control, and annotation name positioning
  • Legends with continuous color bars and discrete icon legends, packable and positionable on all four sides
  • oncoPrint for mutation landscape visualization
  • UpSet plots for set intersection analysis
  • Heatmap3D for 3D bar-style heatmaps with CIE LUV/HCL color space
  • densityHeatmap and frequencyHeatmap for distribution visualization
  • Global options via ht_opt() matching R's ht_opt$... interface
  • Decoration API (decorate_heatmap_body, decorate_annotation, etc.) for post-draw customization

Installation

pip install complexheatmap-python

Or, for a local development checkout:

git clone https://github.com/Bio-Babel/ComplexHeatmap_python.git
cd ComplexHeatmap_python
pip install -e ".[dev]"

Quick Start

import numpy as np
from complexheatmap import Heatmap, color_ramp2

mat = np.random.randn(20, 10)
col = color_ramp2([-2, 0, 2], ["blue", "white", "red"])

ht = Heatmap(mat, name="example", col=col,
             row_km=3, column_title="My Heatmap")
ht.draw()

Combining Heatmaps

import grid_py as gp
from complexheatmap import Heatmap, color_ramp2, rowAnnotation, anno_barplot

np.random.seed(42)
mat1 = np.random.randn(20, 8)
mat2 = np.random.randn(20, 5)

ht1 = Heatmap(mat1, name="expr",
              col=color_ramp2([-2, 0, 2], ["green", "white", "red"]))
ht2 = Heatmap(mat2, name="cnv",
              col=color_ramp2([-1, 0, 1], ["blue", "white", "orange"]))

ht_list = ht1 + ht2 + rowAnnotation(
    bar=anno_barplot(np.random.randn(20), which="row"),
    width=gp.Unit(2, "cm"),
)
ht_list.draw(merge_legends=True)

Tutorials

Jupyter notebooks porting the official R ComplexHeatmap tutorials:

# Notebook Topic
1 Single Heatmap Colors, clustering, splitting, annotations, labels
2 Heatmap Annotations All 20 annotation types, sizing, decoration
3 A List of Heatmaps Horizontal/vertical combination, row/column sync
4 Legends Continuous/discrete legends, positioning
5 Heatmap Decoration Post-draw customization via decorate API
6 OncoPrint Mutation landscape visualization
7 UpSet Plot Set intersection analysis
8 Integration Combining with other analyses
9 Other High-Level Plots densityHeatmap, frequencyHeatmap
10 3D Heatmap Heatmap3D with bar projections
11 Genome-Level Heatmap Chromosome-split genome visualization
12 Examples Gene expression, measles, methylation
13 Other Tricks Utility functions, text measurement, ht_opt

Testing

pip install -e ".[dev]"
pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

complexheatmap_python-2.25.3.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

complexheatmap_python-2.25.3-py3-none-any.whl (3.7 MB view details)

Uploaded Python 3

File details

Details for the file complexheatmap_python-2.25.3.tar.gz.

File metadata

  • Download URL: complexheatmap_python-2.25.3.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for complexheatmap_python-2.25.3.tar.gz
Algorithm Hash digest
SHA256 f27e259dd721ff949f2e42dc9efcbc9c7003a03b4cf19feb3cc861353493b042
MD5 491df7e59f18cbe1eea87049664b6ed2
BLAKE2b-256 e3caf2f2c839ababee161bff8151a69ee353deee486c575f96842f85d96e14a7

See more details on using hashes here.

File details

Details for the file complexheatmap_python-2.25.3-py3-none-any.whl.

File metadata

File hashes

Hashes for complexheatmap_python-2.25.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d73a0124b29f3b07bae2179158e3a38b193e112816f39839e00b3e8bce7807a
MD5 c326b4c3630b9dcd13f7cf98c2ec3faf
BLAKE2b-256 d67bb4a88bd9d62de3fba15cb53378d017dc7be59c4af6dc75a47da206531574

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page