Repository navigation
Add frame ID range filter to BrukerTimsFile - #9387
Conversation
Avoids loading the whole .d file when only a single frame or a range of frames is needed. Memory and I/O now scale with the requested range, not the file size. Honored by load(), transform(), loadDIAStreaming(), and readDIAMetadata() across AUTO/SPECTRUM/FRAME export modes: - MS1/MS2 frame collection loops in loadDDA_/loadDIA_/loadFrames_/ loadDIAStreaming skip out-of-range frames before peak extraction - readDIAMetadata's MS1 count and per-WindowGroup MS2 counts match what loadDIAStreaming will actually emit (CachedSwathFileConsumer sizes its buffers from these) - transform's expected-size computation uses range-aware SQL counts - DDA: precursor entries whose MS2 frame is out of range are dropped; a one-shot warning reports how many precursors become partial at the range boundary Interplay notes (also documented on the Config field): - Frame aggregation (ms1/dia_ms2_n_neighbors) clamps at the range boundaries the same way it clamps at file boundaries; widen the range by n_neighbors for unbiased aggregation throughout - Centroiding is per-frame, so unaffected beyond fewer frames - DDA OLS recalibration is fit from in-range precursors only
Lets callers request a retention-time range instead of (or in addition to) raw frame IDs. The RT range is resolved to a frame_id range at load time via SQL: SELECT MIN(Id), MAX(Id) FROM Frames WHERE Time IN [rt_min, rt_max] and intersected with frame_id_min/frame_id_max — so downstream code still only honors a single filter (frame_id), while users get two intuitive knobs. TIMS frame IDs are monotonic in acquisition time, so an RT range maps cleanly to a contiguous frame_id sub-range. Folded the previous warnInvalidFrameRange() helper into resolveEffectiveConfig(), which now: (a) validates both ranges, (b) resolves the RT range, (c) returns an effective Config that downstream loaders consume. All four public entry points (load, transform, loadDIAStreaming, readDIAMetadata) call it once and pass the effective Config to internal loaders. The DDA partial-precursor warning and all interplay caveats apply identically to either knob.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds inclusive frame ID range filtering (Config.frame_id_min/max) and resolution/validation; applies filtering across metadata counting, DIA/DDA loading, and FRAME export, with tests covering frame and RT range interactions. ChangesFrame ID range filtering
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp (1)
557-575: ⚡ Quick winAdd an explicit filtered
readDIAMetadata↔loadDIAStreamingcount-parity assertion.This block says the counts must match streaming output, but currently only checks
meta_subrelative tometa_full. Please assert exact equality against filtered streaming output too.Proposed test extension
ExperimentalSettings settings_sub; auto meta_sub = f.readDIAMetadata(OPENTIMS_DIA_TEST_DATA, settings_sub, cfg_dia_sub); TEST_EQUAL(meta_sub.nr_ms1_spectra <= meta_full.nr_ms1_spectra, true); TEST_EQUAL(meta_sub.nr_ms2_spectra.size(), meta_full.nr_ms2_spectra.size()); @@ TEST_EQUAL(any_smaller, true); + + // Filtered metadata counts must match filtered streaming emission counts. + RegularSwathFileConsumer consumer_sub(meta_sub.boundaries); + consumer_sub.setExperimentalSettings(settings_sub); + f.loadDIAStreaming(OPENTIMS_DIA_TEST_DATA, consumer_sub, cfg_dia_sub); + + std::vector<OpenSwath::SwathMap> maps_sub; + consumer_sub.retrieveSwathMaps(maps_sub); + Size ms2_idx = 0; + for (const auto& m : maps_sub) + { + if (m.ms1) + { + TEST_EQUAL(m.sptr->getNrSpectra(), static_cast<size_t>(meta_sub.nr_ms1_spectra)); + } + else + { + TEST_EQUAL(m.sptr->getNrSpectra(), static_cast<size_t>(meta_sub.nr_ms2_spectra[ms2_idx])); + ++ms2_idx; + } + } + TEST_EQUAL(ms2_idx, meta_sub.nr_ms2_spectra.size()); `#endif`As per coding guidelines, “Write unit tests for new functionality and ensure existing tests pass before suggesting changes.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp` around lines 557 - 575, Extend the test to assert parity between readDIAMetadata results and what loadDIAStreaming would emit when using the same filter: call loadDIAStreaming (or the streaming loader helper used in tests) with OPENTIMS_DIA_TEST_DATA and cfg_dia_sub, collect the per-window MS1/MS2 counts it produces, and add TEST_EQUAL assertions that those counts exactly equal meta_sub.nr_ms1_spectra and meta_sub.nr_ms2_spectra respectively (in addition to the existing comparisons against meta_full); reference the existing variables/functions meta_sub, meta_full, readDIAMetadata, loadDIAStreaming, and cfg_dia_sub so the new assertions are placed right after the meta_sub creation and the any_smaller loop.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp`:
- Around line 557-575: Extend the test to assert parity between readDIAMetadata
results and what loadDIAStreaming would emit when using the same filter: call
loadDIAStreaming (or the streaming loader helper used in tests) with
OPENTIMS_DIA_TEST_DATA and cfg_dia_sub, collect the per-window MS1/MS2 counts it
produces, and add TEST_EQUAL assertions that those counts exactly equal
meta_sub.nr_ms1_spectra and meta_sub.nr_ms2_spectra respectively (in addition to
the existing comparisons against meta_full); reference the existing
variables/functions meta_sub, meta_full, readDIAMetadata, loadDIAStreaming, and
cfg_dia_sub so the new assertions are placed right after the meta_sub creation
and the any_smaller loop.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0629811a-f978-4197-847b-138fcaee1dbe
📒 Files selected for processing (3)
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.hsrc/openms/source/FORMAT/BrukerTimsFile.cppsrc/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/source/FORMAT/BrukerTimsFile.cpp`:
- Around line 1907-1913: readDIAMetadata() currently counts all in-range MS1
frames into meta.nr_ms1_spectra regardless of the eff.load_ms1 setting; update
the counting so it honors eff.load_ms1 by skipping MS1 counting when
eff.load_ms1 is false (e.g., return/set meta.nr_ms1_spectra to 0 or skip
incrementation) — modify the loop that uses frameInRange(fid, eff),
handle->has_frame(fid) and handle->get_frame(fid).msms_type to only increment
meta.nr_ms1_spectra when eff.load_ms1 is true.
- Around line 780-796: The intersection code in BrukerTimsFile (around
q.executeStep()) may invert eff.frame_id_min/max silently when the explicit
frame_id_* range and the RT-derived range are each valid but disjoint; detect
this by saving the pre-intersection values of eff.frame_id_min and
eff.frame_id_max, perform the intersection using rt_fid_min/rt_fid_max as you
already do, and if the pre-intersection range was valid (pre_min <= pre_max) but
the post-intersection range is empty (eff.frame_id_min > eff.frame_id_max) emit
a clear warning (use OPENMS_LOG_WARN) that the frame and RT filters do not
intersect (include config.rt_min_sec and config.rt_max_sec and the original
frame_id bounds in the message) so the one-shot diagnostic is produced instead
of silently returning zero spectra; keep the existing fallback (eff.frame_id_min
= 1; eff.frame_id_max = 0) when q.executeStep() is false.
In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp`:
- Around line 594-596: The test currently assumes RT order by using
exp_full[0].getRT() and exp_full[exp_full.size()-1].getRT() for rt_lo/rt_hi;
instead compute the true RT bounds by scanning all spectra in exp_full and
taking the minimum and maximum getRT() values (e.g., using a loop or
std::min_element/std::max_element over exp_full.getRT()), then use those
computed min/max RT values in place of rt_lo/rt_hi to avoid ordering
assumptions.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 72f3805a-14b1-4593-9740-0bfc81852c2d
📒 Files selected for processing (3)
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.hsrc/openms/source/FORMAT/BrukerTimsFile.cppsrc/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 2 file(s) based on 3 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 2 file(s) based on 3 unresolved review comments. Co-authored-by: CodeRabbit <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds an inclusive frame-ID range filter (frame_id_min, frame_id_max) to BrukerTimsFile::Config to allow loading only a subset of TIMS frames, reducing I/O and memory for large datasets. The range filtering is applied consistently across load paths (DDA, DIA, FRAME, streaming) and metadata/count calculations, with warnings for invalid/disjoint ranges and tests covering key scenarios.
Changes:
- Added
frame_id_min/frame_id_max(and associated docs) plus RT→frame-range resolution/validation to produce an effective config used by all load entry points. - Applied frame-range filtering to DDA/DIA/FRAME iteration and to SQL-based counting/metadata so expected counts match emitted spectra.
- Added class tests for frame-id range filtering across modes (incl. DIA metadata consistency checks).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h |
Adds the new config knobs with detailed behavior/interactions documentation. |
src/openms/source/FORMAT/BrukerTimsFile.cpp |
Implements range predicate + effective-config resolution, applies filtering across load/stream/metadata/count code paths. |
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp |
Adds new test section for frame-id range filtering across export modes and DIA/DDA paths. |
Comments suppressed due to low confidence (2)
src/openms/source/FORMAT/BrukerTimsFile.cpp:2272
ms2_frame_idsis collected but never used (onlyms1_frame_idsand the SQL-derived precursor frame IDs are used later). This will trigger an unused-variable warning and the surrounding comments refer to a filter that isn’t actually applied viams2_frame_ids. Removems2_frame_ids(and theelsebranch pushing into it) or use it in the downstream MS2/precursor logic.
std::vector<uint32_t> ms1_frame_ids;
std::vector<uint32_t> ms2_frame_ids;
for (uint32_t fid = handle.min_frame_id(); fid <= handle.max_frame_id(); ++fid)
{
if (!frameInRange(fid, config)) continue;
if (!handle.has_frame(fid)) continue;
TimsFrame& frame = handle.get_frame(fid);
if (frame.msms_type == 0)
ms1_frame_ids.push_back(fid);
else
ms2_frame_ids.push_back(fid);
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp:513
- Similarly, the single-frame range test (
frame_id_min == frame_id_max) only asserts<= 1, which would not catch errors like emitting 0 spectra for a valid single-frame range. Prefer asserting exactly 1 spectrum when the fixture contains that frame (or compute the expected presence from the baseline experiment).
// --- Single frame range: at most one spectrum ---
BrukerTimsFile::Config cfg_one;
cfg_one.export_mode = BrukerTimsFile::Config::FRAME;
cfg_one.frame_id_min = 1;
cfg_one.frame_id_max = 1;
MSExperiment exp_one;
f.load(OPENTIMS_DDA_TEST_DATA, exp_one, cfg_one);
TEST_EQUAL(exp_one.size() <= 1, true);
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
- FeatureFinderMetaboIdent: adduct support via optional TSV column (#9382) - BrukerTimsImagingFile: new Bruker .d MALDI imaging loader (#9383) - BrukerTimsFile: frame_id/RT range filter in Config (#9387) - Fix: SwathMapMassCorrection null-pointer and memory leak (#9386) Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
Description
Adds a frame ID range filter (
frame_id_min,frame_id_max) toBrukerTimsFile::Configthat allows selective loading of TIMS frames. This enables memory and I/O efficient processing of large files by skipping peak data for frames outside the specified range.Key Changes
New Config parameters: Added
frame_id_min(default 0) andframe_id_max(default UINT32_MAX) toBrukerTimsFile::Configin the header file with comprehensive documentation of behavior and interactions with other knobs.Helper functions:
frameInRange(): Predicate to check if a frame ID falls within the active rangewarnInvalidFrameRange(): Validates the range against file bounds and emits warnings for invalid configurations (inverted range, non-intersecting range)Range filtering applied throughout:
loadFrames_(),loadDDA_(),loadDIAStreaming(), andloadDIAMetadata()readFrameCounts()andcountDDAPrecursors()to count only in-range framesWarnings and diagnostics:
Comprehensive test coverage: Added
frame_id range filter testsection covering:Behavior Notes
Checklist
https://claude.ai/code/session_01Fx3wbLUovk62F5XxCDv5EG
Summary by CodeRabbit
New Features
Bug Fixes
Tests