Claude cho Bio Research: Phân tích single-cell với scvi-tools
scvi-tools là framework deep learning hàng đầu cho phân tích single-cell genomics, cung cấp các mô hình xác suất (probabilistic models) để tích hợp dữ liệu, hiệu chỉnh batch effect, và phân tích đa phương thức. Claude có thể hỗ trợ toàn bộ quy trình — từ chọn mô hình phù hợp đến chạy script và debug lỗi.
Chọn mô hình phù hợp
| Loại dữ liệu | Mô hình | Mục đích chính |
|---|---|---|
| scRNA-seq | scVI | Integration không giám sát, DE, imputation |
| scRNA-seq + labels | scANVI | Label transfer, semi-supervised integration |
| CITE-seq (RNA+protein) | totalVI | Multi-modal integration, protein denoising |
| scATAC-seq | PeakVI | Chromatin accessibility analysis |
| Multiome (RNA+ATAC) | MultiVI | Phân tích đa phương thức kết hợp |
| Spatial + scRNA reference | DestVI | Cell type deconvolution không gian |
| RNA velocity | veloVI | Động học phiên mã |
| Cross-technology | sysVI | Hiệu chỉnh batch giữa các platform |
Prompt để Claude tự động chọn mô hình:
Tôi có dataset single-cell RNA-seq từ 3 batch khác nhau (10X Genomics),
tổng ~50,000 tế bào. Tôi muốn:
1. Tích hợp và hiệu chỉnh batch effect
2. Cluster và visualize trên UMAP
3. Tìm marker genes cho từng cluster
Mô hình nào trong scvi-tools phù hợp nhất?
Yêu cầu kỹ thuật bắt buộc
Trước khi bắt đầu, có 3 yêu cầu kỹ thuật cứng với scvi-tools:
1. Raw counts là bắt buộc
Các mô hình scvi-tools yêu cầu dữ liệu integer count (không phải log-normalized):
import scanpy as sc
import scvi
# LƯU raw counts TRƯỚC khi normalize
adata.layers["counts"] = adata.X.copy()
# Setup với raw counts
scvi.model.SCVI.setup_anndata(adata, layer="counts")
2. Chọn Highly Variable Genes (HVG)
# Chọn 2000-4000 HVGs
sc.pp.highly_variable_genes(
adata,
n_top_genes=2000,
batch_key="batch",
layer="counts",
flavor="seurat_v3"
)
adata = adata[:, adata.var['highly_variable']].copy()
3. Chỉ định batch key
scvi.model.SCVI.setup_anndata(adata, layer="counts", batch_key="batch")
Quy trình scVI cơ bản
Bước 1: Validate và chuẩn bị dữ liệu
python scripts/validate_adata.py raw.h5ad --batch-key batch --suggest
python scripts/prepare_data.py raw.h5ad prepared.h5ad --batch-key batch --n-hvgs 2000
Bước 2: Train mô hình scVI
python scripts/train_model.py prepared.h5ad results/ --model scvi --batch-key batch
Hoặc trực tiếp với Python:
import scvi
scvi.model.SCVI.setup_anndata(adata, layer="counts", batch_key="batch")
model = scvi.model.SCVI(adata, n_layers=2, n_latent=30)
model.train(max_epochs=400)
Bước 3: Cluster và visualize
python scripts/cluster_embed.py results/adata_trained.h5ad results/ --resolution 0.8
Lấy latent representation và tạo UMAP:
import scanpy as sc
adata.obsm["X_scVI"] = model.get_latent_representation()
sc.pp.neighbors(adata, use_rep="X_scVI")
sc.tl.umap(adata)
sc.tl.leiden(adata, resolution=0.8)
sc.pl.umap(adata, color=["leiden", "batch"])
Bước 4: Differential expression
python scripts/differential_expression.py results/model results/adata_clustered.h5ad results/de.csv --groupby leiden
scVI có ưu điểm lớn trong DE analysis: sử dụng posterior distribution thay vì p-value đơn giản, kiểm soát tốt hơn false positives:
de_results = model.differential_expression(
adata,
groupby="leiden",
group1="0",
group2="1"
)
# Lọc genes có lfc_mean > 1 và is_de_fdr_0.05 = True
Label Transfer với scANVI
Khi bạn có dataset tham chiếu đã annotate và muốn transfer nhãn sang dataset mới:
# Bước 1: Train scVI trên reference dataset
scvi.model.SCVI.setup_anndata(ref_adata, layer="counts", batch_key="batch")
vae = scvi.model.SCVI(ref_adata)
vae.train()
# Bước 2: Train scANVI với cell type labels
scanvi_model = scvi.model.SCANVI.from_scvi_model(
vae,
unlabeled_category="Unknown",
labels_key="cell_type"
)
scanvi_model.train(max_epochs=20)
# Bước 3: Transfer labels sang query dataset
scvi.model.SCANVI.prepare_query_anndata(query_adata, scanvi_model)
query_model = scvi.model.SCANVI.load_query_data(query_adata, scanvi_model)
query_model.train(max_epochs=100)
query_adata.obs["predicted_labels"] = query_model.predict()
Phân tích CITE-seq với totalVI
scvi.model.TOTALVI.setup_anndata(
adata,
layer="counts",
protein_expression_obsm_key="protein_expression",
batch_key="batch"
)
model = scvi.model.TOTALVI(adata)
model.train(max_epochs=400)
# Lấy protein denoised values
protein_foreground_prob = model.get_protein_foreground_probability()
Decision tree chọn mô hình nhanh
Prompt để Claude giúp quyết định:
Mô tả dữ liệu:
- Loại: scRNA-seq
- Số tế bào: 80,000
- Số batch: 5 (3 lab khác nhau, 2 protocol khác nhau)
- Có cell type annotations cho 2 batch đầu: Có
- Có thêm protein (CITE-seq): Không
- Mục tiêu: tích hợp tất cả batch, predict cell type cho batch chưa annotate
Hãy đề xuất mô hình tối ưu và pipeline step-by-step.
Xử lý lỗi thường gặp
CUDA out of memory:
# Giảm batch size
model.train(max_epochs=400, batch_size=128) # default 128
# Hoặc train trên CPU
model.train(max_epochs=400, use_gpu=False)
Convergence chậm:
# Tăng learning rate hoặc early stopping
model.train(
max_epochs=400,
early_stopping=True,
early_stopping_patience=20
)
Integration kém (batch effect còn lại):
- Tăng
n_latent(thử 30, 50, 100) - Tăng số HVGs (thử 3000, 4000)
- Cân nhắc sysVI cho batch effect giữa các technology
Bước tiếp theo
Sau khi hoàn thành phân tích scvi-tools, bước tự nhiên tiếp theo là thực hiện QC chất lượng dữ liệu — hoặc nếu bạn đang bắt đầu từ raw data, hãy xem hướng dẫn Single-Cell RNA QC. Khám phá thêm tại bộ sưu tập Ứng dụng.
Bài viết liên quan
Bai viet co huu ich khong?
Bản quyền thuộc về tác giả. Vui lòng dẫn nguồn khi chia sẻ.



