@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/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,CAAC,CAAA;QAChB,UAAK,GAAG,CAAC,CAAA;QACT,aAAQ,G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|
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,7 +53,7 @@ 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.");
|
|
@@ -67,72 +67,93 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
67
67
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
68
68
|
};
|
|
69
69
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
-
const bamFile_1 = __importStar(require("./bamFile"));
|
|
71
|
-
require("cross-fetch/polyfill");
|
|
72
70
|
const bgzf_filehandle_1 = require("@gmod/bgzf-filehandle");
|
|
71
|
+
const buffer_1 = require("buffer");
|
|
72
|
+
const bamFile_1 = __importStar(require("./bamFile"));
|
|
73
73
|
const sam_1 = require("./sam");
|
|
74
74
|
function concat(arr, opts) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const res = yield Promise.all(arr.map((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
77
77
|
const { url, headers } = chunk;
|
|
78
78
|
if (url.startsWith('data:')) {
|
|
79
|
-
return Buffer.from(url.split(',')[1], 'base64');
|
|
79
|
+
return buffer_1.Buffer.from(url.split(',')[1], 'base64');
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
82
|
//remove referer header, it is not even allowed to be specified
|
|
83
|
-
|
|
83
|
+
// @ts-expect-error
|
|
84
84
|
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
85
|
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) }));
|
|
86
|
+
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
87
|
if (!res.ok) {
|
|
88
|
-
throw new Error(`
|
|
88
|
+
throw new Error(`HTTP ${res.status} fetching ${url}: ${yield res.text()}`);
|
|
89
89
|
}
|
|
90
|
-
return Buffer.from(yield res.arrayBuffer());
|
|
90
|
+
return buffer_1.Buffer.from(yield res.arrayBuffer());
|
|
91
91
|
}
|
|
92
92
|
})));
|
|
93
|
-
return Buffer.concat(yield Promise.all(res.map(elt => (0, bgzf_filehandle_1.unzip)(elt))));
|
|
93
|
+
return buffer_1.Buffer.concat(yield Promise.all(res.map(elt => (0, bgzf_filehandle_1.unzip)(elt))));
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
class HtsgetFile extends bamFile_1.default {
|
|
97
97
|
constructor(args) {
|
|
98
|
-
|
|
99
|
-
super({ bamFilehandle: '?', baiFilehandle: '?' });
|
|
98
|
+
super({ htsget: true });
|
|
100
99
|
this.baseUrl = args.baseUrl;
|
|
101
100
|
this.trackId = args.trackId;
|
|
102
101
|
}
|
|
103
|
-
streamRecordsForRange(chr, min, max, opts
|
|
104
|
-
|
|
105
|
-
pairAcrossChr: false,
|
|
106
|
-
maxInsertSize: 200000,
|
|
107
|
-
}) {
|
|
102
|
+
streamRecordsForRange(chr, min, max, opts) {
|
|
103
|
+
var _a;
|
|
108
104
|
return __asyncGenerator(this, arguments, function* streamRecordsForRange_1() {
|
|
109
105
|
const base = `${this.baseUrl}/${this.trackId}`;
|
|
110
106
|
const url = `${base}?referenceName=${chr}&start=${min}&end=${max}&format=BAM`;
|
|
111
|
-
const chrId = this.chrToIndex
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
const chrId = (_a = this.chrToIndex) === null || _a === void 0 ? void 0 : _a[chr];
|
|
108
|
+
if (chrId === undefined) {
|
|
109
|
+
yield yield __await([]);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const result = yield __await(fetch(url, Object.assign({}, opts)));
|
|
113
|
+
if (!result.ok) {
|
|
114
|
+
throw new Error(`HTTP ${result.status} fetching ${url}: ${yield __await(result.text())}`);
|
|
115
|
+
}
|
|
116
|
+
const data = yield __await(result.json());
|
|
117
|
+
const uncba = yield __await(concat(data.htsget.urls.slice(1), opts));
|
|
118
|
+
yield __await(yield* __asyncDelegator(__asyncValues(this._fetchChunkFeatures([
|
|
119
|
+
// fake stuff to pretend to be a Chunk
|
|
120
|
+
{
|
|
121
|
+
buffer: uncba,
|
|
122
|
+
_fetchedSize: undefined,
|
|
123
|
+
bin: 0,
|
|
124
|
+
compareTo() {
|
|
125
|
+
return 0;
|
|
126
|
+
},
|
|
127
|
+
toUniqueString() {
|
|
128
|
+
return `${chr}_${min}_${max}`;
|
|
129
|
+
},
|
|
130
|
+
fetchedSize() {
|
|
131
|
+
return 0;
|
|
132
|
+
},
|
|
133
|
+
minv: {
|
|
134
|
+
dataPosition: 0,
|
|
135
|
+
blockPosition: 0,
|
|
136
|
+
compareTo: () => 0,
|
|
137
|
+
},
|
|
138
|
+
maxv: {
|
|
139
|
+
dataPosition: Number.MAX_SAFE_INTEGER,
|
|
140
|
+
blockPosition: 0,
|
|
141
|
+
compareTo: () => 0,
|
|
142
|
+
},
|
|
143
|
+
toString() {
|
|
144
|
+
return `${chr}_${min}_${max}`;
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
], chrId, min, max, opts))));
|
|
115
148
|
}
|
|
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
149
|
});
|
|
129
150
|
}
|
|
130
|
-
|
|
131
|
-
_readChunk(params) {
|
|
151
|
+
_readChunk({ chunk }) {
|
|
132
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
153
|
+
if (!chunk.buffer) {
|
|
154
|
+
throw new Error('expected chunk.buffer in htsget');
|
|
155
|
+
}
|
|
156
|
+
return { data: chunk.buffer, cpositions: [], dpositions: [], chunk };
|
|
136
157
|
});
|
|
137
158
|
}
|
|
138
159
|
getHeader(opts = {}) {
|
|
@@ -140,7 +161,7 @@ class HtsgetFile extends bamFile_1.default {
|
|
|
140
161
|
const url = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`;
|
|
141
162
|
const result = yield fetch(url, opts);
|
|
142
163
|
if (!result.ok) {
|
|
143
|
-
throw new Error(`
|
|
164
|
+
throw new Error(`HTTP ${result.status} fetching ${url}: ${yield result.text()}`);
|
|
144
165
|
}
|
|
145
166
|
const data = yield result.json();
|
|
146
167
|
const uncba = yield concat(data.htsget.urls, opts);
|
|
@@ -154,17 +175,21 @@ class HtsgetFile extends bamFile_1.default {
|
|
|
154
175
|
// mapping between ref ref ID numbers and names
|
|
155
176
|
const idToName = [];
|
|
156
177
|
const nameToId = {};
|
|
157
|
-
const sqLines = samHeader.filter(
|
|
158
|
-
sqLines.
|
|
159
|
-
|
|
178
|
+
const sqLines = samHeader.filter(l => l.tag === 'SQ');
|
|
179
|
+
for (const [refId, sqLine] of sqLines.entries()) {
|
|
180
|
+
let refName = '';
|
|
181
|
+
let length = 0;
|
|
182
|
+
for (const item of sqLine.data) {
|
|
160
183
|
if (item.tag === 'SN') {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
184
|
+
refName = item.value;
|
|
185
|
+
}
|
|
186
|
+
else if (item.tag === 'LN') {
|
|
187
|
+
length = +item.value;
|
|
165
188
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
189
|
+
}
|
|
190
|
+
nameToId[refName] = refId;
|
|
191
|
+
idToName[refId] = { refName, length };
|
|
192
|
+
}
|
|
168
193
|
this.chrToIndex = nameToId;
|
|
169
194
|
this.indexToChr = idToName;
|
|
170
195
|
return samHeader;
|
package/dist/htsget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htsget.js","sourceRoot":"","sources":["../src/htsget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"htsget.js","sourceRoot":"","sources":["../src/htsget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAC7C,mCAA+B;AAE/B,qDAA8C;AAE9C,+BAAuC;AAMvC,SAAe,MAAM,CAAC,GAAkB,EAAE,IAA0B;;QAClE,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3B,GAAG,CAAC,GAAG,CAAC,CAAM,KAAK,EAAC,EAAE;YACpB,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;YAC9B,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;gBAC3B,OAAO,eAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;aAChD;iBAAM;gBACL,+DAA+D;gBAC/D,mBAAmB;gBACnB,4DAA4D;gBAC5D,MAAM,EAAE,OAAO,KAAc,OAAO,EAAhB,IAAI,UAAK,OAAO,EAA9B,WAAoB,CAAU,CAAA;gBACpC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,kCACtB,IAAI,KACP,OAAO,kCAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,GAAK,IAAI,KACpC,CAAA;gBACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;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