Skip to content

Added support for more Data-field - #7914

Merged
timosachsenberg merged 8 commits into
OpenMS:developfrom
BhuvanB404:main
Mar 26, 2025
Merged

timosachsenberg merged 8 commits into
OpenMS:developfrom
BhuvanB404:main

Conversation

@BhuvanB404

@BhuvanB404 BhuvanB404 commented Mar 16, 2025 •

Copy link
Copy Markdown
Contributor

User description

Description

ISSUE: #6272
Added changes mentioned in the issue but also want to add the following

data fields :
else if (line.hasPrefix("MSLEVEL="))
{
String tmp = line.substr(8);
int mslevel = tmp.toInt();
spectrum.setMSLevel(mslevel);
}
else if (line.hasPrefix("SOURCE_INSTRUMENT="))
{
String tmp = line.substr(18);
spectrum.setMetaValue("SOURCE_INSTRUMENT", tmp);
}
else if (line.hasPrefix("ORGANISM="))
{
String tmp = line.substr(9);
spectrum.setMetaValue("ORGANISM", tmp);
}
else if (line.hasPrefix("PI="))
{
String tmp = line.substr(3);
spectrum.setMetaValue("PRINCIPAL_INVESTIGATOR", tmp);
}
else if (line.hasPrefix("DATACOLLECTOR="))
{
String tmp = line.substr(14);
spectrum.setMetaValue("DATA_COLLECTOR", tmp);
}
else if (line.hasPrefix("LIBRARYQUALITY="))
{
String tmp = line.substr(15);
spectrum.setMetaValue("LIBRARY_QUALITY", tmp);
}

please check and verify if these changes can be added or not.

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


PR Type

Enhancement


Description

  • Added support for parsing IONMODE metadata in MGF files.

  • Added support for parsing SPECTRUMID metadata in MGF files.

  • Enhanced metadata extraction for better GNPS compatibility.


Changes walkthrough 📝

Relevant files
Enhancement
MascotGenericFile.h
Add parsing for IONMODE and SPECTRUMID metadata                   

src/openms/include/OpenMS/FORMAT/MascotGenericFile.h

  • Added parsing logic for IONMODE metadata.
  • Added parsing logic for SPECTRUMID metadata.
  • Enhanced metadata handling for GNPS-related fields.
  • +5/-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
      • Enhanced data extraction by capturing additional metadata details from input files, including IONMODE, MSLEVEL, SOURCE_INSTRUMENT, ORGANISM, PI, DATACOLLECTOR, and LIBRARYQUALITY information in processed spectra.

    @coderabbitai

    coderabbitai Bot commented Mar 16, 2025 •

    Copy link
    Copy Markdown
    Contributor

    Walkthrough

    The changes introduce multiple new conditional branches within the getNextSpectrum_ method of the MascotGenericFile class. These branches handle lines that begin with specific prefixes: "IONMODE", "MSLEVEL", "SOURCE_INSTRUMENT", "ORGANISM", "PI", "DATACOLLECTOR", and "LIBRARYQUALITY". For each prefix, the code extracts a substring from the line and sets it as a metadata entry in the spectrum object. No alterations were made to the declarations of exported or public entities.

    Changes

    File Change Summary
    src/openms/include/OpenMS/FORMAT/MascotGenericFile.h Added conditional branches in getNextSpectrum_ to handle lines starting with "IONMODE", "MSLEVEL", "SOURCE_INSTRUMENT", "ORGANISM", "PI", "DATACOLLECTOR", and "LIBRARYQUALITY", updating metadata accordingly.

    Sequence Diagram(s)

    sequenceDiagram
        participant Reader as File Reader
        participant Parser as MascotGenericFile
        participant Spectrum as Spectrum Object
    
        Reader->>Parser: Read next line
        Parser->>Parser: Check if line starts with "IONMODE"
        alt Line is "IONMODE"
            Parser->>Parser: Extract substring from index 8
            Parser->>Spectrum: Set metadata {"IONMODE": extracted value}
        end
        Parser->>Parser: Check if line starts with "MSLEVEL"
        alt Line is "MSLEVEL"
            Parser->>Parser: Extract substring from index 9
            Parser->>Spectrum: Set metadata {"MSLEVEL": extracted value}
        end
        Parser->>Parser: Check if line starts with "SOURCE_INSTRUMENT"
        alt Line is "SOURCE_INSTRUMENT"
            Parser->>Parser: Extract substring from index 19
            Parser->>Spectrum: Set metadata {"SOURCE_INSTRUMENT": extracted value}
        end
        Parser->>Parser: Check if line starts with "ORGANISM"
        alt Line is "ORGANISM"
            Parser->>Parser: Extract substring from index 9
            Parser->>Spectrum: Set metadata {"ORGANISM": extracted value}
        end
        Parser->>Parser: Check if line starts with "PI"
        alt Line is "PI"
            Parser->>Parser: Extract substring from index 3
            Parser->>Spectrum: Set metadata {"PI": extracted value}
        end
        Parser->>Parser: Check if line starts with "DATACOLLECTOR"
        alt Line is "DATACOLLECTOR"
            Parser->>Parser: Extract substring from index 15
            Parser->>Spectrum: Set metadata {"DATACOLLECTOR": extracted value}
        end
        Parser->>Parser: Check if line starts with "LIBRARYQUALITY"
        alt Line is "LIBRARYQUALITY"
            Parser->>Parser: Extract substring from index 16
            Parser->>Spectrum: Set metadata {"LIBRARYQUALITY": extracted value}
        end
        Parser->>Reader: Return processed spectrum
    
    Loading

    Poem

    I'm a bunny with clever hops,
    Skipping through code in neat little stops.
    "IONMODE" now finds its rightful place,
    Hopping data with a gentle grace.
    With each line parsed, I smile so bright—
    A rabbit's joy coding into the night!

    ✨ Finishing Touches
    • 📝 Generate Docstrings

    🪧 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 plan to trigger planning for file edits and PR creation.
    • @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

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    6272 - PR Code Verified

    Compliant requirements:

    • Added support for IONMODE metadata
    • SMILES parsing appears to be already implemented
    • SPECTRUMID parsing appears to be already implemented

    Requires further human verification:

    • Verify if the existing SPECTRUMID implementation (storing as "GNPS_Spectrum_ID") is the correct approach
    • Check if additional metadata fields mentioned in PR description (MSLEVEL, SOURCE_INSTRUMENT, ORGANISM, PI, DATACOLLECTOR, LIBRARYQUALITY) should be included as requested by the PR author

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

    Inconsistent Naming

    The PR stores IONMODE directly as "IONMODE" while SPECTRUMID is stored as "GNPS_Spectrum_ID". Consider standardizing the naming convention for metadata fields.

    spectrum.setMetaValue("IONMODE", tmp);

    @qodo-code-review

    Copy link
    Copy Markdown
    Contributor

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Use constant for metadata key

    Consider using a constant for the "IONMODE" key in setMetaValue to maintain
    consistency with other metadata fields that use constants from
    Constants::UserParam.

    src/openms/include/OpenMS/FORMAT/MascotGenericFile.h [302-306]

     else if (line.hasPrefix("IONMODE"))
     {
       String tmp = line.substr(8);
    -  spectrum.setMetaValue("IONMODE", tmp);
    +  spectrum.setMetaValue(Constants::UserParam::IONMODE, tmp);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion improves code consistency by recommending the use of a constant from Constants::UserParam for the "IONMODE" key, similar to how other metadata fields like MSM_INCHI_STRING and MSM_SMILES_STRING are handled. This enhances maintainability and reduces the risk of string literal inconsistencies.

    Medium
    • More

    @coderabbitai coderabbitai Bot left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Actionable comments posted: 1

    📜 Review details

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

    📥 Commits

    Reviewing files that changed from the base of the PR and between 52090de and a04bcb7.

    📒 Files selected for processing (1)
    • src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (1 hunks)
    ⏰ Context from checks skipped due to timeout of 90000ms (5)
    • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
    • 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-13, xcode, 14.2)
    • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
    🔇 Additional comments (1)
    src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (1)

    302-306: Implementation of IONMODE field looks good

    The implementation correctly follows the pattern used for similar metadata fields in the surrounding code. The substring extraction at position 8 aligns with the "IONMODE" prefix length.

    @timosachsenberg

    Copy link
    Copy Markdown
    Contributor

    Nice. Can you add the other ones above as suggested?

    @BhuvanB404

    BhuvanB404 commented Mar 23, 2025 •

    Copy link
    Copy Markdown
    Contributor Author

    Hello @timosachsenberg. I am sorry for the late response. My laptop had display issues and I got it back today after repairs. I have added the changes to the PR and would like to request a review again.

    else if (line.hasPrefix("MSLEVEL"))
    {
    String tmp = line.substr(8);
    spectrum.setMetaValue("MSLEVEL", tmp);

    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.

    Check if the MS level could also be stored in a member of spectrum.

    @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)
    src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (1)

    307-325: Great implementation of MSLEVEL with error handling, but could be more consistent.

    The MSLEVEL implementation correctly sets both the MS level and metadata, with proper error handling for invalid input. However, there's an inconsistency between the two catch blocks:

    • In the std::invalid_argument block, you set both the MS level and metadata.
    • In the std::out_of_range block, you only set the MS level, without updating metadata.
     catch (const std::out_of_range& /*e*/)
     {
         spectrum.setMSLevel(2);
    +    spectrum.setMetaValue("MSLEVEL", "2");
     }

    Additionally, I noticed a minor indentation issue in line 309 that could be fixed for consistency.

    📜 Review details

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

    📥 Commits

    Reviewing files that changed from the base of the PR and between 257c2c8 and bf09087.

    📒 Files selected for processing (1)
    • src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (1 hunks)
    ⏰ 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 (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: build-and-test (ubuntu-22.04, g++, 11)
    🔇 Additional comments (2)
    src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (2)

    326-350: Successfully implemented all required metadata fields.

    You've correctly implemented all the metadata fields mentioned in the PR objectives (SOURCE_INSTRUMENT, ORGANISM, PI, DATACOLLECTOR, LIBRARYQUALITY) with appropriate substring extraction from the input line.

    For future maintenance, consider refactoring these similar metadata handling blocks into a helper method to reduce code duplication, especially if more fields will be added in the future.


    302-350:

    Details

    ✅ Verification successful

    Verify if MS level should be stored both as a property and metadata.

    The code now stores MSLEVEL both as a spectrum property (via setMSLevel()) and as a metadata entry, which is a good approach for backward compatibility. However, this pattern is unique compared to other fields.


    🏁 Script executed:

    #!/bin/bash
    # Check if there are other places in the codebase where this dual storage pattern is used
    # or if other special fields are treated differently from regular metadata
    
    # Look for other usages of setMSLevel along with setMetaValue
    echo "Checking for patterns of setting both MS level and metadata:"
    rg -A 2 "setMSLevel\(" | rg "setMetaValue"
    
    # Look for how MSLEVEL is used elsewhere
    echo "Checking how MSLEVEL is used in the codebase:"
    rg "MSLEVEL" --type cpp

    Length of output: 2042


    MSLEVEL Dual Storage Verified

    After reviewing the code and verifying against the codebase, it appears that storing the MS level both as a spectrum property (via setMSLevel()) and as a metadata entry (via setMetaValue("MSLEVEL", ...)) is intentional and aimed at ensuring backward compatibility. This dual storage pattern is unique to MSLEVEL—other fields (e.g., IONMODE, ORGANISM) do not use the same approach—which suggests that its special treatment was deliberate.

    • The dual storage is isolated to the MascotGenericFile.h implementation.
    • No similar dual pattern was found elsewhere in the codebase for other fields.
    • The use of "MSLEVEL" in both setMSLevel() and setMetaValue() aligns with legacy expectations.

    No changes are required unless you feel adding a clarifying inline comment would improve maintainability.

    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.

    2 participants