@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.
@@ -0,0 +1,259 @@
1
+ import { WalkGraph } from './walkRows.ts';
2
+ import type { PlacedNode } from './walkChunk.ts';
3
+ import type { WalkFilehandle, WalkUnit } from './walkContainer.ts';
4
+ import type { WalkDeparture } from './walkDeparture.ts';
5
+ import type { BudgetNames, WalkHeader } from './walkRows.ts';
6
+ export declare const WALK_CONTEXT = 1000;
7
+ export declare const WALK_BUDGETS: Readonly<{
8
+ stepBudget: 4000000;
9
+ byteBudget: 8000000;
10
+ departureByteBudget: 2000000;
11
+ attachBp: 65536;
12
+ }>;
13
+ export declare const CUT_PRESETS: Readonly<{
14
+ browser: Readonly<{
15
+ context: 1000;
16
+ contained: false;
17
+ attachBp: 65536;
18
+ stepBudget: 4000000;
19
+ byteBudget: 8000000;
20
+ departureByteBudget: 2000000;
21
+ }>;
22
+ figure: Readonly<{
23
+ context: 1000;
24
+ contained: false;
25
+ attachBp: 65536;
26
+ stepBudget: number;
27
+ byteBudget: number;
28
+ departureByteBudget: number;
29
+ }>;
30
+ }>;
31
+ /**
32
+ * A window whose departure read would fetch more than its budget. Zooming in
33
+ * does not lower the read, since a record is filed over its whole stretch,
34
+ * so this is not a RegionTooLargeError and shows no zoom-in notice.
35
+ */
36
+ export declare class DepartureReadError extends Error {
37
+ name: string;
38
+ readonly bytes: number;
39
+ readonly limit: number;
40
+ constructor(bytes: number, limit: number);
41
+ }
42
+ export declare function readInOrder<T, R>(items: T[], limit: number, signal: AbortSignal, read: (item: T) => Promise<R>, use: (item: T, result: R) => void): Promise<void>;
43
+ export declare function touchingRuns<T extends {
44
+ unit: WalkUnit;
45
+ }>(items: T[], maxBytes: number): T[][];
46
+ export interface WalkCutOptions {
47
+ signal?: AbortSignal;
48
+ keep?: (name: string) => boolean;
49
+ stepBudget?: number;
50
+ byteBudget?: number;
51
+ departureByteBudget?: number;
52
+ attachBp?: number;
53
+ context?: number;
54
+ links?: 'walked' | 'between' | 'none';
55
+ sequences?: boolean;
56
+ budgetNames?: BudgetNames;
57
+ nodeLimit?: number;
58
+ placeholderLimit?: number;
59
+ contained?: boolean;
60
+ expand?: string[] | ((name: string) => boolean);
61
+ }
62
+ export type WalkCountOptions = Pick<WalkCutOptions, 'signal' | 'context' | 'contained' | 'attachBp' | 'stepBudget' | 'byteBudget' | 'departureByteBudget' | 'expand' | 'budgetNames'>;
63
+ interface OnReference {
64
+ referenceSample?: string;
65
+ }
66
+ export interface CutForRangeOptions extends WalkCutOptions, OnReference {
67
+ }
68
+ export interface GraphForRangeOptions extends Omit<WalkCutOptions, 'keep'>, OnReference {
69
+ haplotypes?: string[];
70
+ }
71
+ export interface CountsForRangeOptions extends WalkCountOptions, OnReference {
72
+ }
73
+ type WalkRunsOptions = Pick<WalkCutOptions, 'signal' | 'keep' | 'context' | 'contained' | 'attachBp' | 'byteBudget' | 'departureByteBudget' | 'budgetNames'>;
74
+ export interface RunsForRangeOptions extends Omit<WalkRunsOptions, 'keep'>, OnReference {
75
+ haplotypes?: string[];
76
+ }
77
+ export interface BytesForRangeOptions extends OnReference {
78
+ signal?: AbortSignal;
79
+ context?: number;
80
+ attachBp?: number;
81
+ departureByteBudget?: number;
82
+ }
83
+ export interface FormsForRangeOptions extends OnReference {
84
+ stepBudget?: number;
85
+ byteBudget?: number;
86
+ departureByteBudget?: number;
87
+ signal?: AbortSignal;
88
+ }
89
+ export type WalkFileHeader = WalkHeader & {
90
+ tile: number;
91
+ };
92
+ export declare function attachTiles(units: WalkUnit[]): (ownTiles: number[]) => WalkUnit[];
93
+ type OneOf<T> = {
94
+ [K in keyof T]: Pick<T, K> & Partial<Record<Exclude<keyof T, K>, never>>;
95
+ }[keyof T];
96
+ type WalksSource = OneOf<{
97
+ walksUrl: string;
98
+ walksPath: string;
99
+ walksFilehandle: WalkFilehandle;
100
+ }>;
101
+ type IdxSource = OneOf<{
102
+ idxUrl: string;
103
+ idxPath: string;
104
+ idxFilehandle: WalkFilehandle;
105
+ }>;
106
+ type NoIdx = Partial<Record<keyof IdxSource, never>>;
107
+ /**
108
+ * Where the walk file and its directory are: exactly one of `walksUrl`,
109
+ * `walksPath` or `walksFilehandle`, and one of `idxUrl`, `idxPath` or
110
+ * `idxFilehandle`, which may be left out beside a URL or a path: the
111
+ * directory is then `<walks>.idx`, before any query string or fragment of
112
+ * a URL
113
+ */
114
+ export type WalkFileOptions = (Exclude<WalksSource, {
115
+ walksFilehandle: WalkFilehandle;
116
+ }> & (IdxSource | NoIdx)) | (Extract<WalksSource, {
117
+ walksFilehandle: WalkFilehandle;
118
+ }> & IdxSource);
119
+ /**
120
+ * A `gfa-to-tabix --walks` file of walk format 8, `<prefix>.<sample>.walks.gz`
121
+ * and its directory `<prefix>.<sample>.walks.gz.idx`, read a window at a
122
+ * time. At open the directory, the header and the sequence's unit table; for
123
+ * a window, the tiles and departure blocks overlapping the window and its
124
+ * context, in one read wherever their bytes touch, each tile decoded once;
125
+ * the `blocks` unit of each of those tiles that abridges a walk kept and not
126
+ * expanded; the detail records of the pieces of the walks `expand` names
127
+ * that the cut builds; then every tile holding own steps the read lacks of
128
+ * a record within `attachBp` that leaves or rejoins on the window or its
129
+ * context, which give those steps alone, from the tile's rows and the
130
+ * records, with no `blocks` unit read. A record that only jumps over them
131
+ * costs no read past its line. The table gives
132
+ * each read's bytes before it is made; a window whose tiles are past the
133
+ * byte budget reads no row, and one whose attach tiles take it past reads
134
+ * none of them. Only the walks `keep` accepts are decoded. The step budget
135
+ * bounds the steps the cut keeps, and rows of the window holding
136
+ * READ_STEPS_PER_KEPT times as many stop the read.
137
+ *
138
+ * Every range method takes 0-based half-open coordinates and a `refName`
139
+ * that is a contig of the reference sample (`chr6`, on `referenceSample`,
140
+ * the file's first reference by default) or the file's own name for it
141
+ * (`GRCh38#0#chr6`), and throws MissingSequenceError for a sequence the
142
+ * file lacks.
143
+ */
144
+ export declare class WalkFile {
145
+ private readonly container;
146
+ constructor(opts: WalkFileOptions);
147
+ private readonly readHeader;
148
+ private readonly readLookup;
149
+ getHeader(opts?: {
150
+ signal?: AbortSignal;
151
+ }): Promise<{
152
+ tile: number;
153
+ format?: number;
154
+ references: string[];
155
+ haplotypes: string[];
156
+ holes: import("./walkDeparture.ts").Hole[];
157
+ revisited?: number;
158
+ graph?: string;
159
+ leftout?: number;
160
+ }>;
161
+ getReferenceSequences(opts?: {
162
+ signal?: AbortSignal;
163
+ }): Promise<string[]>;
164
+ /**
165
+ * The walk file's sequence for `contig` on `sample`, or for `contig` as
166
+ * the file spells it: `chr6` on `GRCh38` is `GRCh38#0#chr6`. Undefined when
167
+ * the file holds neither.
168
+ */
169
+ getSequenceName(sample: string, contig: string, opts?: {
170
+ signal?: AbortSignal;
171
+ }): Promise<string | undefined>;
172
+ getUnits(refName: string, opts?: {
173
+ signal?: AbortSignal;
174
+ }): Promise<WalkUnit[]>;
175
+ getSequenceLength(refName: string, opts?: {
176
+ signal?: AbortSignal;
177
+ }): Promise<number>;
178
+ private resolve;
179
+ /**
180
+ * The compressed bytes a cut of the range reads when it keeps every walk
181
+ * and expands none: its tiles, their blocks units, its departure blocks,
182
+ * which this reads as the cut does, and the tiles named for their own
183
+ * steps by its records within `attachBp` that leave or rejoin on the
184
+ * window or its context. A cut that keeps fewer walks reads no more, and
185
+ * one that expands walks no more but for their detail units
186
+ */
187
+ getBytesForRange(refName: string, start: number, end: number, opts?: BytesForRangeOptions): Promise<number>;
188
+ private bytesFor;
189
+ getReferenceNodes(refName: string, start: number, end: number, opts?: {
190
+ referenceSample?: string;
191
+ signal?: AbortSignal;
192
+ }): Promise<(PlacedNode & {
193
+ id: number;
194
+ })[]>;
195
+ private referenceNodes;
196
+ /**
197
+ * The cut of the range: its graph, the nodes it keeps, each walk's
198
+ * fragments and departures over it and the gaps between them, and
199
+ * `tables()`, which makes the graph's tables of all of them
200
+ */
201
+ getCutForRange(refName: string, start: number, end: number, opts?: CutForRangeOptions): Promise<{
202
+ refName: string;
203
+ graph: WalkGraph;
204
+ kept: Set<number>;
205
+ fragments: import("./walkRows.ts").WalkFragment[];
206
+ departures: WalkDeparture[];
207
+ readonly gaps: import("./walkGaps.ts").WalkGap[];
208
+ placeholders: number;
209
+ tables: () => import("./util.ts").GraphTables;
210
+ }>;
211
+ private cut;
212
+ /**
213
+ * How many of the file's haplotypes step each node and link over the range,
214
+ * and how often, read as a cut that keeps every walk reads, with the same
215
+ * `context`, `contained`, `attachBp`, budgets and `expand`. It counts each
216
+ * piece the cut builds whole, and each piece holding the own steps of a
217
+ * record the cut attaches, while it decodes the rows, keeping no step and
218
+ * building no graph. Every count states why it may fall short, or that it
219
+ * is exact (docs/counts.md)
220
+ */
221
+ getCountsForRange(refName: string, start: number, end: number, opts?: CountsForRangeOptions): Promise<import("./walkCounts.ts").WalkCounts>;
222
+ private counts;
223
+ /**
224
+ * The graph under the range as tables: the reference sample's sequence
225
+ * over it, with `context` bp either side, and the walks of the haplotypes
226
+ * asked for, every one by default; `refName` names the sequence as the
227
+ * file does, and `sequences` holds the nodes' bases when asked for.
228
+ */
229
+ getGraphForRange(refName: string, start: number, end: number, opts?: GraphForRangeOptions): Promise<{
230
+ tables: import("./util.ts").GraphTables;
231
+ refName: string;
232
+ sample: string;
233
+ sequences: Map<number, string> | undefined;
234
+ }>;
235
+ /**
236
+ * The walks of a cut of the range that expands nothing, with the same
237
+ * `context`, `contained` and `attachBp`, as runs (walkRuns.ts), read from
238
+ * the rows without decoding a step: each walk row's route choices and each
239
+ * abridged piece's blocks row, from the tiles and departure blocks over the
240
+ * window and its context and those tiles' blocks units, with no detail
241
+ * unit and no attach tile. Its walks are the reference's and those of the
242
+ * `haplotypes` asked for, every one by default. It refuses a file whose
243
+ * header does not state revisited:i:0 with a RunsRefusedError, so its
244
+ * `revisited` is always 0, and a window past the byte budgets as a cut
245
+ * does; it never refuses on a step budget, node limit or placeholder
246
+ * limit.
247
+ */
248
+ getRunsForRange(refName: string, start: number, end: number, opts?: RunsForRangeOptions): Promise<import("./walkRuns.ts").WalkRuns>;
249
+ private runs;
250
+ /**
251
+ * Every haplotype's departures over the range, for structuralForms, from
252
+ * one cut without links that expands no walk. A haplotype the header names
253
+ * with no walk in the cut is listed with nothing covered.
254
+ */
255
+ getFormsForRange(refName: string, start: number, end: number, opts?: FormsForRangeOptions): Promise<import("./walkDepartures.ts").HaplotypeDepartures[]>;
256
+ }
257
+ export type CutForRange = Awaited<ReturnType<WalkFile['getCutForRange']>>;
258
+ export type GraphForRange = Awaited<ReturnType<WalkFile['getGraphForRange']>>;
259
+ export {};