Skip to content

[FEATURE] MassTraceDetection: minimum number of peaks of a mass trace (min_trace_scans) - #10954

Merged
timosachsenberg merged 2 commits into
developfrom
mtd-min-trace-scans
Nov 20, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
mtd-min-trace-scans

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds an advanced parameter min_trace_scans (default 4) to MassTraceDetection: the minimum number of peaks of a mass trace. It applies in addition to min_trace_length; 1 disables it. Part of #10900.

Why. min_trace_length counts seconds, so what it lets through depends on the MS1 cycle time. At a cycle of more than a second, a trace of two or three peaks is longer than the limit, and lowering min_trace_length for narrow UHPLC peaks (the request in #10900) would admit more of them. A limit in peaks does not depend on the cycle time. With it in place, min_trace_length can be chosen for the chromatography alone.

Design.

  • The limit counts the peaks of the trace (trace.size()), not the scans it spans. With min_sample_rate 0.5 a trace that spans 4 scans can have 2 peaks.
  • It is checked in isTraceValid_(), next to the length in seconds.
  • The default of min_trace_length (5 s) is not changed here.

Who gets the new default. FeatureFinderMetabo and MassTraceExtractor (as algorithm:mtd:min_trace_scans), and direct users of MassTraceDetection (C++ / pyOpenMS).

Who keeps the previous behavior (parameter set to 1):

  • PeakPickerIM: its traces run along ion mobility, and it already disables the length limits.
  • MassFeatureTrace / FLASHDeconv (top-down): ft:min_trace_scans exists with default 1.
  • DDAWorkflowCommons::estimateMedianChromatographicFWHM (ProteomicsLFQ): with the limit, the 1000 most intense traces are a different set, the median FWHM changes and so do the ProteomicsLFQ_3 results. I kept this out of the PR; whether the estimate should use the limit is a separate question.

Why 4. Measured with pyOpenMS 3.6.0 (the limit emulated by dropping traces after detection), FeatureFinderMetabo defaults, min_trace_length 2 s:

Data (MS1 cycle) Features at ≥ 4 Lost at ≥ 5 Lost at ≥ 6
MTBLS733 SA1, SB1 (0.19 s) 52,555 / 51,334 0 43 / 93
Sciex TripleTOF, msdata, 2 injections (0.28 s) 589 / 568 0 36 / 36
streamlit-template example data, 4 runs (0.63 s) 7,616–9,201 424–524 (5–6%) 849–947 (10–11%)
pyopenms-docs Metabolomics_1, _2 (1.21 s) 8,599 / 8,231 749 / 513 (9% / 6%) 1,283 / 945
FeatureFinderMetabo_1_input (1.77 s) 159 17 (11%) 26
  • On MTBLS733 (836 annotated truth features) no truth feature is lost at any limit from 1 to 11 peaks; the shortest truth peak has 14 peaks. This data set cannot tell 4 from 5.
  • At cycles of 0.6 s and more, 5 removes 5–11% of the features that 4 keeps. There is no ground truth for these runs, so I cannot say whether those features are real. 4 is the smallest limit that rules out traces of two or three peaks.
  • At the current 5 s default the limit of 4 changes little at 1.2 s (Metabolomics_1: 8,659 → 8,417 features) and nothing at 0.19–0.28 s.

Test references. Nine reference files of FeatureFinderMetabo (1, 2, 5, 6) and MassTraceExtractor (1, 2, 4, 5, 6) change, because their inputs scan slowly (1.1–1.8 s) and lose the traces of fewer than 4 peaks. For each of them I checked that the tool run with -algorithm:mtd:min_trace_scans 1 still gives the previous reference (FuzzyDiff passes), so the limit is the only cause. Besides the removed features, the files differ in trace labels (renumbered) and overallquality (normalized over all features). MassTraceExtractor_1 shows the largest effect: 454 → 204 traces, as this tool reports traces without elution peak detection. MassTraceExtractor_3_expected.ini gains the parameter.

Checklist

  • New and existing unit tests pass locally with my changes

Local build: Linux, GCC 13, Release, system dependencies, without Thermo/OpenTIMS/ONNX support and pyOpenMS. All TOPP tests ran and pass. Of the class tests I built and ran those of the changed code: MassTraceDetection_test (with a new section for the parameter), MassTrace_test, ElutionPeakDetection_test, FeatureFindingMetabo_test, PeakPickerIM_test, MassFeatureTrace_test, the FLASH* tests, DDAWorkflowCommons_test, MetaboliteFeatureDeconvolution_test and MetaboliteSpectralMatching_test. The other class tests and the pyOpenMS tests were not built.

AI use (see the OpenMS AI Policy)

  • I have read the OpenMS AI Policy, and I understand, have reviewed and tested every change in this PR and can explain it in my own words
  • Substantial AI use in PR (e.g. agentic tools wrote significant parts); commits carry a Co-authored-by: trailer, and the description above explains the design intent and rationale

Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Mass traces must now meet both a minimum duration and a minimum peak count. The default minimum is four peaks, with a setting to allow traces of any peak count.
  • Bug Fixes
    • FWHM estimation, top-down tracing, and ion mobility profile detection continue to accept traces with any number of peaks.
  • Tests
    • Updated feature detection and mass trace extraction test outputs to reflect the revised trace filtering.

… (min_trace_scans)

'min_trace_length' counts seconds, so what it admits depends on the MS1
cycle time: at a cycle of more than a second a trace of two or three
peaks can be longer than the limit. The new advanced parameter
'min_trace_scans' (default 4, 1 disables it) counts the peaks of a trace
and applies in addition to 'min_trace_length'.

FeatureFinderMetabo and MassTraceExtractor take the new default. Their
test references change: the outputs are identical to the previous
references with '-algorithm:mtd:min_trace_scans 1'.

Unchanged, by setting the parameter to 1: PeakPickerIM (traces along
ion mobility), FLASHDeconv / MassFeatureTrace (top-down) and the
chromatographic peak width estimate of ProteomicsLFQ
(DDAWorkflowCommons).

See #10900.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0149aXmZHbFSUJZfvswYQoDp
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

MassTraceDetection now filters traces by both retention-time span and peak count. Its default minimum is four scans. Several callers set the minimum to one, and detector tests and expected feature-output fixtures are updated.

Changes: Mass-trace filtering

Layer / File(s) Summary
Scan-count parameter and trace validation
src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h, src/openms/source/FEATUREFINDER/MassTraceDetection.cpp, src/tests/class_tests/openms/source/MassTraceDetection_test.cpp, src/tests/topp/MassTraceExtractor_3_expected.ini
MassTraceDetection adds min_trace_scans, defaulting to 4 with a minimum value of 1. Trace validation applies the scan-count and duration limits. Tests check the defaults, parameter validation, and trace counts for different limits.
Caller-specific limits
src/openms/source/ANALYSIS/QUANTITATION/DDAWorkflowCommons.cpp, src/openms/source/ANALYSIS/TOPDOWN/MassFeatureTrace.cpp, src/openms/source/PROCESSING/CENTROIDING/PeakPickerIM.cpp
These callers set min_trace_scans to 1.
Updated expected feature outputs
src/tests/topp/FeatureFinderMetabo_*_output.featureXML, src/tests/topp/MassTraceExtractor_*_output.featureXML
The expected feature-output fixtures contain regenerated records and updated feature counts and metadata.

Possibly related issues

  • OpenMS/OpenMS issue 10900: The issue discusses narrow UHPLC peaks dropped by the seconds-based minimum trace length. This change adds a scan-count limit that applies alongside that duration limit, but does not change the duration default.

Suggested reviewers: poshul, jpfeuffer

Change: Feature

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a new MassTraceDetection parameter, min_trace_scans, that sets a minimum number of peaks per mass trace. The changeset adds this parameter to MassTraceDetection, sets …
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: Title check

Explanation

The title names the main change: a new MassTraceDetection parameter, min_trace_scans, that sets a minimum number of peaks per mass trace. The changeset adds this parameter to MassTraceDetection, sets it per caller (FeatureFinderMetabo, MassTraceExtractor, PeakPickerIM, DDAWorkflowCommons, MassFeatureTrace), and updates the regression test and fixtures. The title is specific and matches the PR objectives. The bracketed [FEATURE] tag is a convention, not a defect.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Review coverage is incomplete: 1 file could not be fully reviewed. Findings from completed review steps are included; see review info for details.

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 counts the scans in rows,
Four peaks mark the default close.
One scan lets special traces through,
The tests check what the limits do.
New feature maps reflect the change,
And moonlit hops complete the range.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68d88702-a1c0-4dfd-9e27-f917caba63e1
Commits

Reviewing files that changed from the base of the PR and between 6be4c55 and e9d08f5.

Files selected for processing: 16

  • src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h
  • src/openms/source/ANALYSIS/QUANTITATION/DDAWorkflowCommons.cpp
  • src/openms/source/ANALYSIS/TOPDOWN/MassFeatureTrace.cpp
  • src/openms/source/FEATUREFINDER/MassTraceDetection.cpp
  • src/openms/source/PROCESSING/CENTROIDING/PeakPickerIM.cpp
  • src/tests/class_tests/openms/source/MassTraceDetection_test.cpp
  • src/tests/topp/FeatureFinderMetabo_1_output.featureXML
  • src/tests/topp/FeatureFinderMetabo_2_noEPD_output.featureXML
  • src/tests/topp/FeatureFinderMetabo_5_output.featureXML
  • src/tests/topp/FeatureFinderMetabo_6_output.featureXML
  • src/tests/topp/MassTraceExtractor_1_output.featureXML
  • src/tests/topp/MassTraceExtractor_2_output.featureXML
  • src/tests/topp/MassTraceExtractor_3_expected.ini
  • src/tests/topp/MassTraceExtractor_4_output.featureXML
  • src/tests/topp/MassTraceExtractor_5_output.featureXML
  • src/tests/topp/MassTraceExtractor_6_output.featureXML
Files not reviewed due to moderation or processing errors: 1

  • src/tests/topp/MassTraceExtractor_5_output.featureXML

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

@timosachsenberg
timosachsenberg enabled auto-merge (squash) November 20, 2026 13:19
Conflict with #10893 in MassTraceDetection::isTraceValid_(), which now
gets the RT range and the peak count instead of the trace. The new
min_trace_scans check uses peak_count instead of trace.size().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0149aXmagZ9HY1kvqXDEweT1
@timosachsenberg
timosachsenberg merged commit 2812dd0 into develop Nov 20, 2026
12 checks passed
@timosachsenberg
timosachsenberg deleted the mtd-min-trace-scans branch November 20, 2026 15:23
timosachsenberg pushed a commit that referenced this pull request Nov 20, 2026
Brings in #10954 (min_trace_scans), so that CI tests the smoothing change
together with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0149aXmagZ9HY1kvqXDEweT1
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.

3 participants