scvi.external.stereoscope.SpatialDeconv#

class scvi.external.stereoscope.SpatialDeconv(n_spots, sc_params, prior_weight='n_obs')[source]#

Bases: BaseModuleClass

Model of single-cell RNA-sequencing data for deconvolution of spatial transriptomics.

Reimplementation of the STModel module of Stereoscope [Andersson20]: https://github.com/almaan/stereoscope/blob/master/stsc/models.py.

Parameters:
n_spots : int

Number of input spots

sc_params : Tuple[ndarray]

Tuple of ndarray of shapes [(n_genes, n_labels), (n_genes)] containing the dictionnary and log dispersion parameters

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

Whether to sample the minibatch by the number of total observations or the monibatch size

Attributes table#

Methods table#

generative(x, ind_x)

Build the deconvolution model for every cell in the minibatch.

get_ct_specific_expression(y)

Returns cell type specific gene expression at the queried spots.

get_proportions([keep_noise])

Returns the loadings.

inference()

Run the inference (recognition) model.

loss(tensors, inference_outputs, ...[, ...])

Compute the loss for a minibatch of data.

sample(tensors[, n_samples, library_size])

Generate samples from the learned model.

Attributes#

T_destination#

SpatialDeconv.T_destination#

alias of TypeVar(‘T_destination’, bound=Mapping[str, Tensor])

alias of TypeVar(‘T_destination’, bound=Mapping[str, Tensor]) .. autoattribute:: SpatialDeconv.T_destination device ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SpatialDeconv.device#

dump_patches#

SpatialDeconv.dump_patches: bool = False#

This allows better BC support for load_state_dict(). In state_dict(), the version number will be saved as in the attribute _metadata of the returned state dict, and thus pickled. _metadata is a dictionary with keys that follow the naming convention of state dict. See _load_from_state_dict on how to use this information in loading.

If new parameters/buffers are added/removed from a module, this number shall be bumped, and the module’s _load_from_state_dict method can compare the version number and do appropriate changes if the state dict is from before the change.

training#

SpatialDeconv.training: bool#

Methods#

generative#

SpatialDeconv.generative(x, ind_x)[source]#

Build the deconvolution model for every cell in the minibatch.

get_ct_specific_expression#

SpatialDeconv.get_ct_specific_expression(y)[source]#

Returns cell type specific gene expression at the queried spots.

Parameters:
y

cell types

get_proportions#

SpatialDeconv.get_proportions(keep_noise=False)[source]#

Returns the loadings.

Return type:

ndarray

inference#

SpatialDeconv.inference()[source]#

Run the inference (recognition) model.

In the case of variational inference, this function will perform steps related to computing variational distribution parameters. In a VAE, this will involve running data through encoder networks.

This function should return a dictionary with str keys and Tensor values.

loss#

SpatialDeconv.loss(tensors, inference_outputs, generative_outputs, kl_weight=1.0, n_obs=1.0)[source]#

Compute the loss for a minibatch of data.

This function uses the outputs of the inference and generative functions to compute a loss. This many optionally include other penalty terms, which should be computed here.

This function should return an object of type LossRecorder.

sample#

SpatialDeconv.sample(tensors, n_samples=1, library_size=1)[source]#

Generate samples from the learned model.