Skip to content

Fix DistanceCalculator identity model with skip_letters - #5365

Closed
barlowa124 wants to merge 2 commits into
biopython:masterfrom
barlowa124:distance-skip-letters-5332
Closed

barlowa124 wants to merge 2 commits into
biopython:masterfrom
barlowa124:distance-skip-letters-5332

Conversation

@barlowa124

@barlowa124 barlowa124 commented Oct 8, 2026 •

Copy link
Copy Markdown
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file. I have run pre-commit
    locally. I understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

The identity branch of DistanceCalculator._pairwise skipped
positions named in skip_letters when computing the score but used
len(seq1) as max_score. Skipped columns inflated the distance, so
two identical sequences containing gap columns returned 1/3 instead of
0, and the identity branch disagreed with the scoring-matrix branch on
the same alignment.

max_score now counts only the aligned positions the score loop does
not skip, matching the scoring-matrix branch and keeping the
documented 0-to-1 range. The default identity path with empty
skip_letters is unchanged.

A new test in test_TreeConstruction.py covers identical sequences
with gap columns and gap-column invariance.
python -m unittest test_TreeConstruction test_Consensus passes:
32 tests on Python 3.13.

barlowa124 and others added 2 commits November 12, 2026 14:55
DistanceCalculator._pairwise scored only non-skipped positions but used
len(seq1) as the maximum, so gap columns inflated the reported distance -
identical sequences with gaps returned > 0 and the identity branch
disagreed with the scoring-matrix branch on the same data.

Count only non-skipped aligned positions in max_score, matching the set
the score is computed over. The default identity path (empty
skip_letters) is unchanged.

Closes biopython#5332.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@barlowa124
barlowa124 force-pushed the distance-skip-letters-5332 branch from 69921cb to 7eb1b00 Compare November 12, 2026 19:56
@peterjc

peterjc commented Nov 12, 2026

Copy link
Copy Markdown
Member

Not following PR template.

@peterjc peterjc closed this Nov 12, 2026
@peterjc

peterjc commented Nov 12, 2026

Copy link
Copy Markdown
Member

Update: It was following the old three-point checklist, but was edited down??? Anyway, could you revise with the new four-point checklist with an AI usage declaration pleas.

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