import{I as g}from"./main-BPWpXae6.js";import{B as m}from"./index-P3rx-5SH.js";import{u as v,i as M}from"./rpcWorker-CVTx5FIM.js";import{r as x}from"./rxjs-Dgg09m9e.js";import{S as y}from"./simpleFeature-DW3q5zmr.js";import{p as T,f as b}from"./featureData-XuIg4mRh.js";class L extends m.BaseFeatureDataAdapter{constructor(){super(...arguments),this.calculatedIntervalTreeMap={}}async loadDataP(a){const{statusCallback:t=()=>{}}=a||{},r=await v.fetchAndMaybeUnzip(M.openLocation(this.getConf("gffLocation"),this.pluginManager)),c=[],i={},d=new TextDecoder("utf8");let o=0,l=0;for(;o<r.length;){const s=r.indexOf(`
`,o),h=s===-1?r.subarray(o):r.subarray(o,s),e=d.decode(h).trim();if(e)if(e.startsWith("#"))c.push(e);else{if(e.startsWith(">"))break;{const f=e.indexOf("	"),n=e.slice(0,f);i[n]||(i[n]=""),i[n]+=`${e}
`}}l++%1e4===0&&t(`Loading ${Math.floor(o/1e6).toLocaleString("en-US")}/${Math.floor(r.length/1e6).toLocaleString("en-US")} MB`),o=s+1}const u=Object.fromEntries(Object.entries(i).map(([s,h])=>[s,e=>{if(!this.calculatedIntervalTreeMap[s]){e==null||e("Parsing GFF data");const f=new g;T(h).flat().map((n,p)=>new y({data:b(n),id:`${this.id}-${s}-${p}`})).forEach(n=>f.insert([n.get("start"),n.get("end")],n)),this.calculatedIntervalTreeMap[s]=f}return this.calculatedIntervalTreeMap[s]}]));return{header:c.join(`
`),intervalTreeMap:u}}async loadData(a){return this.gffFeatures||(this.gffFeatures=this.loadDataP(a).catch(t=>{throw this.gffFeatures=void 0,t})),this.gffFeatures}async getRefNames(a={}){const{intervalTreeMap:t}=await this.loadData(a);return Object.keys(t)}async getHeader(a={}){const{header:t}=await this.loadData(a);return t}getFeatures(a,t={}){return x.ObservableCreate(async r=>{var c;try{const{start:i,end:d,refName:o}=a,{intervalTreeMap:l}=await this.loadData(t);(c=l[o])===null||c===void 0||c.call(l,t.statusCallback).search([i,d]).forEach(u=>{r.next(u)}),r.complete()}catch(i){r.error(i)}},t.stopToken)}freeResources(){}}export{L as default};
