Skip to main content

pelmesha

Peak Extraction Library for Mass spectrometry Enhanced by Statistical High-throughput Analysis

pelmesha is a Python package for processing Mass Spectrometry Imaging (MSI) data stored in .imzml (and, experimentally, .cdf) files. It loads raw spectra, processes them, detects peaks, corrects their m/z values with a kernel density estimate (KDE), and aggregates multiple samples/ROIs into a unified feature matrix.

Features

  • Loading & metadata extraction — reads raw MSI data and builds a structured metadata HDF5 file (*_ingredients.hdf5) containing sample metadata, per-ROI index ranges, m/z ranges, and spatial coordinates.
  • Configuration-driven processing pipeline — a configuration system (Configs, PipelineConfigurator, PreparedDataSource) that validates parameters, distributes them to the pipeline steps, and supports YAML serialisation. The lightweight KDEConfigs class is built on Pydantic.
  • Spectrum processing — smoothing, baseline correction, resampling to a uniform m/z scale, and alignment against reference peaks using a slightly modified version of the msalign implementation.
  • Peak picking — detection of peaks together with their area, FWHM points, peak-base boundaries, and signal-to-noise ratio.
  • KDE-based m/z correction — peaks that wander slightly across spectra are grouped into single m/z values based on their kernel density estimate (using KDEpy).
  • Multi-sample aggregation — builds a feature matrix from the peak lists of several samples and ROIs, with optional occurrence filtering, duplicate merging, pivoting, and coordinate merging.
  • Reference peaks — generates a reference peak list from a reference source and uses it to align the other samples registered in the same DataSet.

Installation

pip install pelmesha

Requires Python >= 3.10. The main dependencies are numpy, pandas, scipy, h5py, pyimzml, pybaselines, KDEpy, scikit-learn, xarray, pydantic, pyyaml, and pyarrow.

Quick start

1. Load data sources

Create a DataSet from a list of raw files (or directories):

from pelmesha import DataSet

ds = DataSet(sources=["/data/sample1.imzml", "/data/sample2.imzml"])

Each source is wrapped in a PreparedDataSource and registered by its sample name:

print(ds)                 # text table of the registered sources
ds["sample1"]             # access a prepared source by sample name

2. Configure the processing pipeline

Per-source processing and KDE configurations can be adjusted either for all ROIs at once or for a single ROI:

# Update a parameter for all ROIs of one sample
ds["sample1"].update({"smooth_window": 7})
ds["sample1"].update_kde(bwc=1.5)

# Or configure a specific ROI directly
roi_config = ds["sample1"].roi_configs["R00"]
roi_config["SNR_threshold"] = 4
roi_config["smooth_algo"] = "GA"

kde_config = ds["sample1"].roi_kde_configs["R00"]
kde_config["bwc"] = 1.5

# Exclude specific methods from the pipeline by deleting them from the config
# This disables baseline correction for this RO
roi_config.delete('Baseline') # Baseline correction will be not implemented

# Change the algorithm or method using set_method
# This replaces the method with 'modpoly' and updates default parameters
roi_config.set_method('Baseline','modpoly') 

Configurations are stored next to each source file and can be saved/loaded as YAML (*_processing_recipe.yaml and *_kde_recipe.yaml).

3. Process spectra and pick peaks

ds.process()    # smoothing → baseline → resampling → alignment
ds.peakpick()   # smoothing → baseline → resampling → alignment and detect peaks for every spectrum

These write *_processed_spectra.hdf5 and *_peaklists.hdf5 next to each source.

4. Estimate peak density

ds.estimate_peak_density_kde()

This writes the per-ROI peak probability density into *_peaks_density.hdf5.

5. Build a feature matrix

fm = ds.feature_matrix(countf=10, pivot_values="Intensity")

Optionally save it as Parquet together with the coordinates:

fm = ds.feature_matrix(save_path="results/feature_matrix.parquet",
                       merge_with_coords=True)

6. Use reference peaks for alignment (optional)

Reference peaks are optional. If you want cross-sample alignment, generate the reference peak list before running process / peakpick on the other samples:

ds.set_reference_source("/data/reference.imzml")
ds.get_reference_peaks()
ds.set_align_peaks_from_ref()

set_align_peaks_from_ref then assigns the reference peaks to the selected samples/ROIs of the DataSet as their alignment targets.

Pipeline steps

The per-spectrum processing pipeline consists of the following steps:

  1. Smoothing — moving-average (MA), Gaussian (GA), or Savitzky–Golay (SG) filters.
  2. Baseline correction — using the pybaselines library.
  3. Resampling — brings the data onto a uniform m/z scale (resample_mz_scale).
  4. Alignment — calibration and alignment relative to reference peaks using the bundled, slightly modified msalign implementation in Aligner.

After peak picking, the probability density function (PDF) of the peaks is built and saved for every individual ROI, using the parameters specified for that ROI. Once both peak picking and the PDF estimation are complete, the resulting files are ready to be combined into a single dataset and to form a common feature matrix across all the samples and ROIs.

Project structure

Module Purpose
filling DataSource, DataManager, and format-specific loaders (imzML, CDF).
dough Utility classes: LinkedList, AdaptiveParameter, Indexator, SliceIndexator.
cookbook Configuration system: Configs, PipelineConfigurator, PreparedDataSource, KDEConfigs.
kneading Base pipeline functions: processing, smoothing, peak picking, KDE estimation, msalign.
serving Orchestration and visualisation: DataSet, Pipeline, Drawer.
align The Aligner class implementing signal calibration/alignment.
utensils Assorted helper functions and constants.

License

Distributed under the Apache-2.0 license. See LICENSE.txt.

Release files for pelmesha 0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelmesha 0.7.3
File Size Uploaded
pelmesha-0.7.3.tar.gz 417.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelmesha 0.7.3
File Interpreter ABI Platform
pelmesha-0.7.3-py3-none-any.whl Python 3 none any Details

Total release size: 551.8 kB

Release files / pelmesha-0.7.3.tar.gz

Download URL pelmesha-0.7.3.tar.gz
Size 417.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a1c89f795e13daaa8fae986ac3d00d2136533e86199176d6577bf946e1e55fe8
BLAKE2b-256 checksum
How to use checksums
6ab51bbc093df15b6c2faf69ce9f0b73a96762503a4af8d76d5468d41cef6a34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release files / pelmesha-0.7.3-py3-none-any.whl

Download URL pelmesha-0.7.3-py3-none-any.whl
Size 134.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2aa7ef9563c4c7ba43eaef917fff837693517f1054a385a7e52dfb8a6a3cca84
BLAKE2b-256 checksum
How to use checksums
bed6451f36cbea700a84e4b8a7df438b49a8e0974bfe7142e34936a44c01cb7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page