Skip to main content

Python package for parsing Bruker timsTOF data with centroiding and noise filtering

Project description

TDFpy Logo

A Python package for extracting data from Bruker timsTOF data files (.tdf and .tdf_bin). Includes a Numba-accelerated centroiding algorithm for efficient extraction of ion mobility data.

Python package codecov PyPI version Python 3.12+ License: MIT

Overview

tdfpy provides a high-level Python API for reading Bruker timsTOF .d folders. It handles DDA, DIA, and PRM acquisition modes and exposes familiar Python objects — no need to think about raw PASEF frames or SQLite queries.

  • DDA — iterate MS1 frames and precursors (MS2 spectra)
  • DIA — iterate MS1 frames and DIA isolation windows
  • Centroiding — Numba-accelerated peak merging across the m/z and ion mobility dimensions, returning (N, 3) arrays of [m/z, intensity, 1/K0]
  • Lazy spectral access — frame metadata is loaded upfront; raw peak data is only read when you call .peaks or .centroid()

Installation

pip install tdfpy

Requires Python 3.12+. The Bruker libtimsdata native library is bundled in the wheel (Linux).

Quick Start

from tdfpy import DDA, DIA, PRM

# DDA acquisition
with DDA("sample.d") as dda:
    for frame in dda.ms1:
        peaks = frame.centroid()  # shape (N, 3): [m/z, intensity, 1/K0]

    for precursor in dda.precursors:
        print(precursor.largest_peak_mz, precursor.charge)
        peaks = precursor.peaks  # centroided MS2 via Bruker's algorithm

# DIA acquisition
with DIA("sample.d") as dia:
    for frame in dia.ms1:
        peaks = frame.centroid()

    for window in dia.windows:
        print(window.isolation_mz, window.isolation_width)
        peaks = window.centroid()

# PRM acquisition
with PRM("sample.d") as prm:
    for target in prm.targets:
        print(target.monoisotopic_mz, target.charge)

    for transition in prm.transitions:
        print(transition.isolation_mz, transition.collision_energy)
        peaks = transition.peaks  # shape (N, 2): [m/z, intensity]

Lookups and Queries

Frames, precursors, and windows can be accessed by ID or queried by m/z and retention time:

with DDA("sample.d") as dda:
    frame = dda.ms1[1]           # by frame ID
    precursor = dda.precursors[1]  # by precursor ID

    # query by m/z and RT window
    hits = dda.precursors.query(
        mz=1292.63,
        mz_tolerance=20.0,   # ppm
        rt=2400.0,           # seconds
        rt_tolerance=30.0,
    )

Centroiding Options

frame.centroid() and window.centroid() accept parameters to control the peak merging:

peaks = frame.centroid(
    mz_tolerance=8,               # ppm (default)
    mz_tolerance_type="ppm",      # or "da"
    im_tolerance=0.05,            # relative (default)
    im_tolerance_type="relative", # or "absolute"
    min_peaks=3,                  # minimum raw peaks to form a centroid
    noise_filter="mad",           # optional: "mad", "percentile", "histogram", etc.
    ion_mobility_type="ook0",     # or "ccs" / "voltage"
)

You can also call merge_peaks directly on your own arrays:

from tdfpy import merge_peaks
import numpy as np

peaks = merge_peaks(mz_array, intensity_array, ion_mobility_array, mz_tolerance=10)

Documentation

Full documentation at tacular-omics.github.io/tdfpy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tdfpy-1.1.0.tar.gz (76.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tdfpy-1.1.0-py3-none-any.whl (5.8 MB view details)

Uploaded Python 3

File details

Details for the file tdfpy-1.1.0.tar.gz.

File metadata

  • Download URL: tdfpy-1.1.0.tar.gz
  • Upload date:
  • Size: 76.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tdfpy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 14cdc5087f1a0180362a15f636396a804614bf55dfc3c372d7264a9e27c3a455
MD5 55b300a4d8444041bb27e122359788f3
BLAKE2b-256 b5fb465388ce26bb6484cde0cc7122c7e3d553ff0a5c0f4604097fc64892dbea

See more details on using hashes here.

File details

Details for the file tdfpy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tdfpy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tdfpy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4a1bc80d74ae91a2bdd1c369f2d10380a50164078b6afcbec95e10a0ee739e9
MD5 fe4be68d573f2439266dffed679168f8
BLAKE2b-256 ccfa9d9e16dc6856dca3b9b71b67f241ae7c63b0dcd16f628ebbc029c4c69e27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page