jbrowse-plugin-graphgenomeviewer 8.3.7 → 8.3.9

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 (80) hide show
  1. package/dist/chunks/{GbzBaseSyntenyAdapter-4FATZPZG.js → GbzBaseSyntenyAdapter-Z4U7CQ6T.js} +2 -2
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-4FATZPZG.js.map → GbzBaseSyntenyAdapter-Z4U7CQ6T.js.map} +1 -1
  3. package/dist/chunks/{GraphGenomeView-H2Z5NQW4.js → GraphGenomeView-GDZY3NRF.js} +2 -2
  4. package/dist/chunks/{GraphTrackSettingsDialog-LFFJHC7F.js → GraphTrackSettingsDialog-ZSMGGYOZ.js} +2 -2
  5. package/dist/chunks/{HighlightColorDialog-76RJSXSV.js → HighlightColorDialog-MS6UZ5QH.js} +2 -2
  6. package/dist/chunks/{LinearGraphDisplay-VYPF26DJ.js → LinearGraphDisplay-VPKAF7RL.js} +2 -2
  7. package/dist/chunks/{MinigraphBubbleAdapter-WQUZTNDM.js → MinigraphBubbleAdapter-XRQSSGO7.js} +2 -2
  8. package/dist/chunks/{RgfaTabixAdapter-K763K62E.js → RgfaTabixAdapter-2CHBK2KR.js} +2 -2
  9. package/dist/chunks/{WalkFormsAdapter-WJTEKIOB.js → WalkFormsAdapter-5PVAUS7M.js} +2 -2
  10. package/dist/chunks/{WalkTabixSyntenyAdapter-PHRULBP7.js → WalkTabixSyntenyAdapter-2SXFYW5W.js} +2 -2
  11. package/dist/chunks/{chunk-VEI7EAE6.js → chunk-32KSITI2.js} +2 -2
  12. package/dist/chunks/chunk-3TGEST7X.js +4 -0
  13. package/dist/chunks/{chunk-VZNECPSI.js.map → chunk-3TGEST7X.js.map} +3 -3
  14. package/dist/chunks/{chunk-XK4HHKSP.js → chunk-44DOTJB7.js} +2 -2
  15. package/dist/chunks/{chunk-HVDE2ZKA.js → chunk-4NUDB5AY.js} +1 -1
  16. package/dist/chunks/{chunk-HVDE2ZKA.js.map → chunk-4NUDB5AY.js.map} +1 -1
  17. package/dist/chunks/{chunk-47KLT4FL.js → chunk-7CZC4GOZ.js} +2 -2
  18. package/dist/chunks/{chunk-47KLT4FL.js.map → chunk-7CZC4GOZ.js.map} +1 -1
  19. package/dist/chunks/{chunk-6NR64IXK.js → chunk-AK6XQ7XZ.js} +1 -1
  20. package/dist/chunks/{chunk-6NR64IXK.js.map → chunk-AK6XQ7XZ.js.map} +1 -1
  21. package/dist/chunks/{chunk-PVRRW4PM.js → chunk-AZUO4NZ5.js} +2 -2
  22. package/dist/chunks/{chunk-PVRRW4PM.js.map → chunk-AZUO4NZ5.js.map} +1 -1
  23. package/dist/chunks/{chunk-75WJWJ45.js → chunk-BDBFDFIM.js} +2 -2
  24. package/dist/chunks/{chunk-75WJWJ45.js.map → chunk-BDBFDFIM.js.map} +1 -1
  25. package/dist/chunks/chunk-CFW2JQMT.js +4 -0
  26. package/dist/chunks/{chunk-6YK4U5LT.js.map → chunk-CFW2JQMT.js.map} +4 -4
  27. package/dist/chunks/{chunk-CI6VQ2KV.js → chunk-FUKZO5AZ.js} +2 -2
  28. package/dist/chunks/{chunk-CI6VQ2KV.js.map → chunk-FUKZO5AZ.js.map} +1 -1
  29. package/dist/chunks/{chunk-477HYXB2.js → chunk-HPEC3JDC.js} +2 -2
  30. package/dist/chunks/{chunk-3M3UH5JQ.js → chunk-JKW2OX73.js} +1 -1
  31. package/dist/chunks/{chunk-3M3UH5JQ.js.map → chunk-JKW2OX73.js.map} +1 -1
  32. package/dist/chunks/chunk-NB7ZUDO4.js +2 -0
  33. package/dist/chunks/chunk-OFUX4PZY.js +3 -0
  34. package/dist/chunks/chunk-OFUX4PZY.js.map +7 -0
  35. package/dist/chunks/{chunk-DFWLOMRU.js → chunk-P6WBR5MX.js} +2 -2
  36. package/dist/chunks/chunk-PXIHCJUD.js +2 -0
  37. package/dist/chunks/{chunk-XTEZPFP4.js.map → chunk-PXIHCJUD.js.map} +4 -4
  38. package/dist/chunks/{chunk-AILGRHTE.js → chunk-QX7UU3CV.js} +2 -2
  39. package/dist/chunks/{chunk-AILGRHTE.js.map → chunk-QX7UU3CV.js.map} +1 -1
  40. package/dist/chunks/{chunk-SVF6WK42.js → chunk-VT5BHBO6.js} +2 -2
  41. package/dist/chunks/{chunk-SVF6WK42.js.map → chunk-VT5BHBO6.js.map} +1 -1
  42. package/dist/chunks/{chunk-IICQFAGJ.js → chunk-YGTSPKS5.js} +1 -1
  43. package/dist/chunks/{chunk-IICQFAGJ.js.map → chunk-YGTSPKS5.js.map} +1 -1
  44. package/dist/chunks/{chunk-UOWS2HEQ.js → chunk-YRAIRXY6.js} +2 -2
  45. package/dist/chunks/{chunk-UOWS2HEQ.js.map → chunk-YRAIRXY6.js.map} +3 -3
  46. package/dist/chunks/{renderSvg-W2VIM3IT.js → renderSvg-XIBZTOXX.js} +2 -2
  47. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
  48. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +2 -2
  49. package/package.json +2 -2
  50. package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +9 -20
  51. package/src/GraphGenomeView/components/usePaneGestures.ts +2 -3
  52. package/src/GraphGenomeView/model.test.ts +56 -1
  53. package/src/GraphGenomeView/pane/fitViews.ts +8 -7
  54. package/src/GraphGenomeView/pane/graphViews.ts +26 -15
  55. package/src/GraphGenomeView/pane/walkRowViews.ts +16 -25
  56. package/src/GraphGenomeView/walkRowGroups.test.ts +28 -0
  57. package/src/GraphGenomeView/walkRowGroups.ts +64 -54
  58. package/src/GraphGenomeView/walkRowSpans.test.ts +16 -0
  59. package/src/GraphGenomeView/walkRowSpans.ts +61 -40
  60. package/src/version.ts +1 -1
  61. package/dist/chunks/chunk-6YK4U5LT.js +0 -4
  62. package/dist/chunks/chunk-SQBD75UZ.js +0 -2
  63. package/dist/chunks/chunk-VZNECPSI.js +0 -4
  64. package/dist/chunks/chunk-XTEZPFP4.js +0 -2
  65. package/dist/chunks/chunk-YDJ6SDQM.js +0 -3
  66. package/dist/chunks/chunk-YDJ6SDQM.js.map +0 -7
  67. /package/dist/chunks/{GraphGenomeView-H2Z5NQW4.js.map → GraphGenomeView-GDZY3NRF.js.map} +0 -0
  68. /package/dist/chunks/{GraphTrackSettingsDialog-LFFJHC7F.js.map → GraphTrackSettingsDialog-ZSMGGYOZ.js.map} +0 -0
  69. /package/dist/chunks/{HighlightColorDialog-76RJSXSV.js.map → HighlightColorDialog-MS6UZ5QH.js.map} +0 -0
  70. /package/dist/chunks/{LinearGraphDisplay-VYPF26DJ.js.map → LinearGraphDisplay-VPKAF7RL.js.map} +0 -0
  71. /package/dist/chunks/{MinigraphBubbleAdapter-WQUZTNDM.js.map → MinigraphBubbleAdapter-XRQSSGO7.js.map} +0 -0
  72. /package/dist/chunks/{RgfaTabixAdapter-K763K62E.js.map → RgfaTabixAdapter-2CHBK2KR.js.map} +0 -0
  73. /package/dist/chunks/{WalkFormsAdapter-WJTEKIOB.js.map → WalkFormsAdapter-5PVAUS7M.js.map} +0 -0
  74. /package/dist/chunks/{WalkTabixSyntenyAdapter-PHRULBP7.js.map → WalkTabixSyntenyAdapter-2SXFYW5W.js.map} +0 -0
  75. /package/dist/chunks/{chunk-VEI7EAE6.js.map → chunk-32KSITI2.js.map} +0 -0
  76. /package/dist/chunks/{chunk-XK4HHKSP.js.map → chunk-44DOTJB7.js.map} +0 -0
  77. /package/dist/chunks/{chunk-477HYXB2.js.map → chunk-HPEC3JDC.js.map} +0 -0
  78. /package/dist/chunks/{chunk-SQBD75UZ.js.map → chunk-NB7ZUDO4.js.map} +0 -0
  79. /package/dist/chunks/{chunk-DFWLOMRU.js.map → chunk-P6WBR5MX.js.map} +0 -0
  80. /package/dist/chunks/{renderSvg-W2VIM3IT.js.map → renderSvg-XIBZTOXX.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbrowse-plugin-graphgenomeviewer",
3
- "version": "8.3.7",
3
+ "version": "8.3.9",
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": {
@@ -40,7 +40,7 @@
40
40
  "@emotion/react": "^11.14.0",
41
41
  "@emotion/styled": "^11.14.1",
42
42
  "@eslint/js": "^10.0.1",
43
- "@jbrowse/bandage-core": "^12.4.0",
43
+ "@jbrowse/bandage-core": "^12.5.0",
44
44
  "@jbrowse/cli": "^4.3.0",
45
45
  "@jbrowse/mobx-state-tree": "^6.10.0",
46
46
  "@jbrowse/plugin-linear-genome-view": "5.0.0-beta.18",
@@ -1,5 +1,6 @@
1
1
  import { useCallback, useMemo } from 'react'
2
2
 
3
+ import { barEnd } from '@jbrowse/bandage-core/layout/walkRowDraw'
3
4
  import { computed } from 'mobx'
4
5
  import { observer } from 'mobx-react'
5
6
 
@@ -30,16 +31,15 @@ import type { GraphPaneModel } from '../model'
30
31
  function WalkRowSpansCanvas({ model }: { model: GraphPaneModel }) {
31
32
  const spans = useMemo(
32
33
  () =>
33
- computed(() => {
34
- const bars = model.walkRowBars
35
- return bars
34
+ computed(() =>
35
+ model.walkRowBars
36
36
  ? walkRowSpans(
37
- [bars.reference, ...bars.rows],
37
+ model.walkRowList,
38
38
  model.scaleX,
39
39
  model.referenceRampDomain,
40
40
  )
41
- : undefined
42
- }),
41
+ : undefined,
42
+ ),
43
43
  [model],
44
44
  )
45
45
  const paint = useCallback(
@@ -51,17 +51,6 @@ function WalkRowSpansCanvas({ model }: { model: GraphPaneModel }) {
51
51
  if (!bars || !place || !pitch || !painted) {
52
52
  return
53
53
  }
54
- const sections = model.walkRowGroups?.sections
55
- const blocks = sections?.length
56
- ? [
57
- { first: 0, count: 1, rowY: place.rowY(0) },
58
- ...sections.map(s => ({
59
- first: s.first,
60
- count: s.count,
61
- rowY: place.rowY(s.first),
62
- })),
63
- ]
64
- : [{ first: 0, count: bars.rows.length + 1, rowY: place.rowY(0) }]
65
54
  paintWalkRowSpans(ctx, painted, {
66
55
  ...model.screenTransform,
67
56
  width: model.paneWidth,
@@ -69,7 +58,7 @@ function WalkRowSpansCanvas({ model }: { model: GraphPaneModel }) {
69
58
  rowPx: pitch.rowPx,
70
59
  barPx: pitch.barPx,
71
60
  origin: bars.origin,
72
- blocks,
61
+ blocks: place.blocks(bars.rows.length + 1),
73
62
  })
74
63
  },
75
64
  [model, spans],
@@ -172,7 +161,7 @@ const HoveredWalkRow = observer(function HoveredWalkRow({
172
161
  if (!bars || !place || !pitch || !model.hoveredWalkRowText) {
173
162
  return null
174
163
  }
175
- const rows = [bars.reference, ...bars.rows]
164
+ const rows = model.walkRowList
176
165
  const index = rows.findIndex(r => r.name === model.hoveredWalkRow)
177
166
  const row = rows[index]
178
167
  if (!row) {
@@ -184,7 +173,7 @@ const HoveredWalkRow = observer(function HoveredWalkRow({
184
173
  data-testid="graph-walk-row-hovered"
185
174
  x={start.x - 2}
186
175
  y={start.y - pitch.rowPx / 2 - 1}
187
- width={row.bp * model.scaleX + 4}
176
+ width={barEnd(row) * model.scaleX + 4}
188
177
  height={pitch.rowPx + 2}
189
178
  fill="none"
190
179
  stroke="#111"
@@ -380,11 +380,10 @@ export function usePaneGestures(model: GraphPaneModel) {
380
380
  setHoveredChip(was =>
381
381
  was?.label === chip?.label && was?.readout === chip?.readout ? was : chip,
382
382
  )
383
- const bars = model.walkRowBars
384
- if (bars) {
383
+ if (model.walkRowBars) {
385
384
  const i = model.walkRowAt(sx, sy)
386
385
  model.setHoveredWalkRow(
387
- i === undefined ? null : [bars.reference, ...bars.rows][i]!.name,
386
+ i === undefined ? null : model.walkRowList[i]!.name,
388
387
  )
389
388
  }
390
389
  if (model.nodePositions && model.graph) {
@@ -39,7 +39,11 @@ import { walkRowGeneKey } from './pane/fitViews'
39
39
  import { EMPTY_BATCH, SELECT_BRIGHTEN } from './pane/paneBase'
40
40
  import { PANEL_REFERENCE_TUBE, PANEL_TUBES } from './tubeMapPanels'
41
41
  import stateModelFactory from './viewModel'
42
- import { SECTION_HEADER_PX, walkRowTrees } from './walkRowGroups'
42
+ import {
43
+ SECTION_HEADER_PX,
44
+ sectionIndexOf,
45
+ walkRowTrees,
46
+ } from './walkRowGroups'
43
47
  import { walkCutFor } from '../RgfaTabixAdapter/walkCut.ts'
44
48
 
45
49
  import type { GraphLayers } from './graphLayers'
@@ -4797,6 +4801,21 @@ describe('walk rows grouped by a sample column', () => {
4797
4801
  expect(model.walkRowAt(x, y)).toBe(last)
4798
4802
  })
4799
4803
 
4804
+ test('a ribbon stays inside its section rather than crossing a header', async () => {
4805
+ const model = await groupedModel({ layers: { walkRibbons: true } })
4806
+ const flat = model.walkRowRibbons!.length
4807
+ model.setWalkRowGroupBy({ field: 'superpopulation' })
4808
+ const sections = model.walkRowGroups!.sections
4809
+ const ribbons = model.walkRowRibbons!
4810
+ expect(ribbons.length).toBeGreaterThan(0)
4811
+ expect(ribbons.length).toBeLessThan(flat)
4812
+ for (const { row } of ribbons) {
4813
+ expect(sectionIndexOf(sections, row)).toBe(
4814
+ sectionIndexOf(sections, row + 1),
4815
+ )
4816
+ }
4817
+ })
4818
+
4800
4819
  test('a packed cohort fits its rows and headers into the pane', async () => {
4801
4820
  rpcRespond()
4802
4821
  const cohort = [
@@ -5170,6 +5189,42 @@ describe('a walk-file cut', () => {
5170
5189
  )
5171
5190
  })
5172
5191
 
5192
+ // HG004#1 jumps over chr1:1500-4500, so its row is a hairline of no bp
5193
+ test("a deletion row's hairline takes the pointer along its length", async () => {
5194
+ mockRpcCall.mockImplementation(
5195
+ (_sid: unknown, method: string, args: { opts: SubgraphCutOptions }) =>
5196
+ method === 'GetSubgraph'
5197
+ ? Promise.resolve(
5198
+ walkCutFor(
5199
+ {
5200
+ ...WALK_TABLES,
5201
+ skips: {
5202
+ names: ['HG004#1#chr1'],
5203
+ starts: Float64Array.of(1500),
5204
+ ends: Float64Array.of(4500),
5205
+ },
5206
+ },
5207
+ TEST_REGION,
5208
+ args.opts.walkRows,
5209
+ ),
5210
+ )
5211
+ : Promise.reject(new Error(`Unexpected RPC: ${method}`)),
5212
+ )
5213
+ const model = restoredView({ layoutMode: 'walkrows' })
5214
+ await model.load()
5215
+ const rows = model.walkRowList
5216
+ const i = rows.findIndex(r => r.deletionBp !== undefined)
5217
+ const row = rows[i]!
5218
+ const run = row.runs[0]!
5219
+ expect(row.bp).toBe(0)
5220
+ expect(run).toMatchObject({ start: 500, bp: 3000 })
5221
+ const x =
5222
+ (model.walkRowBars!.origin + run.start + run.bp / 2) * model.scaleX +
5223
+ model.translateX
5224
+ const y = model.walkRowPlacement!.rowY(i) * model.scaleY + model.translateY
5225
+ expect(model.walkRowAt(x, y)).toBe(i)
5226
+ })
5227
+
5173
5228
  test('parses its walks whole for a layout that draws nodes', async () => {
5174
5229
  const model = restoredView({ layoutMode: 'walkrows' })
5175
5230
  await model.load()
@@ -11,6 +11,7 @@ import {
11
11
  layoutLabels,
12
12
  } from '@jbrowse/bandage-core/labelLayout'
13
13
  import {
14
+ barEnd,
14
15
  boxesGenes,
15
16
  rowPitch,
16
17
  walkRowReadout,
@@ -35,7 +36,7 @@ import { padded } from '@jbrowse/bandage-core/viewport'
35
36
  import { walkPosition } from '@jbrowse/bandage-core/walkKey'
36
37
  import { untracked } from 'mobx'
37
38
 
38
- import { SECTION_HEADER_PX, sectionPlacement } from '../walkRowGroups'
39
+ import { sectionHeadersPx, sectionPlacement } from '../walkRowGroups'
39
40
  import { withHostViews } from './hostViews'
40
41
  import { fadeEntering } from './morph'
41
42
  import {
@@ -99,12 +100,12 @@ export const withFitViews = withHostViews
99
100
  if (!bars) {
100
101
  return undefined
101
102
  }
102
- const room = this.fitRoom
103
- const headersPx =
104
- (self.walkRowGroups?.sections.length ?? 0) * SECTION_HEADER_PX
105
103
  return rowPitch(
106
104
  bars.rows.length + 1,
107
- room - this.fitPadTop - FIT_PADDING - headersPx,
105
+ this.fitRoom -
106
+ this.fitPadTop -
107
+ FIT_PADDING -
108
+ sectionHeadersPx(self.walkRowGroups?.sections ?? []),
108
109
  )
109
110
  },
110
111
  // Where each walk row and section header sits at the rows' pitch
@@ -214,13 +215,13 @@ export const withFitViews = withHostViews
214
215
  (screenY - self.translateY) / self.scaleY,
215
216
  bars.rows.length + 1,
216
217
  )
217
- const row = [bars.reference, ...bars.rows][i]
218
+ const row = self.walkRowList[i]
218
219
  const y = place.rowY(i) * self.scaleY + self.translateY
219
220
  const bp = (screenX - self.translateX) / self.scaleX - bars.origin
220
221
  return row &&
221
222
  Math.abs(screenY - y) <= pitch.barPx / 2 + 2 &&
222
223
  bp >= 0 &&
223
- bp <= row.bp
224
+ bp <= barEnd(row)
224
225
  ? i
225
226
  : undefined
226
227
  },
@@ -14,7 +14,6 @@ import { facetSettingOf } from '@jbrowse/bandage-core/facetGrid'
14
14
  import { genePins } from '@jbrowse/bandage-core/genes/genePins'
15
15
  import { formatBp } from '@jbrowse/bandage-core/graphLabels'
16
16
  import {
17
- ribbonJoin,
18
17
  sharedRowOrder,
19
18
  walkRowBlocks,
20
19
  walkRowLinks,
@@ -92,7 +91,12 @@ import {
92
91
  valueTubeColors,
93
92
  valueTubePalette,
94
93
  } from '../tubeMapPanels'
95
- import { groupByOf, groupWalkRows, metadataColumns } from '../walkRowGroups'
94
+ import {
95
+ groupByOf,
96
+ groupWalkRows,
97
+ metadataColumns,
98
+ sectionIndexOf,
99
+ } from '../walkRowGroups'
96
100
 
97
101
  import type { ScreenTransform } from './keepInView'
98
102
  import type { WalkCut } from '../../RgfaTabixAdapter/walkCut.ts'
@@ -1027,26 +1031,33 @@ export const withGraphViews = paneBase
1027
1031
  ? { ...bars, rows: this.walkRowGroups?.rows ?? rows }
1028
1032
  : undefined
1029
1033
  },
1034
+ // The reference row and the rows under it, as walk rows index them
1035
+ get walkRowList() {
1036
+ const bars = this.walkRowBars
1037
+ return bars ? [bars.reference, ...bars.rows] : []
1038
+ },
1030
1039
  // Where each row walks the same nodes as the row below it, as bar
1031
- // offsets on both, the reference row first
1040
+ // offsets on both, the reference row first. While grouped, a ribbon
1041
+ // stays inside its section rather than crossing a header.
1032
1042
  get walkRowRibbons() {
1033
- const bars = this.walkRowBars
1034
- if (!self.walkRibbons || !self.rowVisitsNeeded || !bars) {
1035
- return undefined
1036
- }
1037
- const rows = [bars.reference, ...bars.rows]
1038
- return walkRowLinks(rows, ribbonJoin(rows))
1043
+ const sections = this.walkRowGroups?.sections ?? []
1044
+ return self.walkRibbons && self.rowVisitsNeeded && this.walkRowBars
1045
+ ? walkRowLinks(this.walkRowList).filter(
1046
+ ({ row }) =>
1047
+ sectionIndexOf(sections, row) ===
1048
+ sectionIndexOf(sections, row + 1),
1049
+ )
1050
+ : undefined
1039
1051
  },
1040
1052
  // The stretches of each row through a block of nodes off the
1041
1053
  // reference's path that two or more rows walk, block 0 the one with the
1042
1054
  // most bp, which the bars letter A, B, C...
1043
1055
  get sharedBlocks() {
1044
- const bars = this.walkRowBars
1045
- if (!self.layerSet.has('walkBlocks') || !self.rowVisitsNeeded || !bars) {
1046
- return undefined
1047
- }
1048
- const rows = [bars.reference, ...bars.rows]
1049
- return walkRowBlocks(rows, ribbonJoin(rows))
1056
+ return self.layerSet.has('walkBlocks') &&
1057
+ self.rowVisitsNeeded &&
1058
+ this.walkRowBars
1059
+ ? walkRowBlocks(this.walkRowList)
1060
+ : undefined
1050
1061
  },
1051
1062
  // Whether the canvas draws the graph's nodes. A tube map and walk rows
1052
1063
  // draw a picture of their own over it, so what sits on nodes (genes,
@@ -16,7 +16,6 @@ import { withLaunchViews } from './launchViews'
16
16
  import { WALK_GENE_ROWS } from './paneBase'
17
17
  import { resolveLocationAssembly } from '../../launchFromGraph/contributors'
18
18
 
19
- import type { SubgraphRegion } from '../../GetSubgraph'
20
19
  import type { WalkAxis, WalkRow } from '@jbrowse/bandage-core/layout/walkRows'
21
20
  import type { LayoutModeValue } from '@jbrowse/bandage-core/layoutModes'
22
21
 
@@ -110,36 +109,28 @@ export const withWalkRowViews = withLaunchViews
110
109
  if (!bars || !self.showGenes) {
111
110
  return undefined
112
111
  }
113
- const reads: {
114
- row: string
115
- trackId: string
116
- region: SubgraphRegion
117
- }[] = []
118
- let untrackedRows = 0
119
- let unplaced = 0
120
- for (const row of bars.rows) {
121
- if (!row.axis) {
122
- unplaced++
123
- continue
124
- }
125
- const { assembly, span } = self.rowLocation(row, row.axis)
112
+ const notDeleted = bars.rows.filter(row => row.deletionBp === undefined)
113
+ const reads = notDeleted.flatMap(row => {
114
+ const location = row.axis ? self.rowLocation(row, row.axis) : undefined
115
+ const assembly = location?.assembly
126
116
  const track = assembly
127
117
  ? self.geneTracksByAssembly.get(assembly)
128
118
  : undefined
129
- if (!assembly || !track) {
130
- untrackedRows++
131
- continue
132
- }
133
- reads.push({
134
- row: row.name,
135
- trackId: track.trackId,
136
- region: { assemblyName: assembly, ...span },
137
- })
138
- }
119
+ return location && assembly && track
120
+ ? [
121
+ {
122
+ row: row.name,
123
+ trackId: track.trackId,
124
+ region: { assemblyName: assembly, ...location.span },
125
+ },
126
+ ]
127
+ : []
128
+ })
129
+ const unplaced = notDeleted.filter(row => !row.axis).length
139
130
  return {
140
131
  reads: reads.slice(0, WALK_GENE_ROWS),
141
132
  gaps: {
142
- untracked: untrackedRows,
133
+ untracked: notDeleted.length - unplaced - reads.length,
143
134
  unplaced,
144
135
  unread: Math.max(0, reads.length - WALK_GENE_ROWS),
145
136
  },
@@ -4,6 +4,7 @@ import {
4
4
  groupWalkRows,
5
5
  metadataColumns,
6
6
  parseSamplesTsv,
7
+ sectionIndexOf,
7
8
  sectionPlacement,
8
9
  } from './walkRowGroups'
9
10
 
@@ -116,3 +117,30 @@ test('one row pitch across sections, a header strip above each', () => {
116
117
  expect(flat.rowAt(13, 6)).toBe(3)
117
118
  expect(flat.headersPx).toBe(0)
118
119
  })
120
+
121
+ test('each section is a block of rows one pitch apart, under the reference row', () => {
122
+ const sections = [
123
+ { key: 'a', title: 'a', first: 1, count: 2 },
124
+ { key: 'b', title: 'b', first: 3, count: 3 },
125
+ ]
126
+ const place = sectionPlacement(sections, 4)
127
+ expect(place.blocks(6)).toEqual([
128
+ { first: 0, count: 1, rowY: 0 },
129
+ { first: 1, count: 2, rowY: place.rowY(1) },
130
+ { first: 3, count: 3, rowY: place.rowY(3) },
131
+ ])
132
+ expect(sectionPlacement([], 4).blocks(6)).toEqual([
133
+ { first: 0, count: 6, rowY: 0 },
134
+ ])
135
+ expect([0, 1, 2, 3, 5].map(i => sectionIndexOf(sections, i))).toEqual([
136
+ -1, 0, 0, 1, 1,
137
+ ])
138
+ })
139
+
140
+ test('a point past either end names the end row, and a tie the upper row', () => {
141
+ const place = sectionPlacement([], 4)
142
+ expect(place.rowAt(-50, 6)).toBe(0)
143
+ expect(place.rowAt(500, 6)).toBe(5)
144
+ expect(place.rowAt(6, 6)).toBe(1)
145
+ expect(place.rowAt(0, 0)).toBe(0)
146
+ })
@@ -149,44 +149,55 @@ export function groupWalkRows<R extends { sample: string; label: string }>(
149
149
  }
150
150
  }
151
151
 
152
+ export const sectionHeadersPx = (sections: WalkRowSection[]) =>
153
+ sections.length * SECTION_HEADER_PX
154
+
155
+ // The index among `sections` of the one row i stacks in, -1 for the reference
156
+ // row above them all
157
+ export function sectionIndexOf(sections: WalkRowSection[], i: number) {
158
+ return sections.findLastIndex(s => s.first <= i)
159
+ }
160
+
152
161
  // Where rows and section headers sit, in px down from the reference row's
153
162
  // centre, at one row pitch shared by every section: a header strip above
154
163
  // each section's first row pushes every row after it down
155
164
  export function sectionPlacement(sections: WalkRowSection[], rowPx: number) {
156
- const sectionOf = (i: number) => {
157
- let k = -1
158
- while (k + 1 < sections.length && sections[k + 1]!.first <= i) {
159
- k++
160
- }
161
- return k
162
- }
163
- const rowY = (i: number) => i * rowPx + (sectionOf(i) + 1) * SECTION_HEADER_PX
165
+ const rowY = (i: number) =>
166
+ i * rowPx + (sectionIndexOf(sections, i) + 1) * SECTION_HEADER_PX
164
167
  return {
165
168
  rowY,
166
169
  headers: sections.map((s, k) => ({
167
170
  ...s,
168
171
  top: (s.first - 0.5) * rowPx + k * SECTION_HEADER_PX,
169
172
  })),
170
- headersPx: sections.length * SECTION_HEADER_PX,
171
- // the row whose centre is nearest y
173
+ headersPx: sectionHeadersPx(sections),
174
+ // runs of `rows` rows each spaced one pitch apart: the reference row and
175
+ // each section, or every row while ungrouped
176
+ blocks(rows: number) {
177
+ return sections.length
178
+ ? [
179
+ { first: 0, count: 1, rowY: 0 },
180
+ ...sections.map(s => ({
181
+ first: s.first,
182
+ count: s.count,
183
+ rowY: rowY(s.first),
184
+ })),
185
+ ]
186
+ : [{ first: 0, count: rows, rowY: 0 }]
187
+ },
188
+ // the row whose centre is nearest y, the upper of two as near
172
189
  rowAt(y: number, rows: number) {
173
- let best = 0
174
- for (let k = -1; k < sections.length; k++) {
175
- const lo = k < 0 ? 0 : sections[k]!.first
176
- const hi =
177
- k < 0
178
- ? Math.min(rows, sections[0]?.first ?? rows)
179
- : lo + sections[k]!.count
180
- const shift = (k + 1) * SECTION_HEADER_PX
181
- const i = Math.min(
182
- hi - 1,
183
- Math.max(lo, Math.round((y - shift) / rowPx)),
184
- )
185
- if (Math.abs(rowY(i) - y) < Math.abs(rowY(best) - y)) {
186
- best = i
190
+ let lo = 0
191
+ let hi = rows - 1
192
+ while (lo < hi) {
193
+ const mid = (lo + hi) >> 1
194
+ if (rowY(mid) < y) {
195
+ lo = mid + 1
196
+ } else {
197
+ hi = mid
187
198
  }
188
199
  }
189
- return best
200
+ return lo > 0 && y - rowY(lo - 1) <= rowY(lo) - y ? lo - 1 : lo
190
201
  },
191
202
  }
192
203
  }
@@ -202,33 +213,32 @@ export function walkRowTrees(
202
213
  frame: WalkRowsFrame & { rowPx: number },
203
214
  o: Parameters<typeof walkRowsTree>[2] & { idPrefix: string },
204
215
  ): El[] {
205
- if (sections.length === 0) {
206
- return [walkRowsTree(bars, frame, o)]
207
- }
208
- return [
209
- walkRowsTree({ ...bars, rows: [] }, frame, o),
210
- ...sections.flatMap((section, k) => {
211
- const tree = walkRowsTree(
212
- {
213
- ...bars,
214
- rows: bars.rows.slice(
215
- section.first - 1,
216
- section.first - 1 + section.count,
217
- ),
218
- },
219
- {
220
- ...frame,
221
- translateY:
222
- frame.translateY +
223
- (rowY(section.first) - frame.rowPx) * frame.scaleY,
224
- },
225
- { ...o, idPrefix: `${o.idPrefix}-s${k}` },
226
- )
227
- return tree.children.filter(
228
- (c): c is El =>
229
- typeof c !== 'string' &&
230
- c.attrs['data-testid'] !== 'graph-walk-reference',
231
- )
232
- }),
233
- ]
216
+ return sections.length === 0
217
+ ? [walkRowsTree(bars, frame, o)]
218
+ : [
219
+ walkRowsTree({ ...bars, rows: [] }, frame, o),
220
+ ...sections.flatMap((section, k) => {
221
+ const tree = walkRowsTree(
222
+ {
223
+ ...bars,
224
+ rows: bars.rows.slice(
225
+ section.first - 1,
226
+ section.first - 1 + section.count,
227
+ ),
228
+ },
229
+ {
230
+ ...frame,
231
+ translateY:
232
+ frame.translateY +
233
+ (rowY(section.first) - frame.rowPx) * frame.scaleY,
234
+ },
235
+ { ...o, idPrefix: `${o.idPrefix}-s${k}` },
236
+ )
237
+ return tree.children.filter(
238
+ (c): c is El =>
239
+ typeof c !== 'string' &&
240
+ c.attrs['data-testid'] !== 'graph-walk-reference',
241
+ )
242
+ }),
243
+ ]
234
244
  }
@@ -122,6 +122,22 @@ test('a solid run under the ramp is one piece in its own hue', () => {
122
122
  expect(runPieces(off, ramp, frame.scaleX)).toHaveLength(1)
123
123
  })
124
124
 
125
+ test('a hue printed in exponent form reads as the hue it is', () => {
126
+ const rounded = (css: string) => cssRgb(css).map(Math.round)
127
+ expect(rounded('hsl(1e-7, 70%, 50%)')).toEqual(rounded('hsl(0, 70%, 50%)'))
128
+ expect(cssRgb('rgb(10, 20.5, 30)')).toEqual([10, 20.5, 30])
129
+ expect(cssRgb('#0a141e')).toEqual([10, 20, 30])
130
+ })
131
+
132
+ test('each kind of span holds exactly its own pieces', () => {
133
+ const spans = walkRowSpans([bars.reference, ...bars.rows], frame.scaleX)
134
+ expect(spans.gaps.count).toBe(1)
135
+ expect(spans.gaps.x).toHaveLength(1)
136
+ expect(spans.hairlines.x).toHaveLength(0)
137
+ expect(spans.bars.x).toHaveLength(spans.bars.count)
138
+ expect(spans.gapRows.at(-1)).toBe(1)
139
+ })
140
+
125
141
  test('the spans state how far the longest row reaches', () => {
126
142
  const all = [bars.reference, ...bars.rows]
127
143
  expect(walkRowSpans(all, frame.scaleX).longest).toBe(3500)