SpatialQuery.spatial_query.__init__

spatial_query.__init__(adata, dataset='ST', spatial_key='X_spatial', label_key='cell_type', leaf_size=10, build_gene_index=False, feature_name='gene', if_lognorm=True, if_normalize_spatial_coord=True)[source]

Initialize spatial_query object.

Parameters:
  • adata (AnnData) – Annotated data object containing expression matrix and metadata.

  • dataset (str, default='ST') – Dataset identifier.

  • spatial_key (str, default='X_spatial') – Key in adata.obsm containing spatial coordinates (n_obs, 2).

  • label_key (str, default='cell_type') – Key in adata.obs containing cell type annotations.

  • leaf_size (int, default=10) – Leaf size parameter for KDTree construction. Larger values reduce tree depth but increase computation per query.

  • build_gene_index (bool, default=False) – If True, constructs SCFind index by compressing original data to binary format to save memory. If False, uses original expression matrix from adata.X directly.

  • feature_name (str, default='gene') – Column name in adata.var containing feature identifiers.

  • if_lognorm (bool, default=True) – If True, applies log1p transformation after library size normalization. Set to False if expression data is already normalized and no more transformation is required.

  • if_normalize_spatial_coord (bool, default=True) – If True, normalizes spatial coordinates so mean nearest neighbor distance equals 1. This makes max_dist parameter interpretable as “number of cell diameters.” Set to False if original spatial units (e.g., micrometers) are required and should be preserved for downstream analysis.

Notes

When if_normalize_spatial_coord=True, the max_dist parameter in query functions represents relative spatial scale (in units of mean nearest neighbor distance). When if_normalize_spatial_coord=False, max_dist uses original coordinate units.