Loading and aligning MALDI + H&E
Overview
load_and_align is the core function of goatpy. It:
Reads a MALDI imzML dataset and extracts ion images for a list of glycan peaks
Loads an H&E whole-slide image at the MALDI pixel resolution
Finds the best rotation and translation to register the two images using normalised cross-correlation
Builds a
SpatialDataobject with the H&E canvas, MALDI pixels, and optional annotations all in the same coordinate system
Basic usage
import goatpy as gp
sdata = gp.load_and_align(
imzml_path="sample.imzML",
he_path="sample.svs",
)
Parameters
Parameter |
Default |
Description |
|---|---|---|
|
required |
Path to |
|
required |
Path to H&E image. SVS/NDPI require openslide |
|
|
Path to peaks CSV. Uses bundled PEAKS.csv when |
|
|
Path to QuPath GeoJSON annotation export |
|
|
Key for annotations in |
|
|
MALDI pixel size in µm. Auto-read from imzML |
|
|
H&E native pixel size in µm. Auto-read from metadata |
|
|
Degrees between coarse rotation candidates (0–360°) |
|
|
±degrees for fine search around best coarse angle |
|
|
Degree increment for fine search |
|
|
Canvas padding in pixels at registration resolution |
|
|
Upscaling factor for the output H&E canvas |
|
|
Ion images loaded in parallel at once |
Output SpatialData structure
sdata
├── images
│ └── he_image # Full registered H&E canvas (upscaled)
├── shapes
│ ├── pixels # One square polygon per MALDI pixel
│ └── annotations # QuPath annotations (if geojson_path provided)
├── points
│ └── centroids # Centroid of each MALDI pixel
└── tables
└── maldi_adata # AnnData: rows=pixels, cols=m/z peaks
├── X # Ion intensities (n_pixels × n_peaks)
├── obs # x, y, he_x, he_y, MPI columns
├── var # m/z peak labels
└── uns
├── spatial # Scanpy-compatible spatial slot
└── he_transform # Registration parameters and affine matrix
Custom peaks
By default, goatpy uses a bundled list of 121 glycan peaks. To use your own:
sdata = gp.load_and_align(
imzml_path="sample.imzML",
he_path="sample.svs",
peaks_path="my_peaks.csv",
)
The peaks CSV should have one m/z value per line (with a header row), in the same
format as the bundled PEAKS.csv.
Registration quality
The registration score is logged during the run. A score above 0.5 generally indicates
a good registration. If the score is low, try:
Increasing
coarse_rotation_stepresolution (e.g.coarse_rotation_step=5)Adjusting
buffer_pxif the MALDI tissue is near the image edgeExplicitly passing
maldi_pixel_umif the imzML metadata is incorrect