jbrowse-plugin-tview 2.2.3 → 3.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 (110) hide show
  1. package/README.md +317 -105
  2. package/dist/AddHighlightModel/index.js +2 -13
  3. package/dist/AddHighlightModel/index.js.map +1 -1
  4. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.d.ts +44 -64
  5. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js +57 -81
  6. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js.map +1 -1
  7. package/dist/LaunchTView/TviewGetPlanRpc/index.d.ts +1 -1
  8. package/dist/LaunchTView/align.d.ts +11 -17
  9. package/dist/LaunchTView/align.js +190 -150
  10. package/dist/LaunchTView/align.js.map +1 -1
  11. package/dist/LaunchTView/alleles.d.ts +14 -0
  12. package/dist/LaunchTView/alleles.js +47 -0
  13. package/dist/LaunchTView/alleles.js.map +1 -1
  14. package/dist/LaunchTView/fetchTviewPlan.d.ts +5 -37
  15. package/dist/LaunchTView/fetchTviewPlan.js +7 -28
  16. package/dist/LaunchTView/fetchTviewPlan.js.map +1 -1
  17. package/dist/LaunchTView/index.js +45 -16
  18. package/dist/LaunchTView/index.js.map +1 -1
  19. package/dist/LaunchTView/launch.d.ts +50 -0
  20. package/dist/LaunchTView/launch.js +48 -0
  21. package/dist/LaunchTView/launch.js.map +1 -0
  22. package/dist/LaunchTView/launchView.d.ts +3 -8
  23. package/dist/LaunchTView/launchView.js +18 -12
  24. package/dist/LaunchTView/launchView.js.map +1 -1
  25. package/dist/LaunchTView/modifications.d.ts +64 -0
  26. package/dist/LaunchTView/modifications.js +131 -0
  27. package/dist/LaunchTView/modifications.js.map +1 -0
  28. package/dist/LaunchTView/readLayout.d.ts +35 -39
  29. package/dist/LaunchTView/readLayout.js +44 -24
  30. package/dist/LaunchTView/readLayout.js.map +1 -1
  31. package/dist/LaunchTView/repeatStats.d.ts +1 -1
  32. package/dist/LaunchTView/repeatStats.js +6 -21
  33. package/dist/LaunchTView/repeatStats.js.map +1 -1
  34. package/dist/LaunchTView/tview.d.ts +34 -23
  35. package/dist/LaunchTView/tview.js +127 -78
  36. package/dist/LaunchTView/tview.js.map +1 -1
  37. package/dist/TViewPanel/components/TViewPanel.js +9 -4
  38. package/dist/TViewPanel/components/TViewPanel.js.map +1 -1
  39. package/dist/TViewPanel/genome.d.ts +11 -0
  40. package/dist/TViewPanel/genome.js +32 -0
  41. package/dist/TViewPanel/genome.js.map +1 -0
  42. package/dist/TViewPanel/init.d.ts +38 -19
  43. package/dist/TViewPanel/init.js +66 -39
  44. package/dist/TViewPanel/init.js.map +1 -1
  45. package/dist/TViewPanel/initMenu.d.ts +28 -0
  46. package/dist/TViewPanel/initMenu.js +79 -0
  47. package/dist/TViewPanel/initMenu.js.map +1 -0
  48. package/dist/TViewPanel/model.d.ts +1057 -334
  49. package/dist/TViewPanel/model.js +298 -87
  50. package/dist/TViewPanel/model.js.map +1 -1
  51. package/dist/TViewPanel/modifications.d.ts +25 -0
  52. package/dist/TViewPanel/modifications.js +89 -0
  53. package/dist/TViewPanel/modifications.js.map +1 -0
  54. package/dist/index.d.ts +0 -1
  55. package/dist/index.js +0 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/jbrowse-plugin-tview.umd.production.min.js +125 -88
  58. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
  59. package/dist/version.d.ts +1 -1
  60. package/dist/version.js +1 -1
  61. package/package.json +8 -8
  62. package/src/AddHighlightModel/index.tsx +8 -14
  63. package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +119 -157
  64. package/src/LaunchTView/TviewGetPlanRpc/index.ts +0 -1
  65. package/src/LaunchTView/align.ts +225 -176
  66. package/src/LaunchTView/alleles.ts +66 -0
  67. package/src/LaunchTView/fetchTviewPlan.ts +11 -54
  68. package/src/LaunchTView/index.ts +74 -16
  69. package/src/LaunchTView/launch.ts +98 -0
  70. package/src/LaunchTView/launchView.ts +28 -20
  71. package/src/LaunchTView/modifications.ts +200 -0
  72. package/src/LaunchTView/readLayout.ts +65 -41
  73. package/src/LaunchTView/repeatStats.ts +7 -23
  74. package/src/LaunchTView/tview.ts +158 -91
  75. package/src/TViewPanel/components/TViewPanel.tsx +33 -4
  76. package/src/TViewPanel/genome.ts +41 -0
  77. package/src/TViewPanel/init.ts +104 -51
  78. package/src/TViewPanel/initMenu.ts +126 -0
  79. package/src/TViewPanel/model.ts +350 -97
  80. package/src/TViewPanel/modifications.ts +127 -0
  81. package/src/index.ts +0 -2
  82. package/src/version.ts +1 -1
  83. package/dist/AddHighlightModel/GenomeMouseoverHighlight.d.ts +0 -6
  84. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js +0 -23
  85. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js.map +0 -1
  86. package/dist/AddHighlightModel/HighlightComponents.d.ts +0 -7
  87. package/dist/AddHighlightModel/HighlightComponents.js +0 -11
  88. package/dist/AddHighlightModel/HighlightComponents.js.map +0 -1
  89. package/dist/LaunchTView/components/ArrayReport.d.ts +0 -10
  90. package/dist/LaunchTView/components/ArrayReport.js +0 -59
  91. package/dist/LaunchTView/components/ArrayReport.js.map +0 -1
  92. package/dist/LaunchTView/components/LaunchTViewDialog.d.ts +0 -6
  93. package/dist/LaunchTView/components/LaunchTViewDialog.js +0 -124
  94. package/dist/LaunchTView/components/LaunchTViewDialog.js.map +0 -1
  95. package/dist/LaunchTView/sampleTree.d.ts +0 -37
  96. package/dist/LaunchTView/sampleTree.js +0 -65
  97. package/dist/LaunchTView/sampleTree.js.map +0 -1
  98. package/dist/LaunchTView/useTviewMsa.d.ts +0 -18
  99. package/dist/LaunchTView/useTviewMsa.js +0 -24
  100. package/dist/LaunchTView/useTviewMsa.js.map +0 -1
  101. package/dist/TViewPanel/coords.d.ts +0 -25
  102. package/dist/TViewPanel/coords.js +0 -56
  103. package/dist/TViewPanel/coords.js.map +0 -1
  104. package/src/AddHighlightModel/GenomeMouseoverHighlight.tsx +0 -46
  105. package/src/AddHighlightModel/HighlightComponents.tsx +0 -25
  106. package/src/LaunchTView/components/ArrayReport.tsx +0 -64
  107. package/src/LaunchTView/components/LaunchTViewDialog.tsx +0 -212
  108. package/src/LaunchTView/sampleTree.ts +0 -73
  109. package/src/LaunchTView/useTviewMsa.ts +0 -39
  110. package/src/TViewPanel/coords.ts +0 -65
