jbrowse-plugin-graphgenomeviewer 4.0.26 → 4.0.28
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 +1 -0
- package/dist/chunks/{AddTrackWorkflow-WYRVQYH2.js → AddTrackWorkflow-F6FBBEJM.js} +2 -2
- package/dist/chunks/GbzBaseSyntenyAdapter-FK6PVNBV.js +8 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-FK6PVNBV.js.map +7 -0
- package/dist/chunks/{GraphGenomeView-CGV6NQQZ.js → GraphGenomeView-T2FW4BLC.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-IK3Y3PW6.js → GraphTrackSettingsDialog-RQ4O7NUQ.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-ZM6IMPJE.js → LinearGraphDisplay-PIVJ7WE5.js} +2 -2
- package/dist/chunks/MinigraphBubbleAdapter-CK7AE4QT.js +2 -0
- package/dist/chunks/{MinigraphBubbleAdapter-NRDD66AK.js.map → MinigraphBubbleAdapter-CK7AE4QT.js.map} +1 -1
- package/dist/chunks/RgfaTabixAdapter-5MD2ZZ2F.js +3 -0
- package/dist/chunks/{RgfaTabixAdapter-NQEERXXI.js.map → RgfaTabixAdapter-5MD2ZZ2F.js.map} +2 -2
- package/dist/chunks/chunk-22N3NFQP.js +5 -0
- package/dist/chunks/chunk-22N3NFQP.js.map +7 -0
- package/dist/chunks/chunk-4T7DPQTR.js +2 -0
- package/dist/chunks/chunk-4T7DPQTR.js.map +7 -0
- package/dist/chunks/chunk-KDIBFGZM.js +2 -0
- package/dist/chunks/{chunk-JAQ2RQAE.js.map → chunk-KDIBFGZM.js.map} +4 -4
- package/dist/chunks/chunk-Q36VDIWB.js +2 -0
- package/dist/chunks/chunk-Q36VDIWB.js.map +7 -0
- package/dist/chunks/chunk-SGA5LPIL.js +2 -0
- package/dist/chunks/{chunk-MMGD6ESZ.js.map → chunk-SGA5LPIL.js.map} +1 -1
- package/dist/chunks/chunk-T6LGFR3R.js +3 -0
- package/dist/chunks/chunk-T6LGFR3R.js.map +7 -0
- package/dist/chunks/chunk-X2HKDCRG.js +2 -0
- package/dist/chunks/chunk-X2HKDCRG.js.map +7 -0
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +6 -4
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +3 -3
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +50 -15
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +13 -52
- package/src/GbzBaseSyntenyAdapter/companion.ts +4 -4
- package/src/GbzBaseSyntenyAdapter/configSchema.ts +4 -3
- package/src/GraphAddTrackWorkflow/buildTrackConfig.test.ts +60 -0
- package/src/GraphAddTrackWorkflow/buildTrackConfig.ts +19 -6
- package/src/GraphGenomeView/components/GraphCanvas.tsx +21 -23
- package/src/GraphGenomeView/components/ReferenceStripOverlay.tsx +8 -6
- package/src/GraphGenomeView/components/TubeMapOverlay.tsx +2 -0
- package/src/GraphGenomeView/components/legendStyles.ts +0 -3
- package/src/GraphGenomeView/model.test.ts +75 -39
- package/src/GraphGenomeView/model.ts +104 -76
- package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +34 -0
- package/src/LinearGraphDisplay/model.ts +20 -0
- package/src/RgfaTabixAdapter/rgfaBed.test.ts +8 -0
- package/src/RgfaTabixAdapter/rgfaBed.ts +3 -2
- package/src/gaf/gafFile.test.ts +20 -0
- package/src/gaf/gafFile.ts +15 -18
- package/src/graphTrackDefaults/graphTrackDefaults.test.ts +12 -0
- package/src/graphTrackDefaults/index.ts +1 -9
- package/src/hoverSync/graphViewHighlights.test.ts +23 -0
- package/src/hoverSync/graphViewHighlights.ts +4 -6
- package/src/hoverSync/lgvHover.ts +2 -4
- package/src/hoverSync/rowWalks.test.ts +58 -0
- package/src/hoverSync/rowWalks.ts +44 -0
- package/src/isRecord.ts +5 -0
- package/src/launchFromGraph/launchFromGraph.test.ts +3 -2
- package/src/launchFromGraph/launchFromGraph.ts +34 -8
- package/src/launchFromGraph/linearViewTarget.ts +2 -14
- package/src/launchFromGraph/syntenyTracks.test.ts +22 -0
- package/src/launchFromGraph/syntenyTracks.ts +7 -1
- package/src/version.ts +1 -1
- package/dist/chunks/GbzBaseSyntenyAdapter-LTKB3OX7.js +0 -8
- package/dist/chunks/GbzBaseSyntenyAdapter-LTKB3OX7.js.map +0 -7
- package/dist/chunks/MinigraphBubbleAdapter-NRDD66AK.js +0 -2
- package/dist/chunks/RgfaTabixAdapter-NQEERXXI.js +0 -3
- package/dist/chunks/chunk-33VHHB43.js +0 -2
- package/dist/chunks/chunk-33VHHB43.js.map +0 -7
- package/dist/chunks/chunk-BIZ6OLP5.js +0 -3
- package/dist/chunks/chunk-BIZ6OLP5.js.map +0 -7
- package/dist/chunks/chunk-JAQ2RQAE.js +0 -2
- package/dist/chunks/chunk-MMGD6ESZ.js +0 -2
- package/dist/chunks/chunk-NXI6CVEJ.js +0 -2
- package/dist/chunks/chunk-NXI6CVEJ.js.map +0 -7
- package/dist/chunks/chunk-QSH263Y6.js +0 -2
- package/dist/chunks/chunk-QSH263Y6.js.map +0 -7
- package/dist/chunks/chunk-WAW3QC3R.js +0 -2
- package/dist/chunks/chunk-WAW3QC3R.js.map +0 -7
- package/dist/chunks/chunk-XK7OPCRQ.js +0 -2
- package/dist/chunks/chunk-XK7OPCRQ.js.map +0 -7
- /package/dist/chunks/{AddTrackWorkflow-WYRVQYH2.js.map → AddTrackWorkflow-F6FBBEJM.js.map} +0 -0
- /package/dist/chunks/{GraphGenomeView-CGV6NQQZ.js.map → GraphGenomeView-T2FW4BLC.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-IK3Y3PW6.js.map → GraphTrackSettingsDialog-RQ4O7NUQ.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-ZM6IMPJE.js.map → LinearGraphDisplay-PIVJ7WE5.js.map} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as bt}from"./chunk-UQEPPJEO.js";import{c as tt}from"./chunk-SCMIJAAX.js";import{A as bn,B as pt,C as ht,D as yn,E as xn,H as mt,I as gt,U as yt,V as en,a as Re,i as ot,j as gn,k as rt,l as st,m as at,n as it,o as lt,t as ct,u as Je,v as ut,w as De,x as Ee,y as dt,z as ft}from"./chunk-Q36VDIWB.js";import{a as Fe,b as O,c as Qe,d as Me,e as we,h as Ze}from"./chunk-EFVAQ2KM.js";import{a as Ke,c as et,d as nt}from"./chunk-KULNKXPT.js";import{a as Ve}from"./chunk-XEJ47DLD.js";import{a as Ge,b as k}from"./chunk-FY3BTKY4.js";var Mt=Ge((_i,xt)=>{xt.exports=JBrowseExports["@mui/material/SvgIcon"]});var Se=Ge((Fi,Et)=>{Et.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var ys=Ge((wl,Ht)=>{Ht.exports=JBrowseExports.mobx});var Go=Ge((Tc,$o)=>{$o.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var Do=Ge((Cc,Fo)=>{Fo.exports=JBrowseExports["@jbrowse/render-core/renderingBackendBase"]});var U=k(Mt(),1);var Ar=3.4,wt=6,Ir=8,vr=18,_r=2,Or=15;function Pr(e){let n=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[t,r]=n>=1e6?[1e6,"Mb"]:n>=1e3?[1e3,"kb"]:[1,"bp"],o=s=>+(s/t).toFixed(t===1?0:1);return`${o(e.covered*n)} of ${o(n)} ${r}`}function Br(e,n,t){return Rt(e,r=>r.gene.end-r.gene.start).map(r=>{let{x:o,y:s}=n(r.at),a=Pr(r);return{item:r,x:o,y:s+t+vr,text:a?`${r.gene.name} \xB7 ${a}`:r.gene.name,fallback:a?`${r.gene.name} \u2026`:void 0,stack:_r}})}function Rt(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function $i(e){let{paneWidth:n,canvasHeight:t,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:n,height:t},i=R=>({x:R.x*s+r,y:R.y*a+o}),c=e.drawnRowLabels.map(({label:R,y:C})=>ut(R,C*a+o)),d=e.referenceStripZonePx??0;d>0&&c.push({x0:0,x1:n,y0:0,y1:d}),e.legendSize.width>0&&c.push({x0:n-wt-e.legendSize.width,x1:n,y0:0,y1:d+wt+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=ct(l,c),f=e.drawnRowLabels.length>0,h=f?Math.min(...e.drawnRowLabels.map(R=>R.y)):1/0,p=e.contigThickness*Ar,m=Rt(e.bubbleHalos,R=>R.members),g=Je(m.map(R=>{let{x:C,y:_}=i({x:R.labelAt.x,y:Math.min(R.labelAt.y,h)}),P=_-p/2-6;return{item:R,x:C,y:f?Math.max(P,Or):P,text:R.label}}),l,u),y=Je(Br(e.genePins,i,e.contigThickness),l,u),w=e.nodePositions&&e.labelsNodeSizes?dt({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:n,height:t,version:e.positionsVersion}):{deletions:[],nodes:[]},N=bn(w.deletions,u),L=Je(m.flatMap(R=>R.routes.map(C=>{let{x:_,y:P}=i(C.at);return{item:{halo:R,route:C},x:_,y:P+4,text:C.text,stack:Ir}})),l,u),S=bn(w.nodes,u,ft(n,t));return{bubbles:g,genes:y,routes:L,sizes:[...N,...S]}}var F=k(Se(),1);var G=k(Se(),1);function Ne(e,n){return(0,G.packAbgr)((0,G.abgrRed)(e),(0,G.abgrGreen)(e),(0,G.abgrBlue)(e),Math.round((0,G.abgrAlpha)(e)*n))}function nn(e,n){return(0,G.packAbgr)(Math.min(255,Math.round((0,G.abgrRed)(e)*n)),Math.min(255,Math.round((0,G.abgrGreen)(e)*n)),Math.min(255,Math.round((0,G.abgrBlue)(e)*n)),(0,G.abgrAlpha)(e))}var $r=4;function qe(e){let n=new Map;function t(r,o){let s=n.get(r);s?s.push(o):n.set(r,[o])}for(let r of e.edges)t(r.from,r.to),t(r.to,r.from);return n}function Gr({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<$r&&o.length>0;l++){let i=[];for(let c of o){let d=t.get(c);if(d){for(let u of d)if(!r.has(u)){r.add(u);let f=n.get(u);f&&O(f)?(s=Math.min(s,f.stable.start+f.length),a=Math.max(a,f.stable.start)):i.push(u)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function Fr({nodeId:e,nodeById:n,neighbors:t}){let r=n.get(e);return r===void 0?void 0:O(r)?{start:r.stable.start,end:r.stable.start+r.length}:Gr({nodeId:e,nodeById:n,neighbors:t})}function St(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=qe(e),r=new Map;for(let o of e.nodes){let s=Fr({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}var Nt=new WeakMap;function Lt(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=Nt.get(e);if(l?.graph===n&&l.scaleX===s&&l.scaleY===a&&l.deletions===r&&l.version===o)return l.curves;let i=new Map;for(let c=0;c<n.edges.length;c++){let d=n.edges[c],u=e[d.from],f=e[d.to];if(u?.length&&f?.length){let h=r?.get(c);i.set(c,it(u,f,at(d),0,0,t,h?lt(e,h):[]))}}return Nt.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var Dr=(0,F.packAbgr)(119,119,119,217),Tt=(0,F.packAbgr)(136,136,136,217),qr=(0,F.packAbgr)(24,24,28,240),Wr=2.2,Pt=(0,F.packAbgr)(160,160,160,255),We=.18,Sn=(0,F.abgrToCssRgba)(Ne(Pt,We)),kr=11,Hr=1.2,Ct=4,Mn=1e-6,Xr=7,Yr=3,zr=3,jr=1.5,Ur=.5,Vr=.45,wn=12,Kr=1e-6,ee=new Float64Array(64),ce=new Float64Array(64),ue=new Float64Array(64);function Qr(e,n,t,r){let o=e.length*wn+1;ee.length<o&&(ee=new Float64Array(o),ce=new Float64Array(o),ue=new Float64Array(o));let s=e[e.length-1];ee[0]=s.x1,ce[0]=s.y1,ue[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let c=e[i];for(let d=1;d<=wn&&l<r;d++){let u=1-(d/wn)**2,f=1-u,h=f*f*f,p=3*f*f*u,m=3*f*u*u,g=u*u*u,y=h*c.x0+p*c.cx0+m*c.cx1+g*c.x1,w=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(y-ee[a-1],(w-ce[a-1])*t)*n,ee[a]=y,ce[a]=w,ue[a]=l,a++}}return a}function At(e,n){let t=1;for(;t<e-1&&ue[t]<n;)t++;let r=ue[t-1],o=ue[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:ee[t-1]+(ee[t]-ee[t-1])*s,y:ce[t-1]+(ce[t]-ce[t-1])*s}}function Zr({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=Xr+Yr*n,c=Qr(e,r,o,t+i),d=ue[c-1],u=Math.min(t,d),f=d<Kr?Jr(a,r,o):d-u,h=Math.min(1,f/i);if(h<Ur)return;let p=At(c,u),m=At(c,u+i*h),g=p.x-m.x,y=(p.y-m.y)*o,w=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,y)>0?Math.atan2(y,g):is(w,o,es(w,l)),length:i*h,halfWidth:(zr+jr*n)*h,color:s}}function Jr(e,n,t){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*t);return r*n}function es(e,n){if(n.length<2)return;let t=n[0],r=n[n.length-1];return Math.hypot(e.x1-t.x,e.y1-t.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:t,to:n[1]}:{from:r,to:n[n.length-2]}}function Rn(e,n=1){let t=n===1?e:e.map(o=>({x:o.x,y:o.y*n})),r=[];for(let o=0;o<t.length;o++){let s=0,a=0;if(o===0){let l=t[1].x-t[0].x,i=t[1].y-t[0].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===t.length-1){let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,c=Math.hypot(l,i),d=t[o+1].x-t[o].x,u=t[o+1].y-t[o].y,f=Math.hypot(d,u);if(c>0&&f>0){let h=-i/c,p=l/c,m=-u/f,g=d/f;s=(h+m)/2,a=(p+g)/2;let y=h*s+p*a;y>.1&&(s/=y,a/=y)}else c>0?(s=-i/c,a=l/c):f>0&&(s=-u/f,a=d/f)}r.push({nx:s,ny:a})}return r}function It(e,n,t,r=1){return e.map((o,s)=>({x:o.x+n[s].nx*t,y:o.y+n[s].ny*t/r}))}function tn(e,n,t,r){return(0,F.packAbgr)(Math.round(e*255),Math.round(n*255),Math.round(t*255),Math.round(r*255))}function Le(e,n,t){let r=(1-Math.abs(2*t-1))*n,o=r*(1-Math.abs(e/60%2-1)),s=t-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var ns=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],ts=[[237,137,44],[158,42,122]],os=[[220,50,50],[50,120,220]];function En(e,n){let t=Math.max(0,Math.min(1,n))*(e.length-1),r=Math.min(e.length-2,Math.floor(t)),o=t-r,s=e[r],a=e[r+1];return(0,F.packAbgr)(Math.round(s[0]+(a[0]-s[0])*o),Math.round(s[1]+(a[1]-s[1])*o),Math.round(s[2]+(a[2]-s[2])*o),255)}function rs(e,n){let[t,r,o]=Le(pt(e),yn,xn);return tn(t,r,o,n)}var Nn=300,ss=.7,as=.5,Bt=[60,65,72],Ln=(0,F.packAbgr)(...Bt,255),Qi=`rgb(${Bt.join(", ")})`;function Zi(e,n){let t=St(e);if(n&&n.end>n.start)return{start:n.start,span:n.end-n.start,midpoints:t};let r=1/0,o=-1/0;for(let s of t.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:t}}function Tn(e){let n=1/0,t=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<n&&(n=a.depth),a.depth>t&&(t=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:n,maxDepth:t,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Cn(e,n,t,r){switch(t){case"random":return rs(e.id,1);case"depth":return En(ns,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return En(os,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.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):En(ts,r.maxRank>1?(e.stable.rank-1)/(r.maxRank-1):0);case"reference-position":{let o=r.referenceRamp,s=o?.midpoints.get(e.id);if(o===void 0||s===void 0)return(0,F.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Ln;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=Le(a*Nn,ss,as);return tn(l,i,c,1)}case"grey":return(0,F.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?n/r.nodeCount*360:0,[s,a,l]=Le(o,.75,.5);return tn(s,a,l,1)}default:return(0,F.packAbgr)(52,152,219,255)}}function is(e,n=1,t){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*n;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return t?Math.atan2((t.to.y-t.from.y)*n,t.to.x-t.from.x):0}function ls(e,n){let t=!1;for(let r=0;r<e.length-1&&!t;r++){let o=e[r],s=e[r+1];t=Math.max(o.x,s.x)>=n.minX&&Math.min(o.x,s.x)<=n.maxX&&Math.max(o.y,s.y)>=n.minY&&Math.min(o.y,s.y)<=n.maxY}return t}function vt(e,n){for(let t of e){let r=Math.min(t.x0,t.cx0,t.cx1,t.x1),o=Math.max(t.x0,t.cx0,t.cx1,t.x1),s=Math.min(t.y0,t.cy0,t.cy1,t.y1),a=Math.max(t.y0,t.cy0,t.cy1,t.y1);if(o>=n.minX&&r<=n.maxX&&a>=n.minY&&s<=n.maxY)return!0}return!1}var _t=new WeakMap;function cs(e){let n=_t.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=Le(ht(s,o.length),yn,xn);t.push(tn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},_t.set(e,n)}return n}var Ot=new WeakMap,us=new Map;function ds(e){let n=Ot.get(e);if(!n){n=new Map;for(let[t,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=n.get(o);s?s.push(t):n.set(o,[t])}Ot.set(e,n)}return n}function Ji(e){let{nodePositions:n,graph:t,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:d,linearLayout:u,viewportBounds:f,referenceRamp:h,deletions:p,hiddenEdges:m,version:g=0}=e,y=i==="depth"?yt(t):0,w=d.scaleX,N=rt(d),L=Lt(n,t,d,p,g),S=[],R=new Map,C=[],_=new Map,P=[],re=new Map,_e={...Tn(t),referenceRamp:h},Ye=new Map;if(o==="rainbow")for(let I=0;I<t.nodes.length;I++)Ye.set(t.nodes[I].id,I);let fn=t.paths?.length??0,{pathColorByIndex:Zn,pathIndexByName:wr}=cs(t),Rr=I=>Zn[wr.get(I)??-1]??Tt,Er=l&&fn>1?ds(t):us,Sr=w>(u?1:Vr);for(let I=0;I<t.edges.length;I++){let B=t.edges[I],K=n[B.from],Q=n[B.to],Z=L.get(I);if(!K?.length||!Q?.length||!Z||m?.has(I))continue;let he=B.pathIds?.length??0,Oe=p?.get(I)!==void 0,Pe=c?.edgeIndexes.has(I)??!1,se=a/2*(Oe?Wr:1),me=l&&he>0,ae=Oe?qr:Dr,Y=!c||Pe?ae:Ne(ae,We),Be=r.get(B.to),ge=(Be?en(Be,s,i,y):s)/2,be=(le,xe,W,J)=>{let j=le===0&&xe===0?Z:gn(Z,le,xe);if(f&&!vt(j,f))return;if(Oe)for(let pn of ot(j,kr/w))P.push({curves:pn,thickness:se,color:W});else P.push({curves:j,thickness:se,color:W});let Ue=Sr&&J!==void 0?Zr({curves:j,edgeHalfWidth:se,nodeHalfWidth:ge,scale:w,yToX:N,color:J,fromSegments:K,toSegments:Q}):void 0;Ue&&C.push(Ue)},ie=P.length,ye=C.length,z=c&&Pe&&!me?c.walks:void 0;if(z){let le=r.get(B.from),xe=le?en(le,s,i,y):s,W=Math.max(xe/z.length,Ct),J=Rn(K,N),{nx:j,ny:Ue}=(B.fromStrand==="-"?J[0]:J.at(-1))??{nx:0,ny:0},pn=1/Math.max(w,Mn);z.forEach((hn,Nr)=>{if(!hn.edgeIndexes.has(I))return;let mn=(Nr-(z.length-1)/2)*W*pn,Jn=mn===0?Z:gn(Z,j*mn,Ue*mn/N);f&&!vt(Jn,f)||P.push({curves:Jn,thickness:W/2,color:hn.colors.get(B.from)??hn.colors.get(B.to)??ae})})}else if(!me)be(0,0,Y,Y);else{let le=st(K,Q,he,d),xe=Math.floor((he-1)/2);for(let W=0;W<he;W++){let J=le[W],j=Rr(B.pathIds[W]);be(J.x,J.y,c&&!c.names.has(B.pathIds[W])?Ne(j,We):j,W===xe?Y:void 0)}}let $e=P.length-ie;$e>0&&re.set(I,{start:ie,count:$e});let je=C.length-ye;je>0&&_.set(I,{start:ye,count:je})}for(let[I,B]of Object.entries(n)){let K=r.get(I);if(!K||f&&!ls(B,f))continue;let Q=c!==void 0&&!c.nodeIds.has(I),Z=Q?Pt:Cn(K,Ye.get(I)??0,o,_e),he=Q?Ne(Z,We):Z,ze=en(K,s,i,y),Oe=ze/2,Pe=S.length,se=Er.get(I),me=ze/fn,ae=B.length>=2,Y=c&&!Q&&!se?.length?c.walks:void 0;if(ae&&Y){let ge=Math.max(ze/Y.length,Ct),be=Rn(B,N),ie=1/Math.max(w,Mn);Y.forEach((ye,z)=>{let $e=ye.colors.get(I);if($e===void 0)return;let je=(z-(Y.length-1)/2)*ge*ie;S.push({points:Y.length===1?B:It(B,be,je,N),thickness:ge/2,color:$e})})}else if(ae&&se?.length&&me>=Hr){let ge=Rn(B,N),be=1/Math.max(w,Mn);for(let ie of se){let ye=(ie-(fn-1)/2)*me*be,z=Zn[ie]??Tt;S.push({points:It(B,ge,ye,N),thickness:me/2,color:Q?Ne(z,We):z})}}else ae&&S.push({points:B,thickness:Oe,color:he});let Be=S.length-Pe;Be>0&&R.set(I,{start:Pe,count:Be})}return{nodeStrokes:S,nodeStrokeRuns:R,arrows:C,arrowRuns:_,edgeCurves:P,edgeCurveRuns:re}}function ol(e){return Fe(e)?$t(e):void 0}function $t(e){return{sample:Ke(e.stable.refName),haplotype:et(e.stable.refName),refName:nt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function fs(e,n){let t=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of t)o=o&&s.start-o.end<=n?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function ps(e){return`${e.haplotype??e.sample}\0${e.refName}`}function rl(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Fe(o)){let s=$t(o),a=ps(s),l=t.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):t.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of t.values()){let s=fs(o.spans,n);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function hs(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function sl(e,n){return e.flatMap(t=>{let r=hs(n,t);return r===void 0?[]:[{...t,sample:r}]})}function al(e){return`${e.refName}:${e.start+1}-${e.end}`}function An(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var Gt=k(Ve(),1),Ft=(0,U.createSvgIcon)((0,Gt.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Dt=k(Ve(),1),qt=(0,U.createSvgIcon)((0,Dt.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 Wt=k(Ve(),1),In=(0,U.createSvgIcon)((0,Wt.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 ms="Linear genome view",gs="Linear synteny view",bs="No synteny track in this session aligns these assemblies";function kt({label:e,icon:n,entries:t,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=t,i=s?[{label:e,icon:n,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return t.length===0?i:t.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:n,onClick:o(l)}]:[{label:e,icon:n,type:"subMenu",subMenu:t.map(c=>({label:r(c),onClick:o(c)}))}]}function yl({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...kt({label:ms,icon:In,entries:e,entryLabel:s=>`${s.sample} ${An(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?kt({label:`${gs} (${o} assemblies)`,icon:Ft,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:bs,onSelect:s=>()=>{r(s.trackId)}}):[]]}function xl({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${An(e.location)}`,target:e}:void 0,n&&n.assembly!==e?.assembly?{label:`Open in ${n.assembly} \u2014 around this node`,target:n}:void 0].filter(a=>a!==void 0);return[...o&&t?[{label:`Highlight in ${t.assembly}`,icon:qt,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:In,onClick:()=>{r(l)}}))]}function vn(e){return e.id.endsWith("-")?"-":"+"}function _n(e,n){return n===vn(e)?e.id:`-${e.id}`}function xs(e,n){let t=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)t[o]=r,r+=e[o];let s=n;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],t[a]=s;return t}function Ms(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=xs(n,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let d=r[c],u=n[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=t[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 tt(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let c=o(a),d=c?Math.min(i,c.room):i;c&&s(c.s,{type:"deletion",pos:c.local,length:d}),a+=d,i-=d}}return t}function Xt(e,n,t){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of n){let a=s.path.map(d=>r.get(d.name)),l=a.flatMap((d,u)=>d?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let d=Ms(s,a.map(h=>h?.length)),u=l.map(h=>_n(a[h],s.path[h].strand)),f=a[c].length;o.push({id:t+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:l.map((h,p)=>({nodeName:u[p],mismatches:d[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var ws=["#6baed6","#4292c6","#2171b5","#08519c"],Rs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Yt(e){let n=e.is_reverse?Rs:ws;return n[e.id%n.length]}function on(e){let n=e.split("#"),t=n.length>=2?Number(n[1]):Number.NaN;return{sample:n[0]??e,haplotype:Number.isFinite(t)?t:void 0}}function Es(e,n,t,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=n.get(l);if(i){o.push(i);for(let c of t.get(l)??[]){let d=n.get(c);d&&(d.stable.rank===0?s.push(d):r.has(c)||(r.add(c),a.push(c)))}}}return{members:o,anchors:s}}function Ss(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let t=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=t[0],o=t.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Ns(e,n,t){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of t.get(n.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of t.get(a)??[])if(r.has(i)){let c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function Ls(e,n,t){let r=Ns(e,n,t),o=[...e].sort((i,c)=>r.get(i.id)-r.get(c.id)),s=new Map(o.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of o.entries()){let d=0;for(let u of t.get(c.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,l.get(u)+f.length))}l.set(c.id,d)}return{offsets:l,ordered:o}}function jt(e){let n=new Map(e.nodes.filter(Fe).map(s=>[s.id,s])),t=qe(e),r=new Set,o=[];for(let s of n.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Es(s.id,n,t,r),i=Ss(l);if(i){let{offsets:c,ordered:d}=Ls(a,i.entry,t);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>c.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,c.get(f.id)+f.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ts=1,Cs=.015;function rn({graph:e,span:n,rowY:t,positions:r}){let o=n*Cs,s=jt(e),a=new Map(e.nodes.map(d=>[d.id,d])),l=[];for(let d of s){let u=d.refSpan-d.pathLength;u>=Ts&&l.push({nodeIds:d.nodeIds,bp:u});let f=Math.max(d.refSpan,o),h=d.pathLength>0?f/d.pathLength:0;d.nodeIds.forEach((p,m)=>{let g=a.get(p);if(g){let y=d.nodeOffsets[m],w=f/d.nodeIds.length,N=S=>d.start+S*h,L=t(g);r[p]=h?[{x:N(y),y:L},{x:N(y+g.length),y:L}]:[{x:d.start+m*w,y:L},{x:d.start+(m+1)*w,y:L}]}})}let i=qe(e),c=Object.keys(r);for(let d of c){let u=r[d].at(-1).x;for(let f of i.get(d)??[]){let h=a.get(f);if(h&&!(f in r)){let p=t(h);r[f]=[{x:u,y:p},{x:u+o,y:p}],c.push(f)}}}return l}function As(e){let n=new Set;for(let t of e.nodes)t.stable&&n.add(t.stable.rank);return new Map([...n].sort((t,r)=>t-r).map((t,r)=>[t,r]))}function Ut(e,n){let t=Me(e);if(t.length===0)return;let r=Ze(t,n),o=As(e),s=we(t),a=rn({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,c])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:c*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Is=12,On=20;function Vt(e){return 10+8*Math.log2(1+e.length)}function ne(e,n){return e<n?-1:e>n?1:0}function Qt(e,n){return ne(e.at,n.at)||ne(e.side,n.side)||ne(e.hops,n.hops)}var Kt={at:1/0,side:0,hops:0};function vs(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=Ps(e);return e.nodes.map(r=>r.id).sort((r,o)=>Qt(t.get(r)??Kt,t.get(o)??Kt)||ne(n.get(r).name,n.get(o).name)||ne(r,o))}function _s(e,n){let t=new Set(e.nodes.map(d=>d.id)),r=new Map(n.map(d=>[d.id,d.stable.start])),o=new Map,s=new Map;n.forEach((d,u)=>{s.set(d.id,n[u-1]?.id),o.set(d.id,n[u+1]?.id)});let a=n[0]?.id,l=(d,u)=>{let f=o.get(d);o.set(d,u),s.set(u,d),o.set(u,f),f!==void 0&&s.set(f,u)},i=(d,u)=>{let f=s.get(d);f===void 0?(a=u,s.set(u,void 0),o.set(u,d),s.set(d,u)):l(f,u)};for(let d of e.paths??[]){let u=0,f=0,h;for(let y of d.nodeIds){let w=r.get(y);w!==void 0&&(h!==void 0&&w!==h&&(w>h?u++:f++),h=w)}let p=f>u?[...d.nodeIds].reverse():d.nodeIds,m,g=new Set;for(let y of p)if(o.has(y)){if(m===void 0)for(let w of g)i(y,w);m=y}else t.has(y)&&(m===void 0?g.add(y):(l(m,y),m=y))}let c=[];for(let d=a;d!==void 0;d=o.get(d))c.push(d);return c}function Os(e,n){let t=[...n.entries()].sort(([a,l],[i,c])=>Qt(l,c)||ne(a,i)).map(([a])=>a),r=t.length;for(let a of t){let l=n.get(a);for(let i of e.get(a)??[])n.has(i)||(n.set(i,{at:l.at,side:1,hops:l.hops+1}),t.push(i))}let o=new Set(t.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=n.get(a),i=[a];s.add(a);let c=!0;for(let d of i){let{hops:u}=n.get(d),f=!0,h=!1;for(let p of e.get(d)??[]){let m=n.get(p);m.at===l&&o.has(p)?(f&&=m.hops<=u,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!f||h}if(c)for(let d of i){let u=n.get(d);n.set(d,{...u,side:-1,hops:-u.hops})}}}function Ps(e){let n=new Set(e.nodes.map(s=>s.id)),t=new Map;for(let s of e.edges)!n.has(s.from)||!n.has(s.to)||((t.get(s.from)??t.set(s.from,[]).get(s.from)).push(s.to),(t.get(s.to)??t.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(O).sort((s,a)=>ne(s.stable.start,a.stable.start)||ne(s.name,a.name)),o=new Map;return _s(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),Os(t,o),o}function Bs(e){let n=new Map(e.nodes.map(u=>[u.id,u])),t=vs(e),r=new Map(t.map((u,f)=>[u,f])),o=u=>O(n.get(u)),s=new Map(t.map(u=>[u,[]])),a=new Map(t.map(u=>[u,[]])),l=(u,f)=>{s.get(f).push(u),a.get(u).push(f)};for(let u of e.edges)u.from===u.to||!r.has(u.from)||!r.has(u.to)||(r.get(u.from)<r.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=t.filter(o);for(let u=1;u<i.length;u++)l(i[u-1],i[u]);let c=new Map;for(let u of t){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=t.length-1;u>=0;u--){let f=t[u],h=a.get(f);if(o(f)||h.length===0)continue;let p=1/0;for(let y of h)p=Math.min(p,c.get(y));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 t)(d[c.get(u)]??=[]).push(u);return{layers:d,layerOf:c,preds:s}}function Zt(e){if(!e.nodes.some(O))return;let n=new Map(e.nodes.map(u=>[u.id,u])),t=u=>O(n.get(u)),{layers:r,layerOf:o,preds:s}=Bs(e),a=r.map(u=>{let f=0;for(let h of u)f=Math.max(f,Vt(n.get(h)));return f}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+Is;let c=new Map;for(let u of r){let f=[];for(let p of u){if(t(p)){c.set(p,0);continue}let m=s.get(p).filter(y=>c.has(y)),g=0;for(let y of m)g+=c.get(y)/m.length;f.push({id:p,ideal:g===0?On: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/On);g===0&&(g=m>=0?1:-1);for(let y=1;h.has(g);y++)h.has(g+y)?h.has(g-y)||(g-=y):g+=y;h.add(g),c.set(p,g*On)}}let d={};for(let u of e.nodes){let f=o.get(u.id),h=Vt(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 $s(e,n){let t=new Map;for(let o of e.nodes)if(Qe(o)){let{sample:s}=on(o.stable.refName);t.set(s,(t.get(s)??0)+o.length)}let r=new Map(n.map((o,s)=>[o,s]));return[...t.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||t.get(s)-t.get(o)||o.localeCompare(s))}function Jt(e,n,t=[]){let r=Me(e),o=$s(e,t);if(r.length===0||o.length===0)return;let s=Ze(r,n),a=new Map(o.map((f,h)=>[f,h+1])),l=we(r),i=o.length+1,c=rn({graph:e,span:s,rowY:f=>{let h=f.stable;return((h?a.get(on(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:on(r[0].stable.refName).sample,y:0},...o.map(f=>({label:f,y:a.get(f)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function Pn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Xe=!1,eo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function bo(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??(n=>eo[n.id%eo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var A=bo({}),Dn=null,b=[],x=[],M=[],T=new Map,Ae=[],E=[],de=[],Wn=[],kn=[],X=-1,$=Pn(),qn={minX:0,maxX:0,minY:0,maxY:0},ke,sn=new Map;function yo(e,n,t=[],r={}){if(A=bo(r),Dn=r.bed??null,$=Pn(),de=[],Wn=[],kn=[],Ae=[],qn={minX:0,maxX:0,minY:0,maxY:0},ke=void 0,sn=new Map,e.length===0||n.length===0)return;let o=Bn(e);b=[],o.forEach((i,c)=>{b[c+1]=i}),x=Bn(n);let s=t.length>0;M=Bn(Ea(t));for(let i=x.length-1;i>=0;i-=1){let c=x[i];if(c.type===void 0&&(c.type="haplotype"),c.hidden===!0){x.splice(i,1);continue}c.indexOfFirstBase!==void 0&&(ke=c.name)}if(x.length===0)return;Fs(0),T=oo(),Te(x),A.showReads&&M.length>0&&Te(M),go(),A.mergeNodesFlag&&(ro(),Gn(),A.showReads&&M.length>0&&$n(),Ra(),T=oo(),go(),Te(x),A.showReads&&M.length>0&&Te(M)),ro(),sa(),Xe&&console.log(`${b.length} nodes.`),Gn(),X=ao(),aa(),Gn(),X=ao();let a=A.showReads&&A.coarsenedReadView&&!s;if(a){let i=ke===void 0?-1:x.findIndex(u=>u.name===ke),c=i===-1?0:i,d=x.filter((u,f)=>f!==c);if(d.length>0){let u=fo(d,"haplotype");u.length>0&&(x=[x[c]],M=u)}}ga(),ua(),A.showExonsFlag&&Dn!==null&&ma();let l=A.showReads&&A.coarsenedReadView&&M.length>0&&!a;return A.showReads&&M.length>0?(Ds(),$n(),Te(M),l&&(M=fo(M,"read"),$n(),Te(M)),Ws(),x=x.concat(M)):b.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),la(),xa(),Xe&&(console.log("Tracks:"),console.log(x),console.log("Nodes:"),console.log(b),console.log("Lane assignment:"),console.log(de)),Js(),{nodes:b,tracks:x,reads:M,nodeMap:T,shapes:$,bounds:qn,maxOrder:X,trackForRuler:ke,coarsenedEdgeMeta:sn}}function Ce(e,n="plain"){return A.trackColor(e,n)}function Gs(e){return A.trackAlpha(e)}function Bn(e){return structuredClone(e)}function q(e){let n=String(e);return n.length>=1&&n.startsWith("-")}function v(e){return q(e)?String(e).substring(1):e}function te(e){return q(e)?e:`-${e}`}function xo(e){return q(e)?v(e):te(e)}function an(e){return(e||1/e)>=0}function Fs(e){let n=new Set,t=x[e].sequence;for(let r=0;r<t.length;r+=1){let o=t[r];if(q(o)){let s=v(o),a=t.indexOf(s);(a===-1||a>r)&&n.add(s)}}for(let r of x){t=r.sequence;for(let o=0;o<t.length;o+=1){let s=t[o];q(s)?n.has(v(s))&&(t[o]=v(s)):n.has(s)&&(t[o]=te(s))}}b.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function Ds(){Ae=[];for(let n=0;n<=X;n+=1)Ae[n]=[];let e=new Map;b.forEach(n=>{n.y!==void 0&&no(e,n.order,n.y+n.contentHeight)}),x.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{no(e,t.order,(t.y??0)+n.width)})}),b.forEach((n,t)=>{n.order>=0&&n.y===void 0&&(n.y=(e.get(n.order)??0)+25,n.contentHeight=0,Ae[n.order].push(t))})}function no(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var ln=7;function qs(){b.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),M.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=ln),e.path.length===1){let t=e.path[0].node;t!==null&&b[t].internalReads.push(n)}else e.path.forEach((t,r)=>{if(r===0){let o=e.path[0].node;o!==null&&b[o].outgoingReads.push([n,r])}else{let o=t.node;o!==null&&b[o].incomingReads.push([n,r])}})})}function Ws(){Vs(),qs();let e=b.slice();e.sort(cn);let n=new Map;for(let a=0;a<M.length;a++){let l=M[a].sourceTrackID,i=n.get(l);i===void 0?n.set(l,[a]):i.push(a)}let t=Array.from(n.keys()).sort((a,l)=>a-l),r=t.length>1?ln:0;e.forEach(a=>{if(a)for(let l of t)ks(n.get(l),a,r)});let o=Us(),s=[];M.forEach((a,l)=>{let i=a.path.length,c=new Array(i),d;for(let h=0;h<i;h++){h===0?c[h]=void 0:c[h]=d??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(d=p)}let u=new Array(i),f;for(let h=i-1;h>=0;h--){h===i-1?u[h]=void 0:u[h]=f??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(f=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=c[p],g=u[p],y=!!(g&&m&&g.isForward!==void 0&&m.isForward!==void 0&&(m.order>g.order||g.order===m.order&&g.isForward===m.isForward));h.betweenCycleReverseTraversal=y,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(Xs),s.forEach(a=>{let l=M[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Xe&&(console.log("Reads:"),console.log(M))}function ks(e,n,t){let r=new Set(e),o=n.incomingReads.filter(([p])=>r.has(p)),s=n.outgoingReads.filter(([p])=>r.has(p)),a=n.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(t=0);let l=n.y+n.contentHeight+t*2,i=o.map(p=>{let[m,g]=p,y=M[m].path,w=g+1,N;for(let L=1;L<=g;L++){let S=y[g-L]?.y;if(S!==void 0){w=L,N=S;break}}return{entry:p,decisionStep:w,y:N}});i.sort(Hs),o=i.map(p=>p.entry);let c=l,d=new Map;o.forEach(p=>{let m=M[p[0]];m.path[p[1]].y=c,to(d,m,p[1],c,n),c+=m.width});let u=c;s.sort(Ys);let f=new Map;c=l,s.forEach(p=>{let m=M[p[0]],g=m.firstNodeOffset??0;m.path[p[1]].y=c,f.set(c,g);let y=d.get(c);y===void 0||y+1<=g?(c+=m.width,u=Math.max(u,c)):(d.set(c,0),o.forEach(w=>{let N=M[w[0]],L=N.path[w[1]];L.y!==void 0&&L.y>=c&&(L.y+=m.width,to(d,N,w[1],L.y,n))}),c+=m.width,u+=m.width)}),a.sort(js),a.forEach(p=>{let m=M[p],g=m.firstNodeOffset??0,y=m.finalNodeCoverLength??0;for(c=l;g<(d.get(c)??-1/0)+2||y>(f.get(c)??1/0)-3;)c+=m.width||ln;m.path[0].y=c,d.set(c,y),u=Math.max(u,c)});let h=u-n.y-n.contentHeight;n.contentHeight+=h,ha(n,h)}function Hs(e,n){return e.decisionStep!==n.decisionStep?e.decisionStep-n.decisionStep:e.y===void 0||n.y===void 0?(e.y===void 0?0:1)-(n.y===void 0?0:1):e.y-n.y}function to(e,n,t,r,o){t===n.path.length-1?e.set(r,n.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function Xs(e,n){let t=M[e.readIndex],r=M[n.readIndex],o=t.path[e.pathIndex],s=r.path[n.pathIndex];if(o.order!==s.order)return o.order-s.order;if(t.sourceTrackID!==r.sourceTrackID)return t.sourceTrackID-r.sourceTrackID;if(e.previousNode&&n.previousNode){let i=b[e.previousNode],c=b[n.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=n.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function Ys([e,n],[t,r]){let o=M[e],s=M[t],a,l,i=o.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let d=o.path[n]?.node,u=s.path[r]?.node,f=d!=null?b[d]:null,h=u!=null?b[u]:null;for(;f!=null&&h!=null&&f===h;){if(n<o.path.length-1){for(n+=1;o.path[n]?.node===null;)n+=1;let m=o.path[n]?.node;f=m!=null?b[m]:null}else f=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?b[m]:null}else h=null}if(f!=null)return h!=null?cn(f,h):1;if(h!=null)return-1;let p=(o.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(o.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function zs(e,n){if(e.path===void 0||n.path===void 0)return(e.path===void 0?0:1)-(n.path===void 0?0:1);let t=e.path,r=n.path,o=0,s=0;for(;o<t.length&&s<r.length;){let a=t[o],l=r[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?o+=1:(i>c||(o+=1),s+=1)}return 0}function js(e,n){let t=M[e],r=M[n],o=t.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=t.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function Us(){let e=[];for(let n=0;n<=X;n+=1)e.push(0);return b.forEach(n=>{n.y!==void 0&&(e[n.order]=Math.max(e[n.order],n.y+n.contentHeight+20))}),x.forEach(n=>{n.path.forEach(t=>{e[t.order]=Math.max(e[t.order],(t.y??0)+n.width)})}),e}function Vs(){M.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=an(e.indexSequence[0]),r=b[n],o,s;e.path=[],e.path.push({order:r.order,isForward:t,node:n});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=t,n=Math.abs(e.indexSequence[a]),t=an(e.indexSequence[a]),r=b[n],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});t?e.path.push({order:r.order,isForward:!0,node:n}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:n}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});t?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:n})):e.path.push({order:r.order,isForward:!1,node:n})}else t!==s?e.path.push({order:r.order,isForward:t,node:n}):(e.path.push({order:r.order,isForward:!t,node:null}),e.path.push({order:r.order,isForward:t,node:n}))})}function $n(){M.forEach(e=>{let n=0;for(;n<e.sequence.length&&e.sequence[n].startsWith("-");)n+=1;if(n===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=v(e.sequence[a]);let t=e.sequenceNew??[];t.reverse(),e.sequenceNew=t;for(let a of t)a.nodeName=v(a.nodeName),Ks(a.mismatches,V(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=V(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=V(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function Ks(e,n){e.forEach(t=>{t.type==="insertion"?t.pos=n-t.pos:t.type==="deletion"?t.pos=n-t.pos-(t.length??0):t.type==="substitution"&&(t.pos=n-t.pos-(t.seq?.length??0)),t.seq!==void 0&&(t.seq=Mo(t.seq).split("").reverse().join(""))})}var Qs={A:"T",T:"A",C:"G",G:"C"};function Mo(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=Qs[e.charAt(t)]??"N";return n}function Te(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=T.get(v(r)),s=b[o]?.switched??!1;s&&(r=xo(r));let a=T.get(v(r));if(a===0)throw new Error("Node "+v(r)+" has prohibited index 0");q(r)!==s?n.indexSequence.push(-a):n.indexSequence.push(a)})})}var Zs=20;function Js(){let e={minX:99,maxX:-99,minY:99,maxY:-99};b.forEach(n=>{n&&(n.x!==void 0&&(e.minX=Math.min(e.minX,n.x),e.maxX=Math.max(e.maxX,n.x+Zs+n.pixelWidth)),n.y!==void 0&&(e.minY=Math.min(e.minY,n.y-10),e.maxY=Math.max(e.maxY,n.y+n.contentHeight+10)))}),x.forEach(n=>{n.path.forEach(t=>{let r=t.y??0;e.maxY=Math.max(e.maxY,r+n.width),e.minY=Math.min(e.minY,r)})}),qn=e}function V(e){let n=T.get(v(e)),t=n===void 0?void 0:b[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function oo(){return T=new Map,b.forEach((e,n)=>{e&&T.set(e.name,n)}),T}function ro(){let e=b.map(()=>new Set),n=b.map(()=>new Set),t=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),n[a].add(s)}};x.forEach(t),A.showReads&&M.length>0&&M.forEach(t),b.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(n[o]))})}function so(e){let n=0,t=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){E[s]===void 0&&(E[s]=t);let a=E[s];a<r&&(r=a),n=a,t=a-1}else{E[s]===void 0&&(E[s]=n);let a=E[s];n=a+1,t=a}}),r<0&&Hn(-r)}function ea(e){let n=0,t=0;for(;n<e.length&&E[Math.abs(e[n])]===void 0;)n+=1;if(n>=e.length)return null;let r=e[n],o,s;r>=0?(o=E[r]-1,s=-1):(o=E[-r]+1,s=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(e[a]);E[l]===void 0&&(E[l]=o,t=Math.min(t,o),o+=s)}return t<0&&Hn(-t),n}var na=-1;function ta(e){let n=[];for(let t of e)n.push(t??na);return n}function Gn(){let e,n,t,r,o=0,s=A.showReads&&M.length>0?x.concat(M):x,a={stamp:new Int32Array(b.length),generation:0};E=new Array(b.length).fill(void 0),b.forEach(i=>{i&&(i.order=void 0)}),so(x[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Xe&&console.log(`generating order for track ${i+1}`),t=ea(s[i].indexSequence),t===null){s[i].type==="haplotype"?so(s[i].indexSequence):(s.splice(i,1),M.splice(i-x.length,1),i-=1);continue}for(e=ra(s[i].indexSequence);t<e.length;){for(r=t,t+=1;t<e.length&&E[e[t]]===void 0;)t+=1;if(t<e.length){n=E[e[r]]+1;for(let c=r+1;c<t;c+=1)E[e[c]]=n,n+=1;if(E[e[t]]>E[e[r]])E[e[t]]<n&&io(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!oa(e[t],e[r],a))io(e[t],e[t-1],n);else if(s[i].indexSequence[r]<0||b[e[r+1]].degree<2&&E[e[t]]<E[e[r]]){n=E[e[r]]-1;for(let c=r+1;c<t;c+=1)E[e[c]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=E[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let d=e[c];E[d]===void 0&&(E[d]=n,n+=1)}}else{n=E[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let d=e[c];E[d]===void 0&&(E[d]=n,o=Math.min(o,n),n-=1)}}}}o<0&&Hn(-o);let l=ta(E);E=l,l.forEach((i,c)=>{let d=b[c];d!==void 0&&(d.order=i)})}function oa(e,n,t){t.generation+=1;let{stamp:r,generation:o}=t,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===n)return!0;for(let l of b[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function ao(){let e=-1;return E.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function ra(e){return e.map(n=>Math.abs(n))}function Hn(e){E.forEach((n,t)=>{n!==void 0&&(E[t]=n+e)})}function io(e,n,t){let r=new Map,o=[[e,t]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=E[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),b[a].successors.forEach(c=>{E[c]>i&&c!==n&&o.push([c,l+1])}),a!==e&&b[a].predecessors.forEach(c=>{E[c]>i&&c!==n&&o.push([c,l+1])}))}r.forEach((a,l)=>{E[l]=a})}function sa(){b.forEach(e=>{e.tracks=[]}),x.forEach(e=>{e.indexSequence.forEach(n=>{b[Math.abs(n)].tracks.push(e.id)})}),b.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function aa(){let e=x[0],n=x.slice(1,x.length);if(A.showReads&&M.length>0&&(n=n.concat(M)),ia(n,e),A.showReads&&M.length>0){for(let t=0;t<M.length;t++)if(M[t]!==n[t+x.length-1])throw new Error("Read inequality")}}function ia(e,n){let t=new Map,r=n?new Set(n.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=v(s[a]),i=V(l);if(r&&!r.has(l)){let c=a>0?V(s[a-1]).order:void 0,d=a<s.length-1?V(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(d===void 0||i.order<d)&&lo(t,l,q(s[a])?1:-1),(c===void 0||c>i.order)&&(d===void 0||i.order>d)&&lo(t,l,q(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=t.get(v(s));l!==void 0&&l>0&&(o.sequence[a]=xo(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=V(s);a.seq=Mo(a.seq),a.switched=!0}})}function lo(e,n,t){e.set(n,(e.get(n)??0)+t)}function la(){let e=0,n=20,t=-1,r=b.slice();r.sort(cn);let o=ca();r.forEach(s=>{s.order>=0&&(s.order>t&&(t=s.order,e=n+10*o[s.order]),s.x=e,n=Math.max(n,e+40+s.pixelWidth))})}function ca(){let e=[],n=[],t=[],r=[];for(let o=0;o<=X;o+=1)e.push(0),n.push(0),t.push(0);x.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:n[a.order]=n[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));t[a.order]=Math.max(i/17.5,t[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=X;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function ua(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=X;i+=1){de[i]=[],l[i]=new Map,a[i]=[];for(let c=0;c<x.length;c+=1)a[i][c]=null}x.forEach((i,c)=>{n=Math.abs(i.indexSequence[0]),t=an(i.indexSequence[0]),r=b[n],i.path=[],i.path.push({order:r.order,lane:null,isForward:t,node:n}),D(r.order,n,c,0,a,l),e=1;for(let d=1;d<i.sequence.length;d+=1)if(o=r,s=t,n=Math.abs(i.indexSequence[d]),t=an(i.indexSequence[d]),r=b[n],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order+1;u<r.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),D(u,null,c,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!0,node:n}),D(r.order,n,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:n}),D(r.order,n,c,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order-1;u>r.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),D(u,null,c,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:n}),D(r.order,n,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:n}),D(r.order,n,c,e,a,l),e+=1)}else t!==s?(i.path.push({order:r.order,lane:null,isForward:t,node:n}),D(r.order,n,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!t,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:t,node:n}),D(r.order,n,c,e,a,l),e+=1)});for(let i=0;i<=X;i+=1)fa(de[i],i)}function D(e,n,t,r,o,s){let a={trackID:t,segmentID:r,compareToFromSame:o[e][t]??null},l=n===null?void 0:s[e].get(n);if(l===void 0){let i={type:"single",node:n,tracks:[a]};de[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function da(e,n){let t;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(x[o.trackID].path[o.segmentID-1].order===n-1)o.idealLane=x[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=x[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<x[o.trackID].path.length-1&&x[o.trackID].path[o.segmentID+1].order===n-1)o.idealLane=x[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=x[o.trackID].path[o.segmentID+1].y;else{for(t=o.segmentID-1;t>=0&&x[o.trackID].path[t].order!==n-1;)t-=1;t<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=x[o.trackID].path[t].lane??void 0,o.idealY=x[o.trackID].path[t].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function fa(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;da(e,n),e.sort(uo),e.forEach(l=>{l.node!==null?(b[l.node].topLane=t,s&&(o-=10),b[l.node].y=o,b[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(uo),l.tracks.forEach(i=>{i.lane=t,i.trackID===a&&l.node===null&&s&&(o+=10),x[i.trackID].path[i.segmentID].lane=t,x[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),t+=1,o+=x[i.trackID].width,l.node!==null&&(b[l.node].contentHeight+=x[i.trackID].width),a=i.trackID}),o+=25}),pa(e,r)}function pa(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{co(e,o)<r&&(r=co(e,o),t=o)}),e.forEach(o=>{o.node!==null&&(b[o.node].y+=t),o.tracks.forEach(s=>{let a=x[s.trackID].path[s.segmentID];a.y=a.y+t})})}function ha(e,n){e.order<0||de[e.order]===void 0||(de[e.order].forEach(t=>{if(t.node!==null){let r=b[t.node];r!==e&&r.y>e.y&&(r.y+=n,t.tracks.forEach(o=>{let s=x[o.trackID].path[o.segmentID];s.y=s.y+n}))}else t.tracks.forEach(r=>{let o=x[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+n)})}),Ae[e.order].length>0&&Ae[e.order].forEach(t=>{b[t]!==e&&b[t].y>e.y&&(b[t].y+=n)}))}function co(e,n){let t=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&x[o.trackID].type!=="read"&&(t+=Math.abs(o.idealY-n-x[o.trackID].path[o.segmentID].y)*x[o.trackID].width)})}),t}function uo(e,n){return e.idealLane!==void 0?n.idealLane!==void 0?e.idealLane<n.idealLane?-1:e.idealLane>n.idealLane?1:0:-1:n.idealLane!==void 0?1:0}function cn(e,n){if(!e)return n?-1:0;if(!n)return 1;if(e.order!==void 0){if(n.order!==void 0){if(e.order<n.order)return-1;if(e.order>n.order)return 1;if(e.y!==void 0&&n.y!==void 0){if(e.y<n.y)return-1;if(e.y>n.y)return 1}return 0}return-1}return n.order!==void 0?1:0}function ma(){let e,n,t={};Dn.forEach(r=>{let o=0;for(;o<x.length&&x[o].name!==r.track;)o+=1;o<x.length&&(e=0,x[o].path.forEach(s=>{s.node!==null&&(t={},n=e+b[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(t.start=0),e<r.start&&n>=r.start&&(t.start=r.start-e),n<=r.end&&n>=r.start&&(t.end=n-e,n<r.end&&(t.continue=!0)),n>r.end&&e<=r.end&&(t.end=r.end-e),t.start!==void 0&&(t.type=r.type,t.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(t)),e=n+1)}))})}function ga(){let e=!0,n=4,t=A.trackWidth;x.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*n):(r.width=t,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(e=!1)}),e&&x.forEach(r=>{r.freq!==void 0&&(r.width=t)})}function ba(e){let n=e.path[0],t=b[n.node],r=e.firstNodeOffset??0;return Xn(t,n.isForward?r:t.sequenceLength-r)}function ya(e){let n=e.path[e.path.length-1],t=b[n.node],r=e.finalNodeCoverLength??0;return Xn(t,n.isForward?r:t.sequenceLength-r)}function wo(e,n){return n>e.sequenceLength?null:Xn(e,n)}function Xn(e,n){let[t,r]=wa(e);if(e.sequenceLength===0)return t;let o=Math.min(Math.max(n,0),e.sequenceLength);return t+o/e.sequenceLength*(r-t)}function xa(){let e,n,t,r,o,s,a,l,i;for(let u=0;u<=X;u+=1)Wn.push(0),kn.push(0);let c=[],d=[];b.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))}),x.sort(zs),x.forEach(u=>{a="plain",o=Ce(u,a),s=Gs(u);let f=a,h=()=>(f!==a&&(f=a,o=Ce(u,a)),o);t=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=ba(u);for(let p=0;p<u.path.length;p+=1)u.path[p].y===t?u.path[p].features!==void 0&&(i=p>0&&u.path[p-1].order===u.path[p].order,l=po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,t,o,i),a=l.highlight,e=l.xStart):(u.path[p-1].isForward?n=d[u.path[p-1].order]:n=c[u.path[p-1].order],n!==e&&(o=h(),$.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})),u.path[p].order-1===u.path[p-1].order?(e=n,n=c[u.path[p].order],r=u.path[p].y,o=h(),$.curves.push({xStart:e,yStart:t,xEnd:n+1,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=n,t=r):u.path[p].order+1===u.path[p-1].order?(e=n,n=d[u.path[p].order],r=u.path[p].y,o=h(),$.curves.push({xStart:e+1,yStart:t,xEnd:n,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=n,t=r):u.path[p-1].isForward?(r=u.path[p].y,mo(1,n,t,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=d[u.path[p].order],t=u.path[p].y):(r=u.path[p].y,mo(-1,n,t,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=c[u.path[p].order],t=u.path[p].y),u.path[p].features!==void 0&&(i=u.path[p-1].order===u.path[p].order,l=po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,t,o,i),a=l.highlight,e=l.xStart));u.type!=="read"?u.path[u.path.length-1].isForward?n=d[u.path[u.path.length-1].order]+20:n=c[u.path[u.path.length-1].order]-20:n=ya(u),$.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})})}var Ma=1e9;function fo(e,n){sn=new Map;let t=new Map,r=A.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],y=Math.abs(m),w=Math.abs(g),N=b[y],L=b[w];if(!N||!L)continue;let S;if(r){let C=`${m}>${g}`,_=`${-g}>${-m}`;S=C<_?C:_}else S=`${m}>${g}`;let R=t.get(S);R===void 0?t.set(S,{sSigned:m,dSigned:g,sName:m<0?`-${N.name}`:N.name,dName:g<0?`-${L.name}`:L.name,count:1,sourceTrackID:f.sourceTrackID}):R.count+=1}}let o=0;for(let f of t.values())f.count>o&&(o=f.count);let s=ln,a=60,l=f=>o<=1?s:s+(a-s)*Math.sqrt(f/o),i=[],c=0;for(let f of t.values()){let h=Ma+c,p=`${f.count.toLocaleString()} ${n}${f.count===1?"":"s"}: Node ${f.sName} \u2192 Node ${f.dName}`;sn.set(h,{count:f.count,label:p});let m=b[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 b){if(!f)continue;let h=f.contentHeight;h>u&&(u=h,d=f.name)}return Xe&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${d}(${u.toFixed(1)})`),i}function po(e,n,t,r,o,s,a,l,i){let c=r,d,u,f,h;n-=8,t+=8;let p=b[e.node].sequenceLength;return e.features.sort((m,g)=>m.start-g.start),e.features.forEach(m=>{c!==m.type&&(d=Ce(o,c),e.isForward?(f=n+Math.round(m.start*(t-n+1)/p),i&&f<n+8&&(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,u=Ce(o,m.type),$.featureRectangles.push({xStart:f,yStart:a,xEnd:h,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),f>s+1&&$.featureRectangles.push({xStart:s,yStart:a,xEnd:f-1,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(f=t-Math.round(m.start*(t-n+1)/p),i&&f>t-8&&(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,u=Ce(o,m.type),$.featureRectangles.push({xStart:h,yStart:a,xEnd:f,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),s>f+1&&$.featureRectangles.push({xStart:f+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=f,c=m.type),(m.end<p-1||m.continue===void 0)&&(d=Ce(o,c),e.isForward?(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,$.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,$.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=h+1,c="plain")}),{xStart:s,highlight:c}}var ho=7;function mo(e,n,t,r,o,s,a,l,i,c){let d=e===1?kn:Wn,u=10*d[l],f=n+e*(u+5),h=ho,p=Math.min(ho,o),m=Math.min(t,r),g=Math.max(t,r),y=e===1?n:f-1,w=e===1?f:n,N=C=>{$.verticalRectangles.push({xStart:y,yStart:C,xEnd:w,yEnd:C+o-1,color:s,id:a,name:c,type:i})};N(t),$.verticalRectangles.push({xStart:e===1?f+h:f-h-p,yStart:m+o+h-1,xEnd:e===1?f+h+p-1:f-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),N(r);let L=f+e*h,S=f+e*(h+p),R=`M ${f} ${g}`;R+=` Q ${L} ${g} ${L} ${g-h}`,R+=` H ${S}`,R+=` Q ${S} ${g+o} ${f} ${g+o}`,R+=" Z ",$.corners.push({path:R,color:s,id:a,type:i}),R=`M ${f} ${m}`,R+=` Q ${S} ${m} ${S} ${m+o+h}`,R+=` H ${L}`,R+=` Q ${L} ${m+o} ${f} ${m+o}`,R+=" Z ",$.corners.push({path:R,color:s,id:a,type:i}),d[l]+=1}function wa(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function go(){switch(b.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),A.nodeWidthOption){case"compressed":b.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":b.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":b.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=A.charWidth;b.forEach(n=>{n.width=n.sequenceLength;let t=n.seq?.length??1;n.pixelWidth=Math.round(e*t)});break}default:throw new Error(`${A.nodeWidthOption} not implemented`)}}function Ra(){let e,n,t=Array.from(b,()=>new Set),r=Array.from(b,()=>new Set),o;A.showReads&&M.length>0?o=x.concat(M):o=x,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)q(l.sequence[i])?(e=v(l.sequence[i]),i>0?(n=l.sequence[i-1],q(n)?r[T.get(e)].add(v(n)):(r[T.get(e)].add(n),r[T.get(e)].add(te(n)))):l.type==="haplotype"&&r[T.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],q(n)?t[T.get(e)].add(v(n)):(t[T.get(e)].add(n),t[T.get(e)].add(te(n)))):l.type==="haplotype"&&t[T.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[T.get(l.sequence[i])].add(e),q(e)&&t[T.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&t[T.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[T.get(l.sequence[i])].add(e),q(e)&&r[T.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&r[T.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(A.showReads&&M.length>0){let l=b.slice();l.sort(cn);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=He(T.get(f.name),s,a);if(h){let p=d(h)+V(h).sequenceLength;i.set(f.name,p),i.set(te(f.name),p),c.set(f.name,u(h)),c.set(te(f.name),u(h))}else i.set(f.name,0),i.set(te(f.name),0),c.set(f.name,f.name),c.set(te(f.name),f.name)}),M.forEach(f=>{let h=f.sequenceNew??[];f.firstNodeOffset=(f.firstNodeOffset??0)+d(f.sequence[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+d(f.sequence[f.sequence.length-1]);for(let p=f.sequence.length-1;p>=0;p-=1){let m=v(f.sequence[p]),g=He(T.get(m),s,a);if(g&&Fn(T.get(g),s,a))if(p>0){f.sequence.splice(p,1);let y=V(g).sequenceLength;h[p].mismatches.forEach(w=>{w.pos+=y}),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 y=h[0],w=d(y.nodeName);y.mismatches.forEach(N=>{N.pos+=w}),y.nodeName=u(y.nodeName)}}})}for(let l=0;l<b.length;l+=1)if(Fn(l,s,a)&&!He(l,s,a)){let i=l;for(;Fn(i,s,a);)i=T.get(v(a[i][0])),b[l].sequenceLength+=b[i].sequenceLength,b[l].seq+=b[i].seq}x.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=v(l.sequence[i]);let c=T.get(e);He(c,s,a)&&l.sequence.splice(i,1)}});for(let l=b.length-1;l>=0;l-=1)He(l,s,a)&&b.splice(l,1)}function He(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=v(n[e][0]),o=T.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function Fn(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=v(t[e][0]),o=T.get(r);return!(n[o].length!==1||n[o][0]==="None")}function Ea(e){let n=A.focusReadNames?new Set(A.focusReadNames):null;return e.filter(t=>t.is_secondary!==!0&&(t.mapping_quality??0)>=A.mappingQualityCutoff&&(n===null||t.name!==void 0&&n.has(t.name)))}function Sa(e,n){let t=new Map;for(let r of e){let o=n(r),s=t.get(o);s===void 0?t.set(o,[r]):s.push(r)}return t}function Na(e,n){return e.xStart<n.xStart?1:e.xStart>n.xStart?-1:e.yStart>n.yStart?1:e.yStart<n.yStart?-1:0}function Ro(e,n){let t=Sa(e.filter(s=>s.type===n),s=>`${s.nodeStart},${s.nodeEnd}`);t.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Na),s.forEach(i=>{let c,d;i.yStart<i.yEnd?(c=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,d=i.xStart+(i.xEnd-i.xStart)*(1-a)):(c=i.xStart+(i.xEnd-i.xStart)*a,a+=l,d=i.xStart+(i.xEnd-i.xStart)*a);let u=`M ${i.xStart} ${i.yStart}`;u+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,u+=` V ${i.yEnd+i.width}`,u+=` C ${d} ${i.yEnd+i.width} ${d} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,u+=" Z",i.path=u})});let r=Array.from(t.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),c=l[0]??0,d=l[1]??0,u=i[0]??0,f=i[1]??0;return c<u?-1:c>u?1:d<f?-1:d>f?1:0});let o=[];for(let s of r){let a=t.get(s);a!==void 0&&o.push(...a)}return o}function Eo(e){let n=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,t=e.x,r=e.y-9;return e.width>1&&(t+=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t+9} ${r} ${t+9} ${r+9}`,t+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,n+=` L ${t} ${r}`),n+=` Q ${t} ${r+9} ${t-9} ${r+9}`,t-=9,r+=9,e.width>1&&(t-=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t-9} ${r} ${t-9} ${r-9}`,t-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,n+=` L ${t} ${r}`),n}function La(e){let n=new Map;for(let[t,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${t}`,a=n.get(s);a?a.push(o.strand):n.set(s,[o.strand])}return n}function Ta(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=La(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>Re(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=Re(s.name).name,i=new Map,c=s.nodeIds.flatMap(d=>{let u=n.get(d);if(!u)return[];let f=i.get(u.name)??0;i.set(u.name,f+1);let h=t.get(`${l} ${u.name}`)?.[f]??vn(u);return[_n(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Ca(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function Ie(e){return(e.paths?.length??0)>0}var Aa=600,Ia=3,va=15;function _a(e){return Math.max(Ia,Math.min(va,Math.floor(Aa/Math.max(1,e))))}function So(e){let n=e.paths??[],t=Ta(e),r=e.reads?Xt(e,e.reads,n.length):[],o=r.length>0?gt:mt,s=n.map((l,i)=>o(i,n.length)),a=yo(Ca(e),t,r,{nodeWidthOption:"compressed",trackWidth:_a(t.length),trackColor:l=>l.type==="read"?Yt(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function Yn(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function No(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function Lo(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function To(e){let n=Ie(e)?So(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of Yn(t))s[i.name]=No(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=Lo(t,o);return{nodePositions:s,tubeMap:{layout:t,yOffset:o,pathColors:r},extent:{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:a,maxY:l}}}function Oa(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of Yn(n)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,c)=>i-c)){let i=r.get(l),c=1/0,d=-1/0;for(let u of i){let f=t.get(u.name);f&&O(f)&&(c=Math.min(c,f.stable.start),d=Math.max(d,f.stable.start+u.sequenceLength))}c===1/0&&(c=d=s),c<s&&(c=s,d=Math.max(s,d)),s=Math.max(s,d),o.push({order:l,x0:Math.min(...i.map(u=>u.x)),x1:Math.max(...i.map(u=>u.x+u.pixelWidth)),bp0:c,bp1:d})}let a=o.find(l=>l.bp0!==-1/0);for(let l of o)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return o}function Pa(e){return e.nodes.some(O)&&Ie(e)}function Co(e){let n=Pa(e)?So(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=Oa(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of Yn(t)){let c=s.get(i.order);l[i.name]=No(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:Lo(t,a)}}function Ao(e){return e.sample??Ke(e.name)}function Ba(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Ao(e)}function $a(e,n,t,r=!0){if(!t||!r)return{ids:e,complete:!0};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((c,d)=>{let u=n.get(c);u&&(u.end<=t.start&&u.end>a&&(a=u.end,o=d),u.start>=t.end&&u.start<l&&(l=u.start,s=d))}),o<0||s<0)return{ids:e,complete:!1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0}}function Io(e,n,t){let r=e.paths??[],o=r.find(m=>Re(m.name).name===e.referencePath)??r[0];if(!o||r.length<2)return;let s=new Map(e.nodes.map(m=>[m.id,m.length])),a=e.anchorPaths?.find(m=>m.name===Re(o.name).name)?.start??0,l=n&&n.end>n.start?n:void 0,i=new Map,c=a;for(let m of o.nodeIds){let g=s.get(m)??0;i.has(m)||i.set(m,{start:c,end:c+g}),c+=g}let d=l===void 0||[...i.values()].some(m=>m.end<=l.start)&&[...i.values()].some(m=>m.start>=l.end),u=m=>{let{ids:g,complete:y}=$a(m.nodeIds,i,l,d),w=[],N=0,L=0,S=0;for(let R of g){let C=s.get(R)??0,_=i.get(R),P=w.at(-1),re=P?.referenceStart,_e=_&&re!==void 0&&S>=0&&re+P.bp===_.start,Ye=_&&re!==void 0&&S<=0&&_.end===re;!_&&P&&!P.onReference?P.bp+=C:_e||Ye?(P.bp+=C,_e||(P.referenceStart=_.start,P.reversed=!0),S=_e?1:-1):(w.push({start:N,bp:C,onReference:_!==void 0,referenceStart:_?.start}),S=0),N+=C,_||(L+=C)}return{name:m.name,label:Ba(m),sample:Ao(m),haplotype:m.haplotype,bp:N,offReferenceBp:L,complete:y,runs:w}},f=m=>m.nodeIds.some(g=>i.has(g)),h=new Set(r.filter(m=>m!==o&&f(m)).map(m=>m.name));return{origin:l?l.start:a,unit:t,reference:u(o),rows:r.filter(m=>m!==o&&(f(m)||!h.has(m.name))).map(u).sort((m,g)=>Number(g.complete)-Number(m.complete)||g.bp-m.bp||m.label.localeCompare(g.label))}}var Ga=1.3;function Fa(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*Ga,maxY:e.rows.length*20}}function vo(e,n){let t=Me(e),r=Io(e,n);if(t.length===0||!r)return;let o=we(t),s=[{label:r.reference.label,y:0},...r.rows.map((a,l)=>({label:a.label,y:(l+1)*20}))];return{nodePositions:o,rowLabels:s,referenceAxis:!0,pixelRows:!0,extent:Fa(r)}}var Da="Force-directed layout",fe=e=>e.nodes.some(O),_o=e=>fe(e)&&(e.paths?.length??0)>1,Oo=e=>fe(e)&&Ie(e),Po=e=>fe(e)&&e.nodes.some(Qe),zn=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:Ut,cutMargins:!0,wholeWalks:!1,available:fe,drawsLocally:fe,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:Jt,cutMargins:!0,wholeWalks:!1,available:Po,drawsLocally:Po,drawsNodes:!0},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, sequence the reference also carries in blue and sequence it does not in purple, so a repeat expansion reads as bar length. Needs W or P lines.",run:vo,cutMargins:!1,wholeWalks:!0,available:_o,drawsLocally:_o,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:Zt,cutMargins:!1,wholeWalks:!1,available:fe,drawsLocally:fe,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:To,cutMargins:!1,wholeWalks:!1,available:Ie,drawsLocally:Ie,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:Co,cutMargins:!0,wholeWalks:!1,available:Oo,drawsLocally:Oo,drawsNodes:!1},{value:"force",label:Da,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],mc=zn.map(e=>e.value);function gc(e,n){return!qa(e).drawsLocally(n)}function qa(e){return zn.find(n=>n.value===e)??zn[0]}var Wa=10;function ka(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=Wa*(o.end-o.start)&&(t===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=t/2))}var Ha=40;function pe(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Xa(e,n){let t=pe(e),r=pe(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function Bo(e){return e>=bt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function xc(e,n=[]){let t=Ya(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function Ya(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=Xa(r,o);if(a>=Ha)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${Bo(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${pe(o)} inv`};let c=o!==r?ka(e,n):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${Bo(s)}`}}let d=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${pe(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${pe(o-t)} ins${d}`}:o===t?{kind:"deletion",label:`${pe(t-r)} del${d}`}:{kind:"complex",label:`${pe(t)} ref \u2192 ${i}, ${s} alleles`}}var Mc={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},wc={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function Rc(e){return e.segments.split(",").filter(Boolean)}function Sc({count:e,bounds:n,pixelRows:t,width:r,room:o,columns:s}){function a(i){let c=Math.ceil(e/i),d=Math.floor((r-(i-1)*8)/i),u=(o-c*34-(c-1)*8)/c,f=(d-24)/n.w,h=n.h>0?(u-24)/n.h:1/0,p=t?f:Math.min(f,h),m=t?n.h:n.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 Nc(e,n){let t={columns:void 0,count:e.length,cells:e.map((l,i)=>i)};if(n==="walk")return t;let r=e.map(l=>{let[i,c,d]=l.split("#"),u=Number(c);return d!==void 0&&Number.isInteger(u)&&u>=0?{sample:i,column:Math.max(0,u-1)}:void 0}),o=[...new Set(r.map(l=>l?.sample))],s=Math.max(1,...r.map(l=>l?l.column+1:1)),a=r.map(l=>l?o.indexOf(l.sample)*s+l.column:-1);return a.includes(-1)||new Set(a).size<a.length?t:{columns:s,count:o.length*s,cells:a}}var ve=k(Se(),1),Wo=k(Go(),1),ko=k(Do(),1);var qo=class extends ko.Canvas2DRenderingBackendBase{constructor(){super(...arguments);this.transform=null;this.batch=null;this.nodeHighlights=new Map;this.highlightedEdge=null;this.highlightFactor=1}resize(t,r){(0,Wo.syncCanvasSize)(this.ctx.canvas,t,r)}uploadGeometry(t){this.batch=t,this.highlightedEdge=null}setNodeHighlights(t){this.nodeHighlights=t}setEdgeHighlight(t,r){this.highlightedEdge=t,this.highlightFactor=r}updateTransform(t){this.transform=t}render(t){if(!this.transform)return;let o=this.ctx,{width:s,height:a}=o.canvas;t[3]<1&&o.clearRect(0,0,s,a),o.fillStyle=(0,ve.normalizedRgbToCssRgba)([t[0],t[1],t[2]],t[3]),o.fillRect(0,0,s,a);let l=this.batch;l&&(o.lineCap="round",o.lineJoin="round",this.renderEdges(l),this.renderNodes(l),this.renderArrows(l))}renderEdges(t){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:t.edgeCurveRuns.get(this.highlightedEdge);for(let{color:a,items:l}of jn(t.edgeCurves,(i,c)=>({color:un(s,c)?nn(i.color,this.highlightFactor):i.color,weight:i.thickness,last:un(s,c)}))){o.strokeStyle=(0,ve.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.curves[0];o.moveTo(c.x0*r.scaleX+r.translateX,c.y0*r.scaleY+r.translateY);for(let d of i.curves)o.bezierCurveTo(d.cx0*r.scaleX+r.translateX,d.cy0*r.scaleY+r.translateY,d.cx1*r.scaleX+r.translateX,d.cy1*r.scaleY+r.translateY,d.x1*r.scaleX+r.translateX,d.y1*r.scaleY+r.translateY)}o.stroke()}}renderNodes(t){let r=this.transform,o=this.ctx,s=new Map;for(let[a,l]of this.nodeHighlights){let i=t.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 jn(t.nodeStrokes,(i,c)=>{let d=s.get(c);return{color:d===void 0?i.color:nn(i.color,d),weight:i.thickness,last:d!==void 0}})){o.strokeStyle=(0,ve.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.points[0];o.moveTo(c.x*r.scaleX+r.translateX,c.y*r.scaleY+r.translateY);for(let d=1,u=i.points.length;d<u;d++){let f=i.points[d];o.lineTo(f.x*r.scaleX+r.translateX,f.y*r.scaleY+r.translateY)}}o.stroke()}}renderArrows(t){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:t.arrowRuns.get(this.highlightedEdge);for(let{color:a,items:l}of jn(t.arrows,(i,c)=>({color:un(s,c)?nn(i.color,this.highlightFactor):i.color,weight:0,last:un(s,c)}))){o.fillStyle=(0,ve.abgrToCssRgba)(a),o.beginPath();for(let i of l){let[c,d,u,f]=ja(i,r);o.moveTo(c.x,c.y),o.lineTo(d.x,d.y),o.lineTo(u.x,u.y),o.lineTo(f.x,f.y),o.closePath()}o.fill()}}dispose(){super.dispose(),this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},za=.25;function ja(e,n){let t=Math.cos(e.angle),r=Math.sin(e.angle),o=e.x*n.scaleX+n.translateX,s=e.y*n.scaleY+n.translateY,a=e.length*n.dpr,l=e.halfWidth*n.dpr,i=o-t*a,c=s-r*a,d=a*(1-za);return[{x:o,y:s},{x:i-r*l,y:c+t*l},{x:o-t*d,y:s-r*d},{x:i+r*l,y:c-t*l}]}function un(e,n){return e!==void 0&&n>=e.start&&n<e.start+e.count}function jn(e,n){let t=new Map,r=new Map;for(let o=0,s=e.length;o<s;o++){let a=e[o],{color:l,weight:i,last:c}=n(a,o),d=c?r:t,u=`${l}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:l,items:[a]})}return[...t.values(),...r.values()]}var jo=k(Se(),1);var Ua=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],Uo=[{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"}],Ho=["blue","red","purple","green"],Va=e=>Ua.some(n=>n.value===e),Ka=e=>Uo.some(n=>n.value===e);function _c(e,n,t,r=!0){let{field:o,scheme:s}=e.color??{},a=Va(o)?o:r?"progress":"walk",l=n?"grey":Ho[t%Ho.length],i=Ka(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var Vo=.5,Qa=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Za=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function Xo(e){let[n,t,r]=[1,3,5].map(l=>Qa(Number.parseInt(e.slice(l,l+2),16)/255)),o=Math.cbrt(.4122214708*n+.5363325363*t+.0514459929*r),s=Math.cbrt(.2119034982*n+.6806995451*t+.1073969566*r),a=Math.cbrt(.0883024619*n+.2817188376*t+.6299787005*r);return[.2104542553*o+.793617785*s-.0040720468*a,1.9779984951*o-2.428592205*s+.4505937099*a,.0259040371*o+.7827717662*s-.808675766*a]}function Ja([e,n,t]){let r=(e+.3963377774*n+.2158037573*t)**3,o=(e-.1055613458*n-.0638541728*t)**3,s=(e-.0894841775*n-1.291485548*t)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s].map(a=>Za(Math.max(0,Math.min(1,a)))*255)}function Ko(e,n){let t=Math.max(0,Math.min(1,n)),r=Uo.find(a=>a.value===e);if(!r||!("ends"in r))return Le(t*Nn,.7,.5).map(a=>a*255);let o=Xo(r.ends[0]),s=Xo(r.ends[1]);return Ja(o.map((a,l)=>a+(s[l]-a)*t))}function Yo(e,n){let[t,r,o]=Ko(e,n).map(Math.round);return`rgb(${t}, ${r}, ${o})`}function zo(e,n){let[t,r,o]=Ko(e,n).map(Math.round);return(0,jo.packAbgr)(t,r,o,255)}function Oc({field:e,scheme:n},t){return e==="walk"?zo(n,Vo):t===void 0?ei:zo(n,t)}var ei=Ln;function ni({field:e,scheme:n}){return e==="walk"?[{offset:0,color:Yo(n,Vo)}]:Array.from({length:7},(t,r)=>({offset:r/6,color:Yo(n,r/6)}))}function Pc(e){let n=ni(e);return n.length===1?n[0].color:`linear-gradient(to right, ${n.map(t=>`${t.color} ${t.offset*100}%`).join(", ")})`}function Qo(e,n,t){let r=Math.round(n),o=Math.round(t);return`${e?`${e}:`:""}${De(r)}-${De(o)} (${Ee(o-r)})`}function Gc(e,n){let{field:t}=e.encoding,r=e.range?Qo(e.range.contig,e.range.start,e.range.end):void 0,o=t==="progress"?r:t==="reference"&&n?Qo(n.name,n.start,n.end):void 0;return{delta:e.referenceBp===void 0||e.bp===e.referenceBp?"":` ${e.bp>e.referenceBp?"+":"\u2212"}${Ee(Math.abs(e.bp-e.referenceBp))}`,reversed:e.reversedBp>0?`, ${Ee(e.reversedBp)} reversed`:"",shades:t!=="walk",scale:o,hover:o===r?void 0:r}}function Fc(e,n,t){let r=e.progress.get(n),o=e.range;if(r===void 0||!o)return;let s=Math.round(o.start+r*e.bp-t/2);return`${o.contig}:${De(s)}-${De(s+t)}`}var Un=k(Se(),1);var oe=12,ti=oe+8,tr=8,Zo=tr+3,oi=12;function kc(e,{colorScheme:n,referenceRamp:t,walks:r}){let o={...Tn(e),referenceRamp:t},s=[];return e.nodes.forEach((a,l)=>{if(O(a)){let i=r?r.map(c=>{let d=c.colors.get(a.id);return d===void 0?Sn:(0,Un.abgrToCssRgba)(d)}):[(0,Un.abgrToCssRgba)(Cn(a,l,n,o))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(Sn)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function Vn(e,n,t){let r=n*e.scale+e.translateX,o=t*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var Jo=2;function ri(e,n,t){let r=-n.translateX/n.scale,o=(t-n.translateX)/n.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let c of e)l+=Math.max(0,Math.min(c.bp1,s)-c.bp0),i+=Math.max(0,c.bp1-Math.max(c.bp0,a));return n.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function Hc(e,n,t,r){if(r<0||r>oe+Jo)return;let o,s=Jo;for(let a of e){let[l,i]=Vn(n,a.bp0,a.bp1),c=Math.max(0,l-t,t-i);c<=s&&(s=c,o=a.node)}return o}function Xc(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function si(e,n,t,r){let o=e.map(c=>{let[d,u]=Vn(n,c.bp0,c.bp1),f=Math.round(d*r);return{colors:c.colors,x0:d,px0:f,px1:Math.max(Math.round(u*r),f+1)}}).filter(c=>c.px1>0&&c.px0<t*r).sort((c,d)=>c.x0-d.x0),s=[],a=-1/0,l=[-1/0,-1/0];for(let{colors:c,px0:d,px1:u}of o){let f=Math.max(d,a);if(u>f){let h=l[0]<f?0:1;l[h]=u,s.push({colors:c,x0:f/r,x1:u/r,tier:h}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*oi?s:s.map(({tier:c,...d})=>d)}function er(e,n,t,r){let o=t>0?n:n-Zo;e.clearRect(o,0,Zo,oe);let s=n+t,a=s+t*tr;e.beginPath(),e.moveTo(s,oe/2),e.lineTo(a,0),e.lineTo(a,oe),e.closePath(),e.fillStyle=r,e.fill()}function nr(e,n,t){return Math.round(e*oe*t/n)/t}function Yc(e,n,t,{width:r,lit:o,darkMode:s,dpr:a=1}){let l=s?"#ffffff":"#18181c";e.clearRect(0,0,r,ti);for(let c of si(n,t,r,a)){let{tier:d}=c,u=d!==void 0&&c.colors.length===1,f=u?2:c.colors.length;c.colors.forEach((h,p)=>{let m=u?d:p,g=nr(m,f,a);e.fillStyle=h,e.fillRect(c.x0,g,c.x1-c.x0,nr(m+1,f,a)-g)})}let i=ri(n,t,r);if(i.left>0&&er(e,0,1,l),i.right>0&&er(e,r,-1,l),o){let[c,d]=Vn(t,o.start,o.end),u=Math.max(d-c,3),f=(c+d)/2-u/2;e.strokeStyle=l,e.lineWidth=1.5,e.strokeRect(f,.75,u,oe-1.5),o.anchor&&(e.beginPath(),e.moveTo(f+u/2,oe),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function Vc(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;n.nodes.forEach(o=>{let s=t.get(o.name);if(o.order>=0&&s&&O(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function Kn(e,n,t=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(t?i<n:i<=n)?r=l+1:o=l}let s=e[r];if(n<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(n,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function Qn(e,n,t){let r=Kn(e,n),o=Kn(e,t,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function Kc(e){let n;for(let t of e.values())(!n||t.length>n.length)&&(n=t);return n}var or=5,ai=10,ii=110,li=3;function ci(e){return e?"#b0b0b8":"#55555c"}function ui(e){let n=10**Math.floor(Math.log10(e)),t=e/n;return(t<=1?1:t<=2?2:t<=5?5:10)*n}function rr(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+ai)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function di(e,n,t,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=n(o.x0),l=n(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let c=ui(i/(l-a)*ii),d=[],u=[];for(let f=Math.ceil(o.bp0/c)*c;f<=s.bp1;f+=c){let h=Math.round(n(Kn(e,f)))+.5;if(h>=0&&h<=t){d.push(h);let p=f.toLocaleString("en-US");u.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:d,labels:rr(u)}}function fi(e,n,t,r){let o=e.map(p=>({box:p,s0:n(p.x0),s1:n(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=t),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),c=[],d=[],u=[],f=[];for(let{box:p,s0:m,s1:g}of o){c.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=li&&d.push(Math.round(g)+.5);let y=l(Ee(p.bp1-p.bp0),(m+g)/2);y.width<=g-m&&u.push(y),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:rr([...h,...u,...f])}}function pi(e,n,t,r,o=!1){return(o?di:fi)(e,n,t,r)}function Qc(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=pi(n,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=ci(l),d=r+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:f}of i.spans)e.moveTo(Math.max(0,u),d),e.lineTo(Math.min(a,f),d);for(let u of i.ticks)e.moveTo(u,r),e.lineTo(u,r+or);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,r+or+2)}function eu(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach(o=>{let s=t.get(o.name);o.order>=0&&s&&O(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function nu(e,n,t,r){let o=[];for(let s of e){let a=t(s.x0),l=t(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:n(s.bp0),top1:n(s.bp1),bottom0:a,bottom1:l})}return o}var hi=3;function tu(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=hi;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,c=l.top1+(l.bottom1-l.top1)*o,d=Math.max(0,Math.min(i,c)-t,t-Math.max(i,c));d<a&&(a=d,s=l.node)}return s}function sr(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.top1,0),e.lineTo(n.bottom1,t),e.lineTo(n.bottom0,t),e.closePath()}function ar(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function ou(e,n,t,{highlightNode:r,darkMode:o}){if(t<=0||n.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of n)sr(e,l,t);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of n)ar(e,l,t);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=n.find(l=>l.node===r);a&&(e.beginPath(),sr(e,a,t),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),ar(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function mi(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach((o,s)=>{let a=t.get(o.name);if(o.order>=0&&a&&O(a)){let l=a.stable.start;r.push({bp0:l,bp1:l+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function gi(e,n,t){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=n?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&t.has(s.index)&&s.bp0<=n&&n<=s.bp1)}function au(e,n,t){let r=mi(e,n),o=[];for(let s of n.tracks){let a=s.name?t.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=gi(r,i.start,l);if(c){let{node:d,bp0:u,bp1:f}=c,h=p=>d.x+(Math.min(p,f)-u)/(f-u)*d.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(c.index),height:s.width})}}}}return o}function bi(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function iu(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=bi(s),e.beginPath();for(let a of n){let l=t(a.x0),i=Math.max(t(a.x1),l+1);if(i>=0&&l<=o){let c=r(a.y);e.rect(l,c,i-l,r(a.y+a.height)-c)}}e.fill()}}function yi(e,n){let t=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=n.nodeMap.get(v(o.nodeName)),l=a===void 0?void 0:n.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=>wo(l,f);for(let f of o.mismatches){let h=u(f.pos);if(h!==null){if(f.type==="insertion"){let p=s===0&&f.pos===e.firstNodeOffset||s===r.length-1&&f.pos===e.finalNodeCoverLength;t.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&&t.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&&t.push({...d,kind:"substitution",x0:h,x1:p,seq:f.seq})}}}}}),t}function ir(e){return e.reads.flatMap(n=>yi(n,e))}function pr(e){let n=e.trim().split(/[\s,]+/),t=[],r=0,o=()=>Number(n[r++]);for(;r<n.length;){let s=n[r++];s==="M"||s==="L"?t.push({op:s,x:o(),y:o()}):s==="H"?t.push({op:s,x:o()}):s==="V"?t.push({op:s,y:o()}):s==="Q"?t.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?t.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&t.push({op:s})}return t}function hr(e){let n=1/0,t=-1/0;for(let r of e)"x"in r&&(n=Math.min(n,r.x),t=Math.max(t,r.x)),"x1"in r&&(n=Math.min(n,r.x1),t=Math.max(t,r.x1));return{x0:n,x1:t}}function lr(e,n,t,r){let o=pr(e);return{commands:o,color:n,track:r,alpha:t,...hr(o)}}function cr(e,n){let{shapes:t}=e,r=l=>n==="haplotype"?l.id:void 0,o=[...t.rectangles,...t.verticalRectangles].filter(l=>l.type===n).map(l=>({color:l.color,track:r(l),alpha:l.alpha??1,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),s=Ro(t.curves,n).map(l=>lr(l.path,l.color,l.alpha??1,r(l))),a=t.corners.filter(l=>l.type===n).map(l=>lr(l.path,l.color,1,r(l)));return{rects:o,shapes:[...s,...a]}}function pu(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=pr(Eo(t));n.push({name:t.name,commands:r,...hr(r)})}}),{bounds:e.bounds,layers:[cr(e,"haplotype"),cr(e,"read")],nodes:n,mismatches:ir(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function ur(e,n,t,r){let o=0,s=0;for(let a of n)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(t(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(t(o),r(s));break;case"H":o=a.x,e.lineTo(t(o),r(s));break;case"V":s=a.y,e.lineTo(t(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(t(a.x1),r(a.y1),t(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(t(a.x1),r(a.y1),t(a.x2),r(a.y2),t(o),r(s));break;case"Z":e.closePath();break}}function dr(e,n,t,r,o){let s=new Map;for(let a of n)if(t(a)){let l=`${r(a)}|${a.alpha}`,i=s.get(l);i?i.push(a):s.set(l,[a])}for(let a of s.values()){e.fillStyle=r(a[0]),e.globalAlpha=a[0].alpha,e.beginPath();for(let l of a)o(l);e.fill()}e.globalAlpha=1}var xi=12,Mi=.15;function wi(e){return Math.max(Mi,Math.min(1,e/xi))}var Ri=.55;function hu(e,n,t){let{x:r,y:o,width:s}=t,a=d=>r(d.x1)>=0&&r(d.x0)<=s,l=d=>d.track!==void 0&&t.tubeColors?.[d.track]||d.color;for(let d of n.layers)dr(e,d.rects,a,l,u=>{let f=r(u.x0),h=o(u.y0);e.rect(f,h,r(u.x1)-f,o(u.y1)-h)}),dr(e,d.shapes,a,l,u=>{ur(e,u.commands,r,o)});let i=t.darkMode?"#d0d0d0":"#000000",c=t.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,t.yScale));for(let d of n.nodes)if(a(d)){let u=d.name===t.highlightNode;e.beginPath(),ur(e,d.commands,r,o);let f=u?void 0:t.nodeColors?.get(d.name);e.fillStyle=u?"rgba(255,192,203,0.5)":f??c,e.strokeStyle=u?"#ff0000":i,e.globalAlpha=f?Ri:1,e.fill(),e.globalAlpha=u?1:wi(r(d.x1)-r(d.x0)),e.stroke(),e.globalAlpha=1}Ni(e,n.mismatches,t)}var mr=12,Ei=6;function Si(e){return mr*e>=Ei}function fr(e,{x:n,width:t}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return n(o)>=0&&n(r)<=t}function Ni(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!Si(s)||n.length===0)return;let l=mr*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&fr(i,t)){let c=r(i.x0),d=o(i.y);e.rect(c,d,r(i.x1)-c,o(i.y+i.height)-d)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of n)fr(i,t)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function bu(e,n){let t=[];for(let r of n){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||t.push({gene:r,...Qn(o,l,i),exons:r.exons.filter(c=>c.end>l&&c.start<i).map(c=>Qn(o,Math.max(c.start,l),Math.min(c.end,i)))})}return t}var gr=22,Li=4,dn=8,Ti="11px sans-serif",Ci=8;function yu(e){let n=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),t=0,r=0;for(let{step:o}of n)t+=o,r=Math.max(r,t);return Math.min(Li,r)}function xu(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/gr)),c=[],d=l?"#e0e0e6":"#1c1c22";e.font=Ti,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=n.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}`,y=(Math.max(h,0)+Math.min(p,a))/2,w=e.measureText(g).width/2,N=Math.min(h,y-w),L=Math.max(p,y+w),S=c.findIndex(C=>C+Ci<=N);S===-1&&(S=Math.min(c.length,i-1)),c[S]=Math.max(c[S]??-1/0,L);let R=r-S*gr-dn/2;e.beginPath(),e.moveTo(h,R+.5),e.lineTo(p,R+.5),e.stroke();for(let C of f.exons){let _=s(C.x0);e.fillRect(_,R-dn/2,Math.max(1,s(C.x1)-_),dn)}e.fillText(g,y,R-dn/2-2)}}function Ai(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function Ii(e,n){let t=e.length,r=n.length,o=Array.from({length:t+1},()=>new Array(r+1).fill(0)),s=Array.from({length:t+1},()=>new Array(r+1).fill(!1));for(let l=t-1;l>=0;l--)for(let i=r-1;i>=0;i--){let c=Math.abs(e[l]-n[i])+o[l+1][i+1],d=t-l>r-i?o[l+1][i]:1/0,u=r-i>t-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,d,u),s[l][i]=o[l][i]===c}let a=new Array(t).fill(void 0);for(let l=0,i=0;l<t&&i<r;)s[l][i]?a[l++]=i++:t-l>r-i?l++:i++;return a}function br(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var xr=e=>e.spanningReads!==0;function yr(e,n){return{...n,agrees:e.complete&&xr(n)?Ai(e.bp,n.bp):void 0}}function vi(e,n){let t=new Map,r=new Set;e.forEach((l,i)=>{let c=n.find(d=>d.haplotype!==void 0&&d.haplotype===l.haplotype);c&&(r.add(c),t.set(i,yr(l,c)))});let o=n.filter(l=>l.haplotype===void 0),s=br(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(xr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!t.has(u.i)),d=br(i.filter(u=>!r.has(u)),u=>u.bp);Ii(c.map(u=>u.item.bp),d.map(u=>u.item.bp)).forEach((u,f)=>{if(u!==void 0){let h=c[f],p=d[u].item;r.add(p),t.set(h.i,yr(h.item,p))}})}return t}function wu(e,n){if(!n)return e;let t=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=n[o];if(a)for(let[l,i]of vi(s,a))t.set(s[l],i)}return e.map(o=>({...o,call:t.get(o)}))}var Mr=k(Ve(),1),Su=(0,U.createSvgIcon)((0,Mr.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{U as a,ys as b,Se as c,qe as d,Fr as e,vs as f,vn as g,ws as h,Rs as i,La as j,Io as k,Fa as l,zn as m,mc as n,gc as o,qa as p,pe as q,xc as r,Mc as s,wc as t,Rc as u,Sc as v,Nc as w,Ar as x,wt as y,Pr as z,Br as A,$i as B,Go as C,qo as D,Lt as E,Sn as F,Nn as G,Qi as H,Zi as I,Tn as J,Cn as K,Ji as L,Ua as M,Uo as N,_c as O,Oc as P,ei as Q,ni as R,Pc as S,Qo as T,Gc as U,Fc as V,ti as W,kc as X,ri as Y,Hc as Z,Xc as _,Yc as $,Vc as aa,Kc as ba,ci as ca,Qc as da,eu as ea,nu as fa,tu as ga,ou as ha,au as ia,bi as ja,iu as ka,pu as la,hu as ma,Si as na,fr as oa,bu as pa,gr as qa,yu as ra,xu as sa,wu as ta,ol as ua,rl as va,hs as wa,sl as xa,al as ya,An as za,yl as Aa,xl as Ba,Su as Ca};
|
|
2
|
+
//# sourceMappingURL=chunk-X2HKDCRG.js.map
|