jbrowse-plugin-graphgenomeviewer 6.11.0 → 6.13.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.
Files changed (62) hide show
  1. package/dist/chunks/{GbzBaseSyntenyAdapter-SPT62NR4.js → GbzBaseSyntenyAdapter-SFTZXPG5.js} +2 -2
  2. package/dist/chunks/{GraphGenomeView-BSJYTSFN.js → GraphGenomeView-D3TBUFNW.js} +2 -2
  3. package/dist/chunks/{LinearGraphDisplay-VW7DGOVT.js → LinearGraphDisplay-YKGK4KBD.js} +2 -2
  4. package/dist/chunks/RgfaTabixAdapter-2PJS7QDO.js +3 -0
  5. package/dist/chunks/RgfaTabixAdapter-2PJS7QDO.js.map +7 -0
  6. package/dist/chunks/WalkTabixSyntenyAdapter-Q5Q5XS4C.js +2 -0
  7. package/dist/chunks/WalkTabixSyntenyAdapter-Q5Q5XS4C.js.map +7 -0
  8. package/dist/chunks/{chunk-MDRNFKXW.js → chunk-5DRS22TL.js} +3 -3
  9. package/dist/chunks/{chunk-MDRNFKXW.js.map → chunk-5DRS22TL.js.map} +2 -2
  10. package/dist/chunks/chunk-BXFEZVDW.js +3 -0
  11. package/dist/chunks/chunk-BXFEZVDW.js.map +7 -0
  12. package/dist/chunks/{chunk-6AYSOQOK.js → chunk-KIXOGZKJ.js} +2 -2
  13. package/dist/chunks/chunk-MIY4JCDL.js +2 -0
  14. package/dist/chunks/{chunk-DOLO4I5J.js.map → chunk-MIY4JCDL.js.map} +1 -1
  15. package/dist/chunks/chunk-P6FDUP52.js +2 -0
  16. package/dist/chunks/chunk-P6FDUP52.js.map +7 -0
  17. package/dist/chunks/{chunk-KROCIQJP.js → chunk-SYETHCAR.js} +5 -5
  18. package/dist/chunks/{chunk-KROCIQJP.js.map → chunk-SYETHCAR.js.map} +1 -1
  19. package/dist/chunks/chunk-WSZ6RCMI.js +2 -0
  20. package/dist/chunks/{chunk-TVXMEJLJ.js.map → chunk-WSZ6RCMI.js.map} +3 -3
  21. package/dist/chunks/renderSvg-4F2JULKR.js +2 -0
  22. package/dist/chunks/{renderSvg-QXWTNVPN.js.map → renderSvg-4F2JULKR.js.map} +2 -2
  23. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
  24. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  25. package/package.json +2 -2
  26. package/src/GetSubgraph.ts +7 -4
  27. package/src/GraphGenomeView/components/PaneSvg.tsx +1 -1
  28. package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +156 -51
  29. package/src/GraphGenomeView/model.test.ts +103 -0
  30. package/src/GraphGenomeView/pane/graphViews.ts +26 -3
  31. package/src/GraphGenomeView/pane/loadActions.ts +62 -12
  32. package/src/GraphGenomeView/pane/paneBase.ts +4 -0
  33. package/src/GraphGenomeView/viewModel.ts +7 -1
  34. package/src/GraphGenomeView/walkRowSpans.test.ts +123 -0
  35. package/src/GraphGenomeView/walkRowSpans.ts +243 -0
  36. package/src/GraphGenomeView/walkRowsCut.ts +93 -0
  37. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +2 -0
  38. package/src/LinearGraphDisplay/model.ts +3 -1
  39. package/src/RgfaTabixAdapter/RgfaTabixAdapter.ts +5 -4
  40. package/src/RgfaTabixAdapter/configSchema.ts +5 -3
  41. package/src/RgfaTabixAdapter/walkReader.ts +22 -4
  42. package/src/RgfaTabixAdapter/walkRowRuns.test.ts +63 -0
  43. package/src/RgfaTabixAdapter/walkRowRuns.ts +416 -0
  44. package/src/RgfaTabixAdapter/walkRows.ts +22 -0
  45. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.test.ts +100 -1
  46. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts +8 -7
  47. package/src/WalkTabixSyntenyAdapter/configSchema.ts +4 -3
  48. package/src/WalkTabixSyntenyAdapter/walkLanes.ts +83 -1
  49. package/src/version.ts +1 -1
  50. package/dist/chunks/RgfaTabixAdapter-5ZRSJMIP.js +0 -3
  51. package/dist/chunks/RgfaTabixAdapter-5ZRSJMIP.js.map +0 -7
  52. package/dist/chunks/WalkTabixSyntenyAdapter-2KJTYCX3.js +0 -2
  53. package/dist/chunks/WalkTabixSyntenyAdapter-2KJTYCX3.js.map +0 -7
  54. package/dist/chunks/chunk-DOLO4I5J.js +0 -2
  55. package/dist/chunks/chunk-TVXMEJLJ.js +0 -2
  56. package/dist/chunks/chunk-UQT5WHCD.js +0 -3
  57. package/dist/chunks/chunk-UQT5WHCD.js.map +0 -7
  58. package/dist/chunks/renderSvg-QXWTNVPN.js +0 -2
  59. /package/dist/chunks/{GbzBaseSyntenyAdapter-SPT62NR4.js.map → GbzBaseSyntenyAdapter-SFTZXPG5.js.map} +0 -0
  60. /package/dist/chunks/{GraphGenomeView-BSJYTSFN.js.map → GraphGenomeView-D3TBUFNW.js.map} +0 -0
  61. /package/dist/chunks/{LinearGraphDisplay-VW7DGOVT.js.map → LinearGraphDisplay-YKGK4KBD.js.map} +0 -0
  62. /package/dist/chunks/{chunk-6AYSOQOK.js.map → chunk-KIXOGZKJ.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- import{b as J,c as K,d as q,e as ne,f as me,g as ae}from"./chunk-KROCIQJP.js";import{b as G,c as V,d as ee,e as te}from"./chunk-X4NNWAXW.js";import{a as O,b as H}from"./chunk-NU53CDGF.js";import{f as le,g as Z,h,i as B,j as z,k as R,l as M,m as k,o as E}from"./chunk-R4DSKZ5P.js";import"./chunk-PR5YUSXN.js";import{a as P}from"./chunk-OGQ6OQDN.js";import"./chunk-YBLNN5FU.js";import{e as F,f as S,g as C}from"./chunk-XKN5LH2Z.js";import"./chunk-E7J6SB5P.js";import{b as U,c as X,d as Y}from"./chunk-R3TRNF7N.js";import"./chunk-7WIBGKBU.js";import{e as W,o as $}from"./chunk-TENPGIPX.js";function A(n){let i=/\.gbz\.db$/i;return i.test(n)?n.replace(i,".haplotype-index.db"):void 0}function de(n){return X(n)&&A(U(n))?Y(n,i=>A(i)):void 0}function fe(n){return n instanceof Error&&(/\bHTTP 40[34]\b/.test(n.message)||n.code==="ENOENT")}async function re(n,i){let t=de(n);if(!t)return{};try{return await P(t,i).stat(),{location:t}}catch(e){return fe(e)?{}:{unreadable:String(e)}}}var he=5e3,ue=50*2**20,T=class extends Error{constructor(t){super(`this GAF is ${(t/2**20).toFixed(0)} MB without an index; bgzip it and index it with tabix -p gaf`);this.name="UnindexedGafTooLargeError"}};function ge(n,i){if(n.length<=i)return n;let t=n.length/i;return Array.from({length:i},(e,a)=>n[Math.floor(a*t)])}var oe=(n,i)=>n.path.some(t=>i.has(t.name)),I=class{constructor(i,t){this.file=i;this.tabix=t;this.whole=G({setup:async({signal:i})=>{let{size:t}=await this.file.stat();if(t>ue)throw new T(t);let e=await this.file.readFile({signal:i}),a=new TextDecoder().decode(e[0]===31&&e[1]===139?await ee(e):e);return H(a)}})}async readIndexed(i,t,e){let a=1/0,r=-1/0;for(let c of t){let s=Number(c);Number.isInteger(s)&&(a=Math.min(a,s),r=Math.max(r,s))}let o=[];return a<=r&&await i.getLines("{node}",a,r+1,{signal:e,lineCallback:c=>{let s=O(c);s&&oe(s,t)&&o.push(s)}}),o}async readsOver(i,{signal:t}={}){let e=this.tabix?await this.readIndexed(this.tabix,i,t):(await this.whole({signal:t})).filter(a=>oe(a,i));return{records:ge(e,he),total:e.length}}};var v=class extends Error{constructor(t){super(t===void 0?"no haplotype index is set, so the walks cannot be named; build one with gbz-haplotype-index (cargo install gbz-haplotype-index) and set it as haplotypeIndexLocation":`the haplotype index beside the graph database could not be checked (${t}), so the walks cannot be named; if it is there, reload to try again, or set haplotypeIndexLocation`);this.name="NoHaplotypeIndexError"}},D=class extends Error{constructor(t,e){super(`the graph is cut on its reference, ${e}; a window on ${t} has no reference coordinates to cut at. Open the graph from a ${e} view, and find this haplotype's lane there`);this.name="HaplotypeWindowError"}};function se(n,i){let t=h(i);return n[t]??n[i.sample]??t}function ye(n,i){return`${h(n)}#${n.contig}@${i.start.node}.${i.start.offset}`}function be({alignment:n,assemblyName:i,refName:t,lane:e}){let{refStart:a,refEnd:r,strand:o,cigar:c}=n;if(!(!n.resolved||r<=a)){let{name:s,hapStart:p,hapEnd:m}=n,u=ye(s,n),g={uniqueId:u,assemblyName:i,refName:t,start:a,end:r,type:"match",strand:o==="-"?-1:1,CIGAR:c,syntenyId:u,mate:{refName:s.contig,start:p,end:m,assemblyName:e}};return new q(g)}}function xe({pair:n,lane:i,mateLane:t}){let e=`${h(n.target)}#${n.target.contig}:${n.targetStart}-${n.targetEnd}|${h(n.query)}#${n.query.contig}:${n.queryStart}-${n.queryEnd}`;return new q({uniqueId:e,assemblyName:i,refName:n.target.contig,start:n.targetStart,end:n.targetEnd,type:"match",strand:n.strand==="-"?-1:1,CIGAR:n.cigar,syntenyId:e,identity:n.matches/Math.max(n.columns,1),numMatches:n.matches,blockLen:n.columns,mate:{refName:n.query.contig,start:n.queryStart,end:n.queryEnd,assemblyName:t}})}var we=12e4;function Se(n,i){let t=new Map;for(let a of n)for(let{name:r,start:o,end:c}of a.walkSpans()){let s=h(r);if(i.has(s)){let p=`${s}#${r.contig}`;t.set(p,[...t.get(p)??[],[o,c]])}}let e=0;for(let a of t.values()){a.sort((r,o)=>r[0]-o[0]);for(let r=1;r<a.length;r++){let o=a[r][0]-a[r-1][1];o>0&&o<=we&&(e=Math.max(e,o))}}return e}function _(n,i){return n instanceof Z&&(n.message=`Zoom in to about ${W(n.fitsBp)} to see ${i}`),n}var Q=n=>!("uri"in n)||n.uri!=="",j=class extends ne{constructor(){super(...arguments);this.graph=G({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),e=this.getConf("haplotypeIndexLocation"),a=Q(e)?{location:e}:await re(t,this.pluginManager),r=a.location,o=await K.open({source:P(t,this.pluginManager),haplotypeIndex:r?P(r,this.pluginManager):void 0}),c=this.getConf("assemblyNames")[0];if(c===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let s=await z(o),p=R({configured:this.getConf("referenceSample"),anchorPrefix:S(this,c),referenceSamples:s});return{db:o,anchor:c,referenceSample:p,referenceSamples:s,unreadableIndex:a.unreadable}}});this.gaf=G({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),e=this.getConf(["readsIndex","location"]);return Q(t)?new I(P(t,this.pluginManager),Q(e)?te(this,["readsLocation"],["readsIndex"]):void 0):void 0}})}async referenceQuery(t,e){let{db:a,referenceSample:r}=await this.graph(e);return M(a,r,t)}async getHaplotypes(t={}){let{db:e,referenceSamples:a}=await this.graph(t),r=new Map;for(let o of await e.paths()){let c=h(o.name),s=r.get(c);s?s.contigs.includes(o.name.contig)||s.contigs.push(o.name.contig):r.set(c,{prefix:c,sample:o.name.sample,haplotype:o.name.haplotype,contigs:[o.name.contig],isReference:a.includes(o.name.sample)})}return[...r.values()]}async getHeader(t={}){let{anchor:e,referenceSample:a,referenceSamples:r}=await this.graph(t),o=C(this),c=[];for(let s of await this.getHaplotypes(t))s.sample!==a&&c.push({name:se(o,s),label:s.prefix,group:s.sample});return{hasCoarseTier:!1,anchorAssemblyName:e,referenceSample:a,referenceSamples:r,lanes:c}}async getRefNames(t={}){let{db:e,anchor:a,referenceSample:r}=await this.graph(t),{assemblyName:o}=t,c=o===a?void 0:S(this,o),s=(await e.paths()).filter(p=>o===a?p.isIndexed&&p.name.sample===r:F(h(p.name),c)).map(p=>p.name.contig);return[...new Set(s)]}keepPredicate(t,e){let a=t===void 0||t.length===0?void 0:t.map(r=>S(this,r));return a===void 0&&e===void 0?void 0:r=>B(r,a)&&(e===void 0||F(h(r),e))}async getSubgraph(t,e={}){let{signal:a}=e,{db:r,anchor:o,referenceSample:c,unreadableIndex:s}=await this.graph({signal:a}),{assemblyName:p,refName:m,start:u,end:g}=t;if(p!==o)throw new D(p,o);let y=await this.referenceQuery(m,{signal:a});if(!y)throw new Error(`${c} has no indexed path ${m} in this graph`);let x=this.keepPredicate(e.haplotypes);if(x!==void 0&&!r.hasHaplotypeIndex)throw new v(s);return E(r,y,u,g,{context:this.getConf("context"),snarls:e.snarls??this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:e.signal,keep:x}).catch(d=>{throw _(d,"the graph")})}async getReads(t,e={}){let a=await this.gaf(e);return a?a.readsOver(new Set(t),e):{records:[],total:0}}async laneHaplotypes(t,e){let a=S(this,t);return(await this.getHaplotypes(e)).filter(r=>F(r.prefix,a))}async anchorFeatures(t,e){let{db:a}=await this.graph(e),{assemblyName:r,refName:o,start:c,end:s}=t,p=S(this,e.targetAssemblyName),m=C(this),u=this.keepPredicate(e.haplotypes,p),g=await this.referenceQuery(o,e),y=this.getConf("nodeLimit");return(g?await $(`Reading graph ${o}:${c.toLocaleString()}-${s.toLocaleString()}`,e.statusCallback,()=>a.getAlignments({path:g,start:c,end:s,context:this.getConf("context"),haplotypes:"all",limit:y,signal:e.signal,keep:u}).catch(d=>{throw _(k(d,y,s-c)??d,"lanes")})):[]).flatMap(d=>{let N=d.resolved?be({alignment:d,assemblyName:r,refName:o,lane:se(m,d.name)}):void 0;return N===void 0?[]:[N]})}async pairFeatures(t,e,a){let{db:r}=await this.graph(a),{refName:o,start:c,end:s}=t,m=(await Promise.all(e.map(async l=>({pair:l,featureSide:await this.laneHaplotypes(l.queryAssemblyName,a),mateSide:await this.laneHaplotypes(l.targetAssemblyName,a)})))).filter(({featureSide:l,mateSide:f})=>l.length>0&&f.length>0),u=new Set(m.flatMap(({featureSide:l,mateSide:f})=>[...l,...f].map(h))),g=await this.referenceQuery(o,a),y=this.getConf("nodeLimit"),x=this.getConf("context"),[d]=e,N=(l,f)=>r.getSubgraphs({path:l,start:c,end:s,context:f,snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:y,signal:a.signal,keep:w=>u.has(h(w))}),ie=async l=>{let f=await N(l,x).catch(b=>{throw _(k(b,y,s-c)??b,"lanes")}),w=Se(f,u),L=Math.ceil(w/2)+2e3;return w>0&&L>x?N(l,L).catch(b=>{if(b instanceof J)return f;throw b}):f};return(g&&d&&m.length>0?await $(e.length===1?`Reading ${d.queryAssemblyName} against ${d.targetAssemblyName}`:`Reading ${e.length} lane pairs`,a.statusCallback,()=>ie(g)):[]).flatMap(l=>m.flatMap(({pair:f,featureSide:w,mateSide:L})=>w.flatMap(b=>L.flatMap(ce=>l.pairAlignments({target:b,query:ce,bases:!1}).map(pe=>xe({pair:pe,lane:f.queryAssemblyName,mateLane:f.targetAssemblyName}))))))}getFeatures(t,e={}){return V(async a=>{let{db:r,anchor:o,unreadableIndex:c}=await this.graph(e);if(!r.hasHaplotypeIndex)throw new v(c);if(t.assemblyName===o){let s=ae(e),p=s.length>0?await this.pairFeatures(t,s,e):await this.anchorFeatures(t,e);for(let m of p)a.next(m)}a.complete()},e.signal)}};export{D as HaplotypeWindowError,v as NoHaplotypeIndexError,le as NoReferenceSampleError,me as PairTargetError,j as default,be as fragmentFeature,se as laneAssemblyName,xe as pairFeature,R as resolveReferenceSample,Se as widestWalkGap};
