SToFM: a Multi-scale Foundation Model for Spatial Transcriptomics

Suyuan Zhao, Yizhen Luo, Ganbo Yang, Yan Zhong, Hao Zhou, Zaiqing Nie

Abstract

Spatial Transcriptomics (ST) has emerged as a transformative technology in biology, enabling the measurement of gene expression while preserving the spatial organization of cells within tissues. However, the complexity of ST data—characterized by high-dimensional gene expression and multi-scale spatial hierarchies—presents significant computational challenges. We present SToFM, a foundation model designed to integrate biological information across three distinct scales: gene-level expression, micro-environmental interactions, and macro-level tissue morphology. Pretrained on a comprehensive dataset of 88 million cells, SToFM demonstrates state-of-the-art performance across diverse downstream tasks, including tissue segmentation and cell type annotation.

Introduction

Single-cell RNA sequencing (scRNA-seq) revolutionized our understanding of cellular heterogeneity but at the cost of losing spatial context. Spatial Transcriptomics (ST) addresses this by providing 2D coordinates for gene expression data. Despite this advancement, existing foundation models often treat ST data as isolated points or fail to capture the hierarchical nature of tissue architecture. To truly understand biological systems, models must comprehend data at the gene scale (individual cell profiles), the micro scale (local cellular neighborhoods), and the macro scale (global tissue structures).

SToFM (Spatial Transcriptomics Foundation Model) is designed to bridge these gaps. By utilizing a multi-scale architecture and a massive, newly curated pretraining corpus, SToFM captures the intricate relationships between a cell's genetic identity and its physical environment.

Methodology

SToFM employs a hierarchical approach to process the complexity of ST data through three primary components:

1. Gene Scale: Domain Adaptation

The model leverages Geneformer, a foundation model pretrained on scRNA-seq data, as its backbone. To account for the inherent noise and technical variations in ST data, the authors apply domain adaptation techniques, including masked gene modeling and contrastive learning, to refine cell embeddings for spatial contexts.

2. Micro Scale: SE(2) Transformer

Processing entire tissue slices is computationally prohibitive. SToFM addresses this by partitioning slices into localized "sub-slices" of approximately 1,000 cells. These sub-slices are processed using an SE(2) Transformer, which models cell embeddings alongside pairwise spatial distances. This architecture ensures the model is invariant to 2D rotations and translations, maintaining consistency regardless of how a tissue sample is oriented on a slide.

3. Macro Scale: Virtual Cells

To prevent the model from developing "tunnel vision" within localized sub-slices, SToFM introduces "virtual cells." By clustering similar cells across the entire tissue slice, the model generates a compressed summary of global morphology. These virtual cells are injected into every sub-slice, providing the necessary global context to inform local predictions.

Pretraining Strategy

SToFM is pretrained using two self-supervised objectives:

  • Masked Cell Modeling: Predicting hidden gene expression values based on spatial and genetic context.
  • Pairwise Distance Recovery: Reconstructing spatial distances between cells that have been artificially perturbed, forcing the model to learn robust spatial representations.

Datasets and Evaluation

SToCorpus-88M

The authors curated SToCorpus-88M, the largest ST dataset to date, containing 88 million cells across 2,000 high-resolution slices. The corpus spans six major ST technologies, including MERFISH, 10x Xenium, and Stereo-seq, providing a diverse foundation for generalizable learning.

Downstream Tasks

The model was evaluated on a wide array of biological contexts, including human embryonic structures, the human brain (DLPFC), and mouse liver and skin samples. Evaluation focused on the model's ability to generalize across different slices and technologies.

Key Results

SToFM significantly outperforms existing benchmarks in several critical areas:

  • Tissue Region Semantic Segmentation: In cross-slice evaluations, SToFM achieved an 11.6% improvement in F1 score over CellPLM, demonstrating its ability to recognize functional tissue zones.
  • Cell Type Annotation: The model outperformed existing methods by 14.34% in F1 score on mouse brain datasets, highlighting the value of spatial context in identifying cell types where gene expression data may be sparse or noisy.
  • Zero-shot Clustering: SToFM’s embeddings naturally group cells by type with high accuracy (ARI of 0.953), surpassing the next best model (0.902) without any task-specific fine-tuning.
  • Robustness: The integration of spatial data acts as an anchor, allowing the model to impute missing gene values and perform spatial deconvolution more effectively than models relying solely on expression data.

Discussion and Future Work

SToFM demonstrates that spatial context is not merely an auxiliary feature but a fundamental component of cellular biology. The model’s success in cross-slice settings suggests that while gene expression varies between samples, the underlying micro-interaction patterns and macro-structures are conserved and learnable.

Currently, SToFM utilizes three discrete scales. Future iterations may explore continuous scale modeling to better reflect the fluid nature of biological structures. Additionally, incorporating multi-modal data, such as co-registered H&E stained images or prior knowledge of gene regulatory networks, could further enhance the model's predictive power and biological interpretability.

Summary updated

BibTeX
@inproceedings{zhao2025stofm,
  author = {Suyuan Zhao and YIZHEN LUO and Ganbo Yang and Yan Zhong and Hao Zhou and Zaiqing Nie},
  title = {{SToFM: a Multi-scale Foundation Model for Spatial Transcriptomics}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=PQx66EJUu0},
}
Figure