scviva.model.base.SpatialPredictiveMixin#

class scviva.model.base.SpatialPredictiveMixin[source]#

Shared predictive methods for spatial models with neighbor graphs.

Applied to: SCVIVA, ResolVI.

Provides:

  • get_neighbor_abundance: cell-type composition of spatial neighborhoods. Two intentionally different contracts depending on the model:

    • ResolVI (Pyro): uses this mixin default — model-predicted abundance from posterior sampling (PyroSampleMixin.sample_posterior). Honors n_samples / return_mean / weights.

    • SCVIVA (PyTorch): overrides this in its class body to return the observed precomputed niche composition (not a posterior quantity).

  • _get_label_names: shared accessor for cell-type label names from the labels registry (used for DataFrame column labels). Note that a model whose neighbor-composition array is stored in a different column order (e.g. SCVIVA’s observed niche_composition) should keep its own stored columns rather than relabel via this accessor.

Notes

Importance-weighted expression (get_normalized_expression_importance) is not provided here: it requires the Pyro guide and likelihood reweighting, so it lives on ResolVI only. PyTorch models obtain importance weighting via get_normalized_expression(weights="importance") (RNASeqMixin).

Methods table

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

Returns the abundance of cell-types within spatial proximity of center cells.

Methods

SpatialPredictiveMixin.get_neighbor_abundance(adata=None, indices=None, neighbor_key=None, n_samples=1, n_samples_overall=None, batch_size=None, summary_frequency=2, weights=None, return_mean=True, return_numpy=None, **kwargs)[source]#

Returns the abundance of cell-types within spatial proximity of center cells.

Uses Pyro posterior sampling (PyroSampleMixin.sample_posterior). Models without a Pyro module should override this method in their class body.

Parameters:
adata AnnData | None

AnnData object. If None, uses the model’s registered adata.

indices Sequence[int] | None

Cell indices. If None, all cells are used.

neighbor_key str | None

Obsm key containing the spatial neighbors of each cell.

n_samples int

Number of posterior samples.

n_samples_overall int

Number of posterior samples. Overrides n_samples.

batch_size int | None

Minibatch size for data loading.

summary_frequency int

Compute summary after this many batches (reduces memory footprint).

weights str | None

Spatial weights per neighbor. If None, no spatial weighting is applied.

return_mean bool

Return the mean over samples.

return_numpy bool | None

Return ndarray instead of DataFrame.

**kwargs

Additional keyword arguments (ignored, for compatibility).

Return type:

ndarray | DataFrame

Returns:

Cell-type abundance array or DataFrame of shape (n_cells, n_cell_types).