Skip to content

Improve Tolerance Determination for Sequence Tags - #8319

Merged
timosachsenberg merged 9 commits into
developfrom
tagger_changes
Oct 31, 2025
Merged

timosachsenberg merged 9 commits into
developfrom
tagger_changes

Conversation

@t0mdavid-m

@t0mdavid-m t0mdavid-m commented Oct 22, 2025 •

Copy link
Copy Markdown
Member

Description

In TDP, we are dealing with relatively large fragment masses. This creates an issue in the current tagging algorithm: the (comparably very small) amino acid mass difference is used to determine the tolerance for matching amino acids, resulting in overly restrictive tolerance windows that miss valid matches. This PR adds the option to use absolute m/z values of the nodes for tolerance determination.

Credit goes to @KyowonJeong

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features
    • Option to interpret mass tolerance as either ppm (default) or absolute m/z.
  • Enhancements
    • Amino-acid matching now selects the closest residue within the specified tolerance, improving tag construction and gap calculations.
  • Documentation
    • Updated docs to explain the new tolerance option and its behavior.
  • Tests
    • Added unit tests covering ppm vs absolute tolerance and varied mass/error scenarios.
  • Chores
    • .gitignore updated to exclude build and doc outputs.

@coderabbitai

coderabbitai Bot commented Oct 22, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Replaces the ppm-only parameter with a unified tolerance and a tol_is_ppm flag; updates Tagger constructor and private members, adjusts mass-matching and gap-bound logic to interpret tolerance as ppm or absolute Da, expands unit tests for both modes, and adds new .gitignore patterns.

Changes

Cohort / File(s) Summary
Header: Tagger declaration
src/openms/include/OpenMS/CHEMISTRY/Tagger.h
Constructor signature changed to Tagger(size_t min_tag_length, double tolerance, size_t max_tag_length = 65535, size_t min_charge = 1, size_t max_charge = 1, const StringList& fixed_mods = StringList(), const StringList& var_mods = StringList(), bool tol_is_ppm = true). Private ppm_ renamed to tolerance_; added bool tol_is_ppm_. Documentation/comments updated.
Implementation: Tagger logic & behavior
src/openms/source/CHEMISTRY/Tagger.cpp
Constructor now stores tolerance_ and tol_is_ppm_. getAAByMass_ computes delta as m * tolerance_ / 1e6 when tol_is_ppm_ is true or as absolute tolerance_ otherwise; returns the closest residue within delta. Gap bounds initialization uses the new tolerance interpretation. Minor comment formatting changes.
Tests: Tagger unit tests
src/tests/class_tests/openms/source/Tagger_test.cpp
Expanded tests added to validate ppm (default) and absolute Da tolerance modes across varied m/z ranges and scenarios, including boundary and high-resolution checks; some duplicated blocks present in the diff.
Repo metadata
.gitignore
Added ignore patterns: build-release/*, build-debug/*, and doc/*. Existing vcpkg_installed entry remains ignored.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Tagger
    participant AALookup

    Caller->>Tagger: Tagger(min_len, tolerance, ..., tol_is_ppm)
    Note over Tagger: stores tolerance_ and tol_is_ppm_

    Caller->>Tagger: getTag_(mass_sequence)
    Tagger->>AALookup: getAAByMass_(m)
    alt tol_is_ppm_ == true
        Note right of AALookup #D6EAF8: delta = m * tolerance_ / 1e6 (ppm)
    else tol_is_ppm_ == false
        Note right of AALookup #FDEBD0: delta = tolerance_ (absolute Da)
    end
    AALookup->>AALookup: scan residues, compute distance to target mass
    AALookup-->>Tagger: return closest residue within delta or 'no match'
    Tagger-->>Caller: assembled tag / result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify all Tagger constructor call sites (production and tests) match new parameter order and default tol_is_ppm = true.
  • Check ppm vs Da calculations for correct scaling and off-by-factor issues.
  • Review expanded tests (and duplicated blocks) for correctness and intended assertions.
  • Inspect references to the old ppm_ member (comments, serialization, or external access).

Poem

🐰 I swapped my ppm for a tunable tol,
both ppm and Da help me find my goal.
I hop through masses, pick the closest one,
stitch tags from fragments till the tagging's done.
A carrot for each matched run.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Improve Tolerance Determination for Sequence Tags" accurately and directly describes the primary change in the changeset. The core modification refactors the Tagger class to support both ppm-based and absolute m/z-based tolerance determination, controlled by a new tol_is_ppm flag. This is achieved through renaming the ppm parameter to tolerance and introducing the new flag, which addresses the issue of overly restrictive tolerance windows in top-down proteomics. The title is concise, clear, and specific enough that a teammate scanning history would understand the main purpose of the PR without requiring knowledge of implementation details like the flag name.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tagger_changes

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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/openms/include/OpenMS/CHEMISTRY/Tagger.h (1)

86-86: Improve the inline comment grammar.

The comment would be clearer with more formal phrasing.

Apply this diff to improve the comment:

-      bool use_absolute_mz_tol_ = false; /// if set, the absolute m/z value is used to determine mass tolerance instead of m/z difference value.
+      bool use_absolute_mz_tol_ = false; ///< when true, use absolute m/z value to determine mass tolerance instead of m/z difference value
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ddb8b9 and a282729.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h (1 hunks)
  • src/openms/source/CHEMISTRY/Tagger.cpp (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h
  • src/openms/source/CHEMISTRY/Tagger.cpp
src/openms/include/OpenMS/**/*.h

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Add Doxygen comments for new public methods and classes

