import{I as w}from"./main-BPWpXae6.js";import{V as m,a as x}from"./index-D8cpZQYx.js";import{B as y}from"./index-6rN3ss-L.js";import{a9 as F,u as T}from"./index-Bm2SqMk3.js";import{r as C}from"./rxjs-DT7GVwt0.js";class L extends y.BaseFeatureDataAdapter{constructor(){super(...arguments),this.calculatedIntervalTreeMap={}}async getHeader(){const{header:e}=await this.setup();return e}async getMetadata(){const{header:e}=await this.setup();return new m({header:e}).getMetadata()}async setupP(e){const{statusCallback:n=()=>{}}=e||{},l=F.openLocation(this.getConf("vcfLocation"),this.pluginManager),a=await T.fetchAndMaybeUnzip(l,e),i=[],o={};let s=0;const u=new TextDecoder("utf8");let p=0;for(;s<a.length;){const r=a.indexOf(`
`,s),d=r===-1?a.subarray(s):a.subarray(s,r),t=u.decode(d).trim();if(t)if(t.startsWith("#"))i.push(t);else{const f=t.indexOf("	"),c=t.slice(0,f);o[c]||(o[c]=[]),o[c].push(t)}p++%1e4===0&&n(`Loading ${Math.floor(s/1e6).toLocaleString("en-US")}/${Math.floor(a.length/1e6).toLocaleString("en-US")} MB`),s=r+1}const g=i.join(`
`),v=new m({header:g}),M=Object.fromEntries(Object.entries(o).map(([r,d])=>[r,t=>{if(!this.calculatedIntervalTreeMap[r]){t==null||t("Parsing VCF data");let f=0;const c=new w;for(const b of d){const h=new x({variant:v.parseLine(b),parser:v,id:`${this.id}-${r}-${f++}`});c.insert([h.get("start"),h.get("end")],h)}this.calculatedIntervalTreeMap[r]=c}return this.calculatedIntervalTreeMap[r]}]));return{header:g,intervalTreeMap:M}}async setup(){return this.vcfFeatures||(this.vcfFeatures=this.setupP().catch(e=>{throw this.vcfFeatures=void 0,e})),this.vcfFeatures}async getRefNames(e={}){const{intervalTreeMap:n}=await this.setup();return Object.keys(n)}getFeatures(e,n={}){return C.ObservableCreate(async l=>{var a;try{const{start:i,end:o,refName:s}=e,{intervalTreeMap:u}=await this.setup();(a=u[s])===null||a===void 0||a.call(u,n.statusCallback).search([i,o]).forEach(p=>{l.next(p)}),l.complete()}catch(i){l.error(i)}},n.stopToken)}freeResources(){}}L.capabilities=["getFeatures","getRefNames"];export{L as default};
