MS2 Spectra Parsing and Loading
Summary
Load and parse tandem mass spectrometry (MS2) spectra files in standardized formats (mzML, mzXML, MGF) using the matchms library to extract MS2 fragmentation peaks, neutral losses, and precursor metadata for downstream sample vectorization and comparison.
When to use
When beginning a MEMO analysis workflow with raw or unaligned MS2 spectra files and needing to extract fragmentation data and precursor information before counting MS2 peaks and neutral losses to generate sample fingerprints. Use this skill as the first step before constructing a MemoMatrix.
When NOT to use
- Input spectra are already parsed as Python matchms Spectrum objects — pass them directly to memo_from_unaligned without re-parsing.
- Working with MS1-only or untargeted metabolomics data without tandem fragmentation spectra.
- Input is already a feature table or abundance matrix (e.g., from XCMS or MZmine) — use MEMO only on raw or library-matched MS2 spectra.
Inputs
- MS2 spectra file in mzML format
- MS2 spectra file in mzXML format
- MS2 spectra file in MGF (Mascot Generic Format)
- MS2 spectra file in msp format
- MS2 spectra file in metabolomics-USI format
- MS2 spectra file in JSON format
Outputs
- Parsed spectra objects (matchms Spectrum class instances)
- Spectrum metadata (precursor m/z, charge, retention time)
- MS2 peak lists with intensities
How to apply
Import MS2 spectra files in formats supported by matchms (mzML, mzXML, MGF, msp, metabolomics-USI, or JSON) using the matchms library's import functions. Parse the spectra to extract MS2 fragmentation peak lists, precursor m/z and charge, and associated metadata. The parsed spectra objects retain both spectral data (peaks and intensities) and metadata needed for subsequent fingerprinting. Validate the loaded spectra by checking that peaks are present, precursor information is populated, and the number of loaded spectra matches expectations. The parsed spectra are then passed directly to the MEMO fingerprinting stage (memo_from_unaligned), which counts peak and neutral loss occurrences across the sample.
Related tools
Examples
from matchms.importing import load_from_mgf; spectra = list(load_from_mgf('unaligned_spectra.mgf')); from memo import memo_from_unaligned; memo_matrix = memo_from_unaligned(spectra)
Evaluation signals
- All spectra are successfully loaded into matchms Spectrum objects with non-null precursor m/z and charge state.
- Peak lists contain expected fragmentation patterns (e.g., presence of product ions, neutral losses relative to precursor m/z).
- Loaded spectra count matches the expected number of MS/MS scans in the input file.
- Metadata fields (precursor_mz, charge, retention_time, spectrum_id) are populated where present in the input file.
- Parsed spectra can be passed without error to memo_from_unaligned() and produce a valid MemoMatrix with correct sample-by-feature dimensionality.
Limitations
- Parsing accuracy depends on file format compliance; malformed or corrupted MS2 files may fail to load or produce incomplete spectra.
- Retention time (RT) information is parsed but not used by MEMO, which is designed to be RT-agnostic; RT fields are retained only for reference.
- Large files (hundreds of thousands of spectra) may require memory optimization; matchms supports sparse array handling in recent versions but parsing time scales linearly with file size.
- File format support is limited to mzML, mzXML, MGF, msp, metabolomics-USI, and JSON; other vendor-specific formats (e.g., raw Thermo files) require prior conversion.
Evidence
- [other] Load unaligned MS2 spectra files in a format supported by matchms (e.g., .mgf, .mzML, .mzXML): "Load unaligned MS2 spectra files in a format supported by matchms (e.g., .mgf, .mzML, .mzXML). 2. Parse spectra using matchms to extract MS2 fragmentation data and precursor information."
- [other] MEMO is mainly built on matchms and spec2vec packages for handling the MS2 spectra: "MEMO is mainly built on
matchms_ and spec2vec_ packages for handling the MS2 spectra"
- [readme] matchms is a versatile open-source Python package for importing, processing, cleaning, and comparing mass spectrometry data (MS/MS): "Matchms is a versatile open-source Python package developed for importing, processing, cleaning, and comparing mass spectrometry data (MS/MS)."
- [readme] matchms 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."
- [other] The occurrence of MS2 peaks and neutral losses (to the precursor) in each sample is counted and used to generate an MS2 fingerprint: "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"
1---2name: ms2-spectra-parsing-and-loading-33description: Use when when beginning a MEMO analysis workflow with raw or unaligned4 MS2 spectra files and needing to extract fragmentation data and precursor information5 before counting MS2 peaks and neutral losses to generate sample fingerprints.6license: CC-BY-4.07metadata:8 edam_operation: http://edamontology.org/operation_33579 edam_topics:10 - http://edamontology.org/topic_352011 - http://edamontology.org/topic_012112 tools:13 - matchms14 - spec2vec15 - Python 3.816 - numpy17 - scikit-bio18 - memo-ms19 techniques:20 - LC-MS21 license_tier: open22 provenance_tier: literature23derived_from:24- doi: 10.3389/fbinf.2022.84296425 title: memo26evidence_spans:27- MEMO is mainly built on `matchms`_ and `spec2vec`_ packages for handling the MS228 spectra29- conda create --name memo python=3.830- pip install numpy31- conda install -c conda-forge scikit-bio32claims: []33provenance:34 collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v235 assembled_by: scripts/collect_metabolomics_collection.py36 sources:37 - build: coll_memo38 doi: 10.3389/fbinf.2022.84296439 title: memo40 dedup_kept_from: coll_memo41schema_version: 0.2.042attribution:43 generator: AgenticScienceBuilder44 original_doi: 10.3389/fbinf.2022.84296445 all_source_dois:46 - 10.3389/fbinf.2022.84296447 zenodo_doi: 10.5281/zenodo.2079402748 curators: []49 promoter: Louis-Félix Nothias50 sponsor: CNRS & Université Côte d'Azur51---5253# MS2 Spectra Parsing and Loading5455## Summary5657Load and parse tandem mass spectrometry (MS2) spectra files in standardized formats (mzML, mzXML, MGF) using the matchms library to extract MS2 fragmentation peaks, neutral losses, and precursor metadata for downstream sample vectorization and comparison.5859## When to use6061When beginning a MEMO analysis workflow with raw or unaligned MS2 spectra files and needing to extract fragmentation data and precursor information before counting MS2 peaks and neutral losses to generate sample fingerprints. Use this skill as the first step before constructing a MemoMatrix.6263## When NOT to use6465- Input spectra are already parsed as Python matchms Spectrum objects — pass them directly to memo_from_unaligned without re-parsing.66- Working with MS1-only or untargeted metabolomics data without tandem fragmentation spectra.67- Input is already a feature table or abundance matrix (e.g., from XCMS or MZmine) — use MEMO only on raw or library-matched MS2 spectra.6869## Inputs7071- MS2 spectra file in mzML format72- MS2 spectra file in mzXML format73- MS2 spectra file in MGF (Mascot Generic Format)74- MS2 spectra file in msp format75- MS2 spectra file in metabolomics-USI format76- MS2 spectra file in JSON format7778## Outputs7980- Parsed spectra objects (matchms Spectrum class instances)81- Spectrum metadata (precursor m/z, charge, retention time)82- MS2 peak lists with intensities8384## How to apply8586Import MS2 spectra files in formats supported by matchms (mzML, mzXML, MGF, msp, metabolomics-USI, or JSON) using the matchms library's import functions. Parse the spectra to extract MS2 fragmentation peak lists, precursor m/z and charge, and associated metadata. The parsed spectra objects retain both spectral data (peaks and intensities) and metadata needed for subsequent fingerprinting. Validate the loaded spectra by checking that peaks are present, precursor information is populated, and the number of loaded spectra matches expectations. The parsed spectra are then passed directly to the MEMO fingerprinting stage (memo_from_unaligned), which counts peak and neutral loss occurrences across the sample.8788## Related tools8990- **matchms** (Core library for importing, parsing, and handling MS2 spectra objects from multiple file formats) — https://github.com/matchms/matchms91- **memo-ms** (Downstream tool that accepts parsed spectra to generate MS2 fingerprints and MemoMatrix alignment) — https://github.com/mandelbrot-project/memo9293## Examples9495```96from matchms.importing import load_from_mgf; spectra = list(load_from_mgf('unaligned_spectra.mgf')); from memo import memo_from_unaligned; memo_matrix = memo_from_unaligned(spectra)97```9899## Evaluation signals100101- All spectra are successfully loaded into matchms Spectrum objects with non-null precursor m/z and charge state.102- Peak lists contain expected fragmentation patterns (e.g., presence of product ions, neutral losses relative to precursor m/z).103- Loaded spectra count matches the expected number of MS/MS scans in the input file.104- Metadata fields (precursor_mz, charge, retention_time, spectrum_id) are populated where present in the input file.105- Parsed spectra can be passed without error to memo_from_unaligned() and produce a valid MemoMatrix with correct sample-by-feature dimensionality.106107## Limitations108109- Parsing accuracy depends on file format compliance; malformed or corrupted MS2 files may fail to load or produce incomplete spectra.110- Retention time (RT) information is parsed but not used by MEMO, which is designed to be RT-agnostic; RT fields are retained only for reference.111- Large files (hundreds of thousands of spectra) may require memory optimization; matchms supports sparse array handling in recent versions but parsing time scales linearly with file size.112- File format support is limited to mzML, mzXML, MGF, msp, metabolomics-USI, and JSON; other vendor-specific formats (e.g., raw Thermo files) require prior conversion.113114## Evidence115116- [other] Load unaligned MS2 spectra files in a format supported by matchms (e.g., .mgf, .mzML, .mzXML): "Load unaligned MS2 spectra files in a format supported by matchms (e.g., .mgf, .mzML, .mzXML). 2. Parse spectra using matchms to extract MS2 fragmentation data and precursor information."117- [other] MEMO is mainly built on matchms and spec2vec packages for handling the MS2 spectra: "MEMO is mainly built on `matchms`_ and `spec2vec`_ packages for handling the MS2 spectra"118- [readme] matchms is a versatile open-source Python package for importing, processing, cleaning, and comparing mass spectrometry data (MS/MS): "Matchms is a versatile open-source Python package developed for importing, processing, cleaning, and comparing mass spectrometry data (MS/MS)."119- [readme] matchms 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."120- [other] The occurrence of MS2 peaks and neutral losses (to the precursor) in each sample is counted and used to generate an MS2 fingerprint: "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"