agentleFS
Scientific-ToolingScientific-Tooling/structured-intelligence/skills/scrnaseq-integration/SKILL.md

scrnaseq-integration

Skill4 starsChanged 12 days agoMITView on GitHub

Multi-sample batch correction and integration of single-cell RNA-seq datasets using Harmony, Seurat CCA/RPCA, or scVI.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run per-sample normalization (log1p or SCTransform) using identical parameters across all samples.

    line 32
  2. Distinctive:

    Run PCA on the unintegrated data.

    line 34
  3. Distinctive:

    Run the selected integration method:

    line 35
  4. Very specific:

    Harmony: run sc.external.pp.harmony_integrate (Scanpy) or RunHarmony (Seurat) on the PCA embedding.

    line 36
  5. Very specific:

    Seurat CCA: run FindIntegrationAnchors with reduction = "cca" then IntegrateData.

    line 37
  6. Very specific:

    Seurat RPCA: run FindIntegrationAnchors with reduction = "rpca" then IntegrateData.

    line 38

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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: scanpy or seurat (default: scanpy)
    • Integration method: harmony, seurat-cca, seurat-rpca, or scvi (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)

Workflow

  1. Load all sample objects and concatenate into a single AnnData or Seurat object, adding a batch (or sample) column to obs/metadata.
  2. Run per-sample normalization (log1p or SCTransform) using identical parameters across all samples. Do not normalize again after concatenation.
  3. 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_genes with batch_key parameter).
  4. Run PCA on the unintegrated data; plot a UMAP to visualize the extent of batch effects before integration.
  5. Run the selected integration method:
    • Harmony: run sc.external.pp.harmony_integrate (Scanpy) or RunHarmony (Seurat) on the PCA embedding. Harmony corrects only the PCA coordinates; raw counts remain unchanged.
    • Seurat CCA: run FindIntegrationAnchors with reduction = "cca" then IntegrateData; produces a corrected expression matrix.
    • Seurat RPCA: run FindIntegrationAnchors with reduction = "rpca" then IntegrateData; faster than CCA for large datasets.
    • scVI: train a variational autoencoder using scvi.model.SCVI with the batch key; extract latent representation (20 dimensions) as the integrated embedding.
  6. Compute the kNN graph and Leiden/Louvain clusters on the integrated embedding.
  7. Compute UMAP on the integrated embedding. Plot UMAP colored by batch/sample (to confirm mixing) and by cluster (to confirm biological signal is preserved).
  8. 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.
  9. 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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.