jbrowse-plugin-tview 2.0.6 → 2.1.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 (73) hide show
  1. package/README.md +157 -4
  2. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.d.ts +132 -0
  3. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js +152 -0
  4. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js.map +1 -0
  5. package/dist/LaunchTView/TviewGetPlanRpc/index.d.ts +3 -0
  6. package/dist/LaunchTView/TviewGetPlanRpc/index.js +5 -0
  7. package/dist/LaunchTView/TviewGetPlanRpc/index.js.map +1 -0
  8. package/dist/LaunchTView/align.d.ts +93 -9
  9. package/dist/LaunchTView/align.js +290 -15
  10. package/dist/LaunchTView/align.js.map +1 -1
  11. package/dist/LaunchTView/alleles.d.ts +57 -0
  12. package/dist/LaunchTView/alleles.js +94 -0
  13. package/dist/LaunchTView/alleles.js.map +1 -0
  14. package/dist/LaunchTView/components/ArrayReport.d.ts +10 -0
  15. package/dist/LaunchTView/components/ArrayReport.js +59 -0
  16. package/dist/LaunchTView/components/ArrayReport.js.map +1 -0
  17. package/dist/LaunchTView/components/LaunchTViewDialog.js +74 -37
  18. package/dist/LaunchTView/components/LaunchTViewDialog.js.map +1 -1
  19. package/dist/LaunchTView/fetchTviewPlan.d.ts +20 -13
  20. package/dist/LaunchTView/fetchTviewPlan.js +27 -27
  21. package/dist/LaunchTView/fetchTviewPlan.js.map +1 -1
  22. package/dist/LaunchTView/launchView.d.ts +25 -0
  23. package/dist/LaunchTView/launchView.js +20 -0
  24. package/dist/LaunchTView/launchView.js.map +1 -0
  25. package/dist/LaunchTView/readLayout.d.ts +85 -0
  26. package/dist/LaunchTView/readLayout.js +96 -0
  27. package/dist/LaunchTView/readLayout.js.map +1 -0
  28. package/dist/LaunchTView/repeats.d.ts +68 -0
  29. package/dist/LaunchTView/repeats.js +200 -0
  30. package/dist/LaunchTView/repeats.js.map +1 -0
  31. package/dist/LaunchTView/sampleTree.d.ts +37 -0
  32. package/dist/LaunchTView/sampleTree.js +65 -0
  33. package/dist/LaunchTView/sampleTree.js.map +1 -0
  34. package/dist/LaunchTView/tview.d.ts +67 -44
  35. package/dist/LaunchTView/tview.js +190 -121
  36. package/dist/LaunchTView/tview.js.map +1 -1
  37. package/dist/LaunchTView/useTviewMsa.d.ts +13 -9
  38. package/dist/LaunchTView/useTviewMsa.js +15 -11
  39. package/dist/LaunchTView/useTviewMsa.js.map +1 -1
  40. package/dist/TViewPanel/coords.d.ts +9 -1
  41. package/dist/TViewPanel/coords.js +22 -2
  42. package/dist/TViewPanel/coords.js.map +1 -1
  43. package/dist/TViewPanel/init.d.ts +56 -0
  44. package/dist/TViewPanel/init.js +59 -0
  45. package/dist/TViewPanel/init.js.map +1 -0
  46. package/dist/TViewPanel/model.d.ts +47 -31
  47. package/dist/TViewPanel/model.js +73 -51
  48. package/dist/TViewPanel/model.js.map +1 -1
  49. package/dist/index.js +5 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/jbrowse-plugin-tview.umd.production.min.js +22 -22
  52. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +5 -2
  56. package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +264 -0
  57. package/src/LaunchTView/TviewGetPlanRpc/index.ts +14 -0
  58. package/src/LaunchTView/align.ts +343 -17
  59. package/src/LaunchTView/alleles.ts +132 -0
  60. package/src/LaunchTView/components/ArrayReport.tsx +64 -0
  61. package/src/LaunchTView/components/LaunchTViewDialog.tsx +122 -39
  62. package/src/LaunchTView/fetchTviewPlan.ts +42 -42
  63. package/src/LaunchTView/launchView.ts +50 -0
  64. package/src/LaunchTView/readLayout.ts +145 -0
  65. package/src/LaunchTView/repeats.ts +218 -0
  66. package/src/LaunchTView/sampleTree.ts +73 -0
  67. package/src/LaunchTView/tview.ts +259 -157
  68. package/src/LaunchTView/useTviewMsa.ts +20 -17
  69. package/src/TViewPanel/coords.ts +23 -1
  70. package/src/TViewPanel/init.ts +127 -0
  71. package/src/TViewPanel/model.ts +82 -61
  72. package/src/index.ts +5 -1
  73. package/src/version.ts +1 -1
