"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[4770,6823],{94770:(e,t,a)=>{a.r(t),a.d(t,{default:()=>f});var s=a(34133),i=a(82088),r=a(44728),n=a(46377),o=a(99546),c=a(99834),u=a(66885),d=a(43334),h=a(95805),g=a(91476);class l{constructor(e,t,a){this.record=e,this.adapter=t,this.ref=a}id(){return`${this.adapter.id}-${this.record.id}`}get mismatches(){return(0,h.getMismatches)(this.record.CIGAR,this.record.tags.MD,this.record.seq,this.ref,this.record.qual)}get qual(){return this.record.qual?.join(" ")}get(e){return"mismatches"===e?this.mismatches:"qual"===e?this.qual:this.fields[e]}parent(){}children(){}get fields(){const e=this.record,t=this.adapter,a=e.isPaired();return{start:e.start,name:e.name,end:e.end,score:e.score,strand:e.strand,template_length:e.template_length,flags:e.flags,tags:e.tags,refName:t.refIdToName(e.ref_id),CIGAR:e.CIGAR,seq:e.seq,type:"match",pair_orientation:e.pair_orientation,next_ref:a?t.refIdToName(e.next_refid):void 0,next_pos:a?e.next_pos:void 0,next_segment_position:a?`${t.refIdToName(e.next_refid)}:${e.next_pos+1}`:void 0,uniqueId:this.id()}}toJSON(){return{...this.fields,qual:this.qual}}}(0,g.Kt)(l,"fields"),(0,g.Kt)(l,"mismatches");class f extends n.BaseFeatureDataAdapter{ultraLongFeatureCache=new d.A({maxSize:500});async configurePre(){const e=this.getConf("bamLocation"),t=this.getConf(["index","location"]),a=this.getConf(["index","indexType"]),i=this.pluginManager,r="CSI"===a,n=new s.j9({bamFilehandle:(0,c.openLocation)(e,i),csiFilehandle:r?(0,c.openLocation)(t,i):void 0,baiFilehandle:r?void 0:(0,c.openLocation)(t,i),yieldThreadTime:Number.POSITIVE_INFINITY}),o=this.getConf("sequenceAdapter");if(o&&this.getSubAdapter){const{dataAdapter:e}=await this.getSubAdapter(o);return{bam:n,sequenceAdapter:e}}return{bam:n}}async configure(){return this.configureP||(this.configureP=this.configurePre().catch((e=>{throw this.configureP=void 0,e}))),this.configureP}async getHeader(e){const{bam:t}=await this.configure();return t.getHeaderText(e)}async setupPre(e){const{statusCallback:t=()=>{}}=e||{},{bam:a}=await this.configure();return this.samHeader=await(0,o.updateStatus)("Downloading index",t,(async()=>{const t=await a.getHeader(e),s=[],i={};return t?.filter((e=>"SQ"===e.tag)).forEach(((e,t)=>{const a=e.data.find((e=>"SN"===e.tag));if(a){const e=a.value;i[e]=t,s[t]=e}})),{idToName:s,nameToId:i}})),this.samHeader}async setup(e){return this.setupP||(this.setupP=this.setupPre(e).catch((e=>{throw this.setupP=void 0,e}))),this.setupP}async getRefNames(e){const{idToName:t}=await this.setup(e);return t}async seqFetch(e,t,a){const{sequenceAdapter:s}=await this.configure();if(!s)return;if(!e)return;const n=s.getFeatures({refName:e,start:t,end:a,assemblyName:""}),o=await(0,r._)(n.pipe((0,i.$)()));let c="";if(o.sort(((e,t)=>e.get("start")-t.get("start"))).forEach((e=>{const s=e.get("start"),i=e.get("end"),r=Math.max(t-s,0),n=Math.min(a-s,i-s)-r,o=e.get("seq")||e.get("residues");c+=o.slice(r,r+n)})),c.length!==a-t)throw new Error(`sequence fetch failed: fetching ${e}:${(t-1).toLocaleString()}-${a.toLocaleString()} returned ${c.length.toLocaleString()} bases, but should have returned ${(a-t).toLocaleString()}`);return c}getFeatures(e,t){const{refName:a,start:s,end:i,originalRefName:r}=e,{signal:n,filterBy:c,statusCallback:d=()=>{}}=t||{};return(0,u.ObservableCreate)((async e=>{const{bam:n}=await this.configure();await this.setup(t);const u=await(0,o.updateStatus)("Downloading alignments",d,(()=>n.getRecordsForRange(a,s,i,t)));await(0,o.updateStatus)("Processing alignments",d,(async()=>{const{flagInclude:t=0,flagExclude:s=0,tagFilter:i,readName:n}=c||{};for(const o of u){let c;o.tags.MD||(c=await this.seqFetch(r||a,o.start,o.end));const u=o.flags;if((u&t)!==t&&!(u&s))continue;if(i){const e=o.tags[i.tag],t=i.value;if("*"===t?void 0===e:`${e}`!=`${t}`)continue}if(n&&o.name!==n)continue;const d=this.ultraLongFeatureCache.get(`${o.id}`);if(d)e.next(d);else{const t=new l(o,this,c);this.ultraLongFeatureCache.set(`${o.id}`,t),e.next(t)}}e.complete()}))}),n)}async getMultiRegionFeatureDensityStats(e,t){const{bam:a}=await this.configure();return a.index?{bytes:await(0,o.bytesForRegions)(e,a),fetchSizeLimit:this.getConf("fetchSizeLimit")}:super.getMultiRegionFeatureDensityStats(e,t)}freeResources(){}refIdToName(e){return this.samHeader?.idToName[e]}}},6823:(e,t,a)=>{a.r(t),a.d(t,{default:()=>r});var s=a(34133),i=a(94770);class r extends i.default{async configurePre(){const e=this.getConf("htsgetBase"),t=this.getConf("htsgetTrackId"),a=new s.Wg({baseUrl:e,trackId:t}),i=this.getConf("sequenceAdapter");return i&&this.getSubAdapter?{bam:a,sequenceAdapter:(await this.getSubAdapter(i)).dataAdapter}:{bam:a}}}}}]);
//# sourceMappingURL=6823.f773c743.chunk.js.map