Skip to content

refactor: peptide id - move rank to metavalue - #7997

Merged
timosachsenberg merged 28 commits into
developfrom
move_rank_to_meta
May 13, 2025
Merged

timosachsenberg merged 28 commits into
developfrom
move_rank_to_meta

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 24, 2025 •

Copy link
Copy Markdown
Contributor

This pull request refactors rank handling in the OpenMS codebase by replacing it with a new approach that stores ranks as meta values. It also updates related rank-based operations and simplifies the code structure.

If a rank got never assigned, no meta value needs to be stored and written out. This "default" is rank=0.
Setting a rank to default with setRank(0) prevents that it is written out to idXML (as rank 0 is implicit).
When importing data from external formats like pepXML or mzIdentML, OpenMS reads the rank information provided. If the imported rank is not 0 (or 1 depending how they are based in the file format), OpenMS stores it as a meta value to preserve the original ranking information from the external source. This ensures that any non-default ranks assigned by other search engines are retained during data processing.


This pull request introduces significant changes to how peptide hit ranks are managed in the OpenMS library, transitioning from a dedicated member variable to storing ranks as meta values. It also includes updates to related methods, file handlers, and tests to align with this new approach. Below is a summary of the most important changes:

Peptide Hit Rank Refactoring:

  • Removed the rank_ member variable from PeptideHit and replaced it with a meta value using the key "rank" for backward compatibility. This ensures ranks are stored as meta values instead of a direct class member. ([[1]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-f57d0fe81ff42dba982fa9f9f2d4d83db5845f66fff737b3a0902e845f285e56L290-L292), [[2]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-70fb8b85bc442403ca3eae6bc8b2623f975050af018cf10e96323927c24c5ff6L143-R152), [[3]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-70fb8b85bc442403ca3eae6bc8b2623f975050af018cf10e96323927c24c5ff6L332-R349))
  • Updated the PeptideHit constructor and setRank method to handle the rank as a meta value, with default rank (0) not being stored explicitly. ([[1]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-70fb8b85bc442403ca3eae6bc8b2623f975050af018cf10e96323927c24c5ff6R10-R85), [[2]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-70fb8b85bc442403ca3eae6bc8b2623f975050af018cf10e96323927c24c5ff6L332-R349))
  • Modified the getRank method to retrieve the rank from meta values, defaulting to 0 if not set. ([src/openms/source/METADATA/PeptideHit.cppL143-R152](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-70fb8b85bc442403ca3eae6bc8b2623f975050af018cf10e96323927c24c5ff6L143-R152))

Updates to Filtering and Sorting:

  • Simplified the filterHitsByRank method in IDFilter by removing explicit rank calculation logic and instead relying on the updated rank handling mechanism. ([src/openms/include/OpenMS/PROCESSING/ID/IDFilter.hL902-R927](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-551b8cf5af907a3a1534ef80b20ed5ca34e1ce4c87cf864e218d6188d895eef5L902-R927))
  • Removed the updateHitRanks method from IDFilter as it is no longer necessary with the new rank handling. ([src/pyOpenMS/pxds/IDFilter.pxdL80](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-3b3bbe829f276767eeea58af38db0dce7c9f1a428a33b3e53cb22524c5304dd3L80))

File Format Adjustments:

  • Updated mzIdentML and pepXML file handlers to correctly handle the 0-based rank system in OpenMS while maintaining compatibility with 1-based rank formats in external files. ([[1]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-e4574eb9f0cd35d749b40f507752fde2333bd97f18a348e27eabd4aff75797e9L2043-R2043), [[2]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-f4393735b439104f428d4c0b4ed61c37138594bf5ce2922c521b762f9b015978L339-R340), [[3]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-5b4ff2575a11d9aef1db84b0346d167d37a6e904cb6381437fdfe52dbf1ea11aL643-R643))
  • Adjusted rank handling in file I/O to ensure consistent rank conversion between OpenMS and external formats. ([[1]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-f4393735b439104f428d4c0b4ed61c37138594bf5ce2922c521b762f9b015978L2098-R2099), [[2]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-5b4ff2575a11d9aef1db84b0346d167d37a6e904cb6381437fdfe52dbf1ea11aL1307-R1308))

Test Updates:

  • Updated unit tests to reflect the new 0-based rank system, ensuring compatibility with the revised PeptideHit implementation. ([[1]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-88ccad1148b828c54c4c317c0f630fedd3bf2c942d2ef2ca69fb225066b13c37L96-R96), [[2]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-88ccad1148b828c54c4c317c0f630fedd3bf2c942d2ef2ca69fb225066b13c37L227-R227), [[3]](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-88ccad1148b828c54c4c317c0f630fedd3bf2c942d2ef2ca69fb225066b13c37L370-R370))

Miscellaneous:

  • Added a new constant RANK in Constants.h to standardize the meta value key for rank. ([src/openms/include/OpenMS/CONCEPT/Constants.hR571-R575](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-3da0f7da14951308957e047a5ccc6bebb8a11e49a080e2fe884685d2d2da4056R571-R575))
  • Updated the CHANGELOG to document the removal of rank_ and related methods, as well as the transition to storing ranks as meta values. ([CHANGELOGL28-R29](https://github.com/OpenMS/OpenMS/pull/7997/files#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdbaL28-R29))

Summary by CodeRabbit

  • New Features

    • Peptide hit rank is now stored as a user parameter, improving metadata consistency across formats.
    • Added a dedicated user parameter name for peptide hit rank.
  • Bug Fixes

    • Ensured correct conversion between 0-based and 1-based rank indexing when importing/exporting identification results in mzIdentML and pepXML formats.
    • Addressed edge cases for rank handling in special mzIdentML data types.
  • Refactor

    • Simplified internal storage and management of peptide hit ranks by removing explicit rank members and methods.
    • Streamlined filtering and ranking logic for peptide identifications.
  • Style

    • Updated code indentation for improved readability.
  • Documentation

    • Clarified documentation regarding rank storage in peptide hits.
  • Tests

    • Updated test data and assertions to reflect changes in rank handling and metadata formatting.
    • Adjusted test output files to include the new rank user parameter and updated significance threshold formatting.
  • Chores

    • Updated changelog to document removal of legacy rank-related methods and member variables.

@coderabbitai

coderabbitai Bot commented Apr 24, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes refactor the PeptideHit class to remove the explicit rank member variable, storing rank as a meta value instead. Static constants for the rank meta key and default value are introduced. Constructors, assignment operators, and methods are updated accordingly. Numerous test output files are updated to include rank as a user parameter in peptide hits. Additionally, rank handling in file formats (mzIdentML, pepXML) is adjusted to convert between 0-based internal and 1-based external indexing. The IDFilter interface is simplified by removing a peptide-based updateHitRanks method.

Changes

File(s) Change Summary
src/openms/include/OpenMS/METADATA/PeptideHit.h
src/openms/source/METADATA/PeptideHit.cpp
Removed explicit rank_ member from PeptideHit; rank is now stored as a meta value. Added static constants for the rank meta key and default value. Updated constructors, assignment operators, and methods to use meta value for rank.
src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h Refactored filterHitsByRank template function to simplify rank filtering logic by removing auxiliary rank vectors and performing filtering in a single pass.
src/openms/include/OpenMS/CONCEPT/Constants.h Added a new constant string RANK in OpenMS::Constants::UserParam namespace for the rank user parameter name.
src/pyOpenMS/pxds/IDFilter.pxd Removed the method declaration updateHitRanks for vector of PeptideIdentification references from the IDFilter class.
src/openms/source/FORMAT/MzIdentMLHandler.cpp Adjusted rank handling for SpectrumIdentificationItem: subtract 1 when reading rank attribute (1-based to 0-based), add 1 when writing rank attribute (0-based to 1-based).
src/openms/source/FORMAT/PepXMLFile.cpp Adjusted rank handling: decrement rank by 1 when reading hit_rank attribute (pepXML 1-based to 0-based), increment rank by 1 when writing hit_rank attribute.
src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp Adjusted rank passed to PeptideHit constructor by subtracting 1 to convert from 1-based mzIdentML rank to 0-based internal rank.
src/openms/source/FORMAT/PercolatorInfile.cpp Adjusted rank passed to PeptideHit constructor by subtracting 1 (rank - 1) to convert from 1-based to 0-based rank.
src/tests/class_tests/openms/source/PepXMLFile_test.cpp Updated test assertions for PeptideHit rank to expect 0 instead of 1, reflecting 0-based rank indexing internally.
src/tests/topp/IDFileConverter_10_output.idXML
src/tests/topp/IDFileConverter_15_output.idXML
src/tests/topp/IDFileConverter_16_output.idXML
src/tests/topp/IDFileConverter_22_output.idXML
src/tests/topp/IDFileConverter_24_output.idXML
src/tests/topp/IDFileConverter_26_output.idXML
src/tests/topp/IDFileConverter_2_output.idXML
src/tests/topp/IDFileConverter_6_output.idXML
Updated test output XML files: changed significance_threshold from integer to float and added a <UserParam> with name="rank" and integer value to each <PeptideHit>.
src/tests/topp/OpenPepXLLF_output.idXML
src/tests/topp/OpenPepXLLF_output2.idXML
src/tests/topp/OpenPepXL_output.idXML
Updated idXML test outputs: added <UserParam name="rank" type="int" value="..."/> to <PeptideHit> entries and updated metadata (file paths, version, date).
src/tests/topp/OpenPepXLLF_output.mzid
src/tests/topp/OpenPepXL_output.mzid
Updated mzIdentML test outputs: added <userParam name="rank" value="..."/> to <SpectrumIdentificationItem> entries and updated creation date, software version, and file paths.
src/tests/topp/OpenPepXLLF_output.xquest.xml Updated xQuest XML test output: added rank="1" attribute to <search_hit> elements and updated metadata (date, paths).
src/tests/topp/THIRDPARTY/Chy_test.idXML
src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML
src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML
src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML
src/tests/topp/THIRDPARTY/MSGFPlusAdapter_1_out.idXML
Updated third-party adapter test outputs: added rank user parameter to peptide hits, updated file paths, parameter values, and minor score adjustments.
src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML Updated CometAdapter test output: added rank user parameters with values 1 to 4 to peptide hits, updated file paths, date, and version metadata.
src/tests/topp/CMakeLists.txt Added "SearchDatabase" to the whitelist of XML tags/attributes ignored during fuzzy diff in the TOPP_PSMFeatureExtractor_2_out test.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PeptideHit
    participant MetaInfoInterface

    User->>PeptideHit: setRank(value)
    PeptideHit->>MetaInfoInterface: setMetaValue("rank", value)
    Note right of MetaInfoInterface: Stores rank as meta value

    User->>PeptideHit: getRank()
    PeptideHit->>MetaInfoInterface: getMetaValue("rank")
    MetaInfoInterface-->>PeptideHit: returns value or DEFAULT_RANK
    PeptideHit-->>User: returns rank
Loading

Possibly related PRs

  • refactor: reduce the use of assignRanks #7991: Removes assignRanks() and sortByRanks() methods and refactors rank assignment logic, complementing the removal of explicit rank members in PeptideHit and simplifying rank handling.

Suggested labels

Review effort 2/5

Suggested reviewers

  • jpfeuffer

Poem

A hop and a skip, the rank hops away,
No longer a member, in meta it’ll stay.
With constants to guide us, and keys set anew,
The tests now all show what meta can do.
As bunnies we cheer for this refactored delight—
Rank in its burrow, tucked safely from sight! 🐇
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b457239 and ee624f3.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h (2 hunks)
  • src/openms/source/METADATA/PeptideHit.cpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h
  • src/openms/source/METADATA/PeptideHit.cpp
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
  • 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 (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
✨ Finishing Touches
  • 📝 Generate Docstrings

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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[bot]

This comment was marked as outdated.

@timosachsenberg

This comment was marked as outdated.

@jpfeuffer

Copy link
Copy Markdown
Contributor

Can you comment on the reasoning for still having the "default" rank?

coderabbitai[bot]

This comment was marked as resolved.

@timosachsenberg

timosachsenberg commented May 12, 2025 •

Copy link
Copy Markdown
Contributor Author

This is mainly for backwards compatibility reasons.
If a rank got never assigned, no meta value needs to be stored and written out. This "default" is rank=0.
Setting a rank to this default rank with setRank(0) will again not write it out (as it is implicit).
When importing data from external formats like pepXML or mzIdentML, OpenMS reads the rank information provided. If the imported rank is not 0, OpenMS stores it as a meta value to preserve the original ranking information from the external source. This ensures that any non-default ranks assigned by other search engines are retained during data processing.

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc0516 and 09c1ca8.

📒 Files selected for processing (7)
  • src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h (1 hunks)
  • src/tests/topp/CMakeLists.txt (1 hunks)
  • src/tests/topp/THIRDPARTY/Chy_test.idXML (2 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML (2 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML (7 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML (3 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML
  • src/tests/topp/THIRDPARTY/Chy_test.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • 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-13, xcode, 14.2)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: cppcheck-test
🔇 Additional comments (1)
src/tests/topp/CMakeLists.txt (1)

3137-3137: Added 'SearchDatabase' to whitelist for test comparison - LGTM.

This change adds "SearchDatabase" to the whitelist for the diff comparison in the PSMFeatureExtractor test output. This is appropriate as it aligns with the PR's refactoring of rank handling, which affects metadata in test output files. When ranks are stored as meta values instead of member variables, differences in XML output are expected, and this whitelist addition ensures the test properly validates the new behavior.

@timosachsenberg
timosachsenberg requested a review from jpfeuffer May 12, 2025 14:03
@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Can you comment on the reasoning for still having the "default" rank?

I removed it. Just use plain 0.

@timosachsenberg
timosachsenberg enabled auto-merge (squash) May 12, 2025 18:22
@timosachsenberg
timosachsenberg requested a review from cbielow May 13, 2025 05:58
@timosachsenberg timosachsenberg changed the title Move rank to meta refactor: peptide id - move rank to metavalue May 13, 2025

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

All fine with me. Didn't check code logic in detail.
Based on description and overall look, looks good.

rank = StringManager::convert(spectrumIdentificationItemElement->getAttribute(CONST_XMLCH("rank"))).toInt();
if (rank == 0)
{
// MzIdentML ranks are typically 1-based. For some special data (PMF) it can be 0.

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.

What the heck? 😂 Do we still need mzidentml?

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.

I think MSGFPlus uses it? not sure though...

}

f << "\t\t<search_hit hit_rank=\"1\" peptide=\""
f << "\t\t<search_hit hit_rank=\"" << String(h.getRank() + 1) << "\" peptide=\"" // rank in pepXML is 1-based, 0-based in OpenMS

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.

So this was never written to pepxml anyway?

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.

yep

@timosachsenberg
timosachsenberg disabled auto-merge May 13, 2025 11:44
@timosachsenberg
timosachsenberg merged commit 4f8e01d into develop May 13, 2025
@timosachsenberg
timosachsenberg deleted the move_rank_to_meta branch May 13, 2025 11:44
@coderabbitai coderabbitai Bot mentioned this pull request Jul 3, 2025
5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Oct 14, 2025
4 of 5 tasks
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.

2 participants