Skip to content

Commit

Permalink
Add some statusCallback to VcfTabixAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 29, 2025
1 parent f314acb commit 17c3d6a
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions plugins/variants/src/VcfTabixAdapter/VcfTabixAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TabixIndexedFile } from '@gmod/tabix'
import VcfParser from '@gmod/vcf'
import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'
import { fetchAndMaybeUnzipText } from '@jbrowse/core/util'
import { fetchAndMaybeUnzipText, updateStatus } from '@jbrowse/core/util'
import { openLocation } from '@jbrowse/core/util/io'
import { ObservableCreate } from '@jbrowse/core/util/rxjs'

Expand All @@ -17,22 +17,28 @@ export default class VcfTabixAdapter extends BaseFeatureDataAdapter {
parser: VcfParser
}>

private async configurePre() {
const pm = this.pluginManager
private async configurePre(opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
const vcfGzLocation = this.getConf('vcfGzLocation')
const location = this.getConf(['index', 'location'])
const indexType = this.getConf(['index', 'indexType'])

const filehandle = openLocation(vcfGzLocation, pm)
const filehandle = openLocation(vcfGzLocation, this.pluginManager)
const isCSI = indexType === 'CSI'
const vcf = new TabixIndexedFile({
filehandle,
csiFilehandle: isCSI ? openLocation(location, pm) : undefined,
tbiFilehandle: !isCSI ? openLocation(location, pm) : undefined,
csiFilehandle: isCSI
? openLocation(location, this.pluginManager)
: undefined,
tbiFilehandle: !isCSI
? openLocation(location, this.pluginManager)
: undefined,
chunkCacheSize: 50 * 2 ** 20,
})

const header = await vcf.getHeader()
const header = await updateStatus('Downloading index', statusCallback, () =>
vcf.getHeader(),
)
return {
vcf,
parser: new VcfParser({ header }),
Expand Down Expand Up @@ -67,19 +73,23 @@ export default class VcfTabixAdapter extends BaseFeatureDataAdapter {
public getFeatures(query: NoAssemblyRegion, opts: BaseOptions = {}) {
return ObservableCreate<Feature>(async observer => {
const { refName, start, end } = query
const { statusCallback = () => {} } = opts || {}
const { vcf, parser } = await this.configure()
await vcf.getLines(refName, start, end, {
lineCallback: (line, fileOffset) => {
observer.next(
new VcfFeature({
variant: parser.parseLine(line),
parser,
id: `${this.id}-vcf-${fileOffset}`,
}),
)
},
...opts,
})

await updateStatus('Downloading variants', statusCallback, () =>
vcf.getLines(refName, start, end, {
lineCallback: (line, fileOffset) => {
observer.next(
new VcfFeature({
variant: parser.parseLine(line),
parser,
id: `${this.id}-vcf-${fileOffset}`,
}),
)
},
...opts,
}),
)
observer.complete()
}, opts.stopToken)
}
Expand Down

0 comments on commit 17c3d6a

Please sign in to comment.