A comprehensive pipeline for processing and deconvolving MALDI imaging mass spectrometry data using Richardson-Lucy deconvolution with realistic PSF modeling.
This project requires uv
Details
macOS & Linux:
curl -LsSf https://astral.sh/uv/install.sh | shWindows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"For more installation options, see the official uv docs.
git clone https://github.com/MMV-Lab/maldi-deconvolution.git
cd maldi-deconvolutionThis project is powered by marimo (interactive Python notebooks that run as apps) and managed with uv for dependency resolution.
Run the notebooks (end users):
uv run marimo run ./notebooksOpen notebooks in edit mode (developers):
uv run marimo edituv will automatically resolve and install all dependencies from pyproject.toml and uv.lock on first run.
The pipeline is split into the following sequential notebooks:
Load one or more .imzML files and extract ion images for selected m/z values (single or batch via CSV). Scans the full dataset to determine m/z ranges and pixel sizes, then exports a structured .h5 (NetCDF) file ready for deconvolution or visualization.
Tracks signal intensity across multiple repeated laser passes on the same tissue section. Auto-detects the top spectral peaks, builds a xarray 4D data cube (pass × m/z × y × x).Exports a Decay_Profile.csv to be used in the deconvolution step.
The core processing step. Given instrument parameters (laser diameter, step size, decay profile), it simulates a realistic PSF and applies Richardson-Lucy deconvolution to the ion image stack. Outputs a multi-iteration deconvolved .h5 file, each iteration slice can be inspected independently.
Browse deconvolved or original .h5 files interactively. Adjust m/z, iteration, colormap, and contrast in real time. Export individual ion images as high-resolution SVG/PNG or dump the full datacube as calibrated TIFFs (with embedded resolution metadata for ImageJ/Fiji).
✨ Realistic PSF Simulation (src/psf_generator.py)
The PSF is simulated on a fine grid (0.05 µm resolution) and then integrated down to the coarse pixel grid. Two beam models are supported:
| Model | Description |
|---|---|
beam_profile |
Continuous Gaussian beam ( |
geometric |
Binary circular aperture. Counts discrete shot overlaps. Faster, useful as a baseline. |
Signal degradation from repeated laser exposure is modeled via the decay profile, with two strategies:
| Decay Model | Description |
|---|---|
exponential |
Fits |
interpolation |
Linear interpolation between measured points. No assumptions on decay shape. |
⚡ Efficient Processing
- Dask-parallelized Richardson-Lucy deconvolution
- Batch processing of full ion image stacks
- Minimal memory footprint for large datasets
📊 Data Structure & Interoperability
- xarray for labeled N-dimensional data (preserves metadata, coordinates, dimensions)
- Seamless integration with scientific Python ecosystem
- NetCDF (
.h5) format for portability and reproducibility
📈 Interactive Visualization
- HoloViews for rapid, responsive real-time previews in notebooks
- Hover tooltips, zoom, pan for exploratory analysis
- Dual backends (Matplotlib + Bokeh)
🎨 Publication-Ready Output
- High-resolution plots (SVG/PNG)
- Palette-mapped TIFF export compatible with ImageJ/Fiji
- Batch export of full datasets with embedded resolution metadata
- Adjust PSF parameters (laser diameter, step size) to match your instrument specs
- The decay profile CSV can be produced by
nb_extract_decay_profile.pyor provided manually (1 or 2 columns, with or without header) - Inspect each deconvolution iteration in
nb_visualize.pyto choose the optimal stopping point - Use
beam_profile+exponentialfor the most physically accurate results
├── notebooks/ # 📓 Interactive marimo notebooks
│ ├── nb_extract_data.py
│ ├── nb_extract_decay_profile.py
│ ├── nb_deconvolve.py
│ ├── nb_visualize.py
│ ├── nb_beamprofile.py
│ ├── nb_registration.py
│ ├── nb_metrics.py
│ └── nb_figures.py
├── src/
│ ├── psf_generator.py # 🔧 PSF simulation engine
│ ├── plotting.py # 📈 Shared interactive (HoloViews/hvplot) plotting helpers
│ └── visualization.py # 🖼️ Static export & colormap helpers
├── data/ # 📂 Input datasets
├── pyproject.toml # 📦 Project dependencies
├── uv.lock # 🔒 Locked dependency versions
└── README.md # 📖 This file
TBD
Contributions welcome! Feel free to open issues or PRs.
uv run notebooks/nb_extract_data.py -- --input PATH [--mz VALUE | --mz-csv PATH] [--tolerance VALUE]| Argument | Required | Description |
|---|---|---|
--input PATH |
yes | Path to the .imzml file to process |
--mz VALUE |
no* | Single m/z value to extract |
--mz-csv PATH |
no* | Path to a CSV with m/z values (no header, one value per line) |
--tolerance VALUE |
no | m/z tolerance in Da (default: 0.005) |
* If neither --mz nor --mz-csv is provided, the midpoint of the m/z range is used.
Happy deconvolving! 🔬✨