UNPKG

@gmod/cram

Version:

read CRAM files with pure Javascript

36 lines 1.44 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const _base_ts_1 = __importDefault(require("./_base.js")); const getBits_ts_1 = require("./getBits.js"); const errors_ts_1 = require("../../errors.js"); class SubexpCodec extends _base_ts_1.default { constructor(parameters, dataType) { super(parameters, dataType); if (this.dataType !== 'int') { throw new errors_ts_1.CramUnimplementedError(`${this.dataType} decoding not yet implemented by SUBEXP codec`); } } decode(_slice, coreDataBlock, _blocksByContentId, cursors) { let numLeadingOnes = 0; while ((0, getBits_ts_1.getBits)(coreDataBlock.content, cursors.coreBlock, 1)) { numLeadingOnes = numLeadingOnes + 1; } let b; let n; if (numLeadingOnes === 0) { b = this.parameters.K; n = (0, getBits_ts_1.getBits)(coreDataBlock.content, cursors.coreBlock, b); } else { b = numLeadingOnes + this.parameters.K - 1; const bits = (0, getBits_ts_1.getBits)(coreDataBlock.content, cursors.coreBlock, b); n = (1 << b) | bits; } return n - this.parameters.offset; } } exports.default = SubexpCodec; //# sourceMappingURL=subexp.js.map