spateo.tools.spatial_impute#

Submodules#

Package Contents#

Classes#

STGNN

Graph neural network for representation learning of spatial transcriptomics data from only the gene expression

Functions#

impute_and_downsample(→ Tuple[anndata.AnnData, ...)

Smooth gene expression distributions and downsample a spatial sample by selecting representative points from

class spateo.tools.spatial_impute.STGNN(adata: anndata.AnnData, spatial_key: str = 'spatial', random_seed: int = 50, add_regularization: bool = True, device: str = 'cpu')[source]#

Graph neural network for representation learning of spatial transcriptomics data from only the gene expression matrix. Wraps preprocessing and training.

adata: class anndata.AnnData spatial_key: Key in .obsm where x- and y-coordinates are stored random_seed: Sets seed for all random number generators add_regularization: Set True to include weight-based penalty term in representation learning. device: Options: ‘cpu’, ‘cuda:_’. Perform computations on CPU or GPU. If GPU, provide the name of the device to run

computations

train_STGNN(**kwargs)#
Parameters
kwargs

Arguments that can be passed to :class Trainer.

Returns

AnnData object with the smoothed values stored in a layer, either “X_smooth_gcn” or

”X_smooth_gcn_reg”.

Return type

adata_output

spateo.tools.spatial_impute.impute_and_downsample(adata: anndata.AnnData, filter_by_moran: bool = False, spatial_key: str = 'spatial', positive_ratio_cutoff: float = 0.1, imputation: bool = True, n_ds: Optional[int] = None, to_visualize: Union[None, str, List[str]] = None, cmap: str = 'magma', device: str = 'cpu', **kwargs) Tuple[anndata.AnnData, anndata.AnnData][source]#

Smooth gene expression distributions and downsample a spatial sample by selecting representative points from this smoothed slice.

Parameters
adata

AnnData object to model

filter_by_moran

Set True to split - for samples with highly uniform expression patterns, simple spatial smoothing will be used. For samples with localized patterns, graph neural network will be used for smoothing. If False, graph neural network will be applied to all genes.

spatial_key

Only used if ‘filter_by_moran’ is True; key in .obsm where x- and y-coordinates are stored.

positive_ratio_cutoff

Filter condition for genes- each gene must be present in higher than this proportion of the total number of cells to be retained

imputation

Set True to perform imputation. If False, will only downsample.

n_ds

Optional number of cells to downsample to- if not given, will not perform downsampling

kwargs

Additional arguments that can be provided to :func STGNN.train_STGNN. Options for kwargs: - learn_rate: Float, controls magnitude of gradient for network learning - dropout: Float between 0 and 1, proportion of weights in each layer to set to 0 - act: String specifying activation function for each encoder layer. Options: “sigmoid”, “tanh”, “relu”,

”elu”

  • clip: Float between 0 and 1, threshold below which imputed feature values will be set to 0,

    as a percentile. Recommended between 0 and 0.1.

  • weight_decay: Float, controls degradation rate of parameters

  • epochs: Int, number of iterations of training loop to perform

  • dim_output: Int, dimensionality of the output representation

  • alpha: Float, controls influence of reconstruction loss in representation learning

  • beta: Float, weight factor to control the influence of contrastive loss in representation learning

  • theta: Float, weight factor to control the influence of the regularization term in representation learning

  • add_regularization: Bool, adds penalty term to representation learning

Returns

Input AnnData object (optional) adata_rex: (optional) adata: AnnData subsetted down to downsampled buckets.

Return type

adata_orig