jbrowse-plugin-graphgenomeviewer 6.18.0 → 6.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/chunks/{GraphGenomeView-KWFMWBUZ.js → GraphGenomeView-WIL37EP3.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-DVPKJ7RW.js → LinearGraphDisplay-IN6JHZVD.js} +2 -2
- package/dist/chunks/chunk-BHJALK4L.js +2 -0
- package/dist/chunks/{chunk-4NBOE4Y6.js.map → chunk-BHJALK4L.js.map} +4 -4
- package/dist/chunks/{chunk-7QKDZD5Q.js → chunk-BXZD5UKL.js} +2 -2
- package/dist/chunks/chunk-BXZD5UKL.js.map +7 -0
- package/dist/chunks/chunk-DGDSLDMB.js +3 -0
- package/dist/chunks/chunk-DGDSLDMB.js.map +7 -0
- package/dist/chunks/chunk-TFCWM3QU.js +3 -0
- package/dist/chunks/chunk-TFCWM3QU.js.map +7 -0
- package/dist/chunks/{renderSvg-RKHBL6EQ.js → renderSvg-A4RK2FEC.js} +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +1 -1
- package/src/GraphGenomeView/components/GraphCanvas.tsx +2 -2
- package/src/GraphGenomeView/components/TubeMapOverlay.tsx +57 -0
- package/src/GraphGenomeView/components/usePaneGestures.ts +2 -0
- package/src/GraphGenomeView/model.test.ts +53 -0
- package/src/GraphGenomeView/pane/fitViews.ts +157 -15
- package/src/GraphGenomeView/pane/graphViews.ts +49 -1
- package/src/GraphGenomeView/pane/hostViews.ts +9 -2
- package/src/GraphGenomeView/pane/launchActions.ts +39 -0
- package/src/GraphGenomeView/pane/loadActions.ts +25 -10
- package/src/GraphGenomeView/pane/paneBase.ts +7 -4
- package/src/GraphGenomeView/pane/renderingActions.ts +30 -3
- package/src/GraphGenomeView/pane/settingActions.ts +4 -0
- package/src/GraphGenomeView/tubeMapPanels.test.ts +121 -0
- package/src/GraphGenomeView/tubeMapPanels.ts +268 -0
- package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-4NBOE4Y6.js +0 -2
- package/dist/chunks/chunk-7QKDZD5Q.js.map +0 -7
- package/dist/chunks/chunk-GQOIHMWY.js +0 -3
- package/dist/chunks/chunk-GQOIHMWY.js.map +0 -7
- package/dist/chunks/chunk-MPLREBD5.js +0 -3
- package/dist/chunks/chunk-MPLREBD5.js.map +0 -7
- /package/dist/chunks/{GraphGenomeView-KWFMWBUZ.js.map → GraphGenomeView-WIL37EP3.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-DVPKJ7RW.js.map → LinearGraphDisplay-IN6JHZVD.js.map} +0 -0
- /package/dist/chunks/{renderSvg-RKHBL6EQ.js.map → renderSvg-A4RK2FEC.js.map} +0 -0
package/README.md
CHANGED
|
@@ -33,6 +33,12 @@ above it.
|
|
|
33
33
|
|
|
34
34
|