@@ -0,0 +1,127 @@
1
+ import { readConfObject } from '@jbrowse/core/configuration'
2
+ import { parseLocString } from '@jbrowse/core/util'
3
+
4
+ import { findTrackConf } from '../LaunchTView/fetchTviewPlan'
5
+
6
+ import type { TviewSource } from '../LaunchTView/fetchTviewPlan'
7
+ import type { AbstractSessionModel } from '@jbrowse/core/util'
8
+
9
+ /**
10
+ * One alignment file the view reads, and optionally the name to group its rows
11
+ * under. A bare trackId is the same thing with the name left to the track.
12
+ */
13
+ export type TviewTrackInit = string | { trackId: string; sample?: string }
14
+
15
+ /**
16
+ * Everything a tview is: a locus, an assembly, and the alignment files to read
17
+ * it from.
18
+ *
19
+ * The view is declared with this and derives the rest, in the shape
20
+ * LinearGenomeView's `init` uses. Two things follow from that which are worth
21
+ * saying out loud:
22
+ *
23
+ * - A session can **author** a tview. `{ type: 'TView', init: { … } }` in a
24
+ * defaultSession opens one with no click path — as does the flat form of the
25
+ * same keys in a session spec URL, which is what makes a repeat locus a link.
26
+ * - There is one code path. Launching from the track menu, restoring a saved
27
+ * session and following a link all end up applying the same blob, so the
28
+ * launch dialog does not build the view — it names it.
29
+ *
30
+ * Unlike LinearGenomeView's, this init is **kept, not cleared**. What it
31
+ * resolves to is a multiple alignment held as one string, which react-msaview
32
+ * drops from snapshots past 50kb and has no file to reload from; the blob is
33
+ * both smaller than what it produces and the only durable statement of what the
34
+ * view is.
35
+ */
36
+ export interface TviewInit {
37
+ /** assembly the locus and the tracks belong to */
38
+ assembly: string
39
+ /** locstring, e.g. `chrX:146,993,530..146,993,670` */
40
+ loc: string
41
+ /** the alignment files to draw rows from, in order */
42
+ tracks: TviewTrackInit[]
43
+ }
44
+
45
+ // Derived from the interface so it cannot drift: the Record requires exactly one
46
+ // entry per key, so adding a field without listing it here is a compile error
47
+ // rather than a key that silently reads as a view prop.
48
+ const initKeyMap: Record<keyof TviewInit, true> = {
49
+ assembly: true,
50
+ loc: true,
51
+ tracks: true,
52
+ }
53
+ export const initKeys = new Set<string>(Object.keys(initKeyMap))
54
+
55
+ /** the region `init.loc` names, or undefined until the assembly can parse it */
56
+ export function initRegion(session: AbstractSessionModel, init: TviewInit) {
57
+ const { assemblyManager } = session
58
+ if (!assemblyManager.get(init.assembly)?.initialized) {
59
+ return undefined
60
+ }
61
+ const parsed = parseLocString(init.loc, refName =>
62
+ assemblyManager.isValidRefName(refName, init.assembly),
63
+ )
64
+ return {
65
+ assemblyName: init.assembly,
66
+ refName: parsed.refName,
67
+ start: parsed.start ?? 0,
68
+ end: parsed.end ?? 0,
69
+ }
70
+ }
71
+
72
+ /**
73
+ * One entry of `init.tracks`, resolved against the session.
74
+ *
75
+ * `sample` is always a string here. Which of the three candidates it came from
76
+ * — what the init asked for, what the track config is called, or the trackId —
77
+ * is settled once, at the point where all three are in hand, so nothing
78
+ * downstream has to ask again. `||` rather than `??` on purpose: a track
79
+ * configured with `name: ''` should fall through to its id, not label a clade
80
+ * with an empty string.
81
+ */
82
+ interface ResolvedTrack {
83
+ trackId: string
84
+ adapterConfig: unknown
85
+ sample: string
86
+ }
87
+
88
+ function resolveTrack(
89
+ session: AbstractSessionModel,
90
+ entry: TviewTrackInit,
91
+ ): ResolvedTrack | undefined {
92
+ const { trackId, sample } =
93
+ typeof entry === 'string' ? { trackId: entry, sample: undefined } : entry
94
+ const conf = findTrackConf(session, trackId)
95
+ return conf
96
+ ? {
97
+ trackId,
98
+ adapterConfig: readConfObject(conf, 'adapter'),
99
+ sample: sample || (readConfObject(conf, 'name') as string) || trackId,
100
+ }
101
+ : undefined
102
+ }
103
+
104
+ /**
105
+ * The sources `init.tracks` names, or undefined until every one of them
106
+ * resolves. All or nothing: a partial set comes back with samples missing and
107
+ * nothing on screen says any were.
108
+ *
109
+ * Whether the names are *used* is decided here and only here — one file's rows
110
+ * need no prefix, and would gain a tree of one clade drawn beside a list.
111
+ */
112
+ export function initSources(
113
+ session: AbstractSessionModel,
114
+ init: TviewInit,
115
+ ): TviewSource[] | undefined {
116
+ const resolved = init.tracks.map(entry => resolveTrack(session, entry))
117
+ const found = resolved.filter(t => t !== undefined)
118
+ if (found.length !== init.tracks.length) {
119
+ return undefined
120
+ }
121
+ const labelled = found.length > 1
122
+ return found.map(track => ({
123
+ trackId: track.trackId,
124
+ adapterConfig: track.adapterConfig,
125
+ sample: labelled ? track.sample : undefined,
126
+ }))
127
+ }
@@ -5,15 +5,12 @@ import { autorun } from 'mobx'
5
5
  import { MSAModelF } from 'react-msaview'
