← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-spatial-transcriptomics-spatial-neighbors / references / usage-guide.md

Spatial Neighbor Graphs - Usage Guide

Overview

This skill builds the spatial neighbor graph -- the sparse weights matrix W over cell or spot coordinates -- that every downstream spatial statistic inherits. Moran's I, neighborhood enrichment, co-occurrence, and graph-based spatial-domain methods are all functions of W, so the graph is not preprocessing; it is an argument to the statistic. The skill covers choosing the graph type by platform (Visium hex grid vs kNN vs Delaunay vs fixed-radius), handling variable cell density, getting coordinate units right, pruning Delaunay long edges, running the graph sensitivity analysis, and knowing when planar neighbors misrepresent a 3D tissue.

Prerequisites

pip install squidpy scanpy anndata numpy

Quick Start

Tell your AI agent what you want to do: - "Build a spatial neighbor graph for my Visium data" - "Build a Delaunay contact graph for my Xenium cells and prune the long edges" - "Build a kNN spatial graph and check whether my Moran's I result is stable across k" - "Check whether my coordinates are in microns or pixels before I set a radius"

Example Prompts

Choosing the graph

"My data is single-cell-resolution MERFISH. Should I use kNN, Delaunay, or a fixed radius for the neighbor graph, and why does it matter?"

"Build a hexagonal-lattice neighbor graph for my Visium section using the grid geometry."

Density and units

"My tissue has dense lymphoid follicles next to sparse stroma. Will a fixed-radius graph bias my neighborhood enrichment, and what should I use instead?"

"Confirm whether my spatial coordinates are in microns before I set a 30-micron interaction radius."

Robustness

"Rebuild my spatial graph under k=6, 15, 30 and Delaunay, and tell me which of my spatially variable genes are graph-robust."

"My Delaunay graph has edges crossing a necrotic hole. Prune them by maximum edge length."

What the Agent Will Do

  1. Identify the platform class (capture/grid vs imaging point cloud) to set the default geometry.
  2. Confirm the coordinate unit (microns vs pixels) before any distance parameter is used.
  3. Build the graph with the matching coord_type and parameters, storing connectivities and distances under named keys.
  4. Prune Delaunay long edges across tissue gaps where relevant.
  5. Inspect degree distribution and connected components for over-density or fragmentation.
  6. Optionally rebuild under several adjacency definitions and compare the downstream statistic to flag graph-fragile results.

Tips