import { BBI } from './bbi.ts' import type { RequestOptions } from './types.ts' /** * Parser for BigWig files. Inherits `getHeader`, `getFeatures`, * `getFeaturesMulti`, `getFeaturesAsArrays`, and `getFeaturesAsArraysMulti` * from `BBI`. * * Supports zoom levels — pass `opts.scale` or `opts.basesPerSpan` to * automatically select the appropriate pre-computed zoom level. */ export class BigWig extends BBI { /** * Retrieves a BlockView of a specific zoomLevel * * @param scale - number * * @param opts - An object containing basesPerSpan (e.g. pixels per basepair) * or scale used to infer the zoomLevel to use */ protected async getView(scale: number, opts?: RequestOptions) { const { zoomLevels, refsByName, uncompressBufSize } = await this.getHeader(opts) const basesPerPx = 1 / scale const maxLevel = zoomLevels.length - 1 for (let i = maxLevel; i >= 0; i -= 1) { const zh = zoomLevels[i]! if (zh.reductionLevel <= 2 * basesPerPx) { return this.getOrCreateBlockView( refsByName, zh.indexOffset, uncompressBufSize, 'summary', ) } } return this.getUnzoomedView(opts) } }