Skip to content

Fix protein_scale for window 1 and even window sizes - #5363

Open
barlowa124 wants to merge 2 commits into
biopython:masterfrom
barlowa124:protein-scale-window-5340
Open

barlowa124 wants to merge 2 commits into
biopython:masterfrom
barlowa124:protein-scale-window-5340

Conversation

@barlowa124

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, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Closes #5340

Two window bugs in ProteinAnalysis.protein_scale are fixed.

With window=1, _weight_list divided by window - 1 and raised ZeroDivisionError. A one-residue window now returns the scale value for each residue.

With an even window, subsequence[window // 2] was counted twice (in the innermost mirrored pair and again as the middle value), so a reversed sequence produced a different profile. Even windows now skip the middle term and normalize by the two-sided weight sum, making the profile direction-invariant.

A window of 1 crashed on a division by zero in _weight_list, and an
even window double-counted subsequence[window//2] (once as the back of
the innermost mirrored pair, once as the 'middle'), making profiles
depend on sequence direction. Even windows now skip the middle term
and normalize by the sum of the two-sided weights.

Fixes biopython#5340.

I agree to dual license my contribution under both the Biopython
License Agreement and the 3-Clause BSD License.
@barlowa124
barlowa124 force-pushed the protein-scale-window-5340 branch from 5fe8afa to 5ab4c90 Compare November 12, 2026 19:56
@peterjc

peterjc commented Nov 12, 2026

Copy link
Copy Markdown
Member

Since you're updating (not sure what changed), could you fill in the revised PR template with an AI declaration please?

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.

ProteinAnalysis.protein_scale crashes for window 1 and silently biases even windows

2 participants