SPEX - Spatial Omics Analysis Library
SPEX is a comprehensive spatial transcriptomics analysis library that implements state-of-the-art methods for tissue segmentation, clustering, and spatial analysis. The library enables researchers to apply advanced image processing and spatial analysis techniques to their own microscopy data.
🚀 Key Features
🖼️ Image Segmentation
- Cellpose - Deep learning-based cell segmentation
- StarDist - Star-convex object-based segmentation
- Watershed - Classical watershed segmentation
- Preprocessing - Background subtraction, noise removal, filtering
- Post-processing - Cell rescue, object filtering, feature extraction
🧬 Spatial Transcriptomics Analysis
- Clustering - PhenoGraph, Leiden, Louvain algorithms
- Niche Analysis - Cell niche identification and interactions
- Differential Expression - Spatial-aware differential analysis
- Pathway Analysis - Cluster annotation and signaling pathways
- CLQ Analysis - Co-localization quotient for spatial relationships
🔧 Utilities
- Data Loading - OME-TIFF, OME-ZARR, AnnData formats
- Preprocessing - Normalization, batch correction, dimensionality reduction
- Visualization - Comprehensive plotting and analysis tools
📦 Installation
Quick Start
# Install from PyPI
pip install spex-tools
Advanced Installation
For optimal performance, we recommend installing system dependencies:
Option 1: Using Conda (Recommended)
# Load Miniforge3/Anaconda (if available on your system)
module load Miniforge3 # or module load Anaconda3
# Create and activate conda environment
conda create -n py311 python=3.11 -c conda-forge -y
conda activate py311
# Install system dependencies (optional, but recommended)
conda install -c conda-forge libjpeg-turbo zlib libpng fftw compilers make cmake imagecodecs -y
# Install SPEX
pip install spex-tools
Option 2: Using System Package Manager
# Ubuntu/Debian
sudo apt install -y libgl1-mesa-glx libjpeg-dev zlib1g-dev libpng-dev libgl1 libfftw3-dev build-essential python3-dev
# Install SPEX
pip install spex-tools
From Source
# Clone repository
git clone https://github.com/genentech/spex-tools.git
cd spex-tools
# Set up environment
conda create -n py311 python=3.11 -c conda-forge -y
conda activate py311
# Install
pip install .
🔧 Quick Start
import spex as sp
# Load an image
array, channels = sp.load_image("path/to/image.ome.tiff")
# Perform cell segmentation
labels = sp.cellpose_cellseg(array, seg_channels=[0], diameter=30, scaling=1)
# Extract features
features = sp.feature_extraction(array, labels)
print(f"Detected {labels.max()} cells")
📚 Documentation
- Installation Guide - Detailed setup instructions
- Tutorials - Step-by-step guides
- API Reference - Complete function documentation
- Examples - Practical workflows and use cases
📂 Example Workflows
Complete Segmentation Pipeline
import spex as sp
# 1. Load and preprocess image
array, channels = sp.load_image("image.ome.tiff")
array = sp.background_subtract(array)
array = sp.median_denoise(array)
# 2. Segment cells
labels = sp.cellpose_cellseg(array, seg_channels=[0], diameter=30)
# 3. Post-process
labels = sp.remove_small_objects(labels, min_size=50)
labels = sp.remove_large_objects(labels, max_size=1000)
# 4. Extract features
features = sp.feature_extraction(array, labels)
Spatial Analysis Workflow
import spex as sp
import scanpy as sc
# 1. Load AnnData
adata = sc.read_h5ad("spatial_data.h5ad")
# 2. Preprocess
adata = sp.preprocess(adata)
# 3. Cluster
adata = sp.cluster(adata, method='leiden', resolution=0.5)
# 4. Spatial analysis
clq_results = sp.CLQ_vec_numba(adata, cluster_key='leiden')
niche_results = sp.niche(adata, cluster_key='leiden')
# 5. Differential expression
de_results = sp.differential_expression(adata, groupby='leiden')
Interactive Examples
Use the methods directly in your own analysis pipelines. Example notebooks are available:
-
▶️ Google Colab Run on Colab
-
🖥️ JupyterLab Server View on Server password "spexspex"
Notebooks include:
- Model downloading (in case Cellpose server access fails)
- Visualization examples
- End-to-end segmentation pipelines
🎯 Getting Started
- Install SPEX - Follow the installation instructions above
- Load your data - Use
load_image()for microscopy images orscanpy.read_h5ad()for AnnData - Segment cells - Choose from Cellpose, StarDist, or Watershed methods
- Extract features - Get per-cell measurements and characteristics
- Analyze spatially - Perform clustering and spatial analysis
⚙️ System Requirements
- Python: 3.11 (recommended), other versions may work
- Memory: 8GB+ RAM recommended for large images
- GPU: Optional, for faster Cellpose processing
- Dependencies: OpenCV, NumPy, SciPy, Scanpy, AnnData
- Platform Compatibility:
- ✅ Linux (x86_64): Fully supported
- ✅ Windows (x86_64): Fully supported
- ❌ macOS: Not supported due to compatibility issues with core dependencies
- ❌ ARM64/Apple Silicon: Not supported
- ❌ Other architectures: Not tested or supported
🔍 Troubleshooting
Common Issues
-
OpenCV Import Error
- Ensure system dependencies are installed
- Try:
conda install -c conda-forge opencv
-
Cellpose Model Download Issues
- Models download automatically on first use
- Check internet connection
- See documentation for manual download
-
Memory Issues
- Large images may require significant RAM
- Consider using smaller image tiles
For more help, see our Troubleshooting Guide.
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
📄 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🔗 Links
SPEX - Empowering spatial transcriptomics research with advanced analysis tools.
Metadata
Release files for spex-tools 0.3.1059
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spex_tools-0.3.1059.tar.gz | 2.4 MB | With provenance | Details for spex_tools-0.3.1059.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spex_tools-0.3.1059-py3-none-any.whl | Python 3 | none | any | Details for spex_tools-0.3.1059-py3-none-any.whl |
Total release size: 4.8 MB
Release files / spex_tools-0.3.1059.tar.gz
| Download URL | spex_tools-0.3.1059.tar.gz |
|---|---|
| Size | 2.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb3a57a68cad702880acc478b5531d259420b33662a6d052d233c3c959a4ca0b
|
|
BLAKE2b-256 checksum How to use checksums |
16bef26f6b9da1b917624747bb227d2936514261db5f3f595d3f27d3b2e3bb81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2025.
Transparency logRelease files / spex_tools-0.3.1059-py3-none-any.whl
| Download URL | spex_tools-0.3.1059-py3-none-any.whl |
|---|---|
| Size | 2.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd05fdeed63cd169ecd065241013e330ed9bf70ebec54e63281a76246b967a15
|
|
BLAKE2b-256 checksum How to use checksums |
caff32e510ab6cb7cdbf065e4fbd0883347fb7b3ff2291a73af0d0e715e9f54e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2025.
Transparency logSecurity for spex-tools 0.3.1059
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spex_tools-0.3.1059.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.