spateo.tools.spatial_impute.impute
#
Denoising and imputation of sparse spatial transcriptomics data
Note that this functionality requires PyTorch >= 1.8.0 Also note that this provides an alternative method for finding spatial domains (not yet fully implemented)
Module Contents#
Classes#
Functions#
|
Given counts matrix in tensor form, return counts matrix with scrambled rows/spot names |
|
From AnnData object, get counts matrix, augment it and store both as .obsm entries |
|
Set seeds for all random number generators using 'seed' parameter (defaults to 888) |
|
Creates array with 1 and 0 labels for each spot- for contrastive learning |
- spateo.tools.spatial_impute.impute.permutation(feature: torch.FloatTensor) torch.Tensor [source]#
Given counts matrix in tensor form, return counts matrix with scrambled rows/spot names
- spateo.tools.spatial_impute.impute.get_aug_feature(adata: anndata.AnnData, highly_variable: bool = False)[source]#
From AnnData object, get counts matrix, augment it and store both as .obsm entries
- Parameters
- adata
Source AnnData object
- highly_variable
Set True to subset to highly-variable genes
- spateo.tools.spatial_impute.impute.fix_seed(seed: int = 888)[source]#
Set seeds for all random number generators using ‘seed’ parameter (defaults to 888)
- spateo.tools.spatial_impute.impute.add_contrastive_label(adata)[source]#
Creates array with 1 and 0 labels for each spot- for contrastive learning
- class spateo.tools.spatial_impute.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
- class spateo.tools.spatial_impute.impute.Trainer(adata: anndata.AnnData, device: torch.device, learn_rate: float = 0.001, dropout: float = 0.0, act=F.relu, clip: Union[None, float] = 0.25, weight_decay: float = 0.0, epochs: int = 1000, dim_output: int = 64, alpha: float = 10, beta: float = 1, theta: float = 0.1, add_regularization: bool = False)[source]#
Graph neural network training module.
- Parameters
- adata
class anndata.AnnData
- device
torch.device object
- learn_rate
Controls magnitude of gradient for network learning
- dropout
Proportion of weights in each layer to set to 0
- act
String specifying activation function for each encoder layer. Options: “linear”, “sigmoid”, “tanh”, “relu”, “elu”
- clip
Threshold below which imputed feature values will be set to 0, as a percentile
- weight_decay
Controls degradation rate of parameters
- epochs
Number of iterations of training loop to perform
- dim_output
Dimensionality of the output representation
- alpha
Controls influence of reconstruction loss in representation learning
- beta
Weight factor to control the influence of contrastive loss in representation learning
- theta
Weight factor to control the influence of the regularization term in representation learning
- add_regularization
Adds penalty term to representation learning