insitucnv-analysis

Detect copy number variations and tumor subclones in Xenium spatial transcriptomics data using infercnvpy.

Updated May 28, 2026
One-click install
npx skills add https://github.com/cpanse/skills --skill insitucnv-analysis-cpanse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: insitucnv-analysis
Source: https://github.com/cpanse/skills/tree/main/single-cell-spatial-general/skills/insitucnv-analysis
Command: npx skills add https://github.com/cpanse/skills --skill insitucnv-analysis-cpanse

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires infercnvpy, scanpy, scipy, numpy, matplotlib, pypdfium2.

What problem does it solve? Spatial transcriptomics platforms like Xenium and MERFISH produce per-cell transcript counts too sparse for direct CNV inference, making tumor subclone detection noisy and unreliable without a specialized smoothing and analysis pipeline. ## Core Features & Use Cases - Neighbor-Based Smoothing: Applies the Jensen et al. 2025 InSituCNV k-NN smoothing method before CNV inference, dramatically improving signal quality on sparse spatial data. - R-to-Python-to-R Pipeline: Converts Seurat objects to AnnData, runs infercnvpy with reference-cell baselining, and merges CNV scores and subclone labels back into Seurat. - Subclone & Chromosome-Arm Analysis: Performs melanoma-only re-clustering for intra-tumor heterogeneity and extracts chromosome-arm scores (e.g., chr3 monosomy, chr8q gain in uveal melanoma) with spatial visualization guidance. - Use Case: Given a Xenium uveal melanoma sample with RCTD cell type annotations, run the full pipeline to identify malignant subclones carrying chr3 loss and chr8q gain, then produce spatial CNV maps and an HTML report. ## Quick Start Ask the agent to run InSituCNV CNV inference on your Xenium Seurat object using macrophages as the diploid reference and merge the subclone results back into Seurat.

Frequently Asked Questions about insitucnv-analysis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect CNVs in Xenium spatial transcriptomics data?

Convert your Seurat object to AnnData with genomic positions, apply k-NN neighbor-based smoothing (n_neighbors=100) on normalized counts, then run infercnvpy's infercnv function with a diploid reference cell type. Smoothing is critical because raw spatial counts are too sparse for direct CNV inference.

What is the difference between infercnvpy and SCEVAN for CNV analysis?

infercnvpy with neighbor-based smoothing is designed for spatial transcriptomics like Xenium where per-cell counts are sparse. SCEVAN is better suited for droplet-based scRNA-seq data and is handled by a separate analysis approach.

Why does CNV clustering only find one melanoma cluster?

Stale neighbors and PCA from the smoothing step are silently reused by cnv.pp.neighbors, collapsing melanoma cells into one group. Delete all neighbors, pca, and obsp keys from the melanoma subset, then recompute PCA and neighbors on X_cnv before leiden clustering.

Which reference cells should I use for infercnvpy CNV baseline?

Use cells expected to be diploid: macrophages or T cells for melanoma, fibroblasts or endothelial cells for carcinoma. Aim for more than 500 reference cells per sample and verify they are not contaminated with tumor cells.

Why does infercnvpy fail with a chromosome unpacking error?

The error occurs when chromosome names in adata.var lack the 'chr' prefix. Ensure adata.var['chromosome'] uses the format 'chr1', 'chr2', etc., and is stored as a categorical before running infercnv.

How much memory does spatial CNV inference need on a cluster?

Approximately 128GB for 15k cells, 256GB for 50k cells, and 512GB for over 100k cells, using 16 CPUs. Also exclude nodes with old libstdc++ to avoid CXXABI incompatibilities with numba and llvmlite.