spectrum-object-instantiation
Summary
Convert parsed mass spectrometry data (m/z arrays, intensity values, and metadata) into matchms Spectrum objects that serve as the standardized input format for downstream processing and similarity comparisons. This skill bridges file parsing and the matchms object model, ensuring spectral data is represented in a canonical, queryable form.
When to use
After successfully parsing raw spectral data from one of the supported file formats (mzML, mzXML, msp, metabolomics-USI, MGF, JSON) into intermediate dictionaries containing m/z arrays, intensity arrays, and metadata key-value pairs. Use this skill immediately before passing spectra to processing pipelines, cleaning workflows, or similarity comparison routines.
When NOT to use
- If spectral data has not yet been parsed into intermediate dictionaries—use format-specific parsers first.
- If the input m/z and intensity arrays have mismatched lengths or contain non-numeric values—validate and clean the parsed data before instantiation.
- If you are working directly with a native matchms import function (e.g., from_msp, from_mzml) that handles both parsing and instantiation in one step.
Inputs
- Parsed spectral data dictionary (containing m/z array, intensity array, metadata key-value pairs)
- File format identifier (mzML, mzXML, msp, metabolomics-USI, MGF, or JSON)
- Intermediate data structure from format-specific parser
Outputs
- matchms Spectrum object(s)
- Collection of instantiated Spectrum objects ready for downstream processing
How to apply
Create Spectrum objects by populating required fields (m/z arrays, intensity arrays, metadata) from the parsed intermediate data dictionary. Each Spectrum instance should have validated m/z and intensity arrays of matching length, and metadata fields that conform to matchms standards. Ensure the instantiated objects are compatible with downstream processing by verifying they expose the expected attributes (e.g., m/z, intensities, metadata dict) before passing them to cleaning, filtering, or comparison workflows. Use pytest to write unit tests that verify spectrum objects from each supported format retain their original m/z, intensity, and metadata values without loss or corruption.
Related tools
- matchms (Python library providing the Spectrum class definition and object instantiation interface) — https://github.com/matchms/matchms
- pytest (Testing framework for writing unit tests that verify Spectrum objects are correctly instantiated with expected m/z, intensity, and metadata attributes)
- Python (Programming language for implementing format-specific parsers and Spectrum instantiation logic)
Evaluation signals
- Instantiated Spectrum objects expose the required attributes: m/z array, intensity array, and metadata dictionary.
- m/z and intensity arrays are of equal length and contain numeric types (float or int).
- Metadata fields match the original values from the parsed intermediate dictionary (no silent omission or corruption).
- Unit test suite using pytest passes for each supported format, confirming round-trip fidelity (parse → instantiate → verify).
- Instantiated Spectrum objects integrate without errors into downstream matchms workflows (processing, filtering, similarity scoring).
Limitations
- matchms supports only six file formats (mzML, mzXML, msp, metabolomics-USI, MGF, JSON); spectra from other formats require custom parsing before instantiation.
- Spectrum instantiation does not perform metadata cleaning or validation; raw metadata from parsed data is preserved as-is—use dedicated metadata cleaning steps afterward if needed.
- Large-scale instantiation of many Spectrum objects may require attention to memory usage, particularly when holding entire spectral libraries in memory before writing to persistent storage.
- The Spectrum object model assumes standard mass spectrometry attributes (m/z, intensity, precursor m/z, etc.); non-standard or missing fields must be handled by the parser before instantiation.
Evidence
- [other] Instantiate matchms spectrum objects from the parsed data, populating required fields (m/z arrays, intensity arrays, metadata).: "Instantiate matchms spectrum objects from the parsed data, populating required fields (m/z arrays, intensity arrays, metadata)"
- [readme] transforming raw data from common mass spectra file formats into pre- and post-processed spectral data: "transforming raw data from common mass spectra file formats into pre- and post-processed spectral data"
- [other] Write unit tests using pytest to verify that spectra from each format are correctly imported with expected m/z, intensity, and metadata attributes.: "Write unit tests using pytest to verify that spectra from each format are correctly imported with expected m/z, intensity, and metadata attributes"
- [other] Validate that imported spectrum objects are compatible with downstream processing and comparison workflows in matchms.: "Validate that imported spectrum objects are compatible with downstream processing and comparison workflows in matchms"
- [other] Implement format-specific parsers for each file type, each extracting spectral peaks, metadata, and intensity values into intermediate data dictionaries.: "Implement format-specific parsers for each file type, each extracting spectral peaks, metadata, and intensity values into intermediate data dictionaries"
1---2name: spectrum-object-instantiation3description: Use when after successfully parsing raw spectral data from one of the supported file formats (mzML, mzXML, msp, metabolomics-USI, MGF, JSON) into intermediate dictionaries containing m/z arrays, intensity arrays, and metadata key-value pairs.4license: CC-BY-4.05---67# spectrum-object-instantiation89## Summary1011Convert parsed mass spectrometry data (m/z arrays, intensity values, and metadata) into matchms Spectrum objects that serve as the standardized input format for downstream processing and similarity comparisons. This skill bridges file parsing and the matchms object model, ensuring spectral data is represented in a canonical, queryable form.1213## When to use1415After successfully parsing raw spectral data from one of the supported file formats (mzML, mzXML, msp, metabolomics-USI, MGF, JSON) into intermediate dictionaries containing m/z arrays, intensity arrays, and metadata key-value pairs. Use this skill immediately before passing spectra to processing pipelines, cleaning workflows, or similarity comparison routines.1617## When NOT to use1819- If spectral data has not yet been parsed into intermediate dictionaries—use format-specific parsers first.20- If the input m/z and intensity arrays have mismatched lengths or contain non-numeric values—validate and clean the parsed data before instantiation.21- If you are working directly with a native matchms import function (e.g., from_msp, from_mzml) that handles both parsing and instantiation in one step.2223## Inputs2425- Parsed spectral data dictionary (containing m/z array, intensity array, metadata key-value pairs)26- File format identifier (mzML, mzXML, msp, metabolomics-USI, MGF, or JSON)27- Intermediate data structure from format-specific parser2829## Outputs3031- matchms Spectrum object(s)32- Collection of instantiated Spectrum objects ready for downstream processing3334## How to apply3536Create Spectrum objects by populating required fields (m/z arrays, intensity arrays, metadata) from the parsed intermediate data dictionary. Each Spectrum instance should have validated m/z and intensity arrays of matching length, and metadata fields that conform to matchms standards. Ensure the instantiated objects are compatible with downstream processing by verifying they expose the expected attributes (e.g., m/z, intensities, metadata dict) before passing them to cleaning, filtering, or comparison workflows. Use pytest to write unit tests that verify spectrum objects from each supported format retain their original m/z, intensity, and metadata values without loss or corruption.3738## Related tools3940- **matchms** (Python library providing the Spectrum class definition and object instantiation interface) — https://github.com/matchms/matchms41- **pytest** (Testing framework for writing unit tests that verify Spectrum objects are correctly instantiated with expected m/z, intensity, and metadata attributes)42- **Python** (Programming language for implementing format-specific parsers and Spectrum instantiation logic)4344## Evaluation signals4546- Instantiated Spectrum objects expose the required attributes: m/z array, intensity array, and metadata dictionary.47- m/z and intensity arrays are of equal length and contain numeric types (float or int).48- Metadata fields match the original values from the parsed intermediate dictionary (no silent omission or corruption).49- Unit test suite using pytest passes for each supported format, confirming round-trip fidelity (parse → instantiate → verify).50- Instantiated Spectrum objects integrate without errors into downstream matchms workflows (processing, filtering, similarity scoring).5152## Limitations5354- matchms supports only six file formats (mzML, mzXML, msp, metabolomics-USI, MGF, JSON); spectra from other formats require custom parsing before instantiation.55- Spectrum instantiation does not perform metadata cleaning or validation; raw metadata from parsed data is preserved as-is—use dedicated metadata cleaning steps afterward if needed.56- Large-scale instantiation of many Spectrum objects may require attention to memory usage, particularly when holding entire spectral libraries in memory before writing to persistent storage.57- The Spectrum object model assumes standard mass spectrometry attributes (m/z, intensity, precursor m/z, etc.); non-standard or missing fields must be handled by the parser before instantiation.5859## Evidence6061- [other] Instantiate matchms spectrum objects from the parsed data, populating required fields (m/z arrays, intensity arrays, metadata).: "Instantiate matchms spectrum objects from the parsed data, populating required fields (m/z arrays, intensity arrays, metadata)"62- [readme] transforming raw data from common mass spectra file formats into pre- and post-processed spectral data: "transforming raw data from common mass spectra file formats into pre- and post-processed spectral data"63- [other] Write unit tests using pytest to verify that spectra from each format are correctly imported with expected m/z, intensity, and metadata attributes.: "Write unit tests using pytest to verify that spectra from each format are correctly imported with expected m/z, intensity, and metadata attributes"64- [other] Validate that imported spectrum objects are compatible with downstream processing and comparison workflows in matchms.: "Validate that imported spectrum objects are compatible with downstream processing and comparison workflows in matchms"65- [other] Implement format-specific parsers for each file type, each extracting spectral peaks, metadata, and intensity values into intermediate data dictionaries.: "Implement format-specific parsers for each file type, each extracting spectral peaks, metadata, and intensity values into intermediate data dictionaries"