@@ -1,9 +1,9 @@
1
- import { readConfObject } from '@jbrowse/core/configuration'
2
1
  import { parseLocString } from '@jbrowse/core/util'
2
+ import { getTrackName } from '@jbrowse/core/util/tracks'
3
3
 
4
- import { findTrackConf } from '../LaunchTView/fetchTviewPlan'
4
+ import { MAX_BP } from '../LaunchTView/limits'
5
5
 
6
- import type { TviewSource } from '../LaunchTView/fetchTviewPlan'
6
+ import type { FetchRegion, TviewSource } from '../LaunchTView/fetchTviewPlan'
7
7
  import type { AbstractSessionModel } from '@jbrowse/core/util'
8
8
 
9
9
  /**
@@ -23,15 +23,14 @@ export type TviewTrackInit = string | { trackId: string; sample?: string }
23
23
  * - A session can **author** a tview. `{ type: 'TView', init: { … } }` in a
24
24
  * defaultSession opens one with no click path — as does the flat form of the
25
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.
26
+ * - There is one code path. Launching from a menu, restoring a saved session
27
+ * and following a link all end up applying the same blob, and changing what
28
+ * the view shows from its own menu is replacing that blob.
29
29
  *
30
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.
31
+ * resolves to — the alignment and its row table — is kept out of snapshots and
32
+ * rebuilt from it on restore, so the blob is the only durable statement of what
33
+ * the view is.
35
34
  */
