Graph contrastive learning of subcellular-resolution spatial transcriptomics improves cell type annotation and reveals critical molecular pathways Authors: Qiaolin Lu, Jiayuan Ding, Lingxiao Li, Yi Chang Published: 2025 ABSTRACT AbstractImaging-based spatial transcriptomics (iST), such as MERFISH, CosMx SMI, and Xenium, quantify gene expression level across cells in space, but more importantly, they directly reveal the subcellular distribution of RNA transcripts at the single-molecule resolution. The subcellular localization of RNA molecules plays a crucial role in the compartmentalization-dependent regulation of genes within individual cells. Understanding the intracellular spatial distribution of RNA for a particular cell type thus not only improves the characterization of cell identity but also is of paramount importance in elucidating unique subcellular regulatory mechanisms specific to the cell type. However, current cell type annotation approaches of iST primarily utilize gene expression information while neglecting the spatial distribution of RNAs within cells. In this work, we introduce a semi-supervised graph contrastive learning method called Focus, the first method, to the best of our knowledge, that explicitly models RNA’s subcellular distribution and community to improve cell type annotation. Focus demonstrates significant improvements over state-of-the-art algorithms across a range of spatial transcriptomics platforms, achieving improvements up to 27.8% in terms of accuracy and 51.9% in terms of F1-score for cell type annotation. Furthermore, Focus enjoys the advantages of intricate cell type-specific subcellular spatial gene patterns and providing interpretable subcellular gene analysis, such as defining the gene importance score. Importantly, with the importance score, Focus identifies genes harboring strong relevance to cell type-specific pathways, indicating its potential in uncovering novel regulatory programs across numerous biological systems.Keywords: spatial transcriptomics, graph contrastive learning, cell type annotation, subcellular gene neighborhood network Introduction Recent developments in imaging-based spatial transcriptomics (iST) [1–9] empower us to measure individual RNA molecules at subcellular resolution, which, in turn, facilitates the revelation of intricate spatial distribution of distinct cell types, and more importantly the cell type-specific subcellular localization of the transcripts. Consequently, these technologies hold exciting potential to shed light on the gene expression dynamics and regulation across many cell types at unprecedented spatial resolution. However, analyzing such data to achieve these goals will introduce several unfathomable computational hurdles. Among them, cell type annotation stands out as a particularly formidable challenge due to its low number of quantified genes, which results from the intrinsic limitation of the diffraction limit of light, the spectral overlap of the fluorescence probes, etc. For example, the Nanostring CosMx [3] platform defines the subcellular expression of merely 960 genes. Similarly, Xenium from 10 Genomics [8] measures only hundreds of genes in total. While MERFISH [7] in principle can measure the entire transcripts through a sophisticated multiplexing scheme, it usually can only robustly measure a few hundred genes. Identifying and categorizing diverse cell types within a mixed population is a crucial objective in single-cell analysis. This task is particularly challenging in spatial transcriptomics (iST) due to the low number of measured genes or high dropout rates. Deep learning techniques [10–18] have been increasingly applied to tackle these challenges. Many cell type annotation methods are designed for single-cell RNA-seq data, such as CellTypist [11], which uses logistic regression for immune cell identification, and TOSICA [12], a deep learning-based multi-head self-attention network, are designed for single-cell RNA-seq data. ACTTINN [13] employs neural networks using reference datasets to predict cell type for each cell. Furthermore, scDOT [19] leverages distance metric learning and Optimal Transport to refine cell type assignments by aligning cells across datasets while preserving biological relationships. These methods rely solely on gene expression values, which has led to the development of new approaches that also incorporate spatial information of cells. Graph-based methods like scDeepSort [14] and sigGCN [15] model complex relationships between cells using graph neural networks (GNN) [20]. sigGCN constructs gene interaction networks based on weighted adjacency matrices, and scDeepSort uses a bipartite graph to represent both cells and genes. Spatial transcriptomics-specific methods have emerged, such as spatial-ID [21], a GCN-based approach that incorporates the spatial information of cells but not of RNA transcripts, and TACCO [22], which transfers annotations from single-cell data to spatial data using optimal transport. However, those methods often overlook the intracellular spatial distribution of RNA transcripts at the single molecule level, which potentially plays an important role in elucidating unique cell type-specific subcellular regulatory mechanisms. To incorporate spatial information of transcripts and their subcellular communities into cell type annotation, we propose Focus, a semi-supervised Graph Contrastive Learning (GCL)-based algorithm of iST at subcellular resolution (Fig. 1). To model the subcellular distribution and functional interaction between RNAs, Focus constructs gene neighborhood networks that constitute the basis for all downstream modeling. To learn subcellular features for each cell, we next employ GCL framework on the gene neighborhood network [23, 24] by maximizing the similarity between positive pairs from the same cell and minimizing the similarity between negative pairs from distinct cells within a common batch where the graph pairs are generated via augmented graphs through adding or removing graph nodes or edges. After the GCL process, Focus computes an importance score for every transcript and RNA subcellular community (the subnetwork formed by a subset of RNA transcripts), reflecting their importance for that cell. We find the genes with high scores tend to have significant importance and relevance to specific cell types based on detailed gene set enrichment analyses. We further demonstrate the effectiveness and robustness of Focus across various platforms in the context of cell type annotation. An overview of the Focus framework. (a) The graph contrastive learning workflow in Focus. (b) Learned scores for each node and subgraph after graph contrastive learning. (c) Gene neighborhood network construction from subcellular information. (d) Augmentation methods at subgraph and node level. (e) Left: subcellular point cloud of the same sample cell before training. Median: subcellular point cloud of the same sample cell after training. Right: subcellular Louvain clustering distribution of one example cell after training. Focus shows significant improvements over state-of-the-art algorithms. It outperforms the baseline methods across all test datasets, achieving up to 27.8% higher accuracy and 51.9% higher F1-scores. Notably, FOCUS maintains robustness, performing well even with limited labeled data, while baseline methods show a rapid performance decline. Additionally, gene ranking based on importance scores reveals that high-scoring genes are highly enriched in cell type-specific pathways. Our main contributions to this paper are as follows: We introduce Focus, a GCL model to enhance cell type annotation on spatial transcriptomics data by leveraging subcellular spatially resolved gene neighborhood networks. To the best of our knowledge, this is the first work that uses the spatial information of the transcript and the RNA subcellular communities in the cell to improve cell type annotation. We introduce Focus, a GCL model to enhance cell type annotation on spatial transcriptomics data by leveraging subcellular spatially resolved gene neighborhood networks. To the best of our knowledge, this is the first work that uses the spatial information of the transcript and the RNA subcellular communities in the cell to improve cell type annotation. Focus exhibits high robustness even when provided with a limited amount of labeled data, and outperforms state-of-the-art methods by a large margin across various iST platforms. Focus exhibits high robustness even when provided with a limited amount of labeled data, and outperforms state-of-the-art methods by a large margin across various iST platforms. Based on learned importance scores for genes by Focus, we identified novel genes with higher scores that are highly relevant to cell type-specific pathways. Based on learned importance scores for genes by Focus, we identified novel genes with higher scores that are highly relevant to cell type-specific pathways. Methods The key idea of Focus is to involve subcellular localization of RNA molecules or RNA subcellular communities within cells to learn cell type-specific intracellular spatial distribution of RNA for cell type identification under the setting of limited or even no labeled data. We achieve the goal with GCL. An overview of Focus is shown in Fig. 1. The input of Focus is gene neighborhood networks constructed from transcripts within cells. Each cell will produce two augmentation views, with each of both being generated by the combination of subgraph and node-level augmentations. Given augmented graph views of each cell, a GNN model is employed to update node embedding and to learn subgraph embedding. Focus aims to maximize the similarity between positive pairs from two augmented views of the same cell and minimize the similarity between negative pairs from different cells within a common batch guided by limited labeled data. Gene neighborhood network construction To ensure the quality of the input data, we process the original subcellular spatial transcriptomics data with the following steps: Elimination of low-quality cells: we exclude cells that are either non-viable or exhibit a transcript count below a predefined threshold denoted as . The determination of the threshold is dataset-specific; for the MERFISH, CosMx SMI, and Xenium datasets, values of 100, 50, and 50, respectively, are employed. Elimination of low-quality cells: we exclude cells that are either non-viable or exhibit a transcript count below a predefined threshold denoted as . The determination of the threshold is dataset-specific; for the MERFISH, CosMx SMI, and Xenium datasets, values of 100, 50, and 50, respectively, are employed. Exclusion of negative control targets: given that negative control probes are designed to capture extraneous sequences not present in the tissue, serving as non-target controls to assess non-specific ISH probe hybridization, we filter out negative control targets and retain transcripts that corresponded to genes. Exclusion of negative control targets: given that negative control probes are designed to capture extraneous sequences not present in the tissue, serving as non-target controls to assess non-specific ISH probe hybridization, we filter out negative control targets and retain transcripts that corresponded to genes. As shown in Fig. 1(c), the connections between transcripts are established based on their spatial coordinates within each cell using the K-nearest neighbors algorithm [25]. Specifically, two transcripts are connected if their separation distance is within a specified radius, denoted as . The choice of values for each sequencing technology is guided by the goal of ensuring each transcript is connected to an average of 10–30 neighbors, a range that balances graph sparsity and computational efficiency. This range is selected based on guidelines from SpaGNN [26], which demonstrates that overly sparse graphs (with small ) fail to capture sufficient neighborhood information, while overly dense graphs (with large ) increase computational complexity and may obscure spatial patterns. By maintaining this balance, we optimize graph density to support robust spatial transcriptomics analysis. For CosMx SMI, MERFISH, and Xenium, the values are chosen as 12 pixels, 2 micrometers (m), and 3 micrometers (m), respectively. These values reflect the resolution and spatial scales inherent to each technology. Specifically, the units of coordinate in CosMx SMI is based on pixel units, where each pixel corresponds to 0.18 m, while MERFISH and Xenium report data directly in micrometers (m). When converted to a consistent metric, the values become approximately 2.16, 2, and 3 m, respectively, making the values comparable across the different sequencing technologies. As a result, in the constructed gene neighborhood network, individual nodes represent single transcripts and are linked to an average of 10-30 neighbors. To better simulate transcript enrichment, a clustering method like Louvain [27] is employed to group the constructed graph into several local gene neighborhood networks, which refer to local RNA density or subcellular spatial regions to reveal the subcellular organization of RNA. Data augmentation Previous studies [28–31] have revealed a strong correlation between the selection of specific components in a graph (such as nodes, subgraphs, etc.) and the intrinsic properties of the graph during contrastive learning. Consequently, the graph property can be effectively captured by retaining highly relevant nodes or subgraphs while eliminating less critical components [32]. Thus it’s essentially the learning process of the intracellular spatial distribution of RNA transcripts for each cell type. Based on the constructed gene neighborhood network with subgraphs, we carefully select several augmentation techniques in two levels, node level and subgraph level, as shown in Fig. 1(d): Augmentation at the node level: identical implies the preservation of edges or nodes in their original state, node dropping involves the removal of nodes, resulting in an alteration of the graph structure, node masking solely conceals node attributes while maintaining the graph structure, and edge perturbation pertains to the deletion of edges connecting nodes. Here, we list several data augmentation methods at the node level. identical, node dropping, node masking are directly related to the procession on each transcript while edge perturbation can indirectly affect each transcript by adding noise to the links between gene symbols. Augmentation at the node level: identical implies the preservation of edges or nodes in their original state, node dropping involves the removal of nodes, resulting in an alteration of the graph structure, node masking solely conceals node attributes while maintaining the graph structure, and edge perturbation pertains to the deletion of edges connecting nodes. Here, we list several data augmentation methods at the node level. identical, node dropping, node masking are directly related to the procession on each transcript while edge perturbation can indirectly affect each transcript by adding noise to the links between gene symbols. Augmentation at the subgraph level: edge perturbation involves the potential removal of edges between subgraphs, while subgraph swapping entails the exchange of two subgraphs. Since a subgraph represents a larger system than a single node, we do not use direct augmentation techniques like subgraph removal or subgraph masking that could disrupt the entire cell graph. Instead, we employ edge perturbation and subgraph swapping to indirectly affect the links within each subgraph. Augmentation at the subgraph level: edge perturbation involves the potential removal of edges between subgraphs, while subgraph swapping entails the exchange of two subgraphs. Since a subgraph represents a larger system than a single node, we do not use direct augmentation techniques like subgraph removal or subgraph masking that could disrupt the entire cell graph. Instead, we employ edge perturbation and subgraph swapping to indirectly affect the links within each subgraph. Combining augmentations at these two levels enables us to comprehensively address both local and global aspects of the data. Node-level augmentations enhance the model’s sensitivity to fine-grained transcript interactions, while subgraph-level augmentations improve its understanding of larger spatial patterns and functional groupings. This complementary approach ensures that the model can robustly analyze spatial transcriptomics data across multiple scales. Similar strategies of multi-scale graph augmentations have been shown to improve performance in various graph-based tasks, such as molecular property prediction [33, 34], drug–drug interaction networks [35], and spatial biology data analysis [36]. These studies consistently highlight the importance of addressing hierarchical structures in graph data to achieve better generalization and accuracy. Through extensive experiments (as detailed in ablation studies), we observed that combining these augmentation strategies significantly improves the model’s accuracy compared to using node-level or subgraph-level augmentations alone. Combining augmentations at these two levels enables us to comprehensively address both local and global aspects of the data. Node-level augmentations enhance the model’s sensitivity to fine-grained transcript interactions, while subgraph-level augmentations improve its understanding of larger spatial patterns and functional groupings. This complementary approach ensures that the model can robustly analyze spatial transcriptomics data across multiple scales. Similar strategies of multi-scale graph augmentations have been shown to improve performance in various graph-based tasks, such as molecular property prediction [33, 34], drug–drug interaction networks [35], and spatial biology data analysis [36]. These studies consistently highlight the importance of addressing hierarchical structures in graph data to achieve better generalization and accuracy. Through extensive experiments (as detailed in ablation studies), we observed that combining these augmentation strategies significantly improves the model’s accuracy compared to using node-level or subgraph-level augmentations alone. The proposed architecture After graph construction introduced in previous section, we have a gene neighborhood graph , where denotes a node set with transcripts in the cell, and denotes an edge set. Node feature is represented by where the node embedding is initialized with one hot embedding with dimension , and corresponds to the total count of gene symbols. The graph structure is characterized as an adjacent matrix . The graph would be further partitioned into subgraphs by a graph clustering algorithm like Louvain. Focus consists of multiple GIN layers to update node embeddings and subgraph embeddings. Specifically, each GIN layer is defined as follows: where is the node representation of node at the -th layer, is a learnable parameter for the -th layer, is the weight matrix of the -th layer, and denotes the set of neighbors of node . is the nonlinear activation function. Here, the input for the first layer would be the original node representation . Here, we utilize the Gumbel-Softmax strategy [37], a sampling method tailored for drawing samples from a discrete distribution in a differentiable way. This technique refines the decision-making process by determining which nodes to augment for each method during the training process. We calculate the Gumbel-Softmax probability for each node, assigning a score from 0 to 1. These scores subsequently inform the choice and implementation of augmentation techniques, guaranteeing a more precise and customized approach to data augmentation. Moreover, these scores reflect the importance of each node within the overall cellular graph: Node Level: the score of node is obtained by calculating the probability of node level augmentation, including node dropping and node masking. Specifically, given the node embedding from GIN layers, the score of node when using node dropping or masking strategy can be formulated as follows: (2) (3)where refers to a multilayer perceptron [38] for one direct augmentation (e.g. node masking or node dropping), denotes the learned embedding of node from GIN, represents the score drawn from the distribution used to determine the nodes chosen for augmentation. For edge perturbation, the probability of each edge being maintained during the augmentation process is determined by taking the average of the scores associated with the nodes related to that edge. Node Level: the score of node is obtained by calculating the probability of node level augmentation, including node dropping and node masking. Specifically, given the node embedding from GIN layers, the score of node when using node dropping or masking strategy can be formulated as follows: (2) (3)where refers to a multilayer perceptron [38] for one direct augmentation (e.g. node masking or node dropping), denotes the learned embedding of node from GIN, represents the score drawn from the distribution used to determine the nodes chosen for augmentation. For edge perturbation, the probability of each edge being maintained during the augmentation process is determined by taking the average of the scores associated with the nodes related to that edge. Subgraph Level: Here, we reweight the node-level scores within each subgraph to represent the subgraph-level score. Thus, given a subgraph S which contains nodes, the score of the subgraph can be formulated as follows: (4)Similar to the augmentation method at the node level, for edges between subgraphs, we determine the probability of these edges being retained during the augmentation process by calculating and weighting the scores of all related nodes associated with these edges. Specifically, in the process of subgraph swapping augmentation, for subgraphs that have already been augmented, we randomly sample nodes from the subgraphs that are set to be connected next in order to establish new inter-subgraph connections. Subgraph Level: Here, we reweight the node-level scores within each subgraph to represent the subgraph-level score. Thus, given a subgraph S which contains nodes, the score of the subgraph can be formulated as follows: (4)Similar to the augmentation method at the node level, for edges between subgraphs, we determine the probability of these edges being retained during the augmentation process by calculating and weighting the scores of all related nodes associated with these edges. Specifically, in the process of subgraph swapping augmentation, for subgraphs that have already been augmented, we randomly sample nodes from the subgraphs that are set to be connected next in order to establish new inter-subgraph connections. Upon completing the augmentation process at both the node level and subgraph level, we introduce the augmented graph into ResGCN [39] for the ongoing update of node embeddings and edge features. Ultimately, the graph embedding is obtained as , where represents the number of nodes in the augmented graph, is the node embedding at the -th layer of ResGCN. Training process In order to better learn the property of each cell, we follow the InfoMin principle [40] which states that good contrastive learning should maximize the label-related information while reducing the similarity between them. In the training phase, a data batch comprising N cells is randomly selected, and this batch is fed into the two graph view generators to generate 2N graph views. The two augmented views originating from the same input graph are treated as the positive view pair, while the views derived from distinct input graphs are considered the negative pair. In our work, we define contrastive learning loss to maximize the uniformity between positive pairs and negative pairs. To be specific, we adopt the normalized temperature-scaled cross-entropy loss(NT-XEnt) , which can be formulated as follows: Here, (, ) represents a positive pair of samples from the same cell, while (, ) denotes a randomly sampled pair from the batch. denotes the embedding of cell obtained from the final output of ResGCN. The cosine similarity between cell and cell , denoted as , where represents the temperature parameter. The loss is computed collectively across all positive pairs within a batch. Different from other supervised learning methods that only train on reference labeled data and infer on query data, We design a novel semi-supervised learning setting that effectively learns intrinsic properties of the query data using labeled data. Specifically, we employ a dual approach: unsupervised contrastive learning to organize the latent space based on similarities in the query and reference datasets, and supervised learning with the labeled reference dataset to ensure the model associates latent features with specific cell types. Positive and negative pairs are constructed from the query dataset to capture intrinsic relationships, while the labeled reference dataset provides biologically meaningful supervision, enabling the model to learn both general representations and cell type-specific features. Here, we adopt the cross entropy loss as supervised classification loss, which can be formulated as follows: where and denote ground truth labels and predicted labels, respectively. The overall objective of Focus can be formulated as follows: where is a hyperparameter to balance unsupervised contrastive learning loss and supervised classification loss . Hyperparameter selection We optimized hyperparameters using a systematic grid search approach. For the unsupervised contrastive learning module, the temperature parameter () was tuned in [0.1, 0.2, 0.5, 1.0], batch size in [16, 32, 64], and learning rate in [1 , 5 , 1 ]. For the cell type classification module, dropout rate was selected from [0.1, 0.3, 0.5], in [0.5, 1, 5], and hidden layer size was tested at [16, 32, 64]. The optimal configuration, minimizing both contrastive loss and cell type classification loss, was = 0.5, batch size = 32, learning rate = 5 , dropout rate = 0.3, =1 or 5, and hidden layer size = 128. Hyperparameter tuning revealed that = 0.5 provided the best balance between feature separation and convergence stability, while the batch size of 32 and learning rate of 5 ensured diversity and stable gradient updates. For the cell type classification module, the dropout rate (0.3) effectively prevented overfitting, and the hidden layer size (128) captured complex relationships without adding excessive complexity. Additionally, values of 1 and 5 produced comparable results, indicating robustness to variations in this parameter. This systematic tuning process ensured optimal performance, generalization across datasets, and enhanced reproducibility. Results Datasets and evalutaion metrics Datasets. CosMx SMI, MERFISH, and Xenium are advanced spatial transcriptomics technologies that map gene expression within tissues. CosMx SMI uses cyclic single-molecule FISH, MERFISH employs barcoded FISH, and Xenium utilizes targeted in situ sequencing or high-plex FISH for high-resolution RNA detection. Despite differences in detection methods and capabilities, all achieve accurate cell type identification through standardized processing steps like normalization, clustering, and annotation. To demonstrate the performance of Focus on cell type annotation, we collect a variety of subcellular spatial transcriptomic datasets from NanoString CosMx SMI [3], Xenium from 10 Genomics [8] and MERFISH [7] for evaluation. The tissues under evaluation encompass the human kidney, lung, breast, and mouse cortex. CosMx Human Lung and Kidney. These datasets are generated using a 960-plex CosMx RNA panel with CosMx SMI. The lung dataset consists of eight samples from non-small cell lung cancer (NSCLC) tissues, including three female and two male patients. A total of 766 313 cells were analyzed, with an average of 265 transcripts per cell, each represented by a subset of 960 selected genes. Each cell was classified into one of 18 unique cell types. For the kidney dataset, five samples were curated from kidney core biopsy tissues of lupus nephritis patients, collected from three different patients. These samples were also processed using the CosMx SMI platform, and we assign eight unique cell types for classification. CosMx Human Lung and Kidney. These datasets are generated using a 960-plex CosMx RNA panel with CosMx SMI. The lung dataset consists of eight samples from non-small cell lung cancer (NSCLC) tissues, including three female and two male patients. A total of 766 313 cells were analyzed, with an average of 265 transcripts per cell, each represented by a subset of 960 selected genes. Each cell was classified into one of 18 unique cell types. For the kidney dataset, five samples were curated from kidney core biopsy tissues of lupus nephritis patients, collected from three different patients. These samples were also processed using the CosMx SMI platform, and we assign eight unique cell types for classification. MERFISH Mouse Primary Motor Cortex (MOp). This dataset comprises spatially resolved gene expression profiles of individual cells within the mouse primary motor cortex, obtained through MERFISH. The dataset encompasses approximately 300 000 cells and 258 gene symbols, with an average of 614 transcripts detected per cell. Furthermore, it identifies a total of 24 distinct cell types within the mouse primary motor cortex. MERFISH Mouse Primary Motor Cortex (MOp). This dataset comprises spatially resolved gene expression profiles of individual cells within the mouse primary motor cortex, obtained through MERFISH. The dataset encompasses approximately 300 000 cells and 258 gene symbols, with an average of 614 transcripts detected per cell. Furthermore, it identifies a total of 24 distinct cell types within the mouse primary motor cortex. Xenium Ductal carcinoma In Situ (DCIS). This dataset was created using Xenium from 10 Genomics and was collected from human breast tissue containing DCIS tumor cells. We conduct data cleaning and utilized two replicates from a single sample, resulting in the detection of approximately 300 000 cells and 313 genes. The dataset encompasses a total of 19 distinct cell types. Xenium Ductal carcinoma In Situ (DCIS). This dataset was created using Xenium from 10 Genomics and was collected from human breast tissue containing DCIS tumor cells. We conduct data cleaning and utilized two replicates from a single sample, resulting in the detection of approximately 300 000 cells and 313 genes. The dataset encompasses a total of 19 distinct cell types. Evaluation metrics. To assess the effectiveness of cell type annotation, we adopt the evaluation metrics Accuracy and F1-score following previous cell type annotation studies [11–14]. We obtain the ground truth released from original datasets and then calculate the Accuracy and F1-score between ground truth and predicted cell type labels generated by Focus or baselines. The Accuracy and F1-score are formulated as follows: where true positive (TP) refers to correctly classified positive samples, true negative (TN) to correctly classified negative samples, false positive (FP) to samples incorrectly classified as positive, and false negative (FN) to samples incorrectly classified as negative. Focus achieves SOTA on cell type annotation across diverse iST platforms To validate the efficacy of our Focus across diverse iST platforms, we perform validation experiments of cell type annotation on four datasets using Focus and state-of-the-art methods. These experiments encompass three iST platforms: CosMx, MERFISH and Xenium. For each dataset, we averaged the results from three experimental runs conducted on several sample pairs, with one sample designated as the reference data and another as the query data. More details can be found in Supplementary Tables 4–8. During the training of Focus, query data without label is also included and contributes informative data for contrasting and understanding the inherent characteristics of the query data. In practical scenarios, reference and query datasets may originate from various studies or different subjects, potentially introducing batch effects that can impair cell type annotation performance. Hence, we conduct our experiments under two conditions: utilizing samples from the same subject and samples from distinct subjects for comprehensive evaluation. We also benchmark scDeepSort [14], CellTypist [11], TOSICA [12], ACTINN [13], classical cell type annotation methods on single-cell RNA seq data and Tacco [22], which is specifically designed for spatially transcriptomic data on the above datasets for comparison. As shown in Table 1 and Table 2, we observe that regardless of whether the reference and query data are sourced from the same or distinct subjects, our Focus consistently outperforms state-of-the-art approaches both on accuracy and F1-score perspectives. Notably, on the Xenium DCIS dataset, Focus demonstrates a remarkable advantage, surpassing the second-ranked method by a substantial 27.8% in terms of accuracy and 50% in terms of F1-score. To be specific, Focus achieves 87.1% (accuracy) and 71.2% (F1-score) while the second-ranked method ACTINN gets 59.3% (accuracy) and 19.3% (F1-score) on Xenium DCIS dataset, The methods specialized in annotating single-cell data, such as CellTypist and scDeepSort, frequently employ the filtration of genes with exceedingly low expression levels in cells. Yet, this strategy can potentially constrain their capacity to harness the full limited gene information within spatial transcriptomics data. Tacco is specifically designed for spatial transcriptomics data, and it performs well in capturing cell-level spatial information on MERFISH and CosMx Lung datasets. However, when applied to other datasets featuring intricate cell types, it encounters notable variability in cell type prediction due to the complexity of cell type. Instead, our Focus focuses on acquiring cell type-specific information at the subcellular level, and this capability is not constrained by the quantity of cell types present. As a result, we consistently achieve top-tier performance, regardless of whether the dataset contains a limited or extensive variety of cell types. Table 1Performance of different methods on CosMx Lung, CosMx Kidney, and MERFISH MOp datasets. The reference and query samples come from the same patient or mouse. Dataset CosMx Lung CosMx Kidney MERFISH MOp Xenium DCIS Model Accuracy F1-score Accuracy F1-score Accuracy F1-score Accuracy F1-score Focus 0.904 0.009 0.704 0.027 0.688 0.013 0.694 0.006 0.948 0.023 0.909 0.082 0.871 0.006 0.712 0.030 scDeepSort 0.725 0.0260.391 0.0120.377 0.0050.248 0.0070.868 0.0520.685 0.025N/AN/A CellTypist 0.634 0.0180.429 0.0130.478 0.0280.495 0.010N/AN/A0.371 0.0110.144 0.002 TOSICA 0.854 0.0210.638 0.001 0.668 0.002 0.664 0.002 0.942 0.004 0.885 0.0590.381 0.0440.176 0.005 ACTTINN 0.852 0.0020.566 0.0290.569 0.0090.551 0.0230.938 0.0110.853 0.059 0.593 0.013 0.193 0.004 Tacco 0.916 0.012 0.729 0.004 0.530 0.0300.522 0.0160.939 0.011 0.902 0.047 0.525 0.001 0.207 0.007 scDot 0.844 0.0090.637 0.0290.481 0.0280.506 0.0330.922 0.0290.868 0.080N/AN/ABold text indicates the best, underlined text indicates the second-best, and ‘N/A’ means no meaningful results. Performance of different methods on CosMx Lung, CosMx Kidney, and MERFISH MOp datasets. The reference and query samples come from the same patient or mouse. Bold text indicates the best, underlined text indicates the second-best, and ‘N/A’ means no meaningful results. Table 2Performance of different methods on CosMx Lung, CosMx Kidney, and MERFISH MOp datasets. The reference and query samples come from the different patients or mice. Dataset CosMx Lung CosMx Kidney MERFISH MOp Model Accuracy F1-score Accuracy F1-score Accuracy F1-score Focus 0.692 0.119 0.399 0.173 0.715 0.025 0.708 0.020 0.934 0.010 0.865 0.048 scDeepSort 0.462 0.0590.150 0.0450.173 0.1190.065 0.0620.854 0.0330.680 0.071 CellTypist 0.450 0.1120.214 0.0180.450 0.0660.472 0.062N/AN/A TOSICA 0.634 0.2020.386 0.158 0.709 0.002 0.703 0.017 0.925 0.0060.825 0.006 ACTTINN 0.636 0.0470.299 0.0570.584 0.0090.543 0.023 0.931 0.008 0.832 0.039 Tacco 0.640 0.0800.363 0.1460.575 0.0490.561 0.0560.922 0.011 0.850 0.034 scDot 0.663 0.134 0.390 0.174 0.584 0.0620.554 0.0690.918 0.0010.847 0.047Bold text indicates the best, underlined text indicates the second-best, and ‘N/A’ means no meaningful results. Performance of different methods on CosMx Lung, CosMx Kidney, and MERFISH MOp datasets. The reference and query samples come from the different patients or mice. Bold text indicates the best, underlined text indicates the second-best, and ‘N/A’ means no meaningful results. It is worth noting that on rather homogeneous datasets Focus still achieves superior performance (71.5% accuracy for the first setting) compared with other methods (scDeepSort: 17.3%, Tacco: 57.5%, CellTypist: 45.0%, TOSICA: 70.9%, ACTINN: 58.4%, and scDot: 58.4%) on CosMx kidney dataset. Among this dataset, there are three main cell types: proliferating proximal tubule cell, distinct proximal tubule 2 cell and distinct proximal tubule 1 cell, which are very similar to each other. This brings challenges to cell type annotation and these cell types are very difficult to distinguish by previous biological researches [41, 42], which mainly rely on gene expression values. The paramount aspect of Focus lies in the acquisition of cell type information from RNA’s subcellular spatial molecular pattern, which proves to be more effective when compared with methods relying solely on gene expression values. Furthermore, Focus presents remarkable transferability, even when applied to samples from distinct subjects. In contrast, other approaches experience a performance decline when confronted with reference data from different subjects. This heightened challenge in spatial transcriptomics data, characterized by a shallower read depth, presents difficulties in feature learning at the individual cell level. However, our model consistently attains the highest classification performance across all datasets. Ablation studies As shown in Table 3, we conduct ablation studies on CosMx Lung, Xenium DCIS, MERFISH MOp datasets to evaluate the impact of different data augmentation strategies on the performance of Focus. The study assessed augmentation techniques at both the node and subgraph levels, as well as their combinations. Node-level augmentation, such as node dropping, feature masking, or altering connections, significantly improved model robustness and generalization by introducing variability. Subgraph-level augmentation, which perturbs entire subgraphs, showed marginal gains compared to node-level augmentation. The combination of both node- and subgraph-level augmentations proved most effective, yielding the highest accuracy and F1-scores across nearly all the platforms. Table 3Ablation studies on CosMx Lung, Xenium DCIS, MERFISH MOp datasets. Augmentation Augmentation CosMx Lung Xenium DCIS MERFISH MOp Level Type* Accuracy F1-score Accuracy F1-score Accuracy F1-score Node Identical 0.852 0.0440.663 0.0230.838 0.0120.701 0.0210.947 0.0320.911 0.021 Node ND 0.872 0.021 0.710 0.017 0.842 0.0190.729 0.021 0.970 0.015 0.961 0.018 Node NM 0.863 0.0180.698 0.0180.832 0.0200.711 0.0190.954 0.0090.922 0.010 Node EP 0.869 0.0110.686 0.0140.834 0.0070.707 0.0060.967 0.0210.944 0.011 Node ND & NM 0.882 0.0150.699 0.0120.855 0.0110.731 0.0230.944 0.0140.887 0.025 Node ND, NM & EP 0.901 0.013 0.691 0.021 0.871 0.018 0.733 0.024 0.965 0.0170.921 0.023 Subgraph EP 0.857 0.0290.671 0.0300.852 0.0320.711 0.0210.937 0.0330.889 0.029 Subgraph SW 0.873 0.0160.681 0.0310.858 0.0280.732 0.0220.945 0.0180.889 0.019 Subgraph EP & SW 0.862 0.0220.672 0.0280.856 0.0260.700 0.0180.941 0.0260.885 0.024 Node & Subgraph ALL 0.901 0.021 0.712 0.008 0.867 0.019 0.734 0.021 0.975 0.011 0.967 0.018 *Identical: no augmentation; ND: node dropping; NM: node masking; EP: edge perturbation; SW: subgraph swapping; ALL: all augmentations including ND, NM & EP from node level and EP & SW from subgraph level.Bold text indicates the best and underlined text indicates the second-best. Ablation studies on CosMx Lung, Xenium DCIS, MERFISH MOp datasets. *Identical: no augmentation; ND: node dropping; NM: node masking; EP: edge perturbation; SW: subgraph swapping; ALL: all augmentations including ND, NM & EP from node level and EP & SW from subgraph level. Bold text indicates the best and underlined text indicates the second-best. Graph-based gene importance scores reveals enriched cell type-specific pathways By leveraging the Gumbel-Softmax strategy for selective augmentations on each gene or transcript, we can derive scores for all genes, serving as indicators of their importance within data augmentation. To effectively illustrate the importance of each gene with respect to each cell type, we compile scores for all 960 genes, categorizing them by cell type within a dataset of 20 645 sampled cells from CosMx Lung NSCLC. It is noteworthy to emphasize that these genes are not only associated with cell types but also play roles in various biological processes, including those related to antigen processing and presentation, ECM-receptor interaction, among others. Moreover, we carefully rank these genes according to their score distribution (based on the averaged score). Based on the ranking and scores of these genes, we perform GSEA preranked gene set enrichment analysis using the gseapy package [43] and KEGG database [44]. We filter for pathways that are significantly enriched in high-ranking genes judged by setting Normalized p-val (NOM p-value) < 0.05, False Positive Rate q-value (FDR) < 0.25, and Normalized Enrichment Score (NES) 1, as reported by previous work [45, 46]. We find that those genes in the enriched pathways are mostly the ones with higher scores, and those pathways are highly relevant to the corresponding cell types. Given the fact that the CosMx dataset contains tumor cells and a large number of immune cells, as shown in Fig. 2(a), our enrichment analysis reveals that these cells predominantly exhibit functions highly related to antigen processing and presentation, ECM-receptor interaction, Epstein-Barr virus infection, which is consistent with their fundamental immunity functionalities. To better discern functional differences among different cell types, we select pathway information that is highly significant only in specific cell types as shown in Fig. 2(b). For NK cells, we have successfully observed highly significant signal pathways expressed within NK cells, such as natural killer cell mediated cytotoxicity. Similarly, we have identified signal pathways associated with tumor cells triggered by colorectal cancer, hypertrophic cardiomyopathy (HCM), and amyotrophic lateral sclerosis, which are consistent with previous research [47, 48]. For B cells, we have discovered specific immunological pathways, such as primary immunodeficiency, an immune deficiency disorder primarily associated with B cell dysfunction [49]. These examples convincingly demonstrate that Focus can learn pathway information highly relevant to cell types, which plays a crucial role in cell type classification for spatial transcriptomics data. Enriched cell type-specific pathways based on gene important score from GSEA Preranked analysis. (a) Enriched pathway of mDC, CD8+ naive T cell, and endothelial cell. (b) Heatmap of selected cell type-specific pathway. NES: normalized enrichment score. Subgraph sampling to illustrate gene neighborhood relation Here we adopt weighted probability in Equation 4, to determine the score of the subgraph. We use the CosMx lung dataset which is also used in previous section. Based on the scores of the subgraphs, we identified the highest and lowest-scoring subgraphs for each cell type. The subgraphs with the highest scores tend to retain their structural characteristics during the contrastive learning augmentation process. Initially, we analyzed the distribution of various genes across different subgraphs. However, the distribution of the top-ranked genes in different subgraphs did not show significant differences. Additionally, previous studies have demonstrated that even within the same cell, the distribution of neighboring genes can vary across different regions. Despite the gene neighborhood network being influenced by various factors such as cell type, intracellular location, and cell state, our model indicates that higher-scoring subgraphs exhibit a more significant coexpression phenomenon and interaction network specific to certain cell types. For each cell type, we collected the highest and lowest-scoring subgraphs and analyzed the neighboring genes around each transcript. To minimize statistical errors caused by data noise, we set a threshold value of alpha = 1, removing edges where the co-occurrence frequency of genes was less than alpha. To better illustrate the subgraph scores related to each cell type, we list several high-scoring and low-scoring subgraphs associated with different cell types. In our study, we collected 1869 NSCLC cells and 1222 fibroblast cells and drew gene neighborhood network for each cell type in Fig. 3. In NSCLC cells, high-scoring subgraphs exhibit stronger neighbor connections with MZT2A, S100A6, and S100P compared to low-scoring subgraphs. MZT2A is a key gene involved in mitotic spindle formation and promotes cell proliferation [50], while S100A6 and S100P are well-known marker genes for tumor cells [51, 52]. While in the low-scoring subgraphs, DUSP5 and NDRG1 show strong connections. Many studies [53–55] have shown that DUSP5 and NDRG1 are tumor suppressors that can effectively inhibit the proliferation and metastasis of tumor cells. This aligns with the characteristic of extensive proliferation in tumor cells. In fibroblast cells, compared to low-scoring subgraphs, we found that high-scoring subgraphs exhibit strong neighbor connections among Collagen family genes such as COL9A2, COL3A1, COL1A2, COL1A1, COL14A1, and COL6A3. These Collagen genes can produce collagen proteins [56], which are crucial components of the extracellular matrix (ECM). This is consistent with the primary function of fibroblast cells. The analysis of high-scoring and low-scoring subgraphs provides a unique lens to investigate gene neighborhood relationships in spatial transcriptomics. High-scoring subgraphs often capture key gene interactions that drive critical cellular processes, such as proliferation and extracellular matrix remodeling, while low-scoring subgraphs highlight less active or potentially suppressed pathways. By comparing these subgraphs across different cell types, we can uncover functional gene clusters specific to cell states or microenvironments. This dual perspective not only enhances our understanding of cellular heterogeneity but also offers a framework for identifying potential biomarkers and therapeutic targets. Gene-neighbor relationship diagram in different subgraphs in CosMx lung dataset. (a) Gene neighborhood network in high-scoring subgraphs of NSCLC cells. (b) Gene neighborhood network in low-scoring subgraphs of NSCLC cells. (c) Gene Neighborhood Network in high-scoring subgraphs of Fibroblast cells. (d) Gene Neighborhood Network in low-scoring subgraphs of Fibroblast cells. Focus is robust to limited reference data Recognizing the challenge of acquiring extensive high-quality labeled reference data, we carry out experiments with a restricted pool of labeled reference data to assess the performance of each method. To achieve this, we devised four distinct scenarios where the query data remained constant at 10 000 cells while varying the proportions of the reference data to 10%, 40%, 70%, and 100% of the query dataset size. In order to ensure consistent findings and mitigate the influence of random variations, we systematically conduct a series of experiments across multiple samples on CosMx Lung dataset (Fig. 4). Our consistent observation is that, regardless of whether our Focus is trained with 10%, 40%, 70%, or 100% reference data, the variation in reference data proportion has a minimal impact on query performance, and accuracy consistently remains above 80%. However, all other methods exhibit a performance decline as reference data decreases, albeit to varying degrees. For instance, scDeepSort experiences the most significant performance drop across all experiments, while cellTypist is less affected by data reduction but consistently demonstrates lower accuracy across reference data scales. ACTINN appears less affected overall. To sum up, our Focus maintains an 80% accuracy level across various experiments, demonstrating robustness to reference data downsampling from 9k to 1k, as well as to the variations in reference data, thus underscoring its robustness. Robustness of Focus and other methods to the reference data size. The horizontal axis represents the proportion of the query dataset size relative to the reference dataset size. The reference dataset contains a total of 10 000 cells, and the query dataset size is scaled accordingly (e.g., 10%, 40%, 70%, and 100% of the reference dataset size). (a) Reference data: CosMx Lung5-1, Query data: CosMx Lung5-2. (b) Reference data: CosMx Lung5-3, Query data: CosMx Lung5-2. Discussion In this study, we present the Focus method, which significantly enhances cell type annotation by leveraging subcellular spatial gene neighborhood networks. Our method demonstrates superior performance compared to state-of-the-art approaches across various iST platforms, including CosMx, MERFISH, and Xenium. Specifically, Focus achieves up to a 10% increase in accuracy, even with limited labeled data. This underscores the robustness and versatility of our method in diverse experimental settings. One of the key innovations of Focus is its ability to utilize transcript’s subcellular and spatial community information. This novel approach allows for a more nuanced understanding of cellular architecture and gene expression patterns, contributing to more accurate cell type annotations. However, it is important to acknowledge that subcellular data inherently contains more noise compared to single-cell data. Additionally, the subcellular spatial mechanisms of different cell types are not yet fully elucidated, which poses challenges for interpreting complex spatial gene expression patterns. However, our study is not without limitations. It is important to acknowledge that subcellular location of image-based spatial transcriptomics of often comes with noise. Additionally, the subcellular spatial mechanisms of different cell types are not yet fully elucidated, which poses challenges for interpreting complex spatial gene expression patterns. The noise in subcellular data can sometimes obscure true biological signals, and our current understanding of subcellular spatial mechanisms is limited. Future research of Focus should focusing on refining data preprocessing techniques to mitigate noise and developing more sophisticated models to better capture subcellular spatial dynamics. Moreover, expanding the application of Focus to a broader range of cell types and tissues will be crucial for validating its generalizability and robustness. In conclusion, Focus represents a valuable advancement in cell type annotation methodologies, offering a powerful tool for the analysis of subcellular spatial transcriptomics data. By addressing the current limitations and further exploring the potential of spatial gene neighborhood networks, we can pave the way for deeper insights into cellular organization and function. This, in turn, will enhance our understanding of tissue heterogeneity and disease pathology, ultimately contributing to advancements in biomedical research and precision medicine. Key Points A graph contrastive learning model (Focus) is proposed to enhance cell type annotation on spatial transcriptomics data by leveraging subcellular spatially resolved gene neighborhood networks. A graph contrastive learning model (Focus) is proposed to enhance cell type annotation on spatial transcriptomics data by leveraging subcellular spatially resolved gene neighborhood networks. The effectiveness and robustness of our model are verified by a series of experiments on several datasets. The effectiveness and robustness of our model are verified by a series of experiments on several datasets. Our model uncovers cell-type-specific pathways by leveraging the learned importance scores for genes. Our model uncovers cell-type-specific pathways by leveraging the learned importance scores for genes. Supplementary Material Acknowledgements We thank the editor, deputy editor, and three anonymous reviewers for their insightful comments and constructive suggestions, which have greatly improved the paper. We also sincerely thank Prof. Xiaojie Qiu, Prof. Yuying Xie, Prof. Hui Liu and Prof. Jiliang Tang for their valuable feedback and suggestions that have contributed significantly to the development of this work. Contributor Information Qiaolin Lu, School of Artificial Intelligence, Jilin University, Qianjin Street 2699, 130010 Changchun, China. Jiayuan Ding, Department of Computer Science and Engineering, Michigan State University, 220 Trowbridge Rd, East Lansing, MI 48824, United States. Lingxiao Li, Department, Boston University, Commonwealth Ave, Boston, MA 02215, United States. Yi Chang, School of Artificial Intelligence, Jilin University, Qianjin Street 2699, 130010 Changchun, China; International Center of Future Science, Jilin University, Qianjin Street 2699, 130010 Changchun, China; Engineering Research Center of Knowledge-Driven Human-Machine Intelligence, Jilin University, Qianjin Street 2699, 130010 Changchun, China. Funding This work is supported by the National Key Research and Development Program of China (No. 2023YFF0905400) and the National Natural Science Foundation of China (No. U2341229). Conflict of interest: The authors declare no competing interests. Data availability Focus is freely accessible at https://github.com/OmicsML/focus. CosMx SMI data are available at https://nanostring.com /products/cosmx-spatial-molecular-imager/ffpe-dataset/. MERFISH MOP data are available at https://download.brainimagelibrary.org/cf/1c/cf1c1a431ef8d021/. Xenium Human DCIS data are available at https://www.10xgenomics.com/products/xenium-in-situ/preview-dataset-human-breast. References Associated Data Supplementary Materials Data Availability Statement Focus is freely accessible at https://github.com/OmicsML/focus. CosMx SMI data are available at https://nanostring.com /products/cosmx-spatial-molecular-imager/ffpe-dataset/. MERFISH MOP data are available at https://download.brainimagelibrary.org/cf/1c/cf1c1a431ef8d021/. Xenium Human DCIS data are available at https://www.10xgenomics.com/products/xenium-in-situ/preview-dataset-human-breast.