diff --git a/.prettierrc.json b/.prettierrc.json index c3e9304..b6cb800 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,7 @@ { "semi": false, - "singleQuote": true, "trailingComma": "all", + "singleQuote": true, "arrowParens": "avoid", "proseWrap": "always" } diff --git a/src/bai.ts b/src/bai.ts index 86bd25d..1d29a5d 100644 --- a/src/bai.ts +++ b/src/bai.ts @@ -26,6 +26,8 @@ function reg2bins(beg: number, end: number) { } export default class BAI extends IndexFile { + public setupP?: ReturnType + async lineCount(refId: number, opts?: BaseOpts) { const indexData = await this.parse(opts) return indexData.indices[refId]?.stats?.lineCount || 0 @@ -166,10 +168,12 @@ export default class BAI extends IndexFile { } const indexData = await this.parse(opts) + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!indexData) { return [] } const ba = indexData.indices[refId] + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!ba) { return [] } @@ -181,10 +185,11 @@ export default class BAI extends IndexFile { // Find chunks in overlapping bins. Leaf bins (< 4681) are not pruned for (const [start, end] of overlappingBins) { for (let bin = start; bin <= end; bin++) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (ba.binIndex[bin]) { const binChunks = ba.binIndex[bin] - for (const chunk of binChunks) { - chunks.push(new Chunk(chunk.minv, chunk.maxv, bin)) + for (const binChunk of binChunks) { + binChunks.push(new Chunk(binChunk.minv, binChunk.maxv, bin)) } } } @@ -199,6 +204,7 @@ export default class BAI extends IndexFile { for (let i = minLin; i <= maxLin; ++i) { const vp = ba.linearIndex[i] + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (vp && (!lowest || vp.compareTo(lowest) < 0)) { lowest = vp } @@ -206,4 +212,19 @@ export default class BAI extends IndexFile { return optimizeChunks(chunks, lowest) } + + async parse(opts: BaseOpts = {}) { + if (!this.setupP) { + this.setupP = this._parse(opts).catch((e: unknown) => { + this.setupP = undefined + throw e + }) + } + return this.setupP + } + + async hasRefSeq(seqId: number, opts: BaseOpts = {}) { + const header = await this.parse(opts) + return !!header.indices[seqId]?.binIndex + } } diff --git a/src/indexFile.ts b/src/indexFile.ts index 5f48c3c..3e1cc90 100644 --- a/src/indexFile.ts +++ b/src/indexFile.ts @@ -1,12 +1,10 @@ import { GenericFilehandle } from 'generic-filehandle' -import VirtualOffset from './virtualOffset' import Chunk from './chunk' import { BaseOpts } from './util' export default abstract class IndexFile { public filehandle: GenericFilehandle public renameRefSeq: (s: string) => string - public setupP?: Promise /** * @param {filehandle} filehandle @@ -23,7 +21,6 @@ export default abstract class IndexFile { this.renameRefSeq = renameRefSeq } public abstract lineCount(refId: number): Promise - protected abstract _parse(opts?: BaseOpts): Promise public abstract indexCov( refId: number, start?: number, @@ -36,28 +33,4 @@ export default abstract class IndexFile { end: number, opts?: BaseOpts, ): Promise - - _findFirstData(data: any, virtualOffset: VirtualOffset) { - const currentFdl = data.firstDataLine - if (currentFdl) { - data.firstDataLine = - currentFdl.compareTo(virtualOffset) > 0 ? virtualOffset : currentFdl - } else { - data.firstDataLine = virtualOffset - } - } - - async parse(opts: BaseOpts = {}) { - if (!this.setupP) { - this.setupP = this._parse(opts).catch(e => { - this.setupP = undefined - throw e - }) - } - return this.setupP - } - - async hasRefSeq(seqId: number, opts: BaseOpts = {}) { - return !!(await this.parse(opts)).indices[seqId]?.binIndex - } }