jbrowse-plugin-graphgenomeviewer 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{GraphGenomeView-PZXBBVUE.js → GraphGenomeView-HZ2EQUOC.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-BGZYUENK.js → LinearGraphDisplay-MJ4ZBJRX.js} +2 -2
- package/dist/chunks/{chunk-FNZHIZQC.js → chunk-F2EPKNTV.js} +1 -1
- package/dist/chunks/{chunk-FNZHIZQC.js.map → chunk-F2EPKNTV.js.map} +3 -3
- package/dist/chunks/{chunk-TCGFPZ4Y.js → chunk-KCL5TF5X.js} +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +2 -2
- package/package.json +2 -2
- package/src/GraphGenomeView/model.test.ts +17 -0
- package/src/GraphGenomeView/model.ts +11 -3
- package/src/version.ts +1 -1
- /package/dist/chunks/{GraphGenomeView-PZXBBVUE.js.map → GraphGenomeView-HZ2EQUOC.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-BGZYUENK.js.map → LinearGraphDisplay-MJ4ZBJRX.js.map} +0 -0
- /package/dist/chunks/{chunk-TCGFPZ4Y.js.map → chunk-KCL5TF5X.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as x}from"./chunk-
|
|
1
|
+
import{a as x}from"./chunk-KCL5TF5X.js";import"./chunk-F2EPKNTV.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-BUXVOMDL.js";import{Z as L}from"./chunk-UTWFU4X6.js";import"./chunk-7BKUWQE5.js";import"./chunk-KULNKXPT.js";import{a as B}from"./chunk-J6KYLXRD.js";import{a as s,b as v,c as g,d as G}from"./chunk-TYJTJGPO.js";import{b as a}from"./chunk-FY3BTKY4.js";var S=a(g(),1);var m=a(v(),1),n=a(G(),1),C=a(g(),1),P=a(L(),1),o=a(s(),1),I=(0,P.makeStyles)()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),b=(0,C.observer)(function({model:e}){let{classes:r}=I();return e.isLoading?(0,o.jsxs)(n.Paper,{className:r.paper,"data-testid":"graph-genome-loading",children:[(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(m.LoadingEllipses,{variant:"h6",message:e.statusMessage}),(0,o.jsx)(n.Button,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),(0,o.jsx)(n.LinearProgress,{variant:"indeterminate"})]}):e.error?(0,o.jsx)(n.Paper,{className:r.paper,children:(0,o.jsx)(m.ErrorBanner,{error:e.error,onReset:()=>{e.retryLoad()}})}):(0,o.jsx)(n.Paper,{className:r.paper,"data-testid":"graph-genome-load-canceled",children:(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(n.Typography,{variant:"h6",children:"Loading canceled"}),(0,o.jsx)(n.Button,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),h=b;var M=a(B(),1),N=a(v(),1),i=a(G(),1),w=a(g(),1),E=a(L(),1),t=a(s(),1),k=`H VN:Z:1.0
|
|
2
2
|
S 1 ACGT
|
|
3
3
|
S 2 GGCC
|
|
4
4
|
S 3 TTAA
|
|
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
|
|
|
7
7
|
L 1 + 3 + 0M
|
|
8
8
|
L 2 + 4 + 0M
|
|
9
9
|
L 3 + 4 + 0M`,z=(0,E.makeStyles)()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),R=(0,w.observer)(function({model:e}){let{classes:r}=z(),[d,T]=(0,M.useState)("");function y(){d.trim()&&e.loadGFAFromLocation({uri:d,locationType:"UriLocation"})}function A(p){let c=p.target.files?.[0];c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return(0,t.jsxs)(i.Paper,{className:r.paper,children:[(0,t.jsx)("div",{className:r.header,children:(0,t.jsx)(i.Typography,{variant:"h6",children:"Load a GFA graph"})}),(0,t.jsxs)("div",{className:r.column,children:[(0,t.jsxs)("div",{className:r.rowCenter,children:[(0,t.jsxs)(i.Button,{variant:"outlined",component:"label",size:"small",children:["Choose file",(0,t.jsx)("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:p=>{A(p)}})]}),(0,t.jsx)(i.Typography,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),(0,t.jsxs)("div",{className:r.rowEnd,children:[(0,t.jsx)(i.TextField,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:d,onChange:p=>{T(p.target.value)},onKeyDown:p=>{p.key==="Enter"&&y()},className:r.flex1}),(0,t.jsx)(i.Button,{variant:"contained",onClick:()=>{y()},disabled:!d.trim(),children:"Open"})]})]}),(0,t.jsx)("div",{className:r.footer,children:(0,t.jsx)(i.Button,{size:"small",onClick:()=>{e.loadGFA(k,"Example graph")},children:"Load 4-node example"})}),e.error?(0,t.jsx)(N.ErrorBanner,{error:e.error}):null]})}),F=R;var l=a(s(),1),U=(0,S.observer)(function({model:e}){return e.hasGraph?(0,l.jsx)(x,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?(0,l.jsx)(h,{model:e}):(0,l.jsxs)(l.Fragment,{children:[e.isLoading?(0,l.jsx)(h,{model:e}):null,(0,l.jsx)("div",{hidden:e.isLoading,children:(0,l.jsx)(F,{model:e})})]})}),O=U;export{O as default};
|
|
10
|
-
//# sourceMappingURL=GraphGenomeView-
|
|
10
|
+
//# sourceMappingURL=GraphGenomeView-HZ2EQUOC.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=LinearGraphDisplay-
|
|
1
|
+
import{a as i}from"./chunk-KCL5TF5X.js";import"./chunk-F2EPKNTV.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-BUXVOMDL.js";import"./chunk-UTWFU4X6.js";import"./chunk-7BKUWQE5.js";import"./chunk-KULNKXPT.js";import"./chunk-J6KYLXRD.js";import{a as e,c as d}from"./chunk-TYJTJGPO.js";import{a as h,b as t}from"./chunk-FY3BTKY4.js";var p=h((l,o)=>{o.exports=JBrowseExports["@jbrowse/display-kit/DisplayChrome"]});var s=t(p(),1),n=t(d(),1);var r=t(e(),1),y=(0,n.observer)(function({model:a}){return(0,r.jsx)(s.DisplayStatusChrome,{model:a,phase:a.displayPhase,drawn:a.painted&&a.geometryPainted,testid:"linear-graph-display","data-layout":a.chosenLayoutMode,"data-cut-tier":a.cutTier,"data-recuts":a.recuts,"data-node-count":a.hasGraph?a.nodeCount:void 0,"data-loading":a.isLoading?"":void 0,style:{width:a.paneWidth,height:a.height,overflow:"hidden"},children:(0,r.jsx)(i,{model:a,ownChrome:!1})})}),c=y;export{c as default};
|
|
2
|
+
//# sourceMappingURL=LinearGraphDisplay-MJ4ZBJRX.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{d as Gn}from"./chunk-UQEPPJEO.js";import{c as wn}from"./chunk-SCMIJAAX.js";import{A as In,B as It,C as vn,D as Pn,E as vt,F as Pt,I as On,J as kn,W as Bn,X as pt,a as le,i as Mn,j as _t,k as Rn,l as En,m as Sn,n as Nn,o as Ln,p as Tn,u as An,v as ft,w as Cn,x as Ve,y as xe,z as _n}from"./chunk-UTWFU4X6.js";import{a as Ue,b as k,c as ut,d as ve,e as yn,f as Pe,i as dt}from"./chunk-7BKUWQE5.js";import{a as lt,c as xn,d as ct}from"./chunk-KULNKXPT.js";import{a as it}from"./chunk-TYJTJGPO.js";import{a as je,b as Y}from"./chunk-FY3BTKY4.js";var Fn=je((Il,$n)=>{$n.exports=JBrowseExports["@mui/material/SvgIcon"]});var ke=je((Bl,qn)=>{qn.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var zs=je((Mc,uo)=>{uo.exports=JBrowseExports.mobx});var mr=je((ed,hr)=>{hr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var br=je((td,gr)=>{gr.exports=JBrowseExports["@jbrowse/render-core/renderingBackendBase"]});var ne=Y(Fn(),1);var ns=3.4,Wn=6,os=8,rs=18,ss=2,as=15;function is(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,r]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],o=s=>+(s/n).toFixed(n===1?0:1);return`${o(e.covered*t)} of ${o(t)} ${r}`}function ls(e,t,n){return Dn(e,r=>r.gene.end-r.gene.start).map(r=>{let{x:o,y:s}=t(r.at),a=is(r);return{item:r,x:o,y:s+n+rs,text:a?`${r.gene.name} \xB7 ${a}`:r.gene.name,fallback:a?`${r.gene.name} \u2026`:void 0,stack:ss}})}function Dn(e,t){return[...e].sort((n,r)=>t(r)-t(n))}function kl(e){let{paneWidth:t,canvasHeight:n,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:t,height:n},i=R=>({x:R.x*s+r,y:R.y*a+o}),c=e.drawnRowLabels.map(({label:R,y:N})=>Cn(R,N*a+o)),d=e.referenceStripZonePx??0;d>0&&c.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&c.push({x0:t-Wn-e.legendSize.width,x1:t,y0:0,y1:d+Wn+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let u=An(l,c),f=e.drawnRowLabels.length>0,h=f?Math.min(...e.drawnRowLabels.map(R=>R.y)):1/0,p=e.contigThickness*ns,m=Dn(e.bubbleHalos,R=>R.members),g=ft(m.map(R=>{let{x:N,y:v}=i({x:R.labelAt.x,y:Math.min(R.labelAt.y,h)}),H=v-p/2-6;return{item:R,x:N,y:f?Math.max(H,as):H,text:R.label}}),l,u),b=ft(ls(e.genePins,i,e.contigThickness),l,u),w=e.nodePositions&&e.labelsNodeSizes?_n({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],deletionRoutes:e.deletionRoutes,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},S=It(w.deletions,u),E=ft(m.flatMap(R=>R.routes.map(N=>{let{x:v,y:H}=i(N.at);return{item:{halo:R,route:N},x:v,y:H+4,text:N.text,stack:os}})),l,u),T=It(w.nodes,u,In(t,n));return{bubbles:g,genes:b,routes:E,sizes:[...S,...T]}}var $=Y(ke(),1);var B=Y(ke(),1);function Ge(e,t){return(0,B.packAbgr)((0,B.abgrRed)(e),(0,B.abgrGreen)(e),(0,B.abgrBlue)(e),Math.round((0,B.abgrAlpha)(e)*t))}function ht(e,t){return(0,B.packAbgr)(Math.min(255,Math.round((0,B.abgrRed)(e)*t)),Math.min(255,Math.round((0,B.abgrGreen)(e)*t)),Math.min(255,Math.round((0,B.abgrBlue)(e)*t)),(0,B.abgrAlpha)(e))}var cs=4;function Qe(e){let t=new Map;function n(r,o){let s=t.get(r);s?s.push(o):t.set(r,[o])}for(let r of e.edges)n(r.from,r.to),n(r.to,r.from);return t}function us({nodeId:e,nodeById:t,neighbors:n}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<cs&&o.length>0;l++){let i=[];for(let c of o){let d=n.get(c);if(d){for(let u of d)if(!r.has(u)){r.add(u);let f=t.get(u);f&&k(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 ds({nodeId:e,nodeById:t,neighbors:n}){let r=t.get(e);return r===void 0?void 0:k(r)?{start:r.stable.start,end:r.stable.start+r.length}:us({nodeId:e,nodeById:t,neighbors:n})}function Hn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=Qe(e),r=new Map;for(let o of e.nodes){let s=ds({nodeId:o.id,nodeById:t,neighbors:n});s&&r.set(o.id,(s.start+s.end)/2)}return r}var Xn=new WeakMap;function Yn(e,t,n,r,o,s){let{scaleX:a,scaleY:l}=n,i=Xn.get(e);if(i?.graph===t&&i.scaleX===a&&i.scaleY===l&&i.deletions===r&&i.routes===s&&i.version===o)return i.curves;let c=new Map;for(let d=0;d<t.edges.length;d++){let u=t.edges[d],f=e[u.from],h=e[u.to];if(f?.length&&h?.length){let p=r?.get(d),m=p&&s?.[d];c.set(d,m?Ln(f,h,m):Nn(f,h,Sn(u),0,0,n,p?Tn(e,p):[]))}}return Xn.set(e,{graph:t,scaleX:a,scaleY:l,deletions:r,routes:s,version:o,curves:c}),c}var fs=(0,$.packAbgr)(119,119,119,217),zn=(0,$.packAbgr)(136,136,136,217),ps=(0,$.packAbgr)(24,24,28,240),hs=2.2,Jn=(0,$.packAbgr)(160,160,160,255),Ze=.18,$t=(0,$.abgrToCssRgba)(Ge(Jn,Ze)),ms=11,gs=1.2,Kn=4,Ot=1e-6,bs=7,xs=3,ys=3,ws=1.5,Ms=.5,Rs=.45,kt=12,Es=1e-6,ce=new Float64Array(64),ye=new Float64Array(64),we=new Float64Array(64);function Ss(e,t,n,r){let o=e.length*kt+1;ce.length<o&&(ce=new Float64Array(o),ye=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];ce[0]=s.x1,ye[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let c=e[i];for(let d=1;d<=kt&&l<r;d++){let u=1-(d/kt)**2,f=1-u,h=f*f*f,p=3*f*f*u,m=3*f*u*u,g=u*u*u,b=h*c.x0+p*c.cx0+m*c.cx1+g*c.x1,w=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(b-ce[a-1],(w-ye[a-1])*n)*t,ce[a]=b,ye[a]=w,we[a]=l,a++}}return a}function jn(e,t){let n=1;for(;n<e-1&&we[n]<t;)n++;let r=we[n-1],o=we[n],s=o>r?Math.min(1,Math.max(0,(t-r)/(o-r))):0;return{x:ce[n-1]+(ce[n]-ce[n-1])*s,y:ye[n-1]+(ye[n]-ye[n-1])*s}}function Ns({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=bs+xs*t,c=Ss(e,r,o,n+i),d=we[c-1],u=Math.min(n,d),f=d<Es?Ls(a,r,o):d-u,h=Math.min(1,f/i);if(h<Ms)return;let p=jn(c,u),m=jn(c,u+i*h),g=p.x-m.x,b=(p.y-m.y)*o,w=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,b)>0?Math.atan2(b,g):Os(w,o,Ts(w,l)),length:i*h,halfWidth:(ys+ws*t)*h,color:s}}function Ls(e,t,n){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*n);return r*t}function Ts(e,t){if(t.length<2)return;let n=t[0],r=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:n,to:t[1]}:{from:r,to:t[t.length-2]}}function Gt(e,t=1){let n=t===1?e:e.map(o=>({x:o.x,y:o.y*t})),r=[];for(let o=0;o<n.length;o++){let s=0,a=0;if(o===0){let l=n[1].x-n[0].x,i=n[1].y-n[0].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===n.length-1){let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i),d=n[o+1].x-n[o].x,u=n[o+1].y-n[o].y,f=Math.hypot(d,u);if(c>0&&f>0){let h=-i/c,p=l/c,m=-u/f,g=d/f;s=(h+m)/2,a=(p+g)/2;let b=h*s+p*a;b>.1&&(s/=b,a/=b)}else c>0?(s=-i/c,a=l/c):f>0&&(s=-u/f,a=d/f)}r.push({nx:s,ny:a})}return r}function Un(e,t,n,r=1){return e.map((o,s)=>({x:o.x+t[s].nx*n,y:o.y+t[s].ny*n/r}))}function mt(e,t,n,r){return(0,$.packAbgr)(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(r*255))}function Be(e,t,n){let r=(1-Math.abs(2*n-1))*t,o=r*(1-Math.abs(e/60%2-1)),s=n-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var As=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],Cs=[[237,137,44],[158,42,122]],_s=[[220,50,50],[50,120,220]];function Bt(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),o=n-r,s=e[r],a=e[r+1];return(0,$.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 Is(e,t){let[n,r,o]=Be(vn(e),vt,Pt);return mt(n,r,o,t)}var $e=300,vs=.7,Ps=.5,eo=[60,65,72],Ft=(0,$.packAbgr)(...eo,255),Wt=`rgb(${eo.join(", ")})`;function Vl(e,t){let n=Hn(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let r=1/0,o=-1/0;for(let s of n.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:n}}function Dt(e){let t=1/0,n=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<t&&(t=a.depth),a.depth>n&&(n=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:t,maxDepth:n,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function qt(e,t,n,r){switch(n){case"random":return Is(e.id,1);case"depth":return Bt(As,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Bt(_s,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,$.packAbgr)(160,160,160,255):e.stable.rank===0?(0,$.packAbgr)(52,152,219,255):Bt(Cs,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,$.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Ft;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=Be(a*$e,vs,Ps);return mt(l,i,c,1)}case"grey":return(0,$.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?t/r.nodeCount*360:0,[s,a,l]=Be(o,.75,.5);return mt(s,a,l,1)}default:return(0,$.packAbgr)(52,152,219,255)}}function Os(e,t=1,n){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*t;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return n?Math.atan2((n.to.y-n.from.y)*t,n.to.x-n.from.x):0}function ks(e,t){let n=!1;for(let r=0;r<e.length-1&&!n;r++){let o=e[r],s=e[r+1];n=Math.max(o.x,s.x)>=t.minX&&Math.min(o.x,s.x)<=t.maxX&&Math.max(o.y,s.y)>=t.minY&&Math.min(o.y,s.y)<=t.maxY}return n}function Vn(e,t){for(let n of e){let r=Math.min(n.x0,n.cx0,n.cx1,n.x1),o=Math.max(n.x0,n.cx0,n.cx1,n.x1),s=Math.min(n.y0,n.cy0,n.cy1,n.y1),a=Math.max(n.y0,n.cy0,n.cy1,n.y1);if(o>=t.minX&&r<=t.maxX&&a>=t.minY&&s<=t.maxY)return!0}return!1}var Qn=new WeakMap;function Gs(e){let t=Qn.get(e);if(!t){let n=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=Be(Pn(s,o.length),vt,Pt);n.push(mt(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}t={pathColorByIndex:n,pathIndexByName:r},Qn.set(e,t)}return t}var Zn=new WeakMap,Bs=new Map;function $s(e){let t=Zn.get(e);if(!t){t=new Map;for(let[n,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=t.get(o);s?s.push(n):t.set(o,[n])}Zn.set(e,t)}return t}function Ql(e){let{nodePositions:t,graph:n,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:d,linearLayout:u,viewportBounds:f,referenceRamp:h,deletions:p,deletionRoutes:m,hiddenEdges:g,version:b=0}=e,w=i==="depth"?Bn(n):0,S=d.scaleX,E=Rn(d),T=Yn(t,n,d,p,b,m),R=[],N=new Map,v=[],H=new Map,W=[],z=new Map,Se={...Dt(n),referenceRamp:h},pe=new Map;if(o==="rainbow")for(let C=0;C<n.nodes.length;C++)pe.set(n.nodes[C].id,C);let Q=n.paths?.length??0,{pathColorByIndex:K,pathIndexByName:Z}=Gs(n),j=C=>K[Z.get(C)??-1]??zn,U=l&&Q>1?$s(n):Bs,Ne=S>(u?1:Rs);for(let C=0;C<n.edges.length;C++){let O=n.edges[C],re=t[O.from],se=t[O.to],ae=T.get(C);if(!re?.length||!se?.length||!ae||g?.has(C))continue;let Le=O.pathIds?.length??0,Xe=p?.get(C)!==void 0,Ye=c?.edgeIndexes.has(C)??!1,he=a/2*(Xe?hs:1),Te=l&&Le>0,me=Xe?ps:fs,J=!c||Ye?me:Ge(me,Ze),ze=r.get(O.to),Ae=(ze?pt(ze,s,i,w):s)/2,Ce=(be,Ie,X,ie)=>{let te=be===0&&Ie===0?ae:_t(ae,be,Ie);if(f&&!Vn(te,f))return;if(Xe)for(let Tt of Mn(te,ms/S))W.push({curves:Tt,thickness:he,color:X});else W.push({curves:te,thickness:he,color:X});let at=Ne&&ie!==void 0?Ns({curves:te,edgeHalfWidth:he,nodeHalfWidth:Ae,scale:S,yToX:E,color:ie,fromSegments:re,toSegments:se}):void 0;at&&v.push(at)},ge=W.length,_e=v.length,ee=c&&Ye&&!Te?c.walks:void 0;if(ee){let be=r.get(O.from),Ie=be?pt(be,s,i,w):s,X=Math.max(Ie/ee.length,Kn),ie=Gt(re,E),{nx:te,ny:at}=(O.fromStrand==="-"?ie[0]:ie.at(-1))??{nx:0,ny:0},Tt=1/Math.max(S,Ot);ee.forEach((At,Jr)=>{if(!At.edgeIndexes.has(C))return;let Ct=(Jr-(ee.length-1)/2)*X*Tt,bn=Ct===0?ae:_t(ae,te*Ct,at*Ct/E);f&&!Vn(bn,f)||W.push({curves:bn,thickness:X/2,color:At.colors.get(O.from)??At.colors.get(O.to)??me})})}else if(!Te)Ce(0,0,J,J);else{let be=En(re,se,Le,d),Ie=Math.floor((Le-1)/2);for(let X=0;X<Le;X++){let ie=be[X],te=j(O.pathIds[X]);Ce(ie.x,ie.y,c&&!c.names.has(O.pathIds[X])?Ge(te,Ze):te,X===Ie?J:void 0)}}let Ke=W.length-ge;Ke>0&&z.set(C,{start:ge,count:Ke});let st=v.length-_e;st>0&&H.set(C,{start:_e,count:st})}for(let[C,O]of Object.entries(t)){let re=r.get(C);if(!re||f&&!ks(O,f))continue;let se=c!==void 0&&!c.nodeIds.has(C),ae=se?Jn:qt(re,pe.get(C)??0,o,Se),Le=se?Ge(ae,Ze):ae,rt=pt(re,s,i,w),Xe=rt/2,Ye=R.length,he=U.get(C),Te=rt/Q,me=O.length>=2,J=c&&!se&&!he?.length?c.walks:void 0;if(me&&J){let Ae=Math.max(rt/J.length,Kn),Ce=Gt(O,E),ge=1/Math.max(S,Ot);J.forEach((_e,ee)=>{let Ke=_e.colors.get(C);if(Ke===void 0)return;let st=(ee-(J.length-1)/2)*Ae*ge;R.push({points:J.length===1?O:Un(O,Ce,st,E),thickness:Ae/2,color:Ke})})}else if(me&&he?.length&&Te>=gs){let Ae=Gt(O,E),Ce=1/Math.max(S,Ot);for(let ge of he){let _e=(ge-(Q-1)/2)*Te*Ce,ee=K[ge]??zn;R.push({points:Un(O,Ae,_e,E),thickness:Te/2,color:se?Ge(ee,Ze):ee})}}else me&&R.push({points:O,thickness:Xe,color:Le});let ze=R.length-Ye;ze>0&&N.set(C,{start:Ye,count:ze})}return{nodeStrokes:R,nodeStrokeRuns:N,arrows:v,arrowRuns:H,edgeCurves:W,edgeCurveRuns:z}}function gt(e){return`hsl(${e}, 70%, 50%)`}function Ht(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*$e}var Fs=30;function to({start:e,bp:t,reversed:n},r){let o=Ht(e,r),s=Ht(e+t,r);if(s-o<1)return[(o+s)/2];let a=Math.ceil((s-o)/Fs);return Array.from({length:a+1},(l,i)=>Ht(e+t*(n?a-i:i)/a,r))}var Xt=Array.from({length:7},(e,t)=>({offset:t/6,color:gt(t/6*$e)})),no=`linear-gradient(to right, ${Xt.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function oc(e){return Ue(e)?oo(e):void 0}function oo(e){return{sample:lt(e.stable.refName),haplotype:xn(e.stable.refName),refName:ct(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Ws(e,t){let n=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of n)o=o&&s.start-o.end<=t?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function Ds(e){return`${e.haplotype??e.sample}\0${e.refName}`}function rc(e,{maxGap:t=1/0}={}){let n=new Map;for(let o of e.nodes)if(Ue(o)){let s=oo(o),a=Ds(s),l=n.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):n.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of n.values()){let s=Ws(o.spans,t);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function qs(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function sc(e,t){return e.flatMap(n=>{let r=qs(t,n);return r===void 0?[]:[{...n,sample:r}]})}function ac(e){return`${e.refName}:${e.start+1}-${e.end}`}function Yt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var ro=Y(it(),1),so=(0,ne.createSvgIcon)((0,ro.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var ao=Y(it(),1),io=(0,ne.createSvgIcon)((0,ao.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 lo=Y(it(),1),zt=(0,ne.createSvgIcon)((0,lo.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 Hs="Linear genome view",Xs="Linear synteny view",Ys="No synteny track in this session aligns these assemblies";function co({label:e,icon:t,entries:n,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=n,i=s?[{label:e,icon:t,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return n.length===0?i:n.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:t,onClick:o(l)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(c=>({label:r(c),onClick:o(c)}))}]}function xc({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:r}){let o=t[0]?.coverage??e.length;return[...co({label:Hs,icon:zt,entries:e,entryLabel:s=>`${s.sample} ${Yt(s)}`,onSelect:s=>()=>{n({location:s,assembly:s.sample})}}),...e.length>=2?co({label:`${Xs} (${o} assemblies)`,icon:so,entries:t,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Ys,onSelect:s=>()=>{r(s.trackId)}}):[]]}function yc({own:e,reference:t,highlight:n,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Yt(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...o&&n?[{label:`Highlight in ${n.assembly}`,icon:io,onClick:()=>{o(n)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:zt,onClick:()=>{r(l)}}))]}function Kt(e){return e.id.endsWith("-")?"-":"+"}function jt(e,t){return t===Kt(e)?e.id:`-${e.id}`}function Ks(e,t){let n=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=r,r+=e[o];let s=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function js(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let r=Ks(t,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let d=r[c],u=t[c];if(d!==void 0&&u!==void 0&&d<=l&&(l<d+u||i&&l===d+u))return{s:c,local:l-d,room:d+u-l}}},s=(l,i)=>{let c=n[l],d=c.at(-1);i.type==="substitution"&&d?.type==="substitution"&&d.pos+d.seq.length===i.pos?d.seq+=i.seq:c.push(i)},a=e.pathStart;for(let l of wn(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let c=o(a),d=c?Math.min(i,c.room):i;c&&s(c.s,{type:"deletion",pos:c.local,length:d}),a+=d,i-=d}}return n}function fo(e,t,n){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of t){let a=s.path.map(d=>r.get(d.name)),l=a.flatMap((d,u)=>d?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let d=js(s,a.map(h=>h?.length)),u=l.map(h=>jt(a[h],s.path[h].strand)),f=a[c].length;o.push({id:n+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:l.map((h,p)=>({nodeName:u[p],mismatches:d[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Us=["#6baed6","#4292c6","#2171b5","#08519c"],Vs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function po(e){let t=e.is_reverse?Vs:Us;return t[e.id%t.length]}function bt(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function Qs(e,t,n,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=t.get(l);if(i){o.push(i);for(let c of n.get(l)??[]){let d=t.get(c);d&&(d.stable.rank===0?s.push(d):r.has(c)||(r.add(c),a.push(c)))}}}return{members:o,anchors:s}}function Zs(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=n[0],o=n.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Js(e,t,n){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of n.get(t.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of n.get(a)??[])if(r.has(i)){let c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function ea(e,t,n){let r=Js(e,t,n),o=[...e].sort((i,c)=>r.get(i.id)-r.get(c.id)),s=new Map(o.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of o.entries()){let d=0;for(let u of n.get(c.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,l.get(u)+f.length))}l.set(c.id,d)}return{offsets:l,ordered:o}}function mo(e){let t=new Map(e.nodes.filter(Ue).map(s=>[s.id,s])),n=Qe(e),r=new Set,o=[];for(let s of t.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Qs(s.id,t,n,r),i=Zs(l);if(i){let{offsets:c,ordered:d}=ea(a,i.entry,n);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>c.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,c.get(f.id)+f.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var ta=1,na=.015;function xt({graph:e,span:t,rowY:n,positions:r}){let o=t*na,s=mo(e),a=new Map(e.nodes.map(d=>[d.id,d])),l=[];for(let d of s){let u=d.refSpan-d.pathLength;u>=ta&&l.push({nodeIds:d.nodeIds,bp:u});let f=Math.max(d.refSpan,o),h=d.pathLength>0?f/d.pathLength:0;d.nodeIds.forEach((p,m)=>{let g=a.get(p);if(g){let b=d.nodeOffsets[m],w=f/d.nodeIds.length,S=T=>d.start+T*h,E=n(g);r[p]=h?[{x:S(b),y:E},{x:S(b+g.length),y:E}]:[{x:d.start+m*w,y:E},{x:d.start+(m+1)*w,y:E}]}})}let i=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=n(h);r[f]=[{x:u,y:p},{x:u+o,y:p}],c.push(f)}}}return l}function oa(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,r)=>n-r).map((n,r)=>[n,r]))}function go(e,t){let n=ve(e);if(n.length===0)return;let r=dt(n,t),o=oa(e),s=Pe(n),a=xt({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 ra=12,Ut=20;function bo(e){return 10+8*Math.log2(1+e.length)}function ue(e,t){return e<t?-1:e>t?1:0}function yo(e,t){return ue(e.at,t.at)||ue(e.side,t.side)||ue(e.hops,t.hops)}var xo={at:1/0,side:0,hops:0};function sa(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=la(e);return e.nodes.map(r=>r.id).sort((r,o)=>yo(n.get(r)??xo,n.get(o)??xo)||ue(t.get(r).name,t.get(o).name)||ue(r,o))}function aa(e,t){let n=new Set(e.nodes.map(d=>d.id)),r=new Map(t.map(d=>[d.id,d.stable.start])),o=new Map,s=new Map;t.forEach((d,u)=>{s.set(d.id,t[u-1]?.id),o.set(d.id,t[u+1]?.id)});let a=t[0]?.id,l=(d,u)=>{let f=o.get(d);o.set(d,u),s.set(u,d),o.set(u,f),f!==void 0&&s.set(f,u)},i=(d,u)=>{let f=s.get(d);f===void 0?(a=u,s.set(u,void 0),o.set(u,d),s.set(d,u)):l(f,u)};for(let d of e.paths??[]){let u=0,f=0,h;for(let b of d.nodeIds){let w=r.get(b);w!==void 0&&(h!==void 0&&w!==h&&(w>h?u++:f++),h=w)}let p=f>u?[...d.nodeIds].reverse():d.nodeIds,m,g=new Set;for(let b of p)if(o.has(b)){if(m===void 0)for(let w of g)i(b,w);m=b}else n.has(b)&&(m===void 0?g.add(b):(l(m,b),m=b))}let c=[];for(let d=a;d!==void 0;d=o.get(d))c.push(d);return c}function ia(e,t){let n=[...t.entries()].sort(([a,l],[i,c])=>yo(l,c)||ue(a,i)).map(([a])=>a),r=n.length;for(let a of n){let l=t.get(a);for(let i of e.get(a)??[])t.has(i)||(t.set(i,{at:l.at,side:1,hops:l.hops+1}),n.push(i))}let o=new Set(n.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=t.get(a),i=[a];s.add(a);let c=!0;for(let d of i){let{hops:u}=t.get(d),f=!0,h=!1;for(let p of e.get(d)??[]){let m=t.get(p);m.at===l&&o.has(p)?(f&&=m.hops<=u,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!f||h}if(c)for(let d of i){let u=t.get(d);t.set(d,{...u,side:-1,hops:-u.hops})}}}function la(e){let t=new Set(e.nodes.map(s=>s.id)),n=new Map;for(let s of e.edges)!t.has(s.from)||!t.has(s.to)||((n.get(s.from)??n.set(s.from,[]).get(s.from)).push(s.to),(n.get(s.to)??n.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(k).sort((s,a)=>ue(s.stable.start,a.stable.start)||ue(s.name,a.name)),o=new Map;return aa(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),ia(n,o),o}function ca(e){let t=new Map(e.nodes.map(u=>[u.id,u])),n=sa(e),r=new Map(n.map((u,f)=>[u,f])),o=u=>k(t.get(u)),s=new Map(n.map(u=>[u,[]])),a=new Map(n.map(u=>[u,[]])),l=(u,f)=>{s.get(f).push(u),a.get(u).push(f)};for(let u of e.edges)u.from===u.to||!r.has(u.from)||!r.has(u.to)||(r.get(u.from)<r.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=n.filter(o);for(let u=1;u<i.length;u++)l(i[u-1],i[u]);let c=new Map;for(let u of n){let f=0;for(let h of s.get(u))f=Math.max(f,c.get(h)+1);c.set(u,f)}for(let u=n.length-1;u>=0;u--){let f=n[u],h=a.get(f);if(o(f)||h.length===0)continue;let p=1/0;for(let b of h)p=Math.min(p,c.get(b));let m=c.get(f),g=Math.max(m,p-1);c.set(f,Math.floor((m+g)/2))}let d=[];for(let u of n)(d[c.get(u)]??=[]).push(u);return{layers:d,layerOf:c,preds:s}}function wo(e){if(!e.nodes.some(k))return;let t=new Map(e.nodes.map(u=>[u.id,u])),n=u=>k(t.get(u)),{layers:r,layerOf:o,preds:s}=ca(e),a=r.map(u=>{let f=0;for(let h of u)f=Math.max(f,bo(t.get(h)));return f}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+ra;let c=new Map;for(let u of r){let f=[];for(let p of u){if(n(p)){c.set(p,0);continue}let m=s.get(p).filter(b=>c.has(b)),g=0;for(let b of m)g+=c.get(b)/m.length;f.push({id:p,ideal:g===0?Ut:g})}f.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of f){let g=Math.round(m/Ut);g===0&&(g=m>=0?1:-1);for(let b=1;h.has(g);b++)h.has(g+b)?h.has(g-b)||(g-=b):g+=b;h.add(g),c.set(p,g*Ut)}}let d={};for(let u of e.nodes){let f=o.get(u.id),h=bo(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 ua(e,t){let n=new Map;for(let o of e.nodes)if(ut(o)){let{sample:s}=bt(o.stable.refName);n.set(s,(n.get(s)??0)+o.length)}let r=new Map(t.map((o,s)=>[o,s]));return[...n.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||n.get(s)-n.get(o)||o.localeCompare(s))}function Mo(e,t,n=[]){let r=ve(e),o=ua(e,n);if(r.length===0||o.length===0)return;let s=dt(r,t),a=new Map(o.map((f,h)=>[f,h+1])),l=Pe(r),i=o.length+1,c=xt({graph:e,span:s,rowY:f=>{let h=f.stable;return((h?a.get(bt(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:bt(r[0].stable.refName).sample,y:0},...o.map(f=>({label:f,y:a.get(f)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function Vt(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var tt=!1,Ro=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function $o(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(t=>Ro[t.id%Ro.length]),trackAlpha:e.trackAlpha??(()=>1)}}var _=$o({}),tn=null,x=[],y=[],M=[],A=new Map,De=[],L=[],Me=[],on=[],rn=[],V=-1,G=Vt(),nn={minX:0,maxX:0,minY:0,maxY:0},Je,yt=new Map;function Fo(e,t,n=[],r={}){if(_=$o(r),tn=r.bed??null,G=Vt(),Me=[],on=[],rn=[],De=[],nn={minX:0,maxX:0,minY:0,maxY:0},Je=void 0,yt=new Map,e.length===0||t.length===0)return;let o=Qt(e);x=[],o.forEach((i,c)=>{x[c+1]=i}),y=Qt(t);let s=n.length>0;M=Qt(Qa(n));for(let i=y.length-1;i>=0;i-=1){let c=y[i];if(c.type===void 0&&(c.type="haplotype"),c.hidden===!0){y.splice(i,1);continue}c.indexOfFirstBase!==void 0&&(Je=c.name)}if(y.length===0)return;fa(0),A=No(),Fe(y),_.showReads&&M.length>0&&Fe(M),Bo(),_.mergeNodesFlag&&(Lo(),Jt(),_.showReads&&M.length>0&&Zt(),Va(),A=No(),Bo(),Fe(y),_.showReads&&M.length>0&&Fe(M)),Lo(),Pa(),tt&&console.log(`${x.length} nodes.`),Jt(),V=Ao(),Oa(),Jt(),V=Ao();let a=_.showReads&&_.coarsenedReadView&&!s;if(a){let i=Je===void 0?-1:y.findIndex(u=>u.name===Je),c=i===-1?0:i,d=y.filter((u,f)=>f!==c);if(d.length>0){let u=Po(d,"haplotype");u.length>0&&(y=[y[c]],M=u)}}Xa(),$a(),_.showExonsFlag&&tn!==null&&Ha();let l=_.showReads&&_.coarsenedReadView&&M.length>0&&!a;return _.showReads&&M.length>0?(pa(),Zt(),Fe(M),l&&(M=Po(M,"read"),Zt(),Fe(M)),ma(),y=y.concat(M)):x.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),Ga(),Ka(),tt&&(console.log("Tracks:"),console.log(y),console.log("Nodes:"),console.log(x),console.log("Lane assignment:"),console.log(Me)),Ta(),{nodes:x,tracks:y,reads:M,nodeMap:A,shapes:G,bounds:nn,maxOrder:V,trackForRuler:Je,coarsenedEdgeMeta:yt}}function We(e,t="plain"){return _.trackColor(e,t)}function da(e){return _.trackAlpha(e)}function Qt(e){return structuredClone(e)}function q(e){let t=String(e);return t.length>=1&&t.startsWith("-")}function P(e){return q(e)?String(e).substring(1):e}function de(e){return q(e)?e:`-${e}`}function Wo(e){return q(e)?P(e):de(e)}function wt(e){return(e||1/e)>=0}function fa(e){let t=new Set,n=y[e].sequence;for(let r=0;r<n.length;r+=1){let o=n[r];if(q(o)){let s=P(o),a=n.indexOf(s);(a===-1||a>r)&&t.add(s)}}for(let r of y){n=r.sequence;for(let o=0;o<n.length;o+=1){let s=n[o];q(s)?t.has(P(s))&&(n[o]=P(s)):t.has(s)&&(n[o]=de(s))}}x.forEach(r=>{r&&t.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function pa(){De=[];for(let t=0;t<=V;t+=1)De[t]=[];let e=new Map;x.forEach(t=>{t.y!==void 0&&Eo(e,t.order,t.y+t.contentHeight)}),y.forEach(t=>{t.type==="haplotype"&&t.path.forEach(n=>{Eo(e,n.order,(n.y??0)+t.width)})}),x.forEach((t,n)=>{t.order>=0&&t.y===void 0&&(t.y=(e.get(t.order)??0)+25,t.contentHeight=0,De[t.order].push(n))})}function Eo(e,t,n){let r=e.get(t);r===void 0?e.set(t,n):e.set(t,Math.max(r,n))}var Mt=7;function ha(){x.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),M.forEach((e,t)=>{if((e.width===void 0||e.width===0)&&(e.width=Mt),e.path.length===1){let n=e.path[0].node;n!==null&&x[n].internalReads.push(t)}else e.path.forEach((n,r)=>{if(r===0){let o=e.path[0].node;o!==null&&x[o].outgoingReads.push([t,r])}else{let o=n.node;o!==null&&x[o].incomingReads.push([t,r])}})})}function ma(){Ea(),ha();let e=x.slice();e.sort(Rt);let t=new Map;for(let a=0;a<M.length;a++){let l=M[a].sourceTrackID,i=t.get(l);i===void 0?t.set(l,[a]):i.push(a)}let n=Array.from(t.keys()).sort((a,l)=>a-l),r=n.length>1?Mt:0;e.forEach(a=>{if(a)for(let l of n)ga(t.get(l),a,r)});let o=Ra(),s=[];M.forEach((a,l)=>{let i=a.path.length,c=new Array(i),d;for(let h=0;h<i;h++){h===0?c[h]=void 0:c[h]=d??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(d=p)}let u=new Array(i),f;for(let h=i-1;h>=0;h--){h===i-1?u[h]=void 0:u[h]=f??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(f=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=c[p],g=u[p],b=!!(g&&m&&g.isForward!==void 0&&m.isForward!==void 0&&(m.order>g.order||g.order===m.order&&g.isForward===m.isForward));h.betweenCycleReverseTraversal=b,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(xa),s.forEach(a=>{let l=M[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),tt&&(console.log("Reads:"),console.log(M))}function ga(e,t,n){let r=new Set(e),o=t.incomingReads.filter(([p])=>r.has(p)),s=t.outgoingReads.filter(([p])=>r.has(p)),a=t.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(n=0);let l=t.y+t.contentHeight+n*2,i=o.map(p=>{let[m,g]=p,b=M[m].path,w=g+1,S;for(let E=1;E<=g;E++){let T=b[g-E]?.y;if(T!==void 0){w=E,S=T;break}}return{entry:p,decisionStep:w,y:S}});i.sort(ba),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,So(d,m,p[1],c,t),c+=m.width});let u=c;s.sort(ya);let f=new Map;c=l,s.forEach(p=>{let m=M[p[0]],g=m.firstNodeOffset??0;m.path[p[1]].y=c,f.set(c,g);let b=d.get(c);b===void 0||b+1<=g?(c+=m.width,u=Math.max(u,c)):(d.set(c,0),o.forEach(w=>{let S=M[w[0]],E=S.path[w[1]];E.y!==void 0&&E.y>=c&&(E.y+=m.width,So(d,S,w[1],E.y,t))}),c+=m.width,u+=m.width)}),a.sort(Ma),a.forEach(p=>{let m=M[p],g=m.firstNodeOffset??0,b=m.finalNodeCoverLength??0;for(c=l;g<(d.get(c)??-1/0)+2||b>(f.get(c)??1/0)-3;)c+=m.width||Mt;m.path[0].y=c,d.set(c,b),u=Math.max(u,c)});let h=u-t.y-t.contentHeight;t.contentHeight+=h,qa(t,h)}function ba(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function So(e,t,n,r,o){n===t.path.length-1?e.set(r,t.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function xa(e,t){let n=M[e.readIndex],r=M[t.readIndex],o=n.path[e.pathIndex],s=r.path[t.pathIndex];if(o.order!==s.order)return o.order-s.order;if(n.sourceTrackID!==r.sourceTrackID)return n.sourceTrackID-r.sourceTrackID;if(e.previousNode&&t.previousNode){let i=x[e.previousNode],c=x[t.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=t.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function ya([e,t],[n,r]){let o=M[e],s=M[n],a,l,i=o.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let d=o.path[t]?.node,u=s.path[r]?.node,f=d!=null?x[d]:null,h=u!=null?x[u]:null;for(;f!=null&&h!=null&&f===h;){if(t<o.path.length-1){for(t+=1;o.path[t]?.node===null;)t+=1;let m=o.path[t]?.node;f=m!=null?x[m]:null}else f=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?x[m]:null}else h=null}if(f!=null)return h!=null?Rt(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 wa(e,t){if(e.path===void 0||t.path===void 0)return(e.path===void 0?0:1)-(t.path===void 0?0:1);let n=e.path,r=t.path,o=0,s=0;for(;o<n.length&&s<r.length;){let a=n[o],l=r[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?o+=1:(i>c||(o+=1),s+=1)}return 0}function Ma(e,t){let n=M[e],r=M[t],o=n.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=n.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function Ra(){let e=[];for(let t=0;t<=V;t+=1)e.push(0);return x.forEach(t=>{t.y!==void 0&&(e[t.order]=Math.max(e[t.order],t.y+t.contentHeight+20))}),y.forEach(t=>{t.path.forEach(n=>{e[n.order]=Math.max(e[n.order],(n.y??0)+t.width)})}),e}function Ea(){M.forEach(e=>{let t=Math.abs(e.indexSequence[0]),n=wt(e.indexSequence[0]),r=x[t],o,s;e.path=[],e.path.push({order:r.order,isForward:n,node:t});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=n,t=Math.abs(e.indexSequence[a]),n=wt(e.indexSequence[a]),r=x[t],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});n?e.path.push({order:r.order,isForward:!0,node:t}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:t}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});n?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:t})):e.path.push({order:r.order,isForward:!1,node:t})}else n!==s?e.path.push({order:r.order,isForward:n,node:t}):(e.path.push({order:r.order,isForward:!n,node:null}),e.path.push({order:r.order,isForward:n,node:t}))})}function Zt(){M.forEach(e=>{let t=0;for(;t<e.sequence.length&&e.sequence[t].startsWith("-");)t+=1;if(t===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=P(e.sequence[a]);let n=e.sequenceNew??[];n.reverse(),e.sequenceNew=n;for(let a of n)a.nodeName=P(a.nodeName),Sa(a.mismatches,oe(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function Sa(e,t){e.forEach(n=>{n.type==="insertion"?n.pos=t-n.pos:n.type==="deletion"?n.pos=t-n.pos-(n.length??0):n.type==="substitution"&&(n.pos=t-n.pos-(n.seq?.length??0)),n.seq!==void 0&&(n.seq=Do(n.seq).split("").reverse().join(""))})}var Na={A:"T",T:"A",C:"G",G:"C"};function Do(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Na[e.charAt(n)]??"N";return t}function Fe(e){e.forEach(t=>{t.indexSequence=[],t.sequence.forEach(n=>{let r=n,o=A.get(P(r)),s=x[o]?.switched??!1;s&&(r=Wo(r));let a=A.get(P(r));if(a===0)throw new Error("Node "+P(r)+" has prohibited index 0");q(r)!==s?t.indexSequence.push(-a):t.indexSequence.push(a)})})}var La=20;function Ta(){let e={minX:99,maxX:-99,minY:99,maxY:-99};x.forEach(t=>{t&&(t.x!==void 0&&(e.minX=Math.min(e.minX,t.x),e.maxX=Math.max(e.maxX,t.x+La+t.pixelWidth)),t.y!==void 0&&(e.minY=Math.min(e.minY,t.y-10),e.maxY=Math.max(e.maxY,t.y+t.contentHeight+10)))}),y.forEach(t=>{t.path.forEach(n=>{let r=n.y??0;e.maxY=Math.max(e.maxY,r+t.width),e.minY=Math.min(e.minY,r)})}),nn=e}function oe(e){let t=A.get(P(e)),n=t===void 0?void 0:x[t];if(n===void 0)throw new Error(`Unknown node ${e}`);return n}function No(){return A=new Map,x.forEach((e,t)=>{e&&A.set(e.name,t)}),A}function Lo(){let e=x.map(()=>new Set),t=x.map(()=>new Set),n=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),t[a].add(s)}};y.forEach(n),_.showReads&&M.length>0&&M.forEach(n),x.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(t[o]))})}function To(e){let t=0,n=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){L[s]===void 0&&(L[s]=n);let a=L[s];a<r&&(r=a),t=a,n=a-1}else{L[s]===void 0&&(L[s]=t);let a=L[s];t=a+1,n=a}}),r<0&&sn(-r)}function Aa(e){let t=0,n=0;for(;t<e.length&&L[Math.abs(e[t])]===void 0;)t+=1;if(t>=e.length)return null;let r=e[t],o,s;r>=0?(o=L[r]-1,s=-1):(o=L[-r]+1,s=1);for(let a=t-1;a>=0;a-=1){let l=Math.abs(e[a]);L[l]===void 0&&(L[l]=o,n=Math.min(n,o),o+=s)}return n<0&&sn(-n),t}var Ca=-1;function _a(e){let t=[];for(let n of e)t.push(n??Ca);return t}function Jt(){let e,t,n,r,o=0,s=_.showReads&&M.length>0?y.concat(M):y,a={stamp:new Int32Array(x.length),generation:0};L=new Array(x.length).fill(void 0),x.forEach(i=>{i&&(i.order=void 0)}),To(y[0].indexSequence);for(let i=1;i<s.length;i+=1){if(tt&&console.log(`generating order for track ${i+1}`),n=Aa(s[i].indexSequence),n===null){s[i].type==="haplotype"?To(s[i].indexSequence):(s.splice(i,1),M.splice(i-y.length,1),i-=1);continue}for(e=va(s[i].indexSequence);n<e.length;){for(r=n,n+=1;n<e.length&&L[e[n]]===void 0;)n+=1;if(n<e.length){t=L[e[r]]+1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,t+=1;if(L[e[n]]>L[e[r]])L[e[n]]<t&&Co(e[n],e[n-1],t);else if(s[i].indexSequence[n]>=0&&!Ia(e[n],e[r],a))Co(e[n],e[n-1],t);else if(s[i].indexSequence[r]<0||x[e[r+1]].degree<2&&L[e[n]]<L[e[r]]){t=L[e[r]]-1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,o=Math.min(o,t),t-=1}}else if(s[i].indexSequence[r]>=0){t=L[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,t+=1)}}else{t=L[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,o=Math.min(o,t),t-=1)}}}}o<0&&sn(-o);let l=_a(L);L=l,l.forEach((i,c)=>{let d=x[c];d!==void 0&&(d.order=i)})}function Ia(e,t,n){n.generation+=1;let{stamp:r,generation:o}=n,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===t)return!0;for(let l of x[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function Ao(){let e=-1;return L.forEach(t=>{t!==void 0&&t>e&&(e=t)}),e}function va(e){return e.map(t=>Math.abs(t))}function sn(e){L.forEach((t,n)=>{t!==void 0&&(L[n]=t+e)})}function Co(e,t,n){let r=new Map,o=[[e,n]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=L[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),x[a].successors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}),a!==e&&x[a].predecessors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}))}r.forEach((a,l)=>{L[l]=a})}function Pa(){x.forEach(e=>{e.tracks=[]}),y.forEach(e=>{e.indexSequence.forEach(t=>{x[Math.abs(t)].tracks.push(e.id)})}),x.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function Oa(){let e=y[0],t=y.slice(1,y.length);if(_.showReads&&M.length>0&&(t=t.concat(M)),ka(t,e),_.showReads&&M.length>0){for(let n=0;n<M.length;n++)if(M[n]!==t[n+y.length-1])throw new Error("Read inequality")}}function ka(e,t){let n=new Map,r=t?new Set(t.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=P(s[a]),i=oe(l);if(r&&!r.has(l)){let c=a>0?oe(s[a-1]).order:void 0,d=a<s.length-1?oe(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(d===void 0||i.order<d)&&_o(n,l,q(s[a])?1:-1),(c===void 0||c>i.order)&&(d===void 0||i.order>d)&&_o(n,l,q(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=n.get(P(s));l!==void 0&&l>0&&(o.sequence[a]=Wo(s),o.indexSequence[a]=-o.indexSequence[a])});n.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=Do(a.seq),a.switched=!0}})}function _o(e,t,n){e.set(t,(e.get(t)??0)+n)}function Ga(){let e=0,t=20,n=-1,r=x.slice();r.sort(Rt);let o=Ba();r.forEach(s=>{s.order>=0&&(s.order>n&&(n=s.order,e=t+10*o[s.order]),s.x=e,t=Math.max(t,e+40+s.pixelWidth))})}function Ba(){let e=[],t=[],n=[],r=[];for(let o=0;o<=V;o+=1)e.push(0),t.push(0),n.push(0);y.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:t[a.order]=t[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));n[a.order]=Math.max(i/17.5,n[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=V;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,t[o-1]-1),n[o]));return r}function $a(){let e,t,n,r,o,s,a=[],l=[];for(let i=0;i<=V;i+=1){Me[i]=[],l[i]=new Map,a[i]=[];for(let c=0;c<y.length;c+=1)a[i][c]=null}y.forEach((i,c)=>{t=Math.abs(i.indexSequence[0]),n=wt(i.indexSequence[0]),r=x[t],i.path=[],i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,0,a,l),e=1;for(let d=1;d<i.sequence.length;d+=1)if(o=r,s=n,t=Math.abs(i.indexSequence[d]),n=wt(i.indexSequence[d]),r=x[t],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order+1;u<r.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order-1;u>r.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else n!==s?(i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!n,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1)});for(let i=0;i<=V;i+=1)Wa(Me[i],i)}function D(e,t,n,r,o,s){let a={trackID:n,segmentID:r,compareToFromSame:o[e][n]??null},l=t===null?void 0:s[e].get(t);if(l===void 0){let i={type:"single",node:t,tracks:[a]};Me[e].push(i),t!==null&&s[e].set(t,i)}else l.type="multiple",l.tracks.push(a);o[e][n]=a}function Fa(e,t){let n;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(y[o.trackID].path[o.segmentID-1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<y[o.trackID].path.length-1&&y[o.trackID].path[o.segmentID+1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID+1].y;else{for(n=o.segmentID-1;n>=0&&y[o.trackID].path[n].order!==t-1;)n-=1;n<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=y[o.trackID].path[n].lane??void 0,o.idealY=y[o.trackID].path[n].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Wa(e,t){let n=0,r=new Set,o=20,s=!1,a=-1;Fa(e,t),e.sort(vo),e.forEach(l=>{l.node!==null?(x[l.node].topLane=n,s&&(o-=10),x[l.node].y=o,x[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(vo),l.tracks.forEach(i=>{i.lane=n,i.trackID===a&&l.node===null&&s&&(o+=10),y[i.trackID].path[i.segmentID].lane=n,y[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),n+=1,o+=y[i.trackID].width,l.node!==null&&(x[l.node].contentHeight+=y[i.trackID].width),a=i.trackID}),o+=25}),Da(e,r)}function Da(e,t){let n=0,r=Number.MAX_SAFE_INTEGER;t.forEach(o=>{Io(e,o)<r&&(r=Io(e,o),n=o)}),e.forEach(o=>{o.node!==null&&(x[o.node].y+=n),o.tracks.forEach(s=>{let a=y[s.trackID].path[s.segmentID];a.y=a.y+n})})}function qa(e,t){e.order<0||Me[e.order]===void 0||(Me[e.order].forEach(n=>{if(n.node!==null){let r=x[n.node];r!==e&&r.y>e.y&&(r.y+=t,n.tracks.forEach(o=>{let s=y[o.trackID].path[o.segmentID];s.y=s.y+t}))}else n.tracks.forEach(r=>{let o=y[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+t)})}),De[e.order].length>0&&De[e.order].forEach(n=>{x[n]!==e&&x[n].y>e.y&&(x[n].y+=t)}))}function Io(e,t){let n=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&y[o.trackID].type!=="read"&&(n+=Math.abs(o.idealY-t-y[o.trackID].path[o.segmentID].y)*y[o.trackID].width)})}),n}function vo(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function Rt(e,t){if(!e)return t?-1:0;if(!t)return 1;if(e.order!==void 0){if(t.order!==void 0){if(e.order<t.order)return-1;if(e.order>t.order)return 1;if(e.y!==void 0&&t.y!==void 0){if(e.y<t.y)return-1;if(e.y>t.y)return 1}return 0}return-1}return t.order!==void 0?1:0}function Ha(){let e,t,n={};tn.forEach(r=>{let o=0;for(;o<y.length&&y[o].name!==r.track;)o+=1;o<y.length&&(e=0,y[o].path.forEach(s=>{s.node!==null&&(n={},t=e+x[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(n.start=0),e<r.start&&t>=r.start&&(n.start=r.start-e),t<=r.end&&t>=r.start&&(n.end=t-e,t<r.end&&(n.continue=!0)),t>r.end&&e<=r.end&&(n.end=r.end-e),n.start!==void 0&&(n.type=r.type,n.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(n)),e=t+1)}))})}function Xa(){let e=!0,t=4,n=_.trackWidth;y.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*t):(r.width=n,r.type!==void 0&&r.type==="read"&&(r.width=t)),r.width!==t&&(e=!1)}),e&&y.forEach(r=>{r.freq!==void 0&&(r.width=n)})}function Ya(e){let t=e.path[0],n=x[t.node],r=e.firstNodeOffset??0;return an(n,t.isForward?r:n.sequenceLength-r)}function za(e){let t=e.path[e.path.length-1],n=x[t.node],r=e.finalNodeCoverLength??0;return an(n,t.isForward?r:n.sequenceLength-r)}function qo(e,t){return t>e.sequenceLength?null:an(e,t)}function an(e,t){let[n,r]=Ua(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(r-n)}function Ka(){let e,t,n,r,o,s,a,l,i;for(let u=0;u<=V;u+=1)on.push(0),rn.push(0);let c=[],d=[];x.forEach(u=>{u.x!==void 0&&(c[u.order]=u.x,d[u.order]===void 0?d[u.order]=u.x+u.pixelWidth:d[u.order]=Math.max(d[u.order],u.x+u.pixelWidth))}),y.sort(wa),y.forEach(u=>{a="plain",o=We(u,a),s=da(u);let f=a,h=()=>(f!==a&&(f=a,o=We(u,a)),o);n=u.path[0].y,u.type!=="read"?u.sequence[0].startsWith("-")?e=d[u.path[0].order]+20:e=c[u.path[0].order]-20:e=Ya(u);for(let p=0;p<u.path.length;p+=1)u.path[p].y===n?u.path[p].features!==void 0&&(i=p>0&&u.path[p-1].order===u.path[p].order,l=Oo(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart):(u.path[p-1].isForward?t=d[u.path[p-1].order]:t=c[u.path[p-1].order],t!==e&&(o=h(),G.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})),u.path[p].order-1===u.path[p-1].order?(e=t,t=c[u.path[p].order],r=u.path[p].y,o=h(),G.curves.push({xStart:e,yStart:n,xEnd:t+1,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p].order+1===u.path[p-1].order?(e=t,t=d[u.path[p].order],r=u.path[p].y,o=h(),G.curves.push({xStart:e+1,yStart:n,xEnd:t,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p-1].isForward?(r=u.path[p].y,Go(1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=d[u.path[p].order],n=u.path[p].y):(r=u.path[p].y,Go(-1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=c[u.path[p].order],n=u.path[p].y),u.path[p].features!==void 0&&(i=u.path[p-1].order===u.path[p].order,l=Oo(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart));u.type!=="read"?u.path[u.path.length-1].isForward?t=d[u.path[u.path.length-1].order]+20:t=c[u.path[u.path.length-1].order]-20:t=za(u),G.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})})}var ja=1e9;function Po(e,t){yt=new Map;let n=new Map,r=_.ignoreStrand;for(let f of e){let h=f.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],g=h[p+1],b=Math.abs(m),w=Math.abs(g),S=x[b],E=x[w];if(!S||!E)continue;let T;if(r){let N=`${m}>${g}`,v=`${-g}>${-m}`;T=N<v?N:v}else T=`${m}>${g}`;let R=n.get(T);R===void 0?n.set(T,{sSigned:m,dSigned:g,sName:m<0?`-${S.name}`:S.name,dName:g<0?`-${E.name}`:E.name,count:1,sourceTrackID:f.sourceTrackID}):R.count+=1}}let o=0;for(let f of n.values())f.count>o&&(o=f.count);let s=Mt,a=60,l=f=>o<=1?s:s+(a-s)*Math.sqrt(f/o),i=[],c=0;for(let f of n.values()){let h=ja+c,p=`${f.count.toLocaleString()} ${t}${f.count===1?"":"s"}: Node ${f.sName} \u2192 Node ${f.dName}`;yt.set(h,{count:f.count,label:p});let m=x[Math.abs(f.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:f.sourceTrackID,type:"read",name:p,sequence:[f.sName,f.dName],indexSequence:[],path:[],width:l(f.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:f.sName,mismatches:[]},{nodeName:f.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:f.count}),c+=1}let d="?",u=0;for(let f of x){if(!f)continue;let h=f.contentHeight;h>u&&(u=h,d=f.name)}return tt&&console.log(`[coarsened] ${t}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${d}(${u.toFixed(1)})`),i}function Oo(e,t,n,r,o,s,a,l,i){let c=r,d,u,f,h;t-=8,n+=8;let p=x[e.node].sequenceLength;return e.features.sort((m,g)=>m.start-g.start),e.features.forEach(m=>{c!==m.type&&(d=We(o,c),e.isForward?(f=t+Math.round(m.start*(n-t+1)/p),i&&f<t+8&&(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,u=We(o,m.type),G.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&&G.featureRectangles.push({xStart:s,yStart:a,xEnd:f-1,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(f=n-Math.round(m.start*(n-t+1)/p),i&&f>n-8&&(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,u=We(o,m.type),G.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&&G.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=We(o,c),e.isForward?(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,G.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,G.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 ko=7;function Go(e,t,n,r,o,s,a,l,i,c){let d=e===1?rn:on,u=10*d[l],f=t+e*(u+5),h=ko,p=Math.min(ko,o),m=Math.min(n,r),g=Math.max(n,r),b=e===1?t:f-1,w=e===1?f:t,S=N=>{G.verticalRectangles.push({xStart:b,yStart:N,xEnd:w,yEnd:N+o-1,color:s,id:a,name:c,type:i})};S(n),G.verticalRectangles.push({xStart:e===1?f+h:f-h-p,yStart:m+o+h-1,xEnd:e===1?f+h+p-1:f-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),S(r);let E=f+e*h,T=f+e*(h+p),R=`M ${f} ${g}`;R+=` Q ${E} ${g} ${E} ${g-h}`,R+=` H ${T}`,R+=` Q ${T} ${g+o} ${f} ${g+o}`,R+=" Z ",G.corners.push({path:R,color:s,id:a,type:i}),R=`M ${f} ${m}`,R+=` Q ${T} ${m} ${T} ${m+o+h}`,R+=` H ${E}`,R+=` Q ${E} ${m+o} ${f} ${m+o}`,R+=" Z ",G.corners.push({path:R,color:s,id:a,type:i}),d[l]+=1}function Ua(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function Bo(){switch(x.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),_.nodeWidthOption){case"compressed":x.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":x.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":x.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=_.charWidth;x.forEach(t=>{t.width=t.sequenceLength;let n=t.seq?.length??1;t.pixelWidth=Math.round(e*n)});break}default:throw new Error(`${_.nodeWidthOption} not implemented`)}}function Va(){let e,t,n=Array.from(x,()=>new Set),r=Array.from(x,()=>new Set),o;_.showReads&&M.length>0?o=y.concat(M):o=y,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)q(l.sequence[i])?(e=P(l.sequence[i]),i>0?(t=l.sequence[i-1],q(t)?r[A.get(e)].add(P(t)):(r[A.get(e)].add(t),r[A.get(e)].add(de(t)))):l.type==="haplotype"&&r[A.get(e)].add("None"),i<l.sequence.length-1?(t=l.sequence[i+1],q(t)?n[A.get(e)].add(P(t)):(n[A.get(e)].add(t),n[A.get(e)].add(de(t)))):l.type==="haplotype"&&n[A.get(e)].add("None")):(i>0?(e=l.sequence[i-1],n[A.get(l.sequence[i])].add(e),q(e)&&n[A.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&n[A.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[A.get(l.sequence[i])].add(e),q(e)&&r[A.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&r[A.get(l.sequence[i])].add("None"))});let s=n.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(_.showReads&&M.length>0){let l=x.slice();l.sort(Rt);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=et(A.get(f.name),s,a);if(h){let p=d(h)+oe(h).sequenceLength;i.set(f.name,p),i.set(de(f.name),p),c.set(f.name,u(h)),c.set(de(f.name),u(h))}else i.set(f.name,0),i.set(de(f.name),0),c.set(f.name,f.name),c.set(de(f.name),f.name)}),M.forEach(f=>{let h=f.sequenceNew??[];f.firstNodeOffset=(f.firstNodeOffset??0)+d(f.sequence[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+d(f.sequence[f.sequence.length-1]);for(let p=f.sequence.length-1;p>=0;p-=1){let m=P(f.sequence[p]),g=et(A.get(m),s,a);if(g&&en(A.get(g),s,a))if(p>0){f.sequence.splice(p,1);let b=oe(g).sequenceLength;h[p].mismatches.forEach(w=>{w.pos+=b}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{f.sequence[0]=u(f.sequence[0]);let b=h[0],w=d(b.nodeName);b.mismatches.forEach(S=>{S.pos+=w}),b.nodeName=u(b.nodeName)}}})}for(let l=0;l<x.length;l+=1)if(en(l,s,a)&&!et(l,s,a)){let i=l;for(;en(i,s,a);)i=A.get(P(a[i][0])),x[l].sequenceLength+=x[i].sequenceLength,x[l].seq+=x[i].seq}y.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=P(l.sequence[i]);let c=A.get(e);et(c,s,a)&&l.sequence.splice(i,1)}});for(let l=x.length-1;l>=0;l-=1)et(l,s,a)&&x.splice(l,1)}function et(e,t,n){if(t[e].length!==1||t[e][0]==="None")return!1;let r=P(t[e][0]),o=A.get(r);return n[o].length!==1||n[o][0]==="None"?!1:r}function en(e,t,n){if(n[e].length!==1||n[e][0]==="None")return!1;let r=P(n[e][0]),o=A.get(r);return!(t[o].length!==1||t[o][0]==="None")}function Qa(e){let t=_.focusReadNames?new Set(_.focusReadNames):null;return e.filter(n=>n.is_secondary!==!0&&(n.mapping_quality??0)>=_.mappingQualityCutoff&&(t===null||n.name!==void 0&&t.has(n.name)))}function Za(e,t){let n=new Map;for(let r of e){let o=t(r),s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}return n}function Ja(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function Ho(e,t){let n=Za(e.filter(s=>s.type===t),s=>`${s.nodeStart},${s.nodeEnd}`);n.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Ja),s.forEach(i=>{let c,d;i.yStart<i.yEnd?(c=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,d=i.xStart+(i.xEnd-i.xStart)*(1-a)):(c=i.xStart+(i.xEnd-i.xStart)*a,a+=l,d=i.xStart+(i.xEnd-i.xStart)*a);let u=`M ${i.xStart} ${i.yStart}`;u+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,u+=` V ${i.yEnd+i.width}`,u+=` C ${d} ${i.yEnd+i.width} ${d} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,u+=" Z",i.path=u})});let r=Array.from(n.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),c=l[0]??0,d=l[1]??0,u=i[0]??0,f=i[1]??0;return c<u?-1:c>u?1:d<f?-1:d>f?1:0});let o=[];for(let s of r){let a=n.get(s);a!==void 0&&o.push(...a)}return o}function Xo(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,r=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n+9} ${r} ${n+9} ${r+9}`,n+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,t+=` L ${n} ${r}`),t+=` Q ${n} ${r+9} ${n-9} ${r+9}`,n-=9,r+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n-9} ${r} ${n-9} ${r-9}`,n-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,t+=` L ${n} ${r}`),t}function ei(e){let t=new Map;for(let[n,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${n}`,a=t.get(s);a?a.push(o.strand):t.set(s,[o.strand])}return t}function ti(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=ei(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>le(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=le(s.name).name,i=new Map,c=s.nodeIds.flatMap(d=>{let u=t.get(d);if(!u)return[];let f=i.get(u.name)??0;i.set(u.name,f+1);let h=n.get(`${l} ${u.name}`)?.[f]??Kt(u);return[jt(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function ni(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function qe(e){return(e.paths?.length??0)>0}var oi=600,ri=3,si=15;function ai(e){return Math.max(ri,Math.min(si,Math.floor(oi/Math.max(1,e))))}function Yo(e){let t=e.paths??[],n=ti(e),r=e.reads?fo(e,e.reads,t.length):[],o=r.length>0?kn:On,s=t.map((l,i)=>o(i,t.length)),a=Fo(ni(e),n,r,{nodeWidthOption:"compressed",trackWidth:ai(n.length),trackColor:l=>l.type==="read"?po(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function ln(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function zo(e,t,n,r){let o=e.y+e.contentHeight/2-t;return[{x:n,y:o},{x:r,y:o}]}function Ko(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function jo(e){let t=qe(e)?Yo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=n.bounds.minY,s={};for(let i of ln(n))s[i.name]=zo(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=Ko(n,o);return{nodePositions:s,tubeMap:{layout:n,yOffset:o,pathColors:r},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:l}}}function ii(e,t){let n=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of ln(t)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,c)=>i-c)){let i=r.get(l),c=1/0,d=-1/0;for(let u of i){let f=n.get(u.name);f&&k(f)&&(c=Math.min(c,f.stable.start),d=Math.max(d,f.stable.start+u.sequenceLength))}c===1/0&&(c=d=s),c<s&&(c=s,d=Math.max(s,d)),s=Math.max(s,d),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 li(e){return e.nodes.some(k)&&qe(e)}function Uo(e){let t=li(e)?Yo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=ii(e,n),s=new Map(o.map(i=>[i.order,i])),a=n.bounds.minY,l={};for(let i of ln(n)){let c=s.get(i.order);l[i.name]=zo(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:n,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:Ko(n,a)}}function Vo(e){return e.sample??lt(e.name)}function ci(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Vo(e)}function ui(e,t){let n=[],r;for(let o of e){r!==void 0&&o.start!==void 0&&o.start>r&&n.push(o.start-r),n.push(...o.nodeIds);let s=o.nodeIds.reduce((a,l)=>a+(t.get(l)??0),0);r=o.start===void 0?void 0:o.start+s}return n}function di(e,t){let n=[],r;for(let o of e){if(o.start===void 0||r!==void 0&&o.start<r)return;r!==void 0&&o.start>r&&n.push({start:r,end:o.start});let s=o.start;for(let a of o.nodeIds){let l=t.get(a)??0;n.push({start:s,end:s+l}),s+=l}r=s}return n}function fi(e,t,n,r=!0){if(!n||!r)return{ids:e,complete:!0,from:-1,to:-1};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((c,d)=>{let u=typeof c=="string"?t.get(c):void 0;u&&(u.end<=n.start&&u.end>a&&(a=u.end,o=d),u.start>=n.end&&u.start<l&&(l=u.start,s=d))}),o<0||s<0)return{ids:e,complete:!1,from:-1,to:-1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0,from:o,to:s}}function ru(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,r)=>t.indexOf(n.sample)-t.indexOf(r.sample)||n.label.localeCompare(r.label)):e}function Qo(e,t,n){let r=e.paths??[],o=g=>le(g.name).name===e.referencePath,s=r.some(o)?r.filter(o).sort((g,b)=>(g.start??0)-(b.start??0)):r.slice(0,1),a=s[0],l=r.filter(g=>!s.includes(g));if(!a||l.length===0)return;let i=new Map;for(let g of l)i.set(g.name,[...i.get(g.name)??[],g]);let c=new Map(e.nodes.map(g=>[g.id,g.length])),d=a.start??0,u=t&&t.end>t.start?t:void 0,f=new Map;for(let g of s){let b=g.start??0;for(let w of g.nodeIds){let S=c.get(w)??0;f.has(w)||f.set(w,{start:b,end:b+S}),b+=S}}let h=u===void 0||[...f.values()].some(g=>g.end<=u.start)&&[...f.values()].some(g=>g.start>=u.end),p=g=>{let b=g[0],w=[...g].sort((K,Z)=>(K.start??0)-(Z.start??0)),{ids:S,complete:E,from:T,to:R}=fi(ui(w,c),f,u,h),N=di(w,c),v=b.contig??ct(le(b.name).name),H=N?.length?T<0?{contig:v,start:N[0].start,reversed:!1}:T<R?{contig:v,start:N[T].end,reversed:!1}:{contig:v,start:N[T].start,reversed:!0}:void 0,W=[],z=0,Se=0,pe=0,Q=0;for(let K of S){if(typeof K=="number"){W.push({start:z,bp:K,onReference:!1,gap:!0}),z+=K,pe+=K,Q=0;continue}let Z=c.get(K)??0,j=f.get(K),U=W.at(-1),Ne=U?.referenceStart,C=j&&Ne!==void 0&&Q>=0&&Ne+U.bp===j.start,O=j&&Ne!==void 0&&Q<=0&&j.end===Ne;!j&&U&&!U.onReference&&!U.gap?U.bp+=Z:C||O?(U.bp+=Z,C||(U.referenceStart=j.start,U.reversed=!0),Q=C?1:-1):(W.push({start:z,bp:Z,onReference:j!==void 0,referenceStart:j?.start}),Q=0),z+=Z,j||(Se+=Z)}return{name:b.name,label:ci(b),sample:Vo(b),haplotype:b.haplotype,bp:z,offReferenceBp:Se,gapBp:pe,complete:E,runs:W,axis:H}};return{origin:u?u.start:d,unit:n,reference:p(s),rows:[...i.values()].map(p).sort((g,b)=>Number(b.complete)-Number(g.complete)||b.bp-g.bp||g.label.localeCompare(b.label))}}var pi=1.3;function hi(e){let t=e.reference.bp;for(let n of e.rows)t=Math.max(t,n.bp);return{maxX:e.origin+t*pi,maxY:e.rows.length*20}}function Zo(e,t){let n=ve(e),r=Qo(e,t);if(n.length===0||!r)return;let o=t?n.filter(l=>yn(l,t)):n,s=Pe(o.length>0?o:n),a=[{label:r.reference.label,y:0},...r.rows.map((l,i)=>({label:l.label,y:(i+1)*20}))];return{nodePositions:s,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:hi(r)}}var mi="Force-directed layout",Re=e=>e.nodes.some(k),Jo=e=>Re(e)&&(e.paths?.length??0)>1,er=e=>Re(e)&&qe(e),tr=e=>Re(e)&&e.nodes.some(ut),cn=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:go,cutMargins:!0,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:Mo,cutMargins:!0,wholeWalks:!1,available:tr,drawsLocally:tr,drawsNodes:!0},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, blue on the reference's path and purple off it, so a repeat expansion reads as bar length, and each bar boxes its haplotype's own genes where the session has them. Needs W or P lines.",run:Zo,cutMargins:!1,wholeWalks:!0,available:Jo,drawsLocally:Jo,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:wo,cutMargins:!1,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:jo,cutMargins:!1,wholeWalks:!1,available:qe,drawsLocally:qe,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:Uo,cutMargins:!0,wholeWalks:!1,available:er,drawsLocally:er,drawsNodes:!1},{value:"force",label:mi,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],gu=cn.map(e=>e.value);function bu(e,t){return!gi(e).drawsLocally(t)}function gi(e){return cn.find(t=>t.value===e)??cn[0]}var bi=10;function xi(e,t){let n=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>r<=bi*(o.end-o.start)&&(n===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=n/2))}var yi=40;function Ee(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function wi(e,t){let n=Ee(e),r=Ee(t),o=r.slice(r.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${r}`:`${n}\u2013${r}`}function nr(e){return e>=Gn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function wu(e,t=[]){let n=Mi(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function Mi(e,t){let n=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=wi(r,o);if(a>=yi)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${nr(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Ee(o)} inv`};let c=o!==r?xi(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${nr(s)}`}}let d=s>2?`, ${s} alleles`:"";return r===o&&r===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Ee(n)} sub`}:n===0||r===n?{kind:"insertion",label:`\u2264${Ee(o-n)} ins${d}`}:o===n?{kind:"deletion",label:`${Ee(n-r)} del${d}`}:{kind:"complex",label:`${Ee(n)} ref \u2192 ${i}, ${s} alleles`}}var Mu={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},Ru={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function Eu(e){return e.segments.split(",").filter(Boolean)}function Nu({count:e,bounds:t,pixelRows:n,width:r,room:o,columns:s}){function a(i){let c=Math.ceil(e/i),d=Math.floor((r-(i-1)*8)/i),u=(o-c*34-(c-1)*8)/c,f=(d-24)/t.w,h=t.h>0?(u-24)/t.h:1/0,p=n?f:Math.min(f,h),m=n?t.h:t.h*p,g=Math.floor(Math.max(60,Math.min(m+24,u)));return{columns:i,width:d,height:g,scale:p,total:c*(g+34)+(c-1)*8}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let l=a(1);for(let i=2;i<=e;i++){let c=a(i);c.scale>l.scale&&(l=c)}return l}function Lu(e){let t=typeof e=="string"?{field:e}:e??{};return{field:t.field==="walk"||t.field==="sample"?t.field:"",domain:[...t.domain??[]],...t.columns===void 0?{}:{columns:t.columns}}}function or(e,t){let n=new Map(t.map((o,s)=>[o,s])),r=o=>n.get(o)??t.length;return e.map((o,s)=>({name:o,i:s})).sort((o,s)=>r(o.name)-r(s.name)||o.i-s.i).map(({name:o})=>o)}function Tu(e,t,n=[]){let r=or(e,n),o={columns:void 0,count:e.length,cells:e.map(c=>r.indexOf(c))};if(t==="walk")return o;let s=e.map(c=>{let[d,u,f]=c.split("#"),h=Number(u);return f!==void 0&&Number.isInteger(h)&&h>=0?{sample:d,column:Math.max(0,h-1)}:void 0}),a=or([...new Set(s.flatMap(c=>c?[c.sample]:[]))],n),l=Math.max(1,...s.map(c=>c?c.column+1:1)),i=s.map(c=>c?a.indexOf(c.sample)*l+c.column:-1);return i.includes(-1)||new Set(i).size<i.length?o:{columns:l,count:a.length*l,cells:i}}function I(e,t={},...n){return{tag:e,attrs:t,children:n.filter(r=>!!r||r==="")}}function rr(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function Ri(e){return rr(e).replaceAll('"',""")}function Ei(e){if(typeof e=="string")return rr(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,r])=>` ${n}="${Ri(String(r))}"`).join("");return`<${e.tag}${t}>${e.children.map(Ei).join("")}</${e.tag}>`}var ar="#2f8fd6",ir="#8e3fbf",lr="#bdbdbd",Et="#1c1c22",cr=12,ur=4,Si=3;function nt(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function sr(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function Ni(e,t,n,r){let{bp:o,gapBp:s,complete:a}=e;if(!t)return`${nt(o)}${sr(o,n)}`;let l=o-t.bp,i=l===0?"":` (${l>0?"+":"\u2212"}${nt(Math.abs(l))})`,c=s>0?` \xB7 ${nt(s)} outside the cut`:"",d=r?` \xB7 called ${nt(r.bp)}${r.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${nt(o)}${sr(o,n)}${i}${c}${a?"":" \xB7 partial walk"}${d}`}function Li(e,t,n){let r=t+6;return r+e.length*6.2<n?{x:r,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Ti(e,t,n){if(t*n<Si)return[];let r=[];for(let o=t;o<e;o+=t)r.push(o);return r}function Ai(e,t){if(e.gap)return{fill:lr};if(!t)return{fill:e.onReference?ar:ir};if(e.referenceStart===void 0)return{fill:Wt};let n=to({...e,start:e.referenceStart},t);return n.length===1?{fill:gt(n[0])}:{stops:n.map(gt)}}function St(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function ku(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function Gu(e,t){let n=new Map;for(let r of e){let o=t.get(r.name);if(!r.axis||!o)continue;let s=r.axis,a=({start:l,end:i})=>({start:Math.max(0,l),end:Math.min(r.bp,i)});n.set(r.name,o.map(l=>({name:l.name,...a(St(s,l.start,l.end)),exons:l.exons.map(i=>a(St(s,i.start,i.end))).filter(i=>i.end>i.start)})).filter(l=>l.end>l.start).sort((l,i)=>l.start-i.start))}return n}var Ci=9,_i=5.2,Ii=8,dr=(e,t)=>Math.min(2,(e-t)/2-1);function dn(e,t){return dr(e,t)>=1}function vi(e,t,n,{rowPx:r=20,barPx:o=cr}={}){if(!dn(r,o))return[];let s=dr(r,o),a=e.map(c=>{let d=t(c.start);return{g:c,x:d,w:Math.max(2,t(c.end)-d)}}),l=[],i=new Set((o>=Ii?[...a]:[]).sort((c,d)=>c.w-d.w).filter(({g:c,x:d,w:u})=>{let f=c.name.length*_i/2,h=[d+u/2-f,d+u/2+f];return 2*f>u+6||l.some(([p,m])=>h[0]<m+2&&h[1]>p-2)?!1:(l.push(h),!0)}));return a.map(c=>({name:c.g.name,x:c.x,y:n-o/2-s,w:c.w,h:o+2*s,exons:c.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:i.has(c)?{x:c.x+c.w/2,y:n+3,size:Ci}:void 0}))}var un=e=>`${e} row${e===1?"":"s"}`;function Bu(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??no,ramp:!0}:{kind:"bar",fill:ar},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Wt:ir},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(r=>r.gapBp>0)&&n.push({swatch:{kind:"gap",fill:lr},label:"walked outside the cut"}),t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):t.genes&&(n.push({swatch:{kind:"gene"},label:"genes, each row's own annotation"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${un(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${un(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${un(t.genes.unread)}`,note:!0})),n}var Pi="#111",Oi="#9e9e9e",ki="#c62828";function $u(e,t,n,r="walk-key"){let o=0,s=e.flatMap((a,l)=>{let i=`${r}-ramp-${l}`,c=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?I("linearGradient",{id:i},...Xt.map(f=>I("stop",{offset:f.offset,"stop-color":f.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?I("rect",{x:o,y:5,width:18,height:8,fill:"none",stroke:Et,"stroke-width":1.5}):I("rect",{x:o,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?ur:8,rx:2,fill:c?`url(#${i})`:a.swatch.fill}),u=I("text",{x:a.note?o:o+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return o+=(a.note?0:23)+a.label.length*6.2+16,[c,d,u].filter(f=>f!==void 0)});return{width:o,tree:I("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function Gi(e,t){let n=1/t,r=[],o=[],s=()=>{if(o.length!==0){if(o.length===1)r.push(o[0]);else{let l=0,i=0;for(let u of o)u.onReference?l+=u.bp:i+=u.bp;let c=l>=i,d=o.find(u=>u.onReference===c);r.push({start:o[0].start,bp:l+i,onReference:c,referenceStart:c?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}o=[]}},a=0;for(let l of e){if(l.gap||l.bp>=n){s(),a=0,r.push(l);continue}o.push(l),a+=l.bp,a>=n&&(s(),a=0)}return s(),r}function Bi(e,t,n){return I("g",{class:"row-gene","data-testid":"graph-walk-gene"},I("title",{},e.name),...e.exons.map(r=>I("rect",{x:r.x,y:t-n/2,width:r.w,height:n,fill:Et,opacity:.35})),I("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:Et,"stroke-width":1.5}),e.label&&I("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:Et,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function Fu(e,t,n={}){let r=p=>p*t.scaleX+t.translateX,o=t.rowPx??20,s=t.barPx??cr,a=p=>p*o*t.scaleY+t.translateY,{origin:l,unit:i,reference:c,rows:d}=e,u=p=>r(l+p),f=n.idPrefix??"walkrow",h=(p,m)=>{let g=a(m);if(g<-s||g>t.height+s)return;let b=Gi(p.runs,t.scaleX).flatMap(N=>{let v=Ai(N,n.ramp),H=N.gap?Math.min(ur,s):s,W=`${f}-${m}-${N.start}`,z=I("rect",{x:u(N.start),y:g-H/2,width:Math.max(1,N.bp*t.scaleX),height:H,fill:"stops"in v?`url(#${W})`:v.fill});return"stops"in v?[I("linearGradient",{id:W},...v.stops.map((Se,pe)=>I("stop",{offset:pe/(v.stops.length-1),"stop-color":Se}))),z]:[z]}),w=i?Ti(p.bp,i,t.scaleX).map(N=>I("line",{x1:u(N),x2:u(N),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:S}=p,E=Ni(p,m===0?void 0:c,i,S),T=Li(E,u(p.bp),t.width),R=t.readouts??!0;return I("g",{"data-testid":m===0?"graph-walk-reference":"graph-walk-row"},...b,...w,...vi(n.rowGenes?.get(p.name)??[],u,g,{rowPx:o,barPx:s}).map(N=>Bi(N,g,s)),S&&I("rect",{"data-testid":"graph-walk-call",x:u(S.bp)-1,y:g-s/2-3,width:2,height:s+6,fill:S.spanningReads===0?Oi:Pi}),R&&I("text",{x:T.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:S?.agrees===!1?ki:"#333",stroke:T.halo?"white":void 0,"stroke-width":T.halo?3:void 0,"paint-order":"stroke","text-anchor":T.anchor},E))};return I("g",{},...[c,...d].map(h))}var ot=6,$i=260,Fi=11,Wi=3,Di=12,qi=1.3,Hi="#111",fr=3;function zu(e,t,n){let r=e.pathVisits?.get(n.name)??[],o=[];for(let s of t){let a=s.axis;if(!a)continue;let l=le(s.name).name;for(let i of r){if(i.path!==l)continue;let{start:c,end:d}=St(a,i.start,i.start+n.length);d>0&&c<s.bp&&o.push({row:s.name,start:c,bp:d-c})}}return o}var pr=new WeakMap;function Xi(e,t){let n=pr.get(e);if(n||(n=new Map,pr.set(e,n)),n.has(t))return n.get(t);let r=new Map(e.nodes.map(a=>[a.id,a.length])),o=(e.paths??[]).filter(a=>a.name===t),s;if(o.every(a=>a.start!==void 0)){s={ids:[],starts:[],ends:[]};for(let a of[...o].sort((l,i)=>l.start-i.start)){let l=a.start;for(let i of a.nodeIds){let c=r.get(i)??0;s.ids.push(i),s.starts.push(l),s.ends.push(l+c),l+=c}}}return n.set(t,s),s}function Ku(e,t,n,r){let o=t.axis,s=o&&Xi(e,t.name);if(!o||!s||n<0||n>t.bp)return;let a=o.reversed?o.start-n:o.start+n,l=.5/r,i=o.reversed?{start:o.start-t.bp,end:o.start}:{start:o.start,end:o.start+t.bp},c=Math.max(a-l,i.start),d=Math.min(a+l,i.end),u=0,f=s.starts.length;for(;u<f;){let g=u+f>>1;s.ends[g]<=c?u=g+1:f=g}let h,p=-1,m=!1;for(let g=u;g<s.starts.length&&s.starts[g]<d;g++){let b=s.ends[g]-s.starts[g],w=s.starts[g]<=a&&a<s.ends[g];(b>p||b===p&&w&&!m)&&(p=b,h=s.ids[g],m=w)}return h}function ju(e,t){let n=t.maxHeight??$i,r=t.labelPx??Math.max(...[e.reference,...e.rows].map(h=>h.label.length))*6.2+16,o=e.rows.length+1,s=Math.max(Wi,Math.min(20,Math.floor((n-2*ot)/o))),a=s>=Di,l=s>=14,i=Math.max(2,Math.round(s*.6)),c=Math.max(e.reference.bp,...e.rows.map(h=>h.bp),1),d=a?r:ot,f=Math.max(1,t.width-d-ot)/(c*(l?qi:1));return{scaleX:f,scaleY:1,translateX:d-e.origin*f,translateY:ot+s/2,width:t.width,height:o*s+2*ot,rowPx:s,barPx:i,readouts:l,labelled:a,boxesGenes:dn(s,i)}}function Uu(e,t,n,r){let o=Math.round((r-t.translateY)/t.rowPx),s=[e.reference,...e.rows][o],a=(n-t.translateX)/t.scaleX-e.origin;return s&&o>=0&&a>=0&&a<=s.bp?{index:o,row:s,offset:a}:void 0}function Vu(e,t,n){let r=new Map([e.reference,...e.rows].map((s,a)=>[s.name,a])),o=s=>(e.origin+s)*t.scaleX+t.translateX;return I("g",{"data-testid":"graph-walk-marks"},...n.flatMap(s=>{let a=r.get(s.row);if(a===void 0)return[];let l=a*t.rowPx+t.translateY,i=o(s.start),c=Math.max(2,s.bp*t.scaleX),d=u=>I("rect",{x:i,y:u,width:c,height:fr,fill:Hi});return[d(l-t.barPx/2-fr-1),d(l+t.barPx/2+1)]}))}function Qu(e,t,n=new Set){return I("g",{"font-family":"sans-serif","font-size":Fi,fill:"#333"},...(t.labelled?[e.reference,...e.rows]:[]).map((r,o)=>I("text",{x:6,y:o*t.rowPx+t.translateY+4,"font-weight":n.has(r.name)?600:void 0},r.label)))}function Zu(e,t,n){if(t?.size)return e.boxesGenes?n:{untracked:0,unread:0,...n,crowded:!0}}var He=Y(ke(),1),yr=Y(mr(),1),wr=Y(br(),1);var xr=class extends wr.Canvas2DRenderingBackendBase{constructor(){super(...arguments);this.transform=null;this.batch=null;this.nodeHighlights=new Map;this.highlightedEdge=null;this.highlightFactor=1}resize(n,r){(0,yr.syncCanvasSize)(this.ctx.canvas,n,r)}uploadGeometry(n){this.batch=n,this.highlightedEdge=null}setNodeHighlights(n){this.nodeHighlights=n}setEdgeHighlight(n,r){this.highlightedEdge=n,this.highlightFactor=r}updateTransform(n){this.transform=n}render(n){if(!this.transform)return;let o=this.ctx,{width:s,height:a}=o.canvas;n[3]<1&&o.clearRect(0,0,s,a),o.fillStyle=(0,He.normalizedRgbToCssRgba)([n[0],n[1],n[2]],n[3]),o.fillRect(0,0,s,a);let l=this.batch;l&&(o.lineCap="round",o.lineJoin="round",this.renderEdges(l),this.renderNodes(l),this.renderArrows(l))}renderEdges(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.edgeCurveRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.edgeCurves,(i,c)=>({color:Nt(s,c)?ht(i.color,this.highlightFactor):i.color,weight:i.thickness,last:Nt(s,c)}))){o.strokeStyle=(0,He.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.curves[0];o.moveTo(c.x0*r.scaleX+r.translateX,c.y0*r.scaleY+r.translateY);for(let d of i.curves)o.bezierCurveTo(d.cx0*r.scaleX+r.translateX,d.cy0*r.scaleY+r.translateY,d.cx1*r.scaleX+r.translateX,d.cy1*r.scaleY+r.translateY,d.x1*r.scaleX+r.translateX,d.y1*r.scaleY+r.translateY)}o.stroke()}}renderNodes(n){let r=this.transform,o=this.ctx,s=new Map;for(let[a,l]of this.nodeHighlights){let i=n.nodeStrokeRuns.get(a);if(i)for(let c=i.start;c<i.start+i.count;c++)s.set(c,l)}for(let{color:a,items:l}of fn(n.nodeStrokes,(i,c)=>{let d=s.get(c);return{color:d===void 0?i.color:ht(i.color,d),weight:i.thickness,last:d!==void 0}})){o.strokeStyle=(0,He.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.points[0];o.moveTo(c.x*r.scaleX+r.translateX,c.y*r.scaleY+r.translateY);for(let d=1,u=i.points.length;d<u;d++){let f=i.points[d];o.lineTo(f.x*r.scaleX+r.translateX,f.y*r.scaleY+r.translateY)}}o.stroke()}}renderArrows(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.arrowRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.arrows,(i,c)=>({color:Nt(s,c)?ht(i.color,this.highlightFactor):i.color,weight:0,last:Nt(s,c)}))){o.fillStyle=(0,He.abgrToCssRgba)(a),o.beginPath();for(let i of l){let[c,d,u,f]=zi(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}},Yi=.25;function zi(e,t){let n=Math.cos(e.angle),r=Math.sin(e.angle),o=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,l=e.halfWidth*t.dpr,i=o-n*a,c=s-r*a,d=a*(1-Yi);return[{x:o,y:s},{x:i-r*l,y:c+n*l},{x:o-n*d,y:s-r*d},{x:i+r*l,y:c-n*l}]}function Nt(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function fn(e,t){let n=new Map,r=new Map;for(let o=0,s=e.length;o<s;o++){let a=e[o],{color:l,weight:i,last:c}=t(a,o),d=c?r:n,u=`${l}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:l,items:[a]})}return[...n.values(),...r.values()]}var Nr=Y(ke(),1);var Ki=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],Lr=[{value:"grey",label:"Grey to black",ends:["#a3a3a3","#151515"]},{value:"blue",label:"Cyan to navy",ends:["#6ee0f0","#0b2c7a"]},{value:"red",label:"Yellow to red",ends:["#ffd24a","#b3121b"]},{value:"purple",label:"Pink to plum",ends:["#f5a3d8","#5e1a6e"]},{value:"green",label:"Lime to forest",ends:["#b6e36c","#0b5d3b"]},{value:"rainbow",label:"Rainbow"}],Mr=["blue","red","purple","green"],ji=e=>Ki.some(t=>t.value===e),Ui=e=>Lr.some(t=>t.value===e);function sd(e,t,n,r=!0){let{field:o,scheme:s}=e.color??{},a=ji(o)?o:r?"progress":"walk",l=t?"grey":Mr[n%Mr.length],i=Ui(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var Tr=.5,Vi=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Qi=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function Rr(e){let[t,n,r]=[1,3,5].map(l=>Vi(Number.parseInt(e.slice(l,l+2),16)/255)),o=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*r),s=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*r),a=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*r);return[.2104542553*o+.793617785*s-.0040720468*a,1.9779984951*o-2.428592205*s+.4505937099*a,.0259040371*o+.7827717662*s-.808675766*a]}function Zi([e,t,n]){let r=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s].map(a=>Qi(Math.max(0,Math.min(1,a)))*255)}function Ar(e,t){let n=Math.max(0,Math.min(1,t)),r=Lr.find(a=>a.value===e);if(!r||!("ends"in r))return Be(n*$e,.7,.5).map(a=>a*255);let o=Rr(r.ends[0]),s=Rr(r.ends[1]);return Zi(o.map((a,l)=>a+(s[l]-a)*n))}function Er(e,t){let[n,r,o]=Ar(e,t).map(Math.round);return`rgb(${n}, ${r}, ${o})`}function Sr(e,t){let[n,r,o]=Ar(e,t).map(Math.round);return(0,Nr.packAbgr)(n,r,o,255)}function ad({field:e,scheme:t},n){return e==="walk"?Sr(t,Tr):n===void 0?Ji:Sr(t,n)}var Ji=Ft;function el({field:e,scheme:t}){return e==="walk"?[{offset:0,color:Er(t,Tr)}]:Array.from({length:7},(n,r)=>({offset:r/6,color:Er(t,r/6)}))}function id(e){let t=el(e);return t.length===1?t[0].color:`linear-gradient(to right, ${t.map(n=>`${n.color} ${n.offset*100}%`).join(", ")})`}function Cr(e,t,n){let r=Math.round(t),o=Math.round(n);return`${e?`${e}:`:""}${Ve(r)}-${Ve(o)} (${xe(o-r)})`}function ud(e,t){let{field:n}=e.encoding,r=e.range?Cr(e.range.contig,e.range.start,e.range.end):void 0,o=n==="progress"?r:n==="reference"&&t?Cr(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${xe(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${xe(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${xe(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:o,hover:o===r?void 0:r}}function dd(e,t,n){let r=e.progress.get(t),o=e.range;if(r===void 0||!o)return;let s=Math.round(o.start+r*(o.end-o.start)-n/2);return`${o.contig}:${Ve(s)}-${Ve(s+n)}`}var pn=Y(ke(),1);var fe=12,tl=fe+8,Or=8,_r=Or+3,nl=12;function md(e,{colorScheme:t,referenceRamp:n,walks:r}){let o={...Dt(e),referenceRamp:n},s=[];return e.nodes.forEach((a,l)=>{if(k(a)){let i=r?r.map(c=>{let d=c.colors.get(a.id);return d===void 0?$t:(0,pn.abgrToCssRgba)(d)}):[(0,pn.abgrToCssRgba)(qt(a,l,t,o))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes($t)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function hn(e,t,n){let r=t*e.scale+e.translateX,o=n*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var Ir=2;function ol(e,t,n){let r=-t.translateX/t.scale,o=(n-t.translateX)/t.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let c of e)l+=Math.max(0,Math.min(c.bp1,s)-c.bp0),i+=Math.max(0,c.bp1-Math.max(c.bp0,a));return t.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function gd(e,t,n,r){if(r<0||r>fe+Ir)return;let o,s=Ir;for(let a of e){let[l,i]=hn(t,a.bp0,a.bp1),c=Math.max(0,l-n,n-i);c<=s&&(s=c,o=a.node)}return o}function bd(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function rl(e,t,n,r){let o=e.map(c=>{let[d,u]=hn(t,c.bp0,c.bp1),f=Math.round(d*r);return{colors:c.colors,x0:d,px0:f,px1:Math.max(Math.round(u*r),f+1)}}).filter(c=>c.px1>0&&c.px0<n*r).sort((c,d)=>c.x0-d.x0),s=[],a=-1/0,l=[-1/0,-1/0];for(let{colors:c,px0:d,px1:u}of o){let f=Math.max(d,a);if(u>f){let h=l[0]<f?0:1;l[h]=u,s.push({colors:c,x0:f/r,x1:u/r,tier:h}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*nl?s:s.map(({tier:c,...d})=>d)}function vr(e,t,n,r){let o=n>0?t:t-_r;e.clearRect(o,0,_r,fe);let s=t+n,a=s+n*Or;e.beginPath(),e.moveTo(s,fe/2),e.lineTo(a,0),e.lineTo(a,fe),e.closePath(),e.fillStyle=r,e.fill()}function Pr(e,t,n){return Math.round(e*fe*n/t)/n}function xd(e,t,n,{width:r,lit:o,darkMode:s,dpr:a=1}){let l=s?"#ffffff":"#18181c";e.clearRect(0,0,r,tl);for(let c of rl(t,n,r,a)){let{tier:d}=c,u=d!==void 0&&c.colors.length===1,f=u?2:c.colors.length;c.colors.forEach((h,p)=>{let m=u?d:p,g=Pr(m,f,a);e.fillStyle=h,e.fillRect(c.x0,g,c.x1-c.x0,Pr(m+1,f,a)-g)})}let i=ol(t,n,r);if(i.left>0&&vr(e,0,1,l),i.right>0&&vr(e,r,-1,l),o){let[c,d]=hn(n,o.start,o.end),u=Math.max(d-c,3),f=(c+d)/2-u/2;e.strokeStyle=l,e.lineWidth=1.5,e.strokeRect(f,.75,u,fe-1.5),o.anchor&&(e.beginPath(),e.moveTo(f+u/2,fe),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function Rd(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;t.nodes.forEach(o=>{let s=n.get(o.name);if(o.order>=0&&s&&k(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function mn(e,t,n=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(n?i<t:i<=t)?r=l+1:o=l}let s=e[r];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function gn(e,t,n){let r=mn(e,t),o=mn(e,n,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function Ed(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var kr=5,sl=10,al=110,il=3;function ll(e){return e?"#b0b0b8":"#55555c"}function cl(e){let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<=1?1:n<=2?2:n<=5?5:10)*t}function Gr(e){let t=[];for(let n of e)t.every(r=>Math.abs(n.at-r.at)>=(n.width+r.width)/2+sl)&&t.push(n);return t.map(({text:n,at:r})=>({text:n,at:r}))}function ul(e,t,n,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=t(o.x0),l=t(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let c=cl(i/(l-a)*al),d=[],u=[];for(let f=Math.ceil(o.bp0/c)*c;f<=s.bp1;f+=c){let h=Math.round(t(mn(e,f)))+.5;if(h>=0&&h<=n){d.push(h);let p=f.toLocaleString("en-US");u.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:d,labels:Gr(u)}}function dl(e,t,n,r){let o=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=n),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),c=[],d=[],u=[],f=[];for(let{box:p,s0:m,s1:g}of o){c.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=il&&d.push(Math.round(g)+.5);let b=l(xe(p.bp1-p.bp0),(m+g)/2);b.width<=g-m&&u.push(b),p!==s.box&&f.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:c,ticks:d,labels:Gr([...h,...u,...f])}}function fl(e,t,n,r,o=!1){return(o?ul:dl)(e,t,n,r)}function Sd(e,t,n,r,o=!1){let{x:s,width:a,darkMode:l}=n;e.font="10px sans-serif";let i=fl(t,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=ll(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+kr);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,r+kr+2)}function Td(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach(o=>{let s=n.get(o.name);o.order>=0&&s&&k(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 Ad(e,t,n,r){let o=[];for(let s of e){let a=n(s.x0),l=n(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:l})}return o}var pl=3;function Cd(e,t,n,r){if(t<=0||r<0||r>t)return;let o=r/t,s,a=pl;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,c=l.top1+(l.bottom1-l.top1)*o,d=Math.max(0,Math.min(i,c)-n,n-Math.max(i,c));d<a&&(a=d,s=l.node)}return s}function Br(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.top1,0),e.lineTo(t.bottom1,n),e.lineTo(t.bottom0,n),e.closePath()}function $r(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function _d(e,t,n,{highlightNode:r,darkMode:o}){if(n<=0||t.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of t)Br(e,l,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of t)$r(e,l,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(l=>l.node===r);a&&(e.beginPath(),Br(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),$r(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function hl(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach((o,s)=>{let a=n.get(o.name);if(o.order>=0&&a&&k(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 ml(e,t,n){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=t?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function Pd(e,t,n){let r=hl(e,t),o=[];for(let s of t.tracks){let a=s.name?n.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let c=ml(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 gl(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Od(e,t,{x:n,y:r,width:o,darkMode:s}){if(t.length!==0){e.fillStyle=gl(s),e.beginPath();for(let a of t){let l=n(a.x0),i=Math.max(n(a.x1),l+1);if(i>=0&&l<=o){let c=r(a.y);e.rect(l,c,i-l,r(a.y+a.height)-c)}}e.fill()}}function bl(e,t){let n=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=t.nodeMap.get(P(o.nodeName)),l=a===void 0?void 0:t.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let c=e.path[i]?.y;if(l&&c!==void 0){let d={readId:e.id,y:c,height:e.width,nodeY:l.y},u=f=>qo(l,f);for(let f of o.mismatches){let h=u(f.pos);if(h!==null){if(f.type==="insertion"){let p=s===0&&f.pos===e.firstNodeOffset||s===r.length-1&&f.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:h,seq:f.seq,softClip:p})}else if(f.type==="deletion"&&f.length!==void 0){let p=u(f.pos+f.length);p!==null&&n.push({...d,kind:"deletion",x0:h,x1:p})}else if(f.type==="substitution"&&f.seq!==void 0){let p=u(f.pos+f.seq.length);p!==null&&n.push({...d,kind:"substitution",x0:h,x1:p,seq:f.seq})}}}}}),n}function Fr(e){return e.reads.flatMap(t=>bl(t,e))}function Yr(e){let t=e.trim().split(/[\s,]+/),n=[],r=0,o=()=>Number(t[r++]);for(;r<t.length;){let s=t[r++];s==="M"||s==="L"?n.push({op:s,x:o(),y:o()}):s==="H"?n.push({op:s,x:o()}):s==="V"?n.push({op:s,y:o()}):s==="Q"?n.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?n.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&n.push({op:s})}return n}function zr(e){let t=1/0,n=-1/0;for(let r of e)"x"in r&&(t=Math.min(t,r.x),n=Math.max(n,r.x)),"x1"in r&&(t=Math.min(t,r.x1),n=Math.max(n,r.x1));return{x0:t,x1:n}}function Wr(e,t,n,r){let o=Yr(e);return{commands:o,color:t,track:r,alpha:n,...zr(o)}}function Dr(e,t){let{shapes:n}=e,r=l=>t==="haplotype"?l.id:void 0,o=[...n.rectangles,...n.verticalRectangles].filter(l=>l.type===t).map(l=>({color:l.color,track:r(l),alpha:l.alpha??1,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),s=Ho(n.curves,t).map(l=>Wr(l.path,l.color,l.alpha??1,r(l))),a=n.corners.filter(l=>l.type===t).map(l=>Wr(l.path,l.color,1,r(l)));return{rects:o,shapes:[...s,...a]}}function Wd(e){let t=[];return e.nodes.forEach(n=>{if(n.order>=0){let r=Yr(Xo(n));t.push({name:n.name,commands:r,...zr(r)})}}),{bounds:e.bounds,layers:[Dr(e,"haplotype"),Dr(e,"read")],nodes:t,mismatches:Fr(e).filter(n=>n.kind!=="insertion"||!n.softClip)}}function qr(e,t,n,r){let o=0,s=0;for(let a of t)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(n(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(n(o),r(s));break;case"H":o=a.x,e.lineTo(n(o),r(s));break;case"V":s=a.y,e.lineTo(n(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),r(a.y1),n(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(n(a.x1),r(a.y1),n(a.x2),r(a.y2),n(o),r(s));break;case"Z":e.closePath();break}}function Hr(e,t,n,r,o){let s=new Map;for(let a of t)if(n(a)){let l=`${r(a)}|${a.alpha}`,i=s.get(l);i?i.push(a):s.set(l,[a])}for(let a of s.values()){e.fillStyle=r(a[0]),e.globalAlpha=a[0].alpha,e.beginPath();for(let l of a)o(l);e.fill()}e.globalAlpha=1}var xl=12,yl=.15;function wl(e){return Math.max(yl,Math.min(1,e/xl))}var Ml=.55;function Dd(e,t,n){let{x:r,y:o,width:s}=n,a=d=>r(d.x1)>=0&&r(d.x0)<=s,l=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;for(let d of t.layers)Hr(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)}),Hr(e,d.shapes,a,l,u=>{qr(e,u.commands,r,o)});let i=n.darkMode?"#d0d0d0":"#000000",c=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,n.yScale));for(let d of t.nodes)if(a(d)){let u=d.name===n.highlightNode;e.beginPath(),qr(e,d.commands,r,o);let f=u?void 0:n.nodeColors?.get(d.name);e.fillStyle=u?"rgba(255,192,203,0.5)":f??c,e.strokeStyle=u?"#ff0000":i,e.globalAlpha=f?Ml:1,e.fill(),e.globalAlpha=u?1:wl(r(d.x1)-r(d.x0)),e.stroke(),e.globalAlpha=1}Sl(e,t.mismatches,n)}var Kr=12,Rl=6;function El(e){return Kr*e>=Rl}function Xr(e,{x:t,width:n}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(o)>=0&&t(r)<=n}function Sl(e,t,n){let{x:r,y:o,yScale:s,darkMode:a}=n;if(!El(s)||t.length===0)return;let l=Kr*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&Xr(i,n)){let c=r(i.x0),d=o(i.y);e.rect(c,d,r(i.x1)-c,o(i.y+i.height)-d)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of t)Xr(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Xd(e,t){let n=[];for(let r of t){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||n.push({gene:r,...gn(o,l,i),exons:r.exons.filter(c=>c.end>l&&c.start<i).map(c=>gn(o,Math.max(c.start,l),Math.min(c.end,i)))})}return n}var jr=22,Nl=4,Lt=8,Ll="11px sans-serif",Tl=8;function Yd(e){let t=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),n=0,r=0;for(let{step:o}of t)n+=o,r=Math.max(r,n);return Math.min(Nl,r)}function zd(e,t,n,r,o=0){let{x:s,width:a,darkMode:l}=n,i=Math.max(1,Math.floor((r-o)/jr)),c=[],d=l?"#e0e0e6":"#1c1c22";e.font=Ll,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=t.map(f=>({g:f,s0:s(f.x0),s1:s(f.x1)})).filter(({s0:f,s1:h})=>h>=0&&f<=a).sort((f,h)=>f.s0-h.s0);for(let{g:f,s0:h,s1:p}of u){let m=f.gene.strand>0?" \u2192":f.gene.strand<0?"\u2190 ":"",g=f.gene.strand<0?`${m}${f.gene.name}`:`${f.gene.name}${m}`,b=(Math.max(h,0)+Math.min(p,a))/2,w=e.measureText(g).width/2,S=Math.min(h,b-w),E=Math.max(p,b+w),T=c.findIndex(N=>N+Tl<=S);T===-1&&(T=Math.min(c.length,i-1)),c[T]=Math.max(c[T]??-1/0,E);let R=r-T*jr-Lt/2;e.beginPath(),e.moveTo(h,R+.5),e.lineTo(p,R+.5),e.stroke();for(let N of f.exons){let v=s(N.x0);e.fillRect(v,R-Lt/2,Math.max(1,s(N.x1)-v),Lt)}e.fillText(g,b,R-Lt/2-2)}}function Al(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function Cl(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0)),s=Array.from({length:n+1},()=>new Array(r+1).fill(!1));for(let l=n-1;l>=0;l--)for(let i=r-1;i>=0;i--){let c=Math.abs(e[l]-t[i])+o[l+1][i+1],d=n-l>r-i?o[l+1][i]:1/0,u=r-i>n-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,d,u),s[l][i]=o[l][i]===c}let a=new Array(n).fill(void 0);for(let l=0,i=0;l<n&&i<r;)s[l][i]?a[l++]=i++:n-l>r-i?l++:i++;return a}function Ur(e,t){return e.map((n,r)=>({item:n,i:r})).sort((n,r)=>t(n.item)-t(r.item))}var Qr=e=>e.spanningReads!==0;function Vr(e,t){return{...t,agrees:e.complete&&Qr(t)?Al(e.bp,t.bp):void 0}}function _l(e,t){let n=new Map,r=new Set;e.forEach((l,i)=>{let c=t.find(d=>d.haplotype!==void 0&&d.haplotype===l.haplotype);c&&(r.add(c),n.set(i,Vr(l,c)))});let o=t.filter(l=>l.haplotype===void 0),s=Ur(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Qr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!n.has(u.i)),d=Ur(i.filter(u=>!r.has(u)),u=>u.bp);Cl(c.map(u=>u.item.bp),d.map(u=>u.item.bp)).forEach((u,f)=>{if(u!==void 0){let h=c[f],p=d[u].item;r.add(p),n.set(h.i,Vr(h.item,p))}})}return n}function jd(e,t){if(!t)return e;let n=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=t[o];if(a)for(let[l,i]of _l(s,a))n.set(s[l],i)}return e.map(o=>({...o,call:n.get(o)}))}var Zr=Y(it(),1),Qd=(0,ne.createSvgIcon)((0,Zr.jsx)("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");export{ne as a,zs as b,ke as c,Qe as d,ds as e,sa as f,Kt as g,Us as h,Vs as i,ei as j,ru as k,Qo as l,hi as m,cn as n,gu as o,bu as p,gi as q,Ee as r,wu as s,Mu as t,Ru as u,Eu as v,Nu as w,Lu as x,Tu as y,Ei as z,ns as A,Wn as B,is as C,ls as D,kl as E,Yn as F,$t as G,Wt as H,Vl as I,Dt as J,qt as K,Ql as L,no as M,Et as N,cr as O,ur as P,Ni as Q,ku as R,Gu as S,Bu as T,ki as U,$u as V,Fu as W,zu as X,Ku as Y,ju as Z,Uu as _,Vu as $,Qu as aa,Zu as ba,mr as ca,xr as da,Ki as ea,Lr as fa,sd as ga,ad as ha,Ji as ia,el as ja,id as ka,Cr as la,ud as ma,dd as na,tl as oa,md as pa,ol as qa,gd as ra,bd as sa,xd as ta,Rd as ua,Ed as va,ll as wa,Sd as xa,Td as ya,Ad as za,Cd as Aa,_d as Ba,Pd as Ca,gl as Da,Od as Ea,Wd as Fa,Dd as Ga,El as Ha,Xr as Ia,Xd as Ja,jr as Ka,Yd as La,zd as Ma,jd as Na,oc as Oa,rc as Pa,qs as Qa,sc as Ra,ac as Sa,Yt as Ta,zt as Ua,xc as Va,yc as Wa,Qd as Xa};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-F2EPKNTV.js.map
|