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,132 @@
1
+ import { alignToUnit } from './align'
2
+
3
+ import type { ReadLayout } from './readLayout'
4
+ import type { ReferenceArray } from './repeats'
5
+
6
+ /**
7
+ * A tandem array laid out as one block of columns per copy, replacing the
8
+ * reference columns the array covers.
9
+ *
10
+ * The interval comes from the reference and the unit comes with it, so every
11
+ * row is measured over the same span against the same unit. That is what makes
12
+ * the counts comparable: a read's allele is what it has between here and here,
13
+ * whatever the aligner did with the gap, and the reference is just the row whose
14
+ * allele the coordinates are named after.
15
+ */
16
+ export interface ArrayBlock {
17
+ /** reference position the array starts at, inclusive */
18
+ start: number
19
+ /** reference position the array ends at, exclusive */
20
+ end: number
21
+ period: number
22
+ unit: string
23
+ /** columns the block occupies */
24
+ width: number
25
+ /** columns each copy occupies, left to right; sums to `width` */
26
+ unitWidths: number[]
27
+ /** gapped block, by row name; only rows whose allele could be measured */
28
+ rowByName: Map<string, string>
29
+ /** copies carried, by row name */
30
+ copiesByName: Map<string, number>
31
+ /** allele length in bp, by row name */
32
+ lengthByName: Map<string, number>
33
+ }
34
+
35
+ const SPANNED_GAP = '-'
36
+ const ABSENT = '.'
37
+
38
+ /**
39
+ * What one row has between two reference positions: its matched bases, plus
40
+ * whatever it inserted inside, minus whatever it deleted.
41
+ *
42
+ * This is the measurement the insertion-anchored reading cannot make. An indel
43
+ * inside an array has no unique placement, so two reads carrying the same allele
44
+ * can disagree about which reference position it is inserted at and by how much;
45
+ * summed over the interval, those choices cancel and both come back the same
46
+ * length. Undefined when the row does not reach both edges — copies cannot be
47
+ * counted from a read that stops inside the array, and guessing from a partial
48
+ * one is how a truncated read reads as a contracted allele.
49
+ */
50
+ export function extractAllele(read: ReadLayout, start: number, end: number) {
51
+ const last = read.start + read.refChars.length
52
+ if (read.start > start || last < end) {
53
+ return undefined
54
+ }
55
+ let ret = ''
56
+ for (let pos = start; pos <= end; pos++) {
57
+ ret += read.insertions.get(pos) ?? ''
58
+ if (pos < end) {
59
+ const char = read.refChars[pos - read.start]!
60
+ if (char === ABSENT) {
61
+ // an N op skips the position rather than deleting it, so the row has no
62
+ // allele here at all rather than a shorter one
63
+ return undefined
64
+ }
65
+ if (char !== SPANNED_GAP) {
66
+ ret += char
67
+ }
68
+ }
69
+ }
70
+ return ret
71
+ }
72
+
73
+ /** Reference positions an array owns, including the insertion slot at its right edge. */
74
+ export function arrayInsertionKeys(array: { start: number; end: number }) {
75
+ const ret: number[] = []
76
+ for (let pos = array.start; pos <= array.end; pos++) {
77
+ ret.push(pos)
78
+ }
79
+ return ret
80
+ }
81
+
82
+ /**
83
+ * Lay every row's allele out unit-per-block, one block per array.
84
+ *
85
+ * Arrays whose alleles are all one length still get a block: squaring the copies
86
+ * up against each other is what turns "this row is 63 bases long" into "this row
87
+ * has 21 copies and the 12th one differs", and that is true whether or not the
88
+ * rows disagree.
89
+ */
90
+ export function buildArrayBlocks(
91
+ reads: ReadLayout[],
92
+ arrays: ReferenceArray[],
93
+ ) {
94
+ const ret: ArrayBlock[] = []
95
+ for (const array of arrays) {
96
+ const alleleByName = new Map<string, string>()
97
+ for (const read of reads) {
98
+ const allele = extractAllele(read, array.start, array.end)
99
+ if (allele !== undefined) {
100
+ alleleByName.set(read.name, allele)
101
+ }
102
+ }
103
+ const aligned = alignToUnit([...alleleByName.values()], array.unit)
104
+ if (!aligned) {
105
+ continue
106
+ }
107
+ const rowByName = new Map<string, string>()
108
+ const copiesByName = new Map<string, number>()
109
+ const lengthByName = new Map<string, number>()
110
+ for (const [name, allele] of alleleByName) {
111
+ const row = aligned.gapped.get(allele)
112
+ const copies = aligned.copies.get(allele)
113
+ if (row !== undefined && copies !== undefined) {
114
+ rowByName.set(name, row)
115
+ copiesByName.set(name, copies)
116
+ lengthByName.set(name, allele.length)
117
+ }
118
+ }
119
+ ret.push({
120
+ start: array.start,
121
+ end: array.end,
122
+ period: aligned.period,
123
+ unit: array.unit,
124
+ width: aligned.unitWidths.reduce((a, b) => a + b, 0),
125
+ unitWidths: aligned.unitWidths,
126
+ rowByName,
127
+ copiesByName,
128
+ lengthByName,
129
+ })
130
+ }
131
+ return ret
132
+ }
@@ -0,0 +1,64 @@
1
+ import React from 'react'
2
+
3
+ import { Typography } from '@mui/material'
4
+
5
+ import type { TviewPlanResult } from '../TviewGetPlanRpc'
6
+
7
+ /** allele lengths seen, commonest first, as `63bp x12` */
8
+ function alleleTally(lengths: [string, number][]) {
9
+ const counts = new Map<number, number>()
10
+ for (const [, length] of lengths) {
11
+ counts.set(length, (counts.get(length) ?? 0) + 1)
12
+ }
13
+ return [...counts]
14
+ .sort((a, b) => b[1] - a[1] || a[0] - b[0])
15
+ .map(([length, n]) => `${length}bp x${n}`)
16
+ }
17
+
18
+ /**
19
+ * What the reads say about the arrays before the view is opened, since the
20
+ * number is often the whole reason for opening it and a picture of 400 columns
21
+ * is a slow way to read one off.
22
+ */
23
+ export default function ArrayReport({ data }: { data: TviewPlanResult }) {
24
+ const { arrays, subjectIndex, region } = data
25
+ const subject = subjectIndex === undefined ? undefined : arrays[subjectIndex]
26
+ if (!subject) {
27
+ return arrays.length ? null : (
28
+ <Typography variant="body2">
29
+ No tandem array in the reference here, so the reads are laid out base by
30
+ base.
31
+ </Typography>
32
+ )
33
+ }
34
+ const copies = subject.copies
35
+ return (
36
+ <>
37
+ <Typography variant="subtitle2">
38
+ Tandem array at {region.refName}:{subject.start.toLocaleString('en-US')}
39
+ -{subject.end.toLocaleString('en-US')}, {subject.period}bp unit{' '}
40
+ {subject.unit}
41
+ </Typography>
42
+ <Typography variant="body2">
43
+ {copies.length} of {data.rowCount} rows span it end to end and carry{' '}
44
+ {Math.min(...copies.map(c => c[1]))}&ndash;
45
+ {Math.max(...copies.map(c => c[1]))} copies. Allele lengths:{' '}
46
+ {alleleTally(subject.lengths).join(', ')}.
47
+ </Typography>
48
+ <Typography variant="body2">
49
+ Each copy gets its own block of columns, so one divergent copy shows up
50
+ as a column rather than shifting every copy after it. Blocks are array
51
+ order, not homology: copies are counted from the left edge, and arrays
52
+ expand and contract anywhere inside themselves, so the 9th copy of one
53
+ row need not be the 9th of another. Read down a row, not across two.
54
+ </Typography>
55
+ {arrays.length > 1 ? (
56
+ <Typography variant="body2">
57
+ {arrays.length - 1} shorter{' '}
58
+ {arrays.length === 2 ? 'array is' : 'arrays are'} also laid out per
59
+ copy; rows are ordered by this one.
60
+ </Typography>
61
+ ) : null}
62
+ </>
63
+ )
64
+ }
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useState } from 'react'
2
2
 
