Abstract
The spatial interactions between malignant and immune cells in the tumor microenvironment are important for tumor immunobiology and patient outcomes. However, analytical tools that can extract rigorous yet interpretable spatial features and link them to patient outcomes remain limited. We propose a framework integrating TDA with statistical approaches to extract interpretable spatial features characterizing malignant-immune interactions. We introduce Topological Malignant Region (TopMR), which uses topological persistence to automatically define regions of malignant cells, providing an objective reference for spatial analysis even when tumor boundaries are ambiguous. Global-scale infiltration is quantified using signed distances from immune cells to the TopMR boundary and local-scale interactions are captured via malignant cell density around individual immune cells. These global and local features are integrated into a unified signed distance-density () space, enabling comprehensive characterization of spatial patterns. We apply this framework to high-resolution multiplex immunofluorescence images of diffuse large B-cell lymphoma, analyzing both malignant-enriched and tumor border regions. Two-stage hierarchical clustering stratifies patients based on spatial interaction patterns, revealing associations with survival outcomes. This framework provides an end-to-end pipeline from spatial feature extraction to clinical interpretation, suggesting how region-aware spatial analysis can capture biologically meaningful patterns linked to patient survival.
Subject terms: Cancer, Computational biology and bioinformatics, Immunology, Oncology
Introduction
Elucidating the spatial interactions between malignant and immune cells in the tumor microenvironment (TME) is critical for understanding tumor progression and predicting patient outcomes1,2. The spatial distribution of these cells reflects complex biological processes such as immune infiltration and evasion, and spatial analysis can help disentangle these processes and link them to clinical prognosis3,4. From an analytical perspective, spatial analysis within the TME typically involves quantifying spatial relationships among different cell populations (e.g., tumor and immune cells) and interpreting how these quantified patterns reflect their interactions. Therefore, developing metrics that provide both rigorous quantification and biological interpretability is essential.
Numerous studies have developed methods to extract spatial features from cellular imaging data to correlate these features with patient outcomes. Point-based analyses have quantified tumor-immune organization using cell densities and nearest-neighbor statistics5, whereas graph-based models have represented cellular neighborhoods to capture structural patterns and enable patient clustering6. Another integrative framework has outlined major categories of spatial analysis, such as localization-, distance-, and graph-based metrics, highlighting their potential clinical relevance7. In diffuse large B-cell lymphoma, combining spatial descriptors (e.g., Ripley’s L-function) with conventional cell counts and densities has yielded complementary prognostic insights8. These approaches predominantly rely on cell-to-cell proximity, capturing local spatial relationships within limited neighborhoods.
Beyond local interactions, some studies have shown that region- and boundary-scale organization, such as tumor-stroma rims or hypoxic cores, can strongly influence immune exclusion, infiltration, and clinical outcomes, sometimes outperforming nearest-neighbor metrics in a context-dependent manner3,9–11. Indeed, direct cell-to-cell distances are often biased by local sampling density and structural voids: dense malignant regions yield smaller distances, whereas stromal gaps inflate them. Without accounting for spatial inhomogeneity, such proximity measures may capture sampling artifacts rather than true biological structure12. These issues motivate moving beyond local metrics toward mesoscopic, region-aware representations that are both robust and biologically interpretable.
Building on this motivation, recent studies have begun to consider regions of cells to identify spatial interactions between tumor and immune cells. A workflow13 characterized spatial distributions of multiple immune markers within pathologist-annotated tissue regions using point pattern statistics and cluster analysis. A statistical framework14 extended Ripley’s K-function to quantify region-to-cell rather than cell-to-cell interactions by computing distances from tumor-defined regions and applying K-function analyses across levelsets. The method effectively showed spatial patterns in histopathological images across patients. Although the tumor region was manually selected by experts, this work showed the potential of region-to-cell approaches for investigating spatial patterns within the TME. Additionally, Topological Data Analysis (TDA)15–17 has emerged as a distinct mathematical framework that characterizes spatial organization through topological features rather than conventional statistics. One approach, based on chromatic alpha complexes, quantifies spatial relationships among differently labeled cells by tracking the scale at which shared empty regions appear as virtual cell boundaries expand18. Another framework employs Dowker and Witness persistent homology to capture proximity and clustering patterns among synthetic cell populations19. Dowker persistence encodes pairwise interactions, whereas Witness persistence treats one population as landmarks to assess the spatial distribution of others. Although not yet applied to biological data, these topology-based approaches may possibly offer a rigorous mathematical framework for quantifying intermixing between cell types.
In this study, we propose a TDA-based integrative framework that combines topological and statistical approaches to extract interpretable spatial interaction features from the TME and relate them to clinical outcomes. Our framework comprises four components, each designed to address a key limitation of traditional spatial analyses: (1) we define a Topological Malignant Region (TopMR) to reconstruct the global organization of malignant cells, providing a topologically defined tumor regions even when explicit margins are absent or irregular; (2) we extract global and local interaction features—global features quantify immune infiltration through signed distances from the TopMR and local features capture malignant cell density around individual immune cells, reflecting micro-scale heterogeneity; (3) we employ Ball Mapper20 to summarize the resulting high-dimensional interaction space, enabling visualization and micro-clusters of spatial patterns across all datasets; and (4) we link these summarized interaction patterns to patient survival using a two-stage hierarchical clustering approach that accounts for varying numbers of data samples per patient and automates parameter selection. Together, these components combine topological abstraction, quantitative analysis, and biological interpretability to offer a coherent approach for characterizing tumor-immune interaction with potential clinical relevance. Finally, we apply our framework to point cloud data derived from high-resolution multiplex immunofluorescence (mIF) images of diffuse large B-cell lymphoma (DLBCL), annotated as either malignant cell-enriched or tumor border regions exhibiting distinct spatial organizations. TopMR robustly captures diverse global morphologies of malignant cell organization across both image types. By integrating global and local interaction features, our framework captures distinct spatial interaction patterns that are indicative of differences in patient survival outcomes.
Results
Building on the framework outlined in the Introduction, the following five subsections develop and present each of its components in turn. The framework operates on point clouds extracted from multiplex immunofluorescence (mIF) images of primary central nervous system diffuse large B-cell lymphoma (DLBCL); the data acquisition, segmentation, pathologist annotation, and phenotype aggregation rationale are described in the Methods section. Here, we begin by formalizing the input as the mathematical objects used throughout the methodological development that follows. Let us denote malignant cell’s (PAX5+) and the ith aggregated immune cell’s locations as point clouds and in a mIF image (Ω), respectively:
| 1 |
| 2 |
where
| 3 |
Throughout the following subsections, serves as the reference population for region reconstruction, while provides the immune cells whose spatial relationship to that region we quantify.
TopMR captures global malignant architecture and yields interpretable signed distances
We first define a topology-based representation of the global organization of , which we call the Topological Malignant Region (TopMR) (e.g. Fig. 1), and we then show that the construction adapts robustly across diverse spatial configurations of malignant cells.
Fig. 1. Topological malignant region (TopMR): global spatial shapes of malignant cell distributions.

