import{T as x}from"./tabixIndexedFile-B_BgWenS.js";import{aw as I,c as l,i as h}from"./rpcWorker-CVTx5FIM.js";import{B as H}from"./index-P3rx-5SH.js";import{r as F}from"./rxjs-Dgg09m9e.js";import{S}from"./simpleFeature-DW3q5zmr.js";import{p as T,f as b}from"./featureData-XuIg4mRh.js";import"./AbortablePromiseCache-xs5eyOH3.js";var L=I();class A extends H.BaseFeatureDataAdapter{constructor(e,n,i){super(e,n,i);const a=l.readConfObject(e,"gffGzLocation"),p=l.readConfObject(e,["index","indexType"]),f=l.readConfObject(e,["index","location"]),d=l.readConfObject(e,"dontRedispatch");this.dontRedispatch=d||["chromosome","contig","region"],this.gff=new x({filehandle:h.openLocation(a,this.pluginManager),csiFilehandle:p==="CSI"?h.openLocation(f,this.pluginManager):void 0,tbiFilehandle:p!=="CSI"?h.openLocation(f,this.pluginManager):void 0,chunkCacheSize:50*2**20,renameRefSeqs:c=>c})}async getRefNames(e={}){return this.gff.getReferenceSequenceNames(e)}async getHeader(){return this.gff.getHeader()}getFeatures(e,n={}){return F.ObservableCreate(async i=>{const a=await this.gff.getMetadata();await this.getFeaturesHelper(e,n,a,i,!0)},n.stopToken)}async getFeaturesHelper(e,n,i,a,p,f=e){var d,c;try{const o=[];if(await this.gff.getLines(e.refName,e.start,e.end,(t,s)=>{o.push(this.parseLine(i.columnNumbers,t,s))}),p&&o.length){let t=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const r of o){const m=r.fields[2];if(!this.dontRedispatch.includes(m)){const u=r.start-1;u<t&&(t=u),r.end>s&&(s=r.end)}}if(s>e.end||t<e.start){await this.getFeaturesHelper({...e,start:t,end:s},n,i,a,!1,e);return}}const g=o.map(t=>(t.fields[8]&&t.fields[8]!=="."?t.fields[8].includes("_lineHash")||(t.fields[8]+=`;_lineHash=${t.lineHash}`):t.fields[8]=`_lineHash=${t.lineHash}`,t.fields.join("	"))).join(`
`);for(const t of T(g))for(const s of t){const r=new S({data:b(s),id:`${this.id}-offset-${(c=(d=s.attributes)===null||d===void 0?void 0:d._lineHash)===null||c===void 0?void 0:c[0]}`});L.doesIntersect2(r.get("start"),r.get("end"),f.start,f.end)&&a.next(r)}a.complete()}catch(o){a.error(o)}}parseLine(e,n,i){const a=n.split("	");return{start:+a[e.start-1],end:+a[e.end-1],lineHash:i,fields:a}}freeResources(){}}export{A as default};
