Skip to content

Fix reverse position calculation in Sequence.py#111

Merged
ssnn-airr merged 3 commits intoimmcantation:masterfrom
vladimirvig:rev_primer_fix
Feb 16, 2026
Merged

Fix reverse position calculation in Sequence.py#111
ssnn-airr merged 3 commits intoimmcantation:masterfrom
vladimirvig:rev_primer_fix

Conversation

@vladimirvig
Copy link
Copy Markdown
Contributor

The bugfix corrects an error in the calculation of the location of the best alignment of the reverse primer.
Whereas the original code calculated the offset by subtracting the alignment-end coordinate, the offset should be either (a) the last position in the sequence record considered (given the user-chosen --maxlen value) of (b) zero, if the considered length covers the entire sequence record (in which case the start of the matched position comes directly from the unmodified alignment coordinates). The actual start and end of the site are then calculated by adding the offset to the alignment coordinates.

This situation only comes up for reverse primers, where the regex failed due to imperfect matching.

@ssnn-airr ssnn-airr requested a review from ggabernet February 12, 2026 17:03
Copy link
Copy Markdown
Contributor

@ssnn-airr ssnn-airr left a comment

Choose a reason for hiding this comment

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

LGT

@vladimirvig
Copy link
Copy Markdown
Contributor Author

@ssnn-airr Thanks for putting the tests together! Cheers!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the calculation of reverse primer alignment positions when using the maxlen parameter. The original code incorrectly computed the position offset by subtracting the alignment end coordinate, when it should instead calculate the offset based on whether a partial sequence was scanned (offset = rec_len - max_len) or the entire sequence was scanned (offset = 0).

Changes:

  • Fixed the reverse primer position offset calculation in the local alignment code path
  • Added a comprehensive test case that validates the fix for reverse primer alignment with maxlen parameter

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
presto/Sequence.py Corrects the rev_pos calculation for reverse primers in localAlignment() from using alignment coordinates to using sequence/maxlen offset
tests/test_MaskPrimers.py Adds test case test_issue110_revprimer_cut() that validates reverse primer alignment and cutting with maxlen parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@immcantation immcantation deleted a comment from Copilot AI Feb 13, 2026
Copy link
Copy Markdown
Contributor

@ggabernet ggabernet left a comment

Choose a reason for hiding this comment

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

Looks good to me too, just updated the changelog as well.

@ssnn-airr ssnn-airr merged commit f705b10 into immcantation:master Feb 16, 2026
2 checks passed
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.

[BUG] MaskPrimers.py trims gapped match correctly only in the forward orientation despite correctly passing in both

4 participants