react-msaview 9.1.0 → 9.1.1

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 (272) hide show
  1. package/bundle/index.js +111 -115
  2. package/bundle/index.js.map +4 -4
  3. package/dist/blosum62.d.ts +3 -0
  4. package/dist/blosum62.js +43 -0
  5. package/dist/blosum62.js.map +1 -0
  6. package/dist/colorSchemes.js +1 -0
  7. package/dist/colorSchemes.js.map +1 -1
  8. package/dist/components/Loading.d.ts +3 -2
  9. package/dist/components/Loading.js +2 -2
  10. package/dist/components/Loading.js.map +1 -1
  11. package/dist/components/MSAView.d.ts +3 -2
  12. package/dist/components/MSAView.js +7 -4
  13. package/dist/components/MSAView.js.map +1 -1
  14. package/dist/components/MSAViewer.d.ts +62 -12
  15. package/dist/components/MetadataTable.d.ts +4 -1
  16. package/dist/components/MetadataTable.js +55 -16
  17. package/dist/components/MetadataTable.js.map +1 -1
  18. package/dist/components/Track.js +6 -0
  19. package/dist/components/Track.js.map +1 -1
  20. package/dist/components/controls.js +2 -1
  21. package/dist/components/controls.js.map +1 -1
  22. package/dist/components/dialogs/AnnotationFileDialog.js +7 -2
  23. package/dist/components/dialogs/AnnotationFileDialog.js.map +1 -1
  24. package/dist/components/dialogs/FeatureDialog.js +2 -2
  25. package/dist/components/dialogs/FeatureDialog.js.map +1 -1
  26. package/dist/components/{header/MSASettingsMenu.d.ts → dialogs/GapThresholdDialog.d.ts} +3 -2
  27. package/dist/components/dialogs/GapThresholdDialog.js +15 -0
  28. package/dist/components/dialogs/GapThresholdDialog.js.map +1 -0
  29. package/dist/components/{header → dialogs}/GappynessSlider.d.ts +1 -1
  30. package/dist/components/{header → dialogs}/GappynessSlider.js +3 -10
  31. package/dist/components/dialogs/GappynessSlider.js.map +1 -0
  32. package/dist/components/{header → dialogs}/GoToBox.d.ts +4 -2
  33. package/dist/components/dialogs/GoToBox.js +48 -0
  34. package/dist/components/dialogs/GoToBox.js.map +1 -0
  35. package/dist/components/dialogs/GoToDialog.d.ts +6 -0
  36. package/dist/components/dialogs/GoToDialog.js +10 -0
  37. package/dist/components/dialogs/GoToDialog.js.map +1 -0
  38. package/dist/components/dialogs/MetadataDialog.js +11 -3
  39. package/dist/components/dialogs/MetadataDialog.js.map +1 -1
  40. package/dist/components/dialogs/goTo.d.ts +5 -0
  41. package/dist/components/{header → dialogs}/goTo.js +1 -1
  42. package/dist/components/dialogs/goTo.js.map +1 -0
  43. package/dist/components/dialogs/metadataLabels.d.ts +4 -0
  44. package/dist/components/dialogs/metadataLabels.js +52 -0
  45. package/dist/components/dialogs/metadataLabels.js.map +1 -0
  46. package/dist/components/dialogs/metadataRecord.d.ts +1 -0
  47. package/dist/components/dialogs/metadataRecord.js +38 -0
  48. package/dist/components/dialogs/metadataRecord.js.map +1 -0
  49. package/dist/components/header/Header.d.ts +6 -2
  50. package/dist/components/header/Header.js +30 -32
  51. package/dist/components/header/Header.js.map +1 -1
  52. package/dist/components/header/{TreeSettingsMenu.d.ts → HiddenColumnsChip.d.ts} +2 -2
  53. package/dist/components/header/HiddenColumnsChip.js +15 -0
  54. package/dist/components/header/HiddenColumnsChip.js.map +1 -0
  55. package/dist/components/header/MenuBar.d.ts +6 -0
  56. package/dist/components/header/MenuBar.js +33 -0
  57. package/dist/components/header/MenuBar.js.map +1 -0
  58. package/dist/components/header/ScrollZoomCheckbox.d.ts +7 -0
  59. package/dist/components/header/ScrollZoomCheckbox.js +19 -0
  60. package/dist/components/header/ScrollZoomCheckbox.js.map +1 -0
  61. package/dist/components/header/ZoomControls.js +10 -30
  62. package/dist/components/header/ZoomControls.js.map +1 -1
  63. package/dist/components/header/colorSchemeMenuItems.d.ts +4 -0
  64. package/dist/components/header/colorSchemeMenuItems.js +106 -0
  65. package/dist/components/header/colorSchemeMenuItems.js.map +1 -0
  66. package/dist/components/header/getAnnotationsMenu.d.ts +3 -30
  67. package/dist/components/header/getAnnotationsMenu.js +48 -54
  68. package/dist/components/header/getAnnotationsMenu.js.map +1 -1
  69. package/dist/components/header/menuBarItems.d.ts +11 -0
  70. package/dist/components/header/menuBarItems.js +277 -0
  71. package/dist/components/header/menuBarItems.js.map +1 -0
  72. package/dist/components/import/ImportForm.js +12 -6
  73. package/dist/components/import/ImportForm.js.map +1 -1
  74. package/dist/components/minimap/Minimap.js +7 -3
  75. package/dist/components/minimap/Minimap.js.map +1 -1
  76. package/dist/components/minimap/MinimapSVG.js +2 -1
  77. package/dist/components/minimap/MinimapSVG.js.map +1 -1
  78. package/dist/components/minimap/minimapLayout.d.ts +12 -0
  79. package/dist/components/minimap/minimapLayout.js +20 -0
  80. package/dist/components/minimap/minimapLayout.js.map +1 -1
  81. package/dist/components/msa/MSACanvas.js +26 -9
  82. package/dist/components/msa/MSACanvas.js.map +1 -1
  83. package/dist/components/msa/MSACanvasBlock.js +15 -11
  84. package/dist/components/msa/MSACanvasBlock.js.map +1 -1
  85. package/dist/components/msa/MSAMouseoverCanvas.js +2 -2
  86. package/dist/components/msa/MSAMouseoverCanvas.js.map +1 -1
  87. package/dist/components/msa/WheelZoomHint.d.ts +7 -0
  88. package/dist/components/msa/WheelZoomHint.js +38 -0
  89. package/dist/components/msa/WheelZoomHint.js.map +1 -0
  90. package/dist/components/msa/msaKeys.js +3 -0
  91. package/dist/components/msa/msaKeys.js.map +1 -1
  92. package/dist/components/msa/msaRaster.d.ts +4 -5
  93. package/dist/components/msa/msaRaster.js +5 -5
  94. package/dist/components/msa/msaRaster.js.map +1 -1
  95. package/dist/components/msa/renderBoxFeatureCanvasBlock.js +22 -2
  96. package/dist/components/msa/renderBoxFeatureCanvasBlock.js.map +1 -1
  97. package/dist/components/msa/renderHighlights.d.ts +0 -3
  98. package/dist/components/msa/renderHighlights.js +3 -3
  99. package/dist/components/msa/renderHighlights.js.map +1 -1
  100. package/dist/components/msa/renderMSABlock.d.ts +6 -1
  101. package/dist/components/msa/renderMSABlock.js +44 -17
  102. package/dist/components/msa/renderMSABlock.js.map +1 -1
  103. package/dist/components/msa/tileColor.js +7 -0
  104. package/dist/components/msa/tileColor.js.map +1 -1
  105. package/dist/components/rowpanels/RowPanelBlock.js +2 -2
  106. package/dist/components/rowpanels/RowPanelBlock.js.map +1 -1
  107. package/dist/components/settings/MenuItemsForm.d.ts +10 -0
  108. package/dist/components/settings/MenuItemsForm.js +80 -0
  109. package/dist/components/settings/MenuItemsForm.js.map +1 -0
  110. package/dist/components/settings/SettingsPanel.d.ts +12 -0
  111. package/dist/components/settings/SettingsPanel.js +92 -0
  112. package/dist/components/settings/SettingsPanel.js.map +1 -0
  113. package/dist/components/{header/FileMenu.d.ts → settings/TrackList.d.ts} +2 -2
  114. package/dist/components/settings/TrackList.js +55 -0
  115. package/dist/components/settings/TrackList.js.map +1 -0
  116. package/dist/components/tracks/TrackBlocks.js +2 -2
  117. package/dist/components/tracks/TrackBlocks.js.map +1 -1
  118. package/dist/components/tree/TreeCanvasBlock.js +2 -2
  119. package/dist/components/tree/TreeCanvasBlock.js.map +1 -1
  120. package/dist/components/tree/TreeMenu.js +4 -6
  121. package/dist/components/tree/TreeMenu.js.map +1 -1
  122. package/dist/components/tree/TreeOverview.js +2 -2
  123. package/dist/components/tree/TreeOverview.js.map +1 -1
  124. package/dist/constants.d.ts +4 -1
  125. package/dist/constants.js +7 -1
  126. package/dist/constants.js.map +1 -1
  127. package/dist/darkReader.d.ts +7 -0
  128. package/dist/darkReader.js +42 -0
  129. package/dist/darkReader.js.map +1 -0
  130. package/dist/element.js +22 -47
  131. package/dist/element.js.map +1 -1
  132. package/dist/featurePanels.d.ts +37 -0
  133. package/dist/featurePanels.js +187 -0
  134. package/dist/featurePanels.js.map +1 -0
  135. package/dist/filehandleLoader.d.ts +41 -0
  136. package/dist/filehandleLoader.js +99 -0
  137. package/dist/filehandleLoader.js.map +1 -0
  138. package/dist/index.d.ts +3 -0
  139. package/dist/index.js +2 -0
  140. package/dist/index.js.map +1 -1
  141. package/dist/model/treeModel.d.ts +9 -0
  142. package/dist/model/treeModel.js +12 -1
  143. package/dist/model/treeModel.js.map +1 -1
  144. package/dist/model.d.ts +142 -32
  145. package/dist/model.js +268 -569
  146. package/dist/model.js.map +1 -1
  147. package/dist/neighborJoining.js +1 -40
  148. package/dist/neighborJoining.js.map +1 -1
  149. package/dist/renderToSvg.js +1 -13
  150. package/dist/renderToSvg.js.map +1 -1
  151. package/dist/rerootTree.d.ts +1 -0
  152. package/dist/rerootTree.js +7 -6
  153. package/dist/rerootTree.js.map +1 -1
  154. package/dist/schemeResidueColor.d.ts +12 -0
  155. package/dist/schemeResidueColor.js +33 -0
  156. package/dist/schemeResidueColor.js.map +1 -0
  157. package/dist/similarityColors.d.ts +11 -0
  158. package/dist/similarityColors.js +90 -0
  159. package/dist/similarityColors.js.map +1 -0
  160. package/dist/svgTestUtil.d.ts +62 -12
  161. package/dist/treeDisplay.d.ts +37 -0
  162. package/dist/treeDisplay.js +209 -0
  163. package/dist/treeDisplay.js.map +1 -0
  164. package/dist/types.d.ts +6 -2
  165. package/dist/useWheelScroll.d.ts +3 -1
  166. package/dist/useWheelScroll.js +36 -17
  167. package/dist/useWheelScroll.js.map +1 -1
  168. package/dist/util.d.ts +2 -0
  169. package/dist/util.js +2 -0
  170. package/dist/util.js.map +1 -1
  171. package/dist/version.d.ts +1 -1
  172. package/dist/version.js +1 -1
  173. package/dist/wheelZoom.d.ts +8 -3
  174. package/dist/wheelZoom.js +44 -32
  175. package/dist/wheelZoom.js.map +1 -1
  176. package/dist/zoomSnapshot.d.ts +29 -0
  177. package/dist/zoomSnapshot.js +47 -0
  178. package/dist/zoomSnapshot.js.map +1 -0
  179. package/package.json +11 -11
  180. package/src/blosum62.ts +45 -0
  181. package/src/colorSchemes.ts +1 -0
  182. package/src/components/Loading.tsx +6 -2
  183. package/src/components/MSAView.tsx +22 -5
  184. package/src/components/MetadataTable.tsx +83 -26
  185. package/src/components/Track.tsx +13 -0
  186. package/src/components/controls.ts +2 -1
  187. package/src/components/dialogs/AnnotationFileDialog.tsx +12 -1
  188. package/src/components/dialogs/FeatureDialog.tsx +2 -5
  189. package/src/components/dialogs/GapThresholdDialog.tsx +36 -0
  190. package/src/components/{header → dialogs}/GappynessSlider.tsx +3 -10
  191. package/src/components/{header → dialogs}/GoToBox.tsx +36 -10
  192. package/src/components/dialogs/GoToDialog.tsx +30 -0
  193. package/src/components/dialogs/MetadataDialog.tsx +32 -4
  194. package/src/components/{header → dialogs}/goTo.ts +1 -1
  195. package/src/components/dialogs/metadataLabels.ts +54 -0
  196. package/src/components/dialogs/metadataRecord.tsx +61 -0
  197. package/src/components/header/Header.tsx +75 -42
  198. package/src/components/header/HiddenColumnsChip.tsx +39 -0
  199. package/src/components/header/MenuBar.tsx +64 -0
  200. package/src/components/header/ScrollZoomCheckbox.tsx +46 -0
  201. package/src/components/header/ZoomControls.tsx +20 -35
  202. package/src/components/header/colorSchemeMenuItems.ts +121 -0
  203. package/src/components/header/getAnnotationsMenu.ts +52 -56
  204. package/src/components/header/menuBarItems.ts +357 -0
  205. package/src/components/import/ImportForm.tsx +19 -7
  206. package/src/components/minimap/Minimap.tsx +11 -3
  207. package/src/components/minimap/MinimapSVG.tsx +17 -1
  208. package/src/components/minimap/minimapLayout.ts +27 -0
  209. package/src/components/msa/MSACanvas.tsx +22 -3
  210. package/src/components/msa/MSACanvasBlock.tsx +18 -11
  211. package/src/components/msa/MSAMouseoverCanvas.tsx +2 -2
  212. package/src/components/msa/WheelZoomHint.tsx +56 -0
  213. package/src/components/msa/msaKeys.ts +3 -0
  214. package/src/components/msa/msaRaster.ts +6 -8
  215. package/src/components/msa/renderBoxFeatureCanvasBlock.ts +28 -5
  216. package/src/components/msa/renderHighlights.ts +3 -3
  217. package/src/components/msa/renderMSABlock.ts +51 -15
  218. package/src/components/msa/tileColor.ts +7 -0
  219. package/src/components/rowpanels/RowPanelBlock.tsx +2 -2
  220. package/src/components/settings/MenuItemsForm.tsx +225 -0
  221. package/src/components/settings/SettingsPanel.tsx +156 -0
  222. package/src/components/settings/TrackList.tsx +119 -0
  223. package/src/components/tracks/TrackBlocks.tsx +2 -2
  224. package/src/components/tree/TreeCanvasBlock.tsx +2 -2
  225. package/src/components/tree/TreeMenu.tsx +4 -6
  226. package/src/components/tree/TreeOverview.tsx +2 -2
  227. package/src/constants.ts +9 -1
  228. package/src/darkReader.ts +57 -0
  229. package/src/element.ts +34 -57
  230. package/src/featurePanels.ts +269 -0
  231. package/src/filehandleLoader.ts +136 -0
  232. package/src/index.ts +4 -0
  233. package/src/model/treeModel.ts +13 -0
  234. package/src/model.ts +345 -748
  235. package/src/neighborJoining.ts +1 -42
  236. package/src/renderToSvg.tsx +1 -13
  237. package/src/rerootTree.ts +7 -6
  238. package/src/schemeResidueColor.ts +37 -0
  239. package/src/similarityColors.ts +112 -0
  240. package/src/treeDisplay.ts +278 -0
  241. package/src/types.ts +6 -3
  242. package/src/useWheelScroll.ts +43 -22
  243. package/src/util.ts +3 -0
  244. package/src/version.ts +1 -1
  245. package/src/wheelZoom.ts +55 -33
  246. package/src/zoomSnapshot.ts +80 -0
  247. package/dist/components/header/ColorSchemeMenu.d.ts +0 -12
  248. package/dist/components/header/ColorSchemeMenu.js +0 -37
  249. package/dist/components/header/ColorSchemeMenu.js.map +0 -1
  250. package/dist/components/header/FileMenu.js +0 -92
  251. package/dist/components/header/FileMenu.js.map +0 -1
  252. package/dist/components/header/GappynessSlider.js.map +0 -1
  253. package/dist/components/header/GoToBox.js +0 -31
  254. package/dist/components/header/GoToBox.js.map +0 -1
  255. package/dist/components/header/MSASettingsMenu.js +0 -11
  256. package/dist/components/header/MSASettingsMenu.js.map +0 -1
  257. package/dist/components/header/ScrollZoomIcons.d.ts +0 -6
  258. package/dist/components/header/ScrollZoomIcons.js +0 -35
  259. package/dist/components/header/ScrollZoomIcons.js.map +0 -1
  260. package/dist/components/header/TreeSettingsMenu.js +0 -11
  261. package/dist/components/header/TreeSettingsMenu.js.map +0 -1
  262. package/dist/components/header/goTo.d.ts +0 -20
  263. package/dist/components/header/goTo.js.map +0 -1
  264. package/dist/components/header/settingsMenuItems.d.ts +0 -5
  265. package/dist/components/header/settingsMenuItems.js +0 -171
  266. package/dist/components/header/settingsMenuItems.js.map +0 -1
  267. package/src/components/header/ColorSchemeMenu.tsx +0 -56
  268. package/src/components/header/FileMenu.tsx +0 -107
  269. package/src/components/header/MSASettingsMenu.tsx +0 -26
  270. package/src/components/header/ScrollZoomIcons.tsx +0 -52
  271. package/src/components/header/TreeSettingsMenu.tsx +0 -30
  272. package/src/components/header/settingsMenuItems.ts +0 -216
@@ -0,0 +1,269 @@
1
+ import { notEmpty } from '@jbrowse/core/util'
2
+
3
+ import { packDomainLanes } from './components/msa/packDomainLanes.ts'
4
+ import { defaultFeaturePanelWidth } from './constants.ts'
5
+ import { featureField } from './featureFields.ts'
6
+ import { resolveScale } from './scales.ts'
7
+ import { outlineColor } from './util.ts'
8
+
9
+ import type { ScaleSpec } from './scales.ts'
10
+ import type {
11
+ Annotation,
12
+ DomainBand,
13
+ RowFeaturesSpec,
14
+ RowPanelSpan,
15
+ RowPanelSpec,
16
+ } from './types.ts'
17
+
18
+ // the fill of a span under a scale that gives its value no color, such as a
19
+ // gene a `map` over gene names leaves out
20
+ const UNSCALED_FEATURE = '#d9d9d9'
21
+
22
+ // the fraction of a span a following one may cover before it takes a lane of
23
+ // its own in a `features` panel
24
+ const laneOverlap = 0.1
25
+
26
+ // a row panel's own width, or a default: the row height, which makes a strip
27
+ // cell square, and a gene neighborhood's width for a features panel. The row
28
+ // height is read only when used, so a panel with a width of its own does not
29
+ // recompute on a vertical zoom
30
+ export function rowPanelWidth(
31
+ panel: RowPanelSpec,
32
+ view: { rowHeight: number },
33
+ ) {
34
+ return (
35
+ panel.width ??
36
+ (panel.kind === 'features' ? defaultFeaturePanelWidth : view.rowHeight)
37
+ )
38
+ }
39
+
40
+ // one row of the row table as the channels read it. A number or a boolean
41
+ // reads as its string, the way a GFF value does, and null or an object drops
42
+ export function stringFields(row: unknown) {
43
+ if (typeof row !== 'object' || row === null) {
44
+ return undefined
45
+ }
46
+ const fields: Record<string, string> = {}
47
+ for (const [field, value] of Object.entries(row)) {
48
+ if (typeof value === 'string') {
49
+ fields[field] = value
50
+ } else if (typeof value === 'number' || typeof value === 'boolean') {
51
+ fields[field] = String(value)
52
+ }
53
+ }
54
+ return fields
55
+ }
56
+
57
+ // the color each row takes from a field of the row table under a scale
58
+ export function colorByRow(
59
+ rowData: Record<string, Record<string, string> | undefined>,
60
+ field: string,
61
+ colorOf: (value: string) => string | undefined,
62
+ ) {
63
+ const colors = new Map<string, string>()
64
+ for (const [name, row] of Object.entries(rowData)) {
65
+ const value = row?.[field]
66
+ const color = value === undefined ? undefined : colorOf(value)
67
+ if (color) {
68
+ colors.set(name, color)
69
+ }
70
+ }
71
+ return colors
72
+ }
73
+
74
+ // the fill and outline of every feature in a list: its own GFF `color=` first,
75
+ // then the scale an encoding resolves over one of its fields, then the
76
+ // accession palette
77
+ export function featureColorMap(
78
+ annotations: Annotation[],
79
+ encoding:
80
+ | { field: string; colorOf: (value: string) => string | undefined }
81
+ | undefined,
82
+ fillPalette: Record<string, string>,
83
+ ) {
84
+ const strokes = new Map<string, string>()
85
+ const strokeOf = (fill: string) => {
86
+ const hit = strokes.get(fill)
87
+ if (hit !== undefined) {
88
+ return hit
89
+ }
90
+ const stroke = outlineColor(fill)
91
+ strokes.set(fill, stroke)
92
+ return stroke
93
+ }
94
+ return new Map(
95
+ annotations.map(annotation => {
96
+ const value = encoding
97
+ ? featureField(annotation, encoding.field)
98
+ : undefined
99
+ const fill =
100
+ annotation.color ??
101
+ (value === undefined ? undefined : encoding!.colorOf(value)) ??
102
+ (encoding ? UNSCALED_FEATURE : fillPalette[annotation.accession]!)
103
+ return [annotation, { fill, stroke: strokeOf(fill) }]
104
+ }),
105
+ )
106
+ }
107
+
108
+ // the text a label channel draws inside each span, for the features carrying
109
+ // the field it names
110
+ export function featureLabelMap(annotations: Annotation[], field: string) {
111
+ const labels = new Map<Annotation, string>()
112
+ for (const annotation of annotations) {
113
+ const value = featureField(annotation, field)
114
+ if (value !== undefined) {
115
+ labels.set(annotation, value)
116
+ }
117
+ }
118
+ return labels
119
+ }
120
+
121
+ /** what `packDomainLanes` needs to lay a row out, before it has its lane */
122
+ type Unlaned = Omit<RowPanelSpan, 'lane' | 'laneCount'> & {
123
+ startCol: number
124
+ endCol: number
125
+ }
126
+
127
+ /**
128
+ * Lanes for `position: "strandpile"`, gggenomes' `position_strandpile`: the
129
+ * forward features stack above the line and the reverse below it, each strand
130
+ * packing on its own. The deepest row on each side sets the grid every row lays
131
+ * out on, so the line between the strands sits at one height down the panel and
132
+ * a reader can scan it. A feature with no strand piles with the forward ones.
133
+ */
134
+ function strandpileLanes(
135
+ rows: [string, Unlaned[]][],
136
+ ): Map<string, RowPanelSpan[]> {
137
+ const piled = rows.map(([name, bands]) => {
138
+ const reverse = packDomainLanes(
139
+ bands.filter(b => b.annotation.strand === -1),
140
+ )
141
+ const forward = packDomainLanes(
142
+ bands.filter(b => b.annotation.strand !== -1),
143
+ )
144
+ return { name, forward, reverse }
145
+ })
146
+ const up = Math.max(0, ...piled.map(p => p.forward[0]?.laneCount ?? 0))
147
+ const down = Math.max(0, ...piled.map(p => p.reverse[0]?.laneCount ?? 0))
148
+ const laneCount = up + down
149
+ return new Map(
150
+ piled.map(({ name, forward, reverse }) => [
151
+ name,
152
+ [
153
+ // forward level 0 is the lane just above the line, stacking upward
154
+ ...forward.map(b => ({ ...b, lane: up - 1 - b.lane, laneCount })),
155
+ ...reverse.map(b => ({ ...b, lane: up + b.lane, laneCount })),
156
+ ],
157
+ ]),
158
+ )
159
+ }
160
+
161
+ /** one row's spans laid out by the panel's `position` */
162
+ function panelLanes(
163
+ panel: RowFeaturesSpec,
164
+ rows: [string, Unlaned[]][],
165
+ ): Map<string, RowPanelSpan[]> {
166
+ return panel.position === 'strandpile'
167
+ ? strandpileLanes(rows)
168
+ : new Map(rows.map(([name, bands]) => [name, packDomainLanes(bands)]))
169
+ }
170
+
171
+ /**
172
+ * The spans a `features` panel draws, keyed by row name and measured in the
173
+ * panel's own pixels. `column` takes the bands the overlay draws, at the
174
+ * alignment's column width. `position` packs each row's features in its own
175
+ * residue positions, shifted by an `align` transform, and maps the extent they
176
+ * cover across every row onto the panel width, so a row with no alignment
177
+ * still has an x.
178
+ */
179
+ export function featurePanelSpans({
180
+ panel,
181
+ width,
182
+ colWidth,
183
+ domainBands,
184
+ annotationsByRow,
185
+ shifts,
186
+ }: {
187
+ panel: RowFeaturesSpec
188
+ width: number
189
+ colWidth: number
190
+ domainBands: Map<string, DomainBand[]>
191
+ annotationsByRow: Record<string, Annotation[]>
192
+ shifts: Map<string, number> | undefined
193
+ }): Map<string, RowPanelSpan[]> {
194
+ if (panel.x === 'column') {
195
+ return panelLanes(
196
+ panel,
197
+ [...domainBands].map(([name, bands]) => [
198
+ name,
199
+ bands.map(band => ({
200
+ ...band,
201
+ xStart: band.startCol * colWidth,
202
+ xEnd: band.endCol * colWidth,
203
+ })),
204
+ ]),
205
+ )
206
+ }
207
+ const shifted = Object.entries(annotationsByRow).map(
208
+ ([name, annotations]) => {
209
+ const shift = shifts?.get(name) ?? 0
210
+ return [
211
+ name,
212
+ annotations.map(annotation => ({
213
+ annotation,
214
+ start: annotation.start - 1 + shift,
215
+ end: annotation.end + shift,
216
+ })),
217
+ ] as const
218
+ },
219
+ )
220
+ let min = Infinity
221
+ let max = -Infinity
222
+ for (const [, features] of shifted) {
223
+ for (const { start, end } of features) {
224
+ min = Math.min(min, start)
225
+ max = Math.max(max, end)
226
+ }
227
+ }
228
+ // a gene arrow ends where its feature does, so the extent maps onto the whole
229
+ // panel less the pixel the rightmost stroke needs
230
+ const drawable = Math.max(1, width - 1)
231
+ const scale = max > min ? drawable / (max - min) : 0
232
+ // a lane opens where a span covers more than a tenth of the one before it,
233
+ // which keeps the genes of an operon on one lane: adjacent genes commonly
234
+ // share a few bases, and a stop codon overlapping the next start reads as a
235
+ // second lane over the whole row
236
+ return panelLanes(
237
+ panel,
238
+ shifted.map(([name, features]) => [
239
+ name,
240
+ features.map(({ annotation, start, end }) => ({
241
+ annotation,
242
+ xStart: (start - min) * scale,
243
+ xEnd: (end - min) * scale,
244
+ startCol: start,
245
+ endCol: end - (end - start) * laneOverlap,
246
+ })),
247
+ ]),
248
+ )
249
+ }
250
+
251
+ // a scale over the values a field takes across every feature loaded, so hiding
252
+ // a type in the filter dialog leaves the rest in their colors, and a legend of
253
+ // the values the features drawn carry
254
+ export function resolveFeatureScale(
255
+ field: string,
256
+ scale: ScaleSpec | undefined,
257
+ annotations: Annotation[],
258
+ drawn: Annotation[],
259
+ ) {
260
+ const valuesOf = (list: Annotation[]) =>
261
+ list.map(a => featureField(a, field)).filter(notEmpty)
262
+ const resolved = resolveScale(scale, valuesOf(annotations))
263
+ const shown = new Set(valuesOf(drawn))
264
+ return {
265
+ field,
266
+ ...resolved,
267
+ legend: resolved.legend.filter(entry => shown.has(entry.id)),
268
+ }
269
+ }
@@ -0,0 +1,136 @@
1
+ import { openLocation } from '@jbrowse/core/util/io'
2
+ import { addDisposer, isAlive } from '@jbrowse/mobx-state-tree'
3
+ import { autorun, transaction } from 'mobx'
4
+
5
+ import { fetchTextWithProgress, isAbortError } from './fetchUtils.ts'
6
+
7
+ import type { FetchStatus } from './fetchUtils.ts'
8
+ import type { FileLocation } from '@jbrowse/core/util/types'
9
+ import type { IStateTreeNode } from '@jbrowse/mobx-state-tree'
10
+
11
+ interface LoaderHost extends IStateTreeNode {
12
+ setStatus: (status?: FetchStatus) => void
13
+ setError: (error?: unknown) => void
14
+ addWarning: (warning: string) => void
15
+ }
16
+
17
+ interface FilehandleLoader {
18
+ /** the layer's name in a failure message */
19
+ what: string
20
+ getFilehandle: () => FileLocation | undefined
21
+ onLoad: (text: string) => void
22
+ setLoading?: (loading: boolean) => void
23
+ /** runs after a local file loads, since a blob has no URL to refetch, and on cancel */
24
+ clearFilehandle?: () => void
25
+ /** a failure adds a warning instead of an error */
26
+ optional?: boolean
27
+ }
28
+
29
+ /**
30
+ * Latest-wins abort rotation, after `createAbortRotation` in
31
+ * jbrowse-components. Each `begin()` aborts the previous fetch and returns a
32
+ * signal with an `isCurrent()` guard; gate every write after an await on it so a
33
+ * superseded or torn-down fetch cannot overwrite fresher data. `end()` in the
34
+ * `finally` closes the guard of a fetch that completed.
35
+ */
36
+ export function createAbortRotation(self: IStateTreeNode) {
37
+ let current: { controller: AbortController; ended: boolean } | undefined
38
+ return {
39
+ /** aborts the running fetch, and returns whether one was running */
40
+ cancel() {
41
+ const running = current !== undefined && !current.ended
42
+ current?.controller.abort()
43
+ current = undefined
44
+ return running
45
+ },
46
+ begin() {
47
+ current?.controller.abort()
48
+ const mine = { controller: new AbortController(), ended: false }
49
+ current = mine
50
+ return {
51
+ controller: mine.controller,
52
+ isCurrent: () => !mine.ended && mine === current && isAlive(self),
53
+ end() {
54
+ mine.ended = true
55
+ },
56
+ }
57
+ },
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Fetches the filehandle whenever it changes and hands the text to `onLoad`. A
63
+ * superseded or cleared request is aborted and clears its status line.
64
+ */
65
+ export function installFilehandleLoader(
66
+ self: LoaderHost,
67
+ {
68
+ what,
69
+ getFilehandle,
70
+ onLoad,
71
+ setLoading,
72
+ clearFilehandle,
73
+ optional = false,
74
+ }: FilehandleLoader,
75
+ ) {
76
+ const rotation = createAbortRotation(self)
77
+ const cancel = () => {
78
+ if (rotation.cancel() && isAlive(self)) {
79
+ self.setStatus(undefined)
80
+ }
81
+ }
82
+ addDisposer(self, cancel)
83
+ addDisposer(
84
+ self,
85
+ autorun(async () => {
86
+ const filehandle = getFilehandle()
87
+ cancel()
88
+ if (!filehandle) {
89
+ setLoading?.(false)
90
+ return
91
+ }
92
+ const { controller, isCurrent, end } = rotation.begin()
93
+ try {
94
+ setLoading?.(true)
95
+ if (!optional) {
96
+ self.setError(undefined)
97
+ }
98
+ const text = await fetchTextWithProgress(
99
+ openLocation(filehandle),
100
+ status => {
101
+ if (isCurrent()) {
102
+ self.setStatus(status)
103
+ }
104
+ },
105
+ { controller },
106
+ )
107
+ if (isCurrent()) {
108
+ transaction(() => {
109
+ onLoad(text)
110
+ if (filehandle.locationType === 'BlobLocation') {
111
+ clearFilehandle?.()
112
+ }
113
+ })
114
+ }
115
+ } catch (e) {
116
+ if (isCurrent()) {
117
+ if (isAbortError(e)) {
118
+ clearFilehandle?.()
119
+ } else {
120
+ console.error(e)
121
+ if (optional) {
122
+ self.addWarning(`The ${what} did not load: ${e}`)
123
+ } else {
124
+ self.setError(e)
125
+ }
126
+ }
127
+ }
128
+ } finally {
129
+ if (isCurrent()) {
130
+ setLoading?.(false)
131
+ }
132
+ end()
133
+ }
134
+ }),
135
+ )
136
+ }
package/src/index.ts CHANGED
@@ -25,10 +25,13 @@ export type {
25
25
  RegionShorthand,
26
26
  } from './expandSpec.ts'
27
27
  export { default as MSAView } from './components/Loading.tsx'
28
+ export type { ToolbarSlots } from './components/header/Header.tsx'
28
29
  export { default as MSAViewer } from './components/MSAViewer.tsx'
29
30
  export type { MSAViewerProps } from './components/MSAViewer.tsx'
30
31
  // the snapshot MSAViewer builds from its props, for the CLI's --props
31
32
  export { resolveTheme, viewerSnapshot } from './viewerSnapshot.ts'
33
+ // the active scheme's hex color for a row residue, to paint a structure with
34
+ export { schemeResidueColor } from './schemeResidueColor.ts'
32
35
  export { mount } from './mount.tsx'
33
36
  export { defineMsaElement } from './element.ts'
34
37
  export { useMsaSvgFigure } from './useMsaSvgFigure.ts'
@@ -47,6 +50,7 @@ export type { InterProScanResults } from 'msa-parsers'
47
50
  // reason.
48
51
  export type { ColumnCounts } from './columnCounts.ts'
49
52
  export type { ColumnStats } from './columnStats.ts'
53
+ export type { ZoomSnapshot } from './zoomSnapshot.ts'
50
54
  // the scale an encoding reads its field through, and what resolving one gives
51
55
  export type { ResolvedScale, ScaleSpec } from './scales.ts'
52
56
  export type {
@@ -10,6 +10,7 @@ import {
10
10
  defaultShowBranchLen,
11
11
  defaultTreeOrder,
12
12
  defaultShowTreeOverview,
13
+ defaultShowTreeScaleBar,
13
14
  treeOrders,
14
15
  } from '../constants.ts'
15
16
  import { stripDefault } from '../stripDefault.ts'
@@ -93,6 +94,12 @@ export function TreeModelF() {
93
94
  */
94
95
  showTreeOverview: stripDefault(types.boolean, defaultShowTreeOverview),
95
96
 
97
+ /**
98
+ * #property
99
+ * draw the branch-length scale bar above the tree of a phylogram
100
+ */
101
+ showTreeScaleBar: stripDefault(types.boolean, defaultShowTreeScaleBar),
102
+
96
103
  /**
97
104
  * #property
98
105
  * height of the tree overview band, px
@@ -163,6 +170,12 @@ export function TreeModelF() {
163
170
  setShowTreeOverview(arg: boolean) {
164
171
  self.showTreeOverview = arg
165
172
  },
173
+ /**
174
+ * #action
175
+ */
176
+ setShowTreeScaleBar(arg: boolean) {
177
+ self.showTreeScaleBar = arg
178
+ },
166
179
  /**
167
180
  * #action
168
181
  */