a A raw multiplex immunofluorescence (source:8). The highlighted area by the yellow rectangle is presented with more details in the second row. b Point clouds of cell centers colored by cell type: olive (malignant), red (CD3+CD8−PD-1−), blue (CD3+CD8−PD-1+), magenta (CD163+PD-L1−), and brown (CD163+PD-L1+) (see Table 1). c TopMR (olive region) overlaid on (a) demonstrates global spatial shapes of malignant cell distributions in (a) and (b). (i) illustrates different phenotypes on yellow box in (a). (ii) shows the segmented cells. (iii) presents the TopMR on (ii). (iv) illustrates the spatial context between immune cells and TopMR. Image segmentation and phenotyping were performed using InForm software (Akoya Biosciences).
Malignant and immune cells in tissue are spatially non-random due to underlying biological architecture. Structural components such as necrotic zones, stromal regions, vascular lumens, and non-malignant compartments often create spatial voids or clustered distributions (Figs. 3 and 5). We therefore propose a method to capture underlying spatial organization from the given point cloud, providing robustness against heterogeneous or irregular cell distributions. It enables the analysis to focus on biologically meaningful malignant-immune interactions rather than structural biases.
Fig. 3. TopMR and signed distance functions across diverse malignant cell distributions.

Each column shows a distinct spatial configuration of malignant cells (a), the corresponding TopMR (b), and the resulting signed distance function (c). For better visualization of the TopMR boundary (where the signed distance is zero), the color scale is set symmetrically for positive and negative values. Red and blue indicate negative and positive distances, respectively, highlighting regions inside (infiltrated) and outside (not infiltrated) the TopMR; its boundary is shown in gray.
Fig. 5. Comparison of three spatial patterns.

Each column represents the three cases in the subsection features distinguish intermixed, segregated and partially mixed spatial patterns: intermixed (first column), segregated (second), and partially mixed (third). The first row shows point clouds (malignant cells, coral; CD163+ macrophages, teal). The second and third rows display distributions in the and spaces with e1 and e2. The fourth row presents Ripley’s L-function (observed, red; CSR, black dashed; confidence interval, blue). The fifth row shows the generalized Ripley’s K-function across 129 distance zones (10 μm width) with statistical indices (ACI, SAI, ASI, δa); green and red bars indicate cell accumulation and depletion, respectively, and gray bars denote statistically insignificant values.
To extract the spatial organization, we employ tools from TDA. In a Vietoris-Rips filtration, a distance threshold is gradually increased, and all pairs of points closer than this threshold are connected by an edge. Whenever every pair within a group of points lies within the threshold, the group forms a simplex: an edge for two points, a triangle for three, a tetrahedron for four, and so on. The collection of all such simplices is a simplicial complex, which generalizes a network by recording not only pairwise connections (edges) but also higher-order relationships among points that are all pairwise within the threshold. Because the construction depends only on pairwise distances, it promotes connectivity and provides robust global shape extraction. As the threshold grows, topological structures such as connected components (H0) and loops (H1) emerge and subsequently disappear (e.g., components merge and loops are filled in by higher-dimensional simplices). This entire process is summarized in a persistence diagram (PD), which records the birth and death of each such structure as a function of the distance threshold15,16.
Small perturbations in point positions produce only small changes in pairwise distances. Therefore, birth and death values shift only slightly, making PDs stable under positional noise such as cell-center detection, segmentation errors, and a small fraction of phenotype misclassifications. Structures with long lifetimes (large gap between birth and death) can represent robust spatial patterns of the point cloud, whereas short-lived structures near the diagonal of the PD typically reflect noise or local irregularities. Ideally, the PD should cover all scales, but this becomes computationally challenging for images with a large number of points21. Hence, we set a practical limit on the maximum length scale:
| 4 |
where is the number of points in (Eq. (1)), ∣Ω∣ is the area of the mIF image domain Ω, and C = 3. This scale, derived from the square root of the inverse point density, adapts to each image to account for variation in malignant cell counts. Such an adaptive approach ensures computational efficiency across images with differing cell counts. The constant C is chosen to balance computational efficiency with the ability to capture meaningful topological features. If C is too small, the number of generated simplices is insufficient to reflect relevant structures. On the other hand, if C is too large, it connects nearly all points, resulting in high computational cost and reduced biological interpretability. In this study, the value of C was determined empirically based on practical performance considerations and observed performance.
Now, we obtain the PD using (Eq. (4)). Each point (b, d) in the PD marks the birth and death of a topological feature. We select the most persistent feature (the dominant topological structure in ), that is, the point in H1 with the longest finite lifetime, given by
| 5 |
Motivated by the idea that the shape corresponding to the longest finite lifetime in the PD reflects the most persistent topological structure of the distribution, we take the midpoint between bm and dm (Fig. 2). This value is constrained by a biologically relevant upper bound, Ø, (Eq. (6)), because long-range connections between malignant cells lack biological plausibility. Given the average malignant cell diameter of ~25 μm in DLBCL22, we set Ø ≈ 50 μm to account for potential segmentation errors in cell center detection. Also, Ø ≈ 50 μm was found as the most informative short-range interaction length in the previous study8.
Fig. 2. Persistence diagrams and TopMR for point clouds with density difference.

