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

feat: Add parameter validation for OffTargetDetector.__init__ #103

Merged
merged 7 commits into from
Jan 13, 2025

Conversation

ameynert
Copy link
Contributor

@ameynert ameynert commented Jan 7, 2025

  • max_amplicon_size > 0
  • max_primer_hits >= 0
  • max_primer_pair_hits >= 0
  • min_primer_pair_hits >= 0
  • three_prime_region_length > 0
  • 0 <= max_mismatches_in_three_prime_region <= three_prime_region_length
  • max_mismatches >= 0
  • max_gap_opens >= 0
  • max_gap_extends == -1 or max_gap_extends >= 0

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.81%. Comparing base (baf2e65) to head (ac16e3c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
+ Coverage   96.77%   96.81%   +0.04%     
==========================================
  Files          26       26              
  Lines        1766     1789      +23     
  Branches      205      215      +10     
==========================================
+ Hits         1709     1732      +23     
  Misses         31       31              
  Partials       26       26              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ameynert ameynert marked this pull request as ready for review January 7, 2025 18:03
@ameynert ameynert requested review from nh13 and tfenne as code owners January 7, 2025 18:03
@ameynert ameynert self-assigned this Jan 7, 2025
Copy link
Member

@tfenne tfenne left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @ameynert. Looks great but would like us to settle on a higher min for 3' region length before merging please. If @nh13 doesn't respond, I think we could set that to 10 for now.

Comment on lines 249 to 263
if three_prime_region_length < 1:
errors.append(
"'three_prime_region_length' must be greater than 0. "
f"Saw {three_prime_region_length}"
)
Copy link
Member

Choose a reason for hiding this comment

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

Given that we use this to drive the "seed region" for bwa I think we should probably enforce a higher miniumum. @nh13 do you have a thought on what's reasonable? E.g. 8, 10, 12 or somewhere around there?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that since this value is use for the seed length, we should (1) add that explanation to the parameter or class docs, and (2) have a minimum of 8.

Base automatically changed from am_primer_pair_hit_building to main January 10, 2025 22:50
@ameynert ameynert force-pushed the am_overlap_detector_post_init_validation branch from 1a61cb0 to c9075ac Compare January 10, 2025 23:06
@ameynert
Copy link
Contributor Author

I've added checks for max_gap_opens and max_gap_extends as well. Will wait on @nh13 to agree on a min for 3' region length before merging.

Copy link

coderabbitai bot commented Jan 10, 2025

Walkthrough

The changes enhance parameter validation in the OffTargetDetector class located in offtarget_detector.py. A new constant, MINIMUM_THREE_PRIME_REGION_LENGTH, is introduced, and the constructor now enforces explicit constraints on several parameters, including max_amplicon_size and three_prime_region_length. Violations of these constraints result in ValueError exceptions with specific messages. Additionally, a new test function, test_init, is added to test_offtarget.py to validate these constraints during initialization, ensuring that improper configurations are detected and reported effectively.


📜 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 c9075ac and ac16e3c.

📒 Files selected for processing (2)
  • prymer/offtarget/offtarget_detector.py (3 hunks)
  • tests/offtarget/test_offtarget.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Tests (3.12)
  • GitHub Check: Tests (3.11)
🔇 Additional comments (4)
prymer/offtarget/offtarget_detector.py (3)

107-109: Good addition of the minimum seed length constant.

Defining MINIMUM_THREE_PRIME_REGION_LENGTH ensures a consistent minimum for the seed length.


195-196: Clear documentation of three_prime_region_length.

Specifying that three_prime_region_length is used as the seed length for bwa aln enhances clarity.


247-293: Effective parameter validation implemented.

The constructor correctly validates parameters and raises ValueError with informative messages when constraints are violated.

tests/offtarget/test_offtarget.py (1)

355-401: Comprehensive tests for constructor validation.

The test_init function thoroughly checks parameter constraints, ensuring ValueError is raised appropriately for invalid inputs.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@tfenne
Copy link
Member

tfenne commented Jan 13, 2025

@ameynert as things have gotten a bit complicated, why don't we merge this with three_prime_region_length > 0 and we can circle back and increase it as/when we see fit?

@ameynert ameynert merged commit a193734 into main Jan 13, 2025
7 checks passed
@ameynert ameynert deleted the am_overlap_detector_post_init_validation branch January 13, 2025 23:26
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.

3 participants