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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbrowse-plugin-graphgenomeviewer",
3
- "version": "4.7.0",
3
+ "version": "5.0.0",
4
4
  "description": "JBrowse 2 graph genome (pangenome) view: rGFA reference-anchored layouts, the Bandage force-directed engine, and haplotype lanes read from a gbz-base database",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "private": false,
27
27
  "dependencies": {
28
28
  "@gmod/bgzf-filehandle": "^6.7.0",
29
- "@gmod/gbz-base": "^6.0.1",
29
+ "@gmod/gbz-base": "^7.0.0",
30
30
  "@gmod/tabix": "^3.9.1",
31
31
  "@gmod/tubemap-core": "^0.1.0",
32
32
  "@jbrowse/cigar-utils": "5.0.0-beta.11",
@@ -76,7 +76,7 @@
76
76
  "typescript-eslint": "^8.71.0",
77
77
  "typescript7": "npm:typescript@^7.0.2",
78
78
  "vitest": "^5.0.3",
79
- "@jbrowse/bandage-core": "4.7.0"
79
+ "@jbrowse/bandage-core": "5.0.0"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": ">=18.0.0",
@@ -342,9 +342,9 @@ test('the graph lists its haplotypes with their contigs, and a fetch can be narr
342
342
  )
343
343
  })
344
344
 
345
- test('the node limit fails a window rather than reading it whole, naming a zoom that fits', async () => {
345
+ test('the node limit fails a window rather than reading it whole, naming a zoom that fits and the display that draws it anyway', async () => {
346
346
  await expect(feats(makeAdapter({ nodeLimit: 2 }), window)).rejects.toThrow(
347
- /nodeLimit \(2\) graph nodes; zoom in to about \d+ bp/,
347
+ /nodeLimit \(2\) graph nodes; zoom in to about \d+ bp or raise nodeLimit; the track's Graph display draws/,
348
348
  )
349
349
  })
350
350
 
@@ -945,3 +945,37 @@ test('a bgzipped reads shorthand takes the .tbi beside it', () => {
945
945
  const plain = configSchema.create({ reads: 'reads.gaf', assemblyNames: [] })
946
946
  expect(readConfObject(plain, ['readsIndex', 'location']).uri).toBe('')
947
947
  })
948
+
949
+ test('the overview classes every haplotype per bin, labels rows as the lanes do, and pins the lanes asked for in their order', async () => {
950
+ const adapter = makeAdapter({
951
+ haplotypeIndexLocation: {
952
+ localPath: require.resolve('./test_data/micb-kir3dl1.haplotype-index.db'),
953
+ locationType: 'LocalPathLocation',
954
+ },
955
+ assemblyNameToPanSN: { hg38: 'GRCh38#0', 'HG00438.1': 'HG00438#1' },
956
+ })
957
+ const region = { ...window, start: 31_500_000, end: 31_520_000 }
958
+ const overview = (await adapter.getOverview(region, {
959
+ bpPerPx: 100,
960
+ haplotypes: ['HG00621', 'HG00438.1'],
961
+ }))!
962
+ expect(overview.bin).toBeLessThanOrEqual(100)
963
+ expect(overview.cells).toHaveLength(
964
+ overview.bins.length * overview.rows.length,
965
+ )
966
+ expect(overview.bins[0]!.start).toBeLessThanOrEqual(region.start)
967
+ expect(overview.rows).toContain('HG00438.1')
968
+ expect(overview.rows).toContain('HG00621#2')
969
+ expect(overview.pinned.map(row => overview.rows[row])).toEqual([
970
+ 'HG00621#1',
971
+ 'HG00621#2',
972
+ 'HG00438.1',
973
+ ])
974
+ expect(overview.reference.map(row => overview.rows[row])).toEqual(['hg38'])
975
+ })
976
+
977
+ test('a companion with no anchors has no overview', async () => {
978
+ await expect(
979
+ makeAdapter().getOverview(window, { bpPerPx: 100 }),
980
+ ).resolves.toBeUndefined()
981
+ })
@@ -25,6 +25,10 @@ import { ComparativeAdapterBase } from '../synteny/ComparativeAdapterBase.ts'
25
25
  import SyntenyFeature from '../synteny/SyntenyFeature.ts'
26
26
 
27
27
  import type { GbzBaseSyntenyAdapterConfig } from './configSchema.ts'
28
+ import type {
29
+ HaplotypeOverviewData,
30
+ OverviewAdapterOptions,
31
+ } from '../GetHaplotypeOverview.ts'
28
32
  import type { SubgraphAdapterOptions } from '../GetSubgraph.ts'
29
33
  import type { GafReads } from '../gaf/gafFile.ts'
30
34
  import type {
@@ -212,6 +216,17 @@ export function pairFeature({
212
216
  })
213
217
  }
214
218
 
219
+ // Lanes past their node limit point at the display that draws the window
220
+ // anyway
221
+ function lanesLimitError(error: unknown, limit: number, windowBp: number) {
222
+ const limitError = nodeLimitError(error, limit, windowBp)
223
+ if (limitError) {
224
+ limitError.message +=
225
+ "; the track's Graph display draws every haplotype's overview at any size"
226
+ }
227
+ return limitError
228
+ }
229
+
215
230
  const isSet = (location: FileLocation) =>
216
231
  !('uri' in location) || location.uri !== ''
217
232
 
@@ -397,6 +412,57 @@ export default class GbzBaseSyntenyAdapter extends ComparativeAdapterBase<GbzBas
397
412
  })
