14 KiB
Deep learning in Mass Spectrometry Imaging: A Hybrid Julia-Python Workflow for the Automated Anatomical Mapping of Datura innoxia
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.
Abstract
Mass Spectrometry Imaging (MSI) has emerged as a fundamental tool in spatial metabolomics (García-Rojas et al., 2024), 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 the need for prior labeling. This system was applied to the study of Datura innoxia (toloache) leaves, achieving automated anatomical segmentation that accurately distinguishes vascular 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).
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.
2. Methodology
2.1 Phase I: 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, enabling the high-throughput extraction of mass slices without compromising spectral precision.
- Ion Extraction and Filtering: Mass slices were extracted from the
Leaf.imzMLdataset within the m/z 50.0 to 700.0 range. 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. - TrIQ Normalization (Threshold Intensity Quantization): A dynamic TrIQ algorithm was implemented, calculating the 98th percentile to mitigate hotspots and preserve contrast in low-intensity regions (Rosas-Román et al., 2024). For each ion map, the 98th percentile of the intensity distribution was calculated; all pixels exceeding this value were capped at this threshold. This percentile-based approach prevents outliers from skewing the global contrast, thereby preserving the spatial details of low-abundance metabolites that would otherwise be suppressed in a standard linear scaling. By compressing the dynamic range, TrIQ ensures that the morphological features of the chemical distributions are standardized, which is essential for the stability of the subsequent contrastive learning phase.
- 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).
2.2 Phase II: Self-Supervised Representation Learning (Python)
We implemented a Contrastive Learning (SimCLR) scheme in PyTorch, following the methodology proposed by Hu et al. (2022).
- Model Architecture: EfficientNet-B0 was used as the backbone encoder. The final classification layer was removed and replaced with a two-layer MLP projection head to project the data into a 128-dimensional space.
- 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.
- NT-Xent Loss Function: The model was trained to maximize the similarity between two augmented views of the same ion, forcing the network to learn which spatial features define a molecule independently of its absolute intensity.
3. Results and Discussion
3.1 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.[X]). 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. 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.
Figure X. 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 100 µ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.
3.2 Chemical-Anatomical Segmentation in D. innoxia
The unsupervised decomposition of the latent space yielded ten distinct molecular domains, each reflecting a specialized spatial organization within the D. innoxia leaf. The morphological patterns observed across these clusters provide significant insights into the metabolic compartmentalization of tropane alkaloids and other secondary metabolites.
3.2.1 Vascular and Transport Systems (Clusters 3, 7, and 8)
The neural network accurately delineated the leaf’s transport system without prior anatomical knowledge. Cluster 3 specifically isolates the primary venation, characterized by ions involved in the long-distance translocation of metabolites. A key finding was the assignment of scopolamine (m/z \approx 304) to this domain corroborating its active mobilization through the vascular conduit from its biosynthetic origin in the roots to the leaf lamina. Clusters 7 and 8 further define "transition zones" and "terminal sinks," where metabolites move from the xylem/phloem into the surrounding parenchyma or accumulate at the apical margins.
3.2.2 Apical Accumulation and Defense (Clusters 1, 6, 8, and 9)
- Cluster 1 (Pure Apical): Exclusively localized at the leaf tip, this cluster represents a highly specific chemical domain. Concentration at the leaf apex is a known defense strategy in Solanaceae, potentially related to guttation or the directed accumulation of toxins to deter herbivores at the most exposed parts of the leaf.
- Cluster 6 (Mixed Apical/Patchy): This cluster exhibits a unique combination of apical concentration and large, patchy distributions across the leaf surface. Hyoscyamine (
m/z \approx 290) was assigned to this domain, suggesting a dual role of storage in specialized tissues (patchy "islands") and accumulation at the leaf tips for localized defense.
3.2.3 Compartmentalized Patchy Distributions (Clusters 0, 4, 5)
- Clusters 0, 4, and 5 reveal a 'punctate' or 'island-like' topography, a spatial hallmark of specialized epidermal structures such as glandular trichomes. In D. innoxia, these chemical foci likely represent discrete sequestration sites where tropane alkaloids are concentrated to mitigate autotoxicity while maintaining a frontline defense against herbivory.
3.2.4 Ubiquitous Homogeneous Background (Cluster 2)
- Cluster 2 (Universal Distribution): This cluster encompasses ions distributed uniformly across the entire leaf surface. These signals are likely associated with primary metabolism (e.g., chlorophylls, lipids, and structural carbohydrates) or common background signals inherent to the biological matrix, serving as the metabolic baseline of the leaf tissue.
4. Conclusion
The integration of a hybrid Julia-Python pipeline (Sierra-Álvarez et al., 2025; Rosas-Román et al., 2024) represents a significant advancement in the democratization of advanced MSI analysis. While Julia overcomes performance barriers in massive data ingestion, contrastive learning in Python enables objective and automated biological interpretation. This approach establishes a standard for spatial metabolomics studies where tissue complexity exceeds manual analysis capacity.
5. References
- Cole, L. M., & Clench, M. R. (Eds.). (2023). Imaging Mass Spectrometry: Methods and Protocols. Springer US. https://doi.org/10.1007/978-1-0716-3319-9
- García-Rojas, N. S., Sierra-Álvarez, C. D., et al. (2024). Identification of Plant Compounds with Mass Spectrometry Imaging (MSI). Metabolites, 14(8), 419. https://doi.org/10.3390/metabo14080419
- 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
- Moreno-Pedraza, A., Rosas-Román, I., et al. (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., Guillén-Alonso, H., et al. (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
- 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., ..., Sierra-Álvarez, C. D., et al. (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
- 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
