jbrowse-plugin-graphgenomeviewer 8.3.0 → 8.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/chunks/{GbzBaseSyntenyAdapter-EJIR3HZM.js → GbzBaseSyntenyAdapter-W5J3E5VT.js} +2 -2
- package/dist/chunks/{GbzBaseSyntenyAdapter-EJIR3HZM.js.map → GbzBaseSyntenyAdapter-W5J3E5VT.js.map} +1 -1
- package/dist/chunks/{GraphGenomeView-2AKRM74B.js → GraphGenomeView-NLPWMIBS.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-7XRZQW6T.js → GraphTrackSettingsDialog-7LHAOYX3.js} +2 -2
- package/dist/chunks/{HighlightColorDialog-LCBGD2ZA.js → HighlightColorDialog-YQEMRPZ6.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-WWQ73BO5.js → LinearGraphDisplay-BEU7V4JU.js} +2 -2
- package/dist/chunks/{MinigraphBubbleAdapter-4OOBJ44C.js → MinigraphBubbleAdapter-FZZLY3ZI.js} +2 -2
- package/dist/chunks/{RgfaTabixAdapter-CEGFN2QY.js → RgfaTabixAdapter-DXBQEVFS.js} +2 -2
- package/dist/chunks/{WalkFormsAdapter-LTAKACZD.js → WalkFormsAdapter-ZKZ5PUYO.js} +2 -2
- package/dist/chunks/{WalkTabixSyntenyAdapter-B6V3YNW7.js → WalkTabixSyntenyAdapter-HEGPYGKB.js} +2 -2
- package/dist/chunks/{chunk-T2VC3EEL.js → chunk-2FCFK2B5.js} +1 -1
- package/dist/chunks/{chunk-T2VC3EEL.js.map → chunk-2FCFK2B5.js.map} +1 -1
- package/dist/chunks/{chunk-PTOKTIQG.js → chunk-5X3OZSDO.js} +2 -2
- package/dist/chunks/chunk-D6NFDQQI.js +4 -0
- package/dist/chunks/chunk-D6NFDQQI.js.map +7 -0
- package/dist/chunks/chunk-D7MOOK6H.js +4 -0
- package/dist/chunks/chunk-D7MOOK6H.js.map +7 -0
- package/dist/chunks/chunk-EINURNZ6.js +2 -0
- package/dist/chunks/chunk-EKIQ3ATV.js +2 -0
- package/dist/chunks/chunk-EKIQ3ATV.js.map +7 -0
- package/dist/chunks/{chunk-WUOXZAGN.js → chunk-HM7XSNBN.js} +1 -1
- package/dist/chunks/{chunk-WUOXZAGN.js.map → chunk-HM7XSNBN.js.map} +1 -1
- package/dist/chunks/{chunk-UECOGSWM.js → chunk-IQQOJGX3.js} +2 -2
- package/dist/chunks/{chunk-UECOGSWM.js.map → chunk-IQQOJGX3.js.map} +1 -1
- package/dist/chunks/{chunk-CZXJXNZN.js → chunk-JTOW3TOE.js} +2 -2
- package/dist/chunks/{chunk-UHV6XIDG.js → chunk-KM2INI7Q.js} +2 -2
- package/dist/chunks/{chunk-UHV6XIDG.js.map → chunk-KM2INI7Q.js.map} +1 -1
- package/dist/chunks/{chunk-OGXVDZPS.js → chunk-MFMAQO3W.js} +2 -2
- package/dist/chunks/{chunk-OGXVDZPS.js.map → chunk-MFMAQO3W.js.map} +1 -1
- package/dist/chunks/{chunk-IK3MQ4ZJ.js → chunk-MNFL7BAC.js} +2 -2
- package/dist/chunks/{chunk-IK3MQ4ZJ.js.map → chunk-MNFL7BAC.js.map} +1 -1
- package/dist/chunks/{chunk-CNCYMJ5E.js → chunk-NB4X56M3.js} +2 -2
- package/dist/chunks/{chunk-CNCYMJ5E.js.map → chunk-NB4X56M3.js.map} +1 -1
- package/dist/chunks/{chunk-VKZALU57.js → chunk-OMF5XFKR.js} +1 -1
- package/dist/chunks/{chunk-VKZALU57.js.map → chunk-OMF5XFKR.js.map} +1 -1
- package/dist/chunks/{chunk-BJHWGRMP.js → chunk-TNEXOJ5F.js} +1 -1
- package/dist/chunks/{chunk-BJHWGRMP.js.map → chunk-TNEXOJ5F.js.map} +1 -1
- package/dist/chunks/chunk-VP6AGIRF.js +2 -0
- package/dist/chunks/chunk-VP6AGIRF.js.map +7 -0
- package/dist/chunks/{chunk-SL4JJJQJ.js → chunk-XBZ4C4R3.js} +3 -3
- package/dist/chunks/{chunk-SL4JJJQJ.js.map → chunk-XBZ4C4R3.js.map} +2 -2
- package/dist/chunks/chunk-Y7VFVMQI.js +2 -0
- package/dist/chunks/chunk-Y7VFVMQI.js.map +7 -0
- package/dist/chunks/{chunk-QWG7NASD.js → chunk-YMK7HFJV.js} +2 -2
- package/dist/chunks/{chunk-CVHKXFVS.js → chunk-ZWRAQSXC.js} +2 -2
- package/dist/chunks/chunk-ZWRAQSXC.js.map +7 -0
- package/dist/chunks/{renderSvg-E5Q7MLCH.js → renderSvg-XIEGA5N5.js} +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
- package/package.json +2 -2
- package/src/GetSubgraph.ts +2 -0
- package/src/GraphGenomeView/legendSections.ts +5 -2
- package/src/GraphGenomeView/model.ts +8 -1
- package/src/RgfaTabixAdapter/walkFiles.test.ts +14 -0
- package/src/RgfaTabixAdapter/walkReader.ts +22 -5
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-CVHKXFVS.js.map +0 -7
- package/dist/chunks/chunk-CZI7IP5S.js +0 -2
- package/dist/chunks/chunk-CZI7IP5S.js.map +0 -7
- package/dist/chunks/chunk-HAAABGE7.js +0 -2
- package/dist/chunks/chunk-MCBYBZZJ.js +0 -4
- package/dist/chunks/chunk-MCBYBZZJ.js.map +0 -7
- package/dist/chunks/chunk-NOXHIOIM.js +0 -2
- package/dist/chunks/chunk-NOXHIOIM.js.map +0 -7
- package/dist/chunks/chunk-OLZZDBQJ.js +0 -4
- package/dist/chunks/chunk-OLZZDBQJ.js.map +0 -7
- package/dist/chunks/chunk-W7IHIVSE.js +0 -2
- package/dist/chunks/chunk-W7IHIVSE.js.map +0 -7
- /package/dist/chunks/{GraphGenomeView-2AKRM74B.js.map → GraphGenomeView-NLPWMIBS.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-7XRZQW6T.js.map → GraphTrackSettingsDialog-7LHAOYX3.js.map} +0 -0
- /package/dist/chunks/{HighlightColorDialog-LCBGD2ZA.js.map → HighlightColorDialog-YQEMRPZ6.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-WWQ73BO5.js.map → LinearGraphDisplay-BEU7V4JU.js.map} +0 -0
- /package/dist/chunks/{MinigraphBubbleAdapter-4OOBJ44C.js.map → MinigraphBubbleAdapter-FZZLY3ZI.js.map} +0 -0
- /package/dist/chunks/{RgfaTabixAdapter-CEGFN2QY.js.map → RgfaTabixAdapter-DXBQEVFS.js.map} +0 -0
- /package/dist/chunks/{WalkFormsAdapter-LTAKACZD.js.map → WalkFormsAdapter-ZKZ5PUYO.js.map} +0 -0
- /package/dist/chunks/{WalkTabixSyntenyAdapter-B6V3YNW7.js.map → WalkTabixSyntenyAdapter-HEGPYGKB.js.map} +0 -0
- /package/dist/chunks/{chunk-PTOKTIQG.js.map → chunk-5X3OZSDO.js.map} +0 -0
- /package/dist/chunks/{chunk-HAAABGE7.js.map → chunk-EINURNZ6.js.map} +0 -0
- /package/dist/chunks/{chunk-CZXJXNZN.js.map → chunk-JTOW3TOE.js.map} +0 -0
- /package/dist/chunks/{chunk-QWG7NASD.js.map → chunk-YMK7HFJV.js.map} +0 -0
- /package/dist/chunks/{renderSvg-E5Q7MLCH.js.map → renderSvg-XIEGA5N5.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../node_modules/.pnpm/@jbrowse+bandage-core@12.
|
|
3
|
+
"sources": ["../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-5ORP7EFJ.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-JQVS4DRW.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-5OJZV6YT.js"],
|
|
4
4
|
"sourcesContent": ["import {\n addTo\n} from \"./chunk-BSOZW3FC.js\";\nimport {\n isBackbone\n} from \"./chunk-RJWPJCIB.js\";\nimport {\n isGenericSample,\n panSNContig,\n panSNHaplotype,\n panSNSample\n} from \"./chunk-2JL2JVZ2.js\";\n\n// src/reference.ts\nvar WELL_KNOWN_SAMPLES = /* @__PURE__ */ new Map([\n [\"hg38\", \"GRCh38\"],\n [\"hg19\", \"GRCh37\"],\n [\"hs1\", \"CHM13\"],\n [\"t2t-chm13\", \"CHM13\"],\n [\"chm13v2\", \"CHM13\"]\n]);\nfunction wellKnownSample(assemblyName) {\n return WELL_KNOWN_SAMPLES.get(assemblyName.toLowerCase());\n}\nfunction sampleOf(refName) {\n const sample = refName.includes(\"#\") ? panSNSample(refName) : void 0;\n return sample === void 0 || isGenericSample(sample) ? void 0 : sample;\n}\nfunction haplotypeOf(refName) {\n return panSNHaplotype(refName) ?? panSNSample(refName);\n}\nfunction graphHaplotypes(graph) {\n const refNames = new Set((graph.anchorPaths ?? []).map((p) => p.name));\n for (const node of graph.nodes) {\n if (node.stable) {\n refNames.add(node.stable.refName);\n }\n }\n const bySample = /* @__PURE__ */ new Map();\n for (const refName of refNames) {\n const sample = sampleOf(refName);\n if (sample !== void 0) {\n addTo(bySample, sample, haplotypeOf(refName));\n }\n }\n return bySample;\n}\nfunction backboneFrom(contigs, haplotypes) {\n const samples = new Set(contigs.map((c) => sampleOf(c.refName)));\n const [sample] = samples;\n if (samples.size !== 1 || sample === void 0) {\n return { contigs, prefixes: [], named: false };\n }\n const own = new Set(contigs.map((c) => haplotypeOf(c.refName)));\n const unique = [...haplotypes.get(sample) ?? []].every((h) => own.has(h));\n const shared = new Set(contigs.map((c) => panSNHaplotype(c.refName)));\n const [haplotype] = shared;\n return {\n contigs,\n prefixes: [\n ...unique ? [sample] : [],\n ...shared.size === 1 && haplotype ? [haplotype] : []\n ],\n named: true\n };\n}\nfunction graphBackbone(graph) {\n const spans = /* @__PURE__ */ new Map();\n for (const node of graph.nodes) {\n if (isBackbone(node)) {\n const { refName, start } = node.stable;\n const end = start + node.length;\n const span = spans.get(refName);\n if (span) {\n span.start = Math.min(span.start, start);\n span.end = Math.max(span.end, end);\n } else {\n spans.set(refName, {\n refName,\n contig: panSNContig(refName),\n start,\n end\n });\n }\n }\n }\n const contigs = [...spans.values()];\n return contigs.length ? backboneFrom(contigs, graphHaplotypes(graph)) : void 0;\n}\nfunction referenceLabel(graph, region) {\n const backbone = graphBackbone(graph);\n const contig = region ? panSNContig(region.refName) : backbone?.contigs.length === 1 ? backbone.contigs[0].contig : void 0;\n const sample = backbone?.named ? panSNSample(backbone.contigs[0].refName) : void 0;\n return contig && (sample ? `${sample} ${contig}` : contig);\n}\nfunction backboneAssembly(backbone, assemblies) {\n const names = (a) => [a.name, ...a.aliases ?? []];\n const naming = (prefix) => (a) => names(a).some((n) => n.toLowerCase() === prefix.toLowerCase());\n const prefixes = [...backbone?.prefixes ?? []].reverse();\n const sample = backbone?.prefixes.find((p) => !p.includes(\"#\"))?.toLowerCase();\n for (const prefix of prefixes) {\n const assembly = assemblies.find(naming(prefix));\n if (assembly) {\n return assembly;\n }\n }\n return sample === void 0 ? void 0 : assemblies.find(\n (a) => names(a).some((n) => wellKnownSample(n)?.toLowerCase() === sample)\n );\n}\nfunction assemblyWalk(graph, assembly) {\n const haplotypes = graphHaplotypes(graph);\n return graph.anchorPaths?.find(\n (walk) => backboneAssembly(\n backboneFrom(\n [\n {\n refName: walk.name,\n contig: panSNContig(walk.name),\n start: walk.start,\n end: walk.start + walk.length\n }\n ],\n haplotypes\n ),\n [assembly]\n )\n );\n}\nfunction contigNames(contig) {\n const bare = contig.replace(/^chr/i, \"\");\n const forms = !bare ? [] : /^(M|MT)$/i.test(bare) ? [\"M\", \"MT\"] : [bare];\n return [.../* @__PURE__ */ new Set([contig, ...forms.flatMap((f) => [f, `chr${f}`])])];\n}\nfunction refNameBinding(refNames, aliases = {}) {\n const exact = new Set(refNames);\n const byName = /* @__PURE__ */ new Map();\n for (const refName of exact) {\n const contig = panSNContig(refName);\n const alias = aliases[contig];\n for (const name of /* @__PURE__ */ new Set([\n ...contigNames(contig),\n ...alias ? [alias] : []\n ])) {\n byName.set(name, byName.has(name) ? void 0 : refName);\n }\n }\n return (name) => exact.has(name) ? name : byName.get(name);\n}\nfunction featuresOnBackbone(features, backbone, aliases) {\n const bind = refNameBinding(\n backbone.contigs.map((c) => c.refName),\n aliases\n );\n return features.flatMap((f) => {\n const refName = bind(f.refName);\n return refName === void 0 ? [] : [refName === f.refName ? f : { ...f, refName }];\n });\n}\n\nexport {\n WELL_KNOWN_SAMPLES,\n wellKnownSample,\n graphBackbone,\n referenceLabel,\n backboneAssembly,\n assemblyWalk,\n contigNames,\n refNameBinding,\n featuresOnBackbone\n};\n", "import {\n END_STOP_TAG,\n START_STOP_TAG,\n StopColumns,\n parseStopTag\n} from \"./chunk-VA5U4F23.js\";\nimport {\n Column\n} from \"./chunk-BEUTROKU.js\";\n\n// src/gfa/gfaTables.ts\nvar GT = 62;\nvar LT = 60;\nvar TAB = 9;\nvar ZERO = 48;\nvar NINE = 57;\nvar TABLE_TAG = /^(?:LN:i|SN:Z|SO:i|SR:i):/;\nvar UNTABLED_RECORD = /^[PEOUFG]\\t/;\nvar trimCR = (line) => line.endsWith(\"\\r\") ? line.slice(0, -1) : line;\nfunction stepColumns() {\n return {\n nodes: new Column(new Int32Array(1 << 16)),\n reversed: new Column(new Uint8Array(1 << 16))\n };\n}\nvar SegmentIndex = class {\n constructor() {\n this.names = [];\n this.byName = /* @__PURE__ */ new Map();\n // ids that are plain decimal, so a walk step finds its segment without\n // slicing a string out of the body\n this.byNumber = /* @__PURE__ */ new Map();\n }\n has(name) {\n return this.byName.has(name);\n }\n add(name) {\n const i = this.names.length;\n this.byName.set(name, i);\n this.names.push(name);\n const n = +name;\n if (Number.isSafeInteger(n) && String(n) === name) {\n this.byNumber.set(n, i);\n }\n return i;\n }\n of(name) {\n return this.byName.get(name) ?? this.add(name);\n }\n ofNumber(n) {\n return this.byNumber.get(n);\n }\n};\nfunction readSegment(line) {\n const [, name, sequence = \"*\", ...tags] = line.split(\"\t\");\n if (!name || /^\\d+$/.test(sequence)) {\n return void 0;\n }\n let length = sequence === \"*\" ? 0 : sequence.length;\n let refName;\n let start;\n let rank;\n for (const tag of tags) {\n if (!TABLE_TAG.test(tag)) {\n return void 0;\n }\n const value = tag.slice(5);\n const key = tag.slice(0, 2);\n if (key === \"LN\") {\n length = +value;\n } else if (key === \"SN\") {\n refName = value;\n } else if (key === \"SO\") {\n start = +value;\n } else {\n rank = +value;\n }\n }\n const stable = refName !== void 0 && start !== void 0 && rank !== void 0 ? { refName, start, rank } : void 0;\n return { name, length, stable };\n}\nfunction readWalkBody(line, from, segments, steps) {\n let reversed = 0;\n let start = -1;\n let value = 0;\n let decimal = true;\n const finish = (end) => {\n if (start >= 0 && end > start) {\n const node = decimal && end - start < 16 && (end - start === 1 || line.charCodeAt(start) !== ZERO) ? segments.ofNumber(value) : void 0;\n steps.nodes.push(node ?? segments.of(line.slice(start, end)));\n steps.reversed.push(reversed);\n }\n };\n let i = from;\n for (; i < line.length; i++) {\n const ch = line.charCodeAt(i);\n if (ch === GT || ch === LT) {\n finish(i);\n reversed = ch === LT ? 1 : 0;\n start = i + 1;\n value = 0;\n decimal = true;\n } else if (ch === TAB) {\n break;\n } else if (decimal && ch >= ZERO && ch <= NINE) {\n value = value * 10 + ch - ZERO;\n } else {\n decimal = false;\n }\n }\n finish(i);\n return i;\n}\nfunction walkFields(line) {\n const fields = [];\n let at = 0;\n while (fields.length < 6) {\n const tab = line.indexOf(\"\t\", at);\n if (tab === -1) {\n return void 0;\n }\n fields.push(line.slice(at, tab));\n at = tab + 1;\n }\n const [, sample, haplotype, contig, start, end] = fields;\n return sample && haplotype && contig && start && end && at < line.length ? { sample, haplotype, contig, start, end, body: at } : void 0;\n}\nfunction gfaTables(text) {\n const lines = text.split(\"\\n\");\n const segments = new SegmentIndex();\n const lengths = [];\n const refs = [];\n const starts = [];\n const ranks = [];\n const refNames = [];\n const refIndex = /* @__PURE__ */ new Map();\n for (const raw of lines) {\n if (UNTABLED_RECORD.test(raw)) {\n return void 0;\n }\n if (raw.startsWith(\"S\t\")) {\n const s = readSegment(trimCR(raw));\n if (!s || segments.has(s.name)) {\n return void 0;\n }\n segments.add(s.name);\n lengths.push(s.length);\n let ref = -1;\n if (s.stable) {\n ref = refIndex.get(s.stable.refName) ?? refNames.length;\n if (ref === refNames.length) {\n refNames.push(s.stable.refName);\n refIndex.set(s.stable.refName, ref);\n }\n }\n refs.push(ref);\n starts.push(s.stable?.start ?? 0);\n ranks.push(s.stable?.rank ?? 0);\n }\n }\n const from = [];\n const to = [];\n const strands = [];\n const names = [];\n const walkStarts = [];\n const walkEnds = [];\n const offsets = [0];\n const steps = stepColumns();\n const before = new StopColumns();\n const after = new StopColumns();\n for (const raw of lines) {\n if (raw.startsWith(\"L\t\")) {\n const [, source, strand1, target, strand2] = trimCR(raw).split(\"\t\");\n if (source && target && strand2) {\n from.push(segments.of(source));\n to.push(segments.of(target));\n strands.push((strand1 === \"-\" ? 1 : 0) | (strand2 === \"-\" ? 2 : 0));\n }\n } else if (raw.startsWith(\"W\t\")) {\n const line = trimCR(raw);\n const w = walkFields(line);\n if (w) {\n names.push(`${w.sample}#${w.haplotype}#${w.contig}`);\n walkStarts.push(w.start === \"*\" ? 0 : +w.start);\n walkEnds.push(w.end === \"*\" ? -1 : +w.end);\n const end = readWalkBody(line, w.body, segments, steps);\n const tags = walkTags(line, end);\n if (tags === void 0) {\n return void 0;\n }\n if (tags.before) {\n before.push(tags.before);\n }\n if (tags.after) {\n after.push(tags.after);\n }\n if (steps.nodes.length === offsets.at(-1)) {\n return void 0;\n }\n offsets.push(steps.nodes.length);\n }\n }\n }\n if ([before.kinds.length, after.kinds.length].some(\n (n) => n > 0 && n < names.length\n )) {\n return void 0;\n }\n return {\n nodes: {\n names: segments.names,\n lengths: Int32Array.from(lengths),\n refs: Int32Array.from(refs),\n starts: Float64Array.from(starts),\n ranks: Int32Array.from(ranks),\n refNames\n },\n links: {\n from: Int32Array.from(from),\n to: Int32Array.from(to),\n strands: Uint8Array.from(strands)\n },\n walks: {\n names,\n starts: Float64Array.from(walkStarts),\n ends: Float64Array.from(walkEnds),\n offsets: Int32Array.from(offsets),\n steps: steps.nodes.data.slice(0, steps.nodes.length),\n reversed: steps.reversed.data.slice(0, steps.reversed.length),\n ...stopColumns(names.length, before, after)\n }\n };\n}\nfunction walkTags(line, from) {\n const out = {};\n for (const tag of from < line.length ? line.slice(from + 1).split(\"\t\") : []) {\n const value = tag.slice(5);\n if (tag.startsWith(`${START_STOP_TAG}:Z:`)) {\n out.before = parseStopTag(value);\n if (!out.before) {\n return void 0;\n }\n } else if (tag.startsWith(`${END_STOP_TAG}:Z:`)) {\n out.after = parseStopTag(value);\n if (!out.after) {\n return void 0;\n }\n }\n }\n return out;\n}\nfunction stopColumns(walks, before, after) {\n return {\n ...before.kinds.length === walks && walks > 0 ? { before: before.table() } : {},\n ...after.kinds.length === walks && walks > 0 ? { after: after.table() } : {}\n };\n}\n\nexport {\n gfaTables\n};\n", "// src/gaf/parseGaf.ts\nvar STEP = /([><])([^><]+)/g;\nfunction parseGafPath(column) {\n if (!column.startsWith(\">\") && !column.startsWith(\"<\")) {\n return void 0;\n }\n const steps = [];\n for (const [, arrow, name] of column.matchAll(STEP)) {\n steps.push({ name, strand: arrow === \">\" ? \"+\" : \"-\" });\n }\n return steps;\n}\nfunction parseGafLine(text) {\n const line = text.trimEnd();\n const columns = line.split(\"\t\");\n if (columns.length < 12 || line.startsWith(\"#\")) {\n return void 0;\n }\n const path = parseGafPath(columns[5]);\n if (!path) {\n return void 0;\n }\n let cs;\n let secondary = false;\n for (let i = 12; i < columns.length; i++) {\n const tag = columns[i];\n if (tag.startsWith(\"cs:Z:\")) {\n cs = tag.slice(5);\n } else if (tag === \"tp:A:S\") {\n secondary = true;\n }\n }\n return {\n name: columns[0],\n queryLength: +columns[1],\n queryStart: +columns[2],\n queryEnd: +columns[3],\n strand: columns[4] === \"-\" ? \"-\" : \"+\",\n path,\n pathLength: +columns[6],\n pathStart: +columns[7],\n pathEnd: +columns[8],\n matches: +columns[9],\n blockLength: +columns[10],\n mappingQuality: +columns[11],\n secondary,\n ...cs === void 0 ? {} : { cs }\n };\n}\nfunction parseGaf(text) {\n const records = [];\n for (const line of text.split(\"\\n\")) {\n const record = parseGafLine(line);\n if (record) {\n records.push(record);\n }\n }\n return records;\n}\nvar CS_OP = /:(\\d+)|=([A-Za-z]+)|\\*[a-zA-Z]([a-zA-Z])|\\+([A-Za-z]+)|-([A-Za-z]+)|~[a-z]{2}(\\d+)[a-z]{2}/g;\nfunction parseCs(cs) {\n const ops = [];\n for (const m of cs.matchAll(CS_OP)) {\n if (m[1] !== void 0) {\n ops.push({ op: \"match\", length: +m[1] });\n } else if (m[2] !== void 0) {\n ops.push({ op: \"match\", length: m[2].length });\n } else if (m[3] !== void 0) {\n ops.push({ op: \"substitution\", seq: m[3].toUpperCase() });\n } else if (m[4] !== void 0) {\n ops.push({ op: \"insertion\", seq: m[4].toUpperCase() });\n } else if (m[5] !== void 0) {\n ops.push({ op: \"deletion\", length: m[5].length });\n } else if (m[6] !== void 0) {\n ops.push({ op: \"match\", length: +m[6] });\n }\n }\n return ops;\n}\n\nexport {\n parseGafPath,\n parseGafLine,\n parseGaf,\n parseCs\n};\n"],
|
|
5
5
|
"mappings": "gLAcA,IAAIA,EAAqC,IAAI,IAAI,CAC/C,CAAC,OAAQ,QAAQ,EACjB,CAAC,OAAQ,QAAQ,EACjB,CAAC,MAAO,OAAO,EACf,CAAC,YAAa,OAAO,EACrB,CAAC,UAAW,OAAO,CACrB,CAAC,EACD,SAASC,EAAgBC,EAAc,CACrC,OAAOF,EAAmB,IAAIE,EAAa,YAAY,CAAC,CAC1D,CACA,SAASC,EAASC,EAAS,CACzB,IAAMC,EAASD,EAA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IAAM,OAClBD,EAAI,KAAK,CAAE,GAAI,YAAa,IAAKC,EAAE,CAAC,EAAE,YAAY,CAAE,CAAC,EAC5CA,EAAE,CAAC,IAAM,OAClBD,EAAI,KAAK,CAAE,GAAI,WAAY,OAAQC,EAAE,CAAC,EAAE,MAAO,CAAC,EACvCA,EAAE,CAAC,IAAM,QAClBD,EAAI,KAAK,CAAE,GAAI,QAAS,OAAQ,CAACC,EAAE,CAAC,CAAE,CAAC,EAG3C,OAAOD,CACT",
|
|
6
6
|
"names": ["WELL_KNOWN_SAMPLES", "wellKnownSample", "assemblyName", "sampleOf", "refName", "sample", "panSNSample", "isGenericSample", "haplotypeOf", "panSNHaplotype", "graphHaplotypes", "graph", "refNames", "p", "node", "bySample", "addTo", "backboneFrom", "contigs", "haplotypes", "samples", "c", "own", "unique", "h", "shared", "haplotype", "graphBackbone", "spans", "isBackbone", "start", "end", "span", "panSNContig", "referenceLabel", "region", "backbone", "contig", "backboneAssembly", "assemblies", "names", "naming", "prefix", "a", "n", "prefixes", "assembly", "assemblyWalk", "walk", "contigNames", "bare", "forms", "f", "refNameBinding", "aliases", "exact", "byName", "alias", "name", "featuresOnBackbone", "features", "bind", "GT", "LT", "TAB", "ZERO", "NINE", "TABLE_TAG", "UNTABLED_RECORD", "trimCR", "line", "stepColumns", "Column", "SegmentIndex", "name", "i", "n", "readSegment", "sequence", "tags", "length", "refName", "start", "rank", "tag", "value", "key", "readWalkBody", "from", "segments", "steps", "reversed", "decimal", "finish", "end", "node", "ch", "walkFields", "fields", "at", "tab", "sample", "haplotype", "contig", "gfaTables", "text", "lines", "lengths", "refs", "starts", "ranks", "refNames", "refIndex", "raw", "s", "ref", "to", "strands", "names", "walkStarts", "walkEnds", "offsets", "before", "StopColumns", "after", "source", "strand1", "target", "strand2", "w", "walkTags", "stopColumns", "out", "START_STOP_TAG", "parseStopTag", "END_STOP_TAG", "walks", "STEP", "parseGafPath", "column", "steps", "arrow", "name", "parseGafLine", "text", "line", "columns", "path", "cs", "secondary", "i", "tag", "parseGaf", "records", "record", "CS_OP", "parseCs", "ops", "m"]
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as u}from"./chunk-OMF5XFKR.js";function b(t,s,e){let n=t.get(s);n?n.push(e):t.set(s,[e])}function S(t,s,e){let n=t.get(s);n?n.add(e):t.set(s,new Set([e]))}function m(t,s){let e=new Map;for(let n of t)b(e,s(n),n);return e}function g(t,s){let e=0,n=t;for(;e<n;){let r=e+n>>1;s(r)?e=r+1:n=r}return e}var l=0;function _(t){return t.stable!==void 0}function w(t){return t.stable?.rank===l}function G(t){return t.stable!==void 0&&t.stable.rank>l}function U(t){return t.nodes.filter(w)}function C(t,s){return t.stable.start<s.end&&t.stable.start+t.length>s.start}function K(t){let s={};for(let e of t)s[e.id]=[{x:e.stable.start,y:0},{x:e.stable.start+e.length,y:0}];return s}function T(t,s){return g(t.length,e=>t[e].stable.start<s)}function y(t){let s=1/0,e=-1/0;for(let n of t)s=Math.min(s,n.stable.start),e=Math.max(e,n.stable.start+n.length);return e-s}function $(t,s){return s&&s.end>s.start?s.end-s.start:y(t)}var A=class{constructor(t){this.segments=t.segments,this.offsets=t.offsets,this.path=t.path,this.start=t.start,this.reversed=t.reversed,this.paths=t.paths,this.samples=t.samples,this.slots=new Map(this.segments.map((s,e)=>[s,e]))}static from(t){let s=new d;for(let[e,n]of t){s.declare(e);for(let r of n)s.add(e,r.path,r.sample,r.start,r.strand==="-")}return s.build()}get size(){return this.segments.length}slot(t){return this.slots.get(t)??-1}pathIndex(t){return this.paths.indexOf(t)}firstBy(t,s){for(let e=this.offsets[t];e<this.offsets[t+1];e++)if(this.path[e]===s)return e;return-1}firstByName(t){let s=this.offsets[t];for(let e=s+1;e<this.offsets[t+1];e++){let n=this.paths[this.path[e]],r=this.paths[this.path[s]];(n<r||n===r&&this.start[e]<this.start[s])&&(s=e)}return s}replay(){let t=new Map;return(s,e)=>{if(s<0||e<0)return-1;let n=s*this.paths.length+e,r=this.offsets[s+1],a=t.get(n)??this.offsets[s];for(;a<r&&this.path[a]!==e;)a++;return t.set(n,a+1),a<r?a:-1}}filter(t,s=()=>!0){let e=this.paths.map(t),n=new d;return this.segments.forEach((r,a)=>{if(!s(r))return;let h=n.declare(r);for(let o=this.offsets[a];o<this.offsets[a+1];o++){let i=this.path[o];e[i]&&n.addAt(h,n.pathOf(this.paths[i],this.samples[i]),this.start[o],this.reversed[o]===1)}}),n.build()}strand(t){return this.reversed[t]?"-":"+"}visit(t){let s=this.path[t];return{path:this.paths[s],sample:this.samples[s],start:this.start[t],strand:this.strand(t)}}visitsAt(t){let s=[];for(let e=this.offsets[t];e<this.offsets[t+1];e++)s.push(this.visit(e));return s}get(t){let s=this.slot(t);return s<0?void 0:this.visitsAt(s)}has(t){return this.slots.has(t)}keys(){return this.segments[Symbol.iterator]()}*values(){for(let t=0;t<this.segments.length;t++)yield this.visitsAt(t)}*entries(){for(let t=0;t<this.segments.length;t++)yield[this.segments[t],this.visitsAt(t)]}[Symbol.iterator](){return this.entries()}},p=class{constructor(t){this.data=t,this.length=0}push(t){if(this.length===this.data.length){let s=new this.data.constructor(this.data.length*2);s.set(this.data),this.data=s}this.data[this.length++]=t}},d=class{constructor(){this.segments=[],this.slots=new Map,this.paths=[],this.samples=[],this.pathIndex=new Map,this.slot=new p(new Int32Array(1024)),this.path=new p(new Int32Array(1024)),this.start=new p(new Float64Array(1024)),this.reversed=new p(new Uint8Array(1024))}declare(t){let s=this.slots.get(t);return s===void 0&&(s=this.segments.length,this.slots.set(t,s),this.segments.push(t)),s}pathOf(t,s){let e=this.pathIndex.get(t);return e===void 0&&(e=this.paths.length,this.pathIndex.set(t,e),this.paths.push(t),this.samples.push(s)),e}add(t,s,e,n,r){this.addAt(this.declare(t),this.pathOf(s,e),n,r)}addAt(t,s,e,n){this.slot.push(t),this.path.push(s),this.start.push(e),this.reversed.push(n?1:0)}build(){let t=this.slot.length,s=this.segments.length,e=new Int32Array(s+1),n=this.slot.data;for(let i=0;i<t;i++)e[n[i]+1]++;for(let i=0;i<s;i++)e[i+1]+=e[i];let r=e.slice(0,s),a=new Int32Array(t),h=new Float64Array(t),o=new Uint8Array(t);for(let i=0;i<t;i++){let f=r[n[i]]++;a[f]=this.path.data[i],h[f]=this.start.data[i],o[f]=this.reversed.data[i]}return new A({segments:this.segments,offsets:e,path:a,start:h,reversed:o,paths:this.paths,samples:this.samples})}};var v=/:(\d+)-\d+$/,x=/^([^#]*#[^#]*#[^#[]*)#(\d+)(?:\[(\d+)-\d+\])?$/,I=/\[(\d+)-\d+\]$/;function E(t){let s=x.exec(t);if(s)return{name:s[1],start:+s[2]+ +(s[3]??0)};let e=v.exec(t)??I.exec(t);return e?{name:t.slice(0,e.index),start:+e[1]}:{name:t,start:0}}function Q(t,s){let e=[],n=new d;for(let r of t){let a=u(r.name),h=n.pathOf(r.name,a),o=r.start;for(let i of r.steps)n.addAt(n.declare(i.id),h,o,i.strand==="-"),o+=s(i.id);e.push({name:r.name,sample:a,start:r.start,length:o-r.start})}return{anchorPaths:e,pathVisits:n.build()}}function P(t,s){return t.find(n=>n.sample===s||n.name===s)??t[0]}var R=1;function N(t,s,e,n){let r=s.slot(t.name);if(r<0||s.offsets[r]===s.offsets[r+1])return t;let a=s.firstBy(r,e),h=a>=0?a:s.firstByName(r);return{...t,stable:{refName:s.paths[s.path[h]],start:s.start[h],rank:a>=0?l:R,strand:s.strand(h)},samples:n(r)}}function O(t){let s=[...new Set(t.samples)].sort(),e=new Map(s.map((h,o)=>[h,o])),n=Int32Array.from(t.samples,h=>e.get(h)),r=new Uint8Array(s.length),a=new Int32Array(s.length);return h=>{let o=0;for(let f=t.offsets[h];f<t.offsets[h+1];f++){let c=n[t.path[f]];r[c]===0&&(r[c]=1,a[o++]=c)}let i;if(o===s.length)i=s,r.fill(0);else if(o*8<s.length){let f=a.subarray(0,o);f.forEach(c=>r[c]=0),i=Array.from(f.sort(),c=>s[c])}else{i=[];for(let f=0;f<s.length;f++)r[f]===1&&(r[f]=0,i.push(s[f]))}return i}}function k(t,s){let{anchorPaths:e,pathVisits:n}=t,r=e&&n?P(e,s):void 0;if(!r||!e||!n)return t;let a=O(n),h=n.pathIndex(r.name);return{...t,nodes:t.nodes.map(o=>N(o,n,h,a)),anchoredBy:"paths",referencePath:r.name}}function Y(t,s){if(t.anchoredBy!=="tags")return k(t,s);let e=B(t);return e?{...t,referencePath:e}:t}function B(t){let s=t.nodes.find(e=>e.stable?.rank===0)?.stable?.refName;return s!==void 0&&t.anchorPaths?.some(e=>e.name===s)?s:void 0}function Z(t,s){if(!t.anchorPaths)return;let e=new Map(t.nodes.map(a=>[a.id,a.length])),n=(a,h=a.length)=>{let o=0;for(let i=0;i<h;i++)o+=e.get(a[i])??0;return o},r=m(t.paths??[],a=>E(a.name).name);return t.anchorPaths.map(a=>{let h=r.get(a.name),o=h?.length===1?h[0]:void 0,i=o&&s.get(o.name);return o&&i?{...a,start:a.start+n(o.nodeIds,i.first),length:n(i.nodeIds)}:a})}function tt(t){let{pathVisits:s}=t,e=new Map;return n=>{let r=e.get(n.id);if(!r){r=[];let a=s?s.slot(n.name):-1,h=a>=0?s.pathIndex(n.stable.refName):-1;if(h>=0)for(let o=s.offsets[a];o<s.offsets[a+1];o++)s.path[o]===h&&r.push(s.start[o]);r.length<2&&(r=[n.stable.start]),e.set(n.id,r)}return r}}export{b as a,S as b,m as c,g as d,l as e,_ as f,w as g,G as h,U as i,C as j,K as k,T as l,y as m,$ as n,A as o,p,d as q,E as r,Q as s,P as t,k as u,Y as v,Z as w,tt as x};
|
|
2
|
+
//# sourceMappingURL=chunk-MNFL7BAC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../node_modules/.pnpm/@jbrowse+bandage-core@12.
|
|
3
|
+
"sources": ["../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-BSOZW3FC.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-HOAIOEI7.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-RJWPJCIB.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-BEUTROKU.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@12.2.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-BRH73RCH.js"],
|
|
4
4
|
"sourcesContent": ["// src/util/groups.ts\nfunction pushTo(map, key, value) {\n const list = map.get(key);\n if (list) {\n list.push(value);\n } else {\n map.set(key, [value]);\n }\n}\nfunction addTo(map, key, value) {\n const set = map.get(key);\n if (set) {\n set.add(value);\n } else {\n map.set(key, /* @__PURE__ */ new Set([value]));\n }\n}\nfunction groupBy(items, keyOf) {\n const groups = /* @__PURE__ */ new Map();\n for (const item of items) {\n pushTo(groups, keyOf(item), item);\n }\n return groups;\n}\n\nexport {\n pushTo,\n addTo,\n groupBy\n};\n", "// src/util/partitionPoint.ts\nfunction partitionPoint(n, pred) {\n let lo = 0;\n let hi = n;\n while (lo < hi) {\n const mid = lo + hi >> 1;\n if (pred(mid)) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return lo;\n}\n\nexport {\n partitionPoint\n};\n", "import {\n partitionPoint\n} from \"./chunk-HOAIOEI7.js\";\n\n// src/anchoredNodes.ts\nvar REFERENCE_RANK = 0;\nfunction isAnchored(node) {\n return node.stable !== void 0;\n}\nfunction isBackbone(node) {\n return node.stable?.rank === REFERENCE_RANK;\n}\nfunction isOffReference(node) {\n return node.stable !== void 0 && node.stable.rank > REFERENCE_RANK;\n}\nfunction backboneNodes(graph) {\n return graph.nodes.filter(isBackbone);\n}\nfunction overlapsWindow(node, window) {\n return node.stable.start < window.end && node.stable.start + node.length > window.start;\n}\nfunction backbonePositions(backbone) {\n const positions = {};\n for (const node of backbone) {\n positions[node.id] = [\n { x: node.stable.start, y: 0 },\n { x: node.stable.start + node.length, y: 0 }\n ];\n }\n return positions;\n}\nfunction firstNodeAtOrAfter(nodes, bp) {\n return partitionPoint(nodes.length, (i) => nodes[i].stable.start < bp);\n}\nfunction backboneSpan(backbone) {\n let min = Infinity;\n let max = -Infinity;\n for (const node of backbone) {\n min = Math.min(min, node.stable.start);\n max = Math.max(max, node.stable.start + node.length);\n }\n return max - min;\n}\nfunction referenceSpan(backbone, region) {\n return region && region.end > region.start ? region.end - region.start : backboneSpan(backbone);\n}\n\nexport {\n REFERENCE_RANK,\n isAnchored,\n isBackbone,\n isOffReference,\n backboneNodes,\n overlapsWindow,\n backbonePositions,\n firstNodeAtOrAfter,\n backboneSpan,\n referenceSpan\n};\n", "// src/pathVisits.ts\nvar PathVisits = class {\n constructor(columns) {\n this.segments = columns.segments;\n this.offsets = columns.offsets;\n this.path = columns.path;\n this.start = columns.start;\n this.reversed = columns.reversed;\n this.paths = columns.paths;\n this.samples = columns.samples;\n this.slots = new Map(this.segments.map((s, i) => [s, i]));\n }\n static from(entries) {\n const builder = new PathVisitsBuilder();\n for (const [segment, visits] of entries) {\n builder.declare(segment);\n for (const v of visits) {\n builder.add(segment, v.path, v.sample, v.start, v.strand === \"-\");\n }\n }\n return builder.build();\n }\n get size() {\n return this.segments.length;\n }\n // the segment's index into `segments` and `offsets`, -1 when unvisited\n slot(segment) {\n return this.slots.get(segment) ?? -1;\n }\n pathIndex(path) {\n return this.paths.indexOf(path);\n }\n // the first of `slot`'s visits by path `p`, -1 for none\n firstBy(slot, p) {\n for (let i = this.offsets[slot]; i < this.offsets[slot + 1]; i++) {\n if (this.path[i] === p) {\n return i;\n }\n }\n return -1;\n }\n // the visit of `slot` on the path first in name order, at its lowest offset\n // there: where gfa-to-tabix places a segment the reference doesn't visit, so\n // both place it alike whatever order the file lists its paths in\n firstByName(slot) {\n let best = this.offsets[slot];\n for (let i = best + 1; i < this.offsets[slot + 1]; i++) {\n const a = this.paths[this.path[i]];\n const b = this.paths[this.path[best]];\n if (a < b || a === b && this.start[i] < this.start[best]) {\n best = i;\n }\n }\n return best;\n }\n // Paths' steps replayed in walk order against their visits: the k-th call\n // for one path and segment answers that path's k-th visit there, -1 past\n // its last. A walk in pieces lists its pieces in path order, so replaying\n // the pieces in order reads each step's own visit.\n replay() {\n const cursor = /* @__PURE__ */ new Map();\n return (slot, p) => {\n if (slot < 0 || p < 0) {\n return -1;\n }\n const key = slot * this.paths.length + p;\n const end = this.offsets[slot + 1];\n let at = cursor.get(key) ?? this.offsets[slot];\n while (at < end && this.path[at] !== p) {\n at++;\n }\n cursor.set(key, at + 1);\n return at < end ? at : -1;\n };\n }\n // the visits of paths `keepPath` accepts, at segments `keepSegment` does\n filter(keepPath, keepSegment = () => true) {\n const kept = this.paths.map(keepPath);\n const builder = new PathVisitsBuilder();\n this.segments.forEach((segment, s) => {\n if (!keepSegment(segment)) {\n return;\n }\n const slot = builder.declare(segment);\n for (let i = this.offsets[s]; i < this.offsets[s + 1]; i++) {\n const p = this.path[i];\n if (kept[p]) {\n builder.addAt(\n slot,\n builder.pathOf(this.paths[p], this.samples[p]),\n this.start[i],\n this.reversed[i] === 1\n );\n }\n }\n });\n return builder.build();\n }\n strand(i) {\n return this.reversed[i] ? \"-\" : \"+\";\n }\n visit(i) {\n const p = this.path[i];\n return {\n path: this.paths[p],\n sample: this.samples[p],\n start: this.start[i],\n strand: this.strand(i)\n };\n }\n visitsAt(slot) {\n const out = [];\n for (let i = this.offsets[slot]; i < this.offsets[slot + 1]; i++) {\n out.push(this.visit(i));\n }\n return out;\n }\n get(segment) {\n const slot = this.slot(segment);\n return slot < 0 ? void 0 : this.visitsAt(slot);\n }\n has(segment) {\n return this.slots.has(segment);\n }\n keys() {\n return this.segments[Symbol.iterator]();\n }\n *values() {\n for (let s = 0; s < this.segments.length; s++) {\n yield this.visitsAt(s);\n }\n }\n *entries() {\n for (let s = 0; s < this.segments.length; s++) {\n yield [this.segments[s], this.visitsAt(s)];\n }\n }\n [Symbol.iterator]() {\n return this.entries();\n }\n};\nvar Column = class {\n constructor(data) {\n this.data = data;\n this.length = 0;\n }\n push(value) {\n if (this.length === this.data.length) {\n const grown = new this.data.constructor(\n this.data.length * 2\n );\n grown.set(this.data);\n this.data = grown;\n }\n this.data[this.length++] = value;\n }\n};\nvar PathVisitsBuilder = class {\n constructor() {\n this.segments = [];\n this.slots = /* @__PURE__ */ new Map();\n this.paths = [];\n this.samples = [];\n this.pathIndex = /* @__PURE__ */ new Map();\n this.slot = new Column(new Int32Array(1024));\n this.path = new Column(new Int32Array(1024));\n this.start = new Column(new Float64Array(1024));\n this.reversed = new Column(new Uint8Array(1024));\n }\n // a segment's place in iteration order, though it has no visits yet\n declare(segment) {\n let s = this.slots.get(segment);\n if (s === void 0) {\n s = this.segments.length;\n this.slots.set(segment, s);\n this.segments.push(segment);\n }\n return s;\n }\n // a path's index, so a caller adding many of its visits names it once\n pathOf(path, sample) {\n let p = this.pathIndex.get(path);\n if (p === void 0) {\n p = this.paths.length;\n this.pathIndex.set(path, p);\n this.paths.push(path);\n this.samples.push(sample);\n }\n return p;\n }\n add(segment, path, sample, start, reversed) {\n this.addAt(\n this.declare(segment),\n this.pathOf(path, sample),\n start,\n reversed\n );\n }\n addAt(slot, path, start, reversed) {\n this.slot.push(slot);\n this.path.push(path);\n this.start.push(start);\n this.reversed.push(reversed ? 1 : 0);\n }\n build() {\n const n = this.slot.length;\n const segments = this.segments.length;\n const offsets = new Int32Array(segments + 1);\n const slot = this.slot.data;\n for (let i = 0; i < n; i++) {\n offsets[slot[i] + 1]++;\n }\n for (let s = 0; s < segments; s++) {\n offsets[s + 1] += offsets[s];\n }\n const fill = offsets.slice(0, segments);\n const path = new Int32Array(n);\n const start = new Float64Array(n);\n const reversed = new Uint8Array(n);\n for (let i = 0; i < n; i++) {\n const at = fill[slot[i]]++;\n path[at] = this.path.data[i];\n start[at] = this.start.data[i];\n reversed[at] = this.reversed.data[i];\n }\n return new PathVisits({\n segments: this.segments,\n offsets,\n path,\n start,\n reversed,\n paths: this.paths,\n samples: this.samples\n });\n }\n};\n\nexport {\n PathVisits,\n Column,\n PathVisitsBuilder\n};\n", "import {\n PathVisitsBuilder\n} from \"./chunk-BEUTROKU.js\";\nimport {\n groupBy\n} from \"./chunk-BSOZW3FC.js\";\nimport {\n REFERENCE_RANK\n} from \"./chunk-RJWPJCIB.js\";\nimport {\n panSNSample\n} from \"./chunk-2JL2JVZ2.js\";\n\n// src/pathAnchoring.ts\nvar RANGE_SUFFIX = /:(\\d+)-\\d+$/;\nvar VG_FRAGMENT = /^([^#]*#[^#]*#[^#[]*)#(\\d+)(?:\\[(\\d+)-\\d+\\])?$/;\nvar VG_SUBRANGE = /\\[(\\d+)-\\d+\\]$/;\nfunction pathOrigin(pathName) {\n const fragment = VG_FRAGMENT.exec(pathName);\n if (fragment) {\n return { name: fragment[1], start: +fragment[2] + +(fragment[3] ?? 0) };\n }\n const match = RANGE_SUFFIX.exec(pathName) ?? VG_SUBRANGE.exec(pathName);\n return match ? { name: pathName.slice(0, match.index), start: +match[1] } : { name: pathName, start: 0 };\n}\nfunction surveyPaths(paths, lengthOf) {\n const anchorPaths = [];\n const visits = new PathVisitsBuilder();\n for (const path of paths) {\n const sample = panSNSample(path.name);\n const p = visits.pathOf(path.name, sample);\n let pos = path.start;\n for (const step of path.steps) {\n visits.addAt(visits.declare(step.id), p, pos, step.strand === \"-\");\n pos += lengthOf(step.id);\n }\n anchorPaths.push({\n name: path.name,\n sample,\n start: path.start,\n length: pos - path.start\n });\n }\n return { anchorPaths, pathVisits: visits.build() };\n}\nfunction chooseReferencePath(anchorPaths, preferred) {\n const named = anchorPaths.find(\n (p) => p.sample === preferred || p.name === preferred\n );\n return named ?? anchorPaths[0];\n}\nvar OFF_REFERENCE_RANK = 1;\nfunction anchorNode(node, visits, reference, samplesOf) {\n const slot = visits.slot(node.name);\n if (slot < 0 || visits.offsets[slot] === visits.offsets[slot + 1]) {\n return node;\n }\n const own = visits.firstBy(slot, reference);\n const anchor = own >= 0 ? own : visits.firstByName(slot);\n return {\n ...node,\n stable: {\n refName: visits.paths[visits.path[anchor]],\n start: visits.start[anchor],\n rank: own >= 0 ? REFERENCE_RANK : OFF_REFERENCE_RANK,\n strand: visits.strand(anchor)\n },\n samples: samplesOf(slot)\n };\n}\nfunction sampleSorter(visits) {\n const sorted = [...new Set(visits.samples)].sort();\n const rank = new Map(sorted.map((sample, i) => [sample, i]));\n const pathRank = Int32Array.from(visits.samples, (s) => rank.get(s));\n const seen = new Uint8Array(sorted.length);\n const ranks = new Int32Array(sorted.length);\n return (slot) => {\n let n = 0;\n for (let i = visits.offsets[slot]; i < visits.offsets[slot + 1]; i++) {\n const r = pathRank[visits.path[i]];\n if (seen[r] === 0) {\n seen[r] = 1;\n ranks[n++] = r;\n }\n }\n let out;\n if (n === sorted.length) {\n out = sorted;\n seen.fill(0);\n } else if (n * 8 < sorted.length) {\n const found = ranks.subarray(0, n);\n found.forEach((r) => seen[r] = 0);\n out = Array.from(found.sort(), (r) => sorted[r]);\n } else {\n out = [];\n for (let r = 0; r < sorted.length; r++) {\n if (seen[r] === 1) {\n seen[r] = 0;\n out.push(sorted[r]);\n }\n }\n }\n return out;\n };\n}\nfunction anchorFromPaths(graph, preferred) {\n const { anchorPaths, pathVisits } = graph;\n const reference = anchorPaths && pathVisits ? chooseReferencePath(anchorPaths, preferred) : void 0;\n if (!reference || !anchorPaths || !pathVisits) {\n return graph;\n }\n const samplesOf = sampleSorter(pathVisits);\n const referenceIndex = pathVisits.pathIndex(reference.name);\n return {\n ...graph,\n nodes: graph.nodes.map(\n (node) => anchorNode(node, pathVisits, referenceIndex, samplesOf)\n ),\n anchoredBy: \"paths\",\n referencePath: reference.name\n };\n}\nfunction anchorGraph(graph, preferred) {\n if (graph.anchoredBy !== \"tags\") {\n return anchorFromPaths(graph, preferred);\n }\n const referencePath = taggedReferencePath(graph);\n return referencePath ? { ...graph, referencePath } : graph;\n}\nfunction taggedReferencePath(graph) {\n const refName = graph.nodes.find((n) => n.stable?.rank === 0)?.stable?.refName;\n return refName !== void 0 && graph.anchorPaths?.some((p) => p.name === refName) ? refName : void 0;\n}\nfunction trimOrigins(graph, kept) {\n if (!graph.anchorPaths) {\n return void 0;\n }\n const lengthOf = new Map(graph.nodes.map((n) => [n.id, n.length]));\n const bp = (ids, end = ids.length) => {\n let sum = 0;\n for (let i = 0; i < end; i++) {\n sum += lengthOf.get(ids[i]) ?? 0;\n }\n return sum;\n };\n const byOrigin = groupBy(graph.paths ?? [], (p) => pathOrigin(p.name).name);\n return graph.anchorPaths.map((o) => {\n const pieces = byOrigin.get(o.name);\n const path = pieces?.length === 1 ? pieces[0] : void 0;\n const stretch = path && kept.get(path.name);\n return path && stretch ? {\n ...o,\n start: o.start + bp(path.nodeIds, stretch.first),\n length: bp(stretch.nodeIds)\n } : o;\n });\n}\nfunction referenceVisitStarts(graph) {\n const { pathVisits } = graph;\n const cache = /* @__PURE__ */ new Map();\n return (node) => {\n let starts = cache.get(node.id);\n if (!starts) {\n starts = [];\n const slot = pathVisits ? pathVisits.slot(node.name) : -1;\n const p = slot >= 0 ? pathVisits.pathIndex(node.stable.refName) : -1;\n if (p >= 0) {\n for (let i = pathVisits.offsets[slot]; i < pathVisits.offsets[slot + 1]; i++) {\n if (pathVisits.path[i] === p) {\n starts.push(pathVisits.start[i]);\n }\n }\n }\n if (starts.length < 2) {\n starts = [node.stable.start];\n }\n cache.set(node.id, starts);\n }\n return starts;\n };\n}\n\nexport {\n pathOrigin,\n surveyPaths,\n chooseReferencePath,\n anchorFromPaths,\n anchorGraph,\n trimOrigins,\n referenceVisitStarts\n};\n"],
|
|
5
5
|
"mappings": "wCACA,SAASA,EAAOC,EAAKC,EAAKC,EAAO,CAC/B,IAAMC,EAAOH,EAAI,IAAIC,CAAG,EACpBE,EACFA,EAAK,KAAKD,CAAK,E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M,CAC3B,CACA,OAAOA,CACT,CACF",
|
|
6
6
|
"names": ["pushTo", "map", "key", "value", "list", "addTo", "set", "groupBy", "items", "keyOf", "groups", "item", "partitionPoint", "n", "pred", "lo", "hi", "mid", "REFERENCE_RANK", "isAnchored", "node", "isBackbone", "isOffReference", "backboneNodes", "graph", "overlapsWindow", "window", "backbonePositions", "backbone", "positions", "firstNodeAtOrAfter", "nodes", "bp", "partitionPoint", "i", "backboneSpan", "min", "max", "referenceSpan", "region", "PathVisits", "columns", "i", "entries", "builder", "PathVisitsBuilder", "segment", "visits", "v", "path", "slot", "p", "best", "a", "b", "cursor", "key", "end", "at", "keepPath", "keepSegment", "kept", "s", "out", "Column", "data", "value", "grown", "sample", "start", "reversed", "n", "segments", "offsets", "fill", "RANGE_SUFFIX", "VG_FRAGMENT", "VG_SUBRANGE", "pathOrigin", "pathName", "fragment", "match", "surveyPaths", "paths", "lengthOf", "anchorPaths", "visits", "PathVisitsBuilder", "path", "sample", "panSNSample", "p", "pos", "step", "chooseReferencePath", "preferred", "OFF_REFERENCE_RANK", "anchorNode", "node", "reference", "samplesOf", "slot", "own", "anchor", "REFERENCE_RANK", "sampleSorter", "sorted", "rank", "i", "pathRank", "s", "seen", "ranks", "n", "r", "out", "found", "anchorFromPaths", "graph", "pathVisits", "referenceIndex", "anchorGraph", "referencePath", "taggedReferencePath", "refName", "trimOrigins", "kept", "bp", "ids", "end", "sum", "byOrigin", "groupBy", "o", "pieces", "stretch", "referenceVisitStarts", "cache", "starts"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ce,b as N,c as Ee,d as Q,e as ee,f as Ft,g as Ue,h as We,i as qt,j as zt,k as He,l as Oe,m as Pe,n as Dt,o as jt,p as Ut,q as Wt,r as Vt}from"./chunk-M2D7NUOY.js";import{a as _t,g as Tt}from"./chunk-OGXVDZPS.js";import{c as Ot}from"./chunk-IK3MQ4ZJ.js";import{a as Ct,g as Bt}from"./chunk-VKZALU57.js";var Ln=4096;function pt(a){let e=[];for(let t of a){let n=e[e.length-1];n&&t-n[1]<=Ln?n[1]=t:e.push([t,t])}return e}var Hn=32768,Gt={mostChosenPaths:32},lt=class{byNode=new Map;get(e){return this.byNode.get(e.node)?.get(e.offset)}set(e,t){let n=this.byNode.get(e.node);n||(n=new Map,this.byNode.set(e.node,n)),n.set(e.offset,t)}},re=class extends Error{};function Ve(a,e,t,n){return a==="forward"?e+t:e-n}function Qt(a,e,t,n){return a==="forward"?e-n:e+t}function Kt(a){return Pe(ee(a.handles[a.handles.length-1]),ee(a.handles[0]))}function Ce(a){return`${a.pathHandle}:${a.hapStart}:${a.hapEnd}`}async function Zt(a){let{db:e,records:t,signal:n}=a,s=performance.now(),o=()=>{let w=performance.now(),S=w-s;return s=w,S},r={spacing:await e.haplotypeAnchorSpacing(),anchors:void 0,anchorsRead:0,chosenPaths:0,scans:[],scanRows:0,strays:void 0,pieces:0,sources:{reference:0,section:0,stray:0,chain:0,twin:0},walks:{},twins:{tried:0,found:0},graphFetches:0,fallback:void 0,ms:{scan:0,walks:0,check:0,twins:0}},i=(w,S)=>{let A=`${w}: ${S}`;r.walks[A]=(r.walks[A]??0)+1},h=await e.haplotypeSampleInterval()??4096,c=new Map,d=async w=>{let S=t.get(w)??c.get(w);if(S)return S;let A=await e.getRecord(w);if(r.graphFetches+=1,!A)throw new Error(`Node record ${w} is missing from the database`);return c.set(w,A),A},f=w=>t.get(w).sequenceLen,p=await e.pathsByHandle(),y=w=>{let S=p.get(w);return S!==void 0&&a.keep(S.name)},g=[],l=new lt,b=new Map,x=new Set,P=new Set,E=async w=>{let S=(await d(w.node)).gbwt().lf(w.offset);return S===void 0||S.node===0?void 0:S},R=async(w,S)=>{let A=(await d(ee(w.node))).gbwt().predecessorAt(w.offset);if(A===void 0||S!==void 0&&!S.has(A))return;let M=(await d(A)).gbwt().offsetTo(w);if(M===void 0)throw new Error(`No offset in ${A} leads to ${w.node}:${w.offset}`);return{node:A,offset:M}},m=(w,S,A,M)=>{let B=A.map(W=>W.pos.node),U=A.map(W=>W.pos.offset),J=0;for(let W of B)J+=f(W);let O=S==="forward"?A[0].left:A[A.length-1].left,L=g.length;g.push({pathHandle:w,orientation:S,handles:B,offsets:U,len:J,hapStart:O,hapEnd:O+J,canonical:Pe(B[0],B[B.length-1]),source:M});for(let W of A)l.set(W.pos,L);let G=b.get(w);return G?G.push(L):b.set(w,[L]),L},I=async(w,S,A,M)=>{let B=[],U=w;for(;;){n?.throwIfAborted();let O=await R(U.pos,t);if(!O)break;U={pos:O,left:Qt(A,U.left,f(U.pos.node),f(O.node))},B.push(U)}B.reverse();let J=[w];for(U=w;;){n?.throwIfAborted();let O=await E(U.pos);if(!O||!t.has(O.node))break;U={pos:O,left:Ve(A,U.left,f(U.pos.node),f(O.node))},J.push(U)}return m(S,A,[...B,...J],M)},$=async(w,S,A,M)=>g[l.get(w.pos)??await I(w,S,A,M)],F=w=>{let S=w.handles[w.handles.length-1];return{pos:{node:S,offset:w.offsets[w.offsets.length-1]},left:w.orientation==="forward"?w.hapEnd-f(S):w.hapStart}},_=w=>{let S=w.handles[0];return{pos:{node:S,offset:w.offsets[0]},left:w.orientation==="forward"?w.hapStart:w.hapEnd-f(S)}},D=await I({pos:a.referencePos,left:a.referenceLeft},a.referenceHandle,"forward","reference"),C=g[D],H=()=>{if(r.fallback!==void 0)return{reference:C,pieces:[],stats:r};let w=new Map;g.forEach((A,M)=>{M!==D&&w.set(Ce(A),[...w.get(Ce(A))??[],A])});let S=[];for(let A of w.values()){let M=new Set;for(let B of A)B.canonical&&!M.has(B.orientation)&&(M.add(B.orientation),S.push(B),r.sources[B.source]+=1)}return r.sources.reference=1,r.pieces=S.length+1,{reference:C,pieces:S,stats:r}},k=async(w,S)=>{let A=S?x:P,M=S?P:x,B=w;for(;;){if(A.has(B))return;A.add(B);let U=g[B],J=S?F(U):_(U),O=0,L;for(;L===void 0;){n?.throwIfAborted();let G=S?await E(J.pos):await R(J.pos);if(!G){L="endmarker";break}let W=(await d(J.pos.node)).sequenceLen,ue=(await d(G.node)).sequenceLen,se=S?Ve(U.orientation,J.left,W,ue):Qt(U.orientation,J.left,W,ue);if(t.has(G.node)){let Y=l.get(G);Y===void 0?(B=await I({pos:G,left:se},U.pathHandle,U.orientation,"chain"),M.add(B),L="landed"):(M.add(Y),L="merge")}else O>Hn?L="bound":(O+=ue,J={pos:G,left:se})}if(i("chain",L),L!=="landed")return}},j=async w=>{if(a.context>w.context)throw new re(`the context of ${a.context} bp exceeds the ${w.context} bp the haplotype index's stray rows cover`);let S=r.spacing;if(S===void 0)throw new re("the haplotype index has no anchors");let{bin:A,bound:M}=w,{fills:B,inserted:U}=a.snarls;if(a.snarls.mode==="overlapping"&&B.length>0)throw new re("the haplotype index's stray rows cover contained snarls only");for(let u of B){if(u.inserted>0&&u.low===u.high)throw new re(`the haplotype index's stray rows leave out the snarl bounded by node ${u.low} at both ends`);if(u.inserted>0&&(w.snarlNodes===void 0||u.nodes>w.snarlNodes))throw new re(w.snarlNodes===void 0?"the haplotype index's stray rows leave snarls out":`a snarl of ${u.nodes} nodes exceeds the ${w.snarlNodes} the haplotype index's stray rows cover`)}let J=Math.floor(a.window.start/A),O=Math.floor((a.window.end-1)/A),L=J*A,G=(O+1)*A,W=new Map,ue=async(u,v)=>{let z=await e.haplotypeAnchorsBetween(a.referenceHandle,u*S,v*S);for(let T of z)W.set(T.anchorOffset/S,T)},se=Math.max(0,Math.floor((L-M)/S)-1),Y=Math.ceil((G+M)/S)+1,[{listed:De,strays:ae}]=await Promise.all([e.haplotypeBinData(a.referenceHandle,J,O),ue(se,Y)]);for(let u of t.keys()){let v=N(u);if(!Q(u)&&!De(v)&&!U.has(v))throw new re(`the haplotype index lists node ${v} of the subgraph in no bin that the window touches`)}r.scans=pt([...t.keys()].sort((u,v)=>u-v));let ie=Promise.all(r.scans.map(([u,v])=>e.haplotypeSamplesInRange(u,v)));for(ie.catch(()=>{});se>0&&(W.get(se)?.pathOffset??Number.POSITIVE_INFINITY)>=L-M;)se-=1,await ue(se,se);for(;W.has(Y)&&W.get(Y).pathOffset<=G+M;)Y+=1,await ue(Y,Y);let pe=[...W.keys()].sort((u,v)=>u-v),ye=W.get(pe[0]??-1);if(!ye)throw new re("the haplotype index has no anchors on this path");let he=u=>W.get(u).pathOffset,Ne=new Map;for(let u of pe){let v=N(W.get(u).node);Ne.set(v,[...Ne.get(v)??[],u])}let ct=[...Ne.keys()],Et=ct.map(u=>W.get(Ne.get(u)[0]).visits);if(!Et[ct.indexOf(N(ye.node))].some(u=>u.pathHandle===a.referenceHandle&&u.orientation==="forward"&&u.pathOffset===ye.pathOffset))throw new Error(`The haplotype index has no anchor row for the reference path ${a.referenceHandle} at offset ${ye.pathOffset} (node ${N(ye.node)}); it does not match this graph`);let kt=pe.filter(u=>he(u)<=a.window.start),$n=pe.filter(u=>he(u)>=a.window.end);r.anchors=[he(kt[kt.length-1]??pe[0]),he($n[0]??pe[pe.length-1])],r.anchorsRead=pe.length;let dt=new Map,vt=new Set;if(ct.forEach((u,v)=>{let z=Ne.get(u),T=z.length===1?z[0]:void 0;for(let q of Et[v])vt.add(q.pathHandle),q.orientation==="forward"&&y(q.pathHandle)&&dt.set(q.pathHandle,[...dt.get(q.pathHandle)??[],{k:T,row:q}])}),r.chosenPaths=[...vt].filter(y).length,r.chosenPaths>Gt.mostChosenPaths)throw new re(`${r.chosenPaths} chosen paths pass the anchors, more than ${Gt.mostChosenPaths}`);let je=[],Ie=Number.POSITIVE_INFINITY,be=0;for(let[u,v]of dt){v.sort((z,T)=>z.row.pathOffset-T.row.pathOffset);for(let z=0;z+1<v.length;z++){let T=v[z],q=v[z+1];if(T.k===void 0||q.k===void 0||Math.abs(T.k-q.k)!==1)continue;let[Z,te]=he(T.k)<=he(q.k)?[T,q]:[q,T],ne=he(Z.k),oe=he(te.k);ne<G&&oe>=L?(je.push({pathHandle:u,from:T.row,to:q.row}),Ie=Math.min(Ie,ne-M),be=Math.max(be,oe+M)):ne>=G&&ne-G<=M?(je.push({pathHandle:u,from:Z.row,to:void 0}),Ie=Math.min(Ie,ne-M),be=Math.max(be,ne+M)):oe<L&&L-oe<=M&&(je.push({pathHandle:u,from:te.row,to:void 0}),Ie=Math.min(Ie,oe-M),be=Math.max(be,oe+M))}}let Rn=new Set(B.map(u=>`${u.low}:${u.high}`)),Nn=ae.filter(u=>y(u.pathHandle)&&(u.snarl===void 0||Rn.has(`${u.snarl[0]}:${u.snarl[1]}`))).sort((u,v)=>u.pathHandle-v.pathHandle||u.pathStart-v.pathStart);r.strays={bins:O-J+1,rows:ae.length,walked:0,outsideBp:0},be>0&&await a.prefetchReferenceRange(a.referenceHandle,Math.max(0,Ie),be+1),r.ms.scan=o();let Pt=8*S+2*(a.window.end-a.window.start),At=r.strays,Me=0,$t=u=>{if(At.outsideBp+=u,Me+=u,Me>Pt)throw new re(`a walk of a chosen path near the window went past its cap of ${Pt} bp`)},ft=new Map,Rt=(u,v,z)=>(ft.get(u)??[]).some(([T,q])=>T<=v&&z<q),Nt=(u,v,z)=>{ft.set(u,[...ft.get(u)??[],[v,z]])},Mt=async(u,v,z,T,q)=>{let Z=v,te=z,ne=te;for(;Z&&te<=T;){n?.throwIfAborted();let oe;if(t.has(Z.node)){let Le=await $({pos:Z,left:te},u,"forward",q),Ht=F(Le);Z=Ht.pos,te=Ht.left,oe=f(Z.node),ne=Math.max(ne,Le.hapEnd)}else oe=(await d(Z.node)).sequenceLen,$t(oe),ne=Math.max(ne,te+oe);Z=await E(Z),te+=oe}return ne},Mn=async(u,v,z,T)=>{let q={pos:v,left:z},Z=z;for(;q.left>T;){n?.throwIfAborted();let te=await R(q.pos);if(!te)break;let ne=(await d(te.node)).sequenceLen,oe=q.left-ne;if(t.has(te.node)){let Le=await $({pos:te,left:oe},u,"forward","section");q=_(Le),Z=Math.min(Z,Le.hapStart)}else $t(ne),q={pos:te,left:oe},Z=Math.min(Z,oe)}return Z};for(let{pathHandle:u,from:v,to:z}of je){let T=v.pathOffset,q=(z??v).pathOffset+M;if(Rt(u,T-M,q))continue;let Z={node:v.node,offset:v.offset};Me=0;let te=await Mt(u,Z,T,q,"section");Me=0;let ne=await Mn(u,Z,T,T-M);Nt(u,Math.min(ne,T-M),Math.max(te,q+1)),i(z?"section":"visit",z?"past the far anchor":"bound")}for(let u of Nn){if(Rt(u.pathHandle,u.pathStart,u.pathEnd))continue;Me=0;let v=await Mt(u.pathHandle,{node:u.node,offset:u.offset},u.pathStart,u.pathEnd,"stray");Nt(u.pathHandle,u.pathStart,Math.max(v,u.pathEnd+1)),At.walked+=1}r.ms.walks=o();let Lt=[];for(let u of await ie)for(let v of u)if(r.scanRows+=1,t.has(v.node)&&y(v.pathHandle)){if(!(b.get(v.pathHandle)??[]).some(z=>{let T=g[z];return T.hapStart<=v.pathOffset&&v.pathOffset<T.hapEnd}))throw new re(`chosen path ${v.pathHandle} has a sample at ${v.pathOffset} on the window's nodes that no walk reached`);v.orientation==="reverse"&&Lt.push(v)}for(let u of Lt)await $({pos:{node:u.node,offset:u.offset},left:u.pathOffset},u.pathHandle,"reverse","twin");r.ms.check=o()},X=async()=>{let w=new Map,S=O=>{let L=Ce(O),G=w.get(L);G?G.add(O.orientation):w.set(L,new Set([O.orientation]))},A=0,M=()=>{for(;A<g.length;A++)S(g[A])};M();let B=O=>(w.get(Ce(O))?.size??0)>1,U=2*h,J=(O,L)=>L===D?y(a.referenceHandle)&&Kt(O):!O.canonical||Kt(O);for(let O=0;O<g.length;O++){let L=g[O];if(B(L)||!J(L,O))continue;r.twins.tried+=1;let G=L.orientation==="forward"?"reverse":"forward",W=F(L),ue=0,se;for(;!se&&ue<=U;){n?.throwIfAborted();let ae=await E(W.pos);if(!ae)break;let ie=(await d(ae.node)).sequenceLen,pe=Ve(L.orientation,W.left,(await d(W.pos.node)).sequenceLen,ie),ye=ee(ae.node);se=(await e.haplotypeSamplesInRange(ye,ye)).find(he=>he.pathHandle===L.pathHandle&&he.orientation===G&&he.pathOffset===pe),ue+=ie,W={pos:ae,left:pe}}let Y=se&&{pos:{node:se.node,offset:se.offset},left:se.pathOffset},De=0;for(;Y&&!B(L)&&De<=U+L.len;){if(n?.throwIfAborted(),t.has(Y.pos.node)){let ae=await $(Y,L.pathHandle,G,"twin"),ie=g.indexOf(ae);await k(ie,!0),await k(ie,!1),M(),Y=F(ae)}if(!B(L)){let ae=(await d(Y.pos.node)).sequenceLen;De+=ae;let ie=await E(Y.pos);Y=ie?{pos:ie,left:Ve(G,Y.left,ae,(await d(ie.node)).sequenceLen)}:void 0}}if(M(),!B(L))throw new re(`piece ${Ce(L)} was found in one orientation where extractPaths keeps the other`);r.twins.found+=1}r.ms.twins=o()};try{let w=await e.haplotypeStrayOptions();if(w===void 0)throw new re("the haplotype index has no stray rows; gbz-haplotype-index 0.2.0 writes them");await j(w),await X()}catch(w){if(!(w instanceof re))throw w;r.fallback=w.message}return H()}function Xt(a,e){return a.handles[0]-e.handles[0]||a.offsets[0]-e.offsets[0]}var On=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),we=(a,e)=>a>>>e|a<<32-e;function Jt(a){let e=Math.ceil((a.length+9)/64),t=new Uint8Array(e*64);t.set(a),t[a.length]=128;let n=new DataView(t.buffer),s=a.length*8;n.setUint32(t.length-8,Math.floor(s/2**32)),n.setUint32(t.length-4,s>>>0);let o=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),r=new Uint32Array(64);for(let c=0;c<e;c++){for(let P=0;P<16;P++)r[P]=n.getUint32(c*64+P*4);for(let P=16;P<64;P++){let E=r[P-15],R=r[P-2],m=we(E,7)^we(E,18)^E>>>3,I=we(R,17)^we(R,19)^R>>>10;r[P]=r[P-16]+m+r[P-7]+I}let d=o[0],f=o[1],p=o[2],y=o[3],g=o[4],l=o[5],b=o[6],x=o[7];for(let P=0;P<64;P++){let E=we(g,6)^we(g,11)^we(g,25),R=g&l^~g&b,m=x+E+R+On[P]+r[P]|0,I=we(d,2)^we(d,13)^we(d,22),$=d&f^d&p^f&p;x=b,b=l,l=g,g=y+m|0,y=p,p=f,f=d,d=m+I+$|0}[d,f,p,y,g,l,b,x].forEach((P,E)=>{o[E]=o[E]+P})}let i=new Uint8Array(32),h=new DataView(i.buffer);for(let c=0;c<8;c++)h.setUint32(c*4,o[c]);return i}function Yt(a,e){let t=new Map;if(a!==void 0)for(let n of a.split(";")){let s=n.split(","),[o,r]=s;if(s.length!==2||!o||!r)throw new Error(`Invalid ${e} relationship: ${n}`);let i=t.get(o);i||(i=new Set,t.set(o,i)),i.add(r)}return t}function nn(a){return{name:a.get("pggname"),subgraph:Yt(a.get("subgraph"),"subgraph"),translation:Yt(a.get("translation"),"translation")}}function en(a,e){for(let[t,n]of e){let s=a.get(t);s||(s=new Set,a.set(t,s));for(let o of n)s.add(o)}}function sn(a,e){let t={name:a,subgraph:new Map,translation:new Map};return e.name!==void 0&&(t.subgraph.set(a,new Set([e.name])),en(t.subgraph,e.subgraph),en(t.translation,e.translation)),t}function tn(a){return[...a.entries()].sort(([e],[t])=>e<t?-1:e>t?1:0).flatMap(([e,t])=>[...t].sort().map(n=>[e,n]))}function on(a){let e=[];a.name!==void 0&&e.push(`H NM:Z:${a.name}`);for(let[t,n]of tn(a.subgraph))e.push(`H SG:Z:${t},${n}`);for(let[t,n]of tn(a.translation))e.push(`H TL:Z:${t},${n}`);return e}async function rn(a){let e=a.reduce((r,i)=>r+i.length,0),t=new Uint8Array(e),n=0;for(let r of a)t.set(r,n),n+=r.length;let s=globalThis.crypto?.subtle;return[...s?new Uint8Array(await s.digest("SHA-256",t)):Jt(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}var Cn="_gbwt_ref";function fe(a){let e=`${a.sample}#${a.haplotype}#${a.contig}`;return a.end===void 0?e:`${e}[${a.fragment}-${a.end}]`}var Bn=/^([^#]+)#(\d+)#([^#]+?)(?:\[\d+-\d+\])?$/,_n=/^([^#]+?)(?:\[\d+-\d+\])?$/;function Tn(a){let e=Bn.exec(a);if(e)return{sample:e[1],haplotype:Number(e[2]),contig:e[3]};let t=_n.exec(a);if(t)return{contig:t[1]};throw new Error(`"${a}" is not a path name; expected "sample#haplotype#contig" or a bare contig`)}function Ae(a){return typeof a=="string"?Tn(a):a}function $e(a,e){return{sample:a.sample??Cn,contig:a.contig,haplotype:a.haplotype??0,fragment:e}}var le=class extends Error{name="SubgraphLimitError";limit;windowBp;walkedBp;constructor(e,t){super(t===void 0?`Subgraph size limit of ${e} nodes exceeded`:`Subgraph size limit of ${e} nodes exceeded ${t.walkedBp} bp into a ${t.windowBp} bp window`),this.limit=e,this.windowBp=t?.windowBp,this.walkedBp=t?.walkedBp}};function ut(a,e){return a[0]<e[0]||a[0]===e[0]&&(a[1]<e[1]||a[1]===e[1]&&a[2]<e[2])}var _e=class{heap=[];push(e,t,n){let s=this.heap;s.push([e,t,n]);let o=s.length-1;for(;o>0;){let r=o-1>>1;if(ut(s[o],s[r]))[s[o],s[r]]=[s[r],s[o]],o=r;else break}}pop(){let e=this.heap,t=e[0],n=e.pop();if(e.length>0&&n!==void 0){e[0]=n;let s=0;for(;;){let o=2*s+1,r=o+1,i=s;if(o<e.length&&ut(e[o],e[i])&&(i=o),r<e.length&&ut(e[r],e[i])&&(i=r),i===s)break;[e[s],e[i]]=[e[i],e[s]],s=i}}return t}get size(){return this.heap.length}};function Fn(a){let e=new Int32Array(a.length),t=new Int32Array(a.length);return a.forEach(([n,s],o)=>{e[o]=n,t[o]=s}),{pathAt:e,refAt:t,count:a.length}}function qn(a,e){let t=0,n=a.length;for(;t<n;){let s=t+n>>1;a[s]>e?n=s:t=s+1}return a[t]}function ke(a){return`${a.node}:${a.offset}`}function Be(a){return a.map(e=>ee(e)).reverse()}function zn(a,e){let t=e.identity.hapStart-a.identity.hapEnd,n=a.strand==="+"?e.refStart-a.refEnd:a.refStart-e.refEnd;return a.strand===e.strand&&t>=0&&n>=0?{insertion:t,deletion:n}:void 0}function Dn(a,e,t){let[n,s]=a.strand==="+"?[a,e]:[e,a],o=n.edits.map(([c,d])=>[c,d]);hn(o,t.insertion,t.deletion);for(let[c,d]of s.edits)K(o,c,d);let r=a.identity.walkForward,[i,h]=r?[a,e]:[e,a];return{strand:a.strand,refStart:n.refStart,refEnd:s.refEnd,edits:o,weight:void 0,path:[...i.path,...h.path],start:i.start,pieces:[...i.pieces,...h.pieces],soloAligned:[...i.soloAligned,...h.soloAligned],identity:{pathHandle:a.identity.pathHandle,name:a.identity.name,hapStart:a.identity.hapStart,hapEnd:e.identity.hapEnd,walkForward:r}}}function jn(a,e,t){if(a.some(r=>r.weight!==void 0))return a;let n=new Map;a.forEach((r,i)=>{if(r.identity){let h=n.get(r.identity.pathHandle);h?h.push(i):n.set(r.identity.pathHandle,[i])}});let s=new Map,o=new Set;for(let r of n.values()){r.sort((d,f)=>a[d].identity.hapStart-a[f].identity.hapStart);let i=r[0],h=a[i],c=[];for(let d of r.slice(1)){let f=a[d],p=c.length===0?zn(h,f):void 0;if(p){h=Dn(h,f,p),o.add(d);continue}if(!e(f)){c.push(d);continue}let y=e(h)?t([h,...c.map(g=>a[g]),f]):void 0;if(y){h=y;for(let g of[...c,d])o.add(g)}else s.set(i,h),i=d,h=f;c=[]}s.set(i,h)}return a.flatMap((r,i)=>o.has(i)?[]:[s.get(i)??r])}function Ge(a,e){return{node:a.path[e],offset:a.offsets[e]}}var Un=32768;function Wn(a){let e=[...a].sort((n,s)=>n-s),t=[];for(let n of e){let s=t[t.length-1];s&&n-s[1]<=Un?s[1]=n:t.push([n,n])}return t}var Te=class a{records=new Map;paths=[];twinStarts=new Set;twinDeferred=!1;unsettled;refId;refPath;refHandle;refInterval;refIndexCache;refPrefixCache;walkedBp;snarlMode="none";snarlFills=[];snarlNodes=new Set;stats={orderedAlignments:0,lcsAlignments:0,snarls:{fills:0,inserted:0},identificationSteps:0,identificationFetches:0,identification:{interval:0,scans:[],windowSamples:0,fragmentLengths:[],companionSeeks:0,companionMisses:0,graphLookups:0,graphFetches:0,chains:[]},keep:void 0};db;limit;signal;constructor(e,t){this.db=e,this.limit=t.limit,this.signal=t.signal}static create(e,t={}){return new a(e,t)}get nodeCount(){return this.records.size/2}get pathCount(){return this.settleDeferred(),this.paths.length}get referenceInterval(){return this.refInterval&&this.refPath?{name:this.refPath,start:this.refPath.fragment+this.refInterval[0],end:this.refPath.fragment+this.refInterval[1]}:void 0}hasNode(e){return this.records.has(ce(e,"forward"))}hasHandle(e){return this.records.has(e)}record(e){let t=this.records.get(e);if(!t)throw new Error(`Subgraph has no record for handle ${e}`);return t}sortedHandles(){return[...this.records.keys()].sort((e,t)=>e-t)}async addNode(e){if(this.signal?.throwIfAborted(),this.limit!==void 0&&this.nodeCount>=this.limit)throw new le(this.limit);let t=await this.db.getRecord(ce(e,"forward")),n=await this.db.getRecord(ce(e,"reverse"));if(!t||!n)throw new Error(`Node ${e} does not exist in the graph`);this.records.set(t.handle,t),this.records.set(n.handle,n)}async ensureNode(e){this.hasNode(e)||await this.addNode(e)}clearPaths(){this.paths=[],this.twinStarts.clear(),this.twinDeferred=!1,this.unsettled=void 0,this.refId=void 0,this.refPath=void 0,this.refHandle=void 0,this.refInterval=void 0,this.refIndexCache=void 0,this.refPrefixCache=void 0}async pathPosition(e){let t=await this.db.findPath(e);if(!t)throw new Error(`Cannot find a path covering offset ${e.fragment} of ${fe(e)}`);if(!t.isIndexed)throw new Error(`The fragment of ${fe(t.name)} at ${t.name.fragment} has not been indexed for random access`);let n=e.fragment-t.name.fragment,s=await this.db.indexedPosition(t.handle,n);if(!s)throw new Error(`The fragment of ${fe(t.name)} at ${t.name.fragment} has not been indexed for random access`);return this.findPathPosition(t,n,s.pathOffset,s.pos)}async findPathPosition(e,t,n,s){let o=n,r=s;for(;;){await this.ensureNode(N(r.node));let i=this.record(r.node);if(o+i.sequenceLen>t)return{position:{seqOffset:t,handle:r.node,nodeOffset:t-o,gbwtOffset:r.offset},name:e.name,handle:e.handle};o+=i.sequenceLen;let h=i.gbwt().lf(r.offset);if(!h)throw new Error(`The fragment of ${fe(e.name)} at ${e.name.fragment} does not contain offset ${t}`);r=h}}async aroundPosition(e,t,n){let s=N(e);await this.ensureNode(s);let o=this.record(e),r=Ee(e),i=new _e;return i.push(t,s,Ue(r)),i.push(o.sequenceLen-t-1,s,We(r)),this.insertContext(i,n)}prefetchReferenceWalk(e,t){return this.prefetchReferenceRange(e.handle,e.position.seqOffset,e.position.seqOffset+t)}async prefetchReferenceRange(e,t,n){let[s,o]=await Promise.all([this.db.indexedPosition(e,t),this.db.indexedPosition(e,n)]);if(s&&o){let r=s.pos.node,i=o.pos.node;if(!await this.db.prefetchRecords([[Math.min(r,i),Math.max(r,i)+1]])){let c=await this.db.indexedPositionsBetween(e,t,n);await this.db.prefetchRecords(Wn(c.map(d=>d.pos.node)).map(([d,f])=>[d,f+2]),!0)}}return s}async aroundInterval(e,t,n){if(!(t>0))throw new Error("Interval length must be greater than 0");this.walkedBp=0;try{return await this.walkInterval(e,t,n)}catch(s){throw s instanceof le&&s.windowBp===void 0?new le(s.limit,{windowBp:t,walkedBp:this.walkedBp}):s}}get referenceWalkedBp(){return this.walkedBp}async walkInterval(e,t,n){let s={node:e.handle,offset:e.gbwtOffset},o=e.nodeOffset,r=t,i=new _e;for(;;){let h=N(s.node),c=Ee(s.node);this.walkedBp=t-r,await this.ensureNode(h);let d=this.record(s.node);if(o>=d.sequenceLen)throw new Error(`Offset ${o} in node ${h} of length ${d.sequenceLen}`);i.push(o,h,Ue(c));let f=d.sequenceLen-o;if(r<=f){i.push(r===f?0:f-r-1,h,We(c));break}i.push(0,h,We(c));let p=d.gbwt().lf(s.offset);if(!p)throw new Error(`No successor for GBWT position (${s.node}, ${s.offset})`);s=p,o=0,r-=f}return this.walkedBp=t,this.insertContext(i,n)}async aroundNodes(e,t){let n=new _e;for(let s of e)await this.ensureNode(s),n.push(0,s,"left"),n.push(0,s,"right");return this.insertContext(n,t)}async insertContext(e,t){this.clearPaths(),this.snarlMode="none",this.snarlFills=[],this.snarlNodes.clear(),this.stats.snarls={fills:0,inserted:0};let n=new Set,s=new Set;for(let r of this.records.keys())s.add(N(r));let o=0;for(;e.size>0;){let[r,i,h]=e.pop(),c=`${i}:${h}`;if(n.has(c))continue;n.add(c),s.delete(i),this.hasNode(i)||(await this.addNode(i),o+=1);let d=Ft(h);if(!n.has(`${i}:${d}`)){let y=this.record(ce(i,qt(h))),g=r+y.sequenceLen-1;g<=t&&e.push(g,i,d)}let f=this.record(ce(i,zt(h))),p=r+1;if(p<=t)for(let y of f.successors()){let g=N(y),l=Ue(Ee(y));n.has(`${g}:${l}`)||e.push(p,g,l)}}for(let r of s)this.records.delete(ce(r,"forward")),this.records.delete(ce(r,"reverse"));return{inserted:o,removed:s.size}}async betweenNodes(e,t){return(await this.fillBetween(e,t)).inserted.length}async fillBetween(e,t){this.clearPaths();let n=[e,ee(t)],s=new Set([N(e),N(t)]),o=[];for(;n.length>0;){let r=n.pop(),i=N(r);this.hasNode(i)||(await this.addNode(i),o.push(i));for(let h of this.record(r).successors()){let c=N(h);s.has(c)||(n.push(h,ee(h)),s.add(c))}}return{inserted:o,nodes:s.size-2}}async extractSnarls(e){let t=0;this.snarlMode=e;for(let[n,s]of await this.overlappingSnarls(e)){let{inserted:o,nodes:r}=await this.fillBetween(n,s),i=N(n),h=N(s);this.snarlFills.push({low:Math.min(i,h),high:Math.max(i,h),nodes:r,inserted:o.length});for(let c of o)this.snarlNodes.add(c);t+=o.length}return this.stats.snarls={fills:this.snarlFills.length,inserted:this.snarlNodes.size},t}async overlappingSnarls(e){let t=[];if(e!=="none"){let n=!1;for(let s of this.sortedHandles()){let o=this.record(s),r=o.next;r!==void 0&&(n=!0,this.hasHandle(r)?He(s,r)&&t.push([s,r]):e==="overlapping"&&this.isSnarlEntryInSubgraph(o)&&t.push([s,r]))}if(!n&&e==="overlapping"&&await this.db.hasChainLinks()){let s=await this.findCoveringSnarl();s&&t.push(s)}}return t}isSnarlEntryInSubgraph(e){let t=e.successors(),n=t.find(s=>this.hasHandle(s));return n===void 0?!1:t.length>1||this.record(ee(n)).successors().length>1}recordReader(e){let t=new Map;return async n=>{let s=this.records.get(n);if(s)return s;let o=t.get(n);if(!o){if(o=await this.db.getRecord(n),e?.(),!o)throw new Error(`Node record ${n} is missing from the database`);t.set(n,o)}return o}}async findCoveringSnarl(){let e=this.recordReader(),t=async h=>{let c=h.successors(),d=c[0];return d===void 0?!1:c.length>1||(await e(ee(d))).successors().length>1},n=async h=>{let c=await e(ee(h));return c.next!==void 0?await t(c)?{kind:"snarl-exit",snarl:[ee(h),c.next]}:{kind:"chain"}:(await e(h)).next!==void 0?{kind:"chain"}:{kind:"regular"}},s=new Set,o=this.sortedHandles().flatMap(h=>this.record(h).successors()),r,i=!1;for(;!i&&o.length>0;){let h=o.shift(),c=N(h);if(!this.hasHandle(h)&&!s.has(c)){s.add(c);let d=await n(h);if(d.kind==="snarl-exit")r=d.snarl,i=!0;else if(d.kind==="chain")i=!0;else for(let f of["forward","reverse"])o.push(...(await e(ce(c,f))).successors())}}return r}extractPaths(e,t){if(this.clearPaths(),t==="none")return;let n=e?.position;this.refPath=e?.name,this.refHandle=e?.handle;let s=this.sortedHandles(),o=s.length,r=new Map;s.forEach((m,I)=>r.set(m,I));let i=new Int32Array(o+1),h=new Int32Array(o),c=[];for(let m=0;m<o;m++){let I=this.record(s[m]),$=I.gbwt().decompressArrays();h[m]=I.sequenceLen,c.push($),i[m+1]=i[m]+$.nodes.length}let d=i[o],f=new Int32Array(d),p=new Int32Array(d),y=new Uint8Array(d);for(let m=0;m<o;m++){let I=c[m];f.set(I.nodes,i[m]),p.set(I.offsets,i[m])}c.length=0;for(let m=0;m<d;m++){let I=r.get(f[m]);I===void 0?f[m]=-1:(f[m]=I,y[i[I]+p[m]]=1)}let g=n===void 0?void 0:r.get(n.handle),l=n?.gbwtOffset,b,x=(m,I,$)=>{let F=[],_=0,D=0,C=-1,H=m,k=I;for(;;){H===g&&k===l&&(C=_),$&&($.push(s[H]),F.push(k)),_+=1,D+=h[H];let j=i[H]+k,X=f[j];if(X<0)break;k=p[j],H=X}return{offsets:F,len:D,refAt:C,last:H}},P=(m,I,$,F)=>{F>=0&&(this.refId=this.paths.length,b=F),this.paths.push({path:m,offsets:I,len:$,weight:void 0,identity:void 0})},E=new Int32Array(o);for(let m=0;m<o;m++){let I=s[m];if(!Q(I)){let $=i[m],F=i[m+1]-$;for(let _=0;_<F;_++)if(y[$+_]===0){let D=[],{offsets:C,len:H,refAt:k,last:j}=x(m,_,D),X=s[j];if(k>=0||Pe(I,X)){if(P(D,C,H,k),!Q(X)){let w=r.get(ee(X));E[w]=E[w]+1}}else this.twinStarts.add(ke({node:I,offset:_}))}}}for(let m=0;m<o;m++){let I=s[m];if(Q(I)){let $=i[m],F=i[m+1]-$,_=0;for(let C=0;C<F;C++)y[$+C]===0&&(_+=1);let D=(g===void 0||b!==void 0)&&_===E[m];for(let C=0;C<F;C++)if(y[$+C]===0){let H=D?void 0:x(m,C,void 0);if(H&&(H.refAt>=0||Pe(I,s[H.last]))){let k=[],{offsets:j,len:X,refAt:w}=x(m,C,k);P(k,j,X,w)}else this.twinStarts.add(ke({node:I,offset:C}))}}}let R=this.refId===void 0?void 0:this.paths[this.refId];if(this.paths.sort((m,I)=>m.path[0]-I.path[0]||m.offsets[0]-I.offsets[0]),R&&(this.refId=this.paths.indexOf(R)),n){if(b===void 0||this.refId===void 0)throw this.clearPaths(),new Error("Could not find the reference path");let m=this.paths[this.refId],I=n.nodeOffset;for(let F of m.path.slice(0,b))I+=this.record(F).sequenceLen;let $=n.seqOffset-I;this.refInterval=[$,$+m.len],m.identity={pathHandle:e.handle,name:e.name,orientation:"forward",hapStart:$,hapEnd:$+m.len}}if(t==="distinct")this.distinctPaths(!0);else if(t==="reference-only"){if(this.refId===void 0)throw new Error("Reference path is required for reference-only output");this.paths=[this.paths[this.refId]],this.refId=0}}distinctPaths(e){let t=this.refId===void 0?void 0:this.paths[this.refId],n=t?.path,s=n&&!Oe(n)?Be(n):void 0,o=c=>s!==void 0&&wt(c,s)===0||Oe(Be(c)),r=e&&this.db.hasHaplotypeIndex;this.twinDeferred=!1,this.paths.sort((c,d)=>wt(c.path,d.path)||c.len-d.len||(c===t?-1:d===t?1:0));let i=[],h;for(let c of this.paths){let d=i[i.length-1],f=r&&c!==t&&o(c.path);this.twinDeferred||=f,d&&wt(d.path,c.path)===0&&!f?d.weight=(d.weight??1)+(c.weight??1):(c===t&&(h=i.length),i.push({...c,weight:c.weight??1}))}this.paths=i,this.refId=h}mergeDistinct(){this.twinDeferred?this.settleDeferred():this.distinctPaths(!1)}settleDeferred(){this.twinDeferred&&(this.unsettled={paths:[...this.paths],refId:this.refId},this.distinctPaths(!1))}dropTwins(){let e=this.refId===void 0?void 0:this.paths[this.refId],t=this.refInterval,n=r=>`${r.pathHandle}:${r.hapStart}-${r.hapEnd}`,s=new Set;e?.identity&&t&&s.add(n({...e.identity,hapStart:t[0],hapEnd:t[1]}));for(let r of this.paths)r!==e&&r.identity?.orientation==="forward"&&s.add(n(r.identity));let o=this.paths.filter(r=>r===e||r.identity?.orientation!=="reverse"||!s.has(n(r.identity)));o.length<this.paths.length&&(this.paths=o,this.refId=e===void 0?void 0:o.indexOf(e)),this.twinDeferred&&this.distinctPaths(!1)}keepHaplotypes(e){if(this.paths.some(r=>r.weight!==void 0))throw new Error("keepHaplotypes needs one walk per haplotype: extract with haplotypes 'all', then call mergeDistinct()");let t=this.paths.filter((r,i)=>i!==this.refId&&r.identity===void 0).length;if(t>0)throw new Error(`${t} of the window's ${this.paths.length} walks have no name, so the haplotypes to keep cannot be told from the rest; call identifyPaths() first, and check that the haplotype index was built for this graph`);let n=this.refId===void 0?void 0:this.paths[this.refId],s=this.paths.filter((r,i)=>i===this.refId||r.identity!==void 0&&e(r.identity.name)),o=new Set;for(let r of s)for(let i of r.path)o.add(N(i));for(let r of[...this.records.keys()])o.has(N(r))||this.records.delete(r);this.paths=s,this.refId=n===void 0?void 0:s.indexOf(n)}async extractChosenPaths(e,t,n,s){this.clearPaths();let o=e.position.seqOffset,r=await Zt({db:this.db,records:this.records,referenceHandle:e.handle,referencePos:{node:e.position.handle,offset:e.position.gbwtOffset},referenceLeft:o-e.position.nodeOffset,window:{start:o,end:o+t},context:s,snarls:{mode:this.snarlMode,fills:this.snarlFills,inserted:this.snarlNodes},keep:n,signal:this.signal,prefetchReferenceRange:(d,f,p)=>this.prefetchReferenceRange(d,f,p)});if(this.stats.keep=r.stats,r.stats.fallback!==void 0)return!1;let i=await this.db.pathsByHandle(),h=d=>({path:d.handles,offsets:d.offsets,len:d.len,weight:void 0,identity:{pathHandle:d.pathHandle,name:d===r.reference?e.name:i.get(d.pathHandle).name,orientation:d.orientation,hapStart:d.hapStart,hapEnd:d.hapEnd}}),c=[r.reference,...r.pieces].sort(Xt);return this.paths=c.map(h),this.refId=c.indexOf(r.reference),this.refPath=e.name,this.refHandle=e.handle,this.refInterval=[r.reference.hapStart,r.reference.hapEnd],this.dropTwins(),!0}async identifyPaths(){if(!this.db.hasHaplotypeIndex)throw new Error("The database has no HaplotypeSamples table; run gbz-haplotype-index on it");this.unsettled&&({paths:this.paths,refId:this.refId}=this.unsettled,this.unsettled=void 0,this.twinDeferred=!0);let e=await this.db.haplotypeSampleGap()??4096,t=pt(this.sortedHandles());if(t.length===0)return;let n=new Map,s=await Promise.all(t.map(([l,b])=>this.db.haplotypeSamplesInRange(l,b)));for(let l of s.flat())n.set(ke(l),l);let o=l=>{let b=0,x=t.length-1;for(;b<x;){let E=b+x+1>>1;t[E][0]<=l?b=E:x=E-1}let P=t[b];return P[0]<=l&&l<=P[1]},r=new Map;this.paths.forEach((l,b)=>{l.path.length>0&&b!==this.refId&&r.set(ke(Ge(l,0)),b)});let i=this.stats.identification;i.interval=e,i.scans=t,i.windowSamples=n.size,this.paths.forEach((l,b)=>{b!==this.refId&&i.fragmentLengths.push(l.len)});let h=this.recordReader(()=>{this.stats.identificationFetches+=1,i.graphFetches+=1}),c=l=>(i.graphLookups+=1,h(l)),d=async(l,b)=>{if(o(l.node))return n.get(ke(l));this.stats.identificationFetches+=1,i.companionSeeks+=1,b.seeks+=1;let x=await this.db.haplotypeSampleAt(l.node,l.offset);return x||(i.companionMisses+=1),x},f=new Map,p=async l=>{let b=f.get(l);if(!b){let x=await this.db.getPath(l);if(!x)throw new Error(`Path ${l} is missing from the database`);b=x.name,f.set(l,b)}return b},y=(l,b,x)=>l.orientation==="forward"?{pathHandle:l.pathHandle,orientation:"forward",base:l.pathOffset-b}:{pathHandle:l.pathHandle,orientation:"reverse",base:l.pathOffset+b+x},g=(l,b)=>l.orientation==="forward"?{pathHandle:l.pathHandle,orientation:"forward",base:l.hapStart-b}:{pathHandle:l.pathHandle,orientation:"reverse",base:l.hapEnd+b};for(let l=0;l<this.paths.length;l++){let b=this.paths[l];if(l===this.refId||b.identity)continue;let x=[],P=new Set,E={fragments:0,steps:0,seeks:0,reentries:0,twinLandings:0,end:"endmarker",pathHandle:void 0};i.chains.push(E);let R,m=0,I=l,$;for(;R===void 0;){if(this.signal?.throwIfAborted(),I!==void 0){if(P.has(I)){E.end="cycle";break}P.add(I);let H=this.paths[I];x.push({index:I,startBp:m}),E.fragments+=1;let k=m;for(let X=0;X<H.path.length;X++){let w=Ge(H,X),S=n.get(ke(w)),A=this.record(w.node).sequenceLen;if(S){R=y(S,k,A);break}k+=A}if(m+=H.len,R){E.end="in-fragment sample";break}let j=Ge(H,H.path.length-1);$=this.record(j.node).gbwt().lf(j.offset),I=void 0}if($===void 0||$.node===0){E.end="endmarker";break}let F=ke($),_=r.get(F);if(_!==void 0){let H=this.paths[_].identity;if(H){R=g(H,m),E.end="identified sibling";break}I=_;continue}this.records.has($.node)&&(E.reentries+=1),this.twinStarts.has(F)&&(E.twinLandings+=1);let D=await d($,E),C=await c($.node);if(D){R=y(D,m,C.sequenceLen),E.end="out-of-window sample";break}if(this.stats.identificationSteps+=1,E.steps+=1,m-x[x.length-1].startBp>4*e+4*C.sequenceLen){E.end="bound";break}m+=C.sequenceLen,$=C.gbwt().lf($.offset)}if(R){E.pathHandle=R.pathHandle;let F=await p(R.pathHandle);for(let{index:_,startBp:D}of x){let C=this.paths[_];C.identity=R.orientation==="forward"?{pathHandle:R.pathHandle,name:F,orientation:"forward",hapStart:R.base+D,hapEnd:R.base+D+C.len}:{pathHandle:R.pathHandle,name:F,orientation:"reverse",hapStart:R.base-D-C.len,hapEnd:R.base-D}}}}this.dropTwins()}refIndex(e){if(this.refIndexCache===void 0){let t=new Map;e.forEach((n,s)=>{let o=t.get(n);o?o.push(s):t.set(n,[s])}),this.refIndexCache=t}return this.refIndexCache}refPrefix(e){if(this.refPrefixCache===void 0){let t=[0];e.forEach((n,s)=>{t.push(t[s]+this.record(n).sequenceLen)}),this.refPrefixCache=t}return this.refPrefixCache}orderedMatches(e,t){let n=this.refIndex(t),s=new Int32Array(e.length),o=new Int32Array(e.length),r=0,i=-1;for(let h=0;h<e.length;h++){let c=n.get(e[h]);if(c){let d=qn(c,i);if(d===void 0)return;s[r]=h,o[r]=d,r+=1,i=d}}return{pathAt:s,refAt:o,count:r}}pathLen(e){let t=0;for(let n of e)t+=this.record(n).sequenceLen;return t}prefixMatches(e,t){let n=0,s=0,o=0,r=0,i=0;for(;s<e.length&&o<t.length;){let h=this.record(e[s]).sequence,c=this.record(t[o]).sequence;for(;r<h.length&&i<c.length;){if(h[r]!==c[i])return n;r+=1,i+=1,n+=1}r===h.length&&(s+=1,r=0),i===c.length&&(o+=1,i=0)}return n}suffixMatches(e,t){let n=0,s=0,o=0,r=0,i=0;for(;s<e.length&&o<t.length;){let h=this.record(e[e.length-s-1]).sequence,c=this.record(t[t.length-o-1]).sequence;for(;r<h.length&&i<c.length;){if(h[h.length-r-1]!==c[c.length-i-1])return n;r+=1,i+=1,n+=1}r===h.length&&(s+=1,r=0),i===c.length&&(o+=1,i=0)}return n}align(e,t,n){let s=this.pathLen(e),o=this.pathLen(t),r=this.prefixMatches(e,t),i=this.suffixMatches(e,t);r+i>s&&(i=s-r),r+i>o&&(i=o-r),K(n,"M",r),hn(n,s-r-i,o-r-i),K(n,"M",i)}sharedWeight(e,t){let n=this.refIndex(t),s=0;for(let o of e)n.has(o)&&(s+=this.record(o).sequenceLen);return s}editsAgainst(e,t){let n=this.orderedMatches(e,t);n?this.stats.orderedAlignments+=1:this.stats.lcsAlignments+=1;let s=n??Fn(Ut(e,t,f=>this.record(f).sequenceLen)[0]),o=[],r=this.refPrefix(t),i=(f,p,y,g)=>{f===p?K(o,"D",r[g]-r[y]):y===g?K(o,"I",this.pathLen(e.slice(f,p))):this.align(e.slice(f,p),t.slice(y,g),o)},h=0,c=0,d=0;for(let f=0;f<s.count;f++){let p=s.pathAt[f],y=s.refAt[f];(c!==p||d!==y)&&i(c,p,d,y);let g=this.record(e[p]).sequenceLen;K(o,"M",g),h+=g,c=p+1,d=y+1}return i(c,e.length,d,t.length),{edits:o,matched:h,matches:s}}alignment(e){let t=this.paths[e];if(this.refId===void 0||e===this.refId||!t)return;let n=this.paths[this.refId].path,s;if(Oe(n)&&(t.identity===void 0||!Oe(Be(t.path))))s={...this.editsAgainst(t.path,n),flipped:!1};else{let o=Be(t.path),r=this.sharedWeight(t.path,n);if(this.sharedWeight(o,n)===0)s={...this.editsAgainst(t.path,n),flipped:!1};else if(r===0)s={...this.editsAgainst(o,n),flipped:!0};else{let h=this.editsAgainst(t.path,n),c=this.editsAgainst(o,n);s=c.matched>h.matched?{...c,flipped:!0}:{...h,flipped:!1}}}return s}alignToRef(e){return this.settleDeferred(),this.alignment(e)?.edits.map(([t,n])=>`${n}${t}`).join("")}alignments(){this.settleDeferred();let e=this.referenceInterval;if(this.refId===void 0||!e)throw new Error("Alignments need a reference path");let t=this.paths[this.refId].path,n=this.refPrefix(t)[t.length],s=(d,f,p,y)=>{let g=Gn(d),l=this.paths[p[0]],b=this.paths[p[p.length-1]],x=l.identity,P=x?.orientation==="forward",[E,R]=P?[l,b]:[b,l];return{strand:f,refStart:e.start+g.leading,refEnd:e.start+n-g.trailing,edits:g.edits,weight:l.weight,path:p.flatMap(m=>this.paths[m].path),start:Ge(l,0),pieces:p,soloAligned:y,identity:x===void 0?void 0:{pathHandle:x.pathHandle,name:x.name,hapStart:x.name.fragment+E.identity.hapStart,hapEnd:x.name.fragment+R.identity.hapEnd,walkForward:P}}},o=d=>d.soloAligned.reduce((f,p)=>f+p,0),r=d=>d.pieces.reduce((f,p)=>f+this.paths[p].len,0),i=d=>2*o(d)>=r(d),h=d=>{let f=d[0],p=d[d.length-1],y=f.identity.walkForward;if(d.some((k,j)=>k.strand!==f.strand||k.identity.walkForward!==y||j>0&&k.identity.hapStart<d[j-1].identity.hapEnd))return;let g=y?d:[...d].reverse(),l=g.flatMap(k=>k.pieces),b=g.flatMap(k=>k.soloAligned),x=f.strand==="+"!==y,P=l.map(k=>this.paths[k]),E=P.slice(1).map((k,j)=>{let X=P[j].identity;return y?k.identity.hapStart-X.hapEnd:X.hapStart-k.identity.hapEnd}),R=x?[...P].reverse():P,m=x?[...E].reverse():E,I=R.flatMap(k=>x?Be(k.path):k.path),{edits:$}=this.editsAgainst(I,t),F=an($,R.map(k=>k.len)),_=new Map((x?[...l].reverse():l).map((k,j)=>[k,F[j]])),D=k=>2*k.pieces.reduce((j,X)=>j+_.get(X),0)>=o(k);if(!D(f)||!D(p))return;let C=[],H=0;return R.slice(0,-1).forEach((k,j)=>{H+=k.len,C.push([H,m[j]])}),s(Qn($,C),f.strand,l,b)},c=[];return this.paths.forEach((d,f)=>{if(f===this.refId)return;let{edits:p,flipped:y}=this.alignment(f),g=d.identity,l=g?g.orientation==="forward"!==y:!y;c.push(s(p,l?"+":"-",[f],an(p,[d.len])))}),jn(c,i,h).map(d=>{let{edits:f,identity:p,pieces:y,soloAligned:g,...l}=d,b={...l,cigar:Kn(f)};return p?{...b,resolved:!0,name:p.name,label:fe({...p.name,fragment:p.hapStart,end:p.hapEnd}),pathHandle:p.pathHandle,hapStart:p.hapStart,hapEnd:p.hapEnd}:{...b,resolved:!1}})}pairAlignments(e){let{target:t,query:n,...s}=e,o=this.paths.flatMap(d=>{let{identity:f}=d;return f?[{name:f.name,start:f.name.fragment+f.hapStart,steps:Ke(d,f)}]:[]}),r=d=>f=>f.sample===d.sample&&f.haplotype===d.haplotype,i=r(t),h=n?r(n):d=>!i(d),c=d=>this.record(ce(d,"forward")).sequence;return o.filter(d=>i(d.name)).flatMap(d=>o.filter(f=>h(f.name)).flatMap(f=>Wt({...s,query:f.steps,target:d.steps,sequenceOf:c}).map(p=>({query:f.name,queryStart:f.start+p.queryStart,queryEnd:f.start+p.queryEnd,strand:p.strand,target:d.name,targetStart:d.start+p.targetStart,targetEnd:d.start+p.targetEnd,cigar:Vt(p.edits),matches:p.edits.reduce((y,[g,l])=>y+(g==="="?l:0),0),columns:p.edits.reduce((y,[,g])=>y+g,0),sharedBases:p.sharedBases}))))}canonicalEdges(e){let t=[];for(let n of["forward","reverse"]){let s=ce(e,n);for(let o of this.record(s).successors())this.hasHandle(o)&&He(s,o)&&t.push([n==="reverse"?1:0,N(o),Q(o)?1:0])}return t.sort((n,s)=>n[0]-s[0]||n[1]-s[1]||n[2]-s[2]),t.filter((n,s)=>s===0||n[0]!==t[s-1][0]||n[1]!==t[s-1][1]||n[2]!==t[s-1][2])}async stableName(){let e=new TextEncoder,t=[];for(let n of this.sortedHandles())if(!Q(n)){let s=N(n),o=`S ${s} ${this.record(n).sequence}
|
|
1
|
+
import{a as ce,b as N,c as Ee,d as Q,e as ee,f as Ft,g as Ue,h as We,i as qt,j as zt,k as He,l as Oe,m as Pe,n as Dt,o as jt,p as Ut,q as Wt,r as Vt}from"./chunk-M2D7NUOY.js";import{a as _t,g as Tt}from"./chunk-MFMAQO3W.js";import{c as Ot}from"./chunk-MNFL7BAC.js";import{a as Ct,g as Bt}from"./chunk-OMF5XFKR.js";var Ln=4096;function pt(a){let e=[];for(let t of a){let n=e[e.length-1];n&&t-n[1]<=Ln?n[1]=t:e.push([t,t])}return e}var Hn=32768,Gt={mostChosenPaths:32},lt=class{byNode=new Map;get(e){return this.byNode.get(e.node)?.get(e.offset)}set(e,t){let n=this.byNode.get(e.node);n||(n=new Map,this.byNode.set(e.node,n)),n.set(e.offset,t)}},re=class extends Error{};function Ve(a,e,t,n){return a==="forward"?e+t:e-n}function Qt(a,e,t,n){return a==="forward"?e-n:e+t}function Kt(a){return Pe(ee(a.handles[a.handles.length-1]),ee(a.handles[0]))}function Ce(a){return`${a.pathHandle}:${a.hapStart}:${a.hapEnd}`}async function Zt(a){let{db:e,records:t,signal:n}=a,s=performance.now(),o=()=>{let w=performance.now(),S=w-s;return s=w,S},r={spacing:await e.haplotypeAnchorSpacing(),anchors:void 0,anchorsRead:0,chosenPaths:0,scans:[],scanRows:0,strays:void 0,pieces:0,sources:{reference:0,section:0,stray:0,chain:0,twin:0},walks:{},twins:{tried:0,found:0},graphFetches:0,fallback:void 0,ms:{scan:0,walks:0,check:0,twins:0}},i=(w,S)=>{let A=`${w}: ${S}`;r.walks[A]=(r.walks[A]??0)+1},h=await e.haplotypeSampleInterval()??4096,c=new Map,d=async w=>{let S=t.get(w)??c.get(w);if(S)return S;let A=await e.getRecord(w);if(r.graphFetches+=1,!A)throw new Error(`Node record ${w} is missing from the database`);return c.set(w,A),A},f=w=>t.get(w).sequenceLen,p=await e.pathsByHandle(),y=w=>{let S=p.get(w);return S!==void 0&&a.keep(S.name)},g=[],l=new lt,b=new Map,x=new Set,P=new Set,E=async w=>{let S=(await d(w.node)).gbwt().lf(w.offset);return S===void 0||S.node===0?void 0:S},R=async(w,S)=>{let A=(await d(ee(w.node))).gbwt().predecessorAt(w.offset);if(A===void 0||S!==void 0&&!S.has(A))return;let M=(await d(A)).gbwt().offsetTo(w);if(M===void 0)throw new Error(`No offset in ${A} leads to ${w.node}:${w.offset}`);return{node:A,offset:M}},m=(w,S,A,M)=>{let B=A.map(W=>W.pos.node),U=A.map(W=>W.pos.offset),J=0;for(let W of B)J+=f(W);let O=S==="forward"?A[0].left:A[A.length-1].left,L=g.length;g.push({pathHandle:w,orientation:S,handles:B,offsets:U,len:J,hapStart:O,hapEnd:O+J,canonical:Pe(B[0],B[B.length-1]),source:M});for(let W of A)l.set(W.pos,L);let G=b.get(w);return G?G.push(L):b.set(w,[L]),L},I=async(w,S,A,M)=>{let B=[],U=w;for(;;){n?.throwIfAborted();let O=await R(U.pos,t);if(!O)break;U={pos:O,left:Qt(A,U.left,f(U.pos.node),f(O.node))},B.push(U)}B.reverse();let J=[w];for(U=w;;){n?.throwIfAborted();let O=await E(U.pos);if(!O||!t.has(O.node))break;U={pos:O,left:Ve(A,U.left,f(U.pos.node),f(O.node))},J.push(U)}return m(S,A,[...B,...J],M)},$=async(w,S,A,M)=>g[l.get(w.pos)??await I(w,S,A,M)],F=w=>{let S=w.handles[w.handles.length-1];return{pos:{node:S,offset:w.offsets[w.offsets.length-1]},left:w.orientation==="forward"?w.hapEnd-f(S):w.hapStart}},_=w=>{let S=w.handles[0];return{pos:{node:S,offset:w.offsets[0]},left:w.orientation==="forward"?w.hapStart:w.hapEnd-f(S)}},D=await I({pos:a.referencePos,left:a.referenceLeft},a.referenceHandle,"forward","reference"),C=g[D],H=()=>{if(r.fallback!==void 0)return{reference:C,pieces:[],stats:r};let w=new Map;g.forEach((A,M)=>{M!==D&&w.set(Ce(A),[...w.get(Ce(A))??[],A])});let S=[];for(let A of w.values()){let M=new Set;for(let B of A)B.canonical&&!M.has(B.orientation)&&(M.add(B.orientation),S.push(B),r.sources[B.source]+=1)}return r.sources.reference=1,r.pieces=S.length+1,{reference:C,pieces:S,stats:r}},k=async(w,S)=>{let A=S?x:P,M=S?P:x,B=w;for(;;){if(A.has(B))return;A.add(B);let U=g[B],J=S?F(U):_(U),O=0,L;for(;L===void 0;){n?.throwIfAborted();let G=S?await E(J.pos):await R(J.pos);if(!G){L="endmarker";break}let W=(await d(J.pos.node)).sequenceLen,ue=(await d(G.node)).sequenceLen,se=S?Ve(U.orientation,J.left,W,ue):Qt(U.orientation,J.left,W,ue);if(t.has(G.node)){let Y=l.get(G);Y===void 0?(B=await I({pos:G,left:se},U.pathHandle,U.orientation,"chain"),M.add(B),L="landed"):(M.add(Y),L="merge")}else O>Hn?L="bound":(O+=ue,J={pos:G,left:se})}if(i("chain",L),L!=="landed")return}},j=async w=>{if(a.context>w.context)throw new re(`the context of ${a.context} bp exceeds the ${w.context} bp the haplotype index's stray rows cover`);let S=r.spacing;if(S===void 0)throw new re("the haplotype index has no anchors");let{bin:A,bound:M}=w,{fills:B,inserted:U}=a.snarls;if(a.snarls.mode==="overlapping"&&B.length>0)throw new re("the haplotype index's stray rows cover contained snarls only");for(let u of B){if(u.inserted>0&&u.low===u.high)throw new re(`the haplotype index's stray rows leave out the snarl bounded by node ${u.low} at both ends`);if(u.inserted>0&&(w.snarlNodes===void 0||u.nodes>w.snarlNodes))throw new re(w.snarlNodes===void 0?"the haplotype index's stray rows leave snarls out":`a snarl of ${u.nodes} nodes exceeds the ${w.snarlNodes} the haplotype index's stray rows cover`)}let J=Math.floor(a.window.start/A),O=Math.floor((a.window.end-1)/A),L=J*A,G=(O+1)*A,W=new Map,ue=async(u,v)=>{let z=await e.haplotypeAnchorsBetween(a.referenceHandle,u*S,v*S);for(let T of z)W.set(T.anchorOffset/S,T)},se=Math.max(0,Math.floor((L-M)/S)-1),Y=Math.ceil((G+M)/S)+1,[{listed:De,strays:ae}]=await Promise.all([e.haplotypeBinData(a.referenceHandle,J,O),ue(se,Y)]);for(let u of t.keys()){let v=N(u);if(!Q(u)&&!De(v)&&!U.has(v))throw new re(`the haplotype index lists node ${v} of the subgraph in no bin that the window touches`)}r.scans=pt([...t.keys()].sort((u,v)=>u-v));let ie=Promise.all(r.scans.map(([u,v])=>e.haplotypeSamplesInRange(u,v)));for(ie.catch(()=>{});se>0&&(W.get(se)?.pathOffset??Number.POSITIVE_INFINITY)>=L-M;)se-=1,await ue(se,se);for(;W.has(Y)&&W.get(Y).pathOffset<=G+M;)Y+=1,await ue(Y,Y);let pe=[...W.keys()].sort((u,v)=>u-v),ye=W.get(pe[0]??-1);if(!ye)throw new re("the haplotype index has no anchors on this path");let he=u=>W.get(u).pathOffset,Ne=new Map;for(let u of pe){let v=N(W.get(u).node);Ne.set(v,[...Ne.get(v)??[],u])}let ct=[...Ne.keys()],Et=ct.map(u=>W.get(Ne.get(u)[0]).visits);if(!Et[ct.indexOf(N(ye.node))].some(u=>u.pathHandle===a.referenceHandle&&u.orientation==="forward"&&u.pathOffset===ye.pathOffset))throw new Error(`The haplotype index has no anchor row for the reference path ${a.referenceHandle} at offset ${ye.pathOffset} (node ${N(ye.node)}); it does not match this graph`);let kt=pe.filter(u=>he(u)<=a.window.start),$n=pe.filter(u=>he(u)>=a.window.end);r.anchors=[he(kt[kt.length-1]??pe[0]),he($n[0]??pe[pe.length-1])],r.anchorsRead=pe.length;let dt=new Map,vt=new Set;if(ct.forEach((u,v)=>{let z=Ne.get(u),T=z.length===1?z[0]:void 0;for(let q of Et[v])vt.add(q.pathHandle),q.orientation==="forward"&&y(q.pathHandle)&&dt.set(q.pathHandle,[...dt.get(q.pathHandle)??[],{k:T,row:q}])}),r.chosenPaths=[...vt].filter(y).length,r.chosenPaths>Gt.mostChosenPaths)throw new re(`${r.chosenPaths} chosen paths pass the anchors, more than ${Gt.mostChosenPaths}`);let je=[],Ie=Number.POSITIVE_INFINITY,be=0;for(let[u,v]of dt){v.sort((z,T)=>z.row.pathOffset-T.row.pathOffset);for(let z=0;z+1<v.length;z++){let T=v[z],q=v[z+1];if(T.k===void 0||q.k===void 0||Math.abs(T.k-q.k)!==1)continue;let[Z,te]=he(T.k)<=he(q.k)?[T,q]:[q,T],ne=he(Z.k),oe=he(te.k);ne<G&&oe>=L?(je.push({pathHandle:u,from:T.row,to:q.row}),Ie=Math.min(Ie,ne-M),be=Math.max(be,oe+M)):ne>=G&&ne-G<=M?(je.push({pathHandle:u,from:Z.row,to:void 0}),Ie=Math.min(Ie,ne-M),be=Math.max(be,ne+M)):oe<L&&L-oe<=M&&(je.push({pathHandle:u,from:te.row,to:void 0}),Ie=Math.min(Ie,oe-M),be=Math.max(be,oe+M))}}let Rn=new Set(B.map(u=>`${u.low}:${u.high}`)),Nn=ae.filter(u=>y(u.pathHandle)&&(u.snarl===void 0||Rn.has(`${u.snarl[0]}:${u.snarl[1]}`))).sort((u,v)=>u.pathHandle-v.pathHandle||u.pathStart-v.pathStart);r.strays={bins:O-J+1,rows:ae.length,walked:0,outsideBp:0},be>0&&await a.prefetchReferenceRange(a.referenceHandle,Math.max(0,Ie),be+1),r.ms.scan=o();let Pt=8*S+2*(a.window.end-a.window.start),At=r.strays,Me=0,$t=u=>{if(At.outsideBp+=u,Me+=u,Me>Pt)throw new re(`a walk of a chosen path near the window went past its cap of ${Pt} bp`)},ft=new Map,Rt=(u,v,z)=>(ft.get(u)??[]).some(([T,q])=>T<=v&&z<q),Nt=(u,v,z)=>{ft.set(u,[...ft.get(u)??[],[v,z]])},Mt=async(u,v,z,T,q)=>{let Z=v,te=z,ne=te;for(;Z&&te<=T;){n?.throwIfAborted();let oe;if(t.has(Z.node)){let Le=await $({pos:Z,left:te},u,"forward",q),Ht=F(Le);Z=Ht.pos,te=Ht.left,oe=f(Z.node),ne=Math.max(ne,Le.hapEnd)}else oe=(await d(Z.node)).sequenceLen,$t(oe),ne=Math.max(ne,te+oe);Z=await E(Z),te+=oe}return ne},Mn=async(u,v,z,T)=>{let q={pos:v,left:z},Z=z;for(;q.left>T;){n?.throwIfAborted();let te=await R(q.pos);if(!te)break;let ne=(await d(te.node)).sequenceLen,oe=q.left-ne;if(t.has(te.node)){let Le=await $({pos:te,left:oe},u,"forward","section");q=_(Le),Z=Math.min(Z,Le.hapStart)}else $t(ne),q={pos:te,left:oe},Z=Math.min(Z,oe)}return Z};for(let{pathHandle:u,from:v,to:z}of je){let T=v.pathOffset,q=(z??v).pathOffset+M;if(Rt(u,T-M,q))continue;let Z={node:v.node,offset:v.offset};Me=0;let te=await Mt(u,Z,T,q,"section");Me=0;let ne=await Mn(u,Z,T,T-M);Nt(u,Math.min(ne,T-M),Math.max(te,q+1)),i(z?"section":"visit",z?"past the far anchor":"bound")}for(let u of Nn){if(Rt(u.pathHandle,u.pathStart,u.pathEnd))continue;Me=0;let v=await Mt(u.pathHandle,{node:u.node,offset:u.offset},u.pathStart,u.pathEnd,"stray");Nt(u.pathHandle,u.pathStart,Math.max(v,u.pathEnd+1)),At.walked+=1}r.ms.walks=o();let Lt=[];for(let u of await ie)for(let v of u)if(r.scanRows+=1,t.has(v.node)&&y(v.pathHandle)){if(!(b.get(v.pathHandle)??[]).some(z=>{let T=g[z];return T.hapStart<=v.pathOffset&&v.pathOffset<T.hapEnd}))throw new re(`chosen path ${v.pathHandle} has a sample at ${v.pathOffset} on the window's nodes that no walk reached`);v.orientation==="reverse"&&Lt.push(v)}for(let u of Lt)await $({pos:{node:u.node,offset:u.offset},left:u.pathOffset},u.pathHandle,"reverse","twin");r.ms.check=o()},X=async()=>{let w=new Map,S=O=>{let L=Ce(O),G=w.get(L);G?G.add(O.orientation):w.set(L,new Set([O.orientation]))},A=0,M=()=>{for(;A<g.length;A++)S(g[A])};M();let B=O=>(w.get(Ce(O))?.size??0)>1,U=2*h,J=(O,L)=>L===D?y(a.referenceHandle)&&Kt(O):!O.canonical||Kt(O);for(let O=0;O<g.length;O++){let L=g[O];if(B(L)||!J(L,O))continue;r.twins.tried+=1;let G=L.orientation==="forward"?"reverse":"forward",W=F(L),ue=0,se;for(;!se&&ue<=U;){n?.throwIfAborted();let ae=await E(W.pos);if(!ae)break;let ie=(await d(ae.node)).sequenceLen,pe=Ve(L.orientation,W.left,(await d(W.pos.node)).sequenceLen,ie),ye=ee(ae.node);se=(await e.haplotypeSamplesInRange(ye,ye)).find(he=>he.pathHandle===L.pathHandle&&he.orientation===G&&he.pathOffset===pe),ue+=ie,W={pos:ae,left:pe}}let Y=se&&{pos:{node:se.node,offset:se.offset},left:se.pathOffset},De=0;for(;Y&&!B(L)&&De<=U+L.len;){if(n?.throwIfAborted(),t.has(Y.pos.node)){let ae=await $(Y,L.pathHandle,G,"twin"),ie=g.indexOf(ae);await k(ie,!0),await k(ie,!1),M(),Y=F(ae)}if(!B(L)){let ae=(await d(Y.pos.node)).sequenceLen;De+=ae;let ie=await E(Y.pos);Y=ie?{pos:ie,left:Ve(G,Y.left,ae,(await d(ie.node)).sequenceLen)}:void 0}}if(M(),!B(L))throw new re(`piece ${Ce(L)} was found in one orientation where extractPaths keeps the other`);r.twins.found+=1}r.ms.twins=o()};try{let w=await e.haplotypeStrayOptions();if(w===void 0)throw new re("the haplotype index has no stray rows; gbz-haplotype-index 0.2.0 writes them");await j(w),await X()}catch(w){if(!(w instanceof re))throw w;r.fallback=w.message}return H()}function Xt(a,e){return a.handles[0]-e.handles[0]||a.offsets[0]-e.offsets[0]}var On=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),we=(a,e)=>a>>>e|a<<32-e;function Jt(a){let e=Math.ceil((a.length+9)/64),t=new Uint8Array(e*64);t.set(a),t[a.length]=128;let n=new DataView(t.buffer),s=a.length*8;n.setUint32(t.length-8,Math.floor(s/2**32)),n.setUint32(t.length-4,s>>>0);let o=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),r=new Uint32Array(64);for(let c=0;c<e;c++){for(let P=0;P<16;P++)r[P]=n.getUint32(c*64+P*4);for(let P=16;P<64;P++){let E=r[P-15],R=r[P-2],m=we(E,7)^we(E,18)^E>>>3,I=we(R,17)^we(R,19)^R>>>10;r[P]=r[P-16]+m+r[P-7]+I}let d=o[0],f=o[1],p=o[2],y=o[3],g=o[4],l=o[5],b=o[6],x=o[7];for(let P=0;P<64;P++){let E=we(g,6)^we(g,11)^we(g,25),R=g&l^~g&b,m=x+E+R+On[P]+r[P]|0,I=we(d,2)^we(d,13)^we(d,22),$=d&f^d&p^f&p;x=b,b=l,l=g,g=y+m|0,y=p,p=f,f=d,d=m+I+$|0}[d,f,p,y,g,l,b,x].forEach((P,E)=>{o[E]=o[E]+P})}let i=new Uint8Array(32),h=new DataView(i.buffer);for(let c=0;c<8;c++)h.setUint32(c*4,o[c]);return i}function Yt(a,e){let t=new Map;if(a!==void 0)for(let n of a.split(";")){let s=n.split(","),[o,r]=s;if(s.length!==2||!o||!r)throw new Error(`Invalid ${e} relationship: ${n}`);let i=t.get(o);i||(i=new Set,t.set(o,i)),i.add(r)}return t}function nn(a){return{name:a.get("pggname"),subgraph:Yt(a.get("subgraph"),"subgraph"),translation:Yt(a.get("translation"),"translation")}}function en(a,e){for(let[t,n]of e){let s=a.get(t);s||(s=new Set,a.set(t,s));for(let o of n)s.add(o)}}function sn(a,e){let t={name:a,subgraph:new Map,translation:new Map};return e.name!==void 0&&(t.subgraph.set(a,new Set([e.name])),en(t.subgraph,e.subgraph),en(t.translation,e.translation)),t}function tn(a){return[...a.entries()].sort(([e],[t])=>e<t?-1:e>t?1:0).flatMap(([e,t])=>[...t].sort().map(n=>[e,n]))}function on(a){let e=[];a.name!==void 0&&e.push(`H NM:Z:${a.name}`);for(let[t,n]of tn(a.subgraph))e.push(`H SG:Z:${t},${n}`);for(let[t,n]of tn(a.translation))e.push(`H TL:Z:${t},${n}`);return e}async function rn(a){let e=a.reduce((r,i)=>r+i.length,0),t=new Uint8Array(e),n=0;for(let r of a)t.set(r,n),n+=r.length;let s=globalThis.crypto?.subtle;return[...s?new Uint8Array(await s.digest("SHA-256",t)):Jt(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}var Cn="_gbwt_ref";function fe(a){let e=`${a.sample}#${a.haplotype}#${a.contig}`;return a.end===void 0?e:`${e}[${a.fragment}-${a.end}]`}var Bn=/^([^#]+)#(\d+)#([^#]+?)(?:\[\d+-\d+\])?$/,_n=/^([^#]+?)(?:\[\d+-\d+\])?$/;function Tn(a){let e=Bn.exec(a);if(e)return{sample:e[1],haplotype:Number(e[2]),contig:e[3]};let t=_n.exec(a);if(t)return{contig:t[1]};throw new Error(`"${a}" is not a path name; expected "sample#haplotype#contig" or a bare contig`)}function Ae(a){return typeof a=="string"?Tn(a):a}function $e(a,e){return{sample:a.sample??Cn,contig:a.contig,haplotype:a.haplotype??0,fragment:e}}var le=class extends Error{name="SubgraphLimitError";limit;windowBp;walkedBp;constructor(e,t){super(t===void 0?`Subgraph size limit of ${e} nodes exceeded`:`Subgraph size limit of ${e} nodes exceeded ${t.walkedBp} bp into a ${t.windowBp} bp window`),this.limit=e,this.windowBp=t?.windowBp,this.walkedBp=t?.walkedBp}};function ut(a,e){return a[0]<e[0]||a[0]===e[0]&&(a[1]<e[1]||a[1]===e[1]&&a[2]<e[2])}var _e=class{heap=[];push(e,t,n){let s=this.heap;s.push([e,t,n]);let o=s.length-1;for(;o>0;){let r=o-1>>1;if(ut(s[o],s[r]))[s[o],s[r]]=[s[r],s[o]],o=r;else break}}pop(){let e=this.heap,t=e[0],n=e.pop();if(e.length>0&&n!==void 0){e[0]=n;let s=0;for(;;){let o=2*s+1,r=o+1,i=s;if(o<e.length&&ut(e[o],e[i])&&(i=o),r<e.length&&ut(e[r],e[i])&&(i=r),i===s)break;[e[s],e[i]]=[e[i],e[s]],s=i}}return t}get size(){return this.heap.length}};function Fn(a){let e=new Int32Array(a.length),t=new Int32Array(a.length);return a.forEach(([n,s],o)=>{e[o]=n,t[o]=s}),{pathAt:e,refAt:t,count:a.length}}function qn(a,e){let t=0,n=a.length;for(;t<n;){let s=t+n>>1;a[s]>e?n=s:t=s+1}return a[t]}function ke(a){return`${a.node}:${a.offset}`}function Be(a){return a.map(e=>ee(e)).reverse()}function zn(a,e){let t=e.identity.hapStart-a.identity.hapEnd,n=a.strand==="+"?e.refStart-a.refEnd:a.refStart-e.refEnd;return a.strand===e.strand&&t>=0&&n>=0?{insertion:t,deletion:n}:void 0}function Dn(a,e,t){let[n,s]=a.strand==="+"?[a,e]:[e,a],o=n.edits.map(([c,d])=>[c,d]);hn(o,t.insertion,t.deletion);for(let[c,d]of s.edits)K(o,c,d);let r=a.identity.walkForward,[i,h]=r?[a,e]:[e,a];return{strand:a.strand,refStart:n.refStart,refEnd:s.refEnd,edits:o,weight:void 0,path:[...i.path,...h.path],start:i.start,pieces:[...i.pieces,...h.pieces],soloAligned:[...i.soloAligned,...h.soloAligned],identity:{pathHandle:a.identity.pathHandle,name:a.identity.name,hapStart:a.identity.hapStart,hapEnd:e.identity.hapEnd,walkForward:r}}}function jn(a,e,t){if(a.some(r=>r.weight!==void 0))return a;let n=new Map;a.forEach((r,i)=>{if(r.identity){let h=n.get(r.identity.pathHandle);h?h.push(i):n.set(r.identity.pathHandle,[i])}});let s=new Map,o=new Set;for(let r of n.values()){r.sort((d,f)=>a[d].identity.hapStart-a[f].identity.hapStart);let i=r[0],h=a[i],c=[];for(let d of r.slice(1)){let f=a[d],p=c.length===0?zn(h,f):void 0;if(p){h=Dn(h,f,p),o.add(d);continue}if(!e(f)){c.push(d);continue}let y=e(h)?t([h,...c.map(g=>a[g]),f]):void 0;if(y){h=y;for(let g of[...c,d])o.add(g)}else s.set(i,h),i=d,h=f;c=[]}s.set(i,h)}return a.flatMap((r,i)=>o.has(i)?[]:[s.get(i)??r])}function Ge(a,e){return{node:a.path[e],offset:a.offsets[e]}}var Un=32768;function Wn(a){let e=[...a].sort((n,s)=>n-s),t=[];for(let n of e){let s=t[t.length-1];s&&n-s[1]<=Un?s[1]=n:t.push([n,n])}return t}var Te=class a{records=new Map;paths=[];twinStarts=new Set;twinDeferred=!1;unsettled;refId;refPath;refHandle;refInterval;refIndexCache;refPrefixCache;walkedBp;snarlMode="none";snarlFills=[];snarlNodes=new Set;stats={orderedAlignments:0,lcsAlignments:0,snarls:{fills:0,inserted:0},identificationSteps:0,identificationFetches:0,identification:{interval:0,scans:[],windowSamples:0,fragmentLengths:[],companionSeeks:0,companionMisses:0,graphLookups:0,graphFetches:0,chains:[]},keep:void 0};db;limit;signal;constructor(e,t){this.db=e,this.limit=t.limit,this.signal=t.signal}static create(e,t={}){return new a(e,t)}get nodeCount(){return this.records.size/2}get pathCount(){return this.settleDeferred(),this.paths.length}get referenceInterval(){return this.refInterval&&this.refPath?{name:this.refPath,start:this.refPath.fragment+this.refInterval[0],end:this.refPath.fragment+this.refInterval[1]}:void 0}hasNode(e){return this.records.has(ce(e,"forward"))}hasHandle(e){return this.records.has(e)}record(e){let t=this.records.get(e);if(!t)throw new Error(`Subgraph has no record for handle ${e}`);return t}sortedHandles(){return[...this.records.keys()].sort((e,t)=>e-t)}async addNode(e){if(this.signal?.throwIfAborted(),this.limit!==void 0&&this.nodeCount>=this.limit)throw new le(this.limit);let t=await this.db.getRecord(ce(e,"forward")),n=await this.db.getRecord(ce(e,"reverse"));if(!t||!n)throw new Error(`Node ${e} does not exist in the graph`);this.records.set(t.handle,t),this.records.set(n.handle,n)}async ensureNode(e){this.hasNode(e)||await this.addNode(e)}clearPaths(){this.paths=[],this.twinStarts.clear(),this.twinDeferred=!1,this.unsettled=void 0,this.refId=void 0,this.refPath=void 0,this.refHandle=void 0,this.refInterval=void 0,this.refIndexCache=void 0,this.refPrefixCache=void 0}async pathPosition(e){let t=await this.db.findPath(e);if(!t)throw new Error(`Cannot find a path covering offset ${e.fragment} of ${fe(e)}`);if(!t.isIndexed)throw new Error(`The fragment of ${fe(t.name)} at ${t.name.fragment} has not been indexed for random access`);let n=e.fragment-t.name.fragment,s=await this.db.indexedPosition(t.handle,n);if(!s)throw new Error(`The fragment of ${fe(t.name)} at ${t.name.fragment} has not been indexed for random access`);return this.findPathPosition(t,n,s.pathOffset,s.pos)}async findPathPosition(e,t,n,s){let o=n,r=s;for(;;){await this.ensureNode(N(r.node));let i=this.record(r.node);if(o+i.sequenceLen>t)return{position:{seqOffset:t,handle:r.node,nodeOffset:t-o,gbwtOffset:r.offset},name:e.name,handle:e.handle};o+=i.sequenceLen;let h=i.gbwt().lf(r.offset);if(!h)throw new Error(`The fragment of ${fe(e.name)} at ${e.name.fragment} does not contain offset ${t}`);r=h}}async aroundPosition(e,t,n){let s=N(e);await this.ensureNode(s);let o=this.record(e),r=Ee(e),i=new _e;return i.push(t,s,Ue(r)),i.push(o.sequenceLen-t-1,s,We(r)),this.insertContext(i,n)}prefetchReferenceWalk(e,t){return this.prefetchReferenceRange(e.handle,e.position.seqOffset,e.position.seqOffset+t)}async prefetchReferenceRange(e,t,n){let[s,o]=await Promise.all([this.db.indexedPosition(e,t),this.db.indexedPosition(e,n)]);if(s&&o){let r=s.pos.node,i=o.pos.node;if(!await this.db.prefetchRecords([[Math.min(r,i),Math.max(r,i)+1]])){let c=await this.db.indexedPositionsBetween(e,t,n);await this.db.prefetchRecords(Wn(c.map(d=>d.pos.node)).map(([d,f])=>[d,f+2]),!0)}}return s}async aroundInterval(e,t,n){if(!(t>0))throw new Error("Interval length must be greater than 0");this.walkedBp=0;try{return await this.walkInterval(e,t,n)}catch(s){throw s instanceof le&&s.windowBp===void 0?new le(s.limit,{windowBp:t,walkedBp:this.walkedBp}):s}}get referenceWalkedBp(){return this.walkedBp}async walkInterval(e,t,n){let s={node:e.handle,offset:e.gbwtOffset},o=e.nodeOffset,r=t,i=new _e;for(;;){let h=N(s.node),c=Ee(s.node);this.walkedBp=t-r,await this.ensureNode(h);let d=this.record(s.node);if(o>=d.sequenceLen)throw new Error(`Offset ${o} in node ${h} of length ${d.sequenceLen}`);i.push(o,h,Ue(c));let f=d.sequenceLen-o;if(r<=f){i.push(r===f?0:f-r-1,h,We(c));break}i.push(0,h,We(c));let p=d.gbwt().lf(s.offset);if(!p)throw new Error(`No successor for GBWT position (${s.node}, ${s.offset})`);s=p,o=0,r-=f}return this.walkedBp=t,this.insertContext(i,n)}async aroundNodes(e,t){let n=new _e;for(let s of e)await this.ensureNode(s),n.push(0,s,"left"),n.push(0,s,"right");return this.insertContext(n,t)}async insertContext(e,t){this.clearPaths(),this.snarlMode="none",this.snarlFills=[],this.snarlNodes.clear(),this.stats.snarls={fills:0,inserted:0};let n=new Set,s=new Set;for(let r of this.records.keys())s.add(N(r));let o=0;for(;e.size>0;){let[r,i,h]=e.pop(),c=`${i}:${h}`;if(n.has(c))continue;n.add(c),s.delete(i),this.hasNode(i)||(await this.addNode(i),o+=1);let d=Ft(h);if(!n.has(`${i}:${d}`)){let y=this.record(ce(i,qt(h))),g=r+y.sequenceLen-1;g<=t&&e.push(g,i,d)}let f=this.record(ce(i,zt(h))),p=r+1;if(p<=t)for(let y of f.successors()){let g=N(y),l=Ue(Ee(y));n.has(`${g}:${l}`)||e.push(p,g,l)}}for(let r of s)this.records.delete(ce(r,"forward")),this.records.delete(ce(r,"reverse"));return{inserted:o,removed:s.size}}async betweenNodes(e,t){return(await this.fillBetween(e,t)).inserted.length}async fillBetween(e,t){this.clearPaths();let n=[e,ee(t)],s=new Set([N(e),N(t)]),o=[];for(;n.length>0;){let r=n.pop(),i=N(r);this.hasNode(i)||(await this.addNode(i),o.push(i));for(let h of this.record(r).successors()){let c=N(h);s.has(c)||(n.push(h,ee(h)),s.add(c))}}return{inserted:o,nodes:s.size-2}}async extractSnarls(e){let t=0;this.snarlMode=e;for(let[n,s]of await this.overlappingSnarls(e)){let{inserted:o,nodes:r}=await this.fillBetween(n,s),i=N(n),h=N(s);this.snarlFills.push({low:Math.min(i,h),high:Math.max(i,h),nodes:r,inserted:o.length});for(let c of o)this.snarlNodes.add(c);t+=o.length}return this.stats.snarls={fills:this.snarlFills.length,inserted:this.snarlNodes.size},t}async overlappingSnarls(e){let t=[];if(e!=="none"){let n=!1;for(let s of this.sortedHandles()){let o=this.record(s),r=o.next;r!==void 0&&(n=!0,this.hasHandle(r)?He(s,r)&&t.push([s,r]):e==="overlapping"&&this.isSnarlEntryInSubgraph(o)&&t.push([s,r]))}if(!n&&e==="overlapping"&&await this.db.hasChainLinks()){let s=await this.findCoveringSnarl();s&&t.push(s)}}return t}isSnarlEntryInSubgraph(e){let t=e.successors(),n=t.find(s=>this.hasHandle(s));return n===void 0?!1:t.length>1||this.record(ee(n)).successors().length>1}recordReader(e){let t=new Map;return async n=>{let s=this.records.get(n);if(s)return s;let o=t.get(n);if(!o){if(o=await this.db.getRecord(n),e?.(),!o)throw new Error(`Node record ${n} is missing from the database`);t.set(n,o)}return o}}async findCoveringSnarl(){let e=this.recordReader(),t=async h=>{let c=h.successors(),d=c[0];return d===void 0?!1:c.length>1||(await e(ee(d))).successors().length>1},n=async h=>{let c=await e(ee(h));return c.next!==void 0?await t(c)?{kind:"snarl-exit",snarl:[ee(h),c.next]}:{kind:"chain"}:(await e(h)).next!==void 0?{kind:"chain"}:{kind:"regular"}},s=new Set,o=this.sortedHandles().flatMap(h=>this.record(h).successors()),r,i=!1;for(;!i&&o.length>0;){let h=o.shift(),c=N(h);if(!this.hasHandle(h)&&!s.has(c)){s.add(c);let d=await n(h);if(d.kind==="snarl-exit")r=d.snarl,i=!0;else if(d.kind==="chain")i=!0;else for(let f of["forward","reverse"])o.push(...(await e(ce(c,f))).successors())}}return r}extractPaths(e,t){if(this.clearPaths(),t==="none")return;let n=e?.position;this.refPath=e?.name,this.refHandle=e?.handle;let s=this.sortedHandles(),o=s.length,r=new Map;s.forEach((m,I)=>r.set(m,I));let i=new Int32Array(o+1),h=new Int32Array(o),c=[];for(let m=0;m<o;m++){let I=this.record(s[m]),$=I.gbwt().decompressArrays();h[m]=I.sequenceLen,c.push($),i[m+1]=i[m]+$.nodes.length}let d=i[o],f=new Int32Array(d),p=new Int32Array(d),y=new Uint8Array(d);for(let m=0;m<o;m++){let I=c[m];f.set(I.nodes,i[m]),p.set(I.offsets,i[m])}c.length=0;for(let m=0;m<d;m++){let I=r.get(f[m]);I===void 0?f[m]=-1:(f[m]=I,y[i[I]+p[m]]=1)}let g=n===void 0?void 0:r.get(n.handle),l=n?.gbwtOffset,b,x=(m,I,$)=>{let F=[],_=0,D=0,C=-1,H=m,k=I;for(;;){H===g&&k===l&&(C=_),$&&($.push(s[H]),F.push(k)),_+=1,D+=h[H];let j=i[H]+k,X=f[j];if(X<0)break;k=p[j],H=X}return{offsets:F,len:D,refAt:C,last:H}},P=(m,I,$,F)=>{F>=0&&(this.refId=this.paths.length,b=F),this.paths.push({path:m,offsets:I,len:$,weight:void 0,identity:void 0})},E=new Int32Array(o);for(let m=0;m<o;m++){let I=s[m];if(!Q(I)){let $=i[m],F=i[m+1]-$;for(let _=0;_<F;_++)if(y[$+_]===0){let D=[],{offsets:C,len:H,refAt:k,last:j}=x(m,_,D),X=s[j];if(k>=0||Pe(I,X)){if(P(D,C,H,k),!Q(X)){let w=r.get(ee(X));E[w]=E[w]+1}}else this.twinStarts.add(ke({node:I,offset:_}))}}}for(let m=0;m<o;m++){let I=s[m];if(Q(I)){let $=i[m],F=i[m+1]-$,_=0;for(let C=0;C<F;C++)y[$+C]===0&&(_+=1);let D=(g===void 0||b!==void 0)&&_===E[m];for(let C=0;C<F;C++)if(y[$+C]===0){let H=D?void 0:x(m,C,void 0);if(H&&(H.refAt>=0||Pe(I,s[H.last]))){let k=[],{offsets:j,len:X,refAt:w}=x(m,C,k);P(k,j,X,w)}else this.twinStarts.add(ke({node:I,offset:C}))}}}let R=this.refId===void 0?void 0:this.paths[this.refId];if(this.paths.sort((m,I)=>m.path[0]-I.path[0]||m.offsets[0]-I.offsets[0]),R&&(this.refId=this.paths.indexOf(R)),n){if(b===void 0||this.refId===void 0)throw this.clearPaths(),new Error("Could not find the reference path");let m=this.paths[this.refId],I=n.nodeOffset;for(let F of m.path.slice(0,b))I+=this.record(F).sequenceLen;let $=n.seqOffset-I;this.refInterval=[$,$+m.len],m.identity={pathHandle:e.handle,name:e.name,orientation:"forward",hapStart:$,hapEnd:$+m.len}}if(t==="distinct")this.distinctPaths(!0);else if(t==="reference-only"){if(this.refId===void 0)throw new Error("Reference path is required for reference-only output");this.paths=[this.paths[this.refId]],this.refId=0}}distinctPaths(e){let t=this.refId===void 0?void 0:this.paths[this.refId],n=t?.path,s=n&&!Oe(n)?Be(n):void 0,o=c=>s!==void 0&&wt(c,s)===0||Oe(Be(c)),r=e&&this.db.hasHaplotypeIndex;this.twinDeferred=!1,this.paths.sort((c,d)=>wt(c.path,d.path)||c.len-d.len||(c===t?-1:d===t?1:0));let i=[],h;for(let c of this.paths){let d=i[i.length-1],f=r&&c!==t&&o(c.path);this.twinDeferred||=f,d&&wt(d.path,c.path)===0&&!f?d.weight=(d.weight??1)+(c.weight??1):(c===t&&(h=i.length),i.push({...c,weight:c.weight??1}))}this.paths=i,this.refId=h}mergeDistinct(){this.twinDeferred?this.settleDeferred():this.distinctPaths(!1)}settleDeferred(){this.twinDeferred&&(this.unsettled={paths:[...this.paths],refId:this.refId},this.distinctPaths(!1))}dropTwins(){let e=this.refId===void 0?void 0:this.paths[this.refId],t=this.refInterval,n=r=>`${r.pathHandle}:${r.hapStart}-${r.hapEnd}`,s=new Set;e?.identity&&t&&s.add(n({...e.identity,hapStart:t[0],hapEnd:t[1]}));for(let r of this.paths)r!==e&&r.identity?.orientation==="forward"&&s.add(n(r.identity));let o=this.paths.filter(r=>r===e||r.identity?.orientation!=="reverse"||!s.has(n(r.identity)));o.length<this.paths.length&&(this.paths=o,this.refId=e===void 0?void 0:o.indexOf(e)),this.twinDeferred&&this.distinctPaths(!1)}keepHaplotypes(e){if(this.paths.some(r=>r.weight!==void 0))throw new Error("keepHaplotypes needs one walk per haplotype: extract with haplotypes 'all', then call mergeDistinct()");let t=this.paths.filter((r,i)=>i!==this.refId&&r.identity===void 0).length;if(t>0)throw new Error(`${t} of the window's ${this.paths.length} walks have no name, so the haplotypes to keep cannot be told from the rest; call identifyPaths() first, and check that the haplotype index was built for this graph`);let n=this.refId===void 0?void 0:this.paths[this.refId],s=this.paths.filter((r,i)=>i===this.refId||r.identity!==void 0&&e(r.identity.name)),o=new Set;for(let r of s)for(let i of r.path)o.add(N(i));for(let r of[...this.records.keys()])o.has(N(r))||this.records.delete(r);this.paths=s,this.refId=n===void 0?void 0:s.indexOf(n)}async extractChosenPaths(e,t,n,s){this.clearPaths();let o=e.position.seqOffset,r=await Zt({db:this.db,records:this.records,referenceHandle:e.handle,referencePos:{node:e.position.handle,offset:e.position.gbwtOffset},referenceLeft:o-e.position.nodeOffset,window:{start:o,end:o+t},context:s,snarls:{mode:this.snarlMode,fills:this.snarlFills,inserted:this.snarlNodes},keep:n,signal:this.signal,prefetchReferenceRange:(d,f,p)=>this.prefetchReferenceRange(d,f,p)});if(this.stats.keep=r.stats,r.stats.fallback!==void 0)return!1;let i=await this.db.pathsByHandle(),h=d=>({path:d.handles,offsets:d.offsets,len:d.len,weight:void 0,identity:{pathHandle:d.pathHandle,name:d===r.reference?e.name:i.get(d.pathHandle).name,orientation:d.orientation,hapStart:d.hapStart,hapEnd:d.hapEnd}}),c=[r.reference,...r.pieces].sort(Xt);return this.paths=c.map(h),this.refId=c.indexOf(r.reference),this.refPath=e.name,this.refHandle=e.handle,this.refInterval=[r.reference.hapStart,r.reference.hapEnd],this.dropTwins(),!0}async identifyPaths(){if(!this.db.hasHaplotypeIndex)throw new Error("The database has no HaplotypeSamples table; run gbz-haplotype-index on it");this.unsettled&&({paths:this.paths,refId:this.refId}=this.unsettled,this.unsettled=void 0,this.twinDeferred=!0);let e=await this.db.haplotypeSampleGap()??4096,t=pt(this.sortedHandles());if(t.length===0)return;let n=new Map,s=await Promise.all(t.map(([l,b])=>this.db.haplotypeSamplesInRange(l,b)));for(let l of s.flat())n.set(ke(l),l);let o=l=>{let b=0,x=t.length-1;for(;b<x;){let E=b+x+1>>1;t[E][0]<=l?b=E:x=E-1}let P=t[b];return P[0]<=l&&l<=P[1]},r=new Map;this.paths.forEach((l,b)=>{l.path.length>0&&b!==this.refId&&r.set(ke(Ge(l,0)),b)});let i=this.stats.identification;i.interval=e,i.scans=t,i.windowSamples=n.size,this.paths.forEach((l,b)=>{b!==this.refId&&i.fragmentLengths.push(l.len)});let h=this.recordReader(()=>{this.stats.identificationFetches+=1,i.graphFetches+=1}),c=l=>(i.graphLookups+=1,h(l)),d=async(l,b)=>{if(o(l.node))return n.get(ke(l));this.stats.identificationFetches+=1,i.companionSeeks+=1,b.seeks+=1;let x=await this.db.haplotypeSampleAt(l.node,l.offset);return x||(i.companionMisses+=1),x},f=new Map,p=async l=>{let b=f.get(l);if(!b){let x=await this.db.getPath(l);if(!x)throw new Error(`Path ${l} is missing from the database`);b=x.name,f.set(l,b)}return b},y=(l,b,x)=>l.orientation==="forward"?{pathHandle:l.pathHandle,orientation:"forward",base:l.pathOffset-b}:{pathHandle:l.pathHandle,orientation:"reverse",base:l.pathOffset+b+x},g=(l,b)=>l.orientation==="forward"?{pathHandle:l.pathHandle,orientation:"forward",base:l.hapStart-b}:{pathHandle:l.pathHandle,orientation:"reverse",base:l.hapEnd+b};for(let l=0;l<this.paths.length;l++){let b=this.paths[l];if(l===this.refId||b.identity)continue;let x=[],P=new Set,E={fragments:0,steps:0,seeks:0,reentries:0,twinLandings:0,end:"endmarker",pathHandle:void 0};i.chains.push(E);let R,m=0,I=l,$;for(;R===void 0;){if(this.signal?.throwIfAborted(),I!==void 0){if(P.has(I)){E.end="cycle";break}P.add(I);let H=this.paths[I];x.push({index:I,startBp:m}),E.fragments+=1;let k=m;for(let X=0;X<H.path.length;X++){let w=Ge(H,X),S=n.get(ke(w)),A=this.record(w.node).sequenceLen;if(S){R=y(S,k,A);break}k+=A}if(m+=H.len,R){E.end="in-fragment sample";break}let j=Ge(H,H.path.length-1);$=this.record(j.node).gbwt().lf(j.offset),I=void 0}if($===void 0||$.node===0){E.end="endmarker";break}let F=ke($),_=r.get(F);if(_!==void 0){let H=this.paths[_].identity;if(H){R=g(H,m),E.end="identified sibling";break}I=_;continue}this.records.has($.node)&&(E.reentries+=1),this.twinStarts.has(F)&&(E.twinLandings+=1);let D=await d($,E),C=await c($.node);if(D){R=y(D,m,C.sequenceLen),E.end="out-of-window sample";break}if(this.stats.identificationSteps+=1,E.steps+=1,m-x[x.length-1].startBp>4*e+4*C.sequenceLen){E.end="bound";break}m+=C.sequenceLen,$=C.gbwt().lf($.offset)}if(R){E.pathHandle=R.pathHandle;let F=await p(R.pathHandle);for(let{index:_,startBp:D}of x){let C=this.paths[_];C.identity=R.orientation==="forward"?{pathHandle:R.pathHandle,name:F,orientation:"forward",hapStart:R.base+D,hapEnd:R.base+D+C.len}:{pathHandle:R.pathHandle,name:F,orientation:"reverse",hapStart:R.base-D-C.len,hapEnd:R.base-D}}}}this.dropTwins()}refIndex(e){if(this.refIndexCache===void 0){let t=new Map;e.forEach((n,s)=>{let o=t.get(n);o?o.push(s):t.set(n,[s])}),this.refIndexCache=t}return this.refIndexCache}refPrefix(e){if(this.refPrefixCache===void 0){let t=[0];e.forEach((n,s)=>{t.push(t[s]+this.record(n).sequenceLen)}),this.refPrefixCache=t}return this.refPrefixCache}orderedMatches(e,t){let n=this.refIndex(t),s=new Int32Array(e.length),o=new Int32Array(e.length),r=0,i=-1;for(let h=0;h<e.length;h++){let c=n.get(e[h]);if(c){let d=qn(c,i);if(d===void 0)return;s[r]=h,o[r]=d,r+=1,i=d}}return{pathAt:s,refAt:o,count:r}}pathLen(e){let t=0;for(let n of e)t+=this.record(n).sequenceLen;return t}prefixMatches(e,t){let n=0,s=0,o=0,r=0,i=0;for(;s<e.length&&o<t.length;){let h=this.record(e[s]).sequence,c=this.record(t[o]).sequence;for(;r<h.length&&i<c.length;){if(h[r]!==c[i])return n;r+=1,i+=1,n+=1}r===h.length&&(s+=1,r=0),i===c.length&&(o+=1,i=0)}return n}suffixMatches(e,t){let n=0,s=0,o=0,r=0,i=0;for(;s<e.length&&o<t.length;){let h=this.record(e[e.length-s-1]).sequence,c=this.record(t[t.length-o-1]).sequence;for(;r<h.length&&i<c.length;){if(h[h.length-r-1]!==c[c.length-i-1])return n;r+=1,i+=1,n+=1}r===h.length&&(s+=1,r=0),i===c.length&&(o+=1,i=0)}return n}align(e,t,n){let s=this.pathLen(e),o=this.pathLen(t),r=this.prefixMatches(e,t),i=this.suffixMatches(e,t);r+i>s&&(i=s-r),r+i>o&&(i=o-r),K(n,"M",r),hn(n,s-r-i,o-r-i),K(n,"M",i)}sharedWeight(e,t){let n=this.refIndex(t),s=0;for(let o of e)n.has(o)&&(s+=this.record(o).sequenceLen);return s}editsAgainst(e,t){let n=this.orderedMatches(e,t);n?this.stats.orderedAlignments+=1:this.stats.lcsAlignments+=1;let s=n??Fn(Ut(e,t,f=>this.record(f).sequenceLen)[0]),o=[],r=this.refPrefix(t),i=(f,p,y,g)=>{f===p?K(o,"D",r[g]-r[y]):y===g?K(o,"I",this.pathLen(e.slice(f,p))):this.align(e.slice(f,p),t.slice(y,g),o)},h=0,c=0,d=0;for(let f=0;f<s.count;f++){let p=s.pathAt[f],y=s.refAt[f];(c!==p||d!==y)&&i(c,p,d,y);let g=this.record(e[p]).sequenceLen;K(o,"M",g),h+=g,c=p+1,d=y+1}return i(c,e.length,d,t.length),{edits:o,matched:h,matches:s}}alignment(e){let t=this.paths[e];if(this.refId===void 0||e===this.refId||!t)return;let n=this.paths[this.refId].path,s;if(Oe(n)&&(t.identity===void 0||!Oe(Be(t.path))))s={...this.editsAgainst(t.path,n),flipped:!1};else{let o=Be(t.path),r=this.sharedWeight(t.path,n);if(this.sharedWeight(o,n)===0)s={...this.editsAgainst(t.path,n),flipped:!1};else if(r===0)s={...this.editsAgainst(o,n),flipped:!0};else{let h=this.editsAgainst(t.path,n),c=this.editsAgainst(o,n);s=c.matched>h.matched?{...c,flipped:!0}:{...h,flipped:!1}}}return s}alignToRef(e){return this.settleDeferred(),this.alignment(e)?.edits.map(([t,n])=>`${n}${t}`).join("")}alignments(){this.settleDeferred();let e=this.referenceInterval;if(this.refId===void 0||!e)throw new Error("Alignments need a reference path");let t=this.paths[this.refId].path,n=this.refPrefix(t)[t.length],s=(d,f,p,y)=>{let g=Gn(d),l=this.paths[p[0]],b=this.paths[p[p.length-1]],x=l.identity,P=x?.orientation==="forward",[E,R]=P?[l,b]:[b,l];return{strand:f,refStart:e.start+g.leading,refEnd:e.start+n-g.trailing,edits:g.edits,weight:l.weight,path:p.flatMap(m=>this.paths[m].path),start:Ge(l,0),pieces:p,soloAligned:y,identity:x===void 0?void 0:{pathHandle:x.pathHandle,name:x.name,hapStart:x.name.fragment+E.identity.hapStart,hapEnd:x.name.fragment+R.identity.hapEnd,walkForward:P}}},o=d=>d.soloAligned.reduce((f,p)=>f+p,0),r=d=>d.pieces.reduce((f,p)=>f+this.paths[p].len,0),i=d=>2*o(d)>=r(d),h=d=>{let f=d[0],p=d[d.length-1],y=f.identity.walkForward;if(d.some((k,j)=>k.strand!==f.strand||k.identity.walkForward!==y||j>0&&k.identity.hapStart<d[j-1].identity.hapEnd))return;let g=y?d:[...d].reverse(),l=g.flatMap(k=>k.pieces),b=g.flatMap(k=>k.soloAligned),x=f.strand==="+"!==y,P=l.map(k=>this.paths[k]),E=P.slice(1).map((k,j)=>{let X=P[j].identity;return y?k.identity.hapStart-X.hapEnd:X.hapStart-k.identity.hapEnd}),R=x?[...P].reverse():P,m=x?[...E].reverse():E,I=R.flatMap(k=>x?Be(k.path):k.path),{edits:$}=this.editsAgainst(I,t),F=an($,R.map(k=>k.len)),_=new Map((x?[...l].reverse():l).map((k,j)=>[k,F[j]])),D=k=>2*k.pieces.reduce((j,X)=>j+_.get(X),0)>=o(k);if(!D(f)||!D(p))return;let C=[],H=0;return R.slice(0,-1).forEach((k,j)=>{H+=k.len,C.push([H,m[j]])}),s(Qn($,C),f.strand,l,b)},c=[];return this.paths.forEach((d,f)=>{if(f===this.refId)return;let{edits:p,flipped:y}=this.alignment(f),g=d.identity,l=g?g.orientation==="forward"!==y:!y;c.push(s(p,l?"+":"-",[f],an(p,[d.len])))}),jn(c,i,h).map(d=>{let{edits:f,identity:p,pieces:y,soloAligned:g,...l}=d,b={...l,cigar:Kn(f)};return p?{...b,resolved:!0,name:p.name,label:fe({...p.name,fragment:p.hapStart,end:p.hapEnd}),pathHandle:p.pathHandle,hapStart:p.hapStart,hapEnd:p.hapEnd}:{...b,resolved:!1}})}pairAlignments(e){let{target:t,query:n,...s}=e,o=this.paths.flatMap(d=>{let{identity:f}=d;return f?[{name:f.name,start:f.name.fragment+f.hapStart,steps:Ke(d,f)}]:[]}),r=d=>f=>f.sample===d.sample&&f.haplotype===d.haplotype,i=r(t),h=n?r(n):d=>!i(d),c=d=>this.record(ce(d,"forward")).sequence;return o.filter(d=>i(d.name)).flatMap(d=>o.filter(f=>h(f.name)).flatMap(f=>Wt({...s,query:f.steps,target:d.steps,sequenceOf:c}).map(p=>({query:f.name,queryStart:f.start+p.queryStart,queryEnd:f.start+p.queryEnd,strand:p.strand,target:d.name,targetStart:d.start+p.targetStart,targetEnd:d.start+p.targetEnd,cigar:Vt(p.edits),matches:p.edits.reduce((y,[g,l])=>y+(g==="="?l:0),0),columns:p.edits.reduce((y,[,g])=>y+g,0),sharedBases:p.sharedBases}))))}canonicalEdges(e){let t=[];for(let n of["forward","reverse"]){let s=ce(e,n);for(let o of this.record(s).successors())this.hasHandle(o)&&He(s,o)&&t.push([n==="reverse"?1:0,N(o),Q(o)?1:0])}return t.sort((n,s)=>n[0]-s[0]||n[1]-s[1]||n[2]-s[2]),t.filter((n,s)=>s===0||n[0]!==t[s-1][0]||n[1]!==t[s-1][1]||n[2]!==t[s-1][2])}async stableName(){let e=new TextEncoder,t=[];for(let n of this.sortedHandles())if(!Q(n)){let s=N(n),o=`S ${s} ${this.record(n).sequence}
|
|
2
2
|
`;for(let[r,i,h]of this.canonicalEdges(s))o+=`L ${s} ${r?"-":"+"} ${i} ${h?"-":"+"}
|
|
3
3
|
`;t.push(e.encode(o))}return rn(t)}async toGFA(e={}){this.settleDeferred();let t=e.cigar??!1,n=[this.refPath?`H VN:Z:1.1 RS:Z:${this.refPath.sample}`:"H VN:Z:1.1",...on(sn(await this.stableName(),await this.db.graphName()))],s=this.sortedHandles();for(let c of s)Q(c)||n.push(`S ${N(c)} ${this.record(c).sequence}`);let o=c=>Q(c)?"-":"+";for(let c of s)for(let d of this.record(c).successors())this.hasHandle(d)&&He(c,d)&&n.push(`L ${N(c)} ${o(c)} ${N(d)} ${o(d)} 0M`);let r=(c,d,f,p,y)=>{let g=Ke(c,d).map(x=>`${Q(x)?"<":">"}${N(x)}`).join(""),l=c.weight===void 0?"":` WT:i:${c.weight}`,b=y===void 0?"":` CG:Z:${y}`;return`W ${f.sample} ${f.haplotype} ${f.contig} ${f.fragment} ${p} ${g}${l}${b}`},i=this.refPath?.contig??"unknown";this.refId!==void 0&&this.refPath&&this.refInterval&&n.push(r(this.paths[this.refId],void 0,{...this.refPath,fragment:this.refPath.fragment+this.refInterval[0]},this.refPath.fragment+this.refInterval[1],void 0));let h=1;return this.paths.forEach((c,d)=>{if(d!==this.refId){let f=e.names!=="anonymous"?c.identity:void 0,p=t?this.alignToRef(d):void 0;n.push(f?r(c,f,{...f.name,fragment:f.name.fragment+f.hapStart},f.name.fragment+f.hapEnd,p):r(c,void 0,{sample:"unknown",contig:i,haplotype:h,fragment:0},c.len,p)),h+=1}}),`${n.join(`
|
|
4
4
|
`)}
|
|
@@ -6,4 +6,4 @@ import{a as ce,b as N,c as Ee,d as Q,e as ee,f as Ft,g as Ue,h as We,i as qt,j a
|
|
|
6
6
|
`).filter(p=>p!=="")),n=(f,p)=>f.filter(y=>y.startsWith(`${p} `)),s=cs(t.flat()),o=0,r=t.map(f=>{let p=n(f,"W").map(hs),y=o;for(let g of p.filter(l=>l.fields[1]===is)){let l=+g.fields[2]+y;g.fields[2]=String(l),g.name=g.fields.slice(1,4).join(" "),o=Math.max(o,l)}return p}),h=[...Ot([...r.flatMap(f=>f.slice(0,1)),...r.flatMap(f=>f.slice(1))],f=>f.name).values()].flatMap(f=>fs(f,s,e)),c=new Set(t.flatMap(f=>n(f,"L")));for(let f of h)for(let p of ls(f))!c.has(p.forward)&&!c.has(p.reverse)&&c.add(p.forward);return`${[...new Set([...n(t[0],"H"),...t.flatMap(f=>n(f,"S")),...c,...h.map(f=>f.fields.join(" "))])].join(`
|
|
7
7
|
`)}
|
|
8
8
|
`}var In=class extends Error{constructor(a,e){super(e.length===0?`the graph names no reference sample (gbwt_reference_samples) and the anchor "${a}" maps to none; set referenceSample`:`the anchor "${a}" is none of the graph's reference samples (${e.join(", ")}); set referenceSample or map it through assemblyNameToPanSN`),this.name="NoReferenceSampleError"}},En=class extends Error{constructor(a,e,t){super(`this ${e.toLocaleString()} bp window reads more than nodeLimit (${a.toLocaleString()}) graph nodes; zoom in to about ${t.toLocaleString()} bp or raise nodeLimit`),this.fitsBp=t,this.name="NodeLimitError",this.regionTooLarge=!0}};function kn(a){return`${a.sample}#${a.haplotype}`}function ps(a,e){let t=kn(a);return e===void 0||e.some(n=>Bt(t,n))}async function us(a){return(await a.tag("gbwt_reference_samples")??"").split(/\s+/).filter(e=>e!=="")}function vn(a,e){let t=a.toLowerCase(),n=_t(a)?.toLowerCase();return e.find(s=>s===a)??e.find(s=>s.toLowerCase()===t)??e.find(s=>s.toLowerCase()===n)}function ws({configured:a,anchorPrefix:e,referenceSamples:t}){if(a!=="")return a;let n=vn(Ct(e),t)??(t.length===1?t[0]:void 0);if(n===void 0)throw new In(e,t);return n}async function gs(a,e,t){let n=(await a.paths()).find(s=>s.isIndexed&&s.name.sample===e&&s.name.contig===t);return n?{sample:n.name.sample,contig:t,haplotype:n.name.haplotype}:void 0}function Pn(a,e,t){if(a instanceof Error&&(a.name==="SubgraphLimitError"||/^Subgraph size limit of \d+ nodes exceeded/.test(a.message))){let s=a.walkedBp,o=typeof s=="number"&&s>0?Math.floor(s*.8):Math.floor(t/2);return new En(e,t,Math.max(o,1))}else return}var ms={context:1e3,snarls:"contained",limit:1e5};async function ys(a,e,t,n,s){return a.getSubgraphs({...s,path:e,start:t,end:n,haplotypes:"all"}).catch(o=>{throw Pn(o,s.limit,n-t)??o})}async function bs(a,e){let t=await a.paths();return Sn(await Promise.all(e.map(n=>n.toGFA())),(n,s,o,r)=>t.some(({name:i})=>i.sample===n&&i.haplotype===s&&i.contig===o&&i.fragment===r))}async function xs(a,e,t,n,s){if(!e)return"";let o=await ys(a,e,t,n,s);if(o.length===1)return An(o[0].toCompactSubgraph());let r=await bs(a,o);return r&&Tt(r)||r}function Ss(a,e){let t=1/0,n=-1/0;for(let i of a)t=Math.min(t,i),n=Math.max(n,i);let s=n-t+1,o=a.length>0&&s<=16*a.length?new Int32Array(s).fill(-1):void 0,r=new Map;return a.forEach((i,h)=>{o?o[i-t]=h:r.set(i,h)}),i=>{let h=N(i),c=o!==void 0&&h>=t&&h<=n,d=c?o[h-t]:r.get(h)??-1;return d>=0?d:(c?o[h-t]=e.length:r.set(h,e.length),e.push(String(h)),e.length-1)}}var Is=/^(.*)\[(\d+)-(\d+)\]$/;function An(a){let e=Array.from(a.nodeIds,String),t=Ss(a.nodeIds,e),n=a.nodeIds.length,s=a.edges.length/2,o=new Int32Array(s),r=new Int32Array(s),i=new Uint8Array(s);for(let l=0;l<s;l++){let b=a.edges[2*l],x=a.edges[2*l+1];o[l]=t(b),r[l]=t(x),i[l]=(Q(b)?1:0)|(Q(x)?2:0)}let h=a.paths.filter(l=>l.steps.length>0),c=new Int32Array(h.length+1);h.forEach((l,b)=>{c[b+1]=c[b]+l.steps.length});let d=new Int32Array(c[h.length]),f=new Uint8Array(d.length),p=new Float64Array(h.length),y=new Float64Array(h.length),g=h.map((l,b)=>{let x=Is.exec(l.name);p[b]=x?+x[2]:0,y[b]=x?+x[3]:-1;let P=c[b];for(let E of l.steps)d[P]=t(E),f[P++]=Q(E)?1:0;return x?x[1]:l.name});return{nodes:{names:e,lengths:Int32Array.from(a.nodeSequences,l=>l.length),refs:new Int32Array(n).fill(-1),starts:new Float64Array(n),ranks:new Int32Array(n),refNames:[]},links:{from:o,to:r,strands:i},walks:{names:g,starts:p,ends:y,offsets:c,steps:d,reversed:f}}}export{le as a,St as b,En as c,kn as d,ps as e,us as f,ws as g,gs as h,Pn as i,ms as j,xs as k};
|
|
9
|
-
//# sourceMappingURL=chunk-
|
|
9
|
+
//# sourceMappingURL=chunk-NB4X56M3.js.map
|