jbrowse-plugin-graphgenomeviewer 8.0.2 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/GbzBaseSyntenyAdapter-OHJ4QDMX.js +2 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-OHJ4QDMX.js.map +7 -0
- package/dist/chunks/{GraphGenomeView-667ZUNDI.js → GraphGenomeView-RWQUR473.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-7M3Q635V.js → GraphTrackSettingsDialog-IQZGEFCA.js} +2 -2
- package/dist/chunks/{HighlightColorDialog-4F34Q4PY.js → HighlightColorDialog-LCBGD2ZA.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-BAEMS5WG.js → LinearGraphDisplay-YDUG4J53.js} +2 -2
- package/dist/chunks/{MinigraphBubbleAdapter-G25V6MZL.js → MinigraphBubbleAdapter-EVYS6XUZ.js} +2 -2
- package/dist/chunks/{RgfaTabixAdapter-JPTUWO2Z.js → RgfaTabixAdapter-QD2AJSBK.js} +2 -2
- package/dist/chunks/{WalkFormsAdapter-PBN7BJZW.js → WalkFormsAdapter-SG4LLHHS.js} +2 -2
- package/dist/chunks/{WalkTabixSyntenyAdapter-27WDE5JF.js → WalkTabixSyntenyAdapter-NEZMRCRO.js} +2 -2
- package/dist/chunks/{chunk-JOYKGTDE.js → chunk-5EWKB2JM.js} +2 -2
- package/dist/chunks/{chunk-2PNGGCQJ.js → chunk-6ZZJCKX5.js} +2 -2
- package/dist/chunks/{chunk-2PNGGCQJ.js.map → chunk-6ZZJCKX5.js.map} +1 -1
- package/dist/chunks/{chunk-O5FDMVL3.js → chunk-B7MGDESF.js} +2 -2
- package/dist/chunks/{chunk-CJAV55QB.js → chunk-BJHWGRMP.js} +1 -1
- package/dist/chunks/{chunk-CJAV55QB.js.map → chunk-BJHWGRMP.js.map} +1 -1
- package/dist/chunks/{chunk-IAXUZMOX.js → chunk-CNCYMJ5E.js} +2 -2
- package/dist/chunks/{chunk-IAXUZMOX.js.map → chunk-CNCYMJ5E.js.map} +2 -2
- package/dist/chunks/{chunk-2V75YPTT.js → chunk-CVHKXFVS.js} +2 -2
- package/dist/chunks/{chunk-2V75YPTT.js.map → chunk-CVHKXFVS.js.map} +2 -2
- package/dist/chunks/chunk-CZI7IP5S.js +2 -0
- package/dist/chunks/chunk-CZI7IP5S.js.map +7 -0
- package/dist/chunks/chunk-HAAABGE7.js +2 -0
- package/dist/chunks/{chunk-JMRW3IGK.js → chunk-IK3MQ4ZJ.js} +2 -2
- package/dist/chunks/chunk-IK3MQ4ZJ.js.map +7 -0
- package/dist/chunks/chunk-IL5HOUFN.js +2 -0
- package/dist/chunks/chunk-IL5HOUFN.js.map +7 -0
- package/dist/chunks/chunk-MJS65EKE.js +3 -0
- package/dist/chunks/chunk-MJS65EKE.js.map +7 -0
- package/dist/chunks/chunk-MK3U4D2U.js +2 -0
- package/dist/chunks/chunk-MK3U4D2U.js.map +7 -0
- package/dist/chunks/{chunk-3EQNVA3F.js → chunk-OG7MODXE.js} +2 -2
- package/dist/chunks/{chunk-3EQNVA3F.js.map → chunk-OG7MODXE.js.map} +2 -2
- package/dist/chunks/{chunk-FY7X6253.js → chunk-OGXVDZPS.js} +2 -2
- package/dist/chunks/{chunk-FY7X6253.js.map → chunk-OGXVDZPS.js.map} +2 -2
- package/dist/chunks/{chunk-NLS74JSZ.js → chunk-PDLKFVVK.js} +1 -1
- package/dist/chunks/{chunk-NLS74JSZ.js.map → chunk-PDLKFVVK.js.map} +1 -1
- package/dist/chunks/{chunk-I6F25EXY.js → chunk-PKMASUMB.js} +2 -2
- package/dist/chunks/{chunk-XB5KC2EZ.js → chunk-T2VC3EEL.js} +1 -1
- package/dist/chunks/{chunk-XB5KC2EZ.js.map → chunk-T2VC3EEL.js.map} +1 -1
- package/dist/chunks/chunk-TBNAAP6E.js +3 -0
- package/dist/chunks/chunk-TBNAAP6E.js.map +7 -0
- package/dist/chunks/{chunk-5RHNR3TH.js → chunk-VKZALU57.js} +1 -1
- package/dist/chunks/{chunk-5RHNR3TH.js.map → chunk-VKZALU57.js.map} +1 -1
- package/dist/chunks/chunk-W7IHIVSE.js +2 -0
- package/dist/chunks/{chunk-XWCLYB5C.js.map → chunk-W7IHIVSE.js.map} +4 -4
- package/dist/chunks/{renderSvg-YNA5VK6A.js → renderSvg-APVNMW6O.js} +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +2 -2
- package/package.json +4 -4
- package/src/GraphGenomeView/components/HoverTooltip.tsx +8 -0
- package/src/RgfaTabixAdapter/test_data/walks5_skip.GRCh38.walks.bed.gz +0 -0
- package/src/RgfaTabixAdapter/test_data/walks5_skip.GRCh38.walks.bed.gz.tbi +0 -0
- package/src/RgfaTabixAdapter/walkFiles.test.ts +21 -0
- package/src/RgfaTabixAdapter/walkReader.ts +20 -15
- package/src/version.ts +1 -1
- package/dist/chunks/GbzBaseSyntenyAdapter-EGNUOKB2.js +0 -2
- package/dist/chunks/GbzBaseSyntenyAdapter-EGNUOKB2.js.map +0 -7
- package/dist/chunks/chunk-DG3E6BSX.js +0 -3
- package/dist/chunks/chunk-DG3E6BSX.js.map +0 -7
- package/dist/chunks/chunk-HLAQQI6G.js +0 -2
- package/dist/chunks/chunk-HLAQQI6G.js.map +0 -7
- package/dist/chunks/chunk-JMRW3IGK.js.map +0 -7
- package/dist/chunks/chunk-Q7QC2EQU.js +0 -2
- package/dist/chunks/chunk-RHYBJCA4.js +0 -2
- package/dist/chunks/chunk-RHYBJCA4.js.map +0 -7
- package/dist/chunks/chunk-X7YIGIYW.js +0 -2
- package/dist/chunks/chunk-X7YIGIYW.js.map +0 -7
- package/dist/chunks/chunk-XWCLYB5C.js +0 -2
- package/dist/chunks/chunk-ZGTG74GE.js +0 -3
- package/dist/chunks/chunk-ZGTG74GE.js.map +0 -7
- /package/dist/chunks/{GraphGenomeView-667ZUNDI.js.map → GraphGenomeView-RWQUR473.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-7M3Q635V.js.map → GraphTrackSettingsDialog-IQZGEFCA.js.map} +0 -0
- /package/dist/chunks/{HighlightColorDialog-4F34Q4PY.js.map → HighlightColorDialog-LCBGD2ZA.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-BAEMS5WG.js.map → LinearGraphDisplay-YDUG4J53.js.map} +0 -0
- /package/dist/chunks/{MinigraphBubbleAdapter-G25V6MZL.js.map → MinigraphBubbleAdapter-EVYS6XUZ.js.map} +0 -0
- /package/dist/chunks/{RgfaTabixAdapter-JPTUWO2Z.js.map → RgfaTabixAdapter-QD2AJSBK.js.map} +0 -0
- /package/dist/chunks/{WalkFormsAdapter-PBN7BJZW.js.map → WalkFormsAdapter-SG4LLHHS.js.map} +0 -0
- /package/dist/chunks/{WalkTabixSyntenyAdapter-27WDE5JF.js.map → WalkTabixSyntenyAdapter-NEZMRCRO.js.map} +0 -0
- /package/dist/chunks/{chunk-JOYKGTDE.js.map → chunk-5EWKB2JM.js.map} +0 -0
- /package/dist/chunks/{chunk-O5FDMVL3.js.map → chunk-B7MGDESF.js.map} +0 -0
- /package/dist/chunks/{chunk-Q7QC2EQU.js.map → chunk-HAAABGE7.js.map} +0 -0
- /package/dist/chunks/{chunk-I6F25EXY.js.map → chunk-PKMASUMB.js.map} +0 -0
- /package/dist/chunks/{renderSvg-YNA5VK6A.js.map → renderSvg-APVNMW6O.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Ca as He,Da as $e,Ea as Ke,Eb as Je,Fa as Xe,Gb as G,Hb as be,Ia as Ue,Ib as fe,Ma as Fe,Mb as Ze,Na as ie,Ob as Qe,Qa as Ye,Rb as he,Ta as ze,Ua as le,Vb as et,Ya as ce,_b as tt,a as Se,b as X,ca as Ae,cb as Ve,ec as nt,f as Q,g as ee,gc as rt,ib as qe,ka as S,kb as pe,la as ae,nb as je,ra as Ie,sa as Be,ta as We,ua as se,wa as Ge,xa as De,yb as ue,zb as de}from"./chunk-ZGTG74GE.js";import{D as oe,f as Ee,m as I,p as re,q as Te,r as B}from"./chunk-XWCLYB5C.js";import{E as ne,T as Oe,U as Ne,Z as ve,n as E,p as F,q as te,y as _e}from"./chunk-2V75YPTT.js";import{b as O,c as W}from"./chunk-CJAV55QB.js";import{c as Z}from"./chunk-FY7X6253.js";import{e as K}from"./chunk-3WG3GF2A.js";import{b as Pe,d as M,e as Le,f as Me,g as U,h as Ce}from"./chunk-NIEZKWQV.js";import{a as T,b as u,c as k,d as m}from"./chunk-JMBDTNUR.js";var Lt="data-pans-with-drawing";function ot(e,t){return{position:"absolute",left:0,top:0,pointerEvents:"none",overflow:t,zIndex:e}}var C=m(function({model:t,zIndex:n,overflow:o="hidden",testId:r,pansWithDrawing:a,children:l}){return u("svg",{style:{...ot(n,o),userSelect:a?"none":void 0},width:t.paneWidth,height:t.canvasHeight,"data-testid":r,...a?{[Lt]:""}:{},children:l})}),at=m(function({model:t,children:n}){let{scaleX:o,scaleY:r,translateX:a,translateY:l}=t;return u("g",{transform:`translate(${a} ${l}) scale(${o} ${r})`,children:n})});function _({model:e,zIndex:t,shown:n=!0,testId:o,paint:r}){let a=Ce(null);return Le(()=>{if(n)return Se(()=>{let l=a.current,i=l?.getContext("2d");if(l&&i){let d=e.paneWidth,c=e.canvasHeight;Ae(rt());let p=Je(l,d,c);i.setTransform(p,0,0,p,0,0),i.clearRect(0,0,d,c),r(i,p)}})},[e,n,r]),u("canvas",{ref:a,"data-testid":n?o:void 0,style:{...ot(t),display:n?"block":"none"}})}var Mt=m(function({model:t}){let{bubbleHalos:n,hoveredBubble:o}=t;if(n.length===0)return null;let r=t.contigThickness*Ze;return u(C,{model:t,zIndex:2,testId:"graph-bubble-halos",children:u(at,{model:t,children:n.filter(a=>!a.whole&&(!a.tick||o&&O(a.bubble,o))).map(a=>u("path",{d:a.path,fill:"none",stroke:S[a.kind],strokeOpacity:o&&O(a.bubble,o)?.45:t.bubbleFaded(a)?.06:.22,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"},W(a.bubble)))})})}),In=Mt;var st=["#d4735e","#d8a94a","#c98aa4"],Ct="#e6e6e6",_t="#555",Et="bold 11px sans-serif";var ge=e=>st[e]??Ct;function Y(e){let t=String.fromCharCode(65+e%26);return e<26?t:Y(Math.floor(e/26)-1)+t}var z=st.length;function it(e,t,n){e.font=Et,e.textAlign="center",e.textBaseline="middle";for(let{row:o,start:r,bp:a,block:l}of t){let i=n.x(r),d=n.x(r+a)-i,c=n.rowCentre(o)-n.barPx/2;e.fillStyle=ge(l),e.fillRect(i,c,d,n.barPx),e.strokeStyle=_t,e.lineWidth=1,e.strokeRect(i+.5,c+.5,d-1,n.barPx-1),d>=12&&n.barPx>=9&&(e.fillStyle="#111",e.fillText(Y(l),i+d/2,n.rowCentre(o)))}}var R=18,me=32,pt="rgba(160, 160, 160, 0.45)",Nt="#18181c",vt=6,ut=7,Tt="#b8b8c0",V=Be-4,At="rgba(119, 119, 119, 0.85)",It=15,lt=10;function j(e){return e.kind==="fill"?e.width??R:R}var ke=e=>e.length>1?3:4;function D(e){switch(e.kind){case"fill":return e.height??8;case"bands":return ke(e.bands)*e.bands.length;case"line":return 3;case"halo":case"overhang":return 10;case"outline":case"tick":return e.height;case"glyph":return 15;case"bracket":return 7;case"blank":return 0}}function Nr(e){return e.reduce((t,n)=>n.swatch?Math.max(t,j(n.swatch)):t,0)}function vr(e){return e.reduce((t,n)=>n.swatch?Math.max(t,Math.ceil(D(n.swatch))+3):t,It)}var y=e=>[{offset:0,color:e}];function q(e,t,n){return{key:e,label:n,swatch:{kind:"fill",stops:y(t),width:lt,height:lt,edged:!0}}}function ct(e){return e.flatMap((t,n)=>[{offset:n/e.length,color:t},{offset:(n+1)/e.length,color:t}])}function Bt(e){let t=e.openBubble;if(!t)return[];let n=e.bubbleHalos.find(o=>O(o.bubble,t));return[{key:"open",label:`open: ${n?.label??"bubble"}`,swatch:n?{kind:"halo",color:S[n.kind]}:{kind:"blank"},closesBubble:!0}]}function Wt(e){let t=e.walkLift?void 0:e.referenceRampDomain;if(!t)return[];let n=Math.round(t.start),o=Math.round(t.end);return[{key:"ramp",label:`position on ${e.graph?Z(e.graph):"reference"}`,swatch:{kind:"fill",stops:I,width:me},under:`${n.toLocaleString("en-US")}-${o.toLocaleString("en-US")} (${ne(o-n)})`},...e.referenceRampDrawsOffReference?[q("off",B,"off the reference")]:[]]}function Gt(e){let t=e.walkLift;if(t)return t.walks.map(r=>oe(r.encoding));if(e.effectiveColorScheme==="reference-position")return[I];let n=e.referenceStripBlocks.map(r=>r.colors[0]).filter((r,a,l)=>r!==l[a-1]),o=Math.min(vt,n.length);return[o===0?y(re):Array.from({length:o},(r,a)=>({offset:o>1?a/(o-1):0,color:n[o>1?Math.round(a*(n.length-1)/(o-1)):0]}))]}function Dt(e){if(!e.referenceStripShown)return[];let t=(e.walkLift?.walks.length??0)>1;return[{key:"strip",label:`reference${t?", a row per walk":""}`,swatch:{kind:"bands",bands:Gt(e)}},...e.referenceStripFaded?[q("strip-faded",re,e.walkLift?`reference not on ${t?"that row's walk":e.liftedWalksLabel}`:"reference outside the open bubble")]:[],...e.referenceStripOverhangs?[{key:"overhang",label:"graph runs past this edge",swatch:{kind:"overhang"}}]:[]]}function Ht(e){let t=new Map;for(let n of e.bubbleHalos)if(!n.whole){let o=S[n.kind],r=t.get(o)??new Set;r.add(ae[n.kind]),t.set(o,r)}return[...t].map(([n,o])=>{let r=[...o].join(" or ");return{key:`halo-${n}`,label:r===ae.superbubble?r:`${r} bubble`,swatch:{kind:"halo",color:n}}})}function dt(e){let{graph:t}=e;return t&&e.deletions.length>0?[{key:"deletion",label:_e(Z(t)),swatch:{kind:"line",color:e.walkLift?pt:Nt,dashed:!0}}]:[]}function we(e,t,n,o){return{key:e,label:t,swatch:{kind:"fill",stops:y(o),width:me,height:n}}}var $t=e=>e>=10?Math.round(e):Math.round(e*10)/10;function Kt(e){let{graph:t,contigThickness:n,depthRange:o}=e;if(!t||!e.drawsNodes||e.walkRowBars)return[];if(e.nodeWidth==="frequency"){let c=t.nodes.some(p=>p.frequency!==void 0);return Oe(n).map(({label:p,widthPx:b})=>we(`width-${p}`,c?`AF ${p}`:`${p} of haplotypes`,b,B))}if(e.nodeWidth!=="depth"||!o||o.min===o.max)return[];let r=t.paths?.length??0,a=r>0,l=[...new Set([o.max,o.mean,o.min].map(a?Math.round:$t))],i=l[0]>r,d=c=>i?`${c.toLocaleString("en-US")} walk pass${c===1?"":"es"}`:`${c.toLocaleString("en-US")} walk${c===1?"":"s"}`;return l.map(c=>we(`width-${c}`,a?d(c):`depth ${c.toLocaleString("en-US")}`,Ne({depth:c},n,"depth",o.mean),B))}function Xt(e){let t=e.busiestLink;return!e.drawsNodes||e.walkRowBars||e.linkWidth!=="walks"||t===0?[]:(t>1?[t,1]:[1]).map(o=>we(`link-width-${o}`,`${o.toLocaleString("en-US")} walk${o===1?"":"s"}`,e.connectorThickness*ve(o,t,"walks"),At))}function Ut(e){return e.genePins.some(t=>t.exonsByNode.length>0)?[{key:"exon",label:"exon",swatch:{kind:"outline",color:G,stroke:2,radius:5,height:8}}]:[]}function Ft(e){let t=e.foldNote;return t?[{key:"fold",label:t}]:[]}function Yt(e){return e.pathLegend.map(({name:t,label:n,color:o})=>({key:`path-${t}`,label:n,swatch:{kind:"line",color:o}}))}function N(e,t,n){return{key:e,label:n,swatch:{kind:"fill",stops:t,height:ut,square:!0}}}function zt(e){let{roles:t,haplotypeTube:n,bundled:o,values:r,logWidths:a,foldBp:l,forwardReads:i,reverseReads:d,substitution:c,insertion:p,deletion:b}=e.tubeMapKeys,h=e.readsShown,s=[];if(r){s.push(N("value-reference",y(pe),"reference"));for(let{value:f,color:g}of r)s.push(N(`value-${f}`,y(g),f))}return t&&s.push(N("ref",y(pe),"reference"),N("hap",y(n),o?"shared route, \xD7n haplotypes":"haplotype")),i&&s.push(N("fwd",ct(Q),"read on the forward strand")),d&&s.push(N("rev",ct(ee),"read on the reverse strand")),h&&h.shown<h.total&&s.push({key:"sampled",label:`${h.shown.toLocaleString("en-US")} of ${h.total.toLocaleString("en-US")} reads shown`,swatch:{kind:"blank"}}),c&&s.push({key:"sub",label:"read mismatch",swatch:{kind:"glyph",char:"A"}}),p&&s.push({key:"ins",label:"read insertion",swatch:{kind:"glyph",char:"*"}}),b&&s.push(N("del",y("grey"),"read deletion")),l!==void 0&&s.push({key:"tube-fold",label:`haplotype variant < ${ne(l)}`,swatch:{kind:"tick",color:ze(),height:ut,backing:Tt}}),a&&s.push({key:"log",label:"width grows with log of length",swatch:{kind:"bracket"}}),s}function Vt(e){return e.kind==="gene"?{kind:"outline",color:Ie,stroke:1.5,radius:0,height:V}:{kind:"fill",stops:e.kind==="bar"&&e.ramp?I:y(e.fill),height:e.kind==="gap"?e.px:V}}function qt(e){let t=new Set(e.sharedBlocks?.map(o=>o.block)),n=o=>({kind:"fill",stops:y(ge(o)),height:V});return[...[...t].filter(o=>o<z).sort((o,r)=>o-r).map(o=>({key:`block-${o}`,label:`${Y(o)}: off the reference, walked by several rows`,swatch:n(o)})),...[...t].some(o=>o>=z)?[{key:"block-more",label:"more shared blocks",swatch:n(z)}]:[]]}function jt(e){let t=e.walkRowBars;if(!t)return[];let n=[t.reference,...t.rows].flatMap(r=>r.call??[]),o=(r,a,l)=>({key:r,label:l,swatch:{kind:"tick",color:a,height:V}});return[...He(t,{ramp:e.referenceRampDomain,genes:e.walkRowGeneKey,annotation:e.walkRowAnnotation}).map(r=>({key:`rows-${r.label}`,label:r.label,swatch:r.note?void 0:Vt(r.swatch)})),...qt(e),...n.some(r=>r.spanningReads!==0)?[o("call",$e,"allele length called for this walk")]:[],...n.some(r=>r.spanningReads===0)?[o("unbacked",Ke,"called with no read spanning it")]:[],...n.some(r=>r.agrees===!1)?[o("disagrees",Xe,`walk and call over ${Math.round(.1*100)}% apart`)]:[]]}function Jt(e,t){let n=et(t,e.walkReference);return{key:`walk-${t.name}`,strong:e.walkLabel(t.name),label:n.delta+n.gaps+n.reversed,swatch:{kind:"fill",stops:oe(t.encoding),width:n.shades?me:R},under:n.scale,title:n.hover,walk:t}}function bt(e,t){return[...e.liftPaintsOffReference?[q("lift-off",B,"off the reference")]:[],q("faded",pt,t)]}function Zt(e){let t=e.walkLift;if(!t||e.facetPanels)return[];let n=t.walks.map(r=>Jt(e,r)),o=e.graph?he(e.graph,t,e.liftedWalksLabel):`not on ${e.liftedWalksLabel}`;return[...n,...bt(e,o)]}function Tr(e){let{graph:t,facetPanels:n}=e;if(!t||!n)return[];let o=new Set(n.map(r=>he(t,r,"the panel's walk")));return[...bt(e,o.size===1?[...o][0]:"not on the panel's walk"),...dt(e)]}function Ar(e){let t=[{testid:"graph-open-bubble-legend",rows:Bt(e)},{testid:"graph-ramp-legend",rows:Wt(e),group:"Color"},{testid:"graph-walk-readout",rows:Zt(e),group:"Walks"},{testid:"graph-width-legend",rows:Kt(e),group:"Node thickness"},{testid:"graph-link-width-legend",rows:Xt(e),group:"Link thickness"},{testid:"graph-halo-legend",rows:Ht(e),group:"Marks"},{testid:"graph-deletion-legend",rows:dt(e),group:"Marks"},{testid:"graph-gene-legend",rows:Ut(e),group:"Marks"},{testid:"graph-path-legend",rows:Yt(e),group:"Paths"},{testid:"graph-tube-map-legend",rows:zt(e),group:"Tube map"},{testid:"graph-walk-rows-legend",rows:jt(e),group:"Walk rows"},{testid:"graph-reference-strip-legend",rows:Dt(e),group:"Top strip"},{testid:"graph-fold-legend",rows:Ft(e)}].filter(r=>r.rows.length>0);if(new Set(t.flatMap(r=>r.group??[])).size<2)return t;let o=new Set;return t.map((r,a)=>{let{group:l}=r;return l?o.has(l)?r:(o.add(l),{...r,heading:l}):a===0?r:{...r,spaced:!0}})}function Qt(e){return e==="class"?"className":/^(data|aria)-/.test(e)?e:e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function ft(e,t){if(typeof e=="string")return e;let n={key:t};for(let[o,r]of Object.entries(e.attrs))r!==void 0&&(n[Qt(o)]=r);return Pe(e.tag,n,e.children.map(ft))}function A(){return Me().replaceAll(/[^\w-]/g,"")}function H({el:e}){return ft(e,0)}var en="rgba(0, 0, 0, 0.28)";function ht({id:e,x:t,y:n,stops:o,width:r,height:a,square:l,edged:i}){let d=i?.5:0,c=p=>u("rect",{x:t+d,y:n+d,width:r-d*2,height:a-d*2,rx:l?0:2,fill:p,stroke:i?en:void 0});return o.length>1?k(T,{children:[u("defs",{children:u("linearGradient",{id:e,children:o.map((p,b)=>u("stop",{offset:p.offset,stopColor:p.color},b))})}),c(`url(#${e})`)]}):c(o[0].color)}function tn({swatch:e,x:t,id:n}){switch(e.kind){case"fill":{let r=D(e);return u(ht,{id:n,x:t,y:-5-r/2,stops:e.stops,width:j(e),height:r,square:e.square,edged:e.edged})}case"bands":{let r=ke(e.bands),a=-5-D(e)/2;return u(T,{children:e.bands.map((l,i)=>u(ht,{id:`${n}-${i}`,x:t,y:a+i*r,stops:l,width:R,height:r,square:!0},i))})}case"line":return e.dashed?u("line",{x1:t+1,x2:t+R,y1:-5,y2:-5,stroke:e.color,strokeWidth:3,strokeDasharray:"4 3"}):u("rect",{x:t,y:-5-1.5,width:R,height:3,rx:2,fill:e.color});case"halo":return u("line",{x1:t+5,x2:t+13,y1:-5,y2:-5,stroke:e.color,strokeOpacity:.35,strokeWidth:8,strokeLinecap:"round"});case"outline":{let r=e.stroke/2;return u("rect",{x:t+r,y:-5-e.height/2+r,width:R-e.stroke,height:e.height-e.stroke,rx:Math.max(0,e.radius-r),fill:"none",stroke:e.color,strokeWidth:e.stroke})}case"overhang":return u("path",{transform:`translate(${t} -10)`,d:"M0,5 L8,0 L8,10 Z M18,5 L10,0 L10,10 Z",fill:"#18181c"});case"glyph":return u("text",{x:t+R/2,y:-1,textAnchor:"middle",fontFamily:"monospace",fontSize:12,fill:"currentColor",children:e.char});case"tick":{let r=-5-e.height/2;return k(T,{children:[e.backing?u("rect",{x:t,y:r,width:R,height:e.height,fill:e.backing}):null,u("rect",{x:t+R/2-1,y:r,width:2,height:e.height,fill:e.color})]})}case"bracket":return u("path",{transform:`translate(${t} ${-5-3.5})`,d:`M0.5,6 V1.5 H5.5 V6 M8.5,6 V1.5 H${R-.5} V6`,fill:"none",stroke:Fe()});case"blank":return null}}function $r({swatch:e}){let t=A(),n=D(e);return u("svg",{width:j(e),height:n,overflow:"visible",style:{flex:"none"},children:u("g",{transform:`translate(0 ${n/2+5})`,children:u(tn,{swatch:e,x:0,id:t})})})}var Ur={background:"#fff",padding:"3px 6px",fontSize:11,lineHeight:"15px",whiteSpace:"nowrap"},Fr={display:"flex",alignItems:"center",gap:5},Yr={color:"#666"},nn="#6b7479",zr=4,Vr={color:nn,fontSize:9.5,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase"};var rn=m(function({model:t}){let n=`exon-outline-${A()}`,o=U(()=>X(()=>{let{genePins:b,walkLift:h}=t,s=h?void 0:t.openBubbleFocus,f=s?b.map(g=>({...g,exonsByNode:g.exonsByNode.filter(w=>s.nodeIds.has(w.nodeId))})):b;return be(f,t.nodeInk.halfWidthPx,h)}),[t]),{scaleX:r,scaleY:a,translateX:l,translateY:i,paneWidth:d,canvasHeight:c}=t,p=fe(o.get(),{id:n,width:d,height:c,transform:`translate(${l} ${i}) scale(${r} ${a})`});return p?u(C,{model:t,zIndex:2,testId:"graph-gene-pins",children:u(H,{el:p})}):null}),no=rn;function gt(e,t,n){return{x:e-n/2,y:t-E-F+2,width:n,height:E+F*2-2}}function wt(e,t,n){let o=gt(e.x,e.y,e.w);return t>=o.x&&t<=o.x+o.width&&n>=o.y&&n<=o.y+o.height}function $({x:e,y:t,w:n,text:o,note:r,color:a,edge:l=a,italic:i,dimmed:d,title:c,testId:p,onClick:b,onHover:h}){return k("g",{style:{pointerEvents:b||h?"auto":"none",cursor:b?"pointer":void 0,opacity:d?.35:1},"data-testid":p,onClick:b,onMouseEnter:()=>{h?.(!0)},onMouseLeave:()=>{h?.(!1)},...b&&{role:"button",tabIndex:0,"aria-label":(c??o).replaceAll(`
|
|
1
|
+
import{Ca as He,Da as $e,Ea as Ke,Eb as Je,Fa as Xe,Gb as G,Hb as be,Ia as Ue,Ib as fe,Ma as Fe,Mb as Ze,Na as ie,Ob as Qe,Qa as Ye,Rb as he,Ta as ze,Ua as le,Vb as et,Ya as ce,_b as tt,a as Se,b as X,ca as Ae,cb as Ve,ec as nt,f as Q,g as ee,gc as rt,ib as qe,ka as S,kb as pe,la as ae,nb as je,ra as Ie,sa as Be,ta as We,ua as se,wa as Ge,xa as De,yb as ue,zb as de}from"./chunk-MJS65EKE.js";import{D as oe,f as Ee,m as I,p as re,q as Te,r as B}from"./chunk-W7IHIVSE.js";import{E as ne,T as Oe,U as Ne,Z as ve,n as E,p as F,q as te,y as _e}from"./chunk-CVHKXFVS.js";import{b as O,c as W}from"./chunk-BJHWGRMP.js";import{c as Z}from"./chunk-OGXVDZPS.js";import{e as K}from"./chunk-3WG3GF2A.js";import{b as Pe,d as M,e as Le,f as Me,g as U,h as Ce}from"./chunk-NIEZKWQV.js";import{a as T,b as u,c as k,d as m}from"./chunk-JMBDTNUR.js";var Lt="data-pans-with-drawing";function ot(e,t){return{position:"absolute",left:0,top:0,pointerEvents:"none",overflow:t,zIndex:e}}var C=m(function({model:t,zIndex:n,overflow:o="hidden",testId:r,pansWithDrawing:a,children:l}){return u("svg",{style:{...ot(n,o),userSelect:a?"none":void 0},width:t.paneWidth,height:t.canvasHeight,"data-testid":r,...a?{[Lt]:""}:{},children:l})}),at=m(function({model:t,children:n}){let{scaleX:o,scaleY:r,translateX:a,translateY:l}=t;return u("g",{transform:`translate(${a} ${l}) scale(${o} ${r})`,children:n})});function _({model:e,zIndex:t,shown:n=!0,testId:o,paint:r}){let a=Ce(null);return Le(()=>{if(n)return Se(()=>{let l=a.current,i=l?.getContext("2d");if(l&&i){let d=e.paneWidth,c=e.canvasHeight;Ae(rt());let p=Je(l,d,c);i.setTransform(p,0,0,p,0,0),i.clearRect(0,0,d,c),r(i,p)}})},[e,n,r]),u("canvas",{ref:a,"data-testid":n?o:void 0,style:{...ot(t),display:n?"block":"none"}})}var Mt=m(function({model:t}){let{bubbleHalos:n,hoveredBubble:o}=t;if(n.length===0)return null;let r=t.contigThickness*Ze;return u(C,{model:t,zIndex:2,testId:"graph-bubble-halos",children:u(at,{model:t,children:n.filter(a=>!a.whole&&(!a.tick||o&&O(a.bubble,o))).map(a=>u("path",{d:a.path,fill:"none",stroke:S[a.kind],strokeOpacity:o&&O(a.bubble,o)?.45:t.bubbleFaded(a)?.06:.22,strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"},W(a.bubble)))})})}),In=Mt;var st=["#d4735e","#d8a94a","#c98aa4"],Ct="#e6e6e6",_t="#555",Et="bold 11px sans-serif";var ge=e=>st[e]??Ct;function Y(e){let t=String.fromCharCode(65+e%26);return e<26?t:Y(Math.floor(e/26)-1)+t}var z=st.length;function it(e,t,n){e.font=Et,e.textAlign="center",e.textBaseline="middle";for(let{row:o,start:r,bp:a,block:l}of t){let i=n.x(r),d=n.x(r+a)-i,c=n.rowCentre(o)-n.barPx/2;e.fillStyle=ge(l),e.fillRect(i,c,d,n.barPx),e.strokeStyle=_t,e.lineWidth=1,e.strokeRect(i+.5,c+.5,d-1,n.barPx-1),d>=12&&n.barPx>=9&&(e.fillStyle="#111",e.fillText(Y(l),i+d/2,n.rowCentre(o)))}}var R=18,me=32,pt="rgba(160, 160, 160, 0.45)",Nt="#18181c",vt=6,ut=7,Tt="#b8b8c0",V=Be-4,At="rgba(119, 119, 119, 0.85)",It=15,lt=10;function j(e){return e.kind==="fill"?e.width??R:R}var ke=e=>e.length>1?3:4;function D(e){switch(e.kind){case"fill":return e.height??8;case"bands":return ke(e.bands)*e.bands.length;case"line":return 3;case"halo":case"overhang":return 10;case"outline":case"tick":return e.height;case"glyph":return 15;case"bracket":return 7;case"blank":return 0}}function Nr(e){return e.reduce((t,n)=>n.swatch?Math.max(t,j(n.swatch)):t,0)}function vr(e){return e.reduce((t,n)=>n.swatch?Math.max(t,Math.ceil(D(n.swatch))+3):t,It)}var y=e=>[{offset:0,color:e}];function q(e,t,n){return{key:e,label:n,swatch:{kind:"fill",stops:y(t),width:lt,height:lt,edged:!0}}}function ct(e){return e.flatMap((t,n)=>[{offset:n/e.length,color:t},{offset:(n+1)/e.length,color:t}])}function Bt(e){let t=e.openBubble;if(!t)return[];let n=e.bubbleHalos.find(o=>O(o.bubble,t));return[{key:"open",label:`open: ${n?.label??"bubble"}`,swatch:n?{kind:"halo",color:S[n.kind]}:{kind:"blank"},closesBubble:!0}]}function Wt(e){let t=e.walkLift?void 0:e.referenceRampDomain;if(!t)return[];let n=Math.round(t.start),o=Math.round(t.end);return[{key:"ramp",label:`position on ${e.graph?Z(e.graph):"reference"}`,swatch:{kind:"fill",stops:I,width:me},under:`${n.toLocaleString("en-US")}-${o.toLocaleString("en-US")} (${ne(o-n)})`},...e.referenceRampDrawsOffReference?[q("off",B,"off the reference")]:[]]}function Gt(e){let t=e.walkLift;if(t)return t.walks.map(r=>oe(r.encoding));if(e.effectiveColorScheme==="reference-position")return[I];let n=e.referenceStripBlocks.map(r=>r.colors[0]).filter((r,a,l)=>r!==l[a-1]),o=Math.min(vt,n.length);return[o===0?y(re):Array.from({length:o},(r,a)=>({offset:o>1?a/(o-1):0,color:n[o>1?Math.round(a*(n.length-1)/(o-1)):0]}))]}function Dt(e){if(!e.referenceStripShown)return[];let t=(e.walkLift?.walks.length??0)>1;return[{key:"strip",label:`reference${t?", a row per walk":""}`,swatch:{kind:"bands",bands:Gt(e)}},...e.referenceStripFaded?[q("strip-faded",re,e.walkLift?`reference not on ${t?"that row's walk":e.liftedWalksLabel}`:"reference outside the open bubble")]:[],...e.referenceStripOverhangs?[{key:"overhang",label:"graph runs past this edge",swatch:{kind:"overhang"}}]:[]]}function Ht(e){let t=new Map;for(let n of e.bubbleHalos)if(!n.whole){let o=S[n.kind],r=t.get(o)??new Set;r.add(ae[n.kind]),t.set(o,r)}return[...t].map(([n,o])=>{let r=[...o].join(" or ");return{key:`halo-${n}`,label:r===ae.superbubble?r:`${r} bubble`,swatch:{kind:"halo",color:n}}})}function dt(e){let{graph:t}=e;return t&&e.deletions.length>0?[{key:"deletion",label:_e(Z(t)),swatch:{kind:"line",color:e.walkLift?pt:Nt,dashed:!0}}]:[]}function we(e,t,n,o){return{key:e,label:t,swatch:{kind:"fill",stops:y(o),width:me,height:n}}}var $t=e=>e>=10?Math.round(e):Math.round(e*10)/10;function Kt(e){let{graph:t,contigThickness:n,depthRange:o}=e;if(!t||!e.drawsNodes||e.walkRowBars)return[];if(e.nodeWidth==="frequency"){let c=t.nodes.some(p=>p.frequency!==void 0);return Oe(n).map(({label:p,widthPx:b})=>we(`width-${p}`,c?`AF ${p}`:`${p} of haplotypes`,b,B))}if(e.nodeWidth!=="depth"||!o||o.min===o.max)return[];let r=t.paths?.length??0,a=r>0,l=[...new Set([o.max,o.mean,o.min].map(a?Math.round:$t))],i=l[0]>r,d=c=>i?`${c.toLocaleString("en-US")} walk pass${c===1?"":"es"}`:`${c.toLocaleString("en-US")} walk${c===1?"":"s"}`;return l.map(c=>we(`width-${c}`,a?d(c):`depth ${c.toLocaleString("en-US")}`,Ne({depth:c},n,"depth",o.mean),B))}function Xt(e){let t=e.busiestLink;return!e.drawsNodes||e.walkRowBars||e.linkWidth!=="walks"||t===0?[]:(t>1?[t,1]:[1]).map(o=>we(`link-width-${o}`,`${o.toLocaleString("en-US")} walk${o===1?"":"s"}`,e.connectorThickness*ve(o,t,"walks"),At))}function Ut(e){return e.genePins.some(t=>t.exonsByNode.length>0)?[{key:"exon",label:"exon",swatch:{kind:"outline",color:G,stroke:2,radius:5,height:8}}]:[]}function Ft(e){let t=e.foldNote;return t?[{key:"fold",label:t}]:[]}function Yt(e){return e.pathLegend.map(({name:t,label:n,color:o})=>({key:`path-${t}`,label:n,swatch:{kind:"line",color:o}}))}function N(e,t,n){return{key:e,label:n,swatch:{kind:"fill",stops:t,height:ut,square:!0}}}function zt(e){let{roles:t,haplotypeTube:n,bundled:o,values:r,logWidths:a,foldBp:l,forwardReads:i,reverseReads:d,substitution:c,insertion:p,deletion:b}=e.tubeMapKeys,h=e.readsShown,s=[];if(r){s.push(N("value-reference",y(pe),"reference"));for(let{value:f,color:g}of r)s.push(N(`value-${f}`,y(g),f))}return t&&s.push(N("ref",y(pe),"reference"),N("hap",y(n),o?"shared route, \xD7n haplotypes":"haplotype")),i&&s.push(N("fwd",ct(Q),"read on the forward strand")),d&&s.push(N("rev",ct(ee),"read on the reverse strand")),h&&h.shown<h.total&&s.push({key:"sampled",label:`${h.shown.toLocaleString("en-US")} of ${h.total.toLocaleString("en-US")} reads shown`,swatch:{kind:"blank"}}),c&&s.push({key:"sub",label:"read mismatch",swatch:{kind:"glyph",char:"A"}}),p&&s.push({key:"ins",label:"read insertion",swatch:{kind:"glyph",char:"*"}}),b&&s.push(N("del",y("grey"),"read deletion")),l!==void 0&&s.push({key:"tube-fold",label:`haplotype variant < ${ne(l)}`,swatch:{kind:"tick",color:ze(),height:ut,backing:Tt}}),a&&s.push({key:"log",label:"width grows with log of length",swatch:{kind:"bracket"}}),s}function Vt(e){return e.kind==="gene"?{kind:"outline",color:Ie,stroke:1.5,radius:0,height:V}:{kind:"fill",stops:e.kind==="bar"&&e.ramp?I:y(e.fill),height:e.kind==="gap"?e.px:V}}function qt(e){let t=new Set(e.sharedBlocks?.map(o=>o.block)),n=o=>({kind:"fill",stops:y(ge(o)),height:V});return[...[...t].filter(o=>o<z).sort((o,r)=>o-r).map(o=>({key:`block-${o}`,label:`${Y(o)}: off the reference, walked by several rows`,swatch:n(o)})),...[...t].some(o=>o>=z)?[{key:"block-more",label:"more shared blocks",swatch:n(z)}]:[]]}function jt(e){let t=e.walkRowBars;if(!t)return[];let n=[t.reference,...t.rows].flatMap(r=>r.call??[]),o=(r,a,l)=>({key:r,label:l,swatch:{kind:"tick",color:a,height:V}});return[...He(t,{ramp:e.referenceRampDomain,genes:e.walkRowGeneKey,annotation:e.walkRowAnnotation}).map(r=>({key:`rows-${r.label}`,label:r.label,swatch:r.note?void 0:Vt(r.swatch)})),...qt(e),...n.some(r=>r.spanningReads!==0)?[o("call",$e,"allele length called for this walk")]:[],...n.some(r=>r.spanningReads===0)?[o("unbacked",Ke,"called with no read spanning it")]:[],...n.some(r=>r.agrees===!1)?[o("disagrees",Xe,`walk and call over ${Math.round(.1*100)}% apart`)]:[]]}function Jt(e,t){let n=et(t,e.walkReference);return{key:`walk-${t.name}`,strong:e.walkLabel(t.name),label:n.delta+n.gaps+n.reversed,swatch:{kind:"fill",stops:oe(t.encoding),width:n.shades?me:R},under:n.scale,title:n.hover,walk:t}}function bt(e,t){return[...e.liftPaintsOffReference?[q("lift-off",B,"off the reference")]:[],q("faded",pt,t)]}function Zt(e){let t=e.walkLift;if(!t||e.facetPanels)return[];let n=t.walks.map(r=>Jt(e,r)),o=e.graph?he(e.graph,t,e.liftedWalksLabel):`not on ${e.liftedWalksLabel}`;return[...n,...bt(e,o)]}function Tr(e){let{graph:t,facetPanels:n}=e;if(!t||!n)return[];let o=new Set(n.map(r=>he(t,r,"the panel's walk")));return[...bt(e,o.size===1?[...o][0]:"not on the panel's walk"),...dt(e)]}function Ar(e){let t=[{testid:"graph-open-bubble-legend",rows:Bt(e)},{testid:"graph-ramp-legend",rows:Wt(e),group:"Color"},{testid:"graph-walk-readout",rows:Zt(e),group:"Walks"},{testid:"graph-width-legend",rows:Kt(e),group:"Node thickness"},{testid:"graph-link-width-legend",rows:Xt(e),group:"Link thickness"},{testid:"graph-halo-legend",rows:Ht(e),group:"Marks"},{testid:"graph-deletion-legend",rows:dt(e),group:"Marks"},{testid:"graph-gene-legend",rows:Ut(e),group:"Marks"},{testid:"graph-path-legend",rows:Yt(e),group:"Paths"},{testid:"graph-tube-map-legend",rows:zt(e),group:"Tube map"},{testid:"graph-walk-rows-legend",rows:jt(e),group:"Walk rows"},{testid:"graph-reference-strip-legend",rows:Dt(e),group:"Top strip"},{testid:"graph-fold-legend",rows:Ft(e)}].filter(r=>r.rows.length>0);if(new Set(t.flatMap(r=>r.group??[])).size<2)return t;let o=new Set;return t.map((r,a)=>{let{group:l}=r;return l?o.has(l)?r:(o.add(l),{...r,heading:l}):a===0?r:{...r,spaced:!0}})}function Qt(e){return e==="class"?"className":/^(data|aria)-/.test(e)?e:e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function ft(e,t){if(typeof e=="string")return e;let n={key:t};for(let[o,r]of Object.entries(e.attrs))r!==void 0&&(n[Qt(o)]=r);return Pe(e.tag,n,e.children.map(ft))}function A(){return Me().replaceAll(/[^\w-]/g,"")}function H({el:e}){return ft(e,0)}var en="rgba(0, 0, 0, 0.28)";function ht({id:e,x:t,y:n,stops:o,width:r,height:a,square:l,edged:i}){let d=i?.5:0,c=p=>u("rect",{x:t+d,y:n+d,width:r-d*2,height:a-d*2,rx:l?0:2,fill:p,stroke:i?en:void 0});return o.length>1?k(T,{children:[u("defs",{children:u("linearGradient",{id:e,children:o.map((p,b)=>u("stop",{offset:p.offset,stopColor:p.color},b))})}),c(`url(#${e})`)]}):c(o[0].color)}function tn({swatch:e,x:t,id:n}){switch(e.kind){case"fill":{let r=D(e);return u(ht,{id:n,x:t,y:-5-r/2,stops:e.stops,width:j(e),height:r,square:e.square,edged:e.edged})}case"bands":{let r=ke(e.bands),a=-5-D(e)/2;return u(T,{children:e.bands.map((l,i)=>u(ht,{id:`${n}-${i}`,x:t,y:a+i*r,stops:l,width:R,height:r,square:!0},i))})}case"line":return e.dashed?u("line",{x1:t+1,x2:t+R,y1:-5,y2:-5,stroke:e.color,strokeWidth:3,strokeDasharray:"4 3"}):u("rect",{x:t,y:-5-1.5,width:R,height:3,rx:2,fill:e.color});case"halo":return u("line",{x1:t+5,x2:t+13,y1:-5,y2:-5,stroke:e.color,strokeOpacity:.35,strokeWidth:8,strokeLinecap:"round"});case"outline":{let r=e.stroke/2;return u("rect",{x:t+r,y:-5-e.height/2+r,width:R-e.stroke,height:e.height-e.stroke,rx:Math.max(0,e.radius-r),fill:"none",stroke:e.color,strokeWidth:e.stroke})}case"overhang":return u("path",{transform:`translate(${t} -10)`,d:"M0,5 L8,0 L8,10 Z M18,5 L10,0 L10,10 Z",fill:"#18181c"});case"glyph":return u("text",{x:t+R/2,y:-1,textAnchor:"middle",fontFamily:"monospace",fontSize:12,fill:"currentColor",children:e.char});case"tick":{let r=-5-e.height/2;return k(T,{children:[e.backing?u("rect",{x:t,y:r,width:R,height:e.height,fill:e.backing}):null,u("rect",{x:t+R/2-1,y:r,width:2,height:e.height,fill:e.color})]})}case"bracket":return u("path",{transform:`translate(${t} ${-5-3.5})`,d:`M0.5,6 V1.5 H5.5 V6 M8.5,6 V1.5 H${R-.5} V6`,fill:"none",stroke:Fe()});case"blank":return null}}function $r({swatch:e}){let t=A(),n=D(e);return u("svg",{width:j(e),height:n,overflow:"visible",style:{flex:"none"},children:u("g",{transform:`translate(0 ${n/2+5})`,children:u(tn,{swatch:e,x:0,id:t})})})}var Ur={background:"#fff",padding:"3px 6px",fontSize:11,lineHeight:"15px",whiteSpace:"nowrap"},Fr={display:"flex",alignItems:"center",gap:5},Yr={color:"#666"},nn="#6b7479",zr=4,Vr={color:nn,fontSize:9.5,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase"};var rn=m(function({model:t}){let n=`exon-outline-${A()}`,o=U(()=>X(()=>{let{genePins:b,walkLift:h}=t,s=h?void 0:t.openBubbleFocus,f=s?b.map(g=>({...g,exonsByNode:g.exonsByNode.filter(w=>s.nodeIds.has(w.nodeId))})):b;return be(f,t.nodeInk.halfWidthPx,h)}),[t]),{scaleX:r,scaleY:a,translateX:l,translateY:i,paneWidth:d,canvasHeight:c}=t,p=fe(o.get(),{id:n,width:d,height:c,transform:`translate(${l} ${i}) scale(${r} ${a})`});return p?u(C,{model:t,zIndex:2,testId:"graph-gene-pins",children:u(H,{el:p})}):null}),no=rn;function gt(e,t,n){return{x:e-n/2,y:t-E-F+2,width:n,height:E+F*2-2}}function wt(e,t,n){let o=gt(e.x,e.y,e.w);return t>=o.x&&t<=o.x+o.width&&n>=o.y&&n<=o.y+o.height}function $({x:e,y:t,w:n,text:o,note:r,color:a,edge:l=a,italic:i,dimmed:d,title:c,testId:p,onClick:b,onHover:h}){return k("g",{style:{pointerEvents:b||h?"auto":"none",cursor:b?"pointer":void 0,opacity:d?.35:1},"data-testid":p,onClick:b,onMouseEnter:()=>{h?.(!0)},onMouseLeave:()=>{h?.(!1)},...b&&{role:"button",tabIndex:0,"aria-label":(c??o).replaceAll(`
|
|
2
2
|
`,", "),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b())},onFocus:()=>{h?.(!0)},onBlur:()=>{h?.(!1)}},children:[c?u("title",{children:c}):null,u("rect",{...gt(e,t,n),rx:3,fill:"rgba(255,255,255,0.85)",stroke:l,strokeWidth:1}),k("text",{x:e,y:t,fontSize:E,fontFamily:"sans-serif",fontStyle:i?"italic":void 0,fontWeight:i?600:void 0,fill:a,textAnchor:"middle",children:[o,r?u("tspan",{fontStyle:"normal",fontWeight:"normal",children:r}):null]})]})}var mt="#1c1c22",Re=9,xe=3;function Po({genes:e},t,n){let o=e.find(l=>wt(l,t,n))?.item;if(!o)return;let{gene:r}=o,a=Qe(o);return{label:r.name,readout:`${r.refName}:${r.start.toLocaleString()}-${r.end.toLocaleString()}${a?`, ${a} in the cut`:""}`}}var on=m(function({model:t}){let{bubbles:n,genes:o,ticks:r}=t.overlayLabels;if(n.length+o.length+r.length===0)return null;let{scaleY:a,translateY:l,contigThickness:i,hoveredBubble:d}=t,c=d?r.find(s=>O(s.item.bubble,d)):void 0,p=s=>r[Number(s.getAttribute("data-tick"))],b=s=>t.bubbleFaded(s),h=s=>t.bubbleIsOpen(s.bubble);return k(C,{model:t,zIndex:3,testId:"graph-label-layer",pansWithDrawing:!0,children:[u("g",{"data-testid":"graph-bubble-ticks",onClick:s=>{let f=p(s.target);f&&t.toggleBubble(f.item.bubble)},onMouseOver:s=>{let f=p(s.target);f&&t.setHoveredBubble(f.item.bubble)},onMouseOut:()=>{K(t)&&t.setHoveredBubble(null)},onFocus:s=>{let f=p(s.target);f&&t.setHoveredBubble(f.item.bubble)},onBlur:()=>{K(t)&&t.setHoveredBubble(null)},onKeyDown:s=>{let f=p(s.target);f&&(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),t.toggleBubble(f.item.bubble))},children:r.map(({item:s,x:f,y:g},w)=>u("rect",{"data-tick":w,role:"button",tabIndex:0,"aria-label":`${s.label}, ${h(s)?"close":"open"} bubble`,x:f-xe/2,y:g-Re,width:xe,height:Re,rx:xe/2,fill:S[s.kind],opacity:b(s)?.35:1,style:{pointerEvents:"all",cursor:"pointer"}},W(s.bubble)))}),o.map(({item:s,x:f,y:g,w,text:P})=>{let{gene:x}=s;return k("g",{children:[u("line",{x1:f,x2:f,y1:g-E-2,y2:s.at.y*a+l+i/2,stroke:mt,strokeWidth:.8,strokeOpacity:.6}),u($,{x:f,y:g,w,text:x.name,note:P.slice(x.name.length)||void 0,color:mt,edge:G,italic:!0,testId:"graph-gene-pin-label"})]},`${x.name}-${x.start}`)}),n.map(({item:s,x:f,y:g,w,text:P})=>u($,{x:f,y:g,w,text:P,color:S[s.kind],dimmed:b(s),title:`${s.label}
|
|
3
3
|
${s.bubble.segmentCount} segments${s.bubble.covering?"":h(s)?" \xB7 click to close":" \xB7 click to open"}`,testId:"graph-bubble-halo-label",onClick:s.bubble.covering?void 0:()=>{t.toggleBubble(s.bubble)},onHover:x=>{K(t)&&t.setHoveredBubble(x?s.bubble:null)}},W(s.bubble))),c?u($,{x:c.x,y:c.y-Re-4,w:te(c.item.label),text:c.item.label,color:S[c.item.kind],testId:"graph-bubble-tick-label"}):null]})}),Lo=on;function an(e,t,{lit:n,dpr:o}){let r=t.hostBpFrame;r&&nt(e,t.referenceStripBlocks,r,{width:t.paneWidth,lit:n,dpr:o})}var sn=m(function({model:t}){let n=M((o,r)=>{an(o,t,{lit:t.referenceStripLit,dpr:r})},[t]);return u(_,{model:t,zIndex:5,shown:t.referenceStripShown,testId:"graph-reference-strip",paint:n})}),vo=sn;var ln=.45;function cn(e,t,{highlightNode:n}){let o=t.tubeMapPicture,r=t.tubeMapFrame;if(!o||!r)return;let a=t.paneWidth,l=t.tubeMapPanelViews;if(l){pn(e,t,l,n);return}let i={...r,width:a,highlightNode:n,tubeColors:t.tubeMapTubeColors,nodeColors:t.tubeMapNodeColors};ce(e,o,i);let d=t.layoutResult?.tubeMap;d&&(ue(e,o,d.graph,i),de(e,d,i)),le(e,t.tubeMapDeviations,i),Ye(e,t.tubeMapConnectors,t.connectorZoneBottom,i);let{bounds:c}=o;tt(e,t.tubeMapGenes,i,r.y(c.minY)-2);let p=t.tubeMapRulerBoxes;p&&ie(e,p,i,r.y(c.maxY)+4,t.layoutResult?.referenceAxis)}function pn(e,t,n,o){let r=t.paneWidth;for(let i of n){if(i.bottom<0||i.titleTop>t.canvasHeight)continue;let d={...i.frame,width:r,highlightNode:o,tubeColors:i.tubeColors,nodeColors:i.nodeColors};ce(e,i.picture,d),ue(e,i.picture,i.panel.result.tubeMap.graph,d),de(e,i.panel.result.tubeMap,d),e.globalAlpha=ln,le(e,i.deviations,d),e.globalAlpha=1,e.strokeStyle="rgba(0,0,0,0.15)",e.lineWidth=1,e.beginPath(),e.moveTo(0,Math.round(i.titleTop)+.5),e.lineTo(r,Math.round(i.titleTop)+.5),e.stroke(),e.font=je,e.textAlign="left",e.textBaseline="top",e.fillStyle="rgba(0,0,0,0.85)",e.fillText(i.label,6,i.titleTop+4)}let a=n.at(-1),l=t.tubeMapPanelRulerBoxes;a&&l&&ie(e,l,{...a.frame,width:r},a.bottom+4,!0)}var un=m(function({model:t}){let n=M(o=>{cn(o,t,{highlightNode:t.selectedNode})},[t]);return u(_,{model:t,zIndex:1,shown:!!t.tubeMapPicture,testId:"graph-tube-map",paint:n})}),Uo=un;var v=JBrowseExports["@jbrowse/render-core/marks"],dn=e=>v!=null&&e in Object(v)?v[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/render-core/marks' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var kt=dn("spanMark");var zo=v&&v.__esModule?v.default:v;function xt(e){if(e.startsWith("#")){let r=Number.parseInt(e.slice(1),16);return[r>>16&255,r>>8&255,r&255]}let[t=0,n=0,o=0]=e.match(/[\d.]+/g).map(Number);return e.startsWith("hsl")?Te(t,n/100,o/100).map(r=>r*255):[t,n,o]}var yt=([e,t,n])=>Ee(Math.round(e),Math.round(t),Math.round(n),255),Rt=new Map;function bn(e){let t=Rt.get(e);return t===void 0&&(t=yt(xt(e)),Rt.set(e,t)),t}function fn(e,t,n){let o=e.start+e.bp,r=De(e,t);if("fill"in r)return[[e.start,o,bn(r.fill)]];let a=r.stops.map(xt),l=r.stops.map(p=>Number(/[\d.]+/.exec(p)[0])),i=Math.abs(l.at(-1)-l[0]),d=Math.max(1,Math.min(Math.ceil(e.bp*n),Math.ceil(i),e.bp)),c=[];for(let p=0;p<d;p++){let b=(p+.5)/d*(a.length-1),h=Math.min(Math.floor(b),a.length-2),s=a[h],f=a[h+1],g=b-h;c.push([Math.round(e.start+e.bp*p/d),Math.round(e.start+e.bp*(p+1)/d),yt([0,1,2].map(w=>s[w]+(f[w]-s[w])*g))])}return c}function ye(e){return{x:new Uint32Array(e),x2:new Uint32Array(e),row:new Uint32Array(e),color:new Uint32Array(e),count:0}}function J(e,t,n){return{x:e.x.subarray(t,n),x2:e.x2.subarray(t,n),row:e.row.subarray(t,n),color:e.color.subarray(t,n),count:n-t}}function St(e,t,n){let o=e.map(h=>Ue(h.runs,t).map(s=>({gap:s.gap,hairline:s.gap&&Ge(s.cause).px===se,pieces:fn(s,n,t)}))),r=0;for(let h of o)for(let s of h)r+=s.pieces.length;let a=ye(r),l=ye(r),i=ye(r),d=new Uint32Array(e.length+1),c=new Uint32Array(e.length+1),p=new Uint32Array(e.length+1),b=1;return o.forEach((h,s)=>{for(let f of h){let g=f.hairline?i:f.gap?l:a;for(let[w,P,x]of f.pieces){let L=g.count++;g.x[L]=w,g.x2[L]=P,g.row[L]=s,g.color[L]=x,b=Math.max(b,g.x2[L])}}d[s+1]=a.count,c[s+1]=l.count,p[s+1]=i.count}),{bars:J(a,0,a.count),gaps:J(l,0,l.count),hairlines:J(i,0,i.count),barRows:d,gapRows:c,hairlineRows:p,longest:b}}function Pt(e,t,n){let{longest:o}=t,r={start:0,end:o,screenStartPx:n.origin*n.scaleX+n.translateX,screenEndPx:(n.origin+o)*n.scaleX+n.translateX,reversed:!1,displayedRegionIndex:0},a={canvasWidth:n.width,canvasHeight:n.height},l=n.rowPx*n.scaleY;for(let{first:i,count:d,rowY:c}of n.blocks){let p=l/2-n.translateY-(c-i*n.rowPx)*n.scaleY,b=(c-n.rowPx/2)*n.scaleY+n.translateY;if(!(b>n.height||b+d*l<0))for(let[h,s,f]of[[t.bars,t.barRows,n.barPx],[t.gaps,t.gapRows,Math.min(We,n.barPx)],[t.hairlines,t.hairlineRows,Math.min(se,n.barPx)]])kt.paintBlock(e,J(h,s[i],s[i+d]),r,a,{rowHeight:l,rowProportion:f/l,minWidthPx:1,seamPx:0,scrollTop:p})}}function hn({model:e}){let t=U(()=>X(()=>{let o=e.walkRowBars;return o?St([o.reference,...o.rows],e.scaleX,e.referenceRampDomain):void 0}),[e]),n=M(o=>{let r=e.walkRowBars,a=e.walkRowPlacement,l=e.walkRowPitch,i=t.get();if(!r||!a||!l||!i)return;let d=e.walkRowGroups?.sections,c=d?.length?[{first:0,count:1,rowY:a.rowY(0)},...d.map(p=>({first:p.first,count:p.count,rowY:a.rowY(p.first)}))]:[{first:0,count:r.rows.length+1,rowY:a.rowY(0)}];Pt(o,i,{...e.screenTransform,width:e.paneWidth,height:e.canvasHeight,rowPx:l.rowPx,barPx:l.barPx,origin:r.origin,blocks:c})},[e,t]);return u(_,{model:e,zIndex:3,testId:"graph-walk-rows-spans",paint:n})}var gn="rgba(160, 196, 232, 0.55)",wn="rgba(160, 140, 220, 0.55)";function mn({model:e}){let t=M(n=>{let o=e.walkRowRibbons,r=e.walkRowBars,a=e.walkRowPlacement,l=e.walkRowPitch;if(!o||!r||!a||!l)return;let{scaleX:i,scaleY:d,translateX:c,translateY:p}=e.screenTransform,b=s=>(r.origin+s)*i+c,h=l.barPx/2;for(let{row:s,a0:f,a1:g,b0:w,b1:P}of o){let x=a.rowY(s)*d+p+h,L=a.rowY(s+1)*d+p-h;n.fillStyle=w>P?wn:gn,n.beginPath(),n.moveTo(b(f),x),n.lineTo(b(g),x),n.lineTo(b(P),L),n.lineTo(b(w),L),n.closePath(),n.fill()}},[e]);return u(_,{model:e,zIndex:2,testId:"graph-walk-rows-ribbons",paint:t})}function kn({model:e}){let t=M(n=>{let o=e.sharedBlocks,r=e.walkRowBars,a=e.walkRowPlacement,l=e.walkRowPitch;if(!o||!r||!a||!l)return;let{scaleX:i,scaleY:d,translateX:c,translateY:p}=e.screenTransform;it(n,o,{x:b=>(r.origin+b)*i+c,rowCentre:b=>a.rowY(b)*d+p,barPx:l.barPx})},[e]);return u(_,{model:e,zIndex:3,testId:"graph-walk-rows-blocks",paint:t})}var Rn=m(function({model:t}){let n=t.walkRowBars,o=t.walkRowPlacement,r=t.walkRowPitch;if(!n||!o||!r||!t.hoveredWalkRowText)return null;let a=[n.reference,...n.rows],l=a.findIndex(c=>c.name===t.hoveredWalkRow),i=a[l];if(!i)return null;let d=t.toScreen({x:n.origin,y:o.rowY(l)});return u("rect",{"data-testid":"graph-walk-row-hovered",x:d.x-2,y:d.y-r.rowPx/2-1,width:i.bp*t.scaleX+4,height:r.rowPx+2,fill:"none",stroke:"#111",strokeWidth:1})}),xn=m(function({model:t,vector:n=!1}){let o=A(),r=t.walkRowBars,a=t.walkRowPlacement,l=t.walkRowPitch;if(!r||!a||!l)return null;let{paneWidth:i,canvasHeight:d}=t,c={...t.screenTransform,width:i,height:d,...l,bars:n};return k(T,{children:[n||!t.walkRowRibbons?null:u(mn,{model:t}),n?null:u(hn,{model:t}),n||!t.sharedBlocks?null:u(kn,{model:t}),k(C,{model:t,zIndex:3,overflow:"visible",testId:"graph-walk-rows",children:[qe(r,t.walkRowGroups?.sections??[],a.rowY,c,{ramp:t.referenceRampDomain,rowGenes:t.walkRowGenes,idPrefix:o}).map((p,b)=>u(H,{el:p},b)),a.headers.map(p=>u("text",{x:10,y:t.toScreen({x:0,y:p.top}).y+Ve-4,fontFamily:"sans-serif",fontSize:11,fontWeight:"bold",fill:"#333","data-testid":"graph-walk-section",children:p.title},p.key)),u(Rn,{model:t})]})]})}),la=xn;export{Lt as a,ot as b,C as c,In as d,A as e,H as f,j as g,Nr as h,vr as i,Vt as j,Jt as k,Tr as l,Ar as m,tn as n,$r as o,Ur as p,Fr as q,Yr as r,nn as s,zr as t,Vr as u,no as v,Po as w,Lo as x,an as y,vo as z,cn as A,Uo as B,la as C};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-5EWKB2JM.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as M,l as W,p as F}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{i as M,l as W,p as F}from"./chunk-PDLKFVVK.js";import{b as O,h as A}from"./chunk-T2VC3EEL.js";import{K as b,Q as _,X as B}from"./chunk-CVHKXFVS.js";import{f as R}from"./chunk-NIEZKWQV.js";import{D as E,E as P,H as m,d as v,o as T,q as I,r as L,s as w,t as N,w as D,y as G,z as x}from"./chunk-5Z4VIKXZ.js";import{b as t,c as r,d as C}from"./chunk-JMBDTNUR.js";var S=[{value:0,label:"Fastest"},{value:1,label:"Fast"},{value:2,label:"Default"},{value:3,label:"Fine"},{value:4,label:"Best"}];function f({label:o,value:n,options:e,testId:s,size:d,sx:p,disabled:a,title:h,shown:g,onChange:z}){let k=R();return r(w,{size:d,sx:p,disabled:a,title:h,children:[t(D,{id:k,shrink:!0,children:o}),t(E,{labelId:k,value:n,label:o,notched:!0,displayEmpty:!0,"data-testid":s,renderValue:i=>g??e.find(H=>H.value===i)?.label??i,onChange:i=>{z(i.target.value)},children:e.map(i=>t(x,{value:i.value,disabled:i.disabled,title:i.disabled?void 0:i.description,children:t(G,{primary:i.label,secondary:i.disabled?i.description:void 0})},i.value))})]})}var u=F()({section:{marginBottom:24},group:{marginBottom:16},heading:{marginBottom:8}});function l({warn:o=!1,children:n}){return t(m,{variant:"caption",component:"div",color:o?"warning.main":"text.secondary",children:n})}function y({title:o,children:n}){let{classes:e}=u();return r("section",{className:e.group,children:[t(m,{variant:"subtitle1",className:e.heading,children:o}),n]})}function U({label:o,checked:n,onChange:e,children:s}){let{classes:d}=u();return r("div",{className:d.section,children:[t(N,{control:t(P,{checked:n,onChange:p=>{e(p.target.checked)}}),label:o}),s]})}function c({children:o,...n}){let{classes:e}=u();return r("div",{className:e.section,children:[t(f,{sx:{minWidth:200},...n}),o]})}var Y=[5e3,2e4,5e4,1e5];function $(o){return[...new Set([...Y,o])].sort((n,e)=>n-e).map(n=>({value:String(n),label:n.toLocaleString()}))}function Q({label:o,choices:n,stored:e,auto:s,testId:d,onChange:p,children:a}){return n.length>0?t(c,{label:o,value:n.some(h=>h.trackId===e)?e:"",options:[{value:"",label:`Automatic (${s?.name??"none"})`},...n.map(({trackId:h,name:g})=>({value:h,label:g}))],testId:d,onChange:p,children:a}):null}var q=C(function(n){let{model:e,onClose:s,children:d}=n,{classes:p}=u();return r(v,{open:!0,onClose:s,title:"Graph settings",children:[r(L,{children:[r(y,{title:"Subgraph",children:[d,t(c,{label:"Node limit",value:String(e.maxGraphNodes),options:$(e.maxGraphNodes),testId:"graph-node-limit-select",onChange:a=>{e.setMaxGraphNodes(Number(a))},children:t(l,{children:"The most nodes a layout draws; past it the graph is declined. Walk rows take no limit."})})]}),r(y,{title:"Drawing",children:[e.anchorPaths.length>1?t(c,{label:"Reference path",value:e.activeReferencePath??"",options:e.anchorPaths.map(({name:a})=>({value:a,label:a})),testId:"graph-reference-path-select",onChange:a=>{e.setReferencePath(a),e.recomputeLayout()},children:t(l,{children:"The path the anchored layouts place x along"})}):null,t(c,{label:"Node width",value:e.nodeWidth,options:_,testId:"graph-node-width-select",onChange:a=>{e.setNodeWidth(a)},children:t(l,{children:"Depth as width. In a cut with walks, depth is how many haplotypes carry the node."})}),t(c,{label:"Link width",value:e.linkWidth,options:B,testId:"graph-link-width-select",onChange:a=>{e.setLinkWidth(a)},children:t(l,{children:"Walks as width, so a common route reads heavy and a private one thin."})}),r(U,{label:"Draw paths",checked:e.drawPaths,onChange:a=>{e.setLayer("paths",a)},children:[t(l,{children:"Color each node by the paths through it, one lane per path"}),e.drawPaths&&!e.effectiveDrawPaths?t(l,{warn:!0,children:e.pathCount>b?`Off: ${e.pathCount.toLocaleString()} paths is past the ${b} this can tell apart`:"Off: this graph states no paths"}):null]}),t(Q,{label:"Gene track",choices:e.geneTrackChoices,stored:e.geneTrackId,auto:W(e.geneTrackChoices,""),testId:"graph-gene-track-select",onChange:a=>{e.setGeneTrackId(a)},children:t(l,{children:"Where genes on the backbone come from"})}),t(Q,{label:"Repeat track",choices:e.repeatTrackChoices,stored:e.repeatTrackId,auto:M(e.repeatTrackChoices,""),testId:"graph-repeat-track-select",onChange:a=>{e.setRepeatTrackId(a)},children:t(l,{children:"The tandem repeat annotation walk rows measure and tile by"})})]}),r(y,{title:"Force-directed layout",children:[e.hasGraph&&!e.usesLayoutEngine?t("div",{className:p.section,children:t(l,{warn:!0,children:"No effect on the current layout until Layout is Force-directed"})}):null,t(c,{label:"Engine",value:e.layoutEngine,options:O,testId:"graph-layout-engine-select",onChange:a=>{e.setLayoutEngine(a)},children:t(l,{children:"Stress keeps the reference straight, so a zoom keeps the picture; FMMM lets the whole graph settle."})}),t(c,{label:"Layout quality",value:String(e.layoutQuality),options:S.map(a=>({value:String(a.value),label:a.label})),testId:"graph-layout-quality-select",onChange:a=>{e.setLayoutQuality(Number(a))},children:t(l,{children:"The engine's iteration budget; higher is slower"})}),t(c,{label:"Bubble spread",value:e.bubbleSpread,options:A,testId:"graph-bubble-spread-select",onChange:a=>{e.setBubbleSpread(a)},children:t(l,{children:"How far the layout opens a bubble"})}),e.layoutEngine==="stress"?null:t(U,{label:"Linear layout",checked:e.linearLayout,onChange:a=>{e.setLinearLayout(a)},children:t(l,{children:"Keeps a chain of nodes on one line where it can"})})]})]}),t(I,{children:t(T,{variant:"contained",color:"primary",onClick:s,children:"Close"})})]})}),ge=q;export{f as a,ge as b};
|
|
2
|
+
//# sourceMappingURL=chunk-6ZZJCKX5.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.1.1/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-K5SIJGAE.js", "../../src/GraphGenomeView/components/LabelledSelect.tsx", "../../src/GraphGenomeView/components/GraphSettingsDialog.tsx"],
|
|
4
4
|
"sourcesContent": ["// src/layoutQualities.ts\nvar LAYOUT_QUALITIES = [\n { value: 0, label: \"Fastest\" },\n { value: 1, label: \"Fast\" },\n { value: 2, label: \"Default\" },\n { value: 3, label: \"Fine\" },\n { value: 4, label: \"Best\" }\n];\n\nexport {\n LAYOUT_QUALITIES\n};\n", "import { useId } from 'react'\n\nimport {\n FormControl,\n InputLabel,\n ListItemText,\n MenuItem,\n Select,\n} from '@mui/material'\n\nimport type { SxProps } from '@mui/material'\n\ninterface SelectOption<T extends string> {\n value: T\n label: string\n // an option's tooltip, and the reason under a disabled one, whose tooltip\n // cannot open\n description?: string\n disabled?: boolean\n}\n\n// One dropdown with its label tied to it, so a screen reader names the combobox\nexport default function LabelledSelect<T extends string>({\n label,\n value,\n options,\n testId,\n size,\n sx,\n disabled,\n title,\n shown,\n onChange,\n}: {\n label: string\n value: T\n options: readonly SelectOption<T>[]\n testId?: string\n size?: 'small' | 'medium'\n sx?: SxProps\n disabled?: boolean\n title?: string\n // what the closed select reads, when not the picked option's label\n shown?: string\n onChange: (value: T) => void\n}) {\n const labelId = useId()\n return (\n <FormControl size={size} sx={sx} disabled={disabled} title={title}>\n <InputLabel id={labelId} shrink>\n {label}\n </InputLabel>\n <Select\n labelId={labelId}\n value={value}\n label={label}\n notched\n displayEmpty\n data-testid={testId}\n renderValue={picked =>\n shown ?? options.find(o => o.value === picked)?.label ?? picked\n }\n onChange={e => {\n onChange(e.target.value as T)\n }}\n >\n {options.map(o => (\n <MenuItem\n key={o.value}\n value={o.value}\n disabled={o.disabled}\n title={o.disabled ? undefined : o.description}\n >\n <ListItemText\n primary={o.label}\n secondary={o.disabled ? o.description : undefined}\n />\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n )\n}\n", "import type { ReactNode } from 'react'\n\nimport { BUBBLE_SPREADS } from '@jbrowse/bandage-core/bubbleSpreads'\nimport { EDGE_WIDTHS } from '@jbrowse/bandage-core/edgeWidths'\nimport { LAYOUT_ENGINES } from '@jbrowse/bandage-core/layoutEngines'\nimport { LAYOUT_QUALITIES } from '@jbrowse/bandage-core/layoutQualities'\nimport { NODE_WIDTHS } from '@jbrowse/bandage-core/nodeWidths'\nimport { MAX_PATH_COLORS } from '@jbrowse/bandage-core/pathColors'\nimport { Dialog } from '@jbrowse/core/ui'\nimport {\n Button,\n DialogActions,\n DialogContent,\n FormControlLabel,\n Switch,\n Typography,\n} from '@mui/material'\nimport { observer } from 'mobx-react'\nimport { makeStyles } from 'tss-react/mui'\n\nimport LabelledSelect from './LabelledSelect'\nimport { pickGeneTrack } from '../genes/geneFeatures'\nimport { pickRepeatTrack } from '../repeats/repeatFeatures'\n\nimport type { GraphPaneModel } from '../model'\n\nconst useStyles = makeStyles()({\n section: {\n marginBottom: 24,\n },\n group: {\n marginBottom: 16,\n },\n heading: {\n marginBottom: 8,\n },\n})\n\nfunction Caption({\n warn = false,\n children,\n}: {\n warn?: boolean\n children: ReactNode\n}) {\n return (\n <Typography\n variant=\"caption\"\n component=\"div\"\n color={warn ? 'warning.main' : 'text.secondary'}\n >\n {children}\n </Typography>\n )\n}\n\nfunction Group({ title, children }: { title: string; children: ReactNode }) {\n const { classes } = useStyles()\n return (\n <section className={classes.group}>\n <Typography variant=\"subtitle1\" className={classes.heading}>\n {title}\n </Typography>\n {children}\n </section>\n )\n}\n\nfunction SettingSwitch({\n label,\n checked,\n onChange,\n children,\n}: {\n label: string\n checked: boolean\n onChange: (checked: boolean) => void\n children?: ReactNode\n}) {\n const { classes } = useStyles()\n return (\n <div className={classes.section}>\n <FormControlLabel\n control={\n <Switch\n checked={checked}\n onChange={e => {\n onChange(e.target.checked)\n }}\n />\n }\n label={label}\n />\n {children}\n </div>\n )\n}\n\n// one dropdown setting, at the dialog's width, and its caption\nfunction SettingSelect<T extends string>({\n children,\n ...props\n}: Omit<Parameters<typeof LabelledSelect<T>>[0], 'size' | 'sx'> & {\n children?: ReactNode\n}) {\n const { classes } = useStyles()\n return (\n <div className={classes.section}>\n <LabelledSelect sx={{ minWidth: 200 }} {...props} />\n {children}\n </div>\n )\n}\n\nconst NODE_LIMITS = [5000, 20_000, 50_000, 100_000]\n\n// the presets, with a limit a session states among them\nfunction nodeLimitOptions(current: number) {\n return [...new Set([...NODE_LIMITS, current])]\n .sort((a, b) => a - b)\n .map(limit => ({ value: String(limit), label: limit.toLocaleString() }))\n}\n\ninterface NamedTrack {\n trackId: string\n name: string\n}\n\n// '' leaves the pick to the heuristic, so a session can go back to it\nfunction TrackPickSetting({\n label,\n choices,\n stored,\n auto,\n testId,\n onChange,\n children,\n}: {\n label: string\n choices: NamedTrack[]\n stored: string\n auto: NamedTrack | undefined\n testId: string\n onChange: (trackId: string) => void\n children: ReactNode\n}) {\n return choices.length > 0 ? (\n <SettingSelect\n label={label}\n value={choices.some(t => t.trackId === stored) ? stored : ''}\n options={[\n { value: '', label: `Automatic (${auto?.name ?? 'none'})` },\n ...choices.map(({ trackId, name }) => ({\n value: trackId,\n label: name,\n })),\n ]}\n testId={testId}\n onChange={onChange}\n >\n {children}\n </SettingSelect>\n ) : null\n}\n\n// Toggles the menus already offer (halos, genes, color) stay out of here.\n// `children` is the host's own part of the subgraph group.\nconst GraphSettingsDialog = observer(function GraphSettingsDialog(props: {\n model: GraphPaneModel\n onClose: () => void\n children?: ReactNode\n}) {\n const { model, onClose, children } = props\n const { classes } = useStyles()\n\n return (\n <Dialog open onClose={onClose} title=\"Graph settings\">\n <DialogContent>\n <Group title=\"Subgraph\">\n {children}\n <SettingSelect\n label=\"Node limit\"\n value={String(model.maxGraphNodes)}\n options={nodeLimitOptions(model.maxGraphNodes)}\n testId=\"graph-node-limit-select\"\n onChange={limit => {\n model.setMaxGraphNodes(Number(limit))\n }}\n >\n <Caption>\n The most nodes a layout draws; past it the graph is declined. Walk\n rows take no limit.\n </Caption>\n </SettingSelect>\n </Group>\n\n <Group title=\"Drawing\">\n {model.anchorPaths.length > 1 ? (\n <SettingSelect\n label=\"Reference path\"\n value={model.activeReferencePath ?? ''}\n options={model.anchorPaths.map(({ name }) => ({\n value: name,\n label: name,\n }))}\n testId=\"graph-reference-path-select\"\n onChange={name => {\n model.setReferencePath(name)\n void model.recomputeLayout()\n }}\n >\n <Caption>The path the anchored layouts place x along</Caption>\n </SettingSelect>\n ) : null}\n\n <SettingSelect\n label=\"Node width\"\n value={model.nodeWidth}\n options={NODE_WIDTHS}\n testId=\"graph-node-width-select\"\n onChange={width => {\n model.setNodeWidth(width)\n }}\n >\n <Caption>\n Depth as width. In a cut with walks, depth is how many haplotypes\n carry the node.\n </Caption>\n </SettingSelect>\n\n <SettingSelect\n label=\"Link width\"\n value={model.linkWidth}\n options={EDGE_WIDTHS}\n testId=\"graph-link-width-select\"\n onChange={links => {\n model.setLinkWidth(links)\n }}\n >\n <Caption>\n Walks as width, so a common route reads heavy and a private one\n thin.\n </Caption>\n </SettingSelect>\n\n <SettingSwitch\n label=\"Draw paths\"\n checked={model.drawPaths}\n onChange={draw => {\n model.setLayer('paths', draw)\n }}\n >\n <Caption>\n Color each node by the paths through it, one lane per path\n </Caption>\n {model.drawPaths && !model.effectiveDrawPaths ? (\n <Caption warn>\n {model.pathCount > MAX_PATH_COLORS\n ? `Off: ${model.pathCount.toLocaleString()} paths is past the ${MAX_PATH_COLORS} this can tell apart`\n : 'Off: this graph states no paths'}\n </Caption>\n ) : null}\n </SettingSwitch>\n\n <TrackPickSetting\n label=\"Gene track\"\n choices={model.geneTrackChoices}\n stored={model.geneTrackId}\n auto={pickGeneTrack(model.geneTrackChoices, '')}\n testId=\"graph-gene-track-select\"\n onChange={trackId => {\n model.setGeneTrackId(trackId)\n }}\n >\n <Caption>Where genes on the backbone come from</Caption>\n </TrackPickSetting>\n\n <TrackPickSetting\n label=\"Repeat track\"\n choices={model.repeatTrackChoices}\n stored={model.repeatTrackId}\n auto={pickRepeatTrack(model.repeatTrackChoices, '')}\n testId=\"graph-repeat-track-select\"\n onChange={trackId => {\n model.setRepeatTrackId(trackId)\n }}\n >\n <Caption>\n The tandem repeat annotation walk rows measure and tile by\n </Caption>\n </TrackPickSetting>\n </Group>\n\n <Group title=\"Force-directed layout\">\n {model.hasGraph && !model.usesLayoutEngine ? (\n <div className={classes.section}>\n <Caption warn>\n No effect on the current layout until Layout is Force-directed\n </Caption>\n </div>\n ) : null}\n\n <SettingSelect\n label=\"Engine\"\n value={model.layoutEngine}\n options={LAYOUT_ENGINES}\n testId=\"graph-layout-engine-select\"\n onChange={engine => {\n model.setLayoutEngine(engine)\n }}\n >\n <Caption>\n Stress keeps the reference straight, so a zoom keeps the picture;\n FMMM lets the whole graph settle.\n </Caption>\n </SettingSelect>\n\n <SettingSelect\n label=\"Layout quality\"\n value={String(model.layoutQuality)}\n options={LAYOUT_QUALITIES.map(q => ({\n value: String(q.value),\n label: q.label,\n }))}\n testId=\"graph-layout-quality-select\"\n onChange={quality => {\n model.setLayoutQuality(Number(quality))\n }}\n >\n <Caption>\n The engine's iteration budget; higher is slower\n </Caption>\n </SettingSelect>\n\n <SettingSelect\n label=\"Bubble spread\"\n value={model.bubbleSpread}\n options={BUBBLE_SPREADS}\n testId=\"graph-bubble-spread-select\"\n onChange={spread => {\n model.setBubbleSpread(spread)\n }}\n >\n <Caption>How far the layout opens a bubble</Caption>\n </SettingSelect>\n\n {model.layoutEngine === 'stress' ? null : (\n <SettingSwitch\n label=\"Linear layout\"\n checked={model.linearLayout}\n onChange={linear => {\n model.setLinearLayout(linear)\n }}\n >\n <Caption>Keeps a chain of nodes on one line where it can</Caption>\n </SettingSwitch>\n )}\n </Group>\n </DialogContent>\n\n <DialogActions>\n <Button variant=\"contained\" color=\"primary\" onClick={onClose}>\n Close\n </Button>\n </DialogActions>\n </Dialog>\n )\n})\n\nexport default GraphSettingsDialog\n"],
|
|
5
5
|
"mappings": "8WACA,IAAIA,EAAmB,CACrB,CAAE,MAAO,EAAG,MAAO,SAAU,EAC7B,CAAE,MAAO,EAAG,MAAO,MAAO,EAC1B,CAAE,MAAO,EAAG,MAAO,SAAU,EAC7B,CAAE,MAAO,EAAG,MAAO,MAAO,EAC1B,CAAE,MAAO,EAAG,MAAO,MAAO,CAC5B,ECee,SAARC,EAAkD,CACvD,MAAAC,EACA,MAAAC,EACA,QAAAC,EACA,OAAAC,EACA,KAAAC,EACA,GAAAC,EACA,SAAAC,EACA,MAAAC,EACA,MAAAC,EACA,SAAAC,CACF,EAYG,CACD,IAAMC,EAAUC,EAAM,EACtB,OACEC,EAACC,EAAA,CAAY,KAAMT,EAAM,GAAIC,EAAI,SAAUC,EAAU,MAAOC,EAC1D,UAAAO,EAACC,EAAA,CAAW,GAAIL,EAAS,OAAM,GAC5B,SAAAV,EACH,EACAc,EAACE,EAAA,CACC,QAASN,EACT,MAAOT,EACP,MAAOD,EACP,QAAO,GACP,aAAY,GACZ,cAAaG,EACb,YAAac,GACXT,GAASN,EAAQ,KAAKgB,GAAKA,EAAE,QAAUD,CAAM,GAAG,OAASA,EAE3D,SAAUE,GAAK,CACbV,EAASU,EAAE,OAAO,KAAU,CAC9B,EAEC,SAAAjB,EAAQ,IAAIgB,GACXJ,EAACM,EAAA,CAEC,MAAOF,EAAE,MACT,SAAUA,EAAE,SACZ,MAAOA,EAAE,SAAW,OAAYA,EAAE,YAElC,SAAAJ,EAACO,EAAA,CACC,QAASH,EAAE,MACX,UAAWA,EAAE,SAAWA,EAAE,YAAc,OAC1C,GARKA,EAAE,KAST,CACD,EACH,GACF,CAEJ,CCxDA,IAAMI,EAAYC,EAAW,EAAE,CAC7B,QAAS,CACP,aAAc,EAChB,EACA,MAAO,CACL,aAAc,EAChB,EACA,QAAS,CACP,aAAc,CAChB,CACF,CAAC,EAED,SAASC,EAAQ,CACf,KAAAC,EAAO,GACP,SAAAC,CACF,EAGG,CACD,OACEC,EAACC,EAAA,CACC,QAAQ,UACR,UAAU,MACV,MAAOH,EAAO,eAAiB,iBAE9B,SAAAC,EACH,CAEJ,CAEA,SAASG,EAAM,CAAE,MAAAC,EAAO,SAAAJ,CAAS,EAA2C,CAC1E,GAAM,CAAE,QAAAK,CAAQ,EAAIT,EAAU,EAC9B,OACEU,EAAC,WAAQ,UAAWD,EAAQ,MAC1B,UAAAJ,EAACC,EAAA,CAAW,QAAQ,YAAY,UAAWG,EAAQ,QAChD,SAAAD,EACH,EACCJ,GACH,CAEJ,CAEA,SAASO,EAAc,CACrB,MAAAC,EACA,QAAAC,EACA,SAAAC,EACA,SAAAV,CACF,EAKG,CACD,GAAM,CAAE,QAAAK,CAAQ,EAAIT,EAAU,EAC9B,OACEU,EAAC,OAAI,UAAWD,EAAQ,QACtB,UAAAJ,EAACU,EAAA,CACC,QACEV,EAACW,EAAA,CACC,QAASH,EACT,SAAUI,GAAK,CACbH,EAASG,EAAE,OAAO,OAAO,CAC3B,EACF,EAEF,MAAOL,EACT,EACCR,GACH,CAEJ,CAGA,SAASc,EAAgC,CACvC,SAAAd,EACA,GAAGe,CACL,EAEG,CACD,GAAM,CAAE,QAAAV,CAAQ,EAAIT,EAAU,EAC9B,OACEU,EAAC,OAAI,UAAWD,EAAQ,QACtB,UAAAJ,EAACe,EAAA,CAAe,GAAI,CAAE,SAAU,GAAI,EAAI,GAAGD,EAAO,EACjDf,GACH,CAEJ,CAEA,IAAMiB,EAAc,CAAC,IAAM,IAAQ,IAAQ,GAAO,EAGlD,SAASC,EAAiBC,EAAiB,CACzC,MAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAGF,EAAaE,CAAO,CAAC,CAAC,EAC1C,KAAK,CAACC,EAAGC,IAAMD,EAAIC,CAAC,EACpB,IAAIC,IAAU,CAAE,MAAO,OAAOA,CAAK,EAAG,MAAOA,EAAM,eAAe,CAAE,EAAE,CAC3E,CAQA,SAASC,EAAiB,CACxB,MAAAf,EACA,QAAAgB,EACA,OAAAC,EACA,KAAAC,EACA,OAAAC,EACA,SAAAjB,EACA,SAAAV,CACF,EAQG,CACD,OAAOwB,EAAQ,OAAS,EACtBvB,EAACa,EAAA,CACC,MAAON,EACP,MAAOgB,EAAQ,KAAKI,GAAKA,EAAE,UAAYH,CAAM,EAAIA,EAAS,GAC1D,QAAS,CACP,CAAE,MAAO,GAAI,MAAO,cAAcC,GAAM,MAAQ,MAAM,GAAI,EAC1D,GAAGF,EAAQ,IAAI,CAAC,CAAE,QAAAK,EAAS,KAAAC,CAAK,KAAO,CACrC,MAAOD,EACP,MAAOC,CACT,EAAE,CACJ,EACA,OAAQH,EACR,SAAUjB,EAET,SAAAV,EACH,EACE,IACN,CAIA,IAAM+B,EAAsBC,EAAS,SAA6BjB,EAI/D,CACD,GAAM,CAAE,MAAAkB,EAAO,QAAAC,EAAS,SAAAlC,CAAS,EAAIe,EAC/B,CAAE,QAAAV,CAAQ,EAAIT,EAAU,EAE9B,OACEU,EAAC6B,EAAA,CAAO,KAAI,GAAC,QAASD,EAAS,MAAM,iBACnC,UAAA5B,EAAC8B,EAAA,CACC,UAAA9B,EAACH,EAAA,CAAM,MAAM,WACV,UAAAH,EACDC,EAACa,EAAA,CACC,MAAM,aACN,MAAO,OAAOmB,EAAM,aAAa,EACjC,QAASf,EAAiBe,EAAM,aAAa,EAC7C,OAAO,0BACP,SAAUX,GAAS,CACjBW,EAAM,iBAAiB,OAAOX,CAAK,CAAC,CACtC,EAEA,SAAArB,EAACH,EAAA,CAAQ,kGAGT,EACF,GACF,EAEAQ,EAACH,EAAA,CAAM,MAAM,UACV,UAAA8B,EAAM,YAAY,OAAS,EAC1BhC,EAACa,EAAA,CACC,MAAM,iBACN,MAAOmB,EAAM,qBAAuB,GACpC,QAASA,EAAM,YAAY,IAAI,CAAC,CAAE,KAAAH,CAAK,KAAO,CAC5C,MAAOA,EACP,MAAOA,CACT,EAAE,EACF,OAAO,8BACP,SAAUA,GAAQ,CAChBG,EAAM,iBAAiBH,CAAI,EACtBG,EAAM,gBAAgB,CAC7B,EAEA,SAAAhC,EAACH,EAAA,CAAQ,uDAA2C,EACtD,EACE,KAEJG,EAACa,EAAA,CACC,MAAM,aACN,MAAOmB,EAAM,UACb,QAASI,EACT,OAAO,0BACP,SAAUC,GAAS,CACjBL,EAAM,aAAaK,CAAK,CAC1B,EAEA,SAAArC,EAACH,EAAA,CAAQ,6FAGT,EACF,EAEAG,EAACa,EAAA,CACC,MAAM,aACN,MAAOmB,EAAM,UACb,QAASM,EACT,OAAO,0BACP,SAAUC,GAAS,CACjBP,EAAM,aAAaO,CAAK,CAC1B,EAEA,SAAAvC,EAACH,EAAA,CAAQ,iFAGT,EACF,EAEAQ,EAACC,EAAA,CACC,MAAM,aACN,QAAS0B,EAAM,UACf,SAAUQ,GAAQ,CAChBR,EAAM,SAAS,QAASQ,CAAI,CAC9B,EAEA,UAAAxC,EAACH,EAAA,CAAQ,sEAET,EACCmC,EAAM,WAAa,CAACA,EAAM,mBACzBhC,EAACH,EAAA,CAAQ,KAAI,GACV,SAAAmC,EAAM,UAAYS,EACf,QAAQT,EAAM,UAAU,eAAe,CAAC,sBAAsBS,CAAe,uBAC7E,kCACN,EACE,MACN,EAEAzC,EAACsB,EAAA,CACC,MAAM,aACN,QAASU,EAAM,iBACf,OAAQA,EAAM,YACd,KAAMU,EAAcV,EAAM,iBAAkB,EAAE,EAC9C,OAAO,0BACP,SAAUJ,GAAW,CACnBI,EAAM,eAAeJ,CAAO,CAC9B,EAEA,SAAA5B,EAACH,EAAA,CAAQ,iDAAqC,EAChD,EAEAG,EAACsB,EAAA,CACC,MAAM,eACN,QAASU,EAAM,mBACf,OAAQA,EAAM,cACd,KAAMW,EAAgBX,EAAM,mBAAoB,EAAE,EAClD,OAAO,4BACP,SAAUJ,GAAW,CACnBI,EAAM,iBAAiBJ,CAAO,CAChC,EAEA,SAAA5B,EAACH,EAAA,CAAQ,sEAET,EACF,GACF,EAEAQ,EAACH,EAAA,CAAM,MAAM,wBACV,UAAA8B,EAAM,UAAY,CAACA,EAAM,iBACxBhC,EAAC,OAAI,UAAWI,EAAQ,QACtB,SAAAJ,EAACH,EAAA,CAAQ,KAAI,GAAC,0EAEd,EACF,EACE,KAEJG,EAACa,EAAA,CACC,MAAM,SACN,MAAOmB,EAAM,aACb,QAASY,EACT,OAAO,6BACP,SAAUC,GAAU,CAClBb,EAAM,gBAAgBa,CAAM,CAC9B,EAEA,SAAA7C,EAACH,EAAA,CAAQ,+GAGT,EACF,EAEAG,EAACa,EAAA,CACC,MAAM,iBACN,MAAO,OAAOmB,EAAM,aAAa,EACjC,QAASc,EAAiB,IAAIC,IAAM,CAClC,MAAO,OAAOA,EAAE,KAAK,EACrB,MAAOA,EAAE,KACX,EAAE,EACF,OAAO,8BACP,SAAUC,GAAW,CACnBhB,EAAM,iBAAiB,OAAOgB,CAAO,CAAC,CACxC,EAEA,SAAAhD,EAACH,EAAA,CAAQ,2DAET,EACF,EAEAG,EAACa,EAAA,CACC,MAAM,gBACN,MAAOmB,EAAM,aACb,QAASiB,EACT,OAAO,6BACP,SAAUC,GAAU,CAClBlB,EAAM,gBAAgBkB,CAAM,CAC9B,EAEA,SAAAlD,EAACH,EAAA,CAAQ,6CAAiC,EAC5C,EAECmC,EAAM,eAAiB,SAAW,KACjChC,EAACM,EAAA,CACC,MAAM,gBACN,QAAS0B,EAAM,aACf,SAAUmB,GAAU,CAClBnB,EAAM,gBAAgBmB,CAAM,CAC9B,EAEA,SAAAnD,EAACH,EAAA,CAAQ,2DAA+C,EAC1D,GAEJ,GACF,EAEAG,EAACoD,EAAA,CACC,SAAApD,EAACqD,EAAA,CAAO,QAAQ,YAAY,MAAM,UAAU,QAASpB,EAAS,iBAE9D,EACF,GACF,CAEJ,CAAC,EAEMqB,GAAQxB",
|
|
6
6
|
"names": ["LAYOUT_QUALITIES", "LabelledSelect", "label", "value", "options", "testId", "size", "sx", "disabled", "title", "shown", "onChange", "labelId", "useId", "jsxs", "FormControl", "jsx", "InputLabel", "Select", "picked", "o", "e", "MenuItem", "ListItemText", "useStyles", "makeStyles", "Caption", "warn", "children", "jsx", "Typography", "Group", "title", "classes", "jsxs", "SettingSwitch", "label", "checked", "onChange", "FormControlLabel", "Switch", "e", "SettingSelect", "props", "LabelledSelect", "NODE_LIMITS", "nodeLimitOptions", "current", "a", "b", "limit", "TrackPickSetting", "choices", "stored", "auto", "testId", "t", "trackId", "name", "GraphSettingsDialog", "observer", "model", "onClose", "Dialog", "DialogContent", "NODE_WIDTHS", "width", "EDGE_WIDTHS", "links", "draw", "MAX_PATH_COLORS", "pickGeneTrack", "pickRepeatTrack", "LAYOUT_ENGINES", "engine", "LAYOUT_QUALITIES", "q", "quality", "BUBBLE_SPREADS", "spread", "linear", "DialogActions", "Button", "GraphSettingsDialog_default"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as Ve}from"./chunk-M2D7NUOY.js";import{b as ze}from"./chunk-
|
|
1
|
+
import{s as Ve}from"./chunk-M2D7NUOY.js";import{b as ze}from"./chunk-TBNAAP6E.js";import{a as He}from"./chunk-VKZALU57.js";import{a as $e,c as Ye}from"./chunk-J5RMHLFJ.js";function qe(e){let r=[],t=0,o;for(let n=0,i=e.length;n<i;n++){let a=e.charCodeAt(n);if(a>=48&&a<=57)t=t*10+a-48;else if(a===58)o=t,t=0;else{let f=e[n];f==="M"||f==="="||f==="X"?r.push({own:o===void 0?t:o,mate:t,op:"M"}):f==="I"?r.push({own:0,mate:t,op:f}):(f==="D"||f==="N")&&r.push({own:t,mate:0,op:f}),o=void 0,t=0}}return r}function Ae(e){let r="";for(let{own:t,mate:o,op:n}of qe(e))r+=n==="M"?t===0?`${o}I`:o===0?`${t}D`:`${t}M`:`${n==="I"?o:t}${n}`;return r}var Se=2**28-1;function ve(e,r,t){for(let o=r;o>0;o-=Se)e.push((Math.min(o,Se)<<4|t)>>>0)}function kr(e,r,t){if(r===t)ve(e,r,0);else{let o=Math.ceil(Math.max(r,t)/Se);for(let n=0;n<o;n++){let i=Math.floor(r*(n+1)/o)-Math.floor(r*n/o),a=Math.floor(t*(n+1)/o)-Math.floor(t*n/o);e.push((i<<4|9)>>>0,(a<<4|9)>>>0)}}}function _e(e){let r=[];for(let{own:t,mate:o,op:n}of qe(e))n==="M"?kr(r,t,o):n==="I"?ve(r,o,1):ve(r,t,n==="N"?3:2);return Uint32Array.from(r)}function Gr(e){return e>=48&&e<=57}function Dr(e){return e!==void 0&&/[A-Za-z]/.test(e)}function Ke(e,r){let t=r;for(;t<e.length&&Dr(e[t]);)t++;return t}function Qe(e,r){let t=r,o=0;for(;t<e.length&&Gr(e.charCodeAt(t));)o=o*10+(e.charCodeAt(t)-48),t++;return{value:o,next:t}}function rr(e,r){let t=0;for(;t<e.length;){let o=e[t];if(o===":"){let{value:n,next:i}=Qe(e,t+1);r(":",n,n,t+1,i),t=i}else if(o==="="){let n=Ke(e,t+1),i=n-t-1;r("=",i,i,t+1,n),t=n}else if(o==="*")r("*",1,1,t+1,Math.min(t+3,e.length)),t+=3;else if(o==="+"||o==="-"){let n=Ke(e,t+1),i=n-t-1;r(o,o==="-"?i:0,o==="+"?i:0,t+1,n),t=n}else if(o==="~"){let{value:n,next:i}=Qe(e,t+3),a=Math.min(i+2,e.length);r("~",n,0,t+1,a),t=a}else t++}}function Ce(e,r,t,o){let n=t??Number.NEGATIVE_INFINITY,i=o??Number.POSITIVE_INFINITY,a=0;rr(e,(f,p,s,c,u)=>{if(f==="*")a>=n&&a<i&&r(88,a,1,e[c+1]??"",-1,0,0);else if(f==="+"){if(a>=n&&a<=i){let m=e.slice(c,u);r(73,a,s,m,-1,0,s)}}else(f==="-"||f==="~")&&a<i&&a+p>n&&r(f==="-"?68:78,a,p,"",-1,0,0);a+=p})}function tr(e,r,t,o){let n=0,i=0,a=[],f=t&&r;for(let p=0,s=e.length;p<s;p++){let c=e[p],u=c>>>4,m=c&15;if(m===0||m===7){if(f)for(let l=0;l<u;l++)(r.charCodeAt(i+l)|32)!==(t.charCodeAt(n+l)|32)&&a.push({start:n+l,type:"mismatch",base:r[i+l],altbase:t[n+l],length:1});i+=u,n+=u}else if(m===1)a.push({start:n,type:"insertion",insertlen:u,insertedBases:r?.slice(i,i+u),length:0}),i+=u;else if(m===2)a.push({start:n,type:"deletion",length:u}),n+=u;else if(m===3)a.push({start:n,type:"skip",length:u}),n+=u;else if(m===8){for(let l=0;l<u;l++)a.push({start:n+l,type:"mismatch",base:r?.[i+l]||"X",qual:o?.[i+l],length:1});i+=u,n+=u}else m===5?a.push({start:n,type:"hardclip",cliplen:u,length:1}):m===4&&(a.push({start:n,type:"softclip",cliplen:u,length:1}),i+=u)}return a}function or(e,r,t,o,n){if(!r)return[];let i=[],a=r.length,f=o.length,p=n!==void 0,s=t.length,c=!1;for(let b=0;b<s;b++)if(t[b].type==="skip"){c=!0;break}let u=0,m=0,l=0,y=0,d=0,x=0,g=e.length;for(;x<g;){let b=e.charCodeAt(x);if(b>=48&&b<=57){let v=0;for(;x<g;){let S=e.charCodeAt(x);if(S>=48&&S<=57)v=v*10+(S-48),x++;else break}u+=v}else if(b===94)for(x++;x<g&&e.charCodeAt(x)>=65;)x++,u++;else if(b>=65){let v=e[x];if(x++,c&&s>0)for(let I=d;I<s;I++){let R=t[I];R.type==="skip"&&u>=R.start&&(u+=R.length,d=I+1)}let S=l,C=y;for(let I=m;I<a&&C<=u;I++,m=I){let R=r[I],L=R>>>4,A=R&15;A===4||A===1?S+=L:A===2||A===6||A===3?C+=L:A!==5&&(S+=L,C+=L)}l=S,y=C;let F=S-(C-u),q=F<f?o[F]:"X";i.push({start:u,base:q,qual:p?n[F]:void 0,altbase:v,length:1,type:"mismatch"}),u++}else x++}return i}var nr={77:0,73:1,68:2,78:3,83:4,72:5,80:6,61:7,88:8};function ir(e=""){let r=0,t=[];for(let o=0,n=e.length;o<n;o++){let i=e.charCodeAt(o);if(i>=48&&i<=57)r=r*10+(i-48);else{let a=nr[i];t.push(r<<4|a),r=0}}return t}function Te(e=""){let r=0;for(let i=0,a=e.length;i<a;i++){let f=e.charCodeAt(i);(f<48||f>57)&&r++}let t=new Uint32Array(r),o=0,n=0;for(let i=0,a=e.length;i<a;i++){let f=e.charCodeAt(i);f>=48&&f<=57?o=o*10+(f-48):(t[n++]=o<<4|nr[f],o=0)}return t}function J(e,r,t,o,n){let i=ir(e),a=e?tr(i,t,o,n):[];return r&&t?a.concat(or(r,i,a,t,n)):a}var N=class extends $e{get(r){return r==="mismatches"?J(this.walkableCigar):r==="clipLengthAtStartOfRead"?this.clipLengthAtStartOfRead:r==="name"?super.get("name")??this.mate?.refName:super.get(r)}get mate(){return super.get("mate")}get walkableCigar(){let r=super.get("CIGAR"),t=super.get("coarseCigar");return typeof r=="string"?r:typeof t=="string"?Ae(t):void 0}get clipLengthAtStartOfRead(){return this.mate?.start??0}forEachMismatch(r,t){let o=this.get("start"),n=t?.start===void 0?void 0:t.start-o,i=t?.end===void 0?void 0:t.end-o,a=this.get("cs");if(a)Ce(a,r,n,i);else{let f=n??Number.NEGATIVE_INFINITY,p=i??Number.POSITIVE_INFINITY;for(let s of J(this.walkableCigar))(s.type==="deletion"||s.type==="skip"?s.start<p&&s.start+s.length>f:s.start>=f&&s.start<=p)&&(s.type==="mismatch"?r(88,s.start,s.length,s.base,s.qual??-1,0,0):s.type==="insertion"?r(73,s.start,s.length,s.insertedBases??"",-1,0,s.insertlen):s.type==="deletion"?r(68,s.start,s.length,"",-1,0,0):s.type==="skip"&&r(78,s.start,s.length,"",-1,0,0))}}};var we=function(e,r){return we=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])},we(e,r)};function H(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");we(e,r);function t(){this.constructor=e}e.prototype=r===null?Object.create(r):(t.prototype=r.prototype,new t)}function ar(e,r,t,o){function n(i){return i instanceof t?i:new t(function(a){a(i)})}return new(t||(t=Promise))(function(i,a){function f(c){try{s(o.next(c))}catch(u){a(u)}}function p(c){try{s(o.throw(c))}catch(u){a(u)}}function s(c){c.done?i(c.value):n(c.value).then(f,p)}s((o=o.apply(e,r||[])).next())})}function ee(e,r){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},o,n,i,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=f(0),a.throw=f(1),a.return=f(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function f(s){return function(c){return p([s,c])}}function p(s){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(t=0)),t;)try{if(o=1,n&&(i=s[0]&2?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[s[0]&2,i.value]),s[0]){case 0:case 1:i=s;break;case 4:return t.label++,{value:s[1],done:!1};case 5:t.label++,n=s[1],s=[0];continue;case 7:s=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){t=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){t.label=s[1];break}if(s[0]===6&&t.label<i[1]){t.label=i[1],i=s;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(s);break}i[2]&&t.ops.pop(),t.trys.pop();continue}s=r.call(e,t)}catch(c){s=[6,c],n=0}finally{o=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}function P(e){var r=typeof Symbol=="function"&&Symbol.iterator,t=r&&e[r],o=0;if(t)return t.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function D(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var o=t.call(e),n,i=[],a;try{for(;(r===void 0||r-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(f){a={error:f}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(a)throw a.error}}return i}function j(e,r,t){if(t||arguments.length===2)for(var o=0,n=r.length,i;o<n;o++)(i||!(o in r))&&(i||(i=Array.prototype.slice.call(r,0,o)),i[o]=r[o]);return e.concat(i||Array.prototype.slice.call(r))}function k(e){return this instanceof k?(this.v=e,this):new k(e)}function sr(e,r,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=t.apply(e,r||[]),n,i=[];return n=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",a),n[Symbol.asyncIterator]=function(){return this},n;function a(l){return function(y){return Promise.resolve(y).then(l,u)}}function f(l,y){o[l]&&(n[l]=function(d){return new Promise(function(x,g){i.push([l,d,x,g])>1||p(l,d)})},y&&(n[l]=y(n[l])))}function p(l,y){try{s(o[l](y))}catch(d){m(i[0][3],d)}}function s(l){l.value instanceof k?Promise.resolve(l.value.v).then(c,u):m(i[0][2],l)}function c(l){p("next",l)}function u(l){p("throw",l)}function m(l,y){l(y),i.shift(),i.length&&p(i[0][0],i[0][1])}}function fr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e[Symbol.asyncIterator],t;return r?r.call(e):(e=typeof P=="function"?P(e):e[Symbol.iterator](),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(i){t[i]=e[i]&&function(a){return new Promise(function(f,p){a=e[i](a),n(f,p,a.done,a.value)})}}function n(i,a,f,p){Promise.resolve(p).then(function(s){i({value:s,done:f})},a)}}function h(e){return typeof e=="function"}function pr(e){var r=function(o){Error.call(o),o.stack=new Error().stack},t=e(r);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var re=pr(function(e){return function(t){e(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
2
|
`+t.map(function(o,n){return n+1+") "+o.toString()}).join(`
|
|
3
3
|
`):"",this.name="UnsubscriptionError",this.errors=t}});function Oe(e,r){if(e){var t=e.indexOf(r);0<=t&&e.splice(t,1)}}var te=(function(){function e(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var r,t,o,n,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var f=P(a),p=f.next();!p.done;p=f.next()){var s=p.value;s.remove(this)}}catch(d){r={error:d}}finally{try{p&&!p.done&&(t=f.return)&&t.call(f)}finally{if(r)throw r.error}}else a.remove(this);var c=this.initialTeardown;if(h(c))try{c()}catch(d){i=d instanceof re?d.errors:[d]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var m=P(u),l=m.next();!l.done;l=m.next()){var y=l.value;try{cr(y)}catch(d){i=i??[],d instanceof re?i=j(j([],D(i)),D(d.errors)):i.push(d)}}}catch(d){o={error:d}}finally{try{l&&!l.done&&(n=m.return)&&n.call(m)}finally{if(o)throw o.error}}}if(i)throw new re(i)}},e.prototype.add=function(r){var t;if(r&&r!==this)if(this.closed)cr(r);else{if(r instanceof e){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(r)}},e.prototype._hasParent=function(r){var t=this._parentage;return t===r||Array.isArray(t)&&t.includes(r)},e.prototype._addParent=function(r){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(r),t):t?[t,r]:r},e.prototype._removeParent=function(r){var t=this._parentage;t===r?this._parentage=null:Array.isArray(t)&&Oe(t,r)},e.prototype.remove=function(r){var t=this._finalizers;t&&Oe(t,r),r instanceof e&&r._removeParent(this)},e.EMPTY=(function(){var r=new e;return r.closed=!0,r})(),e})();var Zt=te.EMPTY;function oe(e){return e instanceof te||e&&"closed"in e&&h(e.remove)&&h(e.add)&&h(e.unsubscribe)}function cr(e){h(e)?e():e.unsubscribe()}var w={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var U={setTimeout:function(e,r){for(var t=[],o=2;o<arguments.length;o++)t[o-2]=arguments[o];var n=U.delegate;return n?.setTimeout?n.setTimeout.apply(n,j([e,r],D(t))):setTimeout.apply(void 0,j([e,r],D(t)))},clearTimeout:function(e){var r=U.delegate;return(r?.clearTimeout||clearTimeout)(e)},delegate:void 0};function ne(e){U.setTimeout(function(){var r=w.onUnhandledError;if(r)r(e);else throw e})}function Re(){}var ur=(function(){return Me("C",void 0,void 0)})();function lr(e){return Me("E",void 0,e)}function mr(e){return Me("N",e,void 0)}function Me(e,r,t){return{kind:e,value:r,error:t}}var G=null;function dr(e){if(w.useDeprecatedSynchronousErrorHandling){var r=!G;if(r&&(G={errorThrown:!1,error:null}),e(),r){var t=G,o=t.errorThrown,n=t.error;if(G=null,o)throw n}}else e()}function xr(e){w.useDeprecatedSynchronousErrorHandling&&G&&(G.errorThrown=!0,G.error=e)}var z=(function(e){H(r,e);function r(t){var o=e.call(this)||this;return o.isStopped=!1,t?(o.destination=t,oe(t)&&t.add(o)):o.destination=Yr,o}return r.create=function(t,o,n){return new ae(t,o,n)},r.prototype.next=function(t){this.isStopped?Le(mr(t),this):this._next(t)},r.prototype.error=function(t){this.isStopped?Le(lr(t),this):(this.isStopped=!0,this._error(t))},r.prototype.complete=function(){this.isStopped?Le(ur,this):(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(t){this.destination.next(t)},r.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r})(te);var Br=Function.prototype.bind;function Fe(e,r){return Br.call(e,r)}var Wr=(function(){function e(r){this.partialObserver=r}return e.prototype.next=function(r){var t=this.partialObserver;if(t.next)try{t.next(r)}catch(o){ie(o)}},e.prototype.error=function(r){var t=this.partialObserver;if(t.error)try{t.error(r)}catch(o){ie(o)}else ie(r)},e.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(t){ie(t)}},e})(),ae=(function(e){H(r,e);function r(t,o,n){var i=e.call(this)||this,a;if(h(t)||!t)a={next:t??void 0,error:o??void 0,complete:n??void 0};else{var f;i&&w.useDeprecatedNextContext?(f=Object.create(t),f.unsubscribe=function(){return i.unsubscribe()},a={next:t.next&&Fe(t.next,f),error:t.error&&Fe(t.error,f),complete:t.complete&&Fe(t.complete,f)}):a=t}return i.destination=new Wr(a),i}return r})(z);function ie(e){w.useDeprecatedSynchronousErrorHandling?xr(e):ne(e)}function $r(e){throw e}function Le(e,r){var t=w.onStoppedNotification;t&&U.setTimeout(function(){return t(e,r)})}var Yr={closed:!0,next:Re,error:$r,complete:Re};var B=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function hr(e){return e}function yr(e){return e.length===0?hr:e.length===1?e[0]:function(t){return e.reduce(function(o,n){return n(o)},t)}}var _=(function(){function e(r){r&&(this._subscribe=r)}return e.prototype.lift=function(r){var t=new e;return t.source=this,t.operator=r,t},e.prototype.subscribe=function(r,t,o){var n=this,i=zr(r)?r:new ae(r,t,o);return dr(function(){var a=n,f=a.operator,p=a.source;i.add(f?f.call(i,p):p?n._subscribe(i):n._trySubscribe(i))}),i},e.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(t){r.error(t)}},e.prototype.forEach=function(r,t){var o=this;return t=gr(t),new t(function(n,i){var a=new ae({next:function(f){try{r(f)}catch(p){i(p),a.unsubscribe()}},error:i,complete:n});o.subscribe(a)})},e.prototype._subscribe=function(r){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(r)},e.prototype[B]=function(){return this},e.prototype.pipe=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return yr(r)(this)},e.prototype.toPromise=function(r){var t=this;return r=gr(r),new r(function(o,n){var i;t.subscribe(function(a){return i=a},function(a){return n(a)},function(){return o(i)})})},e.create=function(r){return new e(r)},e})();function gr(e){var r;return(r=e??w.Promise)!==null&&r!==void 0?r:Promise}function Hr(e){return e&&h(e.next)&&h(e.error)&&h(e.complete)}function zr(e){return e&&e instanceof z||Hr(e)&&oe(e)}function Vr(e){return h(e?.lift)}function E(e){return function(r){if(Vr(r))return r.lift(function(t){try{return e(t,this)}catch(o){this.error(o)}});throw new TypeError("Unable to lift unknown Observable type")}}function M(e,r,t,o,n){return new qr(e,r,t,o,n)}var qr=(function(e){H(r,e);function r(t,o,n,i,a,f){var p=e.call(this,t)||this;return p.onFinalize=a,p.shouldUnsubscribe=f,p._next=o?function(s){try{o(s)}catch(c){t.error(c)}}:e.prototype._next,p._error=i?function(s){try{i(s)}catch(c){t.error(c)}finally{this.unsubscribe()}}:e.prototype._error,p._complete=n?function(){try{n()}catch(s){t.error(s)}finally{this.unsubscribe()}}:e.prototype._complete,p}return r.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;e.prototype.unsubscribe.call(this),!o&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},r})(z);var se=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function fe(e){return h(e?.then)}function pe(e){return h(e[B])}function ce(e){return Symbol.asyncIterator&&h(e?.[Symbol.asyncIterator])}function ue(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Kr(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var le=Kr();function me(e){return h(e?.[le])}function de(e){return sr(this,arguments,function(){var t,o,n,i;return ee(this,function(a){switch(a.label){case 0:t=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,k(t.read())];case 3:return o=a.sent(),n=o.value,i=o.done,i?[4,k(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,k(n)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function xe(e){return h(e?.getReader)}function O(e){if(e instanceof _)return e;if(e!=null){if(pe(e))return Qr(e);if(se(e))return Xr(e);if(fe(e))return Zr(e);if(ce(e))return br(e);if(me(e))return Jr(e);if(xe(e))return et(e)}throw ue(e)}function Qr(e){return new _(function(r){var t=e[B]();if(h(t.subscribe))return t.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Xr(e){return new _(function(r){for(var t=0;t<e.length&&!r.closed;t++)r.next(e[t]);r.complete()})}function Zr(e){return new _(function(r){e.then(function(t){r.closed||(r.next(t),r.complete())},function(t){return r.error(t)}).then(null,ne)})}function Jr(e){return new _(function(r){var t,o;try{for(var n=P(e),i=n.next();!i.done;i=n.next()){var a=i.value;if(r.next(a),r.closed)return}}catch(f){t={error:f}}finally{try{i&&!i.done&&(o=n.return)&&o.call(n)}finally{if(t)throw t.error}}r.complete()})}function br(e){return new _(function(r){rt(e,r).catch(function(t){return r.error(t)})})}function et(e){return br(de(e))}function rt(e,r){var t,o,n,i;return ar(this,void 0,void 0,function(){var a,f;return ee(this,function(p){switch(p.label){case 0:p.trys.push([0,5,6,11]),t=fr(e),p.label=1;case 1:return[4,t.next()];case 2:if(o=p.sent(),!!o.done)return[3,4];if(a=o.value,r.next(a),r.closed)return[2];p.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return f=p.sent(),n={error:f},[3,11];case 6:return p.trys.push([6,,9,10]),o&&!o.done&&(i=t.return)?[4,i.call(t)]:[3,8];case 7:p.sent(),p.label=8;case 8:return[3,10];case 9:if(n)throw n.error;return[7];case 10:return[7];case 11:return r.complete(),[2]}})})}function T(e,r,t,o,n){o===void 0&&(o=0),n===void 0&&(n=!1);var i=r.schedule(function(){t(),n?e.add(this.schedule(null,o)):this.unsubscribe()},o);if(e.add(i),!n)return i}function he(e,r){return r===void 0&&(r=0),E(function(t,o){t.subscribe(M(o,function(n){return T(o,e,function(){return o.next(n)},r)},function(){return T(o,e,function(){return o.complete()},r)},function(n){return T(o,e,function(){return o.error(n)},r)}))})}function ye(e,r){return r===void 0&&(r=0),E(function(t,o){o.add(e.schedule(function(){return t.subscribe(o)},r))})}function Sr(e,r){return O(e).pipe(ye(r),he(r))}function vr(e,r){return O(e).pipe(ye(r),he(r))}function Ar(e,r){return new _(function(t){var o=0;return r.schedule(function(){o===e.length?t.complete():(t.next(e[o++]),t.closed||this.schedule())})})}function _r(e,r){return new _(function(t){var o;return T(t,r,function(){o=e[le](),T(t,r,function(){var n,i,a;try{n=o.next(),i=n.value,a=n.done}catch(f){t.error(f);return}a?t.complete():t.next(i)},0,!0)}),function(){return h(o?.return)&&o.return()}})}function ge(e,r){if(!e)throw new Error("Iterable cannot be null");return new _(function(t){T(t,r,function(){var o=e[Symbol.asyncIterator]();T(t,r,function(){o.next().then(function(n){n.done?t.complete():t.next(n.value)})},0,!0)})})}function Cr(e,r){return ge(de(e),r)}function Ir(e,r){if(e!=null){if(pe(e))return Sr(e,r);if(se(e))return Ar(e,r);if(fe(e))return vr(e,r);if(ce(e))return ge(e,r);if(me(e))return _r(e,r);if(xe(e))return Cr(e,r)}throw ue(e)}function Ne(e,r){return r?Ir(e,r):O(e)}function V(e,r){return E(function(t,o){var n=0;t.subscribe(M(o,function(i){o.next(e.call(r,i,n++))}))})}function Er(e,r,t,o,n,i,a,f){var p=[],s=0,c=0,u=!1,m=function(){u&&!p.length&&!s&&r.complete()},l=function(d){return s<o?y(d):p.push(d)},y=function(d){i&&r.next(d),s++;var x=!1;O(t(d,c++)).subscribe(M(r,function(g){n?.(g),i?l(g):r.next(g)},function(){x=!0},void 0,function(){if(x)try{s--;for(var g=function(){var b=p.shift();a?T(r,a,function(){return y(b)}):y(b)};p.length&&s<o;)g();m()}catch(b){r.error(b)}}))};return e.subscribe(M(r,l,function(){u=!0,m()})),function(){f?.()}}function W(e,r,t){return t===void 0&&(t=1/0),h(r)?W(function(o,n){return V(function(i,a){return r(o,i,n,a)})(O(e(o,n)))},t):(typeof r=="number"&&(t=r),E(function(o,n){return Er(o,n,e,t)}))}function Tr(e,r,t,o,n){return function(i,a){var f=t,p=r,s=0;i.subscribe(M(a,function(c){var u=s++;p=f?e(p,c,u):(f=!0,c),o&&a.next(p)},n&&(function(){f&&a.next(p),a.complete()})))}}function wr(e,r){return E(Tr(e,r,arguments.length>=2,!1,!0))}var tt=function(e,r){return e.push(r),e};function be(){return E(function(e,r){wr(tt,[])(e).subscribe(r)})}var ot=397,nt=387,it=385;function Or(e){return(1<<e&ot)!==0}function Rr(e){return(1<<e&nt)!==0}function Mr(e){return(1<<e&it)!==0}function Pe(e,r,t,o,n,i,a){let f=n===-1?-1:1,p=r,s=n===-1?o:t,c=[],u=1/0,m=-1/0,l=1/0,y=-1/0,d=(x,g)=>{l=Math.min(l,x,g),y=Math.max(y,x,g)};for(let x=0;x<e.length;x++){let g=e[x],b=g>>>4,v=g&15,S=v===9,C=S||Or(v)?b:0,F=S?e[++x]>>>4:Rr(v)?b:0,q=p+C,I=s+F*f,R=p,L=q;if(L>=i&&R<=a)if(C>0){let A=Math.max(R,i),$=Math.min(L,a);if($>A)if(u=Math.min(u,A),m=Math.max(m,$),S){let je=F/b,Ue=$-A,Be=Math.round(Ue*je),We=Math.round(s+(A-p)*je*f);c.push(Ue<<4|9,Be<<4|9),d(We,We+Be*f)}else c.push($-A<<4|v),Mr(v)?d(s+(A-p)*f,s+($-p)*f):d(s,s)}else F>0&&(S?c.push(g,e[x]):c.push(g),u=Math.min(u,p),m=Math.max(m,p),d(s,I));if(p=q,s=I,p>a)break}if(c.length!==0)return{start:u,end:m,mateStart:l,mateEnd:y,cigar:Uint32Array.from(c)}}function at(e){return e===1||e===2||e===3}function ke(e,r,t,o,n,i){let a=n===-1?-1:1,f=[],p=r,s=n===-1?o:t,c,u=!1,m=()=>{c!==void 0&&u&&c.qHi>c.qLo&&f.push({start:c.qLo,end:c.qHi,mateStart:c.tLo,mateEnd:c.tHi,cigar:Uint32Array.from(c.ops)}),c=void 0,u=!1};for(let l=0;l<e.length;l++){let y=e[l],d=y>>>4,x=y&15,g=x===9,b=g?e[++l]:void 0,v=g||Or(x)?d:0,S=b!==void 0?b>>>4:Rr(x)?d:0,C=s+S*a;at(x)&&d>=i?m():(v>0||S>0)&&(c===void 0&&(c={qLo:p,qHi:p,tLo:s,tHi:s,ops:[]}),c.qHi=p+v,c.tLo=Math.min(c.tLo,s,C),c.tHi=Math.max(c.tHi,s,C),c.ops.push(y),b!==void 0&&c.ops.push(b),u=u||g||Mr(x)),p+=v,s=C}return m(),f}function Fr(e){let r=e.get("CIGAR");return typeof r=="string"?r:void 0}function Lr(e){let r=e.get("coarseCigar");return typeof r=="string"?r:void 0}function Ge(e){let r=Fr(e),t=r===void 0?Lr(e):void 0;return r!==void 0?Te(r):t!==void 0?_e(t):void 0}var st=["CIGAR","cs","coarseCigar","cg","cr"];function ft(e){return typeof e=="object"&&e!==null&&"refName"in e&&"start"in e&&"end"in e&&typeof e.refName=="string"&&typeof e.start=="number"&&typeof e.end=="number"}function pt(e){let r=e.get("mate");return ft(r)?r:void 0}function ct(e,r,t,o){let n=Math.max(e.start,o.start),i=Math.min(e.end,o.end),a=(r.end-r.start)/Math.max(e.end-e.start,1),f=c=>t===-1?r.end-(c-e.start)*a:r.start+(c-e.start)*a,p=Math.round(f(n)),s=Math.round(f(i));return i>n?{start:n,end:i,mateStart:Math.min(p,s),mateEnd:Math.max(p,s)}:void 0}function ut(e,r,t,o,n){let i={start:e.get("start"),end:e.get("end")},a=e.get("strand")===-1?-1:1,f=i.start>=t.start&&i.end<=t.end,p=f&&o===void 0&&!n?void 0:Ge(e);if(p===void 0){let s=f?{...i,mateStart:r.start,mateEnd:r.end}:ct(i,r,a,t);return s===void 0?[]:[s]}else return(o===void 0?[{...i,mateStart:r.start,mateEnd:r.end,cigar:p}]:ke(p,i.start,r.start,r.end,a,o)).flatMap(c=>{let u=Pe(c.cigar,c.start,c.mateStart,c.mateEnd,a,t.start,t.end);return u===void 0?[]:[u]})}function lt(e,r,t,o,n,i){let a=`:${o.start}-${o.end}${n}`,f=e.toJSON(),p={...f,uniqueId:`${e.id()}${a}`,recordId:f.recordId??e.id(),start:t.start,end:t.end,mate:{...r,start:t.mateStart,end:t.mateEnd}};f.syntenyId!==void 0&&(p.syntenyId=`${String(f.syntenyId)}${a}`);for(let s of st)delete p[s];return i&&t.cigar&&(p.alignmentOps=t.cigar),new N(p)}function Nr(e,r,t,o=!1){let n=pt(e);if(n===void 0)return[e];{let i=ut(e,n,r,t,o);return i.map((a,f)=>lt(e,n,a,r,i.length>1?`/${f}`:"",o))}}var Pr=class extends ze{constructor(){super(...arguments);this.recordsAreAlignments=!0}static{this.capabilities=["getFeatures","getRefNames"]}async hasDataForRefName(){return!0}getFeaturesInMultipleRegions(t,o={}){let{clipToRegion:n,splitAtGapBp:i,keepAlignment:a,...f}=o,p=n&&this.recordsAreAlignments,s=Ye(f.statusCallback);return Ne(t).pipe(W((c,u)=>this.getFeatures(c,{...f,statusCallback:s()}).pipe(W(m=>p?Nr(m,m.get("assemblyName")===c.assemblyName?c:{start:m.get("start"),end:m.get("end")},i,a):[m]),be(),V(m=>({index:u,features:m})))),be(),W(c=>c.sort((u,m)=>u.index-m.index).flatMap(u=>u.features)))}};var De=class extends Error{constructor(t){super(`a pair query names both lanes: queryAssemblyName ${t} came without a targetAssemblyName`);this.name="PairTargetError"}};function Xi(e){let{lanePairs:r,queryAssemblyName:t,targetAssemblyName:o}=e;if(r?.length)return r;if(t===void 0)return[];if(o===void 0)throw new De(t);return[{queryAssemblyName:t,targetAssemblyName:o}]}function Zi(e){let[r]=e;return e.length===1&&r?`Reading ${r.queryAssemblyName} against ${r.targetAssemblyName}`:`Reading ${e.length} lane pairs`}function Ji(e,r){return e[r]??e[He(r)]??r}function mt(e,r){let t=Math.max(1,r);return e>=10*t?Math.ceil(e/t):Math.max(11,Math.ceil(10*e/t))/10}function ta(e,r){if(Ve(e)&&e instanceof Error){let{fitsBp:t}=e;e.message=e.message.replace("to see the graph","to see lanes"),typeof t=="number"&&(e.message=e.message.replace(/^Zoom in to about [\d.,]*\d[KM]?bp/,`Zoom in about ${mt(r,t)}\xD7`))}return e}function ia({target:e,query:r,strand:t,cigar:o,matches:n,columns:i}){let a=`${e.name}:${e.start}-${e.end}|${r.name}:${r.start}-${r.end}`;return new N({uniqueId:a,assemblyName:e.assemblyName,refName:e.refName,start:e.start,end:e.end,type:"match",strand:t==="-"?-1:1,CIGAR:o,syntenyId:a,identity:n/Math.max(i,1),numMatches:n,blockLen:i,mate:{refName:r.refName,start:r.start,end:r.end,assemblyName:r.assemblyName}})}export{N as a,Pr as b,De as c,Xi as d,Zi as e,Ji as f,ta as g,ia as h};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-B7MGDESF.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
function o(t){return t===void 0||t==="*"?void 0:t}function s(t){let e=t.split(" ");return{refName:e[0],start:+e[1],end:+e[2],segmentCount:+e[3],pathCount:+e[4],inversion:e[5]==="1",shortestAlleleLength:+e[6],longestAlleleLength:+e[7],segments:e[11],shortestAllele:o(e[12]),longestAllele:o(e[13])}}function u(t,e){return t.key!==void 0||e.key!==void 0?t.key===e.key:t.refName===e.refName&&t.start===e.start&&t.end===e.end}function i(t){return t.key??`${t.refName}:${t.start}-${t.end}`}function b(t){let{shortestAlleleLength:e,longestAlleleLength:n}=t;return e===n?`${n.toLocaleString()} bp`:`${e.toLocaleString()}-${n.toLocaleString()} bp`}var r=2147483647;function a(t){let{pathCount:e,segmentCount:n,inversion:l}=t;return[`${n} segments`,e===r?"more paths than gfatools counts":`up to ${e.toLocaleString()} paths`,...l?["inversion"]:[]].join(", ")}export{s as a,u as b,i as c,b as d,r as e,a as f};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-BJHWGRMP.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.1.1/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-FX4RDMDN.js"],
|
|
4
4
|
"sourcesContent": ["// src/bubbles/bubbleLine.ts\nfunction sequence(field) {\n return field === void 0 || field === \"*\" ? void 0 : field;\n}\nfunction parseBubbleLine(line) {\n const cols = line.split(\"\t\");\n return {\n refName: cols[0],\n start: +cols[1],\n end: +cols[2],\n segmentCount: +cols[3],\n pathCount: +cols[4],\n inversion: cols[5] === \"1\",\n shortestAlleleLength: +cols[6],\n longestAlleleLength: +cols[7],\n segments: cols[11],\n shortestAllele: sequence(cols[12]),\n longestAllele: sequence(cols[13])\n };\n}\nfunction sameBubble(a, b) {\n return a.key !== void 0 || b.key !== void 0 ? a.key === b.key : a.refName === b.refName && a.start === b.start && a.end === b.end;\n}\nfunction bubbleKey(b) {\n return b.key ?? `${b.refName}:${b.start}-${b.end}`;\n}\nfunction bubbleLabel(bubble) {\n const { shortestAlleleLength: min, longestAlleleLength: max } = bubble;\n return min === max ? `${max.toLocaleString()} bp` : `${min.toLocaleString()}-${max.toLocaleString()} bp`;\n}\nvar SATURATED_PATH_COUNT = 2147483647;\nfunction bubbleDescription(bubble) {\n const { pathCount, segmentCount, inversion } = bubble;\n return [\n `${segmentCount} segments`,\n pathCount === SATURATED_PATH_COUNT ? \"more paths than gfatools counts\" : `up to ${pathCount.toLocaleString()} paths`,\n ...inversion ? [\"inversion\"] : []\n ].join(\", \");\n}\n\nexport {\n parseBubbleLine,\n sameBubble,\n bubbleKey,\n bubbleLabel,\n SATURATED_PATH_COUNT,\n bubbleDescription\n};\n"],
|
|
5
5
|
"mappings": "AACA,SAASA,EAASC,EAAO,CACvB,OAAOA,IAAU,QAAUA,IAAU,IAAM,OAASA,CACtD,CACA,SAASC,EAAgBC,EAAM,CAC7B,IAAMC,EAAOD,EAAK,MAAM,GAAG,EAC3B,MAAO,CACL,QAASC,EAAK,CAAC,EACf,MAAO,CAACA,EAAK,CAAC,EACd,IAAK,CAACA,EAAK,CAAC,EACZ,aAAc,CAACA,EAAK,CAAC,EACrB,UAAW,CAACA,EAAK,CAAC,EAClB,UAAWA,EAAK,CAAC,IAAM,IACvB,qBAAsB,CAACA,EAAK,CAAC,EAC7B,oBAAqB,CAACA,EAAK,CAAC,EAC5B,SAAUA,EAAK,EAAE,EACjB,eAAgBJ,EAASI,EAAK,EAAE,CAAC,EACjC,cAAeJ,EAASI,EAAK,EAAE,CAAC,CAClC,CACF,CACA,SAASC,EAAWC,EAAGC,EAAG,CACxB,OAAOD,EAAE,MAAQ,QAAUC,EAAE,MAAQ,OAASD,EAAE,MAAQC,EAAE,IAAMD,EAAE,UAAYC,EAAE,SAAWD,EAAE,QAAUC,EAAE,OAASD,EAAE,MAAQC,EAAE,GAChI,CACA,SAASC,EAAUD,EAAG,CACpB,OAAOA,EAAE,KAAO,GAAGA,EAAE,OAAO,IAAIA,EAAE,KAAK,IAAIA,EAAE,GAAG,EAClD,CACA,SAASE,EAAYC,EAAQ,CAC3B,GAAM,CAAE,qBAAsBC,EAAK,oBAAqBC,CAAI,EAAIF,EAChE,OAAOC,IAAQC,EAAM,GAAGA,EAAI,eAAe,CAAC,MAAQ,GAAGD,EAAI,eAAe,CAAC,IAAIC,EAAI,eAAe,CAAC,KACrG,CACA,IAAIC,EAAuB,WAC3B,SAASC,EAAkBJ,EAAQ,CACjC,GAAM,CAAE,UAAAK,EAAW,aAAAC,EAAc,UAAAC,CAAU,EAAIP,EAC/C,MAAO,CACL,GAAGM,CAAY,YACfD,IAAcF,EAAuB,kCAAoC,SAASE,EAAU,eAAe,CAAC,SAC5G,GAAGE,EAAY,CAAC,WAAW,EAAI,CAAC,CAClC,EAAE,KAAK,IAAI,CACb",
|
|
6
6
|
"names": ["sequence", "field", "parseBubbleLine", "line", "cols", "sameBubble", "a", "b", "bubbleKey", "bubbleLabel", "bubble", "min", "max", "SATURATED_PATH_COUNT", "bubbleDescription", "pathCount", "segmentCount", "inversion"]
|
|
@@ -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-FY7X6253.js";import{c as Ot}from"./chunk-JMRW3IGK.js";import{a as Ct,g as Bt}from"./chunk-5RHNR3TH.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-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}
|
|
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-CNCYMJ5E.js.map
|