Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 5, 2024
1 parent a2828e4 commit 87a1d10
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/tabixIndexedFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AbortablePromiseCache from '@gmod/abortable-promise-cache'
import LRU from 'quick-lru'
import { Buffer } from 'buffer'
import { GenericFilehandle, RemoteFile, LocalFile } from 'generic-filehandle'
import { unzip, unzipChunkSlice } from '@gmod/bgzf-filehandle'
Expand Down Expand Up @@ -35,7 +34,7 @@ export default class TabixIndexedFile {
private index: IndexFile
private yieldTime: number
private renameRefSeq: (n: string) => string
private chunkCache: AbortablePromiseCache<Chunk, ReadChunk>
private chunkCache: AbortablePromiseCache<string, Chunk, ReadChunk>

/**
* @param {object} args
Expand Down Expand Up @@ -78,7 +77,7 @@ export default class TabixIndexedFile {
csiFilehandle,
yieldTime = 500,
renameRefSeqs = n => n,
chunkCacheSize = 5 * 2 ** 20,
chunkCacheSize = 20,
}: {
path?: string
filehandle?: GenericFilehandle
Expand Down Expand Up @@ -148,10 +147,23 @@ export default class TabixIndexedFile {

this.renameRefSeq = renameRefSeqs
this.yieldTime = yieldTime
this.chunkCache = new AbortablePromiseCache<Chunk, ReadChunk>({
cache: new LRU({ maxSize: Math.floor(chunkCacheSize / (1 << 16)) }),
fill: (args: Chunk, signal?: AbortSignal) =>
this.readChunk(args, { signal }),
this.chunkCache = new AbortablePromiseCache<string, Chunk, ReadChunk>({
max: chunkCacheSize,
fetchMethod: async (
key,
old,
{
context,
signal,
}: {
context: {
chunk: Chunk
}
signal?: AbortSignal
},
) => {
return this.readChunk(context.chunk, { signal })
},
})
}

Expand Down Expand Up @@ -206,10 +218,12 @@ export default class TabixIndexedFile {
let last = Date.now()
for (const c of chunks) {
let previousStartCoordinate: number | undefined
const { buffer, cpositions, dpositions } = await this.chunkCache.get(
const { buffer, cpositions, dpositions } = await this.chunkCache.fetch(
c.toString(),
c,
signal,
{
signal,
context: { chunk: c },
},
)

checkAbortSignal(signal)
Expand Down

0 comments on commit 87a1d10

Please sign in to comment.