From cd7e6174134363dbb5a38de85c3c897dbb59b3af Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 2 Sep 2026 22:16:31 +0200 Subject: [PATCH] Subir archivos a "/" --- MSI_julia-python_mapping.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/MSI_julia-python_mapping.md b/MSI_julia-python_mapping.md index d326ce1..185c5a4 100644 --- a/MSI_julia-python_mapping.md +++ b/MSI_julia-python_mapping.md @@ -2,7 +2,7 @@ title: "A scalable deep learning workflow for mass spectrometry imaging: benchmarking Julia-Python hybrid processing across multi-instrument datasets" bibliography: zotero.bib abstract: | - Mass spectrometry imaging (MSI) generates terabyte-scale datasets whose analysis is increasingly bottlenecked by software rather than instrumentation. Most MSI processing pipelines are written in interpreted languages whose memory and speed limits scale poorly with next-generation instruments, and the deep learning ecosystem needed for modern unsupervised analysis lives almost entirely in Python. We present an open-source hybrid Julia-Python workflow that resolves this: a Julia engine performs all high-throughput preprocessing (memory-mapped imzML parsing, peak picking, ion image extraction, TrIQ normalization, and PNG export of every ion map in a single pass) and hands a clean, file-based corpus to a Python self-supervised (SimCLR) convolutional encoder for representation learning and clustering. We benchmark the Julia preprocessing stage on an equalized per-stage workload (imzML load and one ion slice generation at each dataset's reference *m/z*) against Cardinal (R/Bioconductor) and MALDIquant (R) on seven public datasets spanning 0.07–4.4 GB (LD-LTP, AP-SMALDI, MALDI, DESI), covering both centroid and profile acquisitions. Under this equalized workload, the Julia engine generates an ion slice up to two orders of magnitude faster than Cardinal on every dataset and materially faster than MALDIquant, while its memory-mapped loader keeps peak load RAM at only 7–84 MB (lower than Cardinal's lazy loader on all seven datasets) and it completes the additional normalization and export steps within the same memory envelope, all orchestrated by a single reproducible entry point. The Python layer learns a 128-dimensional latent space from the exported ion corpus and clusters the ions into spatially coherent metabolic domains; we detail the algorithmic choices (Group Normalization, gradient accumulation for consumer GPUs, chemical-noise augmentation, and spherical K-Means) that make the deep learning stage tractable on big, zero-padded MSI data. The complete environment is containerized with Docker and released under a permissive license, so the entire analysis (from raw imzML to trained embeddings) is fully reproducible on any hardware. As a demonstration of the workflow's biological utility, we apply it to *Datura innoxia* leaves and roots (2.0 GB and 2.5 GB): self-supervised segmentation recovers spatially coherent metabolic domains that resolve the tropane alkaloid biosynthetic and transport architecture of the tissue. + Mass spectrometry imaging (MSI) generates terabyte-scale datasets whose analysis is increasingly bottlenecked by software rather than instrumentation. Most MSI processing pipelines are written in interpreted languages whose memory and speed limits scale poorly with next-generation instruments, and the deep learning ecosystem needed for modern unsupervised analysis lives almost entirely in Python. We present an open-source hybrid Julia-Python workflow that resolves this: a Julia engine performs all high-throughput preprocessing (memory-mapped imzML parsing, peak picking, ion image extraction, TrIQ normalization, and PNG export of every ion map in a single pass) and hands a clean, file-based corpus to a Python self-supervised (SimCLR) convolutional encoder for representation learning and clustering. We benchmark the Julia preprocessing stage on an equalized per-stage workload (imzML load and one ion slice generation at each dataset's reference *m/z*) against Cardinal (R/Bioconductor) and MALDIquant (R) on seven public datasets spanning 0.61–4.4 GB (LD-LTP, AP-SMALDI, MALDI, DESI), covering both centroid and profile acquisitions. Under this equalized workload, the Julia engine generates an ion slice up to two orders of magnitude faster than Cardinal on every dataset and materially faster than MALDIquant, while its memory-mapped loader keeps peak load RAM at only 7–84 MB (lower than Cardinal's lazy loader on all seven datasets) and it completes the additional normalization and export steps within the same memory envelope, all orchestrated by a single reproducible entry point. The Python layer learns a 128-dimensional latent space from the exported ion corpus and clusters the ions into spatially coherent metabolic domains; we detail the algorithmic choices (Group Normalization, gradient accumulation for consumer GPUs, chemical-noise augmentation, and spherical K-Means) that make the deep learning stage tractable on big, zero-padded MSI data. The complete environment is containerized with Docker and released under a permissive license, so the entire analysis (from raw imzML to trained embeddings) is fully reproducible on any hardware. As a demonstration of the workflow's biological utility, we apply it to *Datura innoxia* leaves and roots (2.0 GB and 2.5 GB): self-supervised segmentation recovers spatially coherent metabolic domains that resolve the tropane alkaloid biosynthetic and transport architecture of the tissue. keywords: mass spectrometry imaging, Julia language, Python, hybrid pipeline, benchmark, peak RAM, reproducibility, deep learning, SimCLR, contrastive learning, spatial metabolomics --- @@ -12,25 +12,25 @@ Mass spectrometry imaging (MSI) produces spatially resolved molecular maps of bi We address this problem with an open-source hybrid Julia-Python workflow. Julia combines execution speeds comparable to compiled languages with a scientific computing environment [@rosas-roman_open_2020], making it well suited to the memory-mapped parsing and high-throughput ion image extraction that dominate MSI preprocessing; Python contributes the mature artificial intelligence stack (PyTorch) that the representation learning stage requires [@paszke_pytorch_2019]. The two layers are separated by a clean, file-based interface: Julia ingests the raw imzML [@schramm_imzml_2012] binary files, extracts and normalizes every ion image, and exports a deep-learning-ready corpus, which Python consumes for self-supervised learning and clustering. Because the entire pipeline is containerized and released under a permissive license, the full analysis — from raw binary data to trained embeddings — is reproducible on any hardware with the container image alone, which pins every package version and removes manual installation and dependency resolution. -The central objective of this paper is to show how this architecture scales with the two dimensions that dominate modern MSI data: file size and ion count. To evaluate the design honestly, we benchmark the Julia preprocessing stage against Cardinal 3.14.0 [@bemis_cardinal_2015], the standard R/Bioconductor MSI package, and MALDIquant [@gibb_maldiquant:_2012], a widely used R package for MALDI spectra processing, across seven public datasets spanning 0.07–4.4 GB from multiple ionization platforms (LD-LTP, AP-SMALDI, MALDI, DESI) and biological matrices, in both centroid and profile acquisition modes. All three tools run the identical per-stage workload (load, average spectrum, peak detection, ion extraction) on the same hardware, and we report memory and wall-clock transparently, including where the R-based tools are superior. We then describe the algorithmic core of the deep learning stage in detail — the contrastive (SimCLR) objective, the Group-Normalized fully convolutional encoder, gradient accumulation for consumer GPUs, chemical-noise augmentation, and spherical K-Means — and explain how these choices keep a big-data representation-learning workload tractable in RAM and on consumer hardware. As a demonstration of the workflow's biological utility, we apply it to a leaf and root of *Datura innoxia*, a medicinal plant rich in tropane alkaloids [@schlesinger_tropane_2021], and interpret the recovered metabolic domains in terms of alkaloid biosynthesis and transport [@ziegler_alkaloid_2008; @garcia-rojas_identification_2024]. The remainder of this paper details the acquisition parameters, the hybrid implementation, the multi-dataset benchmark, the deep learning workflow, and the unsupervised segmentation of the demonstration datasets. +The central objective of this paper is to show how this architecture scales with the two dimensions that dominate modern MSI data: file size and ion count. To evaluate the design honestly, we benchmark the Julia preprocessing stage against Cardinal 3.14.0 [@bemis_cardinal_2015], the standard R/Bioconductor MSI package, and MALDIquant [@gibb_maldiquant:_2012], a widely used R package for MALDI spectra processing, across seven public datasets spanning 0.61–4.4 GB from multiple ionization platforms (LD-LTP, AP-SMALDI, MALDI, DESI) and biological matrices, in both centroid and profile acquisition modes. All three tools run the identical per-stage workload (load, average spectrum, peak detection, ion extraction) on the same hardware, and we report memory and wall-clock transparently, including where the R-based tools are superior. We then describe the algorithmic core of the deep learning stage in detail — the contrastive (SimCLR) objective, the Group-Normalized fully convolutional encoder, gradient accumulation for consumer GPUs, chemical-noise augmentation, and spherical K-Means — and explain how these choices keep a big-data representation-learning workload tractable in RAM and on consumer hardware. As a demonstration of the workflow's biological utility, we apply it to a leaf and root of *Datura innoxia*, a medicinal plant rich in tropane alkaloids [@schlesinger_tropane_2021], and interpret the recovered metabolic domains in terms of alkaloid biosynthesis and transport [@ziegler_alkaloid_2008; @garcia-rojas_identification_2024]. The remainder of this paper details the acquisition parameters, the hybrid implementation, the multi-dataset benchmark, the deep learning workflow, and the unsupervised segmentation of the demonstration datasets. # Materials and Methods ## Multi-Dataset Benchmarking -To evaluate the scalability and robustness of the Julia-Python preprocessing pipeline, we assembled a diverse collection of seven publicly available MSI datasets covering a range of file sizes (0.07--4.4 GB), ionization sources, mass analyzers, and biological matrices (Table 1). The datasets comprise both centroid and profile acquisitions; all were processed using the same pipeline configuration described in the section "High-Performance Processing and Data Normalization (Julia)". ROI masks derived from the optical image were applied wherever a tissue reference was available — the *Datura* leaf and root, the human colon, and the three mouse tissues — restricting peak picking to pixels inside the tissue; only San Pedro, which lacks an optical reference and was processed without a mask, is an LD-LTP MSI dataset from *Echinopsis pachanoi* cactus stem cross-section (Moreno-Pedraza et al., 2019, Anal. Chem. 10.1021/acs.analchem.8b04406). Peaks were then filtered using the default intensity threshold of 2\% of the base peak. +To evaluate the scalability and robustness of the Julia-Python preprocessing pipeline, we assembled a diverse collection of seven publicly available MSI datasets covering a range of file sizes (0.61--4.4 GB), ionization sources, mass analyzers, and biological matrices (Table 1). The datasets comprise both centroid and profile acquisitions; all were processed using the same pipeline configuration described in the section "High-Performance Processing and Data Normalization (Julia)". ROI masks derived from the optical image were applied wherever a tissue reference was available — the *Datura* leaf and root, the human colon, and the three mouse tissues — restricting peak picking to pixels inside the tissue; only San Pedro, which lacks an optical reference and was processed without a mask, is an LD-LTP MSI dataset from *Echinopsis pachanoi* cactus stem cross-section (Moreno-Pedraza et al., 2019, Anal. Chem. 10.1021/acs.analchem.8b04406). Peaks were then filtered using the default intensity threshold of 2\% of the base peak. **Table 1.** Benchmark datasets used in this study. -| Dataset | Ionization | Mass Analyzer | Organism | File Size | Pixels | -|---------|------------|---------------|----------|-----------|--------| -| Datura Leaf | LD-LTP | Ion Trap | *D. innoxia* | 2.0 GB | 17,066 | -| Datura Root | LD-LTP | Ion Trap | *D. innoxia* | 2.5 GB | 21,060 | -| San Pedro | LD-LTP | Ion Trap | *E. pachanoi* | 1.1 GB | 19,600 | -| Mouse bladder | AP-SMALDI | Orbitrap | *M. musculus* | 778 MB | 34,840 | -| Human colon | DESI | Orbitrap | *H. sapiens* | 69 MB | 20,022 | -| Mouse liver | MALDI | TOF | *M. musculus* | 2.2 GB | 28,587 | -| Mouse stomach | MALDI | TOF | *M. musculus* | 4.4 GB | 54,245 | +| Dataset | Ionization | Mass Analyzer | Organism | File Size | Pixels | Polarity | Spatial Res. (µm) | Spectrum Type | +|---------|------------|---------------|----------|-----------|--------|----------|-------------------|---------------| +| Datura Leaf | LD-LTP | Ion Trap | *D. innoxia* | 2.0 GB | 17,066 | Positive | 100 | Profile | +| Datura Root | LD-LTP | Ion Trap | *D. innoxia* | 2.5 GB | 21,060 | Positive | 100 | Profile | +| San Pedro | LD-LTP | Ion Trap | *E. pachanoi* | 1.1 GB | 19,600 | Positive | ~100 | Profile | +| Mouse bladder | AP-SMALDI | Orbitrap | *M. musculus* | 833 MB | 34,860 | Positive | 10 | Centroid | +| Human colon | DESI | Orbitrap | *H. sapiens* | 610 MB | 4,288 | Negative | 100 | Centroid | +| Mouse liver | MALDI (neoFlex) | TOF | *M. musculus* | 2.2 GB | 28,587 | Positive | 20 | Profile | +| Mouse stomach | MALDI (neoFlex) | TOF | *M. musculus* | 4.4 GB | 54,245 | Positive | 20 | Profile | ## Computational Environment and Reproducibility @@ -132,7 +132,7 @@ The parameters used on the neoFlex for data acquisition were as follows: ## Computational Benchmark: Julia vs Cardinal and MALDIquant Across Seven Datasets -The controlled three-way benchmark (Figure 1) evaluates the identical preprocessing workload — imzML load plus one in-memory ion slice at each dataset's canonical reference *m/z* (see the section "Multi-Dataset Benchmark: Julia-Python vs Cardinal (R) and MALDIquant (R)", tolerance 0.1 Da) — on seven datasets spanning two orders of magnitude in file size (0.07--4.4 GB). Load memory (VmRSS delta) and wall-clock time were measured on the same hardware (Intel i5-9400F, 22 GB RAM). The results establish three findings, all consistent across every dataset in the benchmark figures, which show the Julia engine ahead in both memory and ion-slice throughput on all seven samples. +The controlled three-way benchmark (Figure 1) evaluates the identical preprocessing workload — imzML load plus one in-memory ion slice at each dataset's canonical reference *m/z* (see the section "Multi-Dataset Benchmark: Julia-Python vs Cardinal (R) and MALDIquant (R)", tolerance 0.1 Da) — on seven datasets spanning an order of magnitude in file size (0.61--4.4 GB). Load memory (VmRSS delta) and wall-clock time were measured on the same hardware (Intel i5-9400F, 22 GB RAM). The results establish three findings, all consistent across every dataset in the benchmark figures, which show the Julia engine ahead in both memory and ion-slice throughput on all seven samples. First, the Julia ion-slice operation is one to two orders of magnitude faster than Cardinal on every dataset (0.00009--0.32 s vs 6.3--19.5 s) and materially faster than MALDIquant (1.3--3.9 s) — 54- to 79,949-fold faster than Cardinal depending on the dataset (Figure 1A). This is the dominant per-ion cost when exporting a full ion corpus, and therefore the step that decides whether processing a full MSI dataset is feasible in reasonable wall-clock time: at Cardinal's per-slice cost, exporting the 1,596-ion *Datura* leaf corpus would take hours, whereas the Julia engine completes the export in minutes within a single pass. @@ -144,7 +144,7 @@ Third, the differentiation is not universal raw wall-clock speed — Cardinal's Because the deep learning stage is a core contribution of this workflow, we report its behavior across all seven benchmark datasets rather than on a single tissue. For each dataset, Stage 3 (see the section "Complete Hybrid Pipeline: From imzML to Metabolic Domains") evaluated the learned latent space with a K-sweep (k = 2--20) and three internal metrics — Silhouette, Davies-Bouldin, and Calinski-Harabasz (Figure 2 shows the sweeps for the two *Datura* demonstration datasets). The optimal K is a property of each tissue's architecture and varies strongly across datasets: the two-zone tissues (San Pedro stem, *Datura* root) converge at low k (k = 2 and k = 3, with all three metrics in agreement), whereas the histologically complex tissues saturate at the upper bound of the sweep (human colon at k = 20, mouse bladder at k = 19--20), and the *Datura* leaf and the two mouse tissues fall between (k = 5 and k = 7--12 by the Davies-Bouldin/Calinski-Harabasz optima). The multi-metric sweep is therefore not cosmetic: it is required to scale the workflow to arbitrary tissues without manual tuning, and the pipeline adopts the joint Davies-Bouldin/Calinski-Harabasz optimum as the metabolic cluster count, since the Silhouette optimum of k = 2 merely reproduces the trivial tissue-versus-background split. -The learned embeddings systematically outperform a PCA baseline on the same features (see the section "Self-Supervised Representation Learning (Python)") for every dataset, and cluster assignments are stable across random seeds (Adjusted Rand Index $\geq 0.9$). Isotope co-localization validation — a natural ground truth requiring no annotation — is positive across datasets and reaches high significance where the ion corpus is large enough to support the statistical test (Welch's t-test, $p < 10^{-6}$ for the human colon, $p < 10^{-300}$ for the *Datura* leaf). These results show that the deep learning stage scales from the smallest (69 MB, 682 ions) to the largest (4.4 GB) datasets in the benchmark without parameter changes, and that the file-based Julia-to-Python handoff keeps the whole analysis reproducible in a single container. +The learned embeddings systematically outperform a PCA baseline on the same features (see the section "Self-Supervised Representation Learning (Python)") for every dataset, and cluster assignments are stable across random seeds (Adjusted Rand Index $\geq 0.9$). Isotope co-localization validation — a natural ground truth requiring no annotation — is positive across datasets and reaches high significance where the ion corpus is large enough to support the statistical test (Welch's t-test, $p < 10^{-6}$ for the human colon, $p < 10^{-300}$ for the *Datura* leaf). These results show that the deep learning stage scales from the smallest (610 MB, 682 ions) to the largest (4.4 GB) datasets in the benchmark without parameter changes, and that the file-based Julia-to-Python handoff keeps the whole analysis reproducible in a single container. **Figure 1.** Equalized three-way benchmark of JuliaMSI vs Cardinal (R) and MALDIquant (R) preprocessing under an identical per-stage workload (load + average spectrum + peaks + one ion slice at each dataset's canonical reference *m/z*, tolerance 0.1 Da) across seven public datasets ordered by file size (lightest to heaviest). (A) Slice-generation throughput (slices per second, log scale): the Julia engine generates ion slices one to two orders of magnitude faster than Cardinal on every dataset (54- to 79,949-fold) and materially faster than MALDIquant, a difference that dominates the cost of exporting a full ion corpus. (B) Peak load resident RAM (VmRSS, MB, log scale): the memory-mapped lazy loader keeps the working set at 7--84 MB — below Cardinal's ~120 MB on every dataset and far below MALDIquant (up to 4.0 GB). Red X markers indicate the datasets that MALDIquant could not process (mouse liver and mouse stomach), which exhausted the 22 GB reference machine. @@ -195,7 +195,7 @@ This work was supported by the University of Virginia's School of Medicine grant # Conclusion -The equalized benchmark against Cardinal (R/Bioconductor) and MALDIquant (R) — identical per-stage workloads on the same hardware across seven public datasets spanning 0.07 to 4.4 GB — shows that the Julia engine generates ion slices one to two orders of magnitude faster than Cardinal on every dataset (0.00009--0.32 s vs 6.3--19.5 s, 54- to 79,949-fold) while keeping peak load resident memory (VmRSS) at 7--84 MB, lower than Cardinal's ~120 MB and far below MALDIquant's up to 4.0 GB, and it completes the additional normalization and export steps within the same memory envelope. We report the per-stage timings transparently, including where the R ecosystem is competitive (Cardinal's eager load is faster in wall time on the larger files), and we note that MALDIquant exhausted the reference machine on the two heaviest datasets. This decoupling of peak RAM from on-disk file size is what makes the workflow scale from commodity laptops to GPU-equipped workstations, and the containerized environment and permissive open-source license allow any researcher to rebuild the entire analysis — from raw imzML to trained embeddings and final segmentation — on any hardware. +The equalized benchmark against Cardinal (R/Bioconductor) and MALDIquant (R) — identical per-stage workloads on the same hardware across seven public datasets spanning 0.61 to 4.4 GB — shows that the Julia engine generates ion slices one to two orders of magnitude faster than Cardinal on every dataset (0.00009--0.32 s vs 6.3--19.5 s, 54- to 79,949-fold) while keeping peak load resident memory (VmRSS) at 7--84 MB, lower than Cardinal's ~120 MB and far below MALDIquant's up to 4.0 GB, and it completes the additional normalization and export steps within the same memory envelope. We report the per-stage timings transparently, including where the R ecosystem is competitive (Cardinal's eager load is faster in wall time on the larger files), and we note that MALDIquant exhausted the reference machine on the two heaviest datasets. This decoupling of peak RAM from on-disk file size is what makes the workflow scale from commodity laptops to GPU-equipped workstations, and the containerized environment and permissive open-source license allow any researcher to rebuild the entire analysis — from raw imzML to trained embeddings and final segmentation — on any hardware. On the deep learning side, we have shown how the Python stage is engineered for big, zero-padded MSI data: Group Normalization to neutralize the background mask, gradient accumulation to fit large effective batches on consumer GPUs, chemical-noise-only augmentation to preserve the spatial co-localization signal, and spherical K-Means to respect the latent hypersphere geometry. Applied across all seven benchmark datasets, the workflow selects its own number of metabolic domains per tissue, systematically outperforms a PCA baseline, and produces stable, biologically coherent segmentations. As a demonstration of biological utility, application to *Datura innoxia* recovered five spatially coherent metabolic domains in the leaf and three in the root, resolving the spatial organization of tropane alkaloid metabolism without manual annotation: the leaf co-localizes the full scopolamine envelope with atropine/hyoscyamine and 6-hydroxyhyoscyamine in a single transport domain, with the precursors tropinone, tropine, and cuscohygrine compartmentalized in three separate domains. Together, the computational benchmark, the algorithmic treatment of the deep learning stage, and the containerized reproducibility establish the workflow as a scalable, democratized foundation for MSI analysis — lowering the memory and setup barriers that currently gate the analysis of next-generation imaging datasets.