scvi.external.SpatialStereoscope

class scvi.external.SpatialStereoscope(st_adata, sc_params, cell_type_mapping, prior_weight='n_obs', **model_kwargs)[source]

Reimplementation of Stereoscope [Andersson20] for deconvolution of spatial transcriptomics from single-cell transcriptomics.

https://github.com/almaan/stereoscope.

Parameters
st_adata : AnnDataAnnData

spatial transcriptomics AnnData object that has been registered via setup_anndata().

sc_params : Tuple[ndarray]Tuple[ndarray]

parameters of the model learned from the single-cell RNA seq data for deconvolution.

cell_type_mapping : ndarrayndarray

numpy array mapping for the cell types used in the deconvolution

prior_weight : {‘n_obs’, ‘minibatch’}Literal[‘n_obs’, ‘minibatch’] (default: 'n_obs')

how to reweight the minibatches for stochastic optimization. “n_obs” is the valid procedure, “minibatch” is the procedure implemented in Stereoscope.

**model_kwargs

Keyword args for SpatialDeconv

Examples

>>> sc_adata = anndata.read_h5ad(path_to_sc_anndata)
>>> scvi.data.setup_anndata(sc_adata, labels_key="labels")
>>> sc_model = scvi.external.stereoscope.RNAStereoscope(sc_adata)
>>> sc_model.train()
>>> st_adata = anndata.read_h5ad(path_to_st_anndata)
>>> scvi.data.setup_anndata(st_adata)
>>> stereo = scvi.external.stereoscope.SpatialStereoscope.from_rna_model(st_adata, sc_model)
>>> stereo.train()
>>> st_adata.obsm["deconv"] = stereo.get_proportions()

Notes

See further usage examples in the following tutorials:

  1. Stereoscope applied to left ventricule data

Attributes

device

history

Returns computed metrics during training.

is_trained

test_indices

train_indices

validation_indices

Methods

from_rna_model(st_adata, sc_model[, …])

Alternate constructor for exploiting a pre-trained model on RNA-seq data.

get_proportions([keep_noise])

Returns the estimated cell type proportion for the spatial data.

get_scale_for_ct(y)

Calculate the cell type specific expression.

load(dir_path[, adata, use_gpu])

Instantiate a model from the saved output.

save(dir_path[, overwrite, save_anndata])

Save the state of the model.

to_device(device)

Move model to device.

train([max_epochs, lr, use_gpu, batch_size, …])

Trains the model using MAP inference.