Skip to main content

A Python library for analyzing histological annotations alongside spatial transcriptomics data

Project description

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

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

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

histomaptx-0.1.7.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

histomaptx-0.1.7-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file histomaptx-0.1.7.tar.gz.

File metadata

  • Download URL: histomaptx-0.1.7.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for histomaptx-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8cf28c504c559b0ccca81a5256446076fa00074d1c7c0f999d34fd6938096ce3
MD5 33ccffe22dc5620b04de83ebe4987a35
BLAKE2b-256 a3e89e36b6d5ab8017b6dde25cb928e82a4b4ca1b17c56cb17fe74b791c97e60

See more details on using hashes here.

File details

Details for the file histomaptx-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: histomaptx-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for histomaptx-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e206bfbc8265640197461b008d7c6d18f1dcce007cecd27e2250e6d98660f930
MD5 01da4cab8663c3ba4586422243c08b23
BLAKE2b-256 fcc2cfaa94ddb51142e0bd84ee2f55e3675e7202774044508e08a017d70f34a3

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