Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
import QuickLRU from '@jbrowse/core/util/QuickLRU';
import { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter';
import { BaseOptions, BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
import { NoAssemblyRegion } from '@jbrowse/core/util/types';
import { ObservableCreate } from '@jbrowse/core/util/rxjs';
import { Feature } from '@jbrowse/core/util/simpleFeature';
import ExtendedVcfFeature from './ExtendedVcfFeature';
import { VcfFeature } from '@jbrowse/plugin-variants';
import { default as VcfTabixAdapter } from './VcfTabixAdapter';

export default class extends VcfTabixAdapter {
export default class extends BaseFeatureDataAdapter {
protected featureCache = new QuickLRU({ maxSize: 20 })
private subAdapterP?: Promise<any>

constructor(...args: any[]) {
super(...args)

// Return a Proxy that forwards any unknown member access to the sub-adapter.
// This avoids re-implementing methods like getHeader/getRefNames/getMetadata/etc.
const self = this
return new Proxy(this, {
get(target, prop, receiver) {
// If we have it already (e.g., getFeatures, getFeaturesAsArray, BaseFeatureDataAdapter-derived properties), use it directly
if (prop in target || typeof prop === 'symbol') {
return Reflect.get(target, prop, receiver)
}

// Otherwise, forward to the VcfTabixAdapter sub-adapter
return async (...callArgs: any[]) => {
const sub = await self.getVcfSubAdapter()
const value = (sub as any)[prop]

// If it’s a method, call it; otherwise return the property value
if (typeof value === 'function') {
return value.apply(sub, callArgs)
}
return value
}
},
})
}

private async getVcfSubAdapter(): Promise<any> {
if (!this.subAdapterP) {
const vcfGzLocation = this.getConf('vcfGzLocation')
const index = this.getConf(['index'])
const vcfAdapterConf = { type: 'VcfTabixAdapter', vcfGzLocation, index }
this.subAdapterP = this.getSubAdapter!(vcfAdapterConf)
.then(({ dataAdapter }) => dataAdapter)
.catch(e => {
this.subAdapterP = undefined
throw e
})
}
return this.subAdapterP
}

public getFeatures(query: NoAssemblyRegion, opts: BaseOptions = {}) {
return ObservableCreate<Feature>(async observer => {
Expand Down Expand Up @@ -50,4 +93,29 @@ export default class extends VcfTabixAdapter {

return features
}

// Typescript errors at compile time without these stubs
async configure(opts?: BaseOptions) {
const sub = await this.getVcfSubAdapter()
return sub.configure(opts)
}

async getRefNames(opts: BaseOptions = {}) {
const sub = await this.getVcfSubAdapter()
return sub.getRefNames(opts)
}

async getHeader(opts?: BaseOptions) {
const sub = await this.getVcfSubAdapter()
return sub.getHeader(opts)
}

async getMetadata(opts?: BaseOptions) {
const sub = await this.getVcfSubAdapter()
return sub.getMetadata(opts)
}

freeResources(): void {
void this.getVcfSubAdapter().then(sub => sub.freeResources?.())
}
}

This file was deleted.