Skip to main content

tdfextractor

Python Package PyPI License Python

Converts Bruker timsTOF .d folders into MS2, MGF, or mzML files that downstream search engines and de novo sequencing tools already know how to read. It's built on tdfpy for the raw PASEF data access, so you get filtering, precursor handling, and batch processing without writing any Bruker SDK code yourself.

Highlights

  • Three output formats — MS2 (MS-GF+, Comet), MGF (general-purpose, Casanovo-tuned), and mzML (includes MS1 and MS2 PASEF spectra with configurable compression/encoding).
  • Built-in presets — --ip2 for IP2 search engine defaults, --casanovo for de novo sequencing defaults.
  • Extensive spectrum and precursor filtering — intensity, m/z, charge, retention time, CCS, and neutral mass thresholds, plus optional precursor peak removal and top-N peak trimming.
  • Batch processing — point at a directory of .d folders and process them with multiple --workers.
  • mzML centroiding and compression controls — choose noise filters, m/z/ion-mobility tolerances, and per-array compression (zlib, zstd, numpress-*).
  • Also usable as a library — write_ms2_file, write_mgf_file, and write_mzml_file take the same typed argument dataclasses as the CLI.

Installation

pip install tdfextractor

Usage

tdfextractor provides three command-line tools for extracting spectra:

MS2 Extraction

Extract MS2 format files (compatible with MS-GF+, Comet, etc.):

ms2-extractor /path/to/sample.d

# shorthand
ms2-ex 
ms2-ex /path/to/sample.d --output custom_output.ms2 --min-intensity 100 --min-charge 2
ms2-ex /path/to/directory_with_multiple_d_folders --output /path/to/output_directory

MGF Extraction

Extract MGF format files

mgf-extractor /path/to/sample.d

#shorthand
mgf-ex
mgf-ex /path/to/sample.d --casanovo  # Optimized for Casanovo de novo sequencing
mgf-ex /path/to/directory_with_multiple_d_folders --output /path/to/output_directory

mzML Extraction

Extract mzML format files (includes both MS1 and MS2 PASEF spectra):

mzml-extractor /path/to/sample.d

# shorthand
mzml-ex /path/to/sample.d
mzml-ex /path/to/sample.d --no-ms1  # MS2 spectra only
mzml-ex /path/to/sample.d --mz-compression zstd --intensity-encoding 32
mzml-ex /path/to/directory_with_multiple_d_folders --output /path/to/output_directory

Output Options

Both extractors support flexible output options:

  1. No output specified: Files are created within each .D folder with auto-generated names
  2. Specific file path: Use -o filename.ms2 or -o filename.mgf for single .D folder processing
  3. Output directory: Use -o /path/to/output_dir for batch processing multiple .D folders
  4. Overwrite protection: Use --overwrite to replace existing output files

Batch Processing

When processing multiple .D folders, the extractors will:

  • Automatically find all .D folders in the specified directory
  • Create output files with names matching the .D folder names
  • Skip existing files unless --overwrite is specified
  • Create the output directory if it doesn't exist

Command Line Arguments

Both MS2 and MGF extractors share the same arguments, with only a few format-specific options:

Argument Type Default Description
analysis_dir str - Path to the .D analysis directory or directory containing .D folders
-o, --output str <analysis_dir_name>.<ext> Output file path or directory
--remove-precursor flag False Remove precursor peaks from MS/MS spectra
--precursor-peak-width float 2.0 Width around precursor m/z to remove (Da)
--batch-size int 100 Batch size for processing spectra
--top-n-peaks int None Keep only top N most intense peaks per spectrum
--min-spectra-intensity float None Minimum intensity threshold for MS/MS peaks (absolute or 0.0-1.0 for percentage)
--max-spectra-intensity float None Maximum intensity threshold for MS/MS peaks (absolute or 0.0-1.0 for percentage)
--min-spectra-mz float None Minimum m/z filter for MS/MS peaks
--max-spectra-mz float None Maximum m/z filter for MS/MS peaks
--min-precursor-intensity float None Minimum precursor intensity filter
--max-precursor-intensity float None Maximum precursor intensity filter
--min-precursor-charge int None Minimum precursor charge state filter
--max-precursor-charge int None Maximum precursor charge state filter
--min-precursor-mz float None Minimum precursor m/z filter
--max-precursor-mz float None Maximum precursor m/z filter
--min-precursor-rt float None Minimum precursor retention time filter (seconds)
--max-precursor-rt float None Maximum precursor retention time filter (seconds)
--min-precursor-ccs float None Minimum precursor CCS filter
--max-precursor-ccs float None Maximum precursor CCS filter
--min-precursor-neutral-mass float None Minimum precursor neutral mass filter
--max-precursor-neutral-mass float None Maximum precursor neutral mass filter
--mz-precision int 5 Number of decimal places for m/z values
--intensity-precision int 0 Number of decimal places for intensity values
--keep-empty-spectra flag False Write empty spectra to output file
--overwrite flag False Overwrite existing output files
--workers int 1 Number of worker threads for processing multiple .d folders
-v, --verbose flag False Enable verbose logging

