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: Check against HN tag instead of is_unmapped property #69

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

Conversation

msto
Copy link
Collaborator

@msto msto commented Oct 8, 2024

Closes #68

bwa aln produces inconsistent behavior when recording the mapped status of multiply mapping reads. In most cases, such reads are flagged as mapped with a mapq of 0. However, we have discovered some cases where these reads are flagged as unmapped.

prymer currently relies on the unmapped flag to identify reads with a hit count of zero. This has been yielding errors when attempting to parse reads in the latter category. This information can instead be obtained directly from the HN tag.

@msto msto requested review from nh13 and tfenne as code owners October 8, 2024 17:04
prymer/offtarget/bwa.py Outdated Show resolved Hide resolved
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.

I think there needs to be a further change here, or at least a clear explanation/justification of why not. I think when the record is marked as unmapped, what that really means is that bwa believes the primary alignment to be erroneous - and as such I think to_hits() should ignore the primary alignment and only decode the secondary alignments.

prymer/offtarget/bwa.py Outdated Show resolved Hide resolved
Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in the pull request primarily focus on the BwaResult and BwaAlnInteractive classes within the prymer/offtarget/bwa.py file. Documentation for the BwaResult class has been reformatted for clarity. The map_one method in BwaAlnInteractive remains functionally unchanged, while the map_all method retains its logic for processing multiple queries. The _to_result method has been revised to handle unmapped reads more effectively, initializing num_hits to zero when the "HN" tag is absent and determining hits based on actual extracted data. Additionally, the to_hits method has been updated to filter out hits that extend beyond the end of a contig, enhancing the accuracy of the results. The workflow configuration in .github/workflows/tests.yml has also been updated to include testing for Python versions 3.11 and 3.12, with minor formatting adjustments.

Assessment against linked issues

Objective Addressed Explanation
Handling unmapped results in BwaAlnInteractive._to_result (#68)

Possibly related PRs

Suggested reviewers

  • nh13

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.

@msto msto requested a review from tfenne October 15, 2024 20:49
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)
prymer/offtarget/bwa.py (1)

159-162: Remove unnecessary whitespace in docstring blank line

The blank line at line 161 contains whitespace. Please remove the extra whitespace to adhere to PEP 8 style guidelines.

🧰 Tools
🪛 Ruff

161-161: Blank line contains whitespace

Remove whitespace from blank line

(W293)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 93ea6e7 and dab5ba8.

📒 Files selected for processing (1)
  • prymer/offtarget/bwa.py (4 hunks)
🧰 Additional context used
🪛 Ruff
prymer/offtarget/bwa.py

161-161: Blank line contains whitespace

Remove whitespace from blank line

(W293)

🔇 Additional comments (2)
prymer/offtarget/bwa.py (2)

363-373: Logic for adjusting hit counts is correct

The updated logic in lines 363-373 appropriately adjusts num_hits and hits, ensuring that the BwaResult accurately reflects the total number of hits even when the number of hits exceeds max_hits.


418-422: Correctly filter out hits that extend beyond contig boundaries

The added filtering in lines 418-422 effectively removes artifacts from bwa aln's alignment process by excluding hits that extend beyond the end of a contig, enhancing the accuracy of the results.

prymer/offtarget/bwa.py Outdated Show resolved Hide resolved
@tfenne tfenne assigned msto and unassigned tfenne Oct 16, 2024
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)
prymer/offtarget/bwa.py (1)

161-161: Remove whitespace on blank line

There's trailing whitespace on the blank line at line 161. This can lead to style inconsistencies.

Apply this diff to remove the whitespace:

-        
+
🧰 Tools
🪛 Ruff

161-161: Blank line contains whitespace

Remove whitespace from blank line

(W293)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dab5ba8 and 2eae4a9.

📒 Files selected for processing (2)
  • .github/workflows/tests.yml (0 hunks)
  • prymer/offtarget/bwa.py (4 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/tests.yml
🧰 Additional context used
🪛 Ruff
prymer/offtarget/bwa.py

161-161: Blank line contains whitespace

Remove whitespace from blank line

(W293)

🔇 Additional comments (2)
prymer/offtarget/bwa.py (2)

363-376: Logic correctly utilizes HN tag for hit count

The updated logic appropriately uses the HN tag to determine the number of hits, aligning with the PR objectives. It correctly handles cases where the number of hits is zero, between zero and self.max_hits, and greater than or equal to self.max_hits.


421-424: Properly filters out hits spanning contig boundaries

The addition ensures that hits extending beyond the end of a contig are removed, addressing artifacts from bwa aln's alignment process. This enhances the accuracy of the returned hits.

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.

Handling unmapped results in BwaAlnInteractive._to_result
2 participants