jbrowse-plugin-tview 2.0.4 → 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 +56 -40
  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 +59 -21
  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 +7 -3
  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,200 @@
1
+ /**
2
+ * Finding tandem arrays in the *reference*, rather than in what the reads
3
+ * inserted.
4
+ *
5
+ * The insertion-anchored reading — "an array is the sequence some read inserted
6
+ * at one reference position" — is what the aligner happens to produce, not what
7
+ * is there. Measured against the GIAB trio at HTT, ATXN3 and TCF4 it fails in
8
+ * three ways at once:
9
+ *
10
+ * - **The array is already in the reference.** A read's insertion is only its
11
+ * allele's *excess* over the reference copy count, so `n=5` at HTT means five
12
+ * copies more than hg19's, not a five-copy allele. A contracted allele inserts
13
+ * nothing at all and vanishes from the site.
14
+ * - **One array reports as several sites.** An indel inside an array has no
15
+ * unique placement, so the aligner anchors different reads at different
16
+ * positions: ATXN3 in HG002 came back as four separate arrays at 92537353,
17
+ * ...354, ...358 and ...372, splitting one locus's alleles across four counts.
18
+ * - **A read that spans the array without an insertion is invisible**, so the
19
+ * reference-length allele — usually the commonest one — is never counted.
20
+ *
21
+ * Anchoring on a reference interval fixes all three: the interval is the same
22
+ * for every read, so an allele is "what this read has between here and here",
23
+ * however the aligner chose to write it, and the reference is just another
24
+ * allele.
25
+ */
26
+ // scoring for the lag-p self-comparison below. A match fraction of 0.75 scores
27
+ // zero, so a real array (~85% identity between copies, plus read error on the
28
+ // reference's own history) accumulates and random sequence (25%) does not.
29
+ const LAG_MATCH = 1;
30
+ const LAG_MISMATCH = -3;
31
+ // Shortest unit worth reporting. A homopolymer is periodic at every lag and its
32
+ // unit is an arbitrary slice of one run, so period 1 is not a unit.
33
+ export const MIN_PERIOD = 2;
34
+ // Longest unit scanned. Covers STRs and the common VNTR range. The scan is
35
+ // O(regionLength * MAX_PERIOD), which is what bounds this rather than biology.
36
+ export const MAX_PERIOD = 300;
37
+ // Copies needed before a run counts as an array. At two the period cannot be
38
+ // told from the sequence alone, and two copies of anything is a duplication.
39
+ export const MIN_COPIES = 3;
40
+ // Shortest array worth reporting, regardless of copies. Three copies of a
41
+ // dinucleotide is six bases, which occurs by chance every few hundred bases —
42
+ // a TP53 exon scanned as a control turned up two — and firing the whole
43
+ // unit-per-block layout on one would relabel an ordinary pileup.
44
+ const MIN_SPAN = 12;
45
+ /**
46
+ * Runs where `scores` stays positive on balance, each cut back to where it
47
+ * scored best.
48
+ *
49
+ * A run is opened at the first positive score, extended while the running total
50
+ * stays above zero, and closed at its peak — so the mismatching tail that ended
51
+ * it is not part of the array, and neither are the short mismatch stretches
52
+ * inside it that the total absorbed. Restarting after each close is what lets
53
+ * one pass find every array of a given period, which a region routinely carries
54
+ * several of.
55
+ */
56
+ function positiveRuns(scores) {
57
+ const ret = [];
58
+ let start = -1;
59
+ let total = 0;
60
+ let best = 0;
61
+ let bestEnd = -1;
62
+ const close = () => {
63
+ if (bestEnd > start) {
64
+ ret.push({ start, end: bestEnd });
65
+ }
66
+ start = -1;
67
+ total = 0;
68
+ best = 0;
69
+ bestEnd = -1;
70
+ };
71
+ for (let i = 0; i < scores.length; i++) {
72
+ if (start < 0) {
73
+ if (scores[i] <= 0) {
74
+ continue;
75
+ }
76
+ start = i;
77
+ }
78
+ total += scores[i];
79
+ if (total > best) {
80
+ best = total;
81
+ bestEnd = i + 1;
82
+ }
83
+ else if (total <= 0) {
84
+ close();
85
+ }
86
+ }
87
+ close();
88
+ return ret;
89
+ }
90
+ /** Arrays of exactly `period`, as intervals into `seq`. */
91
+ function arraysOfPeriod(seq, period) {
92
+ const n = seq.length - period;
93
+ if (n <= 0) {
94
+ return [];
95
+ }
96
+ const scores = new Int32Array(n);
97
+ for (let i = 0; i < n; i++) {
98
+ scores[i] = seq[i] === seq[i + period] ? LAG_MATCH : LAG_MISMATCH;
99
+ }
100
+ const minSpan = Math.max(MIN_SPAN, MIN_COPIES * period);
101
+ return positiveRuns(scores)
102
+ .map(s => ({
103
+ // a lag-p match at the last scored position still asserts p more bases
104
+ start: s.start,
105
+ end: s.end + period,
106
+ period,
107
+ }))
108
+ .filter(s => s.end - s.start >= minSpan);
109
+ }
110
+ /**
111
+ * Tandem arrays in `seq`, which is the reference over the viewed region
112
+ * starting at `offset`.
113
+ *
114
+ * Scanning periods upward and refusing to start an array inside one already
115
+ * found is what reports a 3bp array as 3bp rather than as 6bp or 9bp: every
116
+ * multiple of a real period scores just as well, and the smallest one is the
117
+ * unit. It also means a long array with a short unit hides a spurious long-unit
118
+ * one inside it, which is the failure mode of scanning periods independently.
119
+ */
120
+ export function findReferenceArrays(seq, offset = 0) {
121
+ const upper = seq.toUpperCase();
122
+ const claimed = new Uint8Array(upper.length);
123
+ const ret = [];
124
+ const maxPeriod = Math.min(MAX_PERIOD, Math.floor(upper.length / MIN_COPIES));
125
+ for (let period = MIN_PERIOD; period <= maxPeriod; period++) {
126
+ for (const span of arraysOfPeriod(upper, period)) {
127
+ let free = 0;
128
+ for (let i = span.start; i < span.end; i++) {
129
+ free += claimed[i] ? 0 : 1;
130
+ }
131
+ // mostly inside an array already reported at a shorter period, so it is
132
+ // that array's higher harmonic rather than an array of its own
133
+ if (free < 0.5 * (span.end - span.start)) {
134
+ continue;
135
+ }
136
+ const unit = upper.slice(span.start, span.start + period);
137
+ // a homopolymer is periodic at every lag, so it turns up here as an
138
+ // array of `AA` or `AAA` whose unit boundary is an arbitrary cut through
139
+ // one run of A. Counting its copies is counting its length in twos.
140
+ if (new Set(unit).size < 2) {
141
+ continue;
142
+ }
143
+ for (let i = span.start; i < span.end; i++) {
144
+ claimed[i] = 1;
145
+ }
146
+ ret.push({
147
+ start: offset + span.start,
148
+ end: offset + span.end,
149
+ period,
150
+ unit,
151
+ });
152
+ }
153
+ }
154
+ return ret.sort((a, b) => a.start - b.start || a.period - b.period);
155
+ }
156
+ /**
157
+ * How much of the merged interval an array has to cover before its period is a
158
+ * candidate to name the whole thing. A dinucleotide abutting a VNTR should not
159
+ * rename it; two descriptions of the same locus should compete.
160
+ */
161
+ const RIVAL_SPAN_FRACTION = 0.5;
162
+ /**
163
+ * Merge arrays that touch or overlap into one interval, named by the shortest
164
+ * period that describes most of it.
165
+ *
166
+ * An allele is measured over an interval, so two intervals sharing reference
167
+ * positions would measure the same read bases twice. Overlaps are the norm
168
+ * rather than an edge case, because one locus is genuinely periodic at more
169
+ * than one lag: the ABCA7 VNTR's copies are 25 and 26 bases long, so it scans
170
+ * as a 25mer array, a 26mer array and — over the stretch where the two
171
+ * alternate — a 77mer one, all describing the same 466 bases. Taking the
172
+ * shortest period among the rivals reports it as the 25bp unit it is known by,
173
+ * rather than as a 77bp unit that is three copies wearing one name.
174
+ */
175
+ export function mergeArrays(arrays, gap = 0) {
176
+ const groups = [];
177
+ for (const array of [...arrays].sort((a, b) => a.start - b.start)) {
178
+ const last = groups.at(-1);
179
+ const end = last ? Math.max(...last.map(a => a.end)) : 0;
180
+ if (last && array.start <= end + gap) {
181
+ last.push(array);
182
+ }
183
+ else {
184
+ groups.push([array]);
185
+ }
186
+ }
187
+ return groups.map(group => {
188
+ const span = (a) => a.end - a.start;
189
+ const widest = Math.max(...group.map(span));
190
+ const rivals = group.filter(a => span(a) >= RIVAL_SPAN_FRACTION * widest);
191
+ const named = rivals.reduce((a, b) => (b.period < a.period ? b : a));
192
+ return {
193
+ start: Math.min(...group.map(a => a.start)),
194
+ end: Math.max(...group.map(a => a.end)),
195
+ period: named.period,
196
+ unit: named.unit,
197
+ };
198
+ });
199
+ }
200
+ //# sourceMappingURL=repeats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repeats.js","sourceRoot":"","sources":["../../src/LaunchTView/repeats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,+EAA+E;AAC/E,8EAA8E;AAC9E,2EAA2E;AAC3E,MAAM,SAAS,GAAG,CAAC,CAAA;AACnB,MAAM,YAAY,GAAG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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,GAAG,CAAC,CAAiB,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAA;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,mBAAmB,GAAG,MAAM,CAAC,CAAA;QACzE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACpE,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC3C,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A Newick tree whose only job is to group rows.
3
+ *
4
+ * With one file the rows are a pileup and their order is the whole structure.
5
+ * With several, the rows of two samples interleave into a list nothing separates
6
+ * — and react-msaview already draws a tree, collapses its clades and can show
7
+ * one branch alone, all of it keyed off a Newick string it is currently never
8
+ * given. Handing it one grouped by sample turns those controls on for free: a
9
+ * clade per sample, collapsible, and the allele ladder inside each.
10
+ *
11
+ * The tree is a grouping, not a phylogeny. Branch lengths are all 1 and say
12
+ * nothing; the topology is the sample the row came from, and the leaf order
13
+ * inside a clade is the copy-number order the rows were already in.
14
+ */
15
+ /**
16
+ * Newick reserves these, and a name is not quoted when it goes in.
17
+ *
18
+ * **Applied where the row name is built, not here.** react-msaview joins a tree
19
+ * leaf to an alignment row by name, so sanitizing on the way into the Newick
20
+ * and leaving the FASTA defline alone matches nothing: every row whose name
21
+ * needed fixing renders blank, with its label still in the tree, which looks
22
+ * like a rendering bug rather than a naming one. A track named `HG004 (mother)`
23
+ * is enough to trigger it.
24
+ */
25
+ export declare function newickSafe(name: string): string;
26
+ export interface TreeRow {
27
+ name: string;
28
+ /** what the defline says, when that is not just the name */
29
+ label?: string;
30
+ sample?: string;
31
+ }
32
+ /**
33
+ * Groups rows by sample, keeping the order they arrive in both for the clades
34
+ * and inside them. Returns undefined when there is nothing to group — one
35
+ * sample, or none — since a tree of one clade is a line drawn beside a list.
36
+ */
37
+ export declare function buildSampleTree(rows: TreeRow[]): string | undefined;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A Newick tree whose only job is to group rows.
3
+ *
4
+ * With one file the rows are a pileup and their order is the whole structure.
5
+ * With several, the rows of two samples interleave into a list nothing separates
6
+ * — and react-msaview already draws a tree, collapses its clades and can show
7
+ * one branch alone, all of it keyed off a Newick string it is currently never
8
+ * given. Handing it one grouped by sample turns those controls on for free: a
9
+ * clade per sample, collapsible, and the allele ladder inside each.
10
+ *
11
+ * The tree is a grouping, not a phylogeny. Branch lengths are all 1 and say
12
+ * nothing; the topology is the sample the row came from, and the leaf order
13
+ * inside a clade is the copy-number order the rows were already in.
14
+ */
15
+ /**
16
+ * Newick reserves these, and a name is not quoted when it goes in.
17
+ *
18
+ * **Applied where the row name is built, not here.** react-msaview joins a tree
19
+ * leaf to an alignment row by name, so sanitizing on the way into the Newick
20
+ * and leaving the FASTA defline alone matches nothing: every row whose name
21
+ * needed fixing renders blank, with its label still in the tree, which looks
22
+ * like a rendering bug rather than a naming one. A track named `HG004 (mother)`
23
+ * is enough to trigger it.
24
+ */
25
+ export function newickSafe(name) {
26
+ return name.replaceAll(/[(),:;[\]'\s]+/g, '_').replace(/_+$/, '');
27
+ }
28
+ /**
29
+ * Groups rows by sample, keeping the order they arrive in both for the clades
30
+ * and inside them. Returns undefined when there is nothing to group — one
31
+ * sample, or none — since a tree of one clade is a line drawn beside a list.
32
+ */
33
+ export function buildSampleTree(rows) {
34
+ const bySample = new Map();
35
+ const ungrouped = [];
36
+ for (const row of rows) {
37
+ // the leaf is the row's *defline*, already Newick-safe from getReadNames.
38
+ // The tree must not rewrite it, and must not use the identity where the
39
+ // defline carries a label — react-msaview joins the two by string, and a
40
+ // leaf naming no row leaves that row blank with its label still drawn
41
+ const leaf = row.label ?? row.name;
42
+ if (row.sample === undefined) {
43
+ ungrouped.push(leaf);
44
+ }
45
+ else {
46
+ const group = bySample.get(row.sample);
47
+ if (group) {
48
+ group.push(leaf);
49
+ }
50
+ else {
51
+ bySample.set(row.sample, [leaf]);
52
+ }
53
+ }
54
+ }
55
+ if (bySample.size < 2) {
56
+ return undefined;
57
+ }
58
+ const clades = [
59
+ // the reference has no sample and belongs above all of them
60
+ ...ungrouped.map(name => `${name}:1`),
61
+ ...[...bySample].map(([sample, names]) => `(${names.map(n => `${n}:1`).join(',')})${sample}:1`),
62
+ ];
63
+ return `(${clades.join(',')});`;
64
+ }
65
+ //# sourceMappingURL=sampleTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampleTree.js","sourceRoot":"","sources":["../../src/LaunchTView/sampleTree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;GASG;AACH,MAAM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C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,IAAI,CAC1E;KACF,CAAA;IACD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAA;AACjC,CAAC"}
@@ -1,44 +1,34 @@
1
- /** the subset of an @jbrowse/core Feature that the layout reads */
2
- export interface AlignmentFeature {
3
- get: (key: string) => any;
4
- }
5
- export interface ReadLayout {
6
- name: string;
7
- start: number;
8
- /** one char per reference position consumed: the aligned base, or a gap */
9
- refChars: string;
10
- /** reference position -> bases inserted immediately before that position */
11
- insertions: Map<number, string>;
12
- }
13
- export declare function parseCigar(cigar: string): string[];
14
- export declare function parseRead(feature: AlignmentFeature, name: string): ReadLayout;
1
+ import type { ArrayBlock } from './alleles';
2
+ import type { AlignmentFeature, ReadLayout } from './readLayout';
3
+ export type { AlignmentFeature, ReadLayout } from './readLayout';
4
+ export { clipInsertions, parseCigar, parseRead } from './readLayout';
15
5
  /**
16
- * Reads are fetched by overlap, so they carry insertions on either side of the
17
- * region. Those get no columns and are never rendered, so dropping them keeps
18
- * the pairwise alignment below off the wasted sites entirely.
6
+ * Mutually aligns the sequences inserted at each reference position, so reads
7
+ * sharing an insertion event line up inside it. Positions an array block has
8
+ * taken over are left alone: those bases are part of an allele the block
9
+ * already laid out, and giving them insertion columns as well would render
10
+ * them twice.
19
11
  */
20
- export declare function clipInsertions(reads: ReadLayout[], start: number, end: number): {
12
+ export declare function alignInsertionColumns(reads: ReadLayout[], ownedByArray: Set<number>): {
21
13
  insertions: Map<number, string>;
22
14
  name: string;
15
+ label?: string;
16
+ sample?: string;
23
17
  start: number;
24
- /** one char per reference position consumed: the aligned base, or a gap */
25
18
  refChars: string;
26
19
  }[];
27
- /**
28
- * Mutually aligns the sequences inserted at each reference position, so reads
29
- * sharing an insertion event line up inside it. Sites the aligner declines are
30
- * returned unchanged and stay left-justified.
31
- */
32
- export declare function alignInsertionColumns(reads: ReadLayout[]): ReadLayout[];
33
20
  /** widest insertion any read has at each reference position (sparse) */
34
- export declare function maxInsertionWidths(reads: ReadLayout[]): Map<number, number>;
21
+ export declare function maxInsertionWidths(reads: ReadLayout[], ownedByArray: Set<number>): Map<number, number>;
35
22
  export interface ColumnLayout {
36
23
  start: number;
37
24
  end: number;
38
25
  insWidths: Map<number, number>;
26
+ arrays: ArrayBlock[];
39
27
  /**
40
28
  * column index at which each reference position's columns begin, for
41
- * start..end inclusive
29
+ * start..end inclusive. Positions inside an array block all begin where the
30
+ * block ends: the block is one run of columns and no position inside it owns
31
+ * any of them.
42
32
  */
43
33
  offsets: number[];
44
34
  totalColumns: number;
@@ -46,19 +36,41 @@ export interface ColumnLayout {
46
36
  /**
47
37
  * Each reference position contributes its insertion columns (widest across all
48
38
  * reads) followed by one reference column, so every row comes out the same
49
- * length and stays aligned.
39
+ * length and stays aligned — except where an array block takes over, and
40
+ * contributes one run of columns for the whole interval it covers.
50
41
  */
51
- export declare function buildColumnLayout(start: number, end: number, insWidths: Map<number, number>): ColumnLayout;
42
+ export declare function buildColumnLayout(start: number, end: number, insWidths: Map<number, number>, arrays?: ArrayBlock[]): ColumnLayout;
52
43
  /**
53
- * Lays a single read out across the whole region. Reads are typically a tiny
54
- * fraction of the region, so the columns on either side of the read are filled
55
- * in one shot rather than walked position by position.
44
+ * Lays a single row out across the whole region. Rows are typically a tiny
45
+ * fraction of the region, so the columns on either side are filled in one shot
46
+ * from the offsets rather than walked position by position — which works over
47
+ * array blocks too, since the offsets already carry their width.
56
48
  */
57
49
  export declare function renderRow(read: ReadLayout, layout: ColumnLayout): string;
50
+ /**
51
+ * What a row is called on screen. The one place `label` falls back to `name`,
52
+ * so the defline and the tree leaf cannot disagree about it — react-msaview
53
+ * joins them by string, and a row the tree names differently renders blank.
54
+ */
55
+ export declare function rowLabel(read: ReadLayout): string;
56
+ /**
57
+ * Rows ordered longest-allele-first and labelled with their copy count.
58
+ *
59
+ * Copy number is the measurement at a tandem array, and reading it off where a
60
+ * row runs out is the thing the unit-per-block layout exists to avoid, so it is
61
+ * stated in the label. Ordering by it puts the alleles in a ladder, which is
62
+ * what makes one row's array comparable to the next at a glance. Rows that do
63
+ * not span the array keep genomic order, below the ones that do; the reference
64
+ * stays on top whatever its allele, since it is what the columns are named
65
+ * after rather than one of the observations.
66
+ */
67
+ export declare function labelAndOrderByCopies(reads: ReadLayout[], array: ArrayBlock, referenceName?: string): ReadLayout[];
58
68
  export interface TviewPlan {
59
69
  reads: ReadLayout[];
60
70
  layout: ColumnLayout;
61
71
  insertionWidths: [number, number][];
72
+ /** [start, end, width] per array block, to rebuild the column mapping */
73
+ arraySpans: [number, number, number][];
62
74
  region: {
63
75
  refName: string;
64
76
  start: number;
@@ -66,30 +78,41 @@ export interface TviewPlan {
66
78
  };
67
79
  /** rows x columns, i.e. how big the alignment renderTviewMsa builds will be */
68
80
  cellCount: number;
81
+ /** tandem arrays the reference carries here, left to right */
82
+ arrays: ArrayBlock[];
83
+ /** the array the rows are ordered and labelled by, when there is one */
84
+ subject?: ArrayBlock;
85
+ /** name of the reference row, when the reference sequence was available */
86
+ referenceName?: string;
87
+ /** samples contributing rows, in the order they were given */
88
+ samples: string[];
89
+ }
90
+ export interface PlanArgs {
91
+ features: AlignmentFeature[];
92
+ refName: string;
93
+ start: number;
94
+ end: number;
95
+ /** reference bases for start..end, when the assembly could supply them */
96
+ sequence?: string;
97
+ /** which sample each feature came from, parallel to `features` */
98
+ sampleOf?: (index: number) => string | undefined;
69
99
  }
70
100
  /**
71
101
  * Works out the shape of the alignment without materializing it. Everything
72
102
  * here is proportional to the sequence data, unlike the render, which is
73
103
  * proportional to rows x columns and can be far larger.
74
104
  */
75
- export declare function planTviewMsa({ features, refName, start, end, }: {
76
- features: AlignmentFeature[];
77
- refName: string;
78
- start: number;
79
- end: number;
80
- }): TviewPlan;
105
+ export declare function planTviewMsa({ features, refName, start, end, sequence, sampleOf, }: PlanArgs): TviewPlan;
81
106
  export declare function renderTviewMsa({ reads, layout }: TviewPlan): string;
82
- export declare function buildTviewMsa(args: {
83
- features: AlignmentFeature[];
84
- refName: string;
85
- start: number;
86
- end: number;
87
- }): {
107
+ export declare function buildTviewMsa(args: PlanArgs): {
88
108
  msa: string;
89
109
  insertionWidths: [number, number][];
110
+ arraySpans: [number, number, number][];
90
111
  region: {
91
112
  refName: string;
92
113
  start: number;
93
114
  end: number;
94
115
  };
116
+ arrays: ArrayBlock[];
117
+ subject: ArrayBlock | undefined;
95
118
  };