mass-spectrometry-data-format-parsing
Summary
Load and parse tandem mass spectrometry (MS/MS) spectral data from standard interchange formats (.mgf, .mzML, .msp) into memory for downstream preprocessing and modeling. This is the essential first step that converts heterogeneous file formats into a unified in-memory representation suitable for spectral filtering, fragmentation analysis, and bag-of-fragments conversion.
When to use
You have raw MS/MS spectra in one of the supported exchange formats (.mgf, .mzML, or .msp) and need to ingest them into an MS2LDA pipeline for unsupervised motif discovery. This skill is required before any preprocessing, filtering, or ionization-mode-specific handling can occur.
When NOT to use
- Input is already in memory as Python objects or a parsed spectral object from another tool — skip directly to filtering.
- You have already extracted and aggregated fragment intensities into a bag-of-words or feature matrix — parsing is unnecessary.
- Input file format is not one of the three supported formats (.mgf, .mzML, .msp); conversion to a supported format is required first.
Inputs
- Mass spectrometry spectral file (.mgf format)
- Mass spectrometry spectral file (.mzML format)
- Mass spectrometry spectral file (.msp format)
Outputs
- Parsed spectrum collection (in-memory objects with precursor mass, fragments, intensities, ionization mode)
- Spectrum metadata (MS level, ionization mode, acquisition parameters)
How to apply
Use the MS2LDA.Preprocessing.load_and_clean module to read spectral data from disk. The loader automatically detects or accepts the input format (.mgf, .mzML, or .msp) and deserializes spectra into structured objects that preserve precursor mass, fragment m/z values, intensities, and ionization mode metadata. The module performs basic validation during parsing (e.g., checking for required fields, handling missing intensity values). The parsed spectrum collection is then passed directly to subsequent filtering and neutral loss extraction steps. Correct parsing is verified by confirming that spectrum count matches the input file's declared spectrum count, that all required fields (precursor mass, fragment m/z, intensity) are populated, and that no malformed records cause loader errors.
Related tools
Examples
from MS2LDA.Preprocessing import load_and_clean; spectra = load_and_clean.load_spectra('samples.mgf', ionization_mode='positive')
Evaluation signals
- Spectrum count in parsed collection matches declared count in input file (no records dropped due to parse errors).
- All spectra have populated precursor mass, fragment m/z arrays, and intensity arrays (no null/missing required fields).
- Ionization mode metadata (positive/negative) is correctly assigned to each spectrum based on file headers or user input.
- No parsing exceptions or malformed record warnings during load; loader completes without errors.
- Downstream filtering steps (noise removal, ionization-mode-specific handling) execute without type errors or schema violations.
Limitations
- Only three file formats (.mgf, .mzML, .msp) are supported; other MS data formats (e.g., raw proprietary formats, NetCDF) require conversion before ingestion.
- Parser assumes standard compliance with .mgf, .mzML, and .msp specifications; nonstandard or corrupted files may fail silently or produce incomplete records.
- No automatic ionization-mode detection in .mgf format; user must specify or file must include ionization mode in headers.
- Large files (>1 GB) may cause high memory consumption during parsing; chunked or streaming load is not explicitly documented.
Evidence
- [other] Load MS/MS spectra from supported input file formats (.mgf, .mzML, or .msp) using the MS2LDA.Preprocessing.load_and_clean module.: "Load MS/MS spectra from supported input file formats (.mgf, .mzML, or .msp) using the MS2LDA.Preprocessing.load_and_clean module."
- [readme] MS2LDA is an advanced tool designed for unsupervised substructure discovery in mass spectrometry data, utilizing topic modeling and providing automated annotation of discovered motifs.: "MS2LDA is an advanced tool designed for unsupervised substructure discovery in mass spectrometry data, utilizing topic modeling and providing automated annotation of discovered motifs."
- [methods] Preprocessing → filter & clean your spectra (positive/negative ion mode): "Preprocessing → filter & clean your spectra (positive/negative ion mode)"
1---2name: mass-spectrometry-data-format-parsing3description: Use when you have raw MS/MS spectra in one of the supported exchange formats (.mgf, .mzML, or .msp) and need to ingest them into an MS2LDA pipeline for unsupervised motif discovery. This skill is required before any preprocessing, filtering, or ionization-mode-specific handling can occur.4license: CC-BY-4.05---67# mass-spectrometry-data-format-parsing89## Summary1011Load and parse tandem mass spectrometry (MS/MS) spectral data from standard interchange formats (.mgf, .mzML, .msp) into memory for downstream preprocessing and modeling. This is the essential first step that converts heterogeneous file formats into a unified in-memory representation suitable for spectral filtering, fragmentation analysis, and bag-of-fragments conversion.1213## When to use1415You have raw MS/MS spectra in one of the supported exchange formats (.mgf, .mzML, or .msp) and need to ingest them into an MS2LDA pipeline for unsupervised motif discovery. This skill is required before any preprocessing, filtering, or ionization-mode-specific handling can occur.1617## When NOT to use1819- Input is already in memory as Python objects or a parsed spectral object from another tool — skip directly to filtering.20- You have already extracted and aggregated fragment intensities into a bag-of-words or feature matrix — parsing is unnecessary.21- Input file format is not one of the three supported formats (.mgf, .mzML, .msp); conversion to a supported format is required first.2223## Inputs2425- Mass spectrometry spectral file (.mgf format)26- Mass spectrometry spectral file (.mzML format)27- Mass spectrometry spectral file (.msp format)2829## Outputs3031- Parsed spectrum collection (in-memory objects with precursor mass, fragments, intensities, ionization mode)32- Spectrum metadata (MS level, ionization mode, acquisition parameters)3334## How to apply3536Use the MS2LDA.Preprocessing.load_and_clean module to read spectral data from disk. The loader automatically detects or accepts the input format (.mgf, .mzML, or .msp) and deserializes spectra into structured objects that preserve precursor mass, fragment m/z values, intensities, and ionization mode metadata. The module performs basic validation during parsing (e.g., checking for required fields, handling missing intensity values). The parsed spectrum collection is then passed directly to subsequent filtering and neutral loss extraction steps. Correct parsing is verified by confirming that spectrum count matches the input file's declared spectrum count, that all required fields (precursor mass, fragment m/z, intensity) are populated, and that no malformed records cause loader errors.3738## Related tools3940- **MS2LDA.Preprocessing.load_and_clean** (Primary module for loading and parsing MS/MS spectral data from supported file formats into structured in-memory objects.) — https://github.com/vdhooftcompmet/MS2LDA41- **MS2LDA** (Broader toolkit that orchestrates preprocessing, modeling, and annotation; this skill is the data ingestion entry point.) — https://github.com/vdhooftcompmet/MS2LDA4243## Examples4445```46from MS2LDA.Preprocessing import load_and_clean; spectra = load_and_clean.load_spectra('samples.mgf', ionization_mode='positive')47```4849## Evaluation signals5051- Spectrum count in parsed collection matches declared count in input file (no records dropped due to parse errors).52- All spectra have populated precursor mass, fragment m/z arrays, and intensity arrays (no null/missing required fields).53- Ionization mode metadata (positive/negative) is correctly assigned to each spectrum based on file headers or user input.54- No parsing exceptions or malformed record warnings during load; loader completes without errors.55- Downstream filtering steps (noise removal, ionization-mode-specific handling) execute without type errors or schema violations.5657## Limitations5859- Only three file formats (.mgf, .mzML, .msp) are supported; other MS data formats (e.g., raw proprietary formats, NetCDF) require conversion before ingestion.60- Parser assumes standard compliance with .mgf, .mzML, and .msp specifications; nonstandard or corrupted files may fail silently or produce incomplete records.61- No automatic ionization-mode detection in .mgf format; user must specify or file must include ionization mode in headers.62- Large files (>1 GB) may cause high memory consumption during parsing; chunked or streaming load is not explicitly documented.6364## Evidence6566- [other] Load MS/MS spectra from supported input file formats (.mgf, .mzML, or .msp) using the MS2LDA.Preprocessing.load_and_clean module.: "Load MS/MS spectra from supported input file formats (.mgf, .mzML, or .msp) using the MS2LDA.Preprocessing.load_and_clean module."67- [readme] MS2LDA is an advanced tool designed for unsupervised substructure discovery in mass spectrometry data, utilizing topic modeling and providing automated annotation of discovered motifs.: "MS2LDA is an advanced tool designed for unsupervised substructure discovery in mass spectrometry data, utilizing topic modeling and providing automated annotation of discovered motifs."68- [methods] Preprocessing → filter & clean your spectra (positive/negative ion mode): "Preprocessing → filter & clean your spectra (positive/negative ion mode)"