jbrowse-plugin-tview 2.0.6 → 2.2.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 (77) hide show
  1. package/README.md +222 -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 +106 -9
  9. package/dist/LaunchTView/align.js +349 -15
  10. package/dist/LaunchTView/align.js.map +1 -1
  11. package/dist/LaunchTView/alleles.d.ts +83 -0
  12. package/dist/LaunchTView/alleles.js +180 -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/repeatStats.d.ts +56 -0
  29. package/dist/LaunchTView/repeatStats.js +109 -0
  30. package/dist/LaunchTView/repeatStats.js.map +1 -0
  31. package/dist/LaunchTView/repeats.d.ts +68 -0
  32. package/dist/LaunchTView/repeats.js +200 -0
  33. package/dist/LaunchTView/repeats.js.map +1 -0
  34. package/dist/LaunchTView/sampleTree.d.ts +37 -0
  35. package/dist/LaunchTView/sampleTree.js +65 -0
  36. package/dist/LaunchTView/sampleTree.js.map +1 -0
  37. package/dist/LaunchTView/tview.d.ts +67 -44
  38. package/dist/LaunchTView/tview.js +193 -121
  39. package/dist/LaunchTView/tview.js.map +1 -1
  40. package/dist/LaunchTView/useTviewMsa.d.ts +13 -9
  41. package/dist/LaunchTView/useTviewMsa.js +15 -11
  42. package/dist/LaunchTView/useTviewMsa.js.map +1 -1
  43. package/dist/TViewPanel/coords.d.ts +9 -1
  44. package/dist/TViewPanel/coords.js +22 -2
  45. package/dist/TViewPanel/coords.js.map +1 -1
  46. package/dist/TViewPanel/init.d.ts +56 -0
  47. package/dist/TViewPanel/init.js +59 -0
  48. package/dist/TViewPanel/init.js.map +1 -0
  49. package/dist/TViewPanel/model.d.ts +109 -93
  50. package/dist/TViewPanel/model.js +73 -51
  51. package/dist/TViewPanel/model.js.map +1 -1
  52. package/dist/index.js +5 -1
  53. package/dist/index.js.map +1 -1
  54. package/dist/jbrowse-plugin-tview.umd.production.min.js +25 -25
  55. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
  56. package/dist/version.d.ts +1 -1
  57. package/dist/version.js +1 -1
  58. package/package.json +9 -3
  59. package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +264 -0
  60. package/src/LaunchTView/TviewGetPlanRpc/index.ts +14 -0
  61. package/src/LaunchTView/align.ts +406 -17
  62. package/src/LaunchTView/alleles.ts +229 -0
  63. package/src/LaunchTView/components/ArrayReport.tsx +64 -0
  64. package/src/LaunchTView/components/LaunchTViewDialog.tsx +122 -39
  65. package/src/LaunchTView/fetchTviewPlan.ts +42 -42
  66. package/src/LaunchTView/launchView.ts +50 -0
  67. package/src/LaunchTView/readLayout.ts +145 -0
  68. package/src/LaunchTView/repeatStats.ts +170 -0
  69. package/src/LaunchTView/repeats.ts +218 -0
  70. package/src/LaunchTView/sampleTree.ts +73 -0
  71. package/src/LaunchTView/tview.ts +265 -157
  72. package/src/LaunchTView/useTviewMsa.ts +20 -17
  73. package/src/TViewPanel/coords.ts +23 -1
  74. package/src/TViewPanel/init.ts +127 -0
  75. package/src/TViewPanel/model.ts +82 -61
  76. package/src/index.ts +5 -1
  77. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -20,13 +20,182 @@ insertion show their base, reads that span the position without it show `-`, and
20
20
  reads that do not cover it show `.` — so every row stays the same width and the
21
21
  reference columns still line up.
22
22
 
