Getting started

Install from PyPI:

python -m pip install UniDecImporter

The factory accepts strings and path-like objects:

from pathlib import Path
from UniDecImporter import get_importer

with get_importer(Path("sample.mzML")) as reader:
    first_scan = reader.get_single_scan(reader.scans[0])
    average = reader.get_avg_scan(scan_range=(reader.scans[0], reader.scans[9]))
    print(reader.get_polarity(), average.shape)

Every ordinary spectrum is an N x 2 NumPy array. CD-MS events are N x 5, and ion-mobility data are N x 3. Scan ranges are inclusive.

Single-scan text files may begin with arbitrary header rows. TXT and DAT use whitespace, CSV uses commas, and TSV uses tabs. XLSX files read m/z and intensity from the active worksheet's first two columns and may have one header row. NPZ files must contain an array named data. Standard numeric NPZ files load without pickle support; legacy object-backed NPZ files are supported with a warning and must only be loaded from trusted sources. BIN files are interleaved float64 m/z and intensity pairs.

Use the capability attributes before specialized operations:

if reader.chrom_support:
    tic = reader.get_tic()
if reader.cdms_support:
    events = reader.get_cdms_data()
if reader.imms_support:
    mobility = reader.get_imms_avg_scan(mzbins=1)