Comparing version 3.0.1 to 4.0.0
@@ -1,12 +0,17 @@ | ||
## [3.0.1](https://github.com/GMOD/bbi-js/compare/v3.0.0...v3.0.1) (2023-04-21) | ||
# [4.0.0](https://github.com/GMOD/bbi-js/compare/v3.0.1...v4.0.0) (2023-05-05) | ||
### Features | ||
* explicit buffer import ([#53](https://github.com/GMOD/bbi-js/issues/53)) ([2699c98](https://github.com/GMOD/bbi-js/commit/2699c983dea380bbb56773058ba3f233c833d9c8)) | ||
- Improve typescripting, refactoring | ||
- Options argument only accepts {signal}, not just signal now | ||
## [3.0.1](https://github.com/GMOD/bbi-js/compare/v3.0.0...v3.0.1) (2023-04-21) | ||
### Features | ||
- Add explicit Buffer import | ||
- explicit buffer import ([#53](https://github.com/GMOD/bbi-js/issues/53)) | ||
([2699c98](https://github.com/GMOD/bbi-js/commit/2699c983dea380bbb56773058ba3f233c833d9c8)) | ||
* Add explicit Buffer import | ||
# [3.0.0](https://github.com/GMOD/bbi-js/compare/v2.0.5...v3.0.0) (2023-01-11) | ||
@@ -13,0 +18,0 @@ |
import { GenericFilehandle } from 'generic-filehandle'; | ||
import { Observable } from 'rxjs'; | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
export interface Feature { | ||
@@ -54,4 +54,4 @@ start: number; | ||
protected renameRefSeqs: (a: string) => string; | ||
getHeader(opts?: RequestOptions | AbortSignal): Promise<Header>; | ||
constructor(options?: { | ||
getHeader(opts?: RequestOptions): Promise<Header>; | ||
constructor(args: { | ||
filehandle?: GenericFilehandle; | ||
@@ -66,4 +66,4 @@ path?: string; | ||
private _readChromTree; | ||
protected getUnzoomedView(opts: RequestOptions): Promise<BlockView>; | ||
protected abstract getView(scale: number, opts: RequestOptions): Promise<BlockView>; | ||
protected getUnzoomedView(opts?: RequestOptions): Promise<BlockView>; | ||
protected abstract getView(scale: number, opts?: RequestOptions): Promise<BlockView>; | ||
/** | ||
@@ -70,0 +70,0 @@ * Gets features from a BigWig file |
@@ -18,3 +18,3 @@ "use strict"; | ||
const operators_1 = require("rxjs/operators"); | ||
const blockView_1 = require("./blockView"); | ||
const block_view_1 = require("./block-view"); | ||
const BIG_WIG_MAGIC = -2003829722; | ||
@@ -87,6 +87,5 @@ const BIG_BED_MAGIC = -2021002517; | ||
*/ | ||
getHeader(opts = {}) { | ||
const options = 'aborted' in opts ? { signal: opts } : opts; | ||
getHeader(opts) { | ||
if (!this.headerP) { | ||
this.headerP = this._getHeader(options).catch(e => { | ||
this.headerP = this._getHeader(opts).catch(e => { | ||
this.headerP = undefined; | ||
@@ -104,4 +103,4 @@ throw e; | ||
*/ | ||
constructor(options = {}) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = options; | ||
constructor(args) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = args; | ||
this.renameRefSeqs = renameRefSeqs; | ||
@@ -237,3 +236,3 @@ if (filehandle) { | ||
const { unzoomedIndexOffset, refsByName, uncompressBufSize, isBigEndian, fileType, } = yield this.getHeader(opts); | ||
return new blockView_1.BlockView(this.bbi, refsByName, unzoomedIndexOffset, isBigEndian, uncompressBufSize > 0, fileType); | ||
return new block_view_1.BlockView(this.bbi, refsByName, unzoomedIndexOffset, isBigEndian, uncompressBufSize > 0, fileType); | ||
}); | ||
@@ -249,5 +248,3 @@ } | ||
*/ | ||
getFeatureStream(refName, start, end, opts = { | ||
scale: 1, | ||
}) { | ||
getFeatureStream(refName, start, end, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -257,7 +254,8 @@ yield this.getHeader(opts); | ||
let view; | ||
if (opts.basesPerSpan) { | ||
view = yield this.getView(1 / opts.basesPerSpan, opts); | ||
const { basesPerSpan, scale } = opts || {}; | ||
if (basesPerSpan) { | ||
view = yield this.getView(1 / basesPerSpan, opts); | ||
} | ||
else if (opts.scale) { | ||
view = yield this.getView(opts.scale, opts); | ||
else if (scale) { | ||
view = yield this.getView(scale, opts); | ||
} | ||
@@ -267,6 +265,3 @@ else { | ||
} | ||
if (!view) { | ||
throw new Error('unable to get block view for data'); | ||
} | ||
return new rxjs_1.Observable((observer) => { | ||
return new rxjs_1.Observable(observer => { | ||
view.readWigData(chrName, start, end, observer, opts); | ||
@@ -276,5 +271,3 @@ }); | ||
} | ||
getFeatures(refName, start, end, opts = { | ||
scale: 1, | ||
}) { | ||
getFeatures(refName, start, end, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -281,0 +274,0 @@ const ob = yield this.getFeatureStream(refName, start, end, opts); |
@@ -0,8 +1,14 @@ | ||
import AbortablePromiseCache from 'abortable-promise-cache'; | ||
import { BBI, Feature, RequestOptions } from './bbi'; | ||
import { BlockView } from './blockView'; | ||
interface Index { | ||
type: number; | ||
fieldcount: number; | ||
offset: number; | ||
field: number; | ||
} | ||
export declare function filterUndef<T>(ts: (T | undefined)[]): T[]; | ||
export declare class BigBed extends BBI { | ||
readIndicesCache: any; | ||
readIndices(opts?: AbortSignal | RequestOptions): any; | ||
protected getView(_scale: number, opts: RequestOptions): Promise<BlockView>; | ||
readIndicesCache: AbortablePromiseCache<RequestOptions, Index[]>; | ||
readIndices(opts?: RequestOptions): Promise<Index[]>; | ||
protected getView(_scale: number, opts?: RequestOptions): Promise<import("./block-view").BlockView>; | ||
private _readIndices; | ||
@@ -12,1 +18,2 @@ private searchExtraIndexBlocks; | ||
} | ||
export {}; |
@@ -11,2 +11,13 @@ "use strict"; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -33,16 +44,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
cache: new quick_lru_1.default({ maxSize: 1 }), | ||
fill: (args, signal) => __awaiter(this, void 0, void 0, function* () { | ||
return this._readIndices(Object.assign(Object.assign({}, args), { signal })); | ||
}), | ||
fill: (args, signal) => this._readIndices(Object.assign(Object.assign({}, args), { signal })), | ||
}); | ||
} | ||
readIndices(opts = {}) { | ||
const options = 'aborted' in opts ? { signal: opts } : opts; | ||
return this.readIndicesCache.get(JSON.stringify(options), options, options.signal); | ||
const { signal } = opts, rest = __rest(opts, ["signal"]); | ||
return this.readIndicesCache.get(JSON.stringify(rest), opts, signal); | ||
} | ||
/* | ||
* retrieve unzoomed view for any scale | ||
* @param scale - unused | ||
* @param abortSignal - an optional AbortSignal to kill operation | ||
* @return promise for a BlockView | ||
*/ | ||
@@ -104,3 +110,3 @@ getView(_scale, opts) { | ||
const indices = yield this.readIndices(opts); | ||
if (!indices.length) { | ||
if (indices.length === 0) { | ||
return []; | ||
@@ -187,3 +193,3 @@ } | ||
const blocks = yield this.searchExtraIndexBlocks(name, opts); | ||
if (!blocks.length) { | ||
if (blocks.length === 0) { | ||
return []; | ||
@@ -196,4 +202,4 @@ } | ||
}).pipe((0, operators_1.reduce)((acc, curr) => acc.concat(curr)), (0, operators_1.map)(x => { | ||
for (let i = 0; i < x.length; i += 1) { | ||
x[i].field = block.field; | ||
for (const element of x) { | ||
element.field = block.field; | ||
} | ||
@@ -200,0 +206,0 @@ return x; |
@@ -1,2 +0,2 @@ | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
import { BBI, RequestOptions } from './bbi'; | ||
@@ -3,0 +3,0 @@ export declare class BigWig extends BBI { |
@@ -13,3 +13,3 @@ "use strict"; | ||
exports.BigWig = void 0; | ||
const blockView_1 = require("./blockView"); | ||
const block_view_1 = require("./block-view"); | ||
const bbi_1 = require("./bbi"); | ||
@@ -36,3 +36,3 @@ class BigWig extends bbi_1.BBI { | ||
const indexOffset = Number(zh.indexOffset); | ||
return new blockView_1.BlockView(this.bbi, refsByName, indexOffset, isBigEndian, uncompressBufSize > 0, 'summary'); | ||
return new block_view_1.BlockView(this.bbi, refsByName, indexOffset, isBigEndian, uncompressBufSize > 0, 'summary'); | ||
} | ||
@@ -39,0 +39,0 @@ } |
@@ -62,3 +62,3 @@ "use strict"; | ||
intersection(arg) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
let s0 = this; | ||
@@ -99,4 +99,3 @@ let s1 = arg; | ||
const rl = this.ranges(); | ||
for (let ri = 0; ri < rl.length; ri += 1) { | ||
const r = rl[ri]; | ||
for (const r of rl) { | ||
tot += r.max() - r.min() + 1; | ||
@@ -111,3 +110,3 @@ } | ||
b = a; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
a = this; | ||
@@ -114,0 +113,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { inflateSync } from 'zlib'; | ||
export { inflateSync as unzip }; | ||
export { inflateSync as unzip } from 'zlib'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unzip = void 0; | ||
const zlib_1 = require("zlib"); | ||
var zlib_1 = require("zlib"); | ||
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return zlib_1.inflateSync; } }); | ||
//# sourceMappingURL=unzip.js.map |
@@ -28,17 +28,17 @@ "use strict"; | ||
let lastBlockEnd; | ||
for (let i = 0; i < blocks.length; i += 1) { | ||
for (const block of blocks) { | ||
if (lastBlock && | ||
lastBlockEnd && | ||
Number(blocks[i].offset) - lastBlockEnd <= 2000) { | ||
Number(block.offset) - lastBlockEnd <= 2000) { | ||
lastBlock.length = BigInt(Number(lastBlock.length) + | ||
Number(blocks[i].length) - | ||
Number(block.length) - | ||
lastBlockEnd + | ||
Number(blocks[i].offset)); | ||
lastBlock.blocks.push(blocks[i]); | ||
Number(block.offset)); | ||
lastBlock.blocks.push(block); | ||
} | ||
else { | ||
blockGroups.push((lastBlock = { | ||
blocks: [blocks[i]], | ||
length: blocks[i].length, | ||
offset: blocks[i].offset, | ||
blocks: [block], | ||
length: block.length, | ||
offset: block.offset, | ||
})); | ||
@@ -68,6 +68,3 @@ } | ||
// console.log('bam aborted!') | ||
if (typeof DOMException !== 'undefined') { | ||
throw new DOMException('aborted', 'AbortError'); | ||
} | ||
else { | ||
if (typeof DOMException === 'undefined') { | ||
const e = new AbortError('aborted'); | ||
@@ -77,2 +74,5 @@ e.code = 'ERR_ABORTED'; | ||
} | ||
else { | ||
throw new DOMException('aborted', 'AbortError'); | ||
} | ||
} | ||
@@ -79,0 +79,0 @@ } |
import { GenericFilehandle } from 'generic-filehandle'; | ||
import { Observable } from 'rxjs'; | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
export interface Feature { | ||
@@ -54,4 +54,4 @@ start: number; | ||
protected renameRefSeqs: (a: string) => string; | ||
getHeader(opts?: RequestOptions | AbortSignal): Promise<Header>; | ||
constructor(options?: { | ||
getHeader(opts?: RequestOptions): Promise<Header>; | ||
constructor(args: { | ||
filehandle?: GenericFilehandle; | ||
@@ -66,4 +66,4 @@ path?: string; | ||
private _readChromTree; | ||
protected getUnzoomedView(opts: RequestOptions): Promise<BlockView>; | ||
protected abstract getView(scale: number, opts: RequestOptions): Promise<BlockView>; | ||
protected getUnzoomedView(opts?: RequestOptions): Promise<BlockView>; | ||
protected abstract getView(scale: number, opts?: RequestOptions): Promise<BlockView>; | ||
/** | ||
@@ -70,0 +70,0 @@ * Gets features from a BigWig file |
@@ -6,3 +6,3 @@ import { Buffer } from 'buffer'; | ||
import { toArray } from 'rxjs/operators'; | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
const BIG_WIG_MAGIC = -2003829722; | ||
@@ -75,6 +75,5 @@ const BIG_BED_MAGIC = -2021002517; | ||
*/ | ||
getHeader(opts = {}) { | ||
const options = 'aborted' in opts ? { signal: opts } : opts; | ||
getHeader(opts) { | ||
if (!this.headerP) { | ||
this.headerP = this._getHeader(options).catch(e => { | ||
this.headerP = this._getHeader(opts).catch(e => { | ||
this.headerP = undefined; | ||
@@ -92,4 +91,4 @@ throw e; | ||
*/ | ||
constructor(options = {}) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = options; | ||
constructor(args) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = args; | ||
this.renameRefSeqs = renameRefSeqs; | ||
@@ -228,13 +227,12 @@ if (filehandle) { | ||
*/ | ||
async getFeatureStream(refName, start, end, opts = { | ||
scale: 1, | ||
}) { | ||
async getFeatureStream(refName, start, end, opts) { | ||
await this.getHeader(opts); | ||
const chrName = this.renameRefSeqs(refName); | ||
let view; | ||
if (opts.basesPerSpan) { | ||
view = await this.getView(1 / opts.basesPerSpan, opts); | ||
const { basesPerSpan, scale } = opts || {}; | ||
if (basesPerSpan) { | ||
view = await this.getView(1 / basesPerSpan, opts); | ||
} | ||
else if (opts.scale) { | ||
view = await this.getView(opts.scale, opts); | ||
else if (scale) { | ||
view = await this.getView(scale, opts); | ||
} | ||
@@ -244,12 +242,7 @@ else { | ||
} | ||
if (!view) { | ||
throw new Error('unable to get block view for data'); | ||
} | ||
return new Observable((observer) => { | ||
return new Observable(observer => { | ||
view.readWigData(chrName, start, end, observer, opts); | ||
}); | ||
} | ||
async getFeatures(refName, start, end, opts = { | ||
scale: 1, | ||
}) { | ||
async getFeatures(refName, start, end, opts) { | ||
const ob = await this.getFeatureStream(refName, start, end, opts); | ||
@@ -256,0 +249,0 @@ const ret = await firstValueFrom(ob.pipe(toArray())); |
@@ -0,8 +1,14 @@ | ||
import AbortablePromiseCache from 'abortable-promise-cache'; | ||
import { BBI, Feature, RequestOptions } from './bbi'; | ||
import { BlockView } from './blockView'; | ||
interface Index { | ||
type: number; | ||
fieldcount: number; | ||
offset: number; | ||
field: number; | ||
} | ||
export declare function filterUndef<T>(ts: (T | undefined)[]): T[]; | ||
export declare class BigBed extends BBI { | ||
readIndicesCache: any; | ||
readIndices(opts?: AbortSignal | RequestOptions): any; | ||
protected getView(_scale: number, opts: RequestOptions): Promise<BlockView>; | ||
readIndicesCache: AbortablePromiseCache<RequestOptions, Index[]>; | ||
readIndices(opts?: RequestOptions): Promise<Index[]>; | ||
protected getView(_scale: number, opts?: RequestOptions): Promise<import("./block-view").BlockView>; | ||
private _readIndices; | ||
@@ -12,1 +18,2 @@ private searchExtraIndexBlocks; | ||
} | ||
export {}; |
@@ -16,16 +16,11 @@ import { Buffer } from 'buffer'; | ||
cache: new QuickLRU({ maxSize: 1 }), | ||
fill: async (args, signal) => { | ||
return this._readIndices({ ...args, signal }); | ||
}, | ||
fill: (args, signal) => this._readIndices({ ...args, signal }), | ||
}); | ||
} | ||
readIndices(opts = {}) { | ||
const options = 'aborted' in opts ? { signal: opts } : opts; | ||
return this.readIndicesCache.get(JSON.stringify(options), options, options.signal); | ||
const { signal, ...rest } = opts; | ||
return this.readIndicesCache.get(JSON.stringify(rest), opts, signal); | ||
} | ||
/* | ||
* retrieve unzoomed view for any scale | ||
* @param scale - unused | ||
* @param abortSignal - an optional AbortSignal to kill operation | ||
* @return promise for a BlockView | ||
*/ | ||
@@ -82,3 +77,3 @@ async getView(_scale, opts) { | ||
const indices = await this.readIndices(opts); | ||
if (!indices.length) { | ||
if (indices.length === 0) { | ||
return []; | ||
@@ -163,3 +158,3 @@ } | ||
const blocks = await this.searchExtraIndexBlocks(name, opts); | ||
if (!blocks.length) { | ||
if (blocks.length === 0) { | ||
return []; | ||
@@ -172,4 +167,4 @@ } | ||
}).pipe(reduce((acc, curr) => acc.concat(curr)), map(x => { | ||
for (let i = 0; i < x.length; i += 1) { | ||
x[i].field = block.field; | ||
for (const element of x) { | ||
element.field = block.field; | ||
} | ||
@@ -176,0 +171,0 @@ return x; |
@@ -1,2 +0,2 @@ | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
import { BBI, RequestOptions } from './bbi'; | ||
@@ -3,0 +3,0 @@ export declare class BigWig extends BBI { |
@@ -1,2 +0,2 @@ | ||
import { BlockView } from './blockView'; | ||
import { BlockView } from './block-view'; | ||
import { BBI } from './bbi'; | ||
@@ -3,0 +3,0 @@ export class BigWig extends BBI { |
@@ -60,3 +60,3 @@ /* eslint prefer-rest-params:0, no-nested-ternary:0 */ | ||
intersection(arg) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
let s0 = this; | ||
@@ -97,4 +97,3 @@ let s1 = arg; | ||
const rl = this.ranges(); | ||
for (let ri = 0; ri < rl.length; ri += 1) { | ||
const r = rl[ri]; | ||
for (const r of rl) { | ||
tot += r.max() - r.min() + 1; | ||
@@ -109,3 +108,3 @@ } | ||
b = a; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
a = this; | ||
@@ -112,0 +111,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { inflateSync } from 'zlib'; | ||
export { inflateSync as unzip }; | ||
export { inflateSync as unzip } from 'zlib'; |
@@ -1,3 +0,2 @@ | ||
import { inflateSync } from 'zlib'; | ||
export { inflateSync as unzip }; | ||
export { inflateSync as unzip } from 'zlib'; | ||
//# sourceMappingURL=unzip.js.map |
@@ -15,17 +15,17 @@ /* eslint no-bitwise: ["error", { "allow": ["|"] }] */ | ||
let lastBlockEnd; | ||
for (let i = 0; i < blocks.length; i += 1) { | ||
for (const block of blocks) { | ||
if (lastBlock && | ||
lastBlockEnd && | ||
Number(blocks[i].offset) - lastBlockEnd <= 2000) { | ||
Number(block.offset) - lastBlockEnd <= 2000) { | ||
lastBlock.length = BigInt(Number(lastBlock.length) + | ||
Number(blocks[i].length) - | ||
Number(block.length) - | ||
lastBlockEnd + | ||
Number(blocks[i].offset)); | ||
lastBlock.blocks.push(blocks[i]); | ||
Number(block.offset)); | ||
lastBlock.blocks.push(block); | ||
} | ||
else { | ||
blockGroups.push((lastBlock = { | ||
blocks: [blocks[i]], | ||
length: blocks[i].length, | ||
offset: blocks[i].offset, | ||
blocks: [block], | ||
length: block.length, | ||
offset: block.offset, | ||
})); | ||
@@ -54,6 +54,3 @@ } | ||
// console.log('bam aborted!') | ||
if (typeof DOMException !== 'undefined') { | ||
throw new DOMException('aborted', 'AbortError'); | ||
} | ||
else { | ||
if (typeof DOMException === 'undefined') { | ||
const e = new AbortError('aborted'); | ||
@@ -63,2 +60,5 @@ e.code = 'ERR_ABORTED'; | ||
} | ||
else { | ||
throw new DOMException('aborted', 'AbortError'); | ||
} | ||
} | ||
@@ -65,0 +65,0 @@ } |
{ | ||
"name": "@gmod/bbi", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Parser for BigWig/BigBed files", | ||
@@ -46,2 +46,3 @@ "license": "MIT", | ||
"binary-parser": "^2.1.0", | ||
"eslint-plugin-unicorn": "^46.0.0", | ||
"generic-filehandle": "^3.0.0", | ||
@@ -54,20 +55,19 @@ "pako": "^2.0.0", | ||
"@gmod/bed": "^2.1.2", | ||
"@types/jest": "^29.2.4", | ||
"@types/jest": "^29.5.0", | ||
"@types/long": "^5.0.0", | ||
"@types/node": "^18.11.15", | ||
"@types/node": "^18.15.7", | ||
"@types/pako": "^2.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.46.1", | ||
"@typescript-eslint/parser": "^5.46.1", | ||
"cross-fetch": "^3.0.2", | ||
"eslint": "^8.29.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.25.3", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"@typescript-eslint/parser": "^5.56.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"prettier": "^2.8.1", | ||
"rimraf": "^3.0.2", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"prettier": "^2.8.7", | ||
"rimraf": "^5.0.0", | ||
"standard-changelog": "^2.0.11", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.9.4" | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^5.0.2" | ||
}, | ||
@@ -74,0 +74,0 @@ "publishConfig": { |
import { Buffer } from 'buffer' | ||
import { Parser } from 'binary-parser' | ||
import { LocalFile, RemoteFile, GenericFilehandle } from 'generic-filehandle' | ||
import { firstValueFrom, Observable, Observer } from 'rxjs' | ||
import { firstValueFrom, Observable } from 'rxjs' | ||
import { toArray } from 'rxjs/operators' | ||
import { BlockView } from './blockView' | ||
import { BlockView } from './block-view' | ||
@@ -133,6 +133,5 @@ const BIG_WIG_MAGIC = -2003829722 | ||
*/ | ||
public getHeader(opts: RequestOptions | AbortSignal = {}) { | ||
const options = 'aborted' in opts ? { signal: opts as AbortSignal } : opts | ||
public getHeader(opts?: RequestOptions) { | ||
if (!this.headerP) { | ||
this.headerP = this._getHeader(options).catch(e => { | ||
this.headerP = this._getHeader(opts).catch(e => { | ||
this.headerP = undefined | ||
@@ -151,11 +150,9 @@ throw e | ||
*/ | ||
public constructor( | ||
options: { | ||
filehandle?: GenericFilehandle | ||
path?: string | ||
url?: string | ||
renameRefSeqs?: (a: string) => string | ||
} = {}, | ||
) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = options | ||
public constructor(args: { | ||
filehandle?: GenericFilehandle | ||
path?: string | ||
url?: string | ||
renameRefSeqs?: (a: string) => string | ||
}) { | ||
const { filehandle, renameRefSeqs = s => s, path, url } = args | ||
this.renameRefSeqs = renameRefSeqs | ||
@@ -173,3 +170,3 @@ if (filehandle) { | ||
private async _getHeader(opts: RequestOptions) { | ||
private async _getHeader(opts?: RequestOptions) { | ||
const header = await this._getMainHeader(opts) | ||
@@ -181,3 +178,3 @@ const chroms = await this._readChromTree(header, opts) | ||
private async _getMainHeader( | ||
opts: RequestOptions, | ||
opts?: RequestOptions, | ||
requestSize = 2000, | ||
@@ -215,3 +212,3 @@ ): Promise<Header> { | ||
private _isBigEndian(buffer: Buffer): boolean { | ||
private _isBigEndian(buffer: Buffer) { | ||
let ret = buffer.readInt32LE(0) | ||
@@ -229,3 +226,6 @@ if (ret === BIG_WIG_MAGIC || ret === BIG_BED_MAGIC) { | ||
// todo: add progress if long running | ||
private async _readChromTree(header: Header, opts: { signal?: AbortSignal }) { | ||
private async _readChromTree( | ||
header: Header, | ||
opts?: { signal?: AbortSignal }, | ||
) { | ||
const isBE = header.isBigEndian | ||
@@ -308,3 +308,3 @@ const le = isBE ? 'big' : 'little' | ||
*/ | ||
protected async getUnzoomedView(opts: RequestOptions): Promise<BlockView> { | ||
protected async getUnzoomedView(opts?: RequestOptions) { | ||
const { | ||
@@ -332,3 +332,3 @@ unzoomedIndexOffset, | ||
scale: number, | ||
opts: RequestOptions, | ||
opts?: RequestOptions, | ||
): Promise<BlockView> | ||
@@ -348,14 +348,13 @@ | ||
end: number, | ||
opts: RequestOptions & { scale?: number; basesPerSpan?: number } = { | ||
scale: 1, | ||
}, | ||
): Promise<Observable<Feature[]>> { | ||
opts?: RequestOptions & { scale?: number; basesPerSpan?: number }, | ||
) { | ||
await this.getHeader(opts) | ||
const chrName = this.renameRefSeqs(refName) | ||
let view: BlockView | ||
const { basesPerSpan, scale } = opts || {} | ||
if (opts.basesPerSpan) { | ||
view = await this.getView(1 / opts.basesPerSpan, opts) | ||
} else if (opts.scale) { | ||
view = await this.getView(opts.scale, opts) | ||
if (basesPerSpan) { | ||
view = await this.getView(1 / basesPerSpan, opts) | ||
} else if (scale) { | ||
view = await this.getView(scale, opts) | ||
} else { | ||
@@ -365,6 +364,3 @@ view = await this.getView(1, opts) | ||
if (!view) { | ||
throw new Error('unable to get block view for data') | ||
} | ||
return new Observable((observer: Observer<Feature[]>): void => { | ||
return new Observable<Feature[]>(observer => { | ||
view.readWigData(chrName, start, end, observer, opts) | ||
@@ -378,5 +374,3 @@ }) | ||
end: number, | ||
opts: RequestOptions & { scale?: number; basesPerSpan?: number } = { | ||
scale: 1, | ||
}, | ||
opts?: RequestOptions & { scale?: number; basesPerSpan?: number }, | ||
) { | ||
@@ -383,0 +377,0 @@ const ob = await this.getFeatureStream(refName, start, end, opts) |
@@ -9,3 +9,2 @@ import { Buffer } from 'buffer' | ||
import { BBI, Feature, RequestOptions } from './bbi' | ||
import { BlockView } from './blockView' | ||
@@ -31,16 +30,11 @@ interface Loc { | ||
export class BigBed extends BBI { | ||
public readIndicesCache = new AbortablePromiseCache({ | ||
public readIndicesCache = new AbortablePromiseCache<RequestOptions, Index[]>({ | ||
cache: new QuickLRU({ maxSize: 1 }), | ||
fill: async (args: any, signal?: AbortSignal) => { | ||
return this._readIndices({ ...args, signal }) | ||
}, | ||
fill: (args: RequestOptions, signal?: AbortSignal) => | ||
this._readIndices({ ...args, signal }), | ||
}) | ||
public readIndices(opts: AbortSignal | RequestOptions = {}) { | ||
const options = 'aborted' in opts ? { signal: opts } : opts | ||
return this.readIndicesCache.get( | ||
JSON.stringify(options), | ||
options, | ||
options.signal, | ||
) | ||
public readIndices(opts: RequestOptions = {}) { | ||
const { signal, ...rest } = opts | ||
return this.readIndicesCache.get(JSON.stringify(rest), opts, signal) | ||
} | ||
@@ -50,10 +44,4 @@ | ||
* retrieve unzoomed view for any scale | ||
* @param scale - unused | ||
* @param abortSignal - an optional AbortSignal to kill operation | ||
* @return promise for a BlockView | ||
*/ | ||
protected async getView( | ||
_scale: number, | ||
opts: RequestOptions, | ||
): Promise<BlockView> { | ||
protected async getView(_scale: number, opts?: RequestOptions) { | ||
return this.getUnzoomedView(opts) | ||
@@ -127,3 +115,3 @@ } | ||
const indices = await this.readIndices(opts) | ||
if (!indices.length) { | ||
if (indices.length === 0) { | ||
return [] | ||
@@ -226,3 +214,3 @@ } | ||
const blocks = await this.searchExtraIndexBlocks(name, opts) | ||
if (!blocks.length) { | ||
if (blocks.length === 0) { | ||
return [] | ||
@@ -237,4 +225,4 @@ } | ||
map(x => { | ||
for (let i = 0; i < x.length; i += 1) { | ||
x[i].field = block.field | ||
for (const element of x) { | ||
element.field = block.field | ||
} | ||
@@ -241,0 +229,0 @@ return x |
@@ -1,2 +0,2 @@ | ||
import { BlockView } from './blockView' | ||
import { BlockView } from './block-view' | ||
import { BBI, RequestOptions } from './bbi' | ||
@@ -3,0 +3,0 @@ |
@@ -72,3 +72,3 @@ /* eslint prefer-rest-params:0, no-nested-ternary:0 */ | ||
public intersection(arg: Range): Range { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
let s0 = this | ||
@@ -113,4 +113,3 @@ let s1 = arg | ||
const rl = this.ranges() | ||
for (let ri = 0; ri < rl.length; ri += 1) { | ||
const r = rl[ri] | ||
for (const r of rl) { | ||
tot += r.max() - r.min() + 1 | ||
@@ -126,3 +125,3 @@ } | ||
b = a | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment | ||
a = this | ||
@@ -129,0 +128,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { inflateSync } from 'zlib' | ||
export { inflateSync as unzip } | ||
export { inflateSync as unzip } from 'zlib' |
@@ -18,21 +18,21 @@ /* eslint no-bitwise: ["error", { "allow": ["|"] }] */ | ||
let lastBlockEnd | ||
for (let i = 0; i < blocks.length; i += 1) { | ||
for (const block of blocks) { | ||
if ( | ||
lastBlock && | ||
lastBlockEnd && | ||
Number(blocks[i].offset) - lastBlockEnd <= 2000 | ||
Number(block.offset) - lastBlockEnd <= 2000 | ||
) { | ||
lastBlock.length = BigInt( | ||
Number(lastBlock.length) + | ||
Number(blocks[i].length) - | ||
Number(block.length) - | ||
lastBlockEnd + | ||
Number(blocks[i].offset), | ||
Number(block.offset), | ||
) | ||
lastBlock.blocks.push(blocks[i]) | ||
lastBlock.blocks.push(block) | ||
} else { | ||
blockGroups.push( | ||
(lastBlock = { | ||
blocks: [blocks[i]], | ||
length: blocks[i].length, | ||
offset: blocks[i].offset, | ||
blocks: [block], | ||
length: block.length, | ||
offset: block.offset, | ||
}), | ||
@@ -65,8 +65,8 @@ ) | ||
// console.log('bam aborted!') | ||
if (typeof DOMException !== 'undefined') { | ||
throw new DOMException('aborted', 'AbortError') | ||
} else { | ||
if (typeof DOMException === 'undefined') { | ||
const e = new AbortError('aborted') | ||
e.code = 'ERR_ABORTED' | ||
throw e | ||
} else { | ||
throw new DOMException('aborted', 'AbortError') | ||
} | ||
@@ -73,0 +73,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18
244983
7
81
4145
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@eslint-community/eslint-utils@4.4.1(transitive)
+ Added@eslint-community/regexpp@4.12.1(transitive)
+ Added@eslint/config-array@0.19.0(transitive)
+ Added@eslint/core@0.9.0(transitive)
+ Added@eslint/eslintrc@3.2.0(transitive)
+ Added@eslint/js@9.15.0(transitive)
+ Added@eslint/object-schema@2.1.4(transitive)
+ Added@eslint/plugin-kit@0.2.3(transitive)
+ Added@humanfs/core@0.19.1(transitive)
+ Added@humanfs/node@0.16.6(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/retry@0.3.10.4.1(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Added@types/normalize-package-data@2.4.4(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-jsx@5.3.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuiltin-modules@3.3.0(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedclean-regexp@1.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.54.0.0(transitive)
+ Addedeslint@9.15.0(transitive)
+ Addedeslint-plugin-unicorn@46.0.1(transitive)
+ Addedeslint-scope@8.2.0(transitive)
+ Addedeslint-visitor-keys@3.4.34.2.0(transitive)
+ Addedespree@10.3.0(transitive)
+ Addedesquery@1.6.0(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfile-entry-cache@8.0.0(transitive)
+ Addedfind-up@4.1.05.0.0(transitive)
+ Addedflat-cache@4.0.1(transitive)
+ Addedflatted@3.3.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedglobals@14.0.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-builtin-module@3.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjsesc@0.5.03.0.2(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlevn@0.4.1(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlocate-path@5.0.06.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednatural-compare@1.4.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedoptionator@0.9.4(transitive)
+ Addedp-limit@2.3.03.1.0(transitive)
+ Addedp-locate@4.1.05.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpluralize@8.0.0(transitive)
+ Addedprelude-ls@1.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedread-pkg@5.2.0(transitive)
+ Addedread-pkg-up@7.0.1(transitive)
+ Addedregexp-tree@0.1.27(transitive)
+ Addedregjsparser@0.9.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedsafe-regex@2.1.1(transitive)
+ Addedsemver@5.7.27.6.3(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-indent@3.0.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtype-check@0.4.0(transitive)
+ Addedtype-fest@0.6.00.8.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedyocto-queue@0.1.0(transitive)