Repository navigation
Fix primer cut alignment and category base handling - #12
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding remains in madcats.py: fixed-offset targets outside a row can produce an invalid index, causing incorrect primer retention and possible out-of-range access.
1 open issue
What changed in this PR
This pull request fixes primer trimming so rows retain the base used for category classification, keeping category labels and Variants aligned while simplifying right-primer detection.
Changes:
- Adds shared
category_basehandling for classification and primer trimming. - Updates trimming behavior for unread targets and category bases within primers.
- Adds regression coverage and updates related documentation.
| File | Description |
|---|---|
| tests/test_remove_primers.py | Adds regression coverage for preserving the category-defining base during primer removal. |
| madcats.py | Centralizes category-base lookup and updates classification and right-primer cut handling. |
| docs/src/reference/output-formats.md | Documents category and Variants behavior for rows with differing lengths. |
| docs/src/development/changelog.md | Records the primer-trimming correction and its observed effects. |
| docs/src/commands/generate.md | Updates the documented behavior of --remove-primers. |
Review effort: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
Because the change affects core alignment and primer-trimming behavior and reports cohort-level output deltas, the stated pecan, sweetpotato, alfalfa, and blackberry regression runs should confirm it before approval.
No open issues 🎉
1 resolved since last review
Review effort: Lite
alex-sandercock
force-pushed
the
primer-cut-keeps-category-base
branch
from
November 20, 2026 23:31
e0f0cdb to
f420a76
Compare
With --remove-primers on, the cut found the target with an alignment of its own. That alignment could place the target elsewhere than the row's reading did. The row then lost the base its category came from, and its Variants showed no base or another one on the target. - category_base says which base of a row its category is read from: the fixed offset, or where the accepted gapped reading puts the target. It is None for a target that is deleted, pushed past the row, or in an unresolved end. - classify_sequence names the category from that base and right_primer_cut never removes it. Both ask the one function. - A row whose target is not read has no such base. It is cut where its primer is found. - right_primer_cut no longer aligns the row a second time to find the target. Tables with primers are byte-identical on pecan, sweetpotato, alfalfa and blackberry. Without primers, the row counts and the reads of each allele do not change. 14 pecan rows and 5 alfalfa rows now keep their right primer. 10 pecan, 17 alfalfa, 3 sweetpotato and 1 blackberry rows, all Other, are now cut where their primer is found. Rows whose category and Variants disagree on the target fall from 37 to 27 on pecan and from 22 to 18 on alfalfa. Known limit: a row can take its category from a primer base. Pecan's whole reads show that for 7 of the 14 rows; they now keep 1 to 16 primer bases. The other 7 are now cut right or one base late.
category_base returned the fixed offset without checking that the row reaches it. For a row shorter than the target's position that was an index past the row's end: classify_sequence failed on it, and right_primer_cut would have kept any primer it found. The function now gives None there, as it already did for a gapped reading that puts the target past the row. generate never writes such a row. A row is the first tag-length bases of a read at least that long, and the panel loader refuses a target outside the tag. No table changes. Raised in the pull request's review.
alex-sandercock
force-pushed
the
primer-cut-keeps-category-base
branch
from
November 20, 2026 23:31
f420a76 to
f034c50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes
With
--remove-primers on, the cut found the target with an alignment of its own. That alignment could place the target elsewhere than the row's reading did. The row then lost the base its category came from, and itsVariantsshowed no base or another one on the target.category_basesays which base of a row its category is read from.classify_sequencenames the category from it, andright_primer_cutnever removes it.right_primer_cutno longer aligns the row a second time to find the target.Effect
Tables with primers are byte-identical on pecan, sweetpotato, alfalfa and blackberry. Without primers:
Otherrows now cut where the primer is foundVariantsdisagree, beforeVariantsdisagree, afterKnown limits
Variants. They are read again as printed, and this change does not touch them.