398
413
  }
399
414
 
415
+ /**
416
+ * The haplotype index's overview of a window on the anchor, at the
417
+ * coarsest level whose bins fit `bpPerPx`: every haplotype classed per bin.
418
+ * Undefined when the index carries no overview or the reference sample has
419
+ * no path by that contig.
420
+ */
421
+ async getOverview(
422
+ region: Region,
423
+ opts: OverviewAdapterOptions,
424
+ ): Promise<HaplotypeOverviewData | undefined> {
425
+ const { db, anchor, referenceSample } = await this.graph()
426
+ const { assemblyName, refName, start, end } = region
427
+ if (assemblyName !== anchor) {
428
+ throw new HaplotypeWindowError(assemblyName, anchor)
429
+ }
430
+ const path = await this.referenceQuery(refName, {})
431
+ const overview = path
432
+ ? await db.haplotypeOverview({
433
+ path,
434
+ start,
435
+ end,
436
+ bpPerPixel: opts.bpPerPx,
437
+ })
438
+ : undefined
439
+ if (!overview) {
440
+ return undefined
441
+ }
442
+ const asmByPrefix = assemblyByPanSNPrefix(this)
443
+ const prefixes = overview.haplotypes.map(h => haplotypePrefix(h))
444
+ const pinned = new Set<number>()
445
+ for (const lane of opts.haplotypes ?? []) {
446
+ const wanted = resolvePanSNPrefix(this, lane)
447
+ prefixes.forEach((prefix, row) => {
448
+ if (panSNMatchesPrefix(prefix, wanted)) {
449
+ pinned.add(row)
450
+ }
451
+ })
452
+ }
453
+ return {
454
+ level: overview.level,
455
+ bin: overview.bin,
456
+ rows: overview.haplotypes.map(h => laneAssemblyName(asmByPrefix, h)),
457
+ pinned: [...pinned],
458
+ reference: overview.haplotypes.flatMap((h, row) =>
459
+ h.sample === referenceSample ? [row] : [],
460
+ ),
461
+ bins: overview.bins,
462
+ cells: overview.cells,
463
+ }
464
+ }
465
+
400
466
  private gaf = cachedSetup({
401
467
  label: 'Opening reads',
402
468
  setup: async () => {
@@ -462,7 +528,7 @@ export default class GbzBaseSyntenyAdapter extends ComparativeAdapterBase<GbzBas
462
528
  keep,
463
529
  })
464
530
  .catch((error: unknown) => {
465
- throw nodeLimitError(error, nodeLimit, end - start) ?? error
531
+ throw lanesLimitError(error, nodeLimit, end - start) ?? error
466
532
  }),
467
533
  )
468
534
  : []
