SpatialMAGIC: A Hybrid Framework Integrating Graph Diffusion and Spatial Attention for Spatial Transcriptomics Imputation
Authors: Sayeem Bin Zaman, Fahim Hafiz, Riasat Azim
Organizations: Department of Computer Science and Engineering, United International University, United City, Madani Avenue, Badda, Dhaka 1212, Bangladesh
Spatial transcriptomics (ST) enables mapping gene expression with spatial context but is severely affected by high sparsity and technical noise, which conceals true biological signals and hinders downstream analyses. To address these challenges, SpatialMagic was proposed, which is a hybrid imputation model combining MAGIC-based graph diffusion with transformer-based spatial self-attention. The long-range dependencies in the gene expression are captured by graph diffusion, and local neighborhood structure is captured by spatial attention models, which allow for recovering the missing expression values, retaining spatial consistency. Across multiple platforms, SpatialMagic consistently outperforms existing baselines, including MAGIC and attention-based models, achieving peak Adjusted Rand Index (ARI) scores in clustering accuracy of 0.3301 on high-resolution Stereo-Seq data, 0.3074 on Slide-Seq, and 0.4216 on the Sci-Space dataset. Beyond quantitative improvements, SpatialMagic substantially enhances downstream biological analyses by improving the detection of both up- and down-regulated genes while maintaining regulatory consistency across datasets. The pathway enrichment analysis of the recovered genes indicates that they are involved in consistent processes across key metabolic, transport, and neural signaling pathways, suggesting that the framework improves data quality while preserving biological interpretability. Overall, SpatialMagic's hybrid diffusion attention strategy and refinement module outperform state-of-the-art baselines on quantitative metrics and provide a better understanding of the imputed data by preserving tissue architecture and uncovering biologically relevant genes. The source code and datasets are provided in the following link: https://github.com/sayeemzzaman/SpatialMAGIC
Figures & tables
Figure 1: Overview of the SpatialMAGIC framework. The input gene expression matrix undergoes MAGIC-based diffusion to recover local gene patterns. Simultaneously, spatial coordinates are embedded using a transformer encoder to capture spatial relationships. The outputs from both branches are fused and passed through a neural decoder to reconstruct an enhanced expression profile for downstream spatial clustering and analysis.
Platform
Dataset Name
Biological Description
Cells
Genes
Stereo-seq [ 12 ]
DT2_D0
Embryonic Day 9.5
42,658
20,735
DX6_D2
Embryonic Day 11.5
14,852
19,430
FB2_D1
Adult mouse brain tissue
16,263
19,639
Slide-seq [ 13 ]
slide_seq_diabetes1_T4
Diabetic mouse model (T1D)
9,435
16,884
slide_seq_WT1_T3
Healthy wild-type control
9,008
16,598
stickles_mouse_slideseq
V2 mouse brain benchmark
22,650
3,919
Table 1: Summary of ST Datasets Used for Experiment
Dataset Type
Dataset
Before Imputation
MAGIC
Attention PCA
Attention UMAP
SpatialMAGIC
Stereo-seq
DX6_D2_stereo-seq
0.2661
0.2889
0.2818
0.2839
0.3254
DT2_D0_stereo-seq
0.2847
0.3088
0.3194
0.3014
0.3301
FB2_D1_stereo-seq
0.1679
0.2192
0.2580
0.2543
0.2993
Slide-seq
stickles_mouse_slideseq
0.1740
0.1764
0.2249
0.1736
0.2193
slide_seq_diabetes1_T4
0.2657
0.2577
0.2336
0.2197
0.2688
slide_seq_WT1_T3
0.2891
0.3049
0.2870
0.2287
0.3074
Table 2: Comparison of ARI scores across different spatial transcriptomics datasets and imputation methods. SpatialMAGIC consistently outperforms baselines across all dataset types.
Figure 2: Clustering results of the Stereo-seq dataset before and after imputations.
Figure 3: ARI Comparison Across Imputation Methods (Stereo-seq).
Figure 4: ARI Comparison Across Imputation Methods (Slide-seq).
Figure 5: ARI comparison across imputation methods (Sci-space).
Dataset
MAGIC (s)
SpatialMAGIC (s)
DX6
191.50
291.56
DT2
334.75
1451.36
FB2
282.91
332.74
Table 3: Runtime comparison of MAGIC and SpatialMAGIC across Stereo-seq datasets. All experiments were conducted using the cloud-based notebook environment provided by Kaggle. The implementation was executed on a GPU-accelerated runtime equipped with two NVIDIA Tesla T4 GPUs, each with 15 GiB of VRAM, and approximately 30 GiB of system RAM.
Figure 6: Overlapping up- and down-regulated genes before and after applying SpatialMAGIC across the three Stereo-seq datasets (DT2_D0, DX6_D2, and FB2_D1). Each pair of Venn diagrams represents the overlap and enhancement of significant gene detection after imputation.
Spatial Transcriptomics (ST) provides spatially-resolved gene expression, offering crucial insights into tissue architecture and complex diseases. However, its prohibitive cost limits widespread adoption, leading to significant attention on inferring spatial gene expression from readily available whole slide images. While graph neural networks have been proposed to model interactions between tissue regions, their reliance on pre-defined sparse graphs prevents them from considering potentially interacting spot pairs, resulting in a structural limitation in capturing complex biological relationships. To address this, we propose FEAST (Fully connected Expressive Attention for Spatial Transcriptomics), an attention-based framework that models the tissue as a fully connected graph, enabling the consideration of all pairwise interactions. To better reflect biological interactions, we introduce negative-aware attention, which models both excitatory and inhibitory interactions, capturing essential negative relationships that standard attention often overlooks. Furthermore, to mitigate the information loss from truncated or ignored context in standard spot image extraction, we introduce an off-grid sampling strategy that gathers additional images from intermediate regions, allowing the model to capture a richer morphological context. Experiments on public ST datasets show that FEAST surpasses state-of-the-art methods in gene expression prediction while providing biologically plausible attention maps that clarify positive and negative interactions. Our code is available at https://github.com/starforTJ/ FEAST.
Spatial Transcriptomics (ST) measures gene expression while preserving spatial context, but its high cost and low throughput leave public datasets small. Inferring expression directly from widely available Hematoxylin and Eosin (H&E) stained histology offers a cost-effective alternative. However, existing approaches face several limitations: regression methods over-smooth toward the conditional mean, while generative methods are faithful but require slow multi-step inference; most methods treat genes as independent and equally important, ignoring inter-gene dependencies and heterogeneous gene informativeness; and most are tailored to a single resolution, either spot-level or cell-level. To address these issues, we propose DriftST, a unified framework for inferring spatially resolved gene expression from H&E images. DriftST builds on a Cellular Drifting generative model that learns a direct drift from a histology-conditioned source to the expression distribution, retaining generative expressiveness while enabling efficient one-step generation. To capture gene structure, we introduce the STransformer, which combines a co-expression attention module for inter-gene dependencies with a gene residual gate for differential gene importance. Operating on a generic gene-panel representation, DriftST applies directly to both spot-level and cell-level data in one framework, and extensive experiments across diverse tissues and platforms show that it achieves state-of-the-art performance at both resolutions.
Yuhang Yang, Yonggan Bu, Shengyuan Zhou +2
University of Science and Technology of China, Hefei, China · Peking University Cancer Hospital, Beijing, China
Spatial Transcriptomics (ST) provides spatially resolved gene expression profiles within intact tissue architecture, enabling molecular analysis in histological context. However, the high cost, limited throughput, and restricted data sharing of ST experiments result in severe data scarcity, constraining the development of robust computational models. To address this limitation, we present a Central-to-Local adaptive generative diffusion framework for ST (C2L-ST) that integrates large-scale morphological priors with limited molecular guidance. A global central model is first pretrained on extensive histopathology datasets to learn transferable morphological representations, and institution-specific local models are then adapted through lightweight gene-conditioned modulation using a small number of paired image-gene spots. This strategy enables the synthesis of realistic and molecularly consistent histology patches under data-limited conditions. The generated images exhibit high visual and structural fidelity, reproduce cellular composition, and show strong embedding overlap with real data across multiple organs, reflecting both realism and diversity. When incorporated into downstream training, synthetic image-gene pairs improve gene expression prediction accuracy and spatial coherence, achieving performance comparable to real data while requiring only a fraction of sampled spots. C2L-ST provides a scalable and data-efficient framework for molecular-level data augmentation, offering a domain-adaptive and generalizable approach for integrating histology and transcriptomics in spatial biology and related fields.
Yaoyu Fang, Jiahe Qian, Xinkun Wang +2
Department of Radiology, Northwestern University. · Department of Cell and Developmental Biology, Northwestern University. · Department of Pathology, Northwestern University.