|
|
35
35
|
|
|
36
|
+
- **Panels per group.** A tube map splits into a panel per sample, haplotype or
|
|
37
|
+
sample table column. Split by superpopulation with GSTM1's box hovered, each
|
|
38
|
+
title counts its haplotypes carrying the gene: 6 of AFR's 12, none of EUR's.
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
36
42
|
## As its own view
|
|
37
43
|
|
|
38
44
|
**Add → Graph genome view** opens a whole GFA file. A graph track's **Launch →
|
|
@@ -52,6 +58,7 @@ node in the view bands its bp in the linear view:
|
|
|
52
58
|
- gbz-base haplotypes as walks: the number of walks through a node as its
|
|
53
59
|
thickness, walks lifted out as metro-map lanes or side by side, a panel per
|
|
54
60
|
walk or a row per sample, each shading from its start to its end
|
|
61
|
+
- Tube maps split into a panel per sample, haplotype or sample table column
|
|
55
62
|
- GAF reads in the tube map, with their mismatches, from a gbz-base track
|
|
56
63
|
- Figures as SVG: the graph track in the linear view's Export SVG, the graph
|
|
57
64
|
genome view's own Export SVG, or a JSON spec with no browser
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as C}from"./chunk-
|
|
1
|
+
import{a as C}from"./chunk-BXZD5UKL.js";import"./chunk-FTDRKDJC.js";import"./chunk-TFCWM3QU.js";import"./chunk-DGDSLDMB.js";import{o as d}from"./chunk-2N5OTRJM.js";import"./chunk-BHJALK4L.js";import"./chunk-ZWPNOQ72.js";import"./chunk-FC5FYQXH.js";import"./chunk-4BTEDZYU.js";import"./chunk-B6JUCSWJ.js";import"./chunk-CBIQCOGA.js";import"./chunk-YBLNN5FU.js";import"./chunk-AK4RVLBC.js";import"./chunk-NDRLCGPC.js";import"./chunk-TENPGIPX.js";import{g as x}from"./chunk-6OPB7FOJ.js";import{E as L,G as p,d as s,h as v,n,w as G,z as l}from"./chunk-ECD5B2ZM.js";import{a as y,b as a,c as r,d as i}from"./chunk-JMBDTNUR.js";var w=d()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),E=i(function({model:e}){let{classes:t}=w();return e.isLoading?r(l,{className:t.paper,"data-testid":"graph-genome-loading",children:[r("div",{className:t.row,children:[a(v,{variant:"h6",message:e.statusMessage}),a(n,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),a(G,{variant:"indeterminate"})]}):e.error?a(l,{className:t.paper,children:a(s,{error:e.error,onReset:()=>{e.retryLoad()}})}):a(l,{className:t.paper,"data-testid":"graph-genome-load-canceled",children:r("div",{className:t.row,children:[a(p,{variant:"h6",children:"Loading canceled"}),a(n,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),g=E;var F=`H VN:Z:1.0
|
|
2
2
|
S 1 ACGT
|
|
3
3
|
S 2 GGCC
|
|
4
4
|
S 3 TTAA
|
|
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
|
|
|
7
7
|
L 1 + 3 + 0M
|
|
8
8
|
L 2 + 4 + 0M
|
|
9
9
|
L 3 + 4 + 0M`,S=d()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),T=i(function({model:e}){let{classes:t}=S(),[m,M]=x("");function u(){let o=m.trim();o&&e.loadGFAFromLocation({uri:o,locationType:"UriLocation"})}function N(o){let c=o.target.files?.[0];o.target.value="",c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return r(l,{className:t.paper,children:[a("div",{className:t.header,children:a(p,{variant:"h6",children:"Load a GFA graph"})}),r("div",{className:t.column,children:[r("div",{className:t.rowCenter,children:[r(n,{variant:"outlined",component:"label",size:"small",children:["Choose file",a("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:o=>{N(o)}})]}),a(p,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),r("div",{className:t.rowEnd,children:[a(L,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:m,onChange:o=>{M(o.target.value)},onKeyDown:o=>{o.key==="Enter"&&u()},className:t.flex1}),a(n,{variant:"contained",onClick:()=>{u()},disabled:!m.trim(),children:"Open"})]})]}),a("div",{className:t.footer,children:a(n,{size:"small",onClick:()=>{e.loadGFA(F,"Example graph")},children:"Load 4-node example"})}),e.error?a(s,{error:e.error}):null]})}),P=T;var A=i(function({model:e}){return e.hasGraph?a(C,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?a(g,{model:e}):r(y,{children:[e.isLoading?a(g,{model:e}):null,a("div",{hidden:e.isLoading,children:a(P,{model:e})})]})}),J=A;export{J as default};
|
|
10
|
-
//# sourceMappingURL=GraphGenomeView-
|
|
10
|
+
//# sourceMappingURL=GraphGenomeView-WIL37EP3.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as g}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=LinearGraphDisplay-
|
|
1
|
+
import{a as g}from"./chunk-BXZD5UKL.js";import"./chunk-FTDRKDJC.js";import"./chunk-TFCWM3QU.js";import"./chunk-DGDSLDMB.js";import"./chunk-2N5OTRJM.js";import"./chunk-BHJALK4L.js";import"./chunk-ZWPNOQ72.js";import"./chunk-FC5FYQXH.js";import"./chunk-4BTEDZYU.js";import"./chunk-B6JUCSWJ.js";import"./chunk-CBIQCOGA.js";import"./chunk-YBLNN5FU.js";import"./chunk-AK4RVLBC.js";import"./chunk-NDRLCGPC.js";import"./chunk-TENPGIPX.js";import{g as T}from"./chunk-6OPB7FOJ.js";import"./chunk-ECD5B2ZM.js";import{b as e,c as l,d as y}from"./chunk-JMBDTNUR.js";var s=JBrowseExports["@jbrowse/display-kit/DisplayBackgroundProgress"];var v=s&&s.__esModule?s.default:s;var a=JBrowseExports["@jbrowse/display-kit/DisplayErrorBar"];var h=a&&a.__esModule?a.default:a;var i=JBrowseExports["@jbrowse/display-kit/DisplayLoadingOverlay"];var O=i&&i.__esModule?i.default:i;var n=JBrowseExports["@jbrowse/display-kit/TooLargeMessage"];var f=n&&n.__esModule?n.default:n;var t=JBrowseExports["@jbrowse/display-ui"],p=r=>t!=null&&r in Object(t)?t[r]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+r+"' from '@jbrowse/display-ui' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:r});var w=p("BottomRightCornerContext");var c=p("TrackOverlayPortal");var L=p("useChromeOverlayOverride");var j=t&&t.__esModule?t.default:t;var D={TooLarge:f,ErrorBar:h,Loading:O,BackgroundProgress:v};function d({model:r,phase:o,drawn:u,testid:_,style:C,children:E,...B}){let{TooLarge:G,ErrorBar:S,Loading:m,BackgroundProgress:P}=L()??D,[b,A]=T(null),{displayId:x}=r.configuration;return o==="tooLarge"?e("div",{style:{display:"contents"},"data-display-id":x,"data-display-phase":o,children:e(c,{children:e("div",{style:{pointerEvents:"auto"},children:e(G,{model:r})})})}):l("div",{...B,style:{position:"relative",height:r.height,...C},"data-testid":_,"data-display-id":x,"data-display-drawn":u,"data-display-phase":o,children:[e(w,{value:b,children:E}),l(c,{children:[e(S,{model:r,visible:o==="error"}),e(m,{model:r,visible:o==="loading"||o==="canceled",immediate:!u}),e("div",{ref:A,style:{position:"absolute",bottom:2,right:2,display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,pointerEvents:"none"},children:e(P,{model:r,visible:o==="ready"})})]})]})}var I=y(function({model:o}){return e(d,{model:o,phase:o.displayPhase,drawn:o.painted&&o.geometryPainted,testid:"linear-graph-display","data-layout":o.chosenLayoutMode,"data-cut-tier":o.cutTier,"data-recuts":o.recuts,"data-node-count":o.hasGraph?o.nodeCount:void 0,"data-loading":o.isLoading?"":void 0,style:{width:o.paneWidth,height:o.height,overflow:"hidden"},children:e(g,{model:o,ownChrome:!1})})}),Q=I;export{Q as default};
|
|
2
|
+
//# sourceMappingURL=LinearGraphDisplay-IN6JHZVD.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as L,b as at,c as B,d as pt,e as ht,g as ne,h as oe,i as re,k as ve,l as Re}from"./chunk-ZWPNOQ72.js";import{A as F,B as $,C as Me,D as Ee,E as te,F as Se,a as ct,b as K,c as lt,e as dt,f as Q,g as Z,i as ft,k as ut,n as ye,o as ee,z as we}from"./chunk-FC5FYQXH.js";import{e as mt}from"./chunk-4BTEDZYU.js";import{c as it}from"./chunk-B6JUCSWJ.js";import{a as be,b as st,c as J}from"./chunk-CBIQCOGA.js";function se(e){return`hsl(${e}, 70%, 50%)`}function _e(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*oe}var no=30;function gt({start:e,bp:t,reversed:n},o){let r=_e(e,o),s=_e(e+t,o);if(s-r<1)return[(r+s)/2];let a=Math.ceil((s-r)/no);return Array.from({length:a+1},(i,c)=>_e(e+t*(n?a-c:c)/a,o))}var Oe=Array.from({length:7},(e,t)=>({offset:t/6,color:se(t/6*oe)})),xt=`linear-gradient(to right, ${Oe.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function _(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function bt(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function oo(e){return bt(e).replaceAll('"',""")}function ro(e){if(typeof e=="string")return bt(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${oo(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(ro).join("")}</${e.tag}>`}var Ce="#2f8fd6",$e="#8e3fbf",Ie="#bdbdbd",j="#1c1c22",Pe=12,Le=4,Ne=12,so=6,io=3;function I(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Ae(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function yt(e,t,n,o){let{bp:r,gapBp:s,complete:a,stop:i}=e;if(!t)return`${I(r)}${Ae(r,n)}`;let c=s>0?` \xB7 ${I(s)} outside the cut`:"",l=o?` \xB7 called ${I(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(a){let d=r-t.bp,p=d===0?"":` (${d>0?"+":"\u2212"}${I(Math.abs(d))})`;return`${I(r)}${Ae(r,n)}${p}${c}${l}`}let f=n?"repeat":"window";if(i?.contigEnds&&r===0)return`contig ends ${i.shortBp>0?`${I(i.shortBp)} before`:"at"} the ${f}${l}`;let u=i?i.contigEnds?`contig ends inside the ${f}`:"does not rejoin the reference within the cut":"partial walk";return`\u2265 ${I(r)}${Ae(r,n)} \xB7 ${u}${c}${l}`}function wt(e,t,n){let o=t+6;return o+e.length*K<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Mt(e,t,n){if(t*n<io)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function Et(e,t){if(e.gap)return{fill:Ie};if(!t)return{fill:e.onReference?Ce:$e};if(e.referenceStart===void 0)return{fill:re};let n=gt({...e,start:e.referenceStart},t);return n.length===1?{fill:se(n[0])}:{stops:n.map(se)}}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 ao(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function co(e,t){let n=new Map;for(let o of e){let r=t.get(o.name);if(!o.axis||!r)continue;let s=o.axis,a=({start:i,end:c})=>({start:Math.max(0,i),end:Math.min(o.bp,c)});n.set(o.name,r.map(i=>({name:i.name,...a(ke(s,i.start,i.end)),exons:i.exons.map(c=>a(ke(s,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 lo=9,fo=5.2,uo=8,St=(e,t)=>Math.min(2,(e-t)/2-1);function vt(e,t){return St(e,t)>=1}function Rt(e,t,n,{rowPx:o=Z,barPx:r=Pe}={}){if(!vt(o,r))return[];let s=St(o,r),a=e.map(l=>{let f=t(l.start);return{g:l,x:f,w:Math.max(2,t(l.end)-f)}}),i=[],c=new Set((r>=uo?[...a]:[]).sort((l,f)=>l.w-f.w).filter(({g:l,x:f,w:u})=>{let d=l.name.length*fo/2,p=[f+u/2-d,f+u/2+d];return 2*d>u+6||i.some(([m,h])=>p[0]<h+2&&p[1]>m-2)?!1:(i.push(p),!0)}));return a.map(l=>({name:l.g.name,x:l.x,y:n-r/2-s,w:l.w,h:r+2*s,exons:l.g.exons.map(f=>({x:t(f.start),w:Math.max(1,t(f.end)-t(f.start))})),label:c.has(l)?{x:l.x+l.w/2,y:n+3,size:lo}:void 0}))}var Te=e=>`${e} row${e===1?"":"s"}`;function po(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??xt,ramp:!0}:{kind:"bar",fill:Ce},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?re:$e},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(o=>o.gapBp>0)&&n.push({swatch:{kind:"gap",fill:Ie},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 ${Te(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${Te(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${Te(t.genes.unread)}`,note:!0})),n}var _t="#111",Ot="#9e9e9e",Be="#c62828";function At(e){return e.agrees===!1?Be:e.spanningReads===0?Ot:_t}function ho(e,t,n,o="walk-key"){let r=0,s=e.flatMap((a,i)=>{let c=`${o}-ramp-${i}`,l=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?_("linearGradient",{id:c},...Oe.map(d=>_("stop",{offset:d.offset,"stop-color":d.color}))):void 0,f=a.note?void 0:a.swatch.kind==="gene"?_("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:j,"stroke-width":1.5}):_("rect",{x:r,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Le:8,rx:2,fill:l?`url(#${c})`:a.swatch.fill}),u=_("text",{x:a.note?r:r+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return r+=(a.note?0:23)+a.label.length*K+16,[l,f,u].filter(d=>d!==void 0)});return{width:r,tree:_("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function mo(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(Z,o>=1?Math.floor(o):o));return{rowPx:r,barPx:r<=3?r:Math.max(3,Math.round(r*.6)),labelled:r>=Ne,readouts:r>=Ne}}function Tt(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let i=0,c=0;for(let u of r)u.onReference?i+=u.bp:c+=u.bp;let l=i>=c,f=r.find(u=>u.onReference===l);o.push({start:r[0].start,bp:i+c,onReference:l,referenceStart:l?f.referenceStart:void 0,...f.reversed?{reversed:!0}:{}})}r=[]}},a=0;for(let i of e){if(i.gap||i.bp>=n){s(),a=0,o.push(i);continue}r.push(i),a+=i.bp,a>=n&&(s(),a=0)}return s(),o}function go(e,t,n){return _("g",{class:"row-gene","data-testid":"graph-walk-gene"},_("title",{},e.name),...e.exons.map(o=>_("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:j,opacity:.35})),_("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:j,"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:j,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function xo(e,t,n={}){let o=h=>h*t.scaleX+t.translateX,r=t.rowPx??Z,s=t.barPx??Pe,a=Math.min(3,Math.max(0,(r-s)/2)),i=h=>h*r*t.scaleY+t.translateY,{origin:c,unit:l,reference:f,rows:u}=e,d=h=>o(c+h),p=n.idPrefix??"walkrow",m=(h,g)=>{let x=i(g);if(x<-s||x>t.height+s)return;let y=Tt(h.runs,t.scaleX).flatMap(b=>{let v=Et(b,n.ramp),C=b.gap?Math.min(Le,s):s,N=`${p}-${g}-${b.start}`,W=_("rect",{x:d(b.start),y:x-C/2,width:Math.max(1,b.bp*t.scaleX),height:C,fill:"stops"in v?`url(#${N})`:v.fill});return"stops"in v?[_("linearGradient",{id:N},...v.stops.map((eo,to)=>_("stop",{offset:to/(v.stops.length-1),"stop-color":eo}))),W]:[W]}),M=l&&s>=so?Mt(h.bp,l,t.scaleX).map(b=>_("line",{x1:d(b),x2:d(b),y1:x-s/2,y2:x+s/2,stroke:"white","stroke-width":1})):[],{call:w}=h,S=yt(h,g===0?void 0:f,l,w),E=wt(S,d(h.bp),t.width),R=t.readouts??!0;return _("g",{"data-testid":g===0?"graph-walk-reference":"graph-walk-row"},...y,...M,...Rt(n.rowGenes?.get(h.name)??[],d,x,{rowPx:r,barPx:s}).map(b=>go(b,x,s)),w&&_("rect",{"data-testid":"graph-walk-call",x:d(w.bp)-1,y:x-s/2-a,width:2,height:s+2*a,fill:At(w)}),R&&_("text",{x:E.x,y:x+4,"font-family":"sans-serif","font-size":11,fill:w?.agrees===!1?Be:"#333",stroke:E.halo?"white":void 0,"stroke-width":E.halo?3:void 0,"paint-order":"stroke","text-anchor":E.anchor},S))};return _("g",{},...[f,...u].map(m))}function bo(e){return e.id.endsWith("-")?"-":"+"}function yo(e,t){return t===bo(e)?e.id:`-${e.id}`}function wo(e,t){let n=e.map(()=>{}),o=0,r=0;for(;r<e.length&&e[r]!==void 0;r++)n[r]=o,o+=e[r];let s=t;for(let a=e.length-1;a>r&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Mo(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=wo(t,e.pathLength),r=o.flatMap((d,p)=>d===void 0?[]:[p]),s=d=>o[r[d]],a=d=>s(d)+t[r[d]],i=0,c=(d,p=!1)=>{for(;i<r.length&&a(i)<d;)i++;for(let m=i;m<r.length&&s(m)<=d;m++){let h=a(m);if(d<h||p&&d===h)return{s:r[m],local:d-s(m),room:h-d}}},l=d=>{for(let p=i;p<r.length;p++)if(s(p)>d)return s(p)-d;return 1/0},f=(d,p)=>{let m=n[d],h=m.at(-1);p.type==="substitution"&&h?.type==="substitution"&&h.pos+h.seq.length===p.pos?h.seq+=p.seq:m.push(p)},u=e.pathStart;for(let d of it(e.cs))if(d.op==="match")u+=d.length;else if(d.op==="substitution"){let p=c(u);p&&f(p.s,{type:"substitution",pos:p.local,seq:d.seq}),u+=1}else if(d.op==="insertion"){let p=c(u,u===e.pathEnd);p&&f(p.s,{type:"insertion",pos:p.local,seq:d.seq})}else{let p=d.length;for(;p>0;){let m=c(u),h=Math.min(p,m?m.room:l(u));m&&f(m.s,{type:"deletion",pos:m.local,length:h}),u+=h,p-=h}}return n}function Mi(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let a=s.path.map(f=>o.get(f.name)),i=a.flatMap((f,u)=>f?[u]:[]),c=i[0],l=i.at(-1);if(c!==void 0&&l!==void 0){let f=Mo(s,a.map(p=>p?.length)),u=i.map(p=>yo(a[p],s.path[p].strand)),d=a[l].length;r.push({id:n+r.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:i.map((p,m)=>({nodeName:u[m],mismatches:f[p]})),firstNodeOffset:c===0?s.pathStart:0,finalNodeCoverLength:l===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?void 0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return r}var Eo=["#6baed6","#4292c6","#2171b5","#08519c"],So=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Nt(e){let t=e.is_reverse?So:Eo;return t[e.id%t.length]}var ie=8,De=34,ae=12,vo=60;function Ro({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function a(c){let l=Math.ceil(e/c),f=Math.floor((o-(c-1)*ie)/c),u=(r-l*De-(l-1)*ie)/l,d=(f-2*ae)/t.w,p=t.h>0?(u-2*ae)/t.h:1/0,m=n?d:Math.min(d,p),h=n?t.h:t.h*m,g=Math.floor(Math.max(vo,Math.min(h+2*ae,u)));return{columns:c,width:f,height:g,scale:m,total:l*(g+De)+(l-1)*ie}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let i=a(1);for(let c=2;c<=e;c++){let l=a(c);l.scale>i.scale&&(i=l)}return i}var _o=[{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 Oo(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 kt(e,t){let n=new Map(t.map((r,s)=>[r,s])),o=r=>n.get(r)??t.length;return e.map((r,s)=>({name:r,i:s})).sort((r,s)=>o(r.name)-o(s.name)||r.i-s.i).map(({name:r})=>r)}function Ao(e,t,n=[]){let o=kt(e,n),r={columns:void 0,count:e.length,cells:e.map(l=>o.indexOf(l))};if(t==="walk")return r;let s=e.map(l=>{let[f,u,d]=l.split("#"),p=Number(u);return d!==void 0&&Number.isInteger(p)&&p>=0?{sample:f,column:Math.max(0,p-1)}:void 0}),a=kt([...new Set(s.flatMap(l=>l?[l.sample]:[]))],n),i=Math.max(1,...s.map(l=>l?l.column+1:1)),c=s.map(l=>l?a.indexOf(l.sample)*i+l.column:-1);return c.includes(-1)||new Set(c).size<c.length?r:{columns:i,count:a.length*i,cells:c}}var It=2,ce=8192;function Pt(){return typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,It)}var Ct=!1;function $t(e,t,n){let o=Math.round(e*t);return o>ce?(Ct||(Ct=!0,console.warn(`Canvas ${n} ${o}px exceeds the safe limit ${ce}px and was clamped`)),ce):o}function Xe(e,t,n){let o=Pt(),r=$t(t,o,"width"),s=$t(n,o,"height");(e.width!==r||e.height!==s)&&(e.width=r,e.height=s);let a=`${t}px`,i=`${n}px`;e.style.width!==a&&(e.style.width=a),e.style.height!==i&&(e.style.height=i)}var Ti=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){Xe(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:o,height:r}=n.canvas;e[3]<1&&n.clearRect(0,0,o,r),n.fillStyle=at([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,o,r);let s=this.batch;if(!s)return;n.lineCap="round",n.lineJoin="round";let a=this.highlightFactor,i=this.edgeRun(s.edgeCurveRuns);for(let{color:f,items:u}of G(s.edgeCurves,(d,p)=>({color:le(i,p)?B(d.color,a):d.color,weight:d.thickness,last:le(i,p)})))this.strokeCurves(u,f);let c=this.liftedStrokes(s);for(let{color:f,items:u}of G(s.nodeStrokes,(d,p)=>{let m=c.get(p);return{color:m===void 0?d.color:B(d.color,m),weight:d.thickness,last:m!==void 0}}))this.strokeNodes(u,f);let l=this.edgeRun(s.arrowRuns);for(let{color:f,items:u}of G(s.arrows,(d,p)=>({color:le(l,p)?B(d.color,a):d.color,weight:0,last:le(l,p)})))this.fillArrows(u,f)}renderHighlights(){let e=this.ctx;e.clearRect(0,0,e.canvas.width,e.canvas.height);let t=this.batch;if(!this.transform||!t)return;e.lineCap="round",e.lineJoin="round";let n=this.highlightFactor,o=Lt(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:i}of G(o,c=>({color:B(c.color,n),weight:c.thickness,last:!1})))this.strokeCurves(i,a);let r=[...this.liftedStrokes(t)];for(let{color:a,items:i}of G(r,([c,l])=>({color:B(t.nodeStrokes[c].color,l),weight:t.nodeStrokes[c].thickness,last:!1})))this.strokeNodes(i.map(([c])=>t.nodeStrokes[c]),a);let s=Lt(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:i}of G(s,c=>({color:B(c.color,n),weight:0,last:!1})))this.fillArrows(i,a)}edgeRun(e){return this.highlightedEdge===null?void 0:e.get(this.highlightedEdge)}liftedStrokes(e){let t=new Map;for(let[n,o]of this.nodeHighlights){let r=e.nodeStrokeRuns.get(n);if(r)for(let s=r.start;s<r.start+r.count;s++)t.set(s,o)}return t}strokeCurves(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.curves[0];o.moveTo(s.x0*n.scaleX+n.translateX,s.y0*n.scaleY+n.translateY);for(let a of r.curves)o.bezierCurveTo(a.cx0*n.scaleX+n.translateX,a.cy0*n.scaleY+n.translateY,a.cx1*n.scaleX+n.translateX,a.cy1*n.scaleY+n.translateY,a.x1*n.scaleX+n.translateX,a.y1*n.scaleY+n.translateY)}o.stroke()}strokeNodes(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.points[0];o.moveTo(s.x*n.scaleX+n.translateX,s.y*n.scaleY+n.translateY);for(let a=1,i=r.points.length;a<i;a++){let c=r.points[a];o.lineTo(c.x*n.scaleX+n.translateX,c.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t){let n=this.transform,o=this.ctx;o.fillStyle=L(t),o.beginPath();for(let r of e){let[s,a,i,c]=No(r,n);o.moveTo(s.x,s.y),o.lineTo(a.x,a.y),o.lineTo(i.x,i.y),o.lineTo(c.x,c.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},To=.25;function No(e,t){let n=Math.cos(e.angle),o=Math.sin(e.angle),r=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,i=e.halfWidth*t.dpr,c=r-n*a,l=s-o*a,f=a*(1-To);return[{x:r,y:s},{x:c-o*i,y:l+n*i},{x:r-n*f,y:s-o*f},{x:c+o*i,y:l-n*i}]}function Lt(e,t){return t?e.slice(t.start,t.start+t.count):[]}function le(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function G(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let a=e[r],{color:i,weight:c,last:l}=t(a,r),f=l?o:n,u=`${i}:${c}`,d=f.get(u);d?d.items.push(a):f.set(u,{color:i,items:[a]})}return[...n.values(),...o.values()]}var ko="#daa520",Co=1,$o=2,Io=4;function $i(e,t,n,o=r=>r){let r=s=>{let a=t(s)*2;return n?.nodeIds.has(s)?Math.max(a,n.walks.length*Io):a};return e.flatMap(s=>s.exonsByNode.map(({nodeId:a,d:i})=>({key:`${s.gene.name}-${s.gene.start}-${a}`,d:o(i),inner:r(a)+2*Co})))}function Ii(e,t){if(e.length===0)return;let n=(o,r,s)=>_("path",{d:o.d,fill:"none",stroke:r,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return _("g",{},_("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},_("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*$o)),...e.map(o=>n(o,"#000",o.inner)))),_("rect",{width:t.width,height:t.height,fill:ko,mask:`url(#${t.id})`}))}function qe(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${F(o)}-${F(r)} (${$(r-o)})`}function Po(e,t){let{field:n}=e.encoding,o=e.range?qe(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?qe(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${$(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${$(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${$(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function Lo(e,t,n){let o=e.progress.get(t),r=e.range;if(o===void 0||!r)return;let s=Math.round(r.start+o*(r.end-r.start)-n/2);return`${r.contig}:${F(s)}-${F(s+n)}`}var Bo=50;function Bt(e,t){return t>0?Math.max(1,e/t):Bo}function Do(e){let t=new Set,n=1/0,o=-1/0;for(let r of e)t.add(r.minY),n=Math.min(n,r.minY),o=Math.max(o,r.minY);return t.size>1?(o-n)/(t.size-1):void 0}function Xo(e,t,n){let o=Bt(t,e.length);return{x:o,y:n>0?Bt(n,e.length):Do(e)??o}}function Dt(e,t,n,o){return e===void 0?Xo(t,n,o):typeof e=="number"?{x:e,y:e}:e}function qo(e,t,n){let o=e.get(t);o||(o=new Map,e.set(t,o));let r=o.get(n);return r||(r=[],o.set(n,r)),r}function Xt(e,t,n,o,r,s,a){let i=Math.floor(n/t.x),c=Math.floor(r/t.x),l=Math.floor(o/t.y),f=Math.floor(s/t.y);for(let u=i;u<=c;u++)for(let d=l;d<=f;d++)qo(e,u,d).push(a)}function qt(e,t,n,o,r,s){let a=Math.floor((n-r)/t.x),i=Math.floor((n+r)/t.x),c=Math.floor((o-s)/t.y),l=Math.floor((o+s)/t.y),f=[],u=new Set;for(let d=a;d<=i;d++){let p=e.get(d);if(p)for(let m=c;m<=l;m++){let h=p.get(m);if(h)for(let g of h)u.has(g)||(u.add(g),f.push(g))}}return f}var Ft=class{constructor(e,t){this.cells=new Map;let n=[],o=0,r=0;for(let[s,a]of Object.entries(e))for(let i=0;i<a.length-1;i++){let c=a[i],l=a[i+1],f=Math.min(c.x,l.x),u=Math.min(c.y,l.y),d=Math.max(c.x,l.x),p=Math.max(c.y,l.y);o+=d-f,r+=p-u,n.push({entry:{nodeId:s,segmentIdx:i},minX:f,minY:u,maxX:d,maxY:p})}this.cellSize=Dt(t,n,o,r);for(let s of n)Xt(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return qt(this.cells,this.cellSize,e,t,n,o)}},Gt=class{constructor(e,t,n,o,r,s,a=0,i,c=!1){this.cells=new Map,this.edgeCurves=pt(e,t,o,s,a,i,c);let l=[],f=0,u=0;for(let d=0;d<t.edges.length;d++){let p=t.edges[d],m=e[p.from],h=e[p.to],g=this.edgeCurves.get(d);if(m?.length&&h?.length&&g){let{minX:x,minY:y,maxX:M,maxY:w}=ft(g),S=p.pathIds?.length??0;if(n&&S>0){let E=0,R=0;for(let b of ee(m,h,S,o))E=Math.max(E,Math.abs(b.x)),R=Math.max(R,Math.abs(b.y));x-=E,y-=R,M+=E,w+=R}f+=M-x,u+=w-y,l.push({ei:d,minX:x,minY:y,maxX:M,maxY:w})}}this.cellSize=Dt(r,l,f,u);for(let d of l)Xt(this.cells,this.cellSize,d.minX,d.minY,d.maxX,d.maxY,d.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,o=n){return qt(this.cells,this.cellSize,e,t,n,o)}};function Kt(e,t,n,o,r,s){let a=r-n,i=s-o,c=a*a+i*i;if(c===0)return Math.hypot(e-n,t-o);let l=Math.max(0,Math.min(1,((e-n)*a+(t-o)*i)/c));return Math.hypot(e-(n+l*a),t-(o+l*i))}function Fo(e,t,n,o,r,s,a,i,c,l){let f=1/0,u=20,d=n,p=o;for(let m=1;m<=u;m++){let h=m/u,g=1-h,x=g*g*g*n+3*g*g*h*r+3*g*h*h*a+h*h*h*c,y=g*g*g*o+3*g*g*h*s+3*g*h*h*i+h*h*h*l;f=Math.min(f,Kt(e,t,d,p,x,y)),d=x,p=y}return f}function Go(e,t,n){return Fo(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function Yt(e,t,n,o=1){let r=1/0;for(let s of n){let a=Go(e,t,o===1?s:{x0:s.x0,y0:s.y0*o,cx0:s.cx0,cy0:s.cy0*o,cx1:s.cx1,cy1:s.cy1*o,x1:s.x1,y1:s.y1*o});a<r&&(r=a)}return r}var Ht=new WeakMap;function jt(e,t){let n=Ht.get(e);if(n?.version===t)return n.index;let o=new Ft(e);return Ht.set(e,{version:t,index:o}),o}var Wt=new WeakMap;function Yo(e,t,n,o,r,s,a,i=!1){let c=Wt.get(e);if(c?.graph===t&&c.drawPaths===n&&c.scaleX===o.scaleX&&c.scaleY===o.scaleY&&c.version===r&&c.deletions===s&&c.routes===a&&c.stranded===i)return c.index;let l=new Gt(e,t,n,o,void 0,s,r,a,i);return Wt.set(e,{graph:t,drawPaths:n,scaleX:o.scaleX,scaleY:o.scaleY,version:r,index:l,deletions:s,routes:a,stranded:i}),l}var Ho=5;function Wi(e,t,n,o,r=0,s){let a=ye(o),i=jt(e,r),c=p=>Math.max(Ho,p)/o.scaleX,l=c(s?.maxHalfWidthPx??0),f=i.query(t,n,l,l/a),u=null,d=1/0;for(let{nodeId:p,segmentIdx:m}of f){let h=e[p],g=Kt(t,n*a,h[m].x,h[m].y*a,h[m+1].x,h[m+1].y*a);g<d&&g<c(s?.halfWidthPx(p)??0)&&(d=g,u=p)}return u}function Wo(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,a=1;for(let[i,c]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(i===0){if(c<0)return!1}else i<0?s=Math.max(s,c/i):a=Math.min(a,c/i);return s<=a}function Ut(e,t,n=0){let o=jt(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let a=new Set,i=o.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:c,segmentIdx:l}of i){let f=e[c];!a.has(c)&&Wo(r(f[l]),r(f[l+1]),s)&&a.add(c)}return a}}function Ki(e,t,n,o,r,s,a=0,i,c,l,f=!1){let u=ye(r),d=10/r.scaleX,p=Yo(e,t,s,r,a,i,l,f),m=p.query(n,o,d,d/u),h=null,g=d;for(let x of m){let y=t.edges[x],M=e[y.from],w=e[y.to];if(!M?.length||!w?.length||c?.has(x))continue;let S=y.pathIds?.length??0,E=p.getCurves(x);if(!E)continue;let R;if(!s||S===0)R=Yt(n,o*u,E,u);else{let b=1/0;for(let v of ee(M,w,S,r)){let C=v.x===0&&v.y===0?E:ut(E,v.x,v.y),N=Yt(n,o*u,C,u);N<b&&(b=N)}R=b}R<g&&(g=R,h=x)}return h}var zt=3.4,Fe=6,Ko=8,jo=18,Uo=2,zo=ct+lt;function Vt(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],r=s=>+(s/n).toFixed(n===1?0:1);return`${r(e.covered*t)} of ${r(t)} ${o}`}function Jt(e,t,n,o){let r=n/2;return Qt(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:a,y:i}=t(s.at),c=Vt(s);return{item:s,x:a,y:i+n+jo,text:c?`${s.gene.name} \xB7 ${c}`:s.gene.name,fallback:c?`${s.gene.name} \u2026`:void 0,stack:Uo,fits:l=>[...o({x0:l.x0-r,x1:l.x1+r,y0:l.y0-r,y1:l.y1+r})].every(f=>s.nodeIds.has(f))}})}function Qt(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Vo(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:a}=e.axisScale,i={width:t,height:n},c=b=>({x:b.x*s+o,y:b.y*a+r}),l=e.drawnRowLabels.map(({label:b,y:v})=>we(b,v*a+r)),f=e.referenceStripZonePx??0;f>0&&l.push({x0:0,x1:t,y0:0,y1:f}),e.legendSize.width>0&&l.push({x0:t-Fe-e.legendSize.width,x1:t,y0:0,y1:f+Fe+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*K*1.2,y0:0,y1:44});let u=dt(i,l),d=e.drawnRowLabels.length>0,p=d?Math.min(...e.drawnRowLabels.map(b=>b.y)):1/0,m=e.contigThickness*zt,h=(b,v)=>{let{x:C,y:N}=c({x:b.labelAt.x,y:Math.min(b.labelAt.y,p)}),W=N-m/2-v;return{x:C,y:d?Math.max(W,zo):W}},g=Qt(e.bubbleHalos.filter(b=>!b.tick),b=>b.members),x=Q(g.map(b=>({item:b,...h(b,6),text:b.label})),i,u),y=e.bubbleHalos.filter(b=>b.tick&&!b.whole).map(b=>({item:b,...h(b,2)})).filter(b=>b.x>=0&&b.x<=t&&b.y>=0&&b.y<=n),M=Q(Jt(e.genePins,c,e.contigThickness,Ut(e.nodePositions??{},{scaleX:s,scaleY:a,translateX:o,translateY:r},e.positionsVersion)),i,u),w=e.nodePositions&&e.labelsNodeSizes?Me({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:o,translateY:r,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},S=te(w.deletions,u),E=Q(g.flatMap(b=>b.routes.map(v=>{let{x:C,y:N}=c(v.at);return{item:{halo:b,route:v},x:C,y:N+4,text:v.text,stack:Ko}})),i,u),R=te(w.nodes,u,Ee(t,n));return{bubbles:x,ticks:y,genes:M,routes:E,sizes:[...S,...R]}}function Ge({graph:e,layout:t}){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach((r,s)=>{let a=n.get(r.name);if(r.order>=0&&a&&J(a)){let{refName:i,start:c}=a.stable;(o.get(i)??o.set(i,[]).get(i)).push({name:r.name,index:s,bp0:c,bp1:c+a.length,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,a)=>s.bp0-a.bp0);return o}function de(e,t,n=!1){let o=0,r=e.length-1;for(;o<r;){let i=o+r>>1,c=e[i].bp1;(n?c<t:c<=t)?o=i+1:r=i}let s=e[o];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function fe(e,t,n){let o=de(e,t),r=de(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function Jo(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Zt=5,Qo=10,Zo=110,er=3;function en(e){return e?"#b0b0b8":"#55555c"}function tr(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 tn(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+Qo)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function nr(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let a=t(r.x0),i=t(s.x1),c=s.bp1-r.bp0;if(i<=a||c<=0)return;let l=tr(c/(i-a)*Zo),f=[],u=[];for(let d=Math.ceil(r.bp0/l)*l;d<=s.bp1;d+=l){let p=Math.round(t(de(e,d)))+.5;if(p>=0&&p<=n){f.push(p);let m=d.toLocaleString("en-US");u.push({text:m,at:p,width:o(m)})}}return{spans:[{x0:a,x1:i}],ticks:f,labels:tn(u)}}function or(e,t,n,o){let r=e.map(m=>({box:m,s0:t(m.x0),s1:t(m.x1)})).filter(({s0:m,s1:h})=>h>=0&&m<=n),s=r[0],a=r.at(-1);if(!s||!a)return;let i=(m,h)=>({text:m,at:h,width:o(m)}),c=(m,h)=>i(m.toLocaleString("en-US"),h),l=[],f=[],u=[],d=[];for(let{box:m,s0:h,s1:g}of r){l.push({x0:h,x1:g}),f.push(Math.round(h)+.5),g-h>=er&&f.push(Math.round(g)+.5);let x=i($(m.bp1-m.bp0),(h+g)/2);x.width<=g-h&&u.push(x),m!==s.box&&d.push(c(m.bp0,h))}let p=[c(s.box.bp0,s.s0),c(a.box.bp1,a.s1)];return{spans:l,ticks:f,labels:tn([...p,...u,...d])}}function nn(e,t,n,o,r=!1){return(r?nr:or)(e,t,n,o)}function rr(e,t,n,o,r=!1){let{x:s,width:a,darkMode:i}=n;e.font="10px sans-serif";let c=nn(t,s,a,u=>e.measureText(u).width,r);if(!c)return;let l=en(i),f=o+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:d}of c.spans)e.moveTo(Math.max(0,u),f),e.lineTo(Math.min(a,d),f);for(let u of c.ticks)e.moveTo(u,o),e.lineTo(u,o+Zt);e.stroke();for(let{text:u,at:d}of c.labels)e.fillText(u,d,o+Zt+2)}function sr(e,t,n){let o=0,r=e.length-1;for(;o<r;){let s=o+r+1>>1;e[s].bp0<=t?o=s:r=s-1}return[e[o],e[o-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function Ac(e,t){let{layout:n}=e,o=[...Ge(e).values()].flat().sort((s,a)=>s.bp0-a.bp0),r=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let i=new Map;for(let c of s.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=sr(o,c.start,i);if(l){let{bp0:f,bp1:u,x0:d,x1:p,index:m}=l,h=g=>d+(Math.min(g,u)-f)/(u-f)*(p-d);r.push({x0:h(c.start),x1:h(c.end),y:i.get(m),height:s.width})}}}}return r}function ir(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Tc(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=ir(s),e.beginPath();for(let a of t){let i=n(a.x0),c=Math.max(n(a.x1),i+1);if(c>=0&&i<=r){let l=o(a.y);e.rect(i,l,c-i,o(a.y+a.height)-l)}}e.fill()}}var D=JBrowseExports.mobx,ue=e=>D!=null&&e in Object(D)?D[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from 'mobx' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var qc=ue("autorun");var Fc=ue("computed");var Gc=ue("reaction");var Yc=ue("untracked");var Hc=D&&D.__esModule?D.default:D;var ar=10;function cr(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=ar*(r.end-r.start)&&(n===0?r.start<=e.start&&e.start<=r.end:Math.min(e.end,r.end)-Math.max(e.start,r.start)>=n/2))}var lr=40;function P(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function dr(e,t){let n=P(e),o=P(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function Ye(e){return e>=mt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function fr(e,t=[]){let n=ur(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function ur(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:a,inversion:i}=e,c=dr(o,r);if(a>=lr)return{kind:"superbubble",label:`${c} superbubble, ${a} segments, ${Ye(s)}${i?", inv":""}`};if(i)return{kind:"inversion",label:`${P(r)} inv`};if(e.offReference)return o===r?on(o):{kind:"complex",label:`${c}, ${Ye(s)}`};let l=r!==o?cr(e,t):void 0;if(l){let u=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${c} repeat array${u}, ${Ye(s)}`}}let f=s>2?`, ${s} alleles`:"";return o===r&&o===n?on(n):n===0||o===n?{kind:"insertion",label:`\u2264${P(r-n)} ins${f}`}:r===n?{kind:"deletion",label:`${P(n-o)} del${f}`}:{kind:"complex",label:`${P(n)} ref \u2192 ${c}, ${s} alleles`}}function on(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${P(e)} sub`}}var pr={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},hr={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function mr(e){return e.segments.split(",").filter(Boolean)}function gr(e,t,n,o){let r=[];for(let s of e){let a=n(s.x0),i=n(s.x1);i>=0&&a<=o&&r.push({node:s.name,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:i})}return r}var xr=3;function br(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,a=xr;for(let i of e){let c=i.top0+(i.bottom0-i.top0)*r,l=i.top1+(i.bottom1-i.top1)*r,f=Math.max(0,Math.min(c,l)-n,n-Math.max(c,l));f<a&&(a=f,s=i.node)}return s}function rn(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 sn(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function yr(e,t,n,{highlightNode:o,darkMode:r}){if(n<=0||t.length===0)return;let s=r?"255,255,255":"0,0,0";e.beginPath();for(let a of t)rn(e,a,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let a of t)sn(e,a,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke(),an(e,t,n,o)}function an(e,t,n,o){let r=n>0&&o?t.find(s=>s.node===o):void 0;r&&(e.beginPath(),rn(e,r,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),sn(e,r,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function cn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}var wr=new Set(["_gbwt_ref","unknown"]);function ln(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||wr.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var Sn=!1;function H(...e){Sn&&console.log(...e)}var Mr=["read_group","sample_name"],il=[...Mr,"haplotype_sample"];function Er({layers:e,coarsenedReadView:t=!1,showReads:n=!0},o){if(e!==void 0)return e;let r=t&&n,s=a=>a?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(r&&!o)},{data:"reads",...s(r&&o)}]}function dn(e,t){return e.find(n=>n.data===t)?.stat}function Sr(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:Er(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15}}function vn(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:cn(),imageBounds:{minX:0,maxX:0,minY:0,maxY:0},trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function al(e,t,n=[],o={}){let r=vr(e,t,n,o);return r&&Rr(r,o)}var Rn=new WeakMap;function vr(e,t,n=[],o={}){let r=Or(e,t,n,o);if(r===void 0)return;let s=_n(r,r.tracks,r.reads,"measure");return s.nodes.forEach((a,i)=>{a.order>=0&&(r.nodes[i].x=a.x)}),Rn.set(r,s),r}function Rr(e,t={}){return _r(e,kr(e,t.facet),Ar(e,t))}function _r(e,t,n,o){let r=Rn.get(e);return r!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?r:_n(e,t,n,"topology",o)}function Or(e,t,n,o){let r=vn(Sr(o,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,a)=>{s.seq??="",s.sequenceLength??=s.seq.length,r.nodes[a+1]=s}),r.tracks=structuredClone(t),r.reads=r.config.showReads?structuredClone(n.filter(s=>s.is_secondary!==!0)):[];for(let s=r.tracks.length-1;s>=0;s-=1){let a=r.tracks[s];if(a.type??="haplotype",a.hidden===!0){r.tracks.splice(s,1);continue}a.indexOfFirstBase!==void 0&&(r.trackForRuler=a.name)}if(r.tracks.length!==0)return $r(r,0),r.nodeMap=hn(r),Y(r,r.tracks),Y(r,r.reads),Mn(r),r.config.mergeNodes&&(mn(r),We(r),Ke(r),Es(r),r.nodeMap=hn(r),Mn(r),Y(r,r.tracks),Y(r,r.reads)),mn(r),ts(r),We(r),ns(r),We(r),Ke(r),Y(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:Zr(r),trackForRuler:r.trackForRuler}}}function Ar(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:o}){let r=n?new Set(n):null;return e.reads.filter(s=>(s.mapping_quality??0)>=t&&(r===null||s.name!==void 0&&r.has(s.name))&&(o===void 0||Tr(o,s)))}function Tr(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Nr(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function kr(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Nr(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Cr(o)===t.key)}function Cr(e){return ln(e.name)?.sample??null}function _n(e,t,n,o,r={}){let s=vn(e.options);e.nodes.forEach((d,p)=>{s.nodes[p]={...d}}),s.tracks=t.map(d=>({...d})),s.reads=n.map(d=>({...d})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:a,ignoreStrand:i}=s.config,c=r.haplotypes??Nn,l=dn(a,"haplotypes")==="coarsen"?xs(s,c):void 0;l!==void 0&&(s.tracks=[l.ref]),ps(s),is(s),Ir(s);let f=dn(a,"reads")==="coarsen"&&s.reads.length>0?kn(s,s.reads,"read",r.reads??c+(l?.bands.length??0)):void 0;f!==void 0&&(s.reads=f.bands);let u={};for(let[d,p,m]of[["haplotypes","haplotype",l],["reads","read",f]])m!==void 0&&(Ke(s,m.bands),Y(s,m.bands),u[d]={unit:p,total:m.total,reverse:!i&&m.bands.some(h=>h.is_reverse)});return l!==void 0&&(s.reads=l.bands.concat(s.reads)),s.reads.length>0?(Lr(s),s.tracks=s.tracks.concat(s.reads)):s.nodes.forEach(d=>{d.incomingReads=[],d.outgoingReads=[],d.internalReads=[]}),o==="measure"&&rs(s),gs(s),H("Tracks:",s.tracks),H("Nodes:",s.nodes),H("Lane assignment:",s.assignments),Ur(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:s.imageBounds,maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:u}}function A(e){return e.startsWith("-")}function T(e){return A(e)?e.substring(1):e}function On(e){return A(e)?e:`-${e}`}function je(e){return A(e)?T(e):On(e)}function fn(e){return e>0}function $r(e,t){let n=new Set,o=new Set;for(let r of e.tracks[t].sequence)A(r)?o.has(T(r))||n.add(T(r)):o.add(r);if(n.size!==0){for(let{sequence:r}of[...e.tracks,...e.reads])for(let s=0;s<r.length;s+=1)n.has(T(r[s]))&&(r[s]=je(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Ue(r.seq))})}}function Ir(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&&un(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(o=>{un(t,o.order,(o.y??0)+n.width)})}),e.nodes.forEach((n,o)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(o))})}function un(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var pe=7;function Pr(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=pe),t.path.length===1){let o=t.path[0].node;o!==null&&e.nodes[o].internalReads.push(n)}else t.path.forEach((o,r)=>{if(r===0){let s=t.path[0].node;s!==null&&e.nodes[s].outgoingReads.push([n,r])}else{let s=o.node;s!==null&&e.nodes[s].incomingReads.push([n,r])}})})}function Lr(e){e.reads.forEach(i=>{i.path=An(e,i)}),Pr(e);let t=e.nodes.filter(i=>i.order>=0);t.sort(Ve);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,f=c.sourceTrackID,u=`${l}:${f}`,d=n.get(u);d===void 0?n.set(u,{layer:l,source:f,reads:new Set([i])}):d.reads.add(i)}let o=[...n.values()].sort((i,c)=>i.layer-c.layer||i.source-c.source),r=o.length>1?pe:0;t.forEach(i=>{for(let{reads:c}of o)Br(e,c,i,r)});let s=Yr(e),a=[];e.reads.forEach((i,c)=>{let l=i.path.length,f=new Array(l),u;for(let m=0;m<l;m++){m===0?f[m]=void 0:f[m]=u??i.path[0];let h=i.path[m];h.node!==null&&h.node&&(u=h)}let d=new Array(l),p;for(let m=l-1;m>=0;m--){m===l-1?d[m]=void 0:d[m]=p??i.path[l-1];let h=i.path[m];h.node!==null&&h.node&&(p=h)}i.path.forEach((m,h)=>{if(m.y===void 0){let g=f[h],x=d[h],y=!!(x&&g&&(g.order>x.order||x.order===g.order&&x.isForward===g.isForward));m.betweenCycleReverseTraversal=y,a.push({readIndex:c,pathIndex:h,previousY:g?.y,previousNode:g?.node})}})}),a.sort((i,c)=>Xr(e,i,c)),a.forEach(i=>{let c=e.reads[i.readIndex],l=c.path[i.pathIndex];l.y=s[l.order],s[l.order]+=c.width}),H("Reads:",e.reads)}function Br(e,t,n,o){let r=n.incomingReads.filter(([m])=>t.has(m)),s=n.outgoingReads.filter(([m])=>t.has(m)),a=n.internalReads.filter(m=>t.has(m));r.length===0&&s.length===0&&a.length===0&&(o=0);let i=n.y+n.contentHeight+o*2,c=r.map(m=>{let[h,g]=m,x=e.reads[h].path,y=g+1,M;for(let w=1;w<=g;w++){let S=x[g-w]?.y;if(S!==void 0){y=w,M=S;break}}return{entry:m,decisionStep:y,y:M}});c.sort(Dr),r=c.map(m=>m.entry);let l=i,f=new Map;r.forEach(m=>{let h=e.reads[m[0]];h.path[m[1]].y=l,pn(f,h,m[1],l,n),l+=h.width});let u=l;s.sort((m,h)=>qr(e,m,h));let d=new Map;l=i,s.forEach(m=>{let h=e.reads[m[0]],g=h.firstNodeOffset??0;h.path[m[1]].y=l,d.set(l,g);let x=f.get(l);x===void 0||x+1<=g?(l+=h.width,u=Math.max(u,l)):(f.set(l,0),r.forEach(y=>{let M=e.reads[y[0]],w=M.path[y[1]];w.y!==void 0&&w.y>=l&&(w.y+=h.width,pn(f,M,y[1],w.y,n))}),l+=h.width,u+=h.width)}),a.sort((m,h)=>Gr(e,m,h)),a.forEach(m=>{let h=e.reads[m],g=h.firstNodeOffset??0,x=h.finalNodeCoverLength??0;for(l=i;g<(f.get(l)??-1/0)+2||x>(d.get(l)??1/0)-3;)l+=h.width||pe;h.path[0].y=l,f.set(l,x),u=Math.max(u,l)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,fs(e,n,p)}function Dr(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 pn(e,t,n,o,r){n===t.path.length-1?e.set(o,t.finalNodeCoverLength??0):e.set(o,r.sequenceLength)}function Xr(e,t,n){let o=e.reads[t.readIndex],r=e.reads[n.readIndex],s=o.path[t.pathIndex],a=r.path[n.pathIndex];if(s.order!==a.order)return s.order-a.order;if(o.sourceTrackID!==r.sourceTrackID)return o.sourceTrackID-r.sourceTrackID;if(t.previousNode&&n.previousNode){let u=e.nodes[t.previousNode],d=e.nodes[n.previousNode];if(u&&d&&u.order!==d.order)return u.order-d.order}let i=t.previousY??0,c=n.previousY??0,l=s.betweenCycleReverseTraversal===!0,f=a.betweenCycleReverseTraversal===!0;return l!==f?l?1:-1:l?c-i:i-c}function qr(e,[t,n],[o,r]){let s=e.reads[t],a=e.reads[o],i,c,l=s.path.length-1,f=a.path.length-1;for(;!i&&l>=0;)i=s.path[l]?.y,l-=1;for(;!c&&f>=0;)c=a.path[f]?.y,f-=1;if(i&&c)return i-c;let u=s.path[n]?.node,d=a.path[r]?.node,p=typeof u=="number"?e.nodes[u]:null,m=typeof d=="number"?e.nodes[d]:null;for(;p&&m&&p===m;){if(n<s.path.length-1){for(n+=1;s.path[n]?.node===null;)n+=1;let g=s.path[n]?.node;p=typeof g=="number"?e.nodes[g]:null}else p=null;if(r<a.path.length-1){for(r+=1;a.path[r]?.node===null;)r+=1;let g=a.path[r]?.node;m=typeof g=="number"?e.nodes[g]:null}else m=null}if(p)return m?Ve(p,m):1;if(m)return-1;let h=(s.firstNodeOffset??0)-(a.firstNodeOffset??0);return h!==0?h:(s.finalNodeCoverLength??0)-(a.finalNodeCoverLength??0)}function Fr(e,t){let n=e.path,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let a=n[r],i=o[s],c=a.order,l=i.order;if(c===l&&a.node&&i.node)return(i.y??0)-(a.y??0);c<l?r+=1:(c>l||(r+=1),s+=1)}return 0}function Gr(e,t,n){let o=e.reads[t],r=e.reads[n],s=o.firstNodeOffset??0,a=r.firstNodeOffset??0;if(s<a)return-1;if(s>a)return 1;let i=o.finalNodeCoverLength??0,c=r.finalNodeCoverLength??0;return i<c?-1:i>c?1:0}function Yr(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(o=>{t[o.order]=Math.max(t[o.order],(o.y??0)+n.width)})}),t}function An(e,t){let n=[],o=(c,l)=>{n.push({order:c,isForward:l,node:null})},r=(c,l,f)=>{n.push({order:c,isForward:l,node:f})},s=Math.abs(t.indexSequence[0]),a=fn(t.indexSequence[0]),i=e.nodes[s];r(i.order,a,s);for(let c=1;c<t.sequence.length;c+=1){let l=i,f=a;s=Math.abs(t.indexSequence[c]),a=fn(t.indexSequence[c]),i=e.nodes[s];let{order:u}=i;if(u>l.order){f||o(l.order,!0);for(let d=l.order+1;d<u;d+=1)o(d,!0);a||o(u,!0)}else if(u<l.order){f&&o(l.order,!1);for(let d=l.order-1;d>u;d-=1)o(d,!1);a&&o(u,!1)}else a===f&&o(u,!a);r(u,a,s)}return n}function Ke(e,t=e.reads){t.forEach(n=>{let o=0;for(;o<n.sequence.length&&n.sequence[o].startsWith("-");)o+=1;if(o===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]=T(n.sequence[c]);let r=n.sequenceNew??[];r.reverse(),n.sequenceNew=r;for(let c of r)c.nodeName=T(c.nodeName),Hr(c.mismatches,He(e,c.nodeName).sequenceLength);let s=n.firstNodeOffset??0,a=He(e,n.sequence[0]).sequenceLength;n.firstNodeOffset=a-(n.finalNodeCoverLength??0);let i=He(e,n.sequence[n.sequence.length-1]).sequenceLength;n.finalNodeCoverLength=i-s}})}function Hr(e,t){e.forEach(n=>{Object.assign(n,Wr(n,t))})}function Wr(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:Ue(e.seq)}}}var Kr={A:"T",T:"A",C:"G",G:"C"};function Ue(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Kr[e.charAt(n)]??"N";return t}function Y(e,t){let n=new Map;t.forEach(o=>{o.indexSequence=o.sequence.map(r=>{let s=n.get(r);if(s===void 0){let a=e.nodeMap.get(T(r));if(a===void 0)throw new Error(`Track ${o.name??o.id} visits unknown node ${r}`);s=A(r)?-a:a,n.set(r,s)}return s})})}var jr=20;function Ur(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+jr+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(o=>{let r=o.y??0;t.maxY=Math.max(t.maxY,r+n.width),t.minY=Math.min(t.minY,r)})}),e.imageBounds=t}function He(e,t){let n=e.nodeMap.get(T(t)),o=n===void 0?void 0:e.nodes[n];if(o===void 0)throw new Error(`Unknown node ${t}`);return o}function hn(e){let t=new Map;return e.nodes.forEach((n,o)=>{t.set(n.name,o)}),t}function mn(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),o=r=>{for(let s=0;s<r.indexSequence.length-1;s+=1){let a=Math.abs(r.indexSequence[s]),i=Math.abs(r.indexSequence[s+1]);t[a].add(i),n[i].add(a)}};e.tracks.forEach(o),e.reads.forEach(o),e.nodes.forEach((r,s)=>{r.successors=Array.from(t[s]),r.predecessors=Array.from(n[s])})}function gn(e,t){let n=0,o=0,r=0;t.forEach(s=>{let a=Math.abs(s);if(s<0){let i=e.nodeOrders[a]??=o;i<r&&(r=i),n=i,o=i-1}else{let i=e.nodeOrders[a]??=n;n=i+1,o=i}}),r<0&&ze(e,-r)}function zr(e,t){let n=0,o=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let r=t[n],s,a;r>=0?(s=e.nodeOrders[r]-1,a=-1):(s=e.nodeOrders[-r]+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]=s,o=Math.min(o,s),s+=a)}return o<0&&ze(e,-o),n}var Vr=-1;function Jr(e){let t=[];for(let n of e)t.push(n??Vr);return t}function We(e){let t,n,o,r,s=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}),gn(e,e.tracks[0].indexSequence);for(let l=1;l<a.length;l+=1){if(H(`generating order for track ${l+1}`),o=zr(e,a[l].indexSequence),o===null){l<e.tracks.length?gn(e,a[l].indexSequence):(a.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=es(a[l].indexSequence);o<t.length;){for(r=o,o+=1;o<t.length&&e.nodeOrders[t[o]]===void 0;)o+=1;if(o<t.length){n=e.nodeOrders[t[r]]+1;for(let f=r+1;f<o;f+=1)e.nodeOrders[t[f]]=n,n+=1;if(e.nodeOrders[t[o]]>e.nodeOrders[t[r]])e.nodeOrders[t[o]]<n&&xn(e,t[o],t[o-1],n);else if(a[l].indexSequence[o]>=0&&!Qr(e,t[o],t[r],i))xn(e,t[o],t[o-1],n);else if(a[l].indexSequence[r]<0||e.nodes[t[r+1]].degree<2&&e.nodeOrders[t[o]]<e.nodeOrders[t[r]]){n=e.nodeOrders[t[r]]-1;for(let f=r+1;f<o;f+=1)e.nodeOrders[t[f]]=n,s=Math.min(s,n),n-=1}}else if(a[l].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let f=r+1;f<t.length;f+=1){let u=t[f];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let f=r+1;f<t.length;f+=1){let u=t[f];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,s=Math.min(s,n),n-=1)}}}}s<0&&ze(e,-s);let c=Jr(e.nodeOrders);e.nodeOrders=c,c.forEach((l,f)=>{let u=e.nodes[f];u!==void 0&&(u.order=l)})}function Qr(e,t,n,o){o.generation+=1;let{stamp:r,generation:s}=o,a=[t];for(r[t]=s;a.length>0;){let i=a.pop();if(i===n)return!0;for(let c of e.nodes[i].successors)r[c]!==s&&(r[c]=s,a.push(c))}return!1}function Zr(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function es(e){return e.map(t=>Math.abs(t))}function ze(e,t){e.nodeOrders.forEach((n,o)=>{n!==void 0&&(e.nodeOrders[o]=n+t)})}function xn(e,t,n,o){let r=new Map,s=[[t,o]],a=0;for(;a<s.length;){let[i,c]=s[a];a+=1;let l=e.nodeOrders[i];l!==void 0&&l<c&&(!r.has(i)||r.get(i)<c)&&(r.set(i,c),e.nodes[i].successors.forEach(f=>{e.nodeOrders[f]>l&&f!==n&&s.push([f,c+1])}),i!==t&&e.nodes[i].predecessors.forEach(f=>{e.nodeOrders[f]>l&&f!==n&&s.push([f,c+1])}))}r.forEach((i,c)=>{e.nodeOrders[c]=i})}function ts(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 ns(e){os(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function os(e,t,n){let o=new Int32Array(e.nodes.length),r=new Uint8Array(e.nodes.length);for(let s of n.sequence){let a=A(s)?void 0:e.nodeMap.get(s);a!==void 0&&(r[a]=1)}for(let s of t){let{sequence:a,indexSequence:i}=s,c=i.length-1;for(let l=0;l<=c;l+=1){let f=Math.abs(i[l]);if(r[f]===1)continue;let u=e.nodes[f].order,d=l>0?e.nodes[Math.abs(i[l-1])].order:void 0,p=l<c?e.nodes[Math.abs(i[l+1])].order:void 0,m=A(a[l])?1:-1;(d===void 0||d<u)&&(p===void 0||u<p)&&(o[f]+=m),(d===void 0||d>u)&&(p===void 0||u>p)&&(o[f]-=m)}}for(let s of t){let{sequence:a,indexSequence:i}=s;for(let c=0;c<i.length;c+=1)o[Math.abs(i[c])]>0&&(a[c]=je(a[c]),i[c]=-i[c])}e.nodes.forEach((s,a)=>{o[a]>0&&(s.seq=Ue(s.seq),s.switched=!0)})}function rs(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort(Ve);let s=ss(e);r.forEach(a=>{a.order>=0&&(a.order>o&&(o=a.order,t=n+10*s[a.order]),a.x=t,n=Math.max(n,t+40+a.pixelWidth))})}function ss(e){let t=[],n=[],o=[],r=[];for(let s=0;s<=e.maxOrder;s+=1)t.push(0),n.push(0),o.push(0);e.tracks.forEach(s=>{for(let a=1;a<s.path.length;a+=1){let i=s.path[a],c=s.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));o[i.order]=Math.max(l/17.5,o[i.order])}}}),r.push(Math.max(0,t[0]-1));for(let s=1;s<=e.maxOrder;s+=1)r.push(Math.max(Math.max(0,t[s]-1)+Math.max(0,n[s-1]-1),o[s]));return r}function is(e){let t=[],n=[];for(let o=0;o<=e.maxOrder;o+=1)e.assignments[o]=[],n[o]=new Map,t[o]=[];e.tracks.forEach((o,r)=>{o.path=An(e,o),o.path.forEach((s,a)=>{as(e,s.order,s.node,r,a,t,n)})});for(let o=0;o<=e.maxOrder;o+=1)ls(e,e.assignments[o],o)}function as(e,t,n,o,r,s,a){let i={trackID:o,segmentID:r,compareToFromSame:s[t][o]??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);s[t][o]=i}function cs(e,t,n){let o;t.forEach(r=>{r.idealLane=0,r.tracks.forEach(s=>{if(s.segmentID===0)s.idealLane=s.trackID,s.idealY=null;else if(e.tracks[s.trackID].path[s.segmentID-1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID-1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID-1].y;else if(s.segmentID<e.tracks[s.trackID].path.length-1&&e.tracks[s.trackID].path[s.segmentID+1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID+1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID+1].y;else{for(o=s.segmentID-1;o>=0&&e.tracks[s.trackID].path[o].order!==n-1;)o-=1;o<0?(s.idealLane=s.trackID,s.idealY=null):(s.idealLane=e.tracks[s.trackID].path[o].lane,s.idealY=e.tracks[s.trackID].path[o].y)}r.idealLane+=s.idealLane}),r.idealLane/=r.tracks.length})}function ls(e,t,n){let o=0,r=new Set,s=20,a=!1,i=-1;cs(e,t,n),t.sort(bn),t.forEach(c=>{c.node!==null?(e.nodes[c.node].topLane=o,a&&(s-=10),e.nodes[c.node].y=s,e.nodes[c.node].contentHeight=0,a=!1):(a?s-=25:s>20&&(s-=10),a=!0),c.tracks.sort(bn),c.tracks.forEach(l=>{l.lane=o,l.trackID===i&&c.node===null&&a&&(s+=10),e.tracks[l.trackID].path[l.segmentID].lane=o,e.tracks[l.trackID].path[l.segmentID].y=s,typeof l.idealY=="number"&&r.add(l.idealY-s),o+=1,s+=e.tracks[l.trackID].width,c.node!==null&&(e.nodes[c.node].contentHeight+=e.tracks[l.trackID].width),i=l.trackID}),s+=25}),ds(e,t,r)}function ds(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let a=us(e,t,s);a<r&&(r=a,o=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=o),s.tracks.forEach(a=>{let i=e.tracks[a.trackID].path[a.segmentID];i.y=i.y+o})})}function fs(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(o=>{if(o.node!==null){let r=e.nodes[o.node];r!==t&&r.y>t.y&&(r.y+=n,o.tracks.forEach(s=>{let a=e.tracks[s.trackID].path[s.segmentID];a.y=a.y+n}))}else o.tracks.forEach(r=>{let s=e.tracks[r.trackID].path[r.segmentID];s.y>=t.y&&(s.y=s.y+n)})}),e.nodesPerOrder[t.order].length>0&&e.nodesPerOrder[t.order].forEach(o=>{e.nodes[o]!==t&&e.nodes[o].y>t.y&&(e.nodes[o].y+=n)}))}function us(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{typeof s.idealY=="number"&&e.tracks[s.trackID].type!=="read"&&(o+=Math.abs(s.idealY-n-e.tracks[s.trackID].path[s.segmentID].y)*e.tracks[s.trackID].width)})}),o}function bn(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 Ve(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 ps(e){let t=!0,n=4,o=e.config.trackWidth;for(let r of e.tracks)r.freq!==void 0?r.width=Math.round((Math.log(Math.max(r.freq,1))+1)*n):(r.width=o,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(t=!1);t&&e.tracks.forEach(r=>{r.freq!==void 0&&(r.width=o)})}function hs(e,t){let n=t.path[0],o=e.nodes[n.node],r=t.firstNodeOffset??0;return Je(o,n.isForward?r:o.sequenceLength-r)}function ms(e,t){let n=t.path[t.path.length-1],o=e.nodes[n.node],r=t.finalNodeCoverLength??0;return Je(o,n.isForward?r:o.sequenceLength-r)}function Tn(e,t){return t>e.sequenceLength?null:Je(e,t)}function Je(e,t){let[n,o]=Ms(e);if(e.sequenceLength===0)return n;let r=Math.min(Math.max(t,0),e.sequenceLength);return n+r/e.sequenceLength*(o-n)}function gs(e){let t,n,o,r;for(let i=0;i<=e.maxOrder;i+=1)e.extraLeft.push(0),e.extraRight.push(0);let s=[],a=[];e.nodes.forEach(i=>{i.x!==void 0&&(s[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(Fr),e.tracks.forEach(i=>{o=i.path[0].y,i.type!=="read"?i.sequence[0].startsWith("-")?t=a[i.path[0].order]+20:t=s[i.path[0].order]-20:t=hs(e,i);for(let c=0;c<i.path.length;c+=1)i.path[c].y!==o&&(i.path[c-1].isForward?n=a[i.path[c-1].order]:n=s[i.path[c-1].order],n!==t&&e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+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=s[i.path[c].order],r=i.path[c].y,e.shapes.curves.push({xStart:t,yStart:o,xEnd:n+1,yEnd:r,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,o=r):i.path[c].order+1===i.path[c-1].order?(t=n,n=a[i.path[c].order],r=i.path[c].y,e.shapes.curves.push({xStart:t+1,yStart:o,xEnd:n,yEnd:r,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,o=r):i.path[c-1].isForward?(r=i.path[c].y,wn(e,1,n,o,r,i.width,i.id,i.path[c].order,i.type,i.name),t=a[i.path[c].order],o=i.path[c].y):(r=i.path[c].y,wn(e,-1,n,o,r,i.width,i.id,i.path[c].order,i.type,i.name),t=s[i.path[c].order],o=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=s[i.path[i.path.length-1].order]-20:n=ms(e,i),e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+i.width-1,id:i.id,name:i.name,type:i.type})})}var Nn=1e9;function kn(e,t,n,o=Nn){let r=new Map,s=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);s+=x;let y=g.indexSequence;if(!(y.length<2))for(let M=0;M<y.length-1;M+=1){let w=y[M],S=y[M+1],E=e.nodes[Math.abs(w)],R=e.nodes[Math.abs(S)],b=c?Math.min(i(w,S),i(-S,-w)):i(w,S),v=r.get(b);v===void 0?r.set(b,{sSigned:w,dSigned:S,sName:w<0?`-${E.name}`:E.name,dName:S<0?`-${R.name}`:R.name,count:x,crossings:x,sourceTrackID:g.sourceTrackID,lastSource:h}):(v.crossings+=x,v.lastSource!==h&&(v.count+=x,v.lastSource=h))}}let l=0;for(let h of r.values())h.crossings>l&&(l=h.crossings);let f=pe,u=60,d=h=>l<=1?f:f+(u-f)*Math.sqrt(h/l),p=[],m=0;for(let h of r.values()){let g=o+m,x=n==="haplotype"?{count:h.count,total:s}:void 0,y=x===void 0?"":` (${ws(x)})`,M=h.crossings===h.count?"":`, ${h.crossings.toLocaleString()} crossings`,w=`${h.count.toLocaleString()} ${n}${h.count===1?"":"s"}${y}${M}: Node ${h.sName} \u2192 Node ${h.dName}`;e.coarsenedEdgeMeta.set(g,{count:h.count,label:w});let S=e.nodes[Math.abs(h.sSigned)].sequenceLength;p.push({id:g,sourceTrackID:h.sourceTrackID,type:"read",name:w,sequence:[h.sName,h.dName],indexSequence:[],path:[],width:d(h.crossings),firstNodeOffset:S,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}),m+=1}if(Sn){let h="?",g=0;e.nodes.forEach(x=>{x.contentHeight>g&&(g=x.contentHeight,h=x.name)}),H(`[coarsened] ${n}s_in=${t.length} edges_out=${p.length} tallestNodeBeforePlace=${h}(${g.toFixed(1)})`)}return{bands:p,total:s}}function xs(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(f=>f.name===e.trackForRuler),o=n===-1?0:n,r=e.tracks[o],s=(r.freq??1)-1,a=ys(e,r),i=e.tracks.filter((f,u)=>u!==o).map(f=>bs(a,f));if(s>0&&i.push({...r,freq:s}),i.length===0)return;let{bands:c,total:l}=kn(e,i,"haplotype",t);return c.length>0?{ref:r,bands:c,total:l}:void 0}function bs(e,t){let n=0;for(let o of t.indexSequence){let r=e[Math.abs(o)];r!==void 0&&r!==0&&(n+=r===Math.sign(o)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(je).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function ys(e,t){let n=new Int8Array(e.nodes.length);for(let o of t.indexSequence){let r=Math.abs(o);n[r]===0&&(n[r]=Math.sign(o))}return n}function ws({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var yn=7;function wn(e,t,n,o,r,s,a,i,c,l){let f=t===1?e.extraRight:e.extraLeft,u=10*f[i],d=n+t*(u+5),p=yn,m=Math.min(yn,s),h=Math.min(o,r),g=Math.max(o,r),x=t===1?n:d-1,y=t===1?d:n,M=R=>{e.shapes.verticalRectangles.push({xStart:x,yStart:R,xEnd:y,yEnd:R+s-1,id:a,name:l,type:c})};M(o),e.shapes.verticalRectangles.push({xStart:t===1?d+p:d-p-m,yStart:h+s+p-1,xEnd:t===1?d+p+m-1:d-p-1,yEnd:g-p+1,id:a,name:l,type:c}),M(r);let w=d+t*p,S=d+t*(p+m),E=`M ${d} ${g}`;E+=` Q ${w} ${g} ${w} ${g-p}`,E+=` H ${S}`,E+=` Q ${S} ${g+s} ${d} ${g+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:c}),E=`M ${d} ${h}`,E+=` Q ${S} ${h} ${S} ${h+s+p}`,E+=` H ${w}`,E+=` Q ${w} ${h+s} ${d} ${h+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:c}),f[i]+=1}function Ms(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function Mn(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 X=0;function En(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function O(e,t,n){let o=e.count[t];o===0?(e.first[t]=n,e.count[t]=1):o===1&&e.first[t]!==n&&(e.count[t]=2)}function U(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function Es(e){let t=En(e.nodes.length),n=En(e.nodes.length),o=new Map,r=u=>{let d=o.get(u);if(d===void 0){let p=e.nodeMap.get(T(u));d=A(u)?-p:p,o.set(u,d)}return d};e.tracks.concat(e.reads).forEach(u=>{let{sequence:d}=u,p=u.type==="haplotype",m=d.length-1,h=X,g=m>=0?r(d[0]):X;for(let x=0;x<=m;x+=1){let y=x<m?r(d[x+1]):X;if(g>0)x>0?(O(t,g,h),h<0&&O(t,g,-h)):p&&O(t,g,X),x<m?(O(n,g,y),y<0&&O(n,g,-y)):p&&O(n,g,X);else{let M=-g;x>0?(O(n,M,-h),h>0&&O(n,M,h)):p&&O(n,M,X),x<m?(O(t,M,-y),y>0&&O(t,M,y)):p&&O(t,M,X)}h=g,g=y}});let a=new Uint8Array(e.nodes.length);e.nodes.forEach((u,d)=>{Ss(d,t,n)!==0&&(a[d]=1)});let i=new Int32Array(e.nodes.length),c=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((u,d)=>{if(a[d]!==1){i[d]=d,l[d]=u.sequenceLength;for(let p=d;vs(p,t,n);)p=U(n,p),i[p]=d,c[p]=u.sequenceLength,u.sequenceLength+=e.nodes[p].sequenceLength,u.seq+=e.nodes[p].seq,l[p]=u.sequenceLength}}),e.reads.forEach(u=>{let{sequence:d}=u,p=u.sequenceNew??d.map(M=>({nodeName:M,mismatches:[]})),m=M=>{let w=Math.abs(r(M));return A(M)?e.nodes[i[w]].sequenceLength-l[w]:c[w]},h=d.length-1;u.firstNodeOffset=(u.firstNodeOffset??0)+m(d[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+m(d[h]);let g=[],x=[],y=[];d.forEach((M,w)=>{let S=Math.abs(r(M)),{mismatches:E}=p[w],R=m(M);if(E.forEach(b=>{b.pos+=R}),a[S]===1&&!A(M)&&w>0)x.at(-1).mismatches.push(...E);else if(a[S]===1&&A(M)&&w<h)y.push(...E);else{let b=e.nodes[i[S]].name,v=A(M)?On(b):b;g.push(v),x.push({nodeName:v,mismatches:y.concat(E)}),y=[]}}),u.sequence=g,u.sequenceNew!==void 0&&(u.sequenceNew=x)}),e.tracks.forEach(u=>{let{sequence:d}=u,p=0;for(let m of d)a[Math.abs(r(m))]===0&&(d[p]=m,p+=1);d.length=p});let f=1;for(let u=1;u<e.nodes.length;u+=1)a[u]===0&&(e.nodes[f]=e.nodes[u],f+=1);e.nodes.length=f}function Ss(e,t,n){let o=U(t,e);return o!==0&&U(n,o)!==0?o:0}function vs(e,t,n){let o=U(n,e);return o!==0&&U(t,o)!==0}function Rs(e,t){let n=new Map;for(let o of e){let r=t(o),s=n.get(r);s===void 0?n.set(r,[o]):s.push(o)}return n}function _s(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 Qe(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function Os(e,t){for(let n=0;n<e.length;n+=1){let o=e[n]-t[n];if(o!==0)return o}return 0}function Cn(e,t){let n=Rs(e.filter(o=>o.type===t),o=>Qe(o).join(","));return n.forEach(o=>{let r=.3,s=.4/o.length;o.length<=5&&(r=.5,s=0),o.sort(_s),o.forEach(a=>{let i,c;a.yStart<a.yEnd?(i=a.xStart+(a.xEnd-a.xStart)*(1-r),r+=s,c=a.xStart+(a.xEnd-a.xStart)*(1-r)):(i=a.xStart+(a.xEnd-a.xStart)*r,r+=s,c=a.xStart+(a.xEnd-a.xStart)*r);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((o,r)=>Os(Qe(o[0]),Qe(r[0]))).flat()}function $n(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,o=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n+9} ${o} ${n+9} ${o+9}`,n+=9,o+=9,e.contentHeight>0&&(o+=e.contentHeight,t+=` L ${n} ${o}`),t+=` Q ${n} ${o+9} ${n-9} ${o+9}`,n-=9,o+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n-9} ${o} ${n-9} ${o-9}`,n-=9,o-=9,e.contentHeight>0&&(o-=e.contentHeight,t+=` L ${n} ${o}`),t}function As(e,t){let n=[],o=e.sequenceNew??[],r=e.path.filter(s=>s.node!==null);return o.forEach((s,a)=>{let i=t.nodeMap.get(T(s.nodeName)),c=i===void 0?void 0:t.nodes[i],l=r[a]?.y;if(c&&l!==void 0){let f={readId:e.id,y:l,height:e.width},u=d=>Tn(c,d);for(let d of s.mismatches){let p=u(d.pos);if(p!==null){if(d.type==="insertion"){let m=a===0&&d.pos===e.firstNodeOffset||a===o.length-1&&d.pos===e.finalNodeCoverLength;n.push({...f,kind:"insertion",x:p,seq:d.seq,softClip:m})}else if(d.type==="deletion"&&d.length!==void 0){let m=u(d.pos+d.length);m!==null&&n.push({...f,kind:"deletion",x0:p,x1:m,length:d.length})}else if(d.type==="substitution"&&d.seq!==void 0){let m=u(d.pos+d.seq.length);m!==null&&n.push({...f,kind:"substitution",x0:p,x1:m,seq:d.seq})}}}}}),n}function In(e){return e.reads.flatMap(t=>As(t,e))}function tt(e){let t=e.trim().split(/[\s,]+/),n=[],o=0,r=()=>Number(t[o++]);for(;o<t.length;){let s=t[o++];s==="M"||s==="L"?n.push({op:s,x:r(),y:r()}):s==="H"?n.push({op:s,x:r()}):s==="V"?n.push({op:s,y:r()}):s==="Q"?n.push({op:s,x1:r(),y1:r(),x:r(),y:r()}):s==="C"?n.push({op:s,x1:r(),y1:r(),x2:r(),y2:r(),x:r(),y:r()}):s==="Z"&&n.push({op:s})}return n}function Dn(e){let t=1/0,n=-1/0;for(let o of e)"x"in o&&(t=Math.min(t,o.x),n=Math.max(n,o.x)),"x1"in o&&(t=Math.min(t,o.x1),n=Math.max(n,o.x1));return{x0:t,x1:n}}function Pn(e,t,n,o){let r=tt(e);return{commands:r,color:t,id:n,haplotype:o,...Dn(r)}}function Xn(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?Nt(n):t[n.id]]))}function Ln(e,t,n){let{shapes:o}=e,r=t==="haplotype",s=l=>n.get(l.id),a=[...o.rectangles,...o.verticalRectangles].filter(l=>l.type===t).map(l=>({color:s(l),id:l.id,haplotype:r,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),i=Cn(o.curves,t).map(l=>Pn(l.path,s(l),l.id,r)),c=o.corners.filter(l=>l.type===t).map(l=>Pn(l.path,s(l),l.id,r));return{rects:a,shapes:[...i,...c]}}function Ts({layout:e,pathColors:t}){let n=Xn(e,t),o=[];return e.nodes.forEach(r=>{if(r.order>=0){let s=tt($n(r));o.push({name:r.name,commands:s,...Dn(s)})}}),{bounds:e.bounds,layers:[Ln(e,"haplotype",n),Ln(e,"read",n)],nodes:o,mismatches:In(e).filter(r=>r.kind!=="insertion"||!r.softClip)}}function Ze(e,t,n,o){let r=0,s=0;for(let a of t)switch(a.op){case"M":r=a.x,s=a.y,e.moveTo(n(r),o(s));break;case"L":r=a.x,s=a.y,e.lineTo(n(r),o(s));break;case"H":r=a.x,e.lineTo(n(r),o(s));break;case"V":s=a.y,e.lineTo(n(r),o(s));break;case"Q":r=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),o(a.y1),n(r),o(s));break;case"C":r=a.x,s=a.y,e.bezierCurveTo(n(a.x1),o(a.y1),n(a.x2),o(a.y2),n(r),o(s));break;case"Z":e.closePath();break}}function Bn(e,t,n,o,r){let s=new Map;for(let a of t)if(n(a)){let i=o(a),c=s.get(i);c?c.push(a):s.set(i,[a])}for(let a of s.values()){e.fillStyle=o(a[0]),e.beginPath();for(let i of a)r(i);e.fill()}}var Ns=12,ks=.15;function Cs(e){return Math.max(ks,Math.min(1,e/Ns))}var $s=.55;function Is(e,t,n){let{x:o,y:r,width:s}=n,a=f=>o(f.x1)>=0&&o(f.x0)<=s,i=f=>f.haplotype&&n.tubeColors?.[f.id]||f.color;e.globalAlpha=1;for(let f of t.layers)Bn(e,f.rects,a,i,u=>{let d=o(u.x0),p=r(u.y0);e.rect(d,p,o(u.x1)-d,r(u.y1)-p)}),Bn(e,f.shapes,a,i,u=>{Ze(e,u.commands,o,r)});let c=n.darkMode?"#d0d0d0":"#000000",l=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=qn(n);for(let f of t.nodes)if(a(f)&&f.name!==n.highlightNode){e.beginPath(),Ze(e,f.commands,o,r);let u=n.nodeColors?.get(f.name);e.fillStyle=u??l,e.strokeStyle=c,e.globalAlpha=u?$s:1,e.fill(),e.globalAlpha=Cs(o(f.x1)-o(f.x0)),e.stroke(),e.globalAlpha=1}he(e,t,n),Ls(e,t.mismatches,n)}function qn(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function he(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),Ze(e,o.commands,n.x,n.y),e.globalAlpha=1,e.lineWidth=qn(n),e.fillStyle="rgba(255,192,203,0.5)",e.strokeStyle="#ff0000",e.fill(),e.stroke())}var Fn=12,Ps=6;function nt(e){return Fn*e>=Ps}function et(e,{x:t,width:n}){let[o,r]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(r)>=0&&t(o)<=n}function Ls(e,t,n){let{x:o,y:r,yScale:s,darkMode:a}=n;if(!nt(s)||t.length===0)return;let i=Fn*s;e.fillStyle="grey",e.beginPath();for(let c of t)if(c.kind==="deletion"&&et(c,n)){let l=o(c.x0),f=r(c.y);e.rect(l,f,o(c.x1)-l,r(c.y+c.height)-f)}e.fill(),e.font=`${i}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let c of t)et(c,n)&&(c.kind==="substitution"?e.fillText(c.seq,o(c.x0)+1,r(c.y+c.height)):c.kind==="insertion"&&e.fillText("*",o(c.x)-3,r(c.y+c.height)))}function Bs(e,{x:t,y:n},o,r){for(let s=e.layers.length-1;s>=0;s--)for(let a of e.layers[s].rects)if(t(a.x0)<=o&&o<=t(a.x1)&&n(a.y0)<=r&&r<=n(a.y1))return a.id}var Ds=4;function Xs(e,t,n,o){let{x:r,y:s,yScale:a}=t;return nt(a)?e.mismatches.find(i=>s(i.y)<=o&&o<=s(i.y+i.height)&&(i.kind==="insertion"?Math.abs(r(i.x)-n)<=Ds:r(i.x0)<=n&&n<=r(i.x1))):void 0}function qs(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],a=r?.at(-1);if(!r||!s||!a)continue;let i=Math.max(o.start,s.bp0),c=Math.min(o.end,a.bp1);c<=i||n.push({gene:o,...fe(r,i,c),exons:o.exons.filter(l=>l.end>i&&l.start<c).map(l=>fe(r,Math.max(l.start,i),Math.min(l.end,c)))})}return n}var ot=22,Fs=4,me=8,Gs="11px sans-serif",Ys=8;function Hs(e){let t=e.flatMap(r=>[{x:r.x0,step:1},{x:r.x1,step:-1}]).sort((r,s)=>r.x-s.x||r.step-s.step),n=0,o=0;for(let{step:r}of t)n+=r,o=Math.max(o,n);return Math.min(Fs,o)}function Ws(e,t,n,o,r=0){let{x:s,width:a,darkMode:i}=n,c=Math.max(1,Math.floor((o-r)/ot)),l=[],f=i?"#e0e0e6":"#1c1c22";e.font=Gs,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let u=t.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:p})=>p>=0&&d<=a).sort((d,p)=>d.s0-p.s0);for(let{g:d,s0:p,s1:m}of u){let h=d.gene.strand>0?" \u2192":d.gene.strand<0?"\u2190 ":"",g=d.gene.strand<0?`${h}${d.gene.name}`:`${d.gene.name}${h}`,x=(Math.max(p,0)+Math.min(m,a))/2,y=e.measureText(g).width/2,M=Math.min(p,x-y),w=Math.max(m,x+y),S=l.findIndex(R=>R+Ys<=M);S===-1&&(S=Math.min(l.length,c-1)),l[S]=Math.max(l[S]??-1/0,w);let E=o-S*ot-me/2;e.beginPath(),e.moveTo(p,E+.5),e.lineTo(m,E+.5),e.stroke();for(let R of d.exons){let b=s(R.x0);e.fillRect(b,E-me/2,Math.max(1,s(R.x1)-b),me)}e.fillText(g,x,E-me/2-2)}}function z(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function Ks(e,t,n,o){let r=[],s=[],a=[e];for(o.add(e);a.length>0;){let i=a.pop(),c=t.get(i);if(c){r.push(c);for(let l of n.get(i)??[]){let f=t.get(l);f&&(f.stable.rank===be?s.push(f):o.has(l)||(o.add(l),a.push(l)))}}}return{members:r,anchors:s}}function js(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),o=n[0],r=n.at(-1),s=o.stable.start+o.length,a=r.stable.start;return a>=s?{start:s,end:a,entry:o}:void 0}function Us(e,t,n){let o=new Map(e.map(a=>[a.id,a])),r=new Map,s=[];for(let a of n.get(t.id)??[])o.has(a)&&(r.set(a,0),s.push(a));if(s.length===0)for(let a of e)r.set(a.id,0),s.push(a.id);for(let a of s){let i=r.get(a)+o.get(a).length;for(let c of n.get(a)??[])if(o.has(c)){let l=r.get(c);(l===void 0||i<l)&&(r.set(c,i),s.push(c))}}return r}function zs(e,t,n){let o=Us(e,t,n),r=[...e].sort((c,l)=>o.get(c.id)-o.get(l.id)),s=new Map(r.map((c,l)=>[c.id,l])),a=new Map(e.map(c=>[c.id,c])),i=new Map;for(let[c,l]of r.entries()){let f=0;for(let u of n.get(l.id)??[]){let d=a.get(u);d&&s.get(u)<c&&(f=Math.max(f,i.get(u)+d.length))}i.set(l.id,f)}return{offsets:i,ordered:r}}function Vs(e){let t=new Map(e.nodes.filter(st).map(s=>[s.id,s])),n=ht(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==be&&!o.has(s.id)){let{members:a,anchors:i}=Ks(s.id,t,n,o),c=js(i);if(c){let{offsets:l,ordered:f}=zs(a,c.entry,n);r.push({start:c.start,refSpan:c.end-c.start,nodeIds:f.map(u=>u.id),nodeOffsets:f.map(u=>l.get(u.id)),pathLength:f.reduce((u,d)=>Math.max(u,l.get(d.id)+d.length),0)})}}return r.sort((s,a)=>s.start-a.start)}var q=JBrowseExports["@jbrowse/core/util/groupKeys"],Js=e=>q!=null&&e in Object(q)?q[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/core/util/groupKeys' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var ge=Js("groupKeyComparator");var zl=q&&q.__esModule?q.default:q;var Qs=28,Zs="12px sans-serif",ei=16,td=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],V=e=>Se(e).name;function ti(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return o=>{let{sample:r,haplotype:s}=z(o);return n.get(`${r}#${s}`)||n.get(r)||""}}function Gn(e,t){return`${e} ${t}${e===1?"":"s"}`}function nd(e,t){let n=t.by==="column"?ti(t.field,t.table):t.by==="sample"?i=>z(i).sample:i=>i,o=new Map;for(let{name:i}of e.paths??[]){let c=V(i);if(c!==e.referencePath){let l=n(c),f=o.get(l);f?f.push(i):o.set(l,[i])}}if(t.by==="column")return[...o.keys()].sort(ge(t.domain)).map(i=>{let c=o.get(i),l=new Set(c.map(f=>z(V(f)).sample));return{key:i,paths:c,label:`${i||`${t.field}: none`} \xB7 ${Gn(l.size,"sample")}`}});let r=t.domain??[],s=new Map(r.map((i,c)=>[i,c])),a=i=>s.get(i)??r.length;return[...o].map(([i,c],l)=>({key:i,paths:c,i:l})).sort((i,c)=>a(i.key)-a(c.key)||i.i-c.i).map(({key:i,paths:c})=>({key:i,paths:c}))}function od(e,t){if(e.graph.nodes.some(n=>n.id===t))return t;for(let[n,o]of e.members)if(o.includes(t))return n}function rd(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=V(r.name);s!==e.referencePath&&(n.add(s),r.nodeIds.includes(t)&&o.add(s))}return{here:o.size,of:n.size}}function sd(e,t,n,{width:o,lit:r}){t.forEach((s,a)=>{let i=n?.[a];i&&(r&&he(e,s.picture,{...s.frame,width:o,highlightNode:i.box}),s.top-s.titleTop>=ei&&(e.font=Zs,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${i.here} of ${Gn(i.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4)))})}function id(e,t){let n=new Set(t),o=(e.paths??[]).filter(l=>n.has(l.name)||V(l.name)===e.referencePath),r=new Set(o.map(l=>V(l.name))),s=new Set(o.flatMap(l=>l.nodeIds)),a=e.nodes.filter(l=>s.has(l.id)),i=new Set(a.map(l=>l.name)),c=e.pathVisits?new Map([...e.pathVisits].flatMap(([l,f])=>i.has(l)?[[l,f.filter(u=>r.has(u.path))]]:[])):void 0;return{...e,nodes:a,edges:e.edges.filter(l=>s.has(l.from)&&s.has(l.to)),paths:o,anchorPaths:e.anchorPaths?.filter(l=>r.has(l.name)),pathVisits:c,reads:void 0}}function ad(e,t){let n=[],o={},r=0,s=1/0,a=-1/0;for(let{key:i,paths:c,label:l,result:f}of t){let u=f?.tubeMap,d=f?.extent;if(u&&d){let p=r+Qs,m=(d.maxY??0)-(d.minY??0);n.push({key:i,paths:c,label:l,result:{...f,tubeMap:u},top:p,height:m});let h=p-(d.minY??0);for(let[g,x]of Object.entries(f.nodePositions))o[g]=x.map(y=>({x:y.x,y:y.y+h}));r=p+m,s=Math.min(s,d.minX??s),a=Math.max(a,d.maxX??a)}}return n.length>1?{...e,nodePositions:o,extent:{...s<=a?{minX:s,maxX:a}:{},minY:0,maxY:r},tubeMapPanels:n}:e}var xe=16;function dd(e){let[t="",...n]=e.split(/\r\n|\r|\n/),o=t.split(" ").slice(1),r=new Map;for(let s of n){if(!s)continue;let[a="",...i]=s.split(" ");a&&!r.has(a)&&r.set(a,{...Object.fromEntries(o.map((c,l)=>[c,i[l]??""])),name:a})}return[...r.values()]}function fd(e){let t=new Set;for(let n of e??[])for(let o of Object.keys(n))o!=="name"&&t.add(o);return[...t]}function ud(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(o=>typeof o=="string")}:{field:t}}function ni(e){let t=new Set(e.map(n=>n.label)).size;return`${t} haplotype${t===1?"":"s"}`}function pd(e,t,{field:n,domain:o}){let r=new Map(t.map(c=>[c.name,c[n]??""])),s=new Map;for(let c of e){let l=r.get(c.label)||r.get(c.sample)||"",f=s.get(l);f?f.push(c):s.set(l,[c])}let a=1,i=[...s.keys()].sort(ge(o)).map(c=>{let l=s.get(c),f={key:c,title:`${c||`${n}: none`} \xB7 ${ni(l)}`,first:a,count:l.length};return a+=l.length,f});return{rows:i.flatMap(c=>s.get(c.key)),sections:i}}function hd(e,t){let n=r=>{let s=-1;for(;s+1<e.length&&e[s+1].first<=r;)s++;return s},o=r=>r*t+(n(r)+1)*xe;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*xe})),headersPx:e.length*xe,rowAt(r,s){let a=0;for(let i=-1;i<e.length;i++){let c=i<0?0:e[i].first,l=i<0?Math.min(s,e[0]?.first??s):c+e[i].count,f=(i+1)*xe,u=Math.min(l-1,Math.max(c,Math.round((r-f)/t)));Math.abs(o(u)-r)<Math.abs(o(a)-r)&&(a=u)}return a}}}var k=12,jn=k+8,Un=8,Yn=Un+3,oi=12;function ri(e,{colorScheme:t,referenceRamp:n,walks:o}){let r={...ve(e),referenceRamp:n},s=[];return e.nodes.forEach((a,i)=>{if(J(a)){let c=o?o.map(l=>{let f=l.colors.get(a.id);return f===void 0?ne:L(f)}):[L(Re(a,i,t,r))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:c,faded:c.includes(ne)})}}),s.sort((a,i)=>a.bp0-i.bp0)}function rt(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var Hn=2;function zn(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),a=Math.max(o,r),i=0,c=0;for(let l of e)i+=Math.max(0,Math.min(l.bp1,s)-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 si(e,t,n,o){if(o<0||o>k+Hn)return;let r,s=Hn;for(let a of e){let[i,c]=rt(t,a.bp0,a.bp1),l=Math.max(0,i-n,n-c);l<=s&&(s=l,r=a.node)}return r}function ii(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function Vn(e,t,n,o){let r=e.map(l=>{let[f,u]=rt(t,l.bp0,l.bp1),d=Math.round(f*o);return{colors:l.colors,x0:f,px0:d,px1:Math.max(Math.round(u*o),d+1)}}).filter(l=>l.px1>0&&l.px0<n*o).sort((l,f)=>l.x0-f.x0),s=[],a=-1/0,i=[-1/0,-1/0];for(let{colors:l,px0:f,px1:u}of r){let d=Math.max(f,a);if(u>d){let p=i[0]<d?0:1;i[p]=u,s.push({colors:l,x0:d/o,x1:u/o,tier:p}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*oi?s:s.map(({tier:l,...f})=>f)}function Wn(e,t,n,o){let r=n>0?t:t-Yn;e.clearRect(r,0,Yn,k);let s=t+n,a=s+n*Un;e.beginPath(),e.moveTo(s,k/2),e.lineTo(a,0),e.lineTo(a,k),e.closePath(),e.fillStyle=o,e.fill()}function Kn(e,t,n){return Math.round(e*k*n/t)/n}function ai(e,t,n,{width:o,lit:r,darkMode:s,dpr:a=1}){let i=s?"#ffffff":"#18181c";e.clearRect(0,0,o,jn);for(let l of Vn(t,n,o,a)){let{tier:f}=l,u=f!==void 0&&l.colors.length===1,d=u?2:l.colors.length;l.colors.forEach((p,m)=>{let h=u?f:m,g=Kn(h,d,a);e.fillStyle=p,e.fillRect(l.x0,g,l.x1-l.x0,Kn(h+1,d,a)-g)})}let c=zn(t,n,o);if(c.left>0&&Wn(e,0,1,i),c.right>0&&Wn(e,o,-1,i),r){let[l,f]=rt(n,r.start,r.end),u=Math.max(f-l,3),d=(l+f)/2-u/2;e.strokeStyle=i,e.lineWidth=1.5,e.strokeRect(d,.75,u,k-1.5),r.anchor&&(e.beginPath(),e.moveTo(d+u/2,k),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function ci(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function li(e,t){let n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0)),s=Array.from({length:n+1},()=>new Array(o+1).fill(!1));for(let i=n-1;i>=0;i--)for(let c=o-1;c>=0;c--){let l=Math.abs(e[i]-t[c])+r[i+1][c+1],f=n-i>o-c?r[i+1][c]:1/0,u=o-c>n-i?r[i][c+1]:1/0;r[i][c]=Math.min(l,f,u),s[i][c]=r[i][c]===l}let a=new Array(n).fill(void 0);for(let i=0,c=0;i<n&&c<o;)s[i][c]?a[i++]=c++:n-i>o-c?i++:c++;return a}function Jn(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var Zn=e=>e.spanningReads!==0;function Qn(e,t){return{...t,agrees:e.complete&&Zn(t)?ci(e.bp,t.bp):void 0}}function di(e,t){let n=new Map,o=new Set;e.forEach((i,c)=>{let l=t.find(f=>f.haplotype!==void 0&&f.haplotype===i.haplotype);l&&(o.add(l),n.set(c,Qn(i,l)))});let r=t.filter(i=>i.haplotype===void 0),s=Jn(e,i=>i.bp),a=[[s.filter(i=>i.item.complete),r.filter(Zn)],[s,r]];for(let[i,c]of a){let l=i.filter(u=>!n.has(u.i)),f=Jn(c.filter(u=>!o.has(u)),u=>u.bp);li(l.map(u=>u.item.bp),f.map(u=>u.item.bp)).forEach((u,d)=>{if(u!==void 0){let p=l[d],m=f[u].item;o.add(m),n.set(p.i,Qn(p.item,m))}})}return n}function Bd(e,t){if(!t)return e;let n=new Map,o=new Map;for(let r of e)o.set(r.sample,[...o.get(r.sample)??[],r]);for(let[r,s]of o){let a=t[r];if(a)for(let[i,c]of di(s,a))n.set(s[i],c)}return e.map(r=>({...r,call:n.get(r)}))}export{qc as a,Fc as b,Gc as c,Yc as d,xt as e,_ as f,ro as g,j as h,Pe as i,Le as j,yt as k,Et as l,ke as m,ao as n,co as o,vt as p,po as q,_t as r,Ot as s,Be as t,ho as u,mo as v,Tt as w,xo as x,z as y,Vs as z,bo as A,yo as B,Mi as C,Eo as D,So as E,al as F,A as G,T as H,ie as I,De as J,ae as K,Ro as L,_o as M,Oo as N,Ao as O,P,fr as Q,pr as R,hr as S,mr as T,Pt as U,Ti as V,ko as W,$i as X,Ii as Y,qe as Z,Po as _,Lo as $,Wi as aa,Ut as ba,Ki as ca,zt as da,Fe as ea,Vt as fa,Jt as ga,Vo as ha,Ge as ia,Jo as ja,en as ka,rr as la,gr as ma,br as na,yr as oa,an as pa,Ac as qa,ir as ra,Tc as sa,Ts as ta,Is as ua,he as va,nt as wa,et as xa,Bs as ya,Xs as za,qs as Aa,ot as Ba,Hs as Ca,Ws as Da,Qs as Ea,Zs as Fa,ei as Ga,td as Ha,nd as Ia,od as Ja,rd as Ka,sd as La,id as Ma,ad as Na,xe as Oa,dd as Pa,fd as Qa,ud as Ra,pd as Sa,hd as Ta,jn as Ua,ri as Va,zn as Wa,si as Xa,ii as Ya,ai as Za,Bd as _a};
|
|
2
|
+
//# sourceMappingURL=chunk-BHJALK4L.js.map
|