Fix reverse position calculation in Sequence.py#111
Fix reverse position calculation in Sequence.py#111ssnn-airr merged 3 commits intoimmcantation:masterfrom
Conversation
|
@ssnn-airr Thanks for putting the tests together! Cheers! |
There was a problem hiding this comment.
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
maxlenparameter
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.
ggabernet
left a comment
There was a problem hiding this comment.
Looks good to me too, just updated the changelog as well.
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
--maxlenvalue) 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.