spatialvi.model.DestVI#
- class spatialvi.model.DestVI(st_adata, cell_type_mapping, decoder_state_dict, px_decoder_state_dict, px_r, per_ct_bias, n_hidden, n_latent, n_layers, dropout_decoder, **module_kwargs)[source]#
Multi-resolution deconvolution of Spatial Transcriptomics data (DestVI) [].
Most users will use the alternate constructor (see example).
- Parameters:
st_adata (
AnnData) – spatial transcriptomics AnnData object that has been registered viasetup_anndata().cell_type_mapping (
ndarray) – mapping between numerals and cell type labelsdecoder_state_dict (
OrderedDict) – state_dict from the decoder of the CondSCVI modelpx_decoder_state_dict (
OrderedDict) – state_dict from the px_decoder of the CondSCVI modelpx_r (
tensor) – parameters for the px_r tensor in the CondSCVI modeln_hidden (
int) – Number of nodes per hidden layer.n_latent (
int) – Dimensionality of the latent space.n_layers (
int) – Number of hidden layers used for encoder and decoder NNs.**module_kwargs – Keyword args for
MRDeconv
Examples
>>> sc_adata = anndata.read_h5ad(path_to_scRNA_anndata) >>> scvi.model.CondSCVI.setup_anndata(sc_adata) >>> sc_model = scvi.model.CondSCVI(sc_adata) >>> st_adata = anndata.read_h5ad(path_to_ST_anndata) >>> DestVI.setup_anndata(st_adata) >>> spatial_model = DestVI.from_rna_model(st_adata, sc_model) >>> spatial_model.train(max_epochs=2000) >>> st_adata.obsm["proportions"] = spatial_model.get_proportions(st_adata) >>> gamma = spatial_model.get_gamma(st_adata)
Notes
See further usage examples in the following tutorials:
/tutorials/notebooks/spatial/DestVI_tutorial
/tutorials/notebooks/r/DestVI_in_R
- __init__(st_adata, cell_type_mapping, decoder_state_dict, px_decoder_state_dict, px_r, per_ct_bias, n_hidden, n_latent, n_layers, dropout_decoder, **module_kwargs)[source]#
Methods
__init__(st_adata, cell_type_mapping, ...)convert_legacy_save(dir_path, output_dir_path)Converts a legacy saved model (<v0.15.0) to the updated save format.
data_registry(registry_key)Returns the object in AnnData associated with the key in the data registry.
deregister_manager([adata])Deregisters the
AnnDataManagerinstance associated with adata.differential_abundance(*args, **kwargs)from_rna_model(st_adata, sc_model[, ...])Alternate constructor for exploiting a pre-trained model on a RNA-seq dataset.
from_spatialdata(sdata[, table_key, region])Convenience constructor from a SpatialData object.
get_anndata_manager(adata[, required])Retrieves the
AnnDataManagerfor a given AnnData object.get_expression_for_ct(label[, indices, ...])Return the scaled parameter of the NB for every spot in queried cell types.
get_fine_celltypes(sc_model[, indices, ...])Returns the estimated cell-type specific latent space for the spatial data.
get_from_registry(adata, registry_key)Returns the object in AnnData associated with the key in the data registry.
get_gamma([indices, batch_size, return_numpy])Returns the estimated cell-type specific latent space for the spatial data.
get_latent_representation([adata, indices, ...])Return the latent representation for each cell.
get_normalized_expression(*args, **kwargs)get_proportions([keep_additional, ...])Returns the estimated cell type proportion for the spatial data.
get_proportions_df([adata])Return cell type proportions as a tidy DataFrame.
get_scale_for_ct(label[, indices, batch_size])Return the scaled parameter of the NB for every spot in queried cell types.
get_setup_arg(setup_arg)Returns the string provided to setup of a specific setup_arg.
get_state_registry(registry_key)Returns the state registry for the AnnDataField registered with this instance.
get_var_names([legacy_mudata_format])Variable names of input data.
load(dir_path[, adata, accelerator, device, ...])Instantiate a model from the saved output.
load_registry(dir_path[, prefix])Return the full registry saved with the model.
plot_cell_type_map([adata, cell_type, basis, ax])Plot spatial map of a single cell type's proportion.
plot_spatial_embedding([adata, basis, color])Plot latent embedding overlaid on tissue spatial coordinates.
register_manager(adata_manager)Registers an
AnnDataManagerinstance with this model class.save(dir_path[, prefix, overwrite, ...])Save the state of the model.
setup_anndata(adata[, layer, ...])Sets up the
AnnDataobject for this model.setup_spatialdata(sdata[, table_key, region])Register fields from a SpatialData object.
to_device(device)Move the model to the device.
train([max_epochs, lr, accelerator, ...])Trains the model using MAP inference.
transfer_fields(adata, **kwargs)Transfer fields from a model to an AnnData object.
update_setup_method_args(setup_method_args)Update setup method args.
view_anndata_setup([adata, ...])Print summary of the setup for the initial AnnData or a given AnnData object.
view_registry([hide_state_registries])Prints summary of the registry.
view_setup_args(dir_path[, prefix])Print args used to setup a saved model.
view_setup_method_args()Prints setup kwargs used to produce a given registry.
Attributes
adataData attached to model instance.
adata_managerManager instance associated with self.adata.
deviceThe current device that the module's params are on.
get_normalized_function_nameWhat the get normalized functions name is
historyReturns computed metrics during training.
is_trainedWhether the model has been trained.
registryData attached to model instance.
run_idReturns the run id of the model.
run_nameReturns the run name of the model.
summary_stringSummary string of the model.
test_indicesObservations that are in test set.
train_indicesObservations that are in train set.
validation_indicesObservations that are in validation set.