Skip to content

preliminary support for bedj tk using list of bed items#4304

Merged
xzhou82 merged 2 commits intomasterfrom
bed.1
Mar 13, 2026
Merged

preliminary support for bedj tk using list of bed items#4304
xzhou82 merged 2 commits intomasterfrom
bed.1

Conversation

@xzhou82
Copy link
Collaborator

@xzhou82 xzhou82 commented Mar 12, 2026

Description

see example in newly added test in test/block.integration.spec.ts, which renders as below

image

TODO

  • appdrawer bedj card example
  • input ui of a textarea somewhere (e.g. in block header) to copy-paste bed data to show. need to decide on format of pasted data

Checklist

Check each task that has been performed or verified to be not applicable.

  • Tests: Added and/or passed unit and integration tests, or N/A
  • Todos: Commented or documented, or N/A
  • Notable Changes: updated release.txt, prefixed a commit message with "fix:" or "feat:", added to an internal tracking document, or N/A
  • Rust: Checked to see whether Rust needs to be re-compiled because of this PR, or N/A

Copilot AI review requested due to automatic review settings March 12, 2026 22:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds preliminary support for rendering bedj tracks from a client-supplied in-memory list of BED-like items (instead of reading a BED/bigBed file), with an integration test demonstrating the new behavior.

Changes:

  • Server: refactors bedj item acquisition into getBEDitems() and adds a req.query.bedItems code path.
  • Client: includes bedItems in the POST payload for bedj tracks when present.
  • Tests: adds an integration test that renders a bedj track from bedItems.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
server/src/bedj.js Adds bedItems support and factors item loading/filtering into getBEDitems()
client/src/block.js Sends bedItems in bedj request payload when provided on the track config
client/src/test/block.integration.spec.ts Adds integration coverage for rendering a bedj track from a custom bedItems list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +857 to +880
async function getBEDitems(req, genomeobj, flag_gm, gmisoform) {
if (req.query.bedItems) {
// client supplies list of "bed" items to render. no file to read
if (!Array.isArray(req.query.bedItems)) throw 'bedItems not array'
const lst = []
for (const j of req.query.bedItems) {
if (typeof j != 'object') throw 'one of bedItems[] not obj'
if (!j.chr) throw 'bedItems[].chr missing'
if (!Number.isInteger(j.start)) throw 'bedItems[].start not integer'
if (!Number.isInteger(j.stop)) throw 'bedItems[].stop not integer'
j.rglst = []
// duplicate following lines with elsewhere as chr equivalency check is needed here but not there
for (let i = 0; i < req.query.rglst.length; i++) {
const r = req.query.rglst[i]
if (r.chr != j.chr) continue
if (Math.max(j.start, r.start) < Math.min(j.stop, r.stop)) {
j.rglst.push({ idx: i })
}
}
if (j.rglst.length == 0) continue
lst.push(j)
}
return lst
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When bedItems is provided, the function returns early and bypasses the existing filtering logic (usevalue, bplengthUpperLimit, filterByName). If these query params are meant to apply uniformly to all bedj data sources, the same filters should be applied to bedItems as well (or the API should explicitly reject/ignore them to avoid inconsistent behavior).

Copilot uses AI. Check for mistakes.
Comment on lines +861 to +874
const lst = []
for (const j of req.query.bedItems) {
if (typeof j != 'object') throw 'one of bedItems[] not obj'
if (!j.chr) throw 'bedItems[].chr missing'
if (!Number.isInteger(j.start)) throw 'bedItems[].start not integer'
if (!Number.isInteger(j.stop)) throw 'bedItems[].stop not integer'
j.rglst = []
// duplicate following lines with elsewhere as chr equivalency check is needed here but not there
for (let i = 0; i < req.query.rglst.length; i++) {
const r = req.query.rglst[i]
if (r.chr != j.chr) continue
if (Math.max(j.start, r.start) < Math.min(j.stop, r.stop)) {
j.rglst.push({ idx: i })
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bedItems processing is O(bedItems × rglst) and there is no server-side cap on the number of items beyond the global 5MB JSON body limit. A large bedItems payload can still cause significant CPU/memory load during stacking/rendering; consider enforcing a reasonable max item count (and/or pre-indexing by chr) and returning a clear error when exceeded.

Copilot uses AI. Check for mistakes.
if (!Array.isArray(req.query.bedItems)) throw 'bedItems not array'
const lst = []
for (const j of req.query.bedItems) {
if (typeof j != 'object') throw 'one of bedItems[] not obj'
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof j != 'object' will not reject null (and will also allow arrays), which can lead to a runtime TypeError at j.chr rather than the intended validation error. Consider explicitly checking j && !Array.isArray(j) && typeof j === 'object' (or similar) before accessing fields.

Suggested change
if (typeof j != 'object') throw 'one of bedItems[] not obj'
if (!j || Array.isArray(j) || typeof j !== 'object') throw 'one of bedItems[] not obj'

Copilot uses AI. Check for mistakes.
@xzhou82 xzhou82 marked this pull request as draft March 12, 2026 22:23
@xzhou82 xzhou82 marked this pull request as ready for review March 13, 2026 02:08
@xzhou82 xzhou82 merged commit 78aa431 into master Mar 13, 2026
1 of 3 checks passed
@xzhou82 xzhou82 deleted the bed.1 branch March 13, 2026 02:08
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.

2 participants