Skip to content

Let a gap in one sequence directly follow a gap in the other - #1175

Open
josemduarte wants to merge 2 commits into
biojava:masterfrom
josemduarte:jd/issue-213
Open

josemduarte wants to merge 2 commits into
biojava:masterfrom
josemduarte:jd/issue-213

Conversation

@josemduarte

Copy link
Copy Markdown
Contributor

Fixes #213.

Problem

The affine (Gotoh) recurrence only opened a deletion or an insertion from the substitution state, so an alignment could never switch straight from a gap in one sequence to a gap in the other. With an identity matrix and gaps 9/1:

AAAKKDDDF-----DD
AAA-----FFDDDFDD   score -22

instead of AAAKK--DDDFDD / AAA--FFDDDFDD (-13), and without the shared F it was forced into a forbidden mismatch (-10012).

Change

  • AlignerHelper.setScorePoint and setAffineScorePoint (used by the global, local and anchored aligners) allow deletion → insertion and insertion → deletion. The switch opens a new gap and is charged a full gap opening. The issue's example therefore scores -13, not the -4 suggested there, which charged one opening for both gaps.
  • PairwiseStatisticsAligner computes the same recurrence for AllPairsScores, so it gets the same transitions in its local and global versions, keeping its path statistics. AllPairsScoresTest and PairwiseStatisticsAlignerTest check it against the aligners.
  • A new transition is taken only when strictly better, so ties keep their previous alignment.

Testing

  • First commit adds the failing test NeedlemanWunschTest.testAdjacentGapsInBothSequences: both examples from the issue, checking the score and that no column pairs two different residues.
  • Three tests compare stored score matrices (NeedlemanWunschTest, SmithWatermanTest, SimpleProfileProfileAlignerTest). Their expected strings are regenerated: 121 cells change, all in the deletion and insertion states and all higher. No substitution values change, so the alignments and scores in those tests are the same.
  • biojava-alignment (153), biojava-structure (457) and biojava-genome (206) tests pass against this change.

🤖 Generated with Claude Code

josemduarte and others added 2 commits December 4, 2026 19:17
With an identity matrix, AAAKKDDDFDD against AAAFFDDDFDD should align
KK and FF against gaps (score -13 with gaps 9/1), but the affine
recurrence never lets a gap in one sequence directly follow a gap in the
other, so it returns a worse alignment (-22), or a forbidden mismatch
(-10012) when there is no shared residue to pivot on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#213)

The affine (Gotoh) recurrence only opened a deletion or an insertion from
the substitution state, so an alignment could not switch straight from a
gap in the query to a gap in the target. Allow both transitions, each
charged a full gap opening, in AlignerHelper (global, local and anchored
aligners) and in PairwiseStatisticsAligner, which must compute the same
recurrence. A new transition is taken only when strictly better, so ties
keep their previous alignment.

The stored score matrices in three tests change only in the deletion and
insertion states, and every changed value is higher; no substitution
values, and so no scores in those tests, change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Alignments do not allow consecutive gaps

1 participant