@@ -0,0 +1,77 @@
1
+ import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache'
2
+ import { RpcMethodTypeWithRenameRegion } from '@jbrowse/core/pluggableElementTypes'
3
+
4
+ import type { OverviewBin } from '@gmod/gbz-base'
5
+ import type { RpcExecuteArgs } from '@jbrowse/core/rpc/RpcRegistry'
6
+ import type { Region } from '@jbrowse/core/util'
7
+
8
+ // Every haplotype classed per bin of a reference window, from the overview a
9
+ // format 3 haplotype index carries: what a GBZ track draws once its window is
10
+ // too large to cut. `rows` labels each haplotype as the track's lanes do,
11
+ // `pinned` lists the rows of the lanes the track names, in their order, and
12
+ // `reference` the reference sample's own rows, which match the reference by
13
+ // construction.
14
+ export interface HaplotypeOverviewData {
15
+ level: number
16
+ bin: number
17
+ rows: string[]
18
+ pinned: number[]
19
+ reference: number[]
20
+ bins: OverviewBin[]
21
+ cells: Uint8Array
22
+ }
23
+
24
+ export interface OverviewAdapterOptions {
25
+ bpPerPx: number
26
+ haplotypes?: string[]
27
+ signal?: AbortSignal
28
+ }
29
+
30
+ export interface GetHaplotypeOverviewArgs {
31
+ adapterConfig: Record<string, unknown>
32
+ region: Region
33
+ bpPerPx: number
34
+ haplotypes?: string[]
35
+ }
36
+
37
+ declare module '@jbrowse/core/rpc/RpcRegistry' {
38
+ interface RpcRegistry {
39
+ GetHaplotypeOverview: {
40
+ args: GetHaplotypeOverviewArgs
41
+ return: HaplotypeOverviewData | undefined
42
+ }
43
+ }
44
+ }
45
+
46
+ interface OverviewAdapter {
47
+ getOverview(
48
+ region: Region,
49
+ opts: OverviewAdapterOptions,
50
+ ): Promise<HaplotypeOverviewData | undefined>
51
+ }
52
+
53
+ function isOverviewAdapter(adapter: object): adapter is OverviewAdapter {
54
+ return (
55
+ 'getOverview' in adapter &&
56
+ typeof (adapter as OverviewAdapter).getOverview === 'function'
57
+ )
58
+ }
59
+
60
+ // With region renaming, as GetSubgraph has, so a bare `6` reaches the adapter
61
+ // as the contig its reference path names
62
+ export default class GetHaplotypeOverview extends RpcMethodTypeWithRenameRegion<'GetHaplotypeOverview'> {
63
+ name = 'GetHaplotypeOverview' as const
64
+
65
+ async execute(args: RpcExecuteArgs<'GetHaplotypeOverview'>) {
66
+ const { adapterConfig, region, bpPerPx, haplotypes, sessionId, signal } =
67
+ args
68
+ const { dataAdapter } = await getAdapter(
69
+ this.pluginManager,
70
+ sessionId,
71
+ adapterConfig,
72
+ )
73
+ return isOverviewAdapter(dataAdapter)
74
+ ? dataAdapter.getOverview(region, { bpPerPx, haplotypes, signal })
75
+ : undefined
76
+ }
77
+ }
@@ -0,0 +1,86 @@
1
+ import { useState } from 'react'
2
+
3
+ import { Dialog } from '@jbrowse/core/ui'
4
+ import {
5
+ Autocomplete,
6
+ Button,
7
+ Checkbox,
8
+ DialogActions,
9
+ DialogContent,
10
+ TextField,
11
+ Typography,
12
+ } from '@mui/material'
13
+ import { observer } from 'mobx-react'
14
+
15
+ import type { GraphPaneModel } from '../model'
16
+
17
+ type WalkPicker = Pick<
18
+ GraphPaneModel,
19
+ 'walkChoices' | 'walkLayers' | 'walkLabel' | 'liftWalks'
20
+ >
21
+
22
+ // Which walks to lift, searched by name, for a graph with more walks than a
23
+ // menu can list
24
+ const ChooseWalksDialog = observer(function ChooseWalksDialog({
25
+ model,
26
+ onClose,
27
+ }: {
28
+ model: WalkPicker
29
+ onClose: () => void
30
+ }) {
31
+ const { walkChoices } = model
32
+ const names = new Set(walkChoices.map(c => c.name))
33
+ const [picked, setPicked] = useState(() =>
34
+ model.walkLayers.map(l => l.walk).filter(name => names.has(name)),
35
+ )
36
+ return (
37
+ <Dialog open onClose={onClose} title="Choose walks">
38
+ <DialogContent>
39
+ <Autocomplete
40
+ multiple
41
+ disableCloseOnSelect
42
+ data-testid="graph-choose-walks"
43
+ options={walkChoices.map(c => c.name)}
44
+ getOptionLabel={name => model.walkLabel(name)}
45
+ value={picked}
46
+ onChange={(_, value) => {
47
+ setPicked(value)
48
+ }}
49
+ renderOption={({ key, ...props }, name, { selected }) => (
50
+ <li key={key} {...props}>
51
+ <Checkbox size="small" checked={selected} />
52
+ {model.walkLabel(name)}
53
+ </li>
54
+ )}
55
+ renderInput={params => (
56
+ <TextField
57
+ {...params}
58
+ autoFocus
59
+ label="Walks"
60
+ placeholder="type to search"
61
+ />
62
+ )}
63
+ />
64
+ <Typography variant="caption" color="text.secondary">
65
+ {walkChoices.length.toLocaleString()} walks in this cut. The ones
66
+ picked are lifted out of the drawing in this order, and the rest
67
+ fades.
68
+ </Typography>
69
+ </DialogContent>
70
+ <DialogActions>
71
+ <Button onClick={onClose}>Cancel</Button>
72
+ <Button
73
+ variant="contained"
74
+ onClick={() => {
75
+ model.liftWalks(picked)
76
+ onClose()
77
+ }}
78
+ >
79
+ Lift these walks
80
+ </Button>
81
+ </DialogActions>
82
+ </Dialog>
83
+ )
84
+ })
85
+
86
+ export default ChooseWalksDialog