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

Expose some bwa indel parameters through the off-target checker. #95

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

Conversation

tfenne
Copy link
Member

@tfenne tfenne commented Nov 20, 2024

I did some playing with ntthal, and it appears to that the when calculating Tms of duplexes, an indel closer than 3bp from the end of the primer causes it to see the rest of the primer as non-annealed. In some cases it can be more (depending on sequence, it may not see the remainder as annealed after an indel 4-5bp in), but it seems consistent that it needs at least 3bp past the indel to anneal bases. Hence setting min_indel_to_end_distance: int = 3.

@tfenne tfenne requested a review from clintval November 20, 2024 17:37
@tfenne tfenne requested a review from nh13 as a code owner November 20, 2024 17:37
@tfenne
Copy link
Member Author

tfenne commented Nov 20, 2024

@ ameynert for your consideration

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request introduces updates to the BwaAlnInteractive and OffTargetDetector classes in the prymer/offtarget module. In BwaAlnInteractive, a new parameter, min_indel_to_end_distance, is added to the __init__ method, allowing users to specify a minimum distance from the ends of the query sequence for indel placements, with a default value of 3. The BWA command execution command is modified to include this parameter, and the constructor's docstring is updated accordingly.

In the OffTargetDetector class, the constructor now includes two new parameters: max_gap_opens and max_gap_extends, which affect alignment behavior during off-target detection. The default value for max_amplicon_size is set to 1000. The initialization of BwaAlnInteractive within this class is updated to pass the new parameters, and the constructor's docstring is also modified to reflect these changes.

Possibly related PRs

Suggested reviewers

  • nh13
  • msto

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

@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: 2

🧹 Outside diff range and nitpick comments (1)
prymer/offtarget/offtarget_detector.py (1)

206-211: Enhance gap parameter documentation

Add context about indel impact on primer annealing and define "long gaps".

             max_gap_opens: the maximum number of gaps (insertions or deletions) allowable in an
-                alignment of a oligo to the reference
+                alignment of a oligo to the reference. Indels within 3bp of primer ends
+                significantly affect primer annealing.
             max_gap_extends: the maximum number of gap extensions allowed; extending a gap
                 beyond a single base costs 1 gap extension.  Can be set to -1 to allow
-                unlimited extensions up to max diffs (aka max mismatches), while disallowing
-                "long gaps".
+                unlimited extensions up to max diffs (aka max mismatches). Long gaps
+                (>1bp) near primer ends may prevent proper annealing.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ebc72f7 and a1ef886.

📒 Files selected for processing (2)
  • prymer/offtarget/bwa.py (3 hunks)
  • prymer/offtarget/offtarget_detector.py (3 hunks)
🔇 Additional comments (2)
prymer/offtarget/bwa.py (2)

235-235: LGTM: Parameter addition and documentation are clear.

Parameter name and default value align with experimental findings about indel effects on primer annealing.

Also applies to: 252-253


294-295: Verify BWA flag usage.

Confirm -i is the correct BWA flag for min_indel_to_end_distance.

Comment on lines +162 to +164
max_gap_opens: int = 0,
max_gap_extends: int = -1,
max_amplicon_size: int = 1000,
Copy link

@coderabbitai coderabbitai bot Nov 20, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Default max_gap_opens=0 is too restrictive

PR indicates indels affect primer annealing. Consider default of 1 to allow single indels.

-        max_gap_opens: int = 0,
+        max_gap_opens: int = 1,
📝 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
max_gap_opens: int = 0,
max_gap_extends: int = -1,
max_amplicon_size: int = 1000,
max_gap_opens: int = 1,
max_gap_extends: int = -1,
max_amplicon_size: int = 1000,

Copy link
Member

Choose a reason for hiding this comment

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

@tfenne any reason why not? Or should we keep this at 0 for backwards compatibility?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment on lines +231 to +232
max_gap_opens=max_gap_opens,
max_gap_extensions=max_gap_extends,
Copy link

@coderabbitai coderabbitai bot Nov 20, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix parameter name inconsistency

Parameter names differ between constructor and BWA initialization.

-            max_gap_extensions=max_gap_extends,
+            max_gap_extends=max_gap_extends,
📝 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
max_gap_opens=max_gap_opens,
max_gap_extensions=max_gap_extends,
max_gap_opens=max_gap_opens,
max_gap_extends=max_gap_extends,

Copy link
Member

Choose a reason for hiding this comment

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

@tfenne I do think we should normalize the parameter names across the two signatures. "max gap extensions" appears more commonly in the repo:

MAX_GAP_EXTENSIONS: int = -1
"""The default maximum number of gap extensions allowed in the full query sequence"""

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.67%. Comparing base (ebc72f7) to head (1f1ca9e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #95   +/-   ##
=======================================
  Coverage   96.67%   96.67%           
=======================================
  Files          26       26           
  Lines        1712     1712           
  Branches      333      333           
=======================================
  Hits         1655     1655           
  Misses         31       31           
  Partials       26       26           

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


🚨 Try these New Features:

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)
tests/offtarget/test_bwa.py (1)

Line range hint 218-240: Add test cases for indel distance behavior

Current tests don't verify indel distance constraints.

Add test cases:

@pytest.mark.parametrize(
    "indel_distance, should_map",
    [
        (2, False),  # Too close to end
        (3, True),   # Minimum allowed distance
        (4, True),   # Above minimum
    ]
)
def test_indel_distance_constraints(ref_fasta: Path, indel_distance: int, should_map: bool) -> None:
    bases = _PERFECT_BASES[:indel_distance] + "TTT" + _PERFECT_BASES[indel_distance:]
    with BwaAlnInteractive(ref=ref_fasta, max_hits=1, min_indel_to_end_distance=3) as bwa:
        result = bwa.map_one(query=bases, id="test")
        assert (result.hit_count > 0) == should_map
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a1ef886 and 1f1ca9e.

📒 Files selected for processing (1)
  • tests/offtarget/test_bwa.py (1 hunks)

@@ -222,6 +222,7 @@ def test_map_single_hit(
max_hits=1,
max_mismatches=5,
max_gap_opens=1,
min_indel_to_end_distance=5,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Value mismatch with PR objective

PR states minimum distance should be 3, but test uses 5.

-        min_indel_to_end_distance=5,
+        min_indel_to_end_distance=3,
📝 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
min_indel_to_end_distance=5,
min_indel_to_end_distance=3,

Copy link

@ameynert ameynert left a comment

Choose a reason for hiding this comment

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

Confirming that this is working for me in a project that uses the OffTargetDetector.

Comment on lines +231 to +232
max_gap_opens=max_gap_opens,
max_gap_extensions=max_gap_extends,
Copy link
Member

Choose a reason for hiding this comment

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

@tfenne I do think we should normalize the parameter names across the two signatures. "max gap extensions" appears more commonly in the repo:

MAX_GAP_EXTENSIONS: int = -1
"""The default maximum number of gap extensions allowed in the full query sequence"""

Comment on lines +162 to +164
max_gap_opens: int = 0,
max_gap_extends: int = -1,
max_amplicon_size: int = 1000,
Copy link
Member

Choose a reason for hiding this comment

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

@tfenne any reason why not? Or should we keep this at 0 for backwards compatibility?

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