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,203 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react'
2
+
3
+ import BaseTooltip from '@jbrowse/core/ui/BaseTooltip'
4
+ import { observer } from 'mobx-react'
5
+
6
+ import {
7
+ NOT_SHOWN,
8
+ binAt,
9
+ cellLabel,
10
+ describeBin,
11
+ drawOverview,
12
+ overviewLayout,
13
+ rowAt,
14
+ rowImages,
15
+ } from './draw'
16
+ import { hostFrame } from '../GraphGenomeView/host'
17
+
18
+ import type { OverviewLayout } from './draw'
19
+ import type { HaplotypeOverviewData } from '../GetHaplotypeOverview'
20
+ import type { SubgraphRegion } from '../GetSubgraph'
21
+ import type { LinearHost } from '../GraphGenomeView/host'
22
+
23
+ export interface OverviewCanvasModel {
24
+ overview: HaplotypeOverviewData | undefined
25
+ overviewRegion: SubgraphRegion | undefined
26
+ overviewCounts: number[][] | undefined
27
+ overviewAllRows: boolean
28
+ height: number
29
+ host: LinearHost | undefined
30
+ setOverviewPainted: (data: HaplotypeOverviewData) => void
31
+ }
32
+
33
+ interface Pointer {
34
+ bin: number
35
+ row: number | undefined
36
+ clientX: number
37
+ clientY: number
38
+ }
39
+
40
+ const OverviewTooltip = observer(function OverviewTooltip({
41
+ data,
42
+ region,
43
+ pointer,
44
+ }: {
45
+ data: HaplotypeOverviewData
46
+ region: SubgraphRegion
47
+ pointer: Pointer
48
+ }) {
49
+ const bin = describeBin(data, pointer.bin)
50
+ const cell =
51
+ pointer.row === undefined
52
+ ? undefined
53
+ : data.cells[pointer.bin * data.rows.length + pointer.row]
54
+ return (
55
+ <BaseTooltip clientPoint={{ x: pointer.clientX, y: pointer.clientY }}>
56
+ <div>
57
+ {region.refName}:{bin.span}
58
+ </div>
59
+ {pointer.row !== undefined && cell !== undefined ? (
60
+ <div>
61
+ <strong>{data.rows[pointer.row]}</strong>: {cellLabel(cell)}
62
+ </div>
63
+ ) : (
64
+ <>
65
+ <div>{bin.classes}</div>
66
+ <div>{bin.excursions}</div>
67
+ </>
68
+ )}
69
+ <div style={{ opacity: 0.7 }}>{NOT_SHOWN}</div>
70
+ </BaseTooltip>
71
+ )
72
+ })
73
+
74
+ // The haplotype index's overview on the linear view's axis: a density row of
75
+ // the haplotypes that differ from the reference, then a row per haplotype.
76
+ // A click zooms to the bin under the pointer.
77
+ const HaplotypeOverviewCanvas = observer(function HaplotypeOverviewCanvas({
78
+ model,
79
+ }: {
80
+ model: OverviewCanvasModel
81
+ }) {
82
+ const ref = useRef<HTMLCanvasElement>(null)
83
+ const [pointer, setPointer] = useState<Pointer>()
84
+ const {
85
+ overview,
86
+ overviewRegion,
87
+ overviewCounts,
88
+ overviewAllRows,
89
+ height,
90
+ host,
91
+ } = model
92
+ const width = host?.width ?? 0
93
+ const frame =
94
+ host && overviewRegion ? hostFrame(host, overviewRegion) : undefined
95
+ const scale = frame?.scale
96
+ const translateX = frame?.translateX
97
+ const layout = useMemo<OverviewLayout | undefined>(
98
+ () =>
99
+ overview ? overviewLayout(overview, overviewAllRows, height) : undefined,
100
+ [overview, overviewAllRows, height],
101
+ )
102
+
103
+ const dpr = typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1
104
+ const images = useMemo(
105
+ () => (overview && layout ? rowImages(overview, layout, dpr) : []),
106
+ [overview, layout, dpr],
107
+ )
108
+
109
+ useEffect(() => {
110
+ const canvas = ref.current
111
+ const ctx = canvas?.getContext('2d')
112
+ if (
113
+ !canvas ||
114
+ !ctx ||
115
+ !overview ||
116
+ !layout ||
117
+ scale === undefined ||
118
+ translateX === undefined
119
+ ) {
120
+ return
121
+ }
122
+ const deviceWidth = Math.round(width * dpr)
123
+ const deviceHeight = Math.round(height * dpr)
124
+ if (canvas.width !== deviceWidth || canvas.height !== deviceHeight) {
125
+ canvas.width = deviceWidth
126
+ canvas.height = deviceHeight
127
+ }
128
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
129
+ drawOverview(ctx, overview, overviewCounts, layout, images, {
130
+ xOf: bp => bp * scale + translateX,
131
+ width,
132
+ height,
133
+ dpr,
134
+ })
135
+ model.setOverviewPainted(overview)
136
+ }, [
137
+ model,
138
+ overview,
139
+ overviewCounts,
140
+ layout,
141
+ images,
142
+ scale,
143
+ translateX,
144
+ width,
145
+ height,
146
+ dpr,
147
+ ])
148
+
149
+ const locate = (event: React.MouseEvent<HTMLCanvasElement>) => {
150
+ if (!overview || !layout || !scale || translateX === undefined) {
151
+ return undefined
152
+ }
153
+ const rect = event.currentTarget.getBoundingClientRect()
154
+ const x = event.clientX - rect.left
155
+ const y = event.clientY - rect.top
156
+ const bin = binAt(overview, (x - translateX) / scale)
157
+ return bin === undefined
158
+ ? undefined
159
+ : {
160
+ bin,
161
+ row: rowAt(layout, y),
162
+ clientX: event.clientX,
163
+ clientY: event.clientY,
164
+ }
165
+ }
166
+
167
+ return (
168
+ <>
169
+ <canvas
170
+ ref={ref}
171
+ data-testid="haplotype-overview"
172
+ style={{ width, height, display: 'block', cursor: 'pointer' }}
173
+ onMouseMove={event => {
174
+ setPointer(locate(event))
175
+ }}
176
+ onMouseLeave={() => {
177
+ setPointer(undefined)
178
+ }}
179
+ onClick={event => {
180
+ const at = locate(event)
181
+ const bin = at && overview?.bins[at.bin]
182
+ if (bin && overviewRegion && host?.navTo) {
183
+ host.navTo({
184
+ refName: overviewRegion.refName,
185
+ assemblyName: overviewRegion.assemblyName,
186
+ start: bin.start,
187
+ end: bin.end,
188
+ })
189
+ }
190
+ }}
191
+ />
192
+ {pointer && overview && overviewRegion ? (
193
+ <OverviewTooltip
194
+ data={overview}
195
+ region={overviewRegion}
196
+ pointer={pointer}
197
+ />
198
+ ) : null}
199
+ </>
200
+ )
201
+ })
202
+
203
+ export default HaplotypeOverviewCanvas
@@ -0,0 +1,136 @@
1
+ import {
2
+ DENSITY_PX,
3
+ binAt,
4
+ cellLabel,
5
+ densityCounts,
6
+ drawOverview,
7
+ overviewLayout,
8
+ rowAt,
9
+ rowTop,
10
+ } from './draw'
11
+
12
+ import type { HaplotypeOverviewData } from '../GetHaplotypeOverview'
13
+
14
+ // rows 0-3 are haplotypes, 4 the reference; 2 is the track's lane
15
+ function overview(): HaplotypeOverviewData {
16
+ const rows = ['A.1', 'B.1', 'C.1', 'D.1', 'GRCh38#0']
17
+ const bins = [0, 1, 2].map(b => ({
18
+ start: b * 100,
19
+ end: (b + 1) * 100,
20
+ classes: [0, 0, 0, 0] as [number, number, number, number],
21
+ excursions: 0,
22
+ variants: 0,
23
+ longestExcursion: 0,
24
+ }))
25
+ // bin 0: reference-like but D absent; bin 1: A variant with 16+ marks, B
26
+ // partial; bin 2 (after a gap at 300) everyone reference-like
27
+ const cells = new Uint8Array(
28
+ [
29
+ [1, 1, 1, 0, 1],
30
+ [3 | (3 << 2), 2, 1, 1, 1],
31
+ [1, 1, 1, 1, 1],
32
+ ].flat(),
33
+ )
34
+ bins[2]!.start = 400
35
+ bins[2]!.end = 500
36
+ return { level: 0, bin: 100, rows, pinned: [2], reference: [4], bins, cells }
37
+ }
38
+
39
+ test('the lane comes first at a readable height, then every other haplotype, never the reference', () => {
40
+ const layout = overviewLayout(overview(), true, 400)
41
+ expect(layout.rows).toEqual([2, 0, 1, 3])
42
+ expect(layout.pinnedHeight).toBe(14)
43
+ expect(layout.rowsTop).toBeGreaterThan(DENSITY_PX)
44
+ expect(layout.restTop).toBeGreaterThan(layout.rowsTop + 14)
45
+ expect(rowTop(layout, 3) + layout.restHeight).toBeCloseTo(400)
46
+ })
47
+
48
+ test('with only the lanes asked for, the lane alone fills the rows', () => {
49
+ const layout = overviewLayout(overview(), false, 400)
50
+ expect(layout.rows).toEqual([2])
51
+ expect(layout.restHeight).toBe(0)
52
+ })
53
+
54
+ test('a point maps to the haplotype row under it, and to none over the density row', () => {
55
+ const layout = overviewLayout(overview(), true, 400)
56
+ expect(rowAt(layout, 1)).toBeUndefined()
57
+ expect(rowAt(layout, layout.rowsTop + 1)).toBe(2)
58
+ expect(rowAt(layout, layout.restTop + 1)).toBe(0)
59
+ expect(rowAt(layout, 399)).toBe(3)
60
+ })
61
+
62
+ test('a bp maps to its bin, and to none between fragments or past the end', () => {
63
+ const data = overview()
64
+ expect(binAt(data, 0)).toBe(0)
65
+ expect(binAt(data, 150)).toBe(1)
66
+ expect(binAt(data, 350)).toBeUndefined()
67
+ expect(binAt(data, 499)).toBe(2)
68
+ expect(binAt(data, 500)).toBeUndefined()
69
+ })
70
+
71
+ test('the density counts leave the reference out and split variants by their marks', () => {
72
+ expect(densityCounts(overview())).toEqual([
73
+ [1, 0, 0, 0, 0, 0],
74
+ [0, 1, 0, 0, 0, 1],
75
+ [0, 0, 0, 0, 0, 0],
76
+ ])
77
+ })
78
+
79
+ test('a cell names its class, and a variant cell its marks', () => {
80
+ expect(cellLabel(1)).toBe('reference-like')
81
+ expect(cellLabel(3 | (1 << 2))).toBe('diverges ≥50 bp, 2–3 excursions')
82
+ expect(cellLabel(0)).toMatch(/^absent/)
83
+ })
84
+
85
+ function recordingContext() {
86
+ const calls: string[] = []
87
+ const record =
88
+ (name: string) =>
89
+ (...args: unknown[]) => {
90
+ calls.push(
91
+ `${name}(${args.map(a => (typeof a === 'number' ? Math.round(a) : '_')).join(',')})`,
92
+ )
93
+ }
94
+ const ctx = {
95
+ clearRect: record('clearRect'),
96
+ fillRect: record('fillRect'),
97
+ drawImage: record('drawImage'),
98
+ save: record('save'),
99
+ restore: record('restore'),
100
+ translate: record('translate'),
101
+ scale: record('scale'),
102
+ fillText: record('fillText'),
103
+ measureText: () => ({ width: 10 }),
104
+ } as unknown as CanvasRenderingContext2D
105
+ return { ctx, calls }
106
+ }
107
+
108
+ test('a reversed block draws its rows mirrored over the same screen span', () => {
109
+ const data = overview()
110
+ const layout = overviewLayout(data, true, 200)
111
+ const images = [
112
+ { image: { height: 4 } as HTMLCanvasElement, top: 50, height: 100 },
113
+ ]
114
+ const frame = (scale: number, translateX: number) => ({
115
+ xOf: (bp: number) => bp * scale + translateX,
116
+ width: 500,
117
+ height: 200,
118
+ dpr: 1,
119
+ })
120
+ const forward = recordingContext()
121
+ drawOverview(forward.ctx, data, undefined, layout, images, frame(1, 0))
122
+ const reversed = recordingContext()
123
+ drawOverview(reversed.ctx, data, undefined, layout, images, frame(-1, 500))
124
+ const blits = (calls: string[]) =>
125
+ calls.filter(c => c.startsWith('drawImage'))
126
+ expect(blits(forward.calls)).toEqual([
127
+ 'drawImage(_,0,0,2,4,0,50,200,100)',
128
+ 'drawImage(_,2,0,1,4,400,50,100,100)',
129
+ ])
130
+ expect(blits(reversed.calls)).toEqual([
131
+ 'drawImage(_,0,0,2,4,300,50,200,100)',
132
+ 'drawImage(_,2,0,1,4,0,50,100,100)',
133
+ ])
134
+ expect(reversed.calls).toContain('scale(-1,1)')
135
+ expect(forward.calls).not.toContain('scale(-1,1)')
136
+ })