6
6
 
7
7
  import { buildColumnToRefPos, renderedColToMsaCol } from './coords'
8
- import {
9
- fetchTviewPlan,
10
- findTrackConf,
11
- sourceFromConfig,
12
- } from '../LaunchTView/fetchTviewPlan'
8
+ import { initRegion, initSources } from './init'
9
+ import { fetchTviewPlan } from '../LaunchTView/fetchTviewPlan'
13
10
  import { MAX_CELLS } from '../LaunchTView/limits'
14
- import { renderTviewMsa } from '../LaunchTView/tview'
15
11
 
16
- import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
12
+ import type { TviewInit } from './init'
13
+ import type { FetchRegion, TviewSource } from '../LaunchTView/fetchTviewPlan'
17
14
  import type { MenuItem } from '@jbrowse/core/ui'
18
15
  import type { Instance } from '@jbrowse/mobx-state-tree'
19
16
  import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
@@ -30,11 +27,7 @@ export interface IRegion {
30
27
  end: number
31
28
  }
32
29
 
33
- /** enough to re-run CoreGetFeatures for msaRegion after a session reload */
34
- export interface MsaSource {
35
- trackId: string
36
- assemblyName: string
37
- }
30
+ export type { TviewInit } from './init'
38
31
 
39
32
  /**
40
33
  * #stateModel TViewPlugin
@@ -56,7 +49,14 @@ export default function stateModelFactory() {
56
49
  connectedViewId: types.maybe(types.string),
57
50
  /**
58
51
  * #property
59
- * reference region the alignment columns span
52
+ * what the view is: a locus, an assembly and the alignment files to
53
+ * read it from. Everything else here is derived from it — see
54
+ * `./init.ts` for why this one is kept rather than cleared
55
+ */
56
+ init: types.frozen<TviewInit | undefined>(),
57
+ /**
58
+ * #property
59
+ * reference region the alignment columns span, filled in by the load
60
60
  */
61
61
  msaRegion: types.frozen<IRegion | undefined>(),
62
62
  /**
@@ -66,12 +66,9 @@ export default function stateModelFactory() {
66
66
  insertionWidths: types.frozen<[number, number][]>([]),
67
67
  /**
68
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
69
+ * [start, end, columns] for every tandem array laid out per copy
73
70
  */
74
- msaSource: types.frozen<MsaSource | undefined>(),
71
+ arraySpans: types.frozen<[number, number, number][]>([]),
75
72
  /**
76
73
  * #property
77
74
  */
@@ -83,9 +80,9 @@ export default function stateModelFactory() {
83
80
  * #getter
84
81
  */
85
82
  get columnToRefPos() {
86
- const { msaRegion, insertionWidths } = self
83
+ const { msaRegion, insertionWidths, arraySpans } = self
87
84
  return msaRegion
88
- ? buildColumnToRefPos({ ...msaRegion, insertionWidths })
85
+ ? buildColumnToRefPos({ ...msaRegion, insertionWidths, arraySpans })
89
86
  : undefined
90
87
  },
91
88
  /**
@@ -97,13 +94,19 @@ export default function stateModelFactory() {
97
94
  },
98
95
  /**
99
96
  * #getter
100
- * the source track's config, which outlives the track being open
97
+ * the region `init.loc` names, once the assembly can parse it
101
98
  */
102
- get msaSourceConf() {
103
- const { msaSource } = self
104
- return msaSource
105
- ? findTrackConf(getSession(self), msaSource.trackId)
106
- : undefined
99
+ get initRegion() {
100
+ return self.init ? initRegion(getSession(self), self.init) : undefined
101
+ },
102
+ /**
103
+ * #getter
104
+ * the alignment files `init.tracks` names, once every one resolves. The
105
+ * configs are read rather than the track models, so a tview outlives the
106
+ * tracks it was launched from being closed.
107
+ */
108
+ get initSources() {
109
+ return self.init ? initSources(getSession(self), self.init) : undefined
107
110
  },
108
111
  }))
109
112
  .views(self => ({
@@ -138,29 +141,47 @@ export default function stateModelFactory() {
138
141
  },
139
142
  }))
140
143
  .volatile(() => ({
141
- /** a rebuild is in flight, or has failed and should not be retried */
142
- rebuilding: false,
143
- rebuildFailed: false,
144
+ /** a load is in flight, or has failed and should not be retried */
145
+ loading: false,
146
+ loadFailed: false,
144
147
  }))
