jbrowse-plugin-graphgenomeviewer 4.0.19 → 4.0.21

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 (38) hide show
  1. package/README.md +2 -1
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-KKSNCZXY.js → GbzBaseSyntenyAdapter-7ZKFAEJG.js} +2 -2
  3. package/dist/chunks/{GbzBaseSyntenyAdapter-KKSNCZXY.js.map → GbzBaseSyntenyAdapter-7ZKFAEJG.js.map} +2 -2
  4. package/dist/chunks/{GraphGenomeView-37F7MLFQ.js → GraphGenomeView-CLUMXH4K.js} +2 -2
  5. package/dist/chunks/{GraphTrackSettingsDialog-2QV6TPX7.js → GraphTrackSettingsDialog-QF5OMTCH.js} +2 -2
  6. package/dist/chunks/{LinearGraphDisplay-CJHA56RB.js → LinearGraphDisplay-4CMVCEM5.js} +2 -2
  7. package/dist/chunks/chunk-3FGJLRG2.js +2 -0
  8. package/dist/chunks/chunk-3FGJLRG2.js.map +7 -0
  9. package/dist/chunks/chunk-3SZJ4AFI.js +3 -0
  10. package/dist/chunks/chunk-3SZJ4AFI.js.map +7 -0
  11. package/dist/chunks/{chunk-5E7TVPCI.js → chunk-CLRXQ6BM.js} +2 -2
  12. package/dist/chunks/chunk-VIFXYTIS.js +2 -0
  13. package/dist/chunks/chunk-VIFXYTIS.js.map +7 -0
  14. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
  15. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
  16. package/package.json +2 -2
  17. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +1 -1
  18. package/src/GetSubgraph.ts +3 -0
  19. package/src/GraphGenomeView/components/BubbleHalos.tsx +3 -4
  20. package/src/GraphGenomeView/components/GraphCanvas.tsx +51 -15
  21. package/src/GraphGenomeView/components/LabelLayer.tsx +5 -6
  22. package/src/GraphGenomeView/components/WalkSelect.tsx +26 -13
  23. package/src/GraphGenomeView/model.test.ts +48 -0
  24. package/src/GraphGenomeView/model.ts +75 -21
  25. package/src/GraphGenomeView/viewModel.ts +15 -0
  26. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +23 -2
  27. package/src/LinearGraphDisplay/model.ts +7 -2
  28. package/src/version.ts +1 -1
  29. package/dist/chunks/chunk-BI3M6FZD.js +0 -2
  30. package/dist/chunks/chunk-BI3M6FZD.js.map +0 -7
  31. package/dist/chunks/chunk-IUIIYSGF.js +0 -2
  32. package/dist/chunks/chunk-IUIIYSGF.js.map +0 -7
  33. package/dist/chunks/chunk-MNOQXDMY.js +0 -3
  34. package/dist/chunks/chunk-MNOQXDMY.js.map +0 -7
  35. /package/dist/chunks/{GraphGenomeView-37F7MLFQ.js.map → GraphGenomeView-CLUMXH4K.js.map} +0 -0
  36. /package/dist/chunks/{GraphTrackSettingsDialog-2QV6TPX7.js.map → GraphTrackSettingsDialog-QF5OMTCH.js.map} +0 -0
  37. /package/dist/chunks/{LinearGraphDisplay-CJHA56RB.js.map → LinearGraphDisplay-4CMVCEM5.js.map} +0 -0
  38. /package/dist/chunks/{chunk-5E7TVPCI.js.map → chunk-CLRXQ6BM.js.map} +0 -0
package/README.md CHANGED
@@ -30,7 +30,8 @@ session spec does the same with `loadedTrackId` and `loadedRegion`.
30
30
  walk rows, and sequenceTubeMap's tube map on its own axis or the reference's
31
31
  - Genes from the session's annotation track, drawn on the graph
32
32
  - Bubbles from `gfatools bubble` or the graph itself, opened level by level
33
- - gbz-base haplotypes as walks: carriage as node thickness, one walk lifted out
33
+ - gbz-base haplotypes as walks: carriage as node thickness, several walks lifted
34
+ out at once, each lane coloured by progress, reference position or strand
34
35
  - GAF reads in the tube map, with their mismatches, from a gbz-base track
35
36
 
36
37
  ## Usage
