# Deep Learning in Mass Spectrometry Imaging: A Hybrid Julia-Python Workflow This repository contains the computational pipeline for the automated anatomical mapping of *Datura innoxia* (toloache) using Mass Spectrometry Imaging (MSI). The workflow addresses the "two-language problem" by leveraging **Julia** for high-performance data preprocessing and **Python** for self-supervised representation learning. ## Key Features - **High-Performance Preprocessing**: Rapid `.imzML` ingestion and TrIQ normalization using Julia. - **Self-Supervised Learning**: Contrastive learning (SimCLR) with an EfficientNet-B0 backbone implemented in PyTorch. - **Empirical Clustering**: Automated anatomical segmentation using PCA and K-Means, optimized for vascular and parenchymal tissue differentiation. - **CPU Optimized**: Designed to run on standard consumer hardware (no GPU required for inference). ## Project Structure - `scripts_julia/`: Julia scripts for mass slice extraction, TrIQ normalization, and image generation. - `scripts_python/`: Python scripts for SimCLR training, feature extraction, and clustering. - `Model/`: Contains the pre-trained weights (`msi_encoder_trained.pth`). - `environment/`: Dependency list (`requirements.txt`). - `Articule MSI/`: Manuscript draft and documentation. ## Installation ### Python It is recommended to use a virtual environment: ```bash pip install -r environment/requirements.txt ``` ### Julia Ensure you have Julia installed and the following packages: `MSI.jl`, `ImzML.jl`, `Images.jl`, and `DataFrames.jl`. ## Usage Workflow 1. **Preprocessing (Julia)**: Run `scripts_julia/preparar_datos_simclr.jl` to convert `.imzML` data into normalized PNG ion maps. 2. **Training (Optional)**: Run `scripts_python/CNN_proof_1.py` to retrain the SimCLR encoder. 3. **Clustering & Mapping**: Use `scripts_python/cluster_msi_direct.py` to extract embeddings from the pre-trained model and generate the metabolic clusters. 4. **Visualization**: Run `scripts_python/visualizar_clusters.py` to generate the final cluster galleries. ## Citation & Acknowledgments This implementation is based on the methodology proposed by: > 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. DOI: [10.1039/d1sc04077d](https://doi.org/10.1039/d1sc04077d) ## License This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.