Skip to content

[FEATURE] ThermoRawFile: faster reading, scan selection and PeakFileOptions pushdown (bridge 1.0.0) - #10541

Merged
jpfeuffer merged 10 commits into
developfrom
jpfeuffer-thermo-raw-reader-speed
Oct 13, 2026
Merged

jpfeuffer merged 10 commits into
developfrom
jpfeuffer-thermo-raw-reader-speed

Conversation

@jpfeuffer

@jpfeuffer jpfeuffer commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

PR 1 of 3 for #10522 (Thermo RAW reader speed). Follow-ups: (2) streaming transform() / FileConverter -process_lowmemory / OpenSWATH, (3) random access + ISpectrumAccess + pyOpenMS. Both reuse the per-scan core added here.

Changes

  • Internal::ThermoRawScanReader (new, private, pimpl): reusable conversion of one vendor scan into an MSSpectrum. header(scan) must be called for every scan in acquisition order, because precursors are reconstructed sequentially. convert() turns that scan into an MSSpectrum. If the parent MS1 of an MSn scan was not loaded (MS1 filtered out, metadata-only), the reader decodes it on demand for the precursor-intensity estimate, so MS2 output is identical to an unfiltered load. ThermoRawFile::load is now a thin loop over this reader.

  • ThermoRawFileMetadata: a per-file trailer label→index map replaces the linear string scans, std::from_chars replaces locale-imbued istringstream, and filter strings and SPS labels are parsed without a std::regex per scan.

  • ThermoRawFile:

    • no JSON DOM per scan;
    • trailer JSON is built only when preserve_trailers is set, and without a DOM;
    • the TIC comes from the per-scan headers instead of a second managed pass;
    • MSSpectrum is filled directly, with no per-spectrum sort (the bridge returns m/z-sorted peaks);
    • the final sortSpectra runs only if RTs are not monotone, e.g. PDA spectra interleaved with all_detectors.
  • Read-ahead on worker threads: with more than one OpenMP thread, up to 3 workers read scans ahead while the calling thread converts them; output is unchanged (see below).

  • New ThermoRawFile::Options: first_scan/last_scan, rt_min/rt_max, ms_levels, precursor_mz_min/precursor_mz_max, metadata_only, skip_chromatograms. No peaks are read for skipped scans or with metadata_only.

  • Checksum: FileHandler::loadExperiment no longer asks the bridge for a SHA-1; it computes its own when compute_hash is set. FileConverter gets the opt-in -raw_checksum flag, which writes the SHA-1 into the mzML provenance.

  • FileHandler pushdown: PeakFileOptions for MS levels, RT range, precursor m/z range, metadata-only and skip chromatograms are mapped into ThermoRawFile::Options. applyPostLoadOptions_ only applies the options that are not pushed down (m/z range, intensity range). MS2-only tools such as SimpleSearchEngine and ProSE therefore no longer decode MS1 peaks.

  • openms-thermo-bridge 1.0.0 API:

    • typed ScanHeader plus per-file trailer layout;
    • single-pass, m/z-sorted peak read;
    • header and peaks fetched in one call for scans that will be converted;
    • SHA-1 via an explicit file_sha1() call.

    Pins updated in cmake/cmake_findExternalLibs.cmake, vcpkg-overlays/ports/openms-thermo-bridge and tools/ci/fetch_thermo_assets.sh.

  • pyOpenMS bindings for the new options; tests in ThermoRawFile_test, ThermoRawFileMetadata_test, FileHandler_test (pushdown) and test_ThermoRawFile.py; doc/thermo_raw_mzml.md and CHANGELOG.

Bridge pin

The bridge is pinned to the v1.0.0 release, commit 75849ec, the merge of OpenMS/openms-thermo-bridge#13. fetch_thermo_assets.sh verifies the pre-built managed assets for all four platforms (linux-x64, linux-arm64, osx-arm64, win-x64) against their SHA-256. The linux-arm64 zip was added to the v1.0.0 release by OpenMS/openms-thermo-bridge#15.

Parity

Checked with a dump tool written for this PR; it is not committed. Per spectrum it records native id, RT, MS level, peak count, a hash of m/z and intensity, data arrays, all meta values (recursively including precursors, activation, scan windows and acquisitions), plus chromatograms and run metadata.

Every change was verified against a develop baseline on all datasets and in these configurations:

  • ThermoRawFile defaults
  • without checksum
  • FileHandler default
  • MS2-only
  • metadata-only
  • RT range
  • FileConverter

Filtered loads were compared against the unfiltered baseline with the same filter applied after loading. The output is identical except for the intentional differences below.

