spateo.external.MERFISHVI._model ================================ .. py:module:: spateo.external.MERFISHVI._model Attributes ---------- .. autoapisummary:: spateo.external.MERFISHVI._model.logger Classes ------- .. autoapisummary:: spateo.external.MERFISHVI._model.SpatialVI spateo.external.MERFISHVI._model.MERFISHVI Module Contents --------------- .. py:data:: logger :value: None .. py:class:: 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) Bases: :py:obj:`scvi.model.base.EmbeddingMixin`, :py:obj:`scvi.model.base.RNASeqMixin`, :py:obj:`scvi.model.base.VAEMixin`, :py:obj:`scvi.model.base.ArchesMixin`, :py:obj:`scvi.model.base.UnsupervisedTrainingMixin`, :py:obj:`scvi.model.base.BaseMinifiedModeModelClass` Single-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. :param adata: AnnData object containing single-cell data, which must be registered through the setup_anndata method. :param n_hidden: Number of nodes in hidden layers. :param n_latent: Dimension of the latent space (dimension of low-dimensional representation). :param n_spatial: Dimension of spatial features. Effective when use_spatial=True. :param n_layers: Number of hidden layers in encoder and decoder networks. :param dropout_rate: Ratio of neurons randomly dropped during training. :param 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 :param 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) :param use_observed_lib_size: Whether to use observed library size as scaling factor. :param latent_distribution: Type of latent distribution: * 'normal' - standard normal distribution * 'ln' - logistic normal distribution :param use_spatial: Whether to use spatial information. If True, spatial coordinates will be read from adata.obsm['spatial']. :param spatial_graph_type: Method for spatial graph construction: * 'knn' - K-nearest neighbors graph * 'delaunay' - Delaunay triangulation :param n_neighbors: Number of neighbors for KNN graph when spatial_graph_type='knn'. :param attention_heads: Number of attention heads in graph attention network. :param spatial_kl_weight: Weight for KL divergence of spatial latent variables. :param \*\*kwargs: Additional parameters passed to the VAE module. .. rubric:: 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() .. py:attribute:: _module_cls .. py:attribute:: latent_mean_key :value: 'scvi_latent_qzm' .. py:attribute:: latent_var_key :value: 'scvi_latent_qzv' .. py:attribute:: _module_kwargs .. py:attribute:: _model_summary_string .. py:attribute:: use_spatial :value: False .. py:attribute:: spatial_graph_type :value: 'knn' .. py:attribute:: n_neighbors :value: 10 .. py:attribute:: attention_heads :value: 1 .. py:attribute:: spatial_kl_weight :value: 0.01 .. py:attribute:: edge_index :value: None .. py:attribute:: init_params_ .. py:method:: 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) :classmethod: Set up AnnData object for SpatialVI model training. This method prepares for training by registering necessary data fields. :param adata: AnnData object containing single-cell data :param layer: If provided, use this layer's expression values instead of adata.X :param batch_key: Key in adata.obs representing batch information. If None, assumes all cells are from same batch. :param labels_key: Key in adata.obs representing cell type or other label information :param size_factor_key: Key in adata.obs representing size factor information. Used for normalization. :param categorical_covariate_keys: List of keys in adata.obs representing categorical covariates (like experimental conditions) :param continuous_covariate_keys: List of keys in adata.obs representing continuous covariates (like quality control metrics) .. py:method:: setup_spatial_graph(adata: anndata.AnnData) 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. :param adata: AnnData object containing spatial coordinates in adata.obsm['spatial'] .. py:class:: MERFISHVI(adata_spatial: anndata.AnnData, adata_nonspatial: Optional[anndata.AnnData] = 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) Bases: :py:obj:`SpatialVI` MERFISH 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. :param adata_spatial: AnnData object containing spatial modality data :param adata_nonspatial: AnnData object containing non-spatial modality data, optional :param n_hidden: Number of nodes in hidden layers :param n_latent: Dimension of latent space :param n_spatial: Dimension of spatial features :param n_layers: Number of hidden layers in encoder and decoder networks :param dropout_rate: Dropout rate during training :param dispersion: How to model variance parameters :param gene_likelihood: Distribution used to model gene expression :param latent_distribution: Type of latent distribution :param spatial_graph_type: Spatial graph construction method, 'knn' or 'delaunay' :param n_neighbors: Number of neighbors when spatial_graph_type='knn' :param attention_heads: Number of attention heads in graph attention network :param spatial_kl_weight: Weight for spatial feature KL divergence :param modality_weights: Modality weights to balance contribution of each modality in the loss function :param \*\*kwargs: Additional parameters passed to VAE module .. py:attribute:: adata_nonspatial :value: None .. py:attribute:: modality_weights .. py:attribute:: _module_kwargs .. py:attribute:: _model_summary_string .. py:attribute:: spatial_graph_type :value: 'knn' .. py:attribute:: n_neighbors :value: 10 .. py:attribute:: attention_heads :value: 1 .. py:attribute:: spatial_kl_weight :value: 0.01 .. py:attribute:: edge_index :value: None .. py:attribute:: init_params_ .. py:method:: setup_nonspatial_anndata(adata: anndata.AnnData, **kwargs) :classmethod: Set up non-spatial modality AnnData object. :param adata: Non-spatial modality AnnData object .. py:method:: _create_module() Create model module .. py:method:: get_spatial_representation(adata=None, indices=None, batch_size=None) Get spatial feature representation .. py:method:: get_latent_representation(adata=None, indices=None, batch_size=None, modality='spatial') Get latent representation, can choose from spatial modality, non-spatial modality, or fused representation .. py:method:: get_fused_representation(adata=None, indices=None, batch_size=None) Get fused latent representation