23
- Regenerate with `pnpm figure`.
23
+ Regenerate with `pnpm figure`; the tandem-repeat figures below come from
24
+ `pnpm figures:repeats`.
25
+
26
+ ## How it is built
27
+
28
+ The alignment is built in an **RPC worker** (`TviewGetPlan`), so the reads never
29
+ cross to the main thread — the fetch, the pairwise alignments and the string
30
+ building all happen there and only the FASTA comes back. That is also what makes
31
+ several files one call: their rows are squared up against the same reference
32
+ interval, so an array's copies are counted once, over rows from all of them.
33
+
34
+ ## Tandem repeats
35
+
36
+ ![ABCA7 VNTR alleles in HG003](img/repeat-abca7-vntr.png)
37
+
38
+ The ABCA7 VNTR in one PacBio HiFi sample, a copy per block of columns. Every row
39
+ carries its copy count, and the rows sort by it, so the genotype is the step in
40
+ the ladder — the two alleles the table below reports for HG003, with a scatter
41
+ of reads between them. Laid out base by base this is 2.2kb of sequence with
42
+ nothing to line it up against.
43
+
44
+ ### An array is an interval, not an insertion
45
+
46
+ The array is found in the **reference**, and a row's allele is what it has
47
+ between the two ends of that interval — its matched bases, plus what it inserted
48
+ inside, minus what it deleted. Everything else follows from that:
49
+
50
+ - **The count is the allele, not the excess.** An STR is already in the
51
+ reference, so a read's insertion is only how much more it carries than hg19
52
+ does, and a contracted allele inserts nothing at all.
53
+ - **One locus is one array.** An indel inside an array has no unique placement,
54
+ so an aligner anchors different reads at different positions; measured over an
55
+ interval those choices cancel. ATXN3 in HG002 reported as four separate arrays
56
+ when anchored on insertions, splitting one locus's alleles across four counts.
57
+ - **The interval grows to the allele.** Measuring over an interval settles the
58
+ indels an aligner placed _inside_ it. It settles nothing about the ones it
59
+ placed just outside, and an aligner will happily anchor an expansion at the
60
+ base before the array starts: there the insertion belongs to no allele, so it
61
+ becomes a run of columns of its own and the read carrying it is counted as if
62
+ it matched the reference. An array therefore widens over an insertion within
63
+ one copy of its edge whose sequence is the array's own unit. At ATXN3 that is
64
+ 60 of 162 reads, and it is the difference between HG004 reading as 8/8 with
65
+ three odd reads and reading as 8/21.
66
+ - **Every spanning read is counted**, including the ones that match the
67
+ reference exactly — usually the commonest allele, and invisible to anything
68
+ keyed on insertions.
69
+ - **The reference is a row.** It is laid out and counted like any other allele,
70
+ which is what the coordinates are named after.
71
+
72
+ Nothing declares a repeat. Periods from 2 to 300bp are scanned, the shortest one
73
+ that explains a stretch wins, and a homopolymer is declined — it is periodic at
74
+ every lag and its "unit" is an arbitrary cut through one run.
75
+
76
+ At a detected array:
77
+
78
+ - **copy k of every row occupies the same block**, so one divergent copy shows
79
+ up as a column rather than shifting every copy after it.
80
+ - **each row is labelled with its copy count** (`readname|n=32`), which is the
81
+ measurement, rather than leaving it to be read off where the row ends.
82
+ - **rows are ordered longest allele first**, so the alleles form a ladder.
83
+ - the default column width shrinks to fit the array on screen.
84
+
85
+ **Blocks are array order, not homology.** Copies are counted from the left edge
86
+ of the interval, and arrays expand and contract anywhere inside themselves, so
87
+ the 9th copy of one row need not be the 9th copy of another. Reading down a row
88
+ is sound; reading across two is a hypothesis.
89
+
90
+ ### What the numbers were checked against
91
+
92
+ `pnpm report:repeats` measures the GIAB Ashkenazi trio (PacBio HiFi, GRCh37) at
93
+ known loci with the same plan builder the view runs. **Every number in this
94
+ section is written by `pnpm readme:repeats` and checked by
95
+ `pnpm readme:repeats --check`**, so it is a rendering of a measurement rather
96
+ than a figure typed once that nothing afterwards could contradict.
97
+
98
+ A copy count is reported as one of a sample's alleles when at least 15% of that
99
+ sample's spanning reads carry it, and never on one read. That is a report of
100
+ what the reads say and not a genotype call — it knows no ploidy, so a homozygote
101
+ and a haploid locus both come back as one number. Read that way, every locus
102
+ with variation to check is Mendelian:
103
+
104
+ <!-- repeat-genotypes -->
105
+
106
+ | locus | ref | HG003 (father) | HG004 (mother) | HG002 (son) |
107
+ | ---------------- | --- | -------------- | -------------- | ----------- |
108
+ | HTT (CAG) | 33 | 31 | 31 / 38 | 31 / 38 |
109
+ | ATXN3 (CTG) | 8 | 15 / 17 | 8 / 21 | 17 / 21 |
110
+ | TCF4 CTG18.1 | 38 | 25 / 46 | 28 / 38 | 28 / 46 |
111
+ | DMPK (CTG) | 21 | 12 / 14 | 6 / 12 | 12 |
112
+ | FMR1 (CGG), X | 22 | 31 | 32 / 33 | 33 |
113
+ | C9orf72 (GGGGCC) | 4 | 3 | 3 | 3 |
114
+ | ABCA7 VNTR | 20 | 21 / 89 | 22 / 26 | 22 |
115
+
116
+ <!-- /repeat-genotypes -->
117
+
118
+ FMR1 is the one that cannot be right by accident: nothing tells the layout which
119
+ chromosome it is on, and the two males come back with one allele each and the
120
+ mother with two, with the son's allele one of hers.
121
+
122
+ ### Where it is weaker
123
+
124
+ - **The interval is what scans as periodic, not a curated locus definition.**
125
+ Where a locus runs two related units together — HTT's CAG tract and the CCG
126
+ tract after it are both period 3 — they are one array, the count spans both,
127
+ and it will not match a published CAG size.
128
+ - **Reads land off the alleles**, from slippage in the read and in the aligner.
129
+ Read the distribution — `pnpm report:repeats` prints every copy count with its
130
+ support — rather than one row.
131
+ - **Long VNTR alleles are the noisy ones**, and thin: a row is only counted if
132
+ it spans the interval end to end, so an array of a 25bp unit running past 2kb
133
+ is measured on a handful of reads, each of which had to get all of it right.
134
+ Both effects are in the last two columns:
135
+
136
+ <!-- repeat-spread -->
137
+
138
+ | locus | array | spanning reads | on an allele | off one |
139
+ | ---------------- | ------------------ | -------------- | ------------ | ------- |
140
+ | HTT (CAG) | 97bp of 3bp unit | 176 | 148 | 28 |
141
+ | ATXN3 (CTG) | 25bp of 3bp unit | 151 | 118 | 33 |
142
+ | TCF4 CTG18.1 | 113bp of 3bp unit | 169 | 114 | 55 |
143
+ | DMPK (CTG) | 62bp of 3bp unit | 129 | 118 | 11 |
144
+ | FMR1 (CGG), X | 64bp of 3bp unit | 123 | 109 | 14 |
145
+ | C9orf72 (GGGGCC) | 23bp of 6bp unit | 210 | 209 | 1 |
146
+ | ABCA7 VNTR | 485bp of 25bp unit | 27 | 19 | 8 |
147
+
148
+ <!-- /repeat-spread -->
149
+
150
+ The off-allele reads at ABCA7 are the same handful the row before it is measured
151
+ on, which is what "noisy" means at that locus rather than a proportion to
152
+ compare with the STRs above.
153
+
154
+ ### Several samples at once
155
+
156
+ ![FMR1 CGG in the GIAB trio](img/repeat-fmr1-trio.png)
157
+
158
+ The FMR1 CGG repeat in the GIAB Ashkenazi trio, all three files in one
159
+ alignment. Rows are grouped into a clade per sample by a synthetic tree, which
160
+ turns on react-msaview's collapse and show-only controls for free.
161
+
162
+ The copy numbers are checkable, which is the point of this locus: FMR1 is on the
163
+ X, so the two male samples come back with one allele each (HG002 33, HG003 31)
164
+ and the mother with two (32 and 33) — and the son's single allele is one of his
165
+ mother's, as an X-linked allele has to be.
166
+
167
+ Two things about this figure are settings rather than data, and both are there
168
+ because a column costs the same whether 124 rows use it or one does:
169
+
170
+ - **Columns only one row has a base in are hidden** — the toolbar's "hide
171
+ columns w/ N% gaps", set to whatever percent means "one row" for the number of
172
+ rows there are. That is read error, and it is a fifth of the columns at some
173
+ of these loci; the rows that carry one keep an insertion marker where it was.
174
+ What each figure is made of:
175
+
176
+ <!-- repeat-figures -->
177
+
178
+ | figure | rows | columns | columns one row has | hidden |
179
+ | ---------------------------------- | ---- | ------- | ------------------- | ------ |
180
+ | [fmr1](img/repeat-fmr1-trio.png) | 124 | 222 | 29 | 13% |
181
+ | [htt](img/repeat-htt-trio.png) | 182 | 222 | 25 | 11% |
182
+ | [atxn3](img/repeat-atxn3-trio.png) | 157 | 159 | 15 | 9% |
183
+ | [abca7](img/repeat-abca7-vntr.png) | 16 | 3614 | 1239 | 34% |
184
+
185
+ <!-- /repeat-figures -->
186
+
187
+ - **The window is sized to the alignment**, because a JBrowse view taller than
188
+ its window loses its last rows with nothing on screen to say so — and rows are
189
+ ordered longest allele first, so what falls off the bottom is a whole sample.
190
+ `pnpm figures:repeats` now grows the window to the content and warns when it
191
+ cannot.
24
192
 
