spateo.tdr.widgets.interpolations#

Module Contents#

Functions#

kernel_interpolation(→ anndata.AnnData)

Learn a continuous mapping from space to gene expression pattern with the Kernel method (sparseVFC).

deep_intepretation(→ anndata.AnnData)

Learn a continuous mapping from space to gene expression pattern with the deep neural net model.

get_X_Y_grid(→ Tuple[numpy.ndarray, numpy.ndarray, ...)

Prepare the X (spatial coordinates), Y (gene expression) and grid points for the kernel or deep model.

spateo.tdr.widgets.interpolations.kernel_interpolation(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, NX: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50], lambda_: float = 0.02, lstsq_method: str = 'scipy', **kwargs) anndata.AnnData[source]#

Learn a continuous mapping from space to gene expression pattern with the Kernel method (sparseVFC).

Parameters
adata

AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.

genes

Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.

X

The spatial coordinates of each data point.

Y

The gene expression of the corresponding data point.

NX

The spatial coordinates of new data point. If NX is None, generate new points based on grid_num.

grid_num

Number of grid to generate. Default is 50 for each dimension. Must be non-negative.

lambda

Represents the trade-off between the goodness of data fit and regularization. Larger Lambda_ put more weights on regularization.

lstsq_method

The name of the linear least square solver, can be either ‘scipy` or douin.

**kwargs

Additional parameters that will be passed to SparseVFC function.

Returns

an anndata object that has interpolated expression. The row of the adata object is a grid point within the convex hull formed by the input data points while each column corresponds a gene whose expression values are interpolated.

Return type

interp_adata

spateo.tdr.widgets.interpolations.deep_intepretation(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, NX: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50], **kwargs) anndata.AnnData[source]#

Learn a continuous mapping from space to gene expression pattern with the deep neural net model.

Parameters
adata

AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.

genes

Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.

X

The spatial coordinates of each data point.

Y

The gene expression of the corresponding data point.

NX

The spatial coordinates of new data point. If NX is None, generate new points based on grid_num.

grid_num

Number of grid to generate. Default is 50 for each dimension. Must be non-negative.

**kwargs

Additional parameters that will be passed to the training step of the deep neural net.

Returns

an anndata object that has interpolated expression. The row of the adata object is a grid point within the convex hull formed by the input data points while each column corresponds a gene whose expression values are interpolated.

Return type

interp_adata

spateo.tdr.widgets.interpolations.get_X_Y_grid(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50]) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#

Prepare the X (spatial coordinates), Y (gene expression) and grid points for the kernel or deep model.

Parameters
adata

AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.

genes

Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.

X

The spatial coordinates of each data point.

Y

The gene expression of the corresponding data point.

grid_num

Number of grid to generate. Default is 50 for each dimension. Must be non-negative.

Returns

spatial coordinates. Y: gene expression of the associated spatial coordinates. Grid: grid points formed with the input spatial coordinates. grid_in_hull: A list of booleans indicates whether the current grid points is within the convex hull formed by

the input data points.

Return type

X