agentsclimarketplace

Spectral peak fitting gaussian

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/spectral-peak-fitting-gaussian

Use when you have 1D MS signal data (extracted ion chromatograms, arrival time distributions, or intensity profiles) and need to resolve overlapping or closely-spaced peaks with accurate position, height, and width estimates.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill spectral-peak-fitting-gaussian

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 15 stars15 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

9.2 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it

Spectral peak fitting via Gaussian decomposition

Summary

Detect and quantify peaks in 1D mass spectrometry signal data by iteratively fitting Gaussian curves to the signal and subtracting fitted components from residuals. This method is preferred over local-maximum detection when peak shape, amplitude, and width must be resolved precisely.

When to use

Apply this skill when you have 1D MS signal data (extracted ion chromatograms, arrival time distributions, or intensity profiles) and need to resolve overlapping or closely-spaced peaks with accurate position, height, and width estimates. Use Gaussian fitting instead of local-maximum detection when the signal contains peaks with continuous intensity distributions that require shape characterization or when you need quantitative peak parameters for downstream feature extraction or isotope pattern analysis.

When NOT to use

  • Input signal is already pre-processed into a feature table (e.g., aligned peak matrix); use this skill on raw or minimally-processed 1D traces, not aggregate matrices.
  • Peak shapes are known to be non-Gaussian (e.g., highly asymmetric due to instrumental distortion); consider alternative fitting models (e.g., exponential Gaussian hybrid) or validate Gaussian assumption first.
  • Signal-to-noise ratio is very low or baseline is highly irregular; Gaussian fitting may converge to noise artifacts; apply baseline subtraction and noise filtering before peak fitting.

Inputs

  • 1D signal array (numpy array or similar) — m/z intensities, chromatographic intensities, or arrival time distribution counts
  • Absolute or relative intensity threshold (scalar) — minimum peak height to retain
  • Maximum peak count (integer) — upper limit on number of peaks to extract
  • Gaussian fitting configuration (dict or parameters) — initial guess strategy, optimization tolerances, bounds

Outputs

  • Detected peaks array or list of dicts — each peak with position (mean), height (amplitude), width (standard deviation), and optionally goodness-of-fit metrics
  • Residual signal array — final residuals after all peaks subtracted
  • Peak parameters table — columns: scan/spectrum identifier, peak index, fitted mean m/z, fitted intensity, fitted sigma, residual sum-of-squares

How to apply

Accept a 1D signal array and configure stopping criteria: an absolute or relative intensity threshold below which fitted peaks are discarded, and a maximum number of peaks to extract. Initialize by fitting a Gaussian curve to the full signal using least-squares optimization. Extract the fitted peak's parameters (amplitude, mean position, standard deviation width). Check if the peak height exceeds the stopping threshold; if yes, retain it and subtract the fitted Gaussian from the signal to produce residuals. Repeat the fitting process on the residuals until either the maximum peak count is reached or the next fitted peak falls below the height threshold. Return all detected peaks with their position, height, and width parameters. Validate the results by confirming that detected peak heights decrease across iterations and that residual sum-of-squares improves monotonically with each fit.

Related tools

  • mzapy.peaks.find_peaks_1d_gauss (Core function implementing iterative Gaussian peak fitting and subtraction on 1D MZA spectral arrays) — https://github.com/PNNL-m-q/mzapy
  • scipy.optimize.least_squares or scipy.optimize.curve_fit (Underlying nonlinear optimization engine for Gaussian parameter estimation)
  • numpy (Array manipulation and residual calculation)
  • mzapy.peaks.calc_gauss_psnr (Post-fit validation metric; computes peak signal-to-noise ratio to assess goodness of Gaussian fit) — https://github.com/PNNL-m-q/mzapy
  • mzapy.peaks.calc_peak_area (Auxiliary function to compute integrated peak area from fitted Gaussian parameters) — https://github.com/PNNL-m-q/mzapy

Examples

from mzapy.peaks import find_peaks_1d_gauss; peaks = find_peaks_1d_gauss(signal_array, intensity_threshold=100, max_peaks=10, fit_config={'method': 'lsq'})

Evaluation signals

  • Monotonic decrease in fitted peak heights across successive iterations (first peak height ≥ second peak height ≥ ... ≥ last peak height).
  • Residual sum-of-squares (RSS) decreases with each fitted Gaussian and does not increase after subtraction of subsequent peaks.
  • All retained peaks have height ≥ configured intensity threshold; peaks below threshold are correctly rejected and not included in output.
  • Fitted Gaussian parameters (mean, sigma) are within physically plausible bounds for the instrument and signal range (e.g., mean within m/z axis range, sigma > 0).
  • Visual inspection: overlay of fitted Gaussian curves on original signal shows alignment with observed peak features; residual trace after peak subtraction exhibits noise-like character (no systematic over/under-fit).

Limitations

  • Gaussian assumption may fail for asymmetric or distorted peaks common in high-mass or time-of-flight spectra; method performs best on approximately bell-shaped profiles.
  • Iterative subtraction can propagate fitting errors from early peaks into residuals; poor initial fits may cause spurious peaks in later iterations or false convergence.
  • Requires careful tuning of intensity threshold and maximum peak count to avoid both under-detection (threshold too high) and over-detection (max count too high or threshold too low), especially in noisy data.
  • Computational cost grows with signal length and number of peaks; may be slow for very long chromatographic traces or high-dimensional (2D) data without prior dimensionality reduction.
  • Performance degrades when baseline is non-flat or contains systematic drift; pre-processing (baseline subtraction, smoothing) is recommended.

Evidence

  • [other] Two functions are provided for performing peak fitting on 1-dimensional data: mzapy.peaks.find_peaks_1d_localmax and mzapy.peaks.find_peaks_1d_gauss: "Two functions are provided for performing peak fitting on 1-dimensional data: mzapy.peaks.find_peaks_1d_localmax and mzapy.peaks.find_peaks_1d_gauss"
  • [other] mzapy provides a find_peaks_1d_gauss function for performing peak fitting on 1-dimensional data via Gaussian fitting, distinguished as a separate method from the local-maximum approach.: "mzapy provides a find_peaks_1d_gauss function for performing peak fitting on 1-dimensional data via Gaussian fitting, distinguished as a separate method from the local-maximum approach."
  • [other] Perform iterative least-squares Gaussian fitting on the signal: fit a Gaussian curve to the current data, extract peak parameters (amplitude, mean, standard deviation), and check if peak height exceeds the stopping threshold. Subtract the fitted Gaussian from the residuals and repeat fitting on the updated residuals until reaching maximum peak count or falling below height threshold.: "Perform iterative least-squares Gaussian fitting on the signal: fit a Gaussian curve to the current data, extract peak parameters (amplitude, mean, standard deviation), and check if peak height"
  • [other] Validation: verify that detected peaks have decreasing height across iterations and that residual sum-of-squares improves with each fit.: "Validation: verify that detected peaks have decreasing height across iterations and that residual sum-of-squares improves with each fit."
  • [other] Accept a 1D signal array as input. Initialize parameters: absolute or relative intensity threshold for peak height, maximum number of peaks to find, and Gaussian fitting configuration.: "Accept a 1D signal array as input. Initialize parameters: absolute or relative intensity threshold for peak height, maximum number of peaks to find, and Gaussian fitting configuration."

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.