2
- //# sourceMappingURL=GbzBaseSyntenyAdapter-SPT62NR4.js.map
1
+ import{c as J,d as K,e as q,f as ne,g as me,h as ae}from"./chunk-SYETHCAR.js";import{b as G,c as V,d as ee,e as te}from"./chunk-X4NNWAXW.js";import{a as O,b as H}from"./chunk-NU53CDGF.js";import{f as le,g as Z,h,i as B,j as z,k as R,l as M,m as k,o as E}from"./chunk-R4DSKZ5P.js";import"./chunk-PR5YUSXN.js";import{a as P}from"./chunk-OGQ6OQDN.js";import"./chunk-YBLNN5FU.js";import{e as F,f as S,g as C}from"./chunk-XKN5LH2Z.js";import"./chunk-E7J6SB5P.js";import{b as U,c as X,d as Y}from"./chunk-R3TRNF7N.js";import"./chunk-7WIBGKBU.js";import{e as W,o as $}from"./chunk-TENPGIPX.js";function A(n){let i=/\.gbz\.db$/i;return i.test(n)?n.replace(i,".haplotype-index.db"):void 0}function de(n){return X(n)&&A(U(n))?Y(n,i=>A(i)):void 0}function fe(n){return n instanceof Error&&(/\bHTTP 40[34]\b/.test(n.message)||n.code==="ENOENT")}async function re(n,i){let t=de(n);if(!t)return{};try{return await P(t,i).stat(),{location:t}}catch(e){return fe(e)?{}:{unreadable:String(e)}}}var he=5e3,ue=50*2**20,T=class extends Error{constructor(t){super(`this GAF is ${(t/2**20).toFixed(0)} MB without an index; bgzip it and index it with tabix -p gaf`);this.name="UnindexedGafTooLargeError"}};function ge(n,i){if(n.length<=i)return n;let t=n.length/i;return Array.from({length:i},(e,a)=>n[Math.floor(a*t)])}var oe=(n,i)=>n.path.some(t=>i.has(t.name)),I=class{constructor(i,t){this.file=i;this.tabix=t;this.whole=G({setup:async({signal:i})=>{let{size:t}=await this.file.stat();if(t>ue)throw new T(t);let e=await this.file.readFile({signal:i}),a=new TextDecoder().decode(e[0]===31&&e[1]===139?await ee(e):e);return H(a)}})}async readIndexed(i,t,e){let a=1/0,r=-1/0;for(let c of t){let s=Number(c);Number.isInteger(s)&&(a=Math.min(a,s),r=Math.max(r,s))}let o=[];return a<=r&&await i.getLines("{node}",a,r+1,{signal:e,lineCallback:c=>{let s=O(c);s&&oe(s,t)&&o.push(s)}}),o}async readsOver(i,{signal:t}={}){let e=this.tabix?await this.readIndexed(this.tabix,i,t):(await this.whole({signal:t})).filter(a=>oe(a,i));return{records:ge(e,he),total:e.length}}};var v=class extends Error{constructor(t){super(t===void 0?"no haplotype index is set, so the walks cannot be named; build one with gbz-haplotype-index (cargo install gbz-haplotype-index) and set it as haplotypeIndexLocation":`the haplotype index beside the graph database could not be checked (${t}), so the walks cannot be named; if it is there, reload to try again, or set haplotypeIndexLocation`);this.name="NoHaplotypeIndexError"}},D=class extends Error{constructor(t,e){super(`the graph is cut on its reference, ${e}; a window on ${t} has no reference coordinates to cut at. Open the graph from a ${e} view, and find this haplotype's lane there`);this.name="HaplotypeWindowError"}};function se(n,i){let t=h(i);return n[t]??n[i.sample]??t}function ye(n,i){return`${h(n)}#${n.contig}@${i.start.node}.${i.start.offset}`}function be({alignment:n,assemblyName:i,refName:t,lane:e}){let{refStart:a,refEnd:r,strand:o,cigar:c}=n;if(!(!n.resolved||r<=a)){let{name:s,hapStart:p,hapEnd:m}=n,u=ye(s,n),g={uniqueId:u,assemblyName:i,refName:t,start:a,end:r,type:"match",strand:o==="-"?-1:1,CIGAR:c,syntenyId:u,mate:{refName:s.contig,start:p,end:m,assemblyName:e}};return new q(g)}}function xe({pair:n,lane:i,mateLane:t}){let e=`${h(n.target)}#${n.target.contig}:${n.targetStart}-${n.targetEnd}|${h(n.query)}#${n.query.contig}:${n.queryStart}-${n.queryEnd}`;return new q({uniqueId:e,assemblyName:i,refName:n.target.contig,start:n.targetStart,end:n.targetEnd,type:"match",strand:n.strand==="-"?-1:1,CIGAR:n.cigar,syntenyId:e,identity:n.matches/Math.max(n.columns,1),numMatches:n.matches,blockLen:n.columns,mate:{refName:n.query.contig,start:n.queryStart,end:n.queryEnd,assemblyName:t}})}var we=12e4;function Se(n,i){let t=new Map;for(let a of n)for(let{name:r,start:o,end:c}of a.walkSpans()){let s=h(r);if(i.has(s)){let p=`${s}#${r.contig}`;t.set(p,[...t.get(p)??[],[o,c]])}}let e=0;for(let a of t.values()){a.sort((r,o)=>r[0]-o[0]);for(let r=1;r<a.length;r++){let o=a[r][0]-a[r-1][1];o>0&&o<=we&&(e=Math.max(e,o))}}return e}function _(n,i){return n instanceof Z&&(n.message=`Zoom in to about ${W(n.fitsBp)} to see ${i}`),n}var Q=n=>!("uri"in n)||n.uri!=="",j=class extends ne{constructor(){super(...arguments);this.graph=G({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),e=this.getConf("haplotypeIndexLocation"),a=Q(e)?{location:e}:await re(t,this.pluginManager),r=a.location,o=await K.open({source:P(t,this.pluginManager),haplotypeIndex:r?P(r,this.pluginManager):void 0}),c=this.getConf("assemblyNames")[0];if(c===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let s=await z(o),p=R({configured:this.getConf("referenceSample"),anchorPrefix:S(this,c),referenceSamples:s});return{db:o,anchor:c,referenceSample:p,referenceSamples:s,unreadableIndex:a.unreadable}}});this.gaf=G({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),e=this.getConf(["readsIndex","location"]);return Q(t)?new I(P(t,this.pluginManager),Q(e)?te(this,["readsLocation"],["readsIndex"]):void 0):void 0}})}async referenceQuery(t,e){let{db:a,referenceSample:r}=await this.graph(e);return M(a,r,t)}async getHaplotypes(t={}){let{db:e,referenceSamples:a}=await this.graph(t),r=new Map;for(let o of await e.paths()){let c=h(o.name),s=r.get(c);s?s.contigs.includes(o.name.contig)||s.contigs.push(o.name.contig):r.set(c,{prefix:c,sample:o.name.sample,haplotype:o.name.haplotype,contigs:[o.name.contig],isReference:a.includes(o.name.sample)})}return[...r.values()]}async getHeader(t={}){let{anchor:e,referenceSample:a,referenceSamples:r}=await this.graph(t),o=C(this),c=[];for(let s of await this.getHaplotypes(t))s.sample!==a&&c.push({name:se(o,s),label:s.prefix,group:s.sample});return{hasCoarseTier:!1,anchorAssemblyName:e,referenceSample:a,referenceSamples:r,lanes:c}}async getRefNames(t={}){let{db:e,anchor:a,referenceSample:r}=await this.graph(t),{assemblyName:o}=t,c=o===a?void 0:S(this,o),s=(await e.paths()).filter(p=>o===a?p.isIndexed&&p.name.sample===r:F(h(p.name),c)).map(p=>p.name.contig);return[...new Set(s)]}keepPredicate(t,e){let a=t===void 0||t.length===0?void 0:t.map(r=>S(this,r));return a===void 0&&e===void 0?void 0:r=>B(r,a)&&(e===void 0||F(h(r),e))}async getSubgraph(t,e={}){let{signal:a}=e,{db:r,anchor:o,referenceSample:c,unreadableIndex:s}=await this.graph({signal:a}),{assemblyName:p,refName:m,start:u,end:g}=t;if(p!==o)throw new D(p,o);let y=await this.referenceQuery(m,{signal:a});if(!y)throw new Error(`${c} has no indexed path ${m} in this graph`);let x=this.keepPredicate(e.haplotypes);if(x!==void 0&&!r.hasHaplotypeIndex)throw new v(s);return E(r,y,u,g,{context:this.getConf("context"),snarls:e.snarls??this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:e.signal,keep:x}).catch(d=>{throw _(d,"the graph")})}async getReads(t,e={}){let a=await this.gaf(e);return a?a.readsOver(new Set(t),e):{records:[],total:0}}async laneHaplotypes(t,e){let a=S(this,t);return(await this.getHaplotypes(e)).filter(r=>F(r.prefix,a))}async anchorFeatures(t,e){let{db:a}=await this.graph(e),{assemblyName:r,refName:o,start:c,end:s}=t,p=S(this,e.targetAssemblyName),m=C(this),u=this.keepPredicate(e.haplotypes,p),g=await this.referenceQuery(o,e),y=this.getConf("nodeLimit");return(g?await $(`Reading graph ${o}:${c.toLocaleString()}-${s.toLocaleString()}`,e.statusCallback,()=>a.getAlignments({path:g,start:c,end:s,context:this.getConf("context"),haplotypes:"all",limit:y,signal:e.signal,keep:u}).catch(d=>{throw _(k(d,y,s-c)??d,"lanes")})):[]).flatMap(d=>{let N=d.resolved?be({alignment:d,assemblyName:r,refName:o,lane:se(m,d.name)}):void 0;return N===void 0?[]:[N]})}async pairFeatures(t,e,a){let{db:r}=await this.graph(a),{refName:o,start:c,end:s}=t,m=(await Promise.all(e.map(async l=>({pair:l,featureSide:await this.laneHaplotypes(l.queryAssemblyName,a),mateSide:await this.laneHaplotypes(l.targetAssemblyName,a)})))).filter(({featureSide:l,mateSide:f})=>l.length>0&&f.length>0),u=new Set(m.flatMap(({featureSide:l,mateSide:f})=>[...l,...f].map(h))),g=await this.referenceQuery(o,a),y=this.getConf("nodeLimit"),x=this.getConf("context"),[d]=e,N=(l,f)=>r.getSubgraphs({path:l,start:c,end:s,context:f,snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:y,signal:a.signal,keep:w=>u.has(h(w))}),ie=async l=>{let f=await N(l,x).catch(b=>{throw _(k(b,y,s-c)??b,"lanes")}),w=Se(f,u),L=Math.ceil(w/2)+2e3;return w>0&&L>x?N(l,L).catch(b=>{if(b instanceof J)return f;throw b}):f};return(g&&d&&m.length>0?await $(e.length===1?`Reading ${d.queryAssemblyName} against ${d.targetAssemblyName}`:`Reading ${e.length} lane pairs`,a.statusCallback,()=>ie(g)):[]).flatMap(l=>m.flatMap(({pair:f,featureSide:w,mateSide:L})=>w.flatMap(b=>L.flatMap(ce=>l.pairAlignments({target:b,query:ce,bases:!1}).map(pe=>xe({pair:pe,lane:f.queryAssemblyName,mateLane:f.targetAssemblyName}))))))}getFeatures(t,e={}){return V(async a=>{let{db:r,anchor:o,unreadableIndex:c}=await this.graph(e);if(!r.hasHaplotypeIndex)throw new v(c);if(t.assemblyName===o){let s=ae(e),p=s.length>0?await this.pairFeatures(t,s,e):await this.anchorFeatures(t,e);for(let m of p)a.next(m)}a.complete()},e.signal)}};export{D as HaplotypeWindowError,v as NoHaplotypeIndexError,le as NoReferenceSampleError,me as PairTargetError,j as default,be as fragmentFeature,se as laneAssemblyName,xe as pairFeature,R as resolveReferenceSample,Se as widestWalkGap};
2
+ //# sourceMappingURL=GbzBaseSyntenyAdapter-SFTZXPG5.js.map
@@ -1,4 +1,4 @@
1
- import{a as C}from"./chunk-DOLO4I5J.js";import"./chunk-I574RVHG.js";import"./chunk-UQT5WHCD.js";import"./chunk-MDRNFKXW.js";import{p as d}from"./chunk-LEWWQ7ZK.js";import"./chunk-6AYSOQOK.js";import"./chunk-BXZLLHYP.js";import"./chunk-AB2XVNNS.js";import"./chunk-FSCO2SM4.js";import"./chunk-NU53CDGF.js";import"./chunk-PR5YUSXN.js";import"./chunk-YBLNN5FU.js";import"./chunk-XKN5LH2Z.js";import"./chunk-ELLLNUKS.js";import"./chunk-TENPGIPX.js";import{g as x}from"./chunk-6OPB7FOJ.js";import{E as L,G as p,d as s,h as v,n,w as G,z as l}from"./chunk-ECD5B2ZM.js";import{a as y,b as a,c as r,d as i}from"./chunk-JMBDTNUR.js";var w=d()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),E=i(function({model:e}){let{classes:t}=w();return e.isLoading?r(l,{className:t.paper,"data-testid":"graph-genome-loading",children:[r("div",{className:t.row,children:[a(v,{variant:"h6",message:e.statusMessage}),a(n,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),a(G,{variant:"indeterminate"})]}):e.error?a(l,{className:t.paper,children:a(s,{error:e.error,onReset:()=>{e.retryLoad()}})}):a(l,{className:t.paper,"data-testid":"graph-genome-load-canceled",children:r("div",{className:t.row,children:[a(p,{variant:"h6",children:"Loading canceled"}),a(n,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),g=E;var F=`H VN:Z:1.0
1
+ import{a as C}from"./chunk-MIY4JCDL.js";import"./chunk-I574RVHG.js";import"./chunk-BXFEZVDW.js";import"./chunk-5DRS22TL.js";import{p as d}from"./chunk-LEWWQ7ZK.js";import"./chunk-KIXOGZKJ.js";import"./chunk-BXZLLHYP.js";import"./chunk-AB2XVNNS.js";import"./chunk-FSCO2SM4.js";import"./chunk-NU53CDGF.js";import"./chunk-PR5YUSXN.js";import"./chunk-YBLNN5FU.js";import"./chunk-XKN5LH2Z.js";import"./chunk-ELLLNUKS.js";import"./chunk-TENPGIPX.js";import{g as x}from"./chunk-6OPB7FOJ.js";import{E as L,G as p,d as s,h as v,n,w as G,z as l}from"./chunk-ECD5B2ZM.js";import{a as y,b as a,c as r,d as i}from"./chunk-JMBDTNUR.js";var w=d()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),E=i(function({model:e}){let{classes:t}=w();return e.isLoading?r(l,{className:t.paper,"data-testid":"graph-genome-loading",children:[r("div",{className:t.row,children:[a(v,{variant:"h6",message:e.statusMessage}),a(n,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),a(G,{variant:"indeterminate"})]}):e.error?a(l,{className:t.paper,children:a(s,{error:e.error,onReset:()=>{e.retryLoad()}})}):a(l,{className:t.paper,"data-testid":"graph-genome-load-canceled",children:r("div",{className:t.row,children:[a(p,{variant:"h6",children:"Loading canceled"}),a(n,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),g=E;var F=`H VN:Z:1.0
2
2
  S 1 ACGT
3
3
  S 2 GGCC
4
4
  S 3 TTAA
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
7
7
  L 1 + 3 + 0M
8
8
  L 2 + 4 + 0M
9
9
  L 3 + 4 + 0M`,S=d()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),T=i(function({model:e}){let{classes:t}=S(),[m,M]=x("");function u(){let o=m.trim();o&&e.loadGFAFromLocation({uri:o,locationType:"UriLocation"})}function N(o){let c=o.target.files?.[0];o.target.value="",c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return r(l,{className:t.paper,children:[a("div",{className:t.header,children:a(p,{variant:"h6",children:"Load a GFA graph"})}),r("div",{className:t.column,children:[r("div",{className:t.rowCenter,children:[r(n,{variant:"outlined",component:"label",size:"small",children:["Choose file",a("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:o=>{N(o)}})]}),a(p,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),r("div",{className:t.rowEnd,children:[a(L,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:m,onChange:o=>{M(o.target.value)},onKeyDown:o=>{o.key==="Enter"&&u()},className:t.flex1}),a(n,{variant:"contained",onClick:()=>{u()},disabled:!m.trim(),children:"Open"})]})]}),a("div",{className:t.footer,children:a(n,{size:"small",onClick:()=>{e.loadGFA(F,"Example graph")},children:"Load 4-node example"})}),e.error?a(s,{error:e.error}):null]})}),P=T;var A=i(function({model:e}){return e.hasGraph?a(C,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?a(g,{model:e}):r(y,{children:[e.isLoading?a(g,{model:e}):null,a("div",{hidden:e.isLoading,children:a(P,{model:e})})]})}),J=A;export{J as default};
10
- //# sourceMappingURL=GraphGenomeView-BSJYTSFN.js.map
10
+ //# sourceMappingURL=GraphGenomeView-D3TBUFNW.js.map
@@ -1,2 +1,2 @@
1
- import{a as g}from"./chunk-DOLO4I5J.js";import"./chunk-I574RVHG.js";import"./chunk-UQT5WHCD.js";import"./chunk-MDRNFKXW.js";import"./chunk-LEWWQ7ZK.js";import"./chunk-6AYSOQOK.js";import"./chunk-BXZLLHYP.js";import"./chunk-AB2XVNNS.js";import"./chunk-FSCO2SM4.js";import"./chunk-NU53CDGF.js";import"./chunk-PR5YUSXN.js";import"./chunk-YBLNN5FU.js";import"./chunk-XKN5LH2Z.js";import"./chunk-ELLLNUKS.js";import"./chunk-TENPGIPX.js";import{g as T}from"./chunk-6OPB7FOJ.js";import"./chunk-ECD5B2ZM.js";import{b as e,c as l,d as y}from"./chunk-JMBDTNUR.js";var s=JBrowseExports["@jbrowse/display-kit/DisplayBackgroundProgress"];var v=s&&s.__esModule?s.default:s;var a=JBrowseExports["@jbrowse/display-kit/DisplayErrorBar"];var h=a&&a.__esModule?a.default:a;var i=JBrowseExports["@jbrowse/display-kit/DisplayLoadingOverlay"];var O=i&&i.__esModule?i.default:i;var n=JBrowseExports["@jbrowse/display-kit/TooLargeMessage"];var f=n&&n.__esModule?n.default:n;var t=JBrowseExports["@jbrowse/display-ui"],p=r=>t!=null&&r in Object(t)?t[r]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+r+"' from '@jbrowse/display-ui' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:r});var w=p("BottomRightCornerContext");var c=p("TrackOverlayPortal");var L=p("useChromeOverlayOverride");var j=t&&t.__esModule?t.default:t;var D={TooLarge:f,ErrorBar:h,Loading:O,BackgroundProgress:v};function d({model:r,phase:o,drawn:u,testid:_,style:C,children:E,...B}){let{TooLarge:G,ErrorBar:S,Loading:m,BackgroundProgress:P}=L()??D,[b,A]=T(null),{displayId:x}=r.configuration;return o==="tooLarge"?e("div",{style:{display:"contents"},"data-display-id":x,"data-display-phase":o,children:e(c,{children:e("div",{style:{pointerEvents:"auto"},children:e(G,{model:r})})})}):l("div",{...B,style:{position:"relative",height:r.height,...C},"data-testid":_,"data-display-id":x,"data-display-drawn":u,"data-display-phase":o,children:[e(w,{value:b,children:E}),l(c,{children:[e(S,{model:r,visible:o==="error"}),e(m,{model:r,visible:o==="loading"||o==="canceled",immediate:!u}),e("div",{ref:A,style:{position:"absolute",bottom:2,right:2,display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,pointerEvents:"none"},children:e(P,{model:r,visible:o==="ready"})})]})]})}var I=y(function({model:o}){return e(d,{model:o,phase:o.displayPhase,drawn:o.painted&&o.geometryPainted,testid:"linear-graph-display","data-layout":o.chosenLayoutMode,"data-cut-tier":o.cutTier,"data-recuts":o.recuts,"data-node-count":o.hasGraph?o.nodeCount:void 0,"data-loading":o.isLoading?"":void 0,style:{width:o.paneWidth,height:o.height,overflow:"hidden"},children:e(g,{model:o,ownChrome:!1})})}),Q=I;export{Q as default};
2
- //# sourceMappingURL=LinearGraphDisplay-VW7DGOVT.js.map
1
+ import{a as g}from"./chunk-MIY4JCDL.js";import"./chunk-I574RVHG.js";import"./chunk-BXFEZVDW.js";import"./chunk-5DRS22TL.js";import"./chunk-LEWWQ7ZK.js";import"./chunk-KIXOGZKJ.js";import"./chunk-BXZLLHYP.js";import"./chunk-AB2XVNNS.js";import"./chunk-FSCO2SM4.js";import"./chunk-NU53CDGF.js";import"./chunk-PR5YUSXN.js";import"./chunk-YBLNN5FU.js";import"./chunk-XKN5LH2Z.js";import"./chunk-ELLLNUKS.js";import"./chunk-TENPGIPX.js";import{g as T}from"./chunk-6OPB7FOJ.js";import"./chunk-ECD5B2ZM.js";import{b as e,c as l,d as y}from"./chunk-JMBDTNUR.js";var s=JBrowseExports["@jbrowse/display-kit/DisplayBackgroundProgress"];var v=s&&s.__esModule?s.default:s;var a=JBrowseExports["@jbrowse/display-kit/DisplayErrorBar"];var h=a&&a.__esModule?a.default:a;var i=JBrowseExports["@jbrowse/display-kit/DisplayLoadingOverlay"];var O=i&&i.__esModule?i.default:i;var n=JBrowseExports["@jbrowse/display-kit/TooLargeMessage"];var f=n&&n.__esModule?n.default:n;var t=JBrowseExports["@jbrowse/display-ui"],p=r=>t!=null&&r in Object(t)?t[r]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+r+"' from '@jbrowse/display-ui' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:r});var w=p("BottomRightCornerContext");var c=p("TrackOverlayPortal");var L=p("useChromeOverlayOverride");var j=t&&t.__esModule?t.default:t;var D={TooLarge:f,ErrorBar:h,Loading:O,BackgroundProgress:v};function d({model:r,phase:o,drawn:u,testid:_,style:C,children:E,...B}){let{TooLarge:G,ErrorBar:S,Loading:m,BackgroundProgress:P}=L()??D,[b,A]=T(null),{displayId:x}=r.configuration;return o==="tooLarge"?e("div",{style:{display:"contents"},"data-display-id":x,"data-display-phase":o,children:e(c,{children:e("div",{style:{pointerEvents:"auto"},children:e(G,{model:r})})})}):l("div",{...B,style:{position:"relative",height:r.height,...C},"data-testid":_,"data-display-id":x,"data-display-drawn":u,"data-display-phase":o,children:[e(w,{value:b,children:E}),l(c,{children:[e(S,{model:r,visible:o==="error"}),e(m,{model:r,visible:o==="loading"||o==="canceled",immediate:!u}),e("div",{ref:A,style:{position:"absolute",bottom:2,right:2,display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,pointerEvents:"none"},children:e(P,{model:r,visible:o==="ready"})})]})]})}var I=y(function({model:o}){return e(d,{model:o,phase:o.displayPhase,drawn:o.painted&&o.geometryPainted,testid:"linear-graph-display","data-layout":o.chosenLayoutMode,"data-cut-tier":o.cutTier,"data-recuts":o.recuts,"data-node-count":o.hasGraph?o.nodeCount:void 0,"data-loading":o.isLoading?"":void 0,style:{width:o.paneWidth,height:o.height,overflow:"hidden"},children:e(g,{model:o,ownChrome:!1})})}),Q=I;export{Q as default};
2
+ //# sourceMappingURL=LinearGraphDisplay-YKGK4KBD.js.map
@@ -0,0 +1,3 @@
1
+ import{a as u,b as P,c as O}from"./chunk-WSZ6RCMI.js";import{a as v}from"./chunk-P6FDUP52.js";import{a as B,c as I,e as R,f as T}from"./chunk-X4NNWAXW.js";import"./chunk-R4DSKZ5P.js";import"./chunk-PR5YUSXN.js";import"./chunk-OGQ6OQDN.js";import"./chunk-YBLNN5FU.js";import{c as F,f as M}from"./chunk-XKN5LH2Z.js";import{a as $,o as A}from"./chunk-TENPGIPX.js";function y(i){let e=i.split(" "),a=e.length>=8,r=a?5:0;return{anchored:a,segment:{refName:e[r],start:+e[r+1],end:+e[r+2],id:e[3],rank:+e[4],tags:e[a?8:5]??""}}}function G(i){let e=i.tags.split(" ").find(r=>r.startsWith("SM:Z:"));if(e===void 0)return;let a=e.slice(5).split(",").map(r=>r.trim()).filter(Boolean);return a.length>0?a:void 0}function W(i){return{id:i.slice(0,-1),strand:i.slice(-1)}}function w(i){let e=i.split(" "),a=W(e[3]),r=W(e[4]);return{source:a.id,sourceStrand:a.strand,target:r.id,targetStrand:r.strand,sourceSegment:{id:a.id,refName:e[5],start:+e[6],end:+e[7],rank:+e[8],tags:e[13]??""},targetSegment:{id:r.id,refName:e[9],start:+e[10],end:+e[11],rank:+e[12],tags:e[14]??""}}}function S(i){return`${i.source}${i.sourceStrand}${i.target}${i.targetStrand}`}function Z(i,e,a){let r=n=>n.rank!==0||n.refName!==a.refName?0:n.end<=a.start?-1:n.start>=a.end?1:0,t=new Map(i),s=new Map;for(let n of e)if(i.has(n.source)||i.has(n.target)||r(n.sourceSegment)*r(n.targetSegment)===-1){s.set(S(n),n);for(let o of[n.sourceSegment,n.targetSegment])t.has(o.id)||t.set(o.id,o)}for(let n of e)t.has(n.source)&&t.has(n.target)&&s.set(S(n),n);return{segments:t,links:s}}function H(i,e,a){let r=t=>t.refName!==a.refName||t.end<=a.start||t.start>=a.end;return[...j(i.filter(t=>t.rank>0),e,a.end-a.start),...j(i.filter(t=>t.rank===0&&r(t)),new Set(i.map(t=>t.id)),0)]}function j(i,e,a){let r=[...i].sort((s,n)=>b(s.refName,n.refName)||s.start-n.start),t=[];for(let s of r){let n=t.at(-1);n?.refName===s.refName&&s.start-n.end<=a?(n.needed||=s.start>n.end||e.has(s.id),n.end=Math.max(n.end,s.end)):t.push({refName:s.refName,start:s.start,end:s.end,needed:e.has(s.id)})}return t.filter(s=>s.needed).map(({refName:s,start:n,end:o})=>({refName:s,start:n,end:o}))}function _(i,e,a){let r=t=>e.has(t.id)||a.some(s=>s.refName===t.refName&&t.start>=s.start&&t.end<=s.end);return i.filter(t=>r(t.sourceSegment)&&r(t.targetSegment))}var K=/^[A-Za-z][A-Za-z0-9]:[AifZJHB]:/;function z(i){let{id:e,refName:a,start:r,end:t,rank:s,tags:n}=i,o=n.split(" ").filter(f=>K.test(f)),c=o.length===0?"":` ${o.join(" ")}`;return`S ${e} * LN:i:${t-r} SN:Z:${a} SO:i:${r} SR:i:${s}${c}`}function J(i){let{source:e,sourceStrand:a,target:r,targetStrand:t}=i;return`L ${e} ${a} ${r} ${t} 0M`}function b(i,e){return i<e?-1:i>e?1:0}function L(i,e){let a=[...i.values()].sort((t,s)=>b(t.refName,s.refName)||t.start-s.start||b(t.id,s.id)),r=[...e.keys()].sort((t,s)=>b(t,s));return["H VN:Z:1.0",...a.map(t=>z(t)),...r.map(t=>J(e.get(t)))].join(`
2
+ `)}function D(i){return i.filter(e=>e.rank>0)}var V=1e3,C=class extends B{static{this.capabilities=["getFeatures","getRefNames"]}constructor(e,a,r){super(e,a,r),this.fine=this.openIndex([])}openIndex(e){let a=R(this,[...e,"segmentsLocation"],[...e,"segmentsIndex"]),r=this.getConf("walksLocation"),t=e.length===0&&(!("uri"in r)||r.uri!==""),s=R(this,[...e,"linksLocation"],[...e,"linksIndex"]);return{segments:a,links:s,walks:t?new O({walks:R(this,["walksLocation"],["walksIndex"]),nodes:a,links:s},this.getConf("walkChunk")):void 0,refNames:new T(a,this)}}async getHaplotypeNames(e={}){let a=await this.fine.walks?.header(e);return a?.haplotypes.length?a.haplotypes:void 0}index(e="fine"){return e==="fine"?this.fine:(this.coarse??=this.openIndex(["coarse"]),this.coarse)}async getRefNames(e={}){return this.fine.refNames.assemblyRefNames(e)}async hasDataForRefName(){return!0}getFeatures(e,a={}){let{signal:r,statusCallback:t}=a;return I(async s=>{let n=await this.fine.refNames.resolve(e,a);if(n!==void 0){let o=this.fine.walks?await this.fine.walks.queryStart(e.start,a):e.start;await A("Downloading segments",t,()=>u(this.fine.segments,n,o,e.end,{signal:r,lineCallback:c=>{let{segment:f,anchored:h}=y(c);if(h&&f.refName!==n)return;let l=G(f);s.next(new $({uniqueId:f.id,refName:e.refName,start:f.start,end:f.end,name:f.id,type:"segment",rank:f.rank,stableName:f.refName,...l&&{samples:l,sampleCount:l.length}}))}}))}s.complete()},r)}async getSubgraph(e,a={}){let{hops:r=0,signal:t,tier:s}=a,n=this.index(s),o=new Map,c=new Map,f=await n.refNames.resolve(e,{signal:t}),h=async(p,m,g)=>{let d=[];return await u(n.links,p,m,g,{signal:t,lineCallback:E=>{let k=w(E);c.set(S(k),k);for(let N of[k.sourceSegment,k.targetSegment])o.has(N.id)||(o.set(N.id,N),d.push(N))}}),d};if(f===void 0)throw new Error(`${e.assemblyName} ${e.refName} is not in this graph's index; a graph with PanSN names (GRCh38#0#chr1) needs ${e.assemblyName} mapped to its prefix in assemblyNameToPanSN`);if(n.walks)return this.walkSubgraph(n.walks,f,e,a);let l={anchored:!1};if(await u(n.segments,f,e.start,e.end,{signal:t,lineCallback:p=>{let m=y(p);l.anchored||=m.anchored,o.set(m.segment.id,m.segment)}}),l.anchored){let p=[];await u(n.links,f,e.start,e.end,{signal:t,lineCallback:g=>{p.push(w(g))}});let m=Z(o,p,{refName:f,start:e.start,end:e.end});return L(m.segments,m.links)}let x=D(await h(f,e.start,e.end));for(let p=0;p<r;p++){let m=await Promise.all(x.map(g=>h(g.refName,g.start,g.end)));x=D(m.flat())}if(r>0){let p=H([...o.values()],new Set(x.map(g=>g.id)),{refName:f,start:e.start,end:e.end}),m=[];await Promise.all(p.map(g=>u(n.links,g.refName,g.start,g.end,{signal:t,lineCallback:d=>{m.push(w(d))}})));for(let g of _(m,o,p)){c.set(S(g),g);for(let d of[g.sourceSegment,g.targetSegment])o.has(d.id)||o.set(d.id,d)}}return L(o,c)}async walkSubgraph(e,a,r,t){let{graph:s,kept:n,fragments:o}=await e.cut(a,r,{signal:t.signal,keep:P(t.haplotypes?.map(c=>M(this,c)),F(a)),stepBudget:t.walkRows?1/0:this.getConf("walkStepBudget"),byteBudget:this.getConf("walkByteBudget"),context:V});return v(s.tables(n,o),r,t.walkRows)}};export{C as default};
3
+ //# sourceMappingURL=RgfaTabixAdapter-2PJS7QDO.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/RgfaTabixAdapter/rgfaBed.ts", "../../src/RgfaTabixAdapter/RgfaTabixAdapter.ts"],
4
+ "sourcesContent": ["// A segment as it appears in segs.bed.gz, and as it is repeated inside every\n// links.bed.gz row: `stableName start end segmentId rank [tags]`. The first\n// five are the SN/SO/SR tags rGFA already carries, projected to BED by\n// `gfatools gfa2bed -m`.\n//\n// `tags` is a space-separated list of GFA tags, written verbatim onto the\n// S-line formatSegment synthesizes, where the GFA parser reads them into\n// `GraphNode.tags` with no work here. It is the extension point for everything\n// the five columns cannot say: carriage on a path-derived graph (`SM:Z:`), the\n// collapse summary on a level-of-detail tier (`ct:Z:`, `cn:i:`, ...), a\n// precomputed layout position later. rGFA files have no sixth column at all,\n// so this is empty for them and nothing changes.\nexport interface RgfaSegment {\n refName: string\n start: number\n end: number\n id: string\n rank: number\n tags: string\n}\n\nexport interface RgfaLink {\n source: string\n sourceStrand: string\n target: string\n targetStrand: string\n sourceSegment: RgfaSegment\n targetSegment: RgfaSegment\n}\n\nexport function parseSegmentLine(line: string): RgfaSegment {\n return parseSegmentRow(line).segment\n}\n\n// gfa-to-tabix's anchored layout files a segment under the reference interval\n// its bubble hangs from and states the segment's own coordinate after the rank:\n// `anchorName anchorStart anchorEnd segmentId rank stableName start end [tags]`.\n// One query over a region then returns every segment of every bubble under it,\n// and `anchored` tells a cut it has nothing left to follow.\nexport function parseSegmentRow(line: string) {\n const cols = line.split('\\t')\n const anchored = cols.length >= 8\n const own = anchored ? 5 : 0\n return {\n anchored,\n segment: {\n refName: cols[own]!,\n start: +cols[own + 1]!,\n end: +cols[own + 2]!,\n id: cols[3]!,\n rank: +cols[4]!,\n tags: cols[anchored ? 8 : 5] ?? '',\n } satisfies RgfaSegment,\n }\n}\n\n// Carriage as an ordinary feature attribute, for the linear track rather than\n// the graph. The tag column reaches the graph view through the synthesized\n// S-line (formatSegment below, then gfaConverter reads SM into\n// `GraphNode.samples`), and that route ends at the graph: `getFeatures` builds\n// its own features and had no way to say who carries a segment, so a lane\n// colored by carriage was not expressible.\n//\n// `SM:Z:` is its own grammar check here. build_pggb_tabix.sh wrote a bare\n// comma-separated list in this column before the tag column existed, and those\n// files are still hosted; a bare list has no prefix to match, so it is dropped\n// rather than read as one sample named `K12,Sakai,CFT073`.\n//\n// Undefined rather than [] when the tag is absent, matching gfaConverter: an\n// rGFA has no sixth column at all, so a segment that says nothing about\n// carriage stays distinguishable from one carried by nobody.\nexport function segmentSamples(segment: RgfaSegment) {\n const tag = segment.tags.split(' ').find(t => t.startsWith('SM:Z:'))\n if (tag === undefined) {\n return undefined\n }\n const samples = tag\n .slice('SM:Z:'.length)\n .split(',')\n .map(s => s.trim())\n .filter(Boolean)\n return samples.length > 0 ? samples : undefined\n}\n\n// `s322+` \u2014 the L-line's segment id with its orientation appended, mirroring\n// the GFA record it came from.\nfunction parseEndpoint(field: string) {\n return { id: field.slice(0, -1), strand: field.slice(-1) }\n}\n\nexport function parseLinkLine(line: string): RgfaLink {\n const cols = line.split('\\t')\n const source = parseEndpoint(cols[3]!)\n const target = parseEndpoint(cols[4]!)\n return {\n source: source.id,\n sourceStrand: source.strand,\n target: target.id,\n targetStrand: target.strand,\n sourceSegment: {\n id: source.id,\n refName: cols[5]!,\n start: +cols[6]!,\n end: +cols[7]!,\n rank: +cols[8]!,\n tags: cols[13] ?? '',\n },\n targetSegment: {\n id: target.id,\n refName: cols[9]!,\n start: +cols[10]!,\n end: +cols[11]!,\n rank: +cols[12]!,\n tags: cols[14] ?? '',\n },\n }\n}\n\nexport function linkKey(link: RgfaLink) {\n return `${link.source}${link.sourceStrand}${link.target}${link.targetStrand}`\n}\n\n// The cut an anchored index gives: `under` is what the segment file returned\n// for the window, every segment of every bubble under it, and `found` is what\n// the link file returned. gfa-to-tabix files a link widely enough that `found`\n// holds every link touching a segment in `under` and every link between the\n// segments those lead to, plus links of neither kind, which are dropped here.\n// A backbone link that jumps the whole window, as a deletion or inversion\n// spanning it does, touches nothing in `under` and is kept by its own rule.\nexport function anchoredCut(\n under: Map<string, RgfaSegment>,\n found: RgfaLink[],\n window: StableSpan,\n) {\n const side = (segment: RgfaSegment) =>\n segment.rank !== 0 || segment.refName !== window.refName\n ? 0\n : segment.end <= window.start\n ? -1\n : segment.start >= window.end\n ? 1\n : 0\n const segments = new Map(under)\n const links = new Map<string, RgfaLink>()\n for (const link of found) {\n if (\n under.has(link.source) ||\n under.has(link.target) ||\n side(link.sourceSegment) * side(link.targetSegment) === -1\n ) {\n links.set(linkKey(link), link)\n for (const segment of [link.sourceSegment, link.targetSegment]) {\n if (!segments.has(segment.id)) {\n segments.set(segment.id, segment)\n }\n }\n }\n }\n for (const link of found) {\n if (segments.has(link.source) && segments.has(link.target)) {\n links.set(linkKey(link), link)\n }\n }\n return { segments, links }\n}\n\n// Both endpoints of a link are written into every row, so the same link is\n// indexed under each endpoint's stable sequence and arrives twice for a region\n// covering both. Callers dedupe on linkKey.\n\nexport interface StableSpan {\n refName: string\n start: number\n end: number\n}\n\n// Where a cut reads links once more to close itself. A hop reads the links of\n// the segments the round before it reached, so a link between two segments of\n// the last round is never read and an allele reached from both ends draws as\n// two stubs. rGFA lays an allele out as one stretch of the stable sequence that\n// introduced it, so pieces of one sequence within the window's length of each\n// other merge into a span, and reading it brings the pieces between too.\n// Backbone reached past the window is unread for the same reason; its spans\n// join only abutting pieces, since the reference past the window is not the\n// cut's to fill. A span whose segments were all read and abut is skipped.\nexport function closingSpans(\n held: RgfaSegment[],\n unread: Set<string>,\n window: StableSpan,\n) {\n const outside = (segment: RgfaSegment) =>\n segment.refName !== window.refName ||\n segment.end <= window.start ||\n segment.start >= window.end\n return [\n ...mergedSpans(\n held.filter(segment => segment.rank > 0),\n unread,\n window.end - window.start,\n ),\n ...mergedSpans(\n held.filter(segment => segment.rank === 0 && outside(segment)),\n new Set(held.map(segment => segment.id)),\n 0,\n ),\n ]\n}\n\nfunction mergedSpans(\n segments: RgfaSegment[],\n unread: Set<string>,\n maxGap: number,\n) {\n const sorted = [...segments].sort(\n (a, b) => compare(a.refName, b.refName) || a.start - b.start,\n )\n const spans: (StableSpan & { needed: boolean })[] = []\n for (const segment of sorted) {\n const span = spans.at(-1)\n if (\n span?.refName === segment.refName &&\n segment.start - span.end <= maxGap\n ) {\n span.needed ||= segment.start > span.end || unread.has(segment.id)\n span.end = Math.max(span.end, segment.end)\n } else {\n spans.push({\n refName: segment.refName,\n start: segment.start,\n end: segment.end,\n needed: unread.has(segment.id),\n })\n }\n }\n return spans\n .filter(span => span.needed)\n .map(({ refName, start, end }): StableSpan => ({ refName, start, end }))\n}\n\n// The links a closing read keeps: each end is a segment the cut holds or one\n// lying inside a span. Following anything else is what another hop is for.\nexport function closingLinks(\n found: RgfaLink[],\n held: Map<string, RgfaSegment>,\n spans: StableSpan[],\n) {\n const inside = (segment: RgfaSegment) =>\n held.has(segment.id) ||\n spans.some(\n span =>\n span.refName === segment.refName &&\n segment.start >= span.start &&\n segment.end <= span.end,\n )\n return found.filter(\n link => inside(link.sourceSegment) && inside(link.targetSegment),\n )\n}\n\n// Segments carry no sequence here \u2014 the BED records only their span \u2014 so every\n// S-line is written with `*` and an LN tag, which is what the GFA spec asks for\n// and what packages/graph-core's parser reads back as the node length.\n// `NM:i:0`, `SM:Z:HG002.1,HG002.2` \u2014 the GFA tag grammar, checked rather than\n// trusted. Files built before the tag column existed put a bare comma-separated\n// sample list here, and passing that through would put a field that is not a\n// tag on an S-line, which is a malformed GFA rather than a missing annotation.\n// Dropping it degrades to the pre-tag behaviour instead.\nconst GFA_TAG = /^[A-Za-z][A-Za-z0-9]:[AifZJHB]:/\n\nfunction formatSegment(segment: RgfaSegment) {\n const { id, refName, start, end, rank, tags } = segment\n const valid = tags.split(' ').filter(t => GFA_TAG.test(t))\n const extra = valid.length === 0 ? '' : `\\t${valid.join('\\t')}`\n return `S\\t${id}\\t*\\tLN:i:${end - start}\\tSN:Z:${refName}\\tSO:i:${start}\\tSR:i:${rank}${extra}`\n}\n\nfunction formatLink(link: RgfaLink) {\n const { source, sourceStrand, target, targetStrand } = link\n return `L\\t${source}\\t${sourceStrand}\\t${target}\\t${targetStrand}\\t0M`\n}\n\n// Codepoint order, not localeCompare: the byte-identical-output guarantee below\n// has to hold across locales.\nfunction compare(a: string, b: string) {\n return a < b ? -1 : a > b ? 1 : 0\n}\n\n// Deterministic ordering: the same region always produces byte-identical GFA,\n// so a layout computed from it is reproducible.\nexport function formatSubgraph(\n segments: Map<string, RgfaSegment>,\n links: Map<string, RgfaLink>,\n) {\n const sortedSegments = [...segments.values()].sort(\n (a, b) =>\n compare(a.refName, b.refName) || a.start - b.start || compare(a.id, b.id),\n )\n const sortedLinks = [...links.keys()].sort((a, b) => compare(a, b))\n return [\n 'H\\tVN:Z:1.0',\n ...sortedSegments.map(s => formatSegment(s)),\n ...sortedLinks.map(k => formatLink(links.get(k)!)),\n ].join('\\n')\n}\n", "import { panSNHaplotype, resolvePanSNPrefix } from '@jbrowse/bandage-core/pansn'\nimport { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport { SimpleFeature, updateStatus } from '@jbrowse/core/util'\nimport { ObservableCreate } from '@jbrowse/core/util/rxjs'\n\nimport { PanSNRefNames, openTabixSlot } from '../panSNTabix.ts'\nimport {\n anchoredCut,\n closingLinks,\n closingSpans,\n formatSubgraph,\n linkKey,\n parseLinkLine,\n parseSegmentRow,\n segmentSamples,\n} from './rgfaBed.ts'\nimport { getLines } from './tabixRange.ts'\nimport { WalkReader } from './walkReader.ts'\nimport { walkCutFor } from './walkRowRuns.ts'\nimport { walkNameFilter } from './walkRows.ts'\n\nimport type { RgfaTabixAdapterConfig } from './configSchema.ts'\nimport type { SubgraphAdapterOptions, SubgraphTier } from '../GetSubgraph.ts'\nimport type { RgfaLink, RgfaSegment } from './rgfaBed.ts'\nimport type { WalkCut } from './walkRowRuns.ts'\nimport type { TabixIndexedFile } from '@gmod/tabix'\nimport type PluginManager from '@jbrowse/core/PluginManager'\nimport type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'\nimport type { Feature } from '@jbrowse/core/util'\nimport type { FileLocation, Region } from '@jbrowse/core/util/types'\n\n// What a hop follows: alleles, never the backbone. A rank-0 segment reached\n// through a link is flanking backbone, usually outside the window, so querying\n// its links walks the reference away from the region, brings back more backbone,\n// and closes nothing. Every segment that closes a bubble is an allele interior,\n// and an allele interior is rank > 0 in both index formats (rGFA's SR tag, and\n// pggb's rank 0-or-1 against the anchor path). Reached backbone still becomes a\n// node and its edge still draws; it is only not walked through.\n//\n// This is gfabase's rule, arrived at from the other end. `gfabase sub` expands\n// from a seed either to the whole connected component (`--connected`, which its\n// own README calls overkill) or with `--cutpoints 1`, which takes the biconnected\n// component by *stopping at cutpoints*, the segments every end-to-end walk of\n// the chromosome must traverse. In a reference-anchored pangenome the cutpoints\n// are the backbone, and rank is what the index already states about it, so\n// `rank > 0` is that stopping rule without a connectivity index to build. The\n// third tool is the same shape again: `gfatools view -R` maps the region onto its\n// precomputed bubble decomposition and returns whole overlapping bubbles\n// (gfa_query_by_reg), which is complete for the same reason. Bandage's own\n// `--distance` is a node-step radius, but Bandage holds the entire graph in\n// memory, so its scope is a drawing filter rather than a fetch strategy.\n//\n// Measured with this rule: the E. coli paa window converges at one hop (17\n// segments at 1 and at 2), so the cut closes and stays closed. HPRC's amylase\n// window keeps growing (63 at 0, 78 at 1, 92 at 2) because its alleles have\n// alleles, and wall-clock is flat across all three, since a hop's queries go out\n// together and the remote index dominates.\n//\n// The exact version, when a graph ships a bubble index beside its segments:\n// gfatools' bubble rows carry the member segment ids of every bubble, so the\n// bubbles overlapping the region state which segments a complete cut must\n// contain. That turns the hop count into a termination condition rather than a\n// setting, and MinigraphBubbleAdapter already parses those rows.\nfunction offReference(segments: RgfaSegment[]) {\n return segments.filter(segment => segment.rank > 0)\n}\n\ninterface GraphIndex {\n segments: TabixIndexedFile\n links: TabixIndexedFile\n walks?: WalkReader\n refNames: PanSNRefNames\n}\n\n// How much graph a walk cut keeps around the window, on the reference\nconst WALK_CONTEXT = 1000\n\nexport default class RgfaTabixAdapter extends BaseFeatureDataAdapter<RgfaTabixAdapterConfig> {\n public static capabilities = ['getFeatures', 'getRefNames']\n\n private readonly fine\n private coarse: GraphIndex | undefined\n\n public constructor(\n config: RgfaTabixAdapterConfig,\n getSubAdapter?: getSubAdapterType,\n pluginManager?: PluginManager,\n ) {\n super(config, getSubAdapter, pluginManager)\n this.fine = this.openIndex([])\n }\n\n // refNames off the SEGMENT index: it is the one that names every stable\n // sequence the graph is anchored to, where the link index only names those a\n // link touches.\n private openIndex(under: string[]): GraphIndex {\n const segments = openTabixSlot(\n this,\n [...under, 'segmentsLocation'],\n [...under, 'segmentsIndex'],\n )\n const walksLocation: FileLocation = this.getConf('walksLocation')\n const hasWalks =\n under.length === 0 &&\n (!('uri' in walksLocation) || walksLocation.uri !== '')\n const links = openTabixSlot(\n this,\n [...under, 'linksLocation'],\n [...under, 'linksIndex'],\n )\n return {\n segments,\n links,\n walks: hasWalks\n ? new WalkReader(\n {\n walks: openTabixSlot(this, ['walksLocation'], ['walksIndex']),\n nodes: segments,\n links,\n },\n this.getConf('walkChunk'),\n )\n : undefined,\n refNames: new PanSNRefNames(segments, this),\n }\n }\n\n /**\n * The haplotypes a walk-indexed graph's header names, `sample#haplotype`\n * in byte order, or undefined when it names none\n */\n async getHaplotypeNames(opts: BaseOptions = {}) {\n const header = await this.fine.walks?.header(opts)\n return header?.haplotypes.length ? header.haplotypes : undefined\n }\n\n private index(tier: SubgraphTier = 'fine') {\n if (tier === 'fine') {\n return this.fine\n }\n this.coarse ??= this.openIndex(['coarse'])\n return this.coarse\n }\n\n async getRefNames(opts: BaseOptions = {}) {\n return this.fine.refNames.assemblyRefNames(opts)\n }\n\n public async hasDataForRefName() {\n return true\n }\n\n getFeatures(query: Region, opts: BaseOptions = {}) {\n const { signal, statusCallback } = opts\n return ObservableCreate<Feature>(async observer => {\n const tabixRefName = await this.fine.refNames.resolve(query, opts)\n if (tabixRefName !== undefined) {\n // a walk-indexed node row names only its chunk's first base, and a\n // node crossing in from a chunk before is filed there\n const start = this.fine.walks\n ? await this.fine.walks.queryStart(query.start, opts)\n : query.start\n await updateStatus('Downloading segments', statusCallback, () =>\n getLines(this.fine.segments, tabixRefName, start, query.end, {\n signal,\n lineCallback: line => {\n const { segment, anchored } = parseSegmentRow(line)\n // An anchored index also returns the alleles under the region,\n // which lie on other stable sequences and have no place on this\n // one.\n if (anchored && segment.refName !== tabixRefName) {\n return\n }\n // `samples` lists the haplotypes whose paths visit the segment and\n // `sampleCount` counts them. A lane's color reads the count, and\n // a count in jexl would otherwise rely on `.length` resolving\n // through a member access on an array.\n const samples = segmentSamples(segment)\n observer.next(\n new SimpleFeature({\n uniqueId: segment.id,\n refName: query.refName,\n start: segment.start,\n end: segment.end,\n name: segment.id,\n type: 'segment',\n rank: segment.rank,\n stableName: segment.refName,\n ...(samples && { samples, sampleCount: samples.length }),\n }),\n )\n },\n }),\n )\n }\n observer.complete()\n }, signal)\n }\n\n // Extract the graph around a region for GraphGenomeView: GFA text, or a\n // walk-indexed graph's tables (walkSubgraph). The\n // region's own segments come from segs.bed.gz; links.bed.gz supplies the edges\n // incident to them *and* the coordinates of the segments on the other end,\n // which typically sit on a different stable sequence (a rank>0 bubble) and so\n // are not reachable by any coordinate query on this region.\n //\n // `hops` is extra rounds of link-following past the region's own segments\n // and their immediate neighbours, each costing one tabix query per\n // off-reference segment newly reached. After the last round, one more read\n // per stretch of stable sequence the cut holds closes it (closingSpans), so\n // an allele reached from both ends draws whole. The view asks for one hop; a\n // hopless cut stays as cheap as it was. `signal` goes to every one of those\n // queries, so a cut the view has replaced stops.\n // `tier: 'coarse'` reads the `coarse` pair instead, the same way.\n async getSubgraph(\n region: Region,\n opts: SubgraphAdapterOptions = {},\n ): Promise<string | WalkCut> {\n const { hops = 0, signal, tier } = opts\n const index = this.index(tier)\n const segments = new Map<string, RgfaSegment>()\n const links = new Map<string, RgfaLink>()\n const tabixRefName = await index.refNames.resolve(region, { signal })\n\n const addLinksOver = async (\n refName: string,\n start: number,\n end: number,\n ) => {\n const reached: RgfaSegment[] = []\n await getLines(index.links, refName, start, end, {\n signal,\n lineCallback: line => {\n const link = parseLinkLine(line)\n links.set(linkKey(link), link)\n for (const segment of [link.sourceSegment, link.targetSegment]) {\n if (!segments.has(segment.id)) {\n segments.set(segment.id, segment)\n reached.push(segment)\n }\n }\n },\n })\n return reached\n }\n\n if (tabixRefName === undefined) {\n throw new Error(\n `${region.assemblyName} ${region.refName} is not in this graph's index; a graph with PanSN names (GRCh38#0#chr1) needs ${region.assemblyName} mapped to its prefix in assemblyNameToPanSN`,\n )\n }\n if (index.walks) {\n return this.walkSubgraph(index.walks, tabixRefName, region, opts)\n }\n const layout = { anchored: false }\n await getLines(index.segments, tabixRefName, region.start, region.end, {\n signal,\n lineCallback: line => {\n const row = parseSegmentRow(line)\n layout.anchored ||= row.anchored\n segments.set(row.segment.id, row.segment)\n },\n })\n // An anchored index files every allele and every link under the reference\n // interval its bubble hangs from, so one read of each file holds the whole\n // graph under the region and there is nothing to hop to or close.\n if (layout.anchored) {\n const found: RgfaLink[] = []\n await getLines(index.links, tabixRefName, region.start, region.end, {\n signal,\n lineCallback: line => {\n found.push(parseLinkLine(line))\n },\n })\n const cut = anchoredCut(segments, found, {\n refName: tabixRefName,\n start: region.start,\n end: region.end,\n })\n return formatSubgraph(cut.segments, cut.links)\n }\n let frontier = offReference(\n await addLinksOver(tabixRefName, region.start, region.end),\n )\n for (let hop = 0; hop < hops; hop++) {\n // One hop's queries are independent of each other, so they go out\n // together rather than one round-trip at a time. Their callbacks share\n // the segment and link maps, which is safe because only one of them runs\n // at a time, and the output is sorted at the end regardless of the order\n // they arrive in.\n const reached = await Promise.all(\n frontier.map(segment =>\n addLinksOver(segment.refName, segment.start, segment.end),\n ),\n )\n frontier = offReference(reached.flat())\n }\n if (hops > 0) {\n const spans = closingSpans(\n [...segments.values()],\n new Set(frontier.map(segment => segment.id)),\n { refName: tabixRefName, start: region.start, end: region.end },\n )\n const found: RgfaLink[] = []\n await Promise.all(\n spans.map(span =>\n getLines(index.links, span.refName, span.start, span.end, {\n signal,\n lineCallback: line => {\n found.push(parseLinkLine(line))\n },\n }),\n ),\n )\n for (const link of closingLinks(found, segments, spans)) {\n links.set(linkKey(link), link)\n for (const segment of [link.sourceSegment, link.targetSegment]) {\n if (!segments.has(segment.id)) {\n segments.set(segment.id, segment)\n }\n }\n }\n }\n\n return formatSubgraph(segments, links)\n }\n\n // Only the walks `haplotypes` asks for, and the reference's, are decoded\n private async walkSubgraph(\n walks: WalkReader,\n refName: string,\n region: Region,\n opts: SubgraphAdapterOptions,\n ) {\n const { graph, kept, fragments } = await walks.cut(refName, region, {\n signal: opts.signal,\n keep: walkNameFilter(\n opts.haplotypes?.map(lane => resolvePanSNPrefix(this, lane)),\n panSNHaplotype(refName),\n ),\n stepBudget: opts.walkRows ? Infinity : this.getConf('walkStepBudget'),\n byteBudget: this.getConf('walkByteBudget'),\n context: WALK_CONTEXT,\n })\n return walkCutFor(graph.tables(kept, fragments), region, opts.walkRows)\n }\n}\n"],
5
+ "mappings": "yWAuCO,SAASA,EAAgBC,EAAc,CAC5C,IAAMC,EAAOD,EAAK,MAAM,GAAI,EACtBE,EAAWD,EAAK,QAAU,EAC1BE,EAAMD,EAAW,EAAI,EAC3B,MAAO,CACL,SAAAA,EACA,QAAS,CACP,QAASD,EAAKE,CAAG,EACjB,MAAO,CAACF,EAAKE,EAAM,CAAC,EACpB,IAAK,CAACF,EAAKE,EAAM,CAAC,EAClB,GAAIF,EAAK,CAAC,EACV,KAAM,CAACA,EAAK,CAAC,EACb,KAAMA,EAAKC,EAAW,EAAI,CAAC,GAAK,EAClC,CACF,CACF,CAiBO,SAASE,EAAeC,EAAsB,CACnD,IAAMC,EAAMD,EAAQ,KAAK,MAAM,GAAG,EAAE,KAAKE,GAAKA,EAAE,WAAW,OAAO,CAAC,EACnE,GAAID,IAAQ,OACV,OAEF,IAAME,EAAUF,EACb,MAAM,CAAc,EACpB,MAAM,GAAG,EACT,IAAIG,GAAKA,EAAE,KAAK,CAAC,EACjB,OAAO,OAAO,EACjB,OAAOD,EAAQ,OAAS,EAAIA,EAAU,MACxC,CAIA,SAASE,EAAcC,EAAe,CACpC,MAAO,CAAE,GAAIA,EAAM,MAAM,EAAG,EAAE,EAAG,OAAQA,EAAM,MAAM,EAAE,CAAE,CAC3D,CAEO,SAASC,EAAcZ,EAAwB,CACpD,IAAMC,EAAOD,EAAK,MAAM,GAAI,EACtBa,EAASH,EAAcT,EAAK,CAAC,CAAE,EAC/Ba,EAASJ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vC,IAAW,CAACuC,EAAK,cAAeA,EAAK,aAAa,EACtDxC,EAAS,IAAIC,EAAQ,EAAE,GAC1BD,EAAS,IAAIC,EAAQ,GAAIA,CAAO,CAGtC,CACF,CAEA,OAAO+C,EAAehD,EAAUY,CAAK,CACvC,CAGA,MAAc,aACZ2C,EACAlB,EACAJ,EACAlB,EACA,CACA,GAAM,CAAE,MAAAyC,EAAO,KAAAC,EAAM,UAAAC,CAAU,EAAI,MAAMH,EAAM,IAAIlB,EAASJ,EAAQ,CAClE,OAAQlB,EAAK,OACb,KAAM4C,EACJ5C,EAAK,YAAY,IAAI6C,GAAQC,EAAmB,KAAMD,CAAI,CAAC,EAC3DE,EAAezB,CAAO,CACxB,EACA,WAAYtB,EAAK,SAAW,IAAW,KAAK,QAAQ,gBAAgB,EACpE,WAAY,KAAK,QAAQ,gBAAgB,EACzC,QAASb,CACX,CAAC,EACD,OAAO6D,EAAWP,EAAM,OAAOC,EAAMC,CAAS,EAAGzB,EAAQlB,EAAK,QAAQ,CACxE,CACF",
6
+ "names": ["parseSegmentRow", "line", "cols", "anchored", "own", "segmentSamples", "segment", "tag", "t", "samples", "s", "parseEndpoint", "field", "parseLinkLine", "source", "target", "linkKey", "link", "anchoredCut", "under", "found", "window", "side", "segments", "links", "closingSpans", "held", "unread", "outside", "mergedSpans", "maxGap", "sorted", "a", "b", "compare", "spans", "span", "refName", "start", "end", "closingLinks", "inside", "GFA_TAG", "formatSegment", "id", "rank", "tags", "valid", "extra", "formatLink", "sourceStrand", "targetStrand", "formatSubgraph", "sortedSegments", "sortedLinks", "k", "offReference", "segments", "segment", "WALK_CONTEXT", "RgfaTabixAdapter", "BaseFeatureDataAdapter", "config", "getSubAdapter", "pluginManager", "under", "openTabixSlot", "walksLocation", "hasWalks", "links", "WalkReader", "PanSNRefNames", "opts", "header", "tier", "query", "signal", "statusCallback", "ObservableCreate", "observer", "tabixRefName", "start", "updateStatus", "getLines", "line", "anchored", "parseSegmentRow", "samples", "segmentSamples", "SimpleFeature", "region", "hops", "index", "addLinksOver", "refName", "end", "reached", "link", "parseLinkLine", "linkKey", "layout", "row", "found", "cut", "anchoredCut", "formatSubgraph", "frontier", "hop", "spans", "closingSpans", "span", "closingLinks", "walks", "graph", "kept", "fragments", "walkNameFilter", "lane", "resolvePanSNPrefix", "panSNHaplotype", "walkCutFor"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{b as O,c as D}from"./chunk-WSZ6RCMI.js";import{a as j}from"./chunk-P6FDUP52.js";import{a as C,b as $,e as T,f as _,h as q}from"./chunk-SYETHCAR.js";import{c as v,e as x,f as I}from"./chunk-X4NNWAXW.js";import{g as L}from"./chunk-R4DSKZ5P.js";import"./chunk-PR5YUSXN.js";import"./chunk-OGQ6OQDN.js";import"./chunk-YBLNN5FU.js";import{a as S,c as P,d as F,e as A,f as N,g as W}from"./chunk-XKN5LH2Z.js";import"./chunk-E7J6SB5P.js";import"./chunk-7WIBGKBU.js";import{o as R}from"./chunk-TENPGIPX.js";var Y=50;function Z(i){let e=[];for(let t=0;t<i.length;t++){let[r,s]=i[t],[a,n]=i[t+1]??[];s===n&&s<=Y&&(r==="I"&&a==="D"||r==="D"&&a==="I")?(e.push(["X",s]),t++):e.push([r,s])}return e}function ee(i){return i.map(([e,t])=>`${t}${e}`).join("")}function H(i){let e=new Map,t=a=>{let n=i.get(a),o=n===void 0?0:n.end-n.start,p=e.get(o);return p===void 0&&(p="N".repeat(o),e.set(o,p)),p},r=new Map,s=a=>{let n=r.get(a);return n===void 0&&(n=Array.from(a.ids,(o,p)=>2*o+a.rev[p]),r.set(a,n)),n};return(a,n)=>$({query:s(a),target:s(n),sequenceOf:t,bases:!1})}var te=100;function E(i,e,t){let r=i.at(-1);t>0&&(r?.[0]===e?r[1]+=t:i.push([e,t]))}function X(i){let e=s=>{let a=i.get(s>>1);return a===void 0?0:a.end-a.start},t=s=>{let a=new Float64Array(s.length+1);return s.forEach((n,o)=>{a[o+1]=a[o]+e(n)}),a},r=s=>Array.from(s.ids,(a,n)=>2*a+s.rev[n]);return(s,a)=>{let n=r(a),o=r(s),[p,g]=C(o,n,e),[f,l]=C(o.map(b=>b^1).reverse(),n,e),u=l>g,c=u?f:p,d=Math.max(g,l);if(d<te)return[];let h=t(n),m=t(o),y=b=>u?o.length-1-c[b][0]:c[b][0],w=[];c.forEach(([,b],k)=>{if(k>0){let[U,J]=[y(k-1),y(k)].sort((Q,V)=>Q-V);E(w,"I",m[J]-m[U+1]),E(w,"D",h[b]-h[c[k-1][1]+1])}E(w,"=",e(n[b]))});let[z,K]=[y(0),y(c.length-1)].sort((b,k)=>b-k);return[{queryStart:m[z],queryEnd:m[K+1],targetStart:h[c[0][1]],targetEnd:h[c.at(-1)[1]+1],strand:u?"-":"+",edits:w,sharedBases:d}]}}function M({chain:i,target:e,query:t,assemblyName:r,refName:s,mateAssemblyName:a}){let n=e.hapStart+i.targetStart,o=e.hapStart+i.targetEnd,p=t.hapStart+i.queryStart,g=t.hapStart+i.queryEnd,f=Z(i.edits),l=f.reduce((d,[h,m])=>d+(h==="="?m:0),0),u=f.reduce((d,[,h])=>d+h,0),c=`${e.name}:${n}-${o}|${t.name}:${p}-${g}`;return new T({uniqueId:c,assemblyName:r,refName:s,start:n,end:o,type:"match",strand:i.strand==="-"?-1:1,CIGAR:ee(f),syntenyId:c,identity:l/Math.max(u,1),numMatches:l,blockLen:u,mate:{refName:F(t.name),start:p,end:g,assemblyName:a}})}var ae=1e3;function G(i,e){return i[e]??i[S(e)]??e}var ne=i=>P(i.name)??i.name,B=class extends _{constructor(e,t,r){super(e,t,r);let s=x(this,["nodesLocation"],["nodesIndex"]);this.reader=new D({walks:x(this,["walksLocation"],["walksIndex"]),nodes:s,links:x(this,["linksLocation"],["linksIndex"])},this.getConf("walkChunk")),this.refNames=new I(s,this)}get anchor(){let e=this.getConf("assemblyNames")[0];if(e===void 0)throw new Error("WalkTabixSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");return e}async getHaplotypeNames(e={}){let{haplotypes:t}=await this.reader.header(e);return t.length>0?t:void 0}async getHeader(e={}){let{haplotypes:t,references:r}=await this.reader.header(e),{anchor:s}=this,a=N(this,s),n=W(this);return{hasCoarseTier:!1,anchorAssemblyName:s,referenceSamples:r,lanes:t.filter(o=>o!==a&&S(o)!==a).map(o=>({name:G(n,o),label:o,group:S(o)}))}}async getRefNames(e={}){let{assemblyName:t}=e;return t===void 0||t===this.anchor?this.refNames.assemblyRefNames({...e,assemblyName:this.anchor}):[]}budgets(e){return{stepBudget:e?1/0:this.getConf("walkStepBudget"),byteBudget:this.getConf("walkByteBudget"),context:ae}}async getSubgraph(e,t={}){let{signal:r,haplotypes:s,walkRows:a}=t,n=await this.refNames.resolve(e,{signal:r});if(n===void 0)throw new Error(`${e.assemblyName} ${e.refName} is not in this graph's index; the graph is cut on ${this.anchor}, mapped to its PanSN prefix in assemblyNameToPanSN`);let{graph:o,kept:p,fragments:g}=await this.reader.cut(n,e,{...this.budgets(a),signal:r,keep:O(s?.map(f=>N(this,f)),P(n))});return j(o.tables(p,g),e,a)}async laneWalks(e,t,r,s,a){return R(a,s.statusCallback,()=>this.reader.cut(e,t,{...this.budgets(),signal:s.signal,keep:O(r,P(e)),links:!1}).catch(n=>{throw n instanceof L&&(n.message=n.message.replace("to see the graph","to see lanes")),n}))}async anchorFeatures(e,t,r){let s=r.haplotypes?.length?r.haplotypes.map(m=>N(this,m)):void 0,a=N(this,r.targetAssemblyName),n=a===void 0?s:s===void 0||s.some(m=>A(a,m)||A(m,a))?[a]:[];if(n?.length===0)return[];let{start:o,end:p}=t,{graph:g,fragments:f}=await this.laneWalks(e,t,n,r,`Reading walks ${t.refName}:${o.toLocaleString()}-${p.toLocaleString()}`),l=X(g.nodes),u=W(this),c=f.filter(m=>m.name===e),d=m=>n===void 0?0:n.findIndex(y=>A(m.name,y));return f.filter(m=>m.name!==e&&d(m)>=0).sort((m,y)=>d(m)-d(y)).flatMap(m=>c.flatMap(y=>l(m,y).map(w=>M({chain:w,target:y,query:m,assemblyName:t.assemblyName,refName:t.refName,mateAssemblyName:G(u,ne(m))}))))}async pairFeatures(e,t,r,s){let[a]=r,n=r.map(l=>({pair:l,featurePrefix:N(this,l.queryAssemblyName),matePrefix:N(this,l.targetAssemblyName)})),{graph:o,fragments:p}=await this.laneWalks(e,t,n.flatMap(l=>[l.featurePrefix,l.matePrefix]),s,r.length===1&&a?`Reading ${a.queryAssemblyName} against ${a.targetAssemblyName}`:`Reading ${r.length} lane pairs`),g=H(o.nodes),f=l=>p.filter(u=>A(u.name,l));return n.flatMap(({pair:l,featurePrefix:u,matePrefix:c})=>f(u).flatMap(d=>f(c).flatMap(h=>g(h,d).map(m=>M({chain:m,target:d,query:h,assemblyName:l.queryAssemblyName,refName:F(d.name),mateAssemblyName:l.targetAssemblyName})))))}getFeatures(e,t={}){return v(async r=>{let s=e.assemblyName===this.anchor?await this.refNames.resolve(e,t):void 0;if(s!==void 0){let a=q(t),n=a.length>0?await this.pairFeatures(s,e,a,t):await this.anchorFeatures(s,e,t);for(let o of n)r.next(o)}r.complete()},t.signal)}};export{B as default,G as laneOf};
2
+ //# sourceMappingURL=WalkTabixSyntenyAdapter-Q5Q5XS4C.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/WalkTabixSyntenyAdapter/walkLanes.ts", "../../src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts"],
4
+ "sourcesContent": ["import { pairAlignments, weightedLcs } from '@gmod/gbz-base'\nimport { panSNContig } from '@jbrowse/bandage-core/pansn'\n\nimport SyntenyFeature from '../synteny/SyntenyFeature.ts'\n\nimport type { WalkFragment, WalkNode } from '../RgfaTabixAdapter/walkRows.ts'\nimport type { PairChain, PairEdit } from '@gmod/gbz-base'\n\n// The longest bubble with equal bases on both sides that is written as\n// mismatches; a longer one stays an insertion and a deletion\nconst BALANCED_BUBBLE_MAX_BP = 50\n\n/**\n * A chain's edits with each short balanced bubble as `X`. The walks carry no\n * bases, so two walks differ wherever they leave a shared node, and a SNP is\n * one base inserted and one deleted until it is read as the mismatch it is.\n */\nexport function bubblesAsMismatches(edits: PairEdit[]) {\n const out: PairEdit[] = []\n for (let i = 0; i < edits.length; i++) {\n const [op, len] = edits[i]!\n const [nextOp, nextLen] = edits[i + 1] ?? []\n if (\n len === nextLen &&\n len <= BALANCED_BUBBLE_MAX_BP &&\n ((op === 'I' && nextOp === 'D') || (op === 'D' && nextOp === 'I'))\n ) {\n out.push(['X', len])\n i++\n } else {\n out.push([op, len])\n }\n }\n return out\n}\n\nfunction cigarOf(edits: PairEdit[]) {\n return edits.map(([op, len]) => `${len}${op}`).join('')\n}\n\n/**\n * Aligns one walk fragment to another on the nodes both visit, from node\n * lengths alone: the fragments' steps as the handles gbz-base's chainer reads,\n * and a stand-in sequence of each node's length.\n */\nexport function walkAligner(nodes: Map<number, WalkNode>) {\n const standIn = new Map<number, string>()\n const sequenceOf = (id: number) => {\n const node = nodes.get(id)\n const length = node === undefined ? 0 : node.end - node.start\n let sequence = standIn.get(length)\n if (sequence === undefined) {\n sequence = 'N'.repeat(length)\n standIn.set(length, sequence)\n }\n return sequence\n }\n const handles = new Map<WalkFragment, number[]>()\n const handlesOf = (fragment: WalkFragment) => {\n let steps = handles.get(fragment)\n if (steps === undefined) {\n steps = Array.from(fragment.ids, (id, i) => 2 * id + fragment.rev[i]!)\n handles.set(fragment, steps)\n }\n return steps\n }\n return (query: WalkFragment, target: WalkFragment) =>\n pairAlignments({\n query: handlesOf(query),\n target: handlesOf(target),\n sequenceOf,\n bases: false,\n })\n}\n\n// The fewest bases on shared nodes a record against the reference keeps,\n// gbz-base's floor for a pair record\nconst MIN_MATCH_BP = 100\n\nfunction appendEdit(edits: PairEdit[], op: PairEdit[0], len: number) {\n const last = edits.at(-1)\n if (len > 0) {\n if (last?.[0] === op) {\n last[1] += len\n } else {\n edits.push([op, len])\n }\n }\n}\n\n/**\n * Aligns a haplotype's walk fragment to the reference's as gbz-base aligns a\n * walk to its reference path: the heaviest common subsequence of their steps,\n * each node weighing its length, read in whichever direction shares more. A\n * pair chain leaves out every node either walk passes twice, which is the\n * whole of a collapsed copy-number array (amylase, KIV-2); the subsequence\n * matches one pass over it, and the other copies are insertions.\n */\nexport function referenceAligner(nodes: Map<number, WalkNode>) {\n const lengthOf = (handle: number) => {\n const node = nodes.get(handle >> 1)\n return node === undefined ? 0 : node.end - node.start\n }\n const offsets = (handles: number[]) => {\n const out = new Float64Array(handles.length + 1)\n handles.forEach((handle, i) => {\n out[i + 1] = out[i]! + lengthOf(handle)\n })\n return out\n }\n const handlesOf = (fragment: WalkFragment) =>\n Array.from(fragment.ids, (id, i) => 2 * id + fragment.rev[i]!)\n\n return (query: WalkFragment, target: WalkFragment): PairChain[] => {\n const ref = handlesOf(target)\n const hap = handlesOf(query)\n const [same, sameWeight] = weightedLcs(hap, ref, lengthOf)\n const [turned, turnedWeight] = weightedLcs(\n hap.map(handle => handle ^ 1).reverse(),\n ref,\n lengthOf,\n )\n const reverse = turnedWeight > sameWeight\n const pairs = reverse ? turned : same\n const sharedBases = Math.max(sameWeight, turnedWeight)\n if (sharedBases < MIN_MATCH_BP) {\n return []\n }\n const refAt = offsets(ref)\n const hapAt = offsets(hap)\n // a pair's haplotype step, counted along the haplotype\n const stepOf = (k: number) =>\n reverse ? hap.length - 1 - pairs[k]![0] : pairs[k]![0]\n const edits: PairEdit[] = []\n pairs.forEach(([, r], k) => {\n if (k > 0) {\n const [lo, hi] = [stepOf(k - 1), stepOf(k)].sort((x, y) => x - y)\n appendEdit(edits, 'I', hapAt[hi!]! - hapAt[lo! + 1]!)\n appendEdit(edits, 'D', refAt[r]! - refAt[pairs[k - 1]![1] + 1]!)\n }\n appendEdit(edits, '=', lengthOf(ref[r]!))\n })\n const [lo, hi] = [stepOf(0), stepOf(pairs.length - 1)].sort((x, y) => x - y)\n return [\n {\n queryStart: hapAt[lo!]!,\n queryEnd: hapAt[hi! + 1]!,\n targetStart: refAt[pairs[0]![1]]!,\n targetEnd: refAt[pairs.at(-1)![1] + 1]!,\n strand: reverse ? '-' : '+',\n edits,\n sharedBases,\n },\n ]\n }\n}\n\n/**\n * One record of a walk aligned to another: on the target walk's contig, with\n * the query walk as its mate and the CIGAR read along the target, a `D` being\n * target bases the query lacks.\n */\nexport function chainFeature({\n chain,\n target,\n query,\n assemblyName,\n refName,\n mateAssemblyName,\n}: {\n chain: PairChain\n target: WalkFragment\n query: WalkFragment\n assemblyName: string\n refName: string\n mateAssemblyName: string\n}) {\n const start = target.hapStart + chain.targetStart\n const end = target.hapStart + chain.targetEnd\n const mateStart = query.hapStart + chain.queryStart\n const mateEnd = query.hapStart + chain.queryEnd\n const edits = bubblesAsMismatches(chain.edits)\n const matches = edits.reduce((sum, [op, n]) => sum + (op === '=' ? n : 0), 0)\n const columns = edits.reduce((sum, [, n]) => sum + n, 0)\n const id = `${target.name}:${start}-${end}|${query.name}:${mateStart}-${mateEnd}`\n return new SyntenyFeature({\n uniqueId: id,\n assemblyName,\n refName,\n start,\n end,\n type: 'match',\n strand: chain.strand === '-' ? -1 : 1,\n CIGAR: cigarOf(edits),\n syntenyId: id,\n identity: matches / Math.max(columns, 1),\n numMatches: matches,\n blockLen: columns,\n mate: {\n refName: panSNContig(query.name),\n start: mateStart,\n end: mateEnd,\n assemblyName: mateAssemblyName,\n },\n })\n}\n", "import { NodeLimitError } from '@jbrowse/bandage-core/gbzWindow'\nimport {\n assemblyByPanSNPrefix,\n panSNContig,\n panSNHaplotype,\n panSNMatchesPrefix,\n panSNSample,\n resolvePanSNPrefix,\n} from '@jbrowse/bandage-core/pansn'\nimport { updateStatus } from '@jbrowse/core/util'\nimport { ObservableCreate } from '@jbrowse/core/util/rxjs'\n\nimport { chainFeature, referenceAligner, walkAligner } from './walkLanes.ts'\nimport { WalkReader } from '../RgfaTabixAdapter/walkReader.ts'\nimport { walkCutFor } from '../RgfaTabixAdapter/walkRowRuns.ts'\nimport { walkNameFilter } from '../RgfaTabixAdapter/walkRows.ts'\nimport { PanSNRefNames, openTabixSlot } from '../panSNTabix.ts'\nimport { ComparativeAdapterBase } from '../synteny/ComparativeAdapterBase.ts'\nimport { requestedPairs } from '../synteny/lanePairs.ts'\n\nimport type { WalkTabixSyntenyAdapterConfig } from './configSchema.ts'\nimport type { SubgraphAdapterOptions } from '../GetSubgraph.ts'\nimport type { WalkFragment } from '../RgfaTabixAdapter/walkRows.ts'\nimport type { LaneFeatureOptions, LanePair } from '../synteny/lanePairs.ts'\nimport type PluginManager from '@jbrowse/core/PluginManager'\nimport type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'\nimport type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'\nimport type { Feature } from '@jbrowse/core/util'\nimport type { Region } from '@jbrowse/core/util/types'\n\n// How much graph a cut keeps around the window, on the reference\nconst WALK_CONTEXT = 1000\n\n/**\n * The lane a haplotype draws on: the JBrowse assembly the config maps to it at\n * haplotype or sample depth, else its own PanSN prefix\n */\nexport function laneOf(asmByPrefix: Record<string, string>, prefix: string) {\n return asmByPrefix[prefix] ?? asmByPrefix[panSNSample(prefix)] ?? prefix\n}\n\nconst haplotypeOf = (fragment: WalkFragment) =>\n panSNHaplotype(fragment.name) ?? fragment.name\n\nexport default class WalkTabixSyntenyAdapter extends ComparativeAdapterBase<WalkTabixSyntenyAdapterConfig> {\n private readonly reader\n private readonly refNames\n\n public constructor(\n config: WalkTabixSyntenyAdapterConfig,\n getSubAdapter?: getSubAdapterType,\n pluginManager?: PluginManager,\n ) {\n super(config, getSubAdapter, pluginManager)\n const nodes = openTabixSlot(this, ['nodesLocation'], ['nodesIndex'])\n this.reader = new WalkReader(\n {\n walks: openTabixSlot(this, ['walksLocation'], ['walksIndex']),\n nodes,\n links: openTabixSlot(this, ['linksLocation'], ['linksIndex']),\n },\n this.getConf('walkChunk'),\n )\n this.refNames = new PanSNRefNames(nodes, this)\n }\n\n private get anchor() {\n const anchor = this.getConf('assemblyNames')[0]\n if (anchor === undefined) {\n throw new Error(\n 'WalkTabixSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as',\n )\n }\n return anchor\n }\n\n /**\n * The haplotypes the walk file's header names, `sample#haplotype` in byte\n * order, or undefined when it names none\n */\n async getHaplotypeNames(opts: BaseOptions = {}) {\n const { haplotypes } = await this.reader.header(opts)\n return haplotypes.length > 0 ? haplotypes : undefined\n }\n\n /**\n * `lanes` is every haplotype the header names but the anchor's own,\n * declared up front so the display can offer the whole graph's haplotypes\n * before a fetch has placed any of them\n */\n async getHeader(opts: BaseOptions = {}) {\n const { haplotypes, references } = await this.reader.header(opts)\n const { anchor } = this\n const anchorPrefix = resolvePanSNPrefix(this, anchor)\n const asmByPrefix = assemblyByPanSNPrefix(this)\n return {\n hasCoarseTier: false,\n anchorAssemblyName: anchor,\n referenceSamples: references,\n lanes: haplotypes\n .filter(\n prefix =>\n prefix !== anchorPrefix && panSNSample(prefix) !== anchorPrefix,\n )\n .map(prefix => ({\n name: laneOf(asmByPrefix, prefix),\n label: prefix,\n group: panSNSample(prefix),\n })),\n }\n }\n\n // A lane's contigs are named only in its walk rows, so only the anchor's\n // are listed\n async getRefNames(opts: BaseOptions = {}) {\n const { assemblyName } = opts\n return assemblyName === undefined || assemblyName === this.anchor\n ? this.refNames.assemblyRefNames({ ...opts, assemblyName: this.anchor })\n : []\n }\n\n private budgets(walkRows?: boolean) {\n return {\n stepBudget: walkRows ? Infinity : this.getConf('walkStepBudget'),\n byteBudget: this.getConf('walkByteBudget'),\n context: WALK_CONTEXT,\n }\n }\n\n /**\n * The graph display's cut of the window, as RgfaTabixAdapter cuts a\n * walk-indexed graph: the reference walk first, then the walks `haplotypes`\n * asks for, and the nodes and links they visit\n */\n async getSubgraph(region: Region, opts: SubgraphAdapterOptions = {}) {\n const { signal, haplotypes, walkRows } = opts\n const refName = await this.refNames.resolve(region, { signal })\n if (refName === undefined) {\n throw new Error(\n `${region.assemblyName} ${region.refName} is not in this graph's index; the graph is cut on ${this.anchor}, mapped to its PanSN prefix in assemblyNameToPanSN`,\n )\n }\n const { graph, kept, fragments } = await this.reader.cut(refName, region, {\n ...this.budgets(walkRows),\n signal,\n keep: walkNameFilter(\n haplotypes?.map(lane => resolvePanSNPrefix(this, lane)),\n panSNHaplotype(refName),\n ),\n })\n return walkCutFor(graph.tables(kept, fragments), region, walkRows)\n }\n\n // The window's walks for the haplotypes named and the reference, with no\n // link read; a window past a budget fails as a zoom-in notice for lanes\n private async laneWalks(\n refName: string,\n region: Region,\n prefixes: string[] | undefined,\n opts: LaneFeatureOptions,\n status: string,\n ) {\n return updateStatus(status, opts.statusCallback, () =>\n this.reader\n .cut(refName, region, {\n ...this.budgets(),\n signal: opts.signal,\n keep: walkNameFilter(prefixes, panSNHaplotype(refName)),\n links: false,\n })\n .catch((error: unknown) => {\n if (error instanceof NodeLimitError) {\n error.message = error.message.replace(\n 'to see the graph',\n 'to see lanes',\n )\n }\n throw error\n }),\n )\n }\n\n /**\n * One record per stretch a haplotype's walk shares with the reference's,\n * on the reference with the haplotype as its mate\n */\n private async anchorFeatures(\n refName: string,\n region: Region,\n opts: LaneFeatureOptions,\n ) {\n const wanted = opts.haplotypes?.length\n ? opts.haplotypes.map(lane => resolvePanSNPrefix(this, lane))\n : undefined\n const target = resolvePanSNPrefix(this, opts.targetAssemblyName)\n const prefixes =\n target === undefined\n ? wanted\n : wanted === undefined ||\n wanted.some(\n prefix =>\n panSNMatchesPrefix(target, prefix) ||\n panSNMatchesPrefix(prefix, target),\n )\n ? [target]\n : []\n if (prefixes?.length === 0) {\n return []\n }\n const { start, end } = region\n const { graph, fragments } = await this.laneWalks(\n refName,\n region,\n prefixes,\n opts,\n `Reading walks ${region.refName}:${start.toLocaleString()}-${end.toLocaleString()}`,\n )\n const align = referenceAligner(graph.nodes)\n const asmByPrefix = assemblyByPanSNPrefix(this)\n const references = fragments.filter(f => f.name === refName)\n // lanes come back in the order the fetch names them, which is the order\n // the display stacks lanes of equal weight in\n const rank = (fragment: WalkFragment) =>\n prefixes === undefined\n ? 0\n : prefixes.findIndex(prefix =>\n panSNMatchesPrefix(fragment.name, prefix),\n )\n const shown = fragments\n .filter(fragment => fragment.name !== refName && rank(fragment) >= 0)\n .sort((a, b) => rank(a) - rank(b))\n return shown.flatMap(query =>\n references.flatMap(reference =>\n align(query, reference).map(chain =>\n chainFeature({\n chain,\n target: reference,\n query,\n assemblyName: region.assemblyName,\n refName: region.refName,\n mateAssemblyName: laneOf(asmByPrefix, haplotypeOf(query)),\n }),\n ),\n ),\n )\n }\n\n /**\n * Each pair's two lanes read out of the anchor window, all pairs in one\n * read, and each walk of a pair's query lane aligned to each walk of its\n * target lane. A pair's records sit on its query lane's contigs, the lane\n * the display draws on top.\n */\n private async pairFeatures(\n refName: string,\n region: Region,\n pairs: LanePair[],\n opts: LaneFeatureOptions,\n ) {\n const [first] = pairs\n const sides = pairs.map(pair => ({\n pair,\n featurePrefix: resolvePanSNPrefix(this, pair.queryAssemblyName),\n matePrefix: resolvePanSNPrefix(this, pair.targetAssemblyName),\n }))\n const { graph, fragments } = await this.laneWalks(\n refName,\n region,\n sides.flatMap(side => [side.featurePrefix, side.matePrefix]),\n opts,\n pairs.length === 1 && first\n ? `Reading ${first.queryAssemblyName} against ${first.targetAssemblyName}`\n : `Reading ${pairs.length} lane pairs`,\n )\n const align = walkAligner(graph.nodes)\n const walksOf = (prefix: string) =>\n fragments.filter(f => panSNMatchesPrefix(f.name, prefix))\n return sides.flatMap(({ pair, featurePrefix, matePrefix }) =>\n walksOf(featurePrefix).flatMap(target =>\n walksOf(matePrefix).flatMap(query =>\n align(query, target).map(chain =>\n chainFeature({\n chain,\n target,\n query,\n assemblyName: pair.queryAssemblyName,\n refName: panSNContig(target.name),\n mateAssemblyName: pair.targetAssemblyName,\n }),\n ),\n ),\n ),\n )\n }\n\n // The files are filed under the reference alone, so a window on a\n // haplotype lane has no answer: a lane pair is read inside the anchor's\n getFeatures(region: Region, opts: LaneFeatureOptions = {}) {\n return ObservableCreate<Feature>(async observer => {\n const refName =\n region.assemblyName === this.anchor\n ? await this.refNames.resolve(region, opts)\n : undefined\n if (refName !== undefined) {\n const pairs = requestedPairs(opts)\n const features =\n pairs.length > 0\n ? await this.pairFeatures(refName, region, pairs, opts)\n : await this.anchorFeatures(refName, region, opts)\n for (const feature of features) {\n observer.next(feature)\n }\n }\n observer.complete()\n }, opts.signal)\n }\n}\n"],
5
+ "mappings": "wfAUA,IAAMA,EAAyB,GAOxB,SAASC,EAAoBC,EAAmB,CACrD,IAAMC,EAAkB,CAAC,EACzB,QAASC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAAK,CACrC,GAAM,CAACC,EAAIC,CAAG,EAAIJ,EAAME,CAAC,EACnB,CAACG,EAAQC,CAAO,EAAIN,EAAME,EAAI,CAAC,GAAK,CAAC,EAEzCE,IAAQE,GACRF,GAAON,IACLK,IAAO,KAAOE,IAAW,KAASF,IAAO,KAAOE,IAAW,MAE7DJ,EAAI,KAAK,CAAC,IAAKG,CAAG,CAAC,EACnBF,KAEAD,EAAI,KAAK,CAACE,EAAIC,CAAG,CAAC,CAEtB,CACA,OAAOH,CACT,CAEA,SAASM,GAAQP,EAAmB,CAClC,OAAOA,EAAM,IAAI,CAAC,CAACG,EAAIC,CAAG,IAAM,GAAGA,CAAG,GAAGD,CAAE,EAAE,EAAE,KAAK,EAAE,CACxD,CAOO,SAASK,EAAYC,EAA8B,CACxD,IAAMC,EAAU,IAAI,IACdC,EAAcC,GAAe,CACjC,IAAMC,EAAOJ,EAAM,IAAIG,CAAE,EACnBE,EAASD,IAAS,OAAY,EAAIA,EAAK,IAAMA,EAAK,MACpDE,EAAWL,EAAQ,IAAII,CAAM,EACjC,OAAIC,IAAa,SACfA,EAAW,IAAI,OAAOD,CAAM,EAC5BJ,EAAQ,IAAII,EAAQC,CAAQ,GAEvBA,CACT,EACMC,EAAU,IAAI,IACdC,EAAaC,GAA2B,CAC5C,IAAIC,EAAQH,EAAQ,IAAIE,CAAQ,EAChC,OAAIC,IAAU,S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AI,EACrD,QAAWmD,KAAWD,EACpBF,EAAS,KAAKG,CAAO,CAEzB,CACAH,EAAS,SAAS,CACpB,EAAGhD,EAAK,MAAM,CAChB,CACF",
6
+ "names": ["BALANCED_BUBBLE_MAX_BP", "bubblesAsMismatches", "edits", "out", "i", "op", "len", "nextOp", "nextLen", "cigarOf", "walkAligner", "nodes", "standIn", "sequenceOf", "id", "node", "length", "sequence", "handles", "handlesOf", "fragment", "steps", "query", "target", "pairAlignments", "MIN_MATCH_BP", "appendEdit", "last", "referenceAligner", "lengthOf", "handle", "offsets", "ref", "hap", "same", "sameWeight", "weightedLcs", "turned", "turnedWeight", "reverse", "pairs", "sharedBases", "refAt", "hapAt", "stepOf", "k", "r", "lo", "hi", "x", "y", "chainFeature", "chain", "assemblyName", "refName", "mateAssemblyName", "start", "end", "mateStart", "mateEnd", "matches", "sum", "n", "columns", "SyntenyFeature", "panSNContig", "WALK_CONTEXT", "laneOf", "asmByPrefix", "prefix", "panSNSample", "haplotypeOf", "fragment", "panSNHaplotype", "WalkTabixSyntenyAdapter", "ComparativeAdapterBase", "config", "getSubAdapter", "pluginManager", "nodes", "openTabixSlot", "WalkReader", "PanSNRefNames", "anchor", "opts", "haplotypes", "references", "anchorPrefix", "resolvePanSNPrefix", "assemblyByPanSNPrefix", "assemblyName", "walkRows", "region", "signal", "refName", "graph", "kept", "fragments", "walkNameFilter", "lane", "walkCutFor", "prefixes", "status", "updateStatus", "error", "NodeLimitError", "wanted", "target", "panSNMatchesPrefix", "start", "end", "align", "referenceAligner", "f", "rank", "a", "b", "query", "reference", "chain", "chainFeature", "pairs", "first", "sides", "pair", "side", "walkAligner", "walksOf", "featurePrefix", "matePrefix", "panSNContig", "ObservableCreate", "observer", "requestedPairs", "features", "feature"]
7
+ }
@@ -1,3 +1,3 @@
1
- import{a as Ge,b as $e,c as Ce,e as Xe,h as Qe,j as me,k as Me,l as tt,n as nt,o as ot}from"./chunk-LEWWQ7ZK.js";import{D as oe,J as at,M as it,S as ct,e as We,f as Ye,g as He,j as Je,p as et,u as st}from"./chunk-6AYSOQOK.js";import{a as Z}from"./chunk-BXZLLHYP.js";import{D as T,E as Ue,H as qe,P as Ke,Q as Ze,U as rt,b as Ve,f as O,q as Fe,r as De,u as je,v as ze}from"./chunk-AB2XVNNS.js";import{a as de,b as K,c as k,d as te,e as H,f as ve,g as V,j as ne}from"./chunk-PR5YUSXN.js";import{a as q,c as Be,d as fe}from"./chunk-XKN5LH2Z.js";import{h}from"./chunk-ELLLNUKS.js";import{b as ue}from"./chunk-6OPB7FOJ.js";import{b as A}from"./chunk-JMBDTNUR.js";var F=JBrowseExports["@mui/material/SvgIcon"],Kt=e=>F!=null&&e in Object(F)?F[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@mui/material/SvgIcon' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),I=Kt("createSvgIcon"),yo=F&&F.__esModule?F.default:F;function Ro(e){return K(e)?lt(e):void 0}function lt(e){return{sample:q(e.stable.refName),haplotype:Be(e.stable.refName),refName:fe(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Zt(e,t){let n=[...e].sort((o,a)=>o.start-a.start),s,r;for(let o of n)r=r&&o.start-r.end<=t?{start:r.start,end:Math.max(r.end,o.end)}:{start:o.start,end:o.end},(!s||r.end-r.start>s.end-s.start)&&(s=r);return s}function Jt(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ao(e,{maxGap:t=1/0}={}){let n=new Map;for(let r of e.nodes)if(K(r)){let o=lt(r),a=Jt(o),i=n.get(a);i?(i.spans.push({start:o.start,end:o.end}),i.rank=Math.min(i.rank,r.stable.rank)):n.set(a,{sample:o.sample,haplotype:o.haplotype,refName:o.refName,rank:r.stable.rank,spans:[{start:o.start,end:o.end}]})}let s=new Map;for(let r of n.values()){let o=Zt(r.spans,t);if(o){let a={sample:r.sample,haplotype:r.haplotype,refName:r.refName,start:o.start,end:o.end,rank:r.rank,nodeCount:r.spans.length},i=r.haplotype??r.sample,p=s.get(i);(!p||a.nodeCount>p.nodeCount)&&s.set(i,a)}}return[...s.values()].sort((r,o)=>+(r.rank!==0)-+(o.rank!==0)||r.sample.localeCompare(o.sample)||(r.haplotype??"").localeCompare(o.haplotype??""))}function Qt(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function Oo(e,t){return e.flatMap(n=>{let s=Qt(t,n);return s===void 0?[]:[{...n,sample:s}]})}function _o(e){return`${e.refName}:${e.start+1}-${e.end}`}function Se(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var pt=I(A("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var ft=I(A("path",{d:"M17 5h-2V3h2zm-2 16h2v-2.59L19.59 21 21 19.59 18.41 17H21v-2h-6zm4-12h2V7h-2zm0 4h2v-2h-2zm-8 8h2v-2h-2zM7 5h2V3H7zM3 17h2v-2H3zm2 4v-2H3c0 1.1.9 2 2 2M19 3v2h2c0-1.1-.9-2-2-2m-8 2h2V3h-2zM3 9h2V7H3zm4 12h2v-2H7zm-4-8h2v-2H3zm0-8h2V3c-1.1 0-2 .9-2 2"}),"HighlightAlt");var Le=I(A("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var en="Linear genome view",tn="Linear synteny view",nn="No synteny track in this session aligns these assemblies";function dt({label:e,icon:t,entries:n,entryLabel:s,onSelect:r,disabledHelpText:o,nameTheOnlyEntry:a=!0}){let[i]=n,p=o?[{label:e,icon:t,disabled:!0,disabledHelpText:o,onClick:()=>{}}]:[];return n.length===0?p:n.length===1&&i?[{label:a?`${e} \u2014 ${s(i)}`:e,icon:t,onClick:r(i)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(d=>({label:s(d),onClick:r(d)}))}]}function zo({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:s}){let r=t[0]?.coverage??e.length;return[...dt({label:en,icon:Le,entries:e,entryLabel:o=>`${o.sample} ${Se(o)}`,onSelect:o=>()=>{n({location:o,assembly:o.sample})}}),...e.length>=2?dt({label:`${tn} (${r} assemblies)`,icon:pt,entries:t,entryLabel:o=>o.coverage<r?`${o.name} (${o.coverage} of ${r})`:o.name,nameTheOnlyEntry:!1,disabledHelpText:nn,onSelect:o=>()=>{s(o.trackId)}}):[]]}function Uo({own:e,reference:t,highlight:n,onShowLinear:s,onHighlight:r}){let o=[e?{label:`Open in ${e.assembly} \u2014 ${Se(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...r&&n?[{label:`Highlight in ${n.assembly}`,icon:ft,onClick:()=>{r(n)}}]:[],...o.map(({label:a,target:i})=>({label:a,icon:Le,onClick:()=>{s(i)}}))]}function on(e){let t=new Map;for(let[n,s]of e.pathVisits??[])for(let r of s){let o=`${r.path} ${n}`,a=t.get(o);a?a.push(r.strand):t.set(o,[r.strand])}return t}function rn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=on(e),s=(e.paths??[]).map((o,a)=>({path:o,index:a})),r=s.findIndex(o=>T(o.path.name).name===e.referencePath);return r>0&&s.unshift(...s.splice(r,1)),s.flatMap(({path:o,index:a})=>{let i=T(o.name).name,p=new Map,d=o.nodeIds.flatMap(f=>{let c=t.get(f);if(!c)return[];let u=p.get(c.name)??0;p.set(c.name,u+1);let b=n.get(`${i} ${c.name}`)?.[u]??We(c);return[Ye(c,b)]});return d.length>0?[{id:a,name:o.name,sequence:d,sourceTrackID:0,type:"haplotype"}]:[]})}function sn(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function J(e){return(e.paths?.length??0)>0}var an=600,cn=3,ln=15;function pn(e){return Math.max(cn,Math.min(ln,Math.floor(an/Math.max(1,e))))}function ut(e){let t=e.paths??[],n=rn(e),s=e.reads?He(e,e.reads,t.length):[],r=s.length>0?Ze:Ke,o=t.map((i,p)=>r(p,t.length)),a=Je(sn(e),n,s,{nodeWidthOption:"compressed",trackWidth:pn(n.length)});return a?{layout:a,pathColors:o}:void 0}function ke(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function mt(e,t,n,s){let r=e.y+e.contentHeight/2-t;return[{x:n,y:r},{x:s,y:r}]}function ht(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function bt(e){let t=J(e)?ut(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,r=n.bounds.minY,o={};for(let p of ke(n))o[p.name]=mt(p,r,p.x,p.x+p.pixelWidth);let{minY:a,maxY:i}=ht(n,r);return{nodePositions:o,tubeMap:{layout:n,yOffset:r,pathColors:s},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:i}}}function fn(e,t){let n=new Map(e.nodes.map(i=>[i.id,i])),s=new Map;for(let i of ke(t)){let p=s.get(i.order);p?p.push(i):s.set(i.order,[i])}let r=[],o=-1/0;for(let i of[...s.keys()].sort((p,d)=>p-d)){let p=s.get(i),d=1/0,f=-1/0;for(let c of p){let u=n.get(c.name);u&&k(u)&&(d=Math.min(d,u.stable.start),f=Math.max(f,u.stable.start+c.sequenceLength))}d===1/0&&(d=f=o),d<o&&(d=o,f=Math.max(o,f)),o=Math.max(o,f),r.push({order:i,x0:Math.min(...p.map(c=>c.x)),x1:Math.max(...p.map(c=>c.x+c.pixelWidth)),bp0:d,bp1:f})}let a=r.find(i=>i.bp0!==-1/0);for(let i of r)i.bp0===-1/0&&(i.bp0=i.bp1=a?.bp0??0);return r}function dn(e){return e.nodes.some(k)&&J(e)}function gt(e){let t=dn(e)?ut(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,r=fn(e,n),o=new Map(r.map(p=>[p.order,p])),a=n.bounds.minY,i={};for(let p of ke(n)){let d=o.get(p.order);i[p.name]=mt(p,a,d.bp0,d.bp1)}return{nodePositions:i,tubeMap:{layout:n,yOffset:a,columns:r,pathColors:s},referenceAxis:!0,pixelRows:!0,extent:ht(n,a)}}function he(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function un(e,t,n,s){let r=[],o=[],a=[e];for(s.add(e);a.length>0;){let i=a.pop(),p=t.get(i);if(p){r.push(p);for(let d of n.get(i)??[]){let f=t.get(d);f&&(f.stable.rank===de?o.push(f):s.has(d)||(s.add(d),a.push(d)))}}}return{members:r,anchors:o}}function mn(e){if(new Set(e.map(i=>i.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((i,p)=>i.stable.start-p.stable.start),s=n[0],r=n.at(-1),o=s.stable.start+s.length,a=r.stable.start;return a>=o?{start:o,end:a,entry:s}:void 0}function hn(e,t,n){let s=new Map(e.map(a=>[a.id,a])),r=new Map,o=[];for(let a of n.get(t.id)??[])s.has(a)&&(r.set(a,0),o.push(a));if(o.length===0)for(let a of e)r.set(a.id,0),o.push(a.id);for(let a of o){let i=r.get(a)+s.get(a).length;for(let p of n.get(a)??[])if(s.has(p)){let d=r.get(p);(d===void 0||i<d)&&(r.set(p,i),o.push(p))}}return r}function bn(e,t,n){let s=hn(e,t,n),r=[...e].sort((p,d)=>s.get(p.id)-s.get(d.id)),o=new Map(r.map((p,d)=>[p.id,d])),a=new Map(e.map(p=>[p.id,p])),i=new Map;for(let[p,d]of r.entries()){let f=0;for(let c of n.get(d.id)??[]){let u=a.get(c);u&&o.get(c)<p&&(f=Math.max(f,i.get(c)+u.length))}i.set(d.id,f)}return{offsets:i,ordered:r}}function wt(e){let t=new Map(e.nodes.filter(K).map(o=>[o.id,o])),n=Z(e),s=new Set,r=[];for(let o of t.values())if(o.stable.rank!==de&&!s.has(o.id)){let{members:a,anchors:i}=un(o.id,t,n,s),p=mn(i);if(p){let{offsets:d,ordered:f}=bn(a,p.entry,n);r.push({start:p.start,refSpan:p.end-p.start,nodeIds:f.map(c=>c.id),nodeOffsets:f.map(c=>d.get(c.id)),pathLength:f.reduce((c,u)=>Math.max(c,d.get(u.id)+u.length),0)})}}return r.sort((o,a)=>o.start-a.start)}var gn=1,wn=.015;function be({graph:e,span:t,rowY:n,positions:s}){let r=t*wn,o=wt(e),a=new Map(e.nodes.map(f=>[f.id,f])),i=[];for(let f of o){let c=f.refSpan-f.pathLength;c>=gn&&i.push({nodeIds:f.nodeIds,bp:c});let u=Math.max(f.refSpan,r),b=f.pathLength>0?u/f.pathLength:0;f.nodeIds.forEach((w,x)=>{let l=a.get(w);if(l){let m=f.nodeOffsets[x],y=u/f.nodeIds.length,L=B=>f.start+B*b,R=n(l);s[w]=b?[{x:L(m),y:R},{x:L(m+l.length),y:R}]:[{x:f.start+x*y,y:R},{x:f.start+(x+1)*y,y:R}]}})}let p=Z(e),d=Object.keys(s);for(let f of d){let c=s[f].at(-1).x;for(let u of p.get(f)??[]){let b=a.get(u);if(b&&!(u in s)){let w=n(b);s[u]=[{x:c,y:w},{x:c+r,y:w}],d.push(u)}}}return i}function yn(e,t){let n=new Map;for(let r of e.nodes)if(te(r)){let{sample:o}=he(r.stable.refName);n.set(o,(n.get(o)??0)+r.length)}let s=new Map(t.map((r,o)=>[r,o]));return[...n.keys()].sort((r,o)=>(s.get(r)??1/0)-(s.get(o)??1/0)||n.get(o)-n.get(r)||r.localeCompare(o))}function yt(e,t,n=[]){let s=H(e),r=yn(e,n);if(s.length===0||r.length===0)return;let o=ne(s,t),a=new Map(r.map((u,b)=>[u,b+1])),i=V(s),p=r.length+1,d=be({graph:e,span:o,rowY:u=>{let b=u.stable;return((b?a.get(he(b.refName).sample):void 0)??p)*O},positions:i}),c=[{label:he(s[0].stable.refName).sample,y:0},...r.map(u=>({label:u,y:a.get(u)*O}))];return{nodePositions:i,rowLabels:c,sampleRows:r,referenceAxis:!0,pixelRows:!0,alleleDeletions:d}}function xn(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,s)=>n-s).map((n,s)=>[n,s]))}function xt(e,t){let n=H(e);if(n.length===0)return;let s=ne(n,t),r=xn(e),o=V(n),a=be({graph:e,span:s,rowY:p=>(p.stable?r.get(p.stable.rank)??r.size:r.size)*O,positions:o}),i=[...r].map(([p,d])=>({label:p===0?"Reference (rank 0)":`Rank ${p}`,y:d*O}));return{nodePositions:o,rowLabels:i,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var vn=12,Ne=O;function vt(e){return 10+8*Math.log2(1+e.length)}function C(e,t){return e<t?-1:e>t?1:0}function St(e,t){return C(e.at,t.at)||C(e.side,t.side)||C(e.hops,t.hops)}var Mt={at:1/0,side:0,hops:0};function Mn(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=kn(e);return e.nodes.map(s=>s.id).sort((s,r)=>St(n.get(s)??Mt,n.get(r)??Mt)||C(t.get(s).name,t.get(r).name)||C(s,r))}function Sn(e,t){let n=new Set(e.nodes.map(f=>f.id)),s=new Map(t.map(f=>[f.id,f.stable.start])),r=new Map,o=new Map;t.forEach((f,c)=>{o.set(f.id,t[c-1]?.id),r.set(f.id,t[c+1]?.id)});let a=t[0]?.id,i=(f,c)=>{let u=r.get(f);r.set(f,c),o.set(c,f),r.set(c,u),u!==void 0&&o.set(u,c)},p=(f,c)=>{let u=o.get(f);u===void 0?(a=c,o.set(c,void 0),r.set(c,f),o.set(f,c)):i(u,c)};for(let f of e.paths??[]){let c=0,u=0,b;for(let m of f.nodeIds){let y=s.get(m);y!==void 0&&(b!==void 0&&y!==b&&(y>b?c++:u++),b=y)}let w=u>c?[...f.nodeIds].reverse():f.nodeIds,x,l=new Set;for(let m of w)if(r.has(m)){if(x===void 0)for(let y of l)p(m,y);x=m}else n.has(m)&&(x===void 0?l.add(m):(i(x,m),x=m))}let d=[];for(let f=a;f!==void 0;f=r.get(f))d.push(f);return d}function Ln(e,t){let n=[...t.entries()].sort(([a,i],[p,d])=>St(i,d)||C(a,p)).map(([a])=>a),s=n.length;for(let a of n){let i=t.get(a);for(let p of e.get(a)??[])t.has(p)||(t.set(p,{at:i.at,side:1,hops:i.hops+1}),n.push(p))}let r=new Set(n.slice(s)),o=new Set;for(let a of r){if(o.has(a))continue;let{at:i}=t.get(a),p=[a];o.add(a);let d=!0;for(let f of p){let{hops:c}=t.get(f),u=!0,b=!1;for(let w of e.get(f)??[]){let x=t.get(w);x.at===i&&r.has(w)?(u&&=x.hops<=c,o.has(w)||(o.add(w),p.push(w))):x.at!==i&&(b||=x.at<i,d&&=x.at<i)}d&&=!u||b}if(d)for(let f of p){let c=t.get(f);t.set(f,{...c,side:-1,hops:-c.hops})}}}function kn(e){let t=new Set(e.nodes.map(o=>o.id)),n=new Map;for(let o of e.edges)!t.has(o.from)||!t.has(o.to)||((n.get(o.from)??n.set(o.from,[]).get(o.from)).push(o.to),(n.get(o.to)??n.set(o.to,[]).get(o.to)).push(o.from));let s=e.nodes.filter(k).sort((o,a)=>C(o.stable.start,a.stable.start)||C(o.name,a.name)),r=new Map;return Sn(e,s).forEach((o,a)=>{r.set(o,{at:a,side:0,hops:0})}),Ln(n,r),r}function Nn(e){let t=new Map(e.nodes.map(c=>[c.id,c])),n=Mn(e),s=new Map(n.map((c,u)=>[c,u])),r=c=>k(t.get(c)),o=new Map(n.map(c=>[c,[]])),a=new Map(n.map(c=>[c,[]])),i=(c,u)=>{o.get(u).push(c),a.get(c).push(u)};for(let c of e.edges)c.from===c.to||!s.has(c.from)||!s.has(c.to)||(s.get(c.from)<s.get(c.to)?i(c.from,c.to):i(c.to,c.from));let p=n.filter(r);for(let c=1;c<p.length;c++)i(p[c-1],p[c]);let d=new Map;for(let c of n){let u=0;for(let b of o.get(c))u=Math.max(u,d.get(b)+1);d.set(c,u)}for(let c=n.length-1;c>=0;c--){let u=n[c],b=a.get(u);if(r(u)||b.length===0)continue;let w=1/0;for(let m of b)w=Math.min(w,d.get(m));let x=d.get(u),l=Math.max(x,w-1);d.set(u,Math.floor((x+l)/2))}let f=[];for(let c of n)(f[d.get(c)]??=[]).push(c);return{layers:f,layerOf:d,preds:o}}function Lt(e){if(!e.nodes.some(k))return;let t=new Map(e.nodes.map(c=>[c.id,c])),n=c=>k(t.get(c)),{layers:s,layerOf:r,preds:o}=Nn(e),a=s.map(c=>{let u=0;for(let b of c)u=Math.max(u,vt(t.get(b)));return u}),i=[],p=0;for(let c=0;c<s.length;c++)i[c]=p,p+=a[c]+vn;let d=new Map;for(let c of s){let u=[];for(let w of c){if(n(w)){d.set(w,0);continue}let x=o.get(w).filter(m=>d.has(m)),l=0;for(let m of x)l+=d.get(m)/x.length;u.push({id:w,ideal:l===0?Ne:l})}u.sort((w,x)=>w.ideal-x.ideal);let b=new Set([0]);for(let{id:w,ideal:x}of u){let l=Math.round(x/Ne);l===0&&(l=x>=0?1:-1);for(let m=1;b.has(l);m++)b.has(l+m)?b.has(l-m)||(l-=m):l+=m;b.add(l),d.set(w,l*Ne)}}let f={};for(let c of e.nodes){let u=r.get(c.id),b=vt(c),w=i[u]+a[u]/2,x=d.get(c.id);f[c.id]=[{x:w-b/2,y:x},{x:w+b/2,y:x}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function kt(e){return e.sample??q(e.name)}function En(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:kt(e)}function In(e,t){let n=[],s;for(let r of e){s!==void 0&&r.start!==void 0&&r.start>s&&n.push(r.start-s),n.push(...r.nodeIds);let o=r.nodeIds.reduce((a,i)=>a+(t.get(i)??0),0);s=r.start===void 0?void 0:r.start+o}return n}function Rn(e,t){let n=[],s;for(let r of e){if(r.start===void 0||s!==void 0&&r.start<s)return;s!==void 0&&r.start>s&&n.push({start:s,end:r.start});let o=r.start;for(let a of r.nodeIds){let i=t.get(a)??0;n.push({start:o,end:o+i}),o+=i}s=o}return n}function An(e,t,n,s=!0){if(!n||!s)return{ids:e,complete:!0,from:-1,to:-1};let r=-1,o=-1,a=-1/0,i=1/0;if(e.forEach((d,f)=>{let c=typeof d=="string"?t.get(d):void 0;c&&(c.end<=n.start&&c.end>a&&(a=c.end,r=f),c.start>=n.end&&c.start<i&&(i=c.start,o=f))}),r<0||o<0)return{ids:e,complete:!1,from:-1,to:-1};let p=e.slice(Math.min(r,o)+1,Math.max(r,o));return{ids:r<o?p:p.reverse(),complete:!0,from:r,to:o}}function Mr(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,s)=>t.indexOf(n.sample)-t.indexOf(s.sample)||n.label.localeCompare(s.label)):e}function Nt(e,t,n){let s=e.paths??[],r=l=>T(l.name).name===e.referencePath,o=s.some(r)?s.filter(r).sort((l,m)=>(l.start??0)-(m.start??0)):s.slice(0,1),a=o[0],i=s.filter(l=>!o.includes(l));if(!a||i.length===0)return;let p=new Map;for(let l of i)p.set(l.name,[...p.get(l.name)??[],l]);let d=new Map(e.nodes.map(l=>[l.id,l.length])),f=a.start??0,c=t&&t.end>t.start?t:void 0,u=new Map;for(let l of o){let m=l.start??0;for(let y of l.nodeIds){let L=d.get(y)??0;u.has(y)||u.set(y,{start:m,end:m+L}),m+=L}}let b=c===void 0||[...u.values()].some(l=>l.end<=c.start)&&[...u.values()].some(l=>l.start>=c.end),w=l=>{let m=l[0],y=[...l].sort((S,E)=>(S.start??0)-(E.start??0)),{ids:L,complete:R,from:B,to:ce}=An(In(y,d),u,c,b),X=Rn(y,d),W=m.contig??fe(T(m.name).name),le=X?.length?B<0?{contig:W,start:X[0].start,reversed:!1}:B<ce?{contig:W,start:X[B].end,reversed:!1}:{contig:W,start:X[B].start,reversed:!0}:void 0,Y=[],G=0,g=0,v=0,M=0;for(let S of L){if(typeof S=="number"){Y.push({start:G,bp:S,onReference:!1,gap:!0}),G+=S,v+=S,M=0;continue}let E=d.get(S)??0,N=u.get(S),_=Y.at(-1),$=_?.referenceStart,U=N&&$!==void 0&&M>=0&&$+_.bp===N.start,Q=N&&$!==void 0&&M<=0&&N.end===$;!N&&_&&!_.onReference&&!_.gap?_.bp+=E:U||Q?(_.bp+=E,U||(_.referenceStart=N.start,_.reversed=!0),M=U?1:-1):(Y.push({start:G,bp:E,onReference:N!==void 0,referenceStart:N?.start}),M=0),G+=E,N||(g+=E)}return{name:m.name,label:En(m),sample:kt(m),haplotype:m.haplotype,bp:G,offReferenceBp:g,gapBp:v,complete:R,runs:Y,axis:le}};return{origin:c?c.start:f,unit:n,reference:w(o),rows:[...p.values()].map(w).sort((l,m)=>Number(m.complete)-Number(l.complete)||m.bp-l.bp||l.label.localeCompare(m.label))}}var On=1.3;function _n(e,t={rowPx:O,readouts:!0}){let n=e.reference.bp;for(let s of e.rows)n=Math.max(n,s.bp);return{maxX:e.origin+n*(t.readouts?On:1),maxY:e.rows.length*t.rowPx}}function Er(e,t,n){return e?n&&!n.labelled?[]:[e.reference,...e.rows].map((s,r)=>({label:s.label,y:r*(n?.rowPx??O)})):t?.rowLabels??[]}function Et(e,t){let n=H(e),s=Nt(e,t);if(n.length===0||!s)return;let r=t?n.filter(i=>ve(i,t)):n,o=V(r.length>0?r:n),a=[{label:s.reference.label,y:0},...s.rows.map((i,p)=>({label:i.label,y:(p+1)*O}))];return{nodePositions:o,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:_n(s)}}var Ot="Force-directed layout",D=e=>e.nodes.some(k),It=e=>D(e)&&(e.paths?.length??0)>1,Rt=e=>D(e)&&J(e),At=e=>D(e)&&e.nodes.some(te),ge=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:xt,cutMargins:!0,wholeWalks:!1,available:D,drawsLocally:D,drawsNodes:!0},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:yt,cutMargins:!0,wholeWalks:!1,available:At,drawsLocally:At,drawsNodes:!0},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, blue on the reference's path and purple off it, so a repeat expansion reads as bar length, and each bar boxes its haplotype's own genes where the session has them. Needs W or P lines.",run:Et,cutMargins:!1,wholeWalks:!0,available:It,drawsLocally:It,drawsNodes:!1},{value:"ordered",label:"Ordered",description:"x is reference order, not bp: every node gets room, bubbles read as lenses. Needs rGFA tags or a reference path.",run:Lt,cutMargins:!1,wholeWalks:!1,available:D,drawsLocally:D,drawsNodes:!0},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:bt,cutMargins:!1,wholeWalks:!1,available:J,drawsLocally:J,drawsNodes:!1},{value:"tubemapref",label:"Tube map on reference",description:"The tube map with each column at the reference bp it covers, so the tubes line up with the tracks around them. Needs P or W lines and a reference path.",run:gt,cutMargins:!0,wholeWalks:!1,available:Rt,drawsLocally:Rt,drawsNodes:!1},{value:"force",label:Ot,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],Ee=ge.map(e=>e.value);function Pn(e,t){return!_t(e).drawsLocally(t)}function _t(e){return ge.find(t=>t.value===e)??ge[0]}function Pt(e,t){let n=e.nodes.filter(l=>k(l)&&(t[l.id]?.length??0)>0);if(n.length<2)return t;let s=n.map(l=>{let m=t[l.id],y=m[Math.floor(m.length/2)];return{x:y.x,y:y.y,r:l.stable.start+l.length/2,w:l.length}}),r=s.reduce((l,m)=>l+m.w,0),o=s.reduce((l,m)=>l+m.x*m.w,0)/r,a=s.reduce((l,m)=>l+m.y*m.w,0)/r,i=s.reduce((l,m)=>l+m.r*m.w,0)/r,p=0,d=0;for(let l of s)p+=l.w*(l.x-o)*(l.r-i),d+=l.w*(l.y-a)*(l.r-i);let f=-Math.atan2(d,p),c=Math.cos(f),u=Math.sin(f),b={};for(let[l,m]of Object.entries(t))b[l]=m.map(y=>{let L=y.x-o,R=y.y-a;return{x:o+c*L-u*R,y:a+u*L+c*R}});let w=0,x=0;for(let l of e.nodes)if(!k(l))for(let m of b[l.id]??[])m.y>a?w++:x++;if(x>w)for(let l of Object.values(b))for(let m of l)m.y=2*a-m.y;return b}var Tt=30;function Tn(e,t){let{opts:n}=t,s=new Map(t.nodes.map(u=>[u.id,me(n,u.length)])),r=u=>s.get(u)??n.minimumNodeLength,o=e.nodes.filter(k).sort((u,b)=>u.stable.start-b.stable.start),a=new Map,i=0;for(let u of o)a.set(u.id,{x:i,y:0}),i+=r(u.id)+n.edgeLength;let p=Z(e),d=new Map(o.map(u=>[u.id,0])),f=o.map(u=>u.id);for(let u of f){let b=a.get(u),w=d.get(u)+1;for(let x of p.get(u)??[])d.has(x)||(d.set(x,w),a.set(x,{x:b.x+r(u)/2,y:Tt*w}),f.push(x))}let c=0;for(let u of e.nodes)a.has(u.id)||a.set(u.id,{x:c++*i/e.nodes.length,y:Tt*3});return a}function Bt(e,t){let n=Tn(e,t);return t.nodes.map(s=>({...s,...n.get(s.id)}))}function Bn(e,t){let n=e.indexOf(":"),s=e.indexOf(":",n+1);if(n!==-1&&s!==-1){let r=e.slice(0,n),o=e.slice(n+1,s),a=e.slice(s+1);o==="i"||o==="f"?t[r]=+a:o==="Z"&&(t[r]=a)}}function re(e){let t={};for(let n of e)Bn(n,t);return t}function $t(e){let{SN:t,SO:n,SR:s}=e.tags;return typeof t=="string"&&typeof n=="number"&&typeof s=="number"?{refName:t,start:n,rank:s}:void 0}var Gt=62,Gn=60;function $n(e){let t=[],n="+",s=0;function r(o){o>s&&t.push({id:e.slice(s,o),strand:n})}for(let o=0;o<e.length;o++){let a=e.charCodeAt(o);(a===Gt||a===Gn)&&(r(o),n=a===Gt?"+":"-",s=o+1)}return r(e.length),t}function Ct(e){let t={nodes:[],links:[],paths:[],walks:[],header:[],id:""};for(let n of e.split(`
2
- `)){let s=n.endsWith("\r")?n.slice(0,-1):n;if(s.startsWith("H")){let[,...r]=s.split(" ");t.header.push(re(r))}else if(s.startsWith("S")){let[,r,...o]=s.split(" "),a,i,p,d=!1,f=o[0]??"*";/^\d+$/.test(f)?(a=+f,i=o[1]??"*",p=o.slice(2)):(d=!0,i=f,a=i==="*"?0:i.length,p=o.slice(1));let c=re(p);d&&"LN"in c&&(a=+c.LN),t.nodes.push({id:r,length:a,sequence:i,tags:c})}else if(s.startsWith("E")){let[,,r,o,,,,,a,...i]=s.split(" ");r&&o&&t.links.push({source:r.slice(0,-1),target:o.slice(0,-1),strand1:r.at(-1),strand2:o.at(-1),cigar:a??"*",tags:re(i)})}else if(s.startsWith("L")){let[,r,o,a,i,p,...d]=s.split(" ");r&&a&&i&&t.links.push({source:r,target:a,strand1:o,strand2:i,cigar:p??"*",tags:re(d)})}else if(s.startsWith("W")){let[,r,o,a,i,p,d,...f]=s.split(" ");r&&o&&a&&i&&p&&d&&t.walks.push({sample:r,haplotype:+o,contig:a,start:i==="*"?-1:+i,end:p==="*"?-1:+p,segments:$n(d),tags:re(f)})}else if(s.startsWith("P")){let[,r,o,...a]=s.split(" ");r&&o&&t.paths.push({name:r,path:o,rest:a})}}return t}function Cn(e){let t=new Map,n=new Map;function s(o,a){t.has(o)||t.set(o,a)}function r(o,a){let i=n.get(o);i===void 0&&s(o,a),n.set(o,(i??0)+1)}for(let o of e.links)s(o.source,o.strand1==="-"?"-":"+"),s(o.target,o.strand2==="-"?"-":"+");for(let o of e.paths)for(let a of o.path.split(","))r(a.slice(0,-1),a.endsWith("-")?"-":"+");for(let o of e.walks)for(let a of o.segments)r(a.id,a.strand==="-"?"-":"+");return{canonical:t,traversals:n}}var Xt=e=>e.start===-1?0:e.start,Xn=e=>e.strand==="+"||e.strand==="-";function Wn(e){return[...e.paths.map(t=>({...T(t.name),steps:t.path.split(",").map(n=>({id:n.slice(0,-1),strand:n.endsWith("-")?"-":"+"}))})),...e.walks.map(t=>({name:`${t.sample}#${t.haplotype}#${t.contig}`,start:Xt(t),steps:t.segments.every(Xn)?t.segments:t.segments.map(n=>({id:n.id,strand:n.strand==="-"?"-":"+"}))}))]}function Yn(e){let t=e.tags.SM;if(typeof t!="string")return;let n=t.split(",").map(s=>s.trim()).filter(Boolean);return n.length>0?n:void 0}var se=e=>typeof e=="number"&&e>0?e:void 0;function Hn({tags:e,length:t}){let n=se(e.RC)??se(e.FC)??se(e.KC);return se(e.dp)??se(e.DP)??(n!==void 0&&t>0?n/t:void 0)}function Vn(e,t,n){return{id:`${e.id}${t}`,name:e.id,length:e.length,depth:n,stable:$t(e),samples:Yn(e)}}function Wt(e,t="Imported GFA"){let n=[],s=[],{canonical:r,traversals:o}=Cn(e),a=new Map,i=l=>{let m=a.get(l);return m===void 0&&(m=`${l}${r.get(l)??"+"}`,a.set(l,m)),m};for(let l of e.nodes){let m=Hn(l)??Math.max(o.get(l.id)??1,1);n.push(Vn(l,r.get(l.id)??"+",m))}for(let l of e.links)s.push({from:i(l.source),to:i(l.target),fromStrand:l.strand1==="-"?"-":"+",toStrand:l.strand2==="-"?"-":"+"});let p=[],d=new Map,f=(l,m)=>d.get(l)?.get(m);function c(l,m,y){let L=d.get(l);L||(L=new Map,d.set(l,L)),L.set(m,y)}let u=s.map(l=>{let m=f(l.from,l.to);return m||(m=new Set,c(l.from,l.to,m),c(l.to,l.from,m)),m});function b(l,m){for(let y=0;y<l.length-1;y++)f(l[y],l[y+1])?.add(m)}for(let l of e.paths){let m=l.path.split(",").map(y=>i(y.slice(0,-1)));p.push({name:l.name,nodeIds:m,start:T(l.name).start}),b(m,l.name)}for(let l of e.walks){let m=l.segments.map(L=>i(L.id)),y=`${l.sample}#${l.haplotype}#${l.contig}`;p.push({name:y,nodeIds:m,start:Xt(l),sample:l.sample,haplotype:l.haplotype,contig:l.contig}),b(m,y)}s.forEach((l,m)=>{let y=u[m];y.size>0&&(l.pathIds=[...y])});let w=new Map(e.nodes.map(l=>[l.id,l.length])),x=e.paths.length>0||e.walks.length>0?Ue(Wn(e),l=>w.get(l)??0):void 0;return{name:t,nodes:n,edges:s,paths:p.length>0?p:void 0,anchorPaths:x?.anchorPaths,pathVisits:x?.pathVisits,anchoredBy:n.some(l=>l.stable)?"tags":void 0}}function Fn(e){let[t="",n="",...s]=e.split("#");return{sample:t,haplotype:n,contig:s.join("#")}}function Yt({nodes:e,links:t,walks:n},s="Imported GFA"){let r=e.names.length,o=e.lengths.length,a=new Uint8Array(r),i=(g,v)=>{a[g]===0&&(a[g]=v?2:1)};for(let g=0;g<t.from.length;g++)i(t.from[g],t.strands[g]&1),i(t.to[g],t.strands[g]&2);let p=[];for(let g=0;g<n.names.length;g++)n.offsets[g+1]>n.offsets[g]&&p.push(g);let d=new Int32Array(r);for(let g of p)for(let v=n.offsets[g];v<n.offsets[g+1];v++){let M=n.steps[v];d[M]===0&&i(M,n.reversed[v]),d[M]++}let f=e.names.map((g,v)=>`${g}${a[v]===2?"-":"+"}`),c=[];for(let g=0;g<o;g++){let v=e.refs[g];c.push({id:f[g],name:e.names[g],length:e.lengths[g],depth:Math.max(d[g],1),stable:v<0?void 0:{refName:e.refNames[v],start:e.starts[g],rank:e.ranks[g]},samples:void 0})}let u=[],b=new Array(r),w=(g,v)=>{let M=b[g];if(M){for(let S=0;S<M.length;S+=2)if(M[S]===v)return M[S+1]}},x=(g,v,M)=>{let S=b[g];S?S.push(v,M):b[g]=[v,M]},l=[],m=0;for(let g=0;g<t.from.length;g++){let v=t.from[g],M=t.to[g];u.push({from:f[v],to:f[M],fromStrand:t.strands[g]&1?"-":"+",toStrand:t.strands[g]&2?"-":"+"});let S=w(v,M);S===void 0&&(S=m++,x(v,M,S),x(M,v,S)),l.push(S)}let y=new Map,L=[],R=Array.from({length:m},()=>[]),B=new Int32Array(m).fill(-1),ce=[],X=[],W=new Array(r),le=new Int32Array(r),Y=[];for(let g of p){let{sample:v,haplotype:M,contig:S}=Fn(n.names[g]),E=`${v}#${+M}#${S}`,N=y.get(E),_=N!==void 0;N===void 0&&(N=L.length,y.set(E,N),L.push(E));let $=n.starts[g],U=q(E),Q=n.offsets[g],Pe=new Array(n.offsets[g+1]-Q),ye=$,xe=-1;for(let ee=Q;ee<n.offsets[g+1];ee++){let P=n.steps[ee];if(Pe[ee-Q]=f[P],le[P]===0&&(W[P]=new Array(d[P]),Y.push(P)),W[P][le[P]++]={path:E,sample:U,start:ye,strand:n.reversed[ee]?"-":"+"},ye+=P<o?e.lengths[P]:0,xe>=0){let pe=w(xe,P);if(pe!==void 0&&B[pe]!==g){B[pe]=g;let Te=R[pe];(!_||!Te.includes(N))&&Te.push(N)}}xe=P}ce.push({name:E,nodeIds:Pe,start:$,sample:v,haplotype:+M,contig:S}),X.push({name:E,sample:U,start:$,length:ye-$})}u.forEach((g,v)=>{let M=R[l[v]];M.length>0&&(g.pathIds=M.map(S=>L[S]))});let G=p.length>0;return{name:s,nodes:c,edges:u,paths:G?ce:void 0,anchorPaths:G?X:void 0,pathVisits:G?new Map(Y.map(g=>[e.names[g],W[g]])):void 0,anchoredBy:c.some(g=>g.stable)?"tags":void 0}}function Rs(e,t,n={}){let s=qe(typeof e=="string"?Wt(Ct(e),t):Yt(e,t),n.referencePath);if(s.nodes.length===0)throw new Error(`No graph segments in ${t}`);if(n.maxNodes!==void 0&&s.nodes.length>n.maxNodes)throw new Error(`Graph too large to draw: ${s.nodes.length.toLocaleString()} nodes (limit ${n.maxNodes.toLocaleString()}). Zoom in to a smaller region, or raise maxGraphNodes on this view.`);return s}var j={engine:"fmmm",quality:2,linearLayout:!1,bubbleSpread:"auto",spacing:1,componentSeparation:1,showDeletionEdges:!0};function As(e={}){return{engine:e.engine??j.engine,quality:e.quality??j.quality,linearLayout:e.linearLayout??j.linearLayout,bubbleSpread:e.bubbleSpread??j.bubbleSpread,spacing:e.spacing??j.spacing,componentSeparation:e.componentSeparation??j.componentSeparation,showDeletionEdges:e.showDeletionEdges??j.showDeletionEdges}}var Dn=15;function jn(e,t,n){let s=e.nodes.some(k),r={...t,opts:{...t.opts,edgeLength:t.opts.edgeLength*(n.spacing??1)}};return{graph:{nodes:s?Bt(e,r):r.nodes,edges:e.edges},options:{quality:n.quality,linearLayout:n.linearLayout,...r.opts,componentSeparation:Dn*(n.componentSeparation??1),...s?{rotateComponents:!1}:{},engine:n.engine??"fmmm"}}}function Ie(e,t){let n=e.nodes.some(k);return`${t.engine??"fmmm"}|${t.quality}|${t.linearLayout}|${t.bubbleSpread}|${t.spacing??1}|${t.componentSeparation??1}|${t.showDeletionEdges!==!1}|${n}|${e.referencePath??""}`}async function Ht(e,t,n){let s=ot(t.bubbleSpread),r=je(e),o=t.showDeletionEdges===!1?ze(e,r):new Set,a=r.filter(y=>!o.has(y.edgeIndex)),i=Ge(e,a,o),p=Fe(i.graph,i.ids),d={...p.graph,nodes:p.graph.nodes.filter(y=>!i.ids.has(y.id))},f=Me(d,s),{result:c,duration:u}=await n(jn(p.graph,{...f,nodes:[...f.nodes,...$e(e,a,i.routes,tt(d,s),f.opts)]},t)),b=Me(e,s),w=new Map(b.nodes.map(y=>[y.id,me(b.opts,y.length)])),x=De(c.nodePositions,p.runs,y=>w.get(y)??0),{nodePositions:l,deletionRoutes:m}=Ce(e.nodes.some(k)?Pt(e,x):x,i.routes);return{result:{...c,nodePositions:l,stranded:!0,...a.length?{deletionRoutes:m,extent:Vt(m)}:{}},duration:u}}function Vt(e){let t=1/0,n=1/0,s=-1/0,r=-1/0;for(let o of Object.values(e))for(let a of o)t=Math.min(t,a.x),n=Math.min(n,a.y),s=Math.max(s,a.x),r=Math.max(r,a.y);return{minX:t,minY:n,maxX:s,maxY:r}}var ae=40,zn=1e-6,Un=100;function Re(e){return Math.max(zn,Math.min(Un,e))}function qn(e,t,n,s=ae){let r=t-e.h*n;return s-e.minY*n+Math.max(0,r)/2}function Os(e,t,n,s,{minScale:r=0,padLeft:o=ae,padTop:a=ae,padRight:i=ae,padBottom:p=ae}={}){let d=t-o-i,f=n-a-p;if(d<=0||f<=0||!(e.w>0||!s&&e.h>0))return;let c=e.w>0?d/e.w:1/0,u=e.h>0?f/e.h:1/0,b=Re(Math.max(r,s?c:Math.min(c,u))),w=d-e.w*b;return{scale:b,translateX:o-e.minX*b+Math.max(0,w)/2,translateY:qn(e,f,s?1:b,a)}}function _s(e,t={}){let{minX:n,minY:s,maxX:r,maxY:o}=Vt(e.nodePositions),{region:a}=t;e.referenceAxis&&a&&a.end>a.start&&(n=a.start,r=a.end);let i=t.extent??e.extent;return i&&(n=Math.min(n,i.minX??n),s=Math.min(s,i.minY??s),r=Math.max(r,i.maxX??r),o=Math.max(o,i.maxY??o)),{minX:n,minY:s,w:r-n,h:o-s}}var Kn=4;function Ae(e=Kn){let t=new WeakMap,n=s=>{let r=t.get(s);return r||(r=new Map,t.set(s,r)),r};return{layout(s,r,o){let a=n(s),i=Ie(s,r),p=a.get(i);if(p)return p.run;a.size>=e&&a.delete(a.keys().next().value);let d=performance.now(),f={run:Ht(s,r,o).then(c=>(f.done=c.result,{...c,duration:c.duration||performance.now()-d}))};return f.run.catch(()=>a.delete(i)),a.set(i,f),f.run},ready(s,r){return t.get(s)?.get(Ie(s,r))?.done},inherit(s,r){let o=t.get(s);o&&s!==r&&t.set(r,o)}}}function Zn(e,t){return{scaleX:e,scaleY:t?1:e,pixelRows:t}}function Oe(e,t,n,s){return{minX:-e.translateX/t.scaleX,minY:-e.translateY/t.scaleY,maxX:(n-e.translateX)/t.scaleX,maxY:(s-e.translateY)/t.scaleY}}function Jn(e,t){let n=(e.maxX-e.minX)*t,s=(e.maxY-e.minY)*t;return{minX:e.minX-n,minY:e.minY-s,maxX:e.maxX+n,maxY:e.maxY+s}}function Qn(e,t){return t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY}function eo(e,t,n,s,r){let o=Re(e.scale*t),a=o/e.scale;return{scale:o,translateX:n-(n-e.translateX)*a,translateY:r?e.translateY:s-(s-e.translateY)*a}}var z=JBrowseExports["@jbrowse/render-core/RenderLifecycleMixin"],to=e=>z!=null&&e in Object(z)?z[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/render-core/RenderLifecycleMixin' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),Ft=to("RenderLifecycleMixin"),Sa=z&&z.__esModule?z.default:z;function Dt(e){return t=>e.includes(t)?t:void 0}function _e(e){return h.snapshotProcessor(h.maybe(h.enumeration(e)),{preProcessor:Dt(e)})}function we(e,t){return h.snapshotProcessor(h.optional(h.enumeration(e),t),{preProcessor:Dt(e)})}var Wa=600,Ya=160,Ha=[1,1,1,1],Va=[.12,.12,.12,1],Fa=([e,t,n])=>`rgb(${[e,t,n].map(s=>Math.round(s*255)).join(", ")})`,Da=5,ja=new Set(["tubemap","tubemapref"]),za=ue(()=>import("./ChooseSamplesDialog-75F3KRRG.js")),Ua=ue(()=>import("./ChooseWalksDialog-L23LYMKI.js")),qa=ue(()=>import("./HighlightColorDialog-CU5FQLRJ.js")),Ka=12,no=h.snapshotProcessor(h.model("GraphFacet",{field:h.optional(h.enumeration(["","walk","sample"]),""),domain:h.optional(h.frozen(),[]),columns:h.maybe(h.number)}),{preProcessor:e=>et(e)}),Za=[{bp:0,label:"None"},{bp:3,label:"Under 3 bp"},{bp:10,label:"Under 10 bp"},{bp:50,label:"Under 50 bp, leaving structural variants"},{bp:1e3,label:"Under 1 kb"}],jt=".segs.bed.gz";function Ja(e){if(typeof e.uri=="string")return e.uri;let n=e.segmentsLocation?.uri;return typeof n=="string"&&n.endsWith(jt)?n.slice(0,-jt.length):void 0}var Qa=1.15,ei=1.6,ti=150,ni=1,oi=40,ri={nodeStrokes:[],nodeStrokeRuns:new Map,arrows:[],arrowRuns:new Map,edgeCurves:[],edgeCurveRuns:new Map};function si(...e){}var ai=5e6;function ii(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:`${Math.round(e/1e3)} kb`}var oo=2e4;function ci(e){return("uri"in e?e.uri.split(/[?#]/)[0]:"localPath"in e?e.localPath:"name"in e?e.name:"").split(/[\\/]/).at(-1)??""}function li(e){return e&&"uri"in e&&e.uri?new URL(e.uri,e.baseUri??window.location.href).href:void 0}function pi(e){return e.builtViewport!==void 0&&e.paintedViewport===e.builtViewport&&e.builtViewport.viewportDirty===e.viewportDirty&&!e.viewportRebuildPending}function fi(e){let{width:t,height:n}=e.viewBox;return Oe(e,e.axisScale,t,n)}var di=Ae(),ui=h.compose("GraphPane",Ft(),h.model({layoutQuality:h.optional(h.number,2),layoutEngine:we(Xe,"fmmm"),linearLayout:h.optional(h.boolean,!1),layoutMode:_e(Ee),colorScheme:_e(Qe),highlightOnHover:h.maybe(h.boolean),bubbleSpread:we(nt,"auto"),nodeWidth:we(rt,"depth"),showBubbles:h.optional(h.boolean,!1),showDeletionEdges:h.optional(h.boolean,!0),showGenes:h.optional(h.boolean,!0),showReferenceStrip:h.optional(h.boolean,!0),tubeMapFold:h.optional(h.number,0),geneTrackId:h.optional(h.string,""),repeatTrackId:h.optional(h.string,""),repeatKey:h.optional(h.string,""),walkRowSamples:h.maybe(h.frozen()),walkRowGroupBy:h.maybe(h.snapshotProcessor(h.frozen(),{preProcessor:e=>st(e)})),walkStrip:h.optional(h.boolean,!1),walkLayers:h.optional(h.frozen(),[]),facet:h.optional(no,{}),referencePath:h.optional(h.string,""),showPerf:h.optional(h.boolean,!1),contigThickness:h.optional(h.number,6),connectorThickness:h.optional(h.number,2),darkMode:h.optional(h.boolean,!1),scale:h.optional(h.number,1),translateX:h.optional(h.number,0),translateY:h.optional(h.number,0),drawPaths:h.optional(h.boolean,!1),paneHeight:h.maybe(h.number),maxGraphNodes:h.optional(h.number,oo),colorDomain:h.maybe(h.frozen()),connectedViewId:h.maybe(h.string)})).volatile(()=>({graph:void 0,graphRegion:void 0,loadedReferencePath:void 0,layoutResult:void 0,legendSize:{width:0,height:0},indexBubbles:void 0,geneTrackFeatures:void 0,walkGeneFeatures:void 0,walkRowSampleTable:void 0,repeatArrays:void 0,popStack:[],error:void 0,isLoading:!1,loadCanceled:!1,statusMessage:"",hoveredNode:null,hoveredRowWalks:[],hoveredBubble:null,pointerInPane:!1,stripHover:null,hoveredWalkRow:null,hoveredEdge:null,selectedNode:null,viewportDirty:0,positionsVersion:0,geometryVersion:0,builtViewport:void 0,paintedViewport:void 0,draggingNode:null,isPanning:!1,viewportOwner:"fit",viewportDirtyTimer:void 0,positionsDirtyFrame:0,lastFetchMs:void 0,readsShown:void 0,lastLayoutMs:void 0,lastGeometryMs:void 0,lastGeometryStrokeCount:void 0,viewportRebuildPending:!1}));function ro(e){return e.walkStrip&&e.mode.drawsNodes&&!e.drawsPicture&&!e.popped&&!e.host&&e.walks>1}function so(e,t){return e.wholeWalks||t.walkStrip&&!t.host}var ie=6,qt=260,ao=11,io=3,co=1.3,lo="#111",zt=3;function po(e,t,n){let s=e.pathVisits?.get(n.name)??[],r=[];for(let o of t){let a=o.axis;if(!a)continue;let i=T(o.name).name;for(let p of s){if(p.path!==i)continue;let{start:d,end:f}=at(a,p.start,p.start+n.length);f>0&&d<o.bp&&r.push({row:o.name,start:d,bp:f-d})}}return r}var Ut=new WeakMap;function fo(e,t){let n=Ut.get(e);if(n||(n=new Map,Ut.set(e,n)),n.has(t))return n.get(t);let s=new Map(e.nodes.map(a=>[a.id,a.length])),r=(e.paths??[]).filter(a=>a.name===t),o;if(r.every(a=>a.start!==void 0)){o={ids:[],starts:[],ends:[]};for(let a of[...r].sort((i,p)=>i.start-p.start)){let i=a.start;for(let p of a.nodeIds){let d=s.get(p)??0;o.ids.push(p),o.starts.push(i),o.ends.push(i+d),i+=d}}}return n.set(t,o),o}function uo(e,t,n,s){let r=t.axis,o=r&&fo(e,t.name);if(!r||!o||n<0||n>t.bp)return;let a=r.reversed?r.start-n:r.start+n,i=.5/s,p=r.reversed?{start:r.start-t.bp,end:r.start}:{start:r.start,end:r.start+t.bp},d=Math.max(a-i,p.start),f=Math.min(a+i,p.end),c=0,u=o.starts.length;for(;c<u;){let l=c+u>>1;o.ends[l]<=d?c=l+1:u=l}let b,w=-1,x=!1;for(let l=c;l<o.starts.length&&o.starts[l]<f;l++){let m=o.ends[l]-o.starts[l],y=o.starts[l]<=a&&a<o.ends[l];(m>w||m===w&&y&&!x)&&(w=m,b=o.ids[l],x=y)}return b}function mo(e,t){let n=t.maxHeight??qt,s=t.labelPx??Math.max(...[e.reference,...e.rows].map(b=>b.label.length))*Ve+16,r=e.rows.length+1,{rowPx:o,barPx:a,labelled:i,readouts:p}=ct(r,n-2*ie,io),d=Math.max(e.reference.bp,...e.rows.map(b=>b.bp),1),f=i?s:ie,u=Math.max(1,t.width-f-ie)/(d*(p?co:1));return{scaleX:u,scaleY:1,translateX:f-e.origin*u,translateY:ie+o/2,width:t.width,height:r*o+2*ie,rowPx:o,barPx:a,readouts:p,labelled:i,boxesGenes:it(o,a)}}function ho(e,t,n,s){let r=Math.round((s-t.translateY)/t.rowPx),o=[e.reference,...e.rows][r],a=(n-t.translateX)/t.scaleX-e.origin;return o&&r>=0&&a>=0&&a<=o.bp?{index:r,row:o,offset:a}:void 0}function bo(e,t,n){let s=new Map([e.reference,...e.rows].map((o,a)=>[o.name,a])),r=o=>(e.origin+o)*t.scaleX+t.translateX;return oe("g",{"data-testid":"graph-walk-marks"},...n.flatMap(o=>{let a=s.get(o.row);if(a===void 0)return[];let i=a*t.rowPx+t.translateY,p=r(o.start),d=Math.max(2,o.bp*t.scaleX),f=c=>oe("rect",{x:p,y:c,width:d,height:zt,fill:lo});return[f(i-t.barPx/2-zt-1),f(i+t.barPx/2+1)]}))}function go(e,t,n=new Set){return oe("g",{"font-family":"sans-serif","font-size":ao,fill:"#333"},...(t.labelled?[e.reference,...e.rows]:[]).map((s,r)=>oe("text",{x:6,y:r*t.rowPx+t.translateY+4,"font-weight":n.has(s.name)?600:void 0},s.label)))}function wo(e,t,n){if(t?.size)return e.boxesGenes?n:{untracked:0,unread:0,...n,crowded:!0}}var Vi=I(A("path",{d:"M19 15.18V7c0-2.21-1.79-4-4-4s-4 1.79-4 4v10c0 1.1-.9 2-2 2s-2-.9-2-2V8.82C8.16 8.4 9 7.3 9 6c0-1.66-1.34-3-3-3S3 4.34 3 6c0 1.3.84 2.4 2 2.82V17c0 2.21 1.79 4 4 4s4-1.79 4-4V7c0-1.1.9-2 2-2s2 .9 2 2v8.18c-1.16.41-2 1.51-2 2.82 0 1.66 1.34 3 3 3s3-1.34 3-3c0-1.3-.84-2.4-2-2.82"}),"Route");var zi=I(A("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");var Zi=I(A("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5M12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5m0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"}),"Visibility");export{I as a,on as b,Mn as c,Mr as d,Nt as e,_n as f,Er as g,ge as h,Ee as i,Pn as j,_t as k,Zi as l,Rs as m,j as n,As as o,ae as p,Re as q,qn as r,Os as s,_s as t,Zn as u,Jn as v,Qn as w,eo as x,Wa as y,Ya as z,Ha as A,Va as B,Fa as C,Da as D,ja as E,za as F,Ua as G,qa as H,Ka as I,Za as J,Ja as K,Qa as L,ei as M,ti as N,ni as O,oi as P,ri as Q,si as R,ai as S,ii as T,ci as U,li as V,pi as W,fi as X,di as Y,ui as Z,ro as _,so as $,po as aa,uo as ba,mo as ca,ho as da,bo as ea,go as fa,wo as ga,Ro as ha,Ao as ia,Qt as ja,Oo as ka,_o as la,Se as ma,Le as na,zo as oa,Uo as pa,Vi as qa,zi as ra};
3
- //# sourceMappingURL=chunk-MDRNFKXW.js.map
1
+ import{a as Ce,b as Ge,c as $e,e as We,h as Qe,j as me,k as Me,l as tt,n as nt,o as ot}from"./chunk-LEWWQ7ZK.js";import{D as oe,K as at,N as it,T as ct,e as Xe,f as Ye,g as He,j as Je,p as et,u as st}from"./chunk-KIXOGZKJ.js";import{a as Z}from"./chunk-BXZLLHYP.js";import{D as P,E as Ue,H as qe,P as Ke,Q as Ze,U as rt,b as Ve,f as O,q as Fe,r as De,u as je,v as ze}from"./chunk-AB2XVNNS.js";import{a as de,b as K,c as k,d as te,e as H,f as ve,g as V,j as ne}from"./chunk-PR5YUSXN.js";import{a as q,c as Be,d as fe}from"./chunk-XKN5LH2Z.js";import{h}from"./chunk-ELLLNUKS.js";import{b as ue}from"./chunk-6OPB7FOJ.js";import{b as A}from"./chunk-JMBDTNUR.js";var F=JBrowseExports["@mui/material/SvgIcon"],Kt=e=>F!=null&&e in Object(F)?F[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@mui/material/SvgIcon' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),I=Kt("createSvgIcon"),yo=F&&F.__esModule?F.default:F;function Ro(e){return K(e)?lt(e):void 0}function lt(e){return{sample:q(e.stable.refName),haplotype:Be(e.stable.refName),refName:fe(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function Zt(e,t){let n=[...e].sort((o,a)=>o.start-a.start),s,r;for(let o of n)r=r&&o.start-r.end<=t?{start:r.start,end:Math.max(r.end,o.end)}:{start:o.start,end:o.end},(!s||r.end-r.start>s.end-s.start)&&(s=r);return s}function Jt(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ao(e,{maxGap:t=1/0}={}){let n=new Map;for(let r of e.nodes)if(K(r)){let o=lt(r),a=Jt(o),i=n.get(a);i?(i.spans.push({start:o.start,end:o.end}),i.rank=Math.min(i.rank,r.stable.rank)):n.set(a,{sample:o.sample,haplotype:o.haplotype,refName:o.refName,rank:r.stable.rank,spans:[{start:o.start,end:o.end}]})}let s=new Map;for(let r of n.values()){let o=Zt(r.spans,t);if(o){let a={sample:r.sample,haplotype:r.haplotype,refName:r.refName,start:o.start,end:o.end,rank:r.rank,nodeCount:r.spans.length},i=r.haplotype??r.sample,p=s.get(i);(!p||a.nodeCount>p.nodeCount)&&s.set(i,a)}}return[...s.values()].sort((r,o)=>+(r.rank!==0)-+(o.rank!==0)||r.sample.localeCompare(o.sample)||(r.haplotype??"").localeCompare(o.haplotype??""))}function Qt(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function Oo(e,t){return e.flatMap(n=>{let s=Qt(t,n);return s===void 0?[]:[{...n,sample:s}]})}function _o(e){return`${e.refName}:${e.start+1}-${e.end}`}function Se(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var pt=I(A("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var ft=I(A("path",{d:"M17 5h-2V3h2zm-2 16h2v-2.59L19.59 21 21 19.59 18.41 17H21v-2h-6zm4-12h2V7h-2zm0 4h2v-2h-2zm-8 8h2v-2h-2zM7 5h2V3H7zM3 17h2v-2H3zm2 4v-2H3c0 1.1.9 2 2 2M19 3v2h2c0-1.1-.9-2-2-2m-8 2h2V3h-2zM3 9h2V7H3zm4 12h2v-2H7zm-4-8h2v-2H3zm0-8h2V3c-1.1 0-2 .9-2 2"}),"HighlightAlt");var Le=I(A("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var en="Linear genome view",tn="Linear synteny view",nn="No synteny track in this session aligns these assemblies";function dt({label:e,icon:t,entries:n,entryLabel:s,onSelect:r,disabledHelpText:o,nameTheOnlyEntry:a=!0}){let[i]=n,p=o?[{label:e,icon:t,disabled:!0,disabledHelpText:o,onClick:()=>{}}]:[];return n.length===0?p:n.length===1&&i?[{label:a?`${e} \u2014 ${s(i)}`:e,icon:t,onClick:r(i)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(d=>({label:s(d),onClick:r(d)}))}]}function zo({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:s}){let r=t[0]?.coverage??e.length;return[...dt({label:en,icon:Le,entries:e,entryLabel:o=>`${o.sample} ${Se(o)}`,onSelect:o=>()=>{n({location:o,assembly:o.sample})}}),...e.length>=2?dt({label:`${tn} (${r} assemblies)`,icon:pt,entries:t,entryLabel:o=>o.coverage<r?`${o.name} (${o.coverage} of ${r})`:o.name,nameTheOnlyEntry:!1,disabledHelpText:nn,onSelect:o=>()=>{s(o.trackId)}}):[]]}function Uo({own:e,reference:t,highlight:n,onShowLinear:s,onHighlight:r}){let o=[e?{label:`Open in ${e.assembly} \u2014 ${Se(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...r&&n?[{label:`Highlight in ${n.assembly}`,icon:ft,onClick:()=>{r(n)}}]:[],...o.map(({label:a,target:i})=>({label:a,icon:Le,onClick:()=>{s(i)}}))]}function on(e){let t=new Map;for(let[n,s]of e.pathVisits??[])for(let r of s){let o=`${r.path} ${n}`,a=t.get(o);a?a.push(r.strand):t.set(o,[r.strand])}return t}function rn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=on(e),s=(e.paths??[]).map((o,a)=>({path:o,index:a})),r=s.findIndex(o=>P(o.path.name).name===e.referencePath);return r>0&&s.unshift(...s.splice(r,1)),s.flatMap(({path:o,index:a})=>{let i=P(o.name).name,p=new Map,d=o.nodeIds.flatMap(f=>{let c=t.get(f);if(!c)return[];let u=p.get(c.name)??0;p.set(c.name,u+1);let b=n.get(`${i} ${c.name}`)?.[u]??Xe(c);return[Ye(c,b)]});return d.length>0?[{id:a,name:o.name,sequence:d,sourceTrackID:0,type:"haplotype"}]:[]})}function sn(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function J(e){return(e.paths?.length??0)>0}var an=600,cn=3,ln=15;function pn(e){return Math.max(cn,Math.min(ln,Math.floor(an/Math.max(1,e))))}function ut(e){let t=e.paths??[],n=rn(e),s=e.reads?He(e,e.reads,t.length):[],r=s.length>0?Ze:Ke,o=t.map((i,p)=>r(p,t.length)),a=Je(sn(e),n,s,{nodeWidthOption:"compressed",trackWidth:pn(n.length)});return a?{layout:a,pathColors:o}:void 0}function ke(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function mt(e,t,n,s){let r=e.y+e.contentHeight/2-t;return[{x:n,y:r},{x:s,y:r}]}function ht(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function bt(e){let t=J(e)?ut(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,r=n.bounds.minY,o={};for(let p of ke(n))o[p.name]=mt(p,r,p.x,p.x+p.pixelWidth);let{minY:a,maxY:i}=ht(n,r);return{nodePositions:o,tubeMap:{layout:n,yOffset:r,pathColors:s},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:a,maxY:i}}}function fn(e,t){let n=new Map(e.nodes.map(i=>[i.id,i])),s=new Map;for(let i of ke(t)){let p=s.get(i.order);p?p.push(i):s.set(i.order,[i])}let r=[],o=-1/0;for(let i of[...s.keys()].sort((p,d)=>p-d)){let p=s.get(i),d=1/0,f=-1/0;for(let c of p){let u=n.get(c.name);u&&k(u)&&(d=Math.min(d,u.stable.start),f=Math.max(f,u.stable.start+c.sequenceLength))}d===1/0&&(d=f=o),d<o&&(d=o,f=Math.max(o,f)),o=Math.max(o,f),r.push({order:i,x0:Math.min(...p.map(c=>c.x)),x1:Math.max(...p.map(c=>c.x+c.pixelWidth)),bp0:d,bp1:f})}let a=r.find(i=>i.bp0!==-1/0);for(let i of r)i.bp0===-1/0&&(i.bp0=i.bp1=a?.bp0??0);return r}function dn(e){return e.nodes.some(k)&&J(e)}function gt(e){let t=dn(e)?ut(e):void 0;if(!t)return;let{layout:n,pathColors:s}=t,r=fn(e,n),o=new Map(r.map(p=>[p.order,p])),a=n.bounds.minY,i={};for(let p of ke(n)){let d=o.get(p.order);i[p.name]=mt(p,a,d.bp0,d.bp1)}return{nodePositions:i,tubeMap:{layout:n,yOffset:a,columns:r,pathColors:s},referenceAxis:!0,pixelRows:!0,extent:ht(n,a)}}function he(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function un(e,t,n,s){let r=[],o=[],a=[e];for(s.add(e);a.length>0;){let i=a.pop(),p=t.get(i);if(p){r.push(p);for(let d of n.get(i)??[]){let f=t.get(d);f&&(f.stable.rank===de?o.push(f):s.has(d)||(s.add(d),a.push(d)))}}}return{members:r,anchors:o}}function mn(e){if(new Set(e.map(i=>i.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((i,p)=>i.stable.start-p.stable.start),s=n[0],r=n.at(-1),o=s.stable.start+s.length,a=r.stable.start;return a>=o?{start:o,end:a,entry:s}:void 0}function hn(e,t,n){let s=new Map(e.map(a=>[a.id,a])),r=new Map,o=[];for(let a of n.get(t.id)??[])s.has(a)&&(r.set(a,0),o.push(a));if(o.length===0)for(let a of e)r.set(a.id,0),o.push(a.id);for(let a of o){let i=r.get(a)+s.get(a).length;for(let p of n.get(a)??[])if(s.has(p)){let d=r.get(p);(d===void 0||i<d)&&(r.set(p,i),o.push(p))}}return r}function bn(e,t,n){let s=hn(e,t,n),r=[...e].sort((p,d)=>s.get(p.id)-s.get(d.id)),o=new Map(r.map((p,d)=>[p.id,d])),a=new Map(e.map(p=>[p.id,p])),i=new Map;for(let[p,d]of r.entries()){let f=0;for(let c of n.get(d.id)??[]){let u=a.get(c);u&&o.get(c)<p&&(f=Math.max(f,i.get(c)+u.length))}i.set(d.id,f)}return{offsets:i,ordered:r}}function wt(e){let t=new Map(e.nodes.filter(K).map(o=>[o.id,o])),n=Z(e),s=new Set,r=[];for(let o of t.values())if(o.stable.rank!==de&&!s.has(o.id)){let{members:a,anchors:i}=un(o.id,t,n,s),p=mn(i);if(p){let{offsets:d,ordered:f}=bn(a,p.entry,n);r.push({start:p.start,refSpan:p.end-p.start,nodeIds:f.map(c=>c.id),nodeOffsets:f.map(c=>d.get(c.id)),pathLength:f.reduce((c,u)=>Math.max(c,d.get(u.id)+u.length),0)})}}return r.sort((o,a)=>o.start-a.start)}var gn=1,wn=.015;function be({graph:e,span:t,rowY:n,positions:s}){let r=t*wn,o=wt(e),a=new Map(e.nodes.map(f=>[f.id,f])),i=[];for(let f of o){let c=f.refSpan-f.pathLength;c>=gn&&i.push({nodeIds:f.nodeIds,bp:c});let u=Math.max(f.refSpan,r),b=f.pathLength>0?u/f.pathLength:0;f.nodeIds.forEach((w,x)=>{let l=a.get(w);if(l){let m=f.nodeOffsets[x],y=u/f.nodeIds.length,L=B=>f.start+B*b,R=n(l);s[w]=b?[{x:L(m),y:R},{x:L(m+l.length),y:R}]:[{x:f.start+x*y,y:R},{x:f.start+(x+1)*y,y:R}]}})}let p=Z(e),d=Object.keys(s);for(let f of d){let c=s[f].at(-1).x;for(let u of p.get(f)??[]){let b=a.get(u);if(b&&!(u in s)){let w=n(b);s[u]=[{x:c,y:w},{x:c+r,y:w}],d.push(u)}}}return i}function yn(e,t){let n=new Map;for(let r of e.nodes)if(te(r)){let{sample:o}=he(r.stable.refName);n.set(o,(n.get(o)??0)+r.length)}let s=new Map(t.map((r,o)=>[r,o]));return[...n.keys()].sort((r,o)=>(s.get(r)??1/0)-(s.get(o)??1/0)||n.get(o)-n.get(r)||r.localeCompare(o))}function yt(e,t,n=[]){let s=H(e),r=yn(e,n);if(s.length===0||r.length===0)return;let o=ne(s,t),a=new Map(r.map((u,b)=>[u,b+1])),i=V(s),p=r.length+1,d=be({graph:e,span:o,rowY:u=>{let b=u.stable;return((b?a.get(he(b.refName).sample):void 0)??p)*O},positions:i}),c=[{label:he(s[0].stable.refName).sample,y:0},...r.map(u=>({label:u,y:a.get(u)*O}))];return{nodePositions:i,rowLabels:c,sampleRows:r,referenceAxis:!0,pixelRows:!0,alleleDeletions:d}}function xn(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,s)=>n-s).map((n,s)=>[n,s]))}function xt(e,t){let n=H(e);if(n.length===0)return;let s=ne(n,t),r=xn(e),o=V(n),a=be({graph:e,span:s,rowY:p=>(p.stable?r.get(p.stable.rank)??r.size:r.size)*O,positions:o}),i=[...r].map(([p,d])=>({label:p===0?"Reference (rank 0)":`Rank ${p}`,y:d*O}));return{nodePositions:o,rowLabels:i,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var vn=12,Ne=O;function vt(e){return 10+8*Math.log2(1+e.length)}function $(e,t){return e<t?-1:e>t?1:0}function St(e,t){return $(e.at,t.at)||$(e.side,t.side)||$(e.hops,t.hops)}var Mt={at:1/0,side:0,hops:0};function Mn(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=kn(e);return e.nodes.map(s=>s.id).sort((s,r)=>St(n.get(s)??Mt,n.get(r)??Mt)||$(t.get(s).name,t.get(r).name)||$(s,r))}function Sn(e,t){let n=new Set(e.nodes.map(f=>f.id)),s=new Map(t.map(f=>[f.id,f.stable.start])),r=new Map,o=new Map;t.forEach((f,c)=>{o.set(f.id,t[c-1]?.id),r.set(f.id,t[c+1]?.id)});let a=t[0]?.id,i=(f,c)=>{let u=r.get(f);r.set(f,c),o.set(c,f),r.set(c,u),u!==void 0&&o.set(u,c)},p=(f,c)=>{let u=o.get(f);u===void 0?(a=c,o.set(c,void 0),r.set(c,f),o.set(f,c)):i(u,c)};for(let f of e.paths??[]){let c=0,u=0,b;for(let m of f.nodeIds){let y=s.get(m);y!==void 0&&(b!==void 0&&y!==b&&(y>b?c++:u++),b=y)}let w=u>c?[...f.nodeIds].reverse():f.nodeIds,x,l=new Set;for(let m of w)if(r.has(m)){if(x===void 0)for(let y of l)p(m,y);x=m}else n.has(m)&&(x===void 0?l.add(m):(i(x,m),x=m))}let d=[];for(let f=a;f!==void 0;f=r.get(f))d.push(f);return d}function Ln(e,t){let n=[...t.entries()].sort(([a,i],[p,d])=>St(i,d)||$(a,p)).map(([a])=>a),s=n.length;for(let a of n){let i=t.get(a);for(let p of e.get(a)??[])t.has(p)||(t.set(p,{at:i.at,side:1,hops:i.hops+1}),n.push(p))}let r=new Set(n.slice(s)),o=new Set;for(let a of r){if(o.has(a))continue;let{at:i}=t.get(a),p=[a];o.add(a);let d=!0;for(let f of p){let{hops:c}=t.get(f),u=!0,b=!1;for(let w of e.get(f)??[]){let x=t.get(w);x.at===i&&r.has(w)?(u&&=x.hops<=c,o.has(w)||(o.add(w),p.push(w))):x.at!==i&&(b||=x.at<i,d&&=x.at<i)}d&&=!u||b}if(d)for(let f of p){let c=t.get(f);t.set(f,{...c,side:-1,hops:-c.hops})}}}function kn(e){let t=new Set(e.nodes.map(o=>o.id)),n=new Map;for(let o of e.edges)!t.has(o.from)||!t.has(o.to)||((n.get(o.from)??n.set(o.from,[]).get(o.from)).push(o.to),(n.get(o.to)??n.set(o.to,[]).get(o.to)).push(o.from));let s=e.nodes.filter(k).sort((o,a)=>$(o.stable.start,a.stable.start)||$(o.name,a.name)),r=new Map;return Sn(e,s).forEach((o,a)=>{r.set(o,{at:a,side:0,hops:0})}),Ln(n,r),r}function Nn(e){let t=new Map(e.nodes.map(c=>[c.id,c])),n=Mn(e),s=new Map(n.map((c,u)=>[c,u])),r=c=>k(t.get(c)),o=new Map(n.map(c=>[c,[]])),a=new Map(n.map(c=>[c,[]])),i=(c,u)=>{o.get(u).push(c),a.get(c).push(u)};for(let c of e.edges)c.from===c.to||!s.has(c.from)||!s.has(c.to)||(s.get(c.from)<s.get(c.to)?i(c.from,c.to):i(c.to,c.from));let p=n.filter(r);for(let c=1;c<p.length;c++)i(p[c-1],p[c]);let d=new Map;for(let c of n){let u=0;for(let b of o.get(c))u=Math.max(u,d.get(b)+1);d.set(c,u)}for(let c=n.length-1;c>=0;c--){let u=n[c],b=a.get(u);if(r(u)||b.length===0)continue;let w=1/0;for(let m of b)w=Math.min(w,d.get(m));let x=d.get(u),l=Math.max(x,w-1);d.set(u,Math.floor((x+l)/2))}let f=[];for(let c of n)(f[d.get(c)]??=[]).push(c);return{layers:f,layerOf:d,preds:o}}function Lt(e){if(!e.nodes.some(k))return;let t=new Map(e.nodes.map(c=>[c.id,c])),n=c=>k(t.get(c)),{layers:s,layerOf:r,preds:o}=Nn(e),a=s.map(c=>{let u=0;for(let b of c)u=Math.max(u,vt(t.get(b)));return u}),i=[],p=0;for(let c=0;c<s.length;c++)i[c]=p,p+=a[c]+vn;let d=new Map;for(let c of s){let u=[];for(let w of c){if(n(w)){d.set(w,0);continue}let x=o.get(w).filter(m=>d.has(m)),l=0;for(let m of x)l+=d.get(m)/x.length;u.push({id:w,ideal:l===0?Ne:l})}u.sort((w,x)=>w.ideal-x.ideal);let b=new Set([0]);for(let{id:w,ideal:x}of u){let l=Math.round(x/Ne);l===0&&(l=x>=0?1:-1);for(let m=1;b.has(l);m++)b.has(l+m)?b.has(l-m)||(l-=m):l+=m;b.add(l),d.set(w,l*Ne)}}let f={};for(let c of e.nodes){let u=r.get(c.id),b=vt(c),w=i[u]+a[u]/2,x=d.get(c.id);f[c.id]=[{x:w-b/2,y:x},{x:w+b/2,y:x}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function kt(e){return e.sample??q(e.name)}function En(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:kt(e)}function In(e,t){let n=[],s;for(let r of e){s!==void 0&&r.start!==void 0&&r.start>s&&n.push(r.start-s),n.push(...r.nodeIds);let o=r.nodeIds.reduce((a,i)=>a+(t.get(i)??0),0);s=r.start===void 0?void 0:r.start+o}return n}function Rn(e,t){let n=[],s;for(let r of e){if(r.start===void 0||s!==void 0&&r.start<s)return;s!==void 0&&r.start>s&&n.push({start:s,end:r.start});let o=r.start;for(let a of r.nodeIds){let i=t.get(a)??0;n.push({start:o,end:o+i}),o+=i}s=o}return n}function An(e,t,n,s=!0){if(!n||!s)return{ids:e,complete:!0,from:-1,to:-1};let r=-1,o=-1,a=-1/0,i=1/0;if(e.forEach((d,f)=>{let c=typeof d=="string"?t.get(d):void 0;c&&(c.end<=n.start&&c.end>a&&(a=c.end,r=f),c.start>=n.end&&c.start<i&&(i=c.start,o=f))}),r<0||o<0)return{ids:e,complete:!1,from:-1,to:-1};let p=e.slice(Math.min(r,o)+1,Math.max(r,o));return{ids:r<o?p:p.reverse(),complete:!0,from:r,to:o}}function Mr(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,s)=>t.indexOf(n.sample)-t.indexOf(s.sample)||n.label.localeCompare(s.label)):e}function Nt(e,t,n){let s=e.paths??[],r=l=>P(l.name).name===e.referencePath,o=s.some(r)?s.filter(r).sort((l,m)=>(l.start??0)-(m.start??0)):s.slice(0,1),a=o[0],i=s.filter(l=>!o.includes(l));if(!a||i.length===0)return;let p=new Map;for(let l of i)p.set(l.name,[...p.get(l.name)??[],l]);let d=new Map(e.nodes.map(l=>[l.id,l.length])),f=a.start??0,c=t&&t.end>t.start?t:void 0,u=new Map;for(let l of o){let m=l.start??0;for(let y of l.nodeIds){let L=d.get(y)??0;u.has(y)||u.set(y,{start:m,end:m+L}),m+=L}}let b=c===void 0||[...u.values()].some(l=>l.end<=c.start)&&[...u.values()].some(l=>l.start>=c.end),w=l=>{let m=l[0],y=[...l].sort((S,E)=>(S.start??0)-(E.start??0)),{ids:L,complete:R,from:B,to:ce}=An(In(y,d),u,c,b),W=Rn(y,d),X=m.contig??fe(P(m.name).name),le=W?.length?B<0?{contig:X,start:W[0].start,reversed:!1}:B<ce?{contig:X,start:W[B].end,reversed:!1}:{contig:X,start:W[B].start,reversed:!0}:void 0,Y=[],C=0,g=0,v=0,M=0;for(let S of L){if(typeof S=="number"){Y.push({start:C,bp:S,onReference:!1,gap:!0}),C+=S,v+=S,M=0;continue}let E=d.get(S)??0,N=u.get(S),_=Y.at(-1),G=_?.referenceStart,U=N&&G!==void 0&&M>=0&&G+_.bp===N.start,Q=N&&G!==void 0&&M<=0&&N.end===G;!N&&_&&!_.onReference&&!_.gap?_.bp+=E:U||Q?(_.bp+=E,U||(_.referenceStart=N.start,_.reversed=!0),M=U?1:-1):(Y.push({start:C,bp:E,onReference:N!==void 0,referenceStart:N?.start}),M=0),C+=E,N||(g+=E)}return{name:m.name,label:En(m),sample:kt(m),haplotype:m.haplotype,bp:C,offReferenceBp:g,gapBp:v,complete:R,runs:Y,axis:le}};return{origin:c?c.start:f,unit:n,reference:w(o),rows:[...p.values()].map(w).sort((l,m)=>Number(m.complete)-Number(l.complete)||m.bp-l.bp||l.label.localeCompare(m.label))}}var On=1.3;function _n(e,t={rowPx:O,readouts:!0}){let n=e.reference.bp;for(let s of e.rows)n=Math.max(n,s.bp);return{maxX:e.origin+n*(t.readouts?On:1),maxY:e.rows.length*t.rowPx}}function Er(e,t,n){return e?n&&!n.labelled?[]:[e.reference,...e.rows].map((s,r)=>({label:s.label,y:r*(n?.rowPx??O)})):t?.rowLabels??[]}function Et(e,t){let n=H(e),s=Nt(e,t);if(n.length===0||!s)return;let r=t?n.filter(i=>ve(i,t)):n,o=V(r.length>0?r:n),a=[{label:s.reference.label,y:0},...s.rows.map((i,p)=>({label:i.label,y:(p+1)*O}))];return{nodePositions:o,rowLabels:a,referenceAxis:!0,pixelRows:!0,extent:_n(s)}}var Ot="Force-directed layout",D=e=>e.nodes.some(k),It=e=>D(e)&&(e.paths?.length??0)>1,Rt=e=>D(e)&&J(e),At=e=>D(e)&&e.nodes.some(te),ge=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:xt,cutMargins:!0,wholeWalks:!1,available:D,drawsLocally:D,drawsNodes:!0},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:yt,cutMargins:!0,wholeWalks:!1,available:At,drawsLocally:At,drawsNodes:!0},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, blue on the reference's path and purple off it, so a repeat expansion reads as bar length, and each bar boxes its haplotype's own genes where the session has them. Needs W or P lines.",run:Et,cutMargins:!1,wholeWalks:!0,available:It,drawsLocally:It,drawsNodes:!1},{value:"ordered",label:"Ordered",description:"x is reference order, not bp: every node gets room, bubbles read as lenses. Needs rGFA tags or a reference path.",run:Lt,cutMargins:!1,wholeWalks:!1,available:D,drawsLocally:D,drawsNodes:!0},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:bt,cutMargins:!1,wholeWalks:!1,available:J,drawsLocally:J,drawsNodes:!1},{value:"tubemapref",label:"Tube map on reference",description:"The tube map with each column at the reference bp it covers, so the tubes line up with the tracks around them. Needs P or W lines and a reference path.",run:gt,cutMargins:!0,wholeWalks:!1,available:Rt,drawsLocally:Rt,drawsNodes:!1},{value:"force",label:Ot,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1,drawsNodes:!0}],Ee=ge.map(e=>e.value);function Tn(e,t){return!_t(e).drawsLocally(t)}function _t(e){return ge.find(t=>t.value===e)??ge[0]}function Tt(e,t){let n=e.nodes.filter(l=>k(l)&&(t[l.id]?.length??0)>0);if(n.length<2)return t;let s=n.map(l=>{let m=t[l.id],y=m[Math.floor(m.length/2)];return{x:y.x,y:y.y,r:l.stable.start+l.length/2,w:l.length}}),r=s.reduce((l,m)=>l+m.w,0),o=s.reduce((l,m)=>l+m.x*m.w,0)/r,a=s.reduce((l,m)=>l+m.y*m.w,0)/r,i=s.reduce((l,m)=>l+m.r*m.w,0)/r,p=0,d=0;for(let l of s)p+=l.w*(l.x-o)*(l.r-i),d+=l.w*(l.y-a)*(l.r-i);let f=-Math.atan2(d,p),c=Math.cos(f),u=Math.sin(f),b={};for(let[l,m]of Object.entries(t))b[l]=m.map(y=>{let L=y.x-o,R=y.y-a;return{x:o+c*L-u*R,y:a+u*L+c*R}});let w=0,x=0;for(let l of e.nodes)if(!k(l))for(let m of b[l.id]??[])m.y>a?w++:x++;if(x>w)for(let l of Object.values(b))for(let m of l)m.y=2*a-m.y;return b}var Pt=30;function Pn(e,t){let{opts:n}=t,s=new Map(t.nodes.map(u=>[u.id,me(n,u.length)])),r=u=>s.get(u)??n.minimumNodeLength,o=e.nodes.filter(k).sort((u,b)=>u.stable.start-b.stable.start),a=new Map,i=0;for(let u of o)a.set(u.id,{x:i,y:0}),i+=r(u.id)+n.edgeLength;let p=Z(e),d=new Map(o.map(u=>[u.id,0])),f=o.map(u=>u.id);for(let u of f){let b=a.get(u),w=d.get(u)+1;for(let x of p.get(u)??[])d.has(x)||(d.set(x,w),a.set(x,{x:b.x+r(u)/2,y:Pt*w}),f.push(x))}let c=0;for(let u of e.nodes)a.has(u.id)||a.set(u.id,{x:c++*i/e.nodes.length,y:Pt*3});return a}function Bt(e,t){let n=Pn(e,t);return t.nodes.map(s=>({...s,...n.get(s.id)}))}function Bn(e,t){let n=e.indexOf(":"),s=e.indexOf(":",n+1);if(n!==-1&&s!==-1){let r=e.slice(0,n),o=e.slice(n+1,s),a=e.slice(s+1);o==="i"||o==="f"?t[r]=+a:o==="Z"&&(t[r]=a)}}function re(e){let t={};for(let n of e)Bn(n,t);return t}function Gt(e){let{SN:t,SO:n,SR:s}=e.tags;return typeof t=="string"&&typeof n=="number"&&typeof s=="number"?{refName:t,start:n,rank:s}:void 0}var Ct=62,Cn=60;function Gn(e){let t=[],n="+",s=0;function r(o){o>s&&t.push({id:e.slice(s,o),strand:n})}for(let o=0;o<e.length;o++){let a=e.charCodeAt(o);(a===Ct||a===Cn)&&(r(o),n=a===Ct?"+":"-",s=o+1)}return r(e.length),t}function $t(e){let t={nodes:[],links:[],paths:[],walks:[],header:[],id:""};for(let n of e.split(`
2
+ `)){let s=n.endsWith("\r")?n.slice(0,-1):n;if(s.startsWith("H")){let[,...r]=s.split(" ");t.header.push(re(r))}else if(s.startsWith("S")){let[,r,...o]=s.split(" "),a,i,p,d=!1,f=o[0]??"*";/^\d+$/.test(f)?(a=+f,i=o[1]??"*",p=o.slice(2)):(d=!0,i=f,a=i==="*"?0:i.length,p=o.slice(1));let c=re(p);d&&"LN"in c&&(a=+c.LN),t.nodes.push({id:r,length:a,sequence:i,tags:c})}else if(s.startsWith("E")){let[,,r,o,,,,,a,...i]=s.split(" ");r&&o&&t.links.push({source:r.slice(0,-1),target:o.slice(0,-1),strand1:r.at(-1),strand2:o.at(-1),cigar:a??"*",tags:re(i)})}else if(s.startsWith("L")){let[,r,o,a,i,p,...d]=s.split(" ");r&&a&&i&&t.links.push({source:r,target:a,strand1:o,strand2:i,cigar:p??"*",tags:re(d)})}else if(s.startsWith("W")){let[,r,o,a,i,p,d,...f]=s.split(" ");r&&o&&a&&i&&p&&d&&t.walks.push({sample:r,haplotype:+o,contig:a,start:i==="*"?-1:+i,end:p==="*"?-1:+p,segments:Gn(d),tags:re(f)})}else if(s.startsWith("P")){let[,r,o,...a]=s.split(" ");r&&o&&t.paths.push({name:r,path:o,rest:a})}}return t}function $n(e){let t=new Map,n=new Map;function s(o,a){t.has(o)||t.set(o,a)}function r(o,a){let i=n.get(o);i===void 0&&s(o,a),n.set(o,(i??0)+1)}for(let o of e.links)s(o.source,o.strand1==="-"?"-":"+"),s(o.target,o.strand2==="-"?"-":"+");for(let o of e.paths)for(let a of o.path.split(","))r(a.slice(0,-1),a.endsWith("-")?"-":"+");for(let o of e.walks)for(let a of o.segments)r(a.id,a.strand==="-"?"-":"+");return{canonical:t,traversals:n}}var Wt=e=>e.start===-1?0:e.start,Wn=e=>e.strand==="+"||e.strand==="-";function Xn(e){return[...e.paths.map(t=>({...P(t.name),steps:t.path.split(",").map(n=>({id:n.slice(0,-1),strand:n.endsWith("-")?"-":"+"}))})),...e.walks.map(t=>({name:`${t.sample}#${t.haplotype}#${t.contig}`,start:Wt(t),steps:t.segments.every(Wn)?t.segments:t.segments.map(n=>({id:n.id,strand:n.strand==="-"?"-":"+"}))}))]}function Yn(e){let t=e.tags.SM;if(typeof t!="string")return;let n=t.split(",").map(s=>s.trim()).filter(Boolean);return n.length>0?n:void 0}var se=e=>typeof e=="number"&&e>0?e:void 0;function Hn({tags:e,length:t}){let n=se(e.RC)??se(e.FC)??se(e.KC);return se(e.dp)??se(e.DP)??(n!==void 0&&t>0?n/t:void 0)}function Vn(e,t,n){return{id:`${e.id}${t}`,name:e.id,length:e.length,depth:n,stable:Gt(e),samples:Yn(e)}}function Xt(e,t="Imported GFA"){let n=[],s=[],{canonical:r,traversals:o}=$n(e),a=new Map,i=l=>{let m=a.get(l);return m===void 0&&(m=`${l}${r.get(l)??"+"}`,a.set(l,m)),m};for(let l of e.nodes){let m=Hn(l)??Math.max(o.get(l.id)??1,1);n.push(Vn(l,r.get(l.id)??"+",m))}for(let l of e.links)s.push({from:i(l.source),to:i(l.target),fromStrand:l.strand1==="-"?"-":"+",toStrand:l.strand2==="-"?"-":"+"});let p=[],d=new Map,f=(l,m)=>d.get(l)?.get(m);function c(l,m,y){let L=d.get(l);L||(L=new Map,d.set(l,L)),L.set(m,y)}let u=s.map(l=>{let m=f(l.from,l.to);return m||(m=new Set,c(l.from,l.to,m),c(l.to,l.from,m)),m});function b(l,m){for(let y=0;y<l.length-1;y++)f(l[y],l[y+1])?.add(m)}for(let l of e.paths){let m=l.path.split(",").map(y=>i(y.slice(0,-1)));p.push({name:l.name,nodeIds:m,start:P(l.name).start}),b(m,l.name)}for(let l of e.walks){let m=l.segments.map(L=>i(L.id)),y=`${l.sample}#${l.haplotype}#${l.contig}`;p.push({name:y,nodeIds:m,start:Wt(l),sample:l.sample,haplotype:l.haplotype,contig:l.contig}),b(m,y)}s.forEach((l,m)=>{let y=u[m];y.size>0&&(l.pathIds=[...y])});let w=new Map(e.nodes.map(l=>[l.id,l.length])),x=e.paths.length>0||e.walks.length>0?Ue(Xn(e),l=>w.get(l)??0):void 0;return{name:t,nodes:n,edges:s,paths:p.length>0?p:void 0,anchorPaths:x?.anchorPaths,pathVisits:x?.pathVisits,anchoredBy:n.some(l=>l.stable)?"tags":void 0}}function Fn(e){let[t="",n="",...s]=e.split("#");return{sample:t,haplotype:n,contig:s.join("#")}}function Yt({nodes:e,links:t,walks:n},s="Imported GFA"){let r=e.names.length,o=e.lengths.length,a=new Uint8Array(r),i=(g,v)=>{a[g]===0&&(a[g]=v?2:1)};for(let g=0;g<t.from.length;g++)i(t.from[g],t.strands[g]&1),i(t.to[g],t.strands[g]&2);let p=[];for(let g=0;g<n.names.length;g++)n.offsets[g+1]>n.offsets[g]&&p.push(g);let d=new Int32Array(r);for(let g of p)for(let v=n.offsets[g];v<n.offsets[g+1];v++){let M=n.steps[v];d[M]===0&&i(M,n.reversed[v]),d[M]++}let f=e.names.map((g,v)=>`${g}${a[v]===2?"-":"+"}`),c=[];for(let g=0;g<o;g++){let v=e.refs[g];c.push({id:f[g],name:e.names[g],length:e.lengths[g],depth:Math.max(d[g],1),stable:v<0?void 0:{refName:e.refNames[v],start:e.starts[g],rank:e.ranks[g]},samples:void 0})}let u=[],b=new Array(r),w=(g,v)=>{let M=b[g];if(M){for(let S=0;S<M.length;S+=2)if(M[S]===v)return M[S+1]}},x=(g,v,M)=>{let S=b[g];S?S.push(v,M):b[g]=[v,M]},l=[],m=0;for(let g=0;g<t.from.length;g++){let v=t.from[g],M=t.to[g];u.push({from:f[v],to:f[M],fromStrand:t.strands[g]&1?"-":"+",toStrand:t.strands[g]&2?"-":"+"});let S=w(v,M);S===void 0&&(S=m++,x(v,M,S),x(M,v,S)),l.push(S)}let y=new Map,L=[],R=Array.from({length:m},()=>[]),B=new Int32Array(m).fill(-1),ce=[],W=[],X=new Array(r),le=new Int32Array(r),Y=[];for(let g of p){let{sample:v,haplotype:M,contig:S}=Fn(n.names[g]),E=`${v}#${+M}#${S}`,N=y.get(E),_=N!==void 0;N===void 0&&(N=L.length,y.set(E,N),L.push(E));let G=n.starts[g],U=q(E),Q=n.offsets[g],Te=new Array(n.offsets[g+1]-Q),ye=G,xe=-1;for(let ee=Q;ee<n.offsets[g+1];ee++){let T=n.steps[ee];if(Te[ee-Q]=f[T],le[T]===0&&(X[T]=new Array(d[T]),Y.push(T)),X[T][le[T]++]={path:E,sample:U,start:ye,strand:n.reversed[ee]?"-":"+"},ye+=T<o?e.lengths[T]:0,xe>=0){let pe=w(xe,T);if(pe!==void 0&&B[pe]!==g){B[pe]=g;let Pe=R[pe];(!_||!Pe.includes(N))&&Pe.push(N)}}xe=T}ce.push({name:E,nodeIds:Te,start:G,sample:v,haplotype:+M,contig:S}),W.push({name:E,sample:U,start:G,length:ye-G})}u.forEach((g,v)=>{let M=R[l[v]];M.length>0&&(g.pathIds=M.map(S=>L[S]))});let C=p.length>0;return{name:s,nodes:c,edges:u,paths:C?ce:void 0,anchorPaths:C?W:void 0,pathVisits:C?new Map(Y.map(g=>[e.names[g],X[g]])):void 0,anchoredBy:c.some(g=>g.stable)?"tags":void 0}}function Rs(e,t,n={}){let s=qe(typeof e=="string"?Xt($t(e),t):Yt(e,t),n.referencePath);if(s.nodes.length===0)throw new Error(`No graph segments in ${t}`);if(n.maxNodes!==void 0&&s.nodes.length>n.maxNodes)throw new Error(`Graph too large to draw: ${s.nodes.length.toLocaleString()} nodes (limit ${n.maxNodes.toLocaleString()}). Zoom in to a smaller region, or raise maxGraphNodes on this view.`);return s}var j={engine:"fmmm",quality:2,linearLayout:!1,bubbleSpread:"auto",spacing:1,componentSeparation:1,showDeletionEdges:!0};function As(e={}){return{engine:e.engine??j.engine,quality:e.quality??j.quality,linearLayout:e.linearLayout??j.linearLayout,bubbleSpread:e.bubbleSpread??j.bubbleSpread,spacing:e.spacing??j.spacing,componentSeparation:e.componentSeparation??j.componentSeparation,showDeletionEdges:e.showDeletionEdges??j.showDeletionEdges}}var Dn=15;function jn(e,t,n){let s=e.nodes.some(k),r={...t,opts:{...t.opts,edgeLength:t.opts.edgeLength*(n.spacing??1)}};return{graph:{nodes:s?Bt(e,r):r.nodes,edges:e.edges},options:{quality:n.quality,linearLayout:n.linearLayout,...r.opts,componentSeparation:Dn*(n.componentSeparation??1),...s?{rotateComponents:!1}:{},engine:n.engine??"fmmm"}}}function Ie(e,t){let n=e.nodes.some(k);return`${t.engine??"fmmm"}|${t.quality}|${t.linearLayout}|${t.bubbleSpread}|${t.spacing??1}|${t.componentSeparation??1}|${t.showDeletionEdges!==!1}|${n}|${e.referencePath??""}`}async function Ht(e,t,n){let s=ot(t.bubbleSpread),r=je(e),o=t.showDeletionEdges===!1?ze(e,r):new Set,a=r.filter(y=>!o.has(y.edgeIndex)),i=Ce(e,a,o),p=Fe(i.graph,i.ids),d={...p.graph,nodes:p.graph.nodes.filter(y=>!i.ids.has(y.id))},f=Me(d,s),{result:c,duration:u}=await n(jn(p.graph,{...f,nodes:[...f.nodes,...Ge(e,a,i.routes,tt(d,s),f.opts)]},t)),b=Me(e,s),w=new Map(b.nodes.map(y=>[y.id,me(b.opts,y.length)])),x=De(c.nodePositions,p.runs,y=>w.get(y)??0),{nodePositions:l,deletionRoutes:m}=$e(e.nodes.some(k)?Tt(e,x):x,i.routes);return{result:{...c,nodePositions:l,stranded:!0,...a.length?{deletionRoutes:m,extent:Vt(m)}:{}},duration:u}}function Vt(e){let t=1/0,n=1/0,s=-1/0,r=-1/0;for(let o of Object.values(e))for(let a of o)t=Math.min(t,a.x),n=Math.min(n,a.y),s=Math.max(s,a.x),r=Math.max(r,a.y);return{minX:t,minY:n,maxX:s,maxY:r}}var ae=40,zn=1e-6,Un=100;function Re(e){return Math.max(zn,Math.min(Un,e))}function qn(e,t,n,s=ae){let r=t-e.h*n;return s-e.minY*n+Math.max(0,r)/2}function Os(e,t,n,s,{minScale:r=0,padLeft:o=ae,padTop:a=ae,padRight:i=ae,padBottom:p=ae}={}){let d=t-o-i,f=n-a-p;if(d<=0||f<=0||!(e.w>0||!s&&e.h>0))return;let c=e.w>0?d/e.w:1/0,u=e.h>0?f/e.h:1/0,b=Re(Math.max(r,s?c:Math.min(c,u))),w=d-e.w*b;return{scale:b,translateX:o-e.minX*b+Math.max(0,w)/2,translateY:qn(e,f,s?1:b,a)}}function _s(e,t={}){let{minX:n,minY:s,maxX:r,maxY:o}=Vt(e.nodePositions),{region:a}=t;e.referenceAxis&&a&&a.end>a.start&&(n=a.start,r=a.end);let i=t.extent??e.extent;return i&&(n=Math.min(n,i.minX??n),s=Math.min(s,i.minY??s),r=Math.max(r,i.maxX??r),o=Math.max(o,i.maxY??o)),{minX:n,minY:s,w:r-n,h:o-s}}var Kn=4;function Ae(e=Kn){let t=new WeakMap,n=s=>{let r=t.get(s);return r||(r=new Map,t.set(s,r)),r};return{layout(s,r,o){let a=n(s),i=Ie(s,r),p=a.get(i);if(p)return p.run;a.size>=e&&a.delete(a.keys().next().value);let d=performance.now(),f={run:Ht(s,r,o).then(c=>(f.done=c.result,{...c,duration:c.duration||performance.now()-d}))};return f.run.catch(()=>a.delete(i)),a.set(i,f),f.run},ready(s,r){return t.get(s)?.get(Ie(s,r))?.done},inherit(s,r){let o=t.get(s);o&&s!==r&&t.set(r,o)}}}function Zn(e,t){return{scaleX:e,scaleY:t?1:e,pixelRows:t}}function Oe(e,t,n,s){return{minX:-e.translateX/t.scaleX,minY:-e.translateY/t.scaleY,maxX:(n-e.translateX)/t.scaleX,maxY:(s-e.translateY)/t.scaleY}}function Jn(e,t){let n=(e.maxX-e.minX)*t,s=(e.maxY-e.minY)*t;return{minX:e.minX-n,minY:e.minY-s,maxX:e.maxX+n,maxY:e.maxY+s}}function Qn(e,t){return t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY}function eo(e,t,n,s,r){let o=Re(e.scale*t),a=o/e.scale;return{scale:o,translateX:n-(n-e.translateX)*a,translateY:r?e.translateY:s-(s-e.translateY)*a}}var z=JBrowseExports["@jbrowse/render-core/RenderLifecycleMixin"],to=e=>z!=null&&e in Object(z)?z[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/render-core/RenderLifecycleMixin' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),Ft=to("RenderLifecycleMixin"),Sa=z&&z.__esModule?z.default:z;function Dt(e){return t=>e.includes(t)?t:void 0}function _e(e){return h.snapshotProcessor(h.maybe(h.enumeration(e)),{preProcessor:Dt(e)})}function we(e,t){return h.snapshotProcessor(h.optional(h.enumeration(e),t),{preProcessor:Dt(e)})}var Xa=600,Ya=160,Ha=[1,1,1,1],Va=[.12,.12,.12,1],Fa=([e,t,n])=>`rgb(${[e,t,n].map(s=>Math.round(s*255)).join(", ")})`,Da=5,ja=new Set(["tubemap","tubemapref"]),za=ue(()=>import("./ChooseSamplesDialog-75F3KRRG.js")),Ua=ue(()=>import("./ChooseWalksDialog-L23LYMKI.js")),qa=ue(()=>import("./HighlightColorDialog-CU5FQLRJ.js")),Ka=12,no=h.snapshotProcessor(h.model("GraphFacet",{field:h.optional(h.enumeration(["","walk","sample"]),""),domain:h.optional(h.frozen(),[]),columns:h.maybe(h.number)}),{preProcessor:e=>et(e)}),Za=[{bp:0,label:"None"},{bp:3,label:"Under 3 bp"},{bp:10,label:"Under 10 bp"},{bp:50,label:"Under 50 bp, leaving structural variants"},{bp:1e3,label:"Under 1 kb"}],jt=".segs.bed.gz";function Ja(e){if(typeof e.uri=="string")return e.uri;let n=e.segmentsLocation?.uri;return typeof n=="string"&&n.endsWith(jt)?n.slice(0,-jt.length):void 0}var Qa=1.15,ei=1.6,ti=150,ni=1,oi=40,ri={nodeStrokes:[],nodeStrokeRuns:new Map,arrows:[],arrowRuns:new Map,edgeCurves:[],edgeCurveRuns:new Map};function si(...e){}var ai=5e6;function ii(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:`${Math.round(e/1e3)} kb`}var oo=2e4;function ci(e){return("uri"in e?e.uri.split(/[?#]/)[0]:"localPath"in e?e.localPath:"name"in e?e.name:"").split(/[\\/]/).at(-1)??""}function li(e){return e&&"uri"in e&&e.uri?new URL(e.uri,e.baseUri??window.location.href).href:void 0}function pi(e){return e.builtViewport!==void 0&&e.paintedViewport===e.builtViewport&&e.builtViewport.viewportDirty===e.viewportDirty&&!e.viewportRebuildPending}function fi(e){let{width:t,height:n}=e.viewBox;return Oe(e,e.axisScale,t,n)}var di=Ae(),ui=h.compose("GraphPane",Ft(),h.model({layoutQuality:h.optional(h.number,2),layoutEngine:we(We,"fmmm"),linearLayout:h.optional(h.boolean,!1),layoutMode:_e(Ee),colorScheme:_e(Qe),highlightOnHover:h.maybe(h.boolean),bubbleSpread:we(nt,"auto"),nodeWidth:we(rt,"depth"),showBubbles:h.optional(h.boolean,!1),showDeletionEdges:h.optional(h.boolean,!0),showGenes:h.optional(h.boolean,!0),showReferenceStrip:h.optional(h.boolean,!0),tubeMapFold:h.optional(h.number,0),geneTrackId:h.optional(h.string,""),repeatTrackId:h.optional(h.string,""),repeatKey:h.optional(h.string,""),walkRowSamples:h.maybe(h.frozen()),walkRowGroupBy:h.maybe(h.snapshotProcessor(h.frozen(),{preProcessor:e=>st(e)})),walkStrip:h.optional(h.boolean,!1),walkLayers:h.optional(h.frozen(),[]),facet:h.optional(no,{}),referencePath:h.optional(h.string,""),showPerf:h.optional(h.boolean,!1),contigThickness:h.optional(h.number,6),connectorThickness:h.optional(h.number,2),darkMode:h.optional(h.boolean,!1),scale:h.optional(h.number,1),translateX:h.optional(h.number,0),translateY:h.optional(h.number,0),drawPaths:h.optional(h.boolean,!1),paneHeight:h.maybe(h.number),maxGraphNodes:h.optional(h.number,oo),colorDomain:h.maybe(h.frozen()),connectedViewId:h.maybe(h.string)})).volatile(()=>({graph:void 0,walkCut:void 0,graphRegion:void 0,loadedReferencePath:void 0,layoutResult:void 0,legendSize:{width:0,height:0},indexBubbles:void 0,geneTrackFeatures:void 0,walkGeneFeatures:void 0,walkRowSampleTable:void 0,repeatArrays:void 0,popStack:[],error:void 0,isLoading:!1,loadCanceled:!1,statusMessage:"",hoveredNode:null,hoveredRowWalks:[],hoveredBubble:null,pointerInPane:!1,stripHover:null,hoveredWalkRow:null,hoveredEdge:null,selectedNode:null,viewportDirty:0,positionsVersion:0,geometryVersion:0,builtViewport:void 0,paintedViewport:void 0,draggingNode:null,isPanning:!1,viewportOwner:"fit",viewportDirtyTimer:void 0,positionsDirtyFrame:0,lastFetchMs:void 0,readsShown:void 0,lastLayoutMs:void 0,lastGeometryMs:void 0,lastGeometryStrokeCount:void 0,viewportRebuildPending:!1}));function ro(e){return e.walkStrip&&e.mode.drawsNodes&&!e.drawsPicture&&!e.popped&&!e.host&&e.walks>1}function so(e,t){return e.wholeWalks||t.walkStrip&&!t.host}var ie=6,qt=260,ao=11,io=3,co=1.3,lo="#111",zt=3;function po(e,t,n){let s=e.pathVisits?.get(n.name)??[],r=[];for(let o of t){let a=o.axis;if(!a)continue;let i=P(o.name).name;for(let p of s){if(p.path!==i)continue;let{start:d,end:f}=at(a,p.start,p.start+n.length);f>0&&d<o.bp&&r.push({row:o.name,start:d,bp:f-d})}}return r}var Ut=new WeakMap;function fo(e,t){let n=Ut.get(e);if(n||(n=new Map,Ut.set(e,n)),n.has(t))return n.get(t);let s=new Map(e.nodes.map(a=>[a.id,a.length])),r=(e.paths??[]).filter(a=>a.name===t),o;if(r.every(a=>a.start!==void 0)){o={ids:[],starts:[],ends:[]};for(let a of[...r].sort((i,p)=>i.start-p.start)){let i=a.start;for(let p of a.nodeIds){let d=s.get(p)??0;o.ids.push(p),o.starts.push(i),o.ends.push(i+d),i+=d}}}return n.set(t,o),o}function uo(e,t,n,s){let r=t.axis,o=r&&fo(e,t.name);if(!r||!o||n<0||n>t.bp)return;let a=r.reversed?r.start-n:r.start+n,i=.5/s,p=r.reversed?{start:r.start-t.bp,end:r.start}:{start:r.start,end:r.start+t.bp},d=Math.max(a-i,p.start),f=Math.min(a+i,p.end),c=0,u=o.starts.length;for(;c<u;){let l=c+u>>1;o.ends[l]<=d?c=l+1:u=l}let b,w=-1,x=!1;for(let l=c;l<o.starts.length&&o.starts[l]<f;l++){let m=o.ends[l]-o.starts[l],y=o.starts[l]<=a&&a<o.ends[l];(m>w||m===w&&y&&!x)&&(w=m,b=o.ids[l],x=y)}return b}function mo(e,t){let n=t.maxHeight??qt,s=t.labelPx??Math.max(...[e.reference,...e.rows].map(b=>b.label.length))*Ve+16,r=e.rows.length+1,{rowPx:o,barPx:a,labelled:i,readouts:p}=ct(r,n-2*ie,io),d=Math.max(e.reference.bp,...e.rows.map(b=>b.bp),1),f=i?s:ie,u=Math.max(1,t.width-f-ie)/(d*(p?co:1));return{scaleX:u,scaleY:1,translateX:f-e.origin*u,translateY:ie+o/2,width:t.width,height:r*o+2*ie,rowPx:o,barPx:a,readouts:p,labelled:i,boxesGenes:it(o,a)}}function ho(e,t,n,s){let r=Math.round((s-t.translateY)/t.rowPx),o=[e.reference,...e.rows][r],a=(n-t.translateX)/t.scaleX-e.origin;return o&&r>=0&&a>=0&&a<=o.bp?{index:r,row:o,offset:a}:void 0}function bo(e,t,n){let s=new Map([e.reference,...e.rows].map((o,a)=>[o.name,a])),r=o=>(e.origin+o)*t.scaleX+t.translateX;return oe("g",{"data-testid":"graph-walk-marks"},...n.flatMap(o=>{let a=s.get(o.row);if(a===void 0)return[];let i=a*t.rowPx+t.translateY,p=r(o.start),d=Math.max(2,o.bp*t.scaleX),f=c=>oe("rect",{x:p,y:c,width:d,height:zt,fill:lo});return[f(i-t.barPx/2-zt-1),f(i+t.barPx/2+1)]}))}function go(e,t,n=new Set){return oe("g",{"font-family":"sans-serif","font-size":ao,fill:"#333"},...(t.labelled?[e.reference,...e.rows]:[]).map((s,r)=>oe("text",{x:6,y:r*t.rowPx+t.translateY+4,"font-weight":n.has(s.name)?600:void 0},s.label)))}function wo(e,t,n){if(t?.size)return e.boxesGenes?n:{untracked:0,unread:0,...n,crowded:!0}}var Vi=I(A("path",{d:"M19 15.18V7c0-2.21-1.79-4-4-4s-4 1.79-4 4v10c0 1.1-.9 2-2 2s-2-.9-2-2V8.82C8.16 8.4 9 7.3 9 6c0-1.66-1.34-3-3-3S3 4.34 3 6c0 1.3.84 2.4 2 2.82V17c0 2.21 1.79 4 4 4s4-1.79 4-4V7c0-1.1.9-2 2-2s2 .9 2 2v8.18c-1.16.41-2 1.51-2 2.82 0 1.66 1.34 3 3 3s3-1.34 3-3c0-1.3-.84-2.4-2-2.82"}),"Route");var zi=I(A("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");var Zi=I(A("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5M12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5m0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"}),"Visibility");export{I as a,on as b,Mn as c,Mr as d,Nt as e,_n as f,Er as g,ge as h,Ee as i,Tn as j,_t as k,Zi as l,Rs as m,j as n,As as o,ae as p,Re as q,qn as r,Os as s,_s as t,Zn as u,Jn as v,Qn as w,eo as x,Xa as y,Ya as z,Ha as A,Va as B,Fa as C,Da as D,ja as E,za as F,Ua as G,qa as H,Ka as I,Za as J,Ja as K,Qa as L,ei as M,ti as N,ni as O,oi as P,ri as Q,si as R,ai as S,ii as T,ci as U,li as V,pi as W,fi as X,di as Y,ui as Z,ro as _,so as $,po as aa,uo as ba,mo as ca,ho as da,bo as ea,go as fa,wo as ga,Ro as ha,Ao as ia,Qt as ja,Oo as ka,_o as la,Se as ma,Le as na,zo as oa,Uo as pa,Vi as qa,zi as ra};
3
+ //# sourceMappingURL=chunk-5DRS22TL.js.map