liana.pp.interpolate_adata

liana.pp.interpolate_adata#

liana.pp.interpolate_adata(target, reference, spatial_key, layer=None, use_raw=False, 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.

layer str | None (default: None)

Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.

use_raw bool (default: False)

Whether to use the .raw attribute of adata. Defaults to False (uses .X).

method Literal['linear', 'nearest', 'cubic'] (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.ds.generate_toy_spatial()
>>> reference = target[::2].copy()
>>> interpolated = li.pp.interpolate_adata(target=target, reference=reference, spatial_key="spatial")