mass-spectrometry-file-format-parsing
Summary
Parse and normalize tandem mass spectrometry spectra from multiple input file formats (.mgf, .msp, .mzML) into a unified internal representation with extracted fragment ion masses, intensity normalization, and neutral loss calculation. This foundational preprocessing step converts raw spectral data into a structured format suitable for downstream motif discovery and LDA modeling.
When to use
You have raw MS/MS spectral data in one or more standard mass spectrometry file formats (.mgf, .msp, or .mzML) and need to convert them into a standardized bag-of-fragments representation for unsupervised topic modeling or substructure discovery workflows. Apply this skill at the beginning of any MS2LDA pipeline before noise filtering, corpus generation, or LDA training.
When NOT to use
- Your spectral data is already in a pre-processed bag-of-fragments or document-term matrix format — skip directly to corpus filtering or LDA training.
- Your input files use non-standard or proprietary formats not listed in the MS2LDA.Preprocessing module documentation (.raw Thermo, .d Bruker, .wiff AB Sciex) — you will need custom format converters before applying this skill.
- You require retention-time-aware alignment or ion mobility dimension preservation that extends beyond single-spectrum parsing — this skill operates on individual MS/MS spectra and does not natively handle LC-IM-MS data integration.
Inputs
- MS/MS spectral data file in .mgf format (Mascot Generic Format)
- MS/MS spectral data file in .msp format (NIST MS Search format)
- MS/MS spectral data file in .mzML format (mzML XML-based format)
- Precursor m/z and charge state annotations (per spectrum)
- Peak intensity lists (m/z, intensity pairs per spectrum)
Outputs
- Unified internal spectral representation with parsed fragment ion masses
- Intensity-normalized fragment peak lists (per spectrum)
- Calculated neutral loss m/z values for all fragment pairs
- Preprocessed corpus object compatible with LDA model input (document-term matrix or serialized representation)
- Metadata log documenting format conversion, normalization scheme, and filtering thresholds applied
How to apply
Load MS/MS spectra from the input file using the MS2LDA.Preprocessing.load_and_clean module, which handles multiple format conversions transparently. Extract fragment ion masses from each spectrum and normalize peak intensities to a common scale (e.g., intensity of the base peak = 100). Calculate neutral loss values for all observed fragment ion pairs by subtracting fragment m/z values from the precursor mass minus common adducts. Document which intensity normalization scheme and neutral loss calculation method were applied, as these choices affect downstream motif inference. The preprocessing module outputs a structured corpus object ready for filtering and LDA training.
Related tools
- MS2LDA.Preprocessing.load_and_clean (Primary module for loading and normalizing raw MS/MS spectra from multiple file formats) — https://github.com/vdhooftcompmet/MS2LDA
- MS2LDA.Preprocessing.generate_corpus (Generates the final bag-of-fragments corpus representation by binning fragments and neutral losses into discrete mass tokens) — https://github.com/vdhooftcompmet/MS2LDA
- Python (Scripting language required to invoke MS2LDA preprocessing modules and configure the execution environment)
- Conda (Environment manager for installing MS2LDA and its dependencies with consistent versions)
Examples
from MS2LDA.Preprocessing import load_and_clean, generate_corpus
spectra = load_and_clean('data/compounds.mgf', ion_mode='positive')
corpus = generate_corpus(spectra, bin_width=0.1)
Evaluation signals
- All input spectra are successfully parsed without format conversion errors or missing precursor m/z / charge annotations.
- Fragment ion intensity distributions are normalized to a consistent scale (e.g., max intensity per spectrum equals 100); verify by inspecting normalized intensity histograms across a sample of spectra.
- Neutral loss m/z values are calculated for all fragment pairs and fall within expected chemical mass ranges (e.g., 18.01 for H₂O, 44.01 for CO₂, typical loss < precursor m/z); spot-check calculated neutral losses against known fragmentation rules.
- The output corpus object is serializable and can be loaded by the LDA training module without schema mismatch errors; validate by attempting to instantiate the LDA model on the generated corpus.
- The preprocessing module log records the input file format, normalization method applied, number of spectra loaded, and any spectra excluded due to missing precursor annotations or other quality filters.
Limitations
- The MS2LDA.Preprocessing module assumes standard tandem MS/MS formats (.mgf, .msp, .mzML); other vendor-specific formats (Thermo .raw, Bruker .d, AB Sciex .wiff) require external conversion before preprocessing.
- Intensity normalization is applied per-spectrum; if your dataset spans multiple acquisition instruments or methods with systematically different dynamic ranges, cross-file normalization may be required as an additional preprocessing step.
- Neutral loss calculation is deterministic given the precursor mass and fragment m/z values, but the choice of mass binning resolution (e.g., integer vs. decimal m/z bins) during corpus generation affects downstream motif granularity and must be selected before LDA training.
- High noise floors in spectra can inflate the number of spurious fragment ions and neutral losses; filtering by minimum intensity threshold or statistical significance is performed in a separate workflow step (not part of this skill) to remove noise.
- The preprocessing module does not correct for systematic mass calibration errors; spectra should be calibrated to ≤5 ppm accuracy before parsing, otherwise fragment and neutral loss identification may fail.
Evidence
- [methods] Load MS/MS spectra from input file (.mgf, .msp, or .mzML) using the MS2LDA.Preprocessing.load_and_clean module: "Load MS/MS spectra from input file (.mgf, .msp, or .mzML) using the MS2LDA.Preprocessing.load_and_clean module."
- [methods] Extract fragment ion masses and normalize peak intensities within each spectrum.: "Extract fragment ion masses and normalize peak intensities within each spectrum."
- [methods] Calculate neutral loss values for all observed fragment pairs.: "Calculate neutral loss values for all observed fragment pairs."
- [methods] Generate a bag-of-fragments corpus representation using MS2LDA.Preprocessing.generate_corpus, binning fragments and losses into discrete mass tokens.: "Generate a bag-of-fragments corpus representation using MS2LDA.Preprocessing.generate_corpus, binning fragments and losses into discrete mass tokens."
- [other] The preprocessing module converts MS/MS spectra into a bag-of-fragments format, extracts neutral losses, and filters out noise to prepare data for LDA modeling.: "The preprocessing module converts MS/MS spectra into a bag-of-fragments format, extracts neutral losses, and filters out noise to prepare data for LDA modeling."
- [readme] MS2LDA (Mass Spectrometry–Latent Dirichlet Allocation) is a framework that brings the concept of topic modeling to the world of tandem mass spectrometry: "MS2LDA (Mass Spectrometry–Latent Dirichlet Allocation) is a framework that brings the concept of topic modeling to the world of tandem mass spectrometry"
1---2name: mass-spectrometry-file-format-parsing-43description: Use when you have raw MS/MS spectral data in one or more standard mass4 spectrometry file formats (.mgf, .msp, or .mzML) and need to convert them into a5 standardized bag-of-fragments representation for unsupervised topic modeling or6 substructure discovery workflows.7license: CC-BY-4.08metadata:9 edam_operation: http://edamontology.org/operation_363210 edam_topics:11 - http://edamontology.org/topic_352012 - http://edamontology.org/topic_012113 tools:14 - MS2LDA15 - MS2LDA.Preprocessing.load_and_clean16 - Python17 - Conda18 - MS2LDA.Preprocessing.generate_corpus19 - ProteoWizard Library and Tools20 - pwiz21 techniques:22 - LC-MS23 - ion-mobility-MS24 license_tier: open25 provenance_tier: literature26derived_from:27- doi: 10.1073/pnas.160804111328 title: MS2LDA29- doi: 10.1021/acs.jproteome.9b0064030 title: ''31evidence_spans:32- MS2LDA (Mass Spectrometry–Latent Dirichlet Allocation) is a framework33- MS2LDA uses Latent Dirichlet Allocation (LDA) to infer which motifs are most likely34 to explain the observed fragmentation patterns35- from MS2LDA.Preprocessing import load_and_clean36- Configure the Python environment (set PYTHONPATH, activate conda, etc.)37- These steps assume you have Conda installed38- The ProteoWizard Library and Tools are a set of modular and extensible open-source,39 cross-platform tools and software libraries40claims: []41provenance:42 collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v243 assembled_by: scripts/collect_metabolomics_collection.py44 sources:45 - build: coll_eclipse_cq46 doi: 10.1093/bioinformatics/btaf29047 title: Eclipse48 - build: coll_matchms_cq49 doi: 10.1186/s13321-024-00878-150 title: matchms51 - build: coll_ms2lda52 doi: 10.1073/pnas.160804111353 title: MS2LDA54 - build: coll_skyline_small_molecules_cq55 doi: 10.1021/acs.jproteome.9b0064056 title: Skyline (small molecules)57 dedup_kept_from: coll_ms2lda58schema_version: 0.2.059attribution:60 generator: AgenticScienceBuilder61 original_doi: 10.1073/pnas.160804111362 all_source_dois:63 - 10.1073/pnas.160804111364 - 10.1021/acs.jproteome.9b0064065 zenodo_doi: 10.5281/zenodo.2079402766 curators: []67 promoter: Louis-Félix Nothias68 sponsor: CNRS & Université Côte d'Azur69---7071# mass-spectrometry-file-format-parsing7273## Summary7475Parse and normalize tandem mass spectrometry spectra from multiple input file formats (.mgf, .msp, .mzML) into a unified internal representation with extracted fragment ion masses, intensity normalization, and neutral loss calculation. This foundational preprocessing step converts raw spectral data into a structured format suitable for downstream motif discovery and LDA modeling.7677## When to use7879You have raw MS/MS spectral data in one or more standard mass spectrometry file formats (.mgf, .msp, or .mzML) and need to convert them into a standardized bag-of-fragments representation for unsupervised topic modeling or substructure discovery workflows. Apply this skill at the beginning of any MS2LDA pipeline before noise filtering, corpus generation, or LDA training.8081## When NOT to use8283- Your spectral data is already in a pre-processed bag-of-fragments or document-term matrix format — skip directly to corpus filtering or LDA training.84- Your input files use non-standard or proprietary formats not listed in the MS2LDA.Preprocessing module documentation (.raw Thermo, .d Bruker, .wiff AB Sciex) — you will need custom format converters before applying this skill.85- You require retention-time-aware alignment or ion mobility dimension preservation that extends beyond single-spectrum parsing — this skill operates on individual MS/MS spectra and does not natively handle LC-IM-MS data integration.8687## Inputs8889- MS/MS spectral data file in .mgf format (Mascot Generic Format)90- MS/MS spectral data file in .msp format (NIST MS Search format)91- MS/MS spectral data file in .mzML format (mzML XML-based format)92- Precursor m/z and charge state annotations (per spectrum)93- Peak intensity lists (m/z, intensity pairs per spectrum)9495## Outputs9697- Unified internal spectral representation with parsed fragment ion masses98- Intensity-normalized fragment peak lists (per spectrum)99- Calculated neutral loss m/z values for all fragment pairs100- Preprocessed corpus object compatible with LDA model input (document-term matrix or serialized representation)101- Metadata log documenting format conversion, normalization scheme, and filtering thresholds applied102103## How to apply104105Load MS/MS spectra from the input file using the MS2LDA.Preprocessing.load_and_clean module, which handles multiple format conversions transparently. Extract fragment ion masses from each spectrum and normalize peak intensities to a common scale (e.g., intensity of the base peak = 100). Calculate neutral loss values for all observed fragment ion pairs by subtracting fragment m/z values from the precursor mass minus common adducts. Document which intensity normalization scheme and neutral loss calculation method were applied, as these choices affect downstream motif inference. The preprocessing module outputs a structured corpus object ready for filtering and LDA training.106107## Related tools108109- **MS2LDA.Preprocessing.load_and_clean** (Primary module for loading and normalizing raw MS/MS spectra from multiple file formats) — https://github.com/vdhooftcompmet/MS2LDA110- **MS2LDA.Preprocessing.generate_corpus** (Generates the final bag-of-fragments corpus representation by binning fragments and neutral losses into discrete mass tokens) — https://github.com/vdhooftcompmet/MS2LDA111- **Python** (Scripting language required to invoke MS2LDA preprocessing modules and configure the execution environment)112- **Conda** (Environment manager for installing MS2LDA and its dependencies with consistent versions)113114## Examples115116```117from MS2LDA.Preprocessing import load_and_clean, generate_corpus118spectra = load_and_clean('data/compounds.mgf', ion_mode='positive')119corpus = generate_corpus(spectra, bin_width=0.1)120```121122## Evaluation signals123124- All input spectra are successfully parsed without format conversion errors or missing precursor m/z / charge annotations.125- Fragment ion intensity distributions are normalized to a consistent scale (e.g., max intensity per spectrum equals 100); verify by inspecting normalized intensity histograms across a sample of spectra.126- Neutral loss m/z values are calculated for all fragment pairs and fall within expected chemical mass ranges (e.g., 18.01 for H₂O, 44.01 for CO₂, typical loss < precursor m/z); spot-check calculated neutral losses against known fragmentation rules.127- The output corpus object is serializable and can be loaded by the LDA training module without schema mismatch errors; validate by attempting to instantiate the LDA model on the generated corpus.128- The preprocessing module log records the input file format, normalization method applied, number of spectra loaded, and any spectra excluded due to missing precursor annotations or other quality filters.129130## Limitations131132- The MS2LDA.Preprocessing module assumes standard tandem MS/MS formats (.mgf, .msp, .mzML); other vendor-specific formats (Thermo .raw, Bruker .d, AB Sciex .wiff) require external conversion before preprocessing.133- Intensity normalization is applied per-spectrum; if your dataset spans multiple acquisition instruments or methods with systematically different dynamic ranges, cross-file normalization may be required as an additional preprocessing step.134- Neutral loss calculation is deterministic given the precursor mass and fragment m/z values, but the choice of mass binning resolution (e.g., integer vs. decimal m/z bins) during corpus generation affects downstream motif granularity and must be selected before LDA training.135- High noise floors in spectra can inflate the number of spurious fragment ions and neutral losses; filtering by minimum intensity threshold or statistical significance is performed in a separate workflow step (not part of this skill) to remove noise.136- The preprocessing module does not correct for systematic mass calibration errors; spectra should be calibrated to ≤5 ppm accuracy before parsing, otherwise fragment and neutral loss identification may fail.137138## Evidence139140- [methods] Load MS/MS spectra from input file (.mgf, .msp, or .mzML) using the MS2LDA.Preprocessing.load_and_clean module: "Load MS/MS spectra from input file (.mgf, .msp, or .mzML) using the MS2LDA.Preprocessing.load_and_clean module."141- [methods] Extract fragment ion masses and normalize peak intensities within each spectrum.: "Extract fragment ion masses and normalize peak intensities within each spectrum."142- [methods] Calculate neutral loss values for all observed fragment pairs.: "Calculate neutral loss values for all observed fragment pairs."143- [methods] Generate a bag-of-fragments corpus representation using MS2LDA.Preprocessing.generate_corpus, binning fragments and losses into discrete mass tokens.: "Generate a bag-of-fragments corpus representation using MS2LDA.Preprocessing.generate_corpus, binning fragments and losses into discrete mass tokens."144- [other] The preprocessing module converts MS/MS spectra into a bag-of-fragments format, extracts neutral losses, and filters out noise to prepare data for LDA modeling.: "The preprocessing module converts MS/MS spectra into a bag-of-fragments format, extracts neutral losses, and filters out noise to prepare data for LDA modeling."145- [readme] MS2LDA (Mass Spectrometry–Latent Dirichlet Allocation) is a framework that brings the concept of topic modeling to the world of tandem mass spectrometry: "MS2LDA (Mass Spectrometry–Latent Dirichlet Allocation) is a framework that brings the concept of topic modeling to the world of tandem mass spectrometry"