spatialvi.model.ResolVI#
- class spatialvi.model.ResolVI(adata, n_hidden=32, n_hidden_encoder=128, n_latent=10, n_layers=2, dropout_rate=0.05, dispersion='gene', gene_likelihood='nb', background_ratio=None, median_distance=None, semisupervised=False, mixture_k=50, downsample_counts=True, **model_kwargs)[source]#
ResolVI addresses noise and bias in single-cell resolved spatial transcriptomics data.
- Parameters:
adata (
AnnData) – AnnData object that has been registered viasetup_anndata().n_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.dropout_rate (
float) – Dropout rate for neural networks.dispersion (
Literal['gene','gene-batch']) –One of the following:
'gene'- dispersion parameter of NB is constant per gene across cells'gene-batch'- dispersion can differ between different batches
gene_likelihood (
Literal['nb','poisson']) –One of:
'nb'- Negative binomial distribution'poisson'- Poisson distribution
**model_kwargs – Keyword args for
RESOLVAE
Examples
>>> adata = anndata.read_h5ad(path_to_anndata) >>> ResolVI.setup_anndata(adata, batch_key="batch") >>> model = ResolVI(adata) >>> model.train() >>> adata.obsm["X_resolVI"] = model.get_latent_representation() >>> adata.layers["X_normalized_resolVI"] = model.get_normalized_expression()
- __init__(adata, n_hidden=32, n_hidden_encoder=128, n_latent=10, n_layers=2, dropout_rate=0.05, dispersion='gene', gene_likelihood='nb', background_ratio=None, median_distance=None, semisupervised=False, mixture_k=50, downsample_counts=True, **model_kwargs)[source]#
Methods
__init__(adata[, n_hidden, ...])compute_dataset_dependent_priors([n_small_genes])Compute dataset-dependent priors for background ratio and median distance.
compute_neighbors(adata[, spatial_key, ...])Compute spatial neighbor graph and store in
adata.obsm.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)differential_expression([adata, groupby, ...])A unified method for differential expression analysis.
differential_niche_abundance([adata, ...])A unified method for niche differential abundance analysis.
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_from_registry(adata, registry_key)Returns the object in AnnData associated with the key in the data registry.
get_latent_representation([adata, indices, ...])Return latent representation with optional RAPIDS acceleration.
get_neighbor_abundance([adata, indices, ...])Returns the abundance of cell-types within spatial proximity of center cells.
get_normalized_expression([adata, indices, ...])Returns the normalized (decoded) gene expression.
get_normalized_expression_importance([...])Returns the normalized (decoded) importance-sampled gene expression.
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_query_data([adata, reference_model, ...])Online update of a reference model with scArches algorithm [].
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.
predict([adata, indices, soft, batch_size, ...])Return cell label predictions.
prepare_query_anndata(adata, reference_model)Prepare data for query integration.
prepare_query_mudata(mdata, reference_model)Prepare multimodal dataset for query integration.
register_manager(adata_manager)Registers an
AnnDataManagerinstance with this model class.sample_posterior([adata, input_dl, indices, ...])Summarise posterior distribution.
save(dir_path[, prefix, overwrite, ...])Save the state of the model.
setup_anndata(adata[, layer, batch_key, ...])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, lr_extra, ...])Train the model using amortized variational 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.