scvi-tools by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill scvi-toolsscvi-tools 是一个用于单细胞基因组学概率模型的综合性 Python 框架。它基于 PyTorch 和 PyTorch Lightning 构建,利用变分推断提供深度生成模型,用于分析多种单细胞数据模态。
在以下情况下使用此技能:
scvi-tools 提供按数据模态组织的模型:
用于表达分析、批次校正和整合的核心模型。参见 references/models-scrna-seq.md 了解:
用于分析单细胞染色质数据的模型。参见 references/models-atac-seq.md 了解:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
多种数据类型的联合分析。参见 references/models-multimodal.md 了解:
空间分辨转录组学分析。参见 references/models-spatial.md 了解:
额外的专门分析工具。参见 references/models-specialized.md 了解:
所有 scvi-tools 模型都遵循一致的 API 模式:
# 1. 加载和预处理数据(AnnData 格式)
import scvi
import scanpy as sc
adata = scvi.data.heart_cell_atlas_subsampled()
sc.pp.filter_genes(adata, min_counts=3)
sc.pp.highly_variable_genes(adata, n_top_genes=1200)
# 2. 向模型注册数据(指定图层、协变量)
scvi.model.SCVI.setup_anndata(
adata,
layer="counts", # 使用原始计数,而非对数标准化后的数据
batch_key="batch",
categorical_covariate_keys=["donor"],
continuous_covariate_keys=["percent_mito"]
)
# 3. 创建并训练模型
model = scvi.model.SCVI(adata)
model.train()
# 4. 提取潜在表示和标准化值
latent = model.get_latent_representation()
normalized = model.get_normalized_expression(library_size=1e4)
# 5. 存储在 AnnData 中以供下游分析
adata.obsm["X_scVI"] = latent
adata.layers["scvi_normalized"] = normalized
# 6. 使用 scanpy 进行下游分析
sc.pp.neighbors(adata, use_rep="X_scVI")
sc.tl.umap(adata)
sc.tl.leiden(adata)
关键设计原则:
使用学习到的生成模型进行概率性差异表达分析:
de_results = model.differential_expression(
groupby="cell_type",
group1="TypeA",
group2="TypeB",
mode="change", # 使用复合假设检验
delta=0.25 # 最小效应大小阈值
)
有关详细方法和解释,请参见 references/differential-expression.md。
保存和加载训练好的模型:
# 保存模型
model.save("./model_directory", overwrite=True)
# 加载模型
model = scvi.model.SCVI.load("./model_directory", adata=adata)
跨批次或研究整合数据集:
# 注册批次信息
scvi.model.SCVI.setup_anndata(adata, batch_key="study")
# 模型自动学习批次校正后的表示
model = scvi.model.SCVI(adata)
model.train()
latent = model.get_latent_representation() # 批次校正后的
scvi-tools 基于以下理论构建:
有关数学框架的详细背景,请参见 references/theoretical-foundations.md。
references/workflows.md 包含常见工作流程、最佳实践、超参数调优和 GPU 优化references/ 目录中每个模型类别的详细文档uv pip install scvi-tools
# 如需 GPU 支持
uv pip install scvi-tools[cuda]
min_counts=3)setup_anndata 中包含已知的技术因素(批次、供体等)accelerator="gpu")每周安装量
145
代码仓库
GitHub 星标数
23.4K
首次出现
2026年1月21日
安全审计
安装于
claude-code129
opencode120
gemini-cli115
cursor115
antigravity107
codex104
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.
Use this skill when:
scvi-tools provides models organized by data modality:
Core models for expression analysis, batch correction, and integration. See references/models-scrna-seq.md for:
Models for analyzing single-cell chromatin data. See references/models-atac-seq.md for:
Joint analysis of multiple data types. See references/models-multimodal.md for:
Spatially-resolved transcriptomics analysis. See references/models-spatial.md for:
Additional specialized analysis tools. See references/models-specialized.md for:
All scvi-tools models follow a consistent API pattern:
# 1. Load and preprocess data (AnnData format)
import scvi
import scanpy as sc
adata = scvi.data.heart_cell_atlas_subsampled()
sc.pp.filter_genes(adata, min_counts=3)
sc.pp.highly_variable_genes(adata, n_top_genes=1200)
# 2. Register data with model (specify layers, covariates)
scvi.model.SCVI.setup_anndata(
adata,
layer="counts", # Use raw counts, not log-normalized
batch_key="batch",
categorical_covariate_keys=["donor"],
continuous_covariate_keys=["percent_mito"]
)
# 3. Create and train model
model = scvi.model.SCVI(adata)
model.train()
# 4. Extract latent representations and normalized values
latent = model.get_latent_representation()
normalized = model.get_normalized_expression(library_size=1e4)
# 5. Store in AnnData for downstream analysis
adata.obsm["X_scVI"] = latent
adata.layers["scvi_normalized"] = normalized
# 6. Downstream analysis with scanpy
sc.pp.neighbors(adata, use_rep="X_scVI")
sc.tl.umap(adata)
sc.tl.leiden(adata)
Key Design Principles:
Probabilistic DE analysis using the learned generative models:
de_results = model.differential_expression(
groupby="cell_type",
group1="TypeA",
group2="TypeB",
mode="change", # Use composite hypothesis testing
delta=0.25 # Minimum effect size threshold
)
See references/differential-expression.md for detailed methodology and interpretation.
Save and load trained models:
# Save model
model.save("./model_directory", overwrite=True)
# Load model
model = scvi.model.SCVI.load("./model_directory", adata=adata)
Integrate datasets across batches or studies:
# Register batch information
scvi.model.SCVI.setup_anndata(adata, batch_key="study")
# Model automatically learns batch-corrected representations
model = scvi.model.SCVI(adata)
model.train()
latent = model.get_latent_representation() # Batch-corrected
scvi-tools is built on:
See references/theoretical-foundations.md for detailed background on the mathematical framework.
references/workflows.md contains common workflows, best practices, hyperparameter tuning, and GPU optimizationreferences/ directoryuv pip install scvi-tools
# For GPU support
uv pip install scvi-tools[cuda]
min_counts=3)setup_anndataaccelerator="gpu")Weekly Installs
145
Repository
GitHub Stars
23.4K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
claude-code129
opencode120
gemini-cli115
cursor115
antigravity107
codex104
超能力技能使用指南:AI助手技能调用优先级与工作流程详解
52,100 周安装