36
35
  export interface TviewInit {
37
36
  /** assembly the locus and the tracks belong to */
@@ -42,33 +41,76 @@ export interface TviewInit {
42
41
  tracks: TviewTrackInit[]
43
42
  }
44
43
 
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,
44
+ export type RegionCheck =
45
+ | { region: FetchRegion; error?: undefined }
46
+ | { region?: undefined; error: string }
47
+
48
+ /** the slice of a loaded assembly that a locstring is resolved against */
49
+ export interface LocAssembly {
50
+ name: string
51
+ isValidRefName: (refName: string) => boolean
52
+ getCanonicalRefName2: (refName: string) => string
53
+ getRegionForRefName: (
54
+ refName: string,
55
+ ) => { start: number; end: number } | undefined
52
56
  }
53
- export const initKeys = new Set<string>(Object.keys(initKeyMap))
54
57
 
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,
58
+ function errorText(e: unknown) {
59
+ return e instanceof Error ? e.message : String(e)
60
+ }
61
+
62
+ /**
63
+ * The region `loc` names on `assembly`, under the assembly's own name for the
64
+ * sequence and clamped to it, or why there is none: a locstring that does not
65
+ * parse, a region off the end of the contig, or one wider than {@link MAX_BP}.
66
+ * A bare refName means the whole contig, and is held to the same limit.
67
+ */
68
+ export function checkRegion(assembly: LocAssembly, loc: string): RegionCheck {
69
+ try {
70
+ const parsed = parseLocString(loc, refName =>
71
+ assembly.isValidRefName(refName),
72
+ )
73
+ const refName = assembly.getCanonicalRefName2(parsed.refName)
74
+ const contig = assembly.getRegionForRefName(refName)
75
+ return contig
76
+ ? clampToContig({
77
+ assemblyName: assembly.name,
78
+ refName,
79
+ start: Math.max(contig.start, parsed.start ?? contig.start),
80
+ end: Math.min(contig.end, parsed.end ?? contig.end),
81
+ loc,
82
+ contigLength: contig.end,
83
+ })
84
+ : { error: `${assembly.name} has no sequence named ${refName}` }
85
+ } catch (e) {
86
+ return { error: errorText(e) }
69
87
  }
70
88
  }
71
89
 
90
+ function clampToContig({
91
+ loc,
92
+ contigLength,
93
+ ...region
94
+ }: FetchRegion & { loc: string; contigLength: number }): RegionCheck {
95
+ const width = region.end - region.start
96
+ const n = (x: number) => x.toLocaleString('en-US')
97
+ return width <= 0
98
+ ? {
99
+ error: `${loc} lies outside ${region.refName}, which is ${n(contigLength)}bp`,
100
+ }
101
+ : width > MAX_BP
102
+ ? {
103
+ error: `Region is ${n(width)}bp, wider than the ${n(MAX_BP)}bp limit`,
104
+ }
105
+ : { region }
106
+ }
107
+
108
+ /** {@link checkRegion} for `init`, or undefined until its assembly has loaded */
109
+ export function initRegion(session: AbstractSessionModel, init: TviewInit) {
110
+ const assembly = session.assemblyManager.get(init.assembly)
111
+ return assembly?.initialized ? checkRegion(assembly, init.loc) : undefined
112
+ }
113
+
72
114
  /**
73
115
  * One entry of `init.tracks`, resolved against the session.
74
116
  *
@@ -76,38 +118,47 @@ export function initRegion(session: AbstractSessionModel, init: TviewInit) {
76
118
  * — what the init asked for, what the track config is called, or the trackId —
77
119
  * is settled once, at the point where all three are in hand, so nothing
78
120
  * 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
121
+ * configured with `name: ''` should fall through to its id, not label a band
80
122
  * with an empty string.
81
123
  */
82
124
  interface ResolvedTrack {
83
125
  trackId: string
84
- adapterConfig: unknown
126
+ adapterConfig: Record<string, unknown>
85
127
  sample: string
86
128
  }
87
129
 
130
+ export function entryTrackId(entry: TviewTrackInit) {
131
+ return typeof entry === 'string' ? entry : entry.trackId
132
+ }
133
+
88
134
  function resolveTrack(
89
135
  session: AbstractSessionModel,
90
136
  entry: TviewTrackInit,
91
137
  ): ResolvedTrack | undefined {
92
- const { trackId, sample } =
93
- typeof entry === 'string' ? { trackId: entry, sample: undefined } : entry
94
- const conf = findTrackConf(session, trackId)
138
+ const trackId = entryTrackId(entry)
139
+ const sample = typeof entry === 'string' ? undefined : entry.sample
140
+ const conf = session.getTrackById(trackId)
95
141
  return conf
96
142
  ? {
97
143
  trackId,
98
- adapterConfig: readConfObject(conf, 'adapter'),
99
- sample: sample || (readConfObject(conf, 'name') as string) || trackId,
144
+ adapterConfig: conf.adapter as Record<string, unknown>,
145
+ sample: sample || getTrackName(conf, session) || trackId,
100
146
  }
101
147
  : undefined
102
148
  }
103
149
 
150
+ /** what rows from `entry` are grouped under, or its trackId if no track has it */
151
+ export function trackLabel(
152
+ session: AbstractSessionModel,
153
+ entry: TviewTrackInit,
154
+ ) {
155
+ return resolveTrack(session, entry)?.sample ?? entryTrackId(entry)
156
+ }
157
+
104
158
  /**
105
159
  * The sources `init.tracks` names, or undefined until every one of them
106
160
  * resolves. All or nothing: a partial set comes back with samples missing and
107
161
  * 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
162
  */
112
163
  export function initSources(
113
164
  session: AbstractSessionModel,
@@ -115,13 +166,15 @@ export function initSources(
115
166
  ): TviewSource[] | undefined {
116
167
  const resolved = init.tracks.map(entry => resolveTrack(session, entry))
117
168
  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
- }))
169
+ return found.length === init.tracks.length ? found : undefined
170
+ }
171
+
172
+ /** the trackIds `init.tracks` names that this session has no track for */
173
+ export function missingTrackIds(
174
+ session: AbstractSessionModel,
175
+ init: TviewInit,
176
+ ) {
177
+ return init.tracks
178
+ .map(entryTrackId)
179
+ .filter(trackId => !session.getTrackById(trackId))
127
180
  }
