Spatial Process & Relationship Modeling
Project description
SPRM - Spatial Process & Relationship Modeling
Ted Zhang, Haoran Chen, Matt Ruffalo, and Robert F. Murphy
Ray and Stephanie Lane Computational Biology Department
School of Computer Science, Carnegie Mellon University
V2.0.1 December 23, 2025
Description
SPRM is a statistical modeling program that is used in the HuBMAP project to calculate a range of metrics, descriptors/features and models from multichannel tissue images. It requires at a minimum a multichannel tissue image and a corresponding indexed image containing cell segmentations. The metrics measure the quality of the provided images and the quality of the provided cell segmentation. The descriptors are used for clustering of cells using various approaches and are saved for use in comparison with other tissue images and for content-based image search.
SPRM can be used standalone with any type of multichannel 2D or 3D image (e.g., CODEX, IMC) for which a cell segmentation is available.
Inputs
Primary: Two OMETIFF files -
- a 3D or 4D multichannel intensity Image (2D or 3D for multiple channels)
- a corresponding 3D or 4D Indexed Image containing one channel for each component of cell segmentation (“cells”, “nucleus”, “cell membrane” and “nuclear membrane”).
Execution
Option 1: Modular API (Recommended)
The modular API allows you to run individual components of SPRM independently.
Module Structure
SPRM is organized into 7 modules:
- Preprocessing (Required) - Load images, extract ROIs, quality control
- Segmentation Evaluation (Optional) - Assess segmentation quality
- Shape Analysis (Optional) - Extract cell shape features
- Spatial Graphs (Cell Neighborhood Graphs) (Optional) - Compute spatial relationships
- Image Analysis (Pixel Level Analysis) (Optional) - NMF, superpixels, channel PCA
- Cell Features (Required for clustering) - Intensity & texture features
- Clustering (Analysis) - Multiple clustering methods
Dependency Graph
Preprocessing (Module 1) ✓ Always required
├─→ Segmentation Eval (Module 2) [standalone]
├─→ Shape Analysis (Module 3)
├─→ Spatial Graphs (Module 4)
├─→ Image Analysis (Module 5)
└─→ Cell Features (Module 6) ✓ Required for clustering
└─→ Clustering (Module 7)
Critical path: Preprocessing → Cell Features → Clustering
Optional branches: Modules 2, 3, 4, 5 enhance analysis but aren't required
For example,
from sprm import modules
# Run only what you need
core = modules.preprocessing.run(
img_file="image.ome.tiff",
mask_file="mask.ome.tiff",
output_dir="sprm_outputs"
options="sprm/options.txt" # Pass path to options file
)
features = modules.cell_features.run(
core_data=core,
output_dir="sprm_outputs",
compute_texture=False # Skip texture for speed
)
clusters = modules.clustering.run(
core_data=core,
cell_features=features,
output_dir="sprm_outputs"
)
Benefits:
- Run only the analyses you need
- Resume from checkpoints (save computation time)
- Re-run parts with different parameters
- Better for debugging and development
See Modular API Documentation and demo/ for more details.
Option 2: Legacy Command-Line Interface
For backward compatibility, the original CLI still works:
[python_path] SPRM.py --img-dir [img_dir_path] --mask-dir [mask_dir_path] --optional-img-dir [optional_img_dir_path] --output_dir [output_dir_path] --options_path [options_file_path] --celltype_labels [labels_file] --processes [number_of_processes_to_use]
Outputs
The following sets of files are placed in the folder specified by the “output_dir” argument. They are
- OME-TIFFs showing pixel level results (remapping of channels) [3 per input image]
- CSV containing interpolated cell outlines & polygons [2 per input image]
- CSVs containing features for each cell [4 per image]
- CSVs containing features for subcellular components segmentation [12 per image]
- CSV containing clustering results for each cell (row) for different methods (column) [1 per input image]
- CSVs containing mean values of “markers” for each cluster for each clustering method [5 per input image]
- PNGs showing each cell colored by cluster for each clustering method [7 per input image]
- CSV containing the signal to noise ratios of the image per channel [1 per input image]
- CSV containing PCA and Silhouette analysis of the image [2 per input image]
- JSON containing all features and cluster assignments
The jupyter notebook “visualizeSPRMoutput.ipynb” can be used to visualize the important results files.
Simple illustration
The demo folder contains two simple ways to run SPRM from the terminal. For both, begin by “cd”ing to the “demo” folder and downloading the demo image files from this link.
Beforehand, run the following command to install SPRM
pip install .
Installing with pip
pip install sprmpkg
Even though the distribution name is sprmpkg, the Python import name remains:
import sprm
Then you can either:
- Use the shell script
run_sprm.shwhich will just run SPRM using the downloaded demo image files. It will place the outputs in the folder sprm_demo_outputs and write a log of the messages from SPRM into the file sprm_demo_outputs/sprm_demo_outputs.log. - Activate the SPRM environment (e.g., "conda activate SPRM") and then start jupyter notebook ("jupyter notebook"). Open the sprm_demo.ipynb notebook which will run SRPM on the demo files and then display the outputs in the notebook.
EXAMPLES
We have provided you with example images and masks but feel free to use your own as well!
- downloading the demo image files from this link and putting them in the "demo" folder into their own respective directories "img" and "mask".
Prerequisites
- Python 3.8 or newer
- AICSImageIO
- h5py (for checkpoint system)
- Matplotlib
- Numba
- NumPy
- Pandas
- Pillow
- Pint
- scikit-learn
- SciPy
- Shapely
Documentation
For more information on specific analytical tools and outputs of SPRM:
Development information
The notes below are provided in case you wish to make code changes and submit them to the SPRM github repository via a pull request.
Code in this repository is formatted with black and isort.
A pre-commit hook configuration is provided, which runs black and isort before committing.
Run pre-commit install in each clone of this repository which you will use for development (after pip install pre-commit
into an appropriate Python environment, if necessary).
Contact
Robert F. Murphy - murphy@cmu.edu
Ted (Ce) Zhang - tedz@andrew.cmu.edu
Matt Ruffalo - mruffalo@cs.cmu.edu
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sprmpkg-2.0.1.tar.gz.
File metadata
- Download URL: sprmpkg-2.0.1.tar.gz
- Upload date:
- Size: 100.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af2112cb66fda577269fea0b8a74a7fe1ecaeba7557a03e773ce2b7ae4c44344
|
|
| MD5 |
59e3438ead22916c29245e80d710a181
|
|
| BLAKE2b-256 |
2fd653c72bbfa47b69f15b81aaca534f9efa58a6b5ff0fa54ea2a1f7e9432ec8
|
File details
Details for the file sprmpkg-2.0.1-py3-none-any.whl.
File metadata
- Download URL: sprmpkg-2.0.1-py3-none-any.whl
- Upload date:
- Size: 107.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa778bb099066ca849756c08ddab3850107adb8578074e6bdac1308693b57301
|
|
| MD5 |
fc11234ca5f6cdac85b316f7a2be0d65
|
|
| BLAKE2b-256 |
9a571de91d05d08c5fd705cf15e6a6b52349b2702b7dad020edd9e9acbbe3305
|