Format-Specific Arguments

MS2 Extractor Only:

  • --ip2: Use IP2 preset settings (sets min charge to 2, top 500 peaks)

MGF Extractor Only:

  • --casanovo: Use Casanovo preset settings (enables precursor removal, top-150 peaks, min intensity 0.01, m/z range 50-2500, min charge 2)

mzML Extractor Only:

Argument Type Default Description
--no-ms1 flag False Skip MS1 spectra; write only MS2 PASEF spectra
--mz-compression str zlib Compression for m/z arrays (none, zlib, zstd, numpress-linear, numpress-slof, numpress-pic)
--intensity-compression str zlib Compression for intensity arrays
--mobility-compression str zlib Compression for per-peak ion mobility arrays (MS1)
--mz-encoding int 64 Bit width for m/z values (32 or 64)
--intensity-encoding int 32 Bit width for intensity values (32 or 64)
--centroid-noise-filter str none Noise filter before centroiding (none, mad, percentile, histogram, baseline, iterative_median)
--centroid-mz-tolerance float 8.0 m/z tolerance for centroiding
--centroid-mz-tolerance-type str ppm Unit for m/z tolerance (ppm or da)
--centroid-im-tolerance float 0.05 Ion mobility tolerance for centroiding
--centroid-im-tolerance-type str relative Unit for ion mobility tolerance (relative or absolute)
--centroid-min-peaks int 5 Minimum raw peaks required to form a centroided MS1 peak
--centroid-ms2-min-peaks int 1 Minimum raw peaks required to form a centroided peak in DIA windows / PRM transitions

Performance Options

The --workers argument allows parallel processing of multiple .d folders:

# Process multiple .d folders with 4 worker threads
mgf-ex /path/to/directory_with_multiple_d_folders --workers 4

Note: Workers only affect processing when multiple .d folders are being processed simultaneously. Each worker processes one complete .d folder independently.

Python API

Every extractor is also importable as a function, driven by the same typed argument dataclass the CLI builds internally:

from tdfextractor import Ms2Args, write_ms2_file

args = Ms2Args(
    analysis_dir="/path/to/sample.d",
    output_file="sample.ms2",
    min_precursor_charge=2,
    top_n_peaks=500,
)
write_ms2_file(args)

MgfArgs and write_mgf_file / MzmlArgs and write_mzml_file follow the same pattern. BaseExtractorArgs documents the fields shared by all three.

License

MIT

Metadata

Release files for tdfextractor 0.4.2

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

Source distribution (sdist)

Source distribution for tdfextractor 0.4.2
File Size Uploaded
tdfextractor-0.4.2.tar.gz 36.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tdfextractor 0.4.2
File Interpreter ABI Platform
tdfextractor-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 69.0 kB

Release files / tdfextractor-0.4.2.tar.gz

Download URL tdfextractor-0.4.2.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5539b23937ecbf4cd239286fd9fd5c5110f849e5a46c94d7b496daa45e8f37da
BLAKE2b-256 checksum
How to use checksums
5ff714245e036614c302afa4b88f22f2b3f0fc270e8fa1fe0188d35e9bd4c7f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / tdfextractor-0.4.2-py3-none-any.whl

Download URL tdfextractor-0.4.2-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4302ef014b09eae59fbbdc98e9bf2bedb2bd35628b33fc1a5f4f50ba5b0fae95
BLAKE2b-256 checksum
How to use checksums
1afba0a470f43d3b1491003e9fa2e788a5b7c16e0af2d0e652d52a75391deff6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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