jbrowse-plugin-graphgenomeviewer 4.7.0 → 5.0.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.
Files changed (65) hide show
  1. package/README.md +7 -1
  2. package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js +2 -0
  3. package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js.map +7 -0
  4. package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js +4 -0
  5. package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js.map +7 -0
  6. package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js → GraphGenomeView-YYP4IFSI.js} +2 -2
  7. package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js → GraphTrackSettingsDialog-2WPJRAJC.js} +2 -2
  8. package/dist/chunks/LinearGraphDisplay-7YE624D5.js +2 -0
  9. package/dist/chunks/LinearGraphDisplay-7YE624D5.js.map +7 -0
  10. package/dist/chunks/chunk-2H7GDQ3R.js +6 -0
  11. package/dist/chunks/chunk-2H7GDQ3R.js.map +7 -0
  12. package/dist/chunks/chunk-BZOIENU5.js +2 -0
  13. package/dist/chunks/chunk-BZOIENU5.js.map +7 -0
  14. package/dist/chunks/{chunk-UTWFU4X6.js → chunk-H54W6OQQ.js} +2 -2
  15. package/dist/chunks/{chunk-UTWFU4X6.js.map → chunk-H54W6OQQ.js.map} +4 -4
  16. package/dist/chunks/{chunk-F2EPKNTV.js → chunk-O4XV3K35.js} +2 -2
  17. package/dist/chunks/{chunk-F2EPKNTV.js.map → chunk-O4XV3K35.js.map} +4 -4
  18. package/dist/chunks/chunk-SJNG2XK7.js +2 -0
  19. package/dist/chunks/chunk-SJNG2XK7.js.map +7 -0
  20. package/dist/chunks/chunk-WKVVIDCS.js +3 -0
  21. package/dist/chunks/{chunk-KCL5TF5X.js.map → chunk-WKVVIDCS.js.map} +3 -3
  22. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
  23. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  24. package/package.json +3 -3
  25. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +36 -2
  26. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +67 -1
  27. package/src/GbzBaseSyntenyAdapter/test_data/fragmented.haplotype-index.db +0 -0
  28. package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.haplotype-index.db +0 -0
  29. package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.sampled.haplotype-index.db +0 -0
  30. package/src/GetHaplotypeOverview.ts +77 -0
  31. package/src/GraphGenomeView/components/ChooseWalksDialog.tsx +86 -0
  32. package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +205 -187
  33. package/src/GraphGenomeView/components/TubeMapLegend.test.tsx +29 -0
  34. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +8 -0
  35. package/src/GraphGenomeView/host.ts +6 -0
  36. package/src/GraphGenomeView/model.ts +10 -4224
  37. package/src/GraphGenomeView/pane/fitViews.ts +589 -0
  38. package/src/GraphGenomeView/pane/graphViews.ts +829 -0
  39. package/src/GraphGenomeView/pane/hostViews.ts +193 -0
  40. package/src/GraphGenomeView/pane/launchActions.ts +407 -0
  41. package/src/GraphGenomeView/pane/launchViews.ts +191 -0
  42. package/src/GraphGenomeView/pane/loadActions.ts +701 -0
  43. package/src/GraphGenomeView/pane/paneBase.ts +479 -0
  44. package/src/GraphGenomeView/pane/renderingActions.ts +281 -0
  45. package/src/GraphGenomeView/pane/settingActions.ts +467 -0
  46. package/src/GraphGenomeView/pane/walkRowViews.ts +205 -0
  47. package/src/HaplotypeOverview/HaplotypeOverviewCanvas.tsx +203 -0
  48. package/src/HaplotypeOverview/draw.test.ts +136 -0
  49. package/src/HaplotypeOverview/draw.ts +433 -0
  50. package/src/HaplotypeOverview/model.ts +163 -0
  51. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +184 -0
  52. package/src/LinearGraphDisplay/components/LinearGraphDisplay.tsx +12 -2
  53. package/src/LinearGraphDisplay/model.ts +107 -3
  54. package/src/gaf/gafFile.ts +2 -0
  55. package/src/index.ts +2 -0
  56. package/src/version.ts +1 -1
  57. package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js +0 -8
  58. package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js.map +0 -7
  59. package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js +0 -2
  60. package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js.map +0 -7
  61. package/dist/chunks/chunk-BUXVOMDL.js +0 -2
  62. package/dist/chunks/chunk-BUXVOMDL.js.map +0 -7
  63. package/dist/chunks/chunk-KCL5TF5X.js +0 -3
  64. /package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js.map → GraphGenomeView-YYP4IFSI.js.map} +0 -0
  65. /package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js.map → GraphTrackSettingsDialog-2WPJRAJC.js.map} +0 -0
