Skip to content

Methods and checksMethods

How every result is reached and what it was checked against, app by app.

Methods and checks pages

Overlap, gap and relation of two genomic intervals, version 1.0.2

genome-interval-overlap@1.0.2: this version's equations with their symbols, each constant's value, their sources and whether each was read, a worked example where the record holds one, its level and what it was checked against, the number of cases, and what was not checked. This version's record is not rewritten; a correction is added under Changes.

What this page can and cannot show

Level: Checked against a reference; bedtools 2.31.1; standard half-open definitions; endToStartDistance our convention. Reference kind: an outside program, bedtools, 2.31.1; our own exact-arithmetic script and a hand-worked case.

Not fully recorded, and not independently reviewed. Items marked "Not recorded" are missing from this project's records for the version named. Apart from any worked example shown, the cases and their values are not printed, so a reader cannot re-run these checks. No independent scientist has yet reviewed these methods or checks.

Every version of this method · Every method · What the levels mean

Version 1.0.2

Level: Checked against a reference; bedtools 2.31.1; standard half-open definitions; endToStartDistance our convention. Reference kind: an outside program, bedtools, 2.31.1; our own exact-arithmetic script and a hand-worked case. genome-interval-overlap@1.0.2

Built, not hosted. Generated from a snapshot of the library's records taken on 2026-11-25, as committed on 2026-11-25. A later snapshot replaces this one, so these records and this page can change.

Verification statement: Overlap and gap of two half-open intervals by their standard definitions, on the coordinate systems of SAMv1 §1.2 (hts-specs 510c107b, re-read at source 14 November 2026); endToStartDistance is Drybench's convention, matching bedtools closest -d. Compared with bedtools 2.31.1, and with a second implementation in Python by a separate agent of the same model family (131 cases, 23 of its own at the edges). Coordinates above 2^53 − 1 refused. Exact integer arithmetic.

On half-open intervals: overlap = max(0, min(e) − max(s)); gapBases = max(0, max(s) − min(e)); endToStartDistance = 0 if overlapping else gapBases + 1; the relation; a strand rule reported, never applied to the geometry.

  • How results are reported: none: integers, exact
  • Uncertainty: Exact integer arithmetic.
  • Reference, as its record states it: bedtools 2.31.1 intersect and closest -d
  • Level confirmed by this project's ruling of 14 November 2026

What this page can and cannot show

What was checked

246 cases in 4 files, linked by this exact version.

Run through the tool at build against an outside program, bedtools, 2.31.1; our own exact-arithmetic script and a hand-worked case: 211 agree within the tolerance the file states, 35 refuse as the case expects, 0 differ, 0 were not run.

  • File 1, 23 cases

    • Where the expected values came from: an outside program, bedtools 2.31.1
    • Recorded on: 2026-11-10
    • Reference: bedtools, 2.31.1; licence MIT
    • Tolerance as the file states it: exact: bases, distances, relations, withheld rules, statuses and codes
  • File 2, 45 cases

    • Where the expected values came from: our own exact-arithmetic script and a hand-worked case
    • Recorded on: 2026-11-14
    • Reference: second implementation (Python 3.13, standard library), 2026-11-14; licence PSF-2.0
    • Tolerance as the file states it: exact: bases, distances, relations, withheld rules, statuses and codes
  • File 3, 47 cases

    • Where the expected values came from: our own exact-arithmetic script and a hand-worked case
    • Recorded on: 2026-11-14
    • Reference: second implementation (Python 3.13, standard library), 2026-11-14; licence PSF-2.0
    • Tolerance as the file states it: exact: bases, distances, relations, withheld rules, statuses and codes
  • File 4, 131 cases

    • Where the expected values came from: our own exact-arithmetic script and a hand-worked case
    • Recorded on: 2026-11-14
    • Reference: second implementation (Python 3.13), 2026-11-14; licence BSD-3-Clause
    • Tolerance as the file states it: exact: bases, distances, relations, withheld rules, statuses and codes

Apart from the worked example, the cases and their values are not printed here. This shows agreement with this project's recorded cases. It does not show that a method suits your work, and it is not a qualification.

What was not checked

Sets of intervals (merge, subtract); upstream and downstream signs (bedtools -D); bedtools versions other than 2.31.1.

Definition or model

A closed form: the result follows from the inputs by the equations alone.

Equations

Equation 1

