jbrowse-plugin-graphgenomeviewer 4.1.1 → 4.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/README.md +4 -4
- package/dist/chunks/{GraphGenomeView-QOBHGMLE.js → GraphGenomeView-ZB4N6Q3H.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-RTSJTM6A.js → GraphTrackSettingsDialog-LXYUYPZS.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-TPXW6POY.js → LinearGraphDisplay-BCTYOYQ5.js} +2 -2
- package/dist/chunks/{RgfaTabixAdapter-5MD2ZZ2F.js → RgfaTabixAdapter-QPKEJZXA.js} +3 -3
- package/dist/chunks/{RgfaTabixAdapter-5MD2ZZ2F.js.map → RgfaTabixAdapter-QPKEJZXA.js.map} +2 -2
- package/dist/chunks/{chunk-4C4CMI6K.js → chunk-CNFN6EVE.js} +2 -2
- package/dist/chunks/chunk-PPYB6N2Q.js +2 -0
- package/dist/chunks/chunk-PPYB6N2Q.js.map +7 -0
- package/dist/chunks/chunk-PSOLXUFN.js +3 -0
- package/dist/chunks/chunk-PSOLXUFN.js.map +7 -0
- package/dist/chunks/chunk-UTWFU4X6.js +2 -0
- package/dist/chunks/chunk-UTWFU4X6.js.map +7 -0
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +2 -2
- package/src/GraphGenomeView/components/GraphCanvas.tsx +6 -53
- package/src/GraphGenomeView/components/WalkRowContextMenu.tsx +63 -0
- package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +1 -1
- package/src/GraphGenomeView/components/WalkStrip.tsx +207 -0
- package/src/GraphGenomeView/components/WalkStripLocator.tsx +49 -0
- package/src/GraphGenomeView/components/usePaneGestures.ts +1 -0
- package/src/GraphGenomeView/model.test.ts +42 -3
- package/src/GraphGenomeView/model.ts +143 -19
- package/src/GraphGenomeView/viewModel.ts +23 -7
- package/src/RgfaTabixAdapter/RgfaTabixAdapter.test.ts +8 -8
- package/src/RgfaTabixAdapter/RgfaTabixAdapter.ts +5 -6
- package/src/RgfaTabixAdapter/rgfaBed.test.ts +7 -7
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-ECKLYJWP.js +0 -2
- package/dist/chunks/chunk-ECKLYJWP.js.map +0 -7
- package/dist/chunks/chunk-HW55QCJG.js +0 -3
- package/dist/chunks/chunk-HW55QCJG.js.map +0 -7
- package/dist/chunks/chunk-SIP5IHWK.js +0 -2
- package/dist/chunks/chunk-SIP5IHWK.js.map +0 -7
- /package/dist/chunks/{GraphGenomeView-QOBHGMLE.js.map → GraphGenomeView-ZB4N6Q3H.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-RTSJTM6A.js.map → GraphTrackSettingsDialog-LXYUYPZS.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-TPXW6POY.js.map → LinearGraphDisplay-BCTYOYQ5.js.map} +0 -0
- /package/dist/chunks/{chunk-4C4CMI6K.js.map → chunk-CNFN6EVE.js.map} +0 -0
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ above it.
|
|
|
22
22
|
|
|
23
23
|
- **Copy number off a bar.** Walk rows tile each haplotype by the 5,548 bp
|
|
24
24
|
kringle: GRCh38's six units are the six LPA exon pairs above, and HG00133
|
|
25
|
-
|
|
25
|
+
has 27.
|
|
26
26
|
|
|
27
27
|

|
|
28
28
|
|
|
@@ -49,9 +49,9 @@ node in the view bands its bp in the linear view:
|
|
|
49
49
|
- Genes from the session's annotation track, drawn on the graph
|
|
50
50
|
- Hovering a callset or MAF row in the same view lifts that haplotype's walk
|
|
51
51
|
- Bubbles from `gfatools bubble` or the graph itself, opened level by level
|
|
52
|
-
- gbz-base haplotypes as walks:
|
|
53
|
-
metro-map lanes or side by side, a panel per
|
|
54
|
-
shading from its start to its end
|
|
52
|
+
- gbz-base haplotypes as walks: the number of walks through a node as its
|
|
53
|
+
thickness, walks lifted out as metro-map lanes or side by side, a panel per
|
|
54
|
+
walk or a row per sample, each shading from its start to its end
|
|
55
55
|
- GAF reads in the tube map, with their mismatches, from a gbz-base track
|
|
56
56
|
- Figures as SVG, from the view's Export SVG or from a JSON spec with no browser
|
|
57
57
|
([docs/figures.md](docs/figures.md))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as x}from"./chunk-
|
|
1
|
+
import{a as x}from"./chunk-PSOLXUFN.js";import"./chunk-PPYB6N2Q.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-CNFN6EVE.js";import{Z as L}from"./chunk-UTWFU4X6.js";import"./chunk-7BKUWQE5.js";import"./chunk-KULNKXPT.js";import{a as s,b as g,c as v,d as G,e as B}from"./chunk-XEJ47DLD.js";import{b as a}from"./chunk-FY3BTKY4.js";var S=a(g(),1);var m=a(G(),1),n=a(v(),1),C=a(g(),1),P=a(L(),1),o=a(s(),1),I=(0,P.makeStyles)()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),b=(0,C.observer)(function({model:e}){let{classes:r}=I();return e.isLoading?(0,o.jsxs)(n.Paper,{className:r.paper,"data-testid":"graph-genome-loading",children:[(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(m.LoadingEllipses,{variant:"h6",message:e.statusMessage}),(0,o.jsx)(n.Button,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),(0,o.jsx)(n.LinearProgress,{variant:"indeterminate"})]}):e.error?(0,o.jsx)(n.Paper,{className:r.paper,children:(0,o.jsx)(m.ErrorBanner,{error:e.error,onReset:()=>{e.retryLoad()}})}):(0,o.jsx)(n.Paper,{className:r.paper,"data-testid":"graph-genome-load-canceled",children:(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(n.Typography,{variant:"h6",children:"Loading canceled"}),(0,o.jsx)(n.Button,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),h=b;var M=a(B(),1),N=a(G(),1),i=a(v(),1),w=a(g(),1),E=a(L(),1),t=a(s(),1),k=`H VN:Z:1.0
|
|
2
2
|
S 1 ACGT
|
|
3
3
|
S 2 GGCC
|
|
4
4
|
S 3 TTAA
|
|
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
|
|
|
7
7
|
L 1 + 3 + 0M
|
|
8
8
|
L 2 + 4 + 0M
|
|
9
9
|
L 3 + 4 + 0M`,z=(0,E.makeStyles)()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),R=(0,w.observer)(function({model:e}){let{classes:r}=z(),[d,T]=(0,M.useState)("");function y(){d.trim()&&e.loadGFAFromLocation({uri:d,locationType:"UriLocation"})}function A(p){let c=p.target.files?.[0];c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return(0,t.jsxs)(i.Paper,{className:r.paper,children:[(0,t.jsx)("div",{className:r.header,children:(0,t.jsx)(i.Typography,{variant:"h6",children:"Load a GFA graph"})}),(0,t.jsxs)("div",{className:r.column,children:[(0,t.jsxs)("div",{className:r.rowCenter,children:[(0,t.jsxs)(i.Button,{variant:"outlined",component:"label",size:"small",children:["Choose file",(0,t.jsx)("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:p=>{A(p)}})]}),(0,t.jsx)(i.Typography,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),(0,t.jsxs)("div",{className:r.rowEnd,children:[(0,t.jsx)(i.TextField,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:d,onChange:p=>{T(p.target.value)},onKeyDown:p=>{p.key==="Enter"&&y()},className:r.flex1}),(0,t.jsx)(i.Button,{variant:"contained",onClick:()=>{y()},disabled:!d.trim(),children:"Open"})]})]}),(0,t.jsx)("div",{className:r.footer,children:(0,t.jsx)(i.Button,{size:"small",onClick:()=>{e.loadGFA(k,"Example graph")},children:"Load 4-node example"})}),e.error?(0,t.jsx)(N.ErrorBanner,{error:e.error}):null]})}),F=R;var l=a(s(),1),U=(0,S.observer)(function({model:e}){return e.hasGraph?(0,l.jsx)(x,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?(0,l.jsx)(h,{model:e}):(0,l.jsxs)(l.Fragment,{children:[e.isLoading?(0,l.jsx)(h,{model:e}):null,(0,l.jsx)("div",{hidden:e.isLoading,children:(0,l.jsx)(F,{model:e})})]})}),O=U;export{O as default};
|
|
10
|
-
//# sourceMappingURL=GraphGenomeView-
|
|
10
|
+
//# sourceMappingURL=GraphGenomeView-ZB4N6Q3H.js.map
|
package/dist/chunks/{GraphTrackSettingsDialog-RTSJTM6A.js → GraphTrackSettingsDialog-LXYUYPZS.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as g}from"./chunk-
|
|
1
|
+
import{a as g}from"./chunk-CNFN6EVE.js";import{Z as f}from"./chunk-UTWFU4X6.js";import"./chunk-7BKUWQE5.js";import"./chunk-KULNKXPT.js";import{a as l,b as m,c as y,e as x}from"./chunk-XEJ47DLD.js";import{b as o}from"./chunk-FY3BTKY4.js";var a=o(y(),1),b=o(m(),1),S=o(f(),1),n=o(l(),1),L=(0,S.makeStyles)()({section:{marginBottom:24},formControl:{minWidth:200}}),w=[{value:0,label:"None"},{value:1,label:"1 hop"},{value:2,label:"2 hops"}],k=(0,b.observer)(function({model:e}){let{classes:t}=L();return(0,n.jsxs)("div",{className:t.section,children:[(0,n.jsxs)(a.FormControl,{className:t.formControl,children:[(0,n.jsx)(a.InputLabel,{children:"Graph context"}),(0,n.jsx)(a.Select,{value:e.subgraphContext,label:"Graph context","data-testid":"graph-context-select",onChange:p=>{e.setSubgraphContext(p.target.value),e.cut()},children:w.map(({value:p,label:u})=>(0,n.jsx)(a.MenuItem,{value:p,children:u},p))})]}),(0,n.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"How far the cut follows links out of the region, one hop by default. A detour that leaves the reference before the window and rejoins after it is indexed under its own sequence, so at none its middle is missing and the one bubble draws as two unrelated stubs. Each hop costs a query per off-reference segment already reached."})]})}),v=k;var C=o(x(),1),d=o(y(),1),c=o(m(),1),G=o(f(),1),i=o(l(),1),T=(0,G.makeStyles)()({section:{marginBottom:24}});function M(r){let e=r.split(/[\s,]+/).map(t=>t.trim()).filter(t=>t!=="");return e.length===0?void 0:e}var F=(0,c.observer)(function({model:e}){let[t,p]=(0,C.useState)(e.chosenHaplotypes?.join(", ")??""),u=()=>{let s=M(t)??[];s.join(`
|
|
2
2
|
`)===(e.chosenHaplotypes??[]).join(`
|
|
3
3
|
`)||(e.setSubgraphHaplotypes(s),e.cut())};return(0,i.jsx)(d.TextField,{fullWidth:!0,label:"Haplotypes",placeholder:"every haplotype",value:t,slotProps:{htmlInput:{"data-testid":"graph-haplotypes-field"}},onChange:s=>{p(s.target.value)},onBlur:()=>{u()},onKeyDown:s=>{s.key==="Enter"&&u()}})}),N=(0,c.observer)(function({model:e}){let{classes:t}=T();return e.adapterConfig.type==="GbzBaseSyntenyAdapter"?(0,i.jsxs)("div",{className:t.section,children:[(0,i.jsx)(F,{model:e},e.chosenHaplotypes?.join(",")??""),(0,i.jsx)(d.Typography,{variant:"caption",color:"text.secondary",children:"The haplotypes the cut is for, as lane assembly names or PanSN prefixes (HG002#1, or HG002 for both), separated by commas. The cut keeps their walks and the nodes those walks visit, with the reference. Empty is every haplotype."})]}):null}),H=N;var h=o(l(),1);function B({model:r,open:e,onClose:t}){return(0,h.jsxs)(g,{model:r,open:e,onClose:t,children:[(0,h.jsx)(v,{model:r}),(0,h.jsx)(H,{model:r})]})}export{B as default};
|
|
4
|
-
//# sourceMappingURL=GraphTrackSettingsDialog-
|
|
4
|
+
//# sourceMappingURL=GraphTrackSettingsDialog-LXYUYPZS.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=LinearGraphDisplay-
|
|
1
|
+
import{a as i}from"./chunk-PSOLXUFN.js";import"./chunk-PPYB6N2Q.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-CNFN6EVE.js";import"./chunk-UTWFU4X6.js";import"./chunk-7BKUWQE5.js";import"./chunk-KULNKXPT.js";import{a as e,b as d}from"./chunk-XEJ47DLD.js";import{a as h,b as t}from"./chunk-FY3BTKY4.js";var p=h((l,o)=>{o.exports=JBrowseExports["@jbrowse/display-kit/DisplayChrome"]});var s=t(p(),1),n=t(d(),1);var r=t(e(),1),y=(0,n.observer)(function({model:a}){return(0,r.jsx)(s.DisplayStatusChrome,{model:a,phase:a.displayPhase,drawn:a.painted&&a.geometryPainted,testid:"linear-graph-display","data-layout":a.chosenLayoutMode,"data-cut-tier":a.cutTier,"data-recuts":a.recuts,"data-node-count":a.hasGraph?a.nodeCount:void 0,"data-loading":a.isLoading?"":void 0,style:{width:a.paneWidth,height:a.height,overflow:"hidden"},children:(0,r.jsx)(i,{model:a,ownChrome:!1})})}),c=y;export{c as default};
|
|
2
|
+
//# sourceMappingURL=LinearGraphDisplay-BCTYOYQ5.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as O,b as P,d as h,e as L}from"./chunk-KDIBFGZM.js";import"./chunk-KWAXLUPQ.js";import{a as B}from"./chunk-J4OLMLS5.js";import"./chunk-KULNKXPT.js";import{b as S}from"./chunk-FY3BTKY4.js";var
|
|
2
|
-
`)}function
|
|
3
|
-
//# sourceMappingURL=RgfaTabixAdapter-
|
|
1
|
+
import{a as O,b as P,d as h,e as L}from"./chunk-KDIBFGZM.js";import"./chunk-KWAXLUPQ.js";import{a as B}from"./chunk-J4OLMLS5.js";import"./chunk-KULNKXPT.js";import{b as S}from"./chunk-FY3BTKY4.js";var F=S(O(),1),l=S(B(),1),M=S(P(),1);function x(t){let e=t.split(" ");return{refName:e[0],start:+e[1],end:+e[2],id:e[3],rank:+e[4],tags:e[5]??""}}function $(t){let e=t.tags.split(" ").find(a=>a.startsWith("SM:Z:"));if(e===void 0)return;let n=e.slice(5).split(",").map(a=>a.trim()).filter(Boolean);return n.length>0?n:void 0}function w(t){return{id:t.slice(0,-1),strand:t.slice(-1)}}function A(t){let e=t.split(" "),n=w(e[3]),a=w(e[4]);return{source:n.id,sourceStrand:n.strand,target:a.id,targetStrand:a.strand,sourceSegment:{id:n.id,refName:e[5],start:+e[6],end:+e[7],rank:+e[8],tags:e[13]??""},targetSegment:{id:a.id,refName:e[9],start:+e[10],end:+e[11],rank:+e[12],tags:e[14]??""}}}function I(t){return`${t.source}${t.sourceStrand}${t.target}${t.targetStrand}`}var j=/^[A-Za-z][A-Za-z0-9]:[AifZJHB]:/;function G(t){let{id:e,refName:n,start:a,end:r,rank:s,tags:m}=t,o=m.split(" ").filter(g=>j.test(g)),i=o.length===0?"":` ${o.join(" ")}`;return`S ${e} * LN:i:${r-a} SN:Z:${n} SO:i:${a} SR:i:${s}${i}`}function Z(t){let{source:e,sourceStrand:n,target:a,targetStrand:r}=t;return`L ${e} ${n} ${a} ${r} 0M`}function b(t,e){return t<e?-1:t>e?1:0}function T(t,e){let n=[...t.values()].sort((r,s)=>b(r.refName,s.refName)||r.start-s.start||b(r.id,s.id)),a=[...e.keys()].sort((r,s)=>b(r,s));return["H VN:Z:1.0",...n.map(r=>G(r)),...a.map(r=>Z(e.get(r)))].join(`
|
|
2
|
+
`)}function C(t){return t.filter(e=>e.rank>0)}var N=class extends F.BaseFeatureDataAdapter{static{this.capabilities=["getFeatures","getRefNames"]}constructor(e,n,a){super(e,n,a),this.fine=this.openIndex([])}openIndex(e){let n=h(this,[...e,"segmentsLocation"],[...e,"segmentsIndex"]);return{segments:n,links:h(this,[...e,"linksLocation"],[...e,"linksIndex"]),refNames:new L(n,this)}}index(e="fine"){return e==="fine"?this.fine:(this.coarse??=this.openIndex(["coarse"]),this.coarse)}async getRefNames(e={}){return this.fine.refNames.assemblyRefNames(e)}async hasDataForRefName(){return!0}getFeatures(e,n={}){let{signal:a,statusCallback:r}=n;return(0,M.ObservableCreate)(async s=>{let m=await this.fine.refNames.resolve(e,n);m!==void 0&&await(0,l.updateStatus)("Downloading segments",r,()=>this.fine.segments.getLines(m,e.start,e.end,{signal:a,lineCallback:o=>{let i=x(o),g=$(i);s.next(new l.SimpleFeature({uniqueId:i.id,refName:e.refName,start:i.start,end:i.end,name:i.id,type:"segment",rank:i.rank,stableName:i.refName,...g&&{samples:g,sampleCount:g.length}}))}})),s.complete()},a)}async getSubgraph(e,n={}){let{hops:a=0,signal:r,tier:s}=n,m=this.index(s),o=new Map,i=new Map,g=await m.refNames.resolve(e,{signal:r}),R=async(f,p,d)=>{let y=[];return await m.links.getLines(f,p,d,{signal:r,lineCallback:v=>{let c=A(v);i.set(I(c),c);for(let u of[c.sourceSegment,c.targetSegment])o.has(u.id)||(o.set(u.id,u),y.push(u))}}),y};if(g===void 0)throw new Error(`${e.assemblyName} ${e.refName} is not in this graph's index; a graph with PanSN names (GRCh38#0#chr1) needs ${e.assemblyName} mapped to its prefix in assemblyNameToPanSN`);await m.segments.getLines(g,e.start,e.end,{signal:r,lineCallback:f=>{let p=x(f);o.set(p.id,p)}});let k=C(await R(g,e.start,e.end));for(let f=0;f<a;f++){let p=await Promise.all(k.map(d=>R(d.refName,d.start,d.end)));k=C(p.flat())}return T(o,i)}};export{N as default};
|
|
3
|
+
//# sourceMappingURL=RgfaTabixAdapter-QPKEJZXA.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/RgfaTabixAdapter/RgfaTabixAdapter.ts", "../../src/RgfaTabixAdapter/rgfaBed.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport { SimpleFeature, updateStatus } from '@jbrowse/core/util'\nimport { ObservableCreate } from '@jbrowse/core/util/rxjs'\n\nimport { PanSNRefNames, openTabixSlot } from '../panSNTabix.ts'\nimport {\n formatSubgraph,\n linkKey,\n parseLinkLine,\n parseSegmentLine,\n segmentSamples,\n} from './rgfaBed.ts'\n\nimport type { RgfaTabixAdapterConfig } from './configSchema.ts'\nimport type { SubgraphAdapterOptions, SubgraphTier } from '../GetSubgraph.ts'\nimport type { RgfaLink, RgfaSegment } from './rgfaBed.ts'\nimport type { TabixIndexedFile } from '@gmod/tabix'\nimport type PluginManager from '@jbrowse/core/PluginManager'\nimport type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'\nimport type { Feature } from '@jbrowse/core/util'\nimport type { Region } from '@jbrowse/core/util/types'\n\n// What a hop follows: alleles, never the backbone. A rank-0 segment reached\n// through a link is flanking backbone, usually outside the window, so querying\n// its links walks the reference away from the region, brings back more backbone,\n// and closes nothing. Every segment that closes a bubble is an allele interior,\n// and an allele interior is rank > 0 in both index formats (rGFA's SR tag, and\n// pggb's rank 0-or-1 against the anchor path). Reached backbone still becomes a\n// node and its edge still draws; it is only not walked through.\n//\n// This is gfabase's rule, arrived at from the other end. `gfabase sub` expands\n// from a seed either to the whole connected component (`--connected`, which its\n// own README calls overkill) or with `--cutpoints 1`, which takes the biconnected\n// component by *stopping at cutpoints*, the segments every end-to-end walk of\n// the chromosome must traverse. In a reference-anchored pangenome the cutpoints\n// are the backbone, and rank is what the index already states about it, so\n// `rank > 0` is that stopping rule without a connectivity index to build. The\n// third tool is the same shape again: `gfatools view -R` maps the region onto its\n// precomputed bubble decomposition and returns whole overlapping bubbles\n// (gfa_query_by_reg), which is complete for the same reason. Bandage's own\n// `--distance` is a node-step radius, but Bandage holds the entire graph in\n// memory, so its scope is a drawing filter rather than a fetch strategy.\n//\n// Measured with this rule: the E. coli paa window converges at one hop (17\n// segments at 1 and at 2), so the cut closes and stays closed. HPRC's amylase\n// window keeps growing (63 at 0, 78 at 1, 92 at 2) because its alleles have\n// alleles, and wall-clock is flat across all three, since a hop's queries go out\n// together and the remote index dominates.\n//\n// The exact version, when a graph ships a bubble index beside its segments:\n// gfatools' bubble rows carry the member segment ids of every bubble, so the\n// bubbles overlapping the region state which segments a complete cut must\n// contain. That turns the hop count into a termination condition rather than a\n// setting, and MinigraphBubbleAdapter already parses those rows.\nfunction offReference(segments: RgfaSegment[]) {\n return segments.filter(segment => segment.rank > 0)\n}\n\ninterface GraphIndex {\n segments: TabixIndexedFile\n links: TabixIndexedFile\n refNames: PanSNRefNames\n}\n\nexport default class RgfaTabixAdapter extends BaseFeatureDataAdapter<RgfaTabixAdapterConfig> {\n public static capabilities = ['getFeatures', 'getRefNames']\n\n private readonly fine\n private coarse: GraphIndex | undefined\n\n public constructor(\n config: RgfaTabixAdapterConfig,\n getSubAdapter?: getSubAdapterType,\n pluginManager?: PluginManager,\n ) {\n super(config, getSubAdapter, pluginManager)\n this.fine = this.openIndex([])\n }\n\n // refNames off the SEGMENT index: it is the one that names every stable\n // sequence the graph is anchored to, where the link index only names those a\n // link touches.\n private openIndex(under: string[]): GraphIndex {\n const segments = openTabixSlot(\n this,\n [...under, 'segmentsLocation'],\n [...under, 'segmentsIndex'],\n )\n return {\n segments,\n links: openTabixSlot(\n this,\n [...under, 'linksLocation'],\n [...under, 'linksIndex'],\n ),\n refNames: new PanSNRefNames(segments, this),\n }\n }\n\n private index(tier: SubgraphTier = 'fine') {\n if (tier === 'fine') {\n return this.fine\n }\n this.coarse ??= this.openIndex(['coarse'])\n return this.coarse\n }\n\n async getRefNames(opts: BaseOptions = {}) {\n return this.fine.refNames.assemblyRefNames(opts)\n }\n\n public async hasDataForRefName() {\n return true\n }\n\n getFeatures(query: Region, opts: BaseOptions = {}) {\n const { signal, statusCallback } = opts\n return ObservableCreate<Feature>(async observer => {\n const tabixRefName = await this.fine.refNames.resolve(query, opts)\n if (tabixRefName !== undefined) {\n await updateStatus('Downloading segments', statusCallback, () =>\n this.fine.segments.getLines(tabixRefName, query.start, query.end, {\n signal,\n lineCallback: line => {\n const segment = parseSegmentLine(line)\n // `samples` is who, `carriers` is how many, and the second is not\n // just a convenience: a lane colored by carriage is a jexl\n // expression in a config, where counting a list means relying on\n // jexl resolving `.length` through a member access on an array.\n // The count is the axis the color reads, so the index states it.\n const samples = segmentSamples(segment)\n observer.next(\n new SimpleFeature({\n uniqueId: segment.id,\n refName: query.refName,\n start: segment.start,\n end: segment.end,\n name: segment.id,\n type: 'segment',\n rank: segment.rank,\n stableName: segment.refName,\n ...(samples && { samples, carriers: samples.length }),\n }),\n )\n },\n }),\n )\n }\n observer.complete()\n }, signal)\n }\n\n // Extract the graph around a region as GFA text, for GraphGenomeView. The\n // region's own segments come from segs.bed.gz; links.bed.gz supplies the edges\n // incident to them *and* the coordinates of the segments on the other end,\n // which typically sit on a different stable sequence (a rank>0 bubble) and so\n // are not reachable by any coordinate query on this region.\n //\n // `hops` is extra rounds of link-following past the region's own segments\n // and their immediate neighbours, each costing one tabix query per\n // off-reference segment newly reached. One round is what closes a bubble, so\n // it is the default the view asks for; see the frontier below. `signal` goes\n // to every one of those queries, so a cut the view has replaced stops.\n // `tier: 'coarse'` reads the `coarse` pair instead, the same way.\n async getSubgraph(region: Region, opts: SubgraphAdapterOptions = {}) {\n const { hops = 0, signal, tier } = opts\n const index = this.index(tier)\n const segments = new Map<string, RgfaSegment>()\n const links = new Map<string, RgfaLink>()\n const tabixRefName = await index.refNames.resolve(region, { signal })\n\n const addLinksOver = async (\n refName: string,\n start: number,\n end: number,\n ) => {\n const reached: RgfaSegment[] = []\n await index.links.getLines(refName, start, end, {\n signal,\n lineCallback: line => {\n const link = parseLinkLine(line)\n links.set(linkKey(link), link)\n for (const segment of [link.sourceSegment, link.targetSegment]) {\n if (!segments.has(segment.id)) {\n segments.set(segment.id, segment)\n reached.push(segment)\n }\n }\n },\n })\n return reached\n }\n\n if (tabixRefName === undefined) {\n throw new Error(\n `${region.assemblyName} ${region.refName} is not in this graph's index; a graph with PanSN names (GRCh38#0#chr1) needs ${region.assemblyName} mapped to its prefix in assemblyNameToPanSN`,\n )\n }\n await index.segments.getLines(tabixRefName, region.start, region.end, {\n signal,\n lineCallback: line => {\n const segment = parseSegmentLine(line)\n segments.set(segment.id, segment)\n },\n })\n let frontier = offReference(\n await addLinksOver(tabixRefName, region.start, region.end),\n )\n for (let hop = 0; hop < hops; hop++) {\n // One hop's queries are independent of each other, so they go out\n // together rather than one round-trip at a time. Their callbacks share\n // the segment and link maps, which is safe because only one of them runs\n // at a time, and the output is sorted at the end regardless of the order\n // they arrive in.\n const reached = await Promise.all(\n frontier.map(segment =>\n addLinksOver(segment.refName, segment.start, segment.end),\n ),\n )\n frontier = offReference(reached.flat())\n }\n\n return formatSubgraph(segments, links)\n }\n}\n", "// A segment as it appears in segs.bed.gz, and as it is repeated inside every\n// links.bed.gz row: `stableName start end segmentId rank [tags]`. The first\n// five are the SN/SO/SR tags rGFA already carries, projected to BED by\n// `gfatools gfa2bed -m`.\n//\n// `tags` is a space-separated list of GFA tags, written verbatim onto the\n// S-line formatSegment synthesizes, where the GFA parser reads them into\n// `GraphNode.tags` with no work here. It is the extension point for everything\n// the five columns cannot say: carriage on a path-derived graph (`SM:Z:`), the\n// collapse summary on a level-of-detail tier (`ct:Z:`, `cn:i:`, ...), a\n// precomputed layout position later. rGFA files have no sixth column at all,\n// so this is empty for them and nothing changes.\nexport interface RgfaSegment {\n refName: string\n start: number\n end: number\n id: string\n rank: number\n tags: string\n}\n\nexport interface RgfaLink {\n source: string\n sourceStrand: string\n target: string\n targetStrand: string\n sourceSegment: RgfaSegment\n targetSegment: RgfaSegment\n}\n\nexport function parseSegmentLine(line: string): RgfaSegment {\n const cols = line.split('\\t')\n return {\n refName: cols[0]!,\n start: +cols[1]!,\n end: +cols[2]!,\n id: cols[3]!,\n rank: +cols[4]!,\n tags: cols[5] ?? '',\n }\n}\n\n// Carriage as an ordinary feature attribute, for the linear track rather than\n// the graph. The tag column reaches the graph view through the synthesized\n// S-line (formatSegment below, then gfaConverter reads SM into\n// `GraphNode.samples`), and that route ends at the graph: `getFeatures` builds\n// its own features and had no way to say who carries a segment, so a lane\n// colored by carriage was not expressible.\n//\n// `SM:Z:` is its own grammar check here. build_pggb_tabix.sh wrote a bare\n// comma-separated list in this column before the tag column existed, and those\n// files are still hosted; a bare list has no prefix to match, so it is dropped\n// rather than read as one sample named `K12,Sakai,CFT073`.\n//\n// Undefined rather than [] when the tag is absent, matching gfaConverter: an\n// rGFA has no sixth column at all, so a segment that says nothing about\n// carriage stays distinguishable from one carried by nobody.\nexport function segmentSamples(segment: RgfaSegment) {\n const tag = segment.tags.split(' ').find(t => t.startsWith('SM:Z:'))\n if (tag === undefined) {\n return undefined\n }\n const samples = tag\n .slice('SM:Z:'.length)\n .split(',')\n .map(s => s.trim())\n .filter(Boolean)\n return samples.length > 0 ? samples : undefined\n}\n\n// `s322+` \u2014 the L-line's segment id with its orientation appended, mirroring\n// the GFA record it came from.\nfunction parseEndpoint(field: string) {\n return { id: field.slice(0, -1), strand: field.slice(-1) }\n}\n\nexport function parseLinkLine(line: string): RgfaLink {\n const cols = line.split('\\t')\n const source = parseEndpoint(cols[3]!)\n const target = parseEndpoint(cols[4]!)\n return {\n source: source.id,\n sourceStrand: source.strand,\n target: target.id,\n targetStrand: target.strand,\n sourceSegment: {\n id: source.id,\n refName: cols[5]!,\n start: +cols[6]!,\n end: +cols[7]!,\n rank: +cols[8]!,\n tags: cols[13] ?? '',\n },\n targetSegment: {\n id: target.id,\n refName: cols[9]!,\n start: +cols[10]!,\n end: +cols[11]!,\n rank: +cols[12]!,\n tags: cols[14] ?? '',\n },\n }\n}\n\nexport function linkKey(link: RgfaLink) {\n return `${link.source}${link.sourceStrand}${link.target}${link.targetStrand}`\n}\n\n// Both endpoints of a link are written into every row, so the same link is\n// indexed under each endpoint's stable sequence and arrives twice for a region\n// covering both. Callers dedupe on linkKey.\n\n// Segments carry no sequence here \u2014 the BED records only their span \u2014 so every\n// S-line is written with `*` and an LN tag, which is what the GFA spec asks for\n// and what packages/graph-core's parser reads back as the node length.\n// `NM:i:0`, `SM:Z:HG002.1,HG002.2` \u2014 the GFA tag grammar, checked rather than\n// trusted. Files built before the tag column existed put a bare comma-separated\n// sample list here, and passing that through would put a field that is not a\n// tag on an S-line, which is a malformed GFA rather than a missing annotation.\n// Dropping it degrades to the pre-tag behaviour instead.\nconst GFA_TAG = /^[A-Za-z][A-Za-z0-9]:[AifZJHB]:/\n\nfunction formatSegment(segment: RgfaSegment) {\n const { id, refName, start, end, rank, tags } = segment\n const valid = tags.split(' ').filter(t => GFA_TAG.test(t))\n const extra = valid.length === 0 ? '' : `\\t${valid.join('\\t')}`\n return `S\\t${id}\\t*\\tLN:i:${end - start}\\tSN:Z:${refName}\\tSO:i:${start}\\tSR:i:${rank}${extra}`\n}\n\nfunction formatLink(link: RgfaLink) {\n const { source, sourceStrand, target, targetStrand } = link\n return `L\\t${source}\\t${sourceStrand}\\t${target}\\t${targetStrand}\\t0M`\n}\n\n// Codepoint order, not localeCompare: the byte-identical-output guarantee below\n// has to hold across locales.\nfunction compare(a: string, b: string) {\n return a < b ? -1 : a > b ? 1 : 0\n}\n\n// Deterministic ordering: the same region always produces byte-identical GFA,\n// so a layout computed from it is reproducible.\nexport function formatSubgraph(\n segments: Map<string, RgfaSegment>,\n links: Map<string, RgfaLink>,\n) {\n const sortedSegments = [...segments.values()].sort(\n (a, b) =>\n compare(a.refName, b.refName) || a.start - b.start || compare(a.id, b.id),\n )\n const sortedLinks = [...links.keys()].sort((a, b) => compare(a, b))\n return [\n 'H\\tVN:Z:1.0',\n ...sortedSegments.map(s => formatSegment(s)),\n ...sortedLinks.map(k => formatLink(links.get(k)!)),\n ].join('\\n')\n}\n"],
|
|
5
|
-
"mappings": "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
|
|
4
|
+
"sourcesContent": ["import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport { SimpleFeature, updateStatus } from '@jbrowse/core/util'\nimport { ObservableCreate } from '@jbrowse/core/util/rxjs'\n\nimport { PanSNRefNames, openTabixSlot } from '../panSNTabix.ts'\nimport {\n formatSubgraph,\n linkKey,\n parseLinkLine,\n parseSegmentLine,\n segmentSamples,\n} from './rgfaBed.ts'\n\nimport type { RgfaTabixAdapterConfig } from './configSchema.ts'\nimport type { SubgraphAdapterOptions, SubgraphTier } from '../GetSubgraph.ts'\nimport type { RgfaLink, RgfaSegment } from './rgfaBed.ts'\nimport type { TabixIndexedFile } from '@gmod/tabix'\nimport type PluginManager from '@jbrowse/core/PluginManager'\nimport type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'\nimport type { Feature } from '@jbrowse/core/util'\nimport type { Region } from '@jbrowse/core/util/types'\n\n// What a hop follows: alleles, never the backbone. A rank-0 segment reached\n// through a link is flanking backbone, usually outside the window, so querying\n// its links walks the reference away from the region, brings back more backbone,\n// and closes nothing. Every segment that closes a bubble is an allele interior,\n// and an allele interior is rank > 0 in both index formats (rGFA's SR tag, and\n// pggb's rank 0-or-1 against the anchor path). Reached backbone still becomes a\n// node and its edge still draws; it is only not walked through.\n//\n// This is gfabase's rule, arrived at from the other end. `gfabase sub` expands\n// from a seed either to the whole connected component (`--connected`, which its\n// own README calls overkill) or with `--cutpoints 1`, which takes the biconnected\n// component by *stopping at cutpoints*, the segments every end-to-end walk of\n// the chromosome must traverse. In a reference-anchored pangenome the cutpoints\n// are the backbone, and rank is what the index already states about it, so\n// `rank > 0` is that stopping rule without a connectivity index to build. The\n// third tool is the same shape again: `gfatools view -R` maps the region onto its\n// precomputed bubble decomposition and returns whole overlapping bubbles\n// (gfa_query_by_reg), which is complete for the same reason. Bandage's own\n// `--distance` is a node-step radius, but Bandage holds the entire graph in\n// memory, so its scope is a drawing filter rather than a fetch strategy.\n//\n// Measured with this rule: the E. coli paa window converges at one hop (17\n// segments at 1 and at 2), so the cut closes and stays closed. HPRC's amylase\n// window keeps growing (63 at 0, 78 at 1, 92 at 2) because its alleles have\n// alleles, and wall-clock is flat across all three, since a hop's queries go out\n// together and the remote index dominates.\n//\n// The exact version, when a graph ships a bubble index beside its segments:\n// gfatools' bubble rows carry the member segment ids of every bubble, so the\n// bubbles overlapping the region state which segments a complete cut must\n// contain. That turns the hop count into a termination condition rather than a\n// setting, and MinigraphBubbleAdapter already parses those rows.\nfunction offReference(segments: RgfaSegment[]) {\n return segments.filter(segment => segment.rank > 0)\n}\n\ninterface GraphIndex {\n segments: TabixIndexedFile\n links: TabixIndexedFile\n refNames: PanSNRefNames\n}\n\nexport default class RgfaTabixAdapter extends BaseFeatureDataAdapter<RgfaTabixAdapterConfig> {\n public static capabilities = ['getFeatures', 'getRefNames']\n\n private readonly fine\n private coarse: GraphIndex | undefined\n\n public constructor(\n config: RgfaTabixAdapterConfig,\n getSubAdapter?: getSubAdapterType,\n pluginManager?: PluginManager,\n ) {\n super(config, getSubAdapter, pluginManager)\n this.fine = this.openIndex([])\n }\n\n // refNames off the SEGMENT index: it is the one that names every stable\n // sequence the graph is anchored to, where the link index only names those a\n // link touches.\n private openIndex(under: string[]): GraphIndex {\n const segments = openTabixSlot(\n this,\n [...under, 'segmentsLocation'],\n [...under, 'segmentsIndex'],\n )\n return {\n segments,\n links: openTabixSlot(\n this,\n [...under, 'linksLocation'],\n [...under, 'linksIndex'],\n ),\n refNames: new PanSNRefNames(segments, this),\n }\n }\n\n private index(tier: SubgraphTier = 'fine') {\n if (tier === 'fine') {\n return this.fine\n }\n this.coarse ??= this.openIndex(['coarse'])\n return this.coarse\n }\n\n async getRefNames(opts: BaseOptions = {}) {\n return this.fine.refNames.assemblyRefNames(opts)\n }\n\n public async hasDataForRefName() {\n return true\n }\n\n getFeatures(query: Region, opts: BaseOptions = {}) {\n const { signal, statusCallback } = opts\n return ObservableCreate<Feature>(async observer => {\n const tabixRefName = await this.fine.refNames.resolve(query, opts)\n if (tabixRefName !== undefined) {\n await updateStatus('Downloading segments', statusCallback, () =>\n this.fine.segments.getLines(tabixRefName, query.start, query.end, {\n signal,\n lineCallback: line => {\n const segment = parseSegmentLine(line)\n // `samples` lists the haplotypes whose paths visit the segment and\n // `sampleCount` counts them. A lane's color reads the count, and\n // a count in jexl would otherwise rely on `.length` resolving\n // through a member access on an array.\n const samples = segmentSamples(segment)\n observer.next(\n new SimpleFeature({\n uniqueId: segment.id,\n refName: query.refName,\n start: segment.start,\n end: segment.end,\n name: segment.id,\n type: 'segment',\n rank: segment.rank,\n stableName: segment.refName,\n ...(samples && { samples, sampleCount: samples.length }),\n }),\n )\n },\n }),\n )\n }\n observer.complete()\n }, signal)\n }\n\n // Extract the graph around a region as GFA text, for GraphGenomeView. The\n // region's own segments come from segs.bed.gz; links.bed.gz supplies the edges\n // incident to them *and* the coordinates of the segments on the other end,\n // which typically sit on a different stable sequence (a rank>0 bubble) and so\n // are not reachable by any coordinate query on this region.\n //\n // `hops` is extra rounds of link-following past the region's own segments\n // and their immediate neighbours, each costing one tabix query per\n // off-reference segment newly reached. One round is what closes a bubble, so\n // it is the default the view asks for; see the frontier below. `signal` goes\n // to every one of those queries, so a cut the view has replaced stops.\n // `tier: 'coarse'` reads the `coarse` pair instead, the same way.\n async getSubgraph(region: Region, opts: SubgraphAdapterOptions = {}) {\n const { hops = 0, signal, tier } = opts\n const index = this.index(tier)\n const segments = new Map<string, RgfaSegment>()\n const links = new Map<string, RgfaLink>()\n const tabixRefName = await index.refNames.resolve(region, { signal })\n\n const addLinksOver = async (\n refName: string,\n start: number,\n end: number,\n ) => {\n const reached: RgfaSegment[] = []\n await index.links.getLines(refName, start, end, {\n signal,\n lineCallback: line => {\n const link = parseLinkLine(line)\n links.set(linkKey(link), link)\n for (const segment of [link.sourceSegment, link.targetSegment]) {\n if (!segments.has(segment.id)) {\n segments.set(segment.id, segment)\n reached.push(segment)\n }\n }\n },\n })\n return reached\n }\n\n if (tabixRefName === undefined) {\n throw new Error(\n `${region.assemblyName} ${region.refName} is not in this graph's index; a graph with PanSN names (GRCh38#0#chr1) needs ${region.assemblyName} mapped to its prefix in assemblyNameToPanSN`,\n )\n }\n await index.segments.getLines(tabixRefName, region.start, region.end, {\n signal,\n lineCallback: line => {\n const segment = parseSegmentLine(line)\n segments.set(segment.id, segment)\n },\n })\n let frontier = offReference(\n await addLinksOver(tabixRefName, region.start, region.end),\n )\n for (let hop = 0; hop < hops; hop++) {\n // One hop's queries are independent of each other, so they go out\n // together rather than one round-trip at a time. Their callbacks share\n // the segment and link maps, which is safe because only one of them runs\n // at a time, and the output is sorted at the end regardless of the order\n // they arrive in.\n const reached = await Promise.all(\n frontier.map(segment =>\n addLinksOver(segment.refName, segment.start, segment.end),\n ),\n )\n frontier = offReference(reached.flat())\n }\n\n return formatSubgraph(segments, links)\n }\n}\n", "// A segment as it appears in segs.bed.gz, and as it is repeated inside every\n// links.bed.gz row: `stableName start end segmentId rank [tags]`. The first\n// five are the SN/SO/SR tags rGFA already carries, projected to BED by\n// `gfatools gfa2bed -m`.\n//\n// `tags` is a space-separated list of GFA tags, written verbatim onto the\n// S-line formatSegment synthesizes, where the GFA parser reads them into\n// `GraphNode.tags` with no work here. It is the extension point for everything\n// the five columns cannot say: carriage on a path-derived graph (`SM:Z:`), the\n// collapse summary on a level-of-detail tier (`ct:Z:`, `cn:i:`, ...), a\n// precomputed layout position later. rGFA files have no sixth column at all,\n// so this is empty for them and nothing changes.\nexport interface RgfaSegment {\n refName: string\n start: number\n end: number\n id: string\n rank: number\n tags: string\n}\n\nexport interface RgfaLink {\n source: string\n sourceStrand: string\n target: string\n targetStrand: string\n sourceSegment: RgfaSegment\n targetSegment: RgfaSegment\n}\n\nexport function parseSegmentLine(line: string): RgfaSegment {\n const cols = line.split('\\t')\n return {\n refName: cols[0]!,\n start: +cols[1]!,\n end: +cols[2]!,\n id: cols[3]!,\n rank: +cols[4]!,\n tags: cols[5] ?? '',\n }\n}\n\n// Carriage as an ordinary feature attribute, for the linear track rather than\n// the graph. The tag column reaches the graph view through the synthesized\n// S-line (formatSegment below, then gfaConverter reads SM into\n// `GraphNode.samples`), and that route ends at the graph: `getFeatures` builds\n// its own features and had no way to say who carries a segment, so a lane\n// colored by carriage was not expressible.\n//\n// `SM:Z:` is its own grammar check here. build_pggb_tabix.sh wrote a bare\n// comma-separated list in this column before the tag column existed, and those\n// files are still hosted; a bare list has no prefix to match, so it is dropped\n// rather than read as one sample named `K12,Sakai,CFT073`.\n//\n// Undefined rather than [] when the tag is absent, matching gfaConverter: an\n// rGFA has no sixth column at all, so a segment that says nothing about\n// carriage stays distinguishable from one carried by nobody.\nexport function segmentSamples(segment: RgfaSegment) {\n const tag = segment.tags.split(' ').find(t => t.startsWith('SM:Z:'))\n if (tag === undefined) {\n return undefined\n }\n const samples = tag\n .slice('SM:Z:'.length)\n .split(',')\n .map(s => s.trim())\n .filter(Boolean)\n return samples.length > 0 ? samples : undefined\n}\n\n// `s322+` \u2014 the L-line's segment id with its orientation appended, mirroring\n// the GFA record it came from.\nfunction parseEndpoint(field: string) {\n return { id: field.slice(0, -1), strand: field.slice(-1) }\n}\n\nexport function parseLinkLine(line: string): RgfaLink {\n const cols = line.split('\\t')\n const source = parseEndpoint(cols[3]!)\n const target = parseEndpoint(cols[4]!)\n return {\n source: source.id,\n sourceStrand: source.strand,\n target: target.id,\n targetStrand: target.strand,\n sourceSegment: {\n id: source.id,\n refName: cols[5]!,\n start: +cols[6]!,\n end: +cols[7]!,\n rank: +cols[8]!,\n tags: cols[13] ?? '',\n },\n targetSegment: {\n id: target.id,\n refName: cols[9]!,\n start: +cols[10]!,\n end: +cols[11]!,\n rank: +cols[12]!,\n tags: cols[14] ?? '',\n },\n }\n}\n\nexport function linkKey(link: RgfaLink) {\n return `${link.source}${link.sourceStrand}${link.target}${link.targetStrand}`\n}\n\n// Both endpoints of a link are written into every row, so the same link is\n// indexed under each endpoint's stable sequence and arrives twice for a region\n// covering both. Callers dedupe on linkKey.\n\n// Segments carry no sequence here \u2014 the BED records only their span \u2014 so every\n// S-line is written with `*` and an LN tag, which is what the GFA spec asks for\n// and what packages/graph-core's parser reads back as the node length.\n// `NM:i:0`, `SM:Z:HG002.1,HG002.2` \u2014 the GFA tag grammar, checked rather than\n// trusted. Files built before the tag column existed put a bare comma-separated\n// sample list here, and passing that through would put a field that is not a\n// tag on an S-line, which is a malformed GFA rather than a missing annotation.\n// Dropping it degrades to the pre-tag behaviour instead.\nconst GFA_TAG = /^[A-Za-z][A-Za-z0-9]:[AifZJHB]:/\n\nfunction formatSegment(segment: RgfaSegment) {\n const { id, refName, start, end, rank, tags } = segment\n const valid = tags.split(' ').filter(t => GFA_TAG.test(t))\n const extra = valid.length === 0 ? '' : `\\t${valid.join('\\t')}`\n return `S\\t${id}\\t*\\tLN:i:${end - start}\\tSN:Z:${refName}\\tSO:i:${start}\\tSR:i:${rank}${extra}`\n}\n\nfunction formatLink(link: RgfaLink) {\n const { source, sourceStrand, target, targetStrand } = link\n return `L\\t${source}\\t${sourceStrand}\\t${target}\\t${targetStrand}\\t0M`\n}\n\n// Codepoint order, not localeCompare: the byte-identical-output guarantee below\n// has to hold across locales.\nfunction compare(a: string, b: string) {\n return a < b ? -1 : a > b ? 1 : 0\n}\n\n// Deterministic ordering: the same region always produces byte-identical GFA,\n// so a layout computed from it is reproducible.\nexport function formatSubgraph(\n segments: Map<string, RgfaSegment>,\n links: Map<string, RgfaLink>,\n) {\n const sortedSegments = [...segments.values()].sort(\n (a, b) =>\n compare(a.refName, b.refName) || a.start - b.start || compare(a.id, b.id),\n )\n const sortedLinks = [...links.keys()].sort((a, b) => compare(a, b))\n return [\n 'H\\tVN:Z:1.0',\n ...sortedSegments.map(s => formatSegment(s)),\n ...sortedLinks.map(k => formatLink(links.get(k)!)),\n ].join('\\n')\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["import_BaseAdapter", "import_util", "import_rxjs", "parseSegmentLine", "line", "cols", "segmentSamples", "segment", "tag", "t", "samples", "s", "parseEndpoint", "field", "parseLinkLine", "source", "target", "linkKey", "link", "GFA_TAG", "formatSegment", "id", "refName", "start", "end", "rank", "tags", "valid", "extra", "formatLink", "sourceStrand", "targetStrand", "compare", "a", "b", "formatSubgraph", "segments", "links", "sortedSegments", "sortedLinks", "k", "offReference", "segments", "segment", "RgfaTabixAdapter", "config", "getSubAdapter", "pluginManager", "under", "openTabixSlot", "PanSNRefNames", "tier", "opts", "query", "signal", "statusCallback", "observer", "tabixRefName", "line", "parseSegmentLine", "samples", "segmentSamples", "region", "hops", "index", "links", "addLinksOver", "refName", "start", "end", "reached", "link", "parseLinkLine", "linkKey", "frontier", "hop", "formatSubgraph"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{G as c,O as m,R as u,U as g,Z as M}from"./chunk-UTWFU4X6.js";import{a as d,b as N,c as I,d as G}from"./chunk-XEJ47DLD.js";import{a as T,b as l}from"./chunk-FY3BTKY4.js";var b=T((D,y)=>{y.exports=JBrowseExports["@mui/material/Button"]});var C=l(G(),1),a=l(I(),1),f=l(b(),1),h=l(N(),1),k=l(M(),1),e=l(d(),1),B=(0,k.makeStyles)()({section:{marginBottom:24},formControl:{minWidth:200}}),R=["Lowest","Low","Medium","High","Highest"],v=(0,h.observer)(function({model:s}){return s.hasGraph&&!s.usesLayoutEngine?(0,e.jsx)(a.Typography,{variant:"caption",color:"warning.main",children:"No effect on this layout: only the force-directed layout is drawn by the engine that reads this."}):null}),x=(0,h.observer)(function(s){let{model:o,open:S,onClose:p,children:L}=s,{classes:n}=B();return(0,e.jsxs)(C.Dialog,{open:S,onClose:p,title:"Graph settings",children:[(0,e.jsxs)(a.DialogContent,{children:[(0,e.jsx)("div",{className:n.section,children:(0,e.jsxs)(a.FormControl,{fullWidth:!0,children:[(0,e.jsx)(a.FormLabel,{component:"legend",children:"Layout quality"}),(0,e.jsx)(a.RadioGroup,{value:o.layoutQuality,onChange:t=>{let r=parseInt(t.target.value);o.setLayoutQuality(r),o.recomputeLayout()},children:R.map((t,r)=>(0,e.jsx)(a.FormControlLabel,{value:r,control:(0,e.jsx)(a.Radio,{}),label:t},t))}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"FMMM's iteration budget, the same scale Bandage exposes. Higher is slower: on a thousand-node cut the top setting is seconds rather than tenths."}),(0,e.jsx)(v,{model:o})]})}),(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsx)(a.FormControlLabel,{control:(0,e.jsx)(a.Switch,{checked:o.drawPaths,onChange:t=>{o.setDrawPaths(t.target.checked)}}),label:"Draw paths"}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"Color each node and connector by the paths through it, one lane per path in legend order, so a path that skips a node leaves its lane empty"}),o.drawPaths&&!o.effectiveDrawPaths?(0,e.jsx)(a.Typography,{variant:"caption",color:"warning.main",children:o.pathCount>c?`Off: ${o.pathCount.toLocaleString()} paths is past the ${c} this can tell apart`:"Off: this graph states no paths"}):null]}),(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsx)(a.FormControlLabel,{control:(0,e.jsx)(a.Switch,{checked:o.showBubbles,onChange:t=>{o.setShowBubbles(t.target.checked)}}),label:"Mark bubbles"}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"A halo along the nodes of each bubble, labelled by what it is, with the label opening the bubble on its own"})]}),(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsx)(a.FormControlLabel,{control:(0,e.jsx)(a.Switch,{checked:o.showGenes,onChange:t=>{o.setShowGenes(t.target.checked)}}),label:"Genes on the backbone"}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"Exons along the reference nodes that carry them and each gene's name at its midpoint, from the assembly's annotation track"}),o.geneTrackChoices.length>1?(0,e.jsxs)(a.FormControl,{className:n.formControl,sx:{mt:1},children:[(0,e.jsx)(a.InputLabel,{children:"Gene track"}),(0,e.jsx)(a.Select,{value:o.geneTrack?.trackId??"",label:"Gene track","data-testid":"graph-gene-track-select",onChange:t=>{o.setGeneTrackId(t.target.value),o.reloadGenes()},children:o.geneTrackChoices.map(({trackId:t,name:r})=>(0,e.jsx)(a.MenuItem,{value:t,children:r},t))})]}):null,o.repeatTrackChoices.length>1?(0,e.jsxs)(a.FormControl,{className:n.formControl,sx:{mt:1},children:[(0,e.jsx)(a.InputLabel,{children:"Repeat track"}),(0,e.jsx)(a.Select,{value:o.repeatTrack?.trackId??"",label:"Repeat track","data-testid":"graph-repeat-track-select",onChange:t=>{o.setRepeatTrackId(t.target.value),o.reloadRepeats()},children:o.repeatTrackChoices.map(({trackId:t,name:r})=>(0,e.jsx)(a.MenuItem,{value:t,children:r},t))})]}):null]}),o.anchorPaths.length>1?(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsxs)(a.FormControl,{className:n.formControl,children:[(0,e.jsx)(a.InputLabel,{children:"Reference path"}),(0,e.jsx)(a.Select,{value:o.activeReferencePath??"",label:"Reference path","data-testid":"graph-reference-path-select",onChange:t=>{o.setReferencePath(t.target.value),o.recomputeLayout()},children:o.anchorPaths.map(({name:t})=>(0,e.jsx)(a.MenuItem,{value:t,children:t},t))})]}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"Which path the anchored layouts draw x against. A GFA with no rGFA tags states its coordinates only in its paths, and marks none of them as the reference."})]}):null,(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsxs)(a.FormControl,{className:n.formControl,children:[(0,e.jsx)(a.InputLabel,{children:"Bubble spread"}),(0,e.jsx)(a.Select,{value:o.bubbleSpread,label:"Bubble spread","data-testid":"graph-bubble-spread-select",onChange:t=>{o.setBubbleSpread(t.target.value),o.recomputeLayout()},children:m.map(({value:t,label:r,description:i})=>(0,e.jsx)(a.MenuItem,{value:t,children:(0,e.jsx)(a.Tooltip,{title:i,placement:"right",children:(0,e.jsx)("span",{children:r})})},t))})]}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"How far the force layout opens a bubble. A pangenome allele is a few bp, so at Bandage's own scale both arms land inside one node thickness and the graph draws as a rope."}),(0,e.jsx)(v,{model:o})]}),(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsxs)(a.FormControl,{className:n.formControl,children:[(0,e.jsx)(a.InputLabel,{children:"Node width"}),(0,e.jsx)(a.Select,{value:o.nodeWidth,label:"Node width","data-testid":"graph-node-width-select",onChange:t=>{o.setNodeWidth(t.target.value)},children:g.map(({value:t,label:r,description:i})=>(0,e.jsx)(a.MenuItem,{value:t,children:(0,e.jsx)(a.Tooltip,{title:i,placement:"right",children:(0,e.jsx)("span",{children:r})})},t))})]}),(0,e.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"Bandage's depth as width. In a cut with walks, depth is how many haplotypes carry the node."})]}),L,(0,e.jsxs)("div",{className:n.section,children:[(0,e.jsxs)(a.FormControl,{className:n.formControl,children:[(0,e.jsx)(a.InputLabel,{children:"Color scheme"}),(0,e.jsx)(a.Select,{value:o.chosenColorScheme,label:"Color scheme",onChange:t=>{o.setColorScheme(t.target.value)},children:u.map(({value:t,label:r})=>(0,e.jsx)(a.MenuItem,{value:t,children:r},t))})]}),o.colorSchemeLock?(0,e.jsxs)(a.Typography,{variant:"caption",color:"warning.main",children:["No effect now. ",o.colorSchemeLock.why]}):null]})]}),(0,e.jsx)(a.DialogActions,{children:(0,e.jsx)(f.default,{variant:"contained",color:"primary",onClick:p,children:"Close"})})]})}),O=x;export{O as a};
|
|
2
|
+
//# sourceMappingURL=chunk-CNFN6EVE.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as Bn}from"./chunk-UQEPPJEO.js";import{c as wn}from"./chunk-SCMIJAAX.js";import{A as In,B as vt,C as vn,D as Pn,E as Pt,F as Ot,I as On,J as kn,W as $n,X as pt,a as le,i as Mn,j as It,k as Rn,l as En,m as Sn,n as Nn,o as Ln,p as Tn,u as Cn,v as ft,w as An,x as Ue,y as xe,z as _n}from"./chunk-UTWFU4X6.js";import{a as je,b as O,c as ut,d as ve,e as yn,f as Pe,i as dt}from"./chunk-7BKUWQE5.js";import{a as lt,c as xn,d as ct}from"./chunk-KULNKXPT.js";import{a as it}from"./chunk-XEJ47DLD.js";import{a as Ke,b as Y}from"./chunk-FY3BTKY4.js";var Fn=Ke((Sl,Gn)=>{Gn.exports=JBrowseExports["@mui/material/SvgIcon"]});var Oe=Ke((_l,qn)=>{qn.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var qs=Ke((mc,co)=>{co.exports=JBrowseExports.mobx});var cr=Ke((Ou,lr)=>{lr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var dr=Ke((ku,ur)=>{ur.exports=JBrowseExports["@jbrowse/render-core/renderingBackendBase"]});var ne=Y(Fn(),1);var Zr=3.4,Wn=6,Jr=8,es=18,ts=2,ns=15;function os(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,r]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],o=s=>+(s/n).toFixed(n===1?0:1);return`${o(e.covered*t)} of ${o(t)} ${r}`}function rs(e,t,n){return Dn(e,r=>r.gene.end-r.gene.start).map(r=>{let{x:o,y:s}=t(r.at),a=os(r);return{item:r,x:o,y:s+n+es,text:a?`${r.gene.name} \xB7 ${a}`:r.gene.name,fallback:a?`${r.gene.name} \u2026`:void 0,stack:ts}})}function Dn(e,t){return[...e].sort((n,r)=>t(r)-t(n))}function Cl(e){let{paneWidth:t,canvasHeight:n,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:t,height:n},i=R=>({x:R.x*s+r,y:R.y*a+o}),c=e.drawnRowLabels.map(({label:R,y:N})=>An(R,N*a+o)),d=e.referenceStripZonePx??0;d>0&&c.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&c.push({x0:t-Wn-e.legendSize.width,x1:t,y0:0,y1:d+Wn+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let u=Cn(l,c),f=e.drawnRowLabels.length>0,h=f?Math.min(...e.drawnRowLabels.map(R=>R.y)):1/0,p=e.contigThickness*Zr,m=Dn(e.bubbleHalos,R=>R.members),g=ft(m.map(R=>{let{x:N,y:I}=i({x:R.labelAt.x,y:Math.min(R.labelAt.y,h)}),H=I-p/2-6;return{item:R,x:N,y:f?Math.max(H,ns):H,text:R.label}}),l,u),b=ft(rs(e.genePins,i,e.contigThickness),l,u),w=e.nodePositions&&e.labelsNodeSizes?_n({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],deletionRoutes:e.deletionRoutes,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},S=vt(w.deletions,u),E=ft(m.flatMap(R=>R.routes.map(N=>{let{x:I,y:H}=i(N.at);return{item:{halo:R,route:N},x:I,y:H+4,text:N.text,stack:Jr}})),l,u),T=vt(w.nodes,u,In(t,n));return{bubbles:g,genes:b,routes:E,sizes:[...S,...T]}}var G=Y(Oe(),1);var $=Y(Oe(),1);function ke(e,t){return(0,$.packAbgr)((0,$.abgrRed)(e),(0,$.abgrGreen)(e),(0,$.abgrBlue)(e),Math.round((0,$.abgrAlpha)(e)*t))}function mt(e,t){return(0,$.packAbgr)(Math.min(255,Math.round((0,$.abgrRed)(e)*t)),Math.min(255,Math.round((0,$.abgrGreen)(e)*t)),Math.min(255,Math.round((0,$.abgrBlue)(e)*t)),(0,$.abgrAlpha)(e))}var ss=4;function Ve(e){let t=new Map;function n(r,o){let s=t.get(r);s?s.push(o):t.set(r,[o])}for(let r of e.edges)n(r.from,r.to),n(r.to,r.from);return t}function as({nodeId:e,nodeById:t,neighbors:n}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<ss&&o.length>0;l++){let i=[];for(let c of o){let d=n.get(c);if(d){for(let u of d)if(!r.has(u)){r.add(u);let f=t.get(u);f&&O(f)?(s=Math.min(s,f.stable.start+f.length),a=Math.max(a,f.stable.start)):i.push(u)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function is({nodeId:e,nodeById:t,neighbors:n}){let r=t.get(e);return r===void 0?void 0:O(r)?{start:r.stable.start,end:r.stable.start+r.length}:as({nodeId:e,nodeById:t,neighbors:n})}function Hn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=Ve(e),r=new Map;for(let o of e.nodes){let s=is({nodeId:o.id,nodeById:t,neighbors:n});s&&r.set(o.id,(s.start+s.end)/2)}return r}var Xn=new WeakMap;function Yn(e,t,n,r,o,s){let{scaleX:a,scaleY:l}=n,i=Xn.get(e);if(i?.graph===t&&i.scaleX===a&&i.scaleY===l&&i.deletions===r&&i.routes===s&&i.version===o)return i.curves;let c=new Map;for(let d=0;d<t.edges.length;d++){let u=t.edges[d],f=e[u.from],h=e[u.to];if(f?.length&&h?.length){let p=r?.get(d),m=p&&s?.[d];c.set(d,m?Ln(f,h,m):Nn(f,h,Sn(u),0,0,n,p?Tn(e,p):[]))}}return Xn.set(e,{graph:t,scaleX:a,scaleY:l,deletions:r,routes:s,version:o,curves:c}),c}var ls=(0,G.packAbgr)(119,119,119,217),zn=(0,G.packAbgr)(136,136,136,217),cs=(0,G.packAbgr)(24,24,28,240),us=2.2,Jn=(0,G.packAbgr)(160,160,160,255),Qe=.18,Ft=(0,G.abgrToCssRgba)(ke(Jn,Qe)),ds=11,fs=1.2,Kn=4,kt=1e-6,ps=7,hs=3,ms=3,gs=1.5,bs=.5,xs=.45,Bt=12,ys=1e-6,ce=new Float64Array(64),ye=new Float64Array(64),we=new Float64Array(64);function ws(e,t,n,r){let o=e.length*Bt+1;ce.length<o&&(ce=new Float64Array(o),ye=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];ce[0]=s.x1,ye[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let c=e[i];for(let d=1;d<=Bt&&l<r;d++){let u=1-(d/Bt)**2,f=1-u,h=f*f*f,p=3*f*f*u,m=3*f*u*u,g=u*u*u,b=h*c.x0+p*c.cx0+m*c.cx1+g*c.x1,w=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(b-ce[a-1],(w-ye[a-1])*n)*t,ce[a]=b,ye[a]=w,we[a]=l,a++}}return a}function jn(e,t){let n=1;for(;n<e-1&&we[n]<t;)n++;let r=we[n-1],o=we[n],s=o>r?Math.min(1,Math.max(0,(t-r)/(o-r))):0;return{x:ce[n-1]+(ce[n]-ce[n-1])*s,y:ye[n-1]+(ye[n]-ye[n-1])*s}}function Ms({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=ps+hs*t,c=ws(e,r,o,n+i),d=we[c-1],u=Math.min(n,d),f=d<ys?Rs(a,r,o):d-u,h=Math.min(1,f/i);if(h<bs)return;let p=jn(c,u),m=jn(c,u+i*h),g=p.x-m.x,b=(p.y-m.y)*o,w=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,b)>0?Math.atan2(b,g):_s(w,o,Es(w,l)),length:i*h,halfWidth:(ms+gs*t)*h,color:s}}function Rs(e,t,n){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*n);return r*t}function Es(e,t){if(t.length<2)return;let n=t[0],r=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:n,to:t[1]}:{from:r,to:t[t.length-2]}}function $t(e,t=1){let n=t===1?e:e.map(o=>({x:o.x,y:o.y*t})),r=[];for(let o=0;o<n.length;o++){let s=0,a=0;if(o===0){let l=n[1].x-n[0].x,i=n[1].y-n[0].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===n.length-1){let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i),d=n[o+1].x-n[o].x,u=n[o+1].y-n[o].y,f=Math.hypot(d,u);if(c>0&&f>0){let h=-i/c,p=l/c,m=-u/f,g=d/f;s=(h+m)/2,a=(p+g)/2;let b=h*s+p*a;b>.1&&(s/=b,a/=b)}else c>0?(s=-i/c,a=l/c):f>0&&(s=-u/f,a=d/f)}r.push({nx:s,ny:a})}return r}function Un(e,t,n,r=1){return e.map((o,s)=>({x:o.x+t[s].nx*n,y:o.y+t[s].ny*n/r}))}function gt(e,t,n,r){return(0,G.packAbgr)(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(r*255))}function Be(e,t,n){let r=(1-Math.abs(2*n-1))*t,o=r*(1-Math.abs(e/60%2-1)),s=n-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var Ss=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],Ns=[[237,137,44],[158,42,122]],Ls=[[220,50,50],[50,120,220]];function Gt(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),o=n-r,s=e[r],a=e[r+1];return(0,G.packAbgr)(Math.round(s[0]+(a[0]-s[0])*o),Math.round(s[1]+(a[1]-s[1])*o),Math.round(s[2]+(a[2]-s[2])*o),255)}function Ts(e,t){let[n,r,o]=Be(vn(e),Pt,Ot);return gt(n,r,o,t)}var $e=300,Cs=.7,As=.5,eo=[60,65,72],Wt=(0,G.packAbgr)(...eo,255),Dt=`rgb(${eo.join(", ")})`;function Hl(e,t){let n=Hn(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let r=1/0,o=-1/0;for(let s of n.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:n}}function qt(e){let t=1/0,n=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<t&&(t=a.depth),a.depth>n&&(n=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:t,maxDepth:n,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Ht(e,t,n,r){switch(n){case"random":return Ts(e.id,1);case"depth":return Gt(Ss,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Gt(Ls,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,G.packAbgr)(160,160,160,255):e.stable.rank===0?(0,G.packAbgr)(52,152,219,255):Gt(Ns,r.maxRank>1?(e.stable.rank-1)/(r.maxRank-1):0);case"reference-position":{let o=r.referenceRamp,s=o?.midpoints.get(e.id);if(o===void 0||s===void 0)return(0,G.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Wt;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=Be(a*$e,Cs,As);return gt(l,i,c,1)}case"grey":return(0,G.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?t/r.nodeCount*360:0,[s,a,l]=Be(o,.75,.5);return gt(s,a,l,1)}default:return(0,G.packAbgr)(52,152,219,255)}}function _s(e,t=1,n){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*t;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return n?Math.atan2((n.to.y-n.from.y)*t,n.to.x-n.from.x):0}function Is(e,t){let n=!1;for(let r=0;r<e.length-1&&!n;r++){let o=e[r],s=e[r+1];n=Math.max(o.x,s.x)>=t.minX&&Math.min(o.x,s.x)<=t.maxX&&Math.max(o.y,s.y)>=t.minY&&Math.min(o.y,s.y)<=t.maxY}return n}function Vn(e,t){for(let n of e){let r=Math.min(n.x0,n.cx0,n.cx1,n.x1),o=Math.max(n.x0,n.cx0,n.cx1,n.x1),s=Math.min(n.y0,n.cy0,n.cy1,n.y1),a=Math.max(n.y0,n.cy0,n.cy1,n.y1);if(o>=t.minX&&r<=t.maxX&&a>=t.minY&&s<=t.maxY)return!0}return!1}var Qn=new WeakMap;function vs(e){let t=Qn.get(e);if(!t){let n=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=Be(Pn(s,o.length),Pt,Ot);n.push(gt(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}t={pathColorByIndex:n,pathIndexByName:r},Qn.set(e,t)}return t}var Zn=new WeakMap,Ps=new Map;function Os(e){let t=Zn.get(e);if(!t){t=new Map;for(let[n,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=t.get(o);s?s.push(n):t.set(o,[n])}Zn.set(e,t)}return t}function Xl(e){let{nodePositions:t,graph:n,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:d,linearLayout:u,viewportBounds:f,referenceRamp:h,deletions:p,deletionRoutes:m,hiddenEdges:g,version:b=0}=e,w=i==="depth"?$n(n):0,S=d.scaleX,E=Rn(d),T=Yn(t,n,d,p,b,m),R=[],N=new Map,I=[],H=new Map,F=[],z=new Map,Se={...qt(n),referenceRamp:h},pe=new Map;if(o==="rainbow")for(let A=0;A<n.nodes.length;A++)pe.set(n.nodes[A].id,A);let Q=n.paths?.length??0,{pathColorByIndex:K,pathIndexByName:Z}=vs(n),j=A=>K[Z.get(A)??-1]??zn,U=l&&Q>1?Os(n):Ps,Ne=S>(u?1:xs);for(let A=0;A<n.edges.length;A++){let P=n.edges[A],re=t[P.from],se=t[P.to],ae=T.get(A);if(!re?.length||!se?.length||!ae||g?.has(A))continue;let Le=P.pathIds?.length??0,He=p?.get(A)!==void 0,Xe=c?.edgeIndexes.has(A)??!1,he=a/2*(He?us:1),Te=l&&Le>0,me=He?cs:ls,J=!c||Xe?me:ke(me,Qe),Ye=r.get(P.to),Ce=(Ye?pt(Ye,s,i,w):s)/2,Ae=(be,Ie,X,ie)=>{let te=be===0&&Ie===0?ae:It(ae,be,Ie);if(f&&!Vn(te,f))return;if(He)for(let Ct of Mn(te,ds/S))F.push({curves:Ct,thickness:he,color:X});else F.push({curves:te,thickness:he,color:X});let at=Ne&&ie!==void 0?Ms({curves:te,edgeHalfWidth:he,nodeHalfWidth:Ce,scale:S,yToX:E,color:ie,fromSegments:re,toSegments:se}):void 0;at&&I.push(at)},ge=F.length,_e=I.length,ee=c&&Xe&&!Te?c.walks:void 0;if(ee){let be=r.get(P.from),Ie=be?pt(be,s,i,w):s,X=Math.max(Ie/ee.length,Kn),ie=$t(re,E),{nx:te,ny:at}=(P.fromStrand==="-"?ie[0]:ie.at(-1))??{nx:0,ny:0},Ct=1/Math.max(S,kt);ee.forEach((At,Ur)=>{if(!At.edgeIndexes.has(A))return;let _t=(Ur-(ee.length-1)/2)*X*Ct,bn=_t===0?ae:It(ae,te*_t,at*_t/E);f&&!Vn(bn,f)||F.push({curves:bn,thickness:X/2,color:At.colors.get(P.from)??At.colors.get(P.to)??me})})}else if(!Te)Ae(0,0,J,J);else{let be=En(re,se,Le,d),Ie=Math.floor((Le-1)/2);for(let X=0;X<Le;X++){let ie=be[X],te=j(P.pathIds[X]);Ae(ie.x,ie.y,c&&!c.names.has(P.pathIds[X])?ke(te,Qe):te,X===Ie?J:void 0)}}let ze=F.length-ge;ze>0&&z.set(A,{start:ge,count:ze});let st=I.length-_e;st>0&&H.set(A,{start:_e,count:st})}for(let[A,P]of Object.entries(t)){let re=r.get(A);if(!re||f&&!Is(P,f))continue;let se=c!==void 0&&!c.nodeIds.has(A),ae=se?Jn:Ht(re,pe.get(A)??0,o,Se),Le=se?ke(ae,Qe):ae,rt=pt(re,s,i,w),He=rt/2,Xe=R.length,he=U.get(A),Te=rt/Q,me=P.length>=2,J=c&&!se&&!he?.length?c.walks:void 0;if(me&&J){let Ce=Math.max(rt/J.length,Kn),Ae=$t(P,E),ge=1/Math.max(S,kt);J.forEach((_e,ee)=>{let ze=_e.colors.get(A);if(ze===void 0)return;let st=(ee-(J.length-1)/2)*Ce*ge;R.push({points:J.length===1?P:Un(P,Ae,st,E),thickness:Ce/2,color:ze})})}else if(me&&he?.length&&Te>=fs){let Ce=$t(P,E),Ae=1/Math.max(S,kt);for(let ge of he){let _e=(ge-(Q-1)/2)*Te*Ae,ee=K[ge]??zn;R.push({points:Un(P,Ce,_e,E),thickness:Te/2,color:se?ke(ee,Qe):ee})}}else me&&R.push({points:P,thickness:He,color:Le});let Ye=R.length-Xe;Ye>0&&N.set(A,{start:Xe,count:Ye})}return{nodeStrokes:R,nodeStrokeRuns:N,arrows:I,arrowRuns:H,edgeCurves:F,edgeCurveRuns:z}}function bt(e){return`hsl(${e}, 70%, 50%)`}function Xt(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*$e}var ks=30;function to({start:e,bp:t,reversed:n},r){let o=Xt(e,r),s=Xt(e+t,r);if(s-o<1)return[(o+s)/2];let a=Math.ceil((s-o)/ks);return Array.from({length:a+1},(l,i)=>Xt(e+t*(n?a-i:i)/a,r))}var Kl=`linear-gradient(to right, ${Array.from({length:7},(e,t)=>`${bt(t/6*$e)} ${t/6*100}%`).join(", ")})`;function Ql(e){return je(e)?no(e):void 0}function no(e){return{sample:lt(e.stable.refName),haplotype:xn(e.stable.refName),refName:ct(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Bs(e,t){let n=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of n)o=o&&s.start-o.end<=t?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function $s(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Zl(e,{maxGap:t=1/0}={}){let n=new Map;for(let o of e.nodes)if(je(o)){let s=no(o),a=$s(s),l=n.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):n.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of n.values()){let s=Bs(o.spans,t);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function Gs(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function Jl(e,t){return e.flatMap(n=>{let r=Gs(t,n);return r===void 0?[]:[{...n,sample:r}]})}function ec(e){return`${e.refName}:${e.start+1}-${e.end}`}function Yt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var oo=Y(it(),1),ro=(0,ne.createSvgIcon)((0,oo.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var so=Y(it(),1),ao=(0,ne.createSvgIcon)((0,so.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 io=Y(it(),1),zt=(0,ne.createSvgIcon)((0,io.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 Fs="Linear genome view",Ws="Linear synteny view",Ds="No synteny track in this session aligns these assemblies";function lo({label:e,icon:t,entries:n,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=n,i=s?[{label:e,icon:t,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return n.length===0?i:n.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:t,onClick:o(l)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(c=>({label:r(c),onClick:o(c)}))}]}function fc({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:r}){let o=t[0]?.coverage??e.length;return[...lo({label:Fs,icon:zt,entries:e,entryLabel:s=>`${s.sample} ${Yt(s)}`,onSelect:s=>()=>{n({location:s,assembly:s.sample})}}),...e.length>=2?lo({label:`${Ws} (${o} assemblies)`,icon:ro,entries:t,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Ds,onSelect:s=>()=>{r(s.trackId)}}):[]]}function pc({own:e,reference:t,highlight:n,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Yt(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...o&&n?[{label:`Highlight in ${n.assembly}`,icon:ao,onClick:()=>{o(n)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:zt,onClick:()=>{r(l)}}))]}function Kt(e){return e.id.endsWith("-")?"-":"+"}function jt(e,t){return t===Kt(e)?e.id:`-${e.id}`}function Hs(e,t){let n=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=r,r+=e[o];let s=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Xs(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let r=Hs(t,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let d=r[c],u=t[c];if(d!==void 0&&u!==void 0&&d<=l&&(l<d+u||i&&l===d+u))return{s:c,local:l-d,room:d+u-l}}},s=(l,i)=>{let c=n[l],d=c.at(-1);i.type==="substitution"&&d?.type==="substitution"&&d.pos+d.seq.length===i.pos?d.seq+=i.seq:c.push(i)},a=e.pathStart;for(let l of wn(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let c=o(a),d=c?Math.min(i,c.room):i;c&&s(c.s,{type:"deletion",pos:c.local,length:d}),a+=d,i-=d}}return n}function uo(e,t,n){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of t){let a=s.path.map(d=>r.get(d.name)),l=a.flatMap((d,u)=>d?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let d=Xs(s,a.map(h=>h?.length)),u=l.map(h=>jt(a[h],s.path[h].strand)),f=a[c].length;o.push({id:n+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:l.map((h,p)=>({nodeName:u[p],mismatches:d[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ys=["#6baed6","#4292c6","#2171b5","#08519c"],zs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function fo(e){let t=e.is_reverse?zs:Ys;return t[e.id%t.length]}function xt(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,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=t.get(l);if(i){o.push(i);for(let c of n.get(l)??[]){let d=t.get(c);d&&(d.stable.rank===0?s.push(d):r.has(c)||(r.add(c),a.push(c)))}}}return{members:o,anchors:s}}function js(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=n[0],o=n.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Us(e,t,n){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of n.get(t.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of n.get(a)??[])if(r.has(i)){let c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function Vs(e,t,n){let r=Us(e,t,n),o=[...e].sort((i,c)=>r.get(i.id)-r.get(c.id)),s=new Map(o.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of o.entries()){let d=0;for(let u of n.get(c.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,l.get(u)+f.length))}l.set(c.id,d)}return{offsets:l,ordered:o}}function ho(e){let t=new Map(e.nodes.filter(je).map(s=>[s.id,s])),n=Ve(e),r=new Set,o=[];for(let s of t.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Ks(s.id,t,n,r),i=js(l);if(i){let{offsets:c,ordered:d}=Vs(a,i.entry,n);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>c.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,c.get(f.id)+f.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Qs=1,Zs=.015;function yt({graph:e,span:t,rowY:n,positions:r}){let o=t*Zs,s=ho(e),a=new Map(e.nodes.map(d=>[d.id,d])),l=[];for(let d of s){let u=d.refSpan-d.pathLength;u>=Qs&&l.push({nodeIds:d.nodeIds,bp:u});let f=Math.max(d.refSpan,o),h=d.pathLength>0?f/d.pathLength:0;d.nodeIds.forEach((p,m)=>{let g=a.get(p);if(g){let b=d.nodeOffsets[m],w=f/d.nodeIds.length,S=T=>d.start+T*h,E=n(g);r[p]=h?[{x:S(b),y:E},{x:S(b+g.length),y:E}]:[{x:d.start+m*w,y:E},{x:d.start+(m+1)*w,y:E}]}})}let i=Ve(e),c=Object.keys(r);for(let d of c){let u=r[d].at(-1).x;for(let f of i.get(d)??[]){let h=a.get(f);if(h&&!(f in r)){let p=n(h);r[f]=[{x:u,y:p},{x:u+o,y:p}],c.push(f)}}}return l}function Js(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,r)=>n-r).map((n,r)=>[n,r]))}function mo(e,t){let n=ve(e);if(n.length===0)return;let r=dt(n,t),o=Js(e),s=Pe(n),a=yt({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,c])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:c*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var ea=12,Ut=20;function go(e){return 10+8*Math.log2(1+e.length)}function ue(e,t){return e<t?-1:e>t?1:0}function xo(e,t){return ue(e.at,t.at)||ue(e.side,t.side)||ue(e.hops,t.hops)}var bo={at:1/0,side:0,hops:0};function ta(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=ra(e);return e.nodes.map(r=>r.id).sort((r,o)=>xo(n.get(r)??bo,n.get(o)??bo)||ue(t.get(r).name,t.get(o).name)||ue(r,o))}function na(e,t){let n=new Set(e.nodes.map(d=>d.id)),r=new Map(t.map(d=>[d.id,d.stable.start])),o=new Map,s=new Map;t.forEach((d,u)=>{s.set(d.id,t[u-1]?.id),o.set(d.id,t[u+1]?.id)});let a=t[0]?.id,l=(d,u)=>{let f=o.get(d);o.set(d,u),s.set(u,d),o.set(u,f),f!==void 0&&s.set(f,u)},i=(d,u)=>{let f=s.get(d);f===void 0?(a=u,s.set(u,void 0),o.set(u,d),s.set(d,u)):l(f,u)};for(let d of e.paths??[]){let u=0,f=0,h;for(let b of d.nodeIds){let w=r.get(b);w!==void 0&&(h!==void 0&&w!==h&&(w>h?u++:f++),h=w)}let p=f>u?[...d.nodeIds].reverse():d.nodeIds,m,g=new Set;for(let b of p)if(o.has(b)){if(m===void 0)for(let w of g)i(b,w);m=b}else n.has(b)&&(m===void 0?g.add(b):(l(m,b),m=b))}let c=[];for(let d=a;d!==void 0;d=o.get(d))c.push(d);return c}function oa(e,t){let n=[...t.entries()].sort(([a,l],[i,c])=>xo(l,c)||ue(a,i)).map(([a])=>a),r=n.length;for(let a of n){let l=t.get(a);for(let i of e.get(a)??[])t.has(i)||(t.set(i,{at:l.at,side:1,hops:l.hops+1}),n.push(i))}let o=new Set(n.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=t.get(a),i=[a];s.add(a);let c=!0;for(let d of i){let{hops:u}=t.get(d),f=!0,h=!1;for(let p of e.get(d)??[]){let m=t.get(p);m.at===l&&o.has(p)?(f&&=m.hops<=u,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!f||h}if(c)for(let d of i){let u=t.get(d);t.set(d,{...u,side:-1,hops:-u.hops})}}}function ra(e){let t=new Set(e.nodes.map(s=>s.id)),n=new Map;for(let s of e.edges)!t.has(s.from)||!t.has(s.to)||((n.get(s.from)??n.set(s.from,[]).get(s.from)).push(s.to),(n.get(s.to)??n.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(O).sort((s,a)=>ue(s.stable.start,a.stable.start)||ue(s.name,a.name)),o=new Map;return na(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),oa(n,o),o}function sa(e){let t=new Map(e.nodes.map(u=>[u.id,u])),n=ta(e),r=new Map(n.map((u,f)=>[u,f])),o=u=>O(t.get(u)),s=new Map(n.map(u=>[u,[]])),a=new Map(n.map(u=>[u,[]])),l=(u,f)=>{s.get(f).push(u),a.get(u).push(f)};for(let u of e.edges)u.from===u.to||!r.has(u.from)||!r.has(u.to)||(r.get(u.from)<r.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=n.filter(o);for(let u=1;u<i.length;u++)l(i[u-1],i[u]);let c=new Map;for(let u of n){let f=0;for(let h of s.get(u))f=Math.max(f,c.get(h)+1);c.set(u,f)}for(let u=n.length-1;u>=0;u--){let f=n[u],h=a.get(f);if(o(f)||h.length===0)continue;let p=1/0;for(let b of h)p=Math.min(p,c.get(b));let m=c.get(f),g=Math.max(m,p-1);c.set(f,Math.floor((m+g)/2))}let d=[];for(let u of n)(d[c.get(u)]??=[]).push(u);return{layers:d,layerOf:c,preds:s}}function yo(e){if(!e.nodes.some(O))return;let t=new Map(e.nodes.map(u=>[u.id,u])),n=u=>O(t.get(u)),{layers:r,layerOf:o,preds:s}=sa(e),a=r.map(u=>{let f=0;for(let h of u)f=Math.max(f,go(t.get(h)));return f}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+ea;let c=new Map;for(let u of r){let f=[];for(let p of u){if(n(p)){c.set(p,0);continue}let m=s.get(p).filter(b=>c.has(b)),g=0;for(let b of m)g+=c.get(b)/m.length;f.push({id:p,ideal:g===0?Ut:g})}f.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of f){let g=Math.round(m/Ut);g===0&&(g=m>=0?1:-1);for(let b=1;h.has(g);b++)h.has(g+b)?h.has(g-b)||(g-=b):g+=b;h.add(g),c.set(p,g*Ut)}}let d={};for(let u of e.nodes){let f=o.get(u.id),h=go(u),p=l[f]+a[f]/2,m=c.get(u.id);d[u.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:d,referenceAxis:!1,pixelRows:!0}}function aa(e,t){let n=new Map;for(let o of e.nodes)if(ut(o)){let{sample:s}=xt(o.stable.refName);n.set(s,(n.get(s)??0)+o.length)}let r=new Map(t.map((o,s)=>[o,s]));return[...n.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||n.get(s)-n.get(o)||o.localeCompare(s))}function wo(e,t,n=[]){let r=ve(e),o=aa(e,n);if(r.length===0||o.length===0)return;let s=dt(r,t),a=new Map(o.map((f,h)=>[f,h+1])),l=Pe(r),i=o.length+1,c=yt({graph:e,span:s,rowY:f=>{let h=f.stable;return((h?a.get(xt(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:xt(r[0].stable.refName).sample,y:0},...o.map(f=>({label:f,y:a.get(f)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function Vt(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var et=!1,Mo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function $o(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(t=>Mo[t.id%Mo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var _=$o({}),tn=null,x=[],y=[],M=[],C=new Map,We=[],L=[],Me=[],on=[],rn=[],V=-1,B=Vt(),nn={minX:0,maxX:0,minY:0,maxY:0},Ze,wt=new Map;function Go(e,t,n=[],r={}){if(_=$o(r),tn=r.bed??null,B=Vt(),Me=[],on=[],rn=[],We=[],nn={minX:0,maxX:0,minY:0,maxY:0},Ze=void 0,wt=new Map,e.length===0||t.length===0)return;let o=Qt(e);x=[],o.forEach((i,c)=>{x[c+1]=i}),y=Qt(t);let s=n.length>0;M=Qt(Ka(n));for(let i=y.length-1;i>=0;i-=1){let c=y[i];if(c.type===void 0&&(c.type="haplotype"),c.hidden===!0){y.splice(i,1);continue}c.indexOfFirstBase!==void 0&&(Ze=c.name)}if(y.length===0)return;la(0),C=So(),Ge(y),_.showReads&&M.length>0&&Ge(M),Bo(),_.mergeNodesFlag&&(No(),Jt(),_.showReads&&M.length>0&&Zt(),za(),C=So(),Bo(),Ge(y),_.showReads&&M.length>0&&Ge(M)),No(),Aa(),et&&console.log(`${x.length} nodes.`),Jt(),V=To(),_a(),Jt(),V=To();let a=_.showReads&&_.coarsenedReadView&&!s;if(a){let i=Ze===void 0?-1:y.findIndex(u=>u.name===Ze),c=i===-1?0:i,d=y.filter((u,f)=>f!==c);if(d.length>0){let u=vo(d,"haplotype");u.length>0&&(y=[y[c]],M=u)}}Wa(),Oa(),_.showExonsFlag&&tn!==null&&Fa();let l=_.showReads&&_.coarsenedReadView&&M.length>0&&!a;return _.showReads&&M.length>0?(ca(),Zt(),Ge(M),l&&(M=vo(M,"read"),Zt(),Ge(M)),da(),y=y.concat(M)):x.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),va(),Ha(),et&&(console.log("Tracks:"),console.log(y),console.log("Nodes:"),console.log(x),console.log("Lane assignment:"),console.log(Me)),Ea(),{nodes:x,tracks:y,reads:M,nodeMap:C,shapes:B,bounds:nn,maxOrder:V,trackForRuler:Ze,coarsenedEdgeMeta:wt}}function Fe(e,t="plain"){return _.trackColor(e,t)}function ia(e){return _.trackAlpha(e)}function Qt(e){return structuredClone(e)}function q(e){let t=String(e);return t.length>=1&&t.startsWith("-")}function v(e){return q(e)?String(e).substring(1):e}function de(e){return q(e)?e:`-${e}`}function Fo(e){return q(e)?v(e):de(e)}function Mt(e){return(e||1/e)>=0}function la(e){let t=new Set,n=y[e].sequence;for(let r=0;r<n.length;r+=1){let o=n[r];if(q(o)){let s=v(o),a=n.indexOf(s);(a===-1||a>r)&&t.add(s)}}for(let r of y){n=r.sequence;for(let o=0;o<n.length;o+=1){let s=n[o];q(s)?t.has(v(s))&&(n[o]=v(s)):t.has(s)&&(n[o]=de(s))}}x.forEach(r=>{r&&t.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function ca(){We=[];for(let t=0;t<=V;t+=1)We[t]=[];let e=new Map;x.forEach(t=>{t.y!==void 0&&Ro(e,t.order,t.y+t.contentHeight)}),y.forEach(t=>{t.type==="haplotype"&&t.path.forEach(n=>{Ro(e,n.order,(n.y??0)+t.width)})}),x.forEach((t,n)=>{t.order>=0&&t.y===void 0&&(t.y=(e.get(t.order)??0)+25,t.contentHeight=0,We[t.order].push(n))})}function Ro(e,t,n){let r=e.get(t);r===void 0?e.set(t,n):e.set(t,Math.max(r,n))}var Rt=7;function ua(){x.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),M.forEach((e,t)=>{if((e.width===void 0||e.width===0)&&(e.width=Rt),e.path.length===1){let n=e.path[0].node;n!==null&&x[n].internalReads.push(t)}else e.path.forEach((n,r)=>{if(r===0){let o=e.path[0].node;o!==null&&x[o].outgoingReads.push([t,r])}else{let o=n.node;o!==null&&x[o].incomingReads.push([t,r])}})})}function da(){ya(),ua();let e=x.slice();e.sort(Et);let t=new Map;for(let a=0;a<M.length;a++){let l=M[a].sourceTrackID,i=t.get(l);i===void 0?t.set(l,[a]):i.push(a)}let n=Array.from(t.keys()).sort((a,l)=>a-l),r=n.length>1?Rt:0;e.forEach(a=>{if(a)for(let l of n)fa(t.get(l),a,r)});let o=xa(),s=[];M.forEach((a,l)=>{let i=a.path.length,c=new Array(i),d;for(let h=0;h<i;h++){h===0?c[h]=void 0:c[h]=d??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(d=p)}let u=new Array(i),f;for(let h=i-1;h>=0;h--){h===i-1?u[h]=void 0:u[h]=f??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(f=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=c[p],g=u[p],b=!!(g&&m&&g.isForward!==void 0&&m.isForward!==void 0&&(m.order>g.order||g.order===m.order&&g.isForward===m.isForward));h.betweenCycleReverseTraversal=b,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(ha),s.forEach(a=>{let l=M[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),et&&(console.log("Reads:"),console.log(M))}function fa(e,t,n){let r=new Set(e),o=t.incomingReads.filter(([p])=>r.has(p)),s=t.outgoingReads.filter(([p])=>r.has(p)),a=t.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(n=0);let l=t.y+t.contentHeight+n*2,i=o.map(p=>{let[m,g]=p,b=M[m].path,w=g+1,S;for(let E=1;E<=g;E++){let T=b[g-E]?.y;if(T!==void 0){w=E,S=T;break}}return{entry:p,decisionStep:w,y:S}});i.sort(pa),o=i.map(p=>p.entry);let c=l,d=new Map;o.forEach(p=>{let m=M[p[0]];m.path[p[1]].y=c,Eo(d,m,p[1],c,t),c+=m.width});let u=c;s.sort(ma);let f=new Map;c=l,s.forEach(p=>{let m=M[p[0]],g=m.firstNodeOffset??0;m.path[p[1]].y=c,f.set(c,g);let b=d.get(c);b===void 0||b+1<=g?(c+=m.width,u=Math.max(u,c)):(d.set(c,0),o.forEach(w=>{let S=M[w[0]],E=S.path[w[1]];E.y!==void 0&&E.y>=c&&(E.y+=m.width,Eo(d,S,w[1],E.y,t))}),c+=m.width,u+=m.width)}),a.sort(ba),a.forEach(p=>{let m=M[p],g=m.firstNodeOffset??0,b=m.finalNodeCoverLength??0;for(c=l;g<(d.get(c)??-1/0)+2||b>(f.get(c)??1/0)-3;)c+=m.width||Rt;m.path[0].y=c,d.set(c,b),u=Math.max(u,c)});let h=u-t.y-t.contentHeight;t.contentHeight+=h,Ga(t,h)}function pa(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 Eo(e,t,n,r,o){n===t.path.length-1?e.set(r,t.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function ha(e,t){let n=M[e.readIndex],r=M[t.readIndex],o=n.path[e.pathIndex],s=r.path[t.pathIndex];if(o.order!==s.order)return o.order-s.order;if(n.sourceTrackID!==r.sourceTrackID)return n.sourceTrackID-r.sourceTrackID;if(e.previousNode&&t.previousNode){let i=x[e.previousNode],c=x[t.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=t.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function ma([e,t],[n,r]){let o=M[e],s=M[n],a,l,i=o.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let d=o.path[t]?.node,u=s.path[r]?.node,f=d!=null?x[d]:null,h=u!=null?x[u]:null;for(;f!=null&&h!=null&&f===h;){if(t<o.path.length-1){for(t+=1;o.path[t]?.node===null;)t+=1;let m=o.path[t]?.node;f=m!=null?x[m]:null}else f=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?x[m]:null}else h=null}if(f!=null)return h!=null?Et(f,h):1;if(h!=null)return-1;let p=(o.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(o.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function ga(e,t){if(e.path===void 0||t.path===void 0)return(e.path===void 0?0:1)-(t.path===void 0?0:1);let n=e.path,r=t.path,o=0,s=0;for(;o<n.length&&s<r.length;){let a=n[o],l=r[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?o+=1:(i>c||(o+=1),s+=1)}return 0}function ba(e,t){let n=M[e],r=M[t],o=n.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=n.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function xa(){let e=[];for(let t=0;t<=V;t+=1)e.push(0);return x.forEach(t=>{t.y!==void 0&&(e[t.order]=Math.max(e[t.order],t.y+t.contentHeight+20))}),y.forEach(t=>{t.path.forEach(n=>{e[n.order]=Math.max(e[n.order],(n.y??0)+t.width)})}),e}function ya(){M.forEach(e=>{let t=Math.abs(e.indexSequence[0]),n=Mt(e.indexSequence[0]),r=x[t],o,s;e.path=[],e.path.push({order:r.order,isForward:n,node:t});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=n,t=Math.abs(e.indexSequence[a]),n=Mt(e.indexSequence[a]),r=x[t],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});n?e.path.push({order:r.order,isForward:!0,node:t}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:t}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});n?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:t})):e.path.push({order:r.order,isForward:!1,node:t})}else n!==s?e.path.push({order:r.order,isForward:n,node:t}):(e.path.push({order:r.order,isForward:!n,node:null}),e.path.push({order:r.order,isForward:n,node:t}))})}function Zt(){M.forEach(e=>{let t=0;for(;t<e.sequence.length&&e.sequence[t].startsWith("-");)t+=1;if(t===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=v(e.sequence[a]);let n=e.sequenceNew??[];n.reverse(),e.sequenceNew=n;for(let a of n)a.nodeName=v(a.nodeName),wa(a.mismatches,oe(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function wa(e,t){e.forEach(n=>{n.type==="insertion"?n.pos=t-n.pos:n.type==="deletion"?n.pos=t-n.pos-(n.length??0):n.type==="substitution"&&(n.pos=t-n.pos-(n.seq?.length??0)),n.seq!==void 0&&(n.seq=Wo(n.seq).split("").reverse().join(""))})}var Ma={A:"T",T:"A",C:"G",G:"C"};function Wo(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Ma[e.charAt(n)]??"N";return t}function Ge(e){e.forEach(t=>{t.indexSequence=[],t.sequence.forEach(n=>{let r=n,o=C.get(v(r)),s=x[o]?.switched??!1;s&&(r=Fo(r));let a=C.get(v(r));if(a===0)throw new Error("Node "+v(r)+" has prohibited index 0");q(r)!==s?t.indexSequence.push(-a):t.indexSequence.push(a)})})}var Ra=20;function Ea(){let e={minX:99,maxX:-99,minY:99,maxY:-99};x.forEach(t=>{t&&(t.x!==void 0&&(e.minX=Math.min(e.minX,t.x),e.maxX=Math.max(e.maxX,t.x+Ra+t.pixelWidth)),t.y!==void 0&&(e.minY=Math.min(e.minY,t.y-10),e.maxY=Math.max(e.maxY,t.y+t.contentHeight+10)))}),y.forEach(t=>{t.path.forEach(n=>{let r=n.y??0;e.maxY=Math.max(e.maxY,r+t.width),e.minY=Math.min(e.minY,r)})}),nn=e}function oe(e){let t=C.get(v(e)),n=t===void 0?void 0:x[t];if(n===void 0)throw new Error(`Unknown node ${e}`);return n}function So(){return C=new Map,x.forEach((e,t)=>{e&&C.set(e.name,t)}),C}function No(){let e=x.map(()=>new Set),t=x.map(()=>new Set),n=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),t[a].add(s)}};y.forEach(n),_.showReads&&M.length>0&&M.forEach(n),x.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(t[o]))})}function Lo(e){let t=0,n=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){L[s]===void 0&&(L[s]=n);let a=L[s];a<r&&(r=a),t=a,n=a-1}else{L[s]===void 0&&(L[s]=t);let a=L[s];t=a+1,n=a}}),r<0&&sn(-r)}function Sa(e){let t=0,n=0;for(;t<e.length&&L[Math.abs(e[t])]===void 0;)t+=1;if(t>=e.length)return null;let r=e[t],o,s;r>=0?(o=L[r]-1,s=-1):(o=L[-r]+1,s=1);for(let a=t-1;a>=0;a-=1){let l=Math.abs(e[a]);L[l]===void 0&&(L[l]=o,n=Math.min(n,o),o+=s)}return n<0&&sn(-n),t}var Na=-1;function La(e){let t=[];for(let n of e)t.push(n??Na);return t}function Jt(){let e,t,n,r,o=0,s=_.showReads&&M.length>0?y.concat(M):y,a={stamp:new Int32Array(x.length),generation:0};L=new Array(x.length).fill(void 0),x.forEach(i=>{i&&(i.order=void 0)}),Lo(y[0].indexSequence);for(let i=1;i<s.length;i+=1){if(et&&console.log(`generating order for track ${i+1}`),n=Sa(s[i].indexSequence),n===null){s[i].type==="haplotype"?Lo(s[i].indexSequence):(s.splice(i,1),M.splice(i-y.length,1),i-=1);continue}for(e=Ca(s[i].indexSequence);n<e.length;){for(r=n,n+=1;n<e.length&&L[e[n]]===void 0;)n+=1;if(n<e.length){t=L[e[r]]+1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,t+=1;if(L[e[n]]>L[e[r]])L[e[n]]<t&&Co(e[n],e[n-1],t);else if(s[i].indexSequence[n]>=0&&!Ta(e[n],e[r],a))Co(e[n],e[n-1],t);else if(s[i].indexSequence[r]<0||x[e[r+1]].degree<2&&L[e[n]]<L[e[r]]){t=L[e[r]]-1;for(let c=r+1;c<n;c+=1)L[e[c]]=t,o=Math.min(o,t),t-=1}}else if(s[i].indexSequence[r]>=0){t=L[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,t+=1)}}else{t=L[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let d=e[c];L[d]===void 0&&(L[d]=t,o=Math.min(o,t),t-=1)}}}}o<0&&sn(-o);let l=La(L);L=l,l.forEach((i,c)=>{let d=x[c];d!==void 0&&(d.order=i)})}function Ta(e,t,n){n.generation+=1;let{stamp:r,generation:o}=n,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===t)return!0;for(let l of x[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function To(){let e=-1;return L.forEach(t=>{t!==void 0&&t>e&&(e=t)}),e}function Ca(e){return e.map(t=>Math.abs(t))}function sn(e){L.forEach((t,n)=>{t!==void 0&&(L[n]=t+e)})}function Co(e,t,n){let r=new Map,o=[[e,n]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=L[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),x[a].successors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}),a!==e&&x[a].predecessors.forEach(c=>{L[c]>i&&c!==t&&o.push([c,l+1])}))}r.forEach((a,l)=>{L[l]=a})}function Aa(){x.forEach(e=>{e.tracks=[]}),y.forEach(e=>{e.indexSequence.forEach(t=>{x[Math.abs(t)].tracks.push(e.id)})}),x.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function _a(){let e=y[0],t=y.slice(1,y.length);if(_.showReads&&M.length>0&&(t=t.concat(M)),Ia(t,e),_.showReads&&M.length>0){for(let n=0;n<M.length;n++)if(M[n]!==t[n+y.length-1])throw new Error("Read inequality")}}function Ia(e,t){let n=new Map,r=t?new Set(t.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=v(s[a]),i=oe(l);if(r&&!r.has(l)){let c=a>0?oe(s[a-1]).order:void 0,d=a<s.length-1?oe(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(d===void 0||i.order<d)&&Ao(n,l,q(s[a])?1:-1),(c===void 0||c>i.order)&&(d===void 0||i.order>d)&&Ao(n,l,q(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=n.get(v(s));l!==void 0&&l>0&&(o.sequence[a]=Fo(s),o.indexSequence[a]=-o.indexSequence[a])});n.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=Wo(a.seq),a.switched=!0}})}function Ao(e,t,n){e.set(t,(e.get(t)??0)+n)}function va(){let e=0,t=20,n=-1,r=x.slice();r.sort(Et);let o=Pa();r.forEach(s=>{s.order>=0&&(s.order>n&&(n=s.order,e=t+10*o[s.order]),s.x=e,t=Math.max(t,e+40+s.pixelWidth))})}function Pa(){let e=[],t=[],n=[],r=[];for(let o=0;o<=V;o+=1)e.push(0),t.push(0),n.push(0);y.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:t[a.order]=t[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));n[a.order]=Math.max(i/17.5,n[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=V;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,t[o-1]-1),n[o]));return r}function Oa(){let e,t,n,r,o,s,a=[],l=[];for(let i=0;i<=V;i+=1){Me[i]=[],l[i]=new Map,a[i]=[];for(let c=0;c<y.length;c+=1)a[i][c]=null}y.forEach((i,c)=>{t=Math.abs(i.indexSequence[0]),n=Mt(i.indexSequence[0]),r=x[t],i.path=[],i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,0,a,l),e=1;for(let d=1;d<i.sequence.length;d+=1)if(o=r,s=n,t=Math.abs(i.indexSequence[d]),n=Mt(i.indexSequence[d]),r=x[t],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order+1;u<r.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),D(o.order,null,c,e,a,l),e+=1);for(let u=o.order-1;u>r.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),D(u,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:t}),D(r.order,t,c,e,a,l),e+=1)}else n!==s?(i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!n,node:null}),D(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:n,node:t}),D(r.order,t,c,e,a,l),e+=1)});for(let i=0;i<=V;i+=1)Ba(Me[i],i)}function D(e,t,n,r,o,s){let a={trackID:n,segmentID:r,compareToFromSame:o[e][n]??null},l=t===null?void 0:s[e].get(t);if(l===void 0){let i={type:"single",node:t,tracks:[a]};Me[e].push(i),t!==null&&s[e].set(t,i)}else l.type="multiple",l.tracks.push(a);o[e][n]=a}function ka(e,t){let n;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(y[o.trackID].path[o.segmentID-1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<y[o.trackID].path.length-1&&y[o.trackID].path[o.segmentID+1].order===t-1)o.idealLane=y[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=y[o.trackID].path[o.segmentID+1].y;else{for(n=o.segmentID-1;n>=0&&y[o.trackID].path[n].order!==t-1;)n-=1;n<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=y[o.trackID].path[n].lane??void 0,o.idealY=y[o.trackID].path[n].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Ba(e,t){let n=0,r=new Set,o=20,s=!1,a=-1;ka(e,t),e.sort(Io),e.forEach(l=>{l.node!==null?(x[l.node].topLane=n,s&&(o-=10),x[l.node].y=o,x[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(Io),l.tracks.forEach(i=>{i.lane=n,i.trackID===a&&l.node===null&&s&&(o+=10),y[i.trackID].path[i.segmentID].lane=n,y[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),n+=1,o+=y[i.trackID].width,l.node!==null&&(x[l.node].contentHeight+=y[i.trackID].width),a=i.trackID}),o+=25}),$a(e,r)}function $a(e,t){let n=0,r=Number.MAX_SAFE_INTEGER;t.forEach(o=>{_o(e,o)<r&&(r=_o(e,o),n=o)}),e.forEach(o=>{o.node!==null&&(x[o.node].y+=n),o.tracks.forEach(s=>{let a=y[s.trackID].path[s.segmentID];a.y=a.y+n})})}function Ga(e,t){e.order<0||Me[e.order]===void 0||(Me[e.order].forEach(n=>{if(n.node!==null){let r=x[n.node];r!==e&&r.y>e.y&&(r.y+=t,n.tracks.forEach(o=>{let s=y[o.trackID].path[o.segmentID];s.y=s.y+t}))}else n.tracks.forEach(r=>{let o=y[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+t)})}),We[e.order].length>0&&We[e.order].forEach(n=>{x[n]!==e&&x[n].y>e.y&&(x[n].y+=t)}))}function _o(e,t){let n=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&y[o.trackID].type!=="read"&&(n+=Math.abs(o.idealY-t-y[o.trackID].path[o.segmentID].y)*y[o.trackID].width)})}),n}function Io(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 Et(e,t){if(!e)return t?-1:0;if(!t)return 1;if(e.order!==void 0){if(t.order!==void 0){if(e.order<t.order)return-1;if(e.order>t.order)return 1;if(e.y!==void 0&&t.y!==void 0){if(e.y<t.y)return-1;if(e.y>t.y)return 1}return 0}return-1}return t.order!==void 0?1:0}function Fa(){let e,t,n={};tn.forEach(r=>{let o=0;for(;o<y.length&&y[o].name!==r.track;)o+=1;o<y.length&&(e=0,y[o].path.forEach(s=>{s.node!==null&&(n={},t=e+x[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(n.start=0),e<r.start&&t>=r.start&&(n.start=r.start-e),t<=r.end&&t>=r.start&&(n.end=t-e,t<r.end&&(n.continue=!0)),t>r.end&&e<=r.end&&(n.end=r.end-e),n.start!==void 0&&(n.type=r.type,n.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(n)),e=t+1)}))})}function Wa(){let e=!0,t=4,n=_.trackWidth;y.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*t):(r.width=n,r.type!==void 0&&r.type==="read"&&(r.width=t)),r.width!==t&&(e=!1)}),e&&y.forEach(r=>{r.freq!==void 0&&(r.width=n)})}function Da(e){let t=e.path[0],n=x[t.node],r=e.firstNodeOffset??0;return an(n,t.isForward?r:n.sequenceLength-r)}function qa(e){let t=e.path[e.path.length-1],n=x[t.node],r=e.finalNodeCoverLength??0;return an(n,t.isForward?r:n.sequenceLength-r)}function Do(e,t){return t>e.sequenceLength?null:an(e,t)}function an(e,t){let[n,r]=Ya(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(r-n)}function Ha(){let e,t,n,r,o,s,a,l,i;for(let u=0;u<=V;u+=1)on.push(0),rn.push(0);let c=[],d=[];x.forEach(u=>{u.x!==void 0&&(c[u.order]=u.x,d[u.order]===void 0?d[u.order]=u.x+u.pixelWidth:d[u.order]=Math.max(d[u.order],u.x+u.pixelWidth))}),y.sort(ga),y.forEach(u=>{a="plain",o=Fe(u,a),s=ia(u);let f=a,h=()=>(f!==a&&(f=a,o=Fe(u,a)),o);n=u.path[0].y,u.type!=="read"?u.sequence[0].startsWith("-")?e=d[u.path[0].order]+20:e=c[u.path[0].order]-20:e=Da(u);for(let p=0;p<u.path.length;p+=1)u.path[p].y===n?u.path[p].features!==void 0&&(i=p>0&&u.path[p-1].order===u.path[p].order,l=Po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart):(u.path[p-1].isForward?t=d[u.path[p-1].order]:t=c[u.path[p-1].order],t!==e&&(o=h(),B.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})),u.path[p].order-1===u.path[p-1].order?(e=t,t=c[u.path[p].order],r=u.path[p].y,o=h(),B.curves.push({xStart:e,yStart:n,xEnd:t+1,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p].order+1===u.path[p-1].order?(e=t,t=d[u.path[p].order],r=u.path[p].y,o=h(),B.curves.push({xStart:e+1,yStart:n,xEnd:t,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=t,n=r):u.path[p-1].isForward?(r=u.path[p].y,ko(1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=d[u.path[p].order],n=u.path[p].y):(r=u.path[p].y,ko(-1,t,n,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=c[u.path[p].order],n=u.path[p].y),u.path[p].features!==void 0&&(i=u.path[p-1].order===u.path[p].order,l=Po(u.path[p],c[u.path[p].order],d[u.path[p].order],a,u,e,n,o,i),a=l.highlight,e=l.xStart));u.type!=="read"?u.path[u.path.length-1].isForward?t=d[u.path[u.path.length-1].order]+20:t=c[u.path[u.path.length-1].order]-20:t=qa(u),B.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})})}var Xa=1e9;function vo(e,t){wt=new Map;let n=new Map,r=_.ignoreStrand;for(let f of e){let h=f.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],g=h[p+1],b=Math.abs(m),w=Math.abs(g),S=x[b],E=x[w];if(!S||!E)continue;let T;if(r){let N=`${m}>${g}`,I=`${-g}>${-m}`;T=N<I?N:I}else T=`${m}>${g}`;let R=n.get(T);R===void 0?n.set(T,{sSigned:m,dSigned:g,sName:m<0?`-${S.name}`:S.name,dName:g<0?`-${E.name}`:E.name,count:1,sourceTrackID:f.sourceTrackID}):R.count+=1}}let o=0;for(let f of n.values())f.count>o&&(o=f.count);let s=Rt,a=60,l=f=>o<=1?s:s+(a-s)*Math.sqrt(f/o),i=[],c=0;for(let f of n.values()){let h=Xa+c,p=`${f.count.toLocaleString()} ${t}${f.count===1?"":"s"}: Node ${f.sName} \u2192 Node ${f.dName}`;wt.set(h,{count:f.count,label:p});let m=x[Math.abs(f.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:f.sourceTrackID,type:"read",name:p,sequence:[f.sName,f.dName],indexSequence:[],path:[],width:l(f.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:f.sName,mismatches:[]},{nodeName:f.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:f.count}),c+=1}let d="?",u=0;for(let f of x){if(!f)continue;let h=f.contentHeight;h>u&&(u=h,d=f.name)}return et&&console.log(`[coarsened] ${t}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${d}(${u.toFixed(1)})`),i}function Po(e,t,n,r,o,s,a,l,i){let c=r,d,u,f,h;t-=8,n+=8;let p=x[e.node].sequenceLength;return e.features.sort((m,g)=>m.start-g.start),e.features.forEach(m=>{c!==m.type&&(d=Fe(o,c),e.isForward?(f=t+Math.round(m.start*(n-t+1)/p),i&&f<t+8&&(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,u=Fe(o,m.type),B.featureRectangles.push({xStart:f,yStart:a,xEnd:h,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),f>s+1&&B.featureRectangles.push({xStart:s,yStart:a,xEnd:f-1,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(f=n-Math.round(m.start*(n-t+1)/p),i&&f>n-8&&(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,u=Fe(o,m.type),B.featureRectangles.push({xStart:h,yStart:a,xEnd:f,yEnd:a+o.width-1,color:u,id:o.id,name:o.name,type:o.type})),s>f+1&&B.featureRectangles.push({xStart:f+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=f,c=m.type),(m.end<p-1||m.continue===void 0)&&(d=Fe(o,c),e.isForward?(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,B.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})):(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,B.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s=h+1,c="plain")}),{xStart:s,highlight:c}}var Oo=7;function ko(e,t,n,r,o,s,a,l,i,c){let d=e===1?rn:on,u=10*d[l],f=t+e*(u+5),h=Oo,p=Math.min(Oo,o),m=Math.min(n,r),g=Math.max(n,r),b=e===1?t:f-1,w=e===1?f:t,S=N=>{B.verticalRectangles.push({xStart:b,yStart:N,xEnd:w,yEnd:N+o-1,color:s,id:a,name:c,type:i})};S(n),B.verticalRectangles.push({xStart:e===1?f+h:f-h-p,yStart:m+o+h-1,xEnd:e===1?f+h+p-1:f-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),S(r);let E=f+e*h,T=f+e*(h+p),R=`M ${f} ${g}`;R+=` Q ${E} ${g} ${E} ${g-h}`,R+=` H ${T}`,R+=` Q ${T} ${g+o} ${f} ${g+o}`,R+=" Z ",B.corners.push({path:R,color:s,id:a,type:i}),R=`M ${f} ${m}`,R+=` Q ${T} ${m} ${T} ${m+o+h}`,R+=` H ${E}`,R+=` Q ${E} ${m+o} ${f} ${m+o}`,R+=" Z ",B.corners.push({path:R,color:s,id:a,type:i}),d[l]+=1}function Ya(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function Bo(){switch(x.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),_.nodeWidthOption){case"compressed":x.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":x.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":x.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=_.charWidth;x.forEach(t=>{t.width=t.sequenceLength;let n=t.seq?.length??1;t.pixelWidth=Math.round(e*n)});break}default:throw new Error(`${_.nodeWidthOption} not implemented`)}}function za(){let e,t,n=Array.from(x,()=>new Set),r=Array.from(x,()=>new Set),o;_.showReads&&M.length>0?o=y.concat(M):o=y,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)q(l.sequence[i])?(e=v(l.sequence[i]),i>0?(t=l.sequence[i-1],q(t)?r[C.get(e)].add(v(t)):(r[C.get(e)].add(t),r[C.get(e)].add(de(t)))):l.type==="haplotype"&&r[C.get(e)].add("None"),i<l.sequence.length-1?(t=l.sequence[i+1],q(t)?n[C.get(e)].add(v(t)):(n[C.get(e)].add(t),n[C.get(e)].add(de(t)))):l.type==="haplotype"&&n[C.get(e)].add("None")):(i>0?(e=l.sequence[i-1],n[C.get(l.sequence[i])].add(e),q(e)&&n[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&n[C.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[C.get(l.sequence[i])].add(e),q(e)&&r[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&r[C.get(l.sequence[i])].add("None"))});let s=n.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(_.showReads&&M.length>0){let l=x.slice();l.sort(Et);let i=new Map,c=new Map,d=f=>{let h=i.get(f);if(h===void 0)throw new Error(`No merge offset recorded for node ${f}`);return h},u=f=>{let h=c.get(f);if(h===void 0)throw new Error(`No merge origin recorded for node ${f}`);return h};l.forEach(f=>{let h=Je(C.get(f.name),s,a);if(h){let p=d(h)+oe(h).sequenceLength;i.set(f.name,p),i.set(de(f.name),p),c.set(f.name,u(h)),c.set(de(f.name),u(h))}else i.set(f.name,0),i.set(de(f.name),0),c.set(f.name,f.name),c.set(de(f.name),f.name)}),M.forEach(f=>{let h=f.sequenceNew??[];f.firstNodeOffset=(f.firstNodeOffset??0)+d(f.sequence[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+d(f.sequence[f.sequence.length-1]);for(let p=f.sequence.length-1;p>=0;p-=1){let m=v(f.sequence[p]),g=Je(C.get(m),s,a);if(g&&en(C.get(g),s,a))if(p>0){f.sequence.splice(p,1);let b=oe(g).sequenceLength;h[p].mismatches.forEach(w=>{w.pos+=b}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{f.sequence[0]=u(f.sequence[0]);let b=h[0],w=d(b.nodeName);b.mismatches.forEach(S=>{S.pos+=w}),b.nodeName=u(b.nodeName)}}})}for(let l=0;l<x.length;l+=1)if(en(l,s,a)&&!Je(l,s,a)){let i=l;for(;en(i,s,a);)i=C.get(v(a[i][0])),x[l].sequenceLength+=x[i].sequenceLength,x[l].seq+=x[i].seq}y.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=v(l.sequence[i]);let c=C.get(e);Je(c,s,a)&&l.sequence.splice(i,1)}});for(let l=x.length-1;l>=0;l-=1)Je(l,s,a)&&x.splice(l,1)}function Je(e,t,n){if(t[e].length!==1||t[e][0]==="None")return!1;let r=v(t[e][0]),o=C.get(r);return n[o].length!==1||n[o][0]==="None"?!1:r}function en(e,t,n){if(n[e].length!==1||n[e][0]==="None")return!1;let r=v(n[e][0]),o=C.get(r);return!(t[o].length!==1||t[o][0]==="None")}function Ka(e){let t=_.focusReadNames?new Set(_.focusReadNames):null;return e.filter(n=>n.is_secondary!==!0&&(n.mapping_quality??0)>=_.mappingQualityCutoff&&(t===null||n.name!==void 0&&t.has(n.name)))}function ja(e,t){let n=new Map;for(let r of e){let o=t(r),s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}return n}function Ua(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 qo(e,t){let n=ja(e.filter(s=>s.type===t),s=>`${s.nodeStart},${s.nodeEnd}`);n.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Ua),s.forEach(i=>{let c,d;i.yStart<i.yEnd?(c=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,d=i.xStart+(i.xEnd-i.xStart)*(1-a)):(c=i.xStart+(i.xEnd-i.xStart)*a,a+=l,d=i.xStart+(i.xEnd-i.xStart)*a);let u=`M ${i.xStart} ${i.yStart}`;u+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,u+=` V ${i.yEnd+i.width}`,u+=` C ${d} ${i.yEnd+i.width} ${d} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,u+=" Z",i.path=u})});let r=Array.from(n.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),c=l[0]??0,d=l[1]??0,u=i[0]??0,f=i[1]??0;return c<u?-1:c>u?1:d<f?-1:d>f?1:0});let o=[];for(let s of r){let a=n.get(s);a!==void 0&&o.push(...a)}return o}function Ho(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,r=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n+9} ${r} ${n+9} ${r+9}`,n+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,t+=` L ${n} ${r}`),t+=` Q ${n} ${r+9} ${n-9} ${r+9}`,n-=9,r+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n-9} ${r} ${n-9} ${r-9}`,n-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,t+=` L ${n} ${r}`),t}function Va(e){let t=new Map;for(let[n,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${n}`,a=t.get(s);a?a.push(o.strand):t.set(s,[o.strand])}return t}function Qa(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=Va(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>le(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=le(s.name).name,i=new Map,c=s.nodeIds.flatMap(d=>{let u=t.get(d);if(!u)return[];let f=i.get(u.name)??0;i.set(u.name,f+1);let h=n.get(`${l} ${u.name}`)?.[f]??Kt(u);return[jt(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Za(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function De(e){return(e.paths?.length??0)>0}var Ja=600,ei=3,ti=15;function ni(e){return Math.max(ei,Math.min(ti,Math.floor(Ja/Math.max(1,e))))}function Xo(e){let t=e.paths??[],n=Qa(e),r=e.reads?uo(e,e.reads,t.length):[],o=r.length>0?kn:On,s=t.map((l,i)=>o(i,t.length)),a=Go(Za(e),n,r,{nodeWidthOption:"compressed",trackWidth:ni(n.length),trackColor:l=>l.type==="read"?fo(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function ln(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function Yo(e,t,n,r){let o=e.y+e.contentHeight/2-t;return[{x:n,y:o},{x:r,y:o}]}function zo(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function Ko(e){let t=De(e)?Xo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=n.bounds.minY,s={};for(let i of ln(n))s[i.name]=Yo(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=zo(n,o);return{nodePositions:s,tubeMap:{layout:n,yOffset:o,pathColors:r},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:l}}}function oi(e,t){let n=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of ln(t)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,c)=>i-c)){let i=r.get(l),c=1/0,d=-1/0;for(let u of i){let f=n.get(u.name);f&&O(f)&&(c=Math.min(c,f.stable.start),d=Math.max(d,f.stable.start+u.sequenceLength))}c===1/0&&(c=d=s),c<s&&(c=s,d=Math.max(s,d)),s=Math.max(s,d),o.push({order:l,x0:Math.min(...i.map(u=>u.x)),x1:Math.max(...i.map(u=>u.x+u.pixelWidth)),bp0:c,bp1:d})}let a=o.find(l=>l.bp0!==-1/0);for(let l of o)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return o}function ri(e){return e.nodes.some(O)&&De(e)}function jo(e){let t=ri(e)?Xo(e):void 0;if(!t)return;let{layout:n,pathColors:r}=t,o=oi(e,n),s=new Map(o.map(i=>[i.order,i])),a=n.bounds.minY,l={};for(let i of ln(n)){let c=s.get(i.order);l[i.name]=Yo(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:n,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:zo(n,a)}}function Uo(e){return e.sample??lt(e.name)}function si(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Uo(e)}function ai(e,t){let n=[],r;for(let o of e){r!==void 0&&o.start!==void 0&&o.start>r&&n.push(o.start-r),n.push(...o.nodeIds);let s=o.nodeIds.reduce((a,l)=>a+(t.get(l)??0),0);r=o.start===void 0?void 0:o.start+s}return n}function ii(e,t){let n=[],r;for(let o of e){if(o.start===void 0||r!==void 0&&o.start<r)return;r!==void 0&&o.start>r&&n.push({start:r,end:o.start});let s=o.start;for(let a of o.nodeIds){let l=t.get(a)??0;n.push({start:s,end:s+l}),s+=l}r=s}return n}function li(e,t,n,r=!0){if(!n||!r)return{ids:e,complete:!0,from:-1,to:-1};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((c,d)=>{let u=typeof c=="string"?t.get(c):void 0;u&&(u.end<=n.start&&u.end>a&&(a=u.end,o=d),u.start>=n.end&&u.start<l&&(l=u.start,s=d))}),o<0||s<0)return{ids:e,complete:!1,from:-1,to:-1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0,from:o,to:s}}function Vo(e,t,n){let r=e.paths??[],o=g=>le(g.name).name===e.referencePath,s=r.some(o)?r.filter(o).sort((g,b)=>(g.start??0)-(b.start??0)):r.slice(0,1),a=s[0],l=r.filter(g=>!s.includes(g));if(!a||l.length===0)return;let i=new Map;for(let g of l)i.set(g.name,[...i.get(g.name)??[],g]);let c=new Map(e.nodes.map(g=>[g.id,g.length])),d=a.start??0,u=t&&t.end>t.start?t:void 0,f=new Map;for(let g of s){let b=g.start??0;for(let w of g.nodeIds){let S=c.get(w)??0;f.has(w)||f.set(w,{start:b,end:b+S}),b+=S}}let h=u===void 0||[...f.values()].some(g=>g.end<=u.start)&&[...f.values()].some(g=>g.start>=u.end),p=g=>{let b=g[0],w=[...g].sort((K,Z)=>(K.start??0)-(Z.start??0)),{ids:S,complete:E,from:T,to:R}=li(ai(w,c),f,u,h),N=ii(w,c),I=b.contig??ct(le(b.name).name),H=N?.length?T<0?{contig:I,start:N[0].start,reversed:!1}:T<R?{contig:I,start:N[T].end,reversed:!1}:{contig:I,start:N[T].start,reversed:!0}:void 0,F=[],z=0,Se=0,pe=0,Q=0;for(let K of S){if(typeof K=="number"){F.push({start:z,bp:K,onReference:!1,gap:!0}),z+=K,pe+=K,Q=0;continue}let Z=c.get(K)??0,j=f.get(K),U=F.at(-1),Ne=U?.referenceStart,A=j&&Ne!==void 0&&Q>=0&&Ne+U.bp===j.start,P=j&&Ne!==void 0&&Q<=0&&j.end===Ne;!j&&U&&!U.onReference&&!U.gap?U.bp+=Z:A||P?(U.bp+=Z,A||(U.referenceStart=j.start,U.reversed=!0),Q=A?1:-1):(F.push({start:z,bp:Z,onReference:j!==void 0,referenceStart:j?.start}),Q=0),z+=Z,j||(Se+=Z)}return{name:b.name,label:si(b),sample:Uo(b),haplotype:b.haplotype,bp:z,offReferenceBp:Se,gapBp:pe,complete:E,runs:F,axis:H}};return{origin:u?u.start:d,unit:n,reference:p(s),rows:[...i.values()].map(p).sort((g,b)=>Number(b.complete)-Number(g.complete)||b.bp-g.bp||g.label.localeCompare(b.label))}}var ci=1.3;function ui(e){let t=e.reference.bp;for(let n of e.rows)t=Math.max(t,n.bp);return{maxX:e.origin+t*ci,maxY:e.rows.length*20}}function Qo(e,t){let n=ve(e),r=Vo(e,t);if(n.length===0||!r)return;let o=t?n.filter(l=>yn(l,t)):n,s=Pe(o.length>0?o:n),a=[{label:r.reference.label,y:0},...r.rows.map((l,i)=>({label:l.label,y:(i+1)*20}))];return{nodePositions:s,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:ui(r)}}var di="Force-directed layout",Re=e=>e.nodes.some(O),Zo=e=>Re(e)&&(e.paths?.length??0)>1,Jo=e=>Re(e)&&De(e),er=e=>Re(e)&&e.nodes.some(ut),cn=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:mo,cutMargins:!0,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:wo,cutMargins:!0,wholeWalks:!1,available:er,drawsLocally:er,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:Qo,cutMargins:!1,wholeWalks:!0,available:Zo,drawsLocally:Zo,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:yo,cutMargins:!1,wholeWalks:!1,available:Re,drawsLocally:Re,drawsNodes:!0},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:Ko,cutMargins:!1,wholeWalks:!1,available:De,drawsLocally:De,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:jo,cutMargins:!0,wholeWalks:!1,available:Jo,drawsLocally:Jo,drawsNodes:!1},{value:"force",label:di,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],cu=cn.map(e=>e.value);function uu(e,t){return!fi(e).drawsLocally(t)}function fi(e){return cn.find(t=>t.value===e)??cn[0]}var pi=10;function hi(e,t){let n=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>r<=pi*(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 mi=40;function Ee(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function gi(e,t){let n=Ee(e),r=Ee(t),o=r.slice(r.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${r}`:`${n}\u2013${r}`}function tr(e){return e>=Bn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function pu(e,t=[]){let n=bi(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function bi(e,t){let n=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=gi(r,o);if(a>=mi)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${tr(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Ee(o)} inv`};let c=o!==r?hi(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${tr(s)}`}}let d=s>2?`, ${s} alleles`:"";return r===o&&r===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Ee(n)} sub`}:n===0||r===n?{kind:"insertion",label:`\u2264${Ee(o-n)} ins${d}`}:o===n?{kind:"deletion",label:`${Ee(n-r)} del${d}`}:{kind:"complex",label:`${Ee(n)} ref \u2192 ${i}, ${s} alleles`}}var hu={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},mu={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function gu(e){return e.segments.split(",").filter(Boolean)}function xu({count:e,bounds:t,pixelRows:n,width:r,room:o,columns:s}){function a(i){let c=Math.ceil(e/i),d=Math.floor((r-(i-1)*8)/i),u=(o-c*34-(c-1)*8)/c,f=(d-24)/t.w,h=t.h>0?(u-24)/t.h:1/0,p=n?f:Math.min(f,h),m=n?t.h:t.h*p,g=Math.floor(Math.max(60,Math.min(m+24,u)));return{columns:i,width:d,height:g,scale:p,total:c*(g+34)+(c-1)*8}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let l=a(1);for(let i=2;i<=e;i++){let c=a(i);c.scale>l.scale&&(l=c)}return l}function yu(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 nr(e,t){let n=new Map(t.map((o,s)=>[o,s])),r=o=>n.get(o)??t.length;return e.map((o,s)=>({name:o,i:s})).sort((o,s)=>r(o.name)-r(s.name)||o.i-s.i).map(({name:o})=>o)}function wu(e,t,n=[]){let r=nr(e,n),o={columns:void 0,count:e.length,cells:e.map(c=>r.indexOf(c))};if(t==="walk")return o;let s=e.map(c=>{let[d,u,f]=c.split("#"),h=Number(u);return f!==void 0&&Number.isInteger(h)&&h>=0?{sample:d,column:Math.max(0,h-1)}:void 0}),a=nr([...new Set(s.flatMap(c=>c?[c.sample]:[]))],n),l=Math.max(1,...s.map(c=>c?c.column+1:1)),i=s.map(c=>c?a.indexOf(c.sample)*l+c.column:-1);return i.includes(-1)||new Set(i).size<i.length?o:{columns:l,count:a.length*l,cells:i}}function k(e,t={},...n){return{tag:e,attrs:t,children:n.filter(r=>!!r||r==="")}}function or(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function xi(e){return or(e).replaceAll('"',""")}function yi(e){if(typeof e=="string")return or(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,r])=>` ${n}="${xi(String(r))}"`).join("");return`<${e.tag}${t}>${e.children.map(yi).join("")}</${e.tag}>`}var dn="#2f8fd6",sr="#8e3fbf",ar="#bdbdbd",St="#1c1c22",nt=12,ir=4,wi=3;function tt(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function rr(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function Mi(e,t,n,r){let{bp:o,gapBp:s,complete:a}=e;if(!t)return`${tt(o)}${rr(o,n)}`;let l=o-t.bp,i=l===0?"":` (${l>0?"+":"\u2212"}${tt(Math.abs(l))})`,c=s>0?` \xB7 ${tt(s)} outside the cut`:"",d=r?` \xB7 called ${tt(r.bp)}${r.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${tt(o)}${rr(o,n)}${i}${c}${a?"":" \xB7 partial walk"}${d}`}function Ri(e,t,n){let r=t+6;return r+e.length*6.2<n?{x:r,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Ei(e,t,n){if(t*n<wi)return[];let r=[];for(let o=t;o<e;o+=t)r.push(o);return r}function Si(e,t){if(e.gap)return{fill:ar};if(!t)return{fill:e.onReference?dn:sr};if(e.referenceStart===void 0)return{fill:Dt};let n=to({...e,start:e.referenceStart},t);return n.length===1?{fill:bt(n[0])}:{stops:n.map(bt)}}function Nt(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function Cu(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function Au(e,t){let n=new Map;for(let r of e){let o=t.get(r.name);if(!r.axis||!o)continue;let s=r.axis,a=({start:l,end:i})=>({start:Math.max(0,l),end:Math.min(r.bp,i)});n.set(r.name,o.map(l=>({name:l.name,...a(Nt(s,l.start,l.end)),exons:l.exons.map(i=>a(Nt(s,i.start,i.end))).filter(i=>i.end>i.start)})).filter(l=>l.end>l.start).sort((l,i)=>l.start-i.start))}return n}var Ni=9,Li=5.2;function Ti(e,t,n){let r=e.map(a=>{let l=t(a.start);return{g:a,x:l,w:Math.max(2,t(a.end)-l)}}),o=[],s=new Set([...r].sort((a,l)=>a.w-l.w).filter(({g:a,x:l,w:i})=>{let c=a.name.length*Li/2,d=[l+i/2-c,l+i/2+c];return 2*c>i+6||o.some(([u,f])=>d[0]<f+2&&d[1]>u-2)?!1:(o.push(d),!0)}));return r.map(a=>({name:a.g.name,x:a.x,y:n-nt/2-2,w:a.w,h:nt+4,exons:a.g.exons.map(l=>({x:t(l.start),w:Math.max(1,t(l.end)-t(l.start))})),label:s.has(a)?{x:a.x+a.w/2,y:n+3,size:Ni}:void 0}))}var un=e=>`${e} row${e===1?"":"s"}`;function _u(e,t={}){let n=[{swatch:{kind:"bar",fill:t.ramp?t.rampCss??dn:dn},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Dt:sr},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(r=>r.gapBp>0)&&n.push({swatch:{kind:"gap",fill:ar},label:"walked outside the cut"}),t.genes&&(n.push({swatch:{kind:"gene"},label:"genes, each row's own annotation"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${un(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${un(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${un(t.genes.unread)}`,note:!0})),n}var Ci="#111",Ai="#9e9e9e",_i="#c62828";function Iu(e,t,n){let r=0,o=e.flatMap(s=>{let a=s.note?void 0:s.swatch.kind==="gene"?k("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:St,"stroke-width":1.5}):k("rect",{x:r,y:s.swatch.kind==="gap"?7:5,width:18,height:s.swatch.kind==="gap"?ir:8,rx:2,fill:s.swatch.fill}),l=k("text",{x:s.note?r:r+23,y:13,"font-style":s.note?"italic":void 0,fill:s.note?"#666":void 0},s.label);return r+=(s.note?0:23)+s.label.length*6.2+16,a?[a,l]:[l]});return{width:r,tree:k("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...o)}}function Ii(e,t){let n=1/t,r=[],o=[],s=()=>{if(o.length!==0){if(o.length===1)r.push(o[0]);else{let l=0,i=0;for(let u of o)u.onReference?l+=u.bp:i+=u.bp;let c=l>=i,d=o.find(u=>u.onReference===c);r.push({start:o[0].start,bp:l+i,onReference:c,referenceStart:c?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}o=[]}},a=0;for(let l of e){if(l.gap||l.bp>=n){s(),a=0,r.push(l);continue}o.push(l),a+=l.bp,a>=n&&(s(),a=0)}return s(),r}function vi(e,t){return k("g",{class:"row-gene","data-testid":"graph-walk-gene"},k("title",{},e.name),...e.exons.map(n=>k("rect",{x:n.x,y:t-nt/2,width:n.w,height:nt,fill:St,opacity:.35})),k("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:St,"stroke-width":1.5}),e.label&&k("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:St,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function vu(e,t,n={}){let r=p=>p*t.scaleX+t.translateX,o=t.rowPx??20,s=t.barPx??nt,a=p=>p*o*t.scaleY+t.translateY,{origin:l,unit:i,reference:c,rows:d}=e,u=p=>r(l+p),f=n.idPrefix??"walkrow",h=(p,m)=>{let g=a(m);if(g<-s||g>t.height+s)return;let b=Ii(p.runs,t.scaleX).flatMap(N=>{let I=Si(N,n.ramp),H=N.gap?Math.min(ir,s):s,F=`${f}-${m}-${N.start}`,z=k("rect",{x:u(N.start),y:g-H/2,width:Math.max(1,N.bp*t.scaleX),height:H,fill:"stops"in I?`url(#${F})`:I.fill});return"stops"in I?[k("linearGradient",{id:F},...I.stops.map((Se,pe)=>k("stop",{offset:pe/(I.stops.length-1),"stop-color":Se}))),z]:[z]}),w=i?Ei(p.bp,i,t.scaleX).map(N=>k("line",{x1:u(N),x2:u(N),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:S}=p,E=Mi(p,m===0?void 0:c,i,S),T=Ri(E,u(p.bp),t.width),R=t.readouts??!0;return k("g",{"data-testid":m===0?"graph-walk-reference":"graph-walk-row"},...b,...w,...Ti(n.rowGenes?.get(p.name)??[],u,g).map(N=>vi(N,g)),S&&k("rect",{"data-testid":"graph-walk-call",x:u(S.bp)-1,y:g-s/2-3,width:2,height:s+6,fill:S.spanningReads===0?Ai:Ci}),R&&k("text",{x:T.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:S?.agrees===!1?_i:"#333",stroke:T.halo?"white":void 0,"stroke-width":T.halo?3:void 0,"paint-order":"stroke","text-anchor":T.anchor},E))};return k("g",{},...[c,...d].map(h))}var qe=Y(Oe(),1),pr=Y(cr(),1),hr=Y(dr(),1);var fr=class extends hr.Canvas2DRenderingBackendBase{constructor(){super(...arguments);this.transform=null;this.batch=null;this.nodeHighlights=new Map;this.highlightedEdge=null;this.highlightFactor=1}resize(n,r){(0,pr.syncCanvasSize)(this.ctx.canvas,n,r)}uploadGeometry(n){this.batch=n,this.highlightedEdge=null}setNodeHighlights(n){this.nodeHighlights=n}setEdgeHighlight(n,r){this.highlightedEdge=n,this.highlightFactor=r}updateTransform(n){this.transform=n}render(n){if(!this.transform)return;let o=this.ctx,{width:s,height:a}=o.canvas;n[3]<1&&o.clearRect(0,0,s,a),o.fillStyle=(0,qe.normalizedRgbToCssRgba)([n[0],n[1],n[2]],n[3]),o.fillRect(0,0,s,a);let l=this.batch;l&&(o.lineCap="round",o.lineJoin="round",this.renderEdges(l),this.renderNodes(l),this.renderArrows(l))}renderEdges(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.edgeCurveRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.edgeCurves,(i,c)=>({color:Lt(s,c)?mt(i.color,this.highlightFactor):i.color,weight:i.thickness,last:Lt(s,c)}))){o.strokeStyle=(0,qe.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.curves[0];o.moveTo(c.x0*r.scaleX+r.translateX,c.y0*r.scaleY+r.translateY);for(let d of i.curves)o.bezierCurveTo(d.cx0*r.scaleX+r.translateX,d.cy0*r.scaleY+r.translateY,d.cx1*r.scaleX+r.translateX,d.cy1*r.scaleY+r.translateY,d.x1*r.scaleX+r.translateX,d.y1*r.scaleY+r.translateY)}o.stroke()}}renderNodes(n){let r=this.transform,o=this.ctx,s=new Map;for(let[a,l]of this.nodeHighlights){let i=n.nodeStrokeRuns.get(a);if(i)for(let c=i.start;c<i.start+i.count;c++)s.set(c,l)}for(let{color:a,items:l}of fn(n.nodeStrokes,(i,c)=>{let d=s.get(c);return{color:d===void 0?i.color:mt(i.color,d),weight:i.thickness,last:d!==void 0}})){o.strokeStyle=(0,qe.abgrToCssRgba)(a),o.lineWidth=l[0].thickness*2*r.dpr,o.beginPath();for(let i of l){let c=i.points[0];o.moveTo(c.x*r.scaleX+r.translateX,c.y*r.scaleY+r.translateY);for(let d=1,u=i.points.length;d<u;d++){let f=i.points[d];o.lineTo(f.x*r.scaleX+r.translateX,f.y*r.scaleY+r.translateY)}}o.stroke()}}renderArrows(n){let r=this.transform,o=this.ctx,s=this.highlightedEdge===null?void 0:n.arrowRuns.get(this.highlightedEdge);for(let{color:a,items:l}of fn(n.arrows,(i,c)=>({color:Lt(s,c)?mt(i.color,this.highlightFactor):i.color,weight:0,last:Lt(s,c)}))){o.fillStyle=(0,qe.abgrToCssRgba)(a),o.beginPath();for(let i of l){let[c,d,u,f]=Oi(i,r);o.moveTo(c.x,c.y),o.lineTo(d.x,d.y),o.lineTo(u.x,u.y),o.lineTo(f.x,f.y),o.closePath()}o.fill()}}dispose(){super.dispose(),this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},Pi=.25;function Oi(e,t){let n=Math.cos(e.angle),r=Math.sin(e.angle),o=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,l=e.halfWidth*t.dpr,i=o-n*a,c=s-r*a,d=a*(1-Pi);return[{x:o,y:s},{x:i-r*l,y:c+n*l},{x:o-n*d,y:s-r*d},{x:i+r*l,y:c-n*l}]}function Lt(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function fn(e,t){let n=new Map,r=new Map;for(let o=0,s=e.length;o<s;o++){let a=e[o],{color:l,weight:i,last:c}=t(a,o),d=c?r:n,u=`${l}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:l,items:[a]})}return[...n.values(),...r.values()]}var yr=Y(Oe(),1);var ki=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],wr=[{value:"grey",label:"Grey to black",ends:["#a3a3a3","#151515"]},{value:"blue",label:"Cyan to navy",ends:["#6ee0f0","#0b2c7a"]},{value:"red",label:"Yellow to red",ends:["#ffd24a","#b3121b"]},{value:"purple",label:"Pink to plum",ends:["#f5a3d8","#5e1a6e"]},{value:"green",label:"Lime to forest",ends:["#b6e36c","#0b5d3b"]},{value:"rainbow",label:"Rainbow"}],mr=["blue","red","purple","green"],Bi=e=>ki.some(t=>t.value===e),$i=e=>wr.some(t=>t.value===e);function Fu(e,t,n,r=!0){let{field:o,scheme:s}=e.color??{},a=Bi(o)?o:r?"progress":"walk",l=t?"grey":mr[n%mr.length],i=$i(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var Mr=.5,Gi=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Fi=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function gr(e){let[t,n,r]=[1,3,5].map(l=>Gi(Number.parseInt(e.slice(l,l+2),16)/255)),o=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*r),s=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*r),a=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*r);return[.2104542553*o+.793617785*s-.0040720468*a,1.9779984951*o-2.428592205*s+.4505937099*a,.0259040371*o+.7827717662*s-.808675766*a]}function Wi([e,t,n]){let r=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s].map(a=>Fi(Math.max(0,Math.min(1,a)))*255)}function Rr(e,t){let n=Math.max(0,Math.min(1,t)),r=wr.find(a=>a.value===e);if(!r||!("ends"in r))return Be(n*$e,.7,.5).map(a=>a*255);let o=gr(r.ends[0]),s=gr(r.ends[1]);return Wi(o.map((a,l)=>a+(s[l]-a)*n))}function br(e,t){let[n,r,o]=Rr(e,t).map(Math.round);return`rgb(${n}, ${r}, ${o})`}function xr(e,t){let[n,r,o]=Rr(e,t).map(Math.round);return(0,yr.packAbgr)(n,r,o,255)}function Wu({field:e,scheme:t},n){return e==="walk"?xr(t,Mr):n===void 0?Di:xr(t,n)}var Di=Wt;function qi({field:e,scheme:t}){return e==="walk"?[{offset:0,color:br(t,Mr)}]:Array.from({length:7},(n,r)=>({offset:r/6,color:br(t,r/6)}))}function Du(e){let t=qi(e);return t.length===1?t[0].color:`linear-gradient(to right, ${t.map(n=>`${n.color} ${n.offset*100}%`).join(", ")})`}function Er(e,t,n){let r=Math.round(t),o=Math.round(n);return`${e?`${e}:`:""}${Ue(r)}-${Ue(o)} (${xe(o-r)})`}function Xu(e,t){let{field:n}=e.encoding,r=e.range?Er(e.range.contig,e.range.start,e.range.end):void 0,o=n==="progress"?r:n==="reference"&&t?Er(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${xe(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${xe(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${xe(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:o,hover:o===r?void 0:r}}function Yu(e,t,n){let r=e.progress.get(t),o=e.range;if(r===void 0||!o)return;let s=Math.round(o.start+r*(o.end-o.start)-n/2);return`${o.contig}:${Ue(s)}-${Ue(s+n)}`}var ot=6,Hi=3,Xi=12,Yi=1.3,zi="#111",Sr=3;function Qu(e,t,n){let r=e.pathVisits?.get(n.name)??[],o=[];for(let s of t){let a=s.axis;if(!a)continue;let l=le(s.name).name;for(let i of r){if(i.path!==l)continue;let{start:c,end:d}=Nt(a,i.start,i.start+n.length);d>0&&c<s.bp&&o.push({row:s.name,start:c,bp:d-c})}}return o}var Nr=new WeakMap;function Ki(e,t){let n=Nr.get(e);if(n||(n=new Map,Nr.set(e,n)),n.has(t))return n.get(t);let r=new Map(e.nodes.map(a=>[a.id,a.length])),o=(e.paths??[]).filter(a=>a.name===t),s;if(o.every(a=>a.start!==void 0)){s={ids:[],starts:[],ends:[]};for(let a of[...o].sort((l,i)=>l.start-i.start)){let l=a.start;for(let i of a.nodeIds){let c=r.get(i)??0;s.ids.push(i),s.starts.push(l),s.ends.push(l+c),l+=c}}}return n.set(t,s),s}function Zu(e,t,n,r){let o=t.axis,s=o&&Ki(e,t.name);if(!o||!s||n<0||n>t.bp)return;let a=o.reversed?o.start-n:o.start+n,l=.5/r,i=o.reversed?{start:o.start-t.bp,end:o.start}:{start:o.start,end:o.start+t.bp},c=Math.max(a-l,i.start),d=Math.min(a+l,i.end),u=0,f=s.starts.length;for(;u<f;){let g=u+f>>1;s.ends[g]<=c?u=g+1:f=g}let h,p=-1,m=!1;for(let g=u;g<s.starts.length&&s.starts[g]<d;g++){let b=s.ends[g]-s.starts[g],w=s.starts[g]<=a&&a<s.ends[g];(b>p||b===p&&w&&!m)&&(p=b,h=s.ids[g],m=w)}return h}function Ju(e,t){let n=e.rows.length+1,r=Math.max(Hi,Math.min(20,Math.floor((t.maxHeight-2*ot)/n))),o=r>=Xi,s=r>=14,a=Math.max(2,Math.round(r*.6)),l=Math.max(e.reference.bp,...e.rows.map(u=>u.bp),1),i=o?t.labelPx:ot,d=Math.max(1,t.width-i-ot)/(l*(s?Yi:1));return{scaleX:d,scaleY:1,translateX:i-e.origin*d,translateY:ot+r/2,width:t.width,height:n*r+2*ot,rowPx:r,barPx:a,readouts:s,labelled:o}}function ed(e,t,n,r){let o=Math.round((r-t.translateY)/t.rowPx),s=[e.reference,...e.rows][o],a=(n-t.translateX)/t.scaleX-e.origin;return s&&o>=0&&a>=0&&a<=s.bp?{index:o,row:s,offset:a}:void 0}function td(e,t,n){let r=new Map([e.reference,...e.rows].map((s,a)=>[s.name,a])),o=s=>(e.origin+s)*t.scaleX+t.translateX;return k("g",{"data-testid":"graph-walk-marks"},...n.flatMap(s=>{let a=r.get(s.row);if(a===void 0)return[];let l=a*t.rowPx+t.translateY,i=o(s.start),c=Math.max(2,s.bp*t.scaleX),d=u=>k("rect",{x:i,y:u,width:c,height:Sr,fill:zi});return[d(l-t.barPx/2-Sr-1),d(l+t.barPx/2+1)]}))}var pn=Y(Oe(),1);var fe=12,ji=fe+8,_r=8,Lr=_r+3,Ui=12;function sd(e,{colorScheme:t,referenceRamp:n,walks:r}){let o={...qt(e),referenceRamp:n},s=[];return e.nodes.forEach((a,l)=>{if(O(a)){let i=r?r.map(c=>{let d=c.colors.get(a.id);return d===void 0?Ft:(0,pn.abgrToCssRgba)(d)}):[(0,pn.abgrToCssRgba)(Ht(a,l,t,o))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(Ft)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function hn(e,t,n){let r=t*e.scale+e.translateX,o=n*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var Tr=2;function Vi(e,t,n){let r=-t.translateX/t.scale,o=(n-t.translateX)/t.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let c of e)l+=Math.max(0,Math.min(c.bp1,s)-c.bp0),i+=Math.max(0,c.bp1-Math.max(c.bp0,a));return t.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function ad(e,t,n,r){if(r<0||r>fe+Tr)return;let o,s=Tr;for(let a of e){let[l,i]=hn(t,a.bp0,a.bp1),c=Math.max(0,l-n,n-i);c<=s&&(s=c,o=a.node)}return o}function id(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function Qi(e,t,n,r){let o=e.map(c=>{let[d,u]=hn(t,c.bp0,c.bp1),f=Math.round(d*r);return{colors:c.colors,x0:d,px0:f,px1:Math.max(Math.round(u*r),f+1)}}).filter(c=>c.px1>0&&c.px0<n*r).sort((c,d)=>c.x0-d.x0),s=[],a=-1/0,l=[-1/0,-1/0];for(let{colors:c,px0:d,px1:u}of o){let f=Math.max(d,a);if(u>f){let h=l[0]<f?0:1;l[h]=u,s.push({colors:c,x0:f/r,x1:u/r,tier:h}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Ui?s:s.map(({tier:c,...d})=>d)}function Cr(e,t,n,r){let o=n>0?t:t-Lr;e.clearRect(o,0,Lr,fe);let s=t+n,a=s+n*_r;e.beginPath(),e.moveTo(s,fe/2),e.lineTo(a,0),e.lineTo(a,fe),e.closePath(),e.fillStyle=r,e.fill()}function Ar(e,t,n){return Math.round(e*fe*n/t)/n}function ld(e,t,n,{width:r,lit:o,darkMode:s,dpr:a=1}){let l=s?"#ffffff":"#18181c";e.clearRect(0,0,r,ji);for(let c of Qi(t,n,r,a)){let{tier:d}=c,u=d!==void 0&&c.colors.length===1,f=u?2:c.colors.length;c.colors.forEach((h,p)=>{let m=u?d:p,g=Ar(m,f,a);e.fillStyle=h,e.fillRect(c.x0,g,c.x1-c.x0,Ar(m+1,f,a)-g)})}let i=Vi(t,n,r);if(i.left>0&&Cr(e,0,1,l),i.right>0&&Cr(e,r,-1,l),o){let[c,d]=hn(n,o.start,o.end),u=Math.max(d-c,3),f=(c+d)/2-u/2;e.strokeStyle=l,e.lineWidth=1.5,e.strokeRect(f,.75,u,fe-1.5),o.anchor&&(e.beginPath(),e.moveTo(f+u/2,fe),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function fd(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;t.nodes.forEach(o=>{let s=n.get(o.name);if(o.order>=0&&s&&O(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function mn(e,t,n=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(n?i<t:i<=t)?r=l+1:o=l}let s=e[r];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function gn(e,t,n){let r=mn(e,t),o=mn(e,n,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function pd(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Ir=5,Zi=10,Ji=110,el=3;function tl(e){return e?"#b0b0b8":"#55555c"}function nl(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 vr(e){let t=[];for(let n of e)t.every(r=>Math.abs(n.at-r.at)>=(n.width+r.width)/2+Zi)&&t.push(n);return t.map(({text:n,at:r})=>({text:n,at:r}))}function ol(e,t,n,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=t(o.x0),l=t(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let c=nl(i/(l-a)*Ji),d=[],u=[];for(let f=Math.ceil(o.bp0/c)*c;f<=s.bp1;f+=c){let h=Math.round(t(mn(e,f)))+.5;if(h>=0&&h<=n){d.push(h);let p=f.toLocaleString("en-US");u.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:d,labels:vr(u)}}function rl(e,t,n,r){let o=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=n),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),c=[],d=[],u=[],f=[];for(let{box:p,s0:m,s1:g}of o){c.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=el&&d.push(Math.round(g)+.5);let b=l(xe(p.bp1-p.bp0),(m+g)/2);b.width<=g-m&&u.push(b),p!==s.box&&f.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:c,ticks:d,labels:vr([...h,...u,...f])}}function sl(e,t,n,r,o=!1){return(o?ol:rl)(e,t,n,r)}function hd(e,t,n,r,o=!1){let{x:s,width:a,darkMode:l}=n;e.font="10px sans-serif";let i=sl(t,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=tl(l),d=r+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:f}of i.spans)e.moveTo(Math.max(0,u),d),e.lineTo(Math.min(a,f),d);for(let u of i.ticks)e.moveTo(u,r),e.lineTo(u,r+Ir);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,r+Ir+2)}function bd(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach(o=>{let s=n.get(o.name);o.order>=0&&s&&O(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function xd(e,t,n,r){let o=[];for(let s of e){let a=n(s.x0),l=n(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:l})}return o}var al=3;function yd(e,t,n,r){if(t<=0||r<0||r>t)return;let o=r/t,s,a=al;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,c=l.top1+(l.bottom1-l.top1)*o,d=Math.max(0,Math.min(i,c)-n,n-Math.max(i,c));d<a&&(a=d,s=l.node)}return s}function Pr(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 Or(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function wd(e,t,n,{highlightNode:r,darkMode:o}){if(n<=0||t.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of t)Pr(e,l,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of t)Or(e,l,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(l=>l.node===r);a&&(e.beginPath(),Pr(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),Or(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function il(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach((o,s)=>{let a=n.get(o.name);if(o.order>=0&&a&&O(a)){let l=a.stable.start;r.push({bp0:l,bp1:l+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function ll(e,t,n){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=t?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function Ed(e,t,n){let r=il(e,t),o=[];for(let s of t.tracks){let a=s.name?n.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let c=ll(r,i.start,l);if(c){let{node:d,bp0:u,bp1:f}=c,h=p=>d.x+(Math.min(p,f)-u)/(f-u)*d.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(c.index),height:s.width})}}}}return o}function cl(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Sd(e,t,{x:n,y:r,width:o,darkMode:s}){if(t.length!==0){e.fillStyle=cl(s),e.beginPath();for(let a of t){let l=n(a.x0),i=Math.max(n(a.x1),l+1);if(i>=0&&l<=o){let c=r(a.y);e.rect(l,c,i-l,r(a.y+a.height)-c)}}e.fill()}}function ul(e,t){let n=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=t.nodeMap.get(v(o.nodeName)),l=a===void 0?void 0:t.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let c=e.path[i]?.y;if(l&&c!==void 0){let d={readId:e.id,y:c,height:e.width,nodeY:l.y},u=f=>Do(l,f);for(let f of o.mismatches){let h=u(f.pos);if(h!==null){if(f.type==="insertion"){let p=s===0&&f.pos===e.firstNodeOffset||s===r.length-1&&f.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:h,seq:f.seq,softClip:p})}else if(f.type==="deletion"&&f.length!==void 0){let p=u(f.pos+f.length);p!==null&&n.push({...d,kind:"deletion",x0:h,x1:p})}else if(f.type==="substitution"&&f.seq!==void 0){let p=u(f.pos+f.seq.length);p!==null&&n.push({...d,kind:"substitution",x0:h,x1:p,seq:f.seq})}}}}}),n}function kr(e){return e.reads.flatMap(t=>ul(t,e))}function Dr(e){let t=e.trim().split(/[\s,]+/),n=[],r=0,o=()=>Number(t[r++]);for(;r<t.length;){let s=t[r++];s==="M"||s==="L"?n.push({op:s,x:o(),y:o()}):s==="H"?n.push({op:s,x:o()}):s==="V"?n.push({op:s,y:o()}):s==="Q"?n.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?n.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&n.push({op:s})}return n}function qr(e){let t=1/0,n=-1/0;for(let r of e)"x"in r&&(t=Math.min(t,r.x),n=Math.max(n,r.x)),"x1"in r&&(t=Math.min(t,r.x1),n=Math.max(n,r.x1));return{x0:t,x1:n}}function Br(e,t,n,r){let o=Dr(e);return{commands:o,color:t,track:r,alpha:n,...qr(o)}}function $r(e,t){let{shapes:n}=e,r=l=>t==="haplotype"?l.id:void 0,o=[...n.rectangles,...n.verticalRectangles].filter(l=>l.type===t).map(l=>({color:l.color,track:r(l),alpha:l.alpha??1,x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),s=qo(n.curves,t).map(l=>Br(l.path,l.color,l.alpha??1,r(l))),a=n.corners.filter(l=>l.type===t).map(l=>Br(l.path,l.color,1,r(l)));return{rects:o,shapes:[...s,...a]}}function _d(e){let t=[];return e.nodes.forEach(n=>{if(n.order>=0){let r=Dr(Ho(n));t.push({name:n.name,commands:r,...qr(r)})}}),{bounds:e.bounds,layers:[$r(e,"haplotype"),$r(e,"read")],nodes:t,mismatches:kr(e).filter(n=>n.kind!=="insertion"||!n.softClip)}}function Gr(e,t,n,r){let o=0,s=0;for(let a of t)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(n(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(n(o),r(s));break;case"H":o=a.x,e.lineTo(n(o),r(s));break;case"V":s=a.y,e.lineTo(n(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),r(a.y1),n(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(n(a.x1),r(a.y1),n(a.x2),r(a.y2),n(o),r(s));break;case"Z":e.closePath();break}}function Fr(e,t,n,r,o){let s=new Map;for(let a of t)if(n(a)){let l=`${r(a)}|${a.alpha}`,i=s.get(l);i?i.push(a):s.set(l,[a])}for(let a of s.values()){e.fillStyle=r(a[0]),e.globalAlpha=a[0].alpha,e.beginPath();for(let l of a)o(l);e.fill()}e.globalAlpha=1}var dl=12,fl=.15;function pl(e){return Math.max(fl,Math.min(1,e/dl))}var hl=.55;function Id(e,t,n){let{x:r,y:o,width:s}=n,a=d=>r(d.x1)>=0&&r(d.x0)<=s,l=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;for(let d of t.layers)Fr(e,d.rects,a,l,u=>{let f=r(u.x0),h=o(u.y0);e.rect(f,h,r(u.x1)-f,o(u.y1)-h)}),Fr(e,d.shapes,a,l,u=>{Gr(e,u.commands,r,o)});let i=n.darkMode?"#d0d0d0":"#000000",c=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,n.yScale));for(let d of t.nodes)if(a(d)){let u=d.name===n.highlightNode;e.beginPath(),Gr(e,d.commands,r,o);let f=u?void 0:n.nodeColors?.get(d.name);e.fillStyle=u?"rgba(255,192,203,0.5)":f??c,e.strokeStyle=u?"#ff0000":i,e.globalAlpha=f?hl:1,e.fill(),e.globalAlpha=u?1:pl(r(d.x1)-r(d.x0)),e.stroke(),e.globalAlpha=1}bl(e,t.mismatches,n)}var Hr=12,ml=6;function gl(e){return Hr*e>=ml}function Wr(e,{x:t,width:n}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(o)>=0&&t(r)<=n}function bl(e,t,n){let{x:r,y:o,yScale:s,darkMode:a}=n;if(!gl(s)||t.length===0)return;let l=Hr*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&Wr(i,n)){let c=r(i.x0),d=o(i.y);e.rect(c,d,r(i.x1)-c,o(i.y+i.height)-d)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of t)Wr(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Od(e,t){let n=[];for(let r of t){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||n.push({gene:r,...gn(o,l,i),exons:r.exons.filter(c=>c.end>l&&c.start<i).map(c=>gn(o,Math.max(c.start,l),Math.min(c.end,i)))})}return n}var Xr=22,xl=4,Tt=8,yl="11px sans-serif",wl=8;function kd(e){let t=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),n=0,r=0;for(let{step:o}of t)n+=o,r=Math.max(r,n);return Math.min(xl,r)}function Bd(e,t,n,r,o=0){let{x:s,width:a,darkMode:l}=n,i=Math.max(1,Math.floor((r-o)/Xr)),c=[],d=l?"#e0e0e6":"#1c1c22";e.font=yl,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=t.map(f=>({g:f,s0:s(f.x0),s1:s(f.x1)})).filter(({s0:f,s1:h})=>h>=0&&f<=a).sort((f,h)=>f.s0-h.s0);for(let{g:f,s0:h,s1:p}of u){let m=f.gene.strand>0?" \u2192":f.gene.strand<0?"\u2190 ":"",g=f.gene.strand<0?`${m}${f.gene.name}`:`${f.gene.name}${m}`,b=(Math.max(h,0)+Math.min(p,a))/2,w=e.measureText(g).width/2,S=Math.min(h,b-w),E=Math.max(p,b+w),T=c.findIndex(N=>N+wl<=S);T===-1&&(T=Math.min(c.length,i-1)),c[T]=Math.max(c[T]??-1/0,E);let R=r-T*Xr-Tt/2;e.beginPath(),e.moveTo(h,R+.5),e.lineTo(p,R+.5),e.stroke();for(let N of f.exons){let I=s(N.x0);e.fillRect(I,R-Tt/2,Math.max(1,s(N.x1)-I),Tt)}e.fillText(g,b,R-Tt/2-2)}}function Ml(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function Rl(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0)),s=Array.from({length:n+1},()=>new Array(r+1).fill(!1));for(let l=n-1;l>=0;l--)for(let i=r-1;i>=0;i--){let c=Math.abs(e[l]-t[i])+o[l+1][i+1],d=n-l>r-i?o[l+1][i]:1/0,u=r-i>n-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,d,u),s[l][i]=o[l][i]===c}let a=new Array(n).fill(void 0);for(let l=0,i=0;l<n&&i<r;)s[l][i]?a[l++]=i++:n-l>r-i?l++:i++;return a}function Yr(e,t){return e.map((n,r)=>({item:n,i:r})).sort((n,r)=>t(n.item)-t(r.item))}var Kr=e=>e.spanningReads!==0;function zr(e,t){return{...t,agrees:e.complete&&Kr(t)?Ml(e.bp,t.bp):void 0}}function El(e,t){let n=new Map,r=new Set;e.forEach((l,i)=>{let c=t.find(d=>d.haplotype!==void 0&&d.haplotype===l.haplotype);c&&(r.add(c),n.set(i,zr(l,c)))});let o=t.filter(l=>l.haplotype===void 0),s=Yr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Kr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!n.has(u.i)),d=Yr(i.filter(u=>!r.has(u)),u=>u.bp);Rl(c.map(u=>u.item.bp),d.map(u=>u.item.bp)).forEach((u,f)=>{if(u!==void 0){let h=c[f],p=d[u].item;r.add(p),n.set(h.i,zr(h.item,p))}})}return n}function Gd(e,t){if(!t)return e;let n=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=t[o];if(a)for(let[l,i]of El(s,a))n.set(s[l],i)}return e.map(o=>({...o,call:n.get(o)}))}var jr=Y(it(),1),Dd=(0,ne.createSvgIcon)((0,jr.jsx)("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");export{ne as a,qs as b,Oe as c,Ve as d,is as e,ta as f,Kt as g,Ys as h,zs as i,Va as j,Vo as k,ui as l,cn as m,cu as n,uu as o,fi as p,Ee as q,pu as r,hu as s,mu as t,gu as u,xu as v,yu as w,wu as x,yi as y,Zr as z,Wn as A,os as B,rs as C,Cl as D,Yn as E,Ft as F,Dt as G,Hl as H,qt as I,Ht as J,Xl as K,Kl as L,St as M,nt as N,ir as O,Mi as P,Cu as Q,Au as R,_u as S,_i as T,Iu as U,vu as V,cr as W,fr as X,ki as Y,wr as Z,Fu as _,Wu as $,Di as aa,qi as ba,Du as ca,Er as da,Xu as ea,Yu as fa,Qu as ga,Zu as ha,Ju as ia,ed as ja,td as ka,ji as la,sd as ma,Vi as na,ad as oa,id as pa,ld as qa,fd as ra,pd as sa,tl as ta,hd as ua,bd as va,xd as wa,yd as xa,wd as ya,Ed as za,cl as Aa,Sd as Ba,_d as Ca,Id as Da,gl as Ea,Wr as Fa,Od as Ga,Xr as Ha,kd as Ia,Bd as Ja,Gd as Ka,Ql as La,Zl as Ma,Gs as Na,Jl as Oa,ec as Pa,Yt as Qa,zt as Ra,fc as Sa,pc as Ta,Dd as Ua};
|
|
2
|
+
//# sourceMappingURL=chunk-PPYB6N2Q.js.map
|