agentsclimarketplace

Pairwise spectral comparison

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v1/skills/pairwise-spectral-comparison

Use when you have a collection of preprocessed mass spectra (in mzML, mzXML, msp, MGF, or JSON format) and need to quantify similarity relationships across all pairs—for instance, to identify redundant spectra in a library, cluster related compounds, or perform spectral library searches.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill pairwise-spectral-comparison

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.5 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it

pairwise-spectral-comparison

Summary

Compute similarity scores between all pairs of mass spectra using matchms' built-in similarity measures (Cosine, molecular fingerprint-based, or metadata-related assessments). This skill enables large-scale spectral comparisons and is essential for identifying related or duplicate spectra in spectral libraries.

When to use

Apply this skill when you have a collection of preprocessed mass spectra (in mzML, mzXML, msp, MGF, or JSON format) and need to quantify similarity relationships across all pairs—for instance, to identify redundant spectra in a library, cluster related compounds, or perform spectral library searches.

When NOT to use

  • Input spectra are not preprocessed or peak-filtered; conduct basic peak filtering and metadata cleaning first.
  • You require only single-query-to-library searches rather than all-pairs comparisons; use targeted library search methods instead.
  • Spectra are in unsupported formats (not mzML, mzXML, msp, MGF, or JSON); convert or reformat first.

Inputs

  • Preprocessed mass spectra collection (mzML, mzXML, msp, MGF, or JSON format)
  • Spectrum metadata (if using metadata-related similarity measures)
  • Selected similarity measure (Cosine, fingerprint-based, or metadata-based)

Outputs

  • Pairwise similarity scores matrix (CSV or pickle format)
  • Spectrum identifiers as row and column labels
  • Structured scores output suitable for filtering and clustering

How to apply

Load preprocessed spectra into matchms from a supported file format. Select an appropriate similarity measure: Cosine-based scores for peak-overlap similarity, molecular fingerprint-based comparisons for structural relationships, or metadata-related assessments for compound attribute matching. Apply the chosen measure to all spectrum pairs to generate a pairwise similarity scores matrix. Construct a structured output (CSV or pickle) with spectrum identifiers as row and column labels to enable downstream filtering, clustering, or search operations. The choice of similarity measure should align with your research question: Cosine similarity is computationally efficient and suitable for initial pre-selection of candidates, while fingerprint-based measures capture deeper structural similarity.

Related tools

  • matchms (Core library implementing pairwise similarity measures (Cosine, fingerprint-based, metadata) and scores matrix output) — https://github.com/matchms/matchms
  • Python (Runtime environment for executing matchms workflows and manipulating similarity scores matrices)
  • Spec2Vec (Optional extension for advanced spectrum similarity measures tailored for matchms) — https://github.com/iomega/spec2vec
  • MS2DeepScore (Optional extension for deep learning-based spectrum similarity measures integrated with matchms) — https://github.com/matchms/ms2deepscore

Examples

from matchms import Spectrum, Cosine
from matchms.importing import load_from_msp
spectra = list(load_from_msp('spectra.msp'))
similarity_measure = Cosine()
scores = [[similarity_measure(spectra[i], spectra[j]).score for j in range(len(spectra))] for i in range(len(spectra))]
import pandas as pd
df = pd.DataFrame(scores, index=[s.metadata['spectrum_id'] for s in spectra], columns=[s.metadata['spectrum_id'] for s in spectra])
df.to_csv('pairwise_similarity_scores.csv')

Evaluation signals

  • Scores matrix dimensions match the number of input spectra (n × n symmetry).
  • Scores are bounded within expected range (e.g., 0–1 for normalized Cosine or fingerprint similarity).
  • Diagonal elements equal expected self-similarity (typically 1.0 for normalized measures).
  • Output file is present in the named location and matches the specified format (CSV or pickle).
  • Spot-checks of known spectral pairs (e.g., duplicate or highly related spectra) show high similarity scores, while unrelated pairs show low scores.

Limitations

  • Computing all-pairs scores for very large spectral libraries (several hundred thousand spectra) requires sparse handling of scores and efficient similarity measures to avoid memory exhaustion.
  • Choice of similarity measure significantly impacts interpretation: Cosine similarity captures peak overlap but may miss structural similarity; fingerprint-based measures are computationally more expensive but capture deeper compound relationships.
  • Metadata-related similarity measures depend on data quality and completeness of metadata fields; incomplete or noisy metadata may yield uninformative scores.
  • Preprocessing quality directly affects results; poorly filtered peaks or incorrect metadata cleaning will propagate into the similarity matrix.

Evidence

  • [other] Apply the cosine similarity measure to compute pairwise scores between all spectrum pairs.: "Apply the cosine similarity measure to compute pairwise scores between all spectrum pairs"
  • [other] Matchms applies molecular fingerprint-based comparisons as one of several pairwise similarity measures available for comparing extensive amounts of spectra.: "Matchms implements molecular fingerprint-based comparisons as one of several pairwise similarity measures available for comparing extensive amounts of spectra"
  • [readme] Its ability to apply various pairwise similarity measures encompasses not only common Cosine-related scores but also molecular fingerprint-based comparisons and other metadata-related assessments.: "its ability to apply various pairwise similarity measures for comparing extensive amounts of spectra. This encompasses not only common Cosine-related scores but also molecular fingerprint-based"
  • [other] Load preprocessed spectra from the input file using matchms and construct a scores matrix with spectrum identifiers as row and column labels.: "Load preprocessed spectra from the input file (peak-filtered spectra or reference spectral library) using matchms. Apply the cosine similarity measure to compute pairwise scores between all spectrum"
  • [readme] The software supports a range of popular spectral data formats, including mzML, mzXML, msp, metabolomics-USI, MGF, and JSON.: "The software supports a range of popular spectral data formats, including mzML, mzXML, msp, metabolomics-USI, MGF, and JSON"
  • [readme] Matchms enhances efficiency by using faster similarity measures for initial pre-selection and supports storing results in sparse data formats.: "Matchms enhances efficiency by using faster similarity measures for initial pre-selection and supports storing results in sparse data formats"

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.