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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launchView.js","sourceRoot":"","sources":["../../src/LaunchTView/launchView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AA8B7C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,aAA4B;IAC/D,iFAAiF;IACjF,aAAa,CAAC,mBAAmB,CAC/B,kBAAkB,EAClB,CAAC,IAAqB,EAAE,EAAE;QACxB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;QACjC,MAAM,IAAI,GAA4B,EAAE,CAAA;QACxC,MAAM,SAAS,GAA4B,EAAE,CAAA;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,CAAC;YAAA,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACtD,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;YACvB,IAAI,EAAE,OAAO;YACb,GAAG,SAAS;YACZ,IAAI,EAAE,IAA4B;SACnC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC,CACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,85 @@
1
+ /** the subset of an @jbrowse/core Feature that the layout reads */
2
+ export interface AlignmentFeature {
3
+ get: (key: string) => any;
4
+ }
5
+ /**
6
+ * Only '-' and '.' are treated as gaps by react-msaview (anything else counts
7
+ * as a base in the conservation track and column stats), so the two of them
8
+ * carry the whole vocabulary for "no base here". They are split by meaning:
9
+ *
10
+ * - SPANNED_GAP: the read covers this reference position but aligns no base to
11
+ * it, i.e. a deletion, or padding in an insertion column
12
+ * - ABSENT: the read is not here at all, i.e. outside its bounds, or skipping
13
+ * over the position through an N (an intron, not a deleted allele)
14
+ */
15
+ export declare const SPANNED_GAP = "-";
16
+ export declare const ABSENT = ".";
17
+ export interface ReadLayout {
18
+ /**
19
+ * Identity. Every per-row lookup is keyed by this — the array blocks, the
20
+ * tree — so it is fixed once, here, and nothing downstream rewrites it.
21
+ */
22
+ name: string;
23
+ /**
24
+ * What the row is called on screen, when that is not just its name. Kept
25
+ * apart from `name` because the copy-number label is added after the array
26
+ * blocks are built and keyed: renaming in place instead left every labelled
27
+ * row unable to find its own block, and the block fell back to gaps — a row
28
+ * that silently loses its sequence while keeping its label.
29
+ */
30
+ label?: string;
31
+ /**
32
+ * The sample the row belongs to, when several were loaded at once. Already
33
+ * Newick-safe, and the same string the row's own name is prefixed with, so
34
+ * the clade label and its leaves agree.
35
+ */
36
+ sample?: string;
37
+ start: number;
38
+ /** one char per reference position consumed: the aligned base, or a gap */
39
+ refChars: string;
40
+ /** reference position -> bases inserted immediately before that position */
41
+ insertions: Map<number, string>;
42
+ }
43
+ export declare const byStart: (a: ReadLayout, b: ReadLayout) => number;
44
+ export declare function parseCigar(cigar: string): string[];
45
+ export declare function parseRead(feature: AlignmentFeature, name: string, sample?: string): ReadLayout;
46
+ /**
47
+ * Reads are fetched by overlap, so they carry insertions on either side of the
48
+ * region. Those get no columns and are never rendered, so dropping them keeps
49
+ * the pairwise alignment below off the wasted sites entirely.
50
+ */
51
+ export declare function clipInsertions(reads: ReadLayout[], start: number, end: number): {
52
+ insertions: Map<number, string>;
53
+ /**
54
+ * Identity. Every per-row lookup is keyed by this — the array blocks, the
55
+ * tree — so it is fixed once, here, and nothing downstream rewrites it.
56
+ */
57
+ name: string;
58
+ /**
59
+ * What the row is called on screen, when that is not just its name. Kept
60
+ * apart from `name` because the copy-number label is added after the array
61
+ * blocks are built and keyed: renaming in place instead left every labelled
62
+ * row unable to find its own block, and the block fell back to gaps — a row
63
+ * that silently loses its sequence while keeping its label.
64
+ */
65
+ label?: string;
66
+ /**
67
+ * The sample the row belongs to, when several were loaded at once. Already
68
+ * Newick-safe, and the same string the row's own name is prefixed with, so
69
+ * the clade label and its leaves agree.
70
+ */
71
+ sample?: string;
72
+ start: number;
73
+ /** one char per reference position consumed: the aligned base, or a gap */
74
+ refChars: string;
75
+ }[];
76
+ /**
77
+ * MSA rows are keyed by name, so mates and duplicate names need disambiguating.
78
+ * With several samples loaded at once the same read name can also arrive twice
79
+ * from two files, which the sample prefix separates before the counter has to.
80
+ *
81
+ * The name is made Newick-safe here rather than where the tree is written,
82
+ * because the tree names the same rows the FASTA does and the two have to agree
83
+ * exactly. '|' separates the parts because ':' opens a branch length.
84
+ */
85
+ export declare function getReadNames(features: AlignmentFeature[], sampleOf?: (index: number) => string | undefined): string[];
@@ -0,0 +1,96 @@
1
+ import { newickSafe } from './sampleTree';
2
+ /**
3
+ * Only '-' and '.' are treated as gaps by react-msaview (anything else counts
4
+ * as a base in the conservation track and column stats), so the two of them
5
+ * carry the whole vocabulary for "no base here". They are split by meaning:
6
+ *
7
+ * - SPANNED_GAP: the read covers this reference position but aligns no base to
8
+ * it, i.e. a deletion, or padding in an insertion column
9
+ * - ABSENT: the read is not here at all, i.e. outside its bounds, or skipping
10
+ * over the position through an N (an intron, not a deleted allele)
11
+ */
12
+ export const SPANNED_GAP = '-';
13
+ export const ABSENT = '.';
14
+ const cigarRegex = /([MIDNSHPX=])/;
15
+ export const byStart = (a, b) => a.start - b.start;
16
+ export function parseCigar(cigar) {
17
+ return cigar.split(cigarRegex).slice(0, -1);
18
+ }
19
+ export function parseRead(feature, name, sample) {
20
+ const seq = feature.get('seq');
21
+ const ops = parseCigar(feature.get('CIGAR'));
22
+ const start = feature.get('start');
23
+ const insertions = new Map();
24
+ let refChars = '';
25
+ let seqOffset = 0;
26
+ for (let i = 0; i < ops.length; i += 2) {
27
+ const len = +ops[i];
28
+ const op = ops[i + 1];
29
+ if (op === 'S') {
30
+ seqOffset += len;
31
+ }
32
+ else if (op === 'I') {
33
+ // consecutive I ops (e.g. 3M2I3I3M) land on the same reference position
34
+ const pos = start + refChars.length;
35
+ const prev = insertions.get(pos) ?? '';
36
+ insertions.set(pos, prev + seq.slice(seqOffset, seqOffset + len));
37
+ seqOffset += len;
38
+ }
39
+ else if (op === 'D') {
40
+ refChars += SPANNED_GAP.repeat(len);
41
+ }
42
+ else if (op === 'N') {
43
+ refChars += ABSENT.repeat(len);
44
+ }
45
+ else if (op === 'M' || op === 'X' || op === '=') {
46
+ refChars += seq.slice(seqOffset, seqOffset + len);
47
+ seqOffset += len;
48
+ }
49
+ // H and P consume neither the read sequence nor the reference
50
+ }
51
+ // sanitized here, the same way getReadNames sanitizes the prefix it builds
52
+ // from it, so the clade label and the leaves inside it are one string
53
+ return {
54
+ name,
55
+ sample: sample === undefined ? undefined : newickSafe(sample),
56
+ start,
57
+ refChars,
58
+ insertions,
59
+ };
60
+ }
61
+ /**
62
+ * Reads are fetched by overlap, so they carry insertions on either side of the
63
+ * region. Those get no columns and are never rendered, so dropping them keeps
64
+ * the pairwise alignment below off the wasted sites entirely.
65
+ */
66
+ export function clipInsertions(reads, start, end) {
67
+ return reads.map(read => ({
68
+ ...read,
69
+ insertions: new Map([...read.insertions].filter(([pos]) => pos >= start && pos < end)),
70
+ }));
71
+ }
72
+ function mateSuffix(flags) {
73
+ return flags === undefined || !(flags & 1) ? '' : flags & 64 ? '/1' : '/2';
74
+ }
75
+ /**
76
+ * MSA rows are keyed by name, so mates and duplicate names need disambiguating.
77
+ * With several samples loaded at once the same read name can also arrive twice
78
+ * from two files, which the sample prefix separates before the counter has to.
79
+ *
80
+ * The name is made Newick-safe here rather than where the tree is written,
81
+ * because the tree names the same rows the FASTA does and the two have to agree
82
+ * exactly. '|' separates the parts because ':' opens a branch length.
83
+ */
84
+ export function getReadNames(features, sampleOf) {
85
+ const counts = new Map();
86
+ return features.map((f, i) => {
87
+ const sample = sampleOf?.(i);
88
+ const prefix = sample ? `${newickSafe(sample)}|` : '';
89
+ const name = newickSafe(String(f.get('name')));
90
+ const base = `${prefix}${name}${mateSuffix(f.get('flags'))}`;
91
+ const n = (counts.get(base) ?? 0) + 1;
92
+ counts.set(base, n);
93
+ return n === 1 ? base : `${base}_${n}`;
94
+ });
95
+ }
96
+ //# sourceMappingURL=readLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readLayout.js","sourceRoot":"","sources":["../../src/LaunchTView/readLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAOzC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAA;AAC9B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;AA6BzB,MAAM,UAAU,GAAG,eAAe,CAAA;AAElC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAa,EAAE,CAAa,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;AAE1E,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,OAAyB,EACzB,IAAY,EACZ,MAAe;IAEf,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAW,CAAA;IACxC,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAA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,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QACrD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAC9C,MAAM,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAA;QAC5D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACrC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACnB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { TviewPlan } from './tview';
2
+ export interface Tally {
3
+ value: number;
4
+ reads: number;
5
+ }
6
+ /** Each distinct value with how many rows carried it, smallest value first. */
7
+ export declare function tally(values: number[]): Tally[];
8
+ /**
9
+ * The copy counts a sample carries, as the counts enough of its reads agree on.
10
+ *
11
+ * This is a report of what the reads say, not a genotype call: it does not know
12
+ * a ploidy, so a homozygote and a haploid locus both come back as one number,
13
+ * and a sample whose reads scatter can come back with none.
14
+ */
15
+ export declare function alleleModes(copies: number[]): Tally[];
16
+ export interface SampleArrayStats {
17
+ sample: string;
18
+ /** rows that reached both ends of the interval, i.e. that were measured */
19
+ spanning: number;
20
+ /** copy counts enough of them agreed on */
21
+ modes: Tally[];
22
+ /** every copy count seen, with its support */
23
+ copies: Tally[];
24
+ /** rows whose copy count is not one of the modes */
25
+ offMode: number;
26
+ }
27
+ export interface ArrayStats {
28
+ start: number;
29
+ end: number;
30
+ period: number;
31
+ unit: string;
32
+ /** reference positions the interval covers */
33
+ span: number;
34
+ /** columns the block occupies */
35
+ width: number;
36
+ /** the reference's own copy count, when the reference was a row */
37
+ referenceCopies?: number;
38
+ /** whether the rows were ordered and labelled by this array */
39
+ subject: boolean;
40
+ samples: SampleArrayStats[];
41
+ }
42
+ export interface PlanStats {
43
+ rows: number;
44
+ columns: number;
45
+ /**
46
+ * columns exactly one row has a base in. One read's miscalled indel costs
47
+ * every row a column, so this is the size of what "hide columns w/ N% gaps"
48
+ * takes off a figure — read error, measured rather than estimated.
49
+ */
50
+ singleRowColumns: number;
51
+ /** columns no row has a base in, which no setting is needed to justify */
52
+ emptyColumns: number;
53
+ arrays: ArrayStats[];
54
+ }
55
+ /** Rows, columns, and every array, from a plan the view could equally render. */
56
+ export declare function summarizePlan(plan: TviewPlan, samples?: string[]): PlanStats;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * What a built alignment says about the arrays in it, as numbers rather than as
3
+ * a picture.
4
+ *
5
+ * Everything a report or a README claims about a locus is derived here, from
6
+ * the same plan the view renders, so a number in prose is a number something
7
+ * computed. Nothing in this file fetches or prints — it takes a plan and gives
8
+ * back counts, which is what makes it testable without the network.
9
+ */
10
+ import { ABSENT, SPANNED_GAP } from './readLayout';
11
+ import { renderRow } from './tview';
12
+ /**
13
+ * Least support an allele needs before it is reported as one of a sample's,
14
+ * as a fraction of that sample's spanning reads.
15
+ *
16
+ * Reads scatter around an allele — slippage in the read, slippage in the
17
+ * aligner — so the counts either side of a real allele are populated too, and
18
+ * a rule that took the top two would report the shoulder of one allele as the
19
+ * other. A fraction of coverage rather than a distance in copies is what lets
20
+ * two alleles a single copy apart both be reported, which at FMR1 is the
21
+ * mother's genotype and at ATXN3 the father's.
22
+ */
23
+ const MIN_ALLELE_FRACTION = 0.15;
24
+ /** ...and never on one read, at any coverage. */
25
+ const MIN_ALLELE_READS = 2;
26
+ /** Each distinct value with how many rows carried it, smallest value first. */
27
+ export function tally(values) {
28
+ const counts = new Map();
29
+ for (const v of values) {
30
+ counts.set(v, (counts.get(v) ?? 0) + 1);
31
+ }
32
+ return [...counts]
33
+ .map(([value, reads]) => ({ value, reads }))
34
+ .sort((a, b) => a.value - b.value);
35
+ }
36
+ /**
37
+ * The copy counts a sample carries, as the counts enough of its reads agree on.
38
+ *
39
+ * This is a report of what the reads say, not a genotype call: it does not know
40
+ * a ploidy, so a homozygote and a haploid locus both come back as one number,
41
+ * and a sample whose reads scatter can come back with none.
42
+ */
43
+ export function alleleModes(copies) {
44
+ const floor = Math.max(MIN_ALLELE_READS, MIN_ALLELE_FRACTION * copies.length);
45
+ return tally(copies).filter(t => t.reads >= floor);
46
+ }
47
+ function sampleOfRow(name) {
48
+ const i = name.indexOf('|');
49
+ return i < 0 ? undefined : name.slice(0, i);
50
+ }
51
+ function arrayStats(array, plan, samples) {
52
+ return {
53
+ start: array.start,
54
+ end: array.end,
55
+ period: array.period,
56
+ unit: array.unit,
57
+ span: array.end - array.start,
58
+ width: array.width,
59
+ referenceCopies: plan.referenceName
60
+ ? array.copiesByName.get(plan.referenceName)
61
+ : undefined,
62
+ subject: array === plan.subject,
63
+ samples: samples.map(sample => {
64
+ const copies = [...array.copiesByName]
65
+ .filter(([name]) => sampleOfRow(name) === sample)
66
+ .map(([, n]) => n);
67
+ const modes = alleleModes(copies);
68
+ const called = new Set(modes.map(m => m.value));
69
+ return {
70
+ sample,
71
+ spanning: copies.length,
72
+ modes,
73
+ copies: tally(copies),
74
+ offMode: copies.filter(c => !called.has(c)).length,
75
+ };
76
+ }),
77
+ };
78
+ }
79
+ /** Rows, columns, and every array, from a plan the view could equally render. */
80
+ export function summarizePlan(plan, samples) {
81
+ const rows = plan.reads.map(read => renderRow(read, plan.layout));
82
+ const perColumn = new Int32Array(plan.layout.totalColumns);
83
+ for (const row of rows) {
84
+ for (let col = 0; col < row.length; col++) {
85
+ const char = row[col];
86
+ if (char !== ABSENT && char !== SPANNED_GAP) {
87
+ perColumn[col] = perColumn[col] + 1;
88
+ }
89
+ }
90
+ }
91
+ let singleRowColumns = 0;
92
+ let emptyColumns = 0;
93
+ for (const count of perColumn) {
94
+ if (count === 0) {
95
+ emptyColumns++;
96
+ }
97
+ else if (count === 1) {
98
+ singleRowColumns++;
99
+ }
100
+ }
101
+ return {
102
+ rows: plan.reads.length,
103
+ columns: plan.layout.totalColumns,
104
+ singleRowColumns,
105
+ emptyColumns,
106
+ arrays: plan.arrays.map(array => arrayStats(array, plan, samples ?? plan.samples)),
107
+ };
108
+ }
109
+ //# sourceMappingURL=repeatStats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repeatStats.js","sourceRoot":"","sources":["../../src/LaunchTView/repeatStats.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAKnC;;;;;;;;;;GAUG;AACH,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAO1B,+EAA+E;AAC/E,MAAM,UAAU,KAAK,CAAC,MAAgB;IACpC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IACxC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;SAC3C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAA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G,CAAE,GAAG,CAAC,CAAA;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,gBAAgB,GAAG,CAAC,CAAA;IACxB,IAAI,YAAY,GAAG,CAAC,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;QAC9B,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,YAAY,EAAE,CAAA;QAChB,CAAC;aAAM,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACvB,gBAAgB,EAAE,CAAA;QACpB,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;QACvB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;QACjC,gBAAgB;QAChB,YAAY;QACZ,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAC9B,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CACjD;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,68 @@
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
+ export declare const MIN_PERIOD = 2;
27
+ export declare const MAX_PERIOD = 300;
28
+ export declare const MIN_COPIES = 3;
29
+ export interface ReferenceArray {
30
+ /** reference position the array starts at, inclusive */
31
+ start: number;
32
+ /** reference position the array ends at, exclusive */
33
+ end: number;
34
+ /** repeat unit length in bp */
35
+ period: number;
36
+ /** the reference's own first copy, used as the alignment consensus */
37
+ unit: string;
38
+ }
39
+ /**
40
+ * Tandem arrays in `seq`, which is the reference over the viewed region
41
+ * starting at `offset`.
42
+ *
43
+ * Scanning periods upward and refusing to start an array inside one already
44
+ * found is what reports a 3bp array as 3bp rather than as 6bp or 9bp: every
45
+ * multiple of a real period scores just as well, and the smallest one is the
46
+ * unit. It also means a long array with a short unit hides a spurious long-unit
47
+ * one inside it, which is the failure mode of scanning periods independently.
48
+ */
49
+ export declare function findReferenceArrays(seq: string, offset?: number): ReferenceArray[];
50
+ /**
51
+ * Merge arrays that touch or overlap into one interval, named by the shortest
52
+ * period that describes most of it.
53
+ *
54
+ * An allele is measured over an interval, so two intervals sharing reference
55
+ * positions would measure the same read bases twice. Overlaps are the norm
56
+ * rather than an edge case, because one locus is genuinely periodic at more
57
+ * than one lag: the ABCA7 VNTR's copies are 25 and 26 bases long, so it scans
58
+ * as a 25mer array, a 26mer array and — over the stretch where the two
59
+ * alternate — a 77mer one, all describing the same 466 bases. Taking the
60
+ * shortest period among the rivals reports it as the 25bp unit it is known by,
61
+ * rather than as a 77bp unit that is three copies wearing one name.
62
+ */
63
+ export declare function mergeArrays(arrays: ReferenceArray[], gap?: number): {
64
+ start: number;
65
+ end: number;
66
+ period: number;
67
+ unit: string;
68
+ }[];
@@ -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,CAAC,CAAC,CAAA;AAEvB,gFAAgF;AAChF,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAA;AAE3B,2EAA2E;AAC3E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAE7B,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAA;AAE3B,0EAA0E;AAC1E,8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