Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValueError on enzyme validation #178

Merged
merged 11 commits into from
Oct 8, 2024
Merged

Conversation

levitsky
Copy link
Contributor

@levitsky levitsky commented Oct 8, 2024

User description

Closes #176.

This exempts CS from checking for extra = signs in ontology_term_parser, preserving the old behavior in all other cases but avoiding the unwanted ValueError when parsing cleave rule specification.


PR Type

Bug fix


Description

  • Fixed a ValueError in the ontology_term_parser function by exempting the CS prefix from additional = checks.
  • Ensured that key-value pairs are split only once to avoid incorrect parsing.
  • Improved error handling by raising a ValueError when a non-key-value pair is detected.

Changes walkthrough 📝

Relevant files
Bug fix
sdrf_schema.py
Fix ValueError in ontology_term_parser for enzyme validation

sdrf_pipelines/sdrf/sdrf_schema.py

  • Modified ontology_term_parser to handle CS prefix without raising
    ValueError.
  • Adjusted logic to split key-value pairs only once.
  • Added specific condition to exempt CS from additional = checks.
  • +6/-4     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Summary by CodeRabbit

    • New Features

      • Enhanced ontology term validation process for improved accuracy.
      • Improved error handling in the parsing of key-value pairs.
    • Bug Fixes

      • Resolved issues related to handling key-value pairs with additional equal signs.
    • Chores

      • Updated package version to 0.0.30.
      • Added setuptools as a dependency.
      • Re-included rdflib in the requirements.
      • Added pytest-datadir to the development requirements.

    These updates aim to provide users with a more reliable experience when working with ontology terms.

    Copy link

    coderabbitai bot commented Oct 8, 2024

    Walkthrough

    The changes made in the sdrf_schema.py file focus on enhancing the ontology_term_parser function and the OntologyTerm class. The ontology_term_parser function's logic has been refined to better handle key-value pair parsing, specifically addressing cases with multiple equal signs. Additionally, the validate method in the OntologyTerm class has been improved for more robust validation of ontology terms, ensuring that terms are correctly checked against the provided ontology and handling missing terms more explicitly. Updates were also made to versioning and dependencies in the meta.yaml, requirements-dev.txt, and requirements.txt files, along with improvements to the CI workflow.

    Changes

    File Change Summary
    sdrf_pipelines/sdrf/sdrf_schema.py Modified ontology_term_parser to improve key-value parsing logic and error handling. Updated validate method in OntologyTerm for enhanced term validation and error handling.
    recipe/meta.yaml Updated version from "0.0.29" to "0.0.30" and added setuptools to run and host requirements. Corrected indentation for duckdb and rdflib.
    .github/workflows/ci.yml Added steps to set up Python 3.12 and install Black directly in the CI workflow.
    requirements-dev.txt Added setuptools and explicitly included pytest-datadir for proper formatting.
    requirements.txt Added setuptools and re-included rdflib package.
    setup.py Added a comma after the "setuptools" entry in the install_requires list.

    Assessment against linked issues

    Objective Addressed Explanation
    Improve error handling for enzyme information (176)
    Enhance validation process for ontology terms (176)

    🐰 In the realm of code so bright,
    Parsing terms now feels just right.
    With checks and balances in place,
    Errors vanish without a trace.
    Oh, what joy in every line,
    Validation's dance, so divine! 🌟


    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    ❤️ 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.

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

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Error Handling
    The new error message for non-key-value pairs might be too generic. Consider providing more context or guidance in the error message.

    Code Duplication
    There are two separate ValueError raises with different conditions. Consider combining them for better readability and maintenance.

    Copy link

    codiumai-pr-agent-pro bot commented Oct 8, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Performance
    Use str.partition() for more efficient and cleaner key-value pair extraction

    Consider using the str.partition() method instead of str.split() for a more
    efficient key-value pair extraction, as it always returns a 3-tuple and doesn't
    require checking the length of the result.

    sdrf_pipelines/sdrf/sdrf_schema.py [59-61]

    -value_terms = name.split("=", 1)
    -if len(value_terms) == 1:
    -    raise ValueError("Not a key-value pair: " + name)
    +key, separator, value = name.partition("=")
    +if not separator:
    +    raise ValueError(f"Not a key-value pair: {name}")
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The use of str.partition() is a more efficient method for extracting key-value pairs, as it avoids the need to check the length of the result. This change enhances the performance and readability of the code, aligning well with the PR's goal of refining parsing logic.

    8
    Enhancement
    Simplify the parsing logic using a dictionary comprehension for improved readability and conciseness

    Consider using a dictionary comprehension to simplify the parsing logic and improve
    readability. This approach can handle the special case for 'CS' more elegantly.

    sdrf_pipelines/sdrf/sdrf_schema.py [58-66]

    -for name in values:
    -    value_terms = name.split("=", 1)
    -    if len(value_terms) == 1:
    -        raise ValueError("Not a key-value pair: " + name)
    -    if "=" in value_terms[1] and value_terms[0].lower() != 'cs':
    -        raise ValueError(
    -            f"Invalid term: {name} after splitting by '=', please check the prefix (e.g. AC, NT, " f"TA..)"
    -        )
    -    term[value_terms[0].strip().upper()] = value_terms[1].strip().lower()
    +term = {
    +    k.strip().upper(): v.strip().lower()
    +    for k, v in (name.split("=", 1) for name in values)
    +    if len(name.split("=", 1)) == 2 and (k.lower() == 'cs' or "=" not in v)
    +}
    +if len(term) != len(values):
    +    raise ValueError("Invalid key-value pair found")
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion to use a dictionary comprehension simplifies the parsing logic, making the code more concise and readable. It effectively handles the special case for 'CS' and ensures that all key-value pairs are valid, which aligns with the PR's intent to improve parsing logic.

    7

    💡 Need additional feedback ? start a PR chat

    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Actionable comments posted: 0

    🧹 Outside diff range and nitpick comments (1)
    sdrf_pipelines/sdrf/sdrf_schema.py (1)

    59-62: Add unit tests for the updated parsing logic

    Consider adding unit tests to ensure that the ontology_term_parser function correctly handles 'CS' terms with '=' in the value, and continues to raise ValueError for invalid formats in other keys.

    Would you like assistance in writing these unit tests or creating a new GitHub issue to track this task?

    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    📥 Commits

    Files that changed from the base of the PR and between 24151ed and 5aa8c42.

    📒 Files selected for processing (1)
    • sdrf_pipelines/sdrf/sdrf_schema.py (1 hunks)
    🧰 Additional context used
    🔇 Additional comments (1)
    sdrf_pipelines/sdrf/sdrf_schema.py (1)

    59-62: LGTM: Enhanced parsing logic for 'CS' term

    The modifications to the ontology_term_parser function correctly handle key-value pairs where the value contains '=' characters, specifically for the 'CS' key. This resolves the ValueError encountered during enzyme validation and preserves existing behavior for other cases.

    Lev Levitsky and others added 2 commits October 8, 2024 15:12
    Copy link

    @coderabbitai coderabbitai bot left a comment

    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 and nitpick comments (1)
    recipe/meta.yaml (1)

    Line range hint 1-53: Minor improvements and suggestions.

    1. The indentation corrections for the run dependencies (duckdb, rdflib) are good. They improve readability and ensure correct parsing of the YAML file.

    2. There's a commented out license_file entry with a note that a patch has been applied upstream. Consider adding a TODO comment or creating an issue to remind the team to uncomment this line in the next release that includes the upstream changes.

    Consider adding a TODO comment like this:

      ##license_file: LICENSE ## patch is applied upstream, next version will have it
      # TODO: Uncomment the license_file entry in the next release that includes the upstream changes
    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    📥 Commits

    Files that changed from the base of the PR and between 5aa8c42 and e3066ae.

    📒 Files selected for processing (1)
    • recipe/meta.yaml (2 hunks)
    🧰 Additional context used
    🔇 Additional comments (1)
    recipe/meta.yaml (1)

    4-4: Version update looks good.

    The version bump from 0.0.29 to 0.0.30 is appropriate for the bug fix described in the PR objectives. This minor version increment correctly reflects the nature of the changes made.

    recipe/meta.yaml Outdated Show resolved Hide resolved
    Copy link

    @coderabbitai coderabbitai bot left a comment

    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 and nitpick comments (3)
    requirements-dev.txt (1)

    Line range hint 1-6: Consider enhancing requirements file structure and specificity.

    While the current format is clear, consider the following improvements:

    1. Sort the packages alphabetically for easier readability and maintenance.
    2. Consider adding version specifications to ensure consistency across development environments.

    Example:

    black==<version>
    isort==<version>
    pre-commit==<version>
    pytest==<version>
    pytest-datadir==<version>
    setuptools==<version>
    
    requirements.txt (1)

    Line range hint 3-8: Consider migrating from pandas_schema to pandera.

    The comment in the file indicates that pandas_schema might not be maintained anymore and suggests pandera as an alternative. However, pandas_schema is still listed as a dependency.

    To improve the project's long-term maintainability:

    1. Evaluate the feasibility of migrating from pandas_schema to pandera.
    2. If migration is possible, create a separate issue or PR to handle this transition.
    3. If migration is not currently possible, consider adding a TODO comment with a link to an issue tracking this potential future work.

    Would you like assistance in creating an issue to track the potential migration from pandas_schema to pandera?

    .github/workflows/ci.yml (1)

    20-21: Approved: Good addition of pyproject.toml support for Black.

    The addition of use_pyproject: true is a positive change that allows Black to use the configuration from pyproject.toml. This aligns with best practices for Python project configuration and enables centralized management of Black settings.

    Consider adding a comment explaining why this parameter was added, to help future maintainers understand the reasoning behind this change. For example:

    with:
      use_pyproject: true  # Use Black configuration from pyproject.toml for consistent formatting
    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    📥 Commits

    Files that changed from the base of the PR and between e3066ae and 2557663.

    📒 Files selected for processing (3)
    • .github/workflows/ci.yml (1 hunks)
    • requirements-dev.txt (1 hunks)
    • requirements.txt (1 hunks)
    🧰 Additional context used
    🔇 Additional comments (3)
    requirements-dev.txt (2)

    5-5: LGTM: Addition of pytest-datadir enhances testing capabilities.

    The inclusion of pytest-datadir is a good addition to the development requirements. This pytest plugin will facilitate better management of test data directories and files, improving the overall testing infrastructure of the project.


    6-6: LGTM: Addition of setuptools improves package management.

    The inclusion of setuptools in the development requirements is a positive step. This tool will enhance the project's packaging and distribution capabilities, ensuring a more robust and consistent development environment across different setups.

    requirements.txt (1)

    14-14: Verify the necessity of re-adding rdflib.

    The rdflib package has been re-added to the requirements. While this library is commonly used for working with RDF data and could be relevant for ontology-related tasks, it's important to confirm its necessity in the context of this PR.

    Could you please clarify:

    1. Why was rdflib previously removed?
    2. How does re-adding rdflib relate to fixing the ValueError on enzyme validation?
    3. Are there any specific features of rdflib that are now required for the ontology term parsing or validation?
    ✅ Verification successful

    Verified the necessity of re-adding rdflib.

    The rdflib package is actively used in sdrf_pipelines/ols/ols.py and is listed as a dependency in setup.py. This confirms that re-adding rdflib is essential for handling RDF data and ontology-related functionalities within the project.

    🏁 Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Check for rdflib usage in the codebase
    
    # Test: Search for rdflib imports or usage
    echo "Searching for rdflib usage:"
    rg --type python 'import rdflib|from rdflib'
    
    # Test: Check if rdflib is used in ontology_term_parser or related files
    echo "Checking ontology_term_parser for rdflib usage:"
    rg --type python 'rdflib' $(fd -t f ontology_term_parser)
    

    Length of output: 336


    Script:

    #!/bin/bash
    # Description: Check for rdflib usage in the codebase with corrected file types
    
    # Test: Search for rdflib imports or usage
    echo "Searching for rdflib usage:"
    rg --type py 'import rdflib|from rdflib'
    
    # Test: Check if rdflib is used in ontology_term_parser or related files
    echo "Checking ontology_term_parser for rdflib usage:"
    rg --type py 'rdflib' $(fd -t f ontology_term_parser)
    

    Length of output: 614

    requirements.txt Show resolved Hide resolved
    Copy link

    @coderabbitai coderabbitai bot left a comment

    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 and nitpick comments (2)
    .github/workflows/ci.yml (2)

    25-28: Pin the Black version for consistency

    While installing Black is correct, it's recommended to pin the version to ensure consistent behavior across different environments and over time.

    Consider modifying the installation command:

           run: |
             python -m pip install --upgrade pip
    -        pip install black
    +        pip install black==23.10.1  # Replace with the desired version

    This change will ensure that the same version of Black is used consistently, preventing potential issues caused by version differences.


    32-32: LGTM! Consider adding more Black options for consistency

    The direct invocation of Black is correct and provides more control over the linting process. Great job on this change!

    To ensure full consistency with your project's coding standards, consider adding more options to the Black command. For example:

    -        run: black . --check
    +        run: black . --check --line-length 100 --target-version py38

    Adjust the --line-length and --target-version options according to your project's specific requirements. This will ensure that Black enforces consistent formatting across all contributors' environments.

    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    📥 Commits

    Files that changed from the base of the PR and between 2557663 and 27ae46e.

    📒 Files selected for processing (3)
    • .github/workflows/ci.yml (1 hunks)
    • recipe/meta.yaml (2 hunks)
    • setup.py (1 hunks)
    ✅ Files skipped from review due to trivial changes (1)
    • setup.py
    🚧 Files skipped from review as they are similar to previous changes (1)
    • recipe/meta.yaml
    🧰 Additional context used
    🪛 actionlint
    .github/workflows/ci.yml

    20-20: the runner of "actions/setup-python@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

    (action)

    🔇 Additional comments (1)
    .github/workflows/ci.yml (1)

    18-32: Summary of CI workflow improvements

    The changes to the PythonBlack job in the CI workflow are beneficial:

    1. Setting up a specific Python version (3.12) ensures consistency in the linting environment.
    2. Directly installing and running Black provides more control over the linting process.

    These updates will help maintain code quality and consistency across the project. The suggested improvements (updating action versions, pinning Black version, and adding Black options) will further enhance the robustness of the CI process.

    🧰 Tools
    🪛 actionlint

    20-20: the runner of "actions/setup-python@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

    (action)

    Comment on lines +19 to +22
    - name: Set up Python 3.12
    uses: actions/setup-python@v2
    with:
    python-version: 3.12 # Set your desired Python version here
    Copy link

    Choose a reason for hiding this comment

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

    ⚠️ Potential issue

    Update the actions/setup-python action version

    The current version (v2) of the actions/setup-python action is outdated. To ensure compatibility and access to the latest features, consider updating to the latest stable version.

    Apply this change:

    -        uses: actions/setup-python@v2
    +        uses: actions/setup-python@v4

    This update will resolve the warning from the static analysis tool and ensure you're using the most recent stable version of the action.

    📝 Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    - name: Set up Python 3.12
    uses: actions/setup-python@v2
    with:
    python-version: 3.12 # Set your desired Python version here
    - name: Set up Python 3.12
    uses: actions/setup-python@v4
    with:
    python-version: 3.12 # Set your desired Python version here
    🧰 Tools
    🪛 actionlint

    20-20: the runner of "actions/setup-python@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

    (action)

    @ypriverol ypriverol self-requested a review October 8, 2024 16:01
    @ypriverol ypriverol merged commit eb1f9aa into bigbio:main Oct 8, 2024
    10 of 11 checks passed
    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.

    Validation error for enzyme information encoded by fragpipe
    2 participants