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
@@ -5,16 +5,113 @@
5
5
  * shared event stops being readable. Aligning the inserted sequences against
6
6
  * each other fixes that.
7
7
  *
8
- * This is deliberately local to one reference position: the insertion still
9
- * occupies "as many columns as the widest gapped sequence", which is the only
10
- * thing buildColumnToRefPos knows about, so the column <-> reference mapping is
11
- * untouched.
8
+ * There are two ways to do it, and which one applies is a property of the
9
+ * inserted sequence rather than a setting:
10
+ *
11
+ * - **Aperiodic** (`alignInsertions`): one center-star alignment over the whole
12
+ * inserted sequence. Right for a novel insertion, a mobile element, anything
13
+ * whose bases only make sense read straight through.
14
+ * - **Periodic** (`alignPeriodicInsertions`): a tandem array, where the whole
15
+ * inserted sequence is n copies of one unit. Aligning those base-to-base is
16
+ * both unaffordable and wrong — it is free to align copy 5 of one read to
17
+ * copy 3 of another, and the difference that matters (how many copies) ends
18
+ * up expressed as where the row stops. Aligning unit-to-unit instead puts
19
+ * copy k of every read in the same columns, so copy number reads as a count
20
+ * of blocks and a divergent copy stands out as a column inside its block.
21
+ *
22
+ * Both are local to one reference position: the insertion still occupies "as
23
+ * many columns as the widest gapped sequence", which is the only thing
24
+ * buildColumnToRefPos knows about, so the column <-> reference mapping is
25
+ * untouched either way.
26
+ */
27
+ /**
28
+ * The smallest lag at which a sequence repeats, or undefined when it does not.
29
+ *
30
+ * Scanning up from 1 returns the true minimal period, which is what separates a
31
+ * tandem array from a homopolymer: `AAAA...` matches at every lag and comes back
32
+ * as 1, and a 30bp unit comes back as 30 rather than as 60 or 90.
33
+ */
34
+ export declare function detectPeriod(seq: string): number | undefined;
35
+ /**
36
+ * Majority base at each offset within the unit, over the whole-length copies of
37
+ * `seq`. The consensus is what every copy of every read is aligned to, so it has
38
+ * to be one fixed string for the site — deriving it per read would let two reads
39
+ * disagree about where a unit starts.
40
+ */
41
+ export declare function consensusUnit(seq: string, period: number): string;
42
+ /**
43
+ * How much of `seq` is explained by `unit` repeated end to end: the fraction of
44
+ * `seq`'s bases that align to a matching base of the tiling.
45
+ *
46
+ * Free at both ends of the tiling, since an inserted run of copies can start
47
+ * and stop mid-copy, and global on `seq`, since the question is about all of it.
48
+ * That is what separates "more copies of this array" from "something else that
49
+ * landed next to it" without asking the sequence to be in phase with the unit:
50
+ * measured against the trio, the repeat alleles the aligner anchored just
51
+ * outside an array score 0.94-1.00 and unrelated sequence of the same length
52
+ * scores 0.67 or below.
53
+ */
54
+ export declare function unitIdentity(seq: string, unit: string): number;
55
+ export interface PeriodicAlignment {
56
+ /** repeat unit length in bp */
57
+ period: number;
58
+ /** each distinct input mapped to a gapped version, all the same length */
59
+ gapped: Map<string, string>;
60
+ /** each distinct input mapped to its copy count */
61
+ copies: Map<string, number>;
62
+ /** columns each copy occupies, left to right; sums to the gapped length */
63
+ unitWidths: number[];
64
+ }
65
+ /**
66
+ * Unit-per-block alignment of the sequences inserted at one reference position.
67
+ *
68
+ * Copy k of every sequence lands in the same block of columns, and a block is
69
+ * as wide as the widest version of that copy across the site, so a sequence with
70
+ * fewer copies runs out of blocks rather than drifting out of register. Returns
71
+ * undefined when the site is not a tandem array, or is too big to lay out this
72
+ * way; the caller falls back to `alignInsertions`.
73
+ *
74
+ * **Blocks are array order, not homology.** Copies are anchored at the left edge
75
+ * of the insertion and counted rightward, so block k is "the kth copy along",
76
+ * and arrays grow and shrink by unequal crossing over anywhere inside them —
77
+ * block 9 of a 12-copy allele and block 9 of a 20-copy allele need not be the
78
+ * same copy. What the layout does buy is that copies stay in register, so a
79
+ * single divergent copy shows up as a column instead of shifting every copy
80
+ * after it. Reading down one row is sound; reading across two is a hypothesis.
81
+ */
82
+ export declare function alignPeriodicInsertions(seqs: string[]): PeriodicAlignment | undefined;
83
+ /**
84
+ * Unit-per-block alignment against a unit the caller already knows.
85
+ *
86
+ * Separated from `alignPeriodicInsertions` because where the unit comes from is
87
+ * the whole difference between the two ways of finding an array. Measured off
88
+ * the inserted sequences, it can only be derived from one of them — the longest,
89
+ * which is a guess that one chimeric read overturns for the whole site. Measured
90
+ * off the reference, it is a property of the locus, so every read is laid out
91
+ * against the same unit whatever the reads happen to be.
92
+ */
93
+ export declare function alignToUnit(seqs: string[], consensus: string): PeriodicAlignment | undefined;
94
+ export interface InsertionAlignment {
95
+ /** each distinct input mapped to a gapped version, all of the same length */
96
+ gapped: Map<string, string>;
97
+ /** present when the site is a tandem array */
98
+ periodic?: PeriodicAlignment;
99
+ }
100
+ /**
101
+ * Lay out the sequences inserted at one reference position, by whichever of the
102
+ * two alignments the sequence itself calls for. The single place that decision
103
+ * is made, so a caller reading the period cannot disagree with the layout it
104
+ * gets.
105
+ *
106
+ * A tandem array goes unit-per-block, which is both the readable answer and the
107
+ * affordable one — the size caps here are what the base-to-base alignment costs,
108
+ * and an expansion is always past them. Everything else gets the center-star
109
+ * alignment, or is left alone (`gapped` empty) when there is nothing to gain
110
+ * from a single distinct sequence, or the site is too large to be worth it.
12
111
  */
112
+ export declare function alignInsertionSite(seqs: string[]): InsertionAlignment;
13
113
  /**
14
- * Center-star multiple alignment of the sequences inserted at one reference
15
- * position. Returns each distinct input mapped to a gapped version, all of the
16
- * same length. Returns an empty map when there is nothing to gain (a single
17
- * distinct sequence) or when the site is too large to be worth aligning; the
18
- * caller then keeps the sequences as-is and left-justifies them.
114
+ * The gapped sequences alone, for callers with no use for the period. Every
115
+ * decision lives in `alignInsertionSite`.
19
116
  */
20
117
  export declare function alignInsertions(seqs: string[]): Map<string, string>;
@@ -5,10 +5,24 @@
5
5
  * shared event stops being readable. Aligning the inserted sequences against
6
6
  * each other fixes that.
7
7
  *
8
- * This is deliberately local to one reference position: the insertion still
9
- * occupies "as many columns as the widest gapped sequence", which is the only
10
- * thing buildColumnToRefPos knows about, so the column <-> reference mapping is
11
- * untouched.
8
+ * There are two ways to do it, and which one applies is a property of the
9
+ * inserted sequence rather than a setting:
10
+ *
11
+ * - **Aperiodic** (`alignInsertions`): one center-star alignment over the whole
12
+ * inserted sequence. Right for a novel insertion, a mobile element, anything
13
+ * whose bases only make sense read straight through.
14
+ * - **Periodic** (`alignPeriodicInsertions`): a tandem array, where the whole
15
+ * inserted sequence is n copies of one unit. Aligning those base-to-base is
16
+ * both unaffordable and wrong — it is free to align copy 5 of one read to
17
+ * copy 3 of another, and the difference that matters (how many copies) ends
18
+ * up expressed as where the row stops. Aligning unit-to-unit instead puts
19
+ * copy k of every read in the same columns, so copy number reads as a count
20
+ * of blocks and a divergent copy stands out as a column inside its block.
21
+ *
22
+ * Both are local to one reference position: the insertion still occupies "as
23
+ * many columns as the widest gapped sequence", which is the only thing
24
+ * buildColumnToRefPos knows about, so the column <-> reference mapping is
25
+ * untouched either way.
12
26
  */
13
27
  const MATCH = 2;
14
28
  const MISMATCH = -2;
@@ -17,6 +31,30 @@ const GAP = -3;
17
31
  // back to left-justified layout rather than stall on a pathological site
18
32
  const MAX_LEN = 200;
19
33
  const MAX_DISTINCT = 30;
34
+ // Shortest unit that earns a unit-per-block layout. The scan below starts at 1
35
+ // so it reports the TRUE minimal period, which is what makes a homopolymer come
36
+ // back as 1 and get declined here: `AAAA...` is periodic at every lag, and
37
+ // laying it out as 2bp blocks would be an arbitrary reading of one run of A.
38
+ const MIN_UNIT_PERIOD = 2;
39
+ // Longest unit the scan looks for. Covers STRs and the common VNTR range; the
40
+ // megabase-unit arrays (LPA KIV-2 at 5.5kb) need more copies than a read holds
41
+ // before they are periodic at all, so they are out of reach here regardless.
42
+ const MAX_PERIOD = 300;
43
+ // Copies needed before a sequence counts as an array. Two copies of anything is
44
+ // a duplication, not a tandem repeat, and at two the period is unidentifiable
45
+ // from the sequence alone.
46
+ const MIN_COPIES = 3;
47
+ // Fraction of positions that must agree at lag p for p to be the period. Loose
48
+ // enough for the ~5-15% divergence between copies of a real VNTR unit and for
49
+ // long-read error on top of it.
50
+ const PERIODIC_MATCH = 0.8;
51
+ // The period scan is O(len * maxPeriod), so it runs on a prefix rather than the
52
+ // whole insert. An array that is periodic in its first 3kb is periodic.
53
+ const PROBE_LEN = 3000;
54
+ // Backstops on the unit-level work, in the same spirit as MAX_LEN/MAX_DISTINCT:
55
+ // decline and leave the site to the aperiodic path rather than stall on it.
56
+ const MAX_UNITS = 1000;
57
+ const MAX_PERIODIC_CELLS = 20_000_000;
20
58
  function subst(a, b) {
21
59
  return a === b ? MATCH : MISMATCH;
22
60
  }
@@ -91,19 +129,303 @@ function emit({ slots, atCenter }, slotWidths) {
91
129
  return ret + last + '-'.repeat(slotWidths[atCenter.length] - last.length);
92
130
  }
93
131
  /**
94
- * Center-star multiple alignment of the sequences inserted at one reference
95
- * position. Returns each distinct input mapped to a gapped version, all of the
96
- * same length. Returns an empty map when there is nothing to gain (a single
97
- * distinct sequence) or when the site is too large to be worth aligning; the
98
- * caller then keeps the sequences as-is and left-justifies them.
132
+ * The smallest lag at which a sequence repeats, or undefined when it does not.
133
+ *
134
+ * Scanning up from 1 returns the true minimal period, which is what separates a
135
+ * tandem array from a homopolymer: `AAAA...` matches at every lag and comes back
136
+ * as 1, and a 30bp unit comes back as 30 rather than as 60 or 90.
99
137
  */
100
- export function alignInsertions(seqs) {
138
+ export function detectPeriod(seq) {
139
+ const probe = seq.length > PROBE_LEN ? seq.slice(0, PROBE_LEN) : seq;
140
+ const maxPeriod = Math.min(MAX_PERIOD, Math.floor(probe.length / MIN_COPIES));
141
+ for (let p = 1; p <= maxPeriod; p++) {
142
+ const n = probe.length - p;
143
+ let matches = 0;
144
+ for (let i = 0; i < n; i++) {
145
+ if (probe[i] === probe[i + p]) {
146
+ matches++;
147
+ }
148
+ }
149
+ if (matches / n >= PERIODIC_MATCH) {
150
+ return p;
151
+ }
152
+ }
153
+ return undefined;
154
+ }
155
+ /**
156
+ * Majority base at each offset within the unit, over the whole-length copies of
157
+ * `seq`. The consensus is what every copy of every read is aligned to, so it has
158
+ * to be one fixed string for the site — deriving it per read would let two reads
159
+ * disagree about where a unit starts.
160
+ */
161
+ export function consensusUnit(seq, period) {
162
+ const copies = Math.floor(seq.length / period);
163
+ let ret = '';
164
+ for (let j = 0; j < period; j++) {
165
+ const counts = new Map();
166
+ for (let k = 0; k < copies; k++) {
167
+ const c = seq[k * period + j];
168
+ counts.set(c, (counts.get(c) ?? 0) + 1);
169
+ }
170
+ // ties break lexicographically so the consensus is a function of the input
171
+ // and not of Map iteration order
172
+ ret += [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))[0][0];
173
+ }
174
+ return ret;
175
+ }
176
+ /**
177
+ * Align one copy of the consensus unit against `seq` starting at `from`: global
178
+ * on the consensus, since a copy is a whole copy, and free at the window's right
179
+ * edge, since the copy ends wherever it ends. `consumed` is where the next copy
180
+ * starts, which is what lets an indel inside one copy stay inside it rather than
181
+ * shifting every copy after it.
182
+ */
183
+ function alignUnitAt(consensus, seq, from) {
184
+ const n = consensus.length;
185
+ const m = Math.min(2 * n, seq.length - from);
186
+ const stride = m + 1;
187
+ const score = new Int32Array((n + 1) * stride);
188
+ for (let i = 1; i <= n; i++) {
189
+ score[i * stride] = i * GAP;
190
+ }
191
+ for (let j = 1; j <= m; j++) {
192
+ score[j] = j * GAP;
193
+ }
194
+ for (let i = 1; i <= n; i++) {
195
+ for (let j = 1; j <= m; j++) {
196
+ score[i * stride + j] = Math.max(score[(i - 1) * stride + j - 1] +
197
+ subst(consensus[i - 1], seq[from + j - 1]), score[(i - 1) * stride + j] + GAP, score[i * stride + j - 1] + GAP);
198
+ }
199
+ }
200
+ // the copy ends at whichever window position scores best once the consensus
201
+ // is spent
202
+ let consumed = 0;
203
+ let best = score[n * stride];
204
+ for (let j = 1; j <= m; j++) {
205
+ const s = score[n * stride + j];
206
+ if (s > best) {
207
+ best = s;
208
+ consumed = j;
209
+ }
210
+ }
211
+ // a copy that consumed nothing would not advance the cursor
212
+ if (consumed === 0) {
213
+ return undefined;
214
+ }
215
+ const outCenter = [];
216
+ const outOther = [];
217
+ let i = n;
218
+ let j = consumed;
219
+ while (i > 0 || j > 0) {
220
+ const cur = score[i * stride + j];
221
+ const diagonal = i > 0 &&
222
+ j > 0 &&
223
+ cur ===
224
+ score[(i - 1) * stride + j - 1] +
225
+ subst(consensus[i - 1], seq[from + j - 1]);
226
+ if (diagonal) {
227
+ outCenter.push(consensus[i - 1]);
228
+ outOther.push(seq[from + j - 1]);
229
+ i--;
230
+ j--;
231
+ }
232
+ else if (i > 0 && cur === score[(i - 1) * stride + j] + GAP) {
233
+ outCenter.push(consensus[i - 1]);
234
+ outOther.push('-');
235
+ i--;
236
+ }
237
+ else {
238
+ outCenter.push('-');
239
+ outOther.push(seq[from + j - 1]);
240
+ j--;
241
+ }
242
+ }
243
+ return {
244
+ center: outCenter.reverse().join(''),
245
+ other: outOther.reverse().join(''),
246
+ consumed,
247
+ };
248
+ }
249
+ /** Every copy in `seq`, each as a pairwise alignment against the consensus. */
250
+ function splitIntoUnits(seq, consensus) {
251
+ const units = [];
252
+ let cursor = 0;
253
+ while (cursor < seq.length) {
254
+ const unit = alignUnitAt(consensus, seq, cursor);
255
+ if (!unit || units.length >= MAX_UNITS) {
256
+ return undefined;
257
+ }
258
+ units.push(unit);
259
+ cursor += unit.consumed;
260
+ }
261
+ return units;
262
+ }
263
+ // The tiled alignment below is O(len * len), so it scores a prefix rather than
264
+ // the whole insert. A sequence that is copies of the unit for its first 300
265
+ // bases is copies of the unit.
266
+ const IDENTITY_PROBE_LEN = 300;
267
+ /**
268
+ * How much of `seq` is explained by `unit` repeated end to end: the fraction of
269
+ * `seq`'s bases that align to a matching base of the tiling.
270
+ *
271
+ * Free at both ends of the tiling, since an inserted run of copies can start
272
+ * and stop mid-copy, and global on `seq`, since the question is about all of it.
273
+ * That is what separates "more copies of this array" from "something else that
274
+ * landed next to it" without asking the sequence to be in phase with the unit:
275
+ * measured against the trio, the repeat alleles the aligner anchored just
276
+ * outside an array score 0.94-1.00 and unrelated sequence of the same length
277
+ * scores 0.67 or below.
278
+ */
279
+ export function unitIdentity(seq, unit) {
280
+ const probe = seq.length > IDENTITY_PROBE_LEN ? seq.slice(0, IDENTITY_PROBE_LEN) : seq;
281
+ const n = probe.length;
282
+ if (!n || !unit.length) {
283
+ return 0;
284
+ }
285
+ // two spare copies so the alignment can start mid-copy and still run off the
286
+ // end without paying for it
287
+ const tile = unit.repeat(Math.ceil(n / unit.length) + 2);
288
+ const m = tile.length;
289
+ const stride = m + 1;
290
+ const score = new Int32Array((n + 1) * stride);
291
+ const matches = new Int32Array((n + 1) * stride);
292
+ // row 0 stays zero: starting anywhere in the tiling is free
293
+ for (let i = 1; i <= n; i++) {
294
+ score[i * stride] = i * GAP;
295
+ }
296
+ for (let i = 1; i <= n; i++) {
297
+ for (let j = 1; j <= m; j++) {
298
+ const hit = probe[i - 1] === tile[j - 1];
299
+ const diagonal = score[(i - 1) * stride + j - 1] + (hit ? MATCH : MISMATCH);
300
+ const up = score[(i - 1) * stride + j] + GAP;
301
+ const left = score[i * stride + j - 1] + GAP;
302
+ const best = Math.max(diagonal, up, left);
303
+ score[i * stride + j] = best;
304
+ matches[i * stride + j] =
305
+ best === diagonal
306
+ ? matches[(i - 1) * stride + j - 1] + (hit ? 1 : 0)
307
+ : best === up
308
+ ? matches[(i - 1) * stride + j]
309
+ : matches[i * stride + j - 1];
310
+ }
311
+ }
312
+ let best = score[n * stride];
313
+ let bestMatches = matches[n * stride];
314
+ for (let j = 1; j <= m; j++) {
315
+ if (score[n * stride + j] > best) {
316
+ best = score[n * stride + j];
317
+ bestMatches = matches[n * stride + j];
318
+ }
319
+ }
320
+ return bestMatches / n;
321
+ }
322
+ /**
323
+ * Unit-per-block alignment of the sequences inserted at one reference position.
324
+ *
325
+ * Copy k of every sequence lands in the same block of columns, and a block is
326
+ * as wide as the widest version of that copy across the site, so a sequence with
327
+ * fewer copies runs out of blocks rather than drifting out of register. Returns
328
+ * undefined when the site is not a tandem array, or is too big to lay out this
329
+ * way; the caller falls back to `alignInsertions`.
330
+ *
331
+ * **Blocks are array order, not homology.** Copies are anchored at the left edge
332
+ * of the insertion and counted rightward, so block k is "the kth copy along",
333
+ * and arrays grow and shrink by unequal crossing over anywhere inside them —
334
+ * block 9 of a 12-copy allele and block 9 of a 20-copy allele need not be the
335
+ * same copy. What the layout does buy is that copies stay in register, so a
336
+ * single divergent copy shows up as a column instead of shifting every copy
337
+ * after it. Reading down one row is sound; reading across two is a hypothesis.
338
+ */
339
+ export function alignPeriodicInsertions(seqs) {
340
+ const distinct = [...new Set(seqs)];
341
+ const longest = distinct.reduce((a, b) => (b.length > a.length ? b : a), '');
342
+ const period = detectPeriod(longest);
343
+ if (period === undefined || period < MIN_UNIT_PERIOD) {
344
+ return undefined;
345
+ }
346
+ return alignToUnit(distinct, consensusUnit(longest, period));
347
+ }
348
+ /**
349
+ * Unit-per-block alignment against a unit the caller already knows.
350
+ *
351
+ * Separated from `alignPeriodicInsertions` because where the unit comes from is
352
+ * the whole difference between the two ways of finding an array. Measured off
353
+ * the inserted sequences, it can only be derived from one of them — the longest,
354
+ * which is a guess that one chimeric read overturns for the whole site. Measured
355
+ * off the reference, it is a property of the locus, so every read is laid out
356
+ * against the same unit whatever the reads happen to be.
357
+ */
358
+ export function alignToUnit(seqs, consensus) {
359
+ const distinct = [...new Set(seqs)].filter(s => s.length > 0);
360
+ const period = consensus.length;
361
+ if (!distinct.length || period < MIN_UNIT_PERIOD) {
362
+ return undefined;
363
+ }
364
+ const totalUnits = distinct.reduce((a, s) => a + Math.ceil(s.length / period), 0);
365
+ if (totalUnits * (period + 1) * (2 * period + 1) > MAX_PERIODIC_CELLS) {
366
+ return undefined;
367
+ }
368
+ const splits = new Map();
369
+ for (const seq of distinct) {
370
+ const units = splitIntoUnits(seq, consensus);
371
+ if (!units) {
372
+ return undefined;
373
+ }
374
+ splits.set(seq, units.map(u => splitAgainstCenter(u, period)));
375
+ }
376
+ const maxUnits = Math.max(...[...splits.values()].map(u => u.length));
377
+ const slotWidths = [];
378
+ for (let k = 0; k < maxUnits; k++) {
379
+ const widths = Array.from({ length: period + 1 }, () => 0);
380
+ for (const unitSplits of splits.values()) {
381
+ const split = unitSplits[k];
382
+ if (split) {
383
+ for (let j = 0; j <= period; j++) {
384
+ widths[j] = Math.max(widths[j], split.slots[j].length);
385
+ }
386
+ }
387
+ }
388
+ slotWidths.push(widths);
389
+ }
390
+ const unitWidths = slotWidths.map(w => period + w.reduce((a, b) => a + b, 0));
391
+ const gapped = new Map();
392
+ const copies = new Map();
393
+ for (const [seq, unitSplits] of splits) {
394
+ let row = '';
395
+ for (let k = 0; k < maxUnits; k++) {
396
+ const split = unitSplits[k];
397
+ row += split ? emit(split, slotWidths[k]) : '-'.repeat(unitWidths[k]);
398
+ }
399
+ gapped.set(seq, row);
400
+ copies.set(seq, unitSplits.length);
401
+ }
402
+ return { period, gapped, copies, unitWidths };
403
+ }
404
+ /**
405
+ * Lay out the sequences inserted at one reference position, by whichever of the
406
+ * two alignments the sequence itself calls for. The single place that decision
407
+ * is made, so a caller reading the period cannot disagree with the layout it
408
+ * gets.
409
+ *
410
+ * A tandem array goes unit-per-block, which is both the readable answer and the
411
+ * affordable one — the size caps here are what the base-to-base alignment costs,
412
+ * and an expansion is always past them. Everything else gets the center-star
413
+ * alignment, or is left alone (`gapped` empty) when there is nothing to gain
414
+ * from a single distinct sequence, or the site is too large to be worth it.
415
+ */
416
+ export function alignInsertionSite(seqs) {
101
417
  const distinct = [...new Set(seqs)];
418
+ // an array is worth unrolling even when every read agrees on it: the copies
419
+ // still have to be squared up with each other before they can be counted
420
+ const periodic = alignPeriodicInsertions(distinct);
421
+ if (periodic) {
422
+ return { gapped: periodic.gapped, periodic };
423
+ }
102
424
  const longest = distinct.reduce((a, b) => (b.length > a.length ? b : a), '');
103
425
  if (distinct.length < 2 ||
104
426
  distinct.length > MAX_DISTINCT ||
105
427
  longest.length > MAX_LEN) {
106
- return new Map();
428
+ return { gapped: new Map() };
107
429
  }
108
430
  const centerLen = longest.length;
109
431
  const others = distinct.filter(s => s !== longest);
@@ -113,9 +435,21 @@ export function alignInsertions(seqs) {
113
435
  atCenter: longest,
114
436
  };
115
437
  const slotWidths = Array.from({ length: centerLen + 1 }, (_, j) => splits.reduce((max, s) => Math.max(max, s.slots[j].length), 0));
116
- return new Map([
117
- [longest, emit(centerSplit, slotWidths)],
118
- ...others.map((seq, i) => [seq, emit(splits[i], slotWidths)]),
119
- ]);
438
+ return {
439
+ gapped: new Map([
440
+ [longest, emit(centerSplit, slotWidths)],
441
+ ...others.map((seq, i) => [
442
+ seq,
443
+ emit(splits[i], slotWidths),
444
+ ]),
445
+ ]),
446
+ };
447
+ }
448
+ /**
449
+ * The gapped sequences alone, for callers with no use for the period. Every
450
+ * decision lives in `alignInsertionSite`.
451
+ */
452
+ export function alignInsertions(seqs) {
453
+ return alignInsertionSite(seqs).gapped;
120
454
  }
