Skip to content

Conversation

@ryanbarouki
Copy link

@ryanbarouki ryanbarouki commented Dec 15, 2025

This PR fixes a bug where custom gap penalties (gap_open, gap_extend, terminal_gap_extend) provided via the Python wrapper were effectively ignored by the core C implementation.

The Issues

  1. The underlying C function aln_param_init (in lib/src/aln_param.c) expects positive values to override the default penalties. It specifically checks if (gpo >= 0.0) before applying the user-provided value. However, the current Python wrapper (python-kalign/kalign/__init__.py) enforces that these parameters must be negative or zero, raising a ValueError for positive inputs.

  2. There appears to be a typo on line 85 of lib/src/aln_param.c where it checks if(gpe >= 0.0) and then assigns tgpe. I suspect this is a copy-paste typo and should check if(tgpe >= 0.0).

As a result:

Issue 1:

  1. Users are forced to pass negative values (e.g., -10.0) to satisfy the Python validation.
  2. These negative values are passed to the C core.
  3. The C core sees a negative value, fails the >= 0.0 check, and ignores the input, silently falling back to the default penalties (e.g., 55).

Issue 2:

  1. One issue would be tgpe would only be set if gpe was set to be >=0 which seems undesirable.

The Fix

This change updates the parameter validation in python-kalign/kalign/__init__.py to enforce positive values for custom penalties. This aligns the Python API with the C core's expectations, ensuring that user-specified penalties are correctly passed and applied during alignment.

The existing default behavior (passing None, which converts to -1.0 internally) remains unchanged and continues to correctly trigger the C core's default parameter logic.

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.

1 participant