spateo.external.MERFISHVI._model¶
Attributes¶
Classes¶
Module Contents¶
- class spateo.external.MERFISHVI._model.SpatialVI(adata: anndata.AnnData | None = None, n_hidden: int = 128, n_latent: int = 10, n_spatial: int = 10, n_layers: int = 1, dropout_rate: float = 0.1, dispersion: Literal['gene', 'gene-batch', 'gene-label', 'gene-cell'] = 'gene', gene_likelihood: Literal['zinb', 'nb', 'poisson', 'normal'] = 'zinb', use_observed_lib_size: bool = True, latent_distribution: Literal['normal', 'ln'] = 'normal', use_spatial: bool = False, spatial_graph_type: Literal['knn', 'delaunay'] = 'knn', n_neighbors: int = 10, attention_heads: int = 1, spatial_kl_weight: float = 0.01, **kwargs)[source]¶
Bases:
scvi.model.base.EmbeddingMixin,scvi.model.base.RNASeqMixin,scvi.model.base.VAEMixin,scvi.model.base.ArchesMixin,scvi.model.base.UnsupervisedTrainingMixin,scvi.model.base.BaseMinifiedModeModelClassSingle-cell Variational Inference model.
This model uses a variational autoencoder (VAE) to learn low-dimensional representations of single-cell data. It can be used for batch effect correction, differential expression analysis, data imputation, and various other downstream tasks.
- Parameters:
- adata
AnnData object containing single-cell data, which must be registered through the setup_anndata method.
- n_hidden
Number of nodes in hidden layers.
- n_latent
Dimension of the latent space (dimension of low-dimensional representation).
- n_spatial
Dimension of spatial features. Effective when use_spatial=True.
- n_layers
Number of hidden layers in encoder and decoder networks.
- dropout_rate
Ratio of neurons randomly dropped during training.
- dispersion
How to model variance parameters: * ‘gene’ - one parameter per gene * ‘gene-batch’ - different parameters for each gene in each batch * ‘gene-label’ - different parameters for each gene in each label group * ‘gene-cell’ - different parameters for each gene in each cell
- gene_likelihood
Distribution used to model gene expression: * ‘nb’ - negative binomial distribution (for count data with overdispersion) * ‘zinb’ - zero-inflated negative binomial distribution (for sparse count data) * ‘poisson’ - Poisson distribution (for count data) * ‘normal’ - normal distribution (experimental)
- use_observed_lib_size
Whether to use observed library size as scaling factor.
- latent_distribution
Type of latent distribution: * ‘normal’ - standard normal distribution * ‘ln’ - logistic normal distribution
- use_spatial
Whether to use spatial information. If True, spatial coordinates will be read from adata.obsm[‘spatial’].
- spatial_graph_type
Method for spatial graph construction: * ‘knn’ - K-nearest neighbors graph * ‘delaunay’ - Delaunay triangulation
- n_neighbors
Number of neighbors for KNN graph when spatial_graph_type=’knn’.
- attention_heads
Number of attention heads in graph attention network.
- spatial_kl_weight
Weight for KL divergence of spatial latent variables.
- **kwargs
Additional parameters passed to the VAE module.
Examples
>>> import anndata >>> import scvi >>> adata = anndata.read_h5ad("my_data.h5ad") >>> scvi.model.SCVI.setup_anndata(adata, batch_key="batch") >>> model = scvi.model.SCVI(adata, use_spatial=True) >>> model.train() >>> adata.obsm["X_scVI"] = model.get_latent_representation()
- classmethod setup_anndata(adata: anndata.AnnData, layer: str | None = None, batch_key: str | None = None, labels_key: str | None = None, size_factor_key: str | None = None, categorical_covariate_keys: list[str] | None = None, continuous_covariate_keys: list[str] | None = None, **kwargs)[source]¶
Set up AnnData object for SpatialVI model training.
This method prepares for training by registering necessary data fields.
- Parameters:
- adata
AnnData object containing single-cell data
- layer
If provided, use this layer’s expression values instead of adata.X
- batch_key
Key in adata.obs representing batch information. If None, assumes all cells are from same batch.
- labels_key
Key in adata.obs representing cell type or other label information
- size_factor_key
Key in adata.obs representing size factor information. Used for normalization.
- categorical_covariate_keys
List of keys in adata.obs representing categorical covariates (like experimental conditions)
- continuous_covariate_keys
List of keys in adata.obs representing continuous covariates (like quality control metrics)
- setup_spatial_graph(adata: anndata.AnnData)[source]¶
Set up spatial graph for spatial information processing.
Build spatial graph based on spatial coordinates in adata.obsm[‘spatial’], choosing between K-nearest neighbors graph or Delaunay triangulation.
- Parameters:
- adata
AnnData object containing spatial coordinates in adata.obsm[‘spatial’]
- class spateo.external.MERFISHVI._model.MERFISHVI(adata_spatial: anndata.AnnData, adata_nonspatial: anndata.AnnData | None = None, n_hidden: int = 128, n_latent: int = 10, n_spatial: int = 10, n_layers: int = 1, dropout_rate: float = 0.1, dispersion: Literal['gene', 'gene-batch', 'gene-label', 'gene-cell'] = 'gene', gene_likelihood: Literal['zinb', 'nb', 'poisson', 'normal'] = 'zinb', use_observed_lib_size: bool = True, latent_distribution: Literal['normal', 'ln'] = 'normal', spatial_graph_type: Literal['knn', 'delaunay'] = 'knn', n_neighbors: int = 10, attention_heads: int = 1, spatial_kl_weight: float = 0.01, modality_weights: Dict[str, float] = {'spatial': 1.0, 'nonspatial': 1.0}, **kwargs)[source]¶
Bases:
SpatialVIMERFISH spatial multimodal variational inference model.
This model extends SCVI to simultaneously process MERFISH data with spatial information and other modality data (such as scRNA-seq) without spatial information. It uses a shared latent space to jointly model both modalities.
- Parameters:
- adata_spatial
AnnData object containing spatial modality data
- adata_nonspatial
AnnData object containing non-spatial modality data, optional
- n_hidden
Number of nodes in hidden layers
- n_latent
Dimension of latent space
- n_spatial
Dimension of spatial features
- n_layers
Number of hidden layers in encoder and decoder networks
- dropout_rate
Dropout rate during training
- dispersion
How to model variance parameters
- gene_likelihood
Distribution used to model gene expression
- latent_distribution
Type of latent distribution
- spatial_graph_type
Spatial graph construction method, ‘knn’ or ‘delaunay’
- n_neighbors
Number of neighbors when spatial_graph_type=’knn’
- attention_heads
Number of attention heads in graph attention network
- spatial_kl_weight
Weight for spatial feature KL divergence
- modality_weights
Modality weights to balance contribution of each modality in the loss function
- **kwargs
Additional parameters passed to VAE module
- classmethod setup_nonspatial_anndata(adata: anndata.AnnData, **kwargs)[source]¶
Set up non-spatial modality AnnData object.
- Parameters:
- adata
Non-spatial modality AnnData object
- get_spatial_representation(adata=None, indices=None, batch_size=None)[source]¶
Get spatial feature representation