Skip to content

Fix ORF prediction crash on soft-masked (lowercase) genome FASTA (2.0.4) - #40

Merged
YalanBi merged 4 commits into
masterfrom
fix/lowercase-fasta-orf
Aug 4, 2026
Merged

Fix ORF prediction crash on soft-masked (lowercase) genome FASTA (2.0.4)#40
YalanBi merged 4 commits into
masterfrom
fix/lowercase-fasta-orf

Conversation

@YalanBi

@YalanBi YalanBi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #26: add_orf_prediction/Gene.add_orfs() crashed with an uncaught KeyError when the genome FASTA has soft-masked (lowercase) sequence.

Root cause: Gene.get_sequence() doesn't normalize case, so lowercase bases flowed into kozak_score()'s PWM lookup, which is indexed only by uppercase ACGTN. Also fixes a silent sibling bug: start/stop codon matching uses a case-sensitive regex against "ATG"/"TAA"/etc., so ORFs entirely within soft-masked regions were previously missed with no warning at all, not just crashed.

Fixed at the single point tr_seq is obtained inside add_orfs(), not in get_sequence() itself -- that function is also used by the public write_fasta export, where preserving original case is meaningful to users (e.g. visualizing repeat-masked regions). Checked the other two get_sequence(protein=True) callers in domains.py; they rely on the same upstream add_orfs() fix and don't need separate changes.

Also includes a short tests/README.md documenting the two test styles in this repo (self-contained fixtures vs. the pickle-based pipeline chain), prompted by real debugging time lost to stale cross-run pickle state while working on this fix.

Bumps version to 2.0.4.

Test plan

  • Full pytest suite passes (15 passed), including the new regression test
  • Verified the new test reproduces the original crash against the pre-fix code
  • Verified the pushed branch actually contained the fix (caught and corrected a commit that only included the test, not the source change)
  • flake8/black clean
  • python -m build + twine check dist/* pass at 2.0.4
  • CI green across the full matrix (tests, lint, CodeQL, docs-build)

YalanBi added 4 commits August 4, 2026 19:12
Genome FASTA files commonly soft-mask repeats with lowercase bases.
Gene.get_sequence() doesn't normalize case, so lowercase bases flowed
into kozak_score's PWM lookup (indexed only by uppercase ACGTN),
crashing with an uncaught KeyError (#26). Also fixes a silent sibling
bug: start/stop codon regex matching ("ATG" vs "atg") would silently
miss ORFs entirely in soft-masked regions rather than crash.

Fixed at the single point tr_seq is obtained in add_orfs(), not in
get_sequence() itself, since that's also used by the public
write_fasta export where case is meaningful to preserve.
Covers the lowercase-FASTA ORF prediction fix (#26).
Two styles coexist -- self-contained fixtures vs. the pickle-based
pipeline chain -- prompted by real debugging time lost to stale
cross-run pickle state earlier today.
b06579c's commit message described this fix but only staged the test
files -- the source change itself was never committed.
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@YalanBi YalanBi self-assigned this Aug 4, 2026
@YalanBi YalanBi added the bug Something isn't working label Aug 4, 2026
@YalanBi
YalanBi merged commit b36ba1e into master Aug 4, 2026
19 checks passed
@YalanBi
YalanBi deleted the fix/lowercase-fasta-orf branch August 4, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add_orf_prediction fails with KeyError when Fasta file has lowercase characters

1 participant