diff --git a/eslint.config.mjs b/eslint.config.mjs index 691bc03b..14717446 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -4,7 +4,7 @@ import tseslint from 'typescript-eslint' export default tseslint.config( { - ignores: ['esm/**/*', 'dist/**/*'], + ignores: ['esm/**/*', 'dist/**/*', '*.js', '*.mjs', 'example/*'], }, { languageOptions: { diff --git a/src/craiIndex.ts b/src/craiIndex.ts index 53ce8e62..15b34da1 100644 --- a/src/craiIndex.ts +++ b/src/craiIndex.ts @@ -21,16 +21,17 @@ type ParsedIndex = Record function addRecordToIndex(index: ParsedIndex, record: number[]) { const [seqId, start, span, containerStart, sliceStart, sliceBytes] = record - if (!index[seqId]) { - index[seqId] = [] + const s = seqId! + if (!index[s]) { + index[s] = [] } - index[seqId].push({ - start, - span, - containerStart, - sliceStart, - sliceBytes, + index[s].push({ + start: start!, + span: span!, + containerStart: containerStart!, + sliceStart: sliceStart!, + sliceBytes: sliceBytes!, }) } diff --git a/src/cramFile/codecs/byteArrayLength.ts b/src/cramFile/codecs/byteArrayLength.ts index ce2db4b3..fb7d69ae 100644 --- a/src/cramFile/codecs/byteArrayLength.ts +++ b/src/cramFile/codecs/byteArrayLength.ts @@ -23,11 +23,6 @@ export default class ByteArrayStopCodec extends CramCodec< ) { super(parameters, dataType) this.instantiateCodec = instantiateCodec - if (dataType !== 'byteArray') { - throw new TypeError( - `byteArrayLength does not support data type ${dataType}`, - ) - } } decode( diff --git a/src/cramFile/codecs/byteArrayStop.ts b/src/cramFile/codecs/byteArrayStop.ts index 2495e1cc..7f0a494b 100644 --- a/src/cramFile/codecs/byteArrayStop.ts +++ b/src/cramFile/codecs/byteArrayStop.ts @@ -10,18 +10,6 @@ export default class ByteArrayStopCodec extends CramCodec< 'byteArray', ByteArrayStopCramEncoding['parameters'] > { - constructor( - parameters: ByteArrayStopCramEncoding['parameters'], - dataType: 'byteArray', - ) { - super(parameters, dataType) - if (dataType !== 'byteArray') { - throw new TypeError( - `byteArrayStop codec does not support data type ${dataType}`, - ) - } - } - decode( slice: CramSlice, coreDataBlock: CramFileBlock, diff --git a/src/cramFile/codecs/external.ts b/src/cramFile/codecs/external.ts index 672e41ff..c6f144fe 100644 --- a/src/cramFile/codecs/external.ts +++ b/src/cramFile/codecs/external.ts @@ -64,6 +64,6 @@ export default class ExternalCodec extends CramCodec< 'attempted to read beyond end of block. this file seems truncated.', ) } - return contentBlock.content[cursor.bytePosition++] + return contentBlock.content[cursor.bytePosition++]! } } diff --git a/src/cramFile/codecs/getBits.ts b/src/cramFile/codecs/getBits.ts index 4edf95db..18c3f386 100644 --- a/src/cramFile/codecs/getBits.ts +++ b/src/cramFile/codecs/getBits.ts @@ -17,7 +17,7 @@ export function getBits( for (let dlen = numBits; dlen; dlen--) { // get the next `dlen` bits in the input, put them in val val <<= 1 - val |= (data[cursor.bytePosition] >> cursor.bitPosition) & 1 + val |= (data[cursor.bytePosition]! >> cursor.bitPosition) & 1 cursor.bitPosition -= 1 if (cursor.bitPosition < 0) { cursor.bytePosition += 1 diff --git a/src/cramFile/codecs/huffman.ts b/src/cramFile/codecs/huffman.ts index 159ee9ae..ddd01083 100644 --- a/src/cramFile/codecs/huffman.ts +++ b/src/cramFile/codecs/huffman.ts @@ -48,7 +48,7 @@ export default class HuffmanIntCodec extends CramCodec< // if this is a degenerate zero-length huffman code, special-case the // decoding - if (this.sortedCodes[0].bitLength === 0) { + if (this.sortedCodes[0]!.bitLength === 0) { this._decode = this._decodeZeroLengthCode } } @@ -58,10 +58,10 @@ export default class HuffmanIntCodec extends CramCodec< let codes = new Array<{ symbol: number; bitLength: number }>( this.parameters.numCodes, ) - for (let i = 0; i < this.parameters.numCodes; i += 1) { + for (let i = 0; i < this.parameters.numCodes; i++) { codes[i] = { - symbol: this.parameters.symbols[i], - bitLength: this.parameters.bitLengths[i], + symbol: this.parameters.symbols[i]!, + bitLength: this.parameters.bitLengths[i]!, } } // sort the codes by bit length and symbol value @@ -74,7 +74,7 @@ export default class HuffmanIntCodec extends CramCodec< if (!this.codeBook[code.bitLength]) { this.codeBook[code.bitLength] = [] } - this.codeBook[code.bitLength].push(code.symbol) + this.codeBook[code.bitLength]!.push(code.symbol) }) } @@ -117,7 +117,7 @@ export default class HuffmanIntCodec extends CramCodec< this.bitCodeToValue = new Array(maxBitCode + 1).fill(-1) for (let i = 0; i < this.sortedBitCodes.length; i += 1) { - this.bitCodeToValue[this.sortedCodes[i].bitCode] = i + this.bitCodeToValue[this.sortedCodes[i]!.bitCode] = i } } @@ -136,7 +136,7 @@ export default class HuffmanIntCodec extends CramCodec< // the special case for zero-length codes _decodeZeroLengthCode() { - return this.sortedCodes[0].value + return this.sortedCodes[0]!.value } _decode(slice: CramSlice, coreDataBlock: CramFileBlock, coreCursor: Cursor) { @@ -145,19 +145,19 @@ export default class HuffmanIntCodec extends CramCodec< let prevLen = 0 let bits = 0 for (let i = 0; i < this.sortedCodes.length; i += 1) { - const length = this.sortedCodes[i].bitLength + const length = this.sortedCodes[i]!.bitLength bits <<= length - prevLen bits |= getBits(input, coreCursor, length - prevLen) prevLen = length { - const index = this.bitCodeToValue[bits] + const index = this.bitCodeToValue[bits]! if (index > -1 && this.sortedBitLengthsByBitCode[index] === length) { - return this.sortedValuesByBitCode[index] + return this.sortedValuesByBitCode[index]! } for ( let j = i; - this.sortedCodes[j + 1].bitLength === length && + this.sortedCodes[j + 1]!.bitLength === length && j < this.sortedCodes.length; j += 1 ) { diff --git a/src/cramFile/container/compressionScheme.ts b/src/cramFile/container/compressionScheme.ts index a198e770..a4b0781a 100644 --- a/src/cramFile/container/compressionScheme.ts +++ b/src/cramFile/container/compressionScheme.ts @@ -53,30 +53,30 @@ function parseSubstitutionMatrix(byteArray: number[]) { matrix[i] = new Array(4) } - matrix[0][(byteArray[0] >> 6) & 3] = 'C' - matrix[0][(byteArray[0] >> 4) & 3] = 'G' - matrix[0][(byteArray[0] >> 2) & 3] = 'T' - matrix[0][(byteArray[0] >> 0) & 3] = 'N' - - matrix[1][(byteArray[1] >> 6) & 3] = 'A' - matrix[1][(byteArray[1] >> 4) & 3] = 'G' - matrix[1][(byteArray[1] >> 2) & 3] = 'T' - matrix[1][(byteArray[1] >> 0) & 3] = 'N' - - matrix[2][(byteArray[2] >> 6) & 3] = 'A' - matrix[2][(byteArray[2] >> 4) & 3] = 'C' - matrix[2][(byteArray[2] >> 2) & 3] = 'T' - matrix[2][(byteArray[2] >> 0) & 3] = 'N' - - matrix[3][(byteArray[3] >> 6) & 3] = 'A' - matrix[3][(byteArray[3] >> 4) & 3] = 'C' - matrix[3][(byteArray[3] >> 2) & 3] = 'G' - matrix[3][(byteArray[3] >> 0) & 3] = 'N' - - matrix[4][(byteArray[4] >> 6) & 3] = 'A' - matrix[4][(byteArray[4] >> 4) & 3] = 'C' - matrix[4][(byteArray[4] >> 2) & 3] = 'G' - matrix[4][(byteArray[4] >> 0) & 3] = 'T' + matrix[0]![(byteArray[0]! >> 6) & 3] = 'C' + matrix[0]![(byteArray[0]! >> 4) & 3] = 'G' + matrix[0]![(byteArray[0]! >> 2) & 3] = 'T' + matrix[0]![(byteArray[0]! >> 0) & 3] = 'N' + + matrix[1]![(byteArray[1]! >> 6) & 3] = 'A' + matrix[1]![(byteArray[1]! >> 4) & 3] = 'G' + matrix[1]![(byteArray[1]! >> 2) & 3] = 'T' + matrix[1]![(byteArray[1]! >> 0) & 3] = 'N' + + matrix[2]![(byteArray[2]! >> 6) & 3] = 'A' + matrix[2]![(byteArray[2]! >> 4) & 3] = 'C' + matrix[2]![(byteArray[2]! >> 2) & 3] = 'T' + matrix[2]![(byteArray[2]! >> 0) & 3] = 'N' + + matrix[3]![(byteArray[3]! >> 6) & 3] = 'A' + matrix[3]![(byteArray[3]! >> 4) & 3] = 'C' + matrix[3]![(byteArray[3]! >> 2) & 3] = 'G' + matrix[3]![(byteArray[3]! >> 0) & 3] = 'N' + + matrix[4]![(byteArray[4]! >> 6) & 3] = 'A' + matrix[4]![(byteArray[4]! >> 4) & 3] = 'C' + matrix[4]![(byteArray[4]! >> 2) & 3] = 'G' + matrix[4]![(byteArray[4]! >> 0) & 3] = 'T' return matrix } @@ -145,8 +145,10 @@ export default class CramContainerCompressionScheme { this.dataSeriesCodecCache[dataSeriesName] if (r === undefined) { const encodingData = this.dataSeriesEncoding[dataSeriesName] + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (encodingData) { const dataType = dataSeriesTypes[dataSeriesName] + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!dataType) { throw new CramMalformedError( `data series name ${dataSeriesName} not defined in file compression header`, diff --git a/src/cramFile/file.ts b/src/cramFile/file.ts index 1a8d2fb1..9ba45aa7 100644 --- a/src/cramFile/file.ts +++ b/src/cramFile/file.ts @@ -279,7 +279,7 @@ export default class CramFile { }, position: number, size = section.maxLength, - preReadBuffer = undefined, + preReadBuffer?: Buffer, ) { let buffer: Buffer if (preReadBuffer) { diff --git a/src/cramFile/record.ts b/src/cramFile/record.ts index 9b7f75ae..442f8856 100644 --- a/src/cramFile/record.ts +++ b/src/cramFile/record.ts @@ -42,7 +42,7 @@ function decodeReadSequence(cramRecord: CramRecord, refRegion: RefRegion) { let currentReadFeature = 0 while (bases.length < cramRecord.readLength) { if (currentReadFeature < cramRecord.readFeatures.length) { - const feature = cramRecord.readFeatures[currentReadFeature] + const feature = cramRecord.readFeatures[currentReadFeature]! if (feature.code === 'Q' || feature.code === 'q') { currentReadFeature += 1 } else if (feature.pos === bases.length + 1) { @@ -90,10 +90,7 @@ function decodeReadSequence(cramRecord: CramRecord, refRegion: RefRegion) { // put down a chunk of sequence up to the next read feature const chunk = refRegion.seq.slice( regionPos, - regionPos + - cramRecord.readFeatures[currentReadFeature].pos - - bases.length - - 1, + regionPos + feature.pos - bases.length - 1, ) bases += chunk regionPos += chunk.length @@ -131,10 +128,6 @@ function decodeBaseSubstitution( compressionScheme: CramContainerCompressionScheme, readFeature: ReadFeature, ) { - if (!refRegion) { - return - } - // decode base substitution code using the substitution matrix const refCoord = readFeature.refPos - refRegion.start const refBase = refRegion.seq.charAt(refCoord) @@ -145,7 +138,7 @@ function decodeBaseSubstitution( if (baseNumber === undefined) { baseNumber = 4 } - const substitutionScheme = compressionScheme.substitutionMatrix[baseNumber] + const substitutionScheme = compressionScheme.substitutionMatrix[baseNumber]! const base = substitutionScheme[readFeature.data] if (base) { readFeature.sub = base diff --git a/src/cramFile/sectionParsers.ts b/src/cramFile/sectionParsers.ts index f9eeb1fe..d8dc3022 100644 --- a/src/cramFile/sectionParsers.ts +++ b/src/cramFile/sectionParsers.ts @@ -179,8 +179,8 @@ export function cramPreservationMap() { const ents = [] for (let i = 0; i < mapCount; i++) { const key = - String.fromCharCode(buffer[offset]) + - String.fromCharCode(buffer[offset + 1]) + String.fromCharCode(buffer[offset]!) + + String.fromCharCode(buffer[offset + 1]!) offset += 2 if ( @@ -550,8 +550,8 @@ function cramDataSeriesEncodingMap() { const ents = [] for (let i = 0; i < mapCount; i++) { const key = - String.fromCharCode(buffer[offset]) + - String.fromCharCode(buffer[offset + 1]) + String.fromCharCode(buffer[offset]!) + + String.fromCharCode(buffer[offset + 1]!) offset += 2 const { value, offset: newOffset4 } = cramEncodingSub(buffer, offset) diff --git a/src/cramFile/slice/decodeRecord.ts b/src/cramFile/slice/decodeRecord.ts index 2d542af4..59ff2dcd 100644 --- a/src/cramFile/slice/decodeRecord.ts +++ b/src/cramFile/slice/decodeRecord.ts @@ -22,7 +22,7 @@ import { DataSeriesEncodingKey } from '../codecs/dataSeriesTypes' function readNullTerminatedString(buffer: Uint8Array) { let r = '' for (let i = 0; i < buffer.length && buffer[i] !== 0; i++) { - r += String.fromCharCode(buffer[i]) + r += String.fromCharCode(buffer[i]!) } return r } @@ -32,8 +32,8 @@ function readNullTerminatedString(buffer: Uint8Array) { * @private */ function parseTagValueArray(buffer: Buffer) { - const arrayType = String.fromCharCode(buffer[0]) - const length = Int32Array.from(buffer.slice(1))[0] + const arrayType = String.fromCharCode(buffer[0]!) + const length = Int32Array.from(buffer.slice(1))[0]! const array: number[] = new Array(length) buffer = buffer.slice(5) @@ -41,37 +41,37 @@ function parseTagValueArray(buffer: Buffer) { if (arrayType === 'c') { const arr = new Int8Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 'C') { const arr = new Uint8Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 's') { const arr = new Int16Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 'S') { const arr = new Uint16Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 'i') { const arr = new Int32Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 'I') { const arr = new Uint32Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else if (arrayType === 'f') { const arr = new Float32Array(buffer.buffer) for (let i = 0; i < length; i += 1) { - array[i] = arr[i] + array[i] = arr[i]! } } else { throw new Error(`unknown type: ${arrayType}`) @@ -311,26 +311,17 @@ export default function decodeRecord( const tags: Record = {} // TN = tag names - const TN = compressionScheme.getTagNames(TLindex) + const TN = compressionScheme.getTagNames(TLindex)! const ntags = TN.length for (let i = 0; i < ntags; i += 1) { - const tagId = TN[i] + const tagId = TN[i]! const tagName = tagId.slice(0, 2) const tagType = tagId.slice(2, 3) - const tagCodec = compressionScheme.getCodecForTag(tagId) - if (!tagCodec) { - throw new CramMalformedError( - `no codec defined for auxiliary tag ${tagId}`, - ) - } - const tagData = tagCodec.decode( - slice, - coreDataBlock, - blocksByContentId, - cursors, - ) + const tagData = compressionScheme + .getCodecForTag(tagId) + .decode(slice, coreDataBlock, blocksByContentId, cursors) tags[tagName] = parseTagData(tagType, tagData) } diff --git a/src/cramFile/slice/index.ts b/src/cramFile/slice/index.ts index f777df1a..fbe5076a 100644 --- a/src/cramFile/slice/index.ts +++ b/src/cramFile/slice/index.ts @@ -237,7 +237,7 @@ export default class CramSlice { throw new Error('block undefined') } blocks[i] = block - blockPosition = blocks[i]._endPosition + blockPosition = blocks[i]!._endPosition } return blocks @@ -246,8 +246,7 @@ export default class CramSlice { // no memoize async getCoreDataBlock() { const blocks = await this.getBlocks() - // the core data block is always the first block in the slice - return blocks[0] + return blocks[0]! } // memoize @@ -352,10 +351,6 @@ export default class CramSlice { } const sliceHeader = await this.getHeader() - if (sliceHeader === undefined) { - throw new Error('slice header undefined') - } - const blocksByContentId = await this._getBlocksContentIdIndex() // check MD5 of reference if available @@ -424,7 +419,7 @@ export default class CramSlice { ) return decoded } - let records: CramRecord[] = new Array(sliceHeader.parsedContent.numRecords) + const records: CramRecord[] = new Array(sliceHeader.parsedContent.numRecords) for (let i = 0; i < records.length; i += 1) { try { const init = decodeRecord( @@ -451,7 +446,6 @@ export default class CramSlice { console.warn( 'read attempted beyond end of buffer, file seems truncated.', ) - records = records.filter(r => !!r) break } else { throw e @@ -462,13 +456,13 @@ export default class CramSlice { // interpret `recordsToNextFragment` attributes to make standard `mate` // objects Resolve mate pair cross-references between records in this slice for (let i = 0; i < records.length; i += 1) { - const { mateRecordNumber } = records[i] + const { mateRecordNumber } = records[i]! if (mateRecordNumber !== undefined && mateRecordNumber >= 0) { associateIntraSliceMate( records, i, - records[i], - records[mateRecordNumber], + records[i]!, + records[mateRecordNumber]!, ) } } diff --git a/src/cramFile/util.ts b/src/cramFile/util.ts index 5b7068e0..cd476054 100644 --- a/src/cramFile/util.ts +++ b/src/cramFile/util.ts @@ -20,34 +20,34 @@ export function itf8Size(v: number) { export function parseItf8(buffer: Uint8Array, initialOffset: number) { let offset = initialOffset - const countFlags = buffer[offset] + const countFlags = buffer[offset]! let result: number if (countFlags < 0x80) { result = countFlags offset = offset + 1 } else if (countFlags < 0xc0) { - result = ((countFlags << 8) | buffer[offset + 1]) & 0x3fff + result = ((countFlags << 8) | buffer[offset + 1]!) & 0x3fff offset = offset + 2 } else if (countFlags < 0xe0) { result = - ((countFlags << 16) | (buffer[offset + 1] << 8) | buffer[offset + 2]) & + ((countFlags << 16) | (buffer[offset + 1]! << 8) | buffer[offset + 2]!) & 0x1fffff offset = offset + 3 } else if (countFlags < 0xf0) { result = ((countFlags << 24) | - (buffer[offset + 1] << 16) | - (buffer[offset + 2] << 8) | - buffer[offset + 3]) & + (buffer[offset + 1]! << 16) | + (buffer[offset + 2]! << 8) | + buffer[offset + 3]!) & 0x0fffffff offset = offset + 4 } else { result = ((countFlags & 0x0f) << 28) | - (buffer[offset + 1] << 20) | - (buffer[offset + 2] << 12) | - (buffer[offset + 3] << 4) | - (buffer[offset + 4] & 0x0f) + (buffer[offset + 1]! << 20) | + (buffer[offset + 2]! << 12) | + (buffer[offset + 3]! << 4) | + (buffer[offset + 4]! & 0x0f) // x=((0xff & 0x0f)<<28) | (0xff<<20) | (0xff<<12) | (0xff<<4) | (0x0f & 0x0f); // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1; offset = offset + 5 @@ -62,56 +62,56 @@ export function parseItf8(buffer: Uint8Array, initialOffset: number) { export function parseLtf8(buffer: Buffer, initialOffset: number) { let offset = initialOffset - const countFlags = buffer[offset] + const countFlags = buffer[offset]! let n: number | Long if (countFlags < 0x80) { n = countFlags offset += 1 } else if (countFlags < 0xc0) { - n = ((buffer[offset] << 8) | buffer[offset + 1]) & 0x3fff + n = ((buffer[offset]! << 8) | buffer[offset + 1]!) & 0x3fff offset += 2 } else if (countFlags < 0xe0) { n = - ((buffer[offset] << 16) | - (buffer[offset + 1] << 8) | - buffer[offset + 2]) & + ((buffer[offset]! << 16) | + (buffer[offset + 1]! << 8) | + buffer[offset + 2]!) & 0x1fffff n = ((countFlags & 63) << 16) | buffer.readUInt16LE(offset + 1) offset += 3 } else if (countFlags < 0xf0) { n = - ((buffer[offset] << 24) | - (buffer[offset + 1] << 16) | - (buffer[offset + 2] << 8) | - buffer[offset + 3]) & + ((buffer[offset]! << 24) | + (buffer[offset + 1]! << 16) | + (buffer[offset + 2]! << 8) | + buffer[offset + 3]!) & 0x0fffffff offset += 4 } else if (countFlags < 0xf8) { n = - ((buffer[offset] & 15) * 2 ** 32 + (buffer[offset + 1] << 24)) | - ((buffer[offset + 2] << 16) | - (buffer[offset + 3] << 8) | - buffer[offset + 4]) + ((buffer[offset]! & 15) * 2 ** 32 + (buffer[offset + 1]! << 24)) | + ((buffer[offset + 2]! << 16) | + (buffer[offset + 3]! << 8) | + buffer[offset + 4]!) // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1; offset += 5 } else if (countFlags < 0xfc) { n = - ((((buffer[offset] & 7) << 8) | buffer[offset + 1]) * 2 ** 32 + - (buffer[offset + 2] << 24)) | - ((buffer[offset + 3] << 16) | - (buffer[offset + 4] << 8) | - buffer[offset + 5]) + ((((buffer[offset]! & 7) << 8) | buffer[offset + 1]!) * 2 ** 32 + + (buffer[offset + 2]! << 24)) | + ((buffer[offset + 3]! << 16) | + (buffer[offset + 4]! << 8) | + buffer[offset + 5]!) offset += 6 } else if (countFlags < 0xfe) { n = - ((((buffer[offset] & 3) << 16) | - (buffer[offset + 1] << 8) | - buffer[offset + 2]) * + ((((buffer[offset]! & 3) << 16) | + (buffer[offset + 1]! << 8) | + buffer[offset + 2]!) * 2 ** 32 + - (buffer[offset + 3] << 24)) | - ((buffer[offset + 4] << 16) | - (buffer[offset + 5] << 8) | - buffer[offset + 6]) + (buffer[offset + 3]! << 24)) | + ((buffer[offset + 4]! << 16) | + (buffer[offset + 5]! << 8) | + buffer[offset + 6]!) offset += 7 } else if (countFlags < 0xff) { n = Long.fromBytesBE( @@ -167,6 +167,7 @@ export function tinyMemoize(_class: any, methodName: any) { const res = method.call(this) this[memoAttrName] = res Promise.resolve(res).catch(() => { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete this[memoAttrName] }) } diff --git a/src/indexedCramFile.ts b/src/indexedCramFile.ts index 28a0608c..6245274a 100644 --- a/src/indexedCramFile.ts +++ b/src/indexedCramFile.ts @@ -63,9 +63,6 @@ export default class IndexedCramFile { } this.index = args.index - if (!this.index.getEntriesForRange) { - throw new Error('invalid arguments: not an index') - } } /** @@ -163,7 +160,7 @@ export default class IndexedCramFile { .sort((a, b) => a.toString().localeCompare(b.toString())) .filter( (item, pos, ary) => - !pos || item.toString() !== ary[pos - 1].toString(), + !pos || item.toString() !== ary[pos - 1]!.toString(), ) const mateRecordPromises = [] diff --git a/test/crai.test.ts b/test/crai.test.ts index 7caa4615..5fc64d0e 100644 --- a/test/crai.test.ts +++ b/test/crai.test.ts @@ -61,7 +61,7 @@ describe('.crai reader', () => { () => { throw new Error('the getIndex call should have failed') }, - err => { + (err: unknown) => { expect(`${err}`).toMatch(/invalid/) }, ) @@ -145,7 +145,7 @@ describe('reading a BAI file instead', () => { () => { throw new Error('the getIndex call should have failed') }, - err => { + (err: unknown) => { expect(`${err}`).toMatch(/bai/) }, ) diff --git a/test/cram2sam.ts b/test/cram2sam.ts index eb177885..6c37678a 100644 --- a/test/cram2sam.ts +++ b/test/cram2sam.ts @@ -109,7 +109,7 @@ function decodeSeqCigar(record: CramRecord) { if (oplen) { cigar += oplen + op } - cigar += `${1}I` + cigar += `1I` oplen = 0 } else if (code === 'P') { // Padding diff --git a/test/indexedfile.test.ts b/test/indexedfile.test.ts index 311ac647..6f1309b9 100644 --- a/test/indexedfile.test.ts +++ b/test/indexedfile.test.ts @@ -56,8 +56,16 @@ describe('.crai indexed cram file', () => { }), }) - const features = await cram.getRecordsForRange(0, 0, Number.POSITIVE_INFINITY) - const features2 = await cram.getRecordsForRange(-1, 0, Number.POSITIVE_INFINITY) + const features = await cram.getRecordsForRange( + 0, + 0, + Number.POSITIVE_INFINITY, + ) + const features2 = await cram.getRecordsForRange( + -1, + 0, + Number.POSITIVE_INFINITY, + ) expect(features).toMatchSnapshot() expect(features2).toMatchSnapshot() }) @@ -104,7 +112,11 @@ describe('.crai indexed cram file', () => { index: new CraiIndex({ filehandle: testDataFile(`${filename}.crai`) }), }) - const features = await cram.getRecordsForRange(0, 0, Number.POSITIVE_INFINITY) + const features = await cram.getRecordsForRange( + 0, + 0, + Number.POSITIVE_INFINITY, + ) features.sort((a, b) => (a.readName || '').localeCompare(b.readName || ''), ) @@ -118,7 +130,11 @@ describe('.crai indexed cram file', () => { index: new CraiIndex({ filehandle: testDataFile(`${filename}.crai`) }), }) - const features = await cram.getRecordsForRange(1, 0, Number.POSITIVE_INFINITY) + const features = await cram.getRecordsForRange( + 1, + 0, + Number.POSITIVE_INFINITY, + ) expect(features.length).toBeGreaterThan(-1) expect(features).toMatchSnapshot() }) @@ -239,8 +255,8 @@ test('region not downloading enough records', async () => { }) const entries = await index.getEntriesForRange(0, 75100635, 75125544) expect(entries.length).toEqual(2) - expect(entries[0].start).toEqual(74378949) - expect(entries[1].start).toEqual(74945118) + expect(entries[0]!.start).toEqual(74378949) + expect(entries[1]!.start).toEqual(74945118) }) test('troublesome file returns the correct sequence', async () => { diff --git a/test/lib/fasta/index.ts b/test/lib/fasta/index.ts index 17c1c57e..063aba02 100644 --- a/test/lib/fasta/index.ts +++ b/test/lib/fasta/index.ts @@ -4,7 +4,7 @@ function parseSmallFasta(text: string) { .filter(t => /\S/.test(t)) .map(entryText => { const [defLine, ...seq] = entryText.split('\n') - const [id, ...des] = defLine.split(' ') + const [id, ...des] = defLine!.split(' ') const description = des.join(' ') const sequence = seq.join('').replace(/\s/g, '') return { id, description, sequence }