spatialvi.external.scVIVA#

class spatialvi.external.scVIVA(adata, n_hidden=128, n_latent=10, n_layers=1, dropout_rate=0.1, **kwargs)[source]#

Bases: object

Wrapper for scvi-tools scVIVA model.

scVIVA models cellular microenvironments by learning niche-aware representations that capture both cell-intrinsic and neighborhood-specific factors.

This is a thin wrapper around the scvi-tools implementation that provides a consistent interface with spatialvi-tools.

Parameters:
  • adata (AnnData) – AnnData object that has been registered via setup_anndata().

  • n_hidden (int) – Number of nodes per hidden layer.

  • n_latent (int) – Dimensionality of the latent space.

  • n_layers (int) – Number of hidden layers.

  • dropout_rate (float) – Dropout rate for neural networks.

  • **kwargs – Additional keyword arguments for scvi.external.SCVIVA.

  • adata (AnnData)

  • n_hidden (int)

  • n_latent (int)

  • n_layers (int)

  • dropout_rate (float)

Examples

>>> import spatialvi
>>> adata = spatialvi.data.synthetic_spatial()
>>> scVIVA.setup_anndata(adata, spatial_key="spatial")
>>> model = scVIVA(adata)
>>> model.train()
>>> niche_effects = model.get_niche_effects()
__init__(adata, n_hidden=128, n_latent=10, n_layers=1, dropout_rate=0.1, **kwargs)[source]#
Parameters:

Methods

__init__(adata[, n_hidden, n_latent, ...])

differential_niche_expression(groupby, group1)

Perform niche-aware differential expression.

get_latent_representation([adata, indices, ...])

Get latent representation.

get_niche_effects([adata, indices, batch_size])

Get niche effects for each cell.

load(dir_path[, adata])

Load model from disk.

save(dir_path, **kwargs)

Save model to disk.

setup_anndata(adata[, layer, batch_key, ...])

Setup AnnData for scVIVA.

train([max_epochs, lr, accelerator, devices])

Train the model.

classmethod setup_anndata(adata, layer=None, batch_key=None, labels_key=None, spatial_key='spatial', **kwargs)[source]#

Setup AnnData for scVIVA.

Parameters:
  • adata (AnnData) – AnnData object.

  • layer (str | None) – Layer to use for expression data.

  • batch_key (str | None) – Key for batch information in obs.

  • labels_key (str | None) – Key for cell type labels in obs.

  • spatial_key (str) – Key for spatial coordinates in obsm.

  • **kwargs – Additional keyword arguments.

  • adata (AnnData)

  • layer (str | None)

  • batch_key (str | None)

  • labels_key (str | None)

  • spatial_key (str)

Return type:

None

train(max_epochs=400, lr=0.001, accelerator='auto', devices='auto', **kwargs)[source]#

Train the model.

Parameters:
  • max_epochs (int) – Maximum number of epochs.

  • lr (float) – Learning rate.

  • accelerator (str) – Accelerator to use.

  • devices (int | str) – Devices to use.

  • **kwargs – Additional keyword arguments for training.

  • max_epochs (int)

  • lr (float)

  • accelerator (str)

  • devices (int | str)

Return type:

None

get_latent_representation(adata=None, indices=None, give_mean=True, batch_size=None)[source]#

Get latent representation.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

Returns:

Latent representation array.

get_niche_effects(adata=None, indices=None, batch_size=None)[source]#

Get niche effects for each cell.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

Returns:

Niche effects array.

differential_niche_expression(groupby, group1, group2=None, **kwargs)[source]#

Perform niche-aware differential expression.

Parameters:
Return type:

DataFrame

Returns:

DataFrame with DE results.

save(dir_path, **kwargs)[source]#

Save model to disk.

Return type:

None

Parameters:

dir_path (str)

classmethod load(dir_path, adata=None, **kwargs)[source]#

Load model from disk.

Return type:

scVIVA

Parameters: