From 6af56b9f7effa3aa7477e5299b50756563b087a2 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 2 Sep 2026 22:44:42 +0200 Subject: [PATCH] Subir archivos a "/" --- MSI_julia-python_mapping.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MSI_julia-python_mapping.md b/MSI_julia-python_mapping.md index 185c5a4..f442bd6 100644 --- a/MSI_julia-python_mapping.md +++ b/MSI_julia-python_mapping.md @@ -3,7 +3,7 @@ title: "A scalable deep learning workflow for mass spectrometry imaging: benchma 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.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 +keywords: mass spectrometry imaging, Julia, Python, SimCLR, hybrid pipeline --- # Introduction @@ -24,9 +24,9 @@ To evaluate the scalability and robustness of the Julia-Python preprocessing pip | 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 | +| Datura Leaf | LD-LTP | Ion Trap (LCQ-Fleet) | *D. innoxia* | 2.0 GB | 17,066 | Positive | 100 | Profile | +| Datura Root | LD-LTP | Ion Trap (LCQ-Fleet) | *D. innoxia* | 2.5 GB | 21,060 | Positive | 100 | Profile | +| San Pedro | LD-LTP | Ion Trap (LCQ-Fleet) | *E. pachanoi* | 1.1 GB | 19,072 | Positive | 300 | 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 | @@ -54,7 +54,7 @@ Previous benchmarks support this choice: Julia-based MSI architectures have been ## Multi-Dataset Benchmark: Julia-Python vs Cardinal (R) and MALDIquant (R) -To contextualize the performance of our Julia-based preprocessing within the current MSI software landscape, we conducted a controlled, three-way benchmark against Cardinal 3.14.0, the standard R/Bioconductor package for MSI analysis [@bemis_cardinal_2015], and against MALDIquant [@gibb_maldiquant:_2012], the standard R package for MALDI spectral processing. All three tools processed the same seven datasets (Table 1) on identical hardware (Intel i5-9400F, 22 GB RAM, Ubuntu 24.04). We designed a strictly equalized per-stage workload restricted to the steps that all three tools perform: (1) imzML file loading, and (2) in-memory extraction of a single target ion image at each dataset's canonical reference *m/z* (a biologically informative ion per sample: 304.17 for the *Datura* leaf and root, 885.5 for the human colon, 716.05 for the mouse bladder, 796.18 for the mouse liver, 804.3 for the mouse stomach, and 500.0 for San Pedro (LD-LTP reference ion; mescaline observed at m/z ≈ 212.1 in the original study [@moreno-pedraza_elucidating_2019]); tolerance 0.1 Da), plus the average spectrum and peak detection used to select the slice. The Julia engine runs the JuliaMSI `MSI_src` implementation, whose memory-mapped (`Mmap`) lazy loader and buffer pooling read spectra on demand from the on-disk `.ibd` file; for Cardinal, which stores centroid-mode spectra per-pixel as a list, the average spectrum was computed by binning pixel-wise m/z values onto a common 0.01 Da grid and the target ion image was extracted with the native 3.x API (`bin()` + `sliceImage()`); for MALDIquant, spectra were read into `MassSpectrum` objects and processed with `reduceIntensity`/`detectPeaks`, and the ion image was recovered from the aligned spectrum objects. Load memory (VmRSS delta) and wall-clock time were measured per stage via `/proc/self/status`, with each tool run in isolation. This apples-to-apples design deliberately excludes Julia-only steps (TrIQ normalization and PNG export) so that the comparison reflects identical computational work. +To contextualize the performance of our Julia-based preprocessing within the current MSI software landscape, we conducted a controlled, three-way benchmark against Cardinal 3.14.0, the standard R/Bioconductor package for MSI analysis [@bemis_cardinal_2015], and against MALDIquant [@gibb_maldiquant:_2012], the standard R package for MALDI spectral processing. All three tools processed the same seven datasets (Table 1) on identical hardware (Intel i5-9400F, 22 GB RAM, Ubuntu 24.04). We designed a strictly equalized per-stage workload restricted to the steps that all three tools perform: (1) imzML file loading, and (2) in-memory extraction of a single target ion image at each dataset's canonical reference *m/z* (a biologically informative ion per sample: 304.17 for the *Datura* leaf and root, 885.5 for the human colon, 716.05 for the mouse bladder, 796.18 for the mouse liver, 804.3 for the mouse stomach, and 212.14 for San Pedro (mescaline [M+H]⁺, LD-LTP reference ion [@moreno-pedraza_elucidating_2019]); tolerance 0.1 Da), plus the average spectrum and peak detection used to select the slice. The Julia engine runs the JuliaMSI `MSI_src` implementation, whose memory-mapped (`Mmap`) lazy loader and buffer pooling read spectra on demand from the on-disk `.ibd` file; for Cardinal, which stores centroid-mode spectra per-pixel as a list, the average spectrum was computed by binning pixel-wise m/z values onto a common 0.01 Da grid and the target ion image was extracted with the native 3.x API (`bin()` + `sliceImage()`); for MALDIquant, spectra were read into `MassSpectrum` objects and processed with `reduceIntensity`/`detectPeaks`, and the ion image was recovered from the aligned spectrum objects. Load memory (VmRSS delta) and wall-clock time were measured per stage via `/proc/self/status`, with each tool run in isolation. This apples-to-apples design deliberately excludes Julia-only steps (TrIQ normalization and PNG export) so that the comparison reflects identical computational work. ## Complete Hybrid Pipeline: From imzML to Metabolic Domains @@ -110,6 +110,10 @@ We implemented a Contrastive Learning (SimCLR) scheme in PyTorch [@paszke_pytorc To demonstrate the biological utility of the workflow, we acquired an MSI dataset from a *Datura innoxia* leaf, a medicinal plant whose root-biosynthesized tropane alkaloids are transported to the shoot [@schlesinger_tropane_2021], and whose imaging has previously been pursued with laser desorption low-temperature plasma (LD-LTP) techniques [@moreno-pedraza_elucidating_2019]. 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_low-temperature_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 [@martinez-jarquin_low-temperature_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 sample. +## Benchmark Dataset: LD-LTP-MSI of San Pedro Cactus (*Echinopsis pachanoi*) + +The San Pedro cactus (1.1 GB) dataset was acquired using the same LD-LTP-MSI platform described in Moreno-Pedraza et al. [@moreno-pedraza_elucidating_2019] at CINVESTAV Irapuato. A cactus cross-section (41.70 × 42.00 mm², 2.5 cm thick) was dissected with a scalpel, cleaned with a paper towel, and a wet filter paper was placed underneath to avoid dehydration during analysis. The LD-LTP system used a CW 405 nm UV diode laser (Fermion III Series, Micro Laser Systems Inc., up to 450 mW output) with a plano-convex lens (f = 50 mm) focused perpendicular to the sample, and a 3D-printed LTP probe operated at 0.1 L/min helium, 7 kV, 10 kHz, positioned at 45° and 2 mm from the MS inlet. An LCQ-Fleet ion trap MS (Thermo Scientific) was used in positive mode, *m/z* 50–500, full scan continuous mode (capillary voltage 55 V, capillary temperature 200 °C, tube lens 25 V, max injection time 300 ms, 2 microscans, AGC enabled). Imaging was performed with a RepRap-based stage in a meandering pattern at 300 × 300 µm step width (pixel size), acquiring 19,072 pixels over 164 min. Laser intensity was set to 317.86 MW cm⁻². Mescaline was detected at *m/z* 212.14 [M+H]⁺ and confirmed by MS² fragmentation and GC/EIMS of dissected chlorenchyma/parenchyma. + ## Benchmark Datasets: MALDI-TOF MSI of Mouse Liver and Stomach on Bruker neoFlex The mouse liver (2.2 GB) and mouse stomach (4.4 GB) datasets were acquired on a Bruker neoFlex MALDI-TOF mass spectrometer (Bruker Daltonics) at the Biomolecular Analysis Facility Core, W.M. Keck Biomedical Mass Spectrometry Laboratory, University of Virginia School of Medicine. Liver and stomach tissues were obtained from mice and, after being washed with 1× PBS, were embedded in a mold with 20% fish gelatin and frozen on dry ice. They were subsequently transferred to −20 °C for one hour and stored at −80 °C until use. Sectioning was performed on a microtome cryostat equipped with a blade holder (Epredia CryoStar NX50 OP 957250), and the sections were carefully mounted using a fine paintbrush to pull the tissues onto an Intelligent Slide previously cooled to −15 °C.