jbrowse-plugin-tview 2.2.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +325 -106
- package/dist/AddHighlightModel/index.js +2 -13
- package/dist/AddHighlightModel/index.js.map +1 -1
- package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.d.ts +44 -64
- package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js +57 -81
- package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js.map +1 -1
- package/dist/LaunchTView/TviewGetPlanRpc/index.d.ts +1 -1
- package/dist/LaunchTView/align.d.ts +11 -17
- package/dist/LaunchTView/align.js +190 -150
- package/dist/LaunchTView/align.js.map +1 -1
- package/dist/LaunchTView/alleles.d.ts +51 -0
- package/dist/LaunchTView/alleles.js +213 -0
- package/dist/LaunchTView/alleles.js.map +1 -1
- package/dist/LaunchTView/fetchTviewPlan.d.ts +5 -37
- package/dist/LaunchTView/fetchTviewPlan.js +7 -28
- package/dist/LaunchTView/fetchTviewPlan.js.map +1 -1
- package/dist/LaunchTView/index.js +45 -16
- package/dist/LaunchTView/index.js.map +1 -1
- package/dist/LaunchTView/launch.d.ts +50 -0
- package/dist/LaunchTView/launch.js +48 -0
- package/dist/LaunchTView/launch.js.map +1 -0
- package/dist/LaunchTView/launchView.d.ts +3 -8
- package/dist/LaunchTView/launchView.js +18 -12
- package/dist/LaunchTView/launchView.js.map +1 -1
- package/dist/LaunchTView/modifications.d.ts +64 -0
- package/dist/LaunchTView/modifications.js +131 -0
- package/dist/LaunchTView/modifications.js.map +1 -0
- package/dist/LaunchTView/readLayout.d.ts +35 -39
- package/dist/LaunchTView/readLayout.js +44 -24
- package/dist/LaunchTView/readLayout.js.map +1 -1
- package/dist/LaunchTView/repeatStats.d.ts +1 -1
- package/dist/LaunchTView/repeatStats.js +6 -21
- package/dist/LaunchTView/repeatStats.js.map +1 -1
- package/dist/LaunchTView/tview.d.ts +34 -23
- package/dist/LaunchTView/tview.js +133 -78
- package/dist/LaunchTView/tview.js.map +1 -1
- package/dist/TViewPanel/components/TViewPanel.js +9 -4
- package/dist/TViewPanel/components/TViewPanel.js.map +1 -1
- package/dist/TViewPanel/genome.d.ts +11 -0
- package/dist/TViewPanel/genome.js +32 -0
- package/dist/TViewPanel/genome.js.map +1 -0
- package/dist/TViewPanel/init.d.ts +38 -19
- package/dist/TViewPanel/init.js +66 -39
- package/dist/TViewPanel/init.js.map +1 -1
- package/dist/TViewPanel/initMenu.d.ts +28 -0
- package/dist/TViewPanel/initMenu.js +79 -0
- package/dist/TViewPanel/initMenu.js.map +1 -0
- package/dist/TViewPanel/model.d.ts +1090 -334
- package/dist/TViewPanel/model.js +295 -89
- package/dist/TViewPanel/model.js.map +1 -1
- package/dist/TViewPanel/modifications.d.ts +25 -0
- package/dist/TViewPanel/modifications.js +94 -0
- package/dist/TViewPanel/modifications.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/jbrowse-plugin-tview.umd.production.min.js +125 -88
- package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -8
- package/src/AddHighlightModel/index.tsx +8 -14
- package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +119 -157
- package/src/LaunchTView/TviewGetPlanRpc/index.ts +0 -1
- package/src/LaunchTView/align.ts +225 -176
- package/src/LaunchTView/alleles.ts +272 -0
- package/src/LaunchTView/fetchTviewPlan.ts +11 -54
- package/src/LaunchTView/index.ts +74 -16
- package/src/LaunchTView/launch.ts +98 -0
- package/src/LaunchTView/launchView.ts +28 -20
- package/src/LaunchTView/modifications.ts +200 -0
- package/src/LaunchTView/readLayout.ts +65 -41
- package/src/LaunchTView/repeatStats.ts +7 -23
- package/src/LaunchTView/tview.ts +165 -91
- package/src/TViewPanel/components/TViewPanel.tsx +30 -5
- package/src/TViewPanel/genome.ts +41 -0
- package/src/TViewPanel/init.ts +104 -51
- package/src/TViewPanel/initMenu.ts +126 -0
- package/src/TViewPanel/model.ts +346 -97
- package/src/TViewPanel/modifications.ts +132 -0
- package/src/index.ts +0 -2
- package/src/version.ts +1 -1
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.d.ts +0 -6
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.js +0 -23
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.js.map +0 -1
- package/dist/AddHighlightModel/HighlightComponents.d.ts +0 -7
- package/dist/AddHighlightModel/HighlightComponents.js +0 -11
- package/dist/AddHighlightModel/HighlightComponents.js.map +0 -1
- package/dist/LaunchTView/components/ArrayReport.d.ts +0 -10
- package/dist/LaunchTView/components/ArrayReport.js +0 -59
- package/dist/LaunchTView/components/ArrayReport.js.map +0 -1
- package/dist/LaunchTView/components/LaunchTViewDialog.d.ts +0 -6
- package/dist/LaunchTView/components/LaunchTViewDialog.js +0 -124
- package/dist/LaunchTView/components/LaunchTViewDialog.js.map +0 -1
- package/dist/LaunchTView/sampleTree.d.ts +0 -37
- package/dist/LaunchTView/sampleTree.js +0 -65
- package/dist/LaunchTView/sampleTree.js.map +0 -1
- package/dist/LaunchTView/useTviewMsa.d.ts +0 -18
- package/dist/LaunchTView/useTviewMsa.js +0 -24
- package/dist/LaunchTView/useTviewMsa.js.map +0 -1
- package/dist/TViewPanel/coords.d.ts +0 -25
- package/dist/TViewPanel/coords.js +0 -56
- package/dist/TViewPanel/coords.js.map +0 -1
- package/src/AddHighlightModel/GenomeMouseoverHighlight.tsx +0 -46
- package/src/AddHighlightModel/HighlightComponents.tsx +0 -25
- package/src/LaunchTView/components/ArrayReport.tsx +0 -64
- package/src/LaunchTView/components/LaunchTViewDialog.tsx +0 -212
- package/src/LaunchTView/sampleTree.ts +0 -73
- package/src/LaunchTView/useTviewMsa.ts +0 -39
- package/src/TViewPanel/coords.ts +0 -65
|
@@ -151,6 +151,44 @@ export function shiftInsertion(
|
|
|
151
151
|
return seq
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* `ins`, inserted before `from`, moved to before `to` by re-dividing the read's
|
|
156
|
+
* own bases between the two: the bases it passes over and the inserted ones
|
|
157
|
+
* are one run of the read, and the move only changes which of them are called
|
|
158
|
+
* inserted. Unlike `shiftInsertion` it moves whether or not the bases agree,
|
|
159
|
+
* so the row may come out with mismatches it did not have; it still spells the
|
|
160
|
+
* read exactly. Undefined where the read has no base at a position passed
|
|
161
|
+
* over, or does not reach the target.
|
|
162
|
+
*/
|
|
163
|
+
export function moveInsertion(
|
|
164
|
+
read: ReadLayout,
|
|
165
|
+
from: number,
|
|
166
|
+
to: number,
|
|
167
|
+
ins: string,
|
|
168
|
+
) {
|
|
169
|
+
const lo = Math.min(from, to) - read.start
|
|
170
|
+
const hi = Math.max(from, to) - read.start
|
|
171
|
+
const passed = read.refChars.slice(lo, hi)
|
|
172
|
+
const rightward = from < to
|
|
173
|
+
const spelled = rightward ? ins + passed : passed + ins
|
|
174
|
+
return lo < 0 ||
|
|
175
|
+
hi > read.refChars.length ||
|
|
176
|
+
passed.includes(SPANNED_GAP) ||
|
|
177
|
+
passed.includes(ABSENT)
|
|
178
|
+
? undefined
|
|
179
|
+
: {
|
|
180
|
+
seq: rightward
|
|
181
|
+
? spelled.slice(passed.length)
|
|
182
|
+
: spelled.slice(0, ins.length),
|
|
183
|
+
refChars:
|
|
184
|
+
read.refChars.slice(0, lo) +
|
|
185
|
+
(rightward
|
|
186
|
+
? spelled.slice(0, passed.length)
|
|
187
|
+
: spelled.slice(ins.length)) +
|
|
188
|
+
read.refChars.slice(hi),
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
154
192
|
/** an array with the span of reference positions whose insertions it may claim */
|
|
155
193
|
interface FlankWindow {
|
|
156
194
|
array: ReferenceArray
|
|
@@ -284,6 +322,240 @@ export function reanchorInsertions(
|
|
|
284
322
|
})
|
|
285
323
|
}
|
|
286
324
|
|
|
325
|
+
function mod(a: number, b: number) {
|
|
326
|
+
return ((a % b) + b) % b
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* `ins`, inserted before `pos`, walked left through the read's own bases for as
|
|
331
|
+
* long as each step spells the same read, and no further than `floor`.
|
|
332
|
+
*/
|
|
333
|
+
function walkLeft(read: ReadLayout, pos: number, ins: string, floor: number) {
|
|
334
|
+
let at = pos
|
|
335
|
+
while (
|
|
336
|
+
at > floor &&
|
|
337
|
+
readBase(read, at - 1) === ins[mod(ins.length - 1 - (pos - at), ins.length)]
|
|
338
|
+
) {
|
|
339
|
+
at--
|
|
340
|
+
}
|
|
341
|
+
const cut = ins.length - mod(pos - at, ins.length)
|
|
342
|
+
return { at, seq: ins.slice(cut) + ins.slice(0, cut) }
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Re-file each insertion no array owns at the leftmost position that spells the
|
|
347
|
+
* same read, so reads carrying one event agree on its site.
|
|
348
|
+
*
|
|
349
|
+
* This is `shiftInsertion`'s equivalence walked as far as it holds rather than
|
|
350
|
+
* to a target, which is the left-normalization of Tan, Abecasis & Kang. It runs
|
|
351
|
+
* after `reanchorInsertions`, leaves alone any insertion from an array's `start`
|
|
352
|
+
* to its `end` inclusive, and walks none into that span, so no allele an array
|
|
353
|
+
* measures changes. The walk also stops one base inside the region's start, so
|
|
354
|
+
* an insertion in view keeps a reference base on both sides of it, at the
|
|
355
|
+
* read's own start, and at any position where the read has no base. Two insertions of one read that meet keep their order along
|
|
356
|
+
* it.
|
|
357
|
+
*/
|
|
358
|
+
export function normalizeInsertions(
|
|
359
|
+
reads: ReadLayout[],
|
|
360
|
+
arrays: ReferenceArray[],
|
|
361
|
+
regionStart: number,
|
|
362
|
+
) {
|
|
363
|
+
const owned = (pos: number) =>
|
|
364
|
+
arrays.some(array => pos >= array.start && pos <= array.end)
|
|
365
|
+
const arrayFloor = (pos: number) =>
|
|
366
|
+
Math.max(
|
|
367
|
+
-Infinity,
|
|
368
|
+
...arrays.filter(array => array.end < pos).map(array => array.end + 1),
|
|
369
|
+
)
|
|
370
|
+
return reads.map(read => {
|
|
371
|
+
let moved = false
|
|
372
|
+
let previous = -Infinity
|
|
373
|
+
const next = new Map<number, string>()
|
|
374
|
+
for (const [pos, ins] of [...read.insertions].sort((a, b) => a[0] - b[0])) {
|
|
375
|
+
const { at, seq } = owned(pos)
|
|
376
|
+
? { at: pos, seq: ins }
|
|
377
|
+
: walkLeft(
|
|
378
|
+
read,
|
|
379
|
+
pos,
|
|
380
|
+
ins,
|
|
381
|
+
Math.max(regionStart + 1, read.start, arrayFloor(pos), previous),
|
|
382
|
+
)
|
|
383
|
+
next.set(at, (next.get(at) ?? '') + seq)
|
|
384
|
+
moved ||= at !== pos
|
|
385
|
+
previous = at
|
|
386
|
+
}
|
|
387
|
+
return moved ? { ...read, insertions: next } : read
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
* The four constants below were swept over HG002's PacBio HiFi reads at the
|
|
393
|
+
* NPHP4 Alu and at 80 insertions from the GIAB HG002 SV benchmark (v0.6,
|
|
394
|
+
* GRCh37: PASS, 50 to 2000bp, outside segmental duplications, 40 in tandem
|
|
395
|
+
* repeats and 40 not, taken evenly through the file), each in a 200bp window.
|
|
396
|
+
* Unmerged those windows have 102 insertion sites 10 or more columns wide,
|
|
397
|
+
* holding 34,876 insertion columns; at these values, 85 sites and 28,425.
|
|
398
|
+
*/
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Shortest insertion that is moved, or that draws others. Every value from 2
|
|
402
|
+
* to 20 merges the same sites. At 1 the 1bp read errors scattered through the
|
|
403
|
+
* windows are dragged into each other, 85 sites of them; at 50 a chr18 VNTR's
|
|
404
|
+
* 26 to 30bp allele stays split, and so does a 49 to 51bp insertion on chr5.
|
|
405
|
+
*/
|
|
406
|
+
const MERGE_MIN_BP = 10
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Farthest an insertion is moved. The farthest merge measured is 20bp: at
|
|
410
|
+
* 22:47,740,767 six reads carry a 61bp insertion 20bp from where fourteen
|
|
411
|
+
* others put it, and the bases between spell the same, so moving them costs
|
|
412
|
+
* nothing. Nothing more merges between 25 and 60.
|
|
413
|
+
*/
|
|
414
|
+
const MERGE_REACH_BP = 25
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* How far a read's insertion length may be from the median at the site it
|
|
418
|
+
* joins, as a fraction of that median. One event read twice came out up to 13%
|
|
419
|
+
* apart (26 and 30bp of one chr18 VNTR allele; 8% for a 76bp one), and the
|
|
420
|
+
* different events within reach at least 53% apart (a 29bp allele beside a 62bp
|
|
421
|
+
* one, a 38bp insertion beside a 532bp one) — and both of those would have
|
|
422
|
+
* moved for free, so this is what keeps them apart, not the mismatches.
|
|
423
|
+
*/
|
|
424
|
+
const MERGE_LENGTH_SPREAD = 0.2
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Most mismatches against the reference a move may add to its row, net of
|
|
428
|
+
* those the bases it passes already had. Since a move cannot add more than the
|
|
429
|
+
* bases it passes, a read 1 or 2bp off always merges, and one farther off only
|
|
430
|
+
* where the bases between nearly agree. At this cap 49 reads move, 45 of them
|
|
431
|
+
* adding one mismatch or none. The costs do not fall into two groups: a cap of
|
|
432
|
+
* 3 moves 6 more reads, 3 to 7bp off, and each step up after that moves a few
|
|
433
|
+
* more, at about one mismatch for every two bases passed, which is what
|
|
434
|
+
* unrelated sequence costs.
|
|
435
|
+
*/
|
|
436
|
+
const MERGE_MAX_MISMATCHES = 2
|
|
437
|
+
|
|
438
|
+
function median(values: number[]) {
|
|
439
|
+
return [...values].sort((a, b) => a - b)[Math.floor(values.length / 2)]!
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function differences(a: string, b: string) {
|
|
443
|
+
let ret = 0
|
|
444
|
+
for (let i = 0; i < a.length; i++) {
|
|
445
|
+
ret += a[i] === b[i] ? 0 : 1
|
|
446
|
+
}
|
|
447
|
+
return ret
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* `read` with its insertion `ins` moved from `from` to `to`, unless another of
|
|
452
|
+
* its insertions lies in between, it has no base on a position passed over, or
|
|
453
|
+
* the move adds more than `MERGE_MAX_MISMATCHES` against the reference.
|
|
454
|
+
*/
|
|
455
|
+
function mergedRead(
|
|
456
|
+
read: ReadLayout,
|
|
457
|
+
from: number,
|
|
458
|
+
to: number,
|
|
459
|
+
ins: string,
|
|
460
|
+
reference: { seq: string; start: number },
|
|
461
|
+
) {
|
|
462
|
+
const lo = Math.min(from, to)
|
|
463
|
+
const hi = Math.max(from, to)
|
|
464
|
+
const moved = [...read.insertions.keys()].some(
|
|
465
|
+
pos => pos !== from && pos >= lo && pos <= hi,
|
|
466
|
+
)
|
|
467
|
+
? undefined
|
|
468
|
+
: moveInsertion(read, from, to, ins)
|
|
469
|
+
const passed = (refChars: string) =>
|
|
470
|
+
refChars.slice(lo - read.start, hi - read.start)
|
|
471
|
+
const ref = reference.seq.slice(lo - reference.start, hi - reference.start)
|
|
472
|
+
const insertions = new Map(read.insertions)
|
|
473
|
+
insertions.delete(from)
|
|
474
|
+
return moved &&
|
|
475
|
+
differences(passed(moved.refChars), ref) -
|
|
476
|
+
differences(passed(read.refChars), ref) <=
|
|
477
|
+
MERGE_MAX_MISMATCHES
|
|
478
|
+
? {
|
|
479
|
+
...read,
|
|
480
|
+
refChars: moved.refChars,
|
|
481
|
+
insertions: insertions.set(to, moved.seq),
|
|
482
|
+
}
|
|
483
|
+
: undefined
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Move each long insertion to a nearby site more reads use, when the read
|
|
488
|
+
* inserts about as much there and the move costs its row no more than a
|
|
489
|
+
* mismatch or two against the reference.
|
|
490
|
+
*
|
|
491
|
+
* Left-normalization is exact, so it brings reads together only where their
|
|
492
|
+
* bases allow it. A read with a sequencing error at the boundary, or anchored a
|
|
493
|
+
* base or two off by the aligner, keeps a site of its own, and every other row
|
|
494
|
+
* pays for that site with a run of gap columns as wide as the insertion.
|
|
495
|
+
* `moveInsertion` re-divides the read's own bases, so the row still spells the
|
|
496
|
+
* read; what the move gives up is that some of them now sit on reference
|
|
497
|
+
* positions they do not match.
|
|
498
|
+
*
|
|
499
|
+
* Sites are visited by the reads inserting there, most first and ties to the
|
|
500
|
+
* leftmost. Each insertion at a site goes to the first site already kept that
|
|
501
|
+
* is within reach, of a similar length, and admits the move, and a site keeps
|
|
502
|
+
* its place if any read still inserts there. Like `normalizeInsertions`, this
|
|
503
|
+
* touches no position from an array's `start` to its `end`, keeps an insertion
|
|
504
|
+
* in view a base inside the region, and keeps a read's insertions in order.
|
|
505
|
+
*/
|
|
506
|
+
export function mergeInsertionSites(
|
|
507
|
+
reads: ReadLayout[],
|
|
508
|
+
arrays: ReferenceArray[],
|
|
509
|
+
reference: { seq: string; start: number },
|
|
510
|
+
) {
|
|
511
|
+
const touchesArray = (lo: number, hi: number) =>
|
|
512
|
+
arrays.some(array => array.start <= hi && array.end >= lo)
|
|
513
|
+
const holders = new Map<number, number[]>()
|
|
514
|
+
reads.forEach((read, i) => {
|
|
515
|
+
for (const [pos, ins] of read.insertions) {
|
|
516
|
+
if (ins.length >= MERGE_MIN_BP && !touchesArray(pos, pos)) {
|
|
517
|
+
holders.set(pos, [...(holders.get(pos) ?? []), i])
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
})
|
|
521
|
+
const reaches = (
|
|
522
|
+
target: { pos: number; length: number },
|
|
523
|
+
pos: number,
|
|
524
|
+
length: number,
|
|
525
|
+
) =>
|
|
526
|
+
target.pos > reference.start &&
|
|
527
|
+
Math.abs(target.pos - pos) <= MERGE_REACH_BP &&
|
|
528
|
+
Math.abs(length - target.length) <= MERGE_LENGTH_SPREAD * target.length &&
|
|
529
|
+
!touchesArray(Math.min(pos, target.pos), Math.max(pos, target.pos))
|
|
530
|
+
const ret = [...reads]
|
|
531
|
+
const kept: { pos: number; length: number }[] = []
|
|
532
|
+
for (const [pos, indices] of [...holders].sort(
|
|
533
|
+
(a, b) => b[1].length - a[1].length || a[0] - b[0],
|
|
534
|
+
)) {
|
|
535
|
+
const stayed: number[] = []
|
|
536
|
+
for (const i of indices) {
|
|
537
|
+
const read = ret[i]!
|
|
538
|
+
const ins = read.insertions.get(pos) ?? ''
|
|
539
|
+
const moved = kept
|
|
540
|
+
.filter(target => reaches(target, pos, ins.length))
|
|
541
|
+
.reduce<ReadLayout | undefined>(
|
|
542
|
+
(found, target) =>
|
|
543
|
+
found ?? mergedRead(read, pos, target.pos, ins, reference),
|
|
544
|
+
undefined,
|
|
545
|
+
)
|
|
546
|
+
if (moved) {
|
|
547
|
+
ret[i] = moved
|
|
548
|
+
} else {
|
|
549
|
+
stayed.push(ins.length)
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (stayed.length) {
|
|
553
|
+
kept.push({ pos, length: median(stayed) })
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return ret
|
|
557
|
+
}
|
|
558
|
+
|
|
287
559
|
/**
|
|
288
560
|
* Lay every row's allele out unit-per-block, one block per array.
|
|
289
561
|
*
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { readConfObject } from '@jbrowse/core/configuration'
|
|
2
|
-
|
|
3
1
|
import { MAX_CELLS } from './limits'
|
|
4
2
|
|
|
5
|
-
import type { TviewPlanResult } from './TviewGetPlanRpc'
|
|
6
|
-
import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
|
|
7
3
|
import type { AbstractSessionModel } from '@jbrowse/core/util'
|
|
8
4
|
|
|
9
5
|
/** the RPC needs assemblyName to resolve refNameAliases for the file */
|
|
@@ -16,55 +12,11 @@ export interface FetchRegion {
|
|
|
16
12
|
|
|
17
13
|
/** one track's worth of rows, and the name they are grouped under */
|
|
18
14
|
export interface TviewSource {
|
|
19
|
-
adapterConfig: unknown
|
|
20
|
-
|
|
21
|
-
sample?: string
|
|
15
|
+
adapterConfig: Record<string, unknown>
|
|
16
|
+
sample: string
|
|
22
17
|
trackId: string
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
/**
|
|
26
|
-
* The trackId -> config index, whose shape has changed across hosts still in
|
|
27
|
-
* the wild: v4.0.0 exposes a `tracksById` getter, v4.1-v4.3 a `getTracksById()`
|
|
28
|
-
* method, and newer cores a per-id reactive `getTrackById(id)` (with
|
|
29
|
-
* `getTracksById()` kept but deprecated). All three resolve connection and
|
|
30
|
-
* assembly-sequence tracks; the `tracks` scan is a last resort because it does
|
|
31
|
-
* not, and it subscribes the caller to every track.
|
|
32
|
-
*/
|
|
33
|
-
export interface SessionTrackLookup {
|
|
34
|
-
tracks: AnyConfigurationModel[]
|
|
35
|
-
getTrackById?: (id: string) => AnyConfigurationModel | undefined
|
|
36
|
-
getTracksById?: () => Record<string, AnyConfigurationModel>
|
|
37
|
-
tracksById?: Record<string, AnyConfigurationModel>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function findTrackConf(session: SessionTrackLookup, trackId: string) {
|
|
41
|
-
return session.getTrackById
|
|
42
|
-
? session.getTrackById(trackId)
|
|
43
|
-
: session.getTracksById
|
|
44
|
-
? session.getTracksById()[trackId]
|
|
45
|
-
: session.tracksById
|
|
46
|
-
? session.tracksById[trackId]
|
|
47
|
-
: session.tracks.find(t => readConfObject(t, 'trackId') === trackId)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The assembly's own sequence adapter, which is what makes the reference a row
|
|
52
|
-
* and, through it, makes an array an interval rather than an insertion. An
|
|
53
|
-
* assembly that cannot supply one still works: the alignment is then reads only
|
|
54
|
-
* and no array is reported, which is the pre-reference behaviour.
|
|
55
|
-
*/
|
|
56
|
-
export function sequenceAdapterConfig(
|
|
57
|
-
session: AbstractSessionModel,
|
|
58
|
-
assemblyName: string,
|
|
59
|
-
) {
|
|
60
|
-
const assembly = session.assemblyManager.get(assemblyName)
|
|
61
|
-
const conf = assembly?.configuration
|
|
62
|
-
return conf
|
|
63
|
-
? (readConfObject(conf, ['sequence', 'adapter']) as
|
|
64
|
-
Record<string, unknown> | undefined)
|
|
65
|
-
: undefined
|
|
66
|
-
}
|
|
67
|
-
|
|
68
20
|
/**
|
|
69
21
|
* One RPC per launch, however many files it draws from. The session id is
|
|
70
22
|
* shared across the sources so the worker keeps one adapter cache for the view
|
|
@@ -75,21 +27,26 @@ export async function fetchTviewPlan({
|
|
|
75
27
|
sources,
|
|
76
28
|
region,
|
|
77
29
|
maxCells = MAX_CELLS,
|
|
30
|
+
signal,
|
|
78
31
|
}: {
|
|
79
32
|
session: AbstractSessionModel
|
|
80
33
|
sources: TviewSource[]
|
|
81
34
|
region: FetchRegion
|
|
82
35
|
maxCells?: number
|
|
36
|
+
signal?: AbortSignal
|
|
83
37
|
}) {
|
|
84
38
|
const rpcSessionId = `tview-${sources.map(s => s.trackId).join(',')}`
|
|
85
|
-
|
|
86
|
-
|
|
39
|
+
const assembly = session.assemblyManager.get(region.assemblyName)
|
|
40
|
+
return session.rpcManager.call(rpcSessionId, 'TviewGetPlan', {
|
|
87
41
|
sources: sources.map(s => ({
|
|
88
42
|
adapterConfig: s.adapterConfig,
|
|
89
43
|
sample: s.sample,
|
|
90
44
|
})),
|
|
91
|
-
|
|
45
|
+
assemblyName: region.assemblyName,
|
|
46
|
+
sequenceRefName:
|
|
47
|
+
assembly?.getSeqAdapterRefName(region.refName) ?? region.refName,
|
|
92
48
|
region,
|
|
93
49
|
maxCells,
|
|
94
|
-
|
|
50
|
+
signal,
|
|
51
|
+
})
|
|
95
52
|
}
|
package/src/LaunchTView/index.ts
CHANGED
|
@@ -1,39 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addViewMenuItems } from '@jbrowse/core/pluggableElementTypes'
|
|
2
|
+
import {
|
|
3
|
+
getContainingTrack,
|
|
4
|
+
getContainingView,
|
|
5
|
+
getSession,
|
|
6
|
+
} from '@jbrowse/core/util'
|
|
2
7
|
import AddIcon from '@mui/icons-material/Add'
|
|
3
8
|
|
|
4
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
alignmentsTrackIds,
|
|
11
|
+
isGenomeView,
|
|
12
|
+
launchTView,
|
|
13
|
+
regionLaunch,
|
|
14
|
+
} from './launch'
|
|
5
15
|
|
|
16
|
+
import type { RegionLaunch } from './launch'
|
|
6
17
|
import type PluginManager from '@jbrowse/core/PluginManager'
|
|
7
18
|
import type { PluggableElementType } from '@jbrowse/core/pluggableElementTypes'
|
|
8
19
|
import type DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
|
|
9
20
|
import type { MenuItem } from '@jbrowse/core/ui'
|
|
21
|
+
import type { AbstractSessionModel } from '@jbrowse/core/util'
|
|
10
22
|
import type { IAnyModelType } from '@jbrowse/mobx-state-tree'
|
|
11
23
|
|
|
24
|
+
const VISIBLE_REGION_LABEL = 'Launch tview for visible region'
|
|
25
|
+
const SELECTION_LABEL = 'Tview of all alignments tracks'
|
|
26
|
+
|
|
12
27
|
function isDisplay(elt: { name: string }): elt is DisplayType {
|
|
13
28
|
return elt.name === 'LinearAlignmentsDisplay'
|
|
14
29
|
}
|
|
15
30
|
|
|
31
|
+
function launchItem({
|
|
32
|
+
label,
|
|
33
|
+
launch,
|
|
34
|
+
session,
|
|
35
|
+
tracks,
|
|
36
|
+
connectedViewId,
|
|
37
|
+
}: {
|
|
38
|
+
label: string
|
|
39
|
+
launch: RegionLaunch
|
|
40
|
+
session: AbstractSessionModel
|
|
41
|
+
tracks: string[]
|
|
42
|
+
connectedViewId: string
|
|
43
|
+
}): MenuItem {
|
|
44
|
+
return {
|
|
45
|
+
label,
|
|
46
|
+
icon: AddIcon,
|
|
47
|
+
disabled: launch.reason !== undefined,
|
|
48
|
+
subLabel: launch.reason,
|
|
49
|
+
onClick: () => {
|
|
50
|
+
if (launch.reason === undefined) {
|
|
51
|
+
launchTView(session, { ...launch, tracks, connectedViewId })
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
16
57
|
function extendStateModel(stateModel: IAnyModelType) {
|
|
17
58
|
return stateModel.views((self: { trackMenuItems: () => MenuItem[] }) => {
|
|
18
59
|
const superTrackMenuItems = self.trackMenuItems
|
|
19
60
|
return {
|
|
20
61
|
trackMenuItems() {
|
|
62
|
+
const session = getSession(self)
|
|
63
|
+
const view = getContainingView(self)
|
|
64
|
+
const track = getContainingTrack(self)
|
|
21
65
|
return [
|
|
22
66
|
...superTrackMenuItems(),
|
|
23
|
-
{
|
|
24
|
-
label:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
handleClose,
|
|
33
|
-
},
|
|
34
|
-
])
|
|
35
|
-
},
|
|
36
|
-
},
|
|
67
|
+
launchItem({
|
|
68
|
+
label: VISIBLE_REGION_LABEL,
|
|
69
|
+
launch: isGenomeView(view)
|
|
70
|
+
? regionLaunch(session, view.visibleWholeBaseRegions)
|
|
71
|
+
: { reason: 'Not in a linear genome view' },
|
|
72
|
+
session,
|
|
73
|
+
tracks: [track.configuration.trackId],
|
|
74
|
+
connectedViewId: view.id,
|
|
75
|
+
}),
|
|
37
76
|
]
|
|
38
77
|
},
|
|
39
78
|
}
|
|
@@ -50,4 +89,23 @@ export default function LaunchTViewF(pluginManager: PluginManager) {
|
|
|
50
89
|
return elt
|
|
51
90
|
},
|
|
52
91
|
)
|
|
92
|
+
|
|
93
|
+
addViewMenuItems(pluginManager, 'LinearGenomeView', {
|
|
94
|
+
menu: 'rubberBandLaunchMenuItems',
|
|
95
|
+
items: self => {
|
|
96
|
+
const tracks = alignmentsTrackIds(self.tracks)
|
|
97
|
+
return tracks.length
|
|
98
|
+
? launchItem({
|
|
99
|
+
label: SELECTION_LABEL,
|
|
100
|
+
launch: regionLaunch(
|
|
101
|
+
getSession(self),
|
|
102
|
+
self.getSelectedRegions(self.leftOffset, self.rightOffset),
|
|
103
|
+
),
|
|
104
|
+
session: getSession(self),
|
|
105
|
+
tracks,
|
|
106
|
+
connectedViewId: self.id,
|
|
107
|
+
})
|
|
108
|
+
: undefined
|
|
109
|
+
},
|
|
110
|
+
})
|
|
53
111
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { assembleLocString } from '@jbrowse/core/util'
|
|
2
|
+
|
|
3
|
+
import { checkRegion } from '../TViewPanel/init'
|
|
4
|
+
|
|
5
|
+
import type { LocAssembly, TviewTrackInit } from '../TViewPanel/init'
|
|
6
|
+
import type { AbstractSessionModel } from '@jbrowse/core/util'
|
|
7
|
+
|
|
8
|
+
export interface WholeBaseRegion {
|
|
9
|
+
assemblyName: string
|
|
10
|
+
refName: string
|
|
11
|
+
start: number
|
|
12
|
+
end: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TrackLike {
|
|
16
|
+
configuration: { trackId: string }
|
|
17
|
+
displays: readonly { type: string }[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GenomeView {
|
|
21
|
+
id: string
|
|
22
|
+
tracks: readonly TrackLike[]
|
|
23
|
+
visibleWholeBaseRegions: WholeBaseRegion[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AssemblySource {
|
|
27
|
+
assemblyManager: {
|
|
28
|
+
get: (name: string) => (LocAssembly & { initialized: boolean }) | undefined
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TViewLaunch {
|
|
33
|
+
assembly: string
|
|
34
|
+
loc: string
|
|
35
|
+
tracks: TviewTrackInit[]
|
|
36
|
+
connectedViewId?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type RegionLaunch =
|
|
40
|
+
{ assembly: string; loc: string; reason?: undefined } | { reason: string }
|
|
41
|
+
|
|
42
|
+
export function isGenomeView(view: object): view is GenomeView {
|
|
43
|
+
return 'visibleWholeBaseRegions' in view && 'tracks' in view
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function alignmentsTrackIds(tracks: readonly TrackLike[]) {
|
|
47
|
+
return tracks
|
|
48
|
+
.filter(track =>
|
|
49
|
+
track.displays.some(d => d.type === 'LinearAlignmentsDisplay'),
|
|
50
|
+
)
|
|
51
|
+
.map(track => track.configuration.trackId)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The locus a tview over `regions` would show, or why there is none. The width
|
|
56
|
+
* and contig rules are {@link checkRegion}'s, so a menu offers exactly what the
|
|
57
|
+
* view would then agree to load.
|
|
58
|
+
*/
|
|
59
|
+
export function regionLaunch(
|
|
60
|
+
session: AssemblySource,
|
|
61
|
+
regions: readonly WholeBaseRegion[],
|
|
62
|
+
): RegionLaunch {
|
|
63
|
+
const [region] = regions
|
|
64
|
+
const assembly = region
|
|
65
|
+
? session.assemblyManager.get(region.assemblyName)
|
|
66
|
+
: undefined
|
|
67
|
+
const loc = region
|
|
68
|
+
? assembleLocString({
|
|
69
|
+
refName: region.refName,
|
|
70
|
+
start: region.start,
|
|
71
|
+
end: region.end,
|
|
72
|
+
})
|
|
73
|
+
: ''
|
|
74
|
+
const check = assembly?.initialized ? checkRegion(assembly, loc) : undefined
|
|
75
|
+
return !region
|
|
76
|
+
? { reason: 'No region is in view' }
|
|
77
|
+
: regions.length > 1
|
|
78
|
+
? { reason: 'Spans more than one region' }
|
|
79
|
+
: !check
|
|
80
|
+
? { reason: `Assembly ${region.assemblyName} is not loaded` }
|
|
81
|
+
: check.error !== undefined
|
|
82
|
+
? { reason: check.error }
|
|
83
|
+
: { assembly: region.assemblyName, loc }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function launchTView(
|
|
87
|
+
session: Pick<AbstractSessionModel, 'addView'>,
|
|
88
|
+
{ assembly, loc, tracks, connectedViewId }: TViewLaunch,
|
|
89
|
+
viewProps: Record<string, unknown> = {},
|
|
90
|
+
) {
|
|
91
|
+
return session.addView('TView', {
|
|
92
|
+
displayName: loc,
|
|
93
|
+
connectedViewId,
|
|
94
|
+
...viewProps,
|
|
95
|
+
type: 'TView',
|
|
96
|
+
init: { assembly, loc, tracks },
|
|
97
|
+
})
|
|
98
|
+
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { launchTView } from './launch'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { TviewTrackInit } from '../TViewPanel/init'
|
|
4
4
|
import type PluginManager from '@jbrowse/core/PluginManager'
|
|
5
5
|
import type { AbstractSessionModel } from '@jbrowse/core/util'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* `LaunchView-TView`, so a session spec URL can open one.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* while a config or defaultSession view is MST state, where anything needing
|
|
13
|
-
* resolution on load lives under the view's own `init`. So the spec
|
|
10
|
+
* A spec view is flat arguments to this launcher, while a config or
|
|
11
|
+
* defaultSession view is MST state with the locus under `init`, so the spec
|
|
14
12
|
*
|
|
15
13
|
* { type: 'TView', assembly: 'hg19', loc: 'chrX:1..2', tracks: ['HG002'] }
|
|
16
14
|
*
|
|
@@ -18,32 +16,42 @@ import type { AbstractSessionModel } from '@jbrowse/core/util'
|
|
|
18
16
|
*
|
|
19
17
|
* { type: 'TView', init: { assembly: 'hg19', loc: '…', tracks: […] } }
|
|
20
18
|
*
|
|
21
|
-
* are the same view
|
|
22
|
-
* `initKeys` rather than listing the pass-through props means every react-msaview
|
|
23
|
-
* view prop — colWidth, rowHeight, colorSchemeName, the ones added next — rides
|
|
24
|
-
* along without being enumerated here.
|
|
19
|
+
* are the same view. Every other key is passed through as a view prop.
|
|
25
20
|
*/
|
|
26
21
|
export type LaunchTViewArgs = { session: AbstractSessionModel } & Record<
|
|
27
22
|
string,
|
|
28
23
|
unknown
|
|
29
24
|
>
|
|
30
25
|
|
|
26
|
+
function isTrackInit(entry: unknown): entry is TviewTrackInit {
|
|
27
|
+
return (
|
|
28
|
+
typeof entry === 'string' ||
|
|
29
|
+
(typeof entry === 'object' &&
|
|
30
|
+
entry !== null &&
|
|
31
|
+
'trackId' in entry &&
|
|
32
|
+
typeof entry.trackId === 'string' &&
|
|
33
|
+
(!('sample' in entry) || typeof entry.sample === 'string'))
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
export default function LaunchTViewF(pluginManager: PluginManager) {
|
|
32
38
|
/** #extensionPoint LaunchView-TView | async | Programmatically launch a tview */
|
|
33
39
|
pluginManager.addToExtensionPoint(
|
|
34
40
|
'LaunchView-TView',
|
|
35
41
|
(args: LaunchTViewArgs) => {
|
|
36
|
-
const { session, ...
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const { session, assembly, loc, tracks, ...viewProps } = args
|
|
43
|
+
if (
|
|
44
|
+
typeof assembly === 'string' &&
|
|
45
|
+
typeof loc === 'string' &&
|
|
46
|
+
Array.isArray(tracks) &&
|
|
47
|
+
tracks.every(isTrackInit)
|
|
48
|
+
) {
|
|
49
|
+
launchTView(session, { assembly, loc, tracks }, viewProps)
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'A TView spec needs an assembly name, a loc string and a tracks array of trackIds',
|
|
53
|
+
)
|
|
41
54
|
}
|
|
42
|
-
session.addView('TView', {
|
|
43
|
-
type: 'TView',
|
|
44
|
-
...viewProps,
|
|
45
|
-
init: init as unknown as TviewInit,
|
|
46
|
-
})
|
|
47
55
|
return args
|
|
48
56
|
},
|
|
49
57
|
)
|