omicverse.space.map_spatial_manual

omicverse.space.map_spatial_manual#

omicverse.space.map_spatial_manual(adata_rotated, offset, spatial_key='spatial', key_added='spatial1', offset_mode='legacy', library_id=None, library_key=None)[source]#

Manually adjust spatial transcriptomics data alignment.

This function allows manual adjustment of the alignment between spatial transcriptomics data and the tissue image using specified offsets.

Parameters:
  • adata_rotated – AnnData Annotated data matrix containing spatial data to be aligned.

  • offset – tuple (dx, dy) tuple specifying the manual offset to apply.

  • spatial_key (default: 'spatial') – str, default=’spatial’ Coordinate matrix to translate.

  • key_added (default: 'spatial1') – str, default=’spatial1’ Coordinate key receiving the translated floating-point values.

  • offset_mode (default: 'legacy') – {‘legacy’, ‘absolute’}, default=’legacy’ 'legacy' preserves the historical mean/max-scaled subtraction behavior. 'absolute' applies (dx, dy) directly in the coordinate units, with positive values moving right and down.

  • library_id (default: None) – str or None Spatial library to translate. Required together with library_key for multi-library objects.

  • library_key (default: None) – str or None Observation column identifying library membership. Only observations matching library_id are translated.

Returns:

AnnData

Aligned AnnData object with manually adjusted spatial coordinates.

Notes

  • Useful for fine-tuning automatic alignment results

  • In offset_mode='absolute', offsets use the coordinate units.

  • Positive absolute dx moves spots right; positive dy moves spots down.

Examples

>>> import scanpy as sc
>>> import omicverse as ov
>>> # Load data
>>> adata = sc.read_visium(...)
>>> # Apply manual offset
>>> adata_aligned = ov.space.map_spatial_manual(
...     adata,
...     offset=(10, -5),  # Move 10 pixels right, 5 pixels up
...     offset_mode='absolute'
... )