Intentional differences

  • The SHA-1 is no longer computed by FileHandler, nor by FileConverter by default. Use -raw_checksum to get it back; without it the mzML has an empty SHA-1 cvParam.
  • skip_chromatograms is now honoured for .raw files; it was ignored before.
  • The TIC is built from the scan headers. A non-finite vendor TIC becomes NaN, as before.
  • metadata_only reads no peaks, so there is no precursor intensity estimate and no lowest/highest observed m/z, and the base peak comes from the vendor scan statistics.
  • Instrument configuration ids are stable regardless of which scans are selected.
  • The position of the "Thermo RawFileReader version" userParam changed.
  • With noise_data, scans without a centroid stream (ion trap scans) no longer get a "sampled noise m/z array" without intensity or baseline arrays. The vendor returned the segmented scan masses there, not noise samples. This affects 6,949 ITMS scans in the SPS-MS3 file; FTMS noise arrays are unchanged. The change comes from bridge v1.0.0.

Benchmark

Setup: macOS arm64 (M-series, 12 cores), .NET 8 arm64, Release build. Each value is the median of 3 runs; RSS is the peak resident set size. Before = develop with bridge 0.3.1; after = this PR with bridge 1.0.0, using the default OpenMP thread count. FileHandler and ThermoRawFile rows are library loads; FileConverter runs with its default -threads 1.

Dataset Config Before After Speedup RSS before → after
HeLa QE-HF, PXD042233 (97k scans) FileHandler default 28.76 s 2.32 s 12.4× 2942 → 2339 MB
MS2 only 29.37 s 2.74 s 10.7× 2947 → 1832 MB
metadata only 29.05 s 1.60 s 18.2× 2941 → 806 MB
RT range 28.53 s 0.81 s 35.2× 2945 → 307 MB
FileConverter → mzML 33.24 s 8.58 s 3.9× 2944 → 2313 MB
ThermoRawFile defaults (profile, SHA-1) 32.17 s 7.97 s 4.0× 9051 → 9157 MB
TMT Lumos, PXD007683 FileHandler default 16.79 s 2.42 s 6.9× 1824 → 1831 MB
MS2 only 17.01 s 3.06 s 5.6× 1823 → 1509 MB
FileConverter 19.73 s 7.76 s 2.5×
TMT SPS-MS3, PXD014552 FileHandler default 6.17 s 1.15 s 5.4× 797 → 684 MB
MS2 only 6.15 s 1.14 s 5.4× 796 → 509 MB
FileConverter 7.46 s 2.77 s 2.7×
FAIMS-DIA fixture, PXD029902 FileHandler default 11.44 s 1.57 s 7.3× 790 → 782 MB
RT range 11.50 s 0.85 s 13.5× 793 → 228 MB
FileConverter 14.87 s 5.93 s 2.5×
Angiotensin_AllScans FileHandler default 0.84 s 0.34 s 2.5×

In the FileConverter rows, mzML writing is now the larger share of the time. FileConverter with -threads 4 on HeLa takes 6.9 s instead of 8.4 s.

Read-ahead on worker threads

With more than one OpenMP thread (TOPP -threads), up to three worker threads read the following scans on their own bridge accessors (thread_accessor), in chunks of 128 scans with a bounded window. Each scan is read in a single call: header, trailer text, and peaks when they are needed. The calling thread keeps parsing precursors sequentially and converting in acquisition order, so vendor decoding overlaps with conversion. Inside an enclosing OpenMP parallel region, or with one thread, the reader stays sequential.

HeLa FileHandler default with different thread counts:

OpenMP threads Load time
1 3.5 s
2 2.9 s
4 2.2 s
8 2.2 s
12 2.2 s

Compared with sequential reading, this is a further 1.3–1.8× on library loads. Peak RSS is unchanged except SPS-MS3 in profile mode, which uses about 230 MB more for the look-ahead buffer. Output is identical for every thread count: parity dumps match, and a new class test compares 1 thread vs 4 threads, including early stop and header-only scans.

The bridge's own reading alone scales poorly beyond 3 accessors (2.55 s with 1 thread, 1.90 s with 3, 2.40 s with 8), hence the cap. Batch read_scans gave no gain over per-scan reads.

Not adopted: typed trailer values

Typed values would make the header read about 0.6 s faster on HeLa, but they are not equivalent to the vendor-formatted text that OpenMS parses today. The text is rounded to display precision; typed values carry full precision or float32 noise, for example:

Trailer Text Typed
Monoisotopic M/Z 339.4829 339.48285882
Ion Injection Time 120.000 119.99999732
SPS Mass 1 402.0930 402.09301758

Adopting them would change precursor m/z, SPS masses and injection times in the output. With preserve_trailers on (the default), the text is read anyway for the trailer meta value. This is left for a separate decision.

Testing

  • Locally: ThermoRaw* class tests, FileHandler_test, TOPP_FileConverter_RAW* and TOPPWRITEINI_FileConverter pass.
  • pyOpenMS test_ThermoRawFile.py passes, including the new tests. The wheel-only bundle-layout check is not applicable in-tree.
  • Parity dumps are identical on 5 datasets × 12 configurations, including with read-ahead.

