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: bug with -O being used for gap opening penalty and samtools output directory #3

Closed
wants to merge 2 commits into from

Conversation

korbit-ai[bot]
Copy link

@korbit-ai korbit-ai bot commented Aug 21, 2024

Description

Gap penalty of minimap2 is done via "-O" option and the very same option also exists for samtools, but to indicate output directory. Using "-O" in the "extra" leads to the following error because of using snakemake utils for samtools (https://github.com/snakemake/snakemake-wrapper-utils/blob/f9cba17cb380dc7e6729a845ae37f26972c3d1dd/snakemake_wrapper_utils/samtools.py#LL76C23-L76C23):

You have specified output format (`-O/--output-fmt`) in params.extra; this is automatically inferred from output file extension.

The fastest and not over-engineered solution to me was to add the gap_opening variable to params, but I feel that it's also not very elegant especially when it comes to modifying the other penalty scores, but they can still be set in the extra.

QC

  • I confirm that:

For all wrappers added by this PR,

  • there is a test case which covers any introduced changes,
  • input: and output: file paths in the resulting rule can be changed arbitrarily,
  • either the wrapper can only use a single core, or the example rule contains a threads: x statement with x being a reasonable default,
  • rule names in the test case are in snake_case and somehow tell what the rule is about or match the tools purpose or name (e.g., map_reads for a step that maps reads),
  • all environment.yaml specifications follow the respective best practices,
  • wherever possible, command line arguments are inferred and set automatically (e.g. based on file extensions in input: or output:),
  • all fields of the example rules in the Snakefiles and their entries are explained via comments (input:/output:/params: etc.),
  • stderr and/or stdout are logged correctly (log:), depending on the wrapped tool,
  • temporary files are either written to a unique hidden folder in the working directory, or (better) stored where the Python function tempfile.gettempdir() points to (see here; this also means that using any Python tempfile default behavior works),
  • the meta.yaml contains a link to the documentation of the respective tool or command,
  • Snakefiles pass the linting (snakemake --lint),
  • Snakefiles are formatted with snakefmt,
  • Python wrapper scripts are formatted with black.
  • Conda environments use a minimal amount of channels, in recommended ordering. E.g. for bioconda, use (conda-forge, bioconda, nodefaults, as conda-forge should have highest priority and defaults channels are usually not needed because most packages are in conda-forge nowadays).

Description by Korbit AI

What change is being made?

Fix the bug by adding a parameter for gap opening penalty (-O) in the minimap2 aligner wrapper and correct the samtools output directory handling.

Why are these changes being made?

The gap opening penalty parameter was previously missing, causing incorrect alignment results. Additionally, the samtools output directory handling needed correction to ensure proper file output locations. These changes ensure accurate alignment and correct file management.

Summary by CodeRabbit

  • New Features
    • Introduced a gap_opening parameter to enhance the configurability of the minimap2 alignment process, allowing users to specify gap opening penalties during alignment.
    • Improved command functionality to include the gap_opening parameter for seamless integration with the minimap2 tool.

Copy link
Author

korbit-ai bot commented Aug 21, 2024

Clone of the PR snakemake/snakemake-wrappers#1450

Copy link

My review is in progress 📖 - I will have feedback for you in a few minutes!

1 similar comment
Copy link
Author

korbit-ai bot commented Aug 21, 2024

My review is in progress 📖 - I will have feedback for you in a few minutes!

Copy link

coderabbitai bot commented Aug 21, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a new parameter, gap_opening, to the script in bio/minimap2/aligner/wrapper.py. This parameter allows users to set a gap opening penalty when executing the minimap2 alignment tool. The command-line arguments for minimap2 have been updated to include this new parameter, enhancing the script's configurability for sequence alignment tasks.

Changes

Files Change Summary
bio/minimap2/aligner/wrapper.py Added gap_opening parameter from snakemake.params to allow user-defined gap opening penalties in minimap2 alignment.

Poem

In the code where rabbits roam,
A new gap opening finds its home.
With parameters set just right,
Aligning sequences takes flight.
Hopping through data with glee,
Configurable tools, oh so free! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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
Author

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

I have reviewed your code and found 1 potential issue.

@@ -15,6 +15,7 @@
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
sort = snakemake.params.get("sorting", "none")
sort_extra = snakemake.params.get("sort_extra", "")
gap_opening = snakemake.params.get("gap_opening", "")
Copy link
Author

Choose a reason for hiding this comment

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

category Functionality

The new gap_opening parameter is retrieved without a default value. Consider providing a default value to ensure consistent behavior when the parameter is not explicitly set in the Snakemake rule. For example, you could modify the line to: gap_opening = snakemake.params.get("gap_opening", "10,3") (using minimap2's default values for gap open and extend penalties).

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link

I have reviewed your code and found 3 potential issues.

Choose a reason for hiding this comment

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

category Functionality

The -O {gap_opening} option is currently being added to the minimap2 command unconditionally. This could potentially cause errors if the gap_opening parameter is empty or not applicable in certain scenarios. Consider adding a condition to only include this option when gap_opening is not empty. For example, you could modify the shell command to include this option conditionally:

shell(
    "(minimap2"
    " -t {snakemake.threads}"
    " {extra} "
    " {'-O ' + gap_opening if gap_opening else ''}"
    " {snakemake.input.target}"
    " {snakemake.input.query}"
    " {pipe_cmd}"
    " > {snakemake.output[0]}"
    ") {log}"
)

This change will ensure that the -O option is only included when a gap opening penalty is actually specified.

Chat with Korbit by mentioning @development-korbit-ai-mentor, and give a 👍 or 👎 to help Korbit improve your reviews.

Choose a reason for hiding this comment

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

category Error Handling

Consider adding error handling for the shell command execution. Wrap the shell() function call in a try-except block to catch and handle any exceptions that may occur during the execution of minimap2 and samtools commands. This will ensure that errors are logged and the script exits gracefully in case of failures.

Chat with Korbit by mentioning @development-korbit-ai-mentor, and give a 👍 or 👎 to help Korbit improve your reviews.

Choose a reason for hiding this comment

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

category Functionality

The newly added gap_opening parameter is a good addition to allow more flexibility in the alignment process. However, it's currently not being validated or handled properly. Consider adding input validation for this parameter and handling cases where it might be empty or invalid. For example, you could use a default value if it's not provided or raise an error if an invalid value is given. Also, it would be helpful to update the documentation to explain the usage and expected format of this new parameter.

Chat with Korbit by mentioning @development-korbit-ai-mentor, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link

System configuration at time of review:

- category__name: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__database_operations: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__documentation: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__logging: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__error_handling: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__systems_and_environment: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__objects_and_data_structures: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__tests: {'enabled': False, 'user_values': {'minimum_severity': 'nit'}}
- category__readability_and_maintainability: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__asynchronous_processing: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__design_patterns: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__third_party_libraries: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__performance: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- category__security: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}
- pull_request_review_schedule: {'enabled': True, 'user_values': {'review_schedule': 'non-draft'}}
- maximum_shown_issues: {'enabled': True, 'user_values': {'max_issues': 10}}
- auto_pr_description: {'enabled': True, 'user_values': {}}
- category__functionality: {'enabled': True, 'user_values': {'minimum_severity': 'nit'}}

Copy link

@coderabbitai full review

Copy link

coderabbitai bot commented Aug 22, 2024

Actions performed

Full review triggered.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b915e37 and 120f744.

Files selected for processing (1)
  • bio/minimap2/aligner/wrapper.py (2 hunks)
Additional context used
Ruff
bio/minimap2/aligner/wrapper.py

18-18: Undefined name snakemake

(F821)

Additional comments not posted (2)
bio/minimap2/aligner/wrapper.py (2)

18-18: Consider providing a default value for gap_opening.

The gap_opening parameter is retrieved without a default value. Consider providing a default value to ensure consistent behavior when the parameter is not explicitly set in the Snakemake rule. For example, you could modify the line to:

gap_opening = snakemake.params.get("gap_opening", "10,3")

(using minimap2's default values for gap open and extend penalties).

Tools
Ruff

18-18: Undefined name snakemake

(F821)


49-49: Include the -O option conditionally.

The -O {gap_opening} option is currently being added to the minimap2 command unconditionally. This could potentially cause errors if the gap_opening parameter is empty or not applicable in certain scenarios. Consider adding a condition to only include this option when gap_opening is not empty. For example, you could modify the shell command to include this option conditionally:

shell(
    "(minimap2"
    " -t {snakemake.threads}"
    " {extra} "
    " {'-O ' + gap_opening if gap_opening else ''}"
    " {snakemake.input.target}"
    " {snakemake.input.query}"
    " {pipe_cmd}"
    " > {snakemake.output[0]}"
    ") {log}"
)

This change will ensure that the -O option is only included when a gap opening penalty is actually specified.

@furwellness
Copy link
Owner

/review

Copy link

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Potential Conflict
The new gap_opening parameter might conflict with the existing extra parameter if both are used to set the gap opening penalty.

Parameter Validation
The gap_opening parameter is used without validation, which could lead to errors if an invalid value is provided.

Copy link

/review

@korbit-ai korbit-ai bot deleted the branch cloned_master_b915e August 29, 2024 19:20
@korbit-ai korbit-ai bot closed this Aug 29, 2024
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