@gmod/bam 1.1.18 → 2.0.1
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 +66 -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 +132 -130
- 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 +75 -49
- 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 -25
- package/dist/record.js.map +1 -1
- package/dist/sam.js +11 -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/dist/virtualOffset.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 -25
- package/esm/record.js.map +1 -1
- package/esm/sam.js +11 -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/esm/virtualOffset.js.map +1 -1
- package/package.json +19 -21
- 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 -25
- package/src/sam.ts +11 -7
- package/src/util.ts +54 -13
- package/src/declare.d.ts +0 -2
package/dist/csi.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import VirtualOffset from './virtualOffset';
|
|
2
3
|
import Chunk from './chunk';
|
|
3
4
|
import { BaseOpts } from './util';
|
|
4
5
|
import IndexFile from './indexFile';
|
|
@@ -6,30 +7,93 @@ export default class CSI extends IndexFile {
|
|
|
6
7
|
private maxBinNumber;
|
|
7
8
|
private depth;
|
|
8
9
|
private minShift;
|
|
9
|
-
|
|
10
|
-
lineCount(refId: number): Promise<number>;
|
|
10
|
+
setupP?: ReturnType<CSI['_parse']>;
|
|
11
|
+
lineCount(refId: number, opts?: BaseOpts): Promise<number>;
|
|
11
12
|
indexCov(): Promise<never[]>;
|
|
12
|
-
parseAuxData(bytes: Buffer, offset: number
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
};
|
|
15
|
-
_parseNameBytes(namesBytes: Buffer): {
|
|
13
|
+
parseAuxData(bytes: Buffer, offset: number): {
|
|
16
14
|
refNameToId: {
|
|
17
15
|
[key: string]: number;
|
|
18
16
|
};
|
|
19
17
|
refIdToName: string[];
|
|
18
|
+
columnNumbers: {
|
|
19
|
+
ref: number;
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
};
|
|
23
|
+
coordinateType: string;
|
|
24
|
+
metaValue: number;
|
|
25
|
+
metaChar: string;
|
|
26
|
+
skipLines: number;
|
|
27
|
+
format: string;
|
|
28
|
+
formatFlags: number;
|
|
20
29
|
};
|
|
21
30
|
_parse(opts: {
|
|
22
31
|
signal?: AbortSignal;
|
|
23
32
|
}): Promise<{
|
|
24
|
-
|
|
33
|
+
refNameToId?: {
|
|
34
|
+
[key: string]: number;
|
|
35
|
+
} | undefined;
|
|
36
|
+
refIdToName?: string[] | undefined;
|
|
37
|
+
columnNumbers?: {
|
|
38
|
+
ref: number;
|
|
39
|
+
start: number;
|
|
40
|
+
end: number;
|
|
41
|
+
} | undefined;
|
|
42
|
+
coordinateType?: string | undefined;
|
|
43
|
+
metaValue?: number | undefined;
|
|
44
|
+
metaChar?: string | undefined;
|
|
45
|
+
skipLines?: number | undefined;
|
|
46
|
+
format?: string | undefined;
|
|
47
|
+
formatFlags?: number | undefined;
|
|
48
|
+
csiVersion: number;
|
|
49
|
+
firstDataLine: VirtualOffset | undefined;
|
|
50
|
+
indices: {
|
|
51
|
+
binIndex: {
|
|
52
|
+
[key: string]: Chunk[];
|
|
53
|
+
};
|
|
54
|
+
stats?: {
|
|
55
|
+
lineCount: number;
|
|
56
|
+
} | undefined;
|
|
57
|
+
}[];
|
|
58
|
+
refCount: number;
|
|
59
|
+
csi: boolean;
|
|
60
|
+
maxBlockSize: number;
|
|
25
61
|
}>;
|
|
26
|
-
parsePseudoBin(bytes: Buffer, offset: number): {
|
|
27
|
-
lineCount: number;
|
|
28
|
-
};
|
|
29
62
|
blocksForRange(refId: number, min: number, max: number, opts?: BaseOpts): Promise<Chunk[]>;
|
|
30
63
|
/**
|
|
31
64
|
* calculate the list of bins that may overlap with region [beg,end)
|
|
32
65
|
* (zero-based half-open)
|
|
33
66
|
*/
|
|
34
67
|
reg2bins(beg: number, end: number): number[][];
|
|
68
|
+
parse(opts?: BaseOpts): Promise<{
|
|
69
|
+
refNameToId?: {
|
|
70
|
+
[key: string]: number;
|
|
71
|
+
} | undefined;
|
|
72
|
+
refIdToName?: string[] | undefined;
|
|
73
|
+
columnNumbers?: {
|
|
74
|
+
ref: number;
|
|
75
|
+
start: number;
|
|
76
|
+
end: number;
|
|
77
|
+
} | undefined;
|
|
78
|
+
coordinateType?: string | undefined;
|
|
79
|
+
metaValue?: number | undefined;
|
|
80
|
+
metaChar?: string | undefined;
|
|
81
|
+
skipLines?: number | undefined;
|
|
82
|
+
format?: string | undefined;
|
|
83
|
+
formatFlags?: number | undefined;
|
|
84
|
+
csiVersion: number;
|
|
85
|
+
firstDataLine: VirtualOffset | undefined;
|
|
86
|
+
indices: {
|
|
87
|
+
binIndex: {
|
|
88
|
+
[key: string]: Chunk[];
|
|
89
|
+
};
|
|
90
|
+
stats?: {
|
|
91
|
+
lineCount: number;
|
|
92
|
+
} | undefined;
|
|
93
|
+
}[];
|
|
94
|
+
refCount: number;
|
|
95
|
+
csi: boolean;
|
|
96
|
+
maxBlockSize: number;
|
|
97
|
+
}>;
|
|
98
|
+
hasRefSeq(seqId: number, opts?: BaseOpts): Promise<boolean>;
|
|
35
99
|
}
|
package/dist/csi.js
CHANGED
|
@@ -35,7 +35,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const long_1 = __importDefault(require("long"));
|
|
39
38
|
const bgzf_filehandle_1 = require("@gmod/bgzf-filehandle");
|
|
40
39
|
const virtualOffset_1 = __importStar(require("./virtualOffset"));
|
|
41
40
|
const chunk_1 = __importDefault(require("./chunk"));
|
|
@@ -50,27 +49,17 @@ function rshift(num, bits) {
|
|
|
50
49
|
return Math.floor(num / Math.pow(2, bits));
|
|
51
50
|
}
|
|
52
51
|
class CSI extends indexFile_1.default {
|
|
53
|
-
constructor(
|
|
54
|
-
super(
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
55
54
|
this.maxBinNumber = 0;
|
|
56
55
|
this.depth = 0;
|
|
57
56
|
this.minShift = 0;
|
|
58
57
|
}
|
|
59
|
-
lineCount(refId) {
|
|
58
|
+
lineCount(refId, opts) {
|
|
59
|
+
var _a, _b;
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const indexData = yield this.parse();
|
|
62
|
-
|
|
63
|
-
return -1;
|
|
64
|
-
}
|
|
65
|
-
const idx = indexData.indices[refId];
|
|
66
|
-
if (!idx) {
|
|
67
|
-
return -1;
|
|
68
|
-
}
|
|
69
|
-
const { stats } = indexData.indices[refId];
|
|
70
|
-
if (stats) {
|
|
71
|
-
return stats.lineCount;
|
|
72
|
-
}
|
|
73
|
-
return -1;
|
|
61
|
+
const indexData = yield this.parse(opts);
|
|
62
|
+
return ((_b = (_a = indexData.indices[refId]) === null || _a === void 0 ? void 0 : _a.stats) === null || _b === void 0 ? void 0 : _b.lineCount) || 0;
|
|
74
63
|
});
|
|
75
64
|
}
|
|
76
65
|
indexCov() {
|
|
@@ -78,61 +67,42 @@ class CSI extends indexFile_1.default {
|
|
|
78
67
|
return [];
|
|
79
68
|
});
|
|
80
69
|
}
|
|
81
|
-
parseAuxData(bytes, offset
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
data.coordinateType =
|
|
88
|
-
data.formatFlags & 0x10000 ? 'zero-based-half-open' : '1-based-closed';
|
|
89
|
-
data.format = { 0: 'generic', 1: 'SAM', 2: 'VCF' }[data.formatFlags & 0xf];
|
|
90
|
-
if (!data.format) {
|
|
91
|
-
throw new Error(`invalid Tabix preset format flags ${data.formatFlags}`);
|
|
70
|
+
parseAuxData(bytes, offset) {
|
|
71
|
+
const formatFlags = bytes.readInt32LE(offset);
|
|
72
|
+
const coordinateType = formatFlags & 0x10000 ? 'zero-based-half-open' : '1-based-closed';
|
|
73
|
+
const format = { 0: 'generic', 1: 'SAM', 2: 'VCF' }[formatFlags & 0xf];
|
|
74
|
+
if (!format) {
|
|
75
|
+
throw new Error(`invalid Tabix preset format flags ${formatFlags}`);
|
|
92
76
|
}
|
|
93
|
-
|
|
77
|
+
const columnNumbers = {
|
|
94
78
|
ref: bytes.readInt32LE(offset + 4),
|
|
95
79
|
start: bytes.readInt32LE(offset + 8),
|
|
96
80
|
end: bytes.readInt32LE(offset + 12),
|
|
97
81
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
const metaValue = bytes.readInt32LE(offset + 16);
|
|
83
|
+
const metaChar = metaValue ? String.fromCharCode(metaValue) : '';
|
|
84
|
+
const skipLines = bytes.readInt32LE(offset + 20);
|
|
101
85
|
const nameSectionLength = bytes.readInt32LE(offset + 24);
|
|
102
|
-
Object.assign(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const refNameToId = {};
|
|
110
|
-
for (let i = 0; i < namesBytes.length; i += 1) {
|
|
111
|
-
if (!namesBytes[i]) {
|
|
112
|
-
if (currNameStart < i) {
|
|
113
|
-
let refName = namesBytes.toString('utf8', currNameStart, i);
|
|
114
|
-
refName = this.renameRefSeq(refName);
|
|
115
|
-
refIdToName[currRefId] = refName;
|
|
116
|
-
refNameToId[refName] = currRefId;
|
|
117
|
-
}
|
|
118
|
-
currNameStart = i + 1;
|
|
119
|
-
currRefId += 1;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return { refNameToId, refIdToName };
|
|
86
|
+
return Object.assign({ columnNumbers,
|
|
87
|
+
coordinateType,
|
|
88
|
+
metaValue,
|
|
89
|
+
metaChar,
|
|
90
|
+
skipLines,
|
|
91
|
+
format,
|
|
92
|
+
formatFlags }, (0, util_1.parseNameBytes)(bytes.subarray(offset + 28, offset + 28 + nameSectionLength), this.renameRefSeq));
|
|
123
93
|
}
|
|
124
94
|
// fetch and parse the index
|
|
125
95
|
_parse(opts) {
|
|
126
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const
|
|
128
|
-
const buffer = (yield this.filehandle.readFile(opts));
|
|
97
|
+
const buffer = yield this.filehandle.readFile(opts);
|
|
129
98
|
const bytes = yield (0, bgzf_filehandle_1.unzip)(buffer);
|
|
99
|
+
let csiVersion;
|
|
130
100
|
// check TBI magic numbers
|
|
131
101
|
if (bytes.readUInt32LE(0) === CSI1_MAGIC) {
|
|
132
|
-
|
|
102
|
+
csiVersion = 1;
|
|
133
103
|
}
|
|
134
104
|
else if (bytes.readUInt32LE(0) === CSI2_MAGIC) {
|
|
135
|
-
|
|
105
|
+
csiVersion = 2;
|
|
136
106
|
}
|
|
137
107
|
else {
|
|
138
108
|
throw new Error('Not a CSI file');
|
|
@@ -142,53 +112,50 @@ class CSI extends indexFile_1.default {
|
|
|
142
112
|
this.depth = bytes.readInt32LE(8);
|
|
143
113
|
this.maxBinNumber = ((1 << ((this.depth + 1) * 3)) - 1) / 7;
|
|
144
114
|
const auxLength = bytes.readInt32LE(12);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
data.refCount = bytes.readInt32LE(16 + auxLength);
|
|
115
|
+
const aux = auxLength >= 30 ? this.parseAuxData(bytes, 16) : undefined;
|
|
116
|
+
const refCount = bytes.readInt32LE(16 + auxLength);
|
|
149
117
|
// read the indexes for each reference sequence
|
|
150
|
-
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
|
|
118
|
+
let curr = 16 + auxLength + 4;
|
|
119
|
+
let firstDataLine;
|
|
120
|
+
const indices = new Array(refCount);
|
|
121
|
+
for (let i = 0; i < refCount; i++) {
|
|
154
122
|
// the binning index
|
|
155
|
-
const binCount = bytes.readInt32LE(
|
|
156
|
-
|
|
123
|
+
const binCount = bytes.readInt32LE(curr);
|
|
124
|
+
curr += 4;
|
|
157
125
|
const binIndex = {};
|
|
158
126
|
let stats; // < provided by parsing a pseudo-bin, if present
|
|
159
|
-
for (let j = 0; j < binCount; j
|
|
160
|
-
const bin = bytes.readUInt32LE(
|
|
127
|
+
for (let j = 0; j < binCount; j++) {
|
|
128
|
+
const bin = bytes.readUInt32LE(curr);
|
|
129
|
+
curr += 4;
|
|
161
130
|
if (bin > this.maxBinNumber) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
stats = this.parsePseudoBin(bytes, currOffset + 4);
|
|
165
|
-
currOffset += 4 + 8 + 4 + 16 + 16;
|
|
131
|
+
stats = (0, util_1.parsePseudoBin)(bytes, curr + 28);
|
|
132
|
+
curr += 28 + 16;
|
|
166
133
|
}
|
|
167
134
|
else {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const chunkCount = bytes.readInt32LE(
|
|
171
|
-
|
|
135
|
+
firstDataLine = (0, util_1.findFirstData)(firstDataLine, (0, virtualOffset_1.fromBytes)(bytes, curr));
|
|
136
|
+
curr += 8;
|
|
137
|
+
const chunkCount = bytes.readInt32LE(curr);
|
|
138
|
+
curr += 4;
|
|
172
139
|
const chunks = new Array(chunkCount);
|
|
173
140
|
for (let k = 0; k < chunkCount; k += 1) {
|
|
174
|
-
const u = (0, virtualOffset_1.fromBytes)(bytes,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
141
|
+
const u = (0, virtualOffset_1.fromBytes)(bytes, curr);
|
|
142
|
+
curr += 8;
|
|
143
|
+
const v = (0, virtualOffset_1.fromBytes)(bytes, curr);
|
|
144
|
+
curr += 8;
|
|
145
|
+
firstDataLine = (0, util_1.findFirstData)(firstDataLine, u);
|
|
178
146
|
chunks[k] = new chunk_1.default(u, v, bin);
|
|
179
147
|
}
|
|
180
148
|
binIndex[bin] = chunks;
|
|
181
149
|
}
|
|
182
150
|
}
|
|
183
|
-
|
|
151
|
+
indices[i] = { binIndex, stats };
|
|
184
152
|
}
|
|
185
|
-
return
|
|
153
|
+
return Object.assign({ csiVersion,
|
|
154
|
+
firstDataLine,
|
|
155
|
+
indices,
|
|
156
|
+
refCount, csi: true, maxBlockSize: 1 << 16 }, aux);
|
|
186
157
|
});
|
|
187
158
|
}
|
|
188
|
-
parsePseudoBin(bytes, offset) {
|
|
189
|
-
const lineCount = (0, util_1.longToNumber)(long_1.default.fromBytesLE(Array.prototype.slice.call(bytes, offset + 28, offset + 36), true));
|
|
190
|
-
return { lineCount };
|
|
191
|
-
}
|
|
192
159
|
blocksForRange(refId, min, max, opts = {}) {
|
|
193
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
161
|
if (min < 0) {
|
|
@@ -199,15 +166,18 @@ class CSI extends indexFile_1.default {
|
|
|
199
166
|
if (!ba) {
|
|
200
167
|
return [];
|
|
201
168
|
}
|
|
202
|
-
const overlappingBins = this.reg2bins(min, max);
|
|
169
|
+
const overlappingBins = this.reg2bins(min, max);
|
|
170
|
+
if (overlappingBins.length === 0) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
203
173
|
const chunks = [];
|
|
204
174
|
// Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned
|
|
205
175
|
for (const [start, end] of overlappingBins) {
|
|
206
176
|
for (let bin = start; bin <= end; bin++) {
|
|
207
177
|
if (ba.binIndex[bin]) {
|
|
208
178
|
const binChunks = ba.binIndex[bin];
|
|
209
|
-
for (
|
|
210
|
-
chunks.push(
|
|
179
|
+
for (const c of binChunks) {
|
|
180
|
+
chunks.push(c);
|
|
211
181
|
}
|
|
212
182
|
}
|
|
213
183
|
}
|
|
@@ -242,6 +212,24 @@ class CSI extends indexFile_1.default {
|
|
|
242
212
|
}
|
|
243
213
|
return bins;
|
|
244
214
|
}
|
|
215
|
+
parse(opts = {}) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
if (!this.setupP) {
|
|
218
|
+
this.setupP = this._parse(opts).catch(e => {
|
|
219
|
+
this.setupP = undefined;
|
|
220
|
+
throw e;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return this.setupP;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
hasRefSeq(seqId, opts = {}) {
|
|
227
|
+
var _a;
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const header = yield this.parse(opts);
|
|
230
|
+
return !!((_a = header.indices[seqId]) === null || _a === void 0 ? void 0 : _a.binIndex);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
245
233
|
}
|
|
246
234
|
exports.default = CSI;
|
|
247
235
|
//# sourceMappingURL=csi.js.map
|
package/dist/csi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csi.js","sourceRoot":"","sources":["../src/csi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"csi.js","sourceRoot":"","sources":["../src/csi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAC7C,iEAA0D;AAC1D,oDAA2B;AAC3B,iCAMe;AAEf,4DAAmC;AAEnC,MAAM,UAAU,GAAG,QAAQ,CAAA,CAAC,QAAQ;AACpC,MAAM,UAAU,GAAG,QAAQ,CAAA,CAAC,QAAQ;AAEpC,SAAS,MAAM,CAAC,GAAW,EAAE,IAAY;IACvC,OAAO,GAAG,GAAG,SAAA,CAAC,EAAI,IAAI,CAAA,CAAA;AACxB,CAAC;AACD,SAAS,MAAM,CAAC,GAAW,EAAE,IAAY;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,SAAA,CAAC,EAAI,IAAI,CAAA,CAAC,CAAA;AACpC,CAAC;AAED,MAAqB,GAAI,SAAQ,mBAAS;IAA1C;;QACU,iBAAY,GAAG,CA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AA;YACJ,CAAC;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;AAlND,sBAkNC"}
|
package/dist/htsget.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
2
3
|
import { BaseOpts, BamOpts } from './util';
|
|
3
4
|
import BamFile from './bamFile';
|
|
4
|
-
import 'cross-fetch/polyfill';
|
|
5
5
|
import Chunk from './chunk';
|
|
6
6
|
export default class HtsgetFile extends BamFile {
|
|
7
7
|
private baseUrl;
|
|
@@ -11,16 +11,13 @@ export default class HtsgetFile extends BamFile {
|
|
|
11
11
|
baseUrl: string;
|
|
12
12
|
});
|
|
13
13
|
streamRecordsForRange(chr: string, min: number, max: number, opts?: BamOpts): AsyncGenerator<import("./record").default[], void, unknown>;
|
|
14
|
-
_readChunk(
|
|
15
|
-
chunk:
|
|
16
|
-
buffer: Buffer;
|
|
17
|
-
chunk: Chunk;
|
|
18
|
-
};
|
|
14
|
+
_readChunk({ chunk }: {
|
|
15
|
+
chunk: Chunk;
|
|
19
16
|
opts: BaseOpts;
|
|
20
17
|
}): Promise<{
|
|
21
18
|
data: Buffer;
|
|
22
|
-
cpositions:
|
|
23
|
-
dpositions:
|
|
19
|
+
cpositions: never[];
|
|
20
|
+
dpositions: never[];
|
|
24
21
|
chunk: Chunk;
|
|
25
22
|
}>;
|
|
26
23
|
getHeader(opts?: BaseOpts): Promise<{
|
package/dist/htsget.js
CHANGED
|
@@ -53,13 +53,14 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
53
53
|
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
54
54
|
var i, p;
|
|
55
55
|
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
56
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done:
|
|
56
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
57
57
|
};
|
|
58
58
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
59
59
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
60
60
|
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
61
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
62
|
-
function
|
|
61
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
62
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
63
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
63
64
|
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
64
65
|
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
65
66
|
function fulfill(value) { resume("next", value); }
|
|
@@ -67,72 +68,93 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
67
68
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
68
69
|
};
|
|
69
70
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
-
const bamFile_1 = __importStar(require("./bamFile"));
|
|
71
|
-
require("cross-fetch/polyfill");
|
|
72
71
|
const bgzf_filehandle_1 = require("@gmod/bgzf-filehandle");
|
|
72
|
+
const buffer_1 = require("buffer");
|
|
73
|
+
const bamFile_1 = __importStar(require("./bamFile"));
|
|
73
74
|
const sam_1 = require("./sam");
|
|
74
75
|
function concat(arr, opts) {
|
|
75
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
77
|
const res = yield Promise.all(arr.map((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
77
78
|
const { url, headers } = chunk;
|
|
78
79
|
if (url.startsWith('data:')) {
|
|
79
|
-
return Buffer.from(url.split(',')[1], 'base64');
|
|
80
|
+
return buffer_1.Buffer.from(url.split(',')[1], 'base64');
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
83
|
//remove referer header, it is not even allowed to be specified
|
|
83
|
-
|
|
84
|
+
// @ts-expect-error
|
|
84
85
|
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
86
|
const { referer } = headers, rest = __rest(headers, ["referer"]);
|
|
86
|
-
const res = yield fetch(url, Object.assign(Object.assign({}, opts), { headers: Object.assign(Object.assign({}, opts.headers), rest) }));
|
|
87
|
+
const res = yield fetch(url, Object.assign(Object.assign({}, opts), { headers: Object.assign(Object.assign({}, opts === null || opts === void 0 ? void 0 : opts.headers), rest) }));
|
|
87
88
|
if (!res.ok) {
|
|
88
|
-
throw new Error(`
|
|
89
|
+
throw new Error(`HTTP ${res.status} fetching ${url}: ${yield res.text()}`);
|
|
89
90
|
}
|
|
90
|
-
return Buffer.from(yield res.arrayBuffer());
|
|
91
|
+
return buffer_1.Buffer.from(yield res.arrayBuffer());
|
|
91
92
|
}
|
|
92
93
|
})));
|
|
93
|
-
return Buffer.concat(yield Promise.all(res.map(elt => (0, bgzf_filehandle_1.unzip)(elt))));
|
|
94
|
+
return buffer_1.Buffer.concat(yield Promise.all(res.map(elt => (0, bgzf_filehandle_1.unzip)(elt))));
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
class HtsgetFile extends bamFile_1.default {
|
|
97
98
|
constructor(args) {
|
|
98
|
-
|
|
99
|
-
super({ bamFilehandle: '?', baiFilehandle: '?' });
|
|
99
|
+
super({ htsget: true });
|
|
100
100
|
this.baseUrl = args.baseUrl;
|
|
101
101
|
this.trackId = args.trackId;
|
|
102
102
|
}
|
|
103
|
-
streamRecordsForRange(chr, min, max, opts
|
|
104
|
-
|
|
105
|
-
pairAcrossChr: false,
|
|
106
|
-
maxInsertSize: 200000,
|
|
107
|
-
}) {
|
|
103
|
+
streamRecordsForRange(chr, min, max, opts) {
|
|
104
|
+
var _a;
|
|
108
105
|
return __asyncGenerator(this, arguments, function* streamRecordsForRange_1() {
|
|
109
106
|
const base = `${this.baseUrl}/${this.trackId}`;
|
|
110
107
|
const url = `${base}?referenceName=${chr}&start=${min}&end=${max}&format=BAM`;
|
|
111
|
-
const chrId = this.chrToIndex
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
const chrId = (_a = this.chrToIndex) === null || _a === void 0 ? void 0 : _a[chr];
|
|
109
|
+
if (chrId === undefined) {
|
|
110
|
+
yield yield __await([]);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const result = yield __await(fetch(url, Object.assign({}, opts)));
|
|
114
|
+
if (!result.ok) {
|
|
115
|
+
throw new Error(`HTTP ${result.status} fetching ${url}: ${yield __await(result.text())}`);
|
|
116
|
+
}
|
|
117
|
+
const data = yield __await(result.json());
|
|
118
|
+
const uncba = yield __await(concat(data.htsget.urls.slice(1), opts));
|
|
119
|
+
yield __await(yield* __asyncDelegator(__asyncValues(this._fetchChunkFeatures([
|
|
120
|
+
// fake stuff to pretend to be a Chunk
|
|
121
|
+
{
|
|
122
|
+
buffer: uncba,
|
|
123
|
+
_fetchedSize: undefined,
|
|
124
|
+
bin: 0,
|
|
125
|
+
compareTo() {
|
|
126
|
+
return 0;
|
|
127
|
+
},
|
|
128
|
+
toUniqueString() {
|
|
129
|
+
return `${chr}_${min}_${max}`;
|
|
130
|
+
},
|
|
131
|
+
fetchedSize() {
|
|
132
|
+
return 0;
|
|
133
|
+
},
|
|
134
|
+
minv: {
|
|
135
|
+
dataPosition: 0,
|
|
136
|
+
blockPosition: 0,
|
|
137
|
+
compareTo: () => 0,
|
|
138
|
+
},
|
|
139
|
+
maxv: {
|
|
140
|
+
dataPosition: Number.MAX_SAFE_INTEGER,
|
|
141
|
+
blockPosition: 0,
|
|
142
|
+
compareTo: () => 0,
|
|
143
|
+
},
|
|
144
|
+
toString() {
|
|
145
|
+
return `${chr}_${min}_${max}`;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
], chrId, min, max, opts))));
|
|
115
149
|
}
|
|
116
|
-
const data = yield __await(result.json());
|
|
117
|
-
const uncba = yield __await(concat(data.htsget.urls.slice(1), opts));
|
|
118
|
-
const chunk = {
|
|
119
|
-
buffer: uncba,
|
|
120
|
-
chunk: { minv: { dataPosition: 0 } },
|
|
121
|
-
toString() {
|
|
122
|
-
return `${chr}_${min}_${max}`;
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
yield __await(yield* __asyncDelegator(__asyncValues(this._fetchChunkFeatures(
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
[chunk], chrId, min, max, opts))));
|
|
128
150
|
});
|
|
129
151
|
}
|
|
130
|
-
|
|
131
|
-
_readChunk(params) {
|
|
152
|
+
_readChunk({ chunk }) {
|
|
132
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
if (!chunk.buffer) {
|
|
155
|
+
throw new Error('expected chunk.buffer in htsget');
|
|
156
|
+
}
|
|
157
|
+
return { data: chunk.buffer, cpositions: [], dpositions: [], chunk };
|
|
136
158
|
});
|
|
137
159
|
}
|
|
138
160
|
getHeader(opts = {}) {
|
|
@@ -140,7 +162,7 @@ class HtsgetFile extends bamFile_1.default {
|
|
|
140
162
|
const url = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`;
|
|
141
163
|
const result = yield fetch(url, opts);
|
|
142
164
|
if (!result.ok) {
|
|
143
|
-
throw new Error(`
|
|
165
|
+
throw new Error(`HTTP ${result.status} fetching ${url}: ${yield result.text()}`);
|
|
144
166
|
}
|
|
145
167
|
const data = yield result.json();
|
|
146
168
|
const uncba = yield concat(data.htsget.urls, opts);
|
|
@@ -154,17 +176,21 @@ class HtsgetFile extends bamFile_1.default {
|
|
|
154
176
|
// mapping between ref ref ID numbers and names
|
|
155
177
|
const idToName = [];
|
|
156
178
|
const nameToId = {};
|
|
157
|
-
const sqLines = samHeader.filter(
|
|
158
|
-
sqLines.
|
|
159
|
-
|
|
179
|
+
const sqLines = samHeader.filter(l => l.tag === 'SQ');
|
|
180
|
+
for (const [refId, sqLine] of sqLines.entries()) {
|
|
181
|
+
let refName = '';
|
|
182
|
+
let length = 0;
|
|
183
|
+
for (const item of sqLine.data) {
|
|
160
184
|
if (item.tag === 'SN') {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
185
|
+
refName = item.value;
|
|
186
|
+
}
|
|
187
|
+
else if (item.tag === 'LN') {
|
|
188
|
+
length = +item.value;
|
|
165
189
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
190
|
+
}
|
|
191
|
+
nameToId[refName] = refId;
|
|
192
|
+
idToName[refId] = { refName, length };
|
|
193
|
+
}
|
|
168
194
|
this.chrToIndex = nameToId;
|
|
169
195
|
this.indexToChr = idToName;
|
|
170
196
|
return samHeader;
|