SpatialDE.fit_fast

SpatialDE.fit_fast(adata, genes=None, layer=None, normalized=False, sizefactor_col=None, sparse=None, spatial_key='spatial', kernel_space=None)

Fits Gaussian processes to genes.

This uses the inflexible but fast technique of Svensson et al. (2018). In particular, the kernel lengthscale is not optimized, but must be given beforehand. Multiple kernel functions and lengthscales can be specified, the best-fitting model will be retained. To further improve speed, sparse GPs are used for large (>1000 observations) data sets with inducing points located on a regular grid.

Parameters:
  • adata (AnnData) – The annotated data matrix.

  • genes (Optional[List[str]]) – List of genes to base the analysis on. Defaults to all genes.

  • layer (Optional[str]) – Name of the AnnData object layer to use. By default adata.X is used.

  • normalized (bool) – Whether the data are already normalized to an approximately Gaussian likelihood. If False, they will be normalized using the workflow from Svensson et al, 2018.

  • sizefactor_col (Optional[str]) – Column in adata.obs to be used for normalization. If None, total number of counts per spot will be used.

  • spatial_key (str) – Key in adata.obsm where the spatial coordinates are stored.

  • sparse (Optional[bool]) – Whether to use sparse GPs. Slightly faster on large datasets, but less precise. Defaults to sparse GPs if more than 1000 data points are given.

  • kernel_space (Optional[Dict[str, Union[float, List[float]]]]) –

    Kernels to test against. Dictionary with the name of the kernel function as key and list of lengthscales (if applicable) as values. Currently, three kernel functions are known:

    • SE, the squared exponential kernel \(k(\boldsymbol{x}^{(1)}, \boldsymbol{x}^{(2)}; l) = \exp\left(-\frac{\lVert \boldsymbol{x}^{(1)} - \boldsymbol{x}^{(2)} \rVert}{l^2}\right)\)

    • PER, the periodic kernel \(k(\boldsymbol{x}^{(1)}, \boldsymbol{x}^{(2)}; l) = \cos\left(2 \pi \frac{\sum_i (x^{(1)}_i - x^{(2)}_i)}{l}\right)\)

    • linear, the linear kernel \(k(\boldsymbol{x}^{(1)}, \boldsymbol{x}^{(2)}) = (\boldsymbol{x}^{(1)})^\top \boldsymbol{x}^{(2)}\)

    By default, 5 squared exponential and 5 periodic kernels with lengthscales spanning the range of the data will be used.

Return type:

DataFrame

Returns:

A Pandas DataFrame with the results.