jbrowse-plugin-graphgenomeviewer 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js +2 -0
- package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js.map +7 -0
- package/dist/chunks/{GbzBaseSyntenyAdapter-AZBYMDIW.js → GbzBaseSyntenyAdapter-VOGKGHQ6.js} +1 -1
- package/dist/chunks/{GbzBaseSyntenyAdapter-AZBYMDIW.js.map → GbzBaseSyntenyAdapter-VOGKGHQ6.js.map} +2 -2
- package/dist/chunks/{GraphGenomeView-PZXBBVUE.js → GraphGenomeView-YYP4IFSI.js} +2 -2
- package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js → GraphTrackSettingsDialog-2WPJRAJC.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-BGZYUENK.js → LinearGraphDisplay-4HYL7PDU.js} +2 -2
- package/dist/chunks/{chunk-UTWFU4X6.js → chunk-H54W6OQQ.js} +2 -2
- package/dist/chunks/{chunk-UTWFU4X6.js.map → chunk-H54W6OQQ.js.map} +4 -4
- package/dist/chunks/{chunk-FNZHIZQC.js → chunk-O4XV3K35.js} +2 -2
- package/dist/chunks/{chunk-FNZHIZQC.js.map → chunk-O4XV3K35.js.map} +4 -4
- package/dist/chunks/chunk-SJNG2XK7.js +2 -0
- package/dist/chunks/chunk-SJNG2XK7.js.map +7 -0
- package/dist/chunks/chunk-WKVVIDCS.js +3 -0
- package/dist/chunks/{chunk-TCGFPZ4Y.js.map → chunk-WKVVIDCS.js.map} +3 -3
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
- package/package.json +2 -2
- package/src/GraphGenomeView/components/ChooseWalksDialog.tsx +86 -0
- package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +205 -187
- package/src/GraphGenomeView/components/TubeMapLegend.test.tsx +29 -0
- package/src/GraphGenomeView/components/TubeMapOverlay.tsx +8 -0
- package/src/GraphGenomeView/model.test.ts +17 -0
- package/src/GraphGenomeView/model.ts +10 -4216
- package/src/GraphGenomeView/pane/fitViews.ts +589 -0
- package/src/GraphGenomeView/pane/graphViews.ts +829 -0
- package/src/GraphGenomeView/pane/hostViews.ts +193 -0
- package/src/GraphGenomeView/pane/launchActions.ts +407 -0
- package/src/GraphGenomeView/pane/launchViews.ts +191 -0
- package/src/GraphGenomeView/pane/loadActions.ts +701 -0
- package/src/GraphGenomeView/pane/paneBase.ts +479 -0
- package/src/GraphGenomeView/pane/renderingActions.ts +281 -0
- package/src/GraphGenomeView/pane/settingActions.ts +467 -0
- package/src/GraphGenomeView/pane/walkRowViews.ts +205 -0
- package/src/gaf/gafFile.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-BUXVOMDL.js +0 -2
- package/dist/chunks/chunk-BUXVOMDL.js.map +0 -7
- package/dist/chunks/chunk-TCGFPZ4Y.js +0 -3
- /package/dist/chunks/{GraphGenomeView-PZXBBVUE.js.map → GraphGenomeView-YYP4IFSI.js.map} +0 -0
- /package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js.map → GraphTrackSettingsDialog-2WPJRAJC.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-BGZYUENK.js.map → LinearGraphDisplay-4HYL7PDU.js.map} +0 -0
package/README.md
CHANGED
|
@@ -72,7 +72,9 @@ Needs JBrowse 5.0.0-beta.11 or later.
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
- **File → Open track** opens an rGFA index (`.segs.bed.gz` from
|
|
75
|
-
`build_rgfa_tabix.sh`) or a gbz-base database (`.gbz.db`) as a `GraphTrack
|
|
75
|
+
`build_rgfa_tabix.sh`) or a gbz-base database (`.gbz.db`) as a `GraphTrack`.
|
|
76
|
+
It finds the links and indexes beside the url, which a presigned url's
|
|
77
|
+
signature doesn't cover; spell out each location in a config instead
|
|
76
78
|
- A hand-written track needs only the adapter:
|
|
77
79
|
|
|
78
80
|
```json
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as y}from"./chunk-J6KYLXRD.js";import{a as c,b as u,c as w,d as C}from"./chunk-TYJTJGPO.js";import{b as t}from"./chunk-FY3BTKY4.js";var k=t(y(),1),p=t(u(),1),e=t(C(),1),h=t(w(),1),a=t(c(),1),b=(0,h.observer)(function({model:l,onClose:i}){let{walkChoices:n}=l,d=new Set(n.map(o=>o.name)),[r,g]=(0,k.useState)(()=>l.walkLayers.map(o=>o.walk).filter(o=>d.has(o)));return(0,a.jsxs)(p.Dialog,{open:!0,onClose:i,title:"Choose walks",children:[(0,a.jsxs)(e.DialogContent,{children:[(0,a.jsx)(e.Autocomplete,{multiple:!0,disableCloseOnSelect:!0,"data-testid":"graph-choose-walks",options:n.map(o=>o.name),getOptionLabel:o=>l.walkLabel(o),value:r,onChange:(o,s)=>{g(s)},renderOption:({key:o,...s},m,{selected:f})=>(0,a.jsxs)("li",{...s,children:[(0,a.jsx)(e.Checkbox,{size:"small",checked:f}),l.walkLabel(m)]},o),renderInput:o=>(0,a.jsx)(e.TextField,{...o,autoFocus:!0,label:"Walks",placeholder:"type to search"})}),(0,a.jsxs)(e.Typography,{variant:"caption",color:"text.secondary",children:[n.length.toLocaleString()," walks in this cut. The ones picked are lifted out of the drawing in this order, and the rest fades."]})]}),(0,a.jsxs)(e.DialogActions,{children:[(0,a.jsx)(e.Button,{onClick:i,children:"Cancel"}),(0,a.jsx)(e.Button,{variant:"contained",onClick:()=>{l.liftWalks(r),i()},children:"Lift these walks"})]})]})}),L=b;export{L as default};
|
|
2
|
+
//# sourceMappingURL=ChooseWalksDialog-GVQLSGHX.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/GraphGenomeView/components/ChooseWalksDialog.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useState } from 'react'\n\nimport { Dialog } from '@jbrowse/core/ui'\nimport {\n Autocomplete,\n Button,\n Checkbox,\n DialogActions,\n DialogContent,\n TextField,\n Typography,\n} from '@mui/material'\nimport { observer } from 'mobx-react'\n\nimport type { GraphPaneModel } from '../model'\n\ntype WalkPicker = Pick<\n GraphPaneModel,\n 'walkChoices' | 'walkLayers' | 'walkLabel' | 'liftWalks'\n>\n\n// Which walks to lift, searched by name, for a graph with more walks than a\n// menu can list\nconst ChooseWalksDialog = observer(function ChooseWalksDialog({\n model,\n onClose,\n}: {\n model: WalkPicker\n onClose: () => void\n}) {\n const { walkChoices } = model\n const names = new Set(walkChoices.map(c => c.name))\n const [picked, setPicked] = useState(() =>\n model.walkLayers.map(l => l.walk).filter(name => names.has(name)),\n )\n return (\n <Dialog open onClose={onClose} title=\"Choose walks\">\n <DialogContent>\n <Autocomplete\n multiple\n disableCloseOnSelect\n data-testid=\"graph-choose-walks\"\n options={walkChoices.map(c => c.name)}\n getOptionLabel={name => model.walkLabel(name)}\n value={picked}\n onChange={(_, value) => {\n setPicked(value)\n }}\n renderOption={({ key, ...props }, name, { selected }) => (\n <li key={key} {...props}>\n <Checkbox size=\"small\" checked={selected} />\n {model.walkLabel(name)}\n </li>\n )}\n renderInput={params => (\n <TextField\n {...params}\n autoFocus\n label=\"Walks\"\n placeholder=\"type to search\"\n />\n )}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {walkChoices.length.toLocaleString()} walks in this cut. The ones\n picked are lifted out of the drawing in this order, and the rest\n fades.\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>Cancel</Button>\n <Button\n variant=\"contained\"\n onClick={() => {\n model.liftWalks(picked)\n onClose()\n }}\n >\n Lift these walks\n </Button>\n </DialogActions>\n </Dialog>\n )\n})\n\nexport default ChooseWalksDialog\n"],
|
|
5
|
+
"mappings": "6IAAA,IAAAA,EAAyB,SAEzBC,EAAuB,SACvBC,EAQO,SACPC,EAAyB,SAqCbC,EAAA,SA1BNC,KAAoB,YAAS,SAA2B,CAC5D,MAAAC,EACA,QAAAC,CACF,EAGG,CACD,GAAM,CAAE,YAAAC,CAAY,EAAIF,EAClBG,EAAQ,IAAI,IAAID,EAAY,IAAIE,GAAKA,EAAE,IAAI,CAAC,EAC5C,CAACC,EAAQC,CAAS,KAAI,YAAS,IACnCN,EAAM,WAAW,IAAIO,GAAKA,EAAE,IAAI,EAAE,OAAOC,GAAQL,EAAM,IAAIK,CAAI,CAAC,CAClE,EACA,SACE,QAAC,UAAO,KAAI,GAAC,QAASP,EAAS,MAAM,eACnC,qBAAC,iBACC,oBAAC,gBACC,SAAQ,GACR,qBAAoB,GACpB,cAAY,qBACZ,QAASC,EAAY,IAAIE,GAAKA,EAAE,IAAI,EACpC,eAAgBI,GAAQR,EAAM,UAAUQ,CAAI,EAC5C,MAAOH,EACP,SAAU,CAACI,EAAGC,IAAU,CACtBJ,EAAUI,CAAK,CACjB,EACA,aAAc,CAAC,CAAE,IAAAC,EAAK,GAAGC,CAAM,EAAGJ,EAAM,CAAE,SAAAK,CAAS,OACjD,QAAC,MAAc,GAAGD,EAChB,oBAAC,YAAS,KAAK,QAAQ,QAASC,EAAU,EACzCb,EAAM,UAAUQ,CAAI,IAFdG,CAGT,EAEF,YAAaG,MACX,OAAC,aACE,GAAGA,EACJ,UAAS,GACT,MAAM,QACN,YAAY,iBACd,EAEJ,KACA,QAAC,cAAW,QAAQ,UAAU,MAAM,iBACjC,UAAAZ,EAAY,OAAO,eAAe,EAAE,wGAGvC,GACF,KACA,QAAC,iBACC,oBAAC,UAAO,QAASD,EAAS,kBAAM,KAChC,OAAC,UACC,QAAQ,YACR,QAAS,IAAM,CACbD,EAAM,UAAUK,CAAM,EACtBJ,EAAQ,CACV,EACD,4BAED,GACF,GACF,CAEJ,CAAC,EAEMc,EAAQhB",
|
|
6
|
+
"names": ["import_react", "import_ui", "import_material", "import_mobx_react", "import_jsx_runtime", "ChooseWalksDialog", "model", "onClose", "walkChoices", "names", "c", "picked", "setPicked", "l", "name", "_", "value", "key", "props", "selected", "params", "ChooseWalksDialog_default"]
|
|
7
|
+
}
|
|
@@ -5,4 +5,4 @@ import{a as _n,b as Ps,c as kr,d as Lr}from"./chunk-S3X3QFQD.js";import{e as Ms,
|
|
|
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,end: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!=="anonymous"?i.identity:void 0;r.push({info:i,identity:f,name:f?ge({...f.name,fragment:f.name.fragment+f.hapStart,end:f.name.fragment+f.hapEnd}):ge({sample:"unknown",contig:o,haplotype:s,fragment:0,end: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)&&Ue(e,t)&&(yield[e,t])}toSubgraphJson(e={}){let t=this.sortedHandles().filter(s=>!U(s)).map(s=>({id:String(M(s)),sequence:this.record(s).sequence})),r=[];for(let[s,i]of this.outputEdges())r.push({from:String(M(s)),from_is_reverse:U(s),to:String(M(i)),to_is_reverse:U(i)});let o=this.outputPaths(e).map(s=>ai(s.info,s.identity,s.name,s.cigar));return{nodes:t,edges:r,paths:o}}toCompactSubgraph(e={}){let t=this.sortedHandles().filter(i=>!U(i)),r=new Int32Array(t.length),o=[];t.forEach((i,a)=>{r[a]=M(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(Tt(i.info,i.identity))}))}}};function Tt(n,e){return e?.orientation==="reverse"?n.path.map(t=>oe(t)).reverse():n.path}function ai(n,e,t,r){return{name:t,...n.weight===void 0?{}:{weight:n.weight},...r===void 0?{}:{cigar:r},path:Tt(n,e).map(o=>({id:String(M(o)),is_reverse:U(o)}))}}function kt(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 K(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 go(n,e,t){if(e===0)K(n,"D",t);else if(t===0)K(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?(K(n,"M",r),K(n,"I",e-r),K(n,"D",t-r)):(K(n,"I",e),K(n,"D",t))}}function fi(n){let e=0;for(;e<n.length&&n[e][0]!=="M";)e+=1;if(e===n.length){let a=n.filter(([c])=>c==="I"),f=n.filter(([c])=>c==="D").reduce((c,[,l])=>c+l,0);return{edits:a.map(([c,l])=>[c,l]),leading:0,trailing:f}}let t=n.length;for(;n[t-1][0]!=="M";)t-=1;let r=a=>({inserted:a.reduce((f,[c,l])=>f+(c==="I"?l:0),0),deleted:a.reduce((f,[c,l])=>f+(c==="D"?l:0),0)}),o=r(n.slice(0,e)),s=r(n.slice(t)),i=[];K(i,"I",o.inserted);for(let[a,f]of n.slice(e,t))K(i,a,f);return K(i,"I",s.inserted),{edits:i,leading:o.deleted,trailing:s.deleted}}function mo(n,e){let t=e.map(()=>0),r=e.length-1,o=0,s=e[0],i=0;for(let[a,f]of n){if(a==="D")continue;let c=f;for(;c>0;){for(;o<r&&i>=s;)o+=1,s+=e[o];let l=o<r?Math.min(c,s-i):c;a==="M"&&(t[o]+=l),i+=l,c-=l}}return t}function ci(n,e){let t=[],r=0,o=0;for(let[s,i]of n){if(s==="D"){K(t,s,i);continue}let a=r;for(;o<e.length&&e[o][0]<r+i;){let[f,c]=e[o];K(t,s,f-a),K(t,"I",c),a=f,o+=1}K(t,s,r+i-a),r+=i}for(;o<e.length;o++)K(t,"I",e[o][1]);return t}function li(n){return n.map(([e,t])=>`${t}${e}`).join("")}async function wo(n,e){let t=qe.create(n,e),r=await t.pathPosition(Qe(We(e.path),e.offset));return await t.aroundPosition(r.position.handle,r.position.nodeOffset,e.context??100),await t.extractSnarls(e.snarls??"none"),t.extractPaths(r,e.haplotypes??"all"),t}async function di(n,e){let{start:t,end:r}=e,o=qe.create(n,e);try{let s=await o.pathPosition(Qe(We(e.path),t));return await o.prefetchReferenceWalk(s,r-t),await o.aroundInterval(s.position,r-t,e.context??100),await o.extractSnarls(e.snarls??"none"),{subgraph:o,reference:s}}catch(s){throw s instanceof Se&&s.windowBp===void 0?new Se(s.limit,{windowBp:r-t,walkedBp:o.referenceWalkedBp??0}):s}}async function Bn(n,e){let{keep:t}=e,r=e.haplotypes??"all",o=r==="all"||r==="distinct";if(t!==void 0&&o&&!n.hasHaplotypeIndex)throw new Error("keep needs the haplotype index: this database cannot name its walks");let{subgraph:s,reference:i}=await di(n,e);return t===void 0||!o?(s.extractPaths(i,r),s):(await s.extractChosenPaths(i,e.end-e.start,t,e.context??100)||(s.extractPaths(i,"all"),await s.identifyPaths()),s.keepHaplotypes(t),r==="distinct"&&s.mergeDistinct(),s)}async function yo(n,e){let t=e.haplotypes??"all",r=e.snarls??"none";if(t==="reference-only")throw new Error("Cannot output a reference path in a node-based query");if(r==="overlapping"&&e.nodeIds.length>1)throw new Error("Overlapping snarls cannot be extracted for a node-based query with multiple nodes");let o=qe.create(n,e);return await o.aroundNodes(e.nodeIds,e.context??100),await o.extractSnarls(r),o.extractPaths(void 0,t),o}async function xo(n,e){let t=e.haplotypes??"all";if(t==="reference-only")throw new Error("Cannot output a reference path in a node-based query");let r=qe.create(n,e);return await r.betweenNodes(e.startHandle,e.endHandle),r.extractPaths(void 0,t),r}function ve(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 hi(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 pi=new TextDecoder;function Lt(n){let[e,t]=ve(n,0),r=[],o=t;for(;o<e;){let[a,f]=ve(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=hi(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:pi.decode(c)}throw new Error(`SQLite serial type ${a} is reserved`)})}var at=2,Ft=5,So=10,Nt=13;function Io(n,e){return n[e]*256+n[e+1]}function ke(n,e){return n[e]*16777216+n[e+1]*65536+n[e+2]*256+n[e+3]}function ui(n,e){let t=n[e];if(t!==at&&t!==Ft&&t!==So&&t!==Nt)throw new Error(`SQLite page has unknown b-tree type ${t}`);let r=t===at||t===Ft;return{type:t,cellCount:Io(n,e+3),rightChild:r?ke(n,e+8):0,cellPointers:e+(r?12:8)}}function _e(n,e,t){return Io(n,e.cellPointers+2*t)}var mi=4096,gi=4096,Ht=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=ke(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=ke(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:ui(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===Nt)return s;if(a.type!==Ft)throw new Error("SQLite table b-tree contains an index page");let f=this.childIndexFor(i,a,t);o=f===a.cellCount?a.rightChild:ke(i,_e(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]=ve(e,_e(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},d)=>{let h=d===0?this.childIndexFor(c,l,t):0,u=d===a.length-1?this.childIndexFor(c,l,r):l.cellCount;for(let p=h;p<=u;p++)f.push(p===l.cellCount?l.rightChild:ke(c,_e(c,l,p)))}),f.length>gi)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===Nt){let f=0,c=s.cellCount;for(;f<c;){let l=f+c>>1,d=_e(o,s,l),[h,u]=ve(o,d),[p,m]=ve(o,u);if(p===t)return Lt(await this.payload(o,m,h,!1));p<t?f=l+1:c=l}return}if(s.type!==Ft)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=_e(o,s,f),[l]=ve(o,c+4);l<t?i=f+1:a=f}r=i===s.cellCount?s.rightChild:ke(o,_e(o,s,i))}}async*tableScan(e){let{page:t,header:r}=await this.pageAt(e);if(r.type===Nt)for(let o=0;o<r.cellCount;o++){let s=_e(t,r,o),[i,a]=ve(t,s),[f,c]=ve(t,a);yield{rowid:f,values:Lt(await this.payload(t,c,i,!1))}}else{let o=[];for(let s=0;s<r.cellCount;s++)o.push(ke(t,_e(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>=mi){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=_e(t,r,o),f=r.type===at,[c,l]=ve(t,f?a+4:a);i={values:Lt(await this.payload(t,l,c,!0)),leftChild:f?ke(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);bo(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===at&&(yield*this.indexScanFrom(f.leftChild,t)),yield f.values}o.type===at&&(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,d=await this.indexCell(o,s,i,l);bo(d.values,t)<=0?(r=d.values,a=l+1):(c=d.leftChild,f=l)}if(i.type===So)return r;o=a===i.cellCount?i.rightChild:c}}};function bo(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 $t=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=await this.readRetrying(e,t);if(this.bytesFetched+=r.length,r.length<e)throw new Error(`the file ends at byte ${t+r.length}, short of the ${this.fileSize} bytes its SQLite header gives`);return r}async readRetrying(e,t){let r=0;for(;;)try{return await this.source.read(e,t)}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 ft=class n{pager;btree;objects;constructor(e,t,r){this.pager=e,this.btree=t,this.objects=r}static async open(e,t={}){let r=await e.read(t.blockSize??65536,0),o=r.subarray(0,100);if(new TextDecoder().decode(o.subarray(0,15))!=="SQLite format 3"||o.length<100)throw new Error("Not a SQLite database");let i=new DataView(o.buffer,o.byteOffset,o.byteLength),a=i.getUint16(16),f=a===1?65536:a,c=o[20]??0,l=i.getUint32(56);if(l!==1)throw new Error(`SQLite text encoding ${l} is not UTF-8`);let d=i.getUint32(28);if(d===0||i.getUint32(24)!==i.getUint32(92))throw new Error("SQLite header has no valid database size; the file was written by SQLite older than 3.7.0");let h=d*f,u=new $t(e,f,h,t);u.seed(0,r),u.fetches+=1,u.bytesFetched+=r.length;let p=new Ht(u,c),m=new Map;for await(let{values:w}of p.tableScan(1)){let[x,S,g,I,y]=w;typeof x=="string"&&typeof S=="string"&&typeof g=="string"&&typeof I=="number"&&m.set(S,{type:x,name:S,tableName:g,rootPage:I,sql:typeof y=="string"?y:""})}return new n(u,p,m)}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(o=>o.type==="index"&&o.tableName===e);if(t)return t.rootPage;let r=this.objects.get(e);if(r?.type==="table"&&/without\s+rowid/i.test(r.sql))return r.rootPage;throw new Error(`SQLite table ${e} has no index`)}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 Dn="GBZ-base version 4",Bt=class extends Error{name="UnknownPathError";path;constructor(e){super(`the graph has no path named ${ge(e)}`),this.path=e}},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")}},Dt=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 "${Dn}"`),this.found=e}},Gn=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=Br(o)}get id(){return M(this.handle)}get orientation(){return je(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 q(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 qt(n,e){if(!(n instanceof Uint8Array))throw new Error(`${e} is not a blob in the database`);return n}function vo(n,e){return{handle:n,fwStart:{node:q(e[1],"Paths.fw_node"),offset:q(e[2],"Paths.fw_offset")},revStart:{node:q(e[3],"Paths.rev_node"),offset:q(e[4],"Paths.rev_offset")},name:{sample:zt(e[5],"Paths.sample"),contig:zt(e[6],"Paths.contig"),haplotype:q(e[7],"Paths.haplotype"),fragment:q(e[8],"Paths.fragment")},isIndexed:q(e[9],"Paths.is_indexed")!==0}}async function Eo(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 ct=class n{tagCache;pathCache;pathMapCache;indexTags=new Map;sqlite;index;constructor(e,t){this.sqlite=e,this.index=t}static async open(e){let{source:t,haplotypeIndex:r}=e,o={blockSize:e.blockSize,maxBlocks:e.maxBlocks},s=await ft.open(t,o);for(let c of["Tags","Nodes","Paths","ReferenceIndex"])s.rootPage(c);let i=r?await ft.open(r,o):void 0,a=new n(s,i),f=await a.tag("version");if(f!==Dn)throw new Dt(f);if(i){for(let u of["Tags","HaplotypeSamples","HaplotypeLengths"])i.rootPage(u);a.indexTags=await Eo(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 d=a.indexTags.get("haplotype_index_nodes"),h=await a.tag("nodes");if(d!==void 0&&d!==h)throw new Error(`haplotype index was built for a graph with ${d} nodes but this one has ${h}`);if(a.indexTags.get("haplotype_index_orientations")==="forward")throw new Gt}return a}tags(){return this.tagCache??=Eo(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 Gn(e,qr(qt(t[1],"Nodes.edges")),qt(t[2],"Nodes.bwt"),qt(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(vo(t,r));return e})(),this.pathCache}async getPath(e){let t=await this.sqlite.byRowid("Paths",e);return t?vo(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 pathsNamed(e){let t=Qe(We(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(`${i?`The fragment of ${ge(i.name)} at ${i.name.fragment}`:`Path ${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 getPathFragments(e){let{start:t,end:r}=e,o=await this.pathsNamed(e.path);if(o.length===0)throw new Bt(Qe(We(e.path),0));if(r<=t)return[];let 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){let{sample:r,contig:o,haplotype:s}=e.path.name,i=Math.max(t.start,e.start),a=t.haplotypes??"all";try{let f=await Bn(this,{...t,path:{sample:r,contig:o,haplotype:s},start:i,end:Math.min(t.end,e.end)});return t.keep===void 0&&this.hasHaplotypeIndex&&(a==="all"||a==="distinct")&&await f.identifyPaths(),f}catch(f){throw f instanceof Se&&f.walkedBp!==void 0?new Se(f.limit,{windowBp:t.end-t.start,walkedBp:i-t.start+f.walkedBp}):f}}async getSubgraphs(e){let t=await this.getPathFragments(e);return(await Promise.allSettled(t.map(o=>this.subgraphForFragment(o,e)))).map(o=>{if(o.status==="rejected")throw o.reason;return o.value})}async getAlignments(e){return(await this.getSubgraphs(e)).flatMap(t=>t.alignments())}subgraphInInterval(e){return Bn(this,e)}subgraphAtOffset(e){return wo(this,e)}subgraphAroundNodes(e){return yo(this,e)}subgraphBetween(e){return xo(this,e)}fetchStats(){let e=({pager:t})=>({fetches:t.fetches,bytesFetched:t.bytesFetched});return{graph:e(this.sqlite),haplotypeIndex:this.index?e(this.index):void 0}}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=Ur(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 haplotypeSampleGap(){let e=await this.haplotypeSampleInterval(),t=this.indexTags.get("haplotype_index_reference_interval");return e===void 0?void 0:Math.max(e,t===void 0?0:Number(t))}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 haplotypeStrayOptions(){let e=r=>this.indexTags.get(`haplotype_index_stray_${r}`);if(!this.index?.has("HaplotypeStrays")||!this.index.has("HaplotypeBinNodes")||e("format")!=="2")return;let t=e("snarls")==="modeled"&&e("chain_links")===(await this.tag("chain_links")??"0");return{context:Number(e("context")),bin:Number(e("bin")),bound:Number(e("bound")),snarlNodes:t?Number(e("snarl_nodes")):void 0}}async haplotypeStraysInBins(e,t,r){let o=[];for await(let s of this.companion.indexScanFrom("HaplotypeStrays",[e,t])){let i=q(s[1],"HaplotypeStrays.bin");if(s[0]!==e||i>r)break;let a=q(s[4],"HaplotypeStrays.snarl_low"),f=q(s[5],"HaplotypeStrays.snarl_high");o.push({bin:i,pathHandle:q(s[2],"HaplotypeStrays.path_handle"),pathStart:q(s[3],"HaplotypeStrays.path_start"),snarl:f>0?[a,f]:void 0,pathEnd:q(s[6],"HaplotypeStrays.path_end"),node:q(s[7],"HaplotypeStrays.node_handle"),offset:q(s[8],"HaplotypeStrays.node_offset")})}return o}async haplotypeBinNodes(e,t,r){let o=[];for await(let a of this.companion.indexScanFrom("HaplotypeBinNodes",[e,t])){if(a[0]!==e||q(a[1],"HaplotypeBinNodes.bin")>r)break;let f=qt(a[3],"HaplotypeBinNodes.nodes"),c=0,l=0,d=()=>{let h=0,u=1;for(;;){let p=f[l++];if(p===void 0)throw new Error("HaplotypeBinNodes.nodes ends inside a number");if(h+=(p&127)*u,u*=128,(p&128)===0)return h}};for(;l<f.length;){let h=c+d();c=h+d(),o.push([h,c])}}o.sort((a,f)=>a[0]-f[0]);let s=[],i=[];for(let[a,f]of o){let c=i.length-1;c>=0&&a<=i[c]+1?i[c]=Math.max(i[c],f):(s.push(a),i.push(f))}return a=>{let f=0,c=s.length;for(;f<c;){let l=f+c>>1;s[l]<=a?f=l+1:c=l}return f>0&&a<=i[f-1]}}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",q(r[2],"HaplotypeAnchors rowid")):void 0;return o?{node:q(o[2],"HaplotypeAnchors.node_handle"),pathOffset:q(o[3],"HaplotypeAnchors.path_offset")}:void 0}haplotypeSamplesAtNode(e){return this.haplotypeSamplesInRange(e,e)}sampleFromRow(e){return{node:q(e[0],"HaplotypeSamples.node_handle"),offset:q(e[1],"HaplotypeSamples.node_offset"),pathHandle:q(e[2],"HaplotypeSamples.path_handle"),orientation:q(e[3],"HaplotypeSamples.orientation")===0?"forward":"reverse",pathOffset:q(e[4],"HaplotypeSamples.path_offset")}}async haplotypeSamplesInRange(e,t){let r=[];for await(let o of this.companion.indexScanFrom("HaplotypeSamples",[e,0])){if(q(o[0],"HaplotypeSamples.node_handle")>t)break;let i=await this.companion.byRowid("HaplotypeSamples",q(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",q(r[2],"HaplotypeSamples rowid"));return o?this.sampleFromRow(o):void 0}async haplotypeLength(e){let t=await this.companion.byRowid("HaplotypeLengths",e);return t?q(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:q(t[1],"ReferenceIndex.path_offset"),pos:{node:q(t[2],"ReferenceIndex.node_handle"),offset:q(t[3],"ReferenceIndex.node_offset")}}}async indexedRowid(e,t){let r=await this.sqlite.indexSeekLE("ReferenceIndex",[e,t]);return r?.[0]===e?q(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 lr=de(_n(),1),dr=de(nt(),1),yn=de(_r(),1),Is=de(Ps(),1);function zn(n){let e=/\.gbz\.db$/i;return e.test(n)?n.replace(e,".haplotype-index.db"):void 0}var Ao=de(_r(),1);function wi(n){return Rr(n)&&zn(Mr(n))?Pr(n,e=>zn(e)):void 0}function yi(n){return n instanceof Error&&(/\bHTTP 40[34]\b/.test(n.message)||n.code==="ENOENT")}async function Co(n,e){let t=wi(n);if(!t)return{};try{return await(0,Ao.openLocation)(t,e).stat(),{location:t}}catch(r){return yi(r)?{}:{unreadable:String(r)}}}var Mo=de(_n(),1),xi=5e3,bi=50*2**20,jn=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 Si(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)),jt=class{constructor(e,t){this.file=e;this.tabix=t;this.whole=(0,Mo.cachedSetup)({setup:async()=>{let{size:e}=await this.file.stat();if(e>bi)throw new jn(e);let t=await this.file.readFile(),r=new TextDecoder().decode(t[0]===31&&t[1]===139?await kr(t):t);return Tr(r)}})}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=Or(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.whole({signal:t})).filter(o=>_o(o,e));return{records:Si(r,xi),total:r.length}}};var xs=de(_n(),1),bs=de(nt(),1);var Un=function(n,e){return Un=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])},Un(n,e)};function lt(n,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Un(n,e);function t(){this.constructor=n}n.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function Ro(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(d){i(d)}}function f(l){try{c(r.throw(l))}catch(d){i(d)}}function c(l){l.done?s(l.value):o(l.value).then(a,f)}c((r=r.apply(n,e||[])).next())})}function Ut(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 Be(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 Ve(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 Ke(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 Po(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(u){return function(p){return Promise.resolve(p).then(u,d)}}function a(u,p){r[u]&&(o[u]=function(m){return new Promise(function(w,x){s.push([u,m,w,x])>1||f(u,m)})},p&&(o[u]=p(o[u])))}function f(u,p){try{c(r[u](p))}catch(m){h(s[0][3],m)}}function c(u){u.value instanceof Ge?Promise.resolve(u.value.v).then(l,d):h(s[0][2],u)}function l(u){f("next",u)}function d(u){f("throw",u)}function h(u,p){u(p),s.shift(),s.length&&f(s[0][0],s[0][1])}}function ko(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 Be=="function"?Be(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 D(n){return typeof n=="function"}function Oo(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 Wt=Oo(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
7
|
`):"",this.name="UnsubscriptionError",this.errors=t}});function Wn(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var Qt=(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=Be(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(D(l))try{l()}catch(m){s=m instanceof Wt?m.errors:[m]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var h=Be(d),u=h.next();!u.done;u=h.next()){var p=u.value;try{To(p)}catch(m){s=s??[],m instanceof Wt?s=Ke(Ke([],Ve(s)),Ve(m.errors)):s.push(m)}}}catch(m){r={error:m}}finally{try{u&&!u.done&&(o=h.return)&&o.call(h)}finally{if(r)throw r.error}}}if(s)throw new Wt(s)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)To(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)&&Wn(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&Wn(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=(function(){var e=new n;return e.closed=!0,e})(),n})();var uf=Qt.EMPTY;function Yt(n){return n instanceof Qt||n&&"closed"in n&&D(n.remove)&&D(n.add)&&D(n.unsubscribe)}function To(n){D(n)?n():n.unsubscribe()}var Ie={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Xe={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];var o=Xe.delegate;return o?.setTimeout?o.setTimeout.apply(o,Ke([n,e],Ve(t))):setTimeout.apply(void 0,Ke([n,e],Ve(t)))},clearTimeout:function(n){var e=Xe.delegate;return(e?.clearTimeout||clearTimeout)(n)},delegate:void 0};function Vt(n){Xe.setTimeout(function(){var e=Ie.onUnhandledError;if(e)e(n);else throw n})}function Qn(){}var Lo=(function(){return Yn("C",void 0,void 0)})();function No(n){return Yn("E",void 0,n)}function Fo(n){return Yn("N",n,void 0)}function Yn(n,e,t){return{kind:n,value:e,error:t}}var De=null;function Ho(n){if(Ie.useDeprecatedSynchronousErrorHandling){var e=!De;if(e&&(De={errorThrown:!1,error:null}),n(),e){var t=De,r=t.errorThrown,o=t.error;if(De=null,r)throw o}}else n()}function $o(n){Ie.useDeprecatedSynchronousErrorHandling&&De&&(De.errorThrown=!0,De.error=n)}var dt=(function(n){lt(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,Yt(t)&&t.add(r)):r.destination=Ai,r}return e.create=function(t,r,o){return new Xt(t,r,o)},e.prototype.next=function(t){this.isStopped?Kn(Fo(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?Kn(No(t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?Kn(Lo,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})(Qt);var Ii=Function.prototype.bind;function Vn(n,e){return Ii.call(n,e)}var vi=(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){Kt(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){Kt(r)}else Kt(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Kt(t)}},n})(),Xt=(function(n){lt(e,n);function e(t,r,o){var s=n.call(this)||this,i;if(D(t)||!t)i={next:t??void 0,error:r??void 0,complete:o??void 0};else{var a;s&&Ie.useDeprecatedNextContext?(a=Object.create(t),a.unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&Vn(t.next,a),error:t.error&&Vn(t.error,a),complete:t.complete&&Vn(t.complete,a)}):i=t}return s.destination=new vi(i),s}return e})(dt);function Kt(n){Ie.useDeprecatedSynchronousErrorHandling?$o(n):Vt(n)}function Ei(n){throw n}function Kn(n,e){var t=Ie.onStoppedNotification;t&&Xe.setTimeout(function(){return t(n,e)})}var Ai={closed:!0,next:Qn,error:Ei,complete:Qn};var Ze=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function qo(n){return n}function Bo(n){return n.length===0?qo:n.length===1?n[0]:function(t){return n.reduce(function(r,o){return o(r)},t)}}var pe=(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=_i(e)?e:new Xt(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=Go(t),new t(function(o,s){var i=new Xt({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[Ze]=function(){return this},n.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Bo(e)(this)},n.prototype.toPromise=function(e){var t=this;return e=Go(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 Go(n){var e;return(e=n??Ie.Promise)!==null&&e!==void 0?e:Promise}function Ci(n){return n&&D(n.next)&&D(n.error)&&D(n.complete)}function _i(n){return n&&n instanceof dt||Ci(n)&&Yt(n)}function Mi(n){return D(n?.lift)}function we(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 Me(n,e,t,r,o){return new Ri(n,e,t,r,o)}var Ri=(function(n){lt(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})(dt);var Zt=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function Jt(n){return D(n?.then)}function en(n){return D(n[Ze])}function tn(n){return Symbol.asyncIterator&&D(n?.[Symbol.asyncIterator])}function nn(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 Pi(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var rn=Pi();function on(n){return D(n?.[rn])}function sn(n){return Po(this,arguments,function(){var t,r,o,s;return Ut(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 an(n){return D(n?.getReader)}function Ee(n){if(n instanceof pe)return n;if(n!=null){if(en(n))return ki(n);if(Zt(n))return Oi(n);if(Jt(n))return Ti(n);if(tn(n))return Do(n);if(on(n))return Li(n);if(an(n))return Ni(n)}throw nn(n)}function ki(n){return new pe(function(e){var t=n[Ze]();if(D(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Oi(n){return new pe(function(e){for(var t=0;t<n.length&&!e.closed;t++)e.next(n[t]);e.complete()})}function Ti(n){return new pe(function(e){n.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,Vt)})}function Li(n){return new pe(function(e){var t,r;try{for(var o=Be(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 Do(n){return new pe(function(e){Fi(n,e).catch(function(t){return e.error(t)})})}function Ni(n){return Do(sn(n))}function Fi(n,e){var t,r,o,s;return Ro(this,void 0,void 0,function(){var i,a;return Ut(this,function(f){switch(f.label){case 0:f.trys.push([0,5,6,11]),t=ko(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 ye(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 fn(n,e){return e===void 0&&(e=0),we(function(t,r){t.subscribe(Me(r,function(o){return ye(r,n,function(){return r.next(o)},e)},function(){return ye(r,n,function(){return r.complete()},e)},function(o){return ye(r,n,function(){return r.error(o)},e)}))})}function cn(n,e){return e===void 0&&(e=0),we(function(t,r){r.add(n.schedule(function(){return t.subscribe(r)},e))})}function zo(n,e){return Ee(n).pipe(cn(e),fn(e))}function jo(n,e){return Ee(n).pipe(cn(e),fn(e))}function Uo(n,e){return new pe(function(t){var r=0;return e.schedule(function(){r===n.length?t.complete():(t.next(n[r++]),t.closed||this.schedule())})})}function Wo(n,e){return new pe(function(t){var r;return ye(t,e,function(){r=n[rn](),ye(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 D(r?.return)&&r.return()}})}function ln(n,e){if(!n)throw new Error("Iterable cannot be null");return new pe(function(t){ye(t,e,function(){var r=n[Symbol.asyncIterator]();ye(t,e,function(){r.next().then(function(o){o.done?t.complete():t.next(o.value)})},0,!0)})})}function Qo(n,e){return ln(sn(n),e)}function Yo(n,e){if(n!=null){if(en(n))return zo(n,e);if(Zt(n))return Uo(n,e);if(Jt(n))return jo(n,e);if(tn(n))return ln(n,e);if(on(n))return Wo(n,e);if(an(n))return Qo(n,e)}throw nn(n)}function Xn(n,e){return e?Yo(n,e):Ee(n)}function ht(n,e){return we(function(t,r){var o=0;t.subscribe(Me(r,function(s){r.next(n.call(e,s,o++))}))})}function Vo(n,e,t,r,o,s,i,a){var f=[],c=0,l=0,d=!1,h=function(){d&&!f.length&&!c&&e.complete()},u=function(m){return c<r?p(m):f.push(m)},p=function(m){s&&e.next(m),c++;var w=!1;Ee(t(m,l++)).subscribe(Me(e,function(x){o?.(x),s?u(x):e.next(x)},function(){w=!0},void 0,function(){if(w)try{c--;for(var x=function(){var S=f.shift();i?ye(e,i,function(){return p(S)}):p(S)};f.length&&c<r;)x();h()}catch(S){e.error(S)}}))};return n.subscribe(Me(e,u,function(){d=!0,h()})),function(){a?.()}}function Je(n,e,t){return t===void 0&&(t=1/0),D(e)?Je(function(r,o){return ht(function(s,i){return e(r,s,o,i)})(Ee(n(r,o)))},t):(typeof e=="number"&&(t=e),we(function(r,o){return Vo(r,o,n,t)}))}function Ko(n,e,t,r,o){return function(s,i){var a=t,f=e,c=0;s.subscribe(Me(i,function(l){var d=c++;f=a?n(f,l,d):(a=!0,l),r&&i.next(f)},o&&(function(){a&&i.next(f),i.complete()})))}}function Xo(n,e){return we(Ko(n,e,arguments.length>=2,!1,!0))}var Hi=function(n,e){return n.push(e),n};function dn(){return we(function(n,e){Xo(Hi,[])(n).subscribe(e)})}function Zo(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 er(n){let e="";for(let{own:t,mate:r,op:o}of Zo(n))e+=o==="M"?t===0?`${r}I`:r===0?`${t}D`:`${t}M`:`${o==="I"?r:t}${o}`;return e}var Zn=2**28-1;function Jn(n,e,t){for(let r=e;r>0;r-=Zn)n.push((Math.min(r,Zn)<<4|t)>>>0)}function $i(n,e,t){if(e===t)Jn(n,e,0);else{let r=Math.ceil(Math.max(e,t)/Zn);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 tr(n){let e=[];for(let{own:t,mate:r,op:o}of Zo(n))o==="M"?$i(e,t,r):o==="I"?Jn(e,r,1):Jn(e,t,o==="N"?3:2);return Uint32Array.from(e)}function qi(n){return n>=48&&n<=57}function Bi(n){return n!==void 0&&/[A-Za-z]/.test(n)}function Jo(n,e){let t=e;for(;t<n.length&&Bi(n[t]);)t++;return t}function es(n,e){let t=e,r=0;for(;t<n.length&&qi(n.charCodeAt(t));)r=r*10+(n.charCodeAt(t)-48),t++;return{value:r,next:t}}function ss(n,e){let t=0;for(;t<n.length;){let r=n[t];if(r===":"){let{value:o,next:s}=es(n,t+1);e(":",o,o,t+1,s),t=s}else if(r==="="){let o=Jo(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=Jo(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}=es(n,t+3),i=Math.min(s+2,n.length);e("~",o,0,t+1,i),t=i}else t++}}function nr(n,e,t,r){let o=t??Number.NEGATIVE_INFINITY,s=r??Number.POSITIVE_INFINITY,i=0;ss(n,(a,f,c,l,d)=>{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 h=n.slice(l,d);e(73,i,c,h,-1,0,c)}}else(a==="-"||a==="~")&&i<s&&i+f>o&&e(a==="-"?68:78,i,f,"",-1,0,0);i+=f})}function is(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],d=l>>>4,h=l&15;if(h===0||h===7){if(a)for(let u=0;u<d;u++)(e.charCodeAt(s+u)|32)!==(t.charCodeAt(o+u)|32)&&i.push({start:o+u,type:"mismatch",base:e[s+u],altbase:t[o+u],length:1});s+=d,o+=d}else if(h===1)i.push({start:o,type:"insertion",insertlen:d,insertedBases:e?.slice(s,s+d),length:0}),s+=d;else if(h===2)i.push({start:o,type:"deletion",length:d}),o+=d;else if(h===3)i.push({start:o,type:"skip",length:d}),o+=d;else if(h===8){for(let u=0;u<d;u++)i.push({start:o+u,type:"mismatch",base:e?.[s+u]||"X",qual:r?.[s+u],length:1});s+=d,o+=d}else h===5?i.push({start:o,type:"hardclip",cliplen:d,length:1}):h===4&&(i.push({start:o,type:"softclip",cliplen:d,length:1}),s+=d)}return i}function as(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 S=0;S<c;S++)if(t[S].type==="skip"){l=!0;break}let d=0,h=0,u=0,p=0,m=0,w=0,x=n.length;for(;w<x;){let S=n.charCodeAt(w);if(S>=48&&S<=57){let g=0;for(;w<x;){let I=n.charCodeAt(w);if(I>=48&&I<=57)g=g*10+(I-48),w++;else break}d+=g}else if(S===94)for(w++;w<x&&n.charCodeAt(w)>=65;)w++,d++;else if(S>=65){let g=n[w];if(w++,l&&c>0)for(let T=m;T<c;T++){let O=t[T];O.type==="skip"&&d>=O.start&&(d+=O.length,m=T+1)}let I=u,y=p;for(let T=h;T<i&&y<=d;T++,h=T){let O=e[T],F=O>>>4,_=O&15;_===4||_===1?I+=F:_===2||_===6||_===3?y+=F:_!==5&&(I+=F,y+=F)}u=I,p=y;let E=I-(y-d),A=E<a?r[E]:"X";s.push({start:d,base:A,qual:f?o[E]:void 0,altbase:g,length:1,type:"mismatch"}),d++}else w++}return s}var fs={77:0,73:1,68:2,78:3,83:4,72:5,80:6,61:7,88:8};function cs(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=fs[s];t.push(e<<4|i),e=0}}return t}function sr(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|fs[a],r=0)}return t}function gn(n,e,t,r,o){let s=cs(n),i=n?is(s,t,r,o):[];return e&&t?i.concat(as(e,s,i,t,o)):i}var zi=397,ji=387,Ui=385;function ls(n){return(1<<n&zi)!==0}function ds(n){return(1<<n&ji)!==0}function hs(n){return(1<<n&Ui)!==0}function ir(n,e,t,r,o,s,i){let a=o===-1?-1:1,f=e,c=o===-1?r:t,l=[],d=1/0,h=-1/0,u=1/0,p=-1/0,m=(w,x)=>{u=Math.min(u,w,x),p=Math.max(p,w,x)};for(let w=0;w<n.length;w++){let x=n[w],S=x>>>4,g=x&15,I=g===9,y=I||ls(g)?S:0,E=I?n[++w]>>>4:ds(g)?S:0,A=f+y,T=c+E*a,O=f,F=A;if(F>=s&&O<=i)if(y>0){let _=Math.max(O,s),z=Math.min(F,i);if(z>_)if(d=Math.min(d,_),h=Math.max(h,z),I){let R=E/S,j=z-_,V=Math.round(j*R),ue=Math.round(c+(_-f)*R*a);l.push(j<<4|9,V<<4|9),m(ue,ue+V*a)}else l.push(z-_<<4|g),hs(g)?m(c+(_-f)*a,c+(z-f)*a):m(c,c)}else E>0&&(I?l.push(x,n[w]):l.push(x),d=Math.min(d,f),h=Math.max(h,f),m(c,T));if(f=A,c=T,f>i)break}if(l.length!==0)return{start:d,end:h,mateStart:u,mateEnd:p,cigar:Uint32Array.from(l)}}function Wi(n){return n===1||n===2||n===3}function ar(n,e,t,r,o,s){let i=o===-1?-1:1,a=[],f=e,c=o===-1?r:t,l,d=!1,h=()=>{l!==void 0&&d&&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,d=!1};for(let u=0;u<n.length;u++){let p=n[u],m=p>>>4,w=p&15,x=w===9,S=x?n[++u]:void 0,g=x||ls(w)?m:0,I=S!==void 0?S>>>4:ds(w)?m:0,y=c+I*i;Wi(w)&&m>=s?h():(g>0||I>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,y),l.tHi=Math.max(l.tHi,c,y),l.ops.push(p),S!==void 0&&l.ops.push(S),d=d||x||hs(w)),f+=g,c=y}return h(),a}function ps(n){let e=n.get("CIGAR");return typeof e=="string"?e:void 0}function us(n){let e=n.get("coarseCigar");return typeof e=="string"?e:void 0}function fr(n){let e=ps(n),t=e===void 0?us(n):void 0;return e!==void 0?sr(e):t!==void 0?tr(t):void 0}var Qi=de(nt(),1),Yi=de(gs(),1);var Vi=de(nt(),1);var Ki=de(ks(),1);var ws=de(nt(),1),Oe=class extends ws.SimpleFeature{get(e){return e==="mismatches"?gn(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"?er(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)nr(i,e,o,s);else{let a=o??Number.NEGATIVE_INFINITY,f=s??Number.POSITIVE_INFINITY;for(let c of gn(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 Xi=["CIGAR","cs","coarseCigar","cg","cr"];function Zi(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 Ji(n){let e=n.get("mate");return Zi(e)?e:void 0}function ea(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 ta(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:fr(n);if(f===void 0){let c=a?{...s,mateStart:e.start,mateEnd:e.end}:ea(s,e,i,t);return c===void 0?[]:[c]}else return(r===void 0?[{...s,mateStart:e.start,mateEnd:e.end,cigar:f}]:ar(f,s.start,e.start,e.end,i,r)).flatMap(l=>{let d=ir(l.cigar,l.start,l.mateStart,l.mateEnd,i,t.start,t.end);return d===void 0?[]:[d]})}function na(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 Xi)delete f[c];return s&&t.cigar&&(f.alignmentOps=t.cigar),new Oe(f)}function ys(n,e,t,r=!1){let o=Ji(n);if(o===void 0)return[n];{let s=ta(n,o,e,t,r);return s.map((i,a)=>na(n,o,i,e,s.length>1?`/${a}`:"",r))}}var wn=class extends xs.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,bs.createStatusFanOut)(a.statusCallback);return Xn(t).pipe(Je((l,d)=>this.getFeatures(l,{...a,statusCallback:c()}).pipe(Je(h=>f?ys(h,h.get("assemblyName")===l.assemblyName?l:{start:h.get("start"),end:h.get("end")},s,i):[h]),dn(),ht(h=>({index:d,features:h})))),dn(),Je(l=>l.sort((d,h)=>d.index-h.index).flatMap(d=>d.features)))}};var xn=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"}},hr=class extends Error{constructor(t){super(`a pair query names both lanes: queryAssemblyName ${t} came without a targetAssemblyName`);this.name="PairTargetError"}},pr=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 Ss(n,e){let t=Ae(e);return n[t]??n[e.sample]??t}function ra(n,e){return`${Ae(n)}#${n.contig}@${e.start.node}.${e.start.offset}`}function oa({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,d=ra(f,n),h={uniqueId:d,assemblyName:e,refName:t,start:o,end:s,type:"match",strand:i==="-"?-1:1,CIGAR:a,syntenyId:d,mate:{refName:f.contig,start:c,end:l,assemblyName:r}};return new Oe(h)}}function sa({pair:n,lane:e,mateLane:t}){let r=`${Ae(n.target)}#${n.target.contig}:${n.targetStart}-${n.targetEnd}|${Ae(n.query)}#${n.query.contig}:${n.queryStart}-${n.queryEnd}`;return new Oe({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 cr=n=>!("uri"in n)||n.uri!=="",ur=class extends wn{constructor(){super(...arguments);this.graph=(0,lr.cachedSetup)({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),r=this.getConf("haplotypeIndexLocation"),o=cr(r)?{location:r}:await Co(t,this.pluginManager),s=o.location,i=await ct.open({source:(0,yn.openLocation)(t,this.pluginManager),haplotypeIndex:s?(0,yn.openLocation)(s,this.pluginManager):void 0}),a=this.getConf("assemblyNames")[0];if(a===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let f=await En(i),c=gt({configured:this.getConf("referenceSample"),anchorPrefix:ze(this,a),referenceSamples:f});return{db:i,anchor:a,referenceSample:c,referenceSamples:f,unreadableIndex:o.unreadable}}});this.gaf=(0,lr.cachedSetup)({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),r=this.getConf(["readsIndex","location"]);return cr(t)?new jt((0,yn.openLocation)(t,this.pluginManager),cr(r)?Lr(this,["readsLocation"],["readsIndex"]):void 0):void 0}})}async referenceQuery(t,r){let{db:o,referenceSample:s}=await this.graph(r);return An(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=Ae(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=In(this),a=[];for(let f of await this.getHaplotypes(t))f.sample!==o&&a.push({name:Ss(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:ze(this,i),f=(await r.paths()).filter(c=>i===o?c.isIndexed&&c.name.sample===s:mt(Ae(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=>ze(this,s));return o===void 0&&r===void 0?void 0:s=>vn(s,o)&&(r===void 0||mt(Ae(s),r))}async getSubgraph(t,r={}){let{db:o,anchor:s,unreadableIndex:i}=await this.graph(),{assemblyName:a,refName:f,start:c,end:l}=t;if(a!==s)throw new pr(a,s);let d=await this.referenceQuery(f,{}),h=this.keepPredicate(r.haplotypes);if(h!==void 0&&!o.hasHaplotypeIndex)throw new xn(i);return Cn(o,d,c,l,{context:this.getConf("context"),snarls:r.snarls??this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:r.signal,keep:h})}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=ze(this,t);return(await this.getHaplotypes(r)).filter(s=>mt(s.prefix,o))}async anchorFeatures(t,r){let{db:o}=await this.graph(r),{assemblyName:s,refName:i,start:a,end:f}=t,c=ze(this,r.targetAssemblyName),l=In(this),d=this.keepPredicate(r.haplotypes,c),h=await this.referenceQuery(i,r),u=this.getConf("nodeLimit");return(h?await(0,dr.updateStatus)(`Reading graph ${i}:${a.toLocaleString()}-${f.toLocaleString()}`,r.statusCallback,()=>o.getAlignments({path:h,start:a,end:f,context:this.getConf("context"),haplotypes:"all",limit:u,signal:r.signal,keep:d}).catch(m=>{throw wt(m,u,f-a)??m})):[]).flatMap(m=>{let w=m.resolved?oa({alignment:m,assemblyName:s,refName:i,lane:Ss(l,m.name)}):void 0;return w===void 0?[]:[w]})}async pairFeatures(t,r,o){let{targetAssemblyName:s}=o;if(s===void 0)throw new hr(r);let{db:i}=await this.graph(o),{refName:a,start:f,end:c}=t,l=await this.laneHaplotypes(r,o),d=await this.laneHaplotypes(s,o),h=[...l,...d],u=await this.referenceQuery(a,o),p=this.getConf("nodeLimit"),m=x=>i.getSubgraphs({path:x,start:f,end:c,context:this.getConf("context"),snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:p,signal:o.signal,keep:S=>h.some(g=>g.sample===S.sample&&g.haplotype===S.haplotype)}).catch(S=>{throw wt(S,p,c-f)??S});return(u&&l.length>0&&d.length>0?await(0,dr.updateStatus)(`Reading ${r} against ${s}`,o.statusCallback,()=>m(u)):[]).flatMap(x=>l.flatMap(S=>d.flatMap(g=>x.pairAlignments({target:S,query:g,bases:!1}).map(I=>sa({pair:I,lane:r,mateLane:s})))))}getFeatures(t,r={}){return(0,Is.ObservableCreate)(async o=>{let{db:s,anchor:i,unreadableIndex:a}=await this.graph(r);if(!s.hasHaplotypeIndex)throw new xn(a);if(t.assemblyName===i){let f=r.queryAssemblyName===void 0?await this.anchorFeatures(t,r):await this.pairFeatures(t,r.queryAssemblyName,r);for(let c of f)o.next(c)}o.complete()},r.signal)}};export{pr as HaplotypeWindowError,xn as NoHaplotypeIndexError,Ms as NoReferenceSampleError,Rs as NodeLimitError,hr as PairTargetError,ur as default,oa as fragmentFeature,Ae as haplotypePrefix,Ss as laneAssemblyName,wt as nodeLimitError,sa as pairFeature,gt as resolveReferenceSample};
|
|
8
|
-
//# sourceMappingURL=GbzBaseSyntenyAdapter-
|
|
8
|
+
//# sourceMappingURL=GbzBaseSyntenyAdapter-VOGKGHQ6.js.map
|