@@ -0,0 +1,467 @@
1
+ import { FACET_PAD_PX } from '@jbrowse/bandage-core/facetGrid'
2
+ import { segmentAt } from '@jbrowse/bandage-core/layout/walkStrip'
3
+ import { anchorFromPaths } from '@jbrowse/bandage-core/pathAnchoring'
4
+ import {
5
+ FIT_PADDING,
6
+ clampZoom,
7
+ fittedTranslateY,
8
+ } from '@jbrowse/bandage-core/pipeline'
9
+ import { nodeReferenceSpan } from '@jbrowse/bandage-core/referenceSpan'
10
+ import { zoomAbout } from '@jbrowse/bandage-core/viewport'
11
+ import { getSession, isSessionModelWithWidgets } from '@jbrowse/core/util'
12
+ import { isAlive } from '@jbrowse/mobx-state-tree'
13
+
14
+ import { withFitViews } from './fitViews'
15
+ import { VIEWPORT_DEBOUNCE_MS, inheritForceLayouts } from './paneBase'
16
+ import { nodeOwnLocation } from '../../launchFromGraph/contributors'
17
+ import { withRows } from '../../launchFromGraph/linearViewTarget'
18
+
19
+ import type { BubbleSpread } from '@jbrowse/bandage-core/bubbleSpreads'
20
+ import type { MinigraphBubble } from '@jbrowse/bandage-core/bubbles/bubbleLine'
21
+ import type { ColorScheme } from '@jbrowse/bandage-core/colorSchemes'
22
+ import type { FacetSetting } from '@jbrowse/bandage-core/facetGrid'
23
+ import type { LayoutModeValue } from '@jbrowse/bandage-core/layoutModes'
24
+ import type { NodeWidth } from '@jbrowse/bandage-core/nodeWidths'
25
+ import type { Bounds } from '@jbrowse/bandage-core/pipeline'
26
+ import type {
27
+ WalkEncoding,
28
+ WalkLayer,
29
+ } from '@jbrowse/bandage-core/walkEncoding'
30
+
31
+ export const withSettingActions = withFitViews
32
+ .actions(self => ({
33
+ setError(error: unknown) {
34
+ self.error = error
35
+ self.isLoading = false
36
+ self.statusMessage = ''
37
+ },
38
+ finishLoading() {
39
+ self.isLoading = false
40
+ self.statusMessage = ''
41
+ },
42
+ setStatusMessage(message: string) {
43
+ self.statusMessage = message
44
+ },
45
+ setFetchMs(ms: number) {
46
+ self.lastFetchMs = ms
47
+ },
48
+ setLayoutMs(ms: number) {
49
+ self.lastLayoutMs = ms
50
+ },
51
+ setGeometryMetrics(
52
+ ms: number,
53
+ strokeCount: number,
54
+ built: { scale: number; bounds: Bounds },
55
+ ) {
56
+ self.lastGeometryMs = ms
57
+ self.lastGeometryStrokeCount = strokeCount
58
+ self.builtViewport = { ...built, viewportDirty: self.viewportDirty }
59
+ self.geometryVersion++
60
+ },
61
+ markPainted() {
62
+ self.paintedViewport = self.builtViewport
63
+ },
64
+ setLayoutQuality(quality: number) {
65
+ self.layoutQuality = quality
66
+ },
67
+ setLinearLayout(linear: boolean) {
68
+ self.linearLayout = linear
69
+ },
70
+ setLayoutMode(mode: LayoutModeValue) {
71
+ self.layoutMode = mode
72
+ },
73
+ // Re-anchor in place rather than re-parsing: the coordinate walk is
74
+ // already recorded on the graph, and only which path counts as rank 0
75
+ // changes. The caller recomputes the layout, the same way it does after
76
+ // setLayoutMode. An rGFA is left alone — its coordinates are not derived.
77
+ setReferencePath(name: string) {
78
+ self.referencePath = name
79
+ const graph = self.graph
80
+ if (graph?.anchoredBy === 'paths') {
81
+ const reanchored = anchorFromPaths(graph, name)
82
+ inheritForceLayouts(graph, reanchored)
83
+ self.graph = reanchored
84
+ }
85
+ },
86
+ setDrawPaths(draw: boolean) {
87
+ self.drawPaths = draw
88
+ },
89
+ setShowPerf(show: boolean) {
90
+ self.showPerf = show
91
+ },
92
+ setColorScheme(scheme: ColorScheme) {
93
+ self.colorScheme = scheme
94
+ },
95
+ setBubbleSpread(spread: BubbleSpread) {
96
+ self.bubbleSpread = spread
97
+ },
98
+ setNodeWidth(width: NodeWidth) {
99
+ self.nodeWidth = width
100
+ },
101
+ setShowBubbles(show: boolean) {
102
+ self.showBubbles = show
103
+ },
104
+ setShowDeletionEdges(show: boolean) {
105
+ self.showDeletionEdges = show
106
+ },
107
+ setShowGenes(show: boolean) {
108
+ self.showGenes = show
109
+ },
110
+ setShowReferenceStrip(show: boolean) {
111
+ self.showReferenceStrip = show
112
+ },
113
+ setTubeMapFold(bp: number) {
114
+ self.tubeMapFold = bp
115
+ },
116
+ setGeneTrackId(trackId: string) {
117
+ self.geneTrackId = trackId
118
+ },
119
+ setRepeatTrackId(trackId: string) {
120
+ self.repeatTrackId = trackId
121
+ },
122
+ setRepeatKey(key: string) {
123
+ self.repeatKey = key
124
+ },
125
+ setWalkLayers(layers: WalkLayer[]) {
126
+ self.walkLayers = layers
127
+ },
128
+ // Lift the walks named, in that order, keeping the colour any of them
129
+ // already had
130
+ liftWalks(names: string[]) {
131
+ const had = new Map(self.walkLayers.map(l => [l.walk, l]))
132
+ self.walkLayers = names.map(walk => had.get(walk) ?? { walk })
133
+ },
134
+ // The field the panels split on; a change of field drops the order
135
+ // written for the old one and keeps the column count
136
+ setFacet(field: FacetSetting['field']) {
137
+ if (field !== self.facet.field) {
138
+ self.facet.domain = []
139
+ }
140
+ self.facet.field = field
141
+ },
142
+ setFacetColumns(columns: number | undefined) {
143
+ self.facet.columns = columns
144
+ },
145
+ toggleWalk(walk: string) {
146
+ const layers = self.walkLayers
147
+ self.walkLayers = layers.some(l => l.walk === walk)
148
+ ? layers.filter(l => l.walk !== walk)
149
+ : [...layers, { walk }]
150
+ },
151
+ setWalkColor(walk: string, color: Partial<WalkEncoding>) {
152
+ self.walkLayers = self.walkLayers.map(l =>
153
+ l.walk === walk ? { ...l, color: { ...l.color, ...color } } : l,
154
+ )
155
+ },
156
+
157
+ // Undefined restores the built-in ceiling. Nothing recomputes: the pane
158
+ // reads canvasHeight and the drawing is placed by zoomToFit, which the
159
+ // caller runs if it wants the drawing refitted into the new pane.
160
+ setPaneHeight(px: number | undefined) {
161
+ self.paneHeight = px
162
+ },
163
+ setWalkRowSamples(samples: string[] | undefined) {
164
+ self.walkRowSamples = samples
165
+ },
166
+ // Pair with a linear view for the hover sync, without ever repointing an
167
+ // existing pairing: a graph launched *from* an LGV is already paired with
168
+ // it, and stealing that would break the sync the user came in on. So a
169
+ // launch out of the graph only claims the slot when it is empty.
170
+ //
171
+ // A slot naming a view that has been closed is empty too. Held, the view
172
+ // the graph opened next never got its hover, since a highlight is drawn
173
+ // only in the paired view.
174
+ pairWithLinearView(viewId: string) {
175
+ const paired = self.connectedViewId
176
+ const stillOpen =
177
+ paired !== undefined &&
178
+ withRows([...getSession(self).views]).some(
179
+ view => (view as { id?: unknown }).id === paired,
180
+ )
181
+ if (!stillOpen) {
182
+ self.connectedViewId = viewId
183
+ }
184
+ },
185
+ setHoveredNode(nodeId: string | null) {
186
+ self.hoveredNode = nodeId
187
+ },
188
+ setHoveredRowWalks(walks: string[]) {
189
+ if (walks.join('\n') !== self.hoveredRowWalks.join('\n')) {
190
+ self.hoveredRowWalks = walks
191
+ }
192
+ },
193
+ setHoveredBubble(bubble: MinigraphBubble | null) {
194
+ self.hoveredBubble = bubble
195
+ },
196
+ setPointerInPane(inside: boolean) {
197
+ self.pointerInPane = inside
198
+ },
199
+ setWalkStrip(show: boolean) {
200
+ self.walkStrip = show
201
+ self.stripHover = null
202
+ },
203
+ // The pointer over the strip: the node under it becomes the hovered
204
+ // node, so the drawing, the tooltip and a linked linear view follow
205
+ setStripHover(hover: { row: string; offset: number } | null) {
206
+ self.stripHover = hover
207
+ const bars = self.walkStripRows
208
+ const frame = self.walkStripFrame
209
+ const row =
210
+ hover && bars
211
+ ? [bars.reference, ...bars.rows].find(r => r.name === hover.row)
212
+ : undefined
213
+ const node =
214
+ row && frame && self.graph
215
+ ? segmentAt(self.graph, row, hover!.offset, frame.scaleX)
216
+ : undefined
217
+ self.hoveredNode = node ?? null
218
+ },
219
+ setLegendSize(size: { width: number; height: number }) {
220
+ self.legendSize = size
221
+ },
222
+ setHoveredEdge(edgeIdx: number | null) {
223
+ self.hoveredEdge = edgeIdx
224
+ },
225
+ setSelectedNode(nodeId: string | null) {
226
+ self.selectedNode = nodeId
227
+ },
228
+ setDraggingNode(nodeId: string | null) {
229
+ self.draggingNode = nodeId
230
+ },
231
+ setPanning(panning: boolean) {
232
+ self.isPanning = panning
233
+ },
234
+ stopDragging() {
235
+ self.draggingNode = null
236
+ self.isPanning = false
237
+ },
238
+ // Everything that names a part of the current graph. Reset when the graph
239
+ // is replaced, and by clearGraph.
240
+ clearInteractionState() {
241
+ self.hoveredNode = null
242
+ self.hoveredBubble = null
243
+ self.hoveredEdge = null
244
+ self.selectedNode = null
245
+ self.draggingNode = null
246
+ self.isPanning = false
247
+ },
248
+ showNodeDetails(nodeId: string) {
249
+ const node = self.nodeById?.get(nodeId)
250
+ const nodeById = self.nodeById
251
+ const neighbors = self.nodeNeighbors
252
+ if (node && nodeById && neighbors) {
253
+ const session = getSession(self)
254
+ const region = self.graphRegion
255
+ // refName/start/end are what makes the widget show a location rather
256
+ // than a bare id, and they are the same span the linear view
257
+ // highlights on hover.
258
+ const span = region
259
+ ? nodeReferenceSpan({ nodeId, nodeById, neighbors })
260
+ : undefined
261
+ if (isSessionModelWithWidgets(session)) {
262
+ session.showWidget(
263
+ session.addWidget('BaseFeatureWidget', 'baseFeature', {
264
+ featureData: {
265
+ id: node.id,
266
+ name: node.name,
267
+ length: node.length,
268
+ depth: node.depth,
269
+ rank: node.stable?.rank,
270
+ stableName: node.stable?.refName,
271
+ // The assembly that contributed this segment, split off the
272
+ // stable name. On an HPRC graph this is the only thing that
273
+ // says which of 400-odd haplotypes an allele came from.
274
+ contributingAssembly: nodeOwnLocation(node)?.sample,
275
+ // and the haplotype, where the graph's names state one:
276
+ // the assembly to load to open this node on its own
277
+ // coordinates
278
+ contributingHaplotype: nodeOwnLocation(node)?.haplotype,
279
+ // Every haplotype whose path visits it, which only a path
280
+ // GFA records. Absent on an rGFA, where
281
+ // `contributingAssembly` is the first-seen assembly alone.
282
+ sampleCount: node.samples?.length,
283
+ samples: node.samples,
284
+ ...(region && span
285
+ ? {
286
+ refName: region.refName,
287
+ assemblyName: region.assemblyName,
288
+ start: span.start,
289
+ end: span.end,
290
+ }
291
+ : {}),
292
+ },
293
+ }),
294
+ )
295
+ }
296
+ }
297
+ },
298
+
299
+ // A gesture on a hosted graph moves the linear view, and the frame
300
+ // clock brings x back here; y stays the pane's own.
301
+ setTransform(s: number, tx: number, ty: number) {
302
+ const { host } = self
303
+ if (self.viewportOwner === 'host' && host) {
304
+ host.horizontalScroll(self.translateX - tx)
305
+ } else {
306
+ self.viewportOwner = 'user'
307
+ self.scale = clampZoom(s)
308
+ self.translateX = tx
309
+ }
310
+ self.translateY = ty
311
+ },
312
+ zoom(factor: number, centerX: number, centerY: number) {
313
+ const { host } = self
314
+ if (self.viewportOwner === 'host' && host) {
315
+ host.zoomTo(host.bpPerPx / factor, centerX)
316
+ return
317
+ }
318
+ self.viewportOwner = 'user'
319
+ const t = zoomAbout(self, factor, centerX, centerY, self.pixelRows)
320
+ self.scale = t.scale
321
+ self.translateX = t.translateX
322
+ self.translateY = t.translateY
323
+ },
324
+ setViewportDirty() {
325
+ self.viewportRebuildPending = false
326
+ self.viewportDirty++
327
+ },
328
+ // The positions themselves moved, as opposed to the window onto them.
329
+ setPositionsDirty() {
330
+ self.positionsVersion++
331
+ },
332
+ zoomToFit() {
333
+ // A host owns x, so a fit while hosted places the rows only.
334
+ if (self.viewportOwner === 'host') {
335
+ const bounds = self.layoutBounds
336
+ const faceted = self.facetGrid !== undefined
337
+ const pad = faceted ? FACET_PAD_PX : FIT_PADDING
338
+ const padTop = faceted ? FACET_PAD_PX : self.fitPadTop
339
+ const usableHeight = self.viewBox.height - padTop - pad
340
+ if (bounds && usableHeight > 0) {
341
+ self.translateY = fittedTranslateY(
342
+ bounds,
343
+ usableHeight,
344
+ self.scaleY,
345
+ padTop,
346
+ )
347
+ }
348
+ return
349
+ }
350
+ // Nothing to fit into before the canvas is measured. The fit autorun
351
+ // runs again once width lands, so skipping beats persisting a negative
352
+ // scale into the session snapshot.
353
+ const fit = self.fittedTransform
354
+ if (fit) {
355
+ self.scale = fit.scale
356
+ self.translateX = fit.translateX
357
+ self.translateY = fit.translateY
358
+ }
359
+ },
360
+ clearPerfMetrics() {
361
+ self.lastFetchMs = undefined
362
+ self.lastLayoutMs = undefined
363
+ self.lastGeometryMs = undefined
364
+ self.lastGeometryStrokeCount = undefined
365
+ self.builtViewport = undefined
366
+ },
367
+ }))
368
+ .actions(self => ({
369
+ // The frame clock. Unclamped, since clampZoom's floor is there to keep a
370
+ // scale finite and 1 / bpPerPx already is; clamped, a whole-chromosome
371
+ // window would stop lining up.
372
+ hostTransform(scale: number, translateX: number) {
373
+ const engaging = self.viewportOwner !== 'host'
374
+ if (engaging) {
375
+ self.viewportOwner = 'host'
376
+ }
377
+ self.scale = scale
378
+ self.translateX = translateX
379
+ if (engaging) {
380
+ self.zoomToFit()
381
+ }
382
+ },
383
+ // Faceting changes the box the drawing is fitted into, so a drawing the
384
+ // user placed is fitted again; a host keeps its x
385
+ refitView() {
386
+ if (self.viewportOwner === 'user') {
387
+ self.viewportOwner = 'fit'
388
+ }
389
+ self.zoomToFit()
390
+ },
391
+ // A drawing still on the reference stays where the host left it; one
392
+ // whose x no longer means bp is refit.
393
+ releaseHost() {
394
+ if (self.viewportOwner === 'host') {
395
+ if (self.xIsReferenceBp) {
396
+ self.viewportOwner = 'user'
397
+ } else {
398
+ self.viewportOwner = 'fit'
399
+ self.zoomToFit()
400
+ }
401
+ }
402
+ },
403
+ }))
404
+ .actions(self => {
405
+ // Pan/zoom can wait: the geometry on screen is still correct while the
406
+ // gesture runs (the viewport bounds carry 20% overscan), so rebuilding is
407
+ // deferred until the user settles.
408
+ function scheduleViewportDirty() {
409
+ clearTimeout(self.viewportDirtyTimer)
410
+ self.viewportRebuildPending = true
411
+ self.viewportDirtyTimer = setTimeout(() => {
412
+ if (isAlive(self)) {
413
+ self.setViewportDirty()
414
+ }
415
+ }, VIEWPORT_DEBOUNCE_MS)
416
+ }
417
+
418
+ // A node drag cannot wait — the node only moves on screen when its
419
+ // geometry is rebuilt — but a bump costs a full geometry rebuild plus
420
+ // invalidation of both hit-detection indexes, and mousemove fires in
421
+ // bursts well above the frame rate. Coalescing to the next frame keeps the
422
+ // drag live while bounding that work to once per frame instead of once
423
+ // per event.
424
+ function requestPositionsDirtyFrame() {
425
+ cancelAnimationFrame(self.positionsDirtyFrame)
426
+ self.positionsDirtyFrame = requestAnimationFrame(() => {
427
+ if (isAlive(self)) {
428
+ self.setPositionsDirty()
429
+ }
430
+ })
431
+ }
432
+
433
+ return {
434
+ // Moves the position objects IN PLACE, which is the one thing
435
+ // jbrowse-components' upload invariant says not to do ("per-region
436
+ // upload values must be freshly constructed, never mutated — backends
437
+ // diff by reference identity"), so it is worth saying why this is not
438
+ // that case and what it costs instead.
439
+ //
440
+ // Nothing here diffs by identity: the geometry is rebuilt wholesale and
441
+ // handed over as one batch, so `nodePositions` identity is not a
442
+ // protocol between the model and the backend the way a per-region map
443
+ // is. What identity DOES drive is the fit: the zoom-to-fit autorun and
444
+ // `layoutBounds` — and so `canvasHeight` — key off `layoutResult`, and
445
+ // they mean "a new LAYOUT arrived", not "a node moved". Publishing a
446
+ // fresh positions record per frame of a drag would refit the drawing
447
+ // and resize the pane under the cursor, sixty times a second.
448
+ //
449
+ // So the change is announced by `positionsVersion` instead, and every
450
+ // cache that would otherwise trust identity takes it as a key. The cost
451
+ // of that trade is that the version is a thing to remember: a caller
452
+ // that mutates here and does not bump it gets stale curves, stale hit
453
+ // boxes and stale labels, silently. Everything downstream of it is
454
+ // reached from this one action.
455
+ moveNode(nodeId: string, dx: number, dy: number) {
456
+ const positions = self.layoutResult?.nodePositions
457
+ if (positions?.[nodeId]) {
458
+ for (const seg of positions[nodeId]) {
459
+ seg.x += dx
460
+ seg.y += dy
461
+ }
462
+ requestPositionsDirtyFrame()
463
+ }
464
+ },
465
+ scheduleViewportDirty,
466
+ }
467
+ })
@@ -0,0 +1,205 @@
1
+ import { ROW_HEIGHT_PX } from '@jbrowse/bandage-core/layout/rowSpacing'
2
+ import {
3
+ BAR_PX as WALK_BAR_PX,
4
+ placeRowGenes,
5
+ rowSpan,
6
+ } from '@jbrowse/bandage-core/layout/walkRowDraw'
7
+ import { filterSamples } from '@jbrowse/bandage-core/layout/walkRows'
8
+ import {
9
+ stripMarks,
10
+ walkStripFrame,
11
+ } from '@jbrowse/bandage-core/layout/walkStrip'
12
+ import { layoutModeByValue } from '@jbrowse/bandage-core/layoutModes'
13
+ import { nodeAnchor } from '@jbrowse/bandage-core/referenceStrip'
14
+
15
+ import { withLaunchViews } from './launchViews'
16
+ import { WALK_GENE_ROWS } from './paneBase'
17
+ import { resolveLocationAssembly } from '../../launchFromGraph/contributors'
18
+
19
+ import type { SubgraphRegion } from '../../GetSubgraph'
20
+
21
+ export const withWalkRowViews = withLaunchViews
22
+ .views(self => ({
23
+ // Whether the strip of walk rows sits under the drawing: asked for, on a
24
+ // standalone view whose layout draws nodes, for a graph with walks, and
25
+ // not while a bubble is popped
26
+ get walkStripShown() {
27
+ return (
28
+ self.walkStrip &&
29
+ !self.host &&
30
+ self.modeDrawsNodes &&
31
+ !self.layoutResult?.tubeMap &&
32
+ !self.walkRowBars &&
33
+ self.popStack.length === 0 &&
34
+ (self.graph?.paths?.length ?? 0) > 1
35
+ )
36
+ },
37
+ // The strip's rows: the cut's, with the sample filter and no repeat
38
+ // pick, which the Repeat menu only offers in walk rows
39
+ get walkStripRows() {
40
+ const bars = this.walkStripShown ? self.cutWalkRows : undefined
41
+ return bars
42
+ ? { ...bars, rows: filterSamples(bars.rows, self.walkRowSamples) }
43
+ : undefined
44
+ },
45
+ get walkStripFrame() {
46
+ const bars = this.walkStripRows
47
+ if (!bars) {
48
+ return undefined
49
+ }
50
+ return walkStripFrame(bars, { width: self.paneWidth })
51
+ },
52
+ // Whether a cut must follow every snarl a walk leaves the window by, so
53
+ // walks come back whole: walk rows measure them, and so does the strip
54
+ get cutsWholeWalks() {
55
+ return (
56
+ layoutModeByValue(self.chosenLayoutMode).wholeWalks ||
57
+ (self.walkStrip && !self.host)
58
+ )
59
+ },
60
+ // Where each walk passes the hovered node, or the selected one
61
+ get walkStripMarks() {
62
+ const bars = this.walkStripRows
63
+ const id = self.hoveredNode ?? self.selectedNode
64
+ const node = id === null ? undefined : self.nodeById?.get(id)
65
+ return bars && node && self.graph
66
+ ? stripMarks(self.graph, [bars.reference, ...bars.rows], node)
67
+ : []
68
+ },
69
+ // Where the drawing has the node a strip point lights, for the ring
70
+ // that finds it in a hairball
71
+ get walkStripLocator() {
72
+ const id = self.stripHover ? self.hoveredNode : null
73
+ return id === null
74
+ ? undefined
75
+ : nodeAnchor(self.nodePositions?.[id], p => ({
76
+ x: p.x * self.scaleX + self.translateX,
77
+ y: p.y * self.scaleY + self.translateY,
78
+ }))
79
+ },
80
+ }))
81
+ .views(self => ({
82
+ // The gene reads walk rows need, as the layout or the strip: for each row whose haplotype
83
+ // (`HG00097#1`) names an assembly with a gene track, that track over the
84
+ // span of its own contig the row's bar covers. The first WALK_GENE_ROWS
85
+ // such rows are read, and the rest counted for the key.
86
+ get walkGeneReads() {
87
+ const bars = self.walkRowBars ?? self.walkStripRows
88
+ if (!bars || !self.showGenes) {
89
+ return undefined
90
+ }
91
+ const reads: {
92
+ row: string
93
+ trackId: string
94
+ region: SubgraphRegion
95
+ }[] = []
96
+ let untrackedRows = 0
97
+ let unplaced = 0
98
+ for (const row of bars.rows) {
99
+ if (!row.axis) {
100
+ unplaced++
101
+ continue
102
+ }
103
+ const assemblyName = resolveLocationAssembly(self.assemblyResolver, {
104
+ sample: row.sample,
105
+ haplotype:
106
+ row.haplotype === undefined
107
+ ? undefined
108
+ : `${row.sample}#${row.haplotype}`,
109
+ })
110
+ const track = assemblyName
111
+ ? self.geneTracksByAssembly.get(assemblyName)
112
+ : undefined
113
+ if (!assemblyName || !track) {
114
+ untrackedRows++
115
+ continue
116
+ }
117
+ reads.push({
118
+ row: row.name,
119
+ trackId: track.trackId,
120
+ region: {
121
+ assemblyName,
122
+ refName: row.axis.contig,
123
+ ...rowSpan(row.axis, row.bp),
124
+ },
125
+ })
126
+ }
127
+ return {
128
+ reads: reads.slice(0, WALK_GENE_ROWS),
129
+ gaps: {
130
+ untracked: untrackedRows,
131
+ unplaced,
132
+ unread: Math.max(0, reads.length - WALK_GENE_ROWS),
133
+ },
134
+ }
135
+ },
136
+ get walkRowGeneGaps() {
137
+ return this.walkGeneReads?.gaps
138
+ },
139
+ // The walk row under a pane point, as its index among the reference row
140
+ // and the rows below it, where the point is on its bar
141
+ walkRowAt(screenX: number, screenY: number) {
142
+ const bars = self.walkRowBars
143
+ if (!bars) {
144
+ return undefined
145
+ }
146
+ const i = Math.round(
147
+ (screenY - self.translateY) / (ROW_HEIGHT_PX * self.scaleY),
148
+ )
149
+ const row = [bars.reference, ...bars.rows][i]
150
+ const y = i * ROW_HEIGHT_PX * self.scaleY + self.translateY
151
+ const bp = (screenX - self.translateX) / self.scaleX - bars.origin
152
+ return row &&
153
+ Math.abs(screenY - y) <= WALK_BAR_PX / 2 + 2 &&
154
+ bp >= 0 &&
155
+ bp <= row.bp
156
+ ? i
157
+ : undefined
158
+ },
159
+ // Where a walk row's bar lies in its own assembly, for a linear view to
160
+ // open: the span of its contig the bar covers, on the session assembly
161
+ // its haplotype names (the cut's own assembly for the reference row).
162
+ // The label names the haplotype when no assembly is loaded for it.
163
+ walkRowLaunchTarget(index: number, bars = self.walkRowBars) {
164
+ const row = bars ? [bars.reference, ...bars.rows][index] : undefined
165
+ if (!row?.axis) {
166
+ return undefined
167
+ }
168
+ const haplotype =
169
+ row.haplotype === undefined
170
+ ? undefined
171
+ : `${row.sample}#${row.haplotype}`
172
+ const assembly =
173
+ index === 0
174
+ ? self.graphRegion?.assemblyName
175
+ : resolveLocationAssembly(self.assemblyResolver, {
176
+ sample: row.sample,
177
+ haplotype,
178
+ })
179
+ return {
180
+ label: row.label,
181
+ assembly,
182
+ location: {
183
+ sample: row.sample,
184
+ haplotype,
185
+ refName: row.axis.contig,
186
+ ...rowSpan(row.axis, row.bp),
187
+ },
188
+ }
189
+ },
190
+ // Each row's genes as offsets along its bar: the reference row's from
191
+ // the backbone's gene track, every other row's from its own assembly
192
+ get walkRowGenes() {
193
+ const bars = self.walkRowBars ?? self.walkStripRows
194
+ if (!bars || !self.showGenes) {
195
+ return undefined
196
+ }
197
+ const byRow = new Map(self.walkGeneFeatures ?? [])
198
+ if (self.geneFeatures) {
199
+ byRow.set(bars.reference.name, self.geneFeatures)
200
+ }
201
+ return byRow.size
202
+ ? placeRowGenes([bars.reference, ...bars.rows], byRow)
203
+ : undefined
204
+ },
205
+ }))