Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bio-spatial-transcriptomics-spatial-neighbors

БесплатноЗапускает вложенные скриптыНе проверен

Build the spatial neighbor graph that every downstream spatial statistic (Moran's I, neighborhood enrichment, co-occurrence, spatial domains) inherits, using…

lilinjiот lilinji★ 18 звёзд на GitHub

Об этом скилле

Version Compatibility

Reference examples tested with: squidpy 1.4+, scanpy 1.10+, anndata 0.10+, numpy 1.26+

Before using code patterns, verify installed versions match. If versions differ:

  • Python: pip show <package> then help(module.function) to check signatures

If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.

Spatial Neighbor Graphs

"Build a spatial neighbor graph for my tissue" -> Define which cells or spots count as spatial neighbors, encoded as a sparse weights matrix W over adata.obsm['spatial'].

  • Python: squidpy.gr.spatial_neighbors() -> writes adata.obsp['spatial_connectivities'] and adata.obsp['spatial_distances']

The platform-class fork sets the default geometry. Sequencing/capture data on a fixed lattice (Visium hex, Visium HD grid) has a KNOWN adjacency -> use coord_type='grid'. Imaging/in-situ point clouds (Xenium, MERFISH, CosMx) have irregular cell positions -> use coord_type='generic' with Delaunay or kNN. The first question is always which side of the fork the data is on, because it decides whether "neighbor" is a lattice fact or a modeling choice.

Governing Principle

The graph is the model that all spatial statistics inherit. Moran's I, Geary's C, neighborhood enrichment, co-occurrence, and every graph-neural-network spatial-domain method are functions f(expression, W) of the spatial weights matrix W -- the graph is not preprocessing, it is literally an argument to the statistic. Change k from 6 to 30, switch Delaunay to kNN, or row-standardize W instead of leaving it binary, and the Moran's I value, the enrichment z-scores, the SVG ranking, and the domain boundaries all move. The analyst is never measuring "spatial structure"; they are measuring spatial structure as seen through one particular definition of adjacency.

This is the most under-reported researcher degree of freedom in the field, and it has a name geographers settled decades ago: the modifiable areal unit problem -- aggregate or re-adjacency the units and the answer changes. There is no canonical W. The honest workflow therefore does what almost no paper does: build the graph under at least two definitions, rerun the downstream statistic, and report which genes/pairs/domains are graph-robust versus graph-fragile. A result that survives only one graph choice is a result about that graph, not about the tissue.

Two failure directions bound the choice. Too dense a graph (large k, large radius, many rings) over-smooths -- it inflates apparent autocorrelation, washes out local detail, and merges distinct domains into blobs. Too sparse a graph fragments the tissue into disconnected components, flags spurious local outliers, and misses real medium-scale structure. The right density is the one whose downstream conclusion is stable; the specific k is not the deliverable, the stability across k is.

The Graph-Construction Decision

Each family silently assumes something different about the tissue, and that assumption -- not the algorithm -- is what fails.

Graph type Degree behavior Density bias Best when Fails when
Visium hex grid (coord_type='grid', n_rings) Fixed 6 per ring; known lattice None (regular lattice) Visium / capture grids where geometry is fixed and exact A spot is treated as a cell -- it is a 1-10-cell mixture, so spot adjacency mixes deconvolution error with real contact
kNN (coord_type='generic', n_neighs) Constant COUNT k Radius implicitly stretches in sparse regions, connecting distant cells Single-cell platforms (Xenium/MERFISH/CosMx) where fixed degree is wanted Density varies sharply; asymmetric by default (A is B's neighbor but not vice versa)
Fixed-radius (radius=r) Variable -- more neighbors where dense STRONG: dense regions get more neighbors of EVERYTHING -> inflated enrichment that is pure density artifact A real physical interaction range exists (ligand diffusion ~tens of microns) AND density is ~uniform Density gradients; radius set in the wrong coordinate unit
Delaunay (delaunay=True) Variable; parameter-free "who touches whom" Mild Single-cell data wanting a parameter-free contact graph Tissue has gaps/holes/folds -> long spurious edges leap across empty space; needs distance pruning

Three points the naive analyst misses. squidpy.gr.nhood_enrichment builds NO graph of its own -- it consumes whatever graph spatial_neighbors already stored in obsp (and errors if none exists); the Squidpy non-grid default is kNN with n_neighs=6 (delaunay=False), so a published z-score is specific to whichever graph produced it and would change under a different graph -- always know which graph produced the number. kNN is asymmetric; "mutual kNN" (edge only if both cells are in each other's k-set) is more conservative and stops hub cells in dense regions from dominating

Полный SKILL.md на GitHub

Установить bio-spatial-transcriptomics-spatial-neighbors в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/build_spatial_graph.pyusage-guide.md

FAQ

Что делает скилл bio-spatial-transcriptomics-spatial-neighbors?

Build the spatial neighbor graph that every downstream spatial statistic (Moran's I, neighborhood enrichment, co-occurrence, spatial domains) inherits, using Squidpy. Use when choosing the graph type (kNN vs Delaunay vs fixed-radius vs Visium hex grid) and understanding why it silently changes every downstream result; handling variable cell density (kNN fixes neighbor COUNT, fixed-radius fixes physical DISTANCE -- each distorts the other); getting coordinate units right (pixels vs microns; Visium array coords are not distance); pruning Delaunay long edges across tissue gaps; running the graph sensitivity analysis almost nobody runs; and knowing when planar section neighbors misrepresent a 3D tissue.

Как установить скилл bio-spatial-transcriptomics-spatial-neighbors?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bio-spatial-transcriptomics-spatial-neighbors запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить bio-spatial-transcriptomics-spatial-neighbors с