@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,305 @@
1
+ import { RegionTooLargeError } from './util.ts';
2
+ import type { GraphTables } from './util.ts';
3
+ import type { DepartureRecord, Hole, WalkDeparture } from './walkDeparture.ts';
4
+ import type { WalkGap } from './walkGaps.ts';
5
+ export interface WalkRow {
6
+ name: string;
7
+ fragStart: number;
8
+ hapOffset: number;
9
+ piece: number;
10
+ n: number;
11
+ interior?: number;
12
+ steps: {
13
+ ids: Int32Array;
14
+ rev: Uint8Array;
15
+ refStarts?: Float64Array;
16
+ against?: Uint8Array;
17
+ bp?: Int32Array;
18
+ };
19
+ chunkStart: number;
20
+ span?: [number, number];
21
+ abridged?: Abridged;
22
+ own?: OwnSteps[];
23
+ }
24
+ export interface OwnSteps {
25
+ key: string;
26
+ leave: boolean;
27
+ from: number;
28
+ to: number;
29
+ }
30
+ export interface Abridged {
31
+ steps: number;
32
+ detail: {
33
+ refName: string;
34
+ start: number;
35
+ name: string;
36
+ };
37
+ }
38
+ export declare const isPlaceholder: (id: number) => boolean;
39
+ export interface WalkNode {
40
+ refName: string;
41
+ start: number;
42
+ end: number;
43
+ rank: number;
44
+ passes: number;
45
+ reversed?: boolean;
46
+ onWindow: boolean;
47
+ placeholder?: true;
48
+ }
49
+ export interface WalkWindow {
50
+ refName: string;
51
+ start: number;
52
+ end: number;
53
+ context: number;
54
+ sequences?: boolean;
55
+ }
56
+ export interface WalkHeader {
57
+ format?: number;
58
+ tile?: number;
59
+ references: string[];
60
+ haplotypes: string[];
61
+ holes: Hole[];
62
+ revisited?: number;
63
+ graph?: string;
64
+ leftout?: number;
65
+ }
66
+ /**
67
+ * What a walk file's header states: a `#walks` line with the format and the
68
+ * tile size, `format:i:8\ttile:i:65536`, a `#reference\tGRCh38` line naming
69
+ * the reference sample, a `#haplotype\tHG002#1` line per other haplotype with
70
+ * rows and a `#hole` line per stretch of a reference sequence no line of the
71
+ * reference covers
72
+ */
73
+ export declare function walkHeader(lines: string[]): WalkHeader;
74
+ export declare function walkNameFilter(wanted: string[] | undefined, referenceHaplotype: string | undefined): ((name: string) => boolean) | undefined;
75
+ /**
76
+ * The walks a cut on `refName` decodes: its reference's and those `wanted`
77
+ * names. A pggb P-line names a reference with no haplotype field
78
+ * (`chm13#chr1`), whose walks are its sample's.
79
+ */
80
+ export declare function walksKept(wanted: string[] | undefined, refName: string): ((name: string) => boolean) | undefined;
81
+ export interface WalkRun {
82
+ name: string;
83
+ fragStart: number;
84
+ hapOffset: number;
85
+ firstPiece: number;
86
+ pieceStarts: number[];
87
+ pieceChunks: number[];
88
+ ids: Int32Array;
89
+ rev: Uint8Array;
90
+ refStarts: Float64Array;
91
+ against: Uint8Array;
92
+ bp?: Int32Array;
93
+ unloaded?: {
94
+ from: number;
95
+ to: number;
96
+ piece: Abridged;
97
+ }[];
98
+ own?: OwnSteps[];
99
+ }
100
+ export declare function joinPieces(rows: WalkRow[]): WalkRun[];
101
+ /**
102
+ * One walk's stretch through the cut, from its first step on the drawn
103
+ * stretch of the reference to its last, in consecutive pieces of the tiles
104
+ * over the window and its context. `trimmedBefore` and `trimmedAfter` count
105
+ * the bp of the walk those tiles hold but the cut kept out, before and after
106
+ * it, so they depend on the tiles read.
107
+ */
108
+ export interface WalkFragment {
109
+ name: string;
110
+ fragStart: number;
111
+ hapStart: number;
112
+ hapEnd: number;
113
+ ids: Int32Array;
114
+ rev: Uint8Array;
115
+ refStarts: Float64Array;
116
+ against: Uint8Array;
117
+ trimmedBefore: number;
118
+ trimmedAfter: number;
119
+ abridged?: Abridged[];
120
+ unloadedSteps?: number;
121
+ }
122
+ export interface WalkCutOptions {
123
+ contained?: boolean;
124
+ context?: number;
125
+ attachBp?: number;
126
+ squeeze?: (bp: number) => number;
127
+ drawn?: {
128
+ start: number;
129
+ end: number;
130
+ };
131
+ attach?: WalkRun[];
132
+ placeholder?: (name: string, start: number, end: number) => number;
133
+ links?: boolean;
134
+ }
135
+ export interface Unattached {
136
+ departure: Readonly<DepartureRecord>;
137
+ }
138
+ export declare const edgeKey: (name: string, pos: number, reversed: boolean, hap: number) => string;
139
+ /**
140
+ * The cut a window draws from its walks: the reference inside the window plus
141
+ * its context, the drawn stretch, and each run from its first step on that
142
+ * stretch to its last. The drawn stretch is the window and its context,
143
+ * widened to the reference nodes over them, whole, and to every pass of a
144
+ * run's step over them. Nothing is followed past the drawn stretch and no fragment runs on
145
+ * through nodes other walks kept, so a haplotype's fragment does not depend on
146
+ * which others are cut.
147
+ *
148
+ * A contained cut splits a run wherever it steps onto the reference off the
149
+ * drawn stretch. Each piece between those steps that steps on the stretch is
150
+ * kept from its first such step to its last, so a detour that comes back is
151
+ * kept whole, and `context` bp of the walk past either end. At AMY1
152
+ * haplotypes go from a 4 kb window to the other copies and back: the cut
153
+ * above keeps 9,928 nodes there, the contained cut 182.
154
+ *
155
+ * Each departure comes back once: those inside one piece are computed from
156
+ * its steps, and kept where their stretch overlaps the drawn stretch; those
157
+ * between pieces, in different tiles or across W lines, are `records`, every
158
+ * one of which comes back, as the reader read them over the window and its
159
+ * context. A computed departure's leave and rejoin passes come from the ref
160
+ * rows the cut read, 0 for a node it places off R. A departure within
161
+ * `attachBp` of own sequence that leaves or rejoins on `drawn`, the base of
162
+ * its leave step or of its rejoin step beside the breakpoint lying there,
163
+ * gets its own steps, a 0 bp step included: a record from the leave and
164
+ * rejoin pieces of `runs` or of `attach`, which give nothing else.
165
+ * `unattached` lists those records lacking either piece, whose tiles the
166
+ * reader fetches into `attach`. Any other departure states its ends and its
167
+ * own bp alone.
168
+ */
169
+ export declare function walkCut(readRuns: WalkRun[], nodes: Map<number, WalkNode>, refName: string, records: readonly Readonly<DepartureRecord>[], options?: WalkCutOptions): {
170
+ kept: Set<number>;
171
+ fragments: WalkFragment[];
172
+ departures: WalkDeparture[];
173
+ unattached: Unattached[];
174
+ gapsOf: () => WalkGap[];
175
+ links: number[];
176
+ };
177
+ export declare function unattachedRecords(readRuns: WalkRun[], nodes: Map<number, WalkNode>, records: readonly Readonly<DepartureRecord>[], options?: WalkCutOptions): Readonly<DepartureRecord>[];
178
+ /**
179
+ * Adds to `into` the nodes of decoded rows that walkCut keeps whatever else
180
+ * the cut reads: those of `chunk.nodes` on the window, and those a row steps
181
+ * on between two of its steps on the window, `start`-`end` with its context,
182
+ * with no step onto the reference off the window between them in a contained
183
+ * cut. A node placed later at a reference position off the window can split a
184
+ * contained walk, so the count holds for the placements at the time. A
185
+ * placeholder is no node, and is counted in `placeholders` where a row steps
186
+ * on it between two such steps.
187
+ */
188
+ export declare function surelyKept(chunk: {
189
+ nodes: Map<number, unknown>;
190
+ rows: WalkRow[];
191
+ }, nodes: Map<number, WalkNode>, { contained, start, end }: {
192
+ contained: boolean;
193
+ start: number;
194
+ end: number;
195
+ }, into: Set<number>, placeholders?: Set<number>): void;
196
+ export declare const runName: (name: string, start: number, end: number) => string;
197
+ /**
198
+ * The nodes and links of the chunks a cut reads, and the tables of the cut
199
+ * they make with its walks. A node in two chunks is placed once.
200
+ */
201
+ export declare class WalkGraph {
202
+ readonly nodes: Map<number, WalkNode>;
203
+ readonly sequences: Map<number, string>;
204
+ private links;
205
+ private readonly window;
206
+ private readonly revisited;
207
+ constructor(window: WalkWindow, revisited?: number);
208
+ placeNode(id: number, node: Omit<WalkNode, 'onWindow'>): void;
209
+ addLinkEnds(source: number, target: number): void;
210
+ addSequences(sequences: Map<number, string>): void;
211
+ /**
212
+ * The cut as typed arrays, which the worker transfers rather than copies:
213
+ * nodes by reference position, each link once in the order its L line
214
+ * sorts, then a walk per fragment, the reference's first and the rest by
215
+ * name, and the departures with their own steps. graphTablesGFA writes
216
+ * them as the GFA they stand for, the same bytes for the same rows.
217
+ */
218
+ tables(kept: Set<number>, fragments: WalkFragment[], departures: WalkDeparture[], gaps?: WalkGap[]): GraphTables;
219
+ private placeOffReference;
220
+ private referenceFirst;
221
+ }
222
+ export interface BudgetNames {
223
+ steps: string;
224
+ bytes: string;
225
+ }
226
+ export declare const BUDGET_NAMES: BudgetNames;
227
+ export declare const readSteps: (row: Pick<WalkRow, "n" | "interior">) => number;
228
+ /**
229
+ * The zoom-in notice for a cut whose walk rows hold more steps than
230
+ * `readPerKept` times `stepBudget`, or undefined when they fit. A window reads
231
+ * whole tiles, so the span that fits is counted in tiles of `tile` bp from
232
+ * the window's start; when the tiles a window there always reads are over on
233
+ * their own, no zoom fits and the notice asks for fewer
234
+ * haplotypes. A cut for every haplotype is also offered fewer where the
235
+ * reference and one haplotype, at the walks' average steps, would fit the
236
+ * whole window.
237
+ */
238
+ export declare function stepBudgetError(rows: Pick<WalkRow, 'n' | 'interior' | 'chunkStart' | 'name'>[], stepBudget: number, readPerKept: number, window: {
239
+ start: number;
240
+ end: number;
241
+ }, tile: number, filtered: boolean, names?: BudgetNames): RegionTooLargeError | undefined;
242
+ export declare function countStepsError(rows: Pick<WalkRow, 'n' | 'interior' | 'chunkStart' | 'name'>[], stepBudget: number, readPerKept: number, window: {
243
+ start: number;
244
+ end: number;
245
+ }, tile: number, names?: BudgetNames): RegionTooLargeError | undefined;
246
+ /**
247
+ * The zoom-in notice for a cut that keeps more steps than `budget`, the
248
+ * fragments' and the departures' attached steps together, or undefined when
249
+ * it fits. The span that fits is the window scaled by how far over the cut
250
+ * is. A step built for a piece the cut did not load counts as any other.
251
+ */
252
+ export declare function keptStepsError(fragments: WalkFragment[], departures: WalkDeparture[], budget: number, window: {
253
+ start: number;
254
+ end: number;
255
+ }, filtered: boolean): RegionTooLargeError | undefined;
256
+ export declare function keptNodesError(nodes: number, limit: number, window: {
257
+ start: number;
258
+ end: number;
259
+ }, filtered: boolean, readTo?: number): RegionTooLargeError | undefined;
260
+ /**
261
+ * keptStepsError's notice given before a cut decodes its tiles, or undefined
262
+ * where the steps it surely keeps of the tiles it counted (tileSteps in
263
+ * walkChunk.ts, `steps` here) fit `budget`. `tiles` are the window's tiles in
264
+ * order, those not counted with no `steps`. The span that fits is worked out
265
+ * tile by tile from the start of the window's `context`: a counted tile holds
266
+ * its steps evenly over its extent, a tile not counted holds the counted
267
+ * tiles' steps per bp, and a stretch no tile covers holds none. Where those
268
+ * steps reach the budget is where the context of the span that fits ends,
269
+ * before the last counted tile ends and so before the window's context does:
270
+ * the span is narrower than the window. A tile's `likely`, no fewer than its
271
+ * `steps`, is what the cut is expected to keep of it where `steps` counts a
272
+ * part: the span is worked out from it, and the refusal from `steps` alone.
273
+ */
274
+ export declare function surelyKeptError(tiles: {
275
+ start: number;
276
+ end: number;
277
+ steps?: number;
278
+ likely?: number;
279
+ }[], budget: number, window: {
280
+ start: number;
281
+ end: number;
282
+ }, context: number, filtered: boolean): RegionTooLargeError | undefined;
283
+ /**
284
+ * The zoom-in notice for a cut whose walk read would fetch more than
285
+ * `budget` compressed bytes, or undefined when it fits. `bytesTo(end)` is the
286
+ * bytes of the tiles a read from the window's first base to `end` fetches;
287
+ * the span that fits grows a tile at a time from the tile holding the
288
+ * window's start, and when the tiles that reaches are over on their own, no
289
+ * zoom fits. `attaching` marks bytes the tiles fetched for records' own
290
+ * steps take past the budget.
291
+ */
292
+ export declare function byteBudgetError(bytesTo: (end: number) => number, budget: number, window: {
293
+ start: number;
294
+ end: number;
295
+ }, tile: number, names?: BudgetNames, attaching?: boolean): RegionTooLargeError | undefined;
296
+ /**
297
+ * byteBudgetError's refusal for counts, which draw nothing and choose no
298
+ * haplotypes: what the read would fetch, and a narrower window to count
299
+ * instead where one fits
300
+ */
301
+ export declare function countBytesError(bytesTo: (end: number) => number, budget: number, window: {
302
+ start: number;
303
+ end: number;
304
+ }, tile: number, names?: BudgetNames, attaching?: boolean): RegionTooLargeError | undefined;
305
+ export declare const megabytes: (bytes: number) => string;