Skip to content

refactor: move significance_threshold and pepXML analysis results member in PeptideIdentifications to a meta value as it is often unused - #7985

Merged
timosachsenberg merged 16 commits into
developfrom
move_sig_thresh
Apr 22, 2025

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor

This pull request includes several changes to the PeptideHit and PeptideIdentification classes in the OpenMS library to remove rarely used members and handle them as metadata instead.
The primary aim is to simplify both classes:

  • to potentially make the transition easier to a specturmidentfication class
  • simplify storage in columnar files

Metadata Handling Improvements:

Class Renaming:

Refactoring and Simplification:

Significance Threshold Handling:

These changes improve the clarity and maintainability of the code by using more descriptive class names and simplifying the handling of metadata.## Description

Checklist

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

How can I get additional information on failed tests during CI

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

Advanced commands (admins / reviewer only)

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

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

Summary by CodeRabbit

  • New Features

    • Introduced a new user parameter constant for significance threshold, accessible as a meta value in peptide identification results.
  • Refactor

    • Peptide hit analysis results are now fully managed via meta values, enhancing consistency and memory handling.
    • The significance threshold in peptide identifications is stored and accessed exclusively as a meta value.
    • Updated XML and file format handlers to exclude significance threshold from user parameters, avoiding duplication in outputs.
    • Removed legacy dedicated members for analysis results and significance threshold, unifying meta value usage.
  • Tests

    • Added extensive tests verifying correct storage, retrieval, copying, and moving of analysis results and significance thresholds through meta values.

@coderabbitai

coderabbitai Bot commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This change refactors the handling of analysis results and significance thresholds in the OpenMS metadata classes. In PeptideHit, analysis results are no longer stored in a dedicated pointer member but are now managed entirely through the meta value interface, with new helper methods for extraction and counting. In PeptideIdentification, the significance threshold is now stored as a meta value instead of a member variable, with corresponding updates to its constructor, getter, setter, equality operator, and related logic. Documentation for both classes is clarified to reflect these changes. Additionally, the constant key for the significance threshold was added to the user parameter constants. Test coverage was extended with new tests verifying these behaviors. Minor updates were made to XML handlers, file formats, and exporters to consistently handle the significance threshold as a meta value.

Changes

File(s) Change Summary
src/openms/include/OpenMS/CONCEPT/Constants.h Added a new constant SIGNIFICANCE_THRESHOLD to OpenMS::Constants::UserParam for use as a meta value key.
src/openms/include/OpenMS/METADATA/PeptideHit.h,
src/openms/source/METADATA/PeptideHit.cpp
Refactored PeptideHit to store analysis results as meta values rather than in a pointer member. Removed the pointer, added private helpers for meta value extraction and counting, updated all related methods, and extended class documentation. Updated method signatures to use const references and return by value. Introduced private methods to count and extract analysis results from meta values. Modified constructors, destructor, assignment operators, and equality operator to remove handling of raw pointer and adjust logic accordingly.
src/openms/include/OpenMS/METADATA/PeptideIdentification.h,
src/openms/source/METADATA/PeptideIdentification.cpp
Refactored PeptideIdentification to store the significance threshold as a meta value instead of a member variable. Removed the explicit member variable, updated constructor, getter, setter, equality operator, and related logic. Clarified documentation to reflect meta value storage.
src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp,
src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp,
src/openms/source/FORMAT/IdXMLFile.cpp,
src/openms/source/FORMAT/MzTab.cpp,
src/openms/source/METADATA/ID/IdentificationDataConverter.cpp,
src/topp/TextExporter.cpp
Updated multiple format handlers and exporters to consistently handle the significance threshold as a meta value. This includes removing the "significance_threshold" meta value before writing user parameters to avoid duplication, adjusting XML attribute reading logic to ignore zero values, excluding the key from output columns or internal representations, and removing code writing optional peptide prophet/interprophet analysis results from IdXML.
src/tests/class_tests/openms/source/PeptideHit_test.cpp Added extensive new tests for analysis result handling in PeptideHit, including setting, adding, retrieving, copying, moving, and equality checks, ensuring consistency between meta values and internal representations.
src/tests/class_tests/openms/source/PeptideIdentification_test.cpp Added a new test for the significance threshold meta value in PeptideIdentification, verifying getter/setter and copying behavior. Removed a large block of commented-out tests related to getNonReferencingHits.
src/tests/topp/IDFileConverter_10_output.idXML,
src/tests/topp/IDFileConverter_16_output.idXML,
src/tests/topp/IDFileConverter_24_output.idXML
Updated test output XML files to add new <UserParam> entries _ar_X_higher_is_better with values "true" or "false" for each analysis result score index in PeptideHit elements, reflecting the new meta value storage format.
src/tests/topp/THIRDPARTY/Chy_test.tmp.idXML,
src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML,
src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML,
src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML,
src/tests/topp/THIRDPARTY/CometAdapter_4_out.idXML,
src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML
Updated <IdentificationRun> elements in third-party test XML files to change date attributes and remove commit hash suffixes from search_engine_version attributes, with no functional code changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PeptideHit
    participant MetaInfoInterface

    User->>PeptideHit: setAnalysisResults(vector<AnalysisResult>)
    PeptideHit->>MetaInfoInterface: Clear old analysis result meta values
    PeptideHit->>MetaInfoInterface: Store each AnalysisResult as meta values

    User->>PeptideHit: getAnalysisResults()
    PeptideHit->>MetaInfoInterface: Extract analysis results from meta values
    PeptideHit-->>User: vector<AnalysisResult>
Loading
sequenceDiagram
    participant User
    participant PeptideIdentification
    participant MetaInfoInterface

    User->>PeptideIdentification: setSignificanceThreshold(value)
    PeptideIdentification->>MetaInfoInterface: Set meta value "significance_threshold"

    User->>PeptideIdentification: getSignificanceThreshold()
    PeptideIdentification->>MetaInfoInterface: Get meta value "significance_threshold"
    PeptideIdentification-->>User: value
Loading

Suggested labels

Review effort 3/5

Poem

🐇 In meta fields the secrets hide,
Analysis scores no more divide.
Thresholds now in values nest,
Stored with care, they pass the test.
Tests hop in, to prove and cheer,
Code refined, the path is clear!
🌿✨


📜 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 3564e7b and 5118828.

📒 Files selected for processing (6)
  • src/tests/topp/THIRDPARTY/Chy_test.tmp.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_4_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/tests/topp/THIRDPARTY/CometAdapter_4_out.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML
  • src/tests/topp/THIRDPARTY/Chy_test.tmp.idXML
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • 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 (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
  • GitHub Check: cppcheck-test

🪧 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 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 (3)
src/openms/source/METADATA/PeptideIdentification.cpp (2)

40-40: Avoid direct floating-point equality for significance thresholds.

Comparing doubles with == can lead to unexpected results due to floating-point precision. Consider an approximate comparison instead.

Apply this diff to change exact equality into a tolerance check, and ensure <cmath> is included:

-           && getSignificanceThreshold() == rhs.getSignificanceThreshold()
+           && std::fabs(getSignificanceThreshold() - rhs.getSignificanceThreshold()) < 1e-12
+#include <cmath>

254-254: Use an epsilon-based comparison instead of == 0.0.

Directly comparing to zero can miss floating-point inaccuracies. Use a negligible threshold check.

Apply this diff:

-           && getSignificanceThreshold() == 0.0
+           && std::fabs(getSignificanceThreshold()) < 1e-12
src/openms/source/METADATA/PeptideHit.cpp (1)

246-250: thread_local caching for getAnalysisResults is efficient, but be cautious.

Returning a reference to a thread-local static vector avoids frequent allocations. Just ensure the caller does not store this reference across multiple calls.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cce935f and e89073f.

📒 Files selected for processing (7)
  • src/openms/include/OpenMS/CONCEPT/Constants.h (1 hunks)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h (2 hunks)
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h (3 hunks)
  • src/openms/source/METADATA/PeptideHit.cpp (1 hunks)
  • src/openms/source/METADATA/PeptideIdentification.cpp (4 hunks)
  • src/tests/class_tests/openms/source/PeptideHit_test.cpp (1 hunks)
  • src/tests/class_tests/openms/source/PeptideIdentification_test.cpp (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/openms/source/METADATA/PeptideIdentification.cpp (2)
src/openms/include/OpenMS/METADATA/PeptideIdentification.h (4)
  • getSignificanceThreshold (115-115)
  • rhs (83-83)
  • rhs (85-85)
  • setSignificanceThreshold (117-117)
src/tests/class_tests/openms/source/PeptideIdentification_test.cpp (2)
  • metaValueExists (503-503)
  • getMetaValue (504-504)
⏰ 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-13, xcode, 14.2)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: cppcheck-test
🔇 Additional comments (21)
src/openms/include/OpenMS/CONCEPT/Constants.h (1)

566-570: Good addition of the significance threshold constant.

This new constant and documentation align well with existing user parameter definitions, promoting maintainable meta value usage.

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

236-262: Thorough test coverage for significance threshold meta value.

These tests effectively validate default initialization, setting, and copying of the new meta value. Consider adding boundary or negative-value checks if relevant, but overall the coverage is solid.

src/openms/include/OpenMS/METADATA/PeptideHit.h (3)

22-23: Alias introduction for PeptideHit.

Renaming PeptideHit through using SpectrumMatch is clear and self-documenting. This addition should not break existing code because it’s purely an alias.


26-36: Expanded class documentation.

This updated doc block accurately reflects the metadata-driven design and clarifies how PeptideHit is used within the framework.


299-306: Private helper methods enhance readability.

The new functions for extracting and counting analysis results from meta values keep the core interface clean. They appear well-documented and maintainable.

src/tests/class_tests/openms/source/PeptideHit_test.cpp (8)

269-360: Great test coverage for setAnalysisResults.

These test scenarios thoroughly verify overwriting of existing analysis results and synchronization with meta values. No issues found.


362-400: Comprehensive validation of addAnalysisResults.

The addition of multiple analysis results and proper meta value handling are well-verified.


401-421: Adequate checks for getAnalysisResults.

Retrieving empty vs. populated analysis results is confirmed, ensuring correct meta value reconstruction.


422-449: Copy constructor tests look solid.

These tests confirm that analysis results are copied correctly, including meta values and sub-scores.


450-478: Assignment operator coverage is well-designed.

Verifying that analysis results are properly reassigned ensures consistent meta value behavior.


479-514: Equality operator checks are comprehensive.

Different combinations of analysis results and sub-scores are thoroughly compared.


516-547: Move constructor handling is verified thoroughly.

Ensuring analysis results and meta values are moved correctly helps prevent unintended data copy and potential leaks.


549-579: Move assignment tests are robust.

The tests confirm that all analysis results are transferred properly, leaving the source PeptideHit empty.

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

28-29: Initializing significance threshold as a meta value is a good design.

Setting the default to 0.0 via a meta value simplifies metadata management and remains consistent with the new approach.

src/openms/include/OpenMS/METADATA/PeptideIdentification.h (3)

22-25: New alias SpectrumIdentification is well-introduced.

This forward declaration and alias can simplify future naming transitions.


26-57: Documentation improvements are clear and thorough.

The expanded explanation of retention time, m/z, and the relationship to ProteinIdentification further clarifies usage.


114-117: Updated significance threshold docs align with the meta value approach.

This clarifies how the threshold is stored and retrieved, promoting consistency.

src/openms/source/METADATA/PeptideHit.cpp (4)

204-228: Removing existing analysis results before resetting is a clean approach.

Purging old meta values ensures we do not mix stale and new analysis results.


232-242: Indexing new analysis results is straightforward.

Acquiring the current count from meta values prevents overwriting existing entries.


253-268: Counting analysis results by detecting ScoreType keys is consistent.

This logic is simple and effective for enumerating all result entries.


270-327: Extracting sub-scores in extractAnalysisResultsFromMetaValues_ is well-structured.

Iterating over meta keys by index is a clear approach. The overall design is readable and logically sound.

@jpfeuffer

Copy link
Copy Markdown
Contributor

I like the cleanups. Have you checked how often "rank" is used? Would be a candidate for removal IMHO.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

I like the cleanups. Have you checked how often "rank" is used? Would be a candidate for removal IMHO.

I think it is used quite frequently and it could have some performance impact - I can take a look.

@jpfeuffer

Copy link
Copy Markdown
Contributor

Really? I was convinced that I have never seen an occurrence where rank is actually needed for an algorithm.
Sure, it is filled and updated from time to time (honestly though I am sure not always, because I never cared about it when implementing algorithms). I would not vouch for rank always being correct after applying certain algorithms. And I have yet to see a pyopenms script that accesses it (instead of just using enumerate(hits)).
I would be fine with full removal.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Really? I was convinced that I have never seen an occurrence where rank is actually needed for an algorithm. Sure, it is filled and updated from time to time (honestly though I am sure not always, because I never cared about it when implementing algorithms). I would not vouch for rank always being correct after applying certain algorithms. And I have yet to see a pyopenms script that accesses it (instead of just using enumerate(hits)). I would be fine with full removal.

Totally agree and I want to get rid of it. I think last time I checked there was some funky semantics (e.g. hits with same score had same rank; sometimes same rank reported by search engine etc.). One would need to check individually if it breaks something if we just rely on the order in the vector...

@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

🔭 Outside diff range comments (1)
src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp (1)

403-409: 🛠️ Refactor suggestion

⚠️ Potential issue

Do not silently discard a legitimate threshold value of 0.0.

Using double tmp = 0.0; optionalAttributeAsDouble_(tmp, …) and subsequently testing tmp != 0.0 means:

  • a missing attribute and an attribute explicitly set to 0.0 are treated identically;
  • when writing, the code later serialises significance_threshold="0" unconditionally (id.getSignificanceThreshold() defaults to 0).

If a workflow genuinely wants to record a zero threshold this information will now be lost on round‑trip.

Suggested approach:

-double tmp = 0.0;
-if (optionalAttributeAsDouble_(tmp, attributes, "significance_threshold") /* returns true when present */)
-{
-  prot_id_.setSignificanceThreshold(tmp);
-}
+double tmp;
+if (optionalAttributeAsDouble_(tmp, attributes, "significance_threshold"))
+{
+  prot_id_.setSignificanceThreshold(tmp);
+}

Repeat for the PeptideIdentification branch.
Additionally, during writing only emit the attribute when the meta value was actually present or when a dedicated “is set” flag is true.

Also applies to: 451-454

🧹 Nitpick comments (3)
src/openms/source/METADATA/PeptideHit.cpp (2)

203-229: Consider serialising the boolean flag as an actual boolean/int DataValue.

The meta value _ar_*_higher_is_better is stored as the strings "true"/"false" and later parsed via toBool().
While this works, using an int (1/0) (or a dedicated bool‑to‑int helper) avoids the extra string parsing cost and removes any locale‑dependent pitfalls.

Not urgent, but a small improvement in both performance and robustness.


250-266: Minor optimisation: avoid repeated key scans in tight loops.

getNumberOfAnalysisResultsFromMetaValues_() rebuilds the complete key list and iterates over it every time it is called (e.g. once per addAnalysisResults).
If many analysis results are added in succession, caching the count or incrementing it directly would be O(1) instead of O(N·K).

Not blocking, just pointing out a potential micro‑optimisation path.

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

1170-1172: Improve code clarity with more descriptive comment

The comment explains that this key is being removed for backward compatibility, but it would be more informative to mention that this key is now handled as a standard meta value through a constant in Constants.h (judging from the PR description).

-    // remove key that only exists for backwards compatibility (will likely be deprecated in the future)
+    // Remove significance_threshold from meta values to avoid duplication since it's stored as a dedicated attribute
+    // and now managed via Constants::UserParam::SIGNIFICANCE_THRESHOLD
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e89073f and 88935c6.

📒 Files selected for processing (19)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h (2 hunks)
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h (2 hunks)
  • src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp (2 hunks)
  • src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp (1 hunks)
  • src/openms/source/FORMAT/IdXMLFile.cpp (3 hunks)
  • src/openms/source/FORMAT/MzTab.cpp (4 hunks)
  • src/openms/source/METADATA/ID/IdentificationDataConverter.cpp (1 hunks)
  • src/openms/source/METADATA/PeptideHit.cpp (2 hunks)
  • src/tests/class_tests/openms/source/PeptideHit_test.cpp (1 hunks)
  • src/tests/topp/IDFileConverter_10_output.idXML (8 hunks)
  • src/tests/topp/IDFileConverter_16_output.idXML (6 hunks)
  • src/tests/topp/IDFileConverter_24_output.idXML (2 hunks)
  • src/tests/topp/THIRDPARTY/Chy_test.tmp.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_4_out.idXML (1 hunks)
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML (1 hunks)
  • src/topp/TextExporter.cpp (3 hunks)
✅ Files skipped from review due to trivial changes (12)
  • src/tests/topp/THIRDPARTY/CometAdapter_2_out.idXML
  • src/tests/topp/IDFileConverter_24_output.idXML
  • src/openms/source/METADATA/ID/IdentificationDataConverter.cpp
  • src/tests/topp/THIRDPARTY/CometAdapter_4_out.idXML
  • src/tests/topp/IDFileConverter_10_output.idXML
  • src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp
  • src/tests/topp/THIRDPARTY/CometAdapter_1_out.idXML
  • src/tests/topp/THIRDPARTY/Chy_test.tmp.idXML
  • src/tests/topp/IDFileConverter_16_output.idXML
  • src/openms/include/OpenMS/METADATA/PeptideIdentification.h
  • src/tests/topp/THIRDPARTY/CometAdapter_6_out.idXML
  • src/tests/topp/THIRDPARTY/CometAdapter_3_out.idXML
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h
  • src/tests/class_tests/openms/source/PeptideHit_test.cpp
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • 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-13, xcode, 14.2)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (windows-2022, cl.exe, default)
  • GitHub Check: cppcheck-test
🔇 Additional comments (10)
src/topp/TextExporter.cpp (3)

690-696: LGTM – duplicate “significance_threshold” column is correctly filtered.


865-872: LGTM – keeps exported consensus files free of duplicate thresholds.


1347-1353: LGTM – prevents duplicate meta columns for idXML export as well.

src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp (1)

904-908: Good – meta value removal avoids duplicate XML output.

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

2459-2460: Apply consistent removal pattern for meta value

Good removal of the significance_threshold to maintain consistency with the member variable to meta value refactoring approach. This ensures the key doesn't appear as an optional meta value column in mzTab output.


2536-2537: Apply consistent cleanup for meta values

This properly removes both "spectrum_reference" and "significance_threshold" to prevent these values from being duplicated in the output. This is consistent with the refactoring approach.


2559-2560: Ensure consistent management of meta values

This correctly removes the significance_threshold key after extracting meta values, which is consistent with the overall refactoring approach of moving the significance threshold to a meta value.

src/openms/source/FORMAT/IdXMLFile.cpp (3)

221-223: Improve numerical-to-string conversion

Explicitly converting the significance_threshold to a String ensures proper formatting in the XML output. This is a good defensive programming practice to avoid potential issues with floating-point representation.


287-289: Consistent explicit string conversion

This change applies the same explicit string conversion pattern as used for protein IDs, maintaining consistency throughout the code. This is good practice for XML serialization.


374-375: Eliminate duplicate meta value in XML output

Removing the "significance_threshold" meta value before writing user parameters prevents duplication, since it's already written as an XML attribute. This ensures clean, non-redundant output.

@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 (4)
src/openms/source/METADATA/PeptideHit.cpp (4)

202-228: Refactoring looks good with some potential optimizations.

The implementation correctly manages analysis results as meta values instead of a dedicated member variable. This follows the intended refactoring from the PR objectives.

The current implementation scans all meta value keys and does multiple string operations. Consider these optimizations:

  void PeptideHit::setAnalysisResults(const std::vector<PeptideHit::PepXMLAnalysisResult>& aresult)
  {
    // Remove all existing analysis result meta values
-   std::vector<String> keys;
-   getKeys(keys);
-   for (const auto& key : keys)
-   {
-     if (key.hasPrefix("_ar_"))
-     {
-       removeMetaValue(key);
-     }
-   }
+   // Define constants for prefixes to improve maintainability
+   const String AR_PREFIX = "_ar_";
+   
+   // Use a more efficient approach to remove specific meta values
+   std::vector<String> keys_to_remove;
+   std::vector<String> all_keys;
+   getKeys(all_keys);
+   for (const auto& key : all_keys)
+   {
+     if (key.hasPrefix(AR_PREFIX))
+     {
+       keys_to_remove.push_back(key);
+     }
+   }
+   
+   for (const auto& key : keys_to_remove)
+   {
+     removeMetaValue(key);
+   }
    
    // Add new analysis results as meta values
    for (size_t i = 0; i < aresult.size(); ++i)
    {
      const auto& ar = aresult[i];
-     setMetaValue("_ar_" + String(i) + "_score_type", ar.score_type);
-     setMetaValue("_ar_" + String(i) + "_score", ar.main_score);
-     setMetaValue("_ar_" + String(i) + "_higher_is_better", ar.higher_is_better == true ? "true" : "false");
+     String index_prefix = AR_PREFIX + String(i) + "_";
+     setMetaValue(index_prefix + "score_type", ar.score_type);
+     setMetaValue(index_prefix + "score", ar.main_score);
+     setMetaValue(index_prefix + "higher_is_better", ar.higher_is_better == true ? "true" : "false");
      
      for (const auto& subscore : ar.sub_scores)
      {
-       setMetaValue("_ar_" + String(i) + "_subscore_" + subscore.first, subscore.second);
+       setMetaValue(index_prefix + "subscore_" + subscore.first, subscore.second);
      }
    }
  }

230-242: Consider consistency with the prefix handling.

The implementation correctly adds a new analysis result by determining the next available index. However, the string prefixes could be handled more consistently.

  void PeptideHit::addAnalysisResults(const PeptideHit::PepXMLAnalysisResult& aresult)
  {
    size_t index = getNumberOfAnalysisResultsFromMetaValues_();
    
-   setMetaValue("_ar_" + String(index) + "_score_type", aresult.score_type);
-   setMetaValue("_ar_" + String(index) + "_score", aresult.main_score);
-   setMetaValue("_ar_" + String(index) + "_higher_is_better", aresult.higher_is_better == true ? "true" : "false");
+   const String AR_PREFIX = "_ar_";
+   String index_prefix = AR_PREFIX + String(index) + "_";
+   setMetaValue(index_prefix + "score_type", aresult.score_type);
+   setMetaValue(index_prefix + "score", aresult.main_score);
+   setMetaValue(index_prefix + "higher_is_better", aresult.higher_is_better == true ? "true" : "false");
    
    for (const auto& subscore : aresult.sub_scores)
    {
-     setMetaValue("_ar_" + String(index) + "_subscore_" + subscore.first, subscore.second);
+     setMetaValue(index_prefix + "subscore_" + subscore.first, subscore.second);
    }
  }

249-265: Efficient implementation but could benefit from using constants.

The function correctly counts the number of analysis results by searching for meta value keys with specific prefixes and suffixes.

Consider defining constants for the prefixes and suffixes to improve maintainability:

  size_t PeptideHit::getNumberOfAnalysisResultsFromMetaValues_() const
  {
    size_t count = 0;
    std::vector<String> keys;
    getKeys(keys);
    
+   const String AR_PREFIX = "_ar_";
+   const String SCORE_TYPE_SUFFIX = "_score_type";
+   
    for (const auto& key : keys)
    {
-     if (key.hasPrefix("_ar_") &&
-         key.hasSuffix("_score_type"))
+     if (key.hasPrefix(AR_PREFIX) &&
+         key.hasSuffix(SCORE_TYPE_SUFFIX))
      {
        ++count;
      }
    }
    
    return count;
  }

267-327: Well-structured extraction method with some optimization opportunities.

The method effectively extracts analysis results from meta values with a two-phase approach: first identify all indices, then extract data for each index.

Consider the following optimizations:

  1. Define constants for prefixes and suffixes
  2. Avoid repeated string operations by pre-computing common strings
  3. Use a more efficient approach to group related meta values
  std::vector<PeptideHit::PepXMLAnalysisResult> PeptideHit::extractAnalysisResultsFromMetaValues_() const
  {
    std::vector<PeptideHit::PepXMLAnalysisResult> results;
    std::vector<String> keys;
    getKeys(keys);
    
+   const String AR_PREFIX = "_ar_";
+   const String SCORE_TYPE_SUFFIX = "_score_type";
+   
    // First, find all indices that have analysis results
    std::set<size_t> indices;
    
    for (const auto& key : keys)
    {
-     const String prefix = "_ar_";
-     const String suffix = "_score_type";
-     if (key.hasPrefix(prefix) &&
-         key.hasSuffix(suffix))
+     if (key.hasPrefix(AR_PREFIX) &&
+         key.hasSuffix(SCORE_TYPE_SUFFIX))
      {
-       String index_str = key.substr(prefix.size(), key.size() - prefix.size() - suffix.size()); // Extract index from _ar_<index>_score_type"
+       String index_str = key.substr(AR_PREFIX.size(), key.size() - AR_PREFIX.size() - SCORE_TYPE_SUFFIX.size()); // Extract index from _ar_<index>_score_type"
        indices.insert(index_str.toInt());
      }
    }
    
    // For each index, extract the analysis result
    for (size_t index : indices)
    {
      PeptideHit::PepXMLAnalysisResult ar;
-     String prefix = "_ar_" + String(index) + "_";
+     String prefix = AR_PREFIX + String(index) + "_";
      
      // Get score type
      if (metaValueExists(prefix + "score_type"))
      {
        ar.score_type = getMetaValue(prefix + "score_type").toString();
      }
      
      // Get main score
      if (metaValueExists(prefix + "score"))
      {
        ar.main_score = getMetaValue(prefix + "score");
      }
      
      // Get higher_is_better flag
      if (metaValueExists(prefix + "higher_is_better"))
      {
        ar.higher_is_better = getMetaValue(prefix + "higher_is_better").toBool();
      }
      
      // Get sub-scores
      String subscore_prefix = prefix + "subscore_";
      for (const auto& key : keys)
      {
        if (key.hasPrefix(subscore_prefix))
        {
          String subscore_name = key.substr(subscore_prefix.size());
          ar.sub_scores[subscore_name] = getMetaValue(key);
        }
      }
      
      results.push_back(ar);
    }
    
    return results;
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 88935c6 and 3564e7b.

📒 Files selected for processing (10)
  • src/openms/include/OpenMS/METADATA/PeptideHit.h (2 hunks)
  • src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp (2 hunks)
  • src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp (1 hunks)
  • src/openms/source/FORMAT/IdXMLFile.cpp (3 hunks)
  • src/openms/source/FORMAT/MzTab.cpp (4 hunks)
  • src/openms/source/METADATA/ID/IdentificationDataConverter.cpp (1 hunks)
  • src/openms/source/METADATA/PeptideHit.cpp (1 hunks)
  • src/openms/source/METADATA/PeptideIdentification.cpp (4 hunks)
  • src/tests/class_tests/openms/source/PeptideIdentification_test.cpp (3 hunks)
  • src/topp/TextExporter.cpp (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/openms/source/FORMAT/MzTab.cpp
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/openms/source/METADATA/ID/IdentificationDataConverter.cpp
  • src/tests/class_tests/openms/source/PeptideIdentification_test.cpp
  • src/topp/TextExporter.cpp
  • src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp
  • src/openms/source/METADATA/PeptideIdentification.cpp
  • src/openms/source/FORMAT/HANDLERS/ConsensusXMLHandler.cpp
  • src/openms/source/FORMAT/IdXMLFile.cpp
  • src/openms/include/OpenMS/METADATA/PeptideHit.h
⏰ 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 (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 (ubuntu-22.04, g++, 11)
  • GitHub Check: cppcheck-test
🔇 Additional comments (1)
src/openms/source/METADATA/PeptideHit.cpp (1)

244-247: Clean implementation - nicely leverages private helper method.

The implementation correctly delegates to the private helper method which improves code organization and maintainability.

@timosachsenberg timosachsenberg changed the title refactor: move sig threshold member in PeptideIdentifications to a meta value as it is often unused refactor: move significance_threshold and pepXML analysis results member in PeptideIdentifications to a meta value as it is often unused Apr 17, 2025
@timosachsenberg
timosachsenberg requested a review from Copilot April 21, 2025 08:24

Copilot AI 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.

Pull Request Overview

This PR refactors metadata handling in peptide identification and peptide hit classes by moving the significance threshold and analysis results from dedicated member variables to meta values, streamlining class functionality and ensuring consistency in data storage. Key changes include:

  • Storing the significance threshold exclusively as a meta value and updating related methods.
  • Removing the dedicated analysis_results_ pointer from PeptideHit and replacing its use with meta value based storage and retrieval.
  • Updating relevant exporters, converters, and tests to accommodate the new metadata handling approach.

Reviewed Changes

Copilot reviewed 13 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/topp/TextExporter.cpp Extended meta key filtering to remove SIGNIFICANCE_THRESHOLD from peptide identification meta keys.
src/tests/class_tests/openms/source/PeptideIdentification_test.cpp Added tests to verify significance threshold meta value handling.
src/tests/class_tests/openms/source/PeptideHit_test.cpp Added extensive tests for analysis results meta value functionality.
src/openms/source/METADATA/PeptideIdentification.cpp Refactored significance threshold getter/setter to rely on meta values.
src/openms/source/METADATA/PeptideHit.cpp Removed analysis_results_ pointer and implemented meta value based analysis results storage and retrieval.
src/openms/source/METADATA/ID/IdentificationDataConverter.cpp, MzTab.cpp, IdXMLFile.cpp, FeatureXMLHandler.cpp, ConsensusXMLHandler.cpp Updated to remove SIGNIFICANCE_THRESHOLD meta value where appropriate.
src/openms/include/OpenMS/METADATA/PeptideIdentification.h, PeptideHit.h, Constants.h Updated documentation and header declarations to reflect significance threshold as a meta value and removed the legacy member.
Files not reviewed (3)
  • src/tests/topp/IDFileConverter_10_output.idXML: Language not supported
  • src/tests/topp/IDFileConverter_16_output.idXML: Language not supported
  • src/tests/topp/IDFileConverter_24_output.idXML: Language not supported

@timosachsenberg
timosachsenberg merged commit 0b98927 into develop Apr 22, 2025
@timosachsenberg
timosachsenberg deleted the move_sig_thresh branch April 22, 2025 09:16
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