Deep generative models for single-cell omics; use when you need probabilistic batch correction (scVI), transfer learning, uncertainty-aware differential expression, or multimodal integration (totalVI/MultiVI).
72
89%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Use scvi-tools when you need probabilistic, model-based single-cell analysis beyond standard pipelines (e.g., beyond typical Scanpy workflows), such as:
setup_anndata(...) → Model(adata) → train() → get_*() across model families.setup_anndata.Model catalogs by modality (for reference):
references/models-scrna-seq.md (scVI, scANVI, AUTOZI, VeloVI, contrastiveVI, …)references/models-atac-seq.md (PeakVI, PoissonVI, scBasset, …)references/models-multimodal.md (totalVI, MultiVI, MrVI, …)references/models-spatial.md (DestVI, Stereoscope, Tangram, scVIVA, …)references/models-specialized.md (Solo, CellAssign, MethylVI/MethylANVI, CytoVI, …)scvi-tools (latest compatible with your environment)python>=3.9pytorch>=2.0pytorch-lightning>=2.0 (or lightning depending on scvi-tools version)anndata>=0.8scanpy>=1.9Installation example:
uv pip install scvi-tools
# Optional GPU extras (package extra name may vary by platform/version)
uv pip install "scvi-tools[cuda]"A complete runnable example using scVI for batch correction + latent embedding, then Scanpy for neighbors/UMAP/clustering:
import scanpy as sc
import scvi
# 1) Load example data (AnnData)
adata = scvi.data.heart_cell_atlas_subsampled()
# 2) Minimal preprocessing (keep raw counts available)
sc.pp.filter_genes(adata, min_counts=3)
sc.pp.highly_variable_genes(adata, n_top_genes=1200)
# 3) Register AnnData for scVI (raw counts + covariates)
scvi.model.SCVI.setup_anndata(
adata,
layer="counts", # raw counts layer (not log-normalized)
batch_key="batch", # batch column in adata.obs
categorical_covariate_keys=["donor"],
continuous_covariate_keys=["percent_mito"],
)
# 4) Train model
model = scvi.model.SCVI(adata)
model.train()
# 5) Extract outputs
adata.obsm["X_scVI"] = model.get_latent_representation()
adata.layers["scvi_normalized"] = model.get_normalized_expression(library_size=1e4)
# 6) Downstream analysis with Scanpy
sc.pp.neighbors(adata, use_rep="X_scVI")
sc.tl.umap(adata)
sc.tl.leiden(adata)
# Optional: uncertainty-aware differential expression
de = model.differential_expression(
groupby="cell_type",
group1="TypeA",
group2="TypeB",
mode="change",
delta=0.25,
)
print(de.head())Model persistence:
model.save("./scvi_model", overwrite=True)
model2 = scvi.model.SCVI.load("./scvi_model", adata=adata)layer="counts" or ensure adata.X contains counts.batch_key, donor, QC metrics) are incorporated through setup_anndata, enabling the model to learn representations that reduce unwanted variation.train() performs amortized inference using neural networks shared across cells; GPU acceleration is used automatically when configured.get_latent_representation() returns batch-corrected embeddings suitable for neighbors/UMAP/clustering in Scanpy.differential_expression(...) performs posterior-based comparisons; parameters like:
mode="change": composite hypothesis testing on changesdelta: minimum effect size thresholdreferences/differential-expression.md for interpretation guidance.references/models-*.md files.references/theoretical-foundations.md.f5ef65b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.