diff --git a/MSI_julia-python_mapping.md b/MSI_julia-python_mapping.md index 523bc38..275877e 100644 --- a/MSI_julia-python_mapping.md +++ b/MSI_julia-python_mapping.md @@ -87,9 +87,9 @@ We conducted direct surface analysis of *D. innoxia* leaves using an LD-LTP-MS s ### 3.2 Latent Space Geometry and Chemical Validation The high-dimensional embeddings generated by the custom GroupNorm backbone were projected into a 2-D manifold using t-SNE (Figure 3) (Van der Maaten & Hinton, 2008). The resulting latent space exhibits a highly structured geometry, where ions are grouped not by their absolute intensity, but by their shared spatial topographies. A cornerstone of the validation for this self-supervised approach is the emergence of **Isotopic Coherence** within the latent manifold (Table 2). In MSI, a molecular species and its naturally occurring isotopes (e.g., $[M+H]^+$ and $[M+H+1]^+$) are fundamentally tied by an identical spatial distribution, providing a form of natural "ground truth" that requires no manual annotation. -To quantitatively validate this, we calculated the Cosine Similarity between the normalized feature vectors of known isotopic pairs. For example, Atropine (*m/z* 290.02) and its $+1$ isotope (*m/z* 291.00) yielded a Cosine Similarity of **$0.9898$**. A global statistical analysis across 513 discovered isotopic pairs yielded a mean latent distance of $0.3156$, compared to $0.7076$ for random ion pairs, achieving profound statistical significance (Welch's t-test, $p = 6.7932 \times 10^{-74}$). Although the SimCLR framework is entirely agnostic to the mass-to-charge (*m/z*) values or the chemical identity of the inputs, the encoder consistently projected isotopic pairs into tightly bound coordinates. +To quantitatively validate this, we calculated the Cosine Similarity between the normalized feature vectors of known isotopic pairs. For example, Atropine (*m/z* 290.02) and its $+1$ isotope (*m/z* 291.02) yielded a Cosine Similarity of **$0.9898$**. A global statistical analysis across 513 discovered isotopic pairs yielded a mean latent distance of $0.3156$, compared to $0.7076$ for random ion pairs, achieving profound statistical significance (Welch's t-test, $p = 6.7932 \times 10^{-74}$). Although the SimCLR framework is entirely agnostic to the mass-to-charge (*m/z*) values or the chemical identity of the inputs, the encoder consistently projected isotopic pairs into tightly bound coordinates. -**Disproving Background Mask Exploitation:** A common concern in applying deep learning to zero-padded imaging data is that the network may exploit the outer tissue boundary —an artifact shared identically by every single ion image— as a "shortcut" feature, rather than learning true internal biology (Purushwalkam & Gupta, 2020). Our data provides an elegant empirical refutation of this hypothesis. Atropine (*m/z* 290.02) and its $+1$ isotope (*m/z* 291.00) share a perfectly identical outer mask boundary but have fundamentally different absolute signal intensities due to natural isotopic abundance ratios. If the encoder were exploiting the mask, these two ions would appear identical regardless, yielding a trivially high similarity—providing no discriminative power. Instead, the NT-Xent loss function explicitly penalizes the encoder for relying on zero-variance features shared across all images in the negative pair denominator (Chen et al., 2020). Any feature constant across all ion images —including the outer mask— provides zero contrastive gradient, and is mathematically discarded in favor of internal morphological variations. The observed similarity of $0.9898$ therefore constitutes proof that the network has converged on the true shared spatial silhouette of the ion inside the tissue, not the common boundary around it. +**Disproving Background Mask Exploitation:** A common concern in applying deep learning to zero-padded imaging data is that the network may exploit the outer tissue boundary —an artifact shared identically by every single ion image— as a "shortcut" feature, rather than learning true internal biology (Purushwalkam & Gupta, 2020). Our data provides an elegant empirical refutation of this hypothesis. Atropine (*m/z* 290.02) and its $+1$ isotope (*m/z* 291.02) share a perfectly identical outer mask boundary but have fundamentally different absolute signal intensities due to natural isotopic abundance ratios. If the encoder were exploiting the mask, these two ions would appear identical regardless, yielding a trivially high similarity—providing no discriminative power. Instead, the NT-Xent loss function explicitly penalizes the encoder for relying on zero-variance features shared across all images in the negative pair denominator (Chen et al., 2020). Any feature constant across all ion images —including the outer mask— provides zero contrastive gradient, and is mathematically discarded in favor of internal morphological variations. The observed similarity of $0.9898$ therefore constitutes proof that the network has converged on the true shared spatial silhouette of the ion inside the tissue, not the common boundary around it. Furthermore, this structural mapping revealed the phenomenon of **Inverse Mask Correlation** (Negative Space Co-Exclusion). The network successfully grouped ions that concentrate directly within the vascular bundle (positive distributions, e.g., Scopolamine *m/z* 304.00, achieving a similarity of $0.8796$ with Atropine) with ions that are biologically excluded from the vein (negative distributions, appearing as dark shadows). Because the encoder projects all spatial maps onto an $L_2$ unit hypersphere, it recognizes that the sharp geometric boundary of a bright vein and the boundary of its complementary dark shadow are topologically equivalent structures. Such coherence confirms that the learned representations are anchored in global biological reality rather than technical artifacts. @@ -99,12 +99,13 @@ Furthermore, this structural mapping revealed the phenomenon of **Inverse Mask C | *m/z* Obs. | Identification | Formula $[M+H]^+$ | Cluster | Anatomical Significance | | :--- | :--- | :--- | :--- | :--- | -| 290.02 | Atropine / Hyoscyamine | $C_{17}H_{24}NO_3$ | **9** | Ubiquitous parenchymal distribution with moderate terminal accumulation | -| 304.00 | Scopolamine | $C_{17}H_{22}NO_4$ | **9** | Widespread distribution across the leaf with apical enrichment | -| 225.65 | Cuscohygrine | $C_{13}H_{25}N_2O$ | **9** | Multi-compartmental distribution (parenchymal islands and tip) | -| 306.28 | 6-Hydroxyhyoscyamine | $C_{17}H_{24}NO_4$ | **8** | Vascular transport with apical and parenchymal localization | -| 142.09 | Tropine / Pseudotropine | $C_8H_{16}NO$ | **2** | Constitutive distribution across the leaf mesophyll | -| 291.00 | *Atropine Isotope* | $[M+H+1]^+$ | **9** | Internal validation of Isotopic Coherence (parenchymal distribution) | +| 304.00 | Scopolamine | $C_{17}H_{22}NO_4$ | **3** | Midrib-associated distribution (nervure). Related to chemical defense (biotic and abiotic factors) and pharmaceutical applications. | +| 290.02 | Atropine / Hyoscyamine | $C_{17}H_{24}NO_3$ | **9** | Vascular distribution through the midrib with island formation across the lamina. Chemical defense and precursor of scopolamine. | +| 225.65 | Cuscohygrine | $C_{13}H_{25}N_2O$ | **0** | Vascular architecture from primary to secondary veins, extending from the petiole to the leaf tip. | +| 306.28 | 6-Hydroxyhyoscyamine | $C_{17}H_{24}NO_4$ | **9** | Midrib distribution with evident dispersion across the entire leaf and accumulation in small islands. | +| 142.09 | Tropine / Pseudotropine | $C_8H_{16}NO$ | **2** | Distribution mainly through the midrib with island-like accumulation in other leaf regions. Key biosynthetic precursor of tropane alkaloids. | +| 140.14 | Tropinone | $C_8H_{14}NO$ | **6** | Present in the midrib and throughout the entire leaf surface. Key biosynthetic precursor of tropane alkaloids, essential for the biosynthesis of downstream tropane alkaloids. | +| 291.02 | *Atropine Isotope* | $[M+H+1]^+$ | **9** | Spatial distribution very similar to *m/z* 290.02, with presence in primary and secondary vasculature. | ![Visualizing metabolic specialization across anatomical zones of a *D. innoxia* leaf using t-SNE. This scatter plot displays the t-SNE dimensionality reduction of MSI data acquired from a leaf section at a spatial resolution of 150 µm. The original dataset of 588 *m/z* feature intensities was projected into a 2D space to visualize metabolic similarity. Ten distinct clusters are identified via automated segmentation of the co-localized ion images and are represented here by a qualitative color bar (right). Points of the same color indicate pixels with closely related metabolic signatures, corresponding to different anatomical regions within the leaf. The strong segregation between groups highlights a sharp molecular differentiation of metabolic functions across the tissue.](msi_tsne_corregido.png) @@ -133,7 +134,7 @@ Two clusters are defined by a primary spatial association with the apical region #### 3.3.3 Ubiquitous and Parenchymal Distributions (Clusters 2, 7, 9) Three clusters are characterized by broad spatial distributions that span the entire leaf surface, reflecting compounds with constitutive or widespread parenchymal presence. **Cluster 2** exhibits the most uniform pattern, with detectable signal across the entire leaf surface without pronounced enrichment in any specific anatomical structure. This ubiquitous distribution is characteristic of primary metabolites or constitutive compounds involved in basal cellular processes. **Cluster 7** is dominated by large, well-defined islands distributed across the lamina with a minor presence at the apical tip. The island-like pattern within a broad distribution suggests localized zones of metabolic specialization or differential accumulation within a generally ubiquitous compound class. **Cluster 9** displays a heterogeneous pattern combining both large and small islands across the leaf surface with moderate enrichment at the tip, representing the most complex distribution among the ubiquitous group. -The spatial distribution of atropine (*m/z* 290.02) and scopolamine (*m/z* 304.0) within Cluster 9 provides a nuanced view of tropane alkaloid allocation in *D. innoxia*. Rather than being exclusively confined to the midrib, these compounds exhibit a broad distribution across the leaf in the form of large and small islands, with moderate enrichment at the apical tip. This pattern is consistent with the known biology of tropane alkaloids: synthesized in the roots and transported acropetally via the xylem, they are subsequently unloaded and stored within the leaf parenchyma, forming localized accumulation zones (chemical "islands") that may correspond to specialized storage compartments or idioblastic cells. The co-localization of atropine, scopolamine, cuscohygrine, and the atropine isotopic variant (*m/z* 291.00) within the same cluster (Cluster 9) validates that the self-supervised encoder has captured genuine metabolic relationships rather than instrumental artifacts. By capturing this multi-compartmental distribution, the SimCLR-based segmentation effectively resolves the spatial continuum from vascular import to parenchymal storage to terminal accumulation. +The spatial distribution of key tropane alkaloids reveals distinct but complementary anatomical patterns that reflect their biosynthetic relationships and functional roles. Scopolamine (*m/z* 304.0), assigned to Cluster 3, exhibits a clear midrib-associated distribution, consistent with its role in chemical defense against biotic and abiotic factors and its pharmaceutical significance. Atropine (*m/z* 290.02), assigned to Cluster 9, shows a vascular distribution through the midrib with pronounced island formation across the lamina, functioning as both a defense compound and the biosynthetic precursor of scopolamine. Cuscohygrine (*m/z* 225.65), in Cluster 0, displays a striking vascular architecture from primary to secondary veins extending from the petiole to the leaf tip. 6-Hydroxyhyoscyamine (*m/z* 306.28), also in Cluster 9, follows the midrib with evident dispersion across the entire leaf and accumulation in small islands. Tropine (*m/z* 142.09) and pseudotropine, in Cluster 2, show distribution mainly through the midrib with island-like accumulation, functioning as key biosynthetic precursors of tropane alkaloids. Tropinone (*m/z* 140.14), assigned to Cluster 6, is present in the midrib and throughout the entire leaf surface, serving as the principal biosynthetic precursor essential for the synthesis of downstream tropane alkaloids. The co-localization of atropine, 6-hydroxyhyoscyamine, and the atropine isotopic variant (*m/z* 291.02) within Cluster 9, alongside the distinct vascular assignments of scopolamine (Cluster 3) and cuscohygrine (Cluster 0), demonstrates that the self-supervised encoder successfully discriminates between subtle variations in spatial topography while capturing genuine biosynthetic and metabolic relationships. By resolving these multi-compartmental distributions, the SimCLR-based segmentation effectively maps the spatial continuum from vascular transport to parenchymal storage to terminal accumulation. #### 3.4 Advantages of Contrastive Learning over Linear Decomposition Furthermore, the superiority of the self-supervised contrastive learning approach over traditional linear methods, such as Principal Component Analysis (PCA), lies in its fundamental shift from intensity-driven variance to morphological feature extraction (Shah et al., 2025). To establish a fair quantitative baseline, we compared SimCLR and PCA embeddings under identical conditions: both feature sets were projected to the same dimensionality via PCA and clustered using standard Euclidean $k$-means ($k = 10$) without the Spherical $k$-means re-normalization described in Section 2.4.4, ensuring a direct apples-to-apples comparison. Under these conditions, the SimCLR pipeline achieved a Silhouette Score of **0.508**, compared to the PCA baseline of 0.163, while the Calinski-Harabasz Index rose from 103.7 to **2147.4**. When the full optimized post-processing pipeline is applied (Spherical $k$-means with $L_2$ re-normalization, as described in Section 2.4.4–2.4.5), the Silhouette Score further improves to **0.6894** with a Davies-Bouldin Index of **0.6243**, confirming that the combination of contrastive feature learning and geometrically correct clustering produces massive improvements in spatial separation. diff --git a/msi_tsne_corregido.png b/msi_tsne_corregido.png index 3bb6fa4..ca25186 100644 Binary files a/msi_tsne_corregido.png and b/msi_tsne_corregido.png differ