Point clouds (left column) with 1 ⋅ 103 (top) and 4 ⋅ 103 (bottom) points are in the same domain. The corresponding persistence diagrams (middle colume) are presented by the maximum length scale in Eq. (4), (top) and 5.69 ⋅ 10−2 (bottom). From the most persistent feature (Eq. (5)), (3.66 ⋅ 10−2, 7.30 ⋅ 10−2) (top) and (2.95 ⋅ 10−2, 5.58 ⋅ 10−2) (bottom), the characteristic length ℓchr (Eq. (6)) is calculated with ℓcll = ∞ in these examples. The corresponding TopMR (right column) is visualized, which robustly shows an annulus shape.
Finally, using the characteristic length,
| 6 |
we reconstruct the global spatial shape of malignant cells by the union of 2D simplices (triangles), which we refer to as TopMR. Figure 1 demonstrates that TopMR captures the global spatial shape of malignant cells. The second row (yellow rectangle) shows that while most immune cells (CD3+CD8−PD-1− and CD163+PD-L1+) lie outside TopMR, some immune cells infiltrate into TopMR (panel (iv) in Fig. 1), which will be quantified in terms of malignant-immune interactions in the subsections that follow.
To examine how TopMR responds to qualitatively distinct malignant cell distributions, we apply the construction above to representative DLBCL examples. We present how the proposed TopMR effectively captures the global spatial structure of malignant cell distributions and provides meaningful signed distance functions that reflect spatial interaction patterns. In the first column of Fig. 3, malignant cells appear generally dense but contain several rounded voids, regions where no malignant cells are present. The corresponding TopMR successfully captures the overall spatial shape, considering these voids. The signed distance function shows high positive values inside these voids, indicating that immune cells located there are far from malignant region, interpretable as regions of weak infiltration. The second column shows a more complex case, where malignant cells form a ring-like structure with a non-uniform spatial distribution. Some areas are densely populated while others are sparse. The resulting TopMR identifies the global ring pattern and extract only the most concentrated regions into large area of TopMR. The signed distance function from this TopMR boundary reflects these variations, indicating that distance computations remain robust even under highly non-uniform distributions. In the third column, malignant cells are sparsely scattered with no prominent structure. In this case, the TopMR captures only small and isolated regions. The corresponding signed distance function shows small negative values, suggesting weak spatial attraction to the malignant regions. Overall, these results illustrate that TopMR effectively captures diverse spatial patterns such as dense with voids, non-uniform density, or sparse. Also it provides interpretable signed distance function that reflect immune cell infiltration relative to the malignant region defined by their configuration.
Signed distance-density space quantifies malignant-immune interaction patterns
With TopMR providing a region-level reference for , we now construct the spatial features that quantify malignant-immune interactions. We define complementary global and local features, the signed distance from the TopMR boundary and the local malignant cell density around each immune cell, and combine them into a unified feature space and an image-level descriptor that will serve as input to the topological summarization presented later.
Global feature: computing signed distance fields from TopMR boundaries
In the TME, immune cell positioning can be influenced by signaling gradients that emerge from the collective spatial arrangement of malignant cells can strongly influence immune cell positioning23,24. This motivates a region-to-cell (malignant region) perspective, rather than a purely cell-to-cell (e.g., nearest-neighbor) view, for capturing these relationships more robustly. Accordingly, we quantify malignant-immune spatial interactions using signed distances from the TopMR boundary to each immune cell (TopMR-to-cell), since TopMR captures regions of malignant cells.
Denoting TopMR as the region , we compute the distance function d(x) from TopMR boundary () using the eikonal equation 25. In order to quantify the infiltration of immune cells , we measure a signed distance:
| 7 |
Note that φ(x) is negative if the cell is inside TopMR (infiltration or potential attraction) and positive if outside (no infiltration).
Local feature: estimating local malignant cell density around immune cells
We also compute local malignant cell density to distinguish cases where immune cells have similar infiltration levels into the TopMR but different surrounding malignant cell counts. A Gaussian function is used on the square Wω(r) (side: ω = 4 Ø, center: ):
| 8 |
where σ = 0.2ω and c−1 is a constant , normalizing over the square. It ensures that the total weight of the Gaussian function over the square equals 1, making Gr(x) a probability density function. Now, we compute , where Kσ is the Gaussian kernel with the standard deviation σ and the convolution operation (*). We then rescale to match the range of the signed distance φ(x), ensuring that both features contribute equally. From the global maximum (φM) and minimum (φm) of φ(qi) and the global maximum () of over all and across all mIF images, the density function is defined by
| 9 |
Constructing the signed distance-density () space and image-level features
To quantify malignant-immune cell interactions using both global and local features, we define the signed distance-density space, for in Eq. (3):
| 10 |
where φ(qi) and ψ(qi) denote the signed distance and density functions, respectively, for each immune cell of the aggregated phenotype qi. These measures are complementary yet independent, capturing distinct aspects of malignant-immune interactions in the subsection features distinguish intermixed, segregated and partially mixed spatial patterns. While signed distance indicates an immune cell’s position relative to the TopMR boundary, the density reflects the local concentration of malignant cells around the immune cell.
To summarize patterns in , we apply principal component analysis (PCA), which is parameter-free and yields a fixed set of features from the first two principal components. This also brings interpretable spatial features with stability: small changes in produce only small changes in the PCA features, providing an ideal input for subsequent analysis of summarizing interaction patterns with with Ball Mapper graphs.
From the PCA output, we define the following row vector:
| 11 |
where , , and are 2D vectors; averages of signed distance and density values in space, the first and the second principle components of PCA, respectively. For the nth image, we construct a feature vector by concatenating the three row vectors:
| 12 |
The resulting vectors summarize the spatial characteristics of malignant-immune interactions and are used for grouping and comparison across images. For clinical interpretation, we later return to the full set of immune phenotypes in the subsection Spatial interaction patterns in space associate with patient survival. We include an image only if ∣Qi∣≥2 for all . Based on this, 972 out of 1337 images are analyzed (687 TR and 285 BR images). Stacking the image-level row vectors vertically yields the feature matrix:
| 13 |
We now show the resulting construction on two representative DLBCL images, contrasting a malignant-enriched (TR) and a tumor-border (BR) configuration. We describe the steps of constructing the space using DLBCL data. Starting from point clouds, we generate the TopMR, compute the signed distance and local density functions, and build the space. We then present this process using two representative examples: TR image (Fig. 4a) and BR image (Fig. 4b). These examples are selected to illustrate how captures spatial malignant-immune interactions for contrasting spatial contexts. Figure 4a shows densely packed malignant cells with immune cells located near the TopMR. Figure 4b shows a sparser, more inhomogeneous malignant distribution, with immune cells positioned farther from the TopMR.
Fig. 4. Distance and density functions of point clouds from images.

