Skip to content

Nearest ranges strand direction, again - #173

Merged
marco-mariotti merged 3 commits into
masterfrom
nearest-ranges-strand-direction
Aug 14, 2026
Merged

Nearest ranges strand direction, again#173
marco-mariotti merged 3 commits into
masterfrom
nearest-ranges-strand-direction

Conversation

@marco-mariotti

Copy link
Copy Markdown
Member

I had PRed into a branch rather than master, by mistake

marco-mariotti and others added 3 commits August 10, 2026 15:41
Overlapping intervals are all at distance 0, so with the default
exclude_overlaps=False "every tied interval" means "every interval of
other that self overlaps". One interval of self covered by 500 intervals
of other produces 500 rows, every one of them equally the nearest. On
100 million hg38-like intervals against themselves that is 1.1 billion
output rows against 7.7 million for one per query -- 144x, and the
difference between fitting in memory and not.

`ties="first"` reports one interval per distance instead, so each
interval of self appears at most once. Which one is unspecified, as it
is for bedtools `closest -t first`, GenomicRanges `select="arbitrary"`
and BEDOPS `--closest`; the same input gives the same answer, and
nothing is sorted to decide it because the sort would cost more than the
option saves. The default, "all", is unchanged.

The tied rows are never built. Filtering afterwards would have cost the
same memory as "all" and more time, so the saving comes from the kernel:
the overlap sweep stops at the first hit per interval of self, each
directional sweep emits one row per distinct distance, and the merge
keeps one row per distance bucket. That is `ruranges_core::nearest`, so
the floor on ruranges rises to 0.1.8.

`k` still counts distinct distances, so `ties="first", k=2` gives two
rows rather than being rejected. An unknown value raises ValueError
naming the options, like `direction` and `multiple`, rather than
reaching the kernel and aborting the interpreter with a Rust panic.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@marco-mariotti
marco-mariotti merged commit 976ba2b into master Aug 14, 2026
4 checks passed
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