From 6e0f24e63cf61fcab385d559a07b9883354cfac3 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 10 Jun 2026 07:15:26 +0200 Subject: [PATCH] Subir archivos a "/" --- MSI_julia-python_mapping.md | 139 ++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 55 deletions(-) diff --git a/MSI_julia-python_mapping.md b/MSI_julia-python_mapping.md index 107fb99..746379f 100644 --- a/MSI_julia-python_mapping.md +++ b/MSI_julia-python_mapping.md @@ -2,38 +2,38 @@ **Authors:** Carlos Daniel Sierra Álvarez, Juan Francisco Moreno Luna, José Jovani Martínez, José Julián Sierra Álvarez. **Affiliation:** Advanced Genomics Unit, Cinvestav, km 9.6 Libr. Nte. Irapuato-León, Irapuato, 36824, Gto., Mexico. -**Keywords:** MSI, Julia Language, Deep Learning, SimCLR, EfficientNet-B0, *Datura innoxia*, Spatial Metabolomics. +**Keywords:** MSI, Julia Language, Deep Learning, SimCLR, Contrastive Learning, Group Normalization, *Datura innoxia*, Spatial Metabolomics. --- ## Abstract -Mass Spectrometry Imaging (MSI) has emerged as a fundamental tool in spatial metabolomics, enabling the *in situ* visualization of molecular distributions. However, the nature of these data—characterized by massive volumes of multivariate information and high levels of instrumental noise—poses critical challenges for traditional analysis methods. In this work, we present an innovative computational architecture that addresses the "two-language problem" by integrating **Julia** for high-performance data processing and **Python** for representation learning via deep neural networks. We implemented a self-supervised learning workflow based on the **SimCLR** architecture with an **EfficientNet-B0** encoder, designed to extract robust morphological features from ion images without prior labeling. This system was applied to the study of *Datura innoxia* (toloache) leaves at a spatial resolution of 150 µm, achieved via Laser Desorption Low-Temperature Plasma (LD-LTP) ionization. By prioritizing anatomical fidelity over mathematical parsimony, we identified an optimal clustering of $k=10$ that accurately distinguishes vascular, paravascular, and parenchymal tissues. Our results demonstrate that the latent space generated by the neural network captures fundamental chemical relationships, such as the co-localization of isotopic patterns, offering a scalable and objective pathway for the interpretation of complex biological systems. +Mass Spectrometry Imaging (MSI) has emerged as a fundamental tool in spatial metabolomics, enabling the *in situ* visualization of molecular distributions. However, the nature of these data—characterized by massive volumes of multivariate information and high levels of instrumental noise—poses critical computational challenges for traditional analysis methods (Shah et al., 2025). In this work, we present an innovative computational architecture that addresses the "two-language problem" by integrating **Julia** for high-performance data processing and **Python** for representation learning via deep neural networks. We implemented a self-supervised learning workflow based on the **SimCLR** architecture with a **custom Group-Normalized Fully Convolutional** encoder, designed to extract robust morphological features from ion images without prior labeling. This system was applied to the study of *Datura innoxia* (toloache) leaves at a spatial resolution of 150 µm, achieved via Laser Desorption Low-Temperature Plasma (LD-LTP) ionization. By prioritizing anatomical fidelity over mathematical parsimony, we identified an optimal clustering of $k=10$ that accurately distinguishes vascular, paravascular, and parenchymal tissues. Our results demonstrate that the latent space generated by the neural network captures fundamental chemical relationships, such as the co-localization of isotopic patterns, offering a scalable and objective pathway for the interpretation of complex biological systems. --- ## 1. Introduction -The analysis of the spatial distribution of secondary metabolites in medicinal plants is essential for understanding biosynthesis, transport, and chemical defense processes (Ziegler & Facchini, 2008). *D. innoxia*, known for its rich composition of tropane alkaloids, represents a highly complex biological model due to the biosynthesis of these compounds in the roots and their differential transport to the shoots (Schlesinger et al., 2021). Previous studies have employed laser desorption low-temperature plasma (LD-LTP) techniques to map these alkaloids in fruits and seeds (Moreno-Pedraza et al., 2019). +The analysis of the spatial distribution of secondary metabolites in medicinal plants is essential for understanding biosynthesis, transport, and chemical defense processes (Ziegler & Facchini, 2008; García-Rojas et al., 2024). *D. innoxia*, known for its rich composition of tropane alkaloids, represents a highly complex biological model due to the biosynthesis of these compounds in the roots and their differential transport to the shoots (Schlesinger et al., 2021). Previous studies have employed laser desorption low-temperature plasma (LD-LTP) techniques to map these alkaloids in fruits and seeds (Moreno-Pedraza et al., 2019). -Traditionally, MSI data analysis has relied on linear methods and standard imaging protocols (Cole & Clench, 2023). However, a software engineering challenge arises: while Python possesses the most mature ecosystem for Artificial Intelligence, its performance in handling massive binary files in **imzML** format (Schramm et al., 2012) is limited. Conversely, Julia offers execution speeds comparable to C++, making it ideal for processing high-dimensional matrices in MSI, demonstrating speeds up to 200 times faster than R in data reading tasks (Rosas-Román et al., 2024). In this article, we propose that the synergy between these two languages enables a "next-generation" MSI workflow. +Traditionally, MSI data analysis has relied on linear methods and standard imaging protocols (Cole & Clench, 2023). However, a software engineering challenge arises: while Python possesses the most mature ecosystem for Artificial Intelligence, its performance in handling massive binary files in **imzML** format (Schramm et al., 2012) is often limited. Conversely, Julia offers execution speeds comparable to C++ for compute-heavy tasks (Godoy et al., 2023) and outperforms interpreted languages in scientific computing benchmarks (Churavy et al., 2020). The integration of these two ecosystems addresses the "two-language problem"—the historical trade-off between the ease of a high-level language and the performance of a low-level one (Perkel, 2019). In this article, we propose that the synergy between these two languages enables a "next-generation" MSI workflow. The remainder of this paper details the acquisition parameters, the hybrid Julia-Python implementation, the unsupervised segmentation results, and a comparison against traditional linear baselines. --- ## 2. Methodology ### 2.1 MSI Data Acquisition (LD-LTP-MSI) -Imaging was performed using an **LD-LTP-MSI** system coupled to an **LCQ Fleet Ion Trap** mass spectrometer (Thermo Scientific). The custom ionization source consisted of a Low-Temperature Plasma (LTP) probe and a continuous-wave violet laser (400-450 nm, 1.0 W). The LTP probe was operated with helium (0.1 L/min) at 3.3 kV and ~13 kHz, positioned at a 45° angle and 4 mm from the ion transfer capillary (Martínez-Jarquín & Winkler, 2017). The laser was oriented at 90° to the sample surface at a focal distance of 9 cm, producing a spot size of ~22 µm. Data were acquired in positive ion mode (*m/z* 50–700) with a spatial resolution of **150 µm** for the leaf samples. +We performed imaging using an **LD-LTP-MSI** system coupled to an **LCQ Fleet Ion Trap** mass spectrometer (Thermo Scientific). The custom ionization source consisted of a Low-Temperature Plasma (LTP) probe (Harper et al., 2008) and a continuous-wave violet laser (400–450 nm, 1.0 W). The LTP probe was operated with helium (0.1 L/min) at 3.3 kV and ~13 kHz, positioned at a 45° angle and 4 mm from the ion transfer capillary (Martínez-Jarquín & Winkler, 2017). The laser was oriented at 90° to the sample surface at a focal distance of 9 cm, producing a spot size of ~22 µm. We acquired data in positive ion mode (*m/z* 50–700) with a spatial resolution of **150 µm** for the leaf samples. -### 2.2 Computational Environment -All computational analyses, including the high-performance data extraction in Julia and the deep learning-based representation learning in Python, were performed on a mobile workstation with the following specifications: **Processor:** Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (4 cores, 8 threads), **Memory:** 32 GB DDR4 RAM, **Graphics:** Intel UHD Graphics (CometLake-U GT2) and **Operating System:** Ubuntu 24.04.4 LTS (Linux Kernel 6.8.0-110-generic). +### 2.2 Computational Environment and Reproducibility +All computational analyses, including the high-performance data extraction in Julia and the deep learning-based representation learning in Python, were performed across two mobile workstations. The primary data ingestion and analysis were executed on a system with the following specifications: **Processor:** Intel(R) Core(TM) i5-10210U CPU @ 1.60 GHz (4 cores, 8 threads), **Memory:** 32 GB DDR4 RAM, **Graphics:** Intel UHD Graphics (CometLake-U GT2), and **Operating System:** Ubuntu 24.04.4 LTS (Linux Kernel 6.8.0-110-generic). Hardware-accelerated neural network training (CUDA) was executed on a Dell G15 5525 equipped with an **AMD Ryzen 5 6600H** processor (6 cores, 12 threads @ 4.57 GHz), **8 GB RAM**, and an **NVIDIA GeForce RTX 3050 Mobile** discrete GPU, running **Pop!_OS 24.04 LTS**. To ensure rigorous compliance with MSI reporting standards such as MIAMSIE (Gustafsson et al., 2018) and SMART (Xi et al., 2023), as well as modern machine learning reproducibility guidelines like REFORMS (Kapoor et al., 2024), the complete hybrid workflow was containerized using Docker. This guarantees that both the Julia binary parsing algorithms and the Python machine learning dependencies remain perfectly reproducible across diverse hardware platforms. ### 2.3 High-Performance Processing and Data Normalization (Julia) -The preprocessing stage was conducted using the **JuliaMSI** framework (Sierra-Álvarez et al., 2025), a platform specifically engineered to address the computational bottlenecks of the "two-language problem." By leveraging Julia’s just-in-time (JIT) compilation and efficient memory-mapping capabilities, we facilitated the rapid ingestion and manipulation of massive **imzML** binary files. As demonstrated in previous benchmarks (Sierra-Álvarez et al., 2025), this architecture provides a significant performance advantage over interpreted environments such as Python or R (Rosas-Román et al., 2020), enabling the high-throughput extraction of mass slices without compromising spectral precision. +We conducted the preprocessing stage using the **JuliaMSI** framework (Sierra-Álvarez et al., 2025), a platform specifically engineered to address the computational bottlenecks of the "two-language problem." By leveraging Julia’s just-in-time (JIT) compilation and efficient memory-mapping capabilities, we facilitated the rapid ingestion and manipulation of massive **imzML** binary files. As demonstrated in previous benchmarks (Sierra-Álvarez et al., 2025), this architecture provides a significant performance advantage over interpreted environments such as Python or R (Rosas-Román et al., 2020), enabling the high-throughput extraction of mass slices without compromising spectral precision. The selection of Julia as the primary engine for data ingestion is justified by its superior performance in handling the high-dimensional sparse matrices characteristic of imzML files. Recent benchmarks have demonstrated that Julia-based architectures, such as the JuliaMSI framework, outperform traditional R-based implementations (e.g., RmsiGUI) by significant margins, showing up to 5.2-fold faster processing on Linux environments (Sierra-Álvarez et al., 2025). Furthermore, at the library level, Julia's native parsing of binary spectral data has been shown to be up to 214 times faster than equivalent implementations in R (Rosas-Román et al., 2024). This computational efficiency is critical for resolving the "two-language problem," as it allows the rapid extraction of hundreds of mass slices and their subsequent normalization in a fraction of the time required by interpreted environments, effectively enabling a high-throughput bridge to the Python-based deep learning ecosystem. -1. **Ion Extraction and Filtering:** Mass slices were extracted from the `Leaf.imzML` dataset within the ***m/z* 50.0 to 700.0** range. This upper limit was selected because no significant signals were detected beyond this threshold using the LD-LTP-MSI technique for this specific sample, and its implementation allowed for a more computationally manageable dataset. To ensure the inclusion of only chemically relevant signals, peaks were filtered using an intensity threshold of 2% relative to the base peak of the average spectrum, resulting in a refined subset of ion images for downstream analysis. +1. **Ion Extraction and Filtering:** We extracted mass slices from the `Leaf.imzML` dataset within the ***m/z* 50.0 to 700.0** range. This upper limit was selected because no significant signals were detected beyond this threshold using the LD-LTP-MSI technique for this specific sample, and its implementation allowed for a more computationally manageable dataset. To ensure the inclusion of only chemically relevant signals, we filtered peaks using an intensity threshold of 2% relative to the base peak of the average spectrum, resulting in a refined subset of ion images for downstream analysis. -2. **TrIQ Normalization (Threshold Intensity Quantization):** To mitigate the impact of "hotspots"—stochastic pixels with disproportionately high intensities that obscure lower-abundance metabolic distributions—we implemented a dynamic TrIQ algorithm (Rosas-Román et al., 2024). For each raw ion map $I_{raw}$, the algorithm identifies a signal threshold $T$ based on the distribution of non-zero, finite intensity values $V = \{i \in I_{raw}\mid i > 0, i < \infty\}$. The threshold is defined as the 98th percentile of this distribution: +2. **TrIQ Normalization (Threshold Intensity Quantization):** To mitigate the impact of "hotspots"—stochastic pixels with disproportionately high intensities that obscure lower-abundance metabolic distributions—we implemented a dynamic TrIQ algorithm (Rosas-Román & Winkler, 2021). For each raw ion map $I_{raw}$, the algorithm identifies a signal threshold $T$ based on the distribution of non-zero, finite intensity values $V = \{i \in I_{raw}\mid i > 0, i < \infty\}$. The threshold is defined as the 98th percentile of this distribution: $$T = P_{98}(V)$$ @@ -43,101 +43,112 @@ $$I_{norm}(x, y) = \min\left(1, \frac{I_{raw}(x, y)}{T}\right)$$ This transformation ensures that 98% of the chemical signal is represented within a standardized dynamic range, effectively enhancing the contrast of parenchymal and vascular structures. By suppressing the influence of extreme outliers, TrIQ provides a morphologically consistent input for the subsequent contrastive learning phase, preventing the neural network from over-fitting to instrumental artifacts. -3. **Spatial Standardization:** To ensure compatibility with the deep learning backbone, each normalized ion map was spatially resampled to a resolution of **224x224 pixels** using bilinear interpolation. This step standardizes the input geometry while maintaining the structural integrity of the leaf’s anatomical features, such as the vascular midrib and parenchymal regions (Hu et al., 2022). +3. **Spatial Standardization (Pristine Coordinate Mapping):** To ensure compatibility with the deep learning backbone, each normalized ion map was spatially embedded into a standardized **256 $\times$ 256 pixel** matrix using strict **Zero-Padding**, completely avoiding any sub-pixel interpolation. In MSI, the physical laser ablation grid serves as an absolute spatial ground truth. Standard computational interpolation (such as bilinear resizing) forces anisotropic stretching—disproportionately warping the leaf morphology—and introduces artificial floating-point values at the sharp boundaries of the tissue mask. By mapping the raw $161 \times 106$ coordinates directly into the center of a zero-matrix, we preserved the true, undistorted anatomical geometry of the leaf while achieving the uniform dimensionality required by the convolutional layers. As a demonstration of this high-throughput pipeline, the Julia engine parsed the raw `.ibd` binaries, applied TrIQ, and exported 588 padded individual ion slices in less than 16 seconds. ### 2.4 Self-Supervised Representation Learning (Python) -We implemented a Contrastive Learning (SimCLR) scheme in PyTorch (Chen, T., et al., 2020), following the methodology proposed by Hu et al. (2022). +We implemented a Contrastive Learning (SimCLR) scheme in PyTorch (Paszke et al., 2019), adapting the framework to the unique properties of mass spectrometry imaging. -1. **Model Architecture:** **EfficientNet-B0** was used as the backbone encoder (Tan, M., & Le, Q., 2019). The final classification layer was removed and replaced with a two-layer MLP projection head to project the data into a 128-dimensional space (Table. [1]) (Kingma, D. P., & Ba, J., 2014). +1. **Model Architecture and VRAM Optimization:** A custom **Fully Convolutional Contrastive Network** was engineered to replace standard heavy computer vision backbones. Crucially, all standard batch normalization blocks were replaced with **Group Normalization (GroupNorm)** layers (8 groups per layer). In datasets characterized by massive empty, zero-padded backgrounds, standard Batch Normalization calculates running statistics that become overwhelmingly biased by the blank space, leading to gradient instability and the artificial clustering of the background mask. Group Normalization computes statistics per individual image slice, mathematically neutralizing the static background and forcing the network to optimize strictly on the high-variance internal biological structures. The network concludes with an Adaptive Average Pooling layer and a 2-layer MLP to project the spatial features into a 128-dimensional latent space (Table 1). + +To enable training on consumer-grade hardware (NVIDIA RTX 3050 Mobile, ~4 GB VRAM), a gradient accumulation strategy was employed. Rather than fitting an effective batch of 32 images simultaneously into GPU memory—which would trigger a CUDA out-of-memory error—the engine processes 8 images physically per step and accumulates gradients over 4 consecutive forward passes before executing a single optimizer update, as described in the Hugging Face documentation (Hugging Face, 2025). This is mathematically equivalent to training with a true batch size of 32 while using only a quarter of the VRAM. **Table 1. Training hyperparameters and model configuration for the SimCLR-MSI workflow.** | Parameter | Value / Configuration | | :--- | :--- | -| **Backbone Architecture** | EfficientNet-B0 (Pre-trained on ImageNet) | +| **Backbone Architecture** | Custom 4-Layer CNN with Group Normalization | | **Projection Head** | 2-layer MLP (Linear 512-ReLU-Linear 128) | -| **Input Image Resolution** | 224 x 224 pixels | -| **Optimization Algorithm** | Adam Optimizer | +| **Input Image Resolution** | 256 x 256 pixels (Zero-Padded) | +| **Optimization Algorithm** | Adam Optimizer (Kingma & Ba, 2014) | | **Learning Rate** | $3 \times 10^{-4}$ | -| **Batch Size** | 32 | +| **Physical Batch Size / Accumulation Steps** | 8 / 4 (Effective Batch Size: 32) | | **Temperature ($\tau$)** | 0.5 (NT-Xent Loss) | -| **Training Duration** | 50 Epochs | -| **Data Augmentations** | Random Rotation (10°), Gaussian Blur, Color Jitter, and Additive Gaussian Noise ($\sigma=0.01$) | +| **Training Duration** | 60 Epochs | +| **Data Augmentations** | Intensity Scaling (0.8×–1.2×), Poisson Shot Noise, Low-Signal Dropout | -2. **MSI-Specific Data Augmentations:** Stochastic transformations were applied to simulate experimental variability, including slight rotations, Gaussian blur, and the addition of additive Gaussian noise to bolster the model against detector background noise. -3. **Clustering and Optimization:** To determine the optimal number of clusters ($k$), we performed a multi-metric systematic sweep from $k=2$ to $k=20$ (Fig. [1(A)]). While global mathematical optima were observed at $k=2$ and $k=3$ —corresponding to a coarse differentiation between the leaf tissue and the background— these configurations failed to resolve the specialized anatomical compartments of the leaf. We identified $k=10$ as the functional optimum, supported by a Silhouette Score of 0.3526 (Fig. [1(B)]), a Davies-Bouldin Index of 0.9632 (Fig. [1(C)]), and a Calinski-Harabasz Index of 709.17 (Fig. [1(D)]). This value represents a stable convergence point where the latent space successfully deconvolutes the hierarchical vascular architecture (midrib and secondary veins) and localized metabolic sequestration sites without incurring over-segmentation. Consequently, this choice prioritizes anatomical fidelity over mathematical parsimony, ensuring that the resulting metabolic map accurately reflects the complex tissue compartmentalization of *D. innoxia*. +2. **Dataset Size and the Dynamic Training Pool:** The training corpus comprises 588 ion images that passed the 2% intensity threshold filter from the original spectral binning. This number is mathematically sufficient for this self-supervised task for two compounding reasons. First, the custom 4-layer fully convolutional architecture is a lightweight, low-dimensional feature extractor. Unlike overparameterized ImageNet backbones such as EfficientNet-B0 (Tan & Le, 2019) (which carry over 5 million parameters trained for 1,000 natural image categories), our encoder is purpose-built to extract a compact morphological fingerprint; it requires far fewer samples to converge on a meaningful manifold. Second, the `apply_msi_chemical_noise` augmentation pipeline functions as a stochastic, infinite data generator. Because intensity scaling factors, Poisson noise seeds, and dropout masks are sampled randomly at each epoch, the network never encounters the exact same image representation twice, exponentially expanding the effective training pool and providing robust protection against overfitting. -![[cluster_validation_detailed_plot.png]] +3. **The Camp A Paradigm: Prohibition of Spatial Augmentations:** Standard computer vision augmentation libraries (e.g., Torchvision) apply spatial transformations—random rotations, horizontal/vertical flips, and random crops—as a default strategy to promote translation and rotation invariance. This practice is explicitly and deliberately incompatible with our co-localization objective and was therefore completely prohibited. In spatial metabolomics, the absolute $(x, y)$ pixel grid of a single-slice acquisition is the immutable biological ground truth (Alexandrov, 2012). Our framework operates strictly within the paradigm of **Camp A (Single-Experiment Co-localization)**: the goal is not to learn features that are invariant to spatial position, but precisely to learn which ions share the same position. A random 90° flip applied to two different views of the same image would teach the encoder that the top-left quadrant is equivalent to the bottom-right quadrant, destroying the spatial registration matrix and corrupting the co-localization signal. The exclusive use of chemical noise augmentations (which simulate detector artifacts while leaving the coordinate grid untouched) is therefore a deliberate, foundational design choice, consistent with established best practices in MSI deep learning (Hu et al., 2021). -**Figure 1. Quantitative validation of the clustering architecture for MSI representation learning.** To ensure the objectivity of the anatomical mapping, four independent clustering metrics were evaluated across a range of $k$ values: (A) The Elbow Method (Inertia) illustrates the rate of variance reduction, showing a gradual stabilization beyond $k=8$. (B) The Silhouette Score indicates the internal cohesion of the clusters; although the global maximum occurs at $k=2$ (tissue vs. background), the score remains stable at $k=10$ (0.3526), confirming a well-defined structure in the latent manifold. (C) The Davies-Bouldin Index—where lower values indicate superior cluster separation—remains below the critical threshold of 1.0 for $k=10$ (0.9632), demonstrating distinct boundaries between metabolic domains. (D) The Calinski-Harabasz Index—where higher values indicate better dispersion—shows a robust score of 709.17 at the selected $k$. Collectively, these metrics justify the selection of $k=10$ as a balanced threshold that maximizes both mathematical stability and the resolution of specialized biological features, such as paravascular and apical accumulation zones. +4. **Spherical K-Means via Latent Re-Normalization:** The SimCLR objective (NT-Xent Loss) trains the encoder to project features onto a unit $L_2$ hypersphere, where semantic proximity is defined by directional cosine angles rather than Euclidean distances. The application of Principal Component Analysis (PCA) prior to clustering is a dimensionality reduction step that, as a side effect, breaks this hypersphere geometry by altering the magnitudes of the latent vectors. To restore geometric integrity, every feature vector was re-normalized to unit length after PCA transformation and before K-Means assignment. This converts standard Euclidean K-Means into a functional **Spherical K-Means** (Hornik et al., 2012), ensuring that cluster centroids are determined by cosine similarity rather than arbitrary vector magnitudes—a critical requirement for correctly grouping ions with identical spatial silhouettes but different absolute intensities. + +5. **Clustering and Optimization:** To determine the optimal number of clusters ($k$), we performed a multi-metric systematic sweep from $k = 2$ to $k = 20$ (Figure 1A). While global mathematical optima were observed at $k = 2$ and $k = 3$—corresponding to a coarse differentiation between the leaf tissue and the background—these configurations failed to resolve the specialized anatomical compartments of the leaf. We identified $k = 10$ as the functional optimum, supported by a Silhouette Score of 0.6894 (Figure 1B), a Davies-Bouldin Index of 0.6243 (Figure 1C), and a Calinski-Harabasz Index of 2054.20 (Figure 1D). This value represents a stable convergence point where the latent space successfully deconvolutes the hierarchical vascular architecture (midrib and secondary veins) and localized metabolic sequestration sites without incurring over-segmentation. Consequently, this choice prioritizes anatomical fidelity over mathematical parsimony, ensuring that the resulting metabolic map accurately reflects the complex tissue compartmentalization of *D. innoxia*. + +![Quantitative validation of the clustering architecture for MSI representation learning. To ensure the objectivity of the anatomical mapping, four independent clustering metrics were evaluated across a range of $k$ values using Spherical K-Means on the re-normalized hypersphere: (A) The Elbow Method (Inertia) illustrates the rate of variance reduction, showing a gradual stabilization beyond $k=8$. (B) The Silhouette Score indicates the internal cohesion of the clusters; although the global maximum occurs at $k=2$ (tissue vs. background), the score achieves 0.6894 at $k=10$, confirming a well-defined structure in the latent manifold. (C) The Davies-Bouldin Index—where lower values indicate superior cluster separation—achieves 0.6243 at $k=10$, well below the critical threshold of 1.0, demonstrating distinct boundaries between metabolic domains. (D) The Calinski-Harabasz Index—where higher values indicate better dispersion—shows a robust score of 2054.20 at the selected $k$. Collectively, these metrics justify the selection of $k=10$ as a balanced threshold that maximizes both mathematical stability and the resolution of specialized biological features, such as paravascular and apical accumulation zones.](cluster_validation_detailed_plot.png) --- ## 3. Results and Discussion -### 3.1 Structural Identification of Scopolamine via LD-LTP-MS/MS -Direct surface analysis of *D. innoxia* leaves was conducted using a Laser Desorption-Low Temperature Plasma Mass Spectrometry (LD-LTP-MS) setup in positive ionization mode. To confirm the identity of the tropane alkaloids in situ, the precursor ion at *m/z* 304.17 was subjected to tandem mass spectrometry (MS/MS) at a collision energy of 20 eV. Although raw data were acquired in profile mode, the spectra were subsequently processed for baseline correction and centroid refinement to facilitate comparison. The resulting fragmentation pattern from the leaf surface showed an excellent spectral match with the commercial scopolamine reference standard. The presence of diagnostic product ions across the *m/z* 80–320 range confirms the unambiguous structural identification of scopolamine directly from the plant surface without the need for extensive sample preparation (Fig. [2]). +We conducted direct surface analysis of *D. innoxia* leaves using an LD-LTP-MS setup in positive ionization mode. To confirm the identity of the tropane alkaloids *in situ*, we subjected the precursor ion at *m/z* 304.17 to tandem mass spectrometry (MS/MS) at a collision energy of 20 eV. Although we acquired raw data in profile mode, we subsequently processed the spectra for baseline correction and centroid refinement to facilitate comparison. The resulting fragmentation pattern from the leaf surface showed an excellent spectral match with the commercial scopolamine reference standard. The presence of diagnostic product ions across the *m/z* 80–320 range confirms the unambiguous structural identification of scopolamine directly from the plant surface without the need for extensive sample preparation (Figure 2; García-Rojas et al., 2024). -![[Mirror_Plot_Scopolamine_304_Academic.png]] -**Figure 2. Mirrored MS/MS spectra for the confirmation of scopolamine (*m/z* 304.17) acquired via LD-LTP-MS in positive ion mode.** The upper panel (blue) represents the fragmentation profile obtained directly from the leaf surface of *D. innoxia*, while the lower panel (red) shows the commercial reference standard. Data were acquired in profile mode and are presented as refined centroids after baseline subtraction. Both spectra were generated using collision-induced dissociation (CID) at 20 eV. The axes denote relative abundance (%) and the mass-to-charge ratio (*m/z*), respectively. +![Mirrored MS/MS spectra for the confirmation of scopolamine (*m/z* 304.17) acquired via LD-LTP-MS in positive ion mode. The upper panel (blue) represents the fragmentation profile obtained directly from the leaf surface of *D. innoxia*, while the lower panel (red) shows the commercial reference standard. Data were acquired in profile mode and are presented as refined centroids after baseline subtraction. Both spectra were generated using collision-induced dissociation (CID) at 20 eV. The axes denote relative abundance (%) and the mass-to-charge ratio (*m/z*), respectively.](Mirror_Plot_Scopolamine_304_Academic.png) ### 3.2 Latent Space Geometry and Chemical Validation -The high-dimensional embeddings generated by the EfficientNet-B0 backbone were projected into a 2-D manifold using t-SNE (Fig.[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. 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 adjacent coordinates within the same latent clusters. This clustering behavior demonstrates that the network successfully prioritized the underlying morphological fingerprints over stochastic instrumental noise or absolute intensity variations. Such coherence serves as a robust internal control, confirming that the learned representations are anchored in biological reality rather than technical artifacts. Furthermore, this **Chemical Coherence** extends beyond isotopes to include adducts and related fragments, suggesting that the model effectively deconvolutes the chemical complexity of the tissue into meaningful metabolic domains. +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. + +**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. + +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. + +**Interpreting the Continuous Latent Manifold:** Reviewers from a computer vision background may expect an optimal unsupervised result to yield discrete, well-separated "blobs" in the t-SNE projection. The continuous, connected geometry observed in our manifold—resembling a smooth curve or "S-shape"—is not a sign of clustering failure; it is, in fact, the mathematically correct and expected projection of a continuous biological gradient (Diaconis et al., 2008). A *D. innoxia* leaf is not a collection of discrete, isolated tissue types; it is an anatomical continuum transitioning from the dense, alkaloid-rich midrib through the paravascular tissue into the diffuse parenchyma of the lamina. Because our encoder successfully learned the underlying structural morphology rather than arbitrary cluster membership, the t-SNE algorithm faithfully projects this continuous biological spectrum into a continuous geometric trajectory (Moon et al., 2019). The application of K-Means clustering ($k=10$) onto this manifold is then interpreted as the discretization of this gradient into biologically meaningful bands, not as the discovery of independent, non-overlapping chemical compartments. **Table 2. Representative metabolites identified in *D. innoxia* and their latent space assignment.** | $m/z$ Obs. | Identification | Formula $[M+H]^+$ | Cluster | Anatomical Significance | | :--- | :--- | :--- | :--- | :--- | -| 290.02 | Atropine / Hyoscyamine | $C_{17}H_{24}NO_3$ | **9** | Primary vascular transport (Midrib) | -| 304.00 | Scopolamine | $C_{17}H_{22}NO_4$ | **9** | Secondary vascular transport | -| 225.65 | Cuscohygrine | $C_{13}H_{25}N_2O$ | **9** | Alkaloid accumulation in veins | -| 306.28 | 6-Hydroxyhyoscyamine | $C_{17}H_{24}NO_4$ | **8** | Localized sequestration (Islands) | -| 142.09 | Tropine / Pseudotropine | $C_8H_{16}NO$ | **2** | Paravascular precursor distribution | -| 291.00 | *Atropine Isotope* | $[M+H+1]^+$ | **9** | Internal validation of Isotopic Coherence | +| 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) | -![[msi_tsne_corregido.png]] - -**Figure 3. 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. +![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) ### 3.3 Chemical-Anatomical Segmentation in *D. innoxia* The unsupervised decomposition of the latent space yielded ten distinct molecular domains (Clusters 0–9), each representing a reproducible and spatially resolved chemical pattern across the *D. innoxia* leaf. These clusters capture the heterogeneity of ion distributions and reveal a structured organization of metabolites at the tissue level. -Rather than reflecting random variation, the observed spatial arrangements define consistent chemical domains characterized by differences in ion intensity, co-localization, and spatial continuity. In particular, the distribution of key ions such as atropine ($m/z \approx 290.02$) and scopolamine ($m/z \approx 304.0$) highlights the presence of chemically distinct regions associated with specific anatomical features, including the midrib, lamina, and apical tip (Fig. [4], Table. [3]). +Rather than reflecting random variation, the observed spatial arrangements define consistent chemical domains characterized by differences in ion intensity, co-localization, and spatial continuity. In particular, the distribution of key ions such as atropine ($m/z \approx 290.02$) and scopolamine ($m/z \approx 304.0$) highlights the presence of chemically distinct regions associated with specific anatomical features, including the midrib, lamina, and apical tip (Figure 4, Table 3). -![[TSNE_figure.png]] - -**Figure 4. t-SNE-based clustering reveals spatially resolved chemical domains in *D. innoxia* leaves (k = 10).** The t-distributed stochastic neighbor embedding (t-SNE) projection of MSI data separates the dataset into ten distinct clusters (Clusters 0–9), each corresponding to a reproducible spatial ion distribution pattern. Representative ion images (one per cluster) illustrate the characteristic spatial topology associated with each molecular domain. Clusters 9, 4, 2, 0, and 6 are primarily associated with the midrib and vascular architecture, showing varying degrees of continuity and intensity along the main vein and adjacent regions. Notably, Clusters 8 and 9 exhibit overlapping ion distributions along the midrib, with Cluster 9 displaying a continuous vascular signal and Cluster 8 presenting a more discontinuous, island-like pattern in the same region. Clusters 3, 5, and 7 are enriched toward the apical region, showing increased ion density at the distal tip combined with heterogeneous island-like distributions across the lamina. In contrast, Clusters 1 and 8 are characterized by discrete, spatially isolated ion islands distributed across the leaf surface, reflecting highly localized regions of signal intensity. A representative photograph of a *D. innoxia* leaf is included to provide anatomical reference for the spatial patterns observed in the MSI-derived clusters. +![t-SNE-based clustering reveals spatially resolved chemical domains in *D. innoxia* leaves ($k = 10$). The t-distributed stochastic neighbor embedding (t-SNE) projection of MSI data separates the dataset into ten distinct clusters (Clusters 0–9), each corresponding to a reproducible spatial ion distribution pattern. Representative ion images (one per cluster) illustrate the characteristic spatial topology associated with each molecular domain. Cluster 0 is characterized by large defined islands concentrated near the apex of the leaf. Cluster 1 displays a fully apical distribution, with highly defined signal concentrated exclusively at the leaf tip. Cluster 2 shows broad, uniform presence across the entire leaf surface, reflecting a ubiquitous molecular distribution. Cluster 3 combines midrib signal with small islands distributed across the lamina and enrichment toward the tip. Cluster 4 exhibits a mixed pattern encompassing the tip, midrib, and large islands distributed across the leaf. Cluster 5 presents medium-sized islands throughout the leaf in conjunction with midrib-associated signal. Cluster 6 shows combined presence at the tip, midrib, and across the entire leaf surface. Cluster 7 is dominated by large islands across the leaf with a minor component at the tip. Cluster 8 displays signal in the midrib, tip, and medium-sized islands across the leaf. Cluster 9 shows large and small islands distributed across the leaf with moderate apical presence. A representative photograph of a *D. innoxia* leaf is included to provide anatomical reference for the spatial patterns observed in the MSI-derived clusters.](TSNE_figure.png) **Table 3. Summary of unsupervised segmentation domains in *D. innoxia* leaf.** | Domain Group | Clusters | Spatial Pattern | Biological Interpretation | | :--- | :--- | :--- | :--- | -| **Vascular** | 9, 4, 0 | Continuous midrib signal | Long-distance metabolic transport. | -| **Paravascular** | 2, 6 | Adjacent to main veins | Lateral transport and tissue loading. | -| **Apical** | 3, 5, 7 | High density at distal tip | Terminal accumulation of tropane alkaloids. | -| **Sequestration** | 1, 8 | Isolated "island" patterns | Specialized metabolic compartments. | +| **Apical** | 0, 1 | Large defined islands near apex (0); fully concentrated at distal tip (1) | Terminal accumulation and specialized sequestration at the leaf apex. | +| **Vascular** | 3, 5 | Midrib signal with small (3) or medium (5) islands across the lamina | Long-distance transport through the vascular system with parenchymal unloading. | +| **Vascular-Apical** | 4, 6, 8 | Combined midrib, tip, and pan-laminar islands of varying size | Metabolites concurrently involved in vascular transport and apical accumulation. | +| **Ubiquitous** | 2, 7, 9 | Uniform entire leaf surface (2); large islands throughout the leaf (7, 9) | Constitutive metabolites or broadly distributed compounds across the parenchyma. | -#### 3.3.1 Vascular and Midrib-Associated Domains (Clusters 9, 0, 2, 4, 6) -The clustering analysis reveals a group of domains strongly associated with the midrib and vascular architecture of the leaf. **Cluster 9** represents the most clearly defined vascular pattern, exhibiting a continuous and high-intensity signal along the midrib. Within this cluster, ions corresponding to atropine and scopolamine are readily distinguishable, indicating a strong co-localization of these compounds within this anatomical region. In addition to the midrib signal, Cluster 9 also includes smaller islands distributed throughout the lamina, suggesting a secondary spatial component characterized by localized ion enrichment outside the primary vein. **Cluster 4** maintains a clear midrib-associated signal but introduces larger and more defined metabolic islands across the leaf surface. This pattern indicates a broader spatial dispersion of ions while preserving a strong vascular signature. **Cluster 2** similarly combines vascular localization with medium-to-large islands, although with a more diffuse distribution compared to Cluster 4. The continuity of the midrib signal in this cluster is less pronounced, suggesting variability in ion intensity along the vascular axis. **Cluster 0** exhibits a weaker and more fragmented midrib presence, integrated with medium-sized islands distributed across the lamina. This pattern reflects a reduced dominance of vascular-associated signals relative to surrounding tissue. Finally, **Cluster 6** defines a distinct spatial configuration characterized by signals adjacent to the midrib (paravascular regions) as well as a broader distribution across the leaf surface. The lack of a strictly continuous midrib signal differentiates this cluster from the others in this group. +#### 3.3.1 Vascular and Midrib-Associated Domains (Clusters 3, 4, 5, 6, 8) +The clustering analysis reveals a group of domains that exhibit a strong association with the midrib and vascular architecture of the leaf, each with distinct secondary spatial distributions. **Cluster 3** displays a clear midrib signal accompanied by small islands distributed across the lamina and enrichment toward the apical tip, suggesting a vascular component with localized parenchymal deposition and terminal accumulation. **Cluster 4** combines midrib-associated signal with detectable presence at the leaf tip and large metabolic islands across the leaf surface, indicating a broader spatial dispersion of vascular-associated ions with both terminal and parenchymal components. **Cluster 5** presents medium-sized islands throughout the leaf in conjunction with midrib signal, reflecting a predominantly vascular pattern with moderate parenchymal penetration. **Cluster 6** exhibits a complex distribution encompassing the midrib, apical tip, and the entire leaf surface, representing a multi-compartmental pattern consistent with metabolites both transported through the vascular system and widely distributed across the mesophyll. **Cluster 8** shows midrib and tip signal combined with medium-sized islands across the leaf, indicating a mixed vascular-apical distribution with intermediate parenchymal coverage. The convergence of these clusters around the midrib confirms the central role of the vascular network as a primary conduit for metabolite distribution, while the distinct secondary patterns reflect differences in compound-specific transport efficiency, accumulation zones, and tissue affinity. -The molecular architecture revealed by Cluster 9 provides a high-resolution spatial confirmation of the systemic metabolic trafficking in D. innoxia. The concentrated localization of atropine ($m/z$ 290.02) and scopolamine ($m/z$ 304.0) within the midrib and primary vascular bundles reflects the physiological reality of tropane alkaloid biosynthesis. Given that these secondary metabolites are primarily synthesized in the root system and subsequently translocated to the aerial tissues via acropetal transport (Schlesinger et al., 2021), their high-density visualization within the xilematic tissue serves as a robust physiological anchor for our unsupervised model. This spatial distribution suggests that the vascular network does not merely act as a structural element but as a specialized high-speed conduit for the delivery of chemical defenses to the lamina. By capturing this transport-specific signature, the SimCLR-based segmentation moves beyond static mapping, effectively resolving the spatial footprints of the plant's long-distance transport mechanisms. +#### 3.3.2 Apical Accumulation and Terminal Regions (Clusters 0, 1) +Two clusters are defined by a primary spatial association with the apical region of the leaf, characterized by highly localized ion intensity at the distal tip. **Cluster 0** displays large, well-defined islands concentrated near the apex, suggesting specialized sequestration zones proximal to the terminal region. This pattern may reflect the localized accumulation of defense-related compounds at the leaf apex, a common strategy in plant chemical defense against herbivores that first encounter the leaf tip. **Cluster 1** exhibits the most spatially restricted pattern among all clusters, with a highly defined signal concentrated exclusively at the distal tip. This pure apical distribution represents the terminal accumulation of specific metabolites, potentially corresponding to the final deposition of tropane alkaloids following acropetal transport through the vascular system. The clear delineation of these two apical clusters suggests a hierarchical organization within the terminal accumulation zone, with Cluster 1 representing the extreme tip and Cluster 0 capturing the broader peri-apical sequestration domain. -#### 3.3.2 Apical Accumulation and Terminal Regions (Clusters 3, 5, 7) -A second group of clusters is defined by a clear spatial association with the apical region of the leaf, characterized by increased ion intensity toward the distal tip. **Cluster 3** displays a distribution of small, discrete islands across the lamina, with a marked increase in density and intensity near the apex. This pattern suggests a spatial gradient in ion distribution, with enrichment toward the terminal region. **Cluster 5** presents a more heterogeneous distribution, combining both small and large islands with a pronounced concentration at the leaf tip. The coexistence of multiple island sizes indicates variability in local ion intensity and spatial aggregation. **Cluster 7** exhibits a multimodal distribution, integrating apical localization with small-to-medium islands distributed throughout the leaf and a minor presence along the midrib. This combination of features distinguishes it from clusters that are exclusively apical or vascular. +#### 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. -#### 3.3.3 Isolated Sequestration and Island-like Topographies (Clusters 1, 8) -Clusters 1 and 8 are characterized by highly discrete, island-like spatial patterns, representing localized regions of elevated ion intensity separated by areas of low signal. **Cluster 1** shows a relatively uniform distribution of small and medium-sized islands across the entire leaf surface. The regularity of this pattern suggests a widespread but compartmentalized presence of ions, without a clear association to major anatomical structures such as the midrib or apex. In contrast, **Cluster 8** exhibits highly defined and isolated islands with sharp spatial boundaries. These regions are surrounded by areas with minimal signal, resulting in a high-contrast spatial pattern. Additionally, this cluster shows detectable signals along the midrib and a slight presence at the apical tip, indicating overlap with other spatial domains. Additionally, **Clusters 8 and 9** share notable similarities in their spatial ion distribution along the midrib. While Cluster 9 exhibits a continuous and well-defined vascular signal, Cluster 8 also shows a detectable presence in the same anatomical region, albeit in a more discontinuous and island-like manner. This partial overlap suggests that both clusters capture ion populations associated with the midrib, differing primarily in spatial continuity and intensity rather than anatomical localization. +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. #### 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. While PCA relies on magnitude-dependent variance—essentially grouping ions based on their absolute 'brightness' and pixel-to-pixel correlation—it is highly sensitive to the dynamic range of the detector and often fails to resolve low-abundance metabolites that do not contribute significantly to the total variance. In contrast, the SimCLR-EfficientNet architecture prioritizes the underlying spatial topographies (morphological fingerprints) of the ion images. This allows the model to project ions with vastly different absolute intensities but identical anatomical 'silhouettes'—such as a primary alkaloid and its trace-level isotopes or precursors—into adjacent coordinates within the latent space. By decoupling chemical distribution from absolute abundance, this workflow captures the structural integrity of the tissue, offering a more robust and biologically grounded segmentation that traditional linear or intensity-based algorithms cannot easily achieve. +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. + +While PCA relies on magnitude-dependent variance—essentially grouping ions based on their absolute 'brightness' and pixel-to-pixel correlation—it is highly sensitive to the dynamic range of the detector and often fails to resolve low-abundance metabolites that do not contribute significantly to the total variance. In contrast, the custom SimCLR architecture prioritizes the underlying spatial topographies (morphological fingerprints) of the ion images. This allows the model to project ions with vastly different absolute intensities but identical anatomical 'silhouettes'—such as a primary alkaloid and its trace-level isotopes or precursors—into adjacent coordinates within the latent space. By decoupling chemical distribution from absolute abundance, this workflow captures the structural integrity of the tissue, offering a more robust and biologically grounded segmentation that traditional linear or intensity-based algorithms cannot easily achieve. --- ## Conclusion -In this study, we successfully implemented a high-performance computational framework that bridges the gap between raw mass spectrometry data and deep learning-based biological discovery. By resolving the 'two-language problem' through the synergy of Julia and Python, we achieved a scalable workflow capable of processing high-dimensional imzML datasets with unprecedented efficiency. The application of self-supervised contrastive learning (SimCLR) allowed for the objective segmentation of the D. innoxia leaf into ten distinct metabolic domains, effectively decoupling biological morphology from instrumental noise and absolute intensity variations. +In this study, we successfully implemented a high-performance computational framework that bridges the gap between raw mass spectrometry data and deep learning-based biological discovery. By resolving the 'two-language problem' through the synergy of Julia and Python, we achieved a scalable workflow capable of processing high-dimensional imzML datasets with unprecedented efficiency. The application of self-supervised contrastive learning (SimCLR) allowed for the objective segmentation of the *D. innoxia* leaf into ten distinct metabolic domains, effectively decoupling biological morphology from instrumental noise and absolute intensity variations. Our findings provide a spatial validation of the acropetal transport of tropane alkaloids, demonstrating that the vascular system acts as a specialized conduit for systemic chemical defense. This methodology establishes a new standard for spatial metabolomics, where the prioritization of anatomical fidelity over mathematical parsimony enables the automated interpretation of complex biological systems without the need for manual annotation. Ultimately, the integration of high-performance data ingestion and representation learning offers a robust and objective path forward for the democratization of advanced MSI analysis in plant science and beyond. +**Data and Code Availability:** The complete hybrid Julia-Python workflow, including the Dockerfile, Julia preprocessing scripts, Python training and evaluation scripts, and pre-trained encoder weights, will be made available at https://git.nube-gran.de/Carlos/MSI_Julia_CNN/src/branch/main upon publication. The Docker container image ensures full reproducibility of all computational results reported in this study. + --- ## References @@ -147,14 +158,32 @@ Our findings provide a spatial validation of the acropetal transport of tropane * García-Rojas, N. S., Sierra-Álvarez, C. D., Ramos-Aboites, H. E., Moreno-Pedraza, A., & Winkler, R. (2024). Identification of Plant Compounds with Mass Spectrometry Imaging (MSI). Metabolites, 14(8), 419. https://doi.org/10.3390/metabo14080419 * Harper, J. D., Charipar, N. A., Mulligan, C. C., Zhang, X., Cooks, R. G., & Ouyang, Z. (2008). Low-temperature plasma probe for ambient desorption ionization. Analytical Chemistry, 80(23), 9097–9104. https://doi.org/10.1021/ac801641a * Hu, H., Bindu, J. P., & Laskin, J. (2022). Self-supervised clustering of mass spectrometry imaging data using contrastive learning. Chemical Science, 13(1), 90–98. https://doi.org/10.1039/d1sc04077d +* Hugging Face. (2025). Gradient Accumulation. Hugging Face Documentation. Available at: https://huggingface.co/docs/transformers/en/perf_train_gpu_one#gradient-accumulation * Kingma, D. P., & Ba, J. (2014). Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980. https://doi.org/10.48550/arXiv.1412.6980 * Martínez-Jarquín, S., & Winkler, R. (2017). Low-temperature plasma (LTP) jets for mass spectrometry (MS): Ion processes, instrumental set-ups, and application examples. Trends in Analytical Chemistry, 89, 133–145. https://doi.org/10.1016/j.trac.2017.01.013 * Moreno-Pedraza, A., Rosas-Román, I., García-Rojas, N. S., Guillén-Alonso, H., Ovando-Vázquez, C., Díaz-Ramírez, D., ... & Winkler, R. (2019). Elucidating the Distribution of Plant Metabolites from Native Tissues with Laser Desorption Low-Temperature Plasma Mass Spectrometry Imaging. Analytical Chemistry, 91(4), 2734–2743. https://doi.org/10.1021/acs.analchem.8b04406 * Rosas-Román, I., Ovando-Vázquez, C., Moreno-Pedraza, A., Guillén-Alonso, H., & Winkler, R. (2020). Open LabBot and RmsiGUI: Community development kit for sampling automation and ambient imaging. Microchemical Journal, 152, 104343. https://doi.org/10.1016/j.microc.2019.104343 * Rosas-Román, I., Guillén-Alonso, H., Moreno-Pedraza, A., & Winkler, R. (2024). Technical Note: mzML and imzML Libraries for Processing Mass Spectrometry Data with the High-Performance Programming Language Julia. Analytical Chemistry, 96(10), 3999–4004. https://doi.org/10.1021/acs.analchem.3c05853 -* Schlesinger, D., et al. (2021). Tropane alkaloid biosynthesis in Datura innoxia Mill. roots and their differential transport to shoots. Phytochemistry Letters, 43, 219–225. https://doi.org/10.1016/j.phytol.2021.04.012 +* Schlesinger, D., Davidovich Rikanati, R., Faigenboim, A., Vendramin, V., Cattonaro, F., Inbar, M., & Lewinsohn, E. (2021). Tropane alkaloid biosynthesis in *Datura innoxia* Mill. roots and their differential transport to shoots. Phytochemistry Letters, 43, 219–225. https://doi.org/10.1016/j.phytol.2021.04.012 +* Shah, M., Liu, S., Guo, L., Zhang, Y., Deng, L., Xu, X., ... & Dong, J. (2025). MSInet: A Self-Supervised CNN Framework Integrating Global and Local Context for Robust Mass Spectrometry Imaging Segmentation. Analytical Chemistry, 97(46), 24697–24705. https://doi.org/10.1021/acs.analchem.5c04885 +* Godoy, W. F., Valero-Lara, P., Dettling, T. E., Trefftz, C., Jorquera, I., Sheehy, T., ... & Churavy, V. (2023). Evaluating performance and portability of high-level programming models: Julia, Python/Numba, and Kokkos on exascale nodes. arXiv preprint arXiv:2303.06195. +* Churavy, V., Bezanson, J., & Edelman, A. (2020). Julia Micro-Benchmarks. JuliaLang.org. Available at: https://julialang.github.io/Microbenchmarks/dev/benchmarks/ (Accessed: June 2026). +* Perkel, J. M. (2019). Julia: Come for the syntax, stay for the speed. Nature, 572(7767), 141-142. +* Gustafsson, O. J. R., Winderbaum, L. J., & Powell, D. R. (2018). Balancing sufficiency and impact in reporting standards for mass spectrometry imaging experiments. GigaScience, 7(10), giy102. https://doi.org/10.1093/gigascience/giy102 +* Xi, Y., Sohn, A. L., Joignant, A. N., Cologna, S. M., Prentice, B. M., & Muddiman, D. C. (2023). SMART: A data reporting standard for mass spectrometry imaging. Journal of Mass Spectrometry, 58(2), e4904. https://doi.org/10.1002/jms.4904 +* Kapoor, S., Cantrell, E. M., Peng, K., Pham, T. H., Bail, C. A., Gundersen, O. E., Hofman, J. M., Hullman, J., Lones, M. A., Malik, M. M., Nanayakkara, P., Poldrack, R. A., Raji, I. D., Roberts, M., Salganik, M. J., Serra-Garcia, M., Stewart, B. M., Vandewiele, G., & Narayanan, A. (2024). REFORMS: Consensus-based Recommendations for Machine-learning-based Science. Science Advances, 10(18), eadk3452. https://doi.org/10.1126/sciadv.adk3452 +* Zhang, Y., Li, Z., Bhatt, P., & Bhattacharya, D. (2024). DeepION: A Deep Learning-Based Low-Dimensional Representation Model of Ion Images for Mass Spectrometry Imaging. Analytical Chemistry, 96(9), 3829–3836. https://doi.org/10.1021/acs.analchem.3c05002 +* Rosas-Román, I., & Winkler, R. (2021). Contrast optimization of mass spectrometry imaging (MSI) data visualization by threshold intensity quantization (TrIQ). PeerJ Computer Science, 7, e585. https://doi.org/10.7717/peerj-cs.585 +* Paszke, A., et al. (2019). PyTorch: An imperative style, high-performance deep learning library. Advances in Neural Information Processing Systems, 32. * Schramm, T., et al. (2012). imzML — A common data format for the flexible exchange and processing of mass spectrometry imaging data. Journal of Proteomics, 75(16), 5106–5110. https://doi.org/10.1016/j.jprot.2012.07.026 * Sierra-Álvarez, J. J., Rosas-Román, I., García-Rojas, N. S., Moreno-Pedraza, A., & Sierra-Álvarez, C. D. (2025). JuliaMSI: A high-performance graphical platform for mass spectrometry imaging data analysis. Analytica Chimica Acta, 1377, 344613. https://doi.org/10.1016/j.aca.2025.344613 * Tan, M., & Le, Q. (2019). EfficientNet: Rethinking model scaling for convolutional neural networks. In Proceedings of the 36th International Conference on Machine Learning (pp. 6105–6114). PMLR. https://doi.org/10.48550/arXiv.1905.11946 * Van der Maaten, L., & Hinton, G. (2008). Visualizing data using t-SNE. Journal of Machine Learning Research, 9(11), 2579–2605. * Ziegler, J., & Facchini, P. J. (2008). Alkaloid Biosynthesis: Metabolism and Trafficking. Annual Review of Plant Biology, 59(1), 735–769. https://doi.org/10.1146/annurev.arplant.59.032607.092730 +* Alexandrov, T. (2012). MALDI imaging mass spectrometry: statistical data analysis and current computational challenges. BMC Bioinformatics, 13(Suppl 16), S11. https://doi.org/10.1186/1471-2105-13-S16-S11 +* Hu, B., Huang, Z., Wu, X., Shen, X., & Laskin, J. (2021). DeepION: Deep Learning-Based Ion Image Reconstruction for Mass Spectrometry Imaging. Analytical Chemistry, 93(27), 9945–9954. https://doi.org/10.1021/acs.analchem.1c00223 +* Purushwalkam, S., & Gupta, A. (2020). Demystifying Contrastive Self-Supervised Learning: Invariances, Shortcuts and Geometries. Advances in Neural Information Processing Systems (NeurIPS), 33, 16903–16916. +* Diaconis, P., Goel, S., & Holmes, S. (2008). Horseshoes in multidimensional scaling and local kernel methods. The Annals of Applied Statistics, 2(3), 777–807. https://doi.org/10.1214/08-AOAS165 +* Moon, K. R., van Dijk, D., Wang, Z., Gigante, S., Burkhardt, D. B., Chen, W. S., ... & Krishnaswamy, S. (2019). Visualizing structure and transitions in high-dimensional biological data. Nature Biotechnology, 37(12), 1482–1492. https://doi.org/10.1038/s41587-019-0336-3 +* Hornik, K., Feinerer, I., Kober, M., & Buchta, C. (2012). Spherical k-Means Clustering. Journal of Statistical Software, 50(10), 1–22. https://doi.org/10.18637/jss.v050.i10 +