@gmod/bam 7.6.1 → 7.7.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 +109 -98
- package/dist/bai.d.ts +6 -3
- package/dist/bai.js +32 -16
- package/dist/bai.js.map +1 -1
- package/dist/bamFile.d.ts +16 -3
- package/dist/bamFile.js +83 -36
- package/dist/bamFile.js.map +1 -1
- package/dist/chunk.d.ts +0 -1
- package/dist/chunk.js +0 -5
- package/dist/chunk.js.map +1 -1
- package/dist/csi.d.ts +0 -2
- package/dist/csi.js +4 -11
- package/dist/csi.js.map +1 -1
- package/dist/htsget.d.ts +16 -0
- package/dist/htsget.js +72 -52
- package/dist/htsget.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/indexFile.d.ts +2 -3
- package/dist/indexFile.js.map +1 -1
- package/dist/sam.js +8 -3
- package/dist/sam.js.map +1 -1
- package/dist/util.d.ts +11 -3
- package/dist/util.js +35 -8
- package/dist/util.js.map +1 -1
- package/dist/virtualOffset.d.ts +8 -3
- package/dist/virtualOffset.js +0 -3
- package/dist/virtualOffset.js.map +1 -1
- package/esm/bai.d.ts +6 -3
- package/esm/bai.js +32 -16
- package/esm/bai.js.map +1 -1
- package/esm/bamFile.d.ts +16 -3
- package/esm/bamFile.js +83 -36
- package/esm/bamFile.js.map +1 -1
- package/esm/chunk.d.ts +0 -1
- package/esm/chunk.js +0 -5
- package/esm/chunk.js.map +1 -1
- package/esm/csi.d.ts +0 -2
- package/esm/csi.js +4 -11
- package/esm/csi.js.map +1 -1
- package/esm/htsget.d.ts +16 -0
- package/esm/htsget.js +73 -53
- package/esm/htsget.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/indexFile.d.ts +2 -3
- package/esm/indexFile.js.map +1 -1
- package/esm/sam.js +8 -3
- package/esm/sam.js.map +1 -1
- package/esm/util.d.ts +11 -3
- package/esm/util.js +35 -8
- package/esm/util.js.map +1 -1
- package/esm/virtualOffset.d.ts +8 -3
- package/esm/virtualOffset.js +0 -3
- package/esm/virtualOffset.js.map +1 -1
- package/package.json +3 -3
- package/src/bai.ts +42 -20
- package/src/bamFile.ts +86 -38
- package/src/chunk.ts +0 -8
- package/src/csi.ts +4 -10
- package/src/htsget.ts +117 -62
- package/src/index.ts +2 -0
- package/src/indexFile.ts +2 -3
- package/src/sam.ts +8 -3
- package/src/util.ts +44 -11
- package/src/virtualOffset.ts +9 -8
- package/dist/long.d.ts +0 -1
- package/dist/long.js +0 -17
- package/dist/long.js.map +0 -1
- package/esm/long.d.ts +0 -1
- package/esm/long.js +0 -14
- package/esm/long.js.map +0 -1
- package/src/long.ts +0 -16
package/dist/indexFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexFile.js","sourceRoot":"","sources":["../src/indexFile.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"indexFile.js","sourceRoot":"","sources":["../src/indexFile.ts"],"names":[],"mappings":";;;;;AA6BA,wCAeC;AA5CD,mEAAyC;AAEzC,uCAA0C;AAwB1C,uDAAuD;AACvD,6EAA6E;AAC7E,2CAA2C;AAC3C,SAAgB,cAAc,CAC5B,UAA4C,EAC5C,OAAO,GAAG,CAAC;IAEX,MAAM,KAAK,GAAG,IAAI,mBAAQ,CAAY,EAAE,OAAO,EAAE,CAAC,CAAA;IAClD,OAAO,CAAC,KAAa,EAAE,EAAE;QACvB,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;QACD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAChC,IAAI,MAAM,EAAE,CAAC;YACX,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC1B,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAED,MAA8B,SAAS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CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CACrE,CAAA;QAED,8DAA8D;QAC9D,MAAM,YAAY,GAAG,IAAA,wBAAc,EAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAA;QAExD,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;YACjC,KAAK,IAAI,KAAK,CAAC,WAAW,EAAE,CAAA;QAC9B,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AA5GD,4BA4GC"}
|
package/dist/sam.js
CHANGED
|
@@ -11,9 +11,14 @@ function parseHeaderText(text) {
|
|
|
11
11
|
tag: tag.slice(1),
|
|
12
12
|
data: fields.map(f => {
|
|
13
13
|
const r = f.indexOf(':');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// A field with no colon is not a TAG:VALUE pair — @CO lines are free
|
|
15
|
+
// text, one comment per line (`samtools view -H c2#pad.3.0.cram`).
|
|
16
|
+
// Without this branch `slice(0, -1)` silently drops the comment's last
|
|
17
|
+
// character into the tag. Same shape @gmod/cram's parseHeaderText
|
|
18
|
+
// returns, so both feed a consumer's header parser identically.
|
|
19
|
+
return r === -1
|
|
20
|
+
? { tag: f, value: '' }
|
|
21
|
+
: { tag: f.slice(0, r), value: f.slice(r + 1) };
|
|
17
22
|
}),
|
|
18
23
|
});
|
|
19
24
|
}
|
package/dist/sam.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sam.js","sourceRoot":"","sources":["../src/sam.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"sam.js","sourceRoot":"","sources":["../src/sam.ts"],"names":[],"mappings":";;AAAA,0CAuBC;AAvBD,SAAgB,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACjC,MAAM,IAAI,GAA8D,EAAE,CAAA;IAC1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzC,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,CAAC,IAAI,CAAC;gBACR,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;gBACjB,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;oBACnB,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;oBACxB,qEAAqE;oBACrE,mEAAmE;oBACnE,uEAAuE;oBACvE,kEAAkE;oBAClE,gEAAgE;oBAChE,OAAO,CAAC,KAAK,CAAC,CAAC;wBACb,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;wBACvB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAA;gBACnD,CAAC,CAAC;aACH,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Chunk from './chunk.ts';
|
|
2
2
|
import { VirtualOffset } from './virtualOffset.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OffsetCoords } from './virtualOffset.ts';
|
|
4
4
|
export interface BamOpts {
|
|
5
5
|
viewAsPairs?: boolean;
|
|
6
6
|
pairAcrossChr?: boolean;
|
|
@@ -25,22 +25,30 @@ export interface BaseOpts {
|
|
|
25
25
|
*/
|
|
26
26
|
onProgress?: (bytesDownloaded: number, totalBytes?: number) => void;
|
|
27
27
|
}
|
|
28
|
-
export declare function optimizeChunks(chunks: Chunk[], lowest?:
|
|
28
|
+
export declare function optimizeChunks(chunks: Chunk[], lowest?: OffsetCoords): Chunk[];
|
|
29
29
|
export declare function parsePseudoBin(bytes: Uint8Array, offset: number): {
|
|
30
30
|
lineCount: number;
|
|
31
31
|
};
|
|
32
|
-
export declare function clampChunkEnds(chunks: Chunk[], extraBoundaries?: number
|
|
32
|
+
export declare function clampChunkEnds(chunks: Chunk[], extraBoundaries?: ArrayLike<number>): void;
|
|
33
33
|
export declare function parseRefSeqs(uncba: Uint8Array, start: number, renameRefSeq: (s: string) => string): {
|
|
34
34
|
chrToIndex: Record<string, number>;
|
|
35
35
|
indexToChr: {
|
|
36
36
|
refName: string;
|
|
37
37
|
length: number;
|
|
38
38
|
}[];
|
|
39
|
+
end: number;
|
|
39
40
|
} | undefined;
|
|
40
41
|
/**
|
|
41
42
|
* The smallest of `current` and the `count` packed virtual offsets starting at
|
|
42
43
|
* `offset`, allocating at most one VirtualOffset rather than one per entry.
|
|
43
44
|
*
|
|
45
|
+
* 0:0 is skipped rather than treated as the minimum. No BAM record can live
|
|
46
|
+
* there — the magic and header occupy the start of the file — so it is the
|
|
47
|
+
* "unset" placeholder htslib leaves in linear-index windows ahead of a
|
|
48
|
+
* reference's first read (see test/data/HG00096_illumina_lowcov.bam.bai, whose
|
|
49
|
+
* first three windows are 0). Counting it collapses firstDataLine to 0:0 and
|
|
50
|
+
* makes callers size a header read from nothing.
|
|
51
|
+
*
|
|
44
52
|
* The index first pass exists only to find this minimum, and it visits every
|
|
45
53
|
* linear-index entry in the file to do it. Building a VirtualOffset per entry
|
|
46
54
|
* to compare and discard it is the bulk of that pass.
|
package/dist/util.js
CHANGED
|
@@ -12,7 +12,6 @@ exports.parseNameBytes = parseNameBytes;
|
|
|
12
12
|
exports.concatUint8Array = concatUint8Array;
|
|
13
13
|
exports.appendInRange = appendInRange;
|
|
14
14
|
const chunk_ts_1 = __importDefault(require("./chunk.js"));
|
|
15
|
-
const long_ts_1 = require("./long.js");
|
|
16
15
|
const virtualOffset_ts_1 = require("./virtualOffset.js");
|
|
17
16
|
function optimizeChunks(chunks, lowest) {
|
|
18
17
|
const n = chunks.length;
|
|
@@ -73,9 +72,20 @@ function optimizeChunks(chunks, lowest) {
|
|
|
73
72
|
}
|
|
74
73
|
return mergedChunks;
|
|
75
74
|
}
|
|
75
|
+
// The pseudo-bin's mapped-record count, a little-endian uint64. Read as two
|
|
76
|
+
// 32-bit halves rather than via BigInt: exact up to Number.MAX_SAFE_INTEGER,
|
|
77
|
+
// which is far past any real record count, and allocates nothing.
|
|
76
78
|
function parsePseudoBin(bytes, offset) {
|
|
79
|
+
const low = bytes[offset] |
|
|
80
|
+
(bytes[offset + 1] << 8) |
|
|
81
|
+
(bytes[offset + 2] << 16) |
|
|
82
|
+
(bytes[offset + 3] << 24);
|
|
83
|
+
const high = bytes[offset + 4] |
|
|
84
|
+
(bytes[offset + 5] << 8) |
|
|
85
|
+
(bytes[offset + 6] << 16) |
|
|
86
|
+
(bytes[offset + 7] << 24);
|
|
77
87
|
return {
|
|
78
|
-
lineCount: (0
|
|
88
|
+
lineCount: (high >>> 0) * 2 ** 32 + (low >>> 0),
|
|
79
89
|
};
|
|
80
90
|
}
|
|
81
91
|
// Tighten each chunk's endPosition (default: a full max-size BGZF block past
|
|
@@ -86,11 +96,17 @@ function parsePseudoBin(bytes, offset) {
|
|
|
86
96
|
// least the true block end, so the clamped fetch still contains the whole block.
|
|
87
97
|
// Shrinks both the byte estimate and the actual fetch with no extra I/O.
|
|
88
98
|
function clampChunkEnds(chunks, extraBoundaries = []) {
|
|
89
|
-
|
|
99
|
+
// Float64Array rather than number[]: `extraBoundaries` is the linear index,
|
|
100
|
+
// which runs to tens of thousands of entries on a human-sized reference, and
|
|
101
|
+
// this is the only place they get copied.
|
|
102
|
+
const boundaries = new Float64Array(extraBoundaries.length + chunks.length * 2);
|
|
103
|
+
boundaries.set(extraBoundaries);
|
|
104
|
+
let n = extraBoundaries.length;
|
|
90
105
|
for (const c of chunks) {
|
|
91
|
-
boundaries
|
|
106
|
+
boundaries[n++] = c.minv.blockPosition;
|
|
107
|
+
boundaries[n++] = c.maxv.blockPosition;
|
|
92
108
|
}
|
|
93
|
-
boundaries.sort(
|
|
109
|
+
boundaries.sort();
|
|
94
110
|
for (const c of chunks) {
|
|
95
111
|
const max = c.maxv.blockPosition;
|
|
96
112
|
// first boundary strictly greater than max
|
|
@@ -139,13 +155,23 @@ function parseRefSeqs(uncba, start, renameRefSeq) {
|
|
|
139
155
|
indexToChr.push({ refName, length: lRef });
|
|
140
156
|
p += 8 + lName;
|
|
141
157
|
}
|
|
142
|
-
|
|
158
|
+
// end is the offset just past the header, i.e. where alignment records start
|
|
159
|
+
return { chrToIndex, indexToChr, end: p };
|
|
143
160
|
}
|
|
144
|
-
// SYNC: ~/src/gmod/tabix-js/src/util.ts minVirtualOffset
|
|
161
|
+
// SYNC: ~/src/gmod/tabix-js/src/util.ts minVirtualOffset — but NOT the 0:0
|
|
162
|
+
// skip below, which is only sound for BAM. A tabix'd file with no header lines
|
|
163
|
+
// really does have its first record at 0:0.
|
|
145
164
|
/**
|
|
146
165
|
* The smallest of `current` and the `count` packed virtual offsets starting at
|
|
147
166
|
* `offset`, allocating at most one VirtualOffset rather than one per entry.
|
|
148
167
|
*
|
|
168
|
+
* 0:0 is skipped rather than treated as the minimum. No BAM record can live
|
|
169
|
+
* there — the magic and header occupy the start of the file — so it is the
|
|
170
|
+
* "unset" placeholder htslib leaves in linear-index windows ahead of a
|
|
171
|
+
* reference's first read (see test/data/HG00096_illumina_lowcov.bam.bai, whose
|
|
172
|
+
* first three windows are 0). Counting it collapses firstDataLine to 0:0 and
|
|
173
|
+
* makes callers size a header read from nothing.
|
|
174
|
+
*
|
|
149
175
|
* The index first pass exists only to find this minimum, and it visits every
|
|
150
176
|
* linear-index entry in the file to do it. Building a VirtualOffset per entry
|
|
151
177
|
* to compare and discard it is the bulk of that pass.
|
|
@@ -163,7 +189,8 @@ function minVirtualOffset(bytes, offset, count, current) {
|
|
|
163
189
|
bytes[p + 3] * 0x100 +
|
|
164
190
|
bytes[p + 2];
|
|
165
191
|
const data = (bytes[p + 1] << 8) | bytes[p];
|
|
166
|
-
if (block
|
|
192
|
+
if ((block !== 0 || data !== 0) &&
|
|
193
|
+
(block < minBlock || (block === minBlock && data < minData))) {
|
|
167
194
|
minBlock = block;
|
|
168
195
|
minData = data;
|
|
169
196
|
found = true;
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;AA+BA,wCAsEC;AAKD,wCAcC;AASD,wCAmCC;AAKD,oCAuCC;AAoBD,4CA6BC;AAGD,wCAuBC;AAED,4CAYC;AAYD,sCAoBC;AAzUD,0DAA8B;AAC9B,yDAAkD;AA8BlD,SAAgB,cAAc,CAAC,MAAe,EAAE,MAAqB;IACnE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAA;IACvB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,OAAO,MAAM,CAAA;IACf,CAAC;IAED,0DAA0D;IAC1D,IAAI,QAAiB,CAAA;IACrB,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAA;QACxC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAA;QACtC,QAAQ,GAAG,EAAE,CAAA;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAE,CAAA;YACxB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;YACvB,MAAM,GAAG,GACP,IAAI,CAAC,aAAa,GAAG,WAAW,IAAI,IAAI,CAAC,YAAY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AO,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/C,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAA;QACrB,IAAI,CAAC,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;gBACnB,MAAK;YACP,CAAC;iBAAM,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;gBACxB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACb,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;YAC5B,MAAK;QACP,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/dist/virtualOffset.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The two coordinates a virtual offset packs, without the `blockPos:dataPos`
|
|
3
|
+
* string form. What every consumer that only compares positions needs — the
|
|
4
|
+
* BAI linear index stores these as raw numbers and materializes no object.
|
|
5
|
+
*/
|
|
6
|
+
export interface OffsetCoords {
|
|
2
7
|
blockPosition: number;
|
|
3
8
|
dataPosition: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Offset extends OffsetCoords {
|
|
4
11
|
toString(): string;
|
|
5
|
-
compareTo(arg: Offset): number;
|
|
6
12
|
}
|
|
7
13
|
export declare class VirtualOffset {
|
|
8
14
|
blockPosition: number;
|
|
9
15
|
dataPosition: number;
|
|
10
16
|
constructor(blockPosition: number, dataPosition: number);
|
|
11
17
|
toString(): string;
|
|
12
|
-
compareTo(b: VirtualOffset): number;
|
|
13
18
|
}
|
|
14
19
|
export declare function fromBytes(bytes: Uint8Array, offset?: number): VirtualOffset;
|
package/dist/virtualOffset.js
CHANGED
|
@@ -12,9 +12,6 @@ class VirtualOffset {
|
|
|
12
12
|
toString() {
|
|
13
13
|
return `${this.blockPosition}:${this.dataPosition}`;
|
|
14
14
|
}
|
|
15
|
-
compareTo(b) {
|
|
16
|
-
return (this.blockPosition - b.blockPosition || this.dataPosition - b.dataPosition);
|
|
17
|
-
}
|
|
18
15
|
}
|
|
19
16
|
exports.VirtualOffset = VirtualOffset;
|
|
20
17
|
function fromBytes(bytes, offset = 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtualOffset.js","sourceRoot":"","sources":["../src/virtualOffset.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"virtualOffset.js","sourceRoot":"","sources":["../src/virtualOffset.ts"],"names":[],"mappings":";;;AA0BA,8BAUC;AAtBD,MAAa,aAAa;IACjB,aAAa,CAAQ;IACrB,YAAY,CAAQ;IAC3B,YAAY,aAAqB,EAAE,YAAoB;QACrD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA,CAAC,wCAAwC;QAC3E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA,CAAC,sCAAsC;IACzE,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,EAAE,CAAA;IACrD,CAAC;CACF;AAXD,sCAWC;AACD,SAAgB,SAAS,CAAC,KAAiB,EAAE,MAAM,GAAG,CAAC;IACrD,OAAO,IAAI,aAAa,CACtB,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,aAAa;QAChC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,WAAW;QAChC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,SAAS;QAC9B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,OAAO;QAC5B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,KAAK;QAC1B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,EACpB,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAE,CAC3C,CAAA;AACH,CAAC"}
|
package/esm/bai.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import IndexFile from './indexFile.ts';
|
|
2
2
|
import type { ParsedIndexBase, RefIndex } from './indexFile.ts';
|
|
3
3
|
import type { BaseOpts } from './util.ts';
|
|
4
|
-
import type { VirtualOffset } from './virtualOffset.ts';
|
|
5
4
|
interface BaiRefIndex extends RefIndex {
|
|
6
|
-
|
|
5
|
+
linearBlockPositions: Float64Array;
|
|
6
|
+
linearDataPositions: Float64Array;
|
|
7
7
|
}
|
|
8
8
|
interface BaiParsed extends ParsedIndexBase<BaiRefIndex> {
|
|
9
9
|
bai: true;
|
|
@@ -17,6 +17,9 @@ export default class BAI extends IndexFile<BaiParsed> {
|
|
|
17
17
|
_parse(opts: BaseOpts): Promise<BaiParsed>;
|
|
18
18
|
indexCov(seqId: number, start?: number, end?: number, opts?: BaseOpts): Promise<IndexCovEntry[]>;
|
|
19
19
|
protected reg2bins(min: number, max: number): readonly [readonly [0, 0], readonly [number, number], readonly [number, number], readonly [number, number], readonly [number, number], readonly [number, number]];
|
|
20
|
-
protected getLowestChunk(refIndex: BaiRefIndex, min: number):
|
|
20
|
+
protected getLowestChunk(refIndex: BaiRefIndex, min: number): {
|
|
21
|
+
blockPosition: number;
|
|
22
|
+
dataPosition: number;
|
|
23
|
+
} | undefined;
|
|
21
24
|
}
|
|
22
25
|
export {};
|
package/esm/bai.js
CHANGED
|
@@ -108,22 +108,32 @@ export default class BAI extends IndexFile {
|
|
|
108
108
|
}
|
|
109
109
|
const linearCount = dataView.getInt32(curr, true);
|
|
110
110
|
curr += 4;
|
|
111
|
-
const
|
|
111
|
+
const linearBlockPositions = new Float64Array(linearCount);
|
|
112
|
+
const linearDataPositions = new Float64Array(linearCount);
|
|
112
113
|
for (let j = 0; j < linearCount; j++) {
|
|
113
|
-
|
|
114
|
+
// a virtual offset is a 48-bit block position in the high bytes and a
|
|
115
|
+
// 16-bit data position in the low two
|
|
116
|
+
linearBlockPositions[j] =
|
|
117
|
+
bytes[curr + 7] * 0x10000000000 +
|
|
118
|
+
bytes[curr + 6] * 0x100000000 +
|
|
119
|
+
bytes[curr + 5] * 0x1000000 +
|
|
120
|
+
bytes[curr + 4] * 0x10000 +
|
|
121
|
+
bytes[curr + 3] * 0x100 +
|
|
122
|
+
bytes[curr + 2];
|
|
123
|
+
linearDataPositions[j] = (bytes[curr + 1] << 8) | bytes[curr];
|
|
114
124
|
curr += 8;
|
|
115
125
|
}
|
|
116
|
-
clampChunkEnds(Object.values(binIndex).flat(),
|
|
126
|
+
clampChunkEnds(Object.values(binIndex).flat(), linearBlockPositions);
|
|
117
127
|
return {
|
|
118
128
|
binIndex,
|
|
119
|
-
|
|
129
|
+
linearBlockPositions,
|
|
130
|
+
linearDataPositions,
|
|
120
131
|
stats,
|
|
121
132
|
};
|
|
122
133
|
}
|
|
123
134
|
return {
|
|
124
135
|
bai: true,
|
|
125
136
|
firstDataLine,
|
|
126
|
-
maxBlockSize: 1 << 16,
|
|
127
137
|
indices: memoizeByRefId(getIndices),
|
|
128
138
|
refCount,
|
|
129
139
|
};
|
|
@@ -136,17 +146,18 @@ export default class BAI extends IndexFile {
|
|
|
136
146
|
if (!seqIdx) {
|
|
137
147
|
return [];
|
|
138
148
|
}
|
|
139
|
-
const {
|
|
140
|
-
|
|
149
|
+
const { linearBlockPositions, stats } = seqIdx;
|
|
150
|
+
const nintv = linearBlockPositions.length;
|
|
151
|
+
if (nintv === 0) {
|
|
141
152
|
return [];
|
|
142
153
|
}
|
|
143
|
-
const e = end === undefined ? (
|
|
154
|
+
const e = end === undefined ? (nintv - 1) * v : roundUp(end, v);
|
|
144
155
|
const s = start === undefined ? 0 : roundDown(start, v);
|
|
145
156
|
const depths = range
|
|
146
157
|
? new Array((e - s) / v)
|
|
147
|
-
: new Array(
|
|
148
|
-
const totalSize =
|
|
149
|
-
if (e > (
|
|
158
|
+
: new Array(nintv - 1);
|
|
159
|
+
const totalSize = linearBlockPositions[nintv - 1];
|
|
160
|
+
if (e > (nintv - 1) * v) {
|
|
150
161
|
throw new Error('query outside of range of linear index');
|
|
151
162
|
}
|
|
152
163
|
// Scale the block-delta into a read count as we go, rather than building the
|
|
@@ -154,9 +165,9 @@ export default class BAI extends IndexFile {
|
|
|
154
165
|
// multiply-then-divide order: hoisting lineCount/totalSize into a factor
|
|
155
166
|
// reassociates the arithmetic and shifts scores by an ulp.
|
|
156
167
|
const lineCount = stats?.lineCount ?? 0;
|
|
157
|
-
let currentPos =
|
|
168
|
+
let currentPos = linearBlockPositions[s / v];
|
|
158
169
|
for (let i = s / v, j = 0; i < e / v; i++, j++) {
|
|
159
|
-
const nextPos =
|
|
170
|
+
const nextPos = linearBlockPositions[i + 1];
|
|
160
171
|
depths[j] = {
|
|
161
172
|
score: ((nextPos - currentPos) * lineCount) / totalSize,
|
|
162
173
|
start: i * v,
|
|
@@ -173,9 +184,14 @@ export default class BAI extends IndexFile {
|
|
|
173
184
|
// contain alignments in the region. Linear index entries are monotonically
|
|
174
185
|
// non-decreasing, so the first entry at minLin is the minimum.
|
|
175
186
|
getLowestChunk(refIndex, min) {
|
|
176
|
-
const {
|
|
177
|
-
const
|
|
178
|
-
return
|
|
187
|
+
const { linearBlockPositions, linearDataPositions } = refIndex;
|
|
188
|
+
const i = Math.min(min >> BAI_LINEAR_SHIFT, linearBlockPositions.length - 1);
|
|
189
|
+
return i < 0
|
|
190
|
+
? undefined
|
|
191
|
+
: {
|
|
192
|
+
blockPosition: linearBlockPositions[i],
|
|
193
|
+
dataPosition: linearDataPositions[i],
|
|
194
|
+
};
|
|
179
195
|
}
|
|
180
196
|
}
|
|
181
197
|
//# sourceMappingURL=bai.js.map
|
package/esm/bai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bai.js","sourceRoot":"","sources":["../src/bai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAA;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AA2E;IAC3E,+DAA+D;IACrD,cAAc,CAAC,QAAqB,EAAE,GAAW;QACzD,MAAM,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,GAAG,QAAQ,CAAA;QAC9D,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,gBAAgB,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC5E,OAAO,CAAC,GAAG,CAAC;YACV,CAAC,CAAC,SAAS;YACX,CAAC,CAAC;gBACE,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAE;gBACvC,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAE;aACtC,CAAA;IACP,CAAC;CACF"}
|
package/esm/bamFile.d.ts
CHANGED
|
@@ -72,14 +72,27 @@ export default class BamFile<T extends BamRecordLike = BAMFeature> {
|
|
|
72
72
|
tag: string;
|
|
73
73
|
value: string;
|
|
74
74
|
}[];
|
|
75
|
-
}[]
|
|
75
|
+
}[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Installs the header text and ref name/id maps from the start of a
|
|
78
|
+
* decompressed BAM stream, returning the parsed SAM header lines. Returns
|
|
79
|
+
* undefined if the stream is cut off partway through the ref-seq table, so
|
|
80
|
+
* the caller can retry with more data.
|
|
81
|
+
*/
|
|
82
|
+
protected applyHeader(uncba: Uint8Array): {
|
|
83
|
+
tag: string;
|
|
84
|
+
data: {
|
|
85
|
+
tag: string;
|
|
86
|
+
value: string;
|
|
87
|
+
}[];
|
|
88
|
+
}[] | undefined;
|
|
76
89
|
getHeader(opts?: BaseOpts): Promise<{
|
|
77
90
|
tag: string;
|
|
78
91
|
data: {
|
|
79
92
|
tag: string;
|
|
80
93
|
value: string;
|
|
81
94
|
}[];
|
|
82
|
-
}[]
|
|
95
|
+
}[]>;
|
|
83
96
|
getHeaderText(opts?: BaseOpts): Promise<string | undefined>;
|
|
84
97
|
private getSeqId;
|
|
85
98
|
/**
|
|
@@ -100,7 +113,7 @@ export default class BamFile<T extends BamRecordLike = BAMFeature> {
|
|
|
100
113
|
features: T[];
|
|
101
114
|
bytes: number;
|
|
102
115
|
}>;
|
|
103
|
-
readBamFeatures(ba: Uint8Array, cpositions: number
|
|
116
|
+
readBamFeatures(ba: Uint8Array, cpositions: ArrayLike<number>, dpositions: ArrayLike<number>, chunk: Chunk): T[];
|
|
104
117
|
hasRefSeq(seqName: string, opts?: BaseOpts): Promise<boolean>;
|
|
105
118
|
lineCount(seqName: string, opts?: BaseOpts): Promise<number>;
|
|
106
119
|
indexCov(seqName: string, start?: number, end?: number): Promise<never[] | import("./bai.ts").IndexCovEntry[]>;
|
package/esm/bamFile.js
CHANGED
|
@@ -9,6 +9,11 @@ import { parseHeaderText } from "./sam.js";
|
|
|
9
9
|
import { appendInRange, parseRefSeqs } from "./util.js";
|
|
10
10
|
export const BAM_MAGIC = 21840194;
|
|
11
11
|
const blockLen = 1 << 16;
|
|
12
|
+
// Ceiling on the header read. A million contigs is roughly 10MB of compressed
|
|
13
|
+
// @SQ lines and ref-seq table, so anything past this is a corrupt header
|
|
14
|
+
// claiming a huge n_ref rather than a real one, and growing the read further
|
|
15
|
+
// just downloads the file.
|
|
16
|
+
const maxHeaderReadLen = 32 * 1024 * 1024;
|
|
12
17
|
function resolveFilehandle(filehandle, path, url) {
|
|
13
18
|
return (filehandle ??
|
|
14
19
|
(path ? new LocalFile(path) : url ? new RemoteFile(url) : undefined));
|
|
@@ -125,40 +130,60 @@ export default class BamFile {
|
|
|
125
130
|
}
|
|
126
131
|
async getHeaderPre(opts = {}) {
|
|
127
132
|
if (!this.index) {
|
|
128
|
-
|
|
133
|
+
// Only reachable via `new BamFile({htsget: true})` used directly rather
|
|
134
|
+
// than through HtsgetFile, which overrides this. Throwing rather than
|
|
135
|
+
// returning undefined keeps `| undefined` off getHeader()'s public type,
|
|
136
|
+
// and makes that misuse loud instead of silently answering every query
|
|
137
|
+
// with zero records (getSeqId would find no chrToIndex).
|
|
138
|
+
throw new Error('no index to read a header from: use HtsgetFile for htsget sources');
|
|
129
139
|
}
|
|
130
140
|
const indexData = await this.index.parse(opts);
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
// The records start at firstDataLine, so reading up to it plus the bgzf
|
|
142
|
+
// block straddling it covers the header. It is undefined when the index
|
|
143
|
+
// records no data at all (header-only BAM), and it undershoots when the
|
|
144
|
+
// index leaves offsets unset, so grow the read until the ref-seq table
|
|
145
|
+
// parses. Never readFile() here: on a remote BAM that is a whole-file
|
|
146
|
+
// download to read a header.
|
|
147
|
+
let readLen = indexData.firstDataLine === undefined
|
|
148
|
+
? blockLen
|
|
135
149
|
: indexData.firstDataLine.blockPosition + blockLen;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
let samHeader;
|
|
151
|
+
let atEof = false;
|
|
152
|
+
while (samHeader === undefined && !atEof && readLen <= maxHeaderReadLen) {
|
|
153
|
+
const buffer = await this.bam.read(readLen, 0, { signal: opts.signal });
|
|
154
|
+
// a short read means readLen ran past the end of the file, so there are
|
|
155
|
+
// no more bytes to grow into
|
|
156
|
+
atEof = buffer.length < readLen;
|
|
157
|
+
samHeader = this.applyHeader(await unzip(buffer));
|
|
158
|
+
readLen *= 2;
|
|
159
|
+
}
|
|
160
|
+
if (samHeader === undefined) {
|
|
161
|
+
throw new Error('Insufficient data for reference sequences');
|
|
162
|
+
}
|
|
163
|
+
return samHeader;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Installs the header text and ref name/id maps from the start of a
|
|
167
|
+
* decompressed BAM stream, returning the parsed SAM header lines. Returns
|
|
168
|
+
* undefined if the stream is cut off partway through the ref-seq table, so
|
|
169
|
+
* the caller can retry with more data.
|
|
170
|
+
*/
|
|
171
|
+
applyHeader(uncba) {
|
|
140
172
|
const dataView = new DataView(uncba.buffer, uncba.byteOffset, uncba.byteLength);
|
|
141
173
|
if (dataView.getInt32(0, true) !== BAM_MAGIC) {
|
|
142
174
|
throw new Error('Not a BAM file');
|
|
143
175
|
}
|
|
144
176
|
const headLen = dataView.getInt32(4, true);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
uncba = await unzip(await this.bam.readFile());
|
|
154
|
-
parsed = parseRefSeqs(uncba, refSeqStart, this.renameRefSeq);
|
|
155
|
-
}
|
|
156
|
-
if (!parsed) {
|
|
157
|
-
throw new Error('Insufficient data for reference sequences');
|
|
177
|
+
const parsed = parseRefSeqs(uncba, headLen + 8, this.renameRefSeq);
|
|
178
|
+
let samHeader;
|
|
179
|
+
if (parsed) {
|
|
180
|
+
const headerText = new TextDecoder('utf8').decode(uncba.subarray(8, 8 + headLen));
|
|
181
|
+
this.header = headerText;
|
|
182
|
+
this.chrToIndex = parsed.chrToIndex;
|
|
183
|
+
this.indexToChr = parsed.indexToChr;
|
|
184
|
+
samHeader = parseHeaderText(headerText);
|
|
158
185
|
}
|
|
159
|
-
|
|
160
|
-
this.indexToChr = parsed.indexToChr;
|
|
161
|
-
return parseHeaderText(this.header);
|
|
186
|
+
return samHeader;
|
|
162
187
|
}
|
|
163
188
|
getHeader(opts) {
|
|
164
189
|
if (!this.headerP) {
|
|
@@ -341,21 +366,38 @@ export default class BamFile {
|
|
|
341
366
|
const chunks = res[i];
|
|
342
367
|
for (let j = 0, jl = chunks.length; j < jl; j++) {
|
|
343
368
|
const m = chunks[j];
|
|
344
|
-
|
|
369
|
+
// Key on the virtual-offset span — the same key _cachedChunkFeatures
|
|
370
|
+
// uses. Chunk.toString() also folds in `bin` and fetchedSize(), which
|
|
371
|
+
// keeps two chunks covering an identical span apart here even though
|
|
372
|
+
// the cache below collapses them, so their records came back twice.
|
|
373
|
+
map.set(chunkCacheKey(m), m);
|
|
345
374
|
}
|
|
346
375
|
}
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
376
|
+
const mateChunks = [...map.values()];
|
|
377
|
+
// Bounded for the reason ADR 0008 bounds the main query path: a viewAsPairs
|
|
378
|
+
// query over a busy region resolves to many distinct mate chunks, and an
|
|
379
|
+
// unbounded fan-out inflates every one of them at once. Same inline pool
|
|
380
|
+
// shape as _fetchChunkFeatures — ADR 0009 measured extracting a shared
|
|
381
|
+
// mapConcurrent helper at ~11% on the hot path, so it stays inline.
|
|
382
|
+
const mateFeatLists = new Array(mateChunks.length);
|
|
383
|
+
let next = 0;
|
|
384
|
+
const readNext = async () => {
|
|
385
|
+
while (next < mateChunks.length) {
|
|
386
|
+
const ci = next++;
|
|
387
|
+
const features = await this._cachedChunkFeatures(mateChunks[ci], opts);
|
|
388
|
+
const mateRecs = [];
|
|
389
|
+
for (let i = 0, l = features.length; i < l; i++) {
|
|
390
|
+
const feature = features[i];
|
|
391
|
+
if (readNameCounts.get(feature.name) === 1 &&
|
|
392
|
+
!readIds.has(feature.fileOffset)) {
|
|
393
|
+
mateRecs.push(feature);
|
|
394
|
+
}
|
|
355
395
|
}
|
|
396
|
+
mateFeatLists[ci] = mateRecs;
|
|
356
397
|
}
|
|
357
|
-
|
|
358
|
-
|
|
398
|
+
};
|
|
399
|
+
const workers = Math.min(MAX_CONCURRENT_CHUNK_READS, mateChunks.length);
|
|
400
|
+
await Promise.all(Array.from({ length: workers }, () => readNext()));
|
|
359
401
|
return mateFeatLists.flat();
|
|
360
402
|
}
|
|
361
403
|
async _readChunkFeatures(chunk, opts) {
|
|
@@ -373,6 +415,11 @@ export default class BamFile {
|
|
|
373
415
|
bytes: data.byteLength,
|
|
374
416
|
};
|
|
375
417
|
}
|
|
418
|
+
// cpositions/dpositions are `ArrayLike`, not `number[]`, because the wasm
|
|
419
|
+
// decompressor produces them as Float64Arrays — @gmod/bgzf-filehandle spreads
|
|
420
|
+
// them into plain arrays on the way out, and this signature is what lets that
|
|
421
|
+
// copy be dropped there without a change here. Only indexed reads and
|
|
422
|
+
// `.length` are used below either way.
|
|
376
423
|
readBamFeatures(ba, cpositions, dpositions, chunk) {
|
|
377
424
|
let blockStart = 0;
|
|
378
425
|
const sink = [];
|