UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

80 lines (79 loc) 3.02 kB
import { BigWig } from '@gmod/bbi'; import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'; import { updateStatus } from '@jbrowse/core/util'; import { openLocation } from '@jbrowse/core/util/io'; import { ObservableCreate } from '@jbrowse/core/util/rxjs'; import { rectifyStats } from '@jbrowse/core/util/stats'; class BigWigAdapter extends BaseFeatureDataAdapter { async setupPre(opts) { const { statusCallback = () => { } } = opts || {}; const pluginManager = this.pluginManager; const bigwig = new BigWig({ filehandle: openLocation(this.getConf('bigWigLocation'), pluginManager), }); return { bigwig, header: await updateStatus('Downloading bigwig header', statusCallback, () => bigwig.getHeader(opts)), }; } async setup(opts) { if (!this.setupP) { this.setupP = this.setupPre(opts).catch((e) => { this.setupP = undefined; throw e; }); } return this.setupP; } async getRefNames(opts) { const { header } = await this.setup(opts); return Object.keys(header.refsByName); } async refIdToName(refId) { var _a; const { header } = await this.setup(); return (_a = header.refsByNumber[refId]) === null || _a === void 0 ? void 0 : _a.name; } async getGlobalStats(opts) { const { header } = await this.setup(opts); return rectifyStats(header.totalSummary); } getFeatures(region, opts = {}) { const { refName, start, end } = region; const { bpPerPx = 0, resolution = 1, stopToken, statusCallback = () => { }, } = opts; return ObservableCreate(async (observer) => { const source = this.getConf('source'); const resolutionMultiplier = this.getConf('resolutionMultiplier'); const { bigwig } = await this.setup(opts); const feats = await updateStatus('Downloading bigwig data', statusCallback, () => bigwig.getFeatures(refName, start, end, { ...opts, basesPerSpan: (bpPerPx / resolution) * resolutionMultiplier, })); for (const data of feats) { if (source) { data.source = source; } const uniqueId = `${source}:${region.refName}:${data.start}-${data.end}`; data.refName = refName; data.uniqueId = uniqueId; observer.next({ get: (str) => data[str], id: () => uniqueId, toJSON: () => data, }); } observer.complete(); }, stopToken); } async getMultiRegionFeatureDensityStats(_regions) { return { featureDensity: 0, }; } } BigWigAdapter.capabilities = [ 'hasResolution', 'hasLocalStats', 'hasGlobalStats', ]; export default BigWigAdapter;