Skip to content

Repository files navigation

mzdata

NPM version build status npm download

Read and explore xml files used to encode mass spectra.

This includes:

  • mzData
  • mzML
  • mzXML

Installation

$ 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.

Usage

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);
// 3

parseMZ 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.

Options

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.

imzML

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);

History of formats

https://dx.doi.org/10.1074/mcp.R110.000133

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.

mzml

cv = Controlled Vocabulary

Ontology

Ontology

More examples

You can find various examples files at:

http://www.psidev.info/mzML

License

MIT

About

Read and explore mzData files.

Topics

Resources

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages