Skip to content

Fix primer cut alignment and category base handling - #12

Merged
alex-sandercock merged 2 commits into
developmentfrom
primer-cut-keeps-category-base
Nov 20, 2026
Merged

alex-sandercock merged 2 commits into
developmentfrom
primer-cut-keeps-category-base

Conversation

@alex-sandercock

Copy link
Copy Markdown
Contributor

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 its Variants showed no base or another one on the target.

  • One function: category_base says which base of a row its category is read from. classify_sequence names the category from it, and right_primer_cut never removes it.
  • Unread target: a row whose target is not read has no such base. It is cut where its primer is found.
  • Simpler cut: right_primer_cut no 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:

Pecan Sweetpotato Alfalfa Blackberry
Rows that now keep their right primer 14 0 5 0
Other rows now cut where the primer is found 10 3 17 1
Rows whose category and Variants disagree, before 37 16 22 1
Rows whose category and Variants disagree, after 27 16 18 1
  • No row merges or splits.
  • No read moves between alleles.

Known limits

  • A row can take its category from a primer base. Pecan's whole reads show that for 7 of the 14 rows. Their old cut was right or one base off, and they now keep 1 to 16 primer bases. The other 7 are now cut right or one base late.
  • Rows of another length than the Ref row. Up to 27 rows per panel still name one base in their category and show another in Variants. They are read again as printed, and this change does not touch them.

@alex-sandercock alex-sandercock self-assigned this Nov 20, 2026
Copilot AI lite review requested due to automatic review settings November 20, 2026 21:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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_base handling 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

Comment thread madcats.py Resolved
Copilot AI lite review requested due to automatic review settings November 20, 2026 23:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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
alex-sandercock force-pushed the primer-cut-keeps-category-base branch from e0f0cdb to f420a76 Compare November 20, 2026 23:31
Base automatically changed from read-continuation to development November 20, 2026 23:31
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
alex-sandercock force-pushed the primer-cut-keeps-category-base branch from f420a76 to f034c50 Compare November 20, 2026 23:31
@alex-sandercock
alex-sandercock merged commit 029ced7 into development Nov 20, 2026
16 checks passed
@alex-sandercock
alex-sandercock deleted the primer-cut-keeps-category-base branch November 20, 2026 23:31
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.

2 participants