Files:

  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h
🧬 Code graph analysis (1)
src/openms/include/OpenMS/CHEMISTRY/Tagger.h (1)
src/openms/source/CHEMISTRY/Tagger.cpp (4)
  • setUseAbsoluteMzForTol (187-190)
  • setUseAbsoluteMzForTol (187-187)
  • getAAByMass_ (22-45)
  • getAAByMass_ (22-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: build-and-test (macos-15-intel, xcode, 16.0.0)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (macos-26, xcode, 26.0)
🔇 Additional comments (3)
src/openms/source/CHEMISTRY/Tagger.cpp (3)

63-63: LGTM: Correct conditional logic for tolerance mode.

The conditional call correctly passes the absolute m/z value (mzs[j]) when the flag is enabled, and falls back to the original behavior otherwise. This aligns well with the PR objectives for top-down proteomics support.


187-190: LGTM: Straightforward setter implementation.

The implementation correctly sets the flag to enable absolute m/z-based tolerance calculation.


31-44: Verify that existing tests pass with the new best-match behavior.

The behavior has changed from returning the first amino acid within tolerance to searching for the closest match (smallest mass difference). While the code comment "return the most exact one" indicates this was intentional, the change should be validated by confirming that the existing test expectations still hold.

Run Tagger_test to verify the tag counts remain as expected (890, 1006, 1094, 667, 739 for the respective test cases) and that all tag presence/absence assertions pass with the new matching logic.

Comment thread src/openms/source/CHEMISTRY/Tagger.cpp Resolved
Comment thread src/openms/source/CHEMISTRY/Tagger.cpp Resolved
t0mdavid-m and others added 3 commits October 22, 2025 09:13
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/openms/source/CHEMISTRY/Tagger.cpp (1)

32-33: Initialize min_delta with the actual distance of the first candidate.

The variable min_delta is initialized to delta (the tolerance window) instead of the actual distance of the first candidate (fabs(left->first - m)). This causes incorrect best-match selection when multiple candidates are within tolerance.

Example scenario:

  • First candidate at distance 0.8 from target
  • Second candidate at distance 0.9 from target
  • With min_delta = delta (e.g., 1.0), the comparison 0.9 < 1.0 succeeds and incorrectly selects the second candidate
  • With correct initialization min_delta = 0.8, the comparison 0.9 < 0.8 fails and correctly keeps the first candidate

Apply this diff to fix the initialization:

     if (fabs(left->first - m) >= delta) return ' ';
     // return the most exact one.
     auto best_aa = left;
-    double min_delta = delta;
+    double min_delta = fabs(left->first - m);
🧹 Nitpick comments (1)
src/openms/source/CHEMISTRY/Tagger.cpp (1)

188-191: Consider accepting a boolean parameter for more flexibility.

The current implementation only allows enabling the absolute m/z tolerance mode but doesn't provide a way to disable it. While this may be intentional for the current use case, accepting a boolean parameter would make the API more flexible and align with common setter patterns.

-  void Tagger::setUseAbsoluteMzForTol()
+  void Tagger::setUseAbsoluteMzForTol(bool enable)
   {
-    use_absolute_mz_tol_ = true;
+    use_absolute_mz_tol_ = enable;
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a282729 and 8040138.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h (1 hunks)
  • src/openms/source/CHEMISTRY/Tagger.cpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h
🧰 Additional context used
📓 Path-based instructions (1)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: cppcheck-test

Comment thread src/openms/source/CHEMISTRY/Tagger.cpp Resolved
Comment thread src/openms/source/CHEMISTRY/Tagger.cpp Outdated
Comment on lines +188 to +191
void Tagger::setUseAbsoluteMzForTol()
{
use_absolute_mz_tol_ = true;
}

@coderabbitai coderabbitai Bot Oct 22, 2025 •

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.

⚠️ Potential issue | 🟡 Minor

Add documentation for the new public API method.

The new setUseAbsoluteMzForTol() method lacks documentation explaining its purpose, when it should be used, and its effect on tag generation. Public API methods in OpenMS should include comments describing their functionality, especially for non-obvious features like this tolerance mode.

Add a documentation comment above the method:

+  /**
+   * @brief Enable absolute m/z-based tolerance for amino acid matching.
+   * 
+   * When enabled, tolerance is calculated based on the fragment m/z value
+   * rather than the amino acid mass difference. This is useful for top-down
+   * proteomics where fragment masses are large relative to amino acid masses.
+   */
   void Tagger::setUseAbsoluteMzForTol()
   {
     use_absolute_mz_tol_ = true;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void Tagger::setUseAbsoluteMzForTol()
{
use_absolute_mz_tol_ = true;
}
/**
* @brief Enable absolute m/z-based tolerance for amino acid matching.
*
* When enabled, tolerance is calculated based on the fragment m/z value
* rather than the amino acid mass difference. This is useful for top-down
* proteomics where fragment masses are large relative to amino acid masses.
*/
void Tagger::setUseAbsoluteMzForTol()
{
use_absolute_mz_tol_ = true;
}

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.

this is definitely not restricted to top-down

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.

@timosachsenberg, you're absolutely right! The feature isn't restricted to top-down proteomics—it's useful in any scenario where fragment masses are large relative to amino acid mass differences. Here's a revised documentation suggestion that's more general:

  /**
   * @brief Enable absolute m/z-based tolerance for amino acid matching.
   * 
   * When enabled, tolerance is calculated based on the fragment m/z value
   * rather than the amino acid mass difference. This is useful when working
   * with large fragment masses where tolerance based on small amino acid
   * mass differences would be overly restrictive.
   */
  void Tagger::setUseAbsoluteMzForTol()
  {
    use_absolute_mz_tol_ = true;
  }

This focuses on the technical condition (large fragment masses) rather than tying it to a specific proteomics workflow.


When enabled, the tagger uses the absolute m/z value of the node
to determine the mass tolerance window instead of the m/z difference value.
This is particularly useful for top-down proteomics where fragment masses

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.

not only for top-down. to me it does not make sense to use ppm relative to AAs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

see comments.
I wonder if tolerances relative to AAs masses even make sense.
Can you also check where it is currently used?

@KyowonJeong

KyowonJeong commented Oct 22, 2025 •

Copy link
Copy Markdown
Collaborator

For Top down this tolerance using absolute m/z improved the performance drastically. Oh this code is not for TDP.. I will take a look..

@timosachsenberg

Copy link
Copy Markdown
Contributor

Yeah my argument would be that it could make sense to only use your approach. Could prevent some unexpected results …

@KyowonJeong

Copy link
Copy Markdown
Collaborator

Yeah my argument would be that it could make sense to only use your approach. Could prevent some unexpected results …

I agree. I am using my own code base. So it is a separate PR from @t0mdavid-m .

@t0mdavid-m

t0mdavid-m commented Oct 22, 2025 •

Copy link
Copy Markdown
Member Author

I agree. The new behavior should be the default.

@timosachsenberg

Copy link
Copy Markdown
Contributor

I agree. The new behavior should be the default.

default behavior or only behavior? If possible, I would say only behavior. ;)

@t0mdavid-m t0mdavid-m mentioned this pull request Oct 30, 2025
8 of 13 tasks

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/openms/source/CHEMISTRY/Tagger.cpp (1)

28-29: Add defensive check for iterator validity.

Before dereferencing left->first on line 29, verify that left != mass2aa_.end(). While the boundary check at line 25 should prevent lower_bound from returning end() in normal cases, floating-point precision edge cases or unexpected tolerance calculations could cause m - delta to exceed all map keys. Adding this check improves robustness.

Apply this diff:

   const double delta = tol_is_ppm_ ? Math::ppmToMass(tolerance_, m) : tolerance_;
   auto left = mass2aa_.lower_bound(m - delta);
+  if (left == mass2aa_.end()) return ' ';
   if (fabs(left->first - m) >= delta) return ' ';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8040138 and cc1bc1f.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h (2 hunks)
  • src/openms/source/CHEMISTRY/Tagger.cpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/CHEMISTRY/Tagger.h
🧰 Additional context used
📓 Path-based instructions (1)
src/openms/**/*.{cpp,h,hpp,cc,cxx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms

Files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
🧠 Learnings (9)
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-29T19:09:45.997Z
Learnt from: jcharkow
PR: OpenMS/OpenMS#8188
File: src/topp/OpenSwathWorkflow.cpp:1118-1123
Timestamp: 2025-08-29T19:09:45.997Z
Learning: In OpenMS OpenSwathWorkflow, the use_ms1_ion_mobility parameter should be respected when applying estimated MS1 ion mobility extraction windows. The apply_window calls for MS1 ion mobility should check both pasef AND use_ms1_ion_mobility to avoid re-enabling disabled functionality.

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-10-21T13:02:16.431Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8318
File: src/openms/include/OpenMS/ML/CLUSTERING/HashGrid.h:466-480
Timestamp: 2025-10-21T13:02:16.431Z
Learning: In OpenMS, when making internal methods public (e.g., in HashGrid.h), remove XXX/TODO comments about implementation details rather than documenting them in the public API documentation.

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-07-29T10:05:48.139Z
Learnt from: poshul
PR: OpenMS/OpenMS#8133
File: src/openms/include/OpenMS/ANALYSIS/TARGETED/TargetedExperimentHelper.h:0-0
Timestamp: 2025-07-29T10:05:48.139Z
Learning: In the Nuctide class in TargetedExperimentHelper.h, the Modification struct is intentionally defined but not used (no mods_ member or related methods). This is by design and should be documented with a comment to avoid confusion.

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Ensure existing tests pass before suggesting changes

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)

Applied to files:

  • src/openms/source/CHEMISTRY/Tagger.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: cppcheck-test
  • GitHub Check: build-and-test (macos-15-intel, xcode, 16.0.0)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (macos-26, xcode, 26.0)
🔇 Additional comments (2)
src/openms/source/CHEMISTRY/Tagger.cpp (2)

93-94: Constructor refactoring looks correct.

The signature change from ppm to tolerance with the tol_is_ppm flag properly supports both ppm-based and absolute tolerance modes. The default tol_is_ppm = true maintains backward compatibility for existing code that passes ppm values. Using fabs(tolerance) ensures the tolerance is always positive.


137-146: Gap bounds calculation correctly implements dual tolerance modes.

The conditional initialization properly handles both ppm-based tolerance (calculated at boundary masses) and absolute tolerance (constant value). This aligns with the tolerance calculation in getAAByMass_ and correctly establishes the valid mass range for amino acid matching.

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/tests/class_tests/openms/source/Tagger_test.cpp (4)

310-347: Add specific assertions to validate tolerance behavior.

This test has excellent explanatory comments about the theoretical difference (100 ppm on ~100 Da AA mass = 0.01 Da tolerance vs. 100 ppm on 2000 Da fragment = 0.2 Da tolerance), but the assertion only checks that tags_da_wide.size() >= tags_ppm_tight.size().

Given the intentional 0.05 Da shift and the theoretical tolerance calculations, you can make more specific assertions:

  • The ppm mode (0.01 Da tolerance on AA mass) should miss matches with 0.05 Da shift
  • The Da mode (0.2 Da tolerance on fragment m/z) should successfully match despite the 0.05 Da shift
  • Verify specific expected tags (e.g., "PE") are found in Da mode but not in ppm mode

Apply this pattern to strengthen the test:

   // With the larger shift, ppm mode (tight on AA mass) should find fewer or no tags
   // Da mode (wide on fragment m/z) should find tags despite the shift
   // The exact counts depend on matching, but Da mode should be >= ppm mode
   TEST_EQUAL(tags_da_wide.size() >= tags_ppm_tight.size(), true)
+  
+  // Specifically verify that Da mode finds tags while ppm mode does not (due to 0.05 Da shift)
+  bool found_pe_ppm = std::find(tags_ppm_tight.begin(), tags_ppm_tight.end(), "PE") != tags_ppm_tight.end();
+  bool found_pe_da = std::find(tags_da_wide.begin(), tags_da_wide.end(), "PE") != tags_da_wide.end();
+  
+  // With 0.05 Da shift, ppm mode (0.01 Da tol) should miss, Da mode (0.2 Da tol) should find
+  TEST_EQUAL(found_pe_ppm, false)
+  TEST_EQUAL(found_pe_da, true)

349-370: Compare tag content, not just size, for robust backward compatibility verification.

The test only compares tags_default.size() with tags_explicit_ppm.size(), but two result sets could have the same size yet contain different tags. For robust backward compatibility verification, compare the actual tag contents.

Additionally, verify that the Tagger constructor has proper overloads: the test uses a 5-parameter constructor (line 360) expecting it to default tol_is_ppm to true, while the new signature shown in the code snippets has 8 parameters. Ensure the 5-parameter overload exists and properly defaults the new parameter.

Apply this diff to strengthen the test:

   // Both should produce identical results (backward compatibility)
   TEST_EQUAL(tags_default.size(), tags_explicit_ppm.size())
+  
+  // Verify actual content is identical, not just size
+  std::sort(tags_default.begin(), tags_default.end());
+  std::sort(tags_explicit_ppm.begin(), tags_explicit_ppm.end());
+  TEST_EQUAL(tags_default == tags_explicit_ppm, true)

372-393: Strengthen test with specific tolerance boundary verification.

The test uses realistic high-resolution mass errors (1-2 milliDa) and correctly calculates that 10 ppm at 1500 Da equals 15 milliDa tolerance, but only verifies tags_hires.size() != 0. This doesn't confirm that the tolerance calculation is correct.

Consider adding:

  1. Specific assertions about which tags should be found (given 1-2 milliDa shifts are well within 15 milliDa tolerance)
  2. A boundary test case with a shift at or just beyond the tolerance limit (e.g., 0.016 Da shift) to verify it's correctly excluded
  3. Comparison with a tighter tolerance (e.g., 5 ppm = 7.5 milliDa) that should miss some of the 2 milliDa shifts

237-393: Add edge case and error handling tests.

All five new test sections exercise the happy path but don't test edge cases or error handling for the new tol_is_ppm parameter. Consider adding tests for:

  1. Invalid tolerance values: negative tolerance, zero tolerance, extremely large tolerance
  2. Boundary conditions: tolerance exactly matching mass difference, just under/over tolerance limit
  3. Interaction with modifications: how tol_is_ppm behaves with fixed and variable modifications (the existing tests with modifications don't exercise the new parameter)
  4. Internal state verification: verify that min_gap_ and max_gap_ are calculated correctly for both tolerance modes (as shown in the Tagger.cpp constructor snippet)

The coding guidelines require unit tests for new functionality, and these edge cases are important for ensuring robustness.

Based on coding guidelines

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9902a72 and 450f745.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/Tagger_test.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/tests/class_tests/openms/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for new functionality

Files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
🧠 Learnings (6)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
🧬 Code graph analysis (1)
src/tests/class_tests/openms/source/Tagger_test.cpp (1)
src/openms/source/CHEMISTRY/Tagger.cpp (1)
  • Tagger (94-148)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (python)

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/tests/class_tests/openms/source/Tagger_test.cpp (3)

340-345: Strengthen assertion to verify the specific claim.

The comment states that tags requiring the 0.025 Da error match should NOT be found (since PEP chain is broken by the large error), but line 345 only checks tags_good_tol.size() != 0 without verifying that specific claim. Consider adding an explicit assertion to verify that tags from the properly-matched portion are found while tags requiring the out-of-tolerance match are absent.

Apply this diff to add a more specific assertion:

  // Should NOT find tags requiring the 0.025 Da error match (PEP chain broken by large error)
  // The tag "PEP" might not be found because the third P has 0.025 Da error (outside tolerance)
- // But we should still find tags from the good portion of the sequence
+ // But we should still find tags from the good portion of the sequence (PE with 0.015 Da error)
  TEST_NOT_EQUAL(tags_good_tol.size(), 0)  // Should find some tags
+ TEST_EQUAL(tags_good_tol.find("PE") != tags_good_tol.end(), true)  // Should find PE (0.015 Da error within 0.02 Da tolerance)

456-477: Backward compatibility verified, consider strengthening.

The test correctly verifies that omitting the tol_is_ppm parameter preserves the default ppm behavior. However, it only checks size equality. Consider also verifying that the actual tag sets are identical, not just their sizes, to strengthen the backward compatibility guarantee.

Apply this diff to verify content equality:

  // Both should produce identical results (backward compatibility)
  TEST_EQUAL(tags_default.size(), tags_explicit_ppm.size())
+ 
+ // Verify actual tag contents are identical, not just sizes
+ std::set<std::string> set_default(tags_default.begin(), tags_default.end());
+ std::set<std::string> set_explicit(tags_explicit_ppm.begin(), tags_explicit_ppm.end());
+ TEST_EQUAL(set_default == set_explicit, true)

479-500: Strengthen test to verify specific expected behavior.

This test only checks that tags_hires.size() != 0, which is insufficient to validate that the absolute Da tolerance mode correctly handles realistic high-resolution mass errors. The test setup deliberately creates 1-2 milliDa shifts that should be matched with 10 ppm tolerance (0.015 Da at 1500 Da), but doesn't verify this matching occurs.

Apply this diff to add more specific assertions:

  // Use 10 ppm in absolute Da mode
  // At 1500 Da: 10 ppm = 0.015 Da = 15 milliDa (covers our 1-2 milliDa shifts)
  Tagger tagger_hires = Tagger(2, 10, 3, 1, 1, StringList(), StringList(), false);
  tagger_hires.getTag(mzs_hires, tags_hires);
  
- // Should find tags with realistic high-resolution mass errors
+ // Should find tags with realistic high-resolution mass errors (1-2 milliDa within 15 milliDa tolerance)
  TEST_NOT_EQUAL(tags_hires.size(), 0)
+ 
+ // Verify we find at least a minimum number of tags given the good quality data
+ // With 4 peaks and small errors, expect at least one 2-AA tag
+ TEST_EQUAL(tags_hires.size() >= 1, true)
+ 
+ // Compare with overly tight tolerance to prove the realistic tolerance is needed
+ std::vector<std::string> tags_too_tight;
+ Tagger tagger_too_tight = Tagger(2, 0.0005, 3, 1, 1, StringList(), StringList(), false);  // 0.5 milliDa - too tight
+ tagger_too_tight.getTag(mzs_hires, tags_too_tight);
+ TEST_EQUAL(tags_hires.size() > tags_too_tight.size(), true)  // Realistic tolerance should find more
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 450f745 and 1bad31c.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/Tagger_test.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/tests/class_tests/openms/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for new functionality

Files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
🧠 Learnings (7)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Ensure existing tests pass before suggesting changes

Applied to files:

  • src/tests/class_tests/openms/source/Tagger_test.cpp
🧬 Code graph analysis (1)
src/tests/class_tests/openms/source/Tagger_test.cpp (1)
src/openms/source/CHEMISTRY/Tagger.cpp (1)
  • Tagger (94-148)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
🔇 Additional comments (2)
src/tests/class_tests/openms/source/Tagger_test.cpp (2)

237-313: Well-designed test with comprehensive assertions.

This test effectively validates the difference between ppm and absolute Da tolerance modes with multiple strong assertions:

  • Verifies both modes find tags (non-zero checks)
  • Confirms the sets differ (addressing the key feature)
  • Validates Da mode finds more tags (≥ comparison)
  • Proves Da mode finds exclusive tags not found by ppm mode
  • Requires at least 10% improvement in Da mode

The test setup with deliberate 0.01 Da errors on large fragments (1000-2000 Da) properly demonstrates the practical benefit of the new feature for top-down proteomics workflows.


417-454: Clear demonstration of the tolerance mode difference.

This test effectively illustrates the practical motivation for the new feature: at large m/z values (2000 Da), applying tolerance to the fragment m/z (Da mode) provides ~20× wider tolerance than applying it to amino acid mass (ppm mode). The 0.05 Da shift scenario demonstrates that Da mode will successfully match fragments that ppm mode would miss.

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.

4 participants