Skip to content

Commit 7f89bd8

Browse files
cmdcolinclaude
andcommitted
fix lint and type errors for TypeScript 6 compatibility
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ffa4c05 commit 7f89bd8

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

src/csi.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ export default class CSI extends IndexFile {
9191
}
9292

9393
async _parse(opts: Options = {}) {
94-
const bytes = (await unzip(
95-
await this.filehandle.readFile(opts),
96-
)) as Uint8Array
94+
const buf = await this.filehandle.readFile({ signal: opts.signal })
95+
const bytes = (await unzip(buf)) as Uint8Array
9796
const dataView = new DataView(bytes.buffer)
9897

9998
// check TBI magic numbers

src/tbi.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class TabixIndex extends IndexFile {
4444

4545
// fetch and parse the index
4646
async _parse(opts: Options = {}) {
47-
const buf = await this.filehandle.readFile(opts)
47+
const buf = await this.filehandle.readFile({ signal: opts.signal })
4848
const bytes = (await unzip(buf)) as Uint8Array
4949
const dataView = new DataView(bytes.buffer)
5050

@@ -128,9 +128,10 @@ export default class TabixIndex extends IndexFile {
128128
currOffset += 4
129129
const linearIndex = Array.from<VirtualOffset>({ length: linearCount })
130130
for (let k = 0; k < linearCount; k += 1) {
131-
linearIndex[k] = fromBytes(bytes, currOffset)
131+
const lv = fromBytes(bytes, currOffset)
132+
linearIndex[k] = lv
132133
currOffset += 8
133-
firstDataLine = this._findFirstData(firstDataLine, linearIndex[k])
134+
firstDataLine = this._findFirstData(firstDataLine, lv)
134135
}
135136
return {
136137
binIndex,

test/csi.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import VirtualOffset from '../src/virtualOffset.ts'
66

77
test('loads test.gff3.gz.csi', async () => {
88
const ti = new CSI({
9-
filehandle: new LocalFile(require.resolve('./data/test.gff3.gz.csi')),
9+
filehandle: new LocalFile(
10+
new URL('data/test.gff3.gz.csi', import.meta.url).pathname,
11+
),
1012
})
1113
const indexData = await ti.parse()
1214
expect(indexData.columnNumbers.start).toEqual(4)
@@ -42,7 +44,9 @@ test('loads test.gff3.gz.csi', async () => {
4244
})
4345
test('loads test.vcf.gz.csi', async () => {
4446
const ti = new CSI({
45-
filehandle: new LocalFile(require.resolve('./data/test.vcf.gz.csi')),
47+
filehandle: new LocalFile(
48+
new URL('data/test.vcf.gz.csi', import.meta.url).pathname,
49+
),
4650
})
4751
const indexData = await ti.parse()
4852
expect(indexData.columnNumbers.start).toEqual(2)

test/tabixindexedfile.test.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class RecordCollector {
3636
}
3737
test('can read contigA:1000..4000', async () => {
3838
const f = new TabixIndexedFile({
39-
path: require.resolve('./data/volvox.test.vcf.gz'),
40-
tbiPath: require.resolve('./data/volvox.test.vcf.gz.tbi'),
39+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
40+
tbiPath: new URL('data/volvox.test.vcf.gz.tbi', import.meta.url).pathname,
4141
})
4242
const items = new RecordCollector()
4343
await f.getLines('contigA', 1000, 4000, items.callback)
@@ -81,8 +81,8 @@ test('can read contigA:1000..4000', async () => {
8181
})
8282
test('can read contigA:10000', async () => {
8383
const f = new TabixIndexedFile({
84-
path: require.resolve('./data/volvox.test.vcf.gz'),
85-
tbiPath: require.resolve('./data/volvox.test.vcf.gz.tbi'),
84+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
85+
tbiPath: new URL('data/volvox.test.vcf.gz.tbi', import.meta.url).pathname,
8686
})
8787
const items = new RecordCollector()
8888
await f.getLines('contigA', 10_000, undefined, items.callback)
@@ -97,8 +97,8 @@ test('can read contigA:10000', async () => {
9797
})
9898
test('can read contigA', async () => {
9999
const f = new TabixIndexedFile({
100-
path: require.resolve('./data/volvox.test.vcf.gz'),
101-
tbiPath: require.resolve('./data/volvox.test.vcf.gz.tbi'),
100+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
101+
tbiPath: new URL('data/volvox.test.vcf.gz.tbi', import.meta.url).pathname,
102102
})
103103
const items = new RecordCollector()
104104
await f.getLines('contigA', undefined, undefined, items.callback)
@@ -112,32 +112,32 @@ test('can read contigA', async () => {
112112
})
113113
test('can count lines with TBI', async () => {
114114
const f = new TabixIndexedFile({
115-
path: require.resolve('./data/volvox.test.vcf.gz'),
116-
tbiPath: require.resolve('./data/volvox.test.vcf.gz.tbi'),
115+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
116+
tbiPath: new URL('data/volvox.test.vcf.gz.tbi', import.meta.url).pathname,
117117
})
118118
expect(await f.lineCount('contigA')).toEqual(109)
119119
expect(await f.lineCount('nonexistent')).toEqual(-1)
120120
})
121121
test('can count lines with CSI', async () => {
122122
const f = new TabixIndexedFile({
123-
path: require.resolve('./data/volvox.test.vcf.gz'),
124-
csiPath: require.resolve('./data/volvox.test.vcf.gz.csi'),
123+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
124+
csiPath: new URL('data/volvox.test.vcf.gz.csi', import.meta.url).pathname,
125125
})
126126
expect(await f.lineCount('contigA')).toEqual(109)
127127
expect(await f.lineCount('nonexistent')).toEqual(-1)
128128
})
129129
test("can't count lines without pseudo-bin", async () => {
130130
const f = new TabixIndexedFile({
131-
path: require.resolve('./data/volvox.test.vcf.gz'),
132-
tbiPath: require.resolve('./data/volvox.test.vcf.gz.tbi.no_pseudo'),
131+
path: new URL('data/volvox.test.vcf.gz', import.meta.url).pathname,
132+
tbiPath: new URL('data/volvox.test.vcf.gz.tbi.no_pseudo', import.meta.url).pathname,
133133
})
134134
expect(await f.lineCount('contigA')).toEqual(-1)
135135
})
136136

137137
test('can query volvox.sort.gff3.gz.1', async () => {
138138
const f = new TabixIndexedFile({
139-
path: require.resolve('./data/volvox.sort.gff3.gz.1'),
140-
tbiPath: require.resolve('./data/volvox.sort.gff3.gz.tbi'),
139+
path: new URL('data/volvox.sort.gff3.gz.1', import.meta.url).pathname,
140+
tbiPath: new URL('data/volvox.sort.gff3.gz.tbi', import.meta.url).pathname,
141141
})
142142

143143
const headerString = await f.getHeader()
@@ -169,7 +169,7 @@ test('can query volvox.sort.gff3.gz.1', async () => {
169169
})
170170
test('can query gvcf.vcf.gz', async () => {
171171
const f = new TabixIndexedFile({
172-
path: require.resolve('./data/gvcf.vcf.gz'),
172+
path: new URL('data/gvcf.vcf.gz', import.meta.url).pathname,
173173
})
174174

175175
const headerString = await f.getHeader()
@@ -202,7 +202,7 @@ test('can query gvcf.vcf.gz', async () => {
202202

203203
test('can query out.gff.gz with a TBI index', async () => {
204204
const f = new TabixIndexedFile({
205-
path: require.resolve('./data/out.gff.gz'),
205+
path: new URL('data/out.gff.gz', import.meta.url).pathname,
206206
})
207207

208208
const headerString = await f.getHeader()
@@ -233,8 +233,8 @@ test('can query out.gff.gz with a TBI index', async () => {
233233

234234
test('can query test.vcf.gz with a CSI index', async () => {
235235
const f = new TabixIndexedFile({
236-
path: require.resolve('./data/test.vcf.gz'),
237-
csiPath: require.resolve('./data/test.vcf.gz.csi'),
236+
path: new URL('data/test.vcf.gz', import.meta.url).pathname,
237+
csiPath: new URL('data/test.vcf.gz.csi', import.meta.url).pathname,
238238
})
239239

240240
const headerString = await f.getHeader()
@@ -280,7 +280,7 @@ test('can query test.vcf.gz with a CSI index', async () => {
280280

281281
test('can fetch the entire header for a very large vcf header', async () => {
282282
const f = new TabixIndexedFile({
283-
path: require.resolve('./data/large_vcf_header.vcf.gz'),
283+
path: new URL('data/large_vcf_header.vcf.gz', import.meta.url).pathname,
284284
})
285285

286286
const h = await f.getHeader()
@@ -292,7 +292,7 @@ test('can fetch the entire header for a very large vcf header', async () => {
292292

293293
test('can fetch a CNV with length defined by END in INFO field', async () => {
294294
const f = new TabixIndexedFile({
295-
path: require.resolve('./data/CNVtest.vcf.gz'),
295+
path: new URL('data/CNVtest.vcf.gz', import.meta.url).pathname,
296296
})
297297

298298
const lines = new RecordCollector()
@@ -302,7 +302,7 @@ test('can fetch a CNV with length defined by END in INFO field', async () => {
302302

303303
test('can fetch a CNV with length defined by END in INFO field using the opts.lineCallback', async () => {
304304
const f = new TabixIndexedFile({
305-
path: require.resolve('./data/CNVtest.vcf.gz'),
305+
path: new URL('data/CNVtest.vcf.gz', import.meta.url).pathname,
306306
})
307307

308308
const lines = new RecordCollector()
@@ -314,7 +314,7 @@ test('can fetch a CNV with length defined by END in INFO field using the opts.li
314314

315315
test('returns and empty string for `getHeader()` if there is no header', async () => {
316316
const f = new TabixIndexedFile({
317-
path: require.resolve('./data/test.bed.gz'),
317+
path: new URL('data/test.bed.gz', import.meta.url).pathname,
318318
})
319319

320320
const headerString = await f.getHeader()
@@ -323,7 +323,7 @@ test('returns and empty string for `getHeader()` if there is no header', async (
323323

324324
test('can fetch NC_000001.11:184099343..184125655 correctly', async () => {
325325
const f = new TabixIndexedFile({
326-
path: require.resolve('./data/ncbi_human.sorted.gff.gz'),
326+
path: new URL('data/ncbi_human.sorted.gff.gz', import.meta.url).pathname,
327327
})
328328

329329
// const headerString = await f.getHeader()
@@ -363,7 +363,7 @@ NC_000001.11 Gnomon exon 184121787 184122540 . + . Parent=lnc_RNA1661;Dbxref=Gen
363363

364364
test('usage of the chr22 ultralong nanopore as a bed file', async () => {
365365
const ti = new TabixIndexedFile({
366-
path: require.resolve('./data/chr22_nanopore_subset.bed.gz'),
366+
path: new URL('data/chr22_nanopore_subset.bed.gz', import.meta.url).pathname,
367367
})
368368
await ti.getHeader()
369369
const ret1 = new RecordCollector()
@@ -381,7 +381,7 @@ test('usage of the chr22 ultralong nanopore as a bed file', async () => {
381381

382382
test('too few', async () => {
383383
const ti = new TabixIndexedFile({
384-
path: require.resolve('./data/too_few_reads_if_chunk_merging_on.bed.gz'),
384+
path: new URL('data/too_few_reads_if_chunk_merging_on.bed.gz', import.meta.url).pathname,
385385
})
386386
await ti.getHeader()
387387

@@ -392,7 +392,7 @@ test('too few', async () => {
392392

393393
test('long read consistent IDs', async () => {
394394
const ti = new TabixIndexedFile({
395-
path: require.resolve('./data/CHM1_pacbio_clip2.bed.gz'),
395+
path: new URL('data/CHM1_pacbio_clip2.bed.gz', import.meta.url).pathname,
396396
})
397397
await ti.getHeader()
398398
const ret1 = new RecordCollector()
@@ -412,8 +412,8 @@ test('long read consistent IDs', async () => {
412412

413413
test('fake large chromosome', async () => {
414414
const ti = new TabixIndexedFile({
415-
path: require.resolve('./data/fake_large_chromosome/test.gff3.gz'),
416-
csiPath: require.resolve('./data/fake_large_chromosome/test.gff3.gz.csi'),
415+
path: new URL('data/fake_large_chromosome/test.gff3.gz', import.meta.url).pathname,
416+
csiPath: new URL('data/fake_large_chromosome/test.gff3.gz.csi', import.meta.url).pathname,
417417
})
418418
await ti.getHeader()
419419

@@ -425,8 +425,8 @@ test('fake large chromosome', async () => {
425425
})
426426
test('start equal to end in tabix columns', async () => {
427427
const ti = new TabixIndexedFile({
428-
path: require.resolve('./data/out.bed.gz'),
429-
tbiPath: require.resolve('./data/out.bed.gz.tbi'),
428+
path: new URL('data/out.bed.gz', import.meta.url).pathname,
429+
tbiPath: new URL('data/out.bed.gz.tbi', import.meta.url).pathname,
430430
})
431431
await ti.getHeader()
432432

test/tbi.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import VirtualOffset from '../src/virtualOffset.ts'
66

77
test('loads', async () => {
88
const ti = new TBI({
9-
filehandle: new LocalFile(require.resolve('./data/volvox.test.vcf.gz.tbi')),
9+
filehandle: new LocalFile(
10+
new URL('data/volvox.test.vcf.gz.tbi', import.meta.url).pathname,
11+
),
1012
})
1113
const indexData = await ti.parse()
1214
expect(indexData.columnNumbers.start).toEqual(2)
@@ -44,7 +46,7 @@ test('loads', async () => {
4446
test('failing tabix', async () => {
4547
const ti = new TBI({
4648
filehandle: new LocalFile(
47-
require.resolve('./data/failing_tabix.vcf.gz.tbi'),
49+
new URL('data/failing_tabix.vcf.gz.tbi', import.meta.url).pathname,
4850
),
4951
})
5052

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"outDir": "dist",
55
"lib": ["dom", "esnext"],
6+
"types": ["node"],
67
"declaration": true,
78
"moduleResolution": "bundler",
89
"module": "esnext",

0 commit comments

Comments
 (0)