a and BR image (b): Panels (i)–(v) show analysis using all cell phenotypes, while (vi)–(viii) use aggregated immune phenotypes (see Table 1 for cell type colors). (i) The original point cloud in TR image. (ii) Malignant cell distributions. (iii) TopMR from (ii). (iv) Signed distance function (immune cells overlaid), illustrating immune infiltration (red = inside TopMR, blue = outside). (v) Malignant cell density function around immune cells (purple-to-scarlet colormap for low to high density). (Two example immune cells are highlighted in gray in (i) and circled in (iv)–(v); see main text for details.) (vi)–(viii) spaces (Eq. (10)) for each aggregated immune phenotype (Eq. (3)). Vectors and are drawn at mi (Eq. (11)) in each space, visualizing the corresponding 18D feature from Eq. (12).
The signed distance functions in Fig. 4a(iv), b(iv) illustrate the spatial positioning of immune cells relative to the TopMR boundary. Red indicates negative values (deeper infiltration), blue indicates positive values (large distance), and white denotes proximity to the boundary. This spatial information is complemented by the local density of malignant cells around immune cells (purple-to-scarlet color bar) where scarlet signifies high malignant cell density. Although they are often correlated, discrepancies can arise; immune cells at similar distances from the TopMR boundary may have different local malignant cell densities. For example, in Fig. 4a(i), two CD8+ T cells (PD-1−) (small gray disks), lie near the TopMR boundary as shown in the panel (a)-(iv) (black circles). However, they exhibit distinct density values as shown in the panel (a)-(v). This highlights how these measures provide a complementary view of malignant-immune cell interactions.
We aggregate immune cell phenotypes when constructing the space. The resulting patterns for two distinct malignant cell configurations are presented on the panels (vi), (vii), and (viii) in Fig. 4a, b. TR image shows a strong interaction between immune and malignant cells, reflected as a nearly linear pattern. Conversely, BR image shows that immune cells appear enriched at larger distances from the TopMR with sparse malignant cells nearby, corresponding to an exponential-decay pattern. Both patterns can be effectively described by obtained from PCA in Eq. (11): vectors pointing toward the top-left indicate strong interactions (typical of TR images), while vectors pointing toward the bottom-right imply weak interactions (typical of BR images). However, this interpretation does not always hold for all TR and BR images because cell distribution can change continuously to diverse and atypical configurations.
features distinguish intermixed, segregated and partially mixed spatial patterns
We evaluate the proposed signed distance-density metric () against minimum distance-density (), Ripley’s L-function, and a generalized Ripley’s K-function. We assess these methods across three spatial distribution patterns (Fig. 5). In Case 1 (Intermixed), immune cells are distributed throughout the malignant cell population. In Case 2 (Segregated), immune cells remain spatially separated from the malignant cell distribution. In Case 3 (Partially mixed), immune cells show partial intermingling with malignant cells while maintaining some regional separation. Mathematical expressions for these methods and additional comparisons using Ripley’s K- or G-functions, as well as our TopMR-based distance and density functions, are provided by Supplementary Figs. S1, S2 in Section S2 of Supplementary Information.
Proposed space
In Case 1, the space (first panel in the second row of Fig. 5) exhibits a linear pattern, indicating strong malignant-immune interaction. The average signed distance (mh < 0), that is, the negative value of mh explains that most immune cells are located within TopMR, while the high mv value indicates that many malignant cells are present near immune cells. The principal direction e1 points to the top-left, indicating that immune cells deeply infiltrate TopMR in regions of high malignant cell density. In Case 2 (second panel in the second row), the space displays an exponential-decay pattern with high mh and low mv, indicating weak spatial interaction. Case 3 (third panel in the second row) shows that most immune cells (CD163+) are located in the central region with few malignant cells. However, along the boundaries of this central region, malignant cells are interspersed with CD163+ cells. This heterogeneous pattern is captured in the space, where the distribution exhibits a pattern intermediate between the linear pattern in Case 1 and the exponential-decay in Case 2. The positive mh value indicates that most immune cells are located outside TopMR, consistent with the central clustering of CD163+ cells. However, the top-left orientation of e1 indicates that some immune cells deeply infiltrate TopMR and interact with malignant cells in high-density regions. The mentioned three spatial distribution patterns can be clearly distinguishable by reading the sign of mh and the direction of e1; see Supplementary Table S1 in Supplementary Section S3 of Supplementary Information.
space
For direct comparison, we construct a minimum distance-density space (), which uses the same density calculation as but replaces signed distance with minimum distance from each CD163+ cell to the nearest malignant cell. In Case 1, the space (first panel in the third row) shows a linear pattern similar to , with an average minimum distance, mh = 27.31 (see Supplementary Table S1 of Supplementary Information). In Case 2 (second panel in the third row), displays an exponential-decay pattern, similar to the proposed method. In Case 3 (third panel in the third row), shows an intermediate pattern with mh = 54.45. However, does not indicate whether immune cells are positioned inside or outside the malignant cell region. Since lacks this information, similar patterns can arise from either slightly shifted cell-to-cell distances or fundamentally different spatial organizations, making it difficult to determine whether Cases 1 and 3 represent similar spatial patterns with different cell-to-cell distances or qualitatively distinct organizations.
Ripley’s L-function
In Case 1, Ripley’s L-function (first panel in the fourth row) exceeds the theoretical complete spatial randomness (CSR) line at larger radii (approximately r > 60), suggesting global clustering or attraction, consistent with previous findings8. In Case 2, the L-function remains below the CSR line, indicating spatial separation between the two populations. In Case 3, the L-function lies far below the CSR line, likely due to local spatial isolation of the two cell types. Since this method relies on global spatial statistics and assumes homogeneity, it provides limited information for spatially heterogeneous or unevenly distributed patterns.
Generalized Ripley’s K-function
The generalized Ripley’s K-function14 was originally defined using only positive distances from a region. Since our framework requires both positive and negative distances from TopMR, we use our signed distance metric in this computation. The distance range for the generalized K-function is set using the global minimum and maximum distances observed across all three cases, so that a common range is used to account for differences in image size. In Case 1 (first panel in the fifth row), only green bars are observed across all distance zones, indicating an excess of CD163+ cells relative to a uniform reference (cell accumulation). In Case 2 (second panel in the fifth row), gray bars (statistically unreliable estimates) dominate at short distances because most CD163+ cells lie far from malignant cells, leaving too few neighboring points to compute stable statistics near the malignant region. Green bars appear only at large distances, indicating accumulation far from malignant cells; however, such long-distance accumulation is difficult to interpret biologically in terms of local malignant-immune interaction. In Case 3 (third panel in the fifth row), red bars (depletion) appear at short distances and green bars (accumulation) emerge at larger distances. This transition from depletion near the malignant region to accumulation farther away reflects the partially mixed pattern and provides more nuanced information than Ripley’s L-function in this example. Despite these advantages, the generalized Ripley’s K-function poses practical challenges for large-scale analysis. When a single global distance range is applied across images of varying size and malignant-immune separation, many images may produce numerous gray bars (unreliable estimates), which become zeros in the resulting feature matrix. This leads to highly sparse feature vectors, complicating clustering or classification. Conversely, if the distance range is adapted separately for each image, the physical meaning of the distance axis is no longer consistent across images: a given column in the feature matrix no longer corresponds to a fixed distance scale. In that case, feature values remain dense but lose direct interpretability in terms of absolute distances from the malignant region.
In summary, distinguishes these three spatial patterns in an interpretable manner. The quantitative measures mh, mv, and e1 in the proposed feature matrix enable effective characterization of both the extent and directionality of immune infiltration across all three cases. By explicitly encoding signed distances from the TopMR boundary and evaluating tumor-cell density at the locations of immune cells along this distance axis, and by using TopMR as a global representation of malignant-cell regions, our method enables a quantitative categorization of the three cases that is biologically interpretable as high, low, or heterogeneous infiltration.
Ball Mapper reveals continuous trajectories of malignant-immune interaction
Having quantified the per-image malignant-immune interaction as 18-dimensional vectors, we summarize their organization across all images using Ball Mapper, a topological method that represents a high-dimensional dataset as a graph of overlapping micro-clusters; the graph then provides the basis for our interpretation on the DLBCL feature matrix.
The input is the feature matrix (Eq. (13)) whose rows capture immune cell infiltration and the local concentration of malignant cells across three aggregated phenotypes. Using the cosine dissimilarity and the parameter ϵ of the spatial granularity, Ball Mapper represents this dataset as a simplified graph with nodes and edges (e.g. Fig. 6). A node consists of row vectors (images) with similar characteristics; thus, each node in the graph can be regarded as a micro-cluster in the feature space. An edge between nodes indicates that there is at least one common feature shared by nodes. Adjusting ϵ allows control over the resolution of the graph, with smaller values producing a more detailed graph and larger values generating broader connections among features. A sensitivity analysis of the Ball Mapper graph over a ±50% range of ϵ0 = 4.5 ⋅ 10−2 shows that (i) ϵ0 is the value at which the dominant connected component forms, and (ii) the pairwise co-membership of samples, which samples share at least one node, is locally stable in a neighborhood of this value. Because Ball Mapper produces an overlapping cover rather than a partition, stability is assessed at the level of sample pairs rather than node identities. Full details are provided in Supplementary Section S8 of the Supplementary Information.
Fig. 6. Ball Mapper of feature matrix.

The top-left panel shows TR (malignant-enriched, value = 1) and BR (tumor-border, value = 0) images, with nodes colored by the mean assigned value (red = TR, blue = BR). In the 18D feature space, the graph summarizes the distribution of TR and BR images based on feature similarity (see Eq. (12)). The remaining panels visualize the vertical component of the first principal component () for each aggregated phenotype i using the same color scale, with corresponding value distributions shown alongside.
We now interpret the Ball Mapper graph obtained on the DLBCL feature matrix. We elaborate the meaning of the Ball Mapper graphs (Fig. 6) of the feature matrix (Eq. (13)). We label seven visually distinct branches as Flares only for convenience of description. The color on a node means the average of assigned scalar values on rows (images) in the node. For example, in the top-left panel, we assign value 1 to TR images and 0 to BR images; nodes are colored by the average value. Thus, a red node contains all TR images, a blue node all BR images, and intermediate colors indicate a mix of TR and BR images. Now, it is clear to see that Flares from 1 and 2 mainly consist of TR images, though not exclusively.
In the other panels of Fig. 6, we choose the color of images as for . Consider Flare 3 across all panels simultaneously. Examining the red nodes in Flare 3 (top-left panel), we find these nodes predominantly classified as TR images. Correspondingly, their associated panels indicate large magnitudes of , suggesting a nearly linear pattern in the space. However, some nodes in Flare 3 with similar patterns also include BR images. This shows that both BR and TR images can share comparable patterns under the cosine dissimilarity measure. In Flare 2, nodes are mostly TR images, but shows a very different value than the other two immune cells. In other words, even though two images from Flares 2 and 3 are both annotated as TR, their spatial patterns in the space can be different.
These observations illustrate that three typical geometric patterns in space, such as the panels (vi), (vii), and (viii) in Fig. 4a or b, do not exhaustively describe all TR or BR images. The Ball Mapper graph reveals TR and BR images that deviate from, or interpolate between, these patterns, and provides a clear way to identify such intermediate cases in the high-dimensional feature space. Along each flare, node colors and feature values vary gradually, indicating that Ball Mapper organizes images along continuous trajectories of malignant-immune interaction patterns in the space. This continuity arises because the summary features (Eq. (11)) used to construct the Ball Mapper graph change smoothly under moderate perturbations of the underlying distributions, so small changes in spatial patterns translate into small movements along the flares.
We also examine dimensionality reduction methods, including Uniform Manifold Approximation and Projection (UMAP)26 and Multidimensional Scaling (MDS)27, applied to the same feature matrix (Eq. (13)). (See also results of t-SNE28 and PCA on Supplementary Fig. S3 in Supplementary Section S4 of Supplementary Information.) As shown in Figs. 7, UMAP shows visually separated clusters with some consistent properties in , , and across clusters. However, tumor and border images remain mixed within all clusters. While UMAP’s compact clustering is generally advantageous for clustering tasks, the discrete, isolated nature of these clusters makes it difficult to analyze the continuous change of spatial patterns between clusters. Consequently, this approach can limit to analyze information about the heterogeneity within and between tumor and border images, thereby restricting the ability to address the spatial diversity inherent in our data. In the MDS results, points in the reduced space appear to follow gradual transitions for , , and . However, tumor and border images are quite mixed in the reduced space. Moreover, many images concentrate in the upper region, forming a large aggregation that obscures finer distinctions between images with different spatial patterns.
Fig. 7. UMAP and MDS of feature matrix.

