Sovereign 8s.is mirror of standardgalactic/SPACER
  • Python 56.6%
  • Jupyter Notebook 43.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-14 13:42:06 -05:00
__pycache__ fix the bugs 2026-07-14 13:42:06 -05:00
assets example test 2025-11-21 10:47:02 -06:00
model user friendly 2026-07-14 13:37:45 -05:00
.gitignore review redo 2026-07-09 18:32:11 -05:00
human.csv example test 2025-11-21 10:21:47 -06:00
LICENSE Add MIT License to the project 2026-03-24 21:28:52 -05:00
predict.py user friendly 2026-07-14 13:37:45 -05:00
README.md upload model weights 2026-05-25 11:01:41 -05:00
requirements.txt user friendly 2026-07-14 13:37:45 -05:00
train.ipynb example test 2025-11-21 10:21:47 -06:00
train.py user friendly 2026-07-14 13:37:45 -05:00

SPACER Logo

📘 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.

SPACER model overview

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 expression and 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!