@gmod/gfa-tabix 0.0.0-stage → 10.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.
- package/LICENSE +21 -0
- package/README.md +85 -2
- package/esm/abridgedWalks.d.ts +7 -0
- package/esm/abridgedWalks.js +34 -0
- package/esm/formsCheck.d.ts +50 -0
- package/esm/formsCheck.js +251 -0
- package/esm/gfaTabixFile.d.ts +27 -0
- package/esm/gfaTabixFile.js +168 -0
- package/esm/index.d.ts +30 -0
- package/esm/index.js +16 -0
- package/esm/refNames.d.ts +25 -0
- package/esm/refNames.js +65 -0
- package/esm/rgfaBed.d.ts +67 -0
- package/esm/rgfaBed.js +301 -0
- package/esm/structuralForms.d.ts +225 -0
- package/esm/structuralForms.js +813 -0
- package/esm/tabixSource.d.ts +25 -0
- package/esm/tabixSource.js +7 -0
- package/esm/util.d.ts +95 -0
- package/esm/util.js +59 -0
- package/esm/walkChunk.d.ts +246 -0
- package/esm/walkChunk.js +1314 -0
- package/esm/walkContainer.d.ts +54 -0
- package/esm/walkContainer.js +358 -0
- package/esm/walkCounts.d.ts +158 -0
- package/esm/walkCounts.js +580 -0
- package/esm/walkDeparture.d.ts +58 -0
- package/esm/walkDeparture.js +122 -0
- package/esm/walkDepartures.d.ts +80 -0
- package/esm/walkDepartures.js +301 -0
- package/esm/walkFile.d.ts +259 -0
- package/esm/walkFile.js +1534 -0
- package/esm/walkGaps.d.ts +56 -0
- package/esm/walkGaps.js +345 -0
- package/esm/walkRows.d.ts +315 -0
- package/esm/walkRows.js +1607 -0
- package/esm/walkRuns.d.ts +229 -0
- package/esm/walkRuns.js +989 -0
- package/package.json +63 -3
|
@@ -0,0 +1,315 @@
|
|
|
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
|
+
/**
|
|
101
|
+
* Each line's pieces in runs of consecutive piece numbers, in piece order,
|
|
102
|
+
* the lines in the order `pieces` first names them: a WalkRun's rows, and a
|
|
103
|
+
* run of walkRuns.ts's pieces
|
|
104
|
+
*/
|
|
105
|
+
export declare function consecutivePieces<T extends {
|
|
106
|
+
name: string;
|
|
107
|
+
fragStart: number;
|
|
108
|
+
piece: number;
|
|
109
|
+
}>(pieces: T[]): T[][];
|
|
110
|
+
export declare function joinPieces(rows: WalkRow[]): WalkRun[];
|
|
111
|
+
/**
|
|
112
|
+
* One walk's stretch through the cut, from its first step on the drawn
|
|
113
|
+
* stretch of the reference to its last, in consecutive pieces of the tiles
|
|
114
|
+
* over the window and its context. `trimmedBefore` and `trimmedAfter` count
|
|
115
|
+
* the bp of the walk those tiles hold but the cut kept out, before and after
|
|
116
|
+
* it, so they depend on the tiles read.
|
|
117
|
+
*/
|
|
118
|
+
export interface WalkFragment {
|
|
119
|
+
name: string;
|
|
120
|
+
fragStart: number;
|
|
121
|
+
hapStart: number;
|
|
122
|
+
hapEnd: number;
|
|
123
|
+
ids: Int32Array;
|
|
124
|
+
rev: Uint8Array;
|
|
125
|
+
refStarts: Float64Array;
|
|
126
|
+
against: Uint8Array;
|
|
127
|
+
trimmedBefore: number;
|
|
128
|
+
trimmedAfter: number;
|
|
129
|
+
abridged?: Abridged[];
|
|
130
|
+
unloadedSteps?: number;
|
|
131
|
+
}
|
|
132
|
+
export interface WalkCutOptions {
|
|
133
|
+
contained?: boolean;
|
|
134
|
+
context?: number;
|
|
135
|
+
attachBp?: number;
|
|
136
|
+
squeeze?: (bp: number) => number;
|
|
137
|
+
drawn?: {
|
|
138
|
+
start: number;
|
|
139
|
+
end: number;
|
|
140
|
+
};
|
|
141
|
+
attach?: WalkRun[];
|
|
142
|
+
placeholder?: (name: string, start: number, end: number) => number;
|
|
143
|
+
links?: boolean;
|
|
144
|
+
}
|
|
145
|
+
export interface Unattached {
|
|
146
|
+
departure: Readonly<DepartureRecord>;
|
|
147
|
+
}
|
|
148
|
+
export declare const edgeKey: (name: string, pos: number, reversed: boolean, hap: number) => string;
|
|
149
|
+
/**
|
|
150
|
+
* The cut a window draws from its walks: the reference inside the window plus
|
|
151
|
+
* its context, the drawn stretch, and each run from its first step on that
|
|
152
|
+
* stretch to its last. The drawn stretch is the window and its context,
|
|
153
|
+
* widened to the reference nodes over them, whole, and to every pass of a
|
|
154
|
+
* run's step over them. Nothing is followed past the drawn stretch and no fragment runs on
|
|
155
|
+
* through nodes other walks kept, so a haplotype's fragment does not depend on
|
|
156
|
+
* which others are cut.
|
|
157
|
+
*
|
|
158
|
+
* A contained cut splits a run wherever it steps onto the reference off the
|
|
159
|
+
* drawn stretch. Each piece between those steps that steps on the stretch is
|
|
160
|
+
* kept from its first such step to its last, so a detour that comes back is
|
|
161
|
+
* kept whole, and `context` bp of the walk past either end. At AMY1
|
|
162
|
+
* haplotypes go from a 4 kb window to the other copies and back: the cut
|
|
163
|
+
* above keeps 9,928 nodes there, the contained cut 182.
|
|
164
|
+
*
|
|
165
|
+
* Each departure comes back once: those inside one piece are computed from
|
|
166
|
+
* its steps, and kept where their stretch overlaps the drawn stretch; those
|
|
167
|
+
* between pieces, in different tiles or across W lines, are `records`, every
|
|
168
|
+
* one of which comes back, as the reader read them over the window and its
|
|
169
|
+
* context. A computed departure's leave and rejoin passes come from the ref
|
|
170
|
+
* rows the cut read, 0 for a node it places off R. A departure within
|
|
171
|
+
* `attachBp` of own sequence that leaves or rejoins on `drawn`, the base of
|
|
172
|
+
* its leave step or of its rejoin step beside the breakpoint lying there,
|
|
173
|
+
* gets its own steps, a 0 bp step included: a record from the leave and
|
|
174
|
+
* rejoin pieces of `runs` or of `attach`, which give nothing else.
|
|
175
|
+
* `unattached` lists those records lacking either piece, whose tiles the
|
|
176
|
+
* reader fetches into `attach`. Any other departure states its ends and its
|
|
177
|
+
* own bp alone.
|
|
178
|
+
*/
|
|
179
|
+
export declare function walkCut(readRuns: WalkRun[], nodes: Map<number, WalkNode>, refName: string, records: readonly Readonly<DepartureRecord>[], options?: WalkCutOptions): {
|
|
180
|
+
kept: Set<number>;
|
|
181
|
+
fragments: WalkFragment[];
|
|
182
|
+
departures: WalkDeparture[];
|
|
183
|
+
unattached: Unattached[];
|
|
184
|
+
gapsOf: () => WalkGap[];
|
|
185
|
+
links: number[];
|
|
186
|
+
};
|
|
187
|
+
export declare function unattachedRecords(readRuns: WalkRun[], nodes: Map<number, WalkNode>, records: readonly Readonly<DepartureRecord>[], options?: WalkCutOptions): Readonly<DepartureRecord>[];
|
|
188
|
+
/**
|
|
189
|
+
* Adds to `into` the nodes of decoded rows that walkCut keeps whatever else
|
|
190
|
+
* the cut reads: those of `chunk.nodes` on the window, and those a row steps
|
|
191
|
+
* on between two of its steps on the window, `start`-`end` with its context,
|
|
192
|
+
* with no step onto the reference off the window between them in a contained
|
|
193
|
+
* cut. A node placed later at a reference position off the window can split a
|
|
194
|
+
* contained walk, so the count holds for the placements at the time. A
|
|
195
|
+
* placeholder is no node, and is counted in `placeholders` where a row steps
|
|
196
|
+
* on it between two such steps.
|
|
197
|
+
*/
|
|
198
|
+
export declare function surelyKept(chunk: {
|
|
199
|
+
nodes: Map<number, unknown>;
|
|
200
|
+
rows: WalkRow[];
|
|
201
|
+
}, nodes: Map<number, WalkNode>, { contained, start, end }: {
|
|
202
|
+
contained: boolean;
|
|
203
|
+
start: number;
|
|
204
|
+
end: number;
|
|
205
|
+
}, into: Set<number>, placeholders?: Set<number>): void;
|
|
206
|
+
export declare const runName: (name: string, start: number, end: number) => string;
|
|
207
|
+
/**
|
|
208
|
+
* The nodes and links of the chunks a cut reads, and the tables of the cut
|
|
209
|
+
* they make with its walks. A node in two chunks is placed once.
|
|
210
|
+
*/
|
|
211
|
+
export declare class WalkGraph {
|
|
212
|
+
readonly nodes: Map<number, WalkNode>;
|
|
213
|
+
readonly sequences: Map<number, string>;
|
|
214
|
+
private links;
|
|
215
|
+
private readonly window;
|
|
216
|
+
private readonly revisited;
|
|
217
|
+
constructor(window: WalkWindow, revisited?: number);
|
|
218
|
+
placeNode(id: number, node: Omit<WalkNode, 'onWindow'>): void;
|
|
219
|
+
addLinkEnds(source: number, target: number): void;
|
|
220
|
+
addSequences(sequences: Map<number, string>): void;
|
|
221
|
+
/**
|
|
222
|
+
* The cut as typed arrays, which the worker transfers rather than copies:
|
|
223
|
+
* nodes by reference position, each link once in the order its L line
|
|
224
|
+
* sorts, then a walk per fragment, the reference's first and the rest by
|
|
225
|
+
* name, and the departures with their own steps. graphTablesGFA writes
|
|
226
|
+
* them as the GFA they stand for, the same bytes for the same rows.
|
|
227
|
+
*/
|
|
228
|
+
tables(kept: Set<number>, fragments: WalkFragment[], departures: WalkDeparture[], gaps?: WalkGap[]): GraphTables;
|
|
229
|
+
private placeOffReference;
|
|
230
|
+
private referenceFirst;
|
|
231
|
+
}
|
|
232
|
+
export interface BudgetNames {
|
|
233
|
+
steps: string;
|
|
234
|
+
bytes: string;
|
|
235
|
+
}
|
|
236
|
+
export declare const BUDGET_NAMES: BudgetNames;
|
|
237
|
+
export declare const readSteps: (row: Pick<WalkRow, "n" | "interior">) => number;
|
|
238
|
+
/**
|
|
239
|
+
* The zoom-in notice for a cut whose walk rows hold more steps than
|
|
240
|
+
* `readPerKept` times `stepBudget`, or undefined when they fit. A window reads
|
|
241
|
+
* whole tiles, so the span that fits is counted in tiles of `tile` bp from
|
|
242
|
+
* the window's start; when the tiles a window there always reads are over on
|
|
243
|
+
* their own, no zoom fits and the notice asks for fewer
|
|
244
|
+
* haplotypes. A cut for every haplotype is also offered fewer where the
|
|
245
|
+
* reference and one haplotype, at the walks' average steps, would fit the
|
|
246
|
+
* whole window.
|
|
247
|
+
*/
|
|
248
|
+
export declare function stepBudgetError(rows: Pick<WalkRow, 'n' | 'interior' | 'chunkStart' | 'name'>[], stepBudget: number, readPerKept: number, window: {
|
|
249
|
+
start: number;
|
|
250
|
+
end: number;
|
|
251
|
+
}, tile: number, filtered: boolean, names?: BudgetNames): RegionTooLargeError | undefined;
|
|
252
|
+
export declare function countStepsError(rows: Pick<WalkRow, 'n' | 'interior' | 'chunkStart' | 'name'>[], stepBudget: number, readPerKept: number, window: {
|
|
253
|
+
start: number;
|
|
254
|
+
end: number;
|
|
255
|
+
}, tile: number, names?: BudgetNames): RegionTooLargeError | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* The zoom-in notice for a cut that keeps more steps than `budget`, the
|
|
258
|
+
* fragments' and the departures' attached steps together, or undefined when
|
|
259
|
+
* it fits. The span that fits is the window scaled by how far over the cut
|
|
260
|
+
* is. A step built for a piece the cut did not load counts as any other.
|
|
261
|
+
*/
|
|
262
|
+
export declare function keptStepsError(fragments: WalkFragment[], departures: WalkDeparture[], budget: number, window: {
|
|
263
|
+
start: number;
|
|
264
|
+
end: number;
|
|
265
|
+
}, filtered: boolean): RegionTooLargeError | undefined;
|
|
266
|
+
export declare function keptNodesError(nodes: number, limit: number, window: {
|
|
267
|
+
start: number;
|
|
268
|
+
end: number;
|
|
269
|
+
}, filtered: boolean, readTo?: number): RegionTooLargeError | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* keptStepsError's notice given before a cut decodes its tiles, or undefined
|
|
272
|
+
* where the steps it surely keeps of the tiles it counted (tileSteps in
|
|
273
|
+
* walkChunk.ts, `steps` here) fit `budget`. `tiles` are the window's tiles in
|
|
274
|
+
* order, those not counted with no `steps`. The span that fits is worked out
|
|
275
|
+
* tile by tile from the start of the window's `context`: a counted tile holds
|
|
276
|
+
* its steps evenly over its extent, a tile not counted holds the counted
|
|
277
|
+
* tiles' steps per bp, and a stretch no tile covers holds none. Where those
|
|
278
|
+
* steps reach the budget is where the context of the span that fits ends,
|
|
279
|
+
* before the last counted tile ends and so before the window's context does:
|
|
280
|
+
* the span is narrower than the window. A tile's `likely`, no fewer than its
|
|
281
|
+
* `steps`, is what the cut is expected to keep of it where `steps` counts a
|
|
282
|
+
* part: the span is worked out from it, and the refusal from `steps` alone.
|
|
283
|
+
*/
|
|
284
|
+
export declare function surelyKeptError(tiles: {
|
|
285
|
+
start: number;
|
|
286
|
+
end: number;
|
|
287
|
+
steps?: number;
|
|
288
|
+
likely?: number;
|
|
289
|
+
}[], budget: number, window: {
|
|
290
|
+
start: number;
|
|
291
|
+
end: number;
|
|
292
|
+
}, context: number, filtered: boolean): RegionTooLargeError | undefined;
|
|
293
|
+
/**
|
|
294
|
+
* The zoom-in notice for a cut whose walk read would fetch more than
|
|
295
|
+
* `budget` compressed bytes, or undefined when it fits. `bytesTo(end)` is the
|
|
296
|
+
* bytes of the tiles a read from the window's first base to `end` fetches;
|
|
297
|
+
* the span that fits grows a tile at a time from the tile holding the
|
|
298
|
+
* window's start, and when the tiles that reaches are over on their own, no
|
|
299
|
+
* zoom fits. `attaching` marks bytes the tiles fetched for records' own
|
|
300
|
+
* steps take past the budget.
|
|
301
|
+
*/
|
|
302
|
+
export declare function byteBudgetError(bytesTo: (end: number) => number, budget: number, window: {
|
|
303
|
+
start: number;
|
|
304
|
+
end: number;
|
|
305
|
+
}, tile: number, names?: BudgetNames, attaching?: boolean): RegionTooLargeError | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* byteBudgetError's refusal for counts, which draw nothing and choose no
|
|
308
|
+
* haplotypes: what the read would fetch, and a narrower window to count
|
|
309
|
+
* instead where one fits
|
|
310
|
+
*/
|
|
311
|
+
export declare function countBytesError(bytesTo: (end: number) => number, budget: number, window: {
|
|
312
|
+
start: number;
|
|
313
|
+
end: number;
|
|
314
|
+
}, tile: number, names?: BudgetNames, attaching?: boolean): RegionTooLargeError | undefined;
|
|
315
|
+
export declare const megabytes: (bytes: number) => string;
|