jbrowse-plugin-graphgenomeviewer 6.2.0 → 6.3.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/{GbzBaseSyntenyAdapter-TLI5IUU7.js → GbzBaseSyntenyAdapter-PT4IARIU.js} +2 -2
- package/dist/chunks/{GbzBaseSyntenyAdapter-TLI5IUU7.js.map → GbzBaseSyntenyAdapter-PT4IARIU.js.map} +1 -1
- package/dist/chunks/{GraphGenomeView-5OPCROMQ.js → GraphGenomeView-6CRBLHNG.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-FGLLUIEE.js → GraphTrackSettingsDialog-2QQYWNWW.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-NBJHGOYX.js → LinearGraphDisplay-KNEXJAAV.js} +2 -2
- package/dist/chunks/{MinigraphBubbleAdapter-LQUIL3MD.js → MinigraphBubbleAdapter-MQRO5J7Z.js} +2 -2
- package/dist/chunks/{RgfaTabixAdapter-3BFNY4SB.js → RgfaTabixAdapter-ALEXRTPS.js} +2 -2
- package/dist/chunks/{bandage-layout-3AR6BCUD-I6CCWYSR.js → bandage-layout-3AR6BCUD-BW536UT3.js} +1 -1
- package/dist/chunks/{bandage-layout-3AR6BCUD-I6CCWYSR.js.map → bandage-layout-3AR6BCUD-BW536UT3.js.map} +1 -1
- package/dist/chunks/{chunk-EKMGHBWM.js → chunk-3MJ4ZXML.js} +1 -1
- package/dist/chunks/{chunk-EKMGHBWM.js.map → chunk-3MJ4ZXML.js.map} +1 -1
- package/dist/chunks/{chunk-O5EHYU3Y.js → chunk-4F2MWXJF.js} +2 -2
- package/dist/chunks/{chunk-NGQRKSHY.js → chunk-4LEFC42C.js} +2 -2
- package/dist/chunks/{chunk-NGQRKSHY.js.map → chunk-4LEFC42C.js.map} +2 -2
- package/dist/chunks/{chunk-F7V6ZPKD.js → chunk-5GRQIE5Q.js} +1 -1
- package/dist/chunks/{chunk-F7V6ZPKD.js.map → chunk-5GRQIE5Q.js.map} +1 -1
- package/dist/chunks/{chunk-JYZAMHIP.js → chunk-6IK6ZDSI.js} +2 -2
- package/dist/chunks/{chunk-JYZAMHIP.js.map → chunk-6IK6ZDSI.js.map} +1 -1
- package/dist/chunks/{chunk-X24J6VF4.js → chunk-C4PHHPUP.js} +1 -1
- package/dist/chunks/{chunk-X24J6VF4.js.map → chunk-C4PHHPUP.js.map} +1 -1
- package/dist/chunks/{chunk-XWGKHQYO.js → chunk-CJ47OHWP.js} +2 -2
- package/dist/chunks/{chunk-XWGKHQYO.js.map → chunk-CJ47OHWP.js.map} +1 -1
- package/dist/chunks/{chunk-7MWOPEIC.js → chunk-ETTZTJNK.js} +1 -1
- package/dist/chunks/{chunk-7MWOPEIC.js.map → chunk-ETTZTJNK.js.map} +1 -1
- package/dist/chunks/chunk-PZE3GABA.js +2 -0
- package/dist/chunks/chunk-PZE3GABA.js.map +7 -0
- package/dist/chunks/{chunk-ZKLOV6MW.js → chunk-SYHZ5T54.js} +2 -2
- package/dist/chunks/{chunk-ZKLOV6MW.js.map → chunk-SYHZ5T54.js.map} +1 -1
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +4 -4
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
- package/package.json +2 -3
- package/src/GraphGenomeView/pane/hostViews.ts +1 -1
- package/src/GraphGenomeView/pane/paneBase.ts +1 -1
- package/src/GraphGenomeView/renderer/GraphRenderer.ts +2 -2
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-LZUNK4MQ.js +0 -2
- package/dist/chunks/chunk-LZUNK4MQ.js.map +0 -7
- /package/dist/chunks/{GraphGenomeView-5OPCROMQ.js.map → GraphGenomeView-6CRBLHNG.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-FGLLUIEE.js.map → GraphTrackSettingsDialog-2QQYWNWW.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-NBJHGOYX.js.map → LinearGraphDisplay-KNEXJAAV.js.map} +0 -0
- /package/dist/chunks/{MinigraphBubbleAdapter-LQUIL3MD.js.map → MinigraphBubbleAdapter-MQRO5J7Z.js.map} +0 -0
- /package/dist/chunks/{RgfaTabixAdapter-3BFNY4SB.js.map → RgfaTabixAdapter-ALEXRTPS.js.map} +0 -0
- /package/dist/chunks/{chunk-O5EHYU3Y.js.map → chunk-4F2MWXJF.js.map} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{A as $t,B as Bt,C as st,D as te,J as zn,K as Un,L as Xt,M as Dt,P as Kn,Q as jn,Y as Vn,Z as at,a as I,b as Bn,c as fe,d as Xn,e as Dn,f as ot,h as Fn,i as Wn,j as He,k as rt,l as Ye,m as Ae,n as qn,o as Hn,p as Yn,t as Gn,x as Pt,y as Le,z as ee}from"./chunk-CJ47OHWP.js";import{d as Qn}from"./chunk-3MJ4ZXML.js";import{c as $n}from"./chunk-ETTZTJNK.js";import{a as nt,b as Ne,c as A,d as We,e as ce,f as Tt,g as le,j as qe}from"./chunk-5GRQIE5Q.js";import{a as et,c as Pn,d as tt}from"./chunk-C4PHHPUP.js";import{a as Je}from"./chunk-TYJTJGPO.js";import{a as Ct,b as _e}from"./chunk-FY3BTKY4.js";var Jn=Ct((yf,Zn)=>{Zn.exports=JBrowseExports["@mui/material/SvgIcon"]});var Ya=Ct((cu,Fo)=>{Fo.exports=JBrowseExports.mobx});var Yr=Ct((Vh,Hr)=>{Hr.exports=JBrowseExports["@jbrowse/core/util/groupKeys"]});var K=_e(Jn(),1);function O(e,t,n,s){return(s<<24|n<<16|t<<8|e)>>>0}function Ft(e){return e&255}function Wt(e){return e>>>8&255}function qt(e){return e>>>16&255}function Ht(e){return e>>>24&255}function j(e){return`rgba(${Ft(e)},${Wt(e)},${qt(e)},${Ht(e)/255})`}function eo(e,t){return`rgba(${Math.round(e[0]*255)},${Math.round(e[1]*255)},${Math.round(e[2]*255)},${t})`}function ke(e,t){return O(Ft(e),Wt(e),qt(e),Math.round(Ht(e)*t))}function it(e,t){return O(Math.min(255,Math.round(Ft(e)*t)),Math.min(255,Math.round(Wt(e)*t)),Math.min(255,Math.round(qt(e)*t)),Ht(e))}var to=new WeakMap;function ct(e,t,n,s,o,r,a=!1){let{scaleX:i,scaleY:c}=n,l=to.get(e);if(l?.graph===t&&l.scaleX===i&&l.scaleY===c&&l.deletions===s&&l.routes===r&&l.stranded===a&&l.version===o)return l.curves;let d=new Map;for(let f=0;f<t.edges.length;f++){let u=t.edges[f],m=e[u.from],p=e[u.to];if(m?.length&&p?.length){let h=s?.get(f),g=h&&r?.[f];d.set(f,g?Yn(m,p,g,a?rt(u):void 0):Hn(m,p,qn(u,a),0,0,n,h?Gn(e,h):[]))}}return to.set(e,{graph:t,scaleX:i,scaleY:c,deletions:s,routes:r,stranded:a,version:o,curves:d}),d}var Ds=4;function Ge(e){let t=new Map;function n(s,o){let r=t.get(s);r?r.push(o):t.set(s,[o])}for(let s of e.edges)n(s.from,s.to),n(s.to,s.from);return t}function Fs({nodeId:e,nodeById:t,neighbors:n}){let s=new Set([e]),o=[e],r=1/0,a=-1/0;for(let i=0;i<Ds&&o.length>0;i++){let c=[];for(let l of o){let d=n.get(l);if(d){for(let f of d)if(!s.has(f)){s.add(f);let u=t.get(f);u&&A(u)?(r=Math.min(r,u.stable.start+u.length),a=Math.max(a,u.stable.start)):c.push(f)}}}o=c}return r===1/0?void 0:{start:Math.min(r,a),end:Math.max(r,a)}}function Ws({nodeId:e,nodeById:t,neighbors:n}){let s=t.get(e);return s===void 0?void 0:A(s)?{start:s.stable.start,end:s.stable.start+s.length}:Fs({nodeId:e,nodeById:t,neighbors:n})}function no(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=Ge(e),s=new Map;for(let o of e.nodes){let r=Ws({nodeId:o.id,nodeById:t,neighbors:n});r&&s.set(o.id,(r.start+r.end)/2)}return s}var qs=O(119,119,119,217),oo=O(136,136,136,217),Hs=O(24,24,28,240),Ys=2.2,Kt=O(160,160,160,255),Oe=.18,ft=j(ke(Kt,Oe)),Gs=11,zs=1.2,ro=4,Yt=1e-6,Us=7,Ks=3,js=3,Vs=1.5,so=3,Qs=.5,Zs=.45,Gt=12,Js=1e-6,ne=new Float64Array(64),de=new Float64Array(64),ue=new Float64Array(64);function ea(e,t,n,s){let o=e.length*Gt+1;ne.length<o&&(ne=new Float64Array(o),de=new Float64Array(o),ue=new Float64Array(o));let r=e[e.length-1];ne[0]=r.x1,de[0]=r.y1,ue[0]=0;let a=1,i=0;for(let c=e.length-1;c>=0&&i<s;c--){let l=e[c];for(let d=1;d<=Gt&&i<s;d++){let f=1-(d/Gt)**2,u=1-f,m=u*u*u,p=3*u*u*f,h=3*u*f*f,g=f*f*f,x=m*l.x0+p*l.cx0+h*l.cx1+g*l.x1,b=m*l.y0+p*l.cy0+h*l.cy1+g*l.y1;i+=Math.hypot(x-ne[a-1],(b-de[a-1])*n)*t,ne[a]=x,de[a]=b,ue[a]=i,a++}}return a}function ao(e,t){let n=1;for(;n<e-1&&ue[n]<t;)n++;let s=ue[n-1],o=ue[n],r=o>s?Math.min(1,Math.max(0,(t-s)/(o-s))):0;return{x:ne[n-1]+(ne[n]-ne[n-1])*r,y:de[n-1]+(de[n]-de[n-1])*r}}function ta({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:s,yToX:o,color:r,fromSegments:a,toSegments:i}){let c=Us+Ks*t,l=ea(e,s,o,n+so*c),d=ue[l-1],f=d<Js,u=Math.min(n,d),m=f?Math.min(1,na(a,s,o)/c):1;if(f?m<Qs:d<so*c)return;let p=ao(l,u),h=ao(l,u+c*m),g=p.x-h.x,x=(p.y-h.y)*o,b=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,x)>0?Math.atan2(x,g):ho(b,o,ra(b,i)),length:c*m,halfWidth:(js+Vs*t)*m,color:r}}function na(e,t,n){let s=0;for(let o=1;o<e.length;o++)s+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*n);return s*t}function oa(e,t,n,s,o){if(s)return rt(e).from==="start";let r=a=>Math.hypot(a.x-n.x0,(a.y-n.y0)*o);return r(t[0])<r(t.at(-1))}function ra(e,t){if(t.length<2)return;let n=t[0],s=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-s.x,e.y1-s.y)?{from:n,to:t[1]}:{from:s,to:t[t.length-2]}}function zt(e,t=1){let n=t===1?e:e.map(o=>({x:o.x,y:o.y*t})),s=[];for(let o=0;o<n.length;o++){let r=0,a=0;if(o===0){let i=n[1].x-n[0].x,c=n[1].y-n[0].y,l=Math.hypot(i,c);l>0&&(r=-c/l,a=i/l)}else if(o===n.length-1){let i=n[o].x-n[o-1].x,c=n[o].y-n[o-1].y,l=Math.hypot(i,c);l>0&&(r=-c/l,a=i/l)}else{let i=n[o].x-n[o-1].x,c=n[o].y-n[o-1].y,l=Math.hypot(i,c),d=n[o+1].x-n[o].x,f=n[o+1].y-n[o].y,u=Math.hypot(d,f);if(l>0&&u>0){let m=-c/l,p=i/l,h=-f/u,g=d/u;r=(m+h)/2,a=(p+g)/2;let x=m*r+p*a;x>.1&&(r/=x,a/=x)}else l>0?(r=-c/l,a=i/l):u>0&&(r=-f/u,a=d/u)}s.push({nx:r,ny:a})}return s}function io(e,t,n,s=1){return e.map((o,r)=>({x:o.x+t[r].nx*n,y:o.y+t[r].ny*n/s}))}function lt(e,t,n,s){return O(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(s*255))}function he(e,t,n){let s=(1-Math.abs(2*n-1))*t,o=s*(1-Math.abs(e/60%2-1)),r=n-s/2,a=0,i=0,c=0;return e<60?(a=s,i=o):e<120?(a=o,i=s):e<180?(i=s,c=o):e<240?(i=o,c=s):e<300?(a=o,c=s):(a=s,c=o),[a+r,i+r,c+r]}var sa=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],aa=[[237,137,44],[158,42,122]],ia=[[220,50,50],[50,120,220]];function Ut(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),s=Math.min(e.length-2,Math.floor(n)),o=n-s,r=e[s],a=e[s+1];return O(Math.round(r[0]+(a[0]-r[0])*o),Math.round(r[1]+(a[1]-r[1])*o),Math.round(r[2]+(a[2]-r[2])*o),255)}function ca(e,t){let[n,s,o]=he(zn(e),Xt,Dt);return lt(n,s,o,t)}var pe=300,la=.7,fa=.5,uo=[60,65,72],dt=O(...uo,255),ut=`rgb(${uo.join(", ")})`;function da(e,t){let n=no(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let s=1/0,o=-1/0;for(let r of n.values())s=Math.min(s,r),o=Math.max(o,r);return{start:s===1/0?0:s,span:o>s?o-s:1,midpoints:n}}function ht(e){let t=1/0,n=-1/0,s=1/0,o=-1/0,r=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>r&&(r=a.stable.rank),a.depth<t&&(t=a.depth),a.depth>n&&(n=a.depth),a.length<s&&(s=a.length),a.length>o&&(o=a.length);return{minDepth:t,maxDepth:n,minLength:s,maxLength:o,maxRank:r,nodeCount:e.nodes.length}}function pt(e,t,n,s){switch(n){case"random":return ca(e.id,1);case"depth":return Ut(sa,s.maxDepth>s.minDepth?(e.depth-s.minDepth)/(s.maxDepth-s.minDepth):.5);case"node-length":return Ut(ia,s.maxLength>s.minLength?(e.length-s.minLength)/(s.maxLength-s.minLength):.5);case"stable-rank":return e.stable===void 0?O(160,160,160,255):e.stable.rank===0?O(52,152,219,255):Ut(aa,s.maxRank>1?(e.stable.rank-1)/(s.maxRank-1):0);case"reference-position":{let o=s.referenceRamp,r=o?.midpoints.get(e.id);if(o===void 0||r===void 0)return O(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return dt;let a=Math.max(0,Math.min(1,(r-o.start)/o.span)),[i,c,l]=he(a*pe,la,fa);return lt(i,c,l,1)}case"grey":return O(160,160,160,255);case"rainbow":{let o=s.nodeCount>1?t/s.nodeCount*360:0,[r,a,i]=he(o,.75,.5);return lt(r,a,i,1)}default:return O(52,152,219,255)}}function ho(e,t=1,n){let s=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,r]of s){let a=e.x1-o,i=(e.y1-r)*t;if(Math.hypot(a,i)>0)return Math.atan2(i,a)}return n?Math.atan2((n.to.y-n.from.y)*t,n.to.x-n.from.x):0}function ua(e,t){let n=!1;for(let s=0;s<e.length-1&&!n;s++){let o=e[s],r=e[s+1];n=Math.max(o.x,r.x)>=t.minX&&Math.min(o.x,r.x)<=t.maxX&&Math.max(o.y,r.y)>=t.minY&&Math.min(o.y,r.y)<=t.maxY}return n}function co(e,t){for(let n of e){let s=Math.min(n.x0,n.cx0,n.cx1,n.x1),o=Math.max(n.x0,n.cx0,n.cx1,n.x1),r=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&&s<=t.maxX&&a>=t.minY&&r<=t.maxY)return!0}return!1}var lo=new WeakMap;function ha(e){let t=lo.get(e);if(!t){let n=[],s=new Map,o=e.paths??[];for(let r=0;r<o.length;r++){let[a,i,c]=he(Un(r,o.length),Xt,Dt);n.push(lt(a,i,c,.85)),s.has(o[r].name)||s.set(o[r].name,r)}t={pathColorByIndex:n,pathIndexByName:s},lo.set(e,t)}return t}var fo=new WeakMap,pa=new Map;function ma(e){let t=fo.get(e);if(!t){t=new Map;for(let[n,s]of(e.paths??[]).entries())for(let o of new Set(s.nodeIds)){let r=t.get(o);r?r.push(n):t.set(o,[n])}fo.set(e,t)}return t}function ga(e){let{nodePositions:t,graph:n,nodeById:s,colorScheme:o,contigThickness:r,connectorThickness:a,drawPaths:i,nodeWidth:c="uniform",highlight:l,axis:d,linearLayout:f,viewportBounds:u,referenceRamp:m,deletions:p,deletionRoutes:h,stranded:g,hiddenEdges:x,version:b=0}=e,w=c==="depth"?Vn(n):0,y=d.scaleX,v=Ye(d),M=ct(t,n,d,p,b,h,g),E=[],S=new Map,R=[],C=new Map,k=[],Q=new Map,xe={...ht(n),referenceRamp:m},W=new Map;if(o==="rainbow")for(let N=0;N<n.nodes.length;N++)W.set(n.nodes[N].id,N);let T=n.paths?.length??0,{pathColorByIndex:q,pathIndexByName:X}=ha(n),D=N=>q[X.get(N)??-1]??oo,be=i&&T>1?ma(n):pa,$e=y>(f?1:Zs);for(let N=0;N<n.edges.length;N++){let L=n.edges[N],H=t[L.from],Z=t[L.to],Y=M.get(N);if(!H?.length||!Z?.length||!Y||x?.has(N))continue;let ye=L.pathIds?.length??0,Be=p?.get(N)!==void 0,Xe=l?.edgeIndexes.has(N)??!1,Me=a/2*(Be?Ys:1),we=i&&ye>0,se=Be?Hs:qs,G=!l||Xe?se:ke(se,Oe),De=s.get(L.to),ve=(De?at(De,r,c,w):r)/2,Ee=(ie,Re,P,J)=>{let U=ie===0&&Re===0?Y:He(Y,ie,Re);if(u&&!co(U,u))return;if(Be)for(let kt of Wn(U,Gs/y))k.push({curves:kt,thickness:Me,color:P});else k.push({curves:U,thickness:Me,color:P});let Ze=$e&&J!==void 0?ta({curves:U,edgeHalfWidth:a/2,nodeHalfWidth:ve,scale:y,yToX:v,color:J,fromSegments:H,toSegments:Z}):void 0;Ze&&R.push(Ze)},ae=k.length,Se=R.length,z=l&&Xe&&!we?l.walks:void 0;if(z){let ie=s.get(L.from),Re=ie?at(ie,r,c,w):r,P=Math.max(Re/z.length,ro),J=zt(H,v),{nx:U,ny:Ze}=(oa(L,H,Y[0],g,v)?J[0]:J.at(-1))??{nx:0,ny:0},kt=1/Math.max(y,Yt);z.forEach((Ot,Xs)=>{if(!Ot.edgeIndexes.has(N))return;let It=(Xs-(z.length-1)/2)*P*kt,Tn=It===0?Y:He(Y,U*It,Ze*It/v);u&&!co(Tn,u)||k.push({curves:Tn,thickness:P/2,color:Ot.colors.get(L.from)??Ot.colors.get(L.to)??se})})}else if(!we)Ee(0,0,G,G);else{let ie=Ae(H,Z,ye,d),Re=Math.floor((ye-1)/2);for(let P=0;P<ye;P++){let J=ie[P],U=D(L.pathIds[P]);Ee(J.x,J.y,l&&!l.names.has(L.pathIds[P])?ke(U,Oe):U,P===Re?G:void 0)}}let Fe=k.length-ae;Fe>0&&Q.set(N,{start:ae,count:Fe});let Qe=R.length-Se;Qe>0&&C.set(N,{start:Se,count:Qe})}for(let[N,L]of Object.entries(t)){let H=s.get(N);if(!H||u&&!ua(L,u))continue;let Z=l!==void 0&&!l.nodeIds.has(N),Y=Z?Kt:pt(H,W.get(N)??0,o,xe),ye=Z?ke(Y,Oe):Y,Ve=at(H,r,c,w),Be=Ve/2,Xe=E.length,Me=be.get(N),we=Ve/T,se=L.length>=2,G=l&&!Z&&!Me?.length?l.walks:void 0;if(se&&G){let ve=Math.max(Ve/G.length,ro),Ee=zt(L,v),ae=1/Math.max(y,Yt);G.forEach((Se,z)=>{let Fe=Se.colors.get(N);if(Fe===void 0)return;let Qe=(z-(G.length-1)/2)*ve*ae;E.push({points:G.length===1?L:io(L,Ee,Qe,v),thickness:ve/2,color:Fe})})}else if(se&&Me?.length&&we>=zs){let ve=zt(L,v),Ee=1/Math.max(y,Yt);for(let ae of Me){let Se=(ae-(T-1)/2)*we*Ee,z=q[ae]??oo;E.push({points:io(L,ve,Se,v),thickness:we/2,color:Z?ke(z,Oe):z})}}else se&&E.push({points:L,thickness:Be,color:ye});let De=E.length-Xe;De>0&&S.set(N,{start:Xe,count:De})}return{nodeStrokes:E,nodeStrokeRuns:S,arrows:R,arrowRuns:C,edgeCurves:k,edgeCurveRuns:Q}}function mt(e){return`hsl(${e}, 70%, 50%)`}function jt(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*pe}var xa=30;function po({start:e,bp:t,reversed:n},s){let o=jt(e,s),r=jt(e+t,s);if(r-o<1)return[(o+r)/2];let a=Math.ceil((r-o)/xa);return Array.from({length:a+1},(i,c)=>jt(e+t*(n?a-c:c)/a,s))}var Vt=Array.from({length:7},(e,t)=>({offset:t/6,color:mt(t/6*pe)})),mo=`linear-gradient(to right, ${Vt.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function _(e,t={},...n){return{tag:e,attrs:t,children:n.filter(s=>!!s||s==="")}}function go(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function ba(e){return go(e).replaceAll('"',""")}function ya(e){if(typeof e=="string")return go(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,s])=>` ${n}="${ba(String(s))}"`).join("");return`<${e.tag}${t}>${e.children.map(ya).join("")}</${e.tag}>`}var Ma="#daa520",wa=1,va=2,Ea=4;function Xf(e,t,n,s=o=>o){let o=r=>{let a=t(r)*2;return n?.nodeIds.has(r)?Math.max(a,n.walks.length*Ea):a};return e.flatMap(r=>r.exonsByNode.map(({nodeId:a,d:i})=>({key:`${r.gene.name}-${r.gene.start}-${a}`,d:s(i),inner:o(a)+2*wa})))}function Df(e,t){if(e.length===0)return;let n=(s,o,r)=>_("path",{d:s.d,fill:"none",stroke:o,"stroke-width":r,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return _("g",{},_("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},_("g",{transform:t.transform},...e.map(s=>n(s,"#fff",s.inner+2*va)),...e.map(s=>n(s,"#000",s.inner)))),_("rect",{width:t.width,height:t.height,fill:Ma,mask:`url(#${t.id})`}))}var Sa=50;function xo(e,t){return t>0?Math.max(1,e/t):Sa}function Ra(e){let t=new Set,n=1/0,s=-1/0;for(let o of e)t.add(o.minY),n=Math.min(n,o.minY),s=Math.max(s,o.minY);return t.size>1?(s-n)/(t.size-1):void 0}function _a(e,t,n){let s=xo(t,e.length);return{x:s,y:n>0?xo(n,e.length):Ra(e)??s}}function bo(e,t,n,s){return e===void 0?_a(t,n,s):typeof e=="number"?{x:e,y:e}:e}function Na(e,t,n){let s=e.get(t);s||(s=new Map,e.set(t,s));let o=s.get(n);return o||(o=[],s.set(n,o)),o}function yo(e,t,n,s,o,r,a){let i=Math.floor(n/t.x),c=Math.floor(o/t.x),l=Math.floor(s/t.y),d=Math.floor(r/t.y);for(let f=i;f<=c;f++)for(let u=l;u<=d;u++)Na(e,f,u).push(a)}function Mo(e,t,n,s,o,r){let a=Math.floor((n-o)/t.x),i=Math.floor((n+o)/t.x),c=Math.floor((s-r)/t.y),l=Math.floor((s+r)/t.y),d=[],f=new Set;for(let u=a;u<=i;u++){let m=e.get(u);if(m)for(let p=c;p<=l;p++){let h=m.get(p);if(h)for(let g of h)f.has(g)||(f.add(g),d.push(g))}}return d}var wo=class{constructor(e,t){this.cells=new Map;let n=[],s=0,o=0;for(let[r,a]of Object.entries(e))for(let i=0;i<a.length-1;i++){let c=a[i],l=a[i+1],d=Math.min(c.x,l.x),f=Math.min(c.y,l.y),u=Math.max(c.x,l.x),m=Math.max(c.y,l.y);s+=u-d,o+=m-f,n.push({entry:{nodeId:r,segmentIdx:i},minX:d,minY:f,maxX:u,maxY:m})}this.cellSize=bo(t,n,s,o);for(let r of n)yo(this.cells,this.cellSize,r.minX,r.minY,r.maxX,r.maxY,r.entry)}query(e,t,n,s=n){return Mo(this.cells,this.cellSize,e,t,n,s)}},vo=class{constructor(e,t,n,s,o,r,a=0,i,c=!1){this.cells=new Map,this.edgeCurves=ct(e,t,s,r,a,i,c);let l=[],d=0,f=0;for(let u=0;u<t.edges.length;u++){let m=t.edges[u],p=e[m.from],h=e[m.to],g=this.edgeCurves.get(u);if(p?.length&&h?.length&&g){let{minX:x,minY:b,maxX:w,maxY:y}=Fn(g),v=m.pathIds?.length??0;if(n&&v>0){let M=0,E=0;for(let S of Ae(p,h,v,s))M=Math.max(M,Math.abs(S.x)),E=Math.max(E,Math.abs(S.y));x-=M,b-=E,w+=M,y+=E}d+=w-x,f+=y-b,l.push({ei:u,minX:x,minY:b,maxX:w,maxY:y})}}this.cellSize=bo(o,l,d,f);for(let u of l)yo(this.cells,this.cellSize,u.minX,u.minY,u.maxX,u.maxY,u.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,s=n){return Mo(this.cells,this.cellSize,e,t,n,s)}};function _o(e,t,n,s,o,r){let a=o-n,i=r-s,c=a*a+i*i;if(c===0)return Math.hypot(e-n,t-s);let l=Math.max(0,Math.min(1,((e-n)*a+(t-s)*i)/c));return Math.hypot(e-(n+l*a),t-(s+l*i))}function Aa(e,t,n,s,o,r,a,i,c,l){let d=1/0,f=20,u=n,m=s;for(let p=1;p<=f;p++){let h=p/f,g=1-h,x=g*g*g*n+3*g*g*h*o+3*g*h*h*a+h*h*h*c,b=g*g*g*s+3*g*g*h*r+3*g*h*h*i+h*h*h*l;d=Math.min(d,_o(e,t,u,m,x,b)),u=x,m=b}return d}function La(e,t,n){return Aa(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function Eo(e,t,n,s=1){let o=1/0;for(let r of n){let a=La(e,t,s===1?r:{x0:r.x0,y0:r.y0*s,cx0:r.cx0,cy0:r.cy0*s,cx1:r.cx1,cy1:r.cy1*s,x1:r.x1,y1:r.y1*s});a<o&&(o=a)}return o}var So=new WeakMap;function No(e,t){let n=So.get(e);if(n?.version===t)return n.index;let s=new wo(e);return So.set(e,{version:t,index:s}),s}var Ro=new WeakMap;function ka(e,t,n,s,o,r,a,i=!1){let c=Ro.get(e);if(c?.graph===t&&c.drawPaths===n&&c.scaleX===s.scaleX&&c.scaleY===s.scaleY&&c.version===o&&c.deletions===r&&c.routes===a&&c.stranded===i)return c.index;let l=new vo(e,t,n,s,void 0,r,o,a,i);return Ro.set(e,{graph:t,drawPaths:n,scaleX:s.scaleX,scaleY:s.scaleY,version:o,index:l,deletions:r,routes:a,stranded:i}),l}var Oa=5;function Kf(e,t,n,s,o=0,r){let a=Ye(s),i=No(e,o),c=m=>Math.max(Oa,m)/s.scaleX,l=c(r?.maxHalfWidthPx??0),d=i.query(t,n,l,l/a),f=null,u=1/0;for(let{nodeId:m,segmentIdx:p}of d){let h=e[m],g=_o(t,n*a,h[p].x,h[p].y*a,h[p+1].x,h[p+1].y*a);g<u&&g<c(r?.halfWidthPx(m)??0)&&(u=g,f=m)}return f}function Ia(e,t,n){let s=t.x-e.x,o=t.y-e.y,r=0,a=1;for(let[i,c]of[[-s,e.x-n.x0],[s,n.x1-e.x],[-o,e.y-n.y0],[o,n.y1-e.y]])if(i===0){if(c<0)return!1}else i<0?r=Math.max(r,c/i):a=Math.min(a,c/i);return r<=a}function Ao(e,t,n=0){let s=No(e,n),o=r=>({x:r.x*t.scaleX+t.translateX,y:r.y*t.scaleY+t.translateY});return r=>{let a=new Set,i=s.query(((r.x0+r.x1)/2-t.translateX)/t.scaleX,((r.y0+r.y1)/2-t.translateY)/t.scaleY,Math.abs((r.x1-r.x0)/2/t.scaleX),Math.abs((r.y1-r.y0)/2/t.scaleY));for(let{nodeId:c,segmentIdx:l}of i){let d=e[c];!a.has(c)&&Ia(o(d[l]),o(d[l+1]),r)&&a.add(c)}return a}}function jf(e,t,n,s,o,r,a=0,i,c,l,d=!1){let f=Ye(o),u=10/o.scaleX,m=ka(e,t,r,o,a,i,l,d),p=m.query(n,s,u,u/f),h=null,g=u;for(let x of p){let b=t.edges[x],w=e[b.from],y=e[b.to];if(!w?.length||!y?.length||c?.has(x))continue;let v=b.pathIds?.length??0,M=m.getCurves(x);if(!M)continue;let E;if(!r||v===0)E=Eo(n,s*f,M,f);else{let S=1/0;for(let R of Ae(w,y,v,o)){let C=R.x===0&&R.y===0?M:He(M,R.x,R.y),k=Eo(n,s*f,C,f);k<S&&(S=k)}E=S}E<g&&(g=E,h=x)}return h}var Lo=3.4,Qt=6,Ca=8,Ta=18,Pa=2,$a=Bn+Xn;function ko(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,s]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],o=r=>+(r/n).toFixed(n===1?0:1);return`${o(e.covered*t)} of ${o(t)} ${s}`}function Oo(e,t,n,s){let o=n/2;return Io(e,r=>r.gene.end-r.gene.start).map(r=>{let{x:a,y:i}=t(r.at),c=ko(r);return{item:r,x:a,y:i+n+Ta,text:c?`${r.gene.name} \xB7 ${c}`:r.gene.name,fallback:c?`${r.gene.name} \u2026`:void 0,stack:Pa,fits:l=>[...s({x0:l.x0-o,x1:l.x1+o,y0:l.y0-o,y1:l.y1+o})].every(d=>r.nodeIds.has(d))}})}function Io(e,t){return[...e].sort((n,s)=>t(s)-t(n))}function Ba(e){let{paneWidth:t,canvasHeight:n,translateX:s,translateY:o}=e,{scaleX:r,scaleY:a}=e.axisScale,i={width:t,height:n},c=M=>({x:M.x*r+s,y:M.y*a+o}),l=e.drawnRowLabels.map(({label:M,y:E})=>Pt(M,E*a+o)),d=e.referenceStripZonePx??0;d>0&&l.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&l.push({x0:t-Qt-e.legendSize.width,x1:t,y0:0,y1:d+Qt+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*fe*1.2,y0:0,y1:44});let f=Dn(i,l),u=e.drawnRowLabels.length>0,m=u?Math.min(...e.drawnRowLabels.map(M=>M.y)):1/0,p=e.contigThickness*Lo,h=Io(e.bubbleHalos,M=>M.members),g=ot(h.map(M=>{let{x:E,y:S}=c({x:M.labelAt.x,y:Math.min(M.labelAt.y,m)}),R=S-p/2-6;return{item:M,x:E,y:u?Math.max(R,$a):R,text:M.label}}),i,f),x=ot(Oo(e.genePins,c,e.contigThickness,Ao(e.nodePositions??{},{scaleX:r,scaleY:a,translateX:s,translateY:o},e.positionsVersion)),i,f),b=e.nodePositions&&e.labelsNodeSizes?$t({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:s,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},w=st(b.deletions,f),y=ot(h.flatMap(M=>M.routes.map(E=>{let{x:S,y:R}=c(E.at);return{item:{halo:M,route:E},x:S,y:R+4,text:E.text,stack:Ca}})),i,f),v=st(b.nodes,f,Bt(t,n));return{bubbles:g,genes:x,routes:y,sizes:[...w,...v]}}function Yd(e){return Ne(e)?Co(e):void 0}function Co(e){return{sample:et(e.stable.refName),haplotype:Pn(e.stable.refName),refName:tt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Xa(e,t){let n=[...e].sort((r,a)=>r.start-a.start),s,o;for(let r of n)o=o&&r.start-o.end<=t?{start:o.start,end:Math.max(o.end,r.end)}:{start:r.start,end:r.end},(!s||o.end-o.start>s.end-s.start)&&(s=o);return s}function Da(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Gd(e,{maxGap:t=1/0}={}){let n=new Map;for(let o of e.nodes)if(Ne(o)){let r=Co(o),a=Da(r),i=n.get(a);i?(i.spans.push({start:r.start,end:r.end}),i.rank=Math.min(i.rank,o.stable.rank)):n.set(a,{sample:r.sample,haplotype:r.haplotype,refName:r.refName,rank:o.stable.rank,spans:[{start:r.start,end:r.end}]})}let s=new Map;for(let o of n.values()){let r=Xa(o.spans,t);if(r){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:r.start,end:r.end,rank:o.rank,nodeCount:o.spans.length},i=o.haplotype??o.sample,c=s.get(i);(!c||a.nodeCount>c.nodeCount)&&s.set(i,a)}}return[...s.values()].sort((o,r)=>+(o.rank!==0)-+(r.rank!==0)||o.sample.localeCompare(r.sample)||(o.haplotype??"").localeCompare(r.haplotype??""))}function Fa(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function zd(e,t){return e.flatMap(n=>{let s=Fa(t,n);return s===void 0?[]:[{...n,sample:s}]})}function Ud(e){return`${e.refName}:${e.start+1}-${e.end}`}function Zt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var To=_e(Je(),1),Po=(0,K.createSvgIcon)((0,To.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var $o=_e(Je(),1),Bo=(0,K.createSvgIcon)((0,$o.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 Xo=_e(Je(),1),Jt=(0,K.createSvgIcon)((0,Xo.jsx)("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var Wa="Linear genome view",qa="Linear synteny view",Ha="No synteny track in this session aligns these assemblies";function Do({label:e,icon:t,entries:n,entryLabel:s,onSelect:o,disabledHelpText:r,nameTheOnlyEntry:a=!0}){let[i]=n,c=r?[{label:e,icon:t,disabled:!0,disabledHelpText:r,onClick:()=>{}}]:[];return n.length===0?c:n.length===1&&i?[{label:a?`${e} \u2014 ${s(i)}`:e,icon:t,onClick:o(i)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(l=>({label:s(l),onClick:o(l)}))}]}function su({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:s}){let o=t[0]?.coverage??e.length;return[...Do({label:Wa,icon:Jt,entries:e,entryLabel:r=>`${r.sample} ${Zt(r)}`,onSelect:r=>()=>{n({location:r,assembly:r.sample})}}),...e.length>=2?Do({label:`${qa} (${o} assemblies)`,icon:Po,entries:t,entryLabel:r=>r.coverage<o?`${r.name} (${r.coverage} of ${o})`:r.name,nameTheOnlyEntry:!1,disabledHelpText:Ha,onSelect:r=>()=>{s(r.trackId)}}):[]]}function au({own:e,reference:t,highlight:n,onShowLinear:s,onHighlight:o}){let r=[e?{label:`Open in ${e.assembly} \u2014 ${Zt(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...o&&n?[{label:`Highlight in ${n.assembly}`,icon:Bo,onClick:()=>{o(n)}}]:[],...r.map(({label:a,target:i})=>({label:a,icon:Jt,onClick:()=>{s(i)}}))]}function en(e){return e.id.endsWith("-")?"-":"+"}function tn(e,t){return t===en(e)?e.id:`-${e.id}`}function Ga(e,t){let n=e.map(()=>{}),s=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=s,s+=e[o];let r=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)r-=e[a],n[a]=r;return n}function za(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let s=Ga(t,e.pathLength),o=(i,c=!1)=>{for(let l=0;l<s.length;l++){let d=s[l],f=t[l];if(d!==void 0&&f!==void 0&&d<=i&&(i<d+f||c&&i===d+f))return{s:l,local:i-d,room:d+f-i}}},r=(i,c)=>{let l=n[i],d=l.at(-1);c.type==="substitution"&&d?.type==="substitution"&&d.pos+d.seq.length===c.pos?d.seq+=c.seq:l.push(c)},a=e.pathStart;for(let i of $n(e.cs))if(i.op==="match")a+=i.length;else if(i.op==="substitution"){let c=o(a);c&&r(c.s,{type:"substitution",pos:c.local,seq:i.seq}),a+=1}else if(i.op==="insertion"){let c=o(a,a===e.pathEnd);c&&r(c.s,{type:"insertion",pos:c.local,seq:i.seq})}else{let c=i.length;for(;c>0;){let l=o(a),d=l?Math.min(c,l.room):c;l&&r(l.s,{type:"deletion",pos:l.local,length:d}),a+=d,c-=d}}return n}function Wo(e,t,n){let s=new Map(e.nodes.map(r=>[r.name,r])),o=[];for(let r of t){let a=r.path.map(d=>s.get(d.name)),i=a.flatMap((d,f)=>d?[f]:[]),c=i[0],l=i.at(-1);if(c!==void 0&&l!==void 0){let d=za(r,a.map(m=>m?.length)),f=i.map(m=>tn(a[m],r.path[m].strand)),u=a[l].length;o.push({id:n+o.length,name:r.name,type:"read",sourceTrackID:1,sequence:f,sequenceNew:i.map((m,p)=>({nodeName:f[p],mismatches:d[m]})),firstNodeOffset:c===0?r.pathStart:0,finalNodeCoverLength:l===r.path.length-1?u-(r.pathLength-r.pathEnd):u,mapping_quality:r.mappingQuality===255?0:r.mappingQuality,is_secondary:r.secondary,is_reverse:r.strand==="-"})}}return o}var Ua=["#6baed6","#4292c6","#2171b5","#08519c"],Ka=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function qo(e){let t=e.is_reverse?Ka:Ua;return t[e.id%t.length]}function gt(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 ja(e,t,n,s){let o=[],r=[],a=[e];for(s.add(e);a.length>0;){let i=a.pop(),c=t.get(i);if(c){o.push(c);for(let l of n.get(i)??[]){let d=t.get(l);d&&(d.stable.rank===nt?r.push(d):s.has(l)||(s.add(l),a.push(l)))}}}return{members:o,anchors:r}}function Va(e){if(new Set(e.map(i=>i.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((i,c)=>i.stable.start-c.stable.start),s=n[0],o=n.at(-1),r=s.stable.start+s.length,a=o.stable.start;return a>=r?{start:r,end:a,entry:s}:void 0}function Qa(e,t,n){let s=new Map(e.map(a=>[a.id,a])),o=new Map,r=[];for(let a of n.get(t.id)??[])s.has(a)&&(o.set(a,0),r.push(a));if(r.length===0)for(let a of e)o.set(a.id,0),r.push(a.id);for(let a of r){let i=o.get(a)+s.get(a).length;for(let c of n.get(a)??[])if(s.has(c)){let l=o.get(c);(l===void 0||i<l)&&(o.set(c,i),r.push(c))}}return o}function Za(e,t,n){let s=Qa(e,t,n),o=[...e].sort((c,l)=>s.get(c.id)-s.get(l.id)),r=new Map(o.map((c,l)=>[c.id,l])),a=new Map(e.map(c=>[c.id,c])),i=new Map;for(let[c,l]of o.entries()){let d=0;for(let f of n.get(l.id)??[]){let u=a.get(f);u&&r.get(f)<c&&(d=Math.max(d,i.get(f)+u.length))}i.set(l.id,d)}return{offsets:i,ordered:o}}function Ho(e){let t=new Map(e.nodes.filter(Ne).map(r=>[r.id,r])),n=Ge(e),s=new Set,o=[];for(let r of t.values())if(r.stable.rank!==nt&&!s.has(r.id)){let{members:a,anchors:i}=ja(r.id,t,n,s),c=Va(i);if(c){let{offsets:l,ordered:d}=Za(a,c.entry,n);o.push({start:c.start,refSpan:c.end-c.start,nodeIds:d.map(f=>f.id),nodeOffsets:d.map(f=>l.get(f.id)),pathLength:d.reduce((f,u)=>Math.max(f,l.get(u.id)+u.length),0)})}}return o.sort((r,a)=>r.start-a.start)}var Ja=1,ei=.015;function xt({graph:e,span:t,rowY:n,positions:s}){let o=t*ei,r=Ho(e),a=new Map(e.nodes.map(d=>[d.id,d])),i=[];for(let d of r){let f=d.refSpan-d.pathLength;f>=Ja&&i.push({nodeIds:d.nodeIds,bp:f});let u=Math.max(d.refSpan,o),m=d.pathLength>0?u/d.pathLength:0;d.nodeIds.forEach((p,h)=>{let g=a.get(p);if(g){let x=d.nodeOffsets[h],b=u/d.nodeIds.length,w=v=>d.start+v*m,y=n(g);s[p]=m?[{x:w(x),y},{x:w(x+g.length),y}]:[{x:d.start+h*b,y},{x:d.start+(h+1)*b,y}]}})}let c=Ge(e),l=Object.keys(s);for(let d of l){let f=s[d].at(-1).x;for(let u of c.get(d)??[]){let m=a.get(u);if(m&&!(u in s)){let p=n(m);s[u]=[{x:f,y:p},{x:f+o,y:p}],l.push(u)}}}return i}function ti(e,t){let n=new Map;for(let o of e.nodes)if(We(o)){let{sample:r}=gt(o.stable.refName);n.set(r,(n.get(r)??0)+o.length)}let s=new Map(t.map((o,r)=>[o,r]));return[...n.keys()].sort((o,r)=>(s.get(o)??1/0)-(s.get(r)??1/0)||n.get(r)-n.get(o)||o.localeCompare(r))}function Yo(e,t,n=[]){let s=ce(e),o=ti(e,n);if(s.length===0||o.length===0)return;let r=qe(s,t),a=new Map(o.map((u,m)=>[u,m+1])),i=le(s),c=o.length+1,l=xt({graph:e,span:r,rowY:u=>{let m=u.stable;return((m?a.get(gt(m.refName).sample):void 0)??c)*I},positions:i}),f=[{label:gt(s[0].stable.refName).sample,y:0},...o.map(u=>({label:u,y:a.get(u)*I}))];return{nodePositions:i,rowLabels:f,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:l}}function Go(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}var ni=new Set(["_gbwt_ref","unknown"]);function zo(e){let[t,n,s]=e?.split("#")??[];if(!(t===void 0||t===""||ni.has(t)||n===void 0||!/^\d+$/.test(n)||s===void 0||s===""))return{sample:t,haplotype:Number(n),contig:s}}var ar=!1;function Ce(...e){ar&&console.log(...e)}var oi=["read_group","sample_name"],_u=[...oi,"haplotype_sample"];function ri({layers:e,coarsenedReadView:t=!1,showReads:n=!0},s){if(e!==void 0)return e;let o=t&&n,r=a=>a?{stat:"coarsen"}:{};return[{data:"haplotypes",...r(o&&!s)},{data:"reads",...r(o&&s)}]}function Uo(e,t){return e.find(n=>n.data===t)?.stat}function si(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:ri(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15}}function ir(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:Go(),imageBounds:{minX:0,maxX:0,minY:0,maxY:0},trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function cr(e,t,n=[],s={}){let o=ai(e,t,n,s);return o&&ii(o,s)}var lr=new WeakMap;function ai(e,t,n=[],s={}){let o=li(e,t,n,s);if(o===void 0)return;let r=fr(o,o.tracks,o.reads,"measure");return r.nodes.forEach((a,i)=>{a.order>=0&&(o.nodes[i].x=a.x)}),lr.set(o,r),o}function ii(e,t={}){return ci(e,hi(e,t.facet),fi(e,t))}function ci(e,t,n,s){let o=lr.get(e);return o!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?o:fr(e,t,n,"topology",s)}function li(e,t,n,s){let o=ir(si(s,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((r,a)=>{r.seq??="",r.sequenceLength??=r.seq.length,o.nodes[a+1]=r}),o.tracks=structuredClone(t),o.reads=o.config.showReads?structuredClone(n.filter(r=>r.is_secondary!==!0)):[];for(let r=o.tracks.length-1;r>=0;r-=1){let a=o.tracks[r];if(a.type??="haplotype",a.hidden===!0){o.tracks.splice(r,1);continue}a.indexOfFirstBase!==void 0&&(o.trackForRuler=a.name)}if(o.tracks.length!==0)return mi(o,0),o.nodeMap=Qo(o),Ie(o,o.tracks),Ie(o,o.reads),rr(o),o.config.mergeNodes&&(Zo(o),on(o),rn(o),rc(o),o.nodeMap=Qo(o),rr(o),Ie(o,o.tracks),Ie(o,o.reads)),Zo(o),Bi(o),on(o),Xi(o),on(o),rn(o),Ie(o,o.reads),{options:o.config,nodes:o.nodes,tracks:o.tracks,reads:o.reads,nodeMap:o.nodeMap,maxOrder:Pi(o),trackForRuler:o.trackForRuler}}}function fi(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:s}){let o=n?new Set(n):null;return e.reads.filter(r=>(r.mapping_quality??0)>=t&&(o===null||r.name!==void 0&&o.has(r.name))&&(s===void 0||di(s,r)))}function di(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function ui(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function hi(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=ui(e);return e.tracks.filter(s=>n.has(s)||!("reads"in t)&&pi(s)===t.key)}function pi(e){return zo(e.name)?.sample??null}function fr(e,t,n,s,o={}){let r=ir(e.options);e.nodes.forEach((u,m)=>{r.nodes[m]={...u}}),r.tracks=t.map(u=>({...u})),r.reads=n.map(u=>({...u})),r.nodeMap=e.nodeMap,r.maxOrder=e.maxOrder,r.trackForRuler=e.trackForRuler;let{layers:a,ignoreStrand:i}=r.config,c=o.haplotypes??pr,l=Uo(a,"haplotypes")==="coarsen"?Ji(r,c):void 0;l!==void 0&&(r.tracks=[l.ref]),ji(r),qi(r),gi(r);let d=Uo(a,"reads")==="coarsen"&&r.reads.length>0?mr(r,r.reads,"read",o.reads??c+(l?.bands.length??0)):void 0;d!==void 0&&(r.reads=d.bands);let f={};for(let[u,m,p]of[["haplotypes","haplotype",l],["reads","read",d]])p!==void 0&&(rn(r,p.bands),Ie(r,p.bands),f[u]={unit:m,total:p.total,reverse:!i&&p.bands.some(h=>h.is_reverse)});return l!==void 0&&(r.reads=l.bands.concat(r.reads)),r.reads.length>0?(bi(r),r.tracks=r.tracks.concat(r.reads)):r.nodes.forEach(u=>{u.incomingReads=[],u.outgoingReads=[],u.internalReads=[]}),s==="measure"&&Fi(r),Zi(r),Ce("Tracks:",r.tracks),Ce("Nodes:",r.nodes),Ce("Lane assignment:",r.assignments),ki(r),{nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,shapes:r.shapes,bounds:r.imageBounds,maxOrder:r.maxOrder,trackForRuler:r.trackForRuler,coarsenedEdgeMeta:r.coarsenedEdgeMeta,coarsened:f}}function B(e){return e.startsWith("-")}function F(e){return B(e)?e.substring(1):e}function dr(e){return B(e)?e:`-${e}`}function sn(e){return B(e)?F(e):dr(e)}function Ko(e){return e>0}function mi(e,t){let n=new Set,s=new Set;for(let o of e.tracks[t].sequence)B(o)?s.has(F(o))||n.add(F(o)):s.add(o);if(n.size!==0){for(let{sequence:o}of[...e.tracks,...e.reads])for(let r=0;r<o.length;r+=1)n.has(F(o[r]))&&(o[r]=sn(o[r]));e.nodes.forEach(o=>{n.has(o.name)&&(o.seq=an(o.seq))})}}function gi(e){e.nodesPerOrder=[];for(let n=0;n<=e.maxOrder;n+=1)e.nodesPerOrder[n]=[];let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&jo(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(s=>{jo(t,s.order,(s.y??0)+n.width)})}),e.nodes.forEach((n,s)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(s))})}function jo(e,t,n){let s=e.get(t);s===void 0?e.set(t,n):e.set(t,Math.max(s,n))}var bt=7;function xi(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{if((t.width===void 0||t.width===0)&&(t.width=bt),t.path.length===1){let s=t.path[0].node;s!==null&&e.nodes[s].internalReads.push(n)}else t.path.forEach((s,o)=>{if(o===0){let r=t.path[0].node;r!==null&&e.nodes[r].outgoingReads.push([n,o])}else{let r=s.node;r!==null&&e.nodes[r].incomingReads.push([n,o])}})})}function bi(e){e.reads.forEach(i=>{i.path=ur(e,i)}),xi(e);let t=e.nodes.filter(i=>i.order>=0);t.sort(ln);let n=new Map;for(let i=0;i<e.reads.length;i++){let c=e.reads[i],l=c.haplotypeShare===void 0?1:0,d=c.sourceTrackID,f=`${l}:${d}`,u=n.get(f);u===void 0?n.set(f,{layer:l,source:d,reads:new Set([i])}):u.reads.add(i)}let s=[...n.values()].sort((i,c)=>i.layer-c.layer||i.source-c.source),o=s.length>1?bt:0;t.forEach(i=>{for(let{reads:c}of s)yi(e,c,i,o)});let r=Ri(e),a=[];e.reads.forEach((i,c)=>{let l=i.path.length,d=new Array(l),f;for(let p=0;p<l;p++){p===0?d[p]=void 0:d[p]=f??i.path[0];let h=i.path[p];h.node!==null&&h.node&&(f=h)}let u=new Array(l),m;for(let p=l-1;p>=0;p--){p===l-1?u[p]=void 0:u[p]=m??i.path[l-1];let h=i.path[p];h.node!==null&&h.node&&(m=h)}i.path.forEach((p,h)=>{if(p.y===void 0){let g=d[h],x=u[h],b=!!(x&&g&&(g.order>x.order||x.order===g.order&&x.isForward===g.isForward));p.betweenCycleReverseTraversal=b,a.push({readIndex:c,pathIndex:h,previousY:g?.y,previousNode:g?.node})}})}),a.sort((i,c)=>wi(e,i,c)),a.forEach(i=>{let c=e.reads[i.readIndex],l=c.path[i.pathIndex];l.y=r[l.order],r[l.order]+=c.width}),Ce("Reads:",e.reads)}function yi(e,t,n,s){let o=n.incomingReads.filter(([p])=>t.has(p)),r=n.outgoingReads.filter(([p])=>t.has(p)),a=n.internalReads.filter(p=>t.has(p));o.length===0&&r.length===0&&a.length===0&&(s=0);let i=n.y+n.contentHeight+s*2,c=o.map(p=>{let[h,g]=p,x=e.reads[h].path,b=g+1,w;for(let y=1;y<=g;y++){let v=x[g-y]?.y;if(v!==void 0){b=y,w=v;break}}return{entry:p,decisionStep:b,y:w}});c.sort(Mi),o=c.map(p=>p.entry);let l=i,d=new Map;o.forEach(p=>{let h=e.reads[p[0]];h.path[p[1]].y=l,Vo(d,h,p[1],l,n),l+=h.width});let f=l;r.sort((p,h)=>vi(e,p,h));let u=new Map;l=i,r.forEach(p=>{let h=e.reads[p[0]],g=h.firstNodeOffset??0;h.path[p[1]].y=l,u.set(l,g);let x=d.get(l);x===void 0||x+1<=g?(l+=h.width,f=Math.max(f,l)):(d.set(l,0),o.forEach(b=>{let w=e.reads[b[0]],y=w.path[b[1]];y.y!==void 0&&y.y>=l&&(y.y+=h.width,Vo(d,w,b[1],y.y,n))}),l+=h.width,f+=h.width)}),a.sort((p,h)=>Si(e,p,h)),a.forEach(p=>{let h=e.reads[p],g=h.firstNodeOffset??0,x=h.finalNodeCoverLength??0;for(l=i;g<(d.get(l)??-1/0)+2||x>(u.get(l)??1/0)-3;)l+=h.width||bt;h.path[0].y=l,d.set(l,x),f=Math.max(f,l)});let m=f-n.y-n.contentHeight;n.contentHeight+=m,Ui(e,n,m)}function Mi(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 Vo(e,t,n,s,o){n===t.path.length-1?e.set(s,t.finalNodeCoverLength??0):e.set(s,o.sequenceLength)}function wi(e,t,n){let s=e.reads[t.readIndex],o=e.reads[n.readIndex],r=s.path[t.pathIndex],a=o.path[n.pathIndex];if(r.order!==a.order)return r.order-a.order;if(s.sourceTrackID!==o.sourceTrackID)return s.sourceTrackID-o.sourceTrackID;if(t.previousNode&&n.previousNode){let f=e.nodes[t.previousNode],u=e.nodes[n.previousNode];if(f&&u&&f.order!==u.order)return f.order-u.order}let i=t.previousY??0,c=n.previousY??0,l=r.betweenCycleReverseTraversal===!0,d=a.betweenCycleReverseTraversal===!0;return l!==d?l?1:-1:l?c-i:i-c}function vi(e,[t,n],[s,o]){let r=e.reads[t],a=e.reads[s],i,c,l=r.path.length-1,d=a.path.length-1;for(;!i&&l>=0;)i=r.path[l]?.y,l-=1;for(;!c&&d>=0;)c=a.path[d]?.y,d-=1;if(i&&c)return i-c;let f=r.path[n]?.node,u=a.path[o]?.node,m=typeof f=="number"?e.nodes[f]:null,p=typeof u=="number"?e.nodes[u]:null;for(;m&&p&&m===p;){if(n<r.path.length-1){for(n+=1;r.path[n]?.node===null;)n+=1;let g=r.path[n]?.node;m=typeof g=="number"?e.nodes[g]:null}else m=null;if(o<a.path.length-1){for(o+=1;a.path[o]?.node===null;)o+=1;let g=a.path[o]?.node;p=typeof g=="number"?e.nodes[g]:null}else p=null}if(m)return p?ln(m,p):1;if(p)return-1;let h=(r.firstNodeOffset??0)-(a.firstNodeOffset??0);return h!==0?h:(r.finalNodeCoverLength??0)-(a.finalNodeCoverLength??0)}function Ei(e,t){let n=e.path,s=t.path,o=0,r=0;for(;o<n.length&&r<s.length;){let a=n[o],i=s[r],c=a.order,l=i.order;if(c===l&&a.node&&i.node)return(i.y??0)-(a.y??0);c<l?o+=1:(c>l||(o+=1),r+=1)}return 0}function Si(e,t,n){let s=e.reads[t],o=e.reads[n],r=s.firstNodeOffset??0,a=o.firstNodeOffset??0;if(r<a)return-1;if(r>a)return 1;let i=s.finalNodeCoverLength??0,c=o.finalNodeCoverLength??0;return i<c?-1:i>c?1:0}function Ri(e){let t=[];for(let n=0;n<=e.maxOrder;n+=1)t.push(0);return e.nodes.forEach(n=>{n.y!==void 0&&(t[n.order]=Math.max(t[n.order],n.y+n.contentHeight+20))}),e.tracks.forEach(n=>{n.path.forEach(s=>{t[s.order]=Math.max(t[s.order],(s.y??0)+n.width)})}),t}function ur(e,t){let n=[],s=(c,l)=>{n.push({order:c,isForward:l,node:null})},o=(c,l,d)=>{n.push({order:c,isForward:l,node:d})},r=Math.abs(t.indexSequence[0]),a=Ko(t.indexSequence[0]),i=e.nodes[r];o(i.order,a,r);for(let c=1;c<t.sequence.length;c+=1){let l=i,d=a;r=Math.abs(t.indexSequence[c]),a=Ko(t.indexSequence[c]),i=e.nodes[r];let{order:f}=i;if(f>l.order){d||s(l.order,!0);for(let u=l.order+1;u<f;u+=1)s(u,!0);a||s(f,!0)}else if(f<l.order){d&&s(l.order,!1);for(let u=l.order-1;u>f;u-=1)s(u,!1);a&&s(f,!1)}else a===d&&s(f,!a);o(f,a,r)}return n}function rn(e,t=e.reads){t.forEach(n=>{let s=0;for(;s<n.sequence.length&&n.sequence[s].startsWith("-");)s+=1;if(s===n.sequence.length){n.is_reverse=!0,n.sequence=n.sequence.reverse();for(let c=0;c<n.sequence.length;c+=1)n.sequence[c]=F(n.sequence[c]);let o=n.sequenceNew??[];o.reverse(),n.sequenceNew=o;for(let c of o)c.nodeName=F(c.nodeName),_i(c.mismatches,nn(e,c.nodeName).sequenceLength);let r=n.firstNodeOffset??0,a=nn(e,n.sequence[0]).sequenceLength;n.firstNodeOffset=a-(n.finalNodeCoverLength??0);let i=nn(e,n.sequence[n.sequence.length-1]).sequenceLength;n.finalNodeCoverLength=i-r}})}function _i(e,t){e.forEach(n=>{Object.assign(n,Ni(n,t))})}function Ni(e,t){let n=e.type==="insertion"?0:e.type==="deletion"?e.length??0:e.seq?.length??0;return{...e,pos:t-e.pos-n,...e.seq!==void 0&&{seq:an(e.seq)}}}var Ai={A:"T",T:"A",C:"G",G:"C"};function an(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Ai[e.charAt(n)]??"N";return t}function Ie(e,t){let n=new Map;t.forEach(s=>{s.indexSequence=s.sequence.map(o=>{let r=n.get(o);if(r===void 0){let a=e.nodeMap.get(F(o));if(a===void 0)throw new Error(`Track ${s.name??s.id} visits unknown node ${o}`);r=B(o)?-a:a,n.set(o,r)}return r})})}var Li=20;function ki(e){let t={minX:99,maxX:-99,minY:99,maxY:-99};e.nodes.forEach(n=>{n.x!==void 0&&(t.minX=Math.min(t.minX,n.x),t.maxX=Math.max(t.maxX,n.x+Li+n.pixelWidth)),n.y!==void 0&&(t.minY=Math.min(t.minY,n.y-10),t.maxY=Math.max(t.maxY,n.y+n.contentHeight+10))}),e.tracks.forEach(n=>{n.path.forEach(s=>{let o=s.y??0;t.maxY=Math.max(t.maxY,o+n.width),t.minY=Math.min(t.minY,o)})}),e.imageBounds=t}function nn(e,t){let n=e.nodeMap.get(F(t)),s=n===void 0?void 0:e.nodes[n];if(s===void 0)throw new Error(`Unknown node ${t}`);return s}function Qo(e){let t=new Map;return e.nodes.forEach((n,s)=>{t.set(n.name,s)}),t}function Zo(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),s=o=>{for(let r=0;r<o.indexSequence.length-1;r+=1){let a=Math.abs(o.indexSequence[r]),i=Math.abs(o.indexSequence[r+1]);t[a].add(i),n[i].add(a)}};e.tracks.forEach(s),e.reads.forEach(s),e.nodes.forEach((o,r)=>{o.successors=Array.from(t[r]),o.predecessors=Array.from(n[r])})}function Jo(e,t){let n=0,s=0,o=0;t.forEach(r=>{let a=Math.abs(r);if(r<0){let i=e.nodeOrders[a]??=s;i<o&&(o=i),n=i,s=i-1}else{let i=e.nodeOrders[a]??=n;n=i+1,s=i}}),o<0&&cn(e,-o)}function Oi(e,t){let n=0,s=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let o=t[n],r,a;o>=0?(r=e.nodeOrders[o]-1,a=-1):(r=e.nodeOrders[-o]+1,a=1);for(let i=n-1;i>=0;i-=1){let c=Math.abs(t[i]);e.nodeOrders[c]===void 0&&(e.nodeOrders[c]=r,s=Math.min(s,r),r+=a)}return s<0&&cn(e,-s),n}var Ii=-1;function Ci(e){let t=[];for(let n of e)t.push(n??Ii);return t}function on(e){let t,n,s,o,r=0,a=e.tracks.concat(e.reads),i={stamp:new Int32Array(e.nodes.length),generation:0};e.nodeOrders=new Array(e.nodes.length).fill(void 0),e.nodes.forEach(l=>{l.order=void 0}),Jo(e,e.tracks[0].indexSequence);for(let l=1;l<a.length;l+=1){if(Ce(`generating order for track ${l+1}`),s=Oi(e,a[l].indexSequence),s===null){l<e.tracks.length?Jo(e,a[l].indexSequence):(a.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=$i(a[l].indexSequence);s<t.length;){for(o=s,s+=1;s<t.length&&e.nodeOrders[t[s]]===void 0;)s+=1;if(s<t.length){n=e.nodeOrders[t[o]]+1;for(let d=o+1;d<s;d+=1)e.nodeOrders[t[d]]=n,n+=1;if(e.nodeOrders[t[s]]>e.nodeOrders[t[o]])e.nodeOrders[t[s]]<n&&er(e,t[s],t[s-1],n);else if(a[l].indexSequence[s]>=0&&!Ti(e,t[s],t[o],i))er(e,t[s],t[s-1],n);else if(a[l].indexSequence[o]<0||e.nodes[t[o+1]].degree<2&&e.nodeOrders[t[s]]<e.nodeOrders[t[o]]){n=e.nodeOrders[t[o]]-1;for(let d=o+1;d<s;d+=1)e.nodeOrders[t[d]]=n,r=Math.min(r,n),n-=1}}else if(a[l].indexSequence[o]>=0){n=e.nodeOrders[t[o]]+1;for(let d=o+1;d<t.length;d+=1){let f=t[d];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,n+=1)}}else{n=e.nodeOrders[t[o]]-1;for(let d=o+1;d<t.length;d+=1){let f=t[d];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,r=Math.min(r,n),n-=1)}}}}r<0&&cn(e,-r);let c=Ci(e.nodeOrders);e.nodeOrders=c,c.forEach((l,d)=>{let f=e.nodes[d];f!==void 0&&(f.order=l)})}function Ti(e,t,n,s){s.generation+=1;let{stamp:o,generation:r}=s,a=[t];for(o[t]=r;a.length>0;){let i=a.pop();if(i===n)return!0;for(let c of e.nodes[i].successors)o[c]!==r&&(o[c]=r,a.push(c))}return!1}function Pi(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function $i(e){return e.map(t=>Math.abs(t))}function cn(e,t){e.nodeOrders.forEach((n,s)=>{n!==void 0&&(e.nodeOrders[s]=n+t)})}function er(e,t,n,s){let o=new Map,r=[[t,s]],a=0;for(;a<r.length;){let[i,c]=r[a];a+=1;let l=e.nodeOrders[i];l!==void 0&&l<c&&(!o.has(i)||o.get(i)<c)&&(o.set(i,c),e.nodes[i].successors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&r.push([d,c+1])}),i!==t&&e.nodes[i].predecessors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&r.push([d,c+1])}))}o.forEach((i,c)=>{e.nodeOrders[c]=i})}function Bi(e){e.nodes.forEach(t=>{t.tracks=[]}),e.tracks.forEach(t=>{t.indexSequence.forEach(n=>{e.nodes[Math.abs(n)].tracks.push(t.id)})}),e.nodes.forEach(t=>{t.degree=t.tracks.length})}function Xi(e){Di(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function Di(e,t,n){let s=new Int32Array(e.nodes.length),o=new Uint8Array(e.nodes.length);for(let r of n.sequence){let a=B(r)?void 0:e.nodeMap.get(r);a!==void 0&&(o[a]=1)}for(let r of t){let{sequence:a,indexSequence:i}=r,c=i.length-1;for(let l=0;l<=c;l+=1){let d=Math.abs(i[l]);if(o[d]===1)continue;let f=e.nodes[d].order,u=l>0?e.nodes[Math.abs(i[l-1])].order:void 0,m=l<c?e.nodes[Math.abs(i[l+1])].order:void 0,p=B(a[l])?1:-1;(u===void 0||u<f)&&(m===void 0||f<m)&&(s[d]+=p),(u===void 0||u>f)&&(m===void 0||f>m)&&(s[d]-=p)}}for(let r of t){let{sequence:a,indexSequence:i}=r;for(let c=0;c<i.length;c+=1)s[Math.abs(i[c])]>0&&(a[c]=sn(a[c]),i[c]=-i[c])}e.nodes.forEach((r,a)=>{s[a]>0&&(r.seq=an(r.seq),r.switched=!0)})}function Fi(e){let t=0,n=20,s=-1,o=e.nodes.slice();o.sort(ln);let r=Wi(e);o.forEach(a=>{a.order>=0&&(a.order>s&&(s=a.order,t=n+10*r[a.order]),a.x=t,n=Math.max(n,t+40+a.pixelWidth))})}function Wi(e){let t=[],n=[],s=[],o=[];for(let r=0;r<=e.maxOrder;r+=1)t.push(0),n.push(0),s.push(0);e.tracks.forEach(r=>{for(let a=1;a<r.path.length;a+=1){let i=r.path[a],c=r.path[a-1];if(i.order===c.order)i.isForward?t[i.order]=t[i.order]+1:n[i.order]=n[i.order]+1;else{let l=Math.abs((i.y??0)-(c.y??0));s[i.order]=Math.max(l/17.5,s[i.order])}}}),o.push(Math.max(0,t[0]-1));for(let r=1;r<=e.maxOrder;r+=1)o.push(Math.max(Math.max(0,t[r]-1)+Math.max(0,n[r-1]-1),s[r]));return o}function qi(e){let t=[],n=[];for(let s=0;s<=e.maxOrder;s+=1)e.assignments[s]=[],n[s]=new Map,t[s]=[];e.tracks.forEach((s,o)=>{s.path=ur(e,s),s.path.forEach((r,a)=>{Hi(e,r.order,r.node,o,a,t,n)})});for(let s=0;s<=e.maxOrder;s+=1)Gi(e,e.assignments[s],s)}function Hi(e,t,n,s,o,r,a){let i={trackID:s,segmentID:o,compareToFromSame:r[t][s]??null},c=n===null?void 0:a[t].get(n);if(c===void 0){let l={type:"single",node:n,tracks:[i]};e.assignments[t].push(l),n!==null&&a[t].set(n,l)}else c.type="multiple",c.tracks.push(i);r[t][s]=i}function Yi(e,t,n){let s;t.forEach(o=>{o.idealLane=0,o.tracks.forEach(r=>{if(r.segmentID===0)r.idealLane=r.trackID,r.idealY=null;else if(e.tracks[r.trackID].path[r.segmentID-1].order===n-1)r.idealLane=e.tracks[r.trackID].path[r.segmentID-1].lane??void 0,r.idealY=e.tracks[r.trackID].path[r.segmentID-1].y;else if(r.segmentID<e.tracks[r.trackID].path.length-1&&e.tracks[r.trackID].path[r.segmentID+1].order===n-1)r.idealLane=e.tracks[r.trackID].path[r.segmentID+1].lane??void 0,r.idealY=e.tracks[r.trackID].path[r.segmentID+1].y;else{for(s=r.segmentID-1;s>=0&&e.tracks[r.trackID].path[s].order!==n-1;)s-=1;s<0?(r.idealLane=r.trackID,r.idealY=null):(r.idealLane=e.tracks[r.trackID].path[s].lane,r.idealY=e.tracks[r.trackID].path[s].y)}o.idealLane+=r.idealLane}),o.idealLane/=o.tracks.length})}function Gi(e,t,n){let s=0,o=new Set,r=20,a=!1,i=-1;Yi(e,t,n),t.sort(tr),t.forEach(c=>{c.node!==null?(e.nodes[c.node].topLane=s,a&&(r-=10),e.nodes[c.node].y=r,e.nodes[c.node].contentHeight=0,a=!1):(a?r-=25:r>20&&(r-=10),a=!0),c.tracks.sort(tr),c.tracks.forEach(l=>{l.lane=s,l.trackID===i&&c.node===null&&a&&(r+=10),e.tracks[l.trackID].path[l.segmentID].lane=s,e.tracks[l.trackID].path[l.segmentID].y=r,typeof l.idealY=="number"&&o.add(l.idealY-r),s+=1,r+=e.tracks[l.trackID].width,c.node!==null&&(e.nodes[c.node].contentHeight+=e.tracks[l.trackID].width),i=l.trackID}),r+=25}),zi(e,t,o)}function zi(e,t,n){let s=0,o=Number.MAX_SAFE_INTEGER;n.forEach(r=>{let a=Ki(e,t,r);a<o&&(o=a,s=r)}),t.forEach(r=>{r.node!==null&&(e.nodes[r.node].y+=s),r.tracks.forEach(a=>{let i=e.tracks[a.trackID].path[a.segmentID];i.y=i.y+s})})}function Ui(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(s=>{if(s.node!==null){let o=e.nodes[s.node];o!==t&&o.y>t.y&&(o.y+=n,s.tracks.forEach(r=>{let a=e.tracks[r.trackID].path[r.segmentID];a.y=a.y+n}))}else s.tracks.forEach(o=>{let r=e.tracks[o.trackID].path[o.segmentID];r.y>=t.y&&(r.y=r.y+n)})}),e.nodesPerOrder[t.order].length>0&&e.nodesPerOrder[t.order].forEach(s=>{e.nodes[s]!==t&&e.nodes[s].y>t.y&&(e.nodes[s].y+=n)}))}function Ki(e,t,n){let s=0;return t.forEach(o=>{o.tracks.forEach(r=>{typeof r.idealY=="number"&&e.tracks[r.trackID].type!=="read"&&(s+=Math.abs(r.idealY-n-e.tracks[r.trackID].path[r.segmentID].y)*e.tracks[r.trackID].width)})}),s}function tr(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 ln(e,t){return e.order!==t.order?e.order-t.order:e.y!==void 0&&t.y!==void 0?e.y-t.y:0}function ji(e){let t=!0,n=4,s=e.config.trackWidth;for(let o of e.tracks)o.freq!==void 0?o.width=Math.round((Math.log(Math.max(o.freq,1))+1)*n):(o.width=s,o.type!==void 0&&o.type==="read"&&(o.width=n)),o.width!==n&&(t=!1);t&&e.tracks.forEach(o=>{o.freq!==void 0&&(o.width=s)})}function Vi(e,t){let n=t.path[0],s=e.nodes[n.node],o=t.firstNodeOffset??0;return fn(s,n.isForward?o:s.sequenceLength-o)}function Qi(e,t){let n=t.path[t.path.length-1],s=e.nodes[n.node],o=t.finalNodeCoverLength??0;return fn(s,n.isForward?o:s.sequenceLength-o)}function hr(e,t){return t>e.sequenceLength?null:fn(e,t)}function fn(e,t){let[n,s]=oc(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(s-n)}function Zi(e){let t,n,s,o;for(let i=0;i<=e.maxOrder;i+=1)e.extraLeft.push(0),e.extraRight.push(0);let r=[],a=[];e.nodes.forEach(i=>{i.x!==void 0&&(r[i.order]=i.x,a[i.order]===void 0?a[i.order]=i.x+i.pixelWidth:a[i.order]=Math.max(a[i.order],i.x+i.pixelWidth))}),e.tracks.sort(Ei),e.tracks.forEach(i=>{s=i.path[0].y,i.type!=="read"?i.sequence[0].startsWith("-")?t=a[i.path[0].order]+20:t=r[i.path[0].order]-20:t=Vi(e,i);for(let c=0;c<i.path.length;c+=1)i.path[c].y!==s&&(i.path[c-1].isForward?n=a[i.path[c-1].order]:n=r[i.path[c-1].order],n!==t&&e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:s,xEnd:Math.max(t,n),yEnd:s+i.width-1,id:i.id,name:i.name,type:i.type}),i.path[c].order-1===i.path[c-1].order?(t=n,n=r[i.path[c].order],o=i.path[c].y,e.shapes.curves.push({xStart:t,yStart:s,xEnd:n+1,yEnd:o,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[c-1].node,nodeEnd:i.path[c].node,orderStart:i.path[c-1].order,orderEnd:i.path[c].order}),t=n,s=o):i.path[c].order+1===i.path[c-1].order?(t=n,n=a[i.path[c].order],o=i.path[c].y,e.shapes.curves.push({xStart:t+1,yStart:s,xEnd:n,yEnd:o,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[c-1].node,nodeEnd:i.path[c].node,orderStart:i.path[c-1].order,orderEnd:i.path[c].order}),t=n,s=o):i.path[c-1].isForward?(o=i.path[c].y,or(e,1,n,s,o,i.width,i.id,i.path[c].order,i.type,i.name),t=a[i.path[c].order],s=i.path[c].y):(o=i.path[c].y,or(e,-1,n,s,o,i.width,i.id,i.path[c].order,i.type,i.name),t=r[i.path[c].order],s=i.path[c].y));i.type!=="read"?i.path[i.path.length-1].isForward?n=a[i.path[i.path.length-1].order]+20:n=r[i.path[i.path.length-1].order]-20:n=Qi(e,i),e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:s,xEnd:Math.max(t,n),yEnd:s+i.width-1,id:i.id,name:i.name,type:i.type})})}var pr=1e9;function mr(e,t,n,s=pr){let o=new Map,r=0,a=e.nodes.length,i=(h,g)=>(h+a)*(2*a+1)+g+a,c=e.config.ignoreStrand;for(let[h,g]of t.entries()){let x=Math.max(g.freq??1,1);r+=x;let b=g.indexSequence;if(!(b.length<2))for(let w=0;w<b.length-1;w+=1){let y=b[w],v=b[w+1],M=e.nodes[Math.abs(y)],E=e.nodes[Math.abs(v)],S=c?Math.min(i(y,v),i(-v,-y)):i(y,v),R=o.get(S);R===void 0?o.set(S,{sSigned:y,dSigned:v,sName:y<0?`-${M.name}`:M.name,dName:v<0?`-${E.name}`:E.name,count:x,crossings:x,sourceTrackID:g.sourceTrackID,lastSource:h}):(R.crossings+=x,R.lastSource!==h&&(R.count+=x,R.lastSource=h))}}let l=0;for(let h of o.values())h.crossings>l&&(l=h.crossings);let d=bt,f=60,u=h=>l<=1?d:d+(f-d)*Math.sqrt(h/l),m=[],p=0;for(let h of o.values()){let g=s+p,x=n==="haplotype"?{count:h.count,total:r}:void 0,b=x===void 0?"":` (${nc(x)})`,w=h.crossings===h.count?"":`, ${h.crossings.toLocaleString()} crossings`,y=`${h.count.toLocaleString()} ${n}${h.count===1?"":"s"}${b}${w}: Node ${h.sName} \u2192 Node ${h.dName}`;e.coarsenedEdgeMeta.set(g,{count:h.count,label:y});let v=e.nodes[Math.abs(h.sSigned)].sequenceLength;m.push({id:g,sourceTrackID:h.sourceTrackID,type:"read",name:y,sequence:[h.sName,h.dName],indexSequence:[],path:[],width:u(h.crossings),firstNodeOffset:v,finalNodeCoverLength:0,sequenceNew:[{nodeName:h.sName,mismatches:[]},{nodeName:h.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:h.count,haplotypeShare:x}),p+=1}if(ar){let h="?",g=0;e.nodes.forEach(x=>{x.contentHeight>g&&(g=x.contentHeight,h=x.name)}),Ce(`[coarsened] ${n}s_in=${t.length} edges_out=${m.length} tallestNodeBeforePlace=${h}(${g.toFixed(1)})`)}return{bands:m,total:r}}function Ji(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(d=>d.name===e.trackForRuler),s=n===-1?0:n,o=e.tracks[s],r=(o.freq??1)-1,a=tc(e,o),i=e.tracks.filter((d,f)=>f!==s).map(d=>ec(a,d));if(r>0&&i.push({...o,freq:r}),i.length===0)return;let{bands:c,total:l}=mr(e,i,"haplotype",t);return c.length>0?{ref:o,bands:c,total:l}:void 0}function ec(e,t){let n=0;for(let s of t.indexSequence){let o=e[Math.abs(s)];o!==void 0&&o!==0&&(n+=o===Math.sign(s)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(sn).reverse(),indexSequence:t.indexSequence.map(s=>-s).reverse()}}function tc(e,t){let n=new Int8Array(e.nodes.length);for(let s of t.indexSequence){let o=Math.abs(s);n[o]===0&&(n[o]=Math.sign(s))}return n}function nc({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var nr=7;function or(e,t,n,s,o,r,a,i,c,l){let d=t===1?e.extraRight:e.extraLeft,f=10*d[i],u=n+t*(f+5),m=nr,p=Math.min(nr,r),h=Math.min(s,o),g=Math.max(s,o),x=t===1?n:u-1,b=t===1?u:n,w=E=>{e.shapes.verticalRectangles.push({xStart:x,yStart:E,xEnd:b,yEnd:E+r-1,id:a,name:l,type:c})};w(s),e.shapes.verticalRectangles.push({xStart:t===1?u+m:u-m-p,yStart:h+r+m-1,xEnd:t===1?u+m+p-1:u-m-1,yEnd:g-m+1,id:a,name:l,type:c}),w(o);let y=u+t*m,v=u+t*(m+p),M=`M ${u} ${g}`;M+=` Q ${y} ${g} ${y} ${g-m}`,M+=` H ${v}`,M+=` Q ${v} ${g+r} ${u} ${g+r}`,M+=" Z ",e.shapes.corners.push({path:M,id:a,type:c}),M=`M ${u} ${h}`,M+=` Q ${v} ${h} ${v} ${h+r+m}`,M+=` H ${y}`,M+=` Q ${y} ${h+r} ${u} ${h+r}`,M+=" Z ",e.shapes.corners.push({path:M,id:a,type:c}),d[i]+=1}function oc(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function rr(e){switch(e.config.nodeWidthOption){case"compressed":e.nodes.forEach(t=>{t.width=1+Math.log2(Math.max(t.sequenceLength,1)),t.pixelWidth=Math.round((t.width-1)*8.401)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*8.401),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*8.401)});break;case"normal":{let t=e.config.charWidth;e.nodes.forEach(n=>{n.width=n.sequenceLength,n.pixelWidth=Math.round(t*Math.max(n.sequenceLength-1,0))});break}default:throw new Error(`${e.config.nodeWidthOption} not implemented`)}}var me=0;function sr(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function $(e,t,n){let s=e.count[t];s===0?(e.first[t]=n,e.count[t]=1):s===1&&e.first[t]!==n&&(e.count[t]=2)}function ze(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function rc(e){let t=sr(e.nodes.length),n=sr(e.nodes.length),s=new Map,o=f=>{let u=s.get(f);if(u===void 0){let m=e.nodeMap.get(F(f));u=B(f)?-m:m,s.set(f,u)}return u};e.tracks.concat(e.reads).forEach(f=>{let{sequence:u}=f,m=f.type==="haplotype",p=u.length-1,h=me,g=p>=0?o(u[0]):me;for(let x=0;x<=p;x+=1){let b=x<p?o(u[x+1]):me;if(g>0)x>0?($(t,g,h),h<0&&$(t,g,-h)):m&&$(t,g,me),x<p?($(n,g,b),b<0&&$(n,g,-b)):m&&$(n,g,me);else{let w=-g;x>0?($(n,w,-h),h>0&&$(n,w,h)):m&&$(n,w,me),x<p?($(t,w,-b),b>0&&$(t,w,b)):m&&$(t,w,me)}h=g,g=b}});let a=new Uint8Array(e.nodes.length);e.nodes.forEach((f,u)=>{sc(u,t,n)!==0&&(a[u]=1)});let i=new Int32Array(e.nodes.length),c=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((f,u)=>{if(a[u]!==1){i[u]=u,l[u]=f.sequenceLength;for(let m=u;ac(m,t,n);)m=ze(n,m),i[m]=u,c[m]=f.sequenceLength,f.sequenceLength+=e.nodes[m].sequenceLength,f.seq+=e.nodes[m].seq,l[m]=f.sequenceLength}}),e.reads.forEach(f=>{let{sequence:u}=f,m=f.sequenceNew??u.map(w=>({nodeName:w,mismatches:[]})),p=w=>{let y=Math.abs(o(w));return B(w)?e.nodes[i[y]].sequenceLength-l[y]:c[y]},h=u.length-1;f.firstNodeOffset=(f.firstNodeOffset??0)+p(u[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+p(u[h]);let g=[],x=[],b=[];u.forEach((w,y)=>{let v=Math.abs(o(w)),{mismatches:M}=m[y],E=p(w);if(M.forEach(S=>{S.pos+=E}),a[v]===1&&!B(w)&&y>0)x.at(-1).mismatches.push(...M);else if(a[v]===1&&B(w)&&y<h)b.push(...M);else{let S=e.nodes[i[v]].name,R=B(w)?dr(S):S;g.push(R),x.push({nodeName:R,mismatches:b.concat(M)}),b=[]}}),f.sequence=g,f.sequenceNew!==void 0&&(f.sequenceNew=x)}),e.tracks.forEach(f=>{let{sequence:u}=f,m=0;for(let p of u)a[Math.abs(o(p))]===0&&(u[m]=p,m+=1);u.length=m});let d=1;for(let f=1;f<e.nodes.length;f+=1)a[f]===0&&(e.nodes[d]=e.nodes[f],d+=1);e.nodes.length=d}function sc(e,t,n){let s=ze(t,e);return s!==0&&ze(n,s)!==0?s:0}function ac(e,t,n){let s=ze(n,e);return s!==0&&ze(t,s)!==0}function ic(e,t){let n=new Map;for(let s of e){let o=t(s),r=n.get(o);r===void 0?n.set(o,[s]):r.push(s)}return n}function cc(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 dn(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function lc(e,t){for(let n=0;n<e.length;n+=1){let s=e[n]-t[n];if(s!==0)return s}return 0}function gr(e,t){let n=ic(e.filter(s=>s.type===t),s=>dn(s).join(","));return n.forEach(s=>{let o=.3,r=.4/s.length;s.length<=5&&(o=.5,r=0),s.sort(cc),s.forEach(a=>{let i,c;a.yStart<a.yEnd?(i=a.xStart+(a.xEnd-a.xStart)*(1-o),o+=r,c=a.xStart+(a.xEnd-a.xStart)*(1-o)):(i=a.xStart+(a.xEnd-a.xStart)*o,o+=r,c=a.xStart+(a.xEnd-a.xStart)*o);let l=`M ${a.xStart} ${a.yStart}`;l+=` C ${i} ${a.yStart} ${i} ${a.yEnd} ${a.xEnd} ${a.yEnd}`,l+=` V ${a.yEnd+a.width}`,l+=` C ${c} ${a.yEnd+a.width} ${c} ${a.yStart+a.width} ${a.xStart} ${a.yStart+a.width}`,l+=" Z",a.path=l})}),[...n.values()].sort((s,o)=>lc(dn(s[0]),dn(o[0]))).flat()}function xr(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,s=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${s}`),t+=` Q ${n+9} ${s} ${n+9} ${s+9}`,n+=9,s+=9,e.contentHeight>0&&(s+=e.contentHeight,t+=` L ${n} ${s}`),t+=` Q ${n} ${s+9} ${n-9} ${s+9}`,n-=9,s+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${s}`),t+=` Q ${n-9} ${s} ${n-9} ${s-9}`,n-=9,s-=9,e.contentHeight>0&&(s-=e.contentHeight,t+=` L ${n} ${s}`),t}function fc(e){let t=new Map;for(let[n,s]of e.pathVisits??[])for(let o of s){let r=`${o.path} ${n}`,a=t.get(r);a?a.push(o.strand):t.set(r,[o.strand])}return t}function dc(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=fc(e),s=(e.paths??[]).map((r,a)=>({path:r,index:a})),o=s.findIndex(r=>te(r.path.name).name===e.referencePath);return o>0&&s.unshift(...s.splice(o,1)),s.flatMap(({path:r,index:a})=>{let i=te(r.name).name,c=new Map,l=r.nodeIds.flatMap(d=>{let f=t.get(d);if(!f)return[];let u=c.get(f.name)??0;c.set(f.name,u+1);let m=n.get(`${i} ${f.name}`)?.[u]??en(f);return[tn(f,m)]});return l.length>0?[{id:a,name:r.name,sequence:l,sourceTrackID:0,type:"haplotype"}]:[]})}function uc(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function Te(e){return(e.paths?.length??0)>0}var hc=600,pc=3,mc=15;function gc(e){return Math.max(pc,Math.min(mc,Math.floor(hc/Math.max(1,e))))}function br(e){let t=e.paths??[],n=dc(e),s=e.reads?Wo(e,e.reads,t.length):[],o=s.length>0?jn:Kn,r=t.map((i,c)=>o(c,t.length)),a=cr(uc(e),n,s,{nodeWidthOption:"compressed",trackWidth:gc(n.length)});return a?{layout:a,pathColors:r}:void 0}function un(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function yr(e,t,n,s){let o=e.y+e.contentHeight/2-t;return[{x:n,y:o},{x:s,y:o}]}function Mr(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function wr(e){let t=Te(e)?br(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,o=n.bounds.minY,r={};for(let c of un(n))r[c.name]=yr(c,o,c.x,c.x+c.pixelWidth);let{minY:a,maxY:i}=Mr(n,o);return{nodePositions:r,tubeMap:{layout:n,yOffset:o,pathColors:s},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:i}}}function xc(e,t){let n=new Map(e.nodes.map(i=>[i.id,i])),s=new Map;for(let i of un(t)){let c=s.get(i.order);c?c.push(i):s.set(i.order,[i])}let o=[],r=-1/0;for(let i of[...s.keys()].sort((c,l)=>c-l)){let c=s.get(i),l=1/0,d=-1/0;for(let f of c){let u=n.get(f.name);u&&A(u)&&(l=Math.min(l,u.stable.start),d=Math.max(d,u.stable.start+f.sequenceLength))}l===1/0&&(l=d=r),l<r&&(l=r,d=Math.max(r,d)),r=Math.max(r,d),o.push({order:i,x0:Math.min(...c.map(f=>f.x)),x1:Math.max(...c.map(f=>f.x+f.pixelWidth)),bp0:l,bp1:d})}let a=o.find(i=>i.bp0!==-1/0);for(let i of o)i.bp0===-1/0&&(i.bp0=i.bp1=a?.bp0??0);return o}function bc(e){return e.nodes.some(A)&&Te(e)}function vr(e){let t=bc(e)?br(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,o=xc(e,n),r=new Map(o.map(c=>[c.order,c])),a=n.bounds.minY,i={};for(let c of un(n)){let l=r.get(c.order);i[c.name]=yr(c,a,l.bp0,l.bp1)}return{nodePositions:i,tubeMap:{layout:n,yOffset:a,columns:o,pathColors:s},referenceAxis:!0,pixelRows:!0,extent:Mr(n,a)}}function yc(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,s)=>n-s).map((n,s)=>[n,s]))}function Er(e,t){let n=ce(e);if(n.length===0)return;let s=qe(n,t),o=yc(e),r=le(n),a=xt({graph:e,span:s,rowY:c=>(c.stable?o.get(c.stable.rank)??o.size:o.size)*I,positions:r}),i=[...o].map(([c,l])=>({label:c===0?"Reference (rank 0)":`Rank ${c}`,y:l*I}));return{nodePositions:r,rowLabels:i,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Mc=12,hn=I;function Sr(e){return 10+8*Math.log2(1+e.length)}function oe(e,t){return e<t?-1:e>t?1:0}function _r(e,t){return oe(e.at,t.at)||oe(e.side,t.side)||oe(e.hops,t.hops)}var Rr={at:1/0,side:0,hops:0};function wc(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=Sc(e);return e.nodes.map(s=>s.id).sort((s,o)=>_r(n.get(s)??Rr,n.get(o)??Rr)||oe(t.get(s).name,t.get(o).name)||oe(s,o))}function vc(e,t){let n=new Set(e.nodes.map(d=>d.id)),s=new Map(t.map(d=>[d.id,d.stable.start])),o=new Map,r=new Map;t.forEach((d,f)=>{r.set(d.id,t[f-1]?.id),o.set(d.id,t[f+1]?.id)});let a=t[0]?.id,i=(d,f)=>{let u=o.get(d);o.set(d,f),r.set(f,d),o.set(f,u),u!==void 0&&r.set(u,f)},c=(d,f)=>{let u=r.get(d);u===void 0?(a=f,r.set(f,void 0),o.set(f,d),r.set(d,f)):i(u,f)};for(let d of e.paths??[]){let f=0,u=0,m;for(let x of d.nodeIds){let b=s.get(x);b!==void 0&&(m!==void 0&&b!==m&&(b>m?f++:u++),m=b)}let p=u>f?[...d.nodeIds].reverse():d.nodeIds,h,g=new Set;for(let x of p)if(o.has(x)){if(h===void 0)for(let b of g)c(x,b);h=x}else n.has(x)&&(h===void 0?g.add(x):(i(h,x),h=x))}let l=[];for(let d=a;d!==void 0;d=o.get(d))l.push(d);return l}function Ec(e,t){let n=[...t.entries()].sort(([a,i],[c,l])=>_r(i,l)||oe(a,c)).map(([a])=>a),s=n.length;for(let a of n){let i=t.get(a);for(let c of e.get(a)??[])t.has(c)||(t.set(c,{at:i.at,side:1,hops:i.hops+1}),n.push(c))}let o=new Set(n.slice(s)),r=new Set;for(let a of o){if(r.has(a))continue;let{at:i}=t.get(a),c=[a];r.add(a);let l=!0;for(let d of c){let{hops:f}=t.get(d),u=!0,m=!1;for(let p of e.get(d)??[]){let h=t.get(p);h.at===i&&o.has(p)?(u&&=h.hops<=f,r.has(p)||(r.add(p),c.push(p))):h.at!==i&&(m||=h.at<i,l&&=h.at<i)}l&&=!u||m}if(l)for(let d of c){let f=t.get(d);t.set(d,{...f,side:-1,hops:-f.hops})}}}function Sc(e){let t=new Set(e.nodes.map(r=>r.id)),n=new Map;for(let r of e.edges)!t.has(r.from)||!t.has(r.to)||((n.get(r.from)??n.set(r.from,[]).get(r.from)).push(r.to),(n.get(r.to)??n.set(r.to,[]).get(r.to)).push(r.from));let s=e.nodes.filter(A).sort((r,a)=>oe(r.stable.start,a.stable.start)||oe(r.name,a.name)),o=new Map;return vc(e,s).forEach((r,a)=>{o.set(r,{at:a,side:0,hops:0})}),Ec(n,o),o}function Rc(e){let t=new Map(e.nodes.map(f=>[f.id,f])),n=wc(e),s=new Map(n.map((f,u)=>[f,u])),o=f=>A(t.get(f)),r=new Map(n.map(f=>[f,[]])),a=new Map(n.map(f=>[f,[]])),i=(f,u)=>{r.get(u).push(f),a.get(f).push(u)};for(let f of e.edges)f.from===f.to||!s.has(f.from)||!s.has(f.to)||(s.get(f.from)<s.get(f.to)?i(f.from,f.to):i(f.to,f.from));let c=n.filter(o);for(let f=1;f<c.length;f++)i(c[f-1],c[f]);let l=new Map;for(let f of n){let u=0;for(let m of r.get(f))u=Math.max(u,l.get(m)+1);l.set(f,u)}for(let f=n.length-1;f>=0;f--){let u=n[f],m=a.get(u);if(o(u)||m.length===0)continue;let p=1/0;for(let x of m)p=Math.min(p,l.get(x));let h=l.get(u),g=Math.max(h,p-1);l.set(u,Math.floor((h+g)/2))}let d=[];for(let f of n)(d[l.get(f)]??=[]).push(f);return{layers:d,layerOf:l,preds:r}}function Nr(e){if(!e.nodes.some(A))return;let t=new Map(e.nodes.map(f=>[f.id,f])),n=f=>A(t.get(f)),{layers:s,layerOf:o,preds:r}=Rc(e),a=s.map(f=>{let u=0;for(let m of f)u=Math.max(u,Sr(t.get(m)));return u}),i=[],c=0;for(let f=0;f<s.length;f++)i[f]=c,c+=a[f]+Mc;let l=new Map;for(let f of s){let u=[];for(let p of f){if(n(p)){l.set(p,0);continue}let h=r.get(p).filter(x=>l.has(x)),g=0;for(let x of h)g+=l.get(x)/h.length;u.push({id:p,ideal:g===0?hn:g})}u.sort((p,h)=>p.ideal-h.ideal);let m=new Set([0]);for(let{id:p,ideal:h}of u){let g=Math.round(h/hn);g===0&&(g=h>=0?1:-1);for(let x=1;m.has(g);x++)m.has(g+x)?m.has(g-x)||(g-=x):g+=x;m.add(g),l.set(p,g*hn)}}let d={};for(let f of e.nodes){let u=o.get(f.id),m=Sr(f),p=i[u]+a[u]/2,h=l.get(f.id);d[f.id]=[{x:p-m/2,y:h},{x:p+m/2,y:h}]}return{nodePositions:d,referenceAxis:!1,pixelRows:!0}}function Ar(e){return e.sample??et(e.name)}function _c(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Ar(e)}function Nc(e,t){let n=[],s;for(let o of e){s!==void 0&&o.start!==void 0&&o.start>s&&n.push(o.start-s),n.push(...o.nodeIds);let r=o.nodeIds.reduce((a,i)=>a+(t.get(i)??0),0);s=o.start===void 0?void 0:o.start+r}return n}function Ac(e,t){let n=[],s;for(let o of e){if(o.start===void 0||s!==void 0&&o.start<s)return;s!==void 0&&o.start>s&&n.push({start:s,end:o.start});let r=o.start;for(let a of o.nodeIds){let i=t.get(a)??0;n.push({start:r,end:r+i}),r+=i}s=r}return n}function Lc(e,t,n,s=!0){if(!n||!s)return{ids:e,complete:!0,from:-1,to:-1};let o=-1,r=-1,a=-1/0,i=1/0;if(e.forEach((l,d)=>{let f=typeof l=="string"?t.get(l):void 0;f&&(f.end<=n.start&&f.end>a&&(a=f.end,o=d),f.start>=n.end&&f.start<i&&(i=f.start,r=d))}),o<0||r<0)return{ids:e,complete:!1,from:-1,to:-1};let c=e.slice(Math.min(o,r)+1,Math.max(o,r));return{ids:o<r?c:c.reverse(),complete:!0,from:o,to:r}}function Yu(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,s)=>t.indexOf(n.sample)-t.indexOf(s.sample)||n.label.localeCompare(s.label)):e}function Lr(e,t,n){let s=e.paths??[],o=g=>te(g.name).name===e.referencePath,r=s.some(o)?s.filter(o).sort((g,x)=>(g.start??0)-(x.start??0)):s.slice(0,1),a=r[0],i=s.filter(g=>!r.includes(g));if(!a||i.length===0)return;let c=new Map;for(let g of i)c.set(g.name,[...c.get(g.name)??[],g]);let l=new Map(e.nodes.map(g=>[g.id,g.length])),d=a.start??0,f=t&&t.end>t.start?t:void 0,u=new Map;for(let g of r){let x=g.start??0;for(let b of g.nodeIds){let w=l.get(b)??0;u.has(b)||u.set(b,{start:x,end:x+w}),x+=w}}let m=f===void 0||[...u.values()].some(g=>g.end<=f.start)&&[...u.values()].some(g=>g.start>=f.end),p=g=>{let x=g[0],b=[...g].sort((T,q)=>(T.start??0)-(q.start??0)),{ids:w,complete:y,from:v,to:M}=Lc(Nc(b,l),u,f,m),E=Ac(b,l),S=x.contig??tt(te(x.name).name),R=E?.length?v<0?{contig:S,start:E[0].start,reversed:!1}:v<M?{contig:S,start:E[v].end,reversed:!1}:{contig:S,start:E[v].start,reversed:!0}:void 0,C=[],k=0,Q=0,xe=0,W=0;for(let T of w){if(typeof T=="number"){C.push({start:k,bp:T,onReference:!1,gap:!0}),k+=T,xe+=T,W=0;continue}let q=l.get(T)??0,X=u.get(T),D=C.at(-1),be=D?.referenceStart,$e=X&&be!==void 0&&W>=0&&be+D.bp===X.start,N=X&&be!==void 0&&W<=0&&X.end===be;!X&&D&&!D.onReference&&!D.gap?D.bp+=q:$e||N?(D.bp+=q,$e||(D.referenceStart=X.start,D.reversed=!0),W=$e?1:-1):(C.push({start:k,bp:q,onReference:X!==void 0,referenceStart:X?.start}),W=0),k+=q,X||(Q+=q)}return{name:x.name,label:_c(x),sample:Ar(x),haplotype:x.haplotype,bp:k,offReferenceBp:Q,gapBp:xe,complete:y,runs:C,axis:R}};return{origin:f?f.start:d,unit:n,reference:p(r),rows:[...c.values()].map(p).sort((g,x)=>Number(x.complete)-Number(g.complete)||x.bp-g.bp||g.label.localeCompare(x.label))}}var kc=1.3;function Oc(e,t={rowPx:I,readouts:!0}){let n=e.reference.bp;for(let s of e.rows)n=Math.max(n,s.bp);return{maxX:e.origin+n*(t.readouts?kc:1),maxY:e.rows.length*t.rowPx}}function ju(e,t,n){return e?n&&!n.labelled?[]:[e.reference,...e.rows].map((s,o)=>({label:s.label,y:o*(n?.rowPx??I)})):t?.rowLabels??[]}function kr(e,t){let n=ce(e),s=Lr(e,t);if(n.length===0||!s)return;let o=t?n.filter(i=>Tt(i,t)):n,r=le(o.length>0?o:n),a=[{label:s.reference.label,y:0},...s.rows.map((i,c)=>({label:i.label,y:(c+1)*I}))];return{nodePositions:r,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:Oc(s)}}var Tr="Force-directed layout",ge=e=>e.nodes.some(A),Or=e=>ge(e)&&(e.paths?.length??0)>1,Ir=e=>ge(e)&&Te(e),Cr=e=>ge(e)&&e.nodes.some(We),yt=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:Er,cutMargins:!0,wholeWalks:!1,available:ge,drawsLocally:ge,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:Yo,cutMargins:!0,wholeWalks:!1,available:Cr,drawsLocally:Cr,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:kr,cutMargins:!1,wholeWalks:!0,available:Or,drawsLocally:Or,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:Nr,cutMargins:!1,wholeWalks:!1,available:ge,drawsLocally:ge,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:wr,cutMargins:!1,wholeWalks:!1,available:Te,drawsLocally:Te,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:vr,cutMargins:!0,wholeWalks:!1,available:Ir,drawsLocally:Ir,drawsNodes:!1},{value:"force",label:Tr,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],Ic=yt.map(e=>e.value);function Cc(e,t){return!Pr(e).drawsLocally(t)}function Pr(e){return yt.find(t=>t.value===e)??yt[0]}var Mt=8,pn=34,wt=12,Tc=60;function Pc({count:e,bounds:t,pixelRows:n,width:s,room:o,columns:r}){function a(c){let l=Math.ceil(e/c),d=Math.floor((s-(c-1)*Mt)/c),f=(o-l*pn-(l-1)*Mt)/l,u=(d-2*wt)/t.w,m=t.h>0?(f-2*wt)/t.h:1/0,p=n?u:Math.min(u,m),h=n?t.h:t.h*p,g=Math.floor(Math.max(Tc,Math.min(h+2*wt,f)));return{columns:c,width:d,height:g,scale:p,total:l*(g+pn)+(l-1)*Mt}}if(r!==void 0)return a(Math.max(1,Math.min(e,Math.round(r))));let i=a(1);for(let c=2;c<=e;c++){let l=a(c);l.scale>i.scale&&(i=l)}return i}var $c=[{value:"",label:"None",description:"Every lifted walk in one drawing"},{value:"walk",label:"A panel per walk",description:"One panel per lifted walk, side by side"},{value:"sample",label:"A row per sample",description:"A row per sample, a column per haplotype"}];function Bc(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 $r(e,t){let n=new Map(t.map((o,r)=>[o,r])),s=o=>n.get(o)??t.length;return e.map((o,r)=>({name:o,i:r})).sort((o,r)=>s(o.name)-s(r.name)||o.i-r.i).map(({name:o})=>o)}function Xc(e,t,n=[]){let s=$r(e,n),o={columns:void 0,count:e.length,cells:e.map(l=>s.indexOf(l))};if(t==="walk")return o;let r=e.map(l=>{let[d,f,u]=l.split("#"),m=Number(f);return u!==void 0&&Number.isInteger(m)&&m>=0?{sample:d,column:Math.max(0,m-1)}:void 0}),a=$r([...new Set(r.flatMap(l=>l?[l.sample]:[]))],n),i=Math.max(1,...r.map(l=>l?l.column+1:1)),c=r.map(l=>l?a.indexOf(l.sample)*i+l.column:-1);return c.includes(-1)||new Set(c).size<c.length?o:{columns:i,count:a.length*i,cells:c}}var Dr=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],xn=[{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"}],Br=["blue","red","purple","green"],Dc=e=>Dr.some(t=>t.value===e),Fc=e=>xn.some(t=>t.value===e);function Wc(e,t,n,s=!0){let{field:o,scheme:r}=e.color??{},a=Dc(o)?o:s?"progress":"walk",i=t?"grey":Br[n%Br.length],c=Fc(r)?r==="rainbow"&&a!=="reference"?i:r:i;return{field:a,scheme:c}}var Fr=.5,qc=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Hc=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function Xr(e){let[t,n,s]=[1,3,5].map(i=>qc(Number.parseInt(e.slice(i,i+2),16)/255)),o=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*s),r=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*s),a=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*s);return[.2104542553*o+.793617785*r-.0040720468*a,1.9779984951*o-2.428592205*r+.4505937099*a,.0259040371*o+.7827717662*r-.808675766*a]}function Yc([e,t,n]){let s=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,r=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*s-3.3077115913*o+.2309699292*r,-1.2684380046*s+2.6097574011*o-.3413193965*r,-.0041960863*s-.7034186147*o+1.707614701*r].map(a=>Hc(Math.max(0,Math.min(1,a)))*255)}function bn(e,t){let n=Math.max(0,Math.min(1,t)),s=xn.find(a=>a.value===e);if(!s||!("ends"in s))return he(n*pe,.7,.5).map(a=>a*255);let o=Xr(s.ends[0]),r=Xr(s.ends[1]);return Yc(o.map((a,i)=>a+(r[i]-a)*n))}function mn(e,t){let[n,s,o]=bn(e,t).map(Math.round);return`rgb(${n}, ${s}, ${o})`}function gn(e,t){let[n,s,o]=bn(e,t).map(Math.round);return O(n,s,o,255)}function Gc({field:e,scheme:t},n){return e==="walk"?gn(t,Fr):n===void 0?Wr:gn(t,n)}var Wr=dt;function qr({field:e,scheme:t}){return e==="walk"?[{offset:0,color:mn(t,Fr)}]:Array.from({length:7},(n,s)=>({offset:s/6,color:mn(t,s/6)}))}function zc(e){let t=qr(e);return t.length===1?t[0].color:`linear-gradient(to right, ${t.map(n=>`${n.color} ${n.offset*100}%`).join(", ")})`}var Gr=_e(Yr(),1),vt=16;function Qh(e){let[t="",...n]=e.split(/\r\n|\r|\n/),s=t.split(" ").slice(1),o=new Map;for(let r of n){if(!r)continue;let[a="",...i]=r.split(" ");a&&!o.has(a)&&o.set(a,{...Object.fromEntries(s.map((c,l)=>[c,i[l]??""])),name:a})}return[...o.values()]}function Zh(e){let t=new Set;for(let n of e??[])for(let s of Object.keys(n))s!=="name"&&t.add(s);return[...t]}function Jh(e){if(typeof e=="string")return e?{field:e}:void 0;let{field:t,domain:n}=e??{};if(!(typeof t!="string"||!t))return Array.isArray(n)?{field:t,domain:n.filter(s=>typeof s=="string")}:{field:t}}function Uc(e){let t=new Set(e.map(n=>n.label)).size;return`${t} haplotype${t===1?"":"s"}`}function ep(e,t,{field:n,domain:s}){let o=new Map(t.map(c=>[c.name,c[n]??""])),r=new Map;for(let c of e){let l=o.get(c.label)||o.get(c.sample)||"",d=r.get(l);d?d.push(c):r.set(l,[c])}let a=1,i=[...r.keys()].sort((0,Gr.groupKeyComparator)(s)).map(c=>{let l=r.get(c),d={key:c,title:`${c||`${n}: none`} \xB7 ${Uc(l)}`,first:a,count:l.length};return a+=l.length,d});return{rows:i.flatMap(c=>r.get(c.key)),sections:i}}function tp(e,t){let n=o=>{let r=-1;for(;r+1<e.length&&e[r+1].first<=o;)r++;return r},s=o=>o*t+(n(o)+1)*vt;return{rowY:s,headers:e.map((o,r)=>({...o,top:(o.first-.5)*t+r*vt})),headersPx:e.length*vt,rowAt(o,r){let a=0;for(let i=-1;i<e.length;i++){let c=i<0?0:e[i].first,l=i<0?Math.min(r,e[0]?.first??r):c+e[i].count,d=(i+1)*vt,f=Math.min(l-1,Math.max(c,Math.round((o-d)/t)));Math.abs(s(f)-o)<Math.abs(s(a)-o)&&(a=f)}return a}}}var Kc=10;function jc(e,t){let n=e.end-e.start,s=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>s<=Kc*(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 Vc=40;function re(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Qc(e,t){let n=re(e),s=re(t),o=s.slice(s.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${s}`:`${n}\u2013${s}`}function zr(e){return e>=Qn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Zc(e,t=[]){let n=Jc(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function Jc(e,t){let n=e.end-e.start,{shortestAlleleLength:s,longestAlleleLength:o,pathCount:r,segmentCount:a,inversion:i}=e,c=Qc(s,o);if(a>=Vc)return{kind:"superbubble",label:`${c} superbubble, ${a} segments, ${zr(r)}${i?", inv":""}`};if(i)return{kind:"inversion",label:`${re(o)} inv`};let l=o!==s?jc(e,t):void 0;if(l){let f=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${c} repeat array${f}, ${zr(r)}`}}let d=r>2?`, ${r} alleles`:"";return s===o&&s===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${re(n)} sub`}:n===0||s===n?{kind:"insertion",label:`\u2264${re(o-n)} ins${d}`}:o===n?{kind:"deletion",label:`${re(n-s)} del${d}`}:{kind:"complex",label:`${re(n)} ref \u2192 ${c}, ${r} alleles`}}var el={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},tl={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function nl(e){return e.segments.split(",").filter(Boolean)}var Mn="#2f8fd6",wn="#8e3fbf",vn="#bdbdbd",Ue="#1c1c22",En=12,Sn=4,Et=12,ol=6,rl=3;function Pe(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Ur(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function Kr(e,t,n,s){let{bp:o,gapBp:r,complete:a}=e;if(!t)return`${Pe(o)}${Ur(o,n)}`;let i=o-t.bp,c=i===0?"":` (${i>0?"+":"\u2212"}${Pe(Math.abs(i))})`,l=r>0?` \xB7 ${Pe(r)} outside the cut`:"",d=s?` \xB7 called ${Pe(s.bp)}${s.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${Pe(o)}${Ur(o,n)}${c}${l}${a?"":" \xB7 partial walk"}${d}`}function jr(e,t,n){let s=t+6;return s+e.length*fe<n?{x:s,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Vr(e,t,n){if(t*n<rl)return[];let s=[];for(let o=t;o<e;o+=t)s.push(o);return s}function Qr(e,t){if(e.gap)return{fill:vn};if(!t)return{fill:e.onReference?Mn:wn};if(e.referenceStart===void 0)return{fill:ut};let n=po({...e,start:e.referenceStart},t);return n.length===1?{fill:mt(n[0])}:{stops:n.map(mt)}}function Ke(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function sl(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function al(e,t){let n=new Map;for(let s of e){let o=t.get(s.name);if(!s.axis||!o)continue;let r=s.axis,a=({start:i,end:c})=>({start:Math.max(0,i),end:Math.min(s.bp,c)});n.set(s.name,o.map(i=>({name:i.name,...a(Ke(r,i.start,i.end)),exons:i.exons.map(c=>a(Ke(r,c.start,c.end))).filter(c=>c.end>c.start)})).filter(i=>i.end>i.start).sort((i,c)=>i.start-c.start))}return n}var il=9,cl=5.2,ll=8,Zr=(e,t)=>Math.min(2,(e-t)/2-1);function St(e,t){return Zr(e,t)>=1}function Jr(e,t,n,{rowPx:s=I,barPx:o=En}={}){if(!St(s,o))return[];let r=Zr(s,o),a=e.map(l=>{let d=t(l.start);return{g:l,x:d,w:Math.max(2,t(l.end)-d)}}),i=[],c=new Set((o>=ll?[...a]:[]).sort((l,d)=>l.w-d.w).filter(({g:l,x:d,w:f})=>{let u=l.name.length*cl/2,m=[d+f/2-u,d+f/2+u];return 2*u>f+6||i.some(([p,h])=>m[0]<h+2&&m[1]>p-2)?!1:(i.push(m),!0)}));return a.map(l=>({name:l.g.name,x:l.x,y:n-o/2-r,w:l.w,h:o+2*r,exons:l.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:c.has(l)?{x:l.x+l.w/2,y:n+3,size:il}:void 0}))}var yn=e=>`${e} row${e===1?"":"s"}`;function fl(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??mo,ramp:!0}:{kind:"bar",fill:Mn},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?ut:wn},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(s=>s.gapBp>0)&&n.push({swatch:{kind:"gap",fill:vn},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 ${yn(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${yn(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${yn(t.genes.unread)}`,note:!0})),n}var es="#111",ts="#9e9e9e",Rn="#c62828";function ns(e){return e.agrees===!1?Rn:e.spanningReads===0?ts:es}function dl(e,t,n,s="walk-key"){let o=0,r=e.flatMap((a,i)=>{let c=`${s}-ramp-${i}`,l=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?_("linearGradient",{id:c},...Vt.map(u=>_("stop",{offset:u.offset,"stop-color":u.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?_("rect",{x:o,y:5,width:18,height:8,fill:"none",stroke:Ue,"stroke-width":1.5}):_("rect",{x:o,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Sn:8,rx:2,fill:l?`url(#${c})`:a.swatch.fill}),f=_("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*fe+16,[l,d,f].filter(u=>u!==void 0)});return{width:o,tree:_("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...r)}}function _n(e,t,n=0){let s=t/Math.max(1,e),o=Math.max(n,Math.min(I,s>=1?Math.floor(s):s));return{rowPx:o,barPx:o<=3?o:Math.max(3,Math.round(o*.6)),labelled:o>=Et,readouts:o>=Et}}function os(e,t){let n=1/t,s=[],o=[],r=()=>{if(o.length!==0){if(o.length===1)s.push(o[0]);else{let i=0,c=0;for(let f of o)f.onReference?i+=f.bp:c+=f.bp;let l=i>=c,d=o.find(f=>f.onReference===l);s.push({start:o[0].start,bp:i+c,onReference:l,referenceStart:l?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}o=[]}},a=0;for(let i of e){if(i.gap||i.bp>=n){r(),a=0,s.push(i);continue}o.push(i),a+=i.bp,a>=n&&(r(),a=0)}return r(),s}function ul(e,t,n){return _("g",{class:"row-gene","data-testid":"graph-walk-gene"},_("title",{},e.name),...e.exons.map(s=>_("rect",{x:s.x,y:t-n/2,width:s.w,height:n,fill:Ue,opacity:.35})),_("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:Ue,"stroke-width":1.5}),e.label&&_("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:Ue,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function hl(e,t,n={}){let s=h=>h*t.scaleX+t.translateX,o=t.rowPx??I,r=t.barPx??En,a=Math.min(3,Math.max(0,(o-r)/2)),i=h=>h*o*t.scaleY+t.translateY,{origin:c,unit:l,reference:d,rows:f}=e,u=h=>s(c+h),m=n.idPrefix??"walkrow",p=(h,g)=>{let x=i(g);if(x<-r||x>t.height+r)return;let b=os(h.runs,t.scaleX).flatMap(S=>{let R=Qr(S,n.ramp),C=S.gap?Math.min(Sn,r):r,k=`${m}-${g}-${S.start}`,Q=_("rect",{x:u(S.start),y:x-C/2,width:Math.max(1,S.bp*t.scaleX),height:C,fill:"stops"in R?`url(#${k})`:R.fill});return"stops"in R?[_("linearGradient",{id:k},...R.stops.map((xe,W)=>_("stop",{offset:W/(R.stops.length-1),"stop-color":xe}))),Q]:[Q]}),w=l&&r>=ol?Vr(h.bp,l,t.scaleX).map(S=>_("line",{x1:u(S),x2:u(S),y1:x-r/2,y2:x+r/2,stroke:"white","stroke-width":1})):[],{call:y}=h,v=Kr(h,g===0?void 0:d,l,y),M=jr(v,u(h.bp),t.width),E=t.readouts??!0;return _("g",{"data-testid":g===0?"graph-walk-reference":"graph-walk-row"},...b,...w,...Jr(n.rowGenes?.get(h.name)??[],u,x,{rowPx:o,barPx:r}).map(S=>ul(S,x,r)),y&&_("rect",{"data-testid":"graph-walk-call",x:u(y.bp)-1,y:x-r/2-a,width:2,height:r+2*a,fill:ns(y)}),E&&_("text",{x:M.x,y:x+4,"font-family":"sans-serif","font-size":11,fill:y?.agrees===!1?Rn:"#333",stroke:M.halo?"white":void 0,"stroke-width":M.halo?3:void 0,"paint-order":"stroke","text-anchor":M.anchor},v))};return _("g",{},...[d,...f].map(p))}function pl(e){return e.walkStrip&&e.mode.drawsNodes&&!e.drawsPicture&&!e.popped&&!e.host&&e.walks>1}function ml(e,t){return e.wholeWalks||t.walkStrip&&!t.host}var je=6,as=260,gl=11,xl=3,bl=1.3,yl="#111",rs=3;function Ml(e,t,n){let s=e.pathVisits?.get(n.name)??[],o=[];for(let r of t){let a=r.axis;if(!a)continue;let i=te(r.name).name;for(let c of s){if(c.path!==i)continue;let{start:l,end:d}=Ke(a,c.start,c.start+n.length);d>0&&l<r.bp&&o.push({row:r.name,start:l,bp:d-l})}}return o}var ss=new WeakMap;function wl(e,t){let n=ss.get(e);if(n||(n=new Map,ss.set(e,n)),n.has(t))return n.get(t);let s=new Map(e.nodes.map(a=>[a.id,a.length])),o=(e.paths??[]).filter(a=>a.name===t),r;if(o.every(a=>a.start!==void 0)){r={ids:[],starts:[],ends:[]};for(let a of[...o].sort((i,c)=>i.start-c.start)){let i=a.start;for(let c of a.nodeIds){let l=s.get(c)??0;r.ids.push(c),r.starts.push(i),r.ends.push(i+l),i+=l}}}return n.set(t,r),r}function vl(e,t,n,s){let o=t.axis,r=o&&wl(e,t.name);if(!o||!r||n<0||n>t.bp)return;let a=o.reversed?o.start-n:o.start+n,i=.5/s,c=o.reversed?{start:o.start-t.bp,end:o.start}:{start:o.start,end:o.start+t.bp},l=Math.max(a-i,c.start),d=Math.min(a+i,c.end),f=0,u=r.starts.length;for(;f<u;){let g=f+u>>1;r.ends[g]<=l?f=g+1:u=g}let m,p=-1,h=!1;for(let g=f;g<r.starts.length&&r.starts[g]<d;g++){let x=r.ends[g]-r.starts[g],b=r.starts[g]<=a&&a<r.ends[g];(x>p||x===p&&b&&!h)&&(p=x,m=r.ids[g],h=b)}return m}function El(e,t){let n=t.maxHeight??as,s=t.labelPx??Math.max(...[e.reference,...e.rows].map(m=>m.label.length))*fe+16,o=e.rows.length+1,{rowPx:r,barPx:a,labelled:i,readouts:c}=_n(o,n-2*je,xl),l=Math.max(e.reference.bp,...e.rows.map(m=>m.bp),1),d=i?s:je,u=Math.max(1,t.width-d-je)/(l*(c?bl:1));return{scaleX:u,scaleY:1,translateX:d-e.origin*u,translateY:je+r/2,width:t.width,height:o*r+2*je,rowPx:r,barPx:a,readouts:c,labelled:i,boxesGenes:St(r,a)}}function Sl(e,t,n,s){let o=Math.round((s-t.translateY)/t.rowPx),r=[e.reference,...e.rows][o],a=(n-t.translateX)/t.scaleX-e.origin;return r&&o>=0&&a>=0&&a<=r.bp?{index:o,row:r,offset:a}:void 0}function Rl(e,t,n){let s=new Map([e.reference,...e.rows].map((r,a)=>[r.name,a])),o=r=>(e.origin+r)*t.scaleX+t.translateX;return _("g",{"data-testid":"graph-walk-marks"},...n.flatMap(r=>{let a=s.get(r.row);if(a===void 0)return[];let i=a*t.rowPx+t.translateY,c=o(r.start),l=Math.max(2,r.bp*t.scaleX),d=f=>_("rect",{x:c,y:f,width:l,height:rs,fill:yl});return[d(i-t.barPx/2-rs-1),d(i+t.barPx/2+1)]}))}function _l(e,t,n=new Set){return _("g",{"font-family":"sans-serif","font-size":gl,fill:"#333"},...(t.labelled?[e.reference,...e.rows]:[]).map((s,o)=>_("text",{x:6,y:o*t.rowPx+t.translateY+4,"font-weight":n.has(s.name)?600:void 0},s.label)))}function Nl(e,t,n){if(t?.size)return e.boxesGenes?n:{untracked:0,unread:0,...n,crowded:!0}}var ls=2,Rt=8192;function fs(){return typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,ls)}var is=!1;function cs(e,t,n){let s=Math.round(e*t);return s>Rt?(is||(is=!0,console.warn(`Canvas ${n} ${s}px exceeds the safe limit ${Rt}px and was clamped`)),Rt):s}function Nn(e,t,n){let s=fs(),o=cs(t,s,"width"),r=cs(n,s,"height");(e.width!==o||e.height!==r)&&(e.width=o,e.height=r);let a=`${t}px`,i=`${n}px`;e.style.width!==a&&(e.style.width=a),e.style.height!==i&&(e.style.height=i)}var qp=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1;let t=e.getContext("2d");if(!t)throw new Error("Canvas 2D context not available");this.canvas=e,this.ctx=t}setErrorHandler(e){}releaseOffscreenTargets(){}resize(e,t){Nn(this.canvas,e,t)}uploadGeometry(e){this.batch=e,this.highlightedEdge=null}setNodeHighlights(e){this.nodeHighlights=e}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t}updateTransform(e){this.transform=e}render(e){if(!this.transform)return;let n=this.ctx,{width:s,height:o}=n.canvas;e[3]<1&&n.clearRect(0,0,s,o),n.fillStyle=eo([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,s,o);let r=this.batch;r&&(n.lineCap="round",n.lineJoin="round",this.renderEdges(r),this.renderNodes(r),this.renderArrows(r))}renderEdges(e){let t=this.transform,n=this.ctx,s=this.highlightedEdge===null?void 0:e.edgeCurveRuns.get(this.highlightedEdge);for(let{color:o,items:r}of An(e.edgeCurves,(a,i)=>({color:_t(s,i)?it(a.color,this.highlightFactor):a.color,weight:a.thickness,last:_t(s,i)}))){n.strokeStyle=j(o),n.lineWidth=r[0].thickness*2*t.dpr,n.beginPath();for(let a of r){let i=a.curves[0];n.moveTo(i.x0*t.scaleX+t.translateX,i.y0*t.scaleY+t.translateY);for(let c of a.curves)n.bezierCurveTo(c.cx0*t.scaleX+t.translateX,c.cy0*t.scaleY+t.translateY,c.cx1*t.scaleX+t.translateX,c.cy1*t.scaleY+t.translateY,c.x1*t.scaleX+t.translateX,c.y1*t.scaleY+t.translateY)}n.stroke()}}renderNodes(e){let t=this.transform,n=this.ctx,s=new Map;for(let[o,r]of this.nodeHighlights){let a=e.nodeStrokeRuns.get(o);if(a)for(let i=a.start;i<a.start+a.count;i++)s.set(i,r)}for(let{color:o,items:r}of An(e.nodeStrokes,(a,i)=>{let c=s.get(i);return{color:c===void 0?a.color:it(a.color,c),weight:a.thickness,last:c!==void 0}})){n.strokeStyle=j(o),n.lineWidth=r[0].thickness*2*t.dpr,n.beginPath();for(let a of r){let i=a.points[0];n.moveTo(i.x*t.scaleX+t.translateX,i.y*t.scaleY+t.translateY);for(let c=1,l=a.points.length;c<l;c++){let d=a.points[c];n.lineTo(d.x*t.scaleX+t.translateX,d.y*t.scaleY+t.translateY)}}n.stroke()}}renderArrows(e){let t=this.transform,n=this.ctx,s=this.highlightedEdge===null?void 0:e.arrowRuns.get(this.highlightedEdge);for(let{color:o,items:r}of An(e.arrows,(a,i)=>({color:_t(s,i)?it(a.color,this.highlightFactor):a.color,weight:0,last:_t(s,i)}))){n.fillStyle=j(o),n.beginPath();for(let a of r){let[i,c,l,d]=Ll(a,t);n.moveTo(i.x,i.y),n.lineTo(c.x,c.y),n.lineTo(l.x,l.y),n.lineTo(d.x,d.y),n.closePath()}n.fill()}}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},Al=.25;function Ll(e,t){let n=Math.cos(e.angle),s=Math.sin(e.angle),o=e.x*t.scaleX+t.translateX,r=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,i=e.halfWidth*t.dpr,c=o-n*a,l=r-s*a,d=a*(1-Al);return[{x:o,y:r},{x:c-s*i,y:l+n*i},{x:o-n*d,y:r-s*d},{x:c+s*i,y:l-n*i}]}function _t(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function An(e,t){let n=new Map,s=new Map;for(let o=0,r=e.length;o<r;o++){let a=e[o],{color:i,weight:c,last:l}=t(a,o),d=l?s:n,f=`${i}:${c}`,u=d.get(f);u?u.items.push(a):d.set(f,{color:i,items:[a]})}return[...n.values(),...s.values()]}function Ln(e,t,n){let s=Math.round(t),o=Math.round(n);return`${e?`${e}:`:""}${Le(s)}-${Le(o)} (${ee(o-s)})`}function kl(e,t){let{field:n}=e.encoding,s=e.range?Ln(e.range.contig,e.range.start,e.range.end):void 0,o=n==="progress"?s:n==="reference"&&t?Ln(t.name,t.start,t.end):void 0,r=e.range?e.range.end-e.range.start:e.bp,a=r-e.bp;return{delta:e.referenceBp===void 0||r===e.referenceBp?"":` ${r>e.referenceBp?"+":"\u2212"}${ee(Math.abs(r-e.referenceBp))}`,outside:a>0?`, ${ee(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${ee(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:o,hover:o===s?void 0:s}}function Ol(e,t,n){let s=e.progress.get(t),o=e.range;if(s===void 0||!o)return;let r=Math.round(o.start+s*(o.end-o.start)-n/2);return`${o.contig}:${Le(r)}-${Le(r+n)}`}function Il(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),s=new Map;t.nodes.forEach(o=>{let r=n.get(o.name);if(o.order>=0&&r&&A(r)){let{refName:a,start:i}=r.stable;(s.get(a)??s.set(a,[]).get(a)).push({bp0:i,bp1:i+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of s.values())o.sort((r,a)=>r.bp0-a.bp0);return s}function Nt(e,t,n=!1){let s=0,o=e.length-1;for(;s<o;){let i=s+o>>1,c=e[i].bp1;(n?c<t:c<=t)?s=i+1:o=i}let r=e[s];if(t<=r.bp0)return r.x0;let a=r.bp1-r.bp0;return a>0?r.x0+(Math.min(t,r.bp1)-r.bp0)/a*(r.x1-r.x0):r.x0}function At(e,t,n){let s=Nt(e,t),o=Nt(e,n,!0);return{x0:Math.min(s,o),x1:Math.max(s,o)}}function Cl(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var ds=5,Tl=10,Pl=110,$l=3;function us(e){return e?"#b0b0b8":"#55555c"}function Bl(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 hs(e){let t=[];for(let n of e)t.every(s=>Math.abs(n.at-s.at)>=(n.width+s.width)/2+Tl)&&t.push(n);return t.map(({text:n,at:s})=>({text:n,at:s}))}function Xl(e,t,n,s){let o=e[0],r=e.at(-1);if(!o||!r)return;let a=t(o.x0),i=t(r.x1),c=r.bp1-o.bp0;if(i<=a||c<=0)return;let l=Bl(c/(i-a)*Pl),d=[],f=[];for(let u=Math.ceil(o.bp0/l)*l;u<=r.bp1;u+=l){let m=Math.round(t(Nt(e,u)))+.5;if(m>=0&&m<=n){d.push(m);let p=u.toLocaleString("en-US");f.push({text:p,at:m,width:s(p)})}}return{spans:[{x0:a,x1:i}],ticks:d,labels:hs(f)}}function Dl(e,t,n,s){let o=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:h})=>h>=0&&p<=n),r=o[0],a=o.at(-1);if(!r||!a)return;let i=(p,h)=>({text:p,at:h,width:s(p)}),c=(p,h)=>i(p.toLocaleString("en-US"),h),l=[],d=[],f=[],u=[];for(let{box:p,s0:h,s1:g}of o){l.push({x0:h,x1:g}),d.push(Math.round(h)+.5),g-h>=$l&&d.push(Math.round(g)+.5);let x=i(ee(p.bp1-p.bp0),(h+g)/2);x.width<=g-h&&f.push(x),p!==r.box&&u.push(c(p.bp0,h))}let m=[c(r.box.bp0,r.s0),c(a.box.bp1,a.s1)];return{spans:l,ticks:d,labels:hs([...m,...f,...u])}}function ps(e,t,n,s,o=!1){return(o?Xl:Dl)(e,t,n,s)}function Fl(e,t,n,s,o=!1){let{x:r,width:a,darkMode:i}=n;e.font="10px sans-serif";let c=ps(t,r,a,f=>e.measureText(f).width,o);if(!c)return;let l=us(i),d=s+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:f,x1:u}of c.spans)e.moveTo(Math.max(0,f),d),e.lineTo(Math.min(a,u),d);for(let f of c.ticks)e.moveTo(f,s),e.lineTo(f,s+ds);e.stroke();for(let{text:f,at:u}of c.labels)e.fillText(f,u,s+ds+2)}function Wl(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),s=[];return t.nodes.forEach(o=>{let r=n.get(o.name);o.order>=0&&r&&A(r)&&s.push({node:o.name,bp0:r.stable.start,bp1:r.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),s}function ql(e,t,n,s){let o=[];for(let r of e){let a=n(r.x0),i=n(r.x1);i>=0&&a<=s&&o.push({node:r.node,top0:t(r.bp0),top1:t(r.bp1),bottom0:a,bottom1:i})}return o}var Hl=3;function Yl(e,t,n,s){if(t<=0||s<0||s>t)return;let o=s/t,r,a=Hl;for(let i of e){let c=i.top0+(i.bottom0-i.top0)*o,l=i.top1+(i.bottom1-i.top1)*o,d=Math.max(0,Math.min(c,l)-n,n-Math.max(c,l));d<a&&(a=d,r=i.node)}return r}function ms(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 gs(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function Gl(e,t,n,{highlightNode:s,darkMode:o}){if(n<=0||t.length===0)return;let r=o?"255,255,255":"0,0,0";e.beginPath();for(let i of t)ms(e,i,n);e.fillStyle=`rgba(${r},0.07)`,e.fill(),e.beginPath();for(let i of t)gs(e,i,n);e.strokeStyle=`rgba(${r},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(i=>i.node===s);a&&(e.beginPath(),ms(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),gs(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function zl(e,t){let n=[],s=e.sequenceNew??[];return s.forEach((o,r)=>{let a=t.nodeMap.get(F(o.nodeName)),i=a===void 0?void 0:t.nodes[a],c=r;for(;c<e.path.length&&e.path[c].node!==a;)c+=1;let l=e.path[c]?.y;if(i&&l!==void 0){let d={readId:e.id,y:l,height:e.width,nodeY:i.y},f=u=>hr(i,u);for(let u of o.mismatches){let m=f(u.pos);if(m!==null){if(u.type==="insertion"){let p=r===0&&u.pos===e.firstNodeOffset||r===s.length-1&&u.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:m,seq:u.seq,softClip:p})}else if(u.type==="deletion"&&u.length!==void 0){let p=f(u.pos+u.length);p!==null&&n.push({...d,kind:"deletion",x0:m,x1:p})}else if(u.type==="substitution"&&u.seq!==void 0){let p=f(u.pos+u.seq.length);p!==null&&n.push({...d,kind:"substitution",x0:m,x1:p,seq:u.seq})}}}}}),n}function xs(e){return e.reads.flatMap(t=>zl(t,e))}function On(e){let t=e.trim().split(/[\s,]+/),n=[],s=0,o=()=>Number(t[s++]);for(;s<t.length;){let r=t[s++];r==="M"||r==="L"?n.push({op:r,x:o(),y:o()}):r==="H"?n.push({op:r,x:o()}):r==="V"?n.push({op:r,y:o()}):r==="Q"?n.push({op:r,x1:o(),y1:o(),x:o(),y:o()}):r==="C"?n.push({op:r,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):r==="Z"&&n.push({op:r})}return n}function vs(e){let t=1/0,n=-1/0;for(let s of e)"x"in s&&(t=Math.min(t,s.x),n=Math.max(n,s.x)),"x1"in s&&(t=Math.min(t,s.x1),n=Math.max(n,s.x1));return{x0:t,x1:n}}function bs(e,t,n){let s=On(e);return{commands:s,color:t,track:n,...vs(s)}}function Es(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?qo(n):t[n.id]]))}function ys(e,t,n){let{shapes:s}=e,o=l=>n.get(l.id),r=l=>t==="haplotype"?l.id:void 0,a=[...s.rectangles,...s.verticalRectangles].filter(l=>l.type===t).map(l=>({color:o(l),track:r(l),x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),i=gr(s.curves,t).map(l=>bs(l.path,o(l),r(l))),c=s.corners.filter(l=>l.type===t).map(l=>bs(l.path,o(l),r(l)));return{rects:a,shapes:[...i,...c]}}function Ul({layout:e,pathColors:t}){let n=Es(e,t),s=[];return e.nodes.forEach(o=>{if(o.order>=0){let r=On(xr(o));s.push({name:o.name,commands:r,...vs(r)})}}),{bounds:e.bounds,layers:[ys(e,"haplotype",n),ys(e,"read",n)],nodes:s,mismatches:xs(e).filter(o=>o.kind!=="insertion"||!o.softClip)}}function Ms(e,t,n,s){let o=0,r=0;for(let a of t)switch(a.op){case"M":o=a.x,r=a.y,e.moveTo(n(o),s(r));break;case"L":o=a.x,r=a.y,e.lineTo(n(o),s(r));break;case"H":o=a.x,e.lineTo(n(o),s(r));break;case"V":r=a.y,e.lineTo(n(o),s(r));break;case"Q":o=a.x,r=a.y,e.quadraticCurveTo(n(a.x1),s(a.y1),n(o),s(r));break;case"C":o=a.x,r=a.y,e.bezierCurveTo(n(a.x1),s(a.y1),n(a.x2),s(a.y2),n(o),s(r));break;case"Z":e.closePath();break}}function ws(e,t,n,s,o){let r=new Map;for(let a of t)if(n(a)){let i=s(a),c=r.get(i);c?c.push(a):r.set(i,[a])}for(let a of r.values()){e.fillStyle=s(a[0]),e.beginPath();for(let i of a)o(i);e.fill()}}var Kl=12,jl=.15;function Vl(e){return Math.max(jl,Math.min(1,e/Kl))}var Ql=.55;function Zl(e,t,n){let{x:s,y:o,width:r}=n,a=d=>s(d.x1)>=0&&s(d.x0)<=r,i=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;e.globalAlpha=1;for(let d of t.layers)ws(e,d.rects,a,i,f=>{let u=s(f.x0),m=o(f.y0);e.rect(u,m,s(f.x1)-u,o(f.y1)-m)}),ws(e,d.shapes,a,i,f=>{Ms(e,f.commands,s,o)});let c=n.darkMode?"#d0d0d0":"#000000",l=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 f=d.name===n.highlightNode;e.beginPath(),Ms(e,d.commands,s,o);let u=f?void 0:n.nodeColors?.get(d.name);e.fillStyle=f?"rgba(255,192,203,0.5)":u??l,e.strokeStyle=f?"#ff0000":c,e.globalAlpha=u?Ql:1,e.fill(),e.globalAlpha=f?1:Vl(s(d.x1)-s(d.x0)),e.stroke(),e.globalAlpha=1}ef(e,t.mismatches,n)}var Ss=12,Jl=6;function Rs(e){return Ss*e>=Jl}function kn(e,{x:t,width:n}){let[s,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(o)>=0&&t(s)<=n}function ef(e,t,n){let{x:s,y:o,yScale:r,darkMode:a}=n;if(!Rs(r)||t.length===0)return;let i=Ss*r;e.fillStyle="grey",e.beginPath();for(let c of t)if(c.kind==="deletion"&&kn(c,n)){let l=s(c.x0),d=o(c.y);e.rect(l,d,s(c.x1)-l,o(c.y+c.height)-d)}e.fill(),e.font=`${i}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let c of t)kn(c,n)&&(c.kind==="substitution"?e.fillText(c.seq,s(c.x0)+1,o(c.y+c.height)):c.kind==="insertion"&&e.fillText("*",s(c.x)-3,o(c.y+c.height)))}function tf(e,t){let n=[];for(let s of t){let o=e.get(s.refName),r=o?.[0],a=o?.at(-1);if(!o||!r||!a)continue;let i=Math.max(s.start,r.bp0),c=Math.min(s.end,a.bp1);c<=i||n.push({gene:s,...At(o,i,c),exons:s.exons.filter(l=>l.end>i&&l.start<c).map(l=>At(o,Math.max(l.start,i),Math.min(l.end,c)))})}return n}var In=22,nf=4,Lt=8,of="11px sans-serif",rf=8;function sf(e){let t=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,r)=>o.x-r.x||o.step-r.step),n=0,s=0;for(let{step:o}of t)n+=o,s=Math.max(s,n);return Math.min(nf,s)}function af(e,t,n,s,o=0){let{x:r,width:a,darkMode:i}=n,c=Math.max(1,Math.floor((s-o)/In)),l=[],d=i?"#e0e0e6":"#1c1c22";e.font=of,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let f=t.map(u=>({g:u,s0:r(u.x0),s1:r(u.x1)})).filter(({s0:u,s1:m})=>m>=0&&u<=a).sort((u,m)=>u.s0-m.s0);for(let{g:u,s0:m,s1:p}of f){let h=u.gene.strand>0?" \u2192":u.gene.strand<0?"\u2190 ":"",g=u.gene.strand<0?`${h}${u.gene.name}`:`${u.gene.name}${h}`,x=(Math.max(m,0)+Math.min(p,a))/2,b=e.measureText(g).width/2,w=Math.min(m,x-b),y=Math.max(p,x+b),v=l.findIndex(E=>E+rf<=w);v===-1&&(v=Math.min(l.length,c-1)),l[v]=Math.max(l[v]??-1/0,y);let M=s-v*In-Lt/2;e.beginPath(),e.moveTo(m,M+.5),e.lineTo(p,M+.5),e.stroke();for(let E of u.exons){let S=r(E.x0);e.fillRect(S,M-Lt/2,Math.max(1,r(E.x1)-S),Lt)}e.fillText(g,x,M-Lt/2-2)}}var V=12,ks=V+8,Os=8,_s=Os+3,cf=12;function lf(e,{colorScheme:t,referenceRamp:n,walks:s}){let o={...ht(e),referenceRamp:n},r=[];return e.nodes.forEach((a,i)=>{if(A(a)){let c=s?s.map(l=>{let d=l.colors.get(a.id);return d===void 0?ft:j(d)}):[j(pt(a,i,t,o))];r.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:c,faded:c.includes(ft)})}}),r.sort((a,i)=>a.bp0-i.bp0)}function Cn(e,t,n){let s=t*e.scale+e.translateX,o=n*e.scale+e.translateX;return s<o?[s,o]:[o,s]}var Ns=2;function Is(e,t,n){let s=-t.translateX/t.scale,o=(n-t.translateX)/t.scale,r=Math.min(s,o),a=Math.max(s,o),i=0,c=0;for(let l of e)i+=Math.max(0,Math.min(l.bp1,r)-l.bp0),c+=Math.max(0,l.bp1-Math.max(l.bp0,a));return t.scale>=0?{left:Math.round(i),right:Math.round(c)}:{left:Math.round(c),right:Math.round(i)}}function ff(e,t,n,s){if(s<0||s>V+Ns)return;let o,r=Ns;for(let a of e){let[i,c]=Cn(t,a.bp0,a.bp1),l=Math.max(0,i-n,n-c);l<=r&&(r=l,o=a.node)}return o}function df(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function Cs(e,t,n,s){let o=e.map(l=>{let[d,f]=Cn(t,l.bp0,l.bp1),u=Math.round(d*s);return{colors:l.colors,x0:d,px0:u,px1:Math.max(Math.round(f*s),u+1)}}).filter(l=>l.px1>0&&l.px0<n*s).sort((l,d)=>l.x0-d.x0),r=[],a=-1/0,i=[-1/0,-1/0];for(let{colors:l,px0:d,px1:f}of o){let u=Math.max(d,a);if(f>u){let m=i[0]<u?0:1;i[m]=f,r.push({colors:l,x0:u/s,x1:f/s,tier:m}),a=f}}return(r.length>0?r.at(-1).x1-r[0].x0:0)>=r.length*cf?r:r.map(({tier:l,...d})=>d)}function As(e,t,n,s){let o=n>0?t:t-_s;e.clearRect(o,0,_s,V);let r=t+n,a=r+n*Os;e.beginPath(),e.moveTo(r,V/2),e.lineTo(a,0),e.lineTo(a,V),e.closePath(),e.fillStyle=s,e.fill()}function Ls(e,t,n){return Math.round(e*V*n/t)/n}function uf(e,t,n,{width:s,lit:o,darkMode:r,dpr:a=1}){let i=r?"#ffffff":"#18181c";e.clearRect(0,0,s,ks);for(let l of Cs(t,n,s,a)){let{tier:d}=l,f=d!==void 0&&l.colors.length===1,u=f?2:l.colors.length;l.colors.forEach((m,p)=>{let h=f?d:p,g=Ls(h,u,a);e.fillStyle=m,e.fillRect(l.x0,g,l.x1-l.x0,Ls(h+1,u,a)-g)})}let c=Is(t,n,s);if(c.left>0&&As(e,0,1,i),c.right>0&&As(e,s,-1,i),o){let[l,d]=Cn(n,o.start,o.end),f=Math.max(d-l,3),u=(l+d)/2-f/2;e.strokeStyle=i,e.lineWidth=1.5,e.strokeRect(u,.75,f,V-1.5),o.anchor&&(e.beginPath(),e.moveTo(u+f/2,V),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function hf(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),s=[];return t.nodes.forEach((o,r)=>{let a=n.get(o.name);if(o.order>=0&&a&&A(a)){let i=a.stable.start;s.push({bp0:i,bp1:i+o.sequenceLength,index:r,node:o})}}),s.sort((o,r)=>o.bp0-r.bp0)}function pf(e,t,n){let s=0,o=e.length-1;for(;s<o;){let r=s+o+1>>1;e[r].bp0<=t?s=r:o=r-1}return[e[s],e[s-1]].find(r=>r&&n.has(r.index)&&r.bp0<=t&&t<=r.bp1)}function Ig(e,t,n){let s=hf(e,t),o=[];for(let r of t.tracks){let a=r.name?n.get(r.name):void 0;if(a?.length){let i=new Map;for(let c of r.path)c.node!==null&&c.y!==void 0&&!i.has(c.node)&&i.set(c.node,c.y);for(let c of a){let l=pf(s,c.start,i);if(l){let{node:d,bp0:f,bp1:u}=l,m=p=>d.x+(Math.min(p,u)-f)/(u-f)*d.pixelWidth;o.push({x0:m(c.start),x1:m(c.end),y:i.get(l.index),height:r.width})}}}}return o}function mf(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Cg(e,t,{x:n,y:s,width:o,darkMode:r}){if(t.length!==0){e.fillStyle=mf(r),e.beginPath();for(let a of t){let i=n(a.x0),c=Math.max(n(a.x1),i+1);if(c>=0&&i<=o){let l=s(a.y);e.rect(i,l,c-i,s(a.y+a.height)-l)}}e.fill()}}function gf(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function xf(e,t){let n=e.length,s=t.length,o=Array.from({length:n+1},()=>new Array(s+1).fill(0)),r=Array.from({length:n+1},()=>new Array(s+1).fill(!1));for(let i=n-1;i>=0;i--)for(let c=s-1;c>=0;c--){let l=Math.abs(e[i]-t[c])+o[i+1][c+1],d=n-i>s-c?o[i+1][c]:1/0,f=s-c>n-i?o[i][c+1]:1/0;o[i][c]=Math.min(l,d,f),r[i][c]=o[i][c]===l}let a=new Array(n).fill(void 0);for(let i=0,c=0;i<n&&c<s;)r[i][c]?a[i++]=c++:n-i>s-c?i++:c++;return a}function Ts(e,t){return e.map((n,s)=>({item:n,i:s})).sort((n,s)=>t(n.item)-t(s.item))}var $s=e=>e.spanningReads!==0;function Ps(e,t){return{...t,agrees:e.complete&&$s(t)?gf(e.bp,t.bp):void 0}}function bf(e,t){let n=new Map,s=new Set;e.forEach((i,c)=>{let l=t.find(d=>d.haplotype!==void 0&&d.haplotype===i.haplotype);l&&(s.add(l),n.set(c,Ps(i,l)))});let o=t.filter(i=>i.haplotype===void 0),r=Ts(e,i=>i.bp),a=[[r.filter(i=>i.item.complete),o.filter($s)],[r,o]];for(let[i,c]of a){let l=i.filter(f=>!n.has(f.i)),d=Ts(c.filter(f=>!s.has(f)),f=>f.bp);xf(l.map(f=>f.item.bp),d.map(f=>f.item.bp)).forEach((f,u)=>{if(f!==void 0){let m=l[u],p=d[f].item;s.add(p),n.set(m.i,Ps(m.item,p))}})}return n}function Pg(e,t){if(!t)return e;let n=new Map,s=new Map;for(let o of e)s.set(o.sample,[...s.get(o.sample)??[],o]);for(let[o,r]of s){let a=t[o];if(a)for(let[i,c]of bf(r,a))n.set(r[i],c)}return e.map(o=>({...o,call:n.get(o)}))}var Bs=_e(Je(),1),Xg=(0,K.createSvgIcon)((0,Bs.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{K as a,Ya as b,Ge as c,Ws as d,en as e,Ua as f,Ka as g,fc as h,wc as i,Yu as j,Lr as k,Oc as l,ju as m,yt as n,Ic as o,Cc as p,Pr as q,Mt as r,pn as s,wt as t,Pc as u,$c as v,Bc as w,Xc as x,j as y,ft as z,ut as A,da as B,ht as C,pt as D,ga as E,Dr as F,xn as G,Wc as H,Gc as I,Wr as J,qr as K,zc as L,vt as M,Qh as N,Zh as O,Jh as P,ep as Q,tp as R,re as S,Zc as T,el as U,tl as V,nl as W,mo as X,ya as Y,Ue as Z,En as _,Sn as $,Kr as aa,sl as ba,al as ca,St as da,fl as ea,es as fa,ts as ga,Rn as ha,dl as ia,_n as ja,hl as ka,pl as la,ml as ma,Ml as na,vl as oa,El as pa,Sl as qa,Rl as ra,_l as sa,Nl as ta,fs as ua,qp as va,Ma as wa,Xf as xa,Df as ya,Ln as za,kl as Aa,Ol as Ba,Kf as Ca,Ao as Da,jf as Ea,Lo as Fa,Qt as Ga,ko as Ha,Oo as Ia,Ba as Ja,Il as Ka,Cl as La,us as Ma,Fl as Na,Wl as Oa,ql as Pa,Yl as Qa,Gl as Ra,Ul as Sa,Zl as Ta,Rs as Ua,kn as Va,tf as Wa,In as Xa,sf as Ya,af as Za,ks as _a,lf as $a,Is as ab,ff as bb,df as cb,uf as db,Ig as eb,mf as fb,Cg as gb,Pg as hb,Yd as ib,Gd as jb,Fa as kb,zd as lb,Ud as mb,Zt as nb,Jt as ob,su as pb,au as qb,Xg as rb};
|
|
2
|
+
//# sourceMappingURL=chunk-PZE3GABA.js.map
|