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.
Department of Radiology, Northwestern University. · Department of Cell and Developmental Biology, Northwestern University. · Department of Pathology, Northwestern University.