{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-data-analysis-scvi-tools-7522588ef745","title":"Probabilistic Batch Correction for Single-Cell RNA-Seq","summary":"Use scvi-tools to perform probabilistic batch correction, transfer learning, and multimodal integration in scRNA-seq data using deep generative models. The tool provides batch-corrected latent space embeddings suitable for downstream analysis with Scanpy, such as clustering and visualization.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-scvi-tools-7522588ef745","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-scvi-tools-7522588ef745","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-scvi-tools-7522588ef745.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-scvi-tools-7522588ef745\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure raw counts are available in the AnnData object (via `layer=\"counts\"` or `adata.X`), and register covariates like batch and donor using `setup_anndata(...)` before training. The first deliverable is the latent representation stored in `adata.obsm[\"X_scVI\"]`.","instructions":"---\nname: scvi-tools\ndescription: 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).\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n## When to Use\n\nUse **scvi-tools** when you need probabilistic, model-based single-cell analysis beyond standard pipelines (e.g., beyond typical Scanpy workflows), such as:\n\n1. **Batch correction and dataset integration** for scRNA-seq using a probabilistic latent space (e.g., scVI).\n2. **Transfer learning \/ semi-supervised annotation** when you have partial labels or want to map new data onto a reference (e.g., scANVI).\n3. **Uncertainty-aware differential expression** where effect sizes and posterior uncertainty matter (Bayesian DE).\n4. **Multimodal integration** across RNA+protein (CITE-seq) or RNA+ATAC (multiome), including paired\/unpaired settings (e.g., totalVI, MultiVI).\n5. **Specialized modalities** such as ATAC-seq, spatial transcriptomics deconvolution\/mapping, doublet detection, methylation, or RNA velocity.\n\n## Key Features\n\n- **Unified model API**: `setup_anndata(...) \u2192 Model(adata) \u2192 train() \u2192 get_*()` across model families.\n- **Probabilistic latent representations** for integration, denoising, and downstream clustering\/visualization.\n- **Explicit covariate handling** (batch, donor, technical factors) via `setup_anndata`.\n- **Bayesian differential expression** with posterior-based hypothesis testing and effect-size thresholds.\n- **Multi-omics models** for joint learning across modalities (RNA\/protein, RNA\/ATAC; paired or unpaired).\n- **AnnData-first integration** with the Scanpy ecosystem for downstream neighbors\/UMAP\/clustering.\n- **GPU acceleration** via PyTorch (when available).\n\nModel catalogs by modality (for reference):\n- scRNA-seq: `references\/models-scrna-seq.md` (scVI, scANVI, AUTOZI, VeloVI, contrastiveVI, \u2026)\n- ATAC-seq: `references\/models-atac-seq.md` (PeakVI, PoissonVI, scBasset, \u2026)\n- Multimodal: `references\/models-multimodal.md` (totalVI, MultiVI, MrVI, \u2026)\n- Spatial: `references\/models-spatial.md` (DestVI, Stereoscope, Tangram, scVIVA, \u2026)\n- Specialized: `references\/models-specialized.md` (Solo, CellAssign, MethylVI\/MethylANVI, CytoVI, \u2026)\n\n## Dependencies\n\n- `scvi-tools` (latest compatible with your environment)\n- `python>=3.9`\n- `pytorch>=2.0`\n- `pytorch-lightning>=2.0` (or `lightning` depending on scvi-tools version)\n- `anndata>=0.8`\n- `scanpy>=1.9`\n\nInstallation example:\n\n```bash\nuv pip install scvi-tools\n# Optional GPU extras (package extra name may vary by platform\/version)\nuv pip install \"scvi-tools[cuda]\"\n```\n\n## Example Usage\n\nA complete runnable example using **scVI** for batch correction + latent embedding, then Scanpy for neighbors\/UMAP\/clustering:\n\n```python\nimport scanpy as sc\nimport scvi\n\n# 1) Load example data (AnnData)\nadata = scvi.data.heart_cell_atlas_subsampled()\n\n# 2) Minimal preprocessing (keep raw counts available)\nsc.pp.filter_genes(adata, min_counts=3)\nsc.pp.highly_variable_genes(adata, n_top_genes=1200)\n\n# 3) Register AnnData for scVI (raw counts + covariates)\nscvi.model.SCVI.setup_anndata(\n    adata,\n    layer=\"counts\",                 # raw counts layer (not log-normalized)\n    batch_key=\"batch\",              # batch column in adata.obs\n    categorical_covariate_keys=[\"donor\"],\n    continuous_covariate_keys=[\"percent_mito\"],\n)\n\n# 4) Train model\nmodel = scvi.model.SCVI(adata)\nmodel.train()\n\n# 5) Extract outputs\nadata.obsm[\"X_scVI\"] = model.get_latent_representation()\nadata.layers[\"scvi_normalized\"] = model.get_normalized_expression(library_size=1e4)\n\n# 6) Downstream analysis with Scanpy\nsc.pp.neighbors(adata, use_rep=\"X_scVI\")\nsc.tl.umap(adata)\nsc.tl.leiden(adata)\n\n# Optional: uncertainty-aware differential expression\nde = model.differential_expression(\n    groupby=\"cell_type\",\n    group1=\"TypeA\",\n    group2=\"TypeB\",\n    mode=\"change\",\n    delta=0.25,\n)\nprint(de.head())\n```\n\nModel persistence:\n\n```python\nmodel.save(\".\/scvi_model\", overwrite=True)\nmodel2 = scvi.model.SCVI.load(\".\/scvi_model\", adata=adata)\n```\n\n## Implementation Details\n\n- **Core approach**: deep generative modeling with **variational inference** (typically VAE-style architectures) to learn a latent representation and a likelihood model for counts.\n- **Data requirements**: models generally expect **raw counts** (not log-normalized values). Provide counts via `layer=\"counts\"` or ensure `adata.X` contains counts.\n- **Covariate registration**: technical factors (e.g., `batch_key`, donor, QC metrics) are incorporated through `setup_anndata`, enabling the model to learn representations that reduce unwanted variation.\n- **Training loop**: `train()` performs amortized inference using neural networks shared across cells; GPU acceleration is used automatically when configured.\n- **Latent space usage**: `get_latent_representation()` returns batch-corrected embeddings suitable for neighbors\/UMAP\/clustering in Scanpy.\n- **Differential expression**: `differential_expression(...)` performs posterior-based comparisons; parameters like:\n  - `mode=\"change\"`: composite hypothesis testing on changes\n  - `delta`: minimum effect size threshold  \n  help control practical significance and uncertainty-aware decisions.  \n  See `references\/differential-expression.md` for interpretation guidance.\n- **Model selection by modality**: choose the model family based on data type (e.g., scVI\/scANVI for scRNA-seq, totalVI for CITE-seq, MultiVI for RNA+ATAC, DestVI for spatial deconvolution). For details, see the corresponding `references\/models-*.md` files.\n- **Theory background**: variational inference, amortized inference, and probabilistic modeling foundations are summarized in `references\/theoretical-foundations.md`.","use_cases":["Correct batch effects in scRNA-seq data using scVI for probabilistic latent space modeling.","Map new data to a reference dataset using transfer learning with scANVI.","Perform uncertainty-aware differential expression analysis across cell types."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Data%20Analysis\/scvi-tools\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T12:46:41.000000Z","updated_at":"2026-11-24T12:17:13.000000Z","seo_title":"Probabilistic Batch Correction for scRNA-seq","seo_description":"scvi-tools enables probabilistic batch correction and integration for single-cell RNA-seq data using deep generative models.","seo_keywords":["scRNA-seq batch correction","probabilistic single-cell analysis","scVI for batch integration","transfer learning in scRNA-seq","uncertainty-aware differential expression"]}}