"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[4770,6823],{6823:(e,t,a)=>{a.r(t),a.d(t,{default:()=>r});var s=a(81794),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}}}},94770:(e,t,a)=>{a.r(t),a.d(t,{default:()=>m});var s=a(81794),i=a(46377),r=a(99546),n=a(43334),o=a(99834),c=a(66885),u=a(37347),d=a(44728),h=a(82088),g=a(95805),l=a(91476);class f{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,g.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,l.Kt)(f,"fields"),(0,l.Kt)(f,"mismatches");class m extends i.BaseFeatureDataAdapter{ultraLongFeatureCache=new n.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,o.openLocation)(e,i),csiFilehandle:r?(0,o.openLocation)(t,i):void 0,baiFilehandle:r?void 0:(0,o.openLocation)(t,i),yieldThreadTime:Number.POSITIVE_INFINITY}),c=this.getConf("sequenceAdapter");if(c&&this.getSubAdapter){const{dataAdapter:e}=await this.getSubAdapter(c);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()}async setupPre(e){const{bam:t}=await this.configure(),a=await t.getHeader(),s=[],i={};if(a)for(const[e,t]of a.filter((e=>"SQ"===e.tag)).entries()){const a=t.data.find((e=>"SN"===e.tag));if(a){const t=a.value;i[t]=e,s[e]=t}}return this.samHeader={idToName:s,nameToId:i},this.samHeader}async setupPre2(e){return this.setupP||(this.setupP=this.setupPre(e).catch((e=>{throw this.setupP=void 0,e}))),this.setupP}async setup(e){const{statusCallback:t=()=>{}}=e||{};return(0,r.updateStatus)("Downloading index",t,(()=>this.setupPre2(e)))}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 i=s.getFeatures({refName:e,start:t,end:a,assemblyName:""}),r=await(0,d._)(i.pipe((0,h.$)()));let n="";for(const e of r.sort(((e,t)=>e.get("start")-t.get("start")))){const s=e.get("start"),i=e.get("end"),r=Math.max(t-s,0),o=Math.min(a-s,i-s)-r;n+=(e.get("seq")||e.get("residues")).slice(r,r+o)}if(n.length!==a-t)throw new Error(`sequence fetch failed: fetching ${e}:${(t-1).toLocaleString()}-${a.toLocaleString()} returned ${n.length.toLocaleString()} bases, but should have returned ${(a-t).toLocaleString()}`);return n}getFeatures(e,t){const{refName:a,start:s,end:i,originalRefName:n}=e,{stopToken:o,filterBy:d,statusCallback:h=()=>{}}=t||{};return(0,c.ObservableCreate)((async e=>{const{bam:c}=await this.configure();await this.setup(t),(0,u.SW)(o);const g=await(0,r.updateStatus)("Downloading alignments",h,(()=>c.getRecordsForRange(a,s,i)));(0,u.SW)(o),await(0,r.updateStatus)("Processing alignments",h,(async()=>{const{flagInclude:t=0,flagExclude:s=0,tagFilter:i,readName:r}=d||{};for(const o of g){let c;if(o.tags.MD||(c=await this.seqFetch(n||a,o.start,o.end)),(0,l.lE)(o.flags,t,s))continue;if(i&&(0,l.Kl)(o.tags[i.tag],i.value))continue;if(r&&o.name!==r)continue;const u=this.ultraLongFeatureCache.get(`${o.id}`);if(u)e.next(u);else{const t=new f(o,this,c);this.ultraLongFeatureCache.set(`${o.id}`,t),e.next(t)}}e.complete()}))}))}async getMultiRegionFeatureDensityStats(e,t){const{bam:a}=await this.configure();return a.index?{bytes:await(0,r.bytesForRegions)(e,a),fetchSizeLimit:this.getConf("fetchSizeLimit")}:super.getMultiRegionFeatureDensityStats(e,t)}refIdToName(e){return this.samHeader?.idToName[e]}}}}]);
//# sourceMappingURL=6823.43fb352c.chunk.js.map