"use strict";(self.webpackChunk_jbrowse_web=self.webpackChunk_jbrowse_web||[]).push([[3139],{13139:(t,e,o)=>{o.r(e),o.d(e,{default:()=>v});var n=o(56798),s=o(85291),a=o(16979),i=o(26138),r=o(24201),c=o(39395),d=o(41814),l=o(90872);function u(t){return f(t.type)?1:t.length}function f(t){return"softclip"===t||"hardclip"===t||"insertion"===t}function p(t,e,o,n){let s=t[o][n];void 0===s&&(s=t[o][n]={total:0,"-1":0,0:0,1:0}),s.total++,s[e]++}class v extends n.BaseFeatureDataAdapter{async configure(){var t,e;const o=this.getConf("subadapter"),n=o.sequenceAdapter,s=await(null===(t=this.getSubAdapter)||void 0===t?void 0:t.call(this,o)),a=n?await(null===(e=this.getSubAdapter)||void 0===e?void 0:e.call(this,n)):void 0;if(!s)throw new Error("Failed to get subadapter");return{subadapter:s.dataAdapter,sequenceAdapter:null===a||void 0===a?void 0:a.dataAdapter}}async fetchSequence(t){const{sequenceAdapter:e}=await this.configure();if(e)return(0,c.O)(t,e)}getFeatures(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,a.ObservableCreate)((async o=>{const{subadapter:n}=await this.configure(),a=await(0,r.z)(n.getFeatures(t,e).pipe((0,i.q)())),{bins:v,skipmap:h}=await async function(t,e,o,n){var s;const{colorBy:a}=o,i={...e,start:Math.max(0,e.start-1),end:e.end+1},r=Math.ceil(i.end-i.start),v={},h=t.length&&(0,c.ES)(null===(s=o.colorBy)||void 0===s?void 0:s.type)?await n(e):void 0,g=[];for(const b of t){const t=b.get("start"),o=b.get("end"),n=b.get("strand"),s=b.get("mismatches")||[];for(let a=t;a<o+1;a++){const t=a-e.start;t>=0&&t<r&&(void 0===g[t]&&(g[t]={total:0,all:0,ref:0,"-1":0,0:0,1:0,lowqual:{},cov:{},delskips:{},noncov:{}}),a!==o&&(g[t].total++,g[t].all++,g[t].ref++,g[t][n]++))}if("modifications"===(null===a||void 0===a?void 0:a.type)){const o=b.get("seq"),s=(0,c.TN)(b,"MM","Mm")||"",a=(0,d.parseCigar)(b.get("CIGAR")),i=b.get("end");if(o){const r=(0,d.getModificationPositions)(s,o,n);for(const{type:o,positions:s}of r){const r="mod_".concat(o);for(const o of(0,d.getNextRefPos)(a,s)){const s=o+t-e.start;if(s>=0&&s<g.length&&o+t<i){void 0===g[s]&&(g[s]={total:0,all:0,ref:0,"-1":0,0:0,1:0,lowqual:{},cov:{},delskips:{},noncov:{}});const t=g[s];t?p(t,n,"cov",r):console.warn("Undefined position in modifications snpcoverage encountered")}}}}}if("methylation"===(null===a||void 0===a?void 0:a.type)){if(!h)throw new Error("no region sequence detected, need sequenceAdapter configuration");if(!b.get("seq"))continue;const{methBins:a,methProbs:i}=(0,d.getMethBins)(b),r=s.filter((t=>"deletion"===t.type));for(let s=0;s<o-t;s++){var w,m;const o=s+t,c=null===(w=h[o-e.start+1])||void 0===w?void 0:w.toLowerCase(),d=null===(m=h[o-e.start+2])||void 0===m?void 0:m.toLowerCase();if("c"===c&&"g"===d){const c=g[o-e.start],d=g[o-e.start+1],u=a[s],f=a[s+1],v=i[s],h=i[s+1];u&&(void 0===v||v>.5)||f&&(void 0===h||h>.5)?(c&&(p(c,n,"cov","meth"),c.ref--,c[n]--),d&&(p(d,n,"cov","meth"),d.ref--,d[n]--)):(c&&(null!==r&&void 0!==r&&r.some((e=>(0,l.doesIntersect2)(o,o+1,e.start+t,e.start+t+e.length)))||(p(c,n,"cov","unmeth"),c.ref--,c[n])),d&&(null!==r&&void 0!==r&&r.some((e=>(0,l.doesIntersect2)(o+1,o+2,e.start+t,e.start+t+e.length)))||(p(d,n,"cov","unmeth"),d.ref--,d[n]--)))}}}const i="modifications"!==(null===a||void 0===a?void 0:a.type)&&"methylation"!==(null===a||void 0===a?void 0:a.type);for(const a of s){const o=t+a.start,s=u(a),r=o+s;for(let t=o;t<o+s;t++){const o=t-e.start;if(o>=0&&o<g.length){const t=g[o],{base:e,type:s}=a,r=f(s);r?p(t,n,"noncov",s):(t.ref--,t[n]--),"deletion"===s||"skip"===s?(p(t,n,"delskips",s),t.total--):!r&&i&&(p(t,n,"cov",e),t.refbase=a.altbase)}}if("skip"===a.type){const t="".concat(o,"_").concat(r,"_").concat(n);void 0===v[t]&&(v[t]={feature:b,start:o,end:r,strand:n,xs:(0,c.h1)(b,"XS")||(0,c.h1)(b,"TS"),score:0}),v[t].score++}}}return{bins:g,skipmap:v}}(a,t,e,(t=>this.fetchSequence(t)));v.forEach(((e,n)=>{const a=t.start+n;o.next(new s.Z({id:"".concat(this.id,"-").concat(a),data:{score:e.total,snpinfo:e,start:a,end:a+1,refName:t.refName}}))})),Object.entries(h).forEach((t=>{let[e,n]=t;o.next(new s.Z({id:e,data:{type:"skip",start:n.start,end:n.end,strand:n.strand,score:n.score,xs:n.xs}}))})),o.complete()}),e.signal)}async getMultiRegionFeatureDensityStats(t,e){const{subadapter:o}=await this.configure();return o.getMultiRegionFeatureDensityStats(t,e)}async getRefNames(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{subadapter:e}=await this.configure();return e.getRefNames(t)}freeResources(){}}}}]);
//# sourceMappingURL=3139.9acfc3af.chunk.js.map