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.
- package/README.md +7 -1
- package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js +2 -0
- package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js.map +7 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js +4 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js.map +7 -0
- package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js → GraphGenomeView-YYP4IFSI.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js → GraphTrackSettingsDialog-2WPJRAJC.js} +2 -2
- package/dist/chunks/LinearGraphDisplay-7YE624D5.js +2 -0
- package/dist/chunks/LinearGraphDisplay-7YE624D5.js.map +7 -0
- package/dist/chunks/chunk-2H7GDQ3R.js +6 -0
- package/dist/chunks/chunk-2H7GDQ3R.js.map +7 -0
- package/dist/chunks/chunk-BZOIENU5.js +2 -0
- package/dist/chunks/chunk-BZOIENU5.js.map +7 -0
- package/dist/chunks/{chunk-UTWFU4X6.js → chunk-H54W6OQQ.js} +2 -2
- package/dist/chunks/{chunk-UTWFU4X6.js.map → chunk-H54W6OQQ.js.map} +4 -4
- package/dist/chunks/{chunk-F2EPKNTV.js → chunk-O4XV3K35.js} +2 -2
- package/dist/chunks/{chunk-F2EPKNTV.js.map → chunk-O4XV3K35.js.map} +4 -4
- package/dist/chunks/chunk-SJNG2XK7.js +2 -0
- package/dist/chunks/chunk-SJNG2XK7.js.map +7 -0
- package/dist/chunks/chunk-WKVVIDCS.js +3 -0
- package/dist/chunks/{chunk-KCL5TF5X.js.map → chunk-WKVVIDCS.js.map} +3 -3
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +3 -3
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +36 -2
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +67 -1
- package/src/GbzBaseSyntenyAdapter/test_data/fragmented.haplotype-index.db +0 -0
- package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.haplotype-index.db +0 -0
- package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.sampled.haplotype-index.db +0 -0
- package/src/GetHaplotypeOverview.ts +77 -0
- package/src/GraphGenomeView/components/ChooseWalksDialog.tsx +86 -0
- package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +205 -187
- package/src/GraphGenomeView/components/TubeMapLegend.test.tsx +29 -0
- package/src/GraphGenomeView/components/TubeMapOverlay.tsx +8 -0
- package/src/GraphGenomeView/host.ts +6 -0
- package/src/GraphGenomeView/model.ts +10 -4224
- package/src/GraphGenomeView/pane/fitViews.ts +589 -0
- package/src/GraphGenomeView/pane/graphViews.ts +829 -0
- package/src/GraphGenomeView/pane/hostViews.ts +193 -0
- package/src/GraphGenomeView/pane/launchActions.ts +407 -0
- package/src/GraphGenomeView/pane/launchViews.ts +191 -0
- package/src/GraphGenomeView/pane/loadActions.ts +701 -0
- package/src/GraphGenomeView/pane/paneBase.ts +479 -0
- package/src/GraphGenomeView/pane/renderingActions.ts +281 -0
- package/src/GraphGenomeView/pane/settingActions.ts +467 -0
- package/src/GraphGenomeView/pane/walkRowViews.ts +205 -0
- package/src/HaplotypeOverview/HaplotypeOverviewCanvas.tsx +203 -0
- package/src/HaplotypeOverview/draw.test.ts +136 -0
- package/src/HaplotypeOverview/draw.ts +433 -0
- package/src/HaplotypeOverview/model.ts +163 -0
- package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +184 -0
- package/src/LinearGraphDisplay/components/LinearGraphDisplay.tsx +12 -2
- package/src/LinearGraphDisplay/model.ts +107 -3
- package/src/gaf/gafFile.ts +2 -0
- package/src/index.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js +0 -8
- package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js.map +0 -7
- package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js +0 -2
- package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js.map +0 -7
- package/dist/chunks/chunk-BUXVOMDL.js +0 -2
- package/dist/chunks/chunk-BUXVOMDL.js.map +0 -7
- package/dist/chunks/chunk-KCL5TF5X.js +0 -3
- /package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js.map → GraphGenomeView-YYP4IFSI.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js.map → GraphTrackSettingsDialog-2WPJRAJC.js.map} +0 -0
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FACET_PAD_PX,
|
|
3
|
+
facetCells,
|
|
4
|
+
facetGrid,
|
|
5
|
+
} from '@jbrowse/bandage-core/facetGrid'
|
|
6
|
+
import { figureSvg } from '@jbrowse/bandage-core/figure'
|
|
7
|
+
import {
|
|
8
|
+
LEGEND_INSET_PX,
|
|
9
|
+
layoutLabels,
|
|
10
|
+
} from '@jbrowse/bandage-core/labelLayout'
|
|
11
|
+
import { layoutModeByValue } from '@jbrowse/bandage-core/layoutModes'
|
|
12
|
+
import { FIT_PADDING, fitTransform } from '@jbrowse/bandage-core/pipeline'
|
|
13
|
+
import { buildGeometry } from '@jbrowse/bandage-core/renderer/GeometryBuilder'
|
|
14
|
+
import { rulerBoxes } from '@jbrowse/bandage-core/tubeMap/axis'
|
|
15
|
+
import {
|
|
16
|
+
connectorAt,
|
|
17
|
+
tubeMapConnectors,
|
|
18
|
+
} from '@jbrowse/bandage-core/tubeMap/connectors'
|
|
19
|
+
import {
|
|
20
|
+
mismatchOnScreen,
|
|
21
|
+
mismatchesLegible,
|
|
22
|
+
} from '@jbrowse/bandage-core/tubeMap/draw'
|
|
23
|
+
import {
|
|
24
|
+
tubeMapFrame,
|
|
25
|
+
tubeMapNodeAt,
|
|
26
|
+
} from '@jbrowse/bandage-core/tubeMap/frame'
|
|
27
|
+
import {
|
|
28
|
+
GENE_ROW_PX,
|
|
29
|
+
tubeMapGeneRows,
|
|
30
|
+
} from '@jbrowse/bandage-core/tubeMap/genes'
|
|
31
|
+
import { padded } from '@jbrowse/bandage-core/viewport'
|
|
32
|
+
import { walkPosition } from '@jbrowse/bandage-core/walkKey'
|
|
33
|
+
import {
|
|
34
|
+
expandTabixShorthand,
|
|
35
|
+
readConfObject,
|
|
36
|
+
} from '@jbrowse/core/configuration'
|
|
37
|
+
import { getSession } from '@jbrowse/core/util'
|
|
38
|
+
import { getDpr } from '@jbrowse/render-core/canvas2dUtils'
|
|
39
|
+
import { untracked } from 'mobx'
|
|
40
|
+
|
|
41
|
+
import { hostFrame } from '../host'
|
|
42
|
+
import { withHostViews } from './hostViews'
|
|
43
|
+
import {
|
|
44
|
+
HOVER_BRIGHTEN,
|
|
45
|
+
MAX_CANVAS_HEIGHT,
|
|
46
|
+
MIN_CANVAS_HEIGHT,
|
|
47
|
+
MIN_FIT_TUBE_PX,
|
|
48
|
+
PAPER_DARK,
|
|
49
|
+
PAPER_LIGHT,
|
|
50
|
+
SELECT_BRIGHTEN,
|
|
51
|
+
VIEWPORT_PANES_BUILT,
|
|
52
|
+
dependOn,
|
|
53
|
+
paneViewportOf,
|
|
54
|
+
uriOf,
|
|
55
|
+
} from './paneBase'
|
|
56
|
+
|
|
57
|
+
import type { FacetGrid, FacetSetting } from '@jbrowse/bandage-core/facetGrid'
|
|
58
|
+
import type { Renderer } from '@jbrowse/bandage-core/renderer/types'
|
|
59
|
+
import type { LiftedWalk, WalkLift } from '@jbrowse/bandage-core/walkHighlight'
|
|
60
|
+
import type { FileLocation } from '@jbrowse/core/util/types'
|
|
61
|
+
|
|
62
|
+
export const withFitViews = withHostViews
|
|
63
|
+
.views(self => ({
|
|
64
|
+
// `paneHeight` replaces the built-in ceiling rather than adding a second
|
|
65
|
+
// clamp under it, and the floor still wins: a pane shorter than
|
|
66
|
+
// MIN_CANVAS_HEIGHT leaves no room to hover a node and read its tooltip,
|
|
67
|
+
// which is the reason that floor exists.
|
|
68
|
+
get paneCeiling() {
|
|
69
|
+
return Math.max(MIN_CANVAS_HEIGHT, self.paneHeight ?? MAX_CANVAS_HEIGHT)
|
|
70
|
+
},
|
|
71
|
+
// Room over a tube map for the rows its genes need, one inside the
|
|
72
|
+
// padding and one more for each further gene that overlaps it, and
|
|
73
|
+
// room for the reference strip
|
|
74
|
+
get fitPadTopBase() {
|
|
75
|
+
const rows = tubeMapGeneRows(self.tubeMapGenes)
|
|
76
|
+
return (
|
|
77
|
+
FIT_PADDING +
|
|
78
|
+
Math.max(0, rows - 1) * GENE_ROW_PX +
|
|
79
|
+
self.referenceStripZonePx
|
|
80
|
+
)
|
|
81
|
+
},
|
|
82
|
+
// The fit draws nothing under the legend. It leaves the legend room on
|
|
83
|
+
// the side that costs the drawing less scale: beside a tall drawing,
|
|
84
|
+
// which has width to spare, or above a wide flat one, which takes the
|
|
85
|
+
// height instead. A drawing whose x the host places can only move down.
|
|
86
|
+
// Reads get no room: their letters, and the legend row naming them, come
|
|
87
|
+
// and go with the fit's scale.
|
|
88
|
+
get legendRoom(): 'right' | 'top' | undefined {
|
|
89
|
+
const bounds = self.layoutBounds
|
|
90
|
+
const { width, height } = self.legendSize
|
|
91
|
+
if (
|
|
92
|
+
!bounds ||
|
|
93
|
+
bounds.w <= 0 ||
|
|
94
|
+
width === 0 ||
|
|
95
|
+
self.facetPanels ||
|
|
96
|
+
self.tubeMapReads
|
|
97
|
+
) {
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
if (self.hostPlacesX) {
|
|
101
|
+
return 'top'
|
|
102
|
+
}
|
|
103
|
+
const base = this.fitPadTopBase
|
|
104
|
+
// a track's height is its own
|
|
105
|
+
const room = self.host ? this.canvasHeight : this.paneCeiling
|
|
106
|
+
const across = (padRight: number) =>
|
|
107
|
+
(self.paneWidth - self.fitPadLeft - padRight) / bounds.w
|
|
108
|
+
const down = (padTop: number) =>
|
|
109
|
+
self.pixelRows
|
|
110
|
+
? bounds.h + padTop + FIT_PADDING <= room
|
|
111
|
+
? Infinity
|
|
112
|
+
: 0
|
|
113
|
+
: (room - padTop - FIT_PADDING) / bounds.h
|
|
114
|
+
const beside = Math.min(across(width + 2 * LEGEND_INSET_PX), down(base))
|
|
115
|
+
const above = Math.min(
|
|
116
|
+
across(FIT_PADDING),
|
|
117
|
+
down(base + height + LEGEND_INSET_PX),
|
|
118
|
+
)
|
|
119
|
+
return above >= beside ? 'top' : 'right'
|
|
120
|
+
},
|
|
121
|
+
get fitPadTop() {
|
|
122
|
+
return (
|
|
123
|
+
this.fitPadTopBase +
|
|
124
|
+
(this.legendRoom === 'top'
|
|
125
|
+
? self.legendSize.height + LEGEND_INSET_PX
|
|
126
|
+
: 0)
|
|
127
|
+
)
|
|
128
|
+
},
|
|
129
|
+
get fitPadRight() {
|
|
130
|
+
return this.legendRoom === 'right'
|
|
131
|
+
? Math.max(FIT_PADDING, self.legendSize.width + 2 * LEGEND_INSET_PX)
|
|
132
|
+
: FIT_PADDING
|
|
133
|
+
},
|
|
134
|
+
// A tube map on its own axis reads by panning along it, as in
|
|
135
|
+
// sequenceTubeMap. Rather than shrink a long cut to a strip, the fit
|
|
136
|
+
// stops where its tubes are MIN_FIT_TUBE_PX wide, or at whatever fits
|
|
137
|
+
// the tallest pane, with the cut's left end on screen.
|
|
138
|
+
get minFitScale() {
|
|
139
|
+
const bounds = self.layoutBounds
|
|
140
|
+
const layout = self.layoutResult
|
|
141
|
+
const tubePx = layout?.tubeMap?.layout.tracks[0]?.width
|
|
142
|
+
return bounds && bounds.h > 0 && tubePx && !layout.referenceAxis
|
|
143
|
+
? Math.min(
|
|
144
|
+
MIN_FIT_TUBE_PX / tubePx,
|
|
145
|
+
(this.paneCeiling - this.fitPadTop - FIT_PADDING) / bounds.h,
|
|
146
|
+
)
|
|
147
|
+
: 0
|
|
148
|
+
},
|
|
149
|
+
// The facet as a spec writes it: the bare field while nothing else is
|
|
150
|
+
// written, the whole setting otherwise, and nothing while off
|
|
151
|
+
get facetSpec(): string | FacetSetting | undefined {
|
|
152
|
+
const { field, domain, columns } = self.facet
|
|
153
|
+
return field === ''
|
|
154
|
+
? undefined
|
|
155
|
+
: domain.length === 0 && columns === undefined
|
|
156
|
+
? field
|
|
157
|
+
: {
|
|
158
|
+
field,
|
|
159
|
+
domain: [...domain],
|
|
160
|
+
...(columns === undefined ? {} : { columns }),
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
// Which grid cell each panel takes; see facetCells
|
|
164
|
+
get facetPlacement() {
|
|
165
|
+
const panels = self.facetPanels
|
|
166
|
+
const { field, domain } = self.facet
|
|
167
|
+
return panels
|
|
168
|
+
? facetCells(
|
|
169
|
+
panels.map(p => p.walks[0]!.name),
|
|
170
|
+
self.hostPlacesX || field === '' ? 'walk' : field,
|
|
171
|
+
domain,
|
|
172
|
+
)
|
|
173
|
+
: undefined
|
|
174
|
+
},
|
|
175
|
+
// How the facet panels tile the pane in `room` px. A track whose x the
|
|
176
|
+
// linear view places stacks full-width panels so each keeps that x.
|
|
177
|
+
facetGridIn(room: number): FacetGrid | undefined {
|
|
178
|
+
const place = this.facetPlacement
|
|
179
|
+
const bounds = self.layoutBounds
|
|
180
|
+
return place && bounds && bounds.w > 0
|
|
181
|
+
? facetGrid({
|
|
182
|
+
count: place.count,
|
|
183
|
+
bounds,
|
|
184
|
+
pixelRows: self.pixelRows,
|
|
185
|
+
width: self.paneWidth,
|
|
186
|
+
room,
|
|
187
|
+
columns: self.hostPlacesX
|
|
188
|
+
? 1
|
|
189
|
+
: (place.columns ?? self.facet.columns),
|
|
190
|
+
})
|
|
191
|
+
: undefined
|
|
192
|
+
},
|
|
193
|
+
get facetGrid() {
|
|
194
|
+
return this.facetGridIn(self.host ? this.canvasHeight : this.paneCeiling)
|
|
195
|
+
},
|
|
196
|
+
// The pane is as tall as the drawing, rather than a fixed box the drawing
|
|
197
|
+
// floats in. A row layout's rows are px, so its height is a sum; an
|
|
198
|
+
// isotropic layout has no height of its own and takes its aspect ratio
|
|
199
|
+
// at the width's fit. Neither reads `scale`, so the fit reads this
|
|
200
|
+
// without feeding back into it.
|
|
201
|
+
get canvasHeight(): number {
|
|
202
|
+
const bounds = self.layoutBounds
|
|
203
|
+
const usableWidth = self.paneWidth - FIT_PADDING - this.fitPadRight
|
|
204
|
+
const ceiling = this.paneCeiling
|
|
205
|
+
if (!bounds) {
|
|
206
|
+
return ceiling
|
|
207
|
+
}
|
|
208
|
+
const grid = this.facetGrid
|
|
209
|
+
if (grid) {
|
|
210
|
+
return Math.max(MIN_CANVAS_HEIGHT, grid.total)
|
|
211
|
+
}
|
|
212
|
+
// never shorter than the legend, which a flat drawing would clip
|
|
213
|
+
const floor = Math.max(
|
|
214
|
+
MIN_CANVAS_HEIGHT,
|
|
215
|
+
self.legendSize.height +
|
|
216
|
+
2 * LEGEND_INSET_PX +
|
|
217
|
+
self.referenceStripZonePx,
|
|
218
|
+
)
|
|
219
|
+
if (self.pixelRows) {
|
|
220
|
+
return Math.min(
|
|
221
|
+
ceiling,
|
|
222
|
+
Math.max(floor, bounds.h + this.fitPadTop + FIT_PADDING),
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
return bounds.w > 0 && usableWidth > 0
|
|
226
|
+
? Math.min(
|
|
227
|
+
ceiling,
|
|
228
|
+
Math.max(
|
|
229
|
+
floor,
|
|
230
|
+
bounds.h * Math.max(usableWidth / bounds.w, this.minFitScale) +
|
|
231
|
+
this.fitPadTop +
|
|
232
|
+
FIT_PADDING,
|
|
233
|
+
),
|
|
234
|
+
)
|
|
235
|
+
: ceiling
|
|
236
|
+
},
|
|
237
|
+
// What the transform maps the drawing into: one facet panel while the
|
|
238
|
+
// pane is faceted, since every panel shares it, else the pane
|
|
239
|
+
get viewBox() {
|
|
240
|
+
const grid = this.facetGrid
|
|
241
|
+
return grid
|
|
242
|
+
? { width: grid.width, height: grid.height }
|
|
243
|
+
: { width: self.paneWidth, height: this.canvasHeight }
|
|
244
|
+
},
|
|
245
|
+
// Where the fit puts the drawing, or undefined until there is a layout
|
|
246
|
+
// and a measured canvas to fit it into
|
|
247
|
+
get fittedTransform() {
|
|
248
|
+
const bounds = self.layoutBounds
|
|
249
|
+
const grid = this.facetGrid
|
|
250
|
+
return !bounds
|
|
251
|
+
? undefined
|
|
252
|
+
: grid
|
|
253
|
+
? fitTransform(bounds, grid.width, grid.height, self.pixelRows, {
|
|
254
|
+
padLeft: FACET_PAD_PX,
|
|
255
|
+
padTop: FACET_PAD_PX,
|
|
256
|
+
padRight: FACET_PAD_PX,
|
|
257
|
+
padBottom: FACET_PAD_PX,
|
|
258
|
+
})
|
|
259
|
+
: fitTransform(
|
|
260
|
+
bounds,
|
|
261
|
+
self.paneWidth,
|
|
262
|
+
this.canvasHeight,
|
|
263
|
+
self.pixelRows,
|
|
264
|
+
{
|
|
265
|
+
minScale: this.minFitScale,
|
|
266
|
+
padLeft: self.fitPadLeft,
|
|
267
|
+
padTop: this.fitPadTop,
|
|
268
|
+
padRight: this.fitPadRight,
|
|
269
|
+
},
|
|
270
|
+
)
|
|
271
|
+
},
|
|
272
|
+
}))
|
|
273
|
+
.views(self => ({
|
|
274
|
+
// The window the transform shows plus a pane of overscan all round,
|
|
275
|
+
// which a pan inside needs no rebuild for
|
|
276
|
+
viewportToBuild() {
|
|
277
|
+
return padded(paneViewportOf(self), VIEWPORT_PANES_BUILT)
|
|
278
|
+
},
|
|
279
|
+
// Hover and selection as draw-time colour overrides, stated whole, so
|
|
280
|
+
// there is nothing to restore and nothing to go stale when a rebuild
|
|
281
|
+
// renumbers the batch
|
|
282
|
+
applyHighlights(b: Renderer) {
|
|
283
|
+
const { hoveredNode, hoveredEdge, selectedNode } = self
|
|
284
|
+
const nodes = new Map<string, number>()
|
|
285
|
+
if (selectedNode !== null) {
|
|
286
|
+
nodes.set(selectedNode, SELECT_BRIGHTEN)
|
|
287
|
+
}
|
|
288
|
+
if (hoveredNode !== null && hoveredNode !== selectedNode) {
|
|
289
|
+
nodes.set(hoveredNode, HOVER_BRIGHTEN)
|
|
290
|
+
}
|
|
291
|
+
b.setNodeHighlights(nodes)
|
|
292
|
+
b.setEdgeHighlight(hoveredEdge, HOVER_BRIGHTEN)
|
|
293
|
+
},
|
|
294
|
+
// Draws the uploaded batch through the pane's transform
|
|
295
|
+
paint(b: Renderer) {
|
|
296
|
+
// getDpr(), never a bare `devicePixelRatio`: it is capped at
|
|
297
|
+
// MAX_DPR so this canvas costs what every other canvas in the app
|
|
298
|
+
// costs on a 3x display (the square of the ratio, i.e. 9x the
|
|
299
|
+
// pixels of 1x against the 4x everything else pays), and it is the
|
|
300
|
+
// same read `syncCanvasSize` sizes the backing store with — two
|
|
301
|
+
// call sites reading the global separately can disagree, and then
|
|
302
|
+
// the geometry lands at a different scale from the canvas under it.
|
|
303
|
+
const dpr = getDpr()
|
|
304
|
+
b.updateTransform({
|
|
305
|
+
scaleX: self.scaleX * dpr,
|
|
306
|
+
scaleY: self.scaleY * dpr,
|
|
307
|
+
translateX: self.translateX * dpr,
|
|
308
|
+
translateY: self.translateY * dpr,
|
|
309
|
+
// Handed over rather than read again by the backend: the
|
|
310
|
+
// thicknesses in the vertex buffer are css px and are expanded
|
|
311
|
+
// after this transform, so they need the same ratio the fields
|
|
312
|
+
// above were already multiplied by. See TransformUniform.dpr.
|
|
313
|
+
dpr,
|
|
314
|
+
})
|
|
315
|
+
// Clear under a reference strip: GraphCanvas lays the paper below the
|
|
316
|
+
// strip, so the linear view's gridlines show through between its blocks
|
|
317
|
+
b.render(
|
|
318
|
+
self.referenceStripShown
|
|
319
|
+
? [0, 0, 0, 0]
|
|
320
|
+
: self.darkMode
|
|
321
|
+
? PAPER_DARK
|
|
322
|
+
: PAPER_LIGHT,
|
|
323
|
+
)
|
|
324
|
+
},
|
|
325
|
+
}))
|
|
326
|
+
.views(self => ({
|
|
327
|
+
// The drawing's batch with `highlight`'s walks lifted, for the window
|
|
328
|
+
// the transform shows. A caller's autorun rebuilds it when the window
|
|
329
|
+
// settles after a pan or zoom, when a drag moves the positions, and when
|
|
330
|
+
// any display option read here changes.
|
|
331
|
+
buildDrawing(highlight: WalkLift | undefined, drawPaths: boolean) {
|
|
332
|
+
const { nodePositions, graph, nodeById } = self
|
|
333
|
+
if (!nodePositions || !graph || !nodeById) {
|
|
334
|
+
return undefined
|
|
335
|
+
}
|
|
336
|
+
dependOn(self.viewportDirty, self.positionsVersion)
|
|
337
|
+
const viewportBounds = untracked(() => self.viewportToBuild())
|
|
338
|
+
const batch = buildGeometry({
|
|
339
|
+
// walk rows' overlay draws every bar, the reference's among them;
|
|
340
|
+
// its nodes stay in the hit index, so hovering the bar finds them
|
|
341
|
+
nodePositions: self.walkRowBars ? {} : nodePositions,
|
|
342
|
+
graph,
|
|
343
|
+
nodeById,
|
|
344
|
+
colorScheme: self.effectiveColorScheme,
|
|
345
|
+
contigThickness: self.contigThickness,
|
|
346
|
+
connectorThickness: self.connectorThickness,
|
|
347
|
+
drawPaths,
|
|
348
|
+
nodeWidth: self.nodeWidth,
|
|
349
|
+
highlight,
|
|
350
|
+
// Untracked, so a zoom does not eagerly rebuild geometry — the
|
|
351
|
+
// debounced viewportDirty bump drives the scale-dependent rebuild
|
|
352
|
+
// (flatness, arrow visibility, viewport culling), same as pan.
|
|
353
|
+
axis: untracked(() => self.axisScale),
|
|
354
|
+
linearLayout: self.linearLayout,
|
|
355
|
+
viewportBounds,
|
|
356
|
+
// Held against the graph rather than derived here, the same way
|
|
357
|
+
// `deletions` is and for the same reason — see `referenceRamp`.
|
|
358
|
+
referenceRamp: self.referenceRamp,
|
|
359
|
+
deletions: self.deletionEdgeIndexes,
|
|
360
|
+
deletionRoutes: self.deletionRoutes,
|
|
361
|
+
hiddenEdges: self.hiddenEdgeIndexes,
|
|
362
|
+
// passed so the shared edge-curve cache can tell a drag from a pan
|
|
363
|
+
version: self.positionsVersion,
|
|
364
|
+
})
|
|
365
|
+
return { batch, viewportBounds }
|
|
366
|
+
},
|
|
367
|
+
get overlayLabels() {
|
|
368
|
+
return layoutLabels(self)
|
|
369
|
+
},
|
|
370
|
+
// where the hovered node sits on a lifted walk, while one is hovered
|
|
371
|
+
hoveredOn(walk: LiftedWalk) {
|
|
372
|
+
const id = self.hoveredNode
|
|
373
|
+
const node = id ? self.nodeById?.get(id) : undefined
|
|
374
|
+
return node
|
|
375
|
+
? (walkPosition(walk, node.id, node.length) ?? 'not on this walk')
|
|
376
|
+
: undefined
|
|
377
|
+
},
|
|
378
|
+
// The spec bandage-figure makes this drawing from with no browser, or
|
|
379
|
+
// undefined for a graph it cannot read again: one cut from a gbz-base
|
|
380
|
+
// track or read from a GFA url, with the genes of a GFF3 tabix track
|
|
381
|
+
figureSpec() {
|
|
382
|
+
const region = self.graphRegion
|
|
383
|
+
const adapter = self.sourceAdapter
|
|
384
|
+
const panSN = adapter?.assemblyNameToPanSN as
|
|
385
|
+
Record<string, string> | undefined
|
|
386
|
+
const window = region && `${region.refName}:${region.start}-${region.end}`
|
|
387
|
+
const gfa = uriOf(self.sourceGfaLocation)
|
|
388
|
+
const db =
|
|
389
|
+
adapter?.type === 'GbzBaseSyntenyAdapter'
|
|
390
|
+
? uriOf(adapter.gbzDbLocation as FileLocation)
|
|
391
|
+
: undefined
|
|
392
|
+
const source = gfa
|
|
393
|
+
? { gfa, region: window }
|
|
394
|
+
: db && region && window
|
|
395
|
+
? {
|
|
396
|
+
gbz: {
|
|
397
|
+
db,
|
|
398
|
+
index: uriOf(adapter!.haplotypeIndexLocation as FileLocation),
|
|
399
|
+
region: window,
|
|
400
|
+
// the adapter cuts a lane by its PanSN prefix
|
|
401
|
+
haplotypes: self.cutHaplotypes?.map(
|
|
402
|
+
lane => panSN?.[lane] ?? lane,
|
|
403
|
+
),
|
|
404
|
+
referenceSample:
|
|
405
|
+
(adapter!.referenceSample as string | undefined) ||
|
|
406
|
+
panSN?.[region.assemblyName] ||
|
|
407
|
+
region.assemblyName,
|
|
408
|
+
context: adapter!.context as number | undefined,
|
|
409
|
+
snarls: self.cutsWholeWalks
|
|
410
|
+
? 'overlapping'
|
|
411
|
+
: (adapter!.subgraphSnarls as string | undefined),
|
|
412
|
+
},
|
|
413
|
+
}
|
|
414
|
+
: undefined
|
|
415
|
+
if (!source) {
|
|
416
|
+
return undefined
|
|
417
|
+
}
|
|
418
|
+
const geneTrack = self.showGenes ? self.geneTrack : undefined
|
|
419
|
+
const geneConf = geneTrack
|
|
420
|
+
? getSession(self).tracks.find(t => t.trackId === geneTrack.trackId)
|
|
421
|
+
: undefined
|
|
422
|
+
const geneAdapter = geneConf
|
|
423
|
+
? expandTabixShorthand(
|
|
424
|
+
readConfObject(geneConf, 'adapter') as Record<string, unknown>,
|
|
425
|
+
'gffGzLocation',
|
|
426
|
+
)
|
|
427
|
+
: undefined
|
|
428
|
+
const genes =
|
|
429
|
+
geneAdapter?.type === 'Gff3TabixAdapter'
|
|
430
|
+
? {
|
|
431
|
+
file: uriOf(geneAdapter.gffGzLocation as FileLocation),
|
|
432
|
+
index: uriOf(
|
|
433
|
+
(geneAdapter.index as { location?: FileLocation } | undefined)
|
|
434
|
+
?.location,
|
|
435
|
+
),
|
|
436
|
+
format: 'gff3',
|
|
437
|
+
}
|
|
438
|
+
: undefined
|
|
439
|
+
return JSON.parse(
|
|
440
|
+
JSON.stringify({
|
|
441
|
+
...source,
|
|
442
|
+
genes: genes?.file && genes.index ? genes : undefined,
|
|
443
|
+
referencePath: self.referencePath || undefined,
|
|
444
|
+
layout: self.chosenLayoutMode,
|
|
445
|
+
quality: self.layoutQuality,
|
|
446
|
+
bubbleSpread: self.bubbleSpread,
|
|
447
|
+
walks: self.walkLayers.length
|
|
448
|
+
? self.walkLayers.map(l => (l.color ? l : l.walk))
|
|
449
|
+
: undefined,
|
|
450
|
+
facet: self.walkLayers.length > 1 ? self.facetSpec : undefined,
|
|
451
|
+
walkStrip: self.walkStripShown || undefined,
|
|
452
|
+
walkRowSamples: self.walkStripShown ? self.walkRowSamples : undefined,
|
|
453
|
+
width: self.paneWidth,
|
|
454
|
+
height: self.paneCeiling,
|
|
455
|
+
colorScheme: self.chosenColorScheme,
|
|
456
|
+
nodeWidth: self.nodeWidth,
|
|
457
|
+
showDeletionEdges: self.showDeletionEdges || undefined,
|
|
458
|
+
}),
|
|
459
|
+
) as Record<string, unknown>
|
|
460
|
+
},
|
|
461
|
+
// Why the drawing cannot be written as SVG, which draws the canvas's
|
|
462
|
+
// nodes, or walk rows' bars
|
|
463
|
+
get figureUnavailable() {
|
|
464
|
+
return !self.layoutResult
|
|
465
|
+
? 'Nothing is drawn yet'
|
|
466
|
+
: self.drawsNodes || self.walkRowBars
|
|
467
|
+
? undefined
|
|
468
|
+
: `${layoutModeByValue(self.chosenLayoutMode).label} draws a picture of its own, which the SVG export does not`
|
|
469
|
+
},
|
|
470
|
+
// Why bandage-figure can't make this drawing again: it draws only
|
|
471
|
+
// layouts with nodes, from a graph it can read for itself
|
|
472
|
+
get figureSpecUnavailable() {
|
|
473
|
+
return !self.drawsNodes
|
|
474
|
+
? `bandage-figure draws no ${layoutModeByValue(self.chosenLayoutMode).label} layout`
|
|
475
|
+
: this.figureSpec()
|
|
476
|
+
? undefined
|
|
477
|
+
: 'bandage-figure reads a graph cut from a gbz-base track or a GFA url'
|
|
478
|
+
},
|
|
479
|
+
// The drawing as a standalone SVG, fitted, with its genes, its lifted
|
|
480
|
+
// walks' keys, facet panels and the strip of walk rows; see figureSvg
|
|
481
|
+
figure() {
|
|
482
|
+
const { graph, layoutResult } = self
|
|
483
|
+
return graph && layoutResult && !this.figureUnavailable
|
|
484
|
+
? figureSvg(graph, layoutResult, {
|
|
485
|
+
width: self.paneWidth,
|
|
486
|
+
height: self.paneCeiling,
|
|
487
|
+
walks: self.walkLayers,
|
|
488
|
+
facet: self.facetSpec,
|
|
489
|
+
colorScheme: self.effectiveColorScheme,
|
|
490
|
+
nodeWidth: self.nodeWidth,
|
|
491
|
+
showDeletionEdges: self.showDeletionEdges,
|
|
492
|
+
contigThickness: self.contigThickness,
|
|
493
|
+
connectorThickness: self.connectorThickness,
|
|
494
|
+
region: self.graphRegion,
|
|
495
|
+
colorDomain: self.colorDomain,
|
|
496
|
+
fitToDrawing: self.popStack.length > 0,
|
|
497
|
+
genes: self.showGenes ? self.backboneGenes : undefined,
|
|
498
|
+
walkRows: self.walkRowBars,
|
|
499
|
+
rowGenes: self.walkRowGenes,
|
|
500
|
+
rowGeneGaps: self.walkRowGeneGaps,
|
|
501
|
+
walkStrip: self.walkStripRows && {
|
|
502
|
+
rows: self.walkStripRows,
|
|
503
|
+
rowGenes: self.walkRowGenes,
|
|
504
|
+
rowGeneGaps: self.walkRowGeneGaps,
|
|
505
|
+
},
|
|
506
|
+
spec: this.figureSpec(),
|
|
507
|
+
})
|
|
508
|
+
: undefined
|
|
509
|
+
},
|
|
510
|
+
get tubeMapFrame() {
|
|
511
|
+
const drawing = self.layoutResult?.tubeMap
|
|
512
|
+
return drawing
|
|
513
|
+
? tubeMapFrame(drawing, {
|
|
514
|
+
scaleX: self.scaleX,
|
|
515
|
+
translateX: self.translateX,
|
|
516
|
+
scaleY: self.scaleY,
|
|
517
|
+
translateY: self.translateY,
|
|
518
|
+
usableHeight: self.canvasHeight - self.fitPadTop - FIT_PADDING,
|
|
519
|
+
})
|
|
520
|
+
: undefined
|
|
521
|
+
},
|
|
522
|
+
}))
|
|
523
|
+
.views(self => ({
|
|
524
|
+
// the reference ruler under the tubes, unless the linear view's ruler
|
|
525
|
+
// is already the axis
|
|
526
|
+
get tubeMapRulerBoxes() {
|
|
527
|
+
const reference = self.tubeMapReference
|
|
528
|
+
return reference && !self.hostPlacesX ? rulerBoxes(reference) : undefined
|
|
529
|
+
},
|
|
530
|
+
// The connectors run from the top of the pane down to the tubes' top
|
|
531
|
+
get connectorZoneBottom() {
|
|
532
|
+
const picture = self.tubeMapPicture
|
|
533
|
+
const frame = self.tubeMapFrame
|
|
534
|
+
return picture && frame ? frame.y(picture.bounds.minY) - 2 : 0
|
|
535
|
+
},
|
|
536
|
+
// Read off the live blocks, so the bands' tops follow every frame of a
|
|
537
|
+
// pan in the linear view and their bottoms every pan of the tubes
|
|
538
|
+
get tubeMapConnectors() {
|
|
539
|
+
const nodes = self.tubeMapReferenceNodes
|
|
540
|
+
const frame = self.tubeMapFrame
|
|
541
|
+
const { host, graphRegion } = self
|
|
542
|
+
const bp =
|
|
543
|
+
nodes && frame && host?.initialized && graphRegion
|
|
544
|
+
? hostFrame(host, graphRegion)
|
|
545
|
+
: undefined
|
|
546
|
+
return nodes && frame && bp
|
|
547
|
+
? tubeMapConnectors(
|
|
548
|
+
nodes,
|
|
549
|
+
b => b * bp.scale + bp.translateX,
|
|
550
|
+
frame.x,
|
|
551
|
+
self.paneWidth,
|
|
552
|
+
)
|
|
553
|
+
: []
|
|
554
|
+
},
|
|
555
|
+
}))
|
|
556
|
+
.views(self => ({
|
|
557
|
+
// What the tube map's legend has to explain: that on the own axis a
|
|
558
|
+
// box is as wide as the log of its length, the fold its walks' ticks
|
|
559
|
+
// stand for, the reads' strands, and the marks on the reads in view
|
|
560
|
+
get tubeMapKeys() {
|
|
561
|
+
const layout = self.layoutResult
|
|
562
|
+
const reads = layout?.tubeMap?.layout.reads ?? []
|
|
563
|
+
const picture = self.tubeMapPicture
|
|
564
|
+
const frame = self.tubeMapFrame
|
|
565
|
+
const shown =
|
|
566
|
+
picture && frame && mismatchesLegible(frame.yScale)
|
|
567
|
+
? picture.mismatches.filter(m =>
|
|
568
|
+
mismatchOnScreen(m, { x: frame.x, width: self.paneWidth }),
|
|
569
|
+
)
|
|
570
|
+
: []
|
|
571
|
+
return {
|
|
572
|
+
logWidths: layout?.tubeMap !== undefined && !layout.referenceAxis,
|
|
573
|
+
foldBp:
|
|
574
|
+
self.tubeMapDeviations.length > 0 ? self.tubeMapFold : undefined,
|
|
575
|
+
forwardReads: reads.some(r => !r.is_reverse),
|
|
576
|
+
reverseReads: reads.some(r => r.is_reverse),
|
|
577
|
+
mismatches: new Set(shown.map(m => m.kind)),
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
tubeMapNodeAt(sx: number, sy: number) {
|
|
581
|
+
const drawing = self.layoutResult?.tubeMap
|
|
582
|
+
const frame = self.tubeMapFrame
|
|
583
|
+
return (
|
|
584
|
+
(drawing && frame ? tubeMapNodeAt(drawing, frame, sx, sy) : null) ??
|
|
585
|
+
connectorAt(self.tubeMapConnectors, self.connectorZoneBottom, sx, sy) ??
|
|
586
|
+
null
|
|
587
|
+
)
|
|
588
|
+
},
|
|
589
|
+
}))
|