first commit, migrated repository to contain the scripts only

This commit is contained in:
Pixelguy14
2026-10-14 18:15:57 -06:00
parent bab8f4d2a9
commit 6ea14dfb61
54 changed files with 155 additions and 63664 deletions
+42 -58
View File
@@ -6,21 +6,15 @@ normalization, and per-ion PNG export in a single pass; a **Python SimCLR** enco
learns a 128-dimensional latent space from the exported ion corpus and clusters the ions
into spatially coherent metabolic domains.
This repository accompanies the manuscript *"A scalable deep learning workflow for mass
spectrometry imaging"* (`MSI_julia-python_mapping.md`). It is self-contained: it ships the
manuscript and figures, the pinned environments, the full seven-stage pipeline, and a
**vendored copy of the JuliaMSI engine** (`src/`, MIT) so no external Julia project is
required. Raw MSI datasets are supplied by the user (see [Datasets](#datasets)).
This repository is self-contained: it ships the pinned environments, the full seven-stage
pipeline, and a **vendored copy of the JuliaMSI engine** (`src/`, MIT). Raw MSI datasets
are supplied by the user (see [Datasets](#datasets)).
## Repository layout
```
.
├── README.md
├── MSI_julia-python_mapping.md # manuscript (pandoc/biblatex, references zotero.bib)
├── zotero.bib # manuscript bibliography
├── documentation.md # technical rationale, hyperparameters, validation
├── figure1.png figure2.png figure3.png figure4.png
├── Dockerfile # GPU image (CUDA 12.4 + Julia + Python/SimCLR)
├── Dockerfile.cpu # CPU image (Ubuntu 22.04 + Julia + Python/SimCLR)
├── docker-compose.yml # msi-pipeline-gpu / msi-pipeline-cpu services
@@ -45,9 +39,9 @@ required. Raw MSI datasets are supplied by the user (see [Datasets](#datasets)).
│ ├── visualize_clusters.py # Stage 6: per-cluster galleries
│ ├── plot_mass_spectra_python.py # Stage 7 Python fallback
│ ├── msi_preprocess_python.py # Stage 1 Python fallback (vendor imzML)
│ ├── make_ion_carpet.py # standalone ion-carpet mosaics (manuscript figures)
│ └── build_manuscript_figures.py # composite figure panels
├── datos_para_ai/ # user-provided datasets (git-ignored)
│ ├── make_ion_carpet.py # standalone ion-carpet mosaics (figure panels)
│ └── build_figure_panels.py # composite figure panels
├── ai_data/ # user-provided datasets (git-ignored)
└── outputs/ # generated (git-ignored): ion images, models, figures
```
@@ -71,10 +65,10 @@ required. Raw MSI datasets are supplied by the user (see [Datasets](#datasets)).
make build
# 2) put each dataset in its own folder, e.g.
# datos_para_ai/Datura_leaf/<name>.imzML (+ <name>.ibd, optional ROI .png)
# ai_data/Datura_leaf/<name>.imzML (+ <name>.ibd, optional ROI .png)
# 3) run — works on CPU out of the box (torch falls back when there is no GPU)
make run # every dataset under datos_para_ai/
make run # every dataset under ai_data/
make run-dataset D=Datura_leaf # a single dataset
# with an NVIDIA GPU (needs the Container Toolkit / a CDI spec — see Troubleshooting):
@@ -89,13 +83,13 @@ docker build -t msi-pipeline-gpu .
# CPU (no GPU flags):
docker run --rm --shm-size=2g -it \
-v "$PWD/datos_para_ai:/app/datos_para_ai" \
-v "$PWD/ai_data:/app/ai_data" \
-v "$PWD/outputs:/app/outputs" \
msi-pipeline-gpu bash
# add `--gpus all` (Docker) or `--device nvidia.com/gpu=all` (Podman + CDI) for a GPU.
# then, inside the container:
bash run_full_pipeline.sh # all datasets under datos_para_ai/
bash run_full_pipeline.sh # all datasets under ai_data/
bash run_full_pipeline.sh Datura_leaf # a single dataset
```
@@ -123,13 +117,13 @@ Requires **Julia 1.11.x** (matching `environment/Manifest.toml`) and **Python 3.
`run_full_pipeline.sh` chains the stages below. To re-run a single one (native form):
```bash
julia --threads auto --project=environment scripts_julia/julia_msi_bridge.jl datos_para_ai/<ds> <ds>
julia --threads auto --project=environment scripts_julia/julia_msi_bridge.jl ai_data/<ds> <ds>
python scripts_python/CNN_proof_1.py <ds>
python scripts_python/evaluate_clustering.py <ds> # writes outputs/<ds>/best_k_results.csv
python scripts_python/graph_tsne_msi.py <ds> <K>
python scripts_python/quantitative_validation.py <ds> <K>
python scripts_python/visualize_clusters.py <ds>
julia --project=environment scripts_julia/plot_mass_spectra.jl <ds> datos_para_ai/<ds>
julia --project=environment scripts_julia/plot_mass_spectra.jl <ds> ai_data/<ds>
```
Docker equivalents: `make step1 D=<ds>` … `make step7 D=<ds>`, with
@@ -139,15 +133,15 @@ count `K`; Stage 3 prints and stores the best value (Silhouette optimum by defau
## Datasets
The pipeline reads **any valid imzML** (profile or centroid) — it is **not** restricted to
the manuscript datasets.
a fixed set of datasets.
**Each dataset must live in its own subfolder of `datos_para_ai/`.** The folder name *is*
**Each dataset must live in its own subfolder of `ai_data/`.** The folder name *is*
the dataset name, and it becomes the `outputs/<name>/` directory. Files placed directly in
`datos_para_ai/` — **not inside a subfolder — are ignored** by `run_full_pipeline.sh`, so a
`ai_data/` — **not inside a subfolder — are ignored** by `run_full_pipeline.sh`, so a
dataset dropped loose at the root will not be detected.
```
datos_para_ai/
ai_data/
├── Mouse_bladder/ # folder name = dataset name
│ ├── HR2MSImouseurinarybladderS096.imzML # exactly one .imzML
│ ├── HR2MSImouseurinarybladderS096.ibd # its sibling .ibd (matching basename)
@@ -168,17 +162,6 @@ Rules for each dataset folder:
`region` (case-insensitive) — e.g. `region.png`, `MyData_mask.png`. Masks are resized to the
dataset dimensions; without one the full image is used.
The seven manuscript datasets are all **public**: LD-LTP *Datura* leaf and root, MALDI San
Pedro cactus, MALDI mouse liver and stomach, AP-SMALDI mouse bladder, DESI human colon
(0.07–4.4 GB, centroid and profile). Access instructions: **TODO — add accession DOI/URL
per dataset**. Related dataset DOIs are listed in `DOIs.md` (e.g. San Pedro cactus
<https://doi.org/10.5281/zenodo.3625054>; general imzML test data
<https://doi.org/10.5281/zenodo.10084132>).
`models.zip` contains the trained SimCLR encoders for the seven manuscript datasets.
Unzip it into `outputs/` (`unzip models.zip -d outputs/`) to reuse
`outputs/models/<ds>/msi_encoder_trained.pth` and skip Stage 2 for those datasets.
## JuliaMSI engine (`src/`)
The Julia core used by Stages 1 and 7 is **vendored** into `src/` from the MIT-licensed
@@ -204,7 +187,7 @@ commit and re-run Stage 1. The MIT license of the vendored code is in `src/LICEN
| `MSI_PEAK_MIN_MZ_GAP` | `0` | minimum m/z separation between picked ions (0 disables) |
| `MSI_BIN_AVG` | unset | average-spectrum bin width in Da (needed for high-resolution ToF data) |
| `MSI_MEM_MAX` | unset | cgroup memory ceiling |
| `MSI_DATA_ROOT` | `datos_para_ai` | override the dataset root directory |
| `MSI_DATA_ROOT` | `ai_data` | override the dataset root directory |
| `MSI_K` | auto | force a cluster count instead of the Stage-3 Silhouette choice |
## Prerequisites
@@ -214,23 +197,6 @@ commit and re-run Stage 1. The MIT license of the vendored code is in `src/LICEN
- Optional: **Docker 24+** with NVIDIA Container Toolkit (GPU image) and Compose v2 (`make`).
- Disk: datasets are 0.07–4.4 GB; outputs/models add a few GB. RAM: ~8 GB+ for larger sets.
## Manuscript figures
The manuscript (`MSI_julia-python_mapping.md`, biblatex bibliography `zotero.bib`) is
accompanied by composite panels:
```
figure1.png # JuliaMSI vs Cardinal vs MALDIquant: throughput + RAM (Fig. benchmark)
figure2.png # K-sweep clustering validation for the Datura leaf + root datasets
figure3.png # t-SNE + biologically interpretable ion galleries
figure4.png # additional composite panel
```
They are assembled by `scripts_python/build_manuscript_figures.py` from per-dataset
outputs (`outputs/<ds>/msi_tsne_plot.png`,
`outputs/<ds>/figures/cluster_validation_detailed_plot.png`, `outputs/<ds>/galleries/`).
Re-run that script after any pipeline change to regenerate them.
## Troubleshooting
### `? Please select an image:` at `STEP 1/15` (Podman / Buildah)
@@ -301,13 +267,6 @@ podman builder prune -af
podman-compose build --no-cache msi-pipeline-gpu
```
Global reset (**careful — removes all unused images/cache, not just this project**):
```bash
docker system prune -a --volumes -f # Docker (same as `make clean-all`)
podman system prune -a --volumes -f # Podman
```
Notes:
- `docker builder prune -af` / `podman builder prune -af` affect this project's cache
safely; the `system prune -a` commands are host-wide.
@@ -348,6 +307,31 @@ spec. If you have no NVIDIA GPU, ignore `*-gpu` targets entirely — the CPU fal
**non-fatal**: GLMakie is a GUI-only dependency and the pipeline never loads it. The
images intentionally do not run an explicit `Pkg.precompile()`.
## Data availability
**TODO — add accession DOI/URL per dataset.**
The seven reference datasets are all **public**: LD-LTP *Datura* leaf and root, MALDI San
Pedro cactus, MALDI mouse liver and stomach, AP-SMALDI mouse bladder, DESI human colon
(0.07–4.4 GB, centroid and profile).
Related dataset DOIs:
- San Pedro Cactus: <https://doi.org/10.5281/zenodo.3625054>
- Human Colon & Mouse Bladder: <https://doi.org/10.5281/zenodo.10084132>
- Datura Leaf & Datura Root: pending.
- Mouse Stomach & Mouse Liver: pending.
## Trained models
`models.zip` (pending link) contains the trained SimCLR encoders for the seven reference
datasets. Unzip it into `outputs/` (`unzip models.zip -d outputs/`) to reuse
`outputs/models/<ds>/msi_encoder_trained.pth` and skip Stage 2 for those datasets.
## License
MIT — see `LICENSE`. The vendored `src/` retains its own MIT license (`src/LICENSE`).
## Citation
Once the article/DOI is published...