121
455
  //# sourceMappingURL=align.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"align.js","sourceRoot":"","sources":["../../src/LaunchTView/align.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,KAAK,GAAG,CAAC,CAAA;AACf,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAA;AACnB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAA;AAEd,+EAA+E;AAC/E,yEAAyE;AACzE,MAAM,OAAO,GAAG,GAAG,CAAA;AACnB,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,SAAS,KAAK,CAAC,CAAqB,EAAE,CAAqB;IACzD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAA;AACnC,CAAC;AAED,iEAA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C,CAAC,EAAE,CAAC,EAAE,EAAE,CAChE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAChE,CAAA;IACD,OAAO;QACL,MAAM,EAAE,IAAI,GAAG,CAAC;YACd,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;YACxC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAoB,EAAE,CAAC;gBAC1C,GAAG;gBACH,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,UAAU,CAAC;aAC7B,CAAC;SACH,CAAC;KACH,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAc;IAC5C,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;AACxC,CAAC"}
@@ -0,0 +1,83 @@
1
+ import type { ReadLayout } from './readLayout';
2
+ import type { ReferenceArray } from './repeats';
3
+ /**
4
+ * A tandem array laid out as one block of columns per copy, replacing the
5
+ * reference columns the array covers.
6
+ *
7
+ * The interval comes from the reference and the unit comes with it, so every
8
+ * row is measured over the same span against the same unit. That is what makes
9
+ * the counts comparable: a read's allele is what it has between here and here,
10
+ * whatever the aligner did with the gap, and the reference is just the row whose
11
+ * allele the coordinates are named after.
12
+ */
13
+ export interface ArrayBlock {
14
+ /** reference position the array starts at, inclusive */
15
+ start: number;
16
+ /** reference position the array ends at, exclusive */
17
+ end: number;
18
+ period: number;
19
+ unit: string;
20
+ /** columns the block occupies */
21
+ width: number;
22
+ /** columns each copy occupies, left to right; sums to `width` */
23
+ unitWidths: number[];
24
+ /** gapped block, by row name; only rows whose allele could be measured */
25
+ rowByName: Map<string, string>;
26
+ /** copies carried, by row name */
27
+ copiesByName: Map<string, number>;
28
+ /** allele length in bp, by row name */
29
+ lengthByName: Map<string, number>;
30
+ }
31
+ /**
32
+ * What one row has between two reference positions: its matched bases, plus
33
+ * whatever it inserted inside, minus whatever it deleted.
34
+ *
35
+ * This is the measurement the insertion-anchored reading cannot make. An indel
36
+ * inside an array has no unique placement, so two reads carrying the same allele
37
+ * can disagree about which reference position it is inserted at and by how much;
38
+ * summed over the interval, those choices cancel and both come back the same
39
+ * length. Undefined when the row does not reach both edges — copies cannot be
40
+ * counted from a read that stops inside the array, and guessing from a partial
41
+ * one is how a truncated read reads as a contracted allele.
42
+ */
43
+ export declare function extractAllele(read: ReadLayout, start: number, end: number): string | undefined;
44
+ /** Reference positions an array owns, including the insertion slot at its right edge. */
45
+ export declare function arrayInsertionKeys(array: {
46
+ start: number;
47
+ end: number;
48
+ }): number[];
49
+ /**
50
+ * Widen each array to cover the insertions the aligner anchored just outside it
51
+ * that are made of the array's own unit.
52
+ *
53
+ * An allele is measured over a reference interval, which fixes the "one array
54
+ * reports as several sites" problem for indels the aligner placed *inside* the
55
+ * interval. It does not fix the ones it placed just outside: an aligner is free
56
+ * to anchor an expansion at the base before the array starts, and there the
57
+ * insertion is not part of any allele — it is left to become its own run of
58
+ * insertion columns, and the read it belongs to is measured as if it carried
59
+ * the reference allele. Both halves of that are wrong, and they are not rare:
60
+ * at ATXN3 the aligner anchored 60 of 162 reads' expansions one base outside
61
+ * the array, and at ABCA7 a 1207bp allele 19 bases outside.
62
+ *
63
+ * What is absorbed is decided by the inserted sequence, not by the count of
64
+ * reads carrying it — a single read's expansion is as real as fifty, and the
65
+ * whole point of measuring over an interval is that it does not need a vote.
66
+ * Widening the interval costs every row the few reference bases in between,
67
+ * which they all pay equally, so the counts stay comparable.
68
+ */
69
+ export declare function absorbAdjacentInsertions(reads: ReadLayout[], arrays: ReferenceArray[]): {
70
+ start: number;
71
+ end: number;
72
+ period: number;
73
+ unit: string;
74
+ }[];
75
+ /**
76
+ * Lay every row's allele out unit-per-block, one block per array.
77
+ *
78
+ * Arrays whose alleles are all one length still get a block: squaring the copies
79
+ * up against each other is what turns "this row is 63 bases long" into "this row
80
+ * has 21 copies and the 12th one differs", and that is true whether or not the
81
+ * rows disagree.
82
+ */
83
+ export declare function buildArrayBlocks(reads: ReadLayout[], arrays: ReferenceArray[]): ArrayBlock[];