@gmod/bam 1.1.18 → 2.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.
- package/CHANGELOG.md +61 -25
- package/README.md +95 -57
- package/dist/bai.d.ts +34 -15
- package/dist/bai.js +87 -91
- package/dist/bai.js.map +1 -1
- package/dist/bamFile.d.ts +33 -27
- package/dist/bamFile.js +127 -121
- package/dist/bamFile.js.map +1 -1
- package/dist/chunk.d.ts +4 -8
- package/dist/chunk.js +2 -8
- package/dist/chunk.js.map +1 -1
- package/dist/csi.d.ts +74 -10
- package/dist/csi.js +78 -90
- package/dist/csi.js.map +1 -1
- package/dist/htsget.d.ts +5 -8
- package/dist/htsget.js +72 -47
- package/dist/htsget.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/indexFile.d.ts +0 -6
- package/dist/indexFile.js +0 -35
- package/dist/indexFile.js.map +1 -1
- package/dist/nullIndex.d.ts +7 -0
- package/dist/nullIndex.js +33 -0
- package/dist/nullIndex.js.map +1 -0
- package/dist/record.d.ts +2 -2
- package/dist/record.js +34 -24
- package/dist/record.js.map +1 -1
- package/dist/sam.js +9 -7
- package/dist/sam.js.map +1 -1
- package/dist/util.d.ts +13 -1
- package/dist/util.js +47 -15
- package/dist/util.js.map +1 -1
- package/esm/bai.d.ts +34 -15
- package/esm/bai.js +86 -91
- package/esm/bai.js.map +1 -1
- package/esm/bamFile.d.ts +33 -27
- package/esm/bamFile.js +124 -120
- package/esm/bamFile.js.map +1 -1
- package/esm/chunk.d.ts +4 -8
- package/esm/chunk.js +2 -8
- package/esm/chunk.js.map +1 -1
- package/esm/csi.d.ts +74 -10
- package/esm/csi.js +85 -93
- package/esm/csi.js.map +1 -1
- package/esm/htsget.d.ts +5 -8
- package/esm/htsget.js +68 -43
- package/esm/htsget.js.map +1 -1
- package/esm/index.d.ts +5 -6
- package/esm/index.js +5 -6
- package/esm/index.js.map +1 -1
- package/esm/indexFile.d.ts +0 -6
- package/esm/indexFile.js +0 -22
- package/esm/indexFile.js.map +1 -1
- package/esm/nullIndex.d.ts +7 -0
- package/esm/nullIndex.js +16 -0
- package/esm/nullIndex.js.map +1 -0
- package/esm/record.d.ts +2 -2
- package/esm/record.js +34 -24
- package/esm/record.js.map +1 -1
- package/esm/sam.js +9 -7
- package/esm/sam.js.map +1 -1
- package/esm/util.d.ts +13 -1
- package/esm/util.js +40 -14
- package/esm/util.js.map +1 -1
- package/package.json +16 -17
- package/src/bai.ts +99 -102
- package/src/bamFile.ts +174 -198
- package/src/chunk.ts +6 -20
- package/src/csi.ts +102 -111
- package/src/htsget.ts +81 -61
- package/src/index.ts +5 -7
- package/src/indexFile.ts +0 -27
- package/src/nullIndex.ts +18 -0
- package/src/record.ts +34 -24
- package/src/sam.ts +9 -7
- package/src/util.ts +54 -13
- package/src/declare.d.ts +0 -2
package/dist/bai.js
CHANGED
|
@@ -12,11 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const long_1 = __importDefault(require("long"));
|
|
16
15
|
const virtualOffset_1 = require("./virtualOffset");
|
|
17
16
|
const chunk_1 = __importDefault(require("./chunk"));
|
|
18
|
-
const indexFile_1 = __importDefault(require("./indexFile"));
|
|
19
17
|
const util_1 = require("./util");
|
|
18
|
+
const indexFile_1 = __importDefault(require("./indexFile"));
|
|
20
19
|
const BAI_MAGIC = 21578050; // BAI\1
|
|
21
20
|
function roundDown(n, multiple) {
|
|
22
21
|
return n - (n % multiple);
|
|
@@ -24,91 +23,93 @@ function roundDown(n, multiple) {
|
|
|
24
23
|
function roundUp(n, multiple) {
|
|
25
24
|
return n - (n % multiple) + multiple;
|
|
26
25
|
}
|
|
26
|
+
function reg2bins(beg, end) {
|
|
27
|
+
end -= 1;
|
|
28
|
+
return [
|
|
29
|
+
[0, 0],
|
|
30
|
+
[1 + (beg >> 26), 1 + (end >> 26)],
|
|
31
|
+
[9 + (beg >> 23), 9 + (end >> 23)],
|
|
32
|
+
[73 + (beg >> 20), 73 + (end >> 20)],
|
|
33
|
+
[585 + (beg >> 17), 585 + (end >> 17)],
|
|
34
|
+
[4681 + (beg >> 14), 4681 + (end >> 14)],
|
|
35
|
+
];
|
|
36
|
+
}
|
|
27
37
|
class BAI extends indexFile_1.default {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return { lineCount };
|
|
31
|
-
}
|
|
32
|
-
lineCount(refId, opts = {}) {
|
|
38
|
+
lineCount(refId, opts) {
|
|
39
|
+
var _a, _b;
|
|
33
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
if (!index) {
|
|
37
|
-
return -1;
|
|
38
|
-
}
|
|
39
|
-
const ret = index.stats || {};
|
|
40
|
-
return ret.lineCount === undefined ? -1 : ret.lineCount;
|
|
41
|
+
const indexData = yield this.parse(opts);
|
|
42
|
+
return ((_b = (_a = indexData.indices[refId]) === null || _a === void 0 ? void 0 : _a.stats) === null || _b === void 0 ? void 0 : _b.lineCount) || 0;
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
|
-
fetchBai(opts = {}) {
|
|
44
|
-
if (!this.baiP) {
|
|
45
|
-
this.baiP = this.filehandle.readFile(opts).catch(e => {
|
|
46
|
-
this.baiP = undefined;
|
|
47
|
-
throw e;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return this.baiP;
|
|
51
|
-
}
|
|
52
45
|
// fetch and parse the index
|
|
53
|
-
_parse() {
|
|
46
|
+
_parse(opts) {
|
|
54
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
56
|
-
const bytes = yield this.fetchBai();
|
|
48
|
+
const bytes = (yield this.filehandle.readFile(opts));
|
|
57
49
|
// check BAI magic numbers
|
|
58
50
|
if (bytes.readUInt32LE(0) !== BAI_MAGIC) {
|
|
59
51
|
throw new Error('Not a BAI file');
|
|
60
52
|
}
|
|
61
|
-
|
|
53
|
+
const refCount = bytes.readInt32LE(4);
|
|
62
54
|
const depth = 5;
|
|
63
55
|
const binLimit = ((1 << ((depth + 1) * 3)) - 1) / 7;
|
|
64
56
|
// read the indexes for each reference sequence
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
|
|
57
|
+
let curr = 8;
|
|
58
|
+
let firstDataLine;
|
|
59
|
+
const indices = new Array(refCount);
|
|
60
|
+
for (let i = 0; i < refCount; i++) {
|
|
68
61
|
// the binning index
|
|
69
|
-
const binCount = bytes.readInt32LE(
|
|
62
|
+
const binCount = bytes.readInt32LE(curr);
|
|
70
63
|
let stats;
|
|
71
|
-
|
|
64
|
+
curr += 4;
|
|
72
65
|
const binIndex = {};
|
|
73
66
|
for (let j = 0; j < binCount; j += 1) {
|
|
74
|
-
const bin = bytes.readUInt32LE(
|
|
75
|
-
|
|
67
|
+
const bin = bytes.readUInt32LE(curr);
|
|
68
|
+
curr += 4;
|
|
76
69
|
if (bin === binLimit + 1) {
|
|
77
|
-
|
|
78
|
-
stats =
|
|
79
|
-
|
|
70
|
+
curr += 4;
|
|
71
|
+
stats = (0, util_1.parsePseudoBin)(bytes, curr + 16);
|
|
72
|
+
curr += 32;
|
|
80
73
|
}
|
|
81
74
|
else if (bin > binLimit + 1) {
|
|
82
75
|
throw new Error('bai index contains too many bins, please use CSI');
|
|
83
76
|
}
|
|
84
77
|
else {
|
|
85
|
-
const chunkCount = bytes.readInt32LE(
|
|
86
|
-
|
|
78
|
+
const chunkCount = bytes.readInt32LE(curr);
|
|
79
|
+
curr += 4;
|
|
87
80
|
const chunks = new Array(chunkCount);
|
|
88
|
-
for (let k = 0; k < chunkCount; k
|
|
89
|
-
const u = (0, virtualOffset_1.fromBytes)(bytes,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
for (let k = 0; k < chunkCount; k++) {
|
|
82
|
+
const u = (0, virtualOffset_1.fromBytes)(bytes, curr);
|
|
83
|
+
curr += 8;
|
|
84
|
+
const v = (0, virtualOffset_1.fromBytes)(bytes, curr);
|
|
85
|
+
curr += 8;
|
|
86
|
+
firstDataLine = (0, util_1.findFirstData)(firstDataLine, u);
|
|
93
87
|
chunks[k] = new chunk_1.default(u, v, bin);
|
|
94
88
|
}
|
|
95
89
|
binIndex[bin] = chunks;
|
|
96
90
|
}
|
|
97
91
|
}
|
|
98
|
-
const linearCount = bytes.readInt32LE(
|
|
99
|
-
|
|
100
|
-
// as we're going through the linear index, figure out
|
|
101
|
-
//
|
|
102
|
-
//
|
|
92
|
+
const linearCount = bytes.readInt32LE(curr);
|
|
93
|
+
curr += 4;
|
|
94
|
+
// as we're going through the linear index, figure out the smallest
|
|
95
|
+
// virtual offset in the indexes, which tells us where the BAM header
|
|
96
|
+
// ends
|
|
103
97
|
const linearIndex = new Array(linearCount);
|
|
104
|
-
for (let
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
for (let j = 0; j < linearCount; j++) {
|
|
99
|
+
const offset = (0, virtualOffset_1.fromBytes)(bytes, curr);
|
|
100
|
+
curr += 8;
|
|
101
|
+
firstDataLine = (0, util_1.findFirstData)(firstDataLine, offset);
|
|
102
|
+
linearIndex[j] = offset;
|
|
108
103
|
}
|
|
109
|
-
|
|
104
|
+
indices[i] = { binIndex, linearIndex, stats };
|
|
110
105
|
}
|
|
111
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
bai: true,
|
|
108
|
+
firstDataLine,
|
|
109
|
+
maxBlockSize: 1 << 16,
|
|
110
|
+
indices,
|
|
111
|
+
refCount,
|
|
112
|
+
};
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
indexCov(seqId, start, end, opts = {}) {
|
|
@@ -121,18 +122,14 @@ class BAI extends indexFile_1.default {
|
|
|
121
122
|
return [];
|
|
122
123
|
}
|
|
123
124
|
const { linearIndex = [], stats } = seqIdx;
|
|
124
|
-
if (
|
|
125
|
+
if (linearIndex.length === 0) {
|
|
125
126
|
return [];
|
|
126
127
|
}
|
|
127
|
-
const e = end
|
|
128
|
-
const s = start
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
depths = new Array(linearIndex.length - 1);
|
|
135
|
-
}
|
|
128
|
+
const e = end === undefined ? (linearIndex.length - 1) * v : roundUp(end, v);
|
|
129
|
+
const s = start === undefined ? 0 : roundDown(start, v);
|
|
130
|
+
const depths = range
|
|
131
|
+
? new Array((e - s) / v)
|
|
132
|
+
: new Array(linearIndex.length - 1);
|
|
136
133
|
const totalSize = linearIndex[linearIndex.length - 1].blockPosition;
|
|
137
134
|
if (e > (linearIndex.length - 1) * v) {
|
|
138
135
|
throw new Error('query outside of range of linear index');
|
|
@@ -146,26 +143,9 @@ class BAI extends indexFile_1.default {
|
|
|
146
143
|
};
|
|
147
144
|
currentPos = linearIndex[i + 1].blockPosition;
|
|
148
145
|
}
|
|
149
|
-
return depths.map(d => {
|
|
150
|
-
return Object.assign(Object.assign({}, d), { score: (d.score * stats.lineCount) / totalSize });
|
|
151
|
-
});
|
|
146
|
+
return depths.map(d => (Object.assign(Object.assign({}, d), { score: (d.score * ((stats === null || stats === void 0 ? void 0 : stats.lineCount) || 0)) / totalSize })));
|
|
152
147
|
});
|
|
153
148
|
}
|
|
154
|
-
/**
|
|
155
|
-
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
|
|
156
|
-
* @returns {Array[number]}
|
|
157
|
-
*/
|
|
158
|
-
reg2bins(beg, end) {
|
|
159
|
-
end -= 1;
|
|
160
|
-
return [
|
|
161
|
-
[0, 0],
|
|
162
|
-
[1 + (beg >> 26), 1 + (end >> 26)],
|
|
163
|
-
[9 + (beg >> 23), 9 + (end >> 23)],
|
|
164
|
-
[73 + (beg >> 20), 73 + (end >> 20)],
|
|
165
|
-
[585 + (beg >> 17), 585 + (end >> 17)],
|
|
166
|
-
[4681 + (beg >> 14), 4681 + (end >> 14)],
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
149
|
blocksForRange(refId, min, max, opts = {}) {
|
|
170
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
151
|
if (min < 0) {
|
|
@@ -180,15 +160,15 @@ class BAI extends indexFile_1.default {
|
|
|
180
160
|
return [];
|
|
181
161
|
}
|
|
182
162
|
// List of bin #s that overlap min, max
|
|
183
|
-
const overlappingBins =
|
|
163
|
+
const overlappingBins = reg2bins(min, max);
|
|
184
164
|
const chunks = [];
|
|
185
165
|
// Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned
|
|
186
166
|
for (const [start, end] of overlappingBins) {
|
|
187
167
|
for (let bin = start; bin <= end; bin++) {
|
|
188
168
|
if (ba.binIndex[bin]) {
|
|
189
169
|
const binChunks = ba.binIndex[bin];
|
|
190
|
-
for (
|
|
191
|
-
chunks.push(
|
|
170
|
+
for (const binChunk of binChunks) {
|
|
171
|
+
chunks.push(binChunk);
|
|
192
172
|
}
|
|
193
173
|
}
|
|
194
174
|
}
|
|
@@ -196,20 +176,36 @@ class BAI extends indexFile_1.default {
|
|
|
196
176
|
// Use the linear index to find minimum file position of chunks that could
|
|
197
177
|
// contain alignments in the region
|
|
198
178
|
const nintv = ba.linearIndex.length;
|
|
199
|
-
let lowest
|
|
179
|
+
let lowest;
|
|
200
180
|
const minLin = Math.min(min >> 14, nintv - 1);
|
|
201
181
|
const maxLin = Math.min(max >> 14, nintv - 1);
|
|
202
182
|
for (let i = minLin; i <= maxLin; ++i) {
|
|
203
183
|
const vp = ba.linearIndex[i];
|
|
204
|
-
if (vp) {
|
|
205
|
-
|
|
206
|
-
lowest = vp;
|
|
207
|
-
}
|
|
184
|
+
if (vp && (!lowest || vp.compareTo(lowest) < 0)) {
|
|
185
|
+
lowest = vp;
|
|
208
186
|
}
|
|
209
187
|
}
|
|
210
188
|
return (0, util_1.optimizeChunks)(chunks, lowest);
|
|
211
189
|
});
|
|
212
190
|
}
|
|
191
|
+
parse(opts = {}) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
if (!this.setupP) {
|
|
194
|
+
this.setupP = this._parse(opts).catch(e => {
|
|
195
|
+
this.setupP = undefined;
|
|
196
|
+
throw e;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return this.setupP;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
hasRefSeq(seqId, opts = {}) {
|
|
203
|
+
var _a;
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const header = yield this.parse(opts);
|
|
206
|
+
return !!((_a = header.indices[seqId]) === null || _a === void 0 ? void 0 : _a.binIndex);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
213
209
|
}
|
|
214
210
|
exports.default = BAI;
|
|
215
211
|
//# sourceMappingURL=bai.js.map
|
package/dist/bai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bai.js","sourceRoot":"","sources":["../src/bai.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"bai.js","sourceRoot":"","sources":["../src/bai.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mDAA0D;AAC1D,oDAA2B;AAE3B,iCAAgF;AAChF,4DAAmC;AAEnC,MAAM,SAAS,GAAG,QAAQ,CAAA,CAAC,QAAQ;AAEnC,SAAS,SAAS,CAAC,CAAS,EAAE,QAAgB;IAC5C,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAA;AAC3B,CAAC;AACD,SAAS,OAAO,CAAC,CAAS,EAAE,QAAgB;IAC1C,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAA;AACtC,CAAC;AAED,SAAS,QAAQ,CAAC,GAAW,EAAE,GAAW;IACxC,GAAG,IAAI,CAAC,CAAA;IACR,OAAO;QACL,CA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AC7B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;oBACxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;oBACvB,MAAM,CAAC,CAAA;gBACT,CAAC,CAAC,CAAA;aACH;YACD,OAAO,IAAI,CAAC,MAAM,CAAA;QACpB,CAAC;KAAA;IAEK,SAAS,CAAC,KAAa,EAAE,OAAiB,EAAE;;;YAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACrC,OAAO,CAAC,CAAC,CAAA,MAAA,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,0CAAE,QAAQ,CAAA,CAAA;;KACzC;CACF;AApMD,sBAoMC"}
|
package/dist/bamFile.d.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
2
3
|
import { GenericFilehandle } from 'generic-filehandle';
|
|
4
|
+
import BAI from './bai';
|
|
5
|
+
import CSI from './csi';
|
|
3
6
|
import Chunk from './chunk';
|
|
4
7
|
import BAMFeature from './record';
|
|
5
8
|
import { BamOpts, BaseOpts } from './util';
|
|
6
9
|
export declare const BAM_MAGIC = 21840194;
|
|
7
10
|
export default class BamFile {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
renameRefSeq: (a: string) => string;
|
|
12
|
+
bam: GenericFilehandle;
|
|
13
|
+
header?: string;
|
|
14
|
+
chrToIndex?: Record<string, number>;
|
|
15
|
+
indexToChr?: {
|
|
16
|
+
refName: string;
|
|
17
|
+
length: number;
|
|
18
|
+
}[];
|
|
19
|
+
yieldThreadTime: number;
|
|
20
|
+
index?: BAI | CSI;
|
|
21
|
+
htsget: boolean;
|
|
22
|
+
headerP?: ReturnType<BamFile['getHeaderPre']>;
|
|
17
23
|
private featureCache;
|
|
18
|
-
|
|
19
|
-
* @param {object} args
|
|
20
|
-
* @param {string} [args.bamPath]
|
|
21
|
-
* @param {FileHandle} [args.bamFilehandle]
|
|
22
|
-
* @param {string} [args.baiPath]
|
|
23
|
-
* @param {FileHandle} [args.baiFilehandle]
|
|
24
|
-
*/
|
|
25
|
-
constructor({ bamFilehandle, bamPath, bamUrl, baiPath, baiFilehandle, baiUrl, csiPath, csiFilehandle, csiUrl, fetchSizeLimit, chunkSizeLimit, yieldThreadTime, renameRefSeqs, }: {
|
|
24
|
+
constructor({ bamFilehandle, bamPath, bamUrl, baiPath, baiFilehandle, baiUrl, csiPath, csiFilehandle, csiUrl, htsget, yieldThreadTime, renameRefSeqs, }: {
|
|
26
25
|
bamFilehandle?: GenericFilehandle;
|
|
27
26
|
bamPath?: string;
|
|
28
27
|
bamUrl?: string;
|
|
@@ -32,19 +31,25 @@ export default class BamFile {
|
|
|
32
31
|
csiPath?: string;
|
|
33
32
|
csiFilehandle?: GenericFilehandle;
|
|
34
33
|
csiUrl?: string;
|
|
35
|
-
fetchSizeLimit?: number;
|
|
36
|
-
chunkSizeLimit?: number;
|
|
37
34
|
renameRefSeqs?: (a: string) => string;
|
|
38
35
|
yieldThreadTime?: number;
|
|
36
|
+
htsget?: boolean;
|
|
39
37
|
});
|
|
40
|
-
|
|
38
|
+
getHeaderPre(origOpts?: BaseOpts): Promise<{
|
|
41
39
|
tag: string;
|
|
42
40
|
data: {
|
|
43
41
|
tag: string;
|
|
44
42
|
value: string;
|
|
45
43
|
}[];
|
|
46
|
-
}[]>;
|
|
47
|
-
|
|
44
|
+
}[] | undefined>;
|
|
45
|
+
getHeader(opts?: BaseOpts): Promise<{
|
|
46
|
+
tag: string;
|
|
47
|
+
data: {
|
|
48
|
+
tag: string;
|
|
49
|
+
value: string;
|
|
50
|
+
}[];
|
|
51
|
+
}[] | undefined>;
|
|
52
|
+
getHeaderText(opts?: BaseOpts): Promise<string | undefined>;
|
|
48
53
|
_readRefSeqs(start: number, refSeqBytes: number, opts?: BaseOpts): Promise<{
|
|
49
54
|
chrToIndex: {
|
|
50
55
|
[key: string]: number;
|
|
@@ -56,19 +61,20 @@ export default class BamFile {
|
|
|
56
61
|
}>;
|
|
57
62
|
getRecordsForRange(chr: string, min: number, max: number, opts?: BamOpts): Promise<BAMFeature[]>;
|
|
58
63
|
streamRecordsForRange(chr: string, min: number, max: number, opts?: BamOpts): AsyncGenerator<BAMFeature[], void, unknown>;
|
|
59
|
-
_fetchChunkFeatures(chunks: Chunk[], chrId: number, min: number, max: number, opts
|
|
64
|
+
_fetchChunkFeatures(chunks: Chunk[], chrId: number, min: number, max: number, opts?: BamOpts): AsyncGenerator<BAMFeature[], void, unknown>;
|
|
60
65
|
fetchPairs(chrId: number, feats: BAMFeature[][], opts: BamOpts): Promise<BAMFeature[]>;
|
|
66
|
+
_readRegion(position: number, size: number, opts?: BaseOpts): Promise<Buffer>;
|
|
61
67
|
_readChunk({ chunk, opts }: {
|
|
62
68
|
chunk: Chunk;
|
|
63
69
|
opts: BaseOpts;
|
|
64
70
|
}): Promise<{
|
|
65
|
-
data:
|
|
66
|
-
cpositions:
|
|
67
|
-
dpositions:
|
|
71
|
+
data: Buffer;
|
|
72
|
+
cpositions: number[];
|
|
73
|
+
dpositions: number[];
|
|
68
74
|
chunk: Chunk;
|
|
69
75
|
}>;
|
|
70
76
|
readBamFeatures(ba: Buffer, cpositions: number[], dpositions: number[], chunk: Chunk): Promise<BAMFeature[]>;
|
|
71
|
-
hasRefSeq(seqName: string): Promise<boolean>;
|
|
77
|
+
hasRefSeq(seqName: string): Promise<boolean | undefined>;
|
|
72
78
|
lineCount(seqName: string): Promise<number>;
|
|
73
79
|
indexCov(seqName: string, start?: number, end?: number): Promise<{
|
|
74
80
|
start: number;
|