Skip to content

MapAlignmentAlgorithmIdentification: Made align function work on const data - #7973

Merged
cbielow merged 12 commits into
OpenMS:developfrom
subCode321:alignwork
Apr 14, 2025
Merged

cbielow merged 12 commits into
OpenMS:developfrom
subCode321:alignwork

Conversation

@subCode321

@subCode321 subCode321 commented Apr 9, 2025 •

Copy link
Copy Markdown
Contributor

Description

Fixes #7972

The PR marks all input data const so that they are not modified or re-assigned during runs

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

Summary by CodeRabbit

  • New Features

    • Introduced a new method for retrieving the best-scoring peptide hit, enhancing functionality.
    • Added a static method to dynamically determine score comparison logic based on scoring orientation.
  • Refactor

    • Updated key routines to enforce immutability of input data, preventing unintended modifications.
    • Streamlined sorting process by delegating score comparison logic to a dedicated function, improving modularity and clarity.
  • Bug Fixes

    • Modified existing peptide hit entries to ensure accurate scoring and sequence representation.

@coderabbitai

coderabbitai Bot commented Apr 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request updates several method signatures within the MapAlignmentAlgorithmIdentification class to use const references instead of non-const references. This change enforces immutability for input parameters in methods such as setReference, align, and getRetentionTimes_. Additionally, the implementation of the getRetentionTimes_ method in the source file is restructured to enhance clarity and safety while maintaining the overall functionality. A new method, getBestScoringHit, is introduced to facilitate scoring comparisons. Furthermore, a static method getScoreComparator is added to the PeptideIdentification class to improve sorting logic.

Changes

File(s) Change Summary
src/openms/include/.../MapAlignmentAlgorithmIdentification.h Updated method signatures in MapAlignmentAlgorithmIdentification (i.e., setReference, align, and getRetentionTimes_) to take const references. Changed iterator type to ConstIterator in getRetentionTimes_. Added new method getBestScoringHit.
src/openms/source/.../MapAlignmentAlgorithmIdentification.cpp Modified the getRetentionTimes_ implementation by updating parameters to const, ensuring data remains unaltered during iteration. Introduced logic to utilize getBestScoringHit.
src/openms/include/.../PeptideIdentification.h Added static method getScoreComparator to return a comparator function based on the higher_score_better parameter.
src/openms/source/.../PeptideIdentification.cpp Updated sort method to utilize getScoreComparator for sorting logic based on scores.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Algorithm
    Caller->>Algorithm: Call getRetentionTimes_(data, rt_data)
    loop For each peptide in data
        Algorithm->>Algorithm: Check if peptide hits exist
        alt Hits available
            Algorithm->>Algorithm: Sort hits and perform score check
        else
            Algorithm->>Algorithm: Skip processing for this peptide
        end
    end
    Algorithm->>Caller: Return result (bool)
Loading

Assessment against linked issues

Objective Addressed Explanation
Make align function work on const data [#7972] ✅

Poem

I'm a bunny with a joyful heart,
Hopping over code changes with a hop and a dart.
Const correctness now leads our way,
Keeping our data safe every day.
With a twitch of my whiskers, I celebrate in style—
CodeRabbit hops ahead, mile after mile!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (1)

221-299: Consider breaking down the complex method

The static analysis hint flags this method as complex. While the current changes are good, consider future refactoring to break this method into smaller, more focused functions to improve readability and maintainability.

A potential refactoring approach would be to extract the feature handling logic (lines 241-275) and unassigned peptides logic (lines 281-286) into separate private methods.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-344: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L344
Complex Method

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b36cdec and 94e59bd.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (6 hunks)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (1)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (1)
  • better_ (160-160)
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-344: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L344
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • 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 (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (8)
src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (2)

96-109: Improved code structure with better null-safety

The restructuring of this method significantly improves safety by checking for empty hits before attempting to sort and access them. The nested conditionals make the control flow more explicit and prevent potential null reference issues.


181-183: Good change to enforce const correctness

Changing the parameter to const PeakMap& experiment and using ConstIterator is a proper application of const correctness. This ensures that the function doesn't modify the input data unintentionally and allows it to work with constant data.

src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (6)

58-58: Good application of const correctness in setReference

Changing the parameter type to const DataType& data correctly indicates that this method doesn't modify the input data, allowing it to work with constant references.


86-87: Improved align method signature with const correctness

Changing the parameter to const std::vector<DataType>& data is appropriate as the method should not modify the input vector. This allows the method to be called with constant data, improving usability.


204-204: Consistent const correctness application

This change to const PeakMap& experiment matches the implementation in the .cpp file and maintains the pattern of const correctness throughout the class.


221-222: Proper template method const correctness

Making the template parameter const (const MapType& features) aligns with the rest of the changes and allows this method to be called with constant data.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-344: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L344
Complex Method


239-239: Correct iterator usage for const parameter

Using ConstIterator instead of Iterator is necessary when iterating over a const object. This change is required to maintain consistency with the const parameter change.


248-278: Well-implemented const correctness in nested code

The changes to use const references and const pointers throughout this section properly implement const correctness at all levels. Particularly good is the use of const auto& for iterating over peptide IDs and hits.

@cbielow

cbielow commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

Please ensure OpenMS compiles locally before pushing to GitHub, since this will invoke CI needlessly.

@subCode321

Copy link
Copy Markdown
Contributor Author

Please ensure OpenMS compiles locally before pushing to GitHub, since this will invoke CI needlessly.

yes, will take care of that

@subCode321

Copy link
Copy Markdown
Contributor Author

@cbielow , kindly check now

@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/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (1)

221-295: Refined const usage with read-only iterators and best-scoring-hit checks.

  1. Switching to MapType::ConstIterator (line 239) and std::vector<PeptideIdentification>::const_iterator (line 248) clarifies that the code only reads map data.
  2. The logic for finding and verifying the best-scoring hit with getBestScoringHit ensures a null pointer is never dereferenced (lines 259–262).

Additionally, static analysis flags this method for complexity. Consider refactoring certain sections (e.g., unassigned peptides vs. feature-centroid logic) into smaller subroutines to improve maintainability.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0aaee0e and 4ebfa4c.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10 hunks)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (2)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (6)
  • getBestScoringHit (339-340)
  • getRetentionTimes_ (182-183)
  • getRetentionTimes_ (194-194)
  • getRetentionTimes_ (204-204)
  • getRetentionTimes_ (221-295)
  • getRetentionTimes_ (221-221)
src/topp/FeatureFinderIdentification.cpp (1)
  • features (176-265)
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • 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, default)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (8)
src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (5)

94-110: Adopt const references and ensure null checks remain valid.

The updated function signature and the use of const_iterator correctly ensure that the input vector and its contents are not accidentally modified. The call to getBestScoringHit is safe under the condition if (!pep_it->getHits().empty()), but keep in mind that the returned pointer can be nullptr when called on empty hits in other contexts. Here, the null-check is implicitly guaranteed by if (!pep_it->getHits().empty()), so the usage is correct.


143-143: Good const correctness enhancement.

Changing the signature of getRetentionTimes_ to accept a const IdentificationData& parameter prevents unintentional modifications of the input data and aligns with best practices.


181-190: Const-qualification for PeakMap aligns usage with read-only semantics.

Using const PeakMap& and PeakMap::ConstIterator ensures the method cannot modify the underlying data. This is a solid improvement for clarity and correctness.


354-358: Consistent template instantiations with const references.

Changing the explicit template instantiations to match the updated const references ensures consistency across the codebase and avoids linker mismatches.


359-372: Safely returning a pointer to the best-scoring hit.

The new helper method correctly returns nullptr if no hits are provided and otherwise returns a pointer to the best-scoring entry. Ensure that callers do not store this pointer beyond the lifetime of the original hits vector. Within the current usage, this is handled correctly.

src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (3)

58-74: Improved const-correctness for setReference.

Receiving the data as a const DataType& prevents accidental mutations inside setReference. This change matches the function’s usage, which only reads the input.


86-125: Align method updated to accept const reference.

Fetching input data as const std::vector<DataType>& underlines that the method doesn’t alter the original data. This is a beneficial practice to safeguard against unintended side effects.


340-340: Helper function declaration is clear.

Declaring getBestScoringHit in the header improves code accessibility and consolidates logic to retrieve the best peptide hit. No issues spotted here.

@subCode321

Copy link
Copy Markdown
Contributor Author

@cbielow @timosachsenberg .. is there any test file against which I can test my code. There are many in the code repository and I've tested it out and it's working fine but is there any specific test file that you would want me to test against?


const PeptideHit* MapAlignmentAlgorithmIdentification::getBestScoringHit(
const std::vector<PeptideHit>& hits,
const std::function<bool(double, double)>& better)

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.

using better here is very dangerous since it may be defined as

better_ = [](double, double)
        {return true;};

in which case sort() will fail at runtime.
You need to reproduce

void PeptideIdentification::sort()
  {
    if (higher_score_better_)
    {
      std::stable_sort(hits_.begin(), hits_.end(), PeptideHit::ScoreMore());
    }
    else
    {
      std::stable_sort(hits_.begin(), hits_.end(), PeptideHit::ScoreLess());
    }
  }

which is hard, since you basically need to copy the code (which is dangerous in terms of consistency and maintenance).
So either:
Refactor PeptideIdentification::sort(), so you can pull out the information you need from a fine-grained function which is used in both PeptideIdentification::sort() and your code, or bite the performance bullet and copy the hits, sort them like before (much less preferred, since your linear scan for the best hit is much better).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay, working on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done @cbielow

@subCode321
subCode321 requested a review from cbielow April 12, 2025 06:03

@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/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (1)

194-194: Improved const-correctness for IdentificationData version.

The comment about "id_data" not being "const" is now outdated since the parameter is now properly marked as const. Consider removing or updating this comment.

-    // "id_data" can't be "const" here or template resolution will fail
+    // Parameter is now const as template resolution supports const parameters
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ebfa4c and bdd798d.

📒 Files selected for processing (4)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10 hunks)
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h (1 hunks)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (4 hunks)
  • src/openms/source/METADATA/PeptideIdentification.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/openms/source/METADATA/PeptideIdentification.cpp (1)
src/openms/include/OpenMS/METADATA/PeptideIdentification.h (2)
  • getScoreComparator (135-135)
  • sort (142-142)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (3)
src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (2)
  • getBestScoringHit (359-371)
  • getBestScoringHit (359-359)
src/openms/include/OpenMS/METADATA/PeptideIdentification.h (1)
  • isHigherScoreBetter (103-103)
src/openms/source/METADATA/PeptideIdentification.cpp (2)
  • isHigherScoreBetter (134-137)
  • isHigherScoreBetter (134-134)
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
🔇 Additional comments (13)
src/openms/include/OpenMS/METADATA/PeptideIdentification.h (1)

134-135: Good addition of a utility method for score comparison.

The new getScoreComparator method abstracts the comparison logic based on the score orientation, which improves code reusability and readability.

src/openms/source/METADATA/PeptideIdentification.cpp (2)

212-223: Clean implementation of the score comparator function.

The implementation properly returns the appropriate comparator based on the score orientation parameter, enhancing modularity by separating comparison logic from sorting operations.


225-228: Good refactoring of the sort method.

The updated implementation now uses the new getScoreComparator utility and std::stable_sort, which preserves the relative order of equal elements, ensuring consistent results.

src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10)

58-58: Improved const-correctness for setReference method.

Changing the parameter type to const DataType& ensures the method doesn't modify the input data, which is the expected behavior for a setter method.


86-86: Enhanced const-correctness for align method.

Using const std::vector<DataType>& for the input parameter is appropriate since this method doesn't need to modify the input data, improving safety and potentially enabling compiler optimizations.


182-183: Appropriate const-correctness for getRetentionTimes_ method.

Changing the parameter type to a const reference for the peptides vector ensures the method doesn't modify the input data.


204-204: Consistent const-correctness for PeakMap version.

This change maintains consistency with the other method updates for const-correctness.


221-221: Enhanced const-correctness for MapType version.

Changing the parameter type to const MapType& aligns with the const-correctness improvements throughout the class.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method


239-239: Appropriate iterator type change.

Using ConstIterator instead of Iterator is necessary to maintain const-correctness when iterating over a const container.


248-249: Proper const iterator usage.

Using std::vector<PeptideIdentification>::const_iterator is consistent with the const-correctness improvements.


259-260: Good use of the new utility method.

Using the new getBestScoringHit method improves code readability and maintainability by abstracting the logic for finding the best-scoring hit.


262-262: Const-safety throughout the call chain.

Consistent use of const references and pointers ensures const-correctness is maintained throughout the entire process.


331-340: Well-documented utility method addition.

The new getBestScoringHit method is well-documented with clear parameters and return value descriptions. This utility function encapsulates finding the best-scoring hit, which improves code reusability.

The static analysis tool flagged the enclosing method as complex. While this isn't directly related to your current changes, you might want to consider further refactoring opportunities in this area in the future.

@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 (2)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (2)

193-194: Update outdated comment above this line.

The comment "id_data can't be const here or template resolution will fail" is no longer accurate since you've successfully made the parameter const.

-    // "id_data" can't be "const" here or template resolution will fail
+    // Parameter is now const as the implementation no longer needs to modify it

221-295: Consider refactoring this complex method.

The static analysis tool flagged this method as complex. While not directly related to your current changes, consider breaking it down into smaller, more focused methods in the future.

You could extract the logic for handling feature RTs (lines 242-270) and the logic for removing duplicates (lines 284-294) into separate private methods to reduce the complexity.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdd798d and 4d72e81.

📒 Files selected for processing (1)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • 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 (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (9)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (9)

58-58: Improved const-correctness for setReference method.

This change ensures that the input data parameter is treated as read-only, which is a good practice for parameters that aren't modified.


86-86: Improved const-correctness for align method.

The input data vector is now marked as const, preventing accidental modification and allowing the method to work with const references.


182-183: Improved const-correctness for getRetentionTimes_ method.

This change correctly marks the peptides parameter as const since the method doesn't need to modify it.


204-204: Improved const-correctness for getRetentionTimes_ method (PeakMap overload).

This change correctly marks the experiment parameter as const.


221-221: Improved const-correctness for getRetentionTimes_ template method.

The features parameter is now properly marked as const.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method


239-240: Updated iterator type to match const parameter.

Changed from Iterator to ConstIterator to ensure compatibility with the const features parameter.


248-250: Updated to const_iterator for peptide identifications.

This change ensures const-correctness is maintained throughout the method.


259-263: Added new helper method to find the best scoring hit.

This is a good improvement that encapsulates the logic for finding the best hit and adds a null check before accessing the hit.


331-339: New utility method to find the best-scoring PeptideHit.

This method abstracts the logic for finding the best-scoring hit, improving code organization and reusability. It properly handles the scoring direction (higher vs. lower is better) and returns nullptr for empty lists.

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

Looks good, thanks.

I cannot find a test for MapAlignmentIdentification that uses more than one PeptideHit, so your refactoring of .sort() is currently not tested in this context.

Please replace
https://github.com/OpenMS/OpenMS/blob/develop/src/tests/class_tests/openms/data/MapAlignmentAlgorithmIdentification_test_1.idXML#L8
with something like:

    <PeptideHit score="27.1" sequence="IGNORETHISSECONDBEST" charge="2" aa_before="K" aa_after="D" ></PeptideHit>
    <PeptideHit score="29.1" sequence="VTAFIPPWVK" charge="2" aa_before="K" aa_after="D" ></PeptideHit>

(You should see the test MapAlignmentAlgorithmIdentification_test is still passing).

The solution with std::function surely works, but I'm not sure it does well in terms of performance. This would require some benchmarking. But let's not worry about that for now.


@return Pointer to the best-scoring hit, or nullptr if the list is empty
*/
const PeptideHit* getBestScoringHit(const std::vector<PeptideHit>& hits, const bool isHigherScoreBetter);

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.

Suggested change
const PeptideHit* getBestScoringHit(const std::vector<PeptideHit>& hits, const bool isHigherScoreBetter);
const PeptideHit* getBestScoringHit(const std::vector<PeptideHit>& hits, const bool is_higher_score_better);

@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/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (1)

221-295: Consider refactoring complex method

The static analysis tool flags this method as complex. While your current changes don't add to this complexity (and in fact help reduce it by extracting the getBestScoringHit functionality), you might want to consider further refactoring in the future.

Potential approaches:

  • Extract smaller helper methods for different parts of the logic
  • Simplify the nested conditional structure
  • Consider using algorithm-based approaches instead of manual loops where possible
🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eecc3d7 and 82edd85.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10 hunks)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.cpp
🧰 Additional context used
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • 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 (macos-14, xcode, 15.0.1)
🔇 Additional comments (11)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (11)

58-58: Improved const-correctness in setReference

Good change - making the input parameter const ensures the method won't modify the input data, which aligns with the method's purpose of only reading data to establish a reference.


86-86: Improved const-correctness in align method

Good job making the input data parameter const. This properly communicates to users that the align method doesn't modify the input data vector, improving API clarity and safety.


182-183: Improved const-correctness for PeptideIdentification parameter

Making the peptides parameter const properly reflects that the method only reads from the identifications without modifying them.


194-194: Improved const-correctness for IdentificationData parameter

Making the id_data parameter const is a good change, correctly reflecting that this data is read-only within the method. This also removes the need for the explanatory comment on line 193, but you might want to keep it for clarity.


204-204: Improved const-correctness for PeakMap parameter

Good change - making the experiment parameter const properly reflects that the method doesn't modify the input experiment data.


221-221: Improved const-correctness for MapType template method

Making the features parameter const is consistent with the other getRetentionTimes_ methods and correctly indicates that the method doesn't modify the input data.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method


239-240: Updated iterator type to match const parameter

Correctly updated to ConstIterator to match the now-const features parameter. This ensures const-correctness throughout the method.


248-250: Updated to const_iterator for consistency

Good change - using const_iterator is consistent with the const-correctness approach and properly reflects that you're not modifying the peptide identifications during iteration.


259-261: Improved handling of best scoring hit

Good improvement! Using the new getBestScoringHit method instead of assuming the first hit is the best one makes the code more robust. The null check before accessing the score is also a good defensive programming practice.


262-262: Updated accessor syntax for pointer

Correctly changed from dot notation to arrow notation to match the new pointer return type from getBestScoringHit.


331-339: Well-designed utility method for finding best scoring hit

This new method is a good addition that enhances the functionality of the class. It properly handles the case of empty hit lists by returning nullptr, and takes into account whether higher or lower scores are better.

The method signature matches what reviewer cbielow suggested in previous comments. This is a good implementation of the requested change.

Comment on lines +8 to +10
<PeptideHit score="27.1" sequence="IGNORETHISSECONDBEST" charge="2" aa_before="K" aa_after="D" >
</PeptideHit>
<PeptideHit score="29.1" sequence="VTAFIPPWVK" charge="2" aa_before="K" aa_after="D" >

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The tests are passing locally

I ran
ctest -R MapAlignmentAlgorithmIdentification_test

@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 (2)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (2)

182-183: Update the comment on line 193.

Line 193 contains a comment stating "id_data" can't be "const" here or template resolution will fail", but the parameter on line 194 is now const. This comment is now inconsistent with the actual code.

-    // "id_data" can't be "const" here or template resolution will fail
+    // Parameter is now const since the template resolution issue was resolved

Also applies to: 193-194


221-295: Consider simplifying this complex method in the future.

Static analysis flags this method as complex. While the current changes don't increase complexity, consider breaking this method down into smaller, more focused methods in future refactoring efforts.

🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82edd85 and 4e81515.

📒 Files selected for processing (1)
  • src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (10 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeFactor
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h

[notice] 221-351: src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h#L221-L351
Complex Method

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (6)
src/openms/include/OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithmIdentification.h (6)

58-58: Great improvement on const correctness.

Making setReference parameter const enforces that the input data will not be modified, which aligns well with the method's purpose of only using the data to establish a reference.


86-86: Good job enforcing const correctness for align method.

Input data shouldn't be modified during alignment, and this change properly enforces that constraint.


204-204: Consistent application of const for remaining getRetentionTimes_ methods.

Good work maintaining consistency across all overloads of this method.

Also applies to: 221-221


239-240: Proper iterator usage with const containers.

Changing to ConstIterator and const_iterator correctly maintains const correctness when iterating over const containers.

Also applies to: 248-250


259-263: Good approach for finding the best-scoring hit.

Using a dedicated utility method getBestScoringHit improves code maintainability and readability compared to directly accessing hits. This addresses the previous review comment.


331-339: Well-designed utility method for finding best hit.

The new getBestScoringHit method has a clear purpose and signature, correctly handling potential empty hit lists by returning nullptr.

@subCode321
subCode321 requested a review from cbielow April 14, 2025 10:46

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

looks good to me!
Thanks!

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.

Make align function work on const data

3 participants