Skip to content

Commit 75dfd5d

Browse files
committed
Opt
1 parent 9d9834e commit 75dfd5d

File tree

7 files changed

+630
-850
lines changed

7 files changed

+630
-850
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'node',
5-
};
5+
}

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@
2020
"preversion": "yarn lint && yarn test --run && yarn build",
2121
"postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
2222
"postversion": "git push --follow-tags",
23-
"test": "vitest"
23+
"test": "vitest",
24+
"format": "prettier --write ."
2425
},
2526
"name": "@gmod/trix",
2627
"author": "Matt Morgan",
2728
"repository": "GMOD/trix-js",
2829
"devDependencies": {
29-
"@types/node": "^22.15.21",
30-
"@typescript-eslint/eslint-plugin": "^8.4.0",
31-
"@typescript-eslint/parser": "^8.4.0",
30+
"@types/node": "^25.0.9",
31+
"@typescript-eslint/eslint-plugin": "^8.53.0",
32+
"@typescript-eslint/parser": "^8.53.0",
3233
"eslint": "^9.0.0",
3334
"eslint-plugin-import": "^2.31.0",
3435
"eslint-plugin-unicorn": "^62.0.0",
35-
"generic-filehandle2": "^2.0.5",
36-
"prettier": "^3.3.3",
36+
"generic-filehandle2": "^2.0.18",
37+
"prettier": "^3.8.0",
3738
"rimraf": "^6.0.1",
3839
"typescript": "^5.7.0",
39-
"typescript-eslint": "^8.4.0",
40-
"vitest": "^4.0.6"
40+
"typescript-eslint": "^8.53.0",
41+
"vitest": "^4.0.17"
4142
},
4243
"publishConfig": {
4344
"access": "public"

src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const CHUNK_SIZE = 65536
1010
const ADDRESS_SIZE = 10
1111

1212
export default class Trix {
13+
private decoder = new TextDecoder('utf8')
14+
private indexCache?: readonly (readonly [string, number])[]
15+
1316
constructor(
1417
public ixxFile: GenericFilehandle,
1518
public ixFile: GenericFilehandle,
@@ -29,11 +32,9 @@ export default class Trix {
2932

3033
let { end, buffer } = res
3134
let done = false
32-
const decoder = new TextDecoder('utf8')
3335
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3436
while (!done) {
35-
let foundSomething = false
36-
const str = decoder.decode(buffer)
37+
const str = this.decoder.decode(buffer)
3738

3839
// slice to lastIndexOf('\n') to make sure we get complete records
3940
// since the buffer fetch could get halfway into a record
@@ -46,9 +47,6 @@ export default class Trix {
4647
for (const line of lines) {
4748
const word = line.split(' ')[0]
4849
const match = word.startsWith(searchWord)
49-
if (!foundSomething && match) {
50-
foundSomething = true
51-
}
5250

5351
// we are done scanning if we are lexicographically greater than the
5452
// search string
@@ -91,11 +89,14 @@ export default class Trix {
9189
}
9290

9391
private async getIndex(opts?: { signal?: AbortSignal }) {
92+
if (this.indexCache) {
93+
return this.indexCache
94+
}
9495
const file = await this.ixxFile.readFile({
9596
encoding: 'utf8',
9697
...opts,
9798
})
98-
return file
99+
const result = file
99100
.split('\n')
100101
.filter(f => !!f)
101102
.map(line => {
@@ -105,20 +106,22 @@ export default class Trix {
105106
const pos = Number.parseInt(posStr, 16)
106107
return [prefix, pos] as const
107108
})
109+
this.indexCache = result
110+
return result
108111
}
109112

110113
private async _getBuffer(
111114
searchWord: string,
112115
opts?: { signal?: AbortSignal },
113116
) {
114117
let start = 0
115-
let end = 65536
118+
let end = CHUNK_SIZE
116119
const indexes = await this.getIndex(opts)
117120
for (const [key, value] of indexes) {
118121
const trimmedKey = key.slice(0, searchWord.length)
119122
if (trimmedKey < searchWord) {
120123
start = value
121-
end = value + 65536
124+
end = value + CHUNK_SIZE
122125
}
123126
}
124127

test/testData/D39V_annotation_coding_features_sorted.gff_meta.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
"NCBI_locus",
1313
"Alias"
1414
],
15-
"excludedTypes": [
16-
"CDS",
17-
"exon"
18-
],
15+
"excludedTypes": ["CDS", "exon"],
1916
"adapterConf": {
2017
"type": "Gff3TabixAdapter",
2118
"gffGzLocation": {
@@ -31,7 +28,5 @@
3128
}
3229
}
3330
],
34-
"assemblyNames": [
35-
"D39V"
36-
]
37-
}
31+
"assemblyNames": ["D39V"]
32+
}

test/testData/test4/j.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
{"gmg20150304_scaffold_7313":{"exact":[["GmG20150304_scaffold_7313",1000,"GmG20150304_scaffold_7313",null,0,1000,null]],"prefix":[]}}
1+
{
2+
"gmg20150304_scaffold_7313": {
3+
"exact": [
4+
[
5+
"GmG20150304_scaffold_7313",
6+
1000,
7+
"GmG20150304_scaffold_7313",
8+
null,
9+
0,
10+
1000,
11+
null
12+
]
13+
],
14+
"prefix": []
15+
}
16+
}

tsconfig.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{
22
"compilerOptions": {
33
"moduleResolution": "node",
4-
"lib": [
5-
"es2017",
6-
"es7",
7-
"es6",
8-
"dom"
9-
],
4+
"lib": ["es2017", "es7", "es6", "dom"],
105
"declaration": true,
116
"outDir": "dist",
127
"strict": true,
@@ -15,7 +10,5 @@
1510
"rewriteRelativeImportExtensions": true,
1611
"esModuleInterop": true
1712
},
18-
"include": [
19-
"src"
20-
]
13+
"include": ["src"]
2114
}

0 commit comments

Comments
 (0)