"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[5461],{75461:(t,e,s)=>{s.r(e),s.d(e,{default:()=>g});var o=s(46377),a=s(6434),n=s(66885),r=s(82088),i=s(44728),c=s(86576),d=s(80544),f=s(99546);function l(t){return u(t.type)?1:t.length}function u(t){return"softclip"===t||"hardclip"===t||"insertion"===t}function p(t,e,s,o){let a=t[s][o];void 0===a&&(a=t[s][o]={total:0,"-1":0,0:0,1:0}),a.total++,a[e]++}class g extends o.BaseFeatureDataAdapter{async configure(){const t=this.getConf("subadapter"),e=t.sequenceAdapter,s=await(this.getSubAdapter?.(t)),o=e?await(this.getSubAdapter?.(e)):void 0;if(!s)throw new Error("Failed to get subadapter");return{subadapter:s.dataAdapter,sequenceAdapter:o?.dataAdapter}}async fetchSequence(t){const{sequenceAdapter:e}=await this.configure();if(e)return(0,c.Iw)(t,e)}getFeatures(t,e={}){return(0,n.ObservableCreate)((async s=>{const{subadapter:o}=await this.configure(),n=await(0,i._)(o.getFeatures(t,e).pipe((0,r.$)())),{bins:g,skipmap:h}=await async function(t,e,s,o){const{colorBy:a}=s,n={...e,start:Math.max(0,e.start-1),end:e.end+1},r=Math.ceil(n.end-n.start),i={},g=t.length&&(0,c.k_)(s.colorBy?.type)?await o(e):void 0,h=[];for(const s of t){const t=s.get("start"),o=s.get("end"),n=s.get("strand"),b=s.get("mismatches")||[];for(let s=t;s<o+1;s++){const t=s-e.start;t>=0&&t<r&&(void 0===h[t]&&(h[t]={total:0,all:0,ref:0,"-1":0,0:0,1:0,lowqual:{},cov:{},delskips:{},noncov:{}}),s!==o&&(h[t].total++,h[t].all++,h[t].ref++,h[t][n]++))}if("modifications"===a?.type){const o=s.get("seq"),a=(0,c.c$)(s,"MM","Mm")||"",r=(0,d.parseCigar)(s.get("CIGAR")),i=s.get("end");if(o){const s=(0,d.getModificationPositions)(a,o,n);for(const{type:o,positions:a}of s){const s=`mod_${o}`;for(const o of(0,d.getNextRefPos)(r,a)){const a=o+t-e.start;if(a>=0&&a<h.length&&o+t<i){void 0===h[a]&&(h[a]={total:0,all:0,ref:0,"-1":0,0:0,1:0,lowqual:{},cov:{},delskips:{},noncov:{}});const t=h[a];t?p(t,n,"cov",s):console.warn("Undefined position in modifications snpcoverage encountered")}}}}}if("methylation"===a?.type){if(!g)throw new Error("no region sequence detected, need sequenceAdapter configuration");if(!s.get("seq"))continue;const{methBins:a,methProbs:r}=(0,d.getMethBins)(s),i=b.filter((t=>"deletion"===t.type));for(let s=0;s<o-t;s++){const o=s+t,c=g[o-e.start+1]?.toLowerCase(),d=g[o-e.start+2]?.toLowerCase();if("c"===c&&"g"===d){const c=h[o-e.start],d=h[o-e.start+1],l=a[s],u=a[s+1],g=r[s],b=r[s+1];l&&(void 0===g||g>.5)||u&&(void 0===b||b>.5)?(c&&(p(c,n,"cov","meth"),c.ref--,c[n]--),d&&(p(d,n,"cov","meth"),d.ref--,d[n]--)):(c&&(i?.some((e=>(0,f.doesIntersect2)(o,o+1,e.start+t,e.start+t+e.length)))||(p(c,n,"cov","unmeth"),c.ref--,c[n])),d&&(i?.some((e=>(0,f.doesIntersect2)(o+1,o+2,e.start+t,e.start+t+e.length)))||(p(d,n,"cov","unmeth"),d.ref--,d[n]--)))}}}const w="modifications"!==a?.type&&"methylation"!==a?.type;for(const o of b){const a=t+o.start,r=l(o),d=a+r;for(let t=a;t<a+r;t++){const s=t-e.start;if(s>=0&&s<h.length){const t=h[s],{base:e,type:a}=o,r=u(a);r?p(t,n,"noncov",a):(t.ref--,t[n]--),"deletion"===a||"skip"===a?(p(t,n,"delskips",a),t.total--):!r&&w&&(p(t,n,"cov",e),t.refbase=o.altbase)}}if("skip"===o.type){const t=`${a}_${d}_${n}`;void 0===i[t]&&(i[t]={feature:s,start:a,end:d,strand:n,xs:(0,c.bH)(s,"XS")||(0,c.bH)(s,"TS"),score:0}),i[t].score++}}}return{bins:h,skipmap:i}}(n,t,e,(t=>this.fetchSequence(t)));g.forEach(((e,o)=>{const n=t.start+o;s.next(new a.A({id:`${this.id}-${n}`,data:{score:e.total,snpinfo:e,start:n,end:n+1,refName:t.refName}}))})),Object.entries(h).forEach((([t,e])=>{s.next(new a.A({id:t,data:{type:"skip",start:e.start,end:e.end,strand:e.strand,score:e.score,xs:e.xs}}))})),s.complete()}),e.signal)}async getMultiRegionFeatureDensityStats(t,e){const{subadapter:s}=await this.configure();return s.getMultiRegionFeatureDensityStats(t,e)}async getRefNames(t={}){const{subadapter:e}=await this.configure();return e.getRefNames(t)}freeResources(){}}}}]);
//# sourceMappingURL=5461.b36b42ad.chunk.js.map