@gmod/tabix 1.6.0 → 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 +5 -1
- package/dist/csi.d.ts +3 -4
- package/dist/csi.js +39 -31
- package/dist/csi.js.map +1 -1
- package/dist/indexFile.d.ts +1 -1
- package/dist/indexFile.js +1 -2
- package/dist/indexFile.js.map +1 -1
- package/dist/tabix-bundle.js +1 -2
- package/dist/tabixIndexedFile.d.ts +3 -5
- package/dist/tabixIndexedFile.js +24 -33
- package/dist/tabixIndexedFile.js.map +1 -1
- package/dist/tbi.d.ts +2 -3
- package/dist/tbi.js +29 -26
- package/dist/tbi.js.map +1 -1
- package/dist/virtualOffset.d.ts +1 -2
- package/dist/virtualOffset.js +1 -4
- package/dist/virtualOffset.js.map +1 -1
- package/esm/csi.d.ts +3 -4
- package/esm/csi.js +39 -31
- package/esm/csi.js.map +1 -1
- package/esm/indexFile.d.ts +1 -1
- package/esm/indexFile.js +1 -2
- package/esm/indexFile.js.map +1 -1
- package/esm/tabixIndexedFile.d.ts +3 -5
- package/esm/tabixIndexedFile.js +16 -25
- package/esm/tabixIndexedFile.js.map +1 -1
- package/esm/tbi.d.ts +2 -3
- package/esm/tbi.js +29 -26
- package/esm/tbi.js.map +1 -1
- package/esm/virtualOffset.d.ts +1 -2
- package/esm/virtualOffset.js +1 -4
- package/esm/virtualOffset.js.map +1 -1
- package/package.json +4 -7
- package/src/csi.ts +49 -40
- package/src/indexFile.ts +1 -1
- package/src/tabixIndexedFile.ts +15 -34
- package/src/tbi.ts +33 -29
- package/src/virtualOffset.ts +1 -6
- package/dist/tabix-bundle.js.LICENSE.txt +0 -8
package/esm/tbi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tbi.js","sourceRoot":"","sources":["../src/tbi.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,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.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
1
|
export default class VirtualOffset {
|
|
3
2
|
blockPosition: number;
|
|
4
3
|
dataPosition: number;
|
|
@@ -6,4 +5,4 @@ export default class VirtualOffset {
|
|
|
6
5
|
toString(): string;
|
|
7
6
|
compareTo(b: VirtualOffset): number;
|
|
8
7
|
}
|
|
9
|
-
export declare function fromBytes(bytes:
|
|
8
|
+
export declare function fromBytes(bytes: Uint8Array, offset?: number): VirtualOffset;
|
package/esm/virtualOffset.js
CHANGED
|
@@ -10,10 +10,7 @@ export default class VirtualOffset {
|
|
|
10
10
|
return (this.blockPosition - b.blockPosition || this.dataPosition - b.dataPosition);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export function fromBytes(bytes, offset = 0
|
|
14
|
-
if (bigendian) {
|
|
15
|
-
throw new Error('big-endian virtual file offsets not implemented');
|
|
16
|
-
}
|
|
13
|
+
export function fromBytes(bytes, offset = 0) {
|
|
17
14
|
return new VirtualOffset(bytes[offset + 7] * 0x10000000000 +
|
|
18
15
|
bytes[offset + 6] * 0x100000000 +
|
|
19
16
|
bytes[offset + 5] * 0x1000000 +
|
package/esm/virtualOffset.js.map
CHANGED
|
@@ -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":"AAAA,MAAM,CAAC,OAAO,OAAO,aAAa;IAGhC,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;IAED,SAAS,CAAC,CAAgB;QACxB,OAAO,CACL,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAC3E,CAAA;IACH,CAAC;CACF;AACD,MAAM,UAAU,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmod/tabix",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Read Tabix-indexed files, supports both .tbi and .csi indexes",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "GMOD/tabix-js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@gmod/abortable-promise-cache": "^2.0.0",
|
|
45
|
-
"@gmod/bgzf-filehandle": "^
|
|
46
|
-
"generic-
|
|
45
|
+
"@gmod/bgzf-filehandle": "^2.0.1",
|
|
46
|
+
"generic-filehandle2": "^0.0.2",
|
|
47
47
|
"long": "^4.0.0",
|
|
48
48
|
"quick-lru": "^4.0.0"
|
|
49
49
|
},
|
|
@@ -55,16 +55,13 @@
|
|
|
55
55
|
"@typescript-eslint/eslint-plugin": "^8.0.1",
|
|
56
56
|
"@typescript-eslint/parser": "^8.0.1",
|
|
57
57
|
"@vitest/coverage-v8": "^2.0.5",
|
|
58
|
-
"buffer": "^6.0.3",
|
|
59
58
|
"documentation": "^14.0.3",
|
|
60
59
|
"eslint": "^9.9.0",
|
|
61
|
-
"eslint-config-prettier": "^9.1.0",
|
|
62
|
-
"eslint-plugin-prettier": "^5.0.1",
|
|
63
60
|
"eslint-plugin-unicorn": "^56.0.0",
|
|
64
61
|
"prettier": "^3.3.3",
|
|
65
62
|
"rimraf": "^6.0.1",
|
|
66
63
|
"standard-changelog": "^6.0.0",
|
|
67
|
-
"typescript": "^5.
|
|
64
|
+
"typescript": "^5.7.0",
|
|
68
65
|
"typescript-eslint": "^8.0.1",
|
|
69
66
|
"vitest": "^2.0.5",
|
|
70
67
|
"webpack": "^5.93.0",
|
package/src/csi.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Long from 'long'
|
|
2
|
-
import { Buffer } from 'buffer'
|
|
3
2
|
import { unzip } from '@gmod/bgzf-filehandle'
|
|
4
3
|
|
|
5
4
|
import VirtualOffset, { fromBytes } from './virtualOffset'
|
|
@@ -11,6 +10,12 @@ import IndexFile, { Options } from './indexFile'
|
|
|
11
10
|
const CSI1_MAGIC = 21582659 // CSI\1
|
|
12
11
|
const CSI2_MAGIC = 38359875 // CSI\2
|
|
13
12
|
|
|
13
|
+
const formats = {
|
|
14
|
+
0: 'generic',
|
|
15
|
+
1: 'SAM',
|
|
16
|
+
2: 'VCF',
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
function lshift(num: number, bits: number) {
|
|
15
20
|
return num * 2 ** bits
|
|
16
21
|
}
|
|
@@ -49,26 +54,27 @@ export default class CSI extends IndexFile {
|
|
|
49
54
|
throw new Error('CSI indexes do not support indexcov')
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
parseAuxData(bytes:
|
|
53
|
-
const
|
|
57
|
+
parseAuxData(bytes: Uint8Array, offset: number) {
|
|
58
|
+
const dataView = new DataView(bytes.buffer)
|
|
59
|
+
const formatFlags = dataView.getInt32(offset, true)
|
|
54
60
|
const coordinateType =
|
|
55
61
|
formatFlags & 0x10000 ? 'zero-based-half-open' : '1-based-closed'
|
|
56
|
-
const format =
|
|
62
|
+
const format = formats[(formatFlags & 0xf) as 0 | 1 | 2]
|
|
57
63
|
if (!format) {
|
|
58
64
|
throw new Error(`invalid Tabix preset format flags ${formatFlags}`)
|
|
59
65
|
}
|
|
60
66
|
const columnNumbers = {
|
|
61
|
-
ref:
|
|
62
|
-
start:
|
|
63
|
-
end:
|
|
67
|
+
ref: dataView.getInt32(offset + 4, true),
|
|
68
|
+
start: dataView.getInt32(offset + 8, true),
|
|
69
|
+
end: dataView.getInt32(offset + 12, true),
|
|
64
70
|
}
|
|
65
|
-
const metaValue =
|
|
71
|
+
const metaValue = dataView.getInt32(offset + 16, true)
|
|
66
72
|
const metaChar = metaValue ? String.fromCharCode(metaValue) : null
|
|
67
|
-
const skipLines =
|
|
68
|
-
const nameSectionLength =
|
|
73
|
+
const skipLines = dataView.getInt32(offset + 20, true)
|
|
74
|
+
const nameSectionLength = dataView.getInt32(offset + 24, true)
|
|
69
75
|
|
|
70
76
|
const { refIdToName, refNameToId } = this._parseNameBytes(
|
|
71
|
-
bytes.
|
|
77
|
+
bytes.subarray(offset + 28, offset + 28 + nameSectionLength),
|
|
72
78
|
)
|
|
73
79
|
|
|
74
80
|
return {
|
|
@@ -82,16 +88,18 @@ export default class CSI extends IndexFile {
|
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
|
|
85
|
-
_parseNameBytes(namesBytes:
|
|
91
|
+
_parseNameBytes(namesBytes: Uint8Array) {
|
|
86
92
|
let currRefId = 0
|
|
87
93
|
let currNameStart = 0
|
|
88
94
|
const refIdToName = []
|
|
89
95
|
const refNameToId: Record<string, number> = {}
|
|
96
|
+
const decoder = new TextDecoder('utf8')
|
|
90
97
|
for (let i = 0; i < namesBytes.length; i += 1) {
|
|
91
98
|
if (!namesBytes[i]) {
|
|
92
99
|
if (currNameStart < i) {
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
const refName = this.renameRefSeq(
|
|
101
|
+
decoder.decode(namesBytes.subarray(currNameStart, i)),
|
|
102
|
+
)
|
|
95
103
|
refIdToName[currRefId] = refName
|
|
96
104
|
refNameToId[refName] = currRefId
|
|
97
105
|
}
|
|
@@ -99,30 +107,33 @@ export default class CSI extends IndexFile {
|
|
|
99
107
|
currRefId += 1
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
refNameToId,
|
|
112
|
+
refIdToName,
|
|
113
|
+
}
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
// fetch and parse the index
|
|
106
117
|
|
|
107
118
|
async _parse(opts: Options = {}) {
|
|
108
119
|
const bytes = await unzip(await this.filehandle.readFile(opts))
|
|
120
|
+
const dataView = new DataView(bytes.buffer)
|
|
109
121
|
|
|
110
122
|
// check TBI magic numbers
|
|
111
123
|
let csiVersion
|
|
112
|
-
if (
|
|
124
|
+
if (dataView.getUint32(0, true) === CSI1_MAGIC) {
|
|
113
125
|
csiVersion = 1
|
|
114
|
-
} else if (
|
|
126
|
+
} else if (dataView.getUint32(0, true) === CSI2_MAGIC) {
|
|
115
127
|
csiVersion = 2
|
|
116
128
|
} else {
|
|
117
129
|
throw new Error('Not a CSI file')
|
|
118
|
-
// TODO: do we need to support big-endian CSI files?
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
this.minShift =
|
|
122
|
-
this.depth =
|
|
132
|
+
this.minShift = dataView.getInt32(4, true)
|
|
133
|
+
this.depth = dataView.getInt32(8, true)
|
|
123
134
|
this.maxBinNumber = ((1 << ((this.depth + 1) * 3)) - 1) / 7
|
|
124
135
|
const maxRefLength = 2 ** (this.minShift + this.depth * 3)
|
|
125
|
-
const auxLength =
|
|
136
|
+
const auxLength = dataView.getInt32(12, true)
|
|
126
137
|
const aux =
|
|
127
138
|
auxLength && auxLength >= 30
|
|
128
139
|
? this.parseAuxData(bytes, 16)
|
|
@@ -134,35 +145,33 @@ export default class CSI extends IndexFile {
|
|
|
134
145
|
coordinateType: 'zero-based-half-open',
|
|
135
146
|
format: 'generic',
|
|
136
147
|
}
|
|
137
|
-
const refCount =
|
|
148
|
+
const refCount = dataView.getInt32(16 + auxLength, true)
|
|
138
149
|
|
|
139
150
|
// read the indexes for each reference sequence
|
|
140
151
|
let firstDataLine: VirtualOffset | undefined
|
|
141
152
|
let currOffset = 16 + auxLength + 4
|
|
142
153
|
const indices = new Array(refCount).fill(0).map(() => {
|
|
143
|
-
|
|
144
|
-
const binCount = bytes.readInt32LE(currOffset)
|
|
154
|
+
const binCount = dataView.getInt32(currOffset, true)
|
|
145
155
|
currOffset += 4
|
|
146
156
|
const binIndex: Record<string, Chunk[]> = {}
|
|
147
|
-
let stats
|
|
157
|
+
let stats
|
|
148
158
|
for (let j = 0; j < binCount; j += 1) {
|
|
149
|
-
const bin =
|
|
159
|
+
const bin = dataView.getUint32(currOffset, true)
|
|
150
160
|
if (bin > this.maxBinNumber) {
|
|
151
|
-
// this is a fake bin that actually has stats information
|
|
152
|
-
//
|
|
161
|
+
// this is a fake bin that actually has stats information about the
|
|
162
|
+
// reference sequence in it
|
|
153
163
|
stats = this.parsePseudoBin(bytes, currOffset + 4)
|
|
154
164
|
currOffset += 4 + 8 + 4 + 16 + 16
|
|
155
165
|
} else {
|
|
156
166
|
const loffset = fromBytes(bytes, currOffset + 4)
|
|
157
167
|
firstDataLine = this._findFirstData(firstDataLine, loffset)
|
|
158
|
-
const chunkCount =
|
|
168
|
+
const chunkCount = dataView.getInt32(currOffset + 12, true)
|
|
159
169
|
currOffset += 16
|
|
160
170
|
const chunks = new Array(chunkCount)
|
|
161
171
|
for (let k = 0; k < chunkCount; k += 1) {
|
|
162
172
|
const u = fromBytes(bytes, currOffset)
|
|
163
173
|
const v = fromBytes(bytes, currOffset + 8)
|
|
164
174
|
currOffset += 16
|
|
165
|
-
// this._findFirstData(data, u)
|
|
166
175
|
chunks[k] = new Chunk(u, v, bin)
|
|
167
176
|
}
|
|
168
177
|
binIndex[bin] = chunks
|
|
@@ -186,14 +195,15 @@ export default class CSI extends IndexFile {
|
|
|
186
195
|
}
|
|
187
196
|
}
|
|
188
197
|
|
|
189
|
-
parsePseudoBin(bytes:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
parsePseudoBin(bytes: Uint8Array, offset: number) {
|
|
199
|
+
return {
|
|
200
|
+
lineCount: longToNumber(
|
|
201
|
+
Long.fromBytesLE(
|
|
202
|
+
bytes.subarray(offset + 28, offset + 36) as unknown as number[],
|
|
203
|
+
true,
|
|
204
|
+
),
|
|
194
205
|
),
|
|
195
|
-
|
|
196
|
-
return { lineCount }
|
|
206
|
+
}
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
async blocksForRange(
|
|
@@ -216,9 +226,8 @@ export default class CSI extends IndexFile {
|
|
|
216
226
|
return []
|
|
217
227
|
}
|
|
218
228
|
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
const overlappingBins = this.reg2bins(min, max) // List of bin #s that overlap min, max
|
|
229
|
+
// List of bin #s that overlap min, max
|
|
230
|
+
const overlappingBins = this.reg2bins(min, max)
|
|
222
231
|
const chunks: Chunk[] = []
|
|
223
232
|
|
|
224
233
|
// Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned
|
package/src/indexFile.ts
CHANGED
package/src/tabixIndexedFile.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import AbortablePromiseCache from '@gmod/abortable-promise-cache'
|
|
2
2
|
import LRU from 'quick-lru'
|
|
3
|
-
import {
|
|
4
|
-
import { GenericFilehandle, RemoteFile, LocalFile } from 'generic-filehandle'
|
|
3
|
+
import { GenericFilehandle, RemoteFile, LocalFile } from 'generic-filehandle2'
|
|
5
4
|
import { unzip, unzipChunkSlice } from '@gmod/bgzf-filehandle'
|
|
6
5
|
import { checkAbortSignal } from './util'
|
|
7
6
|
import IndexFile, { Options, IndexData } from './indexFile'
|
|
@@ -17,9 +16,6 @@ function isASCII(str: string) {
|
|
|
17
16
|
|
|
18
17
|
type GetLinesCallback = (line: string, fileOffset: number) => void
|
|
19
18
|
|
|
20
|
-
const decoder =
|
|
21
|
-
typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined
|
|
22
|
-
|
|
23
19
|
interface GetLinesOpts {
|
|
24
20
|
[key: string]: unknown
|
|
25
21
|
signal?: AbortSignal
|
|
@@ -27,7 +23,7 @@ interface GetLinesOpts {
|
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
interface ReadChunk {
|
|
30
|
-
buffer:
|
|
26
|
+
buffer: Uint8Array
|
|
31
27
|
cpositions: number[]
|
|
32
28
|
dpositions: number[]
|
|
33
29
|
}
|
|
@@ -196,6 +192,7 @@ export default class TabixIndexedFile {
|
|
|
196
192
|
|
|
197
193
|
const chunks = await this.index.blocksForRange(refName, start, end, options)
|
|
198
194
|
checkAbortSignal(signal)
|
|
195
|
+
const decoder = new TextDecoder('utf8')
|
|
199
196
|
|
|
200
197
|
// now go through each chunk and parse and filter the lines out of it
|
|
201
198
|
for (const c of chunks) {
|
|
@@ -209,11 +206,11 @@ export default class TabixIndexedFile {
|
|
|
209
206
|
let blockStart = 0
|
|
210
207
|
let pos = 0
|
|
211
208
|
|
|
212
|
-
const str = decoder?.decode(buffer) ?? buffer.toString()
|
|
213
209
|
// fast path, Buffer is just ASCII chars and not gigantor, can be
|
|
214
210
|
// converted to string and processed directly. if it is not ASCII or
|
|
215
211
|
// gigantic (chrome max str len is 512Mb), we have to decode line by line
|
|
216
|
-
const
|
|
212
|
+
const str = decoder.decode(buffer)
|
|
213
|
+
const strIsASCII = isASCII(str)
|
|
217
214
|
while (blockStart < str.length) {
|
|
218
215
|
let line: string
|
|
219
216
|
let n: number
|
|
@@ -224,12 +221,12 @@ export default class TabixIndexedFile {
|
|
|
224
221
|
}
|
|
225
222
|
line = str.slice(blockStart, n)
|
|
226
223
|
} else {
|
|
227
|
-
n = buffer.indexOf('\n', blockStart)
|
|
224
|
+
n = buffer.indexOf('\n'.charCodeAt(0), blockStart)
|
|
228
225
|
if (n === -1) {
|
|
229
226
|
break
|
|
230
227
|
}
|
|
231
228
|
const b = buffer.slice(blockStart, n)
|
|
232
|
-
line = decoder
|
|
229
|
+
line = decoder.decode(b)
|
|
233
230
|
}
|
|
234
231
|
|
|
235
232
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -291,12 +288,11 @@ export default class TabixIndexedFile {
|
|
|
291
288
|
|
|
292
289
|
checkAbortSignal(opts.signal)
|
|
293
290
|
|
|
294
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
295
291
|
const maxFetch = (firstDataLine?.blockPosition || 0) + maxBlockSize
|
|
296
|
-
// TODO: what if we don't have a firstDataLine, and the header
|
|
297
|
-
//
|
|
292
|
+
// TODO: what if we don't have a firstDataLine, and the header actually
|
|
293
|
+
// takes up more than one block? this case is not covered here
|
|
298
294
|
|
|
299
|
-
const buf = await this.
|
|
295
|
+
const buf = await this.filehandle.read(maxFetch, 0, opts)
|
|
300
296
|
const bytes = await unzip(buf)
|
|
301
297
|
|
|
302
298
|
// trim off lines after the last non-meta line
|
|
@@ -325,8 +321,9 @@ export default class TabixIndexedFile {
|
|
|
325
321
|
* @returns {Promise} for a string
|
|
326
322
|
*/
|
|
327
323
|
async getHeader(opts: Options = {}) {
|
|
324
|
+
const decoder = new TextDecoder('utf8')
|
|
328
325
|
const bytes = await this.getHeaderBuffer(opts)
|
|
329
|
-
return
|
|
326
|
+
return decoder.decode(bytes)
|
|
330
327
|
}
|
|
331
328
|
|
|
332
329
|
/**
|
|
@@ -493,32 +490,16 @@ export default class TabixIndexedFile {
|
|
|
493
490
|
return this.index.lineCount(refName, opts)
|
|
494
491
|
}
|
|
495
492
|
|
|
496
|
-
async _readRegion(pos: number, size: number, opts: Options = {}) {
|
|
497
|
-
const b = Buffer.alloc(size)
|
|
498
|
-
const { bytesRead, buffer } = await this.filehandle.read(
|
|
499
|
-
b,
|
|
500
|
-
0,
|
|
501
|
-
size,
|
|
502
|
-
pos,
|
|
503
|
-
opts,
|
|
504
|
-
)
|
|
505
|
-
|
|
506
|
-
return buffer.subarray(0, bytesRead)
|
|
507
|
-
}
|
|
508
|
-
|
|
509
493
|
/**
|
|
510
494
|
* read and uncompress the data in a chunk (composed of one or more
|
|
511
495
|
* contiguous bgzip blocks) of the file
|
|
512
496
|
*/
|
|
513
497
|
async readChunk(c: Chunk, opts: Options = {}) {
|
|
514
|
-
|
|
515
|
-
// stop when done
|
|
516
|
-
|
|
517
|
-
const data = await this._readRegion(
|
|
518
|
-
c.minv.blockPosition,
|
|
498
|
+
const ret = await this.filehandle.read(
|
|
519
499
|
c.fetchedSize(),
|
|
500
|
+
c.minv.blockPosition,
|
|
520
501
|
opts,
|
|
521
502
|
)
|
|
522
|
-
return unzipChunkSlice(
|
|
503
|
+
return unzipChunkSlice(ret, c)
|
|
523
504
|
}
|
|
524
505
|
}
|
package/src/tbi.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Long from 'long'
|
|
2
|
-
import { Buffer } from 'buffer'
|
|
3
2
|
import VirtualOffset, { fromBytes } from './virtualOffset'
|
|
4
3
|
import Chunk from './chunk'
|
|
5
4
|
import { unzip } from '@gmod/bgzf-filehandle'
|
|
@@ -37,11 +36,7 @@ export default class TabixIndex extends IndexFile {
|
|
|
37
36
|
if (!idx) {
|
|
38
37
|
return -1
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
if (stats) {
|
|
42
|
-
return stats.lineCount
|
|
43
|
-
}
|
|
44
|
-
return -1
|
|
39
|
+
return indexData.indices[refId].stats?.lineCount ?? -1
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
// fetch and parse the index
|
|
@@ -49,16 +44,16 @@ export default class TabixIndex extends IndexFile {
|
|
|
49
44
|
const buf = await this.filehandle.readFile(opts)
|
|
50
45
|
const bytes = await unzip(buf)
|
|
51
46
|
checkAbortSignal(opts.signal)
|
|
47
|
+
const dataView = new DataView(bytes.buffer)
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
if (
|
|
49
|
+
const magic = dataView.getUint32(0, true)
|
|
50
|
+
if (magic !== TBI_MAGIC /* "TBI\1" */) {
|
|
55
51
|
throw new Error('Not a TBI file')
|
|
56
|
-
// TODO: do we need to support big-endian TBI files?
|
|
57
52
|
}
|
|
58
53
|
|
|
59
54
|
// number of reference sequences in the index
|
|
60
|
-
const refCount =
|
|
61
|
-
const formatFlags =
|
|
55
|
+
const refCount = dataView.getUint32(4, true)
|
|
56
|
+
const formatFlags = dataView.getUint32(8, true)
|
|
62
57
|
const coordinateType =
|
|
63
58
|
formatFlags & 0x10000 ? 'zero-based-half-open' : '1-based-closed'
|
|
64
59
|
const formatOpts: Record<number, string> = {
|
|
@@ -71,19 +66,19 @@ export default class TabixIndex extends IndexFile {
|
|
|
71
66
|
throw new Error(`invalid Tabix preset format flags ${formatFlags}`)
|
|
72
67
|
}
|
|
73
68
|
const columnNumbers = {
|
|
74
|
-
ref:
|
|
75
|
-
start:
|
|
76
|
-
end:
|
|
69
|
+
ref: dataView.getInt32(12, true),
|
|
70
|
+
start: dataView.getInt32(16, true),
|
|
71
|
+
end: dataView.getInt32(20, true),
|
|
77
72
|
}
|
|
78
|
-
const metaValue =
|
|
73
|
+
const metaValue = dataView.getInt32(24, true)
|
|
79
74
|
const depth = 5
|
|
80
75
|
const maxBinNumber = ((1 << ((depth + 1) * 3)) - 1) / 7
|
|
81
76
|
const maxRefLength = 2 ** (14 + depth * 3)
|
|
82
77
|
const metaChar = metaValue ? String.fromCharCode(metaValue) : null
|
|
83
|
-
const skipLines =
|
|
78
|
+
const skipLines = dataView.getInt32(28, true)
|
|
84
79
|
|
|
85
80
|
// read sequence dictionary
|
|
86
|
-
const nameSectionLength =
|
|
81
|
+
const nameSectionLength = dataView.getInt32(32, true)
|
|
87
82
|
const { refNameToId, refIdToName } = this._parseNameBytes(
|
|
88
83
|
bytes.slice(36, 36 + nameSectionLength),
|
|
89
84
|
)
|
|
@@ -93,26 +88,26 @@ export default class TabixIndex extends IndexFile {
|
|
|
93
88
|
let firstDataLine: VirtualOffset | undefined
|
|
94
89
|
const indices = new Array(refCount).fill(0).map(() => {
|
|
95
90
|
// the binning index
|
|
96
|
-
const binCount =
|
|
91
|
+
const binCount = dataView.getInt32(currOffset, true)
|
|
97
92
|
currOffset += 4
|
|
98
93
|
const binIndex: Record<number, Chunk[]> = {}
|
|
99
94
|
let stats
|
|
100
95
|
for (let j = 0; j < binCount; j += 1) {
|
|
101
|
-
const bin =
|
|
96
|
+
const bin = dataView.getUint32(currOffset, true)
|
|
102
97
|
currOffset += 4
|
|
103
98
|
if (bin > maxBinNumber + 1) {
|
|
104
99
|
throw new Error(
|
|
105
100
|
'tabix index contains too many bins, please use a CSI index',
|
|
106
101
|
)
|
|
107
102
|
} else if (bin === maxBinNumber + 1) {
|
|
108
|
-
const chunkCount =
|
|
103
|
+
const chunkCount = dataView.getInt32(currOffset, true)
|
|
109
104
|
currOffset += 4
|
|
110
105
|
if (chunkCount === 2) {
|
|
111
106
|
stats = this.parsePseudoBin(bytes, currOffset)
|
|
112
107
|
}
|
|
113
108
|
currOffset += 16 * chunkCount
|
|
114
109
|
} else {
|
|
115
|
-
const chunkCount =
|
|
110
|
+
const chunkCount = dataView.getInt32(currOffset, true)
|
|
116
111
|
currOffset += 4
|
|
117
112
|
const chunks = new Array(chunkCount)
|
|
118
113
|
for (let k = 0; k < chunkCount; k += 1) {
|
|
@@ -127,7 +122,7 @@ export default class TabixIndex extends IndexFile {
|
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
// the linear index
|
|
130
|
-
const linearCount =
|
|
125
|
+
const linearCount = dataView.getInt32(currOffset, true)
|
|
131
126
|
currOffset += 4
|
|
132
127
|
const linearIndex = new Array(linearCount)
|
|
133
128
|
for (let k = 0; k < linearCount; k += 1) {
|
|
@@ -135,7 +130,11 @@ export default class TabixIndex extends IndexFile {
|
|
|
135
130
|
currOffset += 8
|
|
136
131
|
firstDataLine = this._findFirstData(firstDataLine, linearIndex[k])
|
|
137
132
|
}
|
|
138
|
-
return {
|
|
133
|
+
return {
|
|
134
|
+
binIndex,
|
|
135
|
+
linearIndex,
|
|
136
|
+
stats,
|
|
137
|
+
}
|
|
139
138
|
})
|
|
140
139
|
|
|
141
140
|
return {
|
|
@@ -154,26 +153,28 @@ export default class TabixIndex extends IndexFile {
|
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
parsePseudoBin(bytes:
|
|
156
|
+
parsePseudoBin(bytes: Uint8Array, offset: number) {
|
|
158
157
|
const lineCount = longToNumber(
|
|
159
158
|
Long.fromBytesLE(
|
|
160
|
-
bytes.
|
|
159
|
+
bytes.subarray(offset + 16, offset + 24) as unknown as number[],
|
|
161
160
|
true,
|
|
162
161
|
),
|
|
163
162
|
)
|
|
164
163
|
return { lineCount }
|
|
165
164
|
}
|
|
166
165
|
|
|
167
|
-
_parseNameBytes(namesBytes:
|
|
166
|
+
_parseNameBytes(namesBytes: Uint8Array) {
|
|
168
167
|
let currRefId = 0
|
|
169
168
|
let currNameStart = 0
|
|
170
169
|
const refIdToName: string[] = []
|
|
171
170
|
const refNameToId: Record<string, number> = {}
|
|
171
|
+
const decoder = new TextDecoder('utf8')
|
|
172
172
|
for (let i = 0; i < namesBytes.length; i += 1) {
|
|
173
173
|
if (!namesBytes[i]) {
|
|
174
174
|
if (currNameStart < i) {
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const refName = this.renameRefSeq(
|
|
176
|
+
decoder.decode(namesBytes.subarray(currNameStart, i)),
|
|
177
|
+
)
|
|
177
178
|
refIdToName[currRefId] = refName
|
|
178
179
|
refNameToId[refName] = currRefId
|
|
179
180
|
}
|
|
@@ -181,7 +182,10 @@ export default class TabixIndex extends IndexFile {
|
|
|
181
182
|
currRefId += 1
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
|
-
return {
|
|
185
|
+
return {
|
|
186
|
+
refNameToId,
|
|
187
|
+
refIdToName,
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
async blocksForRange(
|
package/src/virtualOffset.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer'
|
|
2
1
|
export default class VirtualOffset {
|
|
3
2
|
public blockPosition: number
|
|
4
3
|
public dataPosition: number
|
|
@@ -17,11 +16,7 @@ export default class VirtualOffset {
|
|
|
17
16
|
)
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
export function fromBytes(bytes:
|
|
21
|
-
if (bigendian) {
|
|
22
|
-
throw new Error('big-endian virtual file offsets not implemented')
|
|
23
|
-
}
|
|
24
|
-
|
|
19
|
+
export function fromBytes(bytes: Uint8Array, offset = 0) {
|
|
25
20
|
return new VirtualOffset(
|
|
26
21
|
bytes[offset + 7]! * 0x10000000000 +
|
|
27
22
|
bytes[offset + 6]! * 0x100000000 +
|