"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[5904],{35904:(e,t,n)=>{n.r(t),n.d(t,{default:()=>h});var s=n(68584),a=n(46377),r=n(99546),o=n(99834),c=n(32595),i=n(66885),u=n(42781),m=n(72147),l=n(78054);function f(e){const[t,n]=e.reduce((([e,t],[n,s])=>[e+n*s,t+s]),[0,0]);return t/n}const{parseCigar:p}=u.aF;class h extends a.BaseFeatureDataAdapter{static capabilities=["getFeatures","getRefNames"];async setup(e){return this.setupP||(this.setupP=this.setupPre(e).catch((e=>{throw this.setupP=void 0,e}))),this.setupP}async setupPre(e){const t=this.pluginManager,n=(0,o.openLocation)(this.getConf("pafLocation"),t),s=await(0,r.fetchAndMaybeUnzip)(n,e);return(0,l.PX)(s,l.xI)}async hasDataForRefName(){return!0}getAssemblyNames(){const e=this.getConf("assemblyNames");return 0===e.length?[this.getConf("queryAssembly"),this.getConf("targetAssembly")]:e}async getRefNames(e={}){const t=e.regions?.[0].assemblyName,n=await this.setup(e),s=this.getAssemblyNames().indexOf(t);if(-1!==s){const e=new Set;for(const t of n)e.add(0===s?t.qname:t.tname);return[...e]}return console.warn("Unable to do ref renaming on adapter"),[]}getFeatures(e,t={}){return(0,i.ObservableCreate)((async n=>{let a=await this.setup(t);const{config:r}=t;r&&"meanQueryIdentity"===(0,s.readConfObject)(r,"colorBy")&&(a=function(e){const t={};for(const n of e){const e=`${n.qname}-${n.tname}`;t[e]||(t[e]={quals:[],len:[]}),t[e].quals.push(n.extra.mappingQual||1),t[e].len.push(n.extra.blockLen||1)}const n=Object.fromEntries(Object.entries(t).map((([e,t])=>[e,f((0,l.yU)(t.quals,t.len))])));for(const t of e){const e=`${t.qname}-${t.tname}`;t.extra.meanScore=n[e]}let s=1e4,a=0;for(const t of e)s=Math.min(t.extra.meanScore||0,s),a=Math.max(t.extra.meanScore||0,a);for(const t of e){const e=t.extra.meanScore||0;t.extra.meanScore=(e-s)/(a-s)}return e}(a));const o=this.getAssemblyNames(),{start:i,end:u,refName:h,assemblyName:d}=e,g=o.indexOf(d),b=0===g;-1===g&&(console.warn(`${d} not found in this adapter`),n.complete());for(let e=0;e<a.length;e++){const t=a[e];let s=0,r=0,f="",g="",y=0,x=0;b?(s=t.qstart,r=t.qend,f=t.qname,g=t.tname,y=t.tstart,x=t.tend):(s=t.tstart,r=t.tend,f=t.tname,g=t.qname,y=t.qstart,x=t.qend);const{extra:q,strand:w}=t;if(f===h&&(0,c.R6)(i,u,s,r)){const{numMatches:t=0,blockLen:a=1,cg:c,...i}=q;let u=q.cg;q.cg&&(b&&-1===w?u=(0,l.qm)(p(q.cg)).join(""):b&&(u=(0,l.gJ)(q.cg))),n.next(new m.A({uniqueId:e+d,assemblyName:d,start:s,end:r,type:"match",refName:f,strand:w,...i,CIGAR:u,syntenyId:e,identity:t/a,numMatches:t,blockLen:a,mate:{start:y,end:x,refName:g,assemblyName:o[+b]}}))}}n.complete()}))}freeResources(){}}},72147:(e,t,n)=>{n.d(t,{A:()=>o});var s=n(99546),a=n(42781);const{getMismatches:r}=a.aF;class o extends s.SimpleFeature{get(e){return"mismatches"===e?r(this.get("CIGAR")):super.get(e)}}},78054:(e,t,n)=>{n.d(t,{PX:()=>c,TA:()=>r,fY:()=>a,gJ:()=>m,qm:()=>u,xI:()=>i,yU:()=>o});var s=n(99546);function a(e){return new Map(e.split(/\n|\r\n|\r/).filter((e=>!!e||e.startsWith("#"))).map((e=>{const[t,n,s,a,r,o]=e.split("\t");return[a,{refName:t,start:+n,end:+s,score:+r,name:a,strand:"-"===o?-1:1}]})))}async function r(e,t){return(0,s.fetchAndMaybeUnzipText)(e,t)}function o(e,t){return e.map(((e,n)=>[e,t[n]]))}function c(e,t){let n=0;const s=[],a=new TextDecoder("utf8");for(;n<e.length;){const r=e.indexOf(10,n);if(-1===r)break;const o=e.subarray(n,r),c=a.decode(o).trim();if(c){const e=t(c);e&&s.push(e)}n=r+1}return s}function i(e){const[t,,n,s,a,r,,o,c,i,u,m,...l]=e.split("\t");return{tname:r,tstart:+o,tend:+c,qname:t,qstart:+n,qend:+s,strand:"-"===a?-1:1,extra:{numMatches:+i,blockLen:+u,mappingQual:+m,...Object.fromEntries(l.map((e=>{const t=e.indexOf(":");return[e.slice(0,t),e.slice(t+3)]})))}}}function u(e){const t=[];for(let n=e.length-2;n>=0;n-=2){t.push(e[n]);const s=e[n+1];"D"===s?t.push("I"):"I"===s?t.push("D"):t.push(s)}return t}function m(e){return e.replaceAll("D","K").replaceAll("I","D").replaceAll("K","I")}}}]);
//# sourceMappingURL=5904.0339d73e.chunk.js.map