Skip to content

fix(science): send the UCSC start coordinate 0-relative - #797

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/ucsc-sequence-coordinates
Sep 29, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/ucsc-sequence-coordinates

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What

A genomic position like chr1:100000-100010 is 1-based and inclusive (UCSC's own position bar, Ensembl, VEP). The UCSC JSON API's start is documented as 0-relative and its end as 1-relative:

start=<123> - specify start coordinate (0 relative) for data from track or sequence retrieval
end=<456> - specify end coordinate (1 relative) for data from track or sequence retrieval
— https://genome.ucsc.edu/goldenPath/help/api.html

The connector passed both numbers through unconverted, and its range check also rejected single-base positions:

if (Number.isFinite(start) && Number.isFinite(end) && end > start) { ... }
// otherwise: fall through to /search

Why it matters

This is a scientific connector, so the failure is a silently wrong sequence rather than an error.

chr1:100-200 means 1-based bases 100-200 (101 bases). The request asked for 1-based 101-200 — the wrong first base, and one base short. Nothing about the response looks wrong; the mistake only surfaces when the region is a promoter, an ATGC motif, or a short exon boundary, which is exactly where an off-by-one matters.

And end > start rejected end == start, so chr17:7676154-7676154 — the single-nucleotide lookup — fell through to /search?search=chr17%3A7676154-7676154 and returned whatever a full-text search happened to match.

Verification

New file — ucsc was covered by no test. Three of four fail before the fix:

Expected to contain: "start=99999&end=100010"
Received: ".../getData/sequence?genome=hg38&chrom=chr1&start=100000&end=100010"

Expected to contain: "/getData/sequence"
Received: ".../search?search=chr17%3A7676154-7676154&genome=hg38"

Expected to contain: "start=0&end=50001"
Received: "...&start=1&end=50001"

After the fix:

(pass) a 1-based interval is sent with a 0-relative start
(pass) a single-base interval asks for the sequence, not the search endpoint
(pass) a long interval is still capped at 50,000 bases
(pass) a non-position term goes to the search endpoint
 4 pass
 0 fail

The surrounding connector suites are unaffected — connector-formats, connector-fetch, and the new file together: 61 pass, 0 fail. No network access in any of them; fetch is stubbed the same way the existing connector tests do it.

The change

-      if (Number.isFinite(start) && Number.isFinite(end) && end > start) {
+      // A browser position is 1-based and inclusive, but the API documents
+      // `start` as 0-relative and `end` as 1-relative, so the start shifts down
+      // by one base. Without that the caller got the wrong first base and a
+      // sequence one base short. `>=` rather than `>` because a single-base
+      // position is the common single-nucleotide lookup, and rejecting it
+      // sent the query to /search instead, returning whatever a full-text
+      // search happened to match.
+      if (Number.isFinite(start) && Number.isFinite(end) && start >= 1 && end >= start) {
         const capped = Math.min(end, start + 50_000)
         ...
-            `&start=${start}&end=${capped}`,
+            `&start=${start - 1}&end=${capped}`,

capped is deliberately unchanged: the API's end is already 1-relative, so the existing 50,000-base cap was correct. The added start >= 1 also keeps chr1:0-0 on the search path rather than asking for a negative offset.

bun run typecheck clean; touched files are Prettier-clean (checked on LF-normalized copies — this checkout has core.autocrlf=true, which makes Prettier flag every file in the repo).

Fixes #796

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

A browser position is 1-based inclusive, but the API documents start as 0-relative and end as 1-relative, so the start has to shift down one base. A single-base position also failed end > start and fell through to the search endpoint, answering a single-nucleotide lookup with full-text search results.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit f2371bb into synthetic-sciences:main Sep 29, 2026
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.

The UCSC connector returns an off-by-one sequence, and a single-base position is answered by a text search

2 participants