Comprehensive spatial transcriptomics analysis library with advanced segmentation, clustering, and spatial analysis tools
Project description
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
# macOS (using Homebrew)
brew install libjpeg zlib libpng fftw
# 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
🔍 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 MIT License - see the LICENSE file for details.
🔗 Links
SPEX - Empowering spatial transcriptomics research with advanced analysis tools.
Project details
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 spex_tools-0.3.1057.tar.gz.
File metadata
- Download URL: spex_tools-0.3.1057.tar.gz
- Upload date:
- Size: 2.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3de477df1b17022a2de3c875a56329c1d2cae3387bb9b2fa1111867e5b380b6
|
|
| MD5 |
1a3d1c551bd93d47109f1e6dc35d8a98
|
|
| BLAKE2b-256 |
f6434fcd2c779260a32079742b0260bd737138aa33b33f8fb5de8a74e44fd9ed
|
Provenance
The following attestation bundles were made for spex_tools-0.3.1057.tar.gz:
Publisher:
publish.yml on Genentech/spex-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spex_tools-0.3.1057.tar.gz -
Subject digest:
b3de477df1b17022a2de3c875a56329c1d2cae3387bb9b2fa1111867e5b380b6 - Sigstore transparency entry: 426415037
- Sigstore integration time:
-
Permalink:
Genentech/spex-tools@30be2bbbf9366f9a11c9dfca6283f47672535d97 -
Branch / Tag:
refs/tags/v0.3.1057 - Owner: https://github.com/Genentech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@30be2bbbf9366f9a11c9dfca6283f47672535d97 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spex_tools-0.3.1057-py3-none-any.whl.
File metadata
- Download URL: spex_tools-0.3.1057-py3-none-any.whl
- Upload date:
- Size: 2.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71cf58266fd843f3774448e05231be8802acec79525e0fe53cd861a95d7e46c4
|
|
| MD5 |
b09d2255440ac6afe9234de302784cd6
|
|
| BLAKE2b-256 |
140d947e86e419d3ccce61fda7757f2002e04af8a05eded3553c8be0ac58ae89
|
Provenance
The following attestation bundles were made for spex_tools-0.3.1057-py3-none-any.whl:
Publisher:
publish.yml on Genentech/spex-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spex_tools-0.3.1057-py3-none-any.whl -
Subject digest:
71cf58266fd843f3774448e05231be8802acec79525e0fe53cd861a95d7e46c4 - Sigstore transparency entry: 426415053
- Sigstore integration time:
-
Permalink:
Genentech/spex-tools@30be2bbbf9366f9a11c9dfca6283f47672535d97 -
Branch / Tag:
refs/tags/v0.3.1057 - Owner: https://github.com/Genentech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@30be2bbbf9366f9a11c9dfca6283f47672535d97 -
Trigger Event:
release
-
Statement type: