Skip to content

refactor: reduce the use of assignRanks - #7991

Merged
timosachsenberg merged 9 commits into
developfrom
reduce_assign_ranks
May 12, 2025
Merged

timosachsenberg merged 9 commits into
developfrom
reduce_assign_ranks

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 22, 2025 •

Copy link
Copy Markdown
Contributor

Description

Having assignRanks() in PeptideIdentification was kind of a strange design decision (probably motivated by some file formats).
In principle, a simple sort is sufficient to implicitly assign ranks to peptide hits based on the main score (e.g., the order in the getHits() vector determines the rank).
This PR is a first step to getting rid of the ranks_ member and further simplify the id datastructures.

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

  • Refactor

    • Removed explicit rank assignment for peptide and protein identifications; hits are now consistently sorted by score.
    • Updated all related processing steps, tools, and visualizations to use sorting instead of rank assignment.
    • Simplified meta value handling and accessors related to significance thresholds.
  • Tests

    • Removed or updated test assertions that verified explicit rank values of hits.
  • Style

    • Minor formatting and metadata consistency improvements in test output files.

End-users will observe peptide and protein hits ordered by score without explicit rank annotations.

@coderabbitai

coderabbitai Bot commented Apr 22, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This change set removes the assignRanks() and sortByRank() methods from the PeptideIdentification class and the assignRanks() method from the ProteinIdentification class. Code throughout the codebase is updated to replace calls to assignRanks() with calls to sort(), shifting from explicit rank assignment to relying on sorting for hit ordering. The IDFilter class is refactored to remove the HasMaxRank predicate and updateHitRanks utility, performing rank calculation and filtering inline within filterHitsByRank. Corresponding tests remove assertions related to ranks and update setup calls accordingly. Several test output files are updated to reflect changes in hit ordering and rank data. No new features or control flow changes are introduced.

Changes

Files / Groups Change Summary
src/openms/include/OpenMS/METADATA/PeptideIdentification.h, src/openms/source/METADATA/PeptideIdentification.cpp Removed assignRanks() and sortByRank() methods from PeptideIdentification class and their implementations; cleaned up meta value handling.
src/openms/include/OpenMS/METADATA/ProteinIdentification.h, src/openms/source/METADATA/ProteinIdentification.cpp Removed assignRanks() method from ProteinIdentification class and its implementation.
src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h Removed HasMaxRank predicate struct and updateHitRanks method; refactored filterHitsByRank to compute ranks and filter inline without helper utilities.
src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithm.cpp, src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithmRanks.cpp, src/openms/source/ANALYSIS/ID/FalseDiscoveryRate.cpp, src/openms/source/ANALYSIS/ID/PercolatorFeatureSetHelper.cpp, src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp, src/topp/LuciphorAdapter.cpp, src/topp/MascotAdapterOnline.cpp, src/topp/MetaProSIP.cpp Replaced calls to assignRanks() with sort() for peptide identifications.
src/openms/source/FORMAT/InspectOutfile.cpp, src/openms/source/FORMAT/MzTab.cpp, src/openms/source/FORMAT/OMSSAXMLFile.cpp, src/openms/source/FORMAT/XTandemXMLFile.cpp Replaced assignRanks() with sort() for peptide/protein identifications in output and conversion code.
src/openms_gui/source/VISUAL/MetaDataBrowser.cpp Replaced assignRanks() with sort() before visualization of peptide and protein identifications.
src/openms/source/METADATA/PeptideIdentification.cpp Removed default meta value for significance threshold; simplified meta value accessors; removed assignRanks() and sortByRank() implementations.
src/openms/source/METADATA/ProteinIdentification.cpp Removed assignRanks() implementation.
src/openms/source/FORMAT/HANDLERS/MzIdentMLDOMHandler.cpp Replaced calls to sortByRank() with sort(); adjusted rank conversion between internal 0-based and mzIdentML 1-based ranks.
src/openms/source/FORMAT/HANDLERS/MzIdentMLHandler.cpp Incremented rank by 1 when writing mzIdentML rank attribute for peptide hits.
src/pyOpenMS/pxds/PeptideIdentification.pxd Removed assignRanks() and sortByRank() method declarations from Python bindings interface.
src/tests/class_tests/openms/source/ConsensusIDAlgorithmAverage_test.cpp, src/tests/class_tests/openms/source/ConsensusIDAlgorithmBest_test.cpp, src/tests/class_tests/openms/source/ConsensusIDAlgorithmRanks_test.cpp, src/tests/class_tests/openms/source/ConsensusIDAlgorithmWorst_test.cpp, src/tests/class_tests/openms/source/IDFilter_test.cpp, src/tests/class_tests/openms/source/InspectOutfile_test.cpp, src/tests/class_tests/openms/source/MzIdentMLFile_test.cpp, src/tests/class_tests/openms/source/PepNovoOutfile_test.cpp, src/tests/class_tests/openms/source/PeptideIdentification_test.cpp, src/tests/class_tests/openms/source/ProteinIdentification_test.cpp Removed or updated test assertions related to hit ranks; replaced assignRanks() calls with sort() in test setups; renamed tests accordingly.
src/tests/topp/FalseDiscoveryRate_7_output.idXML, src/tests/topp/IDFilter_10_output.idXML, src/tests/topp/IDFilter_11_output.idXML, src/tests/topp/IDFilter_24_output.consensusXML, src/tests/topp/PSMFeatureExtractor_2_out.mzid Updated test output files to remove or adjust rank-related data and reflect new hit ordering and metadata formatting.
src/topp/FalseDiscoveryRate.cpp, src/topp/IDFilter.cpp Removed calls to IDFilter::updateHitRanks after filtering steps.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Identification
    participant Hit

    User->>Identification: Add hits
    User->>Identification: sort()
    Identification->>Hit: (Hits are sorted by score)
    Note over Identification: No explicit rank assignment performed
Loading

Suggested labels

Review effort 3/5

Suggested reviewers

  • jpfeuffer

Poem

A bunny hopped through code so dense,
Assigning ranks no longer made sense.
Now sorting hits is all we do,
The old rank dance is bid adieu!
With tests and filters swept anew,
The code is lighter, faster too—
🥕 Here’s to changes, crisp and true!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

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

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

next step could be:

  • removing ranks as member and use a meta value (if absolutely needed)

@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 (2)
src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h (2)

916-924: Floating‑point equality test causes duplicate‑rank artefacts

Using direct equality on two double scores (lit->getScore() != last_score) is brittle – tiny FP round‑off differences will create artificial new ranks.

Consider comparing with a small tolerance or, simpler, compare the ordered scores:

-          if ((double)lit->getScore() != last_score)
+          if (lit->getScore() != last_score) // still raw equality

Better:

constexpr double EPS = 1e-12;
if (std::fabs(lit->getScore() - last_score) > EPS)

This prevents inflated rank numbers when scores differ only by machine precision.


927-977: Inefficient two‑phase erase / copy logic – use erase-remove_if once

The current implementation

  1. Builds a std::vector of iterators,
  2. Erases in reverse order,
  3. Re‑creates ranks,
  4. Copies kept hits to a brand‑new container for the max‑rank step.

This is O(n) extra allocations and considerable code. A single erase-remove_if with a lambda capturing ranks (or recomputing rank on the fly) is clearer and faster:

-          // Apply min_rank filter ...
-          std::vector<typename std::vector<typename IdentificationType::HitType>::iterator> to_remove;
-          ...
-          for (auto it = to_remove.rbegin(); it != to_remove.rend(); ++it)
-          {
-            hits.erase(*it);
-          }
+          hits.erase(
+            std::remove_if(hits.begin(), hits.end(),
+              [&](const auto&, Size idx = 0) mutable
+              {
+                return ranks[idx++] < min_rank;
+              }),
+            hits.end());

A similar single pass can then keep rank <= max_rank. Less code, fewer temporaries, and fewer iterator invalidation pitfalls.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b98927 and e027f5f.

📒 Files selected for processing (35)
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h (0 hunks)
  • src/openms/include/OpenMS/METADATA/ProteinIdentification.h (1 hunks)
  • src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h (1 hunks)
  • src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithm.cpp (1 hunks)
  • src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithmRanks.cpp (1 hunks)
  • src/openms/source/ANALYSIS/ID/FalseDiscoveryRate.cpp (1 hunks)
  • src/openms/source/ANALYSIS/ID/PercolatorFeatureSetHelper.cpp (3 hunks)
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp (1 hunks)
  • src/openms/source/FORMAT/InspectOutfile.cpp (1 hunks)
  • src/openms/source/FORMAT/MzTab.cpp (2 hunks)
  • src/openms/source/FORMAT/OMSSAXMLFile.cpp (1 hunks)
  • src/openms/source/FORMAT/XTandemXMLFile.cpp (1 hunks)
  • src/openms/source/METADATA/PeptideIdentification.cpp (0 hunks)
  • src/openms/source/METADATA/ProteinIdentification.cpp (0 hunks)
  • src/openms_gui/source/VISUAL/MetaDataBrowser.cpp (2 hunks)
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmAverage_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmBest_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmRanks_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmWorst_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/IDFilter_test.cpp (2 hunks)
  • src/tests/class_tests/openms/source/InspectOutfile_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/MzIdentMLFile_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/PepNovoOutfile_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/PeptideIdentification_test.cpp (0 hunks)
  • src/tests/class_tests/openms/source/ProteinIdentification_test.cpp (2 hunks)
  • src/tests/topp/FalseDiscoveryRate_7_output.idXML (1 hunks)
  • src/tests/topp/IDFilter_10_output.idXML (2 hunks)
  • src/tests/topp/IDFilter_11_output.idXML (1 hunks)
  • src/tests/topp/IDFilter_24_output.consensusXML (24 hunks)
  • src/tests/topp/PSMFeatureExtractor_2_out.mzid (4 hunks)
  • src/topp/FalseDiscoveryRate.cpp (0 hunks)
  • src/topp/IDFilter.cpp (0 hunks)
  • src/topp/LuciphorAdapter.cpp (1 hunks)
  • src/topp/MascotAdapterOnline.cpp (1 hunks)
  • src/topp/MetaProSIP.cpp (2 hunks)
💤 Files with no reviewable changes (13)
  • src/openms/source/METADATA/PeptideIdentification.cpp
  • src/topp/FalseDiscoveryRate.cpp
  • src/tests/class_tests/openms/source/PeptideIdentification_test.cpp
  • src/tests/class_tests/openms/source/PepNovoOutfile_test.cpp
  • src/topp/IDFilter.cpp
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmRanks_test.cpp
  • src/tests/class_tests/openms/source/InspectOutfile_test.cpp
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h
  • src/tests/class_tests/openms/source/MzIdentMLFile_test.cpp
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmBest_test.cpp
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmAverage_test.cpp
  • src/tests/class_tests/openms/source/ConsensusIDAlgorithmWorst_test.cpp
  • src/openms/source/METADATA/ProteinIdentification.cpp
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/tests/class_tests/openms/source/ProteinIdentification_test.cpp (2)
src/openms/source/METADATA/PeptideIdentification.cpp (2)
  • sort (226-229)
  • sort (226-226)
src/openms/source/METADATA/ProteinIdentification.cpp (2)
  • sort (574-584)
  • sort (574-574)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
  • 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 (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • GitHub Check: cppcheck-test
🔇 Additional comments (47)
src/tests/topp/IDFilter_10_output.idXML (6)

7-7: Standardize significance_threshold to floating-point
Changed significance_threshold from integer "0" to "0.0" for consistency with floating-point representation.


14-17: Swap ProteinHit accessions to match sorted order
The order and accession of PH_3 and PH_4 have been swapped (now PH_3="P01876|IGHA1_HUMAN" and PH_4="P01877|IGHA2_HUMAN"), aligning with the new sorting logic after removing assignRanks().


21-21: Update protein_group_3 to reflect new hit grouping
protein_group_3 now lists PH_3,PH_4 in the updated order, matching the swapped ProteinHit elements.


22-25: Normalize indistinguishable_proteins values
Converted user parameters indistinguishable_proteins_0 through _3 to use "0.0" and updated the PH references for group 3 (PH_3,PH_4), ensuring consistency in floating-point formatting and grouping.


27-27: Standardize PeptideIdentification threshold to floating-point
Converted significance_threshold from "0" to "0.0" in the PeptideIdentification element for consistency.


68-68: Align peptide hit protein_refs with swapped proteins
Updated protein_refs to "PH_3 PH_4" on the sixth PeptideHit to reflect the reordered protein hits.

src/topp/LuciphorAdapter.cpp (1)

640-640: Sort function replaces assignRanks for maintaining peptide hit order

This change replaces the call to assignRanks() with sort() for ordering peptide hits. This is part of a broader refactoring to reduce the usage of rank assignment in favor of sorting to simplify rank management across the codebase.

src/openms/source/FORMAT/OMSSAXMLFile.cpp (1)

55-55: Sort function replaces assignRanks for maintaining peptide hit order

The call to assignRanks() is replaced with sort() as part of a broader refactoring to eliminate explicit rank assignment in favor of relying on sorting for hit ordering. This change aligns with similar modifications across the OpenMS codebase.

src/topp/MascotAdapterOnline.cpp (1)

222-222: Sort function replaces assignRanks in merge operation

The change from assignRanks() to sort() in the mergeIDs_ method aligns with the codebase-wide refactoring to remove explicit rank assignment. After inserting hits from one peptide identification into another, sorting is now used instead of rank assignment to maintain the ordering of peptide hits.

src/openms/include/OpenMS/METADATA/ProteinIdentification.h (1)

366-366: API change: assignRanks method has been removed

The assignRanks() method has been removed from the ProteinIdentification class as part of the refactoring to reduce rank usage. This API change is consistent with similar removals from other classes such as PeptideIdentification. The sort() method on line 365 is now used exclusively to order protein hits instead of explicit rank assignment.

src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithm.cpp (1)

117-117: Replaced assignRanks() with sort() call.

The change aligns with the broader refactoring effort to remove assignRanks() across the codebase and simplify rank management. The replacement with sort() maintains the functionality of ordering peptide hits while eliminating explicit rank assignment.

src/openms/source/FORMAT/InspectOutfile.cpp (1)

270-270: Replaced assignRanks() with sort() call for peptide identifications.

This change is consistent with the codebase-wide refactoring to remove assignRanks() methods. Using sort() ensures peptide hits will be ordered correctly without explicitly assigning ranks.

src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp (1)

341-341: Replaced assignRanks() with sort() in postProcessHits_ method.

The modification is part of the consistent pattern of changes across the codebase to reduce rank usage. This will maintain the correct ordering of peptide hits without explicitly assigning rank values.

src/openms/source/ANALYSIS/ID/PercolatorFeatureSetHelper.cpp (3)

204-204: Replaced assignRanks() with sort() in addMASCOTFeatures function.

This change aligns with the PR objective to reduce the use of assignRanks() in favor of sort(), simplifying rank management across the codebase.


229-229: Replaced assignRanks() with sort() in addCONCATSEFeatures function.

The replacement fits with the larger refactoring effort to simplify rank management by using sort() instead of explicit rank assignment.


606-606: Replaced assignRanks() with sort() in addMULTISEFeatures function.

Consistent with the refactoring approach in other functions, this change replaces explicit rank assignment with sorting operations, which aligns with the PR objectives.

src/openms_gui/source/VISUAL/MetaDataBrowser.cpp (2)

351-351: Refactoring from assignRanks() to sort() is correct.

This change aligns with the PR objective of reducing the use of assignRanks(). Since this visualization method only needs the peptide hits to be properly ordered for display, using sort() is appropriate and sufficient.


386-386: Refactoring from assignRanks() to sort() is correct.

Similar to the peptide identification change, replacing assignRanks() with sort() for protein hits maintains the proper ordering needed for visualization while removing the explicit rank assignment.

src/openms/source/FORMAT/XTandemXMLFile.cpp (2)

63-63: Appropriate replacement of assignRanks() with sort().

This change correctly maintains the ordering of peptide hits after they are swapped from the peptide_hits_ map. Using sort() ensures hits are properly ordered before being added to the peptide_ids vector.


71-71: Appropriate replacement of assignRanks() with sort().

This change correctly ensures protein hits are properly ordered after being swapped into the protein_identification object, while removing the explicit rank assignment.

src/openms/source/ANALYSIS/ID/ConsensusIDAlgorithmRanks.cpp (1)

44-52: Well-implemented replacement for assignRanks() functionality.

This refactoring not only replaces the assignRanks() call with sort(), but also explicitly implements the rank-based scoring logic that was previously hidden in the assignRanks() method.

The implementation correctly:

  1. Sorts the hits by score
  2. Maintains an explicit rank counter starting at 1
  3. Sets each hit's score to rank-1 (best hit gets 0, second gets 1, etc.)

This approach improves code clarity by making the rank computation logic explicit.

src/openms/source/ANALYSIS/ID/FalseDiscoveryRate.cpp (1)

398-398: Appropriate replacement of assignRanks() with sort().

This change correctly replaces the explicit rank assignment with a simple sort after FDR/q-value calculation. Since the actual rank values don't appear to be used after this point, the substitution maintains the required functionality of ensuring hits are properly ordered by their newly assigned FDR/q-value scores.

src/tests/class_tests/openms/source/ProteinIdentification_test.cpp (1)

432-450: Test section renamed and modified to use sort() instead of assignRanks()

The test section has been renamed from assignRanks() to sort() and now calls the sort() method rather than assignRanks(). This change aligns with the PR objective to reduce the use of assignRanks() in favor of sorting the protein hits, which simplifies rank management by making explicit rank assignment unnecessary.

The test still properly verifies that the protein hits are correctly ordered by score (in descending order), with "FIRSTPROTEIN", "SECONDPROTEIN", and "THIRDPROTEIN" as expected.

src/openms/source/FORMAT/MzTab.cpp (2)

837-837: Changed assignRanks() to sort() method call

The method call has been changed from assignRanks() to sort() to align with the PR objective of reducing explicit rank assignment. This modification ensures that peptide hits are ordered by score before selecting the best hit, maintaining functional equivalence while simplifying the rank management approach.


1171-1171: Formatting adjustment after removing significance threshold

A trailing whitespace was added after removing Constants::UserParam::SIGNIFICANCE_THRESHOLD from the set of meta keys. This is a minor formatting adjustment that doesn't affect functionality but maintains code style consistency.

src/tests/topp/PSMFeatureExtractor_2_out.mzid (3)

7-7: Updated metadata timestamps and version information

Timestamps and version information have been updated to reflect the current build date. This is expected when regenerating test output files and doesn't affect the functionality being tested.

Also applies to: 19-19, 44-44


209-209: Changed rank attribute from "1" to "0" in SpectrumIdentificationItem

The rank attribute in the SpectrumIdentificationItem has been changed from "1" to "0", reflecting the refactored approach to rank management. This change aligns with the PR objective of reducing explicit rank assignments, as the rank value now starts at 0 instead of 1.


216-216: Minor floating-point precision adjustment

A very slight adjustment to the floating-point precision of the MS-GF:EValue value, changing from 9.678856999999999e-24 to 9.678857000000001e-24. This is likely due to minor differences in floating-point handling and doesn't affect the functional correctness of the test.

src/tests/class_tests/openms/source/IDFilter_test.cpp (2)

56-56: Sort added for test setup consistency

This change is part of the overall transition from using assignRanks() to using sort() for ordering hits. Sorting the test data at the beginning makes it easier to compare results in subsequent tests.


883-884: Replaced assignRanks() with sort() in test

This change replaces a call to assignRanks() with sort(), aligning with the PR's goal of removing explicit rank assignments and relying on sorting for hit ordering.

src/topp/MetaProSIP.cpp (2)

3190-3190: Replaced assignRanks() with sort() for peptide IDs

The call to assignRanks() has been replaced with sort() as part of the codebase-wide refactoring to eliminate the use of rank assignments. This change maintains the same ordering behavior for the subsequent operations on the peptide hits.


3202-3202: Replaced assignRanks() with sort() for temporary peptide ID

Similar to the previous change, this replaces the explicit rank assignment with a sort operation. This is consistent with the PR's goal to remove the assignRanks() functionality across the codebase.

src/tests/topp/IDFilter_24_output.consensusXML (1)

15-38: Generated test artefact – no code behaviour affected. Skipping detailed review.

src/tests/topp/FalseDiscoveryRate_7_output.idXML (1)

7-55: Test output update only; schema remains valid. Nothing to review here.

src/tests/topp/IDFilter_11_output.idXML (13)

14-14: Align significance_threshold to floating‑point format
The <ProteinIdentification> element now uses significance_threshold="0.0" instead of "0", which matches the refactored code treating thresholds as floats.


15-15: Convert ProteinHit score to floating‑point
The first <ProteinHit> now has score="0.0". Confirm that the test harness compares this exact string and does not strip trailing zeros.


18-18: Verify updated ordering for second ProteinHit
The second hit is now id="PH_1" with score="0.0" after sorting. Ensure this new ordering aligns with the sort‑based logic replacing assignRanks().


21-21: Check third ProteinHit float formatting
The third hit uses id="PH_2" and score="0.0". Confirm that the test output’s ordering and literal formatting match the XML writer’s output.


24-24: Confirm fourth ProteinHit mapping
Updated to id="PH_3" with score="0.0". Please verify the ID-to-score association remains correct after rank removal.


35-35: Floating‑point for Fido_prob_spurious
Changed to value="0.0"; this aligns with the refactored probability outputs. Ensure no unintended rounding or truncation occurs during serialization.


36-41: Verify reordered indistinguishable_proteins_* entries
The indices and associated PH_* IDs have been re‑ordered to reflect sorted probabilities. Confirm the sequence (0…5) matches descending probability order and that the numbering is contiguous.


43-44: High‑precision floats in first PeptideIdentification and PeptideHit
Updated significance_threshold="0.0", MZ="486.475325031900013", RT="358.379999999999995" and score="0.0486". Verify that the XML writer emits exactly these representations to pass string‑based tests.


49-50: Apply float formatting to second peptide entry
The second <PeptideIdentification> now has significance_threshold="0.0" and its <PeptideHit> uses score="0.0". Ensure the test comparator expects the new literal values and formatting.


55-56: Precision check for third peptide match
MZ="345.193225031899999" and RT="377.29000000000002" with score="0.0" may be sensitive to rounding. Confirm that these long‑form floats match exactly what the code outputs.


61-62: Validate fourth peptide float precision
MZ="350.700875031900011", RT="378.29000000000002", and score="0.0" should correspond precisely to the computed values. Check for any off-by-one rounding errors.


67-68: Consistent float formatting for fifth peptide
MZ="804.383175031900009", RT="383.879999999999996", and score="0.0" have high precision. Ensure the XML serializer doesn’t collapse or alter these values in practice.


73-74: Float representation in last peptide match
The final entry updated MZ="383.217350031900025" and RT="391.0". Verify that RT is serialized as "391.0" (not "391") to satisfy exact string comparison in tests.

Comment on lines +27 to +31
<ProteinHit id="PH_4" accession="sp|Q96QS3|ARX_HUMAN" score="0.0" sequence="" >
<UserParam type="string" name="isDecoy" value="false"/>
</ProteinHit>
<ProteinHit id="PH_5" accession="sp|Q96NH3|BROMI_HUMAN" score="0.0" sequence="" >
<UserParam type="string" name="isDecoy" value="false"/>

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

Inconsistent decoy flag attribute names
The entries for PH_4 and PH_5 still use name="isDecoy", whereas the earlier protein hits use name="target_decoy". This mismatch can break parsers expecting a uniform attribute.

Recommend renaming isDecoy → target_decoy for those two <UserParam> elements.

@jpfeuffer

Copy link
Copy Markdown
Contributor

Doesn't look so bad. Unfortunately sorting changed a bit so test output is hard to compare. But an initial check showed that it's really just the order of the proteins that changes. Not their score or associations.

TEST_EQUAL(hits[2].getSequence(), AASequence::fromString("C"));
TEST_REAL_SIMILAR(hits[2].getScore(), 0.3);

// hits with the same score get assigned the same rank:

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.

Suggested change
// hits with the same score get assigned the same rank:

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.

this use case is not directly supported anymore. would need to be done on the score itself

@timosachsenberg
timosachsenberg enabled auto-merge (squash) May 12, 2025 06:56

@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)
CHANGELOG (1)

27-28: Consider clarifying the changelog entry.

The current entry "Removed assignRanks and sortByRanks in PeptideIdentifications and sort and filter by score" could be more specific about what was removed vs. what replaces it.

Consider rewording for clarity:

- - Removed assignRanks and sortByRanks in PeptideIdentifications and sort and filter by score.
+ - Removed assignRanks() and sortByRank() methods from PeptideIdentification class. Sorting peptide hits by their main score (order in getHits() vector) now implicitly assigns ranks.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf8ae93 and 9fbbbc4.

📒 Files selected for processing (2)
  • CHANGELOG (1 hunks)
  • src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/PROCESSING/ID/IDFilter.h
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • 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-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)
  • GitHub Check: cppcheck-test

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

Looks good. I checked the smallest test and only the sorting of the proteins changed, not the actual associations so it should be fine.

@timosachsenberg
timosachsenberg disabled auto-merge May 12, 2025 09:34
@timosachsenberg
timosachsenberg merged commit d736772 into develop May 12, 2025
@timosachsenberg
timosachsenberg deleted the reduce_assign_ranks branch May 12, 2025 09:34
Comment on lines -943 to +903
updateHitRanks(ids);
if (min_rank > 1)
// calculate ranks and store them in a vector of ints
for (auto id_it = ids.begin(); id_it != ids.end(); ++id_it)

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 whole thing can be shortened to

template<class IdentificationType>
static void filterHitsByRank(std::vector<IdentificationType>& ids, Size min_rank, Size max_rank)
{
  for (auto& id : ids)
  {
    auto& hits = id.getHits();
    if (hits.empty()) continue;

    id.sort(); // Ensure hits are properly sorted

    // ignore max_rank?
    if (max_rank < min_rank) max_rank = hits.size();

    Size rank = 1;
    double last_score = hits.front().getScore();

    // Remove hits not within [min_rank, max_rank], while computing rank on the fly
    hits.erase(
      std::remove_if(hits.begin(), hits.end(),
        [&](const auto& hit) {
          if (hit.getScore() != last_score)
          {
            ++rank;
            last_score = hit.getScore();
          }
          return rank < min_rank || rank > max_rank;
        }),
      hits.end()
    );
  }
}

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.

will add it to the next PR. I'm not done with ranks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants