UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

36 lines (35 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getScoreMatrix = getScoreMatrix; const dataAdapterCache_1 = require("@jbrowse/core/data_adapters/dataAdapterCache"); const util_1 = require("@jbrowse/core/util"); const rxjs_1 = require("rxjs"); async function getScoreMatrix({ pluginManager, args, }) { const { sources, regions, adapterConfig, sessionId, bpPerPx } = args; const adapter = await (0, dataAdapterCache_1.getAdapter)(pluginManager, sessionId, adapterConfig); const dataAdapter = adapter.dataAdapter; const r0 = regions[0]; const r0len = r0.end - r0.start; const w = Math.floor(r0len / bpPerPx); const feats = await (0, rxjs_1.firstValueFrom)(dataAdapter.getFeatures(r0, args).pipe((0, rxjs_1.toArray)())); const groups = (0, util_1.groupBy)(feats, f => f.get('source')); const rows = {}; for (const source of sources) { const { name } = source; const features = groups[name] || []; const arr = new Array(w).fill(0); for (const feat of features) { const fstart = feat.get('start'); const fend = feat.get('end'); const score = feat.get('score'); for (let i = fstart; i < fend; i += bpPerPx) { const x = Math.floor((i - r0.start) / bpPerPx); if (x >= 0 && x < w) { arr[x] || (arr[x] = score); } } } rows[name] = arr; } return rows; }