The four graphs on the left and right of the dotted line are the UMAP and MDS results of feature matrix (Eq. (13)) onto 2D coordinates, respectively. For 972 points, the color of panel (i) is red = TR image and blue = BR image. We use the color of panels (ii), (iii), and (iv) is the vertical component of the first principal component () for each aggregated phenotype i. UMAP fragments continuous transitions of malignant-immune cell interaction into clusters. MDS shows continuous transitions of , but it is difficult to distinguish the information on panels (iii) and (iv).
In contrast, the Ball Mapper is not a dimensionality reduction method and thus avoids the information loss inherent in mapping high-dimensional data into a low-dimensional space. The Ball Mapper graph preserves local connectivity directly in the original feature space, capturing continuous transitions in spatial interaction patterns without imposing artificial separations. This topologically faithful representation aligns naturally with the continuous heterogeneity of malignant-immune cell interactions and provides a more interpretable foundation for subsequent survival-linked analysis.
Spatial interaction patterns in space associate with patient survival
In this section, we assess whether the spatial interaction patterns identified above associate with patient survival outcomes. While Ball Mapper effectively captures similarity among 18D feature vectors from images, it operates at the image-level rather than the patient-level. Given the variable number of images per patient (ranging from 3 to 48), directly associating Ball Mapper nodes with survival outcomes (e.g., by averaging survival times across images in each node) would be biased. To address this, we adopt a two-stage hierarchical clustering (HC) strategy, using Euclidean distance with Ward linkage. Stage 1: we cluster images by their spatial interaction patterns in nodes of the Ball Mapper graph. Stage 2: For each patient, we compute the normalized distribution of their images across the clusters obtained from Stage 1. We then group patients by how their images distribute across clusters, i.e., patients with similar image distributions are grouped together. The two-stage HC yields patient-level clusters that can be used for Kaplan–Meier (KM) survival analysis.
We therefore require an algorithm for choosing cluster numbers at both stages and for providing statistical stability. To more fully explore the feature geometry in the 18D space and assess stability, we rerun Ball Mapper multiple times after randomly permuting the rows of the feature matrix (Eq. (13)). These permutations leave the data unchanged but produce complementary coverings, allowing us to observe the same structure in high-dimensional space from multiple views and assess which patterns are stable. With the multiple runs with permuted feature matrices, we determine the optimal number of clusters for both stages based on p-values from survival analysis rather than selecting them manually. Using this approach, we can both strengthen the statistical reliability of Ball Mapper and inform the optimal number of clusters for HC, thus combining the strengths of topological and statistical methods29.
To perform this analysis, we generate ∣J∣ = 1000 shuffled versions of the feature matrix by randomly permuting its row order using a uniform distribution. Let J denote the index set of these shuffled matrices. For each pair (K, L) of positive integers representing candidate cluster numbers, we apply the following procedure to each shuffled matrix indexed by j ∈ J:
Graph construction: Apply Ball Mapper with fixed ϵ0 to the jth feature matrix, yielding a graph with Nj nodes.
Node-level averaged features: For each node, we compute the average of the 18D feature vectors in Eq. (12) assigned to it, resulting in an 18 × Nj matrix.
Stage 1 image-level clustering: We apply hierarchical clustering with K clusters to the columns of the 18 × Nj matrix.
Stage 2 patient-level clustering: For each patient, we compute the normalized count of their images in each of the K clusters, yielding a K × Q matrix, where Q is the number of patients. We then apply hierarchical clustering with L clusters to the columns of this matrix.
Survival analysis: We compute KM survival analysis for the L patient clusters and p-value (log-rank test) pj(K, L).
From the steps above, in order to achieve a statistically meaningful analysis, we count the number of matrices whose KM analysis yields a p-value pj(K, L)≤δ(= 0.05):
| 14 |
For reliable interpretation of survival-related features, we consider only patient clusters containing at least 10 patients, referring to these as valid clusters. For each matrix j ∈ J, we count the total number of patients belonging to these valid clusters, denoted by sj(K, L). We then sum these patient counts across all matrices, (see the Supplementary Algorithm 1 in Supplementary Section S1 of the Supplementary Information).
Finally, we determine the optimal numbers of clusters K* and L* by maximizing the statistical significance and robustness of patient grouping as follows:
| 15 |
where , , T is the total number of patients. In two-stage HC, (K*, L*) identifies the most statistically robust clustering arrangement that includes at least half of the patients.
We integrate spatial interaction patterns with survival analysis to investigate their association with patient outcomes. For our data, the total number of patients is T = 78 in Eq. (15), with optimal cluster numbers (K*, L*) = (8, 12).
Figure 8 shows a two-stage HC result from the jth shuffled feature matrix with pj(K*, L*)≤δ. Stage 1 identifies 8 Node Clusters (NCs), differentiated by averaged 18D features on nodes of Ball Mapper graph (Fig. 8a). Stage 2 distinguishes these into 12 Patient Clusters (PCs) (Fig. 8b), with survival probabilities shown in Fig. 8c. Among these PCs, PC1 and PC9 (containing ≥10 patients) are selected as valid patient clusters. Their node distributions (Fig. 8b) show PC1 predominantly linked to NC1 and PC9 to NC7, where these NCs exhibit the highest average composition among all NCs for patients within each PC. We designate these as dominant NCs for each patient cluster. Since each NC comprises multiple Ball Mapper nodes that track corresponding point cloud data, we computed and averaged spatial features (mean distance, density, principal components) for all phenotypes across these nodes. These averaged features and BR ratios (the proportion of border-annotated images for each patient in valid PCs) are then linked to survival probabilities from KM analysis. We repeat this procedure for all shuffled feature matrices satisfying pj(K*, L*)≤δ and aggregate the results to examine relationships between spatial features and survival outcomes (detailed workflow (Supplementary Fig. S4) in Supplementary Section S5 of Supplementary Information).
Fig. 8. Clustering of node features and patient groups with survival analysis.

