spatialvi.model.GIMVI

spatialvi.model.GIMVI#

class spatialvi.model.GIMVI(adata_seq, adata_spatial, generative_distributions=None, model_library_size=None, n_latent=10, **model_kwargs)[source]#

Joint VAE for imputing missing genes in spatial data [].

Learns a joint latent space for paired scRNA-seq and spatial transcriptomics data, enabling imputation of spatially unmeasured genes.

Parameters:
  • adata_seq (AnnData) – AnnData object registered via setup_anndata() containing scRNA-seq data.

  • adata_spatial (AnnData) – AnnData object registered via setup_anndata() containing spatial transcriptomics data.

  • generative_distributions (list[str] | None) – List of generative distributions for seq and spatial data. Defaults to ['zinb', 'nb'].

  • model_library_size (list[bool] | None) – Whether to model library size per dataset. Defaults to [True, False].

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

  • **model_kwargs – Keyword args for JVAE.

Examples

>>> adata_seq = anndata.read_h5ad(path_to_seq)
>>> adata_spatial = anndata.read_h5ad(path_to_spatial)
>>> spatialvi.model.GIMVI.setup_anndata(adata_seq)
>>> spatialvi.model.GIMVI.setup_anndata(adata_spatial)
>>> model = spatialvi.model.GIMVI(adata_seq, adata_spatial)
>>> model.train(max_epochs=200)

Notes

See further usage examples in the following tutorial:

  1. /tutorials/notebooks/spatial/gimvi_tutorial

__init__(adata_seq, adata_spatial, generative_distributions=None, model_library_size=None, n_latent=10, **model_kwargs)[source]#

Methods

__init__(adata_seq, adata_spatial[, ...])

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 AnnDataManager instance associated with adata.

differential_abundance(*args, **kwargs)

from_spatialdata(sdata[, table_key, region])

Convenience constructor from a SpatialData object.

get_anndata_manager(adata[, required])

Retrieves the AnnDataManager for a given AnnData object.

get_from_registry(adata, registry_key)

Returns the object in AnnData associated with the key in the data registry.

get_imputed_values([adatas, deterministic, ...])

Return imputed values for all genes for each dataset.

get_latent_representation([adatas, ...])

Return the latent space embedding for each dataset.

get_normalized_expression(*args, **kwargs)

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_seq, adata_spatial, ...])

Instantiate a model from the saved output.

load_registry(dir_path[, prefix])

Return the full registry saved with the model.

plot_spatial_embedding([adata, basis, color])

Plot latent embedding overlaid on tissue spatial coordinates.

register_manager(adata_manager)

Registers an AnnDataManager instance with this model class.

save(dir_path[, prefix, overwrite, ...])

Save the state of the model.

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

Sets up the AnnData object for this model.

setup_spatialdata(sdata[, table_key, region])

Register the spatial adata component from a SpatialData object.

to_device(device)

Move the model to the device.

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

Train the model.

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

adata

Data attached to model instance.

adata_manager

Manager instance associated with self.adata.

device

The current device that the module's params are on.

get_normalized_function_name

What the get normalized functions name is

history

Returns computed metrics during training.

is_trained

Whether the model has been trained.

registry

Data attached to model instance.

run_id

Returns the run id of the model.

run_name

Returns the run name of the model.

summary_string

Summary string of the model.

test_indices

Observations that are in test set.

train_indices

Observations that are in train set.

validation_indices

Observations that are in validation set.