Skip to content

feat: add IM_PEAK format checks to four TOPP tools - #9018

Merged
timosachsenberg merged 1 commit into
developfrom
feature/im-peak-warnings
Mar 27, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
feature/im-peak-warnings

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resampler, FeatureFinderCentroided, FeatureFinderMultiplex: error out (INCOMPATIBLE_INPUT_DATA) when input contains per-peak ion mobility data (IM_PEAK) they cannot properly handle
  • PeakPickerHiRes: warns but continues, since it has partial IM_PEAK support (intensity-weighted mean IM per picked peak) that works correctly on pre-binned data but produces incorrect results on unbinned 2D data

All checks report the detected IMPeakType (im_profile/im_centroided) in the message and suggest preprocessing with IonMobilityBinning or PeakPickerIM.

Motivation

With direct Bruker .d file reading now supported, tools can receive IM_PEAK format data (per-peak ion mobility in FloatDataArrays). Tools that operate in m/z only would silently produce wrong results (merging IM-separated species) or destroy IM metadata. These checks make the limitation explicit.

Test plan

  • Existing TOPP tests for all four tools still pass (non-IM data unaffected)
  • Manual test: feed IM_PEAK mzML to Resampler/FFC/FFM → exits with INCOMPATIBLE_INPUT_DATA
  • Manual test: feed IM_PEAK mzML to PeakPickerHiRes → warning printed, processing continues

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • FeatureFinderCentroided, FeatureFinderMultiplex, and Resampler now validate input and reject unsupported per-peak ion mobility data before processing.
    • PeakPickerHiRes now warns when processing per-peak ion mobility data due to potential accuracy concerns.

…, FeatureFinderMultiplex, PeakPickerHiRes

Resampler, FeatureFinderCentroided, and FeatureFinderMultiplex now error
out (INCOMPATIBLE_INPUT_DATA) when given per-peak ion mobility data they
cannot handle. PeakPickerHiRes warns but continues, since it has partial
IM_PEAK support (intensity-weighted mean IM per picked peak) that works
on pre-binned data.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Four TOPP tools (FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes, Resampler) now detect per-peak ion mobility format during startup. Each tool iterates over loaded spectra, identifies if any contain IM_PEAK format, and either logs an error/terminates or emits a warning before proceeding with normal processing.

Changes

Cohort / File(s) Summary
Tools with early termination
src/topp/FeatureFinderCentroided.cpp, src/topp/FeatureFinderMultiplex.cpp, src/topp/Resampler.cpp
Each tool now iterates over loaded spectra, calls IMTypes::determineIMFormat() to detect ion mobility format, and exits with INCOMPATIBLE_INPUT_DATA error if any spectrum contains IMFormat::IM_PEAK per-peak ion mobility data. Includes error logging with specific IM peak type information.
Tool with warning
src/topp/PeakPickerHiRes.cpp
Added ion mobility type detection after loading. Emits a warning (rather than error) when any spectrum contains IMFormat::IM_PEAK per-peak ion mobility, noting that the tool operates on m/z only and reports intensity-weighted mean IM, making unbinned per-peak IM data produce incorrect results.

Possibly related PRs

Suggested labels

enhancement, Review effort [1-5]: 3

Suggested reviewers

  • alhigaylan
  • singjc
  • poshul

Poem