145
148
  .actions(self => ({
146
149
  /**
147
150
  * #action
148
151
  */
149
- setRebuilding(arg: boolean) {
150
- self.rebuilding = arg
152
+ setLoading(arg: boolean) {
153
+ self.loading = arg
151
154
  },
152
155
  /**
153
156
  * #action
154
157
  */
155
- setRebuildFailed(arg: boolean) {
156
- self.rebuildFailed = arg
158
+ setLoadFailed(arg: boolean) {
159
+ self.loadFailed = arg
157
160
  },
158
161
  /**
159
162
  * #action
160
163
  */
161
- setMsaData(msa: string, insertionWidths: [number, number][]) {
162
- self.data.setMSA(msa)
163
- self.insertionWidths = insertionWidths
164
+ setInit(arg?: TviewInit) {
165
+ self.init = arg
166
+ self.loadFailed = false
167
+ },
168
+ /**
169
+ * #action
170
+ */
171
+ setMsaData(result: {
172
+ msa: string
173
+ tree?: string
174
+ insertionWidths: [number, number][]
175
+ arraySpans: [number, number, number][]
176
+ region: IRegion
177
+ }) {
178
+ self.msaRegion = result.region
179
+ self.insertionWidths = result.insertionWidths
180
+ self.arraySpans = result.arraySpans
181
+ self.data.setMSA(result.msa)
182
+ if (result.tree) {
183
+ self.data.setTree(result.tree)
184
+ }
164
185
  },
165
186
  /**
166
187
  * #action
@@ -186,33 +207,30 @@ export default function stateModelFactory() {
186
207
  .actions(self => ({
187
208
  /**
188
209
  * #action
189
- * re-runs CoreGetFeatures for msaRegion and rebuilds the alignment
210
+ * builds the alignment `init` describes, from whatever `init` describes
211
+ * it over. The one way an alignment ever gets here.
190
212
  */
191
- async rebuildMsa(conf: AnyConfigurationModel, source: MsaSource) {
213
+ async load(region: FetchRegion, sources: TviewSource[]) {
192
214
  const session = getSession(self)
193
- self.setRebuilding(true)
215
+ self.setLoading(true)
194
216
  self.setLoadingMSA(true)
195
- self.setStatus({ msg: 'Rebuilding alignment from track data' })
217
+ self.setStatus({ msg: 'Building alignment from track data' })
196
218
  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) {
219
+ const result = await fetchTviewPlan({ session, sources, region })
220
+ if (result.tooLarge) {
203
221
  throw new Error(
204
- `alignment is ${plan.cellCount.toLocaleString('en-US')} cells, above the ${MAX_CELLS.toLocaleString('en-US')} limit`,
222
+ `alignment is ${result.cellCount.toLocaleString('en-US')} cells, above the ${MAX_CELLS.toLocaleString('en-US')} limit`,
205
223
  )
206
224
  }
207
- self.setMsaData(renderTviewMsa(plan), plan.insertionWidths)
225
+ self.setMsaData(result)
208
226
  } catch (e) {
209
227
  console.error(e)
210
- self.setRebuildFailed(true)
211
- session.notify(`Could not rebuild tview alignment: ${e}`, 'error')
228
+ self.setLoadFailed(true)
229
+ session.notify(`Could not build tview alignment: ${e}`, 'error')
212
230
  } finally {
213
231
  self.setLoadingMSA(false)
214
232
  self.setStatus(undefined)
215
- self.setRebuilding(false)
233
+ self.setLoading(false)
216
234
  }
217
235
  },
218
236
  }))
@@ -221,19 +239,22 @@ export default function stateModelFactory() {
221
239
  addDisposer(
222
240
  self,
223
241
  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
242
+ // Everything that decides whether to load is a getter over `init`,
243
+ // so this reads as the one sentence it is: an alignment the view
244
+ // does not have, over a region and files it can now resolve. It
245
+ // stays armed across the assembly loading and the track configs
246
+ // arriving, which is what a restored session needs and what a
247
+ // session-authored view needs, without either being a special case.
248
+ const { data, initRegion, initSources, loading, loadFailed } = self
227
249
  if (
228
250
  !data.msa &&
229
- msaRegion &&
230
- msaSource &&
231
- msaSourceConf &&
232
- !self.rebuilding &&
233
- !self.rebuildFailed
251
+ initRegion &&
252
+ initSources &&
253
+ !loading &&
254
+ !loadFailed
234
255
  ) {
235
- // rebuildMsa handles its own failures, so it never rejects
236
- void self.rebuildMsa(msaSourceConf, msaSource)
256
+ // load handles its own failures, so it never rejects
257
+ void self.load(initRegion, initSources)
237
258
  }
238
259
  }),
239
260
  )
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import Plugin from '@jbrowse/core/Plugin'
2
2
 
3
3
  import AddHighlightModelF from './AddHighlightModel'
4
- import LaunchTViewF from './LaunchTView'
4
+ import TrackMenuItemF from './LaunchTView'
5
+ import TviewGetPlanRpcF from './LaunchTView/TviewGetPlanRpc'
6
+ import LaunchTViewF from './LaunchTView/launchView'
5
7
  import TViewF from './TViewPanel'
6
8
  import { version } from './version'
7
9
 
@@ -13,7 +15,9 @@ export default class TViewPlugin extends Plugin {
13
15
 
14
16
  install(pluginManager: PluginManager) {
15
17
  TViewF(pluginManager)
18
+ TrackMenuItemF(pluginManager)
16
19
  LaunchTViewF(pluginManager)
20
+ TviewGetPlanRpcF(pluginManager)
17
21
  AddHighlightModelF(pluginManager)
18
22
  }
19
23
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.0.6'
1
+ export const version = '2.1.0'