diff --git a/plugins/bed/src/BedGraphAdapter/BedGraphAdapter.ts b/plugins/bed/src/BedGraphAdapter/BedGraphAdapter.ts index f6cf6235ea..c32f5435de 100644 --- a/plugins/bed/src/BedGraphAdapter/BedGraphAdapter.ts +++ b/plugins/bed/src/BedGraphAdapter/BedGraphAdapter.ts @@ -1,5 +1,10 @@ import { ObservableCreate } from '@jbrowse/core/util/rxjs' -import { Feature, fetchAndMaybeUnzip, SimpleFeature } from '@jbrowse/core/util' +import { + Feature, + fetchAndMaybeUnzip, + Region, + SimpleFeature, +} from '@jbrowse/core/util' import IntervalTree from '@flatten-js/interval-tree' import { BaseFeatureDataAdapter, @@ -42,24 +47,29 @@ export default class BedGraphAdapter extends BaseFeatureDataAdapter { const names = (await this.getNames())?.slice(3) || [] const intervalTree = new IntervalTree() for (let i = 0; i < lines.length; i++) { - const [refName, s, e, ...rest] = lines[i]!.split('\t') + const line = lines[i]! + const [refName, s, e, ...rest] = line.split('\t') for (let j = 0; j < rest.length; j++) { - const uniqueId = `${this.id}-${refName}-${i}` + const uniqueId = `${this.id}-${refName}-${i}-${j}` const start = +s! const end = +e! - intervalTree.insert( - [start, end], - new SimpleFeature({ - id: uniqueId, - data: { - refName, - start, - end, - score: +rest[i]!, - source: names[i] || `col${i}`, - }, - }), - ) + const score = +rest[j]! + const source = names[j] || `col${j}` + if (score) { + intervalTree.insert( + [start, end], + new SimpleFeature({ + id: uniqueId, + data: { + refName, + start, + end, + score, + source, + }, + }), + ) + } } } @@ -132,7 +142,6 @@ export default class BedGraphAdapter extends BaseFeatureDataAdapter { const { start, end, refName } = query const intervalTree = await this.loadFeatureIntervalTree(refName) intervalTree?.search([start, end]).forEach(f => { - console.log({ f }) observer.next(f) }) observer.complete() diff --git a/plugins/bed/src/BedGraphAdapter/configSchema.ts b/plugins/bed/src/BedGraphAdapter/configSchema.ts new file mode 100644 index 0000000000..928ec58ffc --- /dev/null +++ b/plugins/bed/src/BedGraphAdapter/configSchema.ts @@ -0,0 +1,32 @@ +import { ConfigurationSchema } from '@jbrowse/core/configuration' + +/** + * #config BedGraphAdapter + */ +function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars + +const BedGraphAdapter = ConfigurationSchema( + 'BedGraphAdapter', + { + /** + * #slot + */ + bedGraphLocation: { + type: 'fileLocation', + defaultValue: { + uri: '/path/to/my.bedgraph', + locationType: 'UriLocation', + }, + }, + /** + * #slot + */ + columnNames: { + type: 'stringArray', + description: 'List of column names', + defaultValue: [], + }, + }, + { explicitlyTyped: true }, +) +export default BedGraphAdapter diff --git a/plugins/bed/src/BedGraphAdapter/index.ts b/plugins/bed/src/BedGraphAdapter/index.ts index 712ec0a7c6..fb7d649926 100644 --- a/plugins/bed/src/BedGraphAdapter/index.ts +++ b/plugins/bed/src/BedGraphAdapter/index.ts @@ -1,7 +1,7 @@ import PluginManager from '@jbrowse/core/PluginManager' import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' -import configSchema from '../BedAdapter/configSchema' +import configSchema from './configSchema' export default function BedGraphAdapterF(pluginManager: PluginManager) { pluginManager.addAdapterType(