agentsclimarketplace

Per sample spectral aggregation

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v1/skills/per-sample-spectral-aggregation

Use when you have raw MS2 spectra from a sample and need to collapse them into a single sample-level representation for comparison across multiple samples, particularly when samples have poor feature overlap, strong retention time shifts between LC methods, or were acquired on different mass.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill per-sample-spectral-aggregation

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

7.4 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it

per-sample-spectral-aggregation

Summary

Aggregate MS2 fragmentation peaks and neutral losses across all spectra within a single sample to produce a numeric fingerprint vector. This skill enables sample-level comparison when individual spectrum alignment is unreliable or retention times vary across LC methods or instruments.

When to use

Use this skill when you have raw MS2 spectra from a sample and need to collapse them into a single sample-level representation for comparison across multiple samples, particularly when samples have poor feature overlap, strong retention time shifts between LC methods, or were acquired on different mass spectrometer technologies (e.g. Maxis Q-ToF vs Q-Exactive Orbitrap).

When NOT to use

  • Input is already a pre-computed feature matrix or peak table — skip directly to alignment.
  • Spectra have been pre-processed into a single consensus spectrum per sample — no aggregation needed.
  • Your analysis requires individual spectrum-level similarity scores (e.g. for spectral library matching) rather than sample-level comparison.
  • Samples contain only a single spectrum each — aggregation would be trivial.

Inputs

  • MS2 spectra files in mzML, mzXML, or MGF format
  • Sample identifier (batch or group label)
  • Precursor m/z values per spectrum
  • Fragment m/z peaks per spectrum

Outputs

  • Per-sample MS2 fingerprint vector (numeric array)
  • Peak occurrence counts (sample-level aggregation)
  • Neutral loss occurrence counts (sample-level aggregation)
  • Sample-level spectral embedding from spec2vec

How to apply

Load MS2 spectra files (mzML, mzXML, or MGF formats) using matchms to parse fragmentation data. For each sample, iterate through all spectra and extract precursor m/z values. Count occurrences of all MS2 peaks (m/z fragments above noise threshold) in each spectrum. Calculate neutral losses by subtracting each observed fragment m/z from the precursor m/z. Aggregate peak and neutral loss counts across all spectra within the sample using spec2vec document conversion to handle the spectral embedding. Normalize the combined peak and neutral loss occurrence counts by sample size (total number of spectra) to produce a final numeric fingerprint vector. This vector becomes the sample's representation for downstream alignment and comparison.

Related tools

  • matchms (Parses raw MS2 spectra files and extracts precursor m/z and fragment peaks; provides spectrum objects and metadata cleaning) — https://github.com/matchms/matchms
  • spec2vec (Converts aggregated peak and neutral loss counts into spectral embeddings; learns structural relationships between fragments for document-level vectorization) — https://github.com/iomega/spec2vec
  • MEMO (Implements the full MS2-based sample vectorization pipeline, integrating matchms and spec2vec for per-sample fingerprint generation and downstream visualization) — https://github.com/mandelbrot-project/memo
  • numpy (Array operations for counting occurrences and normalizing fingerprint vectors)
  • Python 3.8+ (Runtime environment for matchms, spec2vec, and MEMO execution)

Examples

from memo.io import load_ms2_data
from memo.fingerprints import compute_fingerprints
spectra = load_ms2_data('sample.mzML')
fingerprint = compute_fingerprints(spectra, normalize_by_sample_size=True)

Evaluation signals

  • Fingerprint vector length is consistent across all samples (same number of unique peaks and neutral losses counted).
  • Peak and neutral loss counts are non-negative integers summing to approximately sample size × average spectrum complexity.
  • Normalization by sample size produces values in [0, 1] range or interpretable relative frequency scale.
  • Samples from the same experimental group cluster together after fingerprint alignment; samples from different groups show distinct separation.
  • Fingerprint vectors contain no NaN or Inf values; numerical stability is maintained when comparing samples with vastly different spectrum counts.

Limitations

  • Neutral loss calculation depends on accurate precursor m/z assignment; errors propagate through loss aggregation.
  • Aggregation discards temporal and spectral order information; samples with different fragmentation patterns but same peak/loss frequencies may be indistinguishable.
  • Noise threshold for peak detection is not explicitly specified in the method description — threshold choice affects which fragments are counted and must be tuned for each MS instrument type.
  • Sample size normalization assumes equal spectral quality across samples; highly contaminated or low-complexity samples may distort fingerprints.
  • Performance depends on spec2vec embedding training data; fingerprints are meaningful only for fragment types seen during embedding training.

Evidence

  • [other] MS2 fingerprints are generated by counting the occurrence of MS2 peaks and neutral losses (relative to the precursor ion) in each sample, producing a numeric fingerprint representation.: "The occurence of MS2 peaks and neutral losses (to the precursor) in each sample is counted and used to generate an MS2 fingerprint of the sample"
  • [other] Iterate through spectra in each sample and extract precursor m/z values; count occurrences of all MS2 peaks; calculate neutral losses by subtracting fragment m/z from precursor m/z; aggregate across all spectra within each sample.: "1. Load MS2 spectra files using matchms to parse fragmentation data. 2. Iterate through spectra in each sample and extract precursor m/z values. 3. Count occurrences of all MS2 peaks (m/z values"
  • [readme] MEMO suits particularly well to compare chemodiverse samples with poor feature overlap or strong retention time shifts across different LC methods and mass spectrometer technologies.: "MEMO suits particularly well to compare chemodiverse samples, ie with a poor features overlap, or to compare samples with a strong RT shift, acquired using different LC methods or even different mass"
  • [readme] matchms is built primarily on matchms and spec2vec packages for handling MS2 spectra parsing and vectorization.: "MEMO is mainly built on matchms_ and spec2vec_ packages for handling the MS2 spectra"
  • [other] Fingerprints are normalized by sample size to produce the final numeric representation.: "Generate a numeric fingerprint vector per sample combining peak and neutral loss occurrence counts, normalized by sample size."

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.