evaluation of k=2 to k=20 for clustering justification and selection of k=10
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
.imzMLingestion 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:
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
-
Preprocessing (Julia): Run
scripts_julia/preparar_datos_simclr.jlto convert.imzMLdata into normalized PNG ion maps. -
Training (Optional): Run
scripts_python/CNN_proof_1.pyto retrain the SimCLR encoder. -
Clustering & Mapping: Use
scripts_python/cluster_msi_direct.pyto extract embeddings from the pre-trained model and generate the metabolic clusters. -
Visualization: Run
scripts_python/visualizar_clusters.pyto 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
License
This project is licensed under the MIT License - see the LICENSE file for details.