spcoral.pp.clipping_patch

Contents

spcoral.pp.clipping_patch#

spcoral.pp.clipping_patch(adata_omics1, adata_omics2, x_clip=None, y_clip=None, x_num=None, y_num=None, retain_edge=0.1, min_cells=0, use_obsm='spatial')#

Divide the overlapping spatial region of two spatial omics into a grid of patches.

This function computes the overlapping spatial region between two AnnData objects, then tiles it into a regular grid based on either specified patch sizes (x_clip/y_clip) or number of patches (x_num/y_num). For each grid cell, sub-regions are extracted from both datasets. Only patches where both omics have at least min_cells cells are retained. Optional overlapping edges between adjacent patches can be preserved to reduce boundary effects.

Parameters:
  • adata_omics1 (anndata.AnnData) – First spatial omics AnnData object. Must contain spatial coordinates (default in obsm['spatial']) and features (in obsm['feat']).

  • adata_omics2 (anndata.AnnData) – Second spatial omics AnnData object with the same requirements.

  • x_clip (float, optional) – Physical width of each patch along the x-axis (in coordinate units). Takes precedence if provided; otherwise derived from x_num.

  • y_clip (float, optional) – Physical height of each patch along the y-axis.

  • x_num (int, optional) – Desired number of patches along the x-axis. Used to compute x_clip if x_clip is not provided.

  • y_num (int, optional) – Desired number of patches along the y-axis.

  • retain_edge (float, optional (default: 0.1)) – Fraction of patch size to retain as overlap on each side between adjacent patches (range [0, 1)). A value of 0.1 means 10% overlap on each side.

  • min_cells (int, optional (default: 0)) – Minimum number of cells required in a patch for both omics. Patches with fewer cells in either dataset are discarded.

  • use_obsm (str, optional (default: 'spatial')) – Key in .obsm where spatial coordinates are stored.

Returns:

Dictionary containing: - ‘feature_omics1’ : int

Number of features in the first omics dataset.

  • ’feature_omics2’ : int Number of features in the second omics dataset.

  • ’x_clip’ : float Actual patch width used along x.

  • ’y_clip’ : float Actual patch height used along y.

  • ’x_num’ : int Actual number of patches along x.

  • ’y_num’ : int Actual number of patches along y.

  • ’x_retain’ : float Actual overlap length along x.

  • ’y_retain’ : float Actual overlap length along y.

  • ’adata_omics1_clip_dict’ : dict Mapping from patch key "{col}_{row}" to the corresponding sub-AnnData for omics1.

  • ’adata_omics2_clip_dict’ : dict Same as above but for omics2.

Return type:

dict