liana.utils.interpolate_adata

liana.utils.interpolate_adata#

liana.utils.interpolate_adata(target, reference, spatial_key, layer=None, use_raw=True, method='linear', fill_value=0, verbose=False)#

Interpolates spatial data from a target AnnData object to a reference AnnData object based on spatial coordinates.

The function creates a new AnnData object where the .X attribute is filled with interpolated data using the specified method.

Parameters:
  • target (AnnData) – The AnnData object to be interpolated.

  • reference (AnnData) – The AnnData object to be used as reference.

  • spatial_key (str) – Key in adata.obsm that contains the spatial coordinates. Default is 'spatial'.

  • layer (str (default: None)) – Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.

  • use_raw (bool (default: True)) – Use raw attribute of adata if present.

  • method (str (default: 'linear')) – Interpolation method. See scipy.interpolate.griddata for more information.

  • fill_value (float (default: 0)) – Value to fill in for points outside of the convex hull of the input points.

  • verbose (bool (default: False)) – Verbosity flag.

Return type:

AnnData

Returns:

AnnData: A new AnnData object with the same metadata as the reference but with interpolated spatial data in .X.

Examples

Brings two spatial modalities measured on different coordinate grids (e.g. metabolomics and transcriptomics of the same slide) onto a shared set of locations. Here a coarser grid stands in for the reference:

>>> import liana as li
>>> target = li.testing.generate_toy_spatial()
>>> reference = target[::2].copy()
>>> interpolated = li.ut.interpolate_adata(target=target,
...                                        reference=reference,
...                                        spatial_key='spatial')