@@ -0,0 +1,126 @@
1
+ import { getSession } from '@jbrowse/core/util'
2
+
3
+ import { entryTrackId, trackLabel } from './init'
4
+ import {
5
+ alignmentsTrackIds,
6
+ isGenomeView,
7
+ regionLaunch,
8
+ } from '../LaunchTView/launch'
9
+
10
+ import type { TviewInit } from './init'
11
+ import type { RegionLaunch } from '../LaunchTView/launch'
12
+ import type { MenuItem } from '@jbrowse/core/ui'
13
+ import type { IAnyStateTreeNode } from '@jbrowse/mobx-state-tree'
14
+
15
+ export const TRACKS_LABEL = 'Tracks'
16
+ export const CURRENT_REGION_LABEL = "Show the connected view's current region"
17
+
18
+ export interface TrackChoice {
19
+ trackId: string
20
+ label: string
21
+ }
22
+
23
+ /** the alignments tracks open in the genome view, then any others `init` reads */
24
+ export function trackChoiceIds(init: TviewInit, openTrackIds: string[]) {
25
+ const open = new Set(openTrackIds)
26
+ return [
27
+ ...openTrackIds,
28
+ ...init.tracks.map(entryTrackId).filter(trackId => !open.has(trackId)),
29
+ ]
30
+ }
31
+
32
+ export function withTrack(
33
+ init: TviewInit,
34
+ trackId: string,
35
+ included: boolean,
36
+ ): TviewInit {
37
+ const others = init.tracks.filter(entry => entryTrackId(entry) !== trackId)
38
+ return {
39
+ ...init,
40
+ tracks: included
41
+ ? others.length === init.tracks.length
42
+ ? [...init.tracks, trackId]
43
+ : init.tracks
44
+ : others,
45
+ }
46
+ }
47
+
48
+ export function atRegion(
49
+ init: TviewInit,
50
+ { assembly, loc }: { assembly: string; loc: string },
51
+ ): TviewInit {
52
+ return { ...init, assembly, loc }
53
+ }
54
+
55
+ export function initMenuItems({
56
+ init,
57
+ choices,
58
+ region,
59
+ setInit,
60
+ }: {
61
+ init: TviewInit
62
+ choices: TrackChoice[]
63
+ region: RegionLaunch
64
+ setInit: (init: TviewInit) => void
65
+ }): MenuItem[] {
66
+ const included = new Set(init.tracks.map(entryTrackId))
67
+ return [
68
+ {
69
+ label: TRACKS_LABEL,
70
+ type: 'subMenu',
71
+ subMenu: choices.map(({ trackId, label }) => {
72
+ const checked = included.has(trackId)
73
+ return {
74
+ label,
75
+ type: 'checkbox',
76
+ checked,
77
+ disabled: checked && included.size === 1,
78
+ disabledHelpText: 'A tview reads at least one track',
79
+ onClick: () => {
80
+ setInit(withTrack(init, trackId, !checked))
81
+ },
82
+ }
83
+ }),
84
+ },
85
+ {
86
+ label: CURRENT_REGION_LABEL,
87
+ disabled: region.reason !== undefined,
88
+ subLabel: region.reason,
89
+ onClick: () => {
90
+ if (region.reason === undefined) {
91
+ setInit(atRegion(init, region))
92
+ }
93
+ },
94
+ },
95
+ ]
96
+ }
97
+
98
+ export function tviewInitMenuItems(
99
+ view: IAnyStateTreeNode & {
100
+ init?: TviewInit
101
+ connectedView?: object
102
+ setInit: (init: TviewInit) => void
103
+ },
104
+ ) {
105
+ const { init } = view
106
+ const connectedView =
107
+ view.connectedView && isGenomeView(view.connectedView)
108
+ ? view.connectedView
109
+ : undefined
110
+ const session = getSession(view)
111
+ return init
112
+ ? initMenuItems({
113
+ init,
114
+ choices: trackChoiceIds(
115
+ init,
116
+ connectedView ? alignmentsTrackIds(connectedView.tracks) : [],
117
+ ).map(trackId => ({ trackId, label: trackLabel(session, trackId) })),
118
+ region: connectedView
119
+ ? regionLaunch(session, connectedView.visibleWholeBaseRegions)
120
+ : { reason: 'No connected genome view' },
121
+ setInit: next => {
122
+ view.setInit(next)
123
+ },
124
+ })
125
+ : []
126
+ }