$npx -y skills add LeonChaoX/qinyan-academic-skills --skill scvi-toolsDeep generative models for single-cell omics. Use when you need probabilistic batch correction (scVI), transfer learning, differential expression with uncertainty, or multi-modal integration (TOTALVI, MultiVI). Best for advanced modeling, batch effects, multimodal data. For stand
| 1 | # scvi-tools |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | scvi-tools is a comprehensive Python framework for probabilistic models in single-cell genomics. Built on PyTorch and PyTorch Lightning, it provides deep generative models using variational inference for analyzing diverse single-cell data modalities. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Use this skill when: |
| 10 | - Analyzing single-cell RNA-seq data (dimensionality reduction, batch correction, integration) |
| 11 | - Working with single-cell ATAC-seq or chromatin accessibility data |
| 12 | - Integrating multimodal data (CITE-seq, multiome, paired/unpaired datasets) |
| 13 | - Analyzing spatial transcriptomics data (deconvolution, spatial mapping) |
| 14 | - Performing differential expression analysis on single-cell data |
| 15 | - Conducting cell type annotation or transfer learning tasks |
| 16 | - Working with specialized single-cell modalities (methylation, cytometry, RNA velocity) |
| 17 | - Building custom probabilistic models for single-cell analysis |
| 18 | |
| 19 | ## Core Capabilities |
| 20 | |
| 21 | scvi-tools provides models organized by data modality: |
| 22 | |
| 23 | ### 1. Single-Cell RNA-seq Analysis |
| 24 | Core models for expression analysis, batch correction, and integration. See `references/models-scrna-seq.md` for: |
| 25 | - **scVI**: Unsupervised dimensionality reduction and batch correction |
| 26 | - **scANVI**: Semi-supervised cell type annotation and integration |
| 27 | - **AUTOZI**: Zero-inflation detection and modeling |
| 28 | - **VeloVI**: RNA velocity analysis |
| 29 | - **contrastiveVI**: Perturbation effect isolation |
| 30 | |
| 31 | ### 2. Chromatin Accessibility (ATAC-seq) |
| 32 | Models for analyzing single-cell chromatin data. See `references/models-atac-seq.md` for: |
| 33 | - **PeakVI**: Peak-based ATAC-seq analysis and integration |
| 34 | - **PoissonVI**: Quantitative fragment count modeling |
| 35 | - **scBasset**: Deep learning approach with motif analysis |
| 36 | |
| 37 | ### 3. Multimodal & Multi-omics Integration |
| 38 | Joint analysis of multiple data types. See `references/models-multimodal.md` for: |
| 39 | - **totalVI**: CITE-seq protein and RNA joint modeling |
| 40 | - **MultiVI**: Paired and unpaired multi-omic integration |
| 41 | - **MrVI**: Multi-resolution cross-sample analysis |
| 42 | |
| 43 | ### 4. Spatial Transcriptomics |
| 44 | Spatially-resolved transcriptomics analysis. See `references/models-spatial.md` for: |
| 45 | - **DestVI**: Multi-resolution spatial deconvolution |
| 46 | - **Stereoscope**: Cell type deconvolution |
| 47 | - **Tangram**: Spatial mapping and integration |
| 48 | - **scVIVA**: Cell-environment relationship analysis |
| 49 | |
| 50 | ### 5. Specialized Modalities |
| 51 | Additional specialized analysis tools. See `references/models-specialized.md` for: |
| 52 | - **MethylVI/MethylANVI**: Single-cell methylation analysis |
| 53 | - **CytoVI**: Flow/mass cytometry batch correction |
| 54 | - **Solo**: Doublet detection |
| 55 | - **CellAssign**: Marker-based cell type annotation |
| 56 | |
| 57 | ## Typical Workflow |
| 58 | |
| 59 | All scvi-tools models follow a consistent API pattern: |
| 60 | |
| 61 | ```python |
| 62 | # 1. Load and preprocess data (AnnData format) |
| 63 | import scvi |
| 64 | import scanpy as sc |
| 65 | |
| 66 | adata = scvi.data.heart_cell_atlas_subsampled() |
| 67 | sc.pp.filter_genes(adata, min_counts=3) |
| 68 | sc.pp.highly_variable_genes(adata, n_top_genes=1200) |
| 69 | |
| 70 | # 2. Register data with model (specify layers, covariates) |
| 71 | scvi.model.SCVI.setup_anndata( |
| 72 | adata, |
| 73 | layer="counts", # Use raw counts, not log-normalized |
| 74 | batch_key="batch", |
| 75 | categorical_covariate_keys=["donor"], |
| 76 | continuous_covariate_keys=["percent_mito"] |
| 77 | ) |
| 78 | |
| 79 | # 3. Create and train model |
| 80 | model = scvi.model.SCVI(adata) |
| 81 | model.train() |
| 82 | |
| 83 | # 4. Extract latent representations and normalized values |
| 84 | latent = model.get_latent_representation() |
| 85 | normalized = model.get_normalized_expression(library_size=1e4) |
| 86 | |
| 87 | # 5. Store in AnnData for downstream analysis |
| 88 | adata.obsm["X_scVI"] = latent |
| 89 | adata.layers["scvi_normalized"] = normalized |
| 90 | |
| 91 | # 6. Downstream analysis with scanpy |
| 92 | sc.pp.neighbors(adata, use_rep="X_scVI") |
| 93 | sc.tl.umap(adata) |
| 94 | sc.tl.leiden(adata) |
| 95 | ``` |
| 96 | |
| 97 | **Key Design Principles:** |
| 98 | - **Raw counts required**: Models expect unnormalized count data for optimal performance |
| 99 | - **Unified API**: Consistent interface across all models (setup → train → extract) |
| 100 | - **AnnData-centric**: Seamless integration with the scanpy ecosystem |
| 101 | - **GPU acceleration**: Automatic utilization of available GPUs |
| 102 | - **Batch correction**: Handle technical variation through covariate registration |
| 103 | |
| 104 | ## Common Analysis Tasks |
| 105 | |
| 106 | ### Differential Expression |
| 107 | Probabilistic DE analysis using the learned generative models: |
| 108 | |
| 109 | ```python |
| 110 | de_results = model.differential_expression( |
| 111 | groupby="cell_type", |
| 112 | group1="TypeA", |
| 113 | group2="TypeB", |
| 114 | mode="change", # Use composite hypothesis testing |
| 115 | delta=0.25 # Minimum effect size threshold |
| 116 | ) |
| 117 | ``` |
| 118 | |
| 119 | See `references/differential-expression.md` for detailed methodology and interpretation. |
| 120 | |
| 121 | ### Mode |