Fix python bindings to correctly pass gap penalties to C code #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
The underlying C function
aln_param_init(inlib/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 aValueErrorfor positive inputs.There appears to be a typo on line 85 of
lib/src/aln_param.cwhere it checksif(gpe >= 0.0)and then assignstgpe. I suspect this is a copy-paste typo and should checkif(tgpe >= 0.0).As a result:
Issue 1:
-10.0) to satisfy the Python validation.>= 0.0check, and ignores the input, silently falling back to the default penalties (e.g.,55).Issue 2:
tgpewould only be set ifgpewas set to be>=0which seems undesirable.The Fix
This change updates the parameter validation in
python-kalign/kalign/__init__.pyto 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.0internally) remains unchanged and continues to correctly trigger the C core's default parameter logic.