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: allow for left/right primer hits to overlap when building primer pair hits with OverlapDetector #102

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ameynert
Copy link
Contributor

@ameynert ameynert commented Jan 1, 2025

See discussion.

The code before this PR does not return primer pair hits where the hits to the left and right primers overlap, and does not specify a minimum acceptable amplicon size.

This change adds two new parameters to the OffTargetDetector to address this:

  • allow_overlapping_hits - defaults to False to maintain current behaviour. If this is set to True, then primer pair hits where the left and right primer hits overlap are allowed, as long as they meet the acceptable amplicon size criteria.
  • min_amplicon_size - defaults to 1 to maintain current behaviour, and is overridden by allow_overlapping_hits=False.

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.82%. Comparing base (a193734) to head (861736a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #102   +/-   ##
=======================================
  Coverage   96.81%   96.82%           
=======================================
  Files          26       26           
  Lines        1789     1794    +5     
  Branches      215      216    +1     
=======================================
+ Hits         1732     1737    +5     
  Misses         31       31           
  Partials       26       26           

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

@ameynert ameynert force-pushed the am_allow_overlapping_hits branch from dce889a to 434218d Compare January 7, 2025 17:57
@ameynert ameynert changed the base branch from am_primer_pair_hit_building to am_overlap_detector_post_init_validation January 7, 2025 17:58
@ameynert ameynert force-pushed the am_allow_overlapping_hits branch from 434218d to e39670e Compare January 7, 2025 18:02
@ameynert ameynert marked this pull request as ready for review January 7, 2025 18:30
@ameynert ameynert requested review from nh13 and tfenne as code owners January 7, 2025 18:30
@ameynert ameynert self-assigned this Jan 7, 2025
@tfenne
Copy link
Member

tfenne commented Jan 10, 2025

I took a quick look at this ... and I'm leaning towards thinking that we should:
a) not even parameterize, but always allow overlapping hits
b) default the "min amplicon size" to something slightly higher, e.g. 20bp

@nh13 and @ameynert what do you think of that?

@ameynert ameynert force-pushed the am_overlap_detector_post_init_validation branch from 1a61cb0 to c9075ac Compare January 10, 2025 23:06
@ameynert ameynert force-pushed the am_allow_overlapping_hits branch from cfaca8f to 22fc66f Compare January 10, 2025 23:14
@ameynert
Copy link
Contributor Author

I took a quick look at this ... and I'm leaning towards thinking that we should: a) not even parameterize, but always allow overlapping hits b) default the "min amplicon size" to something slightly higher, e.g. 20bp

@nh13 and @ameynert what do you think of that?

I agree - I implemented it this way with the intention of not making a breaking change, but I think a user is more likely to not care too much if the primers overlap a bit so long as they get a long enough amplicon.

Base automatically changed from am_overlap_detector_post_init_validation to main January 13, 2025 23:26
@ameynert ameynert force-pushed the am_allow_overlapping_hits branch from 22fc66f to 6ccafec Compare January 13, 2025 23:30
@@ -165,13 +165,13 @@ def build_primer_pairs( # noqa: C901

# If the right primer isn't "to the right" of the left primer, move on
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes were from linting.

Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces modifications to the off-target detection functionality in the Prymer library. The changes primarily focus on enhancing the OffTargetDetector class by adding two new parameters: min_amplicon_size and allow_overlapping_hits. These additions provide more granular control over amplicon detection, allowing users to specify minimum amplicon sizes and control how overlapping primer hits are handled. The modifications span across multiple files, including the main implementation in offtarget_detector.py and corresponding test files, with updates to method signatures, constructor logic, and test cases to support the new functionality.

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.

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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a193734 and 6ccafec.

📒 Files selected for processing (3)
  • prymer/api/picking.py (1 hunks)
  • prymer/offtarget/offtarget_detector.py (11 hunks)
  • tests/offtarget/test_offtarget.py (7 hunks)
✅ Files skipped from review due to trivial changes (1)
  • prymer/api/picking.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Tests (3.12)
  • GitHub Check: Tests (3.11)
🔇 Additional comments (1)
tests/offtarget/test_offtarget.py (1)

288-294: Tests updated appropriately.

The tests correctly incorporate the new parameters, ensuring proper coverage for min_amplicon_size and allow_overlapping_hits.

prymer/offtarget/offtarget_detector.py Outdated Show resolved Hide resolved
prymer/offtarget/offtarget_detector.py Outdated Show resolved Hide resolved
prymer/offtarget/offtarget_detector.py 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: 0

🧹 Nitpick comments (1)
prymer/offtarget/offtarget_detector.py (1)

643-651: Consider extracting the amplicon validation logic.

The amplicon length and overlap validation logic could be moved to a separate method for better readability.

 def _to_amplicons(...):
+    def _is_valid_amplicon(pos_hit: BwaHit, neg_hit: BwaHit) -> bool:
+        amplicon_length = neg_hit.end - pos_hit.start + 1
+        return (min_len <= amplicon_length <= max_len and 
+                (allow_overlapping_hits or neg_hit.start > pos_hit.end))
+
     ...
     for positive_hit in positive_hits_sorted:
         for negative_hit_index, negative_hit in enumerate(...):
-            amplicon_length: int = negative_hit.end - positive_hit.start + 1
-            if min_len <= amplicon_length <= max_len and (
-                allow_overlapping_hits or negative_hit.start > positive_hit.end
-            ):
+            if _is_valid_amplicon(positive_hit, negative_hit):
                 amplicons.append(...)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ccafec and 861736a.

📒 Files selected for processing (1)
  • prymer/offtarget/offtarget_detector.py (11 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 (4)

174-176: LGTM! Parameter additions are well-structured.

The new parameters min_amplicon_size and allow_overlapping_hits are added with appropriate default values.


231-237: LGTM! Clear and comprehensive docstring updates.

The documentation for new parameters is thorough and explains the interaction between min_amplicon_size and allow_overlapping_hits.


262-266: LGTM! Robust parameter validation.

The validation logic for min_amplicon_size ensures it falls within valid bounds (1 to max_amplicon_size).


381-383: LGTM! Clear documentation of overlapping hits behavior.

The docstring clearly explains how allow_overlapping_hits affects amplicon detection.

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.

2 participants