Skip to content

Fix has_overlap/get_overlap for flipped (reverse-strand) coordinates (2.0.6) - #42

Merged
YalanBi merged 2 commits into
masterfrom
fix/has-overlap-flipped-coords
Aug 4, 2026
Merged

Fix has_overlap/get_overlap for flipped (reverse-strand) coordinates (2.0.6)#42
YalanBi merged 2 commits into
masterfrom
fix/has-overlap-flipped-coords

Conversation

@YalanBi

@YalanBi YalanBi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #23: add_domains_to_table silently missed overlapping domains on reverse-strand genes with no warning.

Root cause (as diagnosed in detail by the reporter): has_overlap/get_overlap assumed start <= end, but genomic_position produces (end, start) for reverse-strand features, since transcript-relative positions map in the opposite direction to genomic coordinates on the minus strand. has_overlap((118, 90), (100, 200)) wrongly returned False for a real partial overlap.

Fixed at the primitive level (has_overlap/get_overlap in _utils.py) rather than at genomic_position's output, since these two functions are called from ~15 places across the codebase and normalizing there is the safest, most general fix -- it's a no-op for already-correctly-ordered pairs, and defensively hardens every other caller against the same class of bug too.

Found and fixed a real regression in my own first attempt: some callers (e.g. IntervalArray.overlap in _transcriptome_io.py) pass intervaltree.Interval objects, which behave like 3-element structures (begin, end, data_dict). The original code only ever indexed [0]/[1]; my first fix called min()/max() over the whole object, which crashed on the data dict. Caught by running the full test suite (not just the new test) before pushing -- fixed by indexing explicitly instead.

Added tests/utils_test.py (new file, following the file-per-feature-area convention documented in tests/README.md) with the reporter's exact reproducer cases. Verified it reproduces the original wrong result against the pre-fix code.

Bumps version to 2.0.6.

Test plan

  • Full pytest suite passes (18 passed), including the new regression test
  • Verified the new test reproduces the original wrong result against the pre-fix code
  • Verified via a fresh independent clone of the pushed branch
  • flake8/black clean
  • python -m build + twine check dist/* pass at 2.0.6
  • CI green across the full matrix (tests, lint, CodeQL, docs-build)

YalanBi added 2 commits August 4, 2026 21:46
Reverse-strand features sometimes pass genomic coordinates as
(end, start) rather than (start, end) -- has_overlap silently
returned False for partial overlaps in that case, causing
add_domains_to_table to miss overlapping domains on the reverse
strand with no warning. Normalize via explicit min/max on just the
first two elements (not the whole object, since callers pass
intervaltree.Interval objects with extra data too). Closes #23.
@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 959ee12 into master Aug 4, 2026
19 checks passed
@YalanBi
YalanBi deleted the fix/has-overlap-flipped-coords branch August 4, 2026 20:02
@kbseah kbseah mentioned this pull request Aug 5, 2026
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_domains_to_table silently fails to add some overlapping domains with options overlap=True and source="hmmer"

1 participant