Understanding Neighborhood Enrichment Analysis with Squidpy
A beginner-friendly walkthrough of neighborhood enrichment analysis in spatial transcriptomics using Python’s Squidpy library.
Spatial Transcriptomics
Xenium
Author
Axel R
Published
September 11, 2025
Work in progress
This site is stll under development, so you may notice that some parts are not fully polished yet. Thanks for your patience and feel free to check back soon for updates!
1 What is this notebook about?
Spatial transcriptomics is a powerful way to study how cells are organized and interact within tissues. One of the most popular Python libraries for this kind of analysis is Squidpy(see the original paper here). Squidpy comes with many tools for exploring and visualizing spatial omics data.
In this guide, we’ll focus on one of its key features: neighborhood enrichment analysis. This method helps us see which cell types are more likely to be close to each other, revealing interesting patterns and possible cell–cell interactions in tissue.
When I first tried Squidpy, I found neighborhood enrichment a bit confusing to interpret. I found it challenging to interpret the output and connect it to biological meaning. This motivated me to write this short guide, where I try to digest what is being done under the hood and how to interpret the results.
I hope you find it useful, and please feel free to share any suggestions or questions in the comments!
Under Output and supplemental files, download the Xenium Output Bundle (we’ll use the full dataset).
Unzip the downloaded file.
Inside the unziped folder, unzip all the .zip files to get everything ready for analysis.
# Load librariesimport spatialdata as sdfrom spatialdata_io import xeniumimport matplotlib.pyplot as pltimport seaborn as snsimport scanpy as scimport squidpy as sq
/home/axel/miniconda3/envs/ne_analysis/lib/python3.12/site-packages/dask/dataframe/__init__.py:31: FutureWarning: The legacy Dask DataFrame implementation is deprecated and will be removed in a future version. Set the configuration option `dataframe.query-planning` to `True` or None to enable the new Dask Dataframe implementation and silence this warning.
warnings.warn(
/home/axel/miniconda3/envs/ne_analysis/lib/python3.12/site-packages/xarray_schema/__init__.py:1: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
from pkg_resources import DistributionNotFound, get_distribution
/home/axel/miniconda3/envs/ne_analysis/lib/python3.12/site-packages/anndata/__init__.py:44: FutureWarning: Importing read_text from `anndata` is deprecated. Import anndata.io.read_text instead.
return module_get_attr_redirect(attr_name, deprecated_mapping=_DEPRECATED)