spatialvi.external.SPARL#
- class spatialvi.external.SPARL(adata, spatial_key='spatial', layer=None, n_latent=32, **model_params)[source]#
Bases:
objectInterface to the SPARL representation learning model.
SPARL learns spatial-aware representations of protein expression data from spatial proteomics technologies.
- Parameters:
adata¶ (
AnnData) – AnnData object containing spatial proteomics data. The main expression matrix (X or a layer) should contain protein measurements. Spatial coordinates should be in obsm.spatial_key¶ (
str) – Key inadata.obsmfor spatial coordinates.layer¶ (
str|None) – Layer inadata.layersto use. If None, usesadata.X.**model_params¶ (
Any) – Additional parameters passed to the SPARL model.adata (AnnData)
spatial_key (str)
layer (str | None)
n_latent (int)
model_params (Any)
Notes
SPARL is distributed separately from spatialvi-tools. To use this wrapper you must install the
sparlpackage.Examples
>>> from spatialvi.external import SPARL >>> # Load CODEX data >>> adata = sc.read("codex_data.h5ad") >>> model = SPARL(adata, n_latent=20) >>> model.train(max_epochs=100) >>> # Get latent representation >>> adata.obsm["X_sparl"] = model.get_latent_representation()
Methods
__init__(adata[, spatial_key, layer, n_latent])get_latent_representation([adata, batch_size])Get latent representations for cells.
impute_proteins([adata, store_layer])Impute missing protein values using the trained model.
predict([adata, store_key])Compute and store latent representations.
reconstruct([adata, batch_size])Reconstruct protein expression from latent space.
train([max_epochs, batch_size, lr])Train the SPARL model.
- train(max_epochs=100, batch_size=128, lr=0.001, **train_kwargs)[source]#
Train the SPARL model.
- Parameters:
- Return type:
Notes
Currently this wrapper provides a placeholder implementation. Full training functionality will be added when the SPARL API stabilizes.
- get_latent_representation(adata=None, batch_size=256)[source]#
Get latent representations for cells.