a Heatmap generated from the feature by node matrix, showing the average values of each feature (rows) across the node numbers (columns). Hierarchical clustering is performed using Euclidean distance with the 8 clusters, named NC by different colors. b Heatmap of the NC frequency by patient matrix, column-scaled and clustered using Euclidean distance-based hierarchical clustering, showing the average NC frequency (rows) for each patient (columns). The patient clusters (PCs) are represented by different colors. c Kaplan–Meier survival analysis for each PC.
Based on the aggregated results, we divided patients into two survival groups and computed the mean values of spatial interaction features (mh, mv, e1h, and e1v) of each group to identify trends linking spatial interaction to survival outcomes. These results are visualized in a mean space (Fig. 9), integrating all phenotypes to provide a comprehensive view of malignant-immune interactions. For visualization, we excluded outliers beyond the interquartile range, which reduced the skewness of nearly all features to below 0.5.
Fig. 9. Survival analysis using TR (malignant-enriched) and/or BR (tumor-border) images and spatial features.

Each panel presents results from shuffled feature matrices in different image-type conditions: TR+BR (a), TR only (b), and BR only (c). a Using 628 shuffled matrices with TR and BR combined: Left: The relationship between final survival rate and the border-image ratio for corresponding patients (BRratio). The border-image ratio is averaged within each bin of the final survival rate, using a bin size of 0.13. The Spearman’s Rank Correlation Coefficient (Rs) of 0.86 indicates a strong positive monotonic relationship. Middle & Right: Mean distance, mean density, and mean e1 across all phenotypes for the poor survival group (median survival probability = 0.23) and the good survival group (=0.68), respectively. Standard errors for distance and density are shown for each phenotype, while mean e1 is represented by arrows with error ranges (rectangles). For better visualization, we scale e1 by multiplying it by 0.05. b TR only; based on 184 shuffled matrices, median survival probabilities: 0.17 (poor group) and 0.52 (good group). c BR only; based on 784 shuffled matrices, median survival probability: 0.25 (poor group) and 0.60 (good group).
Figure 9a (left) shows a positive correlation between the proportion of BR images and survival probability, indicating that PCs with higher survival probability have more BR images. We interpret that tumors with more visible borders (not a sampling artifact, since TR/BR selection is independent of outcome) may be linked to improved survival outcomes (see Discussion). Figure 9a (middle, right) compares poor vs. good survival groups in mean . The good survival group shows significantly lower mean malignant density for all phenotypes, indicating fewer malignant cells nearby. Additionally, the mean e1 orientation (bottom-right) in the right panel suggests that patients in the good survival group have a higher proportion of BR images, consistent with the BR pattern in Fig. 4b. Since BR and TR images exhibit distinct distance and density scales, analyzing them together may obscure interpretation due to scale mixing. This motivates separate analysis of TR and BR images to accurately characterize spatial interaction patterns. We therefore applied the two-stage HC separately to TR (T = 74) and BR (T = 54) images in Eq. (15). The optimal number of clusters were (K*, L*) = (7, 13) for TR and (K*, L*) = (6, 8) for BR.
Figure 9b (TR only) shows that all phenotypes in the poor survival group present a higher mean malignant cell density than in the good survival group. In the good survival group, CD8+ T cell subsets (CD3+CD8+PD-1− and CD3+CD8+PD-1+) are positioned closer to the strong infiltration zone of the mean space than other phenotypes, the pattern not observed in the poor survival group. This pattern may indicate that CD8+ T cell subsets interact more actively with malignant cells in the good survival group. Furthermore, in the good survival group, CD3+CD8−PD-1− cells have a much larger mean e1 magnitude than in the poor survival group, indicating a more dispersed distribution in the original space (they are more widespread in the malignant-enriched regions). Overall, all phenotypes in the good survival group are located closer to each other in the mean space.
When considering BR images only, the mean patterns differ noticeably between the good and poor survival groups (Fig. 9c). The poor survival group for BR images exhibits mean patterns similar to those for TR images (Fig. 9b). This suggests that spatial interaction patterns of BR images may have considerable influence on patient survival outcomes.
Discussion
This study presents a computational framework based on TDA that enables end-to-end analysis (Supplementary Fig. S5 in Supplementary Section S6 of Supplementary Information) of malignant-immune spatial interactions, from interpretable feature extraction (considering both global and local aspects) to patient survival interpretation. We first computationally define regions of malignant cells, called TopMR, based on the topological persistence of the distribution. At the global scale, immune cell infiltration is quantified by signed distance functions from TopMR boundaries, which are robust against noise (e.g., cell-center extraction errors). Locally, malignant cell densities around individual immune cells are assessed using density functions. PCA summarizes each image’s point cloud data in the signed distance-density () space to characterize malignant-immune interactions. Key features (averaged signed distance, averaged density, and the first two principal components) are visualized using Ball Mapper graphs. These graphs reveal continuous transitions of spatial interaction patterns linked to patient survival outcomes. To ensure robustness, we repeatedly apply Ball Mapper to shuffled feature matrices, creating multiple perspectives on the data structure. Each Ball Mapper graph is further summarized into clusters via a two-stage HC. To interpret the relationship between spatial interactions and survival, we associate final survival probabilities (KM analysis) with the averaged spatial features (Ball Mapper nodes) across immune phenotypes. From these associations, we construct a representative mean space by dividing cases into two survival groups. We use this averaged space, excluding outliers, to highlight general trends in malignant-immune interactions while mitigating artifacts from small sample sizes or phenotype mislabeling.
This framework provides two key advantages for spatial TME analysis. First, the automatic extraction of regions of malignant cells (TopMR) based on topological persistence provides an objective reference for quantifying immune-malignant spatial relationships. The spatial positioning of immune cells (whether infiltrating, at boundaries, or excluded) can be associated with immunotherapy response and patient prognosis, however manual tumor boundary annotation can vary between pathologists, particularly when boundaries are ambiguous. Second, the integration of TDA and statistical methods enables comprehensive end-to-end analysis linking spatial patterns to clinical outcomes. By capturing malignant-immune interactions at both global and local scales and connecting these features to survival through interpretable visualization and clustering, our approach provides a complete pipeline from computational spatial analysis to patients’ survival interpretation.
We apply the framework to DLBCL data, where our approach robustly handles complex and heterogeneous spatial cell distributions from both TR and BR images. The separate annotation of TR and BR images given by pathologists is expected to be important because the malignant-enriched regions or border regions of the tumors often represent distinct biological contexts with different immune infiltration patterns. In the patient cohort used in this study (see also Supplementary Table S2 in Supplementary Section S7 of Supplementary Information), our analysis revealed distinct spatial patterns in the mean space associated with event-free survival probabilities between TR and BR regions. Higher proportions of BR images correlate with improved survival, suggesting that well-defined tumor borders are beneficial clinically. This may relate to a previous report30 where a diffusely infiltrative PCNSL subtype (lymphomatosis cerebri) was difficult to diagnose and associated with poor prognosis. This suggests that ill-defined, widespread tumor infiltration may correlate with worse outcomes. However, further biological and molecular studies are needed to clarify any causal relationship.
In TR images, a notable survival-related difference is the positioning of CD8+ T cell subsets (CD3+CD8+PD-1− and CD3+CD8+PD-1+) in the mean space. In patients with good survival, these T cells are positioned closer to the zone of strong immune infiltration than other phenotypes, a feature absent in the poor survival group. These T cells are located near the TopMR periphery with reduced malignant cell density in their vicinity, possibly reflecting active tumor clearance by CD8+ T cells in the good survival group. Beyond CD8+ T cell positioning, the good survival group shows closer spatial proximity among all immune phenotypes in the mean space compared to the poor survival group. This closer positioning may indicate more coordinated immune activity or enhanced immune surveillance, though the underlying mechanisms require further investigation. In addition, CD3+CD8+PD-1− cells show a larger mean e1 magnitude, indicating widespread distribution in the original space. This dispersed pattern is associated with survival advantages, likely enhancing immune efficacy.
Analyzing BR images independently, we find that patients whose tumor border regions exhibit spatial TME patterns resembling those of malignant-enriched regions (characterized by high malignant cell density and infiltration) have lower survival probabilities. This pattern suggests that infiltrative tumor borders may represent an adverse prognostic indicator in DLBCL, similar to findings in colorectal cancer31 and pancreatic neuroendocrine tumors32,33.
Despite the strengths of the proposed framework, several aspects warrant further development. The PCA-based pattern characterization in the space offers parameter-free, compact features that respond continuously to variations within the normal range, but it can be sensitive to large variations. We apply the framework to a DLBCL cohort of 78 patients. The reported survival associations are statistically significant within this cohort and may have prognostic relevance. However, these associations are not adjusted for established clinical or molecular prognostic factors and remain to be validated in an independent cohort. Larger cohorts that account for these factors are needed to establish their generalizability and prognostic value. Broader clinical translation also faces a practical barrier, as the mIF imaging used in this study is more resource-intensive than routinely available whole-slide imaging34, motivating future adaptation of the framework to more accessible imaging modalities. Although the spatial patterns of PD-1+ and PD-L1+ cells can be examined by tracing back to individual patients within clusters, the aggregated nature of the clustering approach limits detailed interpretation specific to these activation markers. Potential future directions include enhancing robustness against such variability, expanding the application to multiple cohorts and cancer types, and developing a classifier that fully utilizes spatial interaction features for clinical outcome prediction. Additionally, while this study focuses on malignant-immune interactions, exploring spatial interactions among different immune cell types represents a valuable direction for extending this framework. Since our framework operates on pre-processed point data instead of raw images, it is not tied to a specific imaging platform or preprocessing pipeline. Applying it to other spatial data types that provide cell-level coordinates and phenotype annotations, such as single-cell spatial transcriptomics platforms (e.g., Xenium and CosMx), represents another promising direction.
Methods
Data acquisition and pathologist annotation
We use the patient data and point clouds from mIF images (e.g. Fig. 1) of primary central nervous system DLBCL patients and the image segmentation and phenotype classification are performed using InForm software (Akoya Biosciences) as described in refs. 8,35. The images were independently annotated by pathologists as two types, ensuring no patient-specific bias:
TR image: the malignant-enriched regions of the tumors.
BR image: the border regions of the tumors.
Pathologists selected these regions based on qualitative criteria such as malignant cell infiltration; TR images have high malignant cell concentrations, while BR images show tumor interactions with adjacent tissue.
From these annotated images, we extract the locations of malignant cells (PAX5+) as the reference point cloud and the locations of three aggregated immune cell types as (Eq. (3)). The formal mathematical definitions of these point clouds and the index set are stated at the start of the Results section (Eqs. (1)–(3)). We aggregate immune cell phenotypes to maximize image inclusion: CD3+CD8−, CD3+CD8+, and CD163+; colors in Table 1. This aggregation is necessary because not every image contains all phenotypes, and PD-1+ and PD-L1+ cells less frequently observed in this dataset.
Table 1.
Legend of cell phenotypes and corresponding colors
![]() |
Persistent homology and simplicial complex construction
The persistent homology computation described in the Results section is performed using the GUDHI library21. Pairwise Euclidean distances among malignant cell positions are precomputed, and a Vietoris–Rips complex is constructed with the simplex tree built up to dimension two. The filled riangles of the extracted simplicial complex are rasterized into a binary mask, which serves as the input for the subsequent signed distance computation.
Signed distance field and density estimation
The signed distance field φ(x) defined in Eq. (7) is computed numerically by solving the eikonal equation25 via the Fast Marching Method, as implemented in the scikit-fmm Python library. Using a discrete grid domain, (: set of natural numbers), let M denote the binary mask on , where M(l, k) = 1 for grid points inside TopMR and M(l, k) = 0 otherwise. The boundary of the mask is defined as
| 16 |
where denotes the four index neighbors in . The Fast Marching Method propagates distances outward from , and the sign is assigned according to Eq. (7). The density field described in Eq. (8) is computed by summing Gaussian contributions from each malignant cell position and subsequently smoothing the result with a Gaussian filter (gaussian_filter from the scipy.ndimage module).
Ball Mapper graph construction
The Ball Mapper graphs presented in the Results section are constructed using the pyballmapper Python library20. Given a point cloud X equipped with a dissimilarity measure and a radius parameter ϵ, Ball Mapper constructs an open cover of X by balls of radius ϵ. The algorithm iterates through the points and, for each point not yet covered, creates a ball of radius ϵ centered at that point; all points within the ball are assigned to the corresponding node. Because a single point can lie within multiple balls, the resulting cover is overlapping. A graph is then formed by placing an edge between any two nodes that share at least one common point. In this study, the cosine dissimilarity is used as the distance measure, and the radius ϵ0 = 4.5 ⋅ 10−2 is selected as described in the Results section.
Hierarchical clustering and survival analysis
The two-stage hierarchical clustering (HC) and survival analysis described in the Results section are implemented in R. At both stages, HC is performed using the Ward.D2 linkage criterion with Euclidean distance, via the pheatmap R package; cluster assignments are obtained with the cutree function. In Stage 1, Ball Mapper nodes are clustered by their averaged 18-dimensional features to form Node Clusters. In Stage 2, patients are clustered by the normalized distribution of their images across these Node Clusters to form Patient Clusters. Kaplan–Meier survival curves are estimated using the survfit function from the survival R package, and p-values are obtained from the log-rank test as implemented in the survminer R package.
Supplementary information
Acknowledgements
P.D. and D.G. acknowledge support by the Dioscuri program initiated by the Max Planck Society, jointly managed with the National Science Centre (Poland), and mutually funded by the Polish Ministry of Science and Higher Education and the German Federal Ministry of Research, Technology and Space. P.D. and D.G. were supported by the National Science Centre, Poland (NCN), grant No. UMO-2019/02/H/ST1/00001. P.D. was funded from “Center of Trustworthy AI for Life Sciences” project carried out within the International Research Agendas programme of the Foundation for Polish Science co-financed by the European Union under the European Funds for Smart Economy 2021-2027 (FENG). We thank Dr. Seung Won Kim (Yonsei Institute of Gastroenterology, Yonsei University, Republic of Korea) for discussions on the prognostic significance of infiltrative tumor borders.
Author contributions
S.A.P. co-led and conceptualized the study, designed and implemented the framework, performed the data analysis, and wrote and revised the manuscript. Y.K. co-led and conceptualized the study, revised the manuscript, and provided clinical data. P.D. and D.G. contributed Ball Mapper and revised the manuscript. J.H. led and conceptualized the study, co-designed and -implemented the framework, and co-wrote and revised the manuscript. All authors discussed the results and contributed to the manuscript.
Data availability
The processed multiplex immunofluorescence images analyzed in this study have been deposited at Zenodo and are publicly available (https://doi.org/10.5281/zenodo.7895745)35, as originally reported by Roemer et al.8. Any additional information required to reanalyze the data reported in this paper is available from the corresponding author upon reasonable request.
Code availability
The code used in this study is implemented in Python and is publicly available at https://github.com/sapark1014/TopMR_sDD. Further inquiries regarding the code can be directed to Dr. Seol Ah Park.
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Contributor Information
Yongsoo Kim, Email: yo.kim@amsterdamumc.nl.
Jooyoung Hahn, Email: jooyoung.hahn@fjfi.cvut.cz.
Supplementary information
The online version contains supplementary material available at https://doi.org/10.1038/s41540-026-00763-7.
References
- 1.Binnewies, M. et al. Understanding the tumor immune microenvironment (time) for effective therapy. Nat. Med.24, 541–550 (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 2.Sadeghi Rad, H. et al. Understanding the tumor microenvironment for effective immunotherapy. Med. Res. Rev.41, 1474–1498 (2021). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 3.Fu, T. et al. Spatial architecture of the immune microenvironment orchestrates tumor immunity and therapeutic response. J. Hematol. Oncol.14, 98 (2021). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 4.Chen, J., Larsson, L., Swarbrick, A. & Lundeberg, J. Spatial landscapes of cancers: insights and opportunities. Nat. Rev. Clin. Oncol.21, 660–674 (2024). [DOI] [PubMed] [Google Scholar]
- 5.Page, D. B. et al. Spatial analyses of immune cell infiltration in cancer: current methods and future directions: A report of the international immuno-oncology biomarker working group on breast cancer. J. Pathol.260, 514–532 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 6.Ehsani, R., Jonassen, I., Akslen, L. A. & Kleftogiannis, D. Locator: feature extraction and spatial analysis of the cancer tissue microenvironment using mass cytometry imaging technologies. Bioinform. Adv.3, vbad146 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 7.Semba, T. & Ishimoto, T. Spatial analysis by current multiplexed imaging technologies for the molecular characterisation of cancer tissues. Brit. J. Cancer131, 1737–1747 (2024). [DOI] [PMC free article] [PubMed]
- 8.Roemer, M. G. et al. Multi-scale spatial modeling of immune cell distributions enables survival prediction in primary central nervous system lymphoma. iScience26, 107331 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 9.Keren, L. et al. A structured tumor-immune microenvironment in triple negative breast cancer revealed by multiplexed ion beam imaging. Cell174, 1373–1387 (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 10.Tiwari, A. et al. Towards a consensus definition of immune exclusion in cancer. Front. Immunol.14, 1084887 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 11.Chen, Z., Han, F., Du, Y., Shi, H. & Zhou, W. Hypoxic microenvironment in cancer: molecular mechanisms and therapeutic interventions. STTT8, 70 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 12.Marcon, E. & Puech, F. Generalizing ripley’s k function to inhomogeneous populations. https://shs.hal.science/halshs-00372631v1/document (2009).
- 13.Mi, H. et al. Digital pathology analysis quantifies spatial heterogeneity of CD3, CD4, CD8, CD20, and FOXP3 immune markers in triple-negative breast cancer. Front. Physiol.11, 583333 (2020). [DOI] [PMC free article] [PubMed]
- 14.Benimam, M. M. et al. Statistical analysis of spatial patterns in tumor microenvironment images. Nat. Commun.16, 3090 (2025). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 15.Edelsbrunner, H. & Harer, J. Computational Topology: An Introduction (AMS, 2010).
- 16.Ghrist, R. Barcodes: The persistent topology of data. Bull. Am. Math. Soc.45, 61–75 (2008). [Google Scholar]
- 17.Carlsson, G. Topology and data. Bull. Am. Math. Soc.46, 255–308 (2009). [Google Scholar]
- 18.Reddy, S. D., Reddy, T. K. & Higashi, H. Chromatic alpha complex generation for EEG signal classification. In 2024 National Conference on Communications (NCC), 1–5 (IEEE, 2024).
- 19.Stolz, B. J. et al. Relational persistent homology for multispecies data with application to the tumor microenvironment. Bull. Math. Biol.86, 128 (2024). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 20.Dłotko, P., Gurnari, D., & Sazdanovic, R. Mapper–type algorithms for complex data and relations. JCGS 1–14 (2024).
- 21.Glisse, M. et al. GUDHI Library: Simplicial complexes and persistent homology (2014–2024). https://gudhi.inria.fr/. Accessed: 2024-10-05.
- 22.Hao, S.-J., Wan, Y., Xia, Y.-Q., Zou, X. & Zheng, S.-Y. Size-based separation methods of circulating tumor cells. Adv. Drug Deliv. Rev.125, 3–20 (2018). [DOI] [PubMed] [Google Scholar]
- 23.Carmona-Fontaine, C. et al. Emergence of spatial structure in the tumor microenvironment due to the Warburg effect. Proc. Natl. Acad. Sci. USA110, 19402–19407 (2013). [DOI] [PMC free article] [PubMed]
- 24.Kohli, K., Pillarisetty, V. G. & Kim, T. S. Key chemokines direct migration of immune cells in solid tumors. Cancer Gene Ther.29, 10–21 (2022). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 25.Sethian, J. A. Level Set Methods and Fast Marching Methods, Evolving Interfaces in Computational Geometry, Fluid Mechanics, Computer Vision, and Materical Science (Cambridge University Press, New York, 1999).
- 26.McInnes, L., Healy, J., Saul, N. & Großberger, L. UMAP: uniform manifold approximation and projection. J. Open Source Softw.3, 861 (2018). [Google Scholar]
- 27.Kruskal, J. B. Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis. Psychometrika29, 1–27 (1964). [Google Scholar]
- 28.Cieslak, M. C., Castelfranco, A. M., Roncalli, V., Lenz, P. H. & Hartline, D. K. t-distributed stochastic neighbor embedding (t-SNE): a tool for eco-physiological transcriptomic analysis. Mar. Genomics51, 100723 (2020). [DOI] [PubMed] [Google Scholar]
- 29.Koljančić, N. et al. Untargeted chemical profiling of two-dimensional gas chromatography coupled with high-resolution mass spectrometry data for botrytized wines via topological data analysis. Anal. Chem.97, 25853–25867 (2025). [DOI] [PMC free article] [PubMed]
- 30.Kerbauy, M. N. et al. Diffuse large B-cell lymphoma of the central nervous system presenting as “lymphomatosis cerebri” and dementia in elderly man: case report and review of the literature. Medicine98, e14367 (2019). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 31.Zlobec, I. et al. Tumor border configuration added to TNM staging better stratifies stage ii colorectal cancer patients into prognostic subgroups. Cancer115, 4021–4029 (2009). [DOI] [PubMed] [Google Scholar]
- 32.Ahn, B., Kim, J. Y. & Hong, S.-M. Combined infiltrative macroscopic growth pattern and infiltrative microscopic tumor border status is a novel surrogate marker of poor prognosis in patients with pancreatic neuroendocrine tumor. Arch. Pathol. Lab. Med.147, 100–116 (2023). [DOI] [PubMed] [Google Scholar]
- 33.Ahn, B., Park, H. J., Kim, H. J. & Hong, S.-M. Radiologic tumor border can further stratify prognosis in patients with pancreatic neuroendocrine tumor. Pancreatology24, 753–763 (2024). [DOI] [PubMed] [Google Scholar]
- 34.Lu, M. Y. et al. AI-based pathology predicts origins for cancers of unknown primary. Nature594, 106–110 (2021). [DOI] [PubMed] [Google Scholar]
- 35.Kim, Y., Roemer, M. G. & de Jong, D. Processed vectra images for primary central nervous system lymphoma (PCNSL) patients (2023).
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
The processed multiplex immunofluorescence images analyzed in this study have been deposited at Zenodo and are publicly available (https://doi.org/10.5281/zenodo.7895745)35, as originally reported by Roemer et al.8. Any additional information required to reanalyze the data reported in this paper is available from the corresponding author upon reasonable request.
The code used in this study is implemented in Python and is publicly available at https://github.com/sapark1014/TopMR_sDD. Further inquiries regarding the code can be directed to Dr. Seol Ah Park.

