jbrowse-plugin-graphgenomeviewer 7.3.2 → 7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/chunks/{GbzBaseSyntenyAdapter-3MELVQRM.js → GbzBaseSyntenyAdapter-FZWSXPAE.js} +2 -2
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-3MELVQRM.js.map → GbzBaseSyntenyAdapter-FZWSXPAE.js.map} +2 -2
  3. package/dist/chunks/{GraphGenomeView-6EDKLBOJ.js → GraphGenomeView-52OPGZER.js} +2 -2
  4. package/dist/chunks/{GraphTrackSettingsDialog-KYEZWI4Z.js → GraphTrackSettingsDialog-JHIP2F5N.js} +2 -2
  5. package/dist/chunks/{HighlightColorDialog-IMLYI64R.js → HighlightColorDialog-S2WPOSDF.js} +2 -2
  6. package/dist/chunks/{LinearGraphDisplay-CRIZLJDE.js → LinearGraphDisplay-EF2GE7X7.js} +2 -2
  7. package/dist/chunks/{MinigraphBubbleAdapter-2HPTGZ5N.js → MinigraphBubbleAdapter-XC75BCG3.js} +2 -2
  8. package/dist/chunks/{RgfaTabixAdapter-GNH3QCPZ.js → RgfaTabixAdapter-56X2U424.js} +2 -2
  9. package/dist/chunks/{WalkTabixSyntenyAdapter-CUPHY36S.js → WalkTabixSyntenyAdapter-ECW557IS.js} +2 -2
  10. package/dist/chunks/{WalkTabixSyntenyAdapter-CUPHY36S.js.map → WalkTabixSyntenyAdapter-ECW557IS.js.map} +3 -3
  11. package/dist/chunks/chunk-2BTNRN57.js +2 -0
  12. package/dist/chunks/chunk-2BTNRN57.js.map +7 -0
  13. package/dist/chunks/{chunk-MNL7IPTH.js → chunk-2Q4D5RHL.js} +2 -2
  14. package/dist/chunks/{chunk-MNL7IPTH.js.map → chunk-2Q4D5RHL.js.map} +1 -1
  15. package/dist/chunks/{chunk-ULLEUORS.js → chunk-4AAW5P6N.js} +2 -2
  16. package/dist/chunks/{chunk-ULLEUORS.js.map → chunk-4AAW5P6N.js.map} +1 -1
  17. package/dist/chunks/{chunk-NGR473EL.js → chunk-4XM5OBD5.js} +1 -1
  18. package/dist/chunks/{chunk-NGR473EL.js.map → chunk-4XM5OBD5.js.map} +1 -1
  19. package/dist/chunks/chunk-ADZBAET3.js +3 -0
  20. package/dist/chunks/chunk-ADZBAET3.js.map +7 -0
  21. package/dist/chunks/{chunk-B5SVBPXN.js → chunk-D5PRXUSS.js} +2 -2
  22. package/dist/chunks/{chunk-B5SVBPXN.js.map → chunk-D5PRXUSS.js.map} +1 -1
  23. package/dist/chunks/{chunk-PUFH6DMJ.js → chunk-JXOLZ5IZ.js} +2 -2
  24. package/dist/chunks/{chunk-PUFH6DMJ.js.map → chunk-JXOLZ5IZ.js.map} +1 -1
  25. package/dist/chunks/chunk-KPP5H27W.js +2 -0
  26. package/dist/chunks/chunk-KPP5H27W.js.map +7 -0
  27. package/dist/chunks/{chunk-Q55PHRHV.js → chunk-LTN6XZR5.js} +1 -1
  28. package/dist/chunks/{chunk-Q55PHRHV.js.map → chunk-LTN6XZR5.js.map} +1 -1
  29. package/dist/chunks/{chunk-QQCTNB2Z.js → chunk-MLVBPMBU.js} +2 -2
  30. package/dist/chunks/{chunk-QQCTNB2Z.js.map → chunk-MLVBPMBU.js.map} +1 -1
  31. package/dist/chunks/chunk-OUHKJSKZ.js +3 -0
  32. package/dist/chunks/chunk-OUHKJSKZ.js.map +7 -0
  33. package/dist/chunks/{chunk-HOSCIP4U.js → chunk-PLTIGGGS.js} +2 -2
  34. package/dist/chunks/{chunk-HOSCIP4U.js.map → chunk-PLTIGGGS.js.map} +2 -2
  35. package/dist/chunks/chunk-QASFRHPG.js +2 -0
  36. package/dist/chunks/{chunk-GN4HSVLB.js → chunk-SI64QXFH.js} +2 -2
  37. package/dist/chunks/{chunk-GN4HSVLB.js.map → chunk-SI64QXFH.js.map} +2 -2
  38. package/dist/chunks/{chunk-4EKOQHUX.js → chunk-UW7INEQF.js} +1 -1
  39. package/dist/chunks/{chunk-4EKOQHUX.js.map → chunk-UW7INEQF.js.map} +1 -1
  40. package/dist/chunks/{chunk-TQKSF3NI.js → chunk-VIVPTP5Z.js} +1 -1
  41. package/dist/chunks/{chunk-TQKSF3NI.js.map → chunk-VIVPTP5Z.js.map} +1 -1
  42. package/dist/chunks/{chunk-6DRBCLWY.js → chunk-XLSVRKFJ.js} +2 -2
  43. package/dist/chunks/chunk-XLSVRKFJ.js.map +7 -0
  44. package/dist/chunks/{chunk-CJMBJJLO.js → chunk-XT4U7I3D.js} +3 -3
  45. package/dist/chunks/{chunk-CJMBJJLO.js.map → chunk-XT4U7I3D.js.map} +4 -4
  46. package/dist/chunks/chunk-YBZA7LPQ.js +2 -0
  47. package/dist/chunks/chunk-YBZA7LPQ.js.map +7 -0
  48. package/dist/chunks/{chunk-IFBKAC2H.js → chunk-Z4YNEFPC.js} +2 -2
  49. package/dist/chunks/renderSvg-IXWB7R54.js +2 -0
  50. package/dist/chunks/renderSvg-IXWB7R54.js.map +7 -0
  51. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +4 -4
  52. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  53. package/package.json +3 -3
  54. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +10 -4
  55. package/src/GbzBaseSyntenyAdapter/companion.test.ts +4 -2
  56. package/src/GetSubgraph.ts +2 -0
  57. package/src/GraphGenomeView/components/ElTree.tsx +1 -1
  58. package/src/GraphGenomeView/components/FacetPanels.tsx +4 -1
  59. package/src/GraphGenomeView/components/PaneContextMenu.tsx +14 -0
  60. package/src/GraphGenomeView/components/PaneSvg.tsx +2 -1
  61. package/src/GraphGenomeView/legendSections.ts +3 -3
  62. package/src/GraphGenomeView/model.test.ts +19 -21
  63. package/src/GraphGenomeView/model.ts +3 -0
  64. package/src/GraphGenomeView/pane/fitViews.ts +2 -2
  65. package/src/GraphGenomeView/pane/paneBase.ts +2 -0
  66. package/src/GraphGenomeView/pane/renderingActions.ts +9 -0
  67. package/src/GraphGenomeView/repeats/walkCalls.test.ts +2 -2
  68. package/src/GraphGenomeView/subgraphLoad.test.ts +18 -2
  69. package/src/GraphGenomeView/tubeMapPanels.test.ts +4 -2
  70. package/src/GraphGenomeView/tubeMapPanels.ts +2 -2
  71. package/src/RgfaTabixAdapter/configSchema.ts +1 -1
  72. package/src/RgfaTabixAdapter/test_data/walks4_follow.GRCh38.walks.bed.gz +0 -0
  73. package/src/RgfaTabixAdapter/test_data/walks4_header.GRCh38.walks.bed.gz +0 -0
  74. package/src/RgfaTabixAdapter/test_data/walks4_inversion.GRCh38.walks.bed.gz +0 -0
  75. package/src/RgfaTabixAdapter/test_data/walks4_lanepairs.GRCh38.walks.bed.gz +0 -0
  76. package/src/RgfaTabixAdapter/test_data/walks4_maxnode.GRCh38.walks.bed.gz +0 -0
  77. package/src/RgfaTabixAdapter/test_data/walks4_rejoin.GRCh38.walks.bed.gz +0 -0
  78. package/src/RgfaTabixAdapter/test_data/walks4_twopart.GRCh38.walks.bed.gz +0 -0
  79. package/src/RgfaTabixAdapter/walkFiles.test.ts +15 -3
  80. package/src/RgfaTabixAdapter/walkReader.ts +4 -1
  81. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts +7 -2
  82. package/src/WalkTabixSyntenyAdapter/configSchema.ts +1 -1
  83. package/src/WalkTabixSyntenyAdapter/gbzParity.test.ts +2 -3
  84. package/src/version.ts +1 -1
  85. package/dist/chunks/chunk-6DRBCLWY.js.map +0 -7
  86. package/dist/chunks/chunk-F4T7JI7S.js +0 -2
  87. package/dist/chunks/chunk-F4T7JI7S.js.map +0 -7
  88. package/dist/chunks/chunk-HTSG4T32.js +0 -3
  89. package/dist/chunks/chunk-HTSG4T32.js.map +0 -7
  90. package/dist/chunks/chunk-N5VWQHTK.js +0 -2
  91. package/dist/chunks/chunk-N5VWQHTK.js.map +0 -7
  92. package/dist/chunks/chunk-ORHUPW3G.js +0 -3
  93. package/dist/chunks/chunk-ORHUPW3G.js.map +0 -7
  94. package/dist/chunks/chunk-R25GOTED.js +0 -2
  95. package/dist/chunks/chunk-R25GOTED.js.map +0 -7
  96. package/dist/chunks/chunk-VW4PPXH6.js +0 -2
  97. package/dist/chunks/renderSvg-HEEQJD5B.js +0 -2
  98. package/dist/chunks/renderSvg-HEEQJD5B.js.map +0 -7
  99. /package/dist/chunks/{GraphGenomeView-6EDKLBOJ.js.map → GraphGenomeView-52OPGZER.js.map} +0 -0
  100. /package/dist/chunks/{GraphTrackSettingsDialog-KYEZWI4Z.js.map → GraphTrackSettingsDialog-JHIP2F5N.js.map} +0 -0
  101. /package/dist/chunks/{HighlightColorDialog-IMLYI64R.js.map → HighlightColorDialog-S2WPOSDF.js.map} +0 -0
  102. /package/dist/chunks/{LinearGraphDisplay-CRIZLJDE.js.map → LinearGraphDisplay-EF2GE7X7.js.map} +0 -0
  103. /package/dist/chunks/{MinigraphBubbleAdapter-2HPTGZ5N.js.map → MinigraphBubbleAdapter-XC75BCG3.js.map} +0 -0
  104. /package/dist/chunks/{RgfaTabixAdapter-GNH3QCPZ.js.map → RgfaTabixAdapter-56X2U424.js.map} +0 -0
  105. /package/dist/chunks/{chunk-VW4PPXH6.js.map → chunk-QASFRHPG.js.map} +0 -0
  106. /package/dist/chunks/{chunk-IFBKAC2H.js.map → chunk-Z4YNEFPC.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/graphTrackConfig.ts", "../../src/GraphGenomeView/trackFeatures.ts", "../../src/GraphGenomeView/repeats/repeatFeatures.ts", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.6.1/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-EQDQ7P4Y.js", "../../src/GraphGenomeView/genes/geneFeatures.ts", "host:tss-react/mui"],
