Scvi tools

From aipoch/medical-research-skills · View interactive version

Scvi tools is an AI agent skill from the GitHub repository aipoch/medical-research-skills. 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).

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

When to Use

Use scvi-tools when you need probabilistic, model-based single-cell analysis beyond standard pipelines (e.g., beyond typical Scanpy workflows), such as:

  1. Batch correction and dataset integration for scRNA-seq using a probabilistic latent space (e.g., scVI).
  2. Transfer learning / semi-supervised annotation when you have partial labels or want to map new data onto a reference (e.g., scANVI).
  3. Uncertainty-aware differential expression where effect sizes and posterior uncertainty matter (Bayesian DE).
  4. Multimodal integration across RNA+protein (CITE-seq) or RNA+ATAC (multiome), including paired/unpaired settings (e.g., totalVI, MultiVI).
  5. Specialized modalities such as ATAC-seq, spatial transcriptomics deconvolution/mapping, doublet detection, methylation, or RNA velocity.

Key Features

Model catalogs by modality (for reference):

Dependencies

Installation example:

uv pip install scvi-tools
# Optional GPU extras (package extra name may vary by platform/version)
uv pip install "scvi-tools[cuda]"

Example Usage

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)

Implementation Details

help control practical significance and uncertainty-aware decisions.

See references/differential-expression.md for interpretation guidance.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.