SPAC: A Python Package for Spatial Single-Cell Analysis of Multiplex Imaging

Zhiyuan Liu, Rui He, Andrei Bombin, Ahmad Abdallah, Omar Eldaghar, Tommy R. Sheeley, Sam E. Ying, George ZakiarXiv 2025 · DOI

Abstract

Multiplexed immunofluorescence microscopy captures detailed measurements of spatially resolved, multiple biomarkers simultaneously, revealing tissue composition and cellular interactions in situ among single cells. The growing scale and dimensional complexity of these datasets demand reproducible, comprehensive and user-friendly computational tools. To address this need, we developed SPAC (SPAtial single-Cell analysis), a Python-based package and a corresponding shiny application within an integrated, modular SPAC ecosystem (Liu et al., 2025) designed specifically for biologists without extensive coding expertise. Following image segmentation and extraction of spatially resolved single-cell data, SPAC streamlines downstream phenotyping and spatial analysis, facilitating characterization of cellular heterogeneity and spatial organization within tissues. Through scalable performance, specialized spatial statistics, highly customizable visualizations, and seamless workflows from dataset to insights, SPAC significantly lowers barriers to sophisticated spatial analyses.

Introduction

Multiplexed immunofluorescence microscopy is a powerful technique that allows researchers to measure dozens of protein biomarkers simultaneously within single cells while preserving their exact spatial locations in the tissue. However, this generates massive, high-dimensional datasets—often reaching hundreds of gigabytes and containing millions of cells. Analyzing this data presents a major computational bottleneck. Many popular spatial biology tools struggle to handle the scale of multiplexed protein imaging. SPAC (SPAtial single-Cell analysis) bridges this gap by providing a scalable, user-friendly ecosystem designed for biological intuition.

Methods and Architecture

SPAC consists of a robust Python package and an interactive Shiny web application. Key methodological highlights include:

  • Biologist-Friendly Data Structures: SPAC utilizes the standard AnnData format but translates technical jargon into intuitive terms (e.g., "cells" and "protein expression levels").
  • Optimized Computational Backend: To handle datasets exceeding 10 million cells, SPAC integrates optimized numerical routines using NumPy's compiled C-based backend, achieving a >5x speedup over traditional methods.
  • Advanced Spatial Statistics: The package includes specialized tools like edge-corrected Ripley’s L statistics and efficient KDTree neighborhood profiling.

Specialized Spatial Statistics

Unlike generalized implementations, SPAC's Ripley’s L statistic explicitly evaluates clustering between specific "center" and "neighbor" phenotype pairs. Crucially, it includes edge correction—excluding cells near the region's borders to prevent statistical biases caused by artificial boundaries.

Ripley's L Statistic analysis in SPAC, demonstrating the evaluation of spatial clustering between phenotypes with edge correction.

Key Insights

  • UX Matters in Bioinformatics: By wrapping standard objects in terminology that makes sense to wet-lab scientists and pairing it with a no-code Shiny app, SPAC drastically lowers the barrier to entry for sophisticated spatial analysis.
  • Edge Effects Skew Spatial Data: Standard spatial clustering algorithms often fail at the borders of a tissue sample. SPAC’s explicit edge correction ensures that researchers are seeing true biological clustering, not mathematical artifacts.
  • Microenvironments as Computable Layers: By capturing a cell's local neighborhood via KDTree, researchers can perform dimensionality reduction (like UMAP) based purely on a cell's spatial context.

Results

SPAC has demonstrated significant performance gains, improving computational efficiency by over 5x when analyzing large multiplex imaging datasets. Modified plotting routines reduce visualization generation time for millions of cells from tens of seconds down to just a few seconds. The package successfully unifies data ingestion, preprocessing, clustering, and spatial analysis into a single, interoperable pipeline, having already been deployed to analyze over 30 million cells across diverse studies.

Conclusion

SPAC provides a comprehensive and scalable solution for the analysis of multiplexed imaging data. By prioritizing both computational performance and user accessibility, it enables biologists to extract meaningful insights from complex spatial datasets. Future work will continue to expand support for emerging spatial modalities and maintain integration with the evolving single-cell software ecosystem.

Summary updated

BibTeX
@misc{liu2025spac,
  author = {Zhiyuan Liu and Rui He and Andrei Bombin and Ahmad Abdallah and Omar Eldaghar and Tommy R. Sheeley and Sam E. Ying and George Zaki},
  title = {{SPAC: A Python Package for Spatial Single-Cell Analysis of Multiplex Imaging}},
  year = {2025},
  eprint = {2506.01560},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.01560},
  howpublished = {arXiv},
}
Figure