Skip to content

Add option to PeakFileOption to ignore loading (#7901) - #7902

Merged
timosachsenberg merged 14 commits into
OpenMS:developfrom
adityamuzumdar:fix/7901
May 6, 2025
Merged

timosachsenberg merged 14 commits into
OpenMS:developfrom
adityamuzumdar:fix/7901

Conversation

@adityamuzumdar

@adityamuzumdar adityamuzumdar commented Mar 12, 2025 •

Copy link
Copy Markdown
Contributor

User description

This PR adds the skip_chromatograms_ option to PeakFileOptions, allowing users to skip loading chromatogram data from MzML files. This is useful when only spectra data is needed, optimizing memory usage and performance.

Key Changes:
• Added setSkipChromatograms(bool) and getSkipChromatograms() methods to PeakFileOptions.
• Updated MzMLFile::load() to respect the skip_chromatograms_ flag and clear chromatogram data if set.
• Added unit tests in MzMLFile_test.cpp and PeakFileOptions_test.cpp to validate the new functionality.


PR Type

Enhancement, Tests


Description

  • Added skip_chromatograms_ option in PeakFileOptions to skip chromatogram loading.

  • Updated MzMLFile::load() to respect the skip_chromatograms_ flag.

  • Introduced new unit tests to validate skip_chromatograms_ functionality.

  • Enhanced memory optimization by clearing chromatogram data when not needed.


Changes walkthrough 📝

Relevant files
Enhancement
MzMLFile.cpp
Update `MzMLFile::load()` to handle chromatogram skipping

src/openms/source/FORMAT/MzMLFile.cpp

  • Added logic to clear chromatogram data if skip_chromatograms_ is
    enabled.
  • Ensures MzMLFile::load() respects the new skip_chromatograms_ flag.
  • +5/-0     
    PeakFileOptions.cpp
    Add methods to configure chromatogram skipping                     

    src/openms/source/FORMAT/OPTIONS/PeakFileOptions.cpp

  • Added setSkipChromatograms and getSkipChromatograms methods.
  • Enabled configuration of the skip_chromatograms_ flag.
  • +10/-0   
    PeakFileOptions.h
    Declare chromatogram skipping methods and variable             

    src/openms/include/OpenMS/FORMAT/OPTIONS/PeakFileOptions.h

  • Declared setSkipChromatograms and getSkipChromatograms methods.
  • Added skip_chromatograms_ private member variable.
  • +4/-0     
    Tests
    MzMLFile_test.cpp
    Add unit test for chromatogram skipping in `MzMLFile`       

    src/tests/class_tests/openms/source/MzMLFile_test.cpp

  • Added a unit test to validate chromatogram skipping in MzMLFile.
  • Ensures chromatograms are cleared when the flag is enabled.
  • +13/-0   
    PeakFileOptions_test.cpp
    Add unit test for `PeakFileOptions` chromatogram skipping

    src/tests/class_tests/openms/source/PeakFileOptions_test.cpp

  • Added a unit test for setSkipChromatograms and getSkipChromatograms.
  • Validates the behavior of the skip_chromatograms_ flag.
  • +8/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Summary by CodeRabbit

    • New Features
      • Introduced a setting that allows users to optionally skip loading chromatogram data during file imports.
      • Added a new option to ignore loading chromatograms or spectra from mzML files.
    • Bug Fixes
      • Enhanced the control flow for handling chromatograms based on user settings.
    • Refactor
      • Streamlined initialization and processing logic to enhance performance when handling chromatogram data.
    • Tests
      • Added tests to verify the correct behavior of the chromatogram toggling feature, ensuring the setting accurately reflects the expected functionality.
    • Chores
      • Added contributor information for Aditya Muzumdar in the AUTHORS file.

    @coderabbitai

    coderabbitai Bot commented Mar 12, 2025 •

    Copy link
    Copy Markdown
    Contributor

    """

    Walkthrough

    The changes introduce functionality to the PeakFileOptions class, allowing for the conditional skipping of chromatogram data during file processing. Two public methods, setSkipChromatograms(bool) and getSkipChromatograms(), along with a private member variable skip_chromatograms_, have been added. The constructor has been simplified, and the MzML handler has been updated to bypass chromatogram processing when the skip option is enabled. Additionally, new tests have been created to validate the behavior of the skipping functionality.

    Changes

    File(s) Change Summary
    src/openms/include/OpenMS/FORMAT/OPTIONS/PeakFileOptions.h
    src/openms/source/FORMAT/OPTIONS/PeakFileOptions.cpp
    Added member variable skip_chromatograms_ and public methods setSkipChromatograms(bool) and getSkipChromatograms(); simplified constructor initialization.
    src/tests/class_tests/openms/source/MzMLFile_test.cpp
    src/tests/class_tests/openms/source/PeakFileOptions_test.cpp
    Added tests for skipChromatograms feature verifying chromatogram skipping and loading behavior.
    src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp Updated chromatogram processing logic to conditionally skip based on skipChromatograms option.
    AUTHORS Added contributor Aditya Muzumdar.
    CHANGELOG Added fix entry for new option to ignore loading chromatograms or spectra, referencing issue #7901.

    Possibly related issues

    Suggested labels

    Review effort 1/5

    Suggested reviewers

    • timosachsenberg

    Poem

    I'm a clever rabbit from CodeRabbit Inc.,
    Skipping chromatograms in just one blink!
    I hop through functions with a merry tune,
    Making options smooth like a shiny new rune.
    With each test, my joy begins to bloom—
    Debugging days, and hopping under the moon!
    🐇 Code leaps high, beyond the gloom!
    """


    📜 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 dca4b8d and 1786f1d.

    📒 Files selected for processing (1)
    • CHANGELOG (1 hunks)
    🚧 Files skipped from review as they are similar to previous changes (1)
    • CHANGELOG

    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.

    @qodo-code-review

    Copy link
    Copy Markdown
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing Initialization

    The new skip_chromatograms_ member variable is added but not initialized in the constructor. This could lead to undefined behavior if getSkipChromatograms() is called before setSkipChromatograms().

    bool skip_chromatograms_;
    Test Section Name

    The test section name doesn't follow the standard pattern of the codebase. It should likely reference the method being tested (load) rather than using a custom test name.

    START_SECTION((void testSkipChromatograms()))

    @qodo-code-review

    qodo-code-review Bot commented Mar 12, 2025 •

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    ✅ Initialize member variable
    Suggestion Impact:The commit implemented the suggestion by initializing skip_chromatograms_ to false, along with initializing all other member variables in the class

    code diff:

    +    bool skip_chromatograms_ = false;

    Initialize the skip_chromatograms_ member variable in the class to prevent
    undefined behavior. All class member variables should be properly initialized.

    src/openms/include/OpenMS/FORMAT/OPTIONS/PeakFileOptions.h [238]

    -bool skip_chromatograms_;
    +bool skip_chromatograms_ = false;

    [Suggestion has been applied]

    Suggestion importance[1-10]: 7

    __

    Why: Initializing the member variable to false is important to prevent undefined behavior. This matches the default behavior shown in the test (line 226) and ensures consistent behavior across all code paths.

    Medium
    General
    Fix test section name

    The test section name doesn't match the actual test function. The section name
    should match the function being tested, which is load() with the skip
    chromatograms option enabled.

    src/tests/class_tests/openms/source/MzMLFile_test.cpp [1221-1232]

    -START_SECTION((void testSkipChromatograms()))
    +START_SECTION((void load(const String& filename, PeakMap& map) with skip chromatograms))
     {
       MzMLFile file;
       PeakFileOptions opts;
       opts.setSkipChromatograms(true);
       file.setOptions(opts);
     
       PeakMap pm;
       file.load(OPENMS_GET_TEST_DATA_PATH("MzMLFile_1.mzML"), pm);
       TEST_EQUAL(pm.getChromatograms().size(), 0)
     }
     END_SECTION
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion correctly identifies that the test section name doesn't match the actual functionality being tested. Using a more descriptive name that references the actual method being tested (load with skip chromatograms) improves test clarity and documentation.

    Low
    • Update

    @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

    🧹 Nitpick comments (1)
    src/openms/include/OpenMS/FORMAT/OPTIONS/PeakFileOptions.h (1)

    209-210: Add documentation for the new methods

    These new methods lack documentation comments explaining their purpose, unlike most other methods in this file. Consider adding documentation that describes what skipping chromatograms means and when this option would be useful.

    +    /// Sets whether to skip loading chromatograms from the file (useful when only spectra data is needed)
         void setSkipChromatograms(bool skip);
    +    /// Returns whether chromatograms should be skipped during loading
         bool getSkipChromatograms() const;
    📜 Review details

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

    📥 Commits

    Reviewing files that changed from the base of the PR and between 1d7b3f7 and bb6c57e.

    📒 Files selected for processing (5)
    • src/openms/include/OpenMS/FORMAT/OPTIONS/PeakFileOptions.h (2 hunks)
    • src/openms/source/FORMAT/MzMLFile.cpp (1 hunks)
    • src/openms/source/FORMAT/OPTIONS/PeakFileOptions.cpp (1 hunks)
    • src/tests/class_tests/openms/source/MzMLFile_test.cpp (1 hunks)
    • src/tests/class_tests/openms/source/PeakFileOptions_test.cpp (1 hunks)
    🔇 Additional comments (4)
    src/openms/source/FORMAT/MzMLFile.cpp (1)

    151-155: New feature to optimize memory usage and performance when only spectra data is needed.

    The added code checks if chromatograms should be skipped based on the user's preferences and clears them if needed. This implementation is clean and efficient, as it first loads all data and then conditionally removes the chromatograms.

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

    223-230: Test case for the new skipChromatograms functionality looks good.

    The test verifies both the default value (false) and the ability to change the setting, following the established pattern for testing properties in this class.

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

    1221-1232: Integration test for skipChromatograms feature is properly implemented.

    The test effectively validates that when the skipChromatograms option is enabled, no chromatograms are loaded from the test file. This provides good coverage for the new feature.

    src/openms/source/FORMAT/OPTIONS/PeakFileOptions.cpp (1)

    315-323: Implementation of getter and setter for skipChromatograms is clean and follows class conventions.

    These methods follow the established pattern for property getters and setters in this class. The implementation is straightforward and consistent with the rest of the codebase.

    Comment thread src/openms/source/FORMAT/MzMLFile.cpp Outdated

    if (options_.getSkipChromatograms())
    {
    map.getChromatograms().clear();

    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.

    I think this is a suboptimal solution as it will still parse the chromatograms.
    skipping should be done in the parser

    @timosachsenberg

    Copy link
    Copy Markdown
    Contributor

    note that there exists already skip_chromatogram_ in MzMLHandler
    would it be possible to set this if the peak file option is set?

    Comment thread src/openms/source/FORMAT/MzMLFile.cpp Outdated
    handler.setOptions(options_);
    if (options_.getSkipChromatograms())
    {
    handler.setLoadDetail(Internal::XMLHandler::LD_NO_CHROMATOGRAMS);

    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.

    where is this defined?

    @cbielow cbielow left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Nice.
    A few things to consider below.

    @timosachsenberg

    Copy link
    Copy Markdown
    Contributor

    note that there exists already skip_chromatogram_ in MzMLHandler would it be possible to set this if the peak file option is set?

    @adityamuzumdar see my comment. Do you think the enum is even needed? I think it should work just with the peak file option.

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

    41-41: Improve clarity of the CHANGELOG entry

    The current entry is a bit unclear about what the PeakFileOption actually does and includes a redundant "fix" term at the end. Since this entry is already in the "Fixes:" section, the term "fix" is redundant.

    - Add option to PeakFileOption to ignore loading of chromatograms or spectra from mzML fix (#7901)
    + Add option to PeakFileOption to ignore loading of chromatograms from mzML files to optimize memory usage and performance (#7901)

    This change clarifies that the option specifically targets chromatogram loading (which aligns with the PR description) and mentions the benefits of this feature.

    📜 Review details

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

    📥 Commits

    Reviewing files that changed from the base of the PR and between 54658bc and d79ae3b.

    📒 Files selected for processing (2)
    • AUTHORS (1 hunks)
    • CHANGELOG (1 hunks)
    🔇 Additional comments (1)
    AUTHORS (1)

    9-9: Author addition is properly formatted and in alphabetical order.

    The addition of "Aditya Muzumdar" to the AUTHORS file follows the project's formatting conventions and maintains the alphabetical ordering of contributors.

    @timosachsenberg

    Copy link
    Copy Markdown
    Contributor

    please resolve merge conflicts

    @timosachsenberg

    Copy link
    Copy Markdown
    Contributor

    if it builds and tests passes it is ready to go. Thanks!

    @timosachsenberg
    timosachsenberg enabled auto-merge (squash) March 27, 2025 16:28
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants