jbrowse-plugin-graphgenomeviewer 4.3.0 → 4.4.0
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.
- package/dist/chunks/{GraphGenomeView-ZB4N6Q3H.js → GraphGenomeView-NHYVE7GZ.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-BCTYOYQ5.js → LinearGraphDisplay-742CW5KL.js} +2 -2
- package/dist/chunks/chunk-5GUQPO7Y.js +3 -0
- package/dist/chunks/{chunk-PSOLXUFN.js.map → chunk-5GUQPO7Y.js.map} +3 -3
- package/dist/chunks/chunk-QHMGWDDH.js +2 -0
- package/dist/chunks/{chunk-PPYB6N2Q.js.map → chunk-QHMGWDDH.js.map} +4 -4
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
- package/package.json +2 -2
- package/src/GraphGenomeView/components/WalkStrip.tsx +25 -22
- package/src/GraphGenomeView/model.ts +133 -138
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-PPYB6N2Q.js +0 -2
- package/dist/chunks/chunk-PSOLXUFN.js +0 -3
- /package/dist/chunks/{GraphGenomeView-ZB4N6Q3H.js.map → GraphGenomeView-NHYVE7GZ.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-BCTYOYQ5.js.map → LinearGraphDisplay-742CW5KL.js.map} +0 -0
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{d as Bn}from"./chunk-UQEPPJEO.js";import{c as wn}from"./chunk-SCMIJAAX.js";import{A as In,B as vt,C as vn,D as Pn,E as Pt,F as Ot,I as On,J as kn,W as $n,X as pt,a as le,i as Mn,j as It,k as Rn,l as En,m as Sn,n as Nn,o as Ln,p as Tn,u as Cn,v as ft,w as An,x as Ue,y as xe,z as _n}from"./chunk-UTWFU4X6.js";import{a as je,b as O,c as ut,d as ve,e as yn,f as Pe,i as dt}from"./chunk-7BKUWQE5.js";import{a as lt,c as xn,d as ct}from"./chunk-KULNKXPT.js";import{a as it}from"./chunk-XEJ47DLD.js";import{a as Ke,b as Y}from"./chunk-FY3BTKY4.js";var Fn=Ke((Sl,Gn)=>{Gn.exports=JBrowseExports["@mui/material/SvgIcon"]});var Oe=Ke((_l,qn)=>{qn.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var qs=Ke((mc,co)=>{co.exports=JBrowseExports.mobx});var cr=Ke((Ou,lr)=>{lr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var dr=Ke((ku,ur)=>{ur.exports=JBrowseExports["@jbrowse/render-core/renderingBackendBase"]});var ne=Y(Fn(),1);var Zr=3.4,Wn=6,Jr=8,es=18,ts=2,ns=15;function os(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,r]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],o=s=>+(s/n).toFixed(n===1?0:1);return`${o(e.covered*t)} of ${o(t)} ${r}`}function rs(e,t,n){return Dn(e,r=>r.gene.end-r.gene.start).map(r=>{let{x:o,y:s}=t(r.at),a=os(r);return{item:r,x:o,y:s+n+es,text:a?`${r.gene.name} \xB7 ${a}`:r.gene.name,fallback:a?`${r.gene.name} \u2026`:void 0,stack:ts}})}function Dn(e,t){return[...e].sort((n,r)=>t(r)-t(n))}function Cl(e){let{paneWidth:t,canvasHeight:n,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:t,height:n},i=R=>({x:R.x*s+r,y:R.y*a+o}),c=e.drawnRowLabels.map(({label:R,y:N})=>An(R,N*a+o)),d=e.referenceStripZonePx??0;d>0&&c.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&c.push({x0:t-Wn-e.legendSize.width,x1:t,y0:0,y1:d+Wn+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let u=Cn(l,c),f=e.drawnRowLabels.length>0,h=f?Math.min(...e.drawnRowLabels.map(R=>R.y)):1/0,p=e.contigThickness*Zr,m=Dn(e.bubbleHalos,R=>R.members),g=ft(m.map(R=>{let{x:N,y:I}=i({x:R.labelAt.x,y:Math.min(R.labelAt.y,h)}),H=I-p/2-6;return{item:R,x:N,y:f?Math.max(H,ns):H,text:R.label}}),l,u),b=ft(rs(e.genePins,i,e.contigThickness),l,u),w=e.nodePositions&&e.labelsNodeSizes?_n({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],deletionRoutes:e.deletionRoutes,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},S=vt(w.deletions,u),E=ft(m.flatMap(R=>R.routes.map(N=>{let{x:I,y:H}=i(N.at);return{item:{halo:R,route:N},x:I,y:H+4,text:N.text,stack:Jr}})),l,u),T=vt(w.nodes,u,In(t,n));return{bubbles:g,genes:b,routes:E,sizes:[...S,...T]}}var G=Y(Oe(),1);var $=Y(Oe(),1);function ke(e,t){return(0,$.packAbgr)((0,$.abgrRed)(e),(0,$.abgrGreen)(e),(0,$.abgrBlue)(e),Math.round((0,$.abgrAlpha)(e)*t))}function mt(e,t){return(0,$.packAbgr)(Math.min(255,Math.round((0,$.abgrRed)(e)*t)),Math.min(255,Math.round((0,$.abgrGreen)(e)*t)),Math.min(255,Math.round((0,$.abgrBlue)(e)*t)),(0,$.abgrAlpha)(e))}var ss=4;function Ve(e){let t=new Map;function n(r,o){let s=t.get(r);s?s.push(o):t.set(r,[o])}for(let r of e.edges)n(r.from,r.to),n(r.to,r.from);return t}function as({nodeId:e,nodeById:t,neighbors:n}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<ss&&o.length>0;l++){let i=[];for(let c of o){let d=n.get(c);if(d){for(let u of d)if(!r.has(u)){r.add(u);let f=t.get(u);f&&O(f)?(s=Math.min(s,f.stable.start+f.length),a=Math.max(a,f.stable.start)):i.push(u)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function is({nodeId:e,nodeById:t,neighbors:n}){let r=t.get(e);return r===void 0?void 0:O(r)?{start:r.stable.start,end:r.stable.start+r.length}:as({nodeId:e,nodeById:t,neighbors:n})}function Hn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=Ve(e),r=new Map;for(let o of e.nodes){let s=is({nodeId:o.id,nodeById:t,neighbors:n});s&&r.set(o.id,(s.start+s.end)/2)}return r}var Xn=new WeakMap;function Yn(e,t,n,r,o,s){let{scaleX:a,scaleY:l}=n,i=Xn.get(e);if(i?.graph===t&&i.scaleX===a&&i.scaleY===l&&i.deletions===r&&i.routes===s&&i.version===o)return i.curves;let c=new Map;for(let d=0;d<t.edges.length;d++){let u=t.edges[d],f=e[u.from],h=e[u.to];if(f?.length&&h?.length){let p=r?.get(d),m=p&&s?.[d];c.set(d,m?Ln(f,h,m):Nn(f,h,Sn(u),0,0,n,p?Tn(e,p):[]))}}return Xn.set(e,{graph:t,scaleX:a,scaleY:l,deletions:r,routes:s,version:o,curves:c}),c}var ls=(0,G.packAbgr)(119,119,119,217),zn=(0,G.packAbgr)(136,136,136,217),cs=(0,G.packAbgr)(24,24,28,240),us=2.2,Jn=(0,G.packAbgr)(160,160,160,255),Qe=.18,Ft=(0,G.abgrToCssRgba)(ke(Jn,Qe)),ds=11,fs=1.2,Kn=4,kt=1e-6,ps=7,hs=3,ms=3,gs=1.5,bs=.5,xs=.45,Bt=12,ys=1e-6,ce=new Float64Array(64),ye=new Float64Array(64),we=new Float64Array(64);function ws(e,t,n,r){let o=e.length*Bt+1;ce.length<o&&(ce=new Float64Array(o),ye=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];ce[0]=s.x1,ye[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let c=e[i];for(let d=1;d<=Bt&&l<r;d++){let u=1-(d/Bt)**2,f=1-u,h=f*f*f,p=3*f*f*u,m=3*f*u*u,g=u*u*u,b=h*c.x0+p*c.cx0+m*c.cx1+g*c.x1,w=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(b-ce[a-1],(w-ye[a-1])*n)*t,ce[a]=b,ye[a]=w,we[a]=l,a++}}return a}function jn(e,t){let n=1;for(;n<e-1&&we[n]<t;)n++;let r=we[n-1],o=we[n],s=o>r?Math.min(1,Math.max(0,(t-r)/(o-r))):0;return{x:ce[n-1]+(ce[n]-ce[n-1])*s,y:ye[n-1]+(ye[n]-ye[n-1])*s}}function Ms({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=ps+hs*t,c=ws(e,r,o,n+i),d=we[c-1],u=Math.min(n,d),f=d<ys?Rs(a,r,o):d-u,h=Math.min(1,f/i);if(h<bs)return;let p=jn(c,u),m=jn(c,u+i*h),g=p.x-m.x,b=(p.y-m.y)*o,w=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,b)>0?Math.atan2(b,g):_s(w,o,Es(w,l)),length:i*h,halfWidth:(ms+gs*t)*h,color:s}}function Rs(e,t,n){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*n);return r*t}function Es(e,t){if(t.length<2)return;let n=t[0],r=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:n,to:t[1]}:{from:r,to:t[t.length-2]}}function $t(e,t=1){let n=t===1?e:e.map(o=>({x:o.x,y:o.y*t})),r=[];for(let o=0;o<n.length;o++){let s=0,a=0;if(o===0){let l=n[1].x-n[0].x,i=n[1].y-n[0].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===n.length-1){let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i),d=n[o+1].x-n[o].x,u=n[o+1].y-n[o].y,f=Math.hypot(d,u);if(c>0&&f>0){let h=-i/c,p=l/c,m=-u/f,g=d/f;s=(h+m)/2,a=(p+g)/2;let b=h*s+p*a;b>.1&&(s/=b,a/=b)}else c>0?(s=-i/c,a=l/c):f>0&&(s=-u/f,a=d/f)}r.push({nx:s,ny:a})}return r}function Un(e,t,n,r=1){return e.map((o,s)=>({x:o.x+t[s].nx*n,y:o.y+t[s].ny*n/r}))}function gt(e,t,n,r){return(0,G.packAbgr)(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(r*255))}function Be(e,t,n){let r=(1-Math.abs(2*n-1))*t,o=r*(1-Math.abs(e/60%2-1)),s=n-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var Ss=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],Ns=[[237,137,44],[158,42,122]],Ls=[[220,50,50],[50,120,220]];function Gt(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),o=n-r,s=e[r],a=e[r+1];return(0,G.packAbgr)(Math.round(s[0]+(a[0]-s[0])*o),Math.round(s[1]+(a[1]-s[1])*o),Math.round(s[2]+(a[2]-s[2])*o),255)}function Ts(e,t){let[n,r,o]=Be(vn(e),Pt,Ot);return gt(n,r,o,t)}var $e=300,Cs=.7,As=.5,eo=[60,65,72],Wt=(0,G.packAbgr)(...eo,255),Dt=`rgb(${eo.join(", ")})`;function Hl(e,t){let n=Hn(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let r=1/0,o=-1/0;for(let s of n.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:n}}function qt(e){let t=1/0,n=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<t&&(t=a.depth),a.depth>n&&(n=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:t,maxDepth:n,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Ht(e,t,n,r){switch(n){case"random":return Ts(e.id,1);case"depth":return Gt(Ss,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Gt(Ls,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,G.packAbgr)(160,160,160,255):e.stable.rank===0?(0,G.packAbgr)(52,152,219,255):Gt(Ns,r.maxRank>1?(e.stable.rank-1)/(r.maxRank-1):0);case"reference-position":{let o=r.referenceRamp,s=o?.midpoints.get(e.id);if(o===void 0||s===void 0)return(0,G.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Wt;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=Be(a*$e,Cs,As);return gt(l,i,c,1)}case"grey":return(0,G.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?t/r.nodeCount*360:0,[s,a,l]=Be(o,.75,.5);return gt(s,a,l,1)}default:return(0,G.packAbgr)(52,152,219,255)}}function _s(e,t=1,n){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*t;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return n?Math.atan2((n.to.y-n.from.y)*t,n.to.x-n.from.x):0}function Is(e,t){let n=!1;for(let r=0;r<e.length-1&&!n;r++){let o=e[r],s=e[r+1];n=Math.max(o.x,s.x)>=t.minX&&Math.min(o.x,s.x)<=t.maxX&&Math.max(o.y,s.y)>=t.minY&&Math.min(o.y,s.y)<=t.maxY}return n}function Vn(e,t){for(let n of e){let r=Math.min(n.x0,n.cx0,n.cx1,n.x1),o=Math.max(n.x0,n.cx0,n.cx1,n.x1),s=Math.min(n.y0,n.cy0,n.cy1,n.y1),a=Math.max(n.y0,n.cy0,n.cy1,n.y1);if(o>=t.minX&&r<=t.maxX&&a>=t.minY&&s<=t.maxY)return!0}return!1}var Qn=new WeakMap;function vs(e){let t=Qn.get(e);if(!t){let n=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=Be(Pn(s,o.length),Pt,Ot);n.push(gt(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}t={pathColorByIndex:n,pathIndexByName:r},Qn.set(e,t)}return t}var Zn=new WeakMap,Ps=new Map;function Os(e){let t=Zn.get(e);if(!t){t=new Map;for(let[n,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=t.get(o);s?s.push(n):t.set(o,[n])}Zn.set(e,t)}return t}function Xl(e){let{nodePositions:t,graph:n,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:d,linearLayout:u,viewportBounds:f,referenceRamp:h,deletions:p,deletionRoutes:m,hiddenEdges:g,version:b=0}=e,w=i==="depth"?$n(n):0,S=d.scaleX,E=Rn(d),T=Yn(t,n,d,p,b,m),R=[],N=new Map,I=[],H=new Map,F=[],z=new Map,Se={...qt(n),referenceRamp:h},pe=new Map;if(o==="rainbow")for(let A=0;A<n.nodes.length;A++)pe.set(n.nodes[A].id,A);let Q=n.paths?.length??0,{pathColorByIndex:K,pathIndexByName:Z}=vs(n),j=A=>K[Z.get(A)??-1]??zn,U=l&&Q>1?Os(n):Ps,Ne=S>(u?1:xs);for(let A=0;A<n.edges.length;A++){let P=n.edges[A],re=t[P.from],se=t[P.to],ae=T.get(A);if(!re?.length||!se?.length||!ae||g?.has(A))continue;let Le=P.pathIds?.length??0,He=p?.get(A)!==void 0,Xe=c?.edgeIndexes.has(A)??!1,he=a/2*(He?us:1),Te=l&&Le>0,me=He?cs:ls,J=!c||Xe?me:ke(me,Qe),Ye=r.get(P.to),Ce=(Ye?pt(Ye,s,i,w):s)/2,Ae=(be,Ie,X,ie)=>{let te=be===0&&Ie===0?ae:It(ae,be,Ie);if(f&&!Vn(te,f))return;if(He)for(let Ct of Mn(te,ds/S))F.push({curves:Ct,thickness:he,color:X});else F.push({curves:te,thickness:he,color:X});let at=Ne&&ie!==void 0?Ms({curves:te,edgeHalfWidth:he,nodeHalfWidth:Ce,scale:S,yToX:E,color:ie,fromSegments:re,toSegments:se}):void 0;at&&I.push(at)},ge=F.length,_e=I.length,ee=c&&Xe&&!Te?c.walks:void 0;if(ee){let be=r.get(P.from),Ie=be?pt(be,s,i,w):s,X=Math.max(Ie/ee.length,Kn),ie=$t(re,E),{nx:te,ny:at}=(P.fromStrand==="-"?ie[0]:ie.at(-1))??{nx:0,ny:0},Ct=1/Math.max(S,kt);ee.forEach((At,Ur)=>{if(!At.edgeIndexes.has(A))return;let _t=(Ur-(ee.length-1)/2)*X*Ct,bn=_t===0?ae:It(ae,te*_t,at*_t/E);f&&!Vn(bn,f)||F.push({curves:bn,thickness:X/2,color:At.colors.get(P.from)??At.colors.get(P.to)??me})})}else if(!Te)Ae(0,0,J,J);else{let be=En(re,se,Le,d),Ie=Math.floor((Le-1)/2);for(let X=0;X<Le;X++){let ie=be[X],te=j(P.pathIds[X]);Ae(ie.x,ie.y,c&&!c.names.has(P.pathIds[X])?ke(te,Qe):te,X===Ie?J:void 0)}}let ze=F.length-ge;ze>0&&z.set(A,{start:ge,count:ze});let st=I.length-_e;st>0&&H.set(A,{start:_e,count:st})}for(let[A,P]of Object.entries(t)){let re=r.get(A);if(!re||f&&!Is(P,f))continue;let se=c!==void 0&&!c.nodeIds.has(A),ae=se?Jn:Ht(re,pe.get(A)??0,o,Se),Le=se?ke(ae,Qe):ae,rt=pt(re,s,i,w),He=rt/2,Xe=R.length,he=U.get(A),Te=rt/Q,me=P.length>=2,J=c&&!se&&!he?.length?c.walks:void 0;if(me&&J){let Ce=Math.max(rt/J.length,Kn),Ae=$t(P,E),ge=1/Math.max(S,kt);J.forEach((_e,ee)=>{let ze=_e.colors.get(A);if(ze===void 0)return;let st=(ee-(J.length-1)/2)*Ce*ge;R.push({points:J.length===1?P:Un(P,Ae,st,E),thickness:Ce/2,color:ze})})}else if(me&&he?.length&&Te>=fs){let Ce=$t(P,E),Ae=1/Math.max(S,kt);for(let ge of he){let _e=(ge-(Q-1)/2)*Te*Ae,ee=K[ge]??zn;R.push({points:Un(P,Ce,_e,E),thickness:Te/2,color:se?ke(ee,Qe):ee})}}else me&&R.push({points:P,thickness:He,color:Le});let Ye=R.length-Xe;Ye>0&&N.set(A,{start:Xe,count:Ye})}return{nodeStrokes:R,nodeStrokeRuns:N,arrows:I,arrowRuns:H,edgeCurves:F,edgeCurveRuns:z}}function bt(e){return`hsl(${e}, 70%, 50%)`}function Xt(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*$e}var ks=30;function to({start:e,bp:t,reversed:n},r){let o=Xt(e,r),s=Xt(e+t,r);if(s-o<1)return[(o+s)/2];let a=Math.ceil((s-o)/ks);return Array.from({length:a+1},(l,i)=>Xt(e+t*(n?a-i:i)/a,r))}var Kl=`linear-gradient(to right, ${Array.from({length:7},(e,t)=>`${bt(t/6*$e)} ${t/6*100}%`).join(", ")})`;function Ql(e){return je(e)?no(e):void 0}function no(e){return{sample:lt(e.stable.refName),haplotype:xn(e.stable.refName),refName:ct(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Bs(e,t){let n=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of n)o=o&&s.start-o.end<=t?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function $s(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Zl(e,{maxGap:t=1/0}={}){let n=new Map;for(let o of e.nodes)if(je(o)){let s=no(o),a=$s(s),l=n.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):n.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of n.values()){let s=Bs(o.spans,t);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function Gs(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function Jl(e,t){return e.flatMap(n=>{let r=Gs(t,n);return r===void 0?[]:[{...n,sample:r}]})}function ec(e){return`${e.refName}:${e.start+1}-${e.end}`}function Yt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var oo=Y(it(),1),ro=(0,ne.createSvgIcon)((0,oo.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var so=Y(it(),1),ao=(0,ne.createSvgIcon)((0,so.jsx)("path",{d:"M17 5h-2V3h2zm-2 16h2v-2.59L19.59 21 21 19.59 18.41 17H21v-2h-6zm4-12h2V7h-2zm0 4h2v-2h-2zm-8 8h2v-2h-2zM7 5h2V3H7zM3 17h2v-2H3zm2 4v-2H3c0 1.1.9 2 2 2M19 3v2h2c0-1.1-.9-2-2-2m-8 2h2V3h-2zM3 9h2V7H3zm4 12h2v-2H7zm-4-8h2v-2H3zm0-8h2V3c-1.1 0-2 .9-2 2"}),"HighlightAlt");var io=Y(it(),1),zt=(0,ne.createSvgIcon)((0,io.jsx)("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var Fs="Linear genome view",Ws="Linear synteny view",Ds="No synteny track in this session aligns these assemblies";function lo({label:e,icon:t,entries:n,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=n,i=s?[{label:e,icon:t,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return n.length===0?i:n.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:t,onClick:o(l)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(c=>({label:r(c),onClick:o(c)}))}]}function fc({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:r}){let o=t[0]?.coverage??e.length;return[...lo({label:Fs,icon:zt,entries:e,entryLabel:s=>`${s.sample} ${Yt(s)}`,onSelect:s=>()=>{n({location:s,assembly:s.sample})}}),...e.length>=2?lo({label:`${Ws} (${o} assemblies)`,icon:ro,entries:t,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Ds,onSelect:s=>()=>{r(s.trackId)}}):[]]}function pc({own:e,reference:t,highlight:n,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Yt(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...o&&n?[{label:`Highlight in ${n.assembly}`,icon:ao,onClick:()=>{o(n)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:zt,onClick:()=>{r(l)}}))]}function Kt(e){return e.id.endsWith("-")?"-":"+"}function jt(e,t){return t===Kt(e)?e.id:`-${e.id}`}function Hs(e,t){let n=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=r,r+=e[o];let s=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Xs(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let r=Hs(t,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let d=r[c],u=t[c];if(d!==void 0&&u!==void 0&&d<=l&&(l<d+u||i&&l===d+u))return{s:c,local:l-d,room:d+u-l}}},s=(l,i)=>{let c=n[l],d=c.at(-1);i.type==="substitution"&&d?.type==="substitution"&&d.pos+d.seq.length===i.pos?d.seq+=i.seq:c.push(i)},a=e.pathStart;for(let l of wn(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let c=o(a),d=c?Math.min(i,c.room):i;c&&s(c.s,{type:"deletion",pos:c.local,length:d}),a+=d,i-=d}}return n}function uo(e,t,n){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of t){let a=s.path.map(d=>r.get(d.name)),l=a.flatMap((d,u)=>d?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let d=Xs(s,a.map(h=>h?.length)),u=l.map(h=>jt(a[h],s.path[h].strand)),f=a[c].length;o.push({id:n+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:l.map((h,p)=>({nodeName:u[p],mismatches:d[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ys=["#6baed6","#4292c6","#2171b5","#08519c"],zs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function fo(e){let t=e.is_reverse?zs:Ys;return t[e.id%t.length]}function xt(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function Ks(e,t,n,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=t.get(l);if(i){o.push(i);for(let c of n.get(l)??[]){let d=t.get(c);d&&(d.stable.rank===0?s.push(d):r.has(c)||(r.add(c),a.push(c)))}}}return{members:o,anchors:s}}function js(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=n[0],o=n.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Us(e,t,n){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of n.get(t.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of n.get(a)??[])if(r.has(i)){let c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function Vs(e,t,n){let r=Us(e,t,n),o=[...e].sort((i,c)=>r.get(i.id)-r.get(c.id)),s=new Map(o.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of o.entries()){let d=0;for(let u of n.get(c.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,l.get(u)+f.length))}l.set(c.id,d)}return{offsets:l,ordered:o}}function ho(e){let t=new Map(e.nodes.filter(je).map(s=>[s.id,s])),n=Ve(e),r=new Set,o=[];for(let s of t.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Ks(s.id,t,n,r),i=js(l);if(i){let{offsets:c,ordered:d}=Vs(a,i.entry,n);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>c.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,c.get(f.id)+f.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Qs=1,Zs=.015;function yt({graph:e,span:t,rowY:n,positions:r}){let o=t*Zs,s=ho(e),a=new Map(e.nodes.map(d=>[d.id,d])),l=[];for(let d of s){let u=d.refSpan-d.pathLength;u>=Qs&&l.push({nodeIds:d.nodeIds,bp:u});let f=Math.max(d.refSpan,o),h=d.pathLength>0?f/d.pathLength:0;d.nodeIds.forEach((p,m)=>{let g=a.get(p);if(g){let b=d.nodeOffsets[m],w=f/d.nodeIds.length,S=T=>d.start+T*h,E=n(g);r[p]=h?[{x:S(b),y:E},{x:S(b+g.length),y:E}]:[{x:d.start+m*w,y:E},{x:d.start+(m+1)*w,y:E}]}})}let i=Ve(e),c=Object.keys(r);for(let d of c){let u=r[d].at(-1).x;for(let f of i.get(d)??[]){let h=a.get(f);if(h&&!(f in r)){let p=n(h);r[f]=[{x:u,y:p},{x:u+o,y:p}],c.push(f)}}}return l}function Js(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,r)=>n-r).map((n,r)=>[n,r]))}function mo(e,t){let n=ve(e);if(n.length===0)return;let r=dt(n,t),o=Js(e),s=Pe(n),a=yt({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,c])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:c*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var ea=12,Ut=20;function go(e){return 10+8*Math.log2(1+e.length)}function ue(e,t){return e<t?-1:e>t?1:0}function xo(e,t){return ue(e.at,t.at)||ue(e.side,t.side)||ue(e.hops,t.hops)}var bo={at:1/0,side:0,hops:0};function ta(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=ra(e);return e.nodes.map(r=>r.id).sort((r,o)=>xo(n.get(r)??bo,n.get(o)??bo)||ue(t.get(r).name,t.get(o).name)||ue(r,o))}function na(e,t){let n=new Set(e.nodes.map(d=>d.id)),r=new Map(t.map(d=>[d.id,d.stable.start])),o=new Map,s=new Map;t.forEach((d,u)=>{s.set(d.id,t[u-1]?.id),o.set(d.id,t[u+1]?.id)});let a=t[0]?.id,l=(d,u)=>{let f=o.get(d);o.set(d,u),s.set(u,d),o.set(u,f),f!==void 0&&s.set(f,u)},i=(d,u)=>{let f=s.get(d);f===void 0?(a=u,s.set(u,void 0),o.set(u,d),s.set(d,u)):l(f,u)};for(let d of e.paths??[]){let u=0,f=0,h;for(let b of d.nodeIds){let w=r.get(b);w!==void 0&&(h!==void 0&&w!==h&&(w>h?u++:f++),h=w)}let p=f>u?[...d.nodeIds].reverse():d.nodeIds,m,g=new Set;for(let b of p)if(o.has(b)){if(m===void 0)for(let w of g)i(b,w);m=b}else n.has(b)&&(m===void 0?g.add(b):(l(m,b),m=b))}let c=[];for(let d=a;d!==void 0;d=o.get(d))c.push(d);return c}function oa(e,t){let n=[...t.entries()].sort(([a,l],[i,c])=>xo(l,c)||ue(a,i)).map(([a])=>a),r=n.length;for(let a of n){let l=t.get(a);for(let i of e.get(a)??[])t.has(i)||(t.set(i,{at:l.at,side:1,hops:l.hops+1}),n.push(i))}let o=new Set(n.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=t.get(a),i=[a];s.add(a);let c=!0;for(let d of i){let{hops:u}=t.get(d),f=!0,h=!1;for(let p of e.get(d)??[]){let m=t.get(p);m.at===l&&o.has(p)?(f&&=m.hops<=u,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!f||h}if(c)for(let d of i){let u=t.get(d);t.set(d,{...u,side:-1,hops:-u.hops})}}}function ra(e){let t=new Set(e.nodes.map(s=>s.id)),n=new Map;for(let s of e.edges)!t.has(s.from)||!t.has(s.to)||((n.get(s.from)??n.set(s.from,[]).get(s.from)).push(s.to),(n.get(s.to)??n.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(O).sort((s,a)=>ue(s.stable.start,a.stable.start)||ue(s.name,a.name)),o=new Map;return na(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),oa(n,o),o}function sa(e){let t=new Map(e.nodes.map(u=>[u.id,u])),n=ta(e),r=new Map(n.map((u,f)=>[u,f])),o=u=>O(t.get(u)),s=new Map(n.map(u=>[u,[]])),a=new Map(n.map(u=>[u,[]])),l=(u,f)=>{s.get(f).push(u),a.get(u).push(f)};for(let u of e.edges)u.from===u.to||!r.has(u.from)||!r.has(u.to)||(r.get(u.from)<r.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=n.filter(o);for(let u=1;u<i.length;u++)l(i[u-1],i[u]);let c=new Map;for(let u of n){let f=0;for(let h of s.get(u))f=Math.max(f,c.get(h)+1);c.set(u,f)}for(let u=n.length-1;u>=0;u--){let f=n[u],h=a.get(f);if(o(f)||h.length===0)continue;let p=1/0;for(let b of h)p=Math.min(p,c.get(b));let m=c.get(f),g=Math.max(m,p-1);c.set(f,Math.floor((m+g)/2))}let d=[];for(let u of n)(d[c.get(u)]??=[]).push(u);return{layers:d,layerOf:c,preds:s}}function yo(e){if(!e.nodes.some(O))return;let t=new Map(e.nodes.map(u=>[u.id,u])),n=u=>O(t.get(u)),{layers:r,layerOf:o,preds:s}=sa(e),a=r.map(u=>{let f=0;for(let h of u)f=Math.max(f,go(t.get(h)));return f}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+ea;let c=new Map;for(let u of r){let f=[];for(let p of u){if(n(p)){c.set(p,0);continue}let m=s.get(p).filter(b=>c.has(b)),g=0;for(let b of m)g+=c.get(b)/m.length;f.push({id:p,ideal:g===0?Ut:g})}f.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of f){let g=Math.round(m/Ut);g===0&&(g=m>=0?1:-1);for(let b=1;h.has(g);b++)h.has(g+b)?h.has(g-b)||(g-=b):g+=b;h.add(g),c.set(p,g*Ut)}}let d={};for(let u of e.nodes){let f=o.get(u.id),h=go(u),p=l[f]+a[f]/2,m=c.get(u.id);d[u.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:d,referenceAxis:!1,pixelRows:!0}}function aa(e,t){let n=new Map;for(let o of e.nodes)if(ut(o)){let{sample:s}=xt(o.stable.refName);n.set(s,(n.get(s)??0)+o.length)}let r=new Map(t.map((o,s)=>[o,s]));return[...n.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||n.get(s)-n.get(o)||o.localeCompare(s))}function wo(e,t,n=[]){let r=ve(e),o=aa(e,n);if(r.length===0||o.length===0)return;let s=dt(r,t),a=new Map(o.map((f,h)=>[f,h+1])),l=Pe(r),i=o.length+1,c=yt({graph:e,span:s,rowY:f=>{let h=f.stable;return((h?a.get(xt(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:xt(r[0].stable.refName).sample,y:0},...o.map(f=>({label:f,y:a.get(f)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function Vt(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var et=!1,Mo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function $o(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(t=>Mo[t.id%Mo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var _=$o({}),tn=null,x=[],y=[],M=[],C=new Map,We=[],L=[],Me=[],on=[],rn=[],V=-1,B=Vt(),nn={minX:0,maxX:0,minY:0,maxY:0},Ze,wt=new Map;function Go(e,t,n=[],r={}){if(_=$o(r),tn=r.bed??null,B=Vt(),Me=[],on=[],rn=[],We=[],nn={minX:0,maxX:0,minY:0,maxY:0},Ze=void 0,wt=new Map,e.length===0||t.length===0)return;let o=Qt(e);x=[],o.forEach((i,c)=>{x[c+1]=i}),y=Qt(t);let s=n.length>0;M=Qt(Ka(n));for(let i=y.length-1;i>=0;i-=1){let c=y[i];if(c.type===void 0&&(c.type="haplotype"),c.hidden===!0){y.splice(i,1);continue}c.indexOfFirstBase!==void 0&&(Ze=c.name)}if(y.length===0)return;la(0),C=So(),Ge(y),_.showReads&&M.length>0&&Ge(M),Bo(),_.mergeNodesFlag&&(No(),Jt(),_.showReads&&M.length>0&&Zt(),za(),C=So(),Bo(),Ge(y),_.showReads&&M.length>0&&Ge(M)),No(),Aa(),et&&console.log(`${x.length} nodes.`),Jt(),V=To(),_a(),Jt(),V=To();let a=_.showReads&&_.coarsenedReadView&&!s;if(a){let i=Ze===void 0?-1:y.findIndex(u=>u.name===Ze),c=i===-1?0:i,d=y.filter((u,f)=>f!==c);if(d.length>0){let u=vo(d,"haplotype");u.length>0&&(y=[y[c]],M=u)}}Wa(),Oa(),_.showExonsFlag&&tn!==null&&Fa();let l=_.showReads&&_.coarsenedReadView&&M.length>0&&!a;return _.showReads&&M.length>0?(ca(),Zt(),Ge(M),l&&(M=vo(M,"read"),Zt(),Ge(M)),da(),y=y.concat(M)):x.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),va(),Ha(),et&&(console.log("Tracks:"),console.log(y),console.log("Nodes:"),console.log(x),console.log("Lane assignment:"),console.log(Me)),Ea(),{nodes:x,tracks:y,reads:M,nodeMap:C,shapes:B,bounds:nn,maxOrder:V,trackForRuler:Ze,coarsenedEdgeMeta:wt}}function Fe(e,t="plain"){return _.trackColor(e,t)}function ia(e){return _.trackAlpha(e)}function Qt(e){return structuredClone(e)}function q(e){let t=String(e);return t.length>=1&&t.startsWith("-")}function v(e){return q(e)?String(e).substring(1):e}function de(e){return q(e)?e:`-${e}`}function Fo(e){return q(e)?v(e):de(e)}function Mt(e){return(e||1/e)>=0}function la(e){let t=new Set,n=y[e].sequence;for(let r=0;r<n.length;r+=1){let o=n[r];if(q(o)){let s=v(o),a=n.indexOf(s);(a===-1||a>r)&&t.add(s)}}for(let r of y){n=r.sequence;for(let o=0;o<n.length;o+=1){let s=n[o];q(s)?t.has(v(s))&&(n[o]=v(s)):t.has(s)&&(n[o]=de(s))}}x.forEach(r=>{r&&t.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function ca(){We=[];for(let t=0;t<=V;t+=1)We[t]=[];let e=new Map;x.forEach(t=>{t.y!==void 0&&Ro(e,t.order,t.y+t.contentHeight)}),y.forEach(t=>{t.type==="haplotype"&&t.path.forEach(n=>{Ro(e,n.order,(n.y??0)+t.width)})}),x.forEach((t,n)=>{t.order>=0&&t.y===void 0&&(t.y=(e.get(t.order)??0)+25,t.contentHeight=0,We[t.order].push(n))})}function Ro(e,t,n){let r=e.get(t);r===void 0?e.set(t,n):e.set(t,Math.max(r,n))}var Rt=7;function ua(){x.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),M.forEach((e,t)=>{if((e.width===void 0||e.width===0)&&(e.width=Rt),e.path.length===1){let n=e.path[0].node;n!==null&&x[n].internalReads.push(t)}else e.path.forEach((n,r)=>{if(r===0){let o=e.path[0].node;o!==null&&x[o].outgoingReads.push([t,r])}else{let o=n.node;o!==null&&x[o].incomingReads.push([t,r])}})})}function da(){ya(),ua();let e=x.slice();e.sort(Et);let t=new Map;for(let a=0;a<M.length;a++){let l=M[a].sourceTrackID,i=t.get(l);i===void 0?t.set(l,[a]):i.push(a)}let n=Array.from(t.keys()).sort((a,l)=>a-l),r=n.length>1?Rt:0;e.forEach(a=>{if(a)for(let l of n)fa(t.get(l),a,r)});let o=xa(),s=[];M.forEach((a,l)=>{let i=a.path.length,c=new Array(i),d;for(let h=0;h<i;h++){h===0?c[h]=void 0:c[h]=d??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(d=p)}let u=new Array(i),f;for(let h=i-1;h>=0;h--){h===i-1?u[h]=void 0:u[h]=f??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(f=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=c[p],g=u[p],b=!!(g&&m&&g.isForward!==void 0&&m.isForward!==void 0&&(m.order>g.order||g.order===m.order&&g.isForward===m.isForward));h.betweenCycleReverseTraversal=b,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(ha),s.forEach(a=>{let l=M[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),et&&(console.log("Reads:"),console.log(M))}function fa(e,t,n){let r=new Set(e),o=t.incomingReads.filter(([p])=>r.has(p)),s=t.outgoingReads.filter(([p])=>r.has(p)),a=t.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(n=0);let l=t.y+t.contentHeight+n*2,i=o.map(p=>{let[m,g]=p,b=M[m].path,w=g+1,S;for(let E=1;E<=g;E++){let T=b[g-E]?.y;if(T!==void 0){w=E,S=T;break}}return{entry:p,decisionStep:w,y:S}});i.sort(pa),o=i.map(p=>p.entry);let c=l,d=new Map;o.forEach(p=>{let m=M[p[0]];m.path[p[1]].y=c,Eo(d,m,p[1],c,t),c+=m.width});let u=c;s.sort(ma);let f=new Map;c=l,s.forEach(p=>{let m=M[p[0]],g=m.firstNodeOffset??0;m.path[p[1]].y=c,f.set(c,g);let b=d.get(c);b===void 0||b+1<=g?(c+=m.width,u=Math.max(u,c)):(d.set(c,0),o.forEach(w=>{let S=M[w[0]],E=S.path[w[1]];E.y!==void 0&&E.y>=c&&(E.y+=m.width,Eo(d,S,w[1],E.y,t))}),c+=m.width,u+=m.width)}),a.sort(ba),a.forEach(p=>{let m=M[p],g=m.firstNodeOffset??0,b=m.finalNodeCoverLength??0;for(c=l;g<(d.get(c)??-1/0)+2||b>(f.get(c)??1/0)-3;)c+=m.width||Rt;m.path[0].y=c,d.set(c,b),u=Math.max(u,c)});let h=u-t.y-t.contentHeight;t.contentHeight+=h,Ga(t,h)}function pa(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function Eo(e,t,n,r,o){n===t.path.length-1?e.set(r,t.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function ha(e,t){let n=M[e.readIndex],r=M[t.readIndex],o=n.path[e.pathIndex],s=r.path[t.pathIndex];if(o.order!==s.order)return o.order-s.order;if(n.sourceTrackID!==r.sourceTrackID)return n.sourceTrackID-r.sourceTrackID;if(e.previousNode&&t.previousNode){let i=x[e.previousNode],c=x[t.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=t.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function ma([e,t],[n,r]){let o=M[e],s=M[n],a,l,i=o.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let d=o.path[t]?.node,u=s.path[r]?.node,f=d!=null?x[d]:null,h=u!=null?x[u]:null;for(;f!=null&&h!=null&&f===h;){if(t<o.path.length-1){for(t+=1;o.path[t]?.node===null;)t+=1;let m=o.path[t]?.node;f=m!=null?x[m]:null}else f=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?x[m]:null}else h=null}if(f!=null)return h!=null?Et(f,h):1;if(h!=null)return-1;let p=(o.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(o.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function ga(e,t){if(e.path===void 0||t.path===void 0)return(e.path===void 0?0:1)-(t.path===void 0?0:1);let n=e.path,r=t.path,o=0,s=0;for(;o<n.length&&s<r.length;){let a=n[o],l=r[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?o+=1:(i>c||(o+=1),s+=1)}return 0}function ba(e,t){let n=M[e],r=M[t],o=n.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=n.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function xa(){let e=[];for(let t=0;t<=V;t+=1)e.push(0);return x.forEach(t=>{t.y!==void 0&&(e[t.order]=Math.max(e[t.order],t.y+t.contentHeight+20))}),y.forEach(t=>{t.path.forEach(n=>{e[n.order]=Math.max(e[n.order],(n.y??0)+t.width)})}),e}function ya(){M.forEach(e=>{let t=Math.abs(e.indexSequence[0]),n=Mt(e.indexSequence[0]),r=x[t],o,s;e.path=[],e.path.push({order:r.order,isForward:n,node:t});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=n,t=Math.abs(e.indexSequence[a]),n=Mt(e.indexSequence[a]),r=x[t],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});n?e.path.push({order:r.order,isForward:!0,node:t}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:t}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});n?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:t})):e.path.push({order:r.order,isForward:!1,node:t})}else n!==s?e.path.push({order:r.order,isForward:n,node:t}):(e.path.push({order:r.order,isForward:!n,node:null}),e.path.push({order:r.order,isForward:n,node:t}))})}function Zt(){M.forEach(e=>{let t=0;for(;t<e.sequence.length&&e.sequence[t].startsWith("-");)t+=1;if(t===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=v(e.sequence[a]);let n=e.sequenceNew??[];n.reverse(),e.sequenceNew=n;for(let a of n)a.nodeName=v(a.nodeName),wa(a.mismatches,oe(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function wa(e,t){e.forEach(n=>{n.type==="insertion"?n.pos=t-n.pos:n.type==="deletion"?n.pos=t-n.pos-(n.length??0):n.type==="substitution"&&(n.pos=t-n.pos-(n.seq?.length??0)),n.seq!==void 0&&(n.seq=Wo(n.seq).split("").reverse().join(""))})}var Ma={A:"T",T:"A",C:"G",G:"C"};function Wo(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Ma[e.charAt(n)]??"N";return t}function Ge(e){e.forEach(t=>{t.indexSequence=[],t.sequence.forEach(n=>{let r=n,o=C.get(v(r)),s=x[o]?.switched??!1;s&&(r=Fo(r));let a=C.get(v(r));if(a===0)throw new Error("Node "+v(r)+" has prohibited index 0");q(r)!==s?t.indexSequence.push(-a):t.indexSequence.push(a)})})}var Ra=20;function Ea(){let e={minX:99,maxX:-99,minY:99,maxY:-99};x.forEach(t=>{t&&(t.x!==void 0&&(e.minX=Math.min(e.minX,t.x),e.maxX=Math.max(e.maxX,t.x+Ra+t.pixelWidth)),t.y!==void 0&&(e.minY=Math.min(e.minY,t.y-10),e.maxY=Math.max(e.maxY,t.y+t.contentHeight+10)))}),y.forEach(t=>{t.path.forEach(n=>{let r=n.y??0;e.maxY=Math.max(e.maxY,r+t.width),e.minY=Math.min(e.minY,r)})}),nn=e}function oe(e){let t=C.get(v(e)),n=t===void 0?void 0:x[t];if(n===void 0)throw new Error(`Unknown node ${e}`);return n}function So(){return C=new Map,x.forEach((e,t)=>{e&&C.set(e.name,t)}),C}function No(){let e=x.map(()=>new Set),t=x.map(()=>new Set),n=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),t[a].add(s)}};y.forEach(n),_.showReads&&M.length>0&&M.forEach(n),x.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(t[o]))})}function Lo(e){let t=0,n=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){L[s]===void 0&&(L[s]=n);let a=L[s];a<r&&(r=a),t=a,n=a-1}else{L[s]===void 0&&(L[s]=t);let a=L[s];t=a+1,n=a}}),r<0&&sn(-r)}function Sa(e){let t=0,n=0;for(;t<e.length&&L[Math.abs(e[t])]===void 0;)t+=1;if(t>=e.length)return null;let r=e[t],o,s;r>=0?(o=L[r]-1,s=-1):(o=L[-r]+1,s=1);for(let a=t-1;a>=0;a-=1){let l=Math.abs(e[a]);L[l]===void 0&&(L[l]=o,n=Math.min(n,o),o+=s)}return n<0&&sn(-n),t}var Na=-1;function La(e){let t=[];for(let n of e)t.push(n??Na);return t}function Jt(){let e,t,n,r,o=0,s=_.showReads&&M.length>0?y.concat(M):y,a={stamp:new Int32Array(x.length),generation:0};L=new Array(x.length).fill(void 0),x.forEach(i=>{i&&(i.order=void 0)}),Lo(y[0].indexSequence);for(let i=1;i<s.length;i+=1){if(et&&console.log(`generating order for track ${i+1}`),n=Sa(s[i].indexSequence),n===null){s[i].type==="haplotype"?Lo(s[i].indexSequence):(s.splice(i,1),M.splice(i-y.length,1),i-=1);continue}for(e=Ca(s[i].indexSequence);n<e.length;){for(r=n,n+=1;n<e.length&&L[e[n]]===void 0;)n+=1;if(n<e.length){t=L[e[r]]+1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,t+=1;if(L[e[n]]>L[e[r]])L[e[n]]<t&&Co(e[n],e[n-1],t);else if(s[i].indexSequence[n]>=0&&!Ta(e[n],e[r],a))Co(e[n],e[n-1],t);else if(s[i].indexSequence[r]<0||x[e[r+1]].degree<2&&L[e[n]]<L[e[r]]){t=L[e[r]]-1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,o=Math.min(o,t),t-=1}}else if(s[i].indexSequence[r]>=0){t=L[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,t+=1)}}else{t=L[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,o=Math.min(o,t),t-=1)}}}}o<0&&sn(-o);let l=La(L);L=l,l.forEach((i,c)=>{let d=x[c];d!==void 0&&(d.order=i)})}function Ta(e,t,n){n.generation+=1;let{stamp:r,generation:o}=n,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===t)return!0;for(let l of x[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function To(){let e=-1;return L.forEach(t=>{t!==void 0&&t>e&&(e=t)}),e}function Ca(e){return e.map(t=>Math.abs(t))}function sn(e){L.forEach((t,n)=>{t!==void 0&&(L[n]=t+e)})}function Co(e,t,n){let r=new Map,o=[[e,n]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=L[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),x[a].successors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}),a!==e&&x[a].predecessors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}))}r.forEach((a,l)=>{L[l]=a})}function Aa(){x.forEach(e=>{e.tracks=[]}),y.forEach(e=>{e.indexSequence.forEach(t=>{x[Math.abs(t)].tracks.push(e.id)})}),x.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function _a(){let e=y[0],t=y.slice(1,y.length);if(_.showReads&&M.length>0&&(t=t.concat(M)),Ia(t,e),_.showReads&&M.length>0){for(let n=0;n<M.length;n++)if(M[n]!==t[n+y.length-1])throw new Error("Read inequality")}}function Ia(e,t){let n=new Map,r=t?new Set(t.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=v(s[a]),i=oe(l);if(r&&!r.has(l)){let c=a>0?oe(s[a-1]).order:void 0,d=a<s.length-1?oe(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(d===void 0||i.order<d)&&Ao(n,l,q(s[a])?1:-1),(c===void 0||c>i.order)&&(d===void 0||i.order>d)&&Ao(n,l,q(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=n.get(v(s));l!==void 0&&l>0&&(o.sequence[a]=Fo(s),o.indexSequence[a]=-o.indexSequence[a])});n.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=Wo(a.seq),a.switched=!0}})}function Ao(e,t,n){e.set(t,(e.get(t)??0)+n)}function va(){let e=0,t=20,n=-1,r=x.slice();r.sort(Et);let o=Pa();r.forEach(s=>{s.order>=0&&(s.order>n&&(n=s.order,e=t+10*o[s.order]),s.x=e,t=Math.max(t,e+40+s.pixelWidth))})}function Pa(){let e=[],t=[],n=[],r=[];for(let o=0;o<=V;o+=1)e.push(0),t.push(0),n.push(0);y.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:t[a.order]=t[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));n[a.order]=Math.max(i/17.5,n[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=V;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,t[o-1]-1),n[o]));return r}function Oa(){let e,t,n,r,o,s,a=[],l=[];for(let i=0;i<=V;i+=1){Me[i]=[],l[i]=new Map,a[i]=[];for(let c=0;c<y.length;c+=1)a[i][c]=null}y.forEach((i,c)=>{t=Math.abs(i.indexSequence[0]),n=Mt(i.indexSequence[0]),r=x[t],i.path=[],i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,0,a,l),e=1;for(let d=1;d<i.sequence.length;d+=1)if(o=r,s=n,t=Math.abs(i.indexSequence[d]),n=Mt(i.indexSequence[d]),r=x[t],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order+1;u<r.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order-1;u>r.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else n!==s?(i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!n,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1)});for(let i=0;i<=V;i+=1)Ba(Me[i],i)}function D(e,t,n,r,o,s){let a={trackID:n,segmentID:r,compareToFromSame:o[e][n]??null},l=t===null?void 0:s[e].get(t);if(l===void 0){let i={type:"single",node:t,tracks:[a]};Me[e].push(i),t!==null&&s[e].set(t,i)}else l.type="multiple",l.tracks.push(a);o[e][n]=a}function ka(e,t){let n;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(y[o.trackID].path[o.segmentID-1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<y[o.trackID].path.length-1&&y[o.trackID].path[o.segmentID+1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID+1].y;else{for(n=o.segmentID-1;n>=0&&y[o.trackID].path[n].order!==t-1;)n-=1;n<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=y[o.trackID].path[n].lane??void 0,o.idealY=y[o.trackID].path[n].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Ba(e,t){let n=0,r=new Set,o=20,s=!1,a=-1;ka(e,t),e.sort(Io),e.forEach(l=>{l.node!==null?(x[l.node].topLane=n,s&&(o-=10),x[l.node].y=o,x[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(Io),l.tracks.forEach(i=>{i.lane=n,i.trackID===a&&l.node===null&&s&&(o+=10),y[i.trackID].path[i.segmentID].lane=n,y[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),n+=1,o+=y[i.trackID].width,l.node!==null&&(x[l.node].contentHeight+=y[i.trackID].width),a=i.trackID}),o+=25}),$a(e,r)}function $a(e,t){let n=0,r=Number.MAX_SAFE_INTEGER;t.forEach(o=>{_o(e,o)<r&&(r=_o(e,o),n=o)}),e.forEach(o=>{o.node!==null&&(x[o.node].y+=n),o.tracks.forEach(s=>{let a=y[s.trackID].path[s.segmentID];a.y=a.y+n})})}function Ga(e,t){e.order<0||Me[e.order]===void 0||(Me[e.order].forEach(n=>{if(n.node!==null){let r=x[n.node];r!==e&&r.y>e.y&&(r.y+=t,n.tracks.forEach(o=>{let s=y[o.trackID].path[o.segmentID];s.y=s.y+t}))}else n.tracks.forEach(r=>{let o=y[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+t)})}),We[e.order].length>0&&We[e.order].forEach(n=>{x[n]!==e&&x[n].y>e.y&&(x[n].y+=t)}))}function _o(e,t){let n=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&y[o.trackID].type!=="read"&&(n+=Math.abs(o.idealY-t-y[o.trackID].path[o.segmentID].y)*y[o.trackID].width)})}),n}function Io(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function Et(e,t){if(!e)return t?-1:0;if(!t)return 1;if(e.order!==void 0){if(t.order!==void 0){if(e.order<t.order)return-1;if(e.order>t.order)return 1;if(e.y!==void 0&&t.y!==void 0){if(e.y<t.y)return-1;if(e.y>t.y)return 1}return 0}return-1}return t.order!==void 0?1:0}function Fa(){let e,t,n={};tn.forEach(r=>{let o=0;for(;o<y.length&&y[o].name!==r.track;)o+=1;o<y.length&&(e=0,y[o].path.forEach(s=>{s.node!==null&&(n={},t=e+x[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(n.start=0),e<r.start&&t>=r.start&&(n.start=r.start-e),t<=r.end&&t>=r.start&&(n.end=t-e,t<r.end&&(n.continue=!0)),t>r.end&&e<=r.end&&(n.end=r.end-e),n.start!==void 0&&(n.type=r.type,n.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(n)),e=t+1)}))})}function Wa(){let e=!0,t=4,n=_.trackWidth;y.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*t):(r.width=n,r.type!==void 0&&r.type==="read"&&(r.width=t)),r.width!==t&&(e=!1)}),e&&y.forEach(r=>{r.freq!==void 0&&(r.width=n)})}function Da(e){let t=e.path[0],n=x[t.node],r=e.firstNodeOffset??0;return an(n,t.isForward?r:n.sequenceLength-r)}function qa(e){let t=e.path[e.path.length-1],n=x[t.node],r=e.finalNodeCoverLength??0;return an(n,t.isForward?r:n.sequenceLength-r)}function Do(e,t){return t>e.sequenceLength?null:an(e,t)}function an(e,t){let[n,r]=Ya(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(r-n)}function Ha(){let e,t,n,r,o,s,a,l,i;for(let u=0;u<=V;u+=1)on.push(0),rn.push(0);let c=[],d=[];x.forEach(u=>{u.x!==void 0&&(c[u.order]=u.x,d[u.order]===void 0?d[u.order]=u.x+u.pixelWidth:d[u.order]=Math.max(d[u.order],u.x+u.pixelWidth))}),y.sort(ga),y.forEach(u=>{a="plain",o=Fe(u,a),s=ia(u);let f=a,h=()=>(f!==a&&(f=a,o=Fe(u,a)),o);n=u.path[0].y,u.type!=="read"?u.sequence[0].startsWith("-")?e=d[u.path[0].order]+20:e=c[u.path[0].order]-20:e=Da(u);for(let p=0;p<u.path.length;p+=1)u.path[p].y===n?u.path[p].features!==void 0&&(i=p>0&&u.path[p-1].order===u.path[p].order,l=Po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart):(u.path[p-1].isForward?t=d[u.path[p-1].order]:t=c[u.path[p-1].order],t!==e&&(o=h(),B.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})),u.path[p].order-1===u.path[p-1].order?(e=t,t=c[u.path[p].order],r=u.path[p].y,o=h(),B.curves.push({xStart:e,yStart:n,xEnd:t+1,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p].order+1===u.path[p-1].order?(e=t,t=d[u.path[p].order],r=u.path[p].y,o=h(),B.curves.push({xStart:e+1,yStart:n,xEnd:t,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p-1].isForward?(r=u.path[p].y,ko(1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=d[u.path[p].order],n=u.path[p].y):(r=u.path[p].y,ko(-1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=c[u.path[p].order],n=u.path[p].y),u.path[p].features!==void 0&&(i=u.path[p-1].order===u.path[p].order,l=Po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart));u.type!=="read"?u.path[u.path.length-1].isForward?t=d[u.path[u.path.length-1].order]+20:t=c[u.path[u.path.length-1].order]-20:t=qa(u),B.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})})}var Xa=1e9;function vo(e,t){wt=new Map;let n=new Map,r=_.ignoreStrand;for(let f of e){let h=f.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],g=h[p+1],b=Math.abs(m),w=Math.abs(g),S=x[b],E=x[w];if(!S||!E)continue;let T;if(r){let N=`${m}>${g}`,I=`${-g}>${-m}`;T=N<I?N:I}else T=`${m}>${g}`;let R=n.get(T);R===void 0?n.set(T,{sSigned:m,dSigned:g,sName:m<0?`-${S.name}`:S.name,dName:g<0?`-${E.name}`:E.name,count:1,sourceTrackID:f.sourceTrackID}):R.count+=1}}let o=0;for(let f of n.values())f.count>o&&(o=f.count);let s=Rt,a=60,l=f=>o<=1?s:s+(a-s)*Math.sqrt(f/o),i=[],c=0;for(let f of n.values()){let h=Xa+c,p=`${f.count.toLocaleString()} ${t}${f.count===1?"":"s"}: Node ${f.sName} \u2192 Node ${f.dName}`;wt.set(h,{count:f.count,label:p});let m=x[Math.abs(f.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:f.sourceTrackID,type:"read",name:p,sequence:[f.sName,f.dName],indexSequence:[],path:[],width:l(f.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:f.sName,mismatches:[]},{nodeName:f.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:f.count}),c+=1}let d="?",u=0;for(let f of x){if(!f)continue;let h=f.contentHeight;h>u&&(u=h,d=f.name)}return et&&console.log(`[coarsened] ${t}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${d}(${u.toFixed(1)})`),i}function Po(e,t,n,r,o,s,a,l,i){let c=r,d,u,f,h;t-=8,n+=8;let p=x[e.node].sequenceLength;return e.features.sort((m,g)=>m.start-g.start),e.features.forEach(m=>{c!==m.type&&(d=Fe(o,c),e.isForward?(f=t+Math.round(m.start*(n-t+1)/p),i&&f<t+8&&(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,u=Fe(o,m.type),B.featureRectangles.push({xStart:f,yStart:a,xEnd:h,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),f>s+1&&B.featureRectangles.push({xStart:s,yStart:a,xEnd:f-1,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(f=n-Math.round(m.start*(n-t+1)/p),i&&f>n-8&&(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,u=Fe(o,m.type),B.featureRectangles.push({xStart:h,yStart:a,xEnd:f,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),s>f+1&&B.featureRectangles.push({xStart:f+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=f,c=m.type),(m.end<p-1||m.continue===void 0)&&(d=Fe(o,c),e.isForward?(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,B.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,B.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=h+1,c="plain")}),{xStart:s,highlight:c}}var Oo=7;function ko(e,t,n,r,o,s,a,l,i,c){let d=e===1?rn:on,u=10*d[l],f=t+e*(u+5),h=Oo,p=Math.min(Oo,o),m=Math.min(n,r),g=Math.max(n,r),b=e===1?t:f-1,w=e===1?f:t,S=N=>{B.verticalRectangles.push({xStart:b,yStart:N,xEnd:w,yEnd:N+o-1,color:s,id:a,name:c,type:i})};S(n),B.verticalRectangles.push({xStart:e===1?f+h:f-h-p,yStart:m+o+h-1,xEnd:e===1?f+h+p-1:f-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),S(r);let E=f+e*h,T=f+e*(h+p),R=`M ${f} ${g}`;R+=` Q ${E} ${g} ${E} ${g-h}`,R+=` H ${T}`,R+=` Q ${T} ${g+o} ${f} ${g+o}`,R+=" Z ",B.corners.push({path:R,color:s,id:a,type:i}),R=`M ${f} ${m}`,R+=` Q ${T} ${m} ${T} ${m+o+h}`,R+=` H ${E}`,R+=` Q ${E} ${m+o} ${f} ${m+o}`,R+=" Z ",B.corners.push({path:R,color:s,id:a,type:i}),d[l]+=1}function Ya(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function Bo(){switch(x.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),_.nodeWidthOption){case"compressed":x.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":x.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":x.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=_.charWidth;x.forEach(t=>{t.width=t.sequenceLength;let n=t.seq?.length??1;t.pixelWidth=Math.round(e*n)});break}default:throw new Error(`${_.nodeWidthOption} not implemented`)}}function za(){let e,t,n=Array.from(x,()=>new Set),r=Array.from(x,()=>new Set),o;_.showReads&&M.length>0?o=y.concat(M):o=y,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)q(l.sequence[i])?(e=v(l.sequence[i]),i>0?(t=l.sequence[i-1],q(t)?r[C.get(e)].add(v(t)):(r[C.get(e)].add(t),r[C.get(e)].add(de(t)))):l.type==="haplotype"&&r[C.get(e)].add("None"),i<l.sequence.length-1?(t=l.sequence[i+1],q(t)?n[C.get(e)].add(v(t)):(n[C.get(e)].add(t),n[C.get(e)].add(de(t)))):l.type==="haplotype"&&n[C.get(e)].add("None")):(i>0?(e=l.sequence[i-1],n[C.get(l.sequence[i])].add(e),q(e)&&n[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&n[C.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[C.get(l.sequence[i])].add(e),q(e)&&r[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&r[C.get(l.sequence[i])].add("None"))});let s=n.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(_.showReads&&M.length>0){let l=x.slice();l.sort(Et);let i=new Map,c=new Map,d=f=>{let h=i.get(f);if(h===void 0)throw new Error(`No merge offset recorded for node ${f}`);return h},u=f=>{let h=c.get(f);if(h===void 0)throw new Error(`No merge origin recorded for node ${f}`);return h};l.forEach(f=>{let h=Je(C.get(f.name),s,a);if(h){let p=d(h)+oe(h).sequenceLength;i.set(f.name,p),i.set(de(f.name),p),c.set(f.name,u(h)),c.set(de(f.name),u(h))}else i.set(f.name,0),i.set(de(f.name),0),c.set(f.name,f.name),c.set(de(f.name),f.name)}),M.forEach(f=>{let h=f.sequenceNew??[];f.firstNodeOffset=(f.firstNodeOffset??0)+d(f.sequence[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+d(f.sequence[f.sequence.length-1]);for(let p=f.sequence.length-1;p>=0;p-=1){let m=v(f.sequence[p]),g=Je(C.get(m),s,a);if(g&&en(C.get(g),s,a))if(p>0){f.sequence.splice(p,1);let b=oe(g).sequenceLength;h[p].mismatches.forEach(w=>{w.pos+=b}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{f.sequence[0]=u(f.sequence[0]);let b=h[0],w=d(b.nodeName);b.mismatches.forEach(S=>{S.pos+=w}),b.nodeName=u(b.nodeName)}}})}for(let l=0;l<x.length;l+=1)if(en(l,s,a)&&!Je(l,s,a)){let i=l;for(;en(i,s,a);)i=C.get(v(a[i][0])),x[l].sequenceLength+=x[i].sequenceLength,x[l].seq+=x[i].seq}y.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=v(l.sequence[i]);let c=C.get(e);Je(c,s,a)&&l.sequence.splice(i,1)}});for(let l=x.length-1;l>=0;l-=1)Je(l,s,a)&&x.splice(l,1)}function Je(e,t,n){if(t[e].length!==1||t[e][0]==="None")return!1;let r=v(t[e][0]),o=C.get(r);return n[o].length!==1||n[o][0]==="None"?!1:r}function en(e,t,n){if(n[e].length!==1||n[e][0]==="None")return!1;let r=v(n[e][0]),o=C.get(r);return!(t[o].length!==1||t[o][0]==="None")}function Ka(e){let t=_.focusReadNames?new Set(_.focusReadNames):null;return e.filter(n=>n.is_secondary!==!0&&(n.mapping_quality??0)>=_.mappingQualityCutoff&&(t===null||n.name!==void 0&&t.has(n.name)))}function ja(e,t){let n=new Map;for(let r of e){let o=t(r),s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}return n}function Ua(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function qo(e,t){let n=ja(e.filter(s=>s.type===t),s=>`${s.nodeStart},${s.nodeEnd}`);n.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Ua),s.forEach(i=>{let c,d;i.yStart<i.yEnd?(c=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,d=i.xStart+(i.xEnd-i.xStart)*(1-a)):(c=i.xStart+(i.xEnd-i.xStart)*a,a+=l,d=i.xStart+(i.xEnd-i.xStart)*a);let u=`M ${i.xStart} ${i.yStart}`;u+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,u+=` V ${i.yEnd+i.width}`,u+=` C ${d} ${i.yEnd+i.width} ${d} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,u+=" Z",i.path=u})});let r=Array.from(n.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),c=l[0]??0,d=l[1]??0,u=i[0]??0,f=i[1]??0;return c<u?-1:c>u?1:d<f?-1:d>f?1:0});let o=[];for(let s of r){let a=n.get(s);a!==void 0&&o.push(...a)}return o}function Ho(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,r=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n+9} ${r} ${n+9} ${r+9}`,n+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,t+=` L ${n} ${r}`),t+=` Q ${n} ${r+9} ${n-9} ${r+9}`,n-=9,r+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n-9} ${r} ${n-9} ${r-9}`,n-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,t+=` L ${n} ${r}`),t}function Va(e){let t=new Map;for(let[n,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${n}`,a=t.get(s);a?a.push(o.strand):t.set(s,[o.strand])}return t}function Qa(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=Va(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>le(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=le(s.name).name,i=new Map,c=s.nodeIds.flatMap(d=>{let u=t.get(d);if(!u)return[];let f=i.get(u.name)??0;i.set(u.name,f+1);let h=n.get(`${l} ${u.name}`)?.[f]??Kt(u);return[jt(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Za(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function De(e){return(e.paths?.length??0)>0}var Ja=600,ei=3,ti=15;function ni(e){return Math.max(ei,Math.min(ti,Math.floor(Ja/Math.max(1,e))))}function Xo(e){let t=e.paths??[],n=Qa(e),r=e.reads?uo(e,e.reads,t.length):[],o=r.length>0?kn:On,s=t.map((l,i)=>o(i,t.length)),a=Go(Za(e),n,r,{nodeWidthOption:"compressed",trackWidth:ni(n.length),trackColor:l=>l.type==="read"?fo(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function ln(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function Yo(e,t,n,r){let o=e.y+e.contentHeight/2-t;return[{x:n,y:o},{x:r,y:o}]}function zo(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function Ko(e){let t=De(e)?Xo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=n.bounds.minY,s={};for(let i of ln(n))s[i.name]=Yo(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=zo(n,o);return{nodePositions:s,tubeMap:{layout:n,yOffset:o,pathColors:r},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:l}}}function oi(e,t){let n=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of ln(t)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,c)=>i-c)){let i=r.get(l),c=1/0,d=-1/0;for(let u of i){let f=n.get(u.name);f&&O(f)&&(c=Math.min(c,f.stable.start),d=Math.max(d,f.stable.start+u.sequenceLength))}c===1/0&&(c=d=s),c<s&&(c=s,d=Math.max(s,d)),s=Math.max(s,d),o.push({order:l,x0:Math.min(...i.map(u=>u.x)),x1:Math.max(...i.map(u=>u.x+u.pixelWidth)),bp0:c,bp1:d})}let a=o.find(l=>l.bp0!==-1/0);for(let l of o)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return o}function ri(e){return e.nodes.some(O)&&De(e)}function jo(e){let t=ri(e)?Xo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=oi(e,n),s=new Map(o.map(i=>[i.order,i])),a=n.bounds.minY,l={};for(let i of ln(n)){let c=s.get(i.order);l[i.name]=Yo(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:n,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:zo(n,a)}}function Uo(e){return e.sample??lt(e.name)}function si(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Uo(e)}function ai(e,t){let n=[],r;for(let o of e){r!==void 0&&o.start!==void 0&&o.start>r&&n.push(o.start-r),n.push(...o.nodeIds);let s=o.nodeIds.reduce((a,l)=>a+(t.get(l)??0),0);r=o.start===void 0?void 0:o.start+s}return n}function ii(e,t){let n=[],r;for(let o of e){if(o.start===void 0||r!==void 0&&o.start<r)return;r!==void 0&&o.start>r&&n.push({start:r,end:o.start});let s=o.start;for(let a of o.nodeIds){let l=t.get(a)??0;n.push({start:s,end:s+l}),s+=l}r=s}return n}function li(e,t,n,r=!0){if(!n||!r)return{ids:e,complete:!0,from:-1,to:-1};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((c,d)=>{let u=typeof c=="string"?t.get(c):void 0;u&&(u.end<=n.start&&u.end>a&&(a=u.end,o=d),u.start>=n.end&&u.start<l&&(l=u.start,s=d))}),o<0||s<0)return{ids:e,complete:!1,from:-1,to:-1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0,from:o,to:s}}function Vo(e,t,n){let r=e.paths??[],o=g=>le(g.name).name===e.referencePath,s=r.some(o)?r.filter(o).sort((g,b)=>(g.start??0)-(b.start??0)):r.slice(0,1),a=s[0],l=r.filter(g=>!s.includes(g));if(!a||l.length===0)return;let i=new Map;for(let g of l)i.set(g.name,[...i.get(g.name)??[],g]);let c=new Map(e.nodes.map(g=>[g.id,g.length])),d=a.start??0,u=t&&t.end>t.start?t:void 0,f=new Map;for(let g of s){let b=g.start??0;for(let w of g.nodeIds){let S=c.get(w)??0;f.has(w)||f.set(w,{start:b,end:b+S}),b+=S}}let h=u===void 0||[...f.values()].some(g=>g.end<=u.start)&&[...f.values()].some(g=>g.start>=u.end),p=g=>{let b=g[0],w=[...g].sort((K,Z)=>(K.start??0)-(Z.start??0)),{ids:S,complete:E,from:T,to:R}=li(ai(w,c),f,u,h),N=ii(w,c),I=b.contig??ct(le(b.name).name),H=N?.length?T<0?{contig:I,start:N[0].start,reversed:!1}:T<R?{contig:I,start:N[T].end,reversed:!1}:{contig:I,start:N[T].start,reversed:!0}:void 0,F=[],z=0,Se=0,pe=0,Q=0;for(let K of S){if(typeof K=="number"){F.push({start:z,bp:K,onReference:!1,gap:!0}),z+=K,pe+=K,Q=0;continue}let Z=c.get(K)??0,j=f.get(K),U=F.at(-1),Ne=U?.referenceStart,A=j&&Ne!==void 0&&Q>=0&&Ne+U.bp===j.start,P=j&&Ne!==void 0&&Q<=0&&j.end===Ne;!j&&U&&!U.onReference&&!U.gap?U.bp+=Z:A||P?(U.bp+=Z,A||(U.referenceStart=j.start,U.reversed=!0),Q=A?1:-1):(F.push({start:z,bp:Z,onReference:j!==void 0,referenceStart:j?.start}),Q=0),z+=Z,j||(Se+=Z)}return{name:b.name,label:si(b),sample:Uo(b),haplotype:b.haplotype,bp:z,offReferenceBp:Se,gapBp:pe,complete:E,runs:F,axis:H}};return{origin:u?u.start:d,unit:n,reference:p(s),rows:[...i.values()].map(p).sort((g,b)=>Number(b.complete)-Number(g.complete)||b.bp-g.bp||g.label.localeCompare(b.label))}}var ci=1.3;function ui(e){let t=e.reference.bp;for(let n of e.rows)t=Math.max(t,n.bp);return{maxX:e.origin+t*ci,maxY:e.rows.length*20}}function Qo(e,t){let n=ve(e),r=Vo(e,t);if(n.length===0||!r)return;let o=t?n.filter(l=>yn(l,t)):n,s=Pe(o.length>0?o:n),a=[{label:r.reference.label,y:0},...r.rows.map((l,i)=>({label:l.label,y:(i+1)*20}))];return{nodePositions:s,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:ui(r)}}var di="Force-directed layout",Re=e=>e.nodes.some(O),Zo=e=>Re(e)&&(e.paths?.length??0)>1,Jo=e=>Re(e)&&De(e),er=e=>Re(e)&&e.nodes.some(ut),cn=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:mo,cutMargins:!0,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:wo,cutMargins:!0,wholeWalks:!1,available:er,drawsLocally:er,drawsNodes:!0},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, blue on the reference's path and purple off it, so a repeat expansion reads as bar length, and each bar boxes its haplotype's own genes where the session has them. Needs W or P lines.",run:Qo,cutMargins:!1,wholeWalks:!0,available:Zo,drawsLocally:Zo,drawsNodes:!1},{value:"ordered",label:"Ordered",description:"x is reference order, not bp: every node gets room, bubbles read as lenses. Needs rGFA tags or a reference path.",run:yo,cutMargins:!1,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:Ko,cutMargins:!1,wholeWalks:!1,available:De,drawsLocally:De,drawsNodes:!1},{value:"tubemapref",label:"Tube map on reference",description:"The tube map with each column at the reference bp it covers, so the tubes line up with the tracks around them. Needs P or W lines and a reference path.",run:jo,cutMargins:!0,wholeWalks:!1,available:Jo,drawsLocally:Jo,drawsNodes:!1},{value:"force",label:di,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],cu=cn.map(e=>e.value);function uu(e,t){return!fi(e).drawsLocally(t)}function fi(e){return cn.find(t=>t.value===e)??cn[0]}var pi=10;function hi(e,t){let n=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>r<=pi*(o.end-o.start)&&(n===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=n/2))}var mi=40;function Ee(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function gi(e,t){let n=Ee(e),r=Ee(t),o=r.slice(r.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${r}`:`${n}\u2013${r}`}function tr(e){return e>=Bn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function pu(e,t=[]){let n=bi(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function bi(e,t){let n=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=gi(r,o);if(a>=mi)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${tr(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Ee(o)} inv`};let c=o!==r?hi(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${tr(s)}`}}let d=s>2?`, ${s} alleles`:"";return r===o&&r===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Ee(n)} sub`}:n===0||r===n?{kind:"insertion",label:`\u2264${Ee(o-n)} ins${d}`}:o===n?{kind:"deletion",label:`${Ee(n-r)} del${d}`}:{kind:"complex",label:`${Ee(n)} ref \u2192 ${i}, ${s} alleles`}}var hu={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},mu={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function gu(e){return e.segments.split(",").filter(Boolean)}function xu({count:e,bounds:t,pixelRows:n,width:r,room:o,columns:s}){function a(i){let c=Math.ceil(e/i),d=Math.floor((r-(i-1)*8)/i),u=(o-c*34-(c-1)*8)/c,f=(d-24)/t.w,h=t.h>0?(u-24)/t.h:1/0,p=n?f:Math.min(f,h),m=n?t.h:t.h*p,g=Math.floor(Math.max(60,Math.min(m+24,u)));return{columns:i,width:d,height:g,scale:p,total:c*(g+34)+(c-1)*8}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let l=a(1);for(let i=2;i<=e;i++){let c=a(i);c.scale>l.scale&&(l=c)}return l}function yu(e){let t=typeof e=="string"?{field:e}:e??{};return{field:t.field==="walk"||t.field==="sample"?t.field:"",domain:[...t.domain??[]],...t.columns===void 0?{}:{columns:t.columns}}}function nr(e,t){let n=new Map(t.map((o,s)=>[o,s])),r=o=>n.get(o)??t.length;return e.map((o,s)=>({name:o,i:s})).sort((o,s)=>r(o.name)-r(s.name)||o.i-s.i).map(({name:o})=>o)}function wu(e,t,n=[]){let r=nr(e,n),o={columns:void 0,count:e.length,cells:e.map(c=>r.indexOf(c))};if(t==="walk")return o;let s=e.map(c=>{let[d,u,f]=c.split("#"),h=Number(u);return f!==void 0&&Number.isInteger(h)&&h>=0?{sample:d,column:Math.max(0,h-1)}:void 0}),a=nr([...new Set(s.flatMap(c=>c?[c.sample]:[]))],n),l=Math.max(1,...s.map(c=>c?c.column+1:1)),i=s.map(c=>c?a.indexOf(c.sample)*l+c.column:-1);return i.includes(-1)||new Set(i).size<i.length?o:{columns:l,count:a.length*l,cells:i}}function k(e,t={},...n){return{tag:e,attrs:t,children:n.filter(r=>!!r||r==="")}}function or(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function xi(e){return or(e).replaceAll('"',""")}function yi(e){if(typeof e=="string")return or(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,r])=>` ${n}="${xi(String(r))}"`).join("");return`<${e.tag}${t}>${e.children.map(yi).join("")}</${e.tag}>`}var dn="#2f8fd6",sr="#8e3fbf",ar="#bdbdbd",St="#1c1c22",nt=12,ir=4,wi=3;function tt(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function rr(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function Mi(e,t,n,r){let{bp:o,gapBp:s,complete:a}=e;if(!t)return`${tt(o)}${rr(o,n)}`;let l=o-t.bp,i=l===0?"":` (${l>0?"+":"\u2212"}${tt(Math.abs(l))})`,c=s>0?` \xB7 ${tt(s)} outside the cut`:"",d=r?` \xB7 called ${tt(r.bp)}${r.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${tt(o)}${rr(o,n)}${i}${c}${a?"":" \xB7 partial walk"}${d}`}function Ri(e,t,n){let r=t+6;return r+e.length*6.2<n?{x:r,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Ei(e,t,n){if(t*n<wi)return[];let r=[];for(let o=t;o<e;o+=t)r.push(o);return r}function Si(e,t){if(e.gap)return{fill:ar};if(!t)return{fill:e.onReference?dn:sr};if(e.referenceStart===void 0)return{fill:Dt};let n=to({...e,start:e.referenceStart},t);return n.length===1?{fill:bt(n[0])}:{stops:n.map(bt)}}function Nt(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function Cu(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function Au(e,t){let n=new Map;for(let r of e){let o=t.get(r.name);if(!r.axis||!o)continue;let s=r.axis,a=({start:l,end:i})=>({start:Math.max(0,l),end:Math.min(r.bp,i)});n.set(r.name,o.map(l=>({name:l.name,...a(Nt(s,l.start,l.end)),exons:l.exons.map(i=>a(Nt(s,i.start,i.end))).filter(i=>i.end>i.start)})).filter(l=>l.end>l.start).sort((l,i)=>l.start-i.start))}return n}var Ni=9,Li=5.2;function Ti(e,t,n){let r=e.map(a=>{let l=t(a.start);return{g:a,x:l,w:Math.max(2,t(a.end)-l)}}),o=[],s=new Set([...r].sort((a,l)=>a.w-l.w).filter(({g:a,x:l,w:i})=>{let c=a.name.length*Li/2,d=[l+i/2-c,l+i/2+c];return 2*c>i+6||o.some(([u,f])=>d[0]<f+2&&d[1]>u-2)?!1:(o.push(d),!0)}));return r.map(a=>({name:a.g.name,x:a.x,y:n-nt/2-2,w:a.w,h:nt+4,exons:a.g.exons.map(l=>({x:t(l.start),w:Math.max(1,t(l.end)-t(l.start))})),label:s.has(a)?{x:a.x+a.w/2,y:n+3,size:Ni}:void 0}))}var un=e=>`${e} row${e===1?"":"s"}`;function _u(e,t={}){let n=[{swatch:{kind:"bar",fill:t.ramp?t.rampCss??dn:dn},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Dt:sr},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(r=>r.gapBp>0)&&n.push({swatch:{kind:"gap",fill:ar},label:"walked outside the cut"}),t.genes&&(n.push({swatch:{kind:"gene"},label:"genes, each row's own annotation"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${un(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${un(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${un(t.genes.unread)}`,note:!0})),n}var Ci="#111",Ai="#9e9e9e",_i="#c62828";function Iu(e,t,n){let r=0,o=e.flatMap(s=>{let a=s.note?void 0:s.swatch.kind==="gene"?k("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:St,"stroke-width":1.5}):k("rect",{x:r,y:s.swatch.kind==="gap"?7:5,width:18,height:s.swatch.kind==="gap"?ir:8,rx:2,fill:s.swatch.fill}),l=k("text",{x:s.note?r:r+23,y:13,"font-style":s.note?"italic":void 0,fill:s.note?"#666":void 0},s.label);return r+=(s.note?0:23)+s.label.length*6.2+16,a?[a,l]:[l]});return{width:r,tree:k("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...o)}}function Ii(e,t){let n=1/t,r=[],o=[],s=()=>{if(o.length!==0){if(o.length===1)r.push(o[0]);else{let l=0,i=0;for(let u of o)u.onReference?l+=u.bp:i+=u.bp;let c=l>=i,d=o.find(u=>u.onReference===c);r.push({start:o[0].start,bp:l+i,onReference:c,referenceStart:c?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}o=[]}},a=0;for(let l of e){if(l.gap||l.bp>=n){s(),a=0,r.push(l);continue}o.push(l),a+=l.bp,a>=n&&(s(),a=0)}return s(),r}function vi(e,t){return k("g",{class:"row-gene","data-testid":"graph-walk-gene"},k("title",{},e.name),...e.exons.map(n=>k("rect",{x:n.x,y:t-nt/2,width:n.w,height:nt,fill:St,opacity:.35})),k("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:St,"stroke-width":1.5}),e.label&&k("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:St,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function vu(e,t,n={}){let r=p=>p*t.scaleX+t.translateX,o=t.rowPx??20,s=t.barPx??nt,a=p=>p*o*t.scaleY+t.translateY,{origin:l,unit:i,reference:c,rows:d}=e,u=p=>r(l+p),f=n.idPrefix??"walkrow",h=(p,m)=>{let g=a(m);if(g<-s||g>t.height+s)return;let b=Ii(p.runs,t.scaleX).flatMap(N=>{let I=Si(N,n.ramp),H=N.gap?Math.min(ir,s):s,F=`${f}-${m}-${N.start}`,z=k("rect",{x:u(N.start),y:g-H/2,width:Math.max(1,N.bp*t.scaleX),height:H,fill:"stops"in I?`url(#${F})`:I.fill});return"stops"in I?[k("linearGradient",{id:F},...I.stops.map((Se,pe)=>k("stop",{offset:pe/(I.stops.length-1),"stop-color":Se}))),z]:[z]}),w=i?Ei(p.bp,i,t.scaleX).map(N=>k("line",{x1:u(N),x2:u(N),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:S}=p,E=Mi(p,m===0?void 0:c,i,S),T=Ri(E,u(p.bp),t.width),R=t.readouts??!0;return k("g",{"data-testid":m===0?"graph-walk-reference":"graph-walk-row"},...b,...w,...Ti(n.rowGenes?.get(p.name)??[],u,g).map(N=>vi(N,g)),S&&k("rect",{"data-testid":"graph-walk-call",x:u(S.bp)-1,y:g-s/2-3,width:2,height:s+6,fill:S.spanningReads===0?Ai:Ci}),R&&k("text",{x:T.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:S?.agrees===!1?_i:"#333",stroke:T.halo?"white":void 0,"stroke-width":T.halo?3:void 0,"paint-order":"stroke","text-anchor":T.anchor},E))};return k("g",{},...[c,...d].map(h))}var qe=Y(Oe(),1),pr=Y(cr(),1),hr=Y(dr(),1);var fr=class extends hr.Canvas2DRenderingBackendBase{constructor(){super(...arguments);this.transform=null;this.batch=null;this.nodeHighlights=new Map;this.highlightedEdge=null;this.highlightFactor=1}resize(n,r){(0,pr.syncCanvasSize)(this.ctx.canvas,n,r)}uploadGeometry(n){this.batch=n,this.highlightedEdge=null}setNodeHighlights(n){this.nodeHighlights=n}setEdgeHighlight(n,r){this.highlightedEdge=n,this.highlightFactor=r}updateTransform(n){this.transform=n}render(n){if(!this.transform)return;let o=this.ctx,{width:s,height:a}=o.canvas;n[3]<1&&o.clearRect(0,0,s,a),o.fillStyle=(0,qe.normalizedRgbToCssRgba)([n[0],n[1],n[2]],n[3]),o.fillRect(0,0,s,a);let l=this.batch;l&&(o.lineCap="round",o.lineJoin="round",this.renderEdges(l),this.renderNodes(l),this.renderArrows(l))}renderEdges(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.edgeCurveRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.edgeCurves,(i,c)=>({color:Lt(s,c)?mt(i.color,this.highlightFactor):i.color,weight:i.thickness,last:Lt(s,c)}))){o.strokeStyle=(0,qe.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.curves[0];o.moveTo(c.x0*r.scaleX+r.translateX,c.y0*r.scaleY+r.translateY);for(let d of i.curves)o.bezierCurveTo(d.cx0*r.scaleX+r.translateX,d.cy0*r.scaleY+r.translateY,d.cx1*r.scaleX+r.translateX,d.cy1*r.scaleY+r.translateY,d.x1*r.scaleX+r.translateX,d.y1*r.scaleY+r.translateY)}o.stroke()}}renderNodes(n){let r=this.transform,o=this.ctx,s=new Map;for(let[a,l]of this.nodeHighlights){let i=n.nodeStrokeRuns.get(a);if(i)for(let c=i.start;c<i.start+i.count;c++)s.set(c,l)}for(let{color:a,items:l}of fn(n.nodeStrokes,(i,c)=>{let d=s.get(c);return{color:d===void 0?i.color:mt(i.color,d),weight:i.thickness,last:d!==void 0}})){o.strokeStyle=(0,qe.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.points[0];o.moveTo(c.x*r.scaleX+r.translateX,c.y*r.scaleY+r.translateY);for(let d=1,u=i.points.length;d<u;d++){let f=i.points[d];o.lineTo(f.x*r.scaleX+r.translateX,f.y*r.scaleY+r.translateY)}}o.stroke()}}renderArrows(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.arrowRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.arrows,(i,c)=>({color:Lt(s,c)?mt(i.color,this.highlightFactor):i.color,weight:0,last:Lt(s,c)}))){o.fillStyle=(0,qe.abgrToCssRgba)(a),o.beginPath();for(let i of l){let[c,d,u,f]=Oi(i,r);o.moveTo(c.x,c.y),o.lineTo(d.x,d.y),o.lineTo(u.x,u.y),o.lineTo(f.x,f.y),o.closePath()}o.fill()}}dispose(){super.dispose(),this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},Pi=.25;function Oi(e,t){let n=Math.cos(e.angle),r=Math.sin(e.angle),o=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,l=e.halfWidth*t.dpr,i=o-n*a,c=s-r*a,d=a*(1-Pi);return[{x:o,y:s},{x:i-r*l,y:c+n*l},{x:o-n*d,y:s-r*d},{x:i+r*l,y:c-n*l}]}function Lt(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function fn(e,t){let n=new Map,r=new Map;for(let o=0,s=e.length;o<s;o++){let a=e[o],{color:l,weight:i,last:c}=t(a,o),d=c?r:n,u=`${l}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:l,items:[a]})}return[...n.values(),...r.values()]}var yr=Y(Oe(),1);var ki=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],wr=[{value:"grey",label:"Grey to black",ends:["#a3a3a3","#151515"]},{value:"blue",label:"Cyan to navy",ends:["#6ee0f0","#0b2c7a"]},{value:"red",label:"Yellow to red",ends:["#ffd24a","#b3121b"]},{value:"purple",label:"Pink to plum",ends:["#f5a3d8","#5e1a6e"]},{value:"green",label:"Lime to forest",ends:["#b6e36c","#0b5d3b"]},{value:"rainbow",label:"Rainbow"}],mr=["blue","red","purple","green"],Bi=e=>ki.some(t=>t.value===e),$i=e=>wr.some(t=>t.value===e);function Fu(e,t,n,r=!0){let{field:o,scheme:s}=e.color??{},a=Bi(o)?o:r?"progress":"walk",l=t?"grey":mr[n%mr.length],i=$i(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var Mr=.5,Gi=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Fi=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function gr(e){let[t,n,r]=[1,3,5].map(l=>Gi(Number.parseInt(e.slice(l,l+2),16)/255)),o=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*r),s=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*r),a=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*r);return[.2104542553*o+.793617785*s-.0040720468*a,1.9779984951*o-2.428592205*s+.4505937099*a,.0259040371*o+.7827717662*s-.808675766*a]}function Wi([e,t,n]){let r=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s].map(a=>Fi(Math.max(0,Math.min(1,a)))*255)}function Rr(e,t){let n=Math.max(0,Math.min(1,t)),r=wr.find(a=>a.value===e);if(!r||!("ends"in r))return Be(n*$e,.7,.5).map(a=>a*255);let o=gr(r.ends[0]),s=gr(r.ends[1]);return Wi(o.map((a,l)=>a+(s[l]-a)*n))}function br(e,t){let[n,r,o]=Rr(e,t).map(Math.round);return`rgb(${n}, ${r}, ${o})`}function xr(e,t){let[n,r,o]=Rr(e,t).map(Math.round);return(0,yr.packAbgr)(n,r,o,255)}function Wu({field:e,scheme:t},n){return e==="walk"?xr(t,Mr):n===void 0?Di:xr(t,n)}var Di=Wt;function qi({field:e,scheme:t}){return e==="walk"?[{offset:0,color:br(t,Mr)}]:Array.from({length:7},(n,r)=>({offset:r/6,color:br(t,r/6)}))}function Du(e){let t=qi(e);return t.length===1?t[0].color:`linear-gradient(to right, ${t.map(n=>`${n.color} ${n.offset*100}%`).join(", ")})`}function Er(e,t,n){let r=Math.round(t),o=Math.round(n);return`${e?`${e}:`:""}${Ue(r)}-${Ue(o)} (${xe(o-r)})`}function Xu(e,t){let{field:n}=e.encoding,r=e.range?Er(e.range.contig,e.range.start,e.range.end):void 0,o=n==="progress"?r:n==="reference"&&t?Er(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${xe(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${xe(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${xe(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:o,hover:o===r?void 0:r}}function Yu(e,t,n){let r=e.progress.get(t),o=e.range;if(r===void 0||!o)return;let s=Math.round(o.start+r*(o.end-o.start)-n/2);return`${o.contig}:${Ue(s)}-${Ue(s+n)}`}var ot=6,Hi=3,Xi=12,Yi=1.3,zi="#111",Sr=3;function Qu(e,t,n){let r=e.pathVisits?.get(n.name)??[],o=[];for(let s of t){let a=s.axis;if(!a)continue;let l=le(s.name).name;for(let i of r){if(i.path!==l)continue;let{start:c,end:d}=Nt(a,i.start,i.start+n.length);d>0&&c<s.bp&&o.push({row:s.name,start:c,bp:d-c})}}return o}var Nr=new WeakMap;function Ki(e,t){let n=Nr.get(e);if(n||(n=new Map,Nr.set(e,n)),n.has(t))return n.get(t);let r=new Map(e.nodes.map(a=>[a.id,a.length])),o=(e.paths??[]).filter(a=>a.name===t),s;if(o.every(a=>a.start!==void 0)){s={ids:[],starts:[],ends:[]};for(let a of[...o].sort((l,i)=>l.start-i.start)){let l=a.start;for(let i of a.nodeIds){let c=r.get(i)??0;s.ids.push(i),s.starts.push(l),s.ends.push(l+c),l+=c}}}return n.set(t,s),s}function Zu(e,t,n,r){let o=t.axis,s=o&&Ki(e,t.name);if(!o||!s||n<0||n>t.bp)return;let a=o.reversed?o.start-n:o.start+n,l=.5/r,i=o.reversed?{start:o.start-t.bp,end:o.start}:{start:o.start,end:o.start+t.bp},c=Math.max(a-l,i.start),d=Math.min(a+l,i.end),u=0,f=s.starts.length;for(;u<f;){let g=u+f>>1;s.ends[g]<=c?u=g+1:f=g}let h,p=-1,m=!1;for(let g=u;g<s.starts.length&&s.starts[g]<d;g++){let b=s.ends[g]-s.starts[g],w=s.starts[g]<=a&&a<s.ends[g];(b>p||b===p&&w&&!m)&&(p=b,h=s.ids[g],m=w)}return h}function Ju(e,t){let n=e.rows.length+1,r=Math.max(Hi,Math.min(20,Math.floor((t.maxHeight-2*ot)/n))),o=r>=Xi,s=r>=14,a=Math.max(2,Math.round(r*.6)),l=Math.max(e.reference.bp,...e.rows.map(u=>u.bp),1),i=o?t.labelPx:ot,d=Math.max(1,t.width-i-ot)/(l*(s?Yi:1));return{scaleX:d,scaleY:1,translateX:i-e.origin*d,translateY:ot+r/2,width:t.width,height:n*r+2*ot,rowPx:r,barPx:a,readouts:s,labelled:o}}function ed(e,t,n,r){let o=Math.round((r-t.translateY)/t.rowPx),s=[e.reference,...e.rows][o],a=(n-t.translateX)/t.scaleX-e.origin;return s&&o>=0&&a>=0&&a<=s.bp?{index:o,row:s,offset:a}:void 0}function td(e,t,n){let r=new Map([e.reference,...e.rows].map((s,a)=>[s.name,a])),o=s=>(e.origin+s)*t.scaleX+t.translateX;return k("g",{"data-testid":"graph-walk-marks"},...n.flatMap(s=>{let a=r.get(s.row);if(a===void 0)return[];let l=a*t.rowPx+t.translateY,i=o(s.start),c=Math.max(2,s.bp*t.scaleX),d=u=>k("rect",{x:i,y:u,width:c,height:Sr,fill:zi});return[d(l-t.barPx/2-Sr-1),d(l+t.barPx/2+1)]}))}var pn=Y(Oe(),1);var fe=12,ji=fe+8,_r=8,Lr=_r+3,Ui=12;function sd(e,{colorScheme:t,referenceRamp:n,walks:r}){let o={...qt(e),referenceRamp:n},s=[];return e.nodes.forEach((a,l)=>{if(O(a)){let i=r?r.map(c=>{let d=c.colors.get(a.id);return d===void 0?Ft:(0,pn.abgrToCssRgba)(d)}):[(0,pn.abgrToCssRgba)(Ht(a,l,t,o))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(Ft)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function hn(e,t,n){let r=t*e.scale+e.translateX,o=n*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var Tr=2;function Vi(e,t,n){let r=-t.translateX/t.scale,o=(n-t.translateX)/t.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let c of e)l+=Math.max(0,Math.min(c.bp1,s)-c.bp0),i+=Math.max(0,c.bp1-Math.max(c.bp0,a));return t.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function ad(e,t,n,r){if(r<0||r>fe+Tr)return;let o,s=Tr;for(let a of e){let[l,i]=hn(t,a.bp0,a.bp1),c=Math.max(0,l-n,n-i);c<=s&&(s=c,o=a.node)}return o}function id(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function Qi(e,t,n,r){let o=e.map(c=>{let[d,u]=hn(t,c.bp0,c.bp1),f=Math.round(d*r);return{colors:c.colors,x0:d,px0:f,px1:Math.max(Math.round(u*r),f+1)}}).filter(c=>c.px1>0&&c.px0<n*r).sort((c,d)=>c.x0-d.x0),s=[],a=-1/0,l=[-1/0,-1/0];for(let{colors:c,px0:d,px1:u}of o){let f=Math.max(d,a);if(u>f){let h=l[0]<f?0:1;l[h]=u,s.push({colors:c,x0:f/r,x1:u/r,tier:h}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Ui?s:s.map(({tier:c,...d})=>d)}function Cr(e,t,n,r){let o=n>0?t:t-Lr;e.clearRect(o,0,Lr,fe);let s=t+n,a=s+n*_r;e.beginPath(),e.moveTo(s,fe/2),e.lineTo(a,0),e.lineTo(a,fe),e.closePath(),e.fillStyle=r,e.fill()}function Ar(e,t,n){return Math.round(e*fe*n/t)/n}function ld(e,t,n,{width:r,lit:o,darkMode:s,dpr:a=1}){let l=s?"#ffffff":"#18181c";e.clearRect(0,0,r,ji);for(let c of Qi(t,n,r,a)){let{tier:d}=c,u=d!==void 0&&c.colors.length===1,f=u?2:c.colors.length;c.colors.forEach((h,p)=>{let m=u?d:p,g=Ar(m,f,a);e.fillStyle=h,e.fillRect(c.x0,g,c.x1-c.x0,Ar(m+1,f,a)-g)})}let i=Vi(t,n,r);if(i.left>0&&Cr(e,0,1,l),i.right>0&&Cr(e,r,-1,l),o){let[c,d]=hn(n,o.start,o.end),u=Math.max(d-c,3),f=(c+d)/2-u/2;e.strokeStyle=l,e.lineWidth=1.5,e.strokeRect(f,.75,u,fe-1.5),o.anchor&&(e.beginPath(),e.moveTo(f+u/2,fe),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function fd(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;t.nodes.forEach(o=>{let s=n.get(o.name);if(o.order>=0&&s&&O(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function mn(e,t,n=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(n?i<t:i<=t)?r=l+1:o=l}let s=e[r];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function gn(e,t,n){let r=mn(e,t),o=mn(e,n,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function pd(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Ir=5,Zi=10,Ji=110,el=3;function tl(e){return e?"#b0b0b8":"#55555c"}function nl(e){let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<=1?1:n<=2?2:n<=5?5:10)*t}function vr(e){let t=[];for(let n of e)t.every(r=>Math.abs(n.at-r.at)>=(n.width+r.width)/2+Zi)&&t.push(n);return t.map(({text:n,at:r})=>({text:n,at:r}))}function ol(e,t,n,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=t(o.x0),l=t(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let c=nl(i/(l-a)*Ji),d=[],u=[];for(let f=Math.ceil(o.bp0/c)*c;f<=s.bp1;f+=c){let h=Math.round(t(mn(e,f)))+.5;if(h>=0&&h<=n){d.push(h);let p=f.toLocaleString("en-US");u.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:d,labels:vr(u)}}function rl(e,t,n,r){let o=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=n),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),c=[],d=[],u=[],f=[];for(let{box:p,s0:m,s1:g}of o){c.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=el&&d.push(Math.round(g)+.5);let b=l(xe(p.bp1-p.bp0),(m+g)/2);b.width<=g-m&&u.push(b),p!==s.box&&f.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:c,ticks:d,labels:vr([...h,...u,...f])}}function sl(e,t,n,r,o=!1){return(o?ol:rl)(e,t,n,r)}function hd(e,t,n,r,o=!1){let{x:s,width:a,darkMode:l}=n;e.font="10px sans-serif";let i=sl(t,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=tl(l),d=r+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:f}of i.spans)e.moveTo(Math.max(0,u),d),e.lineTo(Math.min(a,f),d);for(let u of i.ticks)e.moveTo(u,r),e.lineTo(u,r+Ir);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,r+Ir+2)}function bd(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach(o=>{let s=n.get(o.name);o.order>=0&&s&&O(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function xd(e,t,n,r){let o=[];for(let s of e){let a=n(s.x0),l=n(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:l})}return o}var al=3;function yd(e,t,n,r){if(t<=0||r<0||r>t)return;let o=r/t,s,a=al;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,c=l.top1+(l.bottom1-l.top1)*o,d=Math.max(0,Math.min(i,c)-n,n-Math.max(i,c));d<a&&(a=d,s=l.node)}return s}function Pr(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.top1,0),e.lineTo(t.bottom1,n),e.lineTo(t.bottom0,n),e.closePath()}function Or(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function wd(e,t,n,{highlightNode:r,darkMode:o}){if(n<=0||t.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of t)Pr(e,l,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of t)Or(e,l,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(l=>l.node===r);a&&(e.beginPath(),Pr(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),Or(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function il(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach((o,s)=>{let a=n.get(o.name);if(o.order>=0&&a&&O(a)){let l=a.stable.start;r.push({bp0:l,bp1:l+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function ll(e,t,n){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=t?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function Ed(e,t,n){let r=il(e,t),o=[];for(let s of t.tracks){let a=s.name?n.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let c=ll(r,i.start,l);if(c){let{node:d,bp0:u,bp1:f}=c,h=p=>d.x+(Math.min(p,f)-u)/(f-u)*d.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(c.index),height:s.width})}}}}return o}function cl(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Sd(e,t,{x:n,y:r,width:o,darkMode:s}){if(t.length!==0){e.fillStyle=cl(s),e.beginPath();for(let a of t){let l=n(a.x0),i=Math.max(n(a.x1),l+1);if(i>=0&&l<=o){let c=r(a.y);e.rect(l,c,i-l,r(a.y+a.height)-c)}}e.fill()}}function ul(e,t){let n=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=t.nodeMap.get(v(o.nodeName)),l=a===void 0?void 0:t.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let c=e.path[i]?.y;if(l&&c!==void 0){let d={readId:e.id,y:c,height:e.width,nodeY:l.y},u=f=>Do(l,f);for(let f of o.mismatches){let h=u(f.pos);if(h!==null){if(f.type==="insertion"){let p=s===0&&f.pos===e.firstNodeOffset||s===r.length-1&&f.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:h,seq:f.seq,softClip:p})}else if(f.type==="deletion"&&f.length!==void 0){let p=u(f.pos+f.length);p!==null&&n.push({...d,kind:"deletion",x0:h,x1:p})}else if(f.type==="substitution"&&f.seq!==void 0){let p=u(f.pos+f.seq.length);p!==null&&n.push({...d,kind:"substitution",x0:h,x1:p,seq:f.seq})}}}}}),n}function kr(e){return e.reads.flatMap(t=>ul(t,e))}function Dr(e){let t=e.trim().split(/[\s,]+/),n=[],r=0,o=()=>Number(t[r++]);for(;r<t.length;){let s=t[r++];s==="M"||s==="L"?n.push({op:s,x:o(),y:o()}):s==="H"?n.push({op:s,x:o()}):s==="V"?n.push({op:s,y:o()}):s==="Q"?n.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?n.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&n.push({op:s})}return n}function qr(e){let t=1/0,n=-1/0;for(let r of e)"x"in r&&(t=Math.min(t,r.x),n=Math.max(n,r.x)),"x1"in r&&(t=Math.min(t,r.x1),n=Math.max(n,r.x1));return{x0:t,x1:n}}function Br(e,t,n,r){let o=Dr(e);return{commands:o,color:t,track:r,alpha:n,...qr(o)}}function $r(e,t){let{shapes:n}=e,r=l=>t==="haplotype"?l.id:void 0,o=[...n.rectangles,...n.verticalRectangles].filter(l=>l.type===t).map(l=>({color:l.color,track:r(l),alpha:l.alpha??1,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),s=qo(n.curves,t).map(l=>Br(l.path,l.color,l.alpha??1,r(l))),a=n.corners.filter(l=>l.type===t).map(l=>Br(l.path,l.color,1,r(l)));return{rects:o,shapes:[...s,...a]}}function _d(e){let t=[];return e.nodes.forEach(n=>{if(n.order>=0){let r=Dr(Ho(n));t.push({name:n.name,commands:r,...qr(r)})}}),{bounds:e.bounds,layers:[$r(e,"haplotype"),$r(e,"read")],nodes:t,mismatches:kr(e).filter(n=>n.kind!=="insertion"||!n.softClip)}}function Gr(e,t,n,r){let o=0,s=0;for(let a of t)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(n(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(n(o),r(s));break;case"H":o=a.x,e.lineTo(n(o),r(s));break;case"V":s=a.y,e.lineTo(n(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),r(a.y1),n(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(n(a.x1),r(a.y1),n(a.x2),r(a.y2),n(o),r(s));break;case"Z":e.closePath();break}}function Fr(e,t,n,r,o){let s=new Map;for(let a of t)if(n(a)){let l=`${r(a)}|${a.alpha}`,i=s.get(l);i?i.push(a):s.set(l,[a])}for(let a of s.values()){e.fillStyle=r(a[0]),e.globalAlpha=a[0].alpha,e.beginPath();for(let l of a)o(l);e.fill()}e.globalAlpha=1}var dl=12,fl=.15;function pl(e){return Math.max(fl,Math.min(1,e/dl))}var hl=.55;function Id(e,t,n){let{x:r,y:o,width:s}=n,a=d=>r(d.x1)>=0&&r(d.x0)<=s,l=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;for(let d of t.layers)Fr(e,d.rects,a,l,u=>{let f=r(u.x0),h=o(u.y0);e.rect(f,h,r(u.x1)-f,o(u.y1)-h)}),Fr(e,d.shapes,a,l,u=>{Gr(e,u.commands,r,o)});let i=n.darkMode?"#d0d0d0":"#000000",c=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,n.yScale));for(let d of t.nodes)if(a(d)){let u=d.name===n.highlightNode;e.beginPath(),Gr(e,d.commands,r,o);let f=u?void 0:n.nodeColors?.get(d.name);e.fillStyle=u?"rgba(255,192,203,0.5)":f??c,e.strokeStyle=u?"#ff0000":i,e.globalAlpha=f?hl:1,e.fill(),e.globalAlpha=u?1:pl(r(d.x1)-r(d.x0)),e.stroke(),e.globalAlpha=1}bl(e,t.mismatches,n)}var Hr=12,ml=6;function gl(e){return Hr*e>=ml}function Wr(e,{x:t,width:n}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(o)>=0&&t(r)<=n}function bl(e,t,n){let{x:r,y:o,yScale:s,darkMode:a}=n;if(!gl(s)||t.length===0)return;let l=Hr*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&Wr(i,n)){let c=r(i.x0),d=o(i.y);e.rect(c,d,r(i.x1)-c,o(i.y+i.height)-d)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of t)Wr(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Od(e,t){let n=[];for(let r of t){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||n.push({gene:r,...gn(o,l,i),exons:r.exons.filter(c=>c.end>l&&c.start<i).map(c=>gn(o,Math.max(c.start,l),Math.min(c.end,i)))})}return n}var Xr=22,xl=4,Tt=8,yl="11px sans-serif",wl=8;function kd(e){let t=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),n=0,r=0;for(let{step:o}of t)n+=o,r=Math.max(r,n);return Math.min(xl,r)}function Bd(e,t,n,r,o=0){let{x:s,width:a,darkMode:l}=n,i=Math.max(1,Math.floor((r-o)/Xr)),c=[],d=l?"#e0e0e6":"#1c1c22";e.font=yl,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=t.map(f=>({g:f,s0:s(f.x0),s1:s(f.x1)})).filter(({s0:f,s1:h})=>h>=0&&f<=a).sort((f,h)=>f.s0-h.s0);for(let{g:f,s0:h,s1:p}of u){let m=f.gene.strand>0?" \u2192":f.gene.strand<0?"\u2190 ":"",g=f.gene.strand<0?`${m}${f.gene.name}`:`${f.gene.name}${m}`,b=(Math.max(h,0)+Math.min(p,a))/2,w=e.measureText(g).width/2,S=Math.min(h,b-w),E=Math.max(p,b+w),T=c.findIndex(N=>N+wl<=S);T===-1&&(T=Math.min(c.length,i-1)),c[T]=Math.max(c[T]??-1/0,E);let R=r-T*Xr-Tt/2;e.beginPath(),e.moveTo(h,R+.5),e.lineTo(p,R+.5),e.stroke();for(let N of f.exons){let I=s(N.x0);e.fillRect(I,R-Tt/2,Math.max(1,s(N.x1)-I),Tt)}e.fillText(g,b,R-Tt/2-2)}}function Ml(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function Rl(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0)),s=Array.from({length:n+1},()=>new Array(r+1).fill(!1));for(let l=n-1;l>=0;l--)for(let i=r-1;i>=0;i--){let c=Math.abs(e[l]-t[i])+o[l+1][i+1],d=n-l>r-i?o[l+1][i]:1/0,u=r-i>n-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,d,u),s[l][i]=o[l][i]===c}let a=new Array(n).fill(void 0);for(let l=0,i=0;l<n&&i<r;)s[l][i]?a[l++]=i++:n-l>r-i?l++:i++;return a}function Yr(e,t){return e.map((n,r)=>({item:n,i:r})).sort((n,r)=>t(n.item)-t(r.item))}var Kr=e=>e.spanningReads!==0;function zr(e,t){return{...t,agrees:e.complete&&Kr(t)?Ml(e.bp,t.bp):void 0}}function El(e,t){let n=new Map,r=new Set;e.forEach((l,i)=>{let c=t.find(d=>d.haplotype!==void 0&&d.haplotype===l.haplotype);c&&(r.add(c),n.set(i,zr(l,c)))});let o=t.filter(l=>l.haplotype===void 0),s=Yr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Kr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!n.has(u.i)),d=Yr(i.filter(u=>!r.has(u)),u=>u.bp);Rl(c.map(u=>u.item.bp),d.map(u=>u.item.bp)).forEach((u,f)=>{if(u!==void 0){let h=c[f],p=d[u].item;r.add(p),n.set(h.i,zr(h.item,p))}})}return n}function Gd(e,t){if(!t)return e;let n=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=t[o];if(a)for(let[l,i]of El(s,a))n.set(s[l],i)}return e.map(o=>({...o,call:n.get(o)}))}var jr=Y(it(),1),Dd=(0,ne.createSvgIcon)((0,jr.jsx)("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");export{ne as a,qs as b,Oe as c,Ve as d,is as e,ta as f,Kt as g,Ys as h,zs as i,Va as j,Vo as k,ui as l,cn as m,cu as n,uu as o,fi as p,Ee as q,pu as r,hu as s,mu as t,gu as u,xu as v,yu as w,wu as x,yi as y,Zr as z,Wn as A,os as B,rs as C,Cl as D,Yn as E,Ft as F,Dt as G,Hl as H,qt as I,Ht as J,Xl as K,Kl as L,St as M,nt as N,ir as O,Mi as P,Cu as Q,Au as R,_u as S,_i as T,Iu as U,vu as V,cr as W,fr as X,ki as Y,wr as Z,Fu as _,Wu as $,Di as aa,qi as ba,Du as ca,Er as da,Xu as ea,Yu as fa,Qu as ga,Zu as ha,Ju as ia,ed as ja,td as ka,ji as la,sd as ma,Vi as na,ad as oa,id as pa,ld as qa,fd as ra,pd as sa,tl as ta,hd as ua,bd as va,xd as wa,yd as xa,wd as ya,Ed as za,cl as Aa,Sd as Ba,_d as Ca,Id as Da,gl as Ea,Wr as Fa,Od as Ga,Xr as Ha,kd as Ia,Bd as Ja,Gd as Ka,Ql as La,Zl as Ma,Gs as Na,Jl as Oa,ec as Pa,Yt as Qa,zt as Ra,fc as Sa,pc as Ta,Dd as Ua};
|
|
2
|
-
//# sourceMappingURL=chunk-PPYB6N2Q.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{A as xe,Aa as Et,B as ft,Ba as It,Da as Gt,E as mt,F as fe,G as ht,Ja as Tt,L as ie,La as Nt,M as gt,N as bt,O as yt,P as vt,Qa as Pe,Ra as De,S as Me,T as wt,Ta as Ht,Ua as Wt,V as Ce,W as St,X as Re,a as W,b as Ae,ca as Le,ea as kt,h as st,i as it,ja as xt,ka as Mt,m as lt,qa as Ct,s as se,t as pt,ta as Rt,ua as Lt,ya as Pt,z as ut}from"./chunk-PPYB6N2Q.js";import{b as ct}from"./chunk-UQEPPJEO.js";import{a as we}from"./chunk-FCWXYIFC.js";import{a as Bt}from"./chunk-CNFN6EVE.js";import{R as dt,Z as le,h as rt,j as at,k as Xe,l as Se,y as ke}from"./chunk-UTWFU4X6.js";import{a as y,b as E,c as ee,d as Oe,e as A}from"./chunk-XEJ47DLD.js";import{a as xo,b as s}from"./chunk-FY3BTKY4.js";var zt=xo((la,_t)=>{_t.exports=JBrowseExports["@jbrowse/render-core/useRenderingBackend"]});var ze=s(A(),1);var ae=s(Oe(),1),nt=s(we(),1),wo=s(zt(),1);var At=s(y(),1),Ot=(0,W.createSvgIcon)((0,At.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m1 15h-2v-6h2zm0-8h-2V7h2z"}),"Info");var z=s(E(),1);var Ye=s(E(),1);var H={background:"rgba(255,255,255,0.82)",padding:"4px 6px",borderRadius:3,fontSize:11,lineHeight:"15px",whiteSpace:"nowrap"},C={display:"flex",alignItems:"center",gap:5};var _=s(y(),1),Mo={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"hidden",zIndex:2},Co=(0,Ye.observer)(function({model:e}){let{bubbleHalos:t,walkLift:o,hoveredBubble:r}=e;if(t.length===0)return null;let{scaleX:a,scaleY:l,translateX:i,translateY:u,paneWidth:f,canvasHeight:h}=e,c=e.contigThickness*ut,d=m=>o!==void 0&&!m.nodeIds.some(w=>o.nodeIds.has(w));return(0,_.jsx)("svg",{style:Mo,width:f,height:h,"data-testid":"graph-bubble-halos",children:(0,_.jsx)("g",{transform:`translate(${i} ${u}) scale(${a} ${l})`,children:t.filter(m=>!m.whole).map(m=>(0,_.jsx)("path",{d:m.path,fill:"none",stroke:se[m.kind],strokeOpacity:r&&ct(m.bubble,r)?.45:d(m)?.06:.22,strokeWidth:c,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"},`${m.bubble.start}-${m.bubble.end}`))})})}),Xt=Co;function Ro({color:n}){return(0,_.jsx)("svg",{width:18,height:10,style:{flex:"none"},children:(0,_.jsx)("line",{x1:5,y1:5,x2:13,y2:5,stroke:n,strokeOpacity:.35,strokeWidth:8,strokeLinecap:"round"})})}var Dt=(0,Ye.observer)(function({model:e}){let t=new Map;for(let o of e.bubbleHalos)if(!o.whole){let r=se[o.kind],a=t.get(r)??new Set;a.add(pt[o.kind]),t.set(r,a)}return t.size>0?(0,_.jsx)("div",{style:H,"data-testid":"graph-halo-legend",children:[...t].map(([o,r])=>(0,_.jsxs)("div",{style:C,children:[(0,_.jsx)(Ro,{color:o}),(0,_.jsxs)("span",{children:["bubble: ",[...r].join(", ")]})]},o))}):null});var Te=s(A(),1);var Ne=s(Ae(),1),$e=s(E(),1);var Y=s(y(),1),te={width:18,height:8,borderRadius:2,flex:"none"},Lo={marginBottom:2},Po={...te,width:48};function me({walk:n,label:e,reference:t,hint:o,at:r}){let a=kt(n,t);return(0,Y.jsxs)("div",{style:Lo,title:[a.hover,o].filter(Boolean).join(" \xB7 ")||void 0,children:[(0,Y.jsxs)("div",{style:C,children:[(0,Y.jsx)("div",{style:{...a.shades?Po:te,background:Le(n.encoding)}}),(0,Y.jsxs)("span",{children:[(0,Y.jsx)("strong",{children:e}),a.delta,a.outside,a.reversed]})]}),r?(0,Y.jsx)("div",{"data-testid":"graph-walk-at",children:r}):a.scale?(0,Y.jsx)("div",{children:a.scale}):null]})}var O=s(A(),1);var Eo=50;function Yt(n,e){return e>0?Math.max(1,n/e):Eo}function Io(n){let e=new Set,t=1/0,o=-1/0;for(let r of n)e.add(r.minY),t=Math.min(t,r.minY),o=Math.max(o,r.minY);return e.size>1?(o-t)/(e.size-1):void 0}function Go(n,e,t){let o=Yt(e,n.length);return{x:o,y:t>0?Yt(t,n.length):Io(n)??o}}function $t(n,e,t,o){return n===void 0?Go(e,t,o):typeof n=="number"?{x:n,y:n}:n}function To(n,e,t){let o=n.get(e);o||(o=new Map,n.set(e,o));let r=o.get(t);return r||(r=[],o.set(t,r)),r}function Ft(n,e,t,o,r,a,l){let i=Math.floor(t/e.x),u=Math.floor(r/e.x),f=Math.floor(o/e.y),h=Math.floor(a/e.y);for(let c=i;c<=u;c++)for(let d=f;d<=h;d++)To(n,c,d).push(l)}function Kt(n,e,t,o,r,a){let l=Math.floor((t-r)/e.x),i=Math.floor((t+r)/e.x),u=Math.floor((o-a)/e.y),f=Math.floor((o+a)/e.y),h=[],c=new Set;for(let d=l;d<=i;d++){let m=n.get(d);if(m)for(let w=u;w<=f;w++){let v=m.get(w);if(v)for(let g of v)c.has(g)||(c.add(g),h.push(g))}}return h}var Ee=class{constructor(e,t){this.cells=new Map;let o=[],r=0,a=0;for(let[l,i]of Object.entries(e))for(let u=0;u<i.length-1;u++){let f=i[u],h=i[u+1],c=Math.min(f.x,h.x),d=Math.min(f.y,h.y),m=Math.max(f.x,h.x),w=Math.max(f.y,h.y);r+=m-c,a+=w-d,o.push({entry:{nodeId:l,segmentIdx:u},minX:c,minY:d,maxX:m,maxY:w})}this.cellSize=$t(t,o,r,a);for(let l of o)Ft(this.cells,this.cellSize,l.minX,l.minY,l.maxX,l.maxY,l.entry)}query(e,t,o,r=o){return Kt(this.cells,this.cellSize,e,t,o,r)}},Ie=class{constructor(e,t,o,r,a,l,i=0,u){this.cells=new Map;this.edgeCurves=mt(e,t,r,l,i,u);let f=[],h=0,c=0;for(let d=0;d<t.edges.length;d++){let m=t.edges[d],w=e[m.from],v=e[m.to],g=this.edgeCurves.get(d);if(w?.length&&v?.length&&g){let{minX:L,minY:N,maxX:F,maxY:b}=rt(g),S=m.pathIds?.length??0;if(o&&S>0){let x=0,k=0;for(let G of Se(w,v,S,r))x=Math.max(x,Math.abs(G.x)),k=Math.max(k,Math.abs(G.y));L-=x,N-=k,F+=x,b+=k}h+=F-L,c+=b-N,f.push({ei:d,minX:L,minY:N,maxX:F,maxY:b})}}this.cellSize=$t(a,f,h,c);for(let d of f)Ft(this.cells,this.cellSize,d.minX,d.minY,d.maxX,d.maxY,d.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,o,r=o){return Kt(this.cells,this.cellSize,e,t,o,r)}};function Ut(n,e,t,o,r,a){let l=r-t,i=a-o,u=l*l+i*i;if(u===0)return Math.hypot(n-t,e-o);let f=Math.max(0,Math.min(1,((n-t)*l+(e-o)*i)/u));return Math.hypot(n-(t+f*l),e-(o+f*i))}function No(n,e,t,o,r,a,l,i,u,f){let h=1/0,c=20,d=t,m=o;for(let w=1;w<=c;w++){let v=w/c,g=1-v,L=g*g*g*t+3*g*g*v*r+3*g*v*v*l+v*v*v*u,N=g*g*g*o+3*g*g*v*a+3*g*v*v*i+v*v*v*f;h=Math.min(h,Ut(n,e,d,m,L,N)),d=L,m=N}return h}function Ho(n,e,t){return No(n,e,t.x0,t.y0,t.cx0,t.cy0,t.cx1,t.cy1,t.x1,t.y1)}function Vt(n,e,t,o=1){let r=1/0;for(let a of t){let l=Ho(n,e,o===1?a:{x0:a.x0,y0:a.y0*o,cx0:a.cx0,cy0:a.cy0*o,cx1:a.cx1,cy1:a.cy1*o,x1:a.x1,y1:a.y1*o});l<r&&(r=l)}return r}var Zt=new WeakMap;function Wo(n,e){let t=Zt.get(n);if(t?.version===e)return t.index;let o=new Ee(n);return Zt.set(n,{version:e,index:o}),o}var jt=new WeakMap;function Bo(n,e,t,o,r,a,l){let i=jt.get(n);if(i?.graph===e&&i.drawPaths===t&&i.scaleX===o.scaleX&&i.scaleY===o.scaleY&&i.version===r&&i.deletions===a&&i.routes===l)return i.index;let u=new Ie(n,e,t,o,void 0,a,r,l);return jt.set(n,{graph:e,drawPaths:t,scaleX:o.scaleX,scaleY:o.scaleY,version:r,index:u,deletions:a,routes:l}),u}var _o=5;function qt(n,e,t,o,r=0,a){let l=Xe(o),i=Wo(n,r),u=m=>Math.max(_o,m)/o.scaleX,f=u(a?.maxHalfWidthPx??0),h=i.query(e,t,f,f/l),c=null,d=1/0;for(let{nodeId:m,segmentIdx:w}of h){let v=n[m],g=Ut(e,t*l,v[w].x,v[w].y*l,v[w+1].x,v[w+1].y*l);g<d&&g<u(a?.halfWidthPx(m)??0)&&(d=g,c=m)}return c}function Jt(n,e,t,o,r,a,l=0,i,u,f){let h=Xe(r),c=10/r.scaleX,d=Bo(n,e,a,r,l,i,f),m=d.query(t,o,c,c/h),w=null,v=c;for(let g of m){let L=e.edges[g],N=n[L.from],F=n[L.to];if(!N?.length||!F?.length||u?.has(g))continue;let b=L.pathIds?.length??0,S=d.getCurves(g);if(!S)continue;let x;if(!a||b===0)x=Vt(t,o*h,S,h);else{let k=1/0;for(let G of Se(N,F,b,r)){let ve=G.x===0&&G.y===0?S:at(S,G.x,G.y),ot=Vt(t,o*h,ve,h);ot<k&&(k=ot)}x=k}x<v&&(v=x,w=g)}return w}function Qt(n){let e=n.deltaY*(n.deltaMode===1?40:n.deltaMode===2?800:1),t=(n.ctrlKey?10:1)*e/100;return 1.1**-Math.max(-2,Math.min(2,t))}var en=s(we(),1);function Ge(n,e){(0,O.useEffect)(()=>{if(!n)return;let t=n;function o(r){if(e.hostPlacesX)return;e.host&&r.stopPropagation(),r.preventDefault();let a=t.getBoundingClientRect();e.zoom(Qt(r),r.clientX-a.left,r.clientY-a.top)}return t.addEventListener("wheel",o,{passive:!1}),()=>{t.removeEventListener("wheel",o)}},[n,e])}function tn(n){let e=(0,O.useRef)({x:0,y:0}),t=(0,O.useRef)(!1),o=(0,O.useRef)({frame:0,pan:null,hover:null});(0,O.useEffect)(()=>()=>{cancelAnimationFrame(o.current.frame)},[]);let[r,a]=(0,O.useState)(void 0),[l,i]=(0,O.useState)(void 0);function u(b,S){return{x:(b-n.translateX)/n.scaleX,y:(S-n.translateY)/n.scaleY}}function f(b){let S=b.currentTarget.getBoundingClientRect();return u(b.clientX-S.left,b.clientY-S.top)}function h(b,S){let{nodePositions:x}=n,k=b*n.scaleX+n.translateX,G=S*n.scaleY+n.translateY;if(n.layoutResult?.tubeMap)return n.tubeMapNodeAt(k,G);let ve=n.referenceStripNodeAt(k,G);return ve||(x?qt(x,b,S,n.axisScale,n.positionsVersion,n.nodeInk):null)}function c(b){if(b.button===0){if(t.current=!1,n.hostPlacesX)return;n.host&&b.stopPropagation();let{x:S,y:x}=f(b),k=n.layoutResult?.tubeMap||b.nativeEvent.offsetY<n.referenceStripZonePx?null:h(S,x);k?n.setDraggingNode(k):n.setPanning(!0),e.current={x:b.clientX,y:b.clientY}}}function d(){let b=o.current;if(b.frame=0,b.pan&&(n.setTransform(n.scale,n.translateX+b.pan.dx,n.translateY+b.pan.dy),b.pan=null),b.hover&&n.nodePositions&&n.graph){let{x:S,y:x}=u(b.hover.x,b.hover.y);b.hover=null;let k=h(S,x);n.setHoveredNode(k),n.setHoveredEdge(k||n.layoutResult?.tubeMap?null:Jt(n.nodePositions,n.graph,S,x,n.axisScale,n.effectiveDrawPaths&&!n.facetPanels,n.positionsVersion,n.deletionEdgeIndexes,n.hiddenEdgeIndexes,n.deletionRoutes))}}function m(){o.current.frame||(o.current.frame=requestAnimationFrame(d))}function w(){let b=o.current;cancelAnimationFrame(b.frame),b.frame=0,b.pan=null,b.hover=null}function v(b){let S=b.clientX-e.current.x,x=b.clientY-e.current.y;e.current={x:b.clientX,y:b.clientY},(Math.abs(S)>1||Math.abs(x)>1)&&(t.current=!0);let k=o.current;if(n.draggingNode)n.moveNode(n.draggingNode,S/n.scaleX,x/n.scaleY);else if(n.isPanning)k.pan={dx:(k.pan?.dx??0)+S,dy:(k.pan?.dy??0)+x},m();else{let G=b.currentTarget.getBoundingClientRect();k.hover={x:b.clientX-G.left,y:b.clientY-G.top},m()}}function g(){n.stopDragging()}function L(){w(),(0,en.isAlive)(n)&&(n.stopDragging(),n.setHoveredNode(null),n.setHoveredEdge(null))}function N(b){let{x:S,y:x}=f(b),k=h(S,x);if(k){b.preventDefault(),a({nodeId:k,top:b.clientY,left:b.clientX});return}let G=n.walkRowAt(S*n.scaleX+n.translateX,x*n.scaleY+n.translateY);G!==void 0&&(b.preventDefault(),i({row:G,top:b.clientY,left:b.clientX}))}function F(b){if(!t.current){let{x:S,y:x}=f(b),k=h(S,x);n.setSelectedNode(k),k&&n.showNodeDetails(k)}}return{handlers:{onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:L,onClick:F,onContextMenu:N},contextNode:r,contextRow:l,closeContextMenu:()=>{a(void 0),i(void 0)}}}var K=s(y(),1),Oo={position:"absolute",left:0,top:0,zIndex:4,display:"grid",gap:8,lineHeight:"normal"},Xo={height:34,padding:"2px 6px",boxSizing:"border-box",fontFamily:"inherit",fontSize:11,color:"inherit",cursor:"pointer",border:"none",background:"none",textAlign:"left",display:"block"},Do=(0,$e.observer)(function({model:e,lift:t,width:o,height:r,cell:a,handlers:l}){let[i,u]=(0,Te.useState)(null),f=t.walks[0];Ge(i,e),(0,Te.useEffect)(()=>{if(!i)return;let c=new Re(i);c.resize(o,r);let d=(0,Ne.computed)(()=>e.buildDrawing(t,!1)),m,w=(0,Ne.autorun)(()=>{let v=d.get();v&&(v!==m&&(c.uploadGeometry(v.batch),m=v),e.applyHighlights(c),e.paint(c))});return()=>{w(),c.dispose()}},[i,e,t,o,r]);let h=e.walkLabel(f.name);return(0,K.jsxs)("div",{style:a,children:[(0,K.jsx)("button",{type:"button",style:Xo,"data-testid":"graph-facet-title",onClick:()=>{e.liftWalks([f.name]),e.setFacet("")},children:(0,K.jsx)(me,{walk:f,label:h,reference:e.walkReference,hint:`click to lift ${h} alone`,at:e.hoveredOn(f)})}),(0,K.jsx)("canvas",{ref:u,"data-testid":"graph-facet-canvas",style:{width:o,height:r,display:"block",cursor:e.isPanning||e.draggingNode?"grabbing":"grab"},...l})]})}),Yo=(0,$e.observer)(function({model:e,handlers:t}){let o=e.facetPanels,r=e.facetGrid,a=e.facetPlacement;if(!o||!r||!a)return null;let{columns:l,width:i,height:u}=r;return(0,K.jsx)("div",{"data-testid":"graph-facet-panels",style:{...Oo,width:e.paneWidth,minHeight:e.canvasHeight,gridTemplateColumns:`repeat(${l}, ${i}px)`,background:e.darkMode?"#1f1f1f":"white"},children:o.map((f,h)=>(0,K.jsx)(Do,{model:e,lift:f,width:i,height:u,cell:{gridRow:Math.floor(a.cells[h]/l)+1,gridColumn:a.cells[h]%l+1},handlers:t},f.walks[0].name))})}),nn=Yo;var on=s(A(),1),rn=s(E(),1),V=s(y(),1),$o={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"hidden",zIndex:2},he="#daa520",Fo=4,Ko=1,Vo=2,Zo=(0,rn.observer)(function({model:e}){let t=`exon-outline-${(0,on.useId)().replaceAll(/[^\w-]/g,"")}`,{genePins:o,walkLift:r,nodeInk:a}=e;if(o.length===0)return null;let{scaleX:l,scaleY:i,translateX:u,translateY:f,paneWidth:h,canvasHeight:c}=e,d=g=>{let L=a.halfWidthPx(g)*2;return r?.nodeIds.has(g)?Math.max(L,r.walks.length*Fo):L},m=o.flatMap(g=>g.exonsByNode.map(({nodeId:L,d:N})=>({key:`${g.gene.name}-${g.gene.start}-${L}`,d:N,inner:d(L)+2*Ko}))),w=`translate(${u} ${f}) scale(${l} ${i})`,v={fill:"none",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"};return(0,V.jsxs)("svg",{style:$o,width:h,height:c,"data-testid":"graph-gene-pins",children:[(0,V.jsx)("mask",{id:t,maskUnits:"userSpaceOnUse",x:0,y:0,width:h,height:c,children:(0,V.jsxs)("g",{transform:w,children:[m.map(g=>(0,V.jsx)("path",{d:g.d,stroke:"#fff",strokeWidth:g.inner+2*Vo,...v},g.key)),m.map(g=>(0,V.jsx)("path",{d:g.d,stroke:"#000",strokeWidth:g.inner,...v},g.key))]})}),(0,V.jsx)("rect",{width:h,height:c,fill:he,mask:`url(#${t})`})]})}),an=Zo;var sn=s(y(),1),ln=(0,W.createSvgIcon)((0,sn.jsx)("path",{d:"M3 5v4h2V5h4V3H5c-1.1 0-2 .9-2 2m2 10H3v4c0 1.1.9 2 2 2h4v-2H5zm14 4h-4v2h4c1.1 0 2-.9 2-2v-4h-2zm0-16h-4v2h4v4h2V5c0-1.1-.9-2-2-2"}),"CropFree");var Fe=s(y(),1),cn=(0,W.createSvgIcon)([(0,Fe.jsx)("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14"},"0"),(0,Fe.jsx)("path",{d:"M12 10h-2v2H9v-2H7V9h2V7h1v2h2z"},"1")],"ZoomIn");var pn=s(y(),1),dn=(0,W.createSvgIcon)((0,pn.jsx)("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14M7 9h5v1H7z"}),"ZoomOut");var D=s(ee(),1),je=s(E(),1),Wn=s(le(),1);var Z=s(ee(),1),un=s(E(),1),fn=s(le(),1),ce=s(y(),1),jo=(0,fn.makeStyles)()({formControl:{minWidth:100}}),Uo=(0,un.observer)(function({model:e}){let{classes:t}=jo(),o=e.colorSchemeLock;return(0,ce.jsxs)(Z.FormControl,{size:"small",className:t.formControl,disabled:o!==void 0,title:o?.why,children:[(0,ce.jsx)(Z.InputLabel,{children:"Color"}),(0,ce.jsx)(Z.Select,{value:e.chosenColorScheme,label:"Color",renderValue:o?()=>o.value:void 0,onChange:r=>{e.setColorScheme(r.target.value)},children:dt.map(({value:r,label:a})=>(0,ce.jsx)(Z.MenuItem,{value:r,children:a},r))})]})}),mn=Uo;var Ve=s(ee(),1),Ze=s(E(),1),hn=s(le(),1),pe=s(y(),1),gn=(0,hn.makeStyles)()({stats:{marginLeft:"auto"},perf:{color:"#888",fontVariantNumeric:"tabular-nums"}});function Ke(n){return n===void 0?"\u2013":`${Math.round(n)}ms`}var qo=(0,Ze.observer)(function({model:e}){let{classes:t}=gn(),{lastFetchMs:o,lastLayoutMs:r,lastGeometryMs:a}=e,l=o!==void 0||r!==void 0||a!==void 0;return e.showPerf&&l?(0,pe.jsxs)(Ve.Typography,{variant:"caption",className:t.perf,"data-testid":"graph-perf-stats",children:["fetch ",Ke(o)," \xB7 layout ",Ke(r)," \xB7 geom"," ",Ke(a)]}):null}),Jo=(0,Ze.observer)(function({model:e}){let{classes:t}=gn();return(0,pe.jsxs)("div",{className:t.stats,"data-testid":"graph-stats","data-node-count":e.nodeCount,"data-edge-count":e.edgeCount,"data-path-count":e.pathCount,"data-fetch-ms":e.lastFetchMs??"","data-layout-ms":e.lastLayoutMs??"","data-geometry-ms":e.lastGeometryMs??"","data-geometry-strokes":e.lastGeometryStrokeCount??"",children:[(0,pe.jsxs)(Ve.Typography,{variant:"body2",component:"span",children:[e.nodeCount," nodes, ",e.edgeCount," edges",e.pathCount>0?`, ${e.pathCount} paths`:""]})," ",(0,pe.jsx)(qo,{model:e})]})}),bn=Jo;var X=s(ee(),1),yn=s(E(),1),vn=s(le(),1),j=s(y(),1),Qo=(0,vn.makeStyles)()({formControl:{minWidth:150}}),er=(0,yn.observer)(function({model:e}){let{classes:t}=Qo(),{graph:o}=e;return(0,j.jsxs)(X.FormControl,{size:"small",className:t.formControl,children:[(0,j.jsx)(X.InputLabel,{children:"Layout"}),(0,j.jsx)(X.Select,{value:e.chosenLayoutMode,label:"Layout","data-testid":"graph-layout-select",onChange:r=>{e.switchLayout(r.target.value)},children:lt.map(({value:r,label:a,description:l,available:i})=>(0,j.jsx)(X.MenuItem,{value:r,disabled:o?!i(o):!1,children:(0,j.jsx)(X.Tooltip,{title:l,placement:"right",children:(0,j.jsx)("span",{children:a})})},r))})]})}),wn=er;var $=s(ee(),1),Sn=s(E(),1),kn=s(le(),1),U=s(y(),1),tr=(0,kn.makeStyles)()({formControl:{minWidth:130,maxWidth:240}}),nr=(0,Sn.observer)(function({model:e}){let{classes:t}=tr(),{repeatChoices:o}=e;if(e.chosenLayoutMode!=="walkrows"||o.length===0)return null;let r=new Set(o.map(a=>a.key));return(0,U.jsxs)($.FormControl,{size:"small",className:t.formControl,children:[(0,U.jsx)($.InputLabel,{children:"Repeat"}),(0,U.jsxs)($.Select,{value:r.has(e.repeatKey)?e.repeatKey:"",label:"Repeat","data-testid":"graph-repeat-select",onChange:a=>{e.setRepeatKey(a.target.value)},children:[(0,U.jsx)($.MenuItem,{value:"",children:(0,U.jsx)("em",{children:"Whole window"})}),o.map(({key:a,name:l,unit:i})=>(0,U.jsxs)($.MenuItem,{value:a,children:[l," \xB7 ",i.toLocaleString()," bp unit"]},a))]})]})}),xn=nr;var Pn=s(A(),1),En=s(Oe(),1);var Mn=s(y(),1),Cn=(0,W.createSvgIcon)((0,Mn.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM19 4h-3.5l-1-1h-5l-1 1H5v2h14z"}),"Delete");var Rn=s(y(),1),Ln=(0,W.createSvgIcon)((0,Rn.jsx)("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"}),"MoreVert");var In=s(E(),1);var q=s(y(),1),or=(0,In.observer)(function({model:e}){let[t,o]=(0,Pn.useState)(!1);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(En.CascadingMenuButton,{size:"small",menuItems:[{type:"checkbox",label:"Linear layout",checked:e.linearLayout,onClick:()=>{e.setLinearLayout(!e.linearLayout),e.recomputeLayout()}},{type:"checkbox",label:"Show deletion edges",checked:e.showDeletionEdges,onClick:()=>{e.setShowDeletionEdges(!e.showDeletionEdges)}},{type:"checkbox",label:"Show timings",checked:e.showPerf,onClick:()=>{e.setShowPerf(!e.showPerf)}},{type:"divider"},{label:"Settings",icon:Wt,onClick:()=>{o(!0)}},{type:"divider"},{label:"Return to import form",icon:Cn,onClick:()=>{e.clearGraph()}}],children:(0,q.jsx)(Ln,{})}),(0,q.jsx)(Bt,{model:e,open:t,onClose:()=>{o(!1)}})]})}),Gn=or;var B=s(ee(),1),Tn=s(E(),1),Nn=s(le(),1),J=s(y(),1),rr=(0,Nn.makeStyles)()({formControl:{minWidth:130,maxWidth:260}}),ar=(0,Tn.observer)(function({model:e}){let{classes:t}=rr(),{walkChoices:o}=e;if(o.length===0||!e.liftsWalks)return null;let r=new Set(o.map(i=>i.name)),a=new Map(o.map(i=>[i.name,i.label])),l=e.walkLayers.map(i=>i.walk).filter(i=>r.has(i));return(0,J.jsxs)(B.FormControl,{size:"small",className:t.formControl,children:[(0,J.jsx)(B.InputLabel,{children:"Walks"}),(0,J.jsx)(B.Select,{multiple:!0,value:l,label:"Walks","data-testid":"graph-walk-select",renderValue:i=>i.map(u=>a.get(u)).join(", "),onChange:i=>{let{value:u}=i.target;e.liftWalks(typeof u=="string"?u.split(","):u)},children:o.map(({name:i,label:u})=>(0,J.jsxs)(B.MenuItem,{value:i,dense:!0,children:[(0,J.jsx)(B.Checkbox,{size:"small",checked:l.includes(i)}),(0,J.jsx)(B.ListItemText,{primary:u})]},i))})]})}),Hn=ar;var P=s(y(),1),sr=(0,Wn.makeStyles)()({toolbar:{display:"flex",alignItems:"center",gap:4,padding:"2px 4px",borderBottom:"1px solid #ddd"}}),ir=(0,je.observer)(function({model:e}){return(0,P.jsx)(D.Typography,{variant:"body2",children:e.zoomPercent})}),lr=(0,je.observer)(function({model:e}){let{classes:t}=sr();return(0,P.jsxs)("div",{className:t.toolbar,children:[(0,P.jsx)(wn,{model:e}),(0,P.jsx)(mn,{model:e}),(0,P.jsx)(Hn,{model:e}),(0,P.jsx)(xn,{model:e}),(0,P.jsx)(D.Tooltip,{title:"Zoom in",children:(0,P.jsx)(D.IconButton,{size:"small",onClick:()=>{e.zoom(1.5,e.viewBox.width/2,e.viewBox.height/2)},children:(0,P.jsx)(cn,{})})}),(0,P.jsx)(D.Tooltip,{title:"Zoom out",children:(0,P.jsx)(D.IconButton,{size:"small",onClick:()=>{e.zoom(1/1.5,e.viewBox.width/2,e.viewBox.height/2)},children:(0,P.jsx)(dn,{})})}),(0,P.jsx)(D.Tooltip,{title:"Zoom to fit",children:(0,P.jsx)(D.IconButton,{size:"small",onClick:()=>{e.zoomToFit()},children:(0,P.jsx)(ln,{})})}),(0,P.jsx)(ir,{model:e}),(0,P.jsx)(bn,{model:e}),(0,P.jsx)(Gn,{model:e})]})}),Bn=lr;var An=s(we(),1),On=s(E(),1);var ne=s(y(),1);function ge({x:n,y:e,w:t,text:o,note:r,color:a,edge:l=a,italic:i,small:u,dimmed:f,title:h,testId:c,onClick:d,onHover:m}){return(0,ne.jsxs)("g",{style:{pointerEvents:d||m?"auto":"none",cursor:d?"pointer":void 0,opacity:f?.35:1},"data-testid":c,onClick:d,onMouseEnter:()=>{m?.(!0)},onMouseLeave:()=>{m?.(!1)},children:[h?(0,ne.jsx)("title",{children:h}):null,(0,ne.jsx)("rect",{x:n-t/2,y:e-11-4+2,width:t,height:17,rx:3,fill:"rgba(255,255,255,0.85)",stroke:l,strokeWidth:u?.6:1}),(0,ne.jsxs)("text",{x:n,y:e,fontSize:u?10:11,fontFamily:"sans-serif",fontStyle:i?"italic":void 0,fontWeight:i?600:void 0,fill:a,textAnchor:"middle",children:[o,r?(0,ne.jsx)("tspan",{fontStyle:"normal",fontWeight:"normal",children:r}):null]})]})}var Q=s(y(),1),cr={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"hidden",zIndex:3},zn="#1c1c22",pr=(0,On.observer)(function({model:e}){let{bubbles:t,genes:o,routes:r}=e.overlayLabels;if(t.length+o.length+r.length===0)return null;let{walkLift:a,scaleY:l,translateY:i,contigThickness:u}=e,f=c=>a!==void 0&&!c.nodeIds.some(d=>a.nodeIds.has(d)),h=c=>a!==void 0&&!c.route.walks.some(d=>a.names.has(d));return(0,Q.jsxs)("svg",{style:cr,width:e.paneWidth,height:e.canvasHeight,"data-testid":"graph-label-layer",children:[o.map(({item:c,x:d,y:m,w,text:v})=>{let{gene:g}=c,L=ft(c);return(0,Q.jsxs)("g",{children:[(0,Q.jsx)("line",{x1:d,x2:d,y1:m-11-2,y2:c.at.y*l+i+u/2,stroke:zn,strokeWidth:.8,strokeOpacity:.6}),(0,Q.jsx)(ge,{x:d,y:m,w,text:g.name,note:v.slice(g.name.length)||void 0,color:zn,edge:he,italic:!0,title:`${g.name} ${g.refName}:${g.start.toLocaleString()}-${g.end.toLocaleString()}${L?`, ${L} in the cut`:""}`,testId:"graph-gene-pin-label"})]},`${g.name}-${g.start}`)}),r.map(({item:{halo:c,route:d},x:m,y:w,w:v,text:g})=>(0,Q.jsx)(ge,{x:m,y:w,w:v,text:g,color:se[c.kind],small:!0,dimmed:h(d),title:`${d.route.walks.length} walk(s): ${d.route.walks.join(", ")}`,testId:"graph-route-label"},`${c.bubble.start}-${c.bubble.end}-${d.route.steps.join(",")}`)),t.map(({item:c,x:d,y:m,w,text:v})=>(0,Q.jsx)(ge,{x:d,y:m,w,text:v,color:se[c.kind],dimmed:f(c),title:`${c.label}
|
|
2
|
-
${c.bubble.segmentCount} segments \xB7 click to open`,testId:"graph-bubble-halo-label",onClick:()=>{e.popBubble(c.bubble)},onHover:g=>{(0,An.isAlive)(e)&&e.setHoveredBubble(g?c.bubble:null)}},`${c.bubble.start}-${c.bubble.end}`))]})}),Xn=pr;var He=s(A(),1);var Yn=s(St(),1),$n=s(Ae(),1),Ue=s(E(),1);var I=s(y(),1),dr={position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:5},ur=(0,Ue.observer)(function({model:e}){let t=(0,He.useRef)(null),{referenceStripShown:o,paneWidth:r,canvasHeight:a}=e;return(0,He.useEffect)(()=>(0,$n.autorun)(()=>{let l=t.current,i=e.referenceStripFrame,u=l?.getContext("2d");if(l&&u&&i&&e.referenceStripShown){let f=(0,Yn.getDpr)(),h=e.paneWidth,c=e.canvasHeight;l.width=Math.round(h*f),l.height=Math.round(c*f),u.setTransform(f,0,0,f,0,0),u.clearRect(0,0,h,c),Ct(u,e.referenceStripBlocks,i,{width:h,lit:e.referenceStripLit,darkMode:e.darkMode,dpr:f})}}),[e]),(0,I.jsx)("canvas",{ref:t,"data-testid":o?"graph-reference-strip":void 0,style:{...dr,width:r,height:a,display:o?"block":"none"}})}),Fn=ur,Kn=18,fr="linear-gradient(to right, hsl(0, 70%, 50%) 0 33%, hsl(120, 70%, 50%) 33% 61%, hsl(240, 70%, 50%) 61%)",mr=6;function hr(n){let e=n.filter((r,a)=>r!==n[a-1]),t=Math.min(mr,e.length),o=Array.from({length:t},(r,a)=>e[t>1?Math.round(a*(e.length-1)/(t-1)):0]);return o.length>1?`linear-gradient(to right, ${o.join(", ")})`:o[0]??fe}function Dn({rows:n}){return(0,I.jsx)("div",{style:{width:Kn,flex:"none"},children:n.map(({key:e,background:t})=>(0,I.jsx)("div",{style:{height:n.length>1?3:4,background:t}},e))})}function gr(n){return n.walkLift?.walks.map(e=>({key:e.name,background:Le(e.encoding)}))??[{key:"scheme",background:n.effectiveColorScheme==="reference-position"?fr:hr(n.referenceStripBlocks.map(e=>e.colors[0]))}]}function br(){return(0,I.jsx)("svg",{width:Kn,height:10,style:{flex:"none"},children:(0,I.jsx)("path",{d:"M0,5 L8,0 L8,10 Z M18,5 L10,0 L10,10 Z",fill:"#18181c"})})}var Vn=(0,Ue.observer)(function({model:e}){let t=(e.walkLift?.walks.length??0)>1;return e.referenceStripShown?(0,I.jsxs)("div",{style:H,"data-testid":"graph-reference-strip-legend",children:[(0,I.jsxs)("div",{style:C,children:[(0,I.jsx)(Dn,{rows:gr(e)}),(0,I.jsxs)("span",{children:["top strip: reference segments at their bp",t?", a row per walk":""]})]}),e.referenceStripFaded?(0,I.jsxs)("div",{style:C,children:[(0,I.jsx)(Dn,{rows:[{key:"pale",background:fe}]}),(0,I.jsxs)("span",{children:["reference not on"," ",t?"that row's walk":e.liftedWalksLabel]})]}):null,e.referenceStripOverhangs?(0,I.jsxs)("div",{style:C,children:[(0,I.jsx)(br,{}),(0,I.jsx)("span",{children:"the graph draws reference past this edge"})]}):null]}):null});var Be=s(A(),1);var Un=s(St(),1),qn=s(Ae(),1),qe=s(E(),1);var M=s(y(),1),yr={position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:1},vr=(0,qe.observer)(function({model:e}){let t=(0,Be.useRef)(null),{tubeMapPicture:o,paneWidth:r,canvasHeight:a}=e;return(0,Be.useEffect)(()=>(0,qn.autorun)(()=>{let l=t.current,i=e.tubeMapPicture,u=e.tubeMapFrame,f=l?.getContext("2d");if(l&&f&&i&&u){let h=(0,Un.getDpr)(),c=e.paneWidth,d=e.canvasHeight;l.width=Math.round(c*h),l.height=Math.round(d*h),f.setTransform(h,0,0,h,0,0),f.clearRect(0,0,c,d);let m={...u,width:c,highlightNode:e.hoveredNode??e.selectedNode,darkMode:e.darkMode,tubeColors:e.tubeMapTubeColors,nodeColors:e.tubeMapNodeColors};Gt(f,i,m),It(f,e.tubeMapDeviations,m),Pt(f,e.tubeMapConnectors,e.connectorZoneBottom,m);let{bounds:w}=i;Tt(f,e.tubeMapGenes,m,u.y(w.minY)-2);let v=e.tubeMapRulerBoxes;v&&Lt(f,v,m,u.y(w.maxY)+4,e.layoutResult?.referenceAxis)}}),[e]),(0,M.jsx)("canvas",{ref:t,"data-testid":o?"graph-tube-map":void 0,style:{...yr,width:r,height:a,display:o?"block":"none"}})}),Jn=vr,We=18;function wr(){let n=[[.5,5.5],[8.5,We-.5]];return(0,M.jsx)("svg",{width:We,height:7,style:{flex:"none"},children:(0,M.jsx)("path",{d:n.map(([e,t])=>`M${e},6 V1.5 H${t} V6`).join(" "),fill:"none",stroke:Rt(),strokeWidth:1})})}var Je={width:We,height:7,flex:"none"},Sr={...Je,display:"flex",justifyContent:"center",backgroundColor:"#b8b8c0"};function kr(){return(0,M.jsx)("div",{style:Sr,children:(0,M.jsx)("div",{style:{width:2,backgroundColor:Et()}})})}function Zn({colors:n}){let e=100/n.length,t=n.map((o,r)=>`${o} ${r*e}% ${(r+1)*e}%`);return(0,M.jsx)("div",{style:{...Je,background:`linear-gradient(to right, ${t.join(", ")})`}})}var jn={width:We,flex:"none",textAlign:"center",fontFamily:"monospace",fontSize:12};function xr(){return(0,M.jsx)("div",{style:{...Je,backgroundColor:"grey"}})}function oe({swatch:n,children:e}){return(0,M.jsxs)("div",{style:C,children:[n,(0,M.jsx)("span",{children:e})]})}var Qn=(0,qe.observer)(function({model:e}){let{logWidths:t,foldBp:o,forwardReads:r,reverseReads:a,mismatches:l}=e.tubeMapKeys,i=[r&&(0,M.jsx)(oe,{swatch:(0,M.jsx)(Zn,{colors:st}),children:"read on the forward strand"},"fwd"),a&&(0,M.jsx)(oe,{swatch:(0,M.jsx)(Zn,{colors:it}),children:"read on the reverse strand"},"rev"),l.has("substitution")&&(0,M.jsx)(oe,{swatch:(0,M.jsx)("span",{style:jn,children:"A"}),children:"a read's base unlike the node's"},"sub"),l.has("insertion")&&(0,M.jsx)(oe,{swatch:(0,M.jsx)("span",{style:jn,children:"*"}),children:"bases a read inserts"},"ins"),l.has("deletion")&&(0,M.jsx)(oe,{swatch:(0,M.jsx)(xr,{}),children:"bases a read skips"},"del"),o!==void 0&&(0,M.jsxs)(oe,{swatch:(0,M.jsx)(kr,{}),children:["a haplotype's variant under ",ke(o)]},"fold"),t&&(0,M.jsx)(oe,{swatch:(0,M.jsx)(wr,{}),children:"width grows with log of length"},"log")].filter(Boolean);return i.length>0?(0,M.jsx)("div",{style:H,"data-testid":"graph-tube-map-legend",children:i}):null});var eo=s(ee(),1),to=s(E(),1),oo=s(y(),1),Mr={position:"absolute",left:8,zIndex:5,background:"rgba(255,255,255,0.9)",textTransform:"none"},Cr=(0,to.observer)(function({model:e}){let{poppedFrom:t}=e;return t?(0,oo.jsxs)(eo.Button,{size:"small",variant:"outlined",style:{...Mr,...e.facetPanels?{bottom:8}:{top:8}},"data-testid":"graph-unpop-bubble",onClick:()=>{e.unpopBubble()},children:["\u25C0 Back to ",t.label]}):null}),no=Cr;var ro=s(Oe(),1);var ao=s(E(),1);var so=s(y(),1),_e=(0,ao.observer)(function({model:e,row:t,bars:o,top:r,left:a,onClose:l}){let i=e.walkRowLaunchTarget(t,o??e.walkRowBars),u=i?.assembly;return(0,so.jsx)(ro.Menu,{open:!0,anchorReference:"anchorPosition",anchorPosition:{top:r,left:a},onClose:()=>{l()},onMenuItemClick:f=>{f()},menuItems:[i&&u?{label:`Linear genome view \u2014 ${u} ${Pe(i.location)}`,icon:De,onClick:()=>{e.showInLinearView({location:i.location,assembly:u})}}:{label:"Linear genome view",icon:De,disabled:!0,disabledHelpText:i?`No assembly in this session is ${i.location.haplotype??i.label}`:"This walk states no contig coordinates",onClick:()=>{}}]})});var po=s(A(),1);var Qe=s(E(),1);var io=s(A(),1);function Rr(n){return n==="class"?"className":/^(data|aria)-/.test(n)?n:n.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function lo(n,e){if(typeof n=="string")return n;let t={key:e};for(let[o,r]of Object.entries(n.attrs))r!==void 0&&(t[Rr(o)]=r);return(0,io.createElement)(n.tag,t,...n.children.map(lo))}function ue({el:n}){return lo(n,0)}var R=s(y(),1),Pr={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"visible",zIndex:3},Er="#111",Ir="#9e9e9e",be={width:18,height:bt-4,borderRadius:2},Gr={...be,display:"flex",justifyContent:"center"};function co({color:n}){return(0,R.jsx)("div",{style:Gr,children:(0,R.jsx)("div",{style:{width:2,backgroundColor:n}})})}function et({swatch:n}){return n.kind==="gene"?(0,R.jsx)("div",{style:{...be,boxSizing:"border-box",border:`1.5px solid ${gt}`,borderRadius:0}}):(0,R.jsx)("div",{style:{...be,height:n.kind==="gap"?yt:be.height,background:n.fill}})}var uo=(0,Qe.observer)(function({model:e}){let t=e.walkRowBars;if(!t)return null;let o=[t.reference,...t.rows].flatMap(a=>a.call??[]),r=Me(t,{ramp:e.referenceRampDomain,rampCss:ie,genes:e.walkRowGenes?.size?e.walkRowGeneGaps:void 0});return(0,R.jsxs)("div",{style:H,"data-testid":"graph-walk-rows-legend",children:[r.map(a=>a.note?(0,R.jsx)("div",{style:{color:"#666",fontStyle:"italic"},children:a.label},a.label):(0,R.jsxs)("div",{style:C,children:[(0,R.jsx)(et,{swatch:a.swatch}),(0,R.jsx)("span",{children:a.label})]},a.label)),o.some(a=>a.spanningReads!==0)?(0,R.jsxs)("div",{style:C,children:[(0,R.jsx)(co,{color:Er}),(0,R.jsx)("span",{children:"allele length called for this walk"})]}):null,o.some(a=>a.spanningReads===0)?(0,R.jsxs)("div",{style:C,children:[(0,R.jsx)(co,{color:Ir}),(0,R.jsx)("span",{children:"called with no read spanning it"})]}):null,o.some(a=>a.agrees===!1)?(0,R.jsxs)("div",{style:C,children:[(0,R.jsx)("div",{style:be}),(0,R.jsxs)("span",{style:{color:wt},children:["walk and call over ",Math.round(.1*100),"% apart"]})]}):null]})}),Tr=(0,Qe.observer)(function({model:e}){let t=(0,po.useId)().replace(/[^\w-]/g,""),o=e.walkRowBars;if(!o)return null;let{paneWidth:r,canvasHeight:a}=e;return(0,R.jsx)("svg",{style:Pr,width:r,height:a,"data-testid":"graph-walk-rows",children:(0,R.jsx)(ue,{el:Ce(o,{scaleX:e.scaleX,scaleY:e.scaleY,translateX:e.translateX,translateY:e.translateY,width:r,height:a},{ramp:e.referenceRampDomain,rowGenes:e.walkRowGenes,idPrefix:t})})})}),fo=Tr;var re=s(A(),1);var mo=s(we(),1),tt=s(E(),1);var T=s(y(),1),Nr={display:"flex",flexWrap:"wrap",gap:"2px 14px",padding:"2px 8px 6px",fontSize:11,color:"#333"},Hr={position:"absolute",pointerEvents:"none",background:"rgba(255,255,255,0.92)",border:"1px solid #ccc",borderRadius:3,padding:"1px 6px",fontSize:11,whiteSpace:"nowrap",zIndex:4},Wr=(0,tt.observer)(function({bars:e,frame:t,ramp:o}){let r=(0,re.useId)().replace(/[^\w-]/g,""),a=(0,re.useMemo)(()=>Ce(e,t,{ramp:o,idPrefix:r}),[e,t,o,r]);return(0,T.jsx)(ue,{el:a})}),Br=(0,tt.observer)(function({model:e}){let t=e.walkStripRows,o=e.walkStripFrame,[r,a]=(0,re.useState)(void 0),[l,i]=(0,re.useState)(void 0);if(!t||!o)return null;let u=[t.reference,...t.rows],f=c=>{let d=c.currentTarget.getBoundingClientRect(),m=c.clientX-d.left,w=c.clientY-d.top;return{...xt(t,o,m,w),x:m,y:w}},h=Me(t,{ramp:e.referenceRampDomain,rampCss:ie});return(0,T.jsxs)("div",{"data-testid":"graph-walk-strip",style:{position:"relative",borderTop:"1px solid #ddd"},onMouseEnter:()=>{e.setPointerInPane(!0)},onMouseLeave:()=>{(0,mo.isAlive)(e)&&(e.setPointerInPane(!1),e.setStripHover(null)),i(void 0)},children:[(0,T.jsxs)("svg",{width:o.width,height:o.height,style:{display:"block",cursor:"pointer"},onMouseMove:c=>{let d=f(c);d.row?(e.setStripHover({row:d.row.name,offset:d.offset}),i(o.labelled?void 0:{text:`${d.row.label} \xB7 ${vt(d.row,d.index===0?void 0:t.reference)}`,x:d.x,y:d.y})):(e.setStripHover(null),i(void 0))},onClick:c=>{let d=f(c);d.row&&d.index>0&&e.toggleWalk(d.row.name)},onContextMenu:c=>{let d=f(c);d.row&&(c.preventDefault(),a({row:d.index,top:c.clientY,left:c.clientX}))},children:[(0,T.jsx)(Wr,{bars:t,frame:o,ramp:e.referenceRampDomain}),(0,T.jsx)(ue,{el:Mt(t,o,e.walkStripMarks)}),o.labelled?u.map((c,d)=>(0,T.jsx)("text",{x:6,y:d*o.rowPx+o.translateY+4,fontSize:11,fontFamily:"sans-serif",fill:"#333",fontWeight:e.walkLayers.some(m=>m.walk===c.name)?600:400,children:c.label},c.name)):null]}),l?(0,T.jsx)("div",{style:{...Hr,left:l.x+12,top:l.y-18},children:l.text}):null,(0,T.jsxs)("div",{style:Nr,"data-testid":"graph-walk-strip-key",children:[h.map(c=>(0,T.jsxs)("div",{style:C,children:[(0,T.jsx)(et,{swatch:c.swatch}),(0,T.jsx)("span",{children:c.label})]},c.label)),(0,T.jsx)("div",{style:C,children:(0,T.jsx)("span",{children:"\u25AE ticks: where each walk passes the node under the pointer \xB7 click a bar to lift its walk"})})]}),r?(0,T.jsx)(_e,{model:e,row:r.row,bars:t,top:r.top,left:r.left,onClose:()=>{a(void 0)}}):null]})}),ho=Br;var go=s(E(),1),ye=s(y(),1),_r={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"visible",zIndex:4},zr=(0,go.observer)(function({model:e}){let t=e.walkStripLocator;return t?(0,ye.jsxs)("svg",{style:_r,width:e.paneWidth,height:e.canvasHeight,"data-testid":"graph-walk-strip-locator",children:[(0,ye.jsx)("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"white",strokeWidth:4}),(0,ye.jsx)("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"#111",strokeWidth:1.75})]}):null}),bo=zr;function yo(n){return Promise.resolve(new Re(n))}var p=s(y(),1),vo={position:"absolute",bottom:8,right:8,background:"rgba(0,0,0,0.75)",color:"white",padding:"4px 8px",borderRadius:4,fontSize:12,pointerEvents:"none",zIndex:6},Ar={position:"relative"},Or={position:"relative",lineHeight:0,isolation:"isolate"},Xr={position:"absolute",left:0,right:0,bottom:0,zIndex:0},Dr={position:"absolute",inset:0,zIndex:10,lineHeight:"normal",pointerEvents:"none"},Yr={position:"absolute",left:6,transform:"translateY(-50%)",background:"rgba(255,255,255,0.82)",padding:"0 4px",borderRadius:3,fontSize:11,lineHeight:"16px",whiteSpace:"nowrap",pointerEvents:"none",zIndex:4},$r=(0,z.observer)(function({model:e}){let t=e.drawnRowLabels;return(0,p.jsx)(p.Fragment,{children:t.map(({label:o,y:r})=>{let a=r*e.scaleY+e.translateY;return a>=0&&a<=e.canvasHeight?(0,p.jsx)("div",{"data-testid":"graph-row-label",style:{...Yr,top:a},children:o},r):null})})}),Fr={position:"absolute",top:xe,right:xe,display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,pointerEvents:"none",zIndex:4},Kr={width:18,height:3,borderRadius:2},Vr=(0,z.observer)(function({model:e}){let{pathLegend:t}=e;return t.length>0?(0,p.jsx)("div",{style:H,"data-testid":"graph-path-legend",children:t.map(({name:o,label:r,color:a})=>(0,p.jsxs)("div",{style:C,children:[(0,p.jsx)("div",{style:{...Kr,backgroundColor:a}}),(0,p.jsx)("span",{children:r})]},o))}):null}),Zr=(0,z.observer)(function({model:e}){let t=e.walkLift;return t?(0,p.jsxs)("div",{style:H,"data-testid":"graph-walk-readout",children:[t.walks.map(o=>(0,p.jsx)(me,{walk:o,label:e.walkLabel(o.name),reference:e.walkReference,at:e.hoveredOn(o)},o.name)),e.liftPaintsOffReference?(0,p.jsx)(So,{}):null,(0,p.jsxs)("div",{style:C,children:[(0,p.jsx)("div",{style:{...te,background:fe}}),(0,p.jsxs)("span",{children:["not on ",e.liftedWalksLabel]})]})]}):null}),jr={minWidth:90,height:8,borderRadius:2,background:ie},Ur={display:"flex",justifyContent:"space-between",gap:8},qr=(0,z.observer)(function({model:e}){let t=e.walkLift?void 0:e.referenceRampDomain,{offReference:o,unplaced:r}=e.referenceRampOffKeys,a=Math.round(t?.start??0),l=Math.round(t?.end??0);return t?(0,p.jsxs)("div",{style:H,"data-testid":"graph-ramp-legend",children:[(0,p.jsx)("div",{style:jr}),(0,p.jsxs)("div",{style:Ur,children:[(0,p.jsx)("span",{children:a.toLocaleString()}),(0,p.jsxs)("span",{children:["(",ke(l-a),")"]}),(0,p.jsx)("span",{children:l.toLocaleString()})]}),o?(0,p.jsx)(So,{}):null,r?(0,p.jsxs)("div",{style:C,children:[(0,p.jsx)("div",{style:{...te,background:Jr}}),(0,p.jsx)("span",{children:"no reference position"})]}):null]}):null}),Jr="rgb(160, 160, 160)";function So(){return(0,p.jsxs)("div",{style:C,children:[(0,p.jsx)("div",{style:{...te,background:ht}}),(0,p.jsx)("span",{children:"off the reference"})]})}var Qr={...te,border:`2px solid ${he}`,borderRadius:5,boxSizing:"border-box"},ea=(0,z.observer)(function({model:e}){return e.genePins.some(t=>t.exonsByNode.length>0)?(0,p.jsx)("div",{style:H,"data-testid":"graph-gene-legend",children:(0,p.jsxs)("div",{style:C,children:[(0,p.jsx)("div",{style:Qr}),(0,p.jsx)("span",{children:"exon"})]})}):null}),ko={position:"absolute",transform:"translate(-50%, -50%)",background:"rgba(255,255,255,0.78)",padding:"0 3px",borderRadius:3,fontSize:10,lineHeight:"13px",whiteSpace:"nowrap",pointerEvents:"none",zIndex:3},ta={...ko,color:"#18181c",fontWeight:600},na={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"visible",zIndex:2},oa=(0,z.observer)(function({model:e}){let t=(0,ze.useRef)(null);return(0,ze.useEffect)(()=>{let o=t.current;if(!o)return;let r=new ResizeObserver(()=>{(0,nt.isAlive)(e)&&e.hoveredNode===null&&e.setLegendSize({width:o.offsetWidth,height:o.offsetHeight})});return r.observe(o),()=>{r.disconnect()}},[e]),(0,p.jsxs)("div",{ref:t,style:{...Fr,top:xe+e.referenceStripZonePx},children:[(0,p.jsx)(qr,{model:e}),(0,p.jsx)(Vn,{model:e}),(0,p.jsx)(Dt,{model:e}),(0,p.jsx)(ea,{model:e}),(0,p.jsx)(Vr,{model:e}),(0,p.jsx)(Qn,{model:e}),(0,p.jsx)(uo,{model:e}),(0,p.jsx)(Zr,{model:e})]})}),ra=(0,z.observer)(function({model:e}){let t=e.overlayLabels.sizes,o=t.flatMap(({key:r,leader:a})=>a?[{key:r,...a}]:[]);return(0,p.jsxs)(p.Fragment,{children:[o.length>0?(0,p.jsx)("svg",{style:na,width:e.paneWidth,height:e.canvasHeight,children:o.map(({key:r,arcX:a,arcY:l,labelX:i,labelY:u})=>(0,p.jsx)("line",{"data-testid":"graph-label-leader",x1:a,y1:l,x2:i,y2:u,stroke:"#18181c",strokeWidth:1},r))}):null,t.map(({key:r,text:a,x:l,y:i,kind:u})=>(0,p.jsx)("div",{"data-testid":"graph-size-label",style:{...u==="deletion"?ta:ko,left:l,top:i},children:a},r))]})}),aa=(0,z.observer)(function({model:e}){let t=e.hoveredNode?e.nodeById?.get(e.hoveredNode):null,o=e.hoveredEdge!==null&&e.graph?e.graph.edges[e.hoveredEdge]:null,r=t?Nt(t):void 0,a=e.hoveredEdge===null?void 0:e.deletions.find(l=>l.edgeIndex===e.hoveredEdge);return(0,p.jsxs)(p.Fragment,{children:[t?(0,p.jsxs)("div",{style:vo,children:[(0,p.jsx)("strong",{children:t.name})," \u2014"," ",t.length.toLocaleString()," bp, depth"," ",t.depth.toFixed(1),r?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("br",{}),r.sample," ",Pe(r)," (rank"," ",t.stable?.rank,")"]}):null]}):null,o?(0,p.jsx)("div",{style:vo,children:a?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("strong",{children:"Deletion"})," ",a.bp.toLocaleString()," bp",(0,p.jsx)("br",{}),a.refName,":",a.start.toLocaleString(),"-",a.end.toLocaleString()]}):(0,p.jsxs)(p.Fragment,{children:["Edge: ",o.from," \u2192 ",o.to]})}):null]})}),sa=(0,z.observer)(function({model:e,nodeId:t,top:o,left:r,onClose:a}){let{own:l,reference:i,highlight:u}=e.nodeLaunchTargets(t);return(0,p.jsx)(ae.Menu,{open:!0,anchorReference:"anchorPosition",anchorPosition:{top:o,left:r},onClose:()=>{a()},onMenuItemClick:f=>{f()},menuItems:[{label:"Node details",icon:Ot,onClick:()=>{e.showNodeDetails(t)}},...Ht({own:l,reference:i,highlight:u,onShowLinear:f=>{e.showInLinearView(f)},onHighlight:e.canHighlightInLinearView?f=>{e.highlightInLinearView(f)}:void 0})]})}),ia=(0,z.observer)(function({model:e,ownChrome:t=!0}){let{canvasRef:o,canvas:r,error:a,retry:l}=(0,wo.useRenderingBackend)(yo,e),{handlers:i,contextNode:u,contextRow:f,closeContextMenu:h}=tn(e);Ge(r,e);let c=e.facetPanels!==void 0;return(0,p.jsxs)("div",{style:Ar,children:[t?(0,p.jsx)(Bn,{model:e}):null,(0,p.jsxs)("div",{style:Or,onMouseEnter:()=>{e.setPointerInPane(!0)},onMouseLeave:()=>{(0,nt.isAlive)(e)&&e.setPointerInPane(!1)},children:[e.referenceStripShown?(0,p.jsx)("div",{style:{...Xr,top:e.referenceStripZonePx,background:e.paperCss}}):null,(0,p.jsx)("canvas",{ref:o,"data-testid":"graph-genome-canvas",style:{width:e.paneWidth,height:e.canvasHeight,cursor:e.isPanning||e.draggingNode?"grabbing":"grab",display:"block",position:"relative",zIndex:1},...i}),c?(0,p.jsx)(nn,{model:e,handlers:i}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(Jn,{model:e}),(0,p.jsx)(Fn,{model:e}),(0,p.jsx)($r,{model:e}),(0,p.jsx)(ra,{model:e}),(0,p.jsx)(Xt,{model:e}),(0,p.jsx)(an,{model:e}),(0,p.jsx)(Xn,{model:e}),(0,p.jsx)(fo,{model:e}),(0,p.jsx)(bo,{model:e}),(0,p.jsx)(oa,{model:e})]}),(0,p.jsx)(no,{model:e}),t?(0,p.jsx)("div",{style:Dr,children:(0,p.jsx)(ae.LoadingOverlay,{isVisible:e.isLoading,immediate:!e.layoutResult,statusMessage:e.statusMessage,onCancel:e.canCancelLoad?()=>{e.cancelLoad()}:void 0})}):null]}),e.walkStripShown?(0,p.jsx)(ho,{model:e}):null,(0,p.jsx)(aa,{model:e}),u?(0,p.jsx)(sa,{model:e,nodeId:u.nodeId,top:u.top,left:u.left,onClose:h}):null,f?(0,p.jsx)(_e,{model:e,row:f.row,top:f.top,left:f.left,onClose:h}):null,a?(0,p.jsx)(ae.ErrorBanner,{error:a,onReset:l}):null,t&&e.error?(0,p.jsx)(ae.ErrorBanner,{error:e.error,onReset:e.canRetryLoad?()=>{e.retryLoad()}:void 0}):null]})}),Pi=ia;export{Pi as a};
|
|
3
|
-
//# sourceMappingURL=chunk-PSOLXUFN.js.map
|
|
File without changes
|
/package/dist/chunks/{LinearGraphDisplay-BCTYOYQ5.js.map → LinearGraphDisplay-742CW5KL.js.map}
RENAMED
|
File without changes
|