🐰 A rabbit hops through spectra peaks,
Checking ion mobilities all week!
Per-peak formats? We detect,
Incompatible data? We reject!
Early warnings keep tools correct! 🚫✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding IM_PEAK format detection checks to four TOPP tools (Resampler, FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/im-peak-warnings

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

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

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/topp/PeakPickerHiRes.cpp (1)

169-185: ⚠️ Potential issue | 🟠 Major

Missing IM_PEAK warning in lowmemory processing path.

The IM_PEAK detection and warning is only implemented for the inmemory path (after line 213). When users run with -processOption lowmemory, the doLowMemAlgorithm function processes data via streaming without any warning about per-peak ion mobility data.

This creates inconsistent behavior: the same input file produces a warning with inmemory but silently processes with lowmemory, potentially producing incorrect results without user awareness.

Suggested approach: Add IM_PEAK check to lowmemory consumer

One option is to add IM check in PPHiResMzMLConsumer::processSpectrum_ with a flag to warn once:

   class PPHiResMzMLConsumer :
     public MSDataWritingConsumer
   {

   public:

     PPHiResMzMLConsumer(String filename, const PeakPickerHiRes& pp) :
       MSDataWritingConsumer(std::move(filename)),
-      ms_levels_(pp.getParameters().getValue("ms_levels").toIntVector())
+      ms_levels_(pp.getParameters().getValue("ms_levels").toIntVector()),
+      im_peak_warned_(false)
     {
       pp_ = pp;
     }

     void processSpectrum_(MapType::SpectrumType& s) override
     {
+      // Warn once about per-peak ion mobility data
+      if (!im_peak_warned_)
+      {
+        IMFormat im_format = IMTypes::determineIMFormat(s);
+        if (im_format == IMFormat::IM_PEAK)
+        {
+          OPENMS_LOG_WARN << "Warning: Input contains per-peak ion mobility data (IM_PEAK, "
+                          << imPeakTypeToString(s.getIMPeakType())
+                          << "). PeakPickerHiRes picks in m/z only and reports intensity-weighted "
+                          << "mean ion mobility. This produces incorrect results on unbinned data. "
+                          << "Consider IonMobilityBinning or PeakPickerIM first.\n";
+          im_peak_warned_ = true;
+        }
+      }
       if (ms_levels_.empty()) //auto mode
       // ... rest unchanged
     }

   private:

     PeakPickerHiRes pp_;
     std::vector<Int> ms_levels_;
+    bool im_peak_warned_;
   };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/PeakPickerHiRes.cpp` around lines 169 - 185, doLowMemAlgorithm is
missing the IM_PEAK warning because streaming uses PPHiResMzMLConsumer; add the
same per-file IM_PEAK detection/warn into the low-memory path by implementing
the check inside PPHiResMzMLConsumer::processSpectrum_ (or a helper it calls) so
it detects ion-mobility values per peak and emits the existing IM_PEAK warning
exactly once. Add a boolean member (e.g., warned_im_peak_) to
PPHiResMzMLConsumer to ensure the warning is logged only once and reuse the same
warning text/logic used by the inmemory path so behavior is consistent between
doLowMemAlgorithm and the in-memory code paths.
🧹 Nitpick comments (4)
src/topp/Resampler.cpp (1)

105-117: Consistent IM_PEAK detection implementation.

The implementation correctly follows the same pattern established in FeatureFinderCentroided and FeatureFinderMultiplex. The check is well-placed immediately after loading the experiment.

Same optional style note: consider \n over std::endl.

Optional: Replace std::endl with \n
         OPENMS_LOG_ERROR << "Error: Input contains per-peak ion mobility data (IM_PEAK, "
                          << imPeakTypeToString(spec.getIMPeakType())
                          << ") which is not supported by Resampler. "
-                         << "Preprocess with IonMobilityBinning or PeakPickerIM first." << std::endl;
+                         << "Preprocess with IonMobilityBinning or PeakPickerIM first.\n";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/Resampler.cpp` around lines 105 - 117, The log message in
Resampler.cpp uses std::endl which flushes the stream unnecessarily; in the
IM_PEAK detection block inside the loop that calls
IMTypes::determineIMFormat(spec) (and returns INCOMPATIBLE_INPUT_DATA when
im_format == IMFormat::IM_PEAK), replace the trailing std::endl with "\n" in the
OPENMS_LOG_ERROR call (preserving the existing message and references to
imPeakTypeToString and the return behavior) to avoid extra flushes while keeping
the same error output.
src/topp/FeatureFinderCentroided.cpp (1)

194-206: Well-implemented IM_PEAK detection with early abort.

The ion mobility format check correctly identifies unsupported per-peak IM data and provides a clear error message with recommended preprocessing steps. The immediate return on first detection is efficient.

Minor style note: Consider using \n instead of std::endl for performance (avoids unnecessary flush). As per coding guidelines: "Avoid std::endl for performance; prefer \n".

Optional: Replace std::endl with \n
         OPENMS_LOG_ERROR << "Error: Input contains per-peak ion mobility data (IM_PEAK, "
                          << imPeakTypeToString(spec.getIMPeakType())
                          << ") which is not supported by FeatureFinderCentroided. "
-                         << "Preprocess with IonMobilityBinning or PeakPickerIM first." << std::endl;
+                         << "Preprocess with IonMobilityBinning or PeakPickerIM first.\n";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/FeatureFinderCentroided.cpp` around lines 194 - 206, Replace the
std::endl flush in the error logging inside FeatureFinderCentroided (the loop
using IMTypes::determineIMFormat and imPeakTypeToString) with a '\n' to avoid an
unnecessary stream flush; update the OPENMS_LOG_ERROR call to end with "\n"
instead of std::endl so the message remains the same but is more performant.
src/topp/PeakPickerHiRes.cpp (1)

215-228: Good warning implementation for inmemory path.

The warning appropriately explains that PeakPickerHiRes operates on m/z only and may produce incorrect results on unbinned IM_PEAK data. The break ensures the warning is emitted only once, which is good UX.

Note: This correctly differs from other tools by warning rather than aborting, as PeakPickerHiRes has partial IM_PEAK support per the PR objectives.

Same optional style note: consider \n over std::endl.

Optional: Replace std::endl with \n
         OPENMS_LOG_WARN << "Warning: Input contains per-peak ion mobility data (IM_PEAK, "
                         << imPeakTypeToString(spec.getIMPeakType())
                         << "). PeakPickerHiRes picks in m/z only and reports intensity-weighted "
                         << "mean ion mobility. This produces incorrect results on unbinned data. "
-                        << "Consider IonMobilityBinning or PeakPickerIM first." << std::endl;
+                        << "Consider IonMobilityBinning or PeakPickerIM first.\n";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/PeakPickerHiRes.cpp` around lines 215 - 228, The warning loop in
PeakPickerHiRes that checks each spectrum in ms_exp_raw uses std::endl; change
the final stream terminator to '\n' to avoid flushing the stream unnecessarily:
in the loop where IMTypes::determineIMFormat(spec) yields IMFormat::IM_PEAK and
you log with OPENMS_LOG_WARN and imPeakTypeToString(spec.getIMPeakType()),
replace the std::endl at the end of the message with "\n" and keep the break to
warn only once.
src/topp/FeatureFinderMultiplex.cpp (1)

258-270: Consistent IM_PEAK detection implementation.

The ion mobility format check mirrors the implementation in FeatureFinderCentroided, maintaining consistency across tools. The check is appropriately placed after loading but before processing begins.

Same optional style note applies: consider \n over std::endl for performance.

Optional: Replace std::endl with \n
         OPENMS_LOG_ERROR << "Error: Input contains per-peak ion mobility data (IM_PEAK, "
                          << imPeakTypeToString(spec.getIMPeakType())
                          << ") which is not supported by FeatureFinderMultiplex. "
-                         << "Preprocess with IonMobilityBinning or PeakPickerIM first." << std::endl;
+                         << "Preprocess with IonMobilityBinning or PeakPickerIM first.\n";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/FeatureFinderMultiplex.cpp` around lines 258 - 270, The log line in
the IM_PEAK detection loop uses std::endl which flushes the stream
unnecessarily; update the OPENMS_LOG_ERROR message inside the loop that checks
IMTypes::determineIMFormat(spec) and detects IMFormat::IM_PEAK (the block that
calls imPeakTypeToString(spec.getIMPeakType()) and returns
INCOMPATIBLE_INPUT_DATA) to terminate the message with '\n' instead of std::endl
to avoid the extra flush and improve performance.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/topp/PeakPickerHiRes.cpp`:
- Around line 169-185: doLowMemAlgorithm is missing the IM_PEAK warning because
streaming uses PPHiResMzMLConsumer; add the same per-file IM_PEAK detection/warn
into the low-memory path by implementing the check inside
PPHiResMzMLConsumer::processSpectrum_ (or a helper it calls) so it detects
ion-mobility values per peak and emits the existing IM_PEAK warning exactly
once. Add a boolean member (e.g., warned_im_peak_) to PPHiResMzMLConsumer to
ensure the warning is logged only once and reuse the same warning text/logic
used by the inmemory path so behavior is consistent between doLowMemAlgorithm
and the in-memory code paths.

---

Nitpick comments:
In `@src/topp/FeatureFinderCentroided.cpp`:
- Around line 194-206: Replace the std::endl flush in the error logging inside
FeatureFinderCentroided (the loop using IMTypes::determineIMFormat and
imPeakTypeToString) with a '\n' to avoid an unnecessary stream flush; update the
OPENMS_LOG_ERROR call to end with "\n" instead of std::endl so the message
remains the same but is more performant.

In `@src/topp/FeatureFinderMultiplex.cpp`:
- Around line 258-270: The log line in the IM_PEAK detection loop uses std::endl
which flushes the stream unnecessarily; update the OPENMS_LOG_ERROR message
inside the loop that checks IMTypes::determineIMFormat(spec) and detects
IMFormat::IM_PEAK (the block that calls imPeakTypeToString(spec.getIMPeakType())
and returns INCOMPATIBLE_INPUT_DATA) to terminate the message with '\n' instead
of std::endl to avoid the extra flush and improve performance.

In `@src/topp/PeakPickerHiRes.cpp`:
- Around line 215-228: The warning loop in PeakPickerHiRes that checks each
spectrum in ms_exp_raw uses std::endl; change the final stream terminator to
'\n' to avoid flushing the stream unnecessarily: in the loop where
IMTypes::determineIMFormat(spec) yields IMFormat::IM_PEAK and you log with
OPENMS_LOG_WARN and imPeakTypeToString(spec.getIMPeakType()), replace the
std::endl at the end of the message with "\n" and keep the break to warn only
once.

In `@src/topp/Resampler.cpp`:
- Around line 105-117: The log message in Resampler.cpp uses std::endl which
flushes the stream unnecessarily; in the IM_PEAK detection block inside the loop
that calls IMTypes::determineIMFormat(spec) (and returns INCOMPATIBLE_INPUT_DATA
when im_format == IMFormat::IM_PEAK), replace the trailing std::endl with "\n"
in the OPENMS_LOG_ERROR call (preserving the existing message and references to
imPeakTypeToString and the return behavior) to avoid extra flushes while keeping
the same error output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4f134b6-ea54-4eb9-bf28-cc0ca9c2560c

📥 Commits

Reviewing files that changed from the base of the PR and between ff4eabe and 79438b9.

📒 Files selected for processing (4)
  • src/topp/FeatureFinderCentroided.cpp
  • src/topp/FeatureFinderMultiplex.cpp
  • src/topp/PeakPickerHiRes.cpp
  • src/topp/Resampler.cpp

@timosachsenberg
timosachsenberg merged commit d360fc6 into develop Mar 27, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the feature/im-peak-warnings branch March 27, 2026 10:56
github-actions Bot pushed a commit that referenced this pull request Mar 28, 2026
Add missing changelog entries for commits after the 2026-03-26 sync:
- #9019: OpenSwathWorkflow direct Bruker .d (TDF) file input
- #9018: IM_PEAK format checks in Resampler, FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes
- #9003: TMT 32-plex and 35-plex quantitation support
- #9007: IMPeakType enum added, IMFormat::CENTROIDED deprecated
- #9011: BREAKING IMFormat::MIXED removed; determineIMFormat requires ms_level

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 28, 2026
Add missing changelog entries for commits after the 2026-03-26 sync:
- #9019: OpenSwathWorkflow direct Bruker .d (TDF) file input
- #9018: IM_PEAK format checks in Resampler, FeatureFinderCentroided, FeatureFinderMultiplex, PeakPickerHiRes
- #9003: TMT 32-plex and 35-plex quantitation support
- #9007: IMPeakType enum added, IMFormat::CENTROIDED deprecated
- #9011: BREAKING IMFormat::MIXED removed; determineIMFormat requires ms_level

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

1 participant