overlap = max(0, min(e_a, e_b) − max(s_a, s_b))
gapBases = max(0, max(s_a, s_b) − min(e_a, e_b)): the standard definitions of the shared and intervening lengths of two half-open intervals
SAMv1 is cited for the 0-based half-open coordinate system only, and holds no overlap or gap formula
Symbol Meaning and unit
s, e half-open start and end of each interval
overlap, gapBases bases shared by the intervals, and bases between them, bp

Source: Sequence Alignment/Map Format Specification v1.6, samtools/hts-specs, SAMv1.tex, section 1.2 Terminologies and Concepts: the 1-based and 0-based coordinate systems (the 3rd to 7th bases are [3, 7] 1-based and [2, 7) 0-based), hts-specs master at commit 510c107b; read in full on 2026-11-11 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 5f1326a2298b. Free to read (free to read; no licence stated in the file or repository, so cited only), checked 2026-11-11. No erratum found (searched the file at commit 510c107b (the repository holds the specification's corrections as commits)), 2026-11-11.

Equation 2

endToStartDistance = 0 if overlap > 0, else gapBases + 1: Drybench's convention, matching bedtools closest -d 2.31.1 as measured
relation is a's relation to b, decided in this order, names and precedence the record's own: equal (same start and end), contains (a holds b, ends may be shared), within (b holds a, ends may be shared), overlap (overlap > 0 and neither holds the other), book-ended (a's end is b's start or b's end is a's start, half-open), separate (otherwise)
checks per interval, in this order: a coordinate above 2^53 − 1 as given, before any conversion (COORDINATE_ABOVE_RANGE), then in 1-based closed a start below 1 or an end before the start, and in 0-based half-open a start below 0 or an end before the start (the kit's OUT_OF_RANGE: a zero-length interval cannot be written 1-based closed, so [s, s − 1] is declined as invalid input (OUT_OF_RANGE), not read as a site
ask genome_coordinate_convert for sites), then a half-open start equal to its end (ZERO_LENGTH_USE_SITE)
Symbol Meaning and unit
endToStartDistance distance from the earlier interval's end to the later one's start, 0 when they overlap, bp

Ruling of this project: 10 November 2026, section "2. Reasoning (rulings)". Not yet published; its effect is stated on this page. A choice this project made, not a value from the literature.

Constants

Constants: none used.

Worked example

Worked example: one case of genome-interval-overlap@1.0.2, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • a.contig = toy
  • a.system = 0-based-half-open
  • a.start = 10
  • a.end = 20
  • a.strand = +
  • b.contig = toy
  • b.system = 0-based-half-open
  • b.start = 21
  • b.end = 30
  • b.strand = +

Steps

  1. gap = 1 bp, from a.end, b.start; by equation 1; gives result.gapBases.
  2. d = 2 bp, from gap; by equation 2; gives result.endToStartDistance.

The working, as the case writes it:

a = [10,20), b = [21,30) half-open
overlap = max(0, 20 - 21) = 0
gap = max(0, 21 - 20) = 1
relation separate

Answer

  • result.gapBases = 1 bp
  • result.endToStartDistance = 2 bp

Where these values came from: an outside program, bedtools 2.31.1; overlapBases: bedtools 2.31.1 intersect -wo ('no record'); endToStartDistance: bedtools closest -d = 2; gapBases: exact formula max(0, max(s) - min(e)), agreeing with d - 1; relation: worked by hand.

At build the tool returned this answer within the tolerance the file states: exact: bases, distances, relations, withheld rules, statuses and codes.

Who worked this case: not recorded.

What it refuses, and its input ranges

  • DIFFERENT_CONTIGS: the intervals are on different contigs: there is no distance between chromosomes Next: Compare intervals on the same contig.
  • ZERO_LENGTH_USE_SITE: an interval has zero length Next: Use genome_coordinate_convert for a site.
  • STRAND_RULE_NEEDS_STRANDS: a strand rule is stated but an interval's strand is unstranded or unknown Next: Give both strands as + or -, or leave out the strand rule.
  • COORDINATE_ABOVE_RANGE: a coordinate is above 2^53 − 1 = 9007199254740991, the largest n for which n and n + 1 are both exact Next: No change of input makes this computable on these data.

Changes

No correction is logged for genome-interval-overlap@1.0.2.

Tools that use it

Cite this version

Overlap, gap and relation of two genomic intervals. Drybench; genome-interval-overlap@1.0.2; https://www.drybench.com/methods/m/genome-interval-overlap/1.0.2 (accessed [date]).