scanvi integrate

Integrates a dataset with scANVI using a deep learning model. Requires cell type annotations.

Parameters

batch_key: str Provide a batch key.


labels_key: str Provide a labels key for known cell type annotations.


unlabeled_category: str Value used for unlabeled cells in labels_key used to setup AnnData with scvi.


n_samples_per_label: int Number of subsamples for each label class to sample per epoch. By default, there is no label subsampling.


n_layers: int Number of layers in the neural network.


n_latent: int Dimensionality of the latent space in the neural network.


n_hidden: int Number of nodes per hidden layer.


max_epochs: int Number of epochs to train the neural network.


Web view

scanvi_integrate_screenshot

Python equivalent

!pip install scvi-tools # Install external libraries
import scvi

scvi.model.SCVI.setup_anndata(adata, layer="counts", batch_key="batch")
model = scvi.model.SCVI(adata, n_layers=2, n_latent=30, n_hidden=128, gene_likelihood="nb")

scanvi_model = scvi.model.SCANVI.from_scvi_model(model, adata=adata, labels_key="cell_type", unlabeled_category="unknown")

scanvi_model.train(use_gpu = True, max_epochs=400, n_samples_per_label=100)

SCANVI_LATENT_KEY = "X_scANVI"
adata.obsm[SCANVI_LATENT_KEY] = scanvi_model.get_latent_representation(adata)

SCANVI_MDE_KEY = "X_scANVI_MDE"
adata.obsm[SCANVI_MDE_KEY] = scvi.model.utils.mde(adata.obsm[SCANVI_LATENT_KEY])