- Python 56.6%
- Jupyter Notebook 43.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| __pycache__ | ||
| assets | ||
| model | ||
| .gitignore | ||
| human.csv | ||
| LICENSE | ||
| predict.py | ||
| README.md | ||
| requirements.txt | ||
| train.ipynb | ||
| train.py | ||
📘 SPACER: A Multi-Instance Learning Framework for Spatial Transcriptomics
SPACER (Spatial Analysis of Cellular Engagement and Recruitment) is a deep learning framework designed to model how immune or stromal cells engage with and recruit neighboring cells within tissue microenvironments.
It operates directly on spatial transcriptomics data (.h5ad) and constructs cell-centered neighborhoods (“bags”) for multi-instance learning.
This repository provides:
- The SPACER model and training pipeline
- Bag-construction utilities for AnnData
- Command-line training scripts
- Gene-level SPACER score tracking across epochs
🧪 Training modes
train.py supports two modes:
- Single mode: standard single-dataset training or pooling all bags from all datasets as if they come from one single dataset.
- Joint mode: Multiple samples that are input into SPACER under the joint-sample analysis mode, with optional regularization on the global/shared parameters to stabilize training under heterogeneous SRT sources.
In the current MIL SPACER implementation, federated aggregation is applied to the global parameter vector:
- Global/shared (S):
SPACER score - Data specific parameters (kept local):
Distance,Gene expressionand scale paremeters
Single mode
python train.py \
--training_mode single \
--data path/to/training.csv \
--reference_gene path/to/reference_genes.csv \
--output_dir outputs/run1
Joint mode
Provide one CSV per SRT dataset via --joint_data (each CSV follows the same format as --data).
python train.py \
--training_mode joint \
--joint_data data.csv \
--comm_rounds 50 \
--local_epochs 1 \
--fedprox_mu 0.01 \
--reference_gene path/to/reference_genes.csv \
--output_dir outputs/joint_run \
--save_global_each_round
📄 Full Documentation
For full installation instructions, data preparation steps, and detailed tutorials, visit:
👉 https://spacer-readme.readthedocs.io/en/latest/
📂 Example Data
Example datasets used in tutorials are available here:
👉 https://drive.google.com/drive/folders/1L1zl3Qtk31YYgdURKa5_IdPI0raQUN55?usp=sharing
📂 Model Weights
Pretained model weights(Tumor discovery cohort) are available here:
👉 https://drive.google.com/file/d/1VpY3TeCLLExAHyccilohpA98wD4-g6Pe/view?usp=share_link
This pretrained model could erve as the foundation for the second stage of fine-tuning.
If you have questions or want to contribute, feel free to open an issue or pull request!