"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 a=s(46377),o=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,a){let o=t[s][a];void 0===o&&(o=t[s][a]={total:0,"-1":0,0:0,1:0}),o.total++,o[e]++}class g extends a.BaseFeatureDataAdapter{async configure(){const t=this.getConf("subadapter"),e=t.sequenceAdapter,s=await(this.getSubAdapter?.(t)),a=e?await(this.getSubAdapter?.(e)):void 0;if(!s)throw new Error("Failed to get subadapter");return{subadapter:s.dataAdapter,sequenceAdapter:a?.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:a}=await this.configure(),n=await(0,i._)(a.getFeatures(t,e).pipe((0,r.$)())),{bins:g,skipmap:h}=await async function(t,e,s,a){const{colorBy:o}=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 a(e):void 0,h=[];for(const s of t){const t=s.get("start"),a=s.get("end"),n=s.get("strand"),b=s.get("mismatches")||[];for(let s=t;s<a+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!==a&&(h[t].total++,h[t].all++,h[t].ref++,h[t][n]++))}if("modifications"===o?.type){const a=s.get("seq"),o=(0,c.c$)(s,"MM","Mm")||"",r=(0,d.parseCigar)(s.get("CIGAR")),i=s.get("end");if(a){const s=(0,d.getModificationPositions)(o,a,n);for(const{type:a,positions:o}of s){const s=`mod_${a}`;for(const a of(0,d.getNextRefPos)(r,o)){const o=a+t-e.start;o>=0&&o<h.length&&a+t<i&&(void 0===h[o]&&(h[o]={total:0,all:0,ref:0,"-1":0,0:0,1:0,lowqual:{},cov:{},delskips:{},noncov:{}}),p(h[o],n,"cov",s))}}}}if("methylation"===o?.type){if(!g)throw new Error("no region sequence detected, need sequenceAdapter configuration");if(!s.get("seq"))continue;const{methBins:o,methProbs:r}=(0,d.getMethBins)(s),i=b.filter((t=>"deletion"===t.type));for(let s=0;s<a-t;s++){const a=s+t,c=g[a-e.start+1]?.toLowerCase(),d=g[a-e.start+2]?.toLowerCase();if("c"===c&&"g"===d){const c=h[a-e.start],d=h[a-e.start+1],l=o[s],u=o[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)(a,a+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)(a+1,a+2,e.start+t,e.start+t+e.length)))||(p(d,n,"cov","unmeth"),d.ref--,d[n]--)))}}}const w="modifications"!==o?.type&&"methylation"!==o?.type;for(const a of b){const o=t+a.start,r=l(a),d=o+r;for(let t=o;t<o+r;t++){const s=t-e.start;if(s>=0&&s<h.length){const t=h[s],{base:e,type:o}=a,r=u(o);r?p(t,n,"noncov",o):(t.ref--,t[n]--),"deletion"===o||"skip"===o?(p(t,n,"delskips",o),t.total--):!r&&w&&(p(t,n,"cov",e),t.refbase=a.altbase)}}if("skip"===a.type){const t=`${o}_${d}_${n}`;void 0===i[t]&&(i[t]={feature:s,start:o,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,a)=>{const n=t.start+a;s.next(new o.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 o.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.5c8cf5d1.chunk.js.map