diff --git a/plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.ts b/plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.ts index 511901e2d9..20ab411f94 100644 --- a/plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.ts +++ b/plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.ts @@ -76,36 +76,48 @@ export default class BedGraphAdapter extends BaseFeatureDataAdapter { public getFeatures(query: Region, opts: BaseOptions = {}) { return ObservableCreate(async observer => { - const { refName, start, end } = query const { bedGraph } = await this.configure() - const names = (await this.getNames())?.slice(3) || [] - await bedGraph.getLines(refName, start, end, { - lineCallback: (line, fileOffset) => { - const [refName, s, e, ...rest] = line.split('\t') - for (let j = 0; j < rest.length; j++) { - const uniqueId = `${this.id}-${fileOffset}-${j}` - const start = +s! - const end = +e! - const score = +rest[j]! - const source = names[j] || `col${j}` - if (score) { - observer.next( - new SimpleFeature({ - id: uniqueId, - data: { - refName, - start, - end, - score, - source, - }, - }), - ) + const meta = await bedGraph.getMetadata() + const { columnNumbers } = meta + const colRef = columnNumbers.ref - 1 + const colStart = columnNumbers.start - 1 + const colEnd = columnNumbers.end - 1 + const same = colStart === colEnd + const names = (await this.getNames())?.slice(same ? 2 : 3) || [] + await bedGraph.getLines( + query.refName, + query.start + (same ? -1 : 0), + query.end, + { + lineCallback: (line, fileOffset) => { + const cols = line.split('\t') + const refName = cols[colRef]! + const start = +cols[colStart]! + const end = +(same ? start + 1 : cols[colEnd]!) + const rest = cols.slice(colEnd + 1) + for (let j = 0; j < rest.length; j++) { + const uniqueId = `${this.id}-${fileOffset}-${j}` + const score = Math.abs(+rest[j]!) + const source = names[j] || `col${j}` + if (score) { + observer.next( + new SimpleFeature({ + id: uniqueId, + data: { + refName, + start, + end, + score, + source, + }, + }), + ) + } } - } + }, + ...opts, }, - ...opts, - }) + ) observer.complete() }) } diff --git a/plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts b/plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts index 44079cfb10..4bfa432559 100644 --- a/plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts +++ b/plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts @@ -4,6 +4,7 @@ import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter' import { SimpleFeature } from '@jbrowse/core/util' import { openLocation } from '@jbrowse/core/util/io' import { ObservableCreate } from '@jbrowse/core/util/rxjs' +import { checkStopToken } from '@jbrowse/core/util/stopToken' import { featureData } from '../util' @@ -71,6 +72,7 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter { } public getFeatures(query: Region, opts: BaseOptions = {}) { + const { stopToken } = opts return ObservableCreate(async observer => { const meta = await this.bed.getMetadata() const { columnNumbers } = meta @@ -78,8 +80,14 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter { const colStart = columnNumbers.start - 1 const colEnd = columnNumbers.end - 1 const names = await this.getNames() + let start = performance.now() + checkStopToken(stopToken) await this.bed.getLines(query.refName, query.start, query.end, { lineCallback: (line, fileOffset) => { + if (performance.now() - start > 200) { + checkStopToken(stopToken) + start = performance.now() + } observer.next( new SimpleFeature( featureData({