Summary by CodeRabbit

  • New Features

    • Thermo RAW loading supports filtering by scan number, retention time, MS level, and precursor m/z.
    • Metadata-only loading and optional chromatogram skipping are available. Scan read-ahead can use multiple threads while preserving results.
    • Vendor-sampled noise and baseline arrays can be included in mzML output when available.
    • FileConverter can record a Thermo RAW file’s SHA-1 checksum with -raw_checksum.
  • Changes

    • Thermo RAW files no longer receive a SHA-1 checksum by default. Recording one requires an additional file read.
    • Thermo RAW support requires OpenMS Thermo Bridge version 1.0.0 or newer.

jpfeuffer and others added 4 commits October 12, 2026 17:32
…gex-free filter parsing

Trailer values are looked up via a per-file label->index map instead of linear
string scans; numbers are parsed with std::from_chars instead of locale-imbued
istringstreams; scan filters are parsed without a per-scan std::regex (#10522).

Co-authored-by: Copilot App <[email protected]>
…leHandler pushdown

- Per-scan conversion moved into the reusable Internal::ThermoRawScanReader
  (header()/convert()), for later streaming and random-access readers.
- ThermoRawFile::Options: scan number, RT, MS level and precursor m/z
  selection, metadata_only and skip_chromatograms. Unselected scans are not
  decoded; selected MSn scans keep the precursors (incl. the intensity
  estimate from the parent scan) of a full load.
- TIC built from scan headers; trailer JSON only with preserve_trailers;
  no per-scan sort or final sortSpectra when acquisition order holds.
- Instrument configuration ids are independent of the scan selection.
- FileHandler::loadExperiment passes PeakFileOptions (MS levels, RT/precursor
  ranges, metadata-only, fill-data, skip-chromatograms) to the reader and does
  not compute the SHA-1. FileConverter computes it only with -raw_checksum.
- Tests, pyOpenMS bindings, docs and CHANGELOG.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
…d scan API

Scan headers come from the fixed-layout ScanHeader with trailer text paired
with the per-file trailer layout instead of a JSON document per scan. Header
and peaks of a scan that will be converted are read in one call, peaks
arrive m/z-sorted (no per-spectrum sort), SHA-1 is computed by an explicit
call only when requested, and the preserved trailer JSON is built without a
JSON DOM. Output is unchanged.

The bridge is pinned to the v1.0.0 branch commit (FetchContent, vcpkg
overlay, CI asset script) until the v1.0.0 tag is released.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
With more than one OpenMP thread, up to three worker threads read the
following scans (header, trailer text and, when needed, peaks) on their own
bridge accessors in chunks while the calling thread parses precursors and
converts in acquisition order. A bounded window limits the buffered scans;
worker errors are rethrown in order. Output does not depend on the thread
count (verified by parity dumps and a class test).

HeLa (97k scans) FileHandler load: 4.1 s -> 2.3 s.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
jpfeuffer and others added 4 commits October 13, 2026 13:05
Source-compatible: inline ScanHeader trailer lookups, static Catch2 in shared
builds, and noise triplets that are complete or empty. Scans without a centroid
stream (ion trap) therefore no longer get a noise m/z array without
intensities when noise_data is set; documented in the CHANGELOG.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
The v1.0.0 tag points at the merge of OpenMS/openms-thermo-bridge#13, whose tree
equals the previously pinned e6f0f97. FetchContent, the vcpkg overlay port and
fetch_thermo_assets.sh move to it.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
…assets

The v1.0.0 release publishes linux-x64, osx-arm64 and win-x64 zips; linux-arm64
keeps building the managed assemblies with the .NET SDK, as for v0.3.1.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
…aged zip

The v1.0.0 release now also publishes a linux-arm64 zip (built natively on an
arm64 runner, OpenMS/openms-thermo-bridge#15), so all four platforms download
and verify the same pre-built managed assemblies.

Part of #10522

Co-authored-by: Copilot App <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e3e5fa55-34c3-4144-9dec-d2631fd02f99
📥 Commits

Reviewing files that changed from the base of the PR and between 97194ca and fc4c9ea.

📒 Files selected for processing (5)
  • doc/thermo_raw_mzml.md
  • src/tests/class_tests/openms/source/MzMLFile_test.cpp
  • src/tests/class_tests/openms/source/ThermoRawFile_test.cpp
  • src/tests/topp/CMakeLists.txt
  • src/topp/FileConverter.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/topp/FileConverter.cpp
  • doc/thermo_raw_mzml.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Thermo RAW loading now uses OpenMSThermoBridge 1.0.0 through a typed scan reader. The reader supports scan selection, metadata-only loading, chromatogram controls, and bounded read-ahead. FileConverter can optionally record the RAW file’s SHA-1 checksum.

Changes: Thermo RAW reading

Layer / File(s) Summary
Bridge version and managed assets
cmake/cmake_findExternalLibs.cmake, tools/ci/fetch_thermo_assets.sh, vcpkg-overlays/ports/openms-thermo-bridge/*, CHANGELOG
Build and asset configuration now uses OpenMSThermoBridge 1.0.0 and updated release asset digests. The changelog identifies the 1.0.0 bridge requirement.
Trailer metadata parsing
src/openms/include/OpenMS/FORMAT/HANDLERS/ThermoRawFileMetadata.h, src/openms/source/FORMAT/HANDLERS/ThermoRawFileMetadata.cpp, src/tests/class_tests/openms/source/ThermoRawFileMetadata_test.cpp
Trailer labels use cached positions with fallback lookup. Numeric, filter-key, and SPS-label parsing use explicit string-view processing. Tests cover parsing and trailer-order changes.
Typed scan reader
src/openms/include/OpenMS/FORMAT/HANDLERS/ThermoRawScanReader.h, src/openms/source/FORMAT/HANDLERS/ThermoRawScanReader.cpp, src/openms/{include,source}/FORMAT/HANDLERS/sources.cmake, doc/thermo_raw_mzml.md, CHANGELOG
A new reader converts typed bridge scan data into OpenMS metadata and spectra. It supports ordered scan reads, bounded read-ahead, and TIC, detector, and PDA data conversion.
Loading options and integration
src/openms/include/OpenMS/FORMAT/ThermoRawFile.h, src/openms/source/FORMAT/ThermoRawFile.cpp, src/openms/{include,source}/FORMAT/FileHandler.*, src/pyOpenMS/bindings/bind_format.cpp, src/topp/FileConverter.cpp, CHANGELOG
ThermoRawFile supports scan-number, retention-time, MS-level, and precursor-m/z selection, metadata-only loading, and chromatogram skipping. FileHandler forwards applicable options. FileConverter records RAW SHA-1 only when -raw_checksum is enabled.
Behavior validation and documentation
src/tests/class_tests/openms/source/ThermoRawFile_test.cpp, src/pyOpenMS/tests/unittests/test_ThermoRawFile.py, src/tests/class_tests/openms/source/MzMLFile_test.cpp, src/tests/topp/CMakeLists.txt, doc/thermo_raw_mzml.md
Tests cover selection, read-ahead, option forwarding, sampled-noise array round-tripping, and checksum behavior. Documentation describes scan options, checksum recording, and noise-array handling.

Sequence Diagram(s)

sequenceDiagram
  participant FileHandler
  participant ThermoRawFile
  participant ThermoRawScanReader
  participant thermo_bridge
  FileHandler->>ThermoRawFile: Forward scan and loading options
  ThermoRawFile->>ThermoRawScanReader: Request selected scan headers and conversion
  ThermoRawScanReader->>thermo_bridge: Read typed scan data
  thermo_bridge-->>ThermoRawScanReader: Return scan metadata and data
  ThermoRawScanReader-->>ThermoRawFile: Provide converted scans
Loading

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to fc4c9

No merge-blocking issue is established by the supplied evidence; the PR is mergeable after normal checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 32.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 75 functions across 15 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main changes: faster ThermoRawFile reading, scan selection, PeakFileOptions pushdown, and the bridge 1.0.0 update.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 32.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 75 functions across 15 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads scans by the light of the moon
With peaks tucked away till the right afternoon
Three workers hop forward, then pass data along
Noise arrays return where the mzML grows strong
A checksum waits till its flag says to start
Then down the burrow goes one happy heart

Comment @coderabbitai help to get the list of available commands.

Cover all three noise arrays in RAW and mzML round trips, preserve double precision and independent grids under peak filtering, and exercise FileConverter include_noise. Clarify the existing opt-in export and distinguish vendor noise from calculated reporter S/N.

Co-authored-by: Copilot App <[email protected]>

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed fc4c9ea as the first PR in the stack #10541 → #10544 → #10547, including scan selection, precursor reconstruction, read-ahead, PeakFileOptions pushdown and the affected callers.

No blocking issue found in this PR. LGTM, pending successful CI. The findings on streaming and random access belong to the follow-up PRs and do not block merging this one independently.

At review time, the Linux GCC/Clang build-and-test checks, header-set compatibility and documentation checks have passed. Other platform and wheel checks are still running or queued, so this approval is not a claim that all checks have passed.

Validation: source review and inspection of the current CI results; no full OpenMS build or real-RAW integration tests were run locally.

@jpfeuffer
jpfeuffer merged commit 0d6cfdd into develop Oct 13, 2026
33 checks passed
@jpfeuffer
jpfeuffer deleted the jpfeuffer-thermo-raw-reader-speed branch October 13, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants