Skip to content

fix small bug and some refactoring - #8096

Merged
timosachsenberg merged 1 commit into
developfrom
minor_refactoring
Jul 1, 2025
Merged

timosachsenberg merged 1 commit into
developfrom
minor_refactoring

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

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

  • Refactor

    • Improved clarity and maintainability of protein quantification by simplifying data structures and method signatures.
    • Modularized input processing and protein table header writing for better code organization.
    • Enhanced consistency in sample and channel handling, aligning output formatting and indexing.
  • Bug Fixes

    • Corrected indexing for channel/label handling to ensure accurate quantification and output.
  • Tests

    • Updated test outputs to reflect revised quantification logic and output formats.

@coderabbitai

coderabbitai Bot commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This update refactors and simplifies peptide and protein quantification logic in the PeptideAndProteinQuant class and related tools. Key changes include streamlined data structures, removal of optional parameters, improved const-correctness, and modularization of input processing and output header writing in the quantification workflow.

Changes

File(s) Change Summary
src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp
Simplified and unified peptide/protein quantification data structures (removing fraction/channel keys where unnecessary, using UInt64 for counts), removed boolean parameters from several methods, improved const-correctness, renamed methods for clarity, and updated internal logic for leader accession mapping and abundance aggregation.
src/topp/ProteinQuantifier.cpp Modularized input processing by file type into helper functions, split protein table header writing into a new function, corrected channel indexing to be one-based, and cleaned up redundant code and formatting. No core quantification logic was changed.
src/tests/topp/ProteinQuantifier_17_output.txt Updated test output to reflect new abundance calculations and input file references, with changes in abundance values and structure for two proteins.
src/tests/topp/ProteinQuantifier_2_output2.txt Updated test output to reflect new peptide abundance values, now showing specific floating-point values instead of all ones.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProteinQuantifier
    participant PeptideAndProteinQuant
    participant ExperimentalDesign

    User->>ProteinQuantifier: Run quantification (input file)
    ProteinQuantifier->>ProteinQuantifier: process*Input_()
    ProteinQuantifier->>ExperimentalDesign: Load experimental design
    ProteinQuantifier->>PeptideAndProteinQuant: Read quant data
    PeptideAndProteinQuant->>PeptideAndProteinQuant: quantifyPeptides()
    PeptideAndProteinQuant->>PeptideAndProteinQuant: quantifyProteins()
    PeptideAndProteinQuant->>PeptideAndProteinQuant: transferPeptideDataToProteins_()
    PeptideAndProteinQuant->>PeptideAndProteinQuant: calculateFileAndChannelLevelProteinAbundances_()
    ProteinQuantifier->>ProteinQuantifier: writeProteinTableHeader_()
    ProteinQuantifier->>ProteinQuantifier: writeProteinTable_()
    ProteinQuantifier->>User: Output quantification results
Loading

Possibly related PRs

  • OpenMS/OpenMS#8094: Introduced detailed file and channel level quantification data structures and logic; the current PR simplifies and refactors these aspects, indicating a direct follow-up or cleanup.

Suggested labels

Review effort 2/5

Poem

A rabbit hopped through quant fields anew,
Tidying maps, making signatures few.
Fractions and channels—now less complex,
Leader accessions guide what comes next.
With headers and helpers, the code shines bright,
Quantifying proteins from morning till night!
🐇✨

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (2)

932-932: Remove redundant blank line.

-
             }    

1177-1277: Complex but necessary implementation for detailed protein quantification.

This method handles the intricate task of calculating file and channel-level protein abundances. While the static analysis correctly identifies this as a complex method due to the nested loops, the complexity stems from the multi-dimensional nature of the quantification data.

Consider future refactoring opportunities to break down this method into smaller, more focused helper functions to improve maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 797bf70 and 544ae8e.

📒 Files selected for processing (5)
  • src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h (7 hunks)
  • src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (17 hunks)
  • src/tests/topp/ProteinQuantifier_17_output.txt (1 hunks)
  • src/tests/topp/ProteinQuantifier_2_output2.txt (1 hunks)
  • src/topp/ProteinQuantifier.cpp (11 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: FreezB11
PR: OpenMS/OpenMS#7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (1)
Learnt from: FreezB11
PR: OpenMS/OpenMS#7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.
src/topp/ProteinQuantifier.cpp (2)
Learnt from: FreezB11
PR: OpenMS/OpenMS#7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.
Learnt from: FreezB11
PR: OpenMS/OpenMS#7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:4-4
Timestamp: 2025-06-16T15:48:09.667Z
Learning: In OpenMS .pxd files, the established pattern for extern from statements is to include angle brackets inside the string literal, like `cdef extern from "<OpenMS/PATH/TO/FILE.h>" namespace "OpenMS":`. This is consistent across all existing quantitation method .pxd files and other .pxd files in the OpenMS codebase.
src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h (1)
Learnt from: FreezB11
PR: OpenMS/OpenMS#7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.
🧬 Code Graph Analysis (1)
src/topp/ProteinQuantifier.cpp (2)
src/openms/include/OpenMS/APPLICATIONS/TOPPBase.h (2)
  • getFlag_ (785-785)
  • getStringOption_ (722-722)
src/openms/source/FORMAT/FileHandler.cpp (2)
  • stripExtension (127-148)
  • stripExtension (127-127)
🪛 GitHub Check: CodeFactor
src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp

[notice] 932-932: src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp#L932
Redundant blank line at the end of a code block should be deleted. (whitespace/blank_line)


[notice] 1177-1278: src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp#L1177-L1278
Complex Method

⏰ 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 (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: cppcheck-test
🔇 Additional comments (9)
src/openms/include/OpenMS/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.h (3)

43-43: Good type correction for PSM counts.

Changing from double to UInt64 is appropriate since PSM counts are discrete values that should be represented as integers.


72-77: Well-structured additions for detailed quantification tracking.

The new data members for channel-level abundances and file-level PSM counts enable more granular tracking of quantification data, which aligns with the enhanced output functionality.


174-177: Excellent API improvements.

The simplification of quantifyProteins and the refactoring of mapAccessionToLeader to return a map instead of using an output parameter improve const-correctness and API clarity.

src/topp/ProteinQuantifier.cpp (4)

384-387: Critical fix: Corrected channel indexing from 0-based to 1-based.

The change from c = 0; c < ed.getNumberOfLabels() to c = 1; c <= ed.getNumberOfLabels() correctly aligns with how channels/labels are numbered in the experimental design (starting from 1). This fixes a potential off-by-one error throughout the code.

Also applies to: 432-433, 497-499, 635-636


478-545: Excellent modularization of header writing logic.

Extracting the header writing logic into a separate method writeProteinTableHeader_ improves code organization and reusability.


873-978: Outstanding refactoring with dedicated input processing methods.

The introduction of processFeatureXMLInput_, processIdXMLInput_, and processConsensusXMLInput_ significantly improves code organization by:

  • Eliminating code duplication
  • Providing clear separation of concerns for each input type
  • Making the main method more readable and maintainable

639-652: Indexing Verified: channel_level_abundances Uses 1-Based Labels Consistently

All usages of channels in channel_level_abundances stem from ExperimentalDesign::MSFileSectionEntry::label, which is defined as 1-based. Both peptide‐ and protein‐level quantification store and aggregate abundances using this label, and the output loop in ProteinQuantifier.cpp iterates from 1 to ed.getNumberOfLabels(). The map keys and loop indices therefore align, and no changes are required.

src/openms/source/ANALYSIS/QUANTITATION/PeptideAndProteinQuant.cpp (2)

309-327: Important fix for PSM counting in multiplexed experiments.

The updated logic correctly handles multiplexed designs (e.g., TMT) where a single PSM is associated with all samples measured in different channels. The 1-based channel indexing (channel = 1; channel <= experimental_design_.getNumberOfLabels()) is consistent with the rest of the codebase.


796-947: Comprehensive enhancement of protein annotation with detailed quantification data.

The refactored annotation logic now properly handles:

  • File and channel-level abundance data with proper array sizing
  • Defensive error checking for invalid channel 0
  • Consistent 1-based channel indexing
  • Proper organization of data according to experimental design

The added complexity is justified by the enhanced functionality.

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.

1 participant