igv 2.12.5 → 2.12.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ function(t){var e,n,r,i,o,s,a,c,l,h,u,f,d,p,g,m,v,b,w,y="sizzle"+1*new Date,x=t.
36
36
  *
37
37
  * Copyright (c) 2014 Gliffy Inc.
38
38
  */
39
- function Ps(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function Os(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(Math.random()*e.length)]}while(t[n]);return n}function Fs(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}function Ds(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]}const Bs=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),zs={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"},lineDash:{svgAttr:"stroke-dasharray",canvas:[],svg:null,apply:"stroke"}};class Hs{constructor(t,e){this.__root=t,this.__ctx=e}addColorStop(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),e&&-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",Ps("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)}}class Vs{constructor(t,e){this.__root=t,this.__ctx=e}}class js{constructor(t){if(!(this instanceof js))return new js(t);if(this.config=t,this.width=t.width,this.height=t.height,this.enableMirroring=t.enableMirroring||!1,this.canvas=this,this.__document=document,t.ctx?this.__ctx=t.ctx:(this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d")),this.isSVG=!0,this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__createElement("svg"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__root.setAttribute("overflow","visible"),t.viewbox){const e=t.viewbox.x+" "+t.viewbox.y+" "+t.viewbox.width+" "+t.viewbox.height;this.__root.setAttribute("viewBox",e),this.viewbox=t.viewbox}this.__ids={},this.__defs=this.__createElement("defs"),this.__root.appendChild(this.__defs),this.multiLocusGap=t.multiLocusGap;let e={id:"svg_output_backdrop",width:"100%",height:"100%",fill:t.backdropColor||"white"},n=this.__createElement("rect",e);this.__root.appendChild(n),this.__rootGroup=this.__createElement("g",{id:"root-group"}),this.__root.appendChild(this.__rootGroup),this.__currentElement=this.__rootGroup}setWidth(t){this.width=t,this.__root.setAttribute("width",this.width);const e=this.config.viewbox.x+" "+this.config.viewbox.y+" "+t+" "+this.config.viewbox.height;this.__root.setAttribute("viewBox",e)}setHeight(t){this.height=t,this.__root.setAttribute("height",this.height);const e=this.config.viewbox.x+" "+this.config.viewbox.y+" "+this.config.viewbox.width+" "+t;this.__root.setAttribute("viewBox",e)}__createElement(t,e,n){void 0===e&&(e={});let r=this.__document.createElementNS("http://www.w3.org/2000/svg",t);n&&(r.setAttribute("fill","none"),r.setAttribute("stroke","none"));for(let t of Object.keys(e))r.setAttribute(t,e[t]);return r}__setDefaultStyles(){var t,e,n=Object.keys(zs);for(t=0;t<n.length;t++)this[e=n[t]]=zs[e].canvas}__applyStyleState(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]}__getStyleState(){var t,e,n={},r=Object.keys(zs);for(t=0;t<r.length;t++)n[e=r[t]]=this[e];return n}__applyStyleToCurrentElement(t){var e=this.__currentElement,n=this.__currentElementsToStyle;n&&(e.setAttribute(t,""),e=n.element,n.children.forEach((function(e){e.setAttribute(t,"")})));var r,i,o,s,a,c=Object.keys(zs);for(r=0;r<c.length;r++)if(i=zs[c[r]],o=this[c[r]],i.apply)if(o instanceof Vs){if(o.__ctx)for(;o.__ctx.__defs.childNodes.length;)s=o.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[s]=s,this.__defs.appendChild(o.__ctx.__defs.childNodes[0]);e.setAttribute(i.apply,Ps("url(#{id})",{id:o.__root.getAttribute("id")}))}else if(o instanceof Hs)e.setAttribute(i.apply,Ps("url(#{id})",{id:o.__root.getAttribute("id")}));else if(i&&-1!==i.apply.indexOf(t)&&i.svg!==o)if("stroke"!==i.svgAttr&&"fill"!==i.svgAttr||!o||-1===o.indexOf("rgba")){var l=i.svgAttr;if("globalAlpha"===c[r]&&(l=t+"-"+i.svgAttr,e.getAttribute(l)))continue;e.setAttribute(l,o)}else{a=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(o),e.setAttribute(i.svgAttr,Ps("rgb({r},{g},{b})",{r:a[1],g:a[2],b:a[3]}));var h=a[4],u=this.globalAlpha;null!=u&&(h*=u),e.setAttribute(i.svgAttr+"-opacity",h)}}__closestGroupOrSvg(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)}getSerializedSvg(t){var e,n,r,i,o,s=(new XMLSerializer).serializeToString(this.__root);if(t)for(e=Object.keys(Bs),n=0;n<e.length;n++)r=e[n],i=Bs[r],(o=new RegExp(r,"gi")).test(s)&&(s=s.replace(o,i));return s}getSvg(){return this.__root}saveWithTranslationAndClipRect(t,e,n,r,i,o){const s=`${t}_clip_rect`;let a=this.__createElement("clipPath",{id:s});this.__defs.appendChild(a);const c={x:"0",y:o.toString(),width:r.toString(),height:i.toString()};a.appendChild(this.__createElement("rect",c));const l=this.__createElement("g");l.setAttribute("transform",Ps("translate({x},{y})",{x:e,y:n})),l.setAttribute("clip-path",Ps("url(#{id})",{id:s}));const h=this.__closestGroupOrSvg();h.appendChild(l),this.__groupStack.push(h),this.__currentElement=l,this.__stack.push(this.__getStyleState())}save(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())}restore(){this.__currentElement=this.__groupStack.pop(),this.__currentElementsToStyle=null,this.__currentElement||(this.__currentElement=this.__root.childNodes[1]);var t=this.__stack.pop();this.__applyStyleState(t)}__addTransform(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){"path"===this.__currentElement.nodeName&&(this.__currentElementsToStyle||(this.__currentElementsToStyle={element:e,children:[]}),this.__currentElementsToStyle.children.push(this.__currentElement),this.__applyCurrentDefaultPath());var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)}addTrackGroupWithTranslationAndClipRect(t,e,n,r,i,o){const s=t+"_clip_rect";let a=this.__createElement("clipPath",{id:s});this.__defs.appendChild(a),a.appendChild(this.__createElement("rect",{x:"0",y:o.toString(),width:r.toString(),height:i.toString()}));let c=this.__createElement("g");this.__rootGroup.appendChild(c),c.setAttribute("transform",Ps("translate({x},{y})",{x:e,y:n})),c.setAttribute("id",t+"_group"),c.setAttribute("clip-path",Ps("url(#{id})",{id:s})),this.__currentElement=c}scale(t,e){void 0===e&&(e=t),this.__addTransform(Ps("scale({x},{y})",{x:t,y:e}))}rotate(t){var e=180*t/Math.PI;this.__addTransform(Ps("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))}translate(t,e){this.__addTransform(Ps("translate({x},{y})",{x:t,y:e}))}transform(t,e,n,r,i,o){this.__addTransform(Ps("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:o}))}beginPath(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t}__applyCurrentDefaultPath(){var t=this.__currentElement;"path"===t.nodeName?t.setAttribute("d",this.__currentDefaultPath):console.error("Attempted to apply path command to node",t.nodeName)}__addPathCommand(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t}moveTo(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(Ps("M {x} {y}",{x:t,y:e}))}closePath(){this.__currentDefaultPath&&this.__addPathCommand("Z")}lineTo(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath&&this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(Ps("L {x} {y}",{x:t,y:e})):this.__addPathCommand(Ps("M {x} {y}",{x:t,y:e}))}bezierCurveTo(t,e,n,r,i,o){this.__currentPosition={x:i,y:o},this.__addPathCommand(Ps("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:o}))}quadraticCurveTo(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(Ps("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))}arcTo(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=Ds([o-t,s-e]),c=Ds([n-t,r-e]);if(a[0]*c[1]!=a[1]*c[0]){var l=a[0]*c[0]+a[1]*c[1],h=Math.acos(Math.abs(l)),u=Ds([a[0]+c[0],a[1]+c[1]]),f=i/Math.sin(h/2),d=t+f*u[0],p=e+f*u[1],g=[-a[1],a[0]],m=[c[1],-c[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},b=v(g),w=v(m);this.lineTo(d+g[0]*i,p+g[1]*i),this.arc(d,p,i,b,w)}else this.lineTo(t,e)}}}stroke(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")}fill(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")}rect(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()}fillRect(t,e,n,r){r<0&&(e+=r,r=-r),n<0&&(t+=n,n=-n);var i,o,s,a={x:t,y:e,width:n,height:r};(!this.viewbox||(i=this.viewbox,o=a,i.x<o.x+o.width&&i.x+i.width>o.x&&i.y<o.y+o.height&&i.y+i.height>o.y))&&(s=this.__createElement("rect",a,!0),this.__closestGroupOrSvg().appendChild(s),this.__currentElement=s,this.__applyStyleToCurrentElement("fill"))}strokeRect(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")}strokeEllipse(t,e,n,r,i,o,s,a){this.__ellipse(t,e,n,r,i,o,s,a,"stroke")}fillEllipse(t,e,n,r,i,o,s,a){this.__ellipse(t,e,n,r,i,o,s,a,"fill")}__ellipse(t,e,n,r,i,o,s,a,c){const l={cx:t,cy:e,rx:n,ry:r},h=this.__createElement("ellipse",l,!0);this.__closestGroupOrSvg().appendChild(h),this.__currentElement=h,this.__applyStyleToCurrentElement(c)}__clearCanvas(){for(var t=this.__closestGroupOrSvg().getAttribute("transform"),e=this.__root.childNodes[1],n=e.childNodes,r=n.length-1;r>=0;r--)n[r]&&e.removeChild(n[r]);this.__currentElement=e,this.__groupStack=[],t&&this.__addTransform(t)}clearRect(t,e,n,r){if(0!==t||0!==e||n!==this.width||r!==this.height){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)}else this.__clearCanvas()}createLinearGradient(t,e,n,r){var i=this.__createElement("linearGradient",{id:Os(this.__ids),x1:t+"px",x2:n+"px",y1:e+"px",y2:r+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(i),new Hs(i,this)}createRadialGradient(t,e,n,r,i,o){var s=this.__createElement("radialGradient",{id:Os(this.__ids),cx:r+"px",cy:i+"px",r:o+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(s),new Hs(s,this)}__parseFont(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\'\"\sa-z0-9]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e}__wrapTextLink(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e}__applyText(t,e,n,r){var i,o,s=this.__parseFont(),a=this.__closestGroupOrSvg(),c=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":Fs(this.textBaseline)},!0);c.appendChild(this.__document.createTextNode(t)),this.__currentElement=c,this.__applyStyleToCurrentElement(r),a.appendChild(this.__wrapTextLink(s,c))}fillText(t,e,n){this.__applyText(t,e,n,"fill")}strokeText(t,e,n){this.__applyText(t,e,n,"stroke")}measureText(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)}arc(t,e,n,r,i,o){if(r!==i){(r%=2*Math.PI)===(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(o?-1:1))%(2*Math.PI));var s=t+n*Math.cos(i),a=e+n*Math.sin(i),c=t+n*Math.cos(r),l=e+n*Math.sin(r),h=o?0:1,u=0,f=i-r;f<0&&(f+=2*Math.PI),u=o?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(c,l),this.__addPathCommand(Ps("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:u,sweepFlag:h,endX:s,endY:a})),this.__currentPosition={x:s,y:a}}}clip(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=Os(this.__ids),r=this.__createElement("g");this.__applyCurrentDefaultPath(),t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",Ps("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r}drawImage(){var t,e,n,r,i,o,s,a,c,l,h,u,f,d=Array.prototype.slice.call(arguments),p=d[0],g=0,m=0;if(3===d.length)t=d[1],e=d[2],n=i=p.width,r=o=p.height;else if(5===d.length)t=d[1],e=d[2],n=d[3],r=d[4],i=p.width,o=p.height;else{if(9!==d.length)throw new Error("Invalid number of arguments passed to drawImage: "+arguments.length);g=d[1],m=d[2],i=d[3],o=d[4],t=d[5],e=d[6],n=d[7],r=d[8]}s=this.__closestGroupOrSvg();var v="translate("+t+", "+e+")";if(p instanceof js){if((a=p.getSvg().cloneNode(!0)).childNodes&&a.childNodes.length>1){for(c=a.childNodes[0];c.childNodes.length;)f=c.childNodes[0].getAttribute("id"),this.__ids[f]=f,this.__defs.appendChild(c.childNodes[0]);if(l=a.childNodes[1]){var b,w=l.getAttribute("transform");b=w?w+" "+v:v,l.setAttribute("transform",b),s.appendChild(l)}}}else"CANVAS"!==p.nodeName&&"IMG"!==p.nodeName||((h=this.__createElement("image")).setAttribute("width",n),h.setAttribute("height",r),h.setAttribute("preserveAspectRatio","none"),(g||m||i!==p.width||o!==p.height)&&((u=this.__document.createElement("canvas")).width=n,u.height=r,u.getContext("2d").drawImage(p,g,m,i,o,0,0,n,r),p=u),h.setAttribute("transform",v),h.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===p.nodeName?p.toDataURL():p.getAttribute("src")),s.appendChild(h))}createPattern(t,e){let n,r=this.__document.__createElement("pattern"),i=Os(this.__ids);return r.setAttribute("id",i),r.setAttribute("width",t.width),r.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?(n=this.__createElement("image"),n.setAttribute("width",t.width),n.setAttribute("height",t.height),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),r.appendChild(n),this.__defs.appendChild(r)):t instanceof js&&(r.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(r)),new Vs(r,this)}setLineDash(t){t&&t.length>0?this.lineDash=t.join(","):this.lineDash=null}drawFocusRing(){}createImageData(){}getImageData(){}putImageData(){}globalCompositeOperation(){}setTransform(){}}const Us=function(t,e,n,r,i){this.name=t,this.order=e,this.bpStart=n,this.bpLength=r,this.rangeLocus=i},qs=Se,Ws=new Set(["fastaURL","indexURL","cytobandURL","indexed"]);class $s{constructor(t){this.fastaURL=t.fastaURL,this.withCredentials=t.withCredentials,this.chromosomeNames=[],this.chromosomes={},this.sequences=new Map,this.offsets={};const e={};for(let n in t)t.hasOwnProperty(n)&&!Ws.has(n)&&(e[n]=t[n]);this.config=e}async init(){return this.loadAll()}async getSequence(t,e,n){this.offsets[t]&&(e-=this.offsets[t],n-=this.offsets[t]);let r="";if(e<0)for(let t=e;t<Math.min(n,0);t++)r+="*";if(n<=0)return Promise.resolve(r);const i=this.sequences.get(t),o=Math.min(n,i.length);return r+i.substring(e,o)}async loadAll(){let t;if(ys(this.fastaURL)){let e=Yi(this.fastaURL);t="";for(let n of e)t+=String.fromCharCode(n)}else t=await go.load(this.fastaURL,gs(this.config));const e=qs(t),n=e.length;let r,i,o,s,a=0,c=0,l=0;for(;a<n;)if(o=e[a++].trim(),o.startsWith("#")||0===o.length);else if(o.startsWith(">")){r&&(this.chromosomeNames.push(s),this.sequences.set(s,r),this.chromosomes[s]=new Us(s,l++,c,c+r.length,i));const t=o.substr(1).split(/\s+/)[0].split(":");if(s=t[0],r="",c=0,i=void 0,t.length>1&&t[1].indexOf("-")>0){const e=t[1].split("-");2===e.length&&/^[0-9]+$/.test(e[0])&&/^[0-9]+$/.test(e[1]);const n=Number.parseInt(e[0]);Number.parseInt(e[1])>n&&(c=n-1,this.offsets[s]=c,i=t[1])}}else r+=o;r&&(this.chromosomeNames.push(s),this.sequences.set(s,r),this.chromosomes[s]=new Us(s,l++,c,c+r.length,i))}}const Gs=function(t,e,n,r){this.chr=t,this.start=e,this.end=n,this.features=r};Gs.prototype.contains=function(t,e,n){return this.chr===t&&this.start<=e&&this.end>=n},Gs.prototype.containsRange=function(t){return this.chr===t.chr&&this.start<=t.start&&this.end>=t.end};const Zs=Se,Xs=new Set(["fastaURL","indexURL","compressedIndexURL","cytobandURL","indexed"]);class Ys{constructor(t){this.file=t.fastaURL,this.indexFile=t.indexURL||t.indexFile||this.file+".fai",this.compressedIndexFile=t.compressedIndexURL||!1,this.withCredentials=t.withCredentials,this.chromosomeNames=[],this.chromosomes={},this.sequences={},this.offsets={};const e={};for(let n in t)t.hasOwnProperty(n)&&!Xs.has(n)&&(e[n]=t[n]);this.config=e}async init(){return this.getIndex()}async getSequence(t,e,n){if(!(this.interval&&this.interval.contains(t,e,n))){let r=e,i=n;if(n-e<5e4){const t=n-e,o=Math.round(e+t/2);r=Math.max(0,o-25e3),i=o+25e3}const o=await this.readSequence(t,r,i);this.interval=new Gs(t,r,i,o)}const r=e-this.interval.start,i=n-e;return this.interval.features?this.interval.features.substr(r,i):null}async getIndex(){if(this.index)return this.index;{const t=await go.load(this.indexFile,gs(this.config)),e=Zs(t),n=e.length;let r=0,i=0;for(this.index={};r<n;){const t=e[r++].split("\t");if(5===t.length){const e=t[0],n=parseInt(t[1]),r={size:n,position:parseInt(t[2]),basesPerLine:parseInt(t[3]),bytesPerLine:parseInt(t[4])};this.chromosomeNames.push(e),this.index[e]=r,this.chromosomes[e]=new Us(e,i++,0,n)}}return this.index}}async getCompressedIndex(){if(this.compressedIndex)return this.compressedIndex;if(!this.compressedIndexFile)return this.compressedIndex=[],this.compressedIndex;this.compressedIndex=[];const t=await go.loadArrayBuffer(this.compressedIndexFile,gs(this.config)),e=t.byteLength;if(e<8)return console.log("Cannot parse GZI index file: length ("+e+" bytes) is insufficient to determine content of index."),this.compressedIndex;const n=t.slice(0,8),r=Number(new DataView(n).getBigUint64(0,!0)),i=8+2*r*8;if(e!=i)return console.log("Incorrect file size of reference genome index. Expected : "+i+". Received : "+e),this.compressedIndex;this.compressedIndex.push([0,0]);for(let e=0;e<r;e++){const n=8+2*e*8,r=8+2*e*8+16,i=t.slice(n,r),o=new DataView(i),s=Number(o.getBigUint64(0,!0)),a=Number(o.getBigUint64(8,!0));this.compressedIndex.push([s,a])}return this.compressedIndex}async getRelevantCompressedBlockNumbers(t,e){if(t<0||e<0||e<t)return console.log("Incompatible query positions for reference-genome. Start:"+t+" | End:"+e),[];await this.getCompressedIndex();let n=[];const r=this.compressedIndex.length-1;if(0==this.compressedIndex.length)return console.log("Compressed index does not contain any content"),[];if(t>this.compressedIndex[r][1])return[r];let i=0,o=r,s=Math.floor(this.compressedIndex.length/2),a=this.compressedIndex.length+1,c=!1;for(let e=0;e<a;e++){const e=this.compressedIndex[s][1],n=s<this.compressedIndex.length-1?this.compressedIndex[s+1][1]:1/0;if(e<=t&&n>t){c=!0;break}e<t?i=s+1:o=s-1,s=Math.ceil((o-i)/2)+i}if(!c)return console.log("No blocks within compressed index found that correspond with query positions "+t+","+e),console.log(this.compressedIndex),[];n.push(s);for(let t=s+1;t<this.compressedIndex.length;t++){n.push(t);if(this.compressedIndex[t][1]>=e)break}const l=n[n.length-1];return l===this.compressedIndex.length-1&&this.compressedIndex[l][1]<e&&n.push(-1),n}async loadAndUncompressBlocks(t,e){if(await this.getCompressedIndex(),0==t.length)return"";let n=Array(t.length-1);for(let e=0;e<t.length-1;e++){const r=t[e],i=this.compressedIndex[r][0],o=t[e+1];let s=[];if(-1!=o){const t=this.compressedIndex[o][0]-i;s=await go.loadArrayBuffer(this.file,gs(this.config,{range:{start:i,size:t}}))}else s=await go.loadArrayBuffer(this.file,gs(this.config,{range:{start:i}}));const a=await Wi(s);n[e]=a}let r="";for(let t=0;t<n.length;t++)for(let e=0;e<n[t].length;e++){r+=String.fromCharCode(n[t][e])}const i=e-this.compressedIndex[t[0]][1];return r=r.substring(i),r}async readSequence(t,e,n){await this.getIndex(),await this.getCompressedIndex();const r=this.index[t];if(!r)return console.log("No index entry for chr: "+t),this.interval=new Gs(t,e,n,null),null;const i=Math.max(0,e),o=Math.min(r.size,n),s=r.bytesPerLine,a=r.basesPerLine,c=r.position,l=s-a,h=Math.floor(i/a),u=Math.floor(o/a),f=i-h*a,d=c+h*s+f,p=c+u*s+(o-u*a)-1,g=p-d+1;if(g<=0)return console.error("No sequence for "+t+":"+e+"-"+n),null;let m;if(this.compressedIndexFile){let t=await this.getRelevantCompressedBlockNumbers(d,p);if(0===t.length)return console.log("No blocks in the compressed index that correspond with the requested byte positions ("+d+","+p+")"),null;m=await this.loadAndUncompressBlocks(t,d)}else m=await go.load(this.file,gs(this.config,{range:{start:d,size:g}}));if(!m)return null;let v,b="",w=0,y=m.length;for(f>0&&(v=Math.min(o-i,a-f),b+=m.substr(w,v),w+=v+l);w<y;)v=Math.min(a,y-w),b+=m.substr(w,v),w+=v+l;return b}}const Ks=Se;class Qs{constructor(t){this.url=t,this.chromosomeNames=[],this.chromosomes={}}async init(){return this.loadAll()}async getSequence(t,e,n){}async loadAll(){let t;if(ys(this.url)){let e=Yi(this.fastaURL);t="";for(let n of e)t+=String.fromCharCode(n)}else t=await go.load(this.url,{});this.chromosomeNames=[],this.chromosomes={};const e=Ks(t);let n=0;for(let t of e){const e=t.split("\t");this.chromosomeNames.push(e[0]);const r=Number.parseInt(e[1]),i=new Us(e[0],n++,0,r);this.chromosomes[e[0]]=i}}}const Js=function(t,e,n,r){this.start=t,this.end=e,this.name=n,this.stain=0,"acen"===r?this.type="c":(this.type=r.charAt(1),"p"===this.type&&(this.stain=parseInt(r.substring(4))))};function ta(){return"2.12.5"}const ea=Se,na={loadGenome:async function(t){const e=t.cytobandURL,n=t.aliasURL,r=await async function(t){let e;return e="chromsizes"===t.format?new Qs(t.fastaURL):ys(t.fastaURL)||!1===t.indexed?new $s(t):new Ys(t),await e.init(),e}(t);let i,o;return e&&(i=await async function(t,e){let n;if(ys(t)){const e=Yi(t);n="";const r=e.length;for(let t=0;t<r;t++)n+=String.fromCharCode(e[t])}else n=await go.loadString(t,gs(e));const r={};let i,o=[];const s=ea(n);for(let t of s){var a=t.split("\t"),c=a[0];if(i||(i=c),c!==i&&(r[i]=o,o=[],i=c),5===a.length){var l=parseInt(a[1]),h=parseInt(a[2]),u=a[3],f=a[4];o.push(new Js(l,h,u,f))}}return r}(e,r.config)),n&&(o=await function(t,e){return go.loadString(t,gs(e)).then((function(t){var e=ea(t),n=[];return e.forEach((function(t){!t.startsWith("#")&&t.length>0&&n.push(t.split("\t"))})),n}))}(n,r.config)),new ra(t,r,i,o)},initializeGenomes:async function(t){if(!na.KNOWN_GENOMES){const n={};if(!1!==t.loadDefaultGenomes)try{const i=`https://igv.org/genomes/genomes.json?randomSeed=${Math.random().toString(36)}&version=2.12.5`;e(await go.loadJson(i,{timeout:5e3}))}catch(o){console.error(o);try{const s=`https://s3.amazonaws.com/igv.org.genomes/genomes.json?randomSeed=${Math.random().toString(36)}&version=2.12.5`;e(await go.loadJson(s,{}))}catch(a){console.error(a),console.warn("Errors loading default genome definitions.")}}const r=t.genomeList||t.genomes;if(r)if("string"==typeof r){e(await go.loadJson(r,{}))}else e(r);function e(t){return t.forEach((function(t){n[t.id]=t})),n}na.KNOWN_GENOMES=n}},isWholeGenomeView:function(t){return"all"===t.toLowerCase()},expandReference:function(t){if(ke(t)&&t.startsWith("{"))try{t=JSON.parse(t)}catch(t){}let e;if(ke(t)?e=t:t.genome?e=t.genome:void 0!==t.id&&void 0===t.fastaURL&&(e=t.id),e){const t=na.KNOWN_GENOMES[e];return t||Qo.presentAlert(new Error(`Unknown genome id: ${e}`),void 0),t}return t}};class ra{constructor(t,e,n,r){this.config=t,this.id=t.id||function(t){return void 0!==t.id?t.id:t.fastaURL&&ke(t.fastaURL)?t.fastaURL:t.fastaURL&&t.fastaURL.name?t.fastaURL.name:("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}(t),this.sequence=e,this.chromosomeNames=e.chromosomeNames,this.chromosomes=e.chromosomes,this.ideograms=n,this.featureDB={},this.wholeGenomeView=void 0===t.wholeGenomeView||t.wholeGenomeView,this.wholeGenomeView&&Object.keys(e.chromosomes).length>1?function(t,e){let n;if(e.chromosomeOrder)Array.isArray(e.chromosomeOrder)?t.wgChromosomeNames=e.chromosomeOrder:t.wgChromosomeNames=e.chromosomeOrder.split(",").map((t=>t.trim())),n=t.wgChromosomeNames.map((e=>t.chromosomes[e])).filter((t=>void 0!==t));else{const e=Object.keys(t.chromosomes).map((e=>t.chromosomes[e].bpLength)).reduce(((t,e)=>Math.max(t,e)))/50;n=Object.values(t.chromosomes).filter((t=>t.bpLength>e));const r=n.filter((t=>i(t.name.replace("chr","")))),o=n.filter((t=>!i(t.name.replace("chr",""))));r.sort(((t,e)=>Number.parseInt(t.name.replace("chr",""))-Number.parseInt(e.name.replace("chr",""))));const s=r.map((t=>t.name));for(let t of o)s.push(t.name);t.wgChromosomeNames=s}const r=n.reduce(((t,e)=>t+e.bpLength),0);function i(t){return/^\d+$/.test(t)}t.chromosomes.all={name:"all",bpLength:r}}(this,t):this.wgChromosomeNames=e.chromosomeNames;var i={},o=this;i.all="all",this.chromosomeNames.forEach((function(t){var e=t.startsWith("chr")?t.substring(3):"chr"+t;i[e.toLowerCase()]=t,"chrM"===t&&(i.mt="chrM"),"MT"===t&&(i.chrm="MT"),i[t.toLowerCase()]=t})),r&&r.forEach((function(t){var e,n;for(n=0;n<t.length;n++)if(o.chromosomes[t[n]]){e=t[n];break}e&&t.forEach((function(t){t!==e&&(i[t.toLowerCase()]=e,i[t]=e)}))})),this.chrAliasTable=i}showWholeGenomeView(){return!1!==this.config.wholeGenomeView}toJSON(){return Object.assign({},this.config,{tracks:void 0})}getInitialLocus(){}getHomeChromosomeName(){return this.showWholeGenomeView()&&this.chromosomes.hasOwnProperty("all")?"all":this.chromosomeNames[0]}getChromosomeName(t){const e=t?this.chrAliasTable[t.toLowerCase()]:t;return e||t}getChromosome(t){return t=this.getChromosomeName(t),this.chromosomes[t]}getCytobands(t){return this.ideograms?this.ideograms[t]:null}getLongestChromosome(){var t,e=this.chromosomes;for(let r in e){if(e.hasOwnProperty(r)){var n=e[r];(void 0===t||n.bpLength>t.bpLength)&&(t=n)}return t}}getChromosomes(){return this.chromosomes}getGenomeCoordinate(t,e){var n=this.getCumulativeOffset(t);if(void 0!==n)return n+e}getChromosomeCoordinate(t){let e;void 0===this.cumulativeOffsets&&(this.cumulativeOffsets=computeCumulativeOffsets.call(this));let n=0;for(let r of this.wgChromosomeNames){const i=this.cumulativeOffsets[r];if(i>t){return{chr:e,position:t-n}}e=r,n=i}return{chr:this.wgChromosomeNames[this.wgChromosomeNames.length-1],position:0}}getCumulativeOffset(t){void 0===this.cumulativeOffsets&&(this.cumulativeOffsets=function(){let t=this,e={},n=0;for(let r of t.wgChromosomeNames){e[r]=Math.floor(n);n+=t.getChromosome(r).bpLength}return e}.call(this));const e=this.getChromosomeName(t);return this.cumulativeOffsets[e]}getGenomeLength(){let t=this;if(!this.bpLength){let e=0;t.wgChromosomeNames.forEach((function(n){let r=t.chromosomes[n];e+=r.bpLength})),this.bpLength=e}return this.bpLength}async getSequence(t,e,n){return t=this.getChromosomeName(t),this.sequence.getSequence(t,e,n)}}let ia,oa=0;class sa extends class{constructor(t,e,n,r){this.guid=ve(),this.trackView=t,this.referenceFrame=n,this.browser=t.browser,this.$viewport=de('<div class="igv-viewport">'),e.appendChild(this.$viewport.get(0)),t.track.height&&(this.$viewport.get(0).style.height=`${t.track.height}px`),t.track instanceof Ns&&(this.alert=new Yo(this.$viewport.get(0))),this.$content=de("<div>",{class:"igv-viewport-content"}),this.$viewport.append(this.$content),this.$content.height(this.$viewport.height()),this.contentDiv=this.$content.get(0),this.$viewport.width(r),this.initializationHelper()}initializationHelper(){}showMessage(t){this.messageDiv||(this.messageDiv=document.createElement("div"),this.messageDiv.className="igv-viewport-message",this.contentDiv.append(this.messageDiv)),this.messageDiv.textContent=t,this.messageDiv.style.display="inline-block"}hideMessage(t){this.messageDiv&&(this.messageDiv.style.display="none")}setTrackLabel(t){}startSpinner(){}stopSpinner(){}checkZoomIn(){return!0}shift(){}setTop(t){const e=-t,n=e+this.$viewport.height();this.$content.css("top",`${t}px`),(void 0===this.canvasVerticalRange||this.canvasVerticalRange.bottom<n||this.canvasVerticalRange.top>e)&&this.repaint()}async loadFeatures(){}async repaint(){console.log("Viewport - repaint()")}draw(t,e,n){console.log("Viewport - draw(drawConfiguration, features, roiFeatures)")}checkContentHeight(t){let e=this.trackView.track;if(t=t||this.cachedFeatures,"FILL"===e.displayMode)this.setContentHeight(this.$viewport.height());else if("function"==typeof e.computePixelHeight&&t&&t.length>0){let n=e.computePixelHeight(t);n!==this.$content.height()&&this.setContentHeight(n)}}getContentHeight(){return this.$content.height()}setContentHeight(t){t=Math.min(t,32e3),this.$content.height(t)}isLoading(){return!1}saveSVG(){}isVisible(){return this.$viewport.width()}setWidth(t){this.$viewport.width(t)}getWidth(){return this.$viewport.width()}getContentTop(){return this.contentDiv.offsetTop}containsPosition(t,e){console.log("Viewport - containsPosition(chr, position)")}addMouseHandlers(){}removeMouseHandlers(){}dispose(){this.popover&&this.popover.dispose(),this.$viewport.get(0).remove();for(let t of Object.keys(this))this[t]=void 0}}{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.$spinner=de("<div>",{class:"igv-loading-spinner-container"}),this.$viewport.append(this.$spinner),this.$spinner.append(de("<div>"));const t=this.trackView.track;"sequence"!==t.type&&(this.$zoomInNotice=this.createZoomInNotice(this.$content)),t.name&&"sequence"!==t.id&&(this.$trackLabel=de('<div class="igv-track-label">'),this.$viewport.append(this.$trackLabel),this.setTrackLabel(t.name),!1===this.browser.trackLabelsVisible&&this.$trackLabel.hide()),this.stopSpinner(),this.addMouseHandlers()}setContentHeight(t){super.setContentHeight(t),this.featureCache&&(this.featureCache.redraw=!0)}setTrackLabel(t){this.$trackLabel.empty(),this.$trackLabel.html(t);const e=this.$trackLabel.text();this.$trackLabel.attr("title",e)}startSpinner(){this.$spinner.show()}stopSpinner(){this.$spinner&&this.$spinner.hide()}checkZoomIn(){if(this.trackView.track&&"sequence"===this.trackView.track.type&&this.referenceFrame.bpPerPixel>1)return de(this.canvas).remove(),this.canvas=void 0,!1;if(!this.viewIsReady())return!1;if((()=>{if("all"!==this.referenceFrame.chr.toLowerCase()||this.trackView.track.supportsWholeGenome){const t=this.trackView.track.visibilityWindow;return void 0!==t&&t>0&&this.referenceFrame.bpPerPixel*this.$viewport.width()>t}return!0})()){if(this.canvas&&(de(this.canvas).remove(),this.canvas=void 0),this.trackView.track.autoHeight){const t=this.trackView.minHeight||0;this.setContentHeight(t)}return this.$zoomInNotice&&this.$zoomInNotice.show(),!1}return this.$zoomInNotice&&this.$zoomInNotice.hide(),!0}shift(){const t=this.referenceFrame;if(this.canvas&&this.canvas._data&&this.canvas._data.chr===this.referenceFrame.chr&&this.canvas._data.bpPerPixel===t.bpPerPixel){const e=Math.round((this.canvas._data.startBP-t.start)/t.bpPerPixel);this.canvas.style.left=e+"px"}}async loadFeatures(){const t=this.referenceFrame,e=t.chr,n=this.browser.genome.getChromosome(e).bpLength,r=this.$content.width()*t.bpPerPixel,i=Math.floor(Math.max(0,t.start-r)),o=Math.ceil(Math.min(n,t.start+r+r));if(!this.loading||this.loading.start!==i||this.loading.end!==o){this.loading={start:i,end:o},this.startSpinner();try{const n=this.trackView.track,r=await this.getFeatures(n,e,i,o,t.bpPerPixel);let c=[];const l=(s=this.browser.roi,a=n.roi,s&&a?s.concat(a):s||a);if(l)for(let n of l){const r=await n.getFeatures(e,i,o,t.bpPerPixel);c.push({track:n,features:r})}const h=n&&("wig"===n.type||"merged"===n.type);return this.featureCache=new ca(e,i,o,t.bpPerPixel,r,c,h),this.loading=!1,this.hideMessage(),this.stopSpinner(),this.featureCache}catch(t){this.trackView&&!0!==this.trackView.disposed&&(this.showMessage("Error loading track data"),Qo.presentAlert(t),console.error(t))}finally{this.loading=!1,this.stopSpinner()}var s,a}}repaintDimensions(){const t=na.isWholeGenomeView(this.referenceFrame.chr),e=t?this.$viewport.width():3*this.$viewport.width(),n=this.referenceFrame.bpPerPixel;return{startBP:this.referenceFrame.start-(t?0:e/3*n),endBP:this.referenceFrame.end+(t?0:e/3*n),pixelWidth:e}}repaint(){if(void 0===this.featureCache)return;let{features:t,roiFeatures:e}=this.featureCache;na.isWholeGenomeView(this.referenceFrame.chr);const{startBP:n,endBP:r,pixelWidth:i}=this.repaintDimensions(),o=this.$viewport.height(),s=this.getContentHeight(),a=e?Math.max(s,o):s,c=Math.min(a,3*o);if(0===i||0===c)return void(this.canvas&&de(this.canvas).remove());const l=Math.max(0,-this.$content.position().top-o),h=this.referenceFrame.bpPerPixel,u=Math.round((n-this.referenceFrame.start)/h),f=de('<canvas class="igv-canvas">').get(0);f.style.width=i+"px",f.style.height=c+"px",f.style.left=u+"px",f.style.top=l+"px";const d="FILL"===this.trackView.track.displayMode||!1!==this.trackView.track.supportHiDPI?window.devicePixelRatio:1;f.width=d*i,f.height=d*c;const p=f.getContext("2d");p.scale(d,d),p.translate(0,-l);const g={context:p,pixelXOffset:u,pixelWidth:i,pixelHeight:c,pixelTop:l,bpStart:n,bpEnd:r,bpPerPixel:h,referenceFrame:this.referenceFrame,selection:this.selection,viewport:this,viewportWidth:this.$viewport.width()};this.draw(g,t,e),this.featureCache.canvasTop=l,this.featureCache.height=c,this.canvas&&de(this.canvas).remove(),f._data={chr:this.featureCache.chr,bpPerPixel:h,startBP:n,endBP:r,pixelHeight:c,pixelTop:l},this.canvas=f,this.$content.append(de(f))}draw(t,e,n){if(e&&(t.features=e,this.trackView.track.draw(t)),n)for(let e of n)t.features=e.features,e.track.draw(t)}containsPosition(t,e){return this.referenceFrame.chr===t&&e>=this.referenceFrame.start&&e<=this.referenceFrame.calculateEnd(this.getWidth())}isLoading(){return this.loading}savePNG(){if(!this.canvas)return;const t=this.featureCache,e=t?t.canvasTop:0,n=window.devicePixelRatio,r=this.$viewport.width()*n,i=this.$viewport.height()*n,o=-de(this.canvas).position().left*n,s=(-this.$content.position().top-e)*n,a=this.canvas.getContext("2d").getImageData(o,s,r,i),c=document.createElement("canvas"),l=c.getContext("2d");c.width=a.width,c.height=a.height,l.putImageData(a,0,0);qe((this.$trackLabel.text()?this.$trackLabel.text():"image")+".png",c.toDataURL("image/png"))}saveSVG(){const{width:t,height:e}=this.$viewport.get(0).getBoundingClientRect(),n={width:t,height:e,viewbox:{x:0,y:-this.$content.position().top,width:t,height:e}},r=new js(n),i=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_referenceFrame_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}_guid_${ve()}`;this.drawSVGWithContext(r,t,e,i,0,0,0);const o=r.getSerializedSvg(!0);qe(`${i}.svg`,URL.createObjectURL(new Blob([o],{type:"application/octet-stream"})))}renderSVGContext(t,{deltaX:e,deltaY:n}){if(this.$zoomInNotice&&this.$zoomInNotice.is(":visible"))return;const r=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_referenceFrame_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}_guid_${ve()}`,{top:i}=this.$content.position(),{width:o,height:s}=this.$viewport.get(0).getBoundingClientRect();if(this.drawSVGWithContext(t,o,s,r,e,n+i,-i),this.$trackLabel&&!0===this.browser.trackLabelsVisible){const{x:r,y:i,width:o,height:s}=((t,e)=>{const{x:n,y:r,width:i,height:o}=t.getBoundingClientRect(),{x:s,y:a,width:c,height:l}=e.getBoundingClientRect();return{x:s-n,y:a-r,width:c,height:l}})(this.$viewport.get(0),this.$trackLabel.get(0));this.renderTrackLabelSVG(t,e+r,n+i,o,s)}}renderTrackLabelSVG(t,e,n,r,i){const o=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_track_label_guid_${ve()}`;t.saveWithTranslationAndClipRect(o,e,n,r,i,0),t.fillStyle="white",t.fillRect(0,0,r,i),t.font="12px Arial",t.fillStyle="rgb(68, 68, 68)";const{width:s}=t.measureText(this.$trackLabel.text()),a=.25*(r-s),c=.7*(i-12);t.fillText(this.$trackLabel.text(),a,i-c),t.strokeStyle="rgb(68, 68, 68)",t.strokeRect(0,0,r,i),t.restore()}drawSVGWithContext(t,e,n,r,i,o,s){t.saveWithTranslationAndClipRect(r,i,o,e,n,s);let{start:a,bpPerPixel:c}=this.referenceFrame;const l={context:t,viewport:this,referenceFrame:this.referenceFrame,top:s,pixelTop:s,pixelWidth:e,pixelHeight:n,bpStart:a,bpEnd:a+e*c,bpPerPixel:c,viewportWidth:e,selection:this.selection},h=this.featureCache?this.featureCache.features:[],u=this.featureCache?this.featureCache.roiFeatures:void 0;this.draw(l,h,u),t.restore()}get cachedFeatures(){return this.featureCache?this.featureCache.features:[]}async getFeatures(t,e,n,r,i){if(this.featureCache&&this.featureCache.containsRange(e,n,r,i))return this.featureCache.features;if("function"==typeof t.getFeatures){const o=await t.getFeatures(e,n,r,i,this);return this.checkContentHeight(o),o}}needsRepaint(){if(!this.canvas)return!0;const t=this.canvas._data;return!t||this.referenceFrame.start<t.startBP||this.referenceFrame.end>t.endBP||this.referenceFrame.chr!==t.chr||this.referenceFrame.bpPerPixel!=t.bpPerPixel}needsReload(){if(!this.featureCache)return!0;const t=this.referenceFrame,e=this.referenceFrame.chr,n=t.bpPerPixel,{startBP:r,endBP:i}=this.repaintDimensions();return!this.featureCache.containsRange(e,r,i,n)}createZoomInNotice(t){const e=de("<div>",{class:"igv-zoom-in-notice-container"});t.append(e);const n=de("<div>");return e.append(n),n.text("Zoom in to see features"),e.hide(),e}viewIsReady(){return this.browser&&this.browser.referenceFrameList&&this.referenceFrame}addMouseHandlers(){const t=this.$viewport.get(0);this.addViewportContextMenuHandler(t);const e=t=>{this.enableClick=!0,this.browser.mouseDownOnViewport(t,this),me(t)};t.addEventListener("mousedown",e),t.addEventListener("touchstart",e);const n=t=>{this.browser.dragObject||this.browser.isScrolling?(this.browser.cancelTrackPan(),this.enableClick=!1):(this.browser.cancelTrackPan(),this.browser.endTrackDrag())};t.addEventListener("mouseup",n),t.addEventListener("touchend",n),this.addViewportClickHandler(this.$viewport.get(0)),this.trackView.track.name&&"sequence"!==this.trackView.track.config.type&&this.addTrackLabelClickHandler(this.$trackLabel.get(0))}addViewportContextMenuHandler(t){t.addEventListener("contextmenu",(t=>{if(this.browser.dragObject)return!1;const e=aa(t,this);if(void 0===e)return!1;t.preventDefault();let n=[];if("function"==typeof this.trackView.track.contextMenuItemList){const t=this.trackView.track.contextMenuItemList(e);t&&(n=t)}n.length>0&&n.push({label:de("<HR>")}),n.push({label:"Save Image (PNG)",click:()=>this.saveImage()}),n.push({label:"Save Image (SVG)",click:()=>this.saveSVG()}),this.browser.menuPopup.presentTrackContextMenu(t,n)}))}addViewportClickHandler(t){t.addEventListener("click",(t=>{if(this.enableClick&&this.canvas){if(3===t.which||t.ctrlKey)return;if(de(".igv-popover").hide(),this.browser.dragObject||this.browser.isScrolling)return;t.preventDefault();const e=be(t,this.$viewport.get(0)).x,n=be(t,this.canvas).x,r=this.referenceFrame,i=Math.floor(r.start+r.toBP(n)),o=Date.now();if(o-oa<this.browser.constants.doubleClickDelay){ia&&(window.clearTimeout(ia),ia=void 0);const t=Math.round(r.start+r.toBP(e));let n;if("all"===this.referenceFrame.chr.toLowerCase()){const e=this.browser.genome.getChromosomeCoordinate(t).chr;if(1===this.browser.referenceFrameList.length)n=e;else{const t=this.browser.referenceFrameList.map((({locusSearchString:t})=>t));t[this.browser.referenceFrameList.indexOf(this.referenceFrame)]=e,n=t.join(" ")}this.browser.search(n)}else this.browser.zoomWithScaleFactor(.5,t,this.referenceFrame)}else t.shiftKey&&"function"==typeof this.trackView.track.shiftClick?this.trackView.track.shiftClick(i,t):"function"==typeof this.trackView.track.popupData&&(ia=setTimeout((()=>{const e=function(t,e){const n=aa(t,e);if(void 0===n)return;let r=e.trackView.track;const i=r.popupData(n),o=e.browser.fireEvent("trackclick",[r,i]);let s;void 0===o||!0===o?i&&i.length>0&&(s=i.map((t=>{if(t.name){const e=`<span>${t.name}</span>&nbsp&nbsp&nbsp${t.value}`;return`<div title="${t.value}">${e}</div>`}return"<hr>"===t?t:t.html?t.html:`<div title="${t}">${t}</div>`})).join("")):"string"==typeof o&&(s=o);return s}(t,this);e&&(this.popover&&this.popover.dispose(),this.popover=new os(this.browser.columnContainer),this.popover.presentContentWithEvent(t,e)),window.clearTimeout(ia),ia=void 0}),this.browser.constants.doubleClickDelay));oa=o}}))}addTrackLabelClickHandler(t){t.addEventListener("click",(t=>{t.stopPropagation();const{track:e}=this.trackView;let n;"function"==typeof e.description?n=e.description():e.description&&(n=`<div>${e.description}</div>`),n&&(this.popover&&this.popover.dispose(),this.popover=new os(this.browser.columnContainer,e.name||""),this.popover.presentContentWithEvent(t,n))}))}}function aa(t,e){const n=e.referenceFrame,r=be(t,e.contentDiv),i=be(t,e.canvas),o=n.start+n.toBP(r.x);return{event:t,viewport:e,referenceFrame:n,genomicLocation:o,x:r.x,y:r.y,canvasX:i.x,canvasY:i.y}}class ca{constructor(t,e,n,r,i,o,s){this.chr=t,this.startBP=e,this.endBP=n,this.bpPerPixel=r,this.features=i,this.roiFeatures=o,this.multiresolution=s}containsRange(t,e,n,r){const i=this.multiresolution?this.bpPerPixel/r:1;return e>=this.startBP&&n<=this.endBP&&t===this.chr&&i>.5&&i<2}overlapsRange(t,e,n){return this.chr===t&&n>=this.startBP&&e<=this.endBP}}class la{constructor(t){this.rulerSweeper=pe({class:"igv-ruler-sweeper"}),t.contentDiv.appendChild(this.rulerSweeper),this.rulerViewport=t,this.isMouseHandlers=void 0,this.addBrowserObserver()}addBrowserObserver(){this.boundObserverHandler=function(){this.rulerViewport.referenceFrame&&(na.isWholeGenomeView(this.rulerViewport.referenceFrame.chr)?this.removeMouseHandlers():this.addMouseHandlers())}.bind(this),this.rulerViewport.browser.on("locuschange",this.boundObserverHandler)}removeBrowserObserver(){this.rulerViewport.browser.off("locuschange",this.boundObserverHandler)}addMouseHandlers(){if(!0===this.isMouseHandlers)return;let t,e,n,r,i,o;this.boundContentMouseDownHandler=function(o){t=!0,e=!0;const{x:s}=be(o,this.rulerViewport.contentDiv);r=n=s,i=1,this.rulerSweeper.style.display="block",this.rulerSweeper.style.left=`${r}px`,this.rulerSweeper.style.width=`${i}px`}.bind(this),this.rulerViewport.contentDiv.addEventListener("mousedown",this.boundContentMouseDownHandler),this.boundDocumentMouseMoveHandler=function(s){let a;if(t&&e){const{x:t}=be(s,this.rulerViewport.contentDiv);a=Math.max(Math.min(t,this.rulerViewport.contentDiv.clientWidth),0),o=a-n,i=Math.abs(o),this.rulerSweeper.style.width=`${i}px`,o<0&&(r=n+o,this.rulerSweeper.style.left=`${r}px`)}}.bind(this),document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseUpHandler=function(n){let o;if(!0===t&&!0===e&&(t=e=void 0,this.rulerSweeper.style.display="none",i>1)){o={start:ha(this.rulerViewport.referenceFrame,r),end:ha(this.rulerViewport.referenceFrame,r+i)},vs(this.rulerViewport.browser.genome.getChromosome(this.rulerViewport.referenceFrame.chr).bpLength,o,this.rulerViewport.browser.minimumBases());const t=Math.round(o.start),e=Math.round(o.end);this.rulerViewport.referenceFrame.bpPerPixel=(e-t)/this.rulerViewport.contentDiv.clientWidth,this.rulerViewport.referenceFrame.start=t,this.rulerViewport.referenceFrame.end=e,this.rulerViewport.browser.updateViews()}}.bind(this),document.addEventListener("mouseup",this.boundDocumentMouseUpHandler),this.isMouseHandlers=!0}removeMouseHandlers(){this.rulerViewport.contentDiv.removeEventListener("mousedown",this.boundContentMouseDownHandler),document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.removeEventListener("mouseup",this.boundDocumentMouseUpHandler),this.isMouseHandlers=!1}dispose(){this.removeBrowserObserver(),this.removeMouseHandlers(),this.rulerSweeper.remove()}}function ha(t,e){return t.start+e*t.bpPerPixel}class ua{constructor(t){this.paired=!0,this.firstAlignment=t,this.chr=t.chr,this.readName=t.readName,t.start<t.mate.position?(this.start=t.start,this.scStart=t.scStart,this.connectingStart=t.start+t.lengthOnRef,this.connectingEnd=t.mate.position):(this.start=t.mate.position,this.scStart=this.start,this.connectingStart=t.mate.position,this.connectingEnd=t.start),this.end=Math.max(t.mate.position,t.start+t.lengthOnRef),this.lengthOnRef=this.end-this.start;let e=Math.max(this.end,t.scStart+t.scLengthOnRef);this.scLengthOnRef=e-this.scStart}setSecondAlignment(t){this.secondAlignment=t;const e=this.firstAlignment;t.start>e.start?this.connectingEnd=t.start:this.connectingStart=t.start+t.lengthOnRef,this.start=Math.min(e.start,t.start),this.end=Math.max(e.start+e.lengthOnRef,t.start+t.lengthOnRef),this.lengthOnRef=this.end-this.start,this.scStart=Math.min(e.scStart,t.scStart);const n=Math.max(e.scStart+e.scLengthOnRef,t.scStart+t.scLengthOnRef);this.scLengthOnRef=n-this.scStart}containsLocation(t,e){const n=e?this.scStart:this.start,r=e?this.scLengthOnRef:this.lengthOnRef;return t>=n&&t<=n+r}alignmentContaining(t,e){return this.firstAlignment.containsLocation(t,e)?this.firstAlignment:this.secondAlignment&&this.secondAlignment.containsLocation(t,e)?this.secondAlignment:void 0}popupData(t){let e=this.firstAlignment.popupData(t);return this.secondAlignment&&(e.push("-------------------------------"),e=e.concat(this.secondAlignment.popupData(t))),e}isPaired(){return!0}isMateMapped(){return!0}isProperPair(){return this.firstAlignment.isProperPair()}get fragmentLength(){return Math.abs(this.firstAlignment.fragmentLength)}firstOfPairStrand(){return this.firstAlignment.isFirstOfPair()?this.firstAlignment.strand:this.secondAlignment&&this.secondAlignment.isFirstOfPair()?this.secondAlignment.strand:this.firstAlignment.mate.strand}hasTag(t){return this.firstAlignment.hasTag(t)||this.secondAlignment&&this.secondAlignment.hasTag(t)}}const fa=ke,da=function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)};class pa{constructor(){this.alignments=[],this.score=void 0}findAlignment(t){const e=(t,e)=>e>=t.start&&e<t.start+t.lengthOnRef;let n;for(let r=0;r<this.alignments.length;r++){const i=this.alignments[r];if(t>=i.start&&t<i.start+i.lengthOnRef){i.paired?i.firstAlignment&&e(i.firstAlignment,t)?n=i.firstAlignment:i.secondAlignment&&e(i.secondAlignment,t)&&(n=i.secondAlignment):n=i;break}}return n}updateScore(t,e){this.score=this.calculateScore(t,e)}calculateScore({position:t,option:e,direction:n,tag:r},i){e||(e="BASE");const o=this.findAlignment(t);if(void 0===o)return Number.MAX_VALUE*(n?1:-1);let s;switch(e){case"NUCLEOTIDE":case"BASE":return function(t,e,n){let r;const i=Math.floor(n)-e.start;i<e.sequence.length&&(r=e.sequence.charAt(i));if(!r)return 0;const o=t.readBaseAt(n),s=t.readBaseQualityAt(n),a=e.coverageMap,c=Math.floor(n-a.bpStart),l=a.coverage[c];let h=0;if(t.insertions)for(let e of t.insertions)e.start===n&&(h=-l.ins);if(o)if(r=r.toUpperCase(),"N"===o&&0===h)h=2;else if(r!==o&&"="!==o||0!==h){if("X"===o||r!==o){h-=l["pos"+o]+l["neg"+o]+s/1e3}}else h=4-s/1e3;else{const t=l.del;t>0?h-=t:0===h&&(h=1)}return h}(o,i,t);case"STRAND":return o.strand?1:-1;case"START":return o.start;case"TAG":{const t=o.tags()[r];return void 0!==t?fa(t)?da(t):t:Number.MAX_VALUE}case"READ_NAME":return da(o.readName);case"INSERT_SIZE":return-Math.abs(o.fragmentLength);case"GAP_SIZE":return-o.gapSizeAt(t);case"MATE_CHR":return s=o.mate,s?s.chr===o.chr?Number.MAX_VALUE-1:da(s.chr):Number.MAX_VALUE;case"MQ":return void 0===o.mq?Number.MAX_VALUE:-o.mq;default:return Number.MAX_VALUE}}}function ga(t){return t.isPaired()&&t.mate&&t.isMateMapped()&&t.chr===t.mate.chr&&(t.isFirstOfPair()||t.isSecondOfPair())&&!(t.isSecondary()||t.isSupplementary())}function ma(t){const e=[];for(let n of t)for(let t of n.alignments)t instanceof ua?(t.firstAlignment&&e.push(t.firstAlignment),t.secondAlignment&&e.push(t.secondAlignment)):e.push(t);return e}function va(t,e,n,r){if(t){if(0===t.length)return[];{t.sort((function(t,e){return r?t.scStart-e.scStart:t.start-e.start}));const i=t[0];let o=Math.max(e,r?i.scStart:i.start),s=o;const a=[];for(let e of t){const t=r?e.scStart:e.start,n=Math.max(0,t-o);void 0===a[n]&&(a[n]=[]),a[n].push(e)}let c=0,l=0;const h=[],u=2;try{for(;c<t.length;){const t=new pa;for(;s<=n;){let e,i;for(;!e&&s<=n;)i=s-o,void 0===a[i]?++s:e=a[i];if(!e)break;const l=e.pop();0===e.length&&(a[i]=void 0),t.alignments.push(l),s=r?l.scStart+l.scLengthOnRef+u:l.start+l.lengthOnRef+u,++c}if(t.alignments.length>0&&h.push(t),s=o,c===l)break;l=c}}catch(t){throw console.error(t),t}return h}}}class ba{constructor(t,e,n,{samplingWindowSize:r,samplingDepth:i,pairsSupported:o,alleleFreqThreshold:s}){this.chr=t,this.start=Math.floor(e),this.end=Math.ceil(n),this.length=n-e,this.alleleFreqThreshold=void 0===s?.2:s,this.coverageMap=new ya(t,e,n,this.alleleFreqThreshold),this.alignments=[],this.downsampledIntervals=[],this.samplingWindowSize=void 0===r?100:r,this.samplingDepth=void 0===i?1e3:i,this.pairsSupported=void 0===o||o,this.paired=!1,this.pairsCache={},this.downsampledReads=new Set,this.currentBucket=new wa(this.start,this.start+this.samplingWindowSize,this),this.filter=function(t){return t.isMapped()&&!t.isFailsVendorQualityCheck()}}push(t){!1!==this.filter(t)&&(this.coverageMap.incCounts(t),this.pairsSupported&&this.downsampledReads.has(t.readName)||(t.start>=this.currentBucket.end&&(this.finishBucket(),this.currentBucket=new wa(t.start,t.start+this.samplingWindowSize,this)),this.currentBucket.addAlignment(t)))}forEach(t){this.alignments.forEach(t)}finish(){void 0!==this.currentBucket&&this.finishBucket(),this.alignments.sort((function(t,e){return t.start-e.start})),this.pairsCache=void 0,this.downsampledReads=void 0}contains(t,e,n){return this.chr===t&&this.start<=e&&this.end>=n}hasDownsampledIntervals(){return this.downsampledIntervals&&this.downsampledIntervals.length>0}finishBucket(){this.alignments=this.alignments.concat(this.currentBucket.alignments),this.currentBucket.downsampledCount>0&&this.downsampledIntervals.push(new ka(this.currentBucket.start,this.currentBucket.end,this.currentBucket.downsampledCount)),this.paired=this.paired||this.currentBucket.paired}setViewAsPairs(t){let e;e=t?function(t){const e={},n=[];for(let r of t)for(let t of r.alignments)if(ga(t)){let r=e[t.readName];r?(r.setSecondAlignment(t),e[t.readName]=void 0):(r=new ua(t),e[t.readName]=r,n.push(r))}else n.push(t);return n}(this.packedAlignmentRows):ma(this.packedAlignmentRows),this.packedAlignmentRows=va(e,this.start,this.end)}setShowSoftClips(t){const e=this.allAlignments();this.packedAlignmentRows=va(e,this.start,this.end,t)}repack(t,e){const n=this.allAlignments();this.packedAlignmentRows=va(n,this.start,this.end,e)}allAlignments(){const t=[];for(let e of this.packedAlignmentRows)for(let n of e.alignments)t.push(n);return t}getMax(t,e){return this.coverageMap.getMax(t,e)}}class wa{constructor(t,e,n){this.start=t,this.end=e,this.alignments=[],this.downsampledCount=0,this.samplingDepth=n.samplingDepth,this.pairsSupported=n.pairsSupported,this.downsampledReads=n.downsampledReads,this.pairsCache=n.pairsCache}addAlignment(t){var e,n,r;if(this.pairsSupported&&ga(t)&&(r=this.pairsCache[t.readName]))return r.setSecondAlignment(t),void(this.pairsCache[t.readName]=void 0);this.alignments.length<this.samplingDepth?this.pairsSupported&&ga(t)?(r=new ua(t),this.paired=!0,this.pairsCache[t.readName]=r,this.alignments.push(r)):this.alignments.push(t):((e=Math.floor(Math.random()*(this.samplingDepth+this.downsampledCount-1)))<this.samplingDepth?(n=this.alignments[e],this.pairsSupported&&ga(t)?(void 0!==this.pairsCache[n.readName]&&(this.pairsCache[n.readName]=void 0),r=new ua(t),this.paired=!0,this.pairsCache[t.readName]=r,this.alignments[e]=r):this.alignments[e]=t,this.downsampledReads.add(n.readName)):this.downsampledReads.add(t.readName),this.downsampledCount++)}}class ya{constructor(t,e,n,r){this.chr=t,this.bpStart=e,this.length=n-e,this.coverage=new Array(this.length),this.maximum=0,this.threshold=r,this.qualityWeight=!0}getMax(t,e){let n=0;const r=this.coverage.length;for(let i=0;i<r;i++){const r=this.bpStart+i;if(r>e)break;const o=this.coverage[i];r>=t&&o&&(n=Math.max(n,o.total))}return n}incCounts(t){var e=this;if(void 0===t.blocks?n(t):t.blocks.forEach((function(t){n(t)})),t.gaps)for(let n of t.gaps)if("D"===n.type){const t=n.start-e.bpStart;for(let r=t;r<t+n.len;r++)r<0||(this.coverage[r]||(this.coverage[r]=new xa(e.threshold)),this.coverage[r].del++)}if(t.insertions)for(let n of t.insertions){const t=n.start-this.bpStart;t<0||(this.coverage[t]||(this.coverage[t]=new xa(e.threshold)),this.coverage[t].ins++)}function n(n){if("S"===n.type)return;const r=t.seq,i=t.qual,o=n.seqOffset;for(let s=n.start-e.bpStart,a=0;a<n.len;s++,a++){e.coverage[s]||(e.coverage[s]=new xa(e.threshold));const n=null==r?"N":r.charAt(o+a),c=t.strand?"pos"+n:"neg"+n,l=i&&o+a<i.length?i[o+a]:30;e.coverage[s][c]+=1,e.coverage[s]["qual"+n]+=l,e.coverage[s].total+=1,e.coverage[s].qual+=l,e.maximum=Math.max(e.coverage[s].total,e.maximum)}}}}class xa{constructor(t){this.qualityWeight=!0,this.posA=0,this.negA=0,this.posT=0,this.negT=0,this.posC=0,this.negC=0,this.posG=0,this.negG=0,this.posN=0,this.negN=0,this.pos=0,this.neg=0,this.qualA=0,this.qualT=0,this.qualC=0,this.qualG=0,this.qualN=0,this.qual=0,this.total=0,this.del=0,this.ins=0,this.threshold=t}isMismatch(t){const e=this.threshold*(this.qualityWeight&&this.qual?this.qual:this.total);let n=0;for(let e of["A","T","C","G"])e!==t&&(n+=this.qualityWeight&&this.qual?this["qual"+e]:this["pos"+e]+this["neg"+e]);return n>=e}}class ka{constructor(t,e,n){this.start=t,this.end=e,this.counts=n}popupData(t){return[{name:"start",value:this.start+1},{name:"end",value:this.end},{name:"# downsampled:",value:this.counts}]}}class _a{constructor(t){const e=t.split(",");this.chr=e[0],this.start=parseInt(e[1]),this.strand=e[2].charAt(0),this.mapQ=parseInt(e[4]),this.numMismatches=parseInt(e[5]),this.lenOnRef=za.computeLengthOnReference(e[3])}printString(){return this.chr+":"+_e(this.start)+"-"+_e(this.start+this.lenOnRef)+" ("+this.strand+") = "+_e(this.lenOnRef)+"bp @MAPQ: "+this.mapQ+" NM: "+this.numMismatches}}function Sa(t){return t.split(";").filter((t=>t.length>0)).map((t=>new _a(t)))}const Ca={c:1,C:1,s:2,S:2,i:4,I:4,f:4};class Ea{constructor(){this.hidden=!1}isMapped(){return 0==(4&this.flags)}isPaired(){return 0!=(1&this.flags)}isProperPair(){return 0!=(2&this.flags)}isFirstOfPair(){return 0!=(64&this.flags)}isSecondOfPair(){return 0!=(128&this.flags)}isSecondary(){return 0!=(256&this.flags)}isSupplementary(){return 0!=(2048&this.flags)}isFailsVendorQualityCheck(){return 0!=(512&this.flags)}isDuplicate(){return 0!=(1024&this.flags)}isMateMapped(){return 0==(8&this.flags)}isNegativeStrand(){return 0!=(16&this.flags)}isMateNegativeStrand(){return 0!=(32&this.flags)}hasTag(t){return(this.tagDict||Ta(this.tagBA)).hasOwnProperty(t)}tags(){return this.tagDict||(this.tagBA?(this.tagDict=Ta(this.tagBA),this.tagBA=void 0):this.tagDict={}),this.tagDict}containsLocation(t,e){const n=e?this.scStart:this.start,r=e?this.scLengthOnRef:this.lengthOnRef;return t>=n&&t<=n+r}popupData(t){const e=[];if(t=Math.floor(t),this.insertions){const r=this.seq;for(let i of this.insertions){var n=i.start;if(t===n||t===n-1)return e.push({name:"Insertion",value:r.substr(i.seqOffset,i.len)}),e.push({name:"Location",value:n}),e}}e.push({name:"Read Name",value:this.readName}),e.push("<hr/>"),e.push({name:"Alignment Start",value:_e(1+this.start),borderTop:!0}),e.push({name:"Read Strand",value:!0===this.strand?"(+)":"(-)",borderTop:!0});let r=this.cigar;if(r&&r.length>50){const t=25;r=`${r.substring(0,t-2)} ... ${r.substring(r.length-t+2)}`}e.push({name:"Cigar",value:r}),e.push({name:"Mapping Quality",value:this.mq}),e.push({name:"Secondary",value:s(this.isSecondary())}),e.push({name:"Supplementary",value:s(this.isSupplementary())}),e.push({name:"Duplicate",value:s(this.isDuplicate())}),e.push({name:"Failed QC",value:s(this.isFailsVendorQualityCheck())}),this.isPaired()&&(e.push("<hr/>"),e.push({name:"First in Pair",value:!this.isSecondOfPair(),borderTop:!0}),e.push({name:"Mate is Mapped",value:s(this.isMateMapped())}),this.pairOrientation&&e.push({name:"Pair Orientation",value:this.pairOrientation}),this.isMateMapped()&&(e.push({name:"Mate Chromosome",value:this.mate.chr}),e.push({name:"Mate Start",value:this.mate.position+1}),e.push({name:"Mate Strand",value:!0===this.mate.strand?"(+)":"(-)"}),e.push({name:"Insert Size",value:this.fragmentLength})));const i=this.tags();if(i.hasOwnProperty("SA")){e.push("<hr/>"),e.push({name:"Supplementary Alignments",value:""});const t=Sa(i.SA);if(t){e.push("<ul>");for(let n of t)e.push(`<li>${n.printString()}</li>`);e.push("</ul>")}}const o=new Set(["SA","MD"]);e.push("<hr/>");for(let t in i)o.has(t)||e.push({name:t,value:i[t]});return e.push({name:"Hidden Tags",value:"SA, MD"}),e.push("<hr/>"),e.push({name:"Genomic Location: ",value:_e(1+t)}),e.push({name:"Read Base:",value:this.readBaseAt(t)}),e.push({name:"Base Quality:",value:this.readBaseQualityAt(t)}),e;function s(t){return t?"Yes":"No"}}readBaseAt(t){const e=Aa(this.blocks,t);if(e){if("*"===this.seq)return"*";{const n=e.seqIndexAt(t);return this.seq[n]}}}readBaseQualityAt(t){const e=Aa(this.blocks,t);if(e){if("*"===this.qual)return 30;{const n=e.seqIndexAt(t);return n>=0&&this.qual&&n<this.qual.length?this.qual[n]:30}}}gapSizeAt(t){if(this.gaps)for(let e of this.gaps)if(t>=e.start&&t<e.start+e.len)return e.len;return 0}}function Aa(t,e){for(let n=0;n<t.length;n++){const r=t[n];if(e>=r.start&&e<r.start+r.len)return r}}function Ta(t){let e=0;const n=t.length,r={};for(;e<n;){const n=String.fromCharCode(t[e])+String.fromCharCode(t[e+1]);e+=2;const o=String.fromCharCode(t[e++]);let s;if("A"===o)s=String.fromCharCode(t[e]),e++;else if("i"===o||"I"===o)s=La(t,e),e+=4;else if("c"===o)s=Ia(t,e),e++;else if("C"===o)s=Na(t,e),e++;else if("s"===o||"S"===o)s=Ma(t,e),e+=2;else if("f"===o)s=Ra(t,e),e+=4;else if("Z"===o)for(s="";;){var i=t[e++];if(0===i)break;s+=String.fromCharCode(i)}else{if("B"!==o){s="Error unknown type: "+o,r[n]=s;break}{const i=String.fromCharCode(t[e++]);let o=Ca[i];if(void 0===o){r[n]=`Error: unknown element type '${i}'`;break}e+=4+La(t,e)*o,s="[not shown]"}}r[n]=s}return r}function La(t,e){return t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function Ma(t,e){return t[e+1]<<8|t[e]}function Ra(t,e){return new DataView(t.buffer).getFloat32(e)}function Ia(t,e){return new DataView(t.buffer).getInt8(e)}function Na(t,e){return new DataView(t.buffer).getUint8(e)}class Pa{constructor(t){t&&Object.assign(this,t)}seqIndexAt(t){return Math.floor(t)-this.start+this.seqOffset}}class Oa{constructor(t){t||(t={}),this.vendorFailed=void 0===t.vendorFailed||t.vendorFailed,this.duplicates=void 0===t.duplicates||t.duplicates,this.secondary=t.secondary||!1,this.supplementary=t.supplementary||!1,this.mqThreshold=void 0===t.mqThreshold?0:t.mqThreshold,t.readgroups&&(this.readgroups=new Set(t.readgroups))}pass(t){if(this.vendorFailed&&t.isFailsVendorQualityCheck())return!1;if(this.duplicates&&t.isDuplicate())return!1;if(this.secondary&&t.isSecondary())return!1;if(this.supplementary&&t.isSupplementary())return!1;if(t.mq<this.mqThreshold)return!1;if(this.readgroups){var e=t.tags().RG;return this.readgroups.has(e)}return!0}}const Fa=["=","A","C","x","G","x","x","x","T","x","x","x","x","x","x","N"],Da=["M","I","D","N","S","H","P","=","X","?","?","?","?","?","?","?"],Ba=Va(new Uint8Array([66,65,77,1]),0),za={readHeader:function(t,e,n){return go.loadArrayBuffer(t,e).then((function(t){var e;return e=Wi(t),za.decodeBamHeader(e,n)}))},decodeBamHeader:function(t,e){var n,r,i,o,s;if((n=Va(t,0))!==Ba)throw new Error("BAM header errror: bad magic number. This could be caused by either a corrupt or missing file.");r=Va(t,4);for(var a=0;a<r;++a)String.fromCharCode(t[a+8]);var c=Va(t,r+8),l=r+12;for(i={},o=[],s={},a=0;a<c;++a){for(var h=Va(t,l),u="",f=0;f<h-1;++f)u+=String.fromCharCode(t[l+4+f]);Va(t,l+h+4),i[u]=a,o[a]=u,e&&(s[e.getChromosomeName(u)]=u),l=l+8+h}return{magicNumber:n,size:l,chrNames:o,chrToIndex:i,chrAliasTable:s}},bam_tag2cigar:function(t,e,n,r,i,o){function s(t){return"C"===t||"c"===t||"A"===t?1:"S"===t||"s"===t?2:"I"===t||"i"===t||"f"===t?4:0}if(1!==o.length||i.start<0)return!1;for(var a=n+(r+1>>1)+r;a+4<e;){if("CG"===String.fromCharCode(t[a])+String.fromCharCode(t[a+1]))break;var c=String.fromCharCode(t[a+2]);if("B"===c)a+=8+s(c=String.fromCharCode(t[a+3]))*Va(t,a+4);else if("Z"===c||"H"===c)for(a+=3;0!==t[a++];);else a+=3+s(c)}if(a>=e)return!1;if("B"!==String.fromCharCode(t[a+2])||"I"!==String.fromCharCode(t[a+3]))return!1;var l=Va(t,a+4),h=a+8;if(h+4*l>e)return!1;var u="",f=0;o.length=0,a=h;for(var d=0;d<l;++d,a+=4){var p=Va(t,a),g=p>>4,m=Da[15&p];"M"!==m&&"EQ"!==m&&"X"!==m&&"D"!==m&&"N"!==m&&"="!==m||(f+=g),u=u+g+m,o.push({len:g,ltr:m})}return i.cigar=u,i.lengthOnRef=f,!0},decodeBamRecords:function(t,e,n,r,i,o,s,a){for(;e<t.length;){const f=e+Va(t,e)+4,d=new Ea,p=Va(t,e+4),g=Va(t,e+8);if(f>t.length)return;if(p<0){e=f;continue}if(void 0!==i&&(p>i||g>s))return!0;if(void 0!==i&&p<i){e=f;continue}const m=Va(t,e+12),v=(65280&m)>>8,b=255&m,w=Va(t,e+16),y=(4294901760&w)>>16,x=65535&w,k=Va(t,e+20),_=Va(t,e+24),S=Va(t,e+28),C=Va(t,e+32);let E=[];for(let n=0;n<b-1;++n)E.push(String.fromCharCode(t[e+36+n]));E=E.join("");let A=0,T="",L=e+36+b;const M=[];let R;for(let e=0;e<x;++e){var c=Va(t,L),l=c>>4,h=Da[15&c];"M"!==h&&"EQ"!==h&&"X"!==h&&"D"!==h&&"N"!==h&&"="!==h||(A+=l),T=T+l+h,L+=4,R={len:l,ltr:h},M.push(R)}if(d.chr=r[p],d.start=g,d.flags=y,d.strand=!(16&y),d.readName=E,d.cigar=T,d.lengthOnRef=A,d.fragmentLength=C,d.mq=v,za.bam_tag2cigar(t,f,L,k,d,M),d.end=d.start+d.lengthOnRef,d.end<o){e=f;continue}let I=[];const N=k+1>>1;for(let e=0;e<N;++e){var u=t[L+e];I.push(Fa[(240&u)>>4]),I.push(Fa[15&u])}I=I.slice(0,k).join(""),L+=N;const P=[];for(let e=0;e<k;++e)P.push(t[L+e]);L+=k,_>=0&&(d.mate={chr:r[_],position:S,strand:!(32&y)}),d.seq=I,d.qual=P,d.tagBA=new Uint8Array(t.buffer.slice(L,f)),this.setPairOrientation(d),(void 0===a||a.pass(d))&&(Ha(d,M),n.push(d)),e=f}},decodeSamRecords:function(t,e,n,r,i,o){var s,a,c,l,h,u,f,d,p,g;for(l=(s=Se(t)).length,!1,a=0;a<l;a++)if(h=s[a].split("\t"),(p=new Ea).chr=h[2],p.start=Number.parseInt(h[3])-1,p.flags=Number.parseInt(h[1]),p.readName=h[0],p.strand=!(16&p.flags),p.mq=Number.parseInt(h[4]),p.cigar=h[5],p.fragmentLength=Number.parseInt(h[8]),p.seq=h[9],"*"!==p.chr&&p.isMapped()&&p.chr===n){if(p.start>i)break;if(d=0,(g=ja(p.cigar)).forEach((function(t){var e=t.len,n=t.ltr;"M"!==n&&"EQ"!==n&&"X"!==n&&"D"!==n&&"N"!==n&&"="!==n||(d+=e)})),p.lengthOnRef=d,!(p.start+d<r)){for(u=h[10],p.qual=[],c=0;c<u.length;c++)p.qual[c]=u.charCodeAt(c)-33;p.tagDict=h.length<11?{}:Ua(h.slice(11)),p.isMateMapped()&&(f=h[6],p.mate={chr:"="===f?p.chr:f,position:Number.parseInt(h[7]),strand:!(32&p.flags)}),this.setPairOrientation(p),(void 0===o||o.pass(p))&&(Ha(p,g),e.push(p))}}},setReaderDefaults:function(t,e){t.filter=new Oa(e.filter),e.readgroup&&(t.filter.readgroups=new Set([e.readgroup])),t.alleleFreqThreshold=void 0===e.alleleFreqThreshold?.2:e.alleleFreqThreshold,t.samplingWindowSize=void 0===e.samplingWindowSize?100:e.samplingWindowSize,t.samplingDepth=void 0===e.samplingDepth?500:e.samplingDepth,t.samplingDepth>1e4&&(console.log("Warning: attempt to set sampling depth > maximum value of 10000"),t.samplingDepth=1e4),e.viewAsPairs?t.pairsSupported=!0:t.pairsSupported=void 0===e.pairsSupported||e.pairsSupported},setPairOrientation:function(t){if(t.isMapped()&&t.mate&&t.isMateMapped()&&t.mate.chr===t.chr){var e=t.strand?"F":"R",n=t.mate,r=n.strand?"F":"R",i=" ",o=" ";t.isFirstOfPair()?(i="1",o="2"):t.isSecondOfPair()&&(i="2",o="1");var s=[],a=t.fragmentLength,c=t.end-t.start;if(0===a)a=(t.start<n.position?n.position+c:n.position-c)-t.start;a>0?(s[0]=e,s[1]=i,s[2]=r,s[3]=o):(s[2]=e,s[3]=i,s[0]=r,s[1]=o),t.pairOrientation=s.join("")}},computeLengthOnReference:function(t){let e=0,n="";for(let r=0;r<t.length;r++){const i=t.charCodeAt(r);if(i>47&&i<58)n+=t.charAt(r);else{switch(i){case 78:case 68:case 77:case 61:case 88:e+=parseInt(n.toString())}n=""}}return e}};function Ha(t,e){const n=[];let r,i,o=0,s=t.start;t.scStart=t.start,t.scLengthOnRef=t.lengthOnRef;for(let a of e){let e;switch(a.ltr){case"H":case"P":break;case"S":e=s,t.scLengthOnRef+=a.len,0===n.length&&(t.scStart-=a.len,e-=a.len),n.push(new Pa({start:e,seqOffset:o,len:a.len,type:"S"})),o+=a.len;break;case"N":case"D":void 0===i&&(i=[]),i.push({start:s,len:a.len,type:a.ltr}),s+=a.len;break;case"I":void 0===r&&(r=[]),r.push(new Pa({start:s,len:a.len,seqOffset:o,type:"I"})),o+=a.len;break;case"M":case"EQ":case"=":case"X":n.push(new Pa({start:s,seqOffset:o,len:a.len,type:"M"})),o+=a.len,s+=a.len;break;default:console.log("Error processing cigar element: "+a.len+a.ltr)}}t.blocks=n,t.insertions=r,t.gaps=i}function Va(t,e){return t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function ja(t){var e,n,r,i,o,s,a,c,l;for(e=[],n=[],o=null,i=t.length,r=0;r<i;r++)s=t.charAt(r),l=void 0,(l=s.charCodeAt(0))>=48&&l<=57?n.push(s):(a=s,c=Number.parseInt(n.join("")),n=[],null!==o&&o.ltr===a?o.len+=c:(o={len:c,ltr:a},e.push(o)));return e}function Ua(t){var e={};return t.forEach((function(t){var n=t.split(":");e[n[0]]=n[2]})),e}class qa{constructor(t,e){this.config=t,this.genome=e,this.bamPath=t.url,this.isDataUri=ys(t.url),za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(this.alignmentCache){const r=this.header,i=r.chrAliasTable.hasOwnProperty(t)?r.chrAliasTable[t]:t,o=this.alignmentCache.queryFeatures(i,e,n),s=new ba(t,e,n,this.config);for(let t of o)s.push(t);return s.finish(),s}if(this.isDataUri){const r=Wi(function(t){const e=t.split(","),n=e[0].split(":")[1];let r=e[1];r=n.indexOf("base64")>=0?atob(r):decodeURI(r);const i=new Uint8Array(r.length);for(var o=0;o<r.length;o++)i[o]=r.charCodeAt(o);return i}(this.bamPath).buffer);return this.parseAlignments(r),this.fetchAlignments(t,e,n)}{const r=Wi(await go.loadArrayBuffer(this.bamPath,gs(this.config)));return this.parseAlignments(r),this.fetchAlignments(t,e,n)}}parseAlignments(t){const e=[];this.header=za.decodeBamHeader(t),za.decodeBamRecords(t,this.header.size,e,this.header.chrNames),this.alignmentCache=new Mo(e,this.genome)}fetchAlignments(t,e,n){const r=this.header.chrAliasTable.hasOwnProperty(t)?this.header.chrAliasTable[t]:t,i=this.alignmentCache.queryFeatures(r,e,n),o=new ba(t,e,n,this.config);for(let t of i)o.push(t);return o.finish(),o}}class Wa{constructor(t,e){this.littleEndian=void 0===e||e,this.position=0,this.view=t,this.length=t.byteLength}available(){return this.length-this.position}remLength(){return this.length-this.position}hasNext(){return this.position<this.length-1}getByte(){var t=this.view.getUint8(this.position,this.littleEndian);return this.position++,t}getShort(){var t=this.view.getInt16(this.position,this.littleEndian);return this.position+=2,t}getUShort(){var t=this.view.getUint16(this.position,this.littleEndian);return this.position+=2,t}getInt(){var t=this.view.getInt32(this.position,this.littleEndian);return this.position+=4,t}getUInt(){var t=this.view.getUint32(this.position,this.littleEndian);return this.position+=4,t}getLong(){var t=[];t[0]=this.view.getUint8(this.position),t[1]=this.view.getUint8(this.position+1),t[2]=this.view.getUint8(this.position+2),t[3]=this.view.getUint8(this.position+3),t[4]=this.view.getUint8(this.position+4),t[5]=this.view.getUint8(this.position+5),t[6]=this.view.getUint8(this.position+6),t[7]=this.view.getUint8(this.position+7);var e=0;if(this.littleEndian)for(let n=t.length-1;n>=0;n--)e=256*e+t[n];else for(let n=0;n<t.length;n++)e=256*e+t[n];return this.position+=8,e}getString(t){for(var e,n="";0!==(e=this.view.getUint8(this.position++))&&(n+=String.fromCharCode(e),!t||n.length!==t););return n}getFixedLengthString(t){var e,n,r="";for(e=0;e<t;e++)(n=this.view.getUint8(this.position++))>0&&(r+=String.fromCharCode(n));return r}getFixedLengthTrimmedString(t){var e,n,r="";for(e=0;e<t;e++)(n=this.view.getUint8(this.position++))>32&&(r+=String.fromCharCode(n));return r}getFloat(){var t=this.view.getFloat32(this.position,this.littleEndian);return this.position+=4,t}getDouble(){var t=this.view.getFloat64(this.position,this.littleEndian);return this.position+=8,t}skip(t){return this.position+=t,this.position}getVPointer(){var t=this.position,e=this.view.getUint8(t+1)<<8|this.view.getUint8(t),n=4294967296*(255&this.view.getUint8(t+6))+16777216*(255&this.view.getUint8(t+5))+65536*(255&this.view.getUint8(t+4))+256*(255&this.view.getUint8(t+3))+(255&this.view.getUint8(t+2));return this.position+=8,new $a(n,e)}}class $a{constructor(t,e){this.block=t,this.offset=e}isLessThan(t){return this.block<t.block||this.block===t.block&&this.offset<t.offset}isGreaterThan(t){return this.block>t.block||this.block===t.block&&this.offset>t.offset}print(){return this.block+":"+this.offset}}class Ga{constructor(t){this.tabix=!0}parse(t,e){const n=new Wa(new DataView(t)),r=n.getInt();if(21582659!==r)throw 38359875===r?Error("CSI version 2 is not supported. Please enter an issue at https://github.com/igvteam/igv.js"):Error("Not a CSI index");this.indices=[],this.blockMin=Number.MAX_SAFE_INTEGER,this.lastBlockPosition=[],this.sequenceIndexMap={},this.minShift=n.getInt(),this.depth=n.getInt();const i=[];let o=0;if(n.getInt()>=28){n.getInt(),n.getInt(),n.getInt(),n.getInt(),n.getInt(),n.getInt();const t=n.getInt(),r=n.position+t;let o=0;for(;n.position<r;){let t=n.getString();e&&(t=e.getChromosomeName(t)),this.sequenceIndexMap[t]=o,i[o]=t,o++}}const s=this.bin_limit()+1,a=n.getInt();for(let t=0;t<a;t++){const e=[],r=[],i=n.getInt();for(let t=0;t<i;t++){const t=n.getInt();if(r[t]=n.getVPointer(),t>s)n.getInt(),n.getVPointer(),n.getVPointer(),n.getLong(),n.getLong();else{e[t]=[];const r=n.getInt();for(let i=0;i<r;i++){const r=n.getVPointer(),i=n.getVPointer();r&&i&&(r.block<this.blockMin&&(this.blockMin=r.block),i.block>o&&(o=i.block),e[t].push([r,i]))}}}i>0&&(this.indices[t]={binIndex:e,loffset:r})}this.lastBlockPosition=o}get chromosomeNames(){return Object.keys(this.sequenceIndexMap)}blocksForRange(t,e,n){const r=this.indices[t];if(r){const t=this.reg2bins(e,n);if(0==t.length)return[];const i=[];for(let e of t)for(let t=e[0];t<=e[1];t++)if(r.binIndex[t]){const e=r.binIndex[t],n=e.length;for(let r=0;r<n;++r){const n=e[r][0],o=e[r][1];i.push({minv:n,maxv:o,bin:t})}}return function(t,e){const n=[];let r=null;return 0===t.length?t:(t.sort((function(t,e){const n=t.minv.block-e.minv.block;return 0!==n?n:t.minv.offset-e.minv.offset})),t.forEach((function(t){var i,o;e&&!t.maxv.isGreaterThan(e)||(null===r?(n.push(t),r=t):(i=r,(o=t).minv.block-i.maxv.block<65e3&&o.maxv.block-i.minv.block<5e6?t.maxv.isGreaterThan(r.maxv)&&(r.maxv=t.maxv):(n.push(t),r=t)))})),n)}(i,r.loffset[t[0]])}return[]}reg2bins(t,e){(t-=1)<1&&(t=1),e>2**50&&(e=2**34),e-=1;let n=0,r=0,i=this.minShift+3*this.depth;const o=[];for(;n<=this.depth;i-=3,r+=1<<3*n,n+=1){const n=r+(t>>i),s=r+(e>>i);if(s-n+o.length>this.maxBinNumber)throw new Error(`query ${t}-${e} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);o.push([n,s])}return o}bin_limit(){return((1<<3*(this.depth+1))-1)/7}}class Za{constructor(){}async parse(t,e,n){const r=[];let i=Number.MAX_SAFE_INTEGER,o=0;const s=[],a=new Wa(new DataView(t)),c=a.getInt(),l={};if(!(21578050===c||e&&21578324===c))throw new Error(indexURL+" is not a "+(e?"tabix":"bai")+" file");{const t=a.getInt();if(e){a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt();for(let e=0;e<t;e++){let t=a.getString();n&&(t=n.getChromosomeName(t)),l[t]=e,s[e]=t}}for(let e=0;e<t;e++){const t={},n=[],s=a.getInt();for(let e=0;e<s;e++){const e=a.getInt();if(37450===e)a.getInt(),a.getVPointer(),a.getVPointer(),a.getLong(),a.getLong();else{t[e]=[];const n=a.getInt();for(let r=0;r<n;r++){const n=a.getVPointer(),r=a.getVPointer();n&&r&&(n.block<i&&(i=n.block),r.block>o&&(o=r.block),t[e].push([n,r]))}}}const c=a.getInt();for(let t=0;t<c;t++){const t=a.getVPointer();n.push(t)}s>0&&(r[e]={binIndex:t,linearIndex:n})}this.firstBlockPosition=i,this.lastBlockPosition=o,this.indices=r,this.sequenceIndexMap=l,this.tabix=e}}get chromosomeNames(){return Object.keys(this.sequenceIndexMap)}blocksForRange(t,e,n){const r=this.indices[t];if(r){const t=function(t,e){const n=[];e>=1<<29&&(e=1<<29);return--e,n.push([0,0]),n.push([1+(t>>26),1+(e>>26)]),n.push([9+(t>>23),9+(e>>23)]),n.push([73+(t>>20),73+(e>>20)]),n.push([585+(t>>17),585+(e>>17)]),n.push([4681+(t>>14),4681+(e>>14)]),n}(e,n),i=[];for(let e of t)for(let t=e[0];t<=e[1];t++)if(r.binIndex[t]){const e=r.binIndex[t],n=e.length;for(let r=0;r<n;++r){const n=e[r][0],o=e[r][1];i.push({minv:n,maxv:o,bin:t})}}const o=r.linearIndex.length;let s=null;const a=Math.min(e>>14,o-1),c=Math.min(n>>14,o-1);for(let t=a;t<=c;++t){const e=r.linearIndex[t];e&&(s&&!e.isLessThan(s)||(s=e))}return function(t,e){const n=[];let r=null;return 0===t.length?t:(t.sort((function(t,e){const n=t.minv.block-e.minv.block;return 0!==n?n:t.minv.offset-e.minv.offset})),t.forEach((function(t){e&&!t.maxv.isGreaterThan(e)||(null!==r&&function(t,e){const n=e.minv.block-t.maxv.block,r=e.maxv.block-t.minv.block;return n<3e4&&r<1e7}(r,t)?t.maxv.isGreaterThan(r.maxv)&&(r.maxv=t.maxv):(n.push(t),r=t))})),n)}(i,s)}return[]}}class Xa{constructor(){}async parse(t,e){let n=0;this.chrIndex={},this.lastBlockPosition=[];const r=new Wa(new DataView(t));!function(t){t.getInt(),t.getInt();const e=t.getInt();if(t.getString(),t.getLong(),t.getLong(),t.getString(),t.getInt(),e>=3){let e=t.getInt();for(;e-- >0;)t.getString(),t.getString()}}(r);let i=r.getInt();for(;i-- >0;){let t=r.getString();e&&(t=e.getChromosomeName(t));const i=r.getInt(),o=r.getInt(),s=r.getInt();r.getInt(),r.getInt();let a=r.getLong();const c=[];for(let t=0;t<o;t++){const t=r.getLong();c.push({min:a,max:t}),a=t,t>n&&(n=t)}this.chrIndex[t]={chr:t,blocks:c,longestFeature:s,binWidth:i}}this.lastBlockPosition=n}get chromosomeNames(){return Object.keys(this.chrIndex)}blocksForRange(t,e,n){const r=this.chrIndex[t];if(r){const t=r.blocks,i=r.longestFeature,o=r.binWidth,s=Math.max(e-i,0),a=Math.floor(s/o);if(a>=t.length)return[];{const e=Math.min(Math.floor((n-1)/o),t.length-1),r=t[a].min,i=t[e].max;if(0===i-r)return[];return[{minv:{block:r,offset:0},maxv:{block:i,offset:0}}]}}}}async function Ya(t,e,n){let r=await go.loadArrayBuffer(t,gs(e)),i=new DataView(r);if(31===i.getUint8(0)&&139===i.getUint8(1)){r=Wi(r).buffer,i=new DataView(r)}switch(i.getInt32(0,!0)){case 21578050:return async function(t,e){const n=new Za;return await n.parse(t,!1,e),n}(r,n);case 21578324:return async function(t,e){const n=new Za;return await n.parse(t,!0,e),n}(r,n);case 21582659:return async function(t,e){const n=new Ga;return n.parse(t,e),n}(r,n);case 1480870228:return async function(t,e){const n=new Xa;return n.parse(t,e),n}(r,n);case 38359875:throw Error("CSI version 2 is not supported.");default:throw Error(`Unrecognized index type: ${t}`)}}class Ka{constructor(t,e){this.config=t,this.genome=e,this.bamPath=t.url,this.baiPath=t.indexURL,za.setReaderDefaults(this,t)}async readAlignments(t,e,n){const r=(await this.getChrIndex())[this.chrAliasTable.hasOwnProperty(t)?this.chrAliasTable[t]:t],i=new ba(t,e,n,this.config);if(void 0===r)return i;{const t=(await this.getIndex()).blocksForRange(r,e,n);if(!t||0===t.length)return i;for(let s of t){let t;if(0===s.maxv.offset)t=0;else{const e=gs(this.config,{range:{start:s.maxv.block,size:26}});t=$i(await go.loadArrayBuffer(this.bamPath,e))}const a=s.minv.block,c={start:a,size:s.maxv.block+t-a+1};var o=Wi(await go.loadArrayBuffer(this.bamPath,gs(this.config,{range:c})));if(za.decodeBamRecords(o,s.minv.offset,i,this.indexToChr,r,e,n,this.filter))break}return i.finish(),i}}async getHeader(){if(!this.header){const t=this.genome,e=await this.getIndex();let n;if(e.firstBlockPosition){const t=gs(this.config,{range:{start:e.firstBlockPosition,size:26}}),r=$i(await go.loadArrayBuffer(this.bamPath,t));n=e.firstBlockPosition+r}else n=64e3;const r=gs(this.config,{range:{start:0,size:n}});this.header=await za.readHeader(this.bamPath,r,t)}return this.header}async getIndex(){const t=this.genome;return this.index||(this.index=await Ya(this.baiPath,this.config,t)),this.index}async getChrIndex(){if(this.chrToIndex)return this.chrToIndex;{const t=await this.getHeader();return this.chrToIndex=t.chrToIndex,this.indexToChr=t.chrNames,this.chrAliasTable=t.chrAliasTable,this.chrToIndex}}}class Qa{constructor(t,e){this.config=t,this.genome=e;const n={};t.sources.sequences.forEach((function(r){const i=e?e.getChromosomeName(r):r;n[i]=function(t,e,n){const r={url:t.sources.url.replace("$CHR",n)};t.sources.indexURL&&(r.indexURL=t.sources.indexURL.replace("$CHR",n));const i=Object.assign(t,r);return new Ka(i,e)}(t,e,r)})),this.bamReaders=n,za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(this.bamReaders.hasOwnProperty(t)){let r=this.bamReaders[t];return await r.readAlignments(t,e,n)}return new ba(t,e,n,this.config)}}const Ja=function(t,e){this.config=t,this.genome=e,za.setReaderDefaults(this,t)};function tc(){const t=this,e=this.genome;if(this.header)return Promise.resolve(this.header);{const n=this.config.url+"?file="+this.config.alignmentFile+"&options=-b,-H",r=gs(this.config);return za.readHeader(n,r,e).then((function(e){return t.header=e,e}))}}Ja.prototype.readAlignments=function(t,e,n){var r=this;return tc.call(r).then((function(i){var o,s;return o=i.chrAliasTable.hasOwnProperty(t)?i.chrAliasTable[t]:t,s=r.config.url+"?reference="+r.config.referenceFile+"&file="+r.config.alignmentFile+"&region="+o+":"+e+"-"+n,go.loadString(s,gs(r.config)).then((function(s){var a;return i.chrToIndex[o],a=new ba(t,e,n,r.config),za.decodeSamRecords(s,a,o,e,n,r.filter),a}))}))};class ec{constructor(t,e){if(this.config=t,this.genome=e,this.format=t.format?t.format.toUpperCase():"BAM","BAM"!==this.format&&"VCF"!==this.format)throw Error(`htsget format ${t.format} is not supported`)}async readHeaderData(){const t=`${nc(this.config)}?class=header&format=${this.format}`,e=await go.loadJson(t,gs(this.config));return await this.loadUrls(e.htsget.urls)}async readData(t,e,n){const r=`${nc(this.config)}?format=${this.format}&referenceName=${t}&start=${Math.floor(e)}&end=${Math.ceil(n)}`,i=await go.loadJson(r,gs(this.config));return this.loadUrls(i.htsget.urls)}async loadUrls(t){const e=[];for(let n of t)if(n.url.startsWith("data:"))e.push(Promise.resolve(rc(n.url)));else{const t=gs(this.config||{});n.headers&&(t.headers=Object.assign(t.headers||{},n.headers)),e.push(go.loadArrayBuffer(n.url,t))}return function(t){let e=0;for(let n of t)e+=n.byteLength;let n=0;const r=new Uint8Array(e);for(let e of t){const t=new Uint8Array(e);r.set(t,n),n+=t.length}return r}(await Promise.all(e))}static async inferFormat(t){try{const e=nc(t),n=`${e}${e.includes("?")?"&":"?"}class=header`,r=await go.loadJson(n,gs(t));if(r.htsget){const e=r.htsget.format;if("BAM"!==e&&"VCF"!==e)throw Error(`htsget format ${e} is not supported`);t.format=e.toLowerCase(),t.sourceType="htsget",t.name||(t.name=await bs(t.url))}}catch(t){}}}function nc(t){if(t.url&&t.endpoint&&t.id)return t.url+t.endpoint+t.id;if(t.endpoint&&t.id)return t.endpoint+t.id;if(t.url)return t.url.startsWith("htsget://")?t.url.replace("htsget://","https://"):t.url;throw Error("Must specify either 'url', or 'endpoint' and 'id")}function rc(t){const e=t.split(","),n=e[0].split(":")[1];let r=e[1];r=n.indexOf("base64")>=0?atob(r):decodeURI(r);const i=new Uint8Array(r.length);for(var o=0;o<r.length;o++)i[o]=r.charCodeAt(o);return i}class ic extends ec{constructor(t,e){super(t,e),za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(!this.header){const t=Wi((await this.readHeaderData()).buffer);this.header=za.decodeBamHeader(t,this.genome),this.chrAliasTable=new Map;for(let t of Object.keys(this.header.chrAliasTable))this.chrAliasTable.set(t,this.header.chrAliasTable[t])}let r=this.chrAliasTable.has(t)?this.chrAliasTable.get(t):t;const i=Wi((await this.readData(r,e,n)).buffer),o=this.header.chrToIndex[t],s=new ba(t,e,n,this.config);return za.decodeBamRecords(i,this.header.size,s,this.header.chrNames,o,e,n),s.finish(),s}}const oc=eval,sc=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=163)}([function(t,e,n){var r=n(13),i=n(81).f,o=n(107),s=n(3),a=n(15),c=n(20),l=n(24),h=function(t){var e=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,n)}return new t(e,n,r)}return t.apply(this,arguments)};return e.prototype=t.prototype,e};t.exports=function(t,e){var n,u,f,d,p,g,m,v,b=t.target,w=t.global,y=t.stat,x=t.proto,k=w?r:y?r[b]:(r[b]||{}).prototype,_=w?s:s[b]||(s[b]={}),S=_.prototype;for(f in e)n=!o(w?f:b+(y?".":"#")+f,t.forced)&&k&&l(k,f),p=_[f],n&&(g=t.noTargetGet?(v=i(k,f))&&v.value:k[f]),d=n&&g?g:e[f],n&&typeof p==typeof d||(m=t.bind&&n?a(d,r):t.wrap&&n?h(d):x&&"function"==typeof d?a(Function.call,d):d,(t.sham||d&&d.sham||p&&p.sham)&&c(m,"sham",!0),_[f]=m,x&&(l(s,u=b+"Prototype")||c(s,u,{}),s[u][f]=d,t.real&&S&&!S[f]&&c(S,f,d)))}},function(t,e){t.exports=function(t){return t&&t.__esModule?t:{default:t}}},function(t,e,n){var r=n(14);t.exports=function(t){if(!r(t))throw TypeError(String(t)+" is not an object");return t}},function(t,e){t.exports={}},function(t,e){t.exports=!0},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}},function(t,e,n){var r=n(13),i=n(61),o=n(64),s=n(110),a=r.Symbol,c=i("wks");t.exports=function(t){return c[t]||(c[t]=s&&a[t]||(s?a:o)("Symbol."+t))}},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){var r=n(2),i=n(119),o=n(29),s=n(15),a=n(90),c=n(120),l=function(t,e){this.stopped=t,this.result=e};(t.exports=function(t,e,n,h,u){var f,d,p,g,m,v,b=s(e,n,h?2:1);if(u)f=t;else{if("function"!=typeof(d=a(t)))throw TypeError("Target is not iterable");if(i(d)){for(p=0,g=o(t.length);g>p;p++)if((m=h?b(r(v=t[p])[0],v[1]):b(t[p]))&&m instanceof l)return m;return new l(!1)}f=d.call(t)}for(;!(v=f.next()).done;)if((m=c(f,b,v.value,h))&&m instanceof l)return m;return new l(!1)}).stop=function(t){return new l(!0,t)}},function(t,e,n){var r=n(1),i=r(n(7)),o=r(n(32)),s=r(n(27)),a=r(n(33)),c=r(n(265)),l=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}((0,c.default)(Error)),h=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}((0,c.default)(Error)),u=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l),f=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(u),d=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l),p=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l);t.exports={CramBufferOverrunError:f,CramMalformedError:u,CramUnimplementedError:h,CramSizeLimitError:d,CramArgumentError:p}},function(t,e,n){var r=n(196);function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),r(t,i.key,i)}}t.exports=function(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}},function(t,e,n){var r=n(3),i=n(24),o=n(95),s=n(21).f;t.exports=function(t){var e=r.Symbol||(r.Symbol={});i(e,t)||s(e,t,{value:o.f(t)})}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){(function(e){var n="object",r=function(t){return t&&t.Math==Math&&t};t.exports=r(typeof globalThis==n&&globalThis)||r(typeof window==n&&window)||r(typeof self==n&&self)||r(typeof e==n&&e)||Function("return this")()}).call(this,n(23))},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){var r=n(5);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 0:return function(){return t.call(e)};case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)}}return function(){return t.apply(e,arguments)}}},function(t,e,n){t.exports=n(167)},function(t,e,n){var r=n(12);t.exports=!r((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}))},function(t,e,n){var r=n(3);t.exports=function(t){return r[t+"Prototype"]}},function(t,e,n){(function(t){
39
+ function Ps(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function Os(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(Math.random()*e.length)]}while(t[n]);return n}function Fs(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}function Ds(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]}const Bs=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),zs={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"},lineDash:{svgAttr:"stroke-dasharray",canvas:[],svg:null,apply:"stroke"}};class Hs{constructor(t,e){this.__root=t,this.__ctx=e}addColorStop(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),e&&-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",Ps("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)}}class Vs{constructor(t,e){this.__root=t,this.__ctx=e}}class js{constructor(t){if(!(this instanceof js))return new js(t);if(this.config=t,this.width=t.width,this.height=t.height,this.enableMirroring=t.enableMirroring||!1,this.canvas=this,this.__document=document,t.ctx?this.__ctx=t.ctx:(this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d")),this.isSVG=!0,this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__createElement("svg"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__root.setAttribute("overflow","visible"),t.viewbox){const e=t.viewbox.x+" "+t.viewbox.y+" "+t.viewbox.width+" "+t.viewbox.height;this.__root.setAttribute("viewBox",e),this.viewbox=t.viewbox}this.__ids={},this.__defs=this.__createElement("defs"),this.__root.appendChild(this.__defs),this.multiLocusGap=t.multiLocusGap;let e={id:"svg_output_backdrop",width:"100%",height:"100%",fill:t.backdropColor||"white"},n=this.__createElement("rect",e);this.__root.appendChild(n),this.__rootGroup=this.__createElement("g",{id:"root-group"}),this.__root.appendChild(this.__rootGroup),this.__currentElement=this.__rootGroup}setWidth(t){this.width=t,this.__root.setAttribute("width",this.width);const e=this.config.viewbox.x+" "+this.config.viewbox.y+" "+t+" "+this.config.viewbox.height;this.__root.setAttribute("viewBox",e)}setHeight(t){this.height=t,this.__root.setAttribute("height",this.height);const e=this.config.viewbox.x+" "+this.config.viewbox.y+" "+this.config.viewbox.width+" "+t;this.__root.setAttribute("viewBox",e)}__createElement(t,e,n){void 0===e&&(e={});let r=this.__document.createElementNS("http://www.w3.org/2000/svg",t);n&&(r.setAttribute("fill","none"),r.setAttribute("stroke","none"));for(let t of Object.keys(e))r.setAttribute(t,e[t]);return r}__setDefaultStyles(){var t,e,n=Object.keys(zs);for(t=0;t<n.length;t++)this[e=n[t]]=zs[e].canvas}__applyStyleState(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]}__getStyleState(){var t,e,n={},r=Object.keys(zs);for(t=0;t<r.length;t++)n[e=r[t]]=this[e];return n}__applyStyleToCurrentElement(t){var e=this.__currentElement,n=this.__currentElementsToStyle;n&&(e.setAttribute(t,""),e=n.element,n.children.forEach((function(e){e.setAttribute(t,"")})));var r,i,o,s,a,c=Object.keys(zs);for(r=0;r<c.length;r++)if(i=zs[c[r]],o=this[c[r]],i.apply)if(o instanceof Vs){if(o.__ctx)for(;o.__ctx.__defs.childNodes.length;)s=o.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[s]=s,this.__defs.appendChild(o.__ctx.__defs.childNodes[0]);e.setAttribute(i.apply,Ps("url(#{id})",{id:o.__root.getAttribute("id")}))}else if(o instanceof Hs)e.setAttribute(i.apply,Ps("url(#{id})",{id:o.__root.getAttribute("id")}));else if(i&&-1!==i.apply.indexOf(t)&&i.svg!==o)if("stroke"!==i.svgAttr&&"fill"!==i.svgAttr||!o||-1===o.indexOf("rgba")){var l=i.svgAttr;if("globalAlpha"===c[r]&&(l=t+"-"+i.svgAttr,e.getAttribute(l)))continue;e.setAttribute(l,o)}else{a=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(o),e.setAttribute(i.svgAttr,Ps("rgb({r},{g},{b})",{r:a[1],g:a[2],b:a[3]}));var h=a[4],u=this.globalAlpha;null!=u&&(h*=u),e.setAttribute(i.svgAttr+"-opacity",h)}}__closestGroupOrSvg(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)}getSerializedSvg(t){var e,n,r,i,o,s=(new XMLSerializer).serializeToString(this.__root);if(t)for(e=Object.keys(Bs),n=0;n<e.length;n++)r=e[n],i=Bs[r],(o=new RegExp(r,"gi")).test(s)&&(s=s.replace(o,i));return s}getSvg(){return this.__root}saveWithTranslationAndClipRect(t,e,n,r,i,o){const s=`${t}_clip_rect`;let a=this.__createElement("clipPath",{id:s});this.__defs.appendChild(a);const c={x:"0",y:o.toString(),width:r.toString(),height:i.toString()};a.appendChild(this.__createElement("rect",c));const l=this.__createElement("g");l.setAttribute("transform",Ps("translate({x},{y})",{x:e,y:n})),l.setAttribute("clip-path",Ps("url(#{id})",{id:s}));const h=this.__closestGroupOrSvg();h.appendChild(l),this.__groupStack.push(h),this.__currentElement=l,this.__stack.push(this.__getStyleState())}save(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())}restore(){this.__currentElement=this.__groupStack.pop(),this.__currentElementsToStyle=null,this.__currentElement||(this.__currentElement=this.__root.childNodes[1]);var t=this.__stack.pop();this.__applyStyleState(t)}__addTransform(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){"path"===this.__currentElement.nodeName&&(this.__currentElementsToStyle||(this.__currentElementsToStyle={element:e,children:[]}),this.__currentElementsToStyle.children.push(this.__currentElement),this.__applyCurrentDefaultPath());var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)}addTrackGroupWithTranslationAndClipRect(t,e,n,r,i,o){const s=t+"_clip_rect";let a=this.__createElement("clipPath",{id:s});this.__defs.appendChild(a),a.appendChild(this.__createElement("rect",{x:"0",y:o.toString(),width:r.toString(),height:i.toString()}));let c=this.__createElement("g");this.__rootGroup.appendChild(c),c.setAttribute("transform",Ps("translate({x},{y})",{x:e,y:n})),c.setAttribute("id",t+"_group"),c.setAttribute("clip-path",Ps("url(#{id})",{id:s})),this.__currentElement=c}scale(t,e){void 0===e&&(e=t),this.__addTransform(Ps("scale({x},{y})",{x:t,y:e}))}rotate(t){var e=180*t/Math.PI;this.__addTransform(Ps("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))}translate(t,e){this.__addTransform(Ps("translate({x},{y})",{x:t,y:e}))}transform(t,e,n,r,i,o){this.__addTransform(Ps("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:o}))}beginPath(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t}__applyCurrentDefaultPath(){var t=this.__currentElement;"path"===t.nodeName?t.setAttribute("d",this.__currentDefaultPath):console.error("Attempted to apply path command to node",t.nodeName)}__addPathCommand(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t}moveTo(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(Ps("M {x} {y}",{x:t,y:e}))}closePath(){this.__currentDefaultPath&&this.__addPathCommand("Z")}lineTo(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath&&this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(Ps("L {x} {y}",{x:t,y:e})):this.__addPathCommand(Ps("M {x} {y}",{x:t,y:e}))}bezierCurveTo(t,e,n,r,i,o){this.__currentPosition={x:i,y:o},this.__addPathCommand(Ps("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:o}))}quadraticCurveTo(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(Ps("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))}arcTo(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=Ds([o-t,s-e]),c=Ds([n-t,r-e]);if(a[0]*c[1]!=a[1]*c[0]){var l=a[0]*c[0]+a[1]*c[1],h=Math.acos(Math.abs(l)),u=Ds([a[0]+c[0],a[1]+c[1]]),f=i/Math.sin(h/2),d=t+f*u[0],p=e+f*u[1],g=[-a[1],a[0]],m=[c[1],-c[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},b=v(g),w=v(m);this.lineTo(d+g[0]*i,p+g[1]*i),this.arc(d,p,i,b,w)}else this.lineTo(t,e)}}}stroke(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")}fill(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")}rect(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()}fillRect(t,e,n,r){r<0&&(e+=r,r=-r),n<0&&(t+=n,n=-n);var i,o,s,a={x:t,y:e,width:n,height:r};(!this.viewbox||(i=this.viewbox,o=a,i.x<o.x+o.width&&i.x+i.width>o.x&&i.y<o.y+o.height&&i.y+i.height>o.y))&&(s=this.__createElement("rect",a,!0),this.__closestGroupOrSvg().appendChild(s),this.__currentElement=s,this.__applyStyleToCurrentElement("fill"))}strokeRect(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")}strokeEllipse(t,e,n,r,i,o,s,a){this.__ellipse(t,e,n,r,i,o,s,a,"stroke")}fillEllipse(t,e,n,r,i,o,s,a){this.__ellipse(t,e,n,r,i,o,s,a,"fill")}__ellipse(t,e,n,r,i,o,s,a,c){const l={cx:t,cy:e,rx:n,ry:r},h=this.__createElement("ellipse",l,!0);this.__closestGroupOrSvg().appendChild(h),this.__currentElement=h,this.__applyStyleToCurrentElement(c)}__clearCanvas(){for(var t=this.__closestGroupOrSvg().getAttribute("transform"),e=this.__root.childNodes[1],n=e.childNodes,r=n.length-1;r>=0;r--)n[r]&&e.removeChild(n[r]);this.__currentElement=e,this.__groupStack=[],t&&this.__addTransform(t)}clearRect(t,e,n,r){if(0!==t||0!==e||n!==this.width||r!==this.height){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)}else this.__clearCanvas()}createLinearGradient(t,e,n,r){var i=this.__createElement("linearGradient",{id:Os(this.__ids),x1:t+"px",x2:n+"px",y1:e+"px",y2:r+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(i),new Hs(i,this)}createRadialGradient(t,e,n,r,i,o){var s=this.__createElement("radialGradient",{id:Os(this.__ids),cx:r+"px",cy:i+"px",r:o+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(s),new Hs(s,this)}__parseFont(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\'\"\sa-z0-9]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e}__wrapTextLink(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e}__applyText(t,e,n,r){var i,o,s=this.__parseFont(),a=this.__closestGroupOrSvg(),c=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":Fs(this.textBaseline)},!0);c.appendChild(this.__document.createTextNode(t)),this.__currentElement=c,this.__applyStyleToCurrentElement(r),a.appendChild(this.__wrapTextLink(s,c))}fillText(t,e,n){this.__applyText(t,e,n,"fill")}strokeText(t,e,n){this.__applyText(t,e,n,"stroke")}measureText(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)}arc(t,e,n,r,i,o){if(r!==i){(r%=2*Math.PI)===(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(o?-1:1))%(2*Math.PI));var s=t+n*Math.cos(i),a=e+n*Math.sin(i),c=t+n*Math.cos(r),l=e+n*Math.sin(r),h=o?0:1,u=0,f=i-r;f<0&&(f+=2*Math.PI),u=o?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(c,l),this.__addPathCommand(Ps("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:u,sweepFlag:h,endX:s,endY:a})),this.__currentPosition={x:s,y:a}}}clip(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=Os(this.__ids),r=this.__createElement("g");this.__applyCurrentDefaultPath(),t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",Ps("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r}drawImage(){var t,e,n,r,i,o,s,a,c,l,h,u,f,d=Array.prototype.slice.call(arguments),p=d[0],g=0,m=0;if(3===d.length)t=d[1],e=d[2],n=i=p.width,r=o=p.height;else if(5===d.length)t=d[1],e=d[2],n=d[3],r=d[4],i=p.width,o=p.height;else{if(9!==d.length)throw new Error("Invalid number of arguments passed to drawImage: "+arguments.length);g=d[1],m=d[2],i=d[3],o=d[4],t=d[5],e=d[6],n=d[7],r=d[8]}s=this.__closestGroupOrSvg();var v="translate("+t+", "+e+")";if(p instanceof js){if((a=p.getSvg().cloneNode(!0)).childNodes&&a.childNodes.length>1){for(c=a.childNodes[0];c.childNodes.length;)f=c.childNodes[0].getAttribute("id"),this.__ids[f]=f,this.__defs.appendChild(c.childNodes[0]);if(l=a.childNodes[1]){var b,w=l.getAttribute("transform");b=w?w+" "+v:v,l.setAttribute("transform",b),s.appendChild(l)}}}else"CANVAS"!==p.nodeName&&"IMG"!==p.nodeName||((h=this.__createElement("image")).setAttribute("width",n),h.setAttribute("height",r),h.setAttribute("preserveAspectRatio","none"),(g||m||i!==p.width||o!==p.height)&&((u=this.__document.createElement("canvas")).width=n,u.height=r,u.getContext("2d").drawImage(p,g,m,i,o,0,0,n,r),p=u),h.setAttribute("transform",v),h.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===p.nodeName?p.toDataURL():p.getAttribute("src")),s.appendChild(h))}createPattern(t,e){let n,r=this.__document.__createElement("pattern"),i=Os(this.__ids);return r.setAttribute("id",i),r.setAttribute("width",t.width),r.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?(n=this.__createElement("image"),n.setAttribute("width",t.width),n.setAttribute("height",t.height),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),r.appendChild(n),this.__defs.appendChild(r)):t instanceof js&&(r.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(r)),new Vs(r,this)}setLineDash(t){t&&t.length>0?this.lineDash=t.join(","):this.lineDash=null}drawFocusRing(){}createImageData(){}getImageData(){}putImageData(){}globalCompositeOperation(){}setTransform(){}}const Us=function(t,e,n,r,i){this.name=t,this.order=e,this.bpStart=n,this.bpLength=r,this.rangeLocus=i},qs=Se,Ws=new Set(["fastaURL","indexURL","cytobandURL","indexed"]);class $s{constructor(t){this.fastaURL=t.fastaURL,this.withCredentials=t.withCredentials,this.chromosomeNames=[],this.chromosomes={},this.sequences=new Map,this.offsets={};const e={};for(let n in t)t.hasOwnProperty(n)&&!Ws.has(n)&&(e[n]=t[n]);this.config=e}async init(){return this.loadAll()}async getSequence(t,e,n){this.offsets[t]&&(e-=this.offsets[t],n-=this.offsets[t]);let r="";if(e<0)for(let t=e;t<Math.min(n,0);t++)r+="*";if(n<=0)return Promise.resolve(r);const i=this.sequences.get(t),o=Math.min(n,i.length);return r+i.substring(e,o)}async loadAll(){let t;if(ys(this.fastaURL)){let e=Yi(this.fastaURL);t="";for(let n of e)t+=String.fromCharCode(n)}else t=await go.load(this.fastaURL,gs(this.config));const e=qs(t),n=e.length;let r,i,o,s,a=0,c=0,l=0;for(;a<n;)if(o=e[a++].trim(),o.startsWith("#")||0===o.length);else if(o.startsWith(">")){r&&(this.chromosomeNames.push(s),this.sequences.set(s,r),this.chromosomes[s]=new Us(s,l++,c,c+r.length,i));const t=o.substr(1).split(/\s+/)[0].split(":");if(s=t[0],r="",c=0,i=void 0,t.length>1&&t[1].indexOf("-")>0){const e=t[1].split("-");2===e.length&&/^[0-9]+$/.test(e[0])&&/^[0-9]+$/.test(e[1]);const n=Number.parseInt(e[0]);Number.parseInt(e[1])>n&&(c=n-1,this.offsets[s]=c,i=t[1])}}else r+=o;r&&(this.chromosomeNames.push(s),this.sequences.set(s,r),this.chromosomes[s]=new Us(s,l++,c,c+r.length,i))}}const Gs=function(t,e,n,r){this.chr=t,this.start=e,this.end=n,this.features=r};Gs.prototype.contains=function(t,e,n){return this.chr===t&&this.start<=e&&this.end>=n},Gs.prototype.containsRange=function(t){return this.chr===t.chr&&this.start<=t.start&&this.end>=t.end};const Zs=Se,Xs=new Set(["fastaURL","indexURL","compressedIndexURL","cytobandURL","indexed"]);class Ys{constructor(t){this.file=t.fastaURL,this.indexFile=t.indexURL||t.indexFile||this.file+".fai",this.compressedIndexFile=t.compressedIndexURL||!1,this.withCredentials=t.withCredentials,this.chromosomeNames=[],this.chromosomes={},this.sequences={},this.offsets={};const e={};for(let n in t)t.hasOwnProperty(n)&&!Xs.has(n)&&(e[n]=t[n]);this.config=e}async init(){return this.getIndex()}async getSequence(t,e,n){if(!(this.interval&&this.interval.contains(t,e,n))){let r=e,i=n;if(n-e<5e4){const t=n-e,o=Math.round(e+t/2);r=Math.max(0,o-25e3),i=o+25e3}const o=await this.readSequence(t,r,i);this.interval=new Gs(t,r,i,o)}const r=e-this.interval.start,i=n-e;return this.interval.features?this.interval.features.substr(r,i):null}async getIndex(){if(this.index)return this.index;{const t=await go.load(this.indexFile,gs(this.config)),e=Zs(t),n=e.length;let r=0,i=0;for(this.index={};r<n;){const t=e[r++].split("\t");if(5===t.length){const e=t[0],n=parseInt(t[1]),r={size:n,position:parseInt(t[2]),basesPerLine:parseInt(t[3]),bytesPerLine:parseInt(t[4])};this.chromosomeNames.push(e),this.index[e]=r,this.chromosomes[e]=new Us(e,i++,0,n)}}return this.index}}async getCompressedIndex(){if(this.compressedIndex)return this.compressedIndex;if(!this.compressedIndexFile)return this.compressedIndex=[],this.compressedIndex;this.compressedIndex=[];const t=await go.loadArrayBuffer(this.compressedIndexFile,gs(this.config)),e=t.byteLength;if(e<8)return console.log("Cannot parse GZI index file: length ("+e+" bytes) is insufficient to determine content of index."),this.compressedIndex;const n=t.slice(0,8),r=Number(new DataView(n).getBigUint64(0,!0)),i=8+2*r*8;if(e!=i)return console.log("Incorrect file size of reference genome index. Expected : "+i+". Received : "+e),this.compressedIndex;this.compressedIndex.push([0,0]);for(let e=0;e<r;e++){const n=8+2*e*8,r=8+2*e*8+16,i=t.slice(n,r),o=new DataView(i),s=Number(o.getBigUint64(0,!0)),a=Number(o.getBigUint64(8,!0));this.compressedIndex.push([s,a])}return this.compressedIndex}async getRelevantCompressedBlockNumbers(t,e){if(t<0||e<0||e<t)return console.log("Incompatible query positions for reference-genome. Start:"+t+" | End:"+e),[];await this.getCompressedIndex();let n=[];const r=this.compressedIndex.length-1;if(0==this.compressedIndex.length)return console.log("Compressed index does not contain any content"),[];if(t>this.compressedIndex[r][1])return[r];let i=0,o=r,s=Math.floor(this.compressedIndex.length/2),a=this.compressedIndex.length+1,c=!1;for(let e=0;e<a;e++){const e=this.compressedIndex[s][1],n=s<this.compressedIndex.length-1?this.compressedIndex[s+1][1]:1/0;if(e<=t&&n>t){c=!0;break}e<t?i=s+1:o=s-1,s=Math.ceil((o-i)/2)+i}if(!c)return console.log("No blocks within compressed index found that correspond with query positions "+t+","+e),console.log(this.compressedIndex),[];n.push(s);for(let t=s+1;t<this.compressedIndex.length;t++){n.push(t);if(this.compressedIndex[t][1]>=e)break}const l=n[n.length-1];return l===this.compressedIndex.length-1&&this.compressedIndex[l][1]<e&&n.push(-1),n}async loadAndUncompressBlocks(t,e){if(await this.getCompressedIndex(),0==t.length)return"";let n=Array(t.length-1);for(let e=0;e<t.length-1;e++){const r=t[e],i=this.compressedIndex[r][0],o=t[e+1];let s=[];if(-1!=o){const t=this.compressedIndex[o][0]-i;s=await go.loadArrayBuffer(this.file,gs(this.config,{range:{start:i,size:t}}))}else s=await go.loadArrayBuffer(this.file,gs(this.config,{range:{start:i}}));const a=await Wi(s);n[e]=a}let r="";for(let t=0;t<n.length;t++)for(let e=0;e<n[t].length;e++){r+=String.fromCharCode(n[t][e])}const i=e-this.compressedIndex[t[0]][1];return r=r.substring(i),r}async readSequence(t,e,n){await this.getIndex(),await this.getCompressedIndex();const r=this.index[t];if(!r)return console.log("No index entry for chr: "+t),this.interval=new Gs(t,e,n,null),null;const i=Math.max(0,e),o=Math.min(r.size,n),s=r.bytesPerLine,a=r.basesPerLine,c=r.position,l=s-a,h=Math.floor(i/a),u=Math.floor(o/a),f=i-h*a,d=c+h*s+f,p=c+u*s+(o-u*a)-1,g=p-d+1;if(g<=0)return console.error("No sequence for "+t+":"+e+"-"+n),null;let m;if(this.compressedIndexFile){let t=await this.getRelevantCompressedBlockNumbers(d,p);if(0===t.length)return console.log("No blocks in the compressed index that correspond with the requested byte positions ("+d+","+p+")"),null;m=await this.loadAndUncompressBlocks(t,d)}else m=await go.load(this.file,gs(this.config,{range:{start:d,size:g}}));if(!m)return null;let v,b="",w=0,y=m.length;for(f>0&&(v=Math.min(o-i,a-f),b+=m.substr(w,v),w+=v+l);w<y;)v=Math.min(a,y-w),b+=m.substr(w,v),w+=v+l;return b}}const Ks=Se;class Qs{constructor(t){this.url=t,this.chromosomeNames=[],this.chromosomes={}}async init(){return this.loadAll()}async getSequence(t,e,n){}async loadAll(){let t;if(ys(this.url)){let e=Yi(this.fastaURL);t="";for(let n of e)t+=String.fromCharCode(n)}else t=await go.load(this.url,{});this.chromosomeNames=[],this.chromosomes={};const e=Ks(t);let n=0;for(let t of e){const e=t.split("\t");this.chromosomeNames.push(e[0]);const r=Number.parseInt(e[1]),i=new Us(e[0],n++,0,r);this.chromosomes[e[0]]=i}}}const Js=function(t,e,n,r){this.start=t,this.end=e,this.name=n,this.stain=0,"acen"===r?this.type="c":(this.type=r.charAt(1),"p"===this.type&&(this.stain=parseInt(r.substring(4))))};function ta(){return"2.12.6"}const ea=Se,na={loadGenome:async function(t){const e=t.cytobandURL,n=t.aliasURL,r=await async function(t){let e;return e="chromsizes"===t.format?new Qs(t.fastaURL):ys(t.fastaURL)||!1===t.indexed?new $s(t):new Ys(t),await e.init(),e}(t);let i,o;return e&&(i=await async function(t,e){let n;if(ys(t)){const e=Yi(t);n="";const r=e.length;for(let t=0;t<r;t++)n+=String.fromCharCode(e[t])}else n=await go.loadString(t,gs(e));const r={};let i,o=[];const s=ea(n);for(let t of s){var a=t.split("\t"),c=a[0];if(i||(i=c),c!==i&&(r[i]=o,o=[],i=c),5===a.length){var l=parseInt(a[1]),h=parseInt(a[2]),u=a[3],f=a[4];o.push(new Js(l,h,u,f))}}return r}(e,r.config)),n&&(o=await function(t,e){return go.loadString(t,gs(e)).then((function(t){var e=ea(t),n=[];return e.forEach((function(t){!t.startsWith("#")&&t.length>0&&n.push(t.split("\t"))})),n}))}(n,r.config)),new ra(t,r,i,o)},initializeGenomes:async function(t){if(!na.KNOWN_GENOMES){const n={};if(!1!==t.loadDefaultGenomes)try{const i=`https://igv.org/genomes/genomes.json?randomSeed=${Math.random().toString(36)}&version=2.12.6`;e(await go.loadJson(i,{timeout:5e3}))}catch(o){console.error(o);try{const s=`https://s3.amazonaws.com/igv.org.genomes/genomes.json?randomSeed=${Math.random().toString(36)}&version=2.12.6`;e(await go.loadJson(s,{}))}catch(a){console.error(a),console.warn("Errors loading default genome definitions.")}}const r=t.genomeList||t.genomes;if(r)if("string"==typeof r){e(await go.loadJson(r,{}))}else e(r);function e(t){return t.forEach((function(t){n[t.id]=t})),n}na.KNOWN_GENOMES=n}},isWholeGenomeView:function(t){return"all"===t.toLowerCase()},expandReference:function(t){if(ke(t)&&t.startsWith("{"))try{t=JSON.parse(t)}catch(t){}let e;if(ke(t)?e=t:t.genome?e=t.genome:void 0!==t.id&&void 0===t.fastaURL&&(e=t.id),e){const t=na.KNOWN_GENOMES[e];return t||Qo.presentAlert(new Error(`Unknown genome id: ${e}`),void 0),t}return t}};class ra{constructor(t,e,n,r){this.config=t,this.id=t.id||function(t){return void 0!==t.id?t.id:t.fastaURL&&ke(t.fastaURL)?t.fastaURL:t.fastaURL&&t.fastaURL.name?t.fastaURL.name:("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}(t),this.sequence=e,this.chromosomeNames=e.chromosomeNames,this.chromosomes=e.chromosomes,this.ideograms=n,this.featureDB={},this.wholeGenomeView=void 0===t.wholeGenomeView||t.wholeGenomeView,this.wholeGenomeView&&Object.keys(e.chromosomes).length>1?function(t,e){let n;if(e.chromosomeOrder)Array.isArray(e.chromosomeOrder)?t.wgChromosomeNames=e.chromosomeOrder:t.wgChromosomeNames=e.chromosomeOrder.split(",").map((t=>t.trim())),n=t.wgChromosomeNames.map((e=>t.chromosomes[e])).filter((t=>void 0!==t));else{const e=Object.keys(t.chromosomes).map((e=>t.chromosomes[e].bpLength)).reduce(((t,e)=>Math.max(t,e)))/50;n=Object.values(t.chromosomes).filter((t=>t.bpLength>e));const r=n.filter((t=>i(t.name.replace("chr","")))),o=n.filter((t=>!i(t.name.replace("chr",""))));r.sort(((t,e)=>Number.parseInt(t.name.replace("chr",""))-Number.parseInt(e.name.replace("chr",""))));const s=r.map((t=>t.name));for(let t of o)s.push(t.name);t.wgChromosomeNames=s}const r=n.reduce(((t,e)=>t+e.bpLength),0);function i(t){return/^\d+$/.test(t)}t.chromosomes.all={name:"all",bpLength:r}}(this,t):this.wgChromosomeNames=e.chromosomeNames;var i={},o=this;i.all="all",this.chromosomeNames.forEach((function(t){var e=t.startsWith("chr")?t.substring(3):"chr"+t;i[e.toLowerCase()]=t,"chrM"===t&&(i.mt="chrM"),"MT"===t&&(i.chrm="MT"),i[t.toLowerCase()]=t})),r&&r.forEach((function(t){var e,n;for(n=0;n<t.length;n++)if(o.chromosomes[t[n]]){e=t[n];break}e&&t.forEach((function(t){t!==e&&(i[t.toLowerCase()]=e,i[t]=e)}))})),this.chrAliasTable=i}showWholeGenomeView(){return!1!==this.config.wholeGenomeView}toJSON(){return Object.assign({},this.config,{tracks:void 0})}getInitialLocus(){}getHomeChromosomeName(){return this.showWholeGenomeView()&&this.chromosomes.hasOwnProperty("all")?"all":this.chromosomeNames[0]}getChromosomeName(t){const e=t?this.chrAliasTable[t.toLowerCase()]:t;return e||t}getChromosome(t){return t=this.getChromosomeName(t),this.chromosomes[t]}getCytobands(t){return this.ideograms?this.ideograms[t]:null}getLongestChromosome(){var t,e=this.chromosomes;for(let r in e){if(e.hasOwnProperty(r)){var n=e[r];(void 0===t||n.bpLength>t.bpLength)&&(t=n)}return t}}getChromosomes(){return this.chromosomes}getGenomeCoordinate(t,e){var n=this.getCumulativeOffset(t);if(void 0!==n)return n+e}getChromosomeCoordinate(t){let e;void 0===this.cumulativeOffsets&&(this.cumulativeOffsets=computeCumulativeOffsets.call(this));let n=0;for(let r of this.wgChromosomeNames){const i=this.cumulativeOffsets[r];if(i>t){return{chr:e,position:t-n}}e=r,n=i}return{chr:this.wgChromosomeNames[this.wgChromosomeNames.length-1],position:0}}getCumulativeOffset(t){void 0===this.cumulativeOffsets&&(this.cumulativeOffsets=function(){let t=this,e={},n=0;for(let r of t.wgChromosomeNames){e[r]=Math.floor(n);n+=t.getChromosome(r).bpLength}return e}.call(this));const e=this.getChromosomeName(t);return this.cumulativeOffsets[e]}getGenomeLength(){let t=this;if(!this.bpLength){let e=0;t.wgChromosomeNames.forEach((function(n){let r=t.chromosomes[n];e+=r.bpLength})),this.bpLength=e}return this.bpLength}async getSequence(t,e,n){return t=this.getChromosomeName(t),this.sequence.getSequence(t,e,n)}}let ia,oa=0;class sa extends class{constructor(t,e,n,r){this.guid=ve(),this.trackView=t,this.referenceFrame=n,this.browser=t.browser,this.$viewport=de('<div class="igv-viewport">'),e.appendChild(this.$viewport.get(0)),t.track.height&&(this.$viewport.get(0).style.height=`${t.track.height}px`),t.track instanceof Ns&&(this.alert=new Yo(this.$viewport.get(0))),this.$content=de("<div>",{class:"igv-viewport-content"}),this.$viewport.append(this.$content),this.$content.height(this.$viewport.height()),this.contentDiv=this.$content.get(0),this.$viewport.width(r),this.initializationHelper()}initializationHelper(){}showMessage(t){this.messageDiv||(this.messageDiv=document.createElement("div"),this.messageDiv.className="igv-viewport-message",this.contentDiv.append(this.messageDiv)),this.messageDiv.textContent=t,this.messageDiv.style.display="inline-block"}hideMessage(t){this.messageDiv&&(this.messageDiv.style.display="none")}setTrackLabel(t){}startSpinner(){}stopSpinner(){}checkZoomIn(){return!0}shift(){}setTop(t){const e=-t,n=e+this.$viewport.height();this.$content.css("top",`${t}px`),(void 0===this.canvasVerticalRange||this.canvasVerticalRange.bottom<n||this.canvasVerticalRange.top>e)&&this.repaint()}async loadFeatures(){}async repaint(){console.log("Viewport - repaint()")}draw(t,e,n){console.log("Viewport - draw(drawConfiguration, features, roiFeatures)")}checkContentHeight(t){let e=this.trackView.track;if(t=t||this.cachedFeatures,"FILL"===e.displayMode)this.setContentHeight(this.$viewport.height());else if("function"==typeof e.computePixelHeight&&t&&t.length>0){let n=e.computePixelHeight(t);n!==this.$content.height()&&this.setContentHeight(n)}}getContentHeight(){return this.$content.height()}setContentHeight(t){t=Math.min(t,32e3),this.$content.height(t)}isLoading(){return!1}saveSVG(){}isVisible(){return this.$viewport.width()}setWidth(t){this.$viewport.width(t)}getWidth(){return this.$viewport.width()}getContentTop(){return this.contentDiv.offsetTop}containsPosition(t,e){console.log("Viewport - containsPosition(chr, position)")}addMouseHandlers(){}removeMouseHandlers(){}dispose(){this.popover&&this.popover.dispose(),this.$viewport.get(0).remove();for(let t of Object.keys(this))this[t]=void 0}}{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.$spinner=de("<div>",{class:"igv-loading-spinner-container"}),this.$viewport.append(this.$spinner),this.$spinner.append(de("<div>"));const t=this.trackView.track;"sequence"!==t.type&&(this.$zoomInNotice=this.createZoomInNotice(this.$content)),t.name&&"sequence"!==t.id&&(this.$trackLabel=de('<div class="igv-track-label">'),this.$viewport.append(this.$trackLabel),this.setTrackLabel(t.name),!1===this.browser.trackLabelsVisible&&this.$trackLabel.hide()),this.stopSpinner(),this.addMouseHandlers()}setContentHeight(t){super.setContentHeight(t),this.featureCache&&(this.featureCache.redraw=!0)}setTrackLabel(t){this.$trackLabel.empty(),this.$trackLabel.html(t);const e=this.$trackLabel.text();this.$trackLabel.attr("title",e)}startSpinner(){this.$spinner.show()}stopSpinner(){this.$spinner&&this.$spinner.hide()}checkZoomIn(){if(this.trackView.track&&"sequence"===this.trackView.track.type&&this.referenceFrame.bpPerPixel>1)return de(this.canvas).remove(),this.canvas=void 0,!1;if(!this.viewIsReady())return!1;if((()=>{if("all"!==this.referenceFrame.chr.toLowerCase()||this.trackView.track.supportsWholeGenome){const t=this.trackView.track.visibilityWindow;return void 0!==t&&t>0&&this.referenceFrame.bpPerPixel*this.$viewport.width()>t}return!0})()){if(this.canvas&&(de(this.canvas).remove(),this.canvas=void 0),this.trackView.track.autoHeight){const t=this.trackView.minHeight||0;this.setContentHeight(t)}return this.$zoomInNotice&&this.$zoomInNotice.show(),!1}return this.$zoomInNotice&&this.$zoomInNotice.hide(),!0}shift(){const t=this.referenceFrame;if(this.canvas&&this.canvas._data&&this.canvas._data.chr===this.referenceFrame.chr&&this.canvas._data.bpPerPixel===t.bpPerPixel){const e=Math.round((this.canvas._data.startBP-t.start)/t.bpPerPixel);this.canvas.style.left=e+"px"}}async loadFeatures(){const t=this.referenceFrame,e=t.chr,n=this.browser.genome.getChromosome(e).bpLength,r=this.$content.width()*t.bpPerPixel,i=Math.floor(Math.max(0,t.start-r)),o=Math.ceil(Math.min(n,t.start+r+r));if(!this.loading||this.loading.start!==i||this.loading.end!==o){this.loading={start:i,end:o},this.startSpinner();try{const n=this.trackView.track,r=await this.getFeatures(n,e,i,o,t.bpPerPixel);let c=[];const l=(s=this.browser.roi,a=n.roi,s&&a?s.concat(a):s||a);if(l)for(let n of l){const r=await n.getFeatures(e,i,o,t.bpPerPixel);c.push({track:n,features:r})}const h=n&&("wig"===n.type||"merged"===n.type);return this.featureCache=new ca(e,i,o,t.bpPerPixel,r,c,h),this.loading=!1,this.hideMessage(),this.stopSpinner(),this.featureCache}catch(t){this.trackView&&!0!==this.trackView.disposed&&(this.showMessage("Error loading track data"),Qo.presentAlert(t),console.error(t))}finally{this.loading=!1,this.stopSpinner()}var s,a}}repaintDimensions(){const t=na.isWholeGenomeView(this.referenceFrame.chr),e=t?this.$viewport.width():3*this.$viewport.width(),n=this.referenceFrame.bpPerPixel;return{startBP:this.referenceFrame.start-(t?0:e/3*n),endBP:this.referenceFrame.end+(t?0:e/3*n),pixelWidth:e}}repaint(){if(void 0===this.featureCache)return;let{features:t,roiFeatures:e}=this.featureCache;na.isWholeGenomeView(this.referenceFrame.chr);const{startBP:n,endBP:r,pixelWidth:i}=this.repaintDimensions(),o=this.$viewport.height(),s=this.getContentHeight(),a=e?Math.max(s,o):s,c=Math.min(a,3*o);if(0===i||0===c)return void(this.canvas&&de(this.canvas).remove());const l=Math.max(0,-this.$content.position().top-o),h=this.referenceFrame.bpPerPixel,u=Math.round((n-this.referenceFrame.start)/h),f=de('<canvas class="igv-canvas">').get(0);f.style.width=i+"px",f.style.height=c+"px",f.style.left=u+"px",f.style.top=l+"px";const d="FILL"===this.trackView.track.displayMode||!1!==this.trackView.track.supportHiDPI?window.devicePixelRatio:1;f.width=d*i,f.height=d*c;const p=f.getContext("2d");p.scale(d,d),p.translate(0,-l);const g={context:p,pixelXOffset:u,pixelWidth:i,pixelHeight:c,pixelTop:l,bpStart:n,bpEnd:r,bpPerPixel:h,referenceFrame:this.referenceFrame,selection:this.selection,viewport:this,viewportWidth:this.$viewport.width()};this.draw(g,t,e),this.featureCache.canvasTop=l,this.featureCache.height=c,this.canvas&&de(this.canvas).remove(),f._data={chr:this.featureCache.chr,bpPerPixel:h,startBP:n,endBP:r,pixelHeight:c,pixelTop:l},this.canvas=f,this.$content.append(de(f))}draw(t,e,n){if(e&&(t.features=e,this.trackView.track.draw(t)),n)for(let e of n)t.features=e.features,e.track.draw(t)}containsPosition(t,e){return this.referenceFrame.chr===t&&e>=this.referenceFrame.start&&e<=this.referenceFrame.calculateEnd(this.getWidth())}isLoading(){return this.loading}savePNG(){if(!this.canvas)return;const t=this.featureCache,e=t?t.canvasTop:0,n=window.devicePixelRatio,r=this.$viewport.width()*n,i=this.$viewport.height()*n,o=-de(this.canvas).position().left*n,s=(-this.$content.position().top-e)*n,a=this.canvas.getContext("2d").getImageData(o,s,r,i),c=document.createElement("canvas"),l=c.getContext("2d");c.width=a.width,c.height=a.height,l.putImageData(a,0,0);qe((this.$trackLabel.text()?this.$trackLabel.text():"image")+".png",c.toDataURL("image/png"))}saveSVG(){const{width:t,height:e}=this.$viewport.get(0).getBoundingClientRect(),n={width:t,height:e,viewbox:{x:0,y:-this.$content.position().top,width:t,height:e}},r=new js(n),i=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_referenceFrame_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}_guid_${ve()}`;this.drawSVGWithContext(r,t,e,i,0,0,0);const o=r.getSerializedSvg(!0);qe(`${i}.svg`,URL.createObjectURL(new Blob([o],{type:"application/octet-stream"})))}renderSVGContext(t,{deltaX:e,deltaY:n}){if(this.$zoomInNotice&&this.$zoomInNotice.is(":visible"))return;const r=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_referenceFrame_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}_guid_${ve()}`,{top:i}=this.$content.position(),{width:o,height:s}=this.$viewport.get(0).getBoundingClientRect();if(this.drawSVGWithContext(t,o,s,r,e,n+i,-i),this.$trackLabel&&!0===this.browser.trackLabelsVisible){const{x:r,y:i,width:o,height:s}=((t,e)=>{const{x:n,y:r,width:i,height:o}=t.getBoundingClientRect(),{x:s,y:a,width:c,height:l}=e.getBoundingClientRect();return{x:s-n,y:a-r,width:c,height:l}})(this.$viewport.get(0),this.$trackLabel.get(0));this.renderTrackLabelSVG(t,e+r,n+i,o,s)}}renderTrackLabelSVG(t,e,n,r,i){const o=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_track_label_guid_${ve()}`;t.saveWithTranslationAndClipRect(o,e,n,r,i,0),t.fillStyle="white",t.fillRect(0,0,r,i),t.font="12px Arial",t.fillStyle="rgb(68, 68, 68)";const{width:s}=t.measureText(this.$trackLabel.text()),a=.25*(r-s),c=.7*(i-12);t.fillText(this.$trackLabel.text(),a,i-c),t.strokeStyle="rgb(68, 68, 68)",t.strokeRect(0,0,r,i),t.restore()}drawSVGWithContext(t,e,n,r,i,o,s){t.saveWithTranslationAndClipRect(r,i,o,e,n,s);let{start:a,bpPerPixel:c}=this.referenceFrame;const l={context:t,viewport:this,referenceFrame:this.referenceFrame,top:s,pixelTop:s,pixelWidth:e,pixelHeight:n,bpStart:a,bpEnd:a+e*c,bpPerPixel:c,viewportWidth:e,selection:this.selection},h=this.featureCache?this.featureCache.features:[],u=this.featureCache?this.featureCache.roiFeatures:void 0;this.draw(l,h,u),t.restore()}get cachedFeatures(){return this.featureCache?this.featureCache.features:[]}async getFeatures(t,e,n,r,i){if(this.featureCache&&this.featureCache.containsRange(e,n,r,i))return this.featureCache.features;if("function"==typeof t.getFeatures){const o=await t.getFeatures(e,n,r,i,this);return this.checkContentHeight(o),o}}needsRepaint(){if(!this.canvas)return!0;const t=this.canvas._data;return!t||this.referenceFrame.start<t.startBP||this.referenceFrame.end>t.endBP||this.referenceFrame.chr!==t.chr||this.referenceFrame.bpPerPixel!=t.bpPerPixel}needsReload(){if(!this.featureCache)return!0;const t=this.referenceFrame,e=this.referenceFrame.chr,n=t.bpPerPixel,{startBP:r,endBP:i}=this.repaintDimensions();return!this.featureCache.containsRange(e,r,i,n)}createZoomInNotice(t){const e=de("<div>",{class:"igv-zoom-in-notice-container"});t.append(e);const n=de("<div>");return e.append(n),n.text("Zoom in to see features"),e.hide(),e}viewIsReady(){return this.browser&&this.browser.referenceFrameList&&this.referenceFrame}addMouseHandlers(){const t=this.$viewport.get(0);this.addViewportContextMenuHandler(t);const e=t=>{this.enableClick=!0,this.browser.mouseDownOnViewport(t,this),me(t)};t.addEventListener("mousedown",e),t.addEventListener("touchstart",e);const n=t=>{this.browser.dragObject||this.browser.isScrolling?(this.browser.cancelTrackPan(),this.enableClick=!1):(this.browser.cancelTrackPan(),this.browser.endTrackDrag())};t.addEventListener("mouseup",n),t.addEventListener("touchend",n),this.addViewportClickHandler(this.$viewport.get(0)),this.trackView.track.name&&"sequence"!==this.trackView.track.config.type&&this.addTrackLabelClickHandler(this.$trackLabel.get(0))}addViewportContextMenuHandler(t){t.addEventListener("contextmenu",(t=>{if(this.browser.dragObject)return!1;const e=aa(t,this);if(void 0===e)return!1;t.preventDefault();let n=[];if("function"==typeof this.trackView.track.contextMenuItemList){const t=this.trackView.track.contextMenuItemList(e);t&&(n=t)}n.length>0&&n.push({label:de("<HR>")}),n.push({label:"Save Image (PNG)",click:()=>this.savePNG()}),n.push({label:"Save Image (SVG)",click:()=>this.saveSVG()}),this.browser.menuPopup.presentTrackContextMenu(t,n)}))}addViewportClickHandler(t){t.addEventListener("click",(t=>{if(this.enableClick&&this.canvas){if(3===t.which||t.ctrlKey)return;if(de(".igv-popover").hide(),this.browser.dragObject||this.browser.isScrolling)return;t.preventDefault();const e=be(t,this.$viewport.get(0)).x,n=be(t,this.canvas).x,r=this.referenceFrame,i=Math.floor(r.start+r.toBP(n)),o=Date.now();if(o-oa<this.browser.constants.doubleClickDelay){ia&&(window.clearTimeout(ia),ia=void 0);const t=Math.round(r.start+r.toBP(e));let n;if("all"===this.referenceFrame.chr.toLowerCase()){const e=this.browser.genome.getChromosomeCoordinate(t).chr;if(1===this.browser.referenceFrameList.length)n=e;else{const t=this.browser.referenceFrameList.map((({locusSearchString:t})=>t));t[this.browser.referenceFrameList.indexOf(this.referenceFrame)]=e,n=t.join(" ")}this.browser.search(n)}else this.browser.zoomWithScaleFactor(.5,t,this.referenceFrame)}else t.shiftKey&&"function"==typeof this.trackView.track.shiftClick?this.trackView.track.shiftClick(i,t):"function"==typeof this.trackView.track.popupData&&(ia=setTimeout((()=>{const e=function(t,e){const n=aa(t,e);if(void 0===n)return;let r=e.trackView.track;const i=r.popupData(n),o=e.browser.fireEvent("trackclick",[r,i]);let s;void 0===o||!0===o?i&&i.length>0&&(s=i.map((t=>{if(t.name){const e=`<span>${t.name}</span>&nbsp&nbsp&nbsp${t.value}`;return`<div title="${t.value}">${e}</div>`}return"<hr>"===t?t:t.html?t.html:`<div title="${t}">${t}</div>`})).join("")):"string"==typeof o&&(s=o);return s}(t,this);e&&(this.popover&&this.popover.dispose(),this.popover=new os(this.browser.columnContainer),this.popover.presentContentWithEvent(t,e)),window.clearTimeout(ia),ia=void 0}),this.browser.constants.doubleClickDelay));oa=o}}))}addTrackLabelClickHandler(t){t.addEventListener("click",(t=>{t.stopPropagation();const{track:e}=this.trackView;let n;"function"==typeof e.description?n=e.description():e.description&&(n=`<div>${e.description}</div>`),n&&(this.popover&&this.popover.dispose(),this.popover=new os(this.browser.columnContainer,e.name||""),this.popover.presentContentWithEvent(t,n))}))}}function aa(t,e){const n=e.referenceFrame,r=be(t,e.contentDiv),i=be(t,e.canvas),o=n.start+n.toBP(r.x);return{event:t,viewport:e,referenceFrame:n,genomicLocation:o,x:r.x,y:r.y,canvasX:i.x,canvasY:i.y}}class ca{constructor(t,e,n,r,i,o,s){this.chr=t,this.startBP=e,this.endBP=n,this.bpPerPixel=r,this.features=i,this.roiFeatures=o,this.multiresolution=s}containsRange(t,e,n,r){const i=this.multiresolution?this.bpPerPixel/r:1;return e>=this.startBP&&n<=this.endBP&&t===this.chr&&i>.5&&i<2}overlapsRange(t,e,n){return this.chr===t&&n>=this.startBP&&e<=this.endBP}}class la{constructor(t){this.rulerSweeper=pe({class:"igv-ruler-sweeper"}),t.contentDiv.appendChild(this.rulerSweeper),this.rulerViewport=t,this.isMouseHandlers=void 0,this.addBrowserObserver()}addBrowserObserver(){this.boundObserverHandler=function(){this.rulerViewport.referenceFrame&&(na.isWholeGenomeView(this.rulerViewport.referenceFrame.chr)?this.removeMouseHandlers():this.addMouseHandlers())}.bind(this),this.rulerViewport.browser.on("locuschange",this.boundObserverHandler)}removeBrowserObserver(){this.rulerViewport.browser.off("locuschange",this.boundObserverHandler)}addMouseHandlers(){if(!0===this.isMouseHandlers)return;let t,e,n,r,i,o;this.boundContentMouseDownHandler=function(o){t=!0,e=!0;const{x:s}=be(o,this.rulerViewport.contentDiv);r=n=s,i=1,this.rulerSweeper.style.display="block",this.rulerSweeper.style.left=`${r}px`,this.rulerSweeper.style.width=`${i}px`}.bind(this),this.rulerViewport.contentDiv.addEventListener("mousedown",this.boundContentMouseDownHandler),this.boundDocumentMouseMoveHandler=function(s){let a;if(t&&e){const{x:t}=be(s,this.rulerViewport.contentDiv);a=Math.max(Math.min(t,this.rulerViewport.contentDiv.clientWidth),0),o=a-n,i=Math.abs(o),this.rulerSweeper.style.width=`${i}px`,o<0&&(r=n+o,this.rulerSweeper.style.left=`${r}px`)}}.bind(this),document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseUpHandler=function(n){let o;if(!0===t&&!0===e&&(t=e=void 0,this.rulerSweeper.style.display="none",i>1)){o={start:ha(this.rulerViewport.referenceFrame,r),end:ha(this.rulerViewport.referenceFrame,r+i)},vs(this.rulerViewport.browser.genome.getChromosome(this.rulerViewport.referenceFrame.chr).bpLength,o,this.rulerViewport.browser.minimumBases());const t=Math.round(o.start),e=Math.round(o.end);this.rulerViewport.referenceFrame.bpPerPixel=(e-t)/this.rulerViewport.contentDiv.clientWidth,this.rulerViewport.referenceFrame.start=t,this.rulerViewport.referenceFrame.end=e,this.rulerViewport.browser.updateViews()}}.bind(this),document.addEventListener("mouseup",this.boundDocumentMouseUpHandler),this.isMouseHandlers=!0}removeMouseHandlers(){this.rulerViewport.contentDiv.removeEventListener("mousedown",this.boundContentMouseDownHandler),document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.removeEventListener("mouseup",this.boundDocumentMouseUpHandler),this.isMouseHandlers=!1}dispose(){this.removeBrowserObserver(),this.removeMouseHandlers(),this.rulerSweeper.remove()}}function ha(t,e){return t.start+e*t.bpPerPixel}class ua{constructor(t){this.paired=!0,this.firstAlignment=t,this.chr=t.chr,this.readName=t.readName,t.start<t.mate.position?(this.start=t.start,this.scStart=t.scStart,this.connectingStart=t.start+t.lengthOnRef,this.connectingEnd=t.mate.position):(this.start=t.mate.position,this.scStart=this.start,this.connectingStart=t.mate.position,this.connectingEnd=t.start),this.end=Math.max(t.mate.position,t.start+t.lengthOnRef),this.lengthOnRef=this.end-this.start;let e=Math.max(this.end,t.scStart+t.scLengthOnRef);this.scLengthOnRef=e-this.scStart}setSecondAlignment(t){this.secondAlignment=t;const e=this.firstAlignment;t.start>e.start?this.connectingEnd=t.start:this.connectingStart=t.start+t.lengthOnRef,this.start=Math.min(e.start,t.start),this.end=Math.max(e.start+e.lengthOnRef,t.start+t.lengthOnRef),this.lengthOnRef=this.end-this.start,this.scStart=Math.min(e.scStart,t.scStart);const n=Math.max(e.scStart+e.scLengthOnRef,t.scStart+t.scLengthOnRef);this.scLengthOnRef=n-this.scStart}containsLocation(t,e){const n=e?this.scStart:this.start,r=e?this.scLengthOnRef:this.lengthOnRef;return t>=n&&t<=n+r}alignmentContaining(t,e){return this.firstAlignment.containsLocation(t,e)?this.firstAlignment:this.secondAlignment&&this.secondAlignment.containsLocation(t,e)?this.secondAlignment:void 0}popupData(t){let e=this.firstAlignment.popupData(t);return this.secondAlignment&&(e.push("-------------------------------"),e=e.concat(this.secondAlignment.popupData(t))),e}isPaired(){return!0}isMateMapped(){return!0}isProperPair(){return this.firstAlignment.isProperPair()}get fragmentLength(){return Math.abs(this.firstAlignment.fragmentLength)}firstOfPairStrand(){return this.firstAlignment.isFirstOfPair()?this.firstAlignment.strand:this.secondAlignment&&this.secondAlignment.isFirstOfPair()?this.secondAlignment.strand:this.firstAlignment.mate.strand}hasTag(t){return this.firstAlignment.hasTag(t)||this.secondAlignment&&this.secondAlignment.hasTag(t)}}const fa=ke,da=function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)};class pa{constructor(){this.alignments=[],this.score=void 0}findAlignment(t){const e=(t,e)=>e>=t.start&&e<t.start+t.lengthOnRef;let n;for(let r=0;r<this.alignments.length;r++){const i=this.alignments[r];if(t>=i.start&&t<i.start+i.lengthOnRef){i.paired?i.firstAlignment&&e(i.firstAlignment,t)?n=i.firstAlignment:i.secondAlignment&&e(i.secondAlignment,t)&&(n=i.secondAlignment):n=i;break}}return n}updateScore(t,e){this.score=this.calculateScore(t,e)}calculateScore({position:t,option:e,direction:n,tag:r},i){e||(e="BASE");const o=this.findAlignment(t);if(void 0===o)return Number.MAX_VALUE*(n?1:-1);let s;switch(e){case"NUCLEOTIDE":case"BASE":return function(t,e,n){let r;const i=Math.floor(n)-e.start;i<e.sequence.length&&(r=e.sequence.charAt(i));if(!r)return 0;const o=t.readBaseAt(n),s=t.readBaseQualityAt(n),a=e.coverageMap,c=Math.floor(n-a.bpStart),l=a.coverage[c];let h=0;if(t.insertions)for(let e of t.insertions)e.start===n&&(h=-l.ins);if(o)if(r=r.toUpperCase(),"N"===o&&0===h)h=2;else if(r!==o&&"="!==o||0!==h){if("X"===o||r!==o){h-=l["pos"+o]+l["neg"+o]+s/1e3}}else h=4-s/1e3;else{const t=l.del;t>0?h-=t:0===h&&(h=1)}return h}(o,i,t);case"STRAND":return o.strand?1:-1;case"START":return o.start;case"TAG":{const t=o.tags()[r];return void 0!==t?fa(t)?da(t):t:Number.MAX_VALUE}case"READ_NAME":return da(o.readName);case"INSERT_SIZE":return-Math.abs(o.fragmentLength);case"GAP_SIZE":return-o.gapSizeAt(t);case"MATE_CHR":return s=o.mate,s?s.chr===o.chr?Number.MAX_VALUE-1:da(s.chr):Number.MAX_VALUE;case"MQ":return void 0===o.mq?Number.MAX_VALUE:-o.mq;default:return Number.MAX_VALUE}}}function ga(t){return t.isPaired()&&t.mate&&t.isMateMapped()&&t.chr===t.mate.chr&&(t.isFirstOfPair()||t.isSecondOfPair())&&!(t.isSecondary()||t.isSupplementary())}function ma(t){const e=[];for(let n of t)for(let t of n.alignments)t instanceof ua?(t.firstAlignment&&e.push(t.firstAlignment),t.secondAlignment&&e.push(t.secondAlignment)):e.push(t);return e}function va(t,e,n,r){if(t){if(0===t.length)return[];{t.sort((function(t,e){return r?t.scStart-e.scStart:t.start-e.start}));const i=t[0];let o=Math.max(e,r?i.scStart:i.start),s=o;const a=[];for(let e of t){const t=r?e.scStart:e.start,n=Math.max(0,t-o);void 0===a[n]&&(a[n]=[]),a[n].push(e)}let c=0,l=0;const h=[],u=2;try{for(;c<t.length;){const t=new pa;for(;s<=n;){let e,i;for(;!e&&s<=n;)i=s-o,void 0===a[i]?++s:e=a[i];if(!e)break;const l=e.pop();0===e.length&&(a[i]=void 0),t.alignments.push(l),s=r?l.scStart+l.scLengthOnRef+u:l.start+l.lengthOnRef+u,++c}if(t.alignments.length>0&&h.push(t),s=o,c===l)break;l=c}}catch(t){throw console.error(t),t}return h}}}class ba{constructor(t,e,n,{samplingWindowSize:r,samplingDepth:i,pairsSupported:o,alleleFreqThreshold:s}){this.chr=t,this.start=Math.floor(e),this.end=Math.ceil(n),this.length=n-e,this.alleleFreqThreshold=void 0===s?.2:s,this.coverageMap=new ya(t,e,n,this.alleleFreqThreshold),this.alignments=[],this.downsampledIntervals=[],this.samplingWindowSize=void 0===r?100:r,this.samplingDepth=void 0===i?1e3:i,this.pairsSupported=void 0===o||o,this.paired=!1,this.pairsCache={},this.downsampledReads=new Set,this.currentBucket=new wa(this.start,this.start+this.samplingWindowSize,this),this.filter=function(t){return t.isMapped()&&!t.isFailsVendorQualityCheck()}}push(t){!1!==this.filter(t)&&(this.coverageMap.incCounts(t),this.pairsSupported&&this.downsampledReads.has(t.readName)||(t.start>=this.currentBucket.end&&(this.finishBucket(),this.currentBucket=new wa(t.start,t.start+this.samplingWindowSize,this)),this.currentBucket.addAlignment(t)))}forEach(t){this.alignments.forEach(t)}finish(){void 0!==this.currentBucket&&this.finishBucket(),this.alignments.sort((function(t,e){return t.start-e.start})),this.pairsCache=void 0,this.downsampledReads=void 0}contains(t,e,n){return this.chr===t&&this.start<=e&&this.end>=n}hasDownsampledIntervals(){return this.downsampledIntervals&&this.downsampledIntervals.length>0}finishBucket(){this.alignments=this.alignments.concat(this.currentBucket.alignments),this.currentBucket.downsampledCount>0&&this.downsampledIntervals.push(new ka(this.currentBucket.start,this.currentBucket.end,this.currentBucket.downsampledCount)),this.paired=this.paired||this.currentBucket.paired}setViewAsPairs(t){let e;e=t?function(t){const e={},n=[];for(let r of t)for(let t of r.alignments)if(ga(t)){let r=e[t.readName];r?(r.setSecondAlignment(t),e[t.readName]=void 0):(r=new ua(t),e[t.readName]=r,n.push(r))}else n.push(t);return n}(this.packedAlignmentRows):ma(this.packedAlignmentRows),this.packedAlignmentRows=va(e,this.start,this.end)}setShowSoftClips(t){const e=this.allAlignments();this.packedAlignmentRows=va(e,this.start,this.end,t)}repack(t,e){const n=this.allAlignments();this.packedAlignmentRows=va(n,this.start,this.end,e)}allAlignments(){const t=[];for(let e of this.packedAlignmentRows)for(let n of e.alignments)t.push(n);return t}getMax(t,e){return this.coverageMap.getMax(t,e)}}class wa{constructor(t,e,n){this.start=t,this.end=e,this.alignments=[],this.downsampledCount=0,this.samplingDepth=n.samplingDepth,this.pairsSupported=n.pairsSupported,this.downsampledReads=n.downsampledReads,this.pairsCache=n.pairsCache}addAlignment(t){var e,n,r;if(this.pairsSupported&&ga(t)&&(r=this.pairsCache[t.readName]))return r.setSecondAlignment(t),void(this.pairsCache[t.readName]=void 0);this.alignments.length<this.samplingDepth?this.pairsSupported&&ga(t)?(r=new ua(t),this.paired=!0,this.pairsCache[t.readName]=r,this.alignments.push(r)):this.alignments.push(t):((e=Math.floor(Math.random()*(this.samplingDepth+this.downsampledCount-1)))<this.samplingDepth?(n=this.alignments[e],this.pairsSupported&&ga(t)?(void 0!==this.pairsCache[n.readName]&&(this.pairsCache[n.readName]=void 0),r=new ua(t),this.paired=!0,this.pairsCache[t.readName]=r,this.alignments[e]=r):this.alignments[e]=t,this.downsampledReads.add(n.readName)):this.downsampledReads.add(t.readName),this.downsampledCount++)}}class ya{constructor(t,e,n,r){this.chr=t,this.bpStart=e,this.length=n-e,this.coverage=new Array(this.length),this.maximum=0,this.threshold=r,this.qualityWeight=!0}getMax(t,e){let n=0;const r=this.coverage.length;for(let i=0;i<r;i++){const r=this.bpStart+i;if(r>e)break;const o=this.coverage[i];r>=t&&o&&(n=Math.max(n,o.total))}return n}incCounts(t){var e=this;if(void 0===t.blocks?n(t):t.blocks.forEach((function(t){n(t)})),t.gaps)for(let n of t.gaps)if("D"===n.type){const t=n.start-e.bpStart;for(let r=t;r<t+n.len;r++)r<0||(this.coverage[r]||(this.coverage[r]=new xa(e.threshold)),this.coverage[r].del++)}if(t.insertions)for(let n of t.insertions){const t=n.start-this.bpStart;t<0||(this.coverage[t]||(this.coverage[t]=new xa(e.threshold)),this.coverage[t].ins++)}function n(n){if("S"===n.type)return;const r=t.seq,i=t.qual,o=n.seqOffset;for(let s=n.start-e.bpStart,a=0;a<n.len;s++,a++){e.coverage[s]||(e.coverage[s]=new xa(e.threshold));const n=null==r?"N":r.charAt(o+a),c=t.strand?"pos"+n:"neg"+n,l=i&&o+a<i.length?i[o+a]:30;e.coverage[s][c]+=1,e.coverage[s]["qual"+n]+=l,e.coverage[s].total+=1,e.coverage[s].qual+=l,e.maximum=Math.max(e.coverage[s].total,e.maximum)}}}}class xa{constructor(t){this.qualityWeight=!0,this.posA=0,this.negA=0,this.posT=0,this.negT=0,this.posC=0,this.negC=0,this.posG=0,this.negG=0,this.posN=0,this.negN=0,this.pos=0,this.neg=0,this.qualA=0,this.qualT=0,this.qualC=0,this.qualG=0,this.qualN=0,this.qual=0,this.total=0,this.del=0,this.ins=0,this.threshold=t}isMismatch(t){const e=this.threshold*(this.qualityWeight&&this.qual?this.qual:this.total);let n=0;for(let e of["A","T","C","G"])e!==t&&(n+=this.qualityWeight&&this.qual?this["qual"+e]:this["pos"+e]+this["neg"+e]);return n>=e}}class ka{constructor(t,e,n){this.start=t,this.end=e,this.counts=n}popupData(t){return[{name:"start",value:this.start+1},{name:"end",value:this.end},{name:"# downsampled:",value:this.counts}]}}class _a{constructor(t){const e=t.split(",");this.chr=e[0],this.start=parseInt(e[1]),this.strand=e[2].charAt(0),this.mapQ=parseInt(e[4]),this.numMismatches=parseInt(e[5]),this.lenOnRef=za.computeLengthOnReference(e[3])}printString(){return this.chr+":"+_e(this.start)+"-"+_e(this.start+this.lenOnRef)+" ("+this.strand+") = "+_e(this.lenOnRef)+"bp @MAPQ: "+this.mapQ+" NM: "+this.numMismatches}}function Sa(t){return t.split(";").filter((t=>t.length>0)).map((t=>new _a(t)))}const Ca={c:1,C:1,s:2,S:2,i:4,I:4,f:4};class Ea{constructor(){this.hidden=!1}isMapped(){return 0==(4&this.flags)}isPaired(){return 0!=(1&this.flags)}isProperPair(){return 0!=(2&this.flags)}isFirstOfPair(){return 0!=(64&this.flags)}isSecondOfPair(){return 0!=(128&this.flags)}isSecondary(){return 0!=(256&this.flags)}isSupplementary(){return 0!=(2048&this.flags)}isFailsVendorQualityCheck(){return 0!=(512&this.flags)}isDuplicate(){return 0!=(1024&this.flags)}isMateMapped(){return 0==(8&this.flags)}isNegativeStrand(){return 0!=(16&this.flags)}isMateNegativeStrand(){return 0!=(32&this.flags)}hasTag(t){return(this.tagDict||Ta(this.tagBA)).hasOwnProperty(t)}tags(){return this.tagDict||(this.tagBA?(this.tagDict=Ta(this.tagBA),this.tagBA=void 0):this.tagDict={}),this.tagDict}containsLocation(t,e){const n=e?this.scStart:this.start,r=e?this.scLengthOnRef:this.lengthOnRef;return t>=n&&t<=n+r}popupData(t){const e=[];if(t=Math.floor(t),this.insertions){const r=this.seq;for(let i of this.insertions){var n=i.start;if(t===n||t===n-1)return e.push({name:"Insertion",value:r.substr(i.seqOffset,i.len)}),e.push({name:"Location",value:n}),e}}e.push({name:"Read Name",value:this.readName}),e.push("<hr/>"),e.push({name:"Alignment Start",value:_e(1+this.start),borderTop:!0}),e.push({name:"Read Strand",value:!0===this.strand?"(+)":"(-)",borderTop:!0});let r=this.cigar;if(r&&r.length>50){const t=25;r=`${r.substring(0,t-2)} ... ${r.substring(r.length-t+2)}`}e.push({name:"Cigar",value:r}),e.push({name:"Mapping Quality",value:this.mq}),e.push({name:"Secondary",value:s(this.isSecondary())}),e.push({name:"Supplementary",value:s(this.isSupplementary())}),e.push({name:"Duplicate",value:s(this.isDuplicate())}),e.push({name:"Failed QC",value:s(this.isFailsVendorQualityCheck())}),this.isPaired()&&(e.push("<hr/>"),e.push({name:"First in Pair",value:!this.isSecondOfPair(),borderTop:!0}),e.push({name:"Mate is Mapped",value:s(this.isMateMapped())}),this.pairOrientation&&e.push({name:"Pair Orientation",value:this.pairOrientation}),this.isMateMapped()&&(e.push({name:"Mate Chromosome",value:this.mate.chr}),e.push({name:"Mate Start",value:this.mate.position+1}),e.push({name:"Mate Strand",value:!0===this.mate.strand?"(+)":"(-)"}),e.push({name:"Insert Size",value:this.fragmentLength})));const i=this.tags();if(i.hasOwnProperty("SA")){e.push("<hr/>"),e.push({name:"Supplementary Alignments",value:""});const t=Sa(i.SA);if(t){e.push("<ul>");for(let n of t)e.push(`<li>${n.printString()}</li>`);e.push("</ul>")}}const o=new Set(["SA","MD"]);e.push("<hr/>");for(let t in i)o.has(t)||e.push({name:t,value:i[t]});return e.push({name:"Hidden Tags",value:"SA, MD"}),e.push("<hr/>"),e.push({name:"Genomic Location: ",value:_e(1+t)}),e.push({name:"Read Base:",value:this.readBaseAt(t)}),e.push({name:"Base Quality:",value:this.readBaseQualityAt(t)}),e;function s(t){return t?"Yes":"No"}}readBaseAt(t){const e=Aa(this.blocks,t);if(e){if("*"===this.seq)return"*";{const n=e.seqIndexAt(t);return this.seq[n]}}}readBaseQualityAt(t){const e=Aa(this.blocks,t);if(e){if("*"===this.qual)return 30;{const n=e.seqIndexAt(t);return n>=0&&this.qual&&n<this.qual.length?this.qual[n]:30}}}gapSizeAt(t){if(this.gaps)for(let e of this.gaps)if(t>=e.start&&t<e.start+e.len)return e.len;return 0}}function Aa(t,e){for(let n=0;n<t.length;n++){const r=t[n];if(e>=r.start&&e<r.start+r.len)return r}}function Ta(t){let e=0;const n=t.length,r={};for(;e<n;){const n=String.fromCharCode(t[e])+String.fromCharCode(t[e+1]);e+=2;const o=String.fromCharCode(t[e++]);let s;if("A"===o)s=String.fromCharCode(t[e]),e++;else if("i"===o||"I"===o)s=La(t,e),e+=4;else if("c"===o)s=Ia(t,e),e++;else if("C"===o)s=Na(t,e),e++;else if("s"===o||"S"===o)s=Ma(t,e),e+=2;else if("f"===o)s=Ra(t,e),e+=4;else if("Z"===o)for(s="";;){var i=t[e++];if(0===i)break;s+=String.fromCharCode(i)}else{if("B"!==o){s="Error unknown type: "+o,r[n]=s;break}{const i=String.fromCharCode(t[e++]);let o=Ca[i];if(void 0===o){r[n]=`Error: unknown element type '${i}'`;break}e+=4+La(t,e)*o,s="[not shown]"}}r[n]=s}return r}function La(t,e){return t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function Ma(t,e){return t[e+1]<<8|t[e]}function Ra(t,e){return new DataView(t.buffer).getFloat32(e)}function Ia(t,e){return new DataView(t.buffer).getInt8(e)}function Na(t,e){return new DataView(t.buffer).getUint8(e)}class Pa{constructor(t){t&&Object.assign(this,t)}seqIndexAt(t){return Math.floor(t)-this.start+this.seqOffset}}class Oa{constructor(t){t||(t={}),this.vendorFailed=void 0===t.vendorFailed||t.vendorFailed,this.duplicates=void 0===t.duplicates||t.duplicates,this.secondary=t.secondary||!1,this.supplementary=t.supplementary||!1,this.mqThreshold=void 0===t.mqThreshold?0:t.mqThreshold,t.readgroups&&(this.readgroups=new Set(t.readgroups))}pass(t){if(this.vendorFailed&&t.isFailsVendorQualityCheck())return!1;if(this.duplicates&&t.isDuplicate())return!1;if(this.secondary&&t.isSecondary())return!1;if(this.supplementary&&t.isSupplementary())return!1;if(t.mq<this.mqThreshold)return!1;if(this.readgroups){var e=t.tags().RG;return this.readgroups.has(e)}return!0}}const Fa=["=","A","C","x","G","x","x","x","T","x","x","x","x","x","x","N"],Da=["M","I","D","N","S","H","P","=","X","?","?","?","?","?","?","?"],Ba=Va(new Uint8Array([66,65,77,1]),0),za={readHeader:function(t,e,n){return go.loadArrayBuffer(t,e).then((function(t){var e;return e=Wi(t),za.decodeBamHeader(e,n)}))},decodeBamHeader:function(t,e){var n,r,i,o,s;if((n=Va(t,0))!==Ba)throw new Error("BAM header errror: bad magic number. This could be caused by either a corrupt or missing file.");r=Va(t,4);for(var a=0;a<r;++a)String.fromCharCode(t[a+8]);var c=Va(t,r+8),l=r+12;for(i={},o=[],s={},a=0;a<c;++a){for(var h=Va(t,l),u="",f=0;f<h-1;++f)u+=String.fromCharCode(t[l+4+f]);Va(t,l+h+4),i[u]=a,o[a]=u,e&&(s[e.getChromosomeName(u)]=u),l=l+8+h}return{magicNumber:n,size:l,chrNames:o,chrToIndex:i,chrAliasTable:s}},bam_tag2cigar:function(t,e,n,r,i,o){function s(t){return"C"===t||"c"===t||"A"===t?1:"S"===t||"s"===t?2:"I"===t||"i"===t||"f"===t?4:0}if(1!==o.length||i.start<0)return!1;for(var a=n+(r+1>>1)+r;a+4<e;){if("CG"===String.fromCharCode(t[a])+String.fromCharCode(t[a+1]))break;var c=String.fromCharCode(t[a+2]);if("B"===c)a+=8+s(c=String.fromCharCode(t[a+3]))*Va(t,a+4);else if("Z"===c||"H"===c)for(a+=3;0!==t[a++];);else a+=3+s(c)}if(a>=e)return!1;if("B"!==String.fromCharCode(t[a+2])||"I"!==String.fromCharCode(t[a+3]))return!1;var l=Va(t,a+4),h=a+8;if(h+4*l>e)return!1;var u="",f=0;o.length=0,a=h;for(var d=0;d<l;++d,a+=4){var p=Va(t,a),g=p>>4,m=Da[15&p];"M"!==m&&"EQ"!==m&&"X"!==m&&"D"!==m&&"N"!==m&&"="!==m||(f+=g),u=u+g+m,o.push({len:g,ltr:m})}return i.cigar=u,i.lengthOnRef=f,!0},decodeBamRecords:function(t,e,n,r,i,o,s,a){for(;e<t.length;){const f=e+Va(t,e)+4,d=new Ea,p=Va(t,e+4),g=Va(t,e+8);if(f>t.length)return;if(p<0){e=f;continue}if(void 0!==i&&(p>i||g>s))return!0;if(void 0!==i&&p<i){e=f;continue}const m=Va(t,e+12),v=(65280&m)>>8,b=255&m,w=Va(t,e+16),y=(4294901760&w)>>16,x=65535&w,k=Va(t,e+20),_=Va(t,e+24),S=Va(t,e+28),C=Va(t,e+32);let E=[];for(let n=0;n<b-1;++n)E.push(String.fromCharCode(t[e+36+n]));E=E.join("");let A=0,T="",L=e+36+b;const M=[];let R;for(let e=0;e<x;++e){var c=Va(t,L),l=c>>4,h=Da[15&c];"M"!==h&&"EQ"!==h&&"X"!==h&&"D"!==h&&"N"!==h&&"="!==h||(A+=l),T=T+l+h,L+=4,R={len:l,ltr:h},M.push(R)}if(d.chr=r[p],d.start=g,d.flags=y,d.strand=!(16&y),d.readName=E,d.cigar=T,d.lengthOnRef=A,d.fragmentLength=C,d.mq=v,za.bam_tag2cigar(t,f,L,k,d,M),d.end=d.start+d.lengthOnRef,d.end<o){e=f;continue}let I=[];const N=k+1>>1;for(let e=0;e<N;++e){var u=t[L+e];I.push(Fa[(240&u)>>4]),I.push(Fa[15&u])}I=I.slice(0,k).join(""),L+=N;const P=[];for(let e=0;e<k;++e)P.push(t[L+e]);L+=k,_>=0&&(d.mate={chr:r[_],position:S,strand:!(32&y)}),d.seq=I,d.qual=P,d.tagBA=new Uint8Array(t.buffer.slice(L,f)),this.setPairOrientation(d),(void 0===a||a.pass(d))&&(Ha(d,M),n.push(d)),e=f}},decodeSamRecords:function(t,e,n,r,i,o){var s,a,c,l,h,u,f,d,p,g;for(l=(s=Se(t)).length,!1,a=0;a<l;a++)if(h=s[a].split("\t"),(p=new Ea).chr=h[2],p.start=Number.parseInt(h[3])-1,p.flags=Number.parseInt(h[1]),p.readName=h[0],p.strand=!(16&p.flags),p.mq=Number.parseInt(h[4]),p.cigar=h[5],p.fragmentLength=Number.parseInt(h[8]),p.seq=h[9],"*"!==p.chr&&p.isMapped()&&p.chr===n){if(p.start>i)break;if(d=0,(g=ja(p.cigar)).forEach((function(t){var e=t.len,n=t.ltr;"M"!==n&&"EQ"!==n&&"X"!==n&&"D"!==n&&"N"!==n&&"="!==n||(d+=e)})),p.lengthOnRef=d,!(p.start+d<r)){for(u=h[10],p.qual=[],c=0;c<u.length;c++)p.qual[c]=u.charCodeAt(c)-33;p.tagDict=h.length<11?{}:Ua(h.slice(11)),p.isMateMapped()&&(f=h[6],p.mate={chr:"="===f?p.chr:f,position:Number.parseInt(h[7]),strand:!(32&p.flags)}),this.setPairOrientation(p),(void 0===o||o.pass(p))&&(Ha(p,g),e.push(p))}}},setReaderDefaults:function(t,e){t.filter=new Oa(e.filter),e.readgroup&&(t.filter.readgroups=new Set([e.readgroup])),t.alleleFreqThreshold=void 0===e.alleleFreqThreshold?.2:e.alleleFreqThreshold,t.samplingWindowSize=void 0===e.samplingWindowSize?100:e.samplingWindowSize,t.samplingDepth=void 0===e.samplingDepth?500:e.samplingDepth,t.samplingDepth>1e4&&(console.log("Warning: attempt to set sampling depth > maximum value of 10000"),t.samplingDepth=1e4),e.viewAsPairs?t.pairsSupported=!0:t.pairsSupported=void 0===e.pairsSupported||e.pairsSupported},setPairOrientation:function(t){if(t.isMapped()&&t.mate&&t.isMateMapped()&&t.mate.chr===t.chr){var e=t.strand?"F":"R",n=t.mate,r=n.strand?"F":"R",i=" ",o=" ";t.isFirstOfPair()?(i="1",o="2"):t.isSecondOfPair()&&(i="2",o="1");var s=[],a=t.fragmentLength,c=t.end-t.start;if(0===a)a=(t.start<n.position?n.position+c:n.position-c)-t.start;a>0?(s[0]=e,s[1]=i,s[2]=r,s[3]=o):(s[2]=e,s[3]=i,s[0]=r,s[1]=o),t.pairOrientation=s.join("")}},computeLengthOnReference:function(t){let e=0,n="";for(let r=0;r<t.length;r++){const i=t.charCodeAt(r);if(i>47&&i<58)n+=t.charAt(r);else{switch(i){case 78:case 68:case 77:case 61:case 88:e+=parseInt(n.toString())}n=""}}return e}};function Ha(t,e){const n=[];let r,i,o=0,s=t.start;t.scStart=t.start,t.scLengthOnRef=t.lengthOnRef;for(let a of e){let e;switch(a.ltr){case"H":case"P":break;case"S":e=s,t.scLengthOnRef+=a.len,0===n.length&&(t.scStart-=a.len,e-=a.len),n.push(new Pa({start:e,seqOffset:o,len:a.len,type:"S"})),o+=a.len;break;case"N":case"D":void 0===i&&(i=[]),i.push({start:s,len:a.len,type:a.ltr}),s+=a.len;break;case"I":void 0===r&&(r=[]),r.push(new Pa({start:s,len:a.len,seqOffset:o,type:"I"})),o+=a.len;break;case"M":case"EQ":case"=":case"X":n.push(new Pa({start:s,seqOffset:o,len:a.len,type:"M"})),o+=a.len,s+=a.len;break;default:console.log("Error processing cigar element: "+a.len+a.ltr)}}t.blocks=n,t.insertions=r,t.gaps=i}function Va(t,e){return t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function ja(t){var e,n,r,i,o,s,a,c,l;for(e=[],n=[],o=null,i=t.length,r=0;r<i;r++)s=t.charAt(r),l=void 0,(l=s.charCodeAt(0))>=48&&l<=57?n.push(s):(a=s,c=Number.parseInt(n.join("")),n=[],null!==o&&o.ltr===a?o.len+=c:(o={len:c,ltr:a},e.push(o)));return e}function Ua(t){var e={};return t.forEach((function(t){var n=t.split(":");e[n[0]]=n[2]})),e}class qa{constructor(t,e){this.config=t,this.genome=e,this.bamPath=t.url,this.isDataUri=ys(t.url),za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(this.alignmentCache){const r=this.header,i=r.chrAliasTable.hasOwnProperty(t)?r.chrAliasTable[t]:t,o=this.alignmentCache.queryFeatures(i,e,n),s=new ba(t,e,n,this.config);for(let t of o)s.push(t);return s.finish(),s}if(this.isDataUri){const r=Wi(function(t){const e=t.split(","),n=e[0].split(":")[1];let r=e[1];r=n.indexOf("base64")>=0?atob(r):decodeURI(r);const i=new Uint8Array(r.length);for(var o=0;o<r.length;o++)i[o]=r.charCodeAt(o);return i}(this.bamPath).buffer);return this.parseAlignments(r),this.fetchAlignments(t,e,n)}{const r=Wi(await go.loadArrayBuffer(this.bamPath,gs(this.config)));return this.parseAlignments(r),this.fetchAlignments(t,e,n)}}parseAlignments(t){const e=[];this.header=za.decodeBamHeader(t),za.decodeBamRecords(t,this.header.size,e,this.header.chrNames),this.alignmentCache=new Mo(e,this.genome)}fetchAlignments(t,e,n){const r=this.header.chrAliasTable.hasOwnProperty(t)?this.header.chrAliasTable[t]:t,i=this.alignmentCache.queryFeatures(r,e,n),o=new ba(t,e,n,this.config);for(let t of i)o.push(t);return o.finish(),o}}class Wa{constructor(t,e){this.littleEndian=void 0===e||e,this.position=0,this.view=t,this.length=t.byteLength}available(){return this.length-this.position}remLength(){return this.length-this.position}hasNext(){return this.position<this.length-1}getByte(){var t=this.view.getUint8(this.position,this.littleEndian);return this.position++,t}getShort(){var t=this.view.getInt16(this.position,this.littleEndian);return this.position+=2,t}getUShort(){var t=this.view.getUint16(this.position,this.littleEndian);return this.position+=2,t}getInt(){var t=this.view.getInt32(this.position,this.littleEndian);return this.position+=4,t}getUInt(){var t=this.view.getUint32(this.position,this.littleEndian);return this.position+=4,t}getLong(){var t=[];t[0]=this.view.getUint8(this.position),t[1]=this.view.getUint8(this.position+1),t[2]=this.view.getUint8(this.position+2),t[3]=this.view.getUint8(this.position+3),t[4]=this.view.getUint8(this.position+4),t[5]=this.view.getUint8(this.position+5),t[6]=this.view.getUint8(this.position+6),t[7]=this.view.getUint8(this.position+7);var e=0;if(this.littleEndian)for(let n=t.length-1;n>=0;n--)e=256*e+t[n];else for(let n=0;n<t.length;n++)e=256*e+t[n];return this.position+=8,e}getString(t){for(var e,n="";0!==(e=this.view.getUint8(this.position++))&&(n+=String.fromCharCode(e),!t||n.length!==t););return n}getFixedLengthString(t){var e,n,r="";for(e=0;e<t;e++)(n=this.view.getUint8(this.position++))>0&&(r+=String.fromCharCode(n));return r}getFixedLengthTrimmedString(t){var e,n,r="";for(e=0;e<t;e++)(n=this.view.getUint8(this.position++))>32&&(r+=String.fromCharCode(n));return r}getFloat(){var t=this.view.getFloat32(this.position,this.littleEndian);return this.position+=4,t}getDouble(){var t=this.view.getFloat64(this.position,this.littleEndian);return this.position+=8,t}skip(t){return this.position+=t,this.position}getVPointer(){var t=this.position,e=this.view.getUint8(t+1)<<8|this.view.getUint8(t),n=4294967296*(255&this.view.getUint8(t+6))+16777216*(255&this.view.getUint8(t+5))+65536*(255&this.view.getUint8(t+4))+256*(255&this.view.getUint8(t+3))+(255&this.view.getUint8(t+2));return this.position+=8,new $a(n,e)}}class $a{constructor(t,e){this.block=t,this.offset=e}isLessThan(t){return this.block<t.block||this.block===t.block&&this.offset<t.offset}isGreaterThan(t){return this.block>t.block||this.block===t.block&&this.offset>t.offset}print(){return this.block+":"+this.offset}}class Ga{constructor(t){this.tabix=!0}parse(t,e){const n=new Wa(new DataView(t)),r=n.getInt();if(21582659!==r)throw 38359875===r?Error("CSI version 2 is not supported. Please enter an issue at https://github.com/igvteam/igv.js"):Error("Not a CSI index");this.indices=[],this.blockMin=Number.MAX_SAFE_INTEGER,this.lastBlockPosition=[],this.sequenceIndexMap={},this.minShift=n.getInt(),this.depth=n.getInt();const i=[];let o=0;if(n.getInt()>=28){n.getInt(),n.getInt(),n.getInt(),n.getInt(),n.getInt(),n.getInt();const t=n.getInt(),r=n.position+t;let o=0;for(;n.position<r;){let t=n.getString();e&&(t=e.getChromosomeName(t)),this.sequenceIndexMap[t]=o,i[o]=t,o++}}const s=this.bin_limit()+1,a=n.getInt();for(let t=0;t<a;t++){const e=[],r=[],i=n.getInt();for(let t=0;t<i;t++){const t=n.getInt();if(r[t]=n.getVPointer(),t>s)n.getInt(),n.getVPointer(),n.getVPointer(),n.getLong(),n.getLong();else{e[t]=[];const r=n.getInt();for(let i=0;i<r;i++){const r=n.getVPointer(),i=n.getVPointer();r&&i&&(r.block<this.blockMin&&(this.blockMin=r.block),i.block>o&&(o=i.block),e[t].push([r,i]))}}}i>0&&(this.indices[t]={binIndex:e,loffset:r})}this.lastBlockPosition=o}get chromosomeNames(){return Object.keys(this.sequenceIndexMap)}blocksForRange(t,e,n){const r=this.indices[t];if(r){const t=this.reg2bins(e,n);if(0==t.length)return[];const i=[];for(let e of t)for(let t=e[0];t<=e[1];t++)if(r.binIndex[t]){const e=r.binIndex[t],n=e.length;for(let r=0;r<n;++r){const n=e[r][0],o=e[r][1];i.push({minv:n,maxv:o,bin:t})}}return function(t,e){const n=[];let r=null;return 0===t.length?t:(t.sort((function(t,e){const n=t.minv.block-e.minv.block;return 0!==n?n:t.minv.offset-e.minv.offset})),t.forEach((function(t){var i,o;e&&!t.maxv.isGreaterThan(e)||(null===r?(n.push(t),r=t):(i=r,(o=t).minv.block-i.maxv.block<65e3&&o.maxv.block-i.minv.block<5e6?t.maxv.isGreaterThan(r.maxv)&&(r.maxv=t.maxv):(n.push(t),r=t)))})),n)}(i,r.loffset[t[0]])}return[]}reg2bins(t,e){(t-=1)<1&&(t=1),e>2**50&&(e=2**34),e-=1;let n=0,r=0,i=this.minShift+3*this.depth;const o=[];for(;n<=this.depth;i-=3,r+=1<<3*n,n+=1){const n=r+(t>>i),s=r+(e>>i);if(s-n+o.length>this.maxBinNumber)throw new Error(`query ${t}-${e} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);o.push([n,s])}return o}bin_limit(){return((1<<3*(this.depth+1))-1)/7}}class Za{constructor(){}async parse(t,e,n){const r=[];let i=Number.MAX_SAFE_INTEGER,o=0;const s=[],a=new Wa(new DataView(t)),c=a.getInt(),l={};if(!(21578050===c||e&&21578324===c))throw new Error(indexURL+" is not a "+(e?"tabix":"bai")+" file");{const t=a.getInt();if(e){a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt(),a.getInt();for(let e=0;e<t;e++){let t=a.getString();n&&(t=n.getChromosomeName(t)),l[t]=e,s[e]=t}}for(let e=0;e<t;e++){const t={},n=[],s=a.getInt();for(let e=0;e<s;e++){const e=a.getInt();if(37450===e)a.getInt(),a.getVPointer(),a.getVPointer(),a.getLong(),a.getLong();else{t[e]=[];const n=a.getInt();for(let r=0;r<n;r++){const n=a.getVPointer(),r=a.getVPointer();n&&r&&(n.block<i&&(i=n.block),r.block>o&&(o=r.block),t[e].push([n,r]))}}}const c=a.getInt();for(let t=0;t<c;t++){const t=a.getVPointer();n.push(t)}s>0&&(r[e]={binIndex:t,linearIndex:n})}this.firstBlockPosition=i,this.lastBlockPosition=o,this.indices=r,this.sequenceIndexMap=l,this.tabix=e}}get chromosomeNames(){return Object.keys(this.sequenceIndexMap)}blocksForRange(t,e,n){const r=this.indices[t];if(r){const t=function(t,e){const n=[];e>=1<<29&&(e=1<<29);return--e,n.push([0,0]),n.push([1+(t>>26),1+(e>>26)]),n.push([9+(t>>23),9+(e>>23)]),n.push([73+(t>>20),73+(e>>20)]),n.push([585+(t>>17),585+(e>>17)]),n.push([4681+(t>>14),4681+(e>>14)]),n}(e,n),i=[];for(let e of t)for(let t=e[0];t<=e[1];t++)if(r.binIndex[t]){const e=r.binIndex[t],n=e.length;for(let r=0;r<n;++r){const n=e[r][0],o=e[r][1];i.push({minv:n,maxv:o,bin:t})}}const o=r.linearIndex.length;let s=null;const a=Math.min(e>>14,o-1),c=Math.min(n>>14,o-1);for(let t=a;t<=c;++t){const e=r.linearIndex[t];e&&(s&&!e.isLessThan(s)||(s=e))}return function(t,e){const n=[];let r=null;return 0===t.length?t:(t.sort((function(t,e){const n=t.minv.block-e.minv.block;return 0!==n?n:t.minv.offset-e.minv.offset})),t.forEach((function(t){e&&!t.maxv.isGreaterThan(e)||(null!==r&&function(t,e){const n=e.minv.block-t.maxv.block,r=e.maxv.block-t.minv.block;return n<3e4&&r<1e7}(r,t)?t.maxv.isGreaterThan(r.maxv)&&(r.maxv=t.maxv):(n.push(t),r=t))})),n)}(i,s)}return[]}}class Xa{constructor(){}async parse(t,e){let n=0;this.chrIndex={},this.lastBlockPosition=[];const r=new Wa(new DataView(t));!function(t){t.getInt(),t.getInt();const e=t.getInt();if(t.getString(),t.getLong(),t.getLong(),t.getString(),t.getInt(),e>=3){let e=t.getInt();for(;e-- >0;)t.getString(),t.getString()}}(r);let i=r.getInt();for(;i-- >0;){let t=r.getString();e&&(t=e.getChromosomeName(t));const i=r.getInt(),o=r.getInt(),s=r.getInt();r.getInt(),r.getInt();let a=r.getLong();const c=[];for(let t=0;t<o;t++){const t=r.getLong();c.push({min:a,max:t}),a=t,t>n&&(n=t)}this.chrIndex[t]={chr:t,blocks:c,longestFeature:s,binWidth:i}}this.lastBlockPosition=n}get chromosomeNames(){return Object.keys(this.chrIndex)}blocksForRange(t,e,n){const r=this.chrIndex[t];if(r){const t=r.blocks,i=r.longestFeature,o=r.binWidth,s=Math.max(e-i,0),a=Math.floor(s/o);if(a>=t.length)return[];{const e=Math.min(Math.floor((n-1)/o),t.length-1),r=t[a].min,i=t[e].max;if(0===i-r)return[];return[{minv:{block:r,offset:0},maxv:{block:i,offset:0}}]}}}}async function Ya(t,e,n){let r=await go.loadArrayBuffer(t,gs(e)),i=new DataView(r);if(31===i.getUint8(0)&&139===i.getUint8(1)){r=Wi(r).buffer,i=new DataView(r)}switch(i.getInt32(0,!0)){case 21578050:return async function(t,e){const n=new Za;return await n.parse(t,!1,e),n}(r,n);case 21578324:return async function(t,e){const n=new Za;return await n.parse(t,!0,e),n}(r,n);case 21582659:return async function(t,e){const n=new Ga;return n.parse(t,e),n}(r,n);case 1480870228:return async function(t,e){const n=new Xa;return n.parse(t,e),n}(r,n);case 38359875:throw Error("CSI version 2 is not supported.");default:throw Error(`Unrecognized index type: ${t}`)}}class Ka{constructor(t,e){this.config=t,this.genome=e,this.bamPath=t.url,this.baiPath=t.indexURL,za.setReaderDefaults(this,t)}async readAlignments(t,e,n){const r=(await this.getChrIndex())[this.chrAliasTable.hasOwnProperty(t)?this.chrAliasTable[t]:t],i=new ba(t,e,n,this.config);if(void 0===r)return i;{const t=(await this.getIndex()).blocksForRange(r,e,n);if(!t||0===t.length)return i;for(let s of t){let t;if(0===s.maxv.offset)t=0;else{const e=gs(this.config,{range:{start:s.maxv.block,size:26}});t=$i(await go.loadArrayBuffer(this.bamPath,e))}const a=s.minv.block,c={start:a,size:s.maxv.block+t-a+1};var o=Wi(await go.loadArrayBuffer(this.bamPath,gs(this.config,{range:c})));if(za.decodeBamRecords(o,s.minv.offset,i,this.indexToChr,r,e,n,this.filter))break}return i.finish(),i}}async getHeader(){if(!this.header){const t=this.genome,e=await this.getIndex();let n;if(e.firstBlockPosition){const t=gs(this.config,{range:{start:e.firstBlockPosition,size:26}}),r=$i(await go.loadArrayBuffer(this.bamPath,t));n=e.firstBlockPosition+r}else n=64e3;const r=gs(this.config,{range:{start:0,size:n}});this.header=await za.readHeader(this.bamPath,r,t)}return this.header}async getIndex(){const t=this.genome;return this.index||(this.index=await Ya(this.baiPath,this.config,t)),this.index}async getChrIndex(){if(this.chrToIndex)return this.chrToIndex;{const t=await this.getHeader();return this.chrToIndex=t.chrToIndex,this.indexToChr=t.chrNames,this.chrAliasTable=t.chrAliasTable,this.chrToIndex}}}class Qa{constructor(t,e){this.config=t,this.genome=e;const n={};t.sources.sequences.forEach((function(r){const i=e?e.getChromosomeName(r):r;n[i]=function(t,e,n){const r={url:t.sources.url.replace("$CHR",n)};t.sources.indexURL&&(r.indexURL=t.sources.indexURL.replace("$CHR",n));const i=Object.assign(t,r);return new Ka(i,e)}(t,e,r)})),this.bamReaders=n,za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(this.bamReaders.hasOwnProperty(t)){let r=this.bamReaders[t];return await r.readAlignments(t,e,n)}return new ba(t,e,n,this.config)}}const Ja=function(t,e){this.config=t,this.genome=e,za.setReaderDefaults(this,t)};function tc(){const t=this,e=this.genome;if(this.header)return Promise.resolve(this.header);{const n=this.config.url+"?file="+this.config.alignmentFile+"&options=-b,-H",r=gs(this.config);return za.readHeader(n,r,e).then((function(e){return t.header=e,e}))}}Ja.prototype.readAlignments=function(t,e,n){var r=this;return tc.call(r).then((function(i){var o,s;return o=i.chrAliasTable.hasOwnProperty(t)?i.chrAliasTable[t]:t,s=r.config.url+"?reference="+r.config.referenceFile+"&file="+r.config.alignmentFile+"&region="+o+":"+e+"-"+n,go.loadString(s,gs(r.config)).then((function(s){var a;return i.chrToIndex[o],a=new ba(t,e,n,r.config),za.decodeSamRecords(s,a,o,e,n,r.filter),a}))}))};class ec{constructor(t,e){if(this.config=t,this.genome=e,this.format=t.format?t.format.toUpperCase():"BAM","BAM"!==this.format&&"VCF"!==this.format)throw Error(`htsget format ${t.format} is not supported`)}async readHeaderData(){const t=`${nc(this.config)}?class=header&format=${this.format}`,e=await go.loadJson(t,gs(this.config));return await this.loadUrls(e.htsget.urls)}async readData(t,e,n){const r=`${nc(this.config)}?format=${this.format}&referenceName=${t}&start=${Math.floor(e)}&end=${Math.ceil(n)}`,i=await go.loadJson(r,gs(this.config));return this.loadUrls(i.htsget.urls)}async loadUrls(t){const e=[];for(let n of t)if(n.url.startsWith("data:"))e.push(Promise.resolve(rc(n.url)));else{const t=gs(this.config||{});n.headers&&(t.headers=Object.assign(t.headers||{},n.headers)),e.push(go.loadArrayBuffer(n.url,t))}return function(t){let e=0;for(let n of t)e+=n.byteLength;let n=0;const r=new Uint8Array(e);for(let e of t){const t=new Uint8Array(e);r.set(t,n),n+=t.length}return r}(await Promise.all(e))}static async inferFormat(t){try{const e=nc(t),n=`${e}${e.includes("?")?"&":"?"}class=header`,r=await go.loadJson(n,gs(t));if(r.htsget){const e=r.htsget.format;if("BAM"!==e&&"VCF"!==e)throw Error(`htsget format ${e} is not supported`);t.format=e.toLowerCase(),t.sourceType="htsget",t.name||(t.name=await bs(t.url))}}catch(t){}}}function nc(t){if(t.url&&t.endpoint&&t.id)return t.url+t.endpoint+t.id;if(t.endpoint&&t.id)return t.endpoint+t.id;if(t.url)return t.url.startsWith("htsget://")?t.url.replace("htsget://","https://"):t.url;throw Error("Must specify either 'url', or 'endpoint' and 'id")}function rc(t){const e=t.split(","),n=e[0].split(":")[1];let r=e[1];r=n.indexOf("base64")>=0?atob(r):decodeURI(r);const i=new Uint8Array(r.length);for(var o=0;o<r.length;o++)i[o]=r.charCodeAt(o);return i}class ic extends ec{constructor(t,e){super(t,e),za.setReaderDefaults(this,t)}async readAlignments(t,e,n){if(!this.header){const t=Wi((await this.readHeaderData()).buffer);this.header=za.decodeBamHeader(t,this.genome),this.chrAliasTable=new Map;for(let t of Object.keys(this.header.chrAliasTable))this.chrAliasTable.set(t,this.header.chrAliasTable[t])}let r=this.chrAliasTable.has(t)?this.chrAliasTable.get(t):t;const i=Wi((await this.readData(r,e,n)).buffer),o=this.header.chrToIndex[t],s=new ba(t,e,n,this.config);return za.decodeBamRecords(i,this.header.size,s,this.header.chrNames,o,e,n),s.finish(),s}}const oc=eval,sc=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=163)}([function(t,e,n){var r=n(13),i=n(81).f,o=n(107),s=n(3),a=n(15),c=n(20),l=n(24),h=function(t){var e=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,n)}return new t(e,n,r)}return t.apply(this,arguments)};return e.prototype=t.prototype,e};t.exports=function(t,e){var n,u,f,d,p,g,m,v,b=t.target,w=t.global,y=t.stat,x=t.proto,k=w?r:y?r[b]:(r[b]||{}).prototype,_=w?s:s[b]||(s[b]={}),S=_.prototype;for(f in e)n=!o(w?f:b+(y?".":"#")+f,t.forced)&&k&&l(k,f),p=_[f],n&&(g=t.noTargetGet?(v=i(k,f))&&v.value:k[f]),d=n&&g?g:e[f],n&&typeof p==typeof d||(m=t.bind&&n?a(d,r):t.wrap&&n?h(d):x&&"function"==typeof d?a(Function.call,d):d,(t.sham||d&&d.sham||p&&p.sham)&&c(m,"sham",!0),_[f]=m,x&&(l(s,u=b+"Prototype")||c(s,u,{}),s[u][f]=d,t.real&&S&&!S[f]&&c(S,f,d)))}},function(t,e){t.exports=function(t){return t&&t.__esModule?t:{default:t}}},function(t,e,n){var r=n(14);t.exports=function(t){if(!r(t))throw TypeError(String(t)+" is not an object");return t}},function(t,e){t.exports={}},function(t,e){t.exports=!0},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}},function(t,e,n){var r=n(13),i=n(61),o=n(64),s=n(110),a=r.Symbol,c=i("wks");t.exports=function(t){return c[t]||(c[t]=s&&a[t]||(s?a:o)("Symbol."+t))}},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){var r=n(2),i=n(119),o=n(29),s=n(15),a=n(90),c=n(120),l=function(t,e){this.stopped=t,this.result=e};(t.exports=function(t,e,n,h,u){var f,d,p,g,m,v,b=s(e,n,h?2:1);if(u)f=t;else{if("function"!=typeof(d=a(t)))throw TypeError("Target is not iterable");if(i(d)){for(p=0,g=o(t.length);g>p;p++)if((m=h?b(r(v=t[p])[0],v[1]):b(t[p]))&&m instanceof l)return m;return new l(!1)}f=d.call(t)}for(;!(v=f.next()).done;)if((m=c(f,b,v.value,h))&&m instanceof l)return m;return new l(!1)}).stop=function(t){return new l(!0,t)}},function(t,e,n){var r=n(1),i=r(n(7)),o=r(n(32)),s=r(n(27)),a=r(n(33)),c=r(n(265)),l=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}((0,c.default)(Error)),h=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}((0,c.default)(Error)),u=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l),f=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(u),d=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l),p=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(0,s.default)(e).apply(this,arguments))}return(0,a.default)(e,t),e}(l);t.exports={CramBufferOverrunError:f,CramMalformedError:u,CramUnimplementedError:h,CramSizeLimitError:d,CramArgumentError:p}},function(t,e,n){var r=n(196);function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),r(t,i.key,i)}}t.exports=function(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}},function(t,e,n){var r=n(3),i=n(24),o=n(95),s=n(21).f;t.exports=function(t){var e=r.Symbol||(r.Symbol={});i(e,t)||s(e,t,{value:o.f(t)})}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){(function(e){var n="object",r=function(t){return t&&t.Math==Math&&t};t.exports=r(typeof globalThis==n&&globalThis)||r(typeof window==n&&window)||r(typeof self==n&&self)||r(typeof e==n&&e)||Function("return this")()}).call(this,n(23))},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){var r=n(5);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 0:return function(){return t.call(e)};case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)}}return function(){return t.apply(e,arguments)}}},function(t,e,n){t.exports=n(167)},function(t,e,n){var r=n(12);t.exports=!r((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}))},function(t,e,n){var r=n(3);t.exports=function(t){return r[t+"Prototype"]}},function(t,e,n){(function(t){
40
40
  /*!
41
41
  * The buffer module from node.js, for the browser.
42
42
  *
@@ -68,5 +68,5 @@ var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.pr
68
68
  *
69
69
  * Copyright 2017-2021 Andreas Borgen (https://github.com/Sphinxxxx), Adam Brooks (https://github.com/dissimulate)
70
70
  * Released under the ISC license.
71
- */var Tc=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},Lc=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),Mc=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&a.return&&a.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};String.prototype.startsWith=String.prototype.startsWith||function(t){return 0===this.indexOf(t)},String.prototype.padStart=String.prototype.padStart||function(t,e){for(var n=this;n.length<t;)n=e+n;return n};var Rc={cb:"0f8ff",tqw:"aebd7",q:"-ffff",qmrn:"7fffd4",zr:"0ffff",bg:"5f5dc",bsq:"e4c4",bck:"---",nch:"ebcd",b:"--ff",bvt:"8a2be2",brwn:"a52a2a",brw:"deb887",ctb:"5f9ea0",hrt:"7fff-",chcT:"d2691e",cr:"7f50",rnw:"6495ed",crns:"8dc",crms:"dc143c",cn:"-ffff",Db:"--8b",Dcn:"-8b8b",Dgnr:"b8860b",Dgr:"a9a9a9",Dgrn:"-64-",Dkhk:"bdb76b",Dmgn:"8b-8b",Dvgr:"556b2f",Drng:"8c-",Drch:"9932cc",Dr:"8b--",Dsmn:"e9967a",Dsgr:"8fbc8f",DsTb:"483d8b",DsTg:"2f4f4f",Dtrq:"-ced1",Dvt:"94-d3",ppnk:"1493",pskb:"-bfff",mgr:"696969",grb:"1e90ff",rbrc:"b22222",rwht:"af0",stg:"228b22",chs:"-ff",gnsb:"dcdcdc",st:"8f8ff",g:"d7-",gnr:"daa520",gr:"808080",grn:"-8-0",grnw:"adff2f",hnw:"0fff0",htpn:"69b4",nnr:"cd5c5c",ng:"4b-82",vr:"0",khk:"0e68c",vnr:"e6e6fa",nrb:"0f5",wngr:"7cfc-",mnch:"acd",Lb:"add8e6",Lcr:"08080",Lcn:"e0ffff",Lgnr:"afad2",Lgr:"d3d3d3",Lgrn:"90ee90",Lpnk:"b6c1",Lsmn:"a07a",Lsgr:"20b2aa",Lskb:"87cefa",LsTg:"778899",Lstb:"b0c4de",Lw:"e0",m:"-ff-",mgrn:"32cd32",nn:"af0e6",mgnt:"-ff",mrn:"8--0",mqm:"66cdaa",mmb:"--cd",mmrc:"ba55d3",mmpr:"9370db",msg:"3cb371",mmsT:"7b68ee","":"-fa9a",mtr:"48d1cc",mmvt:"c71585",mnLb:"191970",ntc:"5fffa",mstr:"e4e1",mccs:"e4b5",vjw:"dead",nv:"--80",c:"df5e6",v:"808-0",vrb:"6b8e23",rng:"a5-",rngr:"45-",rch:"da70d6",pgnr:"eee8aa",pgrn:"98fb98",ptrq:"afeeee",pvtr:"db7093",ppwh:"efd5",pchp:"dab9",pr:"cd853f",pnk:"c0cb",pm:"dda0dd",pwrb:"b0e0e6",prp:"8-080",cc:"663399",r:"--",sbr:"bc8f8f",rb:"4169e1",sbrw:"8b4513",smn:"a8072",nbr:"4a460",sgrn:"2e8b57",ssh:"5ee",snn:"a0522d",svr:"c0c0c0",skb:"87ceeb",sTb:"6a5acd",sTgr:"708090",snw:"afa",n:"-ff7f",stb:"4682b4",tn:"d2b48c",t:"-8080",thst:"d8bfd8",tmT:"6347",trqs:"40e0d0",vt:"ee82ee",whT:"5deb3",wht:"",hts:"5f5f5",w:"-",wgrn:"9acd32"};function Ic(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=e>0?t.toFixed(e).replace(/0+$/,"").replace(/\.$/,""):t.toString();return n||"0"}var Nc=function(){function t(e,n,r,i){Tc(this,t);var o=this;if(void 0===e);else if(Array.isArray(e))this.rgba=e;else if(void 0===r){var s=e&&""+e;s&&function(e){if(e.startsWith("hsl")){var n=e.match(/([\-\d\.e]+)/g).map(Number),r=Mc(n,4),i=r[0],s=r[1],a=r[2],c=r[3];void 0===c&&(c=1),i/=360,s/=100,a/=100,o.hsla=[i,s,a,c]}else if(e.startsWith("rgb")){var l=e.match(/([\-\d\.e]+)/g).map(Number),h=Mc(l,4),u=h[0],f=h[1],d=h[2],p=h[3];void 0===p&&(p=1),o.rgba=[u,f,d,p]}else e.startsWith("#")?o.rgba=t.hexToRgb(e):o.rgba=t.nameToRgb(e)||t.hexToRgb(e)}(s.toLowerCase())}else this.rgba=[e,n,r,void 0===i?1:i]}return Lc(t,[{key:"printRGB",value:function(t){var e=(t?this.rgba:this.rgba.slice(0,3)).map((function(t,e){return Ic(t,3===e?3:0)}));return t?"rgba("+e+")":"rgb("+e+")"}},{key:"printHSL",value:function(t){var e=[360,100,100,1],n=["","%","%",""],r=(t?this.hsla:this.hsla.slice(0,3)).map((function(t,r){return Ic(t*e[r],3===r?3:1)+n[r]}));return t?"hsla("+r+")":"hsl("+r+")"}},{key:"printHex",value:function(t){var e=this.hex;return t?e:e.substring(0,7)}},{key:"rgba",get:function(){if(this._rgba)return this._rgba;if(!this._hsla)throw new Error("No color is set");return this._rgba=t.hslToRgb(this._hsla)},set:function(t){3===t.length&&(t[3]=1),this._rgba=t,this._hsla=null}},{key:"rgbString",get:function(){return this.printRGB()}},{key:"rgbaString",get:function(){return this.printRGB(!0)}},{key:"hsla",get:function(){if(this._hsla)return this._hsla;if(!this._rgba)throw new Error("No color is set");return this._hsla=t.rgbToHsl(this._rgba)},set:function(t){3===t.length&&(t[3]=1),this._hsla=t,this._rgba=null}},{key:"hslString",get:function(){return this.printHSL()}},{key:"hslaString",get:function(){return this.printHSL(!0)}},{key:"hex",get:function(){return"#"+this.rgba.map((function(t,e){return e<3?t.toString(16):Math.round(255*t).toString(16)})).map((function(t){return t.padStart(2,"0")})).join("")},set:function(e){this.rgba=t.hexToRgb(e)}}],[{key:"hexToRgb",value:function(t){var e=(t.startsWith("#")?t.slice(1):t).replace(/^(\w{3})$/,"$1F").replace(/^(\w)(\w)(\w)(\w)$/,"$1$1$2$2$3$3$4$4").replace(/^(\w{6})$/,"$1FF");if(!e.match(/^([0-9a-fA-F]{8})$/))throw new Error("Unknown hex color; "+t);var n=e.match(/^(\w\w)(\w\w)(\w\w)(\w\w)$/).slice(1).map((function(t){return parseInt(t,16)}));return n[3]=n[3]/255,n}},{key:"nameToRgb",value:function(e){var n=e.toLowerCase().replace("at","T").replace(/[aeiouyldf]/g,"").replace("ght","L").replace("rk","D").slice(-5,4),r=Rc[n];return void 0===r?r:t.hexToRgb(r.replace(/\-/g,"00").padStart(6,"f"))}},{key:"rgbToHsl",value:function(t){var e=Mc(t,4),n=e[0],r=e[1],i=e[2],o=e[3];n/=255,r/=255,i/=255;var s=Math.max(n,r,i),a=Math.min(n,r,i),c=void 0,l=void 0,h=(s+a)/2;if(s===a)c=l=0;else{var u=s-a;switch(l=h>.5?u/(2-s-a):u/(s+a),s){case n:c=(r-i)/u+(r<i?6:0);break;case r:c=(i-n)/u+2;break;case i:c=(n-r)/u+4}c/=6}return[c,l,h,o]}},{key:"hslToRgb",value:function(t){var e=Mc(t,4),n=e[0],r=e[1],i=e[2],o=e[3],s=void 0,a=void 0,c=void 0;if(0===r)s=a=c=i;else{var l=function(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t},h=i<.5?i*(1+r):i+r-i*r,u=2*i-h;s=l(u,h,n+1/3),a=l(u,h,n),c=l(u,h,n-1/3)}var f=[255*s,255*a,255*c].map(Math.round);return f[3]=o,f}}]),t}(),Pc=function(){function t(){Tc(this,t),this._events=[]}return Lc(t,[{key:"add",value:function(t,e,n){t.addEventListener(e,n,!1),this._events.push({target:t,type:e,handler:n})}},{key:"remove",value:function(e,n,r){this._events=this._events.filter((function(i){var o=!0;return e&&e!==i.target&&(o=!1),n&&n!==i.type&&(o=!1),r&&r!==i.handler&&(o=!1),o&&t._doRemove(i.target,i.type,i.handler),!o}))}},{key:"destroy",value:function(){this._events.forEach((function(e){return t._doRemove(e.target,e.type,e.handler)})),this._events=[]}}],[{key:"_doRemove",value:function(t,e,n){t.removeEventListener(e,n,!1)}}]),t}();function Oc(t,e,n){var r=!1;function i(t,e,n){return Math.max(e,Math.min(t,n))}function o(t,o,s){if(s&&(r=!0),r){t.preventDefault();var a=e.getBoundingClientRect(),c=a.width,l=a.height,h=o.clientX,u=o.clientY,f=i(h-a.left,0,c),d=i(u-a.top,0,l);n(f/c,d/l)}}function s(t,e){1===(void 0===t.buttons?t.which:t.buttons)?o(t,t,e):r=!1}function a(t,e){1===t.touches.length?o(t,t.touches[0],e):r=!1}t.add(e,"mousedown",(function(t){s(t,!0)})),t.add(e,"touchstart",(function(t){a(t,!0)})),t.add(window,"mousemove",s),t.add(e,"touchmove",a),t.add(window,"mouseup",(function(t){r=!1})),t.add(e,"touchend",(function(t){r=!1})),t.add(e,"touchcancel",(function(t){r=!1}))}function Fc(t,e){return(e||document).querySelector(t)}function Dc(t){t.preventDefault(),t.stopPropagation()}function Bc(t,e,n,r,i){t.add(e,"keydown",(function(t){n.indexOf(t.key)>=0&&(i&&Dc(t),r(t))}))}var zc=function(){function t(e){Tc(this,t),this.settings={popup:"right",layout:"default",alpha:!0,editor:!0,editorFormat:"hex",cancelButton:!1,defaultColor:"#0cf"},this._events=new Pc,this.onChange=null,this.onDone=null,this.onOpen=null,this.onClose=null,this.setOptions(e)}return Lc(t,[{key:"setOptions",value:function(t){var e=this;if(t){var n=this.settings;if(t instanceof HTMLElement)n.parent=t;else{n.parent&&t.parent&&n.parent!==t.parent&&(this._events.remove(n.parent),this._popupInited=!1),function(t,e,n){for(var r in t)n&&n.indexOf(r)>=0||(e[r]=t[r])}(t,n),t.onChange&&(this.onChange=t.onChange),t.onDone&&(this.onDone=t.onDone),t.onOpen&&(this.onOpen=t.onOpen),t.onClose&&(this.onClose=t.onClose);var r=t.color||t.colour;r&&this._setColor(r)}var i=n.parent;if(i&&n.popup&&!this._popupInited){var o=function(t){return e.openHandler(t)};this._events.add(i,"click",o),Bc(this._events,i,[" ","Spacebar","Enter"],o),this._popupInited=!0}else t.parent&&!n.popup&&this.show()}}},{key:"openHandler",value:function(t){if(this.show()){t&&t.preventDefault(),this.settings.parent.style.pointerEvents="none";var e=t&&"keydown"===t.type?this._domEdit:this.domElement;setTimeout((function(){return e.focus()}),100),this.onOpen&&this.onOpen(this.colour)}}},{key:"closeHandler",value:function(t){var e=t&&t.type,n=!1;if(t)if("mousedown"===e||"focusin"===e){var r=(this.__containedEvent||0)+100;t.timeStamp>r&&(n=!0)}else Dc(t),n=!0;else n=!0;n&&this.hide()&&(this.settings.parent.style.pointerEvents="","mousedown"!==e&&this.settings.parent.focus(),this.onClose&&this.onClose(this.colour))}},{key:"movePopup",value:function(t,e){this.closeHandler(),this.setOptions(t),e&&this.openHandler()}},{key:"setColor",value:function(t,e){this._setColor(t,{silent:e})}},{key:"_setColor",value:function(t,e){if("string"==typeof t&&(t=t.trim()),t){e=e||{};var n=void 0;try{n=new Nc(t)}catch(t){if(e.failSilently)return;throw t}if(!this.settings.alpha){var r=n.hsla;r[3]=1,n.hsla=r}this.colour=this.color=n,this._setHSLA(null,null,null,null,e)}}},{key:"setColour",value:function(t,e){this.setColor(t,e)}},{key:"show",value:function(){if(!this.settings.parent)return!1;if(this.domElement){var t=this._toggleDOM(!0);return this._setPosition(),t}var e=function(t){var e=document.createElement("div");return e.innerHTML=t,e.firstElementChild}(this.settings.template||'<div class="picker_wrapper" tabindex="-1"><div class="picker_arrow"></div><div class="picker_hue picker_slider"><div class="picker_selector"></div></div><div class="picker_sl"><div class="picker_selector"></div></div><div class="picker_alpha picker_slider"><div class="picker_selector"></div></div><div class="picker_editor"><input aria-label="Type a color name or hex value"/></div><div class="picker_sample"></div><div class="picker_done"><button>Ok</button></div><div class="picker_cancel"><button>Cancel</button></div></div>');return this.domElement=e,this._domH=Fc(".picker_hue",e),this._domSL=Fc(".picker_sl",e),this._domA=Fc(".picker_alpha",e),this._domEdit=Fc(".picker_editor input",e),this._domSample=Fc(".picker_sample",e),this._domOkay=Fc(".picker_done button",e),this._domCancel=Fc(".picker_cancel button",e),e.classList.add("layout_"+this.settings.layout),this.settings.alpha||e.classList.add("no_alpha"),this.settings.editor||e.classList.add("no_editor"),this.settings.cancelButton||e.classList.add("no_cancel"),this._ifPopup((function(){return e.classList.add("popup")})),this._setPosition(),this.colour?this._updateUI():this._setColor(this.settings.defaultColor),this._bindEvents(),!0}},{key:"hide",value:function(){return this._toggleDOM(!1)}},{key:"destroy",value:function(){this._events.destroy(),this.domElement&&this.settings.parent.removeChild(this.domElement)}},{key:"_bindEvents",value:function(){var t=this,e=this,n=this.domElement,r=this._events;function i(t,e,n){r.add(t,e,n)}i(n,"click",(function(t){return t.preventDefault()})),Oc(r,this._domH,(function(t,n){return e._setHSLA(t)})),Oc(r,this._domSL,(function(t,n){return e._setHSLA(null,t,1-n)})),this.settings.alpha&&Oc(r,this._domA,(function(t,n){return e._setHSLA(null,null,null,1-n)}));var o=this._domEdit;i(o,"input",(function(t){e._setColor(this.value,{fromEditor:!0,failSilently:!0})})),i(o,"focus",(function(t){var e=this;e.selectionStart===e.selectionEnd&&e.select()})),this._ifPopup((function(){var e=function(e){return t.closeHandler(e)};i(window,"mousedown",e),i(window,"focusin",e),Bc(r,n,["Esc","Escape"],e);var o=function(e){t.__containedEvent=e.timeStamp};i(n,"mousedown",o),i(n,"focusin",o),i(t._domCancel,"click",e)}));var s=function(e){t._ifPopup((function(){return t.closeHandler(e)})),t.onDone&&t.onDone(t.colour)};i(this._domOkay,"click",s),Bc(r,n,["Enter"],s)}},{key:"_setPosition",value:function(){var t=this.settings.parent,e=this.domElement;t!==e.parentNode&&t.appendChild(e),this._ifPopup((function(n){"static"===getComputedStyle(t).position&&(t.style.position="relative");var r=!0===n?"popup_right":"popup_"+n;["popup_top","popup_bottom","popup_left","popup_right"].forEach((function(t){t===r?e.classList.add(t):e.classList.remove(t)})),e.classList.add(r)}))}},{key:"_setHSLA",value:function(t,e,n,r,i){i=i||{};var o=this.colour,s=o.hsla;[t,e,n,r].forEach((function(t,e){(t||0===t)&&(s[e]=t)})),o.hsla=s,this._updateUI(i),this.onChange&&!i.silent&&this.onChange(o)}},{key:"_updateUI",value:function(t){if(this.domElement){t=t||{};var e=this.colour,n=e.hsla,r="hsl("+360*n[0]+", 100%, 50%)",i=e.hslString,o=e.hslaString,s=this._domH,a=this._domSL,c=this._domA,l=Fc(".picker_selector",s),h=Fc(".picker_selector",a),u=Fc(".picker_selector",c);b(0,l,n[0]),this._domSL.style.backgroundColor=this._domH.style.color=r,b(0,h,n[1]),w(0,h,1-n[2]),a.style.color=i,w(0,u,1-n[3]);var f=i,d=f.replace("hsl","hsla").replace(")",", 0)"),p="linear-gradient("+[f,d]+")";if(this._domA.style.background=p+", linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0 / 2em 2em,\n linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em / 2em 2em",!t.fromEditor){var g=this.settings.editorFormat,m=this.settings.alpha,v=void 0;switch(g){case"rgb":v=e.printRGB(m);break;case"hsl":v=e.printHSL(m);break;default:v=e.printHex(m)}this._domEdit.value=v}this._domSample.style.color=o}function b(t,e,n){e.style.left=100*n+"%"}function w(t,e,n){e.style.top=100*n+"%"}}},{key:"_ifPopup",value:function(t,e){this.settings.parent&&this.settings.popup?t&&t(this.settings.popup):e&&e()}},{key:"_toggleDOM",value:function(t){var e=this.domElement;if(!e)return!1;var n=t?"":"none",r=e.style.display!==n;return r&&(e.style.display=n),r}}]),t}(),Hc=document.createElement("style");function Vc(t){if(jc[t])return jc[t];if(jc["chr"+t]){const e=jc["chr"+t];return jc[t]=e,e}{const i=(e=Math.round(255*Math.random()).toString(10),n=Math.round(255*Math.random()).toString(10),r=Math.round(255*Math.random()).toString(10),"rgb("+e+","+n+","+r+")");return jc[t]=i,i}var e,n,r}Hc.textContent='.picker_wrapper.no_alpha .picker_alpha{display:none}.picker_wrapper.no_editor .picker_editor{position:absolute;z-index:-1;opacity:0}.picker_wrapper.no_cancel .picker_cancel{display:none}.layout_default.picker_wrapper{display:flex;flex-flow:row wrap;justify-content:space-between;align-items:stretch;font-size:10px;width:25em;padding:.5em}.layout_default.picker_wrapper input,.layout_default.picker_wrapper button{font-size:1rem}.layout_default.picker_wrapper>*{margin:.5em}.layout_default.picker_wrapper::before{content:"";display:block;width:100%;height:0;order:1}.layout_default .picker_slider,.layout_default .picker_selector{padding:1em}.layout_default .picker_hue{width:100%}.layout_default .picker_sl{flex:1 1 auto}.layout_default .picker_sl::before{content:"";display:block;padding-bottom:100%}.layout_default .picker_editor{order:1;width:6.5rem}.layout_default .picker_editor input{width:100%;height:100%}.layout_default .picker_sample{order:1;flex:1 1 auto}.layout_default .picker_done,.layout_default .picker_cancel{order:1}.picker_wrapper{box-sizing:border-box;background:#f2f2f2;box-shadow:0 0 0 1px silver;cursor:default;font-family:sans-serif;color:#444;pointer-events:auto}.picker_wrapper:focus{outline:none}.picker_wrapper button,.picker_wrapper input{box-sizing:border-box;border:none;box-shadow:0 0 0 1px silver;outline:none}.picker_wrapper button:focus,.picker_wrapper button:active,.picker_wrapper input:focus,.picker_wrapper input:active{box-shadow:0 0 2px 1px #1e90ff}.picker_wrapper button{padding:.4em .6em;cursor:pointer;background-color:#f5f5f5;background-image:linear-gradient(0deg, gainsboro, transparent)}.picker_wrapper button:active{background-image:linear-gradient(0deg, transparent, gainsboro)}.picker_wrapper button:hover{background-color:#fff}.picker_selector{position:absolute;z-index:1;display:block;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%);border:2px solid #fff;border-radius:100%;box-shadow:0 0 3px 1px #67b9ff;background:currentColor;cursor:pointer}.picker_slider .picker_selector{border-radius:2px}.picker_hue{position:relative;background-image:linear-gradient(90deg, red, yellow, lime, cyan, blue, magenta, red);box-shadow:0 0 0 1px silver}.picker_sl{position:relative;box-shadow:0 0 0 1px silver;background-image:linear-gradient(180deg, white, rgba(255, 255, 255, 0) 50%),linear-gradient(0deg, black, rgba(0, 0, 0, 0) 50%),linear-gradient(90deg, #808080, rgba(128, 128, 128, 0))}.picker_alpha,.picker_sample{position:relative;background:linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0/2em 2em,linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em/2em 2em;box-shadow:0 0 0 1px silver}.picker_alpha .picker_selector,.picker_sample .picker_selector{background:none}.picker_editor input{font-family:monospace;padding:.2em .4em}.picker_sample::before{content:"";position:absolute;display:block;width:100%;height:100%;background:currentColor}.picker_arrow{position:absolute;z-index:-1}.picker_wrapper.popup{position:absolute;z-index:2;margin:1.5em}.picker_wrapper.popup,.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{background:#f2f2f2;box-shadow:0 0 10px 1px rgba(0,0,0,.4)}.picker_wrapper.popup .picker_arrow{width:3em;height:3em;margin:0}.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{content:"";display:block;position:absolute;top:0;left:0;z-index:-99}.picker_wrapper.popup .picker_arrow::before{width:100%;height:100%;-webkit-transform:skew(45deg);transform:skew(45deg);-webkit-transform-origin:0 100%;transform-origin:0 100%}.picker_wrapper.popup .picker_arrow::after{width:150%;height:150%;box-shadow:none}.popup.popup_top{bottom:100%;left:0}.popup.popup_top .picker_arrow{bottom:0;left:0;-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.popup.popup_bottom{top:100%;left:0}.popup.popup_bottom .picker_arrow{top:0;left:0;-webkit-transform:rotate(90deg) scale(1, -1);transform:rotate(90deg) scale(1, -1)}.popup.popup_left{top:0;right:100%}.popup.popup_left .picker_arrow{top:0;right:0;-webkit-transform:scale(-1, 1);transform:scale(-1, 1)}.popup.popup_right{top:0;left:100%}.popup.popup_right .picker_arrow{top:0;left:0}',document.documentElement.firstElementChild.appendChild(Hc),zc.StyleElement=Hc;const jc={chrX:"rgb(204, 153, 0)",chrY:"rgb(153, 204, 0",chrUn:"rgb(50, 50, 50)",chr1:"rgb(80, 80, 255)",chrI:"rgb(139, 155, 187)",chr2:"rgb(206, 61, 50)",chrII:"rgb(206, 61, 50)",chr2a:"rgb(216, 71, 60)",chr2b:"rgb(226, 81, 70)",chr3:"rgb(116, 155, 88)",chrIII:"rgb(116, 155, 88)",chr4:"rgb(240, 230, 133)",chrIV:"rgb(240, 230, 133)",chr5:"rgb(70, 105, 131)",chr6:"rgb(186, 99, 56)",chr7:"rgb(93, 177, 221)",chr8:"rgb(128, 34, 104)",chr9:"rgb(107, 215, 107)",chr10:"rgb(213, 149, 167)",chr11:"rgb(146, 72, 34)",chr12:"rgb(131, 123, 141)",chr13:"rgb(199, 81, 39)",chr14:"rgb(213, 143, 92)",chr15:"rgb(122, 101, 165)",chr16:"rgb(228, 175, 105)",chr17:"rgb(59, 27, 83)",chr18:"rgb(205, 222, 183)",chr19:"rgb(97, 42, 121)",chr20:"rgb(174, 31, 99)",chr21:"rgb(231, 199, 111)",chr22:"rgb(90, 101, 94)",chr23:"rgb(204, 153, 0)",chr24:"rgb(153, 204, 0)",chr25:"rgb(51, 204, 0)",chr26:"rgb(0, 204, 51)",chr27:"rgb(0, 204, 153)",chr28:"rgb(0, 153, 204)",chr29:"rgb(10, 71, 255)",chr30:"rgb(71, 117, 255)",chr31:"rgb(255, 194, 10)",chr32:"rgb(255, 209, 71)",chr33:"rgb(153, 0, 51)",chr34:"rgb(153, 26, 0)",chr35:"rgb(153, 102, 0)",chr36:"rgb(128, 153, 0)",chr37:"rgb(51, 153, 0)",chr38:"rgb(0, 153, 26)",chr39:"rgb(0, 153, 102)",chr40:"rgb(0, 128, 153)",chr41:"rgb(0, 51, 153)",chr42:"rgb(26, 0, 153)",chr43:"rgb(102, 0, 153)",chr44:"rgb(153, 0, 128)",chr45:"rgb(214, 0, 71)",chr46:"rgb(255, 20, 99)",chr47:"rgb(0, 214, 143)",chr48:"rgb(20, 255, 177)"};class Uc{constructor(t){this.tracks=[],this.chordSets=[]}addChordSet(t){this.chordSets=this.chordSets.filter((e=>e.name!==t.name)),this.chordSets.push(t);let e=this.tracks.find((e=>t.trackName===e.name));e&&(e.chordSets=e.chordSets.filter((e=>e.name!==t.name)),e.chordSets.push(t)),e||(e=new qc(t),this.tracks.push(e))}clearChords(){this.tracks=[],this.chordSets=[]}getTrack(t){return this.tracks.find((e=>t===e.name))}getChordSet(t){return this.chordSets.find((e=>t===e.name))}}class qc{constructor(t){this.name=t.trackName,this.color=t.trackColor,this.visible=!0,this.chordSets=[t],this.id=("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}get chords(){if(1===this.chordSets.length)return this.chordSets[0].chords;const t=[];for(let e of this.chordSets)for(let n of e.chords)t.push(n);return t}}const Wc=Math.exp(5);class $c{static isInstalled(){return void 0!==window.JBrowseReactCircularGenomeView&&void 0!==window.React&&void 0!==window.ReactDOM}constructor(t,e){if(e=e||{},this.config=e,$c.isInstalled()){this.parent=t,this.groupByTrack=!0===e.groupByTrack,this.chordManager=new Uc(e);const n=document.createElement("div");n.className="igv-circview-container",t.appendChild(n),this.createControls(n),this.resetControlPanel();const r=document.createElement("div");r.className="igv-circview-circular-genome-view",n.appendChild(r),this.container=r,e.assembly&&this.setAssembly(e.assembly),this.width=e.width||500,this.height=e.height||500,this.setSize(this.width,this.height)}else console.error("JBrowse circular view is not installed")}createControls(t){const e=document.createElement("div");e.className="igv-circview-toolbar",t.appendChild(e),this.toolbar=e;const n=document.createElement("div");n.className="igv-circview-track-panel",t.appendChild(n),this.controlPanel=n,this.controlPanel.style.display="none";const r=document.createElement("div");r.className="igv-circview-toolbar-button-container",this.toolbar.appendChild(r),this.showControlsButton=document.createElement("div"),this.showControlsButton.className="igv-circview-button",r.appendChild(this.showControlsButton),this.showControlsButton.innerText="none"===this.controlPanel.style.display?"Show Controls":"Hide Controls",this.showControlsButton.addEventListener("click",(t=>{this.controlPanel.querySelectorAll("div").length>0&&("none"===this.controlPanel.style.display?(this.controlPanel.style.display="flex",t.target.innerText="Hide Controls"):(this.controlPanel.style.display="none",t.target.innerText="Show Controls"))}));let i=document.createElement("div");i.className="igv-circview-button",r.appendChild(i),i.innerText="Clear All",i.addEventListener("click",(()=>{this.clearChords()})),!1!==this.config.showCloseButton&&(i=document.createElement("div"),i.className="igv-circview-button",r.appendChild(i),i.innerText="Close",i.addEventListener("click",(()=>{this.visible=!1})))}resetControlPanel(){this.controlPanel.innerHTML="",this.controlPanel.appendChild(this.createGroupByCB());const t=this.groupByTrack?this.chordManager.tracks:this.chordManager.chordSets;for(let e of t)this.addToControlPanel(e)}createGroupByCB(){const t=document.createElement("input");t.type="checkbox",t.id="groupByCB",t.style.width="1.4em",t.style.height="1.4em",t.checked=this.groupByTrack,t.onclick=t=>{this.groupByTrack=t.target.checked,this.resetControlPanel(),this.render()};const e=document.createElement("label");e.for="groupByCB",e.innerText="Group by track",e.style.color="black",e.style.paddingLeft="10px";const n=document.createElement("div");return n.style.width="100%",n.style.paddingTop="5px",n.style.paddingBottom="5px",n.style.background="rgb(216, 230, 234)",n.appendChild(t),n.appendChild(e),n}addToControlPanel(t){const e=document.createElement("div");this.controlPanel.appendChild(e);const n=document.createElement("div");n.className="igv-circview-button",e.appendChild(n),n.innerText=!0===t.visible?"Hide":"Show",n.addEventListener("click",(e=>{!0===t.visible?(this.hideChordSet(t.name),e.target.innerText="Show"):(this.showChordSet(t.name),e.target.innerText="Hide")}));const r=document.createElement("input"),i=t=>200*Math.log(t*Wc),o=document.createElement("div");o.className="igv-circview-button",o.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;",e.appendChild(o),o.style.backgroundColor=Gc(t.color,1);const s={parent:o,popup:"right",editorFormat:"rgb",color:t.color,onChange:({rgbaString:e})=>{o.style.backgroundColor=Gc(e,1),this.setColor(t.name,e),r.value=i(Zc(t.color))}},a=new zc(s);r.setAttribute("title","Adjust transparency of arcs"),r.type="range",r.style.width="100px",r.style.marginRight="10px",r.setAttribute("class","range"),r.setAttribute("min","0"),r.setAttribute("max","1000"),r.value=i(Zc(t.color)),r.oninput=()=>{const e=(n=r.value,Math.exp(n/200)/Wc);var n;this.setColor(t.name,Gc(t.color,e)),a.setColor(t.color)},e.appendChild(r);const c=document.createElement("div");c.style.color="black",e.appendChild(c),c.innerText=c.title=t.name}setAssembly(t){const e=this.genomeId||Kc();if(this.genomeId===e)return;this.chordManager.clearChords(),this.genomeId=e,this.chrNames=new Set(t.chromosomes.map((t=>Xc(t.name))));const n=[],r=[];for(let e of t.chromosomes){const t=Xc(e.name);r.push(e.color||Vc(t)),n.push({refName:t,uniqueId:t,start:0,end:e.bpLength})}this.assembly={name:t.name,sequence:{trackId:e,type:"ReferenceSequenceTrack",adapter:{type:"FromConfigSequenceAdapter",features:n}},refNameColors:r},this.render()}addChords(t,e={}){const n=e.name||e.track||"*",r=n.split(" ")[0].replaceAll("%20"," "),i={name:n.replaceAll("%20"," "),trackName:r,chords:t,color:e.color||"black",trackColor:e.trackColor||e.color||"black",visible:!0,id:e.id||Kc()};this.chordManager.addChordSet(i),this.resetControlPanel(),this.render()}setSize(t,e){if(e=e||t,this.width=t,this.height=e,this.viewState){const n=this.viewState.session.view;n.setWidth(t),n.setHeight(e),n.setBpPerPx(n.minBpPerPx)}}getSize(){return Math.min(this.width,this.height)}clearChords(){this.chordManager.clearChords(),this.resetControlPanel(),this.render()}clearSelection(){this.viewState.pluginManager.rootModel.session.clearSelection()}show(){this.parent.style.display="block"}hide(){this.parent.style.display="none"}get visible(){return"none"!==this.parent.style.display}set visible(t){this.parent.style.display=t?"block":"none"}hideChordSet(t){let e=this.getChordSet(t);e?(e.visible=!1,this.render()):console.warn(`No track with name: ${name}`)}showChordSet(t){let e=this.getChordSet(t);e?(e.visible=!0,this.render()):console.warn(`No track with name: ${t}`)}deleteTrack(t){let e=this.tracks.findIndex((e=>t===e.name));e>=0&&this.tracks.splice(e,1),this.render()}getChordSet(t){return this.groupByTrack?this.chordManager.getTrack(t):this.chordManager.getChordSet(t)}setColor(t,e){const n=this.getChordSet(t);if(n){n.color=e;const t=n.id;for(let n of this.viewState.config.tracks)if(t===n.trackId){n.displays[0].renderer.strokeColor.set(e);break}}}render(){const{createViewState:t,JBrowseCircularGenomeView:e}=JBrowseReactCircularGenomeView;ReactDOM.unmountComponentAtNode(this.container);const n=(this.groupByTrack?this.chordManager.tracks:this.chordManager.chordSets).filter((t=>t.visible)),r=[],i=[];for(let t of n)r.push({trackId:t.id,name:t.name,assemblyNames:["forIGV"],type:"VariantTrack",adapter:{type:"FromConfigAdapter",features:t.chords}}),i.push(t.color);this.viewState=t({assembly:this.assembly,tracks:r});for(let t=0;t<n.length;t++)this.viewState.config.tracks[t].displays[0].renderer.strokeColor.set(i[t]);this.element=React.createElement(e,{viewState:this.viewState}),this.setSize(this.width,this.height),ReactDOM.render(this.element,this.container);const o=this.config.onChordClick||Yc;for(let t=0;t<n.length;t++)this.viewState.session.view.showTrack(this.viewState.config.tracks[t].trackId),o&&(this.viewState.pluginManager.jexl.addFunction("onChordClick",o),this.viewState.config.tracks[t].displays[0].onChordClick.set("jexl:onChordClick(feature, track, pluginManager)"))}}function Gc(t,e){const[n,r,i,o]=t.split(",");return`${n},${r},${i},${e})`}function Zc(t){return t.startsWith("rgba(")?Number(t.split(",")[3].replace(")","")):1}function Xc(t){return t.startsWith("chr")?t.substring(3):t}function Yc(t,e,n){console.log(t)}function Kc(){return("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}if("undefined"!=typeof document){function as(t){for(let e of document.styleSheets)if(e=e.href?e.href.replace(/^.*[\\\/]/,""):"",e===t)return!0;return!1}as("circular-view.css")||function(){const t=document.createElement("style");t.setAttribute("type","text/css"),t.innerHTML='.igv-circview-container {\n z-index: 2048;\n width: fit-content;\n height: fit-content;\n box-sizing: content-box;\n color: dimgray;\n font-family: "Open Sans", sans-serif;\n font-size: 12px;\n background-color: white;\n border-color: dimgray;\n border-style: solid;\n border-width: thin;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n}\n\n.igv-circview-toolbar {\n position: relative;\n width: 100%;\n height: 32px;\n background-color: lightgrey;\n border-bottom-style: solid;\n border-bottom-color: dimgray;\n border-bottom-width: thin;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n}\n\n.igv-circview-toolbar-button-container {\n height: 100%;\n width: fit-content;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n}\n.igv-circview-toolbar-button-container > div {\n margin: 4px;\n}\n\n.igv-circview-track-panel {\n z-index: 1024;\n position: absolute;\n top: 33px;\n left: 0;\n width: 100%;\n height: fit-content;\n border-bottom-style: solid;\n border-bottom-color: dimgray;\n border-bottom-width: thin;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n}\n.igv-circview-track-panel > div {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n}\n.igv-circview-track-panel > div > div {\n margin: 4px;\n}\n\n.igv-circview-swatch-button {\n cursor: pointer;\n padding: 5px;\n width: 8px;\n height: 8px;\n border: 1px solid #8d8b8b;\n border-radius: 16px;\n}\n\n.igv-circview-button {\n cursor: pointer;\n padding: 5px;\n color: #444;\n vertical-align: middle;\n text-align: center;\n font-family: "Open Sans", sans-serif;\n font-size: 12px;\n border: 1px solid #8d8b8b;\n border-radius: 4px;\n background: #efefef;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.2);\n}\n\n.igv-circview-button:hover {\n background: #efefef;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.6);\n}\n\n.igv-circview-button:active {\n color: #007bff;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.6);\n}\n\n/*# sourceMappingURL=circular-view.css.map */\n',document.head.insertBefore(t,document.head.childNodes[document.head.childNodes.length-1])}()}const Qc=t=>t.startsWith("chr")?t.substring(3):t;function Jc(t){const e=[],n=[];for(let r of t.wgChromosomeNames){const i=t.getChromosome(r);n.push(ll(i.name)),e.push({name:i.name,bpLength:i.bpLength})}return e}function tl(t,e,n,r){const i=no.addAlpha("all"===n.chr?e.color:ll(n.chr),r),o=no.addAlpha(e.color||"rgb(0,0,255)",r),s=e.name.replaceAll(" ","%20"),a="all"===n.chr?s:`${s} ${n.chr}:${n.start}-${n.end}`;e.browser.circularView.addChords(t,{track:a,color:i,trackColor:o}),e.browser.circularViewVisible||(e.browser.circularViewVisible=!0)}class el{constructor(t,{minTLENPercentile:e,maxTLENPercentile:n}){this.totalCount=0,this.frCount=0,this.rfCount=0,this.ffCount=0,this.sumF=0,this.sumF2=0,this.lp=void 0===e?.1:e,this.up=void 0===n?99.5:n,this.isizes=[],this.compute(t)}compute(t){for(let r of t)if(r.isProperPair()){var e=Math.abs(r.fragmentLength);this.sumF+=e,this.sumF2+=e*e,this.isizes.push(e);var n=r.pairOrientation;if("string"==typeof n&&4===n.length)switch(""+n.charAt(0)+n.charAt(2)){case"FF":case"RR":this.ffCount++;break;case"FR":this.frCount++;break;case"RF":this.rfCount++}this.totalCount++}this.ffCount/this.totalCount>.9?this.orienation="ff":this.frCount/this.totalCount>.9?this.orienation="fr":this.rfCount/this.totalCount>.9&&(this.orienation="rf"),this.minTLEN=0===this.lp?0:nl(this.isizes,this.lp),this.maxTLEN=nl(this.isizes,this.up)}}function nl(t,e){if(0!==t.length){var n=Math.floor(t.length*(e/100));return t.sort((function(t,e){return t-e})),t[n]}}class rl extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type="alignment",void 0===t.alleleFreqThreshold&&(t.alleleFreqThreshold=.2),this.featureSource=new mc(t,this.browser),this.showCoverage=void 0===t.showCoverage||t.showCoverage,this.showAlignments=void 0===t.showAlignments||t.showAlignments,this.coverageTrack=new il(t,this),this.alignmentTrack=new ol(t,this),this.alignmentTrack.setTop(this.coverageTrack,this.showCoverage),this.visibilityWindow=t.visibilityWindow||3e4,this.viewAsPairs=t.viewAsPairs,this.pairsSupported=!1!==t.pairsSupported,this.showSoftClips=t.showSoftClips,this.showAllBases=t.showAllBases,this.showInsertions=!1!==t.showInsertions,this.showMismatches=!1!==t.showMismatches,this.color=t.color,this.coverageColor=t.coverageColor,t.sort&&(Array.isArray(t.sort)?this.assignSort(t.sort[0]):this.assignSort(t.sort)),this.height=void 0!==t.height?t.height:300}set height(t){this._height=t,this.coverageTrack&&this.showAlignments&&(this.alignmentTrack.height=this.showCoverage?t-this.coverageTrack.height:t)}get height(){return this._height}get minTemplateLength(){const t=void 0!==this.config.minTLEN?this.config.minTLEN:this.config.minFragmentLength;return void 0!==t?t:this._pairedEndStats?this._pairedEndStats.minTLEN:0}get maxTemplateLength(){const t=void 0!==this.config.maxTLEN?this.config.maxTLEN:this.config.maxFragmentLength;return void 0!==t?t:this._pairedEndStats?this._pairedEndStats.maxTLEN:1e3}sort(t){t=this.assignSort(t);for(let e of this.trackView.viewports)if(e.containsPosition(t.chr,t.position)){const n=e.cachedFeatures;n&&(sl(t,n),e.repaint())}}assignSort(t){if(t.locus){const e=function(t){const e=t.split(":"),n=e[1].split("-"),r={chr:e[0],start:Number.parseInt(n[0].replace(/,/g,""))-1};return n.length>1?r.end=Number.parseInt(n[1].replace(/,/g,"")):r.end=r.start+1,r}(t.locus);t.chr=e.chr,t.position=e.start}else t.position--;return t.direction="ASC"===t.direction||!0===t.direction,t.chr=this.browser.genome.getChromosomeName(t.chr),this.sortObject=t,this.sortObject}async getFeatures(t,e,n,r,i){const o=await this.featureSource.getAlignments(t,e,n);if(o.paired&&!this._pairedEndStats&&!this.config.maxFragmentLength){const t=new el(o.alignments,this.config);t.totalCount>99&&(this._pairedEndStats=t)}o.alignments=void 0;const s=this.sortObject;return s&&s.chr===t&&s.position>=e&&s.position<=n&&sl(s,o),o}computePixelHeight(t){return(this.showCoverage?this.coverageTrack.height:0)+(this.showAlignments?this.alignmentTrack.computePixelHeight(t):0)+15}draw(t){ls.fillRect(t.context,0,t.pixelTop,t.pixelWidth,t.pixelHeight,{fillStyle:"rgb(255, 255, 255)"}),!0===this.showCoverage&&this.coverageTrack.height>0?(this.trackView.axisCanvas.style.display="block",this.coverageTrack.draw(t)):this.trackView.axisCanvas.style.display="none",!0===this.showAlignments&&(this.alignmentTrack.setTop(this.coverageTrack,this.showCoverage),this.alignmentTrack.draw(t))}paintAxis(t,e,n){this.coverageTrack.paintAxis(t,e,this.coverageTrack.height)}contextMenuItemList(t){return this.alignmentTrack.contextMenuItemList(t)}popupData(t){return!0===this.showCoverage&&t.y>=this.coverageTrack.top&&t.y<this.coverageTrack.height?this.coverageTrack.popupData(t):this.alignmentTrack.popupData(t)}clickedFeatures(t){return!0===this.showCoverage&&t.y>=this.coverageTrack.top&&t.y<this.coverageTrack.height?[this.coverageTrack.getClickedObject(t)]:[this.alignmentTrack.getClickedObject(t)]}menuItemList(){let t=[];t=t.concat(Oo.numericDataMenuItems(this.trackView)),t.push("<hr/>");const e=de('<div class="igv-track-menu-category">');e.text("Color by:"),t.push({name:void 0,object:e,click:void 0,init:void 0});const n=[{key:"strand",label:"read strand"}];this.alignmentTrack.hasPairs&&(n.push({key:"firstOfPairStrand",label:"first-of-pair strand"}),n.push({key:"pairOrientation",label:"pair orientation"}),n.push({key:"tlen",label:"insert size (TLEN)"}),n.push({key:"unexpectedPair",label:"pair orientation & insert size (TLEN)"}));const r="tag"+(this.alignmentTrack.colorByTag?" ("+this.alignmentTrack.colorByTag+")":"");n.push({key:"tag",label:r});for(let e of n){const n=this.alignmentTrack.colorBy===e.key;t.push(this.colorByCB(e,n))}const i=()=>{if(!this.autoHeight){const t=15+(this.showCoverage?this.coverageTrack.height:0)+(this.showAlignments?this.alignmentTrack.height:0);this.trackView.setTrackHeight(t)}};t.push("<hr/>"),t.push({object:de(Po("Show Coverage",this.showCoverage)),click:()=>{this.showCoverage=!this.showCoverage,i(),this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push({object:de(Po("Show Alignments",this.showAlignments)),click:()=>{this.showAlignments=!this.showAlignments,i(),this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push("<hr/>"),t.push({object:de(Po("Show all bases",this.showAllBases)),click:()=>{this.showAllBases=!this.showAllBases,this.config.showAllBases=this.showAllBases,this.trackView.repaintViews()}}),t.push("<hr/>"),t.push({object:de(Po("Show mismatches",this.showMismatches)),click:()=>{this.showMismatches=!this.showMismatches,this.config.showMismatches=this.showMismatches,this.trackView.repaintViews()}}),t.push({object:de(Po("Show insertions",this.showInsertions)),click:()=>{this.showInsertions=!this.showInsertions,this.config.showInsertions=this.showInsertions,this.getCachedAlignmentContainers(),this.trackView.repaintViews()}}),t.push({object:de(Po("Show soft clips",this.showSoftClips)),click:()=>{this.showSoftClips=!this.showSoftClips,this.config.showSoftClips=this.showSoftClips,this.featureSource.setShowSoftClips(this.showSoftClips);const t=this.getCachedAlignmentContainers();for(let e of t)e.setShowSoftClips(this.showSoftClips);this.trackView.repaintViews()}}),this.pairsSupported&&this.alignmentTrack.hasPairs&&(t.push("<hr/>"),t.push({object:de(Po("View as pairs",this.viewAsPairs)),click:()=>{this.viewAsPairs=!this.viewAsPairs,this.config.viewAsPairs=this.viewAsPairs,this.featureSource.setViewAsPairs(this.viewAsPairs);const t=this.getCachedAlignmentContainers();for(let e of t)e.setViewAsPairs(this.viewAsPairs);this.trackView.repaintViews()}})),this.browser.circularView&&(this.alignmentTrack.hasPairs||this.alignmentTrack.hasSupplemental)&&(t.push("<hr/>"),this.alignmentTrack.hasPairs&&t.push({label:"Add discordant pairs to circular view",click:()=>{for(let t of this.trackView.viewports)this.addPairedChordsForViewport(t)}}),this.alignmentTrack.hasSupplemental&&t.push({label:"Add split reads to circular view",click:()=>{for(let t of this.trackView.viewports)this.addSplitChordsForViewport(t)}})),t.push("<hr/>");const o=de('<div class="igv-track-menu-category">');return o.text("Display mode:"),t.push({name:void 0,object:o,click:void 0,init:void 0}),t.push({object:de(Po("expand","EXPANDED"===this.alignmentTrack.displayMode)),click:()=>{this.alignmentTrack.displayMode="EXPANDED",this.config.displayMode="EXPANDED",this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push({object:de(Po("squish","SQUISHED"===this.alignmentTrack.displayMode)),click:()=>{this.alignmentTrack.displayMode="SQUISHED",this.config.displayMode="SQUISHED",this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t}colorByCB(t,e){return{name:void 0,object:de(Po(t.label,e)),click:e=>{"tag"!==t.key?t.key===this.alignmentTrack.colorBy?(this.alignmentTrack.colorBy="none",this.config.colorBy="none",this.trackView.repaintViews()):(this.alignmentTrack.colorBy=t.key,this.config.colorBy=t.key,this.trackView.repaintViews()):this.browser.inputDialog.present({label:"Tag Name",value:this.alignmentTrack.colorByTag?this.alignmentTrack.colorByTag:"",callback:t=>{t?(this.alignmentTrack.colorBy="tag",this.alignmentTrack.colorByTag=t,this.alignmentTrack.tagColors||(this.alignmentTrack.tagColors=new _c("Set1"))):(this.alignmentTrack.colorBy="none",this.alignmentTrack.colorByTag=""),this.trackView.repaintViews()}},e)},init:void 0}}dispose(){this.trackView=void 0}getState(){const t=super.getState();return this.sortObject&&(t.sort={chr:this.sortObject.chr,position:this.sortObject.position+1,option:this.sortObject.option,direction:this.sortObject.direction?"ASC":"DESC"}),t}getCachedAlignmentContainers(){return this.trackView.viewports.map((t=>t.cachedFeatures))}get dataRange(){return this.coverageTrack.dataRange}set dataRange(t){this.coverageTrack.dataRange=t}get logScale(){return this.coverageTrack.logScale}set logScale(t){this.coverageTrack.logScale=t}get autoscale(){return this.coverageTrack.autoscale}set autoscale(t){this.coverageTrack.autoscale=t}addPairedChordsForViewport(t){const e=this.maxTemplateLength,n=[],r=t.referenceFrame;for(let i of t.cachedFeatures.allAlignments())i.end>=r.start&&i.start<=r.end&&(i.paired?i.end-i.start>e&&n.push(i):i.mate&&i.mate.chr&&(i.mate.chr!==i.chr||Math.max(i.fragmentLength)>e)&&n.push(i));tl((t=>{const e=[];for(let n of t)if(n.paired)n.firstAlignment&&n.secondAlignment&&e.push({uniqueId:n.readName,refName:Qc(n.firstAlignment.chr),start:n.firstAlignment.start,end:n.firstAlignment.end,mate:{refName:Qc(n.secondAlignment.chr),start:n.secondAlignment.start,end:n.secondAlignment.end}});else{const t=n.mate;t&&t.chr&&t.position&&e.push({uniqueId:n.readName,refName:Qc(n.chr),start:n.start,end:n.end,mate:{refName:Qc(t.chr),start:t.position-1,end:t.position}})}return e})(n),this,r,.02)}addSplitChordsForViewport(t){const e=[],n=t.referenceFrame;for(let r of t.cachedFeatures.allAlignments()){const t=r.hasTag("SA");r.end>=n.start&&r.start<=n.end&&t&&e.push(r)}tl((t=>{const e=t=>{const e=Sa(t.tags().SA);let r=0;for(let i of e)i.start!==t.start&&n.push({uniqueId:`${t.readName}_${r++}`,refName:Qc(t.chr),start:t.start,end:t.end,mate:{refName:Qc(i.chr),start:i.start,end:i.start+i.lenOnRef}})},n=[];for(let n of t)n.paired?(e(n.firstAlignment),n.secondAlignment&&e(n.secondAlignment)):e(n);return n})(e),this,n,.02)}}class il{constructor(t,e){this.parent=e,this.featureSource=e.featureSource,this.height=void 0!==t.coverageTrackHeight?t.coverageTrackHeight:50,this.paintAxis=yc,this.top=0,this.autoscale=t.autoscale||void 0===t.max,this.autoscale||(this.dataRange={min:t.min||0,max:t.max})}draw(t){const e=t.pixelTop;t.pixelHeight;const n=this.parent.browser.nucleotideColors;if(e>this.height)return;const r=t.context,i=t.features.coverageMap;let o;i.refSeq&&(o=i.refSeq.toUpperCase());const s=t.bpPerPixel,a=t.bpStart,c=a+t.pixelWidth*s+1;let l;l=this.parent.coverageColor?this.parent.coverageColor:void 0!==this.parent.color?no.darkenLighten(this.parent.color,-35):"rgb(150, 150, 150)",ls.setProperties(r,{fillStyle:l,strokeStyle:l});const h=Math.max(1,Math.ceil(1/s));for(let t=0,e=i.coverage.length;t<e;t++){const e=i.bpStart+t;if(e<a)continue;if(e>c)break;const n=i.coverage[t];if(!n)continue;const o=Math.round(n.total/this.dataRange.max*this.height),l=this.height-o,u=Math.floor((e-a)/s);ls.fillRect(r,u,l,h,o)}if(o)for(let t=0,e=i.coverage.length;t<e;t++){const e=i.bpStart+t;if(e<a)continue;if(e>c)break;const l=i.coverage[t];if(!l)continue;const u=l.total/this.dataRange.max*this.height;let f=this.height-u;const d=Math.floor((e-a)/s),p=o[t];if(l.isMismatch(p)){ls.setProperties(r,{fillStyle:n[p]}),ls.fillRect(r,d,f,h,u);let t=0;for(let e of["A","C","T","G"]){const i=(l["pos"+e]+l["neg"+e])/this.dataRange.max*this.height;f=this.height-i-t,t+=i,ls.setProperties(r,{fillStyle:n[e]}),ls.fillRect(r,d,f,h,i)}}}}getClickedObject(t){let e=t.viewport.cachedFeatures;if(!e||0===e.length)return;const n=Math.floor(t.genomicLocation),r=e.coverageMap,i=Math.floor(n-r.bpStart);return r.coverage[i]}popupData(t){const e=[],n=this.getClickedObject(t);if(n){const r=Math.floor(t.genomicLocation),i=t.viewport.referenceFrame;e.push(i.chr+":"+_e(1+r)),e.push({name:"Total Count",value:n.total});let o=n.posA+n.negA;o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posA+"+, "+n.negA+"- )"),e.push({name:"A",value:o}),o=n.posC+n.negC,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posC+"+, "+n.negC+"- )"),e.push({name:"C",value:o}),o=n.posG+n.negG,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posG+"+, "+n.negG+"- )"),e.push({name:"G",value:o}),o=n.posT+n.negT,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posT+"+, "+n.negT+"- )"),e.push({name:"T",value:o}),o=n.posN+n.negN,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posN+"+, "+n.negN+"- )"),e.push({name:"N",value:o}),e.push("<HR/>"),e.push({name:"DEL",value:n.del.toString()}),e.push({name:"INS",value:n.ins.toString()})}return e}}class ol{constructor(t,e){this.parent=e,this.browser=e.browser,this.featureSource=e.featureSource,this.top=0===t.coverageTrackHeight?0:t.coverageTrackHeight+5,this.displayMode=t.displayMode||"EXPANDED",this.alignmentRowHeight=t.alignmentRowHeight||14,this.squishedRowHeight=t.squishedRowHeight||3,this.negStrandColor=t.negStrandColor||"rgba(150, 150, 230, 0.75)",this.posStrandColor=t.posStrandColor||"rgba(230, 150, 150, 0.75)",this.insertionColor=t.insertionColor||"rgb(138, 94, 161)",this.deletionColor=t.deletionColor||"black",this.skippedColor=t.skippedColor||"rgb(150, 170, 170)",this.pairConnectorColor=t.pairConnectorColor,this.smallTLENColor=t.smallTLENColor||t.smallFragmentLengthColor||"rgb(0, 0, 150)",this.largeTLENColor=t.largeTLENColor||t.largeFragmentLengthColor||"rgb(200, 0, 0)",this.pairOrientation=t.pairOrienation||"fr",this.pairColors={},this.pairColors.RL=t.rlColor||"rgb(0, 150, 0)",this.pairColors.RR=t.rrColor||"rgb(20, 50, 200)",this.pairColors.LL=t.llColor||"rgb(0, 150, 150)",this.colorBy=t.colorBy||"unexpectedPair",this.colorByTag=t.colorByTag?t.colorByTag.toUpperCase():void 0,this.bamColorTag=void 0===t.bamColorTag?"YC":t.bamColorTag,this.hideSmallIndels=t.hideSmallIndels,this.indelSizeThreshold=t.indelSizeThreshold||1,this.hasPairs=!1,this.hasSupplemental=!1}setTop(t,e){this.top=0===t.height||!1===e?0:5+t.height}computePixelHeight(t){if(t.packedAlignmentRows){return(t.hasDownsampledIntervals()?10:0)+("SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight)*t.packedAlignmentRows.length+5}return 0}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=i+o*r+1,a=this.parent.showSoftClips,c=this.parent.showAllBases,l=this.browser.nucleotideColors,h=e.packedAlignmentRows;n.save();let u=e.sequence;u&&(u=u.toUpperCase());let f=0,d=t.pixelTop;this.top&&n.translate(0,this.top);const p=d+t.pixelHeight;e.hasDownsampledIntervals()?(f=10,e.downsampledIntervals.forEach((function(t){var e=(t.start-i)/r,o=(t.end-i)/r;o-e>5&&(e+=1,o-=1),ls.fillRect(n,e,2,o-e,3,{fillStyle:"black"})}))):f=0,this.alignmentsYOffset=f;const g="SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight;if(h){const t=h.length;for(let e=0;e<t;e++){const t=h[e],n=f+g*e,r=g<=4?g:g-2;if(n>p)break;if(!(n+r<d))for(let e of t.alignments)if(this.hasPairs=this.hasPairs||e.isPaired(),this.browser.circularView&&(this.hasSupplemental=this.hasSupplemental||e.hasTag("SA")),!(e.start+e.lengthOnRef<i)){if(e.start>s)break;!0!==e.hidden&&(e instanceof ua?(m.call(this,e,n,r),v.call(this,e.firstAlignment,n,r),e.secondAlignment&&v.call(this,e.secondAlignment,n,r)):v.call(this,e,n,r))}}}function m(t,e,o){var a=this.getConnectorColor(t.firstAlignment),c=(t.connectingStart-i)/r,l=(t.connectingEnd-i)/r,h=e+o/2;t.connectingEnd<i||t.connectingStart>s||(t.mq<=0&&(a=no.addAlpha(a,.15)),ls.setProperties(n,{fillStyle:a,strokeStyle:a}),ls.strokeLine(n,c,h,l,h))}function v(t,o,h){if(t.start+t.lengthOnRef<i||t.start>s)return;const f=a?t.blocks:t.blocks.filter((t=>"S"!==t.type));let d=this.getAlignmentColor(t);const p=d;t.mq<=0&&(d=no.addAlpha(d,.15)),ls.setProperties(n,{fillStyle:d,strokeStyle:p});for(let t=0;t<f.length;t++){const e=f[t];if(!(t!==f.length-1&&f[t+1].start<i)&&(m.call(this,e,t),e.start+e.len>s))break}if(t.insertions&&this.parent.showInsertions){let e=-1;for(let a of t.insertions){if(this.hideSmallIndels&&a.len<=this.indelSizeThreshold)continue;if(a.start<i)continue;if(a.start>s)break;const t=(a.start-i)/r-1;if(t-e>2){const r=3;ls.fillRect(n,t,o-1,r,h+2,{fillStyle:this.insertionColor}),e=t}}}if(t.gaps){const e=o+h/2;for(let o of t.gaps){const t=(o.start-i)/r,s=(o.start+o.len-i)/r,a="D"===o.type?this.deletionColor:this.skippedColor;ls.strokeLine(n,t,e,s,e,{strokeStyle:a})}}function m(s,a){const m=s.start-e.start,b=(s.start-i)/r,w=(s.start+s.len-i)/r,y=Math.max(1,w-b),x=100/r,k=Math.min(g/2,x/6),_="S"===s.type,S=t.mq<=0||this.highlightedAlignmentReadNamed===t.readName||_;let C=p;this.highlightedAlignmentReadNamed===t.readName?C="red":_&&(C="rgb(50,50,50)");const E=!0===t.strand&&a===f.length-1,A=!1===t.strand&&0===a;if(E|A){let t,e;E?(t=[b,w,w+k,w,b,b],e=[o,o,o+h/2,o+h,o+h,o]):A&&(t=[w,b,b-k,b,w,w],e=[o,o,o+h/2,o+h,o+h,o]),ls.fillPolygon(n,t,e,{fillStyle:d}),S&&ls.strokePolygon(n,t,e,{strokeStyle:C})}else ls.fillRect(n,b,o,y,h,{fillStyle:d}),S&&(n.save(),n.strokeStyle=C,n.strokeRect(b,o,y,h),n.restore());if(_||c||this.parent.showMismatches&&u&&t.seq&&"*"!==t.seq){const e=t.seq?t.seq.toUpperCase():void 0,a=t.qual,f=s.seqOffset;for(let t=0,d=s.len;t<d;t++){if(m+t<0)continue;let d=e?e.charAt(f+t):"";const p=u.charAt(m+t);if("="===d&&(d=p),"X"===d||p!==d||_||c){let e;if(!_&&void 0!==a&&a.length>f+t){e=al(a[f+t],l[d])}else e=l[d];if(e){const a=(s.start+t-i)/r,c=Math.max(1,1/r);v(n,r,{x:a,y:o,width:c,height:h},e,d)}}}}}function v(t,e,n,r,i){var o;if(.1,e<=.1&&n.height>=8){const e=Math.min(10,n.height);t.font=e+"px sans-serif",o=n.x+n.width/2,ls.strokeText(t,i,o-t.measureText(i).width/2,e-1+n.y,{strokeStyle:r})}else ls.fillRect(t,n.x,n.y,n.width,n.height,{fillStyle:r})}}n.restore()}popupData(t){const e=this.getClickedObject(t);return e?e.popupData(t.genomicLocation):void 0}contextMenuItemList(t){const e=t.viewport,n=[],r=n=>{const r=this.parent.sortObject,i=!r||r.position!==Math.floor(t.genomicLocation)||!r.direction,o={chr:e.referenceFrame.chr,position:Math.floor(t.genomicLocation),option:n,direction:i};this.parent.sortObject=o,sl(o,e.cachedFeatures),e.repaint()};n.push("<b>Sort by...</b>"),n.push({label:"&nbsp; base",click:()=>r("BASE")}),n.push({label:"&nbsp; read strand",click:()=>r("STRAND")}),n.push({label:"&nbsp; insert size",click:()=>r("INSERT_SIZE")}),n.push({label:"&nbsp; gap size",click:()=>r("GAP_SIZE")}),n.push({label:"&nbsp; chromosome of mate",click:()=>r("MATE_CHR")}),n.push({label:"&nbsp; mapping quality",click:()=>r("MQ")}),n.push({label:"&nbsp; read name",click:()=>r("READ_NAME")}),n.push({label:"&nbsp; tag",click:()=>{const n=this.parent.sortObject,r=!n||n.position!==Math.floor(t.genomicLocation)||!n.direction,i={label:"Tag Name",value:this.sortByTag?this.sortByTag:"",callback:n=>{if(n){const i={chr:e.referenceFrame.chr,position:Math.floor(t.genomicLocation),option:"TAG",tag:n,direction:r};this.sortByTag=n,this.parent.sortObject=i,sl(i,e.cachedFeatures),e.repaint()}}};this.browser.inputDialog.present(i,t.event)}}),n.push("<hr/>");const i=this.getClickedObject(t);if(i){const e=this.parent.showSoftClips,r="function"==typeof i.alignmentContaining?i.alignmentContaining(t.genomicLocation,e):i;r&&(r.isPaired()&&r.isMateMapped()&&n.push({label:"View mate in split screen",click:()=>{if(r.mate){const e=t.viewport.referenceFrame;if(this.browser.genome.getChromosome(r.mate.chr)){this.highlightedAlignmentReadNamed=r.readName;const t=e.end-e.start,n=r.mate.position-t/2,i=r.mate.position+t/2;this.browser.addMultiLocusPanel(r.mate.chr,n,i,e)}else Qo.presentAlert(`Reference does not contain chromosome: ${r.mate.chr}`)}},init:void 0}),n.push({label:"View read sequence",click:()=>{const t=r.seq;t&&"*"!==t?Qo.presentAlert(t):Qo.presentAlert("Read sequence: *")}}),Ss()&&n.push({label:"Copy read sequence",click:async()=>{const t=r.seq;try{await navigator.clipboard.writeText(t)}catch(t){console.error(t),Qo.presentAlert(`error copying sequence to clipboard ${t}`)}}}),n.push("<hr/>"))}return this.browser.circularView&&(this.hasPairs||this.hasSupplemental)&&(this.hasPairs&&n.push({label:"Add discordant pairs to circular view",click:()=>{this.parent.addPairedChordsForViewport(e)}}),this.hasSupplemental&&n.push({label:"Add split reads to circular view",click:()=>{this.parent.addSplitChordsForViewport(e)}}),n.push("<hr/>")),n}getClickedObject(t){const e=t.viewport,n=t.y,r=t.genomicLocation,i=this.parent.showSoftClips;let o=e.cachedFeatures;if(!o||0===o.length)return;let s=o.packedAlignmentRows,a=o.downsampledIntervals;const c="SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight;let l=Math.floor((n-this.top-this.alignmentsYOffset)/c);if(l<0){for(let t=0;t<a.length;t++)if(a[t].start<=r&&a[t].end>=r)return a[t]}else if(l<s.length){const t=s[l].alignments.filter((t=>t.containsLocation(r,i)));if(t.length>0)return t[0]}}getConnectorColor(t){if(this.pairConnectorColor)return this.pairConnectorColor;switch(this.colorBy){case"strand":case"firstOfPairStrand":case"pairOrientation":case"tag":return this.parent.color||"rgb(200, 200, 200)";default:return this.getAlignmentColor(t)}}getAlignmentColor(t){let e=this.parent.color||"rgb(185, 185, 185)";const n=this.colorBy;switch(n){case"strand":e=t.strand?this.posStrandColor:this.negStrandColor;break;case"firstOfPairStrand":t instanceof ua?e=t.firstOfPairStrand()?this.posStrandColor:this.negStrandColor:t.isPaired()&&(t.isFirstOfPair()?e=t.strand?this.posStrandColor:this.negStrandColor:t.isSecondOfPair()?e=t.strand?this.negStrandColor:this.posStrandColor:console.error("ERROR. Paired alignments are either first or second."));break;case"unexpectedPair":case"pairOrientation":if(this.pairOrientation&&t.pairOrientation){const n=cl[this.pairOrientation];if(n){const r=this.pairColors[n[t.pairOrientation]];if(r){e=r;break}}}if("pairOrientation"===n)break;case"tlen":case"fragmentLength":t.mate&&t.isMateMapped()&&(t.mate.chr!==t.chr?e=ll(t.mate.chr):this.parent.minTemplateLength&&Math.abs(t.fragmentLength)<this.parent.minTemplateLength?e=this.smallTLENColor:this.parent.maxTemplateLength&&Math.abs(t.fragmentLength)>this.parent.maxTemplateLength&&(e=this.largeTLENColor));break;case"tag":const r=t.tags()[this.colorByTag];void 0!==r&&(this.bamColorTag===this.colorByTag?e="rgb("+r+")":(this.tagColors||(this.tagColors=new _c("Set1")),e=this.tagColors.getColor(r)));break;default:e=this.parent.color||"rgb(185, 185, 185)"}return e}}function sl(t,e){const n=t.direction;for(let n of e.packedAlignmentRows)n.updateScore(t,e);e.packedAlignmentRows.sort((function(t,e){const r=t.score>e.score?1:t.score<e.score?-1:0;return!0===n?r:-r}))}function al(t,e){let n;return n=t<5?.1:Math.max(.1,Math.min(1,.1+.9*(t-5)/15)),n=Math.round(10*n)/10,n<1&&(e=no.addAlpha(e,n)),e}const cl={fr:{F1R2:"LR",F2R1:"LR",F1F2:"LL",F2F1:"LL",R1R2:"RR",R2R1:"RR",R1F2:"RL",R2F1:"RL"},rf:{R1F2:"LR",R2F1:"LR",R1R2:"LL",R2R1:"LL",F1F2:"RR",F2F1:"RR",F1R2:"RL",F2R1:"RL"},ff:{F2F1:"LR",R1R2:"LR",F2R1:"LL",R1F2:"LL",R2F1:"RR",F1R2:"RR",R2R1:"RL",F1F2:"RL"}};function ll(t){if(hl[t])return hl[t];if(hl["chr"+t]){const e=hl["chr"+t];return hl[t]=e,e}{const e=no.randomRGB(0,255);return hl[t]=e,e}}const hl={chrX:"rgb(204, 153, 0)",chrY:"rgb(153, 204, 0)",chrUn:"rgb(50, 50, 50)",chr1:"rgb(80, 80, 255)",chrI:"rgb(139, 155, 187)",chr2:"rgb(206, 61, 50)",chrII:"rgb(206, 61, 50)",chr2a:"rgb(216, 71, 60)",chr2b:"rgb(226, 81, 70)",chr3:"rgb(116, 155, 88)",chrIII:"rgb(116, 155, 88)",chr4:"rgb(240, 230, 133)",chrIV:"rgb(240, 230, 133)",chr5:"rgb(70, 105, 131)",chr6:"rgb(186, 99, 56)",chr7:"rgb(93, 177, 221)",chr8:"rgb(128, 34, 104)",chr9:"rgb(107, 215, 107)",chr10:"rgb(213, 149, 167)",chr11:"rgb(146, 72, 34)",chr12:"rgb(131, 123, 141)",chr13:"rgb(199, 81, 39)",chr14:"rgb(213, 143, 92)",chr15:"rgb(122, 101, 165)",chr16:"rgb(228, 175, 105)",chr17:"rgb(59, 27, 83)",chr18:"rgb(205, 222, 183)",chr19:"rgb(97, 42, 121)",chr20:"rgb(174, 31, 99)",chr21:"rgb(231, 199, 111)",chr22:"rgb(90, 101, 94)",chr23:"rgb(204, 153, 0)",chr24:"rgb(153, 204, 0)",chr25:"rgb(51, 204, 0)",chr26:"rgb(0, 204, 51)",chr27:"rgb(0, 204, 153)",chr28:"rgb(0, 153, 204)",chr29:"rgb(10, 71, 255)",chr30:"rgb(71, 117, 255)",chr31:"rgb(255, 194, 10)",chr32:"rgb(255, 209, 71)",chr33:"rgb(153, 0, 51)",chr34:"rgb(153, 26, 0)",chr35:"rgb(153, 102, 0)",chr36:"rgb(128, 153, 0)",chr37:"rgb(51, 153, 0)",chr38:"rgb(0, 153, 26)",chr39:"rgb(0, 153, 102)",chr40:"rgb(0, 128, 153)",chr41:"rgb(0, 51, 153)",chr42:"rgb(26, 0, 153)",chr43:"rgb(102, 0, 153)",chr44:"rgb(153, 0, 128)",chr45:"rgb(214, 0, 71)",chr46:"rgb(255, 20, 99)",chr47:"rgb(0, 214, 143)",chr48:"rgb(20, 255, 177)"};let ul,fl;class dl extends sa{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.rulerSweeper=new la(this),this.$multiLocusCloseButton=de("<div>",{class:"igv-multi-locus-close-button"}),this.$viewport.append(this.$multiLocusCloseButton),this.$multiLocusCloseButton.get(0).appendChild(we("times-circle")),this.$multiLocusCloseButton.click((()=>{this.browser.removeMultiLocusPanel(this.referenceFrame)})),this.$rulerLabel=de("<div>",{class:"igv-multi-locus-ruler-label"}),this.$viewport.append(this.$rulerLabel),this.$rulerLabel.click((async()=>{await this.browser.gotoMultilocusPanel(this.referenceFrame)})),this.$tooltip=de("<div>",{class:"igv-ruler-tooltip"}),this.$tooltip.height(this.$viewport.height()),this.$viewport.append(this.$tooltip),this.$tooltipContent=de("<div>"),this.$tooltip.append(this.$tooltipContent),this.attachMouseHandlers(na.isWholeGenomeView(this.referenceFrame.chr)),this.$tooltip.hide(),this.dismissLocusLabel()}presentLocusLabel(t){this.$rulerLabel.get(0).innerHTML="",this.$rulerLabel.get(0).style.backgroundColor=ll(this.referenceFrame.chr),this.$rulerLabel.get(0).appendChild((()=>{const e=`<div>${this.referenceFrame.getMultiLocusLabel(t)}</div>`;return document.createRange().createContextualFragment(e).firstChild})()),this.$rulerLabel.show(),this.$multiLocusCloseButton.show()}presentLocusLabel_Square_Dot(t){this.$rulerLabel.get(0).innerHTML="",this.$rulerLabel.get(0).appendChild((()=>{const t=`<div>\n <?xml version="1.0" encoding="UTF-8"?>\n <svg width="14px" height="14px" viewBox="0 0 89 89" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n <g>\n <circle id="Oval" fill="${ll(this.referenceFrame.chr)}" cx="44.5" cy="44.5" r="44.5"></circle>\n </g>\n </svg>\n </div>`;return document.createRange().createContextualFragment(t).firstChild})()),this.$rulerLabel.get(0).appendChild((()=>{const e=`<div>${this.referenceFrame.getMultiLocusLabel(t)}</div>`;return document.createRange().createContextualFragment(e).firstChild})()),this.$rulerLabel.show(),this.$multiLocusCloseButton.show()}dismissLocusLabel(){this.$rulerLabel.hide(),this.$multiLocusCloseButton.hide()}attachMouseHandlers(t){if(this.namespace=`.ruler_track_viewport_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}`,this.$viewport.off(this.namespace),!0===t){const t=this.browser.referenceFrameList.indexOf(this.referenceFrame),e=`click${this.namespace}`;this.$viewport.on(e,(e=>{const{x:n}=be(e,this.$viewport.get(0)),r=Math.round(this.referenceFrame.start+this.referenceFrame.toBP(n));let i;const{chr:o}=this.browser.genome.getChromosomeCoordinate(r);if(1===this.browser.referenceFrameList.length)i=o;else{let e=this.browser.referenceFrameList.map((({locusSearchString:t})=>t));e[t]=o,i=e.join(" ")}this.browser.search(i)})),this.$viewport.get(0).style.cursor="pointer"}else this.$viewport.get(0).style.cursor="default"}mouseMove(t){if(!0===this.browser.cursorGuideVisible){void 0===fl?(fl=this,this.$tooltip.show()):fl.guid!==this.guid?(fl.$tooltip&&fl.$tooltip.hide(),this.$tooltip.show(),fl=this):this.$tooltip.show();if(this.browser.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(this.referenceFrame.chr))return void this.$tooltip.hide();const{x:e}=be(t,this.$viewport.get(0)),{start:n,bpPerPixel:r}=this.referenceFrame,i=Math.round(.5+n+Math.max(0,e)*r);this.$tooltipContent.text(_e(i));const{width:o}=this.$tooltipContent.get(0).getBoundingClientRect(),{width:s}=this.$viewport.get(0).getBoundingClientRect();this.$tooltip.css({left:`${Qi(e,0,s-o)}px`}),clearTimeout(ul),ul=setTimeout((()=>{this.$tooltip&&this.$tooltip.hide()}),1e4)}}startSpinner(){}stopSpinner(){}dispose(){this.rulerSweeper.dispose(),super.dispose()}}class pl extends sa{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.canvas=document.createElement("canvas"),this.canvas.className="igv-ideogram-canvas",this.$content.append(de(this.canvas)),this.ideogram_ctx=this.canvas.getContext("2d"),this.addMouseHandlers()}addMouseHandlers(){this.addViewportClickHandler(this.$viewport.get(0))}addViewportClickHandler(t){this.boundClickHandler=function(t){const{xNormalized:e,width:n}=be(t,this.ideogram_ctx.canvas),{bpLength:r}=this.browser.genome.getChromosome(this.referenceFrame.chr),i=this.referenceFrame.bpPerPixel*n/r;let o=e;o-i/2<0&&(o=i/2);o+i/2>1&&(o=1-i/2);const s=Math.round((o-i/2)*r),a=Math.round((o+i/2)*r);this.referenceFrame.start=s,this.referenceFrame.end=a,this.referenceFrame.bpPerPixel=(a-s)/n,this.browser.updateViews(this.referenceFrame,this.browser.trackViews,!0)}.bind(this),t.addEventListener("click",this.boundClickHandler)}setWidth(t){this.$viewport.width(t)}drawSVGWithContext(t,e,n,r,i,o,s){t.saveWithTranslationAndClipRect(r,i,o,e,n,s),this.trackView.track.draw({context:t,referenceFrame:this.referenceFrame,pixelWidth:e,pixelHeight:n}),t.restore()}repaint(){this.draw({referenceFrame:this.referenceFrame})}draw({referenceFrame:t}){ls.configureHighDPICanvas(this.ideogram_ctx,this.$viewport.width(),this.$viewport.height()),this.trackView.track.draw({context:this.ideogram_ctx,referenceFrame:t,pixelWidth:this.$viewport.width(),pixelHeight:this.$viewport.height()})}startSpinner(){}stopSpinner(){}}function gl(t,e,n,r){return"ruler"===t.track.type?new dl(t,e,n,r):"ideogram"===t.track.id?new pl(t,e,n,r):new sa(t,e,n,r)}const ml={textAlign:"start",textBaseline:"bottom",strokeStyle:"black",fillStyle:"black"};class vl{constructor(t,e,n,r){this.guid=ve(),this.trackView=t,this.browser=t.browser,this.viewport=pe({class:"igv-viewport"}),e.appendChild(this.viewport),t.track.height&&(this.viewport.style.height=`${t.track.height}px`),this.canvas=document.createElement("canvas"),this.viewport.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this.trackScrollDelta=0,this.contentTop=0,this.setWidth(r),!1===this.browser.showSampleNames&&this.hide(),this.addMouseHandlers()}checkCanvas(){const t=window.devicePixelRatio,e=this.viewport.clientHeight,n=this.browser.sampleNameViewportWidth;if(this.canvas.width!==n*t||this.canvas.height!==e*t){const r=this.canvas;r.width=n*t,r.height=e*t,r.style.width=`${n}px`,r.style.height=`${e}px`,this.ctx=this.canvas.getContext("2d"),this.ctx.scale(t,t)}}setTop(t){if("function"==typeof this.trackView.track.getSamples){this.contentTop=t;const e=this.trackView.track.getSamples();this.repaint(e)}}setWidth(t){this.viewport.innerWidth=t,this.checkCanvas()}show(){this.viewport.style.display="block"}hide(){this.viewport.style.display="none"}async repaint(t){this.checkCanvas(),this.draw({context:this.ctx,samples:t})}draw({context:t,samples:e}){if(!e||0===e.names.length)return;!function(t,{textAlign:e,textBaseline:n,strokeStyle:r,fillStyle:i},o){const s=Math.min(o,10);t.font=`${s}px sans-serif`,t.textAlign=e,t.textBaseline=n,t.fillStyle=i}(t,ml,e.height);t.clearRect(0,0,t.canvas.width,t.canvas.height),t.fillStyle=function(t){const{r:e,g:n,b:r}=xc[t];return`rgb(${e},${n},${r})`}("lead");const n=this.viewport.getBoundingClientRect().height;let r=(e.yOffset||0)+this.contentTop;for(let i of e.names){if(r>n)break;if(r+e.height>0){const n=i,o=bl(t,n,r,e.height);t.fillText(n,4,o)}r+=e.height}}renderSVGContext(t,{deltaX:e,deltaY:n}){if("function"==typeof this.trackView.track.getSamples){const r=this.trackView.track.getSamples(),i=0,{width:o,height:s}=this.viewport.getBoundingClientRect(),a=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_sample_names_guid_${ve()}`;t.saveWithTranslationAndClipRect(a,e,n+i,o,s,-i),this.draw({context:t,samples:r}),t.restore()}}addMouseHandlers(){this.addViewportContextMenuHandler(this.viewport)}removeMouseHandlers(){this.removeViewportContextMenuHandler(this.viewport)}addViewportContextMenuHandler(t){this.boundContextMenuHandler=function(t){t.preventDefault(),t.stopPropagation();const e={label:"Name Panel Width",value:this.browser.sampleNameViewportWidth,callback:t=>{this.browser.sampleNameViewportWidth=parseInt(t);for(let{sampleNameViewport:t}of this.browser.trackViews)t.setWidth(this.browser.sampleNameViewportWidth);this.browser.layoutChange()}};this.browser.inputDialog.present(e,t)}.bind(this),t.addEventListener("contextmenu",this.boundContextMenuHandler)}removeViewportContextMenuHandler(t){t.removeEventListener("contextmenu",this.boundContextMenuHandler)}dispose(){this.removeMouseHandlers(),this.viewport.remove()}}function bl(t,e,n,r){return n+r-function(t,e,n){const{actualBoundingBoxAscent:r,actualBoundingBoxDescent:i}=t.measureText(e);return(n-(r+i))/2}(t,e,r)}class wl extends es{constructor({parent:t,width:e}){super({parent:t,width:e,border:"1px solid gray"})}configure(t,e){this.colorHandlers=e,this.setActiveColorHandler("color"),this.createSwatches(t)}setActiveColorHandler(t){this.activeColorHandler=this.colorHandlers[t]}createSwatches(t){this.container.querySelectorAll(".igv-ui-color-swatch").forEach((t=>t.remove()));const e=Object.values(lo);for(let t of e){const e=pe({class:"igv-ui-color-swatch"});this.container.appendChild(e),this.decorateSwatch(e,t)}if(t)for(let e of t){const t=pe({class:"igv-ui-color-swatch"});this.container.appendChild(t),this.decorateSwatch(t,e)}}decorateSwatch(t,e){t.style.backgroundColor=e,t.addEventListener("mouseenter",(()=>t.style.borderColor=e)),t.addEventListener("mouseleave",(()=>t.style.borderColor="white")),t.addEventListener("click",(t=>{t.stopPropagation(),this.activeColorHandler(e)})),t.addEventListener("touchend",(t=>{t.stopPropagation(),this.activeColorHandler(e)}))}}const yl=function(t){this.popover=pe({class:"igv-menu-popup"}),t.appendChild(this.popover);const e=pe({class:"igv-menu-popup-header"});this.popover.appendChild(e),xe(e,(()=>this.hide())),this.popoverContent=pe(),this.popover.appendChild(this.popoverContent),oo(this.popover,e),e.addEventListener("click",(t=>{t.stopPropagation(),t.preventDefault()})),this.hide()};yl.prototype.hide=function(){this.popover.style.display="none"},yl.prototype.presentMenuList=function(t){if(xl(),t.length>0){this.popoverContent.innerHTML="",t=Oo.trackMenuItemListHelper(t,this);for(let e of t){e.init&&e.init();let n=e.object;0===t.indexOf(e)&&n.removeClass("igv-track-menu-border-top"),n.hasClass("igv-track-menu-border-top")||n.hasClass("igv-menu-popup-check-container")||n.is("div")&&n.addClass("igv-menu-popup-shim"),this.popoverContent.appendChild(n.get(0))}this.popover.style.display="flex";const{width:e}=this.popover.getBoundingClientRect();this.popover.style.left=-e+"px",this.popover.style.top="0px"}},yl.prototype.presentTrackContextMenu=function(t,e){this.popoverContent.innerHTML="";const n=(r=e,i=this.popover,r.map((t=>{let e;if("string"==typeof t&&"<hr/>"===t)e=document.createElement("hr");else if("string"==typeof t)e=pe({class:"context-menu"}),e.innerHTML=t;else if("Node"==typeof t)e=t;else{if("function"==typeof t.init&&t.init(),"checkbox"===t.type)e=Po("Show all bases",t.value);else if("color"===t.type){const r=new wl({parent:i.parentElement,width:364});r.configure(void 0,{color:e=>t.click(e)}),e=pe({class:"context-menu"}),"string"==typeof t.label&&(e.innerHTML=t.label);const o=t=>{r.show(),ge(i),t.preventDefault(),t.stopPropagation()};e.addEventListener("click",o),e.addEventListener("touchend",o),e.addEventListener("mouseup",(function(t){t.preventDefault(),t.stopPropagation()}))}else e=pe({class:"context-menu"}),"string"==typeof t.label&&(e.innerHTML=t.label);if(t.click&&"color"!==t.type){function n(e){t.click(),ge(i),e.preventDefault(),e.stopPropagation()}e.addEventListener("click",n),e.addEventListener("touchend",n),e.addEventListener("mouseup",(function(t){t.preventDefault(),t.stopPropagation()}))}}return{el:e,init:t.init}})));var r,i;for(let{el:t}of n)this.popoverContent.appendChild(t);!function(t,e){e.style.display="flex";const{x:n,y:r}=be(t,e.parentNode),{width:i}=e.getBoundingClientRect(),o=n+i,{width:s}=e.parentNode.getBoundingClientRect();e.style.left=`${o>s?n-(o-s):n}px`,e.style.top=`${r}px`}(t,this.popover)},yl.prototype.dispose=function(){this.popoverContent.innerHTML="",this.popover.innerHTML="",Object.keys(this).forEach((function(t){this[t]=void 0}))};const xl=()=>{const t=document.querySelectorAll(".igv-menu-popup");for(let e=0;e<t.length;e++)t[e].style.display="none"},kl=new Set(["ruler","sequence","ideogram"]),_l=new Set(["ruler","sequence","ideogram"]);class Sl{constructor(t,e,n){this.browser=t,this.track=n,n.trackView=this,this.addDOMToColumnContainer(t,e,t.referenceFrameList)}startSpinner(){this.viewports&&this.viewports.length>0&&this.viewports[0].startSpinner()}stopSpinner(){this.viewports&&this.viewports.length>0&&this.viewports[0].stopSpinner()}addDOMToColumnContainer(t,e,n){this.axis=this.createAxis(t,this.track),this.viewports=[];const r=t.calculateViewportWidth(n.length),i=e.querySelectorAll(".igv-column");for(let t=0;t<i.length;t++){const e=gl(this,i[t],n[t],r);this.viewports.push(e)}this.sampleNameViewport=new vl(this,t.columnContainer.querySelector(".igv-sample-name-column"),void 0,t.sampleNameViewportWidth),this.createTrackScrollbar(t),this.createTrackDragHandle(t),this.createTrackGearPopup(t)}createAxis(t,e){const n=pe();if(t.columnContainer.querySelector(".igv-axis-column").appendChild(n),n.style.height=`${e.height}px`,"function"==typeof e.paintAxis){e.dataRange&&n.addEventListener("click",(()=>{t.dataRangeDialog.configure(this),t.dataRangeDialog.present(de(t.columnContainer))}));const{width:r,height:i}=n.getBoundingClientRect();this.axisCanvas=document.createElement("canvas"),this.axisCanvas.style.width=`${r}px`,this.axisCanvas.style.height=`${i}px`,n.appendChild(this.axisCanvas)}return n}resizeAxisCanvas(t,e){this.axis.style.width=`${t}px`,this.axis.style.height=`${e}px`,"function"==typeof this.track.paintAxis&&(this.axisCanvas.style.width=`${t}px`,this.axisCanvas.style.height=`${e}px`)}removeDOMFromColumnContainer(){this.boundAxisClickHander&&this.removeAxisEventListener(this.axis),this.axis.remove();for(let t of this.viewports)t.$viewport.remove();this.sampleNameViewport.dispose(),this.removeTrackScrollMouseHandlers(),this.outerScroll.remove(),this.removeTrackDragMouseHandlers(),this.dragHandle.remove(),this.removeTrackGearMouseHandlers(),this.gearContainer.remove()}renderSVGContext(t,{deltaX:e,deltaY:n}){!function(t,e,n,r,i){if("function"==typeof e.paintAxis){const{y:o,width:s,height:a}=n.getBoundingClientRect(),c=`${(e.name||e.id).replace(/\W/g,"")}_axis_guid_${ve()}`;t.saveWithTranslationAndClipRect(c,r,o+i,s,a,0),e.paintAxis(t,s,a),t.restore()}}(t,this.track,this.axisCanvas,e,n);const{width:r}=this.axis.getBoundingClientRect(),{y:i}=this.viewports[0].$viewport.get(0).getBoundingClientRect();let o={deltaX:r+e,deltaY:i+n};for(let e of this.viewports){e.renderSVGContext(t,o);const{width:n}=e.$viewport.get(0).getBoundingClientRect();o.deltaX+=n}!0===this.browser.showSampleNames&&this.sampleNameViewport.renderSVGContext(t,o)}dataRange(){return this.track.dataRange?this.track.dataRange:void 0}setDataRange(t,e){void 0!==t&&(this.track.dataRange.min=t),void 0!==e&&(this.track.dataRange.max=e),this.track.autoscale=!1,this.repaintViews()}presentColorPicker(t){if(!1===_l.has(this.track.type)){const e=[],n=this.track.color||this.track.defaultColor;ke(n)&&e.push(n),this.track.altColor&&ke(this.track.altColor)&&e.push(this.track.altColor);const r=e.map((t=>t.startsWith("#")?t:t.startsWith("rgb(")?no.rgbToHex(t):no.colorNameToHex(t))),i={color:t=>{this.track.color=t,this.repaintViews()},altColor:t=>{this.track.altColor=t,this.repaintViews()}};this.browser.genericColorPicker.configure(r,i),this.browser.genericColorPicker.setActiveColorHandler(t),this.browser.genericColorPicker.show()}}setTrackHeight(t,e){e||(this.track.minHeight&&(t=Math.max(this.track.minHeight,t)),this.track.maxHeight&&(t=Math.min(this.track.maxHeight,t))),this.track.height=t,this.resizeAxisCanvas(this.axis.clientWidth,this.track.height),"function"==typeof this.track.paintAxis&&this.paintAxis();for(let{$viewport:e}of this.viewports)e.height(t);if(this.sampleNameViewport.viewport.style.height=`${t}px`,"function"!=typeof this.track.computePixelHeight)for(let e of this.viewports)e.setContentHeight(t);this.repaintViews(),!1===kl.has(this.track.type)&&this.updateScrollbar(),this.dragHandle.style.height=`${t}px`,this.gearContainer.style.height=`${t}px`}updateScrollbar(){const t=this.viewports[0].$viewport.height();this.outerScroll.style.height=`${t}px`;const e=Cl(this.viewports),n=Math.round(t/e*t);e>t?(this.innerScroll.style.display="block",this.innerScroll.style.height=`${n}px`):this.innerScroll.style.display="none"}moveScroller(t){const e=de(this.innerScroll).position().top+t,n=Math.min(Math.max(0,e),this.outerScroll.clientHeight-this.innerScroll.clientHeight);de(this.innerScroll).css("top",`${n}px`);const r=Cl(this.viewports),i=-Math.round(n*(r/this.viewports[0].$viewport.height()));for(let t of this.viewports)t.setTop(i);this.sampleNameViewport.trackScrollDelta=t,this.sampleNameViewport.setTop(i)}isLoading(){for(let t of this.viewports)if(t.isLoading())return!0}repaintViews(){for(let t of this.viewports)t.isVisible()&&t.repaint();"function"==typeof this.track.paintAxis&&this.paintAxis(),this.repaintSamples()}repaintSamples(){if("function"==typeof this.track.getSamples){const t=this.track.getSamples();this.sampleNameViewport.repaint(t)}}setTrackLabelName(t){this.viewports.forEach((e=>e.setTrackLabel(t)))}resize(t){for(let e of this.viewports)e.setWidth(t)}async updateViews(){if(!this.browser||!this.browser.referenceFrameList)return;const t=this.viewports.filter((t=>t.isVisible()));if(t.forEach((t=>t.shift())),this.browser.dragObject)return;let e=this.track.autoscale||this.track.autoscaleGroup||"ruler"===this.track.type?t:t.filter((t=>t.needsRepaint()));e=e.filter((t=>t.checkZoomIn()));const n=e.filter((t=>t.needsReload()));for(let t of n)await t.loadFeatures();if(!this.disposed){if(this.track&&"function"==typeof this.track.variantRowCount&&n.length>0){let t=0;for(let e of this.viewports)e.featureCache&&e.featureCache.features&&(t=Math.max(t,e.featureCache.features.reduce(((t,e)=>Math.max(t,e.row||0)),0)));if(this.track.nVariantRows!==t+1){this.track.variantRowCount(t+1);for(let t of this.viewports)t.checkContentHeight()}}if(this.track.autoscale){let e=[];for(let n of t){const t=n.referenceFrame,r=t.start,i=r+t.toBP(de(n.contentDiv).width());if(n.featureCache&&n.featureCache.features)if("function"==typeof n.featureCache.features.getMax){const t=n.featureCache.features.getMax(r,i);e.push({value:t})}else e=e.concat(No(n.featureCache.features,r,i))}"function"==typeof this.track.doAutoscale?this.track.dataRange=this.track.doAutoscale(e):this.track.dataRange=ms(e)}for(let t of e)t.repaint();this.adjustTrackHeight(),this.repaintSamples(),this.updateRulerViewportLabels()}}updateRulerViewportLabels(){const t=this.browser.calculateViewportWidth(this.viewports.length);for(let e of this.viewports)"ruler"===this.track.type&&(this.viewports.length>1?e.presentLocusLabel(t):e.dismissLocusLabel())}async getInViewFeatures(){if(!this.browser||!this.browser.referenceFrameList)return[];let t=[];for(let e of this.viewports)if(e.needsReload()&&await e.loadFeatures(),e.featureCache&&e.featureCache.features){const n=e.referenceFrame,r=n.start,i=r+n.toBP(de(e.contentDiv).width());if("function"==typeof e.featureCache.features.getMax){const n=e.featureCache.features.getMax(r,i);t.push({value:n})}else t=t.concat(No(e.featureCache.features,r,i))}return t}checkContentHeight(){for(let t of this.viewports)t.checkContentHeight();this.adjustTrackHeight()}adjustTrackHeight(){var t=Cl(this.viewports);if(this.track.autoHeight?this.setTrackHeight(t,!1):this.track.paintAxis&&this.paintAxis(),!1===kl.has(this.track.type)){const t=this.viewports[0].getContentTop(),e=this.viewports.map((t=>t.getContentHeight())),n=Math.min(...e),r=Math.min(0,this.viewports[0].$viewport.height()-n);if(t<r)for(let t of this.viewports)t.$content.css("top",`${r}px`);this.updateScrollbar()}}createTrackScrollbar(t){const e=pe();if(t.columnContainer.querySelector(".igv-scrollbar-column").appendChild(e),e.style.height=`${this.track.height}px`,this.outerScroll=e,!1===kl.has(this.track.type)){const n=pe();e.appendChild(n),this.innerScroll=n,this.addTrackScrollMouseHandlers(t)}}createTrackDragHandle(t){const e="ideogram"===this.track.type||"ruler"===this.track.type?"igv-track-drag-shim":"igv-track-drag-handle";this.dragHandle=pe({class:e}),t.columnContainer.querySelector(".igv-track-drag-column").appendChild(this.dragHandle),this.dragHandle.style.height=`${this.track.height}px`,this.addTrackDragMouseHandlers(t)}createTrackGearPopup(t){this.gearContainer=pe(),t.columnContainer.querySelector(".igv-gear-menu-column").appendChild(this.gearContainer),this.gearContainer.style.height=`${this.track.height}px`,!0===this.track.ignoreTrackMenu||(this.gear=pe(),this.gearContainer.appendChild(this.gear),this.gear.appendChild(we("cog")),this.trackGearPopup=new yl(this.gear),this.addTrackGearMouseHandlers())}addAxisEventListener(t){this.boundAxisClickHander=function(t){this.browser.dataRangeDialog.configure(this),this.browser.dataRangeDialog.present(de(this.browser.columnContainer))}.bind(this),t.addEventListener("click",this.boundAxisClickHander)}removeAxisEventListener(t){t.removeEventListener("click",this.boundAxisClickHander)}addTrackScrollMouseHandlers(t){this.boundTrackScrollMouseDownHandler=function(e){e.stopPropagation();const{y:n}=me(e);de(this.innerScroll).data("yDown",n.toString()),this.boundColumnContainerMouseMoveHandler=function(t){t.stopPropagation();const{y:e}=me(t);this.moveScroller(e-parseInt(de(this.innerScroll).data("yDown"))),de(this.innerScroll).data("yDown",e.toString())}.bind(this),t.columnContainer.addEventListener("mousemove",this.boundColumnContainerMouseMoveHandler)}.bind(this),this.innerScroll.addEventListener("mousedown",this.boundTrackScrollMouseDownHandler),this.boundColumnContainerMouseUpHandler=function(e){t.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler)}.bind(this),t.columnContainer.addEventListener("mouseup",this.boundColumnContainerMouseUpHandler)}removeTrackScrollMouseHandlers(){!1===kl.has(this.track.type)&&(this.innerScroll.removeEventListener("mousedown",this.boundTrackScrollMouseDownHandler),this.browser.columnContainer.removeEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.browser.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler))}addTrackDragMouseHandlers(t){if("ideogram"===this.track.id||"ruler"===this.track.id);else{let e;function n(n){n.preventDefault(),e=n.target,e.classList.add("igv-track-drag-handle-hover"),t.startTrackDrag(this)}function r(n){t.endTrackDrag(),e&&n.target!==e&&e.classList.remove("igv-track-drag-handle-hover"),e=void 0}function i(n){n.preventDefault(),void 0===e&&n.target.classList.add("igv-track-drag-handle-hover"),t.updateTrackDrag(this)}function o(t){t.preventDefault(),void 0===e&&t.target.classList.remove("igv-track-drag-handle-hover")}this.boundTrackDragMouseDownHandler=n.bind(this),this.dragHandle.addEventListener("mousedown",this.boundTrackDragMouseDownHandler),this.boundDocumentTrackDragMouseUpHandler=r.bind(this),document.addEventListener("mouseup",this.boundDocumentTrackDragMouseUpHandler),this.boundTrackDragMouseEnterHandler=i.bind(this),this.dragHandle.addEventListener("mouseenter",this.boundTrackDragMouseEnterHandler),this.dragHandle.addEventListener("mouseout",(t=>{t.preventDefault(),void 0===e&&t.target.classList.remove("igv-track-drag-handle-hover")})),this.boundTrackDragMouseOutHandler=o.bind(this),this.dragHandle.addEventListener("mouseout",this.boundTrackDragMouseOutHandler)}}removeTrackDragMouseHandlers(){"ideogram"===this.track.id||"ruler"===this.track.id||(this.dragHandle.removeEventListener("mousedown",this.boundTrackDragMouseDownHandler),document.removeEventListener("mouseup",this.boundDocumentTrackDragMouseUpHandler),this.dragHandle.removeEventListener("mouseup",this.boundTrackDragMouseEnterHandler),this.dragHandle.removeEventListener("mouseout",this.boundTrackDragMouseOutHandler))}addTrackGearMouseHandlers(){if(!0===this.track.ignoreTrackMenu);else{function t(t){t.preventDefault(),t.stopPropagation(),this.trackGearPopup.presentMenuList(Oo.trackMenuItemList(this))}this.boundTrackGearClickHandler=t.bind(this),this.gear.addEventListener("click",this.boundTrackGearClickHandler)}}removeTrackGearMouseHandlers(){!0===this.track.ignoreTrackMenu||this.gear.removeEventListener("click",this.boundTrackGearClickHandler)}dispose(){this.removeAxisEventListener(this.axis),this.axis.remove();for(let t of this.viewports)t.dispose();this.sampleNameViewport.dispose(),this.removeTrackScrollMouseHandlers(),this.outerScroll.remove(),this.removeTrackDragMouseHandlers(),this.dragHandle.remove(),this.removeTrackGearMouseHandlers(),this.gearContainer.remove(),"function"==typeof this.track.dispose&&this.track.dispose();const t=this.track;"function"==typeof t.dispose&&t.dispose();for(let e of Object.keys(t))t[e]=void 0;for(let t of Object.keys(this))this[t]=void 0;this.alert&&this.alert.container.remove(),this.disposed=!0}paintAxis(){if("function"==typeof this.track.paintAxis){const{width:t,height:e}=this.axisCanvas.getBoundingClientRect(),n=window.devicePixelRatio||1;this.axisCanvas.height=n*e,this.axisCanvas.width=n*t;const r=this.axisCanvas.getContext("2d");r.scale(n,n),this.track.paintAxis(r,t,e)}}}function Cl(t){const e=t.map((t=>t.getContentHeight()));return Math.max(...e)}function El(t,e){if(t.length<6)console.log("Skipping line: "+t.join(" "));else{var n={chr1:t[0],start1:Number.parseInt(t[1]),end1:Number.parseInt(t[2]),chr2:t[3],start2:Number.parseInt(t[4]),end2:Number.parseInt(t[5])};if(!(isNaN(n.start1)||isNaN(n.end1)||isNaN(n.start2)||isNaN(n.end2))){if(t.length>6&&"."!==t[6]&&(n.name=t[6]),t.length>7&&"."!==t[7]&&(n.score=Number(t[7])),t.length>8&&"."!==t[8]&&(n.strand1=t[8]),t.length>9&&"."!==t[9]&&(n.strand2=t[9]),e){const r=e.colorColumn;r&&r<t.length&&(n.color=no.createColorString(t[r]));const i=e.thicknessColumn;i&&i<t.length&&(n.thickness=t[i]),t.length>10&&e.columnNames&&e.columnNames.length===t.length&&(n.extras=t.slice(10))}return n.chr1===n.chr2&&(n.chr=n.chr1,n.start=Math.min(n.start1,n.start2),n.end=Math.max(n.end1,n.end2)),n}}}function Al(t,e){if(!(t.length<8))return{chr:t[0],start:Number.parseInt(t[1]),end:Number.parseInt(t[2]),color:no.createColorString(t[6]),value:Number(t[7])}}function Tl(t,e){if(!(t.length<6))return{chr:t[0],start:t[1],end:t[2],chr1:t[8],start1:Number.parseInt(t[9]),end1:Number.parseInt(t[10]),chr2:t[13],start2:Number.parseInt(t[14]),end2:Number.parseInt(t[15]),name:t[3],score:Number(t[4]),value:Number(t[5]),color:"."===t[7]?void 0:"0"===t[7]?"rgb(0,0,0)":t[7]};console.log("Skipping line: "+t.join(" "))}const Ll=new Set(["transcript","primary_transcript","processed_transcript","mRNA","mrna","lnc_RNA","miRNA","ncRNA","rRNA","scRNA","snRNA","snoRNA","tRNA"]),Ml=new Set(["CDS","cds"]),Rl=new Set(["start_codon","stop_codon"]),Il=new Set(["5UTR","3UTR","UTR","five_prime_UTR","three_prime_UTR","3'-UTR","5'-UTR"]),Nl=new Set(["exon","coding-exon"]),Pl=new Set;for(let fd of[Ml,Rl,Il,Nl])for(let dd of fd)Pl.add(dd);function Ol(t){return t.includes("intron")}function Fl(t){return Ml.has(t)||Rl.has(t)}function Dl(t){return Il.has(t)}function Bl(t){return Ll.has(t)||t.endsWith("RNA")||t.endsWith("transcript")}function zl(t){return Pl.has(t)||t.endsWith("RNA")||Ol(t)}const Hl=new Set(["id","parent","name"]);class Vl{constructor(t){Object.assign(this,t)}popupData(t){const e=this.geneObject?this.geneObject.popupData():[];if(this.geneObject&&e.push("<hr/>"),this.name&&e.push({name:"Name",value:this.name}),e.push({name:"Type",value:this.type}),e.push({name:"Source",value:this.source}),void 0!==this.score&&e.push({name:"Score",value:this.score}),this.attributeString){const t=$l(this.attributeString,this.delim);for(let[n,r]of t)void 0!==r&&r.length>0&&!Hl.has(n.toLowerCase())&&e.push({name:n+":",value:r})}return e.push({name:"Location",value:`${this.chr}:${_e(this.start+1)}-${_e(this.end)}`}),e}getAttributeValue(t){if(this.hasOwnProperty(t))return this[t];if(this._attributeCache||(this._attributeCache=new Map),this._attributeCache.has(t))return this._attributeCache.get(t);{const e=$l(this.attributeString,this.delim);let n;for(let[r,i]of e)if(r===t){n=i;break}return this._attributeCache.set(t,n),n}}}class jl extends Vl{constructor(t){super(t),this.exons=[],this.parts=[]}addExon(t){this.exons.push(t),this.start=Math.min(this.start,t.start),this.end=Math.max(this.end,t.end)}addPart(t){this.parts.push(t)}assembleParts(){if(0===this.parts.length)return;this.parts.sort((function(t,e){return t.start-e.start}));let t=this.parts[0].start,e=this.parts[0].end;for(let n=1;n<this.parts.length;n++){const r=this.parts[n];if(!Ol(r.type))if(r.start<=e)e=Math.max(e,r.end);else{this.findExonContaining({start:t,end:e})||this.exons.push({start:t,end:e,psuedo:!0}),t=r.start,e=r.end}}this.findExonContaining({start:t,end:e})||(this.exons.push({start:t,end:e,psuedo:!0}),this.start=Math.min(this.start,t),this.end=Math.max(this.end,e));for(let t of this.parts){const e=t.type;Fl(e)?this.addCDS(t):Dl(e)&&this.addUTR(t)}}findExonContaining({start:t,end:e}){for(let n of this.exons)if(n.end>=e&&n.start<=t)return n}addCDS(t){let e;const n=this.exons;for(let r of n)if(r.start<=t.start&&r.end>=t.end){e=r;break}e?(e.cdStart=e.cdStart?Math.min(t.start,e.cdStart):t.start,e.cdEnd=e.cdEnd?Math.max(t.end,e.cdEnd):t.end):console.error("No exon found spanning "+t.start+"-"+t.end),this.cdStart=this.cdStart?Math.min(t.start,this.cdStart):t.start,this.cdEnd=this.cdEnd?Math.max(t.end,this.cdEnd):t.end}addUTR(t){let e;const n=this.exons;for(let r=0;r<n.length;r++)if(n[r].start<=t.start&&n[r].end>=t.end){e=n[r];break}e?t.start===e.start&&t.end===e.end?e.utr=!0:(t.end<e.end&&(e.cdStart=t.end),t.start>e.start&&(e.cdEnd=t.start)):console.error("No exon found spanning "+cds.start+"-"+cds.end)}finish(){this.assembleParts();var t=this.cdStart,e=this.cdEnd;this.exons.sort((function(t,e){return t.start-e.start})),t&&this.exons.forEach((function(n){(n.end<t||n.start>e)&&(n.utr=!0)}))}popupData(t){const e=super.popupData(t);for(let n of this.exons)if(!n.pseudo&&t>=n.start&&t<n.end&&"function"==typeof n.popupData){e.push("<hr/>");const r=n.popupData(t);for(let t of r)e.push(t)}for(let n of this.parts)if(t>=n.start&&t<n.end&&"function"==typeof n.popupData){e.push("<hr/>");const r=n.popupData(t);for(let t of r)e.push(t)}return e}}function Ul(t,e){const n=e.format;if(t.length<9)return;const r="gff3"===n?"=":" ";return new Vl({source:t[1],type:t[2],chr:t[0],start:parseInt(t[3])-1,end:parseInt(t[4]),score:"."===t[5]?void 0:Number(t[5]),strand:t[6],phase:"."===t[7]?0:parseInt(t[7]),attributeString:t[8],delim:r})}function ql(t,e){const n=Ul(t,e);if(!n)return;const r=$l(n.attributeString,n.delim);for(let[t,e]of r){const r=t.toLowerCase();"color"===r||"colour"===r?n.color=no.createColorString(e):"ID"===t?n.id=e:"Parent"===t&&(n.parent=e)}return n}function Wl(t,e){const n=Ul(t,e);if(!n)return;const r=$l(n.attributeString,n.delim);let i,o;switch(n.type){case"gene":i="gene_id";break;case"transcript":i="transcript_id",o="gene_id";break;default:o="transcript_id"}for(let[t,e]of r){const r=t.toLowerCase();"color"===r||"colour"===r?n.color=no.createColorString(e):t===i?n.id=e:t===o&&(n.parent=e)}return n}function $l(t,e){var n=[];for(let r of t.split(";")){r=r.trim();const t=r.indexOf(e);if(t>0&&t<r.length-1){const e=r.substring(0,t);let i=Gl(decodeURIComponent(r.substring(t+1).trim()));n.push([e,i])}}return n}function Gl(t){return t.startsWith('"')&&t.endsWith('"')&&(t=t.substr(1,t.length-2)),t}class Zl{constructor(t){this.message=t}}function Xl(t,e){if(t.length<3)return;e&&e.gffTags;const n=t[0],r=parseInt(t[1]),i=t.length>2?parseInt(t[2]):r+1;if(isNaN(r)||isNaN(i))return new Zl("Unparsable bed record.");const o=new oh({chr:n,start:r,end:i,score:1e3});try{if(t.length>3){if(t[3].indexOf(";")>0&&t[3].indexOf("=")>0){const e=$l(t[3],"=");o.attributes={};for(let t of e)o.attributes[t[0]]=t[1]}o.name||(o.name="."===t[3]?"":t[3])}if(t.length>4&&(o.score="."===t[4]?0:Number(t[4]),isNaN(o.score)))return o;if(t.length>5&&(o.strand=t[5],"."!==o.strand&&"+"!==o.strand&&"-"!==o.strand))return o;if(t.length>6&&(o.cdStart=parseInt(t[6]),isNaN(o.cdStart)))return o;if(t.length>7&&(o.cdEnd=parseInt(t[7]),isNaN(o.cdEnd)))return o;if(t.length>8&&"."!==t[8]&&"0"!==t[8]&&(o.color=no.createColorString(t[8])),t.length>11){const e=parseInt(t[9]);if(e>1e3)return o;const n=t[10].replace(/,$/,"").split(","),i=t[11].replace(/,$/,"").split(",");if(n.length!==i.length||e!==n.length)return o;const s=[];for(let t=0;t<e;t++){const e=r+parseInt(i[t]),o=e+parseInt(n[t]);s.push({start:e,end:o})}th(s,o.cdStart,o.cdEnd),o.exons=s}if(e){let n=e.thicknessColumn,r=e.colorColumn;r&&r<t.length&&(o.color=no.createColorString(t[r])),n&&n<t.length&&(o.thickness=t[n])}}catch(t){}return o}function Yl(t,e){if(t.length<=15)return;return{swScore:Number.parseInt(t[1]),milliDiv:Number.parseInt(t[2]),milliDel:Number.parseInt(t[3]),milliIns:Number.parseInt(t[4]),chr:t[5],start:Number.parseInt(t[6]),end:Number.parseInt(t[7]),strand:t[9],repName:t[10],repClass:t[11],repFamily:t[12],repStart:Number.parseInt(t[13]),repEnd:Number.parseInt(t[14]),repLeft:Number.parseInt(t[15])}}function Kl(t,e){var n=void 0===e.shift?0:1;if(t.length<=9+n)return;const r=parseInt(t[5+n]),i=parseInt(t[6+n]);var o={name:t[0+n],chr:t[1+n],strand:t[2+n],start:parseInt(t[3+n]),end:parseInt(t[4+n]),cdStart:r,cdEnd:i,id:t[0+n]},s=parseInt(t[7+n]),a=t[8+n].split(","),c=t[9+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function Ql(t,e){var n=void 0===e.shift?0:1;if(t.length<=11+n)return;const r=parseInt(t[5+n]),i=parseInt(t[6+n]),o={name:t[11+n],chr:t[1+n],strand:t[2+n],start:parseInt(t[3+n]),end:parseInt(t[4+n]),cdStart:r,cdEnd:i,id:t[0+n]},s=parseInt(t[7+n]),a=t[8+n].split(","),c=t[9+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function Jl(t,e){var n=void 0===e.shift?0:1;if(t.length<=10+n)return;const r=parseInt(t[6+n]),i=parseInt(t[7+n]);var o={name:t[0+n],id:t[1+n],chr:t[2+n],strand:t[3+n],start:parseInt(t[4+n]),end:parseInt(t[5+n]),cdStart:r,cdEnd:i},s=parseInt(t[8+n]),a=t[9+n].split(","),c=t[10+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function th(t,e,n){for(let r of t){const t=r.end,i=r.start;t<e||i>n?r.utr=!0:(e>=i&&e<=t&&(r.cdStart=e),n>=i&&n<=t&&(r.cdEnd=n))}}function eh(t,e){var n,r,i,o,s,a,c;if(!(t.length<9))return n=t[0],r=parseInt(t[1]),i=parseInt(t[2]),s=t[3],a=Number(t[4]),o=t[5].trim(),c=Number(t[6]),0===a&&(a=c),{chr:n,start:r,end:i,name:s,score:a,strand:o,signal:c,pValue:Number(t[7]),qValue:Number(t[8])}}function nh(t,e){if(t.length<=3)return;const n={chr:t[0],start:parseInt(t[1]),end:parseInt(t[2]),value:Number(t[3])};if(e){let r=e.colorColumn;r&&r<t.length&&(n.color=no.createColorString(t[r]))}return n}function rh(t,e){const n=e.wig;if(n&&"fixedStep"===n.format){const e=n.index*n.step+n.start,r=e+n.span,i=Number(t[0]);return++n.index,isNaN(i)?null:{chr:n.chrom,start:e,end:r,value:i}}if(n&&"variableStep"===n.format){if(t.length<2)return null;const e=parseInt(t[0],10)-1,r=e+n.span,i=Number(t[1]);return isNaN(i)?null:{chr:n.chrom,start:e,end:r,value:i}}return nh(t)}function ih(t,e){if(t.length<6)return;const n=["bin","chr","start","end","name","score","strand","refNCBI","refUCSC","observed","molType","class","valid","avHet","avHetSE","func","locType","weight","exceptions","submitterCount","submitters","alleleFreqCount","alleles","alleleNs","alleleFreqs","bitfields"],r={chr:t[1],start:Number.parseInt(t[2]),end:Number.parseInt(t[3]),name:t[4],score:Number.parseInt(t[5])},i=Math.min(t.length,n.length);for(let e=6;e<i;e++)r[n[e]]=t[e];return r}class oh{constructor(t){Object.assign(this,t)}getAttributeValue(t){return this.hasOwnProperty(t)?this[t]:this.attributes?this.attributes[t]:void 0}}function sh(t,e){if(!(t.length<7)){var n=t[0],r=t[1],i=parseInt(t[2]),o=parseInt(t[3]),s=parseInt(t[4]),a=parseInt(t[5]),c=t[6],l={chr:n,name:r,junction_left:i,junction_right:o,num_junction_reads:s,num_spanning_frags:a,spanning_frag_coords:[],start:-1,end:-1},h=i,u=o;if(a>0)for(var f=c.split(","),d=0;d<f.length;d++){var p=f[d].split("-"),g=p[0],m=p[1];g<h&&(h=g),m>u&&(u=m),l.spanning_frag_coords.push({left:g,right:m})}return l.start=h,l.end=u,l}}function ah(t,e){if(t.length<7)return null;const n={chr:t[0],start:parseInt(t[1])-1,end:parseInt(t[2]),"Strongest SNP-risk allele":t[3],"Disease/Phenotype":t[4],"P-value":t[5],"Odds ratio or beta":t[6]};return t.length>6&&(n.PUBMEDID=`<a target = "blank" href = "https://www.ncbi.nlm.nih.gov/pubmed/${t[7]}">${t[7]}</a>`),n}function ch(t,e){const n=e.customFormat;if(t.length<n.fields.length)return;const r=n.coords||0,i=t[n.chr],o=parseInt(t[n.start])-r,s={chr:i,start:o,end:void 0!==n.end?parseInt(t[n.end]):o+1};return n.fields&&n.fields.forEach((function(e,r){r!==n.chr&&r!==n.start&&r!==n.end&&(s[e]=t[r])})),s}function lh(t,e){const n=e.columnNames;if(!n)throw Error("Sample names are not defined. Missing column headers?");const r=n.length-3,i=t[0],o=parseInt(t[1]),s=parseInt(t[2]),a=t.slice(3).map(Number);return a.length==r?{chr:i,start:o,end:s,values:a}:void console.warn(`${i}:${o}-${s} row contains ${a.length} sample columns instead of the expected ${r} columns. Skipping...`)}class hh{constructor(t){this.config=t,this.header={},t.nameField&&(this.header.nameField=t.nameField),this.skipRows=0,t.decode?(this.decode=t.decode,this.delimiter=t.delimiter||"\t"):t.format&&(this.header.format=t.format.toLowerCase(),this.setDecoder(this.header.format)),this.delimiter||(this.delimiter="\t")}async parseHeader(t){let e,n,r=this.header;for(;void 0!==(n=await t.nextLine());)if(n.startsWith("track")||n.startsWith("#track")){let t=uh(n);Object.assign(r,t)}else if(n.startsWith("browser"));else if(n.startsWith("#columns")){let t=fh(n);Object.assign(r,t)}else if(n.startsWith("##gff-version 3"))r.format="gff3";else if(n.startsWith("#gffTags"))r.gffTags=!0;else{if(n.startsWith("fixedStep")||n.startsWith("variableStep"))break;if(n.startsWith("#")){const t=n.split(this.delimiter||"\t");t.length>1&&(e=t)}else{this.setDecoder(r.format);const t=n.split(this.delimiter||"\t");try{const n=Object.assign({columnNames:e},r);if(this.decode(t,n))break;t.length>1&&(e=t)}catch(n){t.length>1&&(e=t)}}}if(e){r.columnNames=e;for(let t=0;t<e.length;t++)"color"===e[t]||"colour"===e[t]?r.colorColumn=t:"thickness"===e[t]&&(r.thicknessColumn=t)}return this.header=r,r}async parseFeatures(t){const e=[],n=this.decode,r=this.header.format,i=this.delimiter||"\t";let o,s=0,a=0;for(;void 0!==(o=await t.nextLine());){if(s++,s<=this.skipRows)continue;if(!o||o.startsWith("track")||o.startsWith("#")||o.startsWith("browser"))continue;if("wig"===r&&o.startsWith("fixedStep")){this.header.wig=dh(o);continue}if("wig"===r&&o.startsWith("variableStep")){this.header.wig=ph(o);continue}const t=o.split(i);if(t.length<1)continue;const c=n(t,this.header);c instanceof Zl?(a++,a>0&&console.error(`Error parsing line '${o}': ${c.message}`)):c&&e.push(c)}return n===El&&function(t){if(0==t.length)return;const e=t[0];if(void 0===e.score&&void 0!==e.name){for(let e of t)if(!("number"==typeof(n=e.name)?n-n==0:"string"==typeof n&&""!==n.trim()&&(Number.isFinite?Number.isFinite(+n):isFinite(+n)))&&"."!==e.name)return;for(let e of t)e.score=Number(e.name),delete e.name}var n;const r=t.filter((t=>t.chr1!==t.chr2));for(let e of r){const n=Object.assign({},e);n.dup=!0,t.push(n),e.chr=e.chr1,e.start=e.start1,e.end=e.end1,n.chr=n.chr2,n.start=n.start2,n.end=n.end2}}(e),e}setDecoder(t){switch(t){case"narrowpeak":case"broadpeak":case"regionpeak":case"peaks":this.decode=eh,this.delimiter=this.config.delimiter||/\s+/;break;case"bedgraph":this.decode=nh,this.delimiter=/\s+/;break;case"wig":this.decode=rh,this.delimiter=this.config.delimiter||/\s+/;break;case"gff3":case"gff":this.decode=ql,this.delimiter="\t";break;case"gtf":this.decode=Wl,this.delimiter="\t";break;case"fusionjuncspan":this.decode=sh,this.delimiter=this.config.delimiter||/\s+/;break;case"gtexgwas":this.skipRows=1,this.decode=ah,this.delimiter="\t";break;case"refflat":this.decode=Jl,this.delimiter=this.config.delimiter||/\s+/;break;case"genepred":this.decode=Kl,this.delimiter=this.config.delimiter||/\s+/;break;case"genepredext":this.decode=Ql,this.delimiter=this.config.delimiter||/\s+/;break;case"ensgene":this.decode=Kl,this.header.shift=1,this.delimiter=this.config.delimiter||/\s+/;break;case"refgene":this.decode=Ql,this.delimiter=this.config.delimiter||/\s+/,this.header.shift=1;break;case"bed":this.decode=Xl,this.delimiter=this.config.delimiter||/\s+/;break;case"bedpe":this.decode=El,this.delimiter=this.config.delimiter||"\t";break;case"bedpe-domain":this.decode=Al,this.headerLine=!0,this.delimiter=this.config.delimiter||"\t";break;case"bedpe-loop":this.decode=El,this.delimiter=this.config.delimiter||"\t",this.header={colorColumn:7};break;case"interact":this.decode=Tl,this.delimiter=this.config.delimiter||/\s+/;break;case"snp":this.decode=ih,this.delimiter="\t";break;case"rmsk":this.decode=Yl,this.delimiter="\t";break;case"gcnv":this.decode=lh,this.delimiter="\t";break;default:const e=function(t){return us&&us[t]?function(t){const e=t.fields,n=["chr","start","end"];for(let r=0;r<e.length;r++)for(let i of n)i===e[r]&&(t[i]=r);return t}(us[t]):void 0}(t);void 0!==e?(this.decode=ch,this.header.customFormat=e,this.delimiter=e.delimiter||"\t"):(this.decode=Xl,this.delimiter=this.config.delimiter||/\s+/)}}}function uh(t){const e={},n=t.split(/(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g);let r;const i=[];for(let t of n)t&&0!==t.trim().length&&(t.endsWith("=")?r=t:r?(i.push(r+t),r=void 0):i.push(t));for(let t of i){if(!t)return;var o=t.split("=",2);if(2===o.length){const t=o[0].trim(),n=o[1].trim();if(e.hasOwnProperty(t)){let r=e[t];Array.isArray(r)?r.push(n):e[t]=[r,n]}else e[t]=n}}return"interact"==e.type?e.format="interact":"gcnv"===e.type&&(e.format="gcnv"),e}function fh(t){let e={},n=t.split(/\s+/);if(2===n.length){n[1].split(";").forEach((function(t){let n=t.split("=");"color"===n[0]?e.colorColumn=Number.parseInt(n[1])-1:"thickness"===n[0]&&(e.thicknessColumn=Number.parseInt(n[1])-1)}))}return e}function dh(t){const e=t.split(/\s+/);return{format:"fixedStep",chrom:e[1].split("=")[1],start:parseInt(e[2].split("=")[1],10)-1,step:parseInt(e[3].split("=")[1],10),span:e.length>4?parseInt(e[4].split("=")[1],10):1,index:0}}function ph(t){const e=t.split(/\s+/);return{format:"variableStep",chrom:e[1].split("=")[1],span:e.length>2?parseInt(e[2].split("=")[1],10):1}}class gh{constructor(t){switch(this.type=t||"seg",this.type){case"mut":this.sampleColumn=3,this.chrColumn=0,this.startColumn=1,this.endColumn=2,this.dataColumn=4;break;case"maf":this.sampleColumn=15,this.chrColumn=4,this.startColumn=5,this.endColumn=6,this.dataColumn=8;break;default:this.sampleColumn=0,this.chrColumn=1,this.startColumn=2,this.endColumn=3}}async parseHeader(t){let e;for(;void 0!==(e=await t.nextLine());)if(!e.startsWith("#")){const t=e.split("\t");this.header={headings:t};break}return this.header}async parseFeatures(t){const e=[];let n;this.header||(this.header=await this.parseHeader(t)),"seg"===this.type&&(this.dataColumn=this.header.headings.length-1),this.header.headings.length>5&&(n=this.extractExtraColumns(this.header.headings));const r=this.header.headings[this.dataColumn];let i;for(;void 0!==(i=await t.nextLine());){const t=i.split("\t"),o="seg"===this.type?Number(t[this.dataColumn]):t[this.dataColumn];if(t.length>this.dataColumn){const i=new mh({sample:t[this.sampleColumn],chr:t[this.chrColumn],start:parseInt(t[this.startColumn])-1,end:parseInt(t[this.endColumn]),value:o,valueColumnName:r});if(n){const e=this.extractExtraColumns(t);i.setAttributes({names:n,values:e})}e.push(i)}}return e}extractExtraColumns(t){const e=[];for(let n=0;n<t.length;n++)n!==this.chrColumn&&n!==this.startColumn&&n!==this.endColumn&&n!==this.sampleColumn&&e.push(t[n]);return e}}class mh{constructor({sample:t,chr:e,start:n,end:r,value:i,valueColumnName:o}){this.sample=t,this.chr=e,this.start=n,this.end=r,this.value=i,this.valueColumnName=o}setAttributes({names:t,values:e}){this.attributeNames=t,this.attributeValues=e}getAttribute(t){if(this.attributeNames){const e=this.attributeNames.indexOf(t);if(e>=0)return this.attributeValues[e]}}popupData(t,e){const n=new Set(["chr","start","end","sample","value","row","color","sampleKey","uniqueSampleKey","sampleId","chromosome","uniquePatientKey"]),r=this.chr+":"+_e(this.start+1)+"-"+_e(this.end),i=[{name:"Sample",value:this.sample},{name:"Location",value:r},{name:this.valueColumnName?Ee(this.valueColumnName):"Value",value:this.value}];if("mut"===t&&"hg38"===e){const t=this.extractCravatLink(e);t&&(i.push("<hr/>"),i.push({html:t}),i.push("<hr/>"))}if(this.attributeNames&&this.attributeNames.length>0)for(let t=0;t<this.attributeNames.length;t++)!n.has(this.attributeNames[t])&this.valueColumnName!==this.attributeNames[t]&&i.push({name:Ee(this.attributeNames[t]),value:this.attributeValues[t]});return i}extractCravatLink(t){let e,n;if(this.attributeNames&&this.attributeNames.length>0)for(let r=0;r<this.attributeNames.length;r++)if(e||"Reference_Allele"!==this.attributeNames[r]||(e=this.attributeValues[r]),!n&&this.attributeNames[r].startsWith("Tumor_Seq_Allele")&&this.attributeValues[r]!==e&&(n=this.attributeValues[r]),e&&n)return bc.getCravatLink(this.chr,this.start+1,e,n,t)}}function vh(t){const e=new bh;e.chr=t[0],e.pos=parseInt(t[1]),e.names=t[2],e.referenceBases=t[3],e.alternateBases=t[4],e.quality=t[5],e.filter=t[6],e.info={};const n=t[7];if(n)for(let t of n.split(";")){var r=t.split("=");e.info[r[0]]=r[1]}return e.init(),e}class bh{init(){const t=this.referenceBases,e=this.alternateBases;if(this.info&&(this.info.VT?this.type=this.info.VT:this.info.SVTYPE?this.type="SV":this.info.PERIOD&&(this.type="STR")),void 0===this.type&&(this.type=function(t,e){const n=t.length;if(void 0===e)return"UNKNOWN";if(0===e.trim().length||"<NON_REF>"===e||"<*>"===e||"."===e)return"NONVARIANT";{const t=e.split(",").map((function(t){return 1===n&&1===t.length?"SNP":"<NON_REF>"===t?"NONVARIANT":"OTHER"}));let r=t[0];for(let e of t)if(e!==r)return"MIXED";return r}}(t,e)),"NONVARIANT"===this.type&&(this.heterozygosity=0),this.info.END)this.start=this.pos-1,this.info.CHR2&&this.info.CHR2!==this.chr?this.end=this.start+1:this.end=Number.parseInt(this.info.END);else if("NONVARIANT"===this.type)this.start=this.pos-1,this.end=this.start+t.length;else{const n=e.split(",").filter((t=>t.length>0));this.alleles=[],this.start=void 0,this.end=void 0;for(let e of n)if(this.alleles.push(e),"SV"!==this.type&&yh(e)){let n=e.length,r=t.length;const i=Math.min(n,r);let o=0;for(;o<i&&t.charCodeAt(o)===e.charCodeAt(o);)o++,n--,r--;for(;n>0&&r>0;){const i=o+n-1,s=o+r-1;if(e.charCodeAt(i)!==t.charCodeAt(s))break;n--,r--}for(;n>0&&r>0;){const i=o,s=o;if(e.charCodeAt(i)!==t.charCodeAt(s))break;o++,n--,r--}const s=this.pos+o-1,a=s+r;this.start=void 0===this.start?s:Math.min(this.start,s),this.end=void 0===this.end?a:Math.max(this.end,a)}void 0===this.start&&(this.start=this.pos-1,this.end=this.pos)}}popupData(t,e){const n=`${_e(this.pos)}`,r=this.start===this.end?`${_e(this.start)} | ${_e(this.start+1)}`:`${_e(this.start+1)}-${_e(this.end)}`,i=[{name:"Chr",value:this.chr},{name:"Pos",value:n},{name:"Loc",value:r},{name:"Names",value:this.names?this.names:""},{name:"Ref",value:this.referenceBases},{name:"Alt",value:this.alternateBases.replace("<","&lt;")},{name:"Qual",value:this.quality},{name:"Filter",value:this.filter}];if("SNP"===this.type){let t=this.referenceBases;if(1===t.length){let n=this.alternateBases.split(",");for(let r of n)if(1===r.length){let n=bc.getCravatLink(this.chr,this.pos,t,r,e);n&&(i.push("<hr/>"),i.push({html:n}))}}}if(this.hasOwnProperty("heterozygosity")&&i.push({name:"Heterozygosity",value:this.heterozygosity}),this.info){i.push({html:'<hr style="border-top: dotted 1px;border-color: #c9c3ba" />'});for(let t of Object.keys(this.info))i.push({name:t,value:xh(decodeURIComponent(this.info[t]))})}return i}isRefBlock(){return"NONVARIANT"===this.type}}const wh=new Set(["A","C","T","G"].map((t=>t.charCodeAt(0))));function yh(t){for(let e=0;e<t.length;e++)if(!wh.has(t.charCodeAt(e)))return!1;return!0}function xh(t,e){return void 0===e&&(e=","),Array.isArray(t)?t.join(e):t}class kh{construtor(){}async parseHeader(t,e){const n={};n.chrAliasTable=new Map;let r=await t.nextLine();if(!r.startsWith("##fileformat"))throw new Error("Invalid VCF file: missing fileformat line");for(n.version=r.substr(13);void 0!==(r=await t.nextLine())&&r.startsWith("#");){let t;const o={};if(r.startsWith("##")){if(r.startsWith("##INFO")||r.startsWith("##FILTER")||r.startsWith("##FORMAT")){const e=r.indexOf("<"),s=r.lastIndexOf(">");if(!(e>2&&s>0)){console.log("Malformed VCF header line: "+r);continue}const a=r.substring(2,e-1);n[a]||(n[a]={});const c=Ce(r.substring(e+1,s-1),",");for(let e of c){var i=e.split("=");i.length>1&&("ID"===i[0]?t=i[1]:o[i[0]]=i[1])}t&&(n[a][t]=o)}else if(r.startsWith("##contig")&&e){const t=r.indexOf("<ID=");let i=r.indexOf(",",t);-1==i&&(i=r.indexOf(">",t));const o=r.substring(t+4,i),s=e.getChromosomeName(o);n.chrAliasTable.set(s,o)}}else if(r.startsWith("#CHROM")){const t=r.split("\t");if(t.length>8){n.callSets=[];for(let e=9;e<t.length;e++)n.callSets.push({id:e,name:t[e]})}}}return this.header=n,n}async parseFeatures(t){const e=[],n=this.header.callSets,r=8+(n?n.length+1:0);let i;for(;void 0!==(i=await t.nextLine());)if(i&&!i.startsWith("#")){const t=i.split("\t");if(t.length===r){const r=vh(t);if(r.header=this.header,e.push(r),t.length>9){const e=_h(t[8].split(":"));r.calls={};for(let i=9;i<t.length;i++){const o=t[i],s=n[i-9],a={callSetName:s.name,info:{}};r.calls[s.id]=a,o.split(":").forEach((function(t,n){if(n===e.genotypeIndex)a.genotype=[],t.split(/[\|\/]/).forEach((function(t){a.genotype.push("."===t?t:parseInt(t))}));else a.info[e.fields[n]]=t}))}}r.info&&r.info.CHR2&&r.info.END&&e.push(Sh(r))}}return e}}function _h(t){const e={genotypeIndex:-1,fields:t};for(let n=0;n<t.length;n++)"GT"===t[n]&&(e.genotypeIndex=n);return e}function Sh(t){const e=t.info.CHR2,n=Number.parseInt(t.info.END);return{chr:e,start:n-1,end:n,_f:t}}class Ch{constructor(t){if(this.config=t,t.columns){if(void 0===t.columns.chromosome||void 0===t.columns.position||void 0===t.columns.value)throw Error("columns property must define chrCol, posCol, and valueCol");this.posCol=t.columns.position-1,this.chrCol=t.columns.chromosome-1,this.pvalueCol=t.columns.value-1}else this.posCol=2,this.chrCol=1,this.pvalueCol=3}async parseHeader(t){const e=await t.nextLine();return this.parseHeaderLine(e)}parseHeaderLine(t){if(this.columns=t.split(/\t/),!this.config.columns)for(let t=0;t<this.columns.length;t++){switch(this.columns[t].toLowerCase()){case"chr":case"chromosome":case"chr_id":this.chrCol=t;break;case"bp":case"pos":case"position":case"chr_pos":this.posCol=t;break;case"p":case"pval":case"pvalue":case"p-value":case"p.value":this.valueCol=t}}return this.columns}async parseFeatures(t){const e=[],n=t.nextLine();let r;for(this.columns||this.parseHeaderLine(n);void 0!==(r=t.nextLine());){const t=r.split(/\t/);if(t.length===this.columns.length){const n=t[this.chrCol],i=parseInt(t[this.posCol])-1,o=i+1,s=Number(t[this.valueCol]);e.push(new Eh({chr:n,start:i,end:o,value:s,line:r,columns:this.columns}))}}return e}}class Eh{constructor({chr:t,start:e,end:n,value:r,line:i,columns:o}){this.chr=t,this.start=e,this.end=n,this.value=r,this.line=i,this.columns=o}popupData(){const t=this.line.split(/\t/);return this.columns.map((function(e,n){return{name:e,value:t[n]}}))}getAttribute(t){const e=this.line.split(/\t/);for(let n=0;n<this.columns.length;n++)if(this.columns[n]===t)return e[n]}}var Ah=new RegExp("([^:]*)\\(([^)]*)\\)"),Th=new RegExp("([^:]*):([^(]*)\\(([^)]*)\\)");class Lh{constructor(t){const e=t?t.decode:void 0;this.nameField=t?t.nameField:void 0,this.skipRows=0,this.decode=e||Oh,this.delimiter="\t"}async parseHeader(t){let e,n;for(;(e=await t.nextLine())&&(e.startsWith("track")||e.startsWith("#")||e.startsWith("browser"));)if(e.startsWith("track")||e.startsWith("#track")){let t=Ih(e);n?Object.assign(n,t):n=t}else if(e.startsWith("#columns")){let t=Nh(e);n?Object.assign(n,t):n=t}else e.startsWith("##gff-version 3")&&(this.format="gff3",n||(n={}),n.format="gff3");return this.header=n,n}async parseFeatures(t){const e=[],n=this.decode,r=this.delimiter||"\t";let i,o=0;for(;void 0!==(i=t.nextLine());){if(o++,o<=this.skipRows||i.startsWith("track")||i.startsWith("#")||i.startsWith("browser"))continue;let t=s();if(t.length<1)continue;if(!this.aed){this.aed=Rh(t);continue}const r=n.call(this,t,undefined);r&&e.push(r)}return e;function s(){for(var t,e,n=[],o="",s=!1;i||""===i;){for(t=0;t<i.length;t++)(e=i.charAt(t))===r?s?o+=e:(n.push(o),o=""):'"'===e?t+1<i.length&&'"'===i.charAt(t+1)?(s&&(o+='"'),t++):s=!s:o+=e;if(!s)break;o+="\n",i=nextLine()}return n.push(o),n}}}function Mh(t){var e=Th.exec(t);if(e)return{namespace:e[1],name:e[2],type:e[3]};if(e=Ah.exec(t))return{namespace:"?",name:e[1],type:e[2]};throw new Error("Error parsing the header row of AED file - column not in ns:name(ns:type) format")}function Rh(t){var e,n,r;for(e={columns:[],metadata:{}},n=0;n<t.length;n++)r=Mh(t[n]),e.columns.push(r);return e}function Ih(t){const e={},n=t.split(/(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g);let r;const i=[];for(let t of n)t&&0!==t.trim().length&&(t.endsWith("=")>0?r=t:r?(i.push(r+t),r=void 0):i.push(t));for(let t of i){if(!t)return;var o=t.split("=",2);if(2===o.length){const t=o[0].trim(),n=o[1].trim();e[t]=n}}return e}function Nh(t){let e={},n=t.split(/\s+/);if(2===n.length){n[1].split(";").forEach((function(t){let n=t.split("=");"color"===n[0]?e.colorColumn=Number.parseInt(n[1])-1:"thickness"===n[0]&&(e.thicknessColumn=Number.parseInt(n[1])-1)}))}return e}function Ph(t,e){var n,r,i=t.columns;this.aed=t,this.allColumns=e,this.chr=null,this.start=null,this.end=null,this.score=1e3,this.strand=".",this.cdStart=null,this.cdEnd=null,this.name=null,this.color=null;for(let t=0;t<e.length;t++)if(n=e[t]){"aed:Integer"===(r=i[t]).type&&(n=parseInt(n));var o=[];if(r.namespace.length>0)for(let t=0;t<r.namespace.length;t++)o.push(r.namespace.charCodeAt(t));"bio"===r.namespace.trim()?"sequence"===r.name?this.chr=n:"start"===r.name?this.start=n:"end"===r.name?this.end=n:"cdsMin"===r.name?this.cdStart=n:"cdsMax"===r.name?this.cdEnd=n:"strand"===r.name&&(this.strand=n):"aed"===r.namespace?"name"===r.name&&(this.name=n):"style"===r.namespace&&"color"===r.name&&(this.color=no.createColorString(n))}}function Oh(t,e){var n,r,i,o,s,a,c=0,l=this.aed.columns;if(t.length===l.length){for(a=0;a<t.length;a++)o=l[a],""!==(i=t[a])&&c++,"name"===o.name&&"aed"===o.namespace?n=i:"value"===o.name&&"aed"===o.namespace&&(r=i);if(2===c&&n&&r)return s=Mh(n),this.aed.metadata[s.namespace]||(this.aed.metadata[s.namespace]={}),void(this.aed.metadata[s.namespace][s.name]||(this.aed.metadata[s.namespace][s.name]={type:s.type,value:r}));var h=new Ph(this.aed,t);if(h.chr&&(h.start||0===h.start)&&h.end)return h;console.log("Cannot parse feature: "+t.join(","))}else console.log("Corrupted AED file row: "+t.join(","))}function Fh(t){return"string"==typeof t||t instanceof String?new Dh(t):new Bh(t)}Ph.prototype.popupData=function(){for(var t=[],e=this.aed,n=0;n<this.allColumns.length;n++){var r=this.allColumns[n],i=e.columns[n].name;"sequence"!==i&&"color"!==i&&r&&t.push({name:i,value:r})}return t};class Dh{constructor(t){this.data=t,this.ptr=0}nextLine(){var t=this.ptr,e=this.data.indexOf("\n",t),n=this.data;if(e>0)return this.ptr=e+1,e>t&&"\r"===n.charAt(e-1)?n.substring(t,e-1):n.substring(t,e);var r=n.length;return this.ptr=r,t>=r?void 0:n.substring(t)}}class Bh{constructor(t){this.data=t,this.length=this.data.length,this.ptr=0}nextLine(){var t,e;if(e="",!(this.ptr>=this.length)){for(var n=this.ptr;n<this.length;n++)if("\r"!==(t=String.fromCharCode(this.data[n]))){if("\n"===t)break;e+=t}return this.ptr=n+1,e}}}class zh{constructor(t){this.config=t,this.filePtr=0,this.bufferPtr=0,this.buffer}async nextLine(){let t;try{for(;;){const e=this.buffer?this.buffer.length:0;for(;this.bufferPtr<e;){const e=String.fromCharCode(this.buffer[this.bufferPtr++]);if("\r"!==e){if("\n"===e)return t;t=t?t+e:e}}if(this.eof)return t;await this.readNextBlock()}}catch(e){return console.warn(e),this.eof=!0,t}}async readNextBlock(){const t=gs(this.config,{range:{start:this.filePtr,size:26}}),e=$i(await go.loadArrayBuffer(this.config.url,t));if(0===e)this.eof=!0,this.buffer=void 0;else{const t=gs(this.config,{range:{start:this.filePtr,size:e}}),n=await go.loadArrayBuffer(this.config.url,t);n.byteLength<e&&(this.eof=!0),this.buffer=Wi(n),this.bufferPtr=0,this.filePtr+=n.byteLength}}}class Hh{constructor(t,e){var n;this.config=t||{},this.genome=e,this.indexURL=t.indexURL,this.indexed=t.indexed,je(this.config.url)?this.filename=this.config.url.name:ys(this.config.url)?(this.indexed=!1,this.dataURI=t.url):(n=ze(this.config.url),this.filename=t.filename||n.file),this.parser=this.getParser(this.config),"vcf"!==this.config.format||this.config.indexURL||console.warn("Warning: index file not specified. The entire vcf file will be loaded.")}async defaultVisibilityWindow(){if(this.config.indexURL){const t=await this.getIndex();if(t&&t.lastBlockPosition){let e=0;const n=1e4;for(let n of t.chromosomeNames){const t=this.genome.getChromosome(n);t&&(e+=t.bpLength)}return Math.round(e/t.lastBlockPosition*n)}}}async readFeatures(t,e,n){return await this.getIndex()?(this.indexed=!0,this.loadFeaturesWithIndex(t,e,n)):this.dataURI?(this.indexed=!1,this.loadFeaturesFromDataURI()):(this.indexed=!1,this.loadFeaturesNoIndex())}async readHeader(){if(this.dataURI)return await this.loadFeaturesFromDataURI(this.dataURI),this.header;if(this.config.indexURL){const t=await this.getIndex();if(!t)throw new Error("Unable to load index: "+this.config.indexURL);let e;if(t.tabix)e=new zh(this.config);else{const n=Object.values(t.chrIndex).flatMap((t=>t.blocks)).map((t=>t.max)).reduce(((t,e)=>Math.min(t,e)),Number.MAX_SAFE_INTEGER),r=gs(this.config,{bgz:t.tabix,range:{start:0,size:n}});e=Fh(await go.loadString(this.config.url,r))}return this.header=await this.parser.parseHeader(e),this.header}{const t=gs(this.config),e=await go.loadString(this.config.url,t);let n=Fh(e);return this.header=await this.parser.parseHeader(n),n=Fh(e),this.features=await this.parser.parseFeatures(n),this.header}}getParser(t){switch(t.format){case"vcf":return new kh(t);case"seg":return new gh("seg");case"mut":return new gh("mut");case"maf":return new gh("maf");case"gwas":return new Ch(t);case"aed":return new Lh(t);default:return new hh(t)}}async loadFeaturesNoIndex(){if(this.features){const t=this.features;return delete this.features,t}{const t=gs(this.config),e=await go.loadString(this.config.url,t);if(!this.header){const t=Fh(e);this.header=await this.parser.parseHeader(t)}const n=Fh(e);return await this.parser.parseFeatures(n)}}async loadFeaturesWithIndex(t,e,n){const r=this.config,i=this.parser,o=this.index.tabix,s=o?this.index.sequenceIndexMap[t]:t;if(void 0===s)return[];const a=this.genome,c=this.index.blocksForRange(s,e,n);if(c&&0!==c.length){const s=[];for(let l of c){const c=l.minv.block,h=l.minv.offset,u=l.maxv.offset;let f;if(o){let t=0;if(u>0){const e=gs(r,{range:{start:l.maxv.block,size:26}});t=$i(await go.loadArrayBuffer(r.url,e))}f=l.maxv.block+t}else f=l.maxv.block;const d=gs(r,{range:{start:c,size:f-c+1}});let p;if(o){p=Wi(await go.loadArrayBuffer(r.url,d))}else p=await go.loadString(r.url,d);const g=Fh(h?p.slice(h):p);let m=await i.parseFeatures(g);m=m.filter((t=>void 0===t._f));let v=!1;for(let r=0;r<m.length;r++){const i=m[r];if((a?a.getChromosomeName(i.chr):i.chr)!==t){if(0===s.length)continue;break}if(i.start>n){s.push(i);break}i.end>=e&&i.start<=n&&(v||(v=!0,r>0&&s.push(m[r-1])),s.push(i))}}return s.sort((function(t,e){return t.start-e.start})),s}return[]}async getIndex(){return this.index?this.index:this.config.indexURL?(this.index=await this.loadIndex(),this.index):void 0}async loadIndex(){return Ya(this.config.indexURL,this.config,this.genome)}async loadFeaturesFromDataURI(){if(this.features){const t=this.features;return delete this.features,t}{const t=Yi(this.dataURI);let e=Fh(t);return this.header=await this.parser.parseHeader(e),this.header instanceof String&&this.header.startsWith("##gff-version 3")&&(this.format="gff3"),e=Fh(t),this.features=await this.parser.parseFeatures(e),this.features}}}const Vh=ke;class jh{constructor(t){this.config=t}async readFeatures(t,e,n){let r;r="function"==typeof this.config.url?this.config.url({chr:t,start:e,end:n}):this.config.url.replace("$CHR",t).replace("$START",e).replace("$END",n);let i,o=Object.assign({},this.config);void 0!==this.config.body&&("function"==typeof this.config.body?o.body=this.config.body({chr:t,start:e,end:n}):o.body=this.config.body.replace("$CHR",t).replace("$START",e).replace("$END",n));const s=await go.load(r,o);if(s&&(i="function"==typeof this.config.parser?this.config.parser(s):Vh(s)?JSON.parse(s):s),this.config.mappings){let t=Object.keys(this.config.mappings);for(let e of i)for(let n of t)e[n]=e[this.config.mappings[n]]}return i}}const Uh=function(t,e){this.config=t,this.genome=e,this.expandQueryInterval=!1};Uh.prototype.readFeatures=function(t,e,n){const r=Math.max(0,Math.floor(e));let i=Math.ceil(n);if(this.genome){const e=this.genome.getChromosome(t);e&&i>e.bpLength&&(i=e.bpLength)}const o=this.config.url+"?db="+this.config.db+"&table="+this.config.tableName+"&chr="+t+"&start="+r+"&end="+i;return go.loadJson(o,this.config).then((function(t){return t?(t.forEach((function(t){t.hasOwnProperty("exonStarts")&&t.hasOwnProperty("exonEnds")&&t.hasOwnProperty("exonCount")&&t.hasOwnProperty("cdsStart")&&t.hasOwnProperty("cdsEnd")&&function(t){var e,n,r,i,o,s;e=t.exonCount,n=t.exonStarts.split(","),r=t.exonEnds.split(","),i=[];for(var a=0;a<e;a++){var c={start:o=parseInt(n[a]),end:s=parseInt(r[a])};(t.cdsStart>s||t.cdsEnd<t.cdsStart)&&(c.utr=!0),t.cdsStart>=o&&t.cdsStart<=s&&(c.cdStart=t.cdsStart),t.cdsEnd>=o&&t.cdsEnd<=s&&(c.cdEnd=t.cdsEnd),i.push(c)}t.exons=i}(t)})),t):null}))};const qh=["Name","gene_name","gene","gene_id","alias","locus","name"];class Wh{constructor(t){this.format=t.format,this.nameField=t.nameField,this.filterTypes=void 0===t.filterTypes?new Set(["chromosome"]):new Set(t.filterTypes)}combineFeatures(t,e){let n;const r=this.filterTypes;if(t=t.filter((t=>void 0===r||!r.has(t.type))),"gff3"===this.format){const e=this.combineFeaturesById(t);n=this.combineFeaturesByType(e)}else n=this.combineFeaturesByType(t);return n.sort((function(t,e){return t.start-e.start})),this.numberExons(n,e),this.nameFeatures(n),n}combineFeaturesById(t){const e=new Map,n=[];for(let r of t)if(zl(r.type)||Bl(r.type)||!r.id)n.push(r);else{let t=e.get(r.chr);t||(t=new Map,e.set(r.chr,t));let n=t.get(r.id);n?n.push(r):t.set(r.id,[r])}for(let t of e.values())for(let e of t.values())if(e.length>1){const t=e[0];t.exons=[];for(let n of e)t.start=Math.min(t.start,n.start),t.end=Math.max(t.end,n.end),t.exons.push({start:n.start,end:n.end});n.push(t)}else n.push(e[0]);return n}combineFeaturesByType(t){const e=t.filter((t=>"gene"===t.type||t.type.endsWith("_gene"))),n=Object.create(null);for(let t of e)n[t.id]=t;const r=Object.create(null),i=[],o=new Set,s=this.filterTypes;t=t.filter((t=>void 0===s||!s.has(t.type)));for(let e of t)if("biological_region"===e.type&&console.log(),Bl(e.type)){const t=e.id;if(void 0!==t){const s=new jl(e);r[t]=s,i.push(s),o.add(e);const a=n[e.parent];a&&(s.geneObject=a,o.add(a))}}for(let e of t)if(zl(e.type)){const t=l(e);if(t)for(let n of t){let s=r[n];if(!s&&"gtf"===this.format){const t=Object.assign({},e);t.type="transcript",s=new jl(t),r[n]=s,i.push(s)}if(void 0!==s){if(a=e.type,Nl.has(a))if(t.length>1){const t=new Vl(e);s.addExon(t)}else s.addExon(e);else s.addPart(e);o.add(e)}}}var a;i.forEach((function(t){"function"==typeof t.finish&&t.finish()}));const c=t.filter((t=>!o.has(t)));for(let t of c)i.push(t);return i;function l(t){return t.parent&&""!==t.parent.trim()?t.parent.trim().split(","):null}}numberExons(t,e){for(let n of t)if(n.exons&&(!e||n.end<=e.end&&n.start>e.start))for(let t=0;t<n.exons.length;t++){n.exons[t].number="-"===n.strand?n.exons.length-t:t+1}}nameFeatures(t){for(let e of t)if(e.attributeString){const t="gff3"===this.format?"=":" ",n=$l(e.attributeString,t),r=new Map(n);if(this.nameField)e.name=r.get(this.nameField);else for(let t of qh)if(r.has(t)){e.name=r.get(t);break}}}}const $h=function(t){this.config=t,this.url=t.url,this.tissueId=t.tissueSiteDetailId,this.indexed=!0,this.datasetId=t.datasetId||"gtex_v8"};$h.prototype.readFeatures=async function(t,e,n){let r=t.startsWith("chr")?t:"chr"+t,i=Math.floor(e),o=Math.ceil(n),s=this.datasetId,a=this.url+"?chromosome="+r+"&start="+i+"&end="+o+"&tissueSiteDetailId="+this.tissueId+"&datasetId="+s;const c=await go.loadJson(a,{withCredentials:this.config.withCredentials});return c&&c.singleTissueEqtl?(c.singleTissueEqtl.forEach((function(t){t.chr=t.chromosome,t.position=t.pos,t.start=t.pos-1,t.end=t.start+1,t.snp=t.snpId,t.geneName=t.geneSymbol,t.geneId=t.gencodeId})),c.singleTissueEqtl):void 0};const Gh=function(t){this.config=t,this.url=t.url,this.cellConditionId=t.cellConditionId,this.valueThreshold=t.valueThreshold?t.valueThreshold:.05};Gh.prototype.readFeatures=function(t,e,n){var r=this,i=this.url+"?chromosome="+t+"&start="+e+"&end="+n+"&cell_condition_id="+this.cellConditionId;return new Promise((function(t,e){go.loadJson(i,{withCredentials:r.config.withCredentials}).then((function(e){e?(e.eqtls.forEach((function(t){t.chr=t.chromosome,t.start=t.position,t.end=t.position+1})),t(e.eqtls)):t(null)})).catch((function(t){e(t)}))}))};const Zh=function(t,e){this.config=t,this.genome=e,this.url=t.url,this.variantSetId=t.variantSetId,this.callSetIds=t.callSetIds,this.includeCalls=void 0===t.includeCalls||t.includeCalls};Zh.prototype.readHeader=function(){var t=this;return t.header?Promise.resolve(t.header):(t.header={},!1===t.includeCalls?Promise.resolve(t.header):dc({url:t.url+"/callsets/search",fields:"nextPageToken,callSets(id,name)",body:{variantSetIds:Array.isArray(t.variantSetId)?t.variantSetId:[t.variantSetId],pageSize:"10000"},decode:function(e){if(t.callSetIds){var n=[],r=new Set;return t.callSetIds.forEach((function(t){r.add(t)})),e.callSets.forEach((function(t){r.has(t.id)&&n.push(t)})),n}return e.callSets}}).then((function(e){return t.header.callSets=e,t.header})))},Zh.prototype.readFeatures=function(t,e,n){const r=this,i=this.genome;return r.readHeader().then((function(t){return new Promise((function(t,e){r.chrAliasTable?t(r.chrAliasTable):r.readMetadata().then((function(e){r.metadata=e.metadata,r.chrAliasTable={},e.referenceBounds&&i&&e.referenceBounds.forEach((function(t){var e=t.referenceName,n=i.getChromosomeName(e);r.chrAliasTable[n]=e})),t(r.chrAliasTable)}))}))})).then((function(i){var o=i.hasOwnProperty(t)?i[t]:t;return dc({url:r.url+"/variants/search",fields:r.includeCalls?void 0:"nextPageToken,variants(id,variantSetId,names,referenceName,start,end,referenceBases,alternateBases,quality,filter,info)",body:{variantSetIds:Array.isArray(r.variantSetId)?r.variantSetId:[r.variantSetId],callSetIds:r.callSetIds?r.callSetIds:void 0,referenceName:o,start:e.toString(),end:n.toString(),pageSize:"10000"},decode:function(t){var e,n=[];return t.variants.forEach((function(t){e=function(t){var e,n=new bh;return n.chr=t.referenceName,n.start=parseInt(t.start),n.end=parseInt(t.end),n.pos=n.start+1,n.names=xh(t.names,"; "),n.referenceBases=t.referenceBases,n.alternateBases=xh(t.alternateBases),n.quality=t.quality,n.filter=xh(t.filter),n.info={},t.info&&Object.keys(t.info).forEach((function(e){var r,i=t.info[e];r=Array.isArray(i)?i.join(","):i,n.info[e]=r})),n.calls={},t.calls&&t.calls.forEach((function(t){e=t.callSetId,n.calls[e]=t})),init(n),n}(t),e.isRefBlock()||n.push(e)})),n}})}))},Zh.prototype.readMetadata=function(){return fc({url:this.url,entity:"variantsets",entityId:this.variantSetId})};class Xh{constructor(t){this.config=t}async readFeatures(t,e,n){const r=(await go.loadJson(this.config.url+"/variants/?count=50000")).records,i=[];for(let t of r)if(t.coordinates){t.id;const e=t.coordinates;e.chromosome&&i.push(new Yh(e.chromosome,e.start-1,e.stop,t)),e.chromosome2&&i.push(new Yh(e.chromosome2,e.start2-1,e.stop2,t))}return i}}class Yh{constructor(t,e,n,r){if(this.chr=t,this.start=e,this.end=n,this.id=r.id,this.entrezName=r.entrez_name,this.name=r.name,this.actionabilityScore=r.civic_actionability_score,r.coordinates.reference_bases&&(this.refBases=r.coordinates.reference_bases),r.coordinates.variant_bases&&(this.altBases=r.coordinates.variant_bases),r.variant_types&&(this.variant_types=r.variant_types),this.locationString=this.chr+":"+_e(this.start+1)+"-"+_e(this.end),void 0!==this.actionabilityScore){let t;if(this.actionabilityScore<=10)t=.2;else{const e=Math.min(30,this.actionabilityScore);t=.2+.8*Math.log10((e-10)/2)}this.alpha=t}}popupData(){const t=n("CIViC","https://civicdb.org/links/variants/"+this.id);this.refBases!==this.altBases&&this.refBases&&1===this.refBases.length&&this.altBases&&this.altBases.length;const e=[t];if(e.push({name:"Entrez",value:n(this.entrezName,"https://ghr.nlm.nih.gov/gene/"+this.entrezName)}),e.push({name:"Name",value:this.name}),this.variant_types&&this.variant_types.length>0){const t=1===this.variant_types.length?"Type":"Types";let n;for(let t of this.variant_types)n?n+=", "+t.display_name:n=t.display_name;e.push({name:t,value:n})}return e.push({name:"Actionability",value:this.actionabilityScore}),e.push({name:"Location",value:this.locationString}),e;function n(t,e){return"<a target='_blank' href='"+e+"'>"+t+"</a>"}}}function Kh(t,e){e=e||Number.MAX_SAFE_INTEGER;const n=[];t.sort((function(t,e){return t.start-e.start})),n.push(-1e3);for(let r of t){let t=0;const i=Math.min(n.length,e);for(t=0;t<i;t++)if(r.start>=n[t]){r.row=t,n[t]=r.end;break}r.row=t,n[t]=r.end}}class Qh extends ec{constructor(t,e){super(t,e),this.parser=new kh}async readHeader(){if(!this.header){const t=Fh(await this.readHeaderData());this.header=await this.parser.parseHeader(t,this.genome),this.chrAliasTable=this.header.chrAliasTable}return this.header}async readFeatures(t,e,n){if(this.config.format&&"VCF"!==this.config.format.toUpperCase())throw Error(`htsget format ${this.config.format} is not supported`);this.chrAliasTable||await this.readHeader();let r=this.chrAliasTable.has(t)?this.chrAliasTable.get(t):t;const i=Fh(await this.readData(r,e,n));return this.parser.parseFeatures(i)}}class Jh{constructor(t,e){this.config=t||{},this.genome=e,this.sourceType=void 0===t.sourceType?"file":t.sourceType,this.maxWGCount=t.maxWGCount||1e4;const n=new Set(["bigwig","bw","bigbed","bb","biginteract","biggenepred","bignarrowpeak","tdf"]);if(t.features&&Array.isArray(t.features)){let n=function(t,e){if(!t||0===t.length)return[];if(void 0===t[0].chr&&void 0!==t[0].chr1){const n=[];for(let r of t)e&&(r.chr1=e.getChromosomeName(r.chr1),r.chr2=e.getChromosomeName(r.chr2)),r.chr1===r.chr2?(r.chr=r.chr1,r.start=Math.min(r.start1,r.start2),r.end=Math.max(r.end1,r.end2)):n.push(r);for(let e of n){const n=Object.assign({dup:!0},e);t.push(n),e.chr=e.chr1,e.start=e.start1,e.end=e.end1,n.chr=n.chr2,n.start=n.start2,n.end=n.end2}}else if(e)for(let n of t)n.chr=e.getChromosomeName(n.chr);return t}(t.features,e);tu(n),t.mappings&&function(t,e){let n=Object.keys(e);t.forEach((function(t){n.forEach((function(n){t[n]=t[e[n]]}))}))}(n,t.mappings),this.queryable=!1,this.featureCache=new Mo(n,e)}else t.reader?(this.reader=t.reader,this.queryable=!1!==t.queryable):"ga4gh"===t.sourceType?(this.reader=new Zh(t,e),this.queryable=!0):"immvar"===t.sourceType?(this.reader=new Gh(t),this.queryable=!0):"eqtl"===t.type&&"gtex-ws"===t.sourceType?(this.reader=new $h(t),this.queryable=!0):"htsget"===t.sourceType?this.reader=new Qh(t,e):"ucscservice"===t.sourceType?(this.reader=new Uh(t.source),this.queryable=!0):"custom"===t.sourceType?(this.reader=new jh(t.source),this.queryable=!1!==t.source.queryable):"civic-ws"===t.sourceType?(this.reader=new Xh(t),this.queryable=!1):(this.reader=new Hh(t,e),void 0!==t.queryable?this.queryable=t.queryable:(n.has(t.format)||this.reader.indexed)&&(this.queryable=!0))}async defaultVisibilityWindow(){if(this.reader&&"function"==typeof this.reader.defaultVisibilityWindow)return this.reader.defaultVisibilityWindow()}async trackType(){const t=await this.getHeader();return t?t.type:void 0}async getHeader(){if(!this.header)if(this.reader&&"function"==typeof this.reader.readHeader){const t=await this.reader.readHeader();t?(this.header=t,t.format&&(this.config.format=t.format)):this.header={}}else this.header={};return this.header}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i}){const o=this.genome,s=o?o.getChromosomeName(t):t,a="all"===s.toLowerCase();return(a&&!this.getWGFeatures||this.config.disableCache||!this.featureCache||!this.featureCache.containsRange(new Gs(s,e,n)))&&await this.loadFeatures(s,e,n,i),a?(this.wgFeatures||(this.queryable?this.wgFeatures=[]:this.wgFeatures=this.getWGFeatures(this.featureCache.getAllFeatures())),this.wgFeatures):this.featureCache.queryFeatures(s,e,n)}getAllFeatures(){return this.queryable?[]:this.getWGFeatures(this.featureCache.getAllFeatures())}async loadFeatures(t,e,n,r){const i=this.reader;let o=e,s=n;if((!r||r<=0)&&!1!==this.config.expandQuery){const e=this.genome?this.genome.getChromosome(t):void 0;o=0,s=Math.max(e?e.bpLength:Number.MAX_SAFE_INTEGER,n)}else if(r>n-e&&!1!==this.config.expandQuery){const t=Math.min(4.1*(n-e),r);o=Math.max(0,(e+n)/2-t),s=e+t}let a=await i.readFeatures(t,o,s);void 0===this.queryable&&(this.queryable=i.indexed);const c=this.queryable?new Gs(t,o,s):void 0;if(a){if(!1===this.config.assembleGFF||"gtf"!==this.config.format&&"gff3"!==this.config.format&&"gff"!==this.config.format||(a=new Wh(this.config).combineFeatures(a,c)),"wig"!==this.config.format&&"junctions"!==this.config.type){tu(a,this.config.maxRows||Number.MAX_SAFE_INTEGER)}this.featureCache=new Mo(a,this.genome,c),(this.config.searchable||this.config.searchableFields)&&this.addFeaturesToDB(a)}else this.featureCache=new Mo([],c)}addFeaturesToDB(t){for(let e of t)if(e.name&&(this.genome.featureDB[e.name.toUpperCase()]=e),e.gene&&e.gene.name&&(this.genome.featureDB[e.gene.name.toUpperCase()]=e),this.config.searchableFields)for(let t of this.config.searchableFields){const n=e.getAttributeValue(t);n&&(n.indexOf(" ")>0?(this.genome.featureDB[n.replaceAll(" ","+").toUpperCase()]=e,this.genome.featureDB[n.replaceAll(" ","%20").toUpperCase()]=e):this.genome.featureDB[n.toUpperCase()]=e)}}getWGFeatures(t){const e=t=>{const e=Object.assign({},t);return e.chr="all",e.start=n.getGenomeCoordinate(t.chr,t.start),e.end=n.getGenomeCoordinate(t.chr,t.end),e._f=t,e.exons&&delete e.exons,e},n=this.genome,r=new Set(n.wgChromosomeNames),i=[];let o=0;const s=this.maxWGCount;for(let a of n.wgChromosomeNames){const c=t[a];if(c)for(let t of c){let a=n.getChromosomeName(t.chr);if(r.has(a))if(i.length<s)i.push(e(t));else{const n=s/(o+1);if(Math.random()<n){i[Math.floor(Math.random()*(s-1))]=e(t)}}o++}}return i.sort((function(t,e){return t.start-e.start})),i}}function tu(t,e){if(e=e||1e3,null==t||0===t.length)return;const n={},r=[];for(let e of t){const t=e.chr;let i=n[t];i||(i=[],n[t]=i,r.push(t)),i.push(e)}for(let t of r)Kh(n[t],e)}class eu{constructor(t,e,n){this.path=t.url,this.bufferSize=n||512e3,this.range={start:-1,size:-1},this.config=t}async dataViewForRange(t,e){if(!(this.data&&this.range.start<=t.start&&this.range.start+this.range.size>=t.start+t.size)){let e;e=t.size?Math.max(this.bufferSize,t.size):this.bufferSize;const n={start:t.start,size:e},r=await go.loadArrayBuffer(this.path,gs(this.config,{range:n}));this.data=r,this.range=n}const n=this.data.byteLength,r=t.start-this.range.start;return e?new Uint8Array(this.data,r,n-r):new DataView(this.data,r,n-r)}}class nu{constructor(t,e){this.path=t.url,this.format=t.format||"bigwig",this.genome=e,this.rpTreeCache={},this.config=t,this.loader=ys(this.path)?new du(this.path):go}async readWGFeatures(t,e){await this.loadHeader();const n=this.chromTree.idToChrom.length-1,r=this.chromTree.idToChrom[0],i=this.chromTree.idToChrom[n];return this.readFeatures(r,0,i,Number.MAX_VALUE,t,e)}async readFeatures(t,e,n,r,i,o){await this.loadHeader();const s=this.chromTree.chromToID[t],a=this.chromTree.chromToID[n];if(void 0===s||void 0===a)return[];let c,l;if("bigwig"===this.type){const t=await this.getZoomHeaders();let e=i?function(t,e){let n;for(let r=0;r<e.length;r++){const i=e[r];if(i.reductionLevel<t){n=i;break}}return n}(i,t):void 0;e?(c=e.indexOffset,l=fu):(c=this.header.fullIndexOffset,l=hu)}else c=this.header.fullIndexOffset,l=uu.call(this);const h=await this.loadRPTree(c),u=await h.findLeafItemsOverlapping(s,e,a,r);if(u&&0!==u.length){let t=Number.MAX_VALUE,n=0;for(let e of u)t=Math.min(t,e.dataOffset),n=Math.max(n,e.dataOffset+e.dataSize);const i=n-t,c=await this.loader.loadArrayBuffer(this.config.url,gs(this.config,{range:{start:t,size:i}})),h=[];for(let n of u){const i=new Uint8Array(c,n.dataOffset-t,n.dataSize);let u;u=this.header.uncompressBuffSize>0?qi(i):i,l.call(this,new DataView(u.buffer),s,e,a,r,h,this.chromTree.idToChrom,o)}return h.sort((function(t,e){return t.start-e.start})),h}return[]}async getZoomHeaders(){return this.zoomLevelHeaders||await this.loadHeader(),this.zoomLevelHeaders}async loadHeader(){if(this.header)return this.header;{let t,e=await this.loader.loadArrayBuffer(this.path,gs(this.config,{range:{start:0,size:64}}));this.littleEndian=!0;let n=new Wa(new DataView(e)),r=n.getUInt();if(2291137574===r)this.type="bigwig";else if(2273964779===r)this.type="bigbed";else{this.littleEndian=!1,n.littleEndian=!1,n.position=0;let t=n.getUInt();654085990===t?this.type="bigwig":3958540679===t&&(this.type="bigbed")}t={bwVersion:n.getUShort(),nZoomLevels:n.getUShort(),chromTreeOffset:n.getLong(),fullDataOffset:n.getLong(),fullIndexOffset:n.getLong(),fieldCount:n.getUShort(),definedFieldCount:n.getUShort(),autoSqlOffset:n.getLong(),totalSummaryOffset:n.getLong(),uncompressBuffSize:n.getInt(),extensionOffset:n.getLong()};const i=64;let o={start:i,size:t.fullDataOffset-i+5};e=await this.loader.loadArrayBuffer(this.path,gs(this.config,{range:o}));const s=t.nZoomLevels;n=new Wa(new DataView(e)),this.zoomLevelHeaders=[],this.firstZoomDataOffset=Number.MAX_SAFE_INTEGER;for(let t=1;t<=s;t++){const e=s-t,r=new ru(e,n);this.firstZoomDataOffset=Math.min(r.dataOffset,this.firstZoomDataOffset),this.zoomLevelHeaders[e]=r}if(t.autoSqlOffset>0){n.position=t.autoSqlOffset-i;const e=n.getString();e&&(this.autoSql=function(t){let e;const n=[];let r=!1;const i=t.trim().split(/\s*[\r\n]+\s*/g);for(let t of i)if(t.startsWith("table"))e=t.split(/\s+/)[1].trim();else if(t.startsWith("("))r=!0;else if(t.startsWith(")"));else if(r&&t.length>0){const e=t.indexOf(";"),r=t.substr(0,e).split(/\s+/),i=t.substr(e+1).replace(/"/g,"").trim();n.push({type:r[0],name:r[1],description:i})}return{table:e,fields:n}}(e))}if(t.totalSummaryOffset>0&&(n.position=t.totalSummaryOffset-i,this.totalSummary=new cu(n)),!(t.chromTreeOffset>0))throw"BigWig chromosome tree offset <= 0";return n.position=t.chromTreeOffset-i,this.chromTree=new su(n,i,this.genome),n.position=t.fullDataOffset-i,t.dataCount=n.getInt(),this.setDefaultVisibilityWindow(t),this.header=t,this.header}}async loadRPTree(t){let e=this.rpTreeCache[t];return e||(e=new iu(t,this.config,this.littleEndian,this.loader),await e.load(),this.rpTreeCache[t]=e,e)}async getType(){return await this.loadHeader(),this.type}async getTrackType(){return await this.loadHeader(),"bigwig"===this.type?"wig":this.autoSql&&"chromatinInteract"===this.autoSql.table?"interact":"annotation"}setDefaultVisibilityWindow(t){if("bigwig"===this.type)this.visibilityWindow=-1;else{let e=this.genome?this.genome.getGenomeLength():3088286401;this.visibilityWindow=t.dataCount<1e3?-1:e/t.dataCount*1e3}}}class ru{constructor(t,e){this.index=t,this.reductionLevel=e.getInt(),this.reserved=e.getInt(),this.dataOffset=e.getLong(),this.indexOffset=e.getLong()}}class iu{constructor(t,e,n,r){this.config=e,this.loader=r,this.fileOffset=t,this.path=e.url,this.littleEndian=n}async load(){const t=this.fileOffset+48,e=ys(this.path)?this.loader:new eu(this.config,512e3);return this.rootNode=await this.readNode(t,e),this}async readNode(t,e){let n=await e.dataViewForRange({start:t,size:4},!1),r=new Wa(n,this.littleEndian);const i=1===r.getByte();r.getByte();const o=r.getUShort();let s={start:t+=4,size:o*(i?32:24)};n=await e.dataViewForRange(s,!1);const a=new Array(o);if(r=new Wa(n),i){for(let t=0;t<o;t++){let e={isLeaf:!0,startChrom:r.getInt(),startBase:r.getInt(),endChrom:r.getInt(),endBase:r.getInt(),dataOffset:r.getLong(),dataSize:r.getLong()};a[t]=e}return new ou(a)}for(let t=0;t<o;t++){let e={isLeaf:!1,startChrom:r.getInt(),startBase:r.getInt(),endChrom:r.getInt(),endBase:r.getInt(),childOffset:r.getLong()};a[t]=e}return new ou(a)}async findLeafItemsOverlapping(t,e,n,r){let i=this;return new Promise((function(o,s){let a=[],c=new Set,l=ys(i.path)?i.loader:new eu(i.config,512e3);c.add(0),function h(u,f){if(au(u,t,e,n,r)){u.items.forEach((function(o){au(o,t,e,n,r)&&(o.isLeaf?a.push(o):o.childNode?h(o.childNode):(c.add(o.childOffset),i.readNode(o.childOffset,l).then((function(t){o.childNode=t,h(t,o.childOffset)})).catch(s)))}))}void 0!==f&&c.delete(f);0===c.size&&o(a)}(i.rootNode,0)}))}}class ou{constructor(t){this.items=t;let e,n,r=Number.MAX_SAFE_INTEGER,i=0,o=Number.MAX_SAFE_INTEGER,s=0;for(e=0;e<t.length;e++)n=t[e],r=Math.min(r,n.startChrom),i=Math.max(i,n.endChrom),o=Math.min(o,n.startBase),s=Math.max(s,n.endBase);this.startChrom=r,this.endChrom=i,this.startBase=o,this.endBase=s}}class su{constructor(t,e,n){let r=t.getInt(),i=t.getInt(),o=t.getInt(),s=t.getInt(),a=t.getLong(),c=t.getLong(),l={},h=[];this.header={magic:r,blockSize:i,keySize:o,valSize:s,itemCount:a,reserved:c},this.chromToID=l,this.idToChrom=h,function t(r,i){i>=0&&(r.position=i);let s=r.getByte();r.getByte();let a,c,u,f,d,p,g=r.getUShort();if(1===s)for(a=0;a<g;a++)c=r.getFixedLengthTrimmedString(o),u=r.getInt(),r.getInt(),n&&(c=n.getChromosomeName(c)),l[c]=u,h[u]=c;else for(a=0;a<g;a++)c=r.getFixedLengthTrimmedString(o),f=r.getLong(),d=f-e,p=r.position,t(r,d),r.position=p}(t,-1)}}function au(t,e,n,r,i){return t?(r>t.startChrom||r===t.startChrom&&i>=t.startBase)&&(e<t.endChrom||e===t.endChrom&&n<=t.endBase):(console.log("null item for "+e+" "+n+" "+i),!1)}class cu{constructor(t){t?(this.basesCovered=t.getLong(),this.minVal=t.getDouble(),this.maxVal=t.getDouble(),this.sumData=t.getDouble(),this.sumSquares=t.getDouble(),lu.call(this)):(this.basesCovered=0,this.minVal=0,this.maxVal=0,this.sumData=0,this.sumSquares=0,this.mean=0,this.stddev=0)}}function lu(){let t=this.basesCovered;if(t>0){this.mean=this.sumData/t,this.stddev=Math.sqrt(this.sumSquares/(t-1));let e=this.minVal<0?this.mean-2*this.stddev:0,n=this.maxVal>0?this.mean+2*this.stddev:0;this.defaultRange={min:e,max:n}}}function hu(t,e,n,r,i,o,s){const a=new Wa(t),c=a.getInt();let l=a.getInt(),h=a.getInt();const u=a.getInt(),f=a.getInt(),d=a.getByte();a.getByte();let p=a.getUShort();if(c>=e&&c<=r)for(;p-- >0;){let t;switch(d){case 1:l=a.getInt(),h=a.getInt(),t=a.getFloat();break;case 2:l=a.getInt(),t=a.getFloat(),h=l+f;break;case 3:t=a.getFloat(),h=l+f,l+=u}if(!(c<e||c===e&&h<n)){if(c>r||c===r&&l>=i)break;if(Number.isFinite(t)){const e=s[c];o.push({chr:e,start:l,end:h,value:t})}}}}function uu(){const t=function(t,e,n,r){if("biginteract"===r||n&&"chromatinInteract"===n.table||"interact"===n.table)return function(t,e){return t.chr1=e[5],t.start1=Number.parseInt(e[6]),t.end1=Number.parseInt(e[7]),t.chr2=e[10],t.start2=Number.parseInt(e[11]),t.end2=Number.parseInt(e[12]),t.name=e[0],t.score=Number(e[1]),t.value=Number(e[2]),t.color="."===e[4]?void 0:"0"===e[4]?"rgb(0,0,0)":e[4],t};{const r=t-3;return function(i,o){if(r>0&&(i.name=o[0]),r>1&&(i.score=Number(o[1])),r>2&&(i.strand=o[2]),r>3&&(i.cdStart=parseInt(o[3])),r>4&&(i.cdEnd=parseInt(o[4])),r>5&&"."!==o[5]&&"0"!==o[5]&&"-1"!==o[5]){const t=no.createColorString(o[5]);i.color=t.startsWith("rgb")?t:void 0}if(r>8){const t=parseInt(o[6]),e=o[7].split(","),n=o[8].split(","),r=[];for(let o=0;o<t;o++){const t=i.start+parseInt(n[o]),s=t+parseInt(e[o]);r.push({start:t,end:s})}!function(t,e,n){for(let r of t){const t=r.end,i=r.start;t<e||i>n?r.utr=!0:(e>=i&&e<=t&&(r.cdStart=e),n>=i&&n<=t&&(r.cdEnd=n))}}(r,i.cdStart,i.cdEnd),i.exons=r}if(n)for(let r=t;r<e;r++)if(r<n.fields.length){const t=n.fields[r].name,e=o[r-3];i[t]=e}}}}(this.header.definedFieldCount,this.header.fieldCount,this.autoSql,this.format);return function(e,n,r,i,o,s,a){const c=new Wa(e);for(;c.remLength()>=13;){const e=c.getInt(),l=a[e],h=c.getInt(),u=c.getInt(),f=c.getString();if(!(e<n||e===n&&u<r)){if(e>i||e===i&&h>=o)break;if(u>0){const e={chr:l,start:h,end:u};s.push(e);const n=f.split("\t");t(e,n)}}}}}function fu(t,e,n,r,i,o,s,a){const c=new Wa(t);for(;c.remLength()>=32;){const t=c.getInt(),l=s[t],h=c.getInt(),u=c.getInt(),f=c.getInt(),d=c.getFloat(),p=c.getFloat(),g=c.getFloat();let m;switch(c.getFloat(),a){case"min":m=d;break;case"max":m=p;break;default:m=0===f?0:g/f}if(!(t<e||t===e&&u<n)){if(t>r||t===r&&h>=i)break;Number.isFinite(m)&&o.push({chr:l,start:h,end:u,value:m})}}}class du{constructor(t){this.data=Yi(t).buffer}loadArrayBuffer(t,e){const n=e.range;return n?this.data.slice(n.start,n.start+n.size):this.data}async dataViewForRange(t,e){const n=Math.min(this.data.byteLength-t.start,t.size);return e?new Uint8Array(this.data,t.start,n):new DataView(this.data,t.start,n)}}class pu{constructor(t,e){this.reader=new nu(t,e),this.genome=e,this.format=t.format||"bigwig",this.wgValues={}}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,windowFunction:i}){const o="all"===t.toLowerCase()?await this.getWGValues(i):await this.reader.readFeatures(t,e,t,n,r,i);return"bigwig"===this.reader.type||Kh(o),o}async getHeader(){return this.reader.loadHeader()}getDefaultRange(){return void 0!==this.reader.totalSummary?this.reader.totalSummary.defaultRange:void 0}async defaultVisibilityWindow(){return this.reader.defaultVisibilityWindow}async getWGValues(t){const e=this.genome;if(this.wgValues[t])return this.wgValues[t];{const n=e.getGenomeLength()/1e3,r=await this.reader.readWGFeatures(n,t);let i=[];for(let t of r){const n=t.chr,r=e.getCumulativeOffset(n),o=Object.assign({},t);o.chr="all",o.start=r+t.start,o.end=r+t.end,i.push(o)}return this.wgValues[t]=i,i}}supportsWholeGenome(){return"bigwig"===this.reader.type}async trackType(){return this.reader.getTrackType()}}class gu{constructor(t,e){this.config=t,this.genome=e,this.path=t.url,this.groupCache={},this.datasetCache={}}async readHeader(){if(void 0!==this.magic)return this;let t=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:0,size:64e3}})),e=new Wa(new DataView(t));if(this.magic=e.getInt(),this.version=e.getInt(),this.indexPos=e.getLong(),this.indexSize=e.getInt(),e.getInt(),this.version>=2){let t=e.getInt();for(this.windowFunctions=[];t-- >0;)this.windowFunctions.push(e.getString())}this.trackType=e.getString(),this.trackLine=e.getString();let n=e.getInt();for(this.trackNames=[];n-- >0;)this.trackNames.push(e.getString());this.genomeID=e.getString(),this.flags=e.getInt(),this.compressed=0!=(1&this.flags),t=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:this.indexPos,size:this.indexSize}})),e=new Wa(new DataView(t)),this.datasetIndex={};let r=e.getInt();for(;r-- >0;){const t=e.getString(),n=e.getLong(),r=e.getInt();this.datasetIndex[t]={position:n,size:r}}for(this.groupIndex={},r=e.getInt();r-- >0;){const t=e.getString(),n=e.getLong(),r=e.getInt();this.groupIndex[t]={position:n,size:r}}return this}async readDataset(t,e,n){const r=t+"_"+e+"_"+n;if(this.datasetCache[r])return this.datasetCache[r];{await this.readHeader();const i=this.version<2?"":"/"+e,o="all"===t.toLowerCase()||void 0===n?"0":n.toString();let s;s="raw"===e?"/"+t+"/raw":"/"+t+"/z"+o+i;const a=this.datasetIndex[s];if(void 0===a)return;const c=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:a.position,size:a.size}}));if(!c)return;const l=new Wa(new DataView(c));let h=l.getInt();const u={};for(;h-- >0;)u[l.getString()]=l.getString();const f=l.getString(),d=l.getFloat();let p=l.getInt();const g=[];for(;p-- >0;)g.push({position:l.getLong(),size:l.getInt()});const m={name:s,attributes:u,dataType:f,tileWidth:d,tiles:g};return this.datasetCache[r]=m,m}}async readRootGroup(){const t=this.genome,e=this.groupCache["/"];if(e)return e;{const e=await this.readGroup("/"),n=e.chromosomes,r=e.maxZoom;r&&(this.maxZoom=Number(r));const i=e.totalCount;i&&(e.totalCount=Number(i));const o={};return n&&n.split(",").forEach((function(e){const n=t.getChromosomeName(e);o[n]=e})),this.chrAliasTable=o,this.groupCache["/"]=e,e}}async readGroup(t){const e=this.groupCache[t];if(e)return e;{await this.readHeader();const e=this.groupIndex[t];if(void 0===e)return;const n=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:e.position,size:e.size}}));if(!n)return;const r=new Wa(new DataView(n)),i={name:t};let o=r.getInt();for(;o-- >0;){const t=r.getString(),e=r.getString();i[t]=e}return this.groupCache[t]=i,i}}async readTiles(t,e){if(t.sort((function(t,e){return t.position-e.position})),0===(t=t.filter((function(t){return t.size>0}))).length)return Promise.resolve([]);const n=t[0],r=t[t.length-1],i=n.position,o=r.position+r.size-i,s=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:i,size:o}})),a=[];for(let n of t){const t=n.position-i,r=n.size;if(r>0){let n;if(this.compressed){n=qi(s.slice(t,t+r)).buffer}else n=s.slice(t,t+r);const i=new Wa(new DataView(n)),o=i.getString();let c;switch(o){case"fixedStep":c=mu(i,e);break;case"variableStep":c=vu(i,e);break;case"bed":case"bedWithName":c=bu(i,e,o);break;default:throw"Unknown tile type: "+o}a.push(c)}}return a}async readTile(t,e){let n=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:t.position,size:t.size}}));if(this.compressed){n=qi(n).buffer}const r=new Wa(new DataView(n)),i=r.getString();switch(i){case"fixedStep":return mu(r,e);case"variableStep":return vu(r,e);case"bed":case"bedWithName":return bu(r,e,i);default:throw"Unknown tile type: "+i}}}function mu(t,e){const n=t.getInt(),r=t.getInt(),i=t.getFloat(),o=[];let s=e;for(;s-- >0;){let e=n;const r=[];for(;e-- >0;)r.push(t.getFloat());o.push(r)}return{type:"fixedStep",start:r,span:i,data:o,nTracks:e,nPositions:n}}function vu(t,e){const n=t.getInt(),r=t.getFloat(),i=t.getInt(),o=[];let s=i;for(;s-- >0;)o.push(t.getInt());t.getInt();const a=[];let c=e;for(;c-- >0;){s=i;const e=[];for(;s-- >0;)e.push(t.getFloat());a.push(e)}return{type:"variableStep",tileStart:n,span:r,start:o,data:a,nTracks:e,nPositions:i}}function bu(t,e,n){const r=t.getInt();let i=r;const o=[];for(;i-- >0;)o.push(t.getInt());i=r;const s=[];for(;i-- >0;)s.push(t.getInt());t.getInt();const a=[];let c=e;for(;c-- >0;){let e=r;const n=[];for(;e-- >0;)n.push(t.getFloat());a.push(n)}if("bedWithName"===n){i=r;const e=[];for(;i-- >0;)e.push(t.getString())}return{type:n,start:o,end:s,data:a,nTracks:e,nPositions:r}}class wu{constructor(t,e){this.genome=e,this.windowFunction=t.windowFunction||"mean",this.reader=new gu(t,e)}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r}){if("all"===t.toLowerCase()){const t=[],e=this.genome;if(this.genome.wgChromosomeNames)for(let n of e.wgChromosomeNames){const i=e.getChromosome(n).bpLength;r=i/1e3;const o=await this._getFeatures(n,0,i,r);if(o)for(let n of o){const r=Object.assign({},n);r.chr="all",r.start=e.getGenomeCoordinate(n.chr,n.start),r.end=e.getGenomeCoordinate(n.chr,n.end),r._f=n,t.push(r)}}return t}return this._getFeatures(t,e,n,r)}async _getFeatures(t,e,n,r){const i=new Gs(t,e,n),o=this.genome;if(!this.rootGroup&&(this.rootGroup=await this.reader.readRootGroup(),!this.normalizationFactor)){const t=this.rootGroup.totalCount;t&&(this.normalizationFactor=1e6/t)}i.bpPerPixel=r;const s=function(t,e,n){var r=n.getChromosome(t).bpLength;return Math.ceil(Math.log(Math.max(0,r/(700*e)))/_u)}(t,r,o);let a=this.reader.chrAliasTable[t],c=this.reader.maxZoom;void 0===a&&(a=t),void 0===c&&(c=-1);const l=s>c?"raw":this.windowFunction,h=await this.reader.readDataset(a,l,s);if(null==h)return[];const u=h.tileWidth,f=Math.floor(e/u),d=Math.floor(n/u),p=await this.reader.readTiles(h.tiles.slice(f,d+1),1),g=[];for(let i of p)switch(i.type){case"bed":yu(i,t,e,n,r,g);break;case"variableStep":xu(i,t,e,n,r,g);break;case"fixedStep":ku(i,t,e,n,r,g);break;default:throw"Unknown tile type: "+i.type}return g.sort((function(t,e){return t.start-e.start})),g}get supportsWholeGenome(){return!0}}function yu(t,e,n,r,i,o){const s=t.nPositions,a=t.start,c=t.end,l=t.data[0];for(let t=0;t<s;t++){const i=a[t],s=c[t];if(!(s<n)){if(i>r)break;o.push({chr:e,start:i,end:s,value:l[t]})}}}function xu(t,e,n,r,i,o){const s=t.nPositions,a=t.start,c=t.span,l=t.data[0];for(let t=0;t<s;t++){const i=a[t],s=i+c;if(!(s<n)){if(i>r)break;o.push({chr:e,start:i,end:s,value:l[t]})}}}function ku(t,e,n,r,i,o){const s=t.nPositions;let a=t.start;const c=t.span,l=t.data[0];for(let t=0;t<s;t++){const i=a+c;if(a>r)break;i>=n&&(Number.isNaN(l[t])||o.push({chr:e,start:a,end:i,value:l[t]})),a=i}}var _u=Math.log(2);const Su=new Set(["bigwig","bw","bigbed","bb","biginteract","biggenepred","bignarrowpeak"]);function Cu(t,e){const n=t.format?t.format.toLowerCase():void 0;return Su.has(n)?new pu(t,e):"tdf"===n?new wu(t,e):new Jh(t,e)}const Eu={getTissueInfo:function(t,e){let n=(e=e||"https://gtexportal.org/rest/v1")+"/dataset/tissueInfo?datasetId="+(t=t||"gtex_v8");return go.loadJson(n,{})},trackConfiguration:function(t,e){return{type:"eqtl",sourceType:"gtex-ws",url:(e=e||"https://gtexportal.org/rest/v1")+"/association/singleTissueEqtlByLocation",tissueSiteDetailId:t.tissueSiteDetailId,name:t.tissueSiteDetailId.split("_").join(" "),visibilityWindow:25e4}}};function Au(t,e,n){let r=(t.start-e)/n,i=(t.end-e)/n,o=i-r;return o<3&&(o=3,r-=1.5),{px:r,px1:i,pw:o}}function Tu(t,e,n,r,i,o){try{i.save(),i.fillStyle=this.defaultColor,i.strokeStyle=this.defaultColor;const r=Mu.call(this,t);let s,a;i.fillStyle=r,i.strokeStyle=r,"SQUISHED"===this.displayMode&&void 0!==t.row?(s=this.featureHeight/2,a=this.margin+this.squishedRowHeight*t.row):"EXPANDED"===this.displayMode&&void 0!==t.row?(s=this.featureHeight,a=this.margin+this.expandedRowHeight*t.row):(s=this.featureHeight,a=this.margin);const c=o.pixelWidth,l=a+s/2,h=s/2,u=l-h/2,f=t.exons?t.exons.length:0,d=Au(t,e,n),p=this.arrowSpacing,g="+"===t.strand?1:"-"===t.strand?-1:0;if(0===f){const t=Math.max(0,d.px),e=Math.min(c,d.px1),n=e-t;if(i.fillRect(t,a,n,s),0!==g){i.fillStyle="white",i.strokeStyle="white";for(let n=t+p/2;n<e;n+=p)ls.strokeLine(i,n-2*g,l-2,n,l),ls.strokeLine(i,n-2*g,l+2,n,l);i.fillStyle=r,i.strokeStyle=r}}else{ls.strokeLine(i,d.px+1,l,d.px1-1,l);const o=Math.max(0,d.px)+p/2,m=Math.min(c,d.px1);for(let t=o;t<m;t+=p)ls.strokeLine(i,t-2*g,l-2,t,l),ls.strokeLine(i,t-2*g,l+2,t,l);for(let o=0;o<f;o++){const f=t.exons[o];let d,m=Math.round((f.start-e)/n),v=Math.round((f.end-e)/n),b=Math.max(1,v-m);if(!(m+b<0)){if(m>c)break;if(f.utr)i.fillRect(m,u,b,h);else if(f.cdStart&&(d=Math.round((f.cdStart-e)/n),i.fillRect(m,u,d-m,h),b-=d-m,m=d),f.cdEnd&&(d=Math.round((f.cdEnd-e)/n),i.fillRect(d,u,v-d,h),b-=v-d,v=d),b=Math.max(b,1),i.fillRect(m,a,b,s),b>p+5&&0!==g){i.fillStyle="white",i.strokeStyle="white";for(let t=m+p/2;t<v;t+=p)ls.strokeLine(i,t-2*g,l-2,t,l),ls.strokeLine(i,t-2*g,l+2,t,l);i.fillStyle=r,i.strokeStyle=r}}}}o.drawLabel&&"SQUISHED"!==this.displayMode&&Lu.call(this,i,t,d.px,d.px1,a,o.referenceFrame,o)}finally{i.restore()}}function Lu(t,e,n,r,i,o,s){try{t.save();let a=e.name;if(void 0===a&&e.gene&&(a=e.gene.name),void 0===a&&(a=e.id||e.ID),!a||"."===a)return;let c=s.pixelXOffset||0;const l=Math.max(n,-c),h=(l+Math.min(r,-c+s.viewportWidth))/2;let u;"COLLAPSED"===this.displayMode&&"SLANT"===this.labelDisplayMode&&(u={rotate:{angle:45}});const f=function(t,e){return e?t+20:t+25}(i,u);let d,p=Mu.call(this,e),g=!1;o.selection&&Eu.gtexLoaded&&(g=!0,d=o.selection.colorForGene(a));const m={textAlign:"SLANT"===this.labelDisplayMode?void 0:"center",fillStyle:d||p,strokeStyle:d||p},v=t.measureText(a),b=h-v.width/2,w=h+v.width/2;(s.labelAllFeatures||b>s.rowLastLabelX[e.row]||g)&&(s.rowLastLabelX[e.row]=w,ls.fillText(t,a,h,f,m,u))}finally{t.restore()}}function Mu(t){let e;if(this.altColor&&"-"===t.strand)e="function"==typeof this.altColor?this.altColor(t):this.altColor;else if(this.color)e="function"==typeof this.color?this.color(t):this.color;else if(this.colorBy){const n=t.getAttributeValue?t.getAttributeValue(this.colorBy):t[this.colorBy];e=this.colorTable.getColor(n)}else e=t.color?t.color:this.defaultColor;if(t.alpha&&1!==t.alpha)e=no.addAlpha(e,t.alpha);else if(this.useScore&&t.score&&!Number.isNaN(t.score)){const n=function(t,e,n){const r=(e-t)/9,i=Math.floor((n-t)/r);return Math.min(1,.2+.8*i/9)}(this.config.min?this.config.min:0,this.config.max?this.config.max:1e3,t.score);t.alpha=n,e=no.addAlpha(e,n)}return e}const Ru=new Set(["nonsense","missense","stop-loss","frameshift","cds-indel"]),Iu=new Set(["coding-synon"]),Nu=new Set(["splice-3","splice-5"]),Pu=new Set(["untranslated-5","untranslated-3"]);function Ou(t,e,n,r,i){var o,s,a,c,l=Au(t,e,n),h=this.margin,u=this.snpColors.length;switch(o="squished"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight,this.colorBy){case"function":c=t.func,s=c.split(",").map((function(t){return Ru.has(t)||Nu.has(t)?u-1:Iu.has(t)?u-2:Pu.has(t)?u-3:0})).reduce((function(t,e){return Math.max(t,e)}));break;case"class":s="deletion"===(a=t.class)?u-1:"mnp"===a?u-2:"microsatellite"===a||"named"===a?u-3:0}i.fillStyle=this.snpColors[s],i.fillRect(l.px,h,l.pw,o)}function Fu(t,e,n,r,i){const o="EXPANDED"===this.displayMode?this.expandedRowHeight:this.squishedRowHeight;let s=this.margin;"COLLAPSED"!==this.displayMode&&void 0!==t.row&&(s+=t.row*o);const a=s+.5*o,c=a-.5*o,l=a+.5*o,h=Math.round((t.junction_left-e)/n),u=Math.round((t.junction_right-e)/n);i.beginPath(),i.moveTo(h,a),i.bezierCurveTo(h,c,u,c,u,a),i.lineWidth=1+Math.log(t.num_junction_reads)/Math.log(2),i.strokeStyle="blue",i.stroke();const f=t.spanning_frag_coords;for(let t=0;t<f.length;t++){const r=f[t],o=Math.round((r.left-e)/n),s=Math.round((r.right-e)/n);i.beginPath(),i.moveTo(o,a),i.bezierCurveTo(o,l,s,l,s,a),i.lineWidth=1,i.strokeStyle="purple",i.stroke()}}class Du extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type=t.type||"annotation",this.maxRows=void 0===t.maxRows?1e3:t.maxRows,this.displayMode=t.displayMode||"EXPANDED",this.labelDisplayMode=t.labelDisplayMode,t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=t.featureSource?t.featureSource:Cu(t,this.browser.genome),this.autoHeight=t.autoHeight,this.margin=void 0===t.margin?10:t.margin,this.featureHeight=t.featureHeight||14,"FusionJuncSpan"===t.type?(this.render=t.render||Fu,this.squishedRowHeight=t.squishedRowHeight||50,this.expandedRowHeight=t.expandedRowHeight||50,this.height=t.height||this.margin+2*this.expandedRowHeight):"snp"===t.type?(this.render=t.render||Ou,this.snpColors=["rgb(0,0,0)","rgb(0,0,255)","rgb(0,255,0)","rgb(255,0,0)"],this.colorBy="function",this.expandedRowHeight=t.expandedRowHeight||10,this.squishedRowHeight=t.squishedRowHeight||5,this.height=t.height||30):(this.render=t.render||Tu,this.arrowSpacing=30,function(t){t.browser.on&&(t.browser.on("trackdragend",e),t.browser.on("trackremoved",n));function e(){t.trackView&&"SQUISHED"!==t.displayMode&&t.trackView.repaintViews()}function n(r){t.browser.un&&t===r&&(t.browser.un("trackdragend",e),t.browser.un("trackremoved",n))}}(this),this.squishedRowHeight=t.squishedRowHeight||15,this.expandedRowHeight=t.expandedRowHeight||30,this.height=t.height||this.margin+2*this.expandedRowHeight,t.colorBy&&(t.colorBy.field&&(t.colorTable=t.colorBy.pallete||t.colorBy.palette,t.colorBy=t.colorBy.field),this.colorBy=t.colorBy,t.colorTable?this.colorTable=new Sc(t.colorTable):this.colorTable=new _c("Set1"))),this.useScore=t.useScore}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow()),this}get supportsWholeGenome(){return void 0!==this.config.supportsWholeGenome?this.config.supportsWholeGenome:this.featureSource&&"function"==typeof this.featureSource.supportsWholeGenome?this.featureSource.supportsWholeGenome():!(void 0!==this.visibilityWindow||!1!==this.config.indexed&&this.config.indexURL)||void 0}async getFeatures(t,e,n,r){const i=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i})}computePixelHeight(t){if("COLLAPSED"===this.displayMode)return this.margin+this.expandedRowHeight;{let e=0;if(t&&"function"==typeof t.forEach)for(let n of t)n.row&&n.row>e&&(e=n.row);return this.margin+(e+1)*("SQUISHED"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight)}}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=t.pixelHeight,a=i+o*r+1;if(this.config.isMergedTrack||ls.fillRect(n,0,t.pixelTop,o,s,{fillStyle:"rgb(255, 255, 255)"}),e){const c=[];t.rowLastX=[],t.rowLastLabelX=[];for(let n of e)if(n.start>i&&n.end<a){const e="COLLAPSED"===this.displayMode?0:n.row||0;void 0===c[e]?c[e]=1:c[e]++,t.rowLastX[e]=-Number.MAX_SAFE_INTEGER,t.rowLastLabelX[e]=-Number.MAX_SAFE_INTEGER}const l=o/Math.max(...c);let h=[];for(let o of e){if(o.end<i)continue;if(o.start>a)break;const e="COLLAPSED"===this.displayMode?0:o.row;t.drawLabel=t.labelAllFeatures||l>10;const c=Math.ceil((o.end-i)/r),u=h[e];if(!u||c>u){this.render.call(this,o,i,r,s,n,t);const a=Math.floor((o.start-i)/r);u&&a-u<=0&&(n.globalAlpha=.5,ls.strokeLine(n,a,0,a,s,{strokeStyle:"rgb(255, 255, 255)"}),n.globalAlpha=1),h[e]=c}}}else console.log("No feature list")}clickedFeatures(t,e){const n=t.y-this.margin,r=super.clickedFeatures(t,e);let i;switch(this.displayMode){case"SQUISHED":i=Math.floor(n/this.squishedRowHeight);break;case"EXPANDED":i=Math.floor(n/this.expandedRowHeight);break;default:i=void 0}return r.filter((function(t){return void 0===i||void 0===t.row||i===t.row}))}popupData(t,e){e=this.clickedFeatures(t,e);const n=t.genomicLocation,r=[];for(let t of e){const e=t._f||t,i="function"==typeof e.popupData?e.popupData(n):this.extractPopupData(e);if(i){r.length>0&&r.push("<hr/><hr/>");const o=this.infoURL||this.config.infoURL;for(let e of i)if(r.push(e),o&&e.name&&"name"===e.name.toLowerCase()&&e.value&&ke(e.value)&&!e.value.startsWith("<")){const n=o.replace("$$",t.name);e.value=`<a target=_blank href=${n}>${e.value}</a>`}const s="gff"===this.config.format||"gff3"===this.config.format||"gtf"===this.config.format;if(e.exons)for(let t=0;t<e.exons.length;t++){const i=e.exons[t];if(n>=i.start&&n<=i.end){const n=s?i.number:"-"===e.strand?e.exons.length-t:t+1;n&&(r.push("<hr/>"),r.push({name:"Exon Number",value:n}));break}}}}return r}menuItemList(){const t=[];if(this.render===Ou){t.push("<hr/>");for(let e of["function","class"])t.push({object:de(Po("Color by "+e,e===this.colorBy)),click:()=>{this.colorBy=e,this.trackView.repaintViews()}})}t.push("<hr/>");for(let e of["COLLAPSED","SQUISHED","EXPANDED"]){const n={COLLAPSED:"Collapse",SQUISHED:"Squish",EXPANDED:"Expand"};t.push({object:de(Po(n[e],e===this.displayMode)),click:()=>{this.displayMode=e,this.config.displayMode=e,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})}return t}contextMenuItemList(t){const e=this.clickedFeatures(t);e.length>1&&e.sort(((t,e)=>e.end-e.start-(t.end-t.start)));const n=e[0];if(n.end-n.start<=1e6){const t=[{label:"View feature sequence",click:async()=>{let t=await this.browser.genome.getSequence(n.chr,n.start,n.end);"-"===n.strand&&(t=As(t)),t||(t="Unknown sequence"),Qo.presentAlert(t)}}];return Ss()&&void 0!==navigator.clipboard&&t.push({label:"Copy feature sequence",click:async()=>{let t=await this.browser.genome.getSequence(n.chr,n.start,n.end);"-"===n.strand&&(t=As(t));try{await navigator.clipboard.writeText(t)}catch(t){console.error(t),Qo.presentAlert(`error copying sequence to clipboard ${t}`)}}}),t.push("<hr/>"),t}}description(){if(Ou===this.render){let t="<html>"+this.name+"<hr/>";return t+="<em>Color By Function:</em><br>",t+='<span style="color:red">Red</span>: Coding-Non-Synonymous, Splice Site<br>',t+='<span style="color:green">Green</span>: Coding-Synonymous<br>',t+='<span style="color:blue">Blue</span>: Untranslated<br>',t+='<span style="color:black">Black</span>: Intron, Locus, Unknown<br><br>',t+="<em>Color By Class:</em><br>",t+='<span style="color:red">Red</span>: Deletion<br>',t+='<span style="color:green">Green</span>: MNP<br>',t+='<span style="color:blue">Blue</span>: Microsatellite, Named<br>',t+='<span style="color:black">Black</span>: Indel, Insertion, SNP',t+="</html>",t}return super.description()}dispose(){this.trackView=void 0}}class Bu extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type="wig",this.height=t.height||50,this.featureType="numeric",this.paintAxis=yc;const e=t.format?t.format.toLowerCase():t.format;this.flipAxis=!!t.flipAxis&&t.flipAxis,this.logScale=!!t.logScale&&t.logScale,this.featureSource="bigwig"===e?new pu(t,this.browser.genome):"tdf"===e?new wu(t,this.browser.genome):Cu(t,this.browser.genome),this.autoscale=t.autoscale||void 0===t.max,this.autoscale||(this.dataRange={min:t.min||0,max:t.max}),this.windowFunction=t.windowFunction||"mean",this.graphType=t.graphType||"bar",this.normalize=t.normalize,this.scaleFactor=t.scaleFactor}async postInit(){const t=await this.getHeader();t&&this.setTrackProperties(t)}async getFeatures(t,e,n,r){const i=await this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,windowFunction:this.windowFunction});if(this.normalize&&this.featureSource.normalizationFactor){const t=this.featureSource.normalizationFactor;for(let e of i)e.value*=t}if(this.scaleFactor){const t=this.scaleFactor;for(let e of i)e.value*=t}return i}menuItemList(){let t=[];return void 0!==this.flipAxis&&t.push({label:"Flip y-axis",click:()=>{this.flipAxis=!this.flipAxis,this.trackView.repaintViews()}}),t=t.concat(Oo.numericDataMenuItems(this.trackView)),t}async getHeader(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header}getScaleFactor(t,e,n,r){return r?n/(Math.log10(e+1)-(t<=0?0:Math.log10(t+1))):n/(e-t)}computeYPixelValue(t,e){return(this.flipAxis?t-this.dataRange.min:this.dataRange.max-t)*e}computeYPixelValueInLogScale(t,e){let n=this.dataRange.max,r=this.dataRange.min;return n<=0?0:(r<=-1&&(r=0),r=r<=0?0:Math.log10(r+1),n=Math.log10(n+1),t=Math.log10(t+1),(this.flipAxis?t-r:n-t)*e)}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth;t.pixelHeight;const s=i+o*r+1;let a=-1,c=-1;const l=this.color||"rgb(150,150,150)";let h;"string"==typeof l&&l.startsWith("rgb(")&&(h=no.addAlpha(l,.1));const u=this.getScaleFactor(this.dataRange.min,this.dataRange.max,t.pixelHeight,this.logScale),f=t=>this.logScale?this.computeYPixelValueInLogScale(t,u):this.computeYPixelValue(t,u);if(e&&e.length>0&&(void 0===this.dataRange.min&&(this.dataRange.min=0),this.dataRange.max>this.dataRange.min)){const o=f(0);for(let t of e){if(t.end<i)continue;if(t.start>s)break;const e=Math.floor((t.start-i)/r);if(isNaN(e))continue;let h=f(t.value);const u=Math.ceil((t.end-i)/r),d=Math.max(1,u-e);let p=t.value<0&&this.altColor?this.altColor:l;const g="function"==typeof p?p(t.value):p;if("points"===this.graphType){const t=this.config.pointSize||3,r=e+d/2;ls.fillCircle(n,r,h,t/2,{fillStyle:g,strokeStyle:g})}else{let r=h-o;const i=e+d;(i>a||t.value>=0&&t.value>c||t.value<0&&t.value<1)&&ls.fillRect(n,e,o,d,r,{fillStyle:g}),c=t.value,a=i}}if(this.dataRange.min<0){const e=this.dataRange.max/(this.dataRange.max-this.dataRange.min)*t.pixelHeight;ls.strokeLine(n,0,e,t.pixelWidth,e,{strokeStyle:h})}}if(this.config.hasOwnProperty("guideLines"))for(let e of this.config.guideLines)if(e.hasOwnProperty("color")&&e.hasOwnProperty("y")&&e.hasOwnProperty("dotted")){let n=f(e.y),r={strokeStyle:e.color,strokeWidth:2};e.dotted?ls.dashedLine(t.context,0,n,t.pixelWidth,n,5,r):ls.strokeLine(t.context,0,n,t.pixelWidth,n,r)}}popupData(t,e){if((e=this.clickedFeatures(t,e))&&e.length>0){const n=t.genomicLocation,r=[];e.sort((function(t,e){return Math.abs((t.start+t.end)/2-n)-Math.abs((e.start+e.end)/2-n)}));const i=e.length>10?e.slice(0,10):e;i.sort((function(t,e){return t.start-e.start}));for(let t of i)if(t){r.length>0&&r.push("<hr/>");let e=t.end-t.start==1?_e(t.start+1):_e(t.start+1)+"-"+_e(t.end);r.push({name:"Position:",value:e}),r.push({name:"Value:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",value:_e(t.value)})}return i.length<e.length&&r.push("<hr/>..."),r}return[]}get supportsWholeGenome(){return!this.config.indexURL&&!1!==this.config.supportsWholeGenome}dispose(){this.trackView=void 0}getState(){const t=super.getState();return void 0!==this.flipAxis&&(t.flipAxis=this.flipAxis),void 0!==this.logScale&&(t.logScale=this.logScale),t}}function zu(t){this.thresholds=t.thresholds,this.colors=t.colors}function Hu(t){this.scale=t,this.lowColor="rgb("+t.lowR+","+t.lowG+","+t.lowB+")",this.highColor="rgb("+t.highR+","+t.highG+","+t.highB+")",this.diff=t.high-t.low}zu.prototype.getColor=function(t){for(let e of this.thresholds)if(t<e)return this.colors[this.thresholds.indexOf(e)];return this.colors[this.colors.length-1]},Hu.prototype.getColor=function(t){var e,n=this.scale;return t<=n.low?this.lowColor:t>=n.high?this.highColor:(e=(t-n.low)/this.diff,"rgb("+Math.floor(n.lowR+e*(n.highR-n.lowR))+","+Math.floor(n.lowG+e*(n.highG-n.lowG))+","+Math.floor(n.lowB+e*(n.highB-n.lowB))+")")};class Vu{constructor(t){this.color=t}getColor(){return this.color}}class ju extends bc{constructor(t,e){super(t,e)}init(t){if(super.init(t),this.type=t.type||"seg","maf"===this.type&&(this.type="mut"),this.isLog=t.isLog,this.displayMode=t.displayMode||"EXPANDED",this.height=t.height||300,this.maxHeight=t.maxHeight||500,this.squishedRowHeight=t.sampleSquishHeight||t.squishedRowHeight||2,this.expandedRowHeight=t.sampleExpandHeight||t.expandedRowHeight||13,this.sampleHeight=this.squishedRowHeight,t.color?this.color=t.color:(this.posColorScale=t.posColorScale||new Hu({low:.1,lowR:255,lowG:255,lowB:255,high:1.5,highR:255,highG:0,highB:0}),this.negColorScale=t.negColorScale||new Hu({low:-1.5,lowR:0,lowG:0,lowB:255,high:-.1,highR:255,highG:255,highB:255}),"mut"===this.type&&(this.colorTable=new Sc(t.colorTable||Uu))),this.sampleKeys=[],this.sampleNames=new Map,t.samples){for(let e of t.samples)this.sampleKeys.push(e),this.sampleNames.set(e,e);this.explicitSamples=!0}const e=Object.assign({},this.config);e.maxWGCount=e.maxWGCount||Number.MAX_SAFE_INTEGER,this.featureSource=Cu(e,this.browser.genome),this.initialSort=t.sort}async postInit(){"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header)}menuItemList(){const t=[],e={SQUISHED:"Squish",EXPANDED:"Expand",FILL:"Fill"};t.push("<hr/>"),t.push("DisplayMode:");const n="seg"===this.type?["SQUISHED","EXPANDED","FILL"]:["SQUISHED","EXPANDED"];for(let r of n){const n=Po(e[r],r===this.displayMode);t.push({object:de(n),click:()=>{this.displayMode=r,this.config.displayMode=r,this.trackView.checkContentHeight(),this.trackView.repaintViews(),this.trackView.moveScroller(this.trackView.sampleNameViewport.trackScrollDelta)}})}return t}hasSamples(){return!0}getSamples(){return{names:this.sampleKeys.map((t=>this.sampleNames.get(t))),height:this.sampleHeight,yOffset:0}}async getFeatures(t,e,n){const r=await this.featureSource.getFeatures({chr:t,start:e,end:n});if(this.initialSort){const t=this.initialSort;this.sortSamples(t.chr,t.start,t.end,t.direction,r),this.initialSort=void 0}return r}draw({context:t,renderSVG:e,pixelTop:n,pixelWidth:r,pixelHeight:i,features:o,bpPerPixel:s,bpStart:a}){if(ls.fillRect(t,0,0,r,i,{fillStyle:"rgb(255, 255, 255)"}),o&&o.length>0){this.checkForLog(o),this.updateSampleKeys(o);const e={};let c;switch(this.sampleKeys.forEach((function(t,n){e[t]=n})),this.displayMode){case"FILL":this.sampleHeight=i/this.sampleKeys.length,c=0;break;case"SQUISHED":this.sampleHeight=this.squishedRowHeight,c=0;break;default:this.sampleHeight=this.expandedRowHeight,c=1}const l=this.sampleHeight;for(let t of o)t.pixelRect=void 0;const h=n+i,u=a+r*s+1,f=s;this.sampleYStart=void 0;for(let r of o){if(r.end<a)continue;if(r.start>u)break;const i=r.sampleKey||r.sample;r.row=e[i];const o=r.row*l+c;void 0===this.sampleYStart&&(this.sampleYStart=o);if(o+l<n||o>h)continue;const s=Math.max(r.start,a);let d=Math.round((s-a)/f);const p=Math.min(r.end,u),g=Math.round((p-a)/f);let m,v,b=Math.max(1,g-d);if(this.color?m="function"==typeof this.color?this.color(r):this.color:this.colorTable&&(m=this.colorTable.getColor(r.value.toLowerCase())),"mut"===this.type)v=l-2*c,b<3&&(b=3,d-=1);else{let t=r.value;this.isLog||(t=Ji(t/2)),m=t<-.1?this.negColorScale.getColor(t):t>.1?this.posColorScale.getColor(t):"white";let e=l;if(l<.25){const n=.1+2*Math.abs(t);e=Math.min(1,n*l)}v=e-2*c}r.pixelRect={x:d,y:o,w:b,h:v},t.fillStyle=m,t.fillRect(d,o,b,v)}}}checkForLog(t){if(void 0===this.isLog){this.isLog=!1;for(let e of t)if(e.value<0)return void(this.isLog=!0)}}computePixelHeight(t){if(!t)return 0;const e="SQUISHED"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight;return this.updateSampleKeys(t),this.sampleKeys.length*e}async sortSamples(t,e,n,r,i){if(i||(i=await this.featureSource.getFeatures({chr:t,start:e,end:n})),!i)return;this.updateSampleKeys(i);const o={},s="ASC"===r?1:-1,a=()=>{const t=n-e+1;for(let r of i){if(r.end<e)continue;if(r.start>n)break;const i=Math.max(e,r.start),s=(Math.min(n,r.end)-i)/t,a=r.sampleKey||r.sample,c=o[a]||0;o[a]=c+s*r.value}this.sampleKeys.sort((function(t,e){let n=o[t],r=o[e];return n||(n=s*Number.MAX_VALUE),r||(r=s*Number.MAX_VALUE),n===r?0:n>r?s:-1*s}))},c=()=>{for(let t of i){if(t.end<e)continue;if(t.start>n)break;const r=t.sampleKey||t.sample;(!o.hasOwnProperty(r)||t.value.localeCompare(o[r])>0)&&(o[r]=t.value)}this.sampleKeys.sort((function(t,e){let n=o[t]||"",r=o[e]||"";return s*n.localeCompare(r)}))};"mut"===this.type?c():a(),this.trackView.repaintViews()}clickedFeatures(t,e){const n=super.clickedFeatures(t,e),r=t.y;return n.filter((function(t){const e=t.pixelRect;return e&&r>=e.y&&r<=e.y+e.h}))}popupData(t,e){e=this.clickedFeatures(t);const n=[];for(let t of e){n.length>0&&(n.push("<hr/>"),n.push("<hr/>"));const e=t._f||t,r="function"==typeof e.popupData?e.popupData(this.type,this.browser.genome.id):this.extractPopupData(e);Array.prototype.push.apply(n,r)}return n}contextMenuItemList(t){const e=t.viewport.referenceFrame,n=t.genomicLocation,r=this.config.sort?"ASC"===this.config.sort.direction?"DESC":"ASC":"DESC",i=e.toBP(2.5),o=e=>{const n=t.viewport.cachedFeatures;this.sortSamples(e.chr,e.start,e.end,e.direction,n)};return[{label:"seg"===this.type?"Sort by value":"Sort by type",click:e=>{const s={direction:r,chr:t.viewport.referenceFrame.chr,start:n-i,end:n+i};o(s),this.config.sort=s}}]}get supportsWholeGenome(){return(!1===this.config.indexed||!this.config.indexURL)&&!1!==this.config.supportsWholeGenome}updateSampleKeys(t){if(!this.explicitSamples)for(let e of t){const t=e.sampleKey||e.sample;this.sampleNames.has(t)||(this.sampleNames.set(t,e.sample),this.sampleKeys.push(t))}}}const Uu={indel:"rgb(0,200,0)","targeted region":"rgb(236,155,43)",truncating:"rgb(\t150,0,0)","non-coding transcript":"rgb(0,0,150)",synonymous:"rgb(109,165,95)",silent:"rgb(109,135,80)",missense_mutation:"rgb(72,130,187)",missense:"rgb(72,130,187)","splice site":"rgb(143,83,155)",splice_region:"rgb(143,83,155)",nonsense:"rgb(216, 57,81)",nonsense_mutation:"rgb(216, 57,81)",frame_shift_del:"rgb(226,135,65)",frame_shift_ins:"rgb(226,135,65)",in_frame_del:"rgb(247,235,94)",in_frame_ins:"rgb(247,235,94)","*other*":"rgb(159,91,50)"};class qu extends bc{constructor(t,e){super(t,e),this.type="merged",this.featureType="numeric",this.paintAxis=yc}init(t){if(!t.tracks)throw Error("Error: no tracks defined for merged track"+t);super.init(t)}async postInit(){this.tracks=[];const t=[];for(let e of this.config.tracks){e.isMergedTrack=!0;const n=await this.browser.createTrack(e);n?(n.autoscale=!1,this.tracks.push(n)):console.warn("Could not create track "+e),"function"==typeof n.postInit&&t.push(n.postInit())}this.flipAxis=!!this.config.flipAxis&&this.config.flipAxis,this.logScale=!!this.config.logScale&&this.config.logScale,this.autoscale=this.config.autoscale||void 0===this.config.max,this.autoscale||(this.dataRange={min:this.config.min||0,max:this.config.max});for(let t of this.tracks)t.autoscale=!1,t.dataRange=this.dataRange;return this.height=this.config.height||50,Promise.all(t)}get height(){return this._height}set height(t){if(this._height=t,this.tracks)for(let e of this.tracks)e.height=t,e.config.height=t}menuItemList(){let t=[];return void 0!==this.flipAxis&&t.push({label:"Flip y-axis",click:()=>{this.flipAxis=!this.flipAxis,this.trackView.repaintViews()}}),t=t.concat(Oo.numericDataMenuItems(this.trackView)),t}async getFeatures(t,e,n,r){const i=this.tracks.map((i=>i.getFeatures(t,e,n,r)));return Promise.all(i)}draw(t){const e=t.features;this.autoscale&&(this.dataRange=function(t,e){let n=0,r=-Number.MAX_VALUE;for(let t of e)for(let e of t)void 0===e.value||Number.isNaN(e.value)||(n=Math.min(n,e.value),r=Math.max(r,e.value));return{min:n,max:r}}(t.referenceFrame.chr,e));for(let n=0,r=this.tracks.length;n<r;n++){const r=Object.assign({},t);r.features=e[n],this.tracks[n].dataRange=this.dataRange,this.tracks[n].flipAxis=this.flipAxis,this.tracks[n].logScale=this.logScale,this.tracks[n].graphType=this.graphType,this.tracks[n].draw(r)}}popupData(t,e){const n=e||t.viewport.cachedFeatures;if(n&&n.length===this.tracks.length){const e=[];for(let r=0;r<this.tracks.length;r++){r>0&&e.push("<hr/>"),e.push(`<div style=background-color:rgb(245,245,245);border-bottom-style:dashed;border-bottom-width:1px;padding-bottom:5px;padding-top:10px;font-weight:bold;font-size:larger >${this.tracks[r].name}</div>`);const i=this.tracks[r].popupData(t,n[r]);e.push(...i)}return e}}get supportsWholeGenome(){return this.tracks.every((t=>t.supportsWholeGenome()))}}class Wu extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.theta=t.theta||Math.PI/4,this.sinTheta=Math.sin(this.theta),this.cosTheta=Math.cos(this.theta),this.height=t.height||250,this.arcType=function(t){if(!t.arcType)return"nested";switch(t.arcType){case"chiapet":return"inView";case"chiapetoutbound":return"partialInView";default:return t.arcType}}(t),this.arcOrientation=void 0===t.arcOrientation||t.arcOrientation,this.showBlocks=void 0===t.showBlocks||t.showBlocks,this.blockHeight=t.blockHeight||3,this.thickness=t.thickness||1,this.color=t.color||"rgb(180,25,137)",this.alpha=t.alpha||.02,this.painter={flipAxis:!this.arcOrientation,dataRange:this.dataRange,paintAxis:yc},t.valueColumn?(this.valueColumn=t.valueColumn,this.hasValue=!0):t.useScore&&(this.hasValue=!0,this.valueColumn="score"),this.logScale=!1!==t.logScale,t.max?(this.dataRange={min:t.min||0,max:t.max},this.autoscale=!1):this.autoscale=!0,this.featureSource=Cu(t,this.browser.genome),this.featureSource.getWGFeatures=Yu}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow(),this.featureSource.visibilityWindow=this.visibilityWindow),this}get supportsWholeGenome(){return!0}async getFeatures(t,e,n){const r=this.visibilityWindow,i=await this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r});return void 0===this.hasValue&&i&&i.length>0&&(this.hasValue=void 0!==i[0].score),i}draw(t){"proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType?this.drawProportional(t):this.drawNested(t)}drawNested(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight,i=t.viewportWidth,o=t.bpPerPixel,s=t.bpStart,a=o;ls.fillRect(e,0,t.pixelTop,n,r,{fillStyle:"rgb(255, 255, 255)"});const c=t.features;if(c){(function(){let t=0;for(let e of c){let r=(e.start-s)/a,i=(e.end-s)/a;i>=0&&r<=n&&(t=Math.max(t,i-r))}let e=Math.min(i,t)/2;if(t>0){let t=(r-10)/e;this.theta=function(t){let e,n=[.01570925532366355,.15838444032453644,.3249196962329063,.5095254494944288,.7265425280053609,.9999999999999999],r=[.031415926535897934,.3141592653589793,.6283185307179586,.9424777960769379,1.2566370614359172,1.5707963267948966];for(e=0;e<n.length&&!(n[e]>t);e++);let i=0===e?0:n[e-1],o=e<n.length?n[e]:1,s=(t-i)/(o-i),a=0===e?0:r[e-1],c=e<r.length?r[e]:Math.PI/2;return a+s*(c-a)}(t),this.sinTheta=Math.sin(this.theta),this.cosTheta=Math.cos(this.theta)}}).call(this);const o=this.arcOrientation?t.pixelHeight:0,h=this.arcOrientation;e.font="8px sans-serif",e.textAlign="center";for(let t of c){t.drawState=void 0;let r=t.color||this.color;if(r&&this.config.useScore&&(r=Xu(r,(l=t.score,Math.min(1,.11+l/779*.89).toString()))),e.lineWidth=t.thickness||this.thickness||1,t.chr1===t.chr2||"all"===t.chr){const{m1:c,m2:l}=$u(t,this.browser.genome);let u=Math.round((c-s)/a),f=Math.round((l-s)/a);if(f<0||u>n)continue;let d=f-u;d<3&&(d=3,u--);const p=d/2,g=p/this.sinTheta,m=this.cosTheta*g,v=u+p;let b,w,y;if(h?(b=this.height+m,w=Math.PI+Math.PI/2-this.theta,y=Math.PI+Math.PI/2+this.theta):(b=-m,w=Math.PI/2-this.theta,y=Math.PI/2+this.theta),this.showBlocks&&"all"!==t.chr){const n=(t.start1-s)/a,r=(t.end1-s)/a,i=(t.start2-s)/a,c=(t.end2-s)/a,l=this.arcOrientation?-this.blockHeight:this.blockHeight;e.fillRect(n,o,r-n,l),e.fillRect(i,o,c-i,l)}r&&!this.config.useScore&&d>i&&(r=Xu(r,this.alpha)),e.strokeStyle=r,e.fillStyle=r,e.beginPath(),e.arc(v,b,g,w,y,!1),e.stroke(),t.drawState={xc:v,yc:b,r:g}}else{let i=Math.round((t.start-s)/a),o=Math.round((t.end-s)/a);if(o<0||i>n)continue;let c=o-i;c<3&&(c=3,i--);const l=t.chr===t.chr1?t.chr2:t.chr1;e.strokeStyle=r,e.fillStyle=Xu(ll(l),.5),h?(e.fillRect(i,this.height/2,c,this.height/2),e.fillText(l,i+c/2,this.height/2-5),t.drawState={x:i,y:this.height/2,w:c,h:this.height/2}):(e.fillRect(i,0,c,this.height/2),e.fillText(l,i+c/2,this.height/2+13),t.drawState={x:i,y:0,w:c,h:this.height/2})}}}var l}getScaleFactor(t,e,n,r){return r?n/(Math.log10(e+1)-(t<=0?0:Math.log10(t+1))):n/(e-t)}drawProportional(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight,i=t.bpPerPixel,o=t.bpStart,s=i,a=t.referenceFrame.start,c=t.referenceFrame.end;ls.fillRect(e,0,t.pixelTop,n,r,{fillStyle:"rgb(255, 255, 255)"});const l=t.features;if(l&&l.length>0){const r=0,i=this.getScaleFactor(r,this.dataRange.max,t.pixelHeight-1,this.logScale),h=this.arcOrientation?t.pixelHeight:0;for(let t of l){t.drawState=void 0;const r=this.valueColumn?t[this.valueColumn]:t.score;if(void 0===r||Number.isNaN(r))continue;const l=Math.round((this.logScale?Math.log10(r+1):r)*i);if(t.chr1===t.chr2||"all"===t.chr){const{m1:n,m2:i}=$u(t,this.browser.genome);let u=Math.round((n-o)/s),f=Math.round((i-o)/s)-u;if(f<3&&(f=3,u--),r<this.dataRange.min||r>this.dataRange.max)continue;if("proportional"!==this.arcType){const t="partialInView"===this.arcType,e=n>=a&&i<=c;let r=!1,o=!1;if(!e&&t&&(r=a<=n&&n<=c,r||(o=a<=i&&i<=c)),!(e||r||o))continue}const d=f/2,p=u+f/2;t.drawState={xc:p,yc:h,radiusX:d,radiusY:l};const g=!!this.arcOrientation,m=t.color||this.color;if(e.strokeStyle=m,e.lineWidth=t.thickness||this.thickness||1,!0===e.isSVG?e.strokeEllipse(p,h,d,l,0,0,Math.PI,g):(e.beginPath(),e.ellipse(p,h,d,l,0,0,Math.PI,g),e.stroke()),this.alpha&&(e.fillStyle=Xu(m,this.alpha),!0===e.isSVG?e.fillEllipse(p,h,d,l,0,0,Math.PI,g):e.fill()),this.showBlocks&&"all"!==t.chr){e.fillStyle=m;const n=(t.start1-o)/s,r=(t.end1-o)/s,i=(t.start2-o)/s,a=(t.end2-o)/s,c=this.arcOrientation?-this.blockHeight:this.blockHeight;e.fillRect(n,h,r-n,c),e.fillRect(i,h,a-i,c)}}else{let i=Math.round((t.start-o)/s),a=Math.round((t.end-o)/s);if(a<0||i>n||r<this.dataRange.min||r>this.dataRange.max)continue;const c=Math.min(l,this.height-13);let h=a-i;h<3&&(h=3,i--);const u=t.chr===t.chr1?t.chr2:t.chr1;if(e.font="8px sans-serif",e.textAlign="center",e.fillStyle=Xu(ll(u),.5),this.arcOrientation){const n=this.height-c;e.fillRect(i,n,h,c),e.fillText(u,i+h/2,n-5),t.drawState={x:i,y:n,w:h,h:c}}else e.fillRect(i,0,h,c),e.fillText(u,i+h/2,c+13),t.drawState={x:i,y:0,w:h,h:c}}}}}clearAxis(t,e,n){ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"})}paintAxis(t,e,n){const r={min:0,max:this.dataRange.max};"proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType?(this.painter.flipAxis=!this.arcOrientation,this.painter.dataRange=r,this.painter.paintAxis(t,e,n)):this.clearAxis(t,e,n)}menuItemList(){let t=[{name:"Set track color",click:()=>{this.trackView.presentColorPicker()}},"<hr/>"];if(this.hasValue){const e={nested:"Nested",proportional:"Proportional - All",inView:"Proportional - Both Ends in View",partialInView:"Proportional - One End in View"};t.push("<b>Arc Type</b>");for(let n of["nested","proportional","inView","partialInView"])t.push({object:de(Po(e[n],n===this.arcType)),click:()=>{this.arcType=n,this.trackView.repaintViews()}})}return t.push("<hr/>"),t.push({name:"Toggle arc direction",click:()=>{this.arcOrientation=!this.arcOrientation,this.trackView.repaintViews()}}),t.push({name:this.showBlocks?"Hide Blocks":"Show Blocks",click:()=>{this.showBlocks=!this.showBlocks,this.trackView.repaintViews()}}),"proportional"!==this.arcType&&"inView"!==this.arcType&&"partialInView"!==this.arcType||(t=t.concat(Oo.numericDataMenuItems(this.trackView))),this.browser.circularView&&(t.push("<hr/>"),t.push({label:"Add interactions to circular view",click:()=>{for(let t of this.trackView.viewports)this.addChordsForViewport(t.referenceFrame)}})),t}contextMenuItemList(t){if(this.browser.circularView){const e=t.viewport,n=[];return n.push({label:"Add interactions to circular view",click:()=>{const t=e.referenceFrame;this.addChordsForViewport(t)}}),n.push("<hr/>"),n}}addChordsForViewport(t){const e=("all"===t.chr?this.featureSource.getAllFeatures():this.featureSource.featureCache.queryFeatures(t.chr,t.start,t.end)).filter((t=>t.drawState));if(0===e.length)return;tl(e.map((t=>{const e=t._f||t;return{uniqueId:`${e.chr1}:${e.start1}-${e.end1}_${e.chr2}:${e.start2}-${e.end2}`,refName:Qc(e.chr1),start:e.start1,end:e.end1,mate:{refName:Qc(e.chr2),start:e.start2,end:e.end2}}})),this,t,.5)}doAutoscale(t){let e=0;if(t)for(let n of t){const t=this.valueColumn?n[this.valueColumn]:n.score;Number.isNaN(t)||(e=Math.max(e,t))}return{min:0,max:e}}popupData(t,e){e=this.clickedFeatures(t);const n=[];for(let t of e){const e=t._||t;if(n.push({name:"Region 1",value:Gu(e.chr1,e.start1,e.end1,e.strand1)}),n.push({name:"Region 2",value:Gu(e.chr2,e.start2,e.end2,e.strand2)}),e.name&&n.push({name:"Name",value:e.name}),void 0!==e.value&&n.push({name:"Value",value:e.value}),void 0!==e.score&&n.push({name:"Score",value:e.score}),e.extras&&this.header&&this.header.columnNames){const t=this.header.columnNames;for(let r=10;r<t.length;r++)"info"===t[r]?Ku(n,e.extras[r-10]):n.push({name:t[r],value:e.extras[r-10]})}break}return n}clickedFeatures(t,e){const n=e||t.viewport.cachedFeatures,r=[];if(n){const e="proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType;for(let i of n)if(i.drawState)if(i.chr1===i.chr2||"all"===i.chr)if(e){const{xc:e,yc:n,radiusX:o,radiusY:s}=i.drawState,a=t.canvasX-e,c=t.canvasY-n,l=a/o*(a/o)+c/s*(c/s);l<=1&&r.push({score:1/l,feature:i})}else{const{xc:e,yc:n,r:o}=i.drawState,s=t.canvasX-e,a=t.canvasY-n,c=Math.abs(Math.sqrt(s*s+a*a)-o);c<5&&r.push({score:c,feature:i})}else{const{x:e,y:n,w:o,h:s}=i.drawState,a=5;if(t.canvasX>=e-a&&t.canvasX<=e+o+a&&t.canvasY>=n&&t.canvasY<=n+s){const n=-Math.abs(t.canvasX-(e+o/2));r.push({score:n,feature:i});break}}}return r.length>1&&r.sort(((t,e)=>t.score-e.score)),r.map((t=>t.feature))}getState(){const t=super.getState();return void 0!==this.arcType&&(t.arcType=this.arcType),void 0!==this.arcOrientation&&(t.arcOrientation=this.arcOrientation),void 0!==this.showBlocks&&(t.showBlocks=this.showBlocks),void 0!==this.blockHeight&&(t.blockHeight=this.blockHeight),void 0!==this.thickness&&(t.thickness=this.thickness),void 0!==this.alpha&&(t.alpha=this.alpha),t}}function $u(t,e){let n=(t.start1+t.end1)/2,r=(t.start2+t.end2)/2;if("all"===t.chr&&(n=e.getGenomeCoordinate(t.chr1,n),r=e.getGenomeCoordinate(t.chr2,r)),n>r){const t=n;n=r,r=t}return{m1:n,m2:r}}function Gu(t,e,n,r){return r&&"."!==r?`${t}:${_e(e+1)}-${_e(n)} (${r})`:`${t}:${_e(e+1)}-${_e(n)}`}const Zu=new Map;function Xu(t,e){const n=`${t}_${e}`;let r=Zu.get(n);return r||(r=no.addAlpha(t,e),Zu.set(n,r)),r}function Yu(t){const e=t=>{const e=Object.assign({},t);return e.chr="all",e.start=n.getGenomeCoordinate(t.chr1,t.start1),e.end=n.getGenomeCoordinate(t.chr2,t.end2),e},n=this.genome;let r,i=0;for(let e of n.wgChromosomeNames){let n=t[e];if(n)for(let t of n)t.dup||(i++,t.score&&(!r||t.score>r.score)&&(r=t))}const o=this.maxWGCount,s=r&&r.score>0&&i>o?5:1,a=Math.floor(o/s),c=r&&r.score>0?Math.log(r.score)/s:Number.MAX_SAFE_INTEGER;let l,h=[],u=[];for(let t=0;t<s;t++)u.push([0]),h.push([]);for(let r of n.wgChromosomeNames){let n=t[r];if(n)for(let t of n)if(!t.dup){const n=t.score?Math.min(s-1,Math.floor(Math.log(t.score)/c)):0;if(h[n].length<a)h[n].push(e(t));else{const r=a/(u[n]+1);if(Math.random()<r){const r=Math.floor(Math.random()*(a-1));h[n][r]=e(t)}}u[n]++}}if(1===s)l=h[0];else{l=[];for(let t of h)for(let e of t)l.push(e);r&&l.push(e(r)),l.sort((function(t,e){return t.start-e.start})),console.log(l.length)}return l}function Ku(t,e){const n=e.split(";");for(let e of n){const n=e.split("=");2===n.length&&t.push({name:n[0],value:n[1]})}}const Qu=ke,Ju=new Map([["REF","referenceBases"],["ALT","alternateBases"],["QUAL","quality"],["FILTER","filter"]]);class tf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.visibilityWindow=t.visibilityWindow,this.displayMode=t.displayMode||"EXPANDED",this.labelDisplayMode=t.labelDisplayMode,this.expandedVariantHeight=t.expandedVariantHeight||t.variantHeight||10,this.squishedVariantHeight=t.squishedVariantHeight||2,this.squishedCallHeight=t.squishedCallHeight||1,this.expandedCallHeight=t.expandedCallHeight||10,this.expandedVGap=void 0!==t.expandedVGap?t.expandedVGap:2,this.squishedVGap=void 0!==t.squishedVGap?t.squishedVGap:1,this.expandedGroupGap=t.expandedGroupGap||10,this.squishedGroupGap=t.squishedGroupGap||5,this.featureHeight=t.featureHeight||14,this.visibilityWindow=t.visibilityWindow,this.featureSource=Cu(t,this.browser.genome),this.noGenotypeColor=t.noGenotypeColor||"rgb(200,180,180)",this.noCallColor=t.noCallColor||"rgb(225, 225, 225)",this.nonRefColor=t.nonRefColor||"rgb(200, 200, 215)",this.mixedColor=t.mixedColor||"rgb(200, 220, 200)",this.homrefColor=t.homrefColor||"rgb(200, 200, 200)",this.homvarColor=t.homvarColor||"rgb(17,248,254)",this.hetvarColor=t.hetvarColor||"rgb(34,12,253)",this.sortDirection="ASC",this.type=t.type||"variant",this.colorBy=t.colorBy,this._initColorBy=t.colorBy,t.colorTable&&(this.colorTables=new Map,this.colorTables.set(t.colorBy,new Sc(t.colorTable))),this.showGenotypes=void 0===t.showGenotypes||t.showGenotypes,this.variantRowCount(1)}async postInit(){if(this.header=await this.getHeader(),void 0===this.visibilityWindow&&!1!==this.config.indexed){const t=je(this.config.url)?this.config.url.name:this.config.url;Qu(t)&&t.toLowerCase().includes("gnomad")?this.visibilityWindow=1e3:"function"==typeof this.featureSource.defaultVisibilityWindow?this.visibilityWindow=await this.featureSource.defaultVisibilityWindow():this.visibilityWindow=1e6}return this}get supportsWholeGenome(){return!1===this.config.indexed||!0===this.config.supportsWholeGenome}get color(){return this._color}set color(t){this._color=t,this.colorBy=void 0}async getHeader(){if(!this.header){if("function"==typeof this.featureSource.getHeader){const t=await this.featureSource.getHeader();t&&(this.callSets=t.callSets||[]),this.header=t}this.sampleNames=this.callSets?this.callSets.map((t=>t.name)):[]}return this.header}getCallsetsLength(){return this.callSets?this.callSets.length:0}async getFeatures(t,e,n,r){return void 0===this.header&&(this.header=await this.getHeader()),this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:this.visibilityWindow})}hasSamples(){return this.getCallsetsLength()>0}getSamples(){return{yOffset:this.sampleYOffset,names:this.sampleNames,height:this.sampleHeight}}computePixelHeight(t){if(!t||0==t.length)return 10;const e="COLLAPSED"===this.displayMode?1:this.nVariantRows,n="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,r="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,i="SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight;return 10+e*(r+n)+n+((!1===this.showGenotypes?0:this.getCallsetsLength()*e)+1)*(i+n)}variantRowCount(t){this.nVariantRows=t}draw({context:t,pixelWidth:e,pixelHeight:n,bpPerPixel:r,bpStart:i,pixelTop:o,features:s}){ls.fillRect(t,0,o,e,n,{fillStyle:"rgb(255, 255, 255)"});const a="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,c="COLLAPSED"===this.displayMode?1:this.nVariantRows,l="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight;this.variantBandHeight=10+c*(l+a);const h=this.callSets,u=this.getCallsetsLength();if(h&&u>0&&!1!==this.showGenotypes&&ls.strokeLine(t,0,this.variantBandHeight,e,this.variantBandHeight,{strokeStyle:"rgb(224,224,224) "}),s){const n="SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight,o="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,a=i+e*r+1;for(let e of s){if(e.end<i)continue;if(e.start>a)break;const s="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,c=10+("COLLAPSED"===this.displayMode?0:e.row*(s+o)),l=s;let f=Math.round((e.start-i)/r),d=Math.round((e.end-i)/r),p=Math.max(1,d-f);if(p<3?(p=3,f-=1):p>5&&(f+=1,p-=2),t.fillStyle=this.getVariantColor(e),t.fillRect(f,c,p,l),e.pixelRect={x:f,y:c,w:p,h:l},u>0&&!1!==this.showGenotypes){const r="COLLAPSED"===this.displayMode?1:this.nVariantRows;this.sampleYOffset=this.variantBandHeight+o,this.sampleHeight=r*(n+o);let i=0;for(let r of h){const s=e.calls[r.id];if(s){const a="COLLAPSED"===this.displayMode?0:e.row,c=this.sampleYOffset+i*this.sampleHeight+a*(n+o);let l=!0,h=!0,u=!1;if(s.genotype)for(let t of s.genotype){if("."===t){u=!0;break}0!==t&&(h=!1),0===t&&(l=!1)}s.genotype?t.fillStyle=u?this.noCallColor:h?this.homrefColor:l?this.homvarColor:this.hetvarColor:t.fillStyle=this.noGenotypeColor,t.fillRect(f,c,p,n),r.pixelRect={x:f,y:c,w:p,h:n}}i++}}}}else console.log("No feature list")}getVariantColor(t){const e=t._f||t;let n;if(this.colorBy){const t=this.colorBy;let r;if(e.info.hasOwnProperty(t))r=e.info[t];else if(Ju.has(t)){r=e[Ju.get(t)]}n=this.getVariantColorTable(t).getColor(r),n||(n="gray")}else n=this._color?"function"==typeof this._color?this._color(t):this._color:"NONVARIANT"===e.type?this.nonRefColor:"MIXED"===e.type?this.mixedColor:this.defaultColor;return n}clickedFeatures(t,e){let n=super.clickedFeatures(t,e);const r="EXPANDED"===this.displayMode?this.expandedVGap:this.squishedVGap,i=r+("SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight),o=t.y;if(o<=this.variantBandHeight){const t="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,e=Math.floor((o-10)/(t+r));"COLLAPSED"!==this.displayMode&&(n=n.filter((t=>t.row===e)))}else if(this.callSets){const t=this.callSets,e=o-this.variantBandHeight,r=Math.floor(e/this.sampleHeight);if(r>=0&&r<t.length){const o=Math.floor((e-r*this.sampleHeight)/i),s="COLLAPSED"===this.displayMode?n:n.filter((t=>t.row===o)),a=t[r];n=s.map((t=>{const e=t.calls[a.id];return function(t,e){if(t.genotype){let n="";if("."===e.alternateBases)n="No Call";else{const r=e.alternateBases.split(",");for(let i of t.genotype)if(n.length>0&&(n+="|"),"."===i)n+=".";else if(0===i)n+=e.referenceBases;else{n+=r[i-1].replace("<","&lt;")}}t.genotypeName=n}}(e,t),e}))}}return n}popupData(t,e){const n=this.clickedFeatures(t,e),r=t.genomicLocation,i=this.browser.genome.id,o=this.browser.sampleInformation;let s=[];for(let t of n){const e=t._f||t;if(s.length>0&&s.push({html:'<hr style="border-top-width:2px ;border-color: #c9c3ba" />'}),"function"==typeof e.popupData){const t=e.popupData(r,i);Array.prototype.push.apply(s,t)}else{const t=e;if(void 0!==t.callSetName&&s.push({name:"Name",value:t.callSetName}),t.genotypeName&&s.push({name:"Genotype",value:t.genotypeName}),void 0!==t.phaseset&&s.push({name:"Phase set",value:t.phaseset}),void 0!==t.genotypeLikelihood&&s.push({name:"genotypeLikelihood",value:t.genotypeLikelihood.toString()}),o){var a=o.getAttributes(t.callSetName);a&&Object.keys(a).forEach((function(t){var e=t.replace(/([A-Z])/g," $1");e=e.charAt(0).toUpperCase()+e.slice(1),s.push({name:e,value:a[t]})}))}var c=Object.keys(t.info);c.length&&s.push("<hr/>"),c.forEach((function(e){s.push({name:e,value:decodeURIComponent(t.info[e])})}))}}return s}menuItemList(){const t=[];if(this.header.INFO&&this.header.INFO){const e=this.header.INFO.SVTYPE?["SVTYPE"]:[];if(this._initColorBy&&"SVTYPE"!==this._initColorBy&&e.push(this._initColorBy),e.length>0){t.push("<hr/>");const n=de('<div class="igv-track-menu-category igv-track-menu-border-top">');n.text("Color by:"),t.push({name:void 0,object:n,click:void 0,init:void 0}),e.sort();for(let n of e){const e=this.colorBy===n,r=n||"None";t.push(this.colorByCB({key:n,label:r},e))}t.push(this.colorByCB({key:void 0,label:"None"},void 0===this.colorBy)),t.push("<hr/>")}}this.getCallsetsLength()>0&&(t.push({object:de('<div class="igv-track-menu-border-top">')}),t.push({object:de(Po("Show Genotypes",this.showGenotypes)),click:()=>{this.showGenotypes=!this.showGenotypes,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})),t.push({object:de('<div class="igv-track-menu-border-top">')});for(let e of["COLLAPSED","SQUISHED","EXPANDED"]){t.push({object:de(Po({COLLAPSED:"Collapse",SQUISHED:"Squish",EXPANDED:"Expand"}[e],e===this.displayMode)),click:()=>{this.displayMode=e,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})}return this.browser.circularView&&(t.push("<hr>"),t.push({label:"Add SVs to circular view",click:()=>{for(let t of this.trackView.viewports)this.sendChordsForViewport(t)}})),t}contextMenuItemList(t){if(this.browser.circularView){const e=t.viewport,n=[];return n.push({label:"Add SVs to Circular View",click:()=>{this.sendChordsForViewport(e)}}),n.push("<hr/>"),n}}sendChordsForViewport(t){const e=t.referenceFrame,n="all"===e.chr?this.featureSource.getAllFeatures():this.featureSource.featureCache.queryFeatures(e.chr,e.start,e.end);tl(n.filter((t=>{const e=t._f||t;return e.info&&e.info.CHR2&&e.info.END&&(e.info.CHR2!==e.chr||Math.abs(Number.parseInt(e.info.END)-e.pos)>1e6)})).map((t=>{const e=t._f||t,n=Number.parseInt(e.info.END),r=n-100,i=n+100;return{uniqueId:`${e.chr}:${e.start}-${e.end}_${e.info.CHR2}:${e.info.END}`,refName:Qc(e.chr),start:e.start,end:e.end,mate:{refName:Qc(e.info.CHR2),start:r,end:i}}})),this,e,.5)}colorByCB(t,e){return{name:void 0,object:de(Po(t.label,e)),click:()=>{t.key===this.colorBy?(this.colorBy=void 0,delete this.config.colorBy,this.trackView.repaintViews()):(this.colorBy=t.key,this.config.colorBy=t.key,this.trackView.repaintViews())},init:void 0}}getState(){const t=super.getState();return this._color&&"function"!=typeof this._color&&(t.color=this._color),t}getVariantColorTable(t){if(this.colorTables||(this.colorTables=new Map),!this.colorTables.has(t)){let e;if("SVTYPE"===t)e=ef;else e=new _c("Set1");this.colorTables.set(t,e)}return this.colorTables.get(t)}}const ef=new Sc({DEL:"#ff2101",INS:"#001888",DUP:"#028401",INV:"#008688",CNV:"#8931ff",BND:"#891100","*":"#002eff"});class nf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.name=t.name,this.pValueField=t.pValueField||"pValue",this.geneField=t.geneField||"geneSymbol",this.snpField=t.snpField||"snp";const e=t.minLogP||t.min,n=t.maxLogP||t.max;this.dataRange={min:e||3.5,max:n||25},this.autoscale=!n||t.autoscale,this.autoscalePercentile=void 0===t.autoscalePercentile?98:t.autoscalePercentile,this.background=t.background,this.divider=t.divider||"rgb(225,225,225)",this.dotSize=t.dotSize||2,this.height=t.height||100,this.autoHeight=!1,this.disableButtons=t.disableButtons,this.visibilityWindow=void 0===t.visibilityWindow?2e6:t.visibilityWindow>=0?Math.min(2e6,t.visibilityWindow):2e6,this.featureSource=Cu(t,this.browser.genome),Eu.gtexLoaded=!0}paintAxis(t,e,n){const r=(this.dataRange.max-this.dataRange.min)/n,i={font:"normal 10px Arial",textAlign:"right",strokeStyle:"black"};ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"});const o=Math.ceil(10*(this.dataRange.max-this.dataRange.min)/n);for(let s=4;s<=this.dataRange.max;s+=o){const o=.85*e,a=o-5,c=o,l=n-(s-this.dataRange.min)/r;ls.strokeLine(t,a,l,c,l,i),l>8&&ls.fillText(t,s,a-1,l+2,i)}i.textAlign="center",ls.fillText(t,"-log10(pvalue)",e/4,n/2,i,{rotate:{angle:-90}})}async getFeatures(t,e,n){const r=this.pValueField,i=this.visibilityWindow,o=await this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:i});return o.forEach((function(t){t.value=t[r]})),o}draw(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight;this.background&&ls.fillRect(e,0,0,n,r,{fillStyle:this.background}),ls.strokeLine(e,0,r-1,n,r-1,{strokeStyle:this.divider});const i=i=>{const o=i?2*this.dotSize:this.dotSize,s=t.bpStart,a=(this.dataRange.max-this.dataRange.min)/r,c=t.referenceFrame.selection;for(let h of t.features){const u=(h.start-s+.5)/t.bpPerPixel;if(u<0)continue;if(u>n)break;const f=h.snp.toUpperCase(),d=h[this.geneField].toUpperCase(),p=c&&(c.snp===f||c.gene===d);if(!i||p){c&&c.snp===f&&c.addGene(d);var l=-Math.log(h[this.pValueField])/Math.LN10;if(l>=this.dataRange.min){let t;l>this.dataRange.max?(l=this.dataRange.max,t=!0):t=!1;const n=Math.max(0+o,r-Math.round((l-this.dataRange.min)/a));let s;h.px=u,h.py=n,h.radius=o,i&&c?(s=c.colorForGene(d),ls.setProperties(e,{fillStyle:s,strokeStyle:"black"})):(s=t?"rgb(150, 150, 150)":"rgb(180, 180, 180)",ls.setProperties(e,{fillStyle:s,strokeStyle:s})),ls.fillCircle(e,u,n,o),ls.strokeCircle(e,u,n,o)}}}};i(!1),i(!0)}popupData(t){let e=t.viewport.cachedFeatures;if(!e||0===e.length)return[];const n=this.name,r=[];for(let i of e)Math.abs(i.px-t.canvasX)<i.radius+3&&Math.abs(i.py-t.canvasY)<i.radius+3&&(r.length>0&&r.push("<hr/>"),r.push({name:"snp id",value:i.snp},{name:"gene id",value:i.geneId},{name:"gene name",value:i.geneName},{name:"p value",value:i.pValue},{name:"tissue",value:n}));return r}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}doAutoscale(t){if(t.length>0){var e=t.map((function(t){return-Math.log(t.value)/Math.LN10}));this.dataRange.max=Ki(e,this.autoscalePercentile)}else{const t=this.config.maxLogP||this.config.max;this.dataRange.max=t||25}return this.dataRange}}const rf={X:"rgb(204, 153, 0)",Y:"rgb(153, 204, 0)",Un:"darkGray)",1:"rgb(80, 80, 255)",I:"rgb(139, 155, 187)",2:"rgb(206, 61, 50)",II:"rgb(206, 61, 50)","2a":"rgb(210, 65, 55)","2b":"rgb(215, 70, 60)",3:"rgb(116, 155, 88)",III:"rgb(116, 155, 88)",4:"rgb(240, 230, 133)",IV:"rgb(240, 230, 133)",5:"rgb(70, 105, 131)",6:"rgb(186, 99, 56)",7:"rgb(93, 177, 221)",8:"rgb(128, 34, 104)",9:"rgb(107, 215, 107)",10:"rgb(213, 149, 167)",11:"rgb(146, 72, 34)",12:"rgb(131, 123, 141)",13:"rgb(199, 81, 39)",14:"rgb(213, 143, 92)",15:"rgb(122, 101, 165)",16:"rgb(228, 175, 105)",17:"rgb(59, 27, 83)",18:"rgb(205, 222, 183)",19:"rgb(97, 42, 121)",20:"rgb(174, 31, 99)",21:"rgb(231, 199, 111)",22:"rgb(90, 101, 94)",23:"rgb(204, 153, 0)",24:"rgb(153, 204, 0)",25:"rgb(51, 204, 0)",26:"rgb(0, 204, 51)",27:"rgb(0, 204, 153)",28:"rgb(0, 153, 204)",29:"rgb(10, 71, 255)",30:"rgb(71, 117, 255)",31:"rgb(255, 194, 10)",32:"rgb(255, 209, 71)",33:"rgb(153, 0, 51)",34:"rgb(153, 26, 0)",35:"rgb(153, 102, 0)",36:"rgb(128, 153, 0)",37:"rgb(51, 153, 0)",38:"rgb(0, 153, 26)",39:"rgb(0, 153, 102)",40:"rgb(0, 128, 153)",41:"rgb(0, 51, 153)",42:"rgb(26, 0, 153)",43:"rgb(102, 0, 153)",44:"rgb(153, 0, 128)",45:"rgb(214, 0, 71)",46:"rgb(255, 20, 99)",47:"rgb(0, 214, 143)",48:"rgb(20, 255, 177)"};for(let pd of Object.keys(rf)){rf["chr"+pd]=rf[pd]}class of extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.useChrColors=void 0===t.useChrColors||t.useChrColors,this.trait=t.trait,this.posteriorProbability=t.posteriorProbability,this.valueProperty="bed"===t.format?"score":"value",this.height=t.height||100,this.autoscale=t.autoscale,this.autoscalePercentile=void 0===t.autoscalePercentile?98:t.autoscalePercentile,this.background=t.background,this.divider=t.divider||"rgb(225,225,225)",this.dotSize=t.dotSize||3,this.popoverWindow=void 0===t.popoverWindow?1e8:t.popoverWindow,this.colorScales=t.color?new Vu(t.color):{"*":new zu(t.colorScale||{thresholds:[5e-8,5e-4,.5],colors:["rgb(255,50,50)","rgb(251,100,100)","rgb(251,170,170)","rgb(227,238,249)"]})},this.featureSource=Cu(t,this.browser.genome)}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),this.autoscale||(this.posteriorProbability?this.dataRange={min:void 0===this.config.min?0:this.config.min,max:void 0===this.config.max?1:this.config.max}:this.dataRange={min:void 0===this.config.min?0:this.config.min,max:void 0===this.config.max?25:this.config.max}),this}get supportsWholeGenome(){return!0}async getFeatures(t,e,n){const r=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r})}draw(t){const e=t.features,n=t.context,r=t.pixelWidth,i=t.pixelHeight;if(this.background&&ls.fillRect(n,0,0,r,i,{fillStyle:this.background}),ls.strokeLine(n,0,i-1,r,i-1,{strokeStyle:this.divider}),e){const o=t.bpPerPixel,s=t.bpStart,a=s+r*o+1;for(let t of e){const e=t.start;if(e<s)continue;if(e>a)break;const r=this.getColorScale(t._f?t._f.chr:t.chr);let c,l;if(this.posteriorProbability)l=t[this.valueProperty],c=r.getColor(l);else{const e=t[this.valueProperty];if(!e)continue;l=-Math.log10(e),c=r.getColor(l)}const h=(this.dataRange.max-this.dataRange.min)/i,u=Math.round((e-s)/o),f=Math.max(this.dotSize,i-Math.round((l-this.dataRange.min)/h));c&&ls.setProperties(n,{fillStyle:c,strokeStyle:"black"}),ls.fillCircle(n,u,f,this.dotSize),t.px=u,t.py=f}}}getColorScale(t){if(this.useChrColors){let e=this.colorScales[t];if(!e){const n=rf[t]||Ec.get();e=new Vu(n),this.colorScales[t]=e}return e}return this.colorScales("*")}paintAxis(t,e,n){ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"});var r={font:"normal 10px Arial",textAlign:"right",strokeStyle:"black"};const i=(this.dataRange.max-this.dataRange.min)/n;if(this.posteriorProbability){const e=.1;for(let o=this.dataRange.min;o<this.dataRange.max;o+=e){const e=n-Math.round((o-this.dataRange.min)/i);ls.strokeLine(t,45,e-2,50,e-2,r),ls.fillText(t,o.toFixed(1),44,e+2,r)}}else{const e=Math.ceil(10*(this.dataRange.max-this.dataRange.min)/n);for(let o=this.dataRange.min;o<this.dataRange.max;o+=e){const e=n-Math.round((o-this.dataRange.min)/i);ls.strokeLine(t,45,e,50,e,r),ls.fillText(t,Math.floor(o),44,e+4,r)}}r.textAlign="center",this.posteriorProbability?ls.fillText(t,"PPA",e/2,n/2,r,{rotate:{angle:-90}}):ls.fillText(t,"-log10(pvalue)",e/2,n/2,r,{rotate:{angle:-90}})}popupData(t){let e=[];const n=t.viewport.trackView.track,r=t.viewport.cachedFeatures;if(r){let i=0;for(let o of r){const r=Math.abs(t.canvasX-o.px),s=Math.abs(t.canvasY-o.py),a=o[this.valueProperty];if(r<this.dotSize&&s<this.dotSize){if(i>0&&e.push("<HR/>"),5==i){e.push("...");break}if("function"==typeof o.popupData)e=e.concat(o.popupData());else{const t=o.realChr||o.chr,r=(o.realStart||o.start)+1;e.push({name:"chromosome",value:t}),e.push({name:"position",value:r}),e.push({name:"name",value:o.name}),n.posteriorProbability?e.push({name:"posterior probability",value:a}):e.push({name:"pValue",value:a})}i++}}}return e}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}doAutoscale(t){if(t.length>0){const e=this.valueProperty,n=this.posteriorProbability,r=t.map((function(t){const r=t[e];return{value:n?r:-Math.log(r)/Math.LN10}}));this.dataRange=ms(r)}else this.posteriorProbability?(this.dataRange.min=this.config.min||0,this.dataRange.max=this.config.max||1):(this.dataRange.max=this.config.max||25,this.dataRange.min=this.config.min||0);return this.dataRange}}class sf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.autoscale=t.autoscale||void 0===t.max,this.dataRange={min:t.min||0,max:t.max},this.windowFunction=t.windowFunction||"mean",this.paintAxis=yc,this.graphType=t.graphType||"bar",t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=Cu(this.config,this.browser.genome),this.visibilityWindow=-1,this.featureSource.visibilityWindow=this.visibilityWindow}async postInit(){if("function"==typeof this.featureSource.getHeader){if(this.header=await this.featureSource.getHeader(),this.sampleNames=this.header.columnNames.slice(3),this.setTrackProperties(this.header),this.header.hasOwnProperty("clickToHighlight")){let t=this.header.clickToHighlight;this.config.clickToHighlight=t,this.config.samplesClickedToHighlight={}}if(this.header.hasOwnProperty("highlight")){this.config.highlightSamples={};let t=this.header.highlight;Array.isArray(t)||(t=[t]);for(let e of t){const t=e.split(";");2===t.length&&(this.config.highlightSamples[t[0]]=t[1])}}}}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}async getFeatures(t,e,n){const r=await this.featureSource.getFeatures({chr:t,start:0,end:Number.MAX_SAFE_INTEGER,visibilityWindow:this.visibilityWindow});let i,o;for(let t=1;t<r.length-1;t++)if(void 0===i&&r[t].end>e&&(i=t-1),void 0===o&&r[t].start>n){o=t+1;break}return void 0===i&&(i=0),void 0===o&&(o=r.length),r.slice(i,o)}draw(t){const{features:e,context:n,bpPerPixel:r,bpStart:i,pixelWidth:o,pixelHeight:s}=t,a=t=>(this.dataRange.max-t)/(this.dataRange.max-this.dataRange.min)*s,c=function(t){let e=Math.floor((t-i)/r);return isNaN(e)&&console.warn("isNaN(x). feature start "+_e(t)+" bp start "+_e(i)),e};if(e&&e.length>0&&(void 0===this.dataRange.min&&(this.dataRange.min=0),this.dataRange.max>this.dataRange.min)){const t=this.config.highlightSamples,r=this.config.onlyHandleClicksForHighlightedSamples,i=this.config.clickToHighlight;let o=-1,s={},l=[],h=[];this.clickDetectorCache={};for(let u of e){const e=c(u.start),f=c(u.end),d=o>=0?c(o):e;if(!isNaN(e)&&!isNaN(f)){this.clickDetectorCache[e]=[],this.clickDetectorCache[f]=[];for(let o=0;o<u.values.length;o++){const c=this.sampleNames[o],p=u.values[o],g=a(p);if(e-d>=1){const o=s[c],h=a(o),u=t&&t[c];u?l.push([d,h,e,g,u]):i&&c in this.config.samplesClickedToHighlight?l.push([d,h,e,g,this.config.samplesClickedToHighlight[c]]):ls.strokeLine(n,d,h,e,g,{strokeStyle:"#D9D9D9"}),r&&!(c in t)||this.clickDetectorCache[e].push([d,h,e,g,c,u||"gray"])}if(f-e>=1){const o=t&&t[c];o?h.push([e,g,f,g,o]):i&&c in this.config.samplesClickedToHighlight?h.push([e,g,f,g,this.config.samplesClickedToHighlight[c]]):ls.strokeLine(n,e,g,f,g,{strokeStyle:"gray"}),r&&!(c in t)||this.clickDetectorCache[f].push([e,g,f,g,c,o||"gray"])}s[c]=p}o=u.end}}for(let t of l)ls.strokeLine(n,t[0],t[1],t[2],t[3],{strokeStyle:t[4],lineWidth:1.3});for(let t of h)ls.strokeLine(n,t[0],t[1],t[2],t[3],{strokeStyle:t[4],lineWidth:2})}(t=>{if(this.config.hasOwnProperty("guideLines"))for(let e of this.config.guideLines)if(e.hasOwnProperty("color")&&e.hasOwnProperty("y")&&e.hasOwnProperty("dotted")){let n=a(e.y),r={strokeStyle:e.color,strokeWidth:2};e.dotted?ls.dashedLine(t.context,0,n,t.pixelWidth,n,5,r):ls.strokeLine(t.context,0,n,t.pixelWidth,n,r)}})(t)}doAutoscale(t){let e,n;return t.length>0?(e=Number.MAX_VALUE,n=-Number.MAX_VALUE,t.forEach((function(t){e=Math.min(e,...t.values),n=Math.max(n,...t.values)})),e-=.01,n+=.01):(e=0,n=100),{min:e,max:n}}clickedFeatures(t){const e=t.canvasX,n=t.canvasY;let r=null;for(r of Object.keys(this.clickDetectorCache))if(r=parseInt(r),r>=e)break;if(r){let t=Number.MAX_VALUE,s=[];const a=this.clickDetectorCache[r];for(let r of a){const i=r[0],o=r[2];if(e<i||e>o)return[];const a=r[1],c=r[3];if(n<Math.min(a,c)-10||n>Math.max(a,c)+10)continue;const l=af(e,n,i,a,o,c);l<t&&(s=[{name:r[4],color:r[5]}],t=l)}if(t<5){if(this.config.clickToHighlight){if(s[0].name in this.config.samplesClickedToHighlight)delete this.config.samplesClickedToHighlight[s[0].name];else if("any"===this.config.clickToHighlight){var i=["red","darkblue","green","teal","olivedrab","orange","maroon","purple","blue","gold"],o=i[Math.floor(Math.random()*(i.length+1))];this.config.samplesClickedToHighlight[s[0].name]=o}else this.config.samplesClickedToHighlight[s[0].name]=this.config.clickToHighlight;this.trackView.repaintViews()}return s}}return[]}popupData(t,e){e=this.clickedFeatures(t,e);const n=[];return e.forEach((function(t){for(let e of Object.keys(t))ps(t[e])&&n.push({name:e,value:t[e]})})),n}get supportsWholeGenome(){return!1}}function af(t,e,n,r,i,o){const s=i-n,a=o-r,c=Math.abs(s*(r-e)-(n-t)*a),l=Math.sqrt(s*s+a*a);return l>0?c/l:0}class cf extends bc{constructor(t,e){super(t,e),t.height||(this.height=300),this.arcOrientation=!1,this.theta=Math.PI/2,"bp"===t.format?this.featureSource=new hf(t,e.genome):this.featureSource=new Jh(t,e.genome)}async getFeatures(t,e,n){const r=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r})}draw(t){const e=t.context,n=Math.PI/2,r=t.pixelWidth,i=t.pixelHeight;t.viewportWidth;const o=t.bpPerPixel,s=t.bpStart,a=o,c=this.arcOrientation;ls.fillRect(e,0,t.pixelTop,r,i,{fillStyle:"rgb(255, 255, 255)"});const l=t.features;if(l){lf(l,1);for(let t of l)if(t.startLeft){let r=Math.round((t.startLeft-s)/a),i=Math.round((t.startRight-s)/a),o=Math.round((t.endLeft-s)/a),l=Math.round((t.endRight-s)/a);e.fillStyle=t.color,e.strokeStyle=t.color,e.beginPath();let h=(r+l)/2,u=(l-r)/2,f=this.height,d=Math.PI+(Math.PI/2-n),p=2*Math.PI-(Math.PI/2-n);c?(f=0,e.arc(h,f,u,p,d),e.lineTo(l,f)):(e.arc(h,f,u,d,p),e.lineTo(o,f));const g=(i+o)/2,m=(o-i)/2,v=f;c?(e.arc(g,v,m,d,p,!0),e.lineTo(o,v)):(e.arc(g,v,m,p,d,!0),e.lineTo(r,v)),e.stroke(),e.fill(),t.drawState={x1:h,y1:f,r1:u,x2:g,y2:v,r2:m,sa:d,ea:p}}else{let r=Math.round((t.start-s)/a),i=Math.round((t.end-s)/a);e.strokeStyle=t.color,e.beginPath();let o=(r+i)/2,l=(i-r)/2,h=this.height,u=Math.PI+(Math.PI/2-n),f=2*Math.PI-(Math.PI/2-n);c?(h=0,e.arc(o,h,l,f,u)):e.arc(o,h,l,u,f),e.stroke(),t.drawState={x1:o,y1:h,r1:l,sa:u,ea:f}}}}clickedFeatures(t,e){const n=[];lf(e=super.clickedFeatures(t,e),-1);for(let r of e){const e=r.drawState,i=t.canvasX-e.x1,o=t.canvasY-e.y1,s=Math.sqrt(i*i+o*o),a=e.r1+3;let c,l;if(void 0===e.x2)c=s,l=e.r1-3;else{const n=t.canvasX-e.x2,r=t.canvasY-e.y2;c=Math.sqrt(n*n+r*r),l=e.r2-3}if(s<a&&c>l){n.push(r);break}}return n}popupData(t,e){if((e=this.clickedFeatures(t,e))&&e.length>0)return bc.extractPopupData(e[0],this.getGenomeId())}menuItemList(){var t=this;return[{name:"Toggle arc direction",click:function(){t.arcOrientation=!t.arcOrientation,t.trackView.repaintViews()}}]}}function lf(t,e){t.sort((function(t,n){const r=void 0===t.score?-Number.MAX_VALUE:t.score,i=void 0===n.score?-Number.MAX_VALUE:n.score;return(void 0===e?1:e)*(r-i)}))}class hf{constructor(t,e){this.config=t,this.genome=e}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i}){const o=this.genome;if(this.featureCache)return this.featureCache.queryFeatures(t,e,n);{const r=gs(this.config),i=await go.loadString(this.config.url,r);return this.featureCache=new Mo(function(t){if(!t)return null;const e=Fh(t);let n,r=!0;const i=[],o=[],s=[];for(;void 0!==(n=e.nextLine());){const t=n.split("\t");if(r&&n.startsWith("color:")){const e="rgb("+t[1]+","+t[2]+","+t[3]+")";i.push(e),t.length>4&&o.push(t[4])}else{r=!1;const e=t[0],n=Number.parseInt(t[1])-1,c=Number.parseInt(t[2])-1,l=Number.parseInt(t[3]),h=Number.parseInt(t[4]);var a=Number.parseInt(t[5]);const u=i[a];let f;f=n<=h?{chr:e,startLeft:Math.min(n,c),startRight:Math.max(n,c),endLeft:Math.min(l,h),endRight:Math.max(l,h),color:u,score:a}:{chr:e,startLeft:Math.min(l,h),startRight:Math.max(l,h),endLeft:Math.min(n,c),endRight:Math.max(n,c),color:u,score:a},f.start=f.startLeft,f.end=f.endRight,o.length>a&&(f.description=o[a]),s.push(f)}}return s}(i),o),this.featureCache.queryFeatures(t,e,n)}}}class uf{constructor(t){this.browser=t,this.type="ideogram",this.height=16,this.order=Number.MIN_SAFE_INTEGER,this.disableButtons=!0,this.ignoreTrackMenu=!0}async getFeatures(t,e,n){return[]}computePixelHeight(t){return this.height}draw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r}){const i=e.chr,o=e.genome.getChromosome(i);if(void 0===o||n<=0||r<=0||"all"===i.toLowerCase())return;!function({ctx:t,chr:e,referenceFrame:n,genome:r,width:i,height:o,stainColors:s}){const a=1,c=.5*a,l=0;if(void 0===r)return;ls.fillRect(t,0,0,i,o,{fillStyle:no.greyScale(255)});const h=r.getCytobands(e);if(h){const e=l+o/2,n=[],r=[];if(0===h.length)return;const u=i/h[h.length-1].end;t.beginPath(),ls.roundRect(t,c,c+l,i-2*c,o-2*c,(o-2*c)/2,0,1),t.clip();for(let i=0;i<h.length;i++){const c=h[i],f=u*c.start,d=u*c.end;"c"===c.type?("p"===c.name.charAt(0)?(n[0]=f,r[0]=o+l,n[1]=f,r[1]=l,n[2]=d,r[2]=e):(n[0]=d,r[0]=o+l,n[1]=d,r[1]=l,n[2]=f,r[2]=e),t.fillStyle="rgb(150, 0, 0)",t.strokeStyle="rgb(150, 0, 0)",ls.polygon(t,n,r,1,0)):(t.fillStyle=ff(s,c),ls.fillRect(t,f,a+l,d-f,o-2*a))}}t.strokeStyle=no.greyScale(41),ls.roundRect(t,c,c+l,i-2*c,o-2*c,(o-2*c)/2,0,1)}({ctx:t,chr:i,referenceFrame:e,genome:e.genome,width:n,height:r,stainColors:[]});const s=Math.round(e.bpPerPixel*n),a=e.start;let c=o.bpLength;const l=e.genome.getCytobands(i);if(l&&l.length>0&&l[l.length-1].end&&(c=Math.max(c,l[l.length-1].end),o.bpLength=c),s<c){const e=s/c,i=a/c;let o=Math.floor(i*n),l=Math.floor(e*n);o=Math.max(0,o),o=Math.min(n-l,o),t.save(),t.strokeStyle="red",t.lineWidth=l<2?1:2;const h=o+t.lineWidth/2;l=l<2?1:l-t.lineWidth;const u=t.lineWidth/2,f=r-t.lineWidth;t.strokeRect(h,u,l,f),t.restore()}}dispose(){this.trackView=void 0}}function ff(t,e){if("c"===e.type)return"rgb(150, 10, 10)";var n=e.stain,r=230;"p"===e.type&&(r=Math.floor(230-n/100*230));var i=t[r];return i||(i="rgb("+r+","+r+","+r+")",t[r]=i),i}let df=new _c("Dark2");["GT/AG","CT/AC","GC/AG","CT/GC","AT/AC","GT/AT","non-canonical"].forEach((t=>{df.getColor(t)}));const pf={};class gf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type=t.type||"junctions",t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=t.featureSource?t.featureSource:Cu(t,this.browser.genome),this.margin=void 0===t.margin?10:t.margin,this.height||(this.height=100),void 0===t.colorByNumReadsThreshold&&(t.colorByNumReadsThreshold=5)}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow()),this}get supportsWholeGenome(){return!1}async getFeatures(t,e,n,r){const i=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i})}computePixelHeight(t){return this.height}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=t.pixelHeight,a=i+o*r+1;if(this.config.isMergedTrack||ls.fillRect(n,0,t.pixelTop,o,s,{fillStyle:"rgb(255, 255, 255)"}),e){pf.referenceFrame=t.viewport.referenceFrame,pf.referenceFrameStart=pf.referenceFrame.start,pf.referenceFrameEnd=pf.referenceFrameStart+pf.referenceFrame.toBP(de(t.viewport.contentDiv).width()),pf.featureZoomOutTracker={};for(let t of e)if(!(t.end<i)){if(t.start>a)break;this.renderJunction(t,i,r,s,n)}}else console.log("No feature list")}renderJunction(t,e,n,r,i){t.isVisible=!1;const o=Math.round((t.start-e)/n),s=Math.round((t.end-e)/n),a=(o+s)/2;if(s-o<=3){if(a in pf.featureZoomOutTracker)return;pf.featureZoomOutTracker[a]=!0}if(this.config.hideAnnotatedJunctions&&"true"===t.attributes.annotated_junction)return;if(this.config.hideUnannotatedJunctions&&"false"===t.attributes.annotated_junction)return;if(this.config.hideMotifs&&this.config.hideMotifs.includes(t.attributes.motif))return;if(this.config.hideStrand===t.strand)return;if(this.config.minJunctionEndsVisible){let e=0;if(t.start>=pf.referenceFrameStart&&t.start<=pf.referenceFrameEnd&&(e+=1),t.end>=pf.referenceFrameStart&&t.end<=pf.referenceFrameEnd&&(e+=1),e<this.config.minJunctionEndsVisible)return}let c,l,h,u;if(t.attributes.uniquely_mapped){if(c=parseInt(t.attributes.uniquely_mapped),c<this.config.minUniquelyMappedReads)return;if(l=parseInt(t.attributes.multi_mapped),h=c+l,h<this.config.minTotalReads)return;if(h>0&&l/h>this.config.maxFractionMultiMappedReads)return;if(t.attributes.maximum_spliced_alignment_overhang&&parseInt(t.attributes.maximum_spliced_alignment_overhang)<this.config.minSplicedAlignmentOverhang)return}if(t.attributes.num_samples_with_this_junction){if(u=parseInt(t.attributes.num_samples_with_this_junction),this.config.minSamplesWithThisJunction&&u<this.config.minSamplesWithThisJunction)return;if(this.config.maxSamplesWithThisJunction&&u>this.config.maxSamplesWithThisJunction)return;if(t.attributes.num_samples_total&&(t.attributes.percent_samples_with_this_junction=100*u/Number(t.attributes.num_samples_total),this.config.minPercentSamplesWithThisJunction&&(t.attributes.percent_samples_with_this_junction<this.config.minPercentSamplesWithThisJunction||t.attributes.percent_samples_with_this_junction>this.config.maxPercentSamplesWithThisJunction)))return}const f=this.margin,d=this.height,p=f+.5*d;let g=f;const m=f+d-10,v=(o+a)/2,b=(a+s)/2;let w,y,x=1;t.attributes.line_width?x=Number(t.attributes.line_width):(void 0===this.config.thicknessBasedOn||"numUniqueReads"===this.config.thicknessBasedOn?x=c:"numReads"===this.config.thicknessBasedOn?x=h:"numSamplesWithThisJunction"===this.config.thicknessBasedOn&&void 0!==u&&(x=u),x=1+Math.log(x+1)/Math.log(12)),void 0===this.config.bounceHeightBasedOn||"random"===this.config.bounceHeightBasedOn?w=(t.start+t.end)%7:"distance"===this.config.bounceHeightBasedOn?w=6*(t.end-t.start)/(pf.referenceFrameEnd-pf.referenceFrameStart):"thickness"===this.config.bounceHeightBasedOn&&(w=2*x),g+=d*Math.max(7-w,0)/10,y=t.attributes.color?t.attributes.color:void 0===this.config.colorBy||"numUniqueReads"===this.config.colorBy?c>this.config.colorByNumReadsThreshold?"blue":"#AAAAAA":"numReads"===this.config.colorBy?h>this.config.colorByNumReadsThreshold?"blue":"#AAAAAA":"isAnnotatedJunction"===this.config.colorBy?"true"===t.attributes.annotated_junction?"#b0b0ec":"orange":"strand"===this.config.colorBy?"+"===t.strand?"#b0b0ec":"#ecb0b0":"motif"===this.config.colorBy?df.getColor(t.attributes.motif):"#AAAAAA";let k="";t.attributes.label?k=t.attributes.label.replace(/_/g," "):void 0===this.config.labelWith||"uniqueReadCount"===this.config.labelWith?k=c:"totalReadCount"===this.config.labelWith?k=h:"numSamplesWithThisJunction"===this.config.labelWith?void 0!==u&&(k=u):"percentSamplesWithThisJunction"===this.config.labelWith?void 0!==t.attributes.percent_samples_with_this_junction&&(k=t.attributes.percent_samples_with_this_junction.toFixed(0)+"%"):"motif"===this.config.labelWith&&void 0!==t.attributes.motif&&(k+=t.attributes.motif),"uniqueReadCount"===this.config.labelWithInParen?k+=" ("+c+")":"totalReadCount"===this.config.labelWithInParen?k+=" ("+h+")":"multiMappedReadCount"===this.config.labelWithInParen?l>0&&(k+=" (+"+l+")"):"numSamplesWithThisJunction"===this.config.labelWithInParen?void 0!==u&&(k+=" ("+u+")"):"percentSamplesWithThisJunction"===this.config.labelWithInParen?void 0!==t.attributes.percent_samples_with_this_junction&&(k+=" ("+t.attributes.percent_samples_with_this_junction.toFixed(0)+"%)"):"motif"===this.config.labelWithInParen&&void 0!==t.attributes.motif&&(k+=` ${t.attributes.motif}`),t.isVisible=!0,i.beginPath(),i.moveTo(o,m),i.bezierCurveTo(v,g,b,g,s,m),i.lineWidth=x,i.strokeStyle=y,i.stroke();const _=(t,e,n,r)=>{t.beginPath(),t.moveTo(e,n),t.lineTo(e-r/2,n-r),t.lineTo(e+r/2,n-r),t.lineTo(e,n),t.closePath(),t.fill()};if(t.attributes.left_shape||t.attributes.right_shape){i.fillStyle=y;const e=i.lineWidth>2?10:7;t.attributes.left_shape&&_(i,o,m,e),t.attributes.right_shape&&_(i,s,m,e)}i.fillText(k,a-i.measureText(k).width/2,(7*g+p)/8)}clickedFeatures(t,e){return super.clickedFeatures(t,e).filter((function(t){return t.isVisible&&t.attributes}))}popupData(t,e){e=this.clickedFeatures(t,e);const n=t.genomicLocation,r=[];for(let t of e){const e="function"==typeof t.popupData?t.popupData(n):this.extractPopupData(t._f||t,this.getGenomeId());e&&(r.length>0&&r.push("<hr/><hr/>"),Array.prototype.push.apply(r,e))}return r}dispose(){this.trackView=void 0}}const mf=new Map([["ideogram",(t,e)=>new uf(t,e)],["sequence",(t,e)=>new Ns(t,e)],["feature",(t,e)=>new Du(t,e)],["seg",(t,e)=>new ju(t,e)],["mut",(t,e)=>new ju(t,e)],["maf",(t,e)=>new ju(t,e)],["wig",(t,e)=>new Bu(t,e)],["merged",(t,e)=>new qu(t,e)],["alignment",(t,e)=>new rl(t,e)],["interaction",(t,e)=>new Wu(t,e)],["interact",(t,e)=>new Wu(t,e)],["variant",(t,e)=>new tf(t,e)],["eqtl",(t,e)=>new nf(t,e)],["gwas",(t,e)=>new of(t,e)],["arc",(t,e)=>new cf(t,e)],["gcnv",(t,e)=>new sf(t,e)],["junction",(t,e)=>new gf(t,e)]]);var vf=function(t,e){mf.set(t,e)},bf=function(t,e,n){let r;switch(t){case"annotation":case"genes":case"fusionjuncspan":case"snp":r="feature";break;case"seg":case"maf":case"mut":r="seg";break;case"junctions":case"splicejunctions":r="junction";break;default:r=t}return mf.has(r)?mf.get(r)(e,n):void 0};class wf{constructor(t,e){this.config=t,this.name=t.name,this.roiSource=Cu(t,e),this.color=t.color||"rgba(68, 134, 247, 0.25)"}async getFeatures(t,e,n){return this.roiSource.getFeatures({chr:t,start:e,end:n})}draw(t){var e,n,r,i;if(i=t.features){e=t.bpStart+(t.pixelWidth*t.bpPerPixel+1);for(var o=0,s=i.length;o<s;o++)if(!((n=i[o]).end<t.bpStart)){if(n.start>e)break;r=yf(n,t.bpStart,t.bpPerPixel),ls.fillRect(t.context,r.x,t.pixelTop,r.width,t.pixelHeight,{fillStyle:this.color})}}}}function yf(t,e,n){var r,i;return r=Math.round((t.start-e)/n),(i=Math.round((t.end-e)/n)-r)<3&&(i=3,r-=1),{x:r,width:i}}class xf{constructor(t,e){const n=(new DOMParser).parseFromString(t,"text/xml");this.processRootNode(n,e);const r=n.getElementsByTagName("Resource"),i=n.getElementsByTagName("Track"),o=i&&i.length>0,s=[];this.tracks=s;const a=new Map;Array.from(r).forEach((function(t,e){var n={url:t.getAttribute("path"),indexURL:t.getAttribute("index"),order:e};a.set(n.url,n),o||s.push(n)})),o&&Array.from(i).forEach((function(t){const e=t.getElementsByTagName("Track");if(e&&e.length>0){const n={type:"merged",tracks:[]};kf(t,n),s.push(n),Array.from(e).forEach((function(t){t.processed=!0;const e=t.getAttribute("id"),r=a.get(e);r&&(n.tracks.push(r),kf(t,r),r.autoscale=!1,n.height=r.height)}))}else if(!t.processed){const e=t.getAttribute("id"),n=a.get(e);n&&(s.push(n),kf(t,n))}}))}processRootNode(t,e){const n=t.getElementsByTagName("Session");!n||n.length;const r=n.item(0),i=r.getAttribute("genome"),o=r.getAttribute("locus"),s=r.getAttribute("ucscID");e&&e.hasOwnProperty(i)?this.genome=i:(this.reference={fastaURL:i},s&&(this.reference.id=s)),o&&(this.locus=o)}}function kf(t,e){e.name=t.getAttribute("name");const n=t.getAttribute("color");n&&(e.color="rgb("+n+")");const r=t.getAttribute("altColor");n&&(e.altColor="rgb("+r+")");const i=t.getAttribute("height");i&&(e.height=parseInt(i));const o=t.getAttribute("autoScale");o&&(e.autoscale="true"===o);const s=t.getAttribute("autoscaleGroup");s&&(e.autoscaleGroup=s);const a=t.getAttribute("windowFunction");a&&(e.windowFunction=a);const c=t.getAttribute("visibilityWindow")||t.getAttribute("featureVisibilityWindow");c&&(e.visibilityWindow=c);const l=t.getAttribute("indexed");l&&(e.indexed="true"===l);const h=t.getAttribute("normalize");h&&(e.normalize="true"===h);const u=t.getElementsByTagName("DataRange");if(u.length>0){const t=u.item(0);e.min=Number(t.getAttribute("minimum")),e.max=Number(t.getAttribute("maximum")),e.logScale="LOG"===t.getAttribute("type")}}const _f=Se;class Sf{constructor(){this.attributes={},this.plinkLoaded=!1}async loadPlinkFile(t,e){e||(e={});var n=gs(e);const r=await go.loadString(t,n);var i=_f(r);for(let t of i){var o=t.split(" ");this.attributes[o[1]]={familyId:o[0],fatherId:o[2],motherId:o[3],sex:o[4],phenotype:o[5]}}return this.plinkLoaded=!0,this}getAttributes(t){return this.attributes[t]}getAttributeNames(){return this.hasAttributes()?Object.keys(this.attributes[Object.keys(this.attributes)[0]]):[]}hasAttributes(){return Object.keys(this.attributes).length>0}}class Cf{constructor(t,e){this.geneColors={},this.gene=null,this.snp=null,this.genesCount=0,t&&(this.gene=t.toUpperCase(),this.geneColors[this.gene]=Ef[this.genesCount++]),e&&(this.snp=e.toUpperCase())}addGene(t){this.geneColors[t.toUpperCase()]||(this.geneColors[t.toUpperCase()]=Ef[this.genesCount++])}colorForGene(t){return this.geneColors[t.toUpperCase()]}}var Ef=[];Ef.push("rgb(228,26,28)"),Ef.push("rgb(55,126,184)"),Ef.push("rgb(77,175,74)"),Ef.push("rgb(166,86,40)"),Ef.push("rgb(152,78,163)"),Ef.push("rgb(255,127,0)"),Ef.push("rgb(247,129,191)"),Ef.push("rgb(153,153,153)"),Ef.push("rgb(255,255,51)"),Ef.push("rgb(102, 194, 165"),Ef.push("rgb(252, 141, 98"),Ef.push("rgb(141, 160, 203"),Ef.push("rgb(231, 138, 195"),Ef.push("rgb(166, 216, 84"),Ef.push("rgb(255, 217, 47"),Ef.push("rgb(229, 196, 148"),Ef.push("rgb(179, 179, 179"),Ef.push("rgb( 141, 211, 199"),Ef.push("rgb(255, 255, 179"),Ef.push("rgb(190, 186, 218"),Ef.push("rgb(251, 128, 114"),Ef.push("rgb(128, 177, 211"),Ef.push("rgb(253, 180, 98"),Ef.push("rgb(179, 222, 105"),Ef.push("rgb(252, 205, 229"),Ef.push("rgb(217, 217, 217"),Ef.push("rgb(188, 128, 189"),Ef.push("rgb(204, 235, 197"),Ef.push("rgb(255, 237, 111");class Af{constructor(t,e,n,r,i){this.genome=t,this.chr=e,this.start=n,this.end=r,this.bpPerPixel=i,this.id=ve()}extend(t){const e=Math.min(t.start,this.start),n=Math.max(t.end,this.end),r=(n-e)/(this.end-this.start);this.start=e,this.end=n,this.bpPerPixel*=r}calculateEnd(t){return this.start+this.bpPerPixel*t}calculateBPP(t,e){return(t-this.start)/e}set(t){this.chr=t.chr,this.start=t.start,this.bpPerPixel=t.bpPerPixel}toPixels(t){return t/this.bpPerPixel}toBP(t){return this.bpPerPixel*t}shiftPixels(t,e){const n=this.start,r=t*this.bpPerPixel;this.start+=r,this.clampStart(e),this.end+=r;const{bpLength:i}=this.genome.getChromosome(this.chr);return this.end=Math.min(i,this.end),n!==this.start}clampStart(t){const e=this.genome.getChromosome(this.chr).bpStart||0;if(this.start=Math.max(e,this.start),t){const{bpLength:e}=this.genome.getChromosome(this.chr),n=e-t*this.bpPerPixel;this.start>n&&(this.start=n)}}async zoomWithScaleFactor(t,e,n,r){const i=void 0===r?this.start+this.toBP(n/2):r,{start:o,bpPerPixel:s}=this.start,{bpLength:a}=this.getChromosome(),c=e<1?t.minimumBases()/n:a/n;this.bpPerPixel=e<1?Math.max(this.bpPerPixel*e,c):Math.min(this.bpPerPixel*e,c);const l=this.bpPerPixel*n;this.start=i-.5*l,this.clampStart(n),this.end=this.start+l;(o!==this.start||s!==this.bpPerPixel)&&await t.updateViews(!0)}getChromosome(){return this.genome.getChromosome(this.chr)}getMultiLocusLabel(t){const e=Math.floor(this.start)+1,n=Math.round(this.start+this.bpPerPixel*t);return`&nbsp${this.chr}&nbsp &nbsp &nbsp${ws(n-e)}&nbsp`}getPresentationLocusComponents(t){if("all"===this.chr)return{chr:this.chr};{const e=_e(Math.floor(this.start)+1),n=_e(Math.round(this.start+this.bpPerPixel*t));return{chr:this.chr,start:e,end:n}}}getLocusString(){if("all"===this.chr)return"all";{const t=_e(Math.floor(this.start)+1),e=_e(Math.round(this.end));return`${this.chr}:${t}-${e}`}}description(t){console.log(` ${t||""} referenceFrame - ${this.chr} bpp ${this.bpPerPixel.toFixed(3)} start ${_e(Math.round(this.start))} end ${_e(Math.round(this.end))} `)}}const Tf={A:"rgb( 0, 200, 0)",C:"rgb( 0,0,200)",T:"rgb(255,0,0)",G:"rgb(209,113, 5)",N:"rgb(80,80,80)"},Lf={timeout:5e3,type:"plain",url:"https://igv.org/genomes/locus.php?genome=$GENOME$&name=$FEATURE$",coords:0,chromosomeField:"chromosome",startField:"start",endField:"end",geneField:"gene",snpField:"snp"};async function Mf(t,e){if(void 0===e||""===e.trim())return;(e&&"all"===e.trim().toLowerCase()||"*"===e)&&(e="all");const n=e.split(" ");let r=t.searchConfig||Lf,i=[];const o=async n=>{let i=function(t,e){const n=e.split(":"),r=n[0];if("all"===r&&t.genome.getChromosome(r))return{chr:r,start:0,end:t.genome.getChromosome(r).bpLength};if(void 0===t.genome.getChromosome(r))return;{const e={chr:t.genome.getChromosomeName(r),start:0,end:t.genome.getChromosome(r).bpLength};if(n.length>1){const t=n[1].split("-");if(t.length>2)return;{let n;if(n=t[0].replace(/,/g,""),isNaN(n))return;if(e.start=parseInt(n,10)-1,e.end=e.start+1,1===t.length&&(e.start-=20,e.end+=20),2===t.length){if(n=t[1].replace(/,/g,""),isNaN(n))return;e.end=parseInt(n,10)}}}return e}}(t,n);if(!i){const r=t.genome.featureDB[n.toUpperCase()];r&&(i={chr:r.chr,start:r.start,end:r.end,gene:r.name,locusSearchString:e})}if(!i&&t.config&&!1!==t.config.search)try{i=await async function(t,e,n){let r=n.url.replace("$FEATURE$",e.toUpperCase());r.indexOf("$GENOME$")>-1&&(r=r.replace("$GENOME$",t.genome.id?t.genome.id:"hg19"));const i=n.timeout?{timeout:n.timeout}:void 0,o=await go.loadString(r,i),s=function(t,e,n){let r;r="plain"===n.type?function(t,e){const n=[],r=[];return Se(e).forEach((function(t){""===t||n.push(t)})),n.forEach((function(e){var n,i,o,s,a=e.split("\t");a.length>=3&&(o=(i=a[1].split(":"))[1].split("-"),n=a[2].trim(),s={gene:a[0],chromosome:t.genome.getChromosomeName(i[0].trim()),start:parseInt(o[0].replace(/,/g,"")),end:parseInt(o[1].replace(/,/g,"")),type:"gtex"===n?"snp":"gene"},r.push(s))})),r}(t,e):JSON.parse(e);n.resultsField&&(r=r[n.resultsField]);if(r&&0!==r.length){const e=n.chromosomeField||"chromosome",i=n.startField||"start",o=n.endField||"end",s=n.coords||1;let a;a=Array.isArray(r)?r[0]:r,a.hasOwnProperty(e)&&a.hasOwnProperty(i)||console.error("Search service results must include chromosome and start fields: "+a);const c=a[e],l=t.genome.getChromosome(c);if(!l)return;const h=l.name;let u=a[i]-s,f=a[o];void 0===f&&(f=u+1);const d={chr:h,start:u,end:f},p=a.type?a.type:"gene";return n.geneField&&"gene"===p&&(d.gene=a[n.geneField]),n.snpField&&"snp"===p&&(d.snp=a[n.snpField]),d}return}(t,o,n);s&&(s.locusSearchString=e);return s}(t,n,r)}catch(t){throw console.error(t),Error("Search service currently unavailable.")}return i};for(let t of n){const e=await o(t);e&&(e.locusSearchString=t,i.push(e))}if(0===i.length){const t=await o(e);t&&(t.locusSearchString=e,i.push(t))}return 0===i.length?void 0:i}class Rf{constructor(t){this.browser=t}navbarDidResize(t,e){this.updateNavbar(this.createResponsiveClassSchedule(t,e))}updateNavbar(t){this.browser.$toggle_button_container.removeClass(),this.browser.$toggle_button_container.addClass(t.$toggle_button_container),de(this.browser.zoomWidget.zoomContainer).removeClass(),de(this.browser.zoomWidget.zoomContainer).addClass(t.zoomContainer)}createResponsiveClassSchedule(t,e){let n={};return e?this.browser.windowSizePanel.hide():this.browser.windowSizePanel.show(),t>990?(n.$toggle_button_container="igv-navbar-toggle-button-container",n.zoomContainer="igv-zoom-widget"):t>860?(n.$toggle_button_container="igv-navbar-toggle-button-container",n.zoomContainer="igv-zoom-widget-900"):t>540?(n.$toggle_button_container="igv-navbar-toggle-button-container-750",n.zoomContainer="igv-zoom-widget-900"):(n.$toggle_button_container="igv-navbar-toggle-button-container-750",n.zoomContainer="igv-zoom-widget-900",this.browser.windowSizePanel.hide()),e&&(n.zoomContainer="igv-zoom-widget-hidden"),n}}const If=function(t,e){this.container=pe({class:"igv-chromosome-select-widget-container"}),e.appendChild(this.container),this.select=document.createElement("select"),this.select.setAttribute("name","chromosome-select-widget"),this.container.appendChild(this.select),this.select.addEventListener("change",(()=>{this.select.blur(),""!==this.select.value&&t.search(this.select.value)})),this.showAllChromosomes=!1!==t.config.showAllChromosomes};If.prototype.show=function(){this.container.style.display="flex"},If.prototype.hide=function(){this.container.style.display="none"},If.prototype.update=function(t){const e=this.showAllChromosomes?t.chromosomeNames.slice():t.wgChromosomeNames.slice();t.showWholeGenomeView()&&(e.unshift("all"),e.unshift("")),this.select.innerHTML="";for(let t of e){const e=document.createElement("option");e.setAttribute("value",t),e.innerText=t,this.select.appendChild(e)}};class Nf{constructor(t,e){this.container=pe({class:"igv-windowsize-panel-container"}),t.appendChild(this.container),e.on("locuschange",(t=>{this.updatePanel(t)})),this.browser=e}show(){this.container.style.display="block"}hide(){this.container.style.display="none"}updatePanel(t){const e=this.browser.calculateViewportWidth(this.browser.referenceFrameList.length);this.container.innerText=1===t.length?ws(Math.round(e*t[0].bpPerPixel)):""}}class Pf{constructor(t,e){this.browser=e,this.columnContainer=t,this.horizontalGuide=pe({class:"igv-cursor-guide-horizontal"}),t.appendChild(this.horizontalGuide),this.verticalGuide=pe({class:"igv-cursor-guide-vertical"}),t.appendChild(this.verticalGuide),this.addMouseHandler(e),this.setVisibility(e.config.showCursorGuide)}addMouseHandler(t){this.boundMouseMoveHandler=function(e){const{x:n,y:r}=be(e,this.columnContainer);this.horizontalGuide.style.top=`${r}px`;const i=document.elementFromPoint(e.clientX,e.clientY);let o;if(i.parentElement&&(i.parentElement.classList.contains("igv-viewport-content")?o=i.parentElement.parentElement:i.parentElement.classList.contains("igv-viewport")&&i.classList.contains("igv-viewport-content")&&(o=i.parentElement),o&&t.getRulerTrackView())){this.verticalGuide.style.left=`${n}px`;const r=t.root.querySelectorAll(".igv-column");let i;const s=o.parentElement;for(let t=0;t<r.length;t++)void 0===i&&s===r[t]&&(i=t);const a=t.getRulerTrackView().viewports[i].mouseMove(e);if(a){const{start:t,bp:e,end:n}=a,r=(e-t)/(n-t);this.customMouseHandler&&this.customMouseHandler({start:t,bp:e,end:n,interpolant:r})}}}.bind(this),this.columnContainer.addEventListener("mousemove",this.boundMouseMoveHandler)}removeMouseHandler(){this.columnContainer.removeEventListener("mousemove",this.boundMouseMoveHandler)}setVisibility(t){!0===t?this.show():this.hide()}show(){this.verticalGuide.style.display="block",this.horizontalGuide.style.display="block"}hide(){if(this.verticalGuide.style.display="none",this.horizontalGuide.style.display="none",this.browser.getRulerTrackView())for(let t of this.browser.getRulerTrackView().viewports)t.$tooltip.hide()}}class Of{constructor(t,e){this.browser=t,this.button=pe({class:"igv-navbar-button"}),e.appendChild(this.button),this.button.textContent="cursor guide",this.button.addEventListener("click",(()=>{t.cursorGuideVisible=!t.cursorGuideVisible,t.setCursorGuideVisibility(t.cursorGuideVisible),this.setButtonState(t.cursorGuideVisible)})),this.setButtonState(t.cursorGuideVisible),t.config.showCursorTrackingGuideButton?this.show():this.hide()}setButtonState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.button.style.display="block",this.setButtonState(this.browser.cursorGuideVisible)}hide(){this.button.style.display="none"}}class Ff{constructor(t,e){this.browser=t,this.button=pe({class:"igv-navbar-button"}),e.appendChild(this.button),this.button.textContent="center line",this.button.addEventListener("click",(()=>{t.isCenterLineVisible=!t.isCenterLineVisible,t.setCenterLineVisibility(t.isCenterLineVisible),this.setButtonState(t.isCenterLineVisible)})),this.setButtonState(t.isCenterLineVisible),t.config.showCenterGuideButton?this.show():this.hide()}setButtonState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.isVisible=!0,this.button.style.display="block",this.setButtonState(this.browser.isCenterLineVisible)}hide(){this.isVisible=!1,this.button.style.display="none"}}class Df{constructor(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.textContent="track labels",this.button.addEventListener("click",(()=>{e.trackLabelsVisible=!e.trackLabelsVisible,this.setState(e.trackLabelsVisible),e.setTrackLabelVisibility(e.trackLabelsVisible)})),this.browser=e,this.setVisibility(e.config.showTrackLabelButton),this.setState(e.trackLabelsVisible)}setVisibility(t){!0===t?this.show():this.hide()}setState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.button.style.display="block",this.setState(this.browser.trackLabelsVisible)}hide(){this.button.style.display="none"}}class Bf{constructor(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.innerText="Sample Names",this.setState(e.showSampleNames),this.setVisibility(e.showSampleNameButton),this.button.addEventListener("click",(()=>{e.showSampleNames=!e.showSampleNames,this.setState(e.showSampleNames);for(let{sampleNameViewport:t}of e.trackViews)!1===e.showSampleNames?t.hide():t.show();e.layoutChange()}))}setVisibility(t){!0===t?this.show():this.hide()}setState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}hide(){this.button.style.display="none"}show(){this.button.style.display="block"}}let zf=23,Hf=0;const Vf=function(t,e){this.browser=t,this.zoomContainer=pe({class:"igv-zoom-widget"}),e.appendChild(this.zoomContainer),this.zoomOutButton=pe(),this.zoomContainer.appendChild(this.zoomOutButton),this.zoomOutButton.appendChild(we("minus-circle")),this.zoomOutButton.addEventListener("click",(()=>{t.zoomOut()}));const n=pe();this.zoomContainer.appendChild(n),this.slider=document.createElement("input"),this.slider.type="range",this.slider.min="0",this.slider.max=`${zf}`,n.appendChild(this.slider),this.slider.addEventListener("change",(e=>{e.preventDefault(),e.stopPropagation();const n=t.referenceFrameList[0],{bpLength:r}=n.genome.getChromosome(n.chr),{end:i,start:o}=n,s=i-o,a=r/Math.pow(2,e.target.valueAsNumber);t.zoomWithScaleFactor(a/s)})),this.zoomInButton=pe(),this.zoomContainer.appendChild(this.zoomInButton),this.zoomInButton.appendChild(we("plus-circle")),this.zoomInButton.addEventListener("click",(()=>{t.zoomIn()})),t.on("locuschange",(t=>{this.browser.isMultiLocusMode()?this.disable():(this.enable(),this.update(t))}))};Vf.prototype.update=function(t){const e=t[0],{bpLength:n}=e.genome.getChromosome(e.chr),{start:r,end:i}=e;zf=Math.ceil(Math.log2(n/this.browser.minimumBases())),this.slider.max=`${zf}`;const o=n/(i-r);Hf=Math.log2(o),this.slider.value=`${Math.round(Hf)}`},Vf.prototype.enable=function(){this.slider.disabled=!1},Vf.prototype.disable=function(){this.slider.disabled=!0},Vf.prototype.hide=function(){this.zoomContainer.style.display="none"},Vf.prototype.show=function(){this.zoomContainer.style.display="block"},Vf.prototype.hideSlider=function(){this.slider.style.display="none"},Vf.prototype.showSlider=function(){this.slider.style.display="block"};const jf=function(t,e){const n=pe({class:"igv-navbar-button"});t.append(n),n.textContent="Save SVG",n.addEventListener("click",(()=>e.saveSVGtoFile({})))},Uf=(t,e)=>{const n=0===t?e.nextElementSibling:e.previousElementSibling;e.remove(),n.remove()},qf=t=>{const e=pe({class:"igv-column-shim"});_s(e,t);const n=pe({class:"igv-column"});return _s(n,e),n},Wf=(t,e)=>{for(let n=0;n<e;n++){const r=pe({class:"igv-column"});if(ks(r,t),e>1&&n>0){ks(pe({class:"igv-column-shim"}),r)}}};class $f{constructor(t,e,n){this.browser=t,this.referenceFrame=e,this.column=n,this.container=pe({class:"igv-center-line"}),n.appendChild(this.container),t.isCenterLineVisible?this.show():this.hide()}repaint(){const t=Math.floor(this.browser.calculateViewportWidth(this.browser.referenceFrameList.length)/2);if(this.referenceFrame){1/this.referenceFrame.bpPerPixel>1?(this.container.style.left=`${t}px`,this.container.style.width=`${Math.floor(this.referenceFrame.toPixels(1))}px`,this.container.classList.remove("igv-center-line-thin"),this.container.classList.add("igv-center-line-wide")):(this.container.style.left=`${t}px`,this.container.style.width="1px",this.container.classList.remove("igv-center-line-wide"),this.container.classList.add("igv-center-line-thin"))}}show(){this.isVisible=!0,this.container.style.display="block",this.repaint()}hide(){this.isVisible=!1,this.container.style.display="none"}resize(){this.repaint()}}const Gf=_e;class Zf{constructor(t){this.browser=t,this.height=40,this.name="",this.id="ruler",this.disableButtons=!0,this.ignoreTrackMenu=!0,this.order=.01*Number.MIN_SAFE_INTEGER,this.removable=!1,this.type="ruler"}async getFeatures(t,e,n){return[]}computePixelHeight(t){return this.height}draw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpPerPixel:i,bpStart:o}){na.isWholeGenomeView(e.chr)?this.drawWholeGenome({context:t,pixelWidth:n,pixelHeight:r,bpPerPixel:i}):this.doDraw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpStart:o})}drawWholeGenome({context:t,pixelWidth:e,pixelHeight:n,bpPerPixel:r}){t.save(),ls.fillRect(t,0,0,e,n,{fillStyle:"white"});for(let e of this.browser.genome.wgChromosomeNames){let i=this.browser.genome.getCumulativeOffset(e),o=this.browser.genome.getChromosome(e).bpLength,s=Math.round(i/r),a=Math.round(o/r);this.renderChromosomeRect(t,s,0,a,n,e)}t.restore()}doDraw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpStart:i}){t.clearRect(0,0,n,r);const o=function(t,e){if(t<10)return new Xf(1,"bp",1);const n=Math.floor(Math.log10(t));let r="bp",i=1;n>9?(r="gb",i=1e9):n>6?(r="mb",i=1e6):n>3&&(r="kb",i=1e3);const o=Math.pow(10,n-1),s=t/o,a=75,c=Math.pow(10,n-1),l=Math.pow(10,n)/2;return new Xf(s<a&&!0!==e?c:l,r,i)}(Math.floor(e.toBP(n)),t.isSVG);let s=Math.floor(i/o.majorTick)-1;const{tickDelta:a,labelLength:c}=function(t,e,n,r,i){const o=l(e,c(1+r,i),n)-l(e,c(r,i),n),s=`${_e(Math.floor(c(r,i)/i.unitMultiplier))} ${i.majorUnit}`,a=Math.floor(t.measureText(s).width);return{tickDelta:o,labelLength:a};function c(t,e){return Math.floor(t*e.majorTick)}function l(t,e,n){return Math.round(t.toPixels(e-1-n+.5))}}(t,e,i,s,o);let l,h;this.browser.referenceFrameList.indexOf(e);let u=a;const f=.25*c;do{h=Math.floor(s*o.majorTick);const n=`${_e(Math.floor(h/o.unitMultiplier))} ${o.majorUnit}`;l=Math.round(e.toPixels(h-1-i+.5));const r=Math.round(l-t.measureText(n).width/2);r>0&&f+c<=u&&(ls.fillText(t,n,r,this.height-8),u=0),l>0&&ls.strokeLine(t,l,this.height-6,l,this.height-2),h=Math.floor((1+s)*o.majorTick);let d=l+(Math.round(e.toPixels(h-1-i+.5))-l)/2;d>0&&ls.strokeLine(t,d,this.height-6,d,this.height-2),++s,u+=a}while(l<n);ls.strokeLine(t,0,this.height-2,n,this.height-2)}renderChromosomeRect(t,e,n,r,i,o){t.textAlign="center",t.textBaseline="middle",t.font="12px sans-serif",ls.strokeLine(t,e+r,n,e+r,n+i,{strokeStyle:no.greyScale(191)});const s=o.startsWith("chr")?o.substring(3):o;r>t.measureText(s).width&&ls.fillText(t,s,e+r/2,n+i/2,{fillStyle:no.greyScale(68)})}get supportsWholeGenome(){return!0}dispose(){}}class Xf{constructor(t,e,n){this.majorTick=t,this.minorTick=t/10,this.majorUnit=e,this.unitMultiplier=n}description(t){console.log((t||"")+" tick "+Gf(this.majorTick)+" label width "+Gf(this.labelWidthBP)+" multiplier "+this.unitMultiplier)}}const Yf=function(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.textContent="circular view",this.button.addEventListener("click",(()=>{e.circularViewVisible=!e.circularViewVisible})),this.browser=e,this.setVisibility(e.config.showCircularViewButton),this.setState(e.circularViewVisible)};Yf.prototype.setVisibility=function(t){!0===t?this.show():this.hide()},Yf.prototype.setState=function(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")},Yf.prototype.show=function(){this.button.style.display="block",this.setState(this.browser.circularViewVisible)},Yf.prototype.hide=function(){this.button.style.display="none"};const Kf=function(t,e,n){const r=pe({class:"igv-navbar-button"});t.append(r),r.textContent=n.label,r.addEventListener("click",(()=>n.callback(e)))};class Qf{constructor(t,e){this.config=t,this.guid=ve(),this.namespace=".browser_"+this.guid,this.parent=e,this.root=pe({class:"igv-container"}),e.appendChild(this.root),Qo.init(this.root),this.columnContainer=pe({class:"igv-column-container"}),this.root.appendChild(this.columnContainer),this.menuPopup=new yl(this.columnContainer),this.initialize(t),this.trackViews=[],this.constants={dragThreshold:3,scrollThreshold:5,defaultColor:"rgb(0,0,150)",doubleClickDelay:t.doubleClickDelay||500},this.eventHandlers={},this.addMouseHandlers(),this.setControls(t)}initialize(t){t.gtex&&(Eu.gtexLoaded=!0),this.flanking=t.flanking,this.crossDomainProxy=t.crossDomainProxy,this.formats=t.formats,this.trackDefaults=t.trackDefaults,this.nucleotideColors=t.nucleotideColors||Tf;for(let t of Object.keys(this.nucleotideColors))this.nucleotideColors[t.toLowerCase()]=this.nucleotideColors[t];this.trackLabelsVisible=t.showTrackLabels,this.isCenterLineVisible=t.showCenterGuide,this.cursorGuideVisible=t.showCursorGuide,this.showSampleNames=t.showSampleNames,this.showSampleNameButton=t.showSampleNameButton,this.sampleNameViewportWidth=t.sampleNameViewportWidth||200,t.search&&(this.searchConfig={type:"json",url:t.search.url,coords:void 0===t.search.coords?1:t.search.coords,chromosomeField:t.search.chromosomeField||"chromosome",startField:t.search.startField||"start",endField:t.search.endField||"end",geneField:t.search.geneField||"gene",snpField:t.search.snpField||"snp",resultsField:t.search.resultsField})}setControls(t){const e=this.createStandardControls(t);e.insertBefore(de(this.columnContainer)),this.$navigation=e,!1===t.showControls&&e.hide()}createStandardControls(t){this.navbarManager=new Rf(this);const e=de("<div>",{class:"igv-navbar"});this.$navigation=e;const n=de("<div>",{class:"igv-navbar-left-container"});e.append(n);const r=de("<div>",{class:"igv-logo"});n.append(r);const i=de('<svg width="690px" height="324px" viewBox="0 0 690 324" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>IGV</title><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="IGV" fill="#666666"><polygon id="Path" points="379.54574 8.00169252 455.581247 8.00169252 515.564813 188.87244 532.884012 253.529506 537.108207 253.529506 554.849825 188.87244 614.833392 8.00169252 689.60164 8.00169252 582.729511 320.722144 486.840288 320.722144"></polygon><path d="M261.482414,323.793286 C207.975678,323.793286 168.339046,310.552102 142.571329,284.069337 C116.803612,257.586572 103.919946,217.158702 103.919946,162.784513 C103.919946,108.410325 117.437235,67.8415913 144.472217,41.0770945 C171.507199,14.3125977 212.903894,0.930550071 268.663545,0.930550071 C283.025879,0.930550071 298.232828,1.84616386 314.284849,3.6774189 C330.33687,5.50867394 344.839793,7.97378798 357.794056,11.072835 L357.794056,68.968378 C339.48912,65.869331 323.578145,63.5450806 310.060654,61.9955571 C296.543163,60.4460336 284.574731,59.6712835 274.154998,59.6712835 C255.850062,59.6712835 240.502308,61.4320792 228.111274,64.9537236 C215.720241,68.4753679 205.793482,74.2507779 198.330701,82.2801269 C190.867919,90.309476 185.587729,100.87425 182.48997,113.974767 C179.392212,127.075284 177.843356,143.345037 177.843356,162.784513 C177.843356,181.942258 179.251407,198.000716 182.067551,210.960367 C184.883695,223.920018 189.671068,234.41436 196.429813,242.443709 C203.188559,250.473058 212.059279,256.178037 223.042241,259.558815 C234.025202,262.939594 247.683295,264.629958 264.01693,264.629958 C268.241146,264.629958 273.098922,264.489094 278.590403,264.207362 C284.081883,263.925631 289.643684,263.50304 295.275972,262.939577 L295.275972,159.826347 L361.595831,159.826347 L361.595831,308.579859 C344.698967,313.087564 327.239137,316.750019 309.215815,319.567334 C291.192494,322.38465 275.281519,323.793286 261.482414,323.793286 L261.482414,323.793286 L261.482414,323.793286 Z" id="Path"></path>;<polygon id="Path" points="0.81355666 5.00169252 73.0472883 5.00169252 73.0472883 317.722144 0.81355666 317.722144"></polygon></g> </g> </svg>');i.css("width","34px"),i.css("height","32px"),r.append(i),this.$current_genome=de("<div>",{class:"igv-current-genome"}),n.append(this.$current_genome),this.$current_genome.text("");const o=de("<div>",{class:"igv-navbar-genomic-location"});n.append(o),this.chromosomeSelectWidget=new If(this,o.get(0)),void 0===t.showChromosomeWidget&&(t.showChromosomeWidget=!0),!0===t.showChromosomeWidget?this.chromosomeSelectWidget.show():this.chromosomeSelectWidget.hide();const s=de("<div>",{class:"igv-locus-size-group"});o.append(s);const a=de("<div>",{class:"igv-search-container"});s.append(a),this.$searchInput=de("<input>",{class:"igv-search-input",type:"text",placeholder:"Locus Search"}),a.append(this.$searchInput),this.$searchInput.change((()=>this.doSearch(this.$searchInput.val())));const c=pe({class:"igv-search-icon-container"});a.append(de(c)),c.appendChild(we("search")),c.addEventListener("click",(()=>this.doSearch(this.$searchInput.val()))),this.windowSizePanel=new Nf(s.get(0),this);const l=de("<div>",{class:"igv-navbar-right-container"});e.append(l);const h=de('<div class="igv-navbar-toggle-button-container">');if(l.append(h),this.$toggle_button_container=h,this.cursorGuide=new Pf(this.columnContainer,this),this.cursorGuideButton=new Of(this,h.get(0)),this.centerLineButton=new Ff(this,h.get(0)),this.setTrackLabelVisibility(t.showTrackLabels),this.trackLabelControl=new Df(h.get(0),this),this.sampleNameControl=new Bf(h.get(0),this),!0===t.showSVGButton&&(this.svgSaveControl=new jf(h.get(0),this)),t.customButtons)for(let e of t.customButtons)new Kf(h.get(0),this,e);return this.zoomWidget=new Vf(this,l.get(0)),!1===t.showNavigation&&this.$navigation.hide(),this.inputDialog=new Jo(this.root),this.inputDialog.container.id=`igv-input-dialog-${ve()}`,this.dataRangeDialog=new cs(de(this.root)),this.dataRangeDialog.$container.get(0).id=`igv-data-range-dialog-${ve()}`,this.genericColorPicker=new wl({parent:this.columnContainer,width:432}),this.genericColorPicker.container.id=`igv-track-color-picker-${ve()}`,e}getSampleNameViewportWidth(){return!1===this.showSampleNames?0:this.sampleNameViewportWidth}isMultiLocusMode(){return this.referenceFrameList&&this.referenceFrameList.length>1}addTrackToFactory(t,e){vf(t,e)}isMultiLocusWholeGenomeView(){if(void 0===this.referenceFrameList||1===this.referenceFrameList.length)return!1;for(let t of this.referenceFrameList)if("all"===t.chr.toLowerCase())return!0;return!1}toSVG(){let{x:t,y:e,width:n,height:r}=this.columnContainer.getBoundingClientRect();let i=new js({width:n,height:8e3,backdropColor:"white",multiLocusGap:0,viewbox:{x:0,y:0,width:n,height:8e3}});for(let t of this.trackViews)t.renderSVGContext(i,{deltaX:0,deltaY:-e});return i.setHeight(r),i.getSerializedSvg(!0)}renderSVG(t){const e=this.toSVG();return t.empty(),t.append(e),e}saveSVGtoFile(t){let e=this.toSVG();t.$container&&(t.$container.empty(),t.$container.append(e));qe(t.filename||"igvjs.svg",URL.createObjectURL(new Blob([e],{type:"application/octet-stream"})))}async loadSession(t){let e;return this.roi=[],e=t.url||t.file?await async function(t){const e=t.url||t.file;if(t.url&&(t.url.startsWith("blob:")||t.url.startsWith("data:"))){const e=Qf.uncompressSession(t.url);return JSON.parse(e)}{let n=t.filename;if(n||(n=t.url?await bs(t.url):t.file.name),n.endsWith(".xml")){const t=na.KNOWN_GENOMES,n=await go.loadString(e);return new xf(n,t)}return n.endsWith(".json")?go.loadJson(e):void 0}}(t):t,this.loadSessionObject(e)}async loadSessionObject(t){this.cleanHouseForSession(),this.showSampleNames=t.showSampleNames||!1,this.sampleNameControl.setState(!0===this.showSampleNames),t.sampleNameViewportWidth&&(this.sampleNameViewportWidth=t.sampleNameViewportWidth),xs(this.columnContainer,"igv-axis-column"),xs(this.columnContainer,"igv-sample-name-column"),xs(this.columnContainer,"igv-scrollbar-column"),xs(this.columnContainer,"igv-track-drag-column"),xs(this.columnContainer,"igv-gear-menu-column");const e=await na.expandReference(t.reference||t.genome);if(await this.loadReference(e,t.locus),this.centerLineList=this.createCenterLineList(this.columnContainer),!1!==t.showIdeogram){const t=new uf(this);t.id="ideogram",this.trackViews.push(new Sl(this,this.columnContainer,t))}if(!1!==t.showRuler&&this.trackViews.push(new Sl(this,this.columnContainer,new Zf(this))),t.gtexSelections)for(let e of this.referenceFrameList)for(let n of Object.keys(t.gtexSelections)){const r=t.gtexSelections[n].gene,i=t.gtexSelections[n].snp;e.selection=new Cf(r,i)}if(t.roi){this.roi=[];for(let e of t.roi)this.roi.push(new wf(e,this.genome))}const n=e.tracks||[],r=t.tracks?n.concat(t.tracks):n;0===r.filter((t=>"sequence"===t.type)).length&&r.push({type:"sequence",order:Ts});let i=1;for(let t of r)void 0===t.order&&(t.order=i++);await this.loadTrackList(r);for(let t of this.trackViews.filter((t=>"ruler"===t.track.type||"ideogram"===t.track.type)))t.updateViews();this.updateUIWithReferenceFrameList()}createCenterLineList(t){const e=t.querySelectorAll(".igv-center-line");for(let t=0;t<e.length;t++)e[t].remove();const n=[],r=t.querySelectorAll(".igv-column");for(let t=0;t<r.length;t++)n.push(new $f(this,this.referenceFrameList[t],r[t]));return n}async loadReference(t,e){const n=await na.loadGenome(t),r=void 0===this.genome||this.genome.id!==n.id;this.genome=n,this.updateNavbarDOMWithGenome(n),r&&this.removeAllTracks();let i=function(t,e){return t?Array.isArray(t)?t.join(" "):t:e.getHomeChromosomeName()}(e,n);if(!await this.search(i,!0)){console.log("Initial locus not found: "+i),i=n.getHomeChromosomeName();if(!await this.search(i,!0))throw new Error("Cannot set initial locus")}r&&this.circularView&&this.circularView.setAssembly({name:this.genome.id,id:this.genome.id,chromosomes:Jc(this.genome)})}cleanHouseForSession(){for(let t of this.trackViews)t.removeDOMFromColumnContainer();this.columnContainer.querySelectorAll(".igv-axis-column, .igv-column-shim, .igv-column, .igv-sample-name-column, .igv-scrollbar-column, .igv-track-drag-column, .igv-gear-menu-column").forEach((t=>t.remove())),this.trackViews=[],this.circularView&&this.circularView.clearChords()}updateNavbarDOMWithGenome(t){this.$current_genome.text(t.id||""),this.$current_genome.attr("title",t.id||""),this.chromosomeSelectWidget.update(t)}async loadGenome(t){const e=await na.expandReference(t);await this.loadReference(e,void 0);const n=e.tracks||[];return 0===n.filter((t=>"sequence"===t.type)).length&&n.push({type:"sequence",order:Ts}),await this.loadTrackList(n),await this.updateViews(),this.genome}updateUIWithReferenceFrameList(){const t=this.referenceFrameList;this.updateLocusSearchWidget();const e=this.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(t[0].chr);this.navbarManager.navbarDidResize(this.$navigation.width(),e),nd(this.trackViews,this.trackLabelsVisible),this.setCenterLineAndCenterLineButtonVisibility(!na.isWholeGenomeView(t[0].chr))}setTrackLabelVisibility(t){nd(this.trackViews,t)}setCursorGuideVisibility(t){t?this.cursorGuide.show():this.cursorGuide.hide()}setCustomCursorGuideMouseHandler(t){this.cursorGuide.customMouseHandler=t}setCenterLineVisibility(t){for(let e of this.centerLineList)!0===t?(e.show(),e.repaint()):e.hide()}setCenterLineAndCenterLineButtonVisibility(t){for(let e of this.centerLineList){t&&e.isVisible?e.show():e.container.style.display="none"}t&&this.centerLineButton.isVisible?this.centerLineButton.show():this.centerLineButton.button.style.display="none"}async loadTrackList(t){const e=[];for(let n of t)e.push(this.loadTrack(n));const n=await Promise.all(e);return this.trackViews.filter((function(t){return t.track.autoscaleGroup})).length>0&&this.updateViews(),n}async loadROI(t){if(this.roi||(this.roi=[]),Array.isArray(t))for(let e of t)this.roi.push(new wf(e,this.genome));else this.roi.push(new wf(t,this.genome));await this.updateViews(!0)}removeROI(t){for(let e=0;e<this.roi.length;e++)if(this.roi[e].name===t.name){this.roi.splice(e,1);break}for(let t of this.trackViews)t.repaintViews()}clearROIs(){this.roi=[];for(let t of this.trackViews)t.repaintViews()}getRulerTrackView(){const t=this.trackViews.filter((({track:t})=>"ruler"===t.id));return t.length>0?t[0]:void 0}async loadTrack(t){ke(t)&&(t=JSON.parse(t));try{const e=await this.createTrack(t);if(void 0===e)return Qo.presentAlert(new Error(`Unknown file type: ${t.url||t}`),void 0),e;void 0===e.order&&(e.order=this.trackViews.length);const n=new Sl(this,this.columnContainer,e);if(this.trackViews.push(n),nd(this.trackViews,this.trackLabelsVisible),this.reorderTracks(),this.fireEvent("trackorderchanged",[this.getTrackOrder()]),"function"==typeof e.postInit)try{n.startSpinner(),await e.postInit()}finally{n.stopSpinner()}return e.autoscaleGroup||(t.sync?await n.updateViews():n.updateViews()),"function"==typeof e.hasSamples&&e.hasSamples()&&!1!==this.config.showSampleNameButton&&this.sampleNameControl.show(),e}catch(e){const n={401:"Access unauthorized",403:"Access forbidden",404:"Not found"};console.error(e);let r=e.message||e.error||e.toString();n.hasOwnProperty(r)&&(r=n[r]),r+=": "+t.url,Qo.presentAlert(new Error(r),void 0)}}async createTrack(t){let e=await async function(t){return"function"==typeof t?t():t}(t.url);if(ke(e)&&(e=e.trim()),e)if(t.format)t.format=t.format.toLowerCase();else{let n=t.filename;n||(n=await bs(e)),t.format=function(t){var e,n;if((t=t.toLowerCase()).endsWith("refgene.txt.gz")||t.endsWith("refgene.txt.bgz")||t.endsWith("refgene.txt")||t.endsWith("refgene.sorted.txt.gz")||t.endsWith("refgene.sorted.txt.bgz"))return"refgene";switch((e=t.indexOf("?"))>0&&(t=t.substr(0,e)),t.endsWith(".gz")&&(t=t.substr(0,t.length-3)),(t.endsWith(".txt")||t.endsWith(".tab")||t.endsWith(".bgz"))&&(t=t.substr(0,t.length-4)),n=(e=t.lastIndexOf("."))<0?t:t.substr(e+1)){case"bw":return"bigwig";case"bb":return"bigbed";default:return fs.has(n)?n:void 0}}(n),t.format||void 0!==t.sourceType&&"htsget"!==t.sourceType||await ec.inferFormat(t)}let n=t.type?t.type.toLowerCase():void 0;if(!n){if(n=ds(t),"bedtype"===n){const e=Cu(t,this.genome);t._featureSource=e;const r=await e.trackType();n=r||"annotation"}t.type=n}if(this.trackDefaults&&n){const e=this.trackDefaults[n];if(e)for(let n in e)e.hasOwnProperty(n)&&void 0===t[n]&&(t[n]=e[n])}const r=bf(n,t,this);if(r&&t.roi){r.roi=[];for(let e of t.roi)r.roi.push(new wf(e,this.genome))}return r}reorderTracks(){this.trackViews.sort((function(t,e){const n=t=>"ideogram"===t.track.id?1:"ruler"===t.track.id?2:3,r=n(t),i=n(e);if(r===i){return(t.track.order||0)-(e.track.order||0)}return r-i}));for(let{axis:t,viewports:e,sampleNameViewport:n,outerScroll:r,dragHandle:i,gearContainer:o}of this.trackViews){t.remove();for(let{$viewport:t}of e)t.detach();n.viewport.remove(),r.remove(),i.remove(),o.remove()}const t=this.columnContainer.querySelectorAll(".igv-column");for(let{axis:e,viewports:n,sampleNameViewport:r,outerScroll:i,dragHandle:o,gearContainer:s}of this.trackViews){this.columnContainer.querySelector(".igv-axis-column").appendChild(e);for(let e=0;e<t.length;e++){const{$viewport:r}=n[e];t[e].appendChild(r.get(0))}this.columnContainer.querySelector(".igv-sample-name-column").appendChild(r.viewport),this.columnContainer.querySelector(".igv-scrollbar-column").appendChild(i),this.columnContainer.querySelector(".igv-track-drag-column").appendChild(o),this.columnContainer.querySelector(".igv-gear-menu-column").appendChild(s)}}getTrackOrder(){return this.trackViews.filter((t=>t.track&&t.track.name)).map((t=>t.track.name))}removeTrackByName(t){const e=this.trackViews.slice();for(let n of e)t===n.track.name&&this.removeTrack(n.track)}removeTrack(t){this.trackViews.splice(this.trackViews.indexOf(t.trackView),1),this.fireEvent("trackremoved",[t]),this.fireEvent("trackorderchanged",[this.getTrackOrder()]),t.trackView.dispose()}removeAllTracks(){const t=[];for(let e of this.trackViews)"ruler"!==e.track.id&&"ideogram"!==e.track.id?(this.fireEvent("trackremoved",[e.track]),e.dispose()):t.push(e);this.trackViews=t}findTracks(t,e){let n="function"==typeof t?e=>t(e.track):n=>e===n.track[t];return this.trackViews.filter(n).map((t=>t.track))}setTrackHeight(t){this.trackHeight=t,this.trackViews.forEach((function(e){e.setTrackHeight(t)}))}async visibilityChange(){this.layoutChange()}async layoutChange(){if(this.referenceFrameList.find((t=>t.bpPerPixel<0))){const t=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList)e.bpPerPixel=(e.end-e.start)/t}if(this.referenceFrameList){const t=this.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(this.referenceFrameList[0].chr);this.navbarManager.navbarDidResize(this.$navigation.width(),t)}Jf.call(this),await this.updateViews()}async updateViews(){const t=this.trackViews;this.updateLocusSearchWidget();for(let t of this.centerLineList)t.repaint();if(this.dragObject)for(let e of t)await e.updateViews();else{const i={},o=[];for(let n of t){const t=n.track.autoscaleGroup;if(t){var e=i[t];e||(e=[],i[t]=e),e.push(n)}else o.push(n)}if(Object.entries(i).length>0){const t=Object.keys(i);for(let e of t){const t=i[e],o=[];for(let e of t)o.push(e.getInViewFeatures());const s=await Promise.all(o);var n,r=[];for(let t of s)r=r.concat(t);n=ms(r);const a=[];for(let e of t)e.track.dataRange=n,e.track.autoscale=!1,a.push(e.updateViews());await Promise.all(a)}}await Promise.all(o.map((t=>t.updateViews())))}}repaintViews(){for(let t of this.trackViews)t.repaintViews()}updateLocusSearchWidget(){const t=this.referenceFrameList,e=this.calculateViewportWidth(this.referenceFrameList.length);for(let n of t)n.end=n.start+n.bpPerPixel*e;this.chromosomeSelectWidget.select.value=1===t.length?this.referenceFrameList[0].chr:"";const n=this.referenceFrameList.map((t=>t.getLocusString())).join(" ");this.$searchInput.val(n),this.fireEvent("locuschange",[this.referenceFrameList])}calculateViewportWidth(t){let{width:e}=this.columnContainer.getBoundingClientRect();return e-=50+this.getSampleNameViewportWidth()+14+12+28,e-=5*(t-1),Math.floor(e/t)}getCenterLineXOffset(){let{width:t}=this.columnContainer.getBoundingClientRect();return t-=50+this.getSampleNameViewportWidth()+14+12+28,Math.floor(t/2+50)}minimumBases(){return this.config.minimumBases}zoomIn(){this.zoomWithScaleFactor(.5)}zoomOut(){this.zoomWithScaleFactor(2)}async zoomWithScaleFactor(t,e,n){const r=this.calculateViewportWidth(this.referenceFrameList.length);let i=n?[n]:this.referenceFrameList;for(let n of i)n.zoomWithScaleFactor(this,t,r,e)}async addMultiLocusPanel(t,e,n,r){const i=this.calculateViewportWidth(1+this.referenceFrameList.length),o=this.calculateViewportWidth(this.referenceFrameList.length)/this.calculateViewportWidth(1+this.referenceFrameList.length);for(let t of this.referenceFrameList)t.bpPerPixel*=o;const s=(n-e)/i,a=new Af(this.genome,t,e,n,s),c=r?this.referenceFrameList.indexOf(r):this.referenceFrameList.length-1,l=1+c,{$viewport:h}=this.trackViews[0].viewports[c],u=qf(h.get(0).parentElement);if(l===this.referenceFrameList.length){this.referenceFrameList.push(a);for(let t of this.trackViews){const e=gl(t,u,a);t.viewports.push(e)}}else{this.referenceFrameList.splice(l,0,a);for(let t of this.trackViews){const e=gl(t,u,a);t.viewports.splice(l,0,e)}}this.centerLineList=this.createCenterLineList(this.columnContainer),Jf.call(this),await this.updateViews(!0)}async removeMultiLocusPanel(t){const e=this.referenceFrameList.indexOf(t),{$viewport:n}=this.trackViews[0].viewports[e];Uf(e,n.parent().get(0));for(let{viewports:t}of this.trackViews)t[e].dispose(),t.splice(e,1);if(this.referenceFrameList.splice(e,1),1===this.referenceFrameList.length&&this.getRulerTrackView())for(let t of this.getRulerTrackView().viewports)t.dismissLocusLabel();const r=this.calculateViewportWidth(1+this.referenceFrameList.length)/this.calculateViewportWidth(this.referenceFrameList.length);await this.rescaleForMultiLocus(r)}async gotoMultilocusPanel(t){const e=this.referenceFrameList.indexOf(t);this.columnContainer.querySelectorAll(".igv-column").forEach(((t,n)=>{n===e||t.remove()})),this.columnContainer.querySelectorAll(".igv-column-shim").forEach((t=>t.remove()));for(let t of this.trackViews){const n=t.viewports[e];t.viewports.filter(((t,n)=>n!==e)).forEach((t=>t.dispose())),t.viewports=[n]}const n=this.calculateViewportWidth(1);t.bpPerPixel=(t.end-t.start)/n,this.referenceFrameList=[t],this.trackViews.forEach((({viewports:t})=>t.forEach((t=>t.setWidth(n))))),this.centerLineList=this.createCenterLineList(this.columnContainer),this.updateUIWithReferenceFrameList(),await this.updateViews(!0)}async rescaleForMultiLocus(t){const e=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList)e.bpPerPixel*=t;for(let{viewports:t}of this.trackViews)for(let n of t)n.setWidth(e);this.centerLineList=this.createCenterLineList(this.columnContainer),this.updateUIWithReferenceFrameList(),await this.updateViews()}async goto(t,e,n){await this.search(t+":"+e+"-"+n)}async doSearch(t,e){const n=await this.search(t,e);return n||Qo.presentAlert(new Error(`Unrecognized locus: <b> ${t} </b>`)),n}async search(t,e){const n=await Mf(this,t);if(n&&n.length>0){this.referenceFrameList=function(t,e,n,r,i){return t.map((t=>{n&&t.gene&&(t.start=Math.max(0,t.start-n),t.end+=n);const o=e.getChromosome(t.chr);vs(o.bpLength,t,r);const s=new Af(e,t.chr,t.start,t.end,(t.end-t.start)/i);return s.locusSearchString=t.locusSearchString,(t.gene||t.snp)&&(s.selection=new Cf(t.gene,t.snp)),s}))}(n,this.genome,this.flanking,this.minimumBases(),this.calculateViewportWidth(n.length));for(let t of this.trackViews)t.removeDOMFromColumnContainer();this.columnContainer.querySelectorAll(".igv-column-shim, .igv-column").forEach((t=>t.remove())),Wf(this.columnContainer.querySelector(".igv-sample-name-column"),this.referenceFrameList.length),this.centerLineList=this.createCenterLineList(this.columnContainer);for(let t of this.trackViews)t.addDOMToColumnContainer(this,this.columnContainer,this.referenceFrameList);return this.updateUIWithReferenceFrameList(),e||await this.updateViews(),!0}return!1}async loadSampleInformation(t){var e=t;je(t)&&(e=t.name),"fam"===e.substr(e.lastIndexOf(".")+1)&&(this.sampleInformation=await function(t,e){return(new Sf).loadPlinkFile(t,e)}(t))}on(t,e){this.eventHandlers[t]||(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}un(t,e){this.off(t,e)}off(t,e){if(t)if(e){const n=this.eventHandlers[t];if(n&&0!==n.length){const r=n.indexOf(e);-1!==r&&this.eventHandlers[t].splice(r,1)}else console.warn("No handlers to remove for event: "+t)}else this.eventHandlers[t]=[];else this.eventHandlers={}}fireEvent(t,e,n){const r=this.eventHandlers[t];if(void 0===r||0===r.length)return;const i=n||window;return r.map((function(t){return t.apply(i,e)}))[0]}dispose(){this.removeMouseHandlers();for(let t of this.trackViews)t.dispose()}toJSON(){const t={version:"2.12.5"};if(void 0!==this.showSampleNames&&(t.showSampleNames=this.showSampleNames),200!==this.sampleNameViewportWidth&&(t.sampleNameViewportWidth=this.sampleNameViewportWidth),t.reference=this.genome.toJSON(),Ue(t.reference.fastaURL))throw new Error(`Error. Sessions cannot include local file references ${t.reference.fastaURL.name}.`);if(Ue(t.reference.indexURL))throw new Error(`Error. Sessions cannot include local file references ${t.reference.indexURL.name}.`);const e=[],n={};let r=!1,i=this.trackViews[0];for(let{referenceFrame:t}of i.viewports){const i=t.getLocusString();if(e.push(i),t.selection){const e={gene:t.selection.gene,snp:t.selection.snp};n[i]=e,r=!0}}t.locus=1===e.length?e[0]:e,r&&(t.gtexSelections=n);const o=[],s=[];for(let{track:t}of this.trackViews)try{let e;e="function"==typeof t.getState?t.getState():t.config,e&&(e.browser&&delete e.browser,e.order=t.order,o.push(e))}catch(e){console.error(`Track: ${t.name}: ${e}`),s.push(`Track: ${t.name}: ${e}`)}if(s.length>0){let t=1,e="Errors encountered saving session: </br>";for(let n of s)e+=` (${t++}) ${n.toString()} <br/>`;throw Error(e)}return t.tracks=o,t}compressedSession(){return function(t){const e=new Uint8Array(t.length);for(var n=0;n<t.length;n++)e[n]=t.charCodeAt(n);const r=new Ui.deflateRaw(e),i=String.fromCharCode.apply(null,r);return btoa(i).replace(/\+/g,".").replace(/\//g,"_").replace(/=/g,"-")}(JSON.stringify(this.toJSON()))}sessionURL(){const t=window.location.href.slice(),e=t.indexOf("?");return(e>0?t.substring(0,e):t)+"?sessionURL=blob:"+this.compressedSession()}mouseDownOnViewport(t,e){var n;n=me(t),this.vpMouseDown={viewport:e,lastMouseX:n.x,mouseDownX:n.x,lastMouseY:n.y,mouseDownY:n.y,referenceFrame:e.referenceFrame}}cancelTrackPan(){const t=this.dragObject;this.dragObject=void 0,this.isScrolling=!1,this.vpMouseDown=void 0,t&&t.viewport.referenceFrame.start!==t.start&&(this.updateViews(),this.fireEvent("trackdragend"))}startTrackDrag(t){this.dragTrack=t}updateTrackDrag(t){if(t&&this.dragTrack){const e=this.dragTrack,n=this.trackViews.indexOf(t),r=this.trackViews.indexOf(e),i=this.trackViews;i[n]=e,i[r]=t;const o=this.trackViews[n].track.order;this.trackViews[r].track.order=o;const s=i.length;let a=o;if(n<r)for(let t=n+1;t<s;t++){const e=i[t].track;if(!(e.order<=a))break;e.order=Math.min(Number.MAX_SAFE_INTEGER,a+1),a=e.order}else for(let t=n-1;t>0;t--){const e=i[t].track;if(!(e.order>=a))break;e.order=Math.max(-Number.MAX_SAFE_INTEGER,a-1),a=e.order}this.reorderTracks()}}endTrackDrag(){this.dragTrack?(this.dragTrack=void 0,this.fireEvent("trackorderchanged",[this.getTrackOrder()])):this.dragTrack=void 0}addMouseHandlers(){this.addWindowResizeHandler(),this.addRootMouseUpHandler(),this.addRootMouseLeaveHandler(),this.addColumnContainerEventHandlers()}removeMouseHandlers(){this.removeWindowResizeHandler(),this.removeRootMouseUpHandler(),this.removeRootMouseLeaveHandler(),this.removeColumnContainerEventHandlers()}addWindowResizeHandler(){this.boundWindowResizeHandler=Jf.bind(this),window.addEventListener("resize",this.boundWindowResizeHandler)}removeWindowResizeHandler(){window.removeEventListener("resize",this.boundWindowResizeHandler)}addRootMouseUpHandler(){this.boundRootMouseUpHandler=ed.bind(this),this.root.addEventListener("mouseup",this.boundRootMouseUpHandler)}removeRootMouseUpHandler(){this.root.removeEventListener("mouseup",this.boundRootMouseUpHandler)}addRootMouseLeaveHandler(){this.boundRootMouseLeaveHandler=ed.bind(this),this.root.addEventListener("mouseleave",this.boundRootMouseLeaveHandler)}removeRootMouseLeaveHandler(){this.root.removeEventListener("mouseleave",this.boundRootMouseLeaveHandler)}addColumnContainerEventHandlers(){this.boundColumnContainerMouseMoveHandler=td.bind(this),this.boundColumnContainerTouchMoveHandler=td.bind(this),this.boundColumnContainerMouseLeaveHandler=ed.bind(this),this.boundColumnContainerMouseUpHandler=ed.bind(this),this.boundColumnContainerTouchEndHandler=ed.bind(this),this.columnContainer.addEventListener("mousemove",this.boundColumnContainerMouseMoveHandler),this.columnContainer.addEventListener("touchmove",this.boundColumnContainerTouchMoveHandler),this.columnContainer.addEventListener("mouseleave",this.boundColumnContainerMouseLeaveHandler),this.columnContainer.addEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.columnContainer.addEventListener("touchend",this.boundColumnContainerTouchEndHandler)}removeColumnContainerEventHandlers(){this.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler),this.columnContainer.removeEventListener("touchmove",this.boundColumnContainerTouchMoveHandler),this.columnContainer.removeEventListener("mouseleave",this.boundColumnContainerMouseLeaveHandler),this.columnContainer.removeEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.columnContainer.removeEventListener("touchend",this.boundColumnContainerTouchEndHandler)}async getDriveFileInfo(t){const e="https://www.googleapis.com/drive/v3/files/"+Ie(t)+"?supportsTeamDrives=true";return go.loadJson(e,gs({}))}static uncompressSession(t){let e;if(t.indexOf("/gzip;base64")>0){e=Yi(t);let n="";for(let t of e)n+=String.fromCharCode(t);return n}return function(t){t=t.replace(/\./g,"+").replace(/_/g,"/").replace(/-/g,"=");const e=atob(t),n=[];for(let t=0;t<e.length;t++)n.push(e.charCodeAt(t));const r=Ui.inflateRaw(n);let i="";for(let t of r)i+=String.fromCharCode(t);return i}(t.substring(5))}createCircularView(t,e){var n;return e=!0===e,this.circularView=(n=this,new $c(t,{onChordClick:(t,e,r)=>{const i=t.data,o=i.mate;function s(t){t.chr=n.genome.getChromosomeName(t.refName);let e=!1;for(let r of n.referenceFrameList){const n=Ac.fromLocusString(r.getLocusString());if(n.contains(t)){e=!0;break}if(n.overlaps(t)){r.extend(t),e=!0;break}}if(!e){const e=2e3,r=(t.start+t.end)/2;n.addMultiLocusPanel(t.chr,r-e,r+e)}}s(i),s(o)}})),this.circularViewControl=new Yf(this.$toggle_button_container.get(0),this),this.circularView.setAssembly({name:this.genome.id,id:this.genome.id,chromosomes:Jc(this.genome)}),this.circularViewVisible=e,this.circularView}get circularViewVisible(){return void 0!==this.circularView&&this.circularView.visible}set circularViewVisible(t){this.circularView&&(this.circularView.visible=t,this.circularViewControl.setState(t))}}async function Jf(){const t=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList){const n=this.referenceFrameList.indexOf(e),{chr:r,genome:i}=e,{bpLength:o}=i.getChromosome(e.chr),s=e.toBP(t);na.isWholeGenomeView(r)||s>o?e.bpPerPixel=o/t:e.end=e.start+e.toBP(t);for(let{viewports:e}of this.trackViews)e[n].setWidth(t)}this.updateUIWithReferenceFrameList(),await this.updateViews(!0)}function td(t){t.preventDefault();const{x:e,y:n}=me(t);if(this.vpMouseDown){const{viewport:t,referenceFrame:r}=this.vpMouseDown,i=Math.abs(e-this.vpMouseDown.mouseDownX)>Math.abs(n-this.vpMouseDown.mouseDownY);if(!this.dragObject&&!this.isScrolling)if(i)this.vpMouseDown.mouseDownX&&Math.abs(e-this.vpMouseDown.mouseDownX)>this.constants.dragThreshold&&(this.dragObject={viewport:t,start:r.start});else if(this.vpMouseDown.mouseDownY&&Math.abs(n-this.vpMouseDown.mouseDownY)>this.constants.scrollThreshold){this.isScrolling=!0;const e=t.$viewport.height(),n=Cl(t.trackView.viewports);this.vpMouseDown.r=e/n}if(this.dragObject){r.shiftPixels(this.vpMouseDown.lastMouseX-e,t.$viewport.width())&&this.updateViews(),this.fireEvent("trackdrag")}if(this.isScrolling){const e=this.vpMouseDown.r*(this.vpMouseDown.lastMouseY-n);t.trackView.moveScroller(e)}this.vpMouseDown.lastMouseX=e,this.vpMouseDown.lastMouseY=n}}function ed(t){this.cancelTrackPan(),this.endTrackDrag()}function nd(t,e){for(let{viewports:n}of t)for(let t of n)t.$trackLabel&&(0===n.indexOf(t)&&!0===e?t.$trackLabel.show():t.$trackLabel.hide())}let rd=[];const id=go.setApiKey;!function(){var t=document.createElement("style");t.setAttribute("type","text/css"),t.innerHTML='.igv-navbar {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n box-sizing: border-box;\n width: 100%;\n color: #444;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n line-height: 32px;\n padding-left: 8px;\n padding-right: 8px;\n margin-top: 2px;\n margin-bottom: 6px;\n height: 32px;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: #f3f3f3; }\n .igv-navbar .igv-navbar-left-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-navbar .igv-navbar-left-container .igv-logo {\n width: 34px;\n height: 32px;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-left-container .igv-current-genome {\n height: 32px;\n margin-left: 4px;\n margin-right: 4px;\n user-select: none;\n line-height: 32px;\n vertical-align: middle;\n text-align: center; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-chromosome-select-widget-container {\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center;\n height: 100%;\n width: 125px;\n margin-right: 4px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-chromosome-select-widget-container select {\n display: block;\n cursor: pointer;\n width: 100px;\n height: 75%;\n outline: none;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n margin-left: 8px;\n height: 22px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n width: 210px;\n height: 22px;\n line-height: 22px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container input.igv-search-input {\n cursor: text;\n width: 85%;\n height: 22px;\n line-height: 22px;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n text-align: left;\n padding-left: 8px;\n margin-right: 8px;\n outline: none;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: white; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container .igv-search-icon-container {\n cursor: pointer;\n height: 16px;\n width: 16px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-windowsize-panel-container {\n margin-left: 4px;\n user-select: none; }\n .igv-navbar .igv-navbar-right-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container div {\n margin-left: 0;\n margin-right: 4px; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container div:last-child {\n margin-left: 0;\n margin-right: 0; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container-750 {\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:nth-child(even) {\n display: block;\n height: fit-content; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget input {\n display: block;\n width: 125px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget svg {\n display: block; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:nth-child(even) {\n width: 0;\n height: 0;\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 input {\n width: 0;\n height: 0;\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 svg {\n display: block; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-hidden {\n display: none; }\n\n.igv-navbar-button {\n display: block;\n box-sizing: unset;\n padding-left: 6px;\n padding-right: 6px;\n height: 18px;\n text-transform: capitalize;\n user-select: none;\n line-height: 18px;\n text-align: center;\n vertical-align: middle;\n font-family: "Open Sans", sans-serif;\n font-size: 11px;\n font-weight: 200;\n color: #737373;\n background-color: #f3f3f3;\n border-color: #737373;\n border-style: solid;\n border-width: thin;\n border-radius: 6px; }\n\n.igv-navbar-button-clicked {\n color: white;\n background-color: #737373; }\n\n.igv-navbar-button:hover {\n cursor: pointer; }\n\n.igv-zoom-in-notice-container {\n z-index: 1024;\n position: absolute;\n top: 8px;\n left: 50%;\n transform: translate(-50%, 0%);\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n background-color: white; }\n .igv-zoom-in-notice-container > div {\n padding-left: 4px;\n padding-right: 4px;\n padding-top: 2px;\n padding-bottom: 2px;\n width: 100%;\n height: 100%;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #3f3f3f; }\n\n.igv-zoom-in-notice {\n position: absolute;\n top: 10px;\n left: 50%; }\n .igv-zoom-in-notice div {\n position: relative;\n left: -50%;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #3f3f3f;\n background-color: rgba(255, 255, 255, 0.51);\n z-index: 64; }\n\n.igv-container-spinner {\n position: absolute;\n top: 90%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1024;\n width: 24px;\n height: 24px;\n pointer-events: none;\n color: #737373; }\n\n.igv-multi-locus-close-button {\n position: absolute;\n top: 2px;\n right: 0;\n padding-left: 2px;\n padding-right: 2px;\n width: 18px;\n height: 18px;\n color: #666666;\n background-color: white;\n z-index: 1000; }\n .igv-multi-locus-close-button > svg {\n vertical-align: top; }\n\n.igv-multi-locus-close-button:hover {\n cursor: pointer;\n color: #434343; }\n\n.igv-multi-locus-ruler-label {\n z-index: 64;\n position: absolute;\n top: 2px;\n left: 0;\n width: 100%;\n height: 14px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center; }\n .igv-multi-locus-ruler-label div {\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #101010;\n background-color: white; }\n\n.igv-multi-locus-ruler-label-square-dot {\n z-index: 64;\n position: absolute;\n left: 50%;\n top: 5%;\n transform: translate(-50%, 0%);\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-multi-locus-ruler-label-square-dot > div:first-child {\n width: 14px;\n height: 14px; }\n .igv-multi-locus-ruler-label-square-dot > div:last-child {\n margin-left: 16px;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #101010; }\n\n.igv-multi-locus-ruler-label:hover {\n cursor: pointer; }\n\n.igv-ruler-sweeper {\n display: none;\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 100%;\n z-index: 99999;\n background-color: rgba(68, 134, 247, 0.25); }\n\n.igv-ruler-tooltip {\n pointer-events: none;\n z-index: 128;\n position: absolute;\n top: 0;\n left: 0;\n width: 1px;\n height: 32px;\n background-color: transparent;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-ruler-tooltip > div {\n pointer-events: none;\n width: 128px;\n height: auto;\n padding: 1px;\n color: #373737;\n font-size: 10px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n background-color: white;\n border-style: solid;\n border-width: thin;\n border-color: #373737; }\n\n.igv-track-label {\n position: absolute;\n left: 8px;\n top: 8px;\n width: auto;\n height: auto;\n max-width: 200px;\n padding-left: 4px;\n padding-right: 4px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n font-family: "Open Sans", sans-serif;\n font-size: small;\n font-weight: 400;\n text-align: center;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-color: #444;\n border-radius: 2px;\n border-style: solid;\n border-width: thin;\n background-color: white;\n z-index: 128;\n cursor: pointer; }\n\n.igv-track-label:hover,\n.igv-track-label:focus,\n.igv-track-label:active {\n background-color: #e8e8e8; }\n\n.igv-track-label-popup-shim {\n padding-left: 8px;\n padding-right: 8px;\n padding-top: 4px; }\n\n.igv-center-line {\n display: none;\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n transform: translateX(-50%);\n z-index: 8;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-left-style: dashed;\n border-left-width: thin;\n border-right-style: dashed;\n border-right-width: thin; }\n\n.igv-center-line-wide {\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(127, 127, 127, 0.51); }\n\n.igv-center-line-thin {\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(0, 0, 0, 0); }\n\n.igv-cursor-guide-horizontal {\n display: none;\n pointer-events: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n position: absolute;\n left: 0;\n right: 0;\n top: 50%;\n height: 1px;\n z-index: 1;\n margin-left: 50px;\n margin-right: 54px;\n border-top-style: dotted;\n border-top-width: thin;\n border-top-color: rgba(127, 127, 127, 0.76); }\n\n.igv-cursor-guide-vertical {\n pointer-events: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 50%;\n width: 1px;\n z-index: 1;\n border-left-style: dotted;\n border-left-width: thin;\n border-left-color: rgba(127, 127, 127, 0.76);\n display: none; }\n\n.igv-user-feedback {\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 512px;\n height: 360px;\n z-index: 2048;\n background-color: white;\n border-color: #a2a2a2;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #444;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-user-feedback div:first-child {\n position: relative;\n height: 24px;\n width: 100%;\n background-color: white;\n border-bottom-color: #a2a2a2;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-user-feedback div:first-child div {\n position: absolute;\n top: 2px;\n width: 16px;\n height: 16px;\n background-color: transparent; }\n .igv-user-feedback div:first-child div:first-child {\n left: 8px; }\n .igv-user-feedback div:first-child div:last-child {\n cursor: pointer;\n right: 8px; }\n .igv-user-feedback div:last-child {\n width: 100%;\n height: calc(100% - 24px);\n border-width: 0; }\n .igv-user-feedback div:last-child div {\n width: auto;\n height: auto;\n margin: 8px; }\n\n.igv-generic-dialog-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 300px;\n height: 200px;\n border-color: #7F7F7F;\n border-radius: 4px;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n z-index: 2048;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-header {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee; }\n .igv-generic-dialog-container .igv-generic-dialog-header div {\n margin-right: 4px;\n margin-bottom: 2px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-generic-dialog-container .igv-generic-dialog-header div:hover {\n cursor: pointer;\n color: #444; }\n .igv-generic-dialog-container .igv-generic-dialog-one-liner {\n color: #373737;\n width: 95%;\n height: 24px;\n line-height: 24px;\n text-align: left;\n margin-top: 8px;\n padding-left: 8px;\n overflow-wrap: break-word;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input {\n margin-top: 8px;\n width: 95%;\n height: 24px;\n color: #373737;\n line-height: 24px;\n padding-left: 8px;\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input div {\n width: 30%;\n height: 100%;\n font-size: 16px;\n text-align: right;\n padding-right: 8px;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n width: 50%;\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-input {\n margin-top: 8px;\n width: calc(100% - 16px);\n height: 24px;\n color: #373737;\n line-height: 24px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel {\n width: 100%;\n height: 28px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div {\n margin-top: 32px;\n color: white;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n width: 75px;\n height: 28px;\n line-height: 28px;\n text-align: center;\n border-color: transparent;\n border-style: solid;\n border-width: thin;\n border-radius: 2px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child {\n margin-left: 32px;\n margin-right: 0;\n background-color: #5ea4e0; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child {\n margin-left: 0;\n margin-right: 32px;\n background-color: #c4c4c4; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child:hover {\n cursor: pointer;\n background-color: #3b5c7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child:hover {\n cursor: pointer;\n background-color: #7f7f7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok {\n width: 100%;\n height: 36px;\n margin-top: 32px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div {\n width: 98px;\n height: 36px;\n line-height: 36px;\n text-align: center;\n color: white;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n border-color: white;\n border-style: solid;\n border-width: thin;\n border-radius: 4px;\n background-color: #2B81AF; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div:hover {\n cursor: pointer;\n background-color: #25597f; }\n\n.igv-generic-container {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 2048;\n background-color: white;\n cursor: pointer;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-container div:first-child {\n cursor: move;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n height: 24px;\n width: 100%;\n background-color: #dddddd; }\n .igv-generic-container div:first-child i {\n display: block;\n color: #5f5f5f;\n cursor: pointer;\n width: 14px;\n height: 14px;\n margin-right: 8px;\n margin-bottom: 4px; }\n\n.igv-menu-popup {\n position: absolute;\n top: 0;\n left: 0;\n width: max-content;\n z-index: 4096;\n cursor: pointer;\n font-family: "Open Sans", sans-serif;\n font-size: small;\n font-weight: 400;\n color: #4b4b4b;\n background: white;\n border-radius: 4px;\n border-color: #7F7F7F;\n border-style: solid;\n border-width: thin;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-end;\n text-align: left; }\n .igv-menu-popup > div:not(:first-child) {\n width: 100%; }\n .igv-menu-popup > div:not(:first-child) > div {\n background: white; }\n .igv-menu-popup > div:not(:first-child) > div.context-menu {\n padding-left: 4px;\n padding-right: 4px; }\n .igv-menu-popup > div:not(:first-child) > div:last-child {\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px;\n border-bottom-color: transparent;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-menu-popup > div:not(:first-child) > div:hover {\n background: #efefef; }\n\n.igv-menu-popup-shim {\n padding-left: 8px;\n padding-right: 8px;\n padding-bottom: 1px;\n padding-top: 1px; }\n\n.igv-menu-popup-header {\n position: relative;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-color: transparent;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-menu-popup-header div {\n margin-right: 4px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-menu-popup-header div:hover {\n cursor: pointer;\n color: #444; }\n\n.igv-menu-popup-check-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n width: 100%;\n height: 20px;\n margin-right: 4px;\n background-color: transparent; }\n .igv-menu-popup-check-container div {\n padding-top: 2px;\n padding-left: 8px; }\n .igv-menu-popup-check-container div:first-child {\n position: relative;\n width: 12px;\n height: 12px; }\n .igv-menu-popup-check-container div:first-child svg {\n position: absolute;\n width: 12px;\n height: 12px; }\n\n.igv-user-feedback {\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 512px;\n height: 360px;\n z-index: 2048;\n background-color: white;\n border-color: #a2a2a2;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #444;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-user-feedback div:first-child {\n position: relative;\n height: 24px;\n width: 100%;\n background-color: white;\n border-bottom-color: #a2a2a2;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-user-feedback div:first-child div {\n position: absolute;\n top: 2px;\n width: 16px;\n height: 16px;\n background-color: transparent; }\n .igv-user-feedback div:first-child div:first-child {\n left: 8px; }\n .igv-user-feedback div:first-child div:last-child {\n cursor: pointer;\n right: 8px; }\n .igv-user-feedback div:last-child {\n width: 100%;\n height: calc(100% - 24px);\n border-width: 0; }\n .igv-user-feedback div:last-child div {\n width: auto;\n height: auto;\n margin: 8px; }\n\n.igv-loading-spinner-container {\n z-index: 1024;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 32px;\n height: 32px;\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center; }\n .igv-loading-spinner-container > div {\n box-sizing: border-box;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n border: 4px solid rgba(128, 128, 128, 0.5);\n border-top-color: white;\n animation: spin 1s ease-in-out infinite;\n -webkit-animation: spin 1s ease-in-out infinite; }\n\n@keyframes spin {\n to {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n@-webkit-keyframes spin {\n to {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n.igv-container {\n position: relative;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n padding-top: 4px;\n user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none; }\n\n.igv-viewport {\n position: relative;\n margin-top: 5px;\n overflow-x: hidden;\n overflow-y: hidden; }\n\n.igv-viewport-content {\n position: relative;\n width: 100%; }\n .igv-viewport-content > canvas {\n position: relative;\n display: block; }\n\n.igv-column-container {\n position: relative;\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: stretch;\n width: 100%; }\n\n.igv-column-shim {\n width: 1px;\n margin-left: 2px;\n margin-right: 2px;\n background-color: #545453; }\n\n.igv-column {\n position: relative;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%; }\n\n.igv-axis-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 50px; }\n .igv-axis-column > div {\n margin-top: 5px;\n width: 100%; }\n\n.igv-sample-name-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%; }\n\n.igv-scrollbar-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 14px; }\n .igv-scrollbar-column > div {\n position: relative;\n margin-top: 5px;\n width: 14px; }\n .igv-scrollbar-column > div > div {\n cursor: pointer;\n position: absolute;\n top: 0;\n left: 2px;\n width: 8px;\n border-width: 1px;\n border-style: solid;\n border-color: #c4c4c4;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px; }\n .igv-scrollbar-column > div > div:hover {\n background-color: #c4c4c4; }\n\n.igv-track-drag-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 12px;\n background-color: white; }\n .igv-track-drag-column > .igv-track-drag-handle {\n z-index: 512;\n position: relative;\n cursor: pointer;\n margin-top: 5px;\n width: 100%;\n border-style: solid;\n border-width: 0;\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n background-color: #c4c4c4; }\n .igv-track-drag-column .igv-track-drag-handle-hover {\n background-color: #787878; }\n .igv-track-drag-column > .igv-track-drag-shim {\n position: relative;\n margin-top: 5px;\n width: 100%;\n border-style: solid;\n border-width: 0; }\n\n.igv-gear-menu-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 28px; }\n .igv-gear-menu-column > div {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n margin-top: 5px;\n width: 100%;\n background: white; }\n .igv-gear-menu-column > div > div {\n position: relative;\n margin-top: 4px;\n width: 16px;\n height: 16px;\n color: #7F7F7F; }\n .igv-gear-menu-column > div > div:hover {\n cursor: pointer;\n color: #444; }\n\n/*# sourceMappingURL=dom.css.map */\n',document.head.insertBefore(t,document.head.childNodes[document.head.childNodes.length-1])}();var od={IGVGraphics:ls,MenuUtils:Oo,DataRangeDialog:cs,createTrack:async function(t,e){return await Qf.prototype.createTrack.call(e,t)},createBrowser:async function(t,e){void 0===e&&(e={}),na.KNOWN_GENOMES||await na.initializeGenomes(e),function(t){void 0===t.minimumBases&&(t.minimumBases=40);void 0===t.showIdeogram&&(t.showIdeogram=!0);void 0===t.showCircularView&&(t.showCircularView=!1);void 0===t.showCircularViewButton&&(t.showCircularViewButton=!1);void 0===t.showTrackLabelButton&&(t.showTrackLabelButton=!0);void 0===t.showTrackLabels&&(t.showTrackLabels=!0);void 0===t.showCursorTrackingGuideButton&&(t.showCursorTrackingGuideButton=!0);void 0===t.showCursorGuide&&(t.showCursorGuide=t.showCursorTrackingGuide||!1);void 0===t.showCenterGuideButton&&(t.showCenterGuideButton=!0);void 0===t.showCenterGuide&&(t.showCenterGuide=!1);void 0===t.showSampleNames&&(t.showSampleNames=!1);void 0===t.showSVGButton&&(t.showSVGButton=!0);void 0===t.showControls&&(t.showControls=!0);void 0===t.showNavigation&&(t.showNavigation=!0);void 0===t.showRuler&&(t.showRuler=!0);void 0===t.flanking&&(t.flanking=1e3);void 0===t.pairsSupported&&(t.pairsSupported=!0);t.tracks||(t.tracks=[])}(e),e.queryParametersSupported&&function(t){var e,n,r,i,o,s,a,c,l;let h,u,f;if(a=window.location.href,o={},e=a.indexOf("?"),n=a.lastIndexOf("#"),e>=0)for(n<0&&(n=a.length),r=e+1;r<n;)(i=a.indexOf("&",r))<0&&(i=n),2===(s=a.substring(r,i).split("=",2)).length?(c=s[0],l=decodeURIComponent(s[1]),"file"===c?h=l.split(","):"index"===c?u=l.split(","):"name"===c?f=l.split(","):"genome"!==c||!l.startsWith("https://")&&!l.startsWith("http://")||l.endsWith(".json")?t[c]=l:t.reference={fastaURL:l,indexURL:l+".fai"},r=i+1):r++;if(h){t.tracks||(t.tracks=[]);for(let e=0;e<h.length;e++){if(h[e].endsWith(".xml")||h[e].endsWith(".json")){t.sessionURL=h[e];break}const n={url:h[e]};u&&u.length>e&&(n.indexURL=u[e]),f&&f.length>e&&(n.name=f[e]),t.tracks.push(n)}}}(e),e.apiKey&&go.setApiKey(e.apiKey),e.oauthToken&&ho.setToken(e.oauthToken),e.clientId&&!Oe()&&await Pe({clientId:e.clientId,apiKey:e.apiKey,scope:"https://www.googleapis.com/auth/userinfo.profile"});const n=new Qf(e,t);rd.push(n),e.sessionURL?await n.loadSession({url:e.sessionURL}):await n.loadSessionObject(e);const r=n.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(n.referenceFrameList[0].chr);return n.navbarManager.navbarDidResize(n.$navigation.width(),r),n},removeBrowser:function(t){t.dispose(),t.root.remove(),rd=rd.filter((e=>e!==t))},removeAllBrowsers:function(){for(let t of rd)t.dispose(),t.root.remove();rd=[]},visibilityChange:async function(){for(let t of rd)await t.visibilityChange()},setGoogleOauthToken:function(t){return ho.setToken(t)},setOauthToken:function(t,e){return ho.setToken(t,e)},oauth:ho,version:ta,setApiKey:id,doAutoscale:ms,TrackView:Sl};export{od as default};
71
+ */var Tc=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},Lc=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),Mc=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&a.return&&a.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};String.prototype.startsWith=String.prototype.startsWith||function(t){return 0===this.indexOf(t)},String.prototype.padStart=String.prototype.padStart||function(t,e){for(var n=this;n.length<t;)n=e+n;return n};var Rc={cb:"0f8ff",tqw:"aebd7",q:"-ffff",qmrn:"7fffd4",zr:"0ffff",bg:"5f5dc",bsq:"e4c4",bck:"---",nch:"ebcd",b:"--ff",bvt:"8a2be2",brwn:"a52a2a",brw:"deb887",ctb:"5f9ea0",hrt:"7fff-",chcT:"d2691e",cr:"7f50",rnw:"6495ed",crns:"8dc",crms:"dc143c",cn:"-ffff",Db:"--8b",Dcn:"-8b8b",Dgnr:"b8860b",Dgr:"a9a9a9",Dgrn:"-64-",Dkhk:"bdb76b",Dmgn:"8b-8b",Dvgr:"556b2f",Drng:"8c-",Drch:"9932cc",Dr:"8b--",Dsmn:"e9967a",Dsgr:"8fbc8f",DsTb:"483d8b",DsTg:"2f4f4f",Dtrq:"-ced1",Dvt:"94-d3",ppnk:"1493",pskb:"-bfff",mgr:"696969",grb:"1e90ff",rbrc:"b22222",rwht:"af0",stg:"228b22",chs:"-ff",gnsb:"dcdcdc",st:"8f8ff",g:"d7-",gnr:"daa520",gr:"808080",grn:"-8-0",grnw:"adff2f",hnw:"0fff0",htpn:"69b4",nnr:"cd5c5c",ng:"4b-82",vr:"0",khk:"0e68c",vnr:"e6e6fa",nrb:"0f5",wngr:"7cfc-",mnch:"acd",Lb:"add8e6",Lcr:"08080",Lcn:"e0ffff",Lgnr:"afad2",Lgr:"d3d3d3",Lgrn:"90ee90",Lpnk:"b6c1",Lsmn:"a07a",Lsgr:"20b2aa",Lskb:"87cefa",LsTg:"778899",Lstb:"b0c4de",Lw:"e0",m:"-ff-",mgrn:"32cd32",nn:"af0e6",mgnt:"-ff",mrn:"8--0",mqm:"66cdaa",mmb:"--cd",mmrc:"ba55d3",mmpr:"9370db",msg:"3cb371",mmsT:"7b68ee","":"-fa9a",mtr:"48d1cc",mmvt:"c71585",mnLb:"191970",ntc:"5fffa",mstr:"e4e1",mccs:"e4b5",vjw:"dead",nv:"--80",c:"df5e6",v:"808-0",vrb:"6b8e23",rng:"a5-",rngr:"45-",rch:"da70d6",pgnr:"eee8aa",pgrn:"98fb98",ptrq:"afeeee",pvtr:"db7093",ppwh:"efd5",pchp:"dab9",pr:"cd853f",pnk:"c0cb",pm:"dda0dd",pwrb:"b0e0e6",prp:"8-080",cc:"663399",r:"--",sbr:"bc8f8f",rb:"4169e1",sbrw:"8b4513",smn:"a8072",nbr:"4a460",sgrn:"2e8b57",ssh:"5ee",snn:"a0522d",svr:"c0c0c0",skb:"87ceeb",sTb:"6a5acd",sTgr:"708090",snw:"afa",n:"-ff7f",stb:"4682b4",tn:"d2b48c",t:"-8080",thst:"d8bfd8",tmT:"6347",trqs:"40e0d0",vt:"ee82ee",whT:"5deb3",wht:"",hts:"5f5f5",w:"-",wgrn:"9acd32"};function Ic(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=e>0?t.toFixed(e).replace(/0+$/,"").replace(/\.$/,""):t.toString();return n||"0"}var Nc=function(){function t(e,n,r,i){Tc(this,t);var o=this;if(void 0===e);else if(Array.isArray(e))this.rgba=e;else if(void 0===r){var s=e&&""+e;s&&function(e){if(e.startsWith("hsl")){var n=e.match(/([\-\d\.e]+)/g).map(Number),r=Mc(n,4),i=r[0],s=r[1],a=r[2],c=r[3];void 0===c&&(c=1),i/=360,s/=100,a/=100,o.hsla=[i,s,a,c]}else if(e.startsWith("rgb")){var l=e.match(/([\-\d\.e]+)/g).map(Number),h=Mc(l,4),u=h[0],f=h[1],d=h[2],p=h[3];void 0===p&&(p=1),o.rgba=[u,f,d,p]}else e.startsWith("#")?o.rgba=t.hexToRgb(e):o.rgba=t.nameToRgb(e)||t.hexToRgb(e)}(s.toLowerCase())}else this.rgba=[e,n,r,void 0===i?1:i]}return Lc(t,[{key:"printRGB",value:function(t){var e=(t?this.rgba:this.rgba.slice(0,3)).map((function(t,e){return Ic(t,3===e?3:0)}));return t?"rgba("+e+")":"rgb("+e+")"}},{key:"printHSL",value:function(t){var e=[360,100,100,1],n=["","%","%",""],r=(t?this.hsla:this.hsla.slice(0,3)).map((function(t,r){return Ic(t*e[r],3===r?3:1)+n[r]}));return t?"hsla("+r+")":"hsl("+r+")"}},{key:"printHex",value:function(t){var e=this.hex;return t?e:e.substring(0,7)}},{key:"rgba",get:function(){if(this._rgba)return this._rgba;if(!this._hsla)throw new Error("No color is set");return this._rgba=t.hslToRgb(this._hsla)},set:function(t){3===t.length&&(t[3]=1),this._rgba=t,this._hsla=null}},{key:"rgbString",get:function(){return this.printRGB()}},{key:"rgbaString",get:function(){return this.printRGB(!0)}},{key:"hsla",get:function(){if(this._hsla)return this._hsla;if(!this._rgba)throw new Error("No color is set");return this._hsla=t.rgbToHsl(this._rgba)},set:function(t){3===t.length&&(t[3]=1),this._hsla=t,this._rgba=null}},{key:"hslString",get:function(){return this.printHSL()}},{key:"hslaString",get:function(){return this.printHSL(!0)}},{key:"hex",get:function(){return"#"+this.rgba.map((function(t,e){return e<3?t.toString(16):Math.round(255*t).toString(16)})).map((function(t){return t.padStart(2,"0")})).join("")},set:function(e){this.rgba=t.hexToRgb(e)}}],[{key:"hexToRgb",value:function(t){var e=(t.startsWith("#")?t.slice(1):t).replace(/^(\w{3})$/,"$1F").replace(/^(\w)(\w)(\w)(\w)$/,"$1$1$2$2$3$3$4$4").replace(/^(\w{6})$/,"$1FF");if(!e.match(/^([0-9a-fA-F]{8})$/))throw new Error("Unknown hex color; "+t);var n=e.match(/^(\w\w)(\w\w)(\w\w)(\w\w)$/).slice(1).map((function(t){return parseInt(t,16)}));return n[3]=n[3]/255,n}},{key:"nameToRgb",value:function(e){var n=e.toLowerCase().replace("at","T").replace(/[aeiouyldf]/g,"").replace("ght","L").replace("rk","D").slice(-5,4),r=Rc[n];return void 0===r?r:t.hexToRgb(r.replace(/\-/g,"00").padStart(6,"f"))}},{key:"rgbToHsl",value:function(t){var e=Mc(t,4),n=e[0],r=e[1],i=e[2],o=e[3];n/=255,r/=255,i/=255;var s=Math.max(n,r,i),a=Math.min(n,r,i),c=void 0,l=void 0,h=(s+a)/2;if(s===a)c=l=0;else{var u=s-a;switch(l=h>.5?u/(2-s-a):u/(s+a),s){case n:c=(r-i)/u+(r<i?6:0);break;case r:c=(i-n)/u+2;break;case i:c=(n-r)/u+4}c/=6}return[c,l,h,o]}},{key:"hslToRgb",value:function(t){var e=Mc(t,4),n=e[0],r=e[1],i=e[2],o=e[3],s=void 0,a=void 0,c=void 0;if(0===r)s=a=c=i;else{var l=function(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t},h=i<.5?i*(1+r):i+r-i*r,u=2*i-h;s=l(u,h,n+1/3),a=l(u,h,n),c=l(u,h,n-1/3)}var f=[255*s,255*a,255*c].map(Math.round);return f[3]=o,f}}]),t}(),Pc=function(){function t(){Tc(this,t),this._events=[]}return Lc(t,[{key:"add",value:function(t,e,n){t.addEventListener(e,n,!1),this._events.push({target:t,type:e,handler:n})}},{key:"remove",value:function(e,n,r){this._events=this._events.filter((function(i){var o=!0;return e&&e!==i.target&&(o=!1),n&&n!==i.type&&(o=!1),r&&r!==i.handler&&(o=!1),o&&t._doRemove(i.target,i.type,i.handler),!o}))}},{key:"destroy",value:function(){this._events.forEach((function(e){return t._doRemove(e.target,e.type,e.handler)})),this._events=[]}}],[{key:"_doRemove",value:function(t,e,n){t.removeEventListener(e,n,!1)}}]),t}();function Oc(t,e,n){var r=!1;function i(t,e,n){return Math.max(e,Math.min(t,n))}function o(t,o,s){if(s&&(r=!0),r){t.preventDefault();var a=e.getBoundingClientRect(),c=a.width,l=a.height,h=o.clientX,u=o.clientY,f=i(h-a.left,0,c),d=i(u-a.top,0,l);n(f/c,d/l)}}function s(t,e){1===(void 0===t.buttons?t.which:t.buttons)?o(t,t,e):r=!1}function a(t,e){1===t.touches.length?o(t,t.touches[0],e):r=!1}t.add(e,"mousedown",(function(t){s(t,!0)})),t.add(e,"touchstart",(function(t){a(t,!0)})),t.add(window,"mousemove",s),t.add(e,"touchmove",a),t.add(window,"mouseup",(function(t){r=!1})),t.add(e,"touchend",(function(t){r=!1})),t.add(e,"touchcancel",(function(t){r=!1}))}function Fc(t,e){return(e||document).querySelector(t)}function Dc(t){t.preventDefault(),t.stopPropagation()}function Bc(t,e,n,r,i){t.add(e,"keydown",(function(t){n.indexOf(t.key)>=0&&(i&&Dc(t),r(t))}))}var zc=function(){function t(e){Tc(this,t),this.settings={popup:"right",layout:"default",alpha:!0,editor:!0,editorFormat:"hex",cancelButton:!1,defaultColor:"#0cf"},this._events=new Pc,this.onChange=null,this.onDone=null,this.onOpen=null,this.onClose=null,this.setOptions(e)}return Lc(t,[{key:"setOptions",value:function(t){var e=this;if(t){var n=this.settings;if(t instanceof HTMLElement)n.parent=t;else{n.parent&&t.parent&&n.parent!==t.parent&&(this._events.remove(n.parent),this._popupInited=!1),function(t,e,n){for(var r in t)n&&n.indexOf(r)>=0||(e[r]=t[r])}(t,n),t.onChange&&(this.onChange=t.onChange),t.onDone&&(this.onDone=t.onDone),t.onOpen&&(this.onOpen=t.onOpen),t.onClose&&(this.onClose=t.onClose);var r=t.color||t.colour;r&&this._setColor(r)}var i=n.parent;if(i&&n.popup&&!this._popupInited){var o=function(t){return e.openHandler(t)};this._events.add(i,"click",o),Bc(this._events,i,[" ","Spacebar","Enter"],o),this._popupInited=!0}else t.parent&&!n.popup&&this.show()}}},{key:"openHandler",value:function(t){if(this.show()){t&&t.preventDefault(),this.settings.parent.style.pointerEvents="none";var e=t&&"keydown"===t.type?this._domEdit:this.domElement;setTimeout((function(){return e.focus()}),100),this.onOpen&&this.onOpen(this.colour)}}},{key:"closeHandler",value:function(t){var e=t&&t.type,n=!1;if(t)if("mousedown"===e||"focusin"===e){var r=(this.__containedEvent||0)+100;t.timeStamp>r&&(n=!0)}else Dc(t),n=!0;else n=!0;n&&this.hide()&&(this.settings.parent.style.pointerEvents="","mousedown"!==e&&this.settings.parent.focus(),this.onClose&&this.onClose(this.colour))}},{key:"movePopup",value:function(t,e){this.closeHandler(),this.setOptions(t),e&&this.openHandler()}},{key:"setColor",value:function(t,e){this._setColor(t,{silent:e})}},{key:"_setColor",value:function(t,e){if("string"==typeof t&&(t=t.trim()),t){e=e||{};var n=void 0;try{n=new Nc(t)}catch(t){if(e.failSilently)return;throw t}if(!this.settings.alpha){var r=n.hsla;r[3]=1,n.hsla=r}this.colour=this.color=n,this._setHSLA(null,null,null,null,e)}}},{key:"setColour",value:function(t,e){this.setColor(t,e)}},{key:"show",value:function(){if(!this.settings.parent)return!1;if(this.domElement){var t=this._toggleDOM(!0);return this._setPosition(),t}var e=function(t){var e=document.createElement("div");return e.innerHTML=t,e.firstElementChild}(this.settings.template||'<div class="picker_wrapper" tabindex="-1"><div class="picker_arrow"></div><div class="picker_hue picker_slider"><div class="picker_selector"></div></div><div class="picker_sl"><div class="picker_selector"></div></div><div class="picker_alpha picker_slider"><div class="picker_selector"></div></div><div class="picker_editor"><input aria-label="Type a color name or hex value"/></div><div class="picker_sample"></div><div class="picker_done"><button>Ok</button></div><div class="picker_cancel"><button>Cancel</button></div></div>');return this.domElement=e,this._domH=Fc(".picker_hue",e),this._domSL=Fc(".picker_sl",e),this._domA=Fc(".picker_alpha",e),this._domEdit=Fc(".picker_editor input",e),this._domSample=Fc(".picker_sample",e),this._domOkay=Fc(".picker_done button",e),this._domCancel=Fc(".picker_cancel button",e),e.classList.add("layout_"+this.settings.layout),this.settings.alpha||e.classList.add("no_alpha"),this.settings.editor||e.classList.add("no_editor"),this.settings.cancelButton||e.classList.add("no_cancel"),this._ifPopup((function(){return e.classList.add("popup")})),this._setPosition(),this.colour?this._updateUI():this._setColor(this.settings.defaultColor),this._bindEvents(),!0}},{key:"hide",value:function(){return this._toggleDOM(!1)}},{key:"destroy",value:function(){this._events.destroy(),this.domElement&&this.settings.parent.removeChild(this.domElement)}},{key:"_bindEvents",value:function(){var t=this,e=this,n=this.domElement,r=this._events;function i(t,e,n){r.add(t,e,n)}i(n,"click",(function(t){return t.preventDefault()})),Oc(r,this._domH,(function(t,n){return e._setHSLA(t)})),Oc(r,this._domSL,(function(t,n){return e._setHSLA(null,t,1-n)})),this.settings.alpha&&Oc(r,this._domA,(function(t,n){return e._setHSLA(null,null,null,1-n)}));var o=this._domEdit;i(o,"input",(function(t){e._setColor(this.value,{fromEditor:!0,failSilently:!0})})),i(o,"focus",(function(t){var e=this;e.selectionStart===e.selectionEnd&&e.select()})),this._ifPopup((function(){var e=function(e){return t.closeHandler(e)};i(window,"mousedown",e),i(window,"focusin",e),Bc(r,n,["Esc","Escape"],e);var o=function(e){t.__containedEvent=e.timeStamp};i(n,"mousedown",o),i(n,"focusin",o),i(t._domCancel,"click",e)}));var s=function(e){t._ifPopup((function(){return t.closeHandler(e)})),t.onDone&&t.onDone(t.colour)};i(this._domOkay,"click",s),Bc(r,n,["Enter"],s)}},{key:"_setPosition",value:function(){var t=this.settings.parent,e=this.domElement;t!==e.parentNode&&t.appendChild(e),this._ifPopup((function(n){"static"===getComputedStyle(t).position&&(t.style.position="relative");var r=!0===n?"popup_right":"popup_"+n;["popup_top","popup_bottom","popup_left","popup_right"].forEach((function(t){t===r?e.classList.add(t):e.classList.remove(t)})),e.classList.add(r)}))}},{key:"_setHSLA",value:function(t,e,n,r,i){i=i||{};var o=this.colour,s=o.hsla;[t,e,n,r].forEach((function(t,e){(t||0===t)&&(s[e]=t)})),o.hsla=s,this._updateUI(i),this.onChange&&!i.silent&&this.onChange(o)}},{key:"_updateUI",value:function(t){if(this.domElement){t=t||{};var e=this.colour,n=e.hsla,r="hsl("+360*n[0]+", 100%, 50%)",i=e.hslString,o=e.hslaString,s=this._domH,a=this._domSL,c=this._domA,l=Fc(".picker_selector",s),h=Fc(".picker_selector",a),u=Fc(".picker_selector",c);b(0,l,n[0]),this._domSL.style.backgroundColor=this._domH.style.color=r,b(0,h,n[1]),w(0,h,1-n[2]),a.style.color=i,w(0,u,1-n[3]);var f=i,d=f.replace("hsl","hsla").replace(")",", 0)"),p="linear-gradient("+[f,d]+")";if(this._domA.style.background=p+", linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0 / 2em 2em,\n linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em / 2em 2em",!t.fromEditor){var g=this.settings.editorFormat,m=this.settings.alpha,v=void 0;switch(g){case"rgb":v=e.printRGB(m);break;case"hsl":v=e.printHSL(m);break;default:v=e.printHex(m)}this._domEdit.value=v}this._domSample.style.color=o}function b(t,e,n){e.style.left=100*n+"%"}function w(t,e,n){e.style.top=100*n+"%"}}},{key:"_ifPopup",value:function(t,e){this.settings.parent&&this.settings.popup?t&&t(this.settings.popup):e&&e()}},{key:"_toggleDOM",value:function(t){var e=this.domElement;if(!e)return!1;var n=t?"":"none",r=e.style.display!==n;return r&&(e.style.display=n),r}}]),t}(),Hc=document.createElement("style");function Vc(t){if(jc[t])return jc[t];if(jc["chr"+t]){const e=jc["chr"+t];return jc[t]=e,e}{const i=(e=Math.round(255*Math.random()).toString(10),n=Math.round(255*Math.random()).toString(10),r=Math.round(255*Math.random()).toString(10),"rgb("+e+","+n+","+r+")");return jc[t]=i,i}var e,n,r}Hc.textContent='.picker_wrapper.no_alpha .picker_alpha{display:none}.picker_wrapper.no_editor .picker_editor{position:absolute;z-index:-1;opacity:0}.picker_wrapper.no_cancel .picker_cancel{display:none}.layout_default.picker_wrapper{display:flex;flex-flow:row wrap;justify-content:space-between;align-items:stretch;font-size:10px;width:25em;padding:.5em}.layout_default.picker_wrapper input,.layout_default.picker_wrapper button{font-size:1rem}.layout_default.picker_wrapper>*{margin:.5em}.layout_default.picker_wrapper::before{content:"";display:block;width:100%;height:0;order:1}.layout_default .picker_slider,.layout_default .picker_selector{padding:1em}.layout_default .picker_hue{width:100%}.layout_default .picker_sl{flex:1 1 auto}.layout_default .picker_sl::before{content:"";display:block;padding-bottom:100%}.layout_default .picker_editor{order:1;width:6.5rem}.layout_default .picker_editor input{width:100%;height:100%}.layout_default .picker_sample{order:1;flex:1 1 auto}.layout_default .picker_done,.layout_default .picker_cancel{order:1}.picker_wrapper{box-sizing:border-box;background:#f2f2f2;box-shadow:0 0 0 1px silver;cursor:default;font-family:sans-serif;color:#444;pointer-events:auto}.picker_wrapper:focus{outline:none}.picker_wrapper button,.picker_wrapper input{box-sizing:border-box;border:none;box-shadow:0 0 0 1px silver;outline:none}.picker_wrapper button:focus,.picker_wrapper button:active,.picker_wrapper input:focus,.picker_wrapper input:active{box-shadow:0 0 2px 1px #1e90ff}.picker_wrapper button{padding:.4em .6em;cursor:pointer;background-color:#f5f5f5;background-image:linear-gradient(0deg, gainsboro, transparent)}.picker_wrapper button:active{background-image:linear-gradient(0deg, transparent, gainsboro)}.picker_wrapper button:hover{background-color:#fff}.picker_selector{position:absolute;z-index:1;display:block;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%);border:2px solid #fff;border-radius:100%;box-shadow:0 0 3px 1px #67b9ff;background:currentColor;cursor:pointer}.picker_slider .picker_selector{border-radius:2px}.picker_hue{position:relative;background-image:linear-gradient(90deg, red, yellow, lime, cyan, blue, magenta, red);box-shadow:0 0 0 1px silver}.picker_sl{position:relative;box-shadow:0 0 0 1px silver;background-image:linear-gradient(180deg, white, rgba(255, 255, 255, 0) 50%),linear-gradient(0deg, black, rgba(0, 0, 0, 0) 50%),linear-gradient(90deg, #808080, rgba(128, 128, 128, 0))}.picker_alpha,.picker_sample{position:relative;background:linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0/2em 2em,linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em/2em 2em;box-shadow:0 0 0 1px silver}.picker_alpha .picker_selector,.picker_sample .picker_selector{background:none}.picker_editor input{font-family:monospace;padding:.2em .4em}.picker_sample::before{content:"";position:absolute;display:block;width:100%;height:100%;background:currentColor}.picker_arrow{position:absolute;z-index:-1}.picker_wrapper.popup{position:absolute;z-index:2;margin:1.5em}.picker_wrapper.popup,.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{background:#f2f2f2;box-shadow:0 0 10px 1px rgba(0,0,0,.4)}.picker_wrapper.popup .picker_arrow{width:3em;height:3em;margin:0}.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{content:"";display:block;position:absolute;top:0;left:0;z-index:-99}.picker_wrapper.popup .picker_arrow::before{width:100%;height:100%;-webkit-transform:skew(45deg);transform:skew(45deg);-webkit-transform-origin:0 100%;transform-origin:0 100%}.picker_wrapper.popup .picker_arrow::after{width:150%;height:150%;box-shadow:none}.popup.popup_top{bottom:100%;left:0}.popup.popup_top .picker_arrow{bottom:0;left:0;-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.popup.popup_bottom{top:100%;left:0}.popup.popup_bottom .picker_arrow{top:0;left:0;-webkit-transform:rotate(90deg) scale(1, -1);transform:rotate(90deg) scale(1, -1)}.popup.popup_left{top:0;right:100%}.popup.popup_left .picker_arrow{top:0;right:0;-webkit-transform:scale(-1, 1);transform:scale(-1, 1)}.popup.popup_right{top:0;left:100%}.popup.popup_right .picker_arrow{top:0;left:0}',document.documentElement.firstElementChild.appendChild(Hc),zc.StyleElement=Hc;const jc={chrX:"rgb(204, 153, 0)",chrY:"rgb(153, 204, 0",chrUn:"rgb(50, 50, 50)",chr1:"rgb(80, 80, 255)",chrI:"rgb(139, 155, 187)",chr2:"rgb(206, 61, 50)",chrII:"rgb(206, 61, 50)",chr2a:"rgb(216, 71, 60)",chr2b:"rgb(226, 81, 70)",chr3:"rgb(116, 155, 88)",chrIII:"rgb(116, 155, 88)",chr4:"rgb(240, 230, 133)",chrIV:"rgb(240, 230, 133)",chr5:"rgb(70, 105, 131)",chr6:"rgb(186, 99, 56)",chr7:"rgb(93, 177, 221)",chr8:"rgb(128, 34, 104)",chr9:"rgb(107, 215, 107)",chr10:"rgb(213, 149, 167)",chr11:"rgb(146, 72, 34)",chr12:"rgb(131, 123, 141)",chr13:"rgb(199, 81, 39)",chr14:"rgb(213, 143, 92)",chr15:"rgb(122, 101, 165)",chr16:"rgb(228, 175, 105)",chr17:"rgb(59, 27, 83)",chr18:"rgb(205, 222, 183)",chr19:"rgb(97, 42, 121)",chr20:"rgb(174, 31, 99)",chr21:"rgb(231, 199, 111)",chr22:"rgb(90, 101, 94)",chr23:"rgb(204, 153, 0)",chr24:"rgb(153, 204, 0)",chr25:"rgb(51, 204, 0)",chr26:"rgb(0, 204, 51)",chr27:"rgb(0, 204, 153)",chr28:"rgb(0, 153, 204)",chr29:"rgb(10, 71, 255)",chr30:"rgb(71, 117, 255)",chr31:"rgb(255, 194, 10)",chr32:"rgb(255, 209, 71)",chr33:"rgb(153, 0, 51)",chr34:"rgb(153, 26, 0)",chr35:"rgb(153, 102, 0)",chr36:"rgb(128, 153, 0)",chr37:"rgb(51, 153, 0)",chr38:"rgb(0, 153, 26)",chr39:"rgb(0, 153, 102)",chr40:"rgb(0, 128, 153)",chr41:"rgb(0, 51, 153)",chr42:"rgb(26, 0, 153)",chr43:"rgb(102, 0, 153)",chr44:"rgb(153, 0, 128)",chr45:"rgb(214, 0, 71)",chr46:"rgb(255, 20, 99)",chr47:"rgb(0, 214, 143)",chr48:"rgb(20, 255, 177)"};class Uc{constructor(t){this.tracks=[],this.chordSets=[]}addChordSet(t){this.chordSets=this.chordSets.filter((e=>e.name!==t.name)),this.chordSets.push(t);let e=this.tracks.find((e=>t.trackName===e.name));e&&(e.chordSets=e.chordSets.filter((e=>e.name!==t.name)),e.chordSets.push(t)),e||(e=new qc(t),this.tracks.push(e))}clearChords(){this.tracks=[],this.chordSets=[]}getTrack(t){return this.tracks.find((e=>t===e.name))}getChordSet(t){return this.chordSets.find((e=>t===e.name))}}class qc{constructor(t){this.name=t.trackName,this.color=t.trackColor,this.visible=!0,this.chordSets=[t],this.id=("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}get chords(){if(1===this.chordSets.length)return this.chordSets[0].chords;const t=[];for(let e of this.chordSets)for(let n of e.chords)t.push(n);return t}}const Wc=Math.exp(5);class $c{static isInstalled(){return void 0!==window.JBrowseReactCircularGenomeView&&void 0!==window.React&&void 0!==window.ReactDOM}constructor(t,e){if(e=e||{},this.config=e,$c.isInstalled()){this.parent=t,this.groupByTrack=!0===e.groupByTrack,this.chordManager=new Uc(e);const n=document.createElement("div");n.className="igv-circview-container",t.appendChild(n),this.createControls(n),this.resetControlPanel();const r=document.createElement("div");r.className="igv-circview-circular-genome-view",n.appendChild(r),this.container=r,e.assembly&&this.setAssembly(e.assembly),this.width=e.width||500,this.height=e.height||500,this.setSize(this.width,this.height)}else console.error("JBrowse circular view is not installed")}createControls(t){const e=document.createElement("div");e.className="igv-circview-toolbar",t.appendChild(e),this.toolbar=e;const n=document.createElement("div");n.className="igv-circview-track-panel",t.appendChild(n),this.controlPanel=n,this.controlPanel.style.display="none";const r=document.createElement("div");r.className="igv-circview-toolbar-button-container",this.toolbar.appendChild(r),this.showControlsButton=document.createElement("div"),this.showControlsButton.className="igv-circview-button",r.appendChild(this.showControlsButton),this.showControlsButton.innerText="none"===this.controlPanel.style.display?"Show Controls":"Hide Controls",this.showControlsButton.addEventListener("click",(t=>{this.controlPanel.querySelectorAll("div").length>0&&("none"===this.controlPanel.style.display?(this.controlPanel.style.display="flex",t.target.innerText="Hide Controls"):(this.controlPanel.style.display="none",t.target.innerText="Show Controls"))}));let i=document.createElement("div");i.className="igv-circview-button",r.appendChild(i),i.innerText="Clear All",i.addEventListener("click",(()=>{this.clearChords()})),!1!==this.config.showCloseButton&&(i=document.createElement("div"),i.className="igv-circview-button",r.appendChild(i),i.innerText="Close",i.addEventListener("click",(()=>{this.visible=!1})))}resetControlPanel(){this.controlPanel.innerHTML="",this.controlPanel.appendChild(this.createGroupByCB());const t=this.groupByTrack?this.chordManager.tracks:this.chordManager.chordSets;for(let e of t)this.addToControlPanel(e)}createGroupByCB(){const t=document.createElement("input");t.type="checkbox",t.id="groupByCB",t.style.width="1.4em",t.style.height="1.4em",t.checked=this.groupByTrack,t.onclick=t=>{this.groupByTrack=t.target.checked,this.resetControlPanel(),this.render()};const e=document.createElement("label");e.for="groupByCB",e.innerText="Group by track",e.style.color="black",e.style.paddingLeft="10px";const n=document.createElement("div");return n.style.width="100%",n.style.paddingTop="5px",n.style.paddingBottom="5px",n.style.background="rgb(216, 230, 234)",n.appendChild(t),n.appendChild(e),n}addToControlPanel(t){const e=document.createElement("div");this.controlPanel.appendChild(e);const n=document.createElement("div");n.className="igv-circview-button",e.appendChild(n),n.innerText=!0===t.visible?"Hide":"Show",n.addEventListener("click",(e=>{!0===t.visible?(this.hideChordSet(t.name),e.target.innerText="Show"):(this.showChordSet(t.name),e.target.innerText="Hide")}));const r=document.createElement("input"),i=t=>200*Math.log(t*Wc),o=document.createElement("div");o.className="igv-circview-button",o.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;",e.appendChild(o),o.style.backgroundColor=Gc(t.color,1);const s={parent:o,popup:"right",editorFormat:"rgb",color:t.color,onChange:({rgbaString:e})=>{o.style.backgroundColor=Gc(e,1),this.setColor(t.name,e),r.value=i(Zc(t.color))}},a=new zc(s);r.setAttribute("title","Adjust transparency of arcs"),r.type="range",r.style.width="100px",r.style.marginRight="10px",r.setAttribute("class","range"),r.setAttribute("min","0"),r.setAttribute("max","1000"),r.value=i(Zc(t.color)),r.oninput=()=>{const e=(n=r.value,Math.exp(n/200)/Wc);var n;this.setColor(t.name,Gc(t.color,e)),a.setColor(t.color)},e.appendChild(r);const c=document.createElement("div");c.style.color="black",e.appendChild(c),c.innerText=c.title=t.name}setAssembly(t){const e=this.genomeId||Kc();if(this.genomeId===e)return;this.chordManager.clearChords(),this.genomeId=e,this.chrNames=new Set(t.chromosomes.map((t=>Xc(t.name))));const n=[],r=[];for(let e of t.chromosomes){const t=Xc(e.name);r.push(e.color||Vc(t)),n.push({refName:t,uniqueId:t,start:0,end:e.bpLength})}this.assembly={name:t.name,sequence:{trackId:e,type:"ReferenceSequenceTrack",adapter:{type:"FromConfigSequenceAdapter",features:n}},refNameColors:r},this.render()}addChords(t,e={}){const n=e.name||e.track||"*",r=n.split(" ")[0].replaceAll("%20"," "),i={name:n.replaceAll("%20"," "),trackName:r,chords:t,color:e.color||"black",trackColor:e.trackColor||e.color||"black",visible:!0,id:e.id||Kc()};this.chordManager.addChordSet(i),this.resetControlPanel(),this.render()}setSize(t,e){if(e=e||t,this.width=t,this.height=e,this.viewState){const n=this.viewState.session.view;n.setWidth(t),n.setHeight(e),n.setBpPerPx(n.minBpPerPx)}}getSize(){return Math.min(this.width,this.height)}clearChords(){this.chordManager.clearChords(),this.resetControlPanel(),this.render()}clearSelection(){this.viewState.pluginManager.rootModel.session.clearSelection()}show(){this.parent.style.display="block"}hide(){this.parent.style.display="none"}get visible(){return"none"!==this.parent.style.display}set visible(t){this.parent.style.display=t?"block":"none"}hideChordSet(t){let e=this.getChordSet(t);e?(e.visible=!1,this.render()):console.warn(`No track with name: ${name}`)}showChordSet(t){let e=this.getChordSet(t);e?(e.visible=!0,this.render()):console.warn(`No track with name: ${t}`)}deleteTrack(t){let e=this.tracks.findIndex((e=>t===e.name));e>=0&&this.tracks.splice(e,1),this.render()}getChordSet(t){return this.groupByTrack?this.chordManager.getTrack(t):this.chordManager.getChordSet(t)}setColor(t,e){const n=this.getChordSet(t);if(n){n.color=e;const t=n.id;for(let n of this.viewState.config.tracks)if(t===n.trackId){n.displays[0].renderer.strokeColor.set(e);break}}}render(){const{createViewState:t,JBrowseCircularGenomeView:e}=JBrowseReactCircularGenomeView;ReactDOM.unmountComponentAtNode(this.container);const n=(this.groupByTrack?this.chordManager.tracks:this.chordManager.chordSets).filter((t=>t.visible)),r=[],i=[];for(let t of n)r.push({trackId:t.id,name:t.name,assemblyNames:["forIGV"],type:"VariantTrack",adapter:{type:"FromConfigAdapter",features:t.chords}}),i.push(t.color);this.viewState=t({assembly:this.assembly,tracks:r});for(let t=0;t<n.length;t++)this.viewState.config.tracks[t].displays[0].renderer.strokeColor.set(i[t]);this.element=React.createElement(e,{viewState:this.viewState}),this.setSize(this.width,this.height),ReactDOM.render(this.element,this.container);const o=this.config.onChordClick||Yc;for(let t=0;t<n.length;t++)this.viewState.session.view.showTrack(this.viewState.config.tracks[t].trackId),o&&(this.viewState.pluginManager.jexl.addFunction("onChordClick",o),this.viewState.config.tracks[t].displays[0].onChordClick.set("jexl:onChordClick(feature, track, pluginManager)"))}}function Gc(t,e){const[n,r,i,o]=t.split(",");return`${n},${r},${i},${e})`}function Zc(t){return t.startsWith("rgba(")?Number(t.split(",")[3].replace(")","")):1}function Xc(t){return t.startsWith("chr")?t.substring(3):t}function Yc(t,e,n){console.log(t)}function Kc(){return("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}if("undefined"!=typeof document){function as(t){for(let e of document.styleSheets)if(e=e.href?e.href.replace(/^.*[\\\/]/,""):"",e===t)return!0;return!1}as("circular-view.css")||function(){const t=document.createElement("style");t.setAttribute("type","text/css"),t.innerHTML='.igv-circview-container {\n z-index: 2048;\n width: fit-content;\n height: fit-content;\n box-sizing: content-box;\n color: dimgray;\n font-family: "Open Sans", sans-serif;\n font-size: 12px;\n background-color: white;\n border-color: dimgray;\n border-style: solid;\n border-width: thin;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n}\n\n.igv-circview-toolbar {\n position: relative;\n width: 100%;\n height: 32px;\n background-color: lightgrey;\n border-bottom-style: solid;\n border-bottom-color: dimgray;\n border-bottom-width: thin;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n}\n\n.igv-circview-toolbar-button-container {\n height: 100%;\n width: fit-content;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n}\n.igv-circview-toolbar-button-container > div {\n margin: 4px;\n}\n\n.igv-circview-track-panel {\n z-index: 1024;\n position: absolute;\n top: 33px;\n left: 0;\n width: 100%;\n height: fit-content;\n border-bottom-style: solid;\n border-bottom-color: dimgray;\n border-bottom-width: thin;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n}\n.igv-circview-track-panel > div {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n}\n.igv-circview-track-panel > div > div {\n margin: 4px;\n}\n\n.igv-circview-swatch-button {\n cursor: pointer;\n padding: 5px;\n width: 8px;\n height: 8px;\n border: 1px solid #8d8b8b;\n border-radius: 16px;\n}\n\n.igv-circview-button {\n cursor: pointer;\n padding: 5px;\n color: #444;\n vertical-align: middle;\n text-align: center;\n font-family: "Open Sans", sans-serif;\n font-size: 12px;\n border: 1px solid #8d8b8b;\n border-radius: 4px;\n background: #efefef;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.2);\n}\n\n.igv-circview-button:hover {\n background: #efefef;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.6);\n}\n\n.igv-circview-button:active {\n color: #007bff;\n box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.6);\n}\n\n/*# sourceMappingURL=circular-view.css.map */\n',document.head.insertBefore(t,document.head.childNodes[document.head.childNodes.length-1])}()}const Qc=t=>t.startsWith("chr")?t.substring(3):t;function Jc(t){const e=[],n=[];for(let r of t.wgChromosomeNames){const i=t.getChromosome(r);n.push(ll(i.name)),e.push({name:i.name,bpLength:i.bpLength})}return e}function tl(t,e,n,r){const i=no.addAlpha("all"===n.chr?e.color:ll(n.chr),r),o=no.addAlpha(e.color||"rgb(0,0,255)",r),s=e.name.replaceAll(" ","%20"),a="all"===n.chr?s:`${s} ${n.chr}:${n.start}-${n.end}`;e.browser.circularView.addChords(t,{track:a,color:i,trackColor:o}),e.browser.circularViewVisible||(e.browser.circularViewVisible=!0)}class el{constructor(t,{minTLENPercentile:e,maxTLENPercentile:n}){this.totalCount=0,this.frCount=0,this.rfCount=0,this.ffCount=0,this.sumF=0,this.sumF2=0,this.lp=void 0===e?.1:e,this.up=void 0===n?99.5:n,this.isizes=[],this.compute(t)}compute(t){for(let r of t)if(r.isProperPair()){var e=Math.abs(r.fragmentLength);this.sumF+=e,this.sumF2+=e*e,this.isizes.push(e);var n=r.pairOrientation;if("string"==typeof n&&4===n.length)switch(""+n.charAt(0)+n.charAt(2)){case"FF":case"RR":this.ffCount++;break;case"FR":this.frCount++;break;case"RF":this.rfCount++}this.totalCount++}this.ffCount/this.totalCount>.9?this.orienation="ff":this.frCount/this.totalCount>.9?this.orienation="fr":this.rfCount/this.totalCount>.9&&(this.orienation="rf"),this.minTLEN=0===this.lp?0:nl(this.isizes,this.lp),this.maxTLEN=nl(this.isizes,this.up)}}function nl(t,e){if(0!==t.length){var n=Math.floor(t.length*(e/100));return t.sort((function(t,e){return t-e})),t[n]}}class rl extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type="alignment",void 0===t.alleleFreqThreshold&&(t.alleleFreqThreshold=.2),this.featureSource=new mc(t,this.browser),this.showCoverage=void 0===t.showCoverage||t.showCoverage,this.showAlignments=void 0===t.showAlignments||t.showAlignments,this.coverageTrack=new il(t,this),this.alignmentTrack=new ol(t,this),this.alignmentTrack.setTop(this.coverageTrack,this.showCoverage),this.visibilityWindow=t.visibilityWindow||3e4,this.viewAsPairs=t.viewAsPairs,this.pairsSupported=!1!==t.pairsSupported,this.showSoftClips=t.showSoftClips,this.showAllBases=t.showAllBases,this.showInsertions=!1!==t.showInsertions,this.showMismatches=!1!==t.showMismatches,this.color=t.color,this.coverageColor=t.coverageColor,t.sort&&(Array.isArray(t.sort)?this.assignSort(t.sort[0]):this.assignSort(t.sort)),this.height=void 0!==t.height?t.height:300}set height(t){this._height=t,this.coverageTrack&&this.showAlignments&&(this.alignmentTrack.height=this.showCoverage?t-this.coverageTrack.height:t)}get height(){return this._height}get minTemplateLength(){const t=void 0!==this.config.minTLEN?this.config.minTLEN:this.config.minFragmentLength;return void 0!==t?t:this._pairedEndStats?this._pairedEndStats.minTLEN:0}get maxTemplateLength(){const t=void 0!==this.config.maxTLEN?this.config.maxTLEN:this.config.maxFragmentLength;return void 0!==t?t:this._pairedEndStats?this._pairedEndStats.maxTLEN:1e3}sort(t){t=this.assignSort(t);for(let e of this.trackView.viewports)if(e.containsPosition(t.chr,t.position)){const n=e.cachedFeatures;n&&(sl(t,n),e.repaint())}}assignSort(t){if(t.locus){const e=function(t){const e=t.split(":"),n=e[1].split("-"),r={chr:e[0],start:Number.parseInt(n[0].replace(/,/g,""))-1};return n.length>1?r.end=Number.parseInt(n[1].replace(/,/g,"")):r.end=r.start+1,r}(t.locus);t.chr=e.chr,t.position=e.start}else t.position--;return t.direction="ASC"===t.direction||!0===t.direction,t.chr=this.browser.genome.getChromosomeName(t.chr),this.sortObject=t,this.sortObject}async getFeatures(t,e,n,r,i){const o=await this.featureSource.getAlignments(t,e,n);if(o.paired&&!this._pairedEndStats&&!this.config.maxFragmentLength){const t=new el(o.alignments,this.config);t.totalCount>99&&(this._pairedEndStats=t)}o.alignments=void 0;const s=this.sortObject;return s&&s.chr===t&&s.position>=e&&s.position<=n&&sl(s,o),o}computePixelHeight(t){return(this.showCoverage?this.coverageTrack.height:0)+(this.showAlignments?this.alignmentTrack.computePixelHeight(t):0)+15}draw(t){ls.fillRect(t.context,0,t.pixelTop,t.pixelWidth,t.pixelHeight,{fillStyle:"rgb(255, 255, 255)"}),!0===this.showCoverage&&this.coverageTrack.height>0?(this.trackView.axisCanvas.style.display="block",this.coverageTrack.draw(t)):this.trackView.axisCanvas.style.display="none",!0===this.showAlignments&&(this.alignmentTrack.setTop(this.coverageTrack,this.showCoverage),this.alignmentTrack.draw(t))}paintAxis(t,e,n){this.coverageTrack.paintAxis(t,e,this.coverageTrack.height)}contextMenuItemList(t){return this.alignmentTrack.contextMenuItemList(t)}popupData(t){return!0===this.showCoverage&&t.y>=this.coverageTrack.top&&t.y<this.coverageTrack.height?this.coverageTrack.popupData(t):this.alignmentTrack.popupData(t)}clickedFeatures(t){return!0===this.showCoverage&&t.y>=this.coverageTrack.top&&t.y<this.coverageTrack.height?[this.coverageTrack.getClickedObject(t)]:[this.alignmentTrack.getClickedObject(t)]}menuItemList(){let t=[];t=t.concat(Oo.numericDataMenuItems(this.trackView)),t.push("<hr/>");const e=de('<div class="igv-track-menu-category">');e.text("Color by:"),t.push({name:void 0,object:e,click:void 0,init:void 0});const n=[{key:"strand",label:"read strand"}];this.alignmentTrack.hasPairs&&(n.push({key:"firstOfPairStrand",label:"first-of-pair strand"}),n.push({key:"pairOrientation",label:"pair orientation"}),n.push({key:"tlen",label:"insert size (TLEN)"}),n.push({key:"unexpectedPair",label:"pair orientation & insert size (TLEN)"}));const r="tag"+(this.alignmentTrack.colorByTag?" ("+this.alignmentTrack.colorByTag+")":"");n.push({key:"tag",label:r});for(let e of n){const n=this.alignmentTrack.colorBy===e.key;t.push(this.colorByCB(e,n))}const i=()=>{if(!this.autoHeight){const t=15+(this.showCoverage?this.coverageTrack.height:0)+(this.showAlignments?this.alignmentTrack.height:0);this.trackView.setTrackHeight(t)}};t.push("<hr/>"),t.push({object:de(Po("Show Coverage",this.showCoverage)),click:()=>{this.showCoverage=!this.showCoverage,i(),this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push({object:de(Po("Show Alignments",this.showAlignments)),click:()=>{this.showAlignments=!this.showAlignments,i(),this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push("<hr/>"),t.push({object:de(Po("Show all bases",this.showAllBases)),click:()=>{this.showAllBases=!this.showAllBases,this.config.showAllBases=this.showAllBases,this.trackView.repaintViews()}}),t.push("<hr/>"),t.push({object:de(Po("Show mismatches",this.showMismatches)),click:()=>{this.showMismatches=!this.showMismatches,this.config.showMismatches=this.showMismatches,this.trackView.repaintViews()}}),t.push({object:de(Po("Show insertions",this.showInsertions)),click:()=>{this.showInsertions=!this.showInsertions,this.config.showInsertions=this.showInsertions,this.getCachedAlignmentContainers(),this.trackView.repaintViews()}}),t.push({object:de(Po("Show soft clips",this.showSoftClips)),click:()=>{this.showSoftClips=!this.showSoftClips,this.config.showSoftClips=this.showSoftClips,this.featureSource.setShowSoftClips(this.showSoftClips);const t=this.getCachedAlignmentContainers();for(let e of t)e.setShowSoftClips(this.showSoftClips);this.trackView.repaintViews()}}),this.pairsSupported&&this.alignmentTrack.hasPairs&&(t.push("<hr/>"),t.push({object:de(Po("View as pairs",this.viewAsPairs)),click:()=>{this.viewAsPairs=!this.viewAsPairs,this.config.viewAsPairs=this.viewAsPairs,this.featureSource.setViewAsPairs(this.viewAsPairs);const t=this.getCachedAlignmentContainers();for(let e of t)e.setViewAsPairs(this.viewAsPairs);this.trackView.repaintViews()}})),this.browser.circularView&&(this.alignmentTrack.hasPairs||this.alignmentTrack.hasSupplemental)&&(t.push("<hr/>"),this.alignmentTrack.hasPairs&&t.push({label:"Add discordant pairs to circular view",click:()=>{for(let t of this.trackView.viewports)this.addPairedChordsForViewport(t)}}),this.alignmentTrack.hasSupplemental&&t.push({label:"Add split reads to circular view",click:()=>{for(let t of this.trackView.viewports)this.addSplitChordsForViewport(t)}})),t.push("<hr/>");const o=de('<div class="igv-track-menu-category">');return o.text("Display mode:"),t.push({name:void 0,object:o,click:void 0,init:void 0}),t.push({object:de(Po("expand","EXPANDED"===this.alignmentTrack.displayMode)),click:()=>{this.alignmentTrack.displayMode="EXPANDED",this.config.displayMode="EXPANDED",this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t.push({object:de(Po("squish","SQUISHED"===this.alignmentTrack.displayMode)),click:()=>{this.alignmentTrack.displayMode="SQUISHED",this.config.displayMode="SQUISHED",this.trackView.checkContentHeight(),this.trackView.repaintViews()}}),t}colorByCB(t,e){return{name:void 0,object:de(Po(t.label,e)),click:e=>{"tag"!==t.key?t.key===this.alignmentTrack.colorBy?(this.alignmentTrack.colorBy="none",this.config.colorBy="none",this.trackView.repaintViews()):(this.alignmentTrack.colorBy=t.key,this.config.colorBy=t.key,this.trackView.repaintViews()):this.browser.inputDialog.present({label:"Tag Name",value:this.alignmentTrack.colorByTag?this.alignmentTrack.colorByTag:"",callback:t=>{t?(this.alignmentTrack.colorBy="tag",this.alignmentTrack.colorByTag=t,this.alignmentTrack.tagColors||(this.alignmentTrack.tagColors=new _c("Set1"))):(this.alignmentTrack.colorBy="none",this.alignmentTrack.colorByTag=""),this.trackView.repaintViews()}},e)},init:void 0}}dispose(){this.trackView=void 0}getState(){const t=super.getState();return this.sortObject&&(t.sort={chr:this.sortObject.chr,position:this.sortObject.position+1,option:this.sortObject.option,direction:this.sortObject.direction?"ASC":"DESC"}),t}getCachedAlignmentContainers(){return this.trackView.viewports.map((t=>t.cachedFeatures))}get dataRange(){return this.coverageTrack.dataRange}set dataRange(t){this.coverageTrack.dataRange=t}get logScale(){return this.coverageTrack.logScale}set logScale(t){this.coverageTrack.logScale=t}get autoscale(){return this.coverageTrack.autoscale}set autoscale(t){this.coverageTrack.autoscale=t}addPairedChordsForViewport(t){const e=this.maxTemplateLength,n=[],r=t.referenceFrame;for(let i of t.cachedFeatures.allAlignments())i.end>=r.start&&i.start<=r.end&&(i.paired?i.end-i.start>e&&n.push(i):i.mate&&i.mate.chr&&(i.mate.chr!==i.chr||Math.max(i.fragmentLength)>e)&&n.push(i));tl((t=>{const e=[];for(let n of t)if(n.paired)n.firstAlignment&&n.secondAlignment&&e.push({uniqueId:n.readName,refName:Qc(n.firstAlignment.chr),start:n.firstAlignment.start,end:n.firstAlignment.end,mate:{refName:Qc(n.secondAlignment.chr),start:n.secondAlignment.start,end:n.secondAlignment.end}});else{const t=n.mate;t&&t.chr&&t.position&&e.push({uniqueId:n.readName,refName:Qc(n.chr),start:n.start,end:n.end,mate:{refName:Qc(t.chr),start:t.position-1,end:t.position}})}return e})(n),this,r,.02)}addSplitChordsForViewport(t){const e=[],n=t.referenceFrame;for(let r of t.cachedFeatures.allAlignments()){const t=r.hasTag("SA");r.end>=n.start&&r.start<=n.end&&t&&e.push(r)}tl((t=>{const e=t=>{const e=Sa(t.tags().SA);let r=0;for(let i of e)i.start!==t.start&&n.push({uniqueId:`${t.readName}_${r++}`,refName:Qc(t.chr),start:t.start,end:t.end,mate:{refName:Qc(i.chr),start:i.start,end:i.start+i.lenOnRef}})},n=[];for(let n of t)n.paired?(e(n.firstAlignment),n.secondAlignment&&e(n.secondAlignment)):e(n);return n})(e),this,n,.02)}}class il{constructor(t,e){this.parent=e,this.featureSource=e.featureSource,this.height=void 0!==t.coverageTrackHeight?t.coverageTrackHeight:50,this.paintAxis=yc,this.top=0,this.autoscale=t.autoscale||void 0===t.max,this.autoscale||(this.dataRange={min:t.min||0,max:t.max})}draw(t){const e=t.pixelTop;t.pixelHeight;const n=this.parent.browser.nucleotideColors;if(e>this.height)return;const r=t.context,i=t.features.coverageMap;let o;i.refSeq&&(o=i.refSeq.toUpperCase());const s=t.bpPerPixel,a=t.bpStart,c=a+t.pixelWidth*s+1;let l;l=this.parent.coverageColor?this.parent.coverageColor:void 0!==this.parent.color?no.darkenLighten(this.parent.color,-35):"rgb(150, 150, 150)",ls.setProperties(r,{fillStyle:l,strokeStyle:l});const h=Math.max(1,Math.ceil(1/s));for(let t=0,e=i.coverage.length;t<e;t++){const e=i.bpStart+t;if(e<a)continue;if(e>c)break;const n=i.coverage[t];if(!n)continue;const o=Math.round(n.total/this.dataRange.max*this.height),l=this.height-o,u=Math.floor((e-a)/s);ls.fillRect(r,u,l,h,o)}if(o)for(let t=0,e=i.coverage.length;t<e;t++){const e=i.bpStart+t;if(e<a)continue;if(e>c)break;const l=i.coverage[t];if(!l)continue;const u=l.total/this.dataRange.max*this.height;let f=this.height-u;const d=Math.floor((e-a)/s),p=o[t];if(l.isMismatch(p)){ls.setProperties(r,{fillStyle:n[p]}),ls.fillRect(r,d,f,h,u);let t=0;for(let e of["A","C","T","G"]){const i=(l["pos"+e]+l["neg"+e])/this.dataRange.max*this.height;f=this.height-i-t,t+=i,ls.setProperties(r,{fillStyle:n[e]}),ls.fillRect(r,d,f,h,i)}}}}getClickedObject(t){let e=t.viewport.cachedFeatures;if(!e||0===e.length)return;const n=Math.floor(t.genomicLocation),r=e.coverageMap,i=Math.floor(n-r.bpStart);return r.coverage[i]}popupData(t){const e=[],n=this.getClickedObject(t);if(n){const r=Math.floor(t.genomicLocation),i=t.viewport.referenceFrame;e.push(i.chr+":"+_e(1+r)),e.push({name:"Total Count",value:n.total});let o=n.posA+n.negA;o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posA+"+, "+n.negA+"- )"),e.push({name:"A",value:o}),o=n.posC+n.negC,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posC+"+, "+n.negC+"- )"),e.push({name:"C",value:o}),o=n.posG+n.negG,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posG+"+, "+n.negG+"- )"),e.push({name:"G",value:o}),o=n.posT+n.negT,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posT+"+, "+n.negT+"- )"),e.push({name:"T",value:o}),o=n.posN+n.negN,o>0&&(o=o.toString()+" ("+Math.round(o/n.total*100)+"%, "+n.posN+"+, "+n.negN+"- )"),e.push({name:"N",value:o}),e.push("<HR/>"),e.push({name:"DEL",value:n.del.toString()}),e.push({name:"INS",value:n.ins.toString()})}return e}}class ol{constructor(t,e){this.parent=e,this.browser=e.browser,this.featureSource=e.featureSource,this.top=0===t.coverageTrackHeight?0:t.coverageTrackHeight+5,this.displayMode=t.displayMode||"EXPANDED",this.alignmentRowHeight=t.alignmentRowHeight||14,this.squishedRowHeight=t.squishedRowHeight||3,this.negStrandColor=t.negStrandColor||"rgba(150, 150, 230, 0.75)",this.posStrandColor=t.posStrandColor||"rgba(230, 150, 150, 0.75)",this.insertionColor=t.insertionColor||"rgb(138, 94, 161)",this.deletionColor=t.deletionColor||"black",this.skippedColor=t.skippedColor||"rgb(150, 170, 170)",this.pairConnectorColor=t.pairConnectorColor,this.smallTLENColor=t.smallTLENColor||t.smallFragmentLengthColor||"rgb(0, 0, 150)",this.largeTLENColor=t.largeTLENColor||t.largeFragmentLengthColor||"rgb(200, 0, 0)",this.pairOrientation=t.pairOrienation||"fr",this.pairColors={},this.pairColors.RL=t.rlColor||"rgb(0, 150, 0)",this.pairColors.RR=t.rrColor||"rgb(20, 50, 200)",this.pairColors.LL=t.llColor||"rgb(0, 150, 150)",this.colorBy=t.colorBy||"unexpectedPair",this.colorByTag=t.colorByTag?t.colorByTag.toUpperCase():void 0,this.bamColorTag=void 0===t.bamColorTag?"YC":t.bamColorTag,this.hideSmallIndels=t.hideSmallIndels,this.indelSizeThreshold=t.indelSizeThreshold||1,this.hasPairs=!1,this.hasSupplemental=!1}setTop(t,e){this.top=0===t.height||!1===e?0:5+t.height}computePixelHeight(t){if(t.packedAlignmentRows){return(t.hasDownsampledIntervals()?10:0)+("SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight)*t.packedAlignmentRows.length+5}return 0}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=i+o*r+1,a=this.parent.showSoftClips,c=this.parent.showAllBases,l=this.browser.nucleotideColors,h=e.packedAlignmentRows;n.save();let u=e.sequence;u&&(u=u.toUpperCase());let f=0,d=t.pixelTop;this.top&&n.translate(0,this.top);const p=d+t.pixelHeight;e.hasDownsampledIntervals()?(f=10,e.downsampledIntervals.forEach((function(t){var e=(t.start-i)/r,o=(t.end-i)/r;o-e>5&&(e+=1,o-=1),ls.fillRect(n,e,2,o-e,3,{fillStyle:"black"})}))):f=0,this.alignmentsYOffset=f;const g="SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight;if(h){const t=h.length;for(let e=0;e<t;e++){const t=h[e],n=f+g*e,r=g<=4?g:g-2;if(n>p)break;if(!(n+r<d))for(let e of t.alignments)if(this.hasPairs=this.hasPairs||e.isPaired(),this.browser.circularView&&(this.hasSupplemental=this.hasSupplemental||e.hasTag("SA")),!(e.start+e.lengthOnRef<i)){if(e.start>s)break;!0!==e.hidden&&(e instanceof ua?(m.call(this,e,n,r),v.call(this,e.firstAlignment,n,r),e.secondAlignment&&v.call(this,e.secondAlignment,n,r)):v.call(this,e,n,r))}}}function m(t,e,o){var a=this.getConnectorColor(t.firstAlignment),c=(t.connectingStart-i)/r,l=(t.connectingEnd-i)/r,h=e+o/2;t.connectingEnd<i||t.connectingStart>s||(t.mq<=0&&(a=no.addAlpha(a,.15)),ls.setProperties(n,{fillStyle:a,strokeStyle:a}),ls.strokeLine(n,c,h,l,h))}function v(t,o,h){if(t.start+t.lengthOnRef<i||t.start>s)return;const f=a?t.blocks:t.blocks.filter((t=>"S"!==t.type));let d=this.getAlignmentColor(t);const p=d;t.mq<=0&&(d=no.addAlpha(d,.15)),ls.setProperties(n,{fillStyle:d,strokeStyle:p});for(let t=0;t<f.length;t++){const e=f[t];if(!(t!==f.length-1&&f[t+1].start<i)&&(m.call(this,e,t),e.start+e.len>s))break}if(t.insertions&&this.parent.showInsertions){let e=-1;for(let a of t.insertions){if(this.hideSmallIndels&&a.len<=this.indelSizeThreshold)continue;if(a.start<i)continue;if(a.start>s)break;const t=(a.start-i)/r-1;if(t-e>2){const r=3;ls.fillRect(n,t,o-1,r,h+2,{fillStyle:this.insertionColor}),e=t}}}if(t.gaps){const e=o+h/2;for(let o of t.gaps){const t=(o.start-i)/r,s=(o.start+o.len-i)/r,a="D"===o.type?this.deletionColor:this.skippedColor;ls.strokeLine(n,t,e,s,e,{strokeStyle:a})}}function m(s,a){const m=s.start-e.start,b=(s.start-i)/r,w=(s.start+s.len-i)/r,y=Math.max(1,w-b),x=100/r,k=Math.min(g/2,x/6),_="S"===s.type,S=t.mq<=0||this.highlightedAlignmentReadNamed===t.readName||_;let C=p;this.highlightedAlignmentReadNamed===t.readName?C="red":_&&(C="rgb(50,50,50)");const E=!0===t.strand&&a===f.length-1,A=!1===t.strand&&0===a;if(E|A){let t,e;E?(t=[b,w,w+k,w,b,b],e=[o,o,o+h/2,o+h,o+h,o]):A&&(t=[w,b,b-k,b,w,w],e=[o,o,o+h/2,o+h,o+h,o]),ls.fillPolygon(n,t,e,{fillStyle:d}),S&&ls.strokePolygon(n,t,e,{strokeStyle:C})}else ls.fillRect(n,b,o,y,h,{fillStyle:d}),S&&(n.save(),n.strokeStyle=C,n.strokeRect(b,o,y,h),n.restore());if(_||c||this.parent.showMismatches&&u&&t.seq&&"*"!==t.seq){const e=t.seq?t.seq.toUpperCase():void 0,a=t.qual,f=s.seqOffset;for(let t=0,d=s.len;t<d;t++){if(m+t<0)continue;let d=e?e.charAt(f+t):"";const p=u.charAt(m+t);if("="===d&&(d=p),"X"===d||p!==d||_||c){let e;if(!_&&void 0!==a&&a.length>f+t){e=al(a[f+t],l[d])}else e=l[d];if(e){const a=(s.start+t-i)/r,c=Math.max(1,1/r);v(n,r,{x:a,y:o,width:c,height:h},e,d)}}}}}function v(t,e,n,r,i){var o;if(.1,e<=.1&&n.height>=8){const e=Math.min(10,n.height);t.font=e+"px sans-serif",o=n.x+n.width/2,ls.strokeText(t,i,o-t.measureText(i).width/2,e-1+n.y,{strokeStyle:r})}else ls.fillRect(t,n.x,n.y,n.width,n.height,{fillStyle:r})}}n.restore()}popupData(t){const e=this.getClickedObject(t);return e?e.popupData(t.genomicLocation):void 0}contextMenuItemList(t){const e=t.viewport,n=[],r=n=>{const r=this.parent.sortObject,i=!r||r.position!==Math.floor(t.genomicLocation)||!r.direction,o={chr:e.referenceFrame.chr,position:Math.floor(t.genomicLocation),option:n,direction:i};this.parent.sortObject=o,sl(o,e.cachedFeatures),e.repaint()};n.push("<b>Sort by...</b>"),n.push({label:"&nbsp; base",click:()=>r("BASE")}),n.push({label:"&nbsp; read strand",click:()=>r("STRAND")}),n.push({label:"&nbsp; insert size",click:()=>r("INSERT_SIZE")}),n.push({label:"&nbsp; gap size",click:()=>r("GAP_SIZE")}),n.push({label:"&nbsp; chromosome of mate",click:()=>r("MATE_CHR")}),n.push({label:"&nbsp; mapping quality",click:()=>r("MQ")}),n.push({label:"&nbsp; read name",click:()=>r("READ_NAME")}),n.push({label:"&nbsp; tag",click:()=>{const n=this.parent.sortObject,r=!n||n.position!==Math.floor(t.genomicLocation)||!n.direction,i={label:"Tag Name",value:this.sortByTag?this.sortByTag:"",callback:n=>{if(n){const i={chr:e.referenceFrame.chr,position:Math.floor(t.genomicLocation),option:"TAG",tag:n,direction:r};this.sortByTag=n,this.parent.sortObject=i,sl(i,e.cachedFeatures),e.repaint()}}};this.browser.inputDialog.present(i,t.event)}}),n.push("<hr/>");const i=this.getClickedObject(t);if(i){const e=this.parent.showSoftClips,r="function"==typeof i.alignmentContaining?i.alignmentContaining(t.genomicLocation,e):i;r&&(r.isPaired()&&r.isMateMapped()&&n.push({label:"View mate in split screen",click:()=>{if(r.mate){const e=t.viewport.referenceFrame;if(this.browser.genome.getChromosome(r.mate.chr)){this.highlightedAlignmentReadNamed=r.readName;const t=e.end-e.start,n=r.mate.position-t/2,i=r.mate.position+t/2;this.browser.addMultiLocusPanel(r.mate.chr,n,i,e)}else Qo.presentAlert(`Reference does not contain chromosome: ${r.mate.chr}`)}},init:void 0}),n.push({label:"View read sequence",click:()=>{const t=r.seq;t&&"*"!==t?Qo.presentAlert(t):Qo.presentAlert("Read sequence: *")}}),Ss()&&n.push({label:"Copy read sequence",click:async()=>{const t=r.seq;try{await navigator.clipboard.writeText(t)}catch(t){console.error(t),Qo.presentAlert(`error copying sequence to clipboard ${t}`)}}}),n.push("<hr/>"))}return this.browser.circularView&&(this.hasPairs||this.hasSupplemental)&&(this.hasPairs&&n.push({label:"Add discordant pairs to circular view",click:()=>{this.parent.addPairedChordsForViewport(e)}}),this.hasSupplemental&&n.push({label:"Add split reads to circular view",click:()=>{this.parent.addSplitChordsForViewport(e)}}),n.push("<hr/>")),n}getClickedObject(t){const e=t.viewport,n=t.y,r=t.genomicLocation,i=this.parent.showSoftClips;let o=e.cachedFeatures;if(!o||0===o.length)return;let s=o.packedAlignmentRows,a=o.downsampledIntervals;const c="SQUISHED"===this.displayMode?this.squishedRowHeight:this.alignmentRowHeight;let l=Math.floor((n-this.top-this.alignmentsYOffset)/c);if(l<0){for(let t=0;t<a.length;t++)if(a[t].start<=r&&a[t].end>=r)return a[t]}else if(l<s.length){const t=s[l].alignments.filter((t=>t.containsLocation(r,i)));if(t.length>0)return t[0]}}getConnectorColor(t){if(this.pairConnectorColor)return this.pairConnectorColor;switch(this.colorBy){case"strand":case"firstOfPairStrand":case"pairOrientation":case"tag":return this.parent.color||"rgb(200, 200, 200)";default:return this.getAlignmentColor(t)}}getAlignmentColor(t){let e=this.parent.color||"rgb(185, 185, 185)";const n=this.colorBy;switch(n){case"strand":e=t.strand?this.posStrandColor:this.negStrandColor;break;case"firstOfPairStrand":t instanceof ua?e=t.firstOfPairStrand()?this.posStrandColor:this.negStrandColor:t.isPaired()&&(t.isFirstOfPair()?e=t.strand?this.posStrandColor:this.negStrandColor:t.isSecondOfPair()?e=t.strand?this.negStrandColor:this.posStrandColor:console.error("ERROR. Paired alignments are either first or second."));break;case"unexpectedPair":case"pairOrientation":if(this.pairOrientation&&t.pairOrientation){const n=cl[this.pairOrientation];if(n){const r=this.pairColors[n[t.pairOrientation]];if(r){e=r;break}}}if("pairOrientation"===n)break;case"tlen":case"fragmentLength":t.mate&&t.isMateMapped()&&(t.mate.chr!==t.chr?e=ll(t.mate.chr):this.parent.minTemplateLength&&Math.abs(t.fragmentLength)<this.parent.minTemplateLength?e=this.smallTLENColor:this.parent.maxTemplateLength&&Math.abs(t.fragmentLength)>this.parent.maxTemplateLength&&(e=this.largeTLENColor));break;case"tag":const r=t.tags()[this.colorByTag];void 0!==r&&(this.bamColorTag===this.colorByTag?e="rgb("+r+")":(this.tagColors||(this.tagColors=new _c("Set1")),e=this.tagColors.getColor(r)));break;default:e=this.parent.color||"rgb(185, 185, 185)"}return e}}function sl(t,e){const n=t.direction;for(let n of e.packedAlignmentRows)n.updateScore(t,e);e.packedAlignmentRows.sort((function(t,e){const r=t.score>e.score?1:t.score<e.score?-1:0;return!0===n?r:-r}))}function al(t,e){let n;return n=t<5?.1:Math.max(.1,Math.min(1,.1+.9*(t-5)/15)),n=Math.round(10*n)/10,n<1&&(e=no.addAlpha(e,n)),e}const cl={fr:{F1R2:"LR",F2R1:"LR",F1F2:"LL",F2F1:"LL",R1R2:"RR",R2R1:"RR",R1F2:"RL",R2F1:"RL"},rf:{R1F2:"LR",R2F1:"LR",R1R2:"LL",R2R1:"LL",F1F2:"RR",F2F1:"RR",F1R2:"RL",F2R1:"RL"},ff:{F2F1:"LR",R1R2:"LR",F2R1:"LL",R1F2:"LL",R2F1:"RR",F1R2:"RR",R2R1:"RL",F1F2:"RL"}};function ll(t){if(hl[t])return hl[t];if(hl["chr"+t]){const e=hl["chr"+t];return hl[t]=e,e}{const e=no.randomRGB(0,255);return hl[t]=e,e}}const hl={chrX:"rgb(204, 153, 0)",chrY:"rgb(153, 204, 0)",chrUn:"rgb(50, 50, 50)",chr1:"rgb(80, 80, 255)",chrI:"rgb(139, 155, 187)",chr2:"rgb(206, 61, 50)",chrII:"rgb(206, 61, 50)",chr2a:"rgb(216, 71, 60)",chr2b:"rgb(226, 81, 70)",chr3:"rgb(116, 155, 88)",chrIII:"rgb(116, 155, 88)",chr4:"rgb(240, 230, 133)",chrIV:"rgb(240, 230, 133)",chr5:"rgb(70, 105, 131)",chr6:"rgb(186, 99, 56)",chr7:"rgb(93, 177, 221)",chr8:"rgb(128, 34, 104)",chr9:"rgb(107, 215, 107)",chr10:"rgb(213, 149, 167)",chr11:"rgb(146, 72, 34)",chr12:"rgb(131, 123, 141)",chr13:"rgb(199, 81, 39)",chr14:"rgb(213, 143, 92)",chr15:"rgb(122, 101, 165)",chr16:"rgb(228, 175, 105)",chr17:"rgb(59, 27, 83)",chr18:"rgb(205, 222, 183)",chr19:"rgb(97, 42, 121)",chr20:"rgb(174, 31, 99)",chr21:"rgb(231, 199, 111)",chr22:"rgb(90, 101, 94)",chr23:"rgb(204, 153, 0)",chr24:"rgb(153, 204, 0)",chr25:"rgb(51, 204, 0)",chr26:"rgb(0, 204, 51)",chr27:"rgb(0, 204, 153)",chr28:"rgb(0, 153, 204)",chr29:"rgb(10, 71, 255)",chr30:"rgb(71, 117, 255)",chr31:"rgb(255, 194, 10)",chr32:"rgb(255, 209, 71)",chr33:"rgb(153, 0, 51)",chr34:"rgb(153, 26, 0)",chr35:"rgb(153, 102, 0)",chr36:"rgb(128, 153, 0)",chr37:"rgb(51, 153, 0)",chr38:"rgb(0, 153, 26)",chr39:"rgb(0, 153, 102)",chr40:"rgb(0, 128, 153)",chr41:"rgb(0, 51, 153)",chr42:"rgb(26, 0, 153)",chr43:"rgb(102, 0, 153)",chr44:"rgb(153, 0, 128)",chr45:"rgb(214, 0, 71)",chr46:"rgb(255, 20, 99)",chr47:"rgb(0, 214, 143)",chr48:"rgb(20, 255, 177)"};let ul,fl;class dl extends sa{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.rulerSweeper=new la(this),this.$multiLocusCloseButton=de("<div>",{class:"igv-multi-locus-close-button"}),this.$viewport.append(this.$multiLocusCloseButton),this.$multiLocusCloseButton.get(0).appendChild(we("times-circle")),this.$multiLocusCloseButton.click((()=>{this.browser.removeMultiLocusPanel(this.referenceFrame)})),this.$rulerLabel=de("<div>",{class:"igv-multi-locus-ruler-label"}),this.$viewport.append(this.$rulerLabel),this.$rulerLabel.click((async()=>{await this.browser.gotoMultilocusPanel(this.referenceFrame)})),this.$tooltip=de("<div>",{class:"igv-ruler-tooltip"}),this.$tooltip.height(this.$viewport.height()),this.$viewport.append(this.$tooltip),this.$tooltipContent=de("<div>"),this.$tooltip.append(this.$tooltipContent),this.attachMouseHandlers(na.isWholeGenomeView(this.referenceFrame.chr)),this.$tooltip.hide(),this.dismissLocusLabel()}presentLocusLabel(t){this.$rulerLabel.get(0).innerHTML="",this.$rulerLabel.get(0).style.backgroundColor=ll(this.referenceFrame.chr),this.$rulerLabel.get(0).appendChild((()=>{const e=`<div>${this.referenceFrame.getMultiLocusLabel(t)}</div>`;return document.createRange().createContextualFragment(e).firstChild})()),this.$rulerLabel.show(),this.$multiLocusCloseButton.show()}presentLocusLabel_Square_Dot(t){this.$rulerLabel.get(0).innerHTML="",this.$rulerLabel.get(0).appendChild((()=>{const t=`<div>\n <?xml version="1.0" encoding="UTF-8"?>\n <svg width="14px" height="14px" viewBox="0 0 89 89" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n <g>\n <circle id="Oval" fill="${ll(this.referenceFrame.chr)}" cx="44.5" cy="44.5" r="44.5"></circle>\n </g>\n </svg>\n </div>`;return document.createRange().createContextualFragment(t).firstChild})()),this.$rulerLabel.get(0).appendChild((()=>{const e=`<div>${this.referenceFrame.getMultiLocusLabel(t)}</div>`;return document.createRange().createContextualFragment(e).firstChild})()),this.$rulerLabel.show(),this.$multiLocusCloseButton.show()}dismissLocusLabel(){this.$rulerLabel.hide(),this.$multiLocusCloseButton.hide()}attachMouseHandlers(t){if(this.namespace=`.ruler_track_viewport_${this.browser.referenceFrameList.indexOf(this.referenceFrame)}`,this.$viewport.off(this.namespace),!0===t){const t=this.browser.referenceFrameList.indexOf(this.referenceFrame),e=`click${this.namespace}`;this.$viewport.on(e,(e=>{const{x:n}=be(e,this.$viewport.get(0)),r=Math.round(this.referenceFrame.start+this.referenceFrame.toBP(n));let i;const{chr:o}=this.browser.genome.getChromosomeCoordinate(r);if(1===this.browser.referenceFrameList.length)i=o;else{let e=this.browser.referenceFrameList.map((({locusSearchString:t})=>t));e[t]=o,i=e.join(" ")}this.browser.search(i)})),this.$viewport.get(0).style.cursor="pointer"}else this.$viewport.get(0).style.cursor="default"}mouseMove(t){if(!0===this.browser.cursorGuideVisible){void 0===fl?(fl=this,this.$tooltip.show()):fl.guid!==this.guid?(fl.$tooltip&&fl.$tooltip.hide(),this.$tooltip.show(),fl=this):this.$tooltip.show();if(this.browser.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(this.referenceFrame.chr))return void this.$tooltip.hide();const{x:e}=be(t,this.$viewport.get(0)),{start:n,bpPerPixel:r}=this.referenceFrame,i=Math.round(.5+n+Math.max(0,e)*r);this.$tooltipContent.text(_e(i));const{width:o}=this.$tooltipContent.get(0).getBoundingClientRect(),{width:s}=this.$viewport.get(0).getBoundingClientRect();this.$tooltip.css({left:`${Qi(e,0,s-o)}px`}),clearTimeout(ul),ul=setTimeout((()=>{this.$tooltip&&this.$tooltip.hide()}),1e4)}}startSpinner(){}stopSpinner(){}dispose(){this.rulerSweeper.dispose(),super.dispose()}}class pl extends sa{constructor(t,e,n,r){super(t,e,n,r)}initializationHelper(){this.canvas=document.createElement("canvas"),this.canvas.className="igv-ideogram-canvas",this.$content.append(de(this.canvas)),this.ideogram_ctx=this.canvas.getContext("2d"),this.addMouseHandlers()}addMouseHandlers(){this.addViewportClickHandler(this.$viewport.get(0))}addViewportClickHandler(t){this.boundClickHandler=function(t){const{xNormalized:e,width:n}=be(t,this.ideogram_ctx.canvas),{bpLength:r}=this.browser.genome.getChromosome(this.referenceFrame.chr),i=this.referenceFrame.bpPerPixel*n/r;let o=e;o-i/2<0&&(o=i/2);o+i/2>1&&(o=1-i/2);const s=Math.round((o-i/2)*r),a=Math.round((o+i/2)*r);this.referenceFrame.start=s,this.referenceFrame.end=a,this.referenceFrame.bpPerPixel=(a-s)/n,this.browser.updateViews(this.referenceFrame,this.browser.trackViews,!0)}.bind(this),t.addEventListener("click",this.boundClickHandler)}setWidth(t){this.$viewport.width(t)}drawSVGWithContext(t,e,n,r,i,o,s){t.saveWithTranslationAndClipRect(r,i,o,e,n,s),this.trackView.track.draw({context:t,referenceFrame:this.referenceFrame,pixelWidth:e,pixelHeight:n}),t.restore()}repaint(){this.draw({referenceFrame:this.referenceFrame})}draw({referenceFrame:t}){ls.configureHighDPICanvas(this.ideogram_ctx,this.$viewport.width(),this.$viewport.height()),this.trackView.track.draw({context:this.ideogram_ctx,referenceFrame:t,pixelWidth:this.$viewport.width(),pixelHeight:this.$viewport.height()})}startSpinner(){}stopSpinner(){}}function gl(t,e,n,r){return"ruler"===t.track.type?new dl(t,e,n,r):"ideogram"===t.track.id?new pl(t,e,n,r):new sa(t,e,n,r)}const ml={textAlign:"start",textBaseline:"bottom",strokeStyle:"black",fillStyle:"black"};class vl{constructor(t,e,n,r){this.guid=ve(),this.trackView=t,this.browser=t.browser,this.viewport=pe({class:"igv-viewport"}),e.appendChild(this.viewport),t.track.height&&(this.viewport.style.height=`${t.track.height}px`),this.canvas=document.createElement("canvas"),this.viewport.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this.trackScrollDelta=0,this.contentTop=0,this.setWidth(r),!1===this.browser.showSampleNames&&this.hide(),this.addMouseHandlers()}checkCanvas(){const t=window.devicePixelRatio,e=this.viewport.clientHeight,n=this.browser.sampleNameViewportWidth;if(this.canvas.width!==n*t||this.canvas.height!==e*t){const r=this.canvas;r.width=n*t,r.height=e*t,r.style.width=`${n}px`,r.style.height=`${e}px`,this.ctx=this.canvas.getContext("2d"),this.ctx.scale(t,t)}}setTop(t){if("function"==typeof this.trackView.track.getSamples){this.contentTop=t;const e=this.trackView.track.getSamples();this.repaint(e)}}setWidth(t){this.viewport.innerWidth=t,this.checkCanvas()}show(){this.viewport.style.display="block"}hide(){this.viewport.style.display="none"}async repaint(t){this.checkCanvas(),this.draw({context:this.ctx,samples:t})}draw({context:t,samples:e}){if(!e||0===e.names.length)return;!function(t,{textAlign:e,textBaseline:n,strokeStyle:r,fillStyle:i},o){const s=Math.min(o,10);t.font=`${s}px sans-serif`,t.textAlign=e,t.textBaseline=n,t.fillStyle=i}(t,ml,e.height);t.clearRect(0,0,t.canvas.width,t.canvas.height),t.fillStyle=function(t){const{r:e,g:n,b:r}=xc[t];return`rgb(${e},${n},${r})`}("lead");const n=this.viewport.getBoundingClientRect().height;let r=(e.yOffset||0)+this.contentTop;for(let i of e.names){if(r>n)break;if(r+e.height>0){const n=i,o=bl(t,n,r,e.height);t.fillText(n,4,o)}r+=e.height}}renderSVGContext(t,{deltaX:e,deltaY:n}){if("function"==typeof this.trackView.track.getSamples){const r=this.trackView.track.getSamples(),i=0,{width:o,height:s}=this.viewport.getBoundingClientRect(),a=`${(this.trackView.track.name||this.trackView.track.id).replace(/\W/g,"")}_sample_names_guid_${ve()}`;t.saveWithTranslationAndClipRect(a,e,n+i,o,s,-i),this.draw({context:t,samples:r}),t.restore()}}addMouseHandlers(){this.addViewportContextMenuHandler(this.viewport)}removeMouseHandlers(){this.removeViewportContextMenuHandler(this.viewport)}addViewportContextMenuHandler(t){this.boundContextMenuHandler=function(t){t.preventDefault(),t.stopPropagation();const e={label:"Name Panel Width",value:this.browser.sampleNameViewportWidth,callback:t=>{this.browser.sampleNameViewportWidth=parseInt(t);for(let{sampleNameViewport:t}of this.browser.trackViews)t.setWidth(this.browser.sampleNameViewportWidth);this.browser.layoutChange()}};this.browser.inputDialog.present(e,t)}.bind(this),t.addEventListener("contextmenu",this.boundContextMenuHandler)}removeViewportContextMenuHandler(t){t.removeEventListener("contextmenu",this.boundContextMenuHandler)}dispose(){this.removeMouseHandlers(),this.viewport.remove()}}function bl(t,e,n,r){return n+r-function(t,e,n){const{actualBoundingBoxAscent:r,actualBoundingBoxDescent:i}=t.measureText(e);return(n-(r+i))/2}(t,e,r)}class wl extends es{constructor({parent:t,width:e}){super({parent:t,width:e,border:"1px solid gray"})}configure(t,e){this.colorHandlers=e,this.setActiveColorHandler("color"),this.createSwatches(t)}setActiveColorHandler(t){this.activeColorHandler=this.colorHandlers[t]}createSwatches(t){this.container.querySelectorAll(".igv-ui-color-swatch").forEach((t=>t.remove()));const e=Object.values(lo);for(let t of e){const e=pe({class:"igv-ui-color-swatch"});this.container.appendChild(e),this.decorateSwatch(e,t)}if(t)for(let e of t){const t=pe({class:"igv-ui-color-swatch"});this.container.appendChild(t),this.decorateSwatch(t,e)}}decorateSwatch(t,e){t.style.backgroundColor=e,t.addEventListener("mouseenter",(()=>t.style.borderColor=e)),t.addEventListener("mouseleave",(()=>t.style.borderColor="white")),t.addEventListener("click",(t=>{t.stopPropagation(),this.activeColorHandler(e)})),t.addEventListener("touchend",(t=>{t.stopPropagation(),this.activeColorHandler(e)}))}}const yl=function(t){this.popover=pe({class:"igv-menu-popup"}),t.appendChild(this.popover);const e=pe({class:"igv-menu-popup-header"});this.popover.appendChild(e),xe(e,(()=>this.hide())),this.popoverContent=pe(),this.popover.appendChild(this.popoverContent),oo(this.popover,e),e.addEventListener("click",(t=>{t.stopPropagation(),t.preventDefault()})),this.hide()};yl.prototype.hide=function(){this.popover.style.display="none"},yl.prototype.presentMenuList=function(t){if(xl(),t.length>0){this.popoverContent.innerHTML="",t=Oo.trackMenuItemListHelper(t,this);for(let e of t){e.init&&e.init();let n=e.object;0===t.indexOf(e)&&n.removeClass("igv-track-menu-border-top"),n.hasClass("igv-track-menu-border-top")||n.hasClass("igv-menu-popup-check-container")||n.is("div")&&n.addClass("igv-menu-popup-shim"),this.popoverContent.appendChild(n.get(0))}this.popover.style.display="flex";const{width:e}=this.popover.getBoundingClientRect();this.popover.style.left=-e+"px",this.popover.style.top="0px"}},yl.prototype.presentTrackContextMenu=function(t,e){this.popoverContent.innerHTML="";const n=(r=e,i=this.popover,r.map((t=>{let e;if("string"==typeof t&&"<hr/>"===t)e=document.createElement("hr");else if("string"==typeof t)e=pe({class:"context-menu"}),e.innerHTML=t;else if("Node"==typeof t)e=t;else{if("function"==typeof t.init&&t.init(),"checkbox"===t.type)e=Po("Show all bases",t.value);else if("color"===t.type){const r=new wl({parent:i.parentElement,width:364});r.configure(void 0,{color:e=>t.click(e)}),e=pe({class:"context-menu"}),"string"==typeof t.label&&(e.innerHTML=t.label);const o=t=>{r.show(),ge(i),t.preventDefault(),t.stopPropagation()};e.addEventListener("click",o),e.addEventListener("touchend",o),e.addEventListener("mouseup",(function(t){t.preventDefault(),t.stopPropagation()}))}else e=pe({class:"context-menu"}),"string"==typeof t.label&&(e.innerHTML=t.label);if(t.click&&"color"!==t.type){function n(e){t.click(),ge(i),e.preventDefault(),e.stopPropagation()}e.addEventListener("click",n),e.addEventListener("touchend",n),e.addEventListener("mouseup",(function(t){t.preventDefault(),t.stopPropagation()}))}}return{el:e,init:t.init}})));var r,i;for(let{el:t}of n)this.popoverContent.appendChild(t);!function(t,e){e.style.display="flex";const{x:n,y:r}=be(t,e.parentNode),{width:i}=e.getBoundingClientRect(),o=n+i,{width:s}=e.parentNode.getBoundingClientRect();e.style.left=`${o>s?n-(o-s):n}px`,e.style.top=`${r}px`}(t,this.popover)},yl.prototype.dispose=function(){this.popoverContent.innerHTML="",this.popover.innerHTML="",Object.keys(this).forEach((function(t){this[t]=void 0}))};const xl=()=>{const t=document.querySelectorAll(".igv-menu-popup");for(let e=0;e<t.length;e++)t[e].style.display="none"},kl=new Set(["ruler","sequence","ideogram"]),_l=new Set(["ruler","sequence","ideogram"]);class Sl{constructor(t,e,n){this.browser=t,this.track=n,n.trackView=this,this.addDOMToColumnContainer(t,e,t.referenceFrameList)}startSpinner(){this.viewports&&this.viewports.length>0&&this.viewports[0].startSpinner()}stopSpinner(){this.viewports&&this.viewports.length>0&&this.viewports[0].stopSpinner()}addDOMToColumnContainer(t,e,n){this.axis=this.createAxis(t,this.track),this.viewports=[];const r=t.calculateViewportWidth(n.length),i=e.querySelectorAll(".igv-column");for(let t=0;t<i.length;t++){const e=gl(this,i[t],n[t],r);this.viewports.push(e)}this.sampleNameViewport=new vl(this,t.columnContainer.querySelector(".igv-sample-name-column"),void 0,t.sampleNameViewportWidth),this.createTrackScrollbar(t),this.createTrackDragHandle(t),this.createTrackGearPopup(t)}createAxis(t,e){const n=pe();if(t.columnContainer.querySelector(".igv-axis-column").appendChild(n),n.style.height=`${e.height}px`,"function"==typeof e.paintAxis){e.dataRange&&n.addEventListener("click",(()=>{t.dataRangeDialog.configure(this),t.dataRangeDialog.present(de(t.columnContainer))}));const{width:r,height:i}=n.getBoundingClientRect();this.axisCanvas=document.createElement("canvas"),this.axisCanvas.style.width=`${r}px`,this.axisCanvas.style.height=`${i}px`,n.appendChild(this.axisCanvas)}return n}resizeAxisCanvas(t,e){this.axis.style.width=`${t}px`,this.axis.style.height=`${e}px`,"function"==typeof this.track.paintAxis&&(this.axisCanvas.style.width=`${t}px`,this.axisCanvas.style.height=`${e}px`)}removeDOMFromColumnContainer(){this.boundAxisClickHander&&this.removeAxisEventListener(this.axis),this.axis.remove();for(let t of this.viewports)t.$viewport.remove();this.sampleNameViewport.dispose(),this.removeTrackScrollMouseHandlers(),this.outerScroll.remove(),this.removeTrackDragMouseHandlers(),this.dragHandle.remove(),this.removeTrackGearMouseHandlers(),this.gearContainer.remove()}renderSVGContext(t,{deltaX:e,deltaY:n}){!function(t,e,n,r,i){if("function"==typeof e.paintAxis){const{y:o,width:s,height:a}=n.getBoundingClientRect(),c=`${(e.name||e.id).replace(/\W/g,"")}_axis_guid_${ve()}`;t.saveWithTranslationAndClipRect(c,r,o+i,s,a,0),e.paintAxis(t,s,a),t.restore()}}(t,this.track,this.axisCanvas,e,n);const{width:r}=this.axis.getBoundingClientRect(),{y:i}=this.viewports[0].$viewport.get(0).getBoundingClientRect();let o={deltaX:r+e,deltaY:i+n};for(let e of this.viewports){e.renderSVGContext(t,o);const{width:n}=e.$viewport.get(0).getBoundingClientRect();o.deltaX+=n}!0===this.browser.showSampleNames&&this.sampleNameViewport.renderSVGContext(t,o)}dataRange(){return this.track.dataRange?this.track.dataRange:void 0}setDataRange(t,e){void 0!==t&&(this.track.dataRange.min=t),void 0!==e&&(this.track.dataRange.max=e),this.track.autoscale=!1,this.repaintViews()}presentColorPicker(t){if(!1===_l.has(this.track.type)){const e=[],n=this.track.color||this.track.defaultColor;ke(n)&&e.push(n),this.track.altColor&&ke(this.track.altColor)&&e.push(this.track.altColor);const r=e.map((t=>t.startsWith("#")?t:t.startsWith("rgb(")?no.rgbToHex(t):no.colorNameToHex(t))),i={color:t=>{this.track.color=t,this.repaintViews()},altColor:t=>{this.track.altColor=t,this.repaintViews()}};this.browser.genericColorPicker.configure(r,i),this.browser.genericColorPicker.setActiveColorHandler(t),this.browser.genericColorPicker.show()}}setTrackHeight(t,e){e||(this.track.minHeight&&(t=Math.max(this.track.minHeight,t)),this.track.maxHeight&&(t=Math.min(this.track.maxHeight,t))),this.track.height=t,this.resizeAxisCanvas(this.axis.clientWidth,this.track.height),"function"==typeof this.track.paintAxis&&this.paintAxis();for(let{$viewport:e}of this.viewports)e.height(t);if(this.sampleNameViewport.viewport.style.height=`${t}px`,"function"!=typeof this.track.computePixelHeight)for(let e of this.viewports)e.setContentHeight(t);this.repaintViews(),!1===kl.has(this.track.type)&&this.updateScrollbar(),this.dragHandle.style.height=`${t}px`,this.gearContainer.style.height=`${t}px`}updateScrollbar(){const t=this.viewports[0].$viewport.height();this.outerScroll.style.height=`${t}px`;const e=Cl(this.viewports),n=Math.round(t/e*t);e>t?(this.innerScroll.style.display="block",this.innerScroll.style.height=`${n}px`):this.innerScroll.style.display="none"}moveScroller(t){const e=de(this.innerScroll).position().top+t,n=Math.min(Math.max(0,e),this.outerScroll.clientHeight-this.innerScroll.clientHeight);de(this.innerScroll).css("top",`${n}px`);const r=Cl(this.viewports),i=-Math.round(n*(r/this.viewports[0].$viewport.height()));for(let t of this.viewports)t.setTop(i);this.sampleNameViewport.trackScrollDelta=t,this.sampleNameViewport.setTop(i)}isLoading(){for(let t of this.viewports)if(t.isLoading())return!0}repaintViews(){for(let t of this.viewports)t.isVisible()&&t.repaint();"function"==typeof this.track.paintAxis&&this.paintAxis(),this.repaintSamples()}repaintSamples(){if("function"==typeof this.track.getSamples){const t=this.track.getSamples();this.sampleNameViewport.repaint(t)}}setTrackLabelName(t){this.viewports.forEach((e=>e.setTrackLabel(t)))}resize(t){for(let e of this.viewports)e.setWidth(t)}async updateViews(){if(!this.browser||!this.browser.referenceFrameList)return;const t=this.viewports.filter((t=>t.isVisible()));if(t.forEach((t=>t.shift())),this.browser.dragObject)return;let e=this.track.autoscale||this.track.autoscaleGroup||"ruler"===this.track.type?t:t.filter((t=>t.needsRepaint()));e=e.filter((t=>t.checkZoomIn()));const n=e.filter((t=>t.needsReload()));for(let t of n)await t.loadFeatures();if(!this.disposed){if(this.track&&"function"==typeof this.track.variantRowCount&&n.length>0){let t=0;for(let e of this.viewports)e.featureCache&&e.featureCache.features&&(t=Math.max(t,e.featureCache.features.reduce(((t,e)=>Math.max(t,e.row||0)),0)));if(this.track.nVariantRows!==t+1){this.track.variantRowCount(t+1);for(let t of this.viewports)t.checkContentHeight()}}if(this.track.autoscale){let e=[];for(let n of t){const t=n.referenceFrame,r=t.start,i=r+t.toBP(de(n.contentDiv).width());if(n.featureCache&&n.featureCache.features)if("function"==typeof n.featureCache.features.getMax){const t=n.featureCache.features.getMax(r,i);e.push({value:t})}else e=e.concat(No(n.featureCache.features,r,i))}"function"==typeof this.track.doAutoscale?this.track.dataRange=this.track.doAutoscale(e):this.track.dataRange=ms(e)}for(let t of e)t.repaint();this.adjustTrackHeight(),this.repaintSamples(),this.updateRulerViewportLabels()}}updateRulerViewportLabels(){const t=this.browser.calculateViewportWidth(this.viewports.length);for(let e of this.viewports)"ruler"===this.track.type&&(this.viewports.length>1?e.presentLocusLabel(t):e.dismissLocusLabel())}async getInViewFeatures(){if(!this.browser||!this.browser.referenceFrameList)return[];let t=[];for(let e of this.viewports)if(e.needsReload()&&await e.loadFeatures(),e.featureCache&&e.featureCache.features){const n=e.referenceFrame,r=n.start,i=r+n.toBP(de(e.contentDiv).width());if("function"==typeof e.featureCache.features.getMax){const n=e.featureCache.features.getMax(r,i);t.push({value:n})}else t=t.concat(No(e.featureCache.features,r,i))}return t}checkContentHeight(){for(let t of this.viewports)t.checkContentHeight();this.adjustTrackHeight()}adjustTrackHeight(){var t=Cl(this.viewports);if(this.track.autoHeight?this.setTrackHeight(t,!1):this.track.paintAxis&&this.paintAxis(),!1===kl.has(this.track.type)){const t=this.viewports[0].getContentTop(),e=this.viewports.map((t=>t.getContentHeight())),n=Math.min(...e),r=Math.min(0,this.viewports[0].$viewport.height()-n);if(t<r)for(let t of this.viewports)t.$content.css("top",`${r}px`);this.updateScrollbar()}}createTrackScrollbar(t){const e=pe();if(t.columnContainer.querySelector(".igv-scrollbar-column").appendChild(e),e.style.height=`${this.track.height}px`,this.outerScroll=e,!1===kl.has(this.track.type)){const n=pe();e.appendChild(n),this.innerScroll=n,this.addTrackScrollMouseHandlers(t)}}createTrackDragHandle(t){const e="ideogram"===this.track.type||"ruler"===this.track.type?"igv-track-drag-shim":"igv-track-drag-handle";this.dragHandle=pe({class:e}),t.columnContainer.querySelector(".igv-track-drag-column").appendChild(this.dragHandle),this.dragHandle.style.height=`${this.track.height}px`,this.addTrackDragMouseHandlers(t)}createTrackGearPopup(t){this.gearContainer=pe(),t.columnContainer.querySelector(".igv-gear-menu-column").appendChild(this.gearContainer),this.gearContainer.style.height=`${this.track.height}px`,!0===this.track.ignoreTrackMenu||(this.gear=pe(),this.gearContainer.appendChild(this.gear),this.gear.appendChild(we("cog")),this.trackGearPopup=new yl(this.gear),this.addTrackGearMouseHandlers())}addAxisEventListener(t){this.boundAxisClickHander=function(t){this.browser.dataRangeDialog.configure(this),this.browser.dataRangeDialog.present(de(this.browser.columnContainer))}.bind(this),t.addEventListener("click",this.boundAxisClickHander)}removeAxisEventListener(t){t.removeEventListener("click",this.boundAxisClickHander)}addTrackScrollMouseHandlers(t){this.boundTrackScrollMouseDownHandler=function(e){e.stopPropagation();const{y:n}=me(e);de(this.innerScroll).data("yDown",n.toString()),this.boundColumnContainerMouseMoveHandler=function(t){t.stopPropagation();const{y:e}=me(t);this.moveScroller(e-parseInt(de(this.innerScroll).data("yDown"))),de(this.innerScroll).data("yDown",e.toString())}.bind(this),t.columnContainer.addEventListener("mousemove",this.boundColumnContainerMouseMoveHandler)}.bind(this),this.innerScroll.addEventListener("mousedown",this.boundTrackScrollMouseDownHandler),this.boundColumnContainerMouseUpHandler=function(e){t.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler)}.bind(this),t.columnContainer.addEventListener("mouseup",this.boundColumnContainerMouseUpHandler)}removeTrackScrollMouseHandlers(){!1===kl.has(this.track.type)&&(this.innerScroll.removeEventListener("mousedown",this.boundTrackScrollMouseDownHandler),this.browser.columnContainer.removeEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.browser.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler))}addTrackDragMouseHandlers(t){if("ideogram"===this.track.id||"ruler"===this.track.id);else{let e;function n(n){n.preventDefault(),e=n.target,e.classList.add("igv-track-drag-handle-hover"),t.startTrackDrag(this)}function r(n){t.endTrackDrag(),e&&n.target!==e&&e.classList.remove("igv-track-drag-handle-hover"),e=void 0}function i(n){n.preventDefault(),void 0===e&&n.target.classList.add("igv-track-drag-handle-hover"),t.updateTrackDrag(this)}function o(t){t.preventDefault(),void 0===e&&t.target.classList.remove("igv-track-drag-handle-hover")}this.boundTrackDragMouseDownHandler=n.bind(this),this.dragHandle.addEventListener("mousedown",this.boundTrackDragMouseDownHandler),this.boundDocumentTrackDragMouseUpHandler=r.bind(this),document.addEventListener("mouseup",this.boundDocumentTrackDragMouseUpHandler),this.boundTrackDragMouseEnterHandler=i.bind(this),this.dragHandle.addEventListener("mouseenter",this.boundTrackDragMouseEnterHandler),this.dragHandle.addEventListener("mouseout",(t=>{t.preventDefault(),void 0===e&&t.target.classList.remove("igv-track-drag-handle-hover")})),this.boundTrackDragMouseOutHandler=o.bind(this),this.dragHandle.addEventListener("mouseout",this.boundTrackDragMouseOutHandler)}}removeTrackDragMouseHandlers(){"ideogram"===this.track.id||"ruler"===this.track.id||(this.dragHandle.removeEventListener("mousedown",this.boundTrackDragMouseDownHandler),document.removeEventListener("mouseup",this.boundDocumentTrackDragMouseUpHandler),this.dragHandle.removeEventListener("mouseup",this.boundTrackDragMouseEnterHandler),this.dragHandle.removeEventListener("mouseout",this.boundTrackDragMouseOutHandler))}addTrackGearMouseHandlers(){if(!0===this.track.ignoreTrackMenu);else{function t(t){t.preventDefault(),t.stopPropagation(),this.trackGearPopup.presentMenuList(Oo.trackMenuItemList(this))}this.boundTrackGearClickHandler=t.bind(this),this.gear.addEventListener("click",this.boundTrackGearClickHandler)}}removeTrackGearMouseHandlers(){!0===this.track.ignoreTrackMenu||this.gear.removeEventListener("click",this.boundTrackGearClickHandler)}dispose(){this.removeAxisEventListener(this.axis),this.axis.remove();for(let t of this.viewports)t.dispose();this.sampleNameViewport.dispose(),this.removeTrackScrollMouseHandlers(),this.outerScroll.remove(),this.removeTrackDragMouseHandlers(),this.dragHandle.remove(),this.removeTrackGearMouseHandlers(),this.gearContainer.remove(),"function"==typeof this.track.dispose&&this.track.dispose();const t=this.track;"function"==typeof t.dispose&&t.dispose();for(let e of Object.keys(t))t[e]=void 0;for(let t of Object.keys(this))this[t]=void 0;this.alert&&this.alert.container.remove(),this.disposed=!0}paintAxis(){if("function"==typeof this.track.paintAxis){const{width:t,height:e}=this.axisCanvas.getBoundingClientRect(),n=window.devicePixelRatio||1;this.axisCanvas.height=n*e,this.axisCanvas.width=n*t;const r=this.axisCanvas.getContext("2d");r.scale(n,n),this.track.paintAxis(r,t,e)}}}function Cl(t){const e=t.map((t=>t.getContentHeight()));return Math.max(...e)}function El(t,e){if(t.length<6)console.log("Skipping line: "+t.join(" "));else{var n={chr1:t[0],start1:Number.parseInt(t[1]),end1:Number.parseInt(t[2]),chr2:t[3],start2:Number.parseInt(t[4]),end2:Number.parseInt(t[5])};if(!(isNaN(n.start1)||isNaN(n.end1)||isNaN(n.start2)||isNaN(n.end2))){if(t.length>6&&"."!==t[6]&&(n.name=t[6]),t.length>7&&"."!==t[7]&&(n.score=Number(t[7])),t.length>8&&"."!==t[8]&&(n.strand1=t[8]),t.length>9&&"."!==t[9]&&(n.strand2=t[9]),e){const r=e.colorColumn;r&&r<t.length&&(n.color=no.createColorString(t[r]));const i=e.thicknessColumn;i&&i<t.length&&(n.thickness=t[i]),t.length>10&&e.columnNames&&e.columnNames.length===t.length&&(n.extras=t.slice(10))}return n.chr1===n.chr2&&(n.chr=n.chr1,n.start=Math.min(n.start1,n.start2),n.end=Math.max(n.end1,n.end2)),n}}}function Al(t,e){if(!(t.length<8))return{chr:t[0],start:Number.parseInt(t[1]),end:Number.parseInt(t[2]),color:no.createColorString(t[6]),value:Number(t[7])}}function Tl(t,e){if(!(t.length<6))return{chr:t[0],start:t[1],end:t[2],chr1:t[8],start1:Number.parseInt(t[9]),end1:Number.parseInt(t[10]),chr2:t[13],start2:Number.parseInt(t[14]),end2:Number.parseInt(t[15]),name:t[3],score:Number(t[4]),value:Number(t[5]),color:"."===t[7]?void 0:"0"===t[7]?"rgb(0,0,0)":t[7]};console.log("Skipping line: "+t.join(" "))}const Ll=new Set(["transcript","primary_transcript","processed_transcript","mRNA","mrna","lnc_RNA","miRNA","ncRNA","rRNA","scRNA","snRNA","snoRNA","tRNA"]),Ml=new Set(["CDS","cds"]),Rl=new Set(["start_codon","stop_codon"]),Il=new Set(["5UTR","3UTR","UTR","five_prime_UTR","three_prime_UTR","3'-UTR","5'-UTR"]),Nl=new Set(["exon","coding-exon"]),Pl=new Set;for(let fd of[Ml,Rl,Il,Nl])for(let dd of fd)Pl.add(dd);function Ol(t){return t.includes("intron")}function Fl(t){return Ml.has(t)||Rl.has(t)}function Dl(t){return Il.has(t)}function Bl(t){return Ll.has(t)||t.endsWith("RNA")||t.endsWith("transcript")}function zl(t){return Pl.has(t)||t.endsWith("RNA")||Ol(t)}const Hl=new Set(["id","parent","name"]);class Vl{constructor(t){Object.assign(this,t)}popupData(t){const e=this.geneObject?this.geneObject.popupData():[];if(this.geneObject&&e.push("<hr/>"),this.name&&e.push({name:"Name",value:this.name}),e.push({name:"Type",value:this.type}),e.push({name:"Source",value:this.source}),void 0!==this.score&&e.push({name:"Score",value:this.score}),this.attributeString){const t=$l(this.attributeString,this.delim);for(let[n,r]of t)void 0!==r&&r.length>0&&!Hl.has(n.toLowerCase())&&e.push({name:n+":",value:r})}return e.push({name:"Location",value:`${this.chr}:${_e(this.start+1)}-${_e(this.end)}`}),e}getAttributeValue(t){if(this.hasOwnProperty(t))return this[t];if(this._attributeCache||(this._attributeCache=new Map),this._attributeCache.has(t))return this._attributeCache.get(t);{const e=$l(this.attributeString,this.delim);let n;for(let[r,i]of e)if(r===t){n=i;break}return this._attributeCache.set(t,n),n}}}class jl extends Vl{constructor(t){super(t),this.exons=[],this.parts=[]}addExon(t){this.exons.push(t),this.start=Math.min(this.start,t.start),this.end=Math.max(this.end,t.end)}addPart(t){this.parts.push(t)}assembleParts(){if(0===this.parts.length)return;this.parts.sort((function(t,e){return t.start-e.start}));let t=this.parts[0].start,e=this.parts[0].end;for(let n=1;n<this.parts.length;n++){const r=this.parts[n];if(!Ol(r.type))if(r.start<=e)e=Math.max(e,r.end);else{this.findExonContaining({start:t,end:e})||this.exons.push({start:t,end:e,psuedo:!0}),t=r.start,e=r.end}}this.findExonContaining({start:t,end:e})||(this.exons.push({start:t,end:e,psuedo:!0}),this.start=Math.min(this.start,t),this.end=Math.max(this.end,e));for(let t of this.parts){const e=t.type;Fl(e)?this.addCDS(t):Dl(e)&&this.addUTR(t)}}findExonContaining({start:t,end:e}){for(let n of this.exons)if(n.end>=e&&n.start<=t)return n}addCDS(t){let e;const n=this.exons;for(let r of n)if(r.start<=t.start&&r.end>=t.end){e=r;break}e?(e.cdStart=e.cdStart?Math.min(t.start,e.cdStart):t.start,e.cdEnd=e.cdEnd?Math.max(t.end,e.cdEnd):t.end):console.error("No exon found spanning "+t.start+"-"+t.end),this.cdStart=this.cdStart?Math.min(t.start,this.cdStart):t.start,this.cdEnd=this.cdEnd?Math.max(t.end,this.cdEnd):t.end}addUTR(t){let e;const n=this.exons;for(let r=0;r<n.length;r++)if(n[r].start<=t.start&&n[r].end>=t.end){e=n[r];break}e?t.start===e.start&&t.end===e.end?e.utr=!0:(t.end<e.end&&(e.cdStart=t.end),t.start>e.start&&(e.cdEnd=t.start)):console.error("No exon found spanning "+cds.start+"-"+cds.end)}finish(){this.assembleParts();var t=this.cdStart,e=this.cdEnd;this.exons.sort((function(t,e){return t.start-e.start})),t&&this.exons.forEach((function(n){(n.end<t||n.start>e)&&(n.utr=!0)}))}popupData(t){const e=super.popupData(t);for(let n of this.exons)if(!n.pseudo&&t>=n.start&&t<n.end&&"function"==typeof n.popupData){e.push("<hr/>");const r=n.popupData(t);for(let t of r)e.push(t)}for(let n of this.parts)if(t>=n.start&&t<n.end&&"function"==typeof n.popupData){e.push("<hr/>");const r=n.popupData(t);for(let t of r)e.push(t)}return e}}function Ul(t,e){const n=e.format;if(t.length<9)return;const r="gff3"===n?"=":" ";return new Vl({source:t[1],type:t[2],chr:t[0],start:parseInt(t[3])-1,end:parseInt(t[4]),score:"."===t[5]?void 0:Number(t[5]),strand:t[6],phase:"."===t[7]?0:parseInt(t[7]),attributeString:t[8],delim:r})}function ql(t,e){const n=Ul(t,e);if(!n)return;const r=$l(n.attributeString,n.delim);for(let[t,e]of r){const r=t.toLowerCase();"color"===r||"colour"===r?n.color=no.createColorString(e):"ID"===t?n.id=e:"Parent"===t&&(n.parent=e)}return n}function Wl(t,e){const n=Ul(t,e);if(!n)return;const r=$l(n.attributeString,n.delim);let i,o;switch(n.type){case"gene":i="gene_id";break;case"transcript":i="transcript_id",o="gene_id";break;default:o="transcript_id"}for(let[t,e]of r){const r=t.toLowerCase();"color"===r||"colour"===r?n.color=no.createColorString(e):t===i?n.id=e:t===o&&(n.parent=e)}return n}function $l(t,e){var n=[];for(let r of t.split(";")){r=r.trim();const t=r.indexOf(e);if(t>0&&t<r.length-1){const e=r.substring(0,t);let i=Gl(decodeURIComponent(r.substring(t+1).trim()));n.push([e,i])}}return n}function Gl(t){return t.startsWith('"')&&t.endsWith('"')&&(t=t.substr(1,t.length-2)),t}class Zl{constructor(t){this.message=t}}function Xl(t,e){if(t.length<3)return;e&&e.gffTags;const n=t[0],r=parseInt(t[1]),i=t.length>2?parseInt(t[2]):r+1;if(isNaN(r)||isNaN(i))return new Zl("Unparsable bed record.");const o=new oh({chr:n,start:r,end:i,score:1e3});try{if(t.length>3){if(t[3].indexOf(";")>0&&t[3].indexOf("=")>0){const e=$l(t[3],"=");o.attributes={};for(let t of e)o.attributes[t[0]]=t[1]}o.name||(o.name="."===t[3]?"":t[3])}if(t.length>4&&(o.score="."===t[4]?0:Number(t[4]),isNaN(o.score)))return o;if(t.length>5&&(o.strand=t[5],"."!==o.strand&&"+"!==o.strand&&"-"!==o.strand))return o;if(t.length>6&&(o.cdStart=parseInt(t[6]),isNaN(o.cdStart)))return o;if(t.length>7&&(o.cdEnd=parseInt(t[7]),isNaN(o.cdEnd)))return o;if(t.length>8&&"."!==t[8]&&"0"!==t[8]&&(o.color=no.createColorString(t[8])),t.length>11){const e=parseInt(t[9]);if(e>1e3)return o;const n=t[10].replace(/,$/,"").split(","),i=t[11].replace(/,$/,"").split(",");if(n.length!==i.length||e!==n.length)return o;const s=[];for(let t=0;t<e;t++){const e=r+parseInt(i[t]),o=e+parseInt(n[t]);s.push({start:e,end:o})}th(s,o.cdStart,o.cdEnd),o.exons=s}if(e){let n=e.thicknessColumn,r=e.colorColumn;r&&r<t.length&&(o.color=no.createColorString(t[r])),n&&n<t.length&&(o.thickness=t[n])}}catch(t){}return o}function Yl(t,e){if(t.length<=15)return;return{swScore:Number.parseInt(t[1]),milliDiv:Number.parseInt(t[2]),milliDel:Number.parseInt(t[3]),milliIns:Number.parseInt(t[4]),chr:t[5],start:Number.parseInt(t[6]),end:Number.parseInt(t[7]),strand:t[9],repName:t[10],repClass:t[11],repFamily:t[12],repStart:Number.parseInt(t[13]),repEnd:Number.parseInt(t[14]),repLeft:Number.parseInt(t[15])}}function Kl(t,e){var n=void 0===e.shift?0:1;if(t.length<=9+n)return;const r=parseInt(t[5+n]),i=parseInt(t[6+n]);var o={name:t[0+n],chr:t[1+n],strand:t[2+n],start:parseInt(t[3+n]),end:parseInt(t[4+n]),cdStart:r,cdEnd:i,id:t[0+n]},s=parseInt(t[7+n]),a=t[8+n].split(","),c=t[9+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function Ql(t,e){var n=void 0===e.shift?0:1;if(t.length<=11+n)return;const r=parseInt(t[5+n]),i=parseInt(t[6+n]),o={name:t[11+n],chr:t[1+n],strand:t[2+n],start:parseInt(t[3+n]),end:parseInt(t[4+n]),cdStart:r,cdEnd:i,id:t[0+n]},s=parseInt(t[7+n]),a=t[8+n].split(","),c=t[9+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function Jl(t,e){var n=void 0===e.shift?0:1;if(t.length<=10+n)return;const r=parseInt(t[6+n]),i=parseInt(t[7+n]);var o={name:t[0+n],id:t[1+n],chr:t[2+n],strand:t[3+n],start:parseInt(t[4+n]),end:parseInt(t[5+n]),cdStart:r,cdEnd:i},s=parseInt(t[8+n]),a=t[9+n].split(","),c=t[10+n].split(","),l=[];for(let t=0;t<s;t++){const e=parseInt(a[t]),n=parseInt(c[t]);l.push({start:e,end:n})}return th(l,r,i),o.exons=l,o}function th(t,e,n){for(let r of t){const t=r.end,i=r.start;t<e||i>n?r.utr=!0:(e>=i&&e<=t&&(r.cdStart=e),n>=i&&n<=t&&(r.cdEnd=n))}}function eh(t,e){var n,r,i,o,s,a,c;if(!(t.length<9))return n=t[0],r=parseInt(t[1]),i=parseInt(t[2]),s=t[3],a=Number(t[4]),o=t[5].trim(),c=Number(t[6]),0===a&&(a=c),{chr:n,start:r,end:i,name:s,score:a,strand:o,signal:c,pValue:Number(t[7]),qValue:Number(t[8])}}function nh(t,e){if(t.length<=3)return;const n={chr:t[0],start:parseInt(t[1]),end:parseInt(t[2]),value:Number(t[3])};if(e){let r=e.colorColumn;r&&r<t.length&&(n.color=no.createColorString(t[r]))}return n}function rh(t,e){const n=e.wig;if(n&&"fixedStep"===n.format){const e=n.index*n.step+n.start,r=e+n.span,i=Number(t[0]);return++n.index,isNaN(i)?null:{chr:n.chrom,start:e,end:r,value:i}}if(n&&"variableStep"===n.format){if(t.length<2)return null;const e=parseInt(t[0],10)-1,r=e+n.span,i=Number(t[1]);return isNaN(i)?null:{chr:n.chrom,start:e,end:r,value:i}}return nh(t)}function ih(t,e){if(t.length<6)return;const n=["bin","chr","start","end","name","score","strand","refNCBI","refUCSC","observed","molType","class","valid","avHet","avHetSE","func","locType","weight","exceptions","submitterCount","submitters","alleleFreqCount","alleles","alleleNs","alleleFreqs","bitfields"],r={chr:t[1],start:Number.parseInt(t[2]),end:Number.parseInt(t[3]),name:t[4],score:Number.parseInt(t[5])},i=Math.min(t.length,n.length);for(let e=6;e<i;e++)r[n[e]]=t[e];return r}class oh{constructor(t){Object.assign(this,t)}getAttributeValue(t){return this.hasOwnProperty(t)?this[t]:this.attributes?this.attributes[t]:void 0}}function sh(t,e){if(!(t.length<7)){var n=t[0],r=t[1],i=parseInt(t[2]),o=parseInt(t[3]),s=parseInt(t[4]),a=parseInt(t[5]),c=t[6],l={chr:n,name:r,junction_left:i,junction_right:o,num_junction_reads:s,num_spanning_frags:a,spanning_frag_coords:[],start:-1,end:-1},h=i,u=o;if(a>0)for(var f=c.split(","),d=0;d<f.length;d++){var p=f[d].split("-"),g=p[0],m=p[1];g<h&&(h=g),m>u&&(u=m),l.spanning_frag_coords.push({left:g,right:m})}return l.start=h,l.end=u,l}}function ah(t,e){if(t.length<7)return null;const n={chr:t[0],start:parseInt(t[1])-1,end:parseInt(t[2]),"Strongest SNP-risk allele":t[3],"Disease/Phenotype":t[4],"P-value":t[5],"Odds ratio or beta":t[6]};return t.length>6&&(n.PUBMEDID=`<a target = "blank" href = "https://www.ncbi.nlm.nih.gov/pubmed/${t[7]}">${t[7]}</a>`),n}function ch(t,e){const n=e.customFormat;if(t.length<n.fields.length)return;const r=n.coords||0,i=t[n.chr],o=parseInt(t[n.start])-r,s={chr:i,start:o,end:void 0!==n.end?parseInt(t[n.end]):o+1};return n.fields&&n.fields.forEach((function(e,r){r!==n.chr&&r!==n.start&&r!==n.end&&(s[e]=t[r])})),s}function lh(t,e){const n=e.columnNames;if(!n)throw Error("Sample names are not defined. Missing column headers?");const r=n.length-3,i=t[0],o=parseInt(t[1]),s=parseInt(t[2]),a=t.slice(3).map(Number);return a.length==r?{chr:i,start:o,end:s,values:a}:void console.warn(`${i}:${o}-${s} row contains ${a.length} sample columns instead of the expected ${r} columns. Skipping...`)}class hh{constructor(t){this.config=t,this.header={},t.nameField&&(this.header.nameField=t.nameField),this.skipRows=0,t.decode?(this.decode=t.decode,this.delimiter=t.delimiter||"\t"):t.format&&(this.header.format=t.format.toLowerCase(),this.setDecoder(this.header.format)),this.delimiter||(this.delimiter="\t")}async parseHeader(t){let e,n,r=this.header;for(;void 0!==(n=await t.nextLine());)if(n.startsWith("track")||n.startsWith("#track")){let t=uh(n);Object.assign(r,t)}else if(n.startsWith("browser"));else if(n.startsWith("#columns")){let t=fh(n);Object.assign(r,t)}else if(n.startsWith("##gff-version 3"))r.format="gff3";else if(n.startsWith("#gffTags"))r.gffTags=!0;else{if(n.startsWith("fixedStep")||n.startsWith("variableStep"))break;if(n.startsWith("#")){const t=n.split(this.delimiter||"\t");t.length>1&&(e=t)}else{this.setDecoder(r.format);const t=n.split(this.delimiter||"\t");try{const n=Object.assign({columnNames:e},r);if(this.decode(t,n))break;t.length>1&&(e=t)}catch(n){t.length>1&&(e=t)}}}if(e){r.columnNames=e;for(let t=0;t<e.length;t++)"color"===e[t]||"colour"===e[t]?r.colorColumn=t:"thickness"===e[t]&&(r.thicknessColumn=t)}return this.header=r,r}async parseFeatures(t){const e=[],n=this.decode,r=this.header.format,i=this.delimiter||"\t";let o,s=0,a=0;for(;void 0!==(o=await t.nextLine());){if(s++,s<=this.skipRows)continue;if(!o||o.startsWith("track")||o.startsWith("#")||o.startsWith("browser"))continue;if("wig"===r&&o.startsWith("fixedStep")){this.header.wig=dh(o);continue}if("wig"===r&&o.startsWith("variableStep")){this.header.wig=ph(o);continue}const t=o.split(i);if(t.length<1)continue;const c=n(t,this.header);c instanceof Zl?(a++,a>0&&console.error(`Error parsing line '${o}': ${c.message}`)):c&&e.push(c)}return n===El&&function(t){if(0==t.length)return;const e=t[0];if(void 0===e.score&&void 0!==e.name){for(let e of t)if(!("number"==typeof(n=e.name)?n-n==0:"string"==typeof n&&""!==n.trim()&&(Number.isFinite?Number.isFinite(+n):isFinite(+n)))&&"."!==e.name)return;for(let e of t)e.score=Number(e.name),delete e.name}var n;const r=t.filter((t=>t.chr1!==t.chr2));for(let e of r){const n=Object.assign({},e);n.dup=!0,t.push(n),e.chr=e.chr1,e.start=e.start1,e.end=e.end1,n.chr=n.chr2,n.start=n.start2,n.end=n.end2}}(e),e}setDecoder(t){switch(t){case"narrowpeak":case"broadpeak":case"regionpeak":case"peaks":this.decode=eh,this.delimiter=this.config.delimiter||/\s+/;break;case"bedgraph":this.decode=nh,this.delimiter=/\s+/;break;case"wig":this.decode=rh,this.delimiter=this.config.delimiter||/\s+/;break;case"gff3":case"gff":this.decode=ql,this.delimiter="\t";break;case"gtf":this.decode=Wl,this.delimiter="\t";break;case"fusionjuncspan":this.decode=sh,this.delimiter=this.config.delimiter||/\s+/;break;case"gtexgwas":this.skipRows=1,this.decode=ah,this.delimiter="\t";break;case"refflat":this.decode=Jl,this.delimiter=this.config.delimiter||/\s+/;break;case"genepred":this.decode=Kl,this.delimiter=this.config.delimiter||/\s+/;break;case"genepredext":this.decode=Ql,this.delimiter=this.config.delimiter||/\s+/;break;case"ensgene":this.decode=Kl,this.header.shift=1,this.delimiter=this.config.delimiter||/\s+/;break;case"refgene":this.decode=Ql,this.delimiter=this.config.delimiter||/\s+/,this.header.shift=1;break;case"bed":this.decode=Xl,this.delimiter=this.config.delimiter||/\s+/;break;case"bedpe":this.decode=El,this.delimiter=this.config.delimiter||"\t";break;case"bedpe-domain":this.decode=Al,this.headerLine=!0,this.delimiter=this.config.delimiter||"\t";break;case"bedpe-loop":this.decode=El,this.delimiter=this.config.delimiter||"\t",this.header={colorColumn:7};break;case"interact":this.decode=Tl,this.delimiter=this.config.delimiter||/\s+/;break;case"snp":this.decode=ih,this.delimiter="\t";break;case"rmsk":this.decode=Yl,this.delimiter="\t";break;case"gcnv":this.decode=lh,this.delimiter="\t";break;default:const e=function(t){return us&&us[t]?function(t){const e=t.fields,n=["chr","start","end"];for(let r=0;r<e.length;r++)for(let i of n)i===e[r]&&(t[i]=r);return t}(us[t]):void 0}(t);void 0!==e?(this.decode=ch,this.header.customFormat=e,this.delimiter=e.delimiter||"\t"):(this.decode=Xl,this.delimiter=this.config.delimiter||/\s+/)}}}function uh(t){const e={},n=t.split(/(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g);let r;const i=[];for(let t of n)t&&0!==t.trim().length&&(t.endsWith("=")?r=t:r?(i.push(r+t),r=void 0):i.push(t));for(let t of i){if(!t)return;var o=t.split("=",2);if(2===o.length){const t=o[0].trim(),n=o[1].trim();if(e.hasOwnProperty(t)){let r=e[t];Array.isArray(r)?r.push(n):e[t]=[r,n]}else e[t]=n}}return"interact"==e.type?e.format="interact":"gcnv"===e.type&&(e.format="gcnv"),e}function fh(t){let e={},n=t.split(/\s+/);if(2===n.length){n[1].split(";").forEach((function(t){let n=t.split("=");"color"===n[0]?e.colorColumn=Number.parseInt(n[1])-1:"thickness"===n[0]&&(e.thicknessColumn=Number.parseInt(n[1])-1)}))}return e}function dh(t){const e=t.split(/\s+/);return{format:"fixedStep",chrom:e[1].split("=")[1],start:parseInt(e[2].split("=")[1],10)-1,step:parseInt(e[3].split("=")[1],10),span:e.length>4?parseInt(e[4].split("=")[1],10):1,index:0}}function ph(t){const e=t.split(/\s+/);return{format:"variableStep",chrom:e[1].split("=")[1],span:e.length>2?parseInt(e[2].split("=")[1],10):1}}class gh{constructor(t){switch(this.type=t||"seg",this.type){case"mut":this.sampleColumn=3,this.chrColumn=0,this.startColumn=1,this.endColumn=2,this.dataColumn=4;break;case"maf":this.sampleColumn=15,this.chrColumn=4,this.startColumn=5,this.endColumn=6,this.dataColumn=8;break;default:this.sampleColumn=0,this.chrColumn=1,this.startColumn=2,this.endColumn=3}}async parseHeader(t){let e;for(;void 0!==(e=await t.nextLine());)if(!e.startsWith("#")){const t=e.split("\t");this.header={headings:t};break}return this.header}async parseFeatures(t){const e=[];let n;this.header||(this.header=await this.parseHeader(t)),"seg"===this.type&&(this.dataColumn=this.header.headings.length-1),this.header.headings.length>5&&(n=this.extractExtraColumns(this.header.headings));const r=this.header.headings[this.dataColumn];let i;for(;void 0!==(i=await t.nextLine());){const t=i.split("\t"),o="seg"===this.type?Number(t[this.dataColumn]):t[this.dataColumn];if(t.length>this.dataColumn){const i=new mh({sample:t[this.sampleColumn],chr:t[this.chrColumn],start:parseInt(t[this.startColumn])-1,end:parseInt(t[this.endColumn]),value:o,valueColumnName:r});if(n){const e=this.extractExtraColumns(t);i.setAttributes({names:n,values:e})}e.push(i)}}return e}extractExtraColumns(t){const e=[];for(let n=0;n<t.length;n++)n!==this.chrColumn&&n!==this.startColumn&&n!==this.endColumn&&n!==this.sampleColumn&&e.push(t[n]);return e}}class mh{constructor({sample:t,chr:e,start:n,end:r,value:i,valueColumnName:o}){this.sample=t,this.chr=e,this.start=n,this.end=r,this.value=i,this.valueColumnName=o}setAttributes({names:t,values:e}){this.attributeNames=t,this.attributeValues=e}getAttribute(t){if(this.attributeNames){const e=this.attributeNames.indexOf(t);if(e>=0)return this.attributeValues[e]}}popupData(t,e){const n=new Set(["chr","start","end","sample","value","row","color","sampleKey","uniqueSampleKey","sampleId","chromosome","uniquePatientKey"]),r=this.chr+":"+_e(this.start+1)+"-"+_e(this.end),i=[{name:"Sample",value:this.sample},{name:"Location",value:r},{name:this.valueColumnName?Ee(this.valueColumnName):"Value",value:this.value}];if("mut"===t&&"hg38"===e){const t=this.extractCravatLink(e);t&&(i.push("<hr/>"),i.push({html:t}),i.push("<hr/>"))}if(this.attributeNames&&this.attributeNames.length>0)for(let t=0;t<this.attributeNames.length;t++)!n.has(this.attributeNames[t])&this.valueColumnName!==this.attributeNames[t]&&i.push({name:Ee(this.attributeNames[t]),value:this.attributeValues[t]});return i}extractCravatLink(t){let e,n;if(this.attributeNames&&this.attributeNames.length>0)for(let r=0;r<this.attributeNames.length;r++)if(e||"Reference_Allele"!==this.attributeNames[r]||(e=this.attributeValues[r]),!n&&this.attributeNames[r].startsWith("Tumor_Seq_Allele")&&this.attributeValues[r]!==e&&(n=this.attributeValues[r]),e&&n)return bc.getCravatLink(this.chr,this.start+1,e,n,t)}}function vh(t){const e=new bh;e.chr=t[0],e.pos=parseInt(t[1]),e.names=t[2],e.referenceBases=t[3],e.alternateBases=t[4],e.quality=t[5],e.filter=t[6],e.info={};const n=t[7];if(n)for(let t of n.split(";")){var r=t.split("=");e.info[r[0]]=r[1]}return e.init(),e}class bh{init(){const t=this.referenceBases,e=this.alternateBases;if(this.info&&(this.info.VT?this.type=this.info.VT:this.info.SVTYPE?this.type="SV":this.info.PERIOD&&(this.type="STR")),void 0===this.type&&(this.type=function(t,e){const n=t.length;if(void 0===e)return"UNKNOWN";if(0===e.trim().length||"<NON_REF>"===e||"<*>"===e||"."===e)return"NONVARIANT";{const t=e.split(",").map((function(t){return 1===n&&1===t.length?"SNP":"<NON_REF>"===t?"NONVARIANT":"OTHER"}));let r=t[0];for(let e of t)if(e!==r)return"MIXED";return r}}(t,e)),"NONVARIANT"===this.type&&(this.heterozygosity=0),this.info.END)this.start=this.pos-1,this.info.CHR2&&this.info.CHR2!==this.chr?this.end=this.start+1:this.end=Number.parseInt(this.info.END);else if("NONVARIANT"===this.type)this.start=this.pos-1,this.end=this.start+t.length;else{const n=e.split(",").filter((t=>t.length>0));this.alleles=[],this.start=void 0,this.end=void 0;for(let e of n)if(this.alleles.push(e),"SV"!==this.type&&yh(e)){let n=e.length,r=t.length;const i=Math.min(n,r);let o=0;for(;o<i&&t.charCodeAt(o)===e.charCodeAt(o);)o++,n--,r--;for(;n>0&&r>0;){const i=o+n-1,s=o+r-1;if(e.charCodeAt(i)!==t.charCodeAt(s))break;n--,r--}for(;n>0&&r>0;){const i=o,s=o;if(e.charCodeAt(i)!==t.charCodeAt(s))break;o++,n--,r--}const s=this.pos+o-1,a=s+r;this.start=void 0===this.start?s:Math.min(this.start,s),this.end=void 0===this.end?a:Math.max(this.end,a)}void 0===this.start&&(this.start=this.pos-1,this.end=this.pos)}}popupData(t,e){const n=`${_e(this.pos)}`,r=this.start===this.end?`${_e(this.start)} | ${_e(this.start+1)}`:`${_e(this.start+1)}-${_e(this.end)}`,i=[{name:"Chr",value:this.chr},{name:"Pos",value:n},{name:"Loc",value:r},{name:"Names",value:this.names?this.names:""},{name:"Ref",value:this.referenceBases},{name:"Alt",value:this.alternateBases.replace("<","&lt;")},{name:"Qual",value:this.quality},{name:"Filter",value:this.filter}];if("SNP"===this.type){let t=this.referenceBases;if(1===t.length){let n=this.alternateBases.split(",");for(let r of n)if(1===r.length){let n=bc.getCravatLink(this.chr,this.pos,t,r,e);n&&(i.push("<hr/>"),i.push({html:n}))}}}if(this.hasOwnProperty("heterozygosity")&&i.push({name:"Heterozygosity",value:this.heterozygosity}),this.info){i.push({html:'<hr style="border-top: dotted 1px;border-color: #c9c3ba" />'});for(let t of Object.keys(this.info))i.push({name:t,value:xh(decodeURIComponent(this.info[t]))})}return i}isRefBlock(){return"NONVARIANT"===this.type}}const wh=new Set(["A","C","T","G"].map((t=>t.charCodeAt(0))));function yh(t){for(let e=0;e<t.length;e++)if(!wh.has(t.charCodeAt(e)))return!1;return!0}function xh(t,e){return void 0===e&&(e=","),Array.isArray(t)?t.join(e):t}class kh{construtor(){}async parseHeader(t,e){const n={};n.chrAliasTable=new Map;let r=await t.nextLine();if(!r.startsWith("##fileformat"))throw new Error("Invalid VCF file: missing fileformat line");for(n.version=r.substr(13);void 0!==(r=await t.nextLine())&&r.startsWith("#");){let t;const o={};if(r.startsWith("##")){if(r.startsWith("##INFO")||r.startsWith("##FILTER")||r.startsWith("##FORMAT")){const e=r.indexOf("<"),s=r.lastIndexOf(">");if(!(e>2&&s>0)){console.log("Malformed VCF header line: "+r);continue}const a=r.substring(2,e-1);n[a]||(n[a]={});const c=Ce(r.substring(e+1,s-1),",");for(let e of c){var i=e.split("=");i.length>1&&("ID"===i[0]?t=i[1]:o[i[0]]=i[1])}t&&(n[a][t]=o)}else if(r.startsWith("##contig")&&e){const t=r.indexOf("<ID=");let i=r.indexOf(",",t);-1==i&&(i=r.indexOf(">",t));const o=r.substring(t+4,i),s=e.getChromosomeName(o);n.chrAliasTable.set(s,o)}}else if(r.startsWith("#CHROM")){const t=r.split("\t");if(t.length>8){n.callSets=[];for(let e=9;e<t.length;e++)n.callSets.push({id:e,name:t[e]})}}}return this.header=n,n}async parseFeatures(t){const e=[],n=this.header.callSets,r=8+(n?n.length+1:0);let i;for(;void 0!==(i=await t.nextLine());)if(i&&!i.startsWith("#")){const t=i.split("\t");if(t.length===r){const r=vh(t);if(r.header=this.header,e.push(r),t.length>9){const e=_h(t[8].split(":"));r.calls={};for(let i=9;i<t.length;i++){const o=t[i],s=n[i-9],a={callSetName:s.name,info:{}};r.calls[s.id]=a,o.split(":").forEach((function(t,n){if(n===e.genotypeIndex)a.genotype=[],t.split(/[\|\/]/).forEach((function(t){a.genotype.push("."===t?t:parseInt(t))}));else a.info[e.fields[n]]=t}))}}r.info&&r.info.CHR2&&r.info.END&&e.push(Sh(r))}}return e}}function _h(t){const e={genotypeIndex:-1,fields:t};for(let n=0;n<t.length;n++)"GT"===t[n]&&(e.genotypeIndex=n);return e}function Sh(t){const e=t.info.CHR2,n=Number.parseInt(t.info.END);return{chr:e,start:n-1,end:n,_f:t}}class Ch{constructor(t){if(this.config=t,t.columns){if(void 0===t.columns.chromosome||void 0===t.columns.position||void 0===t.columns.value)throw Error("columns property must define chrCol, posCol, and valueCol");this.posCol=t.columns.position-1,this.chrCol=t.columns.chromosome-1,this.pvalueCol=t.columns.value-1}else this.posCol=2,this.chrCol=1,this.pvalueCol=3}async parseHeader(t){const e=await t.nextLine();return this.parseHeaderLine(e)}parseHeaderLine(t){if(this.columns=t.split(/\t/),!this.config.columns)for(let t=0;t<this.columns.length;t++){switch(this.columns[t].toLowerCase()){case"chr":case"chromosome":case"chr_id":this.chrCol=t;break;case"bp":case"pos":case"position":case"chr_pos":this.posCol=t;break;case"p":case"pval":case"pvalue":case"p-value":case"p.value":this.valueCol=t}}return this.columns}async parseFeatures(t){const e=[],n=t.nextLine();let r;for(this.columns||this.parseHeaderLine(n);void 0!==(r=t.nextLine());){const t=r.split(/\t/);if(t.length===this.columns.length){const n=t[this.chrCol],i=parseInt(t[this.posCol])-1,o=i+1,s=Number(t[this.valueCol]);e.push(new Eh({chr:n,start:i,end:o,value:s,line:r,columns:this.columns}))}}return e}}class Eh{constructor({chr:t,start:e,end:n,value:r,line:i,columns:o}){this.chr=t,this.start=e,this.end=n,this.value=r,this.line=i,this.columns=o}popupData(){const t=this.line.split(/\t/);return this.columns.map((function(e,n){return{name:e,value:t[n]}}))}getAttribute(t){const e=this.line.split(/\t/);for(let n=0;n<this.columns.length;n++)if(this.columns[n]===t)return e[n]}}var Ah=new RegExp("([^:]*)\\(([^)]*)\\)"),Th=new RegExp("([^:]*):([^(]*)\\(([^)]*)\\)");class Lh{constructor(t){const e=t?t.decode:void 0;this.nameField=t?t.nameField:void 0,this.skipRows=0,this.decode=e||Oh,this.delimiter="\t"}async parseHeader(t){let e,n;for(;(e=await t.nextLine())&&(e.startsWith("track")||e.startsWith("#")||e.startsWith("browser"));)if(e.startsWith("track")||e.startsWith("#track")){let t=Ih(e);n?Object.assign(n,t):n=t}else if(e.startsWith("#columns")){let t=Nh(e);n?Object.assign(n,t):n=t}else e.startsWith("##gff-version 3")&&(this.format="gff3",n||(n={}),n.format="gff3");return this.header=n,n}async parseFeatures(t){const e=[],n=this.decode,r=this.delimiter||"\t";let i,o=0;for(;void 0!==(i=t.nextLine());){if(o++,o<=this.skipRows||i.startsWith("track")||i.startsWith("#")||i.startsWith("browser"))continue;let t=s();if(t.length<1)continue;if(!this.aed){this.aed=Rh(t);continue}const r=n.call(this,t,undefined);r&&e.push(r)}return e;function s(){for(var t,e,n=[],o="",s=!1;i||""===i;){for(t=0;t<i.length;t++)(e=i.charAt(t))===r?s?o+=e:(n.push(o),o=""):'"'===e?t+1<i.length&&'"'===i.charAt(t+1)?(s&&(o+='"'),t++):s=!s:o+=e;if(!s)break;o+="\n",i=nextLine()}return n.push(o),n}}}function Mh(t){var e=Th.exec(t);if(e)return{namespace:e[1],name:e[2],type:e[3]};if(e=Ah.exec(t))return{namespace:"?",name:e[1],type:e[2]};throw new Error("Error parsing the header row of AED file - column not in ns:name(ns:type) format")}function Rh(t){var e,n,r;for(e={columns:[],metadata:{}},n=0;n<t.length;n++)r=Mh(t[n]),e.columns.push(r);return e}function Ih(t){const e={},n=t.split(/(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g);let r;const i=[];for(let t of n)t&&0!==t.trim().length&&(t.endsWith("=")>0?r=t:r?(i.push(r+t),r=void 0):i.push(t));for(let t of i){if(!t)return;var o=t.split("=",2);if(2===o.length){const t=o[0].trim(),n=o[1].trim();e[t]=n}}return e}function Nh(t){let e={},n=t.split(/\s+/);if(2===n.length){n[1].split(";").forEach((function(t){let n=t.split("=");"color"===n[0]?e.colorColumn=Number.parseInt(n[1])-1:"thickness"===n[0]&&(e.thicknessColumn=Number.parseInt(n[1])-1)}))}return e}function Ph(t,e){var n,r,i=t.columns;this.aed=t,this.allColumns=e,this.chr=null,this.start=null,this.end=null,this.score=1e3,this.strand=".",this.cdStart=null,this.cdEnd=null,this.name=null,this.color=null;for(let t=0;t<e.length;t++)if(n=e[t]){"aed:Integer"===(r=i[t]).type&&(n=parseInt(n));var o=[];if(r.namespace.length>0)for(let t=0;t<r.namespace.length;t++)o.push(r.namespace.charCodeAt(t));"bio"===r.namespace.trim()?"sequence"===r.name?this.chr=n:"start"===r.name?this.start=n:"end"===r.name?this.end=n:"cdsMin"===r.name?this.cdStart=n:"cdsMax"===r.name?this.cdEnd=n:"strand"===r.name&&(this.strand=n):"aed"===r.namespace?"name"===r.name&&(this.name=n):"style"===r.namespace&&"color"===r.name&&(this.color=no.createColorString(n))}}function Oh(t,e){var n,r,i,o,s,a,c=0,l=this.aed.columns;if(t.length===l.length){for(a=0;a<t.length;a++)o=l[a],""!==(i=t[a])&&c++,"name"===o.name&&"aed"===o.namespace?n=i:"value"===o.name&&"aed"===o.namespace&&(r=i);if(2===c&&n&&r)return s=Mh(n),this.aed.metadata[s.namespace]||(this.aed.metadata[s.namespace]={}),void(this.aed.metadata[s.namespace][s.name]||(this.aed.metadata[s.namespace][s.name]={type:s.type,value:r}));var h=new Ph(this.aed,t);if(h.chr&&(h.start||0===h.start)&&h.end)return h;console.log("Cannot parse feature: "+t.join(","))}else console.log("Corrupted AED file row: "+t.join(","))}function Fh(t){return"string"==typeof t||t instanceof String?new Dh(t):new Bh(t)}Ph.prototype.popupData=function(){for(var t=[],e=this.aed,n=0;n<this.allColumns.length;n++){var r=this.allColumns[n],i=e.columns[n].name;"sequence"!==i&&"color"!==i&&r&&t.push({name:i,value:r})}return t};class Dh{constructor(t){this.data=t,this.ptr=0}nextLine(){var t=this.ptr,e=this.data.indexOf("\n",t),n=this.data;if(e>0)return this.ptr=e+1,e>t&&"\r"===n.charAt(e-1)?n.substring(t,e-1):n.substring(t,e);var r=n.length;return this.ptr=r,t>=r?void 0:n.substring(t)}}class Bh{constructor(t){this.data=t,this.length=this.data.length,this.ptr=0}nextLine(){var t,e;if(e="",!(this.ptr>=this.length)){for(var n=this.ptr;n<this.length;n++)if("\r"!==(t=String.fromCharCode(this.data[n]))){if("\n"===t)break;e+=t}return this.ptr=n+1,e}}}class zh{constructor(t){this.config=t,this.filePtr=0,this.bufferPtr=0,this.buffer}async nextLine(){let t;try{for(;;){const e=this.buffer?this.buffer.length:0;for(;this.bufferPtr<e;){const e=String.fromCharCode(this.buffer[this.bufferPtr++]);if("\r"!==e){if("\n"===e)return t;t=t?t+e:e}}if(this.eof)return t;await this.readNextBlock()}}catch(e){return console.warn(e),this.eof=!0,t}}async readNextBlock(){const t=gs(this.config,{range:{start:this.filePtr,size:26}}),e=$i(await go.loadArrayBuffer(this.config.url,t));if(0===e)this.eof=!0,this.buffer=void 0;else{const t=gs(this.config,{range:{start:this.filePtr,size:e}}),n=await go.loadArrayBuffer(this.config.url,t);n.byteLength<e&&(this.eof=!0),this.buffer=Wi(n),this.bufferPtr=0,this.filePtr+=n.byteLength}}}class Hh{constructor(t,e){var n;this.config=t||{},this.genome=e,this.indexURL=t.indexURL,this.indexed=t.indexed,je(this.config.url)?this.filename=this.config.url.name:ys(this.config.url)?(this.indexed=!1,this.dataURI=t.url):(n=ze(this.config.url),this.filename=t.filename||n.file),this.parser=this.getParser(this.config),"vcf"!==this.config.format||this.config.indexURL||console.warn("Warning: index file not specified. The entire vcf file will be loaded.")}async defaultVisibilityWindow(){if(this.config.indexURL){const t=await this.getIndex();if(t&&t.lastBlockPosition){let e=0;const n=1e4;for(let n of t.chromosomeNames){const t=this.genome.getChromosome(n);t&&(e+=t.bpLength)}return Math.round(e/t.lastBlockPosition*n)}}}async readFeatures(t,e,n){return await this.getIndex()?(this.indexed=!0,this.loadFeaturesWithIndex(t,e,n)):this.dataURI?(this.indexed=!1,this.loadFeaturesFromDataURI()):(this.indexed=!1,this.loadFeaturesNoIndex())}async readHeader(){if(this.dataURI)return await this.loadFeaturesFromDataURI(this.dataURI),this.header;if(this.config.indexURL){const t=await this.getIndex();if(!t)throw new Error("Unable to load index: "+this.config.indexURL);let e;if(t.tabix)e=new zh(this.config);else{const n=Object.values(t.chrIndex).flatMap((t=>t.blocks)).map((t=>t.max)).reduce(((t,e)=>Math.min(t,e)),Number.MAX_SAFE_INTEGER),r=gs(this.config,{bgz:t.tabix,range:{start:0,size:n}});e=Fh(await go.loadString(this.config.url,r))}return this.header=await this.parser.parseHeader(e),this.header}{const t=gs(this.config),e=await go.loadString(this.config.url,t);let n=Fh(e);return this.header=await this.parser.parseHeader(n),n=Fh(e),this.features=await this.parser.parseFeatures(n),this.header}}getParser(t){switch(t.format){case"vcf":return new kh(t);case"seg":return new gh("seg");case"mut":return new gh("mut");case"maf":return new gh("maf");case"gwas":return new Ch(t);case"aed":return new Lh(t);default:return new hh(t)}}async loadFeaturesNoIndex(){if(this.features){const t=this.features;return delete this.features,t}{const t=gs(this.config),e=await go.loadString(this.config.url,t);if(!this.header){const t=Fh(e);this.header=await this.parser.parseHeader(t)}const n=Fh(e);return await this.parser.parseFeatures(n)}}async loadFeaturesWithIndex(t,e,n){const r=this.config,i=this.parser,o=this.index.tabix,s=o?this.index.sequenceIndexMap[t]:t;if(void 0===s)return[];const a=this.genome,c=this.index.blocksForRange(s,e,n);if(c&&0!==c.length){const s=[];for(let l of c){const c=l.minv.block,h=l.minv.offset,u=l.maxv.offset;let f;if(o){let t=0;if(u>0){const e=gs(r,{range:{start:l.maxv.block,size:26}});t=$i(await go.loadArrayBuffer(r.url,e))}f=l.maxv.block+t}else f=l.maxv.block;const d=gs(r,{range:{start:c,size:f-c+1}});let p;if(o){p=Wi(await go.loadArrayBuffer(r.url,d))}else p=await go.loadString(r.url,d);const g=Fh(h?p.slice(h):p);let m=await i.parseFeatures(g);m=m.filter((t=>void 0===t._f));let v=!1;for(let r=0;r<m.length;r++){const i=m[r];if((a?a.getChromosomeName(i.chr):i.chr)!==t){if(0===s.length)continue;break}if(i.start>n){s.push(i);break}i.end>=e&&i.start<=n&&(v||(v=!0,r>0&&s.push(m[r-1])),s.push(i))}}return s.sort((function(t,e){return t.start-e.start})),s}return[]}async getIndex(){return this.index?this.index:this.config.indexURL?(this.index=await this.loadIndex(),this.index):void 0}async loadIndex(){return Ya(this.config.indexURL,this.config,this.genome)}async loadFeaturesFromDataURI(){if(this.features){const t=this.features;return delete this.features,t}{const t=Yi(this.dataURI);let e=Fh(t);return this.header=await this.parser.parseHeader(e),this.header instanceof String&&this.header.startsWith("##gff-version 3")&&(this.format="gff3"),e=Fh(t),this.features=await this.parser.parseFeatures(e),this.features}}}const Vh=ke;class jh{constructor(t){this.config=t}async readFeatures(t,e,n){let r;r="function"==typeof this.config.url?this.config.url({chr:t,start:e,end:n}):this.config.url.replace("$CHR",t).replace("$START",e).replace("$END",n);let i,o=Object.assign({},this.config);void 0!==this.config.body&&("function"==typeof this.config.body?o.body=this.config.body({chr:t,start:e,end:n}):o.body=this.config.body.replace("$CHR",t).replace("$START",e).replace("$END",n));const s=await go.load(r,o);if(s&&(i="function"==typeof this.config.parser?this.config.parser(s):Vh(s)?JSON.parse(s):s),this.config.mappings){let t=Object.keys(this.config.mappings);for(let e of i)for(let n of t)e[n]=e[this.config.mappings[n]]}return i}}const Uh=function(t,e){this.config=t,this.genome=e,this.expandQueryInterval=!1};Uh.prototype.readFeatures=function(t,e,n){const r=Math.max(0,Math.floor(e));let i=Math.ceil(n);if(this.genome){const e=this.genome.getChromosome(t);e&&i>e.bpLength&&(i=e.bpLength)}const o=this.config.url+"?db="+this.config.db+"&table="+this.config.tableName+"&chr="+t+"&start="+r+"&end="+i;return go.loadJson(o,this.config).then((function(t){return t?(t.forEach((function(t){t.hasOwnProperty("exonStarts")&&t.hasOwnProperty("exonEnds")&&t.hasOwnProperty("exonCount")&&t.hasOwnProperty("cdsStart")&&t.hasOwnProperty("cdsEnd")&&function(t){var e,n,r,i,o,s;e=t.exonCount,n=t.exonStarts.split(","),r=t.exonEnds.split(","),i=[];for(var a=0;a<e;a++){var c={start:o=parseInt(n[a]),end:s=parseInt(r[a])};(t.cdsStart>s||t.cdsEnd<t.cdsStart)&&(c.utr=!0),t.cdsStart>=o&&t.cdsStart<=s&&(c.cdStart=t.cdsStart),t.cdsEnd>=o&&t.cdsEnd<=s&&(c.cdEnd=t.cdsEnd),i.push(c)}t.exons=i}(t)})),t):null}))};const qh=["Name","gene_name","gene","gene_id","alias","locus","name"];class Wh{constructor(t){this.format=t.format,this.nameField=t.nameField,this.filterTypes=void 0===t.filterTypes?new Set(["chromosome"]):new Set(t.filterTypes)}combineFeatures(t,e){let n;const r=this.filterTypes;if(t=t.filter((t=>void 0===r||!r.has(t.type))),"gff3"===this.format){const e=this.combineFeaturesById(t);n=this.combineFeaturesByType(e)}else n=this.combineFeaturesByType(t);return n.sort((function(t,e){return t.start-e.start})),this.numberExons(n,e),this.nameFeatures(n),n}combineFeaturesById(t){const e=new Map,n=[];for(let r of t)if(zl(r.type)||Bl(r.type)||!r.id)n.push(r);else{let t=e.get(r.chr);t||(t=new Map,e.set(r.chr,t));let n=t.get(r.id);n?n.push(r):t.set(r.id,[r])}for(let t of e.values())for(let e of t.values())if(e.length>1){const t=e[0];t.exons=[];for(let n of e)t.start=Math.min(t.start,n.start),t.end=Math.max(t.end,n.end),t.exons.push({start:n.start,end:n.end});n.push(t)}else n.push(e[0]);return n}combineFeaturesByType(t){const e=t.filter((t=>"gene"===t.type||t.type.endsWith("_gene"))),n=Object.create(null);for(let t of e)n[t.id]=t;const r=Object.create(null),i=[],o=new Set,s=this.filterTypes;t=t.filter((t=>void 0===s||!s.has(t.type)));for(let e of t)if("biological_region"===e.type&&console.log(),Bl(e.type)){const t=e.id;if(void 0!==t){const s=new jl(e);r[t]=s,i.push(s),o.add(e);const a=n[e.parent];a&&(s.geneObject=a,o.add(a))}}for(let e of t)if(zl(e.type)){const t=l(e);if(t)for(let n of t){let s=r[n];if(!s&&"gtf"===this.format){const t=Object.assign({},e);t.type="transcript",s=new jl(t),r[n]=s,i.push(s)}if(void 0!==s){if(a=e.type,Nl.has(a))if(t.length>1){const t=new Vl(e);s.addExon(t)}else s.addExon(e);else s.addPart(e);o.add(e)}}}var a;i.forEach((function(t){"function"==typeof t.finish&&t.finish()}));const c=t.filter((t=>!o.has(t)));for(let t of c)i.push(t);return i;function l(t){return t.parent&&""!==t.parent.trim()?t.parent.trim().split(","):null}}numberExons(t,e){for(let n of t)if(n.exons&&(!e||n.end<=e.end&&n.start>e.start))for(let t=0;t<n.exons.length;t++){n.exons[t].number="-"===n.strand?n.exons.length-t:t+1}}nameFeatures(t){for(let e of t)if(e.attributeString){const t="gff3"===this.format?"=":" ",n=$l(e.attributeString,t),r=new Map(n);if(this.nameField)e.name=r.get(this.nameField);else for(let t of qh)if(r.has(t)){e.name=r.get(t);break}}}}const $h=function(t){this.config=t,this.url=t.url,this.tissueId=t.tissueSiteDetailId,this.indexed=!0,this.datasetId=t.datasetId||"gtex_v8"};$h.prototype.readFeatures=async function(t,e,n){let r=t.startsWith("chr")?t:"chr"+t,i=Math.floor(e),o=Math.ceil(n),s=this.datasetId,a=this.url+"?chromosome="+r+"&start="+i+"&end="+o+"&tissueSiteDetailId="+this.tissueId+"&datasetId="+s;const c=await go.loadJson(a,{withCredentials:this.config.withCredentials});return c&&c.singleTissueEqtl?(c.singleTissueEqtl.forEach((function(t){t.chr=t.chromosome,t.position=t.pos,t.start=t.pos-1,t.end=t.start+1,t.snp=t.snpId,t.geneName=t.geneSymbol,t.geneId=t.gencodeId})),c.singleTissueEqtl):void 0};const Gh=function(t){this.config=t,this.url=t.url,this.cellConditionId=t.cellConditionId,this.valueThreshold=t.valueThreshold?t.valueThreshold:.05};Gh.prototype.readFeatures=function(t,e,n){var r=this,i=this.url+"?chromosome="+t+"&start="+e+"&end="+n+"&cell_condition_id="+this.cellConditionId;return new Promise((function(t,e){go.loadJson(i,{withCredentials:r.config.withCredentials}).then((function(e){e?(e.eqtls.forEach((function(t){t.chr=t.chromosome,t.start=t.position,t.end=t.position+1})),t(e.eqtls)):t(null)})).catch((function(t){e(t)}))}))};const Zh=function(t,e){this.config=t,this.genome=e,this.url=t.url,this.variantSetId=t.variantSetId,this.callSetIds=t.callSetIds,this.includeCalls=void 0===t.includeCalls||t.includeCalls};Zh.prototype.readHeader=function(){var t=this;return t.header?Promise.resolve(t.header):(t.header={},!1===t.includeCalls?Promise.resolve(t.header):dc({url:t.url+"/callsets/search",fields:"nextPageToken,callSets(id,name)",body:{variantSetIds:Array.isArray(t.variantSetId)?t.variantSetId:[t.variantSetId],pageSize:"10000"},decode:function(e){if(t.callSetIds){var n=[],r=new Set;return t.callSetIds.forEach((function(t){r.add(t)})),e.callSets.forEach((function(t){r.has(t.id)&&n.push(t)})),n}return e.callSets}}).then((function(e){return t.header.callSets=e,t.header})))},Zh.prototype.readFeatures=function(t,e,n){const r=this,i=this.genome;return r.readHeader().then((function(t){return new Promise((function(t,e){r.chrAliasTable?t(r.chrAliasTable):r.readMetadata().then((function(e){r.metadata=e.metadata,r.chrAliasTable={},e.referenceBounds&&i&&e.referenceBounds.forEach((function(t){var e=t.referenceName,n=i.getChromosomeName(e);r.chrAliasTable[n]=e})),t(r.chrAliasTable)}))}))})).then((function(i){var o=i.hasOwnProperty(t)?i[t]:t;return dc({url:r.url+"/variants/search",fields:r.includeCalls?void 0:"nextPageToken,variants(id,variantSetId,names,referenceName,start,end,referenceBases,alternateBases,quality,filter,info)",body:{variantSetIds:Array.isArray(r.variantSetId)?r.variantSetId:[r.variantSetId],callSetIds:r.callSetIds?r.callSetIds:void 0,referenceName:o,start:e.toString(),end:n.toString(),pageSize:"10000"},decode:function(t){var e,n=[];return t.variants.forEach((function(t){e=function(t){var e,n=new bh;return n.chr=t.referenceName,n.start=parseInt(t.start),n.end=parseInt(t.end),n.pos=n.start+1,n.names=xh(t.names,"; "),n.referenceBases=t.referenceBases,n.alternateBases=xh(t.alternateBases),n.quality=t.quality,n.filter=xh(t.filter),n.info={},t.info&&Object.keys(t.info).forEach((function(e){var r,i=t.info[e];r=Array.isArray(i)?i.join(","):i,n.info[e]=r})),n.calls={},t.calls&&t.calls.forEach((function(t){e=t.callSetId,n.calls[e]=t})),init(n),n}(t),e.isRefBlock()||n.push(e)})),n}})}))},Zh.prototype.readMetadata=function(){return fc({url:this.url,entity:"variantsets",entityId:this.variantSetId})};class Xh{constructor(t){this.config=t}async readFeatures(t,e,n){const r=(await go.loadJson(this.config.url+"/variants/?count=50000")).records,i=[];for(let t of r)if(t.coordinates){t.id;const e=t.coordinates;e.chromosome&&i.push(new Yh(e.chromosome,e.start-1,e.stop,t)),e.chromosome2&&i.push(new Yh(e.chromosome2,e.start2-1,e.stop2,t))}return i}}class Yh{constructor(t,e,n,r){if(this.chr=t,this.start=e,this.end=n,this.id=r.id,this.entrezName=r.entrez_name,this.name=r.name,this.actionabilityScore=r.civic_actionability_score,r.coordinates.reference_bases&&(this.refBases=r.coordinates.reference_bases),r.coordinates.variant_bases&&(this.altBases=r.coordinates.variant_bases),r.variant_types&&(this.variant_types=r.variant_types),this.locationString=this.chr+":"+_e(this.start+1)+"-"+_e(this.end),void 0!==this.actionabilityScore){let t;if(this.actionabilityScore<=10)t=.2;else{const e=Math.min(30,this.actionabilityScore);t=.2+.8*Math.log10((e-10)/2)}this.alpha=t}}popupData(){const t=n("CIViC","https://civicdb.org/links/variants/"+this.id);this.refBases!==this.altBases&&this.refBases&&1===this.refBases.length&&this.altBases&&this.altBases.length;const e=[t];if(e.push({name:"Entrez",value:n(this.entrezName,"https://ghr.nlm.nih.gov/gene/"+this.entrezName)}),e.push({name:"Name",value:this.name}),this.variant_types&&this.variant_types.length>0){const t=1===this.variant_types.length?"Type":"Types";let n;for(let t of this.variant_types)n?n+=", "+t.display_name:n=t.display_name;e.push({name:t,value:n})}return e.push({name:"Actionability",value:this.actionabilityScore}),e.push({name:"Location",value:this.locationString}),e;function n(t,e){return"<a target='_blank' href='"+e+"'>"+t+"</a>"}}}function Kh(t,e){e=e||Number.MAX_SAFE_INTEGER;const n=[];t.sort((function(t,e){return t.start-e.start})),n.push(-1e3);for(let r of t){let t=0;const i=Math.min(n.length,e);for(t=0;t<i;t++)if(r.start>=n[t]){r.row=t,n[t]=r.end;break}r.row=t,n[t]=r.end}}class Qh extends ec{constructor(t,e){super(t,e),this.parser=new kh}async readHeader(){if(!this.header){const t=Fh(await this.readHeaderData());this.header=await this.parser.parseHeader(t,this.genome),this.chrAliasTable=this.header.chrAliasTable}return this.header}async readFeatures(t,e,n){if(this.config.format&&"VCF"!==this.config.format.toUpperCase())throw Error(`htsget format ${this.config.format} is not supported`);this.chrAliasTable||await this.readHeader();let r=this.chrAliasTable.has(t)?this.chrAliasTable.get(t):t;const i=Fh(await this.readData(r,e,n));return this.parser.parseFeatures(i)}}class Jh{constructor(t,e){this.config=t||{},this.genome=e,this.sourceType=void 0===t.sourceType?"file":t.sourceType,this.maxWGCount=t.maxWGCount||1e4;const n=new Set(["bigwig","bw","bigbed","bb","biginteract","biggenepred","bignarrowpeak","tdf"]);if(t.features&&Array.isArray(t.features)){let n=function(t,e){if(!t||0===t.length)return[];if(void 0===t[0].chr&&void 0!==t[0].chr1){const n=[];for(let r of t)e&&(r.chr1=e.getChromosomeName(r.chr1),r.chr2=e.getChromosomeName(r.chr2)),r.chr1===r.chr2?(r.chr=r.chr1,r.start=Math.min(r.start1,r.start2),r.end=Math.max(r.end1,r.end2)):n.push(r);for(let e of n){const n=Object.assign({dup:!0},e);t.push(n),e.chr=e.chr1,e.start=e.start1,e.end=e.end1,n.chr=n.chr2,n.start=n.start2,n.end=n.end2}}else if(e)for(let n of t)n.chr=e.getChromosomeName(n.chr);return t}(t.features,e);tu(n),t.mappings&&function(t,e){let n=Object.keys(e);t.forEach((function(t){n.forEach((function(n){t[n]=t[e[n]]}))}))}(n,t.mappings),this.queryable=!1,this.featureCache=new Mo(n,e)}else t.reader?(this.reader=t.reader,this.queryable=!1!==t.queryable):"ga4gh"===t.sourceType?(this.reader=new Zh(t,e),this.queryable=!0):"immvar"===t.sourceType?(this.reader=new Gh(t),this.queryable=!0):"eqtl"===t.type&&"gtex-ws"===t.sourceType?(this.reader=new $h(t),this.queryable=!0):"htsget"===t.sourceType?this.reader=new Qh(t,e):"ucscservice"===t.sourceType?(this.reader=new Uh(t.source),this.queryable=!0):"custom"===t.sourceType?(this.reader=new jh(t.source),this.queryable=!1!==t.source.queryable):"civic-ws"===t.sourceType?(this.reader=new Xh(t),this.queryable=!1):(this.reader=new Hh(t,e),void 0!==t.queryable?this.queryable=t.queryable:(n.has(t.format)||this.reader.indexed)&&(this.queryable=!0))}async defaultVisibilityWindow(){if(this.reader&&"function"==typeof this.reader.defaultVisibilityWindow)return this.reader.defaultVisibilityWindow()}async trackType(){const t=await this.getHeader();return t?t.type:void 0}async getHeader(){if(!this.header)if(this.reader&&"function"==typeof this.reader.readHeader){const t=await this.reader.readHeader();t?(this.header=t,t.format&&(this.config.format=t.format)):this.header={}}else this.header={};return this.header}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i}){const o=this.genome,s=o?o.getChromosomeName(t):t,a="all"===s.toLowerCase();return(a&&!this.getWGFeatures||this.config.disableCache||!this.featureCache||!this.featureCache.containsRange(new Gs(s,e,n)))&&await this.loadFeatures(s,e,n,i),a?(this.wgFeatures||(this.queryable?this.wgFeatures=[]:this.wgFeatures=this.getWGFeatures(this.featureCache.getAllFeatures())),this.wgFeatures):this.featureCache.queryFeatures(s,e,n)}getAllFeatures(){return this.queryable?[]:this.getWGFeatures(this.featureCache.getAllFeatures())}async loadFeatures(t,e,n,r){const i=this.reader;let o=e,s=n;if((!r||r<=0)&&!1!==this.config.expandQuery){const e=this.genome?this.genome.getChromosome(t):void 0;o=0,s=Math.max(e?e.bpLength:Number.MAX_SAFE_INTEGER,n)}else if(r>n-e&&!1!==this.config.expandQuery){const t=Math.min(4.1*(n-e),r);o=Math.max(0,(e+n)/2-t),s=e+t}let a=await i.readFeatures(t,o,s);void 0===this.queryable&&(this.queryable=i.indexed);const c=this.queryable?new Gs(t,o,s):void 0;if(a){if(!1===this.config.assembleGFF||"gtf"!==this.config.format&&"gff3"!==this.config.format&&"gff"!==this.config.format||(a=new Wh(this.config).combineFeatures(a,c)),"wig"!==this.config.format&&"junctions"!==this.config.type){tu(a,this.config.maxRows||Number.MAX_SAFE_INTEGER)}this.featureCache=new Mo(a,this.genome,c),(this.config.searchable||this.config.searchableFields)&&this.addFeaturesToDB(a)}else this.featureCache=new Mo([],c)}addFeaturesToDB(t){for(let e of t)if(e.name&&(this.genome.featureDB[e.name.toUpperCase()]=e),e.gene&&e.gene.name&&(this.genome.featureDB[e.gene.name.toUpperCase()]=e),this.config.searchableFields)for(let t of this.config.searchableFields){const n=e.getAttributeValue(t);n&&(n.indexOf(" ")>0?(this.genome.featureDB[n.replaceAll(" ","+").toUpperCase()]=e,this.genome.featureDB[n.replaceAll(" ","%20").toUpperCase()]=e):this.genome.featureDB[n.toUpperCase()]=e)}}getWGFeatures(t){const e=t=>{const e=Object.assign({},t);return e.chr="all",e.start=n.getGenomeCoordinate(t.chr,t.start),e.end=n.getGenomeCoordinate(t.chr,t.end),e._f=t,e.exons&&delete e.exons,e},n=this.genome,r=new Set(n.wgChromosomeNames),i=[];let o=0;const s=this.maxWGCount;for(let a of n.wgChromosomeNames){const c=t[a];if(c)for(let t of c){let a=n.getChromosomeName(t.chr);if(r.has(a))if(i.length<s)i.push(e(t));else{const n=s/(o+1);if(Math.random()<n){i[Math.floor(Math.random()*(s-1))]=e(t)}}o++}}return i.sort((function(t,e){return t.start-e.start})),i}}function tu(t,e){if(e=e||1e3,null==t||0===t.length)return;const n={},r=[];for(let e of t){const t=e.chr;let i=n[t];i||(i=[],n[t]=i,r.push(t)),i.push(e)}for(let t of r)Kh(n[t],e)}class eu{constructor(t,e,n){this.path=t.url,this.bufferSize=n||512e3,this.range={start:-1,size:-1},this.config=t}async dataViewForRange(t,e){if(!(this.data&&this.range.start<=t.start&&this.range.start+this.range.size>=t.start+t.size)){let e;e=t.size?Math.max(this.bufferSize,t.size):this.bufferSize;const n={start:t.start,size:e},r=await go.loadArrayBuffer(this.path,gs(this.config,{range:n}));this.data=r,this.range=n}const n=this.data.byteLength,r=t.start-this.range.start;return e?new Uint8Array(this.data,r,n-r):new DataView(this.data,r,n-r)}}class nu{constructor(t,e){this.path=t.url,this.format=t.format||"bigwig",this.genome=e,this.rpTreeCache={},this.config=t,this.loader=ys(this.path)?new du(this.path):go}async readWGFeatures(t,e){await this.loadHeader();const n=this.chromTree.idToChrom.length-1,r=this.chromTree.idToChrom[0],i=this.chromTree.idToChrom[n];return this.readFeatures(r,0,i,Number.MAX_VALUE,t,e)}async readFeatures(t,e,n,r,i,o){await this.loadHeader();const s=this.chromTree.chromToID[t],a=this.chromTree.chromToID[n];if(void 0===s||void 0===a)return[];let c,l;if("bigwig"===this.type){const t=await this.getZoomHeaders();let e=i?function(t,e){let n;for(let r=0;r<e.length;r++){const i=e[r];if(i.reductionLevel<t){n=i;break}}return n}(i,t):void 0;e?(c=e.indexOffset,l=fu):(c=this.header.fullIndexOffset,l=hu)}else c=this.header.fullIndexOffset,l=uu.call(this);const h=await this.loadRPTree(c),u=await h.findLeafItemsOverlapping(s,e,a,r);if(u&&0!==u.length){let t=Number.MAX_VALUE,n=0;for(let e of u)t=Math.min(t,e.dataOffset),n=Math.max(n,e.dataOffset+e.dataSize);const i=n-t,c=await this.loader.loadArrayBuffer(this.config.url,gs(this.config,{range:{start:t,size:i}})),h=[];for(let n of u){const i=new Uint8Array(c,n.dataOffset-t,n.dataSize);let u;u=this.header.uncompressBuffSize>0?qi(i):i,l.call(this,new DataView(u.buffer),s,e,a,r,h,this.chromTree.idToChrom,o)}return h.sort((function(t,e){return t.start-e.start})),h}return[]}async getZoomHeaders(){return this.zoomLevelHeaders||await this.loadHeader(),this.zoomLevelHeaders}async loadHeader(){if(this.header)return this.header;{let t,e=await this.loader.loadArrayBuffer(this.path,gs(this.config,{range:{start:0,size:64}}));this.littleEndian=!0;let n=new Wa(new DataView(e)),r=n.getUInt();if(2291137574===r)this.type="bigwig";else if(2273964779===r)this.type="bigbed";else{this.littleEndian=!1,n.littleEndian=!1,n.position=0;let t=n.getUInt();654085990===t?this.type="bigwig":3958540679===t&&(this.type="bigbed")}t={bwVersion:n.getUShort(),nZoomLevels:n.getUShort(),chromTreeOffset:n.getLong(),fullDataOffset:n.getLong(),fullIndexOffset:n.getLong(),fieldCount:n.getUShort(),definedFieldCount:n.getUShort(),autoSqlOffset:n.getLong(),totalSummaryOffset:n.getLong(),uncompressBuffSize:n.getInt(),extensionOffset:n.getLong()};const i=64;let o={start:i,size:t.fullDataOffset-i+5};e=await this.loader.loadArrayBuffer(this.path,gs(this.config,{range:o}));const s=t.nZoomLevels;n=new Wa(new DataView(e)),this.zoomLevelHeaders=[],this.firstZoomDataOffset=Number.MAX_SAFE_INTEGER;for(let t=1;t<=s;t++){const e=s-t,r=new ru(e,n);this.firstZoomDataOffset=Math.min(r.dataOffset,this.firstZoomDataOffset),this.zoomLevelHeaders[e]=r}if(t.autoSqlOffset>0){n.position=t.autoSqlOffset-i;const e=n.getString();e&&(this.autoSql=function(t){let e;const n=[];let r=!1;const i=t.trim().split(/\s*[\r\n]+\s*/g);for(let t of i)if(t.startsWith("table"))e=t.split(/\s+/)[1].trim();else if(t.startsWith("("))r=!0;else if(t.startsWith(")"));else if(r&&t.length>0){const e=t.indexOf(";"),r=t.substr(0,e).split(/\s+/),i=t.substr(e+1).replace(/"/g,"").trim();n.push({type:r[0],name:r[1],description:i})}return{table:e,fields:n}}(e))}if(t.totalSummaryOffset>0&&(n.position=t.totalSummaryOffset-i,this.totalSummary=new cu(n)),!(t.chromTreeOffset>0))throw"BigWig chromosome tree offset <= 0";return n.position=t.chromTreeOffset-i,this.chromTree=new su(n,i,this.genome),n.position=t.fullDataOffset-i,t.dataCount=n.getInt(),this.setDefaultVisibilityWindow(t),this.header=t,this.header}}async loadRPTree(t){let e=this.rpTreeCache[t];return e||(e=new iu(t,this.config,this.littleEndian,this.loader),await e.load(),this.rpTreeCache[t]=e,e)}async getType(){return await this.loadHeader(),this.type}async getTrackType(){return await this.loadHeader(),"bigwig"===this.type?"wig":this.autoSql&&"chromatinInteract"===this.autoSql.table?"interact":"annotation"}setDefaultVisibilityWindow(t){if("bigwig"===this.type)this.visibilityWindow=-1;else{let e=this.genome?this.genome.getGenomeLength():3088286401;this.visibilityWindow=t.dataCount<1e3?-1:e/t.dataCount*1e3}}}class ru{constructor(t,e){this.index=t,this.reductionLevel=e.getInt(),this.reserved=e.getInt(),this.dataOffset=e.getLong(),this.indexOffset=e.getLong()}}class iu{constructor(t,e,n,r){this.config=e,this.loader=r,this.fileOffset=t,this.path=e.url,this.littleEndian=n}async load(){const t=this.fileOffset+48,e=ys(this.path)?this.loader:new eu(this.config,512e3);return this.rootNode=await this.readNode(t,e),this}async readNode(t,e){let n=await e.dataViewForRange({start:t,size:4},!1),r=new Wa(n,this.littleEndian);const i=1===r.getByte();r.getByte();const o=r.getUShort();let s={start:t+=4,size:o*(i?32:24)};n=await e.dataViewForRange(s,!1);const a=new Array(o);if(r=new Wa(n),i){for(let t=0;t<o;t++){let e={isLeaf:!0,startChrom:r.getInt(),startBase:r.getInt(),endChrom:r.getInt(),endBase:r.getInt(),dataOffset:r.getLong(),dataSize:r.getLong()};a[t]=e}return new ou(a)}for(let t=0;t<o;t++){let e={isLeaf:!1,startChrom:r.getInt(),startBase:r.getInt(),endChrom:r.getInt(),endBase:r.getInt(),childOffset:r.getLong()};a[t]=e}return new ou(a)}async findLeafItemsOverlapping(t,e,n,r){let i=this;return new Promise((function(o,s){let a=[],c=new Set,l=ys(i.path)?i.loader:new eu(i.config,512e3);c.add(0),function h(u,f){if(au(u,t,e,n,r)){u.items.forEach((function(o){au(o,t,e,n,r)&&(o.isLeaf?a.push(o):o.childNode?h(o.childNode):(c.add(o.childOffset),i.readNode(o.childOffset,l).then((function(t){o.childNode=t,h(t,o.childOffset)})).catch(s)))}))}void 0!==f&&c.delete(f);0===c.size&&o(a)}(i.rootNode,0)}))}}class ou{constructor(t){this.items=t;let e,n,r=Number.MAX_SAFE_INTEGER,i=0,o=Number.MAX_SAFE_INTEGER,s=0;for(e=0;e<t.length;e++)n=t[e],r=Math.min(r,n.startChrom),i=Math.max(i,n.endChrom),o=Math.min(o,n.startBase),s=Math.max(s,n.endBase);this.startChrom=r,this.endChrom=i,this.startBase=o,this.endBase=s}}class su{constructor(t,e,n){let r=t.getInt(),i=t.getInt(),o=t.getInt(),s=t.getInt(),a=t.getLong(),c=t.getLong(),l={},h=[];this.header={magic:r,blockSize:i,keySize:o,valSize:s,itemCount:a,reserved:c},this.chromToID=l,this.idToChrom=h,function t(r,i){i>=0&&(r.position=i);let s=r.getByte();r.getByte();let a,c,u,f,d,p,g=r.getUShort();if(1===s)for(a=0;a<g;a++)c=r.getFixedLengthTrimmedString(o),u=r.getInt(),r.getInt(),n&&(c=n.getChromosomeName(c)),l[c]=u,h[u]=c;else for(a=0;a<g;a++)c=r.getFixedLengthTrimmedString(o),f=r.getLong(),d=f-e,p=r.position,t(r,d),r.position=p}(t,-1)}}function au(t,e,n,r,i){return t?(r>t.startChrom||r===t.startChrom&&i>=t.startBase)&&(e<t.endChrom||e===t.endChrom&&n<=t.endBase):(console.log("null item for "+e+" "+n+" "+i),!1)}class cu{constructor(t){t?(this.basesCovered=t.getLong(),this.minVal=t.getDouble(),this.maxVal=t.getDouble(),this.sumData=t.getDouble(),this.sumSquares=t.getDouble(),lu.call(this)):(this.basesCovered=0,this.minVal=0,this.maxVal=0,this.sumData=0,this.sumSquares=0,this.mean=0,this.stddev=0)}}function lu(){let t=this.basesCovered;if(t>0){this.mean=this.sumData/t,this.stddev=Math.sqrt(this.sumSquares/(t-1));let e=this.minVal<0?this.mean-2*this.stddev:0,n=this.maxVal>0?this.mean+2*this.stddev:0;this.defaultRange={min:e,max:n}}}function hu(t,e,n,r,i,o,s){const a=new Wa(t),c=a.getInt();let l=a.getInt(),h=a.getInt();const u=a.getInt(),f=a.getInt(),d=a.getByte();a.getByte();let p=a.getUShort();if(c>=e&&c<=r)for(;p-- >0;){let t;switch(d){case 1:l=a.getInt(),h=a.getInt(),t=a.getFloat();break;case 2:l=a.getInt(),t=a.getFloat(),h=l+f;break;case 3:t=a.getFloat(),h=l+f,l+=u}if(!(c<e||c===e&&h<n)){if(c>r||c===r&&l>=i)break;if(Number.isFinite(t)){const e=s[c];o.push({chr:e,start:l,end:h,value:t})}}}}function uu(){const t=function(t,e,n,r){if("biginteract"===r||n&&"chromatinInteract"===n.table||"interact"===n.table)return function(t,e){return t.chr1=e[5],t.start1=Number.parseInt(e[6]),t.end1=Number.parseInt(e[7]),t.chr2=e[10],t.start2=Number.parseInt(e[11]),t.end2=Number.parseInt(e[12]),t.name=e[0],t.score=Number(e[1]),t.value=Number(e[2]),t.color="."===e[4]?void 0:"0"===e[4]?"rgb(0,0,0)":e[4],t};{const r=t-3;return function(i,o){if(r>0&&(i.name=o[0]),r>1&&(i.score=Number(o[1])),r>2&&(i.strand=o[2]),r>3&&(i.cdStart=parseInt(o[3])),r>4&&(i.cdEnd=parseInt(o[4])),r>5&&"."!==o[5]&&"0"!==o[5]&&"-1"!==o[5]){const t=no.createColorString(o[5]);i.color=t.startsWith("rgb")?t:void 0}if(r>8){const t=parseInt(o[6]),e=o[7].split(","),n=o[8].split(","),r=[];for(let o=0;o<t;o++){const t=i.start+parseInt(n[o]),s=t+parseInt(e[o]);r.push({start:t,end:s})}!function(t,e,n){for(let r of t){const t=r.end,i=r.start;t<e||i>n?r.utr=!0:(e>=i&&e<=t&&(r.cdStart=e),n>=i&&n<=t&&(r.cdEnd=n))}}(r,i.cdStart,i.cdEnd),i.exons=r}if(n)for(let r=t;r<e;r++)if(r<n.fields.length){const t=n.fields[r].name,e=o[r-3];i[t]=e}}}}(this.header.definedFieldCount,this.header.fieldCount,this.autoSql,this.format);return function(e,n,r,i,o,s,a){const c=new Wa(e);for(;c.remLength()>=13;){const e=c.getInt(),l=a[e],h=c.getInt(),u=c.getInt(),f=c.getString();if(!(e<n||e===n&&u<r)){if(e>i||e===i&&h>=o)break;if(u>0){const e={chr:l,start:h,end:u};s.push(e);const n=f.split("\t");t(e,n)}}}}}function fu(t,e,n,r,i,o,s,a){const c=new Wa(t);for(;c.remLength()>=32;){const t=c.getInt(),l=s[t],h=c.getInt(),u=c.getInt(),f=c.getInt(),d=c.getFloat(),p=c.getFloat(),g=c.getFloat();let m;switch(c.getFloat(),a){case"min":m=d;break;case"max":m=p;break;default:m=0===f?0:g/f}if(!(t<e||t===e&&u<n)){if(t>r||t===r&&h>=i)break;Number.isFinite(m)&&o.push({chr:l,start:h,end:u,value:m})}}}class du{constructor(t){this.data=Yi(t).buffer}loadArrayBuffer(t,e){const n=e.range;return n?this.data.slice(n.start,n.start+n.size):this.data}async dataViewForRange(t,e){const n=Math.min(this.data.byteLength-t.start,t.size);return e?new Uint8Array(this.data,t.start,n):new DataView(this.data,t.start,n)}}class pu{constructor(t,e){this.reader=new nu(t,e),this.genome=e,this.format=t.format||"bigwig",this.wgValues={}}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,windowFunction:i}){const o="all"===t.toLowerCase()?await this.getWGValues(i):await this.reader.readFeatures(t,e,t,n,r,i);return"bigwig"===this.reader.type||Kh(o),o}async getHeader(){return this.reader.loadHeader()}getDefaultRange(){return void 0!==this.reader.totalSummary?this.reader.totalSummary.defaultRange:void 0}async defaultVisibilityWindow(){return this.reader.defaultVisibilityWindow}async getWGValues(t){const e=this.genome;if(this.wgValues[t])return this.wgValues[t];{const n=e.getGenomeLength()/1e3,r=await this.reader.readWGFeatures(n,t);let i=[];for(let t of r){const n=t.chr,r=e.getCumulativeOffset(n),o=Object.assign({},t);o.chr="all",o.start=r+t.start,o.end=r+t.end,i.push(o)}return this.wgValues[t]=i,i}}supportsWholeGenome(){return"bigwig"===this.reader.type}async trackType(){return this.reader.getTrackType()}}class gu{constructor(t,e){this.config=t,this.genome=e,this.path=t.url,this.groupCache={},this.datasetCache={}}async readHeader(){if(void 0!==this.magic)return this;let t=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:0,size:64e3}})),e=new Wa(new DataView(t));if(this.magic=e.getInt(),this.version=e.getInt(),this.indexPos=e.getLong(),this.indexSize=e.getInt(),e.getInt(),this.version>=2){let t=e.getInt();for(this.windowFunctions=[];t-- >0;)this.windowFunctions.push(e.getString())}this.trackType=e.getString(),this.trackLine=e.getString();let n=e.getInt();for(this.trackNames=[];n-- >0;)this.trackNames.push(e.getString());this.genomeID=e.getString(),this.flags=e.getInt(),this.compressed=0!=(1&this.flags),t=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:this.indexPos,size:this.indexSize}})),e=new Wa(new DataView(t)),this.datasetIndex={};let r=e.getInt();for(;r-- >0;){const t=e.getString(),n=e.getLong(),r=e.getInt();this.datasetIndex[t]={position:n,size:r}}for(this.groupIndex={},r=e.getInt();r-- >0;){const t=e.getString(),n=e.getLong(),r=e.getInt();this.groupIndex[t]={position:n,size:r}}return this}async readDataset(t,e,n){const r=t+"_"+e+"_"+n;if(this.datasetCache[r])return this.datasetCache[r];{await this.readHeader();const i=this.version<2?"":"/"+e,o="all"===t.toLowerCase()||void 0===n?"0":n.toString();let s;s="raw"===e?"/"+t+"/raw":"/"+t+"/z"+o+i;const a=this.datasetIndex[s];if(void 0===a)return;const c=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:a.position,size:a.size}}));if(!c)return;const l=new Wa(new DataView(c));let h=l.getInt();const u={};for(;h-- >0;)u[l.getString()]=l.getString();const f=l.getString(),d=l.getFloat();let p=l.getInt();const g=[];for(;p-- >0;)g.push({position:l.getLong(),size:l.getInt()});const m={name:s,attributes:u,dataType:f,tileWidth:d,tiles:g};return this.datasetCache[r]=m,m}}async readRootGroup(){const t=this.genome,e=this.groupCache["/"];if(e)return e;{const e=await this.readGroup("/"),n=e.chromosomes,r=e.maxZoom;r&&(this.maxZoom=Number(r));const i=e.totalCount;i&&(e.totalCount=Number(i));const o={};return n&&n.split(",").forEach((function(e){const n=t.getChromosomeName(e);o[n]=e})),this.chrAliasTable=o,this.groupCache["/"]=e,e}}async readGroup(t){const e=this.groupCache[t];if(e)return e;{await this.readHeader();const e=this.groupIndex[t];if(void 0===e)return;const n=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:e.position,size:e.size}}));if(!n)return;const r=new Wa(new DataView(n)),i={name:t};let o=r.getInt();for(;o-- >0;){const t=r.getString(),e=r.getString();i[t]=e}return this.groupCache[t]=i,i}}async readTiles(t,e){if(t.sort((function(t,e){return t.position-e.position})),0===(t=t.filter((function(t){return t.size>0}))).length)return Promise.resolve([]);const n=t[0],r=t[t.length-1],i=n.position,o=r.position+r.size-i,s=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:i,size:o}})),a=[];for(let n of t){const t=n.position-i,r=n.size;if(r>0){let n;if(this.compressed){n=qi(s.slice(t,t+r)).buffer}else n=s.slice(t,t+r);const i=new Wa(new DataView(n)),o=i.getString();let c;switch(o){case"fixedStep":c=mu(i,e);break;case"variableStep":c=vu(i,e);break;case"bed":case"bedWithName":c=bu(i,e,o);break;default:throw"Unknown tile type: "+o}a.push(c)}}return a}async readTile(t,e){let n=await go.loadArrayBuffer(this.path,gs(this.config,{range:{start:t.position,size:t.size}}));if(this.compressed){n=qi(n).buffer}const r=new Wa(new DataView(n)),i=r.getString();switch(i){case"fixedStep":return mu(r,e);case"variableStep":return vu(r,e);case"bed":case"bedWithName":return bu(r,e,i);default:throw"Unknown tile type: "+i}}}function mu(t,e){const n=t.getInt(),r=t.getInt(),i=t.getFloat(),o=[];let s=e;for(;s-- >0;){let e=n;const r=[];for(;e-- >0;)r.push(t.getFloat());o.push(r)}return{type:"fixedStep",start:r,span:i,data:o,nTracks:e,nPositions:n}}function vu(t,e){const n=t.getInt(),r=t.getFloat(),i=t.getInt(),o=[];let s=i;for(;s-- >0;)o.push(t.getInt());t.getInt();const a=[];let c=e;for(;c-- >0;){s=i;const e=[];for(;s-- >0;)e.push(t.getFloat());a.push(e)}return{type:"variableStep",tileStart:n,span:r,start:o,data:a,nTracks:e,nPositions:i}}function bu(t,e,n){const r=t.getInt();let i=r;const o=[];for(;i-- >0;)o.push(t.getInt());i=r;const s=[];for(;i-- >0;)s.push(t.getInt());t.getInt();const a=[];let c=e;for(;c-- >0;){let e=r;const n=[];for(;e-- >0;)n.push(t.getFloat());a.push(n)}if("bedWithName"===n){i=r;const e=[];for(;i-- >0;)e.push(t.getString())}return{type:n,start:o,end:s,data:a,nTracks:e,nPositions:r}}class wu{constructor(t,e){this.genome=e,this.windowFunction=t.windowFunction||"mean",this.reader=new gu(t,e)}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r}){if("all"===t.toLowerCase()){const t=[],e=this.genome;if(this.genome.wgChromosomeNames)for(let n of e.wgChromosomeNames){const i=e.getChromosome(n).bpLength;r=i/1e3;const o=await this._getFeatures(n,0,i,r);if(o)for(let n of o){const r=Object.assign({},n);r.chr="all",r.start=e.getGenomeCoordinate(n.chr,n.start),r.end=e.getGenomeCoordinate(n.chr,n.end),r._f=n,t.push(r)}}return t}return this._getFeatures(t,e,n,r)}async _getFeatures(t,e,n,r){const i=new Gs(t,e,n),o=this.genome;if(!this.rootGroup&&(this.rootGroup=await this.reader.readRootGroup(),!this.normalizationFactor)){const t=this.rootGroup.totalCount;t&&(this.normalizationFactor=1e6/t)}i.bpPerPixel=r;const s=function(t,e,n){var r=n.getChromosome(t).bpLength;return Math.ceil(Math.log(Math.max(0,r/(700*e)))/_u)}(t,r,o);let a=this.reader.chrAliasTable[t],c=this.reader.maxZoom;void 0===a&&(a=t),void 0===c&&(c=-1);const l=s>c?"raw":this.windowFunction,h=await this.reader.readDataset(a,l,s);if(null==h)return[];const u=h.tileWidth,f=Math.floor(e/u),d=Math.floor(n/u),p=await this.reader.readTiles(h.tiles.slice(f,d+1),1),g=[];for(let i of p)switch(i.type){case"bed":yu(i,t,e,n,r,g);break;case"variableStep":xu(i,t,e,n,r,g);break;case"fixedStep":ku(i,t,e,n,r,g);break;default:throw"Unknown tile type: "+i.type}return g.sort((function(t,e){return t.start-e.start})),g}get supportsWholeGenome(){return!0}}function yu(t,e,n,r,i,o){const s=t.nPositions,a=t.start,c=t.end,l=t.data[0];for(let t=0;t<s;t++){const i=a[t],s=c[t];if(!(s<n)){if(i>r)break;o.push({chr:e,start:i,end:s,value:l[t]})}}}function xu(t,e,n,r,i,o){const s=t.nPositions,a=t.start,c=t.span,l=t.data[0];for(let t=0;t<s;t++){const i=a[t],s=i+c;if(!(s<n)){if(i>r)break;o.push({chr:e,start:i,end:s,value:l[t]})}}}function ku(t,e,n,r,i,o){const s=t.nPositions;let a=t.start;const c=t.span,l=t.data[0];for(let t=0;t<s;t++){const i=a+c;if(a>r)break;i>=n&&(Number.isNaN(l[t])||o.push({chr:e,start:a,end:i,value:l[t]})),a=i}}var _u=Math.log(2);const Su=new Set(["bigwig","bw","bigbed","bb","biginteract","biggenepred","bignarrowpeak"]);function Cu(t,e){const n=t.format?t.format.toLowerCase():void 0;return Su.has(n)?new pu(t,e):"tdf"===n?new wu(t,e):new Jh(t,e)}const Eu={getTissueInfo:function(t,e){let n=(e=e||"https://gtexportal.org/rest/v1")+"/dataset/tissueInfo?datasetId="+(t=t||"gtex_v8");return go.loadJson(n,{})},trackConfiguration:function(t,e){return{type:"eqtl",sourceType:"gtex-ws",url:(e=e||"https://gtexportal.org/rest/v1")+"/association/singleTissueEqtlByLocation",tissueSiteDetailId:t.tissueSiteDetailId,name:t.tissueSiteDetailId.split("_").join(" "),visibilityWindow:25e4}}};function Au(t,e,n){let r=(t.start-e)/n,i=(t.end-e)/n,o=i-r;return o<3&&(o=3,r-=1.5),{px:r,px1:i,pw:o}}function Tu(t,e,n,r,i,o){try{i.save(),i.fillStyle=this.defaultColor,i.strokeStyle=this.defaultColor;const r=Mu.call(this,t);let s,a;i.fillStyle=r,i.strokeStyle=r,"SQUISHED"===this.displayMode&&void 0!==t.row?(s=this.featureHeight/2,a=this.margin+this.squishedRowHeight*t.row):"EXPANDED"===this.displayMode&&void 0!==t.row?(s=this.featureHeight,a=this.margin+this.expandedRowHeight*t.row):(s=this.featureHeight,a=this.margin);const c=o.pixelWidth,l=a+s/2,h=s/2,u=l-h/2,f=t.exons?t.exons.length:0,d=Au(t,e,n),p=this.arrowSpacing,g="+"===t.strand?1:"-"===t.strand?-1:0;if(0===f){const t=Math.max(0,d.px),e=Math.min(c,d.px1),n=e-t;if(i.fillRect(t,a,n,s),0!==g){i.fillStyle="white",i.strokeStyle="white";for(let n=t+p/2;n<e;n+=p)ls.strokeLine(i,n-2*g,l-2,n,l),ls.strokeLine(i,n-2*g,l+2,n,l);i.fillStyle=r,i.strokeStyle=r}}else{ls.strokeLine(i,d.px+1,l,d.px1-1,l);const o=Math.max(0,d.px)+p/2,m=Math.min(c,d.px1);for(let t=o;t<m;t+=p)ls.strokeLine(i,t-2*g,l-2,t,l),ls.strokeLine(i,t-2*g,l+2,t,l);for(let o=0;o<f;o++){const f=t.exons[o];let d,m=Math.round((f.start-e)/n),v=Math.round((f.end-e)/n),b=Math.max(1,v-m);if(!(m+b<0)){if(m>c)break;if(f.utr)i.fillRect(m,u,b,h);else if(f.cdStart&&(d=Math.round((f.cdStart-e)/n),i.fillRect(m,u,d-m,h),b-=d-m,m=d),f.cdEnd&&(d=Math.round((f.cdEnd-e)/n),i.fillRect(d,u,v-d,h),b-=v-d,v=d),b=Math.max(b,1),i.fillRect(m,a,b,s),b>p+5&&0!==g){i.fillStyle="white",i.strokeStyle="white";for(let t=m+p/2;t<v;t+=p)ls.strokeLine(i,t-2*g,l-2,t,l),ls.strokeLine(i,t-2*g,l+2,t,l);i.fillStyle=r,i.strokeStyle=r}}}}o.drawLabel&&"SQUISHED"!==this.displayMode&&Lu.call(this,i,t,d.px,d.px1,a,o.referenceFrame,o)}finally{i.restore()}}function Lu(t,e,n,r,i,o,s){try{t.save();let a=e.name;if(void 0===a&&e.gene&&(a=e.gene.name),void 0===a&&(a=e.id||e.ID),!a||"."===a)return;let c=s.pixelXOffset||0;const l=Math.max(n,-c),h=(l+Math.min(r,-c+s.viewportWidth))/2;let u;"COLLAPSED"===this.displayMode&&"SLANT"===this.labelDisplayMode&&(u={rotate:{angle:45}});const f=function(t,e){return e?t+20:t+25}(i,u);let d,p=Mu.call(this,e),g=!1;o.selection&&Eu.gtexLoaded&&(g=!0,d=o.selection.colorForGene(a));const m={textAlign:"SLANT"===this.labelDisplayMode?void 0:"center",fillStyle:d||p,strokeStyle:d||p},v=t.measureText(a),b=h-v.width/2,w=h+v.width/2;(s.labelAllFeatures||b>s.rowLastLabelX[e.row]||g)&&(s.rowLastLabelX[e.row]=w,ls.fillText(t,a,h,f,m,u))}finally{t.restore()}}function Mu(t){let e;if(this.altColor&&"-"===t.strand)e="function"==typeof this.altColor?this.altColor(t):this.altColor;else if(this.color)e="function"==typeof this.color?this.color(t):this.color;else if(this.colorBy){const n=t.getAttributeValue?t.getAttributeValue(this.colorBy):t[this.colorBy];e=this.colorTable.getColor(n)}else e=t.color?t.color:this.defaultColor;if(t.alpha&&1!==t.alpha)e=no.addAlpha(e,t.alpha);else if(this.useScore&&t.score&&!Number.isNaN(t.score)){const n=function(t,e,n){const r=(e-t)/9,i=Math.floor((n-t)/r);return Math.min(1,.2+.8*i/9)}(this.config.min?this.config.min:0,this.config.max?this.config.max:1e3,t.score);t.alpha=n,e=no.addAlpha(e,n)}return e}const Ru=new Set(["nonsense","missense","stop-loss","frameshift","cds-indel"]),Iu=new Set(["coding-synon"]),Nu=new Set(["splice-3","splice-5"]),Pu=new Set(["untranslated-5","untranslated-3"]);function Ou(t,e,n,r,i){var o,s,a,c,l=Au(t,e,n),h=this.margin,u=this.snpColors.length;switch(o="squished"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight,this.colorBy){case"function":c=t.func,s=c.split(",").map((function(t){return Ru.has(t)||Nu.has(t)?u-1:Iu.has(t)?u-2:Pu.has(t)?u-3:0})).reduce((function(t,e){return Math.max(t,e)}));break;case"class":s="deletion"===(a=t.class)?u-1:"mnp"===a?u-2:"microsatellite"===a||"named"===a?u-3:0}i.fillStyle=this.snpColors[s],i.fillRect(l.px,h,l.pw,o)}function Fu(t,e,n,r,i){const o="EXPANDED"===this.displayMode?this.expandedRowHeight:this.squishedRowHeight;let s=this.margin;"COLLAPSED"!==this.displayMode&&void 0!==t.row&&(s+=t.row*o);const a=s+.5*o,c=a-.5*o,l=a+.5*o,h=Math.round((t.junction_left-e)/n),u=Math.round((t.junction_right-e)/n);i.beginPath(),i.moveTo(h,a),i.bezierCurveTo(h,c,u,c,u,a),i.lineWidth=1+Math.log(t.num_junction_reads)/Math.log(2),i.strokeStyle="blue",i.stroke();const f=t.spanning_frag_coords;for(let t=0;t<f.length;t++){const r=f[t],o=Math.round((r.left-e)/n),s=Math.round((r.right-e)/n);i.beginPath(),i.moveTo(o,a),i.bezierCurveTo(o,l,s,l,s,a),i.lineWidth=1,i.strokeStyle="purple",i.stroke()}}class Du extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type=t.type||"annotation",this.maxRows=void 0===t.maxRows?1e3:t.maxRows,this.displayMode=t.displayMode||"EXPANDED",this.labelDisplayMode=t.labelDisplayMode,t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=t.featureSource?t.featureSource:Cu(t,this.browser.genome),this.autoHeight=t.autoHeight,this.margin=void 0===t.margin?10:t.margin,this.featureHeight=t.featureHeight||14,"FusionJuncSpan"===t.type?(this.render=t.render||Fu,this.squishedRowHeight=t.squishedRowHeight||50,this.expandedRowHeight=t.expandedRowHeight||50,this.height=t.height||this.margin+2*this.expandedRowHeight):"snp"===t.type?(this.render=t.render||Ou,this.snpColors=["rgb(0,0,0)","rgb(0,0,255)","rgb(0,255,0)","rgb(255,0,0)"],this.colorBy="function",this.expandedRowHeight=t.expandedRowHeight||10,this.squishedRowHeight=t.squishedRowHeight||5,this.height=t.height||30):(this.render=t.render||Tu,this.arrowSpacing=30,function(t){t.browser.on&&(t.browser.on("trackdragend",e),t.browser.on("trackremoved",n));function e(){t.trackView&&"SQUISHED"!==t.displayMode&&t.trackView.repaintViews()}function n(r){t.browser.un&&t===r&&(t.browser.un("trackdragend",e),t.browser.un("trackremoved",n))}}(this),this.squishedRowHeight=t.squishedRowHeight||15,this.expandedRowHeight=t.expandedRowHeight||30,this.height=t.height||this.margin+2*this.expandedRowHeight,t.colorBy&&(t.colorBy.field&&(t.colorTable=t.colorBy.pallete||t.colorBy.palette,t.colorBy=t.colorBy.field),this.colorBy=t.colorBy,t.colorTable?this.colorTable=new Sc(t.colorTable):this.colorTable=new _c("Set1"))),this.useScore=t.useScore}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow()),this}get supportsWholeGenome(){return void 0!==this.config.supportsWholeGenome?this.config.supportsWholeGenome:this.featureSource&&"function"==typeof this.featureSource.supportsWholeGenome?this.featureSource.supportsWholeGenome():!(void 0!==this.visibilityWindow||!1!==this.config.indexed&&this.config.indexURL)||void 0}async getFeatures(t,e,n,r){const i=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i})}computePixelHeight(t){if("COLLAPSED"===this.displayMode)return this.margin+this.expandedRowHeight;{let e=0;if(t&&"function"==typeof t.forEach)for(let n of t)n.row&&n.row>e&&(e=n.row);return this.margin+(e+1)*("SQUISHED"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight)}}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=t.pixelHeight,a=i+o*r+1;if(this.config.isMergedTrack||ls.fillRect(n,0,t.pixelTop,o,s,{fillStyle:"rgb(255, 255, 255)"}),e){const c=[];t.rowLastX=[],t.rowLastLabelX=[];for(let n of e)if(n.start>i&&n.end<a){const e="COLLAPSED"===this.displayMode?0:n.row||0;void 0===c[e]?c[e]=1:c[e]++,t.rowLastX[e]=-Number.MAX_SAFE_INTEGER,t.rowLastLabelX[e]=-Number.MAX_SAFE_INTEGER}const l=o/Math.max(...c);let h=[];for(let o of e){if(o.end<i)continue;if(o.start>a)break;const e="COLLAPSED"===this.displayMode?0:o.row;t.drawLabel=t.labelAllFeatures||l>10;const c=Math.ceil((o.end-i)/r),u=h[e];if(!u||c>u){this.render.call(this,o,i,r,s,n,t);const a=Math.floor((o.start-i)/r);u&&a-u<=0&&(n.globalAlpha=.5,ls.strokeLine(n,a,0,a,s,{strokeStyle:"rgb(255, 255, 255)"}),n.globalAlpha=1),h[e]=c}}}else console.log("No feature list")}clickedFeatures(t,e){const n=t.y-this.margin,r=super.clickedFeatures(t,e);let i;switch(this.displayMode){case"SQUISHED":i=Math.floor(n/this.squishedRowHeight);break;case"EXPANDED":i=Math.floor(n/this.expandedRowHeight);break;default:i=void 0}return r.filter((function(t){return void 0===i||void 0===t.row||i===t.row}))}popupData(t,e){e=this.clickedFeatures(t,e);const n=t.genomicLocation,r=[];for(let t of e){const e=t._f||t,i="function"==typeof e.popupData?e.popupData(n):this.extractPopupData(e);if(i){r.length>0&&r.push("<hr/><hr/>");const o=this.infoURL||this.config.infoURL;for(let e of i)if(r.push(e),o&&e.name&&"name"===e.name.toLowerCase()&&e.value&&ke(e.value)&&!e.value.startsWith("<")){const n=o.replace("$$",t.name);e.value=`<a target=_blank href=${n}>${e.value}</a>`}const s="gff"===this.config.format||"gff3"===this.config.format||"gtf"===this.config.format;if(e.exons)for(let t=0;t<e.exons.length;t++){const i=e.exons[t];if(n>=i.start&&n<=i.end){const n=s?i.number:"-"===e.strand?e.exons.length-t:t+1;n&&(r.push("<hr/>"),r.push({name:"Exon Number",value:n}));break}}}}return r}menuItemList(){const t=[];if(this.render===Ou){t.push("<hr/>");for(let e of["function","class"])t.push({object:de(Po("Color by "+e,e===this.colorBy)),click:()=>{this.colorBy=e,this.trackView.repaintViews()}})}t.push("<hr/>");for(let e of["COLLAPSED","SQUISHED","EXPANDED"]){const n={COLLAPSED:"Collapse",SQUISHED:"Squish",EXPANDED:"Expand"};t.push({object:de(Po(n[e],e===this.displayMode)),click:()=>{this.displayMode=e,this.config.displayMode=e,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})}return t}contextMenuItemList(t){const e=this.clickedFeatures(t);e.length>1&&e.sort(((t,e)=>e.end-e.start-(t.end-t.start)));const n=e[0];if(n.end-n.start<=1e6){const t=[{label:"View feature sequence",click:async()=>{let t=await this.browser.genome.getSequence(n.chr,n.start,n.end);"-"===n.strand&&(t=As(t)),t||(t="Unknown sequence"),Qo.presentAlert(t)}}];return Ss()&&void 0!==navigator.clipboard&&t.push({label:"Copy feature sequence",click:async()=>{let t=await this.browser.genome.getSequence(n.chr,n.start,n.end);"-"===n.strand&&(t=As(t));try{await navigator.clipboard.writeText(t)}catch(t){console.error(t),Qo.presentAlert(`error copying sequence to clipboard ${t}`)}}}),t.push("<hr/>"),t}}description(){if(Ou===this.render){let t="<html>"+this.name+"<hr/>";return t+="<em>Color By Function:</em><br>",t+='<span style="color:red">Red</span>: Coding-Non-Synonymous, Splice Site<br>',t+='<span style="color:green">Green</span>: Coding-Synonymous<br>',t+='<span style="color:blue">Blue</span>: Untranslated<br>',t+='<span style="color:black">Black</span>: Intron, Locus, Unknown<br><br>',t+="<em>Color By Class:</em><br>",t+='<span style="color:red">Red</span>: Deletion<br>',t+='<span style="color:green">Green</span>: MNP<br>',t+='<span style="color:blue">Blue</span>: Microsatellite, Named<br>',t+='<span style="color:black">Black</span>: Indel, Insertion, SNP',t+="</html>",t}return super.description()}dispose(){this.trackView=void 0}}class Bu extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type="wig",this.height=t.height||50,this.featureType="numeric",this.paintAxis=yc;const e=t.format?t.format.toLowerCase():t.format;this.flipAxis=!!t.flipAxis&&t.flipAxis,this.logScale=!!t.logScale&&t.logScale,this.featureSource="bigwig"===e?new pu(t,this.browser.genome):"tdf"===e?new wu(t,this.browser.genome):Cu(t,this.browser.genome),this.autoscale=t.autoscale||void 0===t.max,this.autoscale||(this.dataRange={min:t.min||0,max:t.max}),this.windowFunction=t.windowFunction||"mean",this.graphType=t.graphType||"bar",this.normalize=t.normalize,this.scaleFactor=t.scaleFactor}async postInit(){const t=await this.getHeader();t&&this.setTrackProperties(t)}async getFeatures(t,e,n,r){const i=await this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,windowFunction:this.windowFunction});if(this.normalize&&this.featureSource.normalizationFactor){const t=this.featureSource.normalizationFactor;for(let e of i)e.value*=t}if(this.scaleFactor){const t=this.scaleFactor;for(let e of i)e.value*=t}return i}menuItemList(){let t=[];return void 0!==this.flipAxis&&t.push({label:"Flip y-axis",click:()=>{this.flipAxis=!this.flipAxis,this.trackView.repaintViews()}}),t=t.concat(Oo.numericDataMenuItems(this.trackView)),t}async getHeader(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header}getScaleFactor(t,e,n,r){return r?n/(Math.log10(e+1)-(t<=0?0:Math.log10(t+1))):n/(e-t)}computeYPixelValue(t,e){return(this.flipAxis?t-this.dataRange.min:this.dataRange.max-t)*e}computeYPixelValueInLogScale(t,e){let n=this.dataRange.max,r=this.dataRange.min;return n<=0?0:(r<=-1&&(r=0),r=r<=0?0:Math.log10(r+1),n=Math.log10(n+1),t=Math.log10(t+1),(this.flipAxis?t-r:n-t)*e)}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth;t.pixelHeight;const s=i+o*r+1;let a=-1,c=-1;const l=this.color||"rgb(150,150,150)";let h;"string"==typeof l&&l.startsWith("rgb(")&&(h=no.addAlpha(l,.1));const u=this.getScaleFactor(this.dataRange.min,this.dataRange.max,t.pixelHeight,this.logScale),f=t=>this.logScale?this.computeYPixelValueInLogScale(t,u):this.computeYPixelValue(t,u);if(e&&e.length>0&&(void 0===this.dataRange.min&&(this.dataRange.min=0),this.dataRange.max>this.dataRange.min)){const o=f(0);for(let t of e){if(t.end<i)continue;if(t.start>s)break;const e=Math.floor((t.start-i)/r);if(isNaN(e))continue;let h=f(t.value);const u=Math.ceil((t.end-i)/r),d=Math.max(1,u-e);let p=t.value<0&&this.altColor?this.altColor:l;const g="function"==typeof p?p(t.value):p;if("points"===this.graphType){const t=this.config.pointSize||3,r=e+d/2;ls.fillCircle(n,r,h,t/2,{fillStyle:g,strokeStyle:g})}else{let r=h-o;const i=e+d;(i>a||t.value>=0&&t.value>c||t.value<0&&t.value<1)&&ls.fillRect(n,e,o,d,r,{fillStyle:g}),c=t.value,a=i}}if(this.dataRange.min<0){const e=this.dataRange.max/(this.dataRange.max-this.dataRange.min)*t.pixelHeight;ls.strokeLine(n,0,e,t.pixelWidth,e,{strokeStyle:h})}}if(this.config.hasOwnProperty("guideLines"))for(let e of this.config.guideLines)if(e.hasOwnProperty("color")&&e.hasOwnProperty("y")&&e.hasOwnProperty("dotted")){let n=f(e.y),r={strokeStyle:e.color,strokeWidth:2};e.dotted?ls.dashedLine(t.context,0,n,t.pixelWidth,n,5,r):ls.strokeLine(t.context,0,n,t.pixelWidth,n,r)}}popupData(t,e){if((e=this.clickedFeatures(t,e))&&e.length>0){const n=t.genomicLocation,r=[];e.sort((function(t,e){return Math.abs((t.start+t.end)/2-n)-Math.abs((e.start+e.end)/2-n)}));const i=e.length>10?e.slice(0,10):e;i.sort((function(t,e){return t.start-e.start}));for(let t of i)if(t){r.length>0&&r.push("<hr/>");let e=t.end-t.start==1?_e(t.start+1):_e(t.start+1)+"-"+_e(t.end);r.push({name:"Position:",value:e}),r.push({name:"Value:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",value:_e(t.value)})}return i.length<e.length&&r.push("<hr/>..."),r}return[]}get supportsWholeGenome(){return!this.config.indexURL&&!1!==this.config.supportsWholeGenome}dispose(){this.trackView=void 0}getState(){const t=super.getState();return void 0!==this.flipAxis&&(t.flipAxis=this.flipAxis),void 0!==this.logScale&&(t.logScale=this.logScale),t}}function zu(t){this.thresholds=t.thresholds,this.colors=t.colors}function Hu(t){this.scale=t,this.lowColor="rgb("+t.lowR+","+t.lowG+","+t.lowB+")",this.highColor="rgb("+t.highR+","+t.highG+","+t.highB+")",this.diff=t.high-t.low}zu.prototype.getColor=function(t){for(let e of this.thresholds)if(t<e)return this.colors[this.thresholds.indexOf(e)];return this.colors[this.colors.length-1]},Hu.prototype.getColor=function(t){var e,n=this.scale;return t<=n.low?this.lowColor:t>=n.high?this.highColor:(e=(t-n.low)/this.diff,"rgb("+Math.floor(n.lowR+e*(n.highR-n.lowR))+","+Math.floor(n.lowG+e*(n.highG-n.lowG))+","+Math.floor(n.lowB+e*(n.highB-n.lowB))+")")};class Vu{constructor(t){this.color=t}getColor(){return this.color}}class ju extends bc{constructor(t,e){super(t,e)}init(t){if(super.init(t),this.type=t.type||"seg","maf"===this.type&&(this.type="mut"),this.isLog=t.isLog,this.displayMode=t.displayMode||"EXPANDED",this.height=t.height||300,this.maxHeight=t.maxHeight||500,this.squishedRowHeight=t.sampleSquishHeight||t.squishedRowHeight||2,this.expandedRowHeight=t.sampleExpandHeight||t.expandedRowHeight||13,this.sampleHeight=this.squishedRowHeight,t.color?this.color=t.color:(this.posColorScale=t.posColorScale||new Hu({low:.1,lowR:255,lowG:255,lowB:255,high:1.5,highR:255,highG:0,highB:0}),this.negColorScale=t.negColorScale||new Hu({low:-1.5,lowR:0,lowG:0,lowB:255,high:-.1,highR:255,highG:255,highB:255}),"mut"===this.type&&(this.colorTable=new Sc(t.colorTable||Uu))),this.sampleKeys=[],this.sampleNames=new Map,t.samples){for(let e of t.samples)this.sampleKeys.push(e),this.sampleNames.set(e,e);this.explicitSamples=!0}const e=Object.assign({},this.config);e.maxWGCount=e.maxWGCount||Number.MAX_SAFE_INTEGER,this.featureSource=Cu(e,this.browser.genome),this.initialSort=t.sort}async postInit(){"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header)}menuItemList(){const t=[],e={SQUISHED:"Squish",EXPANDED:"Expand",FILL:"Fill"};t.push("<hr/>"),t.push("DisplayMode:");const n="seg"===this.type?["SQUISHED","EXPANDED","FILL"]:["SQUISHED","EXPANDED"];for(let r of n){const n=Po(e[r],r===this.displayMode);t.push({object:de(n),click:()=>{this.displayMode=r,this.config.displayMode=r,this.trackView.checkContentHeight(),this.trackView.repaintViews(),this.trackView.moveScroller(this.trackView.sampleNameViewport.trackScrollDelta)}})}return t}hasSamples(){return!0}getSamples(){return{names:this.sampleKeys.map((t=>this.sampleNames.get(t))),height:this.sampleHeight,yOffset:0}}async getFeatures(t,e,n){const r=await this.featureSource.getFeatures({chr:t,start:e,end:n});if(this.initialSort){const t=this.initialSort;this.sortSamples(t.chr,t.start,t.end,t.direction,r),this.initialSort=void 0}return r}draw({context:t,renderSVG:e,pixelTop:n,pixelWidth:r,pixelHeight:i,features:o,bpPerPixel:s,bpStart:a}){if(ls.fillRect(t,0,0,r,i,{fillStyle:"rgb(255, 255, 255)"}),o&&o.length>0){this.checkForLog(o),this.updateSampleKeys(o);const e={};let c;switch(this.sampleKeys.forEach((function(t,n){e[t]=n})),this.displayMode){case"FILL":this.sampleHeight=i/this.sampleKeys.length,c=0;break;case"SQUISHED":this.sampleHeight=this.squishedRowHeight,c=0;break;default:this.sampleHeight=this.expandedRowHeight,c=1}const l=this.sampleHeight;for(let t of o)t.pixelRect=void 0;const h=n+i,u=a+r*s+1,f=s;this.sampleYStart=void 0;for(let r of o){if(r.end<a)continue;if(r.start>u)break;const i=r.sampleKey||r.sample;r.row=e[i];const o=r.row*l+c;void 0===this.sampleYStart&&(this.sampleYStart=o);if(o+l<n||o>h)continue;const s=Math.max(r.start,a);let d=Math.round((s-a)/f);const p=Math.min(r.end,u),g=Math.round((p-a)/f);let m,v,b=Math.max(1,g-d);if(this.color?m="function"==typeof this.color?this.color(r):this.color:this.colorTable&&(m=this.colorTable.getColor(r.value.toLowerCase())),"mut"===this.type)v=l-2*c,b<3&&(b=3,d-=1);else{let t=r.value;this.isLog||(t=Ji(t/2)),m=t<-.1?this.negColorScale.getColor(t):t>.1?this.posColorScale.getColor(t):"white";let e=l;if(l<.25){const n=.1+2*Math.abs(t);e=Math.min(1,n*l)}v=e-2*c}r.pixelRect={x:d,y:o,w:b,h:v},t.fillStyle=m,t.fillRect(d,o,b,v)}}}checkForLog(t){if(void 0===this.isLog){this.isLog=!1;for(let e of t)if(e.value<0)return void(this.isLog=!0)}}computePixelHeight(t){if(!t)return 0;const e="SQUISHED"===this.displayMode?this.squishedRowHeight:this.expandedRowHeight;return this.updateSampleKeys(t),this.sampleKeys.length*e}async sortSamples(t,e,n,r,i){if(i||(i=await this.featureSource.getFeatures({chr:t,start:e,end:n})),!i)return;this.updateSampleKeys(i);const o={},s="ASC"===r?1:-1,a=()=>{const t=n-e+1;for(let r of i){if(r.end<e)continue;if(r.start>n)break;const i=Math.max(e,r.start),s=(Math.min(n,r.end)-i)/t,a=r.sampleKey||r.sample,c=o[a]||0;o[a]=c+s*r.value}this.sampleKeys.sort((function(t,e){let n=o[t],r=o[e];return n||(n=s*Number.MAX_VALUE),r||(r=s*Number.MAX_VALUE),n===r?0:n>r?s:-1*s}))},c=()=>{for(let t of i){if(t.end<e)continue;if(t.start>n)break;const r=t.sampleKey||t.sample;(!o.hasOwnProperty(r)||t.value.localeCompare(o[r])>0)&&(o[r]=t.value)}this.sampleKeys.sort((function(t,e){let n=o[t]||"",r=o[e]||"";return s*n.localeCompare(r)}))};"mut"===this.type?c():a(),this.trackView.repaintViews()}clickedFeatures(t,e){const n=super.clickedFeatures(t,e),r=t.y;return n.filter((function(t){const e=t.pixelRect;return e&&r>=e.y&&r<=e.y+e.h}))}popupData(t,e){e=this.clickedFeatures(t);const n=[];for(let t of e){n.length>0&&(n.push("<hr/>"),n.push("<hr/>"));const e=t._f||t,r="function"==typeof e.popupData?e.popupData(this.type,this.browser.genome.id):this.extractPopupData(e);Array.prototype.push.apply(n,r)}return n}contextMenuItemList(t){const e=t.viewport.referenceFrame,n=t.genomicLocation,r=this.config.sort?"ASC"===this.config.sort.direction?"DESC":"ASC":"DESC",i=e.toBP(2.5),o=e=>{const n=t.viewport.cachedFeatures;this.sortSamples(e.chr,e.start,e.end,e.direction,n)};return[{label:"seg"===this.type?"Sort by value":"Sort by type",click:e=>{const s={direction:r,chr:t.viewport.referenceFrame.chr,start:n-i,end:n+i};o(s),this.config.sort=s}}]}get supportsWholeGenome(){return(!1===this.config.indexed||!this.config.indexURL)&&!1!==this.config.supportsWholeGenome}updateSampleKeys(t){if(!this.explicitSamples)for(let e of t){const t=e.sampleKey||e.sample;this.sampleNames.has(t)||(this.sampleNames.set(t,e.sample),this.sampleKeys.push(t))}}}const Uu={indel:"rgb(0,200,0)","targeted region":"rgb(236,155,43)",truncating:"rgb(\t150,0,0)","non-coding transcript":"rgb(0,0,150)",synonymous:"rgb(109,165,95)",silent:"rgb(109,135,80)",missense_mutation:"rgb(72,130,187)",missense:"rgb(72,130,187)","splice site":"rgb(143,83,155)",splice_region:"rgb(143,83,155)",nonsense:"rgb(216, 57,81)",nonsense_mutation:"rgb(216, 57,81)",frame_shift_del:"rgb(226,135,65)",frame_shift_ins:"rgb(226,135,65)",in_frame_del:"rgb(247,235,94)",in_frame_ins:"rgb(247,235,94)","*other*":"rgb(159,91,50)"};class qu extends bc{constructor(t,e){super(t,e),this.type="merged",this.featureType="numeric",this.paintAxis=yc}init(t){if(!t.tracks)throw Error("Error: no tracks defined for merged track"+t);super.init(t)}async postInit(){this.tracks=[];const t=[];for(let e of this.config.tracks){e.isMergedTrack=!0;const n=await this.browser.createTrack(e);n?(n.autoscale=!1,this.tracks.push(n)):console.warn("Could not create track "+e),"function"==typeof n.postInit&&t.push(n.postInit())}this.flipAxis=!!this.config.flipAxis&&this.config.flipAxis,this.logScale=!!this.config.logScale&&this.config.logScale,this.autoscale=this.config.autoscale||void 0===this.config.max,this.autoscale||(this.dataRange={min:this.config.min||0,max:this.config.max});for(let t of this.tracks)t.autoscale=!1,t.dataRange=this.dataRange;return this.height=this.config.height||50,Promise.all(t)}get height(){return this._height}set height(t){if(this._height=t,this.tracks)for(let e of this.tracks)e.height=t,e.config.height=t}menuItemList(){let t=[];return void 0!==this.flipAxis&&t.push({label:"Flip y-axis",click:()=>{this.flipAxis=!this.flipAxis,this.trackView.repaintViews()}}),t=t.concat(Oo.numericDataMenuItems(this.trackView)),t}async getFeatures(t,e,n,r){const i=this.tracks.map((i=>i.getFeatures(t,e,n,r)));return Promise.all(i)}draw(t){const e=t.features;this.autoscale&&(this.dataRange=function(t,e){let n=0,r=-Number.MAX_VALUE;for(let t of e)for(let e of t)void 0===e.value||Number.isNaN(e.value)||(n=Math.min(n,e.value),r=Math.max(r,e.value));return{min:n,max:r}}(t.referenceFrame.chr,e));for(let n=0,r=this.tracks.length;n<r;n++){const r=Object.assign({},t);r.features=e[n],this.tracks[n].dataRange=this.dataRange,this.tracks[n].flipAxis=this.flipAxis,this.tracks[n].logScale=this.logScale,this.tracks[n].graphType=this.graphType,this.tracks[n].draw(r)}}popupData(t,e){const n=e||t.viewport.cachedFeatures;if(n&&n.length===this.tracks.length){const e=[];for(let r=0;r<this.tracks.length;r++){r>0&&e.push("<hr/>"),e.push(`<div style=background-color:rgb(245,245,245);border-bottom-style:dashed;border-bottom-width:1px;padding-bottom:5px;padding-top:10px;font-weight:bold;font-size:larger >${this.tracks[r].name}</div>`);const i=this.tracks[r].popupData(t,n[r]);e.push(...i)}return e}}get supportsWholeGenome(){return this.tracks.every((t=>t.supportsWholeGenome()))}}class Wu extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.theta=t.theta||Math.PI/4,this.sinTheta=Math.sin(this.theta),this.cosTheta=Math.cos(this.theta),this.height=t.height||250,this.arcType=function(t){if(!t.arcType)return"nested";switch(t.arcType){case"chiapet":return"inView";case"chiapetoutbound":return"partialInView";default:return t.arcType}}(t),this.arcOrientation=void 0===t.arcOrientation||t.arcOrientation,this.showBlocks=void 0===t.showBlocks||t.showBlocks,this.blockHeight=t.blockHeight||3,this.thickness=t.thickness||1,this.color=t.color||"rgb(180,25,137)",this.alpha=t.alpha||.02,this.painter={flipAxis:!this.arcOrientation,dataRange:this.dataRange,paintAxis:yc},t.valueColumn?(this.valueColumn=t.valueColumn,this.hasValue=!0):t.useScore&&(this.hasValue=!0,this.valueColumn="score"),this.logScale=!1!==t.logScale,t.max?(this.dataRange={min:t.min||0,max:t.max},this.autoscale=!1):this.autoscale=!0,this.featureSource=Cu(t,this.browser.genome),this.featureSource.getWGFeatures=Yu}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow(),this.featureSource.visibilityWindow=this.visibilityWindow),this}get supportsWholeGenome(){return!0}async getFeatures(t,e,n){const r=this.visibilityWindow,i=await this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r});return void 0===this.hasValue&&i&&i.length>0&&(this.hasValue=void 0!==i[0].score),i}draw(t){"proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType?this.drawProportional(t):this.drawNested(t)}drawNested(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight,i=t.viewportWidth,o=t.bpPerPixel,s=t.bpStart,a=o;ls.fillRect(e,0,t.pixelTop,n,r,{fillStyle:"rgb(255, 255, 255)"});const c=t.features;if(c){(function(){let t=0;for(let e of c){let r=(e.start-s)/a,i=(e.end-s)/a;i>=0&&r<=n&&(t=Math.max(t,i-r))}let e=Math.min(i,t)/2;if(t>0){let t=(r-10)/e;this.theta=function(t){let e,n=[.01570925532366355,.15838444032453644,.3249196962329063,.5095254494944288,.7265425280053609,.9999999999999999],r=[.031415926535897934,.3141592653589793,.6283185307179586,.9424777960769379,1.2566370614359172,1.5707963267948966];for(e=0;e<n.length&&!(n[e]>t);e++);let i=0===e?0:n[e-1],o=e<n.length?n[e]:1,s=(t-i)/(o-i),a=0===e?0:r[e-1],c=e<r.length?r[e]:Math.PI/2;return a+s*(c-a)}(t),this.sinTheta=Math.sin(this.theta),this.cosTheta=Math.cos(this.theta)}}).call(this);const o=this.arcOrientation?t.pixelHeight:0,h=this.arcOrientation;e.font="8px sans-serif",e.textAlign="center";for(let t of c){t.drawState=void 0;let r=t.color||this.color;if(r&&this.config.useScore&&(r=Xu(r,(l=t.score,Math.min(1,.11+l/779*.89).toString()))),e.lineWidth=t.thickness||this.thickness||1,t.chr1===t.chr2||"all"===t.chr){const{m1:c,m2:l}=$u(t,this.browser.genome);let u=Math.round((c-s)/a),f=Math.round((l-s)/a);if(f<0||u>n)continue;let d=f-u;d<3&&(d=3,u--);const p=d/2,g=p/this.sinTheta,m=this.cosTheta*g,v=u+p;let b,w,y;if(h?(b=this.height+m,w=Math.PI+Math.PI/2-this.theta,y=Math.PI+Math.PI/2+this.theta):(b=-m,w=Math.PI/2-this.theta,y=Math.PI/2+this.theta),this.showBlocks&&"all"!==t.chr){const n=(t.start1-s)/a,r=(t.end1-s)/a,i=(t.start2-s)/a,c=(t.end2-s)/a,l=this.arcOrientation?-this.blockHeight:this.blockHeight;e.fillRect(n,o,r-n,l),e.fillRect(i,o,c-i,l)}r&&!this.config.useScore&&d>i&&(r=Xu(r,this.alpha)),e.strokeStyle=r,e.fillStyle=r,e.beginPath(),e.arc(v,b,g,w,y,!1),e.stroke(),t.drawState={xc:v,yc:b,r:g}}else{let i=Math.round((t.start-s)/a),o=Math.round((t.end-s)/a);if(o<0||i>n)continue;let c=o-i;c<3&&(c=3,i--);const l=t.chr===t.chr1?t.chr2:t.chr1;e.strokeStyle=r,e.fillStyle=Xu(ll(l),.5),h?(e.fillRect(i,this.height/2,c,this.height/2),e.fillText(l,i+c/2,this.height/2-5),t.drawState={x:i,y:this.height/2,w:c,h:this.height/2}):(e.fillRect(i,0,c,this.height/2),e.fillText(l,i+c/2,this.height/2+13),t.drawState={x:i,y:0,w:c,h:this.height/2})}}}var l}getScaleFactor(t,e,n,r){return r?n/(Math.log10(e+1)-(t<=0?0:Math.log10(t+1))):n/(e-t)}drawProportional(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight,i=t.bpPerPixel,o=t.bpStart,s=i,a=t.referenceFrame.start,c=t.referenceFrame.end;ls.fillRect(e,0,t.pixelTop,n,r,{fillStyle:"rgb(255, 255, 255)"});const l=t.features;if(l&&l.length>0){const r=0,i=this.getScaleFactor(r,this.dataRange.max,t.pixelHeight-1,this.logScale),h=this.arcOrientation?t.pixelHeight:0;for(let t of l){t.drawState=void 0;const r=this.valueColumn?t[this.valueColumn]:t.score;if(void 0===r||Number.isNaN(r))continue;const l=Math.round((this.logScale?Math.log10(r+1):r)*i);if(t.chr1===t.chr2||"all"===t.chr){const{m1:n,m2:i}=$u(t,this.browser.genome);let u=Math.round((n-o)/s),f=Math.round((i-o)/s)-u;if(f<3&&(f=3,u--),r<this.dataRange.min||r>this.dataRange.max)continue;if("proportional"!==this.arcType){const t="partialInView"===this.arcType,e=n>=a&&i<=c;let r=!1,o=!1;if(!e&&t&&(r=a<=n&&n<=c,r||(o=a<=i&&i<=c)),!(e||r||o))continue}const d=f/2,p=u+f/2;t.drawState={xc:p,yc:h,radiusX:d,radiusY:l};const g=!!this.arcOrientation,m=t.color||this.color;if(e.strokeStyle=m,e.lineWidth=t.thickness||this.thickness||1,!0===e.isSVG?e.strokeEllipse(p,h,d,l,0,0,Math.PI,g):(e.beginPath(),e.ellipse(p,h,d,l,0,0,Math.PI,g),e.stroke()),this.alpha&&(e.fillStyle=Xu(m,this.alpha),!0===e.isSVG?e.fillEllipse(p,h,d,l,0,0,Math.PI,g):e.fill()),this.showBlocks&&"all"!==t.chr){e.fillStyle=m;const n=(t.start1-o)/s,r=(t.end1-o)/s,i=(t.start2-o)/s,a=(t.end2-o)/s,c=this.arcOrientation?-this.blockHeight:this.blockHeight;e.fillRect(n,h,r-n,c),e.fillRect(i,h,a-i,c)}}else{let i=Math.round((t.start-o)/s),a=Math.round((t.end-o)/s);if(a<0||i>n||r<this.dataRange.min||r>this.dataRange.max)continue;const c=Math.min(l,this.height-13);let h=a-i;h<3&&(h=3,i--);const u=t.chr===t.chr1?t.chr2:t.chr1;if(e.font="8px sans-serif",e.textAlign="center",e.fillStyle=Xu(ll(u),.5),this.arcOrientation){const n=this.height-c;e.fillRect(i,n,h,c),e.fillText(u,i+h/2,n-5),t.drawState={x:i,y:n,w:h,h:c}}else e.fillRect(i,0,h,c),e.fillText(u,i+h/2,c+13),t.drawState={x:i,y:0,w:h,h:c}}}}}clearAxis(t,e,n){ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"})}paintAxis(t,e,n){const r={min:0,max:this.dataRange.max};"proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType?(this.painter.flipAxis=!this.arcOrientation,this.painter.dataRange=r,this.painter.paintAxis(t,e,n)):this.clearAxis(t,e,n)}menuItemList(){let t=[{name:"Set track color",click:()=>{this.trackView.presentColorPicker()}},"<hr/>"];if(this.hasValue){const e={nested:"Nested",proportional:"Proportional - All",inView:"Proportional - Both Ends in View",partialInView:"Proportional - One End in View"};t.push("<b>Arc Type</b>");for(let n of["nested","proportional","inView","partialInView"])t.push({object:de(Po(e[n],n===this.arcType)),click:()=>{this.arcType=n,this.trackView.repaintViews()}})}return t.push("<hr/>"),t.push({name:"Toggle arc direction",click:()=>{this.arcOrientation=!this.arcOrientation,this.trackView.repaintViews()}}),t.push({name:this.showBlocks?"Hide Blocks":"Show Blocks",click:()=>{this.showBlocks=!this.showBlocks,this.trackView.repaintViews()}}),"proportional"!==this.arcType&&"inView"!==this.arcType&&"partialInView"!==this.arcType||(t=t.concat(Oo.numericDataMenuItems(this.trackView))),this.browser.circularView&&(t.push("<hr/>"),t.push({label:"Add interactions to circular view",click:()=>{for(let t of this.trackView.viewports)this.addChordsForViewport(t.referenceFrame)}})),t}contextMenuItemList(t){if(this.browser.circularView){const e=t.viewport,n=[];return n.push({label:"Add interactions to circular view",click:()=>{const t=e.referenceFrame;this.addChordsForViewport(t)}}),n.push("<hr/>"),n}}addChordsForViewport(t){const e=("all"===t.chr?this.featureSource.getAllFeatures():this.featureSource.featureCache.queryFeatures(t.chr,t.start,t.end)).filter((t=>t.drawState));if(0===e.length)return;tl(e.map((t=>{const e=t._f||t;return{uniqueId:`${e.chr1}:${e.start1}-${e.end1}_${e.chr2}:${e.start2}-${e.end2}`,refName:Qc(e.chr1),start:e.start1,end:e.end1,mate:{refName:Qc(e.chr2),start:e.start2,end:e.end2}}})),this,t,.5)}doAutoscale(t){let e=0;if(t)for(let n of t){const t=this.valueColumn?n[this.valueColumn]:n.score;Number.isNaN(t)||(e=Math.max(e,t))}return{min:0,max:e}}popupData(t,e){e=this.clickedFeatures(t);const n=[];for(let t of e){const e=t._||t;if(n.push({name:"Region 1",value:Gu(e.chr1,e.start1,e.end1,e.strand1)}),n.push({name:"Region 2",value:Gu(e.chr2,e.start2,e.end2,e.strand2)}),e.name&&n.push({name:"Name",value:e.name}),void 0!==e.value&&n.push({name:"Value",value:e.value}),void 0!==e.score&&n.push({name:"Score",value:e.score}),e.extras&&this.header&&this.header.columnNames){const t=this.header.columnNames;for(let r=10;r<t.length;r++)"info"===t[r]?Ku(n,e.extras[r-10]):n.push({name:t[r],value:e.extras[r-10]})}break}return n}clickedFeatures(t,e){const n=e||t.viewport.cachedFeatures,r=[];if(n){const e="proportional"===this.arcType||"inView"===this.arcType||"partialInView"===this.arcType;for(let i of n)if(i.drawState)if(i.chr1===i.chr2||"all"===i.chr)if(e){const{xc:e,yc:n,radiusX:o,radiusY:s}=i.drawState,a=t.canvasX-e,c=t.canvasY-n,l=a/o*(a/o)+c/s*(c/s);l<=1&&r.push({score:1/l,feature:i})}else{const{xc:e,yc:n,r:o}=i.drawState,s=t.canvasX-e,a=t.canvasY-n,c=Math.abs(Math.sqrt(s*s+a*a)-o);c<5&&r.push({score:c,feature:i})}else{const{x:e,y:n,w:o,h:s}=i.drawState,a=5;if(t.canvasX>=e-a&&t.canvasX<=e+o+a&&t.canvasY>=n&&t.canvasY<=n+s){const n=-Math.abs(t.canvasX-(e+o/2));r.push({score:n,feature:i});break}}}return r.length>1&&r.sort(((t,e)=>t.score-e.score)),r.map((t=>t.feature))}getState(){const t=super.getState();return void 0!==this.arcType&&(t.arcType=this.arcType),void 0!==this.arcOrientation&&(t.arcOrientation=this.arcOrientation),void 0!==this.showBlocks&&(t.showBlocks=this.showBlocks),void 0!==this.blockHeight&&(t.blockHeight=this.blockHeight),void 0!==this.thickness&&(t.thickness=this.thickness),void 0!==this.alpha&&(t.alpha=this.alpha),t}}function $u(t,e){let n=(t.start1+t.end1)/2,r=(t.start2+t.end2)/2;if("all"===t.chr&&(n=e.getGenomeCoordinate(t.chr1,n),r=e.getGenomeCoordinate(t.chr2,r)),n>r){const t=n;n=r,r=t}return{m1:n,m2:r}}function Gu(t,e,n,r){return r&&"."!==r?`${t}:${_e(e+1)}-${_e(n)} (${r})`:`${t}:${_e(e+1)}-${_e(n)}`}const Zu=new Map;function Xu(t,e){const n=`${t}_${e}`;let r=Zu.get(n);return r||(r=no.addAlpha(t,e),Zu.set(n,r)),r}function Yu(t){const e=t=>{const e=Object.assign({},t);return e.chr="all",e.start=n.getGenomeCoordinate(t.chr1,t.start1),e.end=n.getGenomeCoordinate(t.chr2,t.end2),e},n=this.genome;let r,i=0;for(let e of n.wgChromosomeNames){let n=t[e];if(n)for(let t of n)t.dup||(i++,t.score&&(!r||t.score>r.score)&&(r=t))}const o=this.maxWGCount,s=r&&r.score>0&&i>o?5:1,a=Math.floor(o/s),c=r&&r.score>0?Math.log(r.score)/s:Number.MAX_SAFE_INTEGER;let l,h=[],u=[];for(let t=0;t<s;t++)u.push([0]),h.push([]);for(let r of n.wgChromosomeNames){let n=t[r];if(n)for(let t of n)if(!t.dup){const n=t.score?Math.min(s-1,Math.floor(Math.log(t.score)/c)):0;if(h[n].length<a)h[n].push(e(t));else{const r=a/(u[n]+1);if(Math.random()<r){const r=Math.floor(Math.random()*(a-1));h[n][r]=e(t)}}u[n]++}}if(1===s)l=h[0];else{l=[];for(let t of h)for(let e of t)l.push(e);r&&l.push(e(r)),l.sort((function(t,e){return t.start-e.start})),console.log(l.length)}return l}function Ku(t,e){const n=e.split(";");for(let e of n){const n=e.split("=");2===n.length&&t.push({name:n[0],value:n[1]})}}const Qu=ke,Ju=new Map([["REF","referenceBases"],["ALT","alternateBases"],["QUAL","quality"],["FILTER","filter"]]);class tf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.visibilityWindow=t.visibilityWindow,this.displayMode=t.displayMode||"EXPANDED",this.labelDisplayMode=t.labelDisplayMode,this.expandedVariantHeight=t.expandedVariantHeight||t.variantHeight||10,this.squishedVariantHeight=t.squishedVariantHeight||2,this.squishedCallHeight=t.squishedCallHeight||1,this.expandedCallHeight=t.expandedCallHeight||10,this.expandedVGap=void 0!==t.expandedVGap?t.expandedVGap:2,this.squishedVGap=void 0!==t.squishedVGap?t.squishedVGap:1,this.expandedGroupGap=t.expandedGroupGap||10,this.squishedGroupGap=t.squishedGroupGap||5,this.featureHeight=t.featureHeight||14,this.visibilityWindow=t.visibilityWindow,this.featureSource=Cu(t,this.browser.genome),this.noGenotypeColor=t.noGenotypeColor||"rgb(200,180,180)",this.noCallColor=t.noCallColor||"rgb(225, 225, 225)",this.nonRefColor=t.nonRefColor||"rgb(200, 200, 215)",this.mixedColor=t.mixedColor||"rgb(200, 220, 200)",this.homrefColor=t.homrefColor||"rgb(200, 200, 200)",this.homvarColor=t.homvarColor||"rgb(17,248,254)",this.hetvarColor=t.hetvarColor||"rgb(34,12,253)",this.sortDirection="ASC",this.type=t.type||"variant",this.colorBy=t.colorBy,this._initColorBy=t.colorBy,t.colorTable&&(this.colorTables=new Map,this.colorTables.set(t.colorBy,new Sc(t.colorTable))),this.showGenotypes=void 0===t.showGenotypes||t.showGenotypes,this.variantRowCount(1)}async postInit(){if(this.header=await this.getHeader(),void 0===this.visibilityWindow&&!1!==this.config.indexed){const t=je(this.config.url)?this.config.url.name:this.config.url;Qu(t)&&t.toLowerCase().includes("gnomad")?this.visibilityWindow=1e3:"function"==typeof this.featureSource.defaultVisibilityWindow?this.visibilityWindow=await this.featureSource.defaultVisibilityWindow():this.visibilityWindow=1e6}return this}get supportsWholeGenome(){return!1===this.config.indexed||!0===this.config.supportsWholeGenome}get color(){return this._color}set color(t){this._color=t,this.colorBy=void 0}async getHeader(){if(!this.header){if("function"==typeof this.featureSource.getHeader){const t=await this.featureSource.getHeader();t&&(this.callSets=t.callSets||[]),this.header=t}this.sampleNames=this.callSets?this.callSets.map((t=>t.name)):[]}return this.header}getCallsetsLength(){return this.callSets?this.callSets.length:0}async getFeatures(t,e,n,r){return void 0===this.header&&(this.header=await this.getHeader()),this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:this.visibilityWindow})}hasSamples(){return this.getCallsetsLength()>0}getSamples(){return{yOffset:this.sampleYOffset,names:this.sampleNames,height:this.sampleHeight}}computePixelHeight(t){if(!t||0==t.length)return 10;const e="COLLAPSED"===this.displayMode?1:this.nVariantRows,n="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,r="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,i="SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight;return 10+e*(r+n)+n+((!1===this.showGenotypes?0:this.getCallsetsLength()*e)+1)*(i+n)}variantRowCount(t){this.nVariantRows=t}draw({context:t,pixelWidth:e,pixelHeight:n,bpPerPixel:r,bpStart:i,pixelTop:o,features:s}){ls.fillRect(t,0,o,e,n,{fillStyle:"rgb(255, 255, 255)"});const a="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,c="COLLAPSED"===this.displayMode?1:this.nVariantRows,l="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight;this.variantBandHeight=10+c*(l+a);const h=this.callSets,u=this.getCallsetsLength();if(h&&u>0&&!1!==this.showGenotypes&&ls.strokeLine(t,0,this.variantBandHeight,e,this.variantBandHeight,{strokeStyle:"rgb(224,224,224) "}),s){const n="SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight,o="SQUISHED"===this.displayMode?this.squishedVGap:this.expandedVGap,a=i+e*r+1;for(let e of s){if(e.end<i)continue;if(e.start>a)break;const s="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,c=10+("COLLAPSED"===this.displayMode?0:e.row*(s+o)),l=s;let f=Math.round((e.start-i)/r),d=Math.round((e.end-i)/r),p=Math.max(1,d-f);if(p<3?(p=3,f-=1):p>5&&(f+=1,p-=2),t.fillStyle=this.getVariantColor(e),t.fillRect(f,c,p,l),e.pixelRect={x:f,y:c,w:p,h:l},u>0&&!1!==this.showGenotypes){const r="COLLAPSED"===this.displayMode?1:this.nVariantRows;this.sampleYOffset=this.variantBandHeight+o,this.sampleHeight=r*(n+o);let i=0;for(let r of h){const s=e.calls[r.id];if(s){const a="COLLAPSED"===this.displayMode?0:e.row,c=this.sampleYOffset+i*this.sampleHeight+a*(n+o);let l=!0,h=!0,u=!1;if(s.genotype)for(let t of s.genotype){if("."===t){u=!0;break}0!==t&&(h=!1),0===t&&(l=!1)}s.genotype?t.fillStyle=u?this.noCallColor:h?this.homrefColor:l?this.homvarColor:this.hetvarColor:t.fillStyle=this.noGenotypeColor,t.fillRect(f,c,p,n),r.pixelRect={x:f,y:c,w:p,h:n}}i++}}}}else console.log("No feature list")}getVariantColor(t){const e=t._f||t;let n;if(this.colorBy){const t=this.colorBy;let r;if(e.info.hasOwnProperty(t))r=e.info[t];else if(Ju.has(t)){r=e[Ju.get(t)]}n=this.getVariantColorTable(t).getColor(r),n||(n="gray")}else n=this._color?"function"==typeof this._color?this._color(t):this._color:"NONVARIANT"===e.type?this.nonRefColor:"MIXED"===e.type?this.mixedColor:this.defaultColor;return n}clickedFeatures(t,e){let n=super.clickedFeatures(t,e);const r="EXPANDED"===this.displayMode?this.expandedVGap:this.squishedVGap,i=r+("SQUISHED"===this.displayMode?this.squishedCallHeight:this.expandedCallHeight),o=t.y;if(o<=this.variantBandHeight){const t="SQUISHED"===this.displayMode?this.squishedVariantHeight:this.expandedVariantHeight,e=Math.floor((o-10)/(t+r));"COLLAPSED"!==this.displayMode&&(n=n.filter((t=>t.row===e)))}else if(this.callSets){const t=this.callSets,e=o-this.variantBandHeight,r=Math.floor(e/this.sampleHeight);if(r>=0&&r<t.length){const o=Math.floor((e-r*this.sampleHeight)/i),s="COLLAPSED"===this.displayMode?n:n.filter((t=>t.row===o)),a=t[r];n=s.map((t=>{const e=t.calls[a.id];return function(t,e){if(t.genotype){let n="";if("."===e.alternateBases)n="No Call";else{const r=e.alternateBases.split(",");for(let i of t.genotype)if(n.length>0&&(n+="|"),"."===i)n+=".";else if(0===i)n+=e.referenceBases;else{n+=r[i-1].replace("<","&lt;")}}t.genotypeName=n}}(e,t),e}))}}return n}popupData(t,e){const n=this.clickedFeatures(t,e),r=t.genomicLocation,i=this.browser.genome.id,o=this.browser.sampleInformation;let s=[];for(let t of n){const e=t._f||t;if(s.length>0&&s.push({html:'<hr style="border-top-width:2px ;border-color: #c9c3ba" />'}),"function"==typeof e.popupData){const t=e.popupData(r,i);Array.prototype.push.apply(s,t)}else{const t=e;if(void 0!==t.callSetName&&s.push({name:"Name",value:t.callSetName}),t.genotypeName&&s.push({name:"Genotype",value:t.genotypeName}),void 0!==t.phaseset&&s.push({name:"Phase set",value:t.phaseset}),void 0!==t.genotypeLikelihood&&s.push({name:"genotypeLikelihood",value:t.genotypeLikelihood.toString()}),o){var a=o.getAttributes(t.callSetName);a&&Object.keys(a).forEach((function(t){var e=t.replace(/([A-Z])/g," $1");e=e.charAt(0).toUpperCase()+e.slice(1),s.push({name:e,value:a[t]})}))}var c=Object.keys(t.info);c.length&&s.push("<hr/>"),c.forEach((function(e){s.push({name:e,value:decodeURIComponent(t.info[e])})}))}}return s}menuItemList(){const t=[];if(this.header.INFO&&this.header.INFO){const e=this.header.INFO.SVTYPE?["SVTYPE"]:[];if(this._initColorBy&&"SVTYPE"!==this._initColorBy&&e.push(this._initColorBy),e.length>0){t.push("<hr/>");const n=de('<div class="igv-track-menu-category igv-track-menu-border-top">');n.text("Color by:"),t.push({name:void 0,object:n,click:void 0,init:void 0}),e.sort();for(let n of e){const e=this.colorBy===n,r=n||"None";t.push(this.colorByCB({key:n,label:r},e))}t.push(this.colorByCB({key:void 0,label:"None"},void 0===this.colorBy)),t.push("<hr/>")}}this.getCallsetsLength()>0&&(t.push({object:de('<div class="igv-track-menu-border-top">')}),t.push({object:de(Po("Show Genotypes",this.showGenotypes)),click:()=>{this.showGenotypes=!this.showGenotypes,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})),t.push({object:de('<div class="igv-track-menu-border-top">')});for(let e of["COLLAPSED","SQUISHED","EXPANDED"]){t.push({object:de(Po({COLLAPSED:"Collapse",SQUISHED:"Squish",EXPANDED:"Expand"}[e],e===this.displayMode)),click:()=>{this.displayMode=e,this.trackView.checkContentHeight(),this.trackView.repaintViews()}})}return this.browser.circularView&&(t.push("<hr>"),t.push({label:"Add SVs to circular view",click:()=>{for(let t of this.trackView.viewports)this.sendChordsForViewport(t)}})),t}contextMenuItemList(t){if(this.browser.circularView){const e=t.viewport,n=[];return n.push({label:"Add SVs to Circular View",click:()=>{this.sendChordsForViewport(e)}}),n.push("<hr/>"),n}}sendChordsForViewport(t){const e=t.referenceFrame,n="all"===e.chr?this.featureSource.getAllFeatures():this.featureSource.featureCache.queryFeatures(e.chr,e.start,e.end);tl(n.filter((t=>{const e=t._f||t;return e.info&&e.info.CHR2&&e.info.END&&(e.info.CHR2!==e.chr||Math.abs(Number.parseInt(e.info.END)-e.pos)>1e6)})).map((t=>{const e=t._f||t,n=Number.parseInt(e.info.END),r=n-100,i=n+100;return{uniqueId:`${e.chr}:${e.start}-${e.end}_${e.info.CHR2}:${e.info.END}`,refName:Qc(e.chr),start:e.start,end:e.end,mate:{refName:Qc(e.info.CHR2),start:r,end:i}}})),this,e,.5)}colorByCB(t,e){return{name:void 0,object:de(Po(t.label,e)),click:()=>{t.key===this.colorBy?(this.colorBy=void 0,delete this.config.colorBy,this.trackView.repaintViews()):(this.colorBy=t.key,this.config.colorBy=t.key,this.trackView.repaintViews())},init:void 0}}getState(){const t=super.getState();return this._color&&"function"!=typeof this._color&&(t.color=this._color),t}getVariantColorTable(t){if(this.colorTables||(this.colorTables=new Map),!this.colorTables.has(t)){let e;if("SVTYPE"===t)e=ef;else e=new _c("Set1");this.colorTables.set(t,e)}return this.colorTables.get(t)}}const ef=new Sc({DEL:"#ff2101",INS:"#001888",DUP:"#028401",INV:"#008688",CNV:"#8931ff",BND:"#891100","*":"#002eff"});class nf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.name=t.name,this.pValueField=t.pValueField||"pValue",this.geneField=t.geneField||"geneSymbol",this.snpField=t.snpField||"snp";const e=t.minLogP||t.min,n=t.maxLogP||t.max;this.dataRange={min:e||3.5,max:n||25},this.autoscale=!n||t.autoscale,this.autoscalePercentile=void 0===t.autoscalePercentile?98:t.autoscalePercentile,this.background=t.background,this.divider=t.divider||"rgb(225,225,225)",this.dotSize=t.dotSize||2,this.height=t.height||100,this.autoHeight=!1,this.disableButtons=t.disableButtons,this.visibilityWindow=void 0===t.visibilityWindow?2e6:t.visibilityWindow>=0?Math.min(2e6,t.visibilityWindow):2e6,this.featureSource=Cu(t,this.browser.genome),Eu.gtexLoaded=!0}paintAxis(t,e,n){const r=(this.dataRange.max-this.dataRange.min)/n,i={font:"normal 10px Arial",textAlign:"right",strokeStyle:"black"};ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"});const o=Math.ceil(10*(this.dataRange.max-this.dataRange.min)/n);for(let s=4;s<=this.dataRange.max;s+=o){const o=.85*e,a=o-5,c=o,l=n-(s-this.dataRange.min)/r;ls.strokeLine(t,a,l,c,l,i),l>8&&ls.fillText(t,s,a-1,l+2,i)}i.textAlign="center",ls.fillText(t,"-log10(pvalue)",e/4,n/2,i,{rotate:{angle:-90}})}async getFeatures(t,e,n){const r=this.pValueField,i=this.visibilityWindow,o=await this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:i});return o.forEach((function(t){t.value=t[r]})),o}draw(t){const e=t.context,n=t.pixelWidth,r=t.pixelHeight;this.background&&ls.fillRect(e,0,0,n,r,{fillStyle:this.background}),ls.strokeLine(e,0,r-1,n,r-1,{strokeStyle:this.divider});const i=i=>{const o=i?2*this.dotSize:this.dotSize,s=t.bpStart,a=(this.dataRange.max-this.dataRange.min)/r,c=t.referenceFrame.selection;for(let h of t.features){const u=(h.start-s+.5)/t.bpPerPixel;if(u<0)continue;if(u>n)break;const f=h.snp.toUpperCase(),d=h[this.geneField].toUpperCase(),p=c&&(c.snp===f||c.gene===d);if(!i||p){c&&c.snp===f&&c.addGene(d);var l=-Math.log(h[this.pValueField])/Math.LN10;if(l>=this.dataRange.min){let t;l>this.dataRange.max?(l=this.dataRange.max,t=!0):t=!1;const n=Math.max(0+o,r-Math.round((l-this.dataRange.min)/a));let s;h.px=u,h.py=n,h.radius=o,i&&c?(s=c.colorForGene(d),ls.setProperties(e,{fillStyle:s,strokeStyle:"black"})):(s=t?"rgb(150, 150, 150)":"rgb(180, 180, 180)",ls.setProperties(e,{fillStyle:s,strokeStyle:s})),ls.fillCircle(e,u,n,o),ls.strokeCircle(e,u,n,o)}}}};i(!1),i(!0)}popupData(t){let e=t.viewport.cachedFeatures;if(!e||0===e.length)return[];const n=this.name,r=[];for(let i of e)Math.abs(i.px-t.canvasX)<i.radius+3&&Math.abs(i.py-t.canvasY)<i.radius+3&&(r.length>0&&r.push("<hr/>"),r.push({name:"snp id",value:i.snp},{name:"gene id",value:i.geneId},{name:"gene name",value:i.geneName},{name:"p value",value:i.pValue},{name:"tissue",value:n}));return r}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}doAutoscale(t){if(t.length>0){var e=t.map((function(t){return-Math.log(t.value)/Math.LN10}));this.dataRange.max=Ki(e,this.autoscalePercentile)}else{const t=this.config.maxLogP||this.config.max;this.dataRange.max=t||25}return this.dataRange}}const rf={X:"rgb(204, 153, 0)",Y:"rgb(153, 204, 0)",Un:"darkGray)",1:"rgb(80, 80, 255)",I:"rgb(139, 155, 187)",2:"rgb(206, 61, 50)",II:"rgb(206, 61, 50)","2a":"rgb(210, 65, 55)","2b":"rgb(215, 70, 60)",3:"rgb(116, 155, 88)",III:"rgb(116, 155, 88)",4:"rgb(240, 230, 133)",IV:"rgb(240, 230, 133)",5:"rgb(70, 105, 131)",6:"rgb(186, 99, 56)",7:"rgb(93, 177, 221)",8:"rgb(128, 34, 104)",9:"rgb(107, 215, 107)",10:"rgb(213, 149, 167)",11:"rgb(146, 72, 34)",12:"rgb(131, 123, 141)",13:"rgb(199, 81, 39)",14:"rgb(213, 143, 92)",15:"rgb(122, 101, 165)",16:"rgb(228, 175, 105)",17:"rgb(59, 27, 83)",18:"rgb(205, 222, 183)",19:"rgb(97, 42, 121)",20:"rgb(174, 31, 99)",21:"rgb(231, 199, 111)",22:"rgb(90, 101, 94)",23:"rgb(204, 153, 0)",24:"rgb(153, 204, 0)",25:"rgb(51, 204, 0)",26:"rgb(0, 204, 51)",27:"rgb(0, 204, 153)",28:"rgb(0, 153, 204)",29:"rgb(10, 71, 255)",30:"rgb(71, 117, 255)",31:"rgb(255, 194, 10)",32:"rgb(255, 209, 71)",33:"rgb(153, 0, 51)",34:"rgb(153, 26, 0)",35:"rgb(153, 102, 0)",36:"rgb(128, 153, 0)",37:"rgb(51, 153, 0)",38:"rgb(0, 153, 26)",39:"rgb(0, 153, 102)",40:"rgb(0, 128, 153)",41:"rgb(0, 51, 153)",42:"rgb(26, 0, 153)",43:"rgb(102, 0, 153)",44:"rgb(153, 0, 128)",45:"rgb(214, 0, 71)",46:"rgb(255, 20, 99)",47:"rgb(0, 214, 143)",48:"rgb(20, 255, 177)"};for(let pd of Object.keys(rf)){rf["chr"+pd]=rf[pd]}class of extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.useChrColors=void 0===t.useChrColors||t.useChrColors,this.trait=t.trait,this.posteriorProbability=t.posteriorProbability,this.valueProperty="bed"===t.format?"score":"value",this.height=t.height||100,this.autoscale=t.autoscale,this.autoscalePercentile=void 0===t.autoscalePercentile?98:t.autoscalePercentile,this.background=t.background,this.divider=t.divider||"rgb(225,225,225)",this.dotSize=t.dotSize||3,this.popoverWindow=void 0===t.popoverWindow?1e8:t.popoverWindow,this.colorScales=t.color?new Vu(t.color):{"*":new zu(t.colorScale||{thresholds:[5e-8,5e-4,.5],colors:["rgb(255,50,50)","rgb(251,100,100)","rgb(251,170,170)","rgb(227,238,249)"]})},this.featureSource=Cu(t,this.browser.genome)}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),this.autoscale||(this.posteriorProbability?this.dataRange={min:void 0===this.config.min?0:this.config.min,max:void 0===this.config.max?1:this.config.max}:this.dataRange={min:void 0===this.config.min?0:this.config.min,max:void 0===this.config.max?25:this.config.max}),this}get supportsWholeGenome(){return!0}async getFeatures(t,e,n){const r=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r})}draw(t){const e=t.features,n=t.context,r=t.pixelWidth,i=t.pixelHeight;if(this.background&&ls.fillRect(n,0,0,r,i,{fillStyle:this.background}),ls.strokeLine(n,0,i-1,r,i-1,{strokeStyle:this.divider}),e){const o=t.bpPerPixel,s=t.bpStart,a=s+r*o+1;for(let t of e){const e=t.start;if(e<s)continue;if(e>a)break;const r=this.getColorScale(t._f?t._f.chr:t.chr);let c,l;if(this.posteriorProbability)l=t[this.valueProperty],c=r.getColor(l);else{const e=t[this.valueProperty];if(!e)continue;l=-Math.log10(e),c=r.getColor(l)}const h=(this.dataRange.max-this.dataRange.min)/i,u=Math.round((e-s)/o),f=Math.max(this.dotSize,i-Math.round((l-this.dataRange.min)/h));c&&ls.setProperties(n,{fillStyle:c,strokeStyle:"black"}),ls.fillCircle(n,u,f,this.dotSize),t.px=u,t.py=f}}}getColorScale(t){if(this.useChrColors){let e=this.colorScales[t];if(!e){const n=rf[t]||Ec.get();e=new Vu(n),this.colorScales[t]=e}return e}return this.colorScales("*")}paintAxis(t,e,n){ls.fillRect(t,0,0,e,n,{fillStyle:"rgb(255, 255, 255)"});var r={font:"normal 10px Arial",textAlign:"right",strokeStyle:"black"};const i=(this.dataRange.max-this.dataRange.min)/n;if(this.posteriorProbability){const e=.1;for(let o=this.dataRange.min;o<this.dataRange.max;o+=e){const e=n-Math.round((o-this.dataRange.min)/i);ls.strokeLine(t,45,e-2,50,e-2,r),ls.fillText(t,o.toFixed(1),44,e+2,r)}}else{const e=Math.ceil(10*(this.dataRange.max-this.dataRange.min)/n);for(let o=this.dataRange.min;o<this.dataRange.max;o+=e){const e=n-Math.round((o-this.dataRange.min)/i);ls.strokeLine(t,45,e,50,e,r),ls.fillText(t,Math.floor(o),44,e+4,r)}}r.textAlign="center",this.posteriorProbability?ls.fillText(t,"PPA",e/2,n/2,r,{rotate:{angle:-90}}):ls.fillText(t,"-log10(pvalue)",e/2,n/2,r,{rotate:{angle:-90}})}popupData(t){let e=[];const n=t.viewport.trackView.track,r=t.viewport.cachedFeatures;if(r){let i=0;for(let o of r){const r=Math.abs(t.canvasX-o.px),s=Math.abs(t.canvasY-o.py),a=o[this.valueProperty];if(r<this.dotSize&&s<this.dotSize){if(i>0&&e.push("<HR/>"),5==i){e.push("...");break}if("function"==typeof o.popupData)e=e.concat(o.popupData());else{const t=o.realChr||o.chr,r=(o.realStart||o.start)+1;e.push({name:"chromosome",value:t}),e.push({name:"position",value:r}),e.push({name:"name",value:o.name}),n.posteriorProbability?e.push({name:"posterior probability",value:a}):e.push({name:"pValue",value:a})}i++}}}return e}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}doAutoscale(t){if(t.length>0){const e=this.valueProperty,n=this.posteriorProbability,r=t.map((function(t){const r=t[e];return{value:n?r:-Math.log(r)/Math.LN10}}));this.dataRange=ms(r)}else this.posteriorProbability?(this.dataRange.min=this.config.min||0,this.dataRange.max=this.config.max||1):(this.dataRange.max=this.config.max||25,this.dataRange.min=this.config.min||0);return this.dataRange}}class sf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.autoscale=t.autoscale||void 0===t.max,this.dataRange={min:t.min||0,max:t.max},this.windowFunction=t.windowFunction||"mean",this.paintAxis=yc,this.graphType=t.graphType||"bar",t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=Cu(this.config,this.browser.genome),this.visibilityWindow=-1,this.featureSource.visibilityWindow=this.visibilityWindow}async postInit(){if("function"==typeof this.featureSource.getHeader){if(this.header=await this.featureSource.getHeader(),this.sampleNames=this.header.columnNames.slice(3),this.setTrackProperties(this.header),this.header.hasOwnProperty("clickToHighlight")){let t=this.header.clickToHighlight;this.config.clickToHighlight=t,this.config.samplesClickedToHighlight={}}if(this.header.hasOwnProperty("highlight")){this.config.highlightSamples={};let t=this.header.highlight;Array.isArray(t)||(t=[t]);for(let e of t){const t=e.split(";");2===t.length&&(this.config.highlightSamples[t[0]]=t[1])}}}}menuItemList(){return Oo.numericDataMenuItems(this.trackView)}async getFeatures(t,e,n){const r=await this.featureSource.getFeatures({chr:t,start:0,end:Number.MAX_SAFE_INTEGER,visibilityWindow:this.visibilityWindow});let i,o;for(let t=1;t<r.length-1;t++)if(void 0===i&&r[t].end>e&&(i=t-1),void 0===o&&r[t].start>n){o=t+1;break}return void 0===i&&(i=0),void 0===o&&(o=r.length),r.slice(i,o)}draw(t){const{features:e,context:n,bpPerPixel:r,bpStart:i,pixelWidth:o,pixelHeight:s}=t,a=t=>(this.dataRange.max-t)/(this.dataRange.max-this.dataRange.min)*s,c=function(t){let e=Math.floor((t-i)/r);return isNaN(e)&&console.warn("isNaN(x). feature start "+_e(t)+" bp start "+_e(i)),e};if(e&&e.length>0&&(void 0===this.dataRange.min&&(this.dataRange.min=0),this.dataRange.max>this.dataRange.min)){const t=this.config.highlightSamples,r=this.config.onlyHandleClicksForHighlightedSamples,i=this.config.clickToHighlight;let o=-1,s={},l=[],h=[];this.clickDetectorCache={};for(let u of e){const e=c(u.start),f=c(u.end),d=o>=0?c(o):e;if(!isNaN(e)&&!isNaN(f)){this.clickDetectorCache[e]=[],this.clickDetectorCache[f]=[];for(let o=0;o<u.values.length;o++){const c=this.sampleNames[o],p=u.values[o],g=a(p);if(e-d>=1){const o=s[c],h=a(o),u=t&&t[c];u?l.push([d,h,e,g,u]):i&&c in this.config.samplesClickedToHighlight?l.push([d,h,e,g,this.config.samplesClickedToHighlight[c]]):ls.strokeLine(n,d,h,e,g,{strokeStyle:"#D9D9D9"}),r&&!(c in t)||this.clickDetectorCache[e].push([d,h,e,g,c,u||"gray"])}if(f-e>=1){const o=t&&t[c];o?h.push([e,g,f,g,o]):i&&c in this.config.samplesClickedToHighlight?h.push([e,g,f,g,this.config.samplesClickedToHighlight[c]]):ls.strokeLine(n,e,g,f,g,{strokeStyle:"gray"}),r&&!(c in t)||this.clickDetectorCache[f].push([e,g,f,g,c,o||"gray"])}s[c]=p}o=u.end}}for(let t of l)ls.strokeLine(n,t[0],t[1],t[2],t[3],{strokeStyle:t[4],lineWidth:1.3});for(let t of h)ls.strokeLine(n,t[0],t[1],t[2],t[3],{strokeStyle:t[4],lineWidth:2})}(t=>{if(this.config.hasOwnProperty("guideLines"))for(let e of this.config.guideLines)if(e.hasOwnProperty("color")&&e.hasOwnProperty("y")&&e.hasOwnProperty("dotted")){let n=a(e.y),r={strokeStyle:e.color,strokeWidth:2};e.dotted?ls.dashedLine(t.context,0,n,t.pixelWidth,n,5,r):ls.strokeLine(t.context,0,n,t.pixelWidth,n,r)}})(t)}doAutoscale(t){let e,n;return t.length>0?(e=Number.MAX_VALUE,n=-Number.MAX_VALUE,t.forEach((function(t){e=Math.min(e,...t.values),n=Math.max(n,...t.values)})),e-=.01,n+=.01):(e=0,n=100),{min:e,max:n}}clickedFeatures(t){const e=t.canvasX,n=t.canvasY;let r=null;for(r of Object.keys(this.clickDetectorCache))if(r=parseInt(r),r>=e)break;if(r){let t=Number.MAX_VALUE,s=[];const a=this.clickDetectorCache[r];for(let r of a){const i=r[0],o=r[2];if(e<i||e>o)return[];const a=r[1],c=r[3];if(n<Math.min(a,c)-10||n>Math.max(a,c)+10)continue;const l=af(e,n,i,a,o,c);l<t&&(s=[{name:r[4],color:r[5]}],t=l)}if(t<5){if(this.config.clickToHighlight){if(s[0].name in this.config.samplesClickedToHighlight)delete this.config.samplesClickedToHighlight[s[0].name];else if("any"===this.config.clickToHighlight){var i=["red","darkblue","green","teal","olivedrab","orange","maroon","purple","blue","gold"],o=i[Math.floor(Math.random()*(i.length+1))];this.config.samplesClickedToHighlight[s[0].name]=o}else this.config.samplesClickedToHighlight[s[0].name]=this.config.clickToHighlight;this.trackView.repaintViews()}return s}}return[]}popupData(t,e){e=this.clickedFeatures(t,e);const n=[];return e.forEach((function(t){for(let e of Object.keys(t))ps(t[e])&&n.push({name:e,value:t[e]})})),n}get supportsWholeGenome(){return!1}}function af(t,e,n,r,i,o){const s=i-n,a=o-r,c=Math.abs(s*(r-e)-(n-t)*a),l=Math.sqrt(s*s+a*a);return l>0?c/l:0}class cf extends bc{constructor(t,e){super(t,e),t.height||(this.height=300),this.arcOrientation=!1,this.theta=Math.PI/2,"bp"===t.format?this.featureSource=new hf(t,e.genome):this.featureSource=new Jh(t,e.genome)}async getFeatures(t,e,n){const r=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,visibilityWindow:r})}draw(t){const e=t.context,n=Math.PI/2,r=t.pixelWidth,i=t.pixelHeight;t.viewportWidth;const o=t.bpPerPixel,s=t.bpStart,a=o,c=this.arcOrientation;ls.fillRect(e,0,t.pixelTop,r,i,{fillStyle:"rgb(255, 255, 255)"});const l=t.features;if(l){lf(l,1);for(let t of l)if(t.startLeft){let r=Math.round((t.startLeft-s)/a),i=Math.round((t.startRight-s)/a),o=Math.round((t.endLeft-s)/a),l=Math.round((t.endRight-s)/a);e.fillStyle=t.color,e.strokeStyle=t.color,e.beginPath();let h=(r+l)/2,u=(l-r)/2,f=this.height,d=Math.PI+(Math.PI/2-n),p=2*Math.PI-(Math.PI/2-n);c?(f=0,e.arc(h,f,u,p,d),e.lineTo(l,f)):(e.arc(h,f,u,d,p),e.lineTo(o,f));const g=(i+o)/2,m=(o-i)/2,v=f;c?(e.arc(g,v,m,d,p,!0),e.lineTo(o,v)):(e.arc(g,v,m,p,d,!0),e.lineTo(r,v)),e.stroke(),e.fill(),t.drawState={x1:h,y1:f,r1:u,x2:g,y2:v,r2:m,sa:d,ea:p}}else{let r=Math.round((t.start-s)/a),i=Math.round((t.end-s)/a);e.strokeStyle=t.color,e.beginPath();let o=(r+i)/2,l=(i-r)/2,h=this.height,u=Math.PI+(Math.PI/2-n),f=2*Math.PI-(Math.PI/2-n);c?(h=0,e.arc(o,h,l,f,u)):e.arc(o,h,l,u,f),e.stroke(),t.drawState={x1:o,y1:h,r1:l,sa:u,ea:f}}}}clickedFeatures(t,e){const n=[];lf(e=super.clickedFeatures(t,e),-1);for(let r of e){const e=r.drawState,i=t.canvasX-e.x1,o=t.canvasY-e.y1,s=Math.sqrt(i*i+o*o),a=e.r1+3;let c,l;if(void 0===e.x2)c=s,l=e.r1-3;else{const n=t.canvasX-e.x2,r=t.canvasY-e.y2;c=Math.sqrt(n*n+r*r),l=e.r2-3}if(s<a&&c>l){n.push(r);break}}return n}popupData(t,e){if((e=this.clickedFeatures(t,e))&&e.length>0)return bc.extractPopupData(e[0],this.getGenomeId())}menuItemList(){var t=this;return[{name:"Toggle arc direction",click:function(){t.arcOrientation=!t.arcOrientation,t.trackView.repaintViews()}}]}}function lf(t,e){t.sort((function(t,n){const r=void 0===t.score?-Number.MAX_VALUE:t.score,i=void 0===n.score?-Number.MAX_VALUE:n.score;return(void 0===e?1:e)*(r-i)}))}class hf{constructor(t,e){this.config=t,this.genome=e}async getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i}){const o=this.genome;if(this.featureCache)return this.featureCache.queryFeatures(t,e,n);{const r=gs(this.config),i=await go.loadString(this.config.url,r);return this.featureCache=new Mo(function(t){if(!t)return null;const e=Fh(t);let n,r=!0;const i=[],o=[],s=[];for(;void 0!==(n=e.nextLine());){const t=n.split("\t");if(r&&n.startsWith("color:")){const e="rgb("+t[1]+","+t[2]+","+t[3]+")";i.push(e),t.length>4&&o.push(t[4])}else{r=!1;const e=t[0],n=Number.parseInt(t[1])-1,c=Number.parseInt(t[2])-1,l=Number.parseInt(t[3]),h=Number.parseInt(t[4]);var a=Number.parseInt(t[5]);const u=i[a];let f;f=n<=h?{chr:e,startLeft:Math.min(n,c),startRight:Math.max(n,c),endLeft:Math.min(l,h),endRight:Math.max(l,h),color:u,score:a}:{chr:e,startLeft:Math.min(l,h),startRight:Math.max(l,h),endLeft:Math.min(n,c),endRight:Math.max(n,c),color:u,score:a},f.start=f.startLeft,f.end=f.endRight,o.length>a&&(f.description=o[a]),s.push(f)}}return s}(i),o),this.featureCache.queryFeatures(t,e,n)}}}class uf{constructor(t){this.browser=t,this.type="ideogram",this.height=16,this.order=Number.MIN_SAFE_INTEGER,this.disableButtons=!0,this.ignoreTrackMenu=!0}async getFeatures(t,e,n){return[]}computePixelHeight(t){return this.height}draw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r}){const i=e.chr,o=e.genome.getChromosome(i);if(void 0===o||n<=0||r<=0||"all"===i.toLowerCase())return;!function({ctx:t,chr:e,referenceFrame:n,genome:r,width:i,height:o,stainColors:s}){const a=1,c=.5*a,l=0;if(void 0===r)return;ls.fillRect(t,0,0,i,o,{fillStyle:no.greyScale(255)});const h=r.getCytobands(e);if(h){const e=l+o/2,n=[],r=[];if(0===h.length)return;const u=i/h[h.length-1].end;t.beginPath(),ls.roundRect(t,c,c+l,i-2*c,o-2*c,(o-2*c)/2,0,1),t.clip();for(let i=0;i<h.length;i++){const c=h[i],f=u*c.start,d=u*c.end;"c"===c.type?("p"===c.name.charAt(0)?(n[0]=f,r[0]=o+l,n[1]=f,r[1]=l,n[2]=d,r[2]=e):(n[0]=d,r[0]=o+l,n[1]=d,r[1]=l,n[2]=f,r[2]=e),t.fillStyle="rgb(150, 0, 0)",t.strokeStyle="rgb(150, 0, 0)",ls.polygon(t,n,r,1,0)):(t.fillStyle=ff(s,c),ls.fillRect(t,f,a+l,d-f,o-2*a))}}t.strokeStyle=no.greyScale(41),ls.roundRect(t,c,c+l,i-2*c,o-2*c,(o-2*c)/2,0,1)}({ctx:t,chr:i,referenceFrame:e,genome:e.genome,width:n,height:r,stainColors:[]});const s=Math.round(e.bpPerPixel*n),a=e.start;let c=o.bpLength;const l=e.genome.getCytobands(i);if(l&&l.length>0&&l[l.length-1].end&&(c=Math.max(c,l[l.length-1].end),o.bpLength=c),s<c){const e=s/c,i=a/c;let o=Math.floor(i*n),l=Math.floor(e*n);o=Math.max(0,o),o=Math.min(n-l,o),t.save(),t.strokeStyle="red",t.lineWidth=l<2?1:2;const h=o+t.lineWidth/2;l=l<2?1:l-t.lineWidth;const u=t.lineWidth/2,f=r-t.lineWidth;t.strokeRect(h,u,l,f),t.restore()}}dispose(){this.trackView=void 0}}function ff(t,e){if("c"===e.type)return"rgb(150, 10, 10)";var n=e.stain,r=230;"p"===e.type&&(r=Math.floor(230-n/100*230));var i=t[r];return i||(i="rgb("+r+","+r+","+r+")",t[r]=i),i}let df=new _c("Dark2");["GT/AG","CT/AC","GC/AG","CT/GC","AT/AC","GT/AT","non-canonical"].forEach((t=>{df.getColor(t)}));const pf={};class gf extends bc{constructor(t,e){super(t,e)}init(t){super.init(t),this.type=t.type||"junctions",t._featureSource?(this.featureSource=t._featureSource,delete t._featureSource):this.featureSource=t.featureSource?t.featureSource:Cu(t,this.browser.genome),this.margin=void 0===t.margin?10:t.margin,this.height||(this.height=100),void 0===t.colorByNumReadsThreshold&&(t.colorByNumReadsThreshold=5)}async postInit(){return"function"==typeof this.featureSource.getHeader&&(this.header=await this.featureSource.getHeader()),this.header&&this.setTrackProperties(this.header),void 0===this.visibilityWindow&&"function"==typeof this.featureSource.defaultVisibilityWindow&&(this.visibilityWindow=await this.featureSource.defaultVisibilityWindow()),this}get supportsWholeGenome(){return!1}async getFeatures(t,e,n,r){const i=this.visibilityWindow;return this.featureSource.getFeatures({chr:t,start:e,end:n,bpPerPixel:r,visibilityWindow:i})}computePixelHeight(t){return this.height}draw(t){const e=t.features,n=t.context,r=t.bpPerPixel,i=t.bpStart,o=t.pixelWidth,s=t.pixelHeight,a=i+o*r+1;if(this.config.isMergedTrack||ls.fillRect(n,0,t.pixelTop,o,s,{fillStyle:"rgb(255, 255, 255)"}),e){pf.referenceFrame=t.viewport.referenceFrame,pf.referenceFrameStart=pf.referenceFrame.start,pf.referenceFrameEnd=pf.referenceFrameStart+pf.referenceFrame.toBP(de(t.viewport.contentDiv).width()),pf.featureZoomOutTracker={};for(let t of e)if(!(t.end<i)){if(t.start>a)break;this.renderJunction(t,i,r,s,n)}}else console.log("No feature list")}renderJunction(t,e,n,r,i){t.isVisible=!1;const o=Math.round((t.start-e)/n),s=Math.round((t.end-e)/n),a=(o+s)/2;if(s-o<=3){if(a in pf.featureZoomOutTracker)return;pf.featureZoomOutTracker[a]=!0}if(this.config.hideAnnotatedJunctions&&"true"===t.attributes.annotated_junction)return;if(this.config.hideUnannotatedJunctions&&"false"===t.attributes.annotated_junction)return;if(this.config.hideMotifs&&this.config.hideMotifs.includes(t.attributes.motif))return;if(this.config.hideStrand===t.strand)return;if(this.config.minJunctionEndsVisible){let e=0;if(t.start>=pf.referenceFrameStart&&t.start<=pf.referenceFrameEnd&&(e+=1),t.end>=pf.referenceFrameStart&&t.end<=pf.referenceFrameEnd&&(e+=1),e<this.config.minJunctionEndsVisible)return}let c,l,h,u;if(t.attributes.uniquely_mapped){if(c=parseInt(t.attributes.uniquely_mapped),c<this.config.minUniquelyMappedReads)return;if(l=parseInt(t.attributes.multi_mapped),h=c+l,h<this.config.minTotalReads)return;if(h>0&&l/h>this.config.maxFractionMultiMappedReads)return;if(t.attributes.maximum_spliced_alignment_overhang&&parseInt(t.attributes.maximum_spliced_alignment_overhang)<this.config.minSplicedAlignmentOverhang)return}if(t.attributes.num_samples_with_this_junction){if(u=parseInt(t.attributes.num_samples_with_this_junction),this.config.minSamplesWithThisJunction&&u<this.config.minSamplesWithThisJunction)return;if(this.config.maxSamplesWithThisJunction&&u>this.config.maxSamplesWithThisJunction)return;if(t.attributes.num_samples_total&&(t.attributes.percent_samples_with_this_junction=100*u/Number(t.attributes.num_samples_total),this.config.minPercentSamplesWithThisJunction&&(t.attributes.percent_samples_with_this_junction<this.config.minPercentSamplesWithThisJunction||t.attributes.percent_samples_with_this_junction>this.config.maxPercentSamplesWithThisJunction)))return}const f=this.margin,d=this.height,p=f+.5*d;let g=f;const m=f+d-10,v=(o+a)/2,b=(a+s)/2;let w,y,x=1;t.attributes.line_width?x=Number(t.attributes.line_width):(void 0===this.config.thicknessBasedOn||"numUniqueReads"===this.config.thicknessBasedOn?x=c:"numReads"===this.config.thicknessBasedOn?x=h:"numSamplesWithThisJunction"===this.config.thicknessBasedOn&&void 0!==u&&(x=u),x=1+Math.log(x+1)/Math.log(12)),void 0===this.config.bounceHeightBasedOn||"random"===this.config.bounceHeightBasedOn?w=(t.start+t.end)%7:"distance"===this.config.bounceHeightBasedOn?w=6*(t.end-t.start)/(pf.referenceFrameEnd-pf.referenceFrameStart):"thickness"===this.config.bounceHeightBasedOn&&(w=2*x),g+=d*Math.max(7-w,0)/10,y=t.attributes.color?t.attributes.color:void 0===this.config.colorBy||"numUniqueReads"===this.config.colorBy?c>this.config.colorByNumReadsThreshold?"blue":"#AAAAAA":"numReads"===this.config.colorBy?h>this.config.colorByNumReadsThreshold?"blue":"#AAAAAA":"isAnnotatedJunction"===this.config.colorBy?"true"===t.attributes.annotated_junction?"#b0b0ec":"orange":"strand"===this.config.colorBy?"+"===t.strand?"#b0b0ec":"#ecb0b0":"motif"===this.config.colorBy?df.getColor(t.attributes.motif):"#AAAAAA";let k="";t.attributes.label?k=t.attributes.label.replace(/_/g," "):void 0===this.config.labelWith||"uniqueReadCount"===this.config.labelWith?k=c:"totalReadCount"===this.config.labelWith?k=h:"numSamplesWithThisJunction"===this.config.labelWith?void 0!==u&&(k=u):"percentSamplesWithThisJunction"===this.config.labelWith?void 0!==t.attributes.percent_samples_with_this_junction&&(k=t.attributes.percent_samples_with_this_junction.toFixed(0)+"%"):"motif"===this.config.labelWith&&void 0!==t.attributes.motif&&(k+=t.attributes.motif),"uniqueReadCount"===this.config.labelWithInParen?k+=" ("+c+")":"totalReadCount"===this.config.labelWithInParen?k+=" ("+h+")":"multiMappedReadCount"===this.config.labelWithInParen?l>0&&(k+=" (+"+l+")"):"numSamplesWithThisJunction"===this.config.labelWithInParen?void 0!==u&&(k+=" ("+u+")"):"percentSamplesWithThisJunction"===this.config.labelWithInParen?void 0!==t.attributes.percent_samples_with_this_junction&&(k+=" ("+t.attributes.percent_samples_with_this_junction.toFixed(0)+"%)"):"motif"===this.config.labelWithInParen&&void 0!==t.attributes.motif&&(k+=` ${t.attributes.motif}`),t.isVisible=!0,i.beginPath(),i.moveTo(o,m),i.bezierCurveTo(v,g,b,g,s,m),i.lineWidth=x,i.strokeStyle=y,i.stroke();const _=(t,e,n,r)=>{t.beginPath(),t.moveTo(e,n),t.lineTo(e-r/2,n-r),t.lineTo(e+r/2,n-r),t.lineTo(e,n),t.closePath(),t.fill()};if(t.attributes.left_shape||t.attributes.right_shape){i.fillStyle=y;const e=i.lineWidth>2?10:7;t.attributes.left_shape&&_(i,o,m,e),t.attributes.right_shape&&_(i,s,m,e)}i.fillText(k,a-i.measureText(k).width/2,(7*g+p)/8)}clickedFeatures(t,e){return super.clickedFeatures(t,e).filter((function(t){return t.isVisible&&t.attributes}))}popupData(t,e){e=this.clickedFeatures(t,e);const n=t.genomicLocation,r=[];for(let t of e){const e="function"==typeof t.popupData?t.popupData(n):this.extractPopupData(t._f||t,this.getGenomeId());e&&(r.length>0&&r.push("<hr/><hr/>"),Array.prototype.push.apply(r,e))}return r}dispose(){this.trackView=void 0}}const mf=new Map([["ideogram",(t,e)=>new uf(t,e)],["sequence",(t,e)=>new Ns(t,e)],["feature",(t,e)=>new Du(t,e)],["seg",(t,e)=>new ju(t,e)],["mut",(t,e)=>new ju(t,e)],["maf",(t,e)=>new ju(t,e)],["wig",(t,e)=>new Bu(t,e)],["merged",(t,e)=>new qu(t,e)],["alignment",(t,e)=>new rl(t,e)],["interaction",(t,e)=>new Wu(t,e)],["interact",(t,e)=>new Wu(t,e)],["variant",(t,e)=>new tf(t,e)],["eqtl",(t,e)=>new nf(t,e)],["gwas",(t,e)=>new of(t,e)],["arc",(t,e)=>new cf(t,e)],["gcnv",(t,e)=>new sf(t,e)],["junction",(t,e)=>new gf(t,e)]]);var vf=function(t,e){mf.set(t,e)},bf=function(t,e,n){let r;switch(t){case"annotation":case"genes":case"fusionjuncspan":case"snp":r="feature";break;case"seg":case"maf":case"mut":r="seg";break;case"junctions":case"splicejunctions":r="junction";break;default:r=t}return mf.has(r)?mf.get(r)(e,n):void 0};class wf{constructor(t,e){this.config=t,this.name=t.name,this.roiSource=Cu(t,e),this.color=t.color||"rgba(68, 134, 247, 0.25)"}async getFeatures(t,e,n){return this.roiSource.getFeatures({chr:t,start:e,end:n})}draw(t){var e,n,r,i;if(i=t.features){e=t.bpStart+(t.pixelWidth*t.bpPerPixel+1);for(var o=0,s=i.length;o<s;o++)if(!((n=i[o]).end<t.bpStart)){if(n.start>e)break;r=yf(n,t.bpStart,t.bpPerPixel),ls.fillRect(t.context,r.x,t.pixelTop,r.width,t.pixelHeight,{fillStyle:this.color})}}}}function yf(t,e,n){var r,i;return r=Math.round((t.start-e)/n),(i=Math.round((t.end-e)/n)-r)<3&&(i=3,r-=1),{x:r,width:i}}class xf{constructor(t,e){const n=(new DOMParser).parseFromString(t,"text/xml");this.processRootNode(n,e);const r=n.getElementsByTagName("Resource"),i=n.getElementsByTagName("Track"),o=i&&i.length>0,s=[];this.tracks=s;const a=new Map;Array.from(r).forEach((function(t,e){var n={url:t.getAttribute("path"),indexURL:t.getAttribute("index"),order:e};a.set(n.url,n),o||s.push(n)})),o&&Array.from(i).forEach((function(t){const e=t.getElementsByTagName("Track");if(e&&e.length>0){const n={type:"merged",tracks:[]};kf(t,n),s.push(n),Array.from(e).forEach((function(t){t.processed=!0;const e=t.getAttribute("id"),r=a.get(e);r&&(n.tracks.push(r),kf(t,r),r.autoscale=!1,n.height=r.height)}))}else if(!t.processed){const e=t.getAttribute("id"),n=a.get(e);n&&(s.push(n),kf(t,n))}}))}processRootNode(t,e){const n=t.getElementsByTagName("Session");!n||n.length;const r=n.item(0),i=r.getAttribute("genome"),o=r.getAttribute("locus"),s=r.getAttribute("ucscID");e&&e.hasOwnProperty(i)?this.genome=i:(this.reference={fastaURL:i},s&&(this.reference.id=s)),o&&(this.locus=o)}}function kf(t,e){e.name=t.getAttribute("name");const n=t.getAttribute("color");n&&(e.color="rgb("+n+")");const r=t.getAttribute("altColor");n&&(e.altColor="rgb("+r+")");const i=t.getAttribute("height");i&&(e.height=parseInt(i));const o=t.getAttribute("autoScale");o&&(e.autoscale="true"===o);const s=t.getAttribute("autoscaleGroup");s&&(e.autoscaleGroup=s);const a=t.getAttribute("windowFunction");a&&(e.windowFunction=a);const c=t.getAttribute("visibilityWindow")||t.getAttribute("featureVisibilityWindow");c&&(e.visibilityWindow=c);const l=t.getAttribute("indexed");l&&(e.indexed="true"===l);const h=t.getAttribute("normalize");h&&(e.normalize="true"===h);const u=t.getElementsByTagName("DataRange");if(u.length>0){const t=u.item(0);e.min=Number(t.getAttribute("minimum")),e.max=Number(t.getAttribute("maximum")),e.logScale="LOG"===t.getAttribute("type")}}const _f=Se;class Sf{constructor(){this.attributes={},this.plinkLoaded=!1}async loadPlinkFile(t,e){e||(e={});var n=gs(e);const r=await go.loadString(t,n);var i=_f(r);for(let t of i){var o=t.split(" ");this.attributes[o[1]]={familyId:o[0],fatherId:o[2],motherId:o[3],sex:o[4],phenotype:o[5]}}return this.plinkLoaded=!0,this}getAttributes(t){return this.attributes[t]}getAttributeNames(){return this.hasAttributes()?Object.keys(this.attributes[Object.keys(this.attributes)[0]]):[]}hasAttributes(){return Object.keys(this.attributes).length>0}}class Cf{constructor(t,e){this.geneColors={},this.gene=null,this.snp=null,this.genesCount=0,t&&(this.gene=t.toUpperCase(),this.geneColors[this.gene]=Ef[this.genesCount++]),e&&(this.snp=e.toUpperCase())}addGene(t){this.geneColors[t.toUpperCase()]||(this.geneColors[t.toUpperCase()]=Ef[this.genesCount++])}colorForGene(t){return this.geneColors[t.toUpperCase()]}}var Ef=[];Ef.push("rgb(228,26,28)"),Ef.push("rgb(55,126,184)"),Ef.push("rgb(77,175,74)"),Ef.push("rgb(166,86,40)"),Ef.push("rgb(152,78,163)"),Ef.push("rgb(255,127,0)"),Ef.push("rgb(247,129,191)"),Ef.push("rgb(153,153,153)"),Ef.push("rgb(255,255,51)"),Ef.push("rgb(102, 194, 165"),Ef.push("rgb(252, 141, 98"),Ef.push("rgb(141, 160, 203"),Ef.push("rgb(231, 138, 195"),Ef.push("rgb(166, 216, 84"),Ef.push("rgb(255, 217, 47"),Ef.push("rgb(229, 196, 148"),Ef.push("rgb(179, 179, 179"),Ef.push("rgb( 141, 211, 199"),Ef.push("rgb(255, 255, 179"),Ef.push("rgb(190, 186, 218"),Ef.push("rgb(251, 128, 114"),Ef.push("rgb(128, 177, 211"),Ef.push("rgb(253, 180, 98"),Ef.push("rgb(179, 222, 105"),Ef.push("rgb(252, 205, 229"),Ef.push("rgb(217, 217, 217"),Ef.push("rgb(188, 128, 189"),Ef.push("rgb(204, 235, 197"),Ef.push("rgb(255, 237, 111");class Af{constructor(t,e,n,r,i){this.genome=t,this.chr=e,this.start=n,this.end=r,this.bpPerPixel=i,this.id=ve()}extend(t){const e=Math.min(t.start,this.start),n=Math.max(t.end,this.end),r=(n-e)/(this.end-this.start);this.start=e,this.end=n,this.bpPerPixel*=r}calculateEnd(t){return this.start+this.bpPerPixel*t}calculateBPP(t,e){return(t-this.start)/e}set(t){this.chr=t.chr,this.start=t.start,this.bpPerPixel=t.bpPerPixel}toPixels(t){return t/this.bpPerPixel}toBP(t){return this.bpPerPixel*t}shiftPixels(t,e){const n=this.start,r=t*this.bpPerPixel;this.start+=r,this.clampStart(e),this.end+=r;const{bpLength:i}=this.genome.getChromosome(this.chr);return this.end=Math.min(i,this.end),n!==this.start}clampStart(t){const e=this.genome.getChromosome(this.chr).bpStart||0;if(this.start=Math.max(e,this.start),t){const{bpLength:e}=this.genome.getChromosome(this.chr),n=e-t*this.bpPerPixel;this.start>n&&(this.start=n)}}async zoomWithScaleFactor(t,e,n,r){const i=void 0===r?this.start+this.toBP(n/2):r,{start:o,bpPerPixel:s}=this.start,{bpLength:a}=this.getChromosome(),c=e<1?t.minimumBases()/n:a/n;this.bpPerPixel=e<1?Math.max(this.bpPerPixel*e,c):Math.min(this.bpPerPixel*e,c);const l=this.bpPerPixel*n;this.start=i-.5*l,this.clampStart(n),this.end=this.start+l;(o!==this.start||s!==this.bpPerPixel)&&await t.updateViews(!0)}getChromosome(){return this.genome.getChromosome(this.chr)}getMultiLocusLabel(t){const e=Math.floor(this.start)+1,n=Math.round(this.start+this.bpPerPixel*t);return`&nbsp${this.chr}&nbsp &nbsp &nbsp${ws(n-e)}&nbsp`}getPresentationLocusComponents(t){if("all"===this.chr)return{chr:this.chr};{const e=_e(Math.floor(this.start)+1),n=_e(Math.round(this.start+this.bpPerPixel*t));return{chr:this.chr,start:e,end:n}}}getLocusString(){if("all"===this.chr)return"all";{const t=_e(Math.floor(this.start)+1),e=_e(Math.round(this.end));return`${this.chr}:${t}-${e}`}}description(t){console.log(` ${t||""} referenceFrame - ${this.chr} bpp ${this.bpPerPixel.toFixed(3)} start ${_e(Math.round(this.start))} end ${_e(Math.round(this.end))} `)}}const Tf={A:"rgb( 0, 200, 0)",C:"rgb( 0,0,200)",T:"rgb(255,0,0)",G:"rgb(209,113, 5)",N:"rgb(80,80,80)"},Lf={timeout:5e3,type:"plain",url:"https://igv.org/genomes/locus.php?genome=$GENOME$&name=$FEATURE$",coords:0,chromosomeField:"chromosome",startField:"start",endField:"end",geneField:"gene",snpField:"snp"};async function Mf(t,e){if(void 0===e||""===e.trim())return;(e&&"all"===e.trim().toLowerCase()||"*"===e)&&(e="all");const n=e.split(" ");let r=t.searchConfig||Lf,i=[];const o=async n=>{let i=function(t,e){const n=e.split(":"),r=n[0];if("all"===r&&t.genome.getChromosome(r))return{chr:r,start:0,end:t.genome.getChromosome(r).bpLength};if(void 0===t.genome.getChromosome(r))return;{const e={chr:t.genome.getChromosomeName(r),start:0,end:t.genome.getChromosome(r).bpLength};if(n.length>1){const t=n[1].split("-");if(t.length>2)return;{let n;if(n=t[0].replace(/,/g,""),isNaN(n))return;if(e.start=parseInt(n,10)-1,e.end=e.start+1,1===t.length&&(e.start-=20,e.end+=20),2===t.length){if(n=t[1].replace(/,/g,""),isNaN(n))return;e.end=parseInt(n,10)}}}return e}}(t,n);if(!i){const r=t.genome.featureDB[n.toUpperCase()];r&&(i={chr:r.chr,start:r.start,end:r.end,gene:r.name,locusSearchString:e})}if(!i&&t.config&&!1!==t.config.search)try{i=await async function(t,e,n){let r=n.url.replace("$FEATURE$",e.toUpperCase());r.indexOf("$GENOME$")>-1&&(r=r.replace("$GENOME$",t.genome.id?t.genome.id:"hg19"));const i=n.timeout?{timeout:n.timeout}:void 0,o=await go.loadString(r,i),s=function(t,e,n){let r;r="plain"===n.type?function(t,e){const n=[],r=[];return Se(e).forEach((function(t){""===t||n.push(t)})),n.forEach((function(e){var n,i,o,s,a=e.split("\t");a.length>=3&&(o=(i=a[1].split(":"))[1].split("-"),n=a[2].trim(),s={gene:a[0],chromosome:t.genome.getChromosomeName(i[0].trim()),start:parseInt(o[0].replace(/,/g,"")),end:parseInt(o[1].replace(/,/g,"")),type:"gtex"===n?"snp":"gene"},r.push(s))})),r}(t,e):JSON.parse(e);n.resultsField&&(r=r[n.resultsField]);if(r&&0!==r.length){const e=n.chromosomeField||"chromosome",i=n.startField||"start",o=n.endField||"end",s=n.coords||1;let a;a=Array.isArray(r)?r[0]:r,a.hasOwnProperty(e)&&a.hasOwnProperty(i)||console.error("Search service results must include chromosome and start fields: "+a);const c=a[e],l=t.genome.getChromosome(c);if(!l)return;const h=l.name;let u=a[i]-s,f=a[o];void 0===f&&(f=u+1);const d={chr:h,start:u,end:f},p=a.type?a.type:"gene";return n.geneField&&"gene"===p&&(d.gene=a[n.geneField]),n.snpField&&"snp"===p&&(d.snp=a[n.snpField]),d}return}(t,o,n);s&&(s.locusSearchString=e);return s}(t,n,r)}catch(t){throw console.error(t),Error("Search service currently unavailable.")}return i};for(let t of n){const e=await o(t);e&&(e.locusSearchString=t,i.push(e))}if(0===i.length){const t=await o(e);t&&(t.locusSearchString=e,i.push(t))}return 0===i.length?void 0:i}class Rf{constructor(t){this.browser=t}navbarDidResize(t,e){this.updateNavbar(this.createResponsiveClassSchedule(t,e))}updateNavbar(t){this.browser.$toggle_button_container.removeClass(),this.browser.$toggle_button_container.addClass(t.$toggle_button_container),de(this.browser.zoomWidget.zoomContainer).removeClass(),de(this.browser.zoomWidget.zoomContainer).addClass(t.zoomContainer)}createResponsiveClassSchedule(t,e){let n={};return e?this.browser.windowSizePanel.hide():this.browser.windowSizePanel.show(),t>990?(n.$toggle_button_container="igv-navbar-toggle-button-container",n.zoomContainer="igv-zoom-widget"):t>860?(n.$toggle_button_container="igv-navbar-toggle-button-container",n.zoomContainer="igv-zoom-widget-900"):t>540?(n.$toggle_button_container="igv-navbar-toggle-button-container-750",n.zoomContainer="igv-zoom-widget-900"):(n.$toggle_button_container="igv-navbar-toggle-button-container-750",n.zoomContainer="igv-zoom-widget-900",this.browser.windowSizePanel.hide()),e&&(n.zoomContainer="igv-zoom-widget-hidden"),n}}const If=function(t,e){this.container=pe({class:"igv-chromosome-select-widget-container"}),e.appendChild(this.container),this.select=document.createElement("select"),this.select.setAttribute("name","chromosome-select-widget"),this.container.appendChild(this.select),this.select.addEventListener("change",(()=>{this.select.blur(),""!==this.select.value&&t.search(this.select.value)})),this.showAllChromosomes=!1!==t.config.showAllChromosomes};If.prototype.show=function(){this.container.style.display="flex"},If.prototype.hide=function(){this.container.style.display="none"},If.prototype.update=function(t){const e=this.showAllChromosomes?t.chromosomeNames.slice():t.wgChromosomeNames.slice();t.showWholeGenomeView()&&(e.unshift("all"),e.unshift("")),this.select.innerHTML="";for(let t of e){const e=document.createElement("option");e.setAttribute("value",t),e.innerText=t,this.select.appendChild(e)}};class Nf{constructor(t,e){this.container=pe({class:"igv-windowsize-panel-container"}),t.appendChild(this.container),e.on("locuschange",(t=>{this.updatePanel(t)})),this.browser=e}show(){this.container.style.display="block"}hide(){this.container.style.display="none"}updatePanel(t){const e=this.browser.calculateViewportWidth(this.browser.referenceFrameList.length);this.container.innerText=1===t.length?ws(Math.round(e*t[0].bpPerPixel)):""}}class Pf{constructor(t,e){this.browser=e,this.columnContainer=t,this.horizontalGuide=pe({class:"igv-cursor-guide-horizontal"}),t.appendChild(this.horizontalGuide),this.verticalGuide=pe({class:"igv-cursor-guide-vertical"}),t.appendChild(this.verticalGuide),this.addMouseHandler(e),this.setVisibility(e.config.showCursorGuide)}addMouseHandler(t){this.boundMouseMoveHandler=function(e){const{x:n,y:r}=be(e,this.columnContainer);this.horizontalGuide.style.top=`${r}px`;const i=document.elementFromPoint(e.clientX,e.clientY);let o;if(i.parentElement&&(i.parentElement.classList.contains("igv-viewport-content")?o=i.parentElement.parentElement:i.parentElement.classList.contains("igv-viewport")&&i.classList.contains("igv-viewport-content")&&(o=i.parentElement),o&&t.getRulerTrackView())){this.verticalGuide.style.left=`${n}px`;const r=t.root.querySelectorAll(".igv-column");let i;const s=o.parentElement;for(let t=0;t<r.length;t++)void 0===i&&s===r[t]&&(i=t);const a=t.getRulerTrackView().viewports[i].mouseMove(e);if(a){const{start:t,bp:e,end:n}=a,r=(e-t)/(n-t);this.customMouseHandler&&this.customMouseHandler({start:t,bp:e,end:n,interpolant:r})}}}.bind(this),this.columnContainer.addEventListener("mousemove",this.boundMouseMoveHandler)}removeMouseHandler(){this.columnContainer.removeEventListener("mousemove",this.boundMouseMoveHandler)}setVisibility(t){!0===t?this.show():this.hide()}show(){this.verticalGuide.style.display="block",this.horizontalGuide.style.display="block"}hide(){if(this.verticalGuide.style.display="none",this.horizontalGuide.style.display="none",this.browser.getRulerTrackView())for(let t of this.browser.getRulerTrackView().viewports)t.$tooltip.hide()}}class Of{constructor(t,e){this.browser=t,this.button=pe({class:"igv-navbar-button"}),e.appendChild(this.button),this.button.textContent="cursor guide",this.button.addEventListener("click",(()=>{t.cursorGuideVisible=!t.cursorGuideVisible,t.setCursorGuideVisibility(t.cursorGuideVisible),this.setButtonState(t.cursorGuideVisible)})),this.setButtonState(t.cursorGuideVisible),t.config.showCursorTrackingGuideButton?this.show():this.hide()}setButtonState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.button.style.display="block",this.setButtonState(this.browser.cursorGuideVisible)}hide(){this.button.style.display="none"}}class Ff{constructor(t,e){this.browser=t,this.button=pe({class:"igv-navbar-button"}),e.appendChild(this.button),this.button.textContent="center line",this.button.addEventListener("click",(()=>{t.isCenterLineVisible=!t.isCenterLineVisible,t.setCenterLineVisibility(t.isCenterLineVisible),this.setButtonState(t.isCenterLineVisible)})),this.setButtonState(t.isCenterLineVisible),t.config.showCenterGuideButton?this.show():this.hide()}setButtonState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.isVisible=!0,this.button.style.display="block",this.setButtonState(this.browser.isCenterLineVisible)}hide(){this.isVisible=!1,this.button.style.display="none"}}class Df{constructor(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.textContent="track labels",this.button.addEventListener("click",(()=>{e.trackLabelsVisible=!e.trackLabelsVisible,this.setState(e.trackLabelsVisible),e.setTrackLabelVisibility(e.trackLabelsVisible)})),this.browser=e,this.setVisibility(e.config.showTrackLabelButton),this.setState(e.trackLabelsVisible)}setVisibility(t){!0===t?this.show():this.hide()}setState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}show(){this.button.style.display="block",this.setState(this.browser.trackLabelsVisible)}hide(){this.button.style.display="none"}}class Bf{constructor(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.innerText="Sample Names",this.setState(e.showSampleNames),this.setVisibility(e.showSampleNameButton),this.button.addEventListener("click",(()=>{e.showSampleNames=!e.showSampleNames,this.setState(e.showSampleNames);for(let{sampleNameViewport:t}of e.trackViews)!1===e.showSampleNames?t.hide():t.show();e.layoutChange()}))}setVisibility(t){!0===t?this.show():this.hide()}setState(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")}hide(){this.button.style.display="none"}show(){this.button.style.display="block"}}let zf=23,Hf=0;const Vf=function(t,e){this.browser=t,this.zoomContainer=pe({class:"igv-zoom-widget"}),e.appendChild(this.zoomContainer),this.zoomOutButton=pe(),this.zoomContainer.appendChild(this.zoomOutButton),this.zoomOutButton.appendChild(we("minus-circle")),this.zoomOutButton.addEventListener("click",(()=>{t.zoomOut()}));const n=pe();this.zoomContainer.appendChild(n),this.slider=document.createElement("input"),this.slider.type="range",this.slider.min="0",this.slider.max=`${zf}`,n.appendChild(this.slider),this.slider.addEventListener("change",(e=>{e.preventDefault(),e.stopPropagation();const n=t.referenceFrameList[0],{bpLength:r}=n.genome.getChromosome(n.chr),{end:i,start:o}=n,s=i-o,a=r/Math.pow(2,e.target.valueAsNumber);t.zoomWithScaleFactor(a/s)})),this.zoomInButton=pe(),this.zoomContainer.appendChild(this.zoomInButton),this.zoomInButton.appendChild(we("plus-circle")),this.zoomInButton.addEventListener("click",(()=>{t.zoomIn()})),t.on("locuschange",(t=>{this.browser.isMultiLocusMode()?this.disable():(this.enable(),this.update(t))}))};Vf.prototype.update=function(t){const e=t[0],{bpLength:n}=e.genome.getChromosome(e.chr),{start:r,end:i}=e;zf=Math.ceil(Math.log2(n/this.browser.minimumBases())),this.slider.max=`${zf}`;const o=n/(i-r);Hf=Math.log2(o),this.slider.value=`${Math.round(Hf)}`},Vf.prototype.enable=function(){this.slider.disabled=!1},Vf.prototype.disable=function(){this.slider.disabled=!0},Vf.prototype.hide=function(){this.zoomContainer.style.display="none"},Vf.prototype.show=function(){this.zoomContainer.style.display="block"},Vf.prototype.hideSlider=function(){this.slider.style.display="none"},Vf.prototype.showSlider=function(){this.slider.style.display="block"};const jf=function(t,e){const n=pe({class:"igv-navbar-button"});t.append(n),n.textContent="Save SVG",n.addEventListener("click",(()=>e.saveSVGtoFile({})))},Uf=(t,e)=>{const n=0===t?e.nextElementSibling:e.previousElementSibling;e.remove(),n.remove()},qf=t=>{const e=pe({class:"igv-column-shim"});_s(e,t);const n=pe({class:"igv-column"});return _s(n,e),n},Wf=(t,e)=>{for(let n=0;n<e;n++){const r=pe({class:"igv-column"});if(ks(r,t),e>1&&n>0){ks(pe({class:"igv-column-shim"}),r)}}};class $f{constructor(t,e,n){this.browser=t,this.referenceFrame=e,this.column=n,this.container=pe({class:"igv-center-line"}),n.appendChild(this.container),t.isCenterLineVisible?this.show():this.hide()}repaint(){const t=Math.floor(this.browser.calculateViewportWidth(this.browser.referenceFrameList.length)/2);if(this.referenceFrame){1/this.referenceFrame.bpPerPixel>1?(this.container.style.left=`${t}px`,this.container.style.width=`${Math.floor(this.referenceFrame.toPixels(1))}px`,this.container.classList.remove("igv-center-line-thin"),this.container.classList.add("igv-center-line-wide")):(this.container.style.left=`${t}px`,this.container.style.width="1px",this.container.classList.remove("igv-center-line-wide"),this.container.classList.add("igv-center-line-thin"))}}show(){this.isVisible=!0,this.container.style.display="block",this.repaint()}hide(){this.isVisible=!1,this.container.style.display="none"}resize(){this.repaint()}}const Gf=_e;class Zf{constructor(t){this.browser=t,this.height=40,this.name="",this.id="ruler",this.disableButtons=!0,this.ignoreTrackMenu=!0,this.order=.01*Number.MIN_SAFE_INTEGER,this.removable=!1,this.type="ruler"}async getFeatures(t,e,n){return[]}computePixelHeight(t){return this.height}draw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpPerPixel:i,bpStart:o}){na.isWholeGenomeView(e.chr)?this.drawWholeGenome({context:t,pixelWidth:n,pixelHeight:r,bpPerPixel:i}):this.doDraw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpStart:o})}drawWholeGenome({context:t,pixelWidth:e,pixelHeight:n,bpPerPixel:r}){t.save(),ls.fillRect(t,0,0,e,n,{fillStyle:"white"});for(let e of this.browser.genome.wgChromosomeNames){let i=this.browser.genome.getCumulativeOffset(e),o=this.browser.genome.getChromosome(e).bpLength,s=Math.round(i/r),a=Math.round(o/r);this.renderChromosomeRect(t,s,0,a,n,e)}t.restore()}doDraw({context:t,referenceFrame:e,pixelWidth:n,pixelHeight:r,bpStart:i}){t.clearRect(0,0,n,r);const o=function(t,e){if(t<10)return new Xf(1,"bp",1);const n=Math.floor(Math.log10(t));let r="bp",i=1;n>9?(r="gb",i=1e9):n>6?(r="mb",i=1e6):n>3&&(r="kb",i=1e3);const o=Math.pow(10,n-1),s=t/o,a=75,c=Math.pow(10,n-1),l=Math.pow(10,n)/2;return new Xf(s<a&&!0!==e?c:l,r,i)}(Math.floor(e.toBP(n)),t.isSVG);let s=Math.floor(i/o.majorTick)-1;const{tickDelta:a,labelLength:c}=function(t,e,n,r,i){const o=l(e,c(1+r,i),n)-l(e,c(r,i),n),s=`${_e(Math.floor(c(r,i)/i.unitMultiplier))} ${i.majorUnit}`,a=Math.floor(t.measureText(s).width);return{tickDelta:o,labelLength:a};function c(t,e){return Math.floor(t*e.majorTick)}function l(t,e,n){return Math.round(t.toPixels(e-1-n+.5))}}(t,e,i,s,o);let l,h;this.browser.referenceFrameList.indexOf(e);let u=a;const f=.25*c;do{h=Math.floor(s*o.majorTick);const n=`${_e(Math.floor(h/o.unitMultiplier))} ${o.majorUnit}`;l=Math.round(e.toPixels(h-1-i+.5));const r=Math.round(l-t.measureText(n).width/2);r>0&&f+c<=u&&(ls.fillText(t,n,r,this.height-8),u=0),l>0&&ls.strokeLine(t,l,this.height-6,l,this.height-2),h=Math.floor((1+s)*o.majorTick);let d=l+(Math.round(e.toPixels(h-1-i+.5))-l)/2;d>0&&ls.strokeLine(t,d,this.height-6,d,this.height-2),++s,u+=a}while(l<n);ls.strokeLine(t,0,this.height-2,n,this.height-2)}renderChromosomeRect(t,e,n,r,i,o){t.textAlign="center",t.textBaseline="middle",t.font="12px sans-serif",ls.strokeLine(t,e+r,n,e+r,n+i,{strokeStyle:no.greyScale(191)});const s=o.startsWith("chr")?o.substring(3):o;r>t.measureText(s).width&&ls.fillText(t,s,e+r/2,n+i/2,{fillStyle:no.greyScale(68)})}get supportsWholeGenome(){return!0}dispose(){}}class Xf{constructor(t,e,n){this.majorTick=t,this.minorTick=t/10,this.majorUnit=e,this.unitMultiplier=n}description(t){console.log((t||"")+" tick "+Gf(this.majorTick)+" label width "+Gf(this.labelWidthBP)+" multiplier "+this.unitMultiplier)}}const Yf=function(t,e){this.button=pe({class:"igv-navbar-button"}),t.appendChild(this.button),this.button.textContent="circular view",this.button.addEventListener("click",(()=>{e.circularViewVisible=!e.circularViewVisible})),this.browser=e,this.setVisibility(e.config.showCircularViewButton),this.setState(e.circularViewVisible)};Yf.prototype.setVisibility=function(t){!0===t?this.show():this.hide()},Yf.prototype.setState=function(t){!0===t?this.button.classList.add("igv-navbar-button-clicked"):this.button.classList.remove("igv-navbar-button-clicked")},Yf.prototype.show=function(){this.button.style.display="block",this.setState(this.browser.circularViewVisible)},Yf.prototype.hide=function(){this.button.style.display="none"};const Kf=function(t,e,n){const r=pe({class:"igv-navbar-button"});t.append(r),r.textContent=n.label,r.addEventListener("click",(()=>n.callback(e)))};class Qf{constructor(t,e){this.config=t,this.guid=ve(),this.namespace=".browser_"+this.guid,this.parent=e,this.root=pe({class:"igv-container"}),e.appendChild(this.root),Qo.init(this.root),this.columnContainer=pe({class:"igv-column-container"}),this.root.appendChild(this.columnContainer),this.menuPopup=new yl(this.columnContainer),this.initialize(t),this.trackViews=[],this.constants={dragThreshold:3,scrollThreshold:5,defaultColor:"rgb(0,0,150)",doubleClickDelay:t.doubleClickDelay||500},this.eventHandlers={},this.addMouseHandlers(),this.setControls(t)}initialize(t){t.gtex&&(Eu.gtexLoaded=!0),this.flanking=t.flanking,this.crossDomainProxy=t.crossDomainProxy,this.formats=t.formats,this.trackDefaults=t.trackDefaults,this.nucleotideColors=t.nucleotideColors||Tf;for(let t of Object.keys(this.nucleotideColors))this.nucleotideColors[t.toLowerCase()]=this.nucleotideColors[t];this.trackLabelsVisible=t.showTrackLabels,this.isCenterLineVisible=t.showCenterGuide,this.cursorGuideVisible=t.showCursorGuide,this.showSampleNames=t.showSampleNames,this.showSampleNameButton=t.showSampleNameButton,this.sampleNameViewportWidth=t.sampleNameViewportWidth||200,t.search&&(this.searchConfig={type:"json",url:t.search.url,coords:void 0===t.search.coords?1:t.search.coords,chromosomeField:t.search.chromosomeField||"chromosome",startField:t.search.startField||"start",endField:t.search.endField||"end",geneField:t.search.geneField||"gene",snpField:t.search.snpField||"snp",resultsField:t.search.resultsField})}setControls(t){const e=this.createStandardControls(t);e.insertBefore(de(this.columnContainer)),this.$navigation=e,!1===t.showControls&&e.hide()}createStandardControls(t){this.navbarManager=new Rf(this);const e=de("<div>",{class:"igv-navbar"});this.$navigation=e;const n=de("<div>",{class:"igv-navbar-left-container"});e.append(n);const r=de("<div>",{class:"igv-logo"});n.append(r);const i=de('<svg width="690px" height="324px" viewBox="0 0 690 324" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>IGV</title><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="IGV" fill="#666666"><polygon id="Path" points="379.54574 8.00169252 455.581247 8.00169252 515.564813 188.87244 532.884012 253.529506 537.108207 253.529506 554.849825 188.87244 614.833392 8.00169252 689.60164 8.00169252 582.729511 320.722144 486.840288 320.722144"></polygon><path d="M261.482414,323.793286 C207.975678,323.793286 168.339046,310.552102 142.571329,284.069337 C116.803612,257.586572 103.919946,217.158702 103.919946,162.784513 C103.919946,108.410325 117.437235,67.8415913 144.472217,41.0770945 C171.507199,14.3125977 212.903894,0.930550071 268.663545,0.930550071 C283.025879,0.930550071 298.232828,1.84616386 314.284849,3.6774189 C330.33687,5.50867394 344.839793,7.97378798 357.794056,11.072835 L357.794056,68.968378 C339.48912,65.869331 323.578145,63.5450806 310.060654,61.9955571 C296.543163,60.4460336 284.574731,59.6712835 274.154998,59.6712835 C255.850062,59.6712835 240.502308,61.4320792 228.111274,64.9537236 C215.720241,68.4753679 205.793482,74.2507779 198.330701,82.2801269 C190.867919,90.309476 185.587729,100.87425 182.48997,113.974767 C179.392212,127.075284 177.843356,143.345037 177.843356,162.784513 C177.843356,181.942258 179.251407,198.000716 182.067551,210.960367 C184.883695,223.920018 189.671068,234.41436 196.429813,242.443709 C203.188559,250.473058 212.059279,256.178037 223.042241,259.558815 C234.025202,262.939594 247.683295,264.629958 264.01693,264.629958 C268.241146,264.629958 273.098922,264.489094 278.590403,264.207362 C284.081883,263.925631 289.643684,263.50304 295.275972,262.939577 L295.275972,159.826347 L361.595831,159.826347 L361.595831,308.579859 C344.698967,313.087564 327.239137,316.750019 309.215815,319.567334 C291.192494,322.38465 275.281519,323.793286 261.482414,323.793286 L261.482414,323.793286 L261.482414,323.793286 Z" id="Path"></path>;<polygon id="Path" points="0.81355666 5.00169252 73.0472883 5.00169252 73.0472883 317.722144 0.81355666 317.722144"></polygon></g> </g> </svg>');i.css("width","34px"),i.css("height","32px"),r.append(i),this.$current_genome=de("<div>",{class:"igv-current-genome"}),n.append(this.$current_genome),this.$current_genome.text("");const o=de("<div>",{class:"igv-navbar-genomic-location"});n.append(o),this.chromosomeSelectWidget=new If(this,o.get(0)),void 0===t.showChromosomeWidget&&(t.showChromosomeWidget=!0),!0===t.showChromosomeWidget?this.chromosomeSelectWidget.show():this.chromosomeSelectWidget.hide();const s=de("<div>",{class:"igv-locus-size-group"});o.append(s);const a=de("<div>",{class:"igv-search-container"});s.append(a),this.$searchInput=de("<input>",{class:"igv-search-input",type:"text",placeholder:"Locus Search"}),a.append(this.$searchInput),this.$searchInput.change((()=>this.doSearch(this.$searchInput.val())));const c=pe({class:"igv-search-icon-container"});a.append(de(c)),c.appendChild(we("search")),c.addEventListener("click",(()=>this.doSearch(this.$searchInput.val()))),this.windowSizePanel=new Nf(s.get(0),this);const l=de("<div>",{class:"igv-navbar-right-container"});e.append(l);const h=de('<div class="igv-navbar-toggle-button-container">');if(l.append(h),this.$toggle_button_container=h,this.cursorGuide=new Pf(this.columnContainer,this),this.cursorGuideButton=new Of(this,h.get(0)),this.centerLineButton=new Ff(this,h.get(0)),this.setTrackLabelVisibility(t.showTrackLabels),this.trackLabelControl=new Df(h.get(0),this),this.sampleNameControl=new Bf(h.get(0),this),!0===t.showSVGButton&&(this.svgSaveControl=new jf(h.get(0),this)),t.customButtons)for(let e of t.customButtons)new Kf(h.get(0),this,e);return this.zoomWidget=new Vf(this,l.get(0)),!1===t.showNavigation&&this.$navigation.hide(),this.inputDialog=new Jo(this.root),this.inputDialog.container.id=`igv-input-dialog-${ve()}`,this.dataRangeDialog=new cs(de(this.root)),this.dataRangeDialog.$container.get(0).id=`igv-data-range-dialog-${ve()}`,this.genericColorPicker=new wl({parent:this.columnContainer,width:432}),this.genericColorPicker.container.id=`igv-track-color-picker-${ve()}`,e}getSampleNameViewportWidth(){return!1===this.showSampleNames?0:this.sampleNameViewportWidth}isMultiLocusMode(){return this.referenceFrameList&&this.referenceFrameList.length>1}addTrackToFactory(t,e){vf(t,e)}isMultiLocusWholeGenomeView(){if(void 0===this.referenceFrameList||1===this.referenceFrameList.length)return!1;for(let t of this.referenceFrameList)if("all"===t.chr.toLowerCase())return!0;return!1}toSVG(){let{x:t,y:e,width:n,height:r}=this.columnContainer.getBoundingClientRect();let i=new js({width:n,height:8e3,backdropColor:"white",multiLocusGap:0,viewbox:{x:0,y:0,width:n,height:8e3}});for(let t of this.trackViews)t.renderSVGContext(i,{deltaX:0,deltaY:-e});return i.setHeight(r),i.getSerializedSvg(!0)}renderSVG(t){const e=this.toSVG();return t.empty(),t.append(e),e}saveSVGtoFile(t){let e=this.toSVG();t.$container&&(t.$container.empty(),t.$container.append(e));qe(t.filename||"igvjs.svg",URL.createObjectURL(new Blob([e],{type:"application/octet-stream"})))}async loadSession(t){let e;return this.roi=[],e=t.url||t.file?await async function(t){const e=t.url||t.file;if(t.url&&(t.url.startsWith("blob:")||t.url.startsWith("data:"))){const e=Qf.uncompressSession(t.url);return JSON.parse(e)}{let n=t.filename;if(n||(n=t.url?await bs(t.url):t.file.name),n.endsWith(".xml")){const t=na.KNOWN_GENOMES,n=await go.loadString(e);return new xf(n,t)}return n.endsWith(".json")?go.loadJson(e):void 0}}(t):t,this.loadSessionObject(e)}async loadSessionObject(t){this.cleanHouseForSession(),this.showSampleNames=t.showSampleNames||!1,this.sampleNameControl.setState(!0===this.showSampleNames),t.sampleNameViewportWidth&&(this.sampleNameViewportWidth=t.sampleNameViewportWidth),xs(this.columnContainer,"igv-axis-column"),xs(this.columnContainer,"igv-sample-name-column"),xs(this.columnContainer,"igv-scrollbar-column"),xs(this.columnContainer,"igv-track-drag-column"),xs(this.columnContainer,"igv-gear-menu-column");const e=await na.expandReference(t.reference||t.genome);if(await this.loadReference(e,t.locus),this.centerLineList=this.createCenterLineList(this.columnContainer),!1!==t.showIdeogram){const t=new uf(this);t.id="ideogram",this.trackViews.push(new Sl(this,this.columnContainer,t))}if(!1!==t.showRuler&&this.trackViews.push(new Sl(this,this.columnContainer,new Zf(this))),t.gtexSelections)for(let e of this.referenceFrameList)for(let n of Object.keys(t.gtexSelections)){const r=t.gtexSelections[n].gene,i=t.gtexSelections[n].snp;e.selection=new Cf(r,i)}if(t.roi){this.roi=[];for(let e of t.roi)this.roi.push(new wf(e,this.genome))}const n=e.tracks||[],r=t.tracks?n.concat(t.tracks):n;0===r.filter((t=>"sequence"===t.type)).length&&r.push({type:"sequence",order:Ts});let i=1;for(let t of r)void 0===t.order&&(t.order=i++);await this.loadTrackList(r);for(let t of this.trackViews.filter((t=>"ruler"===t.track.type||"ideogram"===t.track.type)))t.updateViews();this.updateUIWithReferenceFrameList()}createCenterLineList(t){const e=t.querySelectorAll(".igv-center-line");for(let t=0;t<e.length;t++)e[t].remove();const n=[],r=t.querySelectorAll(".igv-column");for(let t=0;t<r.length;t++)n.push(new $f(this,this.referenceFrameList[t],r[t]));return n}async loadReference(t,e){const n=await na.loadGenome(t),r=void 0===this.genome||this.genome.id!==n.id;this.genome=n,this.updateNavbarDOMWithGenome(n),r&&this.removeAllTracks();let i=function(t,e){return t?Array.isArray(t)?t.join(" "):t:e.getHomeChromosomeName()}(e,n);if(!await this.search(i,!0)){console.log("Initial locus not found: "+i),i=n.getHomeChromosomeName();if(!await this.search(i,!0))throw new Error("Cannot set initial locus")}r&&this.circularView&&this.circularView.setAssembly({name:this.genome.id,id:this.genome.id,chromosomes:Jc(this.genome)})}cleanHouseForSession(){for(let t of this.trackViews)t.removeDOMFromColumnContainer();this.columnContainer.querySelectorAll(".igv-axis-column, .igv-column-shim, .igv-column, .igv-sample-name-column, .igv-scrollbar-column, .igv-track-drag-column, .igv-gear-menu-column").forEach((t=>t.remove())),this.trackViews=[],this.circularView&&this.circularView.clearChords()}updateNavbarDOMWithGenome(t){this.$current_genome.text(t.id||""),this.$current_genome.attr("title",t.id||""),this.chromosomeSelectWidget.update(t)}async loadGenome(t){const e=await na.expandReference(t);await this.loadReference(e,void 0);const n=e.tracks||[];return 0===n.filter((t=>"sequence"===t.type)).length&&n.push({type:"sequence",order:Ts}),await this.loadTrackList(n),await this.updateViews(),this.genome}updateUIWithReferenceFrameList(){const t=this.referenceFrameList;this.updateLocusSearchWidget();const e=this.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(t[0].chr);this.navbarManager.navbarDidResize(this.$navigation.width(),e),nd(this.trackViews,this.trackLabelsVisible),this.setCenterLineAndCenterLineButtonVisibility(!na.isWholeGenomeView(t[0].chr))}setTrackLabelVisibility(t){nd(this.trackViews,t)}setCursorGuideVisibility(t){t?this.cursorGuide.show():this.cursorGuide.hide()}setCustomCursorGuideMouseHandler(t){this.cursorGuide.customMouseHandler=t}setCenterLineVisibility(t){for(let e of this.centerLineList)!0===t?(e.show(),e.repaint()):e.hide()}setCenterLineAndCenterLineButtonVisibility(t){for(let e of this.centerLineList){t&&e.isVisible?e.show():e.container.style.display="none"}t&&this.centerLineButton.isVisible?this.centerLineButton.show():this.centerLineButton.button.style.display="none"}async loadTrackList(t){const e=[];for(let n of t)e.push(this.loadTrack(n));const n=await Promise.all(e);return this.trackViews.filter((function(t){return t.track.autoscaleGroup})).length>0&&this.updateViews(),n}async loadROI(t){if(this.roi||(this.roi=[]),Array.isArray(t))for(let e of t)this.roi.push(new wf(e,this.genome));else this.roi.push(new wf(t,this.genome));await this.updateViews(!0)}removeROI(t){for(let e=0;e<this.roi.length;e++)if(this.roi[e].name===t.name){this.roi.splice(e,1);break}for(let t of this.trackViews)t.repaintViews()}clearROIs(){this.roi=[];for(let t of this.trackViews)t.repaintViews()}getRulerTrackView(){const t=this.trackViews.filter((({track:t})=>"ruler"===t.id));return t.length>0?t[0]:void 0}async loadTrack(t){ke(t)&&(t=JSON.parse(t));try{const e=await this.createTrack(t);if(void 0===e)return Qo.presentAlert(new Error(`Unknown file type: ${t.url||t}`),void 0),e;void 0===e.order&&(e.order=this.trackViews.length);const n=new Sl(this,this.columnContainer,e);if(this.trackViews.push(n),nd(this.trackViews,this.trackLabelsVisible),this.reorderTracks(),this.fireEvent("trackorderchanged",[this.getTrackOrder()]),"function"==typeof e.postInit)try{n.startSpinner(),await e.postInit()}finally{n.stopSpinner()}return e.autoscaleGroup||(t.sync?await n.updateViews():n.updateViews()),"function"==typeof e.hasSamples&&e.hasSamples()&&!1!==this.config.showSampleNameButton&&this.sampleNameControl.show(),e}catch(e){const n={401:"Access unauthorized",403:"Access forbidden",404:"Not found"};console.error(e);let r=e.message||e.error||e.toString();n.hasOwnProperty(r)&&(r=n[r]),r+=": "+t.url,Qo.presentAlert(new Error(r),void 0)}}async createTrack(t){let e=await async function(t){return"function"==typeof t?t():t}(t.url);if(ke(e)&&(e=e.trim()),e)if(t.format)t.format=t.format.toLowerCase();else{let n=t.filename;n||(n=await bs(e)),t.format=function(t){var e,n;if((t=t.toLowerCase()).endsWith("refgene.txt.gz")||t.endsWith("refgene.txt.bgz")||t.endsWith("refgene.txt")||t.endsWith("refgene.sorted.txt.gz")||t.endsWith("refgene.sorted.txt.bgz"))return"refgene";switch((e=t.indexOf("?"))>0&&(t=t.substr(0,e)),t.endsWith(".gz")&&(t=t.substr(0,t.length-3)),(t.endsWith(".txt")||t.endsWith(".tab")||t.endsWith(".bgz"))&&(t=t.substr(0,t.length-4)),n=(e=t.lastIndexOf("."))<0?t:t.substr(e+1)){case"bw":return"bigwig";case"bb":return"bigbed";default:return fs.has(n)?n:void 0}}(n),t.format||void 0!==t.sourceType&&"htsget"!==t.sourceType||await ec.inferFormat(t)}let n=t.type?t.type.toLowerCase():void 0;if(!n){if(n=ds(t),"bedtype"===n){const e=Cu(t,this.genome);t._featureSource=e;const r=await e.trackType();n=r||"annotation"}t.type=n}if(this.trackDefaults&&n){const e=this.trackDefaults[n];if(e)for(let n in e)e.hasOwnProperty(n)&&void 0===t[n]&&(t[n]=e[n])}const r=bf(n,t,this);if(r&&t.roi){r.roi=[];for(let e of t.roi)r.roi.push(new wf(e,this.genome))}return r}reorderTracks(){this.trackViews.sort((function(t,e){const n=t=>"ideogram"===t.track.id?1:"ruler"===t.track.id?2:3,r=n(t),i=n(e);if(r===i){return(t.track.order||0)-(e.track.order||0)}return r-i}));for(let{axis:t,viewports:e,sampleNameViewport:n,outerScroll:r,dragHandle:i,gearContainer:o}of this.trackViews){t.remove();for(let{$viewport:t}of e)t.detach();n.viewport.remove(),r.remove(),i.remove(),o.remove()}const t=this.columnContainer.querySelectorAll(".igv-column");for(let{axis:e,viewports:n,sampleNameViewport:r,outerScroll:i,dragHandle:o,gearContainer:s}of this.trackViews){this.columnContainer.querySelector(".igv-axis-column").appendChild(e);for(let e=0;e<t.length;e++){const{$viewport:r}=n[e];t[e].appendChild(r.get(0))}this.columnContainer.querySelector(".igv-sample-name-column").appendChild(r.viewport),this.columnContainer.querySelector(".igv-scrollbar-column").appendChild(i),this.columnContainer.querySelector(".igv-track-drag-column").appendChild(o),this.columnContainer.querySelector(".igv-gear-menu-column").appendChild(s)}}getTrackOrder(){return this.trackViews.filter((t=>t.track&&t.track.name)).map((t=>t.track.name))}removeTrackByName(t){const e=this.trackViews.slice();for(let n of e)t===n.track.name&&this.removeTrack(n.track)}removeTrack(t){this.trackViews.splice(this.trackViews.indexOf(t.trackView),1),this.fireEvent("trackremoved",[t]),this.fireEvent("trackorderchanged",[this.getTrackOrder()]),t.trackView.dispose()}removeAllTracks(){const t=[];for(let e of this.trackViews)"ruler"!==e.track.id&&"ideogram"!==e.track.id?(this.fireEvent("trackremoved",[e.track]),e.dispose()):t.push(e);this.trackViews=t}findTracks(t,e){let n="function"==typeof t?e=>t(e.track):n=>e===n.track[t];return this.trackViews.filter(n).map((t=>t.track))}setTrackHeight(t){this.trackHeight=t,this.trackViews.forEach((function(e){e.setTrackHeight(t)}))}async visibilityChange(){this.layoutChange()}async layoutChange(){if(this.referenceFrameList.find((t=>t.bpPerPixel<0))){const t=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList)e.bpPerPixel=(e.end-e.start)/t}if(this.referenceFrameList){const t=this.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(this.referenceFrameList[0].chr);this.navbarManager.navbarDidResize(this.$navigation.width(),t)}Jf.call(this),await this.updateViews()}async updateViews(){const t=this.trackViews;this.updateLocusSearchWidget();for(let t of this.centerLineList)t.repaint();if(this.dragObject)for(let e of t)await e.updateViews();else{const i={},o=[];for(let n of t){const t=n.track.autoscaleGroup;if(t){var e=i[t];e||(e=[],i[t]=e),e.push(n)}else o.push(n)}if(Object.entries(i).length>0){const t=Object.keys(i);for(let e of t){const t=i[e],o=[];for(let e of t)o.push(e.getInViewFeatures());const s=await Promise.all(o);var n,r=[];for(let t of s)r=r.concat(t);n=ms(r);const a=[];for(let e of t)e.track.dataRange=n,e.track.autoscale=!1,a.push(e.updateViews());await Promise.all(a)}}await Promise.all(o.map((t=>t.updateViews())))}}repaintViews(){for(let t of this.trackViews)t.repaintViews()}updateLocusSearchWidget(){const t=this.referenceFrameList,e=this.calculateViewportWidth(this.referenceFrameList.length);for(let n of t)n.end=n.start+n.bpPerPixel*e;this.chromosomeSelectWidget.select.value=1===t.length?this.referenceFrameList[0].chr:"";const n=this.referenceFrameList.map((t=>t.getLocusString())).join(" ");this.$searchInput.val(n),this.fireEvent("locuschange",[this.referenceFrameList])}calculateViewportWidth(t){let{width:e}=this.columnContainer.getBoundingClientRect();return e-=50+this.getSampleNameViewportWidth()+14+12+28,e-=5*(t-1),Math.floor(e/t)}getCenterLineXOffset(){let{width:t}=this.columnContainer.getBoundingClientRect();return t-=50+this.getSampleNameViewportWidth()+14+12+28,Math.floor(t/2+50)}minimumBases(){return this.config.minimumBases}zoomIn(){this.zoomWithScaleFactor(.5)}zoomOut(){this.zoomWithScaleFactor(2)}async zoomWithScaleFactor(t,e,n){const r=this.calculateViewportWidth(this.referenceFrameList.length);let i=n?[n]:this.referenceFrameList;for(let n of i)n.zoomWithScaleFactor(this,t,r,e)}async addMultiLocusPanel(t,e,n,r){const i=this.calculateViewportWidth(1+this.referenceFrameList.length),o=this.calculateViewportWidth(this.referenceFrameList.length)/this.calculateViewportWidth(1+this.referenceFrameList.length);for(let t of this.referenceFrameList)t.bpPerPixel*=o;const s=(n-e)/i,a=new Af(this.genome,t,e,n,s),c=r?this.referenceFrameList.indexOf(r):this.referenceFrameList.length-1,l=1+c,{$viewport:h}=this.trackViews[0].viewports[c],u=qf(h.get(0).parentElement);if(l===this.referenceFrameList.length){this.referenceFrameList.push(a);for(let t of this.trackViews){const e=gl(t,u,a);t.viewports.push(e)}}else{this.referenceFrameList.splice(l,0,a);for(let t of this.trackViews){const e=gl(t,u,a);t.viewports.splice(l,0,e)}}this.centerLineList=this.createCenterLineList(this.columnContainer),Jf.call(this),await this.updateViews(!0)}async removeMultiLocusPanel(t){const e=this.referenceFrameList.indexOf(t),{$viewport:n}=this.trackViews[0].viewports[e];Uf(e,n.parent().get(0));for(let{viewports:t}of this.trackViews)t[e].dispose(),t.splice(e,1);if(this.referenceFrameList.splice(e,1),1===this.referenceFrameList.length&&this.getRulerTrackView())for(let t of this.getRulerTrackView().viewports)t.dismissLocusLabel();const r=this.calculateViewportWidth(1+this.referenceFrameList.length)/this.calculateViewportWidth(this.referenceFrameList.length);await this.rescaleForMultiLocus(r)}async gotoMultilocusPanel(t){const e=this.referenceFrameList.indexOf(t);this.columnContainer.querySelectorAll(".igv-column").forEach(((t,n)=>{n===e||t.remove()})),this.columnContainer.querySelectorAll(".igv-column-shim").forEach((t=>t.remove()));for(let t of this.trackViews){const n=t.viewports[e];t.viewports.filter(((t,n)=>n!==e)).forEach((t=>t.dispose())),t.viewports=[n]}const n=this.calculateViewportWidth(1);t.bpPerPixel=(t.end-t.start)/n,this.referenceFrameList=[t],this.trackViews.forEach((({viewports:t})=>t.forEach((t=>t.setWidth(n))))),this.centerLineList=this.createCenterLineList(this.columnContainer),this.updateUIWithReferenceFrameList(),await this.updateViews(!0)}async rescaleForMultiLocus(t){const e=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList)e.bpPerPixel*=t;for(let{viewports:t}of this.trackViews)for(let n of t)n.setWidth(e);this.centerLineList=this.createCenterLineList(this.columnContainer),this.updateUIWithReferenceFrameList(),await this.updateViews()}async goto(t,e,n){await this.search(t+":"+e+"-"+n)}async doSearch(t,e){const n=await this.search(t,e);return n||Qo.presentAlert(new Error(`Unrecognized locus: <b> ${t} </b>`)),n}async search(t,e){const n=await Mf(this,t);if(n&&n.length>0){this.referenceFrameList=function(t,e,n,r,i){return t.map((t=>{n&&t.gene&&(t.start=Math.max(0,t.start-n),t.end+=n);const o=e.getChromosome(t.chr);vs(o.bpLength,t,r);const s=new Af(e,t.chr,t.start,t.end,(t.end-t.start)/i);return s.locusSearchString=t.locusSearchString,(t.gene||t.snp)&&(s.selection=new Cf(t.gene,t.snp)),s}))}(n,this.genome,this.flanking,this.minimumBases(),this.calculateViewportWidth(n.length));for(let t of this.trackViews)t.removeDOMFromColumnContainer();this.columnContainer.querySelectorAll(".igv-column-shim, .igv-column").forEach((t=>t.remove())),Wf(this.columnContainer.querySelector(".igv-sample-name-column"),this.referenceFrameList.length),this.centerLineList=this.createCenterLineList(this.columnContainer);for(let t of this.trackViews)t.addDOMToColumnContainer(this,this.columnContainer,this.referenceFrameList);return this.updateUIWithReferenceFrameList(),e||await this.updateViews(),!0}return!1}async loadSampleInformation(t){var e=t;je(t)&&(e=t.name),"fam"===e.substr(e.lastIndexOf(".")+1)&&(this.sampleInformation=await function(t,e){return(new Sf).loadPlinkFile(t,e)}(t))}on(t,e){this.eventHandlers[t]||(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}un(t,e){this.off(t,e)}off(t,e){if(t)if(e){const n=this.eventHandlers[t];if(n&&0!==n.length){const r=n.indexOf(e);-1!==r&&this.eventHandlers[t].splice(r,1)}else console.warn("No handlers to remove for event: "+t)}else this.eventHandlers[t]=[];else this.eventHandlers={}}fireEvent(t,e,n){const r=this.eventHandlers[t];if(void 0===r||0===r.length)return;const i=n||window;return r.map((function(t){return t.apply(i,e)}))[0]}dispose(){this.removeMouseHandlers();for(let t of this.trackViews)t.dispose()}toJSON(){const t={version:"2.12.6"};if(void 0!==this.showSampleNames&&(t.showSampleNames=this.showSampleNames),200!==this.sampleNameViewportWidth&&(t.sampleNameViewportWidth=this.sampleNameViewportWidth),t.reference=this.genome.toJSON(),Ue(t.reference.fastaURL))throw new Error(`Error. Sessions cannot include local file references ${t.reference.fastaURL.name}.`);if(Ue(t.reference.indexURL))throw new Error(`Error. Sessions cannot include local file references ${t.reference.indexURL.name}.`);const e=[],n={};let r=!1,i=this.trackViews[0];for(let{referenceFrame:t}of i.viewports){const i=t.getLocusString();if(e.push(i),t.selection){const e={gene:t.selection.gene,snp:t.selection.snp};n[i]=e,r=!0}}t.locus=1===e.length?e[0]:e,r&&(t.gtexSelections=n);const o=[],s=[];for(let{track:t}of this.trackViews)try{let e;e="function"==typeof t.getState?t.getState():t.config,e&&(e.browser&&delete e.browser,e.order=t.order,o.push(e))}catch(e){console.error(`Track: ${t.name}: ${e}`),s.push(`Track: ${t.name}: ${e}`)}if(s.length>0){let t=1,e="Errors encountered saving session: </br>";for(let n of s)e+=` (${t++}) ${n.toString()} <br/>`;throw Error(e)}return t.tracks=o,t}compressedSession(){return function(t){const e=new Uint8Array(t.length);for(var n=0;n<t.length;n++)e[n]=t.charCodeAt(n);const r=new Ui.deflateRaw(e),i=String.fromCharCode.apply(null,r);return btoa(i).replace(/\+/g,".").replace(/\//g,"_").replace(/=/g,"-")}(JSON.stringify(this.toJSON()))}sessionURL(){const t=window.location.href.slice(),e=t.indexOf("?");return(e>0?t.substring(0,e):t)+"?sessionURL=blob:"+this.compressedSession()}mouseDownOnViewport(t,e){var n;n=me(t),this.vpMouseDown={viewport:e,lastMouseX:n.x,mouseDownX:n.x,lastMouseY:n.y,mouseDownY:n.y,referenceFrame:e.referenceFrame}}cancelTrackPan(){const t=this.dragObject;this.dragObject=void 0,this.isScrolling=!1,this.vpMouseDown=void 0,t&&t.viewport.referenceFrame.start!==t.start&&(this.updateViews(),this.fireEvent("trackdragend"))}startTrackDrag(t){this.dragTrack=t}updateTrackDrag(t){if(t&&this.dragTrack){const e=this.dragTrack,n=this.trackViews.indexOf(t),r=this.trackViews.indexOf(e),i=this.trackViews;i[n]=e,i[r]=t;const o=this.trackViews[n].track.order;this.trackViews[r].track.order=o;const s=i.length;let a=o;if(n<r)for(let t=n+1;t<s;t++){const e=i[t].track;if(!(e.order<=a))break;e.order=Math.min(Number.MAX_SAFE_INTEGER,a+1),a=e.order}else for(let t=n-1;t>0;t--){const e=i[t].track;if(!(e.order>=a))break;e.order=Math.max(-Number.MAX_SAFE_INTEGER,a-1),a=e.order}this.reorderTracks()}}endTrackDrag(){this.dragTrack?(this.dragTrack=void 0,this.fireEvent("trackorderchanged",[this.getTrackOrder()])):this.dragTrack=void 0}addMouseHandlers(){this.addWindowResizeHandler(),this.addRootMouseUpHandler(),this.addRootMouseLeaveHandler(),this.addColumnContainerEventHandlers()}removeMouseHandlers(){this.removeWindowResizeHandler(),this.removeRootMouseUpHandler(),this.removeRootMouseLeaveHandler(),this.removeColumnContainerEventHandlers()}addWindowResizeHandler(){this.boundWindowResizeHandler=Jf.bind(this),window.addEventListener("resize",this.boundWindowResizeHandler)}removeWindowResizeHandler(){window.removeEventListener("resize",this.boundWindowResizeHandler)}addRootMouseUpHandler(){this.boundRootMouseUpHandler=ed.bind(this),this.root.addEventListener("mouseup",this.boundRootMouseUpHandler)}removeRootMouseUpHandler(){this.root.removeEventListener("mouseup",this.boundRootMouseUpHandler)}addRootMouseLeaveHandler(){this.boundRootMouseLeaveHandler=ed.bind(this),this.root.addEventListener("mouseleave",this.boundRootMouseLeaveHandler)}removeRootMouseLeaveHandler(){this.root.removeEventListener("mouseleave",this.boundRootMouseLeaveHandler)}addColumnContainerEventHandlers(){this.boundColumnContainerMouseMoveHandler=td.bind(this),this.boundColumnContainerTouchMoveHandler=td.bind(this),this.boundColumnContainerMouseLeaveHandler=ed.bind(this),this.boundColumnContainerMouseUpHandler=ed.bind(this),this.boundColumnContainerTouchEndHandler=ed.bind(this),this.columnContainer.addEventListener("mousemove",this.boundColumnContainerMouseMoveHandler),this.columnContainer.addEventListener("touchmove",this.boundColumnContainerTouchMoveHandler),this.columnContainer.addEventListener("mouseleave",this.boundColumnContainerMouseLeaveHandler),this.columnContainer.addEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.columnContainer.addEventListener("touchend",this.boundColumnContainerTouchEndHandler)}removeColumnContainerEventHandlers(){this.columnContainer.removeEventListener("mousemove",this.boundColumnContainerMouseMoveHandler),this.columnContainer.removeEventListener("touchmove",this.boundColumnContainerTouchMoveHandler),this.columnContainer.removeEventListener("mouseleave",this.boundColumnContainerMouseLeaveHandler),this.columnContainer.removeEventListener("mouseup",this.boundColumnContainerMouseUpHandler),this.columnContainer.removeEventListener("touchend",this.boundColumnContainerTouchEndHandler)}async getDriveFileInfo(t){const e="https://www.googleapis.com/drive/v3/files/"+Ie(t)+"?supportsTeamDrives=true";return go.loadJson(e,gs({}))}static uncompressSession(t){let e;if(t.indexOf("/gzip;base64")>0){e=Yi(t);let n="";for(let t of e)n+=String.fromCharCode(t);return n}return function(t){t=t.replace(/\./g,"+").replace(/_/g,"/").replace(/-/g,"=");const e=atob(t),n=[];for(let t=0;t<e.length;t++)n.push(e.charCodeAt(t));const r=Ui.inflateRaw(n);let i="";for(let t of r)i+=String.fromCharCode(t);return i}(t.substring(5))}createCircularView(t,e){var n;return e=!0===e,this.circularView=(n=this,new $c(t,{onChordClick:(t,e,r)=>{const i=t.data,o=i.mate;function s(t){t.chr=n.genome.getChromosomeName(t.refName);let e=!1;for(let r of n.referenceFrameList){const n=Ac.fromLocusString(r.getLocusString());if(n.contains(t)){e=!0;break}if(n.overlaps(t)){r.extend(t),e=!0;break}}if(!e){const e=2e3,r=(t.start+t.end)/2;n.addMultiLocusPanel(t.chr,r-e,r+e)}}s(i),s(o)}})),this.circularViewControl=new Yf(this.$toggle_button_container.get(0),this),this.circularView.setAssembly({name:this.genome.id,id:this.genome.id,chromosomes:Jc(this.genome)}),this.circularViewVisible=e,this.circularView}get circularViewVisible(){return void 0!==this.circularView&&this.circularView.visible}set circularViewVisible(t){this.circularView&&(this.circularView.visible=t,this.circularViewControl.setState(t))}}async function Jf(){const t=this.calculateViewportWidth(this.referenceFrameList.length);for(let e of this.referenceFrameList){const n=this.referenceFrameList.indexOf(e),{chr:r,genome:i}=e,{bpLength:o}=i.getChromosome(e.chr),s=e.toBP(t);na.isWholeGenomeView(r)||s>o?e.bpPerPixel=o/t:e.end=e.start+e.toBP(t);for(let{viewports:e}of this.trackViews)e[n].setWidth(t)}this.updateUIWithReferenceFrameList(),await this.updateViews(!0)}function td(t){t.preventDefault();const{x:e,y:n}=me(t);if(this.vpMouseDown){const{viewport:t,referenceFrame:r}=this.vpMouseDown,i=Math.abs(e-this.vpMouseDown.mouseDownX)>Math.abs(n-this.vpMouseDown.mouseDownY);if(!this.dragObject&&!this.isScrolling)if(i)this.vpMouseDown.mouseDownX&&Math.abs(e-this.vpMouseDown.mouseDownX)>this.constants.dragThreshold&&(this.dragObject={viewport:t,start:r.start});else if(this.vpMouseDown.mouseDownY&&Math.abs(n-this.vpMouseDown.mouseDownY)>this.constants.scrollThreshold){this.isScrolling=!0;const e=t.$viewport.height(),n=Cl(t.trackView.viewports);this.vpMouseDown.r=e/n}if(this.dragObject){r.shiftPixels(this.vpMouseDown.lastMouseX-e,t.$viewport.width())&&this.updateViews(),this.fireEvent("trackdrag")}if(this.isScrolling){const e=this.vpMouseDown.r*(this.vpMouseDown.lastMouseY-n);t.trackView.moveScroller(e)}this.vpMouseDown.lastMouseX=e,this.vpMouseDown.lastMouseY=n}}function ed(t){this.cancelTrackPan(),this.endTrackDrag()}function nd(t,e){for(let{viewports:n}of t)for(let t of n)t.$trackLabel&&(0===n.indexOf(t)&&!0===e?t.$trackLabel.show():t.$trackLabel.hide())}let rd=[];const id=go.setApiKey;!function(){var t=document.createElement("style");t.setAttribute("type","text/css"),t.innerHTML='.igv-navbar {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n box-sizing: border-box;\n width: 100%;\n color: #444;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n line-height: 32px;\n padding-left: 8px;\n padding-right: 8px;\n margin-top: 2px;\n margin-bottom: 6px;\n height: 32px;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: #f3f3f3; }\n .igv-navbar .igv-navbar-left-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-navbar .igv-navbar-left-container .igv-logo {\n width: 34px;\n height: 32px;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-left-container .igv-current-genome {\n height: 32px;\n margin-left: 4px;\n margin-right: 4px;\n user-select: none;\n line-height: 32px;\n vertical-align: middle;\n text-align: center; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-chromosome-select-widget-container {\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center;\n height: 100%;\n width: 125px;\n margin-right: 4px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-chromosome-select-widget-container select {\n display: block;\n cursor: pointer;\n width: 100px;\n height: 75%;\n outline: none;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n margin-left: 8px;\n height: 22px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n width: 210px;\n height: 22px;\n line-height: 22px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container input.igv-search-input {\n cursor: text;\n width: 85%;\n height: 22px;\n line-height: 22px;\n font-size: 12px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n text-align: left;\n padding-left: 8px;\n margin-right: 8px;\n outline: none;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: white; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-search-container .igv-search-icon-container {\n cursor: pointer;\n height: 16px;\n width: 16px; }\n .igv-navbar .igv-navbar-left-container .igv-navbar-genomic-location .igv-locus-size-group .igv-windowsize-panel-container {\n margin-left: 4px;\n user-select: none; }\n .igv-navbar .igv-navbar-right-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container div {\n margin-left: 0;\n margin-right: 4px; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container div:last-child {\n margin-left: 0;\n margin-right: 0; }\n .igv-navbar .igv-navbar-right-container .igv-navbar-toggle-button-container-750 {\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget div:nth-child(even) {\n display: block;\n height: fit-content; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget input {\n display: block;\n width: 125px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget svg {\n display: block; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 div:nth-child(even) {\n width: 0;\n height: 0;\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 input {\n width: 0;\n height: 0;\n display: none; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-900 svg {\n display: block; }\n .igv-navbar .igv-navbar-right-container .igv-zoom-widget-hidden {\n display: none; }\n\n.igv-navbar-button {\n display: block;\n box-sizing: unset;\n padding-left: 6px;\n padding-right: 6px;\n height: 18px;\n text-transform: capitalize;\n user-select: none;\n line-height: 18px;\n text-align: center;\n vertical-align: middle;\n font-family: "Open Sans", sans-serif;\n font-size: 11px;\n font-weight: 200;\n color: #737373;\n background-color: #f3f3f3;\n border-color: #737373;\n border-style: solid;\n border-width: thin;\n border-radius: 6px; }\n\n.igv-navbar-button-clicked {\n color: white;\n background-color: #737373; }\n\n.igv-navbar-button:hover {\n cursor: pointer; }\n\n.igv-zoom-in-notice-container {\n z-index: 1024;\n position: absolute;\n top: 8px;\n left: 50%;\n transform: translate(-50%, 0%);\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n background-color: white; }\n .igv-zoom-in-notice-container > div {\n padding-left: 4px;\n padding-right: 4px;\n padding-top: 2px;\n padding-bottom: 2px;\n width: 100%;\n height: 100%;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #3f3f3f; }\n\n.igv-zoom-in-notice {\n position: absolute;\n top: 10px;\n left: 50%; }\n .igv-zoom-in-notice div {\n position: relative;\n left: -50%;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #3f3f3f;\n background-color: rgba(255, 255, 255, 0.51);\n z-index: 64; }\n\n.igv-container-spinner {\n position: absolute;\n top: 90%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1024;\n width: 24px;\n height: 24px;\n pointer-events: none;\n color: #737373; }\n\n.igv-multi-locus-close-button {\n position: absolute;\n top: 2px;\n right: 0;\n padding-left: 2px;\n padding-right: 2px;\n width: 18px;\n height: 18px;\n color: #666666;\n background-color: white;\n z-index: 1000; }\n .igv-multi-locus-close-button > svg {\n vertical-align: top; }\n\n.igv-multi-locus-close-button:hover {\n cursor: pointer;\n color: #434343; }\n\n.igv-multi-locus-ruler-label {\n z-index: 64;\n position: absolute;\n top: 2px;\n left: 0;\n width: 100%;\n height: 14px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center; }\n .igv-multi-locus-ruler-label div {\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #101010;\n background-color: white; }\n\n.igv-multi-locus-ruler-label-square-dot {\n z-index: 64;\n position: absolute;\n left: 50%;\n top: 5%;\n transform: translate(-50%, 0%);\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-multi-locus-ruler-label-square-dot > div:first-child {\n width: 14px;\n height: 14px; }\n .igv-multi-locus-ruler-label-square-dot > div:last-child {\n margin-left: 16px;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n color: #101010; }\n\n.igv-multi-locus-ruler-label:hover {\n cursor: pointer; }\n\n.igv-ruler-sweeper {\n display: none;\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 100%;\n z-index: 99999;\n background-color: rgba(68, 134, 247, 0.25); }\n\n.igv-ruler-tooltip {\n pointer-events: none;\n z-index: 128;\n position: absolute;\n top: 0;\n left: 0;\n width: 1px;\n height: 32px;\n background-color: transparent;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-ruler-tooltip > div {\n pointer-events: none;\n width: 128px;\n height: auto;\n padding: 1px;\n color: #373737;\n font-size: 10px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n background-color: white;\n border-style: solid;\n border-width: thin;\n border-color: #373737; }\n\n.igv-track-label {\n position: absolute;\n left: 8px;\n top: 8px;\n width: auto;\n height: auto;\n max-width: 200px;\n padding-left: 4px;\n padding-right: 4px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n font-family: "Open Sans", sans-serif;\n font-size: small;\n font-weight: 400;\n text-align: center;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-color: #444;\n border-radius: 2px;\n border-style: solid;\n border-width: thin;\n background-color: white;\n z-index: 128;\n cursor: pointer; }\n\n.igv-track-label:hover,\n.igv-track-label:focus,\n.igv-track-label:active {\n background-color: #e8e8e8; }\n\n.igv-track-label-popup-shim {\n padding-left: 8px;\n padding-right: 8px;\n padding-top: 4px; }\n\n.igv-center-line {\n display: none;\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n transform: translateX(-50%);\n z-index: 8;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-left-style: dashed;\n border-left-width: thin;\n border-right-style: dashed;\n border-right-width: thin; }\n\n.igv-center-line-wide {\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(127, 127, 127, 0.51); }\n\n.igv-center-line-thin {\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(0, 0, 0, 0); }\n\n.igv-cursor-guide-horizontal {\n display: none;\n pointer-events: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n position: absolute;\n left: 0;\n right: 0;\n top: 50%;\n height: 1px;\n z-index: 1;\n margin-left: 50px;\n margin-right: 54px;\n border-top-style: dotted;\n border-top-width: thin;\n border-top-color: rgba(127, 127, 127, 0.76); }\n\n.igv-cursor-guide-vertical {\n pointer-events: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 50%;\n width: 1px;\n z-index: 1;\n border-left-style: dotted;\n border-left-width: thin;\n border-left-color: rgba(127, 127, 127, 0.76);\n display: none; }\n\n.igv-user-feedback {\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 512px;\n height: 360px;\n z-index: 2048;\n background-color: white;\n border-color: #a2a2a2;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #444;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-user-feedback div:first-child {\n position: relative;\n height: 24px;\n width: 100%;\n background-color: white;\n border-bottom-color: #a2a2a2;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-user-feedback div:first-child div {\n position: absolute;\n top: 2px;\n width: 16px;\n height: 16px;\n background-color: transparent; }\n .igv-user-feedback div:first-child div:first-child {\n left: 8px; }\n .igv-user-feedback div:first-child div:last-child {\n cursor: pointer;\n right: 8px; }\n .igv-user-feedback div:last-child {\n width: 100%;\n height: calc(100% - 24px);\n border-width: 0; }\n .igv-user-feedback div:last-child div {\n width: auto;\n height: auto;\n margin: 8px; }\n\n.igv-generic-dialog-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 300px;\n height: 200px;\n border-color: #7F7F7F;\n border-radius: 4px;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n z-index: 2048;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-header {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee; }\n .igv-generic-dialog-container .igv-generic-dialog-header div {\n margin-right: 4px;\n margin-bottom: 2px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-generic-dialog-container .igv-generic-dialog-header div:hover {\n cursor: pointer;\n color: #444; }\n .igv-generic-dialog-container .igv-generic-dialog-one-liner {\n color: #373737;\n width: 95%;\n height: 24px;\n line-height: 24px;\n text-align: left;\n margin-top: 8px;\n padding-left: 8px;\n overflow-wrap: break-word;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input {\n margin-top: 8px;\n width: 95%;\n height: 24px;\n color: #373737;\n line-height: 24px;\n padding-left: 8px;\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input div {\n width: 30%;\n height: 100%;\n font-size: 16px;\n text-align: right;\n padding-right: 8px;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n width: 50%;\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-input {\n margin-top: 8px;\n width: calc(100% - 16px);\n height: 24px;\n color: #373737;\n line-height: 24px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: "Open Sans", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel {\n width: 100%;\n height: 28px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div {\n margin-top: 32px;\n color: white;\n font-family: "Open Sans", sans-serif;\n font-size: 14px;\n font-weight: 400;\n width: 75px;\n height: 28px;\n line-height: 28px;\n text-align: center;\n border-color: transparent;\n border-style: solid;\n border-width: thin;\n border-radius: 2px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child {\n margin-left: 32px;\n margin-right: 0;\n background-color: #5ea4e0; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child {\n margin-left: 0;\n margin-right: 32px;\n background-color: #c4c4c4; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child:hover {\n cursor: pointer;\n background-color: #3b5c7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child:hover {\n cursor: pointer;\n background-color: #7f7f7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok {\n width: 100%;\n height: 36px;\n margin-top: 32px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div {\n width: 98px;\n height: 36px;\n line-height: 36px;\n text-align: center;\n color: white;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n border-color: white;\n border-style: solid;\n border-width: thin;\n border-radius: 4px;\n background-color: #2B81AF; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div:hover {\n cursor: pointer;\n background-color: #25597f; }\n\n.igv-generic-container {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 2048;\n background-color: white;\n cursor: pointer;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-container div:first-child {\n cursor: move;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n height: 24px;\n width: 100%;\n background-color: #dddddd; }\n .igv-generic-container div:first-child i {\n display: block;\n color: #5f5f5f;\n cursor: pointer;\n width: 14px;\n height: 14px;\n margin-right: 8px;\n margin-bottom: 4px; }\n\n.igv-menu-popup {\n position: absolute;\n top: 0;\n left: 0;\n width: max-content;\n z-index: 4096;\n cursor: pointer;\n font-family: "Open Sans", sans-serif;\n font-size: small;\n font-weight: 400;\n color: #4b4b4b;\n background: white;\n border-radius: 4px;\n border-color: #7F7F7F;\n border-style: solid;\n border-width: thin;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-end;\n text-align: left; }\n .igv-menu-popup > div:not(:first-child) {\n width: 100%; }\n .igv-menu-popup > div:not(:first-child) > div {\n background: white; }\n .igv-menu-popup > div:not(:first-child) > div.context-menu {\n padding-left: 4px;\n padding-right: 4px; }\n .igv-menu-popup > div:not(:first-child) > div:last-child {\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px;\n border-bottom-color: transparent;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-menu-popup > div:not(:first-child) > div:hover {\n background: #efefef; }\n\n.igv-menu-popup-shim {\n padding-left: 8px;\n padding-right: 8px;\n padding-bottom: 1px;\n padding-top: 1px; }\n\n.igv-menu-popup-header {\n position: relative;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-color: transparent;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-menu-popup-header div {\n margin-right: 4px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-menu-popup-header div:hover {\n cursor: pointer;\n color: #444; }\n\n.igv-menu-popup-check-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n width: 100%;\n height: 20px;\n margin-right: 4px;\n background-color: transparent; }\n .igv-menu-popup-check-container div {\n padding-top: 2px;\n padding-left: 8px; }\n .igv-menu-popup-check-container div:first-child {\n position: relative;\n width: 12px;\n height: 12px; }\n .igv-menu-popup-check-container div:first-child svg {\n position: absolute;\n width: 12px;\n height: 12px; }\n\n.igv-user-feedback {\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 512px;\n height: 360px;\n z-index: 2048;\n background-color: white;\n border-color: #a2a2a2;\n border-style: solid;\n border-width: thin;\n font-family: "Open Sans", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #444;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-user-feedback div:first-child {\n position: relative;\n height: 24px;\n width: 100%;\n background-color: white;\n border-bottom-color: #a2a2a2;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-user-feedback div:first-child div {\n position: absolute;\n top: 2px;\n width: 16px;\n height: 16px;\n background-color: transparent; }\n .igv-user-feedback div:first-child div:first-child {\n left: 8px; }\n .igv-user-feedback div:first-child div:last-child {\n cursor: pointer;\n right: 8px; }\n .igv-user-feedback div:last-child {\n width: 100%;\n height: calc(100% - 24px);\n border-width: 0; }\n .igv-user-feedback div:last-child div {\n width: auto;\n height: auto;\n margin: 8px; }\n\n.igv-loading-spinner-container {\n z-index: 1024;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 32px;\n height: 32px;\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center; }\n .igv-loading-spinner-container > div {\n box-sizing: border-box;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n border: 4px solid rgba(128, 128, 128, 0.5);\n border-top-color: white;\n animation: spin 1s ease-in-out infinite;\n -webkit-animation: spin 1s ease-in-out infinite; }\n\n@keyframes spin {\n to {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n@-webkit-keyframes spin {\n to {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n.igv-container {\n position: relative;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n padding-top: 4px;\n user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none; }\n\n.igv-viewport {\n position: relative;\n margin-top: 5px;\n overflow-x: hidden;\n overflow-y: hidden; }\n\n.igv-viewport-content {\n position: relative;\n width: 100%; }\n .igv-viewport-content > canvas {\n position: relative;\n display: block; }\n\n.igv-column-container {\n position: relative;\n display: flex;\n flex-direction: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: stretch;\n width: 100%; }\n\n.igv-column-shim {\n width: 1px;\n margin-left: 2px;\n margin-right: 2px;\n background-color: #545453; }\n\n.igv-column {\n position: relative;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%; }\n\n.igv-axis-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 50px; }\n .igv-axis-column > div {\n margin-top: 5px;\n width: 100%; }\n\n.igv-sample-name-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%; }\n\n.igv-scrollbar-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 14px; }\n .igv-scrollbar-column > div {\n position: relative;\n margin-top: 5px;\n width: 14px; }\n .igv-scrollbar-column > div > div {\n cursor: pointer;\n position: absolute;\n top: 0;\n left: 2px;\n width: 8px;\n border-width: 1px;\n border-style: solid;\n border-color: #c4c4c4;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px; }\n .igv-scrollbar-column > div > div:hover {\n background-color: #c4c4c4; }\n\n.igv-track-drag-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 12px;\n background-color: white; }\n .igv-track-drag-column > .igv-track-drag-handle {\n z-index: 512;\n position: relative;\n cursor: pointer;\n margin-top: 5px;\n width: 100%;\n border-style: solid;\n border-width: 0;\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n background-color: #c4c4c4; }\n .igv-track-drag-column .igv-track-drag-handle-hover {\n background-color: #787878; }\n .igv-track-drag-column > .igv-track-drag-shim {\n position: relative;\n margin-top: 5px;\n width: 100%;\n border-style: solid;\n border-width: 0; }\n\n.igv-gear-menu-column {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-start;\n box-sizing: border-box;\n height: 100%;\n width: 28px; }\n .igv-gear-menu-column > div {\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n margin-top: 5px;\n width: 100%;\n background: white; }\n .igv-gear-menu-column > div > div {\n position: relative;\n margin-top: 4px;\n width: 16px;\n height: 16px;\n color: #7F7F7F; }\n .igv-gear-menu-column > div > div:hover {\n cursor: pointer;\n color: #444; }\n\n/*# sourceMappingURL=dom.css.map */\n',document.head.insertBefore(t,document.head.childNodes[document.head.childNodes.length-1])}();var od={IGVGraphics:ls,MenuUtils:Oo,DataRangeDialog:cs,createTrack:async function(t,e){return await Qf.prototype.createTrack.call(e,t)},createBrowser:async function(t,e){void 0===e&&(e={}),na.KNOWN_GENOMES||await na.initializeGenomes(e),function(t){void 0===t.minimumBases&&(t.minimumBases=40);void 0===t.showIdeogram&&(t.showIdeogram=!0);void 0===t.showCircularView&&(t.showCircularView=!1);void 0===t.showCircularViewButton&&(t.showCircularViewButton=!1);void 0===t.showTrackLabelButton&&(t.showTrackLabelButton=!0);void 0===t.showTrackLabels&&(t.showTrackLabels=!0);void 0===t.showCursorTrackingGuideButton&&(t.showCursorTrackingGuideButton=!0);void 0===t.showCursorGuide&&(t.showCursorGuide=t.showCursorTrackingGuide||!1);void 0===t.showCenterGuideButton&&(t.showCenterGuideButton=!0);void 0===t.showCenterGuide&&(t.showCenterGuide=!1);void 0===t.showSampleNames&&(t.showSampleNames=!1);void 0===t.showSVGButton&&(t.showSVGButton=!0);void 0===t.showControls&&(t.showControls=!0);void 0===t.showNavigation&&(t.showNavigation=!0);void 0===t.showRuler&&(t.showRuler=!0);void 0===t.flanking&&(t.flanking=1e3);void 0===t.pairsSupported&&(t.pairsSupported=!0);t.tracks||(t.tracks=[])}(e),e.queryParametersSupported&&function(t){var e,n,r,i,o,s,a,c,l;let h,u,f;if(a=window.location.href,o={},e=a.indexOf("?"),n=a.lastIndexOf("#"),e>=0)for(n<0&&(n=a.length),r=e+1;r<n;)(i=a.indexOf("&",r))<0&&(i=n),2===(s=a.substring(r,i).split("=",2)).length?(c=s[0],l=decodeURIComponent(s[1]),"file"===c?h=l.split(","):"index"===c?u=l.split(","):"name"===c?f=l.split(","):"genome"!==c||!l.startsWith("https://")&&!l.startsWith("http://")||l.endsWith(".json")?t[c]=l:t.reference={fastaURL:l,indexURL:l+".fai"},r=i+1):r++;if(h){t.tracks||(t.tracks=[]);for(let e=0;e<h.length;e++){if(h[e].endsWith(".xml")||h[e].endsWith(".json")){t.sessionURL=h[e];break}const n={url:h[e]};u&&u.length>e&&(n.indexURL=u[e]),f&&f.length>e&&(n.name=f[e]),t.tracks.push(n)}}}(e),e.apiKey&&go.setApiKey(e.apiKey),e.oauthToken&&ho.setToken(e.oauthToken),e.clientId&&!Oe()&&await Pe({clientId:e.clientId,apiKey:e.apiKey,scope:"https://www.googleapis.com/auth/userinfo.profile"});const n=new Qf(e,t);rd.push(n),e.sessionURL?await n.loadSession({url:e.sessionURL}):await n.loadSessionObject(e);const r=n.isMultiLocusWholeGenomeView()||na.isWholeGenomeView(n.referenceFrameList[0].chr);return n.navbarManager.navbarDidResize(n.$navigation.width(),r),n},removeBrowser:function(t){t.dispose(),t.root.remove(),rd=rd.filter((e=>e!==t))},removeAllBrowsers:function(){for(let t of rd)t.dispose(),t.root.remove();rd=[]},visibilityChange:async function(){for(let t of rd)await t.visibilityChange()},setGoogleOauthToken:function(t){return ho.setToken(t)},setOauthToken:function(t,e){return ho.setToken(t,e)},oauth:ho,version:ta,setApiKey:id,doAutoscale:ms,TrackView:Sl};export{od as default};
72
72
  //# sourceMappingURL=igv.esm.min.js.map