11import QuickLRU from '@jbrowse/core/util/QuickLRU' ;
2- import { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter' ;
2+ import { BaseOptions , BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter' ;
33import { NoAssemblyRegion } from '@jbrowse/core/util/types' ;
44import { ObservableCreate } from '@jbrowse/core/util/rxjs' ;
55import { Feature } from '@jbrowse/core/util/simpleFeature' ;
66import ExtendedVcfFeature from './ExtendedVcfFeature' ;
77import { VcfFeature } from '@jbrowse/plugin-variants' ;
8- import { default as VcfTabixAdapter } from './VcfTabixAdapter' ;
98
10- export default class extends VcfTabixAdapter {
9+ export default class extends BaseFeatureDataAdapter {
1110 protected featureCache = new QuickLRU ( { maxSize : 20 } )
11+ private subAdapterP ?: Promise < any >
12+
13+ constructor ( ...args : any [ ] ) {
14+ super ( ...args )
15+
16+ // Return a Proxy that forwards any unknown member access to the sub-adapter.
17+ // This avoids re-implementing methods like getHeader/getRefNames/getMetadata/etc.
18+ const self = this
19+ return new Proxy ( this , {
20+ get ( target , prop , receiver ) {
21+ // If we have it already (e.g., getFeatures, getFeaturesAsArray, BaseFeatureDataAdapter-derived properties), use it directly
22+ if ( prop in target || typeof prop === 'symbol' ) {
23+ return Reflect . get ( target , prop , receiver )
24+ }
25+
26+ // Otherwise, forward to the VcfTabixAdapter sub-adapter
27+ return async ( ...callArgs : any [ ] ) => {
28+ const sub = await self . getVcfSubAdapter ( )
29+ const value = ( sub as any ) [ prop ]
30+
31+ // If it’s a method, call it; otherwise return the property value
32+ if ( typeof value === 'function' ) {
33+ return value . apply ( sub , callArgs )
34+ }
35+ return value
36+ }
37+ } ,
38+ } )
39+ }
40+
41+ private async getVcfSubAdapter ( ) : Promise < any > {
42+ if ( ! this . subAdapterP ) {
43+ const vcfGzLocation = this . getConf ( 'vcfGzLocation' )
44+ const index = this . getConf ( [ 'index' ] )
45+ const vcfAdapterConf = { type : 'VcfTabixAdapter' , vcfGzLocation, index }
46+ this . subAdapterP = this . getSubAdapter ! ( vcfAdapterConf )
47+ . then ( ( { dataAdapter } ) => dataAdapter )
48+ . catch ( e => {
49+ this . subAdapterP = undefined
50+ throw e
51+ } )
52+ }
53+ return this . subAdapterP
54+ }
1255
1356 public getFeatures ( query : NoAssemblyRegion , opts : BaseOptions = { } ) {
1457 return ObservableCreate < Feature > ( async observer => {
@@ -50,4 +93,19 @@ export default class extends VcfTabixAdapter {
5093
5194 return features
5295 }
96+
97+ // Typescript errors at compile time without these stubs
98+ async configure ( opts ?: BaseOptions ) {
99+ const sub = await this . getVcfSubAdapter ( )
100+ return sub . configure ( opts )
101+ }
102+
103+ async getRefNames ( opts : BaseOptions = { } ) {
104+ const sub = await this . getVcfSubAdapter ( )
105+ return sub . getRefNames ( opts )
106+ }
107+
108+ freeResources ( ) : void {
109+ void this . getVcfSubAdapter ( ) . then ( sub => sub . freeResources ?.( ) )
110+ }
53111}
0 commit comments