Skip to main content

HistoMap

HistoMap is a Python library for analyzing and visualizing histological annotations alongside spatially resolved transcriptomics data (Visium, VisiumHD and Xenium). It provides tools for processing, analyzing, and visualizing GeoJSON-based tissue annotations with spatial transcriptomics spot data. It is integrated with QuPath and ImageJ annotations, and interface with scanpy, squidpy and Seurat through either SpatialData or generation of MetaData.

Documentation is available here : https://histomaptx.readthedocs.io/en/latest/

Installation

pip install histomaptx

Supported Technologies

HistoMap works with any spatially resolved transcriptomics platform exposed through a SpatialData object. The unit that annotations are overlapped against depends on the platform:

Technology spatial_type Overlap unit
Visium 'visium' Circular spot
Visium HD 'visium_hd' Square bin (configurable bin size)
Xenium 'xenium' Cell segmentation polygon

More platforms can be added upon request - please open an issue on the GitHub repository describing your data.

Core Functionality

Loading and Processing Annotations

HistoMap automatically processes annotation files in geojson format from QuPath and extracts key information:

import histomaptx as hm
# Initialize with a GeoJSON file
histo = hm.HistoMap("annotations.geojson", visium_spatial_data, '/path/to/image.tiff')

Generating Statistical Summaries

Get comprehensive morphological statistics about each annotation:

# Generate a summary DataFrame with key metrics
summary = histo.generate_summary()
print(summary)

The summary includes metrics such as:

  • Total area and perimeter
  • Mean aspect ratio, circularity, and compactness
  • Centroid coordinates
  • Solidity and extent
  • Polygon counts

Visualization

HistoMap offers multiple visualization options:

Basic Annotation Plot

# Plot annotations with default settings
histo.plot_annotations()

# Customize fill and contour colors
histo.plot_annotations(fill=True, contour="black")

# Specify custom colors for each annotation
histo.plot_annotations(fill=["red", "blue", "green"], contour=["black", "black", "black"])

3D Visualization by Annotation Order

# Create a 3D plot with annotations at different z-levels
histo.plot_annotation_order()

Controlling Annotation Order

The order in which annotations are plotted can be crucial for generating the final map:

# Display current plot order
histo.display_plot_order()

# Change plot order (annotations listed first will be on top)
histo.change_plot_order(["Tumor", "Stroma", "Immune cells"])

Compute overlap of annotation with spatial units

Compute the overlap between histological annotations and Visium spots:

# Compute overlap between annotations and spots
histo.compute_overlap_annotation()

# Visualize spots colored by their overlap with a specific annotation
histo.plot_annotation_overlay("Tumor")

# Find spots that overlap with two different annotations
histo.plot_combined_annotation_overlap("Tumor", "Immune cells")

Generate the annotation map

Once overlaps are computed and positivity threshold set, we can generate the final annotation map

histomap.generate_annotation_map(annotate_all=True)  

hm.plot_annotation_map(histomap, resolution='lowres') 

Advanced Usage

Custom Annotation Colors

You can customize the colors used for annotations to make your visualizations match your publication style:

# Define custom colors
annotation_colors = {
    "Tumor": "#E41A1C",
    "Stroma": "#377EB8",
    "Immune cells": "#4DAF4A"
}

# Use a color list matching the annotation order
annotations = histo.data_exploded['Annotation'].unique()
color_list = [annotation_colors[ann] for ann in annotations]

# Plot with custom colors
histo.plot_annotations(fill=color_list, contour="black")

Exporting Results

# Generate and save a summary to CSV
summary = histo.generate_summary()
summary.to_csv("annotation_summary.csv", index=False)

# Save the figure
fig, ax = plt.subplots(figsize=(10, 10))
histo.plot_annotations()
plt.savefig("annotations.png", dpi=300, bbox_inches="tight")

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use HistoMap in your research, please cite:

Unpublished

Contact

For questions and feedback, please open an issue on the GitHub repository

Metadata

Release files for histomaptx 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for histomaptx 0.1.12
File Size Uploaded Provenance Actions
histomaptx-0.1.12.tar.gz 36.5 kB Without provenance Details for histomaptx-0.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for histomaptx 0.1.12
File Interpreter ABI Platform Actions
histomaptx-0.1.12-py3-none-any.whl Python 3 none any Details for histomaptx-0.1.12-py3-none-any.whl

Total release size: 69.5 kB

Release files / histomaptx-0.1.12.tar.gz

Download URL histomaptx-0.1.12.tar.gz
Size 36.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1a386bcef4948a38ac2be0b334fefe4d33bb07877b9f96f37ddcd5ddb2d421bf
BLAKE2b-256 checksum
How to use checksums
6ecb04d64cfd364f2a48c4cd2434e2f0b94edee8ebdc33a1f53a786b037288ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / histomaptx-0.1.12-py3-none-any.whl

Download URL histomaptx-0.1.12-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b0d596fa813e4e75c3f82f633422ff6e262eeeb7b3600fbf2e08ad7ce48ad96
BLAKE2b-256 checksum
How to use checksums
35ca4710668d2197b4b2712c1b2e9e65a7fc39ed32c7491e1abf56d6f626a284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for histomaptx 0.1.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page