spectral-format-conversion
Summary
Convert mass spectrometry spectral data between standardized formats (mzML, mzXML, msp, MGF, JSON) to enable interoperability across analysis pipelines and ensure compatibility with downstream similarity scoring and comparison workflows.
When to use
When raw spectral data exists in one mass spectrometry file format but downstream analysis requires a different format; when integrating spectra from multiple sources or instruments that produce heterogeneous file formats; or when preparing spectral libraries for large-scale similarity comparisons that require consistent input encoding.
When NOT to use
- Input spectra are already in the target format — apply format conversion only when format mismatch is confirmed.
- Spectral data is already parsed into in-memory spectrum objects — conversion applies to file-level formats, not intermediate representations.
- Proprietary or unsupported file formats are encountered — matchms supports only mzML, mzXML, msp, metabolomics-USI, MGF, and JSON.
Inputs
- Raw spectral data in mzML format
- Raw spectral data in mzXML format
- Raw spectral data in msp format
- Raw spectral data in MGF format
- Raw spectral data in JSON format
Outputs
- Converted spectral dataset in target format (mzML, mzXML, msp, MGF, or JSON)
- Spectrum objects with normalized metadata fields
- Conversion log documenting format-specific transformations applied
How to apply
Load raw spectral data from the source format (mzML, mzXML, msp, MGF, or JSON) using matchms import utilities; apply format-specific parsers to extract peak lists and metadata fields; normalize metadata field names and structures to a common schema; validate that all required fields conform to the target format's specification; then export the converted spectrum dataset to the desired output format. Coordinate format conversion with metadata cleaning and validation (step 2–3 in the reconstruction workflow) to ensure data integrity is preserved across the conversion boundary.
Related tools
- matchms (Provides import utilities and format-specific parsers for reading and writing mzML, mzXML, msp, MGF, and JSON spectral formats) — https://github.com/matchms/matchms
- Python (Programming language for invoking matchms import and export functions within conversion workflows)
- pytest (Test framework for validating that format conversion preserves metadata integrity and peak accuracy across converted spectra)
Examples
from matchms.importing_utils import load_from_msp, save_as_json; spectra = load_from_msp('input.msp'); [spectrum.set("spectrum_type", "MS2") for spectrum in spectra]; save_as_json(spectra, 'output.json')
Evaluation signals
- Output spectrum count matches input spectrum count (no spectra lost or duplicated during conversion).
- All mandatory metadata fields in the target format are populated for each converted spectrum; no required fields are null or malformed.
- Peak lists (m/z and intensity arrays) are numerically identical before and after conversion, within floating-point precision tolerances.
- Metadata field names conform to the target format's naming conventions and schema; no deprecated or format-incompatible field names remain.
- File-level validation passes when output file is re-parsed by matchms import utilities and compared against source spectrum objects.
Limitations
- Conversion between formats may result in loss of format-specific metadata fields not supported by the target format; document such losses in a conversion report.
- Proprietary or vendor-specific extensions in source formats (e.g., instrument-specific annotations in mzML) may not be preserved during export to simpler formats.
- Large-scale batch conversions may introduce I/O bottlenecks if file formats require sequential record processing; consider chunking or parallelization strategies for multi-thousand spectrum datasets.
Evidence
- [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"
- [other] Load imported spectra from matchms-compatible format (mzML, mzXML, msp, MGF, or JSON) using Python and matchms import utilities: "Load imported spectra from matchms-compatible format (mzML, mzXML, msp, MGF, or JSON) using Python and matchms import utilities"
- [readme] It facilitates the implementation of straightforward, reproducible workflows, transforming raw data from common mass spectra file formats into pre- and post-processed spectral data: "It facilitates the implementation of straightforward, reproducible workflows, transforming raw data from common mass spectra file formats into pre- and post-processed spectral data"
- [other] Output cleaned spectrum dataset with validated metadata in the original or preferred matchms format: "Output cleaned spectrum dataset with validated metadata in the original or preferred matchms format"
1---2name: spectral-format-conversion3description: Use when when raw spectral data exists in one mass spectrometry file format but downstream analysis requires a different format; when integrating spectra from multiple sources or instruments that produce heterogeneous file formats;4license: CC-BY-4.05---67# spectral-format-conversion89## Summary1011Convert mass spectrometry spectral data between standardized formats (mzML, mzXML, msp, MGF, JSON) to enable interoperability across analysis pipelines and ensure compatibility with downstream similarity scoring and comparison workflows.1213## When to use1415When raw spectral data exists in one mass spectrometry file format but downstream analysis requires a different format; when integrating spectra from multiple sources or instruments that produce heterogeneous file formats; or when preparing spectral libraries for large-scale similarity comparisons that require consistent input encoding.1617## When NOT to use1819- Input spectra are already in the target format — apply format conversion only when format mismatch is confirmed.20- Spectral data is already parsed into in-memory spectrum objects — conversion applies to file-level formats, not intermediate representations.21- Proprietary or unsupported file formats are encountered — matchms supports only mzML, mzXML, msp, metabolomics-USI, MGF, and JSON.2223## Inputs2425- Raw spectral data in mzML format26- Raw spectral data in mzXML format27- Raw spectral data in msp format28- Raw spectral data in MGF format29- Raw spectral data in JSON format3031## Outputs3233- Converted spectral dataset in target format (mzML, mzXML, msp, MGF, or JSON)34- Spectrum objects with normalized metadata fields35- Conversion log documenting format-specific transformations applied3637## How to apply3839Load raw spectral data from the source format (mzML, mzXML, msp, MGF, or JSON) using matchms import utilities; apply format-specific parsers to extract peak lists and metadata fields; normalize metadata field names and structures to a common schema; validate that all required fields conform to the target format's specification; then export the converted spectrum dataset to the desired output format. Coordinate format conversion with metadata cleaning and validation (step 2–3 in the reconstruction workflow) to ensure data integrity is preserved across the conversion boundary.4041## Related tools4243- **matchms** (Provides import utilities and format-specific parsers for reading and writing mzML, mzXML, msp, MGF, and JSON spectral formats) — https://github.com/matchms/matchms44- **Python** (Programming language for invoking matchms import and export functions within conversion workflows)45- **pytest** (Test framework for validating that format conversion preserves metadata integrity and peak accuracy across converted spectra)4647## Examples4849```50from matchms.importing_utils import load_from_msp, save_as_json; spectra = load_from_msp('input.msp'); [spectrum.set("spectrum_type", "MS2") for spectrum in spectra]; save_as_json(spectra, 'output.json')51```5253## Evaluation signals5455- Output spectrum count matches input spectrum count (no spectra lost or duplicated during conversion).56- All mandatory metadata fields in the target format are populated for each converted spectrum; no required fields are null or malformed.57- Peak lists (m/z and intensity arrays) are numerically identical before and after conversion, within floating-point precision tolerances.58- Metadata field names conform to the target format's naming conventions and schema; no deprecated or format-incompatible field names remain.59- File-level validation passes when output file is re-parsed by matchms import utilities and compared against source spectrum objects.6061## Limitations6263- Conversion between formats may result in loss of format-specific metadata fields not supported by the target format; document such losses in a conversion report.64- Proprietary or vendor-specific extensions in source formats (e.g., instrument-specific annotations in mzML) may not be preserved during export to simpler formats.65- Large-scale batch conversions may introduce I/O bottlenecks if file formats require sequential record processing; consider chunking or parallelization strategies for multi-thousand spectrum datasets.6667## Evidence6869- [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"70- [other] Load imported spectra from matchms-compatible format (mzML, mzXML, msp, MGF, or JSON) using Python and matchms import utilities: "Load imported spectra from matchms-compatible format (mzML, mzXML, msp, MGF, or JSON) using Python and matchms import utilities"71- [readme] It facilitates the implementation of straightforward, reproducible workflows, transforming raw data from common mass spectra file formats into pre- and post-processed spectral data: "It facilitates the implementation of straightforward, reproducible workflows, transforming raw data from common mass spectra file formats into pre- and post-processed spectral data"72- [other] Output cleaned spectrum dataset with validated metadata in the original or preferred matchms format: "Output cleaned spectrum dataset with validated metadata in the original or preferred matchms format"