@gmod/gfa-tabix 10.0.0 → 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/README.md CHANGED
@@ -49,7 +49,8 @@ range: the reference, each haplotype's walk through it, and the nodes and links
49
49
  they visit, as typed arrays. `refName` is a contig of the reference sample
50
50
  (`chr6`) or the file's full name (`GRCh38#0#chr6`). `getCutForRange`,
51
51
  `getCountsForRange` and `getFormsForRange` give the cut itself, per-node
52
- haplotype counts and structural forms.
52
+ haplotype counts and structural forms. `getRunsForRange` gives a range's walks
53
+ as runs of reference stretches, without decoding a step.
53
54
 
54
55
  ## The GFA tabix file
55
56
 
@@ -72,6 +73,8 @@ const gfa = await gfaTabix.getGraphForRange('GRCh38#0#chr6', 0, 100_000)
72
73
  departures, the GFA tabix file
73
74
  - [Reads, budgets and abridged walks](docs/reads.md): what a cut fetches
74
75
  - [Counts](docs/counts.md): haplotypes per node and link
76
+ - [Runs](docs/runs.md): a range's walks as reference stretches and the bp
77
+ between
75
78
  - [Structural forms](docs/structural-forms.md): grouping haplotypes by change
76
79
  - [Migrating to 10](docs/migrating-to-10.md): from @jbrowse/graph-walks
77
80
  - [Migrating to graph-walks 8](docs/migrating-to-8.md): changes in 7 and 8
package/esm/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CUT_PRESETS, DepartureReadError, WALK_BUDGETS, WALK_CONTEXT, WalkFile, } from './walkFile.ts';
2
- export type { BytesForRangeOptions, CountsForRangeOptions, CutForRange, CutForRangeOptions, FormsForRangeOptions, GraphForRange, GraphForRangeOptions, WalkCountOptions, WalkCutOptions, WalkFileHeader, WalkFileOptions, } from './walkFile.ts';
2
+ export type { BytesForRangeOptions, CountsForRangeOptions, CutForRange, CutForRangeOptions, FormsForRangeOptions, GraphForRange, GraphForRangeOptions, RunsForRangeOptions, WalkCountOptions, WalkCutOptions, WalkFileHeader, WalkFileOptions, } from './walkFile.ts';
3
3
  export { GfaTabixFile } from './gfaTabixFile.ts';
4
4
  export type { GfaTabixFileOptions, GfaTabixRangeOptions, } from './gfaTabixFile.ts';
5
5
  export { WALK_FORMAT, WalkFormatError } from './walkContainer.ts';
@@ -14,6 +14,8 @@ export { ATTACH_BP, departureKind, placementChoice } from './walkDeparture.ts';
14
14
  export type { DepartureKind, WalkDeparture } from './walkDeparture.ts';
15
15
  export { GAP_KINDS } from './walkGaps.ts';
16
16
  export type { GapKind, GapSegment, WalkGap } from './walkGaps.ts';
17
+ export { END_KINDS, RunsRefusedError, fragmentRuns } from './walkRuns.ts';
18
+ export type { EndKind, WalkEnds, WalkRuns } from './walkRuns.ts';
17
19
  export { COUNT_REASONS, countReasons } from './walkCounts.ts';
18
20
  export type { CountColumns, CountReason, WalkCounts } from './walkCounts.ts';
19
21
  export { FORMS_STEP_BUDGET, walkDepartures } from './walkDepartures.ts';
