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,829 @@
1
+ import { bubbleHalos } from '@jbrowse/bandage-core/bubbles/bubbleHalos'
2
+ import { bubblesFromGraph } from '@jbrowse/bandage-core/bubbles/bubblesFromGraph'
3
+ import { resolveColorScheme } from '@jbrowse/bandage-core/colorSchemes'
4
+ import { deletionEdges } from '@jbrowse/bandage-core/deletionEdges'
5
+ import { genePins } from '@jbrowse/bandage-core/genes/genePins'
6
+ import { rowLabelBox } from '@jbrowse/bandage-core/graphLabels'
7
+ import { ROW_HEIGHT_PX } from '@jbrowse/bandage-core/layout/rowSpacing'
8
+ import { walkRowsExtent } from '@jbrowse/bandage-core/layout/walkRowLayout'
9
+ import { filterSamples, walkRows } from '@jbrowse/bandage-core/layout/walkRows'
10
+ import {
11
+ layoutModeByValue,
12
+ modeUsesLayoutEngine,
13
+ } from '@jbrowse/bandage-core/layoutModes'
14
+ import { nodeInk } from '@jbrowse/bandage-core/nodeWidths'
15
+ import {
16
+ pathColorsLegible,
17
+ pathGreyCssColor,
18
+ pathLegend,
19
+ } from '@jbrowse/bandage-core/pathColors'
20
+ import { FIT_PADDING, drawingBounds } from '@jbrowse/bandage-core/pipeline'
21
+ import {
22
+ backboneAssembly,
23
+ featuresOnBackbone,
24
+ graphBackbone,
25
+ } from '@jbrowse/bandage-core/reference'
26
+ import {
27
+ buildNeighbors,
28
+ nodeReferenceSpan,
29
+ } from '@jbrowse/bandage-core/referenceSpan'
30
+ import {
31
+ LIFT_BACKDROP_CSS,
32
+ computeReferenceRamp,
33
+ } from '@jbrowse/bandage-core/renderer/GeometryBuilder'
34
+ import { tubeMapNodeColors } from '@jbrowse/bandage-core/tubeMap/nodeColors'
35
+ import { axisScaleOf } from '@jbrowse/bandage-core/viewport'
36
+ import { NO_VALUE_COLOR } from '@jbrowse/bandage-core/walkEncoding'
37
+ import { facetLifts, walkLift } from '@jbrowse/bandage-core/walkHighlight'
38
+ import { readConfObject } from '@jbrowse/core/configuration'
39
+ import {
40
+ getContainingTrack,
41
+ getContainingView,
42
+ getSession,
43
+ } from '@jbrowse/core/util'
44
+
45
+ import { TUBE_MAP_MODES, dependOn, geometryPainted, paneBase } from './paneBase'
46
+ import { GENE_ADAPTER_TYPES, pickGeneTrack } from '../genes/geneFeatures'
47
+ import {
48
+ REPEAT_ADAPTER_TYPES,
49
+ pickRepeatTrack,
50
+ } from '../repeats/repeatFeatures'
51
+ import { withCalls } from '../repeats/walkCalls'
52
+
53
+ import type {
54
+ ColorScheme,
55
+ ResolvedColorScheme,
56
+ } from '@jbrowse/bandage-core/colorSchemes'
57
+ import type { LayoutModeValue } from '@jbrowse/bandage-core/layoutModes'
58
+ import type { AssemblyNames } from '@jbrowse/bandage-core/reference'
59
+ import type { GraphNode } from '@jbrowse/bandage-core/types'
60
+ import type { NodeInk } from '@jbrowse/bandage-core/util/hitDetection'
61
+ import type { WalkLayer } from '@jbrowse/bandage-core/walkEncoding'
62
+ import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
63
+ import type { FileLocation } from '@jbrowse/core/util/types'
64
+
65
+ export const withGraphViews = paneBase
66
+ .views(self => ({
67
+ get defaultLayoutMode(): LayoutModeValue {
68
+ return 'force'
69
+ },
70
+ get defaultColorScheme(): ColorScheme {
71
+ return 'auto'
72
+ },
73
+ // a source declared but not yet loaded
74
+ get hasPendingSource() {
75
+ return false
76
+ },
77
+ get canRetryLoad() {
78
+ return false
79
+ },
80
+ // the track the graph is cut from: the one the pane is a display of
81
+ get sourceTrack(): AnyConfigurationModel | undefined {
82
+ try {
83
+ return getContainingTrack(self).configuration
84
+ } catch {
85
+ return undefined
86
+ }
87
+ },
88
+ }))
89
+ .views(self => ({
90
+ get chosenLayoutMode() {
91
+ return self.layoutMode ?? self.defaultLayoutMode
92
+ },
93
+ get chosenColorScheme() {
94
+ return self.colorScheme ?? self.defaultColorScheme
95
+ },
96
+ }))
97
+ .views(self => ({
98
+ get paneWidth() {
99
+ return getContainingView(self).width
100
+ },
101
+ // The graph the drawing's node ids address: a folded tube map's coarse
102
+ // graph, the cut otherwise. Hover, details and labels read it, so a
103
+ // merged node reports its own span and length.
104
+ get drawnGraph() {
105
+ return self.layoutResult?.tubeMap?.coarse?.graph ?? self.graph
106
+ },
107
+ }))
108
+ .views(self => ({
109
+ get nodeById() {
110
+ if (self.drawnGraph) {
111
+ const m = new Map<string, GraphNode>()
112
+ for (const n of self.drawnGraph.nodes) {
113
+ m.set(n.id, n)
114
+ }
115
+ return m
116
+ }
117
+ return undefined
118
+ },
119
+ // bp per node id, which is all the label overlay needs of a GraphNode.
120
+ // Held here rather than rebuilt in the component: that render runs on
121
+ // every pan, and the map is a fact about the graph (measured 6.9 ms an
122
+ // allocation on a 30k-node cut).
123
+ get nodeLengths() {
124
+ const m = new Map<string, number>()
125
+ for (const n of self.drawnGraph?.nodes ?? []) {
126
+ m.set(n.id, n.length)
127
+ }
128
+ return m
129
+ },
130
+ get nodeCount() {
131
+ return self.graph?.nodes.length ?? 0
132
+ },
133
+ get edgeCount() {
134
+ return self.graph?.edges.length ?? 0
135
+ },
136
+ get pathCount() {
137
+ return self.graph?.paths?.length ?? 0
138
+ },
139
+ get hasGraph() {
140
+ return self.graph !== undefined
141
+ },
142
+ get geometryPainted() {
143
+ return geometryPainted(self)
144
+ },
145
+ // The app-wide readiness contract (AppReadyMarker, @jbrowse/capture)
146
+ // reads this: a declared source still fetching, or a graph whose
147
+ // settled geometry is not on the canvas yet.
148
+ get showLoading() {
149
+ return (
150
+ self.error === undefined &&
151
+ (self.isLoading ||
152
+ self.hasPendingSource ||
153
+ (self.graph !== undefined && !geometryPainted(self)))
154
+ )
155
+ },
156
+ // Only before anything is drawn: past that point a reload is superseded
157
+ // by the next setting change, and stopping one midway would leave a new
158
+ // graph under the previous graph's layout.
159
+ get canCancelLoad() {
160
+ return self.isLoading && !self.layoutResult
161
+ },
162
+ // Whether the drawing on screen is the FMMM engine's. False before there
163
+ // is a graph, since nothing is drawn by anything yet.
164
+ //
165
+ // Read by the settings that only the engine looks at: the layout quality
166
+ // and the bubble spread do nothing at all to an anchored drawing, which
167
+ // places a node from its coordinates, and the guide says so in prose
168
+ // precisely because the dialog did not. A control that silently does
169
+ // nothing is worse than one that says it cannot — the same rule the
170
+ // `drawPaths` switch already follows.
171
+ get usesLayoutEngine() {
172
+ return self.graph
173
+ ? modeUsesLayoutEngine(self.chosenLayoutMode, self.graph)
174
+ : false
175
+ },
176
+ // A rank-0 backbone to draw x against, whether the segments declared it
177
+ // (rGFA) or a path walk derived it. Only a GFA with neither tags nor
178
+ // paths has no backbone at all, and there force is the one honest layout.
179
+ get canAnchorLayout() {
180
+ return self.graph?.nodes.some(n => n.stable?.rank === 0) ?? false
181
+ },
182
+ // The paths this graph could be anchored on, for the picker. Empty for an
183
+ // rGFA, which has no P/W records and needs none.
184
+ get anchorPaths() {
185
+ return self.graph?.anchorPaths ?? []
186
+ },
187
+ // Every walk the graph carries, named for a picker, whatever the count.
188
+ get walkChoices() {
189
+ const paths = self.graph?.paths
190
+ return paths?.length ? pathLegend(paths) : []
191
+ },
192
+ // Whether the drawing is actually painted per path, which is not the same
193
+ // question as whether the user asked for it: past MAX_PATH_COLORS the
194
+ // colours say nothing and cost a stroke per path per edge. A bare getter
195
+ // returning a resolved value, the same shape and for the same reason as
196
+ // `effectiveColorScheme` — every consumer of a path colour reads this
197
+ // one, so the geometry, the hit index and the key cannot disagree about
198
+ // whether there are any. The switch in the settings dialog reads the raw
199
+ // `drawPaths`, so the user's choice stays visible as the choice it is.
200
+ get effectiveDrawPaths() {
201
+ return self.drawPaths && pathColorsLegible(self.graph?.paths?.length ?? 0)
202
+ },
203
+ // The path x is currently drawn on, which is not necessarily the one
204
+ // `referencePath` asked for: an unmatched name falls back rather than
205
+ // leaving the graph unanchored, and the picker has to show what happened.
206
+ get activeReferencePath() {
207
+ return self.graph?.referencePath
208
+ },
209
+ // Undefined for a graph with neither, where the ramp spans the drawn
210
+ // extent (computeReferenceRamp)
211
+ get rampDomain() {
212
+ return self.colorDomain ?? self.graphRegion
213
+ },
214
+ // The ramp a lane coloured by reference position reads, computed only
215
+ // when a layer asks for one: it is a neighbour walk per node
216
+ get walkRamp() {
217
+ const { graph } = self
218
+ return graph &&
219
+ self.walkLayers.some(layer => layer.color?.field === 'reference')
220
+ ? computeReferenceRamp(graph, this.rampDomain)
221
+ : undefined
222
+ },
223
+ // Whether the chosen layout draws the graph's nodes, which a facet
224
+ // splits and a hovered lane row's walk is lifted over
225
+ get modeDrawsNodes() {
226
+ return layoutModeByValue(self.chosenLayoutMode).drawsNodes
227
+ },
228
+ // The walks picked, or while none is, those of the lane row hovered
229
+ get liftedWalkLayers(): WalkLayer[] {
230
+ return self.walkLayers.length > 0 || !this.modeDrawsNodes
231
+ ? self.walkLayers
232
+ : self.hoveredRowWalks.map(walk => ({ walk }))
233
+ },
234
+ // The lifted walks the graph on screen carries, or undefined when none
235
+ // is named or it carries none of those that were
236
+ get walkLift() {
237
+ const { graph } = self
238
+ const layers = this.liftedWalkLayers
239
+ return graph && layers.length > 0 && !self.layoutResult?.tubeMap
240
+ ? walkLift(graph, layers, this.walkRamp)
241
+ : undefined
242
+ },
243
+ // One panel per lifted walk while the pane is faceted by walk, each a
244
+ // lift of that walk alone, on a layout whose nodes the panels can split.
245
+ // See facetLifts.
246
+ get facetPanels() {
247
+ const { graph } = self
248
+ const lift = this.walkLift
249
+ return self.facet.field !== '' &&
250
+ this.modeDrawsNodes &&
251
+ graph &&
252
+ lift &&
253
+ self.walkLayers.length > 1 &&
254
+ lift.walks.length > 1
255
+ ? facetLifts(graph, lift, self.walkLayers, this.walkRamp)
256
+ : undefined
257
+ },
258
+ // The lifted walks as drawn, each panel's own while faceted
259
+ get drawnWalks() {
260
+ return (
261
+ this.facetPanels?.map(panel => panel.walks[0]!) ??
262
+ this.walkLift?.walks ??
263
+ []
264
+ )
265
+ },
266
+ // A tube map draws every walk as a tube of its own
267
+ get liftsWalks() {
268
+ return !TUBE_MAP_MODES.has(self.chosenLayoutMode)
269
+ },
270
+ // The window a lane coloured by reference position spans, by name
271
+ get walkReference() {
272
+ const domain = this.walkLift?.referenceDomain
273
+ return domain && { ...domain, name: self.graphRegion?.refName }
274
+ },
275
+ walkLabel(name: string) {
276
+ return this.walkChoices.find(c => c.name === name)?.label ?? name
277
+ },
278
+ // Whether a lifted lane paints a node charcoal, the colour a lane coloured
279
+ // by reference position gives what is off the reference
280
+ get liftPaintsOffReference() {
281
+ for (const w of this.walkLift?.walks ?? []) {
282
+ if (w.encoding.field !== 'walk') {
283
+ for (const color of w.colors.values()) {
284
+ if (color === NO_VALUE_COLOR) {
285
+ return true
286
+ }
287
+ }
288
+ }
289
+ }
290
+ return false
291
+ },
292
+ // what the faded rest of the drawing is not on
293
+ get liftedWalksLabel() {
294
+ const walks = this.walkLift?.walks ?? []
295
+ return walks.length === 1 ? this.walkLabel(walks[0]!.name) : 'these walks'
296
+ },
297
+ // The scheme the renderer actually paints with, which is the raw prop
298
+ // unless it is 'auto'. A bare getter returns a resolved value (root
299
+ // CLAUDE.md): every consumer of a colour reads this one, and the two
300
+ // dropdowns read `colorScheme` so "Auto" stays visible as the choice it
301
+ // is.
302
+ //
303
+ // 'auto' asks the GRAPH, not the layout. A hue along the reference is
304
+ // meaningful whenever the segments have reference coordinates —
305
+ // `anchoredBy` is exactly that question — and a force-directed drawing of
306
+ // an rGFA is the case that proves it: the layout has no reference axis and
307
+ // the ramp still says where on the reference each node came from, which is
308
+ // the only quantity a linear track beside it can be painted with too.
309
+ //
310
+ // A tube map tells its paths apart by their tubes' hues, so there 'auto'
311
+ // leaves the boxes clear and a node scheme is the user's pick. Beside
312
+ // reads, which take the reds and the blues, the boxes stay clear
313
+ // whatever was picked.
314
+ get effectiveColorScheme(): ResolvedColorScheme {
315
+ return self.layoutResult?.tubeMap &&
316
+ (this.tubeMapReads || self.chosenColorScheme === 'auto')
317
+ ? 'uniform'
318
+ : resolveColorScheme(self.chosenColorScheme, self.graph)
319
+ },
320
+ get tubeMapReads() {
321
+ return (self.layoutResult?.tubeMap?.layout.reads.length ?? 0) > 0
322
+ },
323
+ // Why no node scheme is on screen to pick, for every control that
324
+ // offers one: lifted walks colour their own lanes and grey the rest,
325
+ // and reads take a tube map's reds and blues
326
+ get colorSchemeLock() {
327
+ return this.walkLift
328
+ ? {
329
+ value: 'By walk',
330
+ why: 'Each lifted walk colours its own lane: set it under the menu, Walk, Colour',
331
+ }
332
+ : this.tubeMapReads
333
+ ? {
334
+ value: 'By strand',
335
+ why: 'Reads take the reds and blues, so the tube map leaves its nodes clear',
336
+ }
337
+ : undefined
338
+ },
339
+ get nodePositions() {
340
+ return self.layoutResult?.nodePositions
341
+ },
342
+ // a length label would sit on the lanes of lifted walks
343
+ get labelsNodeSizes() {
344
+ return !self.layoutResult?.tubeMap && !this.walkLift
345
+ },
346
+ // Empty rather than undefined: every consumer maps over it, and a layout
347
+ // with no row structure (FMMM) is a normal state, not a missing one.
348
+ get rowLabels() {
349
+ return self.layoutResult?.rowLabels ?? []
350
+ },
351
+ // Deletions the layout found inside an allele, empty for the same reason
352
+ // rowLabels is: a layout drawn at sequence scale states none, because
353
+ // there a node's drawn extent already IS its length. `deletions` beside
354
+ // this one is the bare-edge kind, which every layout has.
355
+ get alleleDeletions() {
356
+ return self.layoutResult?.alleleDeletions ?? []
357
+ },
358
+ get deletionRoutes() {
359
+ return self.layoutResult?.deletionRoutes
360
+ },
361
+ // Whether the current layout states y in screen px rather than in the same
362
+ // units as x (LayoutResult.pixelRows). Everything that has to put the two
363
+ // axes in one expression reads this through scaleX/scaleY.
364
+ get pixelRows() {
365
+ return self.layoutResult?.pixelRows ?? false
366
+ },
367
+ get zoomPercent() {
368
+ return `${(self.scale * 100).toFixed(1)}%`
369
+ },
370
+ // True while the persisted transform is still the schema default, i.e.
371
+ // neither a restored session nor the user has positioned this view yet,
372
+ // so an incoming layout is free to zoom-to-fit.
373
+ get isDefaultViewport() {
374
+ return self.scale === 1 && self.translateX === 0 && self.translateY === 0
375
+ },
376
+ }))
377
+ .views(self => ({
378
+ get poppedFrom() {
379
+ return self.popStack.at(-1)
380
+ },
381
+ // The bubbles the graph itself states, for a graph with no index: a GBZ
382
+ // cut, a pggb file, the inside of a popped bubble.
383
+ get derivedBubbles() {
384
+ return self.graph ? bubblesFromGraph(self.graph) : []
385
+ },
386
+ }))
387
+ .views(self => ({
388
+ // The bubbles halos draw and pops open. Index rows win where both exist:
389
+ // gfatools measured every allele, the layered order only bounds them.
390
+ get bubbles() {
391
+ return self.indexBubbles?.length ? self.indexBubbles : self.derivedBubbles
392
+ },
393
+ }))
394
+ .views(self => ({
395
+ // the haplotypes the graph on screen was cut for, where a host says
396
+ get cutHaplotypes(): string[] | undefined {
397
+ return undefined
398
+ },
399
+ // the GFA the graph on screen was read from, where a host says
400
+ get sourceGfaLocation(): FileLocation | undefined {
401
+ return undefined
402
+ },
403
+ get sourceAdapter() {
404
+ const track = self.sourceTrack
405
+ return track
406
+ ? (readConfObject(track, 'adapter') as Record<string, unknown>)
407
+ : undefined
408
+ },
409
+ get sourceTrackId() {
410
+ const track = self.sourceTrack
411
+ return track ? (readConfObject(track, 'trackId') as string) : undefined
412
+ },
413
+ get assemblyTrackChoices() {
414
+ const region = self.graphRegion
415
+ if (!region) {
416
+ return []
417
+ }
418
+ return getSession(self)
419
+ .tracks.filter(t =>
420
+ (readConfObject(t, 'assemblyNames') as string[]).includes(
421
+ region.assemblyName,
422
+ ),
423
+ )
424
+ .map(t => ({
425
+ trackId: t.trackId as string,
426
+ name: readConfObject(t, 'name') as string,
427
+ adapterType: (readConfObject(t, 'adapter') as { type: string }).type,
428
+ }))
429
+ },
430
+ }))
431
+ .views(self => ({
432
+ get geneTrackChoices() {
433
+ return self.assemblyTrackChoices.filter(t =>
434
+ GENE_ADAPTER_TYPES.has(t.adapterType),
435
+ )
436
+ },
437
+ // The session's feature tracks a repeat annotation could be, for the
438
+ // picker; which one is read is pickRepeatTrack's choice.
439
+ get repeatTrackChoices() {
440
+ return self.assemblyTrackChoices.filter(t =>
441
+ REPEAT_ADAPTER_TYPES.has(t.adapterType),
442
+ )
443
+ },
444
+ // The arrays over the window that state a unit, for the Repeat picker.
445
+ get repeatChoices() {
446
+ return self.repeatArrays ?? []
447
+ },
448
+ }))
449
+ .views(self => ({
450
+ get repeatTrack() {
451
+ return pickRepeatTrack(self.repeatTrackChoices, self.repeatTrackId)
452
+ },
453
+ get selectedRepeat() {
454
+ return self.repeatChoices.find(r => r.key === self.repeatKey)
455
+ },
456
+ get backbone() {
457
+ return self.graph ? graphBackbone(self.graph) : undefined
458
+ },
459
+ // Each walk sliced to the window, for walk rows and the strip; a repeat
460
+ // pick slices again by its own array
461
+ get cutWalkRows() {
462
+ return self.graph ? walkRows(self.graph, self.graphRegion) : undefined
463
+ },
464
+ // An assembly by each name a backbone may spell it with: the session's
465
+ // name and aliases, and the PanSN prefix the source track maps each of
466
+ // those to.
467
+ assemblySpellings(assemblyName: string): AssemblyNames {
468
+ const { assemblyManager } = getSession(self)
469
+ const assembly = assemblyManager.has(assemblyName)
470
+ ? assemblyManager.get(assemblyName)
471
+ : undefined
472
+ const panSN = (self.sourceAdapter?.assemblyNameToPanSN ?? {}) as Record<
473
+ string,
474
+ string
475
+ >
476
+ const names = [
477
+ assemblyName,
478
+ ...(assembly ? [assembly.name, ...assembly.aliases] : []),
479
+ ]
480
+ return {
481
+ name: assemblyName,
482
+ aliases: [...names, ...names.flatMap(n => panSN[n] ?? [])],
483
+ }
484
+ },
485
+ // Whether x lies along the reference the track's graph came with, not a
486
+ // walk "Draw x along" picked. An rGFA's backbone is fixed.
487
+ get drawsLoadedReference() {
488
+ const graph = self.graph
489
+ return (
490
+ graph?.anchoredBy === 'tags' ||
491
+ (graph?.referencePath !== undefined &&
492
+ graph.referencePath === self.loadedReferencePath)
493
+ )
494
+ },
495
+ }))
496
+ .views(self => ({
497
+ // the assembly the genes were read for
498
+ get geneAssembly() {
499
+ const region = self.graphRegion
500
+ return region ? self.assemblySpellings(region.assemblyName) : undefined
501
+ },
502
+ }))
503
+ .views(self => ({
504
+ // The genes on the drawn backbone under its own refNames. The track's
505
+ // config puts its reference on the cut's assembly, whatever the walk's
506
+ // name. After "Draw x along" another walk, the backbone takes the genes
507
+ // only where its PanSN prefix names their assembly.
508
+ get backboneGenes() {
509
+ const { backbone, geneAssembly, geneFeatures } = self
510
+ const binds =
511
+ self.drawsLoadedReference ||
512
+ (geneAssembly !== undefined &&
513
+ backboneAssembly(backbone, [geneAssembly]) !== undefined)
514
+ return backbone && geneFeatures && binds
515
+ ? featuresOnBackbone(geneFeatures, backbone)
516
+ : undefined
517
+ },
518
+ }))
519
+ .views(self => ({
520
+ get nodeNeighbors() {
521
+ return self.drawnGraph ? buildNeighbors(self.drawnGraph) : undefined
522
+ },
523
+ get nodeInk(): NodeInk {
524
+ return nodeInk(
525
+ self.drawnGraph,
526
+ self.nodeById,
527
+ self.contigThickness,
528
+ self.nodeWidth,
529
+ )
530
+ },
531
+ // Links that skip reference sequence, i.e. the deletions this graph
532
+ // holds. Computed once per graph rather than per geometry rebuild: it is
533
+ // a pass over the edges and the drawing rebuilds on every pan.
534
+ // Walk rows state what each walk skips as its own bar length, so the arcs
535
+ // over the backbone would only say it again, across the bars.
536
+ get deletions() {
537
+ return self.graph && this.drawsNodes ? deletionEdges(self.graph) : []
538
+ },
539
+ // One bar per haplotype walk on its own bp axis, for the walk-rows
540
+ // overlay. Empty under every other layout.
541
+ get walkRowBars() {
542
+ if (self.chosenLayoutMode !== 'walkrows' || !self.graph) {
543
+ return undefined
544
+ }
545
+ const repeat = self.selectedRepeat
546
+ const bars = repeat
547
+ ? walkRows(self.graph, repeat, repeat.unit)
548
+ : self.cutWalkRows
549
+ if (!bars) {
550
+ return undefined
551
+ }
552
+ const rows = filterSamples(bars.rows, self.walkRowSamples)
553
+ const [reference, ...paired] = withCalls(
554
+ [bars.reference, ...rows],
555
+ repeat?.calls,
556
+ )
557
+ return { ...bars, reference: reference!, rows: paired }
558
+ },
559
+ // Whether the canvas draws the graph's nodes. A tube map and walk rows
560
+ // draw a picture of their own over it, so what sits on nodes (genes,
561
+ // bubble halos, deletion arcs, the reference strip) has nowhere to go.
562
+ // Read off what was drawn rather than the mode asked for, which falls
563
+ // back to the force layout on a graph it cannot draw.
564
+ get drawsNodes() {
565
+ return !self.layoutResult?.tubeMap && !this.walkRowBars
566
+ },
567
+ // The labels drawn beside the rows. Walk rows label from the bars
568
+ // themselves, which follow the selected repeat and sample filter that
569
+ // the layout, run once per cut, cannot.
570
+ get drawnRowLabels() {
571
+ const bars = this.walkRowBars
572
+ return bars
573
+ ? [bars.reference, ...bars.rows].map((row, i) => ({
574
+ label: row.label,
575
+ y: i * ROW_HEIGHT_PX,
576
+ }))
577
+ : self.rowLabels
578
+ },
579
+ // The row labels are pinned to the pane's left edge, so the fit starts
580
+ // the drawing past the widest one.
581
+ get fitPadLeft() {
582
+ return Math.max(
583
+ FIT_PADDING,
584
+ ...this.drawnRowLabels.map(r => rowLabelBox(r.label, 0).x1 + 6),
585
+ )
586
+ },
587
+ // Exons and names on the backbone, in layout units. Reads
588
+ // positionsVersion so a dragged node takes its exons with it.
589
+ get genePins() {
590
+ dependOn(self.positionsVersion)
591
+ const positions = self.layoutResult?.nodePositions
592
+ return self.showGenes &&
593
+ this.drawsNodes &&
594
+ self.graph &&
595
+ self.backboneGenes &&
596
+ positions
597
+ ? genePins(self.graph, self.backboneGenes, positions)
598
+ : []
599
+ },
600
+ // The bubbles as halos along their nodes.
601
+ // Reads positionsVersion so a dragged node takes its halo with it.
602
+ get bubbleHalos() {
603
+ dependOn(self.positionsVersion)
604
+ const positions = self.layoutResult?.nodePositions
605
+ if (!self.showBubbles || !this.drawsNodes || !self.graph || !positions) {
606
+ return []
607
+ }
608
+ const labels = new Map(self.walkChoices.map(c => [c.name, c.label]))
609
+ return bubbleHalos(
610
+ self.graph,
611
+ self.bubbles,
612
+ positions,
613
+ name => labels.get(name) ?? name,
614
+ self.repeatArrays,
615
+ )
616
+ },
617
+ // Every node's midpoint on the reference plus the interval the hue ramps
618
+ // over — what `reference-position` paints from, and undefined under every
619
+ // other scheme so the walk is never run for a colouring that ignores it.
620
+ //
621
+ // Here for the same reason `deletions` is, only more so: deriving it is a
622
+ // bounded neighbour walk PER NODE (referenceMidpoints), it depends on
623
+ // nothing the transform touches, and it was being redone inside every
624
+ // geometry rebuild — 1.6 ms at 1.5k nodes, 45 ms at 30k, on a pass that
625
+ // reruns on each debounced pan and each drag frame. `reference-position`
626
+ // is also what `auto` resolves to on any anchored graph, so this was the
627
+ // default path rather than an opt-in one.
628
+ //
629
+ // On the drawn graph, whose ids a folded tube map's boxes carry
630
+ get referenceRamp() {
631
+ return self.effectiveColorScheme === 'reference-position' &&
632
+ self.drawnGraph
633
+ ? computeReferenceRamp(self.drawnGraph, self.rampDomain)
634
+ : undefined
635
+ },
636
+ // The assemblies this view is showing, which is the interface every
637
+ // assembly-aware piece of the app looks for — `viewTitle` first among
638
+ // them, which falls back through it and otherwise names the view
639
+ // "Untitled view". Every published HPRC figure showed that.
640
+ // `launchSubgraphView` only avoids it by writing `displayName`, so a
641
+ // declaratively-instantiated view (a session snapshot, a figure spec) got
642
+ // the fallback.
643
+ //
644
+ // A whole-file import has none: its stable names are a GFA's business and
645
+ // need not name anything the session has loaded. Empty rather than
646
+ // undefined, matching what an LGV with no displayed regions reports.
647
+ get assemblyNames() {
648
+ const region = self.graphRegion
649
+ return region ? [region.assemblyName] : []
650
+ },
651
+ // Screen px per layout unit, per axis. `scale` is the x zoom and the whole
652
+ // of what a user's wheel moves; y is a second question the layout answers
653
+ // for itself.
654
+ //
655
+ // On a row layout the pitch is already in screen px (rowSpacing.ts), so
656
+ // scaleY is 1 and stays 1: rows are a track's row height, unchanged by
657
+ // zoom, and the backbone under them zooms the way the ruler above it does.
658
+ // On an isotropic layout (FMMM) x and y are one simulation space and one
659
+ // number scales both, exactly as before.
660
+ //
661
+ // Everything that mixes the two axes takes their ratio as `yToX`
662
+ // (scaleY / scaleX) — see computeEdgeCurves.
663
+ get scaleX() {
664
+ return axisScaleOf(self.scale, self.pixelRows).scaleX
665
+ },
666
+ get scaleY() {
667
+ return axisScaleOf(self.scale, self.pixelRows).scaleY
668
+ },
669
+ // The pair, for everything that draws or hit-tests. Handed over as one
670
+ // value on purpose: every consumer needs both, and passing them separately
671
+ // let a caller supply the x scale and default y, which compiles and draws
672
+ // a wrong picture. See AxisScale.
673
+ get axisScale() {
674
+ return axisScaleOf(self.scale, self.pixelRows)
675
+ },
676
+ // Extent of the drawing in layout units, shared by the pane height and
677
+ // zoomToFit. On a reference-bp layout x is the cut window rather than
678
+ // how far the drawing reaches: an allele anchored far outside it is a
679
+ // fact about the graph, not a reason to draw the window at 6% of the
680
+ // frame. A popped bubble fits to what it drew. Walk rows reach as far as
681
+ // the bars on screen, which a repeat pick or a sample filter narrows
682
+ // after the layout ran.
683
+ get layoutBounds() {
684
+ const layout = self.layoutResult
685
+ const bars = this.walkRowBars
686
+ return layout
687
+ ? drawingBounds(layout, {
688
+ region: self.popStack.length === 0 ? self.graphRegion : undefined,
689
+ extent: bars && layout.extent ? walkRowsExtent(bars) : undefined,
690
+ })
691
+ : undefined
692
+ },
693
+ }))
694
+ .views(self => ({
695
+ get geneTrack() {
696
+ return pickGeneTrack(self.geneTrackChoices, self.geneTrackId)
697
+ },
698
+ // Which of `graph.edges` are deletions, and what each one bypasses, keyed
699
+ // the way the geometry and the hit index address an edge. One map per
700
+ // graph rather than per rebuild, since both of those take it on every
701
+ // pan.
702
+ get deletionEdgeIndexes() {
703
+ return new Map(self.deletions.map(d => [d.edgeIndex, d.bypassed]))
704
+ },
705
+ get hiddenEdgeIndexes() {
706
+ return new Set(
707
+ self.showDeletionEdges ? [] : self.deletions.map(d => d.edgeIndex),
708
+ )
709
+ },
710
+ // The interval the reference-position ramp runs over, for the key beside
711
+ // the drawing, and undefined when no key should be drawn. Two tutorials
712
+ // carry "red to magenta is left to right of the cut window" as a sentence
713
+ // in prose because nothing on screen said it.
714
+ //
715
+ // Read off the ramp the drawing is actually painted with rather than
716
+ // re-derived from the domain, so the key cannot come to describe a
717
+ // different interval from the hues beside it — and so a graph that states
718
+ // no domain, whose interval has to be measured, does not pay for a second
719
+ // neighbour walk to say what the first one already worked out.
720
+ get referenceRampDomain() {
721
+ const ramp = self.referenceRamp
722
+ return ramp
723
+ ? { start: ramp.start, end: ramp.start + ramp.span }
724
+ : undefined
725
+ },
726
+ // The ramp's two colours for nodes off it, as getNodeColor paints them:
727
+ // charcoal where an rGFA rank puts a node off the reference, grey where
728
+ // a node has no reference position at all. A tube map draws the window
729
+ // alone (trimToWindow), so there only the boxes it drew count.
730
+ get referenceRampOffKeys() {
731
+ const ramp = self.referenceRamp
732
+ const layout = self.layoutResult
733
+ const drawn = layout?.tubeMap ? layout.nodePositions : undefined
734
+ let offReference = false
735
+ let unplaced = false
736
+ if (ramp && self.drawnGraph) {
737
+ for (const node of self.drawnGraph.nodes) {
738
+ if (drawn && !drawn[node.id]) {
739
+ continue
740
+ }
741
+ if (!ramp.midpoints.has(node.id)) {
742
+ unplaced = true
743
+ } else if (node.stable && node.stable.rank > 0) {
744
+ offReference = true
745
+ }
746
+ }
747
+ }
748
+ return { offReference, unplaced }
749
+ },
750
+ // Each tube map box in its node's colour, where the scheme paints one
751
+ get tubeMapNodeColors() {
752
+ const graph = self.drawnGraph
753
+ return self.layoutResult?.tubeMap && graph
754
+ ? tubeMapNodeColors(
755
+ graph,
756
+ self.effectiveColorScheme,
757
+ self.referenceRamp,
758
+ )
759
+ : undefined
760
+ },
761
+ // Beside tinted boxes the tubes step through greys, as they do beside
762
+ // reads, so no tube shares a box's hue
763
+ get tubeMapTubeColors() {
764
+ const colors = self.layoutResult?.tubeMap?.pathColors
765
+ const tubes =
766
+ colors && this.tubeMapNodeColors
767
+ ? colors.map((_, i) => pathGreyCssColor(i, colors.length))
768
+ : colors
769
+ const hovered = new Set(self.hoveredRowWalks)
770
+ const paths = self.drawnGraph?.paths
771
+ return tubes && paths && hovered.size > 0
772
+ ? tubes.map((color, i) =>
773
+ hovered.has(paths[i]?.name ?? '') ? color : LIFT_BACKDROP_CSS,
774
+ )
775
+ : tubes
776
+ },
777
+ // A node's reference interval, an allele's between its flanks
778
+ nodeSpan(nodeId: string) {
779
+ const { nodeById, nodeNeighbors: neighbors } = self
780
+ return nodeById && neighbors
781
+ ? nodeReferenceSpan({ nodeId, nodeById, neighbors })
782
+ : undefined
783
+ },
784
+ }))
785
+ .views(self => ({
786
+ // Which haplotype each ribbon colour belongs to, in the order the file
787
+ // states the paths — the same list and the same order the geometry keys
788
+ // its colours off, so the key cannot name a colour that is not drawn.
789
+ // Empty unless the ribbons are actually on: a colour key beside a drawing
790
+ // with no colours in it is a legend for nothing.
791
+ // The tube map colours its tubes whether or not paths are drawn on the
792
+ // nodes, so under it the key follows the tubes, and names the colours
793
+ // the tubes were drawn in.
794
+ get pathLegend() {
795
+ const paths = self.graph?.paths
796
+ const tubeMap = self.layoutResult?.tubeMap
797
+ const colouring = self.drawPaths || tubeMap
798
+ return colouring && paths && pathColorsLegible(paths.length)
799
+ ? pathLegend(paths, self.tubeMapTubeColors)
800
+ : []
801
+ },
802
+ // The reference interval under the pointer: the hovered node's, or the
803
+ // hovered bubble's
804
+ get hoveredSpan() {
805
+ const nodeId = self.hoveredNode
806
+ const bubble = self.hoveredBubble
807
+ return nodeId !== null
808
+ ? self.nodeSpan(nodeId)
809
+ : bubble
810
+ ? { start: bubble.start, end: bubble.end }
811
+ : undefined
812
+ },
813
+ }))
814
+ .views(self => ({
815
+ // The hovered span, for a connected linear view to highlight. Only a
816
+ // graph cut from a track has one: a whole-file import has no region, and
817
+ // its stable names need not name anything in a loaded assembly.
818
+ get hoverHighlight() {
819
+ const region = self.graphRegion
820
+ const span = self.hoveredSpan
821
+ return region && span
822
+ ? {
823
+ refName: region.refName,
824
+ assemblyName: region.assemblyName,
825
+ ...span,
826
+ }
827
+ : undefined
828
+ },
829
+ }))