@gmod/gfa-tabix 0.0.0-stage → 10.0.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.
@@ -0,0 +1,225 @@
1
+ import type { Departure, HaplotypeDepartures } from './walkDepartures.ts';
2
+ /**
3
+ * What a haplotype's change states against R. A `deletion` runs no bp of the
4
+ * haplotype's own where it leaves R's out, an `insertion` leaves none of R's
5
+ * out where it runs its own, and a `replacement` does both, at any size on
6
+ * either side. An `inversion` walks R against it, and a `duplication` walks a
7
+ * stretch of R again.
8
+ */
9
+ export type MarkKind = 'insertion' | 'deletion' | 'replacement' | 'inversion' | 'duplication';
10
+ export interface Mark {
11
+ kind: MarkKind;
12
+ refStart: number;
13
+ refEnd: number;
14
+ refLength: number;
15
+ altLength: number;
16
+ delta: number;
17
+ repeatedBp?: number;
18
+ copied?: [number, number];
19
+ }
20
+ export interface SiteMark extends Mark {
21
+ site: number;
22
+ state: string;
23
+ }
24
+ /**
25
+ * One state of a site: its key, the median net change of its carriers, and
26
+ * the marks of the carrier with that change, the first by name where several
27
+ * have it. `carriers` are the haplotypes
28
+ * whose own marks give the state, before any folding. `0` is R's structure.
29
+ * At a site wider than SUMMED_SITE_BP each change keys on its size and its
30
+ * place, `-20000@1000`: the first span of the common spans it joins, each
31
+ * covering half of every other, or its own span where it is rarer
32
+ * (commonMarks), written as its start, or as `1000-21000` where a place of
33
+ * the same size starts there too. So every carrier's marks pair one-to-one
34
+ * with `marks`, each pair covering half of each other.
35
+ */
36
+ export interface SiteState {
37
+ key: string;
38
+ delta: number;
39
+ marks: SiteMark[];
40
+ carriers: string[];
41
+ }
42
+ /**
43
+ * A mark is common where at least minCarriers haplotypes share it, two marks
44
+ * shared where each covers at least half of the other on R, and overlapping
45
+ * common marks make one site, whose span is theirs. A rarer mark, or a summed
46
+ * change holding one, states itself at every site it overlaps, so one
47
+ * haplotype's long departure leaves the sites it crosses apart; rarer marks
48
+ * that overlap no common site make sites of their own by overlap. `covered`
49
+ * counts the placed haplotypes with a call there: walks spanning the site's
50
+ * part inside the window, so a mark beside a gap in them is no call. An
51
+ * `edge` site is one most haplotypes in the window have no call at, which no
52
+ * form key holds and no form states anything of. A `shared` site is one where
53
+ * every form but `other` is in one state, a call. Every other site is
54
+ * informative.
55
+ */
56
+ export interface Site {
57
+ refStart: number;
58
+ refEnd: number;
59
+ edge: boolean;
60
+ shared: boolean;
61
+ covered: number;
62
+ states: SiteState[];
63
+ }
64
+ /**
65
+ * Haplotypes with one state at every site that is not an edge, each member's
66
+ * own changes agreeing with it there (formContradictions checks this).
67
+ * `states` holds a SiteState key per informative site, `.` (NO_CALL_STATE)
68
+ * where the form's walks do not span it, and `~` (RARER_STATE) for a change
69
+ * too rare to stand alone that agrees with no common state; `key` joins them.
70
+ * `marks` are its states' marks in R order, those of shared sites included,
71
+ * and `net` sums them, counting at each site a piece that two summed sites
72
+ * share. The `other` form, key `*` (OTHER_STATE), holds the haplotypes no
73
+ * common form fits and states nothing of them.
74
+ */
75
+ export interface Form {
76
+ members: string[];
77
+ key: string;
78
+ states: string[];
79
+ marks: SiteMark[];
80
+ net: number;
81
+ }
82
+ export interface FormsOptions {
83
+ floorBp?: number | 'auto';
84
+ joinBp?: number;
85
+ minCarriers?: number;
86
+ window?: {
87
+ start: number;
88
+ end: number;
89
+ };
90
+ exclude?: string[];
91
+ foldRareForms?: boolean;
92
+ }
93
+ /**
94
+ * The forms a window's haplotypes fall into. `informative` indexes the sites
95
+ * where a second state has minCarriers. `placed` counts the haplotypes in a
96
+ * form, and `unplaced` lists those with no call in the window and no form.
97
+ * `rareCarriers` carry a state or a form too rare to stand alone.
98
+ */
99
+ export interface StructuralForms {
100
+ sites: Site[];
101
+ informative: number[];
102
+ forms: Form[];
103
+ placed: number;
104
+ unplaced: string[];
105
+ rareCarriers: string[];
106
+ minCarriers: number;
107
+ floorBp: number;
108
+ }
109
+ export declare const STRUCTURAL_BP = 50;
110
+ export declare const FLOOR_PRESETS: readonly [50, 1000, 10000];
111
+ export declare const REFERENCE_STATE = "0";
112
+ export declare const NO_CALL_STATE = ".";
113
+ export declare const RARER_STATE = "~";
114
+ export declare const OTHER_STATE = "*";
115
+ /**
116
+ * The floor for a window `widthBp` wide: about 10 px at 1,000 px, snapped to a
117
+ * preset, so 50 bp under 25 kb, 1 kb to 300 kb and 10 kb past it
118
+ */
119
+ export declare function autoFloor(widthBp: number): 1000 | 10000 | 50;
120
+ export declare const minCarriersFor: (haplotypes: number) => number;
121
+ export declare function changeKind(refLength: number, altLength: number): "insertion" | "deletion" | "replacement";
122
+ /**
123
+ * A mark's state, its kind and its size change to two significant figures:
124
+ * one repeat unit is one state wherever the walk's boundaries fall (22,201 and
125
+ * 22,204 bp are both `+22000`), and two units another. A deletion keys as `-`
126
+ * and an insertion as `+`, a replacement as `r-` or `r+` and a duplication as
127
+ * `d`. An inversion keys on its span.
128
+ */
129
+ export declare function stateKey(m: Mark): string;
130
+ interface Joined {
131
+ refStart: number;
132
+ refEnd: number;
133
+ delta: number;
134
+ refBp: number;
135
+ ownBp: number;
136
+ invertedBp: number;
137
+ repeatedBp: number;
138
+ copied?: [number, number];
139
+ }
140
+ export declare function joinDepartures(departures: Departure[], joinBp: number): Joined[];
141
+ export declare const SUMMED_SITE_BP = 1000;
142
+ /**
143
+ * A haplotype's marks of at least `floorBp`: its departures nearer than
144
+ * `joinBp` on R joined, and those touching the window kept.
145
+ * structuralForms then sums the plain changes at each site, so these are the
146
+ * marks the sites come from, not each haplotype's state.
147
+ */
148
+ export declare function haplotypeMarks(departures: Departure[], { floorBp, joinBp, window, }: {
149
+ floorBp?: number;
150
+ joinBp?: number;
151
+ window?: FormsOptions['window'];
152
+ }): Mark[];
153
+ /**
154
+ * Two net changes agree where both are under `floorBp`, or they differ by
155
+ * under `floorBp`, under a tenth of the larger, or under the last figure a
156
+ * state key gives a change of `size`
157
+ */
158
+ export declare const agrees: (a: number, b: number, floorBp: number, size?: number) => boolean;
159
+ export declare const largestChange: (marks: Mark[]) => number;
160
+ export declare const statesAgree: (a: Mark[], b: Mark[], floorBp: number) => boolean;
161
+ /**
162
+ * Groups haplotypes by the structural changes their walks make over a
163
+ * window. Each haplotype's own marks make its state at a site, so a change
164
+ * nested in another counts once. A state with fewer than minCarriers folds
165
+ * only into a common state its change agrees with (`agrees`; where the site
166
+ * keys on place, change by change, each pair covering half of each other),
167
+ * and is `~` where none does; a no call stays
168
+ * one. A haplotype whose form has fewer than minCarriers joins the largest
169
+ * common form whose every state fits it, or `other`.
170
+ */
171
+ export declare function structuralForms(input: HaplotypeDepartures[], opts?: FormsOptions): StructuralForms;
172
+ /**
173
+ * A length to three significant figures with its unit attached: "94bp",
174
+ * "6.46kb", "1.2Mb"
175
+ */
176
+ export declare function sizeTag(n: number): string;
177
+ /**
178
+ * A mark as a short token: "del 18.4kb", "ins 22kb", "repl 32.7kb->58.7kb",
179
+ * "dup 94.1kb", "inv 12kb". A deletion gives the bp of R it leaves out, an
180
+ * insertion and a duplication at a point the bp they run, and a replacement,
181
+ * or a duplication that also leaves R out, both, R's first, at any ratio:
182
+ * "repl 2.65kb->1bp", "dup 113kb->207kb". An inversion gives its span
183
+ */
184
+ export declare function markTag(m: Mark | SiteMark): string;
185
+ export declare const changeName: typeof markTag;
186
+ /**
187
+ * How a form differs from R: each mark's markTag, largest first, then
188
+ * "rarer" and "no call" with their site counts, comma-separated:
189
+ * "ins 6.4kb, del 1.7kb", "del 2kb, no call". "ref" where it makes no change,
190
+ * and "other" for the `other` form.
191
+ */
192
+ export declare function describeForm(form: {
193
+ marks: Mark[];
194
+ states: string[];
195
+ key?: string;
196
+ }): string;
197
+ /**
198
+ * The state key `form` has at `site`, an index into `result.sites`: its key
199
+ * there at an informative site, the state every form carries at a shared one,
200
+ * `*` for the `other` form, and undefined at an edge site, which no form key
201
+ * holds
202
+ */
203
+ export declare function formStateAt(result: Pick<StructuralForms, 'sites' | 'informative'>, form: Pick<Form, 'states' | 'marks'> & {
204
+ key?: string;
205
+ }, site: number): string | undefined;
206
+ /**
207
+ * A form for a row label of about 20 characters: its largest change as
208
+ * markTag gives it, then " +N" counting the rest describeForm names, as in
209
+ * "del 18.4kb" or "ins 78kb +1"; "ref" where it makes no change. Every change
210
+ * as large as the largest, as printed, is named, one drawn over R before one
211
+ * at a point: "del 32.7kb, ins 32.7kb". A replacement's size is its larger
212
+ * side. Given the
213
+ * form's result, the tag leaves out the marks every form shares, so a form
214
+ * with no other change is "shared": naming the change there would read as if
215
+ * the other rows lacked it. Where other forms of the result would read the
216
+ * same, it names the changes that tell it from them, each the largest of those
217
+ * that the most of them lack: at C4, "del 32.7kb, del 6.37kb" and "del 32.7kb,
218
+ * repl 6.32kb->32.7kb" where both had read "del 32.7kb +1".
219
+ */
220
+ export declare function formTag(form: {
221
+ marks: (Mark | SiteMark)[];
222
+ states: string[];
223
+ key?: string;
224
+ }, result?: Pick<StructuralForms, 'sites'> & Partial<Pick<StructuralForms, 'forms'>>): string;
225
+ export {};