@@ -4,5 +4,5 @@ import{a as Ir,b as Ar,c as Rr,d as Ts}from"./chunk-JAQ2RQAE.js";import{a as Cr}
4
4
  `)}
5
5
  `}outputPaths(e){let t=e.cigar??!1,r=[],o=this.refPath?.contig??"unknown";if(this.refId!==void 0&&this.refPath&&this.refInterval){let i={...this.refPath,fragment:this.refPath.fragment+this.refInterval[0]};r.push({info:this.paths[this.refId],identity:void 0,name:ge(i,this.refPath.fragment+this.refInterval[1]),cigar:void 0})}let s=1;return this.paths.forEach((i,a)=>{if(a===this.refId)return;let f=e.names==="resolved"?i.identity:void 0;r.push({info:i,identity:f,name:f?ge({...f.name,fragment:f.name.fragment+f.hapStart},f.name.fragment+f.hapEnd):ge({sample:"unknown",contig:o,haplotype:s,fragment:0},i.len),cigar:t?this.alignToRef(a):void 0}),s+=1}),r}*outputEdges(){for(let e of this.sortedHandles())for(let t of this.record(e).successors())this.hasHandle(t)&&We(e,t)&&(yield[e,t])}toSubgraphJson(e={}){let t=this.sortedHandles().filter(s=>!q(s)).map(s=>({id:String(_(s)),sequence:this.record(s).sequence})),r=[];for(let[s,i]of this.outputEdges())r.push({from:String(_(s)),from_is_reverse:q(s),to:String(_(i)),to_is_reverse:q(i)});let o=this.outputPaths(e).map(s=>pi(s.info,s.identity,s.name,s.cigar));return{nodes:t,edges:r,paths:o}}toCompactSubgraph(e={}){let t=this.sortedHandles().filter(i=>!q(i)),r=new Int32Array(t.length),o=[];t.forEach((i,a)=>{r[a]=_(i),o.push(this.record(i).sequence)});let s=[];for(let[i,a]of this.outputEdges())s.push(i,a);return{nodeIds:r,nodeSequences:o,edges:Int32Array.from(s),paths:this.outputPaths(e).map(i=>({name:i.name,weight:i.info.weight,cigar:i.cigar,steps:Int32Array.from(Lt(i.info,i.identity))}))}}};function Lt(n,e){return e?.orientation==="reverse"?n.path.map(t=>K(t)).reverse():n.path}function pi(n,e,t,r){return{name:t,...n.weight===void 0?{}:{weight:n.weight},...r===void 0?{}:{cigar:r},path:Lt(n,e).map(o=>({id:String(_(o)),is_reverse:q(o)}))}}function Dn(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++){let o=n[r],s=e[r];if(o!==s)return o<s?-1:1}return n.length-e.length}function se(n,e,t){if(t===0)return;let r=n[n.length-1];r?.[0]===e?r[1]+=t:n.push([e,t])}function Ot(n){return n===0?0:6+(n-1)}function uo(n,e,t){if(e===0)se(n,"D",t);else if(t===0)se(n,"I",e);else{let r=Math.min(e,t),o=4*r+Ot(e-r)+Ot(t-r),s=Ot(e)+Ot(t);o<=s?(se(n,"M",r),se(n,"I",e-r),se(n,"D",t-r)):(se(n,"I",e),se(n,"D",t))}}function hi(n){return n.map(([e,t])=>`${t}${e}`).join("")}async function mo(n,e,t,r,o){let s=new Tt(n,o);try{let i=await s.pathPosition(Et(e,t));return await s.prefetchReferenceWalk(i,r-t),await s.aroundInterval(i.position,r-t,o.context??100),await s.extractSnarls(o.snarls??"none"),{subgraph:s,reference:i}}catch(i){throw i instanceof Me&&i.windowBp===void 0?new Me(i.limit,{windowBp:r-t,walkedBp:s.referenceWalkedBp??0}):i}}async function go(n,e,t,r,o={}){let{subgraph:s,reference:i}=await mo(n,e,t,r,o);return s.extractPaths(i,o.haplotypes??"all"),s}async function wo(n,e,t,r,o){if(!n.hasHaplotypeIndex)throw new Error("keep needs the haplotype index: this database cannot name its walks");let{subgraph:s,reference:i}=await mo(n,e,t,r,o),a=o.haplotypes??"all";return(a!=="all"||!await s.extractChosenPaths(i,r-t,o.keep))&&(s.extractPaths(i,a),await s.identifyPaths()),s.keepHaplotypes(o.keep),s}function xe(n,e){let t=0;for(let o=0;o<8;o++){let s=n[e+o];if(s===void 0)throw new Error("SQLite varint runs past the end of the buffer");if(t=t*128+(s&127),(s&128)===0)return[t,e+o+1]}let r=n[e+8];if(r===void 0)throw new Error("SQLite varint runs past the end of the buffer");if(t=t*256+r,!Number.isSafeInteger(t))throw new Error("SQLite varint exceeds the safe integer range");return[t,e+9]}function di(n,e,t){switch(t){case 1:return n.getInt8(e);case 2:return n.getInt16(e);case 3:return n.getInt8(e)<<16|n.getUint16(e+1);case 4:return n.getInt32(e);case 6:return n.getInt16(e)*4294967296+n.getUint32(e+2);default:{let r=n.getBigInt64(e);if(r>BigInt(Number.MAX_SAFE_INTEGER)||r<BigInt(Number.MIN_SAFE_INTEGER))throw new Error(`SQLite integer ${r} exceeds the safe integer range`);return Number(r)}}}var ui=new TextDecoder;function Nt(n){let[e,t]=xe(n,0),r=[],o=t;for(;o<e;){let[a,f]=xe(n,o);r.push(a),o=f}let s=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e;return r.map(a=>{if(a===0)return null;if(a>=1&&a<=6){let f=a<=4?a:a===5?6:8,c=di(s,i,f);return i+=f,c}if(a===7){let f=s.getFloat64(i);return i+=8,f}if(a===8)return 0;if(a===9)return 1;if(a>=12){let f=a-12>>1,c=n.subarray(i,i+f);return i+=f,a%2===0?c:ui.decode(c)}throw new Error(`SQLite serial type ${a} is reserved`)})}var ot=2,qt=5,xo=10,Ft=13;function bo(n,e){return n[e]*256+n[e+1]}function _e(n,e){return n[e]*16777216+n[e+1]*65536+n[e+2]*256+n[e+3]}function mi(n,e){let t=n[e];if(t!==ot&&t!==qt&&t!==xo&&t!==Ft)throw new Error(`SQLite page has unknown b-tree type ${t}`);let r=t===ot||t===qt;return{type:t,cellCount:bo(n,e+3),rightChild:r?_e(n,e+8):0,cellPointers:e+(r?12:8)}}function Re(n,e,t){return bo(n,e.cellPointers+2*t)}var gi=4096,wi=4096,$t=class{usable;pager;decodedIndexPages=new Map;tableDepths=new Map;constructor(e,t){this.pager=e,this.usable=e.pageSize-t}localPayloadSize(e,t){let r=this.usable,o=t?Math.floor((r-12)*64/255)-23:r-35;if(e<=o)return e;let s=Math.floor((r-12)*32/255)-23,i=s+(e-s)%(r-4);return i<=o?i:s}async payload(e,t,r,o){let s=this.localPayloadSize(r,o);if(s===r)return e.subarray(t,t+r);let i=new Uint8Array(r);i.set(e.subarray(t,t+s),0);let a=s,f=_e(e,t+s);for(;f!==0&&a<r;){let c=await this.pager.page(f),l=c.subarray(4,4+Math.min(this.usable-4,r-a));i.set(l,a),a+=l.length,f=_e(c,0)}if(a!==r)throw new Error("SQLite overflow chain ended before the payload was complete");return i}async pageAt(e){let t=await this.pager.page(e);return{page:t,header:mi(t,e===1?100:0)}}tableDepth(e,t){let r=this.tableDepths.get(e);return r||(r=(async()=>{let o=e;for(let s=0;;s++){let{page:i,header:a}=await this.pageAt(o);if(a.type===Ft)return s;if(a.type!==qt)throw new Error("SQLite table b-tree contains an index page");let f=this.childIndexFor(i,a,t);o=f===a.cellCount?a.rightChild:_e(i,Re(i,a,f))}})(),this.tableDepths.set(e,r),r.catch(()=>this.tableDepths.delete(e))),r}childIndexFor(e,t,r){let o=0,s=t.cellCount;for(;o<s;){let i=o+s>>1,[a]=xe(e,Re(e,t,i)+4);a<r?o=i+1:s=i}return o}async prefetchRowidRange(e,t,r){let o=await this.tableDepth(e,t),s=[e];for(let i=0;i<o;i++){let a=await Promise.all(s.map(c=>this.pageAt(c))),f=[];if(a.forEach(({page:c,header:l},p)=>{let u=p===0?this.childIndexFor(c,l,t):0,d=p===a.length-1?this.childIndexFor(c,l,r):l.cellCount;for(let h=u;h<=d;h++)f.push(h===l.cellCount?l.rightChild:_e(c,Re(c,l,h)))}),f.length>wi)return!1;this.pager.prefetch(f),s=f}return!0}async tableRowid(e,t){let r=e;for(;;){let{page:o,header:s}=await this.pageAt(r);if(s.type===Ft){let f=0,c=s.cellCount;for(;f<c;){let l=f+c>>1,p=Re(o,s,l),[u,d]=xe(o,p),[h,m]=xe(o,d);if(h===t)return Nt(await this.payload(o,m,u,!1));h<t?f=l+1:c=l}return}if(s.type!==qt)throw new Error("SQLite table b-tree contains an index page");let i=0,a=s.cellCount;for(;i<a;){let f=i+a>>1,c=Re(o,s,f),[l]=xe(o,c+4);l<t?i=f+1:a=f}r=i===s.cellCount?s.rightChild:_e(o,Re(o,s,i))}}async*tableScan(e){let{page:t,header:r}=await this.pageAt(e);if(r.type===Ft)for(let o=0;o<r.cellCount;o++){let s=Re(t,r,o),[i,a]=xe(t,s),[f,c]=xe(t,a);yield{rowid:f,values:Nt(await this.payload(t,c,i,!1))}}else{let o=[];for(let s=0;s<r.cellCount;s++)o.push(_e(t,Re(t,r,s)));o.push(r.rightChild),this.pager.prefetch(o);for(let s of o)yield*this.tableScan(s)}}decodedCells(e,t){let r=this.decodedIndexPages.get(e);if(r)this.decodedIndexPages.delete(e);else if(r=new Array(t.cellCount),this.decodedIndexPages.size>=gi){let o=this.decodedIndexPages.keys().next().value;o!==void 0&&this.decodedIndexPages.delete(o)}return this.decodedIndexPages.set(e,r),r}async indexCell(e,t,r,o){let s=this.decodedCells(e,r),i=s[o];if(!i){let a=Re(t,r,o),f=r.type===ot,[c,l]=xe(t,f?a+4:a);i={values:Nt(await this.payload(t,l,c,!0)),leftChild:f?_e(t,a):0},s[o]=i}return i}async*indexScanFrom(e,t){let{page:r,header:o}=await this.pageAt(e),s=0,i=o.cellCount;for(;s<i;){let a=s+i>>1,f=await this.indexCell(e,r,o,a);yo(f.values,t)<0?s=a+1:i=a}for(let a=s;a<o.cellCount;a++){let f=await this.indexCell(e,r,o,a);o.type===ot&&(yield*this.indexScanFrom(f.leftChild,t)),yield f.values}o.type===ot&&(yield*this.indexScanFrom(o.rightChild,t))}async indexSeekLE(e,t){let r,o=e;for(;;){let{page:s,header:i}=await this.pageAt(o),a=0,f=i.cellCount,c=0;for(;a<f;){let l=a+f>>1,p=await this.indexCell(o,s,i,l);yo(p.values,t)<=0?(r=p.values,a=l+1):(c=p.leftChild,f=l)}if(i.type===xo)return r;o=a===i.cellCount?i.rightChild:c}}};function yo(n,e){for(let t=0;t<e.length;t++){let r=n[t],o=e[t];if(typeof r!="number"||o===void 0)throw new Error("SQLite index key is not numeric");if(r!==o)return r<o?-1:1}return 0}var Ht=class{blocks=new Map;blockSize;maxBlocks;bytesFetched=0;fetches=0;source;pageSize;fileSize;constructor(e,t,r,o={}){this.source=e,this.pageSize=t,this.fileSize=r;let s=o.blockSize??65536;this.blockSize=Math.max(t,Math.ceil(s/t)*t),this.maxBlocks=o.maxBlocks??256}async read(e,t){let r=0;for(;;)try{let o=await this.source.read(e,t);return this.bytesFetched+=o.length,o}catch(o){if(r+=1,r>=3)throw o;await new Promise(s=>setTimeout(s,200*r))}}seed(e,t){t.length===Math.min(this.blockSize,this.fileSize-e*this.blockSize)&&this.blocks.set(e,Promise.resolve(t))}block(e){let t=this.blocks.get(e);if(t)return this.blocks.delete(e),this.blocks.set(e,t),t;let r=e*this.blockSize,o=Math.min(this.blockSize,this.fileSize-r),s=this.read(o,r);return this.fetches+=1,this.blocks.set(e,s),this.forgetOnFailure(s,[e]),this.evict(),s}prefetch(e){let t=[...new Set(e.map(o=>Math.floor((o-1)*this.pageSize/this.blockSize)))].filter(o=>!this.blocks.has(o)).sort((o,s)=>o-s),r=0;for(;r<t.length;){let o=r+1;for(;o<t.length&&t[o]===t[o-1]+1;)o+=1;this.fetchRun(t[r],o-r),r=o}}fetchRun(e,t){let r=e*this.blockSize,o=Math.min(t*this.blockSize,this.fileSize-r),s=this.read(o,r);this.fetches+=1;let i=[];for(let a=0;a<t;a++){let f=a*this.blockSize;i.push(e+a),this.blocks.set(e+a,s.then(c=>c.subarray(f,f+this.blockSize)))}this.forgetOnFailure(s,i),this.evict()}forgetOnFailure(e,t){e.catch(()=>{for(let r of t)this.blocks.delete(r)})}evict(){for(;this.blocks.size>this.maxBlocks;){let e=this.blocks.keys().next().value;if(e===void 0)break;this.blocks.delete(e)}}async page(e){let t=(e-1)*this.pageSize;if(e<1||t+this.pageSize>this.fileSize)throw new Error(`SQLite page ${e} is outside the file`);let r=await this.block(Math.floor(t/this.blockSize)),o=t%this.blockSize;return r.subarray(o,o+this.pageSize)}};var st=class n{pager;btree;objects;constructor(e,t,r){this.pager=e,this.btree=t,this.objects=r}static async open(e,t={}){let{size:r}=await e.stat(),o=await e.read(Math.min(t.blockSize??65536,r),0),s=o.subarray(0,100);if(new TextDecoder().decode(s.subarray(0,15))!=="SQLite format 3")throw new Error("Not a SQLite database");let a=new DataView(s.buffer,s.byteOffset,s.byteLength),f=a.getUint16(16),c=f===1?65536:f,l=s[20]??0,p=a.getUint32(56);if(p!==1)throw new Error(`SQLite text encoding ${p} is not UTF-8`);let u=new Ht(e,c,r,t);u.seed(0,o),u.fetches+=1,u.bytesFetched+=o.length;let d=new $t(u,l),h=new Map;for await(let{values:m}of d.tableScan(1)){let[y,S,I,g,b]=m;typeof y=="string"&&typeof S=="string"&&typeof I=="string"&&typeof g=="number"&&h.set(S,{type:y,name:S,tableName:I,rootPage:g,sql:typeof b=="string"?b:""})}return new n(u,d,h)}rootPage(e){let t=this.objects.get(e);if(!t)throw new Error(`SQLite database has no object named ${e}`);return t.rootPage}indexOn(e){let t=[...this.objects.values()].find(r=>r.type==="index"&&r.tableName===e);if(!t)throw new Error(`SQLite table ${e} has no index`);return t.rootPage}byRowid(e,t){return this.btree.tableRowid(this.rootPage(e),t)}prefetchRows(e,t,r){return this.btree.prefetchRowidRange(this.rootPage(e),t,r)}scan(e){return this.btree.tableScan(this.rootPage(e))}indexSeekLE(e,t){return this.btree.indexSeekLE(this.indexOn(e),t)}indexScanFrom(e,t){return this.btree.indexScanFrom(this.indexOn(e),t)}has(e){return this.objects.has(e)}};var jn="GBZ-base version 4",Gt=class extends Error{name="ForwardOnlyIndexError";constructor(){super("the haplotype index was written with --forward-only, which cannot name the walks stored against their reference (about half of them); rebuild it with gbz-haplotype-index without --forward-only")}},Bt=class extends Error{name="SchemaVersionError";found;constructor(e){super(e===void 0?"not a gbz-base database: its Tags table has no version":`unsupported database schema "${e}"; this reader understands "${jn}"`),this.found=e}},Dt=class{sequenceLen;handle;edges;bwt;encodedSequence;next;decoded;constructor(e,t,r,o,s){this.handle=e,this.edges=t,this.bwt=r,this.encodedSequence=o,this.next=s,this.sequenceLen=Hr(o)}get id(){return _(this.handle)}get orientation(){return Ue(this.handle)}get sequence(){return this.decoded??=Gr(this.encodedSequence),this.decoded}successors(){return this.edges.filter(e=>e.node!==0).map(e=>e.node)}gbwt(){if(this.edges.length===0)throw new Error(`GBWT record for handle ${this.handle} is empty`);return new It(this.edges,this.bwt)}};function D(n,e){if(typeof n!="number")throw new Error(`${e} is not a number in the database`);return n}function zt(n,e){if(typeof n!="string")throw new Error(`${e} is not text in the database`);return n}function zn(n,e){if(!(n instanceof Uint8Array))throw new Error(`${e} is not a blob in the database`);return n}function So(n,e){return{handle:n,fwStart:{node:D(e[1],"Paths.fw_node"),offset:D(e[2],"Paths.fw_offset")},revStart:{node:D(e[3],"Paths.rev_node"),offset:D(e[4],"Paths.rev_offset")},name:{sample:zt(e[5],"Paths.sample"),contig:zt(e[6],"Paths.contig"),haplotype:D(e[7],"Paths.haplotype"),fragment:D(e[8],"Paths.fragment")},isIndexed:D(e[9],"Paths.is_indexed")!==0}}async function vo(n){let e=new Map;for await(let{values:t}of n.scan("Tags"))e.set(zt(t[0],"Tags.key"),zt(t[1],"Tags.value"));return e}var it=class n{tagCache;pathCache;pathMapCache;indexTags=new Map;sqlite;index;constructor(e,t){this.sqlite=e,this.index=t}static async open(e,t={}){let{haplotypeIndex:r,...o}=t,s=await st.open(e,o);for(let c of["Tags","Nodes","Paths","ReferenceIndex"])s.rootPage(c);let i=r?await st.open(r,o):void 0,a=new n(s,i),f=await a.tag("version");if(f!==jn)throw new Bt(f);if(i){for(let d of["Tags","HaplotypeSamples","HaplotypeLengths"])i.rootPage(d);a.indexTags=await vo(i);let c=a.indexTags.get("haplotype_index_paths"),l=await a.tag("paths");if(c!==l)throw new Error(`haplotype index was built for ${c??"an unknown number of"} paths but the graph has ${l}`);let p=a.indexTags.get("haplotype_index_nodes"),u=await a.tag("nodes");if(p!==void 0&&p!==u)throw new Error(`haplotype index was built for a graph with ${p} nodes but this one has ${u}`);if(a.indexTags.get("haplotype_index_orientations")==="forward")throw new Gt}return a}tags(){return this.tagCache??=vo(this.sqlite),this.tagCache}async tag(e){return(await this.tags()).get(e)}prefetchRecords(e,t){return this.sqlite.prefetchRows("Nodes",e,t)}async getRecord(e){let t=await this.sqlite.byRowid("Nodes",e);if(!t)return;let r=t[4];return new Dt(e,$r(zn(t[1],"Nodes.edges")),zn(t[2],"Nodes.bwt"),zn(t[3],"Nodes.sequence"),typeof r=="number"?r:void 0)}paths(){return this.pathCache??=(async()=>{let e=[];for await(let{rowid:t,values:r}of this.sqlite.scan("Paths"))e.push(So(t,r));return e})(),this.pathCache}async getPath(e){let t=await this.sqlite.byRowid("Paths",e);return t?So(e,t):void 0}pathsByHandle(){return this.pathMapCache??=this.paths().then(e=>new Map(e.map(t=>[t.handle,t]))),this.pathMapCache}async findPath(e){return(await this.paths()).filter(r=>r.name.sample===e.sample&&r.name.contig===e.contig&&r.name.haplotype===e.haplotype&&r.name.fragment<=e.fragment).sort((r,o)=>o.name.fragment-r.name.fragment)[0]}async pathsForSample(e){return(await this.paths()).filter(t=>t.name.sample===e)}async pathsNamed(e){let t=Et(Yr(e),0);return(await this.paths()).filter(r=>r.name.sample===t.sample&&r.name.contig===t.contig&&r.name.haplotype===t.haplotype).sort((r,o)=>r.name.fragment-o.name.fragment)}async hasPath(e){return(await this.pathsNamed(e)).length>0}pathLengths=new Map;pathLength(e){let t=this.pathLengths.get(e);return t||(t=this.walkPathLength(e),this.pathLengths.set(e,t),t.catch(()=>this.pathLengths.delete(e))),t}async walkPathLength(e){let t=this.hasHaplotypeIndex?await this.haplotypeLength(e):void 0;if(t===void 0){let r=await this.indexedPosition(e,Number.MAX_SAFE_INTEGER);if(!r){let i=await this.getPath(e);throw new Error(`Path ${i?ge(i.name,i.name.fragment):e} has not been indexed for random access`)}let o=r.pathOffset,s=r.pos;for(;;){let i=await this.getRecord(s.node);if(!i)throw new Error(`Node ${s.node} does not exist in the graph`);o+=i.sequenceLen;let a=i.gbwt().lf(s.offset);if(!a||a.node===0)return o;s=a}}return t}async pathFragmentsForRange(e,t,r){if(r<=t)return[];let o=await this.pathsNamed(e),s=o.filter(f=>f.name.fragment<=t).slice(-1),i=o.filter(f=>f.name.fragment>t&&f.name.fragment<r);return(await Promise.all([...s,...i].map(async f=>({path:f,start:f.name.fragment,end:f.name.fragment+await this.pathLength(f.handle)})))).filter(f=>t<f.end)}async subgraphForFragment(e,t,r,o){let{keep:s,...i}=o;if(s!==void 0&&!this.hasHaplotypeIndex)throw new Error("keep needs the haplotype index: this database cannot name its walks");let{sample:a,contig:f,haplotype:c}=e.path.name,l={sample:a,contig:f,haplotype:c},p=Math.max(t,e.start),u=Math.min(r,e.end),d=o.haplotypes??"all",h=d==="all"||d==="distinct",m;return s!==void 0&&d==="all"?m=await wo(this,l,p,u,{...i,keep:s}):(m=await go(this,l,p,u,i),this.hasHaplotypeIndex&&h&&(await m.identifyPaths(),s!==void 0&&m.keepHaplotypes(s))),m}async getSubgraphForRange(e,t,r,o={}){let[s]=await this.pathFragmentsForRange(e,t,r);return s?this.subgraphForFragment(s,t,r,o):void 0}async getAlignmentsForRange(e,t,r,o={}){let s=[];for(let i of await this.pathFragmentsForRange(e,t,r)){let a=await this.subgraphForFragment(i,t,r,o);s.push(...a.alignments())}return s}async graphName(){let e=new Map;for(let[r,o]of await this.tags())r.startsWith("gbz_")&&e.set(r.slice(4),o);let t={name:void 0,subgraph:new Map,translation:new Map};try{t=jr(e)}catch{}return t}async hasChainLinks(){let e=await this.tag("chain_links");return e!==void 0&&Number(e)>0}get hasHaplotypeIndex(){return this.index!==void 0}get companion(){if(!this.index)throw new Error("no haplotype index was opened with this database");return this.index}async haplotypeSampleInterval(){let e=this.indexTags.get("haplotype_index_interval");return e===void 0?void 0:Number(e)}async haplotypeAnchorSpacing(){let e=this.index?.has("HaplotypeAnchors")?this.indexTags.get("haplotype_index_anchor_spacing"):void 0;return e===void 0?void 0:Number(e)}async haplotypeAnchor(e,t){let r=await this.companion.indexSeekLE("HaplotypeAnchors",[e,t]),o=r?.[0]===e&&r[1]===t?await this.companion.byRowid("HaplotypeAnchors",D(r[2],"HaplotypeAnchors rowid")):void 0;return o?{node:D(o[2],"HaplotypeAnchors.node_handle"),pathOffset:D(o[3],"HaplotypeAnchors.path_offset")}:void 0}haplotypeSamplesAtNode(e){return this.haplotypeSamplesInRange(e,e)}sampleFromRow(e){return{node:D(e[0],"HaplotypeSamples.node_handle"),offset:D(e[1],"HaplotypeSamples.node_offset"),pathHandle:D(e[2],"HaplotypeSamples.path_handle"),orientation:D(e[3],"HaplotypeSamples.orientation")===0?"forward":"reverse",pathOffset:D(e[4],"HaplotypeSamples.path_offset")}}async haplotypeSamplesInRange(e,t){let r=[];for await(let o of this.companion.indexScanFrom("HaplotypeSamples",[e,0])){if(D(o[0],"HaplotypeSamples.node_handle")>t)break;let i=await this.companion.byRowid("HaplotypeSamples",D(o[2],"HaplotypeSamples rowid"));i&&r.push(this.sampleFromRow(i))}return r}async haplotypeSampleAt(e,t){let r=await this.companion.indexSeekLE("HaplotypeSamples",[e,t]);if(r?.[0]!==e||r[1]!==t)return;let o=await this.companion.byRowid("HaplotypeSamples",D(r[2],"HaplotypeSamples rowid"));return o?this.sampleFromRow(o):void 0}async haplotypeLength(e){let t=await this.companion.byRowid("HaplotypeLengths",e);return t?D(t[1],"HaplotypeLengths.length"):void 0}async indexedRow(e){let t=await this.sqlite.byRowid("ReferenceIndex",e);if(!t)throw new Error("ReferenceIndex row referenced by its index is missing");return{pathOffset:D(t[1],"ReferenceIndex.path_offset"),pos:{node:D(t[2],"ReferenceIndex.node_handle"),offset:D(t[3],"ReferenceIndex.node_offset")}}}async indexedRowid(e,t){let r=await this.sqlite.indexSeekLE("ReferenceIndex",[e,t]);return r?.[0]===e?D(r[2],"ReferenceIndex rowid"):void 0}async indexedPosition(e,t){let r=await this.indexedRowid(e,t);return r===void 0?void 0:this.indexedRow(r)}async indexedPositionsBetween(e,t,r){let[o,s]=await Promise.all([this.indexedRowid(e,t),this.indexedRowid(e,r)]),i=[];if(o!==void 0&&s!==void 0){await this.sqlite.prefetchRows("ReferenceIndex",o,s+1);for(let a=o;a<=s;a++)i.push(await this.indexedRow(a))}return i}};var jt=class extends Error{constructor(t,r){super(r.length===0?`the graph names no reference sample (gbwt_reference_samples) and the anchor "${t}" maps to none; set referenceSample`:`the anchor "${t}" is none of the graph's reference samples (${r.join(", ")}); set referenceSample or map it through assemblyNameToPanSN`);this.name="NoReferenceSampleError"}},Ut=class extends Error{constructor(t,r,o){super(`this ${r.toLocaleString()} bp window reads more than nodeLimit (${t.toLocaleString()}) graph nodes; zoom in to about ${o.toLocaleString()} bp or raise nodeLimit`);this.name="NodeLimitError"}};function be(n){return`${n.sample}#${n.haplotype}`}function Io(n,e){let t=be(n);return e===void 0||e.some(r=>ze(t,r))}async function Ao(n){return(await n.tag("gbwt_reference_samples")??"").split(/\s+/).filter(e=>e!=="")}function yi(n,e){let t=n.toLowerCase(),r=Cr(n)?.toLowerCase();return e.find(o=>o===n)??e.find(o=>o.toLowerCase()===t)??e.find(o=>o.toLowerCase()===r)}function Un({configured:n,anchorPrefix:e,referenceSamples:t}){if(n!=="")return n;let r=yi(Er(e),t)??(t.length===1?t[0]:void 0);if(r===void 0)throw new jt(e,t);return r}async function Eo(n,e,t){let r=(await n.paths()).find(o=>o.isIndexed&&o.name.sample===e&&o.name.contig===t);return r?{sample:r.name.sample,contig:t,haplotype:r.name.haplotype}:void 0}function at(n,e,t){if(n instanceof Error&&(n.name==="SubgraphLimitError"||/^Subgraph size limit of \d+ nodes exceeded/.test(n.message))){let o=n.walkedBp,s=typeof o=="number"&&o>0?Math.floor(o*.8):Math.floor(t/2);return new Ut(e,t,Math.max(s,1))}else return}async function Co(n,e,t,r,{keep:o,...s}){let i=e?await n.getSubgraphForRange(e,t,r,{...s,haplotypes:"all",...o===void 0?{}:{keep:o}}).catch(a=>{throw at(a,s.limit,r-t)??a}):void 0;return i?i.toGFA({names:"resolved"}):""}var hr=le(Rr(),1),dr=le(et(),1),Je=le(Pr(),1),As=le(Ts(),1);var Po=le(Pr(),1);var Ro=/\.gbz\.db$/i;function xi(n){return Ro.test(Mr(n))?_r(n,e=>e.replace(Ro,".haplotype-index.db")):void 0}async function Mo(n,e){let t=xi(n);if(t)try{return await(0,Po.openLocation)(t,e).stat(),t}catch{return}}var bi=5e3,Si=50*2**20,Wn=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 vi(n,e){if(n.length<=e)return n;let t=n.length/e;return Array.from({length:e},(r,o)=>n[Math.floor(o*t)])}var _o=(n,e)=>n.path.some(t=>e.has(t.name)),Wt=class{constructor(e,t){this.file=e;this.tabix=t}readWhole(e){return this.whole??=(async()=>{let{size:t}=await this.file.stat();if(t>Si)throw new Wn(t);let r=await this.file.readFile({signal:e}),o=new TextDecoder().decode(r[0]===31&&r[1]===139?await Ir(r):r);return Or(o)})().catch(t=>{throw this.whole=void 0,t}),this.whole}async readIndexed(e,t,r){let o=1/0,s=-1/0;for(let a of t){let f=Number(a);Number.isInteger(f)&&(o=Math.min(o,f),s=Math.max(s,f))}let i=[];return o<=s&&await e.getLines("{node}",o,s+1,{signal:r,lineCallback:a=>{let f=kr(a);f&&_o(f,t)&&i.push(f)}}),i}async readsOver(e,{signal:t}={}){let r=this.tabix?await this.readIndexed(this.tabix,e,t):(await this.readWhole(t)).filter(o=>_o(o,e));return{records:vi(r,bi),total:r.length}}};var Ss=le(Rr(),1),vs=le(et(),1);var Qn=function(n,e){return Qn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])},Qn(n,e)};function ft(n,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Qn(n,e);function t(){this.constructor=n}n.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function ko(n,e,t,r){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(l){try{c(r.next(l))}catch(p){i(p)}}function f(l){try{c(r.throw(l))}catch(p){i(p)}}function c(l){l.done?s(l.value):o(l.value).then(a,f)}c((r=r.apply(n,e||[])).next())})}function Qt(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function a(c){return function(l){return f([c,l])}}function f(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(t=0)),t;)try{if(r=1,o&&(s=c[0]&2?o.return:c[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,c[1])).done)return s;switch(o=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,o=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){t.label=c[1];break}if(c[0]===6&&t.label<s[1]){t.label=s[1],s=c;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(c);break}s[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(l){c=[6,l],o=0}finally{r=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function He(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ye(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(a){i={error:a}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(i)throw i.error}}return s}function Ve(n,e,t){if(t||arguments.length===2)for(var r=0,o=e.length,s;r<o;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))}function Ge(n){return this instanceof Ge?(this.v=n,this):new Ge(n)}function Oo(n,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t.apply(n,e||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(d){return function(h){return Promise.resolve(h).then(d,p)}}function a(d,h){r[d]&&(o[d]=function(m){return new Promise(function(y,S){s.push([d,m,y,S])>1||f(d,m)})},h&&(o[d]=h(o[d])))}function f(d,h){try{c(r[d](h))}catch(m){u(s[0][3],m)}}function c(d){d.value instanceof Ge?Promise.resolve(d.value.v).then(l,p):u(s[0][2],d)}function l(d){f("next",d)}function p(d){f("throw",d)}function u(d,h){d(h),s.shift(),s.length&&f(s[0][0],s[0][1])}}function Lo(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=n[Symbol.asyncIterator],t;return e?e.call(n):(n=typeof He=="function"?He(n):n[Symbol.iterator](),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(s){t[s]=n[s]&&function(i){return new Promise(function(a,f){i=n[s](i),o(a,f,i.done,i.value)})}}function o(s,i,a,f){Promise.resolve(f).then(function(c){s({value:c,done:a})},i)}}function F(n){return typeof n=="function"}function To(n){var e=function(r){Error.call(r),r.stack=new Error().stack},t=n(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Yt=To(function(n){return function(t){n(this),this.message=t?t.length+` errors occurred during unsubscription:
6
6
  `+t.map(function(r,o){return o+1+") "+r.toString()}).join(`
7
- `):"",this.name="UnsubscriptionError",this.errors=t}});function Yn(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var Vt=(function(){function n(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var e,t,r,o,s;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=He(i),f=a.next();!f.done;f=a.next()){var c=f.value;c.remove(this)}}catch(m){e={error:m}}finally{try{f&&!f.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else i.remove(this);var l=this.initialTeardown;if(F(l))try{l()}catch(m){s=m instanceof Yt?m.errors:[m]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var u=He(p),d=u.next();!d.done;d=u.next()){var h=d.value;try{No(h)}catch(m){s=s??[],m instanceof Yt?s=Ve(Ve([],Ye(s)),Ye(m.errors)):s.push(m)}}}catch(m){r={error:m}}finally{try{d&&!d.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}if(s)throw new Yt(s)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)No(e);else{if(e instanceof n){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},n.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},n.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},n.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Yn(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&Yn(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=(function(){var e=new n;return e.closed=!0,e})(),n})();var hf=Vt.EMPTY;function Kt(n){return n instanceof Vt||n&&"closed"in n&&F(n.remove)&&F(n.add)&&F(n.unsubscribe)}function No(n){F(n)?n():n.unsubscribe()}var we={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Ke={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];var o=Ke.delegate;return o?.setTimeout?o.setTimeout.apply(o,Ve([n,e],Ye(t))):setTimeout.apply(void 0,Ve([n,e],Ye(t)))},clearTimeout:function(n){var e=Ke.delegate;return(e?.clearTimeout||clearTimeout)(n)},delegate:void 0};function Xt(n){Ke.setTimeout(function(){var e=we.onUnhandledError;if(e)e(n);else throw n})}function Vn(){}var Fo=(function(){return Kn("C",void 0,void 0)})();function qo(n){return Kn("E",void 0,n)}function $o(n){return Kn("N",n,void 0)}function Kn(n,e,t){return{kind:n,value:e,error:t}}var Be=null;function Ho(n){if(we.useDeprecatedSynchronousErrorHandling){var e=!Be;if(e&&(Be={errorThrown:!1,error:null}),n(),e){var t=Be,r=t.errorThrown,o=t.error;if(Be=null,r)throw o}}else n()}function Go(n){we.useDeprecatedSynchronousErrorHandling&&Be&&(Be.errorThrown=!0,Be.error=n)}var ct=(function(n){ft(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,Kt(t)&&t.add(r)):r.destination=Ci,r}return e.create=function(t,r,o){return new Jt(t,r,o)},e.prototype.next=function(t){this.isStopped?Zn($o(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?Zn(qo(t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?Zn(Fo,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(Vt);var Ii=Function.prototype.bind;function Xn(n,e){return Ii.call(n,e)}var Ai=(function(){function n(e){this.partialObserver=e}return n.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(r){Zt(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){Zt(r)}else Zt(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Zt(t)}},n})(),Jt=(function(n){ft(e,n);function e(t,r,o){var s=n.call(this)||this,i;if(F(t)||!t)i={next:t??void 0,error:r??void 0,complete:o??void 0};else{var a;s&&we.useDeprecatedNextContext?(a=Object.create(t),a.unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&Xn(t.next,a),error:t.error&&Xn(t.error,a),complete:t.complete&&Xn(t.complete,a)}):i=t}return s.destination=new Ai(i),s}return e})(ct);function Zt(n){we.useDeprecatedSynchronousErrorHandling?Go(n):Xt(n)}function Ei(n){throw n}function Zn(n,e){var t=we.onStoppedNotification;t&&Ke.setTimeout(function(){return t(n,e)})}var Ci={closed:!0,next:Vn,error:Ei,complete:Vn};var Xe=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Bo(n){return n}function Do(n){return n.length===0?Bo:n.length===1?n[0]:function(t){return n.reduce(function(r,o){return o(r)},t)}}var ie=(function(){function n(e){e&&(this._subscribe=e)}return n.prototype.lift=function(e){var t=new n;return t.source=this,t.operator=e,t},n.prototype.subscribe=function(e,t,r){var o=this,s=Pi(e)?e:new Jt(e,t,r);return Ho(function(){var i=o,a=i.operator,f=i.source;s.add(a?a.call(s,f):f?o._subscribe(s):o._trySubscribe(s))}),s},n.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},n.prototype.forEach=function(e,t){var r=this;return t=zo(t),new t(function(o,s){var i=new Jt({next:function(a){try{e(a)}catch(f){s(f),i.unsubscribe()}},error:s,complete:o});r.subscribe(i)})},n.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},n.prototype[Xe]=function(){return this},n.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Do(e)(this)},n.prototype.toPromise=function(e){var t=this;return e=zo(e),new e(function(r,o){var s;t.subscribe(function(i){return s=i},function(i){return o(i)},function(){return r(s)})})},n.create=function(e){return new n(e)},n})();function zo(n){var e;return(e=n??we.Promise)!==null&&e!==void 0?e:Promise}function Ri(n){return n&&F(n.next)&&F(n.error)&&F(n.complete)}function Pi(n){return n&&n instanceof ct||Ri(n)&&Kt(n)}function Mi(n){return F(n?.lift)}function he(n){return function(e){if(Mi(e))return e.lift(function(t){try{return n(t,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function Pe(n,e,t,r,o){return new _i(n,e,t,r,o)}var _i=(function(n){ft(e,n);function e(t,r,o,s,i,a){var f=n.call(this,t)||this;return f.onFinalize=i,f.shouldUnsubscribe=a,f._next=r?function(c){try{r(c)}catch(l){t.error(l)}}:n.prototype._next,f._error=s?function(c){try{s(c)}catch(l){t.error(l)}finally{this.unsubscribe()}}:n.prototype._error,f._complete=o?function(){try{o()}catch(c){t.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,f}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e})(ct);var en=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function tn(n){return F(n?.then)}function nn(n){return F(n[Xe])}function rn(n){return Symbol.asyncIterator&&F(n?.[Symbol.asyncIterator])}function on(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ki(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var sn=ki();function an(n){return F(n?.[sn])}function fn(n){return Oo(this,arguments,function(){var t,r,o,s;return Qt(this,function(i){switch(i.label){case 0:t=n.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,Ge(t.read())];case 3:return r=i.sent(),o=r.value,s=r.done,s?[4,Ge(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,Ge(o)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function cn(n){return F(n?.getReader)}function Se(n){if(n instanceof ie)return n;if(n!=null){if(nn(n))return Oi(n);if(en(n))return Li(n);if(tn(n))return Ti(n);if(rn(n))return jo(n);if(an(n))return Ni(n);if(cn(n))return Fi(n)}throw on(n)}function Oi(n){return new ie(function(e){var t=n[Xe]();if(F(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Li(n){return new ie(function(e){for(var t=0;t<n.length&&!e.closed;t++)e.next(n[t]);e.complete()})}function Ti(n){return new ie(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,Xt)})}function Ni(n){return new ie(function(e){var t,r;try{for(var o=He(n),s=o.next();!s.done;s=o.next()){var i=s.value;if(e.next(i),e.closed)return}}catch(a){t={error:a}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}e.complete()})}function jo(n){return new ie(function(e){qi(n,e).catch(function(t){return e.error(t)})})}function Fi(n){return jo(fn(n))}function qi(n,e){var t,r,o,s;return ko(this,void 0,void 0,function(){var i,a;return Qt(this,function(f){switch(f.label){case 0:f.trys.push([0,5,6,11]),t=Lo(n),f.label=1;case 1:return[4,t.next()];case 2:if(r=f.sent(),!!r.done)return[3,4];if(i=r.value,e.next(i),e.closed)return[2];f.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=f.sent(),o={error:a},[3,11];case 6:return f.trys.push([6,,9,10]),r&&!r.done&&(s=t.return)?[4,s.call(t)]:[3,8];case 7:f.sent(),f.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function de(n,e,t,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var s=e.schedule(function(){t(),o?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(s),!o)return s}function ln(n,e){return e===void 0&&(e=0),he(function(t,r){t.subscribe(Pe(r,function(o){return de(r,n,function(){return r.next(o)},e)},function(){return de(r,n,function(){return r.complete()},e)},function(o){return de(r,n,function(){return r.error(o)},e)}))})}function pn(n,e){return e===void 0&&(e=0),he(function(t,r){r.add(n.schedule(function(){return t.subscribe(r)},e))})}function Uo(n,e){return Se(n).pipe(pn(e),ln(e))}function Wo(n,e){return Se(n).pipe(pn(e),ln(e))}function Qo(n,e){return new ie(function(t){var r=0;return e.schedule(function(){r===n.length?t.complete():(t.next(n[r++]),t.closed||this.schedule())})})}function Yo(n,e){return new ie(function(t){var r;return de(t,e,function(){r=n[sn](),de(t,e,function(){var o,s,i;try{o=r.next(),s=o.value,i=o.done}catch(a){t.error(a);return}i?t.complete():t.next(s)},0,!0)}),function(){return F(r?.return)&&r.return()}})}function hn(n,e){if(!n)throw new Error("Iterable cannot be null");return new ie(function(t){de(t,e,function(){var r=n[Symbol.asyncIterator]();de(t,e,function(){r.next().then(function(o){o.done?t.complete():t.next(o.value)})},0,!0)})})}function Vo(n,e){return hn(fn(n),e)}function Ko(n,e){if(n!=null){if(nn(n))return Uo(n,e);if(en(n))return Qo(n,e);if(tn(n))return Wo(n,e);if(rn(n))return hn(n,e);if(an(n))return Yo(n,e);if(cn(n))return Vo(n,e)}throw on(n)}function Jn(n,e){return e?Ko(n,e):Se(n)}function lt(n,e){return he(function(t,r){var o=0;t.subscribe(Pe(r,function(s){r.next(n.call(e,s,o++))}))})}function Xo(n,e,t,r,o,s,i,a){var f=[],c=0,l=0,p=!1,u=function(){p&&!f.length&&!c&&e.complete()},d=function(m){return c<r?h(m):f.push(m)},h=function(m){s&&e.next(m),c++;var y=!1;Se(t(m,l++)).subscribe(Pe(e,function(S){o?.(S),s?d(S):e.next(S)},function(){y=!0},void 0,function(){if(y)try{c--;for(var S=function(){var I=f.shift();i?de(e,i,function(){return h(I)}):h(I)};f.length&&c<r;)S();u()}catch(I){e.error(I)}}))};return n.subscribe(Pe(e,d,function(){p=!0,u()})),function(){a?.()}}function Ze(n,e,t){return t===void 0&&(t=1/0),F(e)?Ze(function(r,o){return lt(function(s,i){return e(r,s,o,i)})(Se(n(r,o)))},t):(typeof e=="number"&&(t=e),he(function(r,o){return Xo(r,o,n,t)}))}function Zo(n,e,t,r,o){return function(s,i){var a=t,f=e,c=0;s.subscribe(Pe(i,function(l){var p=c++;f=a?n(f,l,p):(a=!0,l),r&&i.next(f)},o&&(function(){a&&i.next(f),i.complete()})))}}function Jo(n,e){return he(Zo(n,e,arguments.length>=2,!1,!0))}var $i=function(n,e){return n.push(e),n};function dn(){return he(function(n,e){Jo($i,[])(n).subscribe(e)})}function es(n){let e=[],t=0,r;for(let o=0,s=n.length;o<s;o++){let i=n.charCodeAt(o);if(i>=48&&i<=57)t=t*10+i-48;else if(i===58)r=t,t=0;else{let a=n[o];a==="M"||a==="="||a==="X"?e.push({own:r===void 0?t:r,mate:t,op:"M"}):a==="I"?e.push({own:0,mate:t,op:a}):(a==="D"||a==="N")&&e.push({own:t,mate:0,op:a}),r=void 0,t=0}}return e}function nr(n){let e="";for(let{own:t,mate:r,op:o}of es(n))e+=o==="M"?t===0?`${r}I`:r===0?`${t}D`:`${t}M`:`${o==="I"?r:t}${o}`;return e}var er=2**28-1;function tr(n,e,t){for(let r=e;r>0;r-=er)n.push((Math.min(r,er)<<4|t)>>>0)}function Hi(n,e,t){if(e===t)tr(n,e,0);else{let r=Math.ceil(Math.max(e,t)/er);for(let o=0;o<r;o++){let s=Math.floor(e*(o+1)/r)-Math.floor(e*o/r),i=Math.floor(t*(o+1)/r)-Math.floor(t*o/r);n.push((s<<4|9)>>>0,(i<<4|9)>>>0)}}}function rr(n){let e=[];for(let{own:t,mate:r,op:o}of es(n))o==="M"?Hi(e,t,r):o==="I"?tr(e,r,1):tr(e,t,o==="N"?3:2);return Uint32Array.from(e)}function Gi(n){return n>=48&&n<=57}function Bi(n){return n!==void 0&&/[A-Za-z]/.test(n)}function ts(n,e){let t=e;for(;t<n.length&&Bi(n[t]);)t++;return t}function ns(n,e){let t=e,r=0;for(;t<n.length&&Gi(n.charCodeAt(t));)r=r*10+(n.charCodeAt(t)-48),t++;return{value:r,next:t}}function as(n,e){let t=0;for(;t<n.length;){let r=n[t];if(r===":"){let{value:o,next:s}=ns(n,t+1);e(":",o,o,t+1,s),t=s}else if(r==="="){let o=ts(n,t+1),s=o-t-1;e("=",s,s,t+1,o),t=o}else if(r==="*")e("*",1,1,t+1,Math.min(t+3,n.length)),t+=3;else if(r==="+"||r==="-"){let o=ts(n,t+1),s=o-t-1;e(r,r==="-"?s:0,r==="+"?s:0,t+1,o),t=o}else if(r==="~"){let{value:o,next:s}=ns(n,t+3),i=Math.min(s+2,n.length);e("~",o,0,t+1,i),t=i}else t++}}function or(n,e,t,r){let o=t??Number.NEGATIVE_INFINITY,s=r??Number.POSITIVE_INFINITY,i=0;as(n,(a,f,c,l,p)=>{if(a==="*")i>=o&&i<s&&e(88,i,1,n[l+1]??"",-1,0,0);else if(a==="+"){if(i>=o&&i<=s){let u=n.slice(l,p);e(73,i,c,u,-1,0,c)}}else(a==="-"||a==="~")&&i<s&&i+f>o&&e(a==="-"?68:78,i,f,"",-1,0,0);i+=f})}function fs(n,e,t,r){let o=0,s=0,i=[],a=t&&e;for(let f=0,c=n.length;f<c;f++){let l=n[f],p=l>>>4,u=l&15;if(u===0||u===7){if(a)for(let d=0;d<p;d++)(e.charCodeAt(s+d)|32)!==(t.charCodeAt(o+d)|32)&&i.push({start:o+d,type:"mismatch",base:e[s+d],altbase:t[o+d],length:1});s+=p,o+=p}else if(u===1)i.push({start:o,type:"insertion",insertlen:p,insertedBases:e?.slice(s,s+p),length:0}),s+=p;else if(u===2)i.push({start:o,type:"deletion",length:p}),o+=p;else if(u===3)i.push({start:o,type:"skip",length:p}),o+=p;else if(u===8){for(let d=0;d<p;d++)i.push({start:o+d,type:"mismatch",base:e?.[s+d]||"X",qual:r?.[s+d],length:1});s+=p,o+=p}else u===5?i.push({start:o,type:"hardclip",cliplen:p,length:1}):u===4&&(i.push({start:o,type:"softclip",cliplen:p,length:1}),s+=p)}return i}function cs(n,e,t,r,o){if(!e)return[];let s=[],i=e.length,a=r.length,f=o!==void 0,c=t.length,l=!1;for(let I=0;I<c;I++)if(t[I].type==="skip"){l=!0;break}let p=0,u=0,d=0,h=0,m=0,y=0,S=n.length;for(;y<S;){let I=n.charCodeAt(y);if(I>=48&&I<=57){let g=0;for(;y<S;){let b=n.charCodeAt(y);if(b>=48&&b<=57)g=g*10+(b-48),y++;else break}p+=g}else if(I===94)for(y++;y<S&&n.charCodeAt(y)>=65;)y++,p++;else if(I>=65){let g=n[y];if(y++,l&&c>0)for(let L=m;L<c;L++){let k=t[L];k.type==="skip"&&p>=k.start&&(p+=k.length,m=L+1)}let b=d,x=h;for(let L=u;L<i&&x<=p;L++,u=L){let k=e[L],T=k>>>4,R=k&15;R===4||R===1?b+=T:R===2||R===6||R===3?x+=T:R!==5&&(b+=T,x+=T)}d=b,h=x;let A=b-(x-p),M=A<a?r[A]:"X";s.push({start:p,base:M,qual:f?o[A]:void 0,altbase:g,length:1,type:"mismatch"}),p++}else y++}return s}var ls={77:0,73:1,68:2,78:3,83:4,72:5,80:6,61:7,88:8};function ps(n=""){let e=0,t=[];for(let r=0,o=n.length;r<o;r++){let s=n.charCodeAt(r);if(s>=48&&s<=57)e=e*10+(s-48);else{let i=ls[s];t.push(e<<4|i),e=0}}return t}function ar(n=""){let e=0;for(let s=0,i=n.length;s<i;s++){let a=n.charCodeAt(s);(a<48||a>57)&&e++}let t=new Uint32Array(e),r=0,o=0;for(let s=0,i=n.length;s<i;s++){let a=n.charCodeAt(s);a>=48&&a<=57?r=r*10+(a-48):(t[o++]=r<<4|ls[a],r=0)}return t}function yn(n,e,t,r,o){let s=ps(n),i=n?fs(s,t,r,o):[];return e&&t?i.concat(cs(e,s,i,t,o)):i}var ji=397,Ui=387,Wi=385;function hs(n){return(1<<n&ji)!==0}function ds(n){return(1<<n&Ui)!==0}function us(n){return(1<<n&Wi)!==0}function fr(n,e,t,r,o,s,i){let a=o===-1?-1:1,f=e,c=o===-1?r:t,l=[],p=1/0,u=-1/0,d=1/0,h=-1/0,m=(y,S)=>{d=Math.min(d,y,S),h=Math.max(h,y,S)};for(let y=0;y<n.length;y++){let S=n[y],I=S>>>4,g=S&15,b=g===9,x=b||hs(g)?I:0,A=b?n[++y]>>>4:ds(g)?I:0,M=f+x,L=c+A*a,k=f,T=M;if(T>=s&&k<=i)if(x>0){let R=Math.max(k,s),B=Math.min(T,i);if(B>R)if(p=Math.min(p,R),u=Math.max(u,B),b){let v=A/I,C=B-R,P=Math.round(C*v),G=Math.round(c+(R-f)*v*a);l.push(C<<4|9,P<<4|9),m(G,G+P*a)}else l.push(B-R<<4|g),us(g)?m(c+(R-f)*a,c+(B-f)*a):m(c,c)}else A>0&&(b?l.push(S,n[y]):l.push(S),p=Math.min(p,f),u=Math.max(u,f),m(c,L));if(f=M,c=L,f>i)break}if(l.length!==0)return{start:p,end:u,mateStart:d,mateEnd:h,cigar:Uint32Array.from(l)}}function Qi(n){return n===1||n===2||n===3}function cr(n,e,t,r,o,s){let i=o===-1?-1:1,a=[],f=e,c=o===-1?r:t,l,p=!1,u=()=>{l!==void 0&&p&&l.qHi>l.qLo&&a.push({start:l.qLo,end:l.qHi,mateStart:l.tLo,mateEnd:l.tHi,cigar:Uint32Array.from(l.ops)}),l=void 0,p=!1};for(let d=0;d<n.length;d++){let h=n[d],m=h>>>4,y=h&15,S=y===9,I=S?n[++d]:void 0,g=S||hs(y)?m:0,b=I!==void 0?I>>>4:ds(y)?m:0,x=c+b*i;Qi(y)&&m>=s?u():(g>0||b>0)&&(l===void 0&&(l={qLo:f,qHi:f,tLo:c,tHi:c,ops:[]}),l.qHi=f+g,l.tLo=Math.min(l.tLo,c,x),l.tHi=Math.max(l.tHi,c,x),l.ops.push(h),I!==void 0&&l.ops.push(I),p=p||S||us(y)),f+=g,c=x}return u(),a}function ms(n){let e=n.get("CIGAR");return typeof e=="string"?e:void 0}function gs(n){let e=n.get("coarseCigar");return typeof e=="string"?e:void 0}function lr(n){let e=ms(n),t=e===void 0?gs(n):void 0;return e!==void 0?ar(e):t!==void 0?rr(t):void 0}var Yi=le(et(),1),Vi=le(ys(),1);var Ki=le(et(),1);var Xi=le(Ns(),1);var xs=le(et(),1),ke=class extends xs.SimpleFeature{get(e){return e==="mismatches"?yn(this.walkableCigar):e==="clipLengthAtStartOfRead"?this.clipLengthAtStartOfRead:e==="name"?super.get("name")??this.mate?.refName:super.get(e)}get mate(){return super.get("mate")}get walkableCigar(){let e=super.get("CIGAR"),t=super.get("coarseCigar");return typeof e=="string"?e:typeof t=="string"?nr(t):void 0}get clipLengthAtStartOfRead(){return this.mate?.start??0}forEachMismatch(e,t){let r=this.get("start"),o=t?.start===void 0?void 0:t.start-r,s=t?.end===void 0?void 0:t.end-r,i=this.get("cs");if(i)or(i,e,o,s);else{let a=o??Number.NEGATIVE_INFINITY,f=s??Number.POSITIVE_INFINITY;for(let c of yn(this.walkableCigar))(c.type==="deletion"||c.type==="skip"?c.start<f&&c.start+c.length>a:c.start>=a&&c.start<=f)&&(c.type==="mismatch"?e(88,c.start,c.length,c.base,c.qual??-1,0,0):c.type==="insertion"?e(73,c.start,c.length,c.insertedBases??"",-1,0,c.insertlen):c.type==="deletion"?e(68,c.start,c.length,"",-1,0,0):c.type==="skip"&&e(78,c.start,c.length,"",-1,0,0))}}};var Zi=["CIGAR","cs","coarseCigar","cg","cr"];function Ji(n){return typeof n=="object"&&n!==null&&"refName"in n&&"start"in n&&"end"in n&&typeof n.refName=="string"&&typeof n.start=="number"&&typeof n.end=="number"}function ea(n){let e=n.get("mate");return Ji(e)?e:void 0}function ta(n,e,t,r){let o=Math.max(n.start,r.start),s=Math.min(n.end,r.end),i=(e.end-e.start)/Math.max(n.end-n.start,1),a=l=>t===-1?e.end-(l-n.start)*i:e.start+(l-n.start)*i,f=Math.round(a(o)),c=Math.round(a(s));return s>o?{start:o,end:s,mateStart:Math.min(f,c),mateEnd:Math.max(f,c)}:void 0}function na(n,e,t,r,o){let s={start:n.get("start"),end:n.get("end")},i=n.get("strand")===-1?-1:1,a=s.start>=t.start&&s.end<=t.end,f=a&&r===void 0&&!o?void 0:lr(n);if(f===void 0){let c=a?{...s,mateStart:e.start,mateEnd:e.end}:ta(s,e,i,t);return c===void 0?[]:[c]}else return(r===void 0?[{...s,mateStart:e.start,mateEnd:e.end,cigar:f}]:cr(f,s.start,e.start,e.end,i,r)).flatMap(l=>{let p=fr(l.cigar,l.start,l.mateStart,l.mateEnd,i,t.start,t.end);return p===void 0?[]:[p]})}function ra(n,e,t,r,o,s){let i=`:${r.start}-${r.end}${o}`,a=n.toJSON(),f={...a,uniqueId:`${n.id()}${i}`,start:t.start,end:t.end,mate:{...e,start:t.mateStart,end:t.mateEnd}};a.syntenyId!==void 0&&(f.syntenyId=`${String(a.syntenyId)}${i}`);for(let c of Zi)delete f[c];return s&&t.cigar&&(f.alignmentOps=t.cigar),new ke(f)}function bs(n,e,t,r=!1){let o=ea(n);if(o===void 0)return[n];{let s=na(n,o,e,t,r);return s.map((i,a)=>ra(n,o,i,e,s.length>1?`/${a}`:"",r))}}var xn=class extends Ss.BaseFeatureDataAdapter{constructor(){super(...arguments);this.recordsAreAlignments=!0}static{this.capabilities=["getFeatures","getRefNames"]}async hasDataForRefName(){return!0}getFeaturesInMultipleRegions(t,r={}){let{clipToRegion:o,splitAtGapBp:s,keepAlignment:i,...a}=r,f=o&&this.recordsAreAlignments,c=(0,vs.createStatusFanOut)(a.statusCallback);return Jn(t).pipe(Ze((l,p)=>this.getFeatures(l,{...a,statusCallback:c()}).pipe(Ze(u=>f?bs(u,u.get("assemblyName")===l.assemblyName?l:{start:u.get("start"),end:u.get("end")},s,i):[u]),dn(),lt(u=>({index:p,features:u})))),dn(),Ze(l=>l.sort((p,u)=>p.index-u.index).flatMap(p=>p.features)))}};var ur=class extends Error{constructor(){super("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");this.name="NoHaplotypeIndexError"}},mr=class extends Error{constructor(t){super(`a pair query names both lanes: queryAssemblyName ${t} came without a targetAssemblyName`);this.name="PairTargetError"}},gr=class extends Error{constructor(t,r){super(`the graph is cut on its reference, ${r}; a window on ${t} has no reference coordinates to cut at. Open the graph from a ${r} view, and find this haplotype's lane there`);this.name="HaplotypeWindowError"}};function Is(n,e){let t=be(e);return n[t]??n[e.sample]??t}function oa(n,e){return`${be(n)}#${n.contig}@${e.start.node}.${e.start.offset}`}function sa({alignment:n,assemblyName:e,refName:t,lane:r}){let{refStart:o,refEnd:s,strand:i,cigar:a}=n;if(!(!n.resolved||s<=o)){let{name:f,hapStart:c,hapEnd:l}=n,p=oa(f,n),u={uniqueId:p,assemblyName:e,refName:t,start:o,end:s,type:"match",strand:i==="-"?-1:1,CIGAR:a,syntenyId:p,mate:{refName:f.contig,start:c,end:l,assemblyName:r}};return new ke(u)}}function ia({pair:n,lane:e,mateLane:t}){let r=`${be(n.target)}#${n.target.contig}:${n.targetStart}-${n.targetEnd}|${be(n.query)}#${n.query.contig}:${n.queryStart}-${n.queryEnd}`;return new ke({uniqueId:r,assemblyName:e,refName:n.target.contig,start:n.targetStart,end:n.targetEnd,type:"match",strand:n.strand==="-"?-1:1,CIGAR:n.cigar,syntenyId:r,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 pr=n=>!("uri"in n)||n.uri!=="",wr=class extends xn{constructor(){super(...arguments);this.graph=(0,hr.cachedSetup)({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),r=this.getConf("haplotypeIndexLocation"),o=pr(r)?r:await Mo(t,this.pluginManager),s=await it.open((0,Je.openLocation)(t,this.pluginManager),o?{haplotypeIndex:(0,Je.openLocation)(o,this.pluginManager)}:{}),i=this.getConf("assemblyNames")[0];if(i===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let a=await Ao(s),f=Un({configured:this.getConf("referenceSample"),anchorPrefix:je(this,i),referenceSamples:a});return{db:s,anchor:i,referenceSample:f,referenceSamples:a}}});this.gaf=(0,hr.cachedSetup)({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),r=this.getConf(["readsIndex","location"]),o=this.pluginManager;if(!pr(t))return;let s=(0,Je.openLocation)(t,o);return new Wt(s,pr(r)?new Ar({filehandle:s,...(0,Je.openTabixIndexFilehandle)(r,this.getConf(["readsIndex","indexType"]),o)}):void 0)}})}async referenceQuery(t,r){let{db:o,referenceSample:s}=await this.graph(r);return Eo(o,s,t)}async getHaplotypes(t={}){let{db:r,referenceSamples:o}=await this.graph(t),s=new Map;for(let i of await r.paths()){let a=be(i.name),f=s.get(a);f?f.contigs.includes(i.name.contig)||f.contigs.push(i.name.contig):s.set(a,{prefix:a,sample:i.name.sample,haplotype:i.name.haplotype,contigs:[i.name.contig],isReference:o.includes(i.name.sample)})}return[...s.values()]}async getHeader(t={}){let{anchor:r,referenceSample:o,referenceSamples:s}=await this.graph(t),i=Pn(this),a=[];for(let f of await this.getHaplotypes(t))f.sample!==o&&a.push({name:Is(i,f),label:f.prefix,group:f.sample});return{hasCoarseTier:!1,anchorAssemblyName:r,referenceSample:o,referenceSamples:s,lanes:a}}async getRefNames(t={}){let{db:r,anchor:o,referenceSample:s}=await this.graph(t),{assemblyName:i}=t,a=i===o?void 0:je(this,i),f=(await r.paths()).filter(c=>i===o?c.isIndexed&&c.name.sample===s:ze(be(c.name),a)).map(c=>c.name.contig);return[...new Set(f)]}keepPredicate(t,r){let o=t===void 0||t.length===0?void 0:t.map(s=>je(this,s));return o===void 0&&r===void 0?void 0:s=>Io(s,o)&&(r===void 0||ze(be(s),r))}async getSubgraph(t,r={}){let{db:o,anchor:s}=await this.graph(),{assemblyName:i,refName:a,start:f,end:c}=t;if(i!==s)throw new gr(i,s);let l=await this.referenceQuery(a,{}),p=this.keepPredicate(r.haplotypes);return Co(o,l,f,c,{context:this.getConf("context"),snarls:this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:r.signal,...p===void 0?{}:{keep:p}})}async getReads(t,r={}){let o=await this.gaf(r);return o?o.readsOver(new Set(t),r):{records:[],total:0}}async laneHaplotypes(t,r){let o=je(this,t);return(await this.getHaplotypes(r)).filter(s=>ze(s.prefix,o))}async referencePieces(t,r,o,s){let{db:i,referenceSample:a}=await this.graph(s),f=(await i.paths()).filter(l=>l.isIndexed&&l.name.sample===a&&l.name.contig===t&&l.name.fragment>r&&l.name.fragment<o).map(l=>l.name.fragment),c=[r,...[...new Set(f)].sort((l,p)=>l-p),o];return c.slice(1).map((l,p)=>({start:c[p],end:l}))}async anchorFeatures(t,r){let{db:o}=await this.graph(r),{assemblyName:s,refName:i,start:a,end:f}=t,c=je(this,r.targetAssemblyName),l=Pn(this),p=this.keepPredicate(r.haplotypes,c),u=await this.referenceQuery(i,r),d=this.getConf("nodeLimit");return(u?await(0,dr.updateStatus)(`Reading graph ${i}:${a.toLocaleString()}-${f.toLocaleString()}`,r.statusCallback,()=>o.getAlignmentsForRange(u,a,f,{context:this.getConf("context"),haplotypes:"all",limit:d,signal:r.signal,...p===void 0?{}:{keep:p}}).catch(m=>{throw at(m,d,f-a)??m})):[]).flatMap(m=>{let y=m.resolved?sa({alignment:m,assemblyName:s,refName:i,lane:Is(l,m.name)}):void 0;return y===void 0?[]:[y]})}async pairFeatures(t,r,o){let{targetAssemblyName:s}=o;if(s===void 0)throw new mr(r);let{db:i}=await this.graph(o),{refName:a,start:f,end:c}=t,l=await this.laneHaplotypes(r,o),p=await this.laneHaplotypes(s,o),u=[...l,...p],d=await this.referenceQuery(a,o),h=this.getConf("nodeLimit"),m=await i.haplotypeAnchorSpacing()!==void 0,y=(g,b)=>i.getSubgraphForRange(g,b.start,b.end,{context:this.getConf("context"),snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:h,signal:o.signal,keep:x=>u.some(A=>A.sample===x.sample&&A.haplotype===x.haplotype)}).catch(x=>{throw at(x,h,c-f)??x}),S=d&&m&&l.length>0&&p.length>0?(await(0,dr.updateStatus)(`Reading ${r} against ${s}`,o.statusCallback,async()=>Promise.all((await this.referencePieces(a,f,c,o)).map(g=>y(d,g))))).filter(g=>g!==void 0):[];return S.every(g=>{let b=g.stats.keep;return b!==void 0&&b.fallback===void 0})?S.flatMap(g=>l.flatMap(b=>p.flatMap(x=>g.pairAlignments({target:b,query:x,bases:!1}).map(A=>ia({pair:A,lane:r,mateLane:s}))))):[]}getFeatures(t,r={}){return(0,As.ObservableCreate)(async o=>{let{db:s,anchor:i}=await this.graph(r);if(!s.hasHaplotypeIndex)throw new ur;if(t.assemblyName===i){let a=r.queryAssemblyName===void 0?await this.anchorFeatures(t,r):await this.pairFeatures(t,r.queryAssemblyName,r);for(let f of a)o.next(f)}o.complete()},r.signal)}};export{gr as HaplotypeWindowError,ur as NoHaplotypeIndexError,jt as NoReferenceSampleError,Ut as NodeLimitError,mr as PairTargetError,wr as default,sa as fragmentFeature,be as haplotypePrefix,Is as laneAssemblyName,at as nodeLimitError,ia as pairFeature,Un as resolveReferenceSample};
8
- //# sourceMappingURL=GbzBaseSyntenyAdapter-KKSNCZXY.js.map
7
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function Yn(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var Vt=(function(){function n(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var e,t,r,o,s;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=He(i),f=a.next();!f.done;f=a.next()){var c=f.value;c.remove(this)}}catch(m){e={error:m}}finally{try{f&&!f.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else i.remove(this);var l=this.initialTeardown;if(F(l))try{l()}catch(m){s=m instanceof Yt?m.errors:[m]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var u=He(p),d=u.next();!d.done;d=u.next()){var h=d.value;try{No(h)}catch(m){s=s??[],m instanceof Yt?s=Ve(Ve([],Ye(s)),Ye(m.errors)):s.push(m)}}}catch(m){r={error:m}}finally{try{d&&!d.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}if(s)throw new Yt(s)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)No(e);else{if(e instanceof n){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},n.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},n.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},n.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Yn(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&Yn(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=(function(){var e=new n;return e.closed=!0,e})(),n})();var hf=Vt.EMPTY;function Kt(n){return n instanceof Vt||n&&"closed"in n&&F(n.remove)&&F(n.add)&&F(n.unsubscribe)}function No(n){F(n)?n():n.unsubscribe()}var we={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Ke={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];var o=Ke.delegate;return o?.setTimeout?o.setTimeout.apply(o,Ve([n,e],Ye(t))):setTimeout.apply(void 0,Ve([n,e],Ye(t)))},clearTimeout:function(n){var e=Ke.delegate;return(e?.clearTimeout||clearTimeout)(n)},delegate:void 0};function Xt(n){Ke.setTimeout(function(){var e=we.onUnhandledError;if(e)e(n);else throw n})}function Vn(){}var Fo=(function(){return Kn("C",void 0,void 0)})();function qo(n){return Kn("E",void 0,n)}function $o(n){return Kn("N",n,void 0)}function Kn(n,e,t){return{kind:n,value:e,error:t}}var Be=null;function Ho(n){if(we.useDeprecatedSynchronousErrorHandling){var e=!Be;if(e&&(Be={errorThrown:!1,error:null}),n(),e){var t=Be,r=t.errorThrown,o=t.error;if(Be=null,r)throw o}}else n()}function Go(n){we.useDeprecatedSynchronousErrorHandling&&Be&&(Be.errorThrown=!0,Be.error=n)}var ct=(function(n){ft(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,Kt(t)&&t.add(r)):r.destination=Ci,r}return e.create=function(t,r,o){return new Jt(t,r,o)},e.prototype.next=function(t){this.isStopped?Zn($o(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?Zn(qo(t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?Zn(Fo,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(Vt);var Ii=Function.prototype.bind;function Xn(n,e){return Ii.call(n,e)}var Ai=(function(){function n(e){this.partialObserver=e}return n.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(r){Zt(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){Zt(r)}else Zt(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Zt(t)}},n})(),Jt=(function(n){ft(e,n);function e(t,r,o){var s=n.call(this)||this,i;if(F(t)||!t)i={next:t??void 0,error:r??void 0,complete:o??void 0};else{var a;s&&we.useDeprecatedNextContext?(a=Object.create(t),a.unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&Xn(t.next,a),error:t.error&&Xn(t.error,a),complete:t.complete&&Xn(t.complete,a)}):i=t}return s.destination=new Ai(i),s}return e})(ct);function Zt(n){we.useDeprecatedSynchronousErrorHandling?Go(n):Xt(n)}function Ei(n){throw n}function Zn(n,e){var t=we.onStoppedNotification;t&&Ke.setTimeout(function(){return t(n,e)})}var Ci={closed:!0,next:Vn,error:Ei,complete:Vn};var Xe=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Bo(n){return n}function Do(n){return n.length===0?Bo:n.length===1?n[0]:function(t){return n.reduce(function(r,o){return o(r)},t)}}var ie=(function(){function n(e){e&&(this._subscribe=e)}return n.prototype.lift=function(e){var t=new n;return t.source=this,t.operator=e,t},n.prototype.subscribe=function(e,t,r){var o=this,s=Pi(e)?e:new Jt(e,t,r);return Ho(function(){var i=o,a=i.operator,f=i.source;s.add(a?a.call(s,f):f?o._subscribe(s):o._trySubscribe(s))}),s},n.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},n.prototype.forEach=function(e,t){var r=this;return t=zo(t),new t(function(o,s){var i=new Jt({next:function(a){try{e(a)}catch(f){s(f),i.unsubscribe()}},error:s,complete:o});r.subscribe(i)})},n.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},n.prototype[Xe]=function(){return this},n.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Do(e)(this)},n.prototype.toPromise=function(e){var t=this;return e=zo(e),new e(function(r,o){var s;t.subscribe(function(i){return s=i},function(i){return o(i)},function(){return r(s)})})},n.create=function(e){return new n(e)},n})();function zo(n){var e;return(e=n??we.Promise)!==null&&e!==void 0?e:Promise}function Ri(n){return n&&F(n.next)&&F(n.error)&&F(n.complete)}function Pi(n){return n&&n instanceof ct||Ri(n)&&Kt(n)}function Mi(n){return F(n?.lift)}function he(n){return function(e){if(Mi(e))return e.lift(function(t){try{return n(t,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function Pe(n,e,t,r,o){return new _i(n,e,t,r,o)}var _i=(function(n){ft(e,n);function e(t,r,o,s,i,a){var f=n.call(this,t)||this;return f.onFinalize=i,f.shouldUnsubscribe=a,f._next=r?function(c){try{r(c)}catch(l){t.error(l)}}:n.prototype._next,f._error=s?function(c){try{s(c)}catch(l){t.error(l)}finally{this.unsubscribe()}}:n.prototype._error,f._complete=o?function(){try{o()}catch(c){t.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,f}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e})(ct);var en=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function tn(n){return F(n?.then)}function nn(n){return F(n[Xe])}function rn(n){return Symbol.asyncIterator&&F(n?.[Symbol.asyncIterator])}function on(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ki(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var sn=ki();function an(n){return F(n?.[sn])}function fn(n){return Oo(this,arguments,function(){var t,r,o,s;return Qt(this,function(i){switch(i.label){case 0:t=n.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,Ge(t.read())];case 3:return r=i.sent(),o=r.value,s=r.done,s?[4,Ge(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,Ge(o)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function cn(n){return F(n?.getReader)}function Se(n){if(n instanceof ie)return n;if(n!=null){if(nn(n))return Oi(n);if(en(n))return Li(n);if(tn(n))return Ti(n);if(rn(n))return jo(n);if(an(n))return Ni(n);if(cn(n))return Fi(n)}throw on(n)}function Oi(n){return new ie(function(e){var t=n[Xe]();if(F(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Li(n){return new ie(function(e){for(var t=0;t<n.length&&!e.closed;t++)e.next(n[t]);e.complete()})}function Ti(n){return new ie(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,Xt)})}function Ni(n){return new ie(function(e){var t,r;try{for(var o=He(n),s=o.next();!s.done;s=o.next()){var i=s.value;if(e.next(i),e.closed)return}}catch(a){t={error:a}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}e.complete()})}function jo(n){return new ie(function(e){qi(n,e).catch(function(t){return e.error(t)})})}function Fi(n){return jo(fn(n))}function qi(n,e){var t,r,o,s;return ko(this,void 0,void 0,function(){var i,a;return Qt(this,function(f){switch(f.label){case 0:f.trys.push([0,5,6,11]),t=Lo(n),f.label=1;case 1:return[4,t.next()];case 2:if(r=f.sent(),!!r.done)return[3,4];if(i=r.value,e.next(i),e.closed)return[2];f.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=f.sent(),o={error:a},[3,11];case 6:return f.trys.push([6,,9,10]),r&&!r.done&&(s=t.return)?[4,s.call(t)]:[3,8];case 7:f.sent(),f.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function de(n,e,t,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var s=e.schedule(function(){t(),o?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(s),!o)return s}function ln(n,e){return e===void 0&&(e=0),he(function(t,r){t.subscribe(Pe(r,function(o){return de(r,n,function(){return r.next(o)},e)},function(){return de(r,n,function(){return r.complete()},e)},function(o){return de(r,n,function(){return r.error(o)},e)}))})}function pn(n,e){return e===void 0&&(e=0),he(function(t,r){r.add(n.schedule(function(){return t.subscribe(r)},e))})}function Uo(n,e){return Se(n).pipe(pn(e),ln(e))}function Wo(n,e){return Se(n).pipe(pn(e),ln(e))}function Qo(n,e){return new ie(function(t){var r=0;return e.schedule(function(){r===n.length?t.complete():(t.next(n[r++]),t.closed||this.schedule())})})}function Yo(n,e){return new ie(function(t){var r;return de(t,e,function(){r=n[sn](),de(t,e,function(){var o,s,i;try{o=r.next(),s=o.value,i=o.done}catch(a){t.error(a);return}i?t.complete():t.next(s)},0,!0)}),function(){return F(r?.return)&&r.return()}})}function hn(n,e){if(!n)throw new Error("Iterable cannot be null");return new ie(function(t){de(t,e,function(){var r=n[Symbol.asyncIterator]();de(t,e,function(){r.next().then(function(o){o.done?t.complete():t.next(o.value)})},0,!0)})})}function Vo(n,e){return hn(fn(n),e)}function Ko(n,e){if(n!=null){if(nn(n))return Uo(n,e);if(en(n))return Qo(n,e);if(tn(n))return Wo(n,e);if(rn(n))return hn(n,e);if(an(n))return Yo(n,e);if(cn(n))return Vo(n,e)}throw on(n)}function Jn(n,e){return e?Ko(n,e):Se(n)}function lt(n,e){return he(function(t,r){var o=0;t.subscribe(Pe(r,function(s){r.next(n.call(e,s,o++))}))})}function Xo(n,e,t,r,o,s,i,a){var f=[],c=0,l=0,p=!1,u=function(){p&&!f.length&&!c&&e.complete()},d=function(m){return c<r?h(m):f.push(m)},h=function(m){s&&e.next(m),c++;var y=!1;Se(t(m,l++)).subscribe(Pe(e,function(S){o?.(S),s?d(S):e.next(S)},function(){y=!0},void 0,function(){if(y)try{c--;for(var S=function(){var I=f.shift();i?de(e,i,function(){return h(I)}):h(I)};f.length&&c<r;)S();u()}catch(I){e.error(I)}}))};return n.subscribe(Pe(e,d,function(){p=!0,u()})),function(){a?.()}}function Ze(n,e,t){return t===void 0&&(t=1/0),F(e)?Ze(function(r,o){return lt(function(s,i){return e(r,s,o,i)})(Se(n(r,o)))},t):(typeof e=="number"&&(t=e),he(function(r,o){return Xo(r,o,n,t)}))}function Zo(n,e,t,r,o){return function(s,i){var a=t,f=e,c=0;s.subscribe(Pe(i,function(l){var p=c++;f=a?n(f,l,p):(a=!0,l),r&&i.next(f)},o&&(function(){a&&i.next(f),i.complete()})))}}function Jo(n,e){return he(Zo(n,e,arguments.length>=2,!1,!0))}var $i=function(n,e){return n.push(e),n};function dn(){return he(function(n,e){Jo($i,[])(n).subscribe(e)})}function es(n){let e=[],t=0,r;for(let o=0,s=n.length;o<s;o++){let i=n.charCodeAt(o);if(i>=48&&i<=57)t=t*10+i-48;else if(i===58)r=t,t=0;else{let a=n[o];a==="M"||a==="="||a==="X"?e.push({own:r===void 0?t:r,mate:t,op:"M"}):a==="I"?e.push({own:0,mate:t,op:a}):(a==="D"||a==="N")&&e.push({own:t,mate:0,op:a}),r=void 0,t=0}}return e}function nr(n){let e="";for(let{own:t,mate:r,op:o}of es(n))e+=o==="M"?t===0?`${r}I`:r===0?`${t}D`:`${t}M`:`${o==="I"?r:t}${o}`;return e}var er=2**28-1;function tr(n,e,t){for(let r=e;r>0;r-=er)n.push((Math.min(r,er)<<4|t)>>>0)}function Hi(n,e,t){if(e===t)tr(n,e,0);else{let r=Math.ceil(Math.max(e,t)/er);for(let o=0;o<r;o++){let s=Math.floor(e*(o+1)/r)-Math.floor(e*o/r),i=Math.floor(t*(o+1)/r)-Math.floor(t*o/r);n.push((s<<4|9)>>>0,(i<<4|9)>>>0)}}}function rr(n){let e=[];for(let{own:t,mate:r,op:o}of es(n))o==="M"?Hi(e,t,r):o==="I"?tr(e,r,1):tr(e,t,o==="N"?3:2);return Uint32Array.from(e)}function Gi(n){return n>=48&&n<=57}function Bi(n){return n!==void 0&&/[A-Za-z]/.test(n)}function ts(n,e){let t=e;for(;t<n.length&&Bi(n[t]);)t++;return t}function ns(n,e){let t=e,r=0;for(;t<n.length&&Gi(n.charCodeAt(t));)r=r*10+(n.charCodeAt(t)-48),t++;return{value:r,next:t}}function as(n,e){let t=0;for(;t<n.length;){let r=n[t];if(r===":"){let{value:o,next:s}=ns(n,t+1);e(":",o,o,t+1,s),t=s}else if(r==="="){let o=ts(n,t+1),s=o-t-1;e("=",s,s,t+1,o),t=o}else if(r==="*")e("*",1,1,t+1,Math.min(t+3,n.length)),t+=3;else if(r==="+"||r==="-"){let o=ts(n,t+1),s=o-t-1;e(r,r==="-"?s:0,r==="+"?s:0,t+1,o),t=o}else if(r==="~"){let{value:o,next:s}=ns(n,t+3),i=Math.min(s+2,n.length);e("~",o,0,t+1,i),t=i}else t++}}function or(n,e,t,r){let o=t??Number.NEGATIVE_INFINITY,s=r??Number.POSITIVE_INFINITY,i=0;as(n,(a,f,c,l,p)=>{if(a==="*")i>=o&&i<s&&e(88,i,1,n[l+1]??"",-1,0,0);else if(a==="+"){if(i>=o&&i<=s){let u=n.slice(l,p);e(73,i,c,u,-1,0,c)}}else(a==="-"||a==="~")&&i<s&&i+f>o&&e(a==="-"?68:78,i,f,"",-1,0,0);i+=f})}function fs(n,e,t,r){let o=0,s=0,i=[],a=t&&e;for(let f=0,c=n.length;f<c;f++){let l=n[f],p=l>>>4,u=l&15;if(u===0||u===7){if(a)for(let d=0;d<p;d++)(e.charCodeAt(s+d)|32)!==(t.charCodeAt(o+d)|32)&&i.push({start:o+d,type:"mismatch",base:e[s+d],altbase:t[o+d],length:1});s+=p,o+=p}else if(u===1)i.push({start:o,type:"insertion",insertlen:p,insertedBases:e?.slice(s,s+p),length:0}),s+=p;else if(u===2)i.push({start:o,type:"deletion",length:p}),o+=p;else if(u===3)i.push({start:o,type:"skip",length:p}),o+=p;else if(u===8){for(let d=0;d<p;d++)i.push({start:o+d,type:"mismatch",base:e?.[s+d]||"X",qual:r?.[s+d],length:1});s+=p,o+=p}else u===5?i.push({start:o,type:"hardclip",cliplen:p,length:1}):u===4&&(i.push({start:o,type:"softclip",cliplen:p,length:1}),s+=p)}return i}function cs(n,e,t,r,o){if(!e)return[];let s=[],i=e.length,a=r.length,f=o!==void 0,c=t.length,l=!1;for(let I=0;I<c;I++)if(t[I].type==="skip"){l=!0;break}let p=0,u=0,d=0,h=0,m=0,y=0,S=n.length;for(;y<S;){let I=n.charCodeAt(y);if(I>=48&&I<=57){let g=0;for(;y<S;){let b=n.charCodeAt(y);if(b>=48&&b<=57)g=g*10+(b-48),y++;else break}p+=g}else if(I===94)for(y++;y<S&&n.charCodeAt(y)>=65;)y++,p++;else if(I>=65){let g=n[y];if(y++,l&&c>0)for(let L=m;L<c;L++){let k=t[L];k.type==="skip"&&p>=k.start&&(p+=k.length,m=L+1)}let b=d,x=h;for(let L=u;L<i&&x<=p;L++,u=L){let k=e[L],T=k>>>4,R=k&15;R===4||R===1?b+=T:R===2||R===6||R===3?x+=T:R!==5&&(b+=T,x+=T)}d=b,h=x;let A=b-(x-p),M=A<a?r[A]:"X";s.push({start:p,base:M,qual:f?o[A]:void 0,altbase:g,length:1,type:"mismatch"}),p++}else y++}return s}var ls={77:0,73:1,68:2,78:3,83:4,72:5,80:6,61:7,88:8};function ps(n=""){let e=0,t=[];for(let r=0,o=n.length;r<o;r++){let s=n.charCodeAt(r);if(s>=48&&s<=57)e=e*10+(s-48);else{let i=ls[s];t.push(e<<4|i),e=0}}return t}function ar(n=""){let e=0;for(let s=0,i=n.length;s<i;s++){let a=n.charCodeAt(s);(a<48||a>57)&&e++}let t=new Uint32Array(e),r=0,o=0;for(let s=0,i=n.length;s<i;s++){let a=n.charCodeAt(s);a>=48&&a<=57?r=r*10+(a-48):(t[o++]=r<<4|ls[a],r=0)}return t}function yn(n,e,t,r,o){let s=ps(n),i=n?fs(s,t,r,o):[];return e&&t?i.concat(cs(e,s,i,t,o)):i}var ji=397,Ui=387,Wi=385;function hs(n){return(1<<n&ji)!==0}function ds(n){return(1<<n&Ui)!==0}function us(n){return(1<<n&Wi)!==0}function fr(n,e,t,r,o,s,i){let a=o===-1?-1:1,f=e,c=o===-1?r:t,l=[],p=1/0,u=-1/0,d=1/0,h=-1/0,m=(y,S)=>{d=Math.min(d,y,S),h=Math.max(h,y,S)};for(let y=0;y<n.length;y++){let S=n[y],I=S>>>4,g=S&15,b=g===9,x=b||hs(g)?I:0,A=b?n[++y]>>>4:ds(g)?I:0,M=f+x,L=c+A*a,k=f,T=M;if(T>=s&&k<=i)if(x>0){let R=Math.max(k,s),B=Math.min(T,i);if(B>R)if(p=Math.min(p,R),u=Math.max(u,B),b){let v=A/I,C=B-R,P=Math.round(C*v),G=Math.round(c+(R-f)*v*a);l.push(C<<4|9,P<<4|9),m(G,G+P*a)}else l.push(B-R<<4|g),us(g)?m(c+(R-f)*a,c+(B-f)*a):m(c,c)}else A>0&&(b?l.push(S,n[y]):l.push(S),p=Math.min(p,f),u=Math.max(u,f),m(c,L));if(f=M,c=L,f>i)break}if(l.length!==0)return{start:p,end:u,mateStart:d,mateEnd:h,cigar:Uint32Array.from(l)}}function Qi(n){return n===1||n===2||n===3}function cr(n,e,t,r,o,s){let i=o===-1?-1:1,a=[],f=e,c=o===-1?r:t,l,p=!1,u=()=>{l!==void 0&&p&&l.qHi>l.qLo&&a.push({start:l.qLo,end:l.qHi,mateStart:l.tLo,mateEnd:l.tHi,cigar:Uint32Array.from(l.ops)}),l=void 0,p=!1};for(let d=0;d<n.length;d++){let h=n[d],m=h>>>4,y=h&15,S=y===9,I=S?n[++d]:void 0,g=S||hs(y)?m:0,b=I!==void 0?I>>>4:ds(y)?m:0,x=c+b*i;Qi(y)&&m>=s?u():(g>0||b>0)&&(l===void 0&&(l={qLo:f,qHi:f,tLo:c,tHi:c,ops:[]}),l.qHi=f+g,l.tLo=Math.min(l.tLo,c,x),l.tHi=Math.max(l.tHi,c,x),l.ops.push(h),I!==void 0&&l.ops.push(I),p=p||S||us(y)),f+=g,c=x}return u(),a}function ms(n){let e=n.get("CIGAR");return typeof e=="string"?e:void 0}function gs(n){let e=n.get("coarseCigar");return typeof e=="string"?e:void 0}function lr(n){let e=ms(n),t=e===void 0?gs(n):void 0;return e!==void 0?ar(e):t!==void 0?rr(t):void 0}var Yi=le(et(),1),Vi=le(ys(),1);var Ki=le(et(),1);var Xi=le(Ns(),1);var xs=le(et(),1),ke=class extends xs.SimpleFeature{get(e){return e==="mismatches"?yn(this.walkableCigar):e==="clipLengthAtStartOfRead"?this.clipLengthAtStartOfRead:e==="name"?super.get("name")??this.mate?.refName:super.get(e)}get mate(){return super.get("mate")}get walkableCigar(){let e=super.get("CIGAR"),t=super.get("coarseCigar");return typeof e=="string"?e:typeof t=="string"?nr(t):void 0}get clipLengthAtStartOfRead(){return this.mate?.start??0}forEachMismatch(e,t){let r=this.get("start"),o=t?.start===void 0?void 0:t.start-r,s=t?.end===void 0?void 0:t.end-r,i=this.get("cs");if(i)or(i,e,o,s);else{let a=o??Number.NEGATIVE_INFINITY,f=s??Number.POSITIVE_INFINITY;for(let c of yn(this.walkableCigar))(c.type==="deletion"||c.type==="skip"?c.start<f&&c.start+c.length>a:c.start>=a&&c.start<=f)&&(c.type==="mismatch"?e(88,c.start,c.length,c.base,c.qual??-1,0,0):c.type==="insertion"?e(73,c.start,c.length,c.insertedBases??"",-1,0,c.insertlen):c.type==="deletion"?e(68,c.start,c.length,"",-1,0,0):c.type==="skip"&&e(78,c.start,c.length,"",-1,0,0))}}};var Zi=["CIGAR","cs","coarseCigar","cg","cr"];function Ji(n){return typeof n=="object"&&n!==null&&"refName"in n&&"start"in n&&"end"in n&&typeof n.refName=="string"&&typeof n.start=="number"&&typeof n.end=="number"}function ea(n){let e=n.get("mate");return Ji(e)?e:void 0}function ta(n,e,t,r){let o=Math.max(n.start,r.start),s=Math.min(n.end,r.end),i=(e.end-e.start)/Math.max(n.end-n.start,1),a=l=>t===-1?e.end-(l-n.start)*i:e.start+(l-n.start)*i,f=Math.round(a(o)),c=Math.round(a(s));return s>o?{start:o,end:s,mateStart:Math.min(f,c),mateEnd:Math.max(f,c)}:void 0}function na(n,e,t,r,o){let s={start:n.get("start"),end:n.get("end")},i=n.get("strand")===-1?-1:1,a=s.start>=t.start&&s.end<=t.end,f=a&&r===void 0&&!o?void 0:lr(n);if(f===void 0){let c=a?{...s,mateStart:e.start,mateEnd:e.end}:ta(s,e,i,t);return c===void 0?[]:[c]}else return(r===void 0?[{...s,mateStart:e.start,mateEnd:e.end,cigar:f}]:cr(f,s.start,e.start,e.end,i,r)).flatMap(l=>{let p=fr(l.cigar,l.start,l.mateStart,l.mateEnd,i,t.start,t.end);return p===void 0?[]:[p]})}function ra(n,e,t,r,o,s){let i=`:${r.start}-${r.end}${o}`,a=n.toJSON(),f={...a,uniqueId:`${n.id()}${i}`,start:t.start,end:t.end,mate:{...e,start:t.mateStart,end:t.mateEnd}};a.syntenyId!==void 0&&(f.syntenyId=`${String(a.syntenyId)}${i}`);for(let c of Zi)delete f[c];return s&&t.cigar&&(f.alignmentOps=t.cigar),new ke(f)}function bs(n,e,t,r=!1){let o=ea(n);if(o===void 0)return[n];{let s=na(n,o,e,t,r);return s.map((i,a)=>ra(n,o,i,e,s.length>1?`/${a}`:"",r))}}var xn=class extends Ss.BaseFeatureDataAdapter{constructor(){super(...arguments);this.recordsAreAlignments=!0}static{this.capabilities=["getFeatures","getRefNames"]}async hasDataForRefName(){return!0}getFeaturesInMultipleRegions(t,r={}){let{clipToRegion:o,splitAtGapBp:s,keepAlignment:i,...a}=r,f=o&&this.recordsAreAlignments,c=(0,vs.createStatusFanOut)(a.statusCallback);return Jn(t).pipe(Ze((l,p)=>this.getFeatures(l,{...a,statusCallback:c()}).pipe(Ze(u=>f?bs(u,u.get("assemblyName")===l.assemblyName?l:{start:u.get("start"),end:u.get("end")},s,i):[u]),dn(),lt(u=>({index:p,features:u})))),dn(),Ze(l=>l.sort((p,u)=>p.index-u.index).flatMap(p=>p.features)))}};var ur=class extends Error{constructor(){super("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");this.name="NoHaplotypeIndexError"}},mr=class extends Error{constructor(t){super(`a pair query names both lanes: queryAssemblyName ${t} came without a targetAssemblyName`);this.name="PairTargetError"}},gr=class extends Error{constructor(t,r){super(`the graph is cut on its reference, ${r}; a window on ${t} has no reference coordinates to cut at. Open the graph from a ${r} view, and find this haplotype's lane there`);this.name="HaplotypeWindowError"}};function Is(n,e){let t=be(e);return n[t]??n[e.sample]??t}function oa(n,e){return`${be(n)}#${n.contig}@${e.start.node}.${e.start.offset}`}function sa({alignment:n,assemblyName:e,refName:t,lane:r}){let{refStart:o,refEnd:s,strand:i,cigar:a}=n;if(!(!n.resolved||s<=o)){let{name:f,hapStart:c,hapEnd:l}=n,p=oa(f,n),u={uniqueId:p,assemblyName:e,refName:t,start:o,end:s,type:"match",strand:i==="-"?-1:1,CIGAR:a,syntenyId:p,mate:{refName:f.contig,start:c,end:l,assemblyName:r}};return new ke(u)}}function ia({pair:n,lane:e,mateLane:t}){let r=`${be(n.target)}#${n.target.contig}:${n.targetStart}-${n.targetEnd}|${be(n.query)}#${n.query.contig}:${n.queryStart}-${n.queryEnd}`;return new ke({uniqueId:r,assemblyName:e,refName:n.target.contig,start:n.targetStart,end:n.targetEnd,type:"match",strand:n.strand==="-"?-1:1,CIGAR:n.cigar,syntenyId:r,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 pr=n=>!("uri"in n)||n.uri!=="",wr=class extends xn{constructor(){super(...arguments);this.graph=(0,hr.cachedSetup)({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),r=this.getConf("haplotypeIndexLocation"),o=pr(r)?r:await Mo(t,this.pluginManager),s=await it.open((0,Je.openLocation)(t,this.pluginManager),o?{haplotypeIndex:(0,Je.openLocation)(o,this.pluginManager)}:{}),i=this.getConf("assemblyNames")[0];if(i===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let a=await Ao(s),f=Un({configured:this.getConf("referenceSample"),anchorPrefix:je(this,i),referenceSamples:a});return{db:s,anchor:i,referenceSample:f,referenceSamples:a}}});this.gaf=(0,hr.cachedSetup)({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),r=this.getConf(["readsIndex","location"]),o=this.pluginManager;if(!pr(t))return;let s=(0,Je.openLocation)(t,o);return new Wt(s,pr(r)?new Ar({filehandle:s,...(0,Je.openTabixIndexFilehandle)(r,this.getConf(["readsIndex","indexType"]),o)}):void 0)}})}async referenceQuery(t,r){let{db:o,referenceSample:s}=await this.graph(r);return Eo(o,s,t)}async getHaplotypes(t={}){let{db:r,referenceSamples:o}=await this.graph(t),s=new Map;for(let i of await r.paths()){let a=be(i.name),f=s.get(a);f?f.contigs.includes(i.name.contig)||f.contigs.push(i.name.contig):s.set(a,{prefix:a,sample:i.name.sample,haplotype:i.name.haplotype,contigs:[i.name.contig],isReference:o.includes(i.name.sample)})}return[...s.values()]}async getHeader(t={}){let{anchor:r,referenceSample:o,referenceSamples:s}=await this.graph(t),i=Pn(this),a=[];for(let f of await this.getHaplotypes(t))f.sample!==o&&a.push({name:Is(i,f),label:f.prefix,group:f.sample});return{hasCoarseTier:!1,anchorAssemblyName:r,referenceSample:o,referenceSamples:s,lanes:a}}async getRefNames(t={}){let{db:r,anchor:o,referenceSample:s}=await this.graph(t),{assemblyName:i}=t,a=i===o?void 0:je(this,i),f=(await r.paths()).filter(c=>i===o?c.isIndexed&&c.name.sample===s:ze(be(c.name),a)).map(c=>c.name.contig);return[...new Set(f)]}keepPredicate(t,r){let o=t===void 0||t.length===0?void 0:t.map(s=>je(this,s));return o===void 0&&r===void 0?void 0:s=>Io(s,o)&&(r===void 0||ze(be(s),r))}async getSubgraph(t,r={}){let{db:o,anchor:s}=await this.graph(),{assemblyName:i,refName:a,start:f,end:c}=t;if(i!==s)throw new gr(i,s);let l=await this.referenceQuery(a,{}),p=this.keepPredicate(r.haplotypes);return Co(o,l,f,c,{context:this.getConf("context"),snarls:r.snarls??this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:r.signal,...p===void 0?{}:{keep:p}})}async getReads(t,r={}){let o=await this.gaf(r);return o?o.readsOver(new Set(t),r):{records:[],total:0}}async laneHaplotypes(t,r){let o=je(this,t);return(await this.getHaplotypes(r)).filter(s=>ze(s.prefix,o))}async referencePieces(t,r,o,s){let{db:i,referenceSample:a}=await this.graph(s),f=(await i.paths()).filter(l=>l.isIndexed&&l.name.sample===a&&l.name.contig===t&&l.name.fragment>r&&l.name.fragment<o).map(l=>l.name.fragment),c=[r,...[...new Set(f)].sort((l,p)=>l-p),o];return c.slice(1).map((l,p)=>({start:c[p],end:l}))}async anchorFeatures(t,r){let{db:o}=await this.graph(r),{assemblyName:s,refName:i,start:a,end:f}=t,c=je(this,r.targetAssemblyName),l=Pn(this),p=this.keepPredicate(r.haplotypes,c),u=await this.referenceQuery(i,r),d=this.getConf("nodeLimit");return(u?await(0,dr.updateStatus)(`Reading graph ${i}:${a.toLocaleString()}-${f.toLocaleString()}`,r.statusCallback,()=>o.getAlignmentsForRange(u,a,f,{context:this.getConf("context"),haplotypes:"all",limit:d,signal:r.signal,...p===void 0?{}:{keep:p}}).catch(m=>{throw at(m,d,f-a)??m})):[]).flatMap(m=>{let y=m.resolved?sa({alignment:m,assemblyName:s,refName:i,lane:Is(l,m.name)}):void 0;return y===void 0?[]:[y]})}async pairFeatures(t,r,o){let{targetAssemblyName:s}=o;if(s===void 0)throw new mr(r);let{db:i}=await this.graph(o),{refName:a,start:f,end:c}=t,l=await this.laneHaplotypes(r,o),p=await this.laneHaplotypes(s,o),u=[...l,...p],d=await this.referenceQuery(a,o),h=this.getConf("nodeLimit"),m=await i.haplotypeAnchorSpacing()!==void 0,y=(g,b)=>i.getSubgraphForRange(g,b.start,b.end,{context:this.getConf("context"),snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:h,signal:o.signal,keep:x=>u.some(A=>A.sample===x.sample&&A.haplotype===x.haplotype)}).catch(x=>{throw at(x,h,c-f)??x}),S=d&&m&&l.length>0&&p.length>0?(await(0,dr.updateStatus)(`Reading ${r} against ${s}`,o.statusCallback,async()=>Promise.all((await this.referencePieces(a,f,c,o)).map(g=>y(d,g))))).filter(g=>g!==void 0):[];return S.every(g=>{let b=g.stats.keep;return b!==void 0&&b.fallback===void 0})?S.flatMap(g=>l.flatMap(b=>p.flatMap(x=>g.pairAlignments({target:b,query:x,bases:!1}).map(A=>ia({pair:A,lane:r,mateLane:s}))))):[]}getFeatures(t,r={}){return(0,As.ObservableCreate)(async o=>{let{db:s,anchor:i}=await this.graph(r);if(!s.hasHaplotypeIndex)throw new ur;if(t.assemblyName===i){let a=r.queryAssemblyName===void 0?await this.anchorFeatures(t,r):await this.pairFeatures(t,r.queryAssemblyName,r);for(let f of a)o.next(f)}o.complete()},r.signal)}};export{gr as HaplotypeWindowError,ur as NoHaplotypeIndexError,jt as NoReferenceSampleError,Ut as NodeLimitError,mr as PairTargetError,wr as default,sa as fragmentFeature,be as haplotypePrefix,Is as laneAssemblyName,at as nodeLimitError,ia as pairFeature,Un as resolveReferenceSample};
8
+ //# sourceMappingURL=GbzBaseSyntenyAdapter-7ZKFAEJG.js.map