spectral-similarity-matching-and-comparison
Summary
Match experimental MS2 spectra (consensus or single) against reference spectral libraries to identify unknown compounds through normalized dot-product similarity scoring. This skill enables compound identification in LC-MS/MS by quantifying spectral peak overlap and intensity agreement between experimental and reference MS2 data.
When to use
After extracting and optionally combining MS2 spectra from a chromatographic peak (e.g., at a known m/z value like 304.1131), you need to determine which compound(s) in a reference library best match the experimental spectrum. This is essential when the precursor m/z alone is insufficient for identification, such as when multiple reference compounds have overlapping mass values (e.g., Flumazenil and Fenamiphos both near m/z 304) or when you need to confirm peak identity against known standards in MGF or spectral database format.
When NOT to use
- When reference spectra for the suspected compounds are not available or differ significantly in acquisition conditions (e.g., different collision energy or MS instrument type) — similarity scores may be artificially low.
- When the experimental MS2 spectrum is of very low intensity or contains few informative peaks — consensus building from multiple spectra is required first.
- When the chromatographic peak is unresolved or contains multiple co-eluting compounds — deconvolution or higher-resolution separation should be performed before spectral matching.
Inputs
- Experimental MS2 spectrum (Spectra object, single or consensus from chromPeakSpectra)
- Reference MS2 spectra in MGF format (loaded via MsBackendMgf)
- Chromatographic peak metadata (m/z, retention time, isolation window)
Outputs
- Similarity scores (numeric vector) for each reference spectrum comparison
- Compound identity assignment (best-matching reference compound and ID)
- Mirror-plot visualization comparing experimental and reference spectra
How to apply
Load reference MS2 spectra from MGF files or spectral libraries (e.g., Metlin IDs 2724 for Flumazenil, 72445 for Fenamiphos) into a Spectra object using the Spectra and MsBackendMgf packages. Prepare the experimental MS2 spectrum by either using a single high-intensity spectrum or combining multiple MS2 spectra from the same chromatographic peak via combineSpectra() with combinePeaks() to increase signal robustness. Call compareSpectra() with the normalized dot-product method, setting the m/z tolerance to 40 ppm (or appropriate for your instrument) to account for mass measurement error. Compare the resulting similarity scores across all reference candidates; a high similarity score (typically >0.7 for reliable matches) to one reference but not others indicates positive compound identification. Generate mirror-plot visualizations to qualitatively inspect peak alignment and confirm that major experimental peaks align with major reference peaks.
Related tools
- Spectra (Core package for loading, manipulating, and storing experimental and reference MS2 spectra objects)
- MsBackendMgf (Backend for reading reference MS2 spectra from MGF (mascot generic format) files into Spectra objects)
- MetaboCoreUtils (Provides compareSpectra() method and similarity metrics (normalized dot-product) for spectral comparison)
- xcms (Upstream tool for chromatographic peak detection (findChromPeaks) and MS2 spectrum extraction (chromPeakSpectra)) — https://github.com/sneumann/xcms
- MsFeatures (Provides combineSpectra() and combinePeaks() functions for consensus spectrum generation prior to matching)
Examples
compareSpectra(experimental_spectrum, reference_spectra, method='dot', ppm=40)
Evaluation signals
- Similarity scores for true-positive reference compound are > 0.70 and substantially higher than false-positive candidates (e.g., >0.3 absolute difference).
- Mirror-plot visualization shows major m/z peaks (those with relative intensity >10% in either spectrum) in spatial alignment within the 40 ppm m/z tolerance window.
- Experimental spectrum intensity pattern across top 5–10 peaks correlates with reference spectrum pattern (visual inspection or Pearson r > 0.60 for peak intensities).
- Consensus spectrum from multiple MS2 scans shows improved match score and lower variance in peak position compared to any individual scan (when applicable).
- Matched compound's literature m/z, retention time range, and chemical class are consistent with the chromatographic peak metadata.
Limitations
- Spectral similarity depends on matching acquisition parameters (collision energy, ionization mode, instrument type); reference spectra acquired under different conditions may yield falsely low similarity scores.
- The 40 ppm m/z tolerance is appropriate for high-resolution Orbitrap or Q-TOF instruments but may need adjustment for lower-resolution instruments; tolerance selection directly impacts false-positive and false-negative rates.
- Compounds with very similar structures (isomers, regioisomers) may produce nearly identical MS2 spectra; additional orthogonal confirmation (e.g., retention time, NMR, or complementary ionization mode) may be necessary.
- Gap-filling and missing signal detection in MS2 spectra are not addressed by this skill; undetected peaks in the experimental or reference spectrum reduce similarity scores even if the compound is correct.
- The normalized dot-product method is sensitive to noise and low-intensity peaks; spectra with poor signal-to-noise ratios or extensive background should be filtered or enhanced before comparison.
Evidence
- [other] The consensus MS2 spectrum from the chromatographic peak at m/z 304.1131 has high similarity to Fenamiphos but not to Flumazenil when compared using the normalized dot-product method with 40 ppm tolerance, allowing identification of the peak as Fenamiphos.: "The consensus MS2 spectrum from the chromatographic peak at m/z 304.1131 has high similarity to Fenamiphos but not to Flumazenil when compared using the normalized dot-product method with 40 ppm"
- [intro] Spectra for identified chromatographic peaks can be extracted with the
chromPeakSpectra() method. We next reduce this to a single MS2 spectrum using the combineSpectra() method employing the combinePeaks() function we can also calculate similarities between them with the compareSpectra() method: "Spectra for identified chromatographic peaks can be extracted with the chromPeakSpectra() method. We next reduce this to a single MS2 spectrum using the combineSpectra() method employing the"
- [other] Match the experimental consensus spectrum against Flumazenil (Metlin ID 2724) and Fenamiphos (Metlin ID 72445) reference spectra in MGF format using compareSpectra().: "Match the experimental consensus spectrum against Flumazenil (Metlin ID 2724) and Fenamiphos (Metlin ID 72445) reference spectra in MGF format using compareSpectra()"
- [readme] The xcms R package provides functionality to efficiently preprocess LC-MS (as well as GC-MS and LC-MS/MS) data.: "The xcms R package provides functionality to efficiently preprocess LC-MS (as well as GC-MS and LC-MS/MS) data"
1---2name: spectral-similarity-matching-and-comparison3description: Use when after extracting and optionally combining MS2 spectra from a chromatographic peak (e.g., at a known m/z value like 304.1131), you need to determine which compound(s) in a reference library match the experimental spectrum.4license: CC-BY-4.05---67# spectral-similarity-matching-and-comparison89## Summary1011Match experimental MS2 spectra (consensus or single) against reference spectral libraries to identify unknown compounds through normalized dot-product similarity scoring. This skill enables compound identification in LC-MS/MS by quantifying spectral peak overlap and intensity agreement between experimental and reference MS2 data.1213## When to use1415After extracting and optionally combining MS2 spectra from a chromatographic peak (e.g., at a known m/z value like 304.1131), you need to determine which compound(s) in a reference library best match the experimental spectrum. This is essential when the precursor m/z alone is insufficient for identification, such as when multiple reference compounds have overlapping mass values (e.g., Flumazenil and Fenamiphos both near m/z 304) or when you need to confirm peak identity against known standards in MGF or spectral database format.1617## When NOT to use1819- When reference spectra for the suspected compounds are not available or differ significantly in acquisition conditions (e.g., different collision energy or MS instrument type) — similarity scores may be artificially low.20- When the experimental MS2 spectrum is of very low intensity or contains few informative peaks — consensus building from multiple spectra is required first.21- When the chromatographic peak is unresolved or contains multiple co-eluting compounds — deconvolution or higher-resolution separation should be performed before spectral matching.2223## Inputs2425- Experimental MS2 spectrum (Spectra object, single or consensus from chromPeakSpectra)26- Reference MS2 spectra in MGF format (loaded via MsBackendMgf)27- Chromatographic peak metadata (m/z, retention time, isolation window)2829## Outputs3031- Similarity scores (numeric vector) for each reference spectrum comparison32- Compound identity assignment (best-matching reference compound and ID)33- Mirror-plot visualization comparing experimental and reference spectra3435## How to apply3637Load reference MS2 spectra from MGF files or spectral libraries (e.g., Metlin IDs 2724 for Flumazenil, 72445 for Fenamiphos) into a Spectra object using the Spectra and MsBackendMgf packages. Prepare the experimental MS2 spectrum by either using a single high-intensity spectrum or combining multiple MS2 spectra from the same chromatographic peak via combineSpectra() with combinePeaks() to increase signal robustness. Call compareSpectra() with the normalized dot-product method, setting the m/z tolerance to 40 ppm (or appropriate for your instrument) to account for mass measurement error. Compare the resulting similarity scores across all reference candidates; a high similarity score (typically >0.7 for reliable matches) to one reference but not others indicates positive compound identification. Generate mirror-plot visualizations to qualitatively inspect peak alignment and confirm that major experimental peaks align with major reference peaks.3839## Related tools4041- **Spectra** (Core package for loading, manipulating, and storing experimental and reference MS2 spectra objects)42- **MsBackendMgf** (Backend for reading reference MS2 spectra from MGF (mascot generic format) files into Spectra objects)43- **MetaboCoreUtils** (Provides compareSpectra() method and similarity metrics (normalized dot-product) for spectral comparison)44- **xcms** (Upstream tool for chromatographic peak detection (findChromPeaks) and MS2 spectrum extraction (chromPeakSpectra)) — https://github.com/sneumann/xcms45- **MsFeatures** (Provides combineSpectra() and combinePeaks() functions for consensus spectrum generation prior to matching)4647## Examples4849```50compareSpectra(experimental_spectrum, reference_spectra, method='dot', ppm=40)51```5253## Evaluation signals5455- Similarity scores for true-positive reference compound are > 0.70 and substantially higher than false-positive candidates (e.g., >0.3 absolute difference).56- Mirror-plot visualization shows major m/z peaks (those with relative intensity >10% in either spectrum) in spatial alignment within the 40 ppm m/z tolerance window.57- Experimental spectrum intensity pattern across top 5–10 peaks correlates with reference spectrum pattern (visual inspection or Pearson r > 0.60 for peak intensities).58- Consensus spectrum from multiple MS2 scans shows improved match score and lower variance in peak position compared to any individual scan (when applicable).59- Matched compound's literature m/z, retention time range, and chemical class are consistent with the chromatographic peak metadata.6061## Limitations6263- Spectral similarity depends on matching acquisition parameters (collision energy, ionization mode, instrument type); reference spectra acquired under different conditions may yield falsely low similarity scores.64- The 40 ppm m/z tolerance is appropriate for high-resolution Orbitrap or Q-TOF instruments but may need adjustment for lower-resolution instruments; tolerance selection directly impacts false-positive and false-negative rates.65- Compounds with very similar structures (isomers, regioisomers) may produce nearly identical MS2 spectra; additional orthogonal confirmation (e.g., retention time, NMR, or complementary ionization mode) may be necessary.66- Gap-filling and missing signal detection in MS2 spectra are not addressed by this skill; undetected peaks in the experimental or reference spectrum reduce similarity scores even if the compound is correct.67- The normalized dot-product method is sensitive to noise and low-intensity peaks; spectra with poor signal-to-noise ratios or extensive background should be filtered or enhanced before comparison.6869## Evidence7071- [other] The consensus MS2 spectrum from the chromatographic peak at m/z 304.1131 has high similarity to Fenamiphos but not to Flumazenil when compared using the normalized dot-product method with 40 ppm tolerance, allowing identification of the peak as Fenamiphos.: "The consensus MS2 spectrum from the chromatographic peak at m/z 304.1131 has high similarity to Fenamiphos but not to Flumazenil when compared using the normalized dot-product method with 40 ppm"72- [intro] Spectra for identified chromatographic peaks can be extracted with the `chromPeakSpectra()` method. We next reduce this to a single MS2 spectrum using the `combineSpectra()` method employing the `combinePeaks()` function we can also calculate similarities between them with the `compareSpectra()` method: "Spectra for identified chromatographic peaks can be extracted with the `chromPeakSpectra()` method. We next reduce this to a single MS2 spectrum using the `combineSpectra()` method employing the"73- [other] Match the experimental consensus spectrum against Flumazenil (Metlin ID 2724) and Fenamiphos (Metlin ID 72445) reference spectra in MGF format using compareSpectra().: "Match the experimental consensus spectrum against Flumazenil (Metlin ID 2724) and Fenamiphos (Metlin ID 72445) reference spectra in MGF format using compareSpectra()"74- [readme] The *xcms* R package provides functionality to efficiently preprocess LC-MS (as well as GC-MS and LC-MS/MS) data.: "The *xcms* R package provides functionality to efficiently preprocess LC-MS (as well as GC-MS and LC-MS/MS) data"