jbrowse-plugin-tview 2.0.4

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 (81) hide show
  1. package/README.md +59 -0
  2. package/dist/AddHighlightModel/GenomeMouseoverHighlight.d.ts +6 -0
  3. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js +23 -0
  4. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js.map +1 -0
  5. package/dist/AddHighlightModel/Highlight.d.ts +10 -0
  6. package/dist/AddHighlightModel/Highlight.js +15 -0
  7. package/dist/AddHighlightModel/Highlight.js.map +1 -0
  8. package/dist/AddHighlightModel/HighlightComponents.d.ts +7 -0
  9. package/dist/AddHighlightModel/HighlightComponents.js +11 -0
  10. package/dist/AddHighlightModel/HighlightComponents.js.map +1 -0
  11. package/dist/AddHighlightModel/MsaToGenomeHighlight.d.ts +6 -0
  12. package/dist/AddHighlightModel/MsaToGenomeHighlight.js +15 -0
  13. package/dist/AddHighlightModel/MsaToGenomeHighlight.js.map +1 -0
  14. package/dist/AddHighlightModel/index.d.ts +2 -0
  15. package/dist/AddHighlightModel/index.js +19 -0
  16. package/dist/AddHighlightModel/index.js.map +1 -0
  17. package/dist/AddHighlightModel/util.d.ts +9 -0
  18. package/dist/AddHighlightModel/util.js +14 -0
  19. package/dist/AddHighlightModel/util.js.map +1 -0
  20. package/dist/LaunchTView/align.d.ts +20 -0
  21. package/dist/LaunchTView/align.js +121 -0
  22. package/dist/LaunchTView/align.js.map +1 -0
  23. package/dist/LaunchTView/components/LaunchTViewDialog.d.ts +6 -0
  24. package/dist/LaunchTView/components/LaunchTViewDialog.js +87 -0
  25. package/dist/LaunchTView/components/LaunchTViewDialog.js.map +1 -0
  26. package/dist/LaunchTView/fetchTviewPlan.d.ts +51 -0
  27. package/dist/LaunchTView/fetchTviewPlan.js +43 -0
  28. package/dist/LaunchTView/fetchTviewPlan.js.map +1 -0
  29. package/dist/LaunchTView/index.d.ts +2 -0
  30. package/dist/LaunchTView/index.js +41 -0
  31. package/dist/LaunchTView/index.js.map +1 -0
  32. package/dist/LaunchTView/limits.d.ts +2 -0
  33. package/dist/LaunchTView/limits.js +8 -0
  34. package/dist/LaunchTView/limits.js.map +1 -0
  35. package/dist/LaunchTView/tview.d.ts +95 -0
  36. package/dist/LaunchTView/tview.js +191 -0
  37. package/dist/LaunchTView/tview.js.map +1 -0
  38. package/dist/LaunchTView/useTviewMsa.d.ts +14 -0
  39. package/dist/LaunchTView/useTviewMsa.js +20 -0
  40. package/dist/LaunchTView/useTviewMsa.js.map +1 -0
  41. package/dist/TViewPanel/components/TViewPanel.d.ts +6 -0
  42. package/dist/TViewPanel/components/TViewPanel.js +11 -0
  43. package/dist/TViewPanel/components/TViewPanel.js.map +1 -0
  44. package/dist/TViewPanel/coords.d.ts +17 -0
  45. package/dist/TViewPanel/coords.js +36 -0
  46. package/dist/TViewPanel/coords.js.map +1 -0
  47. package/dist/TViewPanel/index.d.ts +2 -0
  48. package/dist/TViewPanel/index.js +15 -0
  49. package/dist/TViewPanel/index.js.map +1 -0
  50. package/dist/TViewPanel/model.d.ts +1028 -0
  51. package/dist/TViewPanel/model.js +246 -0
  52. package/dist/TViewPanel/model.js.map +1 -0
  53. package/dist/config.json +8 -0
  54. package/dist/index.d.ts +8 -0
  55. package/dist/index.js +19 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/jbrowse-plugin-tview.umd.production.min.js +104 -0
  58. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +7 -0
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.js +2 -0
  61. package/dist/version.js.map +1 -0
  62. package/package.json +76 -0
  63. package/src/AddHighlightModel/GenomeMouseoverHighlight.tsx +46 -0
  64. package/src/AddHighlightModel/Highlight.tsx +35 -0
  65. package/src/AddHighlightModel/HighlightComponents.tsx +25 -0
  66. package/src/AddHighlightModel/MsaToGenomeHighlight.tsx +31 -0
  67. package/src/AddHighlightModel/index.tsx +28 -0
  68. package/src/AddHighlightModel/util.ts +14 -0
  69. package/src/LaunchTView/align.ts +154 -0
  70. package/src/LaunchTView/components/LaunchTViewDialog.tsx +129 -0
  71. package/src/LaunchTView/fetchTviewPlan.ts +95 -0
  72. package/src/LaunchTView/index.ts +53 -0
  73. package/src/LaunchTView/limits.ts +8 -0
  74. package/src/LaunchTView/tview.ts +272 -0
  75. package/src/LaunchTView/useTviewMsa.ts +36 -0
  76. package/src/TViewPanel/components/TViewPanel.tsx +20 -0
  77. package/src/TViewPanel/coords.ts +43 -0
  78. package/src/TViewPanel/index.ts +20 -0
  79. package/src/TViewPanel/model.ts +289 -0
  80. package/src/index.ts +21 -0
  81. package/src/version.ts +1 -0
@@ -0,0 +1,289 @@
1
+ import { BaseViewModel } from '@jbrowse/core/pluggableElementTypes'
2
+ import { getSession } from '@jbrowse/core/util'
3
+ import { addDisposer, types } from '@jbrowse/mobx-state-tree'
4
+ import { autorun } from 'mobx'
5
+ import { MSAModelF } from 'react-msaview'
6
+
7
+ import { buildColumnToRefPos, renderedColToMsaCol } from './coords'
8
+ import {
9
+ fetchTviewPlan,
10
+ findTrackConf,
11
+ sourceFromConfig,
12
+ } from '../LaunchTView/fetchTviewPlan'
13
+ import { MAX_CELLS } from '../LaunchTView/limits'
14
+ import { renderTviewMsa } from '../LaunchTView/tview'
15
+
16
+ import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
17
+ import type { MenuItem } from '@jbrowse/core/ui'
18
+ import type { Instance } from '@jbrowse/mobx-state-tree'
19
+ import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
20
+
21
+ // re-exported so the inferred (composed) state-model type can name mobx's
22
+ // IKeyValueMap when emitting declarations (avoids TS2883 portability error)
23
+ export type { IKeyValueMap } from 'mobx'
24
+
25
+ type MaybeLGV = LinearGenomeViewModel | undefined
26
+
27
+ export interface IRegion {
28
+ refName: string
29
+ start: number
30
+ end: number
31
+ }
32
+
33
+ /** enough to re-run CoreGetFeatures for msaRegion after a session reload */
34
+ export interface MsaSource {
35
+ trackId: string
36
+ assemblyName: string
37
+ }
38
+
39
+ /**
40
+ * #stateModel TViewPlugin
41
+ * extends
42
+ * - MSAModel from https://github.com/GMOD/react-msaview
43
+ */
44
+ export default function stateModelFactory() {
45
+ return types
46
+ .compose(
47
+ 'TView',
48
+ BaseViewModel,
49
+ MSAModelF(),
50
+ types.model({
51
+ type: types.literal('TView'),
52
+ /**
53
+ * #property
54
+ * LGV this pileup was launched from; drives highlights and click-to-nav
55
+ */
56
+ connectedViewId: types.maybe(types.string),
57
+ /**
58
+ * #property
59
+ * reference region the alignment columns span
60
+ */
61
+ msaRegion: types.frozen<IRegion | undefined>(),
62
+ /**
63
+ * #property
64
+ * [refPos, width] for every position where some read has an insertion
65
+ */
66
+ insertionWidths: types.frozen<[number, number][]>([]),
67
+ /**
68
+ * #property
69
+ * the track the alignment was built from. react-msaview drops data.msa
70
+ * from snapshots over 50kb (it expects a msaFilehandle to reload from,
71
+ * which tview has no equivalent of), so without this a restored session
72
+ * brings the view back empty
73
+ */
74
+ msaSource: types.frozen<MsaSource | undefined>(),
75
+ /**
76
+ * #property
77
+ */
78
+ zoomToBaseLevel: types.optional(types.boolean, false),
79
+ }),
80
+ )
81
+ .views(self => ({
82
+ /**
83
+ * #getter
84
+ */
85
+ get columnToRefPos() {
86
+ const { msaRegion, insertionWidths } = self
87
+ return msaRegion
88
+ ? buildColumnToRefPos({ ...msaRegion, insertionWidths })
89
+ : undefined
90
+ },
91
+ /**
92
+ * #getter
93
+ */
94
+ get connectedView() {
95
+ const { views } = getSession(self)
96
+ return views.find(f => f.id === self.connectedViewId) as MaybeLGV
97
+ },
98
+ /**
99
+ * #getter
100
+ * the source track's config, which outlives the track being open
101
+ */
102
+ get msaSourceConf() {
103
+ const { msaSource } = self
104
+ return msaSource
105
+ ? findTrackConf(getSession(self), msaSource.trackId)
106
+ : undefined
107
+ },
108
+ }))
109
+ .views(self => ({
110
+ /**
111
+ * #method
112
+ */
113
+ colToGenomeRegion(col: number): IRegion | undefined {
114
+ const { columnToRefPos, msaRegion, blanks } = self
115
+ const pos = columnToRefPos?.[renderedColToMsaCol(blanks, col)]
116
+ return msaRegion && pos !== undefined
117
+ ? { refName: msaRegion.refName, start: pos, end: pos + 1 }
118
+ : undefined
119
+ },
120
+ }))
121
+ .views(self => ({
122
+ /**
123
+ * #getter
124
+ * regions the connected LGV highlights: the hovered column plus the
125
+ * sticky clicked column
126
+ */
127
+ get connectedHighlights() {
128
+ const { mouseCol, mouseClickCol } = self
129
+ const regions = [mouseCol, mouseClickCol]
130
+ .filter((col): col is number => col !== undefined)
131
+ .map(col => self.colToGenomeRegion(col))
132
+ .filter((r): r is IRegion => r !== undefined)
133
+ // an insertion column and its reference column resolve to the same
134
+ // position, so deduping by column would still stack two identical bands
135
+ return [
136
+ ...new Map(regions.map(r => [`${r.refName}:${r.start}`, r])).values(),
137
+ ]
138
+ },
139
+ }))
140
+ .volatile(() => ({
141
+ /** a rebuild is in flight, or has failed and should not be retried */
142
+ rebuilding: false,
143
+ rebuildFailed: false,
144
+ }))
145
+ .actions(self => ({
146
+ /**
147
+ * #action
148
+ */
149
+ setRebuilding(arg: boolean) {
150
+ self.rebuilding = arg
151
+ },
152
+ /**
153
+ * #action
154
+ */
155
+ setRebuildFailed(arg: boolean) {
156
+ self.rebuildFailed = arg
157
+ },
158
+ /**
159
+ * #action
160
+ */
161
+ setMsaData(msa: string, insertionWidths: [number, number][]) {
162
+ self.data.setMSA(msa)
163
+ self.insertionWidths = insertionWidths
164
+ },
165
+ /**
166
+ * #action
167
+ */
168
+ setZoomToBaseLevel(arg: boolean) {
169
+ self.zoomToBaseLevel = arg
170
+ },
171
+ /**
172
+ * #action
173
+ */
174
+ navToColumn(col: number) {
175
+ const { connectedView, zoomToBaseLevel } = self
176
+ const r = self.colToGenomeRegion(col)
177
+ if (r && connectedView) {
178
+ if (zoomToBaseLevel) {
179
+ connectedView.navTo(r)
180
+ } else {
181
+ connectedView.centerAt(r.start, r.refName)
182
+ }
183
+ }
184
+ },
185
+ }))
186
+ .actions(self => ({
187
+ /**
188
+ * #action
189
+ * re-runs CoreGetFeatures for msaRegion and rebuilds the alignment
190
+ */
191
+ async rebuildMsa(conf: AnyConfigurationModel, source: MsaSource) {
192
+ const session = getSession(self)
193
+ self.setRebuilding(true)
194
+ self.setLoadingMSA(true)
195
+ self.setStatus({ msg: 'Rebuilding alignment from track data' })
196
+ try {
197
+ const { plan } = await fetchTviewPlan({
198
+ session,
199
+ source: sourceFromConfig(conf),
200
+ region: { ...self.msaRegion!, assemblyName: source.assemblyName },
201
+ })
202
+ if (plan.cellCount > MAX_CELLS) {
203
+ throw new Error(
204
+ `alignment is ${plan.cellCount.toLocaleString('en-US')} cells, above the ${MAX_CELLS.toLocaleString('en-US')} limit`,
205
+ )
206
+ }
207
+ self.setMsaData(renderTviewMsa(plan), plan.insertionWidths)
208
+ } catch (e) {
209
+ console.error(e)
210
+ self.setRebuildFailed(true)
211
+ session.notify(`Could not rebuild tview alignment: ${e}`, 'error')
212
+ } finally {
213
+ self.setLoadingMSA(false)
214
+ self.setStatus(undefined)
215
+ self.setRebuilding(false)
216
+ }
217
+ },
218
+ }))
219
+ .actions(self => ({
220
+ afterCreate() {
221
+ addDisposer(
222
+ self,
223
+ autorun(() => {
224
+ const { data, msaRegion, msaSource, msaSourceConf } = self
225
+ // a restored session arrives with the region and source but no
226
+ // alignment; stays armed if the track config shows up later
227
+ if (
228
+ !data.msa &&
229
+ msaRegion &&
230
+ msaSource &&
231
+ msaSourceConf &&
232
+ !self.rebuilding &&
233
+ !self.rebuildFailed
234
+ ) {
235
+ // rebuildMsa handles its own failures, so it never rejects
236
+ void self.rebuildMsa(msaSourceConf, msaSource)
237
+ }
238
+ }),
239
+ )
240
+ },
241
+ }))
242
+ .actions(self => {
243
+ const superSetMouseClickPos = self.setMouseClickPos.bind(self)
244
+ return {
245
+ /**
246
+ * #action
247
+ */
248
+ setMouseClickPos(col?: number, row?: number) {
249
+ superSetMouseClickPos(col, row)
250
+ if (col !== undefined) {
251
+ self.navToColumn(col)
252
+ }
253
+ },
254
+ }
255
+ })
256
+ .views(self => {
257
+ // react-msaview's extraViewMenuItems() has no caller, in that package or
258
+ // in JBrowse; the view hamburger renders menuItems(), so extend that
259
+ const superMenuItems = self.menuItems.bind(self)
260
+ return {
261
+ /**
262
+ * #method
263
+ * overrides base
264
+ */
265
+ menuItems(): MenuItem[] {
266
+ return [
267
+ ...superMenuItems(),
268
+ {
269
+ label: 'Zoom to base level on click?',
270
+ type: 'checkbox',
271
+ checked: self.zoomToBaseLevel,
272
+ onClick: () => {
273
+ self.setZoomToBaseLevel(!self.zoomToBaseLevel)
274
+ },
275
+ },
276
+ ]
277
+ },
278
+ }
279
+ })
280
+ }
281
+
282
+ export type JBrowsePluginTViewStateModel = ReturnType<typeof stateModelFactory>
283
+ export type JBrowsePluginTViewModel = Instance<JBrowsePluginTViewStateModel>
284
+
285
+ export function isTView(view: {
286
+ type: string
287
+ }): view is JBrowsePluginTViewModel {
288
+ return view.type === 'TView'
289
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import Plugin from '@jbrowse/core/Plugin'
2
+
3
+ import AddHighlightModelF from './AddHighlightModel'
4
+ import LaunchTViewF from './LaunchTView'
5
+ import TViewF from './TViewPanel'
6
+ import { version } from './version'
7
+
8
+ import type PluginManager from '@jbrowse/core/PluginManager'
9
+
10
+ export default class TViewPlugin extends Plugin {
11
+ name = 'TViewPlugin'
12
+ version = version
13
+
14
+ install(pluginManager: PluginManager) {
15
+ TViewF(pluginManager)
16
+ LaunchTViewF(pluginManager)
17
+ AddHighlightModelF(pluginManager)
18
+ }
19
+
20
+ configure(_pluginManager: PluginManager) {}
21
+ }
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const version = '2.0.4'