jbrowse-plugin-graphgenomeviewer 4.0.13 → 4.0.15

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.
Files changed (53) hide show
  1. package/README.md +5 -1
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-Y5NBXK7P.js → GbzBaseSyntenyAdapter-3ZTHTTHA.js} +2 -2
  3. package/dist/chunks/{GraphGenomeView-TTQEJJQD.js → GraphGenomeView-5SMMNFD4.js} +2 -2
  4. package/dist/chunks/{GraphTrackSettingsDialog-3A2PKZRI.js → GraphTrackSettingsDialog-2QV6TPX7.js} +2 -2
  5. package/dist/chunks/{LinearGraphDisplay-MJ5XZFE5.js → LinearGraphDisplay-BEOEIUGA.js} +2 -2
  6. package/dist/chunks/{MinigraphBubbleAdapter-APC7JYOM.js → MinigraphBubbleAdapter-NRDD66AK.js} +2 -2
  7. package/dist/chunks/{RgfaTabixAdapter-4E365PXO.js → RgfaTabixAdapter-NQEERXXI.js} +2 -2
  8. package/dist/chunks/{chunk-5DP7IXD3.js → chunk-33VHHB43.js} +2 -2
  9. package/dist/chunks/{chunk-LA7MQS33.js → chunk-5E7TVPCI.js} +2 -2
  10. package/dist/chunks/chunk-IUIIYSGF.js +2 -0
  11. package/dist/chunks/{chunk-M4YEAXSR.js.map → chunk-IUIIYSGF.js.map} +3 -3
  12. package/dist/chunks/chunk-JXAJ7YLT.js +2 -0
  13. package/dist/chunks/chunk-JXAJ7YLT.js.map +7 -0
  14. package/dist/chunks/chunk-KULNKXPT.js +2 -0
  15. package/dist/chunks/chunk-KULNKXPT.js.map +7 -0
  16. package/dist/chunks/chunk-QSH263Y6.js +2 -0
  17. package/dist/chunks/chunk-QSH263Y6.js.map +7 -0
  18. package/dist/chunks/chunk-UQEPPJEO.js +2 -0
  19. package/dist/chunks/{chunk-VAGPKHHS.js.map → chunk-UQEPPJEO.js.map} +3 -3
  20. package/dist/chunks/chunk-UQN2NWT5.js +4 -0
  21. package/dist/chunks/chunk-UQN2NWT5.js.map +7 -0
  22. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
  23. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
  24. package/package.json +2 -2
  25. package/src/GraphGenomeView/components/BubbleHalos.tsx +67 -3
  26. package/src/GraphGenomeView/components/BubbleOverlay.tsx +10 -0
  27. package/src/GraphGenomeView/components/GraphCanvas.tsx +46 -9
  28. package/src/GraphGenomeView/components/LabelChip.tsx +9 -1
  29. package/src/GraphGenomeView/components/LabelLayer.tsx +7 -0
  30. package/src/GraphGenomeView/components/ReferenceStripOverlay.tsx +116 -0
  31. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +109 -41
  32. package/src/GraphGenomeView/model.test.ts +3 -0
  33. package/src/GraphGenomeView/model.ts +204 -43
  34. package/src/LinearGraphDisplay/model.ts +2 -0
  35. package/src/version.ts +1 -1
  36. package/dist/chunks/chunk-CJ56O2VG.js +0 -2
  37. package/dist/chunks/chunk-CJ56O2VG.js.map +0 -7
  38. package/dist/chunks/chunk-IFRDWMQ2.js +0 -2
  39. package/dist/chunks/chunk-IFRDWMQ2.js.map +0 -7
  40. package/dist/chunks/chunk-M4YEAXSR.js +0 -2
  41. package/dist/chunks/chunk-MUK3KYB4.js +0 -2
  42. package/dist/chunks/chunk-MUK3KYB4.js.map +0 -7
  43. package/dist/chunks/chunk-VAGPKHHS.js +0 -2
  44. package/dist/chunks/chunk-XDOIZTY6.js +0 -4
  45. package/dist/chunks/chunk-XDOIZTY6.js.map +0 -7
  46. /package/dist/chunks/{GbzBaseSyntenyAdapter-Y5NBXK7P.js.map → GbzBaseSyntenyAdapter-3ZTHTTHA.js.map} +0 -0
  47. /package/dist/chunks/{GraphGenomeView-TTQEJJQD.js.map → GraphGenomeView-5SMMNFD4.js.map} +0 -0
  48. /package/dist/chunks/{GraphTrackSettingsDialog-3A2PKZRI.js.map → GraphTrackSettingsDialog-2QV6TPX7.js.map} +0 -0
  49. /package/dist/chunks/{LinearGraphDisplay-MJ5XZFE5.js.map → LinearGraphDisplay-BEOEIUGA.js.map} +0 -0
  50. /package/dist/chunks/{MinigraphBubbleAdapter-APC7JYOM.js.map → MinigraphBubbleAdapter-NRDD66AK.js.map} +0 -0
  51. /package/dist/chunks/{RgfaTabixAdapter-4E365PXO.js.map → RgfaTabixAdapter-NQEERXXI.js.map} +0 -0
  52. /package/dist/chunks/{chunk-5DP7IXD3.js.map → chunk-33VHHB43.js.map} +0 -0
  53. /package/dist/chunks/{chunk-LA7MQS33.js.map → chunk-5E7TVPCI.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["global-externals:tss-react/mui", "../../packages/core/src/layout/drawnScale.ts", "../../packages/core/src/bubbleSpreads.ts", "../../packages/core/src/colorSchemes.ts", "../../packages/core/src/pathAnchoring.ts", "../../packages/core/src/pathColors.ts", "../../packages/core/src/nodeWidths.ts"],
4
- "sourcesContent": ["module.exports = JBrowseExports[\"tss-react/mui\"];", "import type { Graph, GraphNode } from '../types'\n\nexport interface BandageScaleOpts {\n nodeLengthPerMegabase: number\n minimumNodeLength: number\n nodeSegmentLength: number\n edgeLength: number\n}\n\n// Node drawn length, in FMMM units, as a function of bp. Used both by the layouts\n// that run here and by the options handed to the WASM engine, so a graph is drawn\n// at the same scale whichever one draws it. Bandage's own auto rule\n// (`AssemblyGraph::determineGraphInfo`):\n// pick units-per-megabase so the *mean* drawn node length lands on 40, with a\n// floor on total drawn length so a small graph doesn't collapse to a speck.\n//\n// This has to be derived per graph, not fixed. The scale that suits a bacterial\n// assembly's 10-100 kb contigs is wrong by orders of magnitude for a minigraph\n// pangenome window, whose nodes run 300 bp to a few kb: a fixed 1000 units/Mbp\n// makes every node shorter than the edges between them and the graph reads as\n// beads on a string, while 1 unit/bp makes each node a long sweeping curve and\n// the graph sprawls. For the 53-node E. coli window this lands near 35,000.\n//\n// It matters most at the small end. The WASM wrapper's own default of 1000\n// units/Mbp puts *every* node in a 400 bp pggb window below minimumNodeLength,\n// so all 31 clamp to the floor and a 1 bp SNP allele draws the same size as the\n// 164 bp backbone segment beside it \u2014 which is what made that figure read as a\n// chain of same-sized two-node bubbles. Bandage draws the same file with a 75:1\n// length ratio, the SNP alleles as specks.\n//\n// The remaining three are upstream Bandage's shipped defaults\n// (`program/settings.cpp`), which the WASM wrapper's own header does not match \u2014\n// it defaults all of them to 1.0, so they have to be passed explicitly.\nconst MEAN_NODE_LENGTH = 40\nconst MIN_TOTAL_GRAPH_LENGTH = 500\n\n// Bandage's own floor on a node's drawn length. Right for an assembly graph,\n// whose nodes are kb to Mb, and the reason a variation graph draws as a rope:\n// see BUBBLE_SPREADS, which is how a view asks for more.\nconst BANDAGE_MINIMUM_NODE_LENGTH = 5\n\n// The engine's own rule (`settings.h`, `getDrawnNodeLength`), so a seed computed\n// here spans exactly the chain the engine builds from the same numbers.\nexport function drawnNodeLength(opts: BandageScaleOpts, length: number) {\n return Math.max(\n (opts.nodeLengthPerMegabase * length) / 1_000_000,\n opts.minimumNodeLength,\n )\n}\n\nexport function bandageAutoScale(\n graph: Graph,\n // Floor on a node's drawn length, in the same FMMM units as the scale below.\n // Anything at or under Bandage's own floor leaves the drawing exactly as it\n // was, which is what keeps `'auto'` byte-identical to the shipped behaviour.\n minNodeLength = BANDAGE_MINIMUM_NODE_LENGTH,\n): BandageScaleOpts {\n const totalLength = graph.nodes.reduce((sum, n) => sum + n.length, 0)\n const megabases = totalLength / 1_000_000\n const target = Math.max(\n graph.nodes.length * MEAN_NODE_LENGTH,\n MIN_TOTAL_GRAPH_LENGTH,\n )\n return {\n nodeLengthPerMegabase: megabases > 0 ? target / megabases : 10_000,\n minimumNodeLength: Math.max(BANDAGE_MINIMUM_NODE_LENGTH, minNodeLength),\n edgeLength: 5,\n nodeSegmentLength: 20,\n }\n}\n\n// How a node's bp becomes its drawn length, as a power law against the graph's\n// own mean. The idiom is Bandage's, moved onto the axis a pangenome needs it on:\n// upstream derives a node's *width* from its depth exactly this way\n// (`graph/graphicsitemnode.cpp`, `getNodeWidth`), at a `depthPower` of 0.5 and a\n// `depthEffectOnWidth` of 0.5, because depth in an assembly graph spans orders\n// of magnitude and drawing it linearly is unreadable.\n//\n// drawn = meanDrawn * (((bp / meanBp) ^ power - 1) * effect + 1)\n//\n// Length in a *variation* graph spans those same orders of magnitude \u2014 a 1 bp\n// allele beside a 16 kb backbone segment \u2014 and upstream still maps it linearly,\n// because its own nodes are assembled contigs where that range does not arise.\n// That linear map is what draws a pggb window as one rope: past the small end\n// every allele falls under `minimumNodeLength` and clamps, so both arms of a\n// bubble land inside one node thickness of each other.\n//\n// power 1 with effect 1 is exactly proportional, so Bandage's shipped behaviour\n// is a point in this family rather than a mechanism sitting beside it. See\n// BUBBLE_SPREADS for the points a view can ask for.\nexport interface DrawnLengthLaw {\n // exponent applied to a node's length relative to the graph's mean\n power: number\n // how much of that relative length survives. 0 draws every node at the mean,\n // 1 applies the power law undamped.\n effect: number\n}\n\nexport const PROPORTIONAL_LENGTH: DrawnLengthLaw = { power: 1, effect: 1 }\n\nexport function isProportional(law: DrawnLengthLaw) {\n return law.power === 1 && law.effect === 1\n}\n\n// Drawn length in FMMM units for one node of `graph`, under `law`.\nexport function drawnLengthFor(graph: Graph, law: DrawnLengthLaw) {\n const count = graph.nodes.length\n const totalLength = graph.nodes.reduce((sum, n) => sum + n.length, 0)\n const meanBp = count > 0 ? totalLength / count : 0\n // The mean drawn length `bandageAutoScale` already targets, small-graph floor\n // included, so a compressed drawing comes out the same overall size as the\n // proportional one it replaces. That is the property a per-node floor does\n // not have, and the reason raising one is unusable at scale: it lifts the\n // hundreds of non-branching chain nodes along with the alleles, which on a\n // 521-node cut inflates the drawing past what zoom-to-fit can frame.\n const meanDrawn =\n count > 0\n ? Math.max(count * MEAN_NODE_LENGTH, MIN_TOTAL_GRAPH_LENGTH) / count\n : MEAN_NODE_LENGTH\n return (bp: number) => {\n if (meanBp <= 0) {\n return meanDrawn\n }\n const relative = (bp / meanBp) ** law.power\n return Math.max(\n meanDrawn * ((relative - 1) * law.effect + 1),\n BANDAGE_MINIMUM_NODE_LENGTH,\n )\n }\n}\n\n// The engine's own length rule is linear with a floor and takes two numbers\n// (`settings.h`, `getDrawnNodeLength`), so a non-linear law cannot be expressed\n// through them. It can be expressed in the lengths themselves: node length\n// crosses the RPC boundary only to become a drawn length \u2014 `getLength()` has\n// exactly two call sites upstream, both inside that rule \u2014 so handing the engine\n// pre-transformed lengths and a 1:1 scale draws the law without touching the\n// WASM build. Scaled by this factor first because the binding reads a node's\n// length as an `unsigned`, and rounding drawn units straight to integers would\n// quantise the small end where the whole point is legibility.\nconst LAYOUT_LENGTH_PRECISION = 1000\n\n// How a view asks for its node lengths: a law, plus Bandage's own per-node\n// floor. Orthogonal on purpose \u2014 see BUBBLE_SPREADS for which does what.\nexport interface NodeLengthSpread {\n law: DrawnLengthLaw\n // in the same FMMM units as the drawn lengths. At or under Bandage's own\n // floor this leaves the drawing exactly as it was.\n minNodeLength: number\n}\n\nexport const PROPORTIONAL_SPREAD: NodeLengthSpread = {\n law: PROPORTIONAL_LENGTH,\n minNodeLength: 0,\n}\n\nexport interface LayoutScaling {\n // the nodes to hand the engine. Under any law but the proportional one their\n // `length` is a scaled drawn length rather than a bp count, which is why this\n // is a separate array and never the graph's own nodes.\n nodes: GraphNode[]\n opts: BandageScaleOpts\n}\n\nexport function layoutScaling(\n graph: Graph,\n spread: NodeLengthSpread = PROPORTIONAL_SPREAD,\n): LayoutScaling {\n const { law, minNodeLength } = spread\n const opts = bandageAutoScale(graph, minNodeLength)\n // The proportional law is what every committed force figure was drawn\n // against, and it is already exactly what `bandageAutoScale` expresses, so it\n // keeps the untransformed path rather than round-tripping through a rounding\n // step FMMM would be free to amplify. Every floor-based spread comes through\n // here too, unchanged.\n if (isProportional(law)) {\n return { nodes: graph.nodes, opts }\n }\n const drawn = drawnLengthFor(graph, law)\n return {\n nodes: graph.nodes.map(node => ({\n ...node,\n length: Math.round(drawn(node.length) * LAYOUT_LENGTH_PRECISION),\n })),\n opts: {\n ...opts,\n nodeLengthPerMegabase: 1_000_000 / LAYOUT_LENGTH_PRECISION,\n // Bandage's own floor only. A law and a raised floor are alternatives\n // rather than a stack: the law has already lifted the small end, and a\n // floor on top of it would flatten exactly what it just spread.\n minimumNodeLength: BANDAGE_MINIMUM_NODE_LENGTH,\n },\n }\n}\n\n// The mean drawn node length `bandageAutoScale` targets, exported so\n// BUBBLE_SPREADS can state its laws against it rather than against unanchored\n// constants.\nexport { MEAN_NODE_LENGTH }\n", "import { MEAN_NODE_LENGTH, PROPORTIONAL_LENGTH } from './layout/drawnScale'\n\nimport type { NodeLengthSpread } from './layout/drawnScale'\n\n// How far apart the force layout draws the two arms of a bubble, as the law\n// turning a node's bp into its drawn length. One table drives the persisted\n// enum, the dropdown and the value handed to the engine, the same way\n// LAYOUT_MODES and COLOR_SCHEMES do.\n//\n// Why this needs to be a control rather than a better default: the drawn-length\n// law is the one thing standing between a variation graph and a legible force\n// layout, and compressing it costs the property that node length is proportional\n// to bp. Bandage maps length linearly, which suits an assembly graph whose nodes\n// are kb to Mb. In a pangenome an allele is 1-50 bp against a backbone segment\n// of several kb, so on that map every alt clamps to the engine's 5-unit floor,\n// both arms of a bubble land inside one node thickness of each other, and FMMM\n// has nothing to spread \u2014 zoom-to-fit then delivers a single rope with the\n// variation invisible inside it. Compressing the law opens the bubbles and\n// flattens the length ratio, and which of those a reader wants depends on the\n// figure, so the view asks rather than assumes.\n//\n// The compression is Bandage's own, taken off the axis upstream uses it on: it\n// draws node *width* from depth as a power law against the mean, at power 0.5\n// and effect 0.5, for the same reason. 'open' is those two numbers. See\n// DrawnLengthLaw.\n//\n// Measured on an odgi extract of GRCh38#0#chrM:8,200-8,400 from HPRC release 2's\n// chrM pggb graph (61 nodes, 84 edges, 234 haplotype paths), fitted to a 900x560\n// pane: proportional is one squiggle with a single knot in it, and the bubbles\n// come apart into legible lenses once the law compresses.\n//\n// The floor and the law are different instruments and both are kept, because\n// neither does the other's job:\n//\n// - a FLOOR lifts the small end and leaves everything above it proportional. It\n// is what a figure wants when one long node has to stay long \u2014 the ribbons in\n// `pangenome/pggb_haplotype_paths` separate along a 1.2 kb deletion arc, and\n// shortening that arc towards the mean piles them up. Its cost is that it is a\n// per-node minimum, so it lifts a graph's non-branching chain nodes along with\n// its alleles and the drawing inflates with node count: on the 521-node pggb\n// cut in `pangenome/graph_resolution` it reached ~52,000 units and a 1.4% fit,\n// which is why that figure could once afford a spread on its 7-node half only.\n// - the LAW compresses both ends towards the mean, so the drawing stays the size\n// it already was whatever the node count, and a cut spanning 6 bp to 16 kb\n// fits one pane. Its cost is the top end: a node that has to read as long no\n// longer does.\n//\n// So a figure about bubble shape at scale takes 'compress', and a figure about\n// what is drawn along one long edge takes 'open'.\n//\n// 'auto' is the proportional map, unchanged, so every existing figure and the\n// `bandageAutoScale` length-proportionality test are untouched by this existing.\nexport const BUBBLE_SPREADS = [\n {\n value: 'auto',\n label: 'Proportional',\n description:\n \"Bandage's own scale: a node draws proportional to its length, so a 1 bp allele is a speck.\",\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 0,\n },\n {\n value: 'open',\n label: 'Open bubbles',\n description:\n 'Give every allele a drawn length, so a bubble reads as two arms rather than a knot.',\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 2.5,\n },\n {\n value: 'wide',\n label: 'Wide bubbles',\n description:\n 'As open, spread further. Best on a window of a dozen bubbles.',\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 10,\n },\n {\n value: 'compress',\n label: 'Compress lengths',\n description:\n 'Pull the longest and shortest nodes towards the graph\\u2019s mean, so a cut spanning kb and bp fits one pane.',\n law: { power: 0.5, effect: 0.5 },\n minNodeFactor: 0,\n },\n] as const\n\nexport type BubbleSpread = (typeof BUBBLE_SPREADS)[number]['value']\n\nexport const BUBBLE_SPREAD_VALUES = BUBBLE_SPREADS.map(s => s.value)\n\n// The law and floor behind a spread, resolved so the model has one place that\n// knows how a spread becomes numbers. An unknown value draws proportionally\n// rather than throwing, which is what a session persisted by a newer build\n// degrades to.\nexport function spreadFor(spread: string): NodeLengthSpread {\n const entry = BUBBLE_SPREADS.find(s => s.value === spread)\n return {\n law: entry?.law ?? PROPORTIONAL_LENGTH,\n minNodeLength: (entry?.minNodeFactor ?? 0) * MEAN_NODE_LENGTH,\n }\n}\n", "import type { Graph } from './types'\n\n// One table drives the persisted enum and both colour dropdowns, the same way\n// LAYOUT_MODES drives the layout enum and its menu. The values and their labels\n// used to live in two lists in two directories, so adding a scheme meant editing\n// both and a mismatch showed up as a dropdown entry that selected nothing.\n//\n// Kept out of the components directory because the model needs it too.\nexport const COLOR_SCHEMES = [\n // Mirrors `layoutModes`' 'auto': a value the model resolves rather than a\n // colour of its own. It exists because 'uniform' was the default, so a\n // launched graph opened flat grey and both tutorials spent a step saying \"now\n // pick a colour\" \u2014 one figure literally drives that click. A graph with\n // reference coordinates resolves to 'reference-position', which is the one\n // ramp a linear track beside it can be painted with too; a graph with none\n // keeps 'uniform', because there the ramp would be a hue nothing earned.\n //\n // Resolve through `effectiveColorScheme`; the dropdown reads the raw prop, so\n // \"Auto\" stays selectable and visible as what it is.\n { value: 'auto', label: 'Auto' },\n { value: 'uniform', label: 'Uniform' },\n { value: 'random', label: 'Random' },\n { value: 'rainbow', label: 'Rainbow' },\n { value: 'depth', label: 'Depth' },\n { value: 'node-length', label: 'Node Length' },\n { value: 'stable-rank', label: 'Stable rank' },\n { value: 'reference-position', label: 'Reference position' },\n { value: 'grey', label: 'Grey' },\n] as const\n\nexport type ColorScheme = (typeof COLOR_SCHEMES)[number]['value']\n\n// What the renderer can actually paint with: every scheme except the one that\n// stands for \"work it out\". Stated as its own type so `getNodeColor`'s switch\n// has no 'auto' arm to forget.\nexport type ResolvedColorScheme = Exclude<ColorScheme, 'auto'>\n\nexport const COLOR_SCHEME_VALUES = COLOR_SCHEMES.map(s => s.value)\n\n// 'auto' asks the GRAPH, not the layout: a hue along the reference means\n// something whenever the segments have reference coordinates, force-directed\n// drawings included.\nexport function resolveColorScheme(\n scheme: ColorScheme,\n graph: Graph | undefined,\n): ResolvedColorScheme {\n return scheme !== 'auto'\n ? scheme\n : graph?.anchoredBy\n ? 'reference-position'\n : 'uniform'\n}\n", "import { REFERENCE_RANK } from './anchoredNodes'\nimport { panSNSample } from './pansn'\n\nimport type { Graph, GraphNode, PathOrigin, PathVisit } from './types'\n\n// Reference coordinates for a GFA that tags none of its segments with one.\n//\n// rGFA writes the fact per segment (SN/SO/SR). A pggb / odgi / Minigraph-Cactus\n// graph writes the same fact once per path and leaves the arithmetic to the\n// reader: walking a path's steps in order, accumulating segment lengths,\n// assigns every segment that path visits an interval on the path's own\n// sequence. Same information, different encoding \u2014 so a general GFA is not a\n// degraded rGFA, and the anchored layouts work on it once the walk is done.\n//\n// It carries one thing rGFA cannot: a segment's *carriage*, the set of\n// assemblies that actually traverse it. rGFA's SR is build order, so there the\n// most a segment can say is which assembly first contributed it.\n\n// `odgi extract` names an extracted path for the interval it covers on its own\n// sequence: `K12#1#chr:1004500-1004961`. That suffix is the only place a cut\n// subgraph states where in the genome it sits, so it is split off here rather\n// than carried around as part of the name \u2014 no assembly has a sequence called\n// `K12#1#chr:1004500-1004961`, and PanSN parsing of it yields a contig no\n// linear view can open.\n//\n// Anchored on the digits rather than on a trailing colon, because a stable name\n// may legitimately contain one (the same hazard gfaParser's tag splitting has).\nconst RANGE_SUFFIX = /:(\\d+)-\\d+$/\n\nexport function pathOrigin(pathName: string) {\n const match = RANGE_SUFFIX.exec(pathName)\n return match\n ? { name: pathName.slice(0, match.index), start: +match[1]! }\n : { name: pathName, start: 0 }\n}\n\nexport interface PathSteps {\n name: string\n start: number\n steps: { id: string; strand: '+' | '-' }[]\n}\n\n// The single walk. Every segment visit lands in `pathVisits` at the bp its own\n// path reaches it at; `anchorPaths` is what the walk learned about the paths\n// themselves, which is what a reference-path picker lists.\nexport function surveyPaths(\n paths: PathSteps[],\n lengthOf: (segmentId: string) => number,\n) {\n const anchorPaths: PathOrigin[] = []\n const pathVisits = new Map<string, PathVisit[]>()\n for (const path of paths) {\n const sample = panSNSample(path.name)\n let pos = path.start\n for (const step of path.steps) {\n const visit = {\n path: path.name,\n sample,\n start: pos,\n strand: step.strand,\n }\n const existing = pathVisits.get(step.id)\n if (existing) {\n existing.push(visit)\n } else {\n pathVisits.set(step.id, [visit])\n }\n pos += lengthOf(step.id)\n }\n anchorPaths.push({\n name: path.name,\n sample,\n start: path.start,\n length: pos - path.start,\n })\n }\n return { anchorPaths, pathVisits }\n}\n\n// Which path x is drawn on. This is a choice, not a fact: a general GFA's path\n// names are arbitrary and nothing in the file marks one of them as the\n// reference, so a preference is matched against a path's PanSN sample name (the\n// assembly a subgraph was cut against, which is how the launch path knows) and\n// then against its full name. With no preference the first path in the file\n// wins, which is where pggb and odgi leave the reference.\nexport function chooseReferencePath(\n anchorPaths: PathOrigin[],\n preferred: string | undefined,\n) {\n const named = anchorPaths.find(\n p => p.sample === preferred || p.name === preferred,\n )\n return named ?? anchorPaths[0]\n}\n\n// Rank on a path-derived graph is the one distinction the paths support: on the\n// reference path or off it. rGFA's higher ranks are minigraph's build order,\n// which a path GFA has no equivalent of, so drawing more rows than this would\n// be drawing structure the file does not state.\nconst OFF_REFERENCE_RANK = 1\n\n// A segment the reference path visits sits on the backbone at the offset that\n// visit reaches it. One it never visits is an alternate allele, placed on the\n// coordinates of the first path that does carry it \u2014 the same asymmetry rGFA\n// has, where a rank>0 segment's SO is an offset on the assembly that\n// contributed the sequence rather than on the reference.\n//\n// **First visit wins** when a path reaches the same segment more than once, and\n// collapsed repeats make that real rather than hypothetical: pggb folds the\n// E. coli rRNA operons into shared segments, so every strain's path walks them\n// twice (`odgi depth` reaches 10 over a five-strain graph at chr:4,167,000 and\n// chr:3,942,000). A node draws as one tube at one x, so the alternative to\n// picking a copy is one tube spanning both, claiming reference the segment does\n// not occupy. The repeat stays visible as depth: such a node's traversal count\n// is a multiple of the path count.\nfunction anchorNode(\n node: GraphNode,\n visits: PathVisit[] | undefined,\n reference: string,\n): GraphNode {\n let anchored = node\n if (visits && visits.length > 0) {\n const anchor = visits.find(v => v.path === reference) ?? visits[0]!\n anchored = {\n ...node,\n stable: {\n refName: anchor.path,\n start: anchor.start,\n rank: anchor.path === reference ? REFERENCE_RANK : OFF_REFERENCE_RANK,\n strand: anchor.strand,\n },\n samples: [...new Set(visits.map(v => v.sample))].sort(),\n }\n }\n return anchored\n}\n\n// Re-runnable against a different reference path at no parsing cost, which is\n// what the picker needs: the walk is already recorded in `pathVisits`, and only\n// which path counts as rank 0 changes.\nexport function anchorFromPaths(graph: Graph, preferred: string | undefined) {\n const { anchorPaths, pathVisits } = graph\n const reference =\n anchorPaths && pathVisits\n ? chooseReferencePath(anchorPaths, preferred)\n : undefined\n return reference && pathVisits\n ? ({\n ...graph,\n nodes: graph.nodes.map(node =>\n anchorNode(node, pathVisits.get(node.name), reference.name),\n ),\n anchoredBy: 'paths',\n referencePath: reference.name,\n } satisfies Graph)\n : graph\n}\n\n// rGFA states coordinates on every segment, so only a graph that states none\n// has to derive them. A GFA with neither tags nor paths comes back untouched\n// and falls through to the force layout, which is the honest answer for it.\nexport function anchorGraph(graph: Graph, preferred: string | undefined) {\n return graph.anchoredBy === 'tags' ? graph : anchorFromPaths(graph, preferred)\n}\n", "import { pathOrigin } from './pathAnchoring'\n\nimport type { GraphPath } from './types'\n\n// Deterministic colour from a string (djb2-style hash to an HSL hue). Fine for\n// the `random` node scheme, where a collision between two of thousands of nodes\n// means nothing. NOT what the path ribbons use: see pathHueAt.\nexport function nameHue(name: string) {\n let hash = 0\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash)\n }\n return Math.abs(hash % 360)\n}\n\n// Ribbon hues are spread evenly over the wheel by position in the path list,\n// not hashed from the path name. A hash draws from the wheel at random, and at\n// five paths two of them landing on the same hue is common rather than\n// unlucky: `Sakai#1#chr:1983339-1983535` and `NCTC86#1#chr:1709109-1710286`\n// hash 26 degrees apart, which is two purples and a legend that cannot be read\n// off the drawing. Evenly spaced, the worst case is the best available.\n//\n// The cost is that a path's colour depends on how many paths there are, so it\n// moves when the cut changes. That is what the legend is for, and it is the\n// same trade the Bandage demo this was ported from made.\nexport function pathHueAt(index: number, count: number) {\n return (index * 360) / count\n}\n\nexport const PATH_SATURATION = 0.7\nexport const PATH_LIGHTNESS = 0.5\n\n// Past this many paths a graph cannot be drawn per path at all, and the WHOLE\n// of `drawPaths` goes off with it: the node stripes, the edge ribbons and the\n// key naming them.\n//\n// One number for all three because they are one statement, and they used to\n// disagree. Only the stripes were capped. So a Minigraph-Cactus cut, which\n// writes one W record per haplotype and walks every backbone link with all of\n// them, drew: no stripes at all, a key hundreds of rows tall, and one bezier\n// stroke per path per edge \u2014 measured at 99,800 strokes and 64 ms of geometry\n// for 200 paths over 499 links, against 2,495 strokes for the five-path pggb\n// cut the figures use. Every one of those is its own `beginPath`/`stroke` on\n// the Canvas2D backend, every frame.\n//\n// 16 is where the drawing stops SAYING anything, not where it stops being fast.\n// `pathHueAt` spreads the wheel evenly, so 16 hues are 22 degrees apart and\n// still tellable and 200 are one degree; the ribbon fan is PATH_RIBBON_SPACING\n// per path, so 16 of them is a legible fan and 200 is a band wider than the\n// nodes; and a key past about 16 rows is taller than the drawing beside it.\n// Above the cap the honest picture is the plain one \u2014 which is exactly what a\n// graph carrying no paths at all already draws.\nexport const MAX_PATH_COLORS = 16\n\n// Whether this graph's paths can be drawn as colours. Resolve it once and hand\n// the answer down: the geometry, the hit index and the key each used to decide\n// for themselves, which is how they came to disagree.\nexport function pathColorsLegible(pathCount: number) {\n return pathCount > 0 && pathCount <= MAX_PATH_COLORS\n}\n\nexport function pathCssColor(index: number, count: number) {\n return `hsl(${pathHueAt(index, count)}, ${PATH_SATURATION * 100}%, ${\n PATH_LIGHTNESS * 100\n }%)`\n}\n\n// A path is named the way its file names it \u2014 `K12#1#chr:1004500-1004961` for a\n// P record `odgi extract` wrote, `HG00738#1` for a W record \u2014 and neither is a\n// legend entry. The label is the least of that name which still tells the paths\n// apart: the sample where samples are unique, the haplotype too where they are\n// not, the whole stable name where even that repeats. Widening it for every row\n// rather than only for the colliding ones, because a legend where one entry is\n// `HG00738#1` and its neighbour is `HG01071` reads as two kinds of thing.\nfunction labelTiers(name: string) {\n const parts = pathOrigin(name).name.split('#')\n return [parts[0]!, parts.slice(0, 2).join('#'), parts.join('#')]\n}\n\n// Locale-independent, unlike toLocaleString: a figure regenerated on a machine\n// with a different locale would otherwise differ from the committed one.\nfunction groupDigits(n: number) {\n return String(n).replace(/\\B(?=(\\d{3})+$)/g, ',')\n}\n\n// A collapsed repeat puts one sequence through the same segments more than\n// once, and `odgi extract` emits one path per visit \u2014 nine visits over five\n// E. coli chromosomes at the rRNA operons, where every name tier above collides\n// because the sequence really is the same one. What separates those is the\n// offset each name carried, which is the one thing pathOrigin strips off.\nfunction offsetTiers(name: string, tiers: string[]) {\n const { start } = pathOrigin(name)\n return tiers.map(t => `${t} @${groupDigits(start)}`)\n}\n\nexport interface PathLegendEntry {\n name: string\n label: string\n color: string\n}\n\nexport function pathLegend(paths: GraphPath[]): PathLegendEntry[] {\n const named = paths.map(p => labelTiers(p.name))\n // narrowest first, and the offset is tried before the next name tier: two\n // copies of one operon are told apart by where they are, not by widening a\n // name that is genuinely identical\n const candidates = [0, 1, 2].flatMap(t => [\n paths.map((_, i) => named[i]![t]!),\n paths.map((p, i) => offsetTiers(p.name, named[i]!)[t]!),\n ])\n const distinct = candidates.find(\n labels => new Set(labels).size === paths.length,\n )\n // Nothing separates two paths with the same name and the same offset, so the\n // widest labelling is as close as any can get.\n const labels = distinct ?? candidates.at(-1)!\n return paths.map((path, i) => ({\n name: path.name,\n label: labels[i]!,\n color: pathCssColor(i, paths.length),\n }))\n}\n", "import type { Graph, GraphNode } from './types'\nimport type { NodeInk } from './util/hitDetection'\n\n// How thick a node draws. Bandage widens a node by its depth, the square root\n// of its depth against the graph's mean, so a contig every read covers is fat\n// and a spurious one is a hair. In a pangenome cut depth is carriage, how many\n// walks go through the node, and the same rule makes the reference thick and a\n// private allele thin. One table drives the persisted enum and the dropdown,\n// the way BUBBLE_SPREADS does.\nexport const NODE_WIDTHS = [\n {\n value: 'depth',\n label: 'By depth',\n description:\n 'Thicker the more paths carry a node, on the square root of its depth against the mean. A graph with one depth everywhere draws uniform.',\n },\n {\n value: 'uniform',\n label: 'Uniform',\n description: 'Every node the same thickness.',\n },\n] as const\n\nexport type NodeWidth = (typeof NODE_WIDTHS)[number]['value']\n\nexport const NODE_WIDTH_VALUES = NODE_WIDTHS.map(w => w.value)\n\nconst MIN_FACTOR = 0.3\nconst MAX_FACTOR = 3\n\n// Length-weighted, as Bandage's mean depth is, so a cut's long reference nodes\n// set the norm and the alleles read against it.\nexport function meanDepth(graph: Graph) {\n let weighted = 0\n let length = 0\n for (const node of graph.nodes) {\n weighted += node.depth * node.length\n length += node.length\n }\n return length > 0 ? weighted / length : 0\n}\n\nexport function depthWidthFactor(node: GraphNode, mean: number) {\n if (!(mean > 0) || !(node.depth > 0)) {\n return 1\n }\n return Math.min(\n MAX_FACTOR,\n Math.max(MIN_FACTOR, Math.sqrt(node.depth / mean)),\n )\n}\n\n// How wide a node is drawn, in screen px. One function for the geometry and\n// for the hit test, so the pointer finds a node exactly where its ink is.\nexport function nodeWidthPx(\n node: GraphNode,\n contigThickness: number,\n nodeWidth: NodeWidth,\n mean: number,\n) {\n return (\n contigThickness * (nodeWidth === 'depth' ? depthWidthFactor(node, mean) : 1)\n )\n}\n\nexport function maxNodeWidthPx(contigThickness: number, nodeWidth: NodeWidth) {\n return contigThickness * (nodeWidth === 'depth' ? MAX_FACTOR : 1)\n}\n\n// How far each node's ink reaches from its centreline, for the hit test: the\n// widths the geometry draws with, from the same function.\nexport function nodeInk(\n graph: Graph | undefined,\n nodeById: ReadonlyMap<string, GraphNode> | undefined,\n contigThickness: number,\n nodeWidth: NodeWidth,\n): NodeInk {\n const mean = graph ? meanDepth(graph) : 0\n return {\n maxHalfWidthPx: maxNodeWidthPx(contigThickness, nodeWidth) / 2,\n halfWidthPx: id => {\n const node = nodeById?.get(id)\n return node\n ? nodeWidthPx(node, contigThickness, nodeWidth, mean) / 2\n : contigThickness / 2\n },\n }\n}\n"],
5
- "mappings": "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",
6
- "names": ["require_mui", "__commonJSMin", "exports", "module", "drawnNodeLength", "opts", "length", "bandageAutoScale", "graph", "minNodeLength", "megabases", "sum", "n", "target", "PROPORTIONAL_LENGTH", "isProportional", "law", "drawnLengthFor", "count", "totalLength", "meanBp", "meanDrawn", "bp", "relative", "LAYOUT_LENGTH_PRECISION", "PROPORTIONAL_SPREAD", "layoutScaling", "spread", "drawn", "node", "BUBBLE_SPREADS", "PROPORTIONAL_LENGTH", "BUBBLE_SPREAD_VALUES", "s", "spreadFor", "spread", "entry", "COLOR_SCHEMES", "COLOR_SCHEME_VALUES", "s", "resolveColorScheme", "scheme", "graph", "RANGE_SUFFIX", "pathOrigin", "pathName", "match", "surveyPaths", "paths", "lengthOf", "anchorPaths", "pathVisits", "path", "sample", "panSNSample", "pos", "step", "visit", "existing", "chooseReferencePath", "preferred", "p", "OFF_REFERENCE_RANK", "anchorNode", "node", "visits", "reference", "anchored", "anchor", "v", "anchorFromPaths", "graph", "anchorGraph", "nameHue", "name", "hash", "i", "pathHueAt", "index", "count", "PATH_SATURATION", "PATH_LIGHTNESS", "MAX_PATH_COLORS", "pathColorsLegible", "pathCount", "pathCssColor", "labelTiers", "parts", "pathOrigin", "groupDigits", "n", "offsetTiers", "tiers", "start", "t", "pathLegend", "paths", "named", "p", "candidates", "_", "labels", "path", "NODE_WIDTHS", "NODE_WIDTH_VALUES", "w", "MIN_FACTOR", "MAX_FACTOR", "meanDepth", "graph", "weighted", "length", "node", "depthWidthFactor", "mean", "nodeWidthPx", "contigThickness", "nodeWidth", "maxNodeWidthPx", "nodeInk", "nodeById", "id"]
4
+ "sourcesContent": ["module.exports = JBrowseExports[\"tss-react/mui\"];", "import type { Graph, GraphNode } from '../types'\n\nexport interface BandageScaleOpts {\n nodeLengthPerMegabase: number\n minimumNodeLength: number\n nodeSegmentLength: number\n edgeLength: number\n}\n\n// Node drawn length, in FMMM units, as a function of bp. Used both by the layouts\n// that run here and by the options handed to the WASM engine, so a graph is drawn\n// at the same scale whichever one draws it. Bandage's own auto rule\n// (`AssemblyGraph::determineGraphInfo`):\n// pick units-per-megabase so the *mean* drawn node length lands on 40, with a\n// floor on total drawn length so a small graph doesn't collapse to a speck.\n//\n// This has to be derived per graph, not fixed. The scale that suits a bacterial\n// assembly's 10-100 kb contigs is wrong by orders of magnitude for a minigraph\n// pangenome window, whose nodes run 300 bp to a few kb: a fixed 1000 units/Mbp\n// makes every node shorter than the edges between them and the graph reads as\n// beads on a string, while 1 unit/bp makes each node a long sweeping curve and\n// the graph sprawls. For the 53-node E. coli window this lands near 35,000.\n//\n// It matters most at the small end. The WASM wrapper's own default of 1000\n// units/Mbp puts *every* node in a 400 bp pggb window below minimumNodeLength,\n// so all 31 clamp to the floor and a 1 bp SNP allele draws the same size as the\n// 164 bp backbone segment beside it \u2014 which is what made that figure read as a\n// chain of same-sized two-node bubbles. Bandage draws the same file with a 75:1\n// length ratio, the SNP alleles as specks.\n//\n// The remaining three are upstream Bandage's shipped defaults\n// (`program/settings.cpp`), which the WASM wrapper's own header does not match \u2014\n// it defaults all of them to 1.0, so they have to be passed explicitly.\nconst MEAN_NODE_LENGTH = 40\nconst MIN_TOTAL_GRAPH_LENGTH = 500\n\n// Bandage's own floor on a node's drawn length. Right for an assembly graph,\n// whose nodes are kb to Mb, and the reason a variation graph draws as a rope:\n// see BUBBLE_SPREADS, which is how a view asks for more.\nconst BANDAGE_MINIMUM_NODE_LENGTH = 5\n\n// The engine's own rule (`settings.h`, `getDrawnNodeLength`), so a seed computed\n// here spans exactly the chain the engine builds from the same numbers.\nexport function drawnNodeLength(opts: BandageScaleOpts, length: number) {\n return Math.max(\n (opts.nodeLengthPerMegabase * length) / 1_000_000,\n opts.minimumNodeLength,\n )\n}\n\nexport function bandageAutoScale(\n graph: Graph,\n // Floor on a node's drawn length, in the same FMMM units as the scale below.\n // Anything at or under Bandage's own floor leaves the drawing exactly as it\n // was, which is what keeps `'auto'` byte-identical to the shipped behaviour.\n minNodeLength = BANDAGE_MINIMUM_NODE_LENGTH,\n): BandageScaleOpts {\n const totalLength = graph.nodes.reduce((sum, n) => sum + n.length, 0)\n const megabases = totalLength / 1_000_000\n const target = Math.max(\n graph.nodes.length * MEAN_NODE_LENGTH,\n MIN_TOTAL_GRAPH_LENGTH,\n )\n return {\n nodeLengthPerMegabase: megabases > 0 ? target / megabases : 10_000,\n minimumNodeLength: Math.max(BANDAGE_MINIMUM_NODE_LENGTH, minNodeLength),\n edgeLength: 5,\n nodeSegmentLength: 20,\n }\n}\n\n// How a node's bp becomes its drawn length, as a power law against the graph's\n// own mean. The idiom is Bandage's, moved onto the axis a pangenome needs it on:\n// upstream derives a node's *width* from its depth exactly this way\n// (`graph/graphicsitemnode.cpp`, `getNodeWidth`), at a `depthPower` of 0.5 and a\n// `depthEffectOnWidth` of 0.5, because depth in an assembly graph spans orders\n// of magnitude and drawing it linearly is unreadable.\n//\n// drawn = meanDrawn * (((bp / meanBp) ^ power - 1) * effect + 1)\n//\n// Length in a *variation* graph spans those same orders of magnitude \u2014 a 1 bp\n// allele beside a 16 kb backbone segment \u2014 and upstream still maps it linearly,\n// because its own nodes are assembled contigs where that range does not arise.\n// That linear map is what draws a pggb window as one rope: past the small end\n// every allele falls under `minimumNodeLength` and clamps, so both arms of a\n// bubble land inside one node thickness of each other.\n//\n// power 1 with effect 1 is exactly proportional, so Bandage's shipped behaviour\n// is a point in this family rather than a mechanism sitting beside it. See\n// BUBBLE_SPREADS for the points a view can ask for.\nexport interface DrawnLengthLaw {\n // exponent applied to a node's length relative to the graph's mean\n power: number\n // how much of that relative length survives. 0 draws every node at the mean,\n // 1 applies the power law undamped.\n effect: number\n}\n\nexport const PROPORTIONAL_LENGTH: DrawnLengthLaw = { power: 1, effect: 1 }\n\nexport function isProportional(law: DrawnLengthLaw) {\n return law.power === 1 && law.effect === 1\n}\n\n// Drawn length in FMMM units for one node of `graph`, under `law`.\nexport function drawnLengthFor(graph: Graph, law: DrawnLengthLaw) {\n const count = graph.nodes.length\n const totalLength = graph.nodes.reduce((sum, n) => sum + n.length, 0)\n const meanBp = count > 0 ? totalLength / count : 0\n // The mean drawn length `bandageAutoScale` already targets, small-graph floor\n // included, so a compressed drawing comes out the same overall size as the\n // proportional one it replaces. That is the property a per-node floor does\n // not have, and the reason raising one is unusable at scale: it lifts the\n // hundreds of non-branching chain nodes along with the alleles, which on a\n // 521-node cut inflates the drawing past what zoom-to-fit can frame.\n const meanDrawn =\n count > 0\n ? Math.max(count * MEAN_NODE_LENGTH, MIN_TOTAL_GRAPH_LENGTH) / count\n : MEAN_NODE_LENGTH\n return (bp: number) => {\n if (meanBp <= 0) {\n return meanDrawn\n }\n const relative = (bp / meanBp) ** law.power\n return Math.max(\n meanDrawn * ((relative - 1) * law.effect + 1),\n BANDAGE_MINIMUM_NODE_LENGTH,\n )\n }\n}\n\n// The engine's own length rule is linear with a floor and takes two numbers\n// (`settings.h`, `getDrawnNodeLength`), so a non-linear law cannot be expressed\n// through them. It can be expressed in the lengths themselves: node length\n// crosses the RPC boundary only to become a drawn length \u2014 `getLength()` has\n// exactly two call sites upstream, both inside that rule \u2014 so handing the engine\n// pre-transformed lengths and a 1:1 scale draws the law without touching the\n// WASM build. Scaled by this factor first because the binding reads a node's\n// length as an `unsigned`, and rounding drawn units straight to integers would\n// quantise the small end where the whole point is legibility.\nconst LAYOUT_LENGTH_PRECISION = 1000\n\n// How a view asks for its node lengths: a law, plus Bandage's own per-node\n// floor. Orthogonal on purpose \u2014 see BUBBLE_SPREADS for which does what.\nexport interface NodeLengthSpread {\n law: DrawnLengthLaw\n // in the same FMMM units as the drawn lengths. At or under Bandage's own\n // floor this leaves the drawing exactly as it was.\n minNodeLength: number\n}\n\nexport const PROPORTIONAL_SPREAD: NodeLengthSpread = {\n law: PROPORTIONAL_LENGTH,\n minNodeLength: 0,\n}\n\nexport interface LayoutScaling {\n // the nodes to hand the engine. Under any law but the proportional one their\n // `length` is a scaled drawn length rather than a bp count, which is why this\n // is a separate array and never the graph's own nodes.\n nodes: GraphNode[]\n opts: BandageScaleOpts\n}\n\nexport function layoutScaling(\n graph: Graph,\n spread: NodeLengthSpread = PROPORTIONAL_SPREAD,\n): LayoutScaling {\n const { law, minNodeLength } = spread\n const opts = bandageAutoScale(graph, minNodeLength)\n // The proportional law is what every committed force figure was drawn\n // against, and it is already exactly what `bandageAutoScale` expresses, so it\n // keeps the untransformed path rather than round-tripping through a rounding\n // step FMMM would be free to amplify. Every floor-based spread comes through\n // here too, unchanged.\n if (isProportional(law)) {\n return { nodes: graph.nodes, opts }\n }\n const drawn = drawnLengthFor(graph, law)\n return {\n nodes: graph.nodes.map(node => ({\n ...node,\n length: Math.round(drawn(node.length) * LAYOUT_LENGTH_PRECISION),\n })),\n opts: {\n ...opts,\n nodeLengthPerMegabase: 1_000_000 / LAYOUT_LENGTH_PRECISION,\n // Bandage's own floor only. A law and a raised floor are alternatives\n // rather than a stack: the law has already lifted the small end, and a\n // floor on top of it would flatten exactly what it just spread.\n minimumNodeLength: BANDAGE_MINIMUM_NODE_LENGTH,\n },\n }\n}\n\n// The mean drawn node length `bandageAutoScale` targets, exported so\n// BUBBLE_SPREADS can state its laws against it rather than against unanchored\n// constants.\nexport { MEAN_NODE_LENGTH }\n", "import { MEAN_NODE_LENGTH, PROPORTIONAL_LENGTH } from './layout/drawnScale'\n\nimport type { NodeLengthSpread } from './layout/drawnScale'\n\n// How far apart the force layout draws the two arms of a bubble, as the law\n// turning a node's bp into its drawn length. One table drives the persisted\n// enum, the dropdown and the value handed to the engine, the same way\n// LAYOUT_MODES and COLOR_SCHEMES do.\n//\n// Why this needs to be a control rather than a better default: the drawn-length\n// law is the one thing standing between a variation graph and a legible force\n// layout, and compressing it costs the property that node length is proportional\n// to bp. Bandage maps length linearly, which suits an assembly graph whose nodes\n// are kb to Mb. In a pangenome an allele is 1-50 bp against a backbone segment\n// of several kb, so on that map every alt clamps to the engine's 5-unit floor,\n// both arms of a bubble land inside one node thickness of each other, and FMMM\n// has nothing to spread \u2014 zoom-to-fit then delivers a single rope with the\n// variation invisible inside it. Compressing the law opens the bubbles and\n// flattens the length ratio, and which of those a reader wants depends on the\n// figure, so the view asks rather than assumes.\n//\n// The compression is Bandage's own, taken off the axis upstream uses it on: it\n// draws node *width* from depth as a power law against the mean, at power 0.5\n// and effect 0.5, for the same reason. 'open' is those two numbers. See\n// DrawnLengthLaw.\n//\n// Measured on an odgi extract of GRCh38#0#chrM:8,200-8,400 from HPRC release 2's\n// chrM pggb graph (61 nodes, 84 edges, 234 haplotype paths), fitted to a 900x560\n// pane: proportional is one squiggle with a single knot in it, and the bubbles\n// come apart into legible lenses once the law compresses.\n//\n// The floor and the law are different instruments and both are kept, because\n// neither does the other's job:\n//\n// - a FLOOR lifts the small end and leaves everything above it proportional. It\n// is what a figure wants when one long node has to stay long \u2014 the ribbons in\n// `pangenome/pggb_haplotype_paths` separate along a 1.2 kb deletion arc, and\n// shortening that arc towards the mean piles them up. Its cost is that it is a\n// per-node minimum, so it lifts a graph's non-branching chain nodes along with\n// its alleles and the drawing inflates with node count: on the 521-node pggb\n// cut in `pangenome/graph_resolution` it reached ~52,000 units and a 1.4% fit,\n// which is why that figure could once afford a spread on its 7-node half only.\n// - the LAW compresses both ends towards the mean, so the drawing stays the size\n// it already was whatever the node count, and a cut spanning 6 bp to 16 kb\n// fits one pane. Its cost is the top end: a node that has to read as long no\n// longer does.\n//\n// So a figure about bubble shape at scale takes 'compress', and a figure about\n// what is drawn along one long edge takes 'open'.\n//\n// 'auto' is the proportional map, unchanged, so every existing figure and the\n// `bandageAutoScale` length-proportionality test are untouched by this existing.\nexport const BUBBLE_SPREADS = [\n {\n value: 'auto',\n label: 'Proportional',\n description:\n \"Bandage's own scale: a node draws proportional to its length, so a 1 bp allele is a speck.\",\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 0,\n },\n {\n value: 'open',\n label: 'Open bubbles',\n description:\n 'Give every allele a drawn length, so a bubble reads as two arms rather than a knot.',\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 2.5,\n },\n {\n value: 'wide',\n label: 'Wide bubbles',\n description:\n 'As open, spread further. Best on a window of a dozen bubbles.',\n law: PROPORTIONAL_LENGTH,\n minNodeFactor: 10,\n },\n {\n value: 'compress',\n label: 'Compress lengths',\n description:\n 'Pull the longest and shortest nodes towards the graph\\u2019s mean, so a cut spanning kb and bp fits one pane.',\n law: { power: 0.5, effect: 0.5 },\n minNodeFactor: 0,\n },\n] as const\n\nexport type BubbleSpread = (typeof BUBBLE_SPREADS)[number]['value']\n\nexport const BUBBLE_SPREAD_VALUES = BUBBLE_SPREADS.map(s => s.value)\n\n// The law and floor behind a spread, resolved so the model has one place that\n// knows how a spread becomes numbers. An unknown value draws proportionally\n// rather than throwing, which is what a session persisted by a newer build\n// degrades to.\nexport function spreadFor(spread: string): NodeLengthSpread {\n const entry = BUBBLE_SPREADS.find(s => s.value === spread)\n return {\n law: entry?.law ?? PROPORTIONAL_LENGTH,\n minNodeLength: (entry?.minNodeFactor ?? 0) * MEAN_NODE_LENGTH,\n }\n}\n", "import type { Graph } from './types'\n\n// One table drives the persisted enum and both colour dropdowns, the same way\n// LAYOUT_MODES drives the layout enum and its menu. The values and their labels\n// used to live in two lists in two directories, so adding a scheme meant editing\n// both and a mismatch showed up as a dropdown entry that selected nothing.\n//\n// Kept out of the components directory because the model needs it too.\nexport const COLOR_SCHEMES = [\n // Mirrors `layoutModes`' 'auto': a value the model resolves rather than a\n // colour of its own. It exists because 'uniform' was the default, so a\n // launched graph opened flat grey and both tutorials spent a step saying \"now\n // pick a colour\" \u2014 one figure literally drives that click. A graph with\n // reference coordinates resolves to 'reference-position', which is the one\n // ramp a linear track beside it can be painted with too; a graph with none\n // keeps 'uniform', because there the ramp would be a hue nothing earned.\n //\n // Resolve through `effectiveColorScheme`; the dropdown reads the raw prop, so\n // \"Auto\" stays selectable and visible as what it is.\n { value: 'auto', label: 'Auto' },\n { value: 'uniform', label: 'Uniform' },\n { value: 'random', label: 'Random' },\n { value: 'rainbow', label: 'Rainbow' },\n { value: 'depth', label: 'Depth' },\n { value: 'node-length', label: 'Node Length' },\n { value: 'stable-rank', label: 'Stable rank' },\n { value: 'reference-position', label: 'Reference position' },\n { value: 'grey', label: 'Grey' },\n] as const\n\nexport type ColorScheme = (typeof COLOR_SCHEMES)[number]['value']\n\n// What the renderer can actually paint with: every scheme except the one that\n// stands for \"work it out\". Stated as its own type so `getNodeColor`'s switch\n// has no 'auto' arm to forget.\nexport type ResolvedColorScheme = Exclude<ColorScheme, 'auto'>\n\nexport const COLOR_SCHEME_VALUES = COLOR_SCHEMES.map(s => s.value)\n\n// 'auto' asks the GRAPH, not the layout: a hue along the reference means\n// something whenever the segments have reference coordinates, force-directed\n// drawings included.\nexport function resolveColorScheme(\n scheme: ColorScheme,\n graph: Graph | undefined,\n): ResolvedColorScheme {\n return scheme !== 'auto'\n ? scheme\n : graph?.anchoredBy\n ? 'reference-position'\n : 'uniform'\n}\n", "import { REFERENCE_RANK } from './anchoredNodes'\nimport { panSNSample } from './pansn'\n\nimport type { Graph, GraphNode, PathOrigin, PathVisit } from './types'\n\n// Reference coordinates for a GFA that tags none of its segments with one.\n//\n// rGFA writes the fact per segment (SN/SO/SR). A pggb / odgi / Minigraph-Cactus\n// graph writes the same fact once per path and leaves the arithmetic to the\n// reader: walking a path's steps in order, accumulating segment lengths,\n// assigns every segment that path visits an interval on the path's own\n// sequence. Same information, different encoding \u2014 so a general GFA is not a\n// degraded rGFA, and the anchored layouts work on it once the walk is done.\n//\n// It carries one thing rGFA cannot: a segment's *carriage*, the set of\n// assemblies that actually traverse it. rGFA's SR is build order, so there the\n// most a segment can say is which assembly first contributed it.\n\n// `odgi extract` names an extracted path for the interval it covers on its own\n// sequence: `K12#1#chr:1004500-1004961`. That suffix is the only place a cut\n// subgraph states where in the genome it sits, so it is split off here rather\n// than carried around as part of the name \u2014 no assembly has a sequence called\n// `K12#1#chr:1004500-1004961`, and PanSN parsing of it yields a contig no\n// linear view can open.\n//\n// Anchored on the digits rather than on a trailing colon, because a stable name\n// may legitimately contain one (the same hazard gfaParser's tag splitting has).\nconst RANGE_SUFFIX = /:(\\d+)-\\d+$/\n\nexport function pathOrigin(pathName: string) {\n const match = RANGE_SUFFIX.exec(pathName)\n return match\n ? { name: pathName.slice(0, match.index), start: +match[1]! }\n : { name: pathName, start: 0 }\n}\n\nexport interface PathSteps {\n name: string\n start: number\n steps: { id: string; strand: '+' | '-' }[]\n}\n\n// The single walk. Every segment visit lands in `pathVisits` at the bp its own\n// path reaches it at; `anchorPaths` is what the walk learned about the paths\n// themselves, which is what a reference-path picker lists.\nexport function surveyPaths(\n paths: PathSteps[],\n lengthOf: (segmentId: string) => number,\n) {\n const anchorPaths: PathOrigin[] = []\n const pathVisits = new Map<string, PathVisit[]>()\n for (const path of paths) {\n const sample = panSNSample(path.name)\n let pos = path.start\n for (const step of path.steps) {\n const visit = {\n path: path.name,\n sample,\n start: pos,\n strand: step.strand,\n }\n const existing = pathVisits.get(step.id)\n if (existing) {\n existing.push(visit)\n } else {\n pathVisits.set(step.id, [visit])\n }\n pos += lengthOf(step.id)\n }\n anchorPaths.push({\n name: path.name,\n sample,\n start: path.start,\n length: pos - path.start,\n })\n }\n return { anchorPaths, pathVisits }\n}\n\n// Which path x is drawn on. This is a choice, not a fact: a general GFA's path\n// names are arbitrary and nothing in the file marks one of them as the\n// reference, so a preference is matched against a path's PanSN sample name (the\n// assembly a subgraph was cut against, which is how the launch path knows) and\n// then against its full name. With no preference the first path in the file\n// wins, which is where pggb and odgi leave the reference.\nexport function chooseReferencePath(\n anchorPaths: PathOrigin[],\n preferred: string | undefined,\n) {\n const named = anchorPaths.find(\n p => p.sample === preferred || p.name === preferred,\n )\n return named ?? anchorPaths[0]\n}\n\n// Rank on a path-derived graph is the one distinction the paths support: on the\n// reference path or off it. rGFA's higher ranks are minigraph's build order,\n// which a path GFA has no equivalent of, so drawing more rows than this would\n// be drawing structure the file does not state.\nconst OFF_REFERENCE_RANK = 1\n\n// A segment the reference path visits sits on the backbone at the offset that\n// visit reaches it. One it never visits is an alternate allele, placed on the\n// coordinates of the first path that does carry it \u2014 the same asymmetry rGFA\n// has, where a rank>0 segment's SO is an offset on the assembly that\n// contributed the sequence rather than on the reference.\n//\n// **First visit wins** when a path reaches the same segment more than once, and\n// collapsed repeats make that real rather than hypothetical: pggb folds the\n// E. coli rRNA operons into shared segments, so every strain's path walks them\n// twice (`odgi depth` reaches 10 over a five-strain graph at chr:4,167,000 and\n// chr:3,942,000). A node draws as one tube at one x, so the alternative to\n// picking a copy is one tube spanning both, claiming reference the segment does\n// not occupy. The repeat stays visible as depth: such a node's traversal count\n// is a multiple of the path count.\nfunction anchorNode(\n node: GraphNode,\n visits: PathVisit[] | undefined,\n reference: string,\n): GraphNode {\n let anchored = node\n if (visits && visits.length > 0) {\n const anchor = visits.find(v => v.path === reference) ?? visits[0]!\n anchored = {\n ...node,\n stable: {\n refName: anchor.path,\n start: anchor.start,\n rank: anchor.path === reference ? REFERENCE_RANK : OFF_REFERENCE_RANK,\n strand: anchor.strand,\n },\n samples: [...new Set(visits.map(v => v.sample))].sort(),\n }\n }\n return anchored\n}\n\n// Re-runnable against a different reference path at no parsing cost, which is\n// what the picker needs: the walk is already recorded in `pathVisits`, and only\n// which path counts as rank 0 changes.\nexport function anchorFromPaths(graph: Graph, preferred: string | undefined) {\n const { anchorPaths, pathVisits } = graph\n const reference =\n anchorPaths && pathVisits\n ? chooseReferencePath(anchorPaths, preferred)\n : undefined\n return reference && pathVisits\n ? ({\n ...graph,\n nodes: graph.nodes.map(node =>\n anchorNode(node, pathVisits.get(node.name), reference.name),\n ),\n anchoredBy: 'paths',\n referencePath: reference.name,\n } satisfies Graph)\n : graph\n}\n\n// rGFA states coordinates on every segment, so only a graph that states none\n// has to derive them. A GFA with neither tags nor paths comes back untouched\n// and falls through to the force layout, which is the honest answer for it.\nexport function anchorGraph(graph: Graph, preferred: string | undefined) {\n return graph.anchoredBy === 'tags' ? graph : anchorFromPaths(graph, preferred)\n}\n", "import { isGenericSample } from './pansn'\nimport { pathOrigin } from './pathAnchoring'\n\nimport type { GraphPath } from './types'\n\n// Deterministic colour from a string (djb2-style hash to an HSL hue). Fine for\n// the `random` node scheme, where a collision between two of thousands of nodes\n// means nothing. NOT what the path ribbons use: see pathHueAt.\nexport function nameHue(name: string) {\n let hash = 0\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash)\n }\n return Math.abs(hash % 360)\n}\n\n// Ribbon hues are spread evenly over the wheel by position in the path list,\n// not hashed from the path name. A hash draws from the wheel at random, and at\n// five paths two of them landing on the same hue is common rather than\n// unlucky: `Sakai#1#chr:1983339-1983535` and `NCTC86#1#chr:1709109-1710286`\n// hash 26 degrees apart, which is two purples and a legend that cannot be read\n// off the drawing. Evenly spaced, the worst case is the best available.\n//\n// The cost is that a path's colour depends on how many paths there are, so it\n// moves when the cut changes. That is what the legend is for, and it is the\n// same trade the Bandage demo this was ported from made.\nexport function pathHueAt(index: number, count: number) {\n return (index * 360) / count\n}\n\nexport const PATH_SATURATION = 0.7\nexport const PATH_LIGHTNESS = 0.5\n\n// Past this many paths a graph cannot be drawn per path at all, and the WHOLE\n// of `drawPaths` goes off with it: the node stripes, the edge ribbons and the\n// key naming them.\n//\n// One number for all three because they are one statement, and they used to\n// disagree. Only the stripes were capped. So a Minigraph-Cactus cut, which\n// writes one W record per haplotype and walks every backbone link with all of\n// them, drew: no stripes at all, a key hundreds of rows tall, and one bezier\n// stroke per path per edge \u2014 measured at 99,800 strokes and 64 ms of geometry\n// for 200 paths over 499 links, against 2,495 strokes for the five-path pggb\n// cut the figures use. Every one of those is its own `beginPath`/`stroke` on\n// the Canvas2D backend, every frame.\n//\n// 16 is where the drawing stops SAYING anything, not where it stops being fast.\n// `pathHueAt` spreads the wheel evenly, so 16 hues are 22 degrees apart and\n// still tellable and 200 are one degree; the ribbon fan is PATH_RIBBON_SPACING\n// per path, so 16 of them is a legible fan and 200 is a band wider than the\n// nodes; and a key past about 16 rows is taller than the drawing beside it.\n// Above the cap the honest picture is the plain one \u2014 which is exactly what a\n// graph carrying no paths at all already draws.\nexport const MAX_PATH_COLORS = 16\n\n// Whether this graph's paths can be drawn as colours. Resolve it once and hand\n// the answer down: the geometry, the hit index and the key each used to decide\n// for themselves, which is how they came to disagree.\nexport function pathColorsLegible(pathCount: number) {\n return pathCount > 0 && pathCount <= MAX_PATH_COLORS\n}\n\nexport function pathCssColor(index: number, count: number) {\n return `hsl(${pathHueAt(index, count)}, ${PATH_SATURATION * 100}%, ${\n PATH_LIGHTNESS * 100\n }%)`\n}\n\n// Beside reads, which take the blues and the reds, a tube map's paths step\n// from dark grey to light, as sequenceTubeMap draws them under reads, so no\n// tube shares a read's colour\nexport function pathGreyCssColor(index: number, count: number) {\n const lightness = count > 1 ? 25 + (45 * index) / (count - 1) : 45\n return `hsl(0, 0%, ${lightness}%)`\n}\n\n// A path is named the way its file names it \u2014 `K12#1#chr:1004500-1004961` for a\n// P record `odgi extract` wrote, `HG00738#1` for a W record \u2014 and neither is a\n// legend entry. The label is the least of that name which still tells the paths\n// apart: the sample where samples are unique, the haplotype too where they are\n// not, the whole stable name where even that repeats. Widening it for every row\n// rather than only for the colliding ones, because a legend where one entry is\n// `HG00738#1` and its neighbour is `HG01071` reads as two kinds of thing.\n// A generic path, which vg files under a placeholder sample\n// (`_gbwt_ref#0#GI262359905`), is named by its contig alone.\nfunction labelTiers(name: string) {\n const parts = pathOrigin(name).name.split('#')\n const full = parts.join('#')\n if (parts.length >= 3 && isGenericSample(parts[0]!)) {\n const contig = parts.slice(2).join('#')\n return [contig, contig, full]\n }\n return [parts[0]!, parts.slice(0, 2).join('#'), full]\n}\n\n// Locale-independent, unlike toLocaleString: a figure regenerated on a machine\n// with a different locale would otherwise differ from the committed one.\nfunction groupDigits(n: number) {\n return String(n).replace(/\\B(?=(\\d{3})+$)/g, ',')\n}\n\n// A collapsed repeat puts one sequence through the same segments more than\n// once, and `odgi extract` emits one path per visit \u2014 nine visits over five\n// E. coli chromosomes at the rRNA operons, where every name tier above collides\n// because the sequence really is the same one. What separates those is the\n// offset each name carried, which is the one thing pathOrigin strips off.\nfunction offsetTiers(name: string, tiers: string[]) {\n const { start } = pathOrigin(name)\n return tiers.map(t => `${t} @${groupDigits(start)}`)\n}\n\nexport interface PathLegendEntry {\n name: string\n label: string\n color: string\n}\n\n// `colors` is what each path was actually drawn in, where that is not\n// pathCssColor's hue\nexport function pathLegend(\n paths: GraphPath[],\n colors?: readonly string[],\n): PathLegendEntry[] {\n const named = paths.map(p => labelTiers(p.name))\n // narrowest first, and the offset is tried before the next name tier: two\n // copies of one operon are told apart by where they are, not by widening a\n // name that is genuinely identical\n const candidates = [0, 1, 2].flatMap(t => [\n paths.map((_, i) => named[i]![t]!),\n paths.map((p, i) => offsetTiers(p.name, named[i]!)[t]!),\n ])\n const distinct = candidates.find(\n labels => new Set(labels).size === paths.length,\n )\n // Nothing separates two paths with the same name and the same offset, so the\n // widest labelling is as close as any can get.\n const labels = distinct ?? candidates.at(-1)!\n return paths.map((path, i) => ({\n name: path.name,\n label: labels[i]!,\n color: colors?.[i] ?? pathCssColor(i, paths.length),\n }))\n}\n", "import type { Graph, GraphNode } from './types'\nimport type { NodeInk } from './util/hitDetection'\n\n// How thick a node draws. Bandage widens a node by its depth, the square root\n// of its depth against the graph's mean, so a contig every read covers is fat\n// and a spurious one is a hair. In a pangenome cut depth is carriage, how many\n// walks go through the node, and the same rule makes the reference thick and a\n// private allele thin. One table drives the persisted enum and the dropdown,\n// the way BUBBLE_SPREADS does.\nexport const NODE_WIDTHS = [\n {\n value: 'depth',\n label: 'By depth',\n description:\n 'Thicker the more paths carry a node, on the square root of its depth against the mean. A graph with one depth everywhere draws uniform.',\n },\n {\n value: 'uniform',\n label: 'Uniform',\n description: 'Every node the same thickness.',\n },\n] as const\n\nexport type NodeWidth = (typeof NODE_WIDTHS)[number]['value']\n\nexport const NODE_WIDTH_VALUES = NODE_WIDTHS.map(w => w.value)\n\nconst MIN_FACTOR = 0.3\nconst MAX_FACTOR = 3\n\n// Length-weighted, as Bandage's mean depth is, so a cut's long reference nodes\n// set the norm and the alleles read against it.\nexport function meanDepth(graph: Graph) {\n let weighted = 0\n let length = 0\n for (const node of graph.nodes) {\n weighted += node.depth * node.length\n length += node.length\n }\n return length > 0 ? weighted / length : 0\n}\n\nexport function depthWidthFactor(node: GraphNode, mean: number) {\n if (!(mean > 0) || !(node.depth > 0)) {\n return 1\n }\n return Math.min(\n MAX_FACTOR,\n Math.max(MIN_FACTOR, Math.sqrt(node.depth / mean)),\n )\n}\n\n// How wide a node is drawn, in screen px. One function for the geometry and\n// for the hit test, so the pointer finds a node exactly where its ink is.\nexport function nodeWidthPx(\n node: GraphNode,\n contigThickness: number,\n nodeWidth: NodeWidth,\n mean: number,\n) {\n return (\n contigThickness * (nodeWidth === 'depth' ? depthWidthFactor(node, mean) : 1)\n )\n}\n\nexport function maxNodeWidthPx(contigThickness: number, nodeWidth: NodeWidth) {\n return contigThickness * (nodeWidth === 'depth' ? MAX_FACTOR : 1)\n}\n\n// How far each node's ink reaches from its centreline, for the hit test: the\n// widths the geometry draws with, from the same function.\nexport function nodeInk(\n graph: Graph | undefined,\n nodeById: ReadonlyMap<string, GraphNode> | undefined,\n contigThickness: number,\n nodeWidth: NodeWidth,\n): NodeInk {\n const mean = graph ? meanDepth(graph) : 0\n return {\n maxHalfWidthPx: maxNodeWidthPx(contigThickness, nodeWidth) / 2,\n halfWidthPx: id => {\n const node = nodeById?.get(id)\n return node\n ? nodeWidthPx(node, contigThickness, nodeWidth, mean) / 2\n : contigThickness / 2\n },\n }\n}\n"],
5
+ "mappings": "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",
6
+ "names": ["require_mui", "__commonJSMin", "exports", "module", "drawnNodeLength", "opts", "length", "bandageAutoScale", "graph", "minNodeLength", "megabases", "sum", "n", "target", "PROPORTIONAL_LENGTH", "isProportional", "law", "drawnLengthFor", "count", "totalLength", "meanBp", "meanDrawn", "bp", "relative", "LAYOUT_LENGTH_PRECISION", "PROPORTIONAL_SPREAD", "layoutScaling", "spread", "drawn", "node", "BUBBLE_SPREADS", "PROPORTIONAL_LENGTH", "BUBBLE_SPREAD_VALUES", "s", "spreadFor", "spread", "entry", "COLOR_SCHEMES", "COLOR_SCHEME_VALUES", "s", "resolveColorScheme", "scheme", "graph", "RANGE_SUFFIX", "pathOrigin", "pathName", "match", "surveyPaths", "paths", "lengthOf", "anchorPaths", "pathVisits", "path", "sample", "panSNSample", "pos", "step", "visit", "existing", "chooseReferencePath", "preferred", "p", "OFF_REFERENCE_RANK", "anchorNode", "node", "visits", "reference", "anchored", "anchor", "v", "anchorFromPaths", "graph", "anchorGraph", "nameHue", "name", "hash", "i", "pathHueAt", "index", "count", "PATH_SATURATION", "PATH_LIGHTNESS", "MAX_PATH_COLORS", "pathColorsLegible", "pathCount", "pathCssColor", "pathGreyCssColor", "labelTiers", "parts", "pathOrigin", "full", "isGenericSample", "contig", "groupDigits", "n", "offsetTiers", "tiers", "start", "t", "pathLegend", "paths", "colors", "named", "p", "candidates", "_", "labels", "path", "NODE_WIDTHS", "NODE_WIDTH_VALUES", "w", "MIN_FACTOR", "MAX_FACTOR", "meanDepth", "graph", "weighted", "length", "node", "depthWidthFactor", "mean", "nodeWidthPx", "contigThickness", "nodeWidth", "maxNodeWidthPx", "nodeInk", "nodeById", "id"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import{d as dt}from"./chunk-UQEPPJEO.js";import{c as ut}from"./chunk-SCMIJAAX.js";import{i as Le,n as ft,o as pt,p as yn,q as xn,t as ht,u as mt,y as bt,z as Mn}from"./chunk-IUIIYSGF.js";import{a as Ge,b as _,c as Ze,d as ce,e as ue,f as ct,h as Je}from"./chunk-EFVAQ2KM.js";import{a as Qe,c as it,d as lt}from"./chunk-KULNKXPT.js";import{a as Ke}from"./chunk-XEJ47DLD.js";import{a as Ue,b as le}from"./chunk-FY3BTKY4.js";var yt=Ue((al,gt)=>{gt.exports=JBrowseExports["@mui/material/SvgIcon"]});var Ms=Ue((Ql,Jt)=>{Jt.exports=JBrowseExports.mobx});var pn=Ue((su,Vo)=>{Vo.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var tl=Ue((od,xr)=>{xr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var te=le(yt(),1);function ul(e){let n=t=>Math.round(t*100)/100;return e.map((t,r)=>`${r?"L":"M"}${n(t.x)},${n(t.y)}`).join("")}function xt(e,n,t,r,o){let s=Math.hypot(r-n,t-e);if(s===0)return[t,r];let a=(t-e)/s,l=(r-n)/s;return[t+o*a,r+o*l]}function Nn(e,n){let t=1-n,r=t*t*t,o=3*t*t*n,s=3*t*n*n,a=n*n*n;return{x:r*e.x0+o*e.cx0+s*e.cx1+a*e.x1,y:r*e.y0+o*e.cy0+s*e.cy1+a*e.y1}}function Rt(e){let n=e[Math.floor(e.length/2)];return n?Nn(n,.5):void 0}function Et(e){let n=1/0,t=1/0,r=-1/0,o=-1/0;for(let s of e)n=Math.min(n,s.x0,s.cx0,s.cx1,s.x1),r=Math.max(r,s.x0,s.cx0,s.cx1,s.x1),t=Math.min(t,s.y0,s.cy0,s.cy1,s.y1),o=Math.max(o,s.y0,s.cy0,s.cy1,s.y1);return{minX:n,minY:t,maxX:r,maxY:o}}function Rr(e,n,t){let r=Nn(e,n),o=Nn(e,t),s=(t-n)/3,a=Mt(e,n),l=Mt(e,t);return{x0:r.x,y0:r.y,cx0:r.x+a.x*s,cy0:r.y+a.y*s,cx1:o.x-l.x*s,cy1:o.y-l.y*s,x1:o.x,y1:o.y}}function Mt(e,n){let t=1-n,r=3*t*t,o=6*t*n,s=3*n*n;return{x:r*(e.cx0-e.x0)+o*(e.cx1-e.cx0)+s*(e.x1-e.cx1),y:r*(e.cy0-e.y0)+o*(e.cy1-e.cy0)+s*(e.y1-e.cy1)}}function At(e,n){let t=[];for(let r of e){let o=Math.hypot(r.cx0-r.x0,r.cy0-r.y0)+Math.hypot(r.cx1-r.cx0,r.cy1-r.cy0)+Math.hypot(r.x1-r.cx1,r.y1-r.cy1),s=Math.max(3,Math.round(o/n)|1);for(let a=0;a<s;a+=2)t.push([Rr(r,a/s,(a+1)/s)])}return t}function Tt(e,n,t){let r=new Array(e.length);for(let o=0;o<e.length;o++){let s=e[o];r[o]={x0:s.x0+n,y0:s.y0+t,cx0:s.cx0+n,cy0:s.cy0+t,cx1:s.cx1+n,cy1:s.cy1+t,x1:s.x1+n,y1:s.y1+t}}return r}function wn(e,n){let t=e.length-1;return n==="end"?{at:e[t],inward:e[t-1]}:{at:e[0],inward:e[1]}}var Er=.5,Ar=80;function wt(e){let n=1/0,t=-1/0;for(let r of e)n=Math.min(n,r.x),t=Math.max(t,r.x);return{min:n,max:t}}function St(e,n){return Math.max(0,n.min-e,e-n.max)}function Lt(e,n,t){let r=St(e[0].x,n),o=St(e[e.length-1].x,n);return r===o?t:r<o?"start":"end"}function Tr(e,n){return{from:Lt(e,wt(n),"end"),to:Lt(n,wt(e),"start")}}var Cr=.75,Ir=1.15,_r=.35,vr=60;function Br(e,n,t,r,o,s){let a=Math.hypot(t-e,r-n),l=a===0?1:(t-e)/a,i=a===0?0:(r-n)/a,u=0,f=1/0,c=-1/0;for(let m of o){let b=m.x-e,g=m.y-n,x=b*-i+g*l;Math.abs(x)>Math.abs(u)&&(u=x);let R=b*l+g*i;f=Math.min(f,R),c=Math.max(c,R)}let d=o.length?c-f:0,h=Math.max(Math.abs(u)*Ir/Cr,d*_r),p=s===void 0?h:Math.min(h,s);return u<0?-p:p}function en({scaleX:e,scaleY:n}){return n/e}var Or=3;function Sn(e,n,t){let r=n.x-e.x,o=(n.y-e.y)*t,s=Math.hypot(r,o);return s===0?void 0:{x:r/s,y:o/s}}function Ct(e,n,t,r,o=Or){let s=en(r),a=Sn(e[e.length-1],n[0],s)??Sn(e[0],e.at(-1),s)??Sn(n[0],n.at(-1),s)??{x:1,y:0},l=[];for(let i=0;i<t;i++){let u=(i-(t-1)/2)*o;l.push({x:-a.y*u,y:a.x*u/s})}return l}function Ln(e,n){return e.map(t=>({x:t.x,y:t.y*n}))}function Pr(e,n){for(let t of e)t.y0/=n,t.cy0/=n,t.cy1/=n,t.y1/=n;return e}var Gr=12,Dr=40;function Nt(e,n){let t=0;for(let s=1;s<e.length;s++)t+=Math.hypot(e[s].x-e[s-1].x,e[s].y-e[s-1].y);let r=t*n;return Math.min(Dr,Math.max(Gr,r/2))/Math.max(n,Number.EPSILON)}function It(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function $r(e,n,t,r){let{at:o,inward:s}=e,a=s?o.x-s.x:1,l=s?o.y-s.y:0,i=Math.hypot(a,l)||1,u=a/i,f=l/i,c=o.x+t,d=o.y+r,h=c+u*n/3,p=d+f*n/3,m=c+u*n,b=d+f*n,g=-f*n/2,x=u*n/2;return[{x0:c,y0:d,cx0:h,cy0:p,cx1:m+g,cy1:b+x,x1:m,y1:b},{x0:m,y0:b,cx0:m-g,cy0:b-x,cx1:h,cy1:p,x1:c,y1:d}]}function De(e,n,t,r,o,s,a=[],l){let i=s.scaleX,u=en(s),f=l??(s.pixelRows?vr:void 0);if(u!==1)return Pr(De(Ln(e,u),Ln(n,u),t,r,o*u,{scaleX:i,scaleY:i},Ln(a,u),f===void 0?void 0:f*u),u);if(typeof t=="string")return $r(wn(e,t),Nt(e,i),r,o);let c=t?{from:"end",to:"start"}:Tr(e,n),d=wn(e,c.from),h=wn(n,c.to),p=d.at,m=h.at,b=p.x+r,g=p.y+o,x=m.x+r,R=m.y+o;if(t){let N=1,L=0;if(d.inward){let U=p.x-d.inward.x,j=p.y-d.inward.y,V=Math.hypot(U,j);V>0&&(N=U/V,L=j/V)}let S=Nt(e,i),A=-L,M=N,C=(p.x+m.x)/2+r+A*S,B=(p.y+m.y)/2+o+M*S,G=b+N*S,X=g+L*S,F=x-N*S,H=R-L*S;return[{x0:b,y0:g,cx0:G,cy0:X,cx1:G+A*S,cy1:X+M*S,x1:C,y1:B},{x0:C,y0:B,cx0:F+A*S,cy0:H+M*S,cx1:F,cy1:H,x1:x,y1:R}]}else{let N=d.inward??{x:p.x-(m.x-p.x),y:p.y-(m.y-p.y)},L=h.inward??{x:m.x-(p.x-m.x),y:m.y-(p.y-m.y)},S=Math.hypot(x-b,R-g),A=(Z,J,se,_e)=>{let ae=J.x-Z.x,ie=J.y-Z.y,ee=Math.hypot(ae,ie),me=ee===0?0:(se*ae+_e*ie)/ee;return Math.max(0,Math.min(S*Er,Ar,me*.5))},M=m.x-p.x,C=m.y-p.y,[B,G]=xt(N.x,N.y,p.x,p.y,A(N,p,M,C)),[X,F]=xt(L.x,L.y,m.x,m.y,A(L,m,-M,-C)),H=a.length?Br(b,g,x,R,a,f):0,U=S===0?1:S,j=(x-b)/U,V=(R-g)/U,ke=-V*H,O=j*H,$=j*Math.abs(H),K=V*Math.abs(H);return[{x0:b,y0:g,cx0:B+r+ke-$,cy0:G+o+O-K,cx1:X+r+ke+$,cy1:F+o+O+K,x1:x,y1:R}]}}var qr=1;function Rn(e,n){return n.flatMap(t=>e[t]??[])}function _t(e,n,t){let r=e[n.from],o=e[n.to];return r?.length&&o?.length?De(r,o,n.from===n.to,0,0,t,Rn(e,n.bypassed)):void 0}function Fr(e){let n=new Map;for(let t of e.nodes)if(_(t)){let r=n.get(t.stable.refName);r?r.push(t):n.set(t.stable.refName,[t])}for(let t of n.values())t.sort((r,o)=>r.stable.start-o.stable.start);return n}function Hr(e,n,t){let r=[];if(e)for(let o=ct(e,n);o<e.length;o++){let s=e[o];if(s.stable.start>=t)break;s.stable.start+s.length<=t&&r.push(s.id)}return r}function Wr(e,n,t,r){let{fromStrand:o,toStrand:s}=e;if(o===void 0||s===void 0)return!0;let a=o===(n.stable.strand??"+"),l=s===(t.stable.strand??"+");return r?a&&l:!a&&!l}function hl(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fr(e),r=[];for(let o=0;o<e.edges.length;o++){let s=e.edges[o],a=n.get(s.from),l=n.get(s.to);if(a!==void 0&&l!==void 0&&_(a)&&_(l)&&a.stable.refName===l.stable.refName){let i=a.stable.start<=l.stable.start,[u,f]=i?[a,l]:[l,a],c=u.stable.start+u.length,d=f.stable.start,h=d-c;if(h>=qr&&Wr(s,a,l,i)){let p=u.stable.refName;r.push({edgeIndex:o,from:s.from,to:s.to,refName:p,start:c,end:d,bp:h,bypassed:Hr(t.get(p),c,d)})}}}return r}function Ne(e){return e.endsWith("-")?"-":"+"}function vt(e){return e==="+"?"-":"+"}function Xr(e){let n=(e.fromStrand??Ne(e.from))===Ne(e.from)?"end":"start",t=(e.toStrand??Ne(e.to))===Ne(e.to)?"start":"end";return{from:n,to:t}}function gl(e){let n=e.edges.map(Xr),t=new Map,r=(d,h,p)=>{let m=`${d}|${h}`,b=t.get(m);b?b.push(p):t.set(m,[p])};e.edges.forEach((d,h)=>{r(d.from,n[h].from,h),r(d.to,n[h].to,h)});let o=d=>{let h=t.get(`${d}|end`);if(h?.length!==1)return;let p=h[0],m=e.edges[p];return m.from===d&&m.to!==d&&n[p].from==="end"&&n[p].to==="start"&&t.get(`${m.to}|start`)?.length===1?p:void 0},s=new Set,a=new Map,l=new Map;for(let d of e.nodes){let h=t.get(`${d.id}|start`),p=h?.length===1?e.edges[h[0]].from:void 0;if(a.has(d.id)||p!==void 0&&o(p)===h[0])continue;let m=[d.id];for(;;){let b=o(m.at(-1)),g=b===void 0?void 0:e.edges[b].to;if(g===void 0||a.has(g))break;s.add(b),m.push(g)}for(let b of m)a.set(b,d.id);m.length>1&&l.set(d.id,m)}for(let d of e.nodes)a.has(d.id)||a.set(d.id,d.id);let i=new Map(e.nodes.map(d=>[d.id,d])),u=[];for(let d of e.nodes){if(a.get(d.id)!==d.id)continue;let h=l.get(d.id);if(!h){u.push(d);continue}let p=h.map(g=>i.get(g)),m=p.filter(_),b=m.length?m.reduce((g,x)=>g.stable.start<=x.stable.start?g:x):p[0];u.push({id:d.id,name:d.name,length:p.reduce((g,x)=>g+x.length,0),depth:d.depth,stable:b.stable})}let f=new Set,c=[];return e.edges.forEach((d,h)=>{let p=a.get(d.from),m=a.get(d.to),b=n[h],g=`${p}|${b.from}>${m}|${b.to}`;s.has(h)||f.has(g)||(f.add(g),c.push({from:p,to:m,...b.from==="start"?{fromStrand:vt(Ne(p))}:{},...b.to==="end"?{toStrand:vt(Ne(m))}:{}}))}),{graph:{...e,nodes:u,edges:c,paths:void 0,pathVisits:void 0},runs:l}}function yl(e,n,t){let r={...e};for(let[o,s]of n){let a=e[o];if(!a?.length)continue;delete r[o];let l=An(a),i=l.at(-1),u=s.map(d=>Math.max(t(d),0)),f=u.reduce((d,h)=>d+h,0)||s.length,c=0;s.forEach((d,h)=>{let p=f?u[h]/f*i:i/s.length,m=h===s.length-1?i:c+p;r[d]=Ot(a,l,c,m),c=m})}return r}function xl(e,n,t){if(e.length===0)return[];let r=An(e),o=r.at(-1);return Ot(e,r,n*o,t*o)}function Bt(e){let n=An(e);return En(e,n,n.at(-1)/2)}function An(e){let n=[0];for(let t=1;t<e.length;t++)n.push(n[t-1]+Math.hypot(e[t].x-e[t-1].x,e[t].y-e[t-1].y));return n}function En(e,n,t){if(t<=0)return{...e[0]};let r=1;for(;r<n.length&&n[r]<t;)r++;if(r>=n.length)return{...e.at(-1)};let o=n[r]-n[r-1],s=o>0?(t-n[r-1])/o:0,a=e[r-1],l=e[r];return{x:a.x+(l.x-a.x)*s,y:a.y+(l.y-a.y)*s}}function Ot(e,n,t,r){let o=[En(e,n,t)];for(let s=0;s<e.length;s++)n[s]>t&&n[s]<r&&o.push({...e[s]});return o.push(En(e,n,r)),o}function Tn(e){return e.length*6.2+8}function kr(e,n){return e.x0<n.x1&&e.x1>n.x0&&e.y0<n.y1&&e.y1>n.y0}function Pt(e,n){return e.x1<=0||e.x0>=n.width||e.y1<=0||e.y0>=n.height}function Yr(e,n){return e.x0>=0&&e.x1<=n.width&&e.y0>=0&&e.y1<=n.height}function Cn(e,n=[]){let t=[...n];return r=>Pt(r,e)||t.some(o=>kr(o,r))?!1:(t.push(r),!0)}function $e(e,n,t){let r=[];for(let s of e){let a=Tn(s.text),l=s.y>n.height/2?-1:1;for(let i=0;i<=(s.stack??0);i++){let u=s.y+l*i*19,f={x0:s.x-a/2,x1:s.x+a/2,y0:u-11-4,y1:u+4};if(Pt(f,n))break;if(Yr(f,n)&&t(f)){r.push({...s,y:u,w:a});break}}}return r}var zr=26,jr=4e4,Vr=8,Ur=8,Kr=5.7,Qr=6,Zr=13,qe=3,nn=2;function rn(e){return(e.length*Kr+Qr+qe)/2}var de=(Zr+qe)/2,Jr=rn("1 bp");function tn(e,n,t){return{x0:n-e,x1:n+e,y0:t-de,y1:t+de}}function qt(e,n){return{x0:6,x1:6+e.length*6.2+8+qe,y0:n-8-qe/2,y1:n+8+qe/2}}function on(e,n,t){return t<n?e:Math.min(Math.max(e,n),t)}function sn(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:e>=1e3?`${+(e/1e3).toFixed(1)} kb`:`${e} bp`}function Gt(e){return`${sn(e)} del`}function es(e,n,t,r){let o=e[0],s=e[e.length-1],a=(n.x-(o.x0+s.x1)/2)*t,l=(n.y-(o.y0+s.y1)/2)*r,i=Math.hypot(a,l);return i===0?{x:0,y:-1}:{x:a/i,y:l/i}}function ns(e,n){return Math.abs(n.x)*(e.x1-e.x0)/2+Math.abs(n.y)*(e.y1-e.y0)/2}function ts(e,n){let t=(e.x1-e.x0)/2,r=(e.y1-e.y0)/2;return Math.min(n.x===0?1/0:t/Math.abs(n.x),n.y===0?1/0:r/Math.abs(n.y))}function os(e,n,t){let r=0;for(let o=1;o<e.length;o++){let s=e[o-1],a=e[o];r+=Math.hypot((a.x-s.x)*n,(a.y-s.y)*t)}return r}function rs(e,n){let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let a of e)for(let l of n[a]??[])t=Math.min(t,l.x),o=Math.max(o,l.x),r=Math.min(r,l.y),s=Math.max(s,l.y);return t===1/0?void 0:{minX:t,minY:r,maxX:o,maxY:s}}var Dt=new WeakMap;function ss(e,n){let t=Dt.get(e);if(t?.nodeLengths===n)return t.order;let r=Object.entries(e).filter(([o,s])=>s.length>0&&n.has(o)).sort(([o],[s])=>n.get(s)-n.get(o));return Dt.set(e,{nodeLengths:n,order:r}),r}var $t=new WeakMap;function as(e,n,t,r){let{scaleX:o,scaleY:s}=t,a=$t.get(e);if(a?.deletions===n&&a.scaleX===o&&a.scaleY===s&&a.version===r)return a.arcs;let l=[];for(let i of[...n].sort((u,f)=>f.bp-u.bp)){let u=_t(e,i,t),f=u?Rt(u):void 0;if(u&&f){let{minX:c,minY:d,maxX:h,maxY:p}=Et(u);l.push({deletion:i,curves:u,apex:f,extent:Math.max((h-c)*o,(p-d)*s)})}}return $t.set(e,{deletions:n,scaleX:o,scaleY:s,version:r,arcs:l}),l}function Ft({nodePositions:e,nodeLengths:n,deletions:t,alleleDeletions:r,axis:o,translateX:s,translateY:a,width:l,height:i,version:u=0}){let{scaleX:f,scaleY:c}=o,d=[],h=[];for(let{deletion:b,curves:g,apex:x,extent:R}of as(e,t,o,u))if(R>=zr){let N=Gt(b.bp),L=rn(N),S=tn(L,0,0),A=x.x*f+s,M=x.y*c+a,C=R>=L*2/nn,B=es(g,x,f,c),G=ns(S,B)+Ur,X=C?A:on(A+B.x*G,L,l-L),F=C?M:on(M+B.y*G,de,i-de),H=Math.hypot(X-A,F-M),U;if(H>0){let j={x:(X-A)/H,y:(F-M)/H},V=ts(S,j);U={arcX:A,arcY:M,labelX:X-j.x*V,labelY:F-j.y*V}}d.push({label:{key:`del:${b.edgeIndex}`,text:N,x:X,y:F,kind:"deletion",leader:U},box:tn(L,X,F)})}let p=new Set,m=[...r??[]].sort((b,g)=>g.bp-b.bp);for(let b of m){let g=rs(b.nodeIds,e);if(!g)continue;let x=Math.max(g.minX*f+s,0),R=Math.min(g.maxX*f+s,l),N=Math.max(g.minY*c+a,0),L=Math.min(g.maxY*c+a,i);if(R<x||L<N)continue;let S=Math.max(R-x,L-N),A=Gt(b.bp),M=rn(A);if(S>=M*2/nn){for(let G of b.nodeIds)p.add(G);let C=on((x+R)/2,M,l-M),B=on((N+L)/2,de,i-de);d.push({label:{key:`alleledel:${b.nodeIds.join(",")}`,text:A,x:C,y:B,kind:"deletion"},box:tn(M,C,B)})}}for(let[b,g]of ss(e,n)){if(p.has(b))continue;let{x,y:R}=Bt(g),N=R*c+a;if(N+de<=0||N-de>=i)continue;let L=os(g,f,c);if(L<Jr*2/nn)continue;let S=sn(n.get(b)),A=rn(S);if(L>=A*2/nn){let M=x*f+s;h.push({label:{key:`node:${b}`,text:S,x:M,y:N,kind:"node"},box:tn(A,M,N)})}}return{deletions:d,nodes:h}}function Ht(e,n){return Math.max(Vr,Math.floor(e*n/jr))}function In(e,n,t=1/0){let r=[];for(let{label:o,box:s}of e){if(r.length>=t)break;n(s)&&r.push(o)}return r}var ls=3.4,Wt=6,cs=8,us=18,ds=2,fs=60,ps=8,Xt=15;function _n(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function Cl(e){let{paneWidth:n,canvasHeight:t,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:n,height:t},i=M=>({x:M.x*s+r,y:M.y*a+o}),u=e.drawnRowLabels.map(({label:M,y:C})=>qt(M,C*a+o)),f=e.referenceStripZonePx??0;f>0&&u.push({x0:0,x1:n,y0:0,y1:f}),e.legendSize.width>0&&u.push({x0:n-Wt-e.legendSize.width,x1:n,y0:0,y1:f+Wt+e.legendSize.height}),e.poppedFrom&&u.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let c=Cn(l,u),d=e.drawnRowLabels.length>0,h=d?Math.min(...e.drawnRowLabels.map(M=>M.y)):1/0,p=e.contigThickness*ls,m=_n(e.bubbleHalos,M=>M.members),b=$e(m.map(M=>{let{x:C,y:B}=i({x:M.labelAt.x,y:Math.min(M.labelAt.y,h)}),G=B-p/2-6;return{item:M,x:C,y:d?Math.max(G,Xt):G,text:M.label}}),l,c),g=Math.max(2,Math.min(ps,Math.floor((o-fs)/19))),x=$e(_n(e.bubbleGlyphs,M=>M.bubble.end-M.bubble.start).flatMap(M=>{let C=(M.bubble.start+M.bubble.end)/2*s+r,B=Tn(M.label)/2;return C<0||C>n?[]:[{item:{glyph:M,glyphX:C},x:Math.min(Math.max(C,B),n-B),y:Xt,text:M.label,stack:g-1}]}),l,c),R=$e(_n(e.genePins,M=>M.gene.end-M.gene.start).map(M=>{let{x:C,y:B}=i(M.at);return{item:M,x:C,y:B+e.contigThickness+us,text:M.covered<.98?`${M.gene.name} \u2026`:M.gene.name,stack:ds}}),l,c),N=e.nodePositions&&e.labelsNodeSizes?Ft({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:n,height:t,version:e.positionsVersion}):{deletions:[],nodes:[]},L=In(N.deletions,c),S=$e(m.flatMap(M=>M.routes.map(C=>{let{x:B,y:G}=i(C.at);return{item:{halo:M,route:C},x:B,y:G+4,text:C.text,stack:cs}})),l,c),A=In(N.nodes,c,Ht(n,t));return{bubbles:b,glyphs:x,genes:R,routes:S,sizes:[...L,...A]}}function Bl(e){return Ge(e)?zt(e):void 0}function zt(e){return{sample:Qe(e.stable.refName),haplotype:it(e.stable.refName),refName:lt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function hs(e,n){let t=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of t)o=o&&s.start-o.end<=n?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function ms(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ol(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Ge(o)){let s=zt(o),a=ms(s),l=t.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):t.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of t.values()){let s=hs(o.spans,n);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function bs(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function Pl(e,n){return e.flatMap(t=>{let r=bs(n,t);return r===void 0?[]:[{...t,sample:r}]})}function Gl(e){return`${e.refName}:${e.start+1}-${e.end}`}function vn(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var jt=le(Ke(),1),Vt=(0,te.createSvgIcon)((0,jt.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Ut=le(Ke(),1),Kt=(0,te.createSvgIcon)((0,Ut.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 Qt=le(Ke(),1),Bn=(0,te.createSvgIcon)((0,Qt.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 gs="Linear genome view",ys="Linear synteny view",xs="No synteny track in this session aligns these assemblies";function Zt({label:e,icon:n,entries:t,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=t,i=s?[{label:e,icon:n,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return t.length===0?i:t.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:n,onClick:o(l)}]:[{label:e,icon:n,type:"subMenu",subMenu:t.map(u=>({label:r(u),onClick:o(u)}))}]}function Vl({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...Zt({label:gs,icon:Bn,entries:e,entryLabel:s=>`${s.sample} ${vn(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?Zt({label:`${ys} (${o} assemblies)`,icon:Vt,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:xs,onSelect:s=>()=>{r(s.trackId)}}):[]]}function Ul({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${vn(e.location)}`,target:e}:void 0,n&&n.assembly!==e?.assembly?{label:`Open in ${n.assembly} \u2014 around this node`,target:n}:void 0].filter(a=>a!==void 0);return[...o&&t?[{label:`Highlight in ${t.assembly}`,icon:Kt,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:Bn,onClick:()=>{r(l)}}))]}var ws=10;function Ss(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=ws*(o.end-o.start)&&(t===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=t/2))}var Ls=40;function ge(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Ns(e,n){let t=ge(e),r=ge(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function eo(e){return e>=dt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Jl(e,n=[]){let t=Rs(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function Rs(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=Ns(r,o);if(a>=Ls)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${eo(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${ge(o)} inv`};let u=o!==r?Ss(e,n):void 0;if(u){let c=u.name?` (${u.name})`:"";return{kind:"repeat",label:`${i} repeat array${c}, ${eo(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${ge(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${ge(o-t)} ins${f}`}:o===t?{kind:"deletion",label:`${ge(t-r)} del${f}`}:{kind:"complex",label:`${ge(t)} ref \u2192 ${i}, ${s} alleles`}}var ec={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},nc={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function tc(e){return e.segments.split(",").filter(Boolean)}function On(e){return e.id.endsWith("-")?"-":"+"}function Pn(e,n){return n===On(e)?e.id:`-${e.id}`}function Es(e,n){let t=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)t[o]=r,r+=e[o];let s=n;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],t[a]=s;return t}function As(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=Es(n,e.pathLength),o=(l,i=!1)=>{for(let u=0;u<r.length;u++){let f=r[u],c=n[u];if(f!==void 0&&c!==void 0&&f<=l&&(l<f+c||i&&l===f+c))return{s:u,local:l-f,room:f+c-l}}},s=(l,i)=>{let u=t[l],f=u.at(-1);i.type==="substitution"&&f?.type==="substitution"&&f.pos+f.seq.length===i.pos?f.seq+=i.seq:u.push(i)},a=e.pathStart;for(let l of ut(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 u=o(a),f=u?Math.min(i,u.room):i;u&&s(u.s,{type:"deletion",pos:u.local,length:f}),a+=f,i-=f}}return t}function no(e,n,t){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of n){let a=s.path.map(f=>r.get(f.name)),l=a.flatMap((f,c)=>f?[c]:[]),i=l[0],u=l.at(-1);if(i!==void 0&&u!==void 0){let f=As(s,a.map(h=>h?.length)),c=l.map(h=>Pn(a[h],s.path[h].strand)),d=a[u].length;o.push({id:t+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:c,sequenceNew:l.map((h,p)=>({nodeName:c[p],mismatches:f[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:u===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ts=["#6baed6","#4292c6","#2171b5","#08519c"],Cs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function to(e){let n=e.is_reverse?Cs:Ts;return n[e.id%n.length]}var Is=4;function Fe(e){let n=new Map;function t(r,o){let s=n.get(r);s?s.push(o):n.set(r,[o])}for(let r of e.edges)t(r.from,r.to),t(r.to,r.from);return n}function _s({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<Is&&o.length>0;l++){let i=[];for(let u of o){let f=t.get(u);if(f){for(let c of f)if(!r.has(c)){r.add(c);let d=n.get(c);d&&_(d)?(s=Math.min(s,d.stable.start+d.length),a=Math.max(a,d.stable.start)):i.push(c)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function vs({nodeId:e,nodeById:n,neighbors:t}){let r=n.get(e);return r===void 0?void 0:_(r)?{start:r.stable.start,end:r.stable.start+r.length}:_s({nodeId:e,nodeById:n,neighbors:t})}function oo(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fe(e),r=new Map;for(let o of e.nodes){let s=vs({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}function an(e){let n=e.split("#"),t=n.length>=2?Number(n[1]):Number.NaN;return{sample:n[0]??e,haplotype:Number.isFinite(t)?t:void 0}}function Bs(e,n,t,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=n.get(l);if(i){o.push(i);for(let u of t.get(l)??[]){let f=n.get(u);f&&(f.stable.rank===0?s.push(f):r.has(u)||(r.add(u),a.push(u)))}}}return{members:o,anchors:s}}function Os(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let t=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=t[0],o=t.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Ps(e,n,t){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of t.get(n.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of t.get(a)??[])if(r.has(i)){let u=o.get(i);(u===void 0||l<u)&&(o.set(i,l),s.push(i))}}return o}function Gs(e,n,t){let r=Ps(e,n,t),o=[...e].sort((i,u)=>r.get(i.id)-r.get(u.id)),s=new Map(o.map((i,u)=>[i.id,u])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,u]of o.entries()){let f=0;for(let c of t.get(u.id)??[]){let d=a.get(c);d&&s.get(c)<i&&(f=Math.max(f,l.get(c)+d.length))}l.set(u.id,f)}return{offsets:l,ordered:o}}function so(e){let n=new Map(e.nodes.filter(Ge).map(s=>[s.id,s])),t=Fe(e),r=new Set,o=[];for(let s of n.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Bs(s.id,n,t,r),i=Os(l);if(i){let{offsets:u,ordered:f}=Gs(a,i.entry,t);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:f.map(c=>c.id),nodeOffsets:f.map(c=>u.get(c.id)),pathLength:f.reduce((c,d)=>Math.max(c,u.get(d.id)+d.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ds=1,$s=.015;function ln({graph:e,span:n,rowY:t,positions:r}){let o=n*$s,s=so(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let c=f.refSpan-f.pathLength;c>=Ds&&l.push({nodeIds:f.nodeIds,bp:c});let d=Math.max(f.refSpan,o),h=f.pathLength>0?d/f.pathLength:0;f.nodeIds.forEach((p,m)=>{let b=a.get(p);if(b){let g=f.nodeOffsets[m],x=d/f.nodeIds.length,R=L=>f.start+L*h,N=t(b);r[p]=h?[{x:R(g),y:N},{x:R(g+b.length),y:N}]:[{x:f.start+m*x,y:N},{x:f.start+(m+1)*x,y:N}]}})}let i=Fe(e),u=Object.keys(r);for(let f of u){let c=r[f].at(-1).x;for(let d of i.get(f)??[]){let h=a.get(d);if(h&&!(d in r)){let p=t(h);r[d]=[{x:c,y:p},{x:c+o,y:p}],u.push(d)}}}return l}function qs(e){let n=new Set;for(let t of e.nodes)t.stable&&n.add(t.stable.rank);return new Map([...n].sort((t,r)=>t-r).map((t,r)=>[t,r]))}function ao(e,n){let t=ce(e);if(t.length===0)return;let r=Je(t,n),o=qs(e),s=ue(t),a=ln({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,u])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:u*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Fs=12,Gn=20;function io(e){return 10+8*Math.log2(1+e.length)}function fe(e,n){return e<n?-1:e>n?1:0}function co(e,n){return fe(e.at,n.at)||fe(e.side,n.side)||fe(e.hops,n.hops)}var lo={at:1/0,side:0,hops:0};function Hs(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=ks(e);return e.nodes.map(r=>r.id).sort((r,o)=>co(t.get(r)??lo,t.get(o)??lo)||fe(n.get(r).name,n.get(o).name)||fe(r,o))}function Ws(e,n){let t=new Set(e.nodes.map(f=>f.id)),r=new Map(n.map(f=>[f.id,f.stable.start])),o=new Map,s=new Map;n.forEach((f,c)=>{s.set(f.id,n[c-1]?.id),o.set(f.id,n[c+1]?.id)});let a=n[0]?.id,l=(f,c)=>{let d=o.get(f);o.set(f,c),s.set(c,f),o.set(c,d),d!==void 0&&s.set(d,c)},i=(f,c)=>{let d=s.get(f);d===void 0?(a=c,s.set(c,void 0),o.set(c,f),s.set(f,c)):l(d,c)};for(let f of e.paths??[]){let c=0,d=0,h;for(let g of f.nodeIds){let x=r.get(g);x!==void 0&&(h!==void 0&&x!==h&&(x>h?c++:d++),h=x)}let p=d>c?[...f.nodeIds].reverse():f.nodeIds,m,b=new Set;for(let g of p)if(o.has(g)){if(m===void 0)for(let x of b)i(g,x);m=g}else t.has(g)&&(m===void 0?b.add(g):(l(m,g),m=g))}let u=[];for(let f=a;f!==void 0;f=o.get(f))u.push(f);return u}function Xs(e,n){let t=[...n.entries()].sort(([a,l],[i,u])=>co(l,u)||fe(a,i)).map(([a])=>a),r=t.length;for(let a of t){let l=n.get(a);for(let i of e.get(a)??[])n.has(i)||(n.set(i,{at:l.at,side:1,hops:l.hops+1}),t.push(i))}let o=new Set(t.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=n.get(a),i=[a];s.add(a);let u=!0;for(let f of i){let{hops:c}=n.get(f),d=!0,h=!1;for(let p of e.get(f)??[]){let m=n.get(p);m.at===l&&o.has(p)?(d&&=m.hops<=c,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,u&&=m.at<l)}u&&=!d||h}if(u)for(let f of i){let c=n.get(f);n.set(f,{...c,side:-1,hops:-c.hops})}}}function ks(e){let n=new Set(e.nodes.map(s=>s.id)),t=new Map;for(let s of e.edges)!n.has(s.from)||!n.has(s.to)||((t.get(s.from)??t.set(s.from,[]).get(s.from)).push(s.to),(t.get(s.to)??t.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(_).sort((s,a)=>fe(s.stable.start,a.stable.start)||fe(s.name,a.name)),o=new Map;return Ws(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),Xs(t,o),o}function Ys(e){let n=new Map(e.nodes.map(c=>[c.id,c])),t=Hs(e),r=new Map(t.map((c,d)=>[c,d])),o=c=>_(n.get(c)),s=new Map(t.map(c=>[c,[]])),a=new Map(t.map(c=>[c,[]])),l=(c,d)=>{s.get(d).push(c),a.get(c).push(d)};for(let c of e.edges)c.from===c.to||!r.has(c.from)||!r.has(c.to)||(r.get(c.from)<r.get(c.to)?l(c.from,c.to):l(c.to,c.from));let i=t.filter(o);for(let c=1;c<i.length;c++)l(i[c-1],i[c]);let u=new Map;for(let c of t){let d=0;for(let h of s.get(c))d=Math.max(d,u.get(h)+1);u.set(c,d)}for(let c=t.length-1;c>=0;c--){let d=t[c],h=a.get(d);if(o(d)||h.length===0)continue;let p=1/0;for(let g of h)p=Math.min(p,u.get(g));let m=u.get(d),b=Math.max(m,p-1);u.set(d,Math.floor((m+b)/2))}let f=[];for(let c of t)(f[u.get(c)]??=[]).push(c);return{layers:f,layerOf:u,preds:s}}function uo(e){if(!e.nodes.some(_))return;let n=new Map(e.nodes.map(c=>[c.id,c])),t=c=>_(n.get(c)),{layers:r,layerOf:o,preds:s}=Ys(e),a=r.map(c=>{let d=0;for(let h of c)d=Math.max(d,io(n.get(h)));return d}),l=[],i=0;for(let c=0;c<r.length;c++)l[c]=i,i+=a[c]+Fs;let u=new Map;for(let c of r){let d=[];for(let p of c){if(t(p)){u.set(p,0);continue}let m=s.get(p).filter(g=>u.has(g)),b=0;for(let g of m)b+=u.get(g)/m.length;d.push({id:p,ideal:b===0?Gn:b})}d.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of d){let b=Math.round(m/Gn);b===0&&(b=m>=0?1:-1);for(let g=1;h.has(b);g++)h.has(b+g)?h.has(b-g)||(b-=g):b+=g;h.add(b),u.set(p,b*Gn)}}let f={};for(let c of e.nodes){let d=o.get(c.id),h=io(c),p=l[d]+a[d]/2,m=u.get(c.id);f[c.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function zs(e,n){let t=new Map;for(let o of e.nodes)if(Ze(o)){let{sample:s}=an(o.stable.refName);t.set(s,(t.get(s)??0)+o.length)}let r=new Map(n.map((o,s)=>[o,s]));return[...t.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||t.get(s)-t.get(o)||o.localeCompare(s))}function fo(e,n,t=[]){let r=ce(e),o=zs(e,t);if(r.length===0||o.length===0)return;let s=Je(r,n),a=new Map(o.map((d,h)=>[d,h+1])),l=ue(r),i=o.length+1,u=ln({graph:e,span:s,rowY:d=>{let h=d.stable;return((h?a.get(an(h.refName).sample):void 0)??i)*20},positions:l}),c=[{label:an(r[0].stable.refName).sample,y:0},...o.map(d=>({label:d,y:a.get(d)*20}))];return{nodePositions:l,rowLabels:c,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:u}}function Dn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Xe=!1,po=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Co(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(n=>po[n.id%po.length]),trackAlpha:e.trackAlpha??(()=>1)}}var v=Co({}),Wn=null,y=[],w=[],E=[],I=new Map,Ae=[],T=[],ye=[],kn=[],Yn=[],Q=-1,D=Dn(),Xn={minX:0,maxX:0,minY:0,maxY:0},He,cn=new Map;function Io(e,n,t=[],r={}){if(v=Co(r),Wn=r.bed??null,D=Dn(),ye=[],kn=[],Yn=[],Ae=[],Xn={minX:0,maxX:0,minY:0,maxY:0},He=void 0,cn=new Map,e.length===0||n.length===0)return;let o=$n(e);y=[],o.forEach((i,u)=>{y[u+1]=i}),w=$n(n);let s=t.length>0;E=$n(Ba(t));for(let i=w.length-1;i>=0;i-=1){let u=w[i];if(u.type===void 0&&(u.type="haplotype"),u.hidden===!0){w.splice(i,1);continue}u.indexOfFirstBase!==void 0&&(He=u.name)}if(w.length===0)return;Vs(0),I=bo(),Re(w),v.showReads&&E.length>0&&Re(E),To(),v.mergeNodesFlag&&(go(),Fn(),v.showReads&&E.length>0&&qn(),va(),I=bo(),To(),Re(w),v.showReads&&E.length>0&&Re(E)),go(),ma(),Xe&&console.log(`${y.length} nodes.`),Fn(),Q=xo(),ba(),Fn(),Q=xo();let a=v.showReads&&v.coarsenedReadView&&!s;if(a){let i=He===void 0?-1:w.findIndex(c=>c.name===He),u=i===-1?0:i,f=w.filter((c,d)=>d!==u);if(f.length>0){let c=No(f,"haplotype");c.length>0&&(w=[w[u]],E=c)}}Ea(),Ma(),v.showExonsFlag&&Wn!==null&&Ra();let l=v.showReads&&v.coarsenedReadView&&E.length>0&&!a;return v.showReads&&E.length>0?(Us(),qn(),Re(E),l&&(E=No(E,"read"),qn(),Re(E)),Qs(),w=w.concat(E)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),ya(),Ca(),Xe&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(ye)),ca(),{nodes:y,tracks:w,reads:E,nodeMap:I,shapes:D,bounds:Xn,maxOrder:Q,trackForRuler:He,coarsenedEdgeMeta:cn}}function Ee(e,n="plain"){return v.trackColor(e,n)}function js(e){return v.trackAlpha(e)}function $n(e){return structuredClone(e)}function k(e){let n=String(e);return n.length>=1&&n.startsWith("-")}function P(e){return k(e)?String(e).substring(1):e}function pe(e){return k(e)?e:`-${e}`}function _o(e){return k(e)?P(e):pe(e)}function un(e){return(e||1/e)>=0}function Vs(e){let n=new Set,t=w[e].sequence;for(let r=0;r<t.length;r+=1){let o=t[r];if(k(o)){let s=P(o),a=t.indexOf(s);(a===-1||a>r)&&n.add(s)}}for(let r of w){t=r.sequence;for(let o=0;o<t.length;o+=1){let s=t[o];k(s)?n.has(P(s))&&(t[o]=P(s)):n.has(s)&&(t[o]=pe(s))}}y.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function Us(){Ae=[];for(let n=0;n<=Q;n+=1)Ae[n]=[];let e=new Map;y.forEach(n=>{n.y!==void 0&&ho(e,n.order,n.y+n.contentHeight)}),w.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{ho(e,t.order,(t.y??0)+n.width)})}),y.forEach((n,t)=>{n.order>=0&&n.y===void 0&&(n.y=(e.get(n.order)??0)+25,n.contentHeight=0,Ae[n.order].push(t))})}function ho(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var dn=7;function Ks(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),E.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=dn),e.path.length===1){let t=e.path[0].node;t!==null&&y[t].internalReads.push(n)}else e.path.forEach((t,r)=>{if(r===0){let o=e.path[0].node;o!==null&&y[o].outgoingReads.push([n,r])}else{let o=t.node;o!==null&&y[o].incomingReads.push([n,r])}})})}function Qs(){sa(),Ks();let e=y.slice();e.sort(fn);let n=new Map;for(let a=0;a<E.length;a++){let l=E[a].sourceTrackID,i=n.get(l);i===void 0?n.set(l,[a]):i.push(a)}let t=Array.from(n.keys()).sort((a,l)=>a-l),r=t.length>1?dn:0;e.forEach(a=>{if(a)for(let l of t)Zs(n.get(l),a,r)});let o=ra(),s=[];E.forEach((a,l)=>{let i=a.path.length,u=new Array(i),f;for(let h=0;h<i;h++){h===0?u[h]=void 0:u[h]=f??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(f=p)}let c=new Array(i),d;for(let h=i-1;h>=0;h--){h===i-1?c[h]=void 0:c[h]=d??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(d=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=u[p],b=c[p],g=!!(b&&m&&b.isForward!==void 0&&m.isForward!==void 0&&(m.order>b.order||b.order===m.order&&b.isForward===m.isForward));h.betweenCycleReverseTraversal=g,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(ea),s.forEach(a=>{let l=E[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Xe&&(console.log("Reads:"),console.log(E))}function Zs(e,n,t){let r=new Set(e),o=n.incomingReads.filter(([p])=>r.has(p)),s=n.outgoingReads.filter(([p])=>r.has(p)),a=n.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(t=0);let l=n.y+n.contentHeight+t*2,i=o.map(p=>{let[m,b]=p,g=E[m].path,x=b+1,R;for(let N=1;N<=b;N++){let L=g[b-N]?.y;if(L!==void 0){x=N,R=L;break}}return{entry:p,decisionStep:x,y:R}});i.sort(Js),o=i.map(p=>p.entry);let u=l,f=new Map;o.forEach(p=>{let m=E[p[0]];m.path[p[1]].y=u,mo(f,m,p[1],u,n),u+=m.width});let c=u;s.sort(na);let d=new Map;u=l,s.forEach(p=>{let m=E[p[0]],b=m.firstNodeOffset??0;m.path[p[1]].y=u,d.set(u,b);let g=f.get(u);g===void 0||g+1<=b?(u+=m.width,c=Math.max(c,u)):(f.set(u,0),o.forEach(x=>{let R=E[x[0]],N=R.path[x[1]];N.y!==void 0&&N.y>=u&&(N.y+=m.width,mo(f,R,x[1],N.y,n))}),u+=m.width,c+=m.width)}),a.sort(oa),a.forEach(p=>{let m=E[p],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(u=l;b<(f.get(u)??-1/0)+2||g>(d.get(u)??1/0)-3;)u+=m.width||dn;m.path[0].y=u,f.set(u,g),c=Math.max(c,u)});let h=c-n.y-n.contentHeight;n.contentHeight+=h,Na(n,h)}function Js(e,n){return e.decisionStep!==n.decisionStep?e.decisionStep-n.decisionStep:e.y===void 0||n.y===void 0?(e.y===void 0?0:1)-(n.y===void 0?0:1):e.y-n.y}function mo(e,n,t,r,o){t===n.path.length-1?e.set(r,n.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function ea(e,n){let t=E[e.readIndex],r=E[n.readIndex],o=t.path[e.pathIndex],s=r.path[n.pathIndex];if(o.order!==s.order)return o.order-s.order;if(t.sourceTrackID!==r.sourceTrackID)return t.sourceTrackID-r.sourceTrackID;if(e.previousNode&&n.previousNode){let i=y[e.previousNode],u=y[n.previousNode];if(i&&u&&i.order!==u.order)return i.order-u.order}let a=e.previousY??0,l=n.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function na([e,n],[t,r]){let o=E[e],s=E[t],a,l,i=o.path.length-1,u=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&u>=0;)l=s.path[u]?.y,u-=1;if(a&&l)return a-l;let f=o.path[n]?.node,c=s.path[r]?.node,d=f!=null?y[f]:null,h=c!=null?y[c]:null;for(;d!=null&&h!=null&&d===h;){if(n<o.path.length-1){for(n+=1;o.path[n]?.node===null;)n+=1;let m=o.path[n]?.node;d=m!=null?y[m]:null}else d=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?y[m]:null}else h=null}if(d!=null)return h!=null?fn(d,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 ta(e,n){if(e.path===void 0||n.path===void 0)return(e.path===void 0?0:1)-(n.path===void 0?0:1);let t=e.path,r=n.path,o=0,s=0;for(;o<t.length&&s<r.length;){let a=t[o],l=r[s],i=a.order,u=l.order;if(i===u&&a.node&&l.node)return(l.y??0)-(a.y??0);i<u?o+=1:(i>u||(o+=1),s+=1)}return 0}function oa(e,n){let t=E[e],r=E[n],o=t.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=t.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function ra(){let e=[];for(let n=0;n<=Q;n+=1)e.push(0);return y.forEach(n=>{n.y!==void 0&&(e[n.order]=Math.max(e[n.order],n.y+n.contentHeight+20))}),w.forEach(n=>{n.path.forEach(t=>{e[t.order]=Math.max(e[t.order],(t.y??0)+n.width)})}),e}function sa(){E.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=un(e.indexSequence[0]),r=y[n],o,s;e.path=[],e.path.push({order:r.order,isForward:t,node:n});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=t,n=Math.abs(e.indexSequence[a]),t=un(e.indexSequence[a]),r=y[n],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});t?e.path.push({order:r.order,isForward:!0,node:n}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:n}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});t?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:n})):e.path.push({order:r.order,isForward:!1,node:n})}else t!==s?e.path.push({order:r.order,isForward:t,node:n}):(e.path.push({order:r.order,isForward:!t,node:null}),e.path.push({order:r.order,isForward:t,node:n}))})}function qn(){E.forEach(e=>{let n=0;for(;n<e.sequence.length&&e.sequence[n].startsWith("-");)n+=1;if(n===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=P(e.sequence[a]);let t=e.sequenceNew??[];t.reverse(),e.sequenceNew=t;for(let a of t)a.nodeName=P(a.nodeName),aa(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 aa(e,n){e.forEach(t=>{t.type==="insertion"?t.pos=n-t.pos:t.type==="deletion"?t.pos=n-t.pos-(t.length??0):t.type==="substitution"&&(t.pos=n-t.pos-(t.seq?.length??0)),t.seq!==void 0&&(t.seq=vo(t.seq).split("").reverse().join(""))})}var ia={A:"T",T:"A",C:"G",G:"C"};function vo(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=ia[e.charAt(t)]??"N";return n}function Re(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=I.get(P(r)),s=y[o]?.switched??!1;s&&(r=_o(r));let a=I.get(P(r));if(a===0)throw new Error("Node "+P(r)+" has prohibited index 0");k(r)!==s?n.indexSequence.push(-a):n.indexSequence.push(a)})})}var la=20;function ca(){let e={minX:99,maxX:-99,minY:99,maxY:-99};y.forEach(n=>{n&&(n.x!==void 0&&(e.minX=Math.min(e.minX,n.x),e.maxX=Math.max(e.maxX,n.x+la+n.pixelWidth)),n.y!==void 0&&(e.minY=Math.min(e.minY,n.y-10),e.maxY=Math.max(e.maxY,n.y+n.contentHeight+10)))}),w.forEach(n=>{n.path.forEach(t=>{let r=t.y??0;e.maxY=Math.max(e.maxY,r+n.width),e.minY=Math.min(e.minY,r)})}),Xn=e}function oe(e){let n=I.get(P(e)),t=n===void 0?void 0:y[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function bo(){return I=new Map,y.forEach((e,n)=>{e&&I.set(e.name,n)}),I}function go(){let e=y.map(()=>new Set),n=y.map(()=>new Set),t=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),n[a].add(s)}};w.forEach(t),v.showReads&&E.length>0&&E.forEach(t),y.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(n[o]))})}function yo(e){let n=0,t=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){T[s]===void 0&&(T[s]=t);let a=T[s];a<r&&(r=a),n=a,t=a-1}else{T[s]===void 0&&(T[s]=n);let a=T[s];n=a+1,t=a}}),r<0&&zn(-r)}function ua(e){let n=0,t=0;for(;n<e.length&&T[Math.abs(e[n])]===void 0;)n+=1;if(n>=e.length)return null;let r=e[n],o,s;r>=0?(o=T[r]-1,s=-1):(o=T[-r]+1,s=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(e[a]);T[l]===void 0&&(T[l]=o,t=Math.min(t,o),o+=s)}return t<0&&zn(-t),n}var da=-1;function fa(e){let n=[];for(let t of e)n.push(t??da);return n}function Fn(){let e,n,t,r,o=0,s=v.showReads&&E.length>0?w.concat(E):w,a={stamp:new Int32Array(y.length),generation:0};T=new Array(y.length).fill(void 0),y.forEach(i=>{i&&(i.order=void 0)}),yo(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Xe&&console.log(`generating order for track ${i+1}`),t=ua(s[i].indexSequence),t===null){s[i].type==="haplotype"?yo(s[i].indexSequence):(s.splice(i,1),E.splice(i-w.length,1),i-=1);continue}for(e=ha(s[i].indexSequence);t<e.length;){for(r=t,t+=1;t<e.length&&T[e[t]]===void 0;)t+=1;if(t<e.length){n=T[e[r]]+1;for(let u=r+1;u<t;u+=1)T[e[u]]=n,n+=1;if(T[e[t]]>T[e[r]])T[e[t]]<n&&Mo(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!pa(e[t],e[r],a))Mo(e[t],e[t-1],n);else if(s[i].indexSequence[r]<0||y[e[r+1]].degree<2&&T[e[t]]<T[e[r]]){n=T[e[r]]-1;for(let u=r+1;u<t;u+=1)T[e[u]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=T[e[r]]+1;for(let u=r+1;u<e.length;u+=1){let f=e[u];T[f]===void 0&&(T[f]=n,n+=1)}}else{n=T[e[r]]-1;for(let u=r+1;u<e.length;u+=1){let f=e[u];T[f]===void 0&&(T[f]=n,o=Math.min(o,n),n-=1)}}}}o<0&&zn(-o);let l=fa(T);T=l,l.forEach((i,u)=>{let f=y[u];f!==void 0&&(f.order=i)})}function pa(e,n,t){t.generation+=1;let{stamp:r,generation:o}=t,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===n)return!0;for(let l of y[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function xo(){let e=-1;return T.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function ha(e){return e.map(n=>Math.abs(n))}function zn(e){T.forEach((n,t)=>{n!==void 0&&(T[t]=n+e)})}function Mo(e,n,t){let r=new Map,o=[[e,t]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=T[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),y[a].successors.forEach(u=>{T[u]>i&&u!==n&&o.push([u,l+1])}),a!==e&&y[a].predecessors.forEach(u=>{T[u]>i&&u!==n&&o.push([u,l+1])}))}r.forEach((a,l)=>{T[l]=a})}function ma(){y.forEach(e=>{e.tracks=[]}),w.forEach(e=>{e.indexSequence.forEach(n=>{y[Math.abs(n)].tracks.push(e.id)})}),y.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function ba(){let e=w[0],n=w.slice(1,w.length);if(v.showReads&&E.length>0&&(n=n.concat(E)),ga(n,e),v.showReads&&E.length>0){for(let t=0;t<E.length;t++)if(E[t]!==n[t+w.length-1])throw new Error("Read inequality")}}function ga(e,n){let t=new Map,r=n?new Set(n.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=P(s[a]),i=oe(l);if(r&&!r.has(l)){let u=a>0?oe(s[a-1]).order:void 0,f=a<s.length-1?oe(s[a+1]).order:void 0;(u===void 0||u<i.order)&&(f===void 0||i.order<f)&&wo(t,l,k(s[a])?1:-1),(u===void 0||u>i.order)&&(f===void 0||i.order>f)&&wo(t,l,k(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=t.get(P(s));l!==void 0&&l>0&&(o.sequence[a]=_o(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=vo(a.seq),a.switched=!0}})}function wo(e,n,t){e.set(n,(e.get(n)??0)+t)}function ya(){let e=0,n=20,t=-1,r=y.slice();r.sort(fn);let o=xa();r.forEach(s=>{s.order>=0&&(s.order>t&&(t=s.order,e=n+10*o[s.order]),s.x=e,n=Math.max(n,e+40+s.pixelWidth))})}function xa(){let e=[],n=[],t=[],r=[];for(let o=0;o<=Q;o+=1)e.push(0),n.push(0),t.push(0);w.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:n[a.order]=n[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));t[a.order]=Math.max(i/17.5,t[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=Q;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function Ma(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=Q;i+=1){ye[i]=[],l[i]=new Map,a[i]=[];for(let u=0;u<w.length;u+=1)a[i][u]=null}w.forEach((i,u)=>{n=Math.abs(i.indexSequence[0]),t=un(i.indexSequence[0]),r=y[n],i.path=[],i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,0,a,l),e=1;for(let f=1;f<i.sequence.length;f+=1)if(o=r,s=t,n=Math.abs(i.indexSequence[f]),t=un(i.indexSequence[f]),r=y[n],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),W(o.order,null,u,e,a,l),e+=1);for(let c=o.order+1;c<r.order;c+=1)i.path.push({order:c,lane:null,isForward:!0,node:null}),W(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!0,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:n}),W(r.order,n,u,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),W(o.order,null,u,e,a,l),e+=1);for(let c=o.order-1;c>r.order;c-=1)i.path.push({order:c,lane:null,isForward:!1,node:null}),W(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:n}),W(r.order,n,u,e,a,l),e+=1)}else t!==s?(i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!t,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,e,a,l),e+=1)});for(let i=0;i<=Q;i+=1)Sa(ye[i],i)}function W(e,n,t,r,o,s){let a={trackID:t,segmentID:r,compareToFromSame:o[e][t]??null},l=n===null?void 0:s[e].get(n);if(l===void 0){let i={type:"single",node:n,tracks:[a]};ye[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function wa(e,n){let t;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(w[o.trackID].path[o.segmentID-1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<w[o.trackID].path.length-1&&w[o.trackID].path[o.segmentID+1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID+1].y;else{for(t=o.segmentID-1;t>=0&&w[o.trackID].path[t].order!==n-1;)t-=1;t<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=w[o.trackID].path[t].lane??void 0,o.idealY=w[o.trackID].path[t].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Sa(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;wa(e,n),e.sort(Lo),e.forEach(l=>{l.node!==null?(y[l.node].topLane=t,s&&(o-=10),y[l.node].y=o,y[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(Lo),l.tracks.forEach(i=>{i.lane=t,i.trackID===a&&l.node===null&&s&&(o+=10),w[i.trackID].path[i.segmentID].lane=t,w[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),t+=1,o+=w[i.trackID].width,l.node!==null&&(y[l.node].contentHeight+=w[i.trackID].width),a=i.trackID}),o+=25}),La(e,r)}function La(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{So(e,o)<r&&(r=So(e,o),t=o)}),e.forEach(o=>{o.node!==null&&(y[o.node].y+=t),o.tracks.forEach(s=>{let a=w[s.trackID].path[s.segmentID];a.y=a.y+t})})}function Na(e,n){e.order<0||ye[e.order]===void 0||(ye[e.order].forEach(t=>{if(t.node!==null){let r=y[t.node];r!==e&&r.y>e.y&&(r.y+=n,t.tracks.forEach(o=>{let s=w[o.trackID].path[o.segmentID];s.y=s.y+n}))}else t.tracks.forEach(r=>{let o=w[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+n)})}),Ae[e.order].length>0&&Ae[e.order].forEach(t=>{y[t]!==e&&y[t].y>e.y&&(y[t].y+=n)}))}function So(e,n){let t=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&w[o.trackID].type!=="read"&&(t+=Math.abs(o.idealY-n-w[o.trackID].path[o.segmentID].y)*w[o.trackID].width)})}),t}function Lo(e,n){return e.idealLane!==void 0?n.idealLane!==void 0?e.idealLane<n.idealLane?-1:e.idealLane>n.idealLane?1:0:-1:n.idealLane!==void 0?1:0}function fn(e,n){if(!e)return n?-1:0;if(!n)return 1;if(e.order!==void 0){if(n.order!==void 0){if(e.order<n.order)return-1;if(e.order>n.order)return 1;if(e.y!==void 0&&n.y!==void 0){if(e.y<n.y)return-1;if(e.y>n.y)return 1}return 0}return-1}return n.order!==void 0?1:0}function Ra(){let e,n,t={};Wn.forEach(r=>{let o=0;for(;o<w.length&&w[o].name!==r.track;)o+=1;o<w.length&&(e=0,w[o].path.forEach(s=>{s.node!==null&&(t={},n=e+y[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(t.start=0),e<r.start&&n>=r.start&&(t.start=r.start-e),n<=r.end&&n>=r.start&&(t.end=n-e,n<r.end&&(t.continue=!0)),n>r.end&&e<=r.end&&(t.end=r.end-e),t.start!==void 0&&(t.type=r.type,t.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(t)),e=n+1)}))})}function Ea(){let e=!0,n=4,t=v.trackWidth;w.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*n):(r.width=t,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(e=!1)}),e&&w.forEach(r=>{r.freq!==void 0&&(r.width=t)})}function Aa(e){let n=e.path[0],t=y[n.node],r=e.firstNodeOffset??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Ta(e){let n=e.path[e.path.length-1],t=y[n.node],r=e.finalNodeCoverLength??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Bo(e,n){return n>e.sequenceLength?null:jn(e,n)}function jn(e,n){let[t,r]=_a(e);if(e.sequenceLength===0)return t;let o=Math.min(Math.max(n,0),e.sequenceLength);return t+o/e.sequenceLength*(r-t)}function Ca(){let e,n,t,r,o,s,a,l,i;for(let c=0;c<=Q;c+=1)kn.push(0),Yn.push(0);let u=[],f=[];y.forEach(c=>{c.x!==void 0&&(u[c.order]=c.x,f[c.order]===void 0?f[c.order]=c.x+c.pixelWidth:f[c.order]=Math.max(f[c.order],c.x+c.pixelWidth))}),w.sort(ta),w.forEach(c=>{a="plain",o=Ee(c,a),s=js(c);let d=a,h=()=>(d!==a&&(d=a,o=Ee(c,a)),o);t=c.path[0].y,c.type!=="read"?c.sequence[0].startsWith("-")?e=f[c.path[0].order]+20:e=u[c.path[0].order]-20:e=Aa(c);for(let p=0;p<c.path.length;p+=1)c.path[p].y===t?c.path[p].features!==void 0&&(i=p>0&&c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart):(c.path[p-1].isForward?n=f[c.path[p-1].order]:n=u[c.path[p-1].order],n!==e&&(o=h(),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})),c.path[p].order-1===c.path[p-1].order?(e=n,n=u[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e,yStart:t,xEnd:n+1,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p].order+1===c.path[p-1].order?(e=n,n=f[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e+1,yStart:t,xEnd:n,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p-1].isForward?(r=c.path[p].y,Ao(1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=f[c.path[p].order],t=c.path[p].y):(r=c.path[p].y,Ao(-1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=u[c.path[p].order],t=c.path[p].y),c.path[p].features!==void 0&&(i=c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart));c.type!=="read"?c.path[c.path.length-1].isForward?n=f[c.path[c.path.length-1].order]+20:n=u[c.path[c.path.length-1].order]-20:n=Ta(c),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})})}var Ia=1e9;function No(e,n){cn=new Map;let t=new Map,r=v.ignoreStrand;for(let d of e){let h=d.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],b=h[p+1],g=Math.abs(m),x=Math.abs(b),R=y[g],N=y[x];if(!R||!N)continue;let L;if(r){let A=`${m}>${b}`,M=`${-b}>${-m}`;L=A<M?A:M}else L=`${m}>${b}`;let S=t.get(L);S===void 0?t.set(L,{sSigned:m,dSigned:b,sName:m<0?`-${R.name}`:R.name,dName:b<0?`-${N.name}`:N.name,count:1,sourceTrackID:d.sourceTrackID}):S.count+=1}}let o=0;for(let d of t.values())d.count>o&&(o=d.count);let s=dn,a=60,l=d=>o<=1?s:s+(a-s)*Math.sqrt(d/o),i=[],u=0;for(let d of t.values()){let h=Ia+u,p=`${d.count.toLocaleString()} ${n}${d.count===1?"":"s"}: Node ${d.sName} \u2192 Node ${d.dName}`;cn.set(h,{count:d.count,label:p});let m=y[Math.abs(d.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:d.sourceTrackID,type:"read",name:p,sequence:[d.sName,d.dName],indexSequence:[],path:[],width:l(d.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:d.sName,mismatches:[]},{nodeName:d.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:d.count}),u+=1}let f="?",c=0;for(let d of y){if(!d)continue;let h=d.contentHeight;h>c&&(c=h,f=d.name)}return Xe&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${c.toFixed(1)})`),i}function Ro(e,n,t,r,o,s,a,l,i){let u=r,f,c,d,h;n-=8,t+=8;let p=y[e.node].sequenceLength;return e.features.sort((m,b)=>m.start-b.start),e.features.forEach(m=>{u!==m.type&&(f=Ee(o,u),e.isForward?(d=n+Math.round(m.start*(t-n+1)/p),i&&d<n+8&&(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:d,yStart:a,xEnd:h,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),d>s+1&&D.featureRectangles.push({xStart:s,yStart:a,xEnd:d-1,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(d=t-Math.round(m.start*(t-n+1)/p),i&&d>t-8&&(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:h,yStart:a,xEnd:d,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),s>d+1&&D.featureRectangles.push({xStart:d+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=d,u=m.type),(m.end<p-1||m.continue===void 0)&&(f=Ee(o,u),e.isForward?(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=h+1,u="plain")}),{xStart:s,highlight:u}}var Eo=7;function Ao(e,n,t,r,o,s,a,l,i,u){let f=e===1?Yn:kn,c=10*f[l],d=n+e*(c+5),h=Eo,p=Math.min(Eo,o),m=Math.min(t,r),b=Math.max(t,r),g=e===1?n:d-1,x=e===1?d:n,R=A=>{D.verticalRectangles.push({xStart:g,yStart:A,xEnd:x,yEnd:A+o-1,color:s,id:a,name:u,type:i})};R(t),D.verticalRectangles.push({xStart:e===1?d+h:d-h-p,yStart:m+o+h-1,xEnd:e===1?d+h+p-1:d-h-1,yEnd:b-h+1,color:s,id:a,name:u,type:i}),R(r);let N=d+e*h,L=d+e*(h+p),S=`M ${d} ${b}`;S+=` Q ${N} ${b} ${N} ${b-h}`,S+=` H ${L}`,S+=` Q ${L} ${b+o} ${d} ${b+o}`,S+=" Z ",D.corners.push({path:S,color:s,id:a,type:i}),S=`M ${d} ${m}`,S+=` Q ${L} ${m} ${L} ${m+o+h}`,S+=` H ${N}`,S+=` Q ${N} ${m+o} ${d} ${m+o}`,S+=" Z ",D.corners.push({path:S,color:s,id:a,type:i}),f[l]+=1}function _a(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function To(){switch(y.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),v.nodeWidthOption){case"compressed":y.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":y.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":y.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=v.charWidth;y.forEach(n=>{n.width=n.sequenceLength;let t=n.seq?.length??1;n.pixelWidth=Math.round(e*t)});break}default:throw new Error(`${v.nodeWidthOption} not implemented`)}}function va(){let e,n,t=Array.from(y,()=>new Set),r=Array.from(y,()=>new Set),o;v.showReads&&E.length>0?o=w.concat(E):o=w,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)k(l.sequence[i])?(e=P(l.sequence[i]),i>0?(n=l.sequence[i-1],k(n)?r[I.get(e)].add(P(n)):(r[I.get(e)].add(n),r[I.get(e)].add(pe(n)))):l.type==="haplotype"&&r[I.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],k(n)?t[I.get(e)].add(P(n)):(t[I.get(e)].add(n),t[I.get(e)].add(pe(n)))):l.type==="haplotype"&&t[I.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[I.get(l.sequence[i])].add(e),k(e)&&t[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&t[I.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[I.get(l.sequence[i])].add(e),k(e)&&r[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&r[I.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(v.showReads&&E.length>0){let l=y.slice();l.sort(fn);let i=new Map,u=new Map,f=d=>{let h=i.get(d);if(h===void 0)throw new Error(`No merge offset recorded for node ${d}`);return h},c=d=>{let h=u.get(d);if(h===void 0)throw new Error(`No merge origin recorded for node ${d}`);return h};l.forEach(d=>{let h=We(I.get(d.name),s,a);if(h){let p=f(h)+oe(h).sequenceLength;i.set(d.name,p),i.set(pe(d.name),p),u.set(d.name,c(h)),u.set(pe(d.name),c(h))}else i.set(d.name,0),i.set(pe(d.name),0),u.set(d.name,d.name),u.set(pe(d.name),d.name)}),E.forEach(d=>{let h=d.sequenceNew??[];d.firstNodeOffset=(d.firstNodeOffset??0)+f(d.sequence[0]),d.finalNodeCoverLength=(d.finalNodeCoverLength??0)+f(d.sequence[d.sequence.length-1]);for(let p=d.sequence.length-1;p>=0;p-=1){let m=P(d.sequence[p]),b=We(I.get(m),s,a);if(b&&Hn(I.get(b),s,a))if(p>0){d.sequence.splice(p,1);let g=oe(b).sequenceLength;h[p].mismatches.forEach(x=>{x.pos+=g}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{d.sequence[0]=c(d.sequence[0]);let g=h[0],x=f(g.nodeName);g.mismatches.forEach(R=>{R.pos+=x}),g.nodeName=c(g.nodeName)}}})}for(let l=0;l<y.length;l+=1)if(Hn(l,s,a)&&!We(l,s,a)){let i=l;for(;Hn(i,s,a);)i=I.get(P(a[i][0])),y[l].sequenceLength+=y[i].sequenceLength,y[l].seq+=y[i].seq}w.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=P(l.sequence[i]);let u=I.get(e);We(u,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)We(l,s,a)&&y.splice(l,1)}function We(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=P(n[e][0]),o=I.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function Hn(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=P(t[e][0]),o=I.get(r);return!(n[o].length!==1||n[o][0]==="None")}function Ba(e){let n=v.focusReadNames?new Set(v.focusReadNames):null;return e.filter(t=>t.is_secondary!==!0&&(t.mapping_quality??0)>=v.mappingQualityCutoff&&(n===null||t.name!==void 0&&n.has(t.name)))}function Oa(e,n){let t=new Map;for(let r of e){let o=n(r),s=t.get(o);s===void 0?t.set(o,[r]):s.push(r)}return t}function Pa(e,n){return e.xStart<n.xStart?1:e.xStart>n.xStart?-1:e.yStart>n.yStart?1:e.yStart<n.yStart?-1:0}function Oo(e,n){let t=Oa(e.filter(s=>s.type===n),s=>`${s.nodeStart},${s.nodeEnd}`);t.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Pa),s.forEach(i=>{let u,f;i.yStart<i.yEnd?(u=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,f=i.xStart+(i.xEnd-i.xStart)*(1-a)):(u=i.xStart+(i.xEnd-i.xStart)*a,a+=l,f=i.xStart+(i.xEnd-i.xStart)*a);let c=`M ${i.xStart} ${i.yStart}`;c+=` C ${u} ${i.yStart} ${u} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,c+=` V ${i.yEnd+i.width}`,c+=` C ${f} ${i.yEnd+i.width} ${f} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,c+=" Z",i.path=c})});let r=Array.from(t.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),u=l[0]??0,f=l[1]??0,c=i[0]??0,d=i[1]??0;return u<c?-1:u>c?1:f<d?-1:f>d?1:0});let o=[];for(let s of r){let a=t.get(s);a!==void 0&&o.push(...a)}return o}function Po(e){let n=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,t=e.x,r=e.y-9;return e.width>1&&(t+=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t+9} ${r} ${t+9} ${r+9}`,t+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,n+=` L ${t} ${r}`),n+=` Q ${t} ${r+9} ${t-9} ${r+9}`,t-=9,r+=9,e.width>1&&(t-=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t-9} ${r} ${t-9} ${r-9}`,t-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,n+=` L ${t} ${r}`),n}function Ga(e){let n=new Map;for(let[t,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${t}`,a=n.get(s);a?a.push(o.strand):n.set(s,[o.strand])}return n}function Da(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=Ga(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,u=s.nodeIds.flatMap(f=>{let c=n.get(f);if(!c)return[];let d=i.get(c.name)??0;i.set(c.name,d+1);let h=t.get(`${l} ${c.name}`)?.[d]??On(c);return[Pn(c,h)]});return u.length>0?[{id:a,name:s.name,sequence:u,sourceTrackID:0,type:"haplotype"}]:[]})}function $a(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function Te(e){return(e.paths?.length??0)>0}var qa=600,Fa=3,Ha=15;function Wa(e){return Math.max(Fa,Math.min(Ha,Math.floor(qa/Math.max(1,e))))}function Go(e){let n=e.paths??[],t=Da(e),r=e.reads?no(e,e.reads,n.length):[],o=r.length>0?mt:ht,s=n.map((l,i)=>o(i,n.length)),a=Io($a(e),t,r,{nodeWidthOption:"compressed",trackWidth:Wa(t.length),trackColor:l=>l.type==="read"?to(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function Vn(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function Do(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function $o(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function qo(e){let n=Te(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of Vn(t))s[i.name]=Do(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=$o(t,o);return{nodePositions:s,tubeMap:{layout:t,yOffset:o,pathColors:r},extent:{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:a,maxY:l}}}function Xa(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of Vn(n)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,u)=>i-u)){let i=r.get(l),u=1/0,f=-1/0;for(let c of i){let d=t.get(c.name);d&&_(d)&&(u=Math.min(u,d.stable.start),f=Math.max(f,d.stable.start+c.sequenceLength))}u===1/0&&(u=f=s),u<s&&(u=s,f=Math.max(s,f)),s=Math.max(s,f),o.push({order:l,x0:Math.min(...i.map(c=>c.x)),x1:Math.max(...i.map(c=>c.x+c.pixelWidth)),bp0:u,bp1:f})}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 ka(e){return e.nodes.some(_)&&Te(e)}function Fo(e){let n=ka(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=Xa(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of Vn(t)){let u=s.get(i.order);l[i.name]=Do(i,a,u.bp0,u.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:$o(t,a)}}function Ho(e){let n=ce(e);if(n.length!==0)return{nodePositions:ue(n),referenceAxis:!0,pixelRows:!0}}function Wo(e){return e.sample??Qe(e.name)}function Ya(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Wo(e)}function za(e,n,t,r=!0){if(!t||!r)return{ids:e,complete:!0};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((u,f)=>{let c=n.get(u);c&&(c.end<=t.start&&c.end>a&&(a=c.end,o=f),c.start>=t.end&&c.start<l&&(l=c.start,s=f))}),o<0||s<0)return{ids:e,complete:!1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0}}function Xo(e,n,t){let r=e.paths??[],o=r.find(h=>Le(h.name).name===e.referencePath)??r[0];if(!o||r.length<2)return;let s=new Map(e.nodes.map(h=>[h.id,h.length])),a=e.anchorPaths?.find(h=>h.name===Le(o.name).name)?.start??0,l=n&&n.end>n.start?n:void 0,i=new Map,u=a;for(let h of o.nodeIds){let p=s.get(h)??0;i.has(h)||i.set(h,{start:u,end:u+p}),u+=p}let f=l===void 0||[...i.values()].some(h=>h.end<=l.start)&&[...i.values()].some(h=>h.start>=l.end),c=h=>{let{ids:p,complete:m}=za(h.nodeIds,i,l,f),b=[],g=0,x=0,R=0;for(let N of p){let L=s.get(N)??0,S=i.get(N),A=b.at(-1),M=A?.referenceStart,C=S&&M!==void 0&&R>=0&&M+A.bp===S.start,B=S&&M!==void 0&&R<=0&&S.end===M;!S&&A&&!A.onReference?A.bp+=L:C||B?(A.bp+=L,C||(A.referenceStart=S.start,A.reversed=!0),R=C?1:-1):(b.push({start:g,bp:L,onReference:S!==void 0,referenceStart:S?.start}),R=0),g+=L,S||(x+=L)}return{name:h.name,label:Ya(h),sample:Wo(h),haplotype:h.haplotype,bp:g,offReferenceBp:x,complete:m,runs:b}};return{origin:l?l.start:a,unit:t,reference:c(o),rows:r.filter(h=>h!==o).map(c).sort((h,p)=>Number(p.complete)-Number(h.complete)||p.bp-h.bp||h.label.localeCompare(p.label))}}var ja=1.3;function Va(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*ja,maxY:e.rows.length*20}}function ko(e,n){let t=ce(e),r=Xo(e,n);if(t.length===0||!r)return;let o=ue(t),s=[{label:r.reference.label,y:0},...r.rows.map((a,l)=>({label:a.label,y:(l+1)*20}))];return{nodePositions:o,rowLabels:s,referenceAxis:!0,pixelRows:!0,extent:Va(r)}}var Ua="Force-directed layout",re=e=>e.nodes.some(_),Yo=e=>re(e)&&(e.paths?.length??0)>1,zo=e=>re(e)&&Te(e),jo=e=>re(e)&&e.nodes.some(Ze),Un=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:ao,cutMargins:!0,available:re,drawsLocally:re},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:fo,cutMargins:!0,available:jo,drawsLocally:jo},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, sequence the reference also carries in blue and sequence it does not in purple, so a repeat expansion reads as bar length. Needs W or P lines.",run:ko,cutMargins:!1,available:Yo,drawsLocally:Yo},{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:uo,cutMargins:!1,available:re,drawsLocally:re},{value:"variants",label:"Variant map",description:"The reference as a line with one typed glyph per bubble, from the bubble index or from the graph itself: SNP, indel, deletion, inversion, repeat array. Click a glyph to open the graph inside it.",run:Ho,cutMargins:!0,available:re,drawsLocally:re},{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:qo,cutMargins:!1,available:Te,drawsLocally:Te},{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:Fo,cutMargins:!0,available:zo,drawsLocally:zo},{value:"force",label:Ua,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,available:()=>!0,drawsLocally:()=>!1}],tu=Un.map(e=>e.value);function ou(e,n){return!Ka(e).drawsLocally(n)}function Ka(e){return Un.find(n=>n.value===e)??Un[0]}var Y=le(pn(),1);var q=le(pn(),1);function xe(e,n){return(0,q.packAbgr)((0,q.abgrRed)(e),(0,q.abgrGreen)(e),(0,q.abgrBlue)(e),Math.round((0,q.abgrAlpha)(e)*n))}function au(e,n){return(0,q.packAbgr)(Math.min(255,Math.round((0,q.abgrRed)(e)*n)),Math.min(255,Math.round((0,q.abgrGreen)(e)*n)),Math.min(255,Math.round((0,q.abgrBlue)(e)*n)),(0,q.abgrAlpha)(e))}var Uo=new WeakMap;function Ko(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=Uo.get(e);if(l?.graph===n&&l.scaleX===s&&l.scaleY===a&&l.deletions===r&&l.version===o)return l.curves;let i=new Map;for(let u=0;u<n.edges.length;u++){let f=n.edges[u],c=e[f.from],d=e[f.to];if(c?.length&&d?.length){let h=r?.get(u);i.set(u,De(c,d,It(f),0,0,t,h?Rn(e,h):[]))}}return Uo.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var Qa=(0,Y.packAbgr)(119,119,119,217),Qo=(0,Y.packAbgr)(136,136,136,217),Za=(0,Y.packAbgr)(24,24,28,240),Ja=2.2,ei=(0,Y.packAbgr)(30,30,36,245),ni=1.8,Ce=.18,ti=11,oi=1.2,ri=1e-6,si=7,ai=3,ii=3,li=1.5,ci=.5,ui=.45,Kn=12,di=1e-6,he=new Float64Array(64),Me=new Float64Array(64),we=new Float64Array(64);function fi(e,n,t,r){let o=e.length*Kn+1;he.length<o&&(he=new Float64Array(o),Me=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];he[0]=s.x1,Me[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let u=e[i];for(let f=1;f<=Kn&&l<r;f++){let c=1-(f/Kn)**2,d=1-c,h=d*d*d,p=3*d*d*c,m=3*d*c*c,b=c*c*c,g=h*u.x0+p*u.cx0+m*u.cx1+b*u.x1,x=h*u.y0+p*u.cy0+m*u.cy1+b*u.y1;l+=Math.hypot(g-he[a-1],(x-Me[a-1])*t)*n,he[a]=g,Me[a]=x,we[a]=l,a++}}return a}function Zo(e,n){let t=1;for(;t<e-1&&we[t]<n;)t++;let r=we[t-1],o=we[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:he[t-1]+(he[t]-he[t-1])*s,y:Me[t-1]+(Me[t]-Me[t-1])*s}}function pi({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=si+ai*n,u=fi(e,r,o,t+i),f=we[u-1],c=Math.min(t,f),d=f<di?hi(a,r,o):f-c,h=Math.min(1,d/i);if(h<ci)return;let p=Zo(u,c),m=Zo(u,c+i*h),b=p.x-m.x,g=(p.y-m.y)*o,x=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(b,g)>0?Math.atan2(g,b):Ei(x,o,mi(x,l)),length:i*h,halfWidth:(ii+li*n)*h,color:s}}function hi(e,n,t){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*t);return r*n}function mi(e,n){if(n.length<2)return;let t=n[0],r=n[n.length-1];return Math.hypot(e.x1-t.x,e.y1-t.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:t,to:n[1]}:{from:r,to:n[n.length-2]}}function bi(e,n=1){let t=n===1?e:e.map(o=>({x:o.x,y:o.y*n})),r=[];for(let o=0;o<t.length;o++){let s=0,a=0;if(o===0){let l=t[1].x-t[0].x,i=t[1].y-t[0].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else if(o===t.length-1){let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else{let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i),f=t[o+1].x-t[o].x,c=t[o+1].y-t[o].y,d=Math.hypot(f,c);if(u>0&&d>0){let h=-i/u,p=l/u,m=-c/d,b=f/d;s=(h+m)/2,a=(p+b)/2;let g=h*s+p*a;g>.1&&(s/=g,a/=g)}else u>0?(s=-i/u,a=l/u):d>0&&(s=-c/d,a=f/d)}r.push({nx:s,ny:a})}return r}function gi(e,n,t,r=1){return e.map((o,s)=>({x:o.x+n[s].nx*t,y:o.y+n[s].ny*t/r}))}function hn(e,n,t,r){return(0,Y.packAbgr)(Math.round(e*255),Math.round(n*255),Math.round(t*255),Math.round(r*255))}function mn(e,n,t){let r=(1-Math.abs(2*t-1))*n,o=r*(1-Math.abs(e/60%2-1)),s=t-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var yi=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],xi=[[237,137,44],[158,42,122]],Mi=[[220,50,50],[50,120,220]];function Qn(e,n){let t=Math.max(0,Math.min(1,n))*(e.length-1),r=Math.min(e.length-2,Math.floor(t)),o=t-r,s=e[r],a=e[r+1];return(0,Y.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 wi(e,n){let[t,r,o]=mn(ft(e),yn,xn);return hn(t,r,o,n)}var Si=300,Li=.7,Ni=.5,nr=[60,65,72],Ri=(0,Y.packAbgr)(...nr,255),gu=`rgb(${nr.join(", ")})`;function yu(e,n){let t=oo(e);if(n&&n.end>n.start)return{start:n.start,span:n.end-n.start,midpoints:t};let r=1/0,o=-1/0;for(let s of t.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:t}}function Zn(e){let n=1/0,t=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<n&&(n=a.depth),a.depth>t&&(t=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:n,maxDepth:t,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Jn(e,n,t,r){switch(t){case"random":return wi(e.id,1);case"depth":return Qn(yi,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Qn(Mi,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,Y.packAbgr)(160,160,160,255):e.stable.rank===0?(0,Y.packAbgr)(52,152,219,255):Qn(xi,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,Y.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Ri;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,u]=mn(a*Si,Li,Ni);return hn(l,i,u,1)}case"grey":return(0,Y.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?n/r.nodeCount*360:0,[s,a,l]=mn(o,.75,.5);return hn(s,a,l,1)}default:return(0,Y.packAbgr)(52,152,219,255)}}function Ei(e,n=1,t){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*n;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return t?Math.atan2((t.to.y-t.from.y)*n,t.to.x-t.from.x):0}function Ai(e,n){let t=!1;for(let r=0;r<e.length-1&&!t;r++){let o=e[r],s=e[r+1];t=Math.max(o.x,s.x)>=n.minX&&Math.min(o.x,s.x)<=n.maxX&&Math.max(o.y,s.y)>=n.minY&&Math.min(o.y,s.y)<=n.maxY}return t}function Ti(e,n){for(let t of e){let r=Math.min(t.x0,t.cx0,t.cx1,t.x1),o=Math.max(t.x0,t.cx0,t.cx1,t.x1),s=Math.min(t.y0,t.cy0,t.cy1,t.y1),a=Math.max(t.y0,t.cy0,t.cy1,t.y1);if(o>=n.minX&&r<=n.maxX&&a>=n.minY&&s<=n.maxY)return!0}return!1}var Jo=new WeakMap;function Ci(e){let n=Jo.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=mn(pt(s,o.length),yn,xn);t.push(hn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},Jo.set(e,n)}return n}var er=new WeakMap,Ii=new Map;function _i(e){let n=er.get(e);if(!n){n=new Map;for(let[t,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=n.get(o);s?s.push(t):n.set(o,[t])}er.set(e,n)}return n}function xu(e){let{nodePositions:n,graph:t,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:u,axis:f,linearLayout:c,viewportBounds:d,referenceRamp:h,deletions:p,hiddenEdges:m,version:b=0}=e,g=i==="depth"?bt(t):0,x=f.scaleX,R=en(f),N=Ko(n,t,f,p,b),L=[],S=new Map,A=[],M=new Map,C=[],B=new Map,G={...Zn(t),referenceRamp:h},X=new Map;if(o==="rainbow")for(let O=0;O<t.nodes.length;O++)X.set(t.nodes[O].id,O);let F=t.paths?.length??0,{pathColorByIndex:H,pathIndexByName:U}=Ci(t),j=O=>H[U.get(O)??-1]??Qo,V=l&&F>1?_i(t):Ii,ke=x>(c?1:ui);for(let O=0;O<t.edges.length;O++){let $=t.edges[O],K=n[$.from],Z=n[$.to],J=N.get(O);if(!K?.length||!Z?.length||!J||m?.has(O))continue;let se=$.pathIds?.length??0,ae=p?.get(O)!==void 0,ie=u?.edgeIndexes.has(O)??!1,ee=a/2*(ae?Ja:1)*(ie?ni:1),me=l&&se>0,ve=ae?Za:Qa,Se=u?ie?ei:xe(ve,Ce):ve,Ye=r.get($.to),gn=(Ye?Mn(Ye,s,i,g):s)/2,Be=(je,Ve,ne,Pe)=>{let be=je===0&&Ve===0?J:Tt(J,je,Ve);if(d&&!Ti(be,d))return;if(ae)for(let Nr of At(be,ti/x))C.push({curves:Nr,thickness:ee,color:ne});else C.push({curves:be,thickness:ee,color:ne});let at=ke&&Pe!==void 0?pi({curves:be,edgeHalfWidth:ee,nodeHalfWidth:gn,scale:x,yToX:R,color:Pe,fromSegments:K,toSegments:Z}):void 0;at&&A.push(at)},ze=C.length,Oe=A.length;if(!me)Be(0,0,Se,Se);else{let je=Ct(K,Z,se,f),Ve=Math.floor((se-1)/2);for(let ne=0;ne<se;ne++){let Pe=je[ne],be=j($.pathIds[ne]);Be(Pe.x,Pe.y,u&&$.pathIds[ne]!==u.name?xe(be,Ce):be,ne===Ve?Se:void 0)}}let rt=C.length-ze;rt>0&&B.set(O,{start:ze,count:rt});let st=A.length-Oe;st>0&&M.set(O,{start:Oe,count:st})}for(let[O,$]of Object.entries(n)){let K=r.get(O);if(!K||d&&!Ai($,d))continue;let Z=Jn(K,X.get(O)??0,o,G),J=u!==void 0&&!u.nodeIds.has(O),se=J?xe(Z,Ce):Z,_e=Mn(K,s,i,g),ae=_e/2,ie=L.length,ee=V.get(O),me=_e/F,ve=$.length>=2;if(ve&&ee?.length&&me>=oi){let Ye=bi($,R),gn=1/Math.max(x,ri);for(let Be of ee){let ze=(Be-(F-1)/2)*me*gn,Oe=H[Be]??Qo;L.push({points:gi($,Ye,ze,R),thickness:me/2,color:J?xe(Oe,Ce):Oe})}}else ve&&L.push({points:$,thickness:ae,color:se});let Se=L.length-ie;Se>0&&S.set(O,{start:ie,count:Se})}return{nodeStrokes:L,nodeStrokeRuns:S,arrows:A,arrowRuns:M,edgeCurves:C,edgeCurveRuns:B}}var rr=le(pn(),1);var Ie=10,vi=Ie+8,et=5;function Nu(e,{colorScheme:n,referenceRamp:t,walkNodes:r}){let o={...Zn(e),referenceRamp:t},s=[];return e.nodes.forEach((a,l)=>{if(_(a)){let i=Jn(a,l,n,o);s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,color:(0,rr.abgrToCssRgba)(r&&!r.has(a.id)?xe(i,Ce):i)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function nt(e,n,t){let r=n*e.scale+e.translateX,o=t*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var tr=2;function Bi(e,n,t){let r=-n.translateX/n.scale,o=(t-n.translateX)/n.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let u of e)l+=Math.max(0,Math.min(u.bp1,s)-u.bp0),i+=Math.max(0,u.bp1-Math.max(u.bp0,a));return n.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function Ru(e,n,t,r){if(r<0||r>Ie+tr)return;let o,s=tr;for(let a of e){let[l,i]=nt(n,a.bp0,a.bp1),u=Math.max(0,l-t,t-i);u<=s&&(s=u,o=a.node)}return o}function Eu(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function or(e,n,t){let r=Ie/2,o=n+t*(et+1);e.moveTo(n+t,r),e.lineTo(o,r-et/1.4),e.lineTo(o,r+et/1.4),e.closePath()}function Au(e,n,t,{width:r,lit:o,darkMode:s}){let a=s?"#ffffff":"#18181c";e.fillStyle=s?"#1f1f1f":"#ffffff",e.fillRect(0,0,r,vi);for(let i of n){let[u,f]=nt(t,i.bp0,i.bp1);f>=0&&u<=r&&(e.fillStyle=i.color,e.fillRect(u,0,Math.max(f-u,1),Ie))}let l=Bi(n,t,r);if((l.left>0||l.right>0)&&(e.beginPath(),l.left>0&&or(e,0,1),l.right>0&&or(e,r,-1),e.fillStyle=a,e.fill(),e.strokeStyle=s?"#1f1f1f":"#ffffff",e.lineWidth=1,e.stroke()),o){let[i,u]=nt(t,o.start,o.end),f=Math.max(u-i,3),c=(i+u)/2-f/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(c,.75,f,Ie-1.5),o.anchor&&(e.beginPath(),e.moveTo(c+f/2,Ie),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function _u(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;n.nodes.forEach(o=>{let s=t.get(o.name);if(o.order>=0&&s&&_(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 tt(e,n,t=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(t?i<n:i<=n)?r=l+1:o=l}let s=e[r];if(n<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(n,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function ot(e,n,t){let r=tt(e,n),o=tt(e,t,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function vu(e){let n;for(let t of e.values())(!n||t.length>n.length)&&(n=t);return n}var sr=5,Oi=10,Pi=110,Gi=3;function Di(e){return e?"#b0b0b8":"#55555c"}function $i(e){let n=10**Math.floor(Math.log10(e)),t=e/n;return(t<=1?1:t<=2?2:t<=5?5:10)*n}function ar(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+Oi)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function qi(e,n,t,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=n(o.x0),l=n(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let u=$i(i/(l-a)*Pi),f=[],c=[];for(let d=Math.ceil(o.bp0/u)*u;d<=s.bp1;d+=u){let h=Math.round(n(tt(e,d)))+.5;if(h>=0&&h<=t){f.push(h);let p=d.toLocaleString("en-US");c.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:f,labels:ar(c)}}function Fi(e,n,t,r){let o=e.map(p=>({box:p,s0:n(p.x0),s1:n(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=t),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),u=[],f=[],c=[],d=[];for(let{box:p,s0:m,s1:b}of o){u.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Gi&&f.push(Math.round(b)+.5);let g=l(sn(p.bp1-p.bp0),(m+b)/2);g.width<=b-m&&c.push(g),p!==s.box&&d.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:u,ticks:f,labels:ar([...h,...c,...d])}}function Hi(e,n,t,r,o=!1){return(o?qi:Fi)(e,n,t,r)}function Bu(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=Hi(n,s,a,c=>e.measureText(c).width,o);if(!i)return;let u=Di(l),f=r+.5;e.strokeStyle=u,e.fillStyle=u,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:c,x1:d}of i.spans)e.moveTo(Math.max(0,c),f),e.lineTo(Math.min(a,d),f);for(let c of i.ticks)e.moveTo(c,r),e.lineTo(c,r+sr);e.stroke();for(let{text:c,at:d}of i.labels)e.fillText(c,d,r+sr+2)}function Gu(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach(o=>{let s=t.get(o.name);o.order>=0&&s&&_(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 Du(e,n,t,r){let o=[];for(let s of e){let a=t(s.x0),l=t(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:n(s.bp0),top1:n(s.bp1),bottom0:a,bottom1:l})}return o}var Wi=3;function $u(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=Wi;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,u=l.top1+(l.bottom1-l.top1)*o,f=Math.max(0,Math.min(i,u)-t,t-Math.max(i,u));f<a&&(a=f,s=l.node)}return s}function ir(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.top1,0),e.lineTo(n.bottom1,t),e.lineTo(n.bottom0,t),e.closePath()}function lr(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function qu(e,n,t,{highlightNode:r,darkMode:o}){if(t<=0||n.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of n)ir(e,l,t);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of n)lr(e,l,t);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=n.find(l=>l.node===r);a&&(e.beginPath(),ir(e,a,t),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),lr(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Xi(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach((o,s)=>{let a=t.get(o.name);if(o.order>=0&&a&&_(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 ki(e,n,t){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=n?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&t.has(s.index)&&s.bp0<=n&&n<=s.bp1)}function Wu(e,n,t){let r=Xi(e,n),o=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let u=ki(r,i.start,l);if(u){let{node:f,bp0:c,bp1:d}=u,h=p=>f.x+(Math.min(p,d)-c)/(d-c)*f.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(u.index),height:s.width})}}}}return o}function Yi(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Xu(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=Yi(s),e.beginPath();for(let a of n){let l=t(a.x0),i=Math.max(t(a.x1),l+1);if(i>=0&&l<=o){let u=r(a.y);e.rect(l,u,i-l,r(a.y+a.height)-u)}}e.fill()}}function zi(e,n){let t=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=n.nodeMap.get(P(o.nodeName)),l=a===void 0?void 0:n.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let u=e.path[i]?.y;if(l&&u!==void 0){let f={readId:e.id,y:u,height:e.width,nodeY:l.y},c=d=>Bo(l,d);for(let d of o.mismatches){let h=c(d.pos);if(h!==null){if(d.type==="insertion"){let p=s===0&&d.pos===e.firstNodeOffset||s===r.length-1&&d.pos===e.finalNodeCoverLength;t.push({...f,kind:"insertion",x:h,seq:d.seq,softClip:p})}else if(d.type==="deletion"&&d.length!==void 0){let p=c(d.pos+d.length);p!==null&&t.push({...f,kind:"deletion",x0:h,x1:p})}else if(d.type==="substitution"&&d.seq!==void 0){let p=c(d.pos+d.seq.length);p!==null&&t.push({...f,kind:"substitution",x0:h,x1:p,seq:d.seq})}}}}}),t}function cr(e){return e.reads.flatMap(n=>zi(n,e))}function mr(e){let n=e.trim().split(/[\s,]+/),t=[],r=0,o=()=>Number(n[r++]);for(;r<n.length;){let s=n[r++];s==="M"||s==="L"?t.push({op:s,x:o(),y:o()}):s==="H"?t.push({op:s,x:o()}):s==="V"?t.push({op:s,y:o()}):s==="Q"?t.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?t.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&t.push({op:s})}return t}function br(e){let n=1/0,t=-1/0;for(let r of e)"x"in r&&(n=Math.min(n,r.x),t=Math.max(t,r.x)),"x1"in r&&(n=Math.min(n,r.x1),t=Math.max(t,r.x1));return{x0:n,x1:t}}function ur(e,n,t){let r=mr(e);return{commands:r,color:n,alpha:t,...br(r)}}function dr(e,n){let{shapes:t}=e,r=[...t.rectangles,...t.verticalRectangles].filter(a=>a.type===n).map(a=>({color:a.color,alpha:a.alpha??1,x0:a.xStart,x1:a.xEnd+1,y0:a.yStart,y1:a.yEnd+1})),o=Oo(t.curves,n).map(a=>ur(a.path,a.color,a.alpha??1)),s=t.corners.filter(a=>a.type===n).map(a=>ur(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function Uu(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=mr(Po(t));n.push({name:t.name,commands:r,...br(r)})}}),{bounds:e.bounds,layers:[dr(e,"haplotype"),dr(e,"read")],nodes:n,mismatches:cr(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function fr(e,n,t,r){let o=0,s=0;for(let a of n)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(t(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(t(o),r(s));break;case"H":o=a.x,e.lineTo(t(o),r(s));break;case"V":s=a.y,e.lineTo(t(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(t(a.x1),r(a.y1),t(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(t(a.x1),r(a.y1),t(a.x2),r(a.y2),t(o),r(s));break;case"Z":e.closePath();break}}function pr(e,n,t,r){let o=new Map;for(let s of n)if(t(s)){let a=`${s.color}|${s.alpha}`,l=o.get(a);l?l.push(s):o.set(a,[s])}for(let s of o.values()){e.fillStyle=s[0].color,e.globalAlpha=s[0].alpha,e.beginPath();for(let a of s)r(a);e.fill()}e.globalAlpha=1}var ji=12,Vi=.15;function Ui(e){return Math.max(Vi,Math.min(1,e/ji))}function Ku(e,n,t){let{x:r,y:o,width:s}=t,a=u=>r(u.x1)>=0&&r(u.x0)<=s;for(let u of n.layers)pr(e,u.rects,a,f=>{let c=r(f.x0),d=o(f.y0);e.rect(c,d,r(f.x1)-c,o(f.y1)-d)}),pr(e,u.shapes,a,f=>{fr(e,f.commands,r,o)});let l=t.darkMode?"#d0d0d0":"#000000",i=t.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,t.yScale));for(let u of n.nodes)if(a(u)){let f=u.name===t.highlightNode;e.beginPath(),fr(e,u.commands,r,o),e.fillStyle=f?"rgba(255,192,203,0.5)":i,e.strokeStyle=f?"#ff0000":l,e.fill(),e.globalAlpha=f?1:Ui(r(u.x1)-r(u.x0)),e.stroke(),e.globalAlpha=1}Zi(e,n.mismatches,t)}var gr=12,Ki=6;function Qi(e){return gr*e>=Ki}function hr(e,{x:n,width:t}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return n(o)>=0&&n(r)<=t}function Zi(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!Qi(s)||n.length===0)return;let l=gr*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&hr(i,t)){let u=r(i.x0),f=o(i.y);e.rect(u,f,r(i.x1)-u,o(i.y+i.height)-f)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of n)hr(i,t)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Ju(e,n){let t=[];for(let r of n){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||t.push({gene:r,...ot(o,l,i),exons:r.exons.filter(u=>u.end>l&&u.start<i).map(u=>ot(o,Math.max(u.start,l),Math.min(u.end,i)))})}return t}var yr=22,Ji=4,bn=8,el="11px sans-serif",nl=8;function ed(e){let n=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),t=0,r=0;for(let{step:o}of n)t+=o,r=Math.max(r,t);return Math.min(Ji,r)}function nd(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/yr)),u=[],f=l?"#e0e0e6":"#1c1c22";e.font=el,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let c=n.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:h})=>h>=0&&d<=a).sort((d,h)=>d.s0-h.s0);for(let{g:d,s0:h,s1:p}of c){let m=d.gene.strand>0?" \u2192":d.gene.strand<0?"\u2190 ":"",b=d.gene.strand<0?`${m}${d.gene.name}`:`${d.gene.name}${m}`,g=(Math.max(h,0)+Math.min(p,a))/2,x=e.measureText(b).width/2,R=Math.min(h,g-x),N=Math.max(p,g+x),L=u.findIndex(A=>A+nl<=R);L===-1&&(L=Math.min(u.length,i-1)),u[L]=Math.max(u[L]??-1/0,N);let S=r-L*yr-bn/2;e.beginPath(),e.moveTo(h,S+.5),e.lineTo(p,S+.5),e.stroke();for(let A of d.exons){let M=s(A.x0);e.fillRect(M,S-bn/2,Math.max(1,s(A.x1)-M),bn)}e.fillText(b,g,S-bn/2-2)}}function ol(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function rl(e,n){let t=e.length,r=n.length,o=Array.from({length:t+1},()=>new Array(r+1).fill(0)),s=Array.from({length:t+1},()=>new Array(r+1).fill(!1));for(let l=t-1;l>=0;l--)for(let i=r-1;i>=0;i--){let u=Math.abs(e[l]-n[i])+o[l+1][i+1],f=t-l>r-i?o[l+1][i]:1/0,c=r-i>t-l?o[l][i+1]:1/0;o[l][i]=Math.min(u,f,c),s[l][i]=o[l][i]===u}let a=new Array(t).fill(void 0);for(let l=0,i=0;l<t&&i<r;)s[l][i]?a[l++]=i++:t-l>r-i?l++:i++;return a}function Mr(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var Sr=e=>e.spanningReads!==0;function wr(e,n){return{...n,agrees:e.complete&&Sr(n)?ol(e.bp,n.bp):void 0}}function sl(e,n){let t=new Map,r=new Set;e.forEach((l,i)=>{let u=n.find(f=>f.haplotype!==void 0&&f.haplotype===l.haplotype);u&&(r.add(u),t.set(i,wr(l,u)))});let o=n.filter(l=>l.haplotype===void 0),s=Mr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Sr)],[s,o]];for(let[l,i]of a){let u=l.filter(c=>!t.has(c.i)),f=Mr(i.filter(c=>!r.has(c)),c=>c.bp);rl(u.map(c=>c.item.bp),f.map(c=>c.item.bp)).forEach((c,d)=>{if(c!==void 0){let h=u[d],p=f[c].item;r.add(p),t.set(h.i,wr(h.item,p))}})}return t}function rd(e,n){if(!n)return e;let t=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=n[o];if(a)for(let[l,i]of sl(s,a))t.set(s[l],i)}return e.map(o=>({...o,call:t.get(o)}))}var Lr=le(Ke(),1),id=(0,te.createSvgIcon)((0,Lr.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{te as a,Ms as b,pn as c,ge as d,Jl as e,ec as f,nc as g,tc as h,ul as i,Et as j,Tt as k,en as l,Ct as m,Hs as n,hl as o,gl as p,yl as q,xl as r,qt as s,sn as t,ls as u,Wt as v,Cl as w,Xo as x,Va as y,Fe as z,vs as A,On as B,Ts as C,Cs as D,Ga as E,Un as F,tu as G,ou as H,Ka as I,au as J,Ko as K,Si as L,gu as M,yu as N,xu as O,vi as P,Nu as Q,Bi as R,Ru as S,Eu as T,Au as U,_u as V,vu as W,Di as X,Bu as Y,Gu as Z,Du as _,$u as $,qu as aa,Wu as ba,Yi as ca,Xu as da,Uu as ea,Ku as fa,Qi as ga,hr as ha,Ju as ia,yr as ja,ed as ka,nd as la,tl as ma,rd as na,Bl as oa,Ol as pa,bs as qa,Pl as ra,Gl as sa,vn as ta,Vl as ua,Ul as va,id as wa};
2
+ //# sourceMappingURL=chunk-JXAJ7YLT.js.map