3
3
  import { getConf } from '@jbrowse/core/configuration'
4
4
  import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
@@ -7,15 +7,42 @@ import {
7
7
  getContainingView,
8
8
  getSession,
9
9
  } from '@jbrowse/core/util'
10
- import { Button, DialogActions, DialogContent } from '@mui/material'
10
+ import {
11
+ Button,
12
+ Checkbox,
13
+ DialogActions,
14
+ DialogContent,
15
+ FormControlLabel,
16
+ Typography,
17
+ } from '@mui/material'
11
18
 
12
- import { MAX_BP, MAX_CELLS } from '../limits'
13
- import { renderTviewMsa } from '../tview'
19
+ import ArrayReport from './ArrayReport'
20
+ import { MAX_BP } from '../limits'
14
21
  import { useTviewMsa } from '../useTviewMsa'
15
22
 
23
+ import type { TviewInit } from '../../TViewPanel/init'
16
24
  import type { AbstractTrackModel } from '@jbrowse/core/util'
17
25
  import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
18
26
 
27
+ // how much of the alignment the default column width aims to put on screen
28
+ const FIT_WIDTH_PX = 3000
29
+
30
+ function trackLabel(track: AbstractTrackModel) {
31
+ return (
32
+ (getConf(track, 'name') as string) || (getConf(track, 'trackId') as string)
33
+ )
34
+ }
35
+
36
+ /** every alignments track open in the same view, the launching one first */
37
+ function peerTracks(view: LinearGenomeViewModel, model: AbstractTrackModel) {
38
+ const alignments = view.tracks.filter(track =>
39
+ track.displays.some(
40
+ (display: { type: string }) => display.type === 'LinearAlignmentsDisplay',
41
+ ),
42
+ ) as AbstractTrackModel[]
43
+ return [model, ...alignments.filter(t => t.id !== model.id)]
44
+ }
45
+
19
46
  export default function LaunchTViewDialog({
20
47
  handleClose,
21
48
  model,
@@ -26,8 +53,6 @@ export default function LaunchTViewDialog({
26
53
  const view = getContainingView(model) as LinearGenomeViewModel
27
54
  const session = getSession(model)
28
55
  const block = view.dynamicBlocks.contentBlocks[0]
29
- // assemblyName is required: the RPC uses it to map the view's refName onto
30
- // whatever the file calls that sequence (refNameAliases)
31
56
  const region = block
32
57
  ? {
33
58
  assemblyName: block.assemblyName,
@@ -39,16 +64,42 @@ export default function LaunchTViewDialog({
39
64
  const width = region ? region.end - region.start : 0
40
65
  const tooWide = width > MAX_BP
41
66
 
67
+ const candidates = peerTracks(view, model)
68
+ // the launching track is always in; the others are opt-in, because pulling
69
+ // every open pileup into one alignment is a much bigger fetch than the menu
70
+ // item that got here suggests
71
+ const [extra, setExtra] = useState<string[]>([])
72
+ const chosen = candidates.filter(
73
+ t => t.id === model.id || extra.includes(t.id),
74
+ )
75
+
76
+ // The dialog's whole output. Everything below either previews what this
77
+ // resolves to or hands it to a view, so what the button opens is the same
78
+ // blob a session could have been authored with.
79
+ const init: TviewInit | undefined = region
80
+ ? {
81
+ assembly: region.assemblyName,
82
+ loc: assembleLocString(region),
83
+ tracks: chosen.map(t => ({
84
+ trackId: getConf(t, 'trackId') as string,
85
+ sample: trackLabel(t),
86
+ })),
87
+ }
88
+ : undefined
89
+
42
90
  const { data, error, isLoading } = useTviewMsa({
43
- model,
44
- region: tooWide ? undefined : region,
91
+ session,
92
+ init: tooWide ? undefined : init,
45
93
  })
46
- const displayName = region ? assembleLocString(region) : 'Unknown'
47
- const tooLarge = !!data && data.plan.cellCount > MAX_CELLS
48
- // lets the view rebuild itself after a session reload
49
- const msaSource = region
50
- ? { trackId: getConf(model, 'trackId'), assemblyName: region.assemblyName }
51
- : undefined
94
+
95
+ // 10 is comfortable for an ordinary pileup, but an unrolled tandem array runs
96
+ // to hundreds of columns and at 10 almost none of it is on screen at once.
97
+ // Fits the alignment to roughly two screen-widths; a no-op for the narrow
98
+ // regions that already fitted.
99
+ const totalColumns = data?.columnCount ?? 0
100
+ const colWidth = totalColumns
101
+ ? Math.max(1, Math.min(10, Math.floor(FIT_WIDTH_PX / totalColumns)))
102
+ : 10
52
103
 
53
104
  return (
54
105
  <Dialog
@@ -60,53 +111,85 @@ export default function LaunchTViewDialog({
60
111
  open
61
112
  >
62
113
  <DialogContent>
63
- <div>
114
+ <Typography>
64
115
  Create a view similar to "samtools tview" for the reads in the current
65
- region: {displayName}
66
- </div>
67
- {tooWide ? (
116
+ region: {init?.loc ?? 'Unknown'}
117
+ </Typography>
118
+ {candidates.length > 1 ? (
68
119
  <div>
120
+ <Typography variant="subtitle2">
121
+ Include reads from other alignment tracks in this view
122
+ </Typography>
123
+ {candidates.slice(1).map(track => (
124
+ <FormControlLabel
125
+ key={track.id}
126
+ control={
127
+ <Checkbox
128
+ checked={extra.includes(track.id)}
129
+ onChange={event => {
130
+ setExtra(
131
+ event.target.checked
132
+ ? [...extra, track.id]
133
+ : extra.filter(id => id !== track.id),
134
+ )
135
+ }}
136
+ />
137
+ }
138
+ label={trackLabel(track)}
139
+ />
140
+ ))}
141
+ </div>
142
+ ) : null}
143
+ {tooWide ? (
144
+ <Typography>
69
145
  Region is {width.toLocaleString('en-US')}bp, wider than the{' '}
70
146
  {MAX_BP.toLocaleString('en-US')}bp limit. Zoom in and try again.
71
- </div>
147
+ </Typography>
72
148
  ) : error ? (
73
149
  <ErrorMessage error={error} />
74
150
  ) : isLoading ? (
75
- <div>Loading...</div>
76
- ) : tooLarge ? (
77
- <div>
78
- {data.rowCount.toLocaleString('en-US')} reads over{' '}
79
- {data.plan.layout.totalColumns.toLocaleString('en-US')} columns is{' '}
80
- {data.plan.cellCount.toLocaleString('en-US')} cells, above the{' '}
81
- {MAX_CELLS.toLocaleString('en-US')} limit. Zoom in and try again.
82
- </div>
151
+ <Typography>Loading...</Typography>
152
+ ) : data?.tooLarge ? (
153
+ <Typography>
154
+ {data.rowCount.toLocaleString('en-US')} rows over{' '}
155
+ {data.columnCount.toLocaleString('en-US')} columns is{' '}
156
+ {data.cellCount.toLocaleString('en-US')} cells, which is too large
157
+ to render. Zoom in and try again.
158
+ </Typography>
83
159
  ) : data ? (
84
- <div>{data.rowCount} reads with sequence data found</div>
160
+ <>
161
+ <Typography>
162
+ {data.rowCount} rows
163
+ {data.referenceName
164
+ ? ' (the reference plus every read with sequence)'
165
+ : ' of reads with sequence data'}
166
+ {data.samples.length > 1
167
+ ? `, from ${data.samples.length} tracks`
168
+ : ''}
169
+ </Typography>
170
+ <ArrayReport data={data} />
171
+ </>
85
172
  ) : (
86
- <div>No region is currently visible.</div>
173
+ <Typography>No region is currently visible.</Typography>
87
174
  )}
88
175
  </DialogContent>
89
176
  <DialogActions>
90
177
  <Button
91
178
  variant="contained"
92
179
  color="primary"
93
- disabled={!data?.rowCount || tooLarge}
180
+ disabled={!data?.msa || !init}
94
181
  onClick={() => {
95
- if (data && !tooLarge) {
182
+ if (init) {
96
183
  session.addView('TView', {
97
184
  type: 'TView',
98
- displayName,
99
- colWidth: 10,
185
+ displayName: init.loc,
186
+ init,
187
+ colWidth,
100
188
  rowHeight: 12,
101
189
  labelsAlignRight: true,
102
190
  colorSchemeName: 'jbrowse_dna',
191
+ drawTree: init.tracks.length > 1,
103
192
  connectedViewId: view.id,
104
- msaRegion: data.plan.region,
105
- insertionWidths: data.plan.insertionWidths,
106
- msaSource,
107
- data: {
108
- msa: renderTviewMsa(data.plan),
109
- },
110
193
  })
111
194
  }
112
195
  handleClose()
@@ -1,14 +1,10 @@
1
- import { getConf, readConfObject } from '@jbrowse/core/configuration'
2
- import { getRpcSessionId } from '@jbrowse/core/util/tracks'
1
+ import { readConfObject } from '@jbrowse/core/configuration'
3
2
 
4
- import { planTviewMsa } from './tview'
3
+ import { MAX_CELLS } from './limits'
5
4
 
5
+ import type { TviewPlanResult } from './TviewGetPlanRpc'
6
6
  import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
7
- import type {
8
- AbstractSessionModel,
9
- AbstractTrackModel,
10
- Feature,
11
- } from '@jbrowse/core/util'
7
+ import type { AbstractSessionModel } from '@jbrowse/core/util'
12
8
 
13
9
  /** the RPC needs assemblyName to resolve refNameAliases for the file */
14
10
  export interface FetchRegion {
@@ -18,17 +14,12 @@ export interface FetchRegion {
18
14
  end: number
19
15
  }
20
16
 
21
- /** what CoreGetFeatures needs, reachable from a live track or from its config */
17
+ /** one track's worth of rows, and the name they are grouped under */
22
18
  export interface TviewSource {
23
19
  adapterConfig: unknown
24
- rpcSessionId: string
25
- }
26
-
27
- export function sourceFromTrack(track: AbstractTrackModel): TviewSource {
28
- return {
29
- adapterConfig: getConf(track, 'adapter'),
30
- rpcSessionId: getRpcSessionId(track),
31
- }
20
+ /** the label rows from this file carry; omitted when there is only one */
21
+ sample?: string
22
+ trackId: string
32
23
  }
33
24
 
34
25
  /**
@@ -57,39 +48,48 @@ export function findTrackConf(session: SessionTrackLookup, trackId: string) {
57
48
  }
58
49
 
59
50
  /**
60
- * A rebuild runs from the track's config rather than a track model, so it works
61
- * whether or not the track is still open anywhere in the session.
51
+ * The assembly's own sequence adapter, which is what makes the reference a row
52
+ * and, through it, makes an array an interval rather than an insertion. An
53
+ * assembly that cannot supply one still works: the alignment is then reads only
54
+ * and no array is reported, which is the pre-reference behaviour.
62
55
  */
63
- export function sourceFromConfig(conf: AnyConfigurationModel): TviewSource {
64
- return {
65
- adapterConfig: readConfObject(conf, 'adapter'),
66
- rpcSessionId: `tview-${readConfObject(conf, 'trackId')}`,
67
- }
56
+ export function sequenceAdapterConfig(
57
+ session: AbstractSessionModel,
58
+ assemblyName: string,
59
+ ) {
60
+ const assembly = session.assemblyManager.get(assemblyName)
61
+ const conf = assembly?.configuration
62
+ return conf
63
+ ? (readConfObject(conf, ['sequence', 'adapter']) as
64
+ Record<string, unknown> | undefined)
65
+ : undefined
68
66
  }
69
67
 
68
+ /**
69
+ * One RPC per launch, however many files it draws from. The session id is
70
+ * shared across the sources so the worker keeps one adapter cache for the view
71
+ * rather than one per file.
72
+ */
70
73
  export async function fetchTviewPlan({
71
74
  session,
72
- source,
75
+ sources,
73
76
  region,
77
+ maxCells = MAX_CELLS,
74
78
  }: {
75
79
  session: AbstractSessionModel
76
- source: TviewSource
80
+ sources: TviewSource[]
77
81
  region: FetchRegion
82
+ maxCells?: number
78
83
  }) {
79
- const { adapterConfig, rpcSessionId } = source
80
- const feats = (await session.rpcManager.call(
81
- rpcSessionId,
82
- 'CoreGetFeatures',
83
- {
84
- adapterConfig,
85
- sessionId: rpcSessionId,
86
- regions: [region],
87
- },
88
- )) as Feature[]
89
- const features = feats.filter(f => !!f.get('seq'))
90
- // only planned, not rendered: a caller may cancel, or find it too large
91
- return {
92
- plan: planTviewMsa({ features, ...region }),
93
- rowCount: features.length,
94
- }
84
+ const rpcSessionId = `tview-${sources.map(s => s.trackId).join(',')}`
85
+ return (await session.rpcManager.call(rpcSessionId, 'TviewGetPlan', {
86
+ sessionId: rpcSessionId,
87
+ sources: sources.map(s => ({
88
+ adapterConfig: s.adapterConfig,
89
+ sample: s.sample,
90
+ })),
91
+ sequenceAdapterConfig: sequenceAdapterConfig(session, region.assemblyName),
92
+ region,
93
+ maxCells,
94
+ })) as TviewPlanResult
95
95
  }
@@ -0,0 +1,50 @@
1
+ import { initKeys } from '../TViewPanel/init'
2
+
3
+ import type { TviewInit } from '../TViewPanel/init'
4
+ import type PluginManager from '@jbrowse/core/PluginManager'
5
+ import type { AbstractSessionModel } from '@jbrowse/core/util'
6
+
7
+ /**
8
+ * `LaunchView-TView`, so a session spec URL can open one.
9
+ *
10
+ * The two ways of writing a view are not the same shape, and JBrowse's spec
11
+ * loader says so out loud: a spec view is **flat arguments** to this launcher,
12
+ * while a config or defaultSession view is MST state, where anything needing
13
+ * resolution on load lives under the view's own `init`. So the spec
14
+ *
15
+ * { type: 'TView', assembly: 'hg19', loc: 'chrX:1..2', tracks: ['HG002'] }
16
+ *
17
+ * and the config
18
+ *
19
+ * { type: 'TView', init: { assembly: 'hg19', loc: '…', tracks: […] } }
20
+ *
21
+ * are the same view, and this is the one line between them. Splitting on
22
+ * `initKeys` rather than listing the pass-through props means every react-msaview
23
+ * view prop — colWidth, rowHeight, colorSchemeName, the ones added next — rides
24
+ * along without being enumerated here.
25
+ */
26
+ export type LaunchTViewArgs = { session: AbstractSessionModel } & Record<
27
+ string,
28
+ unknown
29
+ >
30
+
31
+ export default function LaunchTViewF(pluginManager: PluginManager) {
32
+ /** #extensionPoint LaunchView-TView | async | Programmatically launch a tview */
33
+ pluginManager.addToExtensionPoint(
34
+ 'LaunchView-TView',
35
+ (args: LaunchTViewArgs) => {
36
+ const { session, ...spec } = args
37
+ const init: Record<string, unknown> = {}
38
+ const viewProps: Record<string, unknown> = {}
39
+ for (const [key, value] of Object.entries(spec)) {
40
+ ;(initKeys.has(key) ? init : viewProps)[key] = value
41
+ }
42
+ session.addView('TView', {
43
+ type: 'TView',
44
+ ...viewProps,
45
+ init: init as unknown as TviewInit,
46
+ })
47
+ return args
48
+ },
49
+ )
50
+ }