Read and explore xml files used to encode mass spectra.
This includes:
- mzData
- mzML
- mzXML
$ npm i mzdata
This package is ESM-only. CommonJS consumers can still require() it on Node.js
≥ 22.12 or any 24.x and later, or switch to import.
import { readFileSync } from 'node:fs';
import { parseMZ } from 'mzdata';
// works the same for mzData, mzML and mzXML files
const file = readFileSync('tiny.mzData.xml');
const result = await parseMZ(file);
console.log(Object.keys(result));
// ['metadata', 'times', 'series']
console.log(result.times);
// [5.8905, 5.944667, 10]
// one entry per spectrum, each a [mass, intensity] pair of Float64Array
console.log(result.series.ms.data.length);
// 3parseMZ accepts an ArrayBuffer, a Uint8Array (including Node.js Buffer)
or a string, detects the format from the file header, and throws
MZ parser: unknown format if it is none of mzData, mzML or mzXML.
| Option | Type | Default | Description |
|---|---|---|---|
logger |
Logger |
console |
A cheminfo-types logger, used to report decoding errors. |
rawData |
ArrayBuffer |
— | imzML only: the content of the companion .ibd file holding the binary spectra. |
An imzML file stores its spectra in a separate .ibd file, passed as rawData.
The result then also carries xPositions and yPositions, one entry per
spectrum:
const result = await parseMZ(imzML, { rawData: ibd });
console.log(result.xPositions.length, result.yPositions.length);https://dx.doi.org/10.1074/mcp.R110.000133
- mzData was developed by HUPO-PSI
- mzXML was developed at the Institute for Systems Biology
- mzML: new unified output format started in 2006
mzML - 4 goals:
- creation of a simple format
- elimination of alternate ways to encode the same information
- support for all the features of both mzXML and mzData
- validation through implementation prior to release.
cv = Controlled Vocabulary
You can find various examples files at:
