Skip to main content

quantion-py

Python wrappers for the quantion Rust library for LC-MS data processing.

Install

pip install git+https://github.com/phenological/quantion#subdirectory=wrappers/python

The install downloads the native library for your platform from the GitHub release that matches the package version.

Concepts

Sample: A parsed mzML or ion file held in memory. Create samples with parse_mzml() or parse_ion(). Use as a context manager (with) to ensure automatic cleanup.

XY data: A pair of numeric sequences where x is retention time and y is intensity.

Quick start

Load a file and extract peaks in a few lines:

import quantion

raw = open("sample.mzML", "rb").read()

with quantion.parse_mzml(raw) as sample:
    eic   = quantion.calculate_eic(sample, target_mz=174.112, from_to={"from": 1, "to": 15})
    peaks = quantion.find_peaks(eic["x"], eic["y"], options={"auto_noise": True, "min_snr": 3.0})
    for p in peaks:
        print(f"rt={p['rt']:.3f}  intensity={p['intensity']:.0f}")

The library loads automatically on import. No initialization call needed.

Load files

Load mzML

Load an mzML file into a sample.

sample = quantion.parse_mzml(bytes)

Load ion

Load an ion binary file into a sample.

sample = quantion.parse_ion(bytes)

Convert

Sample to JSON

Get JSON from a sample.

json = quantion.ion_to_json(sample)

Sample to mzML

Get mzML text from a sample.

mzml = quantion.ion_to_mzml(sample)

Sample to ion

Convert a sample to compressed ion bytes.

ion_bytes = quantion.mzml_to_ion(sample, level=5, f32_compress=False)

Sample instance methods

Convert using sample methods.

with quantion.parse_mzml(data) as sample:
    json = sample.to_json()
    mzml = sample.to_mzml()
    ion_bytes = sample.to_ion(level=12)
    sample.dispose()

Extract from samples

Extract EIC

Get an extracted ion chromatogram for one m/z from a sample.

eic = quantion.calculate_eic(sample, target_mz=174.112, from_to={"from": 1, "to": 15}, ppm_tol=20.0, mz_tol=0.005)

Get scans

Get scans from a sample by retention time range and MS level.

scans = quantion.get_scans(sample, rt_range=(1, 15), level=1)

Process XY data

Calculate baseline

Estimate a baseline for XY data.

baseline = quantion.calculate_baseline(y, lambda_=0, max_iterations=0)

Find noise level

Estimate the noise level in XY data. The result has width, the number of points the estimate came from, and intensity, the noise level itself.

noise = quantion.find_noise_level(y)["intensity"]

Find peaks

Find all peaks in XY data.

peaks = quantion.find_peaks(x, y, options={"auto_noise": True, "min_snr": 3.0})

Get single peak

Find one peak near a target retention time in XY data.

peak = quantion.get_peak(x, y, rt=5.3, range=0.6, options={"auto_noise": True})

Predict retention times

Load an ONNX model from a path, a URL, or bytes, read the keys and values stored in it, and make a warp model from it. The model stays usable after load_warp, and the warp keeps working if the model is disposed.

model = quantion.load_model("model.onnx")
model.get_keys()                  # ["points", "time_from", ..., "targets"]
model.get_value("points")         # "1024"

warp = quantion.load_warp(model)
warp.get_value("targets")         # the warp has the same keys and values

Predict each target's retention time in a sample. You get one {"rt", "uncertainty"} per target, in the same order.

targets = [{"id": "feature_1", "mz": 300.1, "rt": 2.38}]
rts = warp.predict_rts(sample, targets)

Without reference RTs, calibrate from anchor samples such as LTRs or QCs: give the samples and, for each one, the targets seen in it. Each target gets the median calibrated RT over the samples where it was seen. One sample works, three are better, five or more are best. Each RT must be the one measured in that anchor sample: a generic target list runs without error but gives wrong RTs.

anchor_samples = [ltr_1, ltr_2, ltr_3]
target_lists = [seen_in_ltr_1, seen_in_ltr_2, seen_in_ltr_3]
calibrated = warp.calibrate(anchor_samples, target_lists)
rts = warp.predict_rts(other_sample, calibrated)

warp.dispose()
model.dispose()

Find peaks from samples

From EICs

Find peaks for many targets using extracted ion chromatograms from a sample.

targets = [
    {"rt": 5.3, "mz": 174.112, "range": 0.5, "id": "compound_A"},
    {"rt": 7.1, "mz": 203.156, "range": 0.5, "id": "compound_B"},
]

peaks = quantion.get_peaks_from_eic(
    sample, targets,
    from_to={"from": 0.5, "to": 10.0},
    options={"auto_noise": True},
    cores=2
)

From chromatograms

Find peaks from stored chromatograms in a sample.

items = [
    {"idx": 0, "rt": 5.3, "window": 0.5},
    {"idx": 5, "rt": 7.1, "window": 0.5},
]

peaks = quantion.get_peaks_from_chrom(sample, items, options=None, cores=2)

Untargeted

Targeted feature detection

Find targeted features by m/z and retention time from a sample.

targets = [
    {"rt": 5.3, "mz": 174.112, "range": 0.5, "id": "A"},
    {"rt": 7.1, "mz": 203.156, "range": 0.5, "id": "B"},
]

features = quantion.find_feature(
    sample, targets,
    scan_eic={"ppm_tolerance": 10, "mz_tolerance": 0.003},
    eic={"ppm_tolerance": 20, "mz_tolerance": 0.005},
    options={"auto_noise": True},
    cores=2,
)

From single sample

Find all features in a sample.

features = quantion.find_features(
    sample,
    from_to={"from": 1, "to": 15},
    eic={"ppm_tolerance": 10, "mz_tolerance": 0.005},
    grid={"start": 40, "end": 1000, "step_size": 0.005},
    options={"auto_noise": True, "min_snr": 3},
    cores=4,
)

Align features across samples

Find and align features across many samples.

features = quantion.get_features(
    "/path/to/ion/dir",
    from_to={"from": 0, "to": 20},
    eic={"ppm_tolerance": 5},
    grid={"start": 50, "end": 1000, "step_size": 0.01},
    grouping={"ppm_tolerance": 5, "rt_tolerance": 0.05, "frequency": 2},
    cores=8,
)

Peak detection options

Pass peak detection options as a dictionary:

options = {
    "min_integral":        0.0,
    "min_intensity":       150.0,
    "min_peak_width_points": 5,
    "noise":               float("nan"),
    "auto_noise":          True,
    "auto_baseline":       True,
    "lambda_":             0,
    "max_iterations":      0,
    "allow_overlap":       False,
    "min_snr":             3.0,
}

Metadata

Release files for quantion 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for quantion 0.1.6
File Actions
quantion-0.1.6-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for quantion-0.1.6-py3-none-win_amd64.whl
quantion-0.1.6-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details for quantion-0.1.6-py3-none-manylinux_2_34_x86_64.whl
quantion-0.1.6-py3-none-manylinux_2_34_aarch64.whl Python 3 none Linux glibc 2.34+ ARM64 Details for quantion-0.1.6-py3-none-manylinux_2_34_aarch64.whl
quantion-0.1.6-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for quantion-0.1.6-py3-none-macosx_11_0_arm64.whl
quantion-0.1.6-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for quantion-0.1.6-py3-none-macosx_10_12_x86_64.whl

Total release size: 6.5 MB

Release files / quantion-0.1.6-py3-none-win_amd64.whl

Download URL quantion-0.1.6-py3-none-win_amd64.whl
Size 1.3 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
2340a4b06e4c6a422376944716ef7dd0ebb312bec7f551cab2f751527e8e3683
BLAKE2b-256 checksum
How to use checksums
188756b99a8a5e27ad46b04cc9254bb9fb29794bca1fd498fb4d0fed352b68c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / quantion-0.1.6-py3-none-manylinux_2_34_x86_64.whl

Download URL quantion-0.1.6-py3-none-manylinux_2_34_x86_64.whl
Size 1.4 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
720e3d291f231c4033ce57c936a07e90913cc8ea69c7942e22801a82831b10c9
BLAKE2b-256 checksum
How to use checksums
f94b6770c29b64b2ccccde4f7ff22dc568ae2b7bb5d8d3dc1bc08243bfdab2a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / quantion-0.1.6-py3-none-manylinux_2_34_aarch64.whl

Download URL quantion-0.1.6-py3-none-manylinux_2_34_aarch64.whl
Size 1.2 MB
Tags Linux glibc 2.34+ ARM64 Python 3
SHA-256 checksum
How to use checksums
ccd79a07e3478759159bee2071321e36998bef4785ddc7ab83e9f86ea3fcc005
BLAKE2b-256 checksum
How to use checksums
098fb0eac705250552170920c26061a288938b9d47e2459bd226f6643756cceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / quantion-0.1.6-py3-none-macosx_11_0_arm64.whl

Download URL quantion-0.1.6-py3-none-macosx_11_0_arm64.whl
Size 1.2 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1b7a079701a52ab7e8f9ad259adb305a86b1401ce5685865621080d6e719c872
BLAKE2b-256 checksum
How to use checksums
489bf1374e907d71732cbdf9d736c188356855bdd5d5ba9f7cdbe199cc750ab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / quantion-0.1.6-py3-none-macosx_10_12_x86_64.whl

Download URL quantion-0.1.6-py3-none-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c2a4f356b00e110b987753f6a45602333c77b0146781e5c28450abf2b3e0a95e
BLAKE2b-256 checksum
How to use checksums
f4a7cc2e2e3e1815a85fa595e3d8422dca7c644eea62c9170c1eb9d8eba38cc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for quantion 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.6 This release

5 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page