Skill: scRNA-seq Integration
Use When
- User has multiple samples or batches and wants to correct batch effects before clustering and cell type annotation.
- User wants to build a joint embedding from datasets generated at different times, labs, or with different protocols.
- User needs to assess integration quality with quantitative metrics.
- User wants to compare integration methods for a given dataset.
Inputs
- Required:
- Multiple AnnData (.h5ad) or Seurat objects (.rds), one per sample or batch, or a single concatenated object with a batch/sample label column
- Optional:
- Framework:
scanpyorseurat(default:scanpy) - Integration method:
harmony,seurat-cca,seurat-rpca, orscvi(default:harmony) - Batch variable column name (default:
batch) - Number of HVGs (default: 3000)
- Number of PCs for integration (default: 30)
- Number of Harmony iterations (default: 10)
- scVI latent dimensions (default: 20)
- Clustering resolution after integration (default: 0.5)
- Framework:
Workflow
- Load all sample objects and concatenate into a single AnnData or Seurat object, adding a
batch(orsample) column to obs/metadata. - Run per-sample normalization (log1p or SCTransform) using identical parameters across all samples. Do not normalize again after concatenation.
- Select HVGs using batch-aware selection: compute HVGs per batch and take the union of the top genes appearing in most batches (
sc.pp.highly_variable_geneswithbatch_keyparameter). - Run PCA on the unintegrated data; plot a UMAP to visualize the extent of batch effects before integration.
- Run the selected integration method:
- Harmony: run
sc.external.pp.harmony_integrate(Scanpy) orRunHarmony(Seurat) on the PCA embedding. Harmony corrects only the PCA coordinates; raw counts remain unchanged. - Seurat CCA: run
FindIntegrationAnchorswithreduction = "cca"thenIntegrateData; produces a corrected expression matrix. - Seurat RPCA: run
FindIntegrationAnchorswithreduction = "rpca"thenIntegrateData; faster than CCA for large datasets. - scVI: train a variational autoencoder using
scvi.model.SCVIwith the batch key; extract latent representation (20 dimensions) as the integrated embedding.
- Harmony: run
- Compute the kNN graph and Leiden/Louvain clusters on the integrated embedding.
- Compute UMAP on the integrated embedding. Plot UMAP colored by batch/sample (to confirm mixing) and by cluster (to confirm biological signal is preserved).
- Assess integration quality:
- LISI score (Local Inverse Simpson's Index): higher batch LISI = better mixing; higher biological LISI = preserved biology.
- kBET (k-nearest neighbor batch effect test): fraction of cells with well-mixed neighborhoods.
- Silhouette score: positive for biological clusters, near-zero for batch.
- Save integrated AnnData (.h5ad) or Seurat object (.rds) with the integrated embedding and cluster labels.
Output Contract
- Integrated AnnData (.h5ad) or Seurat object (.rds) with integrated embedding (
X_pca_harmony,X_scVI, or equivalent) and cluster labels - UMAP plots before and after integration, colored by batch and cluster (PDF)
- Integration quality metrics table (TSV): LISI (batch), LISI (bio), kBET acceptance rate, silhouette score
- Per-sample cell count summary table (TSV): sample, n_cells, n_clusters
Limits
- Harmony corrects only the PCA embedding; do not use Harmony-corrected PCA coordinates as a substitute for corrected expression values in differential expression.
- scVI requires GPU for practical runtime on large datasets (>100k cells); training on CPU can take many hours.
- Over-integration can merge biologically distinct cell types with similar transcriptomes (e.g., tissue macrophages and circulating monocytes); always validate cluster identity with canonical markers after integration.
- Different integration methods may produce meaningfully different results; Harmony is the recommended starting point due to speed and reliability. Escalate to scVI if Harmony leaves visible batch structure.
- Datasets with very different protocols (e.g., 10x v2 vs v3, or FACS-sorted vs droplet) may require protocol-specific covariates in addition to the batch variable.
- Common failure cases:
- Harmony not converging (LISI not improving after iterations); check that the batch variable has more than one level and that HVG selection used
batch_key. - scVI training producing NaN loss; reduce learning rate or check for cells with zero counts after filtering.
- Seurat CCA failing on very large datasets (>500k cells) due to memory; switch to RPCA or scVI.
- Harmony not converging (LISI not improving after iterations); check that the batch variable has more than one level and that HVG selection used
微信扫一扫