Overview of Squidpy
mainscanpy and anndata, inheriting their modularity and scalability. Squidpy provides specialized analysis tools that utilize spatial coordinates and tissue images to extract biological insights from spatial datasets.repository·main·Indexed 20 days ago
https://github.com/scverse/squidpyA scalable toolkit for the analysis and visualization of spatial molecular data, integrating with the scverse ecosystem (scanpy, anndata). Core capabilities include building spatial neighbor graphs, computing spatial statistics (neighborhood enrichment, co-occurrence, Moran's I), image processing for high-resolution tissue microscopy via scikit-image, and interactive exploration using napari-spatialdata.
scanpy and anndata, inheriting their modularity and scalability. Squidpy provides specialized analysis tools that utilize spatial coordinates and tissue images to extract biological insights from spatial datasets.Squidpy is a toolkit for scalable analysis and visualization of spatial molecular data, built on top of scanpy and anndata. Its core capabilities include:
scikit-image.napari-spatialdata to explore annotated datasets.Squidpy is used for several core spatial biology tasks:
scikit-image.napari-spatialdata for interactive spatial data exploration.Squidpy allows for extensibility through custom graph builders. You can implement or use various builder and postprocessor classes located in squidpy.gr.neighbors to customize how spatial graphs are constructed.
Key Extensibility Components:
GraphBuilder / GraphBuilderCSR: Base classes for building graphs.KNNBuilder, RadiusBuilder, DelaunayBuilder, GridBuilder: Specific builder implementations.GraphPostprocessor: Interface for applying transformations to a graph after construction.DistanceIntervalPostprocessor, PercentilePostprocessor, TransformPostprocessor: Specific postprocessing implementations.Squidpy allows you to implement custom graph construction strategies by subclassing its graph builder base classes. This is useful when you need to use a custom coordinate type, a different sparse-matrix backend, or a specialized nearest-neighbor search algorithm.
There are two primary base classes in squidpy.gr.neighbors:
GraphBuilder: The generic pipeline. Use this for custom coordinate types or non-standard sparse-matrix backends.GraphBuilderCSR: A CSR-specialized builder. Use this if your builder returns scipy.sparse.csr_matrix objects. It allows you to reuse Squidpy's CSR-specific postprocessors, multi-library combination logic (via library_key), and automatic suppression of scipy.sparse.SparseEfficiencyWarning.Both types of builders return two square sparse matrices of shape (n_obs, n_obs):
adj: The connectivity/adjacency matrix (non-zero entries mark edges).dst: The distance matrix for those edges (e.g., Euclidean distance or graph-distance).When subclassing GraphBuilderCSR, both adj and dst must be returned as scipy.sparse.csr_matrix objects.
from squidpy.gr.neighbors import GraphBuilder, GraphBuilderCSRInstall the latest stable version of Squidpy from PyPI using pip. Ensure your environment uses Python version >= 3.11.
pip install squidpySquidpy is recommended for recent Linux or macOS systems with Python ≥3.12. It is also compatible with Windows via WSL. You can install it using pip or conda.
pip install squidpyconda install -c conda-forge squidpySquidpy uses pre-commit to enforce consistent code styles. It is recommended to install it locally to catch issues before pushing to GitHub.
To enable pre-commit locally, run:
pre-commit installIf pre-commit.ci (the GitHub service) makes automatic fixes on your branch, integrate them using:
git pull --rebasepre-commit install
git pull --rebaseSquidpy uses Sphinx for documentation. When contributing new features or use-cases, follow these standards:
myst extension.napoleon extension).sphinx-autodoc-typehints to automatically reference annotated input and output types.sphinxcontrib-bibtex for citations (e.g., {cite:p}palla:22`).intersphinx_mapping in docs/conf.py to enable automatic linking.nitpick_ignore list in docs/conf.py.Squidpy recommends using hatch to manage separate virtual environments for testing and documentation. This prevents dependency conflicts between development tasks.
To interact with environments:
hatch env show -ihatch env create <env_name> (e.g., hatch env create hatch-test.py3.14-stable)hatch env find <env_name>IDE Setup (VS Code):
After finding the path with hatch env find, open the Command Palette (Ctrl+Shift+P), select Python: Select Interpreter, choose Enter Interpreter Path, and paste the path.
Running Tasks:
hatch test (highest supported Python version) or hatch test --all (all supported versions).hatch run docs:build.hatch env show -i
hatch env create hatch-test.py3.14-stable
hatch env find hatch-test.py3.14-stable
hatch test
hatch test --all
hatch run docs:buildYou can build the Squidpy documentation locally using one of the following package managers. After building, you can open the generated HTML in your browser.
### Using Hatch
```bash
hatch run docs:build
hatch run docs:opencd docs
uv run sphinx-build -M html . _build -W
(xdg-)open _build/html/index.htmlsource .venv/bin/activate
cd docs
sphinx-build -M html . _build -W
(xdg-)open _build/html/index.htmlThe original Squidpy napari plugin is deprecated. For interactive visualization within napari, use napari-spatialdata, which provides improved support for the SpatialData ecosystem.
pip install napari-spatialdata