jbrowse-plugin-graphgenomeviewer 5.0.1 → 5.2.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/README.md +3 -4
- package/dist/chunks/GbzBaseSyntenyAdapter-TQVDD3OC.js +8 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-TQVDD3OC.js.map +7 -0
- package/dist/chunks/{GraphGenomeView-YYP4IFSI.js → GraphGenomeView-AY2FO4P2.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-2WPJRAJC.js → GraphTrackSettingsDialog-QJXPMWYG.js} +2 -2
- package/dist/chunks/LinearGraphDisplay-GKVG72J4.js +2 -0
- package/dist/chunks/LinearGraphDisplay-GKVG72J4.js.map +7 -0
- package/dist/chunks/chunk-2V27PV25.js +3 -0
- package/dist/chunks/chunk-2V27PV25.js.map +7 -0
- package/dist/chunks/chunk-FNHKEAKB.js +5 -0
- package/dist/chunks/{chunk-LGFKHSVJ.js.map → chunk-FNHKEAKB.js.map} +3 -3
- package/dist/chunks/chunk-K5Z47YVI.js +2 -0
- package/dist/chunks/chunk-K5Z47YVI.js.map +7 -0
- package/dist/chunks/{chunk-SJNG2XK7.js → chunk-LJZDHT2C.js} +2 -2
- package/dist/chunks/chunk-NWJN4C4V.js +2 -0
- package/dist/chunks/chunk-NWJN4C4V.js.map +7 -0
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +2 -2
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +20 -38
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +14 -65
- package/src/GraphGenomeView/components/GenePins.tsx +25 -80
- package/src/GraphGenomeView/components/usePaneGestures.ts +1 -0
- package/src/GraphGenomeView/genes/geneFeatures.ts +46 -7
- package/src/GraphGenomeView/genes/genes.test.ts +88 -1
- package/src/GraphGenomeView/model.test.ts +1 -1
- package/src/GraphGenomeView/pane/fitViews.ts +1 -0
- package/src/GraphGenomeView/pane/graphViews.ts +39 -5
- package/src/GraphGenomeView/pane/loadActions.ts +5 -5
- package/src/GraphGenomeView/pane/paneBase.ts +3 -2
- package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +160 -92
- package/src/LinearGraphDisplay/components/LinearGraphDisplay.tsx +2 -12
- package/src/LinearGraphDisplay/denseWindow.ts +40 -0
- package/src/LinearGraphDisplay/model.ts +34 -94
- package/src/index.ts +0 -2
- package/src/version.ts +1 -1
- package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js +0 -4
- package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js.map +0 -7
- package/dist/chunks/LinearGraphDisplay-7YE624D5.js +0 -2
- package/dist/chunks/LinearGraphDisplay-7YE624D5.js.map +0 -7
- package/dist/chunks/chunk-2H7GDQ3R.js +0 -6
- package/dist/chunks/chunk-2H7GDQ3R.js.map +0 -7
- package/dist/chunks/chunk-BZOIENU5.js +0 -2
- package/dist/chunks/chunk-BZOIENU5.js.map +0 -7
- package/dist/chunks/chunk-H54W6OQQ.js +0 -2
- package/dist/chunks/chunk-H54W6OQQ.js.map +0 -7
- package/dist/chunks/chunk-LGFKHSVJ.js +0 -5
- package/dist/chunks/chunk-O4XV3K35.js +0 -2
- package/dist/chunks/chunk-O4XV3K35.js.map +0 -7
- package/dist/chunks/chunk-WKVVIDCS.js +0 -3
- package/dist/chunks/chunk-WKVVIDCS.js.map +0 -7
- package/src/GetHaplotypeOverview.ts +0 -77
- package/src/HaplotypeOverview/HaplotypeOverviewCanvas.tsx +0 -203
- package/src/HaplotypeOverview/draw.test.ts +0 -136
- package/src/HaplotypeOverview/draw.ts +0 -433
- package/src/HaplotypeOverview/model.ts +0 -163
- /package/dist/chunks/{GraphGenomeView-YYP4IFSI.js.map → GraphGenomeView-AY2FO4P2.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-2WPJRAJC.js.map → GraphTrackSettingsDialog-QJXPMWYG.js.map} +0 -0
- /package/dist/chunks/{chunk-SJNG2XK7.js.map → chunk-LJZDHT2C.js.map} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{A as Gn,B as Bn,C as $t,D as $n,E as Wn,F as Wt,G as Ft,J as Fn,K as Dn,R as qn,S as xt,a as le,h as Cn,i as An,j as Ze,k as gt,l as Je,m as Oe,n as In,o as _n,p as vn,q as Pn,v as On,w as bt,x as kn,y as et,z as be}from"./chunk-K5Z47YVI.js";import{d as Xn}from"./chunk-UQEPPJEO.js";import{c as Tn}from"./chunk-SCMIJAAX.js";import{a as Qe,b as k,c as ht,d as ve,e as Ln,f as Pe,i as mt}from"./chunk-7BKUWQE5.js";import{a as ft,c as Nn,d as pt}from"./chunk-KULNKXPT.js";import{a as dt}from"./chunk-TYJTJGPO.js";import{a as Ve,b as K}from"./chunk-FY3BTKY4.js";var Yn=Ve((ic,Hn)=>{Hn.exports=JBrowseExports["@mui/material/SvgIcon"]});var ke=Ve((cc,zn)=>{zn.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var Ea=Ve((du,Tr)=>{Tr.exports=JBrowseExports.mobx});var Wo=Ve((jd,$o)=>{$o.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var Do=Ve((Ud,Fo)=>{Fo.exports=JBrowseExports["@jbrowse/render-core/renderingBackendBase"]});var re=K(Yn(),1);var F=K(ke(),1);var W=K(ke(),1);function Ge(e,t){return(0,W.packAbgr)((0,W.abgrRed)(e),(0,W.abgrGreen)(e),(0,W.abgrBlue)(e),Math.round((0,W.abgrAlpha)(e)*t))}function yt(e,t){return(0,W.packAbgr)(Math.min(255,Math.round((0,W.abgrRed)(e)*t)),Math.min(255,Math.round((0,W.abgrGreen)(e)*t)),Math.min(255,Math.round((0,W.abgrBlue)(e)*t)),(0,W.abgrAlpha)(e))}var gs=4;function tt(e){let t=new Map;function n(o,r){let s=t.get(o);s?s.push(r):t.set(o,[r])}for(let o of e.edges)n(o.from,o.to),n(o.to,o.from);return t}function bs({nodeId:e,nodeById:t,neighbors:n}){let o=new Set([e]),r=[e],s=1/0,a=-1/0;for(let l=0;l<gs&&r.length>0;l++){let i=[];for(let c of r){let d=n.get(c);if(d){for(let u of d)if(!o.has(u)){o.add(u);let f=t.get(u);f&&k(f)?(s=Math.min(s,f.stable.start+f.length),a=Math.max(a,f.stable.start)):i.push(u)}}}r=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function xs({nodeId:e,nodeById:t,neighbors:n}){let o=t.get(e);return o===void 0?void 0:k(o)?{start:o.stable.start,end:o.stable.start+o.length}:bs({nodeId:e,nodeById:t,neighbors:n})}function Kn(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=tt(e),o=new Map;for(let r of e.nodes){let s=xs({nodeId:r.id,nodeById:t,neighbors:n});s&&o.set(r.id,(s.start+s.end)/2)}return o}var jn=new WeakMap;function Mt(e,t,n,o,r,s,a=!1){let{scaleX:l,scaleY:i}=n,c=jn.get(e);if(c?.graph===t&&c.scaleX===l&&c.scaleY===i&&c.deletions===o&&c.routes===s&&c.stranded===a&&c.version===r)return c.curves;let d=new Map;for(let u=0;u<t.edges.length;u++){let f=t.edges[u],h=e[f.from],p=e[f.to];if(h?.length&&p?.length){let m=o?.get(u),g=m&&s?.[u];d.set(u,g?vn(h,p,g,a?gt(f):void 0):_n(h,p,In(f,a),0,0,n,m?Pn(e,m):[]))}}return jn.set(e,{graph:t,scaleX:l,scaleY:i,deletions:o,routes:s,stranded:a,version:r,curves:d}),d}var ys=(0,F.packAbgr)(119,119,119,217),Un=(0,F.packAbgr)(136,136,136,217),Ms=(0,F.packAbgr)(24,24,28,240),ws=2.2,rr=(0,F.packAbgr)(160,160,160,255),nt=.18,Yt=(0,F.abgrToCssRgba)(Ge(rr,nt)),Rs=11,Ss=1.2,Vn=4,Dt=1e-6,Es=7,Ns=3,Ls=3,Ts=1.5,Qn=3,Cs=.5,As=.45,qt=12,Is=1e-6,ce=new Float64Array(64),xe=new Float64Array(64),ye=new Float64Array(64);function _s(e,t,n,o){let r=e.length*qt+1;ce.length<r&&(ce=new Float64Array(r),xe=new Float64Array(r),ye=new Float64Array(r));let s=e[e.length-1];ce[0]=s.x1,xe[0]=s.y1,ye[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<o;i--){let c=e[i];for(let d=1;d<=qt&&l<o;d++){let u=1-(d/qt)**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,M=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(b-ce[a-1],(M-xe[a-1])*n)*t,ce[a]=b,xe[a]=M,ye[a]=l,a++}}return a}function Zn(e,t){let n=1;for(;n<e-1&&ye[n]<t;)n++;let o=ye[n-1],r=ye[n],s=r>o?Math.min(1,Math.max(0,(t-o)/(r-o))):0;return{x:ce[n-1]+(ce[n]-ce[n-1])*s,y:xe[n-1]+(xe[n]-xe[n-1])*s}}function vs({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:o,yToX:r,color:s,fromSegments:a,toSegments:l}){let i=Es+Ns*t,c=_s(e,o,r,n+Qn*i),d=ye[c-1],u=d<Is,f=Math.min(n,d),h=u?Math.min(1,Ps(a,o,r)/i):1;if(u?h<Cs:d<Qn*i)return;let p=Zn(c,f),m=Zn(c,f+i*h),g=p.x-m.x,b=(p.y-m.y)*r,M=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,b)>0?Math.atan2(b,g):qs(M,r,ks(M,l)),length:i*h,halfWidth:(Ls+Ts*t)*h,color:s}}function Ps(e,t,n){let o=0;for(let r=1;r<e.length;r++)o+=Math.hypot(e[r].x-e[r-1].x,(e[r].y-e[r-1].y)*n);return o*t}function Os(e,t,n,o,r){if(o)return gt(e).from==="start";let s=a=>Math.hypot(a.x-n.x0,(a.y-n.y0)*r);return s(t[0])<s(t.at(-1))}function ks(e,t){if(t.length<2)return;let n=t[0],o=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-o.x,e.y1-o.y)?{from:n,to:t[1]}:{from:o,to:t[t.length-2]}}function Xt(e,t=1){let n=t===1?e:e.map(r=>({x:r.x,y:r.y*t})),o=[];for(let r=0;r<n.length;r++){let s=0,a=0;if(r===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(r===n.length-1){let l=n[r].x-n[r-1].x,i=n[r].y-n[r-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=n[r].x-n[r-1].x,i=n[r].y-n[r-1].y,c=Math.hypot(l,i),d=n[r+1].x-n[r].x,u=n[r+1].y-n[r].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)}o.push({nx:s,ny:a})}return o}function Jn(e,t,n,o=1){return e.map((r,s)=>({x:r.x+t[s].nx*n,y:r.y+t[s].ny*n/o}))}function wt(e,t,n,o){return(0,F.packAbgr)(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(o*255))}function Be(e,t,n){let o=(1-Math.abs(2*n-1))*t,r=o*(1-Math.abs(e/60%2-1)),s=n-o/2,a=0,l=0,i=0;return e<60?(a=o,l=r):e<120?(a=r,l=o):e<180?(l=o,i=r):e<240?(l=r,i=o):e<300?(a=r,i=o):(a=o,i=r),[a+s,l+s,i+s]}var Gs=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],Bs=[[237,137,44],[158,42,122]],$s=[[220,50,50],[50,120,220]];function Ht(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),o=Math.min(e.length-2,Math.floor(n)),r=n-o,s=e[o],a=e[o+1];return(0,F.packAbgr)(Math.round(s[0]+(a[0]-s[0])*r),Math.round(s[1]+(a[1]-s[1])*r),Math.round(s[2]+(a[2]-s[2])*r),255)}function Ws(e,t){let[n,o,r]=Be($n(e),Wt,Ft);return wt(n,o,r,t)}var $e=300,Fs=.7,Ds=.5,or=[60,65,72],zt=(0,F.packAbgr)(...or,255),Kt=`rgb(${or.join(", ")})`;function Rc(e,t){let n=Kn(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let o=1/0,r=-1/0;for(let s of n.values())o=Math.min(o,s),r=Math.max(r,s);return{start:o===1/0?0:o,span:r>o?r-o:1,midpoints:n}}function jt(e){let t=1/0,n=-1/0,o=1/0,r=-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<o&&(o=a.length),a.length>r&&(r=a.length);return{minDepth:t,maxDepth:n,minLength:o,maxLength:r,maxRank:s,nodeCount:e.nodes.length}}function Ut(e,t,n,o){switch(n){case"random":return Ws(e.id,1);case"depth":return Ht(Gs,o.maxDepth>o.minDepth?(e.depth-o.minDepth)/(o.maxDepth-o.minDepth):.5);case"node-length":return Ht($s,o.maxLength>o.minLength?(e.length-o.minLength)/(o.maxLength-o.minLength):.5);case"stable-rank":return e.stable===void 0?(0,F.packAbgr)(160,160,160,255):e.stable.rank===0?(0,F.packAbgr)(52,152,219,255):Ht(Bs,o.maxRank>1?(e.stable.rank-1)/(o.maxRank-1):0);case"reference-position":{let r=o.referenceRamp,s=r?.midpoints.get(e.id);if(r===void 0||s===void 0)return(0,F.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return zt;let a=Math.max(0,Math.min(1,(s-r.start)/r.span)),[l,i,c]=Be(a*$e,Fs,Ds);return wt(l,i,c,1)}case"grey":return(0,F.packAbgr)(160,160,160,255);case"rainbow":{let r=o.nodeCount>1?t/o.nodeCount*360:0,[s,a,l]=Be(r,.75,.5);return wt(s,a,l,1)}default:return(0,F.packAbgr)(52,152,219,255)}}function qs(e,t=1,n){let o=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[r,s]of o){let a=e.x1-r,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 Xs(e,t){let n=!1;for(let o=0;o<e.length-1&&!n;o++){let r=e[o],s=e[o+1];n=Math.max(r.x,s.x)>=t.minX&&Math.min(r.x,s.x)<=t.maxX&&Math.max(r.y,s.y)>=t.minY&&Math.min(r.y,s.y)<=t.maxY}return n}function er(e,t){for(let n of e){let o=Math.min(n.x0,n.cx0,n.cx1,n.x1),r=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(r>=t.minX&&o<=t.maxX&&a>=t.minY&&s<=t.maxY)return!0}return!1}var tr=new WeakMap;function Hs(e){let t=tr.get(e);if(!t){let n=[],o=new Map,r=e.paths??[];for(let s=0;s<r.length;s++){let[a,l,i]=Be(Wn(s,r.length),Wt,Ft);n.push(wt(a,l,i,.85)),o.has(r[s].name)||o.set(r[s].name,s)}t={pathColorByIndex:n,pathIndexByName:o},tr.set(e,t)}return t}var nr=new WeakMap,Ys=new Map;function zs(e){let t=nr.get(e);if(!t){t=new Map;for(let[n,o]of(e.paths??[]).entries())for(let r of new Set(o.nodeIds)){let s=t.get(r);s?s.push(n):t.set(r,[n])}nr.set(e,t)}return t}function Sc(e){let{nodePositions:t,graph:n,nodeById:o,colorScheme:r,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:d,linearLayout:u,viewportBounds:f,referenceRamp:h,deletions:p,deletionRoutes:m,stranded:g,hiddenEdges:b,version:M=0}=e,L=i==="depth"?qn(n):0,N=d.scaleX,S=Je(d),R=Mt(t,n,d,p,M,m,g),w=[],C=new Map,O=[],H=new Map,B=[],pe=new Map,Se={...jt(n),referenceRamp:h},se=new Map;if(r==="rainbow")for(let v=0;v<n.nodes.length;v++)se.set(n.nodes[v].id,v);let Y=n.paths?.length??0,{pathColorByIndex:V,pathIndexByName:j}=Hs(n),U=v=>V[j.get(v)??-1]??Un,Ee=l&&Y>1?zs(n):Ys,Ye=N>(u?1:As);for(let v=0;v<n.edges.length;v++){let G=n.edges[v],Z=t[G.from],ae=t[G.to],J=R.get(v);if(!Z?.length||!ae?.length||!J||b?.has(v))continue;let Ne=G.pathIds?.length??0,ze=p?.get(v)!==void 0,Ke=c?.edgeIndexes.has(v)??!1,Le=a/2*(ze?ws:1),Te=l&&Ne>0,he=ze?Ms:ys,ee=!c||Ke?he:Ge(he,nt),je=o.get(G.to),Ce=(je?xt(je,s,i,L):s)/2,Ae=(ge,_e,z,ie)=>{let ne=ge===0&&_e===0?J:Ze(J,ge,_e);if(f&&!er(ne,f))return;if(ze)for(let kt of An(ne,Rs/N))B.push({curves:kt,thickness:Le,color:z});else B.push({curves:ne,thickness:Le,color:z});let ut=Ye&&ie!==void 0?vs({curves:ne,edgeHalfWidth:a/2,nodeHalfWidth:Ce,scale:N,yToX:S,color:ie,fromSegments:Z,toSegments:ae}):void 0;ut&&O.push(ut)},me=B.length,Ie=O.length,te=c&&Ke&&!Te?c.walks:void 0;if(te){let ge=o.get(G.from),_e=ge?xt(ge,s,i,L):s,z=Math.max(_e/te.length,Vn),ie=Xt(Z,S),{nx:ne,ny:ut}=(Os(G,Z,J[0],g,S)?ie[0]:ie.at(-1))??{nx:0,ny:0},kt=1/Math.max(N,Dt);te.forEach((Gt,ms)=>{if(!Gt.edgeIndexes.has(v))return;let Bt=(ms-(te.length-1)/2)*z*kt,En=Bt===0?J:Ze(J,ne*Bt,ut*Bt/S);f&&!er(En,f)||B.push({curves:En,thickness:z/2,color:Gt.colors.get(G.from)??Gt.colors.get(G.to)??he})})}else if(!Te)Ae(0,0,ee,ee);else{let ge=Oe(Z,ae,Ne,d),_e=Math.floor((Ne-1)/2);for(let z=0;z<Ne;z++){let ie=ge[z],ne=U(G.pathIds[z]);Ae(ie.x,ie.y,c&&!c.names.has(G.pathIds[z])?Ge(ne,nt):ne,z===_e?ee:void 0)}}let Ue=B.length-me;Ue>0&&pe.set(v,{start:me,count:Ue});let ct=O.length-Ie;ct>0&&H.set(v,{start:Ie,count:ct})}for(let[v,G]of Object.entries(t)){let Z=o.get(v);if(!Z||f&&!Xs(G,f))continue;let ae=c!==void 0&&!c.nodeIds.has(v),J=ae?rr:Ut(Z,se.get(v)??0,r,Se),Ne=ae?Ge(J,nt):J,lt=xt(Z,s,i,L),ze=lt/2,Ke=w.length,Le=Ee.get(v),Te=lt/Y,he=G.length>=2,ee=c&&!ae&&!Le?.length?c.walks:void 0;if(he&&ee){let Ce=Math.max(lt/ee.length,Vn),Ae=Xt(G,S),me=1/Math.max(N,Dt);ee.forEach((Ie,te)=>{let Ue=Ie.colors.get(v);if(Ue===void 0)return;let ct=(te-(ee.length-1)/2)*Ce*me;w.push({points:ee.length===1?G:Jn(G,Ae,ct,S),thickness:Ce/2,color:Ue})})}else if(he&&Le?.length&&Te>=Ss){let Ce=Xt(G,S),Ae=1/Math.max(N,Dt);for(let me of Le){let Ie=(me-(Y-1)/2)*Te*Ae,te=V[me]??Un;w.push({points:Jn(G,Ce,Ie,S),thickness:Te/2,color:ae?Ge(te,nt):te})}}else he&&w.push({points:G,thickness:ze,color:Ne});let je=w.length-Ke;je>0&&C.set(v,{start:Ke,count:je})}return{nodeStrokes:w,nodeStrokeRuns:C,arrows:O,arrowRuns:H,edgeCurves:B,edgeCurveRuns:pe}}function Rt(e){return`hsl(${e}, 70%, 50%)`}function Vt(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*$e}var Ks=30;function sr({start:e,bp:t,reversed:n},o){let r=Vt(e,o),s=Vt(e+t,o);if(s-r<1)return[(r+s)/2];let a=Math.ceil((s-r)/Ks);return Array.from({length:a+1},(l,i)=>Vt(e+t*(n?a-i:i)/a,o))}var Qt=Array.from({length:7},(e,t)=>({offset:t/6,color:Rt(t/6*$e)})),ar=`linear-gradient(to right, ${Qt.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function A(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function ir(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function js(e){return ir(e).replaceAll('"',""")}function Us(e){if(typeof e=="string")return ir(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${js(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(Us).join("")}</${e.tag}>`}var Vs="#daa520",Qs=1,Zs=2,Js=4;function Ac(e,t,n,o=r=>r){let r=s=>{let a=t(s)*2;return n?.nodeIds.has(s)?Math.max(a,n.walks.length*Js):a};return e.flatMap(s=>s.exonsByNode.map(({nodeId:a,d:l})=>({key:`${s.gene.name}-${s.gene.start}-${a}`,d:o(l),inner:r(a)+2*Qs})))}function Ic(e,t){if(e.length===0)return;let n=(o,r,s)=>A("path",{d:o.d,fill:"none",stroke:r,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return A("g",{},A("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},A("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*Zs)),...e.map(o=>n(o,"#000",o.inner)))),A("rect",{width:t.width,height:t.height,fill:Vs,mask:`url(#${t.id})`}))}var ea=50;function lr(e,t){return t>0?Math.max(1,e/t):ea}function ta(e){let t=new Set,n=1/0,o=-1/0;for(let r of e)t.add(r.minY),n=Math.min(n,r.minY),o=Math.max(o,r.minY);return t.size>1?(o-n)/(t.size-1):void 0}function na(e,t,n){let o=lr(t,e.length);return{x:o,y:n>0?lr(n,e.length):ta(e)??o}}function cr(e,t,n,o){return e===void 0?na(t,n,o):typeof e=="number"?{x:e,y:e}:e}function ra(e,t,n){let o=e.get(t);o||(o=new Map,e.set(t,o));let r=o.get(n);return r||(r=[],o.set(n,r)),r}function ur(e,t,n,o,r,s,a){let l=Math.floor(n/t.x),i=Math.floor(r/t.x),c=Math.floor(o/t.y),d=Math.floor(s/t.y);for(let u=l;u<=i;u++)for(let f=c;f<=d;f++)ra(e,u,f).push(a)}function dr(e,t,n,o,r,s){let a=Math.floor((n-r)/t.x),l=Math.floor((n+r)/t.x),i=Math.floor((o-s)/t.y),c=Math.floor((o+s)/t.y),d=[],u=new Set;for(let f=a;f<=l;f++){let h=e.get(f);if(h)for(let p=i;p<=c;p++){let m=h.get(p);if(m)for(let g of m)u.has(g)||(u.add(g),d.push(g))}}return d}var St=class{constructor(t,n){this.cells=new Map;let o=[],r=0,s=0;for(let[a,l]of Object.entries(t))for(let i=0;i<l.length-1;i++){let c=l[i],d=l[i+1],u=Math.min(c.x,d.x),f=Math.min(c.y,d.y),h=Math.max(c.x,d.x),p=Math.max(c.y,d.y);r+=h-u,s+=p-f,o.push({entry:{nodeId:a,segmentIdx:i},minX:u,minY:f,maxX:h,maxY:p})}this.cellSize=cr(n,o,r,s);for(let a of o)ur(this.cells,this.cellSize,a.minX,a.minY,a.maxX,a.maxY,a.entry)}query(t,n,o,r=o){return dr(this.cells,this.cellSize,t,n,o,r)}},Et=class{constructor(t,n,o,r,s,a,l=0,i,c=!1){this.cells=new Map;this.edgeCurves=Mt(t,n,r,a,l,i,c);let d=[],u=0,f=0;for(let h=0;h<n.edges.length;h++){let p=n.edges[h],m=t[p.from],g=t[p.to],b=this.edgeCurves.get(h);if(m?.length&&g?.length&&b){let{minX:M,minY:L,maxX:N,maxY:S}=Cn(b),R=p.pathIds?.length??0;if(o&&R>0){let w=0,C=0;for(let O of Oe(m,g,R,r))w=Math.max(w,Math.abs(O.x)),C=Math.max(C,Math.abs(O.y));M-=w,L-=C,N+=w,S+=C}u+=N-M,f+=S-L,d.push({ei:h,minX:M,minY:L,maxX:N,maxY:S})}}this.cellSize=cr(s,d,u,f);for(let h of d)ur(this.cells,this.cellSize,h.minX,h.minY,h.maxX,h.maxY,h.ei)}getCurves(t){return this.edgeCurves.get(t)}query(t,n,o,r=o){return dr(this.cells,this.cellSize,t,n,o,r)}};function mr(e,t,n,o,r,s){let a=r-n,l=s-o,i=a*a+l*l;if(i===0)return Math.hypot(e-n,t-o);let c=Math.max(0,Math.min(1,((e-n)*a+(t-o)*l)/i));return Math.hypot(e-(n+c*a),t-(o+c*l))}function oa(e,t,n,o,r,s,a,l,i,c){let d=1/0,u=20,f=n,h=o;for(let p=1;p<=u;p++){let m=p/u,g=1-m,b=g*g*g*n+3*g*g*m*r+3*g*m*m*a+m*m*m*i,M=g*g*g*o+3*g*g*m*s+3*g*m*m*l+m*m*m*c;d=Math.min(d,mr(e,t,f,h,b,M)),f=b,h=M}return d}function sa(e,t,n){return oa(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function fr(e,t,n,o=1){let r=1/0;for(let s of n){let a=sa(e,t,o===1?s:{x0:s.x0,y0:s.y0*o,cx0:s.cx0,cy0:s.cy0*o,cx1:s.cx1,cy1:s.cy1*o,x1:s.x1,y1:s.y1*o});a<r&&(r=a)}return r}var pr=new WeakMap;function gr(e,t){let n=pr.get(e);if(n?.version===t)return n.index;let o=new St(e);return pr.set(e,{version:t,index:o}),o}var hr=new WeakMap;function aa(e,t,n,o,r,s,a,l=!1){let i=hr.get(e);if(i?.graph===t&&i.drawPaths===n&&i.scaleX===o.scaleX&&i.scaleY===o.scaleY&&i.version===r&&i.deletions===s&&i.routes===a&&i.stranded===l)return i.index;let c=new Et(e,t,n,o,void 0,s,r,a,l);return hr.set(e,{graph:t,drawPaths:n,scaleX:o.scaleX,scaleY:o.scaleY,version:r,index:c,deletions:s,routes:a,stranded:l}),c}var ia=5;function Bc(e,t,n,o,r=0,s){let a=Je(o),l=gr(e,r),i=h=>Math.max(ia,h)/o.scaleX,c=i(s?.maxHalfWidthPx??0),d=l.query(t,n,c,c/a),u=null,f=1/0;for(let{nodeId:h,segmentIdx:p}of d){let m=e[h],g=mr(t,n*a,m[p].x,m[p].y*a,m[p+1].x,m[p+1].y*a);g<f&&g<i(s?.halfWidthPx(h)??0)&&(f=g,u=h)}return u}function la(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,a=1;for(let[l,i]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(l===0){if(i<0)return!1}else l<0?s=Math.max(s,i/l):a=Math.min(a,i/l);return s<=a}function br(e,t,n=0){let o=gr(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let a=new Set,l=o.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:i,segmentIdx:c}of l){let d=e[i];!a.has(i)&&la(r(d[c]),r(d[c+1]),s)&&a.add(i)}return a}}function $c(e,t,n,o,r,s,a=0,l,i,c,d=!1){let u=Je(r),f=10/r.scaleX,h=aa(e,t,s,r,a,l,c,d),p=h.query(n,o,f,f/u),m=null,g=f;for(let b of p){let M=t.edges[b],L=e[M.from],N=e[M.to];if(!L?.length||!N?.length||i?.has(b))continue;let S=M.pathIds?.length??0,R=h.getCurves(b);if(!R)continue;let w;if(!s||S===0)w=fr(n,o*u,R,u);else{let C=1/0;for(let O of Oe(L,N,S,r)){let H=O.x===0&&O.y===0?R:Ze(R,O.x,O.y),B=fr(n,o*u,H,u);B<C&&(C=B)}w=C}w<g&&(g=w,m=b)}return m}var da=3.4,xr=6,fa=8,pa=18,ha=2,ma=15;function ga(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],r=s=>+(s/n).toFixed(n===1?0:1);return`${r(e.covered*t)} of ${r(t)} ${o}`}function ba(e,t,n,o){let r=n/2;return yr(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:a,y:l}=t(s.at),i=ga(s);return{item:s,x:a,y:l+n+pa,text:i?`${s.gene.name} \xB7 ${i}`:s.gene.name,fallback:i?`${s.gene.name} \u2026`:void 0,stack:ha,fits:c=>[...o({x0:c.x0-r,x1:c.x1+r,y0:c.y0-r,y1:c.y1+r})].every(d=>s.nodeIds.has(d))}})}function yr(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Xc(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:t,height:n},i=R=>({x:R.x*s+o,y:R.y*a+r}),c=e.drawnRowLabels.map(({label:R,y:w})=>kn(R,w*a+r)),d=e.referenceStripZonePx??0;d>0&&c.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&c.push({x0:t-xr-e.legendSize.width,x1:t,y0:0,y1:d+xr+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=On(l,c),f=e.drawnRowLabels.length>0,h=f?Math.min(...e.drawnRowLabels.map(R=>R.y)):1/0,p=e.contigThickness*da,m=yr(e.bubbleHalos,R=>R.members),g=bt(m.map(R=>{let{x:w,y:C}=i({x:R.labelAt.x,y:Math.min(R.labelAt.y,h)}),O=C-p/2-6;return{item:R,x:w,y:f?Math.max(O,ma):O,text:R.label}}),l,u),b=bt(ba(e.genePins,i,e.contigThickness,br(e.nodePositions??{},{scaleX:s,scaleY:a,translateX:o,translateY:r},e.positionsVersion)),l,u),M=e.nodePositions&&e.labelsNodeSizes?Gn({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:o,translateY:r,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},L=$t(M.deletions,u),N=bt(m.flatMap(R=>R.routes.map(w=>{let{x:C,y:O}=i(w.at);return{item:{halo:R,route:w},x:C,y:O+4,text:w.text,stack:fa}})),l,u),S=$t(M.nodes,u,Bn(t,n));return{bubbles:g,genes:b,routes:N,sizes:[...L,...S]}}function Kc(e){return Qe(e)?Mr(e):void 0}function Mr(e){return{sample:ft(e.stable.refName),haplotype:Nn(e.stable.refName),refName:pt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function xa(e,t){let n=[...e].sort((s,a)=>s.start-a.start),o,r;for(let s of n)r=r&&s.start-r.end<=t?{start:r.start,end:Math.max(r.end,s.end)}:{start:s.start,end:s.end},(!o||r.end-r.start>o.end-o.start)&&(o=r);return o}function ya(e){return`${e.haplotype??e.sample}\0${e.refName}`}function jc(e,{maxGap:t=1/0}={}){let n=new Map;for(let r of e.nodes)if(Qe(r)){let s=Mr(r),a=ya(s),l=n.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,r.stable.rank)):n.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:r.stable.rank,spans:[{start:s.start,end:s.end}]})}let o=new Map;for(let r of n.values()){let s=xa(r.spans,t);if(s){let a={sample:r.sample,haplotype:r.haplotype,refName:r.refName,start:s.start,end:s.end,rank:r.rank,nodeCount:r.spans.length},l=r.haplotype??r.sample,i=o.get(l);(!i||a.nodeCount>i.nodeCount)&&o.set(l,a)}}return[...o.values()].sort((r,s)=>+(r.rank!==0)-+(s.rank!==0)||r.sample.localeCompare(s.sample)||(r.haplotype??"").localeCompare(s.haplotype??""))}function Ma(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function Uc(e,t){return e.flatMap(n=>{let o=Ma(t,n);return o===void 0?[]:[{...n,sample:o}]})}function Vc(e){return`${e.refName}:${e.start+1}-${e.end}`}function Zt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var wr=K(dt(),1),Rr=(0,re.createSvgIcon)((0,wr.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Sr=K(dt(),1),Er=(0,re.createSvgIcon)((0,Sr.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 Nr=K(dt(),1),Jt=(0,re.createSvgIcon)((0,Nr.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 wa="Linear genome view",Ra="Linear synteny view",Sa="No synteny track in this session aligns these assemblies";function Lr({label:e,icon:t,entries:n,entryLabel:o,onSelect:r,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 ${o(l)}`:e,icon:t,onClick:r(l)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(c=>({label:o(c),onClick:r(c)}))}]}function lu({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:o}){let r=t[0]?.coverage??e.length;return[...Lr({label:wa,icon:Jt,entries:e,entryLabel:s=>`${s.sample} ${Zt(s)}`,onSelect:s=>()=>{n({location:s,assembly:s.sample})}}),...e.length>=2?Lr({label:`${Ra} (${r} assemblies)`,icon:Rr,entries:t,entryLabel:s=>s.coverage<r?`${s.name} (${s.coverage} of ${r})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Sa,onSelect:s=>()=>{o(s.trackId)}}):[]]}function cu({own:e,reference:t,highlight:n,onShowLinear:o,onHighlight:r}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Zt(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[...r&&n?[{label:`Highlight in ${n.assembly}`,icon:Er,onClick:()=>{r(n)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:Jt,onClick:()=>{o(l)}}))]}function en(e){return e.id.endsWith("-")?"-":"+"}function tn(e,t){return t===en(e)?e.id:`-${e.id}`}function Na(e,t){let n=e.map(()=>{}),o=0,r=0;for(;r<e.length&&e[r]!==void 0;r++)n[r]=o,o+=e[r];let s=t;for(let a=e.length-1;a>r&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function La(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=Na(t,e.pathLength),r=(l,i=!1)=>{for(let c=0;c<o.length;c++){let d=o[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 Tn(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=r(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=r(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=r(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 Cr(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let a=s.path.map(d=>o.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=La(s,a.map(h=>h?.length)),u=l.map(h=>tn(a[h],s.path[h].strand)),f=a[c].length;r.push({id:n+r.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 r}var Ta=["#6baed6","#4292c6","#2171b5","#08519c"],Ca=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Ar(e){let t=e.is_reverse?Ca:Ta;return t[e.id%t.length]}function Nt(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 Aa(e,t,n,o){let r=[],s=[],a=[e];for(o.add(e);a.length>0;){let l=a.pop(),i=t.get(l);if(i){r.push(i);for(let c of n.get(l)??[]){let d=t.get(c);d&&(d.stable.rank===0?s.push(d):o.has(c)||(o.add(c),a.push(c)))}}}return{members:r,anchors:s}}function Ia(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),o=n[0],r=n.at(-1),s=o.stable.start+o.length,a=r.stable.start;return a>=s?{start:s,end:a,entry:o}:void 0}function _a(e,t,n){let o=new Map(e.map(a=>[a.id,a])),r=new Map,s=[];for(let a of n.get(t.id)??[])o.has(a)&&(r.set(a,0),s.push(a));if(s.length===0)for(let a of e)r.set(a.id,0),s.push(a.id);for(let a of s){let l=r.get(a)+o.get(a).length;for(let i of n.get(a)??[])if(o.has(i)){let c=r.get(i);(c===void 0||l<c)&&(r.set(i,l),s.push(i))}}return r}function va(e,t,n){let o=_a(e,t,n),r=[...e].sort((i,c)=>o.get(i.id)-o.get(c.id)),s=new Map(r.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of r.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:r}}function _r(e){let t=new Map(e.nodes.filter(Qe).map(s=>[s.id,s])),n=tt(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==0&&!o.has(s.id)){let{members:a,anchors:l}=Aa(s.id,t,n,o),i=Ia(l);if(i){let{offsets:c,ordered:d}=va(a,i.entry,n);r.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 r.sort((s,a)=>s.start-a.start)}var Pa=1,Oa=.015;function Lt({graph:e,span:t,rowY:n,positions:o}){let r=t*Oa,s=_r(e),a=new Map(e.nodes.map(d=>[d.id,d])),l=[];for(let d of s){let u=d.refSpan-d.pathLength;u>=Pa&&l.push({nodeIds:d.nodeIds,bp:u});let f=Math.max(d.refSpan,r),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],M=f/d.nodeIds.length,L=S=>d.start+S*h,N=n(g);o[p]=h?[{x:L(b),y:N},{x:L(b+g.length),y:N}]:[{x:d.start+m*M,y:N},{x:d.start+(m+1)*M,y:N}]}})}let i=tt(e),c=Object.keys(o);for(let d of c){let u=o[d].at(-1).x;for(let f of i.get(d)??[]){let h=a.get(f);if(h&&!(f in o)){let p=n(h);o[f]=[{x:u,y:p},{x:u+r,y:p}],c.push(f)}}}return l}function ka(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,o)=>n-o).map((n,o)=>[n,o]))}function vr(e,t){let n=ve(e);if(n.length===0)return;let o=mt(n,t),r=ka(e),s=Pe(n),a=Lt({graph:e,span:o,rowY:i=>(i.stable?r.get(i.stable.rank)??r.size:r.size)*20,positions:s}),l=[...r].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 Ga=12,nn=20;function Pr(e){return 10+8*Math.log2(1+e.length)}function ue(e,t){return e<t?-1:e>t?1:0}function kr(e,t){return ue(e.at,t.at)||ue(e.side,t.side)||ue(e.hops,t.hops)}var Or={at:1/0,side:0,hops:0};function Ba(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=Fa(e);return e.nodes.map(o=>o.id).sort((o,r)=>kr(n.get(o)??Or,n.get(r)??Or)||ue(t.get(o).name,t.get(r).name)||ue(o,r))}function $a(e,t){let n=new Set(e.nodes.map(d=>d.id)),o=new Map(t.map(d=>[d.id,d.stable.start])),r=new Map,s=new Map;t.forEach((d,u)=>{s.set(d.id,t[u-1]?.id),r.set(d.id,t[u+1]?.id)});let a=t[0]?.id,l=(d,u)=>{let f=r.get(d);r.set(d,u),s.set(u,d),r.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),r.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 M=o.get(b);M!==void 0&&(h!==void 0&&M!==h&&(M>h?u++:f++),h=M)}let p=f>u?[...d.nodeIds].reverse():d.nodeIds,m,g=new Set;for(let b of p)if(r.has(b)){if(m===void 0)for(let M of g)i(b,M);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=r.get(d))c.push(d);return c}function Wa(e,t){let n=[...t.entries()].sort(([a,l],[i,c])=>kr(l,c)||ue(a,i)).map(([a])=>a),o=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 r=new Set(n.slice(o)),s=new Set;for(let a of r){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&&r.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 Fa(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 o=e.nodes.filter(k).sort((s,a)=>ue(s.stable.start,a.stable.start)||ue(s.name,a.name)),r=new Map;return $a(e,o).forEach((s,a)=>{r.set(s,{at:a,side:0,hops:0})}),Wa(n,r),r}function Da(e){let t=new Map(e.nodes.map(u=>[u.id,u])),n=Ba(e),o=new Map(n.map((u,f)=>[u,f])),r=u=>k(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||!o.has(u.from)||!o.has(u.to)||(o.get(u.from)<o.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=n.filter(r);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(r(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 Gr(e){if(!e.nodes.some(k))return;let t=new Map(e.nodes.map(u=>[u.id,u])),n=u=>k(t.get(u)),{layers:o,layerOf:r,preds:s}=Da(e),a=o.map(u=>{let f=0;for(let h of u)f=Math.max(f,Pr(t.get(h)));return f}),l=[],i=0;for(let u=0;u<o.length;u++)l[u]=i,i+=a[u]+Ga;let c=new Map;for(let u of o){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?nn: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/nn);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*nn)}}let d={};for(let u of e.nodes){let f=r.get(u.id),h=Pr(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 qa(e,t){let n=new Map;for(let r of e.nodes)if(ht(r)){let{sample:s}=Nt(r.stable.refName);n.set(s,(n.get(s)??0)+r.length)}let o=new Map(t.map((r,s)=>[r,s]));return[...n.keys()].sort((r,s)=>(o.get(r)??1/0)-(o.get(s)??1/0)||n.get(s)-n.get(r)||r.localeCompare(s))}function Br(e,t,n=[]){let o=ve(e),r=qa(e,n);if(o.length===0||r.length===0)return;let s=mt(o,t),a=new Map(r.map((f,h)=>[f,h+1])),l=Pe(o),i=r.length+1,c=Lt({graph:e,span:s,rowY:f=>{let h=f.stable;return((h?a.get(Nt(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:Nt(o[0].stable.refName).sample,y:0},...r.map(f=>({label:f,y:a.get(f)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:r,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function rn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var st=!1,$r=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function eo(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=>$r[t.id%$r.length]),trackAlpha:e.trackAlpha??(()=>1)}}var _=eo({}),cn=null,x=[],y=[],E=[],I=new Map,qe=[],T=[],Me=[],dn=[],fn=[],Q=-1,$=rn(),un={minX:0,maxX:0,minY:0,maxY:0},rt,Tt=new Map;function to(e,t,n=[],o={}){if(_=eo(o),cn=o.bed??null,$=rn(),Me=[],dn=[],fn=[],qe=[],un={minX:0,maxX:0,minY:0,maxY:0},rt=void 0,Tt=new Map,e.length===0||t.length===0)return;let r=on(e);x=[],r.forEach((i,c)=>{x[c+1]=i}),y=on(t);let s=n.length>0;E=on(Ai(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&&(rt=c.name)}if(y.length===0)return;Ha(0),I=Dr(),Fe(y),_.showReads&&E.length>0&&Fe(E),Jr(),_.mergeNodesFlag&&(qr(),an(),_.showReads&&E.length>0&&sn(),Ci(),I=Dr(),Jr(),Fe(y),_.showReads&&E.length>0&&Fe(E)),qr(),di(),st&&console.log(`${x.length} nodes.`),an(),Q=Hr(),fi(),an(),Q=Hr();let a=_.showReads&&_.coarsenedReadView&&!s;if(a){let i=rt===void 0?-1:y.findIndex(u=>u.name===rt),c=i===-1?0:i,d=y.filter((u,f)=>f!==c);if(d.length>0){let u=Ur(d,"haplotype");u.length>0&&(y=[y[c]],E=u)}}Ri(),gi(),_.showExonsFlag&&cn!==null&&wi();let l=_.showReads&&_.coarsenedReadView&&E.length>0&&!a;return _.showReads&&E.length>0?(Ya(),sn(),Fe(E),l&&(E=Ur(E,"read"),sn(),Fe(E)),Ka(),y=y.concat(E)):x.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),hi(),Ni(),st&&(console.log("Tracks:"),console.log(y),console.log("Nodes:"),console.log(x),console.log("Lane assignment:"),console.log(Me)),si(),{nodes:x,tracks:y,reads:E,nodeMap:I,shapes:$,bounds:un,maxOrder:Q,trackForRuler:rt,coarsenedEdgeMeta:Tt}}function De(e,t="plain"){return _.trackColor(e,t)}function Xa(e){return _.trackAlpha(e)}function on(e){return structuredClone(e)}function X(e){let t=String(e);return t.length>=1&&t.startsWith("-")}function P(e){return X(e)?String(e).substring(1):e}function de(e){return X(e)?e:`-${e}`}function no(e){return X(e)?P(e):de(e)}function Ct(e){return(e||1/e)>=0}function Ha(e){let t=new Set,n=y[e].sequence;for(let o=0;o<n.length;o+=1){let r=n[o];if(X(r)){let s=P(r),a=n.indexOf(s);(a===-1||a>o)&&t.add(s)}}for(let o of y){n=o.sequence;for(let r=0;r<n.length;r+=1){let s=n[r];X(s)?t.has(P(s))&&(n[r]=P(s)):t.has(s)&&(n[r]=de(s))}}x.forEach(o=>{o&&t.has(o.name)&&(o.seq=o.seq.split("").reverse().join(""))})}function Ya(){qe=[];for(let t=0;t<=Q;t+=1)qe[t]=[];let e=new Map;x.forEach(t=>{t.y!==void 0&&Wr(e,t.order,t.y+t.contentHeight)}),y.forEach(t=>{t.type==="haplotype"&&t.path.forEach(n=>{Wr(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,qe[t.order].push(n))})}function Wr(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var At=7;function za(){x.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),E.forEach((e,t)=>{if((e.width===void 0||e.width===0)&&(e.width=At),e.path.length===1){let n=e.path[0].node;n!==null&&x[n].internalReads.push(t)}else e.path.forEach((n,o)=>{if(o===0){let r=e.path[0].node;r!==null&&x[r].outgoingReads.push([t,o])}else{let r=n.node;r!==null&&x[r].incomingReads.push([t,o])}})})}function Ka(){ti(),za();let e=x.slice();e.sort(It);let t=new Map;for(let a=0;a<E.length;a++){let l=E[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),o=n.length>1?At:0;e.forEach(a=>{if(a)for(let l of n)ja(t.get(l),a,o)});let r=ei(),s=[];E.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(Va),s.forEach(a=>{let l=E[a.readIndex],i=l.path[a.pathIndex];i.y=r[i.order],r[i.order]+=l.width}),st&&(console.log("Reads:"),console.log(E))}function ja(e,t,n){let o=new Set(e),r=t.incomingReads.filter(([p])=>o.has(p)),s=t.outgoingReads.filter(([p])=>o.has(p)),a=t.internalReads.filter(p=>o.has(p));r.length===0&&s.length===0&&a.length===0&&(n=0);let l=t.y+t.contentHeight+n*2,i=r.map(p=>{let[m,g]=p,b=E[m].path,M=g+1,L;for(let N=1;N<=g;N++){let S=b[g-N]?.y;if(S!==void 0){M=N,L=S;break}}return{entry:p,decisionStep:M,y:L}});i.sort(Ua),r=i.map(p=>p.entry);let c=l,d=new Map;r.forEach(p=>{let m=E[p[0]];m.path[p[1]].y=c,Fr(d,m,p[1],c,t),c+=m.width});let u=c;s.sort(Qa);let f=new Map;c=l,s.forEach(p=>{let m=E[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),r.forEach(M=>{let L=E[M[0]],N=L.path[M[1]];N.y!==void 0&&N.y>=c&&(N.y+=m.width,Fr(d,L,M[1],N.y,t))}),c+=m.width,u+=m.width)}),a.sort(Ja),a.forEach(p=>{let m=E[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||At;m.path[0].y=c,d.set(c,b),u=Math.max(u,c)});let h=u-t.y-t.contentHeight;t.contentHeight+=h,Mi(t,h)}function Ua(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 Fr(e,t,n,o,r){n===t.path.length-1?e.set(o,t.finalNodeCoverLength??0):e.set(o,r.sequenceLength)}function Va(e,t){let n=E[e.readIndex],o=E[t.readIndex],r=n.path[e.pathIndex],s=o.path[t.pathIndex];if(r.order!==s.order)return r.order-s.order;if(n.sourceTrackID!==o.sourceTrackID)return n.sourceTrackID-o.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 r.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function Qa([e,t],[n,o]){let r=E[e],s=E[n],a,l,i=r.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=r.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let d=r.path[t]?.node,u=s.path[o]?.node,f=d!=null?x[d]:null,h=u!=null?x[u]:null;for(;f!=null&&h!=null&&f===h;){if(t<r.path.length-1){for(t+=1;r.path[t]?.node===null;)t+=1;let m=r.path[t]?.node;f=m!=null?x[m]:null}else f=null;if(o<s.path.length-1){for(o+=1;s.path[o]?.node===null;)o+=1;let m=s.path[o]?.node;h=m!=null?x[m]:null}else h=null}if(f!=null)return h!=null?It(f,h):1;if(h!=null)return-1;let p=(r.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(r.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function Za(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,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let a=n[r],l=o[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?r+=1:(i>c||(r+=1),s+=1)}return 0}function Ja(e,t){let n=E[e],o=E[t],r=n.firstNodeOffset??0,s=o.firstNodeOffset??0;if(r<s)return-1;if(r>s)return 1;let a=n.finalNodeCoverLength??0,l=o.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function ei(){let e=[];for(let t=0;t<=Q;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 ti(){E.forEach(e=>{let t=Math.abs(e.indexSequence[0]),n=Ct(e.indexSequence[0]),o=x[t],r,s;e.path=[],e.path.push({order:o.order,isForward:n,node:t});for(let a=1;a<e.sequence.length;a+=1)if(r=o,s=n,t=Math.abs(e.indexSequence[a]),n=Ct(e.indexSequence[a]),o=x[t],o.order>r.order){s||e.path.push({order:r.order,isForward:!0,node:null});for(let l=r.order+1;l<o.order;l+=1)e.path.push({order:l,isForward:!0,node:null});n?e.path.push({order:o.order,isForward:!0,node:t}):(e.path.push({order:o.order,isForward:!0,node:null}),e.path.push({order:o.order,isForward:!1,node:t}))}else if(o.order<r.order){s&&e.path.push({order:r.order,isForward:!1,node:null});for(let l=r.order-1;l>o.order;l-=1)e.path.push({order:l,isForward:!1,node:null});n?(e.path.push({order:o.order,isForward:!1,node:null}),e.path.push({order:o.order,isForward:!0,node:t})):e.path.push({order:o.order,isForward:!1,node:t})}else n!==s?e.path.push({order:o.order,isForward:n,node:t}):(e.path.push({order:o.order,isForward:!n,node:null}),e.path.push({order:o.order,isForward:n,node:t}))})}function sn(){E.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]=P(e.sequence[a]);let n=e.sequenceNew??[];n.reverse(),e.sequenceNew=n;for(let a of n)a.nodeName=P(a.nodeName),ni(a.mismatches,oe(a.nodeName).sequenceLength);let o=e.firstNodeOffset??0,r=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=r-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-o}})}function ni(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=ro(n.seq).split("").reverse().join(""))})}var ri={A:"T",T:"A",C:"G",G:"C"};function ro(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=ri[e.charAt(n)]??"N";return t}function Fe(e){e.forEach(t=>{t.indexSequence=[],t.sequence.forEach(n=>{let o=n,r=I.get(P(o)),s=x[r]?.switched??!1;s&&(o=no(o));let a=I.get(P(o));if(a===0)throw new Error("Node "+P(o)+" has prohibited index 0");X(o)!==s?t.indexSequence.push(-a):t.indexSequence.push(a)})})}var oi=20;function si(){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+oi+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 o=n.y??0;e.maxY=Math.max(e.maxY,o+t.width),e.minY=Math.min(e.minY,o)})}),un=e}function oe(e){let t=I.get(P(e)),n=t===void 0?void 0:x[t];if(n===void 0)throw new Error(`Unknown node ${e}`);return n}function Dr(){return I=new Map,x.forEach((e,t)=>{e&&I.set(e.name,t)}),I}function qr(){let e=x.map(()=>new Set),t=x.map(()=>new Set),n=o=>{for(let r=0;r<o.indexSequence.length-1;r+=1){let s=Math.abs(o.indexSequence[r]),a=Math.abs(o.indexSequence[r+1]);e[s].add(a),t[a].add(s)}};y.forEach(n),_.showReads&&E.length>0&&E.forEach(n),x.forEach((o,r)=>{o&&(o.successors=Array.from(e[r]),o.predecessors=Array.from(t[r]))})}function Xr(e){let t=0,n=0,o=0;e.forEach(r=>{let s=Math.abs(r);if(r<0){T[s]===void 0&&(T[s]=n);let a=T[s];a<o&&(o=a),t=a,n=a-1}else{T[s]===void 0&&(T[s]=t);let a=T[s];t=a+1,n=a}}),o<0&&pn(-o)}function ai(e){let t=0,n=0;for(;t<e.length&&T[Math.abs(e[t])]===void 0;)t+=1;if(t>=e.length)return null;let o=e[t],r,s;o>=0?(r=T[o]-1,s=-1):(r=T[-o]+1,s=1);for(let a=t-1;a>=0;a-=1){let l=Math.abs(e[a]);T[l]===void 0&&(T[l]=r,n=Math.min(n,r),r+=s)}return n<0&&pn(-n),t}var ii=-1;function li(e){let t=[];for(let n of e)t.push(n??ii);return t}function an(){let e,t,n,o,r=0,s=_.showReads&&E.length>0?y.concat(E):y,a={stamp:new Int32Array(x.length),generation:0};T=new Array(x.length).fill(void 0),x.forEach(i=>{i&&(i.order=void 0)}),Xr(y[0].indexSequence);for(let i=1;i<s.length;i+=1){if(st&&console.log(`generating order for track ${i+1}`),n=ai(s[i].indexSequence),n===null){s[i].type==="haplotype"?Xr(s[i].indexSequence):(s.splice(i,1),E.splice(i-y.length,1),i-=1);continue}for(e=ui(s[i].indexSequence);n<e.length;){for(o=n,n+=1;n<e.length&&T[e[n]]===void 0;)n+=1;if(n<e.length){t=T[e[o]]+1;for(let c=o+1;c<n;c+=1)T[e[c]]=t,t+=1;if(T[e[n]]>T[e[o]])T[e[n]]<t&&Yr(e[n],e[n-1],t);else if(s[i].indexSequence[n]>=0&&!ci(e[n],e[o],a))Yr(e[n],e[n-1],t);else if(s[i].indexSequence[o]<0||x[e[o+1]].degree<2&&T[e[n]]<T[e[o]]){t=T[e[o]]-1;for(let c=o+1;c<n;c+=1)T[e[c]]=t,r=Math.min(r,t),t-=1}}else if(s[i].indexSequence[o]>=0){t=T[e[o]]+1;for(let c=o+1;c<e.length;c+=1){let d=e[c];T[d]===void 0&&(T[d]=t,t+=1)}}else{t=T[e[o]]-1;for(let c=o+1;c<e.length;c+=1){let d=e[c];T[d]===void 0&&(T[d]=t,r=Math.min(r,t),t-=1)}}}}r<0&&pn(-r);let l=li(T);T=l,l.forEach((i,c)=>{let d=x[c];d!==void 0&&(d.order=i)})}function ci(e,t,n){n.generation+=1;let{stamp:o,generation:r}=n,s=[e];for(o[e]=r;s.length>0;){let a=s.pop();if(a===t)return!0;for(let l of x[a].successors)o[l]!==r&&(o[l]=r,s.push(l))}return!1}function Hr(){let e=-1;return T.forEach(t=>{t!==void 0&&t>e&&(e=t)}),e}function ui(e){return e.map(t=>Math.abs(t))}function pn(e){T.forEach((t,n)=>{t!==void 0&&(T[n]=t+e)})}function Yr(e,t,n){let o=new Map,r=[[e,n]],s=0;for(;s<r.length;){let[a,l]=r[s];s+=1;let i=T[a];i!==void 0&&i<l&&(!o.has(a)||o.get(a)<l)&&(o.set(a,l),x[a].successors.forEach(c=>{T[c]>i&&c!==t&&r.push([c,l+1])}),a!==e&&x[a].predecessors.forEach(c=>{T[c]>i&&c!==t&&r.push([c,l+1])}))}o.forEach((a,l)=>{T[l]=a})}function di(){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 fi(){let e=y[0],t=y.slice(1,y.length);if(_.showReads&&E.length>0&&(t=t.concat(E)),pi(t,e),_.showReads&&E.length>0){for(let n=0;n<E.length;n++)if(E[n]!==t[n+y.length-1])throw new Error("Read inequality")}}function pi(e,t){let n=new Map,o=t?new Set(t.sequence):null;for(let r of e){let s=r.sequence;for(let a=0;a<s.length;a+=1){let l=P(s[a]),i=oe(l);if(o&&!o.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)&&zr(n,l,X(s[a])?1:-1),(c===void 0||c>i.order)&&(d===void 0||i.order>d)&&zr(n,l,X(s[a])?-1:1)}}}for(let r of e)r.sequence.forEach((s,a)=>{let l=n.get(P(s));l!==void 0&&l>0&&(r.sequence[a]=no(s),r.indexSequence[a]=-r.indexSequence[a])});n.forEach((r,s)=>{if(r>0){let a=oe(s);a.seq=ro(a.seq),a.switched=!0}})}function zr(e,t,n){e.set(t,(e.get(t)??0)+n)}function hi(){let e=0,t=20,n=-1,o=x.slice();o.sort(It);let r=mi();o.forEach(s=>{s.order>=0&&(s.order>n&&(n=s.order,e=t+10*r[s.order]),s.x=e,t=Math.max(t,e+40+s.pixelWidth))})}function mi(){let e=[],t=[],n=[],o=[];for(let r=0;r<=Q;r+=1)e.push(0),t.push(0),n.push(0);y.forEach(r=>{for(let s=1;s<r.path.length;s+=1){let a=r.path[s],l=r.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])}}}),o.push(Math.max(0,e[0]-1));for(let r=1;r<=Q;r+=1)o.push(Math.max(Math.max(0,e[r]-1)+Math.max(0,t[r-1]-1),n[r]));return o}function gi(){let e,t,n,o,r,s,a=[],l=[];for(let i=0;i<=Q;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=Ct(i.indexSequence[0]),o=x[t],i.path=[],i.path.push({order:o.order,lane:null,isForward:n,node:t}),q(o.order,t,c,0,a,l),e=1;for(let d=1;d<i.sequence.length;d+=1)if(r=o,s=n,t=Math.abs(i.indexSequence[d]),n=Ct(i.indexSequence[d]),o=x[t],o.order>r.order){s||(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),q(r.order,null,c,e,a,l),e+=1);for(let u=r.order+1;u<o.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),q(u,null,c,e,a,l),e+=1;n?(i.path.push({order:o.order,lane:null,isForward:!0,node:t}),q(o.order,t,c,e,a,l),e+=1):(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),q(o.order,null,c,e,a,l),e+=1,i.path.push({order:o.order,lane:null,isForward:!1,node:t}),q(o.order,t,c,e,a,l),e+=1)}else if(o.order<r.order){s&&(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),q(r.order,null,c,e,a,l),e+=1);for(let u=r.order-1;u>o.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),q(u,null,c,e,a,l),e+=1;n?(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),q(o.order,null,c,e,a,l),e+=1,i.path.push({order:o.order,lane:null,isForward:!0,node:t}),q(o.order,t,c,e,a,l),e+=1):(i.path.push({order:o.order,lane:null,isForward:!1,node:t}),q(o.order,t,c,e,a,l),e+=1)}else n!==s?(i.path.push({order:o.order,lane:null,isForward:n,node:t}),q(o.order,t,c,e,a,l),e+=1):(i.path.push({order:o.order,lane:null,isForward:!n,node:null}),q(o.order,null,c,e,a,l),e+=1,i.path.push({order:o.order,lane:null,isForward:n,node:t}),q(o.order,t,c,e,a,l),e+=1)});for(let i=0;i<=Q;i+=1)xi(Me[i],i)}function q(e,t,n,o,r,s){let a={trackID:n,segmentID:o,compareToFromSame:r[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);r[e][n]=a}function bi(e,t){let n;e.forEach(o=>{o.idealLane=0,o.tracks.forEach(r=>{if(r.segmentID===0)r.idealLane=r.trackID,r.idealY=null;else if(y[r.trackID].path[r.segmentID-1].order===t-1)r.idealLane=y[r.trackID].path[r.segmentID-1].lane??void 0,r.idealY=y[r.trackID].path[r.segmentID-1].y;else if(r.segmentID<y[r.trackID].path.length-1&&y[r.trackID].path[r.segmentID+1].order===t-1)r.idealLane=y[r.trackID].path[r.segmentID+1].lane??void 0,r.idealY=y[r.trackID].path[r.segmentID+1].y;else{for(n=r.segmentID-1;n>=0&&y[r.trackID].path[n].order!==t-1;)n-=1;n<0?(r.idealLane=r.trackID,r.idealY=null):(r.idealLane=y[r.trackID].path[n].lane??void 0,r.idealY=y[r.trackID].path[n].y)}o.idealLane+=r.idealLane}),o.idealLane/=o.tracks.length})}function xi(e,t){let n=0,o=new Set,r=20,s=!1,a=-1;bi(e,t),e.sort(jr),e.forEach(l=>{l.node!==null?(x[l.node].topLane=n,s&&(r-=10),x[l.node].y=r,x[l.node].contentHeight=0,s=!1):(s?r-=25:r>20&&(r-=10),s=!0),l.tracks.sort(jr),l.tracks.forEach(i=>{i.lane=n,i.trackID===a&&l.node===null&&s&&(r+=10),y[i.trackID].path[i.segmentID].lane=n,y[i.trackID].path[i.segmentID].y=r,i.idealY!=null&&o.add(i.idealY-r),n+=1,r+=y[i.trackID].width,l.node!==null&&(x[l.node].contentHeight+=y[i.trackID].width),a=i.trackID}),r+=25}),yi(e,o)}function yi(e,t){let n=0,o=Number.MAX_SAFE_INTEGER;t.forEach(r=>{Kr(e,r)<o&&(o=Kr(e,r),n=r)}),e.forEach(r=>{r.node!==null&&(x[r.node].y+=n),r.tracks.forEach(s=>{let a=y[s.trackID].path[s.segmentID];a.y=a.y+n})})}function Mi(e,t){e.order<0||Me[e.order]===void 0||(Me[e.order].forEach(n=>{if(n.node!==null){let o=x[n.node];o!==e&&o.y>e.y&&(o.y+=t,n.tracks.forEach(r=>{let s=y[r.trackID].path[r.segmentID];s.y=s.y+t}))}else n.tracks.forEach(o=>{let r=y[o.trackID].path[o.segmentID];r.y>=e.y&&(r.y=r.y+t)})}),qe[e.order].length>0&&qe[e.order].forEach(n=>{x[n]!==e&&x[n].y>e.y&&(x[n].y+=t)}))}function Kr(e,t){let n=0;return e.forEach(o=>{o.tracks.forEach(r=>{r.idealY!=null&&y[r.trackID].type!=="read"&&(n+=Math.abs(r.idealY-t-y[r.trackID].path[r.segmentID].y)*y[r.trackID].width)})}),n}function jr(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 It(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 wi(){let e,t,n={};cn.forEach(o=>{let r=0;for(;r<y.length&&y[r].name!==o.track;)r+=1;r<y.length&&(e=0,y[r].path.forEach(s=>{s.node!==null&&(n={},t=e+x[s.node].sequenceLength-1,e>=o.start&&e<=o.end&&(n.start=0),e<o.start&&t>=o.start&&(n.start=o.start-e),t<=o.end&&t>=o.start&&(n.end=t-e,t<o.end&&(n.continue=!0)),t>o.end&&e<=o.end&&(n.end=o.end-e),n.start!==void 0&&(n.type=o.type,n.name=o.name,s.features===void 0&&(s.features=[]),s.features.push(n)),e=t+1)}))})}function Ri(){let e=!0,t=4,n=_.trackWidth;y.forEach(o=>{o.freq!==void 0?o.width=Math.round((Math.log(o.freq)+1)*t):(o.width=n,o.type!==void 0&&o.type==="read"&&(o.width=t)),o.width!==t&&(e=!1)}),e&&y.forEach(o=>{o.freq!==void 0&&(o.width=n)})}function Si(e){let t=e.path[0],n=x[t.node],o=e.firstNodeOffset??0;return hn(n,t.isForward?o:n.sequenceLength-o)}function Ei(e){let t=e.path[e.path.length-1],n=x[t.node],o=e.finalNodeCoverLength??0;return hn(n,t.isForward?o:n.sequenceLength-o)}function oo(e,t){return t>e.sequenceLength?null:hn(e,t)}function hn(e,t){let[n,o]=Ti(e);if(e.sequenceLength===0)return n;let r=Math.min(Math.max(t,0),e.sequenceLength);return n+r/e.sequenceLength*(o-n)}function Ni(){let e,t,n,o,r,s,a,l,i;for(let u=0;u<=Q;u+=1)dn.push(0),fn.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(Za),y.forEach(u=>{a="plain",r=De(u,a),s=Xa(u);let f=a,h=()=>(f!==a&&(f=a,r=De(u,a)),r);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=Si(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=Vr(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,r,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&&(r=h(),$.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:r,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],o=u.path[p].y,r=h(),$.curves.push({xStart:e,yStart:n,xEnd:t+1,yEnd:o,width:u.width,color:r,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=o):u.path[p].order+1===u.path[p-1].order?(e=t,t=d[u.path[p].order],o=u.path[p].y,r=h(),$.curves.push({xStart:e+1,yStart:n,xEnd:t,yEnd:o,width:u.width,color:r,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=o):u.path[p-1].isForward?(o=u.path[p].y,Zr(1,t,n,o,u.width,r,u.id,u.path[p].order,u.type,u.name),e=d[u.path[p].order],n=u.path[p].y):(o=u.path[p].y,Zr(-1,t,n,o,u.width,r,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=Vr(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,r,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=Ei(u),$.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:r,alpha:s,id:u.id,name:u.name,type:u.type})})}var Li=1e9;function Ur(e,t){Tt=new Map;let n=new Map,o=_.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),M=Math.abs(g),L=x[b],N=x[M];if(!L||!N)continue;let S;if(o){let w=`${m}>${g}`,C=`${-g}>${-m}`;S=w<C?w:C}else S=`${m}>${g}`;let R=n.get(S);R===void 0?n.set(S,{sSigned:m,dSigned:g,sName:m<0?`-${L.name}`:L.name,dName:g<0?`-${N.name}`:N.name,count:1,sourceTrackID:f.sourceTrackID}):R.count+=1}}let r=0;for(let f of n.values())f.count>r&&(r=f.count);let s=At,a=60,l=f=>r<=1?s:s+(a-s)*Math.sqrt(f/r),i=[],c=0;for(let f of n.values()){let h=Li+c,p=`${f.count.toLocaleString()} ${t}${f.count===1?"":"s"}: Node ${f.sName} \u2192 Node ${f.dName}`;Tt.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 st&&console.log(`[coarsened] ${t}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${d}(${u.toFixed(1)})`),i}function Vr(e,t,n,o,r,s,a,l,i){let c=o,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=De(r,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=De(r,m.type),$.featureRectangles.push({xStart:f,yStart:a,xEnd:h,yEnd:a+r.width-1,color:u,id:r.id,name:r.name,type:r.type})),f>s+1&&$.featureRectangles.push({xStart:s,yStart:a,xEnd:f-1,yEnd:a+r.width-1,color:d,id:r.id,name:r.name,type:r.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=De(r,m.type),$.featureRectangles.push({xStart:h,yStart:a,xEnd:f,yEnd:a+r.width-1,color:u,id:r.id,name:r.name,type:r.type})),s>f+1&&$.featureRectangles.push({xStart:f+1,yStart:a,xEnd:s,yEnd:a+r.width-1,color:d,id:r.id,name:r.name,type:r.type})),s=f,c=m.type),(m.end<p-1||m.continue===void 0)&&(d=De(r,c),e.isForward?(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,$.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+r.width-1,color:d,id:r.id,name:r.name,type:r.type})):(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,$.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+r.width-1,color:d,id:r.id,name:r.name,type:r.type})),s=h+1,c="plain")}),{xStart:s,highlight:c}}var Qr=7;function Zr(e,t,n,o,r,s,a,l,i,c){let d=e===1?fn:dn,u=10*d[l],f=t+e*(u+5),h=Qr,p=Math.min(Qr,r),m=Math.min(n,o),g=Math.max(n,o),b=e===1?t:f-1,M=e===1?f:t,L=w=>{$.verticalRectangles.push({xStart:b,yStart:w,xEnd:M,yEnd:w+r-1,color:s,id:a,name:c,type:i})};L(n),$.verticalRectangles.push({xStart:e===1?f+h:f-h-p,yStart:m+r+h-1,xEnd:e===1?f+h+p-1:f-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),L(o);let N=f+e*h,S=f+e*(h+p),R=`M ${f} ${g}`;R+=` Q ${N} ${g} ${N} ${g-h}`,R+=` H ${S}`,R+=` Q ${S} ${g+r} ${f} ${g+r}`,R+=" Z ",$.corners.push({path:R,color:s,id:a,type:i}),R=`M ${f} ${m}`,R+=` Q ${S} ${m} ${S} ${m+r+h}`,R+=` H ${N}`,R+=` Q ${N} ${m+r} ${f} ${m+r}`,R+=" Z ",$.corners.push({path:R,color:s,id:a,type:i}),d[l]+=1}function Ti(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function Jr(){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 Ci(){let e,t,n=Array.from(x,()=>new Set),o=Array.from(x,()=>new Set),r;_.showReads&&E.length>0?r=y.concat(E):r=y,r.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)X(l.sequence[i])?(e=P(l.sequence[i]),i>0?(t=l.sequence[i-1],X(t)?o[I.get(e)].add(P(t)):(o[I.get(e)].add(t),o[I.get(e)].add(de(t)))):l.type==="haplotype"&&o[I.get(e)].add("None"),i<l.sequence.length-1?(t=l.sequence[i+1],X(t)?n[I.get(e)].add(P(t)):(n[I.get(e)].add(t),n[I.get(e)].add(de(t)))):l.type==="haplotype"&&n[I.get(e)].add("None")):(i>0?(e=l.sequence[i-1],n[I.get(l.sequence[i])].add(e),X(e)&&n[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&n[I.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],o[I.get(l.sequence[i])].add(e),X(e)&&o[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&o[I.get(l.sequence[i])].add("None"))});let s=n.map(l=>Array.from(l)),a=o.map(l=>Array.from(l));if(_.showReads&&E.length>0){let l=x.slice();l.sort(It);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=ot(I.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)}),E.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=P(f.sequence[p]),g=ot(I.get(m),s,a);if(g&&ln(I.get(g),s,a))if(p>0){f.sequence.splice(p,1);let b=oe(g).sequenceLength;h[p].mismatches.forEach(M=>{M.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],M=d(b.nodeName);b.mismatches.forEach(L=>{L.pos+=M}),b.nodeName=u(b.nodeName)}}})}for(let l=0;l<x.length;l+=1)if(ln(l,s,a)&&!ot(l,s,a)){let i=l;for(;ln(i,s,a);)i=I.get(P(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=P(l.sequence[i]);let c=I.get(e);ot(c,s,a)&&l.sequence.splice(i,1)}});for(let l=x.length-1;l>=0;l-=1)ot(l,s,a)&&x.splice(l,1)}function ot(e,t,n){if(t[e].length!==1||t[e][0]==="None")return!1;let o=P(t[e][0]),r=I.get(o);return n[r].length!==1||n[r][0]==="None"?!1:o}function ln(e,t,n){if(n[e].length!==1||n[e][0]==="None")return!1;let o=P(n[e][0]),r=I.get(o);return!(t[r].length!==1||t[r][0]==="None")}function Ai(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 Ii(e,t){let n=new Map;for(let o of e){let r=t(o),s=n.get(r);s===void 0?n.set(r,[o]):s.push(o)}return n}function _i(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 so(e,t){let n=Ii(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(_i),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 o=Array.from(n.keys());o.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 r=[];for(let s of o){let a=n.get(s);a!==void 0&&r.push(...a)}return r}function ao(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,o=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n+9} ${o} ${n+9} ${o+9}`,n+=9,o+=9,e.contentHeight>0&&(o+=e.contentHeight-0,t+=` L ${n} ${o}`),t+=` Q ${n} ${o+9} ${n-9} ${o+9}`,n-=9,o+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n-9} ${o} ${n-9} ${o-9}`,n-=9,o-=9,e.contentHeight>0&&(o-=e.contentHeight-0,t+=` L ${n} ${o}`),t}function vi(e){let t=new Map;for(let[n,o]of e.pathVisits??[])for(let r of o){let s=`${r.path} ${n}`,a=t.get(s);a?a.push(r.strand):t.set(s,[r.strand])}return t}function Pi(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=vi(e),o=(e.paths??[]).map((s,a)=>({path:s,index:a})),r=o.findIndex(s=>le(s.path.name).name===e.referencePath);return r>0&&o.unshift(...o.splice(r,1)),o.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]??en(u);return[tn(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Oi(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function Xe(e){return(e.paths?.length??0)>0}var ki=600,Gi=3,Bi=15;function $i(e){return Math.max(Gi,Math.min(Bi,Math.floor(ki/Math.max(1,e))))}function io(e){let t=e.paths??[],n=Pi(e),o=e.reads?Cr(e,e.reads,t.length):[],r=o.length>0?Dn:Fn,s=t.map((l,i)=>r(i,t.length)),a=to(Oi(e),n,o,{nodeWidthOption:"compressed",trackWidth:$i(n.length),trackColor:l=>l.type==="read"?Ar(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function mn(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function lo(e,t,n,o){let r=e.y+e.contentHeight/2-t;return[{x:n,y:r},{x:o,y:r}]}function co(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function uo(e){let t=Xe(e)?io(e):void 0;if(!t)return;let{layout:n,pathColors:o}=t,r=n.bounds.minY,s={};for(let i of mn(n))s[i.name]=lo(i,r,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=co(n,r);return{nodePositions:s,tubeMap:{layout:n,yOffset:r,pathColors:o},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:l}}}function Wi(e,t){let n=new Map(e.nodes.map(l=>[l.id,l])),o=new Map;for(let l of mn(t)){let i=o.get(l.order);i?i.push(l):o.set(l.order,[l])}let r=[],s=-1/0;for(let l of[...o.keys()].sort((i,c)=>i-c)){let i=o.get(l),c=1/0,d=-1/0;for(let u of i){let f=n.get(u.name);f&&k(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),r.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=r.find(l=>l.bp0!==-1/0);for(let l of r)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return r}function Fi(e){return e.nodes.some(k)&&Xe(e)}function fo(e){let t=Fi(e)?io(e):void 0;if(!t)return;let{layout:n,pathColors:o}=t,r=Wi(e,n),s=new Map(r.map(i=>[i.order,i])),a=n.bounds.minY,l={};for(let i of mn(n)){let c=s.get(i.order);l[i.name]=lo(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:n,yOffset:a,columns:r,pathColors:o},referenceAxis:!0,pixelRows:!0,extent:co(n,a)}}function po(e){return e.sample??ft(e.name)}function Di(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:po(e)}function qi(e,t){let n=[],o;for(let r of e){o!==void 0&&r.start!==void 0&&r.start>o&&n.push(r.start-o),n.push(...r.nodeIds);let s=r.nodeIds.reduce((a,l)=>a+(t.get(l)??0),0);o=r.start===void 0?void 0:r.start+s}return n}function Xi(e,t){let n=[],o;for(let r of e){if(r.start===void 0||o!==void 0&&r.start<o)return;o!==void 0&&r.start>o&&n.push({start:o,end:r.start});let s=r.start;for(let a of r.nodeIds){let l=t.get(a)??0;n.push({start:s,end:s+l}),s+=l}o=s}return n}function Hi(e,t,n,o=!0){if(!n||!o)return{ids:e,complete:!0,from:-1,to:-1};let r=-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,r=d),u.start>=n.end&&u.start<l&&(l=u.start,s=d))}),r<0||s<0)return{ids:e,complete:!1,from:-1,to:-1};let i=e.slice(Math.min(r,s)+1,Math.max(r,s));return{ids:r<s?i:i.reverse(),complete:!0,from:r,to:s}}function ju(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,o)=>t.indexOf(n.sample)-t.indexOf(o.sample)||n.label.localeCompare(o.label)):e}function ho(e,t,n){let o=e.paths??[],r=g=>le(g.name).name===e.referencePath,s=o.some(r)?o.filter(r).sort((g,b)=>(g.start??0)-(b.start??0)):o.slice(0,1),a=s[0],l=o.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 M of g.nodeIds){let L=c.get(M)??0;f.has(M)||f.set(M,{start:b,end:b+L}),b+=L}}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],M=[...g].sort((Y,V)=>(Y.start??0)-(V.start??0)),{ids:L,complete:N,from:S,to:R}=Hi(qi(M,c),f,u,h),w=Xi(M,c),C=b.contig??pt(le(b.name).name),O=w?.length?S<0?{contig:C,start:w[0].start,reversed:!1}:S<R?{contig:C,start:w[S].end,reversed:!1}:{contig:C,start:w[S].start,reversed:!0}:void 0,H=[],B=0,pe=0,Se=0,se=0;for(let Y of L){if(typeof Y=="number"){H.push({start:B,bp:Y,onReference:!1,gap:!0}),B+=Y,Se+=Y,se=0;continue}let V=c.get(Y)??0,j=f.get(Y),U=H.at(-1),Ee=U?.referenceStart,Ye=j&&Ee!==void 0&&se>=0&&Ee+U.bp===j.start,v=j&&Ee!==void 0&&se<=0&&j.end===Ee;!j&&U&&!U.onReference&&!U.gap?U.bp+=V:Ye||v?(U.bp+=V,Ye||(U.referenceStart=j.start,U.reversed=!0),se=Ye?1:-1):(H.push({start:B,bp:V,onReference:j!==void 0,referenceStart:j?.start}),se=0),B+=V,j||(pe+=V)}return{name:b.name,label:Di(b),sample:po(b),haplotype:b.haplotype,bp:B,offReferenceBp:pe,gapBp:Se,complete:N,runs:H,axis:O}};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 Yi=1.3;function zi(e){let t=e.reference.bp;for(let n of e.rows)t=Math.max(t,n.bp);return{maxX:e.origin+t*Yi,maxY:e.rows.length*20}}function mo(e,t){let n=ve(e),o=ho(e,t);if(n.length===0||!o)return;let r=t?n.filter(l=>Ln(l,t)):n,s=Pe(r.length>0?r:n),a=[{label:o.reference.label,y:0},...o.rows.map((l,i)=>({label:l.label,y:(i+1)*20}))];return{nodePositions:s,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:zi(o)}}var Ki="Force-directed layout",we=e=>e.nodes.some(k),go=e=>we(e)&&(e.paths?.length??0)>1,bo=e=>we(e)&&Xe(e),xo=e=>we(e)&&e.nodes.some(ht),gn=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:vr,cutMargins:!0,wholeWalks:!1,available:we,drawsLocally:we,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:Br,cutMargins:!0,wholeWalks:!1,available:xo,drawsLocally:xo,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:mo,cutMargins:!1,wholeWalks:!0,available:go,drawsLocally:go,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:Gr,cutMargins:!1,wholeWalks:!1,available:we,drawsLocally:we,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:uo,cutMargins:!1,wholeWalks:!1,available:Xe,drawsLocally:Xe,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:fo,cutMargins:!0,wholeWalks:!1,available:bo,drawsLocally:bo,drawsNodes:!1},{value:"force",label:Ki,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],ad=gn.map(e=>e.value);function id(e,t){return!ji(e).drawsLocally(t)}function ji(e){return gn.find(t=>t.value===e)??gn[0]}var So=K(ke(),1);var Ui=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],Eo=[{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"}],yo=["blue","red","purple","green"],Vi=e=>Ui.some(t=>t.value===e),Qi=e=>Eo.some(t=>t.value===e);function ud(e,t,n,o=!0){let{field:r,scheme:s}=e.color??{},a=Vi(r)?r:o?"progress":"walk",l=t?"grey":yo[n%yo.length],i=Qi(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var No=.5,Zi=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Ji=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function Mo(e){let[t,n,o]=[1,3,5].map(l=>Zi(Number.parseInt(e.slice(l,l+2),16)/255)),r=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*o),s=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*o),a=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*o);return[.2104542553*r+.793617785*s-.0040720468*a,1.9779984951*r-2.428592205*s+.4505937099*a,.0259040371*r+.7827717662*s-.808675766*a]}function el([e,t,n]){let o=(e+.3963377774*t+.2158037573*n)**3,r=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*o-3.3077115913*r+.2309699292*s,-1.2684380046*o+2.6097574011*r-.3413193965*s,-.0041960863*o-.7034186147*r+1.707614701*s].map(a=>Ji(Math.max(0,Math.min(1,a)))*255)}function Lo(e,t){let n=Math.max(0,Math.min(1,t)),o=Eo.find(a=>a.value===e);if(!o||!("ends"in o))return Be(n*$e,.7,.5).map(a=>a*255);let r=Mo(o.ends[0]),s=Mo(o.ends[1]);return el(r.map((a,l)=>a+(s[l]-a)*n))}function wo(e,t){let[n,o,r]=Lo(e,t).map(Math.round);return`rgb(${n}, ${o}, ${r})`}function Ro(e,t){let[n,o,r]=Lo(e,t).map(Math.round);return(0,So.packAbgr)(n,o,r,255)}function dd({field:e,scheme:t},n){return e==="walk"?Ro(t,No):n===void 0?tl:Ro(t,n)}var tl=zt;function nl({field:e,scheme:t}){return e==="walk"?[{offset:0,color:wo(t,No)}]:Array.from({length:7},(n,o)=>({offset:o/6,color:wo(t,o/6)}))}function fd(e){let t=nl(e);return t.length===1?t[0].color:`linear-gradient(to right, ${t.map(n=>`${n.color} ${n.offset*100}%`).join(", ")})`}function hd({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function a(i){let c=Math.ceil(e/i),d=Math.floor((o-(i-1)*8)/i),u=(r-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 md(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 To(e,t){let n=new Map(t.map((r,s)=>[r,s])),o=r=>n.get(r)??t.length;return e.map((r,s)=>({name:r,i:s})).sort((r,s)=>o(r.name)-o(s.name)||r.i-s.i).map(({name:r})=>r)}function gd(e,t,n=[]){let o=To(e,n),r={columns:void 0,count:e.length,cells:e.map(c=>o.indexOf(c))};if(t==="walk")return r;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=To([...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?r:{columns:l,count:a.length*l,cells:i}}var rl=10;function ol(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=rl*(r.end-r.start)&&(n===0?r.start<=e.start&&e.start<=r.end:Math.min(e.end,r.end)-Math.max(e.start,r.start)>=n/2))}var sl=40;function Re(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function al(e,t){let n=Re(e),o=Re(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function Co(e){return e>=Xn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function yd(e,t=[]){let n=il(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function il(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:a,inversion:l}=e,i=al(o,r);if(a>=sl)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${Co(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Re(r)} inv`};let c=r!==o?ol(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${Co(s)}`}}let d=s>2?`, ${s} alleles`:"";return o===r&&o===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Re(n)} sub`}:n===0||o===n?{kind:"insertion",label:`\u2264${Re(r-n)} ins${d}`}:r===n?{kind:"deletion",label:`${Re(n-o)} del${d}`}:{kind:"complex",label:`${Re(n)} ref \u2192 ${i}, ${s} alleles`}}var Md={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},wd={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function Rd(e){return e.segments.split(",").filter(Boolean)}var Io="#2f8fd6",_o="#8e3fbf",vo="#bdbdbd",_t="#1c1c22",Po=12,Oo=4,ll=3;function at(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Ao(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function cl(e,t,n,o){let{bp:r,gapBp:s,complete:a}=e;if(!t)return`${at(r)}${Ao(r,n)}`;let l=r-t.bp,i=l===0?"":` (${l>0?"+":"\u2212"}${at(Math.abs(l))})`,c=s>0?` \xB7 ${at(s)} outside the cut`:"",d=o?` \xB7 called ${at(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${at(r)}${Ao(r,n)}${i}${c}${a?"":" \xB7 partial walk"}${d}`}function ul(e,t,n){let o=t+6;return o+e.length*6.2<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function dl(e,t,n){if(t*n<ll)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function fl(e,t){if(e.gap)return{fill:vo};if(!t)return{fill:e.onReference?Io:_o};if(e.referenceStart===void 0)return{fill:Kt};let n=sr({...e,start:e.referenceStart},t);return n.length===1?{fill:Rt(n[0])}:{stops:n.map(Rt)}}function vt(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function Ad(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function Id(e,t){let n=new Map;for(let o of e){let r=t.get(o.name);if(!o.axis||!r)continue;let s=o.axis,a=({start:l,end:i})=>({start:Math.max(0,l),end:Math.min(o.bp,i)});n.set(o.name,r.map(l=>({name:l.name,...a(vt(s,l.start,l.end)),exons:l.exons.map(i=>a(vt(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 pl=9,hl=5.2,ml=8,ko=(e,t)=>Math.min(2,(e-t)/2-1);function xn(e,t){return ko(e,t)>=1}function gl(e,t,n,{rowPx:o=20,barPx:r=Po}={}){if(!xn(o,r))return[];let s=ko(o,r),a=e.map(c=>{let d=t(c.start);return{g:c,x:d,w:Math.max(2,t(c.end)-d)}}),l=[],i=new Set((r>=ml?[...a]:[]).sort((c,d)=>c.w-d.w).filter(({g:c,x:d,w:u})=>{let f=c.name.length*hl/2,h=[d+u/2-f,d+u/2+f];return 2*f>u+6||l.some(([p,m])=>h[0]<m+2&&h[1]>p-2)?!1:(l.push(h),!0)}));return a.map(c=>({name:c.g.name,x:c.x,y:n-r/2-s,w:c.w,h:r+2*s,exons:c.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:i.has(c)?{x:c.x+c.w/2,y:n+3,size:pl}:void 0}))}var bn=e=>`${e} row${e===1?"":"s"}`;function _d(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??ar,ramp:!0}:{kind:"bar",fill:Io},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Kt:_o},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(o=>o.gapBp>0)&&n.push({swatch:{kind:"gap",fill:vo},label:"walked outside the cut"}),t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):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 ${bn(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${bn(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${bn(t.genes.unread)}`,note:!0})),n}var bl="#111",xl="#9e9e9e",yl="#c62828";function vd(e,t,n,o="walk-key"){let r=0,s=e.flatMap((a,l)=>{let i=`${o}-ramp-${l}`,c=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?A("linearGradient",{id:i},...Qt.map(f=>A("stop",{offset:f.offset,"stop-color":f.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?A("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:_t,"stroke-width":1.5}):A("rect",{x:r,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Oo:8,rx:2,fill:c?`url(#${i})`:a.swatch.fill}),u=A("text",{x:a.note?r:r+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return r+=(a.note?0:23)+a.label.length*6.2+16,[c,d,u].filter(f=>f!==void 0)});return{width:r,tree:A("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function Ml(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let l=0,i=0;for(let u of r)u.onReference?l+=u.bp:i+=u.bp;let c=l>=i,d=r.find(u=>u.onReference===c);o.push({start:r[0].start,bp:l+i,onReference:c,referenceStart:c?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}r=[]}},a=0;for(let l of e){if(l.gap||l.bp>=n){s(),a=0,o.push(l);continue}r.push(l),a+=l.bp,a>=n&&(s(),a=0)}return s(),o}function wl(e,t,n){return A("g",{class:"row-gene","data-testid":"graph-walk-gene"},A("title",{},e.name),...e.exons.map(o=>A("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:_t,opacity:.35})),A("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:_t,"stroke-width":1.5}),e.label&&A("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:_t,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function Pd(e,t,n={}){let o=p=>p*t.scaleX+t.translateX,r=t.rowPx??20,s=t.barPx??Po,a=p=>p*r*t.scaleY+t.translateY,{origin:l,unit:i,reference:c,rows:d}=e,u=p=>o(l+p),f=n.idPrefix??"walkrow",h=(p,m)=>{let g=a(m);if(g<-s||g>t.height+s)return;let b=Ml(p.runs,t.scaleX).flatMap(w=>{let C=fl(w,n.ramp),O=w.gap?Math.min(Oo,s):s,H=`${f}-${m}-${w.start}`,B=A("rect",{x:u(w.start),y:g-O/2,width:Math.max(1,w.bp*t.scaleX),height:O,fill:"stops"in C?`url(#${H})`:C.fill});return"stops"in C?[A("linearGradient",{id:H},...C.stops.map((pe,Se)=>A("stop",{offset:Se/(C.stops.length-1),"stop-color":pe}))),B]:[B]}),M=i?dl(p.bp,i,t.scaleX).map(w=>A("line",{x1:u(w),x2:u(w),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:L}=p,N=cl(p,m===0?void 0:c,i,L),S=ul(N,u(p.bp),t.width),R=t.readouts??!0;return A("g",{"data-testid":m===0?"graph-walk-reference":"graph-walk-row"},...b,...M,...gl(n.rowGenes?.get(p.name)??[],u,g,{rowPx:r,barPx:s}).map(w=>wl(w,g,s)),L&&A("rect",{"data-testid":"graph-walk-call",x:u(L.bp)-1,y:g-s/2-3,width:2,height:s+6,fill:L.spanningReads===0?xl:bl}),R&&A("text",{x:S.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:L?.agrees===!1?yl:"#333",stroke:S.halo?"white":void 0,"stroke-width":S.halo?3:void 0,"paint-order":"stroke","text-anchor":S.anchor},N))};return A("g",{},...[c,...d].map(h))}var it=6,Rl=260,Sl=11,El=3,Nl=12,Ll=1.3,Tl="#111",Go=3;function Fd(e,t,n){let o=e.pathVisits?.get(n.name)??[],r=[];for(let s of t){let a=s.axis;if(!a)continue;let l=le(s.name).name;for(let i of o){if(i.path!==l)continue;let{start:c,end:d}=vt(a,i.start,i.start+n.length);d>0&&c<s.bp&&r.push({row:s.name,start:c,bp:d-c})}}return r}var Bo=new WeakMap;function Cl(e,t){let n=Bo.get(e);if(n||(n=new Map,Bo.set(e,n)),n.has(t))return n.get(t);let o=new Map(e.nodes.map(a=>[a.id,a.length])),r=(e.paths??[]).filter(a=>a.name===t),s;if(r.every(a=>a.start!==void 0)){s={ids:[],starts:[],ends:[]};for(let a of[...r].sort((l,i)=>l.start-i.start)){let l=a.start;for(let i of a.nodeIds){let c=o.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 Dd(e,t,n,o){let r=t.axis,s=r&&Cl(e,t.name);if(!r||!s||n<0||n>t.bp)return;let a=r.reversed?r.start-n:r.start+n,l=.5/o,i=r.reversed?{start:r.start-t.bp,end:r.start}:{start:r.start,end:r.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],M=s.starts[g]<=a&&a<s.ends[g];(b>p||b===p&&M&&!m)&&(p=b,h=s.ids[g],m=M)}return h}function qd(e,t){let n=t.maxHeight??Rl,o=t.labelPx??Math.max(...[e.reference,...e.rows].map(h=>h.label.length))*6.2+16,r=e.rows.length+1,s=Math.max(El,Math.min(20,Math.floor((n-2*it)/r))),a=s>=Nl,l=s>=14,i=Math.max(2,Math.round(s*.6)),c=Math.max(e.reference.bp,...e.rows.map(h=>h.bp),1),d=a?o:it,f=Math.max(1,t.width-d-it)/(c*(l?Ll:1));return{scaleX:f,scaleY:1,translateX:d-e.origin*f,translateY:it+s/2,width:t.width,height:r*s+2*it,rowPx:s,barPx:i,readouts:l,labelled:a,boxesGenes:xn(s,i)}}function Xd(e,t,n,o){let r=Math.round((o-t.translateY)/t.rowPx),s=[e.reference,...e.rows][r],a=(n-t.translateX)/t.scaleX-e.origin;return s&&r>=0&&a>=0&&a<=s.bp?{index:r,row:s,offset:a}:void 0}function Hd(e,t,n){let o=new Map([e.reference,...e.rows].map((s,a)=>[s.name,a])),r=s=>(e.origin+s)*t.scaleX+t.translateX;return A("g",{"data-testid":"graph-walk-marks"},...n.flatMap(s=>{let a=o.get(s.row);if(a===void 0)return[];let l=a*t.rowPx+t.translateY,i=r(s.start),c=Math.max(2,s.bp*t.scaleX),d=u=>A("rect",{x:i,y:u,width:c,height:Go,fill:Tl});return[d(l-t.barPx/2-Go-1),d(l+t.barPx/2+1)]}))}function Yd(e,t,n=new Set){return A("g",{"font-family":"sans-serif","font-size":Sl,fill:"#333"},...(t.labelled?[e.reference,...e.rows]:[]).map((o,r)=>A("text",{x:6,y:r*t.rowPx+t.translateY+4,"font-weight":n.has(o.name)?600:void 0},o.label)))}function zd(e,t,n){if(t?.size)return e.boxesGenes?n:{untracked:0,unread:0,...n,crowded:!0}}var He=K(ke(),1),Xo=K(Wo(),1),Ho=K(Do(),1);var qo=class extends Ho.Canvas2DRenderingBackendBase{constructor(){super(...arguments);this.transform=null;this.batch=null;this.nodeHighlights=new Map;this.highlightedEdge=null;this.highlightFactor=1}resize(n,o){(0,Xo.syncCanvasSize)(this.ctx.canvas,n,o)}uploadGeometry(n){this.batch=n,this.highlightedEdge=null}setNodeHighlights(n){this.nodeHighlights=n}setEdgeHighlight(n,o){this.highlightedEdge=n,this.highlightFactor=o}updateTransform(n){this.transform=n}render(n){if(!this.transform)return;let r=this.ctx,{width:s,height:a}=r.canvas;n[3]<1&&r.clearRect(0,0,s,a),r.fillStyle=(0,He.normalizedRgbToCssRgba)([n[0],n[1],n[2]],n[3]),r.fillRect(0,0,s,a);let l=this.batch;l&&(r.lineCap="round",r.lineJoin="round",this.renderEdges(l),this.renderNodes(l),this.renderArrows(l))}renderEdges(n){let o=this.transform,r=this.ctx,s=this.highlightedEdge===null?void 0:n.edgeCurveRuns.get(this.highlightedEdge);for(let{color:a,items:l}of yn(n.edgeCurves,(i,c)=>({color:Pt(s,c)?yt(i.color,this.highlightFactor):i.color,weight:i.thickness,last:Pt(s,c)}))){r.strokeStyle=(0,He.abgrToCssRgba)(a),r.lineWidth=l[0].thickness*2*o.dpr,r.beginPath();for(let i of l){let c=i.curves[0];r.moveTo(c.x0*o.scaleX+o.translateX,c.y0*o.scaleY+o.translateY);for(let d of i.curves)r.bezierCurveTo(d.cx0*o.scaleX+o.translateX,d.cy0*o.scaleY+o.translateY,d.cx1*o.scaleX+o.translateX,d.cy1*o.scaleY+o.translateY,d.x1*o.scaleX+o.translateX,d.y1*o.scaleY+o.translateY)}r.stroke()}}renderNodes(n){let o=this.transform,r=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 yn(n.nodeStrokes,(i,c)=>{let d=s.get(c);return{color:d===void 0?i.color:yt(i.color,d),weight:i.thickness,last:d!==void 0}})){r.strokeStyle=(0,He.abgrToCssRgba)(a),r.lineWidth=l[0].thickness*2*o.dpr,r.beginPath();for(let i of l){let c=i.points[0];r.moveTo(c.x*o.scaleX+o.translateX,c.y*o.scaleY+o.translateY);for(let d=1,u=i.points.length;d<u;d++){let f=i.points[d];r.lineTo(f.x*o.scaleX+o.translateX,f.y*o.scaleY+o.translateY)}}r.stroke()}}renderArrows(n){let o=this.transform,r=this.ctx,s=this.highlightedEdge===null?void 0:n.arrowRuns.get(this.highlightedEdge);for(let{color:a,items:l}of yn(n.arrows,(i,c)=>({color:Pt(s,c)?yt(i.color,this.highlightFactor):i.color,weight:0,last:Pt(s,c)}))){r.fillStyle=(0,He.abgrToCssRgba)(a),r.beginPath();for(let i of l){let[c,d,u,f]=Il(i,o);r.moveTo(c.x,c.y),r.lineTo(d.x,d.y),r.lineTo(u.x,u.y),r.lineTo(f.x,f.y),r.closePath()}r.fill()}}dispose(){super.dispose(),this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},Al=.25;function Il(e,t){let n=Math.cos(e.angle),o=Math.sin(e.angle),r=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,l=e.halfWidth*t.dpr,i=r-n*a,c=s-o*a,d=a*(1-Al);return[{x:r,y:s},{x:i-o*l,y:c+n*l},{x:r-n*d,y:s-o*d},{x:i+o*l,y:c-n*l}]}function Pt(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function yn(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let a=e[r],{color:l,weight:i,last:c}=t(a,r),d=c?o:n,u=`${l}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:l,items:[a]})}return[...n.values(),...o.values()]}function Yo(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${et(o)}-${et(r)} (${be(r-o)})`}function Jd(e,t){let{field:n}=e.encoding,o=e.range?Yo(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?Yo(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"}${be(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${be(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${be(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function ef(e,t,n){let o=e.progress.get(t),r=e.range;if(o===void 0||!r)return;let s=Math.round(r.start+o*(r.end-r.start)-n/2);return`${r.contig}:${et(s)}-${et(s+n)}`}function of(e,t){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach(r=>{let s=n.get(r.name);if(r.order>=0&&s&&k(s)){let{refName:a,start:l}=s.stable;(o.get(a)??o.set(a,[]).get(a)).push({bp0:l,bp1:l+r.sequenceLength,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,a)=>s.bp0-a.bp0);return o}function Mn(e,t,n=!1){let o=0,r=e.length-1;for(;o<r;){let l=o+r>>1,i=e[l].bp1;(n?i<t:i<=t)?o=l+1:r=l}let s=e[o];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 wn(e,t,n){let o=Mn(e,t),r=Mn(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function sf(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var zo=5,_l=10,vl=110,Pl=3;function Ol(e){return e?"#b0b0b8":"#55555c"}function kl(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 Ko(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+_l)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function Gl(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let a=t(r.x0),l=t(s.x1),i=s.bp1-r.bp0;if(l<=a||i<=0)return;let c=kl(i/(l-a)*vl),d=[],u=[];for(let f=Math.ceil(r.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:o(p)})}}return{spans:[{x0:a,x1:l}],ticks:d,labels:Ko(u)}}function Bl(e,t,n,o){let r=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=n),s=r[0],a=r.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:o(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),c=[],d=[],u=[],f=[];for(let{box:p,s0:m,s1:g}of r){c.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=Pl&&d.push(Math.round(g)+.5);let b=l(be(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:Ko([...h,...u,...f])}}function $l(e,t,n,o,r=!1){return(r?Gl:Bl)(e,t,n,o)}function af(e,t,n,o,r=!1){let{x:s,width:a,darkMode:l}=n;e.font="10px sans-serif";let i=$l(t,s,a,u=>e.measureText(u).width,r);if(!i)return;let c=Ol(l),d=o+.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,o),e.lineTo(u,o+zo);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,o+zo+2)}function uf(e,t){let n=new Map(e.nodes.map(r=>[r.id,r])),o=[];return t.nodes.forEach(r=>{let s=n.get(r.name);r.order>=0&&s&&k(s)&&o.push({node:r.name,bp0:s.stable.start,bp1:s.stable.start+r.sequenceLength,x0:r.x,x1:r.x+r.pixelWidth})}),o}function df(e,t,n,o){let r=[];for(let s of e){let a=n(s.x0),l=n(s.x1);l>=0&&a<=o&&r.push({node:s.node,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:l})}return r}var Wl=3;function ff(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,a=Wl;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*r,c=l.top1+(l.bottom1-l.top1)*r,d=Math.max(0,Math.min(i,c)-n,n-Math.max(i,c));d<a&&(a=d,s=l.node)}return s}function jo(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 Uo(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function pf(e,t,n,{highlightNode:o,darkMode:r}){if(n<=0||t.length===0)return;let s=r?"255,255,255":"0,0,0";e.beginPath();for(let l of t)jo(e,l,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of t)Uo(e,l,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(l=>l.node===o);a&&(e.beginPath(),jo(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),Uo(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Fl(e,t){let n=[],o=e.sequenceNew??[];return o.forEach((r,s)=>{let a=t.nodeMap.get(P(r.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=>oo(l,f);for(let f of r.mismatches){let h=u(f.pos);if(h!==null){if(f.type==="insertion"){let p=s===0&&f.pos===e.firstNodeOffset||s===o.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 Vo(e){return e.reads.flatMap(t=>Fl(t,e))}function ns(e){let t=e.trim().split(/[\s,]+/),n=[],o=0,r=()=>Number(t[o++]);for(;o<t.length;){let s=t[o++];s==="M"||s==="L"?n.push({op:s,x:r(),y:r()}):s==="H"?n.push({op:s,x:r()}):s==="V"?n.push({op:s,y:r()}):s==="Q"?n.push({op:s,x1:r(),y1:r(),x:r(),y:r()}):s==="C"?n.push({op:s,x1:r(),y1:r(),x2:r(),y2:r(),x:r(),y:r()}):s==="Z"&&n.push({op:s})}return n}function rs(e){let t=1/0,n=-1/0;for(let o of e)"x"in o&&(t=Math.min(t,o.x),n=Math.max(n,o.x)),"x1"in o&&(t=Math.min(t,o.x1),n=Math.max(n,o.x1));return{x0:t,x1:n}}function Qo(e,t,n,o){let r=ns(e);return{commands:r,color:t,track:o,alpha:n,...rs(r)}}function Zo(e,t){let{shapes:n}=e,o=l=>t==="haplotype"?l.id:void 0,r=[...n.rectangles,...n.verticalRectangles].filter(l=>l.type===t).map(l=>({color:l.color,track:o(l),alpha:l.alpha??1,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),s=so(n.curves,t).map(l=>Qo(l.path,l.color,l.alpha??1,o(l))),a=n.corners.filter(l=>l.type===t).map(l=>Qo(l.path,l.color,1,o(l)));return{rects:r,shapes:[...s,...a]}}function yf(e){let t=[];return e.nodes.forEach(n=>{if(n.order>=0){let o=ns(ao(n));t.push({name:n.name,commands:o,...rs(o)})}}),{bounds:e.bounds,layers:[Zo(e,"haplotype"),Zo(e,"read")],nodes:t,mismatches:Vo(e).filter(n=>n.kind!=="insertion"||!n.softClip)}}function Jo(e,t,n,o){let r=0,s=0;for(let a of t)switch(a.op){case"M":r=a.x,s=a.y,e.moveTo(n(r),o(s));break;case"L":r=a.x,s=a.y,e.lineTo(n(r),o(s));break;case"H":r=a.x,e.lineTo(n(r),o(s));break;case"V":s=a.y,e.lineTo(n(r),o(s));break;case"Q":r=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),o(a.y1),n(r),o(s));break;case"C":r=a.x,s=a.y,e.bezierCurveTo(n(a.x1),o(a.y1),n(a.x2),o(a.y2),n(r),o(s));break;case"Z":e.closePath();break}}function es(e,t,n,o,r){let s=new Map;for(let a of t)if(n(a)){let l=`${o(a)}|${a.alpha}`,i=s.get(l);i?i.push(a):s.set(l,[a])}for(let a of s.values()){e.fillStyle=o(a[0]),e.globalAlpha=a[0].alpha,e.beginPath();for(let l of a)r(l);e.fill()}e.globalAlpha=1}var Dl=12,ql=.15;function Xl(e){return Math.max(ql,Math.min(1,e/Dl))}var Hl=.55;function Mf(e,t,n){let{x:o,y:r,width:s}=n,a=d=>o(d.x1)>=0&&o(d.x0)<=s,l=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;for(let d of t.layers)es(e,d.rects,a,l,u=>{let f=o(u.x0),h=r(u.y0);e.rect(f,h,o(u.x1)-f,r(u.y1)-h)}),es(e,d.shapes,a,l,u=>{Jo(e,u.commands,o,r)});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(),Jo(e,d.commands,o,r);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:Xl(o(d.x1)-o(d.x0)),e.stroke(),e.globalAlpha=1}Kl(e,t.mismatches,n)}var os=12,Yl=6;function zl(e){return os*e>=Yl}function ts(e,{x:t,width:n}){let[o,r]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(r)>=0&&t(o)<=n}function Kl(e,t,n){let{x:o,y:r,yScale:s,darkMode:a}=n;if(!zl(s)||t.length===0)return;let l=os*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&ts(i,n)){let c=o(i.x0),d=r(i.y);e.rect(c,d,o(i.x1)-c,r(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)ts(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,o(i.x0)+1,r(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",o(i.x)-3,r(i.y+i.height)))}function Sf(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],a=r?.at(-1);if(!r||!s||!a)continue;let l=Math.max(o.start,s.bp0),i=Math.min(o.end,a.bp1);i<=l||n.push({gene:o,...wn(r,l,i),exons:o.exons.filter(c=>c.end>l&&c.start<i).map(c=>wn(r,Math.max(c.start,l),Math.min(c.end,i)))})}return n}var ss=22,jl=4,Ot=8,Ul="11px sans-serif",Vl=8;function Ef(e){let t=e.flatMap(r=>[{x:r.x0,step:1},{x:r.x1,step:-1}]).sort((r,s)=>r.x-s.x||r.step-s.step),n=0,o=0;for(let{step:r}of t)n+=r,o=Math.max(o,n);return Math.min(jl,o)}function Nf(e,t,n,o,r=0){let{x:s,width:a,darkMode:l}=n,i=Math.max(1,Math.floor((o-r)/ss)),c=[],d=l?"#e0e0e6":"#1c1c22";e.font=Ul,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,M=e.measureText(g).width/2,L=Math.min(h,b-M),N=Math.max(p,b+M),S=c.findIndex(w=>w+Vl<=L);S===-1&&(S=Math.min(c.length,i-1)),c[S]=Math.max(c[S]??-1/0,N);let R=o-S*ss-Ot/2;e.beginPath(),e.moveTo(h,R+.5),e.lineTo(p,R+.5),e.stroke();for(let w of f.exons){let C=s(w.x0);e.fillRect(C,R-Ot/2,Math.max(1,s(w.x1)-C),Ot)}e.fillText(g,b,R-Ot/2-2)}}var Rn=K(ke(),1);var fe=12,Ql=fe+8,us=8,as=us+3,Zl=12;function Af(e,{colorScheme:t,referenceRamp:n,walks:o}){let r={...jt(e),referenceRamp:n},s=[];return e.nodes.forEach((a,l)=>{if(k(a)){let i=o?o.map(c=>{let d=c.colors.get(a.id);return d===void 0?Yt:(0,Rn.abgrToCssRgba)(d)}):[(0,Rn.abgrToCssRgba)(Ut(a,l,t,r))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(Yt)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function Sn(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var is=2;function Jl(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),a=Math.max(o,r),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 If(e,t,n,o){if(o<0||o>fe+is)return;let r,s=is;for(let a of e){let[l,i]=Sn(t,a.bp0,a.bp1),c=Math.max(0,l-n,n-i);c<=s&&(s=c,r=a.node)}return r}function _f(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function ec(e,t,n,o){let r=e.map(c=>{let[d,u]=Sn(t,c.bp0,c.bp1),f=Math.round(d*o);return{colors:c.colors,x0:d,px0:f,px1:Math.max(Math.round(u*o),f+1)}}).filter(c=>c.px1>0&&c.px0<n*o).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 r){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/o,x1:u/o,tier:h}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Zl?s:s.map(({tier:c,...d})=>d)}function ls(e,t,n,o){let r=n>0?t:t-as;e.clearRect(r,0,as,fe);let s=t+n,a=s+n*us;e.beginPath(),e.moveTo(s,fe/2),e.lineTo(a,0),e.lineTo(a,fe),e.closePath(),e.fillStyle=o,e.fill()}function cs(e,t,n){return Math.round(e*fe*n/t)/n}function vf(e,t,n,{width:o,lit:r,darkMode:s,dpr:a=1}){let l=s?"#ffffff":"#18181c";e.clearRect(0,0,o,Ql);for(let c of ec(t,n,o,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=cs(m,f,a);e.fillStyle=h,e.fillRect(c.x0,g,c.x1-c.x0,cs(m+1,f,a)-g)})}let i=Jl(t,n,o);if(i.left>0&&ls(e,0,1,l),i.right>0&&ls(e,o,-1,l),r){let[c,d]=Sn(n,r.start,r.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),r.anchor&&(e.beginPath(),e.moveTo(f+u/2,fe),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function tc(e,t){let n=new Map(e.nodes.map(r=>[r.id,r])),o=[];return t.nodes.forEach((r,s)=>{let a=n.get(r.name);if(r.order>=0&&a&&k(a)){let l=a.stable.start;o.push({bp0:l,bp1:l+r.sequenceLength,index:s,node:r})}}),o.sort((r,s)=>r.bp0-s.bp0)}function nc(e,t,n){let o=0,r=e.length-1;for(;o<r;){let s=o+r+1>>1;e[s].bp0<=t?o=s:r=s-1}return[e[o],e[o-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function kf(e,t,n){let o=tc(e,t),r=[];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=nc(o,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;r.push({x0:h(i.start),x1:h(i.end),y:l.get(c.index),height:s.width})}}}}return r}function rc(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Gf(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=rc(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<=r){let c=o(a.y);e.rect(l,c,i-l,o(a.y+a.height)-c)}}e.fill()}}function oc(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function sc(e,t){let n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0)),s=Array.from({length:n+1},()=>new Array(o+1).fill(!1));for(let l=n-1;l>=0;l--)for(let i=o-1;i>=0;i--){let c=Math.abs(e[l]-t[i])+r[l+1][i+1],d=n-l>o-i?r[l+1][i]:1/0,u=o-i>n-l?r[l][i+1]:1/0;r[l][i]=Math.min(c,d,u),s[l][i]=r[l][i]===c}let a=new Array(n).fill(void 0);for(let l=0,i=0;l<n&&i<o;)s[l][i]?a[l++]=i++:n-l>o-i?l++:i++;return a}function ds(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var ps=e=>e.spanningReads!==0;function fs(e,t){return{...t,agrees:e.complete&&ps(t)?oc(e.bp,t.bp):void 0}}function ac(e,t){let n=new Map,o=new Set;e.forEach((l,i)=>{let c=t.find(d=>d.haplotype!==void 0&&d.haplotype===l.haplotype);c&&(o.add(c),n.set(i,fs(l,c)))});let r=t.filter(l=>l.haplotype===void 0),s=ds(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),r.filter(ps)],[s,r]];for(let[l,i]of a){let c=l.filter(u=>!n.has(u.i)),d=ds(i.filter(u=>!o.has(u)),u=>u.bp);sc(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;o.add(p),n.set(h.i,fs(h.item,p))}})}return n}function $f(e,t){if(!t)return e;let n=new Map,o=new Map;for(let r of e)o.set(r.sample,[...o.get(r.sample)??[],r]);for(let[r,s]of o){let a=t[r];if(a)for(let[l,i]of ac(s,a))n.set(s[l],i)}return e.map(r=>({...r,call:n.get(r)}))}var hs=K(dt(),1),Df=(0,re.createSvgIcon)((0,hs.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{re as a,Ea as b,ke as c,tt as d,xs as e,Ba as f,en as g,Ta as h,Ca as i,vi as j,ju as k,ho as l,zi as m,gn as n,ad as o,id as p,ji as q,Yt as r,Kt as s,Rc as t,jt as u,Ut as v,Sc as w,Ui as x,Eo as y,ud as z,dd as A,tl as B,nl as C,fd as D,hd as E,md as F,gd as G,Re as H,yd as I,Md as J,wd as K,Rd as L,Us as M,ar as N,_t as O,Po as P,Oo as Q,cl as R,Ad as S,Id as T,_d as U,yl as V,vd as W,Pd as X,Fd as Y,Dd as Z,qd as _,Xd as $,Hd as aa,Yd as ba,zd as ca,Vs as da,Ac as ea,Ic as fa,Bc as ga,br as ha,$c as ia,da as ja,xr as ka,ga as la,ba as ma,Xc as na,Wo as oa,qo as pa,Yo as qa,Jd as ra,ef as sa,of as ta,sf as ua,Ol as va,af as wa,uf as xa,df as ya,ff as za,pf as Aa,yf as Ba,Mf as Ca,zl as Da,ts as Ea,Sf as Fa,ss as Ga,Ef as Ha,Nf as Ia,Ql as Ja,Af as Ka,Jl as La,If as Ma,_f as Na,vf as Oa,kf as Pa,rc as Qa,Gf as Ra,$f as Sa,Kc as Ta,jc as Ua,Ma as Va,Uc as Wa,Vc as Xa,Zt as Ya,Jt as Za,lu as _a,cu as $a,Df as ab};
|
|
2
|
+
//# sourceMappingURL=chunk-NWJN4C4V.js.map
|