Repository navigation
Description
What happens
src/science/connectors/genomics/ucsc.ts matches a genomic interval and passes the coordinates straight through:
const POSITION = /^(chr[\w.]+):([\d,]+)-([\d,]+)$/i
...
const start = Number(coords[2].replace(/,/g, ""))
const end = Number(coords[3].replace(/,/g, ""))
if (Number.isFinite(start) && Number.isFinite(end) && end > start) {
const capped = Math.min(end, start + 50_000)
return getJSON<Rec>(`${API}/getData/sequence?...&start=${start}&end=${capped}`)
}
// otherwise fall through to /searchTwo problems.
1. Off-by-one on every interval. chrN:start-end is the 1-based inclusive convention used by UCSC's own position bar, Ensembl, and VEP. The API's parameter list says:
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
So a 1-based inclusive interval a-b must be sent as start=a-1&end=b. The code sends start=a&end=b.
2. A single-base position is never a sequence lookup. end > start rejects end == start, so the most common single-nucleotide query of all falls through to getJSON("/search?search=chr17:7676154-7676154") and returns whatever a full-text search happened to match.
Why it is wrong
This is a scientific connector, so the result is silently wrong rather than an error. For chr1:100-200 the caller means 1-based bases 100-200 (101 bases) and receives 1-based 101-200: the wrong first base, and one base short. That is invisible in a returned sequence and material when the region is a promoter, an ATGC motif, or a short exon boundary.
For a single-base position, the caller gets a search result instead of a base, with no error either way.
Reproduction
const s = stub('{"dna":"ACGT"}')
await ucsc.fetch("chr1:100,000-100,010", { params: { genome: "hg38" } })
s.url()
// now: .../getData/sequence?genome=hg38&chrom=chr1&start=100000&end=100010
// want: ...&start=99999&end=100010const t = stub('{"dna":"A"}')
await ucsc.fetch("chr17:7676154-7676154", { params: { genome: "hg38" } })
t.url()
// now: /search?search=chr17%3A7676154-7676154&genome=hg38
// want: /getData/sequence?...&start=7676153&end=7676154Suggested fix
Shift the start down one base and accept a single-base interval:
if (Number.isFinite(start) && Number.isFinite(end) && start >= 1 && end >= start) {
const capped = Math.min(end, start + 50_000)
return getJSON<Rec>(`...&start=${start - 1}&end=${capped}`, ...)
}capped needs no change because the API's end is already 1-relative, so the 50,000-base cap is correct as written.
ucsc appears in no existing test file, so this adds test/science/ucsc-coordinates.test.ts covering the conversion, the single-base case, the cap, and that a non-position term still goes to /search.
Activity