25
193
  ## Usage
26
194
 
27
195
  - Install the plugin
28
196
  - Open the track menu (vertical `...`) on an alignments track
29
197
  - Click "Launch tview for visible region"
198
+ - Tick any other open alignments track to fold its reads into the same alignment
30
199
 
31
200
  The launched view stays connected to the genome view it came from: hovering or
32
201
  clicking an alignment column highlights the corresponding genome position, and
@@ -36,6 +205,46 @@ switches between centering and zooming.
36
205
  The visible region is capped at 20kb, since one column per base gets unwieldy
37
206
  beyond that.
38
207
 
208
+ ### As a session, with no click path
209
+
210
+ A tview is a locus, an assembly and the files to read it from, so it can be
211
+ declared rather than driven. In a `defaultSession` or a saved session that is
212
+ the view's `init` block:
213
+
214
+ ```json
215
+ {
216
+ "type": "TView",
217
+ "init": {
218
+ "assembly": "hg19",
219
+ "loc": "chrX:146,993,530..146,993,670",
220
+ "tracks": [
221
+ { "trackId": "HG002", "sample": "HG002_son" },
222
+ { "trackId": "HG003", "sample": "HG003_father" }
223
+ ]
224
+ }
225
+ }
226
+ ```
227
+
228
+ A [session spec](https://jbrowse.org/jb2/docs/urlparams/) URL takes the same
229
+ keys **flat** — that is the one shape difference, and it is JBrowse's, not this
230
+ plugin's:
231
+
232
+ ```json
233
+ {
234
+ "type": "TView",
235
+ "assembly": "hg19",
236
+ "loc": "chrX:146,993,530..146,993,670",
237
+ "tracks": ["HG002"]
238
+ }
239
+ ```
240
+
241
+ Either way the view resolves it itself, which is also how a restored session
242
+ gets its alignment back: react-msaview drops an MSA over 50kb from snapshots and
243
+ there is no file to reload from, so `init` is what persists.
244
+
245
+ `public/repeats.json` is a working example — the GIAB trio on hosted hg19, with
246
+ a tview at FMR1 open on load.
247
+
39
248
  ## Requirements
40
249
 
41
250
  Needs a JBrowse build shipping `@jbrowse/core` >=4.3 with MUI 9 — currently
@@ -47,13 +256,22 @@ internals that the 4.3.0 release does not ship.
47
256
 
48
257
  ```bash
49
258
  pnpm install
50
- pnpm start # dev server on :9000, serves dist/out.js with CORS
51
- pnpm test # unit tests
52
- pnpm test:e2e # puppeteer tests (creates .test-jbrowse nightly on first run)
259
+ pnpm start # dev server on :9000, serves dist/out.js with CORS
260
+ pnpm test # unit tests
261
+ pnpm test:e2e # puppeteer tests (creates .test-jbrowse on first run)
53
262
  pnpm lint
54
263
  pnpm build
264
+
265
+ pnpm figures:repeats # the tandem-repeat figures in img/
266
+ pnpm qc:repeats # copy numbers at known loci, from live GIAB data
55
267
  ```
56
268
 
269
+ `qc:repeats` is not a test. It fetches from GIAB and UCSC and prints what the
270
+ plan builder measured at each locus, per sample, so the numbers can be read
271
+ against what the locus is known to carry — Mendelian consistency across the
272
+ trio, hemizygosity on the X, published allele ranges. The loci and samples live
273
+ in `test/liveRepeatsData.ts`.
274
+
57
275
  `pnpm start` serves the repo root, so a JBrowse instance unpacked at
58
276
  `.test-jbrowse` can load the plugin from the same origin via
59
277
  `http://localhost:9000/.test-jbrowse/index.html?config=../public/config.json`.
@@ -0,0 +1,132 @@
1
+ import { RpcMethodType } from '@jbrowse/core/pluggableElementTypes';
2
+ import type { Region } from '@jbrowse/core/util';
3
+ /** one BAM/CRAM to draw rows from, and the name its rows are grouped under */
4
+ export interface TviewSourceArgs {
5
+ adapterConfig: Record<string, unknown>;
6
+ sample?: string;
7
+ /**
8
+ * what this file calls the region's sequence. Filled in on the client, where
9
+ * the assembly's aliases live: two files over one assembly routinely spell it
10
+ * `4` and `chr4`, and a mismatched name fetches nothing and reports nothing.
11
+ */
12
+ refName?: string;
13
+ }
14
+ export interface TviewGetPlanArgs {
15
+ sessionId: string;
16
+ sources: TviewSourceArgs[];
17
+ /** the assembly's sequence adapter, when it has one */
18
+ sequenceAdapterConfig?: Record<string, unknown>;
19
+ /** the sequence adapter's own spelling of the region */
20
+ sequenceRefName?: string;
21
+ region: Region;
22
+ /** stop before rendering an alignment bigger than this many cells */
23
+ maxCells: number;
24
+ }
25
+ /** what crosses back: the alignment, and the numbers the dialog reports */
26
+ export interface TviewArrayReport {
27
+ start: number;
28
+ end: number;
29
+ period: number;
30
+ unit: string;
31
+ width: number;
32
+ /** per row: copies carried, and allele length in bp */
33
+ copies: [string, number][];
34
+ lengths: [string, number][];
35
+ }
36
+ export interface TviewPlanResult {
37
+ msa: string;
38
+ /** Newick grouping rows by sample; absent unless several were loaded */
39
+ tree?: string;
40
+ rowCount: number;
41
+ columnCount: number;
42
+ cellCount: number;
43
+ insertionWidths: [number, number][];
44
+ arraySpans: [number, number, number][];
45
+ region: {
46
+ refName: string;
47
+ start: number;
48
+ end: number;
49
+ };
50
+ arrays: TviewArrayReport[];
51
+ subjectIndex?: number;
52
+ referenceName?: string;
53
+ samples: string[];
54
+ /** set when the alignment was over maxCells and `msa` is empty */
55
+ tooLarge?: boolean;
56
+ }
57
+ /**
58
+ * Builds the whole alignment in the worker and sends back the FASTA.
59
+ *
60
+ * The work this moves is not the fetch — `CoreGetFeatures` already ran in a
61
+ * worker — but everything after it. Fetching from the client meant serializing
62
+ * every read's sequence and CIGAR across the boundary and then running the
63
+ * pairwise alignments and the string building on the main thread, where a
64
+ * region carrying a kilobase-scale array froze the UI for as long as it took.
65
+ * What comes back now is the alignment, which is smaller than the reads it was
66
+ * built from and is the only thing the view has a use for.
67
+ *
68
+ * It is also what makes several files one call: their rows are squared up
69
+ * against the same reference interval, so an array's copies are counted once,
70
+ * over rows from all of them.
71
+ */
72
+ export default class TviewGetPlan extends RpcMethodType {
73
+ name: string;
74
+ /**
75
+ * Written against the 4.3.0 base class, which takes a bare
76
+ * `Record<string, unknown>` and has no `renameRegions` helper — that is the
77
+ * oldest host this bundle boots on, and the newer base class accepts the same
78
+ * shape.
79
+ */
80
+ serializeArguments(args: Record<string, unknown>, rpcDriverClassName: string): Promise<Record<string, unknown>>;
81
+ execute(args: TviewGetPlanArgs, rpcDriverClassName: string): Promise<{
82
+ msa: string;
83
+ tooLarge: boolean;
84
+ rowCount: number;
85
+ columnCount: number;
86
+ cellCount: number;
87
+ insertionWidths: [number, number][];
88
+ arraySpans: [number, number, number][];
89
+ region: {
90
+ refName: string;
91
+ start: number;
92
+ end: number;
93
+ };
94
+ arrays: {
95
+ start: number;
96
+ end: number;
97
+ period: number;
98
+ unit: string;
99
+ width: number;
100
+ copies: [string, number][];
101
+ lengths: [string, number][];
102
+ }[];
103
+ subjectIndex: number | undefined;
104
+ referenceName: string | undefined;
105
+ samples: string[];
106
+ } | {
107
+ msa: string;
108
+ tree: string | undefined;
109
+ rowCount: number;
110
+ columnCount: number;
111
+ cellCount: number;
112
+ insertionWidths: [number, number][];
113
+ arraySpans: [number, number, number][];
114
+ region: {
115
+ refName: string;
116
+ start: number;
117
+ end: number;
118
+ };
119
+ arrays: {
120
+ start: number;
121
+ end: number;
122
+ period: number;
123
+ unit: string;
124
+ width: number;
125
+ copies: [string, number][];
126
+ lengths: [string, number][];
127
+ }[];
128
+ subjectIndex: number | undefined;
129
+ referenceName: string | undefined;
130
+ samples: string[];
131
+ }>;
132
+ }
@@ -0,0 +1,152 @@
1
+ import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache';
2
+ import { RpcMethodType } from '@jbrowse/core/pluggableElementTypes';
3
+ import { renameRegionsIfNeeded } from '@jbrowse/core/util';
4
+ import { buildSampleTree } from '../sampleTree';
5
+ import { planTviewMsa, renderTviewMsa } from '../tview';
6
+ function isFeatureSource(adapter) {
7
+ return 'getFeatures' in adapter && typeof adapter.getFeatures === 'function';
8
+ }
9
+ /**
10
+ * Drains an adapter's feature observable into an array.
11
+ *
12
+ * Hand-rolled rather than `firstValueFrom(...pipe(toArray()))` because rxjs is
13
+ * not a dependency here and `@jbrowse/core/util/rxjs` publishes only
14
+ * `ObservableCreate`. Subscribing directly needs neither.
15
+ */
16
+ async function fetchAll(pluginManager, sessionId, adapterConfig, region) {
17
+ const { dataAdapter } = await getAdapter(pluginManager, sessionId, adapterConfig);
18
+ if (!isFeatureSource(dataAdapter)) {
19
+ throw new Error(`${adapterConfig.type} has no getFeatures`);
20
+ }
21
+ return new Promise((resolve, reject) => {
22
+ const ret = [];
23
+ dataAdapter.getFeatures(region).subscribe({
24
+ next: feature => ret.push(feature),
25
+ error: reject,
26
+ complete: () => {
27
+ resolve(ret);
28
+ },
29
+ });
30
+ });
31
+ }
32
+ /**
33
+ * Builds the whole alignment in the worker and sends back the FASTA.
34
+ *
35
+ * The work this moves is not the fetch — `CoreGetFeatures` already ran in a
36
+ * worker — but everything after it. Fetching from the client meant serializing
37
+ * every read's sequence and CIGAR across the boundary and then running the
38
+ * pairwise alignments and the string building on the main thread, where a
39
+ * region carrying a kilobase-scale array froze the UI for as long as it took.
40
+ * What comes back now is the alignment, which is smaller than the reads it was
41
+ * built from and is the only thing the view has a use for.
42
+ *
43
+ * It is also what makes several files one call: their rows are squared up
44
+ * against the same reference interval, so an array's copies are counted once,
45
+ * over rows from all of them.
46
+ */
47
+ export default class TviewGetPlan extends RpcMethodType {
48
+ constructor() {
49
+ super(...arguments);
50
+ this.name = 'TviewGetPlan';
51
+ }
52
+ /**
53
+ * Written against the 4.3.0 base class, which takes a bare
54
+ * `Record<string, unknown>` and has no `renameRegions` helper — that is the
55
+ * oldest host this bundle boots on, and the newer base class accepts the same
56
+ * shape.
57
+ */
58
+ async serializeArguments(args, rpcDriverClassName) {
59
+ const typed = args;
60
+ const assemblyManager = this.pluginManager.rootModel?.session?.assemblyManager;
61
+ if (!assemblyManager) {
62
+ throw new Error('no assembly manager');
63
+ }
64
+ const refNameFor = async (adapterConfig) => {
65
+ const { regions } = await renameRegionsIfNeeded(assemblyManager, {
66
+ sessionId: typed.sessionId,
67
+ adapterConfig,
68
+ regions: [typed.region],
69
+ });
70
+ return regions[0].refName;
71
+ };
72
+ const sources = await Promise.all(typed.sources.map(async (source) => ({
73
+ ...source,
74
+ refName: await refNameFor(source.adapterConfig),
75
+ })));
76
+ const sequenceRefName = typed.sequenceAdapterConfig
77
+ ? await refNameFor(typed.sequenceAdapterConfig)
78
+ : undefined;
79
+ return super.serializeArguments({ ...args, sources, sequenceRefName }, rpcDriverClassName);
80
+ }
81
+ async execute(args, rpcDriverClassName) {
82
+ const { sessionId, sources, sequenceAdapterConfig, sequenceRefName, region, maxCells, } = await this.deserializeArguments(args, rpcDriverClassName);
83
+ const perSource = await Promise.all(sources.map(source => fetchAll(this.pluginManager, sessionId, source.adapterConfig, {
84
+ ...region,
85
+ refName: source.refName ?? region.refName,
86
+ })));
87
+ const features = [];
88
+ const sampleByIndex = [];
89
+ for (const [i, feats] of perSource.entries()) {
90
+ for (const feature of feats) {
91
+ if (feature.get('seq')) {
92
+ features.push(feature);
93
+ sampleByIndex.push(sources[i].sample);
94
+ }
95
+ }
96
+ }
97
+ let sequence;
98
+ if (sequenceAdapterConfig) {
99
+ const seqFeats = await fetchAll(this.pluginManager, sessionId, sequenceAdapterConfig, { ...region, refName: sequenceRefName ?? region.refName });
100
+ const seq = seqFeats[0]?.get('seq');
101
+ const seqStart = seqFeats[0]?.get('start');
102
+ // the adapter may answer with a wider block than it was asked for
103
+ const sliced = seq !== undefined && seqStart !== undefined
104
+ ? seq.slice(region.start - seqStart, region.end - seqStart)
105
+ : undefined;
106
+ // a short answer means the region runs off the end of the contig, and a
107
+ // reference row that stops early would misplace every column after it
108
+ sequence =
109
+ sliced?.length === region.end - region.start ? sliced : undefined;
110
+ }
111
+ const plan = planTviewMsa({
112
+ features,
113
+ refName: region.refName,
114
+ start: region.start,
115
+ end: region.end,
116
+ sequence,
117
+ sampleOf: i => sampleByIndex[i],
118
+ });
119
+ const shared = {
120
+ rowCount: plan.reads.length,
121
+ columnCount: plan.layout.totalColumns,
122
+ cellCount: plan.cellCount,
123
+ insertionWidths: plan.insertionWidths,
124
+ arraySpans: plan.arraySpans,
125
+ region: plan.region,
126
+ arrays: plan.arrays.map(a => ({
127
+ start: a.start,
128
+ end: a.end,
129
+ period: a.period,
130
+ unit: a.unit,
131
+ width: a.width,
132
+ copies: [...a.copiesByName.entries()],
133
+ lengths: [...a.lengthByName.entries()],
134
+ })),
135
+ subjectIndex: plan.subject
136
+ ? plan.arrays.indexOf(plan.subject)
137
+ : undefined,
138
+ referenceName: plan.referenceName,
139
+ samples: plan.samples,
140
+ };
141
+ // the render is the expensive half and the only part bounded by rows x
142
+ // columns, so the size check happens before it rather than after
143
+ return plan.cellCount > maxCells
144
+ ? { ...shared, msa: '', tooLarge: true }
145
+ : {
146
+ ...shared,
147
+ msa: renderTviewMsa(plan),
148
+ tree: buildSampleTree(plan.reads),
149
+ };
150
+ }
151
+ }
152
+ //# sourceMappingURL=TviewGetPlan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TviewGetPlan.js","sourceRoot":"","sources":["../../../src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAuEvD,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,aAAa,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,UAAU,CAAA;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,QAAQ,CACrB,aAA4B,EAC5B,SAAiB,EACjB,aAAsC,EACtC,MAAc;IAEd,MAAM,E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AAE,IAAI,EAAE;YACxC,CAAC,CAAC;gBACE,GAAG,MAAM;gBACT,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC;aAClC,CAAA;IACP,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import type PluginManager from '@jbrowse/core/PluginManager';
2
+ export default function TviewGetPlanRpcF(pluginManager: PluginManager): void;
3
+ export type { TviewArrayReport, TviewGetPlanArgs, TviewPlanResult, TviewSourceArgs, } from './TviewGetPlan';
@@ -0,0 +1,5 @@
1
+ import TviewGetPlan from './TviewGetPlan';
2
+ export default function TviewGetPlanRpcF(pluginManager) {
3
+ pluginManager.addRpcMethod(() => new TviewGetPlan(pluginManager));
4
+ }
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/LaunchTView/TviewGetPlanRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAIzC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,aAA4B;IACnE,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC,CAAA;AACnE,CAAC"}