package/esm/index.js CHANGED
@@ -7,6 +7,7 @@ export { RegionTooLargeError, bpString, panSNContig, panSNHaplotype, panSNMatche
7
7
  export { BUDGET_NAMES, isPlaceholder, keptStepsError, walksKept, } from "./walkRows.js";
8
8
  export { ATTACH_BP, departureKind, placementChoice } from "./walkDeparture.js";
9
9
  export { GAP_KINDS } from "./walkGaps.js";
10
+ export { END_KINDS, RunsRefusedError, fragmentRuns } from "./walkRuns.js";
10
11
  export { COUNT_REASONS, countReasons } from "./walkCounts.js";
11
12
  export { FORMS_STEP_BUDGET, walkDepartures } from "./walkDepartures.js";
12
13
  export { FLOOR_PRESETS, NO_CALL_STATE, OTHER_STATE, RARER_STATE, REFERENCE_STATE, STRUCTURAL_BP, changeKind, describeForm, formStateAt, formTag, markTag, sizeTag, stateKey, structuralForms, } from "./structuralForms.js";
@@ -30,6 +30,16 @@ export interface DepartureSource {
30
30
  departures: WalkDeparture[];
31
31
  nodes: Map<number, WalkNode>;
32
32
  }
33
+ export type ChainEvent = {
34
+ kind: 'on';
35
+ lo: number;
36
+ hi: number;
37
+ reversed: boolean;
38
+ } | {
39
+ kind: 'own';
40
+ bp: number;
41
+ loaded?: boolean;
42
+ };
33
43
  /**
34
44
  * Each haplotype's departures from R, `refName`, read off a cut: its
35
45
  * departures, every one over the drawn stretch, give where each path leaves
@@ -46,4 +56,25 @@ export interface DepartureSource {
46
56
  * them. The walks on R's own haplotype are left out.
47
57
  */
48
58
  export declare function walkDepartures({ fragments, departures, nodes }: DepartureSource, refName: string): HaplotypeDepartures[];
59
+ /**
60
+ * A chain's crossings in the forward view: its stretches along R in order,
61
+ * turned round where it reads R back to front, and between each two, from
62
+ * where the one leaves R to where the next takes it, a crossing wherever
63
+ * they do not follow on or the path runs bp between them: those of its own
64
+ * and those of the stretches it takes against its way. `first` and `reach`
65
+ * span R from the first stretch along it to the furthest any reaches.
66
+ */
67
+ export declare function chainCrossings(events: ChainEvent[]): {
68
+ flip: boolean;
69
+ crossings: {
70
+ from: number;
71
+ to: number;
72
+ ownBp: number;
73
+ invertedBp: number;
74
+ loaded: boolean;
75
+ }[];
76
+ first: number;
77
+ reach: number;
78
+ };
79
+ export declare function chainDepartures(events: ChainEvent[]): HaplotypeDepartures;
49
80
  export declare const FORMS_STEP_BUDGET = 16000000;
@@ -195,51 +195,80 @@ function readsBackToFront(events) {
195
195
  : progress < 0;
196
196
  }
197
197
  /**
198
- * A path's departures in the forward view: its stretches along R in order,
199
- * turned round where it reads R back to front, each stretch against it or of
200
- * its own between two along it making one departure.
198
+ * A chain's crossings in the forward view: its stretches along R in order,
199
+ * turned round where it reads R back to front, and between each two, from
200
+ * where the one leaves R to where the next takes it, a crossing wherever
201
+ * they do not follow on or the path runs bp between them: those of its own
202
+ * and those of the stretches it takes against its way. `first` and `reach`
203
+ * span R from the first stretch along it to the furthest any reaches.
201
204
  */
202
- function readPath(events, h) {
205
+ export function chainCrossings(events) {
203
206
  const flip = readsBackToFront(events);
204
- let first = NaN;
205
- let prevEnd = NaN;
207
+ const crossings = [];
208
+ let first = Number.NaN;
209
+ let prevEnd = Number.NaN;
206
210
  let reach = -Infinity;
207
- let alt = 0;
211
+ let own = 0;
208
212
  let inverted = 0;
213
+ let loaded = true;
209
214
  for (const e of flip ? events.toReversed() : events) {
210
215
  if (e.kind === 'own') {
211
- alt += e.bp;
216
+ own += e.bp;
217
+ loaded && (loaded = e.loaded !== false);
212
218
  }
213
219
  else if (e.reversed !== flip) {
214
- alt += e.hi - e.lo;
215
220
  inverted += e.hi - e.lo;
216
221
  }
217
222
  else {
218
- const start = e.lo;
219
223
  if (Number.isNaN(prevEnd)) {
220
- first = start;
224
+ first = e.lo;
221
225
  }
222
- else if (start !== prevEnd || alt > 0) {
223
- const repeated = start < prevEnd ? prevEnd - start : 0;
224
- h.departures.push({
225
- refStart: prevEnd,
226
- refEnd: repeated > 0 ? prevEnd : start,
227
- altLength: alt + repeated,
226
+ else if (e.lo !== prevEnd || own + inverted > 0) {
227
+ crossings.push({
228
+ from: prevEnd,
229
+ to: e.lo,
230
+ ownBp: own,
228
231
  invertedBp: inverted,
229
- repeatedBp: repeated,
230
- ...(repeated > 0 ? { copied: [start, prevEnd] } : {}),
232
+ loaded,
231
233
  });
232
234
  }
233
235
  prevEnd = e.hi;
234
236
  reach = Math.max(reach, e.hi);
235
- alt = 0;
237
+ own = 0;
236
238
  inverted = 0;
239
+ loaded = true;
237
240
  }
238
241
  }
242
+ return { flip, crossings, first, reach };
243
+ }
244
+ /**
245
+ * A path's departures in the forward view: its chain's crossings, each a
246
+ * departure from where it leaves R to where it rejoins, a jump back a point
247
+ * at the junction with the bp walked again as `repeatedBp`.
248
+ */
249
+ function readPath(events, h) {
250
+ const { crossings, first, reach } = chainCrossings(events);
251
+ for (const c of crossings) {
252
+ const repeated = c.to < c.from ? c.from - c.to : 0;
253
+ h.departures.push({
254
+ refStart: c.from,
255
+ refEnd: repeated > 0 ? c.from : c.to,
256
+ altLength: c.ownBp + c.invertedBp + repeated,
257
+ invertedBp: c.invertedBp,
258
+ repeatedBp: repeated,
259
+ ...(repeated > 0 ? { copied: [c.to, c.from] } : {}),
260
+ });
261
+ }
239
262
  if (!Number.isNaN(first)) {
240
263
  h.covered.push([first, reach]);
241
264
  }
242
265
  }
266
+ // One chain's departures and the R it covers, as walkDepartures reads them
267
+ export function chainDepartures(events) {
268
+ const h = { haplotype: '', covered: [], departures: [] };
269
+ readPath(events, h);
270
+ return h;
271
+ }
243
272
  /**
244
273
  * The stretches of R that exactly one of a haplotype's paths covers, each
245
274
  * within one path. Where two paths overlap, such as a second contig over the
package/esm/walkFile.d.ts CHANGED
@@ -70,6 +70,10 @@ export interface GraphForRangeOptions extends Omit<WalkCutOptions, 'keep'>, OnRe
70
70
  }
71
71
  export interface CountsForRangeOptions extends WalkCountOptions, OnReference {
72
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
+ }
73
77
  export interface BytesForRangeOptions extends OnReference {
74
78
  signal?: AbortSignal;
75
79
  context?: number;
@@ -228,6 +232,21 @@ export declare class WalkFile {
228
232
  sample: string;
229
233
  sequences: Map<number, string> | undefined;
230
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;
231
250
  /**
232
251
  * Every haplotype's departures over the range, for structuralForms, from
233
252
  * one cut without links that expands no walk. A haplotype the header names
package/esm/walkFile.js CHANGED
@@ -8,6 +8,7 @@ import { WalkTally } from "./walkCounts.js";
8
8
  import { ATTACH_BP, attachesOwnSteps, departureOwnTiles, parseDepartureRow, squeezer, } from "./walkDeparture.js";
9
9
  import { FORMS_STEP_BUDGET, walkDepartures } from "./walkDepartures.js";
10
10
  import { WalkGraph, byteBudgetError, countBytesError, countStepsError, edgeKey, isPlaceholder, joinPieces, keptNodesError, keptStepsError, megabytes, readSteps, stepBudgetError, surelyKept, surelyKeptError, unattachedRecords, walkCut, walkHeader, walksKept, } from "./walkRows.js";
11
+ import { blocksPiece, refuseRevisited, runsTile, skippedPiece, windowRuns, } from "./walkRuns.js";
11
12
  // A window reads whole tiles and keeps the steps on it, so a narrow window
12
13
  // reads several times what it keeps: 464 haplotypes across the 1.5 kb ABCA7
13
14
  // repeat read 5.0 M steps and keep 1.16 M, and the cut takes 0.4 s from warm
@@ -1355,6 +1356,150 @@ export class WalkFile {
1355
1356
  sequences: opts.sequences === true ? cut.graph.sequences : undefined,
1356
1357
  };
1357
1358
  }
1359
+ /**
1360
+ * The walks of a cut of the range that expands nothing, with the same
1361
+ * `context`, `contained` and `attachBp`, as runs (walkRuns.ts), read from
1362
+ * the rows without decoding a step: each walk row's route choices and each
1363
+ * abridged piece's blocks row, from the tiles and departure blocks over the
1364
+ * window and its context and those tiles' blocks units, with no detail
1365
+ * unit and no attach tile. Its walks are the reference's and those of the
1366
+ * `haplotypes` asked for, every one by default. It refuses a file whose
1367
+ * header does not state revisited:i:0 with a RunsRefusedError, so its
1368
+ * `revisited` is always 0, and a window past the byte budgets as a cut
1369
+ * does; it never refuses on a step budget, node limit or placeholder
1370
+ * limit.
1371
+ */
1372
+ async getRunsForRange(refName, start, end, opts = {}) {
1373
+ const { haplotypes, ...rest } = opts;
1374
+ const sequence = await this.resolve(refName, opts);
1375
+ return this.runs(sequence.refName, { start, end }, { ...rest, keep: walksKept(haplotypes, sequence.refName) });
1376
+ }
1377
+ async runs(refName, region, opts = {}) {
1378
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1379
+ const { signal, keep, context = WALK_CONTEXT, contained = false, attachBp = ATTACH_BP, byteBudget = WALK_BUDGETS.byteBudget, departureByteBudget = WALK_BUDGETS.departureByteBudget, } = opts;
1380
+ checkRange(refName, region.start, region.end);
1381
+ const [header, units] = await Promise.all([
1382
+ this.getHeader({ signal }),
1383
+ this.getUnits(refName, { signal }),
1384
+ ]);
1385
+ const refused = refuseRevisited(header.revisited);
1386
+ if (refused) {
1387
+ throw refused;
1388
+ }
1389
+ const drawn = drawnSpan(region, context);
1390
+ const { tiles, departureBlocks } = windowUnits(units, drawn);
1391
+ const tileBytesTo = (end) => bytesOf(tiles.filter(u => u.start < end + context));
1392
+ const checkBytes = (bytesTo) => {
1393
+ const tooLarge = Number.isFinite(byteBudget)
1394
+ ? byteBudgetError(bytesTo, byteBudget, region, header.tile, opts.budgetNames)
1395
+ : undefined;
1396
+ if (tooLarge) {
1397
+ throw tooLarge;
1398
+ }
1399
+ };
1400
+ checkBytes(tileBytesTo);
1401
+ checkDepartureBytes(departureBlocks, departureByteBudget);
1402
+ const read = await this.container.read([...tiles, ...departureBlocks], signal);
1403
+ const { records } = departureRecords(read.slice(tiles.length).flat(), drawn, keep);
1404
+ const decoded = tiles.map((unit, k) => runsTile(split(read[k]), Number(unit.name), keep));
1405
+ const blocksUnits = new Map(units.filter(u => u.kind === 'blocks').map(u => [u.name, u]));
1406
+ const wanted = tiles.flatMap((tileUnit, k) => {
1407
+ const unit = blocksUnits.get(tileUnit.name);
1408
+ if (decoded[k].abridged.length > 0 && !unit) {
1409
+ throw new WalkFormatError(`${refName}'s unit table lists no blocks unit ${tileUnit.name}, which the abridged rows of that tile need`);
1410
+ }
1411
+ return unit && decoded[k].abridged.length > 0
1412
+ ? [{ unit, from: tileUnit.start, k }]
1413
+ : [];
1414
+ });
1415
+ checkBytes(end => tileBytesTo(end) +
1416
+ bytesOf(wanted.filter(x => x.from < end + context).map(x => x.unit)));
1417
+ const blocksRead = await this.container.read(wanted.map(x => x.unit), signal);
1418
+ const blocksRows = new Map();
1419
+ wanted.forEach(({ k }, w) => {
1420
+ blocksRows.set(k, new Map(split(blocksRead[w]).map(cols => {
1421
+ var _a, _b, _c;
1422
+ return [
1423
+ pieceKey((_a = cols[4]) !== null && _a !== void 0 ? _a : '', (_b = cols[5]) !== null && _b !== void 0 ? _b : '', (_c = cols[6]) !== null && _c !== void 0 ? _c : ''),
1424
+ cols,
1425
+ ];
1426
+ })));
1427
+ });
1428
+ // the drawn stretch as far as the reference's passes over it reach, and
1429
+ // the window and its context as walkCut widens them
1430
+ const over = { ...drawn };
1431
+ const bounds = {
1432
+ start: region.start - context,
1433
+ end: region.end + context,
1434
+ };
1435
+ const window = { ...bounds };
1436
+ for (const { path } of decoded) {
1437
+ const hull = path.hull(drawn);
1438
+ over.start = Math.min(over.start, (_a = hull === null || hull === void 0 ? void 0 : hull.start) !== null && _a !== void 0 ? _a : over.start);
1439
+ over.end = Math.max(over.end, (_b = hull === null || hull === void 0 ? void 0 : hull.end) !== null && _b !== void 0 ? _b : over.end);
1440
+ const reach = path.hull(bounds);
1441
+ window.start = Math.min(window.start, (_c = reach === null || reach === void 0 ? void 0 : reach.start) !== null && _c !== void 0 ? _c : window.start);
1442
+ window.end = Math.max(window.end, (_d = reach === null || reach === void 0 ? void 0 : reach.end) !== null && _d !== void 0 ? _d : window.end);
1443
+ }
1444
+ const onOver = (span) => span.start < over.end && span.end > over.start;
1445
+ const abridged = decoded.flatMap((tile, k) => tile.abridged.map(piece => ({ piece, k })));
1446
+ const lines = new Map();
1447
+ for (const { piece } of abridged) {
1448
+ const key = `${piece.name}\t${piece.fragStart}`;
1449
+ const line = (_e = lines.get(key)) !== null && _e !== void 0 ? _e : [];
1450
+ lines.set(key, line);
1451
+ line.push({ piece: piece.piece, on: onOver(piece.span), item: piece });
1452
+ }
1453
+ for (const tile of decoded) {
1454
+ for (const piece of tile.pieces) {
1455
+ (_f = lines.get(`${piece.name}\t${piece.fragStart}`)) === null || _f === void 0 ? void 0 : _f.push({
1456
+ piece: piece.piece,
1457
+ on: piece.span === undefined || onOver(piece.span),
1458
+ });
1459
+ }
1460
+ }
1461
+ const inOrder = [...lines.values()].map(line => line.sort((a, b) => a.piece - b.piece));
1462
+ const drawnPieces = new Set(betweenDrawn(inOrder).map(held => held.item));
1463
+ const reached = new Set(contained && context > 0 ? beforeDrawn(inOrder) : []);
1464
+ const ownRecords = new Map();
1465
+ for (const d of records) {
1466
+ if (d.ownBp > 0) {
1467
+ ownRecords.set(d.name, [...((_g = ownRecords.get(d.name)) !== null && _g !== void 0 ? _g : []), d]);
1468
+ }
1469
+ }
1470
+ const built = (piece) => {
1471
+ var _a;
1472
+ const runs = ((_a = ownRecords.get(piece.name)) !== null && _a !== void 0 ? _a : []).flatMap(d => {
1473
+ const stretch = ownStretch(piece, d);
1474
+ return stretch
1475
+ ? [{ ...stretch, attached: attachesOwnSteps(d, drawn, attachBp) }]
1476
+ : [];
1477
+ });
1478
+ return (drawnPieces.has(piece) ||
1479
+ runs.some(run => run.attached) ||
1480
+ (reached.has(piece) && runs.some(run => run.trailing)));
1481
+ };
1482
+ const pieces = decoded.flatMap(tile => tile.pieces);
1483
+ for (const { piece, k } of abridged) {
1484
+ const cols = (_h = blocksRows.get(k)) === null || _h === void 0 ? void 0 : _h.get(keyOf(piece));
1485
+ if (built(piece) && !cols) {
1486
+ throw new WalkFormatError(`${refName}'s blocks unit ${tiles[k].name} holds no row for piece ${piece.piece} of ${piece.name}, which its tile abridges`);
1487
+ }
1488
+ pieces.push(cols && built(piece)
1489
+ ? blocksPiece(piece, cols, decoded[k].path)
1490
+ : skippedPiece(piece));
1491
+ }
1492
+ return windowRuns({
1493
+ refName,
1494
+ pieces,
1495
+ records,
1496
+ window,
1497
+ contained,
1498
+ context,
1499
+ holes: header.holes,
1500
+ revisited: (_j = header.revisited) !== null && _j !== void 0 ? _j : Number.NaN,
1501
+ });
1502
+ }
1358
1503
  /**
1359
1504
  * Every haplotype's departures over the range, for structuralForms, from
1360
1505
  * one cut without links that expands no walk. A haplotype the header names
package/esm/walkRows.d.ts CHANGED
@@ -97,6 +97,16 @@ export interface WalkRun {
97
97
  }[];
98
98
  own?: OwnSteps[];
99
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[][];
100
110
  export declare function joinPieces(rows: WalkRow[]): WalkRun[];
101
111
  /**
102
112
  * One walk's stretch through the cut, from its first step on the drawn
package/esm/walkRows.js CHANGED
@@ -75,10 +75,14 @@ export function walkNameFilter(wanted, referenceHaplotype) {
75
75
  export function walksKept(wanted, refName) {
76
76
  return walkNameFilter(wanted, panSNHaplotypeOrSample(refName));
77
77
  }
78
- export function joinPieces(rows) {
78
+ /**
79
+ * Each line's pieces in runs of consecutive piece numbers, in piece order,
80
+ * the lines in the order `pieces` first names them: a WalkRun's rows, and a
81
+ * run of walkRuns.ts's pieces
82
+ */
83
+ export function consecutivePieces(pieces) {
79
84
  const byPath = new Map();
80
- const runs = [];
81
- for (const row of rows) {
85
+ for (const row of pieces) {
82
86
  const key = `${row.name}\t${row.fragStart}`;
83
87
  const list = byPath.get(key);
84
88
  if (list) {
@@ -88,19 +92,22 @@ export function joinPieces(rows) {
88
92
  byPath.set(key, [row]);
89
93
  }
90
94
  }
91
- for (const pieces of byPath.values()) {
92
- pieces.sort((a, b) => a.piece - b.piece);
95
+ const runs = [];
96
+ for (const line of byPath.values()) {
97
+ line.sort((a, b) => a.piece - b.piece);
93
98
  let from = 0;
94
- for (let i = 1; i <= pieces.length; i++) {
95
- if (i === pieces.length ||
96
- pieces[i].piece !== pieces[i - 1].piece + 1) {
97
- runs.push(decodeRun(pieces.slice(from, i)));
99
+ for (let i = 1; i <= line.length; i++) {
100
+ if (i === line.length || line[i].piece !== line[i - 1].piece + 1) {
101
+ runs.push(line.slice(from, i));
98
102
  from = i;
99
103
  }
100
104
  }
101
105
  }
102
106
  return runs;
103
107
  }
108
+ export function joinPieces(rows) {
109
+ return consecutivePieces(rows).map(decodeRun);
110
+ }
104
111
  function decodeRun(pieces) {
105
112
  var _a;
106
113
  const n = pieces.reduce((sum, p) => sum + p.n, 0);