3
+ "sources": ["../../src/graphTrackConfig.ts", "../../src/GraphGenomeView/trackFeatures.ts", "../../src/GraphGenomeView/repeats/repeatFeatures.ts", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.7.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-EQDQ7P4Y.js", "../../src/GraphGenomeView/genes/geneFeatures.ts", "host:tss-react/mui"],
4
4
  "sourcesContent": ["import { readConfObject } from '@jbrowse/core/configuration'\n\nimport { snapshotNamesFile } from './locationName.ts'\n\nimport type { AnyConfigurationModel } from '@jbrowse/core/configuration'\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(item => typeof item === 'string')\n}\n\n// The assemblies the track names after its reference, which is what core's\n// MultiWaySyntenyDisplay opens a lane-declaring source on.\nexport function trackLanes(track: AnyConfigurationModel) {\n const assemblyNames: unknown = readConfObject(track, 'assemblyNames')\n const lanes = isStringArray(assemblyNames) ? assemblyNames.slice(1) : []\n return lanes.length > 0 ? lanes : undefined\n}\n\n// Whether a track names a walk file, by the `walksUri` shorthand as written\n// or the location it expands to: an rGFA track may, and a\n// WalkTabixSyntenyAdapter one does\nexport function walkIndexed(adapterConfig: Record<string, unknown>) {\n return (\n adapterConfig.type === 'WalkTabixSyntenyAdapter' ||\n (adapterConfig.type === 'RgfaTabixAdapter' &&\n ((typeof adapterConfig.walksUri === 'string' &&\n adapterConfig.walksUri !== '') ||\n snapshotNamesFile(adapterConfig.walksLocation)))\n )\n}\n\n// Whether a track's cut reads `haplotypes`: a GBZ cut does, and so does an\n// rGFA one with a walk file\nexport function cutsByHaplotype(adapterConfig: Record<string, unknown>) {\n return (\n adapterConfig.type === 'GbzBaseSyntenyAdapter' || walkIndexed(adapterConfig)\n )\n}\n\n// The haplotypes a walk-indexed track's config names to cut for until the\n// user picks others\nexport function configHaplotypes(adapterConfig: Record<string, unknown>) {\n const { defaultHaplotypes } = adapterConfig\n return walkIndexed(adapterConfig) &&\n isStringArray(defaultHaplotypes) &&\n defaultHaplotypes.length > 0\n ? defaultHaplotypes\n : undefined\n}\n\n// A graph is cut on the first assembly its track names, the rule\n// GbzBaseSyntenyAdapter states for its anchor. Every other assembly the track\n// names holds its sequence as rank>0 alleles off that reference's backbone, so\n// a window on one has no reference coordinates to frame the cut by.\nexport function graphReferenceAssembly(track: AnyConfigurationModel) {\n const assemblyNames: unknown = readConfObject(track, 'assemblyNames')\n return isStringArray(assemblyNames) ? assemblyNames[0] : undefined\n}\n\nexport function offReferenceProblem(\n referenceAssembly: string | undefined,\n assemblyName: string,\n) {\n return referenceAssembly === undefined || referenceAssembly === assemblyName\n ? undefined\n : `The graph is cut on its reference, ${referenceAssembly}: open it from a view of ${referenceAssembly}`\n}\n", "import type { Feature } from '@jbrowse/core/util'\n\nexport type FeatureLike = Feature | Record<string, unknown>\n\nexport function ownField(f: FeatureLike, name: string): unknown {\n return typeof (f as Feature).get === 'function'\n ? (f as Feature).get(name)\n : (f as Record<string, unknown>)[name]\n}\n\nexport interface TrackChoice {\n trackId: string\n name?: string\n adapterType: string\n}\n\nexport function namedTrack<T extends TrackChoice>(tracks: T[], named: string) {\n return tracks.find(t => t.trackId === named)\n}\n\n// what a track-name hint such as /repeat|tandem/ is matched against\nexport function trackLabel(t: TrackChoice) {\n return `${t.trackId} ${t.name ?? ''}`\n}\n", "import { namedTrack, ownField, trackLabel } from '../trackFeatures'\n\nimport type { FeatureLike, TrackChoice } from '../trackFeatures'\n\nexport interface RepeatCall {\n bp: number\n // TRGT's `SD`. Zero means the allele is a copy of the one the reads did\n // support, so its length states nothing about a second haplotype; absent\n // where the genotyper writes no such field.\n spanningReads?: number\n // the PanSN haplotype a phased genotype puts this allele on\n haplotype?: number\n}\n\n// A tandem repeat array as the walk rows need it: its span on the reference,\n// which is what the bars measure between, and its unit length, which is what\n// they tile by. Read off whatever repeat annotation the session has, since the\n// tools all state the same two facts under different names: VCF 4.5's\n// `<CNV:TR>` allele gives `RUL` and `RUS` (one entry per repeat sequence,\n// grouped by `RN`), UCSC simpleRepeat and TRF give `period` and the consensus\n// `sequence`, TRGT gives `MOTIFS` and `TRID`, ExpansionHunter `RU` and `REPID`,\n// HipSTR and GangSTR `PERIOD`, vamos its `motifs`. A VCF record's INFO is\n// searched as well as its top level, and a list's first entry is the unit the\n// bars tile by: for a compound array that is the first repeat sequence, which\n// is the expanding one at every such locus in the common catalogues.\nexport interface RepeatArray {\n key: string\n name: string\n refName: string\n start: number\n end: number\n unit: number\n motif?: string\n // Each sample's genotyped alleles, from a genotyper's per-sample `AL`\n // (TRGT) or a genotype over VCF 4.5 <CNV:TR> alleles; absent from a\n // catalogue.\n calls?: Record<string, RepeatCall[]>\n}\n\nexport const REPEAT_ADAPTER_TYPES = new Set([\n 'BedAdapter',\n 'BedTabixAdapter',\n 'BigBedAdapter',\n 'VcfAdapter',\n 'VcfTabixAdapter',\n])\n\nexport const REPEAT_TRACK_HINT =\n /repeat|tandem|\\bstr\\b|vntr|trf|trgt|vamos|expansion|microsat/i\n\nexport function pickRepeatTrack<T extends TrackChoice>(\n tracks: T[],\n named: string,\n) {\n const chosen = named ? namedTrack(tracks, named) : undefined\n if (chosen) {\n return chosen\n }\n const candidates = tracks.filter(t => REPEAT_ADAPTER_TYPES.has(t.adapterType))\n return candidates.find(t => REPEAT_TRACK_HINT.test(trackLabel(t)))\n}\n\n// A TRGT repeat catalogue is a BED whose name column packs the record:\n// `ID=HTT;MOTIFS=CAG,CCG;STRUC=(CAG)nCAACAG(CCG)n`. Read as fields when it\n// has that shape.\nconst PACKED_NAME = /^\\w+=[^;]*(;\\w+=[^;]*)*$/\n\nfunction packedName(f: FeatureLike) {\n const name = ownField(f, 'name')\n if (typeof name !== 'string' || !PACKED_NAME.test(name)) {\n return undefined\n }\n return Object.fromEntries(\n name.split(';').map(pair => {\n const i = pair.indexOf('=')\n return [pair.slice(0, i), pair.slice(i + 1)]\n }),\n )\n}\n\n// A field at the feature's top level, in a VCF record's INFO, or in a packed\n// name column, in that order.\nfunction field(f: FeatureLike, name: string): unknown {\n const top = ownField(f, name)\n if (top !== undefined) {\n return top\n }\n const info = ownField(f, 'INFO') as Record<string, unknown> | undefined\n return info?.[name] ?? packedName(f)?.[name]\n}\n\nconst MOTIF_FIELDS = [\n 'RUS',\n 'MOTIFS',\n 'RU',\n 'motifs',\n 'motif',\n 'sequence',\n 'consensus',\n]\nconst PERIOD_FIELDS = [\n 'RUL',\n 'period',\n 'PERIOD',\n 'consensusSize',\n 'unit',\n 'unitLength',\n]\nconst NAME_FIELDS = ['TRID', 'REPID', 'VARID', 'ID', 'name', 'id']\n\n// The first entry of a list-valued field, whether it arrived parsed or as\n// the comma-joined text a VCF INFO or a BED column holds; VCF's missing \".\"\n// counts as absent.\nfunction first(f: FeatureLike, names: string[]) {\n for (const name of names) {\n const value = field(f, name)\n const one = String((Array.isArray(value) ? value[0] : value) ?? '')\n .split(',')[0]!\n .trim()\n if (one !== '' && one !== '.') {\n return one\n }\n }\n return undefined\n}\n\nconst IUPAC = /^[ACGTURYSWKMBDHVN]+$/i\n\n// The unit in bp: a stated period, else the length of the first motif.\nexport function repeatUnitOf(f: FeatureLike) {\n const period = Number(first(f, PERIOD_FIELDS))\n if (Number.isFinite(period) && period > 0) {\n return Math.round(period)\n }\n const motif = first(f, MOTIF_FIELDS)\n return motif && IUPAC.test(motif) ? motif.length : undefined\n}\n\n// A per-sample list field, parsed or as the comma-joined text a VCF column\n// holds. A missing entry stays missing: read as 0, an absent `SD` would make\n// every allele of every genotyper that writes no such field unspanned.\nfunction numbers(value: unknown) {\n const raw: unknown[] = Array.isArray(value)\n ? value\n : String(value ?? '').split(',')\n return raw.map(one => {\n const n =\n one === '' || one === null || one === undefined ? NaN : Number(one)\n return Number.isFinite(n) ? n : undefined\n })\n}\n\nfunction strings(value: unknown) {\n const raw: unknown[] = Array.isArray(value)\n ? value\n : String(value ?? '').split(',')\n return raw.map(one => {\n const text = String(one ?? '').trim()\n return text === '' || text === '.' ? undefined : text\n })\n}\n\nconst TANDEM_REPEAT = '<CNV:TR>'\n\n// Each ALT allele's length, off VCF 4.5's flattened list-of-lists: RN says how\n// many RUS/RUL/RUC/RB entries each allele takes, and the allele's bases are\n// its runs' RB, or unit length times count where RB is missing. An allele that\n// is not <CNV:TR>, or has a run stating neither, has none.\nfunction tandemAlleleBp(f: FeatureLike) {\n const alts = strings(ownField(f, 'ALT'))\n if (!alts.includes(TANDEM_REPEAT)) {\n return undefined\n }\n const rn = numbers(field(f, 'RN'))\n const rus = strings(field(f, 'RUS'))\n const rul = numbers(field(f, 'RUL'))\n const ruc = numbers(field(f, 'RUC'))\n const rb = numbers(field(f, 'RB'))\n let k = 0\n return alts.map((alt, i) => {\n const n = rn[i] ?? (alt === TANDEM_REPEAT ? 1 : 0)\n let bp = 0\n let known = 0\n for (let j = 0; j < n; j++, k++) {\n const motif = rus[k]\n const unitLength =\n rul[k] ?? (motif && IUPAC.test(motif) ? motif.length : undefined)\n const count = ruc[k]\n const runBp =\n rb[k] ??\n (unitLength && count !== undefined\n ? Math.round(unitLength * count)\n : undefined)\n if (runBp !== undefined) {\n bp += runBp\n known++\n }\n }\n return alt === TANDEM_REPEAT && n > 0 && known === n ? bp : undefined\n })\n}\n\n// A sample's alleles through its genotype: 0 is the reference's, an index\n// past it the ALT allele's. A phased genotype's k-th allele is PanSN\n// haplotype k, the order vg deconstruct writes an assembly's haplotypes in.\nfunction genotyped(\n gt: string | undefined,\n alleleBp: (number | undefined)[],\n referenceBp: number,\n) {\n const phased = gt?.includes('|')\n return (gt ?? '').split(/[/|]/).flatMap((index, k): RepeatCall[] => {\n const i = index === '' ? NaN : Number(index)\n const bp = i > 0 ? alleleBp[i - 1] : referenceBp\n if (!Number.isInteger(i) || bp === undefined) {\n return []\n }\n return [{ bp, ...(phased ? { haplotype: k + 1 } : {}) }]\n })\n}\n\nfunction callsOf(\n f: FeatureLike,\n alleleBp: (number | undefined)[] | undefined,\n referenceBp: number,\n) {\n const samples = ownField(f, 'samples') as\n Record<string, Record<string, unknown>> | undefined\n const called: Record<string, RepeatCall[]> = {}\n for (const [sample, fields] of Object.entries(samples ?? {})) {\n const reads = numbers(fields.SD)\n const lengths = numbers(fields.AL).flatMap((bp, i) =>\n bp !== undefined && bp > 0\n ? [reads[i] === undefined ? { bp } : { bp, spanningReads: reads[i] }]\n : [],\n )\n const calls =\n lengths.length > 0 || !alleleBp\n ? lengths\n : genotyped(strings(fields.GT)[0], alleleBp, referenceBp)\n if (calls.length > 0) {\n called[sample] = calls\n }\n }\n return Object.keys(called).length > 0 ? called : undefined\n}\n\n// A <CNV:TR> record's POS is the base before the array and SVLEN the\n// reference allele's length, while a VCF feature starts at that padding base.\nfunction spanOf(f: FeatureLike, tandem: boolean) {\n const start = field(f, 'start') as number\n const end = field(f, 'end') as number\n const svlen = numbers(field(f, 'SVLEN'))[0]\n return tandem && svlen !== undefined\n ? { start: start + 1, end: start + 1 + svlen }\n : { start, end }\n}\n\nexport function repeatArraysFrom(features: FeatureLike[]): RepeatArray[] {\n const arrays: RepeatArray[] = []\n for (const f of features) {\n const alleleBp = tandemAlleleBp(f)\n const { start, end } = spanOf(f, alleleBp !== undefined)\n const unit = repeatUnitOf(f)\n if (!(end > start) || unit === undefined) {\n continue\n }\n const refName = field(f, 'refName') as string\n const motif = first(f, MOTIF_FIELDS)\n const stated = first(f, NAME_FIELDS)\n arrays.push({\n key: `${refName}:${start}-${end}`,\n name:\n (stated && !PACKED_NAME.test(stated) ? stated : undefined) ??\n (motif && motif.length <= 12\n ? `(${motif})n`\n : `${refName}:${(start + 1).toLocaleString('en-US')}-${end.toLocaleString('en-US')}`),\n refName,\n start,\n end,\n unit,\n motif,\n calls: callsOf(f, alleleBp, end - start),\n })\n }\n return arrays.sort((a, b) => a.start - b.start)\n}\n", "// src/genes/geneFiles.ts\nvar GENE_TYPE = /(gene|gene_segment|RNA|transcript)$/i;\nvar isGene = (type) => GENE_TYPE.test(type) || type === \"CDS\" || type === \"exon\";\nfunction mergedIntervals(intervals) {\n const out = [];\n for (const iv of [...intervals].sort((a, b) => a.start - b.start)) {\n const last = out.at(-1);\n if (last && iv.start <= last.end) {\n last.end = Math.max(last.end, iv.end);\n } else {\n out.push({ ...iv });\n }\n }\n return out;\n}\nfunction strandOf(s) {\n return s === \"+\" ? 1 : s === \"-\" ? -1 : 0;\n}\nfunction unescape(value) {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\nfunction attributes(column) {\n const out = /* @__PURE__ */ new Map();\n for (const pair of column.split(\";\")) {\n const eq = pair.indexOf(\"=\");\n if (eq > 0) {\n out.set(pair.slice(0, eq).trim(), unescape(pair.slice(eq + 1).trim()));\n }\n }\n return out;\n}\nfunction gff3Row(line) {\n const cols = line.split(\"\t\");\n const start = Number(cols[3]);\n const end = Number(cols[4]);\n if (cols.length < 9 || !Number.isInteger(start) || !Number.isInteger(end)) {\n return void 0;\n }\n return {\n refName: cols[0],\n type: cols[2],\n start: start - 1,\n end,\n strand: strandOf(cols[6]),\n attrs: attributes(cols[8])\n };\n}\nfunction genesFromGff3Lines(lines) {\n const rows = [];\n for (const line of lines) {\n if (line.startsWith(\"##FASTA\")) {\n break;\n }\n const row = line.startsWith(\"#\") ? void 0 : gff3Row(line);\n if (row) {\n rows.push(row);\n }\n }\n const parentOf = /* @__PURE__ */ new Map();\n for (const { attrs } of rows) {\n const id = attrs.get(\"ID\");\n const parent = attrs.get(\"Parent\")?.split(\",\")[0];\n if (id && parent) {\n parentOf.set(id, parent);\n }\n }\n const rootOf = (row) => {\n let id = row.attrs.get(\"Parent\")?.split(\",\")[0] ?? row.attrs.get(\"ID\");\n if (!id) {\n return row.attrs.get(\"gene_id\");\n }\n const seen = /* @__PURE__ */ new Set();\n while (id && parentOf.has(id) && !seen.has(id)) {\n seen.add(id);\n id = parentOf.get(id);\n }\n return id;\n };\n const groups = /* @__PURE__ */ new Map();\n rows.forEach((row, i) => {\n const root = rootOf(row) ?? `#${i}`;\n const key = `${row.refName}\t${root}`;\n const group = groups.get(key) ?? groups.set(key, { rows: [] }).get(key);\n group.rows.push(row);\n if (!row.attrs.has(\"Parent\") && !group.top) {\n group.top = row;\n }\n });\n const genes = [];\n for (const [key, { top, rows: rows2 }] of groups) {\n if (top && !isGene(top.type)) {\n continue;\n }\n const first = top ?? rows2[0];\n const start = top?.start ?? Math.min(...rows2.map((r) => r.start));\n const end = top?.end ?? Math.max(...rows2.map((r) => r.end));\n const a = first.attrs;\n const spans = (type) => rows2.filter((r) => r.type === type).map((r) => ({ start: r.start, end: r.end }));\n const exons = spans(\"exon\");\n const coding = spans(\"CDS\");\n const transcribed = rows2.some(\n (r) => r !== top && r.type !== \"exon\" && r.type !== \"CDS\"\n );\n genes.push({\n name: a.get(\"Name\") ?? a.get(\"gene_name\") ?? a.get(\"gene\") ?? a.get(\"gene_id\") ?? key.split(\"\t\")[1],\n refName: first.refName,\n start,\n end,\n strand: first.strand,\n // A range read holds only the rows over its window, so a gene with\n // transcripts but no exon or CDS there is intronic in it. Only a gene\n // with no transcripts, as a bacterium's gene and CDS, is one exon.\n exons: exons.length ? mergedIntervals(exons) : transcribed ? mergedIntervals(coding) : [{ start, end }]\n });\n }\n return genes;\n}\nfunction mergeOverlappingByName(genes) {\n const out = [];\n const open = /* @__PURE__ */ new Map();\n for (const g of [...genes].sort((a, b) => a.start - b.start)) {\n const key = `${g.refName}\t${g.strand}\t${g.name}`;\n const last = open.get(key);\n if (last && g.start < last.end) {\n last.end = Math.max(last.end, g.end);\n last.exons = mergedIntervals([...last.exons, ...g.exons]);\n } else {\n const gene = { ...g, exons: mergedIntervals(g.exons) };\n out.push(gene);\n open.set(key, gene);\n }\n }\n return out;\n}\nvar BED_HEADER = /^(#|track\\s|browser\\s)/;\nfunction genesFromBed(text) {\n const rows = [];\n for (const line of text.split(\"\\n\")) {\n const cols = line.replace(/\\r$/, \"\").split(\"\t\");\n const start = Number(cols[1]);\n const end = Number(cols[2]);\n if (BED_HEADER.test(line) || cols.length < 3 || !Number.isInteger(start) || !(end > start)) {\n continue;\n }\n const refName = cols[0];\n const name = cols[3] && cols[3] !== \".\" ? cols[3] : `${refName}:${start + 1}-${end}`;\n const sizes = cols[10]?.split(\",\").filter((s) => s !== \"\").map(Number);\n const starts = cols[11]?.split(\",\").filter((s) => s !== \"\").map(Number);\n const blocks = sizes?.length && sizes.length === starts?.length ? sizes.map((size, i) => ({\n start: start + starts[i],\n end: start + starts[i] + size\n })) : [{ start, end }];\n rows.push({\n name,\n refName,\n start,\n end,\n strand: strandOf(cols[5]),\n exons: blocks\n });\n }\n return mergeOverlappingByName(rows);\n}\nfunction sniffedFormat(text) {\n const first = text.split(\"\\n\", 1e3).find((l) => l.trim() !== \"\" && !BED_HEADER.test(l));\n const cols = first?.split(\"\t\") ?? [];\n return /^\\d+$/.test(cols[1] ?? \"\") && /^\\d+$/.test(cols[2] ?? \"\") ? \"bed\" : \"gff3\";\n}\nfunction genesFromText(text, format = sniffedFormat(text)) {\n return format === \"bed\" ? genesFromBed(text) : genesFromGff3Lines(text.split(/\\r?\\n/));\n}\n\nexport {\n mergedIntervals,\n genesFromGff3Lines,\n mergeOverlappingByName,\n genesFromBed,\n genesFromText\n};\n", "import {\n mergeOverlappingByName,\n mergedIntervals,\n} from '@jbrowse/bandage-core/genes/geneFiles'\nimport { readConfObject } from '@jbrowse/core/configuration'\n\nimport { REPEAT_TRACK_HINT } from '../repeats/repeatFeatures'\nimport { namedTrack, ownField, trackLabel } from '../trackFeatures'\n\nimport type { FeatureLike, TrackChoice } from '../trackFeatures'\nimport type { GeneModel } from '@jbrowse/bandage-core/genes/genePins'\nimport type { AnyConfigurationModel } from '@jbrowse/core/configuration'\n\n// The adapters whose tracks hold gene models, in the order the session's\n// tracks are searched when no track is named.\nexport const GENE_ADAPTER_TYPES = new Set([\n 'Gff3TabixAdapter',\n 'Gff3Adapter',\n 'BedTabixAdapter',\n 'BedAdapter',\n 'GtfTabixAdapter',\n 'GtfAdapter',\n 'BigBedAdapter',\n 'NCListAdapter',\n])\n\nconst GENE_TRACK_HINT = /gene|refseq|gencode|ensembl|annotation/i\n\n// A BED track is as often peaks or repeats as genes, so one counts only where\n// its name says it is annotation\nconst BED_ADAPTER_TYPES = new Set(['BedTabixAdapter', 'BedAdapter'])\n\n// Which of the session's tracks to read genes from: the named one while the\n// assembly has it (a saved pick can name a track since removed), else the\n// first gene-bearing track on the assembly whose name says it is annotation,\n// else the first non-BED gene-bearing track. A track whose name says repeats is\n// never picked unnamed, as \"RepeatMasker annotation\" would be.\nexport function pickGeneTrack<T extends TrackChoice>(\n tracks: T[],\n named: string,\n) {\n const chosen = named ? namedTrack(tracks, named) : undefined\n if (chosen) {\n return chosen\n }\n const candidates = tracks.filter(\n t =>\n GENE_ADAPTER_TYPES.has(t.adapterType) &&\n !REPEAT_TRACK_HINT.test(trackLabel(t)),\n )\n return (\n candidates.find(t => GENE_TRACK_HINT.test(trackLabel(t))) ??\n candidates.find(t => !BED_ADAPTER_TYPES.has(t.adapterType))\n )\n}\n\ninterface LaneView {\n tracks?: readonly {\n configuration: AnyConfigurationModel\n displays: readonly { configuration: AnyConfigurationModel }[]\n }[]\n}\n\n// The `filter` of the gene track's lane in the view the graph is drawn in, so\n// the chips name what the lane draws. None where the view shows no such lane,\n// or has no tracks, as a graph genome view of its own.\nexport function laneFilters(view: object, trackId: string | undefined) {\n const lane = (view as LaneView).tracks?.find(\n t => readConfObject(t.configuration, 'trackId') === trackId,\n )?.displays[0]\n return lane\n ? ((readConfObject(lane.configuration, 'filter') as string[] | undefined) ??\n [])\n : []\n}\n\n// Records spanning a whole sequence, the types the GFF3 adapter declines to\n// widen a fetch for. RefSeq opens every molecule with a `region` named\n// ANONYMOUS.\nconst WHOLE_SEQUENCE_TYPES = new Set([\n 'chromosome',\n 'region',\n 'contig',\n 'supercontig',\n 'scaffold',\n])\n\n// JBrowse's BED parser splits a coding BED12 block into CDS and UTR parts and\n// keeps `exon` for non-coding ones, so all of them are exon\nconst EXON_PARTS = new Set([\n 'exon',\n 'CDS',\n 'five_prime_UTR',\n 'three_prime_UTR',\n 'UTR',\n])\n\nfunction exonsOf(f: FeatureLike, into: { start: number; end: number }[]) {\n const type = ownField(f, 'type')\n if (typeof type === 'string' && EXON_PARTS.has(type)) {\n into.push({\n start: ownField(f, 'start') as number,\n end: ownField(f, 'end') as number,\n })\n }\n const children = ownField(f, 'subfeatures') as FeatureLike[] | undefined\n for (const child of children ?? []) {\n exonsOf(child, into)\n }\n}\n\n// Genes from a track's features: every top-level feature but a whole-sequence\n// record, named by the first of gene_name, name, gene and gene_id it carries,\n// with the exons found anywhere under it merged. A feature with no exons is one exon,\n// its whole span. A BED track gives one feature per transcript, so a name's\n// overlapping features merge, while its copies down the contig stay apart.\n// UCSC's ncbiRefSeq.gff gene records carry their symbol only as gene_id. A\n// feature with none of those names is left out: its raw ID, RefSeq's\n// `id-NC_000913.3:1978503..1979270`, only restates where it is.\nexport function geneModelsFrom(features: FeatureLike[]): GeneModel[] {\n const genes: GeneModel[] = []\n for (const f of features) {\n const name =\n (ownField(f, 'gene_name') as string | undefined) ??\n (ownField(f, 'name') as string | undefined) ??\n (ownField(f, 'gene') as string | undefined) ??\n (ownField(f, 'gene_id') as string | undefined)\n const start = ownField(f, 'start') as number\n const end = ownField(f, 'end') as number\n if (\n !name ||\n !(end > start) ||\n WHOLE_SEQUENCE_TYPES.has(ownField(f, 'type') as string)\n ) {\n continue\n }\n const exons: { start: number; end: number }[] = []\n exonsOf(f, exons)\n genes.push({\n name,\n refName: ownField(f, 'refName') as string,\n start,\n end,\n strand: (ownField(f, 'strand') as number | undefined) ?? 0,\n exons: exons.length ? mergedIntervals(exons) : [{ start, end }],\n })\n }\n return mergeOverlappingByName(genes)\n}\n", "const host = JBrowseExports[\"tss-react/mui\"]\nconst read = name =>\n host != null && name in Object(host)\n ? host[name]\n : Object.assign(\n function () {\n throw new Error(\n \"This JBrowse does not provide '\" + name + \"' from '\" + \"tss-react/mui\" + \"' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse\",\n )\n },\n { jbrowseHostMissing: name },\n )\nexport const cx = /* @__PURE__ */ read(\"cx\")\nexport const keyframes = /* @__PURE__ */ read(\"keyframes\")\nexport const makeStyles = /* @__PURE__ */ read(\"makeStyles\")\nexport default host && host.__esModule ? host.default : host"],
5
5
  "mappings": "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",
6
6
  "names": ["isStringArray", "value", "item", "trackLanes", "track", "assemblyNames", "readConfObject", "lanes", "walkIndexed", "adapterConfig", "snapshotNamesFile", "cutsByHaplotype", "configHaplotypes", "defaultHaplotypes", "graphReferenceAssembly", "offReferenceProblem", "referenceAssembly", "assemblyName", "ownField", "f", "name", "namedTrack", "tracks", "named", "t", "trackLabel", "REPEAT_ADAPTER_TYPES", "REPEAT_TRACK_HINT", "pickRepeatTrack", "tracks", "named", "chosen", "namedTrack", "t", "trackLabel", "PACKED_NAME", "packedName", "f", "name", "ownField", "pair", "i", "field", "top", "MOTIF_FIELDS", "PERIOD_FIELDS", "NAME_FIELDS", "first", "names", "value", "one", "IUPAC", "repeatUnitOf", "period", "motif", "numbers", "n", "strings", "text", "TANDEM_REPEAT", "tandemAlleleBp", "alts", "rn", "rus", "rul", "ruc", "rb", "k", "alt", "bp", "known", "j", "unitLength", "count", "runBp", "genotyped", "gt", "alleleBp", "referenceBp", "phased", "index", "callsOf", "samples", "called", "sample", "fields", "reads", "lengths", "calls", "spanOf", "tandem", "start", "end", "svlen", "repeatArraysFrom", "features", "arrays", "unit", "refName", "stated", "a", "b", "mergedIntervals", "intervals", "out", "iv", "a", "b", "last", "mergeOverlappingByName", "genes", "out", "open", "g", "a", "b", "key", "last", "mergedIntervals", "gene", "GENE_ADAPTER_TYPES", "GENE_TRACK_HINT", "BED_ADAPTER_TYPES", "pickGeneTrack", "tracks", "named", "chosen", "namedTrack", "candidates", "t", "REPEAT_TRACK_HINT", "trackLabel", "laneFilters", "view", "trackId", "lane", "readConfObject", "WHOLE_SEQUENCE_TYPES", "EXON_PARTS", "exonsOf", "f", "into", "type", "ownField", "children", "child", "geneModelsFrom", "features", "genes", "name", "start", "end", "exons", "mergedIntervals", "mergeOverlappingByName", "host", "read", "name", "makeStyles", "read", "mui_default", "host"]
@@ -0,0 +1,3 @@
1
+ import{a as Te,d as H,e as et,g as U,h as tt,i as Mn,j as vn,k as En,l as Sn,m as _e,o as Oe,r as nt,s as ot}from"./chunk-MLVBPMBU.js";import{a as an,c as cn,e as Ae,f as rt,g as kn,i as Rn,j as Tn}from"./chunk-UW7INEQF.js";import{A as Qe,H as yn,I as wn,a as ke,c as ln,e as dn,f as ne,g as fn,h as Ke,i as Re,k as ze,l as un,m as de,n as pn,p as hn,q as Ze,r as mn,s as gn,v as bn,w as xn,x as Je,y as oe,z as A}from"./chunk-D5PRXUSS.js";import{e as _n}from"./chunk-LTN6XZR5.js";import{a as nn,d as sn}from"./chunk-SI64QXFH.js";import{c as D,d as te,g as en,j as Ue,k as Ee,l as on,m as rn}from"./chunk-YBZA7LPQ.js";import{a as ee,c as zt,d as V,e as We,f as Zt,g as O,q as tn,r as I,s as je,v as Ve}from"./chunk-4AAW5P6N.js";import{d as Jt,e as Qt,f as le}from"./chunk-VIVPTP5Z.js";import{a as He}from"./chunk-IKJZPPOA.js";import{g as E}from"./chunk-NDRLCGPC.js";import{b as Se}from"./chunk-YU7T5WOQ.js";var Ne=8,st=34,Pe=12,Ur=60;function jr({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function i(l){let c=Math.ceil(e/l),f=Math.floor((o-(l-1)*Ne)/l),u=(r-c*st-(c-1)*Ne)/c,d=(f-2*Pe)/t.w,p=t.h>0?(u-2*Pe)/t.h:1/0,h=n?d:Math.min(d,p),m=n?t.h:t.h*h,b=Math.floor(Math.max(Ur,Math.min(m+2*Pe,u)));return{columns:l,width:f,height:b,scale:h,total:c*(b+st)+(c-1)*Ne}}if(s!==void 0)return i(Math.max(1,Math.min(e,Math.round(s))));let a=i(1);if(n)return a;for(let l=2;l<=e;l++){let c=i(l);c.scale>a.scale&&(a=c)}return a}var Vr=[{value:"",label:"None",description:"Every lifted walk in one drawing"},{value:"walk",label:"A panel per walk",description:"One panel per lifted walk, side by side"},{value:"sample",label:"A row per sample",description:"A row per sample, a column per haplotype"}];function Kr(e){let t=typeof e=="string"?{field:e}:e??{};return{field:t.field==="walk"||t.field==="sample"?t.field:"",domain:[...t.domain??[]],...t.columns===void 0?{}:{columns:t.columns}}}function On(e,t){let n=new Map(t.map((r,s)=>[r,s])),o=r=>n.get(r)??t.length;return e.map((r,s)=>({name:r,i:s})).sort((r,s)=>o(r.name)-o(s.name)||r.i-s.i).map(({name:r})=>r)}function zr(e,t,n=[]){let o=On(e,n),r={columns:void 0,count:e.length,cells:e.map(c=>o.indexOf(c))};if(t==="walk")return r;let s=e.map(c=>{let f=Qt(c);return f&&Number.isInteger(f.haplotype)&&f.haplotype>=0?{sample:f.sample,column:Math.max(0,f.haplotype-1)}:void 0}),i=On([...new Set(s.flatMap(c=>c?[c.sample]:[]))],n),a=Math.max(1,...s.map(c=>c?c.column+1:1)),l=s.map(c=>c?i.indexOf(c.sample)*a+c.column:-1);return l.includes(-1)||new Set(l).size<l.length?r:{columns:a,count:i.length*a,cells:l}}var Zr=Math.PI/24;function An(e,t){let n=e[t-1],o=e[t],r=e[t+1];if(!n||!r)return 0;let s=Math.abs(Math.atan2(r.y-o.y,r.x-o.x)-Math.atan2(o.y-n.y,o.x-n.x));return s>Math.PI?2*Math.PI-s:s}function Jr(e,t,n,o,r){let s=(h,m)=>Math.max(Math.hypot(m.x-h.x,m.y-h.y)**.5,1e-9),i=s(e,t),a=i+s(t,n),l=a+s(n,o),c=i+r*(a-i),f=(h,m,b,g)=>{let x=(c-b)/(g-b);return{x:h.x+(m.x-h.x)*x,y:h.y+(m.y-h.y)*x}},u=f(e,t,0,i),d=f(t,n,i,a),p=f(n,o,a,l);return f(f(u,d,0,a),f(d,p,i,l),i,a)}var Nn=(e,t)=>({x:2*t.x-e.x,y:2*t.y-e.y});function Pn(e){if(e.length<3)return e;let t=[e[0]];for(let n=0;n+1<e.length;n++){let o=e[n],r=e[n+1],s=Math.ceil(Math.max(An(e,n),An(e,n+1))/Zr),i=e[n-1]??Nn(r,o),a=e[n+2]??Nn(o,r);for(let l=1;l<s;l++)t.push(Jr(i,o,r,a,l/s));t.push(r)}return t}function $n(e,t){let n=e.nodes.filter(b=>O(b)&&(t[b.id]?.length??0)>0);if(n.length<2)return t;let o=n.map(b=>{let g=t[b.id],x=g[Math.floor(g.length/2)];return{x:x.x,y:x.y,r:b.stable.start+b.length/2,w:b.length}}),r=o.reduce((b,g)=>b+g.w,0);if(r===0)return t;let s=o.reduce((b,g)=>b+g.x*g.w,0)/r,i=o.reduce((b,g)=>b+g.y*g.w,0)/r,a=o.reduce((b,g)=>b+g.r*g.w,0)/r,l=0,c=0;for(let b of o)l+=b.w*(b.x-s)*(b.r-a),c+=b.w*(b.y-i)*(b.r-a);let f=-Math.atan2(c,l),u=Math.cos(f),d=Math.sin(f),p={};for(let[b,g]of Object.entries(t))p[b]=g.map(x=>{let M=x.x-s,y=x.y-i;return{x:s+u*M-d*y,y:i+d*M+u*y}});let h=0,m=0;for(let b of e.nodes)if(!O(b))for(let g of p[b.id]??[])g.y>i?h++:m++;if(m>h)for(let b of Object.values(p))for(let g of b)g.y=2*i-g.y;return p}var Cn=30;function Qr(e,t){let{opts:n}=t,o=new Map(t.nodes.map(d=>[d.id,Ae(n,d.length)])),r=d=>o.get(d)??n.minimumNodeLength,s=e.nodes.filter(O).sort((d,p)=>d.stable.start-p.stable.start),i=new Map,a=0;for(let d of s)i.set(d.id,{x:a,y:0}),a+=r(d.id)+n.edgeLength;let l=Te(e),c=new Map(s.map(d=>[d.id,0])),f=s.map(d=>d.id);for(let d of f){let p=i.get(d),h=c.get(d)+1;for(let m of l.get(d)??[])c.has(m)||(c.set(m,h),i.set(m,{x:p.x+r(d)/2,y:Cn*h}),f.push(m))}let u=0;for(let d of e.nodes)i.has(d.id)||i.set(d.id,{x:u++*a/e.nodes.length,y:Cn*3});return i}function In(e,t){let n=Qr(e,t);return t.nodes.map(o=>({...o,...n.get(o.id)}))}var es=.5;function Ln(e,t,n=new Set){let o=new Map(t.map(s=>[s.edgeIndex,`${an}${s.edgeIndex}`])),r=[];return e.edges.forEach((s,i)=>{let a=o.get(i);if(!n.has(i))if(a===void 0)r.push(s);else{let{fromStrand:l,toStrand:c}=s;r.push({from:s.from,to:a,...l?{fromStrand:l}:{}},{from:a,to:s.to,...c?{toStrand:c}:{}})}}),{graph:{...e,nodes:[...e.nodes,...[...o.values()].map(s=>({id:s,name:s,length:0,depth:0}))],edges:r},routes:o,ids:new Set(o.values())}}function Bn(e,t,n,o,r){let s=new Map(e.nodes.map(i=>[i.id,i.length]));return t.map(i=>{let a=i.bypassed.reduce((f,u)=>f+(s.get(u)??0),0),l=Math.max(r.minimumNodeLength,o(a)*es),c=n.get(i.edgeIndex);return{id:c,name:c,length:Math.round(l*1e6/r.nodeLengthPerMegabase),depth:0}})}function Xn(e,t){let n={...e},o={};for(let[r,s]of t){let i=n[s];delete n[s],i?.length&&(o[r]=i)}return{nodePositions:n,deletionRoutes:o}}function ts(e,t){let n=e.indexOf(":"),o=e.indexOf(":",n+1);if(n!==-1&&o!==-1){let r=e.slice(0,n),s=e.slice(n+1,o),i=e.slice(o+1);s==="i"||s==="f"?t[r]=+i:s==="Z"&&(t[r]=i)}}function fe(e){let t={};for(let n of e)ts(n,t);return t}function Fn(e){let{SN:t,SO:n,SR:o}=e.tags;return typeof t=="string"&&typeof n=="number"&&typeof o=="number"?{refName:t,start:n,rank:o}:void 0}var Dn=62,ns=60;function os(e){let t=[],n="+",o=0;function r(s){s>o&&t.push({id:e.slice(o,s),strand:n})}for(let s=0;s<e.length;s++){let i=e.charCodeAt(s);(i===Dn||i===ns)&&(r(s),n=i===Dn?"+":"-",o=s+1)}return r(e.length),t}function qn(e){let t={nodes:[],links:[],paths:[],walks:[],header:[],id:""};for(let n of e.split(`
2
+ `)){let o=n.endsWith("\r")?n.slice(0,-1):n,r=o.indexOf(" "),s=r===-1?o:o.slice(0,r);if(s==="H"){let[,...i]=o.split(" ");t.header.push(fe(i))}else if(s==="S"){let[,i,...a]=o.split(" "),l,c,f,u=!1,d=a[0]??"*";/^\d+$/.test(d)?(l=+d,c=a[1]??"*",f=a.slice(2)):(u=!0,c=d,l=c==="*"?0:c.length,f=a.slice(1));let p=fe(f);u&&"LN"in p&&(l=+p.LN),t.nodes.push({id:i,length:l,sequence:c,tags:p})}else if(s==="E"){let[,,i,a,,,,,l,...c]=o.split(" ");i&&a&&t.links.push({source:i.slice(0,-1),target:a.slice(0,-1),strand1:i.at(-1),strand2:a.at(-1),cigar:l??"*",tags:fe(c)})}else if(s==="L"){let[,i,a,l,c,f,...u]=o.split(" ");i&&l&&c&&t.links.push({source:i,target:l,strand1:a,strand2:c,cigar:f??"*",tags:fe(u)})}else if(s==="W"){let[,i,a,l,c,f,u,...d]=o.split(" ");i&&a&&l&&c&&f&&u&&t.walks.push({sample:i,haplotype:+a,contig:l,start:c==="*"?-1:+c,end:f==="*"?-1:+f,segments:os(u),tags:fe(d)})}else if(s==="P"){let[,i,a,...l]=o.split(" ");i&&a&&t.paths.push({name:i,path:a,rest:l})}}return t}function rs(e,t){let n=new Map,o=new Map;function r(i,a){n.has(i)||n.set(i,a)}function s(i,a){let l=o.get(i);l===void 0&&r(i,a),o.set(i,(l??0)+1)}for(let i of e.links)r(i.source,i.strand1==="-"?"-":"+"),r(i.target,i.strand2==="-"?"-":"+");for(let{steps:i}of t)for(let a of i)s(a.id,a.strand);for(let i of e.walks)for(let a of i.segments)s(a.id,a.strand);return{canonical:n,traversals:o}}var Gn=e=>e.start===-1?0:e.start;function ss(e){return{...I(e.name),steps:e.path.split(",").map(t=>({id:t.slice(0,-1),strand:t.endsWith("-")?"-":"+"}))}}function is(e,t){return[...t,...e.walks.map(n=>({name:`${n.sample}#${n.haplotype}#${n.contig}`,start:Gn(n),steps:n.segments}))]}function as(e){let t=e.tags.SM;if(typeof t!="string")return;let n=t.split(",").map(o=>o.trim()).filter(Boolean);return n.length>0?n:void 0}var ue=e=>typeof e=="number"&&e>0?e:void 0;function cs({tags:e,length:t}){let n=ue(e.RC)??ue(e.FC)??ue(e.KC);return ue(e.dp)??ue(e.DP)??(n!==void 0&&t>0?n/t:void 0)}function ls(e,t,n){return{id:`${e.id}${t}`,name:e.id,length:e.length,depth:n,stable:Fn(e),samples:as(e)}}function Yn(e,t="Imported GFA"){let n=[],o=[],r=e.paths.map(ss),{canonical:s,traversals:i}=rs(e,r),a=new Map,l=g=>{let x=a.get(g);return x===void 0&&(x=`${g}${s.get(g)??"+"}`,a.set(g,x)),x},c=new Map;for(let g of e.nodes){if(c.has(g.id))continue;c.set(g.id,g.length);let x=cs(g)??Math.max(i.get(g.id)??1,1);n.push(ls(g,s.get(g.id)??"+",x))}for(let g of e.links)o.push({from:l(g.source),to:l(g.target),fromStrand:g.strand1==="-"?"-":"+",toStrand:g.strand2==="-"?"-":"+"});let f=[],u=new Map,d=(g,x)=>u.get(g)?.get(x);function p(g,x,M){let y=u.get(g);y||(y=new Map,u.set(g,y)),y.set(x,M)}let h=o.map(g=>{let x=d(g.from,g.to);return x||(x=new Set,p(g.from,g.to,x),p(g.to,g.from,x)),x});function m(g,x){for(let M=0;M<g.length-1;M++)d(g[M],g[M+1])?.add(x)}e.paths.forEach(({name:g},x)=>{let{start:M,steps:y}=r[x],w=y.map(v=>l(v.id));f.push({name:g,nodeIds:w,start:M}),m(w,g)});for(let g of e.walks){let x=g.segments.map(y=>l(y.id)),M=`${g.sample}#${g.haplotype}#${g.contig}`;f.push({name:M,nodeIds:x,start:Gn(g),sample:g.sample,haplotype:g.haplotype,contig:g.contig,...en(g.tags)}),m(x,M)}o.forEach((g,x)=>{let M=h[x];M.size>0&&(g.pathIds=[...M])});let b=e.paths.length>0||e.walks.length>0?je(is(e,r),g=>c.get(g)??0):void 0;return{name:t,nodes:n,edges:o,paths:f.length>0?f:void 0,anchorPaths:b?.anchorPaths,pathVisits:b?.pathVisits,anchoredBy:n.some(g=>g.stable)?"tags":void 0}}function ds(e,t){if(typeof e!="string")return Ue(e,t);let n=nn(e);return n?Ue(n,t):Yn(qn(e),t)}function ql(e,t,n={}){let o=ds(e,t);if(o.nodes.length===0)throw new Error(`No graph segments in ${t}`);if(n.maxNodes!==void 0&&o.nodes.length>n.maxNodes)throw new Error(`Graph too large to draw: ${o.nodes.length.toLocaleString()} nodes (limit ${n.maxNodes.toLocaleString()}). Zoom in to a smaller region, or raise maxGraphNodes on this view.`);return Ve(o,n.referencePath)}var K={engine:"fmmm",quality:2,linearLayout:!1,bubbleSpread:"auto",spacing:1,componentSeparation:1,showDeletionEdges:!0};function Wn(e={}){return{engine:e.engine??K.engine,quality:e.quality??K.quality,linearLayout:e.linearLayout??K.linearLayout,bubbleSpread:e.bubbleSpread??K.bubbleSpread,spacing:e.spacing??K.spacing,componentSeparation:e.componentSeparation??K.componentSeparation,showDeletionEdges:e.showDeletionEdges??K.showDeletionEdges}}var fs=15;function us(e,t,n){let o=e.nodes.some(O),r=Wn(n),s={...t,opts:{...t.opts,edgeLength:t.opts.edgeLength*r.spacing}};return{graph:{nodes:o?In(e,s):s.nodes,edges:e.edges},options:{quality:r.quality,linearLayout:r.linearLayout,...s.opts,componentSeparation:fs*r.componentSeparation,...o?{rotateComponents:!1}:{},engine:r.engine}}}function it(e,t){let n=e.nodes.some(O);return[...Object.values(Wn(t)),n,e.referencePath??""].join("|")}async function Hn(e,t,n){let o=Tn(t.bubbleSpread),{shown:r,hidden:s}=xn(e,bn(e),t.showDeletionEdges!==!1),i=Ln(e,r,s),a=mn(i.graph,i.ids),l={...a.graph,nodes:a.graph.nodes.filter(x=>!i.ids.has(x.id))},c=rt(l,o),{result:f,duration:u}=await n(us(a.graph,{...c,nodes:[...c.nodes,...Bn(e,r,i.routes,kn(l,o),c.opts)]},t)),d=rt(e,o),p=new Map(d.nodes.map(x=>[x.id,Ae(d.opts,x.length)])),h=Object.fromEntries(Object.entries(f.nodePositions).map(([x,M])=>[x,Pn(M)])),m=gn(h,a.runs,x=>p.get(x)??0),{nodePositions:b,deletionRoutes:g}=Xn(e.nodes.some(O)?$n(e,m):m,i.routes);return{result:{...f,nodePositions:b,stranded:!0,...r.length?{deletionRoutes:g,extent:Un(g)}:{}},duration:u}}function Un(e){let t=1/0,n=1/0,o=-1/0,r=-1/0;for(let s of Object.values(e))for(let i of s)t=Math.min(t,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x),r=Math.max(r,i.y);return{minX:t,minY:n,maxX:o,maxY:r}}var pe=40,ps=1e-6,hs=100;function at(e){return Math.max(ps,Math.min(hs,e))}function ms(e,t,n,o=pe){let r=t-e.h*n;return o-e.minY*n+Math.max(0,r)/2}function Gl(e,t,n,o,{minScale:r=0,padLeft:s=pe,padTop:i=pe,padRight:a=pe,padBottom:l=pe}={}){let c=t-s-a,f=n-i-l;if(c<=0||f<=0||!(e.w>0||!o&&e.h>0))return;let u=e.w>0?c/e.w:1/0,d=e.h>0?f/e.h:1/0,p=at(Math.max(r,o?u:Math.min(u,d))),h=c-e.w*p;return{scale:p,translateX:s-e.minX*p+Math.max(0,h)/2,translateY:ms(e,f,o?1:p,i)}}function Yl(e,t={}){let{minX:n,minY:o,maxX:r,maxY:s}=Un(e.nodePositions),{region:i}=t;e.referenceAxis&&i&&i.end>i.start&&(n=i.start,r=i.end);let a=t.extent??e.extent;return a&&(n=Math.min(n,a.minX??n),o=Math.min(o,a.minY??o),r=Math.max(r,a.maxX??r),s=Math.max(s,a.maxY??s)),{minX:n,minY:o,w:r-n,h:s-o}}var gs=4;function ct(e=gs){let t=new WeakMap,n=o=>{let r=t.get(o);return r||(r=new Map,t.set(o,r)),r};return{layout(o,r,s){let i=n(o),a=it(o,r),l=i.get(a);if(l)return l.run;i.size>=e&&i.delete(i.keys().next().value);let c=performance.now(),f={run:Hn(o,r,s).then(u=>(f.done=u.result,{...u,duration:u.duration||performance.now()-c}))};return f.run.catch(()=>{i.get(a)===f&&i.delete(a)}),i.set(a,f),f.run},ready(o,r){return t.get(o)?.get(it(o,r))?.done},inherit(o,r){let s=t.get(o);s&&o!==r&&t.set(r,s)}}}function bs(e,t){return{scaleX:e,scaleY:t?1:e,pixelRows:t}}function lt(e,t,n,o){return{minX:-e.translateX/t.scaleX,minY:-e.translateY/t.scaleY,maxX:(n-e.translateX)/t.scaleX,maxY:(o-e.translateY)/t.scaleY}}function xs(e,t){let n=(e.maxX-e.minX)*t,o=(e.maxY-e.minY)*t;return{minX:e.minX-n,minY:e.minY-o,maxX:e.maxX+n,maxY:e.maxY+o}}function ys(e,t){return t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY}function ws(e,t,n,o,r){let s=at(e.scale*t),i=s/e.scale;return{scale:s,translateX:n-(n-e.translateX)*i,translateY:r?e.translateY:o-(o-e.translateY)*i}}function Ms(e,t,n,o){return{x:(e-n.translateX)/o.scaleX,y:(t-n.translateY)/o.scaleY}}var z=JBrowseExports["@jbrowse/render-core/RenderLifecycleMixin"],vs=e=>z!=null&&e in Object(z)?z[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/render-core/RenderLifecycleMixin' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),jn=vs("RenderLifecycleMixin"),Hd=z&&z.__esModule?z.default:z;function Vn(e){return t=>e.includes(t)?t:void 0}function Vd(e){return E.snapshotProcessor(E.maybe(E.enumeration(e)),{preProcessor:Vn(e)})}function $e(e,t){return E.snapshotProcessor(E.optional(E.enumeration(e),t),{preProcessor:Vn(e)})}var sf=600,af=160,cf=[1,1,1,1],lf="rgb(255, 255, 255)",df=5,ff=new Set(["tubemap","tubemapref"]),uf=Se(()=>import("./ChooseSamplesDialog-JRN4YLBY.js")),pf=Se(()=>import("./ChooseWalksDialog-SM326TOX.js")),hf=Se(()=>import("./HighlightColorDialog-S2WPOSDF.js")),mf=12,gf=[{bp:0,label:"None"},{bp:3,label:"Under 3 bp"},{bp:10,label:"Under 10 bp"},{bp:50,label:"Under 50 bp, leaving structural variants"},{bp:1e3,label:"Under 1 kb"}];function bf(e){if(typeof e.uri=="string")return e.uri;let n=e.segmentsLocation?.uri;return typeof n=="string"&&n.endsWith(He)?n.slice(0,-He.length):void 0}var xf=1.15,yf=1.6,wf=150,Mf=1,vf=40,Ef=[{value:"each",label:"A tube per haplotype"},{value:"grouped",label:"A tube per haplotype, grouped by route"},{value:"bundled",label:"A tube per route"}],Es={nodeStrokes:[],nodeStrokeRuns:new Map,arrows:[],arrowRuns:new Map,edgeCurves:[],edgeCurveRuns:new Map};function Sf(...e){}var Ss=5e6;function kf(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:`${Math.round(e/1e3)} kb`}var ks=2e4;function Rf(e){return("uri"in e?e.uri.split(/[?#]/)[0]:"localPath"in e?e.localPath:"name"in e?e.name:"").split(/[\\/]/).at(-1)??""}function Tf(e){return e&&"uri"in e&&e.uri?new URL(e.uri,e.baseUri??window.location.href).href:void 0}function _f(e){return e.builtViewport!==void 0&&e.paintedViewport===e.builtViewport&&e.builtViewport.viewportDirty===e.viewportDirty&&!e.viewportRebuildPending}function Of(e){let{width:t,height:n}=e.viewBox;return lt(e,e.axisScale,t,n)}var Af=ct(),Nf=E.compose("GraphPane",jn(),E.model({layoutQuality:E.optional(E.number,2),layoutEngine:$e(cn,"fmmm"),linearLayout:E.optional(E.boolean,!1),bubbleSpread:$e(Rn,"auto"),tubeMapFold:E.optional(E.number,0),tubeMapRoutes:$e(["each","grouped","bundled"],"each"),tubeMapColorBy:E.optional(E.string,""),geneTrackId:E.optional(E.string,""),repeatTrackId:E.optional(E.string,""),repeatKey:E.optional(E.string,""),walkLayers:E.optional(E.frozen(),[]),referencePath:E.optional(E.string,""),showPerf:E.optional(E.boolean,!1),connectorThickness:E.optional(E.number,2),scale:E.optional(E.number,1),translateX:E.optional(E.number,0),translateY:E.optional(E.number,0),paneHeight:E.maybe(E.number),maxGraphNodes:E.optional(E.number,ks),connectedViewId:E.maybe(E.string),maxRegionBp:E.optional(E.number,Ss),subgraphContext:E.optional(E.number,1),subgraphHaplotypes:E.maybe(E.frozen()),expandedWalks:E.optional(E.frozen(),[])})).volatile(()=>({graph:void 0,walkCut:void 0,graphRegion:void 0,loadedReferencePath:void 0,layoutResult:void 0,drawnLayoutMode:void 0,legendSize:{width:0,height:0},indexBubbles:void 0,foldedBelowBp:void 0,geneTrackFeatures:void 0,walkGeneFeatures:void 0,walkRowSampleTable:void 0,repeatArrays:void 0,handledLayoutMode:void 0,openBubbles:[],error:void 0,isLoading:!1,loadCanceled:!1,statusMessage:"",hoveredNode:null,hoveredAt:null,hoveredTube:null,hoveredPanel:null,hoveredRowWalks:[],hoveredBubble:null,pointerInPane:!1,stripHover:null,hoveredWalkRow:null,hoveredEdge:null,selectedNode:null,viewportDirty:0,positionsVersion:0,morphEntering:void 0,drawnBatch:Es,builtViewport:void 0,paintedViewport:void 0,draggingNode:null,isPanning:!1,viewportOwner:"fit",viewportDirtyTimer:void 0,positionsDirtyFrame:0,lastFetchMs:void 0,readsShown:void 0,lastLayoutMs:void 0,lastGeometryMs:void 0,lastGeometryStrokeCount:void 0,viewportRebuildPending:!1}));var Kn=2,zn=8192;function re(e=0,t=0){let n=typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,Kn);return Math.min(n,zn/Math.max(e,t,1))}function dt(e,t,n){let o=re(t,n),r=Math.round(t*o),s=Math.round(n*o);(e.width!==r||e.height!==s)&&(e.width=r,e.height=s);let i=`${t}px`,a=`${n}px`;return e.style.width!==i&&(e.style.width=i),e.style.height!==a&&(e.style.height=a),o}var Lf=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1,this.fit=1,this.painted=null;let t=e.getContext("2d");if(!t)throw new Error("Canvas 2D context not available");this.canvas=e,this.ctx=t}setErrorHandler(e){}releaseOffscreenTargets(){}resize(e,t){this.fit=dt(this.canvas,e,t)/re()}uploadGeometry(e){this.batch=e,this.highlightedEdge=null,this.painted=null}setNodeHighlights(e){this.nodeHighlights=e,this.painted=null}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t,this.painted=null}updateTransform(e){this.transform=e}fitted(){let e=this.transform,t=this.fit;return!e||t===1?e:{...e,scaleX:e.scaleX*t,scaleY:e.scaleY*t,translateX:e.translateX*t,translateY:e.translateY*t,dpr:e.dpr*t}}render(e){let t=this.fitted();if(!t)return;let n=this.ctx,{width:o,height:r}=n.canvas;e[3]<1&&n.clearRect(0,0,o,r),e[3]>0&&(n.fillStyle=et([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,o,r));let s=this.batch;if(!s)return;n.lineCap="round",n.lineJoin="round";let{edges:i,nodes:a,arrows:l}=this.paintedGroups(s);for(let{color:c,items:f}of i)this.strokeCurves(f,c,t);for(let{color:c,items:f}of a)this.strokeNodes(f,c,t);for(let{color:c,items:f}of l)this.fillArrows(f,c,t)}paintedGroups(e){if(this.painted)return this.painted;let t=this.highlightFactor,n=this.edgeRun(e.edgeCurveRuns),o=this.edgeRun(e.arrowRuns),r=this.liftedStrokes(e);return this.painted={edges:se(e.edgeCurves,(s,i)=>({color:Ce(n,i)?U(s.color,t):s.color,weight:s.thickness,last:Ce(n,i)})),nodes:se(e.nodeStrokes,(s,i)=>{let a=r.get(i);return{color:a===void 0?s.color:U(s.color,a),weight:s.thickness,last:a!==void 0}}),arrows:se(e.arrows,(s,i)=>({color:Ce(o,i)?U(s.color,t):s.color,weight:0,last:Ce(o,i)}))}}renderHighlights(){let e=this.ctx;e.clearRect(0,0,e.canvas.width,e.canvas.height);let t=this.batch,n=this.fitted();if(!n||!t)return;e.lineCap="round",e.lineJoin="round";let o=this.highlightFactor,r=Zn(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:l}of se(r,c=>({color:U(c.color,o),weight:c.thickness,last:!1})))this.strokeCurves(l,a,n);let s=[...this.liftedStrokes(t)];for(let{color:a,items:l}of se(s,([c,f])=>({color:U(t.nodeStrokes[c].color,f),weight:t.nodeStrokes[c].thickness,last:!1})))this.strokeNodes(l.map(([c])=>t.nodeStrokes[c]),a,n);let i=Zn(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:l}of se(i,c=>({color:U(c.color,o),weight:0,last:!1})))this.fillArrows(l,a,n)}edgeRun(e){return this.highlightedEdge===null?void 0:e.get(this.highlightedEdge)}liftedStrokes(e){let t=new Map;for(let[n,o]of this.nodeHighlights){let r=e.nodeStrokeRuns.get(n);if(r)for(let s=r.start;s<r.start+r.count;s++)t.set(s,o)}return t}strokeCurves(e,t,n){let o=this.ctx;o.strokeStyle=H(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.curves[0];o.moveTo(s.x0*n.scaleX+n.translateX,s.y0*n.scaleY+n.translateY);for(let i of r.curves)o.bezierCurveTo(i.cx0*n.scaleX+n.translateX,i.cy0*n.scaleY+n.translateY,i.cx1*n.scaleX+n.translateX,i.cy1*n.scaleY+n.translateY,i.x1*n.scaleX+n.translateX,i.y1*n.scaleY+n.translateY)}o.stroke()}strokeNodes(e,t,n){let o=this.ctx;o.strokeStyle=H(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.points[0];o.moveTo(s.x*n.scaleX+n.translateX,s.y*n.scaleY+n.translateY);for(let i=1,a=r.points.length;i<a;i++){let l=r.points[i];o.lineTo(l.x*n.scaleX+n.translateX,l.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t,n){let o=this.ctx;o.fillStyle=H(t),o.beginPath();for(let r of e){let[s,i,a,l]=Ts(r,n);o.moveTo(s.x,s.y),o.lineTo(i.x,i.y),o.lineTo(a.x,a.y),o.lineTo(l.x,l.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.painted=null}},Rs=.25;function Ts(e,t){let n=Math.cos(e.angle),o=Math.sin(e.angle),r=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,i=e.length*t.dpr,a=e.halfWidth*t.dpr,l=r-n*i,c=s-o*i,f=i*(1-Rs);return[{x:r,y:s},{x:l-o*a,y:c+n*a},{x:r-n*f,y:s-o*f},{x:l+o*a,y:c-n*a}]}function Zn(e,t){return t?e.slice(t.start,t.start+t.count):[]}function Ce(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function se(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let i=e[r],{color:a,weight:l,last:c}=t(i,r),f=c?o:n,u=`${a}:${l}`,d=f.get(u);d?d.items.push(i):f.set(u,{color:a,items:[i]})}return[...n.values(),...o.values()]}var N=e=>+e.toFixed(1),_s=e=>+e.toFixed(3);function Os(e){let t=/^rgba?\(([^,]+),([^,]+),([^,)]+)(?:,([^)]+))?\)$/.exec(e.replaceAll(" ",""));if(!t)return{color:e,opacity:1};let n=t[4]===void 0?1:Number(t[4]);return{color:`rgb(${t[1]},${t[2]},${t[3]})`,opacity:n}}function ft(e,t){let{color:n,opacity:o}=Os(t);return`${e}="${n}"${o<1?` ${e}-opacity="${_s(o)}"`:""}`}var Jn=.5,Qn=.25;function Df(e,t){let n=[],o=[],r=(c,f)=>{let u={d:`M${N(c)} ${N(f)}`,segments:0,x0:c,x1:c,y0:f,y1:f};return o.push(u),u},s=c=>{let f=o.at(-1)??r(c[0],c[1]);for(let u=0;u<c.length;u+=2)f.x0=Math.min(f.x0,c[u]),f.x1=Math.max(f.x1,c[u]),f.y0=Math.min(f.y0,c[u+1]),f.y1=Math.max(f.y1,c[u+1]);return f.segments++,f},i=c=>{let f=new Set;return o.map(u=>{if(!c||u.x1-u.x0>=Jn||u.y1-u.y0>=Jn)return u.d;let d=(u.x0+u.x1)/2,p=(u.y0+u.y1)/2,h=`${Math.round(d/Qn)} ${Math.round(p/Qn)}`;return u.segments===0||f.has(h)?"":(f.add(h),`M${N(d)} ${N(p)}h0`)}).join("")},a={canvas:void 0,fillStyle:"#000",strokeStyle:"#000",lineWidth:1,lineCap:"butt",lineJoin:"miter",beginPath(){o=[]},moveTo(c,f){r(c,f)},lineTo(c,f){s([c,f]).d+=`L${N(c)} ${N(f)}`},bezierCurveTo(c,f,u,d,p,h){s([c,f,u,d,p,h]).d+=`C${N(c)} ${N(f)} ${N(u)} ${N(d)} ${N(p)} ${N(h)}`},closePath(){let c=o.at(-1);c&&(c.d+="Z")},stroke(){let c=i(a.lineCap!=="butt");c&&n.push(`<path d="${c}" fill="none" ${ft("stroke",a.strokeStyle)} stroke-width="${N(a.lineWidth)}" stroke-linecap="${a.lineCap}" stroke-linejoin="${a.lineJoin}"/>`)},fill(){let c=i(!1);c&&n.push(`<path d="${c}" ${ft("fill",a.fillStyle)}/>`)},clearRect(){n.length=0},fillRect(c,f,u,d){n.push(`<rect x="${N(c)}" y="${N(f)}" width="${N(u)}" height="${N(d)}" ${ft("fill",a.fillStyle)}/>`)}},l={width:e,height:t,style:{},getContext:()=>a};return a.canvas=l,{canvas:l,markup:()=>n.join("")}}var As=50;function eo(e,t){return t>0?Math.max(1,e/t):As}function Ns(e){let t=new Set,n=1/0,o=-1/0;for(let r of e)t.add(r.minY),n=Math.min(n,r.minY),o=Math.max(o,r.minY);return t.size>1?(o-n)/(t.size-1):void 0}function to(e,t,n){let o=eo(t,e.length);return{x:o,y:n>0?eo(n,e.length):Ns(e)??o}}function Ps(e,t,n,o){return e===void 0?to(t,n,o):typeof e=="number"?{x:e,y:e}:e}function $s(e,t,n){let o=e.get(t);o||(o=new Map,e.set(t,o));let r=o.get(n);return r||(r=[],o.set(n,r)),r}function no(e,t,n,o,r,s,i){let a=Math.floor(n/t.x),l=Math.floor(r/t.x),c=Math.floor(o/t.y),f=Math.floor(s/t.y);for(let u=a;u<=l;u++)for(let d=c;d<=f;d++)$s(e,u,d).push(i)}function oo(e,t,n,o,r,s){let i=Math.floor((n-r)/t.x),a=Math.floor((n+r)/t.x),l=Math.floor((o-s)/t.y),c=Math.floor((o+s)/t.y),f=[],u=new Set;for(let d=i;d<=a;d++){let p=e.get(d);if(p)for(let h=l;h<=c;h++){let m=p.get(h);if(m)for(let b of m)u.has(b)||(u.add(b),f.push(b))}}return f}var ro=class{constructor(e,t){this.cells=new Map;let n=[],o=0,r=0;for(let[s,i]of Object.entries(e))for(let a=0;a<i.length-1;a++){let l=i[a],c=i[a+1],f=Math.min(l.x,c.x),u=Math.min(l.y,c.y),d=Math.max(l.x,c.x),p=Math.max(l.y,c.y);o+=d-f,r+=p-u,n.push({entry:{nodeId:s,segmentIdx:a},minX:f,minY:u,maxX:d,maxY:p})}this.cellSize=Ps(t,n,o,r);for(let s of n)no(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return oo(this.cells,this.cellSize,e,t,n,o)}},so=class{constructor(e,t,n,o,r,s=0,i,a=!1){this.cells=new Map,this.edgeCurves=Sn(e,t,o,r,s,i,a);let l=[],c=0,f=0;for(let u=0;u<t.edges.length;u++){let d=t.edges[u],p=e[d.from],h=e[d.to],m=this.edgeCurves.get(u);if(p?.length&&h?.length&&m){let{minX:b,minY:g,maxX:x,maxY:M}=ln(m),y=d.pathIds?.length??0;if(n&&y>0){let w=0,v=0;for(let S of Re(p,h,y,o))w=Math.max(w,Math.abs(S.x)),v=Math.max(v,Math.abs(S.y));b-=w,g-=v,x+=w,M+=v}c+=x-b,f+=M-g,l.push({ei:u,minX:b,minY:g,maxX:x,maxY:M})}}this.cellSize=to(l,c,f);for(let u of l)no(this.cells,this.cellSize,u.minX,u.minY,u.maxX,u.maxY,u.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,o=n){return oo(this.cells,this.cellSize,e,t,n,o)}};function ao(e,t,n,o,r,s){let i=r-n,a=s-o,l=i*i+a*a;if(l===0)return Math.hypot(e-n,t-o);let c=Math.max(0,Math.min(1,((e-n)*i+(t-o)*a)/l));return Math.hypot(e-(n+c*i),t-(o+c*a))}function Cs(e,t,n){let o=1/0,r=20,s=n.x0,i=n.y0;for(let a=1;a<=r;a++){let l=a/r,c=1-l,f=c*c*c*n.x0+3*c*c*l*n.cx0+3*c*l*l*n.cx1+l*l*l*n.x1,u=c*c*c*n.y0+3*c*c*l*n.cy0+3*c*l*l*n.cy1+l*l*l*n.y1;o=Math.min(o,ao(e,t,s,i,f,u)),s=f,i=u}return o}function io(e,t,n,o=1){let r=1/0;for(let s of n){let i=Cs(e,t,o===1?s:{x0:s.x0,y0:s.y0*o,cx0:s.cx0,cy0:s.cy0*o,cx1:s.cx1,cy1:s.cy1*o,x1:s.x1,y1:s.y1*o});i<r&&(r=i)}return r}var Is=ze();function co(e,t){return Is(e,[t],()=>new ro(e))}var Ls=ze();function Bs(e,t,n,o,r,s,i,a=!1){return Ls(e,[t,n,o.scaleX,o.scaleY,r,s,i,a],()=>new so(e,t,n,o,s,r,i,a))}var Xs=5;function Kf(e,t,n,o,r=0,s){let i=Ke(o),a=co(e,r),l=p=>Math.max(Xs,p)/o.scaleX,c=l(s?.maxHalfWidthPx??0),f=a.query(t,n,c,c/i),u=null,d=1/0;for(let{nodeId:p,segmentIdx:h}of f){let m=e[p],b=ao(t,n*i,m[h].x,m[h].y*i,m[h+1].x,m[h+1].y*i);b<d&&b<l(s?.halfWidthPx(p)??0)&&(d=b,u=p)}return u}function Ds(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,i=1;for(let[a,l]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(a===0){if(l<0)return!1}else a<0?s=Math.max(s,l/a):i=Math.min(i,l/a);return s<=i}function lo(e,t,n=0){let o=co(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let i=new Set,a=o.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:l,segmentIdx:c}of a){let f=e[l];!i.has(l)&&Ds(r(f[c]),r(f[c+1]),s)&&i.add(l)}return i}}function zf(e,t,n,o,r,s,i=0,a,l,c,f=!1){let u=Ke(r),d=10/r.scaleX,p=Bs(e,t,s,r,i,a,c,f),h=p.query(n,o,d,d/u),m=null,b=d;for(let g of h){let x=t.edges[g],M=e[x.from],y=e[x.to];if(!M?.length||!y?.length||l?.has(g))continue;let w=x.pathIds?.length??0,v=p.getCurves(g);if(!v)continue;let S;if(!s||w===0)S=io(n,o*u,v,u);else{let k=1/0;for(let T of Re(M,y,w,r)){let G=T.x===0&&T.y===0?v:dn(v,T.x,T.y),Y=io(n,o*u,G,u);Y<k&&(k=Y)}S=k}S<b&&(b=S,m=g)}return m}var fo=3.4,ut=6,Fs=18,qs=2,Gs=3,Ys=un+pn;function uo(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=999500?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],r=s=>+(s/n).toFixed(n===1?0:1);return`${r(e.covered*t)} of ${r(t)} ${o}`}function po(e,t,n,o){let r=n/2;return ho(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:i,y:a}=t(s.at),l=uo(s);return{item:s,x:i,y:a+n+Fs,text:l?`${s.gene.name} \xB7 ${l}`:s.gene.name,fallback:l?`${s.gene.name} \u2026`:void 0,stack:qs,fits:c=>[...o({x0:c.x0-r,x1:c.x1+r,y0:c.y0-r,y1:c.y1+r})].every(f=>s.nodeIds.has(f))}})}function ho(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Ws(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:i}=e.axisScale,a={width:t,height:n},l=w=>({x:w.x*s+o,y:w.y*i+r}),c=e.drawnRowLabels.map(({label:w,y:v})=>Je(w,v*i+r)),f=e.referenceStripZonePx??0;f>0&&c.push({x0:0,x1:t,y0:0,y1:f}),e.legendSize.width>0&&c.push({x0:t-ut-e.legendSize.width,x1:t,y0:0,y1:f+ut+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*de*1.2,y0:0,y1:44});let u=hn(a,c),d=e.drawnRowLabels.length>0,p=d?Math.min(...e.drawnRowLabels.map(w=>w.y)):1/0,h=e.contigThickness*fo,m=(w,v)=>{let{x:S,y:k}=l({x:w.labelAt.x,y:Math.min(w.labelAt.y,p)}),T=k-h/2-v;return{x:S,y:d?Math.max(T,Ys):T}},b=ho(e.bubbleHalos.filter(w=>!w.tick),w=>w.whole?-1:w.members),g=Ze(b.map(w=>({item:w,...m(w,6),text:w.label,fallback:w.label.includes(",")?w.label.split(",")[0]:void 0,stack:Gs})),a,u),x=e.bubbleHalos.filter(w=>w.tick).map(w=>({item:w,...m(w,2)})).filter(w=>w.x>=0&&w.x<=t&&w.y>=0&&w.y<=n),M=Ze(po(e.genePins,l,e.contigThickness,lo(e.nodePositions??{},{scaleX:s,scaleY:i,translateX:o,translateY:r},e.positionsVersion)),a,u),y=e.nodePositions&&e.labelsNodeSizes?Qe({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:o,translateY:r,width:t,height:n,version:e.positionsVersion,take:u}):[];return{bubbles:g,ticks:x,genes:M,sizes:y}}var Z=JBrowseExports.mobx,ie=e=>Z!=null&&e in Object(Z)?Z[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from 'mobx' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var wu=ie("autorun");var Mu=ie("computed");var mo=ie("observable");var vu=ie("reaction");var go=ie("runInAction");var Eu=ie("untracked");var Su=Z&&Z.__esModule?Z.default:Z;function pt(e,t){return t===ne(e.id)?e.id:`-${e.id}`}function Hs(e,t){let n=e.map(()=>{}),o=0,r=0;for(;r<e.length&&e[r]!==void 0;r++)n[r]=o,o+=e[r];let s=t;for(let i=e.length-1;i>r&&e[i]!==void 0;i--)s-=e[i],n[i]=s;return n}function Us(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=Hs(t,e.pathLength),r=o.flatMap((d,p)=>d===void 0?[]:[p]),s=d=>o[r[d]],i=d=>s(d)+t[r[d]],a=0,l=d=>{for(;a<r.length&&i(a)<d;)a++;for(let p=a;p<r.length&&s(p)<=d;p++){let h=i(p);if(d<h)return{s:r[p],local:d-s(p),room:h-d}}},c=d=>{for(let p=a;p<r.length;p++)if(s(p)>d)return s(p)-d;return 1/0},f=(d,p)=>{let h=n[d],m=h.at(-1);p.type==="substitution"&&m?.type==="substitution"&&m.pos+m.seq.length===p.pos?m.seq+=p.seq:h.push(p)},u=e.pathStart;for(let d of sn(e.cs))if(d.op==="match")u+=d.length;else if(d.op==="substitution"){let p=l(u);p&&f(p.s,{type:"substitution",pos:p.local,seq:d.seq}),u+=1}else if(d.op==="insertion"){let p=u>e.pathStart&&u<e.pathEnd?l(u):void 0;p&&f(p.s,{type:"insertion",pos:p.local,seq:d.seq})}else{let p=d.length;for(;p>0;){let h=l(u),m=Math.min(p,h?h.room:c(u));h&&f(h.s,{type:"deletion",pos:h.local,length:m}),u+=m,p-=m}}return n}function bo(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let i=s.path.map(f=>o.get(f.name)),a=i.flatMap((f,u)=>f?[u]:[]),l=a[0],c=a.at(-1);if(l!==void 0&&c!==void 0){let f=Us(s,i.map(p=>p?.length)),u=a.map(p=>pt(i[p],s.path[p].strand)),d=i[c].length;r.push({id:n+r.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:a.map((p,h)=>({nodeName:u[h],mismatches:f[p]})),firstNodeOffset:l===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?void 0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return r}var js=["#6baed6","#4292c6","#2171b5","#08519c"],Vs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function xo(e){let t=e.is_reverse?Vs:js;return t[e.id%t.length]}function _(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function yo(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function Ks(e){return yo(e).replaceAll('"',"&quot;")}function zs(e){if(typeof e=="string")return yo(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${Ks(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(zs).join("")}</${e.tag}>`}var xt="#2f8fd6",yt="#8e3fbf",wo="#bdbdbd",Mo="#8a8a8a",vo="#e2e2e2",Eo="#d9a441",he="#1c1c22",wt=12,Ie=4,So=1,gt=12,Zs=6,Js=3;function F(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Qs(e){let t=Math.abs(e);return`${e>0?"+":"\u2212"}${t<1e3?`${t} bp`:F(t)}`}function ht(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}var ei=({refName:e,start:t})=>`${Jt(e)}:${t<1e6?`${Math.round(t/1e3)} kb`:`${(t/1e6).toFixed(1)} Mb`}`;function ti(e){return e<1e3?`${e}`:`${Math.round(e/1e3)} k`}function ni(e,t,n=0){if(e<=0)return"";let o=(t??[]).filter(l=>l.gap);if(!o.some(l=>l.cause))return` \xB7 ${F(e)} ${te}`;let r=l=>o.filter(c=>c.cause===l).reduce((c,f)=>c+f.bp,0),s=[...new Set(o.flatMap(l=>l.chunk?[ei(l.chunk)]:[]))],i=[[r("missing"),D.missing],[r("elsewhere"),`on nodes filed near ${s[0]}${s.length>1?` and ${s.length-1} more place${s.length>2?"s":""}`:""}`],[r("unknown"),D.unknown],[r(void 0),te]],a=r("abridged");return(a>0?` \xB7 ${ti(n)} steps, ${F(a)} not loaded`:"")+i.filter(([l])=>l>0).map(([l,c])=>` \xB7 ${F(l)} ${c}`).join("")}function ko(e,t,n,o){let{bp:r,gapBp:s,complete:i,stop:a}=e;if(!t)return`${F(r)}${ht(r,n)}`;let l=ni(s,e.runs,e.abridgedSteps),c=o?` \xB7 called ${F(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(i){let d=r-t.bp,p=d===0?"":` (${Qs(d)})`;return`${F(r)}${ht(r,n)}${p}${l}${c}`}let f=n?"repeat":"window";if(a?.contigEnds&&r===0)return`contig ends ${a.shortBp>0?`${F(a.shortBp)} before`:"at"} the ${f}${c}`;let u=a?a.contigEnds?`contig ends inside the ${f}`:"does not rejoin the reference within the extracted subgraph":"partial walk";return`\u2265 ${F(r)}${ht(r,n)} \xB7 ${u}${l}${c}`}function Ro(e,t,n){let o=t+6;return o+e.length*de<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function To(e,t,n){if(t*n<Js)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function me(e){return e==="missing"?{fill:Mo,px:So,label:D.missing}:e==="unknown"?{fill:vo,px:Ie,label:D.unknown}:e==="abridged"?{fill:Eo,px:Ie,label:D.abridged}:{fill:wo,px:Ie,label:te}}function _o(e,t){if(e.gap)return{fill:me(e.cause).fill};if(!t)return{fill:e.onReference?xt:yt};if(e.referenceStart===void 0)return{fill:Oe};let n=Mn({...e,start:e.referenceStart},t);return n.length===1?{fill:tt(n[0])}:{stops:n.map(tt)}}function bt(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function oi(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function ri(e,t){let n=new Map;for(let o of e){let r=t.get(o.name);if(!o.axis||!r)continue;let s=o.axis,i=({start:a,end:l})=>({start:Math.max(0,a),end:Math.min(o.bp,l)});n.set(o.name,r.map(a=>({name:a.name,...i(bt(s,a.start,a.end)),exons:a.exons.map(l=>i(bt(s,l.start,l.end))).filter(l=>l.end>l.start)})).filter(a=>a.end>a.start).sort((a,l)=>a.start-l.start))}return n}var si=9,ii=5.2,ai=8,Oo=(e,t)=>Math.min(2,(e-t)/2-1);function Ao(e,t){return Oo(e,t)>=1}function No(e,t,n,{rowPx:o=ke,barPx:r=wt}={}){if(!Ao(o,r))return[];let s=Oo(o,r),i=e.map(c=>{let f=t(c.start);return{g:c,x:f,w:Math.max(2,t(c.end)-f)}}),a=[],l=new Set((r>=ai?[...i]:[]).sort((c,f)=>c.w-f.w).filter(({g:c,x:f,w:u})=>{let d=c.name.length*ii/2,p=[f+u/2-d,f+u/2+d];return 2*d>u+6||a.some(([h,m])=>p[0]<m+2&&p[1]>h-2)?!1:(a.push(p),!0)}));return i.map(c=>({name:c.g.name,x:c.x,y:n-r/2-s,w:c.w,h:r+2*s,exons:c.g.exons.map(f=>({x:t(f.start),w:Math.max(1,t(f.end)-t(f.start))})),label:l.has(c)?{x:c.x+c.w/2,y:n+3,size:si}:void 0}))}var mt=e=>`${e} row${e===1?"":"s"}`;function ci(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??En,ramp:!0}:{kind:"bar",fill:xt},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Oe:yt},label:`off ${e.reference.label}'s path`}],o=[e.reference,...e.rows].flatMap(s=>s.runs.filter(i=>i.gap)),r=new Set(o.map(s=>me(s.cause).label));for(let s of[void 0,"missing","unknown","abridged"]){let{fill:i,px:a,label:l}=me(s);r.has(l)&&n.push({swatch:{kind:"gap",fill:i,px:a},label:l})}return t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):t.genes&&(n.push({swatch:{kind:"gene"},label:"gene"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${mt(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${mt(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${mt(t.genes.unread)}`,note:!0})),n}var Po="#111",$o="#9e9e9e",Mt="#c62828";function Co(e){return e.agrees===!1?Mt:e.spanningReads===0?$o:Po}function li(e,t,n,o="walk-key"){let r=0,s=e.flatMap((i,a)=>{let l=`${o}-ramp-${a}`,c=!i.note&&i.swatch.kind==="bar"&&i.swatch.ramp?_("linearGradient",{id:l},...vn.map(d=>_("stop",{offset:d.offset,"stop-color":d.color}))):void 0,f=i.note?void 0:i.swatch.kind==="gene"?_("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:he,"stroke-width":1.5}):_("rect",{x:r,y:i.swatch.kind==="gap"?9-i.swatch.px/2:5,width:18,height:i.swatch.kind==="gap"?i.swatch.px:8,rx:2,fill:c?`url(#${l})`:i.swatch.fill}),u=_("text",{x:i.note?r:r+23,y:13,"font-style":i.note?"italic":void 0,fill:i.note?"#666":void 0},i.label);return r+=(i.note?0:23)+i.label.length*de+16,[c,f,u].filter(d=>d!==void 0)});return{width:r,tree:_("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function di(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(ke,o>=1?Math.floor(o):o));return{rowPx:r,barPx:r<=3?r:Math.max(3,Math.round(r*.6)),labelled:r>=gt,readouts:r>=gt}}function Io(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let a=0,l=0;for(let u of r)u.onReference?a+=u.bp:l+=u.bp;let c=a>=l,f=r.find(u=>u.onReference===c);o.push({start:r[0].start,bp:a+l,onReference:c,referenceStart:c?f.referenceStart:void 0,...f.reversed?{reversed:!0}:{}})}r=[]}},i=0;for(let a of e){if(a.gap||a.bp>=n){s(),i=0,o.push(a);continue}r.push(a),i+=a.bp,i>=n&&(s(),i=0)}return s(),o}function fi(e,t,n){return _("g",{class:"row-gene","data-testid":"graph-walk-gene"},_("title",{},e.name),...e.exons.map(o=>_("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:he,opacity:.35})),_("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:he,"stroke-width":1.5}),e.label&&_("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:he,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function ge(e,t,n={}){let o=m=>m*t.scaleX+t.translateX,r=t.rowPx??ke,s=t.barPx??wt,i=Math.min(3,Math.max(0,(r-s)/2)),a=m=>m*r*t.scaleY+t.translateY,{origin:l,unit:c,reference:f,rows:u}=e,d=m=>o(l+m),p=n.idPrefix??"walkrow",h=(m,b)=>{let g=a(b);if(g<-s||g>t.height+s)return;let x=t.bars===!1?[]:m.runs,M=Io(x,t.scaleX).flatMap(k=>{let T=_o(k,n.ramp),G=k.gap?Math.min(me(k.cause).px,s):s,Y=`${p}-${b}-${k.start}`,ye=_("rect",{x:d(k.start),y:g-G/2,width:Math.max(1,k.bp*t.scaleX),height:G,fill:"stops"in T?`url(#${Y})`:T.fill});return"stops"in T?[_("linearGradient",{id:Y},...T.stops.map((we,Me)=>_("stop",{offset:Me/(T.stops.length-1),"stop-color":we}))),ye]:[ye]}),y=c&&s>=Zs?To(m.bp,c,t.scaleX).map(k=>_("line",{x1:d(k),x2:d(k),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:w}=m,v=t.readouts??!0?{text:ko(m,b===0?void 0:f,c,w)}:void 0,S=v&&Ro(v.text,d(m.bp),t.width);return _("g",{"data-testid":b===0?"graph-walk-reference":"graph-walk-row"},...M,...y,...No(n.rowGenes?.get(m.name)??[],d,g,{rowPx:r,barPx:s}).map(k=>fi(k,g,s)),w&&_("rect",{"data-testid":"graph-walk-call",x:d(w.bp)-1,y:g-s/2-i,width:2,height:s+2*i,fill:Co(w)}),v&&S&&_("text",{x:S.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:w?.agrees===!1?Mt:"#333",stroke:S.halo?"white":void 0,"stroke-width":S.halo?3:void 0,"paint-order":"stroke","text-anchor":S.anchor},v.text))};return _("g",{},...[f,...u].map(h))}var ui=10;function pi(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=ui*(r.end-r.start)&&(n===0?r.start<=e.start&&e.start<=r.end:Math.min(e.end,r.end)-Math.max(e.start,r.start)>=n/2))}var hi=40;function mi(e,t){let n=A(e),o=A(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function vt(e){return e>=_n?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function gi(e,t=[]){let n=bi(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function bi(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:i,inversion:a}=e,l=mi(o,r);if(i>=hi)return{kind:"superbubble",label:`${l} superbubble, ${i} segments, ${vt(s)}${a?", inv":""}`};if(a)return{kind:"inversion",label:`${A(r)} inv`};if(e.offReference)return o===r?Lo(o):{kind:"complex",label:`${l}, ${vt(s)}`};let c=r!==o?pi(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${l} repeat array${u}, ${vt(s)}`}}let f=s>2?`, ${s} alleles`:"";return o===r&&o===n?Lo(n):n===0||o===n?{kind:"insertion",label:`\u2264${A(r-n)} ins${f}`}:r===n?{kind:"deletion",label:`${A(n-o)} del${f}`}:{kind:"complex",label:`${A(n)} ref \u2192 ${l}, ${s} alleles`}}function Lo(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${A(e)} sub`}}var xi={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},yi={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function wi(e){return e.segments.split(",").filter(Boolean)}function Et({graph:e,layout:t}){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach((r,s)=>{let i=n.get(r.name);if(r.order>=0&&i&&O(i)){let{refName:a,start:l}=i.stable;ee(o,a,{name:r.name,index:s,bp0:l,bp1:l+i.length,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,i)=>s.bp0-i.bp0);return o}function Le(e,t,n=!1){let o=V(e.length-1,r=>n?e[r].bp1<t:e[r].bp1<=t);return be(e[o],t)}function be(e,t){let n=e.bp1-e.bp0;return t<=e.bp0||n<=0?e.x0:e.x0+(Math.min(t,e.bp1)-e.bp0)/n*(e.x1-e.x0)}function Be(e,t,n){let o=Le(e,t),r=Le(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function Mi(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Bo=5,vi=10,Ei=110,Si=3;function Xo(e){return e?"#b0b0b8":"#55555c"}function ki(e){let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<=1?1:n<=2?2:n<=5?5:10)*t}function Do(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+vi)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function Ri(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let i=t(r.x0),a=t(s.x1),l=s.bp1-r.bp0;if(a<=i||l<=0)return;let c=ki(l/(a-i)*Ei),f=[],u=[];for(let d=Math.ceil(r.bp0/c)*c;d<=s.bp1;d+=c){let p=Math.round(t(Le(e,d)))+.5;if(p>=0&&p<=n){f.push(p);let h=d.toLocaleString("en-US");u.push({text:h,at:p,width:o(h)})}}return{spans:[{x0:i,x1:a}],ticks:f,labels:Do(u)}}function Ti(e,t,n,o){let r=e.map(h=>({box:h,s0:t(h.x0),s1:t(h.x1)})).filter(({s0:h,s1:m})=>m>=0&&h<=n),s=r[0],i=r.at(-1);if(!s||!i)return;let a=(h,m)=>({text:h,at:m,width:o(h)}),l=(h,m)=>a(h.toLocaleString("en-US"),m),c=[],f=[],u=[],d=[];for(let{box:h,s0:m,s1:b}of r){c.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Si&&f.push(Math.round(b)+.5);let g=a(A(h.bp1-h.bp0),(m+b)/2);g.width<=b-m&&u.push(g),h!==s.box&&d.push(l(h.bp0,m))}let p=[l(s.box.bp0,s.s0),l(i.box.bp1,i.s1)];return{spans:c,ticks:f,labels:Do([...p,...u,...d])}}function Fo(e,t,n,o,r=!1){return(r?Ri:Ti)(e,t,n,o)}function _i(e,t,n,o,r=!1){let{x:s,width:i,darkMode:a}=n;e.font="10px sans-serif";let l=Fo(t,s,i,u=>e.measureText(u).width,r);if(!l)return;let c=Xo(a),f=o+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:d}of l.spans)e.moveTo(Math.max(0,u),f),e.lineTo(Math.min(i,d),f);for(let u of l.ticks)e.moveTo(u,o),e.lineTo(u,o+Bo);e.stroke();for(let{text:u,at:d}of l.labels)e.fillText(u,d,o+Bo+2)}function Oi(e,t,n,o){let r=[];for(let s of e){let i=n(s.x0),a=n(s.x1);a>=0&&i<=o&&r.push({node:s.name,top0:t(s.bp0),top1:t(s.bp1),bottom0:i,bottom1:a})}return r}var Ai=3;function Ni(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,i=Ai;for(let a of e){let l=a.top0+(a.bottom0-a.top0)*r,c=a.top1+(a.bottom1-a.top1)*r,f=Math.max(0,Math.min(l,c)-n,n-Math.max(l,c));f<i&&(i=f,s=a.node)}return s}function qo(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.top1,0),e.lineTo(t.bottom1,n),e.lineTo(t.bottom0,n),e.closePath()}function Go(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function Pi(e,t,n,{highlightNode:o,darkMode:r}){if(n<=0||t.length===0)return;let s=r?"255,255,255":"0,0,0";e.beginPath();for(let i of t)qo(e,i,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let i of t)Go(e,i,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke(),Yo(e,t,n,o)}function Yo(e,t,n,o){let r=n>0&&o?t.find(s=>s.node===o):void 0;r&&(e.beginPath(),qo(e,r,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),Go(e,r,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Wo(e,t){let n=new Map;for(let o of e){let r=t(o),s=n.get(r);s===void 0?n.set(r,[o]):s.push(o)}return n}var $i=new Set(["_gbwt_ref","unknown"]);function Ho(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||$i.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var Ci=["read_group","sample_name"],Up=[...Ci,"haplotype_sample"],Xe=8.401;function Ii({layers:e,coarsenedReadView:t=!1,showReads:n=!0},o){if(e!==void 0)return e;let r=t&&n,s=i=>i?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(r&&!o)},{data:"reads",...s(r&&o)}]}function Uo(e,t){return e.find(n=>n.data===t)?.stat}function Li(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:Ii(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??Xe,trackWidth:e.trackWidth??15,freqWidth:e.freqWidth??"log"}}function Bi(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}function sr(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:Bi(),trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function ir(e,t,n=[],o={}){let r=Xi(e,t,n,o);return r&&Di(r,o)}var ar=new WeakMap;function Xi(e,t,n=[],o={}){let r=qi(e,t,n,o);if(r===void 0)return;let s=cr(r,r.tracks,r.reads,"measure");return s.nodes.forEach((i,a)=>{i.order>=0&&(r.nodes[a].x=i.x)}),ar.set(r,s),r}function Di(e,t={}){return Fi(e,Hi(e,t.facet),Gi(e,t))}function Fi(e,t,n,o){let r=ar.get(e);return r!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?r:cr(e,t,n,"topology",o)}function qi(e,t,n,o){let r=sr(Li(o,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,i)=>{s.seq??="",s.sequenceLength??=s.seq.length,r.nodes[i+1]=s}),r.tracks=structuredClone(t),r.reads=r.config.showReads?structuredClone(n.filter(s=>s.is_secondary!==!0)):[];for(let s=r.tracks.length-1;s>=0;s-=1){let i=r.tracks[s];if(i.type??="haplotype",i.hidden===!0){r.tracks.splice(s,1);continue}i.indexOfFirstBase!==void 0&&(r.trackForRuler=i.name)}if(r.tracks.length!==0)return ji(r,0),r.nodeMap=zo(r),ae(r,r.tracks),ae(r,r.reads),or(r),r.config.mergeNodes&&(Zo(r),kt(r),Tt(r),La(r),r.nodeMap=zo(r),or(r),ae(r,r.tracks),ae(r,r.reads)),Zo(r),ha(r),kt(r),ma(r),kt(r),Tt(r),ae(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:ua(r),trackForRuler:r.trackForRuler}}}function Gi(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:o}){let r=n?new Set(n):null;return e.reads.filter(s=>(s.mapping_quality??0)>=t&&(r===null||s.name!==void 0&&r.has(s.name))&&(o===void 0||Yi(o,s)))}function Yi(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Wi(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Hi(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Wi(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Ui(o)===t.key)}function Ui(e){return Ho(e.name)?.sample??null}function cr(e,t,n,o,r={}){let s=sr(e.options);e.nodes.forEach((d,p)=>{s.nodes[p]={...d}}),s.tracks=t.map(d=>({...d})),s.reads=n.map(d=>({...d})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:i,ignoreStrand:a}=s.config,l=r.haplotypes??Oa,c=Uo(i,"haplotypes")==="coarsen"?Aa(s,l):void 0;c!==void 0&&(s.tracks=[c.ref]),Ta(s),wa(s),Vi(s);let f=Uo(i,"reads")==="coarsen"&&s.reads.length>0?pr(s,s.reads,"read",r.reads??l+(c?.bands.length??0)):void 0;f!==void 0&&(s.reads=f.bands);let u={};for(let[d,p,h]of[["haplotypes","haplotype",c],["reads","read",f]])h!==void 0&&(Tt(s,h.bands),ae(s,h.bands),u[d]={unit:p,total:h.total,reverse:!a&&h.bands.some(m=>m.is_reverse)});return c!==void 0&&(s.reads=c.bands.concat(s.reads)),zi(s),s.tracks=s.tracks.concat(s.reads),o==="measure"&&ba(s),_a(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:ia(s),maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:u}}function P(e){return e.startsWith("-")}function $(e){return P(e)?e.substring(1):e}function lr(e){return P(e)?e:`-${e}`}function _t(e){return P(e)?$(e):lr(e)}function jo(e){return e>0}function ji(e,t){let n=new Set,o=new Set;for(let r of e.tracks[t].sequence)P(r)?o.has($(r))||n.add($(r)):o.add(r);if(n.size!==0){for(let{sequence:r}of[...e.tracks,...e.reads])for(let s=0;s<r.length;s+=1)n.has($(r[s]))&&(r[s]=_t(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Nt(r.seq))})}}function Vi(e){e.nodesPerOrder=Array.from({length:e.maxOrder+1},()=>[]);let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&Vo(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(o=>{Vo(t,o.order,(o.y??0)+n.width)})}),e.nodes.forEach((n,o)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(o))})}function Vo(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var Ot=7;function Ki(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{(t.width===void 0||t.width===0)&&(t.width=Ot),t.path.forEach((o,r)=>{if(o.node===null)return;let s=e.nodes[o.node];t.path.length===1?s.internalReads.push(n):r===0?s.outgoingReads.push([n,r]):s.incomingReads.push([n,r])})})}function zi(e){e.reads.forEach(a=>{a.path=dr(e,a)}),Ki(e);let t=e.nodes.filter(a=>a.order>=0);t.sort($t);let n=new Map;for(let a=0;a<e.reads.length;a++){let l=e.reads[a],c=l.haplotypeShare===void 0?1:0,f=l.sourceTrackID,u=`${c}:${f}`,d=n.get(u);d===void 0?n.set(u,{layer:c,source:f,reads:new Set([a])}):d.reads.add(a)}let o=[...n.values()].sort((a,l)=>a.layer-l.layer||a.source-l.source),r=o.length>1?Ot:0;t.forEach(a=>{for(let{reads:l}of o)Zi(e,l,a,r)});let s=oa(e),i=[];e.reads.forEach((a,l)=>{let c=[],f=[],u;a.path.forEach((d,p)=>{c[p]=u,d.node!==null&&(u=d)}),u=void 0;for(let d=a.path.length-1;d>=0;d-=1)f[d]=u,a.path[d].node!==null&&(u=a.path[d]);a.path.forEach((d,p)=>{if(d.y===void 0){let h=c[p],m=f[p],b=!!(m&&h&&(h.order>m.order||m.order===h.order&&m.isForward===h.isForward));d.betweenCycleReverseTraversal=b,i.push({readIndex:l,pathIndex:p,previousY:h?.y,previousNode:h?.node})}})}),i.sort((a,l)=>Qi(e,a,l)),i.forEach(a=>{let l=e.reads[a.readIndex],c=l.path[a.pathIndex];c.y=s[c.order],s[c.order]+=l.width})}function Zi(e,t,n,o){let r=n.incomingReads.filter(([h])=>t.has(h)),s=n.outgoingReads.filter(([h])=>t.has(h)),i=n.internalReads.filter(h=>t.has(h));r.length===0&&s.length===0&&i.length===0&&(o=0);let a=n.y+n.contentHeight+o*2,l=r.map(h=>{let[m,b]=h,g=e.reads[m].path,x=b+1,M;for(let y=1;y<=b;y++){let w=g[b-y]?.y;if(w!==void 0){x=y,M=w;break}}return{entry:h,decisionStep:x,y:M}});l.sort(Ji),r=l.map(h=>h.entry);let c=a,f=new Map;r.forEach(h=>{let m=e.reads[h[0]];m.path[h[1]].y=c,Ko(f,m,h[1],c,n),c+=m.width});let u=c;s.sort((h,m)=>ea(e,h,m));let d=new Map;c=a,s.forEach(h=>{let m=e.reads[h[0]],b=m.firstNodeOffset??0;m.path[h[1]].y=c,d.set(c,b);let g=f.get(c);g===void 0||g+1<=b?(c+=m.width,u=Math.max(u,c)):(f.set(c,0),r.forEach(x=>{let M=e.reads[x[0]],y=M.path[x[1]];y.y!==void 0&&y.y>=c&&(y.y+=m.width,Ko(f,M,x[1],y.y,n))}),c+=m.width,u+=m.width)}),i.sort((h,m)=>na(e,h,m)),i.forEach(h=>{let m=e.reads[h],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(c=a;b<(f.get(c)??-1/0)+2||g>(d.get(c)??1/0)-3;)c+=m.width;m.path[0].y=c,f.set(c,g),u=Math.max(u,c)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,ka(e,n,p)}function Ji(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function Ko(e,t,n,o,r){e.set(o,n===t.path.length-1?t.finalNodeCoverLength??0:r.sequenceLength)}function Qi(e,t,n){let o=e.reads[t.readIndex],r=e.reads[n.readIndex],s=o.path[t.pathIndex],i=r.path[n.pathIndex];if(s.order!==i.order)return s.order-i.order;if(o.sourceTrackID!==r.sourceTrackID)return o.sourceTrackID-r.sourceTrackID;if(t.previousNode&&n.previousNode){let u=e.nodes[t.previousNode],d=e.nodes[n.previousNode];if(u&&d&&u.order!==d.order)return u.order-d.order}let a=t.previousY??0,l=n.previousY??0,c=s.betweenCycleReverseTraversal===!0,f=i.betweenCycleReverseTraversal===!0;return c!==f?c?1:-1:c?l-a:a-l}function ea(e,[t,n],[o,r]){let s=e.reads[t],i=e.reads[o],a=s.path.findLast(p=>p.y!==void 0)?.y,l=i.path.findLast(p=>p.y!==void 0)?.y;if(a!==void 0&&l!==void 0)return a-l;let c=(p,h)=>{let m=p.path[h]?.node;return m==null?null:e.nodes[m]??null},f=(p,h)=>{let m=h+1;for(;p.path[m]?.node===null;)m+=1;return m},u=c(s,n),d=c(i,r);for(;u!==null&&u===d;)n=f(s,n),r=f(i,r),u=c(s,n),d=c(i,r);return u!==null&&d!==null?$t(u,d):u!==null||d!==null?u===null?-1:1:(s.firstNodeOffset??0)-(i.firstNodeOffset??0)||(s.finalNodeCoverLength??0)-(i.finalNodeCoverLength??0)}function ta(e,t){let n=e.path,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let i=n[r],a=o[s],l=i.order,c=a.order;if(l===c&&i.node&&a.node)return(a.y??0)-(i.y??0);l<c?r+=1:(l>c||(r+=1),s+=1)}return 0}function na(e,t,n){let o=e.reads[t],r=e.reads[n];return(o.firstNodeOffset??0)-(r.firstNodeOffset??0)||(o.finalNodeCoverLength??0)-(r.finalNodeCoverLength??0)}function oa(e){let t=new Array(e.maxOrder+1).fill(0);return e.nodes.forEach(n=>{n.y!==void 0&&(t[n.order]=Math.max(t[n.order],n.y+n.contentHeight+20))}),e.tracks.forEach(n=>{n.path.forEach(o=>{t[o.order]=Math.max(t[o.order],(o.y??0)+n.width)})}),t}function dr(e,t){let n=[],o=(l,c)=>{n.push({order:l,isForward:c,node:null})},r=(l,c,f)=>{n.push({order:l,isForward:c,node:f})},s=Math.abs(t.indexSequence[0]),i=jo(t.indexSequence[0]),a=e.nodes[s];r(a.order,i,s);for(let l=1;l<t.sequence.length;l+=1){let c=a,f=i;s=Math.abs(t.indexSequence[l]),i=jo(t.indexSequence[l]),a=e.nodes[s];let{order:u}=a;if(u>c.order){f||o(c.order,!0);for(let d=c.order+1;d<u;d+=1)o(d,!0);i||o(u,!0)}else if(u<c.order){f&&o(c.order,!1);for(let d=c.order-1;d>u;d-=1)o(d,!1);i&&o(u,!1)}else i===f&&o(u,!i);r(u,i,s)}return n}function Tt(e,t=e.reads){t.forEach(n=>{if(!n.sequence.every(P))return;n.is_reverse=n.is_reverse!==!0,n.sequence=n.sequence.toReversed().map($),n.sequenceNew!==void 0&&(n.sequenceNew=n.sequenceNew.toReversed());for(let i of n.sequenceNew??[]){i.nodeName=$(i.nodeName);let{sequenceLength:a}=St(e,i.nodeName);i.mismatches=i.mismatches.map(l=>At(l,a))}let o=n.firstNodeOffset??0,r=St(e,n.sequence[0]).sequenceLength,s=St(e,n.sequence.at(-1)).sequenceLength;n.firstNodeOffset=r-(n.finalNodeCoverLength??0),n.finalNodeCoverLength=s-o})}function At(e,t){let n=e.type==="insertion"?0:e.type==="deletion"?e.length??0:e.seq?.length??0;return{...e,pos:t-e.pos-n,...e.seq!==void 0&&{seq:Nt(e.seq)}}}var ra={A:"T",T:"A",C:"G",G:"C"};function Nt(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=ra[e.charAt(n)]??"N";return t}function ae(e,t){let n=new Map;t.forEach(o=>{o.indexSequence=o.sequence.map(r=>{let s=n.get(r);if(s===void 0){let i=e.nodeMap.get($(r));if(i===void 0)throw new Error(`Track ${o.name??o.id} visits unknown node ${r}`);s=P(r)?-i:i,n.set(r,s)}return s})})}var sa=20;function ia(e){let t={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0},{rectangles:n,verticalRectangles:o,curves:r}=e.shapes;for(let s of[n,o,r])for(let{xStart:i,xEnd:a}of s)t.minX=Math.min(t.minX,i,a),t.maxX=Math.max(t.maxX,i,a);return e.nodes.forEach(s=>{s.x!==void 0&&(t.minX=Math.min(t.minX,s.x-9),t.maxX=Math.max(t.maxX,s.x+sa+s.pixelWidth)),s.y!==void 0&&(t.minY=Math.min(t.minY,s.y-10),t.maxY=Math.max(t.maxY,s.y+s.contentHeight+10))}),e.tracks.forEach(s=>{s.path.forEach(i=>{let a=i.y??0;t.maxY=Math.max(t.maxY,a+s.width),t.minY=Math.min(t.minY,a)})}),t}function St(e,t){let n=e.nodeMap.get($(t)),o=n===void 0?void 0:e.nodes[n];if(o===void 0)throw new Error(`Unknown node ${t}`);return o}function zo(e){let t=new Map;return e.nodes.forEach((n,o)=>{t.set(n.name,o)}),t}function Zo(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),o=r=>{for(let s=0;s<r.indexSequence.length-1;s+=1){let i=Math.abs(r.indexSequence[s]),a=Math.abs(r.indexSequence[s+1]);t[i].add(a),n[a].add(i)}};e.tracks.forEach(o),e.reads.forEach(o),e.nodes.forEach((r,s)=>{r.successors=Array.from(t[s]),r.predecessors=Array.from(n[s])})}function Jo(e,t){let n=0,o=0,r=0;t.forEach(s=>{let i=Math.abs(s);if(s<0){let a=e.nodeOrders[i]??=o;a<r&&(r=a),n=a,o=a-1}else{let a=e.nodeOrders[i]??=n;n=a+1,o=a}}),r<0&&Pt(e,-r)}function aa(e,t){let n=0,o=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let r=t[n],s,i;r>=0?(s=e.nodeOrders[r]-1,i=-1):(s=e.nodeOrders[-r]+1,i=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(t[a]);e.nodeOrders[l]===void 0&&(e.nodeOrders[l]=s,o=Math.min(o,s),s+=i)}return o<0&&Pt(e,-o),n}var ca=-1;function la(e){return Array.from(e,t=>t??ca)}function da(e){let t=[...new Set(e.filter(o=>o>=0))].sort((o,r)=>o-r),n=new Map(t.map((o,r)=>[o,r]));return e.map(o=>n.get(o)??o)}function kt(e){let t,n,o,r,s=0,i=e.tracks.concat(e.reads),a={stamp:new Int32Array(e.nodes.length),generation:0};e.nodeOrders=new Array(e.nodes.length).fill(void 0),e.nodes.forEach(l=>{l.order=void 0}),Jo(e,e.tracks[0].indexSequence);for(let l=1;l<i.length;l+=1){if(o=aa(e,i[l].indexSequence),o===null){l<e.tracks.length?Jo(e,i[l].indexSequence):(i.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=pa(i[l].indexSequence);o<t.length;){for(r=o,o+=1;o<t.length&&e.nodeOrders[t[o]]===void 0;)o+=1;if(o<t.length){n=e.nodeOrders[t[r]]+1;for(let c=r+1;c<o;c+=1)e.nodeOrders[t[c]]=n,n+=1;if(e.nodeOrders[t[o]]>e.nodeOrders[t[r]])e.nodeOrders[t[o]]<n&&Qo(e,t[o],t[o-1],n);else if(i[l].indexSequence[o]>=0&&!fa(e,t[o],t[r],a))Qo(e,t[o],t[o-1],n);else if(i[l].indexSequence[r]<0||e.nodes[t[r+1]].degree<2&&e.nodeOrders[t[o]]<e.nodeOrders[t[r]]){n=e.nodeOrders[t[r]]-1;for(let c=r+1;c<o;c+=1)e.nodeOrders[t[c]]=n,s=Math.min(s,n),n-=1}}else if(i[l].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let c=r+1;c<t.length;c+=1){let f=t[c];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let c=r+1;c<t.length;c+=1){let f=t[c];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,s=Math.min(s,n),n-=1)}}}}s<0&&Pt(e,-s),e.nodeOrders=da(la(e.nodeOrders)),e.nodes.forEach((l,c)=>{l.order=e.nodeOrders[c]})}function fa(e,t,n,o){o.generation+=1;let{stamp:r,generation:s}=o,i=[t];for(r[t]=s;i.length>0;){let a=i.pop();if(a===n)return!0;for(let l of e.nodes[a].successors)r[l]!==s&&(r[l]=s,i.push(l))}return!1}function ua(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function pa(e){return e.map(t=>Math.abs(t))}function Pt(e,t){e.nodeOrders.forEach((n,o)=>{n!==void 0&&(e.nodeOrders[o]=n+t)})}function Qo(e,t,n,o){let r=new Map,s=[[t,o]],i=0;for(;i<s.length;){let[a,l]=s[i];i+=1;let c=e.nodeOrders[a];c!==void 0&&c<l&&(r.get(a)??-1/0)<l&&(r.set(a,l),e.nodes[a].successors.forEach(f=>{e.nodeOrders[f]>c&&f!==n&&s.push([f,l+1])}),a!==t&&e.nodes[a].predecessors.forEach(f=>{e.nodeOrders[f]>c&&f!==n&&s.push([f,l+1])}))}r.forEach((a,l)=>{e.nodeOrders[l]=a})}function ha(e){e.nodes.forEach(t=>{t.tracks=[]}),e.tracks.forEach(t=>{t.indexSequence.forEach(n=>{e.nodes[Math.abs(n)].tracks.push(t.id)})}),e.nodes.forEach(t=>{t.degree=t.tracks.length})}function ma(e){ga(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function ga(e,t,n){let o=new Int32Array(e.nodes.length),r=new Uint8Array(e.nodes.length);for(let s of n.sequence){let i=P(s)?void 0:e.nodeMap.get(s);i!==void 0&&(r[i]=1)}for(let s of t){let{sequence:i,indexSequence:a}=s,l=a.length-1;for(let c=0;c<=l;c+=1){let f=Math.abs(a[c]);if(r[f]===1)continue;let u=e.nodes[f].order,d=c>0?e.nodes[Math.abs(a[c-1])].order:void 0,p=c<l?e.nodes[Math.abs(a[c+1])].order:void 0,h=P(i[c])?1:-1;(d===void 0||d<u)&&(p===void 0||u<p)&&(o[f]+=h),(d===void 0||d>u)&&(p===void 0||u>p)&&(o[f]-=h)}}for(let s of t){let{sequence:i,indexSequence:a}=s;for(let l=0;l<a.length;l+=1)o[Math.abs(a[l])]>0&&(i[l]=_t(i[l]),a[l]=-a[l])}e.nodes.forEach((s,i)=>{o[i]>0&&(s.seq=Nt(s.seq),s.switched=!0)})}function ba(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort($t);let s=ya(e);r.forEach(i=>{i.order>=0&&(i.order>o&&(o=i.order,t=n+10*s[i.order]),i.x=t,n=Math.max(n,t+40+i.pixelWidth))})}var Rt=35;function xa(e){return e<=Rt?e/17.5:Rt/17.5*Math.sqrt(e/Rt)}function ya(e){let t=e.maxOrder+1,n=new Array(t).fill(0),o=new Array(t).fill(0),r=new Array(t).fill(0),s=[];e.tracks.forEach(i=>{for(let a=1;a<i.path.length;a+=1){let l=i.path[a],c=i.path[a-1];l.order===c.order?l.isForward?n[l.order]+=1:o[l.order]+=1:r[l.order]=Math.max(xa(Math.abs((l.y??0)-(c.y??0))),r[l.order])}}),s.push(Math.max(0,n[0]-1));for(let i=1;i<=e.maxOrder;i+=1)s.push(Math.max(Math.max(0,n[i]-1)+Math.max(0,o[i-1]-1),r[i]));return s}function wa(e){e.assignments=Array.from({length:e.maxOrder+1},()=>[]);let t=new Map;e.tracks.forEach((n,o)=>{n.path=dr(e,n),n.path.forEach(({order:r,node:s},i)=>{let a={trackID:o,segmentID:i},l=s===null?void 0:t.get(s);if(l===void 0){let c={node:s,tracks:[a]};e.assignments[r].push(c),s!==null&&t.set(s,c)}else l.tracks.push(a)})});for(let n=0;n<=e.maxOrder;n+=1)Ea(e,e.assignments[n],n)}function Ma(e,t,n){t.forEach(o=>{let r=0;o.tracks.forEach(s=>{let i=va(e.tracks[s.trackID].path,s.segmentID,n-1);s.idealLane=i===void 0?s.trackID:i.lane,s.idealY=i===void 0?null:i.y,r+=s.idealLane}),o.idealLane=r/o.tracks.length})}function va(e,t,n){if(t!==0)return e[t-1].order===n?e[t-1]:e[t+1]?.order===n?e[t+1]:e.slice(0,t).findLast(o=>o.order===n)}function Ea(e,t,n){let o=0,r=new Set,s=20,i=!1,a=-1;Ma(e,t,n),t.sort(er),t.forEach(l=>{let c=l.node===null?void 0:e.nodes[l.node];c!==void 0?(i&&(s-=10),c.y=s,c.contentHeight=0,i=!1):(i?s-=25:s>20&&(s-=10),i=!0),l.tracks.sort(er),l.tracks.forEach(f=>{let{path:u,width:d}=e.tracks[f.trackID];f.trackID===a&&c===void 0&&i&&(s+=10),u[f.segmentID].lane=o,u[f.segmentID].y=s,typeof f.idealY=="number"&&r.add(f.idealY-s),o+=1,s+=d,c!==void 0&&(c.contentHeight+=d),a=f.trackID}),s+=25}),Sa(e,t,r)}function Sa(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let i=Ra(e,t,s);i<r&&(r=i,o=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=o),s.tracks.forEach(i=>{let a=e.tracks[i.trackID].path[i.segmentID];a.y=a.y+o})})}function ka(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(o=>{if(o.node!==null){let r=e.nodes[o.node];r!==t&&r.y>t.y&&(r.y+=n,o.tracks.forEach(s=>{let i=e.tracks[s.trackID].path[s.segmentID];i.y=i.y+n}))}else o.tracks.forEach(r=>{let s=e.tracks[r.trackID].path[r.segmentID];s.y>=t.y&&(s.y=s.y+n)})}),e.nodesPerOrder[t.order].forEach(o=>{let r=e.nodes[o];r!==t&&r.y>t.y&&(r.y+=n)}))}function Ra(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{let{type:i,path:a,width:l}=e.tracks[s.trackID];typeof s.idealY=="number"&&i!=="read"&&(o+=Math.abs(s.idealY-n-a[s.segmentID].y)*l)})}),o}function er(e,t){return e.idealLane===void 0||t.idealLane===void 0?+(e.idealLane===void 0)-+(t.idealLane===void 0):e.idealLane-t.idealLane}function $t(e,t){return e.order!==t.order?e.order-t.order:e.y!==void 0&&t.y!==void 0?e.y-t.y:0}function Ta(e){let n=e.config.trackWidth;if(e.config.freqWidth==="linear"){for(let o of e.tracks)o.width=o.type==="read"?4:Math.max(1,Math.round(o.freq??1))*n;return}for(let o of e.tracks)o.width=o.freq!==void 0?Math.round((Math.log(Math.max(o.freq,1))+1)*4):o.type==="read"?4:n;e.tracks.every(o=>o.width===4)&&e.tracks.forEach(o=>{o.freq!==void 0&&(o.width=n)})}function tr(e,t,n){let o=e.nodes[t.node];return ur(o,t.isForward?n:o.sequenceLength-n)}function fr(e,t){return t>e.sequenceLength?null:ur(e,t)}function ur(e,t){let[n,o]=Ia(e);if(e.sequenceLength===0)return n;let r=Math.min(Math.max(t,0),e.sequenceLength);return n+r/e.sequenceLength*(o-n)}function _a(e){e.extraLeft=new Array(e.maxOrder+1).fill(0),e.extraRight=new Array(e.maxOrder+1).fill(0);let t=[],n=[];e.nodes.forEach(r=>{r.x!==void 0&&(t[r.order]=r.x,n[r.order]=Math.max(n[r.order]??-1/0,r.x+r.pixelWidth))});let o=e.tracks[0];e.tracks.sort(ta),e.tracks.forEach(r=>{let{id:s,name:i,type:a,width:l,path:c}=r,f=(g,x,M)=>{e.shapes.rectangles.push({xStart:Math.min(g,x),yStart:M,xEnd:Math.max(g,x),yEnd:M+l-1,id:s,name:i,type:a})},u=g=>g.isForward?n[g.order]:t[g.order],d=c[0],p=d.y,h=a==="read"?tr(e,d,r.firstNodeOffset??0):d.isForward?t[d.order]-20:n[d.order]+20;for(let g=1;g<c.length;g+=1){let x=c[g-1],M=c[g];if(M.y===p)continue;let y=u(x);y!==h&&f(h,y,p);let w=M.y,v=M.order-x.order;if(v===1||v===-1){let S=v===1?t[M.order]:n[M.order];e.shapes.curves.push({xStart:v===1?y:y+1,yStart:p,xEnd:v===1?S+1:S,yEnd:w,width:l,id:s,name:i,type:a,nodeStart:x.node,nodeEnd:M.node,orderStart:x.order,orderEnd:M.order,...r===o?{reference:!0}:{}}),h=S}else Ca(e,r,x.isForward?1:-1,y,p,w,M.order),h=y;p=w}let m=c[c.length-1],b=a==="read"?tr(e,m,r.finalNodeCoverLength??0):u(m)+(m.isForward?20:-20);f(h,b,p)})}var Oa=1e9;function pr(e,t,n,o){let r=new Map,s=0,i=e.nodes.length,a=(m,b)=>(m+i)*(2*i+1)+b+i,l=e.config.ignoreStrand;for(let[m,b]of t.entries()){let g=Math.max(b.freq??1,1);s+=g;let x=b.indexSequence;if(!(x.length<2))for(let M=0;M<x.length-1;M+=1){let y=x[M],w=x[M+1],v=e.nodes[Math.abs(y)],S=e.nodes[Math.abs(w)],k=l?Math.min(a(y,w),a(-w,-y)):a(y,w),T=r.get(k);T===void 0?r.set(k,{sSigned:y,dSigned:w,sName:y<0?`-${v.name}`:v.name,dName:w<0?`-${S.name}`:S.name,count:g,crossings:g,sourceTrackID:b.sourceTrackID,lastSource:m}):(T.crossings+=g,T.lastSource!==m&&(T.count+=g,T.lastSource=m))}}let c=0;for(let m of r.values())m.crossings>c&&(c=m.crossings);let f=Ot,u=60,d=m=>c<=1?f:f+(u-f)*Math.sqrt(m/c),p=[],h=0;for(let m of r.values()){let b=o+h,g=n==="haplotype"?{count:m.count,total:s}:void 0,x=g===void 0?"":` (${$a(g)})`,M=m.crossings===m.count?"":`, ${m.crossings.toLocaleString()} crossings`,y=`${m.count.toLocaleString()} ${n}${m.count===1?"":"s"}${x}${M}: Node ${m.sName} \u2192 Node ${m.dName}`;e.coarsenedEdgeMeta.set(b,{count:m.count,label:y});let w=e.nodes[Math.abs(m.sSigned)].sequenceLength;p.push({id:b,sourceTrackID:m.sourceTrackID,type:"read",name:y,sequence:[m.sName,m.dName],indexSequence:[],path:[],width:d(m.crossings),firstNodeOffset:w,finalNodeCoverLength:0,sequenceNew:[{nodeName:m.sName,mismatches:[]},{nodeName:m.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:m.count,haplotypeShare:g}),h+=1}return{bands:p,total:s}}function Aa(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(f=>f.name===e.trackForRuler),o=n===-1?0:n,r=e.tracks[o],s=(r.freq??1)-1,i=Pa(e,r),a=e.tracks.filter((f,u)=>u!==o).map(f=>Na(i,f));if(s>0&&a.push({...r,freq:s}),a.length===0)return;let{bands:l,total:c}=pr(e,a,"haplotype",t);return l.length>0?{ref:r,bands:l,total:c}:void 0}function Na(e,t){let n=0;for(let o of t.indexSequence){let r=e[Math.abs(o)];r!==void 0&&r!==0&&(n+=r===Math.sign(o)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(_t).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function Pa(e,t){let n=new Int8Array(e.nodes.length);for(let o of t.indexSequence){let r=Math.abs(o);n[r]===0&&(n[r]=Math.sign(o))}return n}function $a({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var nr=7;function Ca(e,{width:t,id:n,name:o,type:r},s,i,a,l,c){let f=s===1?e.extraRight:e.extraLeft,u=10*f[c],d=i+s*(u+5),p=nr,h=Math.min(nr,t),m=Math.min(a,l),b=Math.max(a,l),g=s===1?i:d-1,x=s===1?d:i,M=S=>{e.shapes.verticalRectangles.push({xStart:g,yStart:S,xEnd:x,yEnd:S+t-1,id:n,name:o,type:r})};M(a),e.shapes.verticalRectangles.push({xStart:s===1?d+p:d-p-h,yStart:m+t+p-1,xEnd:s===1?d+p+h-1:d-p-1,yEnd:b-p+1,id:n,name:o,type:r}),M(l);let y=d+s*p,w=d+s*(p+h),v=`M ${d} ${b}`;v+=` Q ${y} ${b} ${y} ${b-p}`,v+=` H ${w}`,v+=` Q ${w} ${b+t} ${d} ${b+t}`,v+=" Z ",e.shapes.corners.push({path:v,id:n,name:o,type:r}),v=`M ${d} ${m}`,v+=` Q ${w} ${m} ${w} ${m+t+p}`,v+=` H ${y}`,v+=` Q ${y} ${m+t} ${d} ${m+t}`,v+=" Z ",e.shapes.corners.push({path:v,id:n,name:o,type:r}),f[c]+=1}function Ia(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function or(e){switch(e.config.nodeWidthOption){case"compressed":e.nodes.forEach(t=>{t.width=1+Math.log2(Math.max(t.sequenceLength,1)),t.pixelWidth=Math.round((t.width-1)*Xe)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*Xe),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*Xe)});break;case"normal":{let t=e.config.charWidth;e.nodes.forEach(n=>{n.width=n.sequenceLength,n.pixelWidth=Math.round(t*Math.max(n.sequenceLength-1,0))});break}default:throw new Error(`${e.config.nodeWidthOption} not implemented`)}}var J=0;function rr(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function L(e,t,n){let o=e.count[t];o===0?(e.first[t]=n,e.count[t]=1):o===1&&e.first[t]!==n&&(e.count[t]=2)}function xe(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function La(e){let t=rr(e.nodes.length),n=rr(e.nodes.length),o=new Map,r=u=>{let d=o.get(u);if(d===void 0){let p=e.nodeMap.get($(u));d=P(u)?-p:p,o.set(u,d)}return d};e.tracks.concat(e.reads).forEach(u=>{let{sequence:d}=u,p=u.type==="haplotype",h=d.length-1,m=J,b=h>=0?r(d[0]):J;for(let g=0;g<=h;g+=1){let x=g<h?r(d[g+1]):J;if(b>0)g>0?(L(t,b,m),m<0&&L(t,b,-m)):p&&L(t,b,J),g<h?(L(n,b,x),x<0&&L(n,b,-x)):p&&L(n,b,J);else{let M=-b;g>0?(L(n,M,-m),m>0&&L(n,M,m)):p&&L(n,M,J),g<h?(L(t,M,-x),x>0&&L(t,M,x)):p&&L(t,M,J)}m=b,b=x}});let i=new Uint8Array(e.nodes.length);e.nodes.forEach((u,d)=>{Ba(d,t,n)&&(i[d]=1)});let a=new Int32Array(e.nodes.length),l=new Float64Array(e.nodes.length),c=new Float64Array(e.nodes.length);e.nodes.forEach((u,d)=>{if(i[d]!==1){a[d]=d,c[d]=u.sequenceLength;for(let p=d;Xa(p,t,n);)p=xe(n,p),a[p]=d,l[p]=u.sequenceLength,u.sequenceLength+=e.nodes[p].sequenceLength,u.seq+=e.nodes[p].seq,c[p]=u.sequenceLength}}),e.reads.forEach(u=>{let{sequence:d}=u,p=u.sequenceNew??d.map(M=>({nodeName:M,mismatches:[]})),h=M=>{let y=Math.abs(r(M));return P(M)?e.nodes[a[y]].sequenceLength-c[y]:l[y]},m=d.length-1;u.firstNodeOffset=(u.firstNodeOffset??0)+h(d[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+h(d[m]);let b=[],g=[],x=[];d.forEach((M,y)=>{let w=Math.abs(r(M)),{mismatches:v}=p[y],S=h(M);if(v.forEach(k=>{k.pos+=S}),i[w]===1&&!P(M)&&y>0)g.at(-1).mismatches.push(...v);else if(i[w]===1&&P(M)&&y<m)x.push(...v);else{let k=e.nodes[a[w]].name,T=P(M)?lr(k):k;b.push(T),g.push({nodeName:T,mismatches:x.concat(v)}),x=[]}}),u.sequence=b,u.sequenceNew!==void 0&&(u.sequenceNew=g)}),e.tracks.forEach(u=>{let{sequence:d}=u,p=0;for(let h of d)i[Math.abs(r(h))]===0&&(d[p]=h,p+=1);d.length=p});let f=1;for(let u=1;u<e.nodes.length;u+=1)i[u]===0&&(e.nodes[f]=e.nodes[u],f+=1);e.nodes.length=f}function Ba(e,t,n){let o=xe(t,e);return o!==0&&xe(n,o)!==0}function Xa(e,t,n){let o=xe(n,e);return o!==0&&xe(t,o)!==0}function Da(e,t){return t.xStart-e.xStart||e.yStart-t.yStart}function Ct(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function Fa(e,t){for(let n=0;n<e.length;n+=1){let o=e[n]-t[n];if(o!==0)return o}return 0}var hr=.75,De=.8;function qa(e,t){let n=e[0],o=Math.min(Math.abs(n.xEnd-n.xStart),t);if(o===0)return e.map(()=>0);let r=e.length>5?.4/e.length:0,s=e.map(d=>{let p=Math.abs(d.yEnd-d.yStart),h=p/Math.hypot(p,o)*Math.min(d.width,De*hr*o);return Math.max(r,h/(hr*o))}),i=d=>s.reduce((p,h,m)=>p+(d(e[m])?h:0),0),a=i(d=>d.reference===!0),l=i(d=>d.reference!==!0),c=a>De?De/a:1,f=De-a*c,u=l>f?f/l:1;return s.map((d,p)=>d*(e[p].reference?c:u))}function mr(e,t,{gapWidth:n=1/0}={}){let o=Wo(e.filter(r=>r.type===t),r=>Ct(r).join(","));return o.forEach(r=>{r.sort(Da);let s=qa(r,n),i=.5-s.reduce((a,l)=>a+l,0)/2;r.forEach((a,l)=>{let c=p=>a.xStart+(a.xEnd-a.xStart)*(a.yStart<a.yEnd?1-p:p),f=c(i);i+=s[l];let u=c(i),d=`M ${a.xStart} ${a.yStart}`;d+=` C ${f} ${a.yStart} ${f} ${a.yEnd} ${a.xEnd} ${a.yEnd}`,d+=` V ${a.yEnd+a.width}`,d+=` C ${u} ${a.yEnd+a.width} ${u} ${a.yStart+a.width} ${a.xStart} ${a.yStart+a.width}`,d+=" Z",a.path=d})}),[...o.values()].sort((r,s)=>Fa(Ct(r[0]),Ct(s[0]))).flat()}function gr(e,t=16){let n=e.match(/[A-Za-z]|-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/g)??[],o=[],r=0,s=0,i=0,a=()=>Number(n[i++]);for(;i<n.length;){let l=n[i++];if(l==="M"||l==="L")r=a(),s=a(),o.push([r,s]);else if(l==="H")r=a(),o.push([r,s]);else if(l==="V")s=a(),o.push([r,s]);else if(l==="C"){let[c,f,u,d,p,h]=[a(),a(),a(),a(),a(),a()];for(let m=1;m<=t;m+=1){let b=m/t,g=1-b,x=g*g*g,M=3*g*g*b,y=3*g*b*b,w=b*b*b;o.push([x*r+M*c+y*u+w*p,x*s+M*f+y*d+w*h])}r=p,s=h}else if(l==="Q"){let[c,f,u,d]=[a(),a(),a(),a()];for(let p=1;p<=t;p+=1){let h=p/t,m=1-h;o.push([m*m*r+2*m*h*c+h*h*u,m*m*s+2*m*h*f+h*h*d])}r=u,s=d}else if(l!=="Z")throw new Error(`flattenPath: unsupported path command ${l}`)}return o}function br(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,o=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n+9} ${o} ${n+9} ${o+9}`,n+=9,o+=9,e.contentHeight>0&&(o+=e.contentHeight,t+=` L ${n} ${o}`),t+=` Q ${n} ${o+9} ${n-9} ${o+9}`,n-=9,o+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n-9} ${o} ${n-9} ${o-9}`,n-=9,o-=9,e.contentHeight>0&&(o-=e.contentHeight,t+=` L ${n} ${o}`),t}function It(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=e.pathVisits,o=n?.replay();return(e.paths??[]).map(r=>{let s=n?.pathIndex(I(r.name).name)??-1;return r.nodeIds.flatMap(i=>{let a=t.get(i);if(!a)return[];let l=n&&o?o(n.slot(a.name),s):-1;return[{node:a,strand:l>=0?n.strand(l):ne(a.id)}]})})}function Ga(e){let t=It(e),n=(e.paths??[]).flatMap((s,i)=>{let a=t[i].map(l=>pt(l.node,l.strand));return a.length>0?[{id:i,name:s.name,sequence:a,sourceTrackID:0,type:"haplotype",...s.members?{freq:s.members.length}:{}}]:[]}),o=Ee(e),r=n.findIndex(s=>I(s.name).name===o);return r>0&&n.unshift(...n.splice(r,1)),n}function Ya(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function yr(e){return(e.paths?.length??0)>0}var Wa=600,Ha=3,Ua=15;function ja(e){return Math.max(Ha,Math.min(Ua,Math.floor(Wa/Math.max(1,e))))}function Va(e){let t=new Set,n=new Set;for(let o of e?.sequence??[])P(o)?n.has($(o))||t.add($(o)):n.add(o);return t}function Ka(e,t,n){let o=Va(n[0]),r=new Map;for(let{sequence:l,is_secondary:c}of n)c||l.forEach((f,u)=>{let d=$(f),h=P(f)!==o.has(d)?l[u+1]:l[u-1];!t.nodeMap.has(d)&&h!==void 0&&r.set(d,$(h))});let s=new Map(e.nodes.map(l=>[l.id,Math.max(1,l.length)])),i=new Map([...r].map(([l,c])=>[c,l])),a=new Map;for(let l of i.keys()){let c=t.nodeMap.get(l);if(c!==void 0){let f=[l];for(let d=i.get(l);d!==void 0;d=i.get(d))f.push(d);f.reduce((d,p)=>d+(s.get(p)??0),0)===t.nodes[c].sequenceLength&&a.set(l,f)}}return{members:a,flipped:o}}var za={start:"end",end:"start"},xr={"+":"-","-":"+"};function Za(e,{members:t,flipped:n}){if(t.size===0)return e;let o=new Map(e.nodes.map(d=>[d.id,d])),r=new Map,s=new Set,i=(d,p)=>n.has(d)?za[p]:p;for(let[d,p]of t)p.forEach((h,m)=>{r.set(h,d);let b=p[m+1];b!==void 0&&s.add(`${h}:${i(h,"end")} ${b}:${i(b,"start")}`)});let a=new Set([...r].filter(([d,p])=>d!==p).map(([d])=>d)),l=e.nodes.flatMap(d=>{let p=t.get(d.id);if(!p)return a.has(d.id)?[]:[d];let h=p.map(b=>o.get(b)),m=h.flatMap(b=>b.stable?[b.stable.start]:[]);return[{...d,length:h.reduce((b,g)=>b+g.length,0),stable:d.stable&&{...d.stable,start:Math.min(...m)}}]}),c=(d,p,h)=>i(p,i(d,h))==="end"?ne(p):xr[ne(p)],f=e.edges.flatMap(d=>{let p=fn(d),h=`${d.from}:${p.from}`,m=`${d.to}:${p.to}`;if(s.has(`${h} ${m}`)||s.has(`${m} ${h}`))return[];let b=r.get(d.from),g=r.get(d.to);return[{...d,...b===void 0?{}:{from:b,fromStrand:c(d.from,b,p.from)},...g===void 0?{}:{to:g,toStrand:xr[c(d.to,g,p.to)]}}]}),u=new Set([...a].map(d=>o.get(d)?.name??d));return{...e,nodes:l,edges:f,paths:e.paths?.map(d=>({...d,nodeIds:d.nodeIds.filter(p=>!a.has(p))})),pathVisits:e.pathVisits?.filter(()=>!0,d=>!u.has(d))}}function wr(e){let t=e.paths??[],n=Ga(e),o=e.reads?bo(e,e.reads,t.length):[],r=o.length>0?wn:yn,s=t.map((f,u)=>r(u,t.length)),i=t.some(f=>f.members),a=t.reduce((f,u)=>f+(u.members?.length??1),0),l=ir(Ya(e),n,o,{nodeWidthOption:"compressed",trackWidth:ja(i?a:n.length),...i?{freqWidth:"linear"}:{}});if(!l)return;let c=Ka(e,l,[...n,...o]);return{layout:l,pathColors:s,members:c.members,graph:Za(e,c)}}function Lt(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function Mr(e,t,n,o){let r=e.y+e.contentHeight/2-t;return[{x:n,y:r},{x:o,y:r}]}function vr(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function rh(e){let t=yr(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=n.bounds.minY,s={};for(let l of Lt(n))s[l.name]=Mr(l,r,l.x,l.x+l.pixelWidth);let{minY:i,maxY:a}=vr(n,r);return{nodePositions:s,tubeMap:{layout:n,yOffset:r,...o},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:i,maxY:a}}}function Ja(e,t){let n=new Map(e.nodes.map(a=>[a.id,a])),o=zt(Lt(t),a=>a.order),r=[],s=-1/0;for(let a of[...o.keys()].sort((l,c)=>l-c)){let l=o.get(a),c=1/0,f=-1/0;for(let u of l){let d=n.get(u.name);d&&O(d)&&(c=Math.min(c,d.stable.start),f=Math.max(f,d.stable.start+d.length))}c===1/0&&(c=f=s),c<s&&(c=s,f=Math.max(s,f)),s=Math.max(s,f),r.push({order:a,x0:Math.min(...l.map(u=>u.x)),x1:Math.max(...l.map(u=>u.x+u.pixelWidth)),bp0:c,bp1:f})}let i=r.find(a=>a.bp0!==-1/0);for(let a of r)a.bp0===-1/0&&(a.bp0=a.bp1=i?.bp0??0);return r}function Qa(e){return yr(e)&&e.nodes.some(O)}function sh(e){let t=Qa(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=Ja(o.graph,n),s=new Map(r.map(l=>[l.order,l])),i=n.bounds.minY,a={};for(let l of Lt(n)){let c=s.get(l.order);a[l.name]=Mr(l,i,c.bp0,c.bp1)}return{nodePositions:a,tubeMap:{layout:n,yOffset:i,columns:r,...o},referenceAxis:!0,pixelRows:!0,extent:vr(n,i)}}function ec(e,t){let n=[],o=()=>({a:-1/0,b:1/0,detour:[],bp:0}),r=[o()];for(let{node:s,strand:i}of t){let a=r.at(-1),l=n.at(-1);if(O(s)){let c=s.stable.start,f=c+s.length,u=i!==(s.stable.strand??"+"),d=l!==void 0&&a.detour.length===0;d&&!l.inverted&&!u&&l.end===c?l.end=f:d&&l.inverted&&u&&l.start===f?l.start=c:(n.push({start:c,end:f,inverted:u}),r.push(o()))}else a.detour.push({node:s,strand:i}),a.bp+=s.length}return n.forEach((s,i)=>{r[i].b=s.start,r[i+1].a=s.end}),{path:e,runs:n,gaps:r}}function Bt(e,t){return Number.isFinite(e.a)&&Number.isFinite(e.b)&&e.b>=e.a&&Math.max(e.b-e.a,e.bp)<t}function Er(e,t,n){let o=V(e.length,r=>e[r]<=t);return o<e.length&&e[o]<n}function tc(e){let t=new Map;for(let n=1;n<e.length;n++){let o=e[n-1],r=e[n],s=o.stable.start+o.length;s!==r.stable.start&&(t.set(s,"reference-gap"),t.set(r.stable.start,"reference-gap"))}return t}function nc(e,t,n){let o=(s,i)=>{Number.isFinite(s)&&!n.has(s)&&n.set(s,i)};for(let{runs:s,gaps:i}of e){let a=s[0],l=s.at(-1);a&&l&&(o(a.start,"walk-end"),o(l.end,"walk-end"));for(let c of s)c.inverted&&c.end-c.start>=t&&(o(c.start,"inversion"),o(c.end,"inversion"));for(let c of i)c.b<c.a?(o(c.a,"backward"),o(c.b,"backward")):Bt(c,t)||(o(c.a,"variant"),o(c.b,"variant"))}let r=e.flatMap(({runs:s,gaps:i})=>[...i.filter(a=>Bt(a,t)).map(a=>[a.a,a.b]),...s.filter(a=>a.inverted&&a.end-a.start<t).map(a=>[a.start,a.end])]);for(let s=!0;s;){s=!1;let i=[...n.keys()].sort((a,l)=>a-l);for(let[a,l]of r)Er(i,a,l)&&(s||=!n.has(a)||!n.has(l),o(a,"overlap"),o(l,"overlap"))}return n}function oc(e,t){let n=[],o=[],r=()=>{let s=o[0],i=o.at(-1);if(s&&i){let a=s.stable.start,l=i.stable.start+i.length,c=`${a}-${l}`;n.push({node:{id:`${c}+`,name:c,length:l-a,depth:0,stable:{refName:s.stable.refName,start:a,rank:0,strand:"+"}},members:o})}o=[]};for(let s of e)t.has(s.stable.start)&&r(),o.push(s);return r(),n}function Xt(e,t,n){return Math.max(0,V(e.length,o=>t(e[o])<=n)-1)}function uh(e,t){let n=e.nodes.filter(O).sort((y,w)=>y.stable.start-w.stable.start),o=e.paths??[];if(n.length===0||o.length===0)return;let r=It(e),s=o.map((y,w)=>ec(y,r[w])),i=nc(s,t,tc(n)),a=[...i.keys()].sort((y,w)=>y-w),l=oc(n,i),c=y=>Xt(l,w=>w.node.stable.start,y),f=new Map,u=new Map;for(let y of l){f.set(y.node.id,y.members.map(w=>w.id));for(let w of y.members)u.set(w.id,y.node.id)}let d=new Map,p=y=>{let w=`${y.a} ${y.b} ${y.detour.map(S=>S.node.id+S.strand).join(",")}`,v=d.get(w);if(!v){let S=`r${d.size}`;v={id:`${S}+`,name:S,length:y.bp,depth:0,stable:{refName:n[0].stable.refName,start:Number.isFinite(y.a)?y.a:y.b,rank:1,strand:"+"}},d.set(w,v),f.set(v.id,y.detour.map(k=>k.node.id));for(let k of y.detour)u.has(k.node.id)||u.set(k.node.id,v.id)}return v},h=new Map,m=[],b=new tn,g=new Map,x=new Map;for(let{path:y,runs:w,gaps:v}of s){let S=[],k=[],T=!1,G=(R,B)=>{let C=S.at(-1);T&&C?.node===R&&C.strand===B||S.push({node:R,strand:B}),T=!0},Y=R=>{T=!1,R.detour.length>0&&(G(p(R),"+"),T=!1)},ye=R=>{(R.bp>0||R.b>R.a)&&k.push({start:R.a,end:R.b,bp:R.bp});let B=l[c(R.b>R.a?R.a:R.a-1)];for(let C of R.detour)u.has(C.node.id)||(u.set(C.node.id,B.node.id),f.get(B.node.id).push(C.node.id))};w.forEach((R,B)=>{let C=v[B];Bt(C,t)&&!Er(a,C.a,C.b)?ye(C):Y(C);let W=c(R.start),ce=c(R.end-1),ve=R.end-R.start<t;if(R.inverted&&!ve){T=!1;for(let j=ce;j>=W;j--)G(l[j].node,"-");T=!1}else{R.inverted&&k.push({start:R.start,end:R.end,bp:R.end-R.start,inverted:!0});for(let j=W;j<=ce;j++)G(l[j].node,"+")}}),Y(v.at(-1));let we=I(y.name).name,Me=0;S.forEach(({node:R,strand:B},C)=>{x.set(R.id,(x.get(R.id)??0)+1),b.add(R.name,we,y.sample??we,Me,B==="-"),Me+=R.length;let W=S[C+1];if(W){let ce=`${R.id}${B} ${W.node.id}${W.strand}`,ve=g.get(ce);ve?ve.pathIds.push(y.name):g.set(ce,{from:R.id,to:W.node.id,fromStrand:B,toStrand:W.strand,pathIds:[y.name]})}}),m.push({...y,nodeIds:S.map(R=>R.node.id)}),h.set(y.name,k)}let M=[...l.map(y=>y.node),...d.values()].filter(y=>x.has(y.id)).map(y=>({...y,depth:x.get(y.id)}));return{graph:{...e,nodes:M,edges:[...g.values()],paths:m,pathVisits:b.build(),reads:void 0},members:f,coarseOf:u,deviations:h,cuts:i}}function mh(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,o)=>t.indexOf(n.sample)-t.indexOf(o.sample)||n.label.localeCompare(o.label)):e}function gh(e,t,n,o={}){let r=on(e,t,o);return r&&rn(r,n)}function rc(e,t,n){let o=Xt(e,r=>r.bp0,t);return[e[o],e[o-1]].find(r=>r&&n.has(r.index)&&r.bp0<=t&&t<=r.bp1)}function sc(e,t){let n=new Map;for(let[r,s]of t)for(let i of s)ee(n,I(r).name,i);let o=new Map;for(let r of e.paths??[])if(r.members){let s=new Map;for(let i of r.members.flatMap(a=>n.get(a)??[]))s.set(`${i.start}-${i.end}`,i);o.set(r.name,[...s.values()])}else o.set(r.name,t.get(r.name)??[]);return o}function qh(e,t){let{graph:n,layout:o}=e,r=[...Et(e).values()].flat().sort((a,l)=>a.bp0-l.bp0),s=sc(n,t),i=[];for(let a of o.tracks){let l=a.name?s.get(a.name):void 0;if(l?.length){let c=new Map;for(let f of a.path)f.node!==null&&f.y!==void 0&&!c.has(f.node)&&c.set(f.node,f.y);for(let f of l){let u=rc(r,f.start,c);u&&i.push({x0:be(u,f.start),x1:be(u,f.end),y:c.get(u.index),height:a.width})}}}return i}function ic(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Gh(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=ic(s),e.beginPath();for(let i of t){let a=n(i.x0),l=Math.max(n(i.x1),a+1);if(l>=0&&a<=r){let c=o(i.y);e.rect(a,c,l-a,o(i.y+i.height)-c)}}e.fill()}}function ac(e,t){let n=[],o=e.sequenceNew??[],r=e.path.filter(s=>s.node!==null);return o.forEach((s,i)=>{let a=t.nodeMap.get($(s.nodeName)),l=a===void 0?void 0:t.nodes[a],c=r[i];if(l&&c?.y!==void 0){let f={readId:e.id,y:c.y,height:e.width},u=d=>fr(l,d);for(let d of s.mismatches){let p=c.isForward?d:At(d,l.sequenceLength),h=u(p.pos);if(h!==null){if(p.type==="insertion")n.push({...f,kind:"insertion",x:h,seq:p.seq});else if(p.type==="deletion"&&p.length!==void 0){let m=u(p.pos+p.length);m!==null&&n.push({...f,kind:"deletion",x0:h,x1:m,length:p.length})}else if(p.type==="substitution"&&p.seq!==void 0){let m=u(p.pos+p.seq.length);m!==null&&n.push({...f,kind:"substitution",x0:h,x1:m,seq:p.seq})}}}}}),n}function Sr(e){return e.reads.flatMap(t=>ac(t,e))}var Dt=24,cc=.5,lc=e=>e.bp1>e.bp0;function jh(e,t){let n=e.filter(lc);if(n.length===0){let c=e[0];return c?[{tx:c.x0,sx:t(c.bp0)}]:[]}let o=[],r=[],s=[];n.forEach((c,f)=>{o.push(c.x0,c.x1),r.push(t(c.bp0),t(c.bp1)),s.push(f===0?0:Math.min(c.x0-n[f-1].x1,Dt),0)});let i=r.at(-1)-r[0],a=s.reduce((c,f)=>c+f,0),l=a>0?Math.min(1,cc*i/a):1;return dc(r,s,l).map((c,f)=>({tx:o[f],sx:c}))}function dc(e,t,n){let o=[],r=0;for(let i of t)r+=i*n,o.push(r);let s=[];return e.forEach((i,a)=>{let l={mean:i-o[a],n:1},c=s.at(-1);for(;c&&c.mean>=l.mean;){s.pop();let f=c.n+l.n;l={mean:(c.mean*c.n+l.mean*l.n)/f,n:f},c=s.at(-1)}s.push(l)}),s.flatMap(i=>Array(i.n).fill(i.mean)).map((i,a)=>i+o[a])}function Vh(e,t){let n=e.length;if(n===0)return t;let o=e[0],r=e[n-1];if(t<=o.tx)return o.sx+(t-o.tx);if(t>=r.tx)return r.sx+(t-r.tx);let s=1+V(n-2,c=>e[c+1].tx<=t),i=e[s-1],a=e[s],l=a.tx-i.tx;return l>0?i.sx+(t-i.tx)/l*(a.sx-i.sx):i.sx}function Gt(e){let t=e.trim().split(/[\s,]+/),n=[],o=0,r=()=>Number(t[o++]);for(;o<t.length;){let s=t[o++];s==="M"||s==="L"?n.push({op:s,x:r(),y:r()}):s==="H"?n.push({op:s,x:r()}):s==="V"?n.push({op:s,y:r()}):s==="Q"?n.push({op:s,x1:r(),y1:r(),x:r(),y:r()}):s==="C"?n.push({op:s,x1:r(),y1:r(),x2:r(),y2:r(),x:r(),y:r()}):s==="Z"&&n.push({op:s})}return n}function _r(e){let t=1/0,n=-1/0;for(let o of e)"x"in o&&(t=Math.min(t,o.x),n=Math.max(n,o.x)),"x1"in o&&(t=Math.min(t,o.x1),n=Math.max(n,o.x1));return{x0:t,x1:n}}function kr(e,t,n,o,r){let s=Gt(e);return{commands:s,outline:gr(e,12),color:t,id:n,haplotype:o,reference:r,..._r(s)}}function Or(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?xo(n):t[n.id]]))}function Rr(e,t,n,o,r){let{shapes:s}=e,i=t==="haplotype",a=d=>n.get(d.id),l=d=>i&&o.has(d.id),c=[...s.rectangles,...s.verticalRectangles].filter(d=>d.type===t).map(d=>({color:a(d),id:d.id,haplotype:i,reference:l(d),x0:d.xStart,x1:d.xEnd+1,y0:d.yStart,y1:d.yEnd+1})),f=mr(s.curves,t,{gapWidth:r}).map(d=>kr(d.path,a(d),d.id,i,l(d))),u=s.corners.filter(d=>d.type===t).map(d=>kr(d.path,a(d),d.id,i,l(d)));return{rects:c,shapes:[...f,...u]}}function fc(e){let t=new Set,n=e&&Ee(e);return e?.paths?.forEach((o,r)=>{I(o.name).name===n&&t.add(r)}),t}function uc({layout:e,pathColors:t,graph:n,columns:o}){let r=Or(e,t),s=fc(n),i=o?Dt:void 0,a=[];return e.nodes.forEach(l=>{if(l.order>=0){let c=Gt(br(l));a.push({name:l.name,commands:c,..._r(c)})}}),{bounds:e.bounds,layers:[Rr(e,"haplotype",r,s,i),Rr(e,"read",r,s,i)],nodes:a,mismatches:Sr(e)}}function Ft(e,t,n,o){let r=0,s=0;for(let i of t)switch(i.op){case"M":r=i.x,s=i.y,e.moveTo(n(r),o(s));break;case"L":r=i.x,s=i.y,e.lineTo(n(r),o(s));break;case"H":r=i.x,e.lineTo(n(r),o(s));break;case"V":s=i.y,e.lineTo(n(r),o(s));break;case"Q":r=i.x,s=i.y,e.quadraticCurveTo(n(i.x1),o(i.y1),n(r),o(s));break;case"C":r=i.x,s=i.y,e.bezierCurveTo(n(i.x1),o(i.y1),n(i.x2),o(i.y2),n(r),o(s));break;case"Z":e.closePath();break}}function Tr(e,t,n,o,r){let s=new Map;for(let i of t)n(i)&&ee(s,o(i),i);for(let i of s.values()){e.fillStyle=o(i[0]),e.beginPath();for(let a of i)r(a);e.fill()}}var pc=12,hc=.15;function mc(e){return Math.max(hc,Math.min(1,e/pc))}var gc=.55;function bc(e,t,n){let{x:o,y:r,width:s}=n,i=f=>o(f.x1)>=0&&o(f.x0)<=s,a=f=>f.haplotype&&n.tubeColors?.[f.id]||f.color;e.globalAlpha=1;for(let f of t.layers)for(let u of[!1,!0]){let d=p=>p.reference===u;Tr(e,f.rects,p=>d(p)&&i(p),a,p=>{let h=o(p.x0),m=r(p.y0);e.rect(h,m,o(p.x1)-h,r(p.y1)-m)}),Tr(e,f.shapes,p=>d(p)&&i(p),a,p=>{Ft(e,p.commands,o,r)})}let l=n.darkMode?"#d0d0d0":"#000000",c=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=Ar(n);for(let f of t.nodes)if(i(f)&&f.name!==n.highlightNode){e.beginPath(),Ft(e,f.commands,o,r);let u=n.nodeColors?.get(f.name);e.fillStyle=u??c,e.strokeStyle=l,e.globalAlpha=u?gc:1,e.fill(),e.globalAlpha=mc(o(f.x1)-o(f.x0)),e.stroke(),e.globalAlpha=1}Fe(e,t,n),yc(e,t.mismatches,n)}function Ar(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function Fe(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),Ft(e,o.commands,n.x,n.y),e.globalAlpha=1,e.lineWidth=Ar(n),e.fillStyle="rgba(255,192,203,0.5)",e.strokeStyle="#ff0000",e.fill(),e.stroke())}var Nr=12,xc=6;function Yt(e){return Nr*e>=xc}function qt(e,{x:t,width:n}){let[o,r]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(r)>=0&&t(o)<=n}function yc(e,t,n){let{x:o,y:r,yScale:s,darkMode:i}=n;if(!Yt(s)||t.length===0)return;let a=Nr*s;e.fillStyle="grey",e.beginPath();for(let l of t)if(l.kind==="deletion"&&qt(l,n)){let c=o(l.x0),f=r(l.y);e.rect(c,f,o(l.x1)-c,r(l.y+l.height)-f)}e.fill(),e.font=`${a}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=i?"#ffffff":"#000000";for(let l of t)qt(l,n)&&(l.kind==="substitution"?e.fillText(l.seq,o(l.x0)+1,r(l.y+l.height)):l.kind==="insertion"&&e.fillText("*",o(l.x)-3,r(l.y+l.height)))}function wc(e,t,n){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[l,c]=e[s];a>n!=c>n&&t<(l-i)*(n-a)/(c-a)+i&&(o=!o)}return o}function Mc(e,{x:t,y:n},o,r){for(let s=e.layers.length-1;s>=0;s--){let{rects:i,shapes:a}=e.layers[s];for(let l of[!0,!1]){for(let c of i)if(c.reference===l&&t(c.x0)<=o&&o<=t(c.x1)&&n(c.y0)<=r&&r<=n(c.y1))return c.id;for(let c of a)if(c.reference===l&&t(c.x0)<=o&&o<=t(c.x1)&&wc(c.outline.map(([f,u])=>[t(f),n(u)]),o,r))return c.id}}}var vc=4;function Ec(e,t,n,o){let{x:r,y:s,yScale:i}=t;return Yt(i)?e.mismatches.find(a=>s(a.y)<=o&&o<=s(a.y+a.height)&&(a.kind==="insertion"?Math.abs(r(a.x)-n)<=vc:r(a.x0)<=n&&n<=r(a.x1))):void 0}var Q=JBrowseExports["@jbrowse/core/util/groupKeys"],Sc=e=>Q!=null&&e in Object(Q)?Q[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/core/util/groupKeys' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var qe=Sc("groupKeyComparator");var jm=Q&&Q.__esModule?Q.default:Q;var Ge=16;function Zm(e){let[t="",...n]=e.split(/\r\n|\r|\n/),o=t.split(" ").slice(1),r=new Map;for(let s of n){if(!s)continue;let[i="",...a]=s.split(" ");i&&!r.has(i)&&r.set(i,{...Object.fromEntries(o.map((l,c)=>[l,a[c]??""])),name:i})}return[...r.values()]}function Jm(e){let t=new Set;for(let n of e??[])for(let o of Object.keys(n))o!=="name"&&t.add(o);return[...t]}function Qm(e){if(typeof e=="string")return e?{field:e}:void 0;let{field:t,domain:n}=e??{};if(!(typeof t!="string"||!t))return Array.isArray(n)?{field:t,domain:n.filter(o=>typeof o=="string")}:{field:t}}function Wt(e,t){return`${e} ${t}${e===1?"":"s"}`}function Ht(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return(o,r)=>n.get(o)||n.get(r)||""}function Ut(e,t,{field:n,domain:o},r,s){let i=new Map;for(let a of e){let l=t(a),c=i.get(l);c?c.push(a):i.set(l,[a])}return[...i.keys()].sort(qe(o)).map(a=>{let l=i.get(a),c=new Set(l.map(s)).size;return{key:a,members:l,title:`${a||`${n}: none`} \xB7 ${Wt(c,r)}`}})}function eg(e,t,n){let o=Ht(n.field,t),r=Ut(e,a=>o(a.label,a.sample),n,"haplotype",a=>a.label),s=1,i=r.map(({key:a,members:l,title:c})=>{let f={key:a,title:c,first:s,count:l.length};return s+=l.length,f});return{rows:r.flatMap(a=>a.members),sections:i}}function tg(e,t){let n=r=>{let s=-1;for(;s+1<e.length&&e[s+1].first<=r;)s++;return s},o=r=>r*t+(n(r)+1)*Ge;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*Ge})),headersPx:e.length*Ge,rowAt(r,s){let i=0;for(let a=-1;a<e.length;a++){let l=a<0?0:e[a].first,c=a<0?Math.min(s,e[0]?.first??s):l+e[a].count,f=(a+1)*Ge,u=Math.min(c-1,Math.max(l,Math.round((r-f)/t)));Math.abs(o(u)-r)<Math.abs(o(i)-r)&&(i=u)}return i}}}function ng(e,t,n,o,r){return t.length===0?[ge(e,o,r)]:[ge({...e,rows:[]},o,r),...t.flatMap((s,i)=>ge({...e,rows:e.rows.slice(s.first-1,s.first-1+s.count)},{...o,translateY:o.translateY+(n(s.first)-o.rowPx)*o.scaleY},{...r,idPrefix:`${r.idPrefix}-s${i}`}).children.filter(l=>typeof l!="string"&&l.attrs["data-testid"]!=="graph-walk-reference"))]}function kc(e,t,n,o){let r=[],s=[],i=[e];for(o.add(e);i.length>0;){let a=i.pop(),l=t.get(a);if(l){r.push(l);for(let c of n.get(a)??[]){let f=t.get(c);f&&(f.stable.rank===We?s.push(f):o.has(c)||(o.add(c),i.push(c)))}}}return{members:r,anchors:s}}function Rc(e){if(new Set(e.map(a=>a.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((a,l)=>a.stable.start-l.stable.start),o=n[0],r=n.at(-1),s=o.stable.start+o.length,i=r.stable.start;return i>=s?{start:s,end:i,entry:o}:void 0}function Tc(e,t,n){let o=new Map(e.map(i=>[i.id,i])),r=new Map,s=[];for(let i of n.get(t.id)??[])o.has(i)&&(r.set(i,0),s.push(i));if(s.length===0)for(let i of e)r.set(i.id,0),s.push(i.id);for(let i of s){let a=r.get(i)+o.get(i).length;for(let l of n.get(i)??[])if(o.has(l)){let c=r.get(l);(c===void 0||a<c)&&(r.set(l,a),s.push(l))}}return r}function _c(e,t,n){let o=Tc(e,t,n),r=[...e].sort((l,c)=>o.get(l.id)-o.get(c.id)),s=new Map(r.map((l,c)=>[l.id,c])),i=new Map(e.map(l=>[l.id,l])),a=new Map;for(let[l,c]of r.entries()){let f=0;for(let u of n.get(c.id)??[]){let d=i.get(u);d&&s.get(u)<l&&(f=Math.max(f,a.get(u)+d.length))}a.set(c.id,f)}return{offsets:a,ordered:r}}function Oc(e){let t=new Map(e.nodes.filter(Zt).map(s=>[s.id,s])),n=Te(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==We&&!o.has(s.id)){let{members:i,anchors:a}=kc(s.id,t,n,o),l=Rc(a);if(l){let{offsets:c,ordered:f}=_c(i,l.entry,n);r.push({start:l.start,refSpan:l.end-l.start,nodeIds:f.map(u=>u.id),nodeOffsets:f.map(u=>c.get(u.id)),pathLength:f.reduce((u,d)=>Math.max(u,c.get(d.id)+d.length),0)})}}return r.sort((s,i)=>s.start-i.start)}var Ac=28,Pr="#4d4d4d",Nc="#5b8cc4",Pc=[Nc,"#82abd9"],Ng=["#8c8c8c","#adadad"],$c="12px sans-serif",Pg=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],X=e=>I(e).name;function $g(e,t,n=Pc){let o=0;return e.map(r=>X(r.name)===t?Pr:n[o++%n.length])}var Cc=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#76b7b2","#edc948","#9c755f","#ff9da7","#bab0ac"],$r="#c8c8c8";function Cg(e){let t=[...new Set(e)].filter(n=>n!=="").sort(qe());return new Map(t.map((n,o)=>[n,Cc[o]??$r]))}function Ig(e,t,n,o){return e.map(r=>{let s=X(r.name);return s===t?Pr:o.get(n(r.members?.[0]??s))??$r})}function Ic(e,t){let n=Ht(e,t);return o=>{let{sample:r,haplotype:s}=le(o);return n(`${r}#${s}`,r)}}function Lg(e,t){let n=(e.paths??[]).map(l=>l.name).filter(l=>X(l)!==e.referencePath);if(t.by==="column"){let l=Ic(t.field,t.table);return Ut(n,c=>l(X(c)),t,"sample",c=>le(X(c)).sample).map(({key:c,members:f,title:u})=>({key:c,paths:f,label:u}))}let o=t.by==="sample"?l=>le(l).sample:l=>l,r=new Map;for(let l of n){let c=o(X(l)),f=r.get(c);f?f.push(l):r.set(c,[l])}let s=t.domain??[],i=new Map(s.map((l,c)=>[l,c])),a=l=>i.get(l)??s.length;return[...r].map(([l,c],f)=>({key:l,paths:c,i:f})).sort((l,c)=>a(l.key)-a(c.key)||l.i-c.i).map(({key:l,paths:c})=>({key:l,paths:c}))}function Bg(e,t){if(e.graph.nodes.some(n=>n.id===t))return t;for(let[n,o]of e.members)if(o.includes(t))return n}function Xg(e,t,n,o,r){let s=e.flatMap(u=>{let d=t(u);return d?[{id:u,...d}]:[]});if(s.length===0)return;let i=s.reduce((u,d)=>Math.min(u,d.start),1/0),a=s.reduce((u,d)=>Math.max(u,d.end),-1/0),l=o>n?(r-n)/(o-n):0,c=i+Math.min(1,Math.max(0,l))*(a-i),f=u=>c<u.start?u.start-c:c>=u.end?c-u.end+1:0;return s.reduce((u,d)=>f(d)<f(u)?d:u).id}function Dg(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=X(r.name);if(s!==e.referencePath)for(let i of r.members??[s])n.add(i),r.nodeIds.includes(t)&&o.add(i)}return{here:o.size,of:n.size}}var Lc="bold 11px sans-serif",Bc=80,Xc=9;function Fg(e,t,n,{x:o,y:r,width:s}){let i=n.paths??[];if(!i.some(l=>l.members))return;let a=new Map;i.forEach((l,c)=>{X(l.name)!==n.referencePath&&a.set(c,l.members?.length??1)}),e.font=Lc,e.textAlign="left",e.textBaseline="middle",e.fillStyle="#0b1f3a";for(let l of t.layers[0]?.rects??[]){let c=a.get(l.id),f=Math.max(0,o(l.x0)),u=Math.min(s,o(l.x1)),d=r(l.y0),p=r(l.y1);c!==void 0&&u-f>=Bc&&p-d>=Xc&&e.fillText(`\xD7${c}`,f+4,(d+p)/2)}}var Dc="10px sans-serif",Fc=1e3;function qg(e,t,{x:n,y:o,width:r}){if(!t.columns)return;let s=new Map(t.graph.nodes.map(l=>[l.id,l.length]));e.font=Dc;let i=new Map;t.layout.nodes.forEach(l=>{let c=s.get(l.name)??0,f=n(l.x),u=n(l.x+l.pixelWidth),d=A(c);if(l.order>=0&&c>=Fc&&u-f<e.measureText(d).width){let p=(o(l.y)+o(l.y+l.contentHeight))/2,h=`${Math.round(u)}:${d}`,m=i.get(h);m?(m.count++,m.mid=Math.max(m.mid,p)):i.set(h,{text:d,right:u,mid:p,count:1})}}),e.textAlign="left",e.textBaseline="middle",e.lineJoin="round",e.lineWidth=3,e.strokeStyle="rgba(255,255,255,0.9)",e.fillStyle="rgba(0,0,0,0.75)";let a=[];for(let{text:l,right:c,mid:f,count:u}of i.values()){let d=u>1?`${l} each`:l,p={x0:c+3,x1:c+3+e.measureText(d).width,y0:f-6,y1:f+6};p.x1<=r&&!a.some(h=>h.x0<p.x1&&p.x0<h.x1&&h.y0<p.y1&&p.y0<h.y1)&&(a.push(p),e.strokeText(d,p.x0,f),e.fillText(d,p.x0,f))}}function Gg(e,t,n,{width:o,lit:r}){t.forEach((s,i)=>{let a=n?.[i];a&&(r&&Fe(e,s.picture,{...s.frame,width:o,highlightNode:a.box}),e.font=$c,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${a.here} of ${Wt(a.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4))})}function Yg(e,t){let n=new Set(t),o=(e.paths??[]).filter(c=>n.has(c.name)||X(c.name)===e.referencePath),r=new Set(o.map(c=>X(c.name))),s=new Set(o.flatMap(c=>c.nodeIds)),i=e.nodes.filter(c=>s.has(c.id)),a=new Set(i.map(c=>c.name)),l=e.pathVisits?.filter(c=>r.has(c),c=>a.has(c));return{...e,nodes:i,edges:e.edges.filter(c=>s.has(c.from)&&s.has(c.to)),paths:o,anchorPaths:e.anchorPaths?.filter(c=>r.has(c.name)),pathVisits:l,reads:void 0}}function Wg(e,t){let n=[],o={},r=0,s=1/0,i=-1/0;for(let{key:a,paths:l,label:c,result:f}of t){let u=f?.tubeMap,d=f?.extent;if(u&&d){let p=r+Ac,h=(d.maxY??0)-(d.minY??0);n.push({key:a,paths:l,label:c,result:{...f,tubeMap:u},top:p,height:h});let m=p-(d.minY??0);for(let[b,g]of Object.entries(f.nodePositions))o[b]=g.map(x=>({x:x.x,y:x.y+m}));r=p+h,s=Math.min(s,d.minX??s),i=Math.max(i,d.maxX??i)}}return n.length>1?{...e,nodePositions:o,extent:{...s<=i?{minX:s,maxX:i}:{},minY:0,maxY:r},tubeMapPanels:n}:e}var qc="#daa520",Gc=1,Yc=2,Wc=4;function jg(e,t,n,o=r=>r){let r=s=>{let i=t(s)*2;return n?.nodeIds.has(s)?Math.max(i,n.walks.length*Wc):i};return e.flatMap(s=>s.exonsByNode.map(({nodeId:i,d:a})=>({key:`${s.gene.name}-${s.gene.start}-${i}`,d:o(a),inner:r(i)+2*Gc})))}function Vg(e,t){if(e.length===0)return;let n=(o,r,s)=>_("path",{d:o.d,fill:"none",stroke:r,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return _("g",{},_("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},_("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*Yc)),...e.map(o=>n(o,"#000",o.inner)))),_("rect",{width:t.width,height:t.height,fill:qc,mask:`url(#${t.id})`}))}function jt(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${oe(o+1)}-${oe(r)} (${A(r-o)})`}function Hc(e,t){let{field:n}=e.encoding,o=e.range?jt(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?jt(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,i=s-e.bp-e.missingBp-e.unknownBp,a=[[e.missingBp,D.missing],[e.unknownBp,D.unknown],[i,te]];return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${A(Math.abs(s-e.referenceBp))}`,gaps:a.filter(([l])=>l>0).map(([l,c])=>`, ${A(l)} ${c}`).join(""),reversed:e.reversedBp>0?`, ${A(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function Uc(e,t,n){let o=e.progress.get(t),r=e.range;if(o===void 0||!r)return;let s=Math.round(r.start+o*(r.end-r.start)-n/2);return`${r.contig}:${oe(s+1)}-${oe(s+n)}`}function jc(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],i=r?.at(-1);if(!r||!s||!i)continue;let a=Math.max(o.start,s.bp0),l=Math.min(o.end,i.bp1);l<=a||n.push({gene:o,...Be(r,a,l),exons:o.exons.filter(c=>c.end>a&&c.start<l).map(c=>Be(r,Math.max(c.start,a),Math.min(c.end,l)))})}return n}var Vt=22,Vc=4,Ye=8,Kc="11px sans-serif",zc=8;function Zc(e){let t=e.flatMap(r=>[{x:r.x0,step:1},{x:r.x1,step:-1}]).sort((r,s)=>r.x-s.x||r.step-s.step),n=0,o=0;for(let{step:r}of t)n+=r,o=Math.max(o,n);return Math.min(Vc,o)}function Jc(e,t,n,o,r=0){let{x:s,width:i,darkMode:a}=n,l=Math.max(1,Math.floor((o-r)/Vt)),c=[],f=a?"#e0e0e6":"#1c1c22";e.font=Kc,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let u=t.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:p})=>p>=0&&d<=i).sort((d,p)=>d.s0-p.s0);for(let{g:d,s0:p,s1:h}of u){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(p,0)+Math.min(h,i))/2,x=e.measureText(b).width/2,M=Math.min(p,g-x),y=Math.max(h,g+x),w=c.findIndex(S=>S+zc<=M);w===-1&&(w=Math.min(c.length,l-1)),c[w]=Math.max(c[w]??-1/0,y);let v=o-w*Vt-Ye/2;e.beginPath(),e.moveTo(p,v+.5),e.lineTo(h,v+.5),e.stroke();for(let S of d.exons){let k=s(S.x0);e.fillRect(k,v-Ye/2,Math.max(1,s(S.x1)-k),Ye)}e.fillText(b,g,v-Ye/2-2)}}var q=12,Xr=q+8,Dr=8,Cr=Dr+3,Qc=12;function el(e,{colorScheme:t,referenceRamp:n,walks:o}){let r=nt(e,n),s=[];return e.nodes.forEach((i,a)=>{if(O(i)){let l=o?o.map(c=>{let f=c.colors.get(i.id);return f===void 0?_e:H(f)}):[H(ot(i,a,t,r))];s.push({node:i.id,bp0:i.stable.start,bp1:i.stable.start+i.length,colors:l,faded:l.includes(_e)})}}),s.sort((i,a)=>i.bp0-a.bp0)}function Kt(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var Ir=2;function Fr(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),i=Math.max(o,r),a=0,l=0;for(let c of e)a+=Math.max(0,Math.min(c.bp1,s)-c.bp0),l+=Math.max(0,c.bp1-Math.max(c.bp0,i));return t.scale>=0?{left:Math.round(a),right:Math.round(l)}:{left:Math.round(l),right:Math.round(a)}}function tl(e,t,n,o){if(o<0||o>q+Ir)return;let r,s=Ir;for(let i of e){let[a,l]=Kt(t,i.bp0,i.bp1),c=Math.max(0,a-n,n-l);c<=s&&(s=c,r=i.node)}return r}function nl(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function qr(e,t,n,o){let r=e.map(c=>{let[f,u]=Kt(t,c.bp0,c.bp1),d=Math.round(f*o);return{colors:c.colors,x0:f,px0:d,px1:Math.max(Math.round(u*o),d+1)}}).filter(c=>c.px1>0&&c.px0<n*o).sort((c,f)=>c.x0-f.x0),s=[],i=-1/0,a=[-1/0,-1/0];for(let{colors:c,px0:f,px1:u}of r){let d=Math.max(f,i);if(u>d){let p=a[0]<d?0:1;a[p]=u,s.push({colors:c,x0:d/o,x1:u/o,tier:p}),i=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Qc?s:s.map(({tier:c,...f})=>f)}function Lr(e,t,n,o){let r=n>0?t:t-Cr;e.clearRect(r,0,Cr,q);let s=t+n,i=s+n*Dr;e.beginPath(),e.moveTo(s,q/2),e.lineTo(i,0),e.lineTo(i,q),e.closePath(),e.fillStyle=o,e.fill()}function Br(e,t,n){return Math.round(e*q*n/t)/n}function ol(e,t,n,{width:o,lit:r,darkMode:s,dpr:i=1}){let a=s?"#ffffff":"#18181c";e.clearRect(0,0,o,Xr);for(let c of qr(t,n,o,i)){let{tier:f}=c,u=f!==void 0&&c.colors.length===1,d=u?2:c.colors.length;c.colors.forEach((p,h)=>{let m=u?f:h,b=Br(m,d,i);e.fillStyle=p,e.fillRect(c.x0,b,c.x1-c.x0,Br(m+1,d,i)-b)})}let l=Fr(t,n,o);if(l.left>0&&Lr(e,0,1,a),l.right>0&&Lr(e,o,-1,a),r){let[c,f]=Kt(n,r.start,r.end),u=Math.max(f-c,3),d=(c+f)/2-u/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(d,.75,u,q-1.5),r.anchor&&(e.beginPath(),e.moveTo(d+u/2,q),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function rl(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function sl(e,t){let n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0)),s=Array.from({length:n+1},()=>new Array(o+1).fill(!1));for(let a=n-1;a>=0;a--)for(let l=o-1;l>=0;l--){let c=Math.abs(e[a]-t[l])+r[a+1][l+1],f=n-a>o-l?r[a+1][l]:1/0,u=o-l>n-a?r[a][l+1]:1/0;r[a][l]=Math.min(c,f,u),s[a][l]=r[a][l]===c}let i=new Array(n).fill(void 0);for(let a=0,l=0;a<n&&l<o;)s[a][l]?i[a++]=l++:n-a>o-l?a++:l++;return i}function Gr(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var Yr=e=>e.spanningReads!==0;function il(e,t){return{...t,agrees:e.complete&&Yr(t)?rl(e.bp,t.bp):void 0}}function al(e,t){let n=new Map,o=new Set,r=Gr(e,i=>i.bp),s=(i,a)=>{let l=[[i.filter(c=>c.item.complete),a.filter(Yr)],[i,a]];for(let[c,f]of l){let u=c.filter(p=>!n.has(p.i)),d=Gr(f.filter(p=>!o.has(p)),p=>p.bp);sl(u.map(p=>p.item.bp),d.map(p=>p.item.bp)).forEach((p,h)=>{if(p!==void 0){let m=u[h],b=d[p].item;o.add(b),n.set(m.i,il(m.item,b))}})}};for(let i of new Set(t.flatMap(a=>a.haplotype??[])))s(r.filter(a=>a.item.haplotype===i),t.filter(a=>a.haplotype===i));return s(r,t.filter(i=>i.haplotype===void 0)),n}function I0(e,t){if(!t)return e;let n=new Map,o=new Map;for(let r of e){let s=o.get(r.sample);s?s.push(r):o.set(r.sample,[r])}for(let[r,s]of o){let i=t[r];if(i)for(let[a,l]of al(s,i))n.set(s[a],l)}return e.map(r=>({...r,call:n.get(r)}))}var Wr=mo.box(typeof devicePixelRatio>"u"?1:devicePixelRatio);function Hr(){matchMedia(`(resolution: ${devicePixelRatio}dppx)`).addEventListener("change",()=>{go(()=>{Wr.set(devicePixelRatio)}),Hr()},{once:!0})}typeof matchMedia=="function"&&Hr();function q0(e=0,t=0){return Wr.get(),re(e,t)}export{wu as a,Mu as b,vu as c,Eu as d,js as e,Vs as f,It as g,yr as h,rh as i,Qa as j,sh as k,Oc as l,mh as m,gh as n,Vd as o,$e as p,_ as q,Ks as r,zs as s,he as t,wt as u,Ie as v,So as w,ko as x,me as y,_o as z,bt as A,oi as B,ri as C,Ao as D,ci as E,Po as F,$o as G,Mt as H,li as I,di as J,Io as K,ge as L,Ne as M,st as N,Pe as O,jr as P,Vr as Q,Kr as R,zr as S,ql as T,K as U,Wn as V,pe as W,at as X,ms as Y,Gl as Z,Yl as _,bs as $,xs as aa,ys as ba,ws as ca,Ms as da,sf as ea,af as fa,cf as ga,lf as ha,df as ia,ff as ja,uf as ka,pf as la,hf as ma,mf as na,gf as oa,bf as pa,xf as qa,yf as ra,wf as sa,Mf as ta,vf as ua,Ef as va,Es as wa,Sf as xa,kf as ya,Rf as za,Tf as Aa,_f as Ba,Of as Ca,Af as Da,Nf as Ea,gi as Fa,xi as Ga,yi as Ha,wi as Ia,uh as Ja,Et as Ka,Mi as La,Xo as Ma,_i as Na,Oi as Oa,Ni as Pa,Pi as Qa,Yo as Ra,qh as Sa,ic as Ta,Gh as Ua,jh as Va,Vh as Wa,uc as Xa,bc as Ya,Fe as Za,Yt as _a,qt as $a,Mc as ab,Ec as bb,Ge as cb,Zm as db,Jm as eb,Qm as fb,eg as gb,tg as hb,ng as ib,Ac as jb,Pr as kb,Nc as lb,Ng as mb,$c as nb,Pg as ob,$g as pb,$r as qb,Cg as rb,Ig as sb,Ic as tb,Lg as ub,Bg as vb,Xg as wb,Dg as xb,Fg as yb,qg as zb,Gg as Ab,Yg as Bb,Wg as Cb,dt as Db,Lf as Eb,Df as Fb,qc as Gb,jg as Hb,Vg as Ib,Kf as Jb,lo as Kb,zf as Lb,fo as Mb,ut as Nb,uo as Ob,po as Pb,Ws as Qb,jt as Rb,Hc as Sb,Uc as Tb,jc as Ub,Vt as Vb,Zc as Wb,Jc as Xb,Xr as Yb,el as Zb,Fr as _b,tl as $b,nl as ac,ol as bc,I0 as cc,q0 as dc};
3
+ //# sourceMappingURL=chunk-ADZBAET3.js.map