chromosomix 0.16.0 → 0.18.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 +95 -11
- package/dist/THIRD-PARTY-NOTICES.txt +2 -2
- package/dist/assets/{ConnectCard-CWRFeF4q.js → ConnectCard-CNwlR_yV.js} +1 -1
- package/dist/assets/{Tour-5RTXNjqt.js → Tour-Dn4L7jES.js} +1 -1
- package/dist/assets/analysis.worker-2Jx8_NWN.js +8 -0
- package/dist/assets/annotations.worker-Bd03nKdJ.js +28 -0
- package/dist/assets/index-BZqg8J4S.js +106 -0
- package/dist/assets/index-Cxw-esX1.css +1 -0
- package/dist/assets/likelihood.worker-CUgAXfAe.js +1 -0
- package/dist/assets/reader.worker-DKXrm0nO.js +9 -0
- package/dist/assets/{three-D5ICz1As.js → three-BZagS2ne.js} +1 -1
- package/dist/assets/{tutorial-qCyAYx6Y.js → tutorial-DOptkiKU.js} +1 -1
- package/dist/assets/workspace-ZYKuBclx.js +15 -0
- package/dist/index.html +2 -2
- package/dist-cli/THIRD-PARTY-NOTICES.txt +2 -2
- package/dist-cli/chromosomix.mjs +5965 -1369
- package/package.json +6 -1
- package/dist/assets/analysis.worker-DZ9FXIW0.js +0 -8
- package/dist/assets/annotations.worker-Bybt4X5J.js +0 -27
- package/dist/assets/index-CJPGLvTr.css +0 -1
- package/dist/assets/index-DkMx8MnH.js +0 -103
- package/dist/assets/reader.worker-CuEqyC9X.js +0 -9
- package/dist/assets/workspace-tu5v3vK_.js +0 -17
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function xt(){return typeof MessageChannel>"u"?new Promise(e=>{setTimeout(e,0)}):new Promise(e=>{const t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),t.port2.close(),e()},t.port2.postMessage(void 0)})}const _1=200,D1=3e3,R1=3e4,P1=1e3;function z1(e=_1,t=D1){const n=[];let s=performance.now();const o=setInterval(()=>{const r=performance.now(),i=r-s;for(s=r,i<R1?n.push({at:r,span:i,late:Math.max(0,i-e)}):n.length=0;n.length>0&&r-n[0].at>t;)n.shift()},e);return{busy(){if(n.length<3)return 0;let r=0,i=0;for(const a of n)r+=a.span,i+=a.late;return r<=0?0:Math.min(1,i/r)},reset(){n.length=0,s=performance.now()},stop(){clearInterval(o)}}}function st(e){if(e==null)return"None";if(typeof e=="boolean")return e?"True":"False";if(typeof e=="number")return Number.isInteger(e),String(e);if(Array.isArray(e))return`[${e.map(st).join(", ")}]`;if(typeof e!="string")return String(e);const t=e.includes("'")&&!e.includes('"')?'"':"'",n=e.replace(/\\/g,"\\\\").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(new RegExp(t,"g"),`\\${t}`);return`${t}${n}${t}`}function zt(e){return`[${e.map(st).join(", ")}]`}function Bc(e){const t=e.trim();if(!/^[+-]?[0-9](?:_?[0-9])*$/.test(t))return null;const n=Number(t.replace(/_/g,""));return Number.isFinite(n)?n:null}class T extends Error{code;detail;constructor(t,n,s={}){super(n),this.name="ViewerError",this.code=t,this.detail=s}}class at extends T{constructor(t,n={},s="format"){super(s,t,n),this.name="MetaCoolerFormatError"}}function Ke(e,t=20){return e.length<=t?zt(e):`${zt(e.slice(0,t))} ... (${e.length-t} more)`}const ys="HDF5::MetaCooler",uo=1,Tc="HDF5::MMetaCooler",Nr="HDF5::Cooler",Nn="HDF5::SCOOL",ho=1,ls="cells",Mr=["bins","pixels","indexes"],li=5e4,q1=3/4,U1=8,Un=2**31,G1=1e9,H1=2,ui=["symmetric-upper","square"],Gn="genome-then-length",Mn="__unbinned__",Q1=["","null","none","nan"],fo=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),K1=new Intl.NumberFormat(void 0,{maximumFractionDigits:3}),W1=new Intl.NumberFormat(void 0,{maximumSignificantDigits:3}),hi=new Map,Y1=new Intl.NumberFormat("en-US",{maximumFractionDigits:0}),Mt={int(e){return Number.isFinite(e)?fo.format(e):"—"},num(e){if(!Number.isFinite(e))return"—";if(Number.isInteger(e))return fo.format(e);const t=Math.abs(e);return t>=.001?K1.format(e):t>=1e-7?W1.format(e):e.toExponential(2)},fixed(e,t){if(!Number.isFinite(e))return"—";let n=hi.get(t);return n===void 0&&(n=new Intl.NumberFormat(void 0,{minimumFractionDigits:t,maximumFractionDigits:t}),hi.set(t,n)),n.format(e)},pct(e,t=1){return Number.isFinite(e)?`${(e*100).toFixed(t)}%`:"—"},pos(e){return Number.isFinite(e)?Y1.format(Math.round(e)):"—"},bp(e){return Number.isFinite(e)?Math.abs(e)>=1e6?`${(e/1e6).toFixed(2)} Mb`:Math.abs(e)>=1e3?`${(e/1e3).toFixed(1)} kb`:`${fo.format(e)} bp`:"—"},bytes(e){if(!Number.isFinite(e))return"—";const t=["B","kB","MB","GB","TB"];let n=e,s=0;for(;n>=1e3&&s<t.length-1;)n/=1e3,s++;return`${s===0?n:n.toFixed(1)} ${t[s]}`}};function V1(e){return!Number.isFinite(e)||e<=0?"—":e>=1e6?`${mo(e/1e6)} Mb`:e>=1e3?`${mo(e/1e3)} kb`:`${mo(e)} bp`}function mo(e){return String(Number(e.toFixed(2)))}const X1=["exact","case","decorated","prefix","padded","roman","organelle","accession","version"],fi=new Set(["gi","gb","ref","emb","dbj","tpg","tpe","tpd","lcl","pir","prf","sp","tr","pdb","ena","bbs"]);function Ir(e){let t=e.trim().split(/\s+/)[0]??"";if(t=t.replace(/[,;]+$/,""),t.includes("|")){const n=t.split("|").filter(s=>s!=="");if(n.some(s=>fi.has(s.toLowerCase()))){const s=n.filter((o,r)=>fi.has(o.toLowerCase())?!1:!(/^[0-9]+$/.test(o)&&r>0&&n[r-1].toLowerCase()==="gi"));s.length>0&&(t=s[s.length-1])}}return t}const Oc=/^(?:chromosome|chrom|chr)[ _.-]?/i;function Lc(e){const t=e.replace(Oc,"");if(t===""||t===e)return null;const n=t.toLowerCase();return/^[0-9]/.test(t)||Ms.has(n)||Ns.has(n)||qs(t)>0||/^un[_.-]/i.test(t)||/^[A-Za-z]{1,2}[0-9]/.test(t)||Dc.test(t)||Rc.test(t.replace(/\.[0-9]+$/,""))?t:null}const J1=/^(?:lg|linkage_?group|group)[ _.-]?(?=[0-9])/i,_c=/_(random|alt|fix|hap\d+|maternal|paternal)$/i,Z1=/(?:^|[_.-])([A-Z]{2}[0-9]{5,6})v([0-9]+)(?:$|[_.-])/,Dc=/^(N[CGTWZ]|AC)_([0-9]{5,})$/i,Rc=/^[A-Z]{1,6}[0-9]{5,8}$/,j1=[["mito",["m","mt","mtdna","mito","mitochondrion","mitochondria","mitochondrial","mitochondrion_genome","dmel_mitochondrion_genome","mitochondrial_genome","mitochondrion_dna","chrmt","nc_012920","j01415","nc_001224","nc_005089"]],["plastid",["c","pt","cp","chloroplast","plastid","chloroplast_genome","chrc","nc_000932"]],["2micron",["2-micron","2micron","2u","2-micron_plasmid","nc_001398"]]],Ns=new Map;for(const[e,t]of j1)for(const n of t)Ns.set(n,e);const Ms=new Set(["x","y","z","w"]),tu=/^(XL|L|X{0,3})(IX|IV|V?I{0,3})$/i,eu={"":0,x:10,xx:20,xxx:30,xl:40,l:50},nu={"":0,i:1,ii:2,iii:3,iv:4,v:5,vi:6,vii:7,viii:8,ix:9};function qs(e){const t=tu.exec(e);if(t===null)return 0;const n=eu[t[1].toLowerCase()],s=nu[t[2].toLowerCase()];return n===void 0||s===void 0?0:n+s}const su=[{from:1,to:22,first:1,tail:["x","y"]},{from:67,to:85,first:1,tail:["x","y"]}];function ou(e){for(const t of su){if(e>=t.from&&e<=t.to)return String(t.first+(e-t.from));const n=e-t.to-1;if(n>=0&&n<t.tail.length)return t.tail[n]}return null}const Xo=200;function ru(e){return e.length<2||Ms.has(e.toLowerCase())?!1:qs(e)>0}function Ee(e){const t=e.map(c=>Pc(c)),s=t.filter(c=>ru(c)).length>=2,o=t.filter(c=>/^[0-9]+$/.test(c)&&Number(c)>=1&&Number(c)<=Xo),r=o.length<Xo,i=c=>t.some(u=>u.toLowerCase()===c),a=r&&o.length>=2;return{roman:s,ordinals:r,xIsTen:s&&!a&&(i("ix")||i("xi"))}}function Pc(e){const t=Ir(e);return(Lc(t)??t).replace(_c,"")}function us(e,t){const n=[],s=Ir(e);s!==e.trim()&&n.push("decorated");const o=Lc(s),r=o??s;o!==null&&n.push("prefix");const i=_c.exec(r),a=i===null?r:r.slice(0,i.index),c=i===null?"":`+${i[1].toLowerCase()}`,u=a.toLowerCase(),l=Z1.exec(r);if(l!==null)return n.push("accession"),{key:`acc:${l[1].toLowerCase()}`,via:n,version:l[2],opaque:!1};const h=/^(.*?)\.([0-9]+)$/.exec(a),f=h===null?a:h[1],d=h===null?null:h[2],m=Ns.get(u)??Ns.get(f.toLowerCase());if(m!==void 0)return m!==u&&n.push("organelle"),{key:`org:${m}`,via:n,version:d,opaque:!1};const g=Dc.exec(f);if(g!==null){n.push("accession");const b=g[1].toLowerCase()==="nc"?ou(Number(g[2])):null;return b!==null?{key:Ms.has(b)?`sex:${b}${c}`:`num:${b}${c}`,via:n,version:d,opaque:!1}:{key:`acc:${f.toLowerCase()}${c}`,via:n,version:d,opaque:!1}}if(Rc.test(f))return n.push("accession"),{key:`acc:${f.toLowerCase()}${c}`,via:n,version:d,opaque:!1};if(/^[0-9]+$/.test(a)&&t.ordinals&&Number(a)<=Xo)return/^0[0-9]/.test(a)&&n.push("padded"),{key:`num:${Number(a)}${c}`,via:n,version:null,opaque:!1};const p=/^([0-9]{1,2})([a-z]{1,2})$/i.exec(a);if(p!==null&&t.ordinals)return p[1].startsWith("0")&&n.push("padded"),{key:`num:${Number(p[1])}${p[2].toLowerCase()}${c}`,via:n,version:null,opaque:!1};const w=J1.exec(a);if(w!==null){const b=a.slice(w[0].length);if(/^[0-9]+$/.test(b))return/^0[0-9]/.test(b)&&n.push("padded"),{key:`lg:${Number(b)}${c}`,via:n,version:null,opaque:!1}}if(Ms.has(u)&&!(u==="x"&&t.xIsTen))return{key:`sex:${u}${c}`,via:n,version:null,opaque:!1};if(t.roman){const b=qs(a);if(b>0)return n.push("roman"),{key:`num:${b}${c}`,via:n,version:null,opaque:!1}}return{key:`raw:${u}${c}`,via:n,version:null,opaque:!0}}function Is(e){return X1.indexOf(e)}function iu(e,t){let n="case";for(const s of[...e.via,...t.via])Is(s)>Is(n)&&(n=s);return n}function go(e,t){return e===void 0||t===void 0||e<=0||t<=0?"unknown":e===t?"agree":"differ"}const di=new WeakMap;class ge{names;context;styleCache=null;get style(){return this.styleCache??=cu(this.names,this.context),this.styleCache}exact=new Map;folded=new Map;keyed=new Map;constructor(t){this.names=t.map(n=>n.name),this.context=Ee(this.names);for(const n of t){this.exact.has(n.name)||this.exact.set(n.name,n),mi(this.folded,n.name.toLowerCase(),n);const s=us(n.name,this.context);mi(this.keyed,s.key,{sequence:n,canon:s})}}static of(t){return new ge(t)}static ofNames(t){return new ge(t.map(n=>({name:n})))}static for(t){const n=di.get(t);if(n!==void 0)return n;const s=typeof t[0]=="string"?ge.ofNames(t):ge.of(t);return di.set(t,s),s}has(t){return this.exact.has(t)}find(t,n={}){const{length:s}=n,o=this.exact.get(t);if(o!==void 0)return{name:o.name,asked:t,tier:"exact",lengths:go(s,o.length)};const r=this.folded.get(t.toLowerCase());if(r!==void 0&&r.length===1)return{name:r[0].name,asked:t,tier:"case",lengths:go(s,r[0].length)};const i=n.from??this.context,a=this.byKey(t,us(t,i),s);if(a!==null)return a;if(!i.roman){const c=Pc(t).toLowerCase();if(c!=="x"&&c!=="l"&&qs(c)>0)return this.byKey(t,us(t,{...i,roman:!0,xIsTen:!1}),s)}return null}byKey(t,n,s){const o=this.keyed.get(n.key);if(o===void 0||o.length===0)return null;const r=au(o,s);if(r===null)return null;const i=iu(n,r.canon),a=n.version!==null&&r.canon.version!==null&&n.version!==r.canon.version;return{name:r.sequence.name,asked:t,tier:a&&Is(i)<Is("version")?"version":i,lengths:go(s,r.sequence.length)}}}function au(e,t){if(e.length===1)return e[0];if(t===void 0||t<=0)return null;const n=e.filter(s=>s.sequence.length===t);return n.length===1?n[0]:null}function mi(e,t,n){const s=e.get(t);s===void 0?e.set(t,[n]):s.push(n)}function cu(e,t=Ee(e)){if(e.length===0)return"empty";let n=0,s=0,o=0,r=0;for(const a of e){const c=us(a,t);if(c.opaque){r++;continue}c.via.includes("accession")?o++:Oc.test(Ir(a))?n++:s++}const i=n+s+o;return i===0||r>i*4?"assembly":t.roman&&n<=s?"roman":o>n&&o>s?"accession":n>0&&s>0?"mixed":n>0?t.roman?"roman":"ucsc":t.roman?"roman":"ensembl"}function xs(e,t){const n=lu(e),s=n.get(t);if(s!==void 0)return s;const o=ge.for(e).find(t);return o===null?-1:n.get(o.name)??-1}const gi=new WeakMap;function lu(e){const t=gi.get(e);if(t!==void 0)return t;const n=new Map;return e.forEach((s,o)=>{const r=typeof s=="string"?s:s.name;n.has(r)||n.set(r,o)}),gi.set(e,n),n}let ln=null;function kn(){const e=globalThis;return typeof e.window<"u"?!1:typeof e.process<"u"&&e.process?.versions?.node!=null}function We(){return ln||(ln=uu().catch(e=>{throw ln=null,new T("not-hdf5",`Could not initialise the HDF5 (h5wasm) runtime: ${hu(e)}`,{runtime:kn()?"node":"browser"})}),ln)}async function uu(){let e;return kn()?e=await import("h5wasm/node"):e=await import("./hdf5_hl-8FoHa7pu.js"),await e.ready,{File:e.File,Group:e.Group,Dataset:e.Dataset,FS:e.FS,Module:e.Module}}function hu(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}const fu="bhilnpq",du="BHILNPQu",mu="defg";function zc(e){const t=e.trim(),n=()=>{throw new at(`cannot interpret the HDF5 dtype ${JSON.stringify(e)} as a numpy kind`,{dtype:e})};t===""&&n();const s="<>|=".includes(t[0])?t[0]:"",o=s===""?t:t.slice(1);o===""&&n();const r=o[0],i=o.slice(1);switch(i!==""&&!/^\d+$/.test(i)&&n(),r){case"A":case"S":return i===""?"O":"S";case"U":return"U";case"O":return"O";case"?":return"b";case"b":return s==="|"?"b":"i";default:return fu.includes(r)?"i":du.includes(r)?"u":mu.includes(r)?"f":n()}}const Jo=new Uint8Array(new Uint32Array([1]).buffer)[0]===1?0:1;function Zo(e){const t=new Float64Array(e.length);if(e instanceof BigInt64Array||e instanceof BigUint64Array){const n=e.length,s=new Uint32Array(e.buffer,e.byteOffset,n*2),o=e instanceof BigInt64Array?new Int32Array(e.buffer,e.byteOffset,n*2):s,r=Jo,i=1-Jo;for(let a=0;a<n;a++)t[a]=o[2*a+i]*4294967296+s[2*a+r];return t}return t.set(e),t}function qc(e){const t=e.length,n=new Int32Array(e.buffer,e.byteOffset,t*2),s=new Int32Array(t),o=Jo;for(let r=0;r<t;r++)s[r]=n[2*r+o];return s}const gu=new TextDecoder("utf-8");function jo(e,t){const n=e.Module.H5T_class_t;return t.type===n.H5T_STRING.value?"string":t.type===n.H5T_INTEGER.value||t.type===n.H5T_FLOAT.value||t.type===n.H5T_ENUM.value?"number":"other"}function pu(e,t,n,s,o){const r=o-s;if(r<=0)return new Uint8Array(0);const a=n.metadata.size*r,c=xr(e,a);try{return e.Module.get_dataset_data(t.file_id,n.path,[BigInt(r)],[BigInt(s)],[1n],BigInt(c)),e.Module.HEAPU8.slice(c,c+a)}finally{e.Module._free(c)}}function wu(e,t,n){const s=new Array(n);for(let o=0;o<n;o++){let r=e.subarray(o*t,(o+1)*t);const i=r.indexOf(0);i>-1&&(r=r.subarray(0,i)),s[o]=gu.decode(r)}return s}function Uc(e,t,n,s,o){const r=o-s;if(r<=0)return[];const i=n.metadata;if(!i.vlen)return wu(pu(e,t,n,s,o),i.size,r);const a=i.size*r,c=xr(e,a);try{e.Module.get_dataset_data(t.file_id,n.path,[BigInt(r)],[BigInt(s)],[1n],BigInt(c));const u=new Uint32Array(e.Module.HEAPU8.slice(c,c+a).buffer),l=new Array(r);for(let h=0;h<r;h++)l[h]=e.Module.UTF8ToString(u[h]);return l}finally{e.Module.reclaim_vlen_memory_count(t.file_id,n.path,"",BigInt(c),[BigInt(r)]),e.Module._free(c)}}function bu(e,t){if(t.littleEndian===!1||t.vlen)return null;const n=e.Module.H5T_class_t;if(t.type===n.H5T_INTEGER.value)return t.size===8?t.signed?"i64":"u64":t.size===4?t.signed?"i32":"u32":null;if(t.type===n.H5T_FLOAT.value){if(t.size===8)return"f64";if(t.size===4)return"f32"}return null}function Gc(e,t,n,s,o){const r=t.metadata,i=bu(e.h5,r);if(i===null)return null;const a=s-n,{Module:c}=e.h5,u=xr(e.h5,r.size*a);try{return c.get_dataset_data(e.file.file_id,t.path,[BigInt(a)],[BigInt(n)],[1n],BigInt(u)),o(c.HEAPU8.buffer,u,a,i)}finally{c._free(u)}}function Au(e,t,n,s){switch(s){case"f64":return new Float64Array(e,t,n).slice();case"i64":case"u64":return Zo(s==="i64"?new BigInt64Array(e,t,n):new BigUint64Array(e,t,n));default:{const o=new Float64Array(n);return o.set(s==="i32"?new Int32Array(e,t,n):s==="u32"?new Uint32Array(e,t,n):new Float32Array(e,t,n)),o}}}function yu(e,t,n,s){switch(s){case"i32":return new Int32Array(e,t,n).slice();case"i64":case"u64":return qc(s==="i64"?new BigInt64Array(e,t,n):new BigUint64Array(e,t,n));default:{const o=new Int32Array(n);return o.set(s==="u32"?new Uint32Array(e,t,n):s==="f64"?new Float64Array(e,t,n):new Float32Array(e,t,n)),o}}}function Hc(e,t,n,s){if(n-t<=0)return new Float64Array(0);if(s!==void 0){const i=Gc(s,e,t,n,Au);if(i!==null)return i}const r=e.slice([[t,n]]);if(r instanceof Float64Array)return r;if(r instanceof BigInt64Array||r instanceof BigUint64Array||ArrayBuffer.isView(r)&&!(r instanceof DataView))return Zo(r);throw new at(`/${e.path.replace(/^\//,"")} did not read back as a numeric array`,{path:e.path})}function Nu(e,t,n,s){const o=n-t;if(o<=0)return new Int32Array(0);if(s!==void 0){const i=Gc(s,e,t,n,yu);if(i!==null)return i}const r=e.slice([[t,n]]);if(r instanceof Int32Array)return r;if(r instanceof BigInt64Array||r instanceof BigUint64Array)return qc(r);if(ArrayBuffer.isView(r)&&!(r instanceof DataView)){const i=new Int32Array(o);return i.set(r),i}throw new at(`/${e.path.replace(/^\//,"")} did not read back as a numeric array`,{path:e.path})}function en(e,t,n){return{length:e,columns:t,data:n,get(s,o){const r=n[s];if(r===void 0||o<0||o>=e)return;const i=r[o];if(typeof i=="bigint")return Number(i);if(typeof i=="string"||typeof i=="number")return i},strings(s){const o=n[s];if(o===void 0)throw new at(`no such column: ${s}`,{column:s});if(Array.isArray(o)&&(o.length===0||typeof o[0]=="string"))return o;throw new at(`column ${s} is not a string column`,{column:s})},numbers(s){const o=n[s];if(o===void 0)throw new at(`no such column: ${s}`,{column:s});if(o instanceof BigInt64Array)return Array.from(o,Number);if(Array.isArray(o)&&o.length>0&&typeof o[0]=="string")throw new at(`column ${s} is not a numeric column`,{column:s});return Array.from(o)}}}function Mu(e,t,n,s,o,r,i){const a=[];for(const g of n.keys()){const p=n.get(g);if(!(p instanceof e.Dataset))continue;const w=p.metadata,b=w.shape;!b||b.length!==1||a.push({name:g,ds:p,md:w,length:b[0]})}if(new Set(a.map(g=>g.length)).size>1){const g=a.map(p=>`${p.name}=${p.length}`).sort().join(", ");throw new at(`/${s} columns have unequal lengths (${g}); every column of a table must have one row per record`,{table:s})}const u=a.length===0?0:a[0].length,l=pi(o??0,0,u),h=pi(r??u,l,u),f=i===void 0?null:new Set(i),d=[],m={};for(const{name:g,ds:p,md:w}of a)if(!(f!==null&&!f.has(g)))switch(jo(e,w)){case"string":d.push(g),m[g]=Uc(e,t,p,l,h);break;case"number":d.push(g),m[g]=Hc(p,l,h,{h5:e,file:t});break}return en(h-l,d,m)}function pi(e,t,n){return Math.min(Math.max(Math.trunc(e),t),n)}function xr(e,t){if(t>e.Module.MAXIMUM_MEMORY)throw new at(`a ${t} byte read exceeds the wasm heap limit of ${e.Module.MAXIMUM_MEMORY} bytes`,{nbytes:t,limit:e.Module.MAXIMUM_MEMORY});const n=e.Module._malloc(t);if(n===0)throw new at(`allocation of ${t} bytes in the wasm heap failed`,{nbytes:t});return n}function Vt(e){const t=e.indexOf("::");let n,s;if(t!==-1){n=e.slice(0,t).trim();const o=e.slice(t+2).trim();!o||o==="/"?s="/":s=o.startsWith("/")?o:`/${o}`}else n=e.trim(),s="/";if(!n)throw new T("bad-uri",`URI has an empty file path: ${st(e)}`,{uri:e});return{path:n,group:s}}const Iu=["genomes","contigs","bins","pixels","indexes"],xu=["bin-size","format-version","nbins","nnz","sum","ngenomes","ncontigs"];function Tt(e,t){const n=e[t];return typeof n=="string"?n:null}function hs(e,t){const n=e[t];if(n==null)return null;const s=()=>{throw new at(`attrs[${st(t)}] must be an integer, got ${st(n)}`,{key:t,value:n})};if(typeof n=="string"){if(Q1.includes(n.trim().toLowerCase()))return null;const o=Bc(n);return o===null?s():o}return typeof n=="boolean"?s():typeof n=="number"&&Number.isInteger(n)?n:s()}function Qc(e){const t=e["storage-mode"];if(t==null)return"symmetric-upper";if(typeof t=="string"&&ui.includes(t))return t;throw new at(`attrs['storage-mode'] must be one of ${zt([...ui].sort())}, got ${st(t)}`,{"storage-mode":t})}function Kc(e){return e.has("entries")?e.keys("entries"):[]}function vu(e,t){return Mr.some(n=>!e.has(`${t}/${n}`))?!1:Tt(e.attrsAt(t),"format")===Nr}function ku(e,t){if(Tt(t,"format")===Nn)return e.has(ls);if(Tt(t,"metacooler-format")===ys)return!1;const n=Tt(t,"format");return n!==null&&n!==Nr||Mr.some(s=>e.has(s))||e.has("chroms")?!1:!e.has("resolutions")&&!e.has("entries")}function Su(e,t){if(Tt(t,"format")===Nn){const s=e.keys(ls);if(s.length>0)return{names:s,group:ls};throw new T("not-a-cooler",`${e.uri} declares format ${st(Nn)} but has no cells under /${ls}. Top-level keys: ${zt(e.keys("").slice(0,20))}.`,{format:Nn,group:e.group})}if(Mr.some(s=>e.has(s)))return null;const n=e.keys("");return n.length===0?null:vu(e,n[0])?{names:n,group:""}:null}function Cu(e,t,n={}){const s=t??e.attrs(),o=Tt(s,"format");if(n.metacool===!1&&Fu(e,s,o)&&wi(e),o===Tc&&e.has("entries"))return{kind:"mmetacool",group:e.group,entries:Kc(e)};if(Tt(s,"metacooler-format")===ys){const a=Iu.filter(c=>!e.has(c));if(a.length===0)return{kind:"metacool",group:e.group};throw new T("not-a-cooler",`${e.uri} declares metacooler-format ${st(ys)} but is missing ${zt(a.map(c=>`/${c}`))}. It cannot be read as a metacool, and reading it as the plain cooler it also is would drop the genome layer it says it has. If this came out of \`cooler zoomify\`, re-derive the resolutions with \`metacooler zoomify\` instead.`,{missing:[...a]})}const r=e.keys("resolutions");if(r.length>0)return{kind:"mcool",group:e.group,entries:Wc(r)};const i=Su(e,s);if(i!==null)return{kind:"scool",group:e.group,entries:i.names,cellGroup:i.group};if(o===Nr)return{kind:"cool",group:e.group};throw n.metacool===!1&&wi(e),new T("not-a-cooler",`${e.uri} is HDF5 but not a cooler or metacool file: its 'format' attribute is ${st(o)} and 'metacooler-format' is ${st(Tt(s,"metacooler-format"))}. Top-level keys: ${zt(e.keys("").slice(0,20))}. Convert a plain cooler with \`metacooler create cool\`.`,{format:o,group:e.group})}function Fu(e,t,n){return n===Tc&&e.has("entries")||Tt(t,"metacooler-format")===ys}function wi(e){throw new T("not-a-cooler",`${e.uri} is an HDF5 file, but not a contact map this viewer reads: it is not a cooler, an .mcool or an .scool. Top-level keys: ${zt(e.keys("").slice(0,20))}.`,{group:e.group})}function $u(e){const{path:t}=Vt(e.uri),n=Kc(e),s=n.map(r=>`/entries/${r}`),o=s.length>0?s[0]:"/entries/<name>";throw new T("mmetacool-root",`No metacool entry at root of ${t}. Metacool entries found: ${zt(s)}. Use '::' to specify a group path, e.g. ${t}::${o}.`,{path:t,entries:n})}function Wc(e){return e.length>0&&e.every(n=>/^\d+$/.test(n)&&Number(n)>0)?[...e].sort((n,s)=>Number(n)-Number(s)):e}function Eu(e){const t=[...e].sort((n,s)=>n-s);return t[Math.floor(t.length/3)]}function Bu(e,t){const{path:n}=Vt(e.uri),s=t.map(r=>`/resolutions/${r}`),o=s.length>0?s[0]:"/resolutions/<binsize>";throw new T("mcool-root",`No cooler at root of ${n}: an .mcool is a collection of resolutions, each a complete cooler. Resolutions found: ${zt(s)}. Use '::' to pick one, e.g. ${n}::${o}.`,{path:n,entries:t,group:"resolutions"})}function vs(e,t){const n=e.cellGroup??"";return n===""?t:`${n}/${t}`}function Yc(e,t,n){if(hs(n,"bin-size")!==null)return{attrs:n,from:null};const s=t.entries?.[0];if(s===void 0)return{attrs:n,from:null};const o=vs(t,s);return{attrs:e.attrsAt(o),from:o}}function Tu(e,t){if(!((t.entries??[]).length>0))throw new T("not-a-cooler",`${Vt(e.uri).path} is a single-cell cooler container with no cells in it.`,{path:Vt(e.uri).path})}function Ou(e,t,n,s={}){t.kind==="mmetacool"&&$u(e),t.kind==="mcool"&&Bu(e,t.entries??[]);const o=n??e.attrs();if(t.kind==="metacool"){const c=hs(o,"metacooler-format-version");if(c!==null&&c!==uo)throw new T("bad-format-version",`This file declares metacooler-format-version ${c}; the viewer only understands version ${uo}. Re-create it with a matching metacooler release, or open it with the version of the viewer that reads ${c}.`,{found:c,expected:uo});const u=Tt(o,"contig-ordering");if(u!==Gn)throw new T("bad-ordering",`This file's contig-ordering is ${st(u)}; the viewer requires ${st(Gn)}. Only a genome-grouped layout puts every genome in one contiguous block of bins, which is what makes a genome or a genome pair a single bounded read. Re-create the file with \`metacooler create pairs --contig-order ${Gn}\`.`,{found:u,expected:Gn})}const r=t.kind==="scool"?Yc(e,t,o):{attrs:o};if(t.kind==="scool"){Tu(e,t);const c=hs(o,"format-version");if(Tt(o,"format")===Nn&&c!==null&&c!==ho)throw new T("bad-format-version",`This file declares scool format-version ${c}; the viewer understands version ${ho}. Open it with a viewer that reads ${c}, or re-create it with \`cooler.create_scool\`.`,{found:c,expected:ho})}const i=Tt(r.attrs,"bin-type"),a=hs(r.attrs,"bin-size");if(i==="variable"||a===null||a<=0)throw new T("variable-bins",s.metacool===!1?`The viewer supports fixed-bin files only; this file's bin-type is ${st(i)} and its bin-size is ${st(a)}. Bin its contacts at a fixed size — \`cooler cload pairs\` does, from the pairs it was made from — and open that.`:`The viewer supports fixed-bin files only; this file's bin-type is ${st(i)} and its bin-size is ${st(a)}. Fragment-level and contig-level metacools are variable-bin by construction. Produce a fixed-bin file with \`metacooler binnify --binsize <bp>\` and open that.`,{"bin-type":i,"bin-size":a});Qc(r.attrs)}function Vc(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Lu(e){if(typeof e=="number")return Number.isFinite(e)?Math.trunc(e):e;if(typeof e=="string"){const t=Bc(e);return t===null?e:t}return e}function Ae(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function un(e){return typeof e=="string"?e:null}function _u(e){const t={};for(const[w,b]of Object.entries(e))t[w]=Vc(b);const n=w=>{const b=t[w];return delete t[w],b},s=n("metacooler-format"),o=n("metacooler-format-url"),r=n("metacooler-format-version"),i=s!=null,a=i?s:t.format,c=i?o:t["format-url"],u=i?r:t["format-version"],l=n("contig-ordering"),h=n("nchroms"),f=n("assembly-name"),d=n("assembly"),m=n("genome-assembly");let g=m!==void 0?m:d;(g==null||g===""||g==="unknown")&&f!==void 0&&f!==null&&(g=f),n("metadata");const p={"bin-size":t["bin-size"],"format-version":u,nbins:t.nbins,nnz:t.nnz,sum:t.sum,ngenomes:t.ngenomes,ncontigs:h};for(const w of xu)p[w]!==void 0&&(p[w]=Lu(p[w]));return{...t,format:un(a),"format-url":un(c),"format-version":Ae(p["format-version"]),"bin-size":Ae(p["bin-size"]),"bin-type":un(t["bin-type"]),ordering:un(l),assembly:un(g),"storage-mode":Qc(e),nbins:Ae(p.nbins),nnz:Ae(p.nnz),sum:Ae(p.sum),ngenomes:Ae(p.ngenomes),ncontigs:Ae(p.ncontigs)}}function Du(e){const t=Vc(e.metadata);return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}const Ru=new TextDecoder("utf-8");async function Pu(e,t,n){const s=await We(),o=await t.mount();let r;try{r=new s.File(o,"r")}catch(u){throw t.close(),new T("not-hdf5",`${e} could not be opened as an HDF5 file: ${zu(u)}`,{uri:e,source:t.id})}const i=Xc(n);try{if(i!=="/"){const u=r.get(i);if(u===null)throw new T("entry-not-found",`Group '${i}' not found in ${t.id}. Top-level keys: ${Ke(r.keys())}`,{uri:e,group:i,available:r.keys()});if(!(u instanceof s.Group))throw new at(`'${i}' in ${t.id} is not an HDF5 group`,{uri:e,group:i},"entry-not-found")}}catch(u){throw r.close(),t.close(),u}let a=[],c="";try{for(const u of["entries","resolutions"]){if(r.get_type(`/${u}`)<0)continue;const l=r.get(u);if(l instanceof s.Group){a=Wc(l.keys()),c=u;break}}}catch{}return new vr(e,i,s,r,t,a,c)}class vr{uri;group;rootEntries;rootEntryGroup;h5;file;heap;source;closed=!1;borrowed;constructor(t,n,s,o,r,i=[],a="",c=!1){this.uri=t,this.group=n,this.rootEntries=i,this.rootEntryGroup=a,this.borrowed=c,this.h5=s,this.file=o,this.heap={h5:s,file:o},this.source=r}attrs(){return this.attrsAt("")}attrsAt(t){const n=this.entity(t),s=n instanceof this.h5.Group||n instanceof this.h5.Dataset;if(n===null||!s)throw new at(`${this.describe(t)} does not exist, or carries no attributes`,{uri:this.uri,path:this.resolve(t)});const o={};for(const[r,i]of Object.entries(n.attrs))o[r]=this.decodeAttr(n.path,r,i.metadata,i.json_value);return o}has(t){return this.assertOpen(),this.file.get_type(this.resolve(t))>=0}keys(t){const n=this.entity(t);return n===null||!(n instanceof this.h5.Group)?[]:n.keys()}isSoftLink(t){if(!this.has(t))return!1;const n=this.file.get_link(this.resolve(t));return typeof n=="string"&&n.length>0}datasetLength(t){const n=this.dataset(t).metadata.shape;return n&&n.length>0?n[0]:0}dtype(t){const n=this.dataset(t).dtype;if(typeof n!="string")throw new at(`${this.describe(t)} has a compound datatype, which this reader does not read`,{uri:this.uri,path:this.resolve(t)});return n}readNumeric(t,n,s){const[o,r,i]=this.numericRange(t,n,s);return Hc(o,r,i,this.heap)}readInt32(t,n,s){const[o,r,i]=this.numericRange(t,n,s);return Nu(o,r,i,this.heap)}numericRange(t,n,s){const o=this.dataset(t);if(jo(this.h5,o.metadata)!=="number")throw new at(`${this.describe(t)} is ${String(o.dtype)}, not a numeric dataset`,{uri:this.uri,path:this.resolve(t),dtype:String(o.dtype)});const[r,i]=this.range(o,n,s);return[o,r,i]}readStrings(t,n,s){const o=this.dataset(t),r=o.metadata;if(jo(this.h5,r)!=="string")throw new at(`${this.describe(t)} is ${String(o.dtype)}, not a string dataset`,{uri:this.uri,path:this.resolve(t),dtype:String(o.dtype)});const[i,a]=this.range(o,n,s);return Uc(this.h5,this.file,o,i,a)}readTable(t,n,s,o){const r=this.entity(t);if(r===null||!(r instanceof this.h5.Group))throw new at(`${this.describe(t)} is not a table group`,{uri:this.uri,path:this.resolve(t)});const i=this.resolve(t).slice(this.group==="/"?1:this.group.length+1);return Mu(this.h5,this.file,r,i,n,s,o)}at(t){const n=this.resolve(t);return new vr(this.uri,n,this.h5,this.file,this.source,this.rootEntries,this.rootEntryGroup,!0)}close(){if(!(this.closed||this.borrowed)){this.closed=!0;try{this.file.close()}finally{this.source.close()}}}resolve(t){const n=t.replace(/^\/+/,"");return n===""?this.group:Xc(this.group==="/"?`/${n}`:`${this.group}/${n}`)}describe(t){return`${this.uri} :: ${this.resolve(t)}`}entity(t){this.assertOpen();const n=this.resolve(t);return n==="/"?this.file:this.file.get(n)}dataset(t){const n=this.entity(t);if(n===null)throw new at(`${this.describe(t)} does not exist`,{uri:this.uri,path:this.resolve(t)});if(!(n instanceof this.h5.Dataset))throw new at(`${this.describe(t)} is not a dataset`,{uri:this.uri,path:this.resolve(t)});return n}range(t,n,s){const o=t.metadata.shape;if(!o||o.length!==1)throw new at(`/${t.path.replace(/^\//,"")} is ${o?`${o.length}-D`:"scalar"}; this reader only slices 1-D columns`,{path:t.path,shape:o});const r=o[0],i=Math.min(Math.max(Math.trunc(n??0),0),r),a=Math.min(Math.max(Math.trunc(s??r),i),r);return[i,a]}decodeAttr(t,n,s,o){if(s.type===this.h5.Module.H5T_class_t.H5T_STRING.value&&!s.vlen){const r=this.readFixedStringAttr(t,n,s);if(r!==null)return r}return qu(o)}readFixedStringAttr(t,n,s){const o=s.total_size,r=s.size*o;if(r<=0)return null;const i=this.h5.Module,a=i._malloc(r);if(a===0)return null;let c;try{i.get_attribute_data(this.file.file_id,t,n,BigInt(a)),c=i.HEAPU8.slice(a,a+r)}finally{i._free(a)}const u=[];for(let h=0;h<o;h++){let f=c.subarray(h*s.size,(h+1)*s.size);const d=f.indexOf(0);d>-1&&(f=f.subarray(0,d)),u.push(Ru.decode(f))}const l=s.shape;return l&&l.length>0?u:u[0]??""}assertOpen(){if(this.closed)throw new at(`${this.uri} is closed`,{uri:this.uri})}}function zu(e){return e instanceof Error?e.message:String(e)}function Xc(e){const t=`/${e}`.replace(/\/+/g,"/").replace(/(.)\/$/,"$1");return t===""?"/":t}function qu(e){if(e==null)return null;if(typeof e=="bigint")return Number(e);if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e)){if(e.every(n=>typeof n=="string"))return e;const t=n=>typeof n=="number"||typeof n=="boolean"||typeof n=="bigint";return e.every(t)?e.map(n=>Number(n)):e.map(n=>String(n))}return null}const qe=4096,ks={binsPerCell:1,contigsPerCell:1};function Jc(e,t,n,s=ks,o){const r=Math.max(0,Math.trunc(e));if(r===0)return{slot:new Int32Array(0),cellStart:new Int32Array(1),cellSegments:new Int32Array(0),cells:0,plan:ks};const i=t.length>0?t.length:1,a=Math.max(1,Math.trunc(n)),c=h=>t.length>0?t[h]:0,u=h=>(h+1<i?c(h+1):r)-c(h),l=Math.max(s.binsPerCell,Zc(i,u,a,o));return Gu(r,i,c,u,l,o)}function Uu(e,t,n,s){let o=0,r=0,i=-1;for(let a=0;a<e;a++){const c=t(a);if(c>=n){o+=Math.ceil(c/n),r=0,i=-1;continue}const u=s===void 0?0:s[a];r===0||r+c>n||u!==i?(o++,r=c,i=u):r+=c}return o}function Zc(e,t,n,s){let o=s;const r=c=>Uu(e,t,c,o)<=n;let i=1;for(;!r(i);)if(i>=Number.MAX_SAFE_INTEGER/2){if(o===void 0)return i;o=void 0,i=1}else i*=2;let a=1;for(;a<i;){const c=a+i>>1;r(c)?i=c:a=c+1}return a}function Gu(e,t,n,s,o,r){const i=new Int32Array(e),a=[],c=[];let u=0,l=0,h=-1;for(let d=0;d<t;d++){const m=n(d),g=s(d),p=m+g;if(g>=o){l=0,h=-1;for(let b=m;b<p;b++)(b-m)%o===0&&(a.push(b),c.push(1),u++),i[b]=u-1;continue}const w=r===void 0?0:r[d];l===0||l+g>o||w!==h?(a.push(m),c.push(1),u++,l=g,h=w):(l+=g,c[u-1]++);for(let b=m;b<p;b++)i[b]=u-1}a.push(e);let f=1;for(const d of c)f=Math.max(f,d);return{slot:i,cellStart:Int32Array.from(a),cellSegments:Int32Array.from(c),cells:u,plan:{binsPerCell:o,contigsPerCell:f}}}function Hu(e){const t=[];for(let n=0;n<e.length;n++)(n===0||e[n]!==e[n-1])&&t.push(n);return Int32Array.from(t)}function bi(e,t,n,s=ks,o=qe,r){const i=Math.max(0,n-t);if(i===0)return{slot:new Int32Array(0),ids:new Int32Array(0),stride:1,contigsPerCell:1,cellStart:new Int32Array(1),members:new Int32Array(0),memberStart:new Int32Array(1)};const a=e.contigsOfBins(t,n),c=Hu(a),u=r===void 0||r.length===0?void 0:Int32Array.from(c,m=>r[a[m]]??-1),l=Jc(i,c,o,s,u),h=new Int32Array(l.cells),f=[],d=new Int32Array(l.cells+1);for(let m=0;m<l.cells;m++){d[m]=f.length;const g=l.cellStart[m],p=l.cellStart[m+1];h[m]=a[g];for(let w=g;w<p;w++)(w===g||a[w]!==a[w-1])&&f.push(a[w])}return d[l.cells]=f.length,{slot:l.slot,ids:h,stride:l.plan.binsPerCell,contigsPerCell:l.plan.contigsPerCell,cellStart:l.cellStart,members:Int32Array.from(f),memberStart:d}}function Qu(e,t,n,s=qe,o){const r=t.map(({extent:y})=>Math.max(0,y[1]-y[0])),i=r.reduce((y,A)=>y+A,0),a=o===void 0?void 0:Int32Array.from(t,({id:y})=>o[y]??-1),c=Math.max(n.binsPerCell,Zc(r.length,y=>r[y],Math.max(1,Math.trunc(s)),a)),u=new Int32Array(e).fill(-1),l=[],h=[],f=[],d=[];let m=0,g=0,p=-1,w=1,b=0;for(let y=0;y<t.length;y++){const{id:A,extent:N}=t[y],[I,M]=N,x=r[y];if(x===0)continue;const v=a===void 0?0:a[y],S=x>=c;for(let k=I;k<M;k++){const C=k-I;(S?C%c===0:C===0&&(g===0||g+x>c||v!==p))?(l.push(A),h.push(m),d.push(f.length),f.push(A),g=0,p=v,b=0):C===0&&f.push(A),u[k]=l.length-1,m++}S?(g=0,p=-1,b=0):(g+=x,b++,w=Math.max(w,b))}return h.push(m),d.push(f.length),{slot:u,ids:Int32Array.from(l),stride:c,contigsPerCell:w,cellStart:Int32Array.from(h),members:Int32Array.from(f),memberStart:Int32Array.from(d),bins:i}}function jc(e){const t=new Int32Array(e.length),n=new Map,s=[];for(let o=0;o<e.length;o++){const r=e[o];let i=n.get(r);i===void 0&&(i=s.length,n.set(r,i),s.push(r)),t[o]=i}return{slot:t,ids:Int32Array.from(s)}}function Ku(e,t,n,s,o=!1){const r=t.ids.length,i=n.ids.length,a=new Float64Array(r*i),c=o&&e.nrows===e.ncols;for(let u=0;u<e.nrows;u++){const l=t.slot[u],h=u*e.ncols;for(let f=c?u:0;f<e.ncols;f++){const d=n.slot[f],m=c&&l>d?d*i+l:l*i+d,g=e.values[h+f];Number.isNaN(g)||(a[m]+=g)}}if(c)for(let u=0;u<r;u++)for(let l=u+1;l<i;l++)a[l*i+u]=a[u*i+l];return{nrows:r,ncols:i,values:a,rowIds:t.ids,colIds:n.ids,level:s}}function tl(e,t,n){return jc(e.contigsOfBins(t,n))}function el(e,t,n,s){const o=e.contigsOfBins(n,s),r=new Int32Array(o.length);for(let i=0;i<o.length;i++)r[i]=t[o[i]];return jc(r)}function Ai(e,t,n){const s=e.ids.length;if(s<=t)return{grouping:e,perCell:1};const o=Int32Array.from({length:s},(u,l)=>l),r=n===void 0?void 0:Int32Array.from(e.ids,n),i=Jc(s,o,t,ks,r),a=new Int32Array(e.slot.length);for(let u=0;u<a.length;u++){const l=e.slot[u];a[u]=l<0?-1:i.slot[l]}const c=new Int32Array(i.cells);for(let u=0;u<i.cells;u++)c[u]=e.ids[i.cellStart[u]];return{grouping:{slot:a,ids:c},perCell:i.plan.contigsPerCell}}function Wu(e,t,n,s,o,r,i=!0,a=Number.POSITIVE_INFINITY){const c=m=>o==="contig"?tl(n,m[0],m[1]):el(n,s,m[0],m[1]),u=e[0]===t[0]&&e[1]===t[1],l=o==="contig"&&s.length>0?m=>s[m]??-1:void 0,h=Ai(c(e),a,l),f=u?h:Ai(c(t),a,l),d=tr(e,t,h.grouping,f.grouping,r,i);return{place:d.place,finish:()=>({...d.finish(),level:o}),perCell:Math.max(h.perCell,f.perCell)}}function tr(e,t,n,s,o,r=!0,i=!1){const c=e[0]===t[0]&&e[1]===t[1]&&r,u=n.ids.length,l=s.ids.length,h=i&&c&&u===l,f=new Float64Array(h?u*(u+1)/2:u*l),[d,m]=e,[g,p]=t,w=o!=="transpose",b=o!=="direct"&&!c,y=o==="symmetric",A=(N,I,M)=>{const x=n.slot[N],v=s.slot[I];if(!(x<0||v<0)){if(h){const S=x<v?x:v,k=x<v?v:x;f[S*u-S*(S-1)/2+(k-S)]+=M;return}f[c&&x>v?v*l+x:x*l+v]+=M}};return{place(N,I,M){Number.isNaN(M)||(w&&N>=d&&N<m&&I>=g&&I<p&&A(N-d,I-g,M),b&&!(y&&N===I)&&I>=d&&I<m&&N>=g&&N<p&&A(I-d,N-g,M))},finish(){if(h){const N=new Float32Array(u*u);let I=0;for(let M=0;M<u;M++)for(let x=M;x<u;x++,I++){const v=f[I];N[M*u+x]=v,N[x*u+M]=v}return{nrows:u,ncols:l,values:N,rowIds:n.ids,colIds:s.ids}}if(c)for(let N=0;N<u;N++)for(let I=N+1;I<l;I++)f[I*l+N]=f[N*l+I];return{nrows:u,ncols:l,values:f,rowIds:n.ids,colIds:s.ids}}}}function Yu(e,t,n,s,o=!0){const r=u=>s==="contig"?tl(t,u[0],u[1]):el(t,n,u[0],u[1]),i=e.rowExtent[0]===e.colExtent[0]&&e.rowExtent[1]===e.colExtent[1],a=r(e.rowExtent),c=i?a:r(e.colExtent);return Ku(e,a,c,s,i&&o)}function Vu(e,t){let n=0,s=e.length-1;for(;n<s;){const o=n+s+1>>1;e[o]<=t?n=o:s=o-1}return n}class Xu{binsize;chromOffset;contigLengths;constructor(t,n,s){this.binsize=t,this.chromOffset=n,this.contigLengths=s}get nContigs(){return this.contigLengths.length}get nBins(){return this.chromOffset.length>0?this.chromOffset[this.chromOffset.length-1]:0}binsInContig(t){return Math.ceil(this.contigLengths[t]/this.binsize)}contigStartBin(t){return this.chromOffset[t]}contigBinExtent(t){return[this.chromOffset[t],this.chromOffset[t+1]]}binIndex(t,n){return this.chromOffset[t]+Math.floor(n/this.binsize)}contigOfBin(t){return Vu(this.chromOffset,t)}binStart(t){const n=this.contigOfBin(t);return(t-this.chromOffset[n])*this.binsize}binEnd(t){const n=this.contigOfBin(t),s=(t-this.chromOffset[n])*this.binsize;return Math.min(s+this.binsize,this.contigLengths[n])}contigsOfBins(t,n){const s=new Int32Array(Math.max(0,n-t));if(s.length===0)return s;let o=this.contigOfBin(t),r=this.chromOffset[o+1];for(let i=t;i<n;i++){for(;i>=r&&o+1<this.nContigs;)o+=1,r=this.chromOffset[o+1];s[i-t]=o}return s}}const hn=256,Ju=["#FFFEF9","#FCF9CE","#FFF2A9","#FDE188","#FFCA67","#FAAA4B","#F78E40","#F15C34","#ED3024","#D42027","#B01F29","#7A1128","#1A0A10"],Zu=["#FFFFFF","#FFF5F0","#FEE0D2","#FCBBA1","#FC9272","#FB6A4A","#EF3B2C","#CB181D","#A50F15","#67000D"],ju=["#053061","#2166AC","#4393C3","#92C5DE","#D1E5F0","#F7F7F7","#FDDBC7","#F4A582","#D6604D","#B2182B","#67001F"],t2=["#1659b1","#487BA8","#819EC8","#D1E6F1","#FFFFFF","#FAC1C1","#F1606C","#EE222A"],e2=[0,.125,.25,.375,.5,2/3,5/6,1],n2=["#00004D","#0000FF","#FFFFFF","#FF0000","#800000"];function fn(e,t,n){const s=e.map(a=>[Number.parseInt(a.slice(1,3),16),Number.parseInt(a.slice(3,5),16),Number.parseInt(a.slice(5,7),16)]),o=s.length-1,r=n??s.map((a,c)=>c/o),i=new Array(t*3);for(let a=0;a<t;a++){const c=a/(t-1);let u=0;for(;u<o-1&&c>=r[u+1];)u++;const l=r[u+1]-r[u],h=l>0?(c-r[u])/l:0;for(let f=0;f<3;f++)i[a*3+f]=Math.round(s[u][f]+(s[u+1][f]-s[u][f])*h)}return i}fn(Ju,hn),fn(Zu,hn),fn(ju,hn),fn(t2,hn,e2),fn(n2,hn);const nl="RdBu_r",s2=16384;function yi(e,t=s2){return e<=t?1:Math.ceil(e/t)}const re="weight",j="count",o2=new Set(["bin1_id","bin2_id"]);function r2(e){const t=e.keys("pixels").filter(n=>!o2.has(n));return[...t.filter(n=>n===j),...t.filter(n=>n!==j).sort()]}const po={range:"Use a narrower --range/--range2.",binSelection:"Use --range to select a smaller region, or --level contig."};function i2(e,t,n){if(e*t>li**2){const s=e*t*8/1e9;throw new T("dense-too-large",`Refusing to allocate a ${e}×${t} dense matrix (${s.toFixed(1)} GB). ${n}`,{nRows:e,nCols:t,limit:li})}}function a2(e,t){const n=e*t,s=Math.ceil(e/yi(e))*Math.ceil(t/yi(t));return n*4+s*12+u2}function sl(){const e=globalThis.navigator?.deviceMemory;return c2(typeof e=="number"&&e>0?e:U1)}function c2(e){const t=e*1073741824*q1;return e>=H1?Math.max(G1,t):t}function l2(e,t,n,s={}){const o=e*t;if(o*4>=Un){const a=Math.floor(Math.sqrt(Un/4));throw new T("dense-too-large",`Refusing to load a ${e}×${t} block: its ${er(o)} values are ${Mt.bytes(o*4)} and a browser serves at most ${Mt.bytes(Un)} in a single array — a limit of the tab, not of this machine, so more memory and more patience will not lift it. The largest square block is about ${a}×${a} bins.`+(n===""?"":` ${n}`),{nRows:e,nCols:t,cells:o,bytes:o*4,limit:Un,where:"array-limit"})}const r=s.budgetBytes??sl(),i=a2(e,t);if(!(i<=r))throw new T("dense-too-large",`Refusing to load a ${e}×${t} block in a browser tab: ${er(o)} cells needs about ${Mt.bytes(i)}, and this tab is budgeting ${Mt.bytes(r)}. ${n}`,{nRows:e,nCols:t,cells:o,bytes:i,budget:r,where:"browser"})}function er(e){return e>=1e9?`${(e/1e9).toFixed(1)} billion`:e>=1e6?`${(e/1e6).toFixed(0)} million`:String(e)}function Ni(e){const t=zc(e);if(t==="i"||t==="u"||t==="f")return t;throw new T("format",`/pixels/count is stored as ${e} (kind '${t}'); expected one of the kinds ['i', 'u', 'f']. A non-numeric count column cannot be rendered.`,{dtype:e,kind:t})}const Us=1e6,u2=Us*36;class kr{constructor(t,n){this.offsets=t,this.firstBin=n}row=0;bin1(t,n){const s=new Int32Array(Math.max(0,n-t)),o=this.offsets,r=o.length-2;if(r<0)return s;t<o[this.row]&&this.seek(t);let i=this.row;for(let a=t;a<n;){for(;i<r&&o[i+1]<=a;)i++;const c=i<r?Math.min(n,o[i+1]):n,u=c>a?c:n;s.fill(this.firstBin+i,a-t,u-t),a=u}return this.row=i,s}seek(t){const n=this.offsets;let s=0,o=Math.max(0,n.length-2);for(;s<o;){const r=s+o+1>>1;n[r]<=t?s=r:o=r-1}this.row=s}}function h2(e,t,n){if(n<=t)return null;const s=e.readNumeric("indexes/bin1_offset",t,n+1),o=s[0],r=s[s.length-1];return r<=o?null:{p0:o,p1:r,rows:new kr(s,t)}}function Sr(e,t,n,s=j,o=null){const r=e.readInt32("pixels/bin2_id",t,n),i=e.readNumeric(`pixels/${s}`,t,n);return{bin1:o===null?e.readInt32("pixels/bin1_id",t,n):o.bin1(t,t+i.length),bin2:r,count:i,length:i.length}}async function f2(e,t,n,s,o={}){const r=h2(e,t,n);if(r===null)return!0;const{p0:i,p1:a,rows:c}=r,u=Math.max(1,Math.trunc(o.chunkSize??Us)),l=a-i,h=o.value??j;for(let f=i;f<a;f+=u){if(o.cancelled?.()===!0)return!1;const d=Math.min(f+u,a);s(Sr(e,f,d,h,c)),o.onProgress?.(d-i,l),await xt()}return!0}const ol=65536;async function d2(e,t,n,s={},o=null){const r=Math.max(1,Math.trunc(s.chunkSize??Us)),i=t.reduce((l,[h,f])=>l+Math.max(0,f-h),0),a=s.value??j,c=o===null?null:new kr(o,0);let u=0;for(const[l,h]of t){c?.seek(l);for(let f=l;f<h;f+=r){if(s.cancelled?.()===!0)return!1;const d=Math.min(f+r,h);n(Sr(e,f,d,a,c)),u+=d-f,s.onProgress?.(u,i),await xt()}}return!0}function Ye(e,t,n){return n!=="symmetric-upper"?{span:e,mode:"direct"}:t[1]<=e[0]?{span:t,mode:"transpose"}:e[1]<=t[0]?{span:e,mode:"direct"}:{span:[Math.min(e[0],t[0]),Math.min(e[1],t[1])],mode:"symmetric"}}function m2(e,t,n,s,o){const[r,i]=t,[a,c]=n,u=c-a,{bin1:l,bin2:h,count:f,length:d}=e,m=s.mode!=="transpose",g=s.mode!=="direct",p=s.mode==="symmetric";for(let w=0;w<d;w++){const b=l[w],y=h[w],A=f[w];m&&b>=r&&b<i&&y>=a&&y<c&&(o[(b-r)*u+(y-a)]+=A),g&&!(p&&b===y)&&y>=r&&y<i&&b>=a&&b<c&&(o[(y-r)*u+(b-a)]+=A)}}async function g2(e,t,n){const s=Mi(t.rows,e.nBins,"rows"),o=Mi(t.cols??t.rows,e.nBins,"cols"),r=s[1]-s[0],i=o[1]-o[0];i2(r,i,n),l2(r,i,n,{...t.budgetBytes===void 0?{}:{budgetBytes:t.budgetBytes}});const a=p2(r,i,n);if(r>0&&i>0){const c=Ye(s,o,e.storageMode);await e.store.forEachWindow(s,o,c,u=>{m2(u,s,o,c,a)},{chunkSize:Us,value:t.value??j}),t.balance===!0&&w2(e.handle,s,o,a)}return{nrows:r,ncols:i,values:a,rowExtent:s,colExtent:o}}function p2(e,t,n){try{return new Float32Array(e*t)}catch(s){const o=e*t;throw new T("dense-too-large",`This machine could not allocate the ${e}×${t} block: ${er(o)} cells is ${Mt.bytes(o*4)} in one array, and the request was refused. ${n}`,{nRows:e,nCols:t,cells:o,bytes:o*4,where:"allocation",cause:String(s)})}}function w2(e,t,n,s){const o=re,r=`bins/${o}`;if(!e.has(r))throw new T("unsupported",`This file has no /bins/${o} column, so there are no weights to balance with. Run \`cooler balance\` on it, or view the raw counts.`,{column:o});const i=e.readNumeric(r,t[0],t[1]),a=n[0]===t[0]&&n[1]===t[1]?i:e.readNumeric(r,n[0],n[1]),c=n[1]-n[0];for(let u=0;u<t[1]-t[0];u++){const l=i[u],h=u*c;for(let f=0;f<c;f++)s[h+f]=s[h+f]*l*a[f]}}function Mi(e,t,n){const[s,o]=e;if(!Number.isInteger(s)||!Number.isInteger(o)||s<0||o<s||o>t)throw new T("bad-range",`Bin range for ${n} is [${s}, ${o}); it must be a half-open integer interval inside [0, ${t}).`,{extent:e,nBins:t,which:n});return[s,o]}class rl{constructor(t,n,s){this.handle=t,this.nBins=n,this.countKind=s}offsets=null;get nnz(){return this.handle.datasetLength("pixels/bin1_id")}scoreColumns(){return r2(this.handle)}binOffsets(){return this.offsets??=this.handle.readNumeric("indexes/bin1_offset"),this.offsets}async forEachWindow(t,n,s,o,r={}){return f2(this.handle,s.span[0],s.span[1],o,r)}async forEachBands(t,n,s={}){return d2(this.handle,this.pixelBandsOf(t),n,s,this.binOffsets())}async scanAll(t){const n=t.chunkSize??1e6,s=this.nnz,o=t.storedRows===!0?null:new kr(this.binOffsets(),0);for(let r=0;r<s;r+=n){const i=Math.min(r+n,s),a=t.onChunk(Sr(this.handle,r,i,j,o));if(t.onProgress?.(i,s),a===!1)return;await(t.pause?.()??xt())}}pixelBandsOf(t){const n=this.binOffsets(),s=[];for(const[r,i]of t){if(i<=r)continue;const a=n[Math.max(0,r)],c=n[Math.min(this.nBins,i)];c>a&&s.push([a,c])}s.sort((r,i)=>r[0]-i[0]);const o=[];for(const r of s){const i=o[o.length-1];i!==void 0&&r[0]<=i[1]+ol?i[1]=Math.max(i[1],r[1]):o.push([r[0],r[1]])}return o}}const b2=64*1024*1024,A2=256;function xe(e,t,n){return e*n-e*(e-1)/2+(t-e)}function Ss(e){return e*(e+1)/2}function il(e,t){if(!(e>0))return 0;const n=(Math.log10(e)-t.low)*(254/(t.high-t.low)),s=1+Math.round(n);return s<1?1:s>255?255:s}function y2(e,t){return e===0?Number.NEGATIVE_INFINITY:t.low+(e-1)*(t.high-t.low)/254}function N2(e){const t=new Float64Array(256);for(let n=1;n<256;n++)t[n]=10**y2(n,e);return t}function M2(e){const s=new Uint32Array(4e3);let o=0,r=Number.NEGATIVE_INFINITY;for(let h=0;h<e.length;h++){const f=e[h];if(!(f>0))continue;const d=Math.log10(f);d>r&&(r=d);const m=Math.floor((d- -20)*100);s[m<0?0:m>=4e3?3999:m]++,o++}if(o<1e3)return null;const i=o*.001;let a=0,c=-20;for(let h=0;h<4e3;h++)if(a+=s[h],a>=i){c=-20+h/100;break}const u=c-1,l=Math.max(r+.5,u+1);return{low:u,high:l}}const Ii={low:-12,high:8},I2=4e6;function x2(e,t){const n=i=>{let a=0;for(let c=0;c+1<e.length;c++)a+=Math.ceil((e[c+1]-e[c])/i);return a};let s=1;for(let i=0;i+1<e.length;i++)s=Math.max(s,e[i+1]-e[i]);if(n(1)<=t)return 1;if(n(s)>t)return s;let o=1,r=s;for(;o+1<r;){const i=o+r>>1;n(i)<=t?r=i:o=i}return r}async function v2(e){const{store:t,layout:n,weights:s}=e,o=n.n,r=n.slot,i=r.length,a=new Uint8Array(Ss(o)),c=new Float64Array(256),u=e.gather===void 0?null:k2(n,s,e.gather),l=new Int32Array(o).fill(-1),h=new Int32Array(o);for(let N=0;N<i;N++){const I=r[N];I<0||(l[I]<0&&(l[I]=N),h[I]=N+1)}const f=(N,I)=>{const M=[];for(let x=N;x<I;x++){if(l[x]<0)continue;const v=M[M.length-1];v!==void 0&&v[1]===l[x]?v[1]=h[x]:M.push([l[x],h[x]])}return M},d=Math.max(1,Math.floor((e.bandBytes??b2)/(4*Math.max(1,o)))),m=new Float32Array(Math.min(o,d)*o);let g=null;try{g=t.binOffsets()}catch{g=null}const p=N=>g===null?0:N.reduce((I,[M,x])=>I+(g[x]-g[M]),0),w=g!==null?p(f(0,o)):o;let b=0,y=null,A=0;for(let N=0;N<o;N+=d){if(e.cancelled?.()===!0)return null;const I=Math.min(o,N+d),M=f(N,I),x=(I-N)*o;m.fill(0,0,x);const v=b;if(!await t.forEachBands(M,k=>{for(let C=0;C<k.length;C++){const B=k.bin1[C],F=k.bin2[C];if(F<B)continue;const E=r[B],_=r[F];if(E<0||_<0)continue;let $=k.count[C];s!==null&&($*=s[B]*s[F]),$>0&&(m[(E-N)*o+_]+=E===_&&B!==F?2*$:$)}A+=k.length},{...e.cancelled===void 0?{}:{cancelled:e.cancelled},...e.value===void 0?{}:{value:e.value},onProgress:k=>{g!==null&&e.onProgress?.(v+k,w)}}))return null;y??=M2(m.subarray(0,x))??Ii;for(let k=N;k<I;k++){const C=(k-N)*o;let B=xe(k,k,o);for(let F=k;F<o;F++,B++){const E=il(m[C+F],y);a[B]=E,c[E]++}u?.row(k,m,C)}b=g!==null?v+p(M):I,e.onProgress?.(b,w),await xt()}return{cells:a,quantizer:y??Ii,histogram:c,pixels:A,...u===null?{}:{contacts:u.finish()}}}function k2(e,t,n){const s=e.n,o=Math.max(1,Math.trunc(n.width)),r=new Uint16Array(s);for(let M=0;M<e.slot.length;M++)e.slot[M]>=0&&(t===null||t[M]>0)&&r[e.slot[M]]++;const i=new Int32Array(s);for(let M=0;M+1<e.offsets.length;M++)i.fill(M,e.offsets[M],e.offsets[M+1]);const a=x2(e.offsets,Math.max(1,n.coarseCells)),c=new Int32Array(s);let u=0;for(let M=0;M+1<e.offsets.length;M++){const x=e.offsets[M];for(let v=x;v<e.offsets[M+1];v++)c[v]=u+Math.floor((v-x)/a);u+=Math.ceil((e.offsets[M+1]-x)/a)}const l=new Float32Array(s*o).fill(Number.NaN),h=new Float64Array(Ss(u)),f=new Uint32Array(Ss(u)),d=new Float64Array(s),m=Math.max(0,Math.trunc(n.endDepth??0)),g=new Int32Array(s).fill(-1);if(m>0)for(let M=0;M+1<e.offsets.length;M++){const x=e.offsets[M],v=e.offsets[M+1],S=v-x;g.fill(2*M,x,x+Math.min(m,Math.ceil(S/2))),g.fill(2*M+1,v-Math.min(m,Math.floor(S/2)),v)}const p=Math.max(0,Math.trunc(n.endBudget??I2)),w=new Int32Array(m>0?s+1:0);let b=new Int32Array(m>0?1024:0),y=new Float32Array(b.length),A=0,N=!0;const I=(M,x)=>{if(A>=p){N=!1;return}if(A===b.length){const v=Math.min(p,b.length*2),S=new Int32Array(v),k=new Float32Array(v);S.set(b),k.set(y),b=S,y=k}b[A]=M,y[A]=x,A++};return{row(M,x,v){m>0&&(w[M]=A);const S=r[M];if(S===0)return;const k=i[M],C=c[M],B=xe(C,C,u)-C,F=g[M]>=0;for(let E=M;E<s;E++){const _=r[E];if(_===0)continue;const $=x[v+E]/(S*_);E-M<o&&i[E]===k?l[M*o+(E-M)]=$:F&&$>0&&g[E]>=0&&I(E,$);const L=B+c[E];h[L]+=$,f[L]++,d[M]+=$,E!==M&&(d[E]+=$)}},finish(){const M=new Float32Array(h.length);for(let x=0;x<h.length;x++)M[x]=f[x]===0?Number.NaN:h[x]/f[x];return{n:s,sequenceOf:i,width:o,band:l,coarse:{n:u,factor:a,of:c,values:M},marginal:d,kept:r,...m>0?{ends:{depth:m,zone:g,rowStart:S2(w,A),cols:b.slice(0,A),values:y.slice(0,A),complete:N}}:{}}}}}function S2(e,t){return e[e.length-1]=t,e}function C2(e,t,n=A2){const s=N2(t),o=[e];let r=e;for(;r.n>n;){const i=r.n,a=r.cells,c=Math.ceil(i/2),u=new Uint8Array(Ss(c));let l=0;for(let h=0;h<c;h++){const f=2*h,d=f+1;for(let m=h;m<c;m++,l++){const g=2*m,p=g+1;let w=s[a[xe(f,g,i)]],b=1;p<i&&(w+=s[a[xe(f,p,i)]],b++),d<i&&(w+=s[a[d<=g?xe(d,g,i):xe(g,d,i)]],b++,p<i&&(w+=s[a[xe(d,p,i)]],b++)),u[l]=il(w/b,t)}}r={n:c,cells:u},o.push(r)}return o}function ft(e){return e.gap!==void 0}const F2=["debris","contaminant","haplotig","unplaced"];function Gs(e){const t=new Map(e.names.map((n,s)=>[n,e.lengths[s]]));for(const n of e.elsewhere??[])t.has(n.name)||t.set(n.name,n.length);return t}function oe(e,t){for(let n=1;;n++){const s=`${e}_e${n}`;if(!t.has(s))return s}}function Hs(e){return ft(e)?e.gap:e.end-e.start}function Pe(e){let t=0;for(const n of e)t+=Hs(n);return t}function ie(e,t,n){return e<t?t:e>n?n:e}function $2(e,t,n){return ft(e)?[{gap:t},{gap:e.gap-t}]:e.strand===1?[{...e,id:n.next(e.id),end:e.start+t},{...e,id:n.next(e.id),start:e.start+t}]:[{...e,id:n.next(e.id),start:e.end-t},{...e,id:n.next(e.id),end:e.end-t}]}function Ue(e,t,n){const s=[],o=[];let r=0;for(const i of e){const a=Hs(i);if(r+a<=t)s.push(i);else if(r>=t)o.push(i);else{const[c,u]=$2(i,t-r,n);s.push(c),o.push(u)}r+=a}return[s,o]}function Hn(e,t,n,s){const[o,r]=Ue(e,t,s),[i,a]=Ue(r,n-t,s);return[o,i,a]}function dn(e){const t=[];for(let n=e.length-1;n>=0;n--){const s=e[n];t.push(ft(s)?{gap:s.gap}:{...s,strand:s.strand===1?-1:1})}return t}function _t(e){const t=[];for(const n of e){if(Hs(n)===0)continue;const s=t[t.length-1];if(s!==void 0&&ft(s)&&ft(n)){t[t.length-1]={gap:s.gap+n.gap};continue}if(s!==void 0&&!ft(s)&&!ft(n)&&s.sequence===n.sequence&&s.strand===n.strand){if(n.strand===1&&s.end===n.start){t[t.length-1]={...s,end:n.end};continue}if(n.strand===-1&&s.start===n.end){t[t.length-1]={...s,start:n.start};continue}}t.push(n)}return t}class E2{counter=0;next(t){return this.counter+=1,`${t.split("~")[0]}~${this.counter}`}}function B2(e){return{sequences:e.names.map((t,n)=>({name:t,parts:[{id:t,sequence:t,start:0,end:e.lengths[n],strand:1}]})),aside:[]}}function Lt(e,t){return e.sequences.find(n=>n.name===t)??null}function Qn(e,t,n){const s=Pe(e.parts),o=ie(Math.round(t),0,s),r=ie(Math.round(n),0,s);return o<=r?[o,r]:[r,o]}function T2(e,t,n,s){const o=e.sequences.map(c=>({...c,parts:[...c.parts]})),r={sequences:o,aside:[...e.aside]},i=new Set(o.map(c=>c.name)),a=new Set(Gs(n).keys());switch(t.op){case"cut":{const c=Lt(r,t.sequence);if(c===null)return e;const u=ie(Math.round(t.at),0,Pe(c.parts)),[l,h]=Ue(c.parts,u,s);return c.parts=[...l,...h],r}case"invert":{const c=Lt(r,t.sequence);if(c===null)return e;const[u,l]=Qn(c,t.from,t.to);if(l===u)return e;const[h,f,d]=Hn(c.parts,u,l,s);return c.parts=_t([...h,...dn(f),...d]),r}case"move":case"duplicate":{const c=Lt(r,t.sequence),u=Lt(r,t.into);if(c===null||u===null)return e;const[l,h]=Qn(c,t.from,t.to);if(h===l)return e;const[f,d,m]=Hn(c.parts,l,h,s),g=t.strand===1?d:dn(d);t.op==="move"?c.parts=_t([...f,...m]):g.forEach((y,A)=>{ft(y)||(g[A]={...y,id:s.next(y.id)})});const p=ie(Math.round(t.at),0,Pe(u.parts)),[w,b]=Ue(u.parts,p,s);return u.parts=_t([...w,...g,...b]),c!==u&&c.parts.length===0&&(r.sequences=r.sequences.filter(y=>y!==c)),r}case"join":{const c=Lt(r,t.a),u=Lt(r,t.b);if(c===null||u===null||c===u)return e;const l=t.aEnd==="end"?c.parts:dn(c.parts),h=t.bEnd==="start"?u.parts:dn(u.parts),f=t.gap>0?[{gap:Math.round(t.gap)}]:[];return c.parts=_t([...l,...f,...h]),a.has(c.name)&&!Qs(c,n)&&(i.delete(c.name),c.name=oe(c.name,i)),t.place==="b"?(r.sequences=r.sequences.filter(d=>d!==c),r.sequences.splice(r.sequences.indexOf(u),1,c)):r.sequences=r.sequences.filter(d=>d!==u),r}case"split":{const c=Lt(r,t.sequence);if(c===null)return e;const u=ie(Math.round(t.at),0,Pe(c.parts));if(u===0||u===Pe(c.parts))return e;const[l,h]=Ue(c.parts,u,s);c.parts=_t(l);const f=bn(c.name);a.has(c.name)&&(i.delete(c.name),c.name=oe(f,i),i.add(c.name));const d=t.name!==void 0&&!i.has(t.name)?t.name:oe(f,i);i.add(d);const m=r.sequences.indexOf(c);return r.sequences.splice(m+1,0,{name:d,parts:_t(h)}),r}case"aside":{const c=Lt(r,t.sequence);if(c===null)return e;const[u,l]=Qn(c,t.from,t.to);if(l===u)return e;const[h,f,d]=Hn(c.parts,u,l,s),m=typeof t.genome=="string"&&t.genome!==""?t.genome:void 0;for(const g of f)ft(g)||r.aside.push({piece:g,why:t.why,...m===void 0?{}:{genome:m}});return c.parts=_t([...h,...d]),c.parts.length===0&&(r.sequences=r.sequences.filter(g=>g!==c)),r}case"restore":{const c=r.aside.findIndex(({piece:h})=>h.sequence===t.sequence&&h.start===t.start&&h.end===t.end);if(c<0)return e;const[u]=r.aside.splice(c,1),l=oe(bn(t.sequence),i);return r.sequences.push({name:l,parts:[{...u.piece,strand:1}]}),r}case"bring":{const c=n.elsewhere?.find(h=>h.name===t.sequence);if(c===void 0||!(c.length>0))return e;const u=h=>h.sequence===c.name;if(r.sequences.some(h=>h.parts.some(f=>!ft(f)&&u(f)))||r.aside.some(h=>u(h.piece)))return e;const l=i.has(c.name)?oe(c.name,i):c.name;return r.sequences.push({name:l,parts:[{id:s.next(c.name),sequence:c.name,start:0,end:c.length,strand:1}]}),r}case"rotate":{const c=Lt(r,t.sequence);if(c===null)return e;const u=ie(Math.round(t.at),0,Pe(c.parts)),[l,h]=Ue(c.parts,u,s);return c.parts=_t([...h,...l]),r}case"rename":{const c=Lt(r,t.sequence);return c===null||t.name===""||i.has(t.name)&&t.name!==c.name||a.has(t.name)&&al(c,n)!==t.name?e:(c.name=t.name,c.named=!0,r)}case"reorder":{const c=new Map(t.names.map((u,l)=>[u,l]));return r.sequences.sort((u,l)=>(c.get(u.name)??1/0)-(c.get(l.name)??1/0)),r}case"place":{const c=Lt(r,t.sequence);if(c===null)return e;const[u,l]=Qn(c,t.from,t.to);if(l===u)return e;const h=r.sequences,f=h.indexOf(c),d=t.before===null?h.length:h.findIndex(A=>A.name===t.before),[m,g,p]=Hn(c.parts,u,l,s),w=_t(t.strand===1?g:dn(g)),b=_t([...m,...p]);if(b.every(A=>ft(A))){c.parts=w,h.splice(f,1);const A=d<0?h.length:d>f?d-1:d;return h.splice(A,0,c),r}c.parts=b,a.has(c.name)&&(i.delete(c.name),c.name=oe(bn(c.name),i),i.add(c.name));const y=oe(bn(c.name),i);return i.add(y),h.splice(d<0?h.length:d,0,{name:y,parts:w}),r}case"layout":return O2(t,n,s)}}function O2(e,t,n){const s=Gs(t),o=new Map,r=(l,h,f)=>{const d=o.get(l)??[];d.push([h,f]),o.set(l,d)},i=(l,h,f)=>{const d=s.get(l);if(d===void 0)return null;const m=ie(Math.round(h),0,d),g=ie(Math.round(f),0,d);return g>m?[m,g]:null},a=new Set,c=[];for(const l of Array.isArray(e.sequences)?e.sequences:[]){if(l===null||typeof l!="object"||!Array.isArray(l.parts))continue;const h=[];for(const m of l.parts){if(m===null||typeof m!="object")continue;if("gap"in m){typeof m.gap=="number"&&m.gap>0&&h.push({gap:Math.round(m.gap)});continue}if(typeof m.sequence!="string"||typeof m.start!="number"||typeof m.end!="number"||m.strand!==1&&m.strand!==-1)continue;const g=i(m.sequence,m.start,m.end);g!==null&&(r(m.sequence,g[0],g[1]),h.push({id:n.next(m.sequence),sequence:m.sequence,start:g[0],end:g[1],strand:m.strand}))}for(;h.length>0&&ft(h[0]);)h.shift();for(;h.length>0&&ft(h[h.length-1]);)h.pop();if(h.length===0)continue;const f=typeof l.name=="string"?l.name:"",d=f!==""&&!a.has(f)?f:oe(f===""?"seq":f,a);a.add(d),c.push({name:d,parts:_t(h),...l.circular===!0?{circular:!0}:{}})}const u=[];for(const l of Array.isArray(e.aside)?e.aside:[]){if(l===null||typeof l!="object"||typeof l.sequence!="string"||!F2.includes(l.why))continue;const h=i(l.sequence,l.start,l.end);if(h===null)continue;r(l.sequence,h[0],h[1]);const f=typeof l.genome=="string"&&l.genome!==""?l.genome:void 0;u.push({piece:{id:n.next(l.sequence),sequence:l.sequence,start:h[0],end:h[1],strand:1},why:l.why,...f===void 0?{}:{genome:f}})}for(let l=0;l<t.names.length;l++){const h=t.names[l],f=(o.get(h)??[]).sort((m,g)=>m[0]-g[0]);let d=0;for(const[m,g]of f)m>d&&u.push({piece:{id:n.next(h),sequence:h,start:d,end:m,strand:1},why:"unplaced"}),d=Math.max(d,g);d<t.lengths[l]&&u.push({piece:{id:n.next(h),sequence:h,start:d,end:t.lengths[l],strand:1},why:"unplaced"})}return{sequences:c,aside:u}}function bn(e){return e.replace(/_e\d+$/,"")}function Qs(e,t){let n=0,s=null;for(const i of e.parts){if(ft(i)||i.strand!==1||i.start!==n||s!==null&&i.sequence!==s)return!1;s=i.sequence,n=i.end}if(s===null)return!1;const o=t.names.indexOf(s);if(o>=0)return n===t.lengths[o];const r=t.elsewhere?.find(i=>i.name===s);return r!==void 0&&n===r.length}function L2(e,t){const n=new Set(Gs(t).keys()),s=new Set(e.sequences.map(o=>o.name));for(const o of e.sequences)n.has(o.name)&&!Qs(o,t)&&(s.delete(o.name),o.name=oe(bn(o.name),s),s.add(o.name));for(const o of e.sequences){if(o.named===!0)continue;const r=al(o,t);r!==null&&o.name!==r&&!s.has(r)&&(s.delete(o.name),o.name=r,s.add(r))}return e}function al(e,t){if(!Qs(e,t))return null;const n=e.parts[0];return ft(n)?null:n.sequence}class Cr{original;sequences;aside;offsets=new Map;byOriginal=new Map;constructor(t,n){this.original=t,this.sequences=n.sequences,this.aside=n.aside;for(const s of n.sequences){const o=[];let r=0;for(const i of s.parts){if(o.push(r),!ft(i)){const a=this.byOriginal.get(i.sequence)??[];a.push({sequence:s.name,offset:r,piece:i}),this.byOriginal.set(i.sequence,a)}r+=Hs(i)}o.push(r),this.offsets.set(s.name,o)}for(const s of this.byOriginal.values())s.sort((o,r)=>o.piece.start-r.piece.start)}static of(t){const n=new E2;let s=B2(t.original);const o=ie(t.cursor,0,t.history.length);for(let r=0;r<o;r++)s=L2(T2(s,t.history[r].step,t.original,n),t.original);return new Cr(t.original,s)}get isIdentity(){return this.aside.length===0&&this.sequences.length===this.original.names.length&&this.sequences.every((t,n)=>t.name===this.original.names[n]&&Qs(t,this.original))}sequence(t){return this.sequences.find(n=>n.name===t)??null}lengthOf(t){const n=this.offsets.get(t);return n===void 0?null:n[n.length-1]}contigs(){return this.sequences.map(t=>({name:t.name,length:this.lengthOf(t.name)??0}))}toOriginal(t,n){const s=this.sequence(t),o=this.offsets.get(t);if(s===null||o===void 0)return null;const r=_2(o,n);if(r<0)return null;const i=s.parts[r];if(ft(i))return null;const a=n-o[r];return i.strand===1?{sequence:i.sequence,bp:i.start+a,strand:1}:{sequence:i.sequence,bp:i.end-1-a,strand:-1}}toEdited(t,n){const s=[];for(const o of this.landings(t)){const r=o.piece;n<r.start||n>=r.end||s.push(r.strand===1?{sequence:o.sequence,bp:o.offset+(n-r.start),strand:1}:{sequence:o.sequence,bp:o.offset+(r.end-1-n),strand:-1})}return s}landings(t){return this.byOriginal.get(t)??[]}piecesIn(t,n,s){const o=this.sequence(t),r=this.offsets.get(t);if(o===null||r===void 0)return[];const i=[];for(let a=0;a<o.parts.length;a++){const c=o.parts[a],u=r[a],l=r[a+1];if(ft(c)||l<=n||u>=s)continue;const h=Math.max(n,u)-u,f=Math.min(s,l)-u,d=c.strand===1?{...c,start:c.start+h,end:c.start+f}:{...c,start:c.end-f,end:c.end-h};i.push({offset:u+h,piece:d})}return i}junctions(){const t=[];for(const n of this.sequences){const s=this.offsets.get(n.name)??[];for(let o=1;o<n.parts.length;o++)t.push({sequence:n.name,at:s[o]})}return t}}function _2(e,t){if(t<0||t>=e[e.length-1])return-1;let n=0,s=e.length-2;for(;n<=s;){const o=n+s>>1;if(t<e[o])s=o-1;else if(t>=e[o+1])n=o+1;else return o}return-1}function D2(e,t,n){const s=e.original;if(s.genome!==void 0){const o=new Map(t.map((r,i)=>[r,n[i]]));for(const[r,i]of Gs(s)){const a=o.get(r);if(a===void 0)return`the edit names ${r}, which this file does not have`;if(a!==i)return`${r} is ${i} bp in the edit and ${a} bp here`}return null}if(s.names.length!==t.length)return`the edit was made on ${s.names.length} sequences and this file has ${t.length}`;for(let o=0;o<t.length;o++){if(s.names[o]!==t[o])return`sequence ${o+1} is ${s.names[o]} in the edit and ${t[o]} here`;if(s.lengths[o]!==n[o])return`${t[o]} is ${s.lengths[o]} bp in the edit and ${n[o]} bp here`}return null}const R2=64;class Fr{names;lengths;chromOffset;toOriginal;landingStart;landings;originalBins;constructor(t){this.names=t.names,this.lengths=t.lengths,this.chromOffset=t.chromOffset,this.toOriginal=t.toOriginal,this.originalBins=t.originalBins;const n=new Int32Array(t.originalBins+1);for(const r of t.toOriginal)r>=0&&n[r+1]++;for(let r=0;r<t.originalBins;r++)n[r+1]+=n[r];const s=n.slice(0,t.originalBins),o=new Int32Array(n[t.originalBins]);t.toOriginal.forEach((r,i)=>{r>=0&&(o[s[r]++]=i)}),this.landingStart=n,this.landings=o}get nBins(){return this.toOriginal.length}static of(t,n,s){const o=t.binsize,r=new Map(n.map((l,h)=>[l,h])),i=[],a=[],c=[],u=[0];for(const l of s.sequences){const h=s.lengthOf(l.name)??0,f=Math.ceil(h/o);let d=0;l.parts.forEach((m,g)=>{const p=ft(m)?m.gap:m.end-m.start,w=Math.min(f,Math.round(d/o));d+=p;const b=g===l.parts.length-1?f:Math.min(f,Math.round(d/o)),y=Math.max(0,b-w),A=ft(m)?void 0:r.get(m.sequence);if(ft(m)||A===void 0){for(let B=0;B<y;B++)i.push(-1);return}const[N,I]=t.contigBinExtent(A),M=I-N,x=t.contigLengths[A],v=B=>B>=x?M:Math.max(0,Math.min(M,Math.round(B/o)));let S=v(m.start),k=v(m.end);k<=S&&(S=Math.max(0,Math.min(M-1,Math.floor((m.start+m.end)/2/o))),k=S+1);const C=k-S;for(let B=0;B<y;B++){const F=Math.min(C-1,Math.floor((B+.5)*C/y));i.push(N+(m.strand===1?S+F:k-1-F))}}),a.push(l.name),c.push(h),u.push(i.length)}return new Fr({names:a,lengths:Float64Array.from(c),chromOffset:Float64Array.from(u),toOriginal:Int32Array.from(i),originalBins:t.nBins})}originalBands(t){const n=new Uint8Array(this.originalBins);for(const[s,o]of t)for(let r=Math.max(0,s);r<Math.min(this.nBins,o);r++){const i=this.toOriginal[r];i>=0&&(n[i]=1)}return this.bandsOf(n)}windowBands(t,n){const s=([r,i])=>{let a=-1;for(let c=Math.max(0,r);c<Math.min(this.nBins,i);c++)a=Math.max(a,this.toOriginal[c]);return a},o=new Uint8Array(this.originalBins);for(const[[r,i],a]of[[t,s(n)],[n,s(t)]])for(let c=Math.max(0,r);c<Math.min(this.nBins,i);c++){const u=this.toOriginal[c];u>=0&&u<=a&&(o[u]=1)}return this.bandsOf(o)}bandsOf(t){const n=[];let s=-1;for(let o=0;o<=this.originalBins;o++){const r=o<this.originalBins&&t[o]===1;r&&s<0&&(s=o),!r&&s>=0&&(n.push([s,o]),s=-1)}return n}originalRectangles(t,n,s){const o=new Uint8Array(this.originalBins);for(const[[u,l],h]of[[t,1],[n,2]])for(let f=Math.max(0,u);f<Math.min(this.nBins,l);f++){const d=this.toOriginal[f];d>=0&&(o[d]|=h)}const r=[];let i=-1,a=0;for(let u=0;u<=this.originalBins;u++){const l=u<this.originalBins?o[u]:0;l!==0?(i<0&&(i=u,a=0),a|=l):i>=0&&(r.push({extent:[i,u],bits:a}),i=-1)}const c=[];for(let u=0;u<r.length;u++)for(let l=u;l<r.length;l++){const h=r[u].bits,f=r[l].bits;if(h&1&&f&2||h&2&&f&1){if(c.length===s)return null;c.push([r[u].extent,r[l].extent])}}return c}translate(t,n,s,o){s.reset();const{landingStart:r,landings:i}=this,[[a,c],[u,l]]=o??[[0,this.originalBins],[0,this.originalBins]];for(let h=0;h<t.length;h++){const f=t.bin1[h],d=t.bin2[h];if(o!==void 0&&!(f>=a&&f<c&&d>=u&&d<l)&&!(f>=u&&f<l&&d>=a&&d<c))continue;const m=r[f],g=r[f+1];if(m===g)continue;const p=r[d],w=r[d+1];if(p===w)continue;const b=t.count[h];if(f===d&&n){for(let y=m;y<g;y++)for(let A=y;A<g;A++)s.push(i[y],i[A],b,n);continue}for(let y=m;y<g;y++)for(let A=p;A<w;A++)s.push(i[y],i[A],b,n)}return s.chunk()}gather(t,n=0,s=this.nBins){const o=new Float64Array(Math.max(0,s-n));for(let r=n;r<s;r++){const i=this.toOriginal[r];o[r-n]=i>=0&&i<t.length?t[i]:Number.NaN}return o}gatherText(t,n=0,s=this.nBins){const o=[];for(let r=n;r<s;r++){const i=this.toOriginal[r];o.push(i>=0&&i<t.length?t[i]:"")}return o}}class cl{bin1=new Int32Array(1024);bin2=new Int32Array(1024);count=new Float64Array(1024);length=0;reset(){this.length=0}push(t,n,s,o){this.length===this.bin1.length&&this.grow();const r=o&&t>n;this.bin1[this.length]=r?n:t,this.bin2[this.length]=r?t:n,this.count[this.length]=s,this.length++}chunk(){return{bin1:this.bin1,bin2:this.bin2,count:this.count,length:this.length}}grow(){const t=this.bin1.length*2,n=new Int32Array(t);n.set(this.bin1);const s=new Int32Array(t);s.set(this.bin2);const o=new Float64Array(t);o.set(this.count),this.bin1=n,this.bin2=s,this.count=o}}class P2{constructor(t,n,s){this.inner=t,this.lens=n,this.upper=s}buffer=new cl;get nnz(){return this.inner.nnz}get countKind(){return this.inner.countKind}scoreColumns(){return this.inner.scoreColumns()}binOffsets(){const t=this.inner.binOffsets(),n=new Float64Array(this.lens.nBins+1);for(let s=0;s<this.lens.nBins;s++){const o=this.lens.toOriginal[s];n[s+1]=n[s]+(o>=0?t[o+1]-t[o]:0)}return n}async forEachWindow(t,n,s,o,r){const i=this.inner.rectangular===!0?this.lens.originalRectangles(t,n,R2):null;if(i===null){const c=this.upper?this.lens.windowBands(t,n):this.lens.originalBands([t]);return c.length===0?!0:this.inner.forEachBands(c,u=>o(this.lens.translate(u,this.upper,this.buffer)),r)}const a=this.upper?"symmetric-upper":"square";for(const c of i){const[u,l]=c;if(!await this.inner.forEachWindow(u,l,Ye(u,l,a),f=>o(this.lens.translate(f,this.upper,this.buffer,c)),r))return!1}return!0}forEachBands(t,n,s){const o=this.lens.originalBands(t);return o.length===0?Promise.resolve(!0):this.inner.forEachBands(o,r=>n(this.lens.translate(r,this.upper,this.buffer)),s)}scanAll(t){return this.inner.scanAll({...t,onChunk:n=>t.onChunk(this.lens.translate(n,this.upper,this.buffer))})}}function z2(e,t,n,s){const o=new Map,r=new Map,i=c=>c.startsWith("bins/"),a=c=>c==="chroms"||c==="contigs";return new Proxy(e,{get(c,u){switch(u){case"attrs":return()=>s;case"datasetLength":return l=>i(l)?t.nBins:l.startsWith("chroms/")||l.startsWith("contigs/")?n.length:c.datasetLength(l);case"readNumeric":return(l,h,f)=>{if(!i(l))return c.readNumeric(l,h,f);let d=o.get(l);return d===void 0&&(d=c.readNumeric(l),o.set(l,d)),t.gather(d,h??0,f??t.nBins)};case"readStrings":return(l,h,f)=>{if(!i(l))return c.readStrings(l,h,f);let d=r.get(l);return d===void 0&&(d=c.readStrings(l),r.set(l,d)),t.gatherText(d,h??0,f??t.nBins)};case"readTable":return(l,h,f,d)=>a(l)?n:c.readTable(l,h,f,d);default:{const l=Reflect.get(c,u,c);return typeof l=="function"?l.bind(c):l}}}})}function q2(e){return en(e.names.length,["name","length"],{name:e.names,length:e.lengths})}function U2(e,t,n,s={}){const o=D2(e,t,Array.from(n));if(o!==null)return{refusal:`The edit was made on another assembly: ${o}.`};const r=Cr.of(e);return r.isIdentity&&s.always!==!0?null:{assembly:r}}class $r{constructor(t,n,s){this.factor=t,this.fineOffset=n,this.chromOffset=s}static of(t,n){const s=Float64Array.from(t),o=new Float64Array(s.length);for(let r=0;r+1<s.length;r++)o[r+1]=o[r]+Math.ceil((s[r+1]-s[r])/n);return new $r(n,s,o)}get nBins(){return this.chromOffset[this.chromOffset.length-1]??0}get fineBins(){return this.fineOffset[this.fineOffset.length-1]??0}coarseBin(t){if(t>=this.fineBins)return this.nBins;const n=xi(this.fineOffset,t);return this.chromOffset[n]+Math.floor((t-this.fineOffset[n])/this.factor)}fineBin(t){if(t>=this.nBins)return this.fineBins;const n=xi(this.chromOffset,t);return this.fineOffset[n]+(t-this.chromOffset[n])*this.factor}toFine(t){return[this.fineBin(t[0]),this.fineBin(t[1])]}toCoarse(t){const n=this.coarseBin(t[0]);return t[1]<=t[0]?[n,n]:[n,this.coarseBin(t[1]-1)+1]}coarseIndex(){const t=new Int32Array(this.fineBins);for(let n=0;n+1<this.fineOffset.length;n++){const s=this.chromOffset[n],o=this.fineOffset[n];for(let r=o;r<this.fineOffset[n+1];r++)t[r]=s+Math.floor((r-o)/this.factor)}return t}}function xi(e,t){let n=0,s=e.length-1;for(;n<s;){const o=n+s>>>1;e[o]<=t?n=o+1:s=o}return Math.max(0,n-1)}const G2="weight",H2=65536;class Q2{constructor(t,n,s){this.inner=t,this.grid=n,this.storageMode=s}index=null;get nnz(){return null}get countKind(){return this.inner.countKind}get rectangular(){return this.inner.rectangular}scoreColumns(){return this.inner.scoreColumns()}binOffsets(){const t=this.inner.binOffsets(),n=new Float64Array(this.grid.nBins+1);for(let s=0;s<=this.grid.nBins;s++)n[s]=t[this.grid.fineBin(s)]??0;return n}async forEachWindow(t,n,s,o,r){const i=this.grid.toFine(t),a=this.grid.toFine(n),c=Ye(i,a,this.storageMode),u=new wo(this.coarseIndex(),{rows:t,cols:n,mode:c.mode},o),l=await this.inner.forEachWindow(i,a,c,h=>u.add(h),r);return l&&u.finish(),l}forEachBands(t,n,s){const o=t.map(i=>this.grid.toFine(i)).filter(([i,a])=>a>i);if(o.length===0)return Promise.resolve(!0);const r=new wo(this.coarseIndex(),this.grid.nBins,n);return this.inner.forEachBands(o,i=>r.add(i),s).then(i=>(i&&r.finish(),i))}async scanAll(t){let n=!1;const s=new wo(this.coarseIndex(),this.grid.nBins,o=>{n||t.onChunk(o)===!1&&(n=!0)});await this.inner.scanAll({...t,onChunk:o=>(s.add(o),!n)}),n||s.finish()}coarseIndex(){return this.index??=this.grid.coarseIndex(),this.index}}class wo{constructor(t,n,s){this.coarseOf=t,this.reach=n,this.emit=s,typeof n=="number"?(this.colLo=0,this.colSpan=n,this.rowLo=0,this.sums=new Float64Array(n)):(this.colLo=n.cols[0],this.colSpan=n.cols[1]-n.cols[0],this.rowLo=n.rows[0],this.sums=new Float64Array(this.colSpan+(n.rows[1]-n.rows[0]))),this.stamp=new Int32Array(this.sums.length)}sums;stamp;touched=new Int32Array(256);nTouched=0;row=-1;generation=0;out=new cl;held=0;colLo;colSpan;rowLo;add(t){const{bin1:n,bin2:s,count:o,length:r}=t,i=this.coarseOf,a=typeof this.reach=="number"?null:this.reach;for(let c=0;c<r;c++){const u=i[n[c]],l=i[s[c]];if(u===void 0||l===void 0||a!==null&&!K2(a,u,l))continue;u!==this.row&&this.startRow(u);let h=l-this.colLo;if((h<0||h>=this.colSpan)&&(h=this.colSpan+(l-this.rowLo)),!(h<0||h>=this.sums.length))if(this.stamp[h]!==this.generation){if(this.stamp[h]=this.generation,this.sums[h]=o[c],this.nTouched===this.touched.length){const f=new Int32Array(this.touched.length*2);f.set(this.touched),this.touched=f}this.touched[this.nTouched++]=l}else this.sums[h]+=o[c]}this.held>0&&this.handOn()}finish(){this.closeRow(),this.row=-1,this.held>0&&this.handOn()}startRow(t){this.closeRow(),this.row=t,this.generation++}closeRow(){if(this.nTouched===0)return;const t=this.touched.subarray(0,this.nTouched).sort();for(const n of t){let s=n-this.colLo;(s<0||s>=this.colSpan)&&(s=this.colSpan+(n-this.rowLo)),this.out.push(this.row,n,this.sums[s],!1),this.held++}this.nTouched=0,this.held>=H2&&this.handOn()}handOn(){this.emit(this.out.chunk()),this.out.reset(),this.held=0}}function K2(e,t,n){const{rows:s,cols:o,mode:r}=e;return r!=="transpose"&&t>=s[0]&&t<s[1]&&n>=o[0]&&n<o[1]?!0:r!=="direct"&&n>=s[0]&&n<s[1]&&t>=o[0]&&t<o[1]}function W2(e,t,n){const s=new Map,o=new Map,r=c=>c.startsWith("bins/"),i=c=>{let u=s.get(c);return u===void 0&&(u=Y2(c.slice(5),e.readNumeric(c),t),s.set(c,u)),u},a=c=>{let u=o.get(c);if(u===void 0){const l=e.readStrings(c);u=[];for(let h=0;h<t.nBins;h++)u.push(l[t.fineBin(h)]??"");o.set(c,u)}return u};return new Proxy(e,{get(c,u){switch(u){case"attrs":return()=>n;case"datasetLength":return l=>r(l)?t.nBins:c.datasetLength(l);case"readNumeric":return(l,h,f)=>r(l)?i(l).slice(h??0,f??t.nBins):c.readNumeric(l,h,f);case"readStrings":return(l,h,f)=>r(l)?a(l).slice(h??0,f??t.nBins):c.readStrings(l,h,f);default:{const l=Reflect.get(c,u,c);return typeof l=="function"?l.bind(c):l}}}})}function Y2(e,t,n){const s=new Float64Array(n.nBins);for(let o=0;o<n.nBins;o++){const r=n.fineBin(o),i=n.fineBin(o+1);if(e==="chrom"||e==="start")s[o]=t[r];else if(e==="end")s[o]=t[i-1];else if(e===G2){let a=0,c=0;for(let u=r;u<i;u++){const l=t[u];Number.isFinite(l)&&l>0&&(a++,c+=1/l)}s[o]=a===0?Number.NaN:a/c}else{let a=0,c=0;for(let u=r;u<i;u++){const l=t[u];Number.isFinite(l)&&(a++,c+=l)}s[o]=a===0?Number.NaN:c/a}}return s}const V2="AGFzbQEAAAABCAFgBH9/f38AAg8BA2VudgZtZW1vcnkCAAIDAgEABAUBcAEBAQYIAX8BQYCIBAsHCQEFZmxveWQAAAq5CQG2CQQJfwJ8FH8EewJAIAIgA04NACABQQFIDQACQCABQQdLDQAgAkEDdCEEIAFBA3QhBSABQQJGIQYgAUEERiEHIAFBBUYhCCABQQZGIQkDQCAAIAIgAWxBA3RqIQogACELIAEhDANAAkAgCyAEaisDACINRAAAAAAAAPB/YQ0AAkAgDSAKKwMAoCIOIAsrAwBjRQ0AIAsgDjkDAAsgAUEBRg0AAkAgDSAKKwMIoCIOIAtBCGoiDysDAGNFDQAgDyAOOQMACyAGDQACQCANIAorAxCgIg4gC0EQaiIPKwMAY0UNACAPIA45AwALIAFBA0YNAAJAIA0gCisDGKAiDiALQRhqIg8rAwBjRQ0AIA8gDjkDAAsgBw0AAkAgDSAKKwMgoCIOIAtBIGoiDysDAGNFDQAgDyAOOQMACyAIDQACQCANIAorAyigIg4gC0EoaiIPKwMAY0UNACAPIA45AwALIAkNACANIAorAzCgIg0gC0EwaiIPKwMAY0UNACAPIA05AwALIAsgBWohCyAMQX9qIgwNAAsgBEEIaiEEIAJBAWoiAiADRw0ADAILCyABIAFBDyABQQ9KGyIEQfj///8HcSILQQFyIgwgASAMShsiDCALayIFIAxBAXEiEGshESALIBByIAxrIRIgACABIARBeGoiC0F4cUEJaiIMIAEgDEobQQN0IgwgC0EDdEFAcSILa2ohEyAAIAIgAWxBA3QiBCAMaiALa2ohFCAAQcAAaiEVIAFBA3QhFkEAIRcgBUEGSSEYIAAgBGoiGUHAAGoiGiEbA0AgFCAWIBdsIgtqIRwgGiALaiEdIAAgAiABbEEDdGohHiAAIR8gFSEgQQAhIQNAAkAgACAhIAFsQQN0aiIIIAJBA3RqKwMAIg5EAAAAAAAA8H9hDQAgFiAhbCEiIA79FCEjQQghBEEAIQUgGyEKICAhD0EAIQwDQCAeIAxBA3QiC2oiDP0AADAhJCAM/QAAICElIAz9AAAQISYgCCALaiILIAv9AAAAICMgDP0AAAD98AH99gH9CwAAIAsgC/0AABAgIyAm/fAB/fYB/QsAECALIAv9AAAgICMgJf3wAf32Af0LACAgCyAL/QAAMCAjICT98AH99gH9CwAwIAoiB0HAAGohCiAPIgZBwABqIQ8gBSIJQQFqIQUgBCILIQwgC0EIaiIEIAFMDQALIAsgAU4NAAJAIBgNAAJAIAAgCUEGdCIMaiAiakHAAGogHCAMak8NACAdIAxqIBMgDGogImpJDQELIAsgEWohCyASIQwDQAJAICMgB/0AAwD98AEiJCAG/QADAP1JIiX9GwBBAXFFDQAgBiAk/SEAOQMACwJAICX9GwJBAXFFDQAgBkEIaiAk/SEBOQMACyAHQRBqIQcgBkEQaiEGIAxBAmoiDA0ACyAQRQ0BCyAZIAtBA3QiDGohBCAfIAxqIQwDQAJAIA4gBCsDAKAiDSAMKwMAY0UNACAMIA05AwALIARBCGohBCAMQQhqIQwgC0EBaiILIAFIDQALCyAfIBZqIR8gICAWaiEgICFBAWoiISABRw0ACyAZIBZqIRkgGyAWaiEbIBdBAWohFyACQQFqIgIgA0cNAAsLCwAwBG5hbWUACwpmbG95ZC53YXNtAQgBAAVmbG95ZAcSAQAPX19zdGFja19wb2ludGVyADgJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDFVidW50dSBjbGFuZxExOC4xLjMgKDF1YnVudHUxKQA1D3RhcmdldF9mZWF0dXJlcwMrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQrB3NpbWQxMjg=",Er=.2,bo=3e3,X2=.05,J2=.995,Z2=2e3,j2=10;function th(e,t,n=Er,s){if(t<2)return null;const o=new Float64Array(t);for(let m=0;m<t;m++){const g=m*t;for(let p=0;p<t;p++)o[p]+=e[g+p]}const r=lh(o);let i=0;for(let m=0;m<t;m++)r[m]===0&&i++;if(i<2)return null;const a=new Int32Array(i);for(let m=0,g=0;m<t;m++)r[m]===0&&(a[g++]=m);const c=new Float64Array(i*i);for(let m=0;m<i;m++){const g=a[m]*t,p=m*i;for(let w=0;w<i;w++)c[p+w]=e[g+a[w]]}const{rows:u,cols:l}=nh(c,i),h=new Float64Array(i*i);for(let m=0;m<h.length;m++){const g=c[m];h[m]=g>0?1/Math.pow(g,n):Number.POSITIVE_INFINITY}sh(h,i);const f=-1/n;for(let m=0;m<h.length;m++){const g=h[m];h[m]=Number.isFinite(g)?Math.pow(g,f):0}const d=ch(c,h,i);return{kept:a,scn:c,boosted:d,rows:u,cols:l}}function eh(e,t,n=Er,s){const o=th(e,t,n);if(o===null)return null;const{kept:r,boosted:i,rows:a,cols:c}=o,u=r.length;for(let l=0;l<u;l++){const h=l*u;for(let f=0;f<u;f++){const d=(a[l]*c[f]+a[f]*c[l])/2;i[h+f]=d>0?i[h+f]/d:0}}return{kept:r,counts:i}}function nh(e,t,n=j2){const s=new Float64Array(t).fill(1),o=new Float64Array(t).fill(1),r=new Float64Array(t);for(let i=0;i<n;i++){r.fill(0);for(let a=0;a<t;a++){const c=a*t;for(let u=0;u<t;u++)r[u]+=e[c+u]}for(let a=0;a<t;a++){const c=Math.max(1,r[a]);r[a]=c,o[a]/=c}for(let a=0;a<t;a++){const c=a*t;for(let u=0;u<t;u++)e[c+u]/=r[u]}for(let a=0;a<t;a++){const c=a*t;let u=0;for(let h=0;h<t;h++)u+=e[c+h];const l=Math.max(1,u);s[a]/=l;for(let h=0;h<t;h++)e[c+h]/=l}}for(let i=0;i<t;i++)for(let a=i+1;a<t;a++){const c=(e[i*t+a]+e[a*t+i])/2;e[i*t+a]=c,e[a*t+i]=c}return{rows:s,cols:o}}function sh(e,t,n,s="auto"){if(s!=="js"&&ih(e,t))return"wasm";for(let o=0;o<t;o++){const r=o*t;for(let i=0;i<t;i++){const a=i*t,c=e[a+o];if(c!==Number.POSITIVE_INFINITY)for(let u=0;u<t;u++){const l=c+e[r+u];l<e[a+u]&&(e[a+u]=l)}}}return"js"}let Le;const Ao=131072,oh=65536,vi=64;function rh(){if(Le!==void 0)return Le;Le=null;try{if(typeof WebAssembly>"u")return null;const e=atob(V2),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);WebAssembly.validate(t)&&(Le=new WebAssembly.Module(t))}catch{Le=null}return Le}function ih(e,t,n){const s=rh();if(s===null)return!1;let o,r;try{const i=new WebAssembly.Memory({initial:Math.ceil((Ao+e.length*8)/oh)});o=new WebAssembly.Instance(s,{env:{memory:i}}).exports.floyd,r=new Float64Array(i.buffer,Ao,e.length)}catch{return!1}r.set(e);for(let i=0;i<t;i+=vi){const a=Math.min(t,i+vi);o(Ao,t,i,a)}return e.set(r),!0}function ah(e){const t=new Float64Array(e);t[0]=1;for(let a=1;a<e;a++)t[a]=t[a-1]*1.01;const n=[];let s=0;for(let a=0;a<e&&s<e;a++){const c=Math.floor(t[a]);n.push(c),s+=c}const o=n.length-1;n[o]-=s-e,n[o-1]+=n[o],n.length=o;const r=new Int32Array(e);let i=0;for(let a=0;a<n.length;a++)for(let c=0;c<n[a];c++)r[i++]=a;return{window:r,sizes:n}}function ki(e,t,n){const s=new Float64Array(n.length);let o=0;for(let r=0;r<n.length;r++){let i=0,a=0;for(let c=0;c<n[r];c++,o++){for(let u=0;u+o<t;u++)i+=e[u*t+u+o];a+=t-o}s[r]=a>0?i/a:0}return s}function ch(e,t,n){const{window:s,sizes:o}=ah(n),r=ki(e,n,o),i=ki(t,n,o),a=new Float64Array(t);for(let c=0;c<n;c++){const u=s[c],l=i[u]>0?r[u]/i[u]:0;for(let h=c;h<n;h++){const f=(h-c)*n+h,d=h*n+(h-c);a[f]=t[f]*l,a[d]=t[d]*l}}return a}function lh(e,t=X2,n=J2,s=Z2){const o=e.length,r=new Uint8Array(o),i=[];let a=0;for(let w=0;w<o;w++){const b=e[w];b>0&&i.push(b),b>a&&(a=b)}if(i.length===0)return r.fill(1),r;const c=Math.floor(a)+1,u=c>1?a/(c-1):0,l=w=>{const b=w*u+u/2;let y=0;for(const A of i)y+=uh((b-A)/s);return y},h=l(-1),f=l(c-1)-h,d=w=>f>0?(l(w)-h)/f:1,m=w=>{let b=0,y=c-1;for(;b<y;){const A=b+y>>>1;d(A)>=w?y=A:b=A+1}return b>0&&Math.abs(d(b-1)-w)<=Math.abs(d(b)-w)?b-1:b},g=m(t),p=m(n);for(let w=0;w<o;w++)(e[w]<g||e[w]>p)&&(r[w]=1);return r}function uh(e){return .5*hh(-e/Math.SQRT2)}function hh(e){const t=Math.abs(e);let n;if(t<2){let s=t,o=t;for(let r=1;r<200&&(s*=2*t*t/(2*r+1),o+=s,!(s<Math.abs(o)*1e-17));r++);n=1-2/Math.sqrt(Math.PI)*Math.exp(-t*t)*o}else if(t>27)n=0;else{let o=1/t,r=1e300,i=o;for(let a=1;a<300;a++){const c=a/2;o=t+c*o,o===0&&(o=1e-300),r=t+c/r,r===0&&(r=1e-300),o=1/o;const u=r*o;if(i*=u,Math.abs(u-1)<1e-16)break}n=Math.exp(-t*t)/Math.sqrt(Math.PI)*i}return e>=0?n:2-n}const fh=9007199254740992;function Si(e,t){return e<<t|e>>>32-t}function Ci(e){return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^e>>>16)>>>0}function ll(...e){let t=2166136261;for(const n of e){const s=Number.isFinite(n)?Math.trunc(n):0,o=s>>>0,r=Math.floor(s/4294967296)>>>0;t=Ci((t^o)+2654435769),t=Ci((t^r)+2135587861)}return t}class ul{s0;s1;s2;s3;constructor(t){let n=t|0;const s=()=>{n=n+2654435769|0;let o=n^n>>>16;return o=Math.imul(o,569420461),o^=o>>>15,o=Math.imul(o,1935289751),(o^o>>>15)>>>0};this.s0=s(),this.s1=s(),this.s2=s(),this.s3=s(),(this.s0|this.s1|this.s2|this.s3)===0&&(this.s0=1)}nextUint32(){let t=this.s0,n=this.s1,s=this.s2,o=this.s3;const r=Math.imul(Si(Math.imul(n,5),7),9)>>>0,i=n<<9;return s^=t,o^=n,n^=s,t^=o,s^=i,o=Si(o,11),this.s0=t,this.s1=n,this.s2=s,this.s3=o,r}nextDouble(){const t=this.nextUint32()>>>5,n=this.nextUint32()>>>6;return(t*67108864+n)/fh}interval(t){if(t<=0)return 0;if(t<=4294967295){let n=t;for(n|=n>>>1,n|=n>>>2,n|=n>>>4,n|=n>>>8,n|=n>>>16;;){const s=(this.nextUint32()&n)>>>0;if(s<=t)return s}}return Math.floor(this.nextDouble()*(t+1))}}function hl(e,t,n){if(!(t>0)||!(n>0))return 0;if(n>=1)return t;if(n<=.5)return n*t<=30?Fi(e,t,n):$i(e,t,n);const s=1-n;return t-(s*t<=30?Fi(e,t,s):$i(e,t,s))}function Fi(e,t,n){const s=1-n,o=Math.exp(t*Math.log1p(-n)),r=t*n,i=Math.min(t,Math.floor(r+10*Math.sqrt(r*s+1)));let a=0,c=o,u=e.nextDouble();for(;u>c;)a++,a>i?(a=0,c=o,u=e.nextDouble()):(u-=c,c=(t-a+1)*n*c/(a*s));return a}function Kn(e){const t=e*e;return(13680-(462-(132-(99-140/t)/t)/t)/t)/e/166320}function $i(e,t,n){const s=Math.min(n,1-n),o=1-s,r=t*s+s,i=Math.floor(r),a=Math.floor(2.195*Math.sqrt(t*s*o)-4.6*o)+.5,c=i+.5,u=c-a,l=c+a,h=.134+20.5/(15.3+i);let f=(r-u)/(r-u*s);const d=f*(1+f/2);f=(l-r)/(l*o);const m=f*(1+f/2),g=a*(1+2*h),p=g+h/d,w=p+h/m,b=t*s*o,y=A=>n>.5?t-A:A;for(;;){const A=e.nextDouble()*w;let N=e.nextDouble(),I;if(A<=a)return y(Math.floor(c-a*N+A));if(A<=g){const _=u+(A-a)/h;if(N=N*h+1-Math.abs(i-_+.5)/a,N>1)continue;I=Math.floor(_)}else if(A<=p){if(I=Math.floor(u+Math.log(N)/d),I<0||N===0)continue;N=N*(A-g)*d}else{if(I=Math.floor(l-Math.log(N)/m),I>t||N===0)continue;N=N*(A-p)*m}const M=Math.abs(I-i);if(!(M>20&&M<b/2-1)){const _=s/o,$=_*(t+1);let O=1;if(i<I)for(let L=i+1;L<=I;L++)O*=$/L-_;else if(i>I)for(let L=I+1;L<=i;L++)O/=$/L-_;if(N>O)continue;return y(I)}const x=M/b*((M*(M/3+.625)+.16666666666666666)/b+.5),v=-M*M/(2*b),S=Math.log(N);if(S<v-x)return y(I);if(S>v+x)continue;const k=I+1,C=i+1,B=t+1-i,F=t-I+1,E=c*Math.log(C/k)+(t-i+.5)*Math.log(B/F)+(I-i)*Math.log(F*s/(k*o))+Kn(C)+Kn(B)+Kn(k)+Kn(F);if(!(S>E))return y(I)}}const dh=(()=>{const e=new Float64Array(126);for(let t=2;t<126;t++)e[t]=e[t-1]+Math.log(t);return e})(),mh=.9189385332046728;function fe(e){return e<126?dh[e]:(e+.5)*Math.log(e)-e+(mh+1/e*(1/12-1/(360*e*e)))}function fl(e,t,n,s){if(!(s>0)||!(t>0))return 0;if(!(n>0))return Math.min(s,t);const o=t+n;return s>=o?t:s>=10&&s<=o-10?bh(e,t,n,s):gh(e,t,n,s)}function gh(e,t,n,s){const o=t+n,r=Math.floor(o/2);let i=s>r?o-s:s,a=o,c=t;for(;i>0&&c>0&&a>c;)a--,e.interval(a)<c&&c--,i--;return a===c&&(c-=i),s>r?c:t-c}const ph=1.7155277699214135,wh=.8989161620588988;function bh(e,t,n,s){const o=t+n,r=Math.min(s,o-s),i=Math.min(t,n),a=Math.max(t,n),c=i/o,u=a/o,h=r*c+.5,f=(o-r)*r*c*u/(o-1),d=Math.sqrt(f+.5),m=ph*d+wh,g=Math.floor((r+1)*(i+1)/(o+2)),p=fe(g)+fe(i-g)+fe(r-g)+fe(a-r+g),w=Math.min(Math.min(r,i)+1,Math.floor(h+16*d));let b;for(;;){const y=e.nextDouble(),A=e.nextDouble();if(y===0)continue;const N=h+m*(A-.5)/y;if(N<0||N>=w)continue;b=Math.floor(N);const I=fe(b)+fe(i-b)+fe(r-b)+fe(a-r+b),M=p-I;if(y*(4-y)-3<=M)break;if(!(y*(y-M)>=1)&&2*Math.log(y)<=M)break}return t>n&&(b=r-b),r<s&&(b=t-b),b}const Ah=1;function yh(e,t){return t===e?"none":t<e?"sub":"over"}const Nh=81,dl=91,ml=14,Mh=192*1024*1024,Ih=4096,xh=32,vh=1e6;function ae(e,t={}){return new T("unsupported",e,{...t,resample:!0})}function kh(e){return e>=0&&Number.isInteger(e)}class fs{constructor(t){this.starts=t}last=0;get count(){return this.starts.length-1}of(t){const n=this.starts,s=this.last;if(t>=n[s]&&t<n[s+1])return s;let o=0,r=n.length-2;for(;o<r;){const i=o+r+1>>>1;n[i]<=t?o=i:r=i-1}return this.last=o,o}touching(t,n){const s=[];if(n<=t)return s;const o=this.of(Math.max(0,t));for(let r=o;r<this.count&&this.starts[r]<n;r++)this.starts[r+1]>this.starts[r]&&s.push(r);return s}}async function Ei(e,t,n={}){const s=new fs(t),o=s.count,r=t[o],i=o<=512?new Float64Array(o*o):null,a=i===null?new Map:null;let c=0,u=null,l=!1;if(await e.scanAll({chunkSize:vh,...n.pause===void 0?{}:{pause:n.pause},onChunk:p=>{if(n.cancelled?.()===!0)return l=!0,!1;const{bin1:w,bin2:b,count:y,length:A}=p;for(let N=0;N<A;N++){const I=y[N];if(!kh(I))return u=ae(`This map stores ${I} where a number of contacts would be, so there are no contacts to draw from it. Resampling reads raw counts — whole numbers, one per contact.`,{value:I}),!1;if(I===0)continue;const M=w[N],x=b[N];if(x<M)return u=ae("This map stores pixels below its diagonal, so each contact would be drawn twice. Resampling reads upper-triangular files — cooler’s default."),!1;const v=s.of(M),S=x<t[v+1]?v:s.of(x);c++,i!==null?i[v*o+S]+=I:a.set(v*o+S,(a.get(v*o+S)??0)+I)}return!0},onProgress:n.onProgress}),u!==null)throw u;if(l)throw new DOMException("The census was cancelled.","AbortError");const h=[];if(i!==null)for(let p=0;p<i.length;p++)i[p]>0&&h.push(p);else{for(const p of a.keys())h.push(p);h.sort((p,w)=>p-w)}const f=new Int32Array(h.length),d=new Int32Array(h.length),m=new Float64Array(h.length);let g=0;for(let p=0;p<h.length;p++){const w=h[p];f[p]=Math.floor(w/o),d[p]=w-f[p]*o,m[p]=i!==null?i[w]:a.get(w),g+=m[p]}return{total:g,nnz:c,sequences:o,nBins:r,a:f,b:d,sum:m}}function Sh(e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw ae(`${e} is not a number of contacts: it must be a positive whole number.`,{contacts:e});if(e>Number.MAX_SAFE_INTEGER)throw ae(`${e} contacts is past what can be counted exactly here (2⁵³).`,{contacts:e});return e}function Ch(e,t,n,s){const o=Sh(t.contacts),r=e.total;if(!(r>0))throw ae("This map holds no contacts, so there is nothing to draw from it.",{total:r});const i=t.seed??Ah,a=t.alpha??Er,c=yh(r,o),u=new Map,l={mode:c,contacts:o,total:r,seed:i,alpha:a,shares:u,weightScale:Math.sqrt(r/o)};if(c==="none")return l;const h=new ul(ll(i,Nh,c==="sub"?dl:ml)),f=e.sum.length;if(c==="sub"){let g=o,p=r;for(let w=0;w<f&&g>0;w++){const b=e.sum[w],y=fl(h,b,p-b,g);y>0&&u.set(e.a[w]*e.sequences+e.b[w],y),g-=y,p-=b}return l}if(!(a>0))throw ae(`Boost-HiC’s alpha must be above zero; ${a} was given.`,{alpha:a});for(let g=0;g<f;g++){const p=e.a[g];if(e.b[g]!==p)continue;const w=n[p+1]-n[p];if(w>bo){const b=s?.[p]??`sequence ${p+1}`;throw ae(`${b} is ${w.toLocaleString("en-US")} bins at this resolution, and Boost-HiC — which oversamples it — walks every path between them: at most ${bo.toLocaleString("en-US")}. Open a coarser resolution to oversample this map.`,{sequence:b,bins:w,limit:bo})}}let d=o-r,m=r;for(let g=0;g<f&&d>0;g++){const p=e.sum[g],w=g===f-1?d:hl(h,d,Math.min(1,p/m));w>0&&u.set(e.a[g]*e.sequences+e.b[g],w),d-=w,m-=p}return l}class Bi{bin1;bin2;count;length=0;constructor(t=1024){this.bin1=new Int32Array(t),this.bin2=new Int32Array(t),this.count=new Float64Array(t)}push(t,n,s){this.length===this.bin1.length&&this.grow(this.length*2),this.bin1[this.length]=t,this.bin2[this.length]=n,this.count[this.length]=s,this.length++}grow(t){const n=new Int32Array(t),s=new Int32Array(t),o=new Float64Array(t);n.set(this.bin1.subarray(0,this.length)),s.set(this.bin2.subarray(0,this.length)),o.set(this.count.subarray(0,this.length)),this.bin1=n,this.bin2=s,this.count=o}}function Fh(e,t,n,s,o){let r=t,i=n;const{bin1:a,bin2:c,count:u}=e;for(let l=0;l<u.length&&r>0;l++){const h=u[l];if(h===0)continue;let f;if(r===i)f=h,i-=h;else if(h<=xh){f=0;for(let d=0;d<h;d++)s.nextDouble()*i<r-f&&f++,i--}else f=fl(s,h,i-h,r),i-=h;r-=f,f>0&&o.push(a[l],c[l],f)}}function gl(e,t,n){const s=e.length,o=new Float64Array(s);if(t<=0||s===0)return o;const r=new Float64Array(s+1);let i=-1;for(let c=s-1;c>=0;c--){const u=e[c]>0?e[c]:0;r[c]=r[c+1]+u,u>0&&i<0&&(i=c)}if(i<0)return o;let a=t;for(let c=0;c<s&&a>0;c++){const u=e[c];if(!(u>0))continue;const l=c===i?a:hl(n,a,Math.min(1,u/r[c]));o[c]=l,a-=l}return o}function $h(e,t,n,s){const o=gl(e.count,t,n),{bin1:r,bin2:i,count:a}=e;for(let c=0;c<a.length;c++){const u=a[c]+o[c];u>0&&s.push(r[c],i[c],u)}}function Eh(e,t,n){const s=new Float64Array(n*n),{bin1:o,bin2:r,count:i}=e;for(let a=0;a<i.length;a++){const c=o[a]-t,u=r[a]-t;s[c*n+u]+=i[a],c!==u&&(s[u*n+c]+=i[a])}return s}function Bh(e,t,n,s,o,r,i){const a=Eh(e,t,n),c=eh(new Float64Array(a),n,o),u=n*(n+1)/2,l=new Float64Array(u);let h=0;for(let d=0;d<n;d++)for(let m=d;m<n;m++)l[h++]=a[d*n+m];if(c!==null){const{kept:d,counts:m}=c,g=d.length;let p=0,w=0;for(let y=0;y<g;y++)for(let A=y;A<g;A++)p+=a[d[y]*n+d[A]],w+=m[y*g+A];const b=w>0?p/w:0;for(let y=0;y<g;y++){const A=d[y],N=A*n-A*(A-1)/2-A;for(let I=y;I<g;I++)l[N+d[I]]=m[y*g+I]*b}}const f=gl(l,s,r);h=0;for(let d=0;d<n;d++)for(let m=d;m<n;m++,h++){const g=a[d*n+m]+f[h];g>0&&i.push(t+d,t+m,g)}}class Th{constructor(t,n,s,o){this.inner=t,this.geometry=n,this.spec=s,this.index=new fs(n.starts),this.census=o}countKind="i";index;census;planned=null;plan=null;bands=new Map;bytes=0;get nnz(){return this.inner.nnz}get weightScale(){return this.plan?.weightScale??1}ready(){return this.planned??=this.census.then(t=>{if(t.nBins!==this.geometry.starts[this.index.count])throw ae("This census was taken over another map.",{bins:t.nBins,nBins:this.geometry.starts[this.index.count]});const n=Ch(t,this.spec,this.geometry.starts,this.geometry.names);return this.plan=n,n}),this.planned}scoreColumns(){return["count"]}binOffsets(){return this.inner.binOffsets()}async forEachWindow(t,n,s,o,r={}){return(await this.ready()).mode==="none"?this.inner.forEachWindow(t,n,s,o,r):this.walk([[s.span[0],s.span[1]]],o,r)}async forEachBands(t,n,s={}){return(await this.ready()).mode==="none"?this.inner.forEachBands(t,n,s):this.walk(t,n,s)}async scanAll(t){if((await this.ready()).mode==="none")return this.inner.scanAll(t);const n=this.geometry.starts[this.index.count];let s=!1;await this.walk([[0,n]],o=>{s||t.onChunk(o)===!1&&(s=!0)},{cancelled:()=>s,onProgress:(o,r)=>t.onProgress?.(o,r)})}async walk(t,n,s){if(s.value!==void 0&&s.value!=="count")throw ae(`A resampled map is drawn from its contacts, and “${s.value}” is not a count of them. Read the counts, or balance them, while the map is resampled.`,{value:s.value});const o=await this.ready(),r=Oh(t),i=[];for(const[u,l]of r)for(const h of this.index.touching(u,l))i[i.length-1]!==h&&i.push(h);const a=[...new Set(i)].sort((u,l)=>u-l);let c=0;for(let u=0;u<a.length;){if(s.cancelled?.()===!0)return!1;const l=[];let h=0;for(;u<a.length;){const d=a[u],m=this.geometry.starts[d+1]-this.geometry.starts[d];if(l.length>0&&h+m>Ih)break;l.push(d),h+=m,u++}const f=l.filter(d=>!this.bands.has(d));if(f.length>0&&await this.draw(f,o,s)===null)return!1;for(const d of l){const m=this.bands.get(d);this.touch(d);for(const[g,p]of r){const w=Math.max(g,m.from)-m.from,b=Math.min(p,m.from+m.rows.length-1)-m.from;if(b<=w)continue;const y=m.rows[w],A=m.rows[b];A>y&&n({bin1:m.bin1.subarray(y,A),bin2:m.bin2.subarray(y,A),count:m.count.subarray(y,A),length:A-y})}c++,s.onProgress?.(c,a.length)}this.evict(new Set(l)),await xt()}return!0}async draw(t,n,s){const o=this.geometry.starts,r=new Map;for(const l of t)r.set(l,new Bi);const i=new fs(o);let a=-1,c;if(!await this.inner.forEachBands(t.map(l=>[o[l],o[l+1]]),l=>{const{bin1:h,bin2:f,count:d,length:m}=l;for(let g=0;g<m;g++){if(d[g]===0)continue;const p=i.of(h[g]);p!==a&&(a=p,c=r.get(p)),c?.push(h[g],f[g],d[g])}},...s.cancelled===void 0?[]:[{cancelled:s.cancelled}]))return null;for(const l of t){if(this.store(this.drawBand(l,r.get(l),n)),r.delete(l),s.cancelled?.()===!0)return null;await xt()}return!0}drawBand(t,n,s){const o=this.geometry.starts,r=o[t],i=o[t+1],a=this.index.count,c=n.length,u=Lh(n),l=new fs(o),h=new Int32Array(c),f=new Map,d=[];let m=-1,g=-1;for(let M=0;M<c;M++){const x=l.of(n.bin2[u[M]]);if(x!==m){let v=f.get(x);v===void 0&&(v=d.length,f.set(x,v),d.push(x)),m=x,g=v}h[M]=g}const p=new Int32Array(d.length+1);for(let M=0;M<c;M++)p[h[M]+1]++;for(let M=0;M<d.length;M++)p[M+1]+=p[M];const w=p.slice(0,d.length),b=new Int32Array(c),y=new Int32Array(c),A=new Float64Array(c);for(let M=0;M<c;M++){const x=u[M],v=w[h[M]]++;b[v]=n.bin1[x],y[v]=n.bin2[x],A[v]=n.count[x]}const N=new Bi(Math.max(1024,s.mode==="sub"?Math.ceil(c/2):c)),I=d.map((M,x)=>({b:M,local:x})).sort((M,x)=>M.b-x.b);for(const{b:M,local:x}of I){const v=p[x],S=p[x+1],k={bin1:b.subarray(v,S),bin2:y.subarray(v,S),count:A.subarray(v,S)};if(s.mode==="none"){for(let F=0;F<k.count.length;F++)N.push(k.bin1[F],k.bin2[F],k.count[F]);continue}const C=s.shares.get(t*a+M)??0,B=new ul(ll(s.seed,s.mode==="sub"?dl:ml,t,M));if(s.mode==="sub"){let F=0;for(let E=0;E<k.count.length;E++)F+=k.count[E];Fh(k,C,F,B,N)}else M===t?Bh(k,r,i-r,C,s.alpha,B,N):$h(k,C,B,N)}return _h(t,r,i,N)}store(t){this.bands.set(t.sequence,t),this.bytes+=t.bytes}touch(t){const n=this.bands.get(t);n!==void 0&&(this.bands.delete(t),this.bands.set(t,n))}evict(t){for(const[n,s]of this.bands){if(this.bytes<=Mh)return;t.has(n)||(this.bands.delete(n),this.bytes-=s.bytes)}}}function Oh(e){const t=e.filter(([s,o])=>o>s).map(([s,o])=>[s,o]);t.sort((s,o)=>s[0]-o[0]);const n=[];for(const s of t){const o=n[n.length-1];o!==void 0&&s[0]<=o[1]?o[1]=Math.max(o[1],s[1]):n.push(s)}return n}function Lh(e){const t=e.length,n=new Int32Array(t);let s=!0;for(let i=0;i<t;i++)n[i]=i,i>0&&(e.bin1[i]<e.bin1[i-1]||e.bin1[i]===e.bin1[i-1]&&e.bin2[i]<e.bin2[i-1])&&(s=!1);if(s)return n;const{bin1:o,bin2:r}=e;return n.sort((i,a)=>o[i]-o[a]||r[i]-r[a])}function _h(e,t,n,s){const o=n-t,r=new Int32Array(o+1);for(let l=0;l<s.length;l++)r[s.bin1[l]-t+1]++;for(let l=0;l<o;l++)r[l+1]+=r[l];const i=r.slice(0,o),a=new Int32Array(s.length),c=new Int32Array(s.length),u=new Float64Array(s.length);for(let l=0;l<s.length;l++){const h=i[s.bin1[l]-t]++;a[h]=s.bin1[l],c[h]=s.bin2[l],u[h]=s.count[l]}return{sequence:e,from:t,bin1:a,bin2:c,count:u,rows:r,bytes:s.length*16+r.length*4}}class Wn{constructor(t,n,s,o,r){this.nBins=o,this.countKind=r,this.cells=s.map(i=>({name:i,store:new rl(t.at(vs(n,i)),o,r)}))}countKind;cells;offsets=null;onCells=null;get names(){return this.cells.map(t=>t.name)}get nnz(){let t=0;for(const n of this.cells)t+=n.store.nnz;return t}scoreColumns(){const[t,...n]=this.cells;if(t===void 0)return[j];let s=t.store.scoreColumns();for(const o of n){const r=new Set(o.store.scoreColumns());s=s.filter(i=>r.has(i))}return s.length>0?s:[j]}binOffsets(){if(this.offsets!==null)return this.offsets;const t=new Float64Array(this.nBins+1);for(const n of this.cells){const s=n.store.binOffsets(),o=Math.min(t.length,s.length);for(let r=0;r<o;r++)t[r]+=s[r]}return this.offsets=t,t}async forEachWindow(t,n,s,o,r={}){let i=0;for(const a of this.cells){if(!await a.store.forEachWindow(t,n,s,o,r))return!1;await xt(),this.onCells?.(++i,this.cells.length)}return!0}async forEachBands(t,n,s={}){let o=0;for(const r of this.cells){if(!await r.store.forEachBands(t,n,s))return!1;await xt(),this.onCells?.(++o,this.cells.length)}return!0}async scanAll(t){const n=this.nnz;let s=0,o=!1;for(const r of this.cells){if(o)return;const i=s;await r.store.scanAll({...t.chunkSize===void 0?{}:{chunkSize:t.chunkSize},...t.storedRows===void 0?{}:{storedRows:t.storedRows},onChunk:a=>{const c=t.onChunk(a);return c===!1&&(o=!0),c},onProgress:a=>{s=i+a,t.onProgress?.(s,n)}}),s=i+r.store.nnz,t.onProgress?.(Math.min(s,n),n)}}async scanPerCell(t){const n=this.nnz;let s=0;for(let o=0;o<this.cells.length;o++){const r=this.cells[o];t.onCell?.(o,r.name);const i=s;let a=!1;if(await r.store.scanAll({...t.chunkSize===void 0?{}:{chunkSize:t.chunkSize},onChunk:c=>{const u=t.onChunk(o,c);return u===!1&&(a=!0),u},onProgress:c=>{s=i+c,t.onProgress?.(s,n)}}),a)return;s=i+r.store.nnz,t.onProgress?.(Math.min(s,n),n),await xt()}}}function Ti(e,t){if(t===null||t.length===0)return[...e];const n=new Set(e),s=t.filter(r=>!n.has(r));if(s.length>0)throw new T("cell-not-found",`This file has no ${s.length===1?"cell":"cells"} ${zt(s.slice(0,8))}. It carries ${e.length} ${e.length===1?"cell":"cells"}, starting ${zt(e.slice(0,3))}.`,{missing:s,available:e.length});const o=new Set(t);return e.filter(r=>o.has(r))}function It(e,t){const n=bl(e),s=Al(n,t);if(s===null)return n;throw new T("format",`The ${t.field} of this ${t.format} reads ${sr(e)}, ${s.reason}. `+Ve,{format:t.format,field:t.field,value:typeof e=="bigint"?e.toString():e,ceiling:t.ceiling,...t.available===void 0?{}:{available:t.available},...s.most===void 0?{}:{most:s.most}})}function Dh(e,t){return Al(bl(e),t)===null}function Ks(e,t,n){const s={format:n.format,field:n.field,offset:e,length:t,size:n.size};if(!nr(e)||!nr(t))throw new T("format",`The ${n.field} of this ${n.format} points at ${sr(t)} bytes from byte ${sr(e)}, which is not a place in a file. ${Ve}`,s);if(n.ceiling!==void 0&&t>n.ceiling)throw new T("format",`The ${n.field} of this ${n.format} is ${Mt.int(t)} bytes long, more than the ${Mt.int(n.ceiling)} any real one holds. ${Ve}`,{...s,ceiling:n.ceiling});if(e+t>n.size)throw new T("format",`The ${n.field} of this ${n.format} points at bytes ${Mt.int(e)} to ${Mt.int(e+t)}, past the end of a file of ${Mt.int(n.size)}. ${Ve}`,s)}const Oi=65536,Br=2**29;async function Tr(e,t){if(typeof DecompressionStream>"u")throw new T("unsupported",`Reading a ${t.format} needs DecompressionStream, which this runtime does not have. Every browser since 2023 has it; a very old one does not.`,{format:t.format});const n=new DecompressionStream(t.encoding),s=n.writable.getWriter(),o=n.readable.getReader(),r=[];let i=0,a=!1;const c=(async()=>{for(;;){const{done:g,value:p}=await o.read();if(g)return;if(i+=p.byteLength,i>t.maxBytes){a=!0,await o.cancel();return}r.push(p)}})(),u=(async()=>{for(let g=0;g<e.byteLength;g+=Oi){if(a)return;const p=e.subarray(g,Math.min(g+Oi,e.byteLength));await s.write(p)}a||await s.close()})(),[l,h]=await Promise.allSettled([c,u]);if(a)throw wl(t,t.maxBytes,e.byteLength);const f=l.status==="rejected"?l.reason:h.status==="rejected"?h.reason:null;if(f!==null){const g=f instanceof Error?f.message:String(f);throw new T("format",`The ${t.field} of this ${t.format} does not inflate (${g.replace(/\.$/,"")}). ${Ve}`,{format:t.format,field:t.field})}if(r.length===1)return r[0];const d=new Uint8Array(i);let m=0;for(const g of r)d.set(g,m),m+=g.length;return d}function pl(e,t){return Math.min(t.ceiling,Math.max(t.floor,Math.ceil(e*t.ratio)))}function wl(e,t,n){return new T("format",`The ${e.field} of this ${e.format} inflates to more than ${Mt.bytes(t)}, past what any real one holds. ${Ve}`,{format:e.format,field:e.field,maxBytes:t,compressed:n})}const Ve="The file is truncated, corrupt, or not the format its first bytes claim.";function bl(e){return typeof e=="number"?e:e>=BigInt(Number.MIN_SAFE_INTEGER)&&e<=BigInt(Number.MAX_SAFE_INTEGER)?Number(e):Number.NaN}function nr(e){return Number.isSafeInteger(e)&&e>=0}function Al(e,t){if(!nr(e))return{reason:"which is not a count"};if(e>t.ceiling)return{reason:`more than the ${Mt.int(t.ceiling)} any real one declares`};if(t.available!==void 0){const n=Math.floor(Math.max(0,t.available)/Math.max(1,t.bytesPerItem??1));if(e>n){const s=Math.max(0,t.available);return{reason:`and the ${Mt.int(s)} byte${s===1?"":"s"} after it could hold at most ${Mt.int(n)}`,most:n}}}return null}function sr(e){return typeof e=="bigint"?e.toString():Number.isSafeInteger(e)?Mt.int(e):String(e)}const Li=[7,8,9],dt=".hic",yl=2**31-1,Rh=2**40;class jt extends RangeError{needed;constructor(t){super(`a read needs ${t} bytes of a shorter buffer`),this.name="Truncated",this.needed=t}}class nn{constructor(t){this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}view;at=0;get position(){return this.at}set position(t){this.at=t}get remaining(){return this.bytes.byteLength-this.at}need(t){if(this.at+t>this.bytes.byteLength)throw new jt(this.at+t)}int8(){this.need(1);const t=this.view.getInt8(this.at);return this.at+=1,t}int16(){this.need(2);const t=this.view.getInt16(this.at,!0);return this.at+=2,t}int32(){this.need(4);const t=this.view.getInt32(this.at,!0);return this.at+=4,t}int64(){this.need(8);const t=this.view.getBigInt64(this.at,!0);return this.at+=8,t>BigInt(Number.MAX_SAFE_INTEGER)||t<BigInt(Number.MIN_SAFE_INTEGER)?Number.NaN:Number(t)}float32(){this.need(4);const t=this.view.getFloat32(this.at,!0);return this.at+=4,t}float64(){this.need(8);const t=this.view.getFloat64(this.at,!0);return this.at+=8,t}string(){const t=this.at,n=this.bytes.indexOf(0,t);if(n<0)throw new jt(Math.max(t,this.bytes.byteLength)+1);const s=new TextDecoder().decode(this.bytes.subarray(t,n));return this.at=n+1,s}skip(t){if(!(t>=0))throw new RangeError(`a cursor cannot skip ${t} bytes`);this.at+=t}}const Ph=512*1024;function Nl(e){return e.length>=4&&e[0]===72&&e[1]===73&&e[2]===67&&e[3]===0}function zh(e){let t=Math.min(Ph,e.size);for(;;){const n=e.readBytes(0,t);try{return qh(n,e.size)}catch(s){if(!(s instanceof jt))throw s;if(t>=e.size)throw new T("format",`This .hic ends inside its header, ${e.size.toLocaleString("en-US")} bytes in. The file is truncated, or is not the format its first four bytes claim.`,{size:e.size});t=Math.min(e.size,Math.max(t*4,s.needed))}}}function qh(e,t=e.byteLength){if(!Nl(e))throw new T("format","This file does not begin with the `.hic` magic bytes.",{});const n=new nn(e);n.position=4;const s=n.int32();if(!Li.includes(s))throw new T("unsupported",`This is a version ${s} .hic file, and this reader accepts versions ${Li.join(", ")}. Versions below 7 predate the block index this reader navigates by, and a version above the list is a format this build has not seen. Convert it with \`hic2cool\` or re-run Juicer Tools \`pre\`.`,{version:s});const o=n.int64(),r=n.string();let i=null,a=null;s>=9&&(i=n.int64(),a=n.int64());const c=()=>t-n.position,u={},l=It(n.int32(),{format:dt,field:"header attribute count",ceiling:1e6,available:c(),bytesPerItem:2});for(let g=0;g<l;g++){const p=n.string();u[p]=n.string()}const h=It(n.int32(),{format:dt,field:"chromosome count",ceiling:1e7,available:c(),bytesPerItem:1+(s>=9?8:4)});yo(h>0,"chromosome count");const f=[];for(let g=0;g<h;g++){const p=n.string(),w=It(s>=9?n.int64():n.int32(),{format:dt,field:`length of chromosome ${p}`,ceiling:Rh});f.push({name:p,length:w})}const d=It(n.int32(),{format:dt,field:"resolution count",ceiling:1e4,available:c(),bytesPerItem:4});yo(d>0,"resolution count");const m=[];for(let g=0;g<d;g++){const p=n.int32();yo(p>0,"bin size"),m.push(p)}return{version:s,footerPosition:o,genomeId:r,attributes:u,chroms:f,bpResolutions:m,normVectorIndexPosition:i,normVectorIndexLength:a,headerBytes:n.position}}function yo(e,t){if(!e)throw new T("format",`The ${t} in this .hic header is not a plausible number. The file is either truncated or is not the format its first four bytes claim.`,{what:t})}function or(e,t,n,s){return`${e}/${t}/${n}/${s}`}function Uh(e,t){const{version:n,footerPosition:s}=t,o=n>=9?8:4;Ks(s,o+4,{format:dt,field:"footer position",size:e.size});const r=e.size-s,i=new nn(e.readBytes(s,o)),a=It(n>=9?i.int64():i.int32(),{format:dt,field:"footer length",ceiling:Number.MAX_SAFE_INTEGER,available:r-o}),c={fileSize:e.size,footerPosition:s};let u=Math.min(r,Math.max(a+o+(1<<20),65536));for(;;){const l=e.readBytes(s,u);try{return Hh(l,n,o,c)}catch(h){if(!(h instanceof jt))throw h;if(u>=r)throw new T("format",`This .hic ends inside its footer, which begins ${s.toLocaleString("en-US")} bytes in. The file is truncated, or its header does not point at its footer.`,{footerPosition:s,size:e.size});u=Math.min(r,Math.max(u*4,h.needed))}}}const Gh=13;function Hh(e,t,n,s){const o=new nn(e);o.position=n;const r=s?.fileSize??e.byteLength,i=s?.footerPosition??0,a=()=>r-(i+o.position),c=new Map,u=It(o.int32(),{format:dt,field:"master index size",ceiling:1e8,available:a(),bytesPerItem:Gh});let l=0;for(let d=0;d<u;d++){const m=o.string(),g=o.int64(),p=o.int32();if(s!==void 0&&(Ks(g,p,{format:dt,field:`matrix record for ${m}`,size:s.fileSize}),l+=p,l>s.fileSize))throw new T("format",`The master index of this .hic gives its matrix records ${l.toLocaleString("en-US")} bytes between them by entry ${d+1}, more than the whole file's ${s.fileSize.toLocaleString("en-US")}. The file is corrupt, or not the format its first bytes claim.`,{entries:d+1,bytes:l,size:s.fileSize});c.set(m,{key:m,position:g,size:p})}_i(o,t,!1,a),_i(o,t,!0,a);const h=new Map,f=[];if(a()>=4){const d=o.int32(),m=18+(t>=9?8:4),g={ceiling:1e8,available:a(),bytesPerItem:m};if(Dh(d,g)){let p=0;for(let w=0;w<d;w++){const b=o.string(),y=o.int32(),A=o.string(),N=o.int32(),I=o.int64(),M=t>=9?o.int64():o.int32();h.set(or(b,y,A,N),{type:b,chromIdx:y,unit:A,binSize:N,position:I,nBytes:M}),f.includes(b)||f.push(b),p+=M}s!==void 0&&!(p<=s.fileSize)&&(h.clear(),f.length=0)}}return{masterIndex:c,normVectors:h,normTypes:f}}function _i(e,t,n,s){if(s()<4)return;const o=t>=9?4:8,r=It(e.int32(),{format:dt,field:`${n?"normalised ":""}expected-value vector count`,ceiling:1e6,available:s(),bytesPerItem:(n?1:0)+1+4+(t>=9?8:4)+4});for(let i=0;i<r;i++){n&&e.string(),e.string(),e.int32();const a=It(t>=9?e.int64():e.int32(),{format:dt,field:"expected-value vector length",ceiling:yl,available:s(),bytesPerItem:o});e.skip(a*o);const c=It(e.int32(),{format:dt,field:"expected-value scale factor count",ceiling:1e7,available:s(),bytesPerItem:4+o});e.skip(c*(4+o))}if(e.remaining<0)throw new jt(e.position)}function Qh(e,t,n){const s=`${n.type} normalisation vector of chromosome ${n.chromIdx}`,o=t>=9?8:4,r=t>=9?4:8;Ks(n.position,n.nBytes,{format:dt,field:s,size:e.size});const i=e.readBytes(n.position,o);if(i.byteLength<o)throw new T("format",`The ${s} begins in the last ${i.byteLength} bytes of this .hic, too few for its length. The file is truncated, or its normalisation index does not point at its vectors.`,{type:n.type,chromIdx:n.chromIdx,position:n.position});const a=new nn(i),c=It(t>=9?a.int64():a.int32(),{format:dt,field:`length of the ${s}`,ceiling:yl,available:n.nBytes-o,bytesPerItem:r}),u=e.readBytes(n.position+o,c*r),l=new DataView(u.buffer,u.byteOffset,u.byteLength),h=new Float64Array(c);for(let f=0;f<c;f++){const d=r===4?l.getFloat32(f*4,!0):l.getFloat64(f*8,!0);h[f]=d>0&&Number.isFinite(d)?1/d:Number.NaN}return h}const Di={ratio:64,floor:16<<20,ceiling:1<<30},rr=2**26,Kh=37,Ri=16,ds=2**31-1,No=4096;function Ws(e,t,n,s){const o=new nn(e),r=()=>s===void 0?void 0:s-o.position;o.int32(),o.int32();const i=It(o.int32(),{format:dt,field:"resolution count of a matrix record",ceiling:1e4,available:r(),bytesPerItem:Kh});for(let a=0;a<i;a++){const c=o.string();o.int32();const u=o.float32();o.float32(),o.float32(),o.float32();const l=o.int32(),h=o.int32(),f=o.int32(),d=It(o.int32(),{format:dt,field:"block count of a matrix record",ceiling:ds,available:r(),bytesPerItem:Ri});if(c!==t||l!==n){o.skip(d*Ri);continue}if(!(h>=1)||!(f>=1))throw new T("format",`This .hic's ${l} bp matrix declares blocks of ${h} bins in ${f} columns, which no block grid has. The file is truncated, corrupt, or not the format its first bytes claim.`,{binSize:l,blockBinCount:h,blockColumnCount:f});const m=new Map;for(let g=0;g<d;g++){const p=o.int32(),w=o.int64(),b=o.int32();m.set(p,{number:p,position:w,size:b})}return{unit:c,binSize:l,blockBinCount:h,blockColumnCount:f,blocks:m,sumCounts:u}}return null}function Wh(e,t,n,s,o){if(o>0&&o<t.size){try{return{zoom:Ws(e(t.position,o),n,s,t.size),beyondHead:!1}}catch(r){if(!(r instanceof jt))throw r}return{zoom:Je(e(t.position,t.size),t,n,s),beyondHead:!0}}return{zoom:Je(e(t.position,t.size),t,n,s),beyondHead:!1}}async function Yh(e,t,n,s,o){if(o>0&&o<t.size){try{return{zoom:Ws(await e(t.position,o),n,s,t.size),beyondHead:!1}}catch(r){if(!(r instanceof jt))throw r}return{zoom:Je(await e(t.position,t.size),t,n,s),beyondHead:!0}}return{zoom:Je(await e(t.position,t.size),t,n,s),beyondHead:!1}}function Je(e,t,n,s){try{return Ws(e,n,s,t.size)}catch(o){throw o instanceof jt?new T("format",`The matrix record for ${t.key} in this .hic ends inside its block index, ${e.byteLength.toLocaleString("en-US")} bytes in. The file is truncated, or its master index does not point at its records.`,{key:t.key,position:t.position,size:t.size}):o}}function Yn(e,t,n){const s=[...e].sort((r,i)=>r.position-i.position),o=[];for(const r of s){const i=o[o.length-1],a=r.position+r.size;if(i!==void 0&&r.position-(i.position+i.length)<=t&&a-i.position<=n){i.length=Math.max(i.length,a-i.position),i.refs.push(r);continue}o.push({position:r.position,length:r.size,refs:[r]})}return o}function Pi(e,t,n,s,o){const r=n&&t>=9?Jh(e,s,o):Xh(e,n,s,o);let i=0;for(const c of r)i+=Math.max(0,c.r2-c.r1+1)*Math.max(0,c.c2-c.c1+1);if(i>Math.max(Vh,e.blocks.size))return Zh(e,r);const a=new Set;for(const{r1:c,r2:u,c1:l,c2:h}of r)for(let f=c;f<=u;f++)for(let d=l;d<=h;d++)a.add(f*e.blockColumnCount+d);return[...a]}const Vh=1<<20;function Xh(e,t,n,s){const{blockBinCount:o}=e,r=Math.floor(n[0]/o),i=Math.floor(Math.max(n[0],n[1]-1)/o),a=Math.floor(s[0]/o),c=Math.floor(Math.max(s[0],s[1]-1)/o),u=[{r1:a,r2:c,c1:r,c2:i}];return t&&u.push({r1:r,r2:i,c1:a,c2:c}),u}function Jh(e,t,n){const{blockBinCount:s}=e,[o,r]=[t[0],Math.max(t[0],t[1]-1)],[i,a]=[n[0],Math.max(n[0],n[1]-1)],c=Math.floor((o+i)/2/s),u=Math.floor((r+a)/2/s)+1,l=Math.floor(Math.log2(1+Math.abs(o-a)/Math.SQRT2/s)),h=Math.floor(Math.log2(1+Math.abs(r-i)/Math.SQRT2/s)),d=o>a&&r<i||r>i&&o<a?0:Math.min(l,h),m=Math.max(l,h)+1;return[{r1:Math.max(0,d),r2:m,c1:Math.max(0,c),c2:u}]}function Zh(e,t){const n=e.blockColumnCount,s=[];for(const o of e.blocks.keys()){const r=Math.floor(o/n),i=o-r*n;t.some(a=>r>=a.r1&&r<=a.r2&&i>=a.c1&&i<=a.c2)&&s.push(o)}return s.sort((o,r)=>o-r)}function jh(e,t){try{return tf(e,t)}catch(n){throw n instanceof jt?new T("format",`A block of this .hic ends before its records do, ${e.byteLength.toLocaleString("en-US")} bytes in. The file is truncated, corrupt, or not the format its first bytes claim.`,{bytes:e.byteLength}):n}}function tf(e,t){const n=new nn(e),s=n.int32();if(s===0)return{x:new Int32Array(0),y:new Int32Array(0),value:new Float32Array(0),length:0};const o=n.int32(),r=n.int32(),i=n.int8()===0,a=t>8?n.int8()===0:!0,c=t>8?n.int8()===0:!0,u=n.int8();if(u!==1&&u!==2)throw new T("format",`A block of this .hic is in encoding ${u}, and the format has two: 1, a list of rows, and 2, a dense rectangle. The file is corrupt, or was written by a tool this reader has not seen.`,{type:u});const l=i?2:4,h=u===1?(a?2:4)+l:l,f=It(s,{format:dt,field:"record count of a block",ceiling:rr,available:n.remaining,bytesPerItem:h});let d=new Int32Array(f),m=new Int32Array(f),g=new Float32Array(f),p=0;const w=()=>i?n.int16():n.float32();if(u===1){const A=It(c?n.int16():n.int32(),{format:dt,field:"row count of a block",ceiling:ds,available:n.remaining,bytesPerItem:(c?2:4)+(a?2:4)});for(let N=0;N<A;N++){const I=r+(c?n.int16():n.int32()),M=It(a?n.int16():n.int32(),{format:dt,field:"column count of a block row",ceiling:ds,available:n.remaining,bytesPerItem:h});for(let x=0;x<M;x++){const v=o+(a?n.int16():n.int32()),S=w();(i?S===-32768:!Number.isFinite(S))||(p===d.length&&([d,m,g]=zi(d,m,g,n.remaining,h)),d[p]=v,m[p]=I,g[p]=S,p+=1)}}return{x:d,y:m,value:g,length:p}}const b=It(n.int32(),{format:dt,field:"cell count of a dense block",ceiling:ds,available:n.remaining-2,bytesPerItem:l}),y=n.int16();if(b>0&&!(y>=1))throw new T("format",`A dense block of this .hic is ${y} bins wide, which no rectangle is. The file is truncated, corrupt, or not the format its first bytes claim.`,{width:y});for(let A=0;A<b;A++){const N=w();if(i?N===-32768:!Number.isFinite(N))continue;const I=Math.floor(A/y);p===d.length&&([d,m,g]=zi(d,m,g,n.remaining,h)),d[p]=o+(A-I*y),m[p]=r+I,g[p]=N,p+=1}return{x:d,y:m,value:g,length:p}}function zi(e,t,n,s,o){const r=e.length,i=Math.floor(Math.max(0,s)/o)+1,a=r+Math.min(Math.max(r,1024),i);if(a>rr)throw new T("format",`A block of this .hic holds more than ${rr.toLocaleString("en-US")} records, more than any real one. The file is corrupt, or not the format its first bytes claim.`,{records:a});const c=new Int32Array(a),u=new Int32Array(a),l=new Float32Array(a);return c.set(e),u.set(t),l.set(n),[c,u,l]}const ir=48<<20,qi=4,ef=6,nf=64<<20,Ui=28,Vn=65536,Xn=16<<20,sf=4096,of=ir/2,rf=1024,Gi=["SCALE","KR","INTER_KR","GW_KR","VC_SQRT","VC"],ye="BP";class Hi{free;waiting=[];constructor(t){this.free=Math.max(1,t)}async run(t){this.free>0?this.free-=1:await new Promise(n=>this.waiting.push(n));try{return await t()}finally{const n=this.waiting.shift();n===void 0?this.free+=1:n()}}}class Or{header;footer;chroms;binSize;resolutions;chromOffset;nBins;normType;source;fileIndex;zooms=new Map;zoomsInFlight=new Map;beyondHead=!1;blockCache=new Map;blockCacheBytes=0;normCache=new Map;normFallbacks=new Map;exactSlots;backgroundSlots;constructor(t,n,s,o){this.source=t,this.header=n,this.footer=s;const r=[],i=[];n.chroms.forEach((c,u)=>{c.name.toLowerCase()!=="all"&&(r.push(c),i.push(u))}),this.chroms=r,this.fileIndex=Int32Array.from(i),this.resolutions=[...n.bpResolutions].sort((c,u)=>c-u),this.binSize=o,this.chromOffset=new Float64Array(r.length+1);for(let c=0;c<r.length;c++)this.chromOffset[c+1]=this.chromOffset[c]+Math.ceil(r[c].length/o);this.nBins=this.chromOffset[r.length];const a=this.walkAhead();this.exactSlots=new Hi(a===qi?ef:a),this.backgroundSlots=new Hi(a),this.normType=Gi.find(c=>r.some((u,l)=>s.normVectors.has(or(c,this.fileIndex[l],ye,o))))??null}static open(t,n={}){const s=zh(t),o=Uh(t,s),r=[...s.bpResolutions].sort((a,c)=>a-c);if(r.length===0)throw new T("unsupported","This .hic carries no base-pair resolutions. Fragment-resolution matrices are variable-bin and are excluded from this viewer.",{});const i=n.binSize??Eu(r);if(!r.includes(i))throw new T("unsupported",`This .hic has no ${i} bp resolution. It offers ${r.join(", ")}.`,{binSize:i,available:r});return new Or(t,s,o,i)}stats(){return this.source.stats()}fileIndexOf(t){return this.fileIndex[t]}chromExtent(t){return[this.chromOffset[t],this.chromOffset[t+1]]}chromAt(t){let n=0,s=this.chroms.length-1;for(;n<s;){const o=n+s+1>>1;this.chromOffset[o]<=t?n=o:s=o-1}return n}chromsSpanning(t){const n=[];if(t[1]<=t[0])return n;const s=this.chromAt(t[0]),o=this.chromAt(Math.min(t[1]-1,this.nBins-1));for(let r=s;r<=o;r++)n.push(r);return n}totalCount(){let t=0;for(const n of this.footer.masterIndex.keys()){const s=this.zoomAt(n);s!==null&&(t+=s.sumCounts)}return t}weights(t,n){const s=new Float64Array(Math.max(0,n-t)).fill(Number.NaN);if(this.normType===null||n<=t)return s;for(const o of this.chromsSpanning([t,n])){const r=this.normVector(o);if(r===null)continue;const i=this.chromOffset[o],a=Math.max(t,i),c=Math.min(n,this.chromOffset[o+1]);for(let u=a;u<c;u++){const l=u-i;s[u-t]=l<r.length?r[l]:Number.NaN}}return s}normVector(t){if(this.normCache.has(t))return this.normCache.get(t)??null;let n=null;if(this.normType!==null){const s=this.normType,o=[s,...Gi.filter(r=>r!==s)];for(const r of o){const i=this.footer.normVectors.get(or(r,this.fileIndex[t],ye,this.binSize));if(i===void 0)continue;const a=Qh(this.source,this.header.version,i);if(a.some(c=>Number.isFinite(c))){n=a,r!==s&&this.normFallbacks.set(t,r);break}}}return this.normCache.set(t,n),n}normTypeFor(t){return this.normType===null||(this.normCache.has(t)||this.normVector(t),(this.normCache.get(t)??null)===null)?null:this.normFallbacks.get(t)??this.normType}zoomAt(t){if(this.zooms.has(t))return this.zooms.get(t)??null;const n=this.footer.masterIndex.get(t);let s=null;if(n!==void 0){const o=Wh((r,i)=>this.source.readBytes(r,i),n,ye,this.binSize,this.beyondHead?0:No);s=this.fitted(t,o.zoom),o.beyondHead&&(this.beyondHead=!0)}return this.zooms.set(t,s),s}fitted(t,n){if(n===null)return null;let s=0;for(const o of n.blocks.values())s+=Math.max(0,o.size);if(!(s<=this.source.size))throw new T("format",`The ${this.binSize} bp blocks of this .hic's ${t} matrix claim ${s.toLocaleString("en-US")} bytes between them, more than the whole file's ${this.source.size.toLocaleString("en-US")}. The file is corrupt, or not the format its first bytes claim.`,{key:t,binSize:this.binSize,bytes:s,size:this.source.size});return n}zoomAtSparse(t){if(this.zooms.has(t))return Promise.resolve(this.zooms.get(t)??null);const n=this.zoomsInFlight.get(t);if(n!==void 0)return n;const s=this.footer.masterIndex.get(t);if(s===void 0||this.source.readExact===void 0)return Promise.resolve(this.zoomAt(t));const o=Yh((r,i)=>this.exactRead(r,i),s,ye,this.binSize,this.beyondHead?0:No).then(r=>{r.beyondHead&&(this.beyondHead=!0);const i=this.fitted(t,r.zoom);return this.zooms.set(t,i),i}).finally(()=>this.zoomsInFlight.delete(t));return this.zoomsInFlight.set(t,o),o}zoomFor(t,n){return this.zoomAt(this.pairKey(t,n))}pairKey(t,n){return`${this.fileIndex[t]}_${this.fileIndex[n]}`}walkAhead(){let t=0;for(let s=0;s<this.chroms.length;s++)t=Math.max(t,this.chromOffset[s+1]-this.chromOffset[s]);const n=Math.max(1,t*t*Ui);return Math.max(1,Math.min(qi,Math.floor(nf/n)))}walkPlans(t){const n=[];let s=[],o=0;for(const r of t){const i=this.binsOf(r[0])*this.binsOf(r[1])*Ui;s.length>0&&(o+i>of||s.length>=rf)&&(n.push(s),s=[],o=0),s.push(r),o+=i}return s.length>0&&n.push(s),n}async prefetchWalk(t,n={}){if(this.source.readExact===void 0)return!0;const s=[],o=new Set;for(const h of t){const f=this.pairKey(Math.min(h.a,h.b),Math.max(h.a,h.b));if(o.has(f)||this.zooms.has(f))continue;o.add(f);const d=this.footer.masterIndex.get(f);d===void 0?this.zooms.set(f,null):s.push(d)}const r=[];for(const h of s){const f=this.beyondHead?h.size:Math.min(h.size,No);r.push({position:h.position,size:f,entry:h,head:!0});const d=h.position+h.size,m=Math.min(sf,this.source.size-d);m>0&&r.push({position:d,size:m,entry:h,head:!1})}const i=new Map,a=[];if(!await this.fetchRuns(Yn(r,Vn,Xn),n,(h,f)=>{for(const d of h.refs){const m=d.position-h.position,g=f.subarray(m,m+d.size);if(!d.head){i.set(d.entry.key,{position:d.position,bytes:g.slice()});continue}const{entry:p}=d;try{const w=d.size===p.size?Je(g,p,ye,this.binSize):Ws(g,ye,this.binSize,p.size);this.zooms.set(p.key,this.fitted(p.key,w))}catch(w){if(!(w instanceof jt))throw w;this.beyondHead=!0,a.push({position:p.position,size:p.size,entry:p})}}})||a.length>0&&!await this.fetchRuns(Yn(a,Vn,Xn),n,(f,d)=>{for(const m of f.refs){const g=m.position-f.position,p=Je(d.subarray(g,g+m.size),m.entry,ye,this.binSize);this.zooms.set(m.entry.key,this.fitted(m.entry.key,p))}}))return!1;const u=[],l=new Set;for(const h of t){const f=this.windowOf(h.a,h.b,h.rows,h.cols);if(f===null)continue;const d=this.pairKey(f.low,f.high),m=this.zooms.get(d);if(m==null)continue;const g=i.get(d);for(const p of Pi(m,this.header.version,f.intra,f.lowSpan,f.highSpan)){const w=m.blocks.get(p);if(w===void 0||w.size<=0)continue;const b=this.blockKey(w);if(l.has(b)||this.blockCache.has(b))continue;l.add(b),this.checkBlock(w);const y=g===void 0?-1:w.position-g.position;g!==void 0&&y>=0&&y+w.size<=g.bytes.byteLength?await this.decode(w,g.bytes.subarray(y,y+w.size)):u.push(w)}}return this.fetchRuns(Yn(u,Vn,Xn),n,async(h,f)=>{for(const d of h.refs){const m=d.position-h.position;await this.decode(d,f.subarray(m,m+d.size))}})}async fetchRuns(t,n,s){let o=!1;return await Promise.all(t.map(async r=>{await n.pause?.();const i=()=>this.exactSlots.run(async()=>o||n.cancelled?.()===!0?(o=!0,null):this.readExactNow(r.position,r.length)),a=n.pause===void 0?await i():await this.backgroundSlots.run(i);a!==null&&await s(r,a)})),!o}exactRead(t,n){return this.exactSlots.run(()=>this.readExactNow(t,n))}readExactNow(t,n){const s=this.source,o=s.readExact;return o===void 0?Promise.resolve(s.readBytes(t,n)):o.call(s,t,n)}binsOf(t){return this.chromOffset[t+1]-this.chromOffset[t]}hasAnyMatrix(){for(let t=0;t<this.chroms.length;t++)if(this.zoomFor(t,t)!==null)return!0;return!1}indexedPairs(){const t=new Map;this.fileIndex.forEach((o,r)=>t.set(o,r));const n=new Set,s=[];for(const o of this.footer.masterIndex.keys()){const[r,i]=o.split("_").map(h=>Number.parseInt(h,10)),a=t.get(r),c=t.get(i);if(a===void 0||c===void 0)continue;const u=a<=c?[a,c]:[c,a],l=`${u[0]}_${u[1]}`;n.has(l)||(n.add(l),s.push(u))}return s.sort((o,r)=>o[0]-r[0]||o[1]-r[1]),s}async pairRecords(t,n,s,o,r=!1){const[i,a]=t<=n?[t,n]:[n,t],c=r?await this.zoomAtSparse(this.pairKey(i,a)):this.zoomFor(i,a);if(c===null)return null;const u=this.windowOf(t,n,s,o);if(u===null)return null;const{intra:l,lowSpan:h,highSpan:f}=u,d=Pi(c,this.header.version,l,h,f),m=this.chromOffset[i],g=this.chromOffset[a];let p=0;const w=await this.blocks(c,d,r);for(const I of w)p+=I.length;if(p===0)return null;const b=new Int32Array(p),y=new Int32Array(p),A=new Float64Array(p);let N=0;for(const I of w)for(let M=0;M<I.length;M++){const x=m+I.x[M],v=g+I.y[M];x<=v?(b[N]=x,y[N]=v):(b[N]=v,y[N]=x),A[N]=I.value[M],N+=1}return{bin1:b,bin2:y,count:A,length:N}}windowOf(t,n,s,o){const[r,i]=t<=n?[t,n]:[n,t],a=r===i,[c,u]=a?[this.clipSpan(r,s),this.clipSpan(r,o)]:[this.localSpan(r,s,o),this.localSpan(i,s,o)];return c===null||u===null?null:{low:r,high:i,intra:a,lowSpan:c,highSpan:u}}clipSpan(t,n){const s=this.chromOffset[t],o=Math.max(n[0],s),r=Math.min(n[1],this.chromOffset[t+1]);return r>o?[o-s,r-s]:null}localSpan(t,n,s){const o=this.chromOffset[t],r=this.chromOffset[t+1];let i=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const c of[n,s]){const u=Math.max(c[0],o),l=Math.min(c[1],r);l<=u||(i=Math.min(i,u-o),a=Math.max(a,l-o))}return Number.isFinite(i)?[i,a]:null}async blocks(t,n,s){const o=new Map,r=[];for(const a of n){const c=t.blocks.get(a);if(c===void 0||c.size<=0)continue;const u=this.held(c);if(u!==void 0){o.set(a,u);continue}this.checkBlock(c),r.push(c)}if(s&&this.source.readExact!==void 0)for(const a of Yn(r,Vn,Xn)){const c=await this.exactRead(a.position,a.length);for(const u of a.refs){const l=u.position-a.position;o.set(u.number,await this.decode(u,c.subarray(l,l+u.size)))}}else for(const a of r)o.set(a.number,await this.decode(a,this.source.readBytes(a.position,a.size)));const i=[];for(const a of n){const c=o.get(a);c!==void 0&&i.push(c)}return i}checkBlock(t){Ks(t.position,t.size,{format:dt,field:`block ${t.number} of the ${this.binSize} bp matrix`,size:this.source.size,ceiling:Di.ceiling})}held(t){const n=this.blockKey(t),s=this.blockCache.get(n);if(s!==void 0)return this.blockCache.delete(n),this.blockCache.set(n,s),s}async decode(t,n){const s=await Tr(n,{format:dt,field:`block ${t.number} of the ${this.binSize} bp matrix`,encoding:"deflate",maxBytes:pl(n.byteLength,Di)}),o=jh(s,this.header.version);return this.remember(this.blockKey(t),o),o}blockKey(t){return`${this.binSize}/${t.position}`}remember(t,n){const s=n.x.byteLength+n.y.byteLength+n.value.byteLength;if(!(s>ir)){this.blockCache.set(t,n),this.blockCacheBytes+=s;for(const o of this.blockCache.keys()){if(this.blockCacheBytes<=ir)break;const r=this.blockCache.get(o);r!==void 0&&(this.blockCacheBytes-=r.x.byteLength+r.y.byteLength+r.value.byteLength),this.blockCache.delete(o)}}}close(){this.zooms.clear(),this.blockCache.clear(),this.normCache.clear(),this.blockCacheBytes=0}}function Qi(e){throw new T("unsupported",`A .hic has no ${e}: it is indexed per chromosome pair and per block, not as one sorted pixel table. Read pixels through PixelStore (metacooler/store.ts), which is the seam that exists for exactly this difference.`,{path:e})}function af(e,t){const n=()=>en(t.chroms.length,["name","length"],{name:t.chroms.map(o=>o.name),length:Float64Array.from(t.chroms,o=>o.length)}),s={format:"HIC","format-url":"https://github.com/aidenlab/juicer/wiki/Data-structure","format-version":t.header.version,"bin-size":t.binSize,"bin-type":"fixed",ordering:"genome-then-length","storage-mode":"symmetric-upper",assembly:t.header.genomeId,nbins:t.nBins,ncontigs:t.chroms.length,nnz:null,sum:null,ngenomes:null,...t.header.attributes,...t.normType===null?{}:{"hic-normalisation":t.normType}};return{uri:e,group:"/",rootEntries:t.resolutions.map(o=>String(o)),rootEntryGroup:"resolutions",attrs:()=>({...s}),attrsAt:o=>o===""||o==="/"?{...s}:{},has(o){return o==="bins/weight"?t.normType!==null:["chroms","chroms/name","chroms/length","indexes","pixels","bins"].includes(o)},keys(o){return o===""||o==="/"?["chroms","bins","pixels","indexes"]:o==="chroms"?["name","length"]:o==="pixels"?["bin1_id","bin2_id","count"]:o==="bins"?t.normType===null?[]:["weight"]:[]},isSoftLink:()=>!1,datasetLength(o){return o==="chroms/name"||o==="chroms/length"?t.chroms.length:o==="bins/weight"?t.nBins:(o.startsWith("pixels/"),0)},dtype(o){return o==="pixels/count"?"<f":o==="chroms/length"?"<i":o==="chroms/name"?"S":"<d"},readNumeric(o,r=0,i){if(o==="indexes/chrom_offset")return t.chromOffset.slice();if(o==="chroms/length"){const a=i??t.chroms.length;return Float64Array.from(t.chroms.slice(r,a),c=>c.length)}if(o==="bins/weight"){if(t.normType===null)throw new T("unsupported","This .hic carries no normalisation vectors, so there are no weights to balance with. Re-run Juicer Tools `addNorm`, or view the raw counts.",{});return t.weights(r,i??t.nBins)}throw(o==="indexes/bin1_offset"||o.startsWith("pixels/"))&&Qi(o),new T("unsupported",`A .hic has no ${o}.`,{path:o})},readInt32(o){throw o.startsWith("pixels/")&&Qi(o),new T("unsupported",`A .hic has no ${o}.`,{path:o})},readStrings(o,r=0,i){if(o==="chroms/name")return t.chroms.slice(r,i??t.chroms.length).map(a=>a.name);throw new T("unsupported",`A .hic has no ${o}.`,{path:o})},readTable(o){if(o==="chroms"||o==="contigs")return n();throw new T("unsupported",`A .hic has no /${o} table.`,{path:o})},at(o){throw new T("unsupported",`A .hic has no /${o} group to open.`,{path:o})},close:()=>t.close()}}function cf(e,t){return e*1e6+t}class lf{constructor(t){this.file=t}nnz=null;countKind="f";rectangular=!0;scoreColumns(){return["count"]}binOffsets(){throw new T("unsupported","A .hic has no per-bin pixel index, so the stored-pixel density column cannot be computed for one. It is a metagenome diagnostic and a .hic has no genomes, so nothing that draws asks for it.",{})}async forEachWindow(t,n,s,o,r={}){this.refuseOtherColumns(r.value);const i=this.pairsFor(t,n),a=i.length>1;return this.walk(i,(c,u)=>this.file.pairRecords(c,u,t,n,a),o,r,()=>[t,n])}async forEachBands(t,n,s={}){this.refuseOtherColumns(s.value);const o=new Set;for(const u of t)for(const l of this.file.chromsSpanning(u))o.add(l);const r=[0,this.file.nBins],i=this.file.indexedPairs().filter(([u])=>o.has(u)),a=i.length>1,c=u=>{const l=this.clipTo(u,t);return l===null?null:[l,r]};return this.walk(i,(u,l)=>{const h=c(u);return h===null?Promise.resolve(null):this.file.pairRecords(u,l,h[0],h[1],a)},n,s,c)}async scanAll(t){const n=[0,this.file.nBins],s=this.file.indexedPairs(),o=s.length>1;await this.inOrder(s,(r,i)=>this.file.pairRecords(r,i,n,n,o),(r,i)=>{const a=r!==null&&t.onChunk(r)===!1;return t.onProgress?.(i,s.length),!a},void 0,t.pause,()=>[n,n])}pairsFor(t,n){const s=this.file.chromsSpanning(t),o=this.file.chromsSpanning(n),r=new Set,i=[];for(const a of s)for(const c of o){const u=a<=c?[a,c]:[c,a],l=cf(u[0],u[1]);r.has(l)||(r.add(l),i.push(u))}return i}clipTo(t,n){const[s,o]=this.file.chromExtent(t);let r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const a of n){const c=Math.max(a[0],s),u=Math.min(a[1],o);u<=c||(r=Math.min(r,c),i=Math.max(i,u))}return Number.isFinite(r)?[r,i]:null}walk(t,n,s,o,r){return this.inOrder(t,n,(i,a)=>(i!==null&&i.length>0&&s(i),o.onProgress?.(a,t.length),!0),()=>o.cancelled?.()===!0,void 0,r)}async inOrder(t,n,s,o,r,i){const a=t.length>1?this.file.walkAhead():1,c=this.planned(t,o,r,i),u=[];let l=0,h=0;for(;h<t.length;){if(await(r?.()??xt()),o?.()===!0)return!1;for(;u.length<a&&l<t.length;){const[d,m]=t[l],g=c(l).then(p=>p?n(d,m):null);l+=1,g.catch(()=>{}),u.push(g)}const f=await u.shift();if(h+=1,!s(f,h))return!1}return!0}planned(t,n,s,o){if(t.length<2||o===void 0)return()=>Promise.resolve(!0);const r=this.file.walkPlans(t),i=[];r.forEach((c,u)=>c.forEach(()=>i.push(u)));const a=new Map;return c=>{const u=i[c];let l=a.get(u);if(l===void 0){const h=r[u].flatMap(([f,d])=>{const m=o(f,d);return m===null?[]:[{a:f,b:d,rows:m[0],cols:m[1]}]});l=this.file.prefetchWalk(h,{pause:s,cancelled:n}),a.set(u,l)}return l}}refuseOtherColumns(t){if(!(t===void 0||t==="count"))throw new T("unsupported",`A .hic stores one value per record, so there is no '${t}' column to draw. Extra per-pixel columns are a cooler feature.`,{value:t})}}const Lr=4<<20,_r=12,uf=65536;function Ml(e){return e.length>=2&&e[0]===31&&e[1]===139}function Il(e,t=0){return e.length<t+_r||e[t]!==31||e[t+1]!==139||e[t+2]!==8||(e[t+3]&4)===0?!1:Dr(e,t)!==null}function Dr(e,t=0){if(e.length<t+_r)return null;const n=new DataView(e.buffer,e.byteOffset,e.byteLength),s=n.getUint16(t+10,!0);let o=t+12;const r=Math.min(o+s,e.length);for(;o+4<=r;){const i=e[o],a=e[o+1],c=n.getUint16(o+2,!0);if(i===66&&a===67&&c===2)return n.getUint16(o+4,!0)+1;o+=4+c}return null}async function xl(e){return e.length===0?e:Tr(e,{format:"BGZF file",field:"member",encoding:"deflate-raw",maxBytes:uf})}function hf(e,t,n){return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t+n-4,!0)}function ff(e,t,n){const o=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(t+10,!0);return e.subarray(t+12+o,t+n-8)}function Rr(e,t={}){const n=e.readBytes(0,Math.min(e.size,64));return Il(n)?mf(e,t):Ml(n)?Ki(e,t,df).pipeThrough(new DecompressionStream("gzip")):Ki(e,t,Lr)}const df=65536;function Ki(e,t,n){const s=t.from??0,o=Math.min(t.to??e.size,e.size),r=Math.max(0,o-s);let i=s,a=0;return new ReadableStream({pull(c){if(t.cancelled?.()===!0||i>=o){c.close();return}const u=e.readBytes(i,Math.min(Lr,o-i));if(u.length===0){c.close();return}i+=u.length,a+=u.length;for(let l=0;l<u.length;l+=n)c.enqueue(u.subarray(l,Math.min(l+n,u.length)));t.onProgress?.(a,r)}})}function mf(e,t){const n=t.from??0,s=Math.min(t.to??e.size,e.size),o=Math.max(0,s-n);let r=n,i=0,a=new Uint8Array(0),c=!1;const u=l=>{t.onFraming?.({partialMember:a.length>0,endedOnEofMarker:c}),l.close()};return new ReadableStream({async pull(l){for(;;){if(t.cancelled?.()===!0){l.close();return}const h=a.length>=_r?Dr(a):null;if(h!==null&&a.length>=h){const d=ff(a,0,h),m=hf(a,0,h);if(a=a.subarray(h),c=m===0,m>0){l.enqueue(await xl(d));return}continue}if(r>=s){u(l);return}const f=e.readBytes(r,Math.min(Lr,s-r));if(f.length===0){u(l);return}if(r+=f.length,i+=f.length,t.onProgress?.(i,o),a.length===0)a=f.slice();else{const d=new Uint8Array(a.length+f.length);d.set(a),d.set(f,a.length),a=d}}}})}async function Pr(e,t,n){const s=e.getReader();let o=[],r=0;const i=a=>{if(r===0)return a;const c=new Uint8Array(r+a.length);let u=0;for(const l of o)c.set(l,u),u+=l.length;return c.set(a,u),o=[],r=0,c};try{for(;;){if(n?.()===!0)return!1;const{done:a,value:c}=await s.read();if(a)break;let u=0;for(let l=c.indexOf(10);l>=0;l=c.indexOf(10,u)){const h=i(c.subarray(u,l)),f=h.length>0&&h[h.length-1]===13?h.length-1:h.length;t(h.subarray(0,f)),u=l+1}if(u<c.length&&(o.push(c.slice(u)),r+=c.length-u,r>Mo))throw new T("format",`A line of this .pairs file runs past ${Mo>>20} MiB without ending, and no pairs line is that long. The file is corrupt, or is not a .pairs file.`,{maxLineBytes:Mo})}return r>0&&t(i(new Uint8Array(0))),!0}finally{s.releaseLock()}}const Mo=64<<20,gf=["readID","chr1","pos1","chr2","pos2","strand1","strand2"],Jn={chrom1:["chr1","chrom1","chromosome1"],pos1:["pos1","position1"],chrom2:["chr2","chrom2","chromosome2"],pos2:["pos2","position2"]},Wi={strand1:["strand1","strand_1"],strand2:["strand2","strand_2"]},pf=["pair_type","pairtype"],wf=64<<20,bf=64,Af=65536;function vl(e){return/^##\s*pairs\s+format/i.test(e)}async function yf(e){let t=null;try{await Pr(Rr(e,{to:Nf(e)}),n=>{t??=new TextDecoder().decode(n)},()=>t!==null)}catch{}return t!==null&&vl(t)}function Nf(e){const t=e.readBytes(0,Math.min(e.size,bf));if(Il(t)){const n=Dr(t);if(n!==null)return Math.min(e.size,n)}return Math.min(e.size,Af)}async function Ys(e){const t=[],n=new Set,s=[];let o=null,r=null,i=null,a=null,c=null,u=0,l=!1;const h=new TextDecoder,f=Rr(e,{to:Math.min(e.size,wf)});if(await Pr(f,d=>{if(l)return;if(u+=d.length+1,d.length===0||d[0]!==35){l=!0;return}const m=h.decode(d);if(s.push(m),o===null&&vl(m)){o=m.replace(/^##\s*/,"").trim();return}const g=m.indexOf(":");if(g<0)return;const p=m.slice(1,g).trim().toLowerCase(),w=m.slice(g+1).trim();if(p==="chromsize"||p==="chromosome"){const b=w.split(/\s+/);b.length>=2&&Yi(t,n,b[0],Number(b[1]))}else if(p==="samheader"){const b=/^@SQ\s.*\bSN:(\S+).*\bLN:(\d+)/.exec(w);b!==null&&Yi(t,n,b[1],Number(b[2]))}else p==="genome_assembly"?r=w:p==="sorted"?i=w:p==="shape"?a=w:p==="columns"&&(c=w.split(/\s+/).filter(b=>b!==""))},()=>l).catch(()=>!1),o===null)throw new T("format","This file does not begin with a `## pairs format` line, so it is not a 4DN pairs file. If it is a headerless contact list, add a header with `pairtools header generate`, or bin it with `cooler cload pairs` and open the cooler.",{bytesRead:u});if(t.length===0)throw new T("format","This .pairs file declares no `#chromsize:` lines, so there is no bin table to build. Chromosome sizes cannot be inferred from the records — a grid guessed from the largest coordinate seen would differ between two subsamples of the same library. Add them with `pairtools header generate --chroms-path <chrom.sizes>`.",{contigs:0});return{version:o,assembly:r,sorted:i,shape:a,contigs:t,columns:Mf(c??gf,c!==null),text:s.join(`
|
|
2
|
+
`)}}function Yi(e,t,n,s){t.has(n)||!Number.isFinite(s)||s<=0||(t.add(n),e.push({name:n,length:s}))}function Mf(e,t){const n=e.map(i=>i.toLowerCase()),s=i=>{for(const a of i){const c=n.indexOf(a);if(c>=0)return c}return-1},o={chrom1:s(Jn.chrom1),pos1:s(Jn.pos1),chrom2:s(Jn.chrom2),pos2:s(Jn.pos2),strand1:s(Wi.strand1),strand2:s(Wi.strand2),pairType:s(pf)},r=["chrom1","pos1","chrom2","pos2"].filter(i=>o[i]<0);if(r.length>0)throw new T("unsupported",`This .pairs file's ${t?"`#columns:` line":"assumed column layout"} has no ${r.join(", ")} column. It declares ${e.join(", ")}. The importer needs two chromosome columns and two position columns.`,{missing:r,columns:[...e]});return o}function kl(e,t){const n=new Float64Array(e.length+1);let s=0;for(let o=0;o<e.length;o++)n[o]=s,s+=Math.ceil(e[o].length/t);return n[e.length]=s,n}function Sl(e,t){let n=0;for(const s of e)n+=Math.ceil(s.length/t);return n}function Vi(e){throw new T("unsupported",`A map binned from a .pairs file serves ${e} through PixelStore (metacooler/store.ts), not through the handle. Reaching for the column by name bypasses the chunking and the cancellation every other read has.`,{path:e})}function If(e){const{header:t,pixels:n}=e,s=()=>en(n.contigs.length,["name","length"],{name:n.contigs.map(r=>r.name),length:Float64Array.from(n.contigs,r=>r.length)}),o={format:"PAIRS","format-url":"https://github.com/4dn-dcic/pairix/blob/master/pairs_format_specification.md","format-version":xf(t.version),"bin-size":n.binSize,"bin-type":"fixed","contig-ordering":"genome-then-length","storage-mode":"symmetric-upper","genome-assembly":t.assembly,nbins:n.nBins,nchroms:n.contigs.length,nnz:n.nnz,sum:n.sum,ngenomes:null,"pairs-source":e.uri,"pairs-header":t.text,"pairs-sorted":t.sorted,"pairs-shape":t.shape,"pairs-indexed":e.indexed,"pairs-records":n.sum,...e.declaredRecords==null?{}:{"pairs-declared-records":e.declaredRecords},...n.skippedUnknownContig===0?{}:{"pairs-skipped-unknown-contig":n.skippedUnknownContig},...n.skippedBadPosition===0?{}:{"pairs-skipped-bad-position":n.skippedBadPosition},...n.clampedPosition===0?{}:{"pairs-clamped-positions":n.clampedPosition},...n.wasUnsorted?{"pairs-required-merge":!0}:{},...n.truncated?{"pairs-truncated":!0}:{},...n.contigsWithoutCisContacts.length===0?{}:{"pairs-sequences-without-cis-contacts":n.contigsWithoutCisContacts.join(", ")}};return{uri:e.uri,group:"/",rootEntries:e.rungs.map(r=>String(r)),rootEntryGroup:"resolutions",attrs:()=>({...o}),attrsAt:r=>r===""||r==="/"?{...o}:{},has(r){return["chroms","chroms/name","chroms/length","contigs","indexes","indexes/chrom_offset","pixels","pixels/count","bins"].includes(r)},keys(r){return r===""||r==="/"?["chroms","bins","pixels","indexes"]:r==="chroms"||r==="contigs"?["name","length"]:r==="pixels"?["bin1_id","bin2_id","count"]:r==="indexes"?["chrom_offset"]:r==="bins"?[]:[]},isSoftLink:()=>!1,datasetLength(r){return r==="chroms/name"||r==="chroms/length"?n.contigs.length:r==="indexes/chrom_offset"?n.contigs.length+1:r.startsWith("pixels/")?n.nnz:0},dtype(r){return r==="pixels/count"||r==="pixels/bin1_id"||r==="pixels/bin2_id"||r==="chroms/length"?"<i":r==="chroms/name"?"S":"<d"},readNumeric(r,i=0,a){if(r==="indexes/chrom_offset")return n.chromOffset.slice();if(r==="chroms/length"){const c=a??n.contigs.length;return Float64Array.from(n.contigs.slice(i,c),u=>u.length)}throw r==="bins/weight"?new T("unsupported","A map binned from a .pairs file carries raw counts and no balancing weights: nothing has been balanced. Export the .mcool and run `cooler balance` on it, or open a cooler that was written with weights.",{}):((r==="indexes/bin1_offset"||r.startsWith("pixels/"))&&Vi(r),new T("unsupported",`An imported .pairs map has no ${r}.`,{path:r}))},readInt32(r){throw r.startsWith("pixels/")&&Vi(r),new T("unsupported",`An imported .pairs map has no ${r}.`,{path:r})},readStrings(r,i=0,a){if(r==="chroms/name")return n.contigs.slice(i,a??n.contigs.length).map(c=>c.name);throw new T("unsupported",`An imported .pairs map has no ${r}.`,{path:r})},readTable(r){if(r==="chroms"||r==="contigs")return s();throw new T("unsupported",`An imported .pairs map has no /${r} table.`,{path:r})},at(r){throw new T("unsupported",`An imported .pairs has no /${r} group to open.`,{path:r})},close:()=>{}}}function xf(e){const t=/v?(\d+)(?:\.(\d+))?/.exec(e);return t===null?null:Number(t[1])}const Xi=1<<20;class vf{constructor(t){this.pixels=t}offsets=null;get nnz(){return this.pixels.nnz}countKind="i";scoreColumns(){return["count"]}binOffsets(){if(this.offsets!==null)return this.offsets;const{bin1:t,nnz:n,nBins:s}=this.pixels,o=new Float64Array(s+1);let r=0;for(let i=0;i<s;i++){for(;r<n&&t[r]===i;)r++;o[i+1]=r}return this.offsets=o,o}async forEachWindow(t,n,s,o,r={}){this.refuseOtherColumns(r.value);const i=this.pixelRange(s.span[0],s.span[1]);return this.emit(i[0],i[1],o,r)}async forEachBands(t,n,s={}){this.refuseOtherColumns(s.value);for(const[o,r]of this.mergedBands(t))if(!await this.emit(o,r,n,s))return!1;return!0}async scanAll(t){const n=Math.max(1,Math.trunc(t.chunkSize??Xi)),s=this.pixels.nnz;for(let o=0;o<s;o+=n){const r=Math.min(o+n,s);if(t.onChunk(this.chunk(o,r))===!1)return;t.onProgress?.(r,s),await xt()}}pixelRange(t,n){const s=this.binOffsets(),o=this.pixels.nBins,r=s[Math.max(0,Math.min(o,t))],i=s[Math.max(0,Math.min(o,n))];return[r,Math.max(r,i)]}mergedBands(t){const n=[];for(const[o,r]of t){if(r<=o)continue;const[i,a]=this.pixelRange(o,r);a>i&&n.push([i,a])}n.sort((o,r)=>o[0]-r[0]);const s=[];for(const o of n){const r=s[s.length-1];r!==void 0&&o[0]<=r[1]+ol?r[1]=Math.max(r[1],o[1]):s.push([o[0],o[1]])}return s}async emit(t,n,s,o){const r=Math.max(1,Math.trunc(o.chunkSize??Xi)),i=n-t;for(let a=t;a<n;a+=r){if(o.cancelled?.()===!0)return!1;const c=Math.min(a+r,n);s(this.chunk(a,c)),o.onProgress?.(c-t,i),await xt()}return!0}chunk(t,n){const{bin1:s,bin2:o,count:r}=this.pixels;return{bin1:s.slice(t,n),bin2:o.slice(t,n),count:Float64Array.from(r.subarray(t,n)),length:n-t}}refuseOtherColumns(t){if(!(t===void 0||t==="count"))throw new T("unsupported",`A map binned from a .pairs file stores one value per pixel — the number of contacts — so there is no '${t}' column to draw. Extra per-pixel columns come from a cooler that was written with them.`,{value:t})}}function mn(e,t,n){const s=Math.max(0,Math.min(Math.trunc(t),e)),o=Math.max(s,Math.min(Math.trunc(n??e),e));return[s,o]}function kf(e,t){const{bins:n,pixels:s}=t,o=()=>en(n.names.length,["name","length"],{name:[...n.names],length:n.lengths.slice()}),r={format:"HiC-Pro","format-url":"https://github.com/nservant/HiC-Pro","bin-size":n.binsize,"bin-type":"fixed",ordering:"genome-then-length","storage-mode":"symmetric-upper",nbins:n.nBins,ncontigs:n.names.length,nnz:s.nnz,sum:s.sum,ngenomes:null,"hicpro-matrix":t.matrixName,"hicpro-bins":t.binsName,"hicpro-stored":s.observed};return{uri:e,group:"/",rootEntries:[],rootEntryGroup:"",attrs:()=>({...r}),attrsAt:i=>i===""||i==="/"?{...r}:{},has(i){return["chroms","chroms/name","chroms/length","bins","pixels","pixels/bin1_id","pixels/bin2_id","pixels/count","indexes","indexes/bin1_offset","indexes/chrom_offset"].includes(i)},keys(i){return i===""||i==="/"?["chroms","bins","pixels","indexes"]:i==="chroms"?["name","length"]:i==="pixels"?["bin1_id","bin2_id","count"]:i==="indexes"?["bin1_offset","chrom_offset"]:i==="bins"?[]:[]},isSoftLink:()=>!1,datasetLength(i){return i==="chroms/name"||i==="chroms/length"?n.names.length:i.startsWith("pixels/")?s.nnz:i==="indexes/bin1_offset"?n.nBins+1:i==="indexes/chrom_offset"?n.names.length+1:0},dtype(i){return i==="pixels/count"?"<f":i==="pixels/bin1_id"||i==="pixels/bin2_id"||i==="chroms/length"?"<i":i==="chroms/name"?"S":"<d"},readNumeric(i,a=0,c){if(i==="indexes/chrom_offset")return n.chromOffset.slice();if(i==="indexes/bin1_offset"){const[u,l]=mn(n.nBins+1,a,c);return s.binOffset.slice(u,l)}if(i==="chroms/length"){const[u,l]=mn(n.names.length,a,c);return n.lengths.slice(u,l)}if(i==="pixels/count"){const[u,l]=mn(s.nnz,a,c);return Float64Array.from(s.count.subarray(u,l))}throw i==="bins/weight"?new T("unsupported","A HiC-Pro matrix carries no balancing weights. Its `iced/` matrix is already normalised — open that one instead of balancing this one — and its `.biases` file belongs to the raw matrix, so applying it here would normalise twice.",{path:i}):new T("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readInt32(i,a=0,c){const[u,l]=mn(s.nnz,a,c);if(i==="pixels/bin1_id")return s.bin1.subarray(u,l);if(i==="pixels/bin2_id")return s.bin2.subarray(u,l);throw new T("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readStrings(i,a=0,c){if(i==="chroms/name"){const[u,l]=mn(n.names.length,a,c);return n.names.slice(u,l)}throw new T("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readTable(i){if(i==="chroms"||i==="contigs")return o();throw new T("unsupported",`A HiC-Pro matrix has no /${i} table.`,{path:i})},at(i){throw new T("unsupported",`A HiC-Pro matrix has no /${i} group.`,{path:i})},close:()=>{}}}const Sf={K:1e3,KB:1e3,M:1e6,MB:1e6,G:1e9,GB:1e9};function Jt(e,t={}){throw new T("bad-range",e,t)}function Ji(e){const t=e.replace(/,/g,"").split(/([0-9.]+)/);(t.length!==3||t[0]!=="")&&Jt(`Unexpected token "${e}"`,{token:e});const[,n,s]=t;if(s.length===0)return/^[0-9]+$/.test(n)||Jt(`Unexpected token "${e}"`,{token:e}),Number(n);const o=Number.parseFloat(n);Number.isFinite(o)||Jt(`Unexpected token "${e}"`,{token:e});const r=s.toUpperCase().trim(),i=Sf[r];return i===void 0&&Jt(`Unknown unit '${r}'`,{unit:r}),Math.trunc(o*i)}function Cf(e){const t=/\s*(-)|\s*([0-9,]+(?:\.[0-9]*)?(?:[a-z]+)?)|\s*(.+)/gi,n=[];for(const s of e.matchAll(t)){const o=s[1],r=s[2],i=s[3];o!==void 0?n.push({kind:"HYPHEN",text:o}):r!==void 0?n.push({kind:"COORD",text:r}):n.push({kind:"OTHER",text:i??""})}return n}function zr(e){const t=[];let n="";for(let s=0;s<e.length;s++){const o=e[s];if(o===","&&!Ff(e,s)){t.push(n),n="";continue}n+=o}return t.push(n),t.map(s=>s.trim()).filter(s=>s!=="")}function Ff(e,t){return/[0-9]$/.test(e.slice(0,t))&&/^[0-9]{3}(?![0-9])/.test(e.slice(t+1))}function Vs(e,t={}){const n=e.split(":"),s=n[0].trim();if(s.length===0&&Jt("Chromosome name cannot be empty",{region:e}),n.length<2)return[s,null,null];const o=Cf(n[1]);let r=0;const i=()=>o[r++],a=(h,f)=>(h===void 0&&Jt(`Expected ${f.join(" or ")} token missing`,{region:e}),f.includes(h.kind)||Jt(`Unexpected token "${h.text}"`,{region:e}),h),c=Ji(a(i(),["COORD"]).text);a(i(),["HYPHEN"]);const u=i();if(u===void 0)return[s,c,null];const l=Ji(a(u,["COORD"]).text);return l<c&&t.reversed!==!0&&Jt("End coordinate less than start — unless the sequence joins its own ends, which is a tick in the circular column of the Chromosomes table",{region:e,start:c,end:l}),[s,c,l]}function $f(e,t){const[n,s,o]=Vs(e),r=t.get(n);if(r===void 0)throw new T("unknown-label",`Unknown sequence label: ${n}`,{label:n});const i=s===null?0:s,a=o===null?r:o;return a<i&&Jt("End cannot be less than start",{region:e,start:i,end:a}),(i<0||a>r)&&Jt(`Genomic region out of bounds: [${i}, ${a})`,{region:e,start:i,end:a,length:r}),[n,i,a]}function Ef(e,t,n,s){const o=t.split(":")[0],r=e.genomes===null?[]:e.genomes.strings("name"),i=e.contigs.strings("name");if(r.includes(o)){if(o===Mn)throw new T("unbinned-not-displayable",`Range ${st(t)}: ${st(Mn)} holds every contig that binning failed to assign. It is a bookkeeping row, not a genome — there is no coherent contact map to draw for it — so it cannot be displayed. Its share of the file is reported as a QC statistic in the file info panel.`,{label:o});if(t.includes(":"))throw new T("genome-coordinate-suffix",`Range ${st(t)}: ${st(o)} is a genome name — coordinate suffixes are not allowed for genome ranges. Use just ${st(o)}.`,{label:o,region:t});return{kind:"genome",label:o,extent:e.genomeExtent(o)}}if(i.includes(o))return{kind:"contig",label:o,extent:Zi(e,o,t)};const a=(e.names??Bf(e)).find(o,{from:n});if(a!==null){const c=t.slice(o.length);return{kind:"contig",label:a.name,extent:Zi(e,a.name,`${a.name}${c}`),matched:a}}throw e.genomes===null?new T("unknown-label",`Range ${st(t)}: ${st(o)} is not a sequence of this file.
|
|
3
|
+
Sequences: ${Ke(i)}`,{label:o,region:t}):new T("unknown-label",`Range ${st(t)}: ${st(o)} is not a known genome or contig.
|
|
4
|
+
Genomes: ${Ke(e.displayGenomes().map(c=>r[c]))}
|
|
5
|
+
Contigs: ${Ke(i)}`,{label:o,region:t})}function Zi(e,t,n,s){return e.extent(n)}function Bf(e){const t=e.contigs.strings("name"),n=e.contigs.numbers("length");return ge.of(t.map((s,o)=>({name:s,length:n[o]})))}function Tf(e,t,n,s,o){const r=e[t],i=e[t+1]??r,a=Math.min(r+Math.floor(n/o),i),c=Math.min(r+Math.ceil(s/o),i);return[a,Math.max(a,c)]}const Of=["name","length","n_contigs","n_bins"],Lf=["name","length"],Io=["name","length","genome_id"],_f=["name","length","n_contigs","n_bins"],Df=["bin-size","bin-type","storage-mode"],xo=["nnz","sum"];class wt{uri;layout;entries;entryGroup;tables;info;metadata;genomes;contigs;binsize;unlensed;storageMode;countKind;coords;chromnames;get chromsizes(){return this.chromsizeCache??=new Map(this.chromnames.map((t,n)=>[t,this.contigLengths[n]])),this.chromsizeCache}get contigIds(){return this.contigIdCache??=new Map(this.chromnames.map((t,n)=>[t,n])),this.contigIdCache}get names(){return this.nameIndexCache??=ge.of(this.chromnames.map((t,n)=>({name:t,length:this.contigLengths[n]}))),this.nameIndexCache}genomeNames;contigGenomeIds;rawHandle;get handle(){const t=this.resampled?.weightScale??1;return t===1?this.rawHandle:(this.weighted?.scale!==t&&(this.weighted={scale:t,handle:Rf(this.rawHandle,t)}),this.weighted.handle)}weighted=null;pixelStore;get store(){return this.resampled??this.pixelStore}get storedPixels(){return this.pixelStore}resampled=null;census=null;censusWanted=!1;chromOffset;genomeOffset;genomeIds;closed=!1;fullContigTable=null;fullGenomeTable=null;contigIdCache=null;chromsizeCache=null;nameIndexCache=null;contigLengths;static async open(t,n,s={}){if(await n.mount(),Nl(n.readBytes(0,4)))return wt.fromHic(t,n);if(await yf(n)){const i=await Ys(n);throw new T("pairs-binning-needed","This is a .pairs file: a list of contacts with no resolution of its own. Choose a bin size to build a map at.",{contigs:i.contigs.length,assembly:i.assembly,sorted:i.sorted})}const o=s.metacool===!1?".cool, .mcool or .scool":".cool, .mcool, .scool or .metacool";if(Ml(n.readBytes(0,2)))throw new T("not-hdf5",`This file is gzip-compressed. HDF5 is read in place and cannot be decompressed on the fly, so a ${o} must be decompressed first. A .pairs.gz is read compressed — but this one carries no \`## pairs format\` line, so it is not one.`,{});if(!Gf(n))throw new T("not-hdf5",`${Vt(t).path} does not start with the HDF5 signature, so it is not a ${o} whatever its name says. A download that stopped short, an HTML page saved under the file’s name, or a text matrix look like this.`,{});const r=await Pu(t,n,Vt(t).group);try{return s.listingAgreed!==!0&&qf(r,n),wt.fromHandle(r,s)}catch(i){if(r.close(),!(i instanceof T)&&i instanceof Error){const a=Vt(t).group;throw new T("format",`${Vt(t).path}${a===""?"":`::${a}`} could not be read as a cooler container. HDF5 said: ${i.message}. The file opens as HDF5, so this is a group, dataset or attribute the reader expected and did not find.`,{hdf5:i.message})}throw i}}static fromHic(t,n){const{group:s}=Vt(t),o=/^\/resolutions\/(\d+)$/.exec(s),r=Or.open(n,o===null?{}:{binSize:Number(o[1])});if(!r.hasAnyMatrix())throw new T("unsupported",`This .hic carries no base-pair matrix at ${r.binSize} bp. Its resolutions are ${r.resolutions.join(", ")}.`,{binSize:r.binSize,resolutions:r.resolutions});const i=af(t,r),a=i.attrs();return new wt({uri:t,handle:i,layout:{kind:"hic",group:s,entries:r.resolutions.map(c=>String(c))},attrs:a,contigs:i.readTable("chroms"),chromOffset:i.readNumeric("indexes/chrom_offset"),store:new lf(r)})}static fromPairs(t){const n=If({uri:t.uri,header:t.header,pixels:t.pixels,rungs:t.rungs,indexed:t.indexed,declaredRecords:t.declaredRecords??null});return new wt({uri:t.uri,handle:n,layout:{kind:"pairs",group:`/resolutions/${t.pixels.binSize}`,entries:t.rungs.map(s=>String(s))},attrs:n.attrs(),contigs:n.readTable("chroms"),chromOffset:n.readNumeric("indexes/chrom_offset"),store:new vf(t.pixels)})}static fromScool(t,n,s,o){const r=Ti(n.entries??[],o),i=t.at(vs(n,(n.entries??[])[0])),a=Yc(t,n,s).attrs,c={...s};for(const f of Df)c[f]===void 0&&a[f]!==void 0&&(c[f]=a[f]);const u=i.readNumeric("indexes/chrom_offset"),l=Ni(i.dtype("pixels/count")),h=Number(u[u.length-1]??0);return new wt({uri:t.uri,handle:t,tables:i,layout:n,attrs:c,contigs:i.readTable("chroms",void 0,void 0,Io),chromOffset:u,store:new Wn(t,n,r,h,l)})}static fromHicPro(t,n){if(!n.bins.fixed||n.bins.binsize===null)throw new T("variable-bins",`The viewer supports fixed-bin files only, and ${n.binsName} is not one: its intervals are of differing widths, which is what a fragment-level map (\`GENOME_FRAGMENT\` in HiC-Pro's config) looks like. Re-run HiC-Pro with a \`BIN_SIZE\`, or open the fixed-bin matrix beside this one.`,{"bin-type":"variable","bin-size":null,bins:n.binsName});const s=kf(t,n);return new wt({uri:t,handle:s,layout:{kind:"hicpro",group:"/"},attrs:s.attrs(),contigs:s.readTable("chroms"),chromOffset:n.bins.chromOffset})}static fromHandle(t,n={}){const s=t.attrs(),o=n.metacool===void 0?{}:{metacool:n.metacool},r=Cu(t,s,o);if(Ou(t,r,s,o),r.kind==="scool")return wt.fromScool(t,r,s,null);if(r.kind!=="metacool")return new wt({uri:t.uri,handle:t,layout:r,attrs:s,contigs:t.readTable("chroms",void 0,void 0,Io),chromOffset:t.readNumeric("indexes/chrom_offset")});if(!t.has("indexes/genome_offset"))throw new at("indexes/genome_offset is missing");return new wt({uri:t.uri,handle:t,layout:r,attrs:s,genomes:t.readTable("genomes",void 0,void 0,_f),contigs:t.readTable("contigs",void 0,void 0,Io),chromOffset:t.readNumeric("indexes/chrom_offset"),genomeOffset:t.readNumeric("indexes/genome_offset")})}fullContigs(){return this.fullContigTable??=this.tables.readTable(this.layout.kind==="metacool"?"contigs":"chroms"),this.fullContigTable}fullGenomes(){return this.genomes===null?null:(this.fullGenomeTable??=this.handle.readTable("genomes"),this.fullGenomeTable)}constructor(t){this.uri=t.uri,this.unlensed=t.unlensed??null,this.rawHandle=t.handle,this.tables=t.tables??t.handle,this.layout=t.layout,this.entries=t.handle.rootEntries,this.entryGroup=t.handle.rootEntryGroup,this.genomes=t.genomes??null,this.contigs=t.contigs,this.chromOffset=t.chromOffset,this.genomeOffset=t.genomeOffset??new Float64Array(0),this.info=_u(t.attrs),this.metadata=Du(t.attrs),this.storageMode=this.info["storage-mode"];const n=this.info["bin-size"];if(n===null||n<=0)throw new at(`attrs['bin-size'] must be positive, got ${st(n)}`,{"bin-size":n});this.binsize=n,this.chromnames=this.contigs.strings("name"),this.genomeNames=this.genomes===null?[]:this.genomes.strings("name");const s=Pf(this.contigs,"length");this.contigGenomeIds=this.genomes===null?new Int32Array(0):zf(this.contigs,"genome_id"),this.coords=new Xu(this.binsize,this.chromOffset,s),this.contigLengths=s,this.genomeIds=new Map;for(let o=0;o<this.genomeNames.length;o++)this.genomeIds.set(this.genomeNames[o],o);this.countKind=Ni(this.tables.dtype("pixels/count")),this.pixelStore=t.store??new rl(this.rawHandle,this.nBins,this.countKind),this.validateLight()}get hasGenomes(){return this.genomes!==null}get hasWeights(){return this.handle.has(`bins/${re}`)}get scoreColumns(){return this.store.scoreColumns()}get nGenomes(){return this.genomes?.length??0}get nContigs(){return this.contigs.length}get nBins(){return this.coords.nBins}get shape(){return[this.nBins,this.nBins]}hasGenome(t){return this.genomeIds.has(t)}hasContig(t){return this.contigIds.has(t)}genomeId(t){const n=this.genomeIds.get(t);if(n===void 0)throw new T("unknown-label",`Genome ${st(t)} not found. Available: ${Ke(this.displayGenomes().map(s=>this.genomeNames[s]))}`,{label:t});return n}contigId(t){const n=this.contigIds.get(t);if(n===void 0)throw new T("unknown-label",`Contig ${st(t)} not found. Available: ${Ke(this.chromnames)}`,{label:t});return n}extent(t){const[n,s,o]=$f(t,this.chromsizes);return Tf(this.chromOffset,this.contigId(n),s,o,this.binsize)}offset(t){return this.extent(t)[0]}genomeContigExtent(t){const n=typeof t=="number"?t:this.genomeId(t);return[this.genomeOffset[n],this.genomeOffset[n+1]]}genomeExtent(t){const n=typeof t=="number"?t:this.genomeId(t),[s,o]=this.genomeContigExtent(n);if(o<=s)return[0,0];this.assertContiguous(n,s,o);const r=this.chromOffset[s],i=this.chromOffset[o];return i<=r?[0,0]:[r,i]}assertContiguous(t,n,s){const o=this.contigGenomeIds;if(o[n]!==t||o[s-1]!==t||n>0&&o[n-1]===t||s<o.length&&o[s]===t)throw new T("bad-ordering",`Genome ${st(this.genomeNames[t])} is not contiguous in bin space under contig-ordering ${st(this.info.ordering)}; a single bin range cannot represent it, so the file's ordering attribute does not describe its actual contig layout. Re-create the file with a genome-grouped ordering.`,{genome:this.genomeNames[t],genomeId:t,contigs:[n,s]})}contigExtent(t){const n=typeof t=="number"?t:this.contigId(t),[s,o]=this.coords.contigBinExtent(n);return o<=s?[0,0]:[s,o]}displayGenomes(){const t=[];for(let n=0;n<this.genomeNames.length;n++)this.genomeNames[n]!==Mn&&t.push(n);return t}displayBinExtent(){const t=[0,this.nBins],n=this.genomeIds.get(Mn);if(n===void 0)return t;const[s,o]=this.genomeExtent(n);return o<=s?t:s===0?[o,this.nBins]:o===this.nBins?[0,s]:t}unassignedStats(){const t=this.nContigs,n=this.nBins,s=this.genomeIds.get(Mn);if(s===void 0||this.genomes===null)return null;const o=Number(this.genomes.get("n_contigs",s)??0),r=Number(this.genomes.get("n_bins",s)??0);return{genomeIndex:s,contigs:o,bins:r,totalContigs:t,totalBins:n,contigFraction:t>0?o/t:0,binFraction:n>0?r/n:0}}genomeDensity(t){const[n,s]=this.genomeExtent(t);if(s<=n)return 0;const o=this.binOffsets();return o[s]-o[n]}binOffsets(){return this.store.binOffsets()}genomeDensities(){const t=new Float64Array(this.nGenomes);if(this.genomes===null)return t;const n=this.binOffsets();for(const s of this.displayGenomes()){const[o,r]=this.genomeExtent(s);r>o&&(t[s]=n[r]-n[o])}return t}async matrix(t,n=po.range){return g2(this,t,n)}async genomeMatrix(t){const n=this.genomeExtent(t);return this.matrix({rows:n},po.binSelection)}async genomePairMatrix(t,n){return this.matrix({rows:this.genomeExtent(t),cols:this.genomeExtent(n)},po.binSelection)}async aggregateSparse(t,n,s={}){const o=Zn(t.rows,this.nBins),r=Zn(t.cols??t.rows,this.nBins),i=Ye(o,r,this.storageMode),a=Wu(o,r,this.coords,this.contigGenomeIds,n,i.mode,this.storageMode==="symmetric-upper",qe),c=t.balance===!0?this.weightSlices(o,r):null;return await this.store.forEachWindow(o,r,i,u=>{for(let l=0;l<u.length;l++){const h=u.bin1[l],f=u.bin2[l],d=c===null?u.count[l]:u.count[l]*jn(c,o,r,h)*jn(c,o,r,f);a.place(h,f,d)}},ta(s,t.value)),{...a.finish(),contigsPerCell:a.perCell}}async pooledMatrix(t,n,s={}){const o=Zn(t.rows,this.nBins),r=Zn(t.cols??t.rows,this.nBins),i=Ye(o,r,this.storageMode),a=o[0]===r[0]&&o[1]===r[1],c=this.contigGenomeIds,u=bi(this.coords,o[0],o[1],n,qe,c),l=a?u:bi(this.coords,r[0],r[1],n,qe,c),h=tr(o,r,u,l,i.mode,this.storageMode==="symmetric-upper",!0),f=t.balance===!0?this.weightSlices(o,r):null;return await this.store.forEachWindow(o,r,i,d=>{for(let m=0;m<d.length;m++){const g=d.bin1[m],p=d.bin2[m],w=f===null?d.count[m]:d.count[m]*jn(f,o,r,g)*jn(f,o,r,p);h.place(g,p,w)}},ta(s,t.value)),{...h.finish(),binsPerCell:u.stride,contigsPerCell:Math.max(u.contigsPerCell,l.contigsPerCell),rowMembers:u,colMembers:l}}async selectionMatrix(t,n,s={}){const o=s.byGenome===!0?this.contigGenomeIds:void 0,r=Qu(this.nBins,t,n,s.cellCap===void 0?qe:s.cellCap,o),i=[0,this.nBins],a=tr(i,i,r,r,Ye(i,i,this.storageMode).mode,this.storageMode==="symmetric-upper"),c=s.balance===!0?this.weightSlices(i,i):null;return await this.store.forEachBands(t.map(({extent:l})=>[l[0],l[1]]),l=>{for(let h=0;h<l.length;h++){const f=l.bin1[h],d=l.bin2[h],m=c===null?l.count[h]:l.count[h]*c.rows[f]*c.cols[d];a.place(f,d,m)}},s),{...a.finish(),binsPerCell:r.stride,contigsPerCell:r.contigsPerCell,ids:r.ids,pooling:r}}static withLens(t,n){const s=n.original.genome!==void 0;if(t.hasGenomes&&!s)return{map:t,refusal:"An edit is not yet drawn on a map of several genomes."};if(t.layout.kind==="scool")return{map:t,refusal:"An edit is not yet drawn on a single-cell file."};const o=U2(n,t.chromnames,t.contigLengths,{always:s});if(o===null)return{map:t,refusal:null};if("refusal"in o)return{map:t,refusal:o.refusal};const r=Fr.of(t.coords,t.chromnames,o.assembly),i=q2(r),a={...t.rawHandle.attrs(),nchroms:r.names.length,nbins:r.nBins};return{map:new wt({uri:t.uri,handle:z2(t.rawHandle,r,i,a),layout:t.layout,attrs:a,contigs:i,chromOffset:r.chromOffset,store:new P2(t.store,r,t.storageMode==="symmetric-upper"),unlensed:t}),refusal:null}}static coarsened(t,n){if(!Number.isInteger(n)||n<1)return{map:t,refusal:`A resolution is a whole number of this map's bins, not ${n} of them.`};if(n===1)return{map:t,refusal:null};if(t.layout.kind==="scool")return{map:t,refusal:"A single-cell file is not yet measured at a resolution you added; measure it at one it stores."};const s=$r.of(t.chromOffset,n),{nnz:o,...r}=t.handle.attrs(),i={...r,"bin-size":t.binsize*n,nbins:s.nBins};return{map:new wt({uri:t.uri,handle:W2(t.handle,s,i),layout:t.layout,attrs:i,contigs:t.contigs,chromOffset:s.chromOffset,...t.genomes===null?{}:{genomes:t.genomes,genomeOffset:t.genomeOffset},store:new Q2(t.store,s,t.storageMode),...t.unlensed===null?{}:{unlensed:t.unlensed}}),refusal:null}}async picture(t,n={}){const s=[0,this.nBins],o=n.balance===!0?this.weightSlices(s,s).rows:null,r=await v2({store:this.store,coords:this.coords,layout:t,weights:o,...n.value===void 0?{}:{value:n.value},...n.gather===void 0?{}:{gather:n.gather},...n.cancelled===void 0?{}:{cancelled:n.cancelled},...n.onProgress===void 0?{}:{onProgress:n.onProgress}});return r===null?null:{levels:C2({n:t.n,cells:r.cells},r.quantizer),quantizer:r.quantizer,histogram:r.histogram,pixels:r.pixels,...r.contacts===void 0?{}:{contacts:r.contacts}}}binColumns(){if(!this.tables.has("bins"))return[];const t=[];for(const n of this.tables.keys("bins")){const s=ji(this.tables.dtype(`bins/${n}`));s!==null&&t.push({name:n,text:s})}return t}binColumn(t,n,s){const o=`bins/${t}`;if(!this.tables.has(o))throw new T("unsupported",`This file has no /${o} column.`,{column:t});const r=Math.max(0,Math.min(n,this.nBins)),i=Math.max(r,Math.min(s,this.nBins));return t===re&&this.tables===this.rawHandle?this.handle.readNumeric(o,r,i):ji(this.tables.dtype(o))===!0?this.tables.readStrings(o,r,i):this.tables.readNumeric(o,r,i)}weightSlices(t,n){const s=`bins/${re}`;if(!this.handle.has(s))throw new T("unsupported",`This file has no /${s} column, so there are no weights to balance with. Run \`cooler balance\` on it, or view the raw counts.`,{column:re});const o=this.handle.readNumeric(s,t[0],t[1]),r=n[0]===t[0]&&n[1]===t[1]?o:this.handle.readNumeric(s,n[0],n[1]);return{rows:o,cols:r}}aggregate(t,n){return Yu(t,this.coords,this.contigGenomeIds,n,this.storageMode==="symmetric-upper")}get cells(){return this.layout.kind==="scool"?this.layout.entries??[]:[]}get activeCells(){return this.pixelStore instanceof Wn?this.pixelStore.names:[]}selectCells(t){if(this.layout.kind!=="scool")throw new T("unsupported",`${this.uri} is not a single-cell container, so it has no cells to choose.`,{layout:this.layout.kind});const n=Ti(this.cells,t);this.pixelStore=new Wn(this.handle,this.layout,n,this.nBins,this.countKind)}async scanCells(t){if(!(this.pixelStore instanceof Wn))throw new T("unsupported",`${this.uri} is not a single-cell container, so it has no cells to walk.`,{layout:this.layout.kind});await this.pixelStore.scanPerCell(t)}cellTable(){const t=this.cells,n=t.map(a=>this.handle.attrsAt(vs(this.layout,a))),s=["name"],o={name:t},r=new Set;for(const a of n)for(const c of Object.keys(a))r.add(c);const i=[...r].filter(a=>!xo.includes(a)&&a!=="metadata").sort();for(const a of[...xo,...i]){if(!r.has(a))continue;const c=n.map(l=>l[a]);if(!xo.includes(a)&&c.every(l=>l===c[0]))continue;c.every(l=>typeof l=="number"||typeof l=="boolean")?o[a]=Float64Array.from(c,l=>Number(l)):o[a]=c.map(l=>l==null?"":String(l)),s.push(a)}return en(t.length,s,o)}get nnz(){return this.store.nnz??0}async scanPixels(t){await this.store.scanAll(t)}async validateDeep(t){const n=[],s=new Set,o=(b,y)=>{s.has(b)||(s.add(b),n.push(y))},r=this.nBins,i=this.storageMode==="square",a=this.binOffsets(),c=this.nnz;a.length!==r+1?n.push(`bin1_offset length (${a.length}) != ${r+1}`):(a[0]!==0||a[r]!==c)&&n.push(`bin1_offset endpoints (${a[0]}, ${a[r]}) do not bracket the table (0, ${c})`);for(let b=1;b<a.length;b++)if(a[b]<a[b-1]){o("monotone",`bin1_offset is not non-decreasing: bin1_offset[${b-1}]=${a[b-1]} > bin1_offset[${b}]=${a[b]}`);break}let u=0;const l=this.countKind!=="f";let h=-1,f=-1;const d=a.length===r+1;let m=0,g=0;const p=t?.cancelled;if(await this.pixelStore.scanAll({onProgress:t?.onProgress,storedRows:!0,onChunk:b=>{if(p?.()===!0)return!1;for(let y=0;y<b.length;y++,g++){const A=b.bin1[y],N=b.bin2[y],I=b.count[y];if(l&&(u+=I),(A<0||N<0||A>=r||N>=r)&&o("range",`pixel bin ids out of range [0, ${r}) at row ${g}`),!i&&A>N&&o("triangle",`pixels are not upper-triangular (bin1_id <= bin2_id): row ${g} is (${A}, ${N})`),h>=0&&!(h<A||h===A&&f<=N)&&o("order",`pixels are not sorted by (bin1_id, bin2_id) at row ${g}`),d){for(;m<r&&a[m+1]<=g;)m++;m!==A&&o("index",`bin1_offset disagrees with pixels/bin1_id at row ${g}: the index places it in bin ${m}, the pixel says ${A}`)}h=A,f=N}return!0}}),p?.()===!0){const b=new Error("cancelled");throw b.name="AbortError",b}const w=this.info.sum;return l&&w!==null&&w!==u&&n.push(`attrs['sum'] (${w}) != the sum of pixels/count (${u})`),{ok:n.length===0,problems:n,note:`Scanned ${c} pixels for range, upper-triangle, sort order and bin1_offset agreement${l?", and reconciled attrs['sum']":" (float counts: sum not reconciled)"}. The /bins geometry checks of the Python validate() are not run — this reader never reads /bins.`}}validateLight(){const t=(s,o={})=>{throw new at(s,o)};this.nContigs===0&&t("/contigs table is empty");for(const s of Lf)this.contigs.columns.includes(s)||t(`Missing column in /contigs: ${s}`);if(this.chromOffset.length!==this.nContigs+1&&t(`chrom_offset length (${this.chromOffset.length}) != ${this.nContigs+1}`),this.chromOffset[0]!==0&&t(`chrom_offset endpoints (${this.chromOffset[0]}, ${this.nBins}) do not bracket the table`),this.genomes!==null){this.nGenomes===0&&t("/genomes table is empty");for(const s of Of)this.genomes.columns.includes(s)||t(`Missing column in /genomes: ${s}`);this.contigs.columns.includes("genome_id")||t("Missing column in /contigs: genome_id"),this.handle.isSoftLink("chroms")||t("/chroms must be a soft link to /contigs for cooler compatibility"),this.genomeOffset.length!==this.nGenomes+1&&t(`genome_offset length (${this.genomeOffset.length}) != ${this.nGenomes+1}`),(this.genomeOffset[0]!==0||this.genomeOffset[this.nGenomes]!==this.nContigs)&&t(`genome_offset endpoints (${this.genomeOffset[0]}, ${this.genomeOffset[this.nGenomes]}) do not bracket the table (0, ${this.nContigs})`)}const n=[["nchroms",this.info.ncontigs,this.nContigs,"len(/contigs)"],...this.genomes===null?[]:[["ngenomes",this.info.ngenomes,this.nGenomes,"len(/genomes)"]],["nbins",this.info.nbins,this.nBins,"len(/bins)"],["nnz",this.info.nnz,this.tables.datasetLength("pixels/bin1_id"),"len(/pixels)"]];for(const[s,o,r,i]of n)o!==null&&o!==r&&t(`attrs[${st(s)}] (${o}) != ${i} (${r})`)}async resample(t,n={}){if(t===null)return this.resampled=null,null;const s=this.resampleRefusal();this.censusWanted=!0,n.census!==void 0&&(this.census=Promise.resolve(n.census));let o;s!==null?o=Promise.reject(s):(this.census??=Ei(this.pixelStore,this.chromOffset,{...n.onProgress===void 0?{}:{onProgress:n.onProgress},cancelled:()=>this.closed||n.cancelled?.()===!0}),o=this.census,o.catch(i=>{i instanceof DOMException&&i.name==="AbortError"&&this.census===o&&(this.census=null)}));const r=new Th(this.pixelStore,{starts:this.chromOffset,names:this.chromnames},t,o);return this.resampled=r,r.ready()}get declaredContacts(){const t=this.info.sum;return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:null}async countContacts(t={}){const n=this.declaredContacts;if(n!==null)return n;if(this.resampleRefusal()!==null)return null;const s=t.pause;this.census??=Ei(this.pixelStore,this.chromOffset,{...t.onProgress===void 0?{}:{onProgress:t.onProgress},...s===void 0?{}:{pause:()=>s(()=>this.censusWanted)},cancelled:()=>this.closed});try{return(await this.census).total}catch{return null}}async takenCensus(){if(this.census===null)return null;try{return await this.census}catch{return null}}resampleRefusal(){return this.layout.kind==="scool"?new T("unsupported","A single-cell container’s map is a sum of its cells rather than one library, so it is not resampled as one. Open one cell, or a pseudo-bulk written as a cooler, to resample it.",{resample:!0,layout:"scool"}):this.storageMode!=="symmetric-upper"?new T("unsupported","This map stores both triangles, so each contact would be drawn twice. Resampling reads upper-triangular files — cooler’s default.",{resample:!0,storageMode:this.storageMode}):null}close(){this.closed||(this.closed=!0,this.rawHandle.close())}}function Rf(e,t){const n=`bins/${re}`;return new Proxy(e,{get(s,o){if(o==="readNumeric")return(i,a,c)=>{const u=s.readNumeric(i,a,c);if(i!==n)return u;const l=new Float64Array(u.length);for(let h=0;h<u.length;h++)l[h]=u[h]*t;return l};const r=Reflect.get(s,o,s);return typeof r=="function"?r.bind(s):r}})}function Pf(e,t){const n=e.data[t];return n instanceof Float64Array?n:Float64Array.from(e.numbers(t))}function ji(e){try{return"SOU".includes(zc(e))}catch{return null}}function zf(e,t){const n=e.data[t];if(ArrayBuffer.isView(n)&&!(n instanceof DataView)&&!(n instanceof BigInt64Array)){const s=new Int32Array(n.length);return s.set(n),s}return Int32Array.from(e.numbers(t))}function ta(e,t){return t===void 0?e:{...e,value:t}}function Zn(e,t){const n=Math.min(Math.max(Math.trunc(e[0]),0),t),s=Math.min(Math.max(Math.trunc(e[1]),n),t);return[n,s]}function jn(e,t,n,s){return s>=t[0]&&s<t[1]?e.rows[s-t[0]]:s>=n[0]&&s<n[1]?e.cols[s-n[0]]:1}function qf(e,t){if(!t.isRemote||!ku(e,e.attrs()))return;const{path:n}=Vt(e.uri);throw new T("scool-listing-cost",`${n} is a single-cell container, and listing its cells is not a bounded read: the names live in HDF5 link records spread across the whole object. Reading them over the network costs either one download of ${Mt.bytes(t.size)} or a few percent of that in about a thousand separate requests. Choose which to pay, or open a local copy, where neither cost applies.`,{path:n,size:t.size})}const Uf=[137,72,68,70,13,10,26,10];function Gf(e){for(const t of[0,512,1024,2048,4096,8192]){if(t+8>e.size)return!1;const n=e.readBytes(t,8);if(n.length===8&&Uf.every((s,o)=>n[o]===s))return!0}return!1}const Hf="0.18.0",Qf="b1f1a7a";function ms(e){if(e==null)return null;switch(typeof e){case"string":case"number":case"boolean":return e;case"bigint":return Number(e);case"object":{if(Array.isArray(e))return e.map(ms);if(ArrayBuffer.isView(e))return Array.from(e);if(e instanceof Map){const n={};for(const[s,o]of e)n[String(s)]=ms(o);return n}const t={};for(const[n,s]of Object.entries(e))t[n]=ms(s);return t}default:return String(e)}}function Kf(e){return e instanceof T?{name:e.name,code:e.code,message:e.message,detail:ms(e.detail),stack:e.stack}:e instanceof Error?{name:e.name,code:null,message:e.message,detail:{},stack:e.stack}:{name:"Error",code:null,message:String(e),detail:{}}}const _e=1<<20,Wf=64<<20;let ea=0;class ce{id;size;isRemote=!1;bytes;blob;existingPath;tempDir;mountPath=null;ownsMount=!1;requests=0;bytesRead=0;cache=new Map;cachedBytes=0;syncReader=null;module=null;readExact;constructor(t,n={}){if(this.tempDir=n.tempDir,this.bytes=null,this.blob=null,this.existingPath=null,Yf(t)){const o=typeof File<"u"&&t instanceof File?t.name:null;this.blob=t,this.size=t.size,this.id=n.name??o??`blob-${vo()}`,this.readExact=(r,i)=>this.readBlobExact(t,r,i);return}if(Vf(t)){this.existingPath=t.path,this.size=t.size,this.id=n.name??t.path;return}const s=Xf(t);this.bytes=s,this.size=s.byteLength,this.id=n.name??`bytes-${vo()}`}static async fromPath(t,n={}){if(!kn())throw new T("bad-uri",`cannot open the filesystem path ${t} in a browser; pass the File object instead`,{path:t});const s=await We();let o;try{o=s.FS.stat(t).size}catch(r){throw new T("not-hdf5",`cannot stat ${t}: ${r instanceof Error?r.message:String(r)}`,{path:t})}return new ce({path:t,size:o},{name:n.name??t,...n})}static async open(t,n={}){return typeof t=="string"?ce.fromPath(t,n):new ce(t,n)}async mount(){if(this.mountPath!==null)return this.mountPath;const t=await We();if(this.module=t,this.existingPath!==null)return this.mountPath=this.existingPath,this.ownsMount=!1,this.mountPath;if(this.blob!==null&&typeof FileReaderSync<"u")return this.mountPath=this.mountLazy(t,this.blob),this.ownsMount=!0,this.mountPath;const n=this.bytes??new Uint8Array(await this.blob.arrayBuffer()),s=this.mountTarget();return t.FS.writeFile(s,n),this.mountPath=s,this.ownsMount=!0,this.requests+=1,this.bytesRead+=n.byteLength,s}mountLazy(t,n){const s=this.mountTarget().replace(/^\//,""),o=t.FS.createFile("/",s,{},!0,!1),r={length:this.size};return o.contents=r,Object.defineProperty(o,"usedBytes",{get:()=>r.length}),o.stream_ops={...o.stream_ops,read:(i,a,c,u,l)=>{if(l>=this.size)return 0;const h=Math.min(this.size-l,u);return this.copyInto(n,a,c,l,h),h},mmap:(i,a,c)=>{const u=t.Module._malloc(a);if(u===0)throw new Error("mmap allocation failed");const l=Math.max(0,Math.min(this.size-c,a));return l>0&&this.copyInto(n,t.Module.HEAPU8,u,c,l),{ptr:u,allocated:!0}}},`/${s}`}readBytes(t,n){const s=Math.max(0,Math.min(this.size-t,n));if(s<=0)return new Uint8Array(0);if(this.bytes!==null)return this.bytes.subarray(t,t+s).slice();if(this.blob!==null){const a=new Uint8Array(s);return this.copyInto(this.blob,a,0,t,s),a}const o=this.module;if(this.existingPath===null||o===null)throw new T("unsupported",`${this.id} cannot be read directly before it has been mounted.`,{id:this.id});const r=new Uint8Array(s),i=o.FS.open(this.existingPath,"r");try{let a=0;for(;a<s;){const c=o.FS.read(i,r,a,s-a,t+a);if(c<=0)break;a+=c}return this.requests+=1,this.bytesRead+=a,a===s?r:r.subarray(0,a)}finally{o.FS.close(i)}}async readBlobExact(t,n,s){const o=Math.max(0,Math.min(this.size-n,s));if(o===0)return new Uint8Array(0);const r=Math.floor(n/_e),i=Math.floor((n+o-1)/_e);let a=!0;for(let u=r;u<=i&&a;u++)a=this.cache.has(u);if(a)return this.readBytes(n,o);const c=new Uint8Array(await t.slice(n,n+o).arrayBuffer());return this.requests+=1,this.bytesRead+=c.byteLength,c}copyInto(t,n,s,o,r){let i=0;for(;i<r;){const a=o+i,c=Math.floor(a/_e);let u=this.cache.get(c);if(u===void 0){const f=c*_e,d=Math.min(f+_e,this.size);u=new Uint8Array(this.reader().readAsArrayBuffer(t.slice(f,d))),this.store(c,u),this.requests+=1,this.bytesRead+=u.byteLength}else this.cache.delete(c),this.cache.set(c,u);const l=a-c*_e,h=Math.min(u.length-l,r-i);if(h<=0)throw new Error(`short read of ${this.id} at ${a}`);n.set(u.subarray(l,l+h),s+i),i+=h}}store(t,n){this.cache.set(t,n),this.cachedBytes+=n.byteLength;for(const s of this.cache.keys()){if(this.cachedBytes<=Wf)break;if(s===t)continue;const o=this.cache.get(s);o&&(this.cachedBytes-=o.byteLength),this.cache.delete(s)}}reader(){return this.syncReader??=new FileReaderSync,this.syncReader}close(){if(this.cache.clear(),this.cachedBytes=0,this.mountPath===null)return;const t=this.mountPath;this.mountPath=null,this.ownsMount&&(this.ownsMount=!1,We().then(n=>{try{n.FS.unlink(t)}catch{}},()=>{}))}stats(){return{requests:this.requests,bytes:this.bytesRead}}cachedChunkCount(){return this.cache.size}resetStats(){this.requests=0,this.bytesRead=0}mountTarget(){const t=this.id.replace(/[^A-Za-z0-9._-]+/g,"_").slice(-100),n=`chromosomix-${vo()}-${t}`;if(!kn())return`/${n}`;const s=globalThis.process?.env;return`${(this.tempDir??s?.TMPDIR??s?.TMP??s?.TEMP??"/tmp").replace(/\/+$/,"")}/${n}`}}function vo(){return ea+=1,`${Date.now().toString(36)}${ea.toString(36)}`}function Yf(e){return typeof Blob<"u"&&e instanceof Blob}function Vf(e){return typeof e=="object"&&e!==null&&typeof e.path=="string"&&typeof e.size=="number"}function Xf(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}const Jf="/chromosomix-lazy",In=new Map,na=new WeakSet;let ko=0;function Zf(e,t,n){return{read:(s,o,r,i,a)=>{if(a>=t)return 0;const c=Math.min(t-a,i);return n(o,r,a,c),c},llseek:(s,o,r)=>{const i=r===1?s.position+o:r===2?t+o:o;if(i<0)throw new Error("a lazy file cannot be sought before its start");return i},mmap:(s,o,r)=>{const i=e.Module._malloc(o);if(i===0)throw new Error("mmap allocation failed");const a=Math.max(0,Math.min(t-r,o));return a>0&&n(e.Module.HEAPU8,i,r,a),{ptr:i,allocated:!0}}}}function jf(e,t,n,s){const o=Zf(e,n,s);if(kn()){e5(e),ko+=1;const a=`${Jf}/${t}-${ko}`;return In.set(a,{size:n,ino:79691776+ko,ops:o}),a}const r=e.FS.createFile("/",t,{},!0,!1),i={length:n};return r.contents=i,Object.defineProperty(r,"usedBytes",{get:()=>i.length}),r.stream_ops={...r.stream_ops,read:o.read,mmap:o.mmap},`/${t}`}function t5(e,t){if(!In.delete(t))try{e.FS.unlink(t)}catch{}}function sa(e){const t=new Date(0);return{dev:76,ino:e.ino,mode:33060,nlink:1,uid:0,gid:0,rdev:0,size:e.size,blksize:4096,blocks:Math.ceil(e.size/512),atime:t,mtime:t,ctime:t}}function e5(e){const t=e.FS;if(na.has(t))return;na.add(t);const n=t.open.bind(t),s=t.fstat.bind(t),o=t.stat.bind(t);t.open=(r,i,a)=>{const c=typeof r=="string"?In.get(r):void 0;if(c===void 0)return n(r,i,a);const u={id:c.ino,mode:33060,node_ops:{},path:r,usedBytes:c.size};return t.createStream({path:r,flags:0,node:u,stream_ops:c.ops,seekable:!0,position:0})},t.fstat=r=>{const i=t.getStream(r),a=i?.path===void 0?void 0:In.get(i.path);return a!==void 0&&i?.stream_ops===a.ops?sa(a):s(r)},t.stat=(r,i)=>{const a=typeof r=="string"?In.get(r):void 0;return a===void 0?o(r,i):sa(a)}}const n5=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),s5=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qt=64,Cl=32;function Gt(e,t){return e>>>t|e<<32-t}function gs(e){const t=new Uint32Array(s5),n=new Uint32Array(64),s=e.length*8,o=new Uint8Array((Math.floor((e.length+8)/Qt)+1)*Qt);o.set(e),o[e.length]=128;const r=new DataView(o.buffer);r.setUint32(o.length-8,Math.floor(s/4294967296),!1),r.setUint32(o.length-4,s>>>0,!1);for(let c=0;c<o.length;c+=Qt){for(let w=0;w<16;w++)n[w]=r.getUint32(c+w*4,!1);for(let w=16;w<64;w++){const b=n[w-15],y=n[w-2],A=Gt(b,7)^Gt(b,18)^b>>>3,N=Gt(y,17)^Gt(y,19)^y>>>10;n[w]=n[w-16]+A+n[w-7]+N>>>0}let[u,l,h,f,d,m,g,p]=t;for(let w=0;w<64;w++){const b=Gt(d,6)^Gt(d,11)^Gt(d,25),y=d&m^~d&g,A=p+b+y+n5[w]+n[w]>>>0,N=Gt(u,2)^Gt(u,13)^Gt(u,22),I=u&l^u&h^l&h,M=N+I>>>0;p=g,g=m,m=d,d=f+A>>>0,f=h,h=l,l=u,u=A+M>>>0}t[0]=t[0]+u>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+f>>>0,t[4]=t[4]+d>>>0,t[5]=t[5]+m>>>0,t[6]=t[6]+g>>>0,t[7]=t[7]+p>>>0}const i=new Uint8Array(Cl),a=new DataView(i.buffer);for(let c=0;c<8;c++)a.setUint32(c*4,t[c],!1);return i}function An(e,t){const n=new Uint8Array(Qt);n.set(e.length>Qt?gs(e):e);const s=new Uint8Array(Qt+t.length),o=new Uint8Array(Qt+Cl);for(let r=0;r<Qt;r++)s[r]=n[r]^54,o[r]=n[r]^92;return s.set(t,Qt),o.set(gs(s),Qt),gs(o)}function oa(e){let t="";for(const n of e)t+=n.toString(16).padStart(2,"0");return t}function ve(e){return new TextEncoder().encode(e)}const o5="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",ra="AWS4-HMAC-SHA256",Fl="s3",$l="aws4_request";function r5(e){const t=(n,s=2)=>String(n).padStart(s,"0");return`${t(e.getUTCFullYear(),4)}${t(e.getUTCMonth()+1)}${t(e.getUTCDate())}T${t(e.getUTCHours())}${t(e.getUTCMinutes())}${t(e.getUTCSeconds())}Z`}function ar(e){return encodeURIComponent(e).replace(/[!'()*]/g,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`)}function i5(e){return e===""?"/":e.split("/").map(t=>ar(decodeURIComponent(t))).join("/")}function a5(e){const t=[];return e.forEach((n,s)=>t.push([ar(s),ar(n)])),t.sort((n,s)=>n[0]===s[0]?n[1]<s[1]?-1:1:n[0]<s[0]?-1:1),t.map(([n,s])=>`${n}=${s}`).join("&")}let ts=null;function c5(e,t,n){const s=`${e}|${t}|${n}`;if(ts!==null&&ts.id===s)return ts.key;const o=An(ve(`AWS4${e}`),ve(t)),r=An(o,ve(n)),i=An(r,ve(Fl)),a=An(i,ve($l));return ts={id:s,key:a},a}function l5(e){const t=new URL(e.url),n=e.now??new Date,s=r5(n),o=s.slice(0,8),r=e.payloadHash??o5,{credential:i}=e,a=[["host",t.host],["x-amz-content-sha256",r],["x-amz-date",s]];i.sessionToken!==void 0&&i.sessionToken!==""&&a.push(["x-amz-security-token",i.sessionToken]);const c=a.map(([g,p])=>`${g}:${p.trim()}
|
|
6
|
+
`).join(""),u=a.map(([g])=>g).join(";"),l=[e.method.toUpperCase(),i5(t.pathname),a5(t.searchParams),c,u,r].join(`
|
|
7
|
+
`),h=`${o}/${i.region}/${Fl}/${$l}`,f=[ra,s,h,oa(gs(ve(l)))].join(`
|
|
8
|
+
`),d=oa(An(c5(i.secretAccessKey,o,i.region),ve(f))),m={Authorization:`${ra} Credential=${i.accessKeyId}/${h}, SignedHeaders=${u}, Signature=${d}`,"x-amz-content-sha256":r,"x-amz-date":s};return i.sessionToken!==void 0&&i.sessionToken!==""&&(m["x-amz-security-token"]=i.sessionToken),m}function Fe(e){const t={...e.headers};return e.credential===void 0?t:{...t,...l5({method:(e.method??"GET").toUpperCase(),url:e.url,credential:e.credential})}}function qr(e){const t=u5(e);return t.has("x-amz-signature")||t.has("x-goog-signature")?!0:t.has("sig")&&t.has("sv")}function u5(e){const t=new Set;if(typeof e!="string")return t;const n=e.indexOf("#"),s=n<0?e:e.slice(0,n),o=s.indexOf("?");if(o<0)return t;const r=s.slice(o+1);for(const i of r.split("&")){const a=i.indexOf("=");a<=0||t.add(i.slice(0,a).toLowerCase())}return t}const h5=1<<20,f5=64<<20,d5=4<<20,m5=16<<20,g5=8;function p5(e,t){const n=new XMLHttpRequest;n.open("GET",e,!1);for(const[s,o]of Object.entries(t))n.setRequestHeader(s,o);return n.responseType="arraybuffer",n.send(null),{status:n.status,body:new Uint8Array(n.response??new ArrayBuffer(0)),contentRange:n.getResponseHeader("content-range")}}class Se{id;size;isRemote=!0;url;chunkSize;onRead;maxCacheBytes;cache=new Map;cachedBytes=0;readAhead;recent=[];requests;bytesRead;mountPath=null;credential;headers;fetchImpl;syncFetch;constructor(t,n,s,o){this.url=t,this.id=t,this.size=n,this.credential=s.credential,this.headers=s.headers,this.fetchImpl=s.fetchImpl??((i,a)=>globalThis.fetch(i,a)),this.syncFetch=s.syncFetch??null,this.chunkSize=Math.max(1,Math.trunc(s.chunkSize??h5)),this.readAhead=s.readAhead??!0,this.onRead=s.onRead;const r=Math.trunc(s.maxCacheBytes??f5);this.maxCacheBytes=Math.max(this.chunkSize,r),this.requests=o.requests,this.bytesRead=o.bytes}static async open(t,n={}){const s=n.fetchImpl??globalThis.fetch,o=m=>Fe({url:t,method:m,...n.headers===void 0?{}:{headers:n.headers},...n.credential===void 0?{}:{credential:n.credential}});if(typeof s!="function")throw new T("remote-cors","this runtime has no fetch(); remote files need one",{url:t});const r=gn(t),i={requests:0,bytes:0};let a=null;if(!qr(t))try{i.requests+=1,a=await s(t,{method:"HEAD",headers:o("HEAD")})}catch(m){await aa(t,r,m,s,i)}if(a&&!a.ok)throw new T("bad-uri",n.credential===void 0?`${r} answered ${a.status} ${a.statusText} to a HEAD of ${t}; the viewer needs a publicly readable object, or a bucket entry holding a key for it (Open a file → Private buckets). A presigned link is read without this probe and does not reach here, so a URL carrying a signature in its query that fails has expired rather than been rejected for its method.`:`${r} answered ${a.status} ${a.statusText} to a signed HEAD of ${t}. The key reached the bucket and was rejected: check that the region on the bucket entry matches the bucket, that the key is allowed \`s3:GetObject\` on this prefix, and — for a temporary credential — that the session token has not expired.`,{url:t,host:r,status:a.status,signed:n.credential!==void 0});const c=ca(a);if(c!==null){const m=await w5(t,s,o,i),g=la(m?.headers.get("content-range")??null)??es(m,"content-length");if(m!==null&&m.status===206&&ca(m)===null&&g!==null)return new Se(t,g,n,i);throw new T("remote-compressed",`${r} is serving ${t} with “Content-Encoding: ${c}”, so byte ranges address the compressed stream rather than the file.`,{url:t,host:r,encoding:c,encodedLength:es(a,"content-length")})}const u=es(a,"content-length"),l=u===0?null:u;if((a?.headers.get("accept-ranges")??"").toLowerCase().includes("bytes")&&l!==null)return new Se(t,l,n,i);let f;try{i.requests+=1,f=await s(t,{method:"GET",headers:{...o("GET"),Range:"bytes=0-0"}})}catch(m){throw await aa(t,r,m,s,i),new Error("unreachable")}if(i.bytes+=es(f,"content-length")??1,f.status!==206)throw new T("remote-no-ranges",`${r} does not serve HTTP range requests: a “Range: bytes=0-0” request for ${t} returned ${f.status}, not 206 Partial Content.`,{url:t,host:r,status:f.status});const d=la(f.headers.get("content-range"))??l;if(d===null)throw new T("remote-cors",`${r} serves ranges for ${t} but does not expose its size to this page: neither “Content-Length” nor “Content-Range” was readable. Add both to the bucket’s CORS “Access-Control-Expose-Headers”.`,{url:t,host:r});return new Se(t,d,n,i)}async mount(){if(this.mountPath!==null)return this.mountPath;if(this.syncFetch===null&&typeof XMLHttpRequest>"u")throw new T("remote-cors","remote files are read with synchronous XMLHttpRequest, which exists only in a browser worker; this runtime has none.",{url:this.url});const t=await We(),n=`remote-${Math.abs(A5(this.url)).toString(36)}`;return this.mountPath=jf(t,n,this.size,(s,o,r,i)=>this.copyInto(s,o,r,i)),this.mountPath}close(){if(this.cache.clear(),this.cachedBytes=0,this.mountPath===null)return;const t=this.mountPath;this.mountPath=null,We().then(n=>t5(n,t),()=>{})}stats(){return{requests:this.requests,bytes:this.bytesRead}}resetStats(){this.requests=0,this.bytesRead=0}cachedChunkCount(){return this.cache.size}readBytes(t,n){const s=Math.max(0,Math.min(this.size-t,n)),o=new Uint8Array(s);return s>0&&this.copyInto(o,0,t,s),o}async readExact(t,n){const s=Math.max(0,Math.min(this.size-t,n));if(s===0)return new Uint8Array(0);const o=Math.floor(t/this.chunkSize),r=Math.floor((t+s-1)/this.chunkSize);let i=!0;for(let d=o;d<=r&&i;d++)i=this.cache.has(d);if(i)return this.readBytes(t,s);const a=t,c=t+s-1,u=this.fetchImpl,l=await u(this.url,{method:"GET",headers:{...this.authorisation(),Range:`bytes=${a}-${c}`}});this.requests+=1,this.refuseStatus(l.status,a,c);const h=new Uint8Array(await l.arrayBuffer());this.bytesRead+=h.byteLength,this.onRead?.(this.requests,this.bytesRead);const f=this.windowOf(h,a,c,l.headers.get("content-range"));if(f.byteLength<s)throw new T("remote-no-ranges","a range request returned a short response",{wanted:s,available:f.byteLength});return f.byteLength===s&&f.buffer.byteLength===s?f:f.slice(0,s)}copyInto(t,n,s,o){let r=0;for(;r<o;){const i=s+r,a=Math.floor(i/this.chunkSize),c=this.cache.get(a);if(c){this.touch(a),r+=ia(t,n+r,c,i-a*this.chunkSize,o-r);continue}const u=Math.floor((s+o-1)/this.chunkSize);let l=a;for(;l+1<=u&&!this.cache.has(l+1);)l+=1;const{ahead:h,streak:f}=this.aheadFor(a,l),d=Math.min(l+h,Math.ceil(this.size/this.chunkSize)-1);for(;l<d&&!this.cache.has(l+1);)l+=1;this.recent.push({from:a,to:l,streak:f}),this.recent.length>g5&&this.recent.shift();const m=a*this.chunkSize,g=Math.min((l+1)*this.chunkSize,this.size)-1,p=this.fetchRange(m,g);r+=ia(t,n+r,p,i-m,o-r);for(let w=a;w<=l;w++){const b=w*this.chunkSize-m;if(b>=p.length)break;this.store(w,p.subarray(b,Math.min(b+this.chunkSize,p.length)))}}}aheadFor(t,n){if(!this.readAhead)return{ahead:0,streak:0};const s=Math.max(1,Math.floor(d5/this.chunkSize));let o=0;for(const i of this.recent)t>=i.from-s&&t<=i.to+s&&(o=Math.max(o,i.streak+1));if(o<2)return{ahead:0,streak:o};const r=Math.max(0,Math.floor(m5/this.chunkSize)-(n-t+1));return{ahead:Math.min(r,2**(o-2)),streak:o}}fetchRange(t,n){const s={...this.authorisation(),Range:`bytes=${t}-${n}`},o=(this.syncFetch??p5)(this.url,s);return this.requests+=1,this.refuseStatus(o.status,t,n),this.bytesRead+=o.body.byteLength,this.onRead?.(this.requests,this.bytesRead),this.windowOf(o.body,t,n,o.contentRange)}authorisation(){return this.credential===void 0&&this.headers===void 0?{}:Fe({url:this.url,method:"GET",...this.headers===void 0?{}:{headers:this.headers},...this.credential===void 0?{}:{credential:this.credential}})}refuseStatus(t,n,s){if(t===403&&this.credential!==void 0)throw new T("bad-uri",`${gn(this.url)} refused a signed request for bytes ${n}-${s} of ${this.url}. The key reached the bucket and was rejected: check the region on the bucket entry matches the bucket, that the key is allowed \`s3:GetObject\` on this prefix, and — for a temporary credential — that the session token has not expired.`,{url:this.url,status:403,from:n,to:s,signed:!0});if(t!==206&&t!==200)throw new T("remote-no-ranges",`${gn(this.url)} returned ${t} for bytes ${n}-${s} of ${this.url}`,{url:this.url,status:t,from:n,to:s})}windowOf(t,n,s,o){const r=s-n+1,i=El(o);if(i!==null&&i.end-i.start+1!==t.byteLength)throw new T("remote-compressed",`${gn(this.url)} answered a request for bytes ${n}-${s} of ${this.url} with “Content-Range: ${o}” — ${i.end-i.start+1} octets — but the body is ${t.byteLength}. The response was re-encoded in transit (transfer compression), so ranges do not address the file. Serve it without “Content-Encoding”, or download it and drop it here.`,{url:this.url,from:n,to:s,claimed:i.end-i.start+1,received:t.byteLength});const a=i?.start??b5(o),c=a===null?t.byteLength>r?n:0:n-a;if(c===0&&t.byteLength<=r)return t;if(c<0||c>=t.byteLength)throw new T("remote-no-ranges",`${gn(this.url)} answered a request for bytes ${n}-${s} of ${this.url} with ${t.byteLength} bytes starting at ${a??"an unstated offset"}, which does not contain what was asked for.`,{url:this.url,from:n,to:s,start:a,length:t.byteLength});return t.subarray(c,Math.min(c+r,t.byteLength))}store(t,n){const s=new Uint8Array(n);this.cache.set(t,s),this.cachedBytes+=s.byteLength;for(const o of this.cache.keys()){if(this.cachedBytes<=this.maxCacheBytes)break;if(o===t)continue;const r=this.cache.get(o);r&&(this.cachedBytes-=r.byteLength),this.cache.delete(o)}}touch(t){const n=this.cache.get(t);n&&(this.cache.delete(t),this.cache.set(t,n))}}function ia(e,t,n,s,o){const r=Math.min(n.length-s,o);if(r<=0)throw new T("remote-no-ranges","a range request returned a short response",{wanted:o,available:n.length-s});return e.set(n.subarray(s,s+r),t),r}async function aa(e,t,n,s,o){let r=!1;try{o.requests+=1,await s(e,{method:"GET",mode:"no-cors",headers:{Range:"bytes=0-0"}}),r=!0}catch{r=!1}const i=n instanceof Error?`${n.name}: ${n.message}`:String(n);throw r?new T("remote-cors",`${t} is reachable but refused a cross-origin read of ${e} (${i}). That is what a missing “Access-Control-Allow-Origin” looks like from a browser: the failure has no status and no headers. Configure the bucket to allow GET and HEAD and the “Range” request header, and to expose “Content-Length” and “Content-Range”.`,{url:e,host:t,cause:i,reachable:!0}):new T("remote-cors",`${t} could not be reached for ${e} (${i}). The request failed before any response arrived, so this is a DNS, TLS or connectivity problem rather than a CORS one.`,{url:e,host:t,cause:i,reachable:!1})}function gn(e){try{return new URL(e).host}catch{return e}}async function w5(e,t,n,s){try{return s.requests+=1,await t(e,{method:"HEAD",headers:{...n("HEAD"),Range:"bytes=0-"}})}catch{return null}}function ca(e){const t=(e?.headers.get("content-encoding")??"").trim().toLowerCase();return t===""||t==="identity"?null:t}function es(e,t){const n=e?.headers.get(t);if(n==null||n.trim()==="")return null;const s=Number(n);return Number.isFinite(s)?s:null}function b5(e){return El(e)?.start??null}function El(e){if(!e)return null;const t=/bytes\s+(\d+)-(\d+)\/\s*(\d+|\*)\s*$/.exec(e);if(!t)return null;const n=Number(t[1]),s=Number(t[2]),o=t[3]==="*"?null:Number(t[3]);return!Number.isFinite(n)||!Number.isFinite(s)?null:{start:n,end:s,total:o!==null&&Number.isFinite(o)?o:null}}function la(e){if(!e)return null;const t=/\/\s*(\d+)\s*$/.exec(e);if(!t)return null;const n=Number(t[1]);return Number.isFinite(n)?n:null}function A5(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return t}class le{rows=[];contigIds=new Map;contigs=[];contigId(t){const n=this.contigIds.get(t);if(n!==void 0)return n;const s=this.contigs.length;return this.contigIds.set(t,s),this.contigs.push(t),s}add(t,n,s,o={}){const r=Math.min(n,s),i=Math.max(r+1,Math.max(n,s));this.rows.push({contig:this.contigId(t),start:r,end:i,strand:o.strand??0,score:o.score??Number.NaN,name:o.name??"",id:o.id??"",detail:o.detail??"",exons:o.exons??null,cds:o.cds??null,bars:o.bars??null,xyz:o.xyz??null,hap:o.hap??0})}get length(){return this.rows.length}finish(t=null,n=null){const s=this.rows;s.sort((d,m)=>d.contig-m.contig||d.start-m.start||d.end-m.end||d.hap-m.hap);const o=s.length,r={contigs:this.contigs,length:o,contig:new Int32Array(o),start:new Int32Array(o),end:new Int32Array(o),strand:new Int8Array(o),score:new Float32Array(o),name:new Array(o),id:new Array(o),detail:new Array(o),exonAt:new Int32Array(o+1),exonStart:new Int32Array(0),exonEnd:new Int32Array(0),cdsStart:new Int32Array(o),cdsEnd:new Int32Array(o),contigAt:new Int32Array(this.contigs.length+1),maxSpan:new Int32Array(this.contigs.length)};let i=0;for(const d of s)i+=d.exons===null?0:d.exons.length>>1;r.exonStart=new Int32Array(i),r.exonEnd=new Int32Array(i);const a=t===null?0:t.labels.length,c=new Float32Array(a*o).fill(Number.NaN);let u=0;const l=n===null?null:{x:new Float32Array(o),y:new Float32Array(o),z:new Float32Array(o),hap:new Int8Array(o)};let h=0;for(let d=0;d<o;d++){const m=s[d];if(r.contig[d]=m.contig,r.start[d]=m.start,r.end[d]=m.end,r.strand[d]=m.strand,r.score[d]=m.score,r.name[d]=m.name,r.id[d]=m.id,r.detail[d]=m.detail,r.cdsStart[d]=m.cds===null?-1:m.cds[0],r.cdsEnd[d]=m.cds===null?-1:m.cds[1],r.exonAt[d]=h,m.exons!==null){const p=[];for(let w=0;w+1<m.exons.length;w+=2)p.push([m.exons[w],m.exons[w+1]]);p.sort((w,b)=>w[0]-b[0]);for(const[w,b]of p)r.exonStart[h]=w,r.exonEnd[h]=b,h++}if(a>0&&m.bars!==null&&m.bars.length===a)for(let p=0;p<a;p++){const w=m.bars[p];c[d*a+p]=w,w>u&&(u=w)}l!==null&&(l.x[d]=m.xyz===null?Number.NaN:m.xyz[0],l.y[d]=m.xyz===null?Number.NaN:m.xyz[1],l.z[d]=m.xyz===null?Number.NaN:m.xyz[2],l.hap[d]=m.hap);const g=m.end-m.start;g>r.maxSpan[m.contig]&&(r.maxSpan[m.contig]=g)}r.exonAt[o]=h;let f=0;for(let d=0;d<this.contigs.length;d++)for(r.contigAt[d]=f;f<o&&r.contig[f]===d;)f++;if(r.contigAt[this.contigs.length]=f,t!==null){const{limit:d,...m}=t;r.bars={...m,values:c,max:Number.isFinite(d)&&d>0?d:u}}return l!==null&&n!==null&&(r.model={...l,haplotypes:[...n.haplotypes],width:n.width}),r}}class Bl{rows=[];contigIds=new Map;contigs=[];contigId(t){const n=this.contigIds.get(t);if(n!==void 0)return n;const s=this.contigs.length;return this.contigIds.set(t,s),this.contigs.push(t),s}add(t,n,s,o,r,i,a={}){this.rows.push({c1:this.contigId(t),s1:n,e1:Math.max(n+1,s),c2:this.contigId(o),s2:r,e2:Math.max(r+1,i),score:a.score??Number.NaN,name:a.name??"",detail:a.detail??""})}get length(){return this.rows.length}finish(){const t=this.rows.length,n={contigs:this.contigs,length:t,contig1:new Int32Array(t),start1:new Int32Array(t),end1:new Int32Array(t),contig2:new Int32Array(t),start2:new Int32Array(t),end2:new Int32Array(t),score:new Float32Array(t),name:new Array(t),detail:new Array(t)};for(let s=0;s<t;s++){const o=this.rows[s];n.contig1[s]=o.c1,n.start1[s]=o.s1,n.end1[s]=o.e1,n.contig2[s]=o.c2,n.start2[s]=o.s2,n.end2[s]=o.e2,n.score[s]=o.score,n.name[s]=o.name,n.detail[s]=o.detail}return n}}(()=>{const e=new Int8Array(256).fill(-1),t=(n,s)=>{for(const o of n)e[o.charCodeAt(0)]=s,e[o.toLowerCase().charCodeAt(0)]=s};return t("TU",0),t("C",1),t("A",2),t("G",3),e})();const y5=["gtf","track","segments","variants","barchart","ideogram","junctions","pairs","sequence","metadata","classes","alignments","reads","structure"];function N5(e){return e==="gtf"||e==="segments"||e==="variants"||e==="barchart"||e==="ideogram"||e==="junctions"||e==="structure"}const M5=" · ",Ur=12,ua=65536;function I5(e){return e.length<Ur||e[0]!==31||e[1]!==139||e[2]!==8||(e[3]&4)===0?!1:Gr(e)!==null}function Gr(e){if(e.length<Ur)return null;const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(10,!0);let s=12;const o=Math.min(12+n,e.length);for(;s+4<=o;){const r=e[s],i=e[s+1],a=t.getUint16(s+2,!0);if(r===66&&i===67&&a===2)return t.getUint16(s+4,!0)+1;s+=4+a}return null}const x5=xl;async function Tl(e,t=Number.POSITIVE_INFINITY,n=Br){const s=[];let o=0,r=0;for(;r+Ur<=e.length;){const c=r,u=Gr(e.subarray(r,Math.min(r+64,e.length)));if(u===null||r+u>e.length)break;const h=new DataView(e.buffer,e.byteOffset+r,u).getUint16(10,!0),f=r+12+h,d=r+u-8;if(d>f){const m=await x5(e.subarray(f,d));if(m.length>0){if(o+m.length>n)throw wl({format:"BGZF file",field:"span read"},n,e.length);s.push(m),o+=m.length}}if(r+=u,c>=t)break}const i=new Uint8Array(o);let a=0;for(const c of s)i.set(c,a),a+=c.length;return i}const v5={ratio:64,floor:Br,ceiling:2**34};async function k5(e,t=Br){if(!(e.length>2&&e[0]===31&&e[1]===139))return e;if(typeof DecompressionStream>"u")throw new Error("This file is gzipped and this browser has no DecompressionStream to un-gzip it with. Decompress it and drop the plain text file.");return I5(e)?Tl(e,Number.POSITIVE_INFINITY,t):Tr(e,{format:"file",field:"gzip stream",encoding:"gzip",maxBytes:t})}async function S5(e,t){if(e.kind==="local"){const r=E5(e.file);return r!==null?r:(Cn(),$5(e.file,new ce(e.file)))}if(e.reading==="whole"){const r=L5(e.url);return r!==null?r:O5(e.url,await _l(e.url,Sn(e),t))}const n=e.reading??"",s=B5(e.url,n);if(s!==null)return s;const o=Sn(e);try{return ha(e.url,n,await Se.open(e.url,{...o,...e.reading==="fine"?{chunkSize:Ll,readAhead:!1,...t?.onRead===void 0?{}:{onRead:t.onRead.bind(t)}}:{}}))}catch(r){if(r instanceof T&&r.code==="remote-compressed")return ha(e.url,n,await T5(e.url,r,o));if(r instanceof T)throw r;const i=Cs(e.url);throw new T("remote-cors",`Could not read ${e.url}. The host ${i} either did not allow this page to read it (CORS must permit GET and HEAD and expose Content-Length and Content-Range) or refused the request outright. Underlying error: ${r instanceof Error?r.message:String(r)}`,{url:e.url,host:i})}}async function cr(e){if(e.kind==="local")return new ce(e.file);const t=Sn(e);return e.reading==="whole"?await _l(e.url,t):await Se.open(e.url,{...t,...e.reading==="fine"?{chunkSize:Ll,readAhead:!1}:{}})}async function C5(e){if(e.kind==="local")return e.index===void 0?null:new ce(e.index);const t=`${F5(e.url)}.px2`;try{return await Se.open(t,Sn(e))}catch{return null}}function F5(e){const t=e.search(/[?#]/);return t<0?e:e.slice(0,t)}function Sn(e){return{...e.credential===void 0?{}:{credential:e.credential},...e.headers===void 0?{}:{headers:e.headers}}}function Ol(e){return e===void 0?{}:"accessKeyId"in e?{credential:e}:e}let ke=null,Xe=null;function $5(e,t){return Xe={file:e,source:t},sn(t)}function E5(e){return Xe===null||Xe.file!==e?null:sn(Xe.source)}function ha(e,t,n){return ke={url:e,reading:t,source:n},sn(n)}function sn(e){const t=e.readExact?.bind(e);return{id:e.id,size:e.size,isRemote:e.isRemote,mount:()=>e.mount(),readBytes:(n,s)=>e.readBytes(n,s),...t===void 0?{}:{readExact:t},stats:()=>e.stats(),close:()=>{}}}function B5(e,t){return ke===null||ke.url!==e||ke.reading!==t?(Cn(),null):sn(ke.source)}function Cn(){ke?.source.close(),ke=null,Xe?.source.close(),Xe=null,me?.source.close(),me=null}const fa=128<<20;async function T5(e,t,n={}){const s=t.detail.encodedLength,o=typeof s=="number"?s:null;if(o!==null&&o>fa)throw new T("remote-too-large",`${t.message} Downloading it whole is the only way left to read it, and at ${Math.round(o/(1<<20))} MB encoded that is too much to ask a browser tab for. Download it and drop it here instead.`,{...t.detail,limit:fa});let r;try{const i=await fetch(e,{headers:Fe({url:e,method:"GET",...Ol(n)})});if(!i.ok)throw new Error(`${i.status} ${i.statusText}`);r=new Uint8Array(await i.arrayBuffer())}catch(i){throw new T("remote-compressed",`${t.message} Falling back to downloading it whole also failed: ${i instanceof Error?i.message:String(i)}`,t.detail)}return new ce(r,{name:e})}const Ll=16384,da=2*(1<<30);async function _l(e,t={},n){let s;try{const o=await fetch(e,{headers:Fe({url:e,method:"GET",...Ol(t)})});if(!o.ok)throw new Error(`${o.status} ${o.statusText}`);const r=Number(o.headers.get("Content-Length")??Number.NaN);if(Number.isFinite(r)&&r>da)throw new T("remote-too-large",`${e} is ${(r/(1<<30)).toFixed(1)} GB, which is more than a browser tab can hold in memory. Download it and drop it here instead, where it is read from disk rather than held.`,{url:e,size:r,limit:da});s=await Dl(o,n)}catch(o){throw o instanceof T||D5(o)?o:new T("remote-cors",`Could not download ${e} whole: ${o instanceof Error?o.message:String(o)}`,{url:e,host:Cs(e)})}return new ce(s,{name:e})}let me=null;function O5(e,t){return Cn(),me={url:e,source:t},sn(t)}function L5(e){return me===null?null:me.url!==e?(me.source.close(),me=null,null):sn(me.source)}async function ma(e,t){let n;if(e.kind==="local")n=new Uint8Array(await e.file.arrayBuffer());else{let s;try{s=await fetch(e.url,{headers:Fe({url:e.url,method:"GET",...Sn(e)})})}catch(o){throw new T("remote-cors",`Could not read ${e.url}: ${o instanceof Error?o.message:String(o)}. The host ${Cs(e.url)} must allow this page to GET it.`,{url:e.url,host:Cs(e.url)})}if(!s.ok)throw new T("remote-cors",`${e.url} answered ${s.status} ${s.statusText}.`,{url:e.url,status:s.status});n=await Dl(s,t)}return k5(n,pl(n.length,v5))}function _5(){const e=new Error("cancelled");return e.name="AbortError",e}function D5(e){return e instanceof Error&&e.name==="AbortError"}async function Dl(e,t){const n=Number(e.headers.get("Content-Length")??Number.NaN),s=Number.isFinite(n)&&n>0?n:0,o=R5(e)?0:s,r=e.body,i=t?.onProgress;if(r===null||t===void 0)return new Uint8Array(await e.arrayBuffer());const a=r.getReader(),c=()=>{throw a.cancel(),_5()};let u=0;if(o>0){const l=new Uint8Array(o);for(;;){const{done:h,value:f}=await a.read();if(h)break;if(t.cancelled?.()===!0&&c(),f!==void 0){if(u+f.length>o){const d=[l.subarray(0,u),f];return await ga(a,t,c,d,u+f.length)}l.set(f,u),u+=f.length,i?.(u,o)}}if(i?.(u,o),u<o){const h=e.url??"";throw new T("remote-cors",`${h===""?"The response":h} ended after ${u} bytes, short of the ${o} its \`Content-Length\` promised. The transfer was cut off; a partial file is not opened as though it were whole. Retry it, or download the file and drop it here.`,{url:e.url,received:u,declared:o})}return l}return await ga(a,t,c,[],0)}async function ga(e,t,n,s,o){const r=t.onProgress;for(o>0&&r?.(o,0);;){const{done:c,value:u}=await e.read();if(c)break;t.cancelled?.()===!0&&n(),u!==void 0&&(s.push(u),o+=u.length,r?.(o,0))}const i=new Uint8Array(o);let a=0;for(const c of s)i.set(c,a),a+=c.length;return i}function R5(e){const t=(e.headers.get("Content-Encoding")??"").trim().toLowerCase();return t!==""&&t!=="identity"}function Cs(e){try{return new URL(e).host}catch{return e}}function P5(e){return/\.matrix(\.gz)?$/i.test(e)}function Fs(e){const t=e.replace(/\.matrix(\.gz)?$/i,"").replace(/_iced$/i,"");return[`${t}_abs.bed`,`${t}_abs.bed.gz`]}const xn=9,Pt=10,Rl=13,Pl=35,z5=43,lr=45,q5=46,Et=48,ze=57,U5=69,G5=101;function H5(e,t){const n=[],s=[],o=[0];let r=0,i=0,a=null,c=0,u=!1;const l=new TextDecoder,h=e.length;let f=0;for(;f<h;){if(e[f]===Pt||e[f]===Rl){f++;continue}if(e[f]===Pl||K5(e,f)){for(;f<h&&e[f]!==Pt;)f++;continue}const g=f;for(;f<h&&e[f]!==xn&&e[f]!==Pt;)f++;const p=l.decode(e.subarray(g,f));if(f<h&&e[f]===Pt)throw De(t,i+1,"a row with one column");f++;const w=So(e,f);if(f=w.at,e[f]!==xn)throw De(t,i+1,"a row with two columns");f++;const b=So(e,f);f=b.at;let y=null;if(e[f]===xn){f++;const N=So(e,f);if(f=N.at,!N.saw)throw new T("format",`${t} is a BED whose fourth column holds names rather than bin ids, so it describes features rather than a bin grid — drop it as a track instead. A HiC-Pro bin file numbers its bins 1…n, and is written as \`<prefix>_<res>_abs.bed\`.`,{label:t,row:i+1});y=N.value}for(;f<h&&e[f]!==Pt;)f++;f++;const A=b.value-w.value;if(A<=0)throw De(t,i+1,`an interval of width ${A}`);if(A>r&&(r=A),i++,y!==null&&(u||(a=y),u=!0,c=y),n.length===0||n[n.length-1]!==p){if(n.includes(p))throw De(t,i,`${JSON.stringify(p)} in two separate runs of rows`);n.push(p),s.push(b.value),o.push(i-1)}else s[s.length-1]=b.value}if(i===0)throw De(t,0,"no rows at all");const d=Float64Array.from([...o.slice(1),i]);if(d.length!==n.length+1)throw De(t,i,`${n.length} sequences but ${d.length} offsets`);const m=Q5(n.length,d,s,r);if(a!==null&&(a!==1||c!==i))throw new T("format",`${t} is not a HiC-Pro bin file: its bin ids run ${a}…${c} over ${i} rows, and HiC-Pro numbers them 1…n in row order. If this is an ordinary BED, it describes features rather than a bin grid — drop it as a track instead.`,{label:t,firstId:a,lastId:c,rows:i});return{names:n,lengths:Float64Array.from(s),chromOffset:d,nBins:i,binsize:m?r:null,fixed:m}}function Q5(e,t,n,s){if(s<=0)return!1;for(let o=0;o<e;o++){const r=t[o+1]-t[o],i=(r-1)*s;if(n[o]<=i||n[o]>r*s)return!1}return!0}function K5(e,t){const n="track";if(t+n.length>e.length)return!1;for(let s=0;s<n.length;s++)if(e[t+s]!==n.charCodeAt(s))return!1;return!0}function De(e,t,n){return new T("format",`${e} is not a HiC-Pro bin file: ${n}${t>0?` at row ${t}`:""}. The file beside a \`.matrix\` is \`chrom start end binID\`, one row per bin of the whole genome, and HiC-Pro writes it as \`<prefix>_<res>_abs.bed\`.`,{label:e,row:t})}const W5=()=>{},Y5=()=>!1;async function V5(e,t,n,s={}){const o=e.length;let r=0;for(let k=0;k<o;k++)e[k]===Pt&&r++;if(o>0&&e[o-1]!==Pt&&r++,r===0)throw new T("format",`${n} holds no pixels. A HiC-Pro matrix is \`binA binB count\`, one row per non-zero pixel.`,{label:n});const i=new Int32Array(r),a=new Int32Array(r),c=new Float32Array(r),u=new Uint8Array(r),l={out:0,line:0,sawUpper:!1,sawLower:!1};let h=0,f=0;const d=s.onProgress??W5,m=s.cancelled??Y5;for(;f<o;){const k=J5(e,Math.min(o,f+X5));if(f=Z5(e,f,k,t,n,i,a,c,u,l),await xt(),m())throw n3();d(l.out,r)}const g=l.out,{sawUpper:p,sawLower:w}=l,b=p&&w?"mixed":w?"lower":"upper",y=t3(a,g,t),{order:A,offsets:N}=e3(i,y,g,t),I=new Int32Array(g),M=new Int32Array(g),x=new Float32Array(g),v=new Uint8Array(g);for(let k=0;k<g;k++){const C=A[k];I[k]=i[C],M[k]=a[C],x[k]=c[C],v[k]=u[C]}const S=j5(I,M,x,v,N,t);for(let k=0;k<S.nnz;k++)h+=x[k];return{bin1:I.subarray(0,S.nnz),bin2:M.subarray(0,S.nnz),count:x.subarray(0,S.nnz),binOffset:S.binOffset,nnz:S.nnz,sum:h,observed:b==="mixed"&&S.mirrored>0?"complete":b}}const X5=1<<23;function J5(e,t){let n=t;for(;n<e.length&&e[n]!==Pt;)n++;return Math.min(e.length,n+1)}function Z5(e,t,n,s,o,r,i,a,c,u){let l=t,h=u.out,f=u.line,d=u.sawUpper,m=u.sawLower;for(;l<n;){if(e[l]===Pt||e[l]===Rl){l++;continue}if(e[l]===Pl){for(;l<n&&e[l]!==Pt;)l++;continue}f++;let g=0,p=!1;for(;l<n;){const x=e[l];if(x<Et||x>ze)break;g=g*10+(x-Et),p=!0,l++}if(!p||e[l]!==xn)throw Co(o,f,s);l++;let w=0,b=!1;for(;l<n;){const x=e[l];if(x<Et||x>ze)break;w=w*10+(x-Et),b=!0,l++}if(!b||e[l]!==xn)throw Co(o,f,s);l++;let y=0,A=!1,N=!1;for(e[l]===lr&&(N=!0,l++);l<n;){const x=e[l];if(x<Et||x>ze)break;y=y*10+(x-Et),A=!0,l++}if(e[l]===q5){l++;let x=.1;for(;l<n;){const v=e[l];if(v<Et||v>ze)break;y+=(v-Et)*x,x/=10,A=!0,l++}}if(e[l]===G5||e[l]===U5){const x=l;l++;let v=1;e[l]===lr?(v=-1,l++):e[l]===z5&&l++;let S=0,k=!1;for(;l<n;){const C=e[l];if(C<Et||C>ze)break;S=S*10+(C-Et),k=!0,l++}k?y*=10**(S*v):l=x}if(!A)throw Co(o,f,s);for(N&&(y=-y);l<n&&e[l]!==Pt;)l++;l++;const I=g-1,M=w-1;if(I<0||M<0||I>=s||M>=s)throw new T("format",`${o} names bin ${g} × ${w} on line ${f}, and the bin file has ${s} bins numbered 1…${s}. The two halves of the pair are for different resolutions, or for different genomes.`,{label:o,line:f,bin1:g,bin2:w,nBins:s});I<M&&(d=!0),I>M&&(m=!0),r[h]=I<=M?I:M,i[h]=I<=M?M:I,a[h]=y,c[h]=I<=M?0:1,h++}return u.out=h,u.line=f,u.sawUpper=d,u.sawLower=m,l}function j5(e,t,n,s,o,r){let i=0,a=0;const c=new Float64Array(r+1);for(let u=0;u<r;u++){const l=o[u],h=o[u+1];c[u]=i;let f=-1;for(let d=l;d<h;d++){if(d>l&&t[d]===t[d-1]){if(s[d]!==f){a++,f=-2;continue}n[i-1]+=n[d];continue}f=s[d],e[i]=u,t[i]=t[d],n[i]=n[d],i++}}return c[r]=i,{nnz:i,binOffset:c,mirrored:a}}function t3(e,t,n){const s=new Int32Array(n+1);for(let r=0;r<t;r++)s[e[r]+1]++;for(let r=0;r<n;r++)s[r+1]+=s[r];const o=new Int32Array(t);for(let r=0;r<t;r++)o[s[e[r]]++]=r;return o}function e3(e,t,n,s){const o=new Float64Array(s+1);for(let a=0;a<n;a++)o[e[a]+1]++;for(let a=0;a<s;a++)o[a+1]+=o[a];const r=Float64Array.from(o),i=new Int32Array(n);for(let a=0;a<n;a++){const c=t[a];i[r[e[c]]++]=c}return{order:i,offsets:o}}function So(e,t){let n=0,s=!1,o=1;for(e[t]===lr&&(o=-1,t++);t<e.length;){const r=e[t];if(r<Et||r>ze)break;n=n*10+(r-Et),s=!0,t++}return{value:n*o,at:t,saw:s}}function Co(e,t,n){return new T("format",`${e} is not a HiC-Pro matrix: line ${t} is not \`binA binB count\`. The bin file beside it has ${n} bins, and the matrix names pairs of them, tab-separated, one pixel per line.`,{label:e,line:t,nBins:n})}function n3(){const e=new Error("cancelled");return e.name="AbortError",e}const ur=["+-","-+","--","++"],ns=[1,2,4,10,20,40],zl=.05,s3=8;function ql(e=s3){const t=1/e,n=Math.ceil(9.001/t),s=new Set([0]);for(let o=0;o<n;o++)s.add(Math.round(10**(o*t)));return[...s].sort((o,r)=>o-r)}const pa=33,Fo=43,$o=45;function o3(e,t){return e===Fo?t===$o?0:t===Fo?3:-1:e===$o?t===Fo?1:t===$o?2:-1:-1}const r3=1024;class i3{constructor(t,n){this.contigs=t,this.pairTypeColumn=n,this.edges=ql(),this.distFreq=ur.map(()=>new Float64Array(this.edges.length)),this.nContigs=t.length,this.densePairs=t.length<=r3?new Float64Array(t.length*t.length):null}total=0;totalUnmapped=0;totalMapped=0;totalDups=0;cis=0;trans=0;cisAtLeast=new Float64Array(ns.length);edges;distFreq;shortTypes=new Float64Array(65536);typeOrder=[];longTypes=new Map;nContigs;densePairs;sparsePairs=new Map;namedPairs=new Map;pairSeen=new Map;decoder=new TextDecoder;pairTypeSeen=!1;add(t,n,s,o,r,i,a,c,u,l,h,f,d){this.total++;let m=!1;if(f>=0&&d>f)if(this.pairTypeSeen=!0,d-f===2){const A=t[f]<<8|t[f+1];this.shortTypes[A]===0&&this.typeOrder.push(String.fromCharCode(t[f],t[f+1])),this.shortTypes[A]++,m=A===17476}else{const A=this.decoder.decode(t.subarray(f,d));this.longTypes.has(A)||this.typeOrder.push(A),this.longTypes.set(A,(this.longTypes.get(A)??0)+1)}const g=o-s===1&&t[s]===pa,p=a-i===1&&t[i]===pa;if(g&&p){this.totalUnmapped++;return}if(g||p)return;if(this.totalMapped++,m){this.totalDups++;return}let w;if(n>=0&&r>=0){w=n===r;const A=n*this.nContigs+r;if(this.densePairs!==null)this.densePairs[A]===0&&this.notePair(this.contigs[n].name,this.contigs[r].name),this.densePairs[A]++;else{const N=this.sparsePairs.get(A);N===void 0&&this.notePair(this.contigs[n].name,this.contigs[r].name),this.sparsePairs.set(A,(N??0)+1)}}else{const A=n>=0?this.contigs[n].name:this.decoder.decode(t.subarray(s,o)),N=r>=0?this.contigs[r].name:this.decoder.decode(t.subarray(i,a));w=A===N;const I=`${A} ${N}`;this.namedPairs.has(I)||this.notePair(A,N),this.namedPairs.set(I,(this.namedPairs.get(I)??0)+1)}if(!w){this.trans++;return}if(this.cis++,c<0||u<0)return;const b=Math.abs(u-c),y=o3(l,h);if(y>=0){const A=this.edges;let N=0,I=A.length;for(;I-N>1;){const M=N+I>>1;A[M]<=b?N=M:I=M}this.distFreq[y][N]++}for(let A=0;A<ns.length;A++)b>=ns[A]*1e3&&this.cisAtLeast[A]++}notePair(t,n){const s=`${t} ${n}`;this.pairSeen.has(s)||this.pairSeen.set(s,this.pairSeen.size)}result(t){const n=c=>c.length===2&&this.longTypes.get(c)===void 0?this.shortTypes[c.charCodeAt(0)<<8|c.charCodeAt(1)]:this.longTypes.get(c)??0,s=this.typeOrder.map((c,u)=>({name:c,count:n(c),order:u})).sort((c,u)=>u.count-c.count||c.order-u.order).map(({name:c,count:u})=>[c,u]),o=[],r=this.nContigs;if(this.densePairs!==null)for(let c=0;c<this.densePairs.length;c++){const u=this.densePairs[c];u>0&&o.push({name1:this.contigs[Math.floor(c/r)].name,name2:this.contigs[c%r].name,count:u})}else for(const[c,u]of this.sparsePairs)o.push({name1:this.contigs[Math.floor(c/r)].name,name2:this.contigs[c%r].name,count:u});for(const[c,u]of this.namedPairs){const[l,h]=c.split(" ");o.push({name1:l,name2:h,count:u})}const i=c=>this.pairSeen.get(`${c.name1} ${c.name2}`)??0;o.sort((c,u)=>u.count-c.count||i(c)-i(u));const a={};return ur.forEach((c,u)=>{a[c]=Array.from(this.distFreq[u])}),{total:this.total,totalUnmapped:this.totalUnmapped,totalSingleSidedMapped:this.total-this.totalMapped-this.totalUnmapped,totalMapped:this.totalMapped,totalDups:this.totalDups,totalNodups:this.totalMapped-this.totalDups,cis:this.cis,trans:this.trans,pairTypes:s,cisAtLeast:ns.map((c,u)=>[c,this.cisAtLeast[u]]),chromFreq:o.map(({name1:c,name2:u,count:l})=>[c,u,l]),distEdges:[...this.edges],distFreq:a,chromsizes:this.contigs.map(c=>[c.name,c.length]),pairTypeColumn:this.pairTypeColumn&&this.pairTypeSeen,scoped:t}}}const Ge=["++","--","-+","+-"];function Ul(e,t=zl){const n=l=>e.distFreq[l],s=e.distEdges.length,o=new Float64Array(s);for(let l=0;l<s;l++){let h=0;for(const f of Ge)h+=n(f)[l];o[l]=h/Ge.length}let r=0,i=null;for(const l of Ge){let h=0;for(let f=0;f<s;f++)(o[f]===0?0:Math.abs(n(l)[f]-o[f])/o[f])>t&&(h=f);h>r&&(r=h,i=l)}const a={};let c=0,u=0;for(const l of Ge){let h=0,f=0;n(l).forEach((d,m)=>{m<=r?h+=d:f+=d}),a[l]=h,c+=h,u+=f}return{distance:i===null?null:e.distEdges[r+1]??Number.MAX_SAFE_INTEGER,strands:i,below:a,belowAll:c,aboveAll:u,binIndex:r}}function a3(e,t){if(e===0)return 0;const n=(e-t)/e;return n===0?0:e/(c3(-Math.exp(-1/n)/n)+1/n)}function c3(e){if(e===0)return 0;const t=-Math.exp(-1);if(e<=t)return Number.NaN;const n=Math.sqrt(2*(Math.E*e+1));let s=e<-.25?-1+n-n*n/3+11/72*n*n*n:e;for(let o=0;o<64;o++){const r=Math.exp(s),i=s*r-e,a=s+1;if(a===0)break;const c=i/(r*a-(s+2)*i/(2*a)),u=s-c;if(!Number.isFinite(u))break;if(Math.abs(u-s)<=1e-16*Math.max(1,Math.abs(u)))return u;s=u}return s}function l3(e){const t=l=>({int:l}),n=(l,h)=>h>0?{float:l/h}:t(0),s=(l,h)=>({float:l/h}),o=[["total",t(e.total)],["total_unmapped",t(e.totalUnmapped)],["total_single_sided_mapped",t(e.totalSingleSidedMapped)],["total_mapped",t(e.totalMapped)],["total_dups",t(e.totalDups)],["total_nodups",t(e.totalNodups)],["cis",t(e.cis)],["trans",t(e.trans)]];for(const[l,h]of e.pairTypes)o.push([`pair_types/${l}`,t(h)]);for(const[l,h]of e.cisAtLeast)o.push([`cis_${l}kb+`,t(h)]);o.push(["summary/frac_cis",n(e.cis,e.totalNodups)]);for(const[l,h]of e.cisAtLeast)o.push([`summary/frac_cis_${l}kb+`,n(h,e.totalNodups)]);o.push(["summary/frac_dups",n(e.totalDups,e.totalMapped)]);const r=a3(e.totalMapped,e.totalDups);o.push(["summary/complexity_naive",e.totalMapped===0||r===0?t(0):{float:r}]);const i=Ul(e),a="summary/dist_freq_convergence";o.push([`${a}/convergence_dist`,i.distance===null?{text:"0"}:t(i.distance)]),o.push([`${a}/strands_w_max_convergence_dist`,{text:i.strands??"??"}]),o.push([`${a}/convergence_rel_diff_threshold`,{float:zl}]);for(const l of Ge)o.push([`${a}/n_cis_pairs_below_convergence_dist/${l}`,t(i.below[l])]);o.push([`${a}/n_cis_pairs_below_convergence_dist_all_strands`,t(i.belowAll)]),o.push([`${a}/n_cis_pairs_above_convergence_dist_all_strands`,t(i.aboveAll)]);const c=[["cis",e.cis],["total_mapped",e.totalMapped],["total_nodups",e.totalNodups]];for(const[l,h]of c){let f=0;for(const d of Ge){const m=i.below[d]/h;f+=m,o.push([`${a}/frac_${l}_in_cis_below_convergence_dist/${d}`,s(i.below[d],h)])}o.push([`${a}/frac_${l}_in_cis_below_convergence_dist_all_strands`,{float:f}]),o.push([`${a}/frac_${l}_in_cis_above_convergence_dist_all_strands`,s(i.aboveAll,h)])}for(const[l,h,f]of e.chromFreq)o.push([`chrom_freq/${l}/${h}`,t(f)]);const u=e.distEdges;for(let l=0;l<u.length;l++){const h=l<u.length-1?`${u[l]}-${u[l+1]}`:`${u[l]}+`;for(const f of ur)o.push([`dist_freq/${h}/${f}`,t(e.distFreq[f][l])])}for(const[l,h]of e.chromsizes)o.push([`chromsizes/${l}`,t(h)]);return o}function u3(e){return"text"in e?e.text:"int"in e?String(e.int):h3(e.float)}function h3(e){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(e===0)return Object.is(e,-0)?"-0.0":"0.0";const[t,n]=e.toExponential().split("e"),s=Number(n),o=t.startsWith("-"),r=t.replace("-","").replace(".",""),i=o?"-":"";if(s<-4||s>=16){const u=r.length>1?`${r[0]}.${r.slice(1)}`:r,l=Math.abs(s);return`${i}${u}e${s<0?"-":"+"}${l<10?`0${l}`:l}`}if(s<0)return`${i}0.${"0".repeat(-s-1)}${r}`;const a=r.slice(0,s+1).padEnd(s+1,"0"),c=r.slice(s+1);return`${i}${a}.${c===""?"0":c}`}const f3=9,d3=35,Eo=1<<20;class m3{unique=new Map;ambiguous=new Map;byName=new Map;decoder=new TextDecoder;constructor(t){for(let n=0;n<t.length;n++){const s=t[n].name;this.byName.set(s,n);const o=g3(s),r=this.unique.get(o);if(r===void 0&&!this.ambiguous.has(o)){this.unique.set(o,n);continue}const i=this.ambiguous.get(o)??[];r!==void 0&&(i.push([t[r].name,r]),this.unique.delete(o)),i.push([s,n]),this.ambiguous.set(o,i)}}lookup(t,n,s){let o=2166136261;for(let c=n;c<s;c++)o^=t[c],o=Math.imul(o,16777619);o|=0;const r=this.unique.get(o);if(r!==void 0)return r;const i=this.ambiguous.get(o);if(i===void 0)return-1;const a=this.decoder.decode(t.subarray(n,s));for(const[c,u]of i)if(c===a)return u;return-1}of(t){return this.byName.get(t)??-1}}function g3(e){let t=2166136261;const n=new TextEncoder().encode(e);for(let s=0;s<n.length;s++)t^=n[s],t=Math.imul(t,16777619);return t|0}const p3=1.05;function w3(e){const t=[0,1];let n=1;for(;n<e;)n=Math.max(n+1,Math.round(n*p3)),t.push(n);return Float64Array.from(t)}function b3(e,t){return e===Bo?t===Bo?0:t===To?1:-1:e===To?t===Bo?2:t===To?3:-1:-1}const Bo=43,To=45;async function Hr(e,t){const{binSize:n,contigs:s,columns:o}=t,r=t.oneBased??!0,i=kl(s,n),a=Sl(s,n),c=new m3(s),u=s.length,l=o.strand1>=0&&o.strand2>=0,h=o.pairType??-1,f=Math.max(o.chrom1,o.chrom2,o.pos1,o.pos2,...l?[o.strand1,o.strand2]:[],h),d=new i3(s,h>=0),m=t.onRecord;let g=0;for(const U of s)g=Math.max(g,U.length);const p=l?w3(g):null,w=p===null?null:[new Float64Array(p.length-1),new Float64Array(p.length-1),new Float64Array(p.length-1),new Float64Array(p.length-1)];let b=0;const y=new Int32Array(s.length);for(let U=0;U<s.length;U++)y[U]=Math.max(0,Math.ceil(s[U].length/n)-1);const A=new Int32Array(a);let N=new Int32Array(Math.min(a,65536)),I=0,M=new Int32Array(Eo),x=new Int32Array(Eo),v=new Int32Array(Eo),S=0,k=-1,C=0,B=0,F=0,E=0,_=0,$=!1,O=!1,L=-1;const D=new Set;let q=!1,X=!1;const P=new Uint8Array(s.length);let z=null;const R=t.maxPixelBytes===void 0?1/0:Math.floor(t.maxPixelBytes/12),H=()=>{if(I===0)return;const U=N.subarray(0,I);if(U.sort(),S+I>R)throw z=new T("dense-too-large",`Binning this file at ${n} bp produces more stored pixels than the memory budget allows. Choose a coarser base resolution, or import fewer sequences.`,{binSize:n,nnz:S,limitBytes:t.maxPixelBytes}),z;for(;S+I>M.length;)M=ss(M),x=ss(x),v=ss(v);for(let V=0;V<I;V++){const Z=U[V];M[S]=k,x[S]=Z,v[S]=A[Z],S++,A[Z]=0}I=0},K=t.expectedRecords??0,G=U=>{if(U.length===0||U[0]===d3)return;let V=0,Z=0,J=-1,ot=-1,it=-1,lt=-1,ut=-1,vt=-1,gt=0,St=0,mt=0,At=0,yt=-1,ne=-1;const qt=U.length;for(let rt=0;rt<=qt;rt++)if(!(rt!==qt&&U[rt]!==f3)){if(V===o.chrom1?(J=c.lookup(U,Z,rt),gt=Z,St=rt):V===o.chrom2?(ot=c.lookup(U,Z,rt),mt=Z,At=rt):V===h?(yt=Z,ne=rt):V===o.pos1?it=wa(U,Z,rt):V===o.pos2?lt=wa(U,Z,rt):l&&V===o.strand1?ut=rt>Z?U[Z]:-1:l&&V===o.strand2&&(vt=rt>Z?U[Z]:-1),V++,V>f)break;Z=rt+1}if(d.add(U,J,gt,St,ot,mt,At,it,lt,ut,vt,yt,ne),m!==void 0&&m(U,J,gt,St,ot,mt,At,it,lt,ut,vt,yt,ne),J<0||ot<0){F++;return}if(it<0||lt<0){E++;return}if(w!==null&&p!==null&&J===ot){const rt=b3(ut,vt);if(rt>=0){const Ot=Math.abs(lt-it);let ue=0,he=p.length-1;for(;ue+1<he;){const se=ue+he>>1;p[se]<=Ot?ue=se:he=se}w[rt][ue]++,b++}}let pt=W(it),$t=W(lt);if(pt>y[J]&&(pt=y[J],_++),$t>y[ot]&&($t=y[ot],_++),pt+=i[J],$t+=i[ot],pt>$t){const rt=pt;pt=$t,$t=rt}J===ot&&(P[J]=1);let on=!1;if(!O){const rt=J<=ot?J*u+ot:ot*u+J;rt!==L&&(on=!0,L>=0&&D.add(L),D.has(rt)&&(O=!0,D.clear()),L=rt)}pt!==k&&(pt<k&&($=!0,on||(O=!0)),H(),k=pt),A[$t]===0&&(I===N.length&&(N=ss(N)),N[I++]=$t),A[$t]++,C++,B++};function W(U){const V=r?U-1:U;return V<0?0:Math.floor(V/n)}const Y=t.spans??[{from:0,to:e.size}],tt=Y.reduce((U,V)=>U+Math.max(0,V.to-V.from),0);let et=0;try{for(const U of Y){const V={from:U.from,to:U.to,onProgress:J=>{K>0?t.onProgress?.(C,K,"reading records"):t.onProgress?.(et+J,tt,"reading records")}};t.cancelled!==void 0&&(V.cancelled=t.cancelled),t.spans===void 0&&(V.onFraming=J=>{X=!0,(J.partialMember||!J.endedOnEofMarker)&&(q=!0)});const Z=await Pr(Rr(e,V),G,t.cancelled);if(et+=Math.max(0,U.to-U.from),!Z||t.cancelled?.()===!0)return null}H()}catch(U){throw z!==null?z:U}const ht={binSize:n,contigs:[...s],chromOffset:i,nBins:a,bin1:M.subarray(0,S),bin2:x.subarray(0,S),count:v.subarray(0,S),nnz:S,sum:B,skippedUnknownContig:F,skippedBadPosition:E,clampedPosition:_,wasUnsorted:O,truncated:X&&q,contigsWithoutCisContacts:s.filter((U,V)=>P[V]===0).map(U=>U.name),orientation:p===null||w===null?null:{edges:p,counts:w,total:b},stats:d.result(t.spans!==void 0)};return $?A3(ht):ht}function ss(e){const t=new Int32Array(e.length*2);return t.set(e),t}function wa(e,t,n){if(n<=t)return-1;let s=0;for(let o=t;o<n;o++){const r=e[o]-48;if(r<0||r>9)return-1;s=s*10+r}return s}function A3(e){const{nnz:t,nBins:n}=e,s=new Int32Array(n+1);for(let h=0;h<t;h++)s[e.bin1[h]+1]++;for(let h=0;h<n;h++)s[h+1]+=s[h];const o=s.slice(0,n),r=new Int32Array(t),i=new Int32Array(t);for(let h=0;h<t;h++){const f=o[e.bin1[h]]++;r[f]=e.bin2[h],i[f]=e.count[h]}const a=new Int32Array(t),c=new Int32Array(t),u=new Int32Array(t);let l=0;for(let h=0;h<n;h++){const f=s[h],d=s[h+1];if(d<=f)continue;let m=!0;for(let w=f+1;w<d;w++)if(r[w]<r[w-1]){m=!1;break}const g=m?null:Array.from({length:d-f},(w,b)=>f+b);g?.sort((w,b)=>r[w]-r[b]);let p=-1;for(let w=0;w<d-f;w++){const b=g===null?f+w:g[w],y=r[b];if(y===p){u[l-1]+=i[b];continue}a[l]=h,c[l]=y,u[l]=i[b],l++,p=y}}return{...e,bin1:a.subarray(0,l),bin2:c.subarray(0,l),count:u.subarray(0,l),nnz:l}}const Gl=[1,2,5,10,20,50,100,200,500,1e3,2e3,5e3,1e4],y3=Gl.length;function N3(e,t){const n=Math.max(1,Math.min(t,y3));return Gl.slice(0,n).map(s=>e*s)}function M3(e,t){const n=new Int32Array(t);for(let s=0;s+1<e.length;s++){const o=e[s],r=e[s+1];for(let i=o;i<r&&i<t;i++)n[i]=s}return n}async function I3(e,t,n={}){if(t===e.binSize)return e;if(t%e.binSize!==0)throw new Error(`A ladder rung must be a whole multiple of the base: ${t} is not a multiple of ${e.binSize}.`);const s=t/e.binSize,o=e.contigs,r=kl(o,t),i=Sl(o,t),a=M3(e.chromOffset,e.nBins),c=A=>{const N=a[A];return r[N]+Math.floor((A-e.chromOffset[N])/s)},u=new Int32Array(i);let l=new Int32Array(Math.min(i,65536)),h=0,f=new Int32Array(Math.min(e.nnz,1<<20)||1),d=new Int32Array(f.length),m=new Int32Array(f.length),g=0,p=-1,w=0;const b=()=>{if(h===0)return;const A=l.subarray(0,h);for(A.sort();g+h>f.length;)f=os(f),d=os(d),m=os(m);for(let N=0;N<h;N++){const I=A[N];f[g]=p,d[g]=I,m[g]=u[I],g++,u[I]=0}h=0},y=1<<20;for(let A=0;A<e.nnz;A+=y){if(n.cancelled?.()===!0)return null;const N=Math.min(A+y,e.nnz);for(let I=A;I<N;I++){const M=c(e.bin1[I]),x=c(e.bin2[I]);M!==p&&(b(),p=M),u[x]===0&&(h===l.length&&(l=os(l)),l[h++]=x),u[x]+=e.count[I],w+=e.count[I]}n.onProgress?.(N,e.nnz,`aggregating to ${t} bp`),await xt()}return b(),{binSize:t,contigs:[...o],chromOffset:r,nBins:i,bin1:f.subarray(0,g),bin2:d.subarray(0,g),count:m.subarray(0,g),nnz:g,sum:w,skippedUnknownContig:e.skippedUnknownContig,skippedBadPosition:e.skippedBadPosition,clampedPosition:e.clampedPosition,wasUnsorted:e.wasUnsorted,truncated:e.truncated,contigsWithoutCisContacts:[...e.contigsWithoutCisContacts]}}function os(e){const t=new Int32Array(Math.max(1,e.length*2));return t.set(e),t}const x3=[{magic:"PX2.004",wideLinecount:!0},{magic:"PX2.003",wideLinecount:!1},{magic:"PX2.002",wideLinecount:!1}],ba=[36,40,44];function v3(e){if(e.length<20)throw new T("format","This .px2 index is too short to hold a header.",{bytes:e.length});const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=String.fromCharCode(...e.subarray(0,8)),s=x3.find(w=>w.magic===n);if(s===void 0)throw new T("format","This is not a pairix index: the magic bytes are not PX2. A `.tbi` cannot be used for a pairs file — build one with `pairix <file>.pairs.gz`.",{magic:n.replace(/[^\x20-\x7e]/g,"?")});const o=t.getInt32(8,!0);let r=12,i;s.wideLinecount?(i=Number(t.getBigUint64(r,!0)),r+=8):(i=t.getUint32(r,!0),r+=4);const a=k3(t,e,r,o),{splitChar:c,metaChar:u,lineSkip:l,namesAt:h,nameBytes:f}=a,d=[],m=new TextDecoder().decode(e.subarray(h,h+f));for(const w of m.split("\0"))w!==""&&d.push(w);let g=h+f;const p=new Map;for(let w=0;w<o&&!(g+4>e.length);w++){const b=t.getInt32(g,!0);g+=4;let y=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY;for(let I=0;I<b&&!(g+8>e.length);I++){g+=4;const M=t.getInt32(g,!0);g+=4;for(let x=0;x<M&&!(g+16>e.length);x++){const v=Number(t.getBigUint64(g,!0)>>16n),S=Number(t.getBigUint64(g+8,!0)>>16n);g+=16,v<y&&(y=v),S>A&&(A=S)}}if(g+4>e.length)break;const N=t.getInt32(g,!0);g+=4;for(let I=0;I<N&&!(g+8>e.length);I++){const M=Number(t.getBigUint64(g,!0)>>16n);g+=8,M>0&&M<y&&(y=M)}Number.isFinite(y)&&Number.isFinite(A)&&w<d.length&&p.set(d[w],{from:y,to:A})}return{keys:d,spans:p,linecount:i,splitChar:c,metaChar:u,lineSkip:l}}function k3(e,t,n,s){const o=[];for(const r of ba){const i=n+r;if(i+4>t.length)continue;const a=e.getInt32(i,!0),c=i+4;if(o.push(a),a<=0||c+a>t.length||new TextDecoder().decode(t.subarray(c,c+a)).split("\0").filter(h=>h!=="").length!==s)continue;const l=n+28;return{splitChar:String.fromCharCode(t[l+1]||124),metaChar:String.fromCharCode(t[l+2]||35),lineSkip:e.getInt32(n+32,!0),namesAt:c,nameBytes:a}}throw new T("format",`This .px2 index has a header this reader cannot lay out: no candidate config size produced a coherent name block for ${s} references. Rebuild it with \`pairix <file>.pairs.gz\`, or open the file without an index.`,{nRef:s,candidates:ba,sawNameBytes:o})}async function S3(e){const t=await e();if(t===null)return null;try{const n=t.readBytes(0,t.size);return v3(await Tl(n))}finally{t.close()}}function C3(e,t,n){const s=[];for(const r of t){const i=e.spans.get(r);i!==void 0&&s.push({from:i.from,to:F3(n,i.to)})}s.sort((r,i)=>r.from-i.from);const o=[];for(const r of s){const i=o[o.length-1];i!==void 0&&r.from<=i.to+(1<<20)?i.to=Math.max(i.to,r.to):o.push({...r})}return o}function F3(e,t){if(t>=e.size)return e.size;const n=e.readBytes(t,Math.min(ua,e.size-t)),s=Gr(n);return s===null?Math.min(e.size,t+ua):Math.min(e.size,t+s)}async function $3(e,t){const n=await Ys(e);let s=null;try{s=await S3(t)}catch(r){if(!(r instanceof T))throw r;s=null}let o=0;for(const r of n.contigs)o+=r.length;return{header:n,index:s,records:s?.linecount??null,genomeLength:o,sourceBytes:e.size}}async function E3(e,t,n){const s=N3(n.base,n.rungs),o=n.maxPixelBytes??sl(),r=.85,i=(h,f)=>{n.onProgress?.(Math.round(h*1e3),1e3,f)},a=n.keys===void 0?void 0:B3(t,n.keys,e),c={binSize:n.base,contigs:t.header.contigs,columns:t.header.columns,oneBased:n.oneBased??!0,maxPixelBytes:o,onProgress:(h,f,d)=>{i(f>0?h/f*r:0,d??"reading records")}};a!==void 0&&(c.spans=a),t.records!==null&&(c.expectedRecords=t.records),n.cancelled!==void 0&&(c.cancelled=n.cancelled);const u=await Hr(e,c);if(u===null)return null;const l=new Map([[n.base,u]]);for(let h=1;h<s.length;h++){const f=s[h],d=await I3(u,f,{onProgress:(m,g)=>{const p=g>0?m/g:1,w=(h-1+p)/Math.max(1,s.length-1);i(r+w*(1-r),`building the ${T3(f)} rung`)},...n.cancelled===void 0?{}:{cancelled:n.cancelled}});if(d===null)return null;l.set(f,d)}return i(1,"done"),{header:t.header,rungs:s,tables:l,indexed:t.index!==null,declaredRecords:t.records}}function B3(e,t,n){if(e.index===null)return;const s=C3(e.index,t,n);return s.length===0?void 0:s}function T3(e){return e>=1e6&&e%1e6===0?`${e/1e6} Mb`:e>=1e3&&e%1e3===0?`${e/1e3} kb`:`${e} bp`}async function Hl(e,t,n={}){const s=await P3(t);return s===null?await O3(e,t,n):await D3(e,t,s,n)}async function O3(e,t,n){const s=n.detached===!0?await cr(t):await S5(t,{...n.report===void 0?{}:{onProgress:(r,i)=>n.report?.(r,i,"downloading")},...n.cancelled===void 0?{}:{cancelled:n.cancelled},...n.report===void 0||!Aa(e)?{}:{onRead:(r,i)=>n.report?.(i,0,`listing cells · ${r.toLocaleString()} reads`)}}),o=t.kind==="remote"&&t.reading!==void 0;Aa(e)&&n.report?.(0,0,"listing cells");try{return{mc:await wt.open(e,s,{...o?{listingAgreed:!0}:{},...n.metacool===void 0?{}:{metacool:n.metacool}}),source:s}}catch(r){const i=n.binning;if(i===void 0||!(r instanceof T)||r.code!=="pairs-binning-needed")throw r;return{mc:await L3(e,t,s,i,n),source:s}}}async function L3(e,t,n,s,o){const r=await $3(n,()=>C5(t)),i=await E3(n,r,{base:s.base,rungs:s.rungs,oneBased:s.oneBased??!0,...o.report===void 0?{}:{onProgress:(c,u,l)=>o.report?.(c,u,l??"binning records")},...o.cancelled===void 0?{}:{cancelled:o.cancelled}});if(i===null)throw _3();const a=i.tables.get(i.rungs[0]);if(a===void 0)throw new T("format",`${e} imported no pixel table.`);return wt.fromPairs({uri:e,header:i.header,pixels:a,rungs:i.rungs,indexed:i.indexed,declaredRecords:i.declaredRecords})}function _3(){const e=new Error("open cancelled");return e.name="AbortError",e}async function D3(e,t,n,s){const o=hr(n),r=hr(t),i=l=>({...s.report===void 0?{}:{onProgress:(h,f)=>s.report?.(h,f,l)},...s.cancelled===void 0?{}:{cancelled:s.cancelled}}),a=await ma(n,i("reading the bins")),c=H5(a,o);await U3(t,r,c.nBins);const u=await ma(t,i("downloading the matrix"));return R3(e,{bytes:u,name:r},c,o,a.length,s)}async function R3(e,t,n,s,o,r={}){const i=await V5(t.bytes,n.nBins,t.name,{...r.cancelled===void 0?{}:{cancelled:r.cancelled},...r.report===void 0?{}:{onProgress:(c,u)=>r.report?.(c,u,"reading pixels")}});return{mc:wt.fromHicPro(e,{bins:n,pixels:i,matrixName:t.name,binsName:s}),source:H3(t.name,o+t.bytes.length)}}async function P3(e){const t=hr(e);if(!P5(t))return null;if(e.bins!==void 0)return e.bins;if(e.kind==="remote"){const n=await z3(e.url,e.credential,e.headers);if(n!==null)return n}throw new T("hicpro-no-bins",`${t} is a HiC-Pro matrix, which is half of a contact map: the bin file beside it — ${Fs(t).join(" or ")} — is what says which genomic interval each bin id means, and there are no coordinates without it. Drop the two together, pick the matrix out of a connected folder so its bin file comes with it, or name the bin file on the URL as \`<matrix>#bins=<url>\`.`,{matrix:t,wanted:Fs(t)})}async function z3(e,t,n){if(qr(e))return null;const s=e.lastIndexOf("/"),o=s<0?"":e.slice(0,s+1),r=e.slice(s+1),i=Fs(r).map(c=>`${o}${c}`);if(o.includes("/iced/"))for(const c of Fs(r))i.push(`${o.replace("/iced/","/raw/")}${c}`);const a={...t===void 0?{}:{credential:t},...n===void 0?{}:{headers:n}};for(const c of i)try{if((await fetch(c,{method:"HEAD",headers:Fe({url:c,method:"HEAD",...a})})).ok)return{kind:"remote",url:c,...a}}catch{}return null}function Aa(e){return/\.scool(\.gz)?(\?|#|$)/i.test(e)}const q3=200<<20;async function U3(e,t,n){if(e.reading!==void 0)return;const s=await G3(e);if(s===null||s<=q3)return;const o=Math.round(s/15);throw new T("hicpro-load-cost",`${t} is ${Math.round(s/(1<<20))} MB of text, and a HiC-Pro matrix has no index — so the whole of it is read and turned into about ${o.toLocaleString()} pixels over ${n.toLocaleString()} bins before anything can be drawn. That is the only cost: afterwards every region is instant and panning is free.`,{matrix:t,bytes:s,pixels:o,nBins:n})}async function G3(e){if(e.kind==="local")return e.file.size;if(qr(e.url))return null;try{const t=await fetch(e.url,{method:"HEAD",headers:Fe({url:e.url,method:"HEAD",...e.credential===void 0?{}:{credential:e.credential},...e.headers===void 0?{}:{headers:e.headers}})}),n=Number(t.headers.get("Content-Length")??Number.NaN);return Number.isFinite(n)?n:null}catch{return null}}function hr(e){const t=e.kind==="local"?e.file.name:e.url;return t.split(/[\\/]/).pop()?.split(/[?#]/)[0]??t}function H3(e,t){return{id:e,size:t,isRemote:!1,mount:()=>Promise.resolve(e),readBytes(){throw new T("unsupported",`${e} was read whole and parsed at open; there are no bytes left to read from it. A read reaching here is a code path that bypassed the parsed arrays.`,{id:e})},stats:()=>({requests:1,bytes:t}),close:()=>{}}}const Qr=3;function Ql(e,t){const n=Math.min(e.length,t.length);let s=0,o=0,r=0;for(let h=0;h<n;h++){const f=e[h],d=t[h];Number.isNaN(f)||Number.isNaN(d)||(o+=f,r+=d,s++)}if(s<Qr)return Number.NaN;const i=o/s,a=r/s;let c=0,u=0,l=0;for(let h=0;h<n;h++){const f=e[h],d=t[h];if(Number.isNaN(f)||Number.isNaN(d))continue;const m=f-i,g=d-a;c+=m*g,u+=m*m,l+=g*g}return u<=0||l<=0?Number.NaN:c/Math.sqrt(u*l)}function Kl(e,t){const n=Math.min(e.length,t.length);let s=0;for(let a=0;a<n;a++)!Number.isNaN(e[a])&&!Number.isNaN(t[a])&&s++;if(s<Qr)return Number.NaN;const o=new Float64Array(s),r=new Float64Array(s);let i=0;for(let a=0;a<n;a++){const c=e[a],u=t[a];Number.isNaN(c)||Number.isNaN(u)||(o[i]=c,r[i]=u,i++)}return Ql(ya(o),ya(r))}function ya(e){const t=e.length,n=new Float64Array(t),s=[];for(let r=0;r<t;r++)Number.isNaN(e[r])?n[r]=Number.NaN:s.push(r);s.sort((r,i)=>e[r]-e[i]);let o=0;for(;o<s.length;){let r=o+1;for(;r<s.length&&e[s[r]]===e[s[o]];)r++;const i=(o+r+1)/2;for(let a=o;a<r;a++)n[s[a]]=i;o=r}return n}function Q3(e,t){const n=Math.max(1,Math.trunc(t)),s=Y3(e);if(s.length===0)return new Float64Array(0);const o=new Float64Array(n+1);for(let r=0;r<=n;r++)o[r]=V3(s,r/n);return o}const K3=16384;function W3(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=e)return new Float64Array(0);const s=Number.isFinite(n)&&n>1?n:1+1e-6,o=[e];let r=e;for(;r<t&&o.length<K3;)r*=s,o.push(r);return Float64Array.from(o)}function Y3(e){let t=0;for(let o=0;o<e.length;o++)Number.isNaN(e[o])||t++;const n=new Float64Array(t);let s=0;for(let o=0;o<e.length;o++){const r=e[o];Number.isNaN(r)||(n[s]=r,s++)}return n.sort(),n}function V3(e,t){const n=e.length;if(n===0)return Number.NaN;if(n===1)return e[0];const s=Math.min(1,Math.max(0,t))*(n-1),o=Math.floor(s),r=Math.min(n-1,o+1),i=s-o;return e[o]+i*(e[r]-e[o])}class Fn{maxOffset;sum;count;lap;constructor(t,n=0){this.maxOffset=Math.max(0,Math.trunc(t)),this.sum=new Float64Array(this.maxOffset+1),this.count=new Float64Array(this.maxOffset+1),this.lap=Math.max(0,Math.trunc(n))}separation(t,n){const s=Math.abs(t-n);return this.lap>0?Math.min(s,this.lap-s):s}add(t,n){if(t<0||t>this.maxOffset||Number.isNaN(n))return;const s=t|0;this.sum[s]+=n,this.count[s]+=1}addBlock(t){const{nrows:n,ncols:s,values:o}=t,r=t.rowExtent[0],i=t.colExtent[0];for(let a=0;a<n;a++){const c=r+a,u=a*s;for(let l=0;l<s;l++){const h=o[u+l];if(Number.isNaN(h))continue;const f=this.separation(i+l,c);f>this.maxOffset||(this.sum[f]+=h,this.count[f]+=1)}}}merge(t){const n=Math.min(this.sum.length,t.sum.length);for(let s=0;s<n;s++)this.sum[s]+=t.sum[s],this.count[s]+=t.count[s]}finish(){const t=new Float64Array(this.sum.length);for(let n=0;n<t.length;n++)t[n]=this.count[n]>0?this.sum[n]/this.count[n]:Number.NaN;return{maxOffset:this.maxOffset,sum:this.sum.slice(),count:this.count.slice(),mean:t}}}function Kr(e,t,n,s){const o=t>0?t:1,r=Number.isFinite(s)?s:0,i=Math.max(1,Math.ceil(r)),a=W3(i,e.maxOffset+1,n),c=[],u=[],l=[];for(let h=0;h+1<a.length;h++){const f=Math.max(i,Math.ceil(a[h])),d=Math.min(e.maxOffset+1,Math.ceil(a[h+1]));let m=0,g=0,p=0;for(let w=f;w<d;w++){const b=e.count[w];b<=0||(m+=e.sum[w],g+=b,p+=b*w)}g<=0||(c.push(p/g*o),u.push(m/g),l.push(g))}return{x:Float64Array.from(c),y:Float64Array.from(u),n:Float64Array.from(l)}}function Wl(e,t){const n=Math.min(e.length,t.length),s=Math.max(0,n-2),o=new Float64Array(s),r=new Float64Array(s);for(let i=1;i+1<n;i++){o[i-1]=e[i];const a=e[i-1],c=e[i+1],u=t[i-1],l=t[i+1],h=Math.log(c)-Math.log(a),f=a>0&&c>0&&u>0&&l>0&&h!==0;r[i-1]=f?(Math.log(l)-Math.log(u))/h:Number.NaN}return{x:o,y:r}}function Wr(e,t){if(!Number.isFinite(t)||t<0||t>e.maxOffset)return Number.NaN;const{mean:n}=e,s=Math.floor(t);if(s===t&&!Number.isNaN(n[s]))return n[s];let o=s;for(;o>=0&&Number.isNaN(n[o]);)o--;let r=Math.ceil(t);for(;r<=e.maxOffset&&Number.isNaN(n[r]);)r++;if(o<0||r>e.maxOffset)return Number.NaN;const i=(t-o)/(r-o);return n[o]+i*(n[r]-n[o])}function X3(e,t){const n=Number.isFinite(e)&&e>1?e:1.1,s=Number.isFinite(t)&&t>0?t:0,o=[];let r=-1;for(let a=0;o.length<4096;a++){const c=Math.round(Math.pow(n,a));if(c!==r&&(o.push(c),r=c,c>s&&o.length>=2))break}const i=new Float64Array(o.length-1);for(let a=0;a+1<o.length;a++)i[a]=o[a+1]-o[a];return{pos:Float64Array.from(o),width:i}}function J3(e,t){const n=e.length-2;if(n<0||t<e[0])return 0;let s=0,o=n;for(;s<o;){const r=s+o+1>>1;e[r]<=t?s=r:o=r-1}return s}function Z3(e,t,n,s,o){const r=t>0?t:1,i=Math.max(0,Math.ceil(Number.isFinite(s)?s:0)),a=o?2:1,c=X3(n,Math.max(0,e.maxOffset-1)*r),u=c.width.length,l=new Float64Array(u),h=new Float64Array(u),f=new Int32Array(u);let d=0;for(let w=i;w<=e.maxOffset;w++){const b=J3(c.pos,(w-1)*r);f[b]+=1;const y=e.count[w];if(!(y>0))continue;const A=w===0?1:a,N=e.sum[w]/A;Number.isNaN(N)||(l[b]+=N,h[b]+=y/A,d+=N)}if(!(d>0))return{x:new Float64Array(0),y:new Float64Array(0),n:new Float64Array(0)};const m=[],g=[],p=[];for(let w=0;w<u;w++)h[w]<=0||(m.push(c.pos[w]),g.push(l[w]/d/(f[w]*r)),p.push(h[w]));return{x:Float64Array.from(m),y:Float64Array.from(g),n:Float64Array.from(p)}}const j3="AGFzbQEAAAABEAFgDH9/f39/f39/f39/fwACDwEDZW52Bm1lbW9yeQIAAgMDAgAABAUBcAEBAQYIAX8BQYCIBAsHFgIEZ3JhbQAAC2dyYW1fbWFza2VkAAEKthICxQoIE38DewF/BXsGfwV7AX8NfAJAIAYgB04NACACQQR0IQwgAkECdCENIAJBA3QhDiAKQQJ0IQ8gACAGIAJsQQJ0aiEQIApBA2ogC04hEQNAAkAgCCAGIAggBkobIhIgCU4NACAAIAZBAWoiEyAGIBMgB0gbIhQgAmxBAnRqIRUgAyAUIAVrIARsQQN0aiEWIAMgBiAFayAEbEEDdGohFyABIA0gEmxqIRgDQCABIBJBA2oiGSASIBkgCUgbIAJsQQJ0aiEaIAEgEkECaiIbIBIgGyAJSBsgAmxBAnRqIRwgASASQQFqIh0gEiAdIAlIGyACbEECdGohHgJAAkAgEUUNAP0MAAAAAAAAAAAAAAAAAAAAACIfISAgHyEhIAohIiAfISMgHyEkIB8hJSAfISYgHyEnDAELIBohFCAcISggHiEpIBghKiAVISsgECEs/QwAAAAAAAAAAAAAAAAAAAAAIichJiAnISUgJyEkICchIyAKIS0gJyEhICchICAnIR8DQCAhICsgD2r9AAAAIi4gFCAPav0AAAAiL/3mAf3kASEhICAgLiAoIA9q/QAAACIw/eYB/eQBISAgHyAuICkgD2r9AAAAIjH95gH95AEhHyAjIC4gKiAPav0AAAAiMv3mAf3kASEjICQgLCAPav0AAAAiLiAv/eYB/eQBISQgJSAuIDD95gH95AEhJSAmIC4gMf3mAf3kASEmICcgLiAy/eYB/eQBIScgFEEQaiEUIChBEGohKCApQRBqISkgKkEQaiEqICtBEGohKyAsQRBqISwgLUEHaiEzIC1BBGoiIiEtIDMgC0gNAAsLICH9HwC7ICH9HwG7oCAh/R8Cu6AgIf0fA7ugITQgIP0fALsgIP0fAbugICD9HwK7oCAg/R8Du6AhNSAf/R8AuyAf/R8Bu6AgH/0fArugIB/9HwO7oCE2ICP9HwC7ICP9HwG7oCAj/R8Cu6AgI/0fA7ugITcgJP0fALsgJP0fAbugICT9HwK7oCAk/R8Du6AhOCAl/R8AuyAl/R8Bu6AgJf0fArugICX9HwO7oCE5ICb9HwC7ICb9HwG7oCAm/R8Cu6AgJv0fA7ugITogJ/0fALsgJ/0fAbugICf9HwK7oCAn/R8Du6AhOwJAIAsgIkwNACAiQQJ0IRQgCyAiayErIBAhKCAVISkgGCEqA0AgKSAUaioCALsiPCAaIBRqKgIAuyI9oiA0oCE0IDwgHCAUaioCALsiPqIgNaAhNSA8IB4gFGoqAgC7Ij+iIDagITYgPCAqIBRqKgIAuyJAoiA3oCE3ICggFGoqAgC7IjwgPaIgOKAhOCA8ID6iIDmgITkgPCA/oiA6oCE6IDwgQKIgO6AhOyAoQQRqISggKUEEaiEpICpBBGohKiAeQQRqIR4gHEEEaiEcIBpBBGohGiArQX9qIisNAAsLIBcgEkEDdCIaaiIUIDsgFCsDAKA5AwACQCAdIAlOIhQNACAXIB1BA3RqIhwgOiAcKwMAoDkDAAsCQCAbIAlOIhwNACAXIBtBA3RqIh4gOSAeKwMAoDkDAAsCQCAZIAlOIh4NACAXIBlBA3RqIiggOCAoKwMAoDkDAAsCQCATIAdODQAgFiAaaiIaIDcgGisDAKA5AwACQCAUDQAgFiAdQQN0aiIUIDYgFCsDAKA5AwALAkAgHA0AIBYgG0EDdGoiFCA1IBQrAwCgOQMACyAeDQAgFiAZQQN0aiIUIDQgFCsDAKA5AwALIBggDGohGCASQQRqIhIgCUgNAAsLIBAgDmohECAGQQJqIgYgB0gNAAsLC+wHBhR/C3sBfwZ8An0CfAJAIAYgB04NACAAIAYgAWxBAnQiDCAKQQJ0Ig1qaiEOIAFBAnQhDyAAIA1qIRAgACAMaiERIARBBWxBA3QhEiAEQQJ0QQN0IRMgBEEDbEEDdCEUIARBAXRBA3QhFSAKQQNqIAtOIRYDQAJAIAggBiAIIAZKGyIXIAlODQAgECAPIBdsIgFqIRggACABaiEZIAIgBiAFayADbEEDdGoiGiASaiEbIBogE2ohHCAaIBRqIR0gGiAVaiEeA0ACQAJAIBZFDQAgCiEf/QwAAAAAAAAAAAAAAAAAAAAAIiAhISAgISIgICEjICAhJCAgISUMAQsgGCEBIA4hDP0MAAAAAAAAAAAAAAAAAAAAACIlISQgJSEjICUhIiAlISEgJSEgIAohDQNAICT9DAAAgD8AAIA/AACAPwAAgD/9DAAAAAAAAAAAAAAAAAAAAAAgDP0AAAAiJiAm/UEiJ/1SIAH9AAAAIiggKP1BIin9Tv3kASEkICUgJiAn/U4iKiAoICn9TiIm/eYB/eQBISUgAUEQaiEBIAxBEGohDCAiICYgJ/1OIib95AEhIiAjICogKf1OIif95AEhIyAgICYgJv3mAf3kASEgICEgJyAn/eYB/eQBISEgDUEHaiErIA1BBGoiHyENICsgC0gNAAsLICD9HwC7ICD9HwG7oCAg/R8Cu6AgIP0fA7ugISwgIf0fALsgIf0fAbugICH9HwK7oCAh/R8Du6AhLSAi/R8AuyAi/R8Bu6AgIv0fArugICL9HwO7oCEuICP9HwC7ICP9HwG7oCAj/R8Cu6AgI/0fA7ugIS8gJP0fALsgJP0fAbugICT9HwK7oCAk/R8Du6AhMCAl/R8AuyAl/R8Bu6AgJf0fArugICX9HwO7oCExAkAgCyAfTA0AIAsgH2shDSARIB9BAnQiDGohASAZIAxqIQwDQAJAIAEqAgAiMiAyXA0AIAwqAgAiMyAzXA0AIDBEAAAAAAAA8D+gITAgLiAzuyI0oCEuIC8gMrsiNaAhLyA0IDSiICygISwgNSA1oiAtoCEtIDUgNKIgMaAhMQsgAUEEaiEBIAxBBGohDCANQX9qIg0NAAsLIBogF0EDdCIBaiIMIDEgDCsDAKA5AwAgDCAEQQN0aiIMIDAgDCsDAKA5AwAgHiABaiIMIC8gDCsDAKA5AwAgHSABaiIMIC4gDCsDAKA5AwAgHCABaiIMIC0gDCsDAKA5AwAgGyABaiIBICwgASsDAKA5AwAgGSAPaiEZIBggD2ohGCAXQQFqIhcgCUgNAAsLIBEgD2ohESAOIA9qIQ4gBkEBaiIGIAdHDQALCwsAOwRuYW1lAAoJZ3JhbS53YXNtARQCAARncmFtAQtncmFtX21hc2tlZAcSAQAPX19zdGFja19wb2ludGVyADgJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDFVidW50dSBjbGFuZxExOC4xLjMgKDF1YnVudHUxKQA1D3RhcmdldF9mZWF0dXJlcwMrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQrB3NpbWQxMjg=",t4="AGFzbQEAAAABEAFgDH9/f39/f39/f39/fwACDwEDZW52Bm1lbW9yeQIAAgMDAgAABAUBcAEBAQYIAX8BQYCIBAsHFgIEZ3JhbQAAC2dyYW1fbWFza2VkAAEKlRICrQoIE38DewF/BXsGfwV7AX8NfAJAIAYgB04NACACQQR0IQwgAkECdCENIAJBA3QhDiAKQQJ0IQ8gACAGIAJsQQJ0aiEQIApBA2ogC04hEQNAAkAgCCAGIAggBkobIhIgCU4NACAAIAZBAWoiEyAGIBMgB0gbIhQgAmxBAnRqIRUgAyAUIAVrIARsQQN0aiEWIAMgBiAFayAEbEEDdGohFyABIA0gEmxqIRgDQCABIBJBA2oiGSASIBkgCUgbIAJsQQJ0aiEaIAEgEkECaiIbIBIgGyAJSBsgAmxBAnRqIRwgASASQQFqIh0gEiAdIAlIGyACbEECdGohHgJAAkAgEUUNAP0MAAAAAAAAAAAAAAAAAAAAACIfISAgHyEhIAohIiAfISMgHyEkIB8hJSAfISYgHyEnDAELIBohFCAcISggHiEpIBghKiAVISsgECEs/QwAAAAAAAAAAAAAAAAAAAAAIichJiAnISUgJyEkICchIyAKIS0gJyEhICchICAnIR8DQCArIA9q/QAAACIuIBQgD2r9AAAAIi8gIf2FAiEhIC4gKCAPav0AAAAiMCAg/YUCISAgLiApIA9q/QAAACIxIB/9hQIhHyAuICogD2r9AAAAIjIgI/2FAiEjICwgD2r9AAAAIi4gLyAk/YUCISQgLiAwICX9hQIhJSAuIDEgJv2FAiEmIC4gMiAn/YUCIScgFEEQaiEUIChBEGohKCApQRBqISkgKkEQaiEqICtBEGohKyAsQRBqISwgLUEHaiEzIC1BBGoiIiEtIDMgC0gNAAsLICH9HwC7ICH9HwG7oCAh/R8Cu6AgIf0fA7ugITQgIP0fALsgIP0fAbugICD9HwK7oCAg/R8Du6AhNSAf/R8AuyAf/R8Bu6AgH/0fArugIB/9HwO7oCE2ICP9HwC7ICP9HwG7oCAj/R8Cu6AgI/0fA7ugITcgJP0fALsgJP0fAbugICT9HwK7oCAk/R8Du6AhOCAl/R8AuyAl/R8Bu6AgJf0fArugICX9HwO7oCE5ICb9HwC7ICb9HwG7oCAm/R8Cu6AgJv0fA7ugITogJ/0fALsgJ/0fAbugICf9HwK7oCAn/R8Du6AhOwJAIAsgIkwNACAiQQJ0IRQgCyAiayErIBAhKCAVISkgGCEqA0AgKSAUaioCALsiPCAaIBRqKgIAuyI9oiA0oCE0IDwgHCAUaioCALsiPqIgNaAhNSA8IB4gFGoqAgC7Ij+iIDagITYgPCAqIBRqKgIAuyJAoiA3oCE3ICggFGoqAgC7IjwgPaIgOKAhOCA8ID6iIDmgITkgPCA/oiA6oCE6IDwgQKIgO6AhOyAoQQRqISggKUEEaiEpICpBBGohKiAeQQRqIR4gHEEEaiEcIBpBBGohGiArQX9qIisNAAsLIBcgEkEDdCIaaiIUIDsgFCsDAKA5AwACQCAdIAlOIhQNACAXIB1BA3RqIhwgOiAcKwMAoDkDAAsCQCAbIAlOIhwNACAXIBtBA3RqIh4gOSAeKwMAoDkDAAsCQCAZIAlOIh4NACAXIBlBA3RqIiggOCAoKwMAoDkDAAsCQCATIAdODQAgFiAaaiIaIDcgGisDAKA5AwACQCAUDQAgFiAdQQN0aiIUIDYgFCsDAKA5AwALAkAgHA0AIBYgG0EDdGoiFCA1IBQrAwCgOQMACyAeDQAgFiAZQQN0aiIUIDQgFCsDAKA5AwALIBggDGohGCASQQRqIhIgCUgNAAsLIBAgDmohECAGQQJqIgYgB0gNAAsLC+MHBhR/CnsBfwZ8An0CfAJAIAYgB04NACAAIAYgAWxBAnQiDCAKQQJ0Ig1qaiEOIAFBAnQhDyAAIA1qIRAgACAMaiERIARBBWxBA3QhEiAEQQJ0QQN0IRMgBEEDbEEDdCEUIARBAXRBA3QhFSAKQQNqIAtOIRYDQAJAIAggBiAIIAZKGyIXIAlODQAgECAPIBdsIgFqIRggACABaiEZIAIgBiAFayADbEEDdGoiGiASaiEbIBogE2ohHCAaIBRqIR0gGiAVaiEeA0ACQAJAIBZFDQAgCiEf/QwAAAAAAAAAAAAAAAAAAAAAIiAhISAgISIgICEjICAhJCAgISUMAQsgGCEBIA4hDP0MAAAAAAAAAAAAAAAAAAAAACIlISQgJSEjICUhIiAlISEgJSEgIAohDQNAIAz9AAAAIiYgJiAm/UEiJv1OIicgAf0AAAAiKCAoICj9QSIo/U4iKSAl/YUCISUgJP0MAACAPwAAgD8AAIA/AACAP/0MAAAAAAAAAAAAAAAAAAAAACAm/VIgKP1O/eQBISQgAUEQaiEBIAxBEGohDCApICb9TiImICYgIP2FAiEgICcgKP1OIiggKCAh/YUCISEgIiAm/eQBISIgIyAo/eQBISMgDUEHaiEqIA1BBGoiHyENICogC0gNAAsLICD9HwC7ICD9HwG7oCAg/R8Cu6AgIP0fA7ugISsgIf0fALsgIf0fAbugICH9HwK7oCAh/R8Du6AhLCAi/R8AuyAi/R8Bu6AgIv0fArugICL9HwO7oCEtICP9HwC7ICP9HwG7oCAj/R8Cu6AgI/0fA7ugIS4gJP0fALsgJP0fAbugICT9HwK7oCAk/R8Du6AhLyAl/R8AuyAl/R8Bu6AgJf0fArugICX9HwO7oCEwAkAgCyAfTA0AIAsgH2shDSARIB9BAnQiDGohASAZIAxqIQwDQAJAIAEqAgAiMSAxXA0AIAwqAgAiMiAyXA0AIC9EAAAAAAAA8D+gIS8gLSAyuyIzoCEtIC4gMbsiNKAhLiAzIDOiICugISsgNCA0oiAsoCEsIDQgM6IgMKAhMAsgAUEEaiEBIAxBBGohDCANQX9qIg0NAAsLIBogF0EDdCIBaiIMIDAgDCsDAKA5AwAgDCAEQQN0aiIMIC8gDCsDAKA5AwAgHiABaiIMIC4gDCsDAKA5AwAgHSABaiIMIC0gDCsDAKA5AwAgHCABaiIMICwgDCsDAKA5AwAgGyABaiIBICsgASsDAKA5AwAgGSAPaiEZIBggD2ohGCAXQQFqIhcgCUgNAAsLIBEgD2ohESAOIA9qIQ4gBkEBaiIGIAdHDQALCwsAQwRuYW1lABIRZ3JhbS1yZWxheGVkLndhc20BFAIABGdyYW0BC2dyYW1fbWFza2VkBxIBAA9fX3N0YWNrX3BvaW50ZXIAOAlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQEMVWJ1bnR1IGNsYW5nETE4LjEuMyAoMXVidW50dTEpAEMPdGFyZ2V0X2ZlYXR1cmVzBCsPbXV0YWJsZS1nbG9iYWxzKwxyZWxheGVkLXNpbWQrCHNpZ24tZXh0KwdzaW1kMTI4",$s=512,Es=256,bt=64,Na=1e-9;async function e4(e,t,n,s={}){const o=e.m;if(o<=0)return;const{engine:r,rows:i}=Vl(e,s.engine??"wasm"),a=new Float64Array(o);for(let c=0;c<o;c+=bt){const u=Math.min(o,c+bt);if(n!==void 0)for(let l=c;l<u;l++){const h=n(l);h!==void 0&&await h}Xl(r,i,c,u,a,t)}}function Yl(e){return e+3&-4}function Vl(e,t="wasm"){const n=e.m,s=Yl(n),o=r4(t,s,n),r=o.x,i=new Float64Array(n),a=new Float64Array(n),c=new Float64Array(n),u=Math.floor(n*n/8),l=new Int32Array(n+1);let h=new Int32Array(Math.min(u,Math.max(64,n))),f=0,d=!1;const m=new Float64Array(n);for(let g=0;g<n;g++){e.row(g,m);let p=0,w=0;for(let I=0;I<n;I++){const M=m[I];Number.isFinite(M)&&(p+=M,w++)}const b=w>0?p/w:0;l[g]=f;const y=g*s;let A=0,N=0;for(let I=0;I<n;I++){const M=m[I];if(Number.isFinite(M)){const x=Math.fround(M-b);r[y+I]=x,A+=x,N+=x*x;continue}if(r[y+I]=Number.NaN,!d){if(f===u){d=!0;continue}if(f===h.length){const x=new Int32Array(Math.min(u,h.length*2));x.set(h),h=x}h[f++]=I}}for(let I=n;I<s;I++)r[y+I]=Number.NaN;i[g]=w,a[g]=A,c[g]=N}if(l[n]=f,!d)for(let g=0;g<n;g++){for(let p=l[g];p<l[g+1];p++)r[g*s+h[p]]=0;for(let p=n;p<s;p++)r[g*s+p]=0}return{engine:o,rows:{m:n,ld:s,first:0,masked:d,count:i,sum:a,squares:c,starts:d?new Int32Array(n+1):l,cols:d?new Int32Array(0):h.subarray(0,f)}}}function Xl(e,t,n,s,o,r){const{m:i,first:a}=t,c=i-a;e.run(n-a,s-a,t.masked);const u=e.out;for(let l=n;l<s;l++){const h=(l-n)*c-a;if(t.masked){const f=bt*c;for(let d=l+1;d<i;d++){const m=h+d;o[d]=Jl(u[m],u[f+m],u[2*f+m],u[3*f+m],u[4*f+m],u[5*f+m])}}else n4(l,e.x,t,u,h,o);r(l,o)}}function n4(e,t,n,s,o,r){const{m:i,ld:a,first:c,count:u,sum:l,squares:h,starts:f,cols:d}=n,m=e-c,g=f[m],p=f[m+1],w=m*a;for(let b=e+1;b<i;b++){const y=b-c;let A=u[m],N=l[m],I=h[m],M=l[y],x=h[y];const v=f[y],S=f[y+1];if(S>v){for(let k=v;k<S;k++){const C=t[w+d[k]];N-=C,I-=C*C}A-=S-v}if(p>g){const k=y*a;for(let C=g;C<p;C++){const B=t[k+d[C]];M-=B,x-=B*B}S>v&&(A+=s4(d,g,p,v,S))}r[b]=Jl(s[o+b],A,N,M,I,x)}}function s4(e,t,n,s,o){let r=0,i=t,a=s;for(;i<n&&a<o;){const c=e[i],u=e[a];c===u?(r++,i++,a++):c<u?i++:a++}return r}function Jl(e,t,n,s,o,r){if(!(t>=Qr))return Number.NaN;const i=o-n*n/t,a=r-s*s/t;if(!(i>Na*o)||!(a>Na*r))return Number.NaN;const c=(e-n*s/t)/Math.sqrt(i*a);return c>1?1:c<-1?-1:c}let rs;function Ma(e){try{if(typeof WebAssembly>"u")return null;const t=atob(e),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return WebAssembly.validate(n)?new WebAssembly.Module(n):null}catch{return null}}function o4(e){return rs??={relaxed:Ma(t4),simd:Ma(j3)},e==="wasm"?rs.relaxed??rs.simd:rs.simd}function r4(e,t,n){const s=e==="js"?null:o4(e);if(s!==null)try{return a4(s,t,n)}catch{}return c4(t,n)}const i4=65536;function a4(e,t,n){const s=n*t*4,o=Math.ceil(s/8)*8,r=6*bt*n,i=new WebAssembly.Memory({initial:Math.ceil((o+r*8)/i4)+1}),a=new WebAssembly.Instance(e,{env:{memory:i}}),c=a.exports.gram,u=a.exports.gram_masked,l=new Float32Array(i.buffer,0,n*t),h=new Float64Array(i.buffer,o,r);return{x:l,out:h,run(f,d,m){h.fill(0,0,m?h.length:bt*n);for(let g=0;g<t;g+=$s){const p=Math.min(t,g+$s);for(let w=f;w<n;w+=Es){const b=Math.min(n,w+Es);m?u(0,t,o,n,bt*n,f,f,d,w,b,g,p):c(0,0,t,o,n,f,f,d,w,b,g,p)}}}}}function c4(e,t){const n=new Float32Array(t*e),s=new Float64Array(6*bt*t);return{x:n,out:s,run(o,r,i){s.fill(0,0,i?s.length:bt*t);for(let a=0;a<e;a+=$s){const c=Math.min(e,a+$s);for(let u=o;u<t;u+=Es){const l=Math.min(t,u+Es);i?u4(n,e,s,t,bt*t,o,o,r,u,l,a,c):l4(n,e,s,t,o,o,r,u,l,a,c)}}}}}function l4(e,t,n,s,o,r,i,a,c,u,l){for(let h=r;h<i;h+=2){const f=h+1<i?h+1:h,d=h*t,m=f*t,g=(h-o)*s,p=(f-o)*s;for(let w=Math.max(h,a);w<c;w+=2){const b=w+1<c?w+1:w,y=w*t,A=b*t;let N=0,I=0,M=0,x=0;for(let v=u;v<l;v++){const S=e[d+v],k=e[m+v],C=e[y+v],B=e[A+v];N+=S*C,I+=S*B,M+=k*C,x+=k*B}n[g+w]+=N,b!==w&&(n[g+b]+=I),f!==h&&(n[p+w]+=M,b!==w&&(n[p+b]+=x))}}}function u4(e,t,n,s,o,r,i,a,c,u,l,h){for(let f=i;f<a;f++){const d=f*t,m=(f-r)*s;for(let g=Math.max(f,c);g<u;g++){const p=g*t;let w=0,b=0,y=0,A=0,N=0,I=0;for(let M=l;M<h;M++){const x=e[d+M],v=e[p+M];x!==x||v!==v||(w+=x*v,b++,y+=x,A+=v,N+=x*x,I+=v*v)}n[m+g]+=w,n[o+m+g]+=b,n[2*o+m+g]+=y,n[3*o+m+g]+=A,n[4*o+m+g]+=N,n[5*o+m+g]+=I}}}const h4=384*1024*1024,f4=1024,Ia=.9,d4=6e4;let ps=null,m4=1;function g4(e,t){ps!==null&&Zl(ps),ps=t>0?{spawn:e,helpers:t,idle:[],release:null}:null}function p4(e){const t=e.idle.pop();if(t!==void 0)return t;try{return e.spawn()}catch{return null}}function w4(e,t){t.onmessage=null,t.onerror=null,e.idle.push(t)}function Zl(e){e.release!==null&&clearTimeout(e.release),e.release=null;for(const t of e.idle.splice(0))t.terminate()}function b4(e){e.release!==null&&clearTimeout(e.release),e.release=null,e.idle.length!==0&&(e.release=setTimeout(()=>{e.release=null,Zl(e)},d4),e.release.unref?.())}async function jl(e,t,n){const s=e.m,o=ps;if(o===null||s<f4)return e4(e,t,n);const r=A4(s,Yl(s),o.helpers);o.release!==null&&clearTimeout(o.release),o.release=null;const i=[];for(let l=1;l<r.length-1;l++)i.push({worker:p4(o),from:r[l],to:r[l+1],delivered:!1,failed:!1});const a=new Float64Array(s),c=new Map,u=l=>{let h;const f=new Promise(d=>{h=d});c.set(l,{settle:h,lines:f})};try{const{engine:l,rows:h}=Vl(e);for(const f of i){const{worker:d,from:m,to:g}=f;for(let A=m;A<g;A+=bt)u(A);const p=()=>{f.failed=!0;for(let A=m;A<g;A+=bt)c.get(A)?.settle(null)};if(d===null){p();continue}const w=m4++,b=m+Math.floor((g-1-m)/bt)*bt;d.onmessage=A=>{const N=A.data;N.id===w&&(N.kind==="band"?(c.get(N.r0)?.settle(N.lines),N.r0===b&&(f.delivered=!0)):N.kind==="error"&&p())},d.onerror=A=>{A.preventDefault(),p()};const y=y4(w,l.x,h,m,g);d.postMessage(y,[y.x.buffer,y.count.buffer,y.sum.buffer,y.squares.buffer,y.starts.buffer,y.cols.buffer])}for(let f=0;f<s;f+=bt){const d=Math.min(s,f+bt),m=c.get(f),g=m===void 0?null:await m.lines;if(g===null){if(n!==void 0)for(let p=f;p<d;p++){const w=n(p);w!==void 0&&await w}Xl(l,h,f,d,a,t);continue}for(let p=f;p<d;p++){if(n!==void 0){const b=n(p);b!==void 0&&await b}const w=(p-f)*s;for(let b=p+1;b<s;b++)a[b]=g[w+b];t(p,a)}}}finally{for(const{worker:l,delivered:h,failed:f}of i)l!==null&&(h&&!f?w4(o,l):l.terminate());b4(o)}}function A4(e,t,n){for(let s=n+1;s>1;s--){const o=[0],r=Ia+s-1;for(let a=1;a<s;a++){const c=(Ia+a-1)/r,u=Math.round(e*(1-Math.sqrt(1-c))/bt)*bt;u>o[o.length-1]&&u<e&&o.push(u)}o.push(e);let i=0;for(let a=1;a<o.length-1;a++)i+=(e-o[a])*t*4;if(o.length>2&&i<=h4)return o}return[0,e]}function y4(e,t,n,s,o){const{m:r,ld:i}=n,a=r-s,c=new Int32Array(a+1),u=n.starts[s];for(let l=0;l<=a;l++)c[l]=n.starts[s+l]-u;return{id:e,m:r,ld:i,first:s,to:o,masked:n.masked,x:t.slice(s*i,r*i),count:n.count.slice(s,r),sum:n.sum.slice(s,r),squares:n.squares.slice(s,r),starts:c,cols:n.cols.slice(u,n.starts[r])}}function t0(e,t,n=.1){const s=[],o=Math.max(1,Math.ceil(t*n));for(let r=0;r<t;r++){let i=0;for(let a=0;a<t&&i<o;a++)Number.isFinite(e[r*t+a])&&i++;i>=o&&s.push(r)}return Int32Array.from(s)}function _n(e,t){return t>0?Math.min(e,t-e):e}function N4(e,t,n,s){const o=n.length,r=s.cis.length,i=new Float64Array(o*o);for(let a=0;a<o;a++){const c=n[a],u=s.group[c];for(let l=0;l<o;l++){const h=n[l],f=s.group[h],d=u===f;if(d?s.contacts==="trans":s.contacts==="cis"){i[a*o+l]=Number.NaN;continue}const m=d?_n(Math.abs(h-c),s.laps?.[u]??0):Math.abs(h-c);if(d&&m<s.ignoreDiags){i[a*o+l]=Number.NaN;continue}const g=e[c*t+h],p=d?Wr(s.cis[u],m):s.trans[u*r+f];i[a*o+l]=Number.isFinite(g)&&Number.isFinite(p)&&p!==0?g/p:Number.NaN}}return i}async function M4(e,t,n){const s=new Float64Array(t*t);return await jl({m:t,row:(o,r)=>r.set(e.subarray(o*t,(o+1)*t))},(o,r)=>{s[o*t+o]=1;for(let i=o+1;i<t;i++)s[o*t+i]=Number.isFinite(r[i])?r[i]:0},n),e0(s,t),s}function e0(e,t){for(let s=0;s<t;s+=64){const o=Math.min(t,s+64);for(let r=s;r<t;r+=64){const i=Math.min(t,r+64);for(let a=s;a<o;a++){const c=a*t;for(let u=Math.max(r,a+1);u<i;u++)e[u*t+a]=e[c+u]}}}}const Yr=99.9;function I4(e,t,n=Yr){const s=s0(e,n),o=new Float64Array(t*t);for(let r=0;r<t*t;r++)o[r]=n0(e[r],s);return o}function n0(e,t){return Number.isFinite(e)?Math.min(Math.max(e,0),t)-1:0}function x4(e,t,n,s=Yr){const o=s0(e,s),r=new Float64Array(n.length),i=new Float64Array(t);let a=0;for(let c=0;c<t;c++){for(let u=0;u<t;u++){const l=n0(e[c*t+u],o);i[u]=l,a+=l*l}for(let u=0;u<n.length;u++){const l=n[u];let h=0;for(let f=0;f<t;f++)h+=i[f]*l[f];r[u]+=l[c]*h}}return Array.from(r,c=>a>0?c*c/a:Number.NaN)}function s0(e,t){let n=0;for(let h=0;h<e.length;h++)Number.isFinite(e[h])&&n++;if(n===0)return Number.NaN;const s=Math.min(100,Math.max(0,t))/100*(n-1),o=Math.floor(s),r=n-o,i=new Float64Array(r);let a=0;const c=(h,f)=>{let d=h;for(;;){const m=2*d+1,g=m+1;let p=d;if(m<f&&i[m]<i[p]&&(p=m),g<f&&i[g]<i[p]&&(p=g),p===d)return;const w=i[d];i[d]=i[p],i[p]=w,d=p}};for(let h=0;h<e.length;h++){const f=e[h];if(Number.isFinite(f))if(a<r){let d=a++;for(i[d]=f;d>0;){const m=d-1>>1;if(i[m]<=i[d])break;const g=i[m];i[m]=i[d],i[d]=g,d=m}}else f>i[0]&&(i[0]=f,c(0,a))}const u=i[0],l=s-o;return l===0||a<2?u:(i[0]=i[a-1],c(0,a-1),u+(i[0]-u)*l)}async function v4(e,t,n){const s=t0(e,t),o=s.length,r=new Float32Array(t*t).fill(Number.NaN);return o<2?{values:r,kept:o,dropped:t-o}:(await jl({m:o,row:(i,a)=>{const c=s[i]*t;for(let u=0;u<o;u++)a[u]=e[c+s[u]]}},(i,a)=>{const c=s[i],u=c*t;r[u+c]=1;for(let l=i+1;l<o;l++)r[u+s[l]]=Number.isFinite(a[l])?a[l]:0},n),e0(r,t),{values:r,kept:o,dropped:t-o})}function k4(e,t,n){const s=Ql(e,t.values);if(!Number.isFinite(s)||Math.abs(s)<n)return{flipped:!1,r:Number.isFinite(s)?s:Number.NaN,confident:!1,signal:t.name};const o=s<0;if(o)for(let r=0;r<e.length;r++)e[r]=-e[r];return{flipped:o,r:s,confident:!0,signal:t.name}}function S4(e,t,n,s){const o=Q3(n,s),r=new Int32Array(t).fill(-1);for(let h=0;h<t;h++){const f=n[h];if(!Number.isFinite(f))continue;let d=0;for(;d<s-1&&f>=o[d+1];)d++;r[h]=d}const i=new Float64Array(s*s),a=new Float64Array(s*s);for(let h=0;h<t;h++){const f=r[h];if(!(f<0))for(let d=0;d<t;d++){const m=r[d];if(m<0)continue;const g=e[h*t+d];Number.isFinite(g)&&(i[f*s+m]+=g,a[f*s+m]+=1)}}const c=new Float32Array(s*s);for(let h=0;h<c.length;h++)c[h]=a[h]>0?i[h]/a[h]:Number.NaN;const u=Math.max(1,Math.round(s/5)),l=(h,f,d,m)=>{let g=0,p=0;for(let w=h;w<f;w++)for(let b=d;b<m;b++){const y=c[w*s+b];Number.isFinite(y)&&(g+=y,p++)}return p===0?Number.NaN:g/p};return{values:c,edges:o,strength:{bb:l(0,u,0,u),aa:l(s-u,s,s-u,s),ab:l(0,u,s-u,s)}}}function C4(e,t){const n=[];let s=-1,o=-1,r=0,i=0,a=0;const c=()=>{s>=0&&r!==0&&n.push({side:r>0?"A":"B",from:s,to:o,mean:a===0?Number.NaN:i/a,bins:a}),s=-1,i=0,a=0};for(let u=0;u<e.length&&u<t.length;u++){const l=e[u],h=t[u],f=Number.isFinite(h)&&h>0?1:h<0?-1:0;(f!==r||l!==o+1)&&c(),r=f,o=l,f!==0&&(s<0&&(s=l),i+=h,a++)}return c(),n}function F4(){return new Worker(new URL(""+new URL("gram.worker-Cf7kBq9K.js",import.meta.url).href,import.meta.url),{type:"module"})}const o0=.001,r0=20,$4=1e-12;function*i0(e,t={}){const n=Math.max(0,Math.round(t.iterations??200)),s=Math.max(1,Math.round(t.history??10)),o=t.tolerance??1e-9,r=t.gradientTolerance??1e-10,i=e.length,a=Float64Array.from(e),c=new Float64Array(i),u=new Float64Array(i),l=new Float64Array(i),h=new Float64Array(i),f=[],d=[],m=[],g=new Float64Array(s),p={evaluations:0};let w=yield*$n(a,c,p,0,n,Number.POSITIVE_INFINITY);if(!Number.isFinite(w))return{point:a,value:w,iterations:0,evaluations:p.evaluations,stop:"search"};let b="steps",y=0;for(;y<n;y++){if(B4(c)<=r){b="gradient";break}h.set(c);const A=f.length;for(let C=A-1;C>=0;C--){const B=m[C]*Bt(f[C],h);g[C]=B,va(h,d[C],-B)}if(A>0){const C=A-1,B=Bt(f[C],d[C])/Bt(d[C],d[C]);if(Number.isFinite(B)&&B>0)for(let F=0;F<i;F++)h[F]*=B}for(let C=0;C<A;C++){const B=m[C]*Bt(d[C],h);va(h,f[C],g[C]-B)}for(let C=0;C<i;C++)h[C]=-h[C];let N=Bt(c,h);if(!(N<0)){f.length=0,d.length=0,m.length=0;for(let C=0;C<i;C++)h[C]=-c[C];if(N=-Bt(c,c),!(N<0)){b="gradient";break}}const I=f.length===0?Math.min(1e10,1/Math.sqrt(Bt(c,c))):1,M=yield*E4(a,h,u,l,w,N,I,p,y,n);if(!M.ok){if(f.length>0){f.length=0,d.length=0,m.length=0,y--;continue}b="search";break}const x=new Float64Array(i),v=new Float64Array(i);for(let C=0;C<i;C++)x[C]=M.step*h[C],v[C]=l[C]-c[C];const S=w;a.set(u),c.set(l),w=M.value;const k=Bt(x,v);if(k>$4*Math.sqrt(Bt(x,x)*Bt(v,v))&&(f.push(x),d.push(v),m.push(1/k),f.length>s&&(f.shift(),d.shift(),m.shift())),S-w<=o*Math.max(1,Math.abs(S),Math.abs(w))){y++,b="value";break}}return{point:a,value:w,iterations:y,evaluations:p.evaluations,stop:b}}function*E4(e,t,n,s,o,r,i,a,c,u){const l=e.length,h=p=>{for(let w=0;w<l;w++)n[w]=e[w]+p*t[w]};let f=0,d=o,m=i,g=Number.NaN;for(let p=0;p<r0;p++){h(m);const w=yield*$n(n,s,a,c,u,o);if(g=m,!Number.isFinite(w)||w>o+o0*m*r||p>0&&w>=d)return yield*xa(e,t,n,s,o,r,f,d,m,a,c,u);const y=Bt(s,t);if(Math.abs(y)<=-.9*r)return{ok:!0,step:m,value:w};if(y>=0)return yield*xa(e,t,n,s,o,r,m,w,f,a,c,u);if(f=m,d=w,m*=2,!Number.isFinite(m))break}if(Number.isFinite(g)){h(g);const p=yield*$n(n,s,a,c,u,o);if(Number.isFinite(p)&&p<o)return{ok:!0,step:g,value:p}}return{ok:!1,step:0,value:o}}function*xa(e,t,n,s,o,r,i,a,c,u,l,h){const f=e.length;let d=i,m=a,g=c;for(let p=0;p<r0;p++){const w=(d+g)/2;if(!Number.isFinite(w)||w<=0)break;for(let N=0;N<f;N++)n[N]=e[N]+w*t[N];const b=yield*$n(n,s,u,l,h,o);if(!Number.isFinite(b)||b>o+o0*w*r||b>=m){g=w;continue}const A=Bt(s,t);if(Math.abs(A)<=-.9*r)return{ok:!0,step:w,value:b};A*(g-d)>=0&&(g=d),d=w,m=b}if(d>0&&m<o){for(let w=0;w<f;w++)n[w]=e[w]+d*t[w];const p=yield*$n(n,s,u,l,h,o);if(Number.isFinite(p))return{ok:!0,step:d,value:p}}return{ok:!1,step:0,value:o}}function*$n(e,t,n,s,o,r){n.evaluations++;const i=yield{point:e,gradient:t,iteration:s,iterations:o,evaluations:n.evaluations,current:r};return Number.isNaN(i)?Number.POSITIVE_INFINITY:i}function Bt(e,t){let n=0;for(let s=0;s<e.length;s++)n+=e[s]*t[s];return n}function va(e,t,n){for(let s=0;s<e.length;s++)e[s]+=n*t[s]}function B4(e){let t=0;for(let n=0;n<e.length;n++){const s=Math.abs(e[n]);s>t&&(t=s)}return t}const a0=2220446049250313e-31,Oo={tolerance:1e12*a0,gradient:1e-5,iterations:1e4},ka={tolerance:10*a0,gradient:1},c0=10,T4=3,O4=2/3;function L4(e,t,n,s,o=null){const r=new Map;for(let d=0;d<t;d++){const m=r.get(n[d]);m===void 0?r.set(n[d],[d]):m.push(d)}let i=0;const a=[];for(const d of r.values())d.sort((m,g)=>s[m]-s[g]),a.push(Int32Array.from(d)),i=Math.max(i,d.length);const c=[],u=[],l=[],h=[],f=Math.floor(i*O4);for(let d=1;d<f;d++){let m=0,g=0,p=0;for(const y of a)for(let A=0;A+d<y.length;A++){const N=y[A],I=y[A+d],M=e[N<I?N*t+I:I*t+N];if(!Number.isFinite(M))continue;const x=o===null?1:o[N]*o[I];m++,g+=M/x,p+=1/x}if(m<2)continue;const w=g/m;let b=0;for(const y of a)for(let A=0;A+d<y.length;A++){const N=y[A],I=y[A+d],M=e[N<I?N*t+I:I*t+N];if(!Number.isFinite(M))continue;const x=M/(o===null?1:o[N]*o[I])-w;b+=x*x}c.push(d),u.push(w),l.push(b/(m-1)/(p/m)),h.push(m)}return{separation:Int32Array.from(c),mean:Float64Array.from(u),variance:Float64Array.from(l),pairs:Float64Array.from(h)}}function _4(e){const t=[],n=[],s=[];for(let u=0;u<e.mean.length;u++){const l=e.mean[u],h=e.variance[u];if(!(l>0)||!(h>l+3*Math.sqrt((l+2*l*l)/e.pairs[u])))continue;const f=l*l/(h-l);Number.isFinite(f)&&(t.push(Math.log(l)),n.push(f),s.push(e.pairs[u]))}if(t.length<T4)return null;const o=(u,l)=>{let h=0;for(let f=0;f<t.length;f++){const d=Math.exp(u+l*t[f])-n[f];h+=s[f]*d*d}return h};let r=0,i=0,a=o(r,i),c=.001;for(let u=0;u<500&&Number.isFinite(a);u++){let l=0,h=0,f=0,d=0,m=0;for(let p=0;p<t.length;p++){const w=Math.exp(r+i*t[p]),b=w-n[p],y=s[p];l+=y*w*w,h+=y*w*w*t[p],f+=y*w*w*t[p]*t[p],d+=y*w*b,m+=y*w*b*t[p]}let g=!1;for(;c<1e16;){const p=l*(1+c),w=f*(1+c),b=p*w-h*h;if(!(Math.abs(b)>0)){c*=10;continue}const y=-(w*d-h*m)/b,A=-(p*m-h*d)/b,N=o(r+y,i+A);if(Number.isFinite(N)&&N<a){r+=y,i+=A;const I=a-N;a=N,c=Math.max(c/10,1e-12),g=I>1e-15*a&&Math.abs(y)+Math.abs(A)>1e-15*(1+Math.abs(r)+Math.abs(i));break}c*=10}if(!g)break}return Number.isFinite(r)&&Number.isFinite(i)?{c0:r,c1:i}:null}function Sa(e,t){return Math.exp(e.c0+e.c1*Math.log(t))}function D4(e,t){const n=new Float64Array(e),s=new Float64Array(e),o=new Float64Array(e);for(let r=0;r<e;r++)n[r]=1-2*t(),s[r]=1-2*t(),o[r]=1-2*t();return{x:n,y:s,z:o}}function R4(e,t,n,s){const o=1/s;for(let r=0;r<t;r++)for(let i=r+1;i<t;i++){const a=e[r*t+i],c=Number.isFinite(a)&&a>0?a/(n===null?1:n[r]*n[i]):0;e[i*t+r]=c>0?s===3?Math.cbrt(c):Math.pow(c,o):0}}function P4(e){const t=h0(e),n=[0];for(let s=1;s<t;s++){const o=Math.round(e*Math.sqrt(s/t));o>n[n.length-1]&&o<e&&n.push(o)}return n.push(e),Int32Array.from(n)}function z4(e,t,n,s,o,r,i){const a=o;i.fill(0);let c=0;for(let u=Math.max(1,s);u<o;u++){const l=u*n,h=r[u],f=r[n+u],d=r[2*n+u];let m=0,g=0,p=0;for(let w=0;w<u;w++){const b=e[l+w];if(!(b>0))continue;const y=h-r[w],A=f-r[n+w],N=d-r[2*n+w],I=Math.sqrt(y*y+A*A+N*N),M=I*b-1;if(c+=2*M*M,!(I>0))continue;const x=4*M*b/I,v=x*y,S=x*A,k=x*N;m+=v,g+=S,p+=k,i[w]-=v,i[a+w]-=S,i[2*a+w]-=k}i[u]+=m,i[a+u]+=g,i[2*a+u]+=p}return c}let l0=0,u0=0;const Ca=7,q4=16,U4=1e9;function G4(e,t,n){let s=t,o=1,r=0;for(;s<Ca;)o*=s,r+=1/s,s+=1;let i=e+t,a=1,c=0;for(;i<Ca;)a*=i,c+=1/i,i+=1;const u=s===t?n:Math.log(s),l=Math.log1p((i-s)/s),h=1/s,f=1/i,d=h*h,m=f*f,g=h*(1/12-d*(1/360-d*(1/1260-d*(1/1680-d*(1/1188-d*691/360360))))),p=f*(1/12-m*(1/360-m*(1/1260-m*(1/1680-m*(1/1188-m*691/360360))))),w=d*(1/12-d*(1/120-d*(1/252-d*(1/240-d*(1/132-d*691/32760))))),b=m*(1/12-m*(1/120-m*(1/252-m*(1/240-m*(1/132-m*691/32760))))),y=o===a?0:Math.log(o/a),A=o===1&&a===1?0:(i-s)*u-e*n;l0=(i-.5)*l-(o===1&&a===1?e:i-s)+p-g+y+A,u0=t*(l-.5*(f-h)-b+w-c+r)}function H4(e){const t=e.bias??null;return{n:e.n,alpha:e.alpha,bias:t,logBias:t===null?null:Float64Array.from(t,n=>Math.log(n)),dispersion:e.dispersion}}const Q4=32,K4=64;function h0(e){return Math.max(1,Math.min(K4,Math.round(e/Q4)))}function Fa(e){const t=h0(e),n=[0];for(let s=1;s<t;s++){const o=Math.round(e*(1-Math.sqrt(1-s/t)));o>n[n.length-1]&&o<e&&n.push(o)}return n.push(e),Int32Array.from(n)}function W4(e,t,n,s,o,r,i){const{n:a,dispersion:c,alpha:u,bias:l,logBias:h}=e,f=u/2,d=u===3,m=c!==null,g=m?c.c0:0,p=m?c.c1:0,w=1-p,b=a-s;i.fill(0);let y=0;for(let A=s;A<o;A++){const N=A*a,I=r[A],M=r[a+A],x=r[2*a+A],v=l===null?1:l[A],S=h===null?0:h[A];let k=0,C=0,B=0;for(let F=A+1;F<a;F++){const E=t[N+F];if(!(E>=0))continue;const _=I-r[F],$=M-r[a+F],O=x-r[2*a+F],L=_*_+$*$+O*O;if(!(L>0))return Number.POSITIVE_INFINITY;const D=-f*Math.log(L),q=d?1/(L*Math.sqrt(L)):Math.exp(D),X=(l===null?1:v*l[F])*q;let P;if(m){const G=w*D-g,W=Math.exp(G),Y=X/W,tt=W>.001?Math.log(1+W):Math.log1p(W);if(y+=(E+Y)*tt,P=w*(X-E)/(1+W)+p*Y*tt,E>0){const et=S+(h===null?0:h[F])+D,ht=et-G;let U=0,V=1;if(E>1&&E<=q4&&E===Math.floor(E)&&Y<U4){let Z=1,J=0,ot=0;for(;ot+4<=E;ot+=4){const it=Y+ot,lt=it+1,ut=it+2,vt=it+3,gt=it*lt,St=ut*vt,mt=gt*St;J=J*mt+((it+lt)*St+(ut+vt)*gt)*Z,Z*=mt}for(;ot<E;ot++){const it=Y+ot;J=J*it+Z,Z*=it}U=Math.log(Z)-E*ht,V=Y*J/Z}else E!==1&&(G4(E,Y,ht),U=l0,V=u0);y-=U+E*et,P-=p*V}}else y+=X,P=X-E,E>0&&(y-=E*(S+(h===null?0:h[F])+D));const z=-u*P/L,R=z*_,H=z*$,K=z*O;k+=R,C+=H,B+=K,i[F-s]-=R,i[b+F-s]-=H,i[2*b+F-s]-=K}i[A-s]+=k,i[b+A-s]+=C,i[2*b+A-s]+=B}return y}function Y4(e,t,n,s,o){for(let r=0;r<o;r++)e[s+r]+=t[r],e[n+s+r]+=t[o+r],e[2*n+s+r]+=t[2*o+r]}function f0(e){const t=e.x.length,n=new Float64Array(3*t);return n.set(e.x,0),n.set(e.y,t),n.set(e.z,2*t),n}function V4(e,t){return{x:Float64Array.from(e.subarray(0,t)),y:Float64Array.from(e.subarray(t,2*t)),z:Float64Array.from(e.subarray(2*t,3*t))}}function X4(e,t,n={}){const s=i0(f0(t),{iterations:n.iterations??Oo.iterations,history:c0,tolerance:Oo.tolerance,gradientTolerance:Oo.gradient});return d0(s,e)}function J4(e,t,n={}){const s=i0(f0(t),{iterations:n.iterations??1e5,history:c0,tolerance:ka.tolerance,gradientTolerance:ka.gradient});return d0(s,e)}function*d0(e,t){const n=yield*e;return{coords:V4(n.point,t),value:n.value,iterations:n.iterations,evaluations:n.evaluations,stop:n.stop}}const Z4=512*1024*1024,j4=256,$a=.9;let m0=null,t6=1;function e6(e,t){m0=t>0?{spawn:e,helpers:Math.floor(t)}:null}function n6(e,t){const n=m0,s=a=>Ea(a)?0:a.BYTES_PER_ELEMENT,o=n===null||e<j4?0:Ba(Fa(e),e,n.helpers,s(t)).length-2,r=[];for(let a=0;n!==null&&a<o;a++){let c;try{c=n.spawn()}catch{continue}const u={worker:c,alive:!0,ready:!1,owed:null};c.onmessage=l=>{const h=l.data;if(h.kind==="ready"){u.ready=!0;return}if(h.kind==="error"){pn(u);return}const f=u.owed;f===null||h.id!==f.id||h.seq!==f.seq||(u.owed=null,f.resolve(h))},c.onerror=l=>{l.preventDefault(),pn(u)},r.push(u)}const i=(a,c)=>{const u=c.counts,l=Ea(u),h=a==="mds",f=h?null:H4(c),d=h?P4(e):Fa(e),m=d.length-1,g=v=>h?0:d[v],p=v=>h?d[v+1]:e-d[v],w=Array.from({length:m},(v,S)=>new Float64Array(3*p(S))),b=new Float64Array(m),y=t6++;let A=0;for(const v of r){const S=v.owed;v.owed=null,S?.resolve(null)}const N=r.filter(v=>v.alive),I=N.length===0?[0,m]:Ba(d,e,N.length,s(u),a),M=[];for(let v=1;v+1<I.length;v++){const S=N[v-1];try{const k=s6(y,a,c,d,I[v],I[v+1],l);S.worker.postMessage(k,l?[]:[k.values.buffer])}catch{pn(S)}M.push({helper:S,from:I[v],to:I[v+1]})}const x=(v,S)=>{w[v].length===0&&(w[v]=new Float64Array(3*p(v))),b[v]=f===null?z4(u,null,e,d[v],d[v+1],S,w[v]):W4(f,u,null,d[v],d[v+1],S,w[v])};return{threads:1+M.filter(({helper:v})=>v.alive).length,async evaluate(v,S){A++;const k=M.map(({helper:F,from:E,to:_})=>!F.alive||!F.ready?Promise.resolve(null):new Promise($=>{F.owed={id:y,seq:A,resolve:$};const O=[];for(let D=E;D<_;D++)w[D].length===0&&(w[D]=new Float64Array(3*p(D))),O.push(w[D]);const L={kind:"evaluate",id:y,seq:A,point:v,parts:O};try{F.worker.postMessage(L,O.map(D=>D.buffer))}catch{pn(F)}}));for(let F=0;F<I[1];F++)x(F,v);const C=await Promise.all(k);M.forEach(({from:F,to:E},_)=>{const $=C[_];for(let O=F;O<E;O++){if($===null){x(O,v);continue}b[O]=$.values[O-F],w[O]=$.parts[O-F]}}),S.fill(0);let B=0;for(let F=0;F<m;F++){const E=b[F];if(!h&&!Number.isFinite(E))return Number.POSITIVE_INFINITY;B+=E,Y4(S,w[F],e,g(F),p(F))}return h||Number.isFinite(B)?B:Number.POSITIVE_INFINITY}}};return{threads:1+r.length,mds:a=>i("mds",{counts:a,n:e,alpha:1,bias:null,dispersion:null}),likelihood:a=>i("likelihood",a),close(){for(const a of r)pn(a)}}}function pn(e){if(!e.alive)return;e.alive=!1,e.worker.onmessage=null,e.worker.onerror=null,e.worker.terminate();const t=e.owed;e.owed=null,t?.resolve(null)}function Ea(e){return typeof SharedArrayBuffer=="function"&&e.buffer instanceof SharedArrayBuffer}function Ba(e,t,n,s,o="likelihood"){const r=e.length-1;for(let i=Math.min(n+1,r);i>1;i--){const a=$a+i-1,c=[0];for(let l=1;l<i;l++){const h=Math.round(r*($a+l-1)/a);h>c[c.length-1]&&h<r&&c.push(h)}c.push(r);let u=0;for(let l=1;l+1<c.length;l++)u+=g0(o,e[c[l]],e[c[l+1]],t)*s;if(c.length>2&&u<=Z4)return c}return[0,r]}function g0(e,t,n,s){let o=0;for(let r=t;r<n;r++)o+=e==="mds"?r:s-1-r;return o}function s6(e,t,n,s,o,r,i){const{n:a,counts:c}=n,u=s[o],l=s[r];let h=c;if(!i){const f=new(c instanceof Float64Array?Float64Array:Float32Array)(g0(t,u,l,a));let d=0;for(let m=u;m<l;m++){const g=t==="mds"?c.subarray(m*a,m*a+m):c.subarray(m*a+m+1,(m+1)*a);f.set(g,d),d+=g.length}h=f}return{kind:"setup",id:e,objective:t,n:a,alpha:n.alpha,bias:n.bias??null,dispersion:n.dispersion,edges:Array.from(s.subarray(o,r+1)),values:h,shared:i}}function o6(){return new Worker(new URL(""+new URL("likelihood.worker-CUgAXfAe.js",import.meta.url).href,import.meta.url),{type:"module"})}function is(e,t){const{nrows:n,ncols:s,values:o}=e;if(!(t>=1)||n===0||s===0)return o;const r=Math.floor(t),i=new Float32Array(n*s),a=new Float64Array(s),c=new Int32Array(s),u=(l,h)=>{if(l<0||l>=n)return;const f=l*s;for(let d=0;d<s;d++){const m=o[f+d];Number.isFinite(m)&&(a[d]+=h*m,c[d]+=h)}};for(let l=0;l<=r&&l<n;l++)u(l,1);for(let l=0;l<n;l++){l>0&&(u(l-r-1,-1),u(l+r,1));let h=0,f=0;for(let m=0;m<=r&&m<s;m++)h+=a[m],f+=c[m];const d=l*s;for(let m=0;m<s;m++){if(m>0){const p=m-r-1;p>=0&&(h-=a[p],f-=c[p]);const w=m+r;w<s&&(h+=a[w],f+=c[w])}const g=o[d+m];if(Number.isNaN(g)){i[d+m]=Number.NaN;continue}i[d+m]=f>0?h/f:g}}return i}const r6=192,i6=16e6,Ta=4e6,a6=.5;function Ne(e,t,n,s){const o=n+1,r=t-e+1,i=new Float64Array((r+1)*o);for(let a=0;a<r;a++){const c=a*o,u=(a+1)*o,l=(e+a)*n;let h=0;for(let f=0;f<n;f++)h+=s(l+f),i[u+f+1]=i[c+f+1]+h}return{table:i,stride:o,origin:e}}function wn(e,t,n,s,o){const{table:r,stride:i,origin:a}=e,c=(t-a)*i,u=(s-a+1)*i;return r[u+o+1]-r[c+o+1]-r[u+n]+r[c+n]}function c6(e,t,n,s){const{nrows:o,ncols:r,values:i}=e,a=Math.max(1,Math.floor(n.floor)),c={kind:"fixed",radius:a},u=()=>({values:is(e,a),over:s===void 0?null:is({...e,values:s},a)});if(o===0||r===0)return{values:i,over:s??null,applied:n,scope:null};if(o*r>i6)return{...u(),applied:c,scope:"adaptive smoothing not applied — block too large"};let l=0,h=0;const f=o*r;for(let v=0;v<f;v++){const S=t[v];Number.isFinite(S)&&S>0&&(l+=S,h++)}const d=h>0?l/h:0;if(!(d>0))return{...u(),applied:c,scope:null};const m=n.target*d,g=Math.min(r6,Math.max(o,r)),p=v=>Number.isFinite(i[v])&&(s===void 0||Number.isFinite(s[v])),w=Math.max(1,Math.floor(Ta/(r+1))-2*g);if(Math.min(o,w+2*g+1)*(r+1)>Ta*2)return{values:is(e,a),applied:c,over:s===void 0?null:is({...e,values:s},a),scope:"adaptive smoothing not applied — block too large"};const y=[];for(let v=0;v<o;v+=w){const S=Math.min(o-1,v+w-1);y.push([v,S,Math.max(0,v-g),Math.min(o-1,S+g)])}const A=(v,S,k,C,B,F)=>{const E=$=>{const O=S-$<C?C:S-$,L=k-$<0?0:k-$,D=S+$>B?B:S+$,q=k+$>=r?r-1:k+$;return wn(v,O,L,D,q)>=m};let _=F<a?a:F>g?g:F;if(E(_))for(;_>a&&E(_-1);)_--;else for(;_<g&&!E(_);)_++;return _},N=(v,S,k,C,B,F,E)=>{const _=k-B<F?F:k-B,$=C-B<0?0:C-B,O=k+B>E?E:k+B,L=C+B>=r?r-1:C+B,D=wn(S,_,$,O,L);return D>0?wn(v,_,$,O,L)/D:Number.NaN},I=new Float32Array(o*r);for(const[v,S,k,C]of y){const B=Ne(k,C,r,$=>{const O=t[$];return Number.isFinite(O)&&O>0?O:0}),F=Ne(k,C,r,$=>p($)?i[$]:0),E=Ne(k,C,r,$=>p($)?1:0);let _=a;for(let $=v;$<=S;$++){const O=$*r;let L=_;for(let D=0;D<r;D++){const q=i[O+D];if(!p(O+D)){I[O+D]=q;continue}L=A(B,$,D,k,C,L),D===0&&(_=L);const X=$-L<k?k:$-L,P=D-L<0?0:D-L,z=$+L>C?C:$+L,R=D+L>=r?r-1:D+L,H=wn(E,X,P,z,R)-1,K=H>0?(wn(F,X,P,z,R)-q)/H:0;I[O+D]=K>0?Math.min(q,K*(1+a6*H)):q}}}const M=new Float32Array(o*r),x=s===void 0?null:new Float32Array(o*r);for(const[v,S,k,C]of y){const B=Ne(k,C,r,O=>{const L=t[O];return Number.isFinite(L)&&L>0?L:0}),F=Ne(k,C,r,O=>p(O)?I[O]:0),E=s===void 0?null:Ne(k,C,r,O=>p(O)?s[O]:0),_=Ne(k,C,r,O=>p(O)?1:0);let $=a;for(let O=v;O<=S;O++){const L=O*r;let D=$;for(let q=0;q<r;q++){const X=i[L+q];if(Number.isNaN(X)){M[L+q]=Number.NaN,x!==null&&(x[L+q]=Number.NaN);continue}D=A(B,O,q,k,C,D),q===0&&($=D);const P=D>>1<a?a:D>>1,z=D+(D>>1)>g?g:D+(D>>1);let R=0,H=0,K=0;for(const G of[P,D,z]){const W=N(F,_,O,q,G,k,C);Number.isNaN(W)||(R+=W,H++,E!==null&&(K+=N(E,_,O,q,G,k,C)))}M[L+q]=H>0?R/H:X,x!==null&&(x[L+q]=H>0?K/H:s?.[L+q]??Number.NaN)}}}return{values:M,over:x,applied:n,scope:null}}function l6(e){return`${e.contig}:${(e.start+1).toLocaleString("en-US")}-${e.end.toLocaleString("en-US")}`}function Vr(e,t){return`${e}:${u6(t)}`}function u6(e){return(e+1).toLocaleString("en-US")}function p0(e){const t=h6(e);if(t===null)return e;const[n,s,o]=t;return s===null?e:o===null?`${n}:${(s+1).toLocaleString("en-US")}-`:l6({contig:n,start:s,end:o})}function h6(e){const t=e.indexOf(":");if(t<0)return[e,null,null];const n=e.slice(t+1).replace(/–|\.\./g,"-");try{return Vs(`${e.slice(0,t)}:${n}`,{reversed:!0})}catch{return null}}function Q(e,t,n){const s=e[t];return typeof s=="number"&&Number.isFinite(s)?s:n}function ct(e,t,n){const s=e[t];return typeof s=="string"?s:n}function nt(e,t,n){const s=e[t];return typeof s=="boolean"?s:n}function f6(e,t){const n=e[t];return Array.isArray(n)?n.filter(s=>typeof s=="string"):typeof n=="string"&&n!==""?[n]:[]}function te(e,t){const n=e[t];return Array.isArray(n)?n.filter(s=>typeof s=="string"):typeof n=="string"&&n.trim()!==""?[n.trim()]:null}function Bs(e,t){const n=e[t];return typeof n=="string"&&n!==""?n:null}function Ts(e,t,n){return{value:e?.[n],chosen:Bs(t,n)!==null}}function w0(e,t){return e.value!==void 0?null:e.chosen?t.gone:t.unchosen}function Be(e,t,n){if(e.hasContig(t))return e.contigId(t);const s=e.names.find(t,...n===void 0?[]:[{from:n}]);return s===null||!e.hasContig(s.name)?-1:e.contigId(s.name)}function Xs(e,t,n){const s=new Set,o=[];for(const r of t){const i=Be(e,r,n);i<0?o.push(r):s.add(i)}return{ids:[...s].sort((r,i)=>r-i),missing:o}}function Te(e,t){const n=e.framing.circular;if(n===void 0||n.length===0)return!1;if(n.includes(t))return!0;const s=e.mc.hasContig(t)?e.mc.contigId(t):-1;return s<0?!1:n.some(o=>Be(e.mc,o)===s)}function b0(e,t){const n=e.framing.origins;if(n===void 0)return;const s=n[t];if(typeof s=="number"&&Number.isFinite(s))return s;const o=e.mc.hasContig(t)?e.mc.contigId(t):-1;if(!(o<0)){for(const[r,i]of Object.entries(n))if(typeof i=="number"&&Number.isFinite(i)&&Be(e.mc,r)===o)return i}}function Ze(){const e=new Error("cancelled");return e.name="AbortError",e}class as{constructor(t,n){this.rows=t,this.cols=n,this.sum=new Float64Array(t*n),this.count=new Float64Array(t*n)}sum;count;windows=0;add(t){let n=!1;for(let s=0;s<this.sum.length;s++){const o=t[s];Number.isFinite(o)&&(this.sum[s]+=o,this.count[s]+=1,n=!0)}n&&this.windows++}finish(){const t=new Float32Array(this.sum.length);for(let n=0;n<t.length;n++)t[n]=this.count[n]>0?this.sum[n]/this.count[n]:Number.NaN;return{values:t,n:this.windows}}}function A0(e,t,n,s,o){const r=new Float64Array(s*o);if(t===s&&n===o){for(let u=0;u<r.length;u++)r[u]=e[u];return r}const i=new Float64Array(s*o),a=s/t,c=o/n;for(let u=0;u<t;u++){const l=u*a,h=(u+1)*a;for(let f=0;f<n;f++){const d=e[u*n+f];if(!Number.isFinite(d))continue;const m=f*c,g=(f+1)*c;for(let p=Math.floor(l);p<Math.min(s,Math.ceil(h));p++){const w=Math.min(h,p+1)-Math.max(l,p);if(w>0)for(let b=Math.floor(m);b<Math.min(o,Math.ceil(g));b++){const y=Math.min(g,b+1)-Math.max(m,b);if(!(y>0))continue;const A=w*y;r[p*o+b]+=d*A,i[p*o+b]+=A}}}}for(let u=0;u<r.length;u++)r[u]=i[u]>0?r[u]/i[u]:Number.NaN;return r}function y0(e,t,n,s,o){const r=s.length-1,i=o.length-1,a=new Float64Array(r*i);for(let c=0;c<r;c++){const u=s[c],l=s[c+1],h=Math.max(0,Math.floor(u)),f=Math.min(t,Math.ceil(l));for(let d=0;d<i;d++){const m=o[d],g=o[d+1],p=Math.max(0,Math.floor(m)),w=Math.min(n,Math.ceil(g));let b=0,y=0;for(let A=h;A<f;A++){const N=Math.min(l,A+1)-Math.max(u,A);if(!(N>0))continue;const I=A*n;for(let M=p;M<w;M++){const x=e[I+M];if(!Number.isFinite(x))continue;const v=Math.min(g,M+1)-Math.max(m,M);if(!(v>0))continue;const S=N*v;b+=x*S,y+=S}}a[c*i+d]=y>0?b/y:Number.NaN}}return a}function d6(e,t,n){const s=n<t?Math.ceil(t/n):1,o=n*s,r=o>1?(t-1)/(o-1):1,i=new Int32Array(n),a=[];for(let f=0;f<n;f++){let d=Number.POSITIVE_INFINITY,m=-1;const g=[];for(let w=f*s;w<(f+1)*s;w++){const b=w*r;if(b>t-1)continue;const y=Math.floor(b),A=b-y;g.push([y,1-A]),y+1<t&&g.push([y+1,A]),d=Math.min(d,y),m=Math.max(m,y+1<t?y+1:y)}if(m<0){i[f]=0,a.push(new Float64Array(0));continue}const p=new Float64Array(m-d+1);for(const[w,b]of g)p[w-d]+=b;i[f]=d,a.push(p)}const c=new Float64Array(t*n),u=new Float64Array(t*n);for(let f=0;f<t;f++)for(let d=0;d<n;d++){const m=a[d],g=i[d];let p=0,w=0;for(let b=0;b<m.length;b++){const y=e[f*t+g+b];Number.isFinite(y)?p+=m[b]*y:w+=m[b]}c[f*n+d]=p,u[f*n+d]=w}const l=new Float64Array(n*n),h=1/(s*s);for(let f=0;f<n;f++){const d=a[f],m=i[f];for(let g=0;g<n;g++){let p=0,w=0;for(let b=0;b<d.length;b++)p+=d[b]*c[(m+b)*n+g],w+=d[b]*u[(m+b)*n+g];l[f*n+g]=w>0?Number.NaN:p*h}}return l}function m6(e,t,n,s){const r=.5*(2*n+1-1)*(t-e);return{from:Math.floor(Oa(e-r)/s),to:Math.ceil(Oa(t+r)/s)}}function Oa(e){const t=Math.floor(e),n=e-t;return n>.5?t+1:n<.5||t%2===0?t:t+1}function g6(e,t){const n=Math.max(3,Math.round(e)),s=Math.max(0,t),o=Math.floor((n-1)/2),r=Math.min(o,Math.round(n*s/(1+2*s)));return{side:n,flank:r,body:n-2*r}}function N0(e,t,n,s){const o=new Float64Array(e.side+1);for(let r=0;r<e.flank;r++)o[r]=t-s+s*r/e.flank;for(let r=0;r<=e.body;r++)o[e.flank+r]=t+(n-t)*r/e.body;for(let r=1;r<=e.flank;r++)o[e.flank+e.body+r]=n+s*r/e.flank;return o}function La(e,t){const{side:n,flank:s,body:o}=t;if(s===0||o===0)return Number.NaN;const r=Math.max(1,Math.round(o/4)),i=Math.min(s,r),a=(d,m,g,p)=>{let w=0,b=0;for(let y=Math.max(0,d);y<Math.min(n,m);y++)for(let A=Math.max(0,g);A<Math.min(n,p);A++){const N=e[y*n+A];Number.isFinite(N)&&(w+=N,b++)}return b===0?Number.NaN:w/b},c=a(s,s+r,s+o-r,s+o),u=[],l=a(s-i,s,s+o-r,s+o);Number.isFinite(l)&&u.push(l);const h=a(s,s+r,s+o,s+o+i);if(Number.isFinite(h)&&u.push(h),!Number.isFinite(c)||u.length===0)return Number.NaN;const f=u.reduce((d,m)=>d+m,0)/u.length;return f===0?Number.NaN:c/f}function fr(e,t,n){const s=Math.max(1,Math.floor(Math.min(t,n)/5)),o=Math.floor(t/2),r=Math.floor(n/2),i=Math.max(0,Math.floor(s/2)),a=(l,h,f,d)=>{let m=0,g=0;for(let p=Math.max(0,l);p<Math.min(t,h);p++)for(let w=Math.max(0,f);w<Math.min(n,d);w++){const b=e[p*n+w];Number.isFinite(b)&&(m+=b,g++)}return g===0?Number.NaN:m/g},c=a(o-i,o+i+1,r-i,r+i+1),u=a(t-s,t,0,s);return!Number.isFinite(c)||!Number.isFinite(u)||u===0?Number.NaN:c/u}function p6(e,t){const n=new Float32Array(e.length);for(let s=0;s<n.length;s++){const o=e[s],r=t[s];n[s]=Number.isFinite(o)&&Number.isFinite(r)&&r!==0?o/r:Number.NaN}return n}function w6(e,t,n){const s=[];for(let o=0;o<n.perPair;o++){const r=n.minShift+Math.floor(n.rng()*(n.maxShift-n.minShift+1)),i=n.rng()<.5?-1:1,a=e.row+i*r,c=e.col+i*r;a<t.from||c>=t.to||s.push({row:a,col:c,separation:e.separation})}return s}const b6=2e3;function Js(e,t){const n=e.filter(i=>i.separation>0&&Number.isFinite(i.score)).map(i=>({separation:i.separation,score:i.score})).sort((i,a)=>i.separation-a.separation);if(n.length<2)return null;const s=Math.ceil(n.length/(t.cap??b6)),o=s<=1?n:n.filter((i,a)=>a%s===0),r=A6(n);return{kind:"curve",id:t.id,label:t.label,series:[{name:`${n.length.toLocaleString()} ${t.noun}`,x:Float64Array.from(o,i=>i.separation),y:Float64Array.from(o,i=>i.score),n:n.length,mark:"points"},{name:"median",x:r.x,y:r.y,n:n.length}],xLabel:"Separation between anchors (bp)",yLabel:t.yLabel,xScale:"log",yScale:"linear"}}function A6(e){const t=e[0].separation,n=e[e.length-1].separation,s=Math.max(3,Math.min(24,Math.round(Math.sqrt(e.length)))),o=n>t?Math.log(n/t)/s:0,r=Array.from({length:s},()=>[]),i=Array.from({length:s},()=>[]);for(const u of e){const l=o>0?Math.min(s-1,Math.floor(Math.log(u.separation/t)/o)):0;r[l].push(u.score),i[l].push(u.separation)}const a=[],c=[];for(let u=0;u<s;u++)r[u].length!==0&&(a.push(_a(i[u])),c.push(_a(r[u])));return{x:Float64Array.from(a),y:Float64Array.from(c)}}function _a(e){const t=[...e].sort((s,o)=>s-o),n=t.length>>1;return t.length%2===1?t[n]:(t[n-1]+t[n])/2}function Xr(e){let t=(Number.isFinite(e)?Math.trunc(e):0)>>>0;return function(){t=t+1831565813>>>0;let s=t;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}function y6(e){const t=new Uint32Array(624);t[0]=(Number.isFinite(e)?Math.trunc(e):0)>>>0;for(let o=1;o<624;o++){const r=t[o-1]^t[o-1]>>>30;t[o]=Math.imul(1812433253,r)+o>>>0}let n=624;const s=()=>{if(n>=624){for(let r=0;r<624;r++){const i=t[r]&2147483648|t[(r+1)%624]&2147483647;t[r]=t[(r+397)%624]^i>>>1^(i&1?2567483615:0)}n=0}let o=t[n++];return o^=o>>>11,o^=o<<7&2636928640,o^=o<<15&4022730752,o^=o>>>18,o>>>0};return function(){const r=s()>>>5,i=s()>>>6;return(r*67108864+i)/9007199254740992}}const je=[{name:"loops",blurb:"Focal contacts between two anchors — the classic dot off the diagonal.",minDist:2e4,maxDist:2e6,maxIterations:1,maxPercZero:10,maxPercUndetected:50,minSeparation:5e3,pearson:.3,resolution:2e3,onDiagonal:!1,sizes:[17]},{name:"loops_small",blurb:"The same, at a tighter 7×7 template, for short-range dots.",minDist:2e4,maxDist:2e6,maxIterations:1,maxPercZero:10,maxPercUndetected:50,minSeparation:5e3,pearson:.5,resolution:2e3,onDiagonal:!1,sizes:[7]},{name:"borders",blurb:"Domain boundaries: the corner where one self-interacting block ends and the next begins.",minDist:0,maxDist:0,maxIterations:1,maxPercZero:10,maxPercUndetected:75,minSeparation:5e3,pearson:.15,resolution:5e3,onDiagonal:!0,sizes:[17,17,17]},{name:"hairpins",blurb:"The fold-back signal of a hairpin, on the diagonal.",minDist:0,maxDist:0,maxIterations:1,maxPercZero:10,maxPercUndetected:75,minSeparation:5e3,pearson:.1,resolution:1e4,onDiagonal:!0,sizes:[15]},{name:"centromeres",blurb:"The large-scale depletion around a centromere.",minDist:0,maxDist:0,maxIterations:1,maxPercZero:30,maxPercUndetected:50,minSeparation:1e5,pearson:.5,resolution:2e3,onDiagonal:!0,sizes:[81]},{name:"stripes_left",blurb:"An architectural stripe running left from an anchor.",minDist:6e4,maxDist:2e6,maxIterations:1,maxPercZero:80,maxPercUndetected:50,minSeparation:4e4,pearson:.17,resolution:1e4,onDiagonal:!1,sizes:[31]},{name:"stripes_right",blurb:"An architectural stripe running right from an anchor.",minDist:6e4,maxDist:2e6,maxIterations:1,maxPercZero:80,maxPercUndetected:50,minSeparation:4e4,pearson:.17,resolution:1e4,onDiagonal:!1,sizes:[31]}];function N6(e){return e.hasWeights}const M0={kind:"toggle",key:"balance",label:"use balancing weights",default:!1,derive:N6},Lo=y5.filter(N5);function Os(e){const t=e.at;return t==="start"||t==="end"?t:"centre"}function M6(e){const t=typeof e.window=="number"?e.window:21;return Math.max(1,Math.min(200,Math.round(t)))}function Nt(e){return e.mode==="scaled"&&e.norm!=="chromosight"}function I6(e){return e.norm==="chromosight"}const dr=2;function x6(e){const t=typeof e.minDiag=="number"?e.minDiag:dr;return Number.isFinite(t)?Math.max(0,Math.round(t)):dr}const I0=5;function v6(e){const t=e.minDist;return typeof t=="number"&&Number.isFinite(t)?Math.max(0,Math.round(t)):I0}function He(e){const t=typeof e.flankFraction=="number"?e.flankFraction:.5;return Math.max(0,Math.min(4,t))}function Zs(e){return Nt(e)&&Xt(e)}function x0(e){return Zs(e)&&e.norm==="oe"}function Xt(e){return e.anchors!=="pairs"&&e.anchors!=="allpairs"&&e.anchors!=="consecutive"}function k6(e){return!Xt(e)&&e.symmetric!==!1}function S6(e){const t=e.tracks;return Array.isArray(t)?t.length>0:typeof t=="string"&&t!==""}function _o(e){return e.anchors==="features"&&typeof e.rankBy=="string"&&e.rankBy!==""}function v0(e){return e.anchors==="pairs"}function Da(e){return e.anchors==="allpairs"}function k0(e){return e.anchors==="consecutive"}function C6(e){if(Xt(e))return 1;const t=typeof e.byDistance=="number"?Math.round(e.byDistance):0;return t>1?Math.min(S0,t):1}const S0=6,Ra=2e5;je.map(e=>({value:e.name,label:e.name.replace(/_/g," "),hint:e.blurb}));const F6={loops:[{size:17,values:[.85312823,.84999888,.86449323,.89848067,.89731004,.8828079,.8991951,.93574241,.98626893,.94680858,.92496206,.90751005,.91428048,.87331718,.89081318,.88887735,.89812284,.87427503,.84537754,.82985454,.81558,.89584271,.88080858,.91475572,.95848669,.96150597,.98247128,.90971439,.89248861,.85932324,.80995337,.88023035,.86361754,.8646012,.8692519,.88788988,.84916643,.85686,.86176338,.87028908,.91911272,.96605567,.96166305,.96432123,.92984099,.89885302,.85358974,.85747452,.86083162,.822195,.88605451,.88360881,.81610713,.86454241,.85453919,.88771835,.90972731,.99139015,1.0591303,1.0764743,1.0508512,.94905558,.91890882,.907508,.89806679,.84979212,.80942624,.88818904,.89273526,.86257584,.8398885,.90191445,.92520181,.9669612,1.0207693,1.1247707,1.1201985,1.110737,1.0138251,.97310288,.94194931,.8933119,.87546462,.89259011,.91885526,.8873561,.87646597,.87459739,.93436395,.96454701,.96674092,1.0503075,1.1603753,1.1935154,1.1222083,1.0359268,1.0131198,.97551707,.89427219,.89454472,.89683122,.90296185,.8897287,.9113657,.92834789,.9646179,1.0079169,1.030991,1.1441288,1.2773436,1.3594681,1.2540048,1.1579206,1.0552433,1.0266774,.97582784,.92060582,.9131044,.93442846,.92655103,.98995901,.95292056,1.0712673,1.1226021,1.1346177,1.294605,1.5249332,1.6538844,1.4644965,1.2367435,1.1479659,1.1129056,1.0387143,.97745634,.95099896,.95599996,1.000965,.99160949,.99041644,1.0976704,1.1502586,1.1870256,1.3883191,1.6925473,1.7306489,1.6152215,1.330617,1.2000051,1.0901384,1.0552782,.93290965,.93140245,.97157288,.92655103,.98995901,.95292056,1.0712673,1.1226021,1.1346177,1.294605,1.5249332,1.6538844,1.4644965,1.2367435,1.1479659,1.1129056,1.0387143,.97745634,.95099896,.95599996,.8897287,.9113657,.92834789,.9646179,1.0079169,1.030991,1.1441288,1.2773436,1.3594681,1.2540048,1.1579206,1.0552433,1.0266774,.97582784,.92060582,.9131044,.93442846,.8873561,.87646597,.87459739,.93436395,.96454701,.96674092,1.0503075,1.1603753,1.1935154,1.1222083,1.0359268,1.0131198,.97551707,.89427219,.89454472,.89683122,.90296185,.89273526,.86257584,.8398885,.90191445,.92520181,.9669612,1.0207693,1.1247707,1.1201985,1.110737,1.0138251,.97310288,.94194931,.8933119,.87546462,.89259011,.91885526,.88360881,.81610713,.86454241,.85453919,.88771835,.90972731,.99139015,1.0591303,1.0764743,1.0508512,.94905558,.91890882,.907508,.89806679,.84979212,.80942624,.88818904,.8692519,.88788988,.84916643,.85686,.86176338,.87028908,.91911272,.96605567,.96166305,.96432123,.92984099,.89885302,.85358974,.85747452,.86083162,.822195,.88605451,.87427503,.84537754,.82985454,.81558,.89584271,.88080858,.91475572,.95848669,.96150597,.98247128,.90971439,.89248861,.85932324,.80995337,.88023035,.86361754,.8646012,.85312823,.84999888,.86449323,.89848067,.89731004,.8828079,.8991951,.93574241,.98626893,.94680858,.92496206,.90751005,.91428048,.87331718,.89081318,.88887735,.89812284]}],loops_small:[{size:7,values:[.96674092,1.0503075,1.1603753,1.1935154,1.1222083,1.0359268,1.0131198,1.030991,1.1441288,1.2773436,1.3594681,1.2540048,1.1579206,1.0552433,1.1346177,1.294605,1.5249332,1.6538844,1.4644965,1.2367435,1.1479659,1.1870256,1.3883191,1.6925473,1.7306489,1.6152215,1.330617,1.2000051,1.1346177,1.294605,1.5249332,1.6538844,1.4644965,1.2367435,1.1479659,1.030991,1.1441288,1.2773436,1.3594681,1.2540048,1.1579206,1.0552433,.96674092,1.0503075,1.1603753,1.1935154,1.1222083,1.0359268,1.0131198]}],borders:[{size:17,values:[1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5]},{size:17,values:[1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5]},{size:17,values:[.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,.5,.5,.5,.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5]}],hairpins:[{size:15,values:[.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,1.75,1.75,1.75,1.75,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5]}],centromeres:[{size:81,values:[1.2281821,1.5665572,1.4762153,1.2397266,1.635678,1.5984158,1.1191438,1.559039,2.4802534,1.6591749,1.3981162,1.5282018,1.8675983,1.8368934,1.774249,1.3852965,1.8730091,1.6371324,1.586814,1.582305,1.1812525,1.6710035,1.6708221,1.3683022,1.5944455,1.5520679,1.6823268,1.4757592,1.6575846,1.5005167,1.9364187,.77497146,1.1736426,.7974988,1.3514356,1.2565539,1.0873172,.66686457,1.3130565,.55905722,.82774648,1.0764362,.84438987,.98804222,.9512087,1.060165,1.153551,1.6506198,.83026034,1.2553665,1.2039925,1.826186,1.5281806,1.9149942,1.8528276,1.385265,1.4134311,1.3303022,1.4539632,1.3152465,1.7132557,1.8423132,2.1014836,1.6568267,2.1174016,1.4646016,1.4565563,1.6645845,1.6118399,1.9165392,1.5504494,1.6615528,2.5067972,2.3427305,1.6964471,2.1217943,1.7786356,1.771775,2.1123204,1.7533281,1.6200988,1.1142446,1.1891177,1.7021685,1.639686,1.4593039,1.2757495,1.2551392,1.1521365,1.4428055,1.5304253,1.6840202,1.7142015,1.3704876,1.4896554,1.9912845,1.8217913,1.8117989,1.6721571,1.429595,1.5178622,1.5898692,1.9172806,1.5962391,1.6772917,1.4224527,1.4945697,2.2835728,1.466699,1.6035575,1.5943082,1.1777293,1.3931749,1.2491393,1.4212451,1.2184207,1.0032095,.92111424,1.0393002,.8825064,.79913533,1.0245933,1.0570704,.90549327,.8787752,.91563503,1.0011201,1.4246769,1.1501216,1.2888828,1.1041855,1.696173,1.1296678,1.5008347,1.6407639,1.4500274,1.515316,1.6536225,1.3547914,1.3714829,1.5561923,1.8723597,1.5399201,1.6435546,1.5183806,1.4932029,2.1514542,1.8814164,2.802379,2.1633295,1.6002091,1.6440576,2.1647862,1.830919,2.1789371,3.0088628,1.935386,1.5612024,1.5137108,1.4917002,1.8859538,2.0889227,1.2653756,1.2882204,1.436168,1.7437268,1.3614143,1.7534004,1.286542,1.6634342,1.3038817,1.627952,1.3141127,1.7861668,1.993894,2.0019478,1.2589192,1.5552105,1.3838447,1.7378047,1.5095603,1.9744936,1.483336,2.113924,1.7916639,2.2426275,1.6007411,1.2886184,1.4264287,1.2244309,1.7650874,1.4205113,.97194903,1.2512782,1.3192343,1.2608687,.93649722,1.0101217,.79693481,.66068132,.81619306,1.1270831,1.002784,1.004373,.7460736,.95066683,.99090385,.72778255,1.393795,1.3307624,1.0262551,1.1274217,1.0601048,1.8038424,1.4231768,1.4432051,1.2320833,1.4569727,2.0010981,1.5366687,1.6542766,1.5540459,1.3044308,1.7356108,1.5684255,2.2121276,1.7177643,1.2819309,1.6424472,1.875896,2.20556,1.7448882,1.235719,1.664337,1.908706,1.439897,1.6938442,1.6965743,1.8139262,1.2152072,2.0635421,1.7899035,1.9085503,1.4717358,1.8123437,1.3793539,1.508161,1.613869,1.3818616,1.2832351,1.3862234,1.3115369,1.3360966,1.560245,1.7229718,2.0436006,1.458418,1.3780453,1.7767131,1.507528,1.7311624,1.8606006,1.5818158,1.6381555,1.446764,1.600451,1.0989136,1.2589428,1.9540058,1.4195192,1.2222831,1.3252366,1.9032141,1.6887659,1.1926241,1.7335094,1.0989058,1.2302038,1.236687,.73329478,.84531655,.92779841,.88813244,.72984081,.87727784,1.130269,1.0297311,.82484452,.85460535,.94327788,1.2437314,1.1746982,1.4538097,1.2926531,1.2188052,1.5403496,1.4188448,1.7986682,1.5249981,1.7523987,1.9165484,1.8156769,1.6500994,1.2770293,1.7436501,2.088007,2.6148127,1.2488737,1.8443432,1.5969489,1.6326269,1.9893896,2.1291717,2.4289678,1.6119557,1.6056789,2.1228301,1.3976315,1.7689038,1.961196,1.7038397,2.5312481,2.0318371,2.1387169,1.0463385,1.1705493,1.3610896,1.2953676,1.0248097,1.7215619,1.2272949,1.723823,1.6528966,1.250391,1.1906423,1.561404,1.3797916,1.5852771,1.4151383,1.7869095,1.6341682,1.3648291,2.1641315,1.6603348,1.9343634,1.3871896,1.6664489,1.3139517,1.7663311,1.4575318,1.3906609,1.6209767,1.2610888,1.3671377,1.3220515,1.6884327,1.6723102,1.3172839,1.4343311,1.0677345,1.2205866,.99977567,1.1954819,.83141566,1.0253346,.82844489,.89418014,1.1647021,.90523327,.69101007,1.0894265,1.1501319,1.2677724,1.2699685,1.3907603,1.4418155,1.6205801,2.0170201,1.3784159,1.6021307,1.6869586,1.6336618,1.7067967,2.4468134,1.844659,1.9859419,1.6549902,1.2099298,1.6607599,1.9804752,1.7192682,1.8559679,1.7126817,1.8062766,1.8028094,2.1401791,1.683478,2.1551589,2.1193484,1.8661304,2.0174786,2.2214514,1.5978211,1.3854038,1.2656458,1.4859479,1.6040474,1.2464047,1.2730952,1.3796375,.96158352,1.5179224,1.8743632,1.4643206,1.6832089,1.5515785,1.6055125,1.7445488,1.862286,1.5491368,1.3624474,1.6119064,1.7074539,2.3156789,2.2985598,1.9235266,1.6576506,1.8274361,1.8219517,1.9124709,1.799844,1.4789926,1.2060526,1.2903157,1.6558607,1.6150645,1.6487009,1.1791305,1.1926907,1.4351337,1.2679291,1.0158968,.92592944,.75581679,1.1352978,.82153411,1.0007804,.92663681,1.0171561,1.1634271,1.0762344,1.2042936,1.3604298,1.3490448,1.1579155,1.2690319,1.7705364,1.7218791,2.2015845,1.4287451,1.5850552,2.0926797,1.5189462,2.3673894,1.7228599,1.8850001,1.4887195,1.7528845,1.9097913,1.5012268,1.5452881,1.8121949,1.9665804,1.8487535,1.4795083,2.0728987,1.8907705,2.2612062,2.7537088,2.0293423,2.5500304,1.9742728,1.8874839,2.007173,1.9113256,1.6338367,1.3350004,1.6093612,1.3257089,1.3066841,1.2581263,1.0365617,1.1421176,1.4151261,1.3789035,1.579346,1.611804,1.5175564,1.4924479,1.566885,1.9519575,1.8140691,1.985468,1.4742501,1.3554018,1.4682532,2.2356139,1.6621601,1.8262554,1.7778474,1.7725874,1.4244114,1.7300352,1.8371789,2.104406,1.3607506,1.6998209,1.1803949,1.4845493,1.087594,1.2450712,.81127339,1.1827991,.88222719,.90203792,.84604752,.85304682,.75612027,.99922702,1.2599842,.87687157,1.5081939,.98047087,1.2154685,1.3645392,1.0278316,1.3450874,1.7477078,2.3201213,1.6606412,1.7111159,2.4422814,1.5996084,1.6906186,1.6328091,1.6007609,1.8818963,1.5296549,1.9085197,1.8377088,1.8927013,2.4795272,1.9323645,1.9869591,1.7035839,1.919089,1.8148035,1.7302709,1.4815153,1.5841561,1.6922544,1.9853494,1.9113969,2.3635356,2.5781922,1.8684073,1.9273321,1.3888996,1.16525,1.3951398,1.1518959,1.5884502,1.1116862,1.5847148,1.5489369,1.7048899,1.8260978,1.5973448,1.4765868,2.2349854,1.714829,1.8828616,1.5839577,2.0294049,1.698403,1.8761481,1.8398768,2.1351538,2.3300878,1.9213591,1.7422279,2.0318438,1.9443019,1.8530272,1.5796115,1.8278486,1.5622321,1.6671014,1.8839342,1.6375991,1.4479651,1.3310351,1.0633794,1.4914018,.94964838,1.0430462,.95611353,.93278743,1.0904492,1.3084238,1.3913446,1.339618,1.3237439,1.473057,1.1172476,1.3599359,2.0216424,1.465996,1.4795925,1.7805525,1.8687939,1.7478032,2.1702265,1.7689065,2.5504444,1.808126,1.4951132,1.7454758,1.7351118,1.7278428,1.8810956,1.8253533,1.8974336,2.2131159,1.87621,2.1697527,1.9828608,2.3852555,1.9192996,2.039803,1.7642199,2.5191192,1.9039362,2.8849176,1.8894482,1.822512,2.0449776,1.9508479,1.3851861,1.5838111,1.3428709,1.3804065,1.3009546,1.4232557,1.5050843,1.4508404,1.5369379,1.4068913,1.8025772,1.4522079,1.8348206,2.4397466,1.8612876,2.1105862,1.5424866,1.7611775,1.829651,2.0527963,2.0009949,2.1535336,1.9658227,1.2884804,1.8677063,2.4132432,1.5548323,1.8566468,2.1679707,2.176818,2.0091718,1.7847282,1.5977346,1.5571175,1.6981142,1.0740788,1.4925847,1.160238,1.095743,1.3577438,1.2746748,.87894146,1.0822266,1.2110714,1.0400777,1.131795,1.1426784,1.1213092,1.6466643,1.5691323,1.8709124,1.6881095,1.3581907,1.8956749,1.5102003,2.0871289,1.7838157,1.5408709,2.1896332,1.7226656,1.6179185,2.8293784,1.7330855,1.957682,2.0346655,1.9221937,1.7223971,1.5972463,1.9361893,1.9319625,2.2871439,1.8569278,1.8148895,2.0745643,2.0657642,1.5723105,1.9182782,1.8038725,2.2353551,1.9939921,2.0206593,1.7988806,1.3982423,1.1747897,1.2994286,1.4016155,1.4093024,.96687983,1.3277113,1.3894779,1.6831804,1.6894799,1.7755053,1.8315352,2.1090953,1.8594914,1.7148616,1.5875902,1.5850218,1.6426416,1.5850378,1.7510098,1.8077193,1.7298094,1.8856004,1.7227693,2.209243,1.7519225,1.2271658,1.7335581,1.6458039,2.2460944,1.2994318,1.4802563,1.8950261,1.0364234,1.2515673,.66252274,1.2283045,.97173188,1.134374,1.09104,.97425805,1.2715438,1.4059462,1.2011455,.93735762,1.2652993,1.0615703,1.3271563,1.0748616,1.7672229,1.2732235,2.1903528,1.7783523,1.6515845,2.1073992,1.7080223,2.7413453,2.0114994,2.273893,1.6673248,1.9709255,1.6759152,1.8492865,1.6426177,1.8251729,1.6958557,1.7151299,1.8145959,2.0592947,2.0668286,1.5571022,2.4473328,2.1197413,1.4871664,2.2371904,2.6019438,1.6269761,2.5724959,2.171419,1.8867702,1.3011648,1.6058634,1.2794605,1.1385628,1.8482499,1.5360197,1.729164,1.3665132,1.658138,1.3848169,1.6089256,2.0301362,1.8384875,2.2911403,1.8820747,2.3757763,1.7114301,1.8261708,1.7040414,1.7842767,1.5048127,2.6808743,2.1360954,2.2111987,1.6227312,1.8569816,2.1859847,1.880047,2.0560867,1.6916072,1.7646106,1.7667278,1.7352207,1.4893796,1.2628871,2.348805,1.4622192,1.2501143,.95730636,1.021558,.8335584,1.0402648,1.216886,1.1699272,1.335345,1.2303404,1.6594952,1.566163,1.3729238,1.9305437,1.8977699,2.0418087,2.0898778,1.9965275,1.8061095,1.7717002,2.0137702,1.373344,1.9660341,2.3979575,1.8508722,1.7363805,1.4894547,2.1344598,2.058871,1.8372765,2.0875807,1.7086021,1.6427717,1.5847233,1.4610139,1.8679585,1.6271029,2.580351,2.5102036,2.2195124,2.0551551,1.6232778,2.0402827,2.0967432,1.9106916,1.5564293,2.0628769,1.1160338,1.7733892,1.6869719,1.6864402,1.8082074,1.8250731,1.8907896,1.4485662,1.7532252,1.9866841,1.7308821,1.8393791,2.0070016,1.6668975,2.3154035,2.5732324,1.8469527,2.481187,2.4683161,2.6018325,1.6662509,2.7406655,1.9282628,1.7686076,1.7964852,1.3553925,2.0367599,2.9438648,2.9661425,1.7069741,1.7378013,2.0120382,1.5178378,1.46907,1.9991083,1.301083,1.1298421,1.4151063,.81451338,1.2869426,1.5404901,1.3913848,1.3971248,1.18675,1.1296599,1.5678574,1.8027911,1.5745133,2.3497138,1.9799344,2.0048491,1.8559884,1.4185151,1.6679042,2.4730395,1.8462868,1.8456426,2.4281857,2.2020008,2.411478,2.2818341,1.8633196,1.8932787,2.2789318,1.944635,1.7871921,1.7499025,1.5618166,1.8835028,1.3829753,2.0401064,2.2925753,2.539569,2.6714908,1.6314713,2.5406506,1.7785248,2.1109043,1.3598737,1.6092047,1.3169494,2.4825281,1.6557949,2.0776093,2.2698974,2.0211097,2.2204884,1.7903639,1.8578211,1.8313128,1.9219363,2.0618585,2.6322246,2.3104224,2.3507939,1.5242865,2.5784967,1.632481,2.123599,2.1901284,2.2728947,1.8640019,2.6262222,2.2030846,1.9803192,2.3606338,2.1471387,2.0391922,1.9227836,1.8741521,1.8355501,1.5323782,1.9299325,1.354171,1.5001559,1.2631218,1.5976992,1.4785029,1.0034022,1.1290856,1.3022414,1.7698572,1.3905626,1.3731824,1.624604,1.8550657,1.9723663,2.0495023,2.2467138,1.9595726,2.1096505,1.8632877,2.0176779,2.5621678,2.4075573,1.8180857,2.6465756,1.9605823,2.2771967,2.1163069,1.9386753,1.7247073,2.0010282,1.8549208,1.5712025,1.921265,1.9280373,1.9338265,2.0879407,2.0506003,2.1127958,1.8003571,2.2878993,2.8865805,2.0052722,1.9004884,2.1782886,1.9820993,1.7875423,1.9661973,1.8724601,1.5974332,1.3361324,1.3912742,1.4647316,1.2579849,1.4850515,1.3075636,1.6482255,1.8531702,1.2797063,1.6027614,1.5516375,2.0038152,1.6038294,1.4639799,2.056078,1.7761721,1.3799626,1.9920462,2.2494585,1.9465089,1.8858784,2.357125,2.4795207,1.520614,2.1945038,1.8087004,2.3974498,2.6052038,2.5246852,1.6118728,2.1543642,1.4046371,1.8037037,1.4189373,1.4955668,1.4886637,1.109131,1.4181381,1.5512052,.98014297,1.5120601,1.2609024,1.3139663,1.4515051,1.6801646,1.3726141,1.8723222,1.5998268,2.3024936,2.1112624,2.5997268,2.1680394,2.1572821,1.7299494,2.747826,2.2331623,2.3375018,1.6993166,2.1272967,2.4238072,1.9369145,1.7835651,1.8600808,1.700759,2.0623853,1.7302959,1.6322612,2.1551828,1.7826019,2.2375474,2.1145817,2.3048437,1.9998658,1.7866584,1.3621175,1.6107703,1.8981502,1.8615933,1.5854527,1.7139005,1.4988466,1.7344541,1.2542622,2.0428705,1.5765679,1.5347404,2.3721283,1.8007967,1.45334,1.62937,2.1091977,1.6265674,2.0608064,2.0460502,1.9422756,1.7060555,1.8609178,1.9771171,2.2449454,2.4012673,2.1314498,1.6640012,2.1211634,2.1399437,2.2886097,2.4201544,2.0182026,1.7541029,2.1445411,1.7085882,1.8812964,1.8662716,1.6281113,2.0641524,1.7977273,1.7412378,1.186685,1.3722729,1.5900902,1.2592395,1.4960771,1.445406,1.3924462,1.5080094,1.4398482,1.7253682,1.5418885,2.0553236,1.8113401,2.1951563,1.8035779,2.2288797,2.1038527,1.8384735,2.4821069,2.3219637,1.8415634,2.1968535,1.9975513,2.2521239,1.5390849,1.7606167,2.2121964,2.1697868,1.9602222,1.9059157,2.3069714,1.9478026,1.8667029,1.4986946,2.5676031,1.666288,1.8131773,1.9887553,2.0867931,2.6275939,2.2669632,1.8108865,2.0223422,1.5946431,1.9891064,1.4660185,1.7499676,1.8063468,1.5866347,1.6483613,2.0853781,2.1786791,1.8920358,1.855485,2.2199609,2.0670894,1.5739795,1.6386028,2.0758797,1.7777706,2.5551276,2.1775251,1.8270255,2.2081997,2.2280135,1.7901753,2.0485942,2.1285759,1.7429559,2.1723832,1.9713098,2.4371206,3.1621103,1.8153116,2.0342798,1.6099036,2.5080099,2.0024782,1.4630344,1.3921135,1.6487539,1.150136,1.3265862,1.6617193,1.3560241,.9635006,1.5488801,1.717694,1.3589154,1.5738609,1.6866387,1.694184,2.0887199,1.7775249,1.8401456,2.1639192,2.2667839,2.2220107,2.3617477,2.2893369,1.911468,1.9301181,2.7194445,2.0549137,1.8989069,2.4435376,2.0833026,1.9042328,1.5199393,2.0827152,1.5646561,1.8515286,1.6402446,1.6788955,2.2600775,2.036186,2.3015187,2.5470493,1.9202701,2.0515152,1.9501422,1.9348411,1.4258656,1.5235425,1.2739153,1.1003172,1.5356543,1.7067769,1.4537106,1.9829513,1.4658087,1.3233433,1.6140262,1.8096622,1.8792628,1.9525516,1.7605103,1.777209,1.4840584,1.5020231,1.6423392,2.4509537,2.1417676,2.0904689,1.7093996,2.0649807,2.4487386,2.0149022,2.0265372,2.378787,2.0621637,1.8725509,1.9168712,1.9864029,2.1747451,2.3404017,1.9249811,2.1432794,1.5967608,1.427104,1.2752407,1.0821453,1.3172125,1.1161174,1.3744274,1.589317,1.2648489,1.9120596,1.7421771,1.8024597,1.6181186,2.082684,1.6464282,1.9906183,1.9398746,2.7860802,1.6440761,2.3002995,2.0444746,2.6238451,1.4796471,2.1687299,2.3942628,2.5492927,1.4822847,2.2432685,1.8026255,2.4541595,1.690559,1.6916939,1.7312464,1.9975241,1.8360942,1.9203694,1.7258471,1.6550545,1.9404048,1.5680278,2.3295684,1.9311543,1.7223234,2.1371627,2.209418,2.1406123,1.6520289,1.9557166,1.4806218,1.2748748,1.5528585,2.2967126,1.4485314,1.7751319,1.6767038,1.7065835,1.8669224,2.0928929,1.4316223,1.3591718,1.4569057,1.7022805,1.9991672,1.943906,1.9021255,2.1962119,2.0691005,2.3358303,2.3733606,2.2405565,2.3444749,1.9317766,2.2105853,2.4278401,2.2477531,2.1392544,2.0858019,1.919679,2.2372282,2.1790176,1.7989086,1.697079,2.2141439,1.2199302,1.6621833,1.5258387,1.6204141,1.7047009,1.1475579,1.4016421,1.4257828,1.7798818,1.7647437,1.6891118,2.1559824,2.6803148,1.7490262,1.8216787,2.1385188,3.1828935,2.1445446,2.1402807,2.4344089,2.0976946,2.3855514,2.4192591,1.9638012,3.4296965,2.2181325,1.9187192,1.9156968,2.0010099,2.5055484,1.8282979,2.1422122,1.9891253,2.5418293,1.8165416,2.1135667,2.2239178,2.1720424,2.281256,1.7872628,1.9292377,1.8726749,2.411853,1.4428875,1.8689599,2.0699108,1.4724327,1.1648855,1.7898585,1.6696796,1.5257173,1.7457196,1.55345,2.0584473,1.7119168,2.080426,2.1235502,2.0454498,1.9216182,1.836803,1.7591695,2.3250603,2.0341132,1.9347802,2.3621773,2.1165671,2.5321812,2.3021188,1.9192056,2.1888573,2.0055395,1.9438353,2.6722729,2.2038845,2.4788169,2.5334777,2.8191994,2.1659872,2.2552939,2.2188354,2.033484,1.7510865,1.6545647,1.3848707,2.2269795,1.8365123,1.896057,1.3111991,1.5356641,1.7464184,1.9756153,1.741086,1.8118577,2.6279301,2.9741027,2.8293177,2.1791196,3.3631801,2.4370861,2.8523719,2.5107038,1.9608018,1.8589908,3.0585591,1.9928571,1.7590304,2.2209178,1.7866462,2.0750702,1.6195619,2.4172739,2.4689555,2.2470296,1.8764299,2.0697265,2.3885711,2.2596874,1.4989627,1.8380605,1.7486996,1.8754964,1.841658,1.7227006,1.6077899,1.5281837,2.1918319,2.015833,1.755589,1.4220975,1.0626261,1.7837637,2.3005332,1.8938708,1.8940734,2.1810068,1.7514677,1.5933059,1.8906492,2.0655648,1.5660421,2.3578016,2.3465774,2.0251159,2.1988303,2.2061295,2.9528427,1.9351881,2.1850452,2.4060322,2.8939109,2.1030341,2.5618035,2.3749976,2.2276088,3.2061878,2.442885,2.7919725,3.4230152,1.9974057,1.5450538,2.9474237,3.3334954,2.2293925,1.7585186,1.8382322,1.6370776,1.3873455,1.2752018,1.7779439,1.9677266,2.1707617,1.8827576,1.9711621,2.2161963,2.2273938,2.5782575,2.5090481,3.5086867,3.0378798,3.1581745,2.5105761,2.8783539,1.9834471,2.444037,2.5608947,2.3061983,2.417654,2.3449189,2.0240786,1.8838864,2.3217362,2.3870858,2.6258438,2.6383181,2.3952262,2.741563,2.4590861,1.9852029,1.5471138,1.7465702,1.6394023,2.2998458,1.8832322,3.0936222,2.1275746,1.844841,2.5894287,1.7121675,1.0873471,.9597012,1.0680838,1.5501898,1.4853986,1.2590668,1.7669554,1.7058274,2.6452054,2.3665054,1.8311615,2.2413756,2.1054813,1.6662598,1.8722419,1.742039,2.0366717,2.0200095,2.377686,2.7743702,2.5203395,2.5154162,2.5742551,2.8723272,2.4960954,2.6179972,2.1023842,2.9382743,2.4420256,2.8464432,2.9420979,2.7317914,2.3346609,2.0609107,2.9819565,2.0090961,2.1298859,1.3841104,2.074271,1.731858,1.8439934,1.7475616,1.7886092,2.0780083,1.8436749,2.4918928,2.7544019,2.4839501,1.9692245,2.9576478,3.124483,2.378462,2.7013245,3.0343746,1.9940908,2.8425862,2.4075789,3.4888004,2.7485761,2.3640521,2.3280131,3.2404513,2.4185709,1.6037517,1.9763805,2.4490207,1.6783794,1.7069089,1.7816318,2.7421833,2.0077337,2.1641975,2.6074255,1.4520996,1.9971335,1.589016,1.5288566,2.2849562,1.916112,1.7852681,1.6932169,1.5644811,1.8461885,1.4740217,1.5353087,1.4435496,1.667283,1.4184303,1.5150715,1.5997691,2.4286995,2.2960023,1.4996206,2.2123563,2.571866,2.2840284,2.1849291,2.28903,1.8801851,2.4869987,1.5263324,2.4249944,2.6473655,2.2659979,2.6208782,1.6519463,1.7516078,2.6741596,2.7859941,2.5028466,2.0301106,1.8780133,2.5860232,1.9797314,2.9591883,2.2598864,2.2896379,1.8335645,1.8970387,1.3879799,1.6356119,1.5539179,2.0317942,1.9211543,2.0655289,2.0138479,2.3520605,2.4659114,2.3941466,2.3148675,2.6733819,2.508712,2.7401113,2.6391292,3.154632,3.0573719,2.6623727,2.3921411,1.9751008,2.1905461,2.3488614,2.2661984,2.0918858,2.7353344,2.4242662,2.3788889,2.1835833,1.835015,2.1033608,1.9246432,1.9446678,2.0967985,2.1031367,1.8713073,1.7439494,1.5330889,2.2915008,1.6671249,1.4994063,1.4706023,1.4989097,1.8731205,.84773652,1.0611147,1.3593184,1.3348391,1.5541516,2.0593954,1.7921462,2.4617001,1.4675667,1.5795162,2.1088454,1.865124,1.9729475,1.5304767,1.7607666,1.7153861,1.9726072,2.3555012,2.1485626,2.1297021,2.6277326,2.1135982,2.0915791,2.0864236,2.5632355,2.2148316,2.1824093,2.3124868,1.7737303,2.9306318,2.1743802,2.8885327,2.3316538,3.1168857,2.7765628,1.9287301,2.4258611,2.0465354,1.8802128,2.000909,2.3080008,2.0863801,1.9581656,2.4920112,1.8596017,2.5916332,2.8331679,3.0560084,2.877613,3.4440431,2.8817694,3.0966025,3.0537488,3.7618863,3.4335838,3.1653225,2.6342327,2.7377056,2.4026667,2.8696677,2.354813,2.3838334,2.6835464,1.8595803,1.4514915,2.2350414,1.9650879,2.7664911,1.9905527,1.2666729,1.9680398,1.5914933,1.8435444,1.8932994,1.7493175,1.6015962,1.6973333,1.7894987,1.7761613,1.7140721,1.8598816,1.2630901,1.2136591,1.1445975,2.04163,1.5336287,2.4661758,1.5143799,1.9747417,2.1871939,1.7786471,2.0404474,1.9412317,2.7339813,2.1882374,1.4554871,2.1971275,1.9671433,1.9489456,1.8099708,1.7965716,2.4031256,2.1912059,2.3972898,2.5408939,3.1349214,1.9814435,2.3620222,1.8185854,2.4183876,3.0843814,3.2342489,2.2808942,2.616829,2.3899506,2.4697832,2.3815759,1.9734426,2.1642553,2.1531487,2.1698642,2.0108869,1.7368162,2.0135599,2.5462553,2.5028847,2.5344925,2.4045236,2.9224721,2.3833379,3.2440807,2.4146364,2.9347184,2.4499489,2.6315466,2.5569228,3.0943671,2.4861166,3.1434749,3.0162861,2.3572044,2.172593,2.5004521,2.3911892,2.1301252,2.4301905,2.42793,2.2900369,2.0378527,1.8995397,2.3042441,2.3535152,1.9172648,1.4450711,2.1047915,1.5364107,2.5918446,1.9165941,2.0392799,1.5782427,1.6639782,1.5317094,1.643587,1.1175138,1.507933,1.5043575,1.6712869,1.5043591,1.5370548,1.7843644,1.9397588,2.0612905,2.0445956,1.9190101,2.0661538,2.2679805,1.9570542,1.6407511,1.7936704,2.020946,2.1045915,1.8976704,1.9395738,2.9360897,2.4612322,3.4064635,2.0272479,2.683631,2.305027,3.2658061,2.7684165,2.4735025,2.653852,2.4986542,2.3715001,2.6074464,3.311486,3.4469258,3.6014324,2.7895176,2.130839,2.8020695,2.0037273,1.8256267,2.1493285,2.7084837,2.3403278,2.6811487,2.3698593,2.8263404,2.9109505,3.8771676,2.7993633,2.2481354,3.2821948,2.978187,3.2099335,3.2599431,3.5726807,2.8264471,2.3365349,2.1403411,1.9695896,2.0970815,2.7356191,1.8963325,2.1022634,2.7445048,1.8721117,1.9801716,1.599216,2.3041738,1.8792593,1.4747684,2.1888333,2.4790958,2.1507264,1.863112,2.0666211,1.9978507,1.605062,1.4232421,1.2327922,1.1800311,1.4001844,1.0665592,1.6500993,1.6842617,2.7907296,1.5044087,1.3030804,2.0881718,2.1854146,1.7404497,2.2260219,1.7009805,1.8081162,2.1313642,1.7911023,2.2802655,1.8717105,2.3168036,2.9885858,2.4661196,1.9700915,2.4814966,2.8105738,2.9273212,2.7140949,3.360417,2.4397391,2.8983077,2.598895,2.7227676,3.5910973,2.8929164,2.708292,3.7042207,2.6721962,2.6271298,2.6236689,2.2994531,1.8467222,2.0523061,2.4897062,2.058532,2.7792926,3.729212,2.5832676,3.2394511,3.5441683,2.8361609,3.5454153,2.9619168,2.7300537,3.1952096,3.0142051,3.1137576,2.4495988,2.9029301,2.6832959,2.4333367,3.5439673,2.6470999,3.01574,2.5726837,1.9601275,2.0288181,1.8987811,2.1415597,1.6578427,1.5348636,1.7424476,1.6857441,1.8149128,1.7694327,1.8060193,2.124638,2.1436623,1.2085687,1.5681836,1.1676068,1.2068787,1.5134001,1.3699585,1.8168436,1.998418,1.4182461,1.3736205,1.0766686,2.3354895,1.7255246,1.5936624,2.0097943,1.1081989,1.7049025,1.8121871,1.6545462,1.9137091,1.7064872,1.6758733,1.6718639,1.732117,2.1372224,2.3591479,2.073107,1.8190087,2.7451348,2.5845399,2.6583272,2.8643913,3.132109,2.9711634,2.5742807,3.389419,3.3284998,3.5789808,2.7603816,3.1299594,2.2631898,2.8798282,2.2956784,2.9142621,1.7280724,4.1251128,2.2754297,2.7754543,3.6148421,2.865413,4.9767799,3.2202068,2.6132365,3.8040087,3.9119489,3.7616924,3.1551533,3.6539951,3.0018449,2.2459401,3.5033318,3.7510811,2.2952443,3.1656711,3.0389512,2.5131781,2.6598408,2.3247605,2.7127605,1.9406629,2.0774982,2.4853882,1.6424382,1.985548,2.2220769,1.4932767,1.7042456,1.9382821,1.6457722,2.1506498,1.6867559,1.9208491,1.2502171,1.7172333,1.5370917,1.28841,1.2931266,1.4535656,1.8788757,1.4579123,1.8008683,1.405515,2.0078792,1.6222105,1.4693958,1.8374059,1.6966655,2.0028594,2.0647571,1.9387442,2.4313784,1.6394709,2.2546965,1.5815291,2.5434306,2.4142652,2.3663972,2.6853704,3.7958601,2.5025552,3.0636508,2.8942133,3.0111135,3.1125328,3.7685764,3.0946191,4.0056906,3.9557224,3.3072263,2.6786686,3.0158187,3.0447841,2.8024415,2.9651038,2.2437694,2.3913493,2.7048347,2.8948834,2.577219,3.2360552,2.3990456,3.9684262,4.2343755,3.2581197,3.4478388,3.6952486,3.5913706,4.3569632,4.3904522,2.7765547,3.050732,2.4172828,3.014684,3.1966686,2.2420585,1.723845,2.5894907,2.4161666,3.0127936,2.2793604,2.1593108,2.4239686,1.9160064,2.2883748,1.8017213,2.2219406,1.6159705,1.385913,1.7556351,1.91337,1.6317844,1.3083323,2.1891356,1.4442812,1.6105022,1.5223145,1.2802658,1.2517934,1.2300549,1.1872779,1.8575006,1.5746817,1.7168809,1.689625,1.3059182,2.0373796,1.3761098,2.2864995,1.6095824,1.7707206,2.1673666,1.677239,1.6269298,1.371324,1.8948158,1.9223916,1.6284076,2.0164306,2.6435016,2.8603867,2.7866058,2.993722,2.7070987,3.0300792,3.0215461,3.5677586,3.7576367,4.2955538,4.7854177,4.7384028,3.5234824,3.5773201,3.5413396,3.6919731,3.5312558,2.5632352,3.3124276,3.8604908,3.5925841,3.045456,3.8919472,3.2971828,4.0063009,5.129414,3.610524,3.2450435,4.124865,3.5953797,3.7410963,3.6999848,2.9869691,3.207284,3.0566074,3.1103515,2.2645934,3.3397644,2.0847617,2.0706245,2.6997188,2.9521832,2.7454147,2.3295998,1.9382542,1.7664727,1.6725484,1.9799995,1.780614,1.7501393,1.8444428,1.8318856,1.4556676,1.6188775,1.4598914,1.3528814,1.5034556,1.5760472,1.1894987,1.3668214,1.0398148,1.3083914,1.8121303,1.3933668,1.6920908,1.4861731,1.3390595,1.6564047,1.5533882,1.4901351,2.0062735,2.0393728,1.85489,2.334753,1.8174102,1.8272169,2.1434544,1.9712624,2.0089582,2.1538483,2.4954261,2.076965,2.5231724,3.2008859,3.0180496,2.4303772,3.9350914,4.7936619,4.4851031,4.3864779,4.1873865,4.7117079,3.4873105,3.338599,3.675901,3.6625195,4.7887671,4.7546437,4.8259535,4.0145819,3.7967184,3.5047375,2.9537924,3.5322653,4.7327991,3.2101946,3.5855938,3.4134834,4.375955,3.8261034,3.8003719,4.3291194,3.5027538,3.545166,2.9412903,3.122977,2.7814963,3.4288057,2.5830213,2.4882665,2.0489115,1.9691644,2.2423129,2.6557065,2.0255453,1.9602668,2.2185618,1.9440829,1.6635506,1.7037979,1.5194411,1.6671169,1.839227,1.9920417,2.146604,1.4328095,1.3376046,1.0219204,1.2697091,1.1980333,1.382578,1.5333332,1.0467392,1.4762574,1.7664875,1.5067465,1.4901796,1.1320144,1.3850264,1.6275181,1.3635753,1.9243296,2.4010283,2.1901471,1.902966,1.6169846,1.9272755,2.2254085,1.4398554,1.7834952,1.8127481,3.1923923,2.2221505,2.395574,2.6084508,2.6251598,2.659356,3.8372583,4.7379796,3.1177434,4.7310622,4.0381666,4.4662097,4.6367739,4.4490116,4.7195519,4.47367,3.3099278,4.2069043,3.4734315,3.7296739,3.317292,3.3562506,3.8544498,3.3332616,3.6711749,4.2606824,4.2705276,5.3481276,4.5017101,3.9678005,2.8825461,4.0887869,3.8823254,3.6463755,2.8509382,2.156067,2.861794,2.5738251,2.1857869,2.1113936,2.0520813,2.5139221,2.4069496,2.0412984,1.8407547,2.0368029,1.7522393,2.5458021,1.7917612,1.5928436,1.8125855,1.92771,1.951082,2.1147993,1.4465088,1.1649836,1.0723909,1.3944544,1.2648929,1.0367455,1.2939168,1.1605523,1.9826791,1.3141531,1.4763536,1.2599568,1.5236662,1.0302163,1.8949487,.95641878,1.4530104,1.4983509,1.6488842,1.8724375,1.9411358,2.0049026,1.6101378,2.5154808,1.7858674,2.0337548,1.5183801,2.5665422,2.3885602,2.7843211,2.4750105,2.4880578,3.3454771,2.8206486,4.5317571,4.5777677,4.5535278,5.6760094,3.9250027,3.855238,3.6597696,3.6366056,5.1124704,5.4561128,4.5628447,4.3099262,5.1536931,4.1278648,4.1900256,4.6888478,5.6410042,4.6918477,4.9784349,4.5843779,3.9511516,4.4963325,3.8125403,3.4192813,4.2798454,3.5200599,3.3800548,2.2646504,2.7063071,3.3679913,2.3939184,2.1302555,2.7457276,1.9146363,2.9676366,2.0460593,2.1817708,2.0659544,1.9628077,2.4506123,1.2955903,1.5141425,1.5354109,1.5558811,1.9343412,1.1280586,2.400217,1.4582334,1.2080096,1.3639018,1.4379602,1.1678428,1.1708367,1.0142831,.88658781,1.2147708,.83171549,1.4243756,.99632948,1.3927401,1.2098711,1.3683022,1.5887478,1.8515444,1.4887349,1.6284766,1.522014,2.5169671,2.2193388,1.9842871,1.73436,1.5816048,1.8081841,2.5622246,2.5824511,2.2984295,3.6835077,2.9552147,2.9229448,3.1924919,3.8515199,4.1596597,4.4238811,4.0570362,4.9090571,4.2057573,4.1203513,5.0363886,4.9726336,5.8287791,5.0464087,5.0796467,4.8558959,4.7159103,5.2523269,4.1417234,4.0504064,5.2855977,4.8883579,4.6750632,5.4041387,4.4531092,4.8712571,3.439518,3.8418831,4.3325905,3.8839924,3.3020336,2.8541915,2.5439954,1.9339814,2.3899419,2.2366834,2.1343663,1.9626223,2.8720408,2.4892183,1.6462017,1.8279137,1.4910623,1.7841354,1.6902265,2.1710176,1.9406437,1.8164165,1.8629957,1.1772609,1.7022291,1.5563119,1.5121379,1.1611844,1.0784902,1.1945201,1.3401182,1.0227255,.91870703,.69902243,.93505169,1.249555,1.3187975,1.4017388,1.1471292,1.5620297,1.1136337,1.3724252,1.3694458,1.486476,2.2658051,1.9016314,1.9449517,1.6133091,1.5025035,1.5756496,1.293241,2.1770087,1.985043,1.5221771,2.5530317,2.6602267,3.1603516,3.2805304,3.2320571,3.8136338,3.598314,4.1158222,4.3517747,5.2726623,4.449591,4.6877331,5.0552796,7.6376431,5.7688743,5.3920622,4.405773,5.2093036,5.3988757,4.5037587,4.2939611,4.9778987,4.9934081,5.9954029,6.8449093,5.8874853,3.594219,4.9654507,3.7705154,3.0296754,4.0175864,4.1566879,2.5771871,1.6208774,2.3194752,2.056328,3.2823769,2.1624751,2.0730038,1.8853799,2.4766658,1.4783197,1.7966075,1.7353132,1.1804326,2.0887466,1.7911358,1.7116954,1.7731517,1.1881084,1.1465629,1.2985232,1.7883936,1.4758644,1.6311629,1.1856965,1.5503265,1.1902838,1.4680221,.93936759,2.1819741,1.0452443,1.081639,.98588941,1.6687542,1.8950473,1.6082503,2.0141212,1.5828979,2.030912,1.7103023,1.8375261,1.997867,1.9304289,1.4031479,2.0373666,1.4408079,2.3805595,1.8877224,2.6657172,1.7046202,2.4438278,2.6572743,3.7485709,2.998767,3.7272773,4.0771891,3.7416114,5.1544166,5.7962799,4.8729123,6.2250895,5.8529083,5.1170855,4.4838542,6.1740429,6.3446712,5.5777346,7.5883693,6.0084497,6.0037378,5.7222162,6.953672,5.3388184,6.601292,5.6382986,5.053867,4.9388514,4.9793267,4.2494004,3.9979679,3.5417235,3.4729861,3.6950257,3.1979481,2.8489374,1.8864165,1.6382342,1.9983393,1.7934712,1.8529009,2.0158432,1.9255699,1.6465309,2.236531,2.3884942,1.6635606,1.2697442,1.8588695,1.6962479,1.2797987,1.2873402,1.8430985,1.557673,1.5626404,1.4773328,1.3737529,1.6031159,1.3270658,1.6752371,.9631958,1.9450491,.75601909,1.2316898,1.0962134,1.6320112,.89303027,.92580677,1.2787514,1.5398601,1.3842735,1.461231,1.4276838,1.6124353,2.0299565,1.390276,1.474512,1.8441606,2.3019577,1.7606998,1.8035652,2.3621006,2.3613996,2.3748265,2.6947781,4.0646565,2.7655903,4.0733504,3.8280017,4.3554207,5.8668263,5.2206708,5.2916541,6.7909558,8.7678245,6.9966154,7.6896896,6.9543095,7.4726889,8.1369461,7.3814816,6.2353457,8.1974732,7.4708378,8.6562021,5.6600917,6.9976387,5.3921415,6.1871008,3.6147088,3.7446405,4.7130737,3.8077104,3.2230597,2.6746986,2.7167404,2.2441653,2.5090717,2.6670628,2.2686997,1.6568597,1.4912022,1.9954857,1.6354763,1.7884402,1.8194752,1.7213223,1.6089183,1.324807,2.0416705,1.6711146,1.6547874,.98304491,1.5041095,1.1154811,1.1771727,1.1181043,.67407854,.98273326,1.2763546,1.0858834,.83479053,.8620052,.71017311,1.1223944,1.0736545,.84949224,.86599775,1.2828718,1.363637,1.2262795,1.929887,1.1459183,1.8528945,1.7467838,1.8108344,1.7997451,1.624893,1.5158485,1.7510842,1.7344654,1.9420552,1.9386737,2.5776864,2.4866917,2.6319333,2.4862084,2.8631375,2.8682349,4.5699805,3.8722139,3.7367356,4.7107852,5.1701591,6.7694542,5.314395,8.1010528,7.5467849,8.9812344,8.5654799,9.852546,9.0323052,11.22444,9.2886849,7.6617184,7.3297105,6.0165246,8.2632385,6.8463011,5.2758195,5.7479378,4.98743,5.0808259,3.9582355,3.2255589,3.4592222,2.4468584,2.9930111,2.565188,2.2431314,2.0832688,1.960565,1.5968613,1.739569,1.6691954,1.3448581,1.6851168,1.6684179,1.5116516,1.3882162,1.3707462,1.3695522,1.1266699,1.034621,1.098882,1.1884045,1.2586189,.99404925,1.6888062,.92456151,1.1186296,.99775294,.75894276,1.3054393,1.0196258,.752827,1.3919657,1.1280418,.58824454,1.1757509,1.0221197,1.0810679,1.3107237,1.6469614,1.0362125,1.4353333,1.9097856,1.5179423,1.7408258,1.6059566,1.5684582,1.935901,1.6074322,2.1036397,1.8052208,2.2043551,2.2824924,2.4740781,2.6475944,4.0204946,3.5989155,3.4141997,4.7683135,5.0872981,5.7970513,6.3387116,6.9354658,7.9808606,8.4783167,9.9666705,9.5630293,13.79886,12.205793,9.6729567,9.0208349,9.2396908,7.5604439,7.6130466,7.8385888,7.4384517,5.3806669,4.3649046,4.6088013,4.2904471,3.6988634,2.6181711,2.1279866,2.7373655,1.9191327,1.968672,2.303219,1.4792483,1.8161898,1.6491994,1.5635515,1.6463416,1.2916201,1.4920273,1.4965931,.94890156,1.2993708,1.3406037,1.8027637,1.1332485,.9630116,.95008291,1.3539373,1.1455458,1.1240217,1.207962,.88299235,1.3345489,.71238207,.95464436,.84181078,1.003284,.96968842,.79723302,1.2081566,1.199488,1.0889573,1.0034902,1.1304194,1.7564535,.9792078,1.5730508,1.4769968,1.2461155,1.5100211,1.0510706,1.5399687,1.4020352,1.57174,1.6640445,2.3422653,2.1025939,1.9102712,2.4817942,2.4707303,2.6335492,4.3833438,3.6158162,5.4283955,4.5796948,6.2939373,5.2626466,6.4848017,9.0644175,9.6781411,10.655354,13.401246,15.841601,16.018899,15.061532,13.163563,12.95226,14.208965,10.353561,11.736353,8.0240178,6.753305,5.4493259,5.0176106,4.473543,3.7235483,4.0733146,2.5261747,2.6209576,3.3965924,3.6104341,2.1090472,2.181949,1.6180294,1.8530485,2.1704144,1.6559144,1.3141246,1.2461374,1.2925142,1.1735058,1.3577158,1.3047445,1.1086048,1.5023414,1.1048581,1.2830739,1.1096668,1.1543121,.62658817,1.0652159,.98337505,.85797858,1.0960474,.76142008,.59253495,.69869567,1.4661653,.83555817,1.049369,1.2534595,.68768647,1.667187,.83564363,1.1164699,1.299768,1.095813,1.2933011,1.3999265,1.4468438,1.8203555,1.9115788,1.4672908,1.424583,1.8521956,1.9130666,1.7467969,2.7951083,1.9198271,2.8092403,2.0822023,2.2546502,2.95525,3.1880403,4.0909676,5.3895008,3.8863863,6.7548222,6.1508506,8.3680729,8.0995096,10.264562,11.32088,15.950325,16.792941,18.016149,17.520703,14.619817,9.0611419,9.1329914,10.9519,7.9011934,6.0331496,5.449525,4.645258,3.2877972,4.9243239,2.9801781,2.3117919,2.1817439,1.9715737,2.0227721,2.6170184,1.9648643,1.4901347,1.4379608,1.7675474,.99850407,1.4476955,.94160819,1.6582148,1.2756171,1.577902,1.0083684,1.2363335,1.4494957,.88718345,1.1806623,1.0050259,.97200752,.91137065,1.1021581,1.0321627,1.0177052,.63500056,.99096126,.92871007,.7140504,.90375952,.90068937,.65678462,1.117746,.44322987,.55319402,.98422841,.77826291,1.1531126,.59637652,1.2721316,1.1957872,1.4538003,1.14404,.98870629,1.5346895,1.6328783,1.456585,1.8107548,1.9596894,1.7511843,1.9540626,1.9516638,2.0180559,2.1215899,2.5211975,3.1906617,2.6783724,3.9869191,3.5457247,4.4638758,5.6459235,7.3622279,7.7269484,9.8125826,14.056056,13.502428,19.224289,21.339681,20.591881,15.987653,12.405964,9.231152,9.2275523,6.6619596,8.4638326,4.4605672,4.972979,2.8499197,3.2814427,3.0298239,2.6593904,1.8402116,2.0653079,2.1060606,2.0288377,2.1224409,.9921361,1.6526505,1.5999173,1.4276278,1.522673,1.5710474,1.2072759,1.5018304,1.1805758,1.3615719,.85291633,1.4303543,1.2825711,1.1771729,1.2842883,1.3056324,1.2175879,1.6235643,.98095112,.83101638,.953051,1.1463265,1.1340093,.75389872,1.1027307,.69831981,.98737164,.9199895,.7870589,.75128035,1.0270138,.9255541,.8162165,1.0755713,.82168275,1.0214578,1.2003228,1.1731254,1.2484251,.88332533,1.4304415,1.8154059,2.0565234,1.4911914,1.9863533,2.3525368,2.0414625,1.8522317,2.6052663,2.6847397,4.2966719,4.1645265,5.9892872,5.1301221,4.4044322,6.3648372,7.6926131,10.59074,6.8364315,10.083302,14.496944,18.295495,20.431812,17.610725,12.80801,11.754487,10.495823,8.8910907,7.2010715,5.6948574,4.4253106,3.9593099,3.986018,3.9266684,3.201446,2.0318586,2.8195963,2.0914408,1.9675743,2.0150402,2.047683,1.609498,1.5973144,1.3605108,.89735547,1.3860323,1.0858624,1.2900101,1.036792,1.4210222,1.3647757,1.2881742,1.0526865,1.1306247,.80287775,1.0581702,.65657523,1.0056704,.73892003,.85235369,.92419687,.74123335,.65846467,.58406816,.63100953,.92732656,.95655309,.93780623,1.1505245,.70364515,1.1258869,1.3880789,1.0162793,1.7027043,1.248149,1.530804,1.2272664,1.1544653,1.189697,1.2755828,1.3939327,1.9191486,1.5387069,1.5223838,1.8827338,2.0462312,2.8354144,2.0829119,2.4557351,3.6146809,2.9670955,3.2483825,4.0327375,5.2639134,4.9489402,4.9398924,5.8499534,5.9303491,8.4705048,10.197802,9.937582,11.57343,14.76631,13.928308,9.9519783,13.821778,10.080608,8.9008063,6.7373678,7.7004234,6.5545356,6.6801225,4.7847453,3.7211702,3.8736077,2.6541578,3.0665873,2.5704872,2.5957144,2.1895976,2.6501393,1.9554863,1.7226996,1.5590126,1.6177919,1.6528067,1.2647088,1.1092626,1.1238858,1.0566087,1.0625932,1.2514495,1.1001806,1.0468272,1.1952926,.77777099,1.2968581,.98982556,1.001005,1.1289569,.94178757,.81464124,.98893969,1.3291995,.66320545,1.034357,.69678357,.87483459,1.2652661,.9149917,1.6137597,1.9295605,1.0311286,1.2243012,1.4347811,1.4514641,1.509402,1.154596,1.5117359,1.171381,1.1630478,1.6938533,2.2435947,2.3569135,2.2684442,2.4246132,2.0550869,2.5900396,2.3786289,2.2866906,2.8989143,3.1269506,4.5177257,4.4316397,4.4971275,4.614844,5.0727616,7.7225918,9.6205641,9.3677717,10.770792,10.014099,8.7015253,10.740593,12.137987,10.992495,10.286966,9.4481679,6.7812666,8.2731653,6.9293826,5.7153814,6.0839539,4.5474467,5.0328447,4.6284209,3.8476535,3.2069528,3.6248153,2.8829901,2.3845617,2.0370791,2.559851,1.662568,1.9144728,1.5038049,1.6529217,1.5317161,1.6462891,1.5771036,1.3141878,1.5135621,.95510022,1.1440472,1.0869848,1.4591477,.94117798,1.0826675,1.026368,1.1882169,1.0885895,1.0471571,1.1012322,1.3733882,1.0591351,.75160239,1.1715076,.92071129,1.3140545,.92131764,.90987126,1.2210068,1.410068,1.0018876,1.0601917,1.0989989,1.4892542,1.6886425,1.5619652,1.3237266,1.1883168,2.3249209,1.829506,2.5326082,1.639586,2.4307122,2.136748,2.2362998,2.4086673,2.883778,2.2271043,2.9022502,3.8726349,3.7269533,4.3961694,4.1255638,4.8740833,6.1311143,6.1019658,8.5724714,8.9902332,8.1730783,12.893334,8.7928745,10.56547,7.6053738,9.4203749,9.1894878,7.6670062,7.729865,7.0833352,6.1837555,5.9978587,5.0421057,5.1403509,3.7752856,3.841658,3.1466767,3.5637813,3.1790539,2.5468451,2.6650713,1.9014054,1.9008585,1.6198272,1.7246871,1.7469185,1.6976874,1.4211893,1.254067,1.8365036,1.8369018,1.3031921,1.1164167,1.4581682,1.4583367,1.1296686,1.3744254,1.2720617,.8183568,1.4691987,1.1139096,1.2698689,1.1946276,1.0948523,.86988455,.55540603,.97045695,1.3535963,1.6044879,1.1638904,1.0218608,1.315082,1.1703963,1.0864504,1.3172711,1.0992519,1.4566844,1.730561,1.4497887,1.7634137,2.2969008,1.7556347,1.4588144,3.0275041,2.257662,1.9793597,3.0099401,2.4989728,2.9703857,2.6732384,2.7774799,3.5553025,3.6454743,2.9703694,4.2111383,6.1584403,4.5072754,5.3874264,7.0173371,6.0255097,7.8525511,7.11173,7.368685,10.298407,8.8905586,7.4006148,7.4094261,7.0870743,7.0820625,6.7393905,6.5034219,6.30174,6.2798687,5.5967257,4.8584564,4.5929891,4.6427728,3.9629064,3.4110447,2.8441571,2.6372692,2.7859012,2.2659549,2.6669763,2.6650562,1.6029533,1.9121502,2.0735004,1.6085723,1.5280864,1.3044483,1.7499055,1.7340051,1.3213128,.89174521,1.4418085,1.8753594,1.1954195,1.5715681,.98230147,1.592071,1.0392763,1.1138062,1.013912,1.3123119,1.132181,.90150896,.64127881,1.2485226,1.2217093,.89739577,1.0688099,1.2452777,1.1061568,.89245341,1.4142161,1.2312145,1.6602783,2.2439835,2.0197548,3.0076526,1.7022754,1.6608604,1.4057535,2.1579805,2.1062732,2.3910521,3.6396713,2.7089965,2.7797915,2.7616356,2.9092233,3.3013477,4.711775,3.6147806,3.9829118,4.6137048,4.8233653,5.4457904,5.11974,6.5454554,8.2890849,7.5042849,7.9154763,9.1059387,6.027027,7.7309978,7.2754935,9.3251783,6.193075,9.4307111,5.6047658,5.4321268,5.7910801,4.8137791,4.8810626,5.0989429,4.3522941,4.5421536,4.2594707,3.4215506,2.9241442,2.8285679,2.885734,2.498858,1.7186351,2.0859601,2.2665258,1.7834567,1.833001,1.5191323,1.5871705,1.5056875,1.1870489,1.2785009,1.5839096,1.4281477,1.1756194,1.3619773,1.3710536,1.9489844,1.6666506,1.1265621,1.1469502,1.0816155,1.4094488,1.143862,1.0661688,1.4364715,.98920554,1.0122507,1.2802591,1.1626293,1.3623621,1.1979016,1.6706617,1.7768027,1.6947789,1.6282181,1.5165967,2.4508611,1.7073765,2.2612405,2.4158931,2.179953,1.5405181,2.1377916,1.9401465,2.3867058,2.653755,2.8791968,2.5198053,3.0758742,3.7987595,4.0462692,4.3443338,4.1832645,5.3445688,4.926408,4.1386385,5.2045773,7.3544532,5.3940835,5.8139209,6.2604339,5.3366505,6.0039899,5.5589914,5.7508845,7.9435707,5.381047,6.0506871,7.2419183,5.4021352,4.7425014,4.4924269,5.2325785,5.1584179,3.5698182,4.0839697,3.3529597,4.5567956,2.6281745,2.6462196,3.244384,3.0704994,1.8423863,1.7247907,2.1419393,2.0696601,1.9322215,1.3935289,1.701757,1.6357365,1.8881559,1.4191563,2.0608182,1.7005607,1.2262892,1.7879432,1.3092162,1.5826759,1.7790902,1.5890815,1.4621965,1.2637985,1.0361356,1.2777159,1.494658,1.0152783,1.3778887,2.0607769,1.4721226,1.327762,1.7413124,1.3418529,2.0153787,1.9088854,1.1922208,2.0748889,2.135076,2.1863029,2.4413956,2.1654914,2.152052,2.003447,3.2714111,2.6681573,3.8346589,2.8943436,3.4360009,3.6164964,3.3728418,3.0764882,4.0587227,4.7377244,4.7696073,3.7202944,6.1831724,4.6105104,6.5402813,6.5397218,5.3764513,5.2979768,5.9841891,4.916182,6.0157154,8.9873044,4.9937485,5.5021188,6.0384777,5.675832,3.8141607,5.1965377,5.6348883,5.6840188,5.4909133,4.1044368,5.3510056,4.5664877,3.1941371,3.2442297,4.7145166,2.7979688,4.0760644,3.6003988,2.5278743,2.3049942,2.1216812,1.8795905,2.514154,2.4823278,1.7484011,2.0632185,2.245399,2.0107559,1.7279313,1.9381344,1.6030511,1.4036084,1.3901809,1.4429003,1.3340299,1.7413163,1.4617838,.931749,.99622752,1.0968561,1.5857075,1.0591468,1.2529467,.93357442,1.7589628,1.9294929,1.9109628,1.4388009,2.469461,1.716117,1.319304,1.804743,1.9634992,1.4598129,2.3654507,2.0358845,2.2949711,2.1197086,1.7697538,2.5145803,3.0387518,2.8874326,2.8165808,3.1880517,3.5502187,3.2888024,2.8916388,3.3029054,3.5074532,4.0190297,4.3810369,5.0699843,5.5399616,4.0271416,5.1536515,5.4926697,5.3532598,3.836454,5.6830048,5.1862,5.610442,4.6911191,4.0825372,4.7418306,4.557493,4.1959809,4.328106,5.4963074,3.5958698,4.5573997,3.3458881,3.9779576,4.784597,3.8416837,3.4138559,3.7521005,3.340189,2.6383384,3.1617565,2.2464167,2.3202964,1.9866038,3.1380019,2.1841415,2.2639169,2.4981935,1.808173,2.1891225,1.7799002,1.4197194,1.0300785,2.2598547,2.1541742,1.3596296,1.5933393,1.5951283,1.8588909,1.3965805,1.6185889,1.3920673,1.1790391,1.2892085,1.4628188,1.7019949,1.5659381,1.2942994,1.1747315,1.4874732,1.2444547,1.8094872,1.9536032,1.7267763,2.6807163,1.7662428,1.9714902,2.2873568,2.2875033,2.5530436,2.8669608,2.2279737,2.5334926,3.464253,2.5541002,3.3645093,3.6095086,3.6605226,2.9647202,2.0583841,4.4272152,4.6831138,4.0722735,4.7274788,3.9042529,3.5296419,4.4661266,4.8742675,5.3134991,5.4719119,3.6912368,3.8577823,3.5858859,4.3742478,4.3774809,4.4483305,4.2608502,4.2577148,5.0515878,4.1577782,5.5145183,4.2636796,5.3898315,3.6217607,3.9597398,3.9234697,3.7695685,3.9990973,3.1366345,3.695261,3.0045131,3.5443615,3.0419259,2.1184506,2.6572979,2.491989,1.8965421,2.0777789,2.1289246,2.0297214,2.3356643,2.4140647,2.2226935,2.0494534,2.2208387,1.985285,2.5993448,1.6336565,1.6910867,2.5146588,1.38828,2.3560109,2.0339916,1.74432,1.2032908,.88855774,1.4248857,1.7072731,1.6166418,1.5251973,1.7566495,1.3472995,2.0343566,1.0499147,2.0559371,1.5724982,1.4017911,1.7671575,2.0533608,2.9289213,2.6180834,3.1129938,2.5329716,3.1764653,2.9147007,3.1261679,2.9155285,2.4475051,3.7113865,2.7866741,3.2128412,2.4920778,4.0971803,3.1038376,4.8636873,4.1163994,5.3549273,4.003646,2.9504411,4.9198775,5.0059228,3.756377,3.6725643,3.4951508,3.7608898,3.2098653,3.1241218,3.5929646,5.193655,3.8336057,4.1532421,3.7759529,5.1689857,5.0198565,4.6399284,4.2476448,4.3042535,3.943359,3.152322,4.4487803,3.5578826,2.7822488,2.4586348,3.9149059,2.7303518,2.701974,3.0352644,2.2323069,2.6129765,1.9426022,2.4412886,2.0830912,2.2901207,2.60352,1.9169948,1.7949664,2.5126233,2.138566,3.0234075,1.593032,1.4496833,1.7043515,2.3225084,1.8740255,1.5767574,1.5486101,1.0086569,.94526474,.98279077,2.3914427,1.3349233,1.662824,2.339585,1.7526785,1.5862078,1.8610395,2.3762897,2.0166726,1.6022628,3.1933354,2.8571055,2.5257729,2.2244317,2.1511868,2.124472,2.5147777,2.4212357,2.644408,3.0539043,2.2300806,3.1284882,3.1343258,3.6810976,3.7845642,3.7384032,4.0991779,3.9117012,4.2865827,4.0266169,2.9410464,4.1842732,3.1924183,4.3201712,2.1871915,2.7436362,3.3541433,2.8596771,4.1878851,2.6142636,2.9329908,4.1246693,3.6137715,3.8244525,3.7397349,3.9338839,3.1285973,3.6519795,4.5199139,3.697693,2.4859625,3.5974918,2.9213166,2.3955754,3.1453298,3.2863417,2.6117658,3.8960039,2.7854036,2.8472614,2.4324246,2.0804645,2.3453173,2.0402417,1.5093892,1.9235784,1.4262282,2.9496656,1.8228929,2.1659591,2.1881185,1.3273391,2.080789,2.1228795,2.190858,1.4611134,2.0319684,1.7938403,2.1299913,1.2124929,1.4141927,1.2035249,1.5306318,1.6586828,2.5056311,1.9386174,2.3676524,1.7895453,2.2681061,2.005874,2.2053365,2.5413435,3.1307276,2.8479943,1.9716775,2.3335658,2.9462844,3.6205107,3.2300032,3.4403449,3.3256801,2.4973198,2.0849346,2.9557563,3.0652164,3.366852,2.8278154,2.9864101,3.877302,6.0303115,3.2688723,3.5190745,2.639111,3.714445,3.5635734,3.24532,2.3533246,3.5833929,3.0448218,2.299633,3.4734401,3.7384744,2.2719605,3.9412303,3.6377095,3.2771119,4.3027501,3.8484619,2.4276811,3.0953322,2.8841077,4.1025334,4.2917576,2.6197757,3.3645138,2.4314183,1.8174194,2.8708788,2.403895,2.3589196,2.464658,2.4679907,2.3679985,2.4593946,2.4610779,2.2022625,2.2353027,2.5090053,2.0262569,2.0019615,1.4434697,1.4343788,1.5575397,1.4840818,1.8685464,1.6611002,2.3447595,2.2903757,1.1514776,1.5191833,1.0677715,2.1799466,1.7810843,1.2329185,1.3770509,1.2855529,1.6682111,1.5280775,2.4811806,2.2756383,1.9633624,2.7255051,2.0590435,2.1707241,1.9101258,2.1841365,2.6666939,1.6214889,2.6328187,2.7202091,2.8138242,2.8078783,2.8834629,2.5901096,2.3271893,3.1778248,3.9981471,3.9017082,4.0047739,4.0254713,2.4416343,4.6464583,4.2059929,2.9643663,3.451808,3.0252913,2.0898613,2.1381241,2.8784052,3.1247475,2.4667662,2.4751101,3.5039007,3.196976,3.9225509,4.6569945,3.6595093,2.4477783,2.7009495,2.5139625,2.7078665,3.2955959,3.758326,2.9206129,2.1607569,2.9329364,2.2193393,3.0691617,2.491672,2.9229015,2.2599894,2.6257638,2.307559,2.8692551,2.3554224,2.3762496,2.1136694,1.8869619,1.6637637,1.9777072,1.6481753,2.4218741,1.7282279,1.5245874,2.0205218,1.4359097,1.806009,2.1156843,1.4973111,2.0881653,1.5425025,1.1207337,1.2373331,1.357714,2.4873457,1.8521436,2.1994765,2.0450172,1.7376926,1.8371209,1.9261675,1.2650022,2.1753933,2.2675921,2.7752472,2.7339213,2.2504079,2.779555,2.3061332,3.0225079,2.2012532,2.8859209,2.8508381,2.3204393,2.7048592,2.2870153,3.1331141,3.4142485,2.6659103,3.1208968,3.0700521,3.1678036,3.3227998,3.3524141,4.2078986,3.2534622,3.0633676,3.0361458,2.4070208,3.127032,2.7343483,2.8085012,2.4785207,3.5431721,3.0041483,3.4155417,3.1883619,3.9387126,3.4372021,3.7709427,3.1696447,3.3070393,3.3017278,3.6088445,3.1380236,2.9559838,2.4681664,3.1302263,2.5382151,1.98369,2.7218488,2.4572655,2.747108,2.337239,2.0142952,2.3746822,2.2432434,1.8851716,1.8991448,1.8650244,1.9405107,2.0414038,1.8514746,1.9505811,1.9915473,2.2992275,1.6694529,1.5069999,1.1927527,1.8625175,1.6083106,2.3634707,1.1268652,1.319124,1.550456,2.167305,1.6624752,1.6797931,1.2817896,2.3547965,3.0417863,2.5599888,2.1678682,2.1882733,2.1737328,3.5933338,2.4979413,2.2777058,1.9875959,2.3851093,2.8959397,2.1435461,2.4614248,2.3759947,2.3082881,2.8803163,3.3675013,3.7249837,3.4582348,3.7308486,3.4623323,4.1891991,2.8846025,2.414989,3.8853606,2.8220506,2.7486158,2.5916212,2.3691058,2.1362572,2.9772587,2.9726772,2.5683964,2.5931004,3.3006919,2.8018009,3.2360739,2.9439428,3.0076574,2.530469,2.9164013,2.9640402,4.1879908,3.4459483,3.7470515,3.0953917,3.3743524,3.3379163,3.4338191,2.5970668,2.977305,2.4469682,2.2288582,2.5700798,2.2180937,2.5434766,2.0457856,1.8196689,2.4919511,1.8756653,1.9271162,1.6246183,2.1486223,1.7416291,1.6286651,2.7429568,1.8760217,1.511259,1.1401331,1.4559092,1.7956338,1.4025986,2.0769671,2.1885823,2.2859212,1.9724645,1.8490097,1.5428219,1.1609433,1.5581891,1.5500508,2.6324304,1.8824616,1.5216121,2.6384122,2.6320114,2.9699431,2.0938214,1.8331607,3.0998718,2.220329,1.8743962,1.5694134,2.7567912,2.2946468,1.9036605,2.6032552,3.3552207,3.0925421,3.7670158,3.3934116,2.8211113,2.7443922,4.0649083,3.0707547,3.4362311,2.5429864,2.2227649,1.7158489,1.8938501,2.5886793,1.9567585,1.2530184,2.8781564,2.619036,2.3123263,2.8100784,2.6468293,2.6494291,3.5312879,2.6083287,4.1647276,3.865765,3.0960333,3.8794466,2.5874003,2.6493856,3.5719867,3.068232,2.206468,2.7493425,3.2002151,2.0876092,3.1585995,2.0880792,2.215382,2.1695197,2.9012322,2.2149929,2.7186513,3.0939733,2.0884968,2.0590951,2.0554619,2.7188304,1.9278885,3.039938,1.58457,2.4995078,2.0631091,1.663603,2.7869127,2.1547038,1.6132883,2.0066623,2.3029744,2.0787818,2.2253451,1.974008,2.2741049,2.0685602,1.7166929,1.7817857,2.2880598,3.2131031,2.2890521,3.092812,2.5081707,2.8935188,1.9370422,1.8247684,2.7272384,2.3373358,2.7136271,2.7825329,2.6074275,2.3615403,2.6912467,2.6976287,2.2293496,2.3569712,2.7278514,3.0664779,2.8229872,2.719053,3.2213882,1.8734228,2.6986775,2.4309322,2.7534264,2.5020957,2.3092594,2.9419433,2.0284219,2.0139626,2.7918141,3.1072548,3.5224388,2.5032715,3.3557738,3.1200516,3.7449449,2.8579646,2.5135575,4.0654558,2.7758894,2.7385484,3.7570694,2.9749303,2.1311345,2.6206746,2.6021903,2.0907876,2.666256,3.8521962,2.3794581,2.236391,2.0307487,1.9296913,2.6010741,1.5414681,1.7869169,2.6423708,2.7537031,2.354426,2.7171518,2.1031868,1.8891381,2.1579672,1.7526763,1.765915,1.9714716,1.5582489,1.9353291,1.7436377,1.2530238,1.0888718,2.2274333,1.902162,1.355863,2.1658009,2.148127,2.0760883,1.1295943,1.9698673,1.8106116,1.8699013,2.0823057,3.2537903,2.1225036,1.7115783,2.0788841,1.6948263,2.3110374,1.5951523,2.1917969,1.7858164,3.0106739,2.7736664,2.795891,2.2123178,2.3454618,2.9382848,2.5790068,4.0439108,2.2954307,3.2748263,2.5102989,3.0343863,2.2159444,2.7667823,2.1310627,2.4683296,2.3778815,1.8691957,2.0187164,1.9531402,2.1187417,2.1417038,2.38315,2.4560892,2.0751409,3.1087945,3.1940879,2.7100041,4.4971099,2.8719994,3.32567,2.4097376,2.4691645,2.8138074,2.4125011,3.3513671,2.9930381,2.2608525,2.24499,2.1250562,2.14907,2.0867142,1.816637,2.2791981,2.5293934,1.9377913,2.5713846,1.7580076,1.8669798,1.3818829,1.9467103,1.9402774,2.3380654,2.126128,1.262681,2.0926249,2.065123,2.0378668,1.584575,1.8147973,2.2975679,1.8963987,2.1877793,1.983272,1.8889297,3.6371753,2.3034083,1.936248,1.6498452,2.6182049,2.2154592,1.8438022,2.4709299,3.1742946,2.3998794,2.3771231,2.4712226,2.7081758,2.5852713,2.7806426,2.8586778,2.1783928,2.1456366,2.6416863,3.5352878,3.0691915,2.3512015,2.7121063,2.6335059,2.6088299,2.047827,3.7866274,2.3482743,2.2572027,2.418581,2.1323501,1.8707078,2.223617,2.4131865,1.9750457,2.373449,1.9985017,2.1606145,2.4528057,2.0009498,2.2826453,2.5053277,2.5889298,3.1960144,3.1511066,2.9429558,3.4567229,3.5582477,2.4844828,2.8516518,2.7997466,3.3349205,2.2321127,2.1761108,2.775887,2.1191279,2.1790616,2.1947244,1.8397668,1.4147559,2.2351731,2.3289453,2.0471203,2.3383806,2.163754,2.3054297,1.6707258,1.8216285,2.141492,1.8454948,1.4615444,1.8668115,1.6872305,1.4182309,1.2303322,1.9315612,1.9794734,1.7804993,2.5807698,1.8059306,1.8106945,1.7813833,1.7388731,1.6585575,1.9516076,1.950433,2.0599881,1.7884966,2.4195636,1.8715973,1.9788956,1.6612426,3.5866308,2.0495437,2.3561091,2.4345525,2.9577589,2.417021,2.3799655,2.7413716,3.3145689,3.2001918,2.4823507,3.0948253,3.1081626,3.1602272,3.2060045,2.622409,3.1502396,3.2323287,2.0134792,1.5981567,1.7885223,2.2166163,1.5689586,2.3716627,2.0819625,2.5023223,2.3721338,2.3718219,2.3248316,3.0576187,1.9365711,1.8463423,2.7593669,2.8824033,2.6929363,2.8849758,3.8863788,2.7152039,2.3272339,2.4880438,3.8769269,2.9355076,2.0176006,2.1759968,2.5234584,2.4732865,1.8876527,2.0612722,3.2115867,1.8131362,2.067105,2.01859,2.7776353,1.4746675,2.0799367,2.5639535,2.7081865,2.4870038,1.6354672,1.9367316,1.8763661,1.4904414,2.1911521,1.6249459,2.1877548,1.6432794,2.2204326,1.9696207,1.5941823,3.0597752,1.7261852,2.0669377,1.7479766,2.4761598,2.4327564,2.470571,2.3243763,2.4789758,2.1070609,1.6037902,2.102305,2.5268225,2.3018746,3.0660983,2.842377,3.0182569,2.8726901,2.6994424,2.8727361,2.6473279,2.5408394,2.6348276,2.8801448,2.0109667,2.5323076,1.8405108,3.4196159,2.0566278,2.3069432,2.3313679,1.7029393,1.2637975,2.2086765,2.1535156,1.5799854,1.6167468,1.7377936,1.8818713,1.8119377,2.2111747,1.9933301,2.1719376,2.1168001,3.1539843,4.1993737,3.3211358,2.606165,2.2874983,2.3967551,2.0071401,3.0762291,2.6037495,2.8699929,2.3756243,3.2258159,2.1663393,2.4399133,2.5403759,1.5241727,1.8567909,1.931845,3.0275596,1.5034203,2.3306334,2.3996919,2.2702621,2.4128991,2.0222093,1.6029859,2.2740026,2.8779283,2.8762496,1.5014027,1.5387403,1.8107833,1.1940166,1.6507929,1.1761456,2.2553838,1.5948138,1.4650658,1.4880179,1.4954774,2.0680532,2.0343072,2.5279229,2.7426858,2.730995,1.8990979,3.0099374,2.3674646,2.5780924,3.7719697,2.3363335,2.7527954,3.5297958,2.4621901,2.8523478,2.1862074,2.2859444,1.8283227,2.8246476,2.1538208,2.5282616,2.3639611,2.8584154,3.035728,2.1502987,1.7586214,1.5324398,2.6522453,2.1273933,1.8182495,1.2456449,2.0389307,1.2750065,1.7770425,1.6752197,1.8005969,2.0548374,1.585869,1.7451527,2.1098167,2.5085751,2.3580887,2.5241841,1.673247,2.4727432,2.986818,2.5055412,3.1991836,3.4013885,2.9727617,2.3824126,2.3430509,1.5732426,1.8624314,2.2306958,1.7112334,2.0566642,1.6597689,1.7232449,1.9554877,1.5164974,2.5418695,2.210037,1.8992428,1.0094014,2.7929686,1.2927406,2.141303,2.3755399,2.065332,1.4599714,1.8311518,1.6016267,1.457112,1.6800138,2.0187107,1.641135,2.6571451,2.0596754,1.7927337,1.8028919,1.252789,1.6599207,2.2550712,1.8005523,2.0906642,2.2563348,1.996283,1.9015441,1.91457,2.4114571,2.5946939,2.8719431,1.7282237,2.645844,3.0876978,1.9352885,2.4522401,1.3768203,2.174308,1.6867061,2.5499766,1.9361878,1.9867352,1.5096237,2.9019509,1.7052017,1.7968846,1.8571559,.98205895,1.8945704,1.8772241,.93149389,1.5651287,1.6471251,2.2216318,1.9548921,1.7144566,1.4436749,2.641558,1.7938671,2.134576,1.6241978,1.9649049,2.1771009,2.1630554,2.8749226,2.5362045,2.8538626,2.2887464,3.2952252,3.0539202,2.1773857,2.0927042,1.7127113,1.7833065,2.1496275,1.6511817,1.8749838,1.6428218,1.756386,1.2394393,2.3597462,2.429746,1.2193716,1.9166708,1.4044111,1.287159,2.0685065,1.4489287,2.4784924,1.7301762,2.1593814,1.5436542,1.7410039,1.4314954,1.4187692,2.9365215,2.1047021,1.7489635,2.1125065,2.1230712,1.4434282,2.2630774,1.871933,1.8786935,2.4840349,1.900356,1.9092503,2.0880277,3.4982653,1.7298124,2.0173265,1.9657934,2.0405873,2.4244834,2.2430405,2.539473,2.4511349,1.8957479,2.5168316,2.5149379,2.3080183,2.5845515,2.161376,1.7017604,2.1439074,1.755998,1.6547605,1.1977078,1.6652113,.83425938,.8564632,1.448916,1.0679841,1.3870344,1.975974,.94501629,1.732736,2.204028,1.7214861,2.0645008,1.4572249,2.6291565,2.8051834,2.5093319,2.0076982,2.6362848,1.8332811,2.8915754,1.964082,1.6884376,3.1844177,2.429813,2.1846481,1.6742047,2.4565996,1.6583262,1.7268643,1.5515063,1.9243572,1.5200847,1.6981686,1.9390205,2.2257496,1.7811031,1.7333563,1.5109923,1.9164516,2.4995955,1.1549183,2.2375897,1.6063275,1.7672052,1.3882897,1.6162181,1.8914177,1.1926533,1.7818192,1.2782574,1.9514753,1.9777712,1.620942,1.8291532,1.436183,3.143729,2.4494535,3.0345127,2.0730229,2.3893869,2.5354082,2.7589102,1.8677414,1.7965585,2.3826539,2.0827881,2.4729081,2.9984808,2.6023855,2.5252197,2.4493793,3.3770014,1.9969213,2.0955974,1.4557975,2.5512676,1.6581994,1.1357497,1.4866726,1.5149368,1.6137232,1.3551421,1.9617397,1.5101058,1.245078,1.2801677,.98326431,1.4854022,1.6444093,1.4030566,2.8344494,1.3558252,2.2120555,1.4665224,2.3041848,2.4575899,2.0246388,2.6366668,2.7526793,2.8031448,2.5112882,2.95341,2.8416679,2.4655499,2.3549519,2.2037656,2.6332552,2.7088805,1.9556061,1.7628069,2.496695,2.5368465,1.9660005,1.5400431,1.8545345,2.0741437,2.2078247,2.4834239,2.0107254,1.9847618,1.7829467,1.9224809,1.3900617,1.4081977,1.3166354,2.0612257,2.4714891,2.2299161,1.7752641,2.9113395,1.7760014,1.9065337,1.877075,1.6253226,1.6215736,1.737427,2.8470114,2.2536916,2.3736558,3.5538697,2.0560542,2.2459497,1.3520696,2.4557831,1.8767046,2.0052332,2.7601783,2.8653436,2.5693832,1.8870747,1.8695047,1.9235118,2.7543425,1.5855319,1.7503964,1.70962,2.3982979,1.3092469,2.6025455,1.4514932,2.003394,1.1912446,1.4864406,1.6178744,1.2432954,.71780706,1.6311487,1.3251213,1.5186753,2.6719131,1.8267867,1.8932529,1.8999905,1.1975088,1.6728558,2.1505221,2.918871,2.5764408,2.5213528,1.9841386,1.8701658,2.4029567,1.9540922,1.9224031,1.8238828,2.0146119,2.4911758,2.2232743,1.6869953,2.1750618,2.2716943,2.4885497,2.6842515,1.9055483,1.5207456,1.3690668,1.7895467,1.7181907,1.9784921,1.8835985,1.6123766,1.6450049,1.7424415,1.924465,2.5283681,1.9732152,2.077388,1.9201045,2.4087999,1.7634124,1.9394359,1.8396952,1.8870543,1.545977,1.3854143,2.2271213,2.0093391,1.8950086,1.8971694,1.90527,1.7539787,2.1853306,2.3514298,1.8912982,1.8354199,2.1110042,1.9776326,1.7199595,2.0367148,3.0302039,1.5951848,2.4691822,2.4689356,1.783465,2.2264434,1.8496104,1.9873584,2.4685408,1.9803505,1.7647098,2.0724703,1.3907017,1.5061439,.87527431,1.1507149,1.4207834,1.161215,1.1276096,1.6295528,1.7039592,1.9533922,1.5765184,1.6365323,1.8224206,1.3617254,2.1259925,1.6089289,2.417532,1.8326854,2.6539303,1.5504236,1.3482398,1.599989,2.1521118,1.5506126,2.263368,1.6242548,1.8378209,2.5036583,1.7905984,1.8761239,1.9576806,1.5904046,1.9315544,1.3985896,1.7284463,1.7871083,1.9990943,1.485661,2.5088249,1.9004822,1.7111805,1.736225,1.863159,1.9888656,1.3675667,1.9419778,1.9942537,1.9139808,2.1866328,2.2363117,1.8449013,1.6049772,2.3908241,2.150671,1.9204851,2.5318571,1.8942279,1.4609321,2.3615657,1.6131291,2.0835277,2.3694488,2.6242605,2.2288634,2.6575403,1.9879634,2.3612383,2.0359086,2.3156425,2.1694274,2.2481842,1.7929961,2.0015238,2.3799189,2.2226938,2.6824985,2.0723558,1.7295132,1.917688,2.0318084,1.8304456,1.341896,1.1394123,1.4443099,1.2406437,1.358046,1.5085967,.71220018,1.2727869,1.2770429,1.5083049,1.5079532,1.52746,1.4858768,1.6471964,1.621834,2.3145163,1.9509016,2.59022,1.5537627,2.1164047,2.0122211,1.1992089,3.2747371,1.4655824,2.269247,1.5517391,2.0368914,1.6720741,1.9730631,2.5069554,1.9504472,3.0503912,1.7800241,2.0798124,1.7864842,1.8605557,1.5733882,1.8801561,1.4596532,2.3495454,2.2342816,1.8980225,1.6801397,1.88078,1.5957642,2.8473033,1.7837329,1.7317581,1.5112854,2.8881932,1.7365568,1.3717013,1.7612199,1.9791704,.99849991,2.111441,2.2690058,1.8688699,1.8303655,1.5165718,2.2048086,1.9537364,2.1761731,3.1172293,2.3634281,1.5390785,2.5514438,2.5130811,2.1814153,1.4866666,1.726888,2.9655165,2.2036744,2.6278128,1.8914937,1.4511832,2.276316,2.208094,1.4279578,1.6914182,1.6835757,1.3432019,1.5494011,1.1781422,1.6435976,1.4548737,.83002106,1.1242384,.80138381,1.2524261,1.2573104,1.1125233,1.222561,1.4427389,1.5224594,1.679095,1.7133606,1.4751725,1.4904459,1.7120079,1.5918958,2.0797286,1.760043,2.033961,2.002554,2.7433757,1.8496813,2.0370773,1.6484719,1.8527105,1.3834457,1.4280802,1.3116238,2.0553094,2.1343938,1.6718025,1.6052598,1.5400427,2.5514022,1.9997492,1.3181581,2.2490458,1.6542942,1.6974176,1.5192033,2.193872,2.6127009,1.9973062,1.7190944,2.1044035,1.88718,2.3962808,1.8163198,1.1807574,1.6488288,2.2167592,.95015681,1.983633,2.2545886,2.1887568,2.2714182,1.8477507,1.5397618,1.9202836,2.1454134,2.3367346,2.1882957,2.1669828,1.4450626,1.8792752,2.6775395,1.9746154,1.7695012,2.1809191,2.1748169,1.2347989,1.4377964,2.1792883,1.863154,1.5424336,2.2771547,1.3850572,1.2643787,1.0750502,1.2806733,1.3209787,1.2055279,.95970957,1.2125106,.55752152,1.1182064,1.0889919,1.3337615,1.7079026,2.1449927,1.7293258,1.8805774,1.4715356,2.0841567,2.1687361,1.3861364,2.3101635,1.669222,2.7429097,1.1347173,2.1970731,1.7891419,1.5806897,1.5980383,1.9914476,2.4306479,1.6054717,2.1487356,2.4385789,2.1924893,2.706522,1.9003238,1.8027308,1.9653792,1.4870187,1.8199841,1.7116251,1.8387781,2.27893,1.4707321,1.5012781,1.8599507,2.643843,1.3474685,2.7543888,2.3926587,2.0599629,1.6576112,2.0033419,1.8477658,1.1923152,1.8002779,1.6865568,2.7677061,1.6314038,1.6874064,2.0633386,3.2075171,1.4153052,1.2623564,1.7272425,2.0483456,1.5730251,2.9270368,2.1774514,2.2557849,2.2373435,1.598812,1.1924487,2.098487,3.1131986,2.1626021,1.8054886,1.5735135,1.4884572,1.9197685,1.2548668,1.3178826,1.6181616,1.1515121,.8338156,1.0758449,.91361492,1.0607173,1.2898844,1.3335163,1.2239475,.87093766,1.3692269,1.2267534,2.0857788,1.3617606,1.9036878,1.7620303,2.227032,1.7993649,1.8504501,1.7157396,1.6623763,1.8822909,2.0353768,1.9183549,2.7029566,3.6134577,1.4150624,2.4459061,2.4862385,1.5702534,1.476116,2.3538547,1.1836144,2.0005251,2.3942032,1.8320351,1.9329519,2.4778369,2.0718811,1.6222112,1.8641935,1.6004538,1.9784886,1.443055,1.8352299,1.8693099,1.3138299,2.4006107,2.4940645,1.6426751,1.6118467,2.2599108,2.0837132,3.0470947,1.5768486,.97634502,1.5913458,2.6594978,1.8186912,1.9169223,2.3253224,2.3986398,2.371961,3.4753605,1.6601488,1.6510313,1.5010407,1.8574498,1.8898645,2.1749959,1.5373309,1.6428408,1.2783029,1.9767043,2.2936493,1.6538095,1.0904218,1.5955439,1.769362,1.2383781,1.1166075,.99760077,1.5136025,1.200187,.97629321,.80033395,1.0981986,.81465839,.85448195,1.3240306,1.6190239,1.2139452,1.0310994,1.7279537,1.4246087,1.4693778,1.5267279,1.64361,1.5147679,2.2460687,1.3570052,1.27049,1.6587986,1.0527913,2.0414787,1.6194969,1.6225034,1.5957874,2.3949669,1.4328523,1.7800166,1.3525579,1.9948422,1.6434825,1.3649216,1.4754267,1.1953161,1.7543847,2.0327057,1.6531045,1.4528075,1.706656,1.5525566,2.0257176,1.9187212,1.4474351,1.5162162,1.2728672,1.8429029,1.9768607,1.6059284,1.5572298,1.7222487,1.4422234,2.3624042,1.8548196,1.0591202,1.7464634,1.3333837,1.4001926,2.0864621,2.135864,1.9152907,1.6185073,1.4474026,2.0131741,2.6180217,1.4586311,1.7698581,1.5642927,2.3051762,1.7145479,1.7145645,1.686396,1.4899991,1.2135307,1.4200605,1.5569857,1.7726416,1.4438518,.99346558,1.5999108,1.024861,1.0890406,.91933744,1.631669,.89991865,1.4717787,1.3357447,1.2887007,1.1523481,1.1371681,1.2714111,1.2332876,1.5540449,2.0911602,1.2036373,1.3793298,1.5489395,1.4627402,1.2310435,2.6069604,2.0952637,1.534267,2.7847317,1.8598911,1.5839004,1.8625952,1.8365601,1.6842834,1.3806975,1.7106167,1.8237703,1.342825,1.5512142,1.9411451,1.5953167,2.1147168,1.6496782,2.2741814,1.7366068,1.6470036,1.5167117,2.3126912,1.9166349,1.242891,1.9067896,2.0101604,1.2212879,1.4096559,1.2251759,1.5259432,1.4631568,1.8955268,1.4246145,1.5085565,1.9460133,1.7631678,3.2188826,2.742478,1.8447851,1.6068085,1.3747885,2.4756272,1.7552015,1.7832165,1.5593729,2.2621883,1.4796391,1.8490986,1.792128,2.0261348,2.1561015,1.2429311,1.3281518,2.5511558,1.738545,1.4227243,1.4659203,2.1570527,1.2574987,1.4903584,1.724805,1.0257101,1.1914645,2.1636661,1.2449466,1.5675588,.71819203,.91069681,1.112042,1.059094,1.4016226,1.22884,.90974121,1.5294787,.75044547,1.4624927,1.7430586,1.5516605,2.1101952,1.6960647,1.9273923,2.1971365,1.628087,1.9659735,2.4745676,1.22784,1.8180211,2.27114,1.7073591,1.843049,1.6394438,1.8169245,2.0020694,1.7913346,2.0081313,1.7451584,1.5667649,2.2579828,1.3410296,1.3549474,1.3722005,1.3446939,2.0278481,1.433244,1.739939,2.1418223,1.8681138,1.991315,1.5827643,3.2166968,2.3677273,2.684128,1.5974134,2.1795129,1.959992,1.9770005,1.3667313,1.7696264,1.3126062,1.6385399,2.209409,3.398844,1.4406392,3.0053185,2.4490745,2.0494008,1.8151632,2.5998114,1.5836965,2.5674557,1.9263718,2.2258983,1.7093807,1.721037,2.354009,1.8219143,2.0446016,1.6848209,1.6674662,1.8788552,1.5705137,1.3692913,1.0830433,1.6098257,1.1150221,1.4863497,1.2348629,1.3997423,1.0324226,.70651103,.81840928,1.0610551,1.3971293,1.7091173,1.2914554,1.3361535,1.7702115,1.5718114,1.2342786,1.9199208,1.7113216,1.7345578,1.3867797,1.7573394,1.3220703,2.4610131,2.052728,2.1391144,1.8627941,1.4298997,1.8283747,2.2112668,1.3295455,1.4537863,2.3316472,1.3983411,2.1515619,1.8163179,1.7619085,2.4582894,1.145609,2.0469658,1.8484048,1.3397731,1.7212729,2.0031649,2.1266671,1.7427529,1.0914236,2.2757567,1.5439375,1.8276355,1.6543269,1.3133395,1.850561,2.2805973,1.5998383,1.5990931,1.6748949,1.8292394,1.5952028,2.2015504,2.1979343,1.4296741,2.2587221,1.7946045,1.7349746,2.0361851,2.5008145,1.2286589,3.003856,1.4883894,1.4313113,1.9285079,1.4378405,1.8820868,1.675351,1.4690324,1.4573307,1.3491714,1.0891999,1.2978958,1.0351488,1.1114601,1.0504016,.48704082,.84641174,.56313555,.93137038,1.2709865,1.2326208,1.3559667,.94564396,1.0821413,1.1768049,1.3273345,1.347848,1.4514521,1.5827775,1.3774996,1.8692279,1.5825967,1.5205748,2.5684084,1.4142632,2.0504448,1.3072908,2.351949,1.9189055,1.5827215,1.4451363,1.9412271,1.7505884,1.6364608,1.3631338,1.8308923,1.7752157,1.2608082,1.3337804,1.6766684,1.1493091,1.6412264,1.7983686,1.0340087,1.6793624,2.0351679,1.075778,1.2246538,2.3885818,3.3433779,1.9020843,2.0337582,2.0749151,1.2772,1.2934398,1.4177308,1.2881155,2.1180323,1.4404893,1.897107,2.2287185,2.2918815,1.4420972,1.7806136,2.0255825,1.4946133,2.0114159,2.9045439,2.4749023,1.6911367,2.2445156,1.9403802,1.9760059,1.6861774,1.3147485,1.4126053,2.2710464,1.3255159,1.8275645,1.2031277,1.4333958,2.0027225,1.3958972,.78224003,.9202684,1.1732191,.76449677,.83786714,1.3011927,1.0298418,1.2801513,1.0735571,.82556287,.76321105,1.0365768,1.4775897,.9853043,1.7069666,2.1189453,1.2133785,1.9913764,1.4454624,2.2484218,1.5783358,1.0190089,1.9692241,1.5486198,2.2319056,1.6985272,1.752126,.9249996,.83413708,1.8578428,1.2145486,1.8112283,1.5251548,1.3013898,1.498576,1.5068849,1.6962861,.95696495,1.7806734,1.7453003,1.9514403,1.537452,1.7536699,1.6713509,1.7753993,1.0556818,1.457435,2.2829708,1.8036095,1.7325867,2.0988298,1.9278818,1.763997,1.4868074,1.911837,1.8669759,2.9070022,1.8368694,1.4938891,1.8296825,2.0860863,2.1724129,1.95032,1.3521269,2.2371862,1.8834968,1.5354294,1.762551,1.2585985,1.4943407,2.1265129,2.0581704,3.2141419,1.5431596,1.324378,2.0646874,1.7924824,1.1511113,1.8634772,1.1816361,1.0668434,1.6807702,1.2952483,1.4129145,1.5738213,.55114483,1.0613712,.63884596,.8950345,.86622096,1.0681119,.49981524,1.1443626,.97904212,1.2883847,1.217222,1.6035471,1.4790314,1.3611865,1.1487499,1.5347683,1.8983919,1.2954843,1.4859352,1.2857622,2.5702313,1.5159285,1.1574183,1.7673056,1.4261945,1.3591552,1.4242272,1.9970829,1.8756067,1.6559662,1.3306276,1.5611635,2.0419886,1.9570897,1.0631568,1.6665088,1.9753713,1.5479708,1.7180006,2.520308,1.727262,2.3928876,1.2889912,1.5577313,1.1297018,1.7681409,1.7456424,2.7558087,1.8975271,1.6579552,1.7083436,2.2418886,1.5759265,2.0886155,2.2414315,2.1080626,1.5099303,1.5151621,2.45117,2.2226929,1.4985808,2.0700989,1.6579781,2.0344462,1.5723177,1.3405269,1.8791903,1.6642831,.90567026,1.964873,2.2848443,1.1787853,1.1905507,.90776062,2.108124,1.0883983,1.5888046,.77732123,.83693763,.81551928,1.1710005,.86512618,1.2811787,.7820897,.9149315,.45850858,.88493222,.84057314,.92816296,1.1396381,1.2427449,1.0486576,2.1429215,1.0905735,1.6358539,1.2471114,1.3042478,1.2267781,2.5087277,1.1206302,2.7349566,2.4281831,1.6228703,1.3679348,1.3552291,1.1415301,1.6776165,1.7728657,1.8638664,1.3011915,2.403519,1.3827296,1.0209027,1.6168274,1.5757992,2.1462606,1.8757055,1.2016595,.98610813,1.6683705,1.8458875,1.5489873,1.5827084,1.3896466]}],stripes_left:[{size:31,values:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}],stripes_right:[{size:31,values:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]};function C0(e){return(F6[e.name]??[]).map(n=>({size:n.size,values:Float64Array.from(n.values)}))}class F0{constructor(t,n,s){this.n=t,this.lo=n,this.hi=s,this.values=new Float64Array((s-n+1)*t)}values;index(t,n){const s=n-t;return s<this.lo||s>this.hi||t<0||t>=this.n?-1:(s-this.lo)*this.n+t}at(t,n){const s=this.index(t,n);return s<0?0:this.values[s]}set(t,n,s){const o=this.index(t,n);o>=0&&(this.values[o]=s)}}function $0(e,t,n){const s=new Uint8Array(n-t);for(let o=t;o<n;o++)s[o-t]=Number.isFinite(e[o])?1:0;return s}function E0(e,t){const n=e.length,s=Pa(e),o=new Float64Array(n);for(let c=0;c<n;c++)o[c]=Math.abs(e[c]-s);const r=Pa(o),i=Math.max(1,s-r*t),a=new Uint8Array(n);for(let c=0;c<n;c++)a[c]=e[c]>=i?1:0;return a}function Pa(e){const t=Array.from(e).filter(s=>Number.isFinite(s));if(t.length===0)return Number.NaN;t.sort((s,o)=>s-o);const n=t.length>>1;return t.length%2===1?t[n]:(t[n-1]+t[n])/2}function $6(e,t,n,s){const o=new Float64Array(t),r=Math.min(t,s+1);for(let i=0;i<r;i++){let a=0,c=0;for(let u=0;u+i<t;u++){if(n[u]===0||n[u+i]===0)continue;const l=e.at(u,u+i);l>0&&(a+=l,c++)}o[i]=c===0?Number.NaN:a/c}return o}function E6(e,t,n,s,o=10){const r=Math.min(s,Math.max(0,t-1)),i=$6(e,t,n,s),a=new F0(t,0,r);for(let c=0;c<=r;c++){const u=Number.isFinite(i[c])?i[c]:0,l=(c-a.lo)*t;for(let h=0;h+c<t;h++){const f=e.at(h,h+c);if(!Number.isFinite(f)||f===0)continue;const d=f/u;a.values[l+h]=d>=o?1:d}}return a}function B6(e,t,n,s,o,r){const i=e-t;if(i>=1&&i<=r)return!0;if(e>=0&&e<n&&t>=0&&t<n){const a=t-e;return a>=0&&a<=o&&(s[e]===0||s[t]===0)}return t<0?e<0:t>=n?e>=n-o-2:e<0?t<o+r:!1}function Jr(e,t,n,s,o,r,i){const a=s.size,c=(a-1)/2,u=a*a,l=Math.trunc((1-i.missingTol)*u);let h=0,f=0,d=0,m=0,g=0,p=0,w=0,b=0;for(let k=0;k<a;k++){const C=o-c+k;for(let B=0;B<a;B++){const F=r-c+B,E=s.values[k*a+B];if(w+=E,b+=E*E,B6(C,F,t,n,i.maxDist,a)){p++,m+=E,g+=E*E;continue}const _=C>=0&&C<t&&F>=0&&F<t?e.at(C,F):0;h+=_,f+=_*_,d+=_*E}}const y=u-p;if(y<l||y===0)return{corr:0,present:y};const A=h/y,N=f/y,I=(w-m)/y,M=(b-g)/y,x=(N-A*A)*(M-I*I),v=x>0?Math.sqrt(x):0;if(!(Math.abs(v)>=1e-10))return{corr:0,present:y};const S=(d/y-A*I)/v;return{corr:Math.min(1,Math.max(-1,S)),present:y}}function T6(e,t){return new F0(e,0,Math.min(t,Math.max(0,e-1)))}function O6(e,t,n,s,o,r,i,a){const c=o.size,u=(c-1)/2,l=c*c,h=new Int32Array(n+1);for(let F=0;F<n;F++)h[F+1]=h[F]+(s[F]===0?1:0);const f=(F,E)=>{const _=Math.max(0,F),$=Math.min(n,E);return $<=_?!1:h[$]-h[_]>0};let d=0,m=0;for(let F=0;F<l;F++)d+=o.values[F],m+=o.values[F]*o.values[F];const g=d/l,w=m/l-g*g,b=Math.trunc((1-r.missingTol)*l),y=t.values,A=o.values,N=(F,E,_,$,O,L)=>{const D=l-$;if(D<b||D===0)return 0;const q=F/D,X=E/D,P=(d-O)/D,z=(m-L)/D,R=(X-q*q)*(z-P*P),H=R>0?Math.sqrt(R):0;return Math.abs(H)>=1e-10?Math.min(1,Math.max(-1,(_/D-q*P)/H)):0},I=new Float64Array(c+3),M=(F,E,_)=>{if(E===0)return 0;const $=F/l,O=(E/l-$*$)*w,L=O>0?Math.sqrt(O):0;return Math.abs(L)>=1e-10?Math.min(1,Math.max(-1,(_/l-$*g)/L)):0},x=t.hi-t.lo+1,v=Math.max(0,i-u),S=Math.min(n,a+u),k=new Float64Array(Math.max(0,S-v)*x);for(let F=0;F<x;F++)for(let E=v;E<S;E++)k[(E-v)*x+F]=y[F*n+E];const C=Math.max(c-1,t.lo+c-1),B=Math.min(e.hi,t.hi-c+1)-3;for(let F=Math.max(0,i);F<Math.min(n,a);F++){const E=F-u,_=F+u+1,$=E>=0&&_<=n,O=$&&!f(E,_);for(let L=0;L<=e.hi;L++){const D=F+L;if(D>=n)break;const q=D-u,X=D+u+1,P=$&&L>=C&&L<=B&&X+3<=n;if(P&&O&&!f(q,X+3)){let G=0,W=0,Y=0,tt=0,et=0,ht=0,U=0,V=0,Z=0,J=0,ot=0,it=0;for(let ut=0;ut<c;ut++){const vt=E+ut;let gt=(vt-v)*x+(q-vt)-t.lo,St=ut*c,mt=k[gt],At=k[gt+1],yt=k[gt+2];for(let ne=0;ne<c;ne++){const qt=A[St],pt=mt;mt=At,At=yt,yt=k[gt+3],G+=pt,W+=pt*pt,Y+=pt*qt,tt+=mt,et+=mt*mt,ht+=mt*qt,U+=At,V+=At*At,Z+=At*qt,J+=yt,ot+=yt*yt,it+=yt*qt,gt++,St++}}const lt=L*n+F;e.values[lt]=M(G,W,Y),e.values[lt+n]=M(tt,et,ht),e.values[lt+2*n]=M(U,V,Z),e.values[lt+3*n]=M(J,ot,it),L+=3;continue}if(P&&L+3+c-1<=r.maxDist){for(let Ot=0;Ot<c+3;Ot++)I[Ot]=s[q+Ot]===0?1:0;const G=h[_]-h[E],W=G*c+(c-G)*(h[X]-h[q]),Y=G*c+(c-G)*(h[X+1]-h[q+1]),tt=G*c+(c-G)*(h[X+2]-h[q+2]),et=G*c+(c-G)*(h[X+3]-h[q+3]);let ht=0,U=0,V=0,Z=0,J=0,ot=0,it=0,lt=0,ut=0,vt=0,gt=0,St=0,mt=0,At=0,yt=0,ne=0,qt=0,pt=0,$t=0,on=0;for(let Ot=0;Ot<c;Ot++){const ue=E+Ot,he=s[ue]===0;let se=(ue-v)*x+(q-ue)-t.lo,ci=Ot*c,ro=k[se],io=k[se+1],ao=k[se+2],rn=he?1:I[0],an=he?1:I[1],cn=he?1:I[2];for(let co=0;co<c;co++){const Ut=A[ci],Dn=Ut*Ut,L1=ro;ro=io,io=ao,ao=k[se+3];const lo=rn;rn=an,an=cn,cn=he?1:I[co+3];const Rn=L1*(1-lo),Pn=ro*(1-rn),zn=io*(1-an),qn=ao*(1-cn);ht+=Rn,U+=Rn*Rn,V+=Rn*Ut,Z+=Ut*lo,J+=Dn*lo,ot+=Pn,it+=Pn*Pn,lt+=Pn*Ut,ut+=Ut*rn,vt+=Dn*rn,gt+=zn,St+=zn*zn,mt+=zn*Ut,At+=Ut*an,yt+=Dn*an,ne+=qn,qt+=qn*qn,pt+=qn*Ut,$t+=Ut*cn,on+=Dn*cn,se++,ci++}}const rt=L*n+F;e.values[rt]=N(ht,U,V,W,Z,J),e.values[rt+n]=N(ot,it,lt,Y,ut,vt),e.values[rt+2*n]=N(gt,St,mt,tt,At,yt),e.values[rt+3*n]=N(ne,qt,pt,et,$t,on),L+=3;continue}if(!(E>=0&&_<=n&&q>=0&&X<=n)){const G=Jr(t,n,s,o,F,D,r);e.values[L*n+F]=G.corr;continue}if(q<=_-2||f(E,_)||f(q,X)){e.values[L*n+F]=L6(t,n,s,o,E,q,r.maxDist,d,m,b);continue}let R=0,H=0,K=0;for(let G=0;G<c;G++){const W=E+G,Y=Math.max(0,t.lo-(q-W)),tt=Math.min(c,t.hi-(q-W)+1);if(tt<=Y)continue;let et=(q+Y-W-t.lo)*n+W,ht=G*c+Y;for(let U=Y;U<tt;U++){const V=y[et];R+=V,H+=V*V,K+=V*A[ht],et+=n,ht++}}e.values[L*n+F]=M(R,H,K)}}}function L6(e,t,n,s,o,r,i,a,c,u){const l=s.size,h=s.values,f=e.values,{lo:d,hi:m}=e;let g=0,p=0,w=0,b=0,y=0,A=0;for(let F=0;F<l;F++){const E=o+F,_=n[E]===0;for(let $=0;$<l;$++){const O=r+$,L=h[F*l+$],D=O-E;if(D<0||(_||n[O]===0)&&D<=i){b++,y+=L,A+=L*L;continue}const q=D>=d&&D<=m?f[(D-d)*t+E]:0;g+=q,p+=q*q,w+=q*L}}const I=l*l-b;if(I<u||I===0)return 0;const M=g/I,x=p/I,v=(a-y)/I,S=(c-A)/I,k=(x-M*M)*(S-v*v),C=k>0?Math.sqrt(k):0;if(!(Math.abs(C)>=1e-10))return 0;const B=(w/I-M*v)/C;return Math.min(1,Math.max(-1,B))}function B0(e,t){if(!Number.isFinite(e)||t<=3)return Number.NaN;const n=Math.atanh(Math.min(1-1e-16,Math.max(-1+1e-16,e)));return 2*_6(-Math.abs(n*Math.sqrt(t-3)))}function _6(e){return .5*D6(-e/Math.SQRT2)}function D6(e){const t=Math.abs(e),n=t<2?1-R6(t):P6(t);return e>=0?n:2-n}function R6(e){let t=e,n=e;for(let s=1;s<200&&(t*=2*e*e/(2*s+1),n+=t,!(t<Math.abs(n)*1e-17));s++);return 2/Math.sqrt(Math.PI)*Math.exp(-e*e)*n}function P6(e){let n=1/e,s=1e300,o=n;for(let r=1;r<300;r++){const i=r/2;n=e+i*n,n===0&&(n=1e-300),s=e+i/s,s===0&&(s=1e-300),n=1/n;const a=s*n;if(o*=a,Math.abs(a-1)<1e-16)break}return Math.exp(-e*e)/Math.sqrt(Math.PI)*o}function T0(e){const t=e.length,n=new Float64Array(t).fill(Number.NaN),s=[];for(let i=0;i<t;i++)Number.isFinite(e[i])&&s.push(i);s.sort((i,a)=>e[a]-e[i]);const o=s.length;let r=Number.POSITIVE_INFINITY;for(let i=0;i<o;i++){const a=o/(o-i);r=Math.min(r,a*e[s[i]]),n[s[i]]=Math.min(1,r)}return n}function z6(e,t,n=2){const s=e.n,o=e.hi-e.lo+1,r=new Int32Array(o*s).fill(-1),i=l=>{let h=l;for(;r[h]!==h;)h=r[h];let f=l;for(;r[f]!==h;){const d=r[f];r[f]=h,f=d}return h},a=(l,h)=>{const f=i(l),d=i(h);f!==d&&(r[Math.max(f,d)]=Math.min(f,d))},c=(l,h)=>{const f=e.index(l,h);return f<0?-1:e.values[f]>=t?f:-1};for(let l=0;l<s;l++)for(let h=e.lo;h<=e.hi;h++){const f=l+h;if(f<0)continue;if(f>=s)break;const d=c(l,f);if(d<0)continue;r[d]=d;const m=c(l,f-1);m>=0&&a(d,m);const g=c(l-1,f);g>=0&&a(d,g)}const u=new Map;for(let l=0;l<s;l++)for(let h=e.lo;h<=e.hi;h++){const f=l+h;if(f<0)continue;if(f>=s)break;const d=c(l,f);if(d<0)continue;const m=i(d),g=e.values[d],p=u.get(m);if(p===void 0){u.set(m,{row:l,col:f,score:g,size:1});continue}p.size++,g>p.score&&(p.row=l,p.col=f,p.score=g)}return[...u.values()].filter(l=>l.size>=n)}function O0(e,t,n,s,o,r){const i=Math.floor(s/2)+1,a=(s-1)/2;if(o-i+1+a<0||o+i+a>=t+2*a||r-i+1+a<0||r+i+a>=t+2*a)return null;const c=new Float64Array(s*s);for(let u=0;u<s;u++){const l=o-i+1+u,h=l<0||l>=t||n[l]===0;for(let f=0;f<s;f++){const d=r-i+1+f,m=h||d<0||d>=t||n[d]===0||l-d>=1&&l-d<=s;c[u*s+f]=m?Number.NaN:e.at(l,d)}}return c}function L0(e,t){let n=0,s=0;for(const a of e)Number.isFinite(a)?a===0&&s++:n++;const o=e.length,r=n/o,i=o-n===0?1:s/(o-n);return r<t.missingTol&&i<t.zeroTol}function Zr(e,t){const n=new Float64Array(t*t),s=new Int32Array(t*t);for(const r of e)for(let i=0;i<n.length;i++){const a=r[i];Number.isFinite(a)&&(n[i]+=a,s[i]++)}const o=new Float64Array(t*t);for(let r=0;r<o.length;r++)o[r]=s[r]>0?n[r]/s[r]:Number.NaN;return o}function _0(e,t){const n=new Float64Array(t*t);for(let s=0;s<n.length;s++)n[s]=Number.isFinite(e[s])?e[s]:0;for(let s=0;s<t;s++)for(let o=0;o<t;o++)s!==o&&(n[s*t+o]+=Number.isFinite(e[o*t+s])?e[o*t+s]:0);return n}function D0(e,t){return E6(e.contacts,e.n,e.detectable,jr(e.n,t.maxDist,t.largestKernel))}function jr(e,t,n){return Math.min(t,e)+n}function q6(e,t,n,s,o){const{n:r,detectable:i}=e,a=[];let c=0;for(const u of z6(n,o.pearson)){const l=o.onDiagonal===!0?u.col:u.row,h=O0(t,r,i,s.size,l,u.col);if(h===null||!L0(h,o)){c++;continue}const f=Jr(t,r,i,s,l,u.col,o);a.push({pattern:{bin1:l,bin2:u.col,score:n.at(l,u.col),pvalue:B0(n.at(l,u.col),f.present),kernel:0,iteration:0},values:h})}return{matrix:t,corr:n,found:a,rejected:c}}function U6(e,t,n,s,o){const{n:r,detectable:i}=e,a=[];for(const c of o){const u=O0(t,r,i,n.size,c.bin1,c.bin2),l=u!==null&&L0(u,s),h=l?Jr(t,r,i,n,c.bin1,c.bin2,s):null;a.push({pattern:{bin1:c.bin1,bin2:c.bin2,score:h===null?Number.NaN:h.corr,pvalue:h===null?Number.NaN:B0(h.corr,h.present),kernel:0,iteration:0},values:l&&u!==null?u:new Float64Array(n.size*n.size).fill(Number.NaN)})}return a}function G6(e,t){const n=e.map((o,r)=>r);n.sort((o,r)=>{const i=e[r].score-e[o].score;return Number.isNaN(i)?Number.isNaN(e[o].score)?1:-1:i!==0?i:o-r});const s=new Set;for(const o of n){if(s.has(o))continue;const r=e[o];for(const i of n)i===o||s.has(i)||Math.abs(e[i].bin1-r.bin1)<t&&Math.abs(e[i].bin2-r.bin2)<t&&s.add(i)}return e.map((o,r)=>!s.has(r))}function H6(e,t){const n=G6(e,t.separationBins),s=e.filter((o,r)=>n[r]&&Math.abs(o.bin2-o.bin1)>=t.minDistBins&&Number.isFinite(o.pvalue));return{kept:s,qvalues:T0(s.map(o=>o.pvalue))}}const Q6=0,K6=2,R0={colormap:"seismic",centre:1,range:[Q6,K6]},W6=16e6;function js(e,t){let s=Math.max(256,Math.min(e,4096));for(;s>1&&s*(s+t)>W6;)s=Math.floor(s/2);return Math.max(1,s)}function Y6(e,t){const n=js(Math.max(0,t)*2,Math.max(0,t)*2);return Math.max(1,Math.ceil(Math.max(1,e)/n))}function ti(e,t){return e.rowExtent[0]<=t.from&&e.rowExtent[1]>=t.to&&e.colExtent[0]<=t.from&&e.colExtent[1]>=t.to}function Ft(e,t,n){const s=e.inputs.block;if(s===void 0||s.binsPerCell!==1||e.framing.balance!==n)return null;for(const o of t)if(!ti(s,o))return null;return s}function ei(e,t){if(e.rowExtent[0]===t.from&&e.rowExtent[1]===t.to&&e.colExtent[0]===t.from&&e.colExtent[1]===t.to)return e;const s=t.to-t.from,o=new Float32Array(s*s),r=t.from-e.rowExtent[0],i=t.from-e.colExtent[0];for(let a=0;a<s;a++){const c=(r+a)*e.ncols+i;o.set(e.values.subarray(c,c+s),a*s)}return{nrows:s,ncols:s,values:o,rowExtent:[t.from,t.to],colExtent:[t.from,t.to],binsPerCell:1}}async function ni(e,t,n){if(n.block!==null)return ei(n.block,t);const s=await e.mc.matrix({rows:[t.from,t.to],cols:[t.from,t.to],balance:n.balance,value:n.value});return{nrows:s.nrows,ncols:s.ncols,values:s.values,rowExtent:[s.rowExtent[0],s.rowExtent[1]],colExtent:[s.colExtent[0],s.colExtent[1]],binsPerCell:1}}class V6{constructor(t,n,s=!1){this.n=t,this.hi=n,this.circular=s,this.values=new Float32Array((n+1)*t).fill(Number.NaN)}values;at(t,n){const s=n-t;if(s<0||s>this.hi||t<0||t>=this.n)return 0;const o=this.values[s*this.n+t];return Number.isNaN(o)?0:o}forward(t,n){if(n<0)return this.forward(t+n,-n);if(n>this.hi)return Number.NaN;let s=t;if(this.circular)s=(t%this.n+this.n)%this.n;else if(s<0||s+n>=this.n)return Number.NaN;return this.values[n*this.n+s]}}async function Oe(e,t,n){const s=t.to-t.from,o=n.circular===!0,r=Math.max(0,Math.min(n.hi,o?Math.floor(s/2):Math.max(0,s-1))),i=new V6(s,r,o),a=(h,f,d,m,g)=>{for(let p=d;p<m;p++){const w=(p-d)*f-g,b=Math.min(s-1,p+r);for(let y=p;y<=b;y++)i.values[(y-p)*s+p]=h[w+y]}},c=(h,f)=>{for(let d=0;d<r;d++)for(let m=s-r;m<s;m++){const g=d+s-m;g<1||g>r||(i.values[g*s+m]=h[d*f+(m-(s-r))])}};if(n.block!==null){const h=n.block,f=t.from-h.rowExtent[0],d=t.from-h.colExtent[0];for(let m=0;m<s;m++){const g=(f+m)*h.ncols+d,p=Math.min(s-1,m+r);for(let w=m;w<=p;w++)i.values[(w-m)*s+m]=h.values[g+w]}if(o&&r>0)for(let m=0;m<r;m++){const g=(f+m)*h.ncols+d;for(let p=s-r;p<s;p++){const w=m+s-p;w<1||w>r||(i.values[w*s+p]=h.values[g+p])}}return i}const u=js(r,r),l=Math.max(1,Math.ceil(s/u));for(let h=0;h<l;h++){await n.onTile?.(h,l);const f=h*u,d=Math.min(s,f+u);if(d<=f)break;const m=Math.min(s,d+r),g=await e.mc.matrix({rows:[t.from+f,t.from+d],cols:[t.from+f,t.from+m],balance:n.balance,value:n.value});a(g.values,g.ncols,f,d,f)}if(o&&r>0){const h=await e.mc.matrix({rows:[t.from,t.from+r],cols:[t.to-r,t.to],balance:n.balance,value:n.value});c(h.values,h.ncols)}return await n.onTile?.(l,l),i}async function X6(e,t,n){const s=t.to-t.from,o=Math.max(0,Math.min(n.hi,s-1)),r=new Float64Array(o+1),i=new Float64Array(o+1),a=(l,h,f,d,m)=>{for(let g=d;g<m;g++){const p=f+g*h,w=Math.min(s-1,g+o);for(let b=g;b<=w;b++){const y=l[p+b];Number.isNaN(y)||(r[b-g]+=y,i[b-g]+=1)}}},c=n.block;if(c!==null&&ti(c,t)){const l=t.from-c.rowExtent[0],h=t.from-c.colExtent[0];a(c.values,c.ncols,l*c.ncols+h,0,s)}else{const l=js(o,o),h=Math.max(1,Math.ceil(s/l));for(let f=0;f<h;f++){await n.onTile?.(f,h);const d=f*l,m=Math.min(s,d+l);if(m<=d)break;const g=await e.mc.matrix({rows:[t.from+d,t.from+m],cols:[t.from+d,t.from+Math.min(s,m+o)],balance:n.balance,value:n.value});a(g.values,g.ncols,-d*g.ncols-d,d,m)}await n.onTile?.(h,h)}const u=new Float64Array(o+1);for(let l=0;l<=o;l++)u[l]=i[l]>0?r[l]/i[l]:Number.NaN;return u}async function P0(e,t,n,s){const o=t.to-t.from,r=Math.max(0,n.halo),i=js(r*2,r*2),a=Y6(o,r);for(let c=0;c<a;c++){const u=c*i,l=Math.min(o,u+i);if(l<=u)break;const h=Math.max(0,u-r),f=Math.min(o,l+r),d=await ni(e,{from:t.from+h,to:t.from+f},{block:n.block,balance:n.balance,value:n.value});await s({values:d.values,size:f-h,from:h,ownFrom:u,ownTo:l,index:c,total:a})}}async function z0(e){const t=e.mc,n=new Int32Array(t.nBins).fill(-1);for(let o=0;o<t.nContigs;o++){const[r,i]=t.contigExtent(o);for(let a=r;a<i;a++)n[a]=o}const s=new Float64Array(t.nBins);return e.progress(0,1,"counting coverage"),await t.scanPixels({onChunk:o=>{e.throwIfCancelled();for(let r=0;r<o.length;r++){const i=o.bin1[r],a=o.bin2[r];if(n[i]!==n[a])continue;const c=o.count[r];!Number.isFinite(c)||c===0||(s[i]+=1,a!==i&&(s[a]+=1))}},onProgress:(o,r)=>e.progress(o,r,"counting coverage")}),s}function to(e){const t=[],n=e.hasGenomes?new Set(e.displayGenomes()):null;for(let s=0;s<e.nContigs;s++)n!==null&&!n.has(e.contigGenomeIds[s])||t.push(s);return t}function $e(e,t){return t===null?{ids:to(e),missing:[]}:Xs(e,t)}function be(e,t,n){if(t.length===0)return null;const s=`${t.slice(0,6).join(", ")}${t.length>6?", …":""}`;return n>0?`${t.length.toLocaleString()} ticked ${t.length===1?"sequence is":"sequences are"} not in this file and ${t.length===1?"is":"are"} left out: ${s}.`:`This file has no sequence called ${s}, under that spelling or any this viewer knows of. It has ${e.chromnames.slice(0,6).join(", ")}${e.chromnames.length>6?", …":""}.`}function Zt(e,t){const[n,s]=e.contigExtent(t);return s>n?{from:n,to:s}:null}function ee(e,t){if(!t)return null;const n=`bins/${re}`;if(!e.handle.has(n))throw new T("unsupported",`This file has no /${n} column, so there are no weights to balance with. Run \`cooler balance\` on it, or turn balancing off and read the raw counts.`,{column:re});return e.handle.readNumeric(n,0,e.nBins)}function kt(e){return V1(e)}function J6(e){const t=Math.round(e);return t===0?"0":`${t<0?"-":"+"}${kt(Math.abs(t))}`}function En(e,t){if(!(e>0)||!(t>0))return[];const n=(e-1)/2*t;return[0,.25,.5,.75,1].map(s=>J6(-n+s*2*n))}function Z6(e){const t=ct(e.params,"csPattern","loops");return je.find(n=>n.name===t)??je[0]}async function j6(e,t){const n=Z6(e),s=C0(n)[0],o=nt(e.params,"balance",!1),r=e.framing.value===""?j:e.framing.value,i=e.mc.binsize,a=t.reduce((v,S)=>Math.max(v,S.col-S.row),0),c=Math.max(Math.min(a,e.mc.nBins),1),u={maxDist:c,pearson:n.pearson,missingTol:n.maxPercUndetected/100,zeroTol:n.maxPercZero/100,onDiagonal:n.onDiagonal},l=t,h=new Map;for(const v of l){const S=h.get(v.bounds.from);S===void 0?h.set(v.bounds.from,[v]):S.push(v)}const f=ee(e.mc,o);let d;if(f!==null)d=(v,S)=>$0(f,v,S);else{const v=await z0(e);d=(S,k)=>E0(v.subarray(S,k),5)}const m=[...h.values()].map(v=>v[0].bounds),g=Ft(e,m,o),p=[],w=[];let b=0;for(const[,v]of h){await e.breathe(),e.progress(b,l.length,`${v.length.toLocaleString()} anchors`);const S=v[0].bounds,k=S.to-S.from;if(k<=s.size){b+=v.length;continue}const B={contacts:await Oe(e,S,{hi:jr(k,c,s.size),block:g,balance:o,value:r,onTile:async()=>{await e.breathe()}}),n:k,detectable:d(S.from,S.to)},F=D0(B,{maxDist:c,largestKernel:s.size}),E=U6(B,F,s,u,v.map(_=>({bin1:_.row-S.from,bin2:_.col-S.from})));for(let _=0;_<E.length;_++)p.push({anchor:v[_],score:E[_].pattern.score,pvalue:E[_].pattern.pvalue,qvalue:Number.NaN}),w.push(E[_].values);b+=v.length}if(e.progress(l.length,l.length,"done"),e.throwIfCancelled(),w.length===0)return e.note("No anchor landed on a sequence long enough to score against this template."),[];const y=T0(p.map(v=>v.pvalue));for(let v=0;v<p.length;v++)p[v].qvalue=y[v];const A=p.filter(v=>Number.isFinite(v.score)).length;A<p.length&&e.note(`${(p.length-A).toLocaleString()} of ${p.length.toLocaleString()} anchors could not be scored: their window holds too many undetectable or empty pixels. They are in the table with no score, and they contribute nothing to the pileup.`);const N=s.size,I=Zr(w,N),M=n.onDiagonal?_0(I,N):I,x=[td(M,N,{preset:n,n:A,binsize:i}),ed(p,n)];if(!n.onDiagonal){const v=Js(p.map(S=>({separation:(S.anchor.col-S.anchor.row)*i,score:S.score})),{id:"apa-chromosight-loop-spectrum",label:`Loop spectrum · ${n.name.replace(/_/g," ")}`,noun:"anchors",yLabel:"Pearson correlation with the template"});v!==null&&x.push(v)}return x.push(nd(p,i)),x}function td(e,t,n){return{kind:"matrix",id:"apa-chromosight",label:`Pileup of ${n.n.toLocaleString()} ${n.preset.name.replace(/_/g," ")} · chromosight`,nrows:t,ncols:t,values:Float32Array.from(e),xLabel:"Distance from the centre",yLabel:"Distance from the centre",xTicks:En(t,n.binsize),yTicks:En(t,n.binsize),...R0,stats:[{label:"windows",value:n.n,digits:0,hint:"Anchors that could be scored."},{label:"P2LL",value:fr(e,t,t),digits:2,hint:"Centre against the lower-left corner. Above 1 is enrichment."}]}}function ed(e,t){const n=e.map(l=>l.score).filter(l=>Number.isFinite(l)),s=n.length>0?Math.min(...n):0,o=n.length>0?Math.max(...n):1,r=Math.max(10,Math.min(50,Math.round(Math.sqrt(n.length)*2))),i=o>s?(o-s)/r:1,a=new Float64Array(r),c=new Float64Array(r);for(let l=0;l<r;l++)a[l]=s+i*(l+.5);for(const l of n)c[Math.min(r-1,Math.max(0,Math.floor((l-s)/i)))]++;return{kind:"curve",id:"apa-chromosight-spectrum",label:`Score spectrum · ${n.filter(l=>l>=t.pearson).length.toLocaleString()} of ${n.length.toLocaleString()} at or above ${t.pearson}`,series:[{name:"Anchors",x:a,y:c,n:n.length}],xLabel:"Pearson correlation with the template",yLabel:"Anchors",xScale:"linear",yScale:"linear"}}function nd(e,t){return{kind:"table",id:"apa-chromosight-anchors",label:"Per anchor",columns:[{key:"anchor",label:"Anchor",kind:"text"},{key:"separation",label:"Separation (bp)",kind:"number",digits:0},{key:"score",label:"Score",kind:"number",digits:4,hint:"Pearson r with the template."},{key:"pvalue",label:"p",kind:"number",digits:6},{key:"qvalue",label:"q",kind:"number",digits:6,hint:"Benjamini-Hochberg."}],rows:e.map(n=>({anchor:n.anchor.label,separation:(n.anchor.col-n.anchor.row)*t,score:n.score,pvalue:n.pvalue,qvalue:n.qvalue}))}}const za=512,sd=async e=>{const t=v0(e.params),n=Ts(e.inputs.pairs,e.params,"pairs"),s=Ts(e.inputs.features,e.params,"features"),o=t?n.value:void 0,r=t?void 0:s.value;if(o===void 0&&r===void 0)return e.note(w0(t?n:s,{unchosen:t?"No loop set was chosen. Load a BEDPE — a loop table, a set of anchor pairs — and pick it under Pairs.":"No feature set was chosen. Load a BED or a GTF and pick it under Features.",gone:`The ${t?"loop":"feature"} set chosen is no longer loaded. Re-open the file, or pick another.`})??""),[];const i=nt(e.params,"balance",!1),a=e.framing.value===""?j:e.framing.value,c=Nt(e.params)?Math.max(11,Math.round(Q(e.params,"grid",51))):M6(e.params)*2+1,u=ct(e.params,"norm","matched"),l=Da(e.params),h=k0(e.params),f=t?ad(e,o):l?Md(e,r):h?Nd(e,r):ld(e,r);if(f.length===0)return e.note(l?"No two features of this set are on one sequence within the separation range, so there is no pair to pile up. Widen the range, or check that the set and the file spell their sequences alike.":h?"No two features of this set are on one sequence this file has, so no feature has a next one to pair with. Check that the set and the file spell their sequences alike.":"No anchor of this set lands inside a sequence this file has, so there is nothing to pile up."),[];if(l&&e.note(`${f.length.toLocaleString()} pairs made from ${r.length.toLocaleString()} features.`),h&&e.note(`${f.length.toLocaleString()} pairs, each feature with the next along its sequence, made from ${r.length.toLocaleString()} features.`),I6(e.params))return j6(e,f.map(R=>({row:R.pair.row,col:R.pair.col,bounds:R.bounds,label:R.label})));const d=(t||h)&&!Nt(e.params)?cd(e,f):f;if(d.length===0)return[];const m=C6(e.params),g=m>1?Id(d,m):ud(e,d,Xt(e.params)?r:null),p=m>1?xd(g,R=>e.toBp(R)):null,w=g6(c,He(e.params)),b=Nt(e.params),y=Zs(e.params),A=[],N=Xr(Math.round(Q(e.params,"seed",1))),I=u==="matched"?Math.max(1,Math.round(Q(e.params,"controls",5))):0,M=Math.max(0,Math.round(Q(e.params,"minShift",50))),x=Math.max(M,Math.round(Q(e.params,"maxShift",500))),v=Math.max(0,Q(e.params,"minShiftScale",1)),S=Math.max(v,Q(e.params,"maxShiftScale",3));for(let R=0;R<g.length;R++)for(const H of g[R]){const K=Ga(e,H,c,w);if(K===null||(A.push({...K,label:H.label,separation:H.pair.separation,control:!1,group:R,bounds:H.bounds}),I===0))continue;const G=b?Math.max(1,dd(K.rect)):0,W=b?Math.round(G*v):M,Y=b?Math.max(W,Math.round(G*S)):x;for(const tt of w6(H.pair,H.bounds,{perPair:I,minShift:W,maxShift:Y,rng:N})){const et=Ga(e,fd(H,tt),c,w);et!==null&&A.push({...et,separation:tt.separation,control:!0,group:R,bounds:H.bounds})}}if(A.length===0)return e.note("Every window ran off the end of its sequence. Use a narrower window."),[];const k=u==="oe"&&Nt(e.params)&&!Xt(e.params);k&&e.note("Observed / expected on a scaled grid is for a feature set on the diagonal, and these are pairs. The raw pileup is shown — use the distance-matched control, which is drawn at the same separations by construction.");const C=g.map(()=>new as(c,c)),B=g.map(()=>new as(c,c)),F=od(e),E=g.map(()=>F.map(()=>new as(1,c))),_=g.map(()=>F.map(()=>new as(1,c))),$=k6(e.params),O=[],L={minDiag:x6(e.params),mirrored:Xt(e.params)},D=Ft(e,A.map(pd),i),q=u==="oe"&&!k?await yd(e,A,{block:D,balance:i,value:a}):null,X=wd(A);let P=0;for(const R of X){await e.breathe(),e.progress(P,A.length,`${P.toLocaleString()} of ${A.length.toLocaleString()} windows`);const H=await bd(e,R.rect,{block:D,balance:i,value:a});for(const K of R.plans){P++;const G=Ad(H,R.rect,K,c,w,{...L,expected:q?.get(K.bounds.from)});if(G!==null){if(K.control){B[K.group].add(G);continue}if(C[K.group].add(G),F.length>0){const W=rd(K,w);for(let Y=0;Y<F.length;Y++){const tt=qa(F[Y].values,K.rect.rowFrom,K.rect.rowTo,c,W),et=qa(F[Y].values,K.rect.colFrom,K.rect.colTo,c,W);E[K.group][Y].add(tt),_[K.group][Y].add(et),$&&(E[K.group][Y].add(et),_[K.group][Y].add(tt))}}K.label!==void 0&&O.push({label:K.label,separation:K.separation*e.mc.binsize,score:y?La(G,w):fr(G,c,c)})}}}e.progress(A.length,A.length,"done"),e.throwIfCancelled();const z=[];for(let R=0;R<g.length;R++){const H=C[R].finish();if(H.n===0)continue;const K=p!==null?`APA · ${p[R]}`:g.length===1?"APA":`APA · group ${R+1}`;let G=H.values,W,Y=`${K} · raw`;if(u==="matched"){const U=B[R].finish();U.n>0?(G=p6(H.values,U.values),W=1,Y=`${K} · over distance-matched control`):e.note("No control window could be placed, so the raw pileup is shown.")}else q!==null&&(W=1,Y=`${K} · observed / expected`);const tt=Xt(e.params)?Os(e.params)==="start"?"the feature’s start":Os(e.params)==="end"?"the feature’s end":"the feature’s centre":"the centre",et=Nt(e.params)?y?`Position along the feature (0 → 1), flanked by ${He(e.params)}×`:"Scaled position":`Distance from ${tt}`,ht=Nt(e.params)?y?x0(e.params)?gd(He(e.params)):md(w,He(e.params)):[]:En(c,e.mc.binsize);z.push({kind:"matrix",id:`apa-${R}`,label:Y,nrows:c,ncols:c,values:G,xLabel:et,yLabel:et,xTicks:ht,yTicks:ht,colormap:W===void 0?"default":nl,...W===void 0?{}:{centre:W},...(()=>{const U=id(F,E[R],_[R]);return U===void 0?{}:{margins:U}})(),stats:[{label:"windows",value:H.n,digits:0,hint:"Anchors that contributed."},y?{label:"in / out",value:La(G,w),digits:2,hint:"The domain’s own corner against the same block across its boundary. Above 1 means contact stops at the edge."}:{label:"P2LL",value:fr(G,c,c),digits:2,hint:"Centre against the lower-left corner. Above 1 is enrichment."}]})}if(O.length>0){if(!Xt(e.params)){const R=Js(O,{id:"apa-loop-spectrum",label:"Loop spectrum",noun:Da(e.params)?"pairs":"loops",yLabel:"P2LL — centre against the lower-left corner"});R!==null&&z.push(R)}O.sort((R,H)=>(Number.isNaN(H.score)?-1:H.score)-(Number.isNaN(R.score)?-1:R.score)),z.push({kind:"table",id:"apa-anchors",label:"Per anchor",columns:[{key:"anchor",label:"Anchor",kind:"text"},{key:"separation",label:"Separation (bp)",kind:"number",digits:0},{key:"score",label:y?"In / out":"P2LL",kind:"number",digits:3}],rows:O.map(R=>({anchor:R.label,separation:R.separation,score:R.score}))})}return z};function od(e){const t=f6(e.params,"tracks"),n=[];for(const s of t){const o=e.inputs.vectors?.[`tracks:${s}`];o!==void 0&&n.push({name:e.inputs.labels?.[s]??s,values:o})}return n.length<t.length&&e.note(`${(t.length-n.length).toLocaleString()} of ${t.length.toLocaleString()} tracks could not be read and are not drawn beside the pileup. Re-open the file, or pick another under Track aggregates.`),n}function rd(e,t){if(e.body!==void 0)return N0(t,e.body.from-e.rect.rowFrom,e.body.to-e.rect.rowFrom,e.body.pad)}function qa(e,t,n,s,o){const r=n-t;if(r<=0)return new Float64Array(s).fill(Number.NaN);const i=new Float64Array(r);for(let a=0;a<r;a++){const c=t+a;i[a]=c>=0&&c<e.length?e[c]:Number.NaN}return o===void 0?A0(i,1,r,1,s):y0(i,1,r,Float64Array.from([0,1]),o)}function id(e,t,n){if(e.length===0)return;const s=[],o=[];for(let r=0;r<e.length;r++){const i=n[r].finish(),a=t[r].finish();i.n>0&&s.push({name:e[r].name,values:Float64Array.from(i.values)}),a.n>0&&o.push({name:e[r].name,values:Float64Array.from(a.values)})}if(!(s.length===0&&o.length===0))return{...s.length===0?{}:{top:s},...o.length===0?{}:{right:o}}}function ad(e,t){const n=[],s=Ee(t.contigs);for(let o=0;o<t.length;o++){const r=Ls(e,t.contigs[t.contig1[o]],t.start1[o],t.end1[o],s),i=Ls(e,t.contigs[t.contig2[o]],t.start2[o],t.end2[o],s);if(r===null||i===null||r.contig!==i.contig)continue;const a=Math.min(r.bin,i.bin),c=Math.max(r.bin,i.bin);n.push({pair:{row:a,col:c,separation:c-a},bounds:r.bounds,label:t.name[o]===""?Vr(t.contigs[t.contig1[o]],t.start1[o]):t.name[o],rank:t.score[o],span:c-a,centreDistance:Math.abs((t.start2[o]+t.end2[o])/2-(t.start1[o]+t.end1[o])/2),rows:{from:a,to:a+1},cols:{from:c,to:c+1}})}return n}function cd(e,t){const n=v6(e.params),s=n*e.mc.binsize,o=t.filter(a=>(a.centreDistance??Number.POSITIVE_INFINITY)>=s),r=t.length-o.length;if(r===0)return o;const i=`nearer the diagonal than ${n.toLocaleString()} bins (${Bn(s)})`;return e.note(o.length===0?`Every loop of this set is ${i} so there is nothing to pile up. Set the nearest loop lower, or to 0 for every one.`:`${r.toLocaleString()} of ${t.length.toLocaleString()} loops are ${i} and are left out. Set the nearest loop to 0 to pile up every one.`),o}function q0(e,t,n){const s=e.start[t],o=e.end[t];if(n==="centre")return U0(s,o);const r=Math.max(s,o-1),i=e.strand[t]<0;return n==="start"?i?r:s:i?s:r}function U0(e,t){return Math.floor((e+t)/2)}function ld(e,t){const n=[],s=Ee(t.contigs),o=Os(e.params);for(let r=0;r<t.length;r++){const i=Ls(e,t.contigs[t.contig[r]],t.start[r],t.end[r],s,{point:q0(t,r,o)});i!==null&&n.push({pair:{row:i.bin,col:i.bin,separation:0},bounds:i.bounds,label:t.name[r]===""?Vr(t.contigs[t.contig[r]],t.start[r]):t.name[r],rank:t.score[r],span:i.body.to-i.body.from,rows:i.body,cols:i.body,extent:{start:t.start[r],end:t.end[r]}})}return n}function Ls(e,t,n,s,o,r={}){const i=Be(e.mc,t,o);if(i<0)return null;const[a,c]=e.mc.contigExtent(i),u=e.mc.coords.binIndex(i,r.point??U0(n,s));if(u<a||u>=c)return null;const l=Ua(e.mc.coords.binIndex(i,Math.max(0,Math.min(n,s))),a,c-1),h=Ua(e.mc.coords.binIndex(i,Math.max(0,Math.max(n,s)-1)),l,c-1);return{bin:u,body:{from:l,to:h+1},bounds:{from:a,to:c},contig:e.mc.chromnames[i]}}function Ua(e,t,n){return Math.min(n,Math.max(t,e))}function ud(e,t,n){const s=Bs(e.params,"rankBy"),o=ct(e.params,"subset","all");if(s===null||o==="all"||n===null)return[t];const i=[...s==="score"?t:hd(t,n,s)].sort((l,h)=>Number.isNaN(l.rank)?Number.isNaN(h.rank)?0:1:Number.isNaN(h.rank)?-1:h.rank-l.rank);if(o==="top")return[i.slice(0,Math.max(1,Math.round(Q(e.params,"count",500))))];const a=Math.max(2,Math.round(Q(e.params,"groups",4))),c=Math.ceil(i.length/a),u=[];for(let l=0;l<a;l++){const h=i.slice(l*c,(l+1)*c);h.length>0&&u.push(h)}return u}function hd(e,t,n){return e.map((s,o)=>{for(const r of(t.detail[o]??"").split(M5)){const i=r.search(/[=:]/);if(i<0||r.slice(0,i).trim()!==n)continue;const a=Number.parseFloat(r.slice(i+1).trim());return{...s,rank:Number.isFinite(a)?a:Number.NaN}}return{...s,rank:Number.NaN}})}function Ga(e,t,n,s){const{from:o,to:r}=t.bounds;if(Nt(e.params)){if(t.span<=0)return null;if(x0(e.params)&&t.extent!==void 0){const l=m6(t.extent.start,t.extent.end,He(e.params),e.mc.binsize),h={rowFrom:o+l.from,rowTo:o+l.to,colFrom:o+l.from,colTo:o+l.to};return h.rowFrom<o||h.rowTo>r||h.rowTo<=h.rowFrom?null:{rect:h,zoomed:!0}}const c=s.flank===0?0:t.span*He(e.params),u={rowFrom:Math.floor(t.rows.from-c),rowTo:Math.ceil(t.rows.to+c),colFrom:Math.floor(t.cols.from-c),colTo:Math.ceil(t.cols.to+c)};return u.rowFrom<o||u.colTo>r||u.rowTo<=u.rowFrom||u.colTo<=u.colFrom?null:Zs(e.params)?{rect:u,body:{from:t.rows.from,to:t.rows.to,pad:c}}:{rect:u}}const i=(n-1)/2,a={rowFrom:t.pair.row-i,rowTo:t.pair.row+i+1,colFrom:t.pair.col-i,colTo:t.pair.col+i+1};return a.rowFrom<o||a.colTo>r?null:{rect:a}}function fd(e,t){const n=t.row-e.pair.row;return{...e,pair:t,rows:{from:e.rows.from+n,to:e.rows.to+n},cols:{from:e.cols.from+n,to:e.cols.to+n}}}function dd(e){return Math.max(e.rowTo-e.rowFrom,e.colTo-e.colFrom)}function md(e,t){if(e.flank===0)return["0","0.25","0.5","0.75","1"];const n=e.flank/e.side,s=(e.flank+e.body)/e.side,o=r=>r<=n?-t*(1-r/n):r>=s?1+t*(r-s)/(1-s):(r-n)/(s-n);return[0,.25,.5,.75,1].map(r=>String(Number(o(r).toFixed(2))))}function gd(e){return[0,.25,.5,.75,1].map(t=>String(Number((t*(1+2*e)-e).toFixed(2))))}function pd(e){return{from:Math.min(e.rect.rowFrom,e.rect.colFrom),to:Math.max(e.rect.rowTo,e.rect.colTo)}}function wd(e){const t=[...e].sort((s,o)=>s.rect.rowFrom-o.rect.rowFrom||s.rect.colFrom-o.rect.colFrom),n=[];for(const s of t){const o=n[n.length-1];if(o!==void 0){const r={rowFrom:Math.min(o.rect.rowFrom,s.rect.rowFrom),rowTo:Math.max(o.rect.rowTo,s.rect.rowTo),colFrom:Math.min(o.rect.colFrom,s.rect.colFrom),colTo:Math.max(o.rect.colTo,s.rect.colTo)};if(r.rowTo-r.rowFrom<=za&&r.colTo-r.colFrom<=za){o.rect=r,o.plans.push(s);continue}}n.push({rect:{...s.rect},plans:[s]})}return n}async function bd(e,t,n){if(n.block!==null){const o=n.block,r=t.rowTo-t.rowFrom,i=t.colTo-t.colFrom,a=new Float32Array(r*i);for(let c=0;c<r;c++){const u=(t.rowFrom-o.rowExtent[0]+c)*o.ncols+(t.colFrom-o.colExtent[0]);a.set(o.values.subarray(u,u+i),c*i)}return{values:a,nrows:r,ncols:i}}const s=await e.mc.matrix({rows:[t.rowFrom,t.rowTo],cols:[t.colFrom,t.colTo],balance:n.balance,value:n.value});return{values:s.values,nrows:s.nrows,ncols:s.ncols}}function Ad(e,t,n,s,o,r){const i=n.rect,a=i.rowTo-i.rowFrom,c=i.colTo-i.colFrom;if(a<=0||c<=0)return null;const u=i.rowFrom-t.rowFrom,l=i.colFrom-t.colFrom;if(u<0||l<0||u+a>e.nrows||l+c>e.ncols)return null;const h=new Float64Array(a*c),{minDiag:f,mirrored:d,expected:m}=r;for(let p=0;p<a;p++){const w=(u+p)*e.ncols+l;for(let b=0;b<c;b++){const y=i.colFrom+b-(i.rowFrom+p);if((d?Math.abs(y):y)<f){h[p*c+b]=Number.NaN;continue}const A=e.values[w+b];if(m===void 0){h[p*c+b]=A;continue}const N=m[Math.abs(y)];h[p*c+b]=N>0?A/N:Number.NaN}}if(n.zoomed===!0)return d6(h,a,s);if(n.body===void 0)return A0(h,a,c,s,s);const g=N0(o,n.body.from-i.rowFrom,n.body.to-i.rowFrom,n.body.pad);return y0(h,a,c,g,g)}async function yd(e,t,n){const s=new Map;for(const i of t){const a=Math.max(Math.abs(i.rect.colTo-1-i.rect.rowFrom),Math.abs(i.rect.rowTo-1-i.rect.colFrom)),c=s.get(i.bounds.from);c===void 0?s.set(i.bounds.from,{bounds:i.bounds,hi:a}):a>c.hi&&(c.hi=a)}const o=new Map;let r=0;for(const[i,{bounds:a,hi:c}]of s)e.progress(r,s.size,`the expected, sequence ${r+1} of ${s.size}`),o.set(i,await X6(e,a,{hi:c,block:n.block,balance:n.balance,value:n.value,onTile:async()=>{await e.breathe(),e.throwIfCancelled()}})),r++;return o}function G0(e,t){const n=Ee(t.contigs),s=[],o=Os(e.params);for(let r=0;r<t.length;r++){const i=q0(t,r,o),a=Ls(e,t.contigs[t.contig[r]],t.start[r],t.end[r],n,{point:i});a!==null&&s.push({contig:a.contig,centre:i,exact:o==="centre"?(t.start[r]+t.end[r])/2:i,bin:a.bin,bounds:a.bounds,body:a.body,label:t.name[r]===""?Vr(t.contigs[t.contig[r]],t.start[r]):t.name[r]})}return s.sort((r,i)=>r.contig===i.contig?r.centre-i.centre:r.contig<i.contig?-1:1),s}function Nd(e,t){const n=G0(e,t),s=[];for(let o=0;o+1<n.length;o++){const r=n[o],i=n[o+1];if(i.contig!==r.contig)continue;const a=Math.min(r.bin,i.bin),c=Math.max(r.bin,i.bin);s.push({pair:{row:a,col:c,separation:c-a},bounds:r.bounds,label:`${r.label} × ${i.label}`,rank:Number.NaN,span:c-a,centreDistance:Math.abs(i.exact-r.exact),rows:{from:a,to:a+1},cols:{from:c,to:c+1}})}return s}function Md(e,t){const n=Math.max(0,Math.round(Q(e.params,"minSep",2))),s=Math.max(n+1,Math.round(Q(e.params,"maxSep",200)));e.note(`Pairs ${n.toLocaleString()} to ${s.toLocaleString()} bins apart, which is ${Bn(n*e.mc.binsize)} to ${Bn(s*e.mc.binsize)} at this file’s ${e.mc.binsize.toLocaleString()} bp resolution.`);const o=Xr(Math.round(Q(e.params,"seed",1))),r=G0(e,t),i=[];let a=0;const c=u=>{if(a++,i.length<Ra){i.push(u);return}const l=Math.floor(o()*a);l<Ra&&(i[l]=u)};for(let u=0;u<r.length;u++){const l=r[u];for(let h=u+1;h<r.length;h++){const f=r[h];if(f.contig!==l.contig)break;const d=Math.min(l.bin,f.bin),m=Math.max(l.bin,f.bin),g=m-d;if(g>s)break;g<n||d!==m&&c({pair:{row:d,col:m,separation:m-d},bounds:l.bounds,label:`${l.label} × ${f.label}`,rank:Number.NaN,span:m-d,rows:{from:d,to:d+1},cols:{from:m,to:m+1}})}}return a>i.length&&e.note(`${a.toLocaleString()} pairs are inside the separation range and ${i.length.toLocaleString()} were sampled, uniformly and with this run’s seed. Narrow the range for all of them.`),i}function Id(e,t){let n=Number.POSITIVE_INFINITY,s=0;for(const a of e){const c=a.pair.separation;c<=0||(c<n&&(n=c),c>s&&(s=c))}if(!Number.isFinite(n)||s<=n)return[e];const o=Math.log(n),r=(Math.log(s)-o)/t,i=Array.from({length:t},()=>[]);for(const a of e){const c=a.pair.separation,u=c<=0?0:Math.min(t-1,Math.floor((Math.log(c)-o)/r));i[u].push(a)}return i.filter(a=>a.length>0)}function xd(e,t){return e.map(n=>{let s=Number.POSITIVE_INFINITY,o=0;for(const r of n){const i=r.pair.separation;i<s&&(s=i),i>o&&(o=i)}return`${Bn(t(Math.max(0,s)))}–${Bn(t(o))}`})}function Bn(e){return Number.isFinite(e)?e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)} Mb`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)} kb`:`${Math.round(e)} bp`:"?"}class H0{constructor(t,n,s=null){this.nBins=t,this.contigOf=n,this.covered=s,this.cis=new Float64Array(t),this.trans=new Float64Array(t)}cis;trans;add(t,n,s){if(!Number.isFinite(s)||t<0||t>=this.nBins||n<0||n>=this.nBins)return;const o=this.contigOf[t]===this.contigOf[n]?this.cis:this.trans;o[t]+=s,t!==n&&(o[n]+=s)}addPixels(t,n,s,o,r){const{cis:i,trans:a,contigOf:c,nBins:u}=this;for(let l=0;l<o;l++){const h=t[l],f=n[l],d=r===null?s[l]:s[l]*r[h]*r[f];if(!Number.isFinite(d)||h<0||h>=u||f<0||f>=u)continue;const m=c[h]===c[f]?i:a;m[h]+=d,h!==f&&(m[f]+=d)}}addBlock(t){const{nrows:n,ncols:s,values:o}=t;for(let r=0;r<n;r++){const i=t.rowExtent[0]+r,a=r*s;for(let c=0;c<s;c++){const u=t.colExtent[0]+c;u<i||this.add(i,u,o[a+c])}}}finish(){const t=new Float64Array(this.nBins),n=new Float64Array(this.nBins),s=new Float64Array(this.nBins),o=new Float64Array(this.nBins);for(let r=0;r<this.nBins;r++){if(this.covered!==null&&!this.covered(r)){t[r]=Number.NaN,n[r]=Number.NaN,s[r]=Number.NaN,o[r]=Number.NaN;continue}const i=this.cis[r],a=this.trans[r];t[r]=i+a,n[r]=i,s[r]=a,o[r]=i+a>0?i/(i+a):Number.NaN}return{total:t,cis:n,trans:s,cisFraction:o}}}function eo(e,t){const n=new Int32Array(t).fill(-1);for(let s=0;s<e.length;s++){const o=e[s],r=Math.min(t,o.startBin+o.bins);for(let i=o.startBin;i<r;i++)n[i]=s}return n}const vd=23e3,kd=2e6,Sd=12e6,Cd=async e=>{const t=e.mc;if(t.cells.length===0)return e.note("This file has no cells, so there is nothing to measure per cell."),[];const n=ct(e.params,"cells","all")!=="selected",s=t.activeCells;n&&t.selectCells(null);try{return await Fd(e,s)}finally{n&&t.selectCells(s)}};async function Fd(e,t){const n=e.mc,s=n.activeCells,o=nt(e.params,"balance",!1),r=ee(n,o),i=[];let a=0;for(let A=0;A<n.nContigs;A++){const[N,I]=n.contigExtent(A);i.push({startBin:N,bins:Math.max(0,I-N)}),a=Math.max(a,(I-N)*n.binsize)}const c=eo(i,n.nBins),u=Math.max(0,Q(e.params,"nearFrom",vd)),l=Math.max(u+1,Q(e.params,"nearTo",kd)),h=Math.max(l+1,Q(e.params,"mitoticTo",Sd));a<=l&&e.note(`The longest sequence here is ${Math.round(a).toLocaleString()} bp, which is inside the near band — so the mitotic and far bands are empty by construction and the phasing plot says nothing. Set the band edges to this assembly’s own scale.`);const f=s.map(()=>({contacts:0,nnz:0,cis:0,trans:0,short:0,near:0,mitotic:0,far:0}));e.progress(0,s.length,"reading cells"),await n.scanCells({onCell:(A,N)=>e.progress(A,s.length,N),onChunk:(A,N)=>{e.throwIfCancelled();const I=f[A];for(let M=0;M<N.length;M++){const x=N.bin1[M],v=N.bin2[M],S=N.count[M],k=r===null?S:S*r[x]*r[v];if(!Number.isFinite(k))continue;I.nnz++,I.contacts+=k;const C=c[x],B=c[v];if(C<0||B<0)continue;if(C!==B){I.trans+=k;continue}I.cis+=k;const F=Math.abs(v-x)*n.binsize;F<u?I.short+=k:F<l?I.near+=k:F<h?I.mitotic+=k:I.far+=k}return!0},onProgress:()=>e.throwIfCancelled()}),e.progress(s.length,s.length,"done"),e.throwIfCancelled();const d=new Set(t),m=(A,N)=>N>0?A/N:Number.NaN,g=s.map((A,N)=>{const I=f[N];return{cell:A,ticked:d.has(A)?"yes":"",contacts:I.contacts,nnz:I.nnz,cis:m(I.cis,I.contacts),trans:m(I.trans,I.contacts),short:m(I.short,I.contacts),near:m(I.near,I.contacts),mitotic:m(I.mitotic,I.contacts),far:m(I.far,I.contacts)}}),p=g.filter(A=>A.contacts===0).length;p>0&&e.note(`${p.toLocaleString()} cell${p===1?" has":"s have"} no contact at all, so ${p===1?"its":"their"} fractions are blank rather than zero.`);const w=[{kind:"table",id:"cellqc",label:`${s.length.toLocaleString()} cells`,columns:[{key:"cell",label:"Cell",kind:"text"},{key:"ticked",label:"Ticked",kind:"text",hint:"Whether this cell is in the set the map is drawn from."},{key:"contacts",label:"Contacts",kind:"number",digits:0},{key:"nnz",label:"Stored pixels",kind:"number",digits:0},{key:"cis",label:"Cis",kind:"number",digits:3},{key:"trans",label:"Trans",kind:"number",digits:3},{key:"short",label:`< ${Ht(u)}`,kind:"number",digits:3,hint:"Self-ligation and unligated ends, mostly."},{key:"near",label:`${Ht(u)}–${Ht(l)}`,kind:"number",digits:3,hint:"The near band. High in G1, low just after mitosis."},{key:"mitotic",label:`${Ht(l)}–${Ht(h)}`,kind:"number",digits:3,hint:"The mitotic band. The condensed chromosome’s signature."},{key:"far",label:`> ${Ht(h)}`,kind:"number",digits:3}],rows:g}],b=Float64Array.from(g,A=>A.near),y=Float64Array.from(g,A=>A.mitotic);return w.push({kind:"curve",id:"cellqc-phase",label:"Cell-cycle phasing",series:[{name:`${s.length.toLocaleString()} cells`,x:b,y,n:s.length,mark:"points"}],xLabel:`Contacts ${Ht(u)}–${Ht(l)} (near)`,yLabel:`Contacts ${Ht(l)}–${Ht(h)} (mitotic)`,xScale:"linear",yScale:"linear"}),w}function Ht(e){return e>=1e6?`${Number((e/1e6).toFixed(1))} Mb`:e>=1e3?`${Number((e/1e3).toFixed(1))} kb`:`${Math.round(e)} bp`}const $d=96e6;function Ed(e,t,n){return(Math.min(t,e)+n+1)*e}function Bd(e){const t=typeof e.pattern=="string"?e.pattern:"";return je.find(n=>n.name===t)??je[0]}function Do(e,t,n){if(e.thresholds!=="custom")return n;const s=e[t];return typeof s=="number"&&Number.isFinite(s)?s:n}function Ie(e){return e.thresholds==="custom"}function Ha(e,t){return e===0?0:Math.max(1,Math.round(e/(t>0?t:1)))}function Ro(e,t,n,s){if(!Ie(e))return Ha(n,s);const o=e[t];return typeof o=="number"&&Number.isFinite(o)?Math.max(0,Math.round(o)):Ha(n,s)}je.map(e=>({value:e.name,label:e.name.replace(/_/g," "),hint:e.blurb}));const Qa=64,Td=200,Od=async e=>{const t=Bd(e.params),n=nt(e.params,"balance",!1),s=e.framing.value===""?j:e.framing.value,o=e.mc.binsize,r=Ro(e.params,"maxDist",t.maxDist,o),i=Ro(e.params,"minDist",t.minDist,o),a=Ro(e.params,"minSeparation",t.minSeparation,o),c={maxDist:Math.max(r,1),pearson:Do(e.params,"pearson",t.pearson),missingTol:Do(e.params,"maxPercUndetected",t.maxPercUndetected)/100,zeroTol:Do(e.params,"maxPercZero",t.maxPercZero)/100,onDiagonal:r===0},u=r===0;e.note(`A ${c.maxDist.toLocaleString()}-diagonal scan band reaches ${kt(c.maxDist*o)} from the diagonal at this file’s ${o.toLocaleString()} bp resolution.`);const l=Math.max(1,Math.round(Q(e.params,"iterations",1))),h=C0(t),f=h.reduce((M,x)=>Math.max(M,x.size),0),{units:d,skipped:m}=Ld(e,c.maxDist,f);if(m.length>0&&e.note(`${m.length} sequence${m.length===1?"":"s"} would need a band bigger than a scan can hold, and ${m.length===1?"was":"were"} skipped: ${_d(m)}. The band is the scan distance times the sequence — bring “furthest from the diagonal” down, or open the file at a coarser resolution.`),d.length===0)return e.note(m.length===0?"No sequence in this file is long enough for this template.":"Every sequence in this file would need a band bigger than a scan can hold. Bring “furthest from the diagonal” down, or open the file at a coarser resolution."),[];const g=ee(e.mc,n);g===null&&e.note(`This file carries no balancing weights, so detectable bins are found from the coverage of the raw counts (${Q(e.params,"nMads",5)} MADs below the median). The published method balances the file first and this app does not write to the file it opened, so the two do not start from the same matrix — the scores are comparable in kind, not to the digit.`);const p=Ft(e,d.map(M=>M.span),n),w=[];let b=0;const y=d.length*h.length*l;let A=0,N;if(g!==null)N=(M,x)=>$0(g,M,x);else{const M=Q(e.params,"nMads",5),x=await z0(e);N=(v,S)=>E0(x.subarray(v,S),M)}for(const M of d){await e.breathe();const x=M.span.to-M.span.from,v=jr(x,c.maxDist,f),k={contacts:await Oe(e,M.span,{hi:v,block:p,balance:n,value:s,onTile:async(B,F)=>{await e.breathe(),e.progress(A,y,F===1?`${M.name} · reading`:`${M.name} · reading ${B+1} of ${F}`)}}),n:x,detectable:N(M.span.from,M.span.to)},C=D0(k,{maxDist:c.maxDist,largestKernel:f});for(let B=0;B<h.length;B++){let F=h[B];for(let E=0;E<l&&(e.progress(A,y,`${M.name}${h.length>1?` · template ${B+1}`:""}${l>1?` · pass ${E+1}`:""}`),!(x<=F.size));E++){const _=T6(x,c.maxDist);for(let O=0;O<x;O+=Qa)await e.breathe(),O6(_,C,x,k.detectable,F,c,O,O+Qa);const $=q6(k,C,_,F,c);b+=$.rejected;for(const O of $.found)w.push({unit:M,bin1:M.span.from+O.pattern.bin1,bin2:M.span.from+O.pattern.bin2,score:O.pattern.score,pvalue:O.pattern.pvalue,qvalue:Number.NaN,kernel:B,iteration:E,values:O.values});if(A++,E+1<l){const O=Zr($.found.map(L=>L.values),F.size);if($.found.length===0||O.some(L=>!Number.isFinite(L))){e.note(`Refinement stopped after pass ${E+1} on ${M.name}: the pileup of what it found has gaps in it, and a template with gaps cannot be correlated.`);break}F={size:F.size,values:O}}}}}if(e.progress(y,y,"done"),e.throwIfCancelled(),w.length===0)return e.note(`Nothing reached a score of ${c.pearson} on ${d.length.toLocaleString()} ${d.length===1?"sequence":"sequences"}${b>0?`; ${b.toLocaleString()} candidates were found and then dropped for sitting in missing data`:""}. Lower the score threshold, or check that the pattern suits this map.`),[];const I=Dd(e,w,{separationBins:Math.max(1,a),minDistBins:u?0:i,maxQvalue:Q(e.params,"maxQvalue",1)});return I.length===0?(e.note("Every call was suppressed by the separation, distance or q-value filters."),[]):(b>0&&e.note(`${b.toLocaleString()} candidate ${b===1?"pixel was":"pixels were"} dropped for sitting in too much missing or empty data.`),Rd(e,t,I,{onDiagonal:u,size:h[0].size,sequences:d.length}))};function Ld(e,t,n){const s=e.mc,o=s.chromsizes,r=e.params.sequences,i=Array.isArray(r)?new Set(r.filter(u=>typeof u=="string")):null,a=[],c=[];for(const u of to(s)){const l=s.chromnames[u];if(i!==null&&!i.has(l))continue;const h=Zt(s,u);if(h!==null){if(Ed(h.to-h.from,t,n)>$d){c.push(l);continue}a.push({name:l,cid:u,span:h,length:o.get(l)??(h.to-h.from)*s.binsize})}}return{units:a,skipped:c}}function _d(e){const t=e.slice(0,6).join(", ");return e.length>6?`${t} and ${e.length-6} more`:t}function Dd(e,t,n){const{kept:s,qvalues:o}=H6(t,{separationBins:n.separationBins,minDistBins:n.minDistBins});for(let a=0;a<s.length;a++)s[a].qvalue=o[a];const r=t.length-s.length;if(r>0&&e.note(`${r.toLocaleString()} of ${t.length.toLocaleString()} calls were dropped as overlapping neighbours or as too close to the diagonal.`),n.maxQvalue>=1)return s;const i=s.filter(a=>a.qvalue<=n.maxQvalue);return e.note(`${i.length.toLocaleString()} of ${s.length.toLocaleString()} calls are at q ≤ ${n.maxQvalue}.`),i}function Rd(e,t,n,s){const o=e.mc.binsize,r=t.name.replace(/_/g," "),i=[];i.push(s.onDiagonal?zd(n,r,o):Pd(n,r,o));const a=Zr(n.map(c=>c.values),s.size);if(i.push({kind:"matrix",id:"chromosight-pileup",label:`Pileup of ${n.length.toLocaleString()} ${r}`,nrows:s.size,ncols:s.size,values:Float32Array.from(s.onDiagonal?_0(a,s.size):a),xLabel:"Distance from the centre",yLabel:"Distance from the centre",xTicks:En(s.size,o),yTicks:En(s.size,o),...R0,stats:[{label:"patterns",value:n.length,digits:0,hint:"Calls that entered the pileup."},{label:"median score",value:Gd(n.map(c=>c.score)),digits:3,hint:"Pearson correlation with the template."}]}),i.push(qd(n,t)),!s.onDiagonal){const c=Js(n.map(u=>({separation:Math.abs(u.bin2-u.bin1)*o,score:u.score})),{id:"chromosight-loop-spectrum",label:`Loop spectrum · ${r}`,noun:"calls",yLabel:"Pearson correlation with the template"});c!==null&&i.push(c)}return i.push(Ud(n,o)),e.note(`${n.length.toLocaleString()} ${r} across ${s.sequences.toLocaleString()} ${s.sequences===1?"sequence":"sequences"}.`),i}function Pd(e,t,n){const s=new Bl;for(const o of e){const r=(o.bin1-o.unit.span.from)*n,i=(o.bin2-o.unit.span.from)*n;s.add(o.unit.name,r,Math.min(o.unit.length,r+n),o.unit.name,i,Math.min(o.unit.length,i+n),{score:o.score,name:"",detail:Q0(o)})}return{kind:"intervals",id:"chromosight-patterns",label:`Detected ${t}`,payload:{kind:"pairs",data:s.finish()},noun:{one:"pair",many:"pairs"},display:"overlay"}}function zd(e,t,n){const s=new le;for(const o of e){const r=(o.bin2-o.unit.span.from)*n;s.add(o.unit.name,r,Math.min(o.unit.length,r+n),{score:o.score,name:"",detail:Q0(o)})}return{kind:"intervals",id:"chromosight-patterns",label:`Detected ${t}`,payload:{kind:"features",data:s.finish()},noun:{one:"interval",many:"intervals"},display:"overlay",look:"border"}}function Q0(e){return`score ${e.score.toFixed(4)} · p ${Ka(e.pvalue)} · q ${Ka(e.qvalue)}${e.kernel>0?` · template ${e.kernel+1}`:""}`}function qd(e,t){const n=e.map(u=>u.score).filter(u=>Number.isFinite(u)),s=Math.min(...n),o=Math.max(...n),r=Math.max(10,Math.min(50,Math.round(Math.sqrt(n.length)*2))),i=o>s?(o-s)/r:1,a=new Float64Array(r);for(const u of n){const l=i>0?Math.min(r-1,Math.floor((u-s)/i)):0;a[l]++}const c=new Float64Array(r);for(let u=0;u<r;u++)c[u]=s+i*(u+.5);return{kind:"curve",id:"chromosight-spectrum",label:`Score spectrum · ${t.name.replace(/_/g," ")}`,series:[{name:"Calls",x:c,y:a,n:n.length}],xLabel:"Pearson correlation with the template",yLabel:"Calls",xScale:"linear",yScale:"linear"}}function Ud(e,t){const n=[...e].sort((s,o)=>o.score-s.score).slice(0,Td).map(s=>({sequence:s.unit.name,start1:(s.bin1-s.unit.span.from)*t,start2:(s.bin2-s.unit.span.from)*t,separation:Math.abs(s.bin2-s.bin1)*t,score:s.score,pvalue:s.pvalue,qvalue:s.qvalue}));return{kind:"table",id:"chromosight-table",label:n.length<e.length?`Strongest ${n.length} of ${e.length}`:"Patterns",columns:[{key:"sequence",label:"Sequence",kind:"text"},{key:"start1",label:"Start 1",kind:"number",coordinate:"start"},{key:"start2",label:"Start 2",kind:"number",coordinate:"start"},{key:"separation",label:"Separation (bp)",kind:"number",digits:0},{key:"score",label:"Score",kind:"number",digits:4,hint:"Pearson r with the template."},{key:"pvalue",label:"p",kind:"number",digits:6},{key:"qvalue",label:"q",kind:"number",digits:6,hint:"Benjamini-Hochberg."}],rows:n}}function Gd(e){const t=e.filter(s=>Number.isFinite(s)).sort((s,o)=>s-o);if(t.length===0)return Number.NaN;const n=t.length>>1;return t.length%2===1?t[n]:(t[n-1]+t[n])/2}function Ka(e){return Number.isFinite(e)?e===0?"0":e<1e-4?e.toExponential(2):e.toFixed(6):"n/a"}const Hd=8e6;class Qd{constructor(t){this.nContigs=t,this.cis=new Float64Array(t),this.trans=new Float64Array(t)}cis;trans;transTotal=0;dropped=0;pairsOverflowed=!1;between=new Map;add(t,n,s){if(!Number.isFinite(s))return;if(t<0||n<0){this.dropped+=s;return}if(t===n){this.cis[t]+=s;return}this.trans[t]+=s,this.trans[n]+=s,this.transTotal+=s;const o=t<n?t:n,r=t<n?n:t,i=o*this.nContigs+r,a=this.between.get(i);a!==void 0?this.between.set(i,a+s):this.between.size<Hd?this.between.set(i,s):this.pairsOverflowed=!0}pair(t,n){if(t===n)return this.cis[t];const s=t<n?t:n,o=t<n?n:t;return this.between.get(s*this.nContigs+o)??0}*pairs(){for(const[t,n]of this.between){const s=Math.floor(t/this.nContigs);yield[s,t-s*this.nContigs,n]}}}function Kd(e,t){if(!(t>0))return()=>Number.NaN;let n=0;for(let r=0;r<e.length;r++)n+=e[r]*e[r];const s=4*t*t-n,o=s>0?4*t*t/s:1;return(r,i)=>o*e[r]*e[i]/(2*t)}const Wa=512,Wd=async e=>{const t=e.mc,n=nt(e.params,"balance",!1),s=ee(t,n),o=[];for(let A=0;A<t.nContigs;A++){const[N,I]=t.contigExtent(A);o.push({startBin:N,bins:Math.max(0,I-N)})}const r=eo(o,t.nBins),i=new Qd(t.nContigs),a=te(e.params,"sequences");if(a!==null&&a.length===0)return e.note("No sequence is ticked, so there is nothing to report."),[];const c=e.inputs.block;if(c!==void 0&&c.binsPerCell===1&&e.framing.balance===n&&c.rowExtent[0]===0&&c.rowExtent[1]===t.nBins&&c.colExtent[0]===0&&c.colExtent[1]===t.nBins&&c!==void 0){e.progress(0,1,"summing the block on screen");for(let A=0;A<c.nrows;A++){e.throwIfCancelled();const N=A*c.ncols;for(let I=A;I<c.ncols;I++){const M=c.values[N+I];M!==0&&i.add(r[A],r[I],M)}}}else e.framing.value!==""&&e.framing.value!==j&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${j}. These numbers are of the counts.`),e.progress(0,1,"reading pixels"),await t.scanPixels({onChunk:A=>{e.throwIfCancelled();for(let N=0;N<A.length;N++){const I=A.bin1[N],M=A.bin2[N],x=A.count[N];i.add(r[I],r[M],s===null?x:x*s[I]*s[M])}return!0},onProgress:(A,N)=>e.progress(A,N,"reading pixels")});e.throwIfCancelled(),i.pairsOverflowed&&e.note("This file has more sequence pairs with contact than the pair table holds, so the ranked list below is of the pairs seen first rather than of the strongest. The per-sequence rows are unaffected. Tick fewer sequences."),i.dropped>0&&e.note(`${Math.round(i.dropped).toLocaleString()} contacts have an end outside every sequence and are left out. A bin belonging to no contig means the bin table and the contig table disagree about this file.`);let l;if(a===null)l=o.map((A,N)=>N);else{const A=Xs(t,a),N=be(t,A.missing,A.ids.length);N!==null&&e.note(N),l=A.ids}if(l.length===0)return[];const h=l.map(A=>{const N=i.cis[A],I=i.trans[A],M=N+I;return{sequence:t.chromnames[A],bins:o[A].bins,cis:N,trans:I,total:M,fraction:M>0?N/M:Number.NaN,ratio:N>0?I/N:Number.NaN,perBin:o[A].bins>0?M/o[A].bins:Number.NaN}}),f=[{kind:"table",id:"cistrans",label:"Cis and trans per sequence",columns:[{key:"sequence",label:"Sequence",kind:"text"},{key:"bins",label:"Bins",kind:"number",digits:0},{key:"cis",label:"Cis",kind:"number",digits:0},{key:"trans",label:"Trans",kind:"number",digits:0},{key:"total",label:"Total",kind:"number",digits:0},{key:"fraction",label:"Cis fraction",kind:"number",digits:3,hint:"Of the contacts touching this sequence, how many stay on it."},{key:"ratio",label:"Trans / cis",kind:"number",digits:3},{key:"perBin",label:"Contacts per bin",kind:"number",digits:2}],rows:h},Yd(h,ct(e.params,"bars","cis"))],d=ct(e.params,"normalise","enrichment"),m=Math.max(0,Q(e.params,"minContacts",10)),g=Math.max(10,Math.round(Q(e.params,"maxEdges",500))),p=Kd(i.trans,i.transTotal),w=(A,N,I)=>{if(d==="raw")return I;if(d==="bins"){const x=o[A].bins*o[N].bins;return x>0?I/x:Number.NaN}const M=p(A,N);return M>0?I/M:Number.NaN},b=new Set(l),y=[];for(const[A,N,I]of i.pairs()){if(!b.has(A)||!b.has(N)||I<m)continue;const M=w(A,N,I);Number.isFinite(M)&&y.push({a:t.chromnames[A],b:t.chromnames[N],raw:I,value:M,expected:p(A,N)})}if(y.sort((A,N)=>N.value-A.value),y.length>0&&(f.push({kind:"table",id:"cistrans-pairs",label:d==="enrichment"?"Sequence pairs, against indifference":"Sequence pairs, ranked",columns:[{key:"a",label:"Sequence",kind:"text"},{key:"b",label:"Sequence",kind:"text"},{key:"raw",label:"Contacts",kind:"number",digits:0},...d==="enrichment"?[{key:"expected",label:"Expected",kind:"number",digits:1,hint:"From the two sequences’ own trans coverage, under indifference."}]:[],{key:"value",label:d==="raw"?"Contacts":d==="bins"?"Per bin pair":"Observed / expected",kind:"number",digits:d==="raw"?0:d==="bins"?5:2}],rows:y.slice(0,g)}),y.length>g&&e.note(`${y.length.toLocaleString()} sequence pairs pass the threshold and the strongest ${g.toLocaleString()} are listed. Raise “pairs to list” to see more.`)),nt(e.params,"matrix",!0))if(l.length>Wa)e.note(`${l.length.toLocaleString()} sequences is past the ${Wa.toLocaleString()} this draws a square for, so the ranked table above is the answer. Tick fewer sequences for the picture.`);else{const A=l.length,N=new Float32Array(A*A);for(let M=0;M<A;M++)for(let x=0;x<A;x++){const v=l[M],S=l[x];N[M*A+x]=v===S?Number.NaN:w(v,S,i.pair(v,S))}const I=A<=40?l.map(M=>t.chromnames[M]):[];f.push({kind:"matrix",id:"cistrans-matrix",label:d==="enrichment"?"Between sequences, against indifference":"Between sequences",nrows:A,ncols:A,values:N,xLabel:"Sequence",yLabel:"Sequence",xTicks:I,yTicks:I,colormap:d==="enrichment"?"RdBu_r":"default",...d==="enrichment"?{centre:1}:{}})}return f},Ya="contacts";function Yd(e,t){const n=(a,c)=>c>0?a/c:Number.NaN,s=Float64Array.from(e,(a,c)=>c),o=t==="both",r={name:"cis",x:s,y:Float64Array.from(e,a=>n(a.cis,a.total)),mark:"bars",...o?{stack:Ya}:{}},i={name:"trans",x:s,y:Float64Array.from(e,a=>n(a.trans,a.total)),mark:"bars",...o?{stack:Ya}:{}};return{kind:"curve",id:"cistrans-fractions",label:o?"Cis and trans fraction per sequence":t==="trans"?"Trans fraction per sequence":"Cis fraction per sequence",series:o?[r,i]:[t==="trans"?i:r],xLabel:"Sequence",yLabel:"Share of the sequence’s contacts (%)",xScale:"linear",yScale:"linear",yDomain:[0,1],xTicks:e.map(a=>a.sequence)}}function si(e){const{n:t,origin:n,circular:s}=e,o=new Int32Array(t),r=Math.floor(t/2);for(let i=0;i<t;i++){const a=i-n;o[i]=s?((a+r)%t+t)%t-r:a}return o}function oi(e){let t=0;for(let n=0;n<e.length;n++)t=Math.max(t,Math.abs(e[n]));return t}function K0(e,t,n,s,o){const r=si(s),i=t.length,a=n.length,c=oi(r),u=c+1,l=2*c+1,h=!(o>0),f=h?l:Math.max(1,Math.floor(o/4)),d=Math.ceil(l/f),m=h?d:Math.max(1,Math.ceil(o/f)),g=[new Float64Array(u*d),new Float64Array(u*d)],p=[new Float64Array(u*d),new Float64Array(u*d)],w=(A,N)=>{const I=r[t[A]],M=r[n[N]],x=Math.abs(I),v=Math.abs(M);return{kind:I>=0==M>=0?0:1,delta:Math.abs(x-v),slot:Math.floor((x+v)/f)}};for(let A=0;A<i;A++)for(let N=0;N<a;N++){const I=e[A*a+N];if(!Number.isFinite(I))continue;const{kind:M,delta:x,slot:v}=w(A,N),S=x*d+v;g[M][S]+=I,p[M][S]+=1}const b=[new Float64Array(u*d),new Float64Array(u*d)];for(let A=0;A<2;A++){const N=new Float64Array(d+1),I=new Float64Array(d+1);for(let M=0;M<u;M++){const x=M*d;for(let v=0;v<d;v++)N[v+1]=N[v]+g[A][x+v],I[v+1]=I[v]+p[A][x+v];for(let v=0;v<d;v++){const S=Math.max(0,v-m),k=Math.min(d,v+m+1),C=I[k]-I[S];b[A][x+v]=C>0?(N[k]-N[S])/C:Number.NaN}}}const y=new Float64Array(i*a);for(let A=0;A<i;A++)for(let N=0;N<a;N++){const{kind:I,delta:M,slot:x}=w(A,N);y[A*a+N]=b[I][M*d+x]}return y}function Vd(e,t){const{n}=t,s=si(t),o=oi(s),r=()=>({maxOffset:o,sum:new Float64Array(o+1),count:new Float64Array(o+1),mean:new Float64Array(o+1)}),i=r(),a=r();for(let c=0;c<n;c++){const u=s[c],l=Math.abs(u);for(let h=0;h<n;h++){const f=e[c*n+h];if(!Number.isFinite(f))continue;const d=s[h],m=u>=0==d>=0?i:a,g=Math.abs(l-Math.abs(d));m.sum[g]+=f,m.count[g]+=1}}for(const c of[i,a])for(let u=0;u<=o;u++)c.mean[u]=c.count[u]>0?c.sum[u]/c.count[u]:Number.NaN;return{within:i,across:a}}function Va(e,t,n){const{n:s,circular:o}=t,r=si(t),i=Math.max(0,Math.round(n)),a=2*i+2,c=oi(r)+1,u=new Float64Array(c),l=new Float64Array(c),h=new Float64Array(s),f=new Float64Array(s);for(let g=0;g<s;g++){const p=r[g],w=Math.abs(p);for(let b=0;b<s;b++){const y=r[b];if(p>=0==y>=0)continue;const A=Math.abs(y);if(Math.abs(w-A)>i)continue;const N=Math.abs(g-b);if((o?Math.min(N,s-N):N)<a)continue;const I=e[g*s+b];if(!Number.isFinite(I))continue;const M=Math.min(c-1,Math.round((w+A)/2));u[M]+=I,l[M]+=1,h[g]+=I,f[g]+=1}}const d=new Float64Array(c);for(let g=0;g<c;g++)d[g]=l[g]>0?u[g]/l[g]:Number.NaN;const m=new Float64Array(s);for(let g=0;g<s;g++)m[g]=f[g]>0?h[g]/f[g]:Number.NaN;return{byDistance:d,byBin:m}}const Xd=.02,Jd=.2;function Xa(e,t){let n=0;const s=e.length,o=new Float64Array(s);for(let m=0;m<s;m++){const g=e[m];o[m]=g>0?Math.log2(g):Number.NaN,Number.isFinite(o[m])&&n++}if(n===0)return{score:Number.NaN,reach:Number.NaN,peak:Number.NaN};const r=Math.max(1,Math.round(s*Xd)),i=new Float64Array(s).fill(Number.NaN);let a=Number.NEGATIVE_INFINITY,c=-1;for(let m=0;m<s;m++){let g=0,p=0;for(let w=Math.max(0,m-r);w<=Math.min(s-1,m+r);w++)Number.isFinite(o[w])&&(g+=o[w],p++);p!==0&&(i[m]=g/p,i[m]>a&&(a=i[m],c=m))}let u=Number.NaN;if(a>0){u=c;for(let m=c+1;m<s;m++)if(Number.isFinite(i[m])){if(i[m]<a*Jd)break;u=m}}const l=t===void 0?u:t,h=Number.isFinite(l)?Math.min(s-1,Math.max(0,Math.floor(l))):s-1;let f=0,d=0;for(let m=0;m<=h;m++)Number.isFinite(o[m])&&(f+=o[m],d++);return{score:d>0?f/d:Number.NaN,reach:u,peak:a}}function Zd(e,t,n,s={}){const o=s.iterations??512,r=s.tolerance??1e-12,i=[];if(t===0)return i;for(let a=0;a<n;a++){const c=W0(e,t,o,r,a);if(c===null)break;i.push(c),Y0(e,t,c)}return i}function W0(e,t,n,s,o){const r=Xr(24301+o),i=new Float64Array(t);for(let p=0;p<t;p++)i[p]=r()*2-1;if(!Ja(i))return null;const a=Math.max(1,Math.min(t,n)),c=[i],u=new Float64Array(a),l=new Float64Array(a),h=new Float64Array(t);let f=0,d=null;for(let p=0;p<a;p++){V0(e,t,c[p],h);let w=0;for(let M=0;M<2;M++)for(let x=0;x<=p;x++){const v=c[x];let S=0;for(let k=0;k<t;k++)S+=v[k]*h[k];for(let k=0;k<t;k++)h[k]-=S*v[k];x===p&&(w+=S)}let b=0;for(let M=0;M<t;M++)b+=h[M]*h[M];if(b=Math.sqrt(b),!Number.isFinite(w)||!Number.isFinite(b))return null;u[p]=w,f=Math.max(f,Math.abs(w)+b+(p>0?l[p-1]:0));const y=p+1,N=!(b>f*1e-14)||y===a;if(N||y<=16||y%Math.ceil(y/8)===0){if(d=jd(u,l,y),d===null)return null;if(N||b*Math.abs(d.coefficients[y-1])<=s*Math.abs(d.value))break}l[p]=b;const I=new Float64Array(t);for(let M=0;M<t;M++)I[M]=h[M]/b;c.push(I)}if(d===null)return null;const m=new Float64Array(t),{coefficients:g}=d;for(let p=0;p<g.length;p++){const w=g[p],b=c[p];for(let y=0;y<t;y++)m[y]+=w*b[y]}return Ja(m)?{value:d.value,vector:m}:null}function jd(e,t,n){const s=e.slice(0,n),o=new Float64Array(n);for(let l=0;l+1<n;l++)o[l]=t[l];const r=new Float64Array(n*n);for(let l=0;l<n;l++)r[l*n+l]=1;let i=0,a=0;const c=2**-52;for(let l=0;l<n;l++){a=Math.max(a,Math.abs(s[l])+Math.abs(o[l]));let h=l;for(;h<n-1&&!(Math.abs(o[h])<=c*a);)h++;if(h>l){let f=0;do{if(++f>64)return null;let d=s[l],m=(s[l+1]-d)/(2*o[l]),g=Math.hypot(m,1);m<0&&(g=-g),s[l]=o[l]/(m+g),s[l+1]=o[l]*(m+g);const p=s[l+1];let w=d-s[l];for(let x=l+2;x<n;x++)s[x]-=w;i+=w,m=s[h];let b=1,y=b,A=b;const N=o[l+1];let I=0,M=0;for(let x=h-1;x>=l;x--){A=y,y=b,M=I,d=b*o[x],w=b*m,g=Math.hypot(m,o[x]),o[x+1]=I*g,I=o[x]/g,b=m/g,m=b*s[x]-I*d,s[x+1]=w+I*(b*d+I*s[x]);const v=x*n,S=(x+1)*n;for(let k=0;k<n;k++)w=r[S+k],r[S+k]=I*r[v+k]+b*w,r[v+k]=b*r[v+k]-I*w}m=-I*M*A*N*o[l]/p,o[l]=I*m,s[l]=b*m}while(Math.abs(o[l])>c*a)}s[l]+=i,o[l]=0}let u=0;for(let l=1;l<n;l++)Math.abs(s[l])>Math.abs(s[u])&&(u=l);return Number.isFinite(s[u])?{value:s[u],coefficients:r.slice(u*n,u*n+n)}:null}function Y0(e,t,n){const{value:s,vector:o}=n;for(let r=0;r<t;r++){const i=s*o[r];for(let a=0;a<t;a++)e[r*t+a]-=i*o[a]}}function V0(e,t,n,s){s.fill(0);let o=0;for(;o+3<t;o+=4){const r=o*t,i=r+t,a=i+t,c=a+t,u=n[o],l=n[o+1],h=n[o+2],f=n[o+3],d=e[r+o+1],m=e[r+o+2],g=e[r+o+3],p=e[i+o+2],w=e[i+o+3],b=e[a+o+3];let y=e[r+o]*u+d*l+m*h+g*f,A=d*u+e[i+o+1]*l+p*h+w*f,N=m*u+p*l+e[a+o+2]*h+b*f,I=g*u+w*l+b*h+e[c+o+3]*f;for(let M=o+4;M<t;M++){const x=e[r+M],v=e[i+M],S=e[a+M],k=e[c+M],C=n[M];y+=x*C,A+=v*C,N+=S*C,I+=k*C,s[M]+=x*u+v*l+S*h+k*f}s[o]+=y,s[o+1]+=A,s[o+2]+=N,s[o+3]+=I}for(;o<t;o++){const r=o*t,i=n[o];let a=e[r+o]*i;for(let c=o+1;c<t;c++){const u=e[r+c];a+=u*n[c],s[c]+=u*i}s[o]+=a}}function Ja(e){let t=0;for(const s of e)t+=s*s;const n=Math.sqrt(t);if(!(n>0))return!1;for(let s=0;s<e.length;s++)e[s]/=n;return!0}function t8(e,t){if(t<2)return null;const n=new Float64Array(t);for(let l=0;l<t;l++){let h=0;for(let f=0;f<t;f++){const d=e[l*t+f];Number.isFinite(d)&&(h+=d)}n[l]=h}let s=0;for(const l of n)l>s&&(s=l);if(s*=2,!(s>0))return null;const o=new Float64Array(t*t);for(let l=0;l<t;l++)for(let h=0;h<t;h++){const f=Number.isFinite(e[l*t+h])?e[l*t+h]:0,d=l===h?n[l]-f:-f;o[l*t+h]=(l===h?s:0)-d}const r=new Float64Array(t).fill(1/Math.sqrt(t));let i=0;{const l=new Float64Array(t);V0(o,t,r,l);for(let h=0;h<t;h++)i+=r[h]*l[h]}Y0(o,t,{value:i,vector:r});const a=W0(o,t,512,1e-9,0);if(a===null)return null;const c=new Int8Array(t);for(let l=0;l<t;l++)c[l]=a.vector[l]>=0?1:-1;let u=0;for(const l of c)l===1&&u++;return u===0||u===t?null:{side:c,value:s-a.value}}const _s=8192,e8=.1;function Za(e,t){const{ids:n}=Xs(e.mc,t,Ee(t)),s=[];for(const u of n){const[l,h]=e.mc.contigExtent(u);h>l&&s.push(u)}let o=0;const r=[],i=[];for(let u=0;u<s.length;u++){const[l,h]=e.mc.contigExtent(s[u]);for(let f=l;f<h;f++)r.push(f),i.push(u);o+=h-l}const a=[],c=[];for(let u=0;u<r.length;u++){const l=a[a.length-1];if(l!==void 0&&r[u]===l.to){l.to++;continue}c.push(u),a.push({from:r[u],to:r[u]+1})}return{contigs:s,spans:a,spanAt:c,bin:Int32Array.from(r),group:Int32Array.from(i),n:o}}async function n8(e,t,n){const{spans:s,spanAt:o,n:r}=t,i=new Float32Array(r*r).fill(Number.NaN),a=Ft(e,s,n.balance),c=s.length*(s.length+1)/2;let u=0;const l=(h,f,d,m)=>{const g=s[d].to-s[d].from,p=s[m].to-s[m].from,w=o[d],b=o[m];for(let y=0;y<g;y++)for(let A=0;A<p;A++){const N=h[y*f+A];i[(w+y)*r+b+A]=N,i[(b+A)*r+w+y]=N}};for(let h=0;h<s.length;h++)for(let f=h;f<s.length;f++){if(e.throwIfCancelled(),e.progress(u,c,"reading"),u++,a!==null){const m=s[h].from-a.rowExtent[0],g=s[f].from-a.colExtent[0],p=s[h].to-s[h].from,w=s[f].to-s[f].from,b=new Float32Array(p*w);for(let y=0;y<p;y++){const A=(m+y)*a.ncols+g;b.set(a.values.subarray(A,A+w),y*w)}l(b,w,h,f);continue}const d=await e.mc.matrix({rows:[s[h].from,s[h].to],cols:[s[f].from,s[f].to],balance:n.balance,value:n.value});l(d.values,d.ncols,h,f)}return i}function s8(e,t,n){const{group:s,n:o}=t,r=t.contigs.length,i=[],a=[];for(let l=0;l<r;l++)i.push(s.indexOf(l)),a.push(s.lastIndexOf(l)+1);const c=i.map((l,h)=>{const f=a[h]-l,d=n[h],m=new Fn(d>0?Math.floor(f/2):Math.max(0,f-1),d);for(let g=l;g<a[h];g++)for(let p=l;p<a[h];p++)m.add(_n(Math.abs(p-g),d),e[g*o+p]);return m.finish()}),u=new Float64Array(r*r).fill(Number.NaN);for(let l=0;l<r;l++)for(let h=l+1;h<r;h++){let f=0,d=0;for(let g=i[l];g<a[l];g++)for(let p=i[h];p<a[h];p++){const w=e[g*o+p];Number.isFinite(w)&&(f+=w,d++)}const m=d===0?Number.NaN:f/d;u[l*r+h]=m,u[h*r+l]=m}return{group:s,cis:c,trans:u,contacts:"both",ignoreDiags:0,...n.some(l=>l>0)?{laps:n}:{}}}function o8(e,t){const n=new Int32Array(t.contigs.length);for(let s=0;s<t.contigs.length;s++){const o=t.contigs[s];if(!Te(e,e.mc.chromnames[o]))continue;const[r,i]=e.mc.contigExtent(o);n[s]=i-r}return n}function r8(e,t,n,s,o,r){const i=Int32Array.from({length:t},(h,f)=>f),a=K0(e,i,i,s,o),c=n.length,u=s.circular?t:0,l=new Float64Array(c*c);for(let h=0;h<c;h++){const f=n[h];for(let d=0;d<c;d++){const m=n[d];if(_n(Math.abs(m-f),u)<r){l[h*c+d]=Number.NaN;continue}const g=e[f*t+m],p=a[f*t+m];l[h*c+d]=Number.isFinite(g)&&Number.isFinite(p)&&p!==0?g/p:Number.NaN}}return l}function i8(e,t,n,s){const o=t.contigs[0],r=e.mc.chromnames[o],i=b0(e,r),a=e.mc.binsize;i===void 0&&e.note(`${s}: the arms were read from the first base, the origin every sequence has until one is set — on the Chromosomes table, or by Origin and terminus.`);const c=i??0,u=Math.max(0,Math.min(t.n-1,Math.floor(c/a)));return e.note(`${s}: arms read from the origin at ${(c+1).toLocaleString()} (bin ${u.toLocaleString()}), ${n[0]>0?"round the circle":"along the line"}.`),{n:t.n,origin:u,circular:n[0]>0}}function a8(e){const t=e.contacts;return t==="trans"||t==="both"?t:"cis"}async function c8(e,t,n){const{label:s}=n,o=nt(e.params,"balance",!0),r=e.framing.value===""?j:e.framing.value,i=await n8(e,t,{balance:o,value:r});e.throwIfCancelled();const a=o8(e,t),c={...s8(i,t,a),contacts:n.contacts,ignoreDiags:n.ignoreDiags},u=t0(i,t.n,e8);if(u.length<8)return e.note(`${s}: only ${u.length} bins carry enough data to correlate, which is too few for a component to mean anything.`),null;u.length<t.n&&e.note(`${s}: ${(t.n-u.length).toLocaleString()} of ${t.n.toLocaleString()} bins were left out for want of data. They are gaps in the track rather than zeros.`);const l=n.arms!==void 0&&t.contigs.length===1?r8(i,t.n,u,i8(e,t,a,s),n.arms.window,n.ignoreDiags):N4(i,t.n,u,c);e.throwIfCancelled();let h=0;for(let N=0;N<l.length;N++)Number.isFinite(l[N])&&h++;if(h===0)return e.note(`${s}: nothing was left to correlate — ${c.ignoreDiags} ignored ${c.ignoreDiags===1?"diagonal covers":"diagonals cover"} the whole of a ${t.n.toLocaleString()}-bin square. Ignore fewer.`),null;const f=n.method==="cooltools";let d,m=u.length;if(f){e.progress(n.step.at,n.step.of,`decomposing ${s}`),d=I4(l,u.length),m=0;for(let N=0;N<d.length;N++)m+=d[N]*d[N]}else d=await M4(l,u.length,async N=>{if(N%64!==0){e.throwIfCancelled();return}await e.breathe(),e.progress(n.step.at,n.step.of,`correlating ${s}`)});const g=Zd(d,u.length,n.wanted);if(g.length===0)return e.note(`${s}: the ${f?"matrix":"correlation matrix"} has no leading component; it may be too sparse.`),null;const p=f?g.map(({value:N})=>N*N/m):x4(l,u.length,g.map(N=>N.vector)),w=f8(e,t,u);let b=null;for(let N=0;N<g.length&&N<n.tracks.length;N++){const{value:I,vector:M}=g[N];if(f){const S=Math.sqrt(Math.abs(I));for(let k=0;k<M.length;k++)M[k]*=S}let x=Number.NaN;if(w!==null){const S=k4(M,w,Q(e.params,"minR",.1));x=S.flipped?-S.r:S.r,N===0&&(b=S,e.note(S.confident?`${s}: E1 phased against ${S.signal} (r = ${tc(S.r)})${S.flipped?", sign flipped":""}.`:`${s}: phasing against ${S.signal} was ambiguous (r = ${tc(S.r)}), so E1’s sign is arbitrary and should not be compared with another run.`))}else N===0&&e.note("Nothing was chosen to phase against, so the sign of each component is arbitrary.");n.rows.push({sequence:s,component:`E${N+1}`,eigenvalue:I,...f?{}:{explained:I/m},contacts:p[N],r:x});const v=n.tracks[N];for(let S=0;S<u.length;S++)v[t.bin[u[S]]]=M[S]}if(h8(e,n.segments,t,u,g[0].vector),!nt(e.params,"saddle",!0))return{saddle:null};const y=Math.max(5,Math.min(100,Math.round(Q(e.params,"quantiles",50)))),A=S4(l,u.length,g[0].vector,y);return{saddle:{kind:"matrix",id:`compartment-saddle-${s}`,label:`Saddle · ${s}`,nrows:y,ncols:y,values:A.values,xLabel:"E1 quantile",yLabel:"E1 quantile",xTicks:[],yTicks:[],colormap:nl,centre:1,stats:[{label:"AA",value:A.strength.aa,digits:2},{label:"BB",value:A.strength.bb,digits:2},{label:"AB",value:A.strength.ab,digits:2},...b===null||b.confident?[]:[{label:"phasing r",value:b.r,digits:2,hint:"Too weak to fix the sign, so AA and BB may be the wrong way round."}]]}}}const l8=async e=>{const n=te(e.params,"sequences")??to(e.mc).map(w=>e.mc.chromnames[w]);if(n.length===0)return e.note("No sequence is ticked, so there is nothing to correlate."),[];const s=Xs(e.mc,n,Ee(n)).missing;if(s.length>0&&s.length<n.length){const w=s.slice(0,6).join(", ");e.note(`${s.length} of the ${n.length} ticked ${s.length===1?"sequence is":"sequences are"} not in this file and ${s.length===1?"was":"were"} left out: ${w}${s.length>6?", …":""}.`)}const o=Za(e,n);if(o.n===0)return e.note(`None of the ${n.length} ticked ${n.length===1?"sequence":"sequences"} is in this file, under that spelling or any this viewer knows of. It has ${e.mc.chromnames.slice(0,6).join(", ")}${e.mc.chromnames.length>6?", …":""}.`),[];const r=a8(e.params);if(r==="trans"&&o.contigs.length<2)throw new Error("A trans correlation is between sequences, so it needs at least two ticked. Tick more, or read this one’s cis contacts instead.");const i=r==="cis"?o.contigs.map(w=>Za(e,[e.mc.chromnames[w]])):[o],a=Math.max(0,Math.round(Q(e.params,"ignoreDiags",2))),c=Math.max(1,Math.min(3,Math.round(Q(e.params,"components",1)))),u=[];for(let w=0;w<c;w++)u.push(new Float32Array(e.mc.nBins).fill(Number.NaN));const l=new le,h=[],f=[],d=r==="cis"&&ct(e.params,"expected","distance")==="arms"?{window:Math.max(0,Math.round(Q(e.params,"armWindow",50)))}:void 0;d!==void 0&&e.note(d.window===0?"Divided by the decay along both arms, over the whole of each chromosome.":`Divided by the decay along both arms, within ${d.window.toLocaleString()} bins (${(d.window*e.mc.binsize).toLocaleString()} bp) of each cell along them.`);const m=ct(e.params,"method","cooltools");if(m!=="correlation"&&m!=="cooltools")throw new Error(`There is no method “${m}”. It is cooltools or correlation (Lieberman-Aiden 2009).`);e.note(m==="cooltools"?`Observed/expected decomposed itself, as cooltools does: clipped at its ${Yr}th percentile, one subtracted, every gap read as expected, and each eigenvector scaled by the square root of its eigenvalue.`:"The correlation of observed/expected’s rows decomposed, as Lieberman-Aiden et al. (2009) did it.");let g=0;for(let w=0;w<i.length;w++){await e.breathe();const b=i[w],y=ja(e,b);if(b.n>_s){const N=`${y} is ${b.n.toLocaleString()} bins, past the ${_s.toLocaleString()}-bin limit on a correlation matrix`;if(i.length===1)throw new Error(`Refusing to build it: ${N}. Untick some, or open the file coarser.`);e.note(`${N}, so it was skipped. Open the file at a coarser resolution to include it.`);continue}e.progress(w,i.length,`compartments on ${y}`);const A=await c8(e,b,{contacts:r,ignoreDiags:a,wanted:c,tracks:u,segments:l,label:y,step:{at:w,of:i.length},...d===void 0?{}:{arms:d},method:m,rows:f});A!==null&&(g++,A.saddle!==null&&h.push(A.saddle))}if(g===0)return e.note("Nothing produced a component. See the notes above."),[];const p=`${ja(e,o)} · ${u8[r]}${d===void 0?"":" · arms"}${m==="correlation"?" · correlation":""}`;return h.push({kind:"table",id:"compartment-components",label:`Components · ${p}`,columns:[{key:"sequence",label:"sequence",kind:"text"},{key:"component",label:"component",kind:"text",hint:"By eigenvalue, largest first."},{key:"eigenvalue",label:"eigenvalue",kind:"number",digits:3},...m==="cooltools"?[]:[{key:"explained",label:"variance",kind:"number",digits:3,hint:"Share of the correlation matrix’s variance — how alike the rows are, not how much of the map: its eigenvalue over its rows."}],{key:"contacts",label:"of contacts",kind:"number",digits:3,hint:"How much of the contacts this component accounts for: the share of the map’s departure from expected — observed/expected, clipped, less one — that its checkerboard carries. The same measure under either method, and the components’ shares add up."},{key:"r",label:"r with phasing",kind:"number",digits:3,hint:"Pearson’s r with the phasing signal, as drawn: positive once the sign is fixed."}],rows:f}),h.unshift(...u.map((w,b)=>({kind:"profile",id:`compartment-e${b+1}`,label:`E${b+1} · ${p}`,values:w,extent:[0,e.mc.nBins],binsize:e.mc.binsize,unit:""})),{kind:"intervals",id:"compartment-ab",label:`A/B compartments · ${p}`,payload:{kind:"features",data:l.finish()},noun:{one:"segment",many:"segments"},lane:{under:{output:"compartment-e1"}},display:"lane",look:"corner"}),e.progress(i.length,i.length,"done"),h},u8={cis:"cis",trans:"trans",both:"cis + trans"};function ja(e,t){const n=t.contigs.length;if(n===1)return e.mc.chromnames[t.contigs[0]];const s=e.mc.chromnames.length;return n===s?"genome-wide":`${n.toLocaleString()} of ${s.toLocaleString()} sequences`}function tc(e){return Number.isFinite(e)?e.toFixed(3):"—"}function h8(e,t,n,s,o){const r=e.mc.binsize;for(let i=0;i<n.contigs.length;i++){const a=n.contigs[i],c=e.mc.chromnames[a],[u]=e.mc.contigExtent(a),l=e.mc.chromsizes.get(c)??Number.POSITIVE_INFINITY,h=[],f=[];for(let d=0;d<s.length;d++)n.group[s[d]]===i&&(h.push(n.bin[s[d]]),f.push(o[d]));if(h.length!==0)for(const d of C4(Int32Array.from(h),Float64Array.from(f)))t.add(c,(d.from-u)*r,Math.min(l,(d.to-u+1)*r),{name:d.side,score:d.mean,detail:`E1 mean ${d.mean.toFixed(3)} · ${d.bins} bins`})}}function f8(e,t,n){const s=Ts(e.inputs.features,e.params,"phaseFeatures").value;if(s!==void 0)return{name:"gene density",values:d8(e,s,t,n)};const o=Bs(e.params,"phaseTrack");if(o!==null){const c=e.inputs.vectors?.phaseTrack;if(c===void 0)e.note("The track chosen for phasing could not be read, so it was not used. Load it again, or choose another.");else{const u=new Float64Array(n.length);for(let l=0;l<n.length;l++){const h=t.bin[n[l]];u[l]=h>=0&&h<c.length?c[h]:Number.NaN}return{name:e.inputs.labels?.[o]??"the chosen track",values:u}}}if(Bs(e.params,"phaseSequence")===null)return null;const i=e.inputs.vectors?.phaseSequence;if(i===void 0)return e.note("The sequence chosen for phasing could not be read, so the sign was left alone. Re-open the FASTA, or choose a gene model instead."),null;const a=new Float64Array(n.length);for(let c=0;c<n.length;c++){const u=t.bin[n[c]];a[c]=u>=0&&u<i.length?i[u]:Number.NaN}return{name:"GC content",values:a}}function d8(e,t,n,s){const o=new Float64Array(e.mc.nBins);for(const i of n.contigs){const a=e.mc.chromnames[i],c=t.contigs.indexOf(a);if(!(c<0))for(let u=0;u<t.length;u++){if(t.contig[u]!==c)continue;const l=e.mc.coords.binIndex(i,t.start[u]),h=e.mc.coords.binIndex(i,Math.max(t.start[u],t.end[u]-1));for(let f=l;f<=h;f++)f>=0&&f<o.length&&(o[f]+=1)}}const r=new Float64Array(s.length);for(let i=0;i<s.length;i++)r[i]=o[n.bin[s[i]]];return r}function m8(e,t){const n=Math.max(1,Math.trunc(e)),s=Math.max(0,Math.trunc(t));let o=0;for(let r=0;r<n;r++)for(let i=0;i<n;i++)r+i>=s&&o++;return o}function g8(e,t){const{size:n,values:s}=e,o=Math.max(1,Math.trunc(t.window)),r=Math.max(0,Math.trunc(t.ignoreDiags??0)),i=new Float64Array(n),a=new Float64Array(n);for(let c=0;c<n;c++){let u=0,l=0;for(let h=0;h<o&&c-h>=0;h++){const f=(c-h)*n;for(let d=Math.max(0,r-h);d<o&&c+d<n;d++){const m=s[f+c+d];Number.isNaN(m)||(u+=m,l++)}}i[c]=u,a[c]=l}return{sums:i,counts:a}}function p8(e,t){const n=e.n,s=Math.max(1,Math.trunc(t.window)),o=Math.max(0,Math.trunc(t.ignoreDiags??0)),r=new Float64Array(n),i=new Float64Array(n);for(let a=0;a<n;a++){let c=0,u=0;for(let l=0;l<s;l++)for(let h=Math.max(0,o-l);h<s;h++){const f=e.forward(a-l,l+h);Number.isFinite(f)&&(c+=f,u++)}r[a]=c,i[a]=u}return{sums:r,counts:i}}function w8(e){const t=e.sums.length,n=new Float64Array(t).fill(Number.NaN),s=[];for(let i=0;i<t;i++)e.counts[i]>0&&(n[i]=e.sums[i]/e.counts[i],s.push(n[i]));const o=new Float64Array(t).fill(Number.NaN),r=b8(s);if(!(r>0))return o;for(let i=0;i<t;i++){const a=Math.log2(n[i]/r);Number.isFinite(a)&&(o[i]=a)}return o}function b8(e){if(e.length===0)return Number.NaN;const t=Float64Array.from(e).sort(),n=t.length>>1;return t.length%2===1?t[n]:(t[n-1]+t[n])/2}function A8(e){const t=e.length,n=[];for(let c=0;c<t;c++)Number.isNaN(e[c])||n.push(c);const s=[],o=[];for(let c=1;c<n.length-1;c++){const u=e[n[c-1]],l=e[n[c]],h=e[n[c+1]];u>l&&l<h&&s.push(n[c]),u<l&&l>h&&o.push(n[c])}const r=[],i=[];for(const c of o){const u=e[c];let l=-1;for(let m=c-1;m>=0;m--)if(e[m]>u){l=m;break}let h=-1;for(let m=c+1;m<t;m++)if(e[m]>u){h=m;break}const f=l>=0?u-Po(e,l,c):Number.NaN,d=h>=0?u-Po(e,c,h):Number.NaN;r.push(y8(f,d)),i.push(l<0&&h<0)}const a=i.indexOf(!0);if(a>=0){const c=o[a];let u=Number.POSITIVE_INFINITY;for(const l of s)u=Math.min(u,e[l]);r[a]=e[c]-(s.length>0?u:Po(e,0,t))}return{positions:o,prominences:r}}function Po(e,t,n){let s=Number.NaN;for(let o=t;o<n;o++){const r=e[o];Number.isNaN(r)||(Number.isNaN(s)||r<s)&&(s=r)}return s}function y8(e,t){return Number.isNaN(e)?t:Number.isNaN(t)?e:Math.min(e,t)}function N8(e,t,n){const s=[];for(let c=0;c<e.length;c++)t[c]>=n.minCells&&s.push(c);const o=s.map(c=>-e[c]),{positions:r,prominences:i}=A8(o),a=[];for(let c=0;c<r.length;c++){const u=i[c];if(!(u>=n.threshold))continue;const l=s[r[c]];a.push({bin:l,score:e[l],prominence:u})}return M8(a,n.spacing)}function M8(e,t){if(t<=1)return[...e].sort((o,r)=>o.bin-r.bin);const n=[...e].sort((o,r)=>r.prominence-o.prominence),s=[];for(const o of n)s.some(r=>Math.abs(r.bin-o.bin)<t)||s.push(o);return s.sort((o,r)=>o.bin-r.bin)}function I8(e,t){const n=[],s=e.length;for(let r=0;r<s;r++){const i=e[r];if(!Number.isFinite(i))continue;const a=x8(e,r),c=v8(e,r),u=a<0?Number.POSITIVE_INFINITY:e[a],l=c<0?Number.POSITIVE_INFINITY:e[c];if(i>u||i>l||i===u&&i===l||i===u)continue;const h=Math.min(ec(e,r,-1),ec(e,r,1));h>=t.prominence&&n.push({bin:r,score:i,prominence:h})}n.sort((r,i)=>i.prominence-r.prominence);const o=[];for(const r of n)o.some(i=>Math.abs(i.bin-r.bin)<t.spacing)||o.push(r);return o.sort((r,i)=>r.bin-i.bin),o}function X0(e){const t=[...e].sort((s,o)=>s.bin-o.bin),n=[];for(let s=1;s<t.length;s++){const o=t[s-1],r=t[s];r.bin<=o.bin||n.push({from:o.bin,to:r.bin,strength:Math.min(o.prominence,r.prominence)})}return n}function ec(e,t,n){const s=e[t];let o=s;for(let r=t+n;r>=0&&r<e.length;r+=n){const i=e[r];if(!Number.isFinite(i)||i<s)break;i>o&&(o=i)}return o-s}function x8(e,t){for(let n=t-1;n>=0;n--)if(Number.isFinite(e[n]))return n;return-1}function v8(e,t){for(let n=t+1;n<e.length;n++)if(Number.isFinite(e[n]))return n;return-1}function k8(e,t){const n=e.n,s=Math.max(1,Math.trunc(t.window)),o=Math.max(0,Math.trunc(t.ignoreDiags??0)),r=Math.max(1,o),i=new Float64Array(n).fill(Number.NaN);if(s<r)return i;const a=s-r+1,c=Math.max(1,Math.ceil(a*Math.max(0,Math.min(1,t.minValid))));for(let u=0;u<n;u++){let l=0,h=0,f=0,d=0;for(let w=r;w<=s;w++){const b=e.forward(u,w);Number.isFinite(b)&&(h+=b,d++);const y=e.forward(u-w,w);Number.isFinite(y)&&(l+=y,f++)}if(f<c||d<c)continue;const m=l+h;if(!(m>0))continue;const g=l-h,p=g*g/m;i[u]=h>=l?p:-p}return i}function S8(e){const t=e.length,n=new Float64Array(t).fill(Number.NaN),s=[];for(let i=0;i<t;i++){const a=e[i];Number.isFinite(a)&&s.push(Math.abs(a))}if(s.length===0)return n;s.sort((i,a)=>i-a);const o=s[s.length>>1];if(!(o>0))return n;let r=0;for(let i=0;i<t;i++){const a=e[i];Number.isFinite(a)&&(r+=a/o,n[i]=r)}return n}function C8(e,t){const n=e.length,s=I8(S8(e),{prominence:t.prominence,spacing:t.spacing}),o=[],r=new Set;for(const i of s){const a=i.bin+1;a>=n||r.has(a)||(r.add(a),o.push({bin:a,score:e[a],prominence:i.prominence}))}return o}const F8=50;function $8(e){const t=typeof e.window=="number"?e.window:F8;return Math.max(1,Math.round(t))}function E8(e,t){const n=e.mc,s=n.chromsizes,{ids:o,missing:r}=$e(n,t),i=[];for(const a of o){const c=Zt(n,a);if(c===null)continue;const u=n.chromnames[a];i.push({name:u,span:c,length:s.get(u)??(c.to-c.from)*n.binsize,circular:Te(e,u)})}return{units:i,missing:r}}const B8=async e=>{const t=nt(e.params,"balance",!1),n=e.framing.value===""?j:e.framing.value,s=Math.max(0,Math.min(1,Q(e.params,"minValid",.5))),o=Math.max(0,Math.round(Q(e.params,"ignoreDiags",0))),r=$8(e.params),i=r*e.mc.binsize,a=nt(e.params,"call",!0),c=Math.max(0,Q(e.params,"prominence",10)),u=Math.max(0,Math.round(Q(e.params,"spacing",0)));e.note(`A ${r.toLocaleString()}-bin window is ${kt(i)} at this file’s ${e.mc.binsize.toLocaleString()} bp resolution.`),r<5&&e.note(`Each side of the statistic is then a sum over ${r} ${r===1?"cell":"cells"} per row. Widen the window, or open a finer rung.`);const l=te(e.params,"sequences");if(l!==null&&l.length===0)return e.note("No sequence is ticked, so there is nothing to score."),[];const{units:h,missing:f}=E8(e,l),d=be(e.mc,f,h.length);if(d!==null&&e.note(d),h.length===0)return[];const m=h.filter(M=>M.span.to-M.span.from>r*2);if(m.length===0)return e.note(`No sequence in this file is longer than twice a ${r.toLocaleString()}-bin window, so no bin on any of them has a whole window either side. Use a narrower window.`),[];const g=e.mc.nBins,p=new Float32Array(g).fill(Number.NaN),w=Ft(e,m.map(M=>M.span),t);let b=0;const y=[];for(let M=0;M<m.length;M++){const x=m[M];await e.breathe(),e.progress(M,m.length,x.name),x.circular&&b++;const v=await Oe(e,x.span,{hi:r,block:w,balance:t,value:n,circular:x.circular,onTile:async(k,C)=>{await e.breathe(),e.progress(M,m.length,C===1?x.name:`${x.name} · strip ${Math.min(k+1,C)} of ${C}`)}}),S=k8(v,{window:r,minValid:s,ignoreDiags:o});for(let k=0;k<S.length;k++)p[x.span.from+k]=S[k];a&&y.push({unit:x,borders:C8(S,{prominence:c,spacing:u})})}e.progress(m.length,m.length,"done"),b>0&&e.note(`${b.toLocaleString()} of ${m.length.toLocaleString()} ${m.length===1?"sequence was":"sequences were"} read as circular, so the window wraps past the end and every bin is scored.`);const N=[{kind:"profile",id:`di-w${r}`,label:`DI · ${kt(i)}`,values:p,extent:[0,g],binsize:e.mc.binsize,unit:"signed χ²"}];if(!a)return N;const I=y.reduce((M,x)=>M+x.borders.length,0);if(I===0)return e.note(`No sign flip carried ${c} bins of steady bias on both sides, so no border was called. Lower the prominence, or widen the window.`),N;if(N.push(T8(e,y)),e.note(`${I.toLocaleString()} borders called across ${y.length.toLocaleString()} sequences.`),nt(e.params,"domains",!0)){const M=O8(e,y);M===null?e.note("No sequence had two borders, so no domain has both of its edges and none was made."):(N.push(M.output),e.note(`${M.count.toLocaleString()} domains between them, from each border to the next.`))}return N};function T8(e,t){const n=new le;let s=0;for(const{unit:o,borders:r}of t)for(const i of r){const a=i.bin*e.mc.binsize,c=Number.isFinite(i.score)?`DI ${i.score.toFixed(1)}`:"DI not scored";n.add(o.name,a,Math.min(o.length,a+e.mc.binsize),{score:i.prominence,name:`border_${++s}`,detail:`${c} · prominence ${i.prominence.toFixed(1)} bins`})}return{kind:"intervals",id:"di-borders",label:"DI borders",payload:{kind:"features",data:n.finish()},noun:{one:"border",many:"borders"},display:"lane",look:"point"}}function O8(e,t){const n=new le;let s=0;for(const{unit:o,borders:r}of t)for(const i of X0(r)){const a=i.from*e.mc.binsize,c=Math.min(o.length,i.to*e.mc.binsize);c<=a||(s++,n.add(o.name,a,c,{score:i.strength,name:`domain_${s}`,detail:`${i.to-i.from} bins · weaker border prominence ${i.strength.toFixed(1)} bins`}))}return s===0?null:{count:s,output:{kind:"intervals",id:"di-domains",label:"DI domains",payload:{kind:"features",data:n.finish()},noun:{one:"domain",many:"domains"},display:"overlay",look:"corner"}}}function J0(e,t=0){const n=Math.max(1,Math.trunc(e))-1,s=Math.max(0,Math.trunc(t));let o=0;for(let r=s;r<=n;r++)o+=r===0?1:2;return o}function L8(e,t){const n=e.n,s=Math.max(1,Math.trunc(t.diagonals))-1,o=Math.max(0,Math.trunc(t.ignoreDiags??0)),r=new Float64Array(n).fill(Number.NaN);if(n===0)return r;const i=J0(s+1,o);if(i<=0)return r;const a=Math.max(1,Math.ceil(i*Math.max(0,Math.min(1,t.minValid)))),c=e.circular?0:s,u=e.circular?n-1:n-1-s;if(u<c)return r;for(let l=c;l<=u;l++){let h=0,f=0;for(let d=o;d<=s;d++){const m=e.forward(l,d);if(Number.isFinite(m)&&(h+=m,f++),d===0)continue;const g=e.forward(l,-d);Number.isFinite(g)&&(h+=g,f++)}f>=a&&(r[l]=h/i)}return r}const _8=3;function Z0(e){const t=typeof e.diagonals=="number"?e.diagonals:_8;return Math.max(1,Math.round(t))}function D8(e){return Z0(e)-1}function R8(e,t){const n=e.mc,{ids:s,missing:o}=$e(n,t),r=[];for(const i of s){const a=Zt(n,i);if(a===null)continue;const c=n.chromnames[i];r.push({name:c,span:a,circular:Te(e,c)})}return{units:r,missing:o}}const P8=async e=>{const t=nt(e.params,"balance",!1),n=e.framing.value===""?j:e.framing.value,s=Math.max(0,Math.min(1,Q(e.params,"minValid",.5))),o=Math.max(0,Math.round(Q(e.params,"ignoreDiags",0))),r=Z0(e.params),i=D8(e.params),a=i*e.mc.binsize,c=J0(r,o),u=o>0?"less the diagonals cut below":"the main diagonal included";if(e.note(`${r.toLocaleString()} ${r===1?"diagonal reaches":"diagonals reach"} ${kt(a)} either way at this file’s ${e.mc.binsize.toLocaleString()} bp resolution, and each score is the mean of ${c.toLocaleString()} ${c===1?"cell":"cells"} — the bin’s own line across them, ${u}.`),c===0)return e.note(`Ignoring ${o.toLocaleString()} diagonals leaves nothing of a ${r.toLocaleString()}-diagonal line, so there is no cell left to average. Count more diagonals, or ignore fewer.`),[];const l=te(e.params,"sequences");if(l!==null&&l.length===0)return e.note("No sequence is ticked, so there is nothing to score."),[];const{units:h,missing:f}=R8(e,l),d=be(e.mc,f,h.length);if(d!==null&&e.note(d),h.length===0)return[];const m=h.filter(N=>N.span.to-N.span.from>2*i);if(m.length===0)return e.note(`No sequence in this file is longer than the ${(2*i+1).toLocaleString()} bins this line spans, so no bin on any of them has a whole line through it. Use fewer diagonals.`),[];const g=e.mc.nBins,p=new Float32Array(g).fill(Number.NaN),w=Ft(e,m.map(N=>N.span),t);let b=0;for(let N=0;N<m.length;N++){const I=m[N];await e.breathe(),e.progress(N,m.length,I.name),I.circular&&b++;const M=await Oe(e,I.span,{hi:i,block:w,balance:t,value:n,circular:I.circular,onTile:async(v,S)=>{await e.breathe(),e.progress(N,m.length,S===1?I.name:`${I.name} · strip ${Math.min(v+1,S)} of ${S}`)}}),x=L8(M,{diagonals:r,minValid:s,ignoreDiags:o});for(let v=0;v<x.length;v++)p[I.span.from+v]=x[v]}return e.progress(m.length,m.length,"done"),b>0&&e.note(`${b.toLocaleString()} of ${m.length.toLocaleString()} ${m.length===1?"sequence was":"sequences were"} read as circular, so the line wraps past the end and every bin is scored.`),b<m.length&&i>0&&e.note(`The first and last ${i.toLocaleString()} ${i===1?"bin":"bins"} of a linear sequence have no whole line through them and are left as gaps, rather than scored on the part of it that fits — which would fade both ends towards zero.`),[{kind:"profile",id:`hicscore-d${r}`,label:`HiC score · ${r} diag`,values:p,extent:[0,g],binsize:e.mc.binsize,unit:"contacts"}]},z8=50,Ds=new Float64Array(1),Dt=new Uint32Array(Ds.buffer),j0=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,nc=134217729;function q8(e,t){Ds[0]=e;const n=j0?0:1,s=1-n;return t?(Dt[n]=Dt[n]+1>>>0,Dt[n]===0&&(Dt[s]=Dt[s]+1>>>0)):(Dt[n]===0&&(Dt[s]=Dt[s]-1>>>0),Dt[n]=Dt[n]-1>>>0),Ds[0]}function U8(e){return Ds[0]=e,(Dt[j0?0:1]&1)===1}function Rs(e,t,n){const s=e*t;if(!Number.isFinite(s)||!Number.isFinite(n))return s+n;let o=nc*e;const r=o-(o-e),i=e-r;o=nc*t;const a=o-(o-t),c=t-a,u=r*a-s+r*c+i*a+i*c,l=n+s,h=l-n,f=n-(l-h)+(s-h);let d=f+u;const m=d-f,g=f-(d-m)+(u-m);return g!==0&&!U8(d)&&(d=q8(d,g>0==d>0)),l+d}function zo(e,t,n,s){return Rs(t,s,e*n)}function G8(e,t,n,s,o){return o===1?Rs(t,s,e*n):Rs(e,n,t*s)}function t1(e,t,n,s){return Rs(t,s,e*n)}function mr(e,t){return e*e+t*t}class Tn{n=0;ls0=0;ls1=0;ss=0;c0=0;c1=0;sqNorm=0;child=null;static of(t,n){const s=new Tn;return s.n=1,s.ls0=t,s.ls1=n,s.c0=t,s.c1=n,s.ss=s.sqNorm=zo(t,n,t,n),s}update(t){this.n+=t.n,this.ls0+=t.ls0,this.ls1+=t.ls1,this.ss+=t.ss,this.c0=this.ls0/this.n,this.c1=this.ls1/this.n,this.sqNorm=zo(this.c0,this.c1,this.c0,this.c1)}merge(t,n){const s=this.ss+t.ss,o=this.ls0+t.ls0,r=this.ls1+t.ls1,i=this.n+t.n,a=1/i,c=a*o,u=a*r,l=zo(c,u,c,u);return s/i-l<=n*n?(this.n=i,this.ls0=o,this.ls1=r,this.ss=s,this.c0=c,this.c1=u,this.sqNorm=l,!0):!1}}class vn{constructor(t,n,s){this.threshold=t,this.branching=n,this.leaf=s}subclusters=[];centroids=[];sqNorms=[];prev=null;next=null;append(t){const n=this.subclusters.length;this.subclusters.push(t),this.centroids[2*n]=t.c0,this.centroids[2*n+1]=t.c1,this.sqNorms[n]=t.sqNorm}refresh(t){const n=this.subclusters[t];this.centroids[2*t]=n.c0,this.centroids[2*t+1]=n.c1,this.sqNorms[t]=n.sqNorm}replace(t,n,s){const o=this.subclusters.indexOf(t);this.subclusters[o]=n,this.refresh(o),this.append(s)}insert(t){const n=this.subclusters.length;if(n===0)return this.append(t),!1;let s=0,o=Number.POSITIVE_INFINITY;for(let i=0;i<n;i++){const a=G8(this.centroids[2*i],this.centroids[2*i+1],t.c0,t.c1,n)*-2+this.sqNorms[i];a<o&&(o=a,s=i)}const r=this.subclusters[s];if(r.child!==null){if(!r.child.insert(t))return r.update(t),this.refresh(s),!1;const[a,c]=e1(r.child,this.threshold,this.branching);return this.replace(r,a,c),this.subclusters.length>this.branching}return r.merge(t,this.threshold)?(this.refresh(s),!1):(this.append(t),this.subclusters.length>this.branching)}}function e1(e,t,n){const s=new Tn,o=new Tn,r=new vn(t,n,e.leaf),i=new vn(t,n,e.leaf);s.child=r,o.child=i,e.leaf&&(e.prev!==null&&(e.prev.next=r),r.prev=e.prev,r.next=i,i.prev=r,i.next=e.next,e.next!==null&&(e.next.prev=i));const a=e.subclusters.length,c=e.centroids,u=new Float64Array(a);for(let m=0;m<a;m++)u[m]=mr(c[2*m],c[2*m+1]);const l=new Float64Array(a*a);let h=0;for(let m=0;m<a;m++)for(let g=0;g<a;g++){let p=0;m!==g&&(p=-2*t1(c[2*m],c[2*m+1],c[2*g],c[2*g+1])+u[m]+u[g],p>0||(p=0)),l[m*a+g]=p,p>l[h]&&(h=m*a+g)}const f=Math.floor(h/a),d=h%a;for(let m=0;m<a;m++){const g=e.subclusters[m];m===f||l[f*a+m]<l[d*a+m]?(r.append(g),s.update(g)):(i.append(g),o.update(g))}return[s,o]}function H8(e,t,n=z8){const s=e.length/2;let o=new vn(t,n,!0);const r=new vn(t,n,!0);r.next=o,o.prev=r;for(let f=0;f<s;f++){const d=Tn.of(e[2*f],e[2*f+1]);if(o.insert(d)){const[m,g]=e1(o,t,n);o=new vn(t,n,!1),o.append(m),o.append(g)}}const i=[];for(let f=r.next;f!==null;f=f.next)for(let d=0;d<f.subclusters.length;d++)i.push(f.centroids[2*d],f.centroids[2*d+1]);const a=Float64Array.from(i),c=a.length/2,u=new Float64Array(c);for(let f=0;f<c;f++)u[f]=mr(a[2*f],a[2*f+1]);const l=new Float64Array(c),h=new Int32Array(s);for(let f=0;f<s;f++){const d=e[2*f],m=e[2*f+1],g=mr(d,m);let p=Number.POSITIVE_INFINITY;for(let y=0;y<c;y++){const A=-2*(d*a[2*y]+m*a[2*y+1])+g+u[y];l[y]=A,A<p&&(p=A)}let w=0,b=Number.POSITIVE_INFINITY;for(let y=0;y<c;y++){if(l[y]>p+1e-12*(g+u[y]+Math.abs(p)))continue;let A=-2*t1(d,m,a[2*y],a[2*y+1])+g+u[y];A>0||(A=0),A=Math.sqrt(A),A<b&&(b=A,w=y)}h[f]=w}return{labels:h,centers:a}}const ri=["donut","vertical","horizontal","lowleft"];function n1(e){return e>28e3?null:e>=18e3?{w:3,p:1}:e>=8e3?{w:5,p:2}:e>=4e3?{w:7,p:4}:null}function Q8(e,t){const{w:n,p:s}=e,o=2*n+1,r=new Uint8Array(o*o);for(let i=0;i<o;i++)for(let a=0;a<o;a++){const c=i-n,u=a-n,l=-s<=u&&u<=s&&-s<=c&&c<=s;let h;switch(t){case"donut":h=l||u===0||c===0;break;case"vertical":h=-1>u||u>1||l;break;case"horizontal":h=-1>c||c>1||l;break;case"lowleft":{const f=-c,d=-u;h=d>=-s&&f<=s||d>=0||f<=0;break}}r[i*o+a]=h?0:1}return r}function K8(e,t){const{w:n}=e,s=2*n+1,o=Q8(e,t),r=[],i=[];for(let a=-n;a<=n;a++)for(let c=-n;c<=n;c++)o[(n-a)*s+(n-c)]!==0&&(r.push(a),i.push(c-a));return{dr:Int32Array.from(r),dd:Int32Array.from(i)}}const sc=40,oc=50,W8=[1,1.2599210498948732,1.5874010519681996,2,2.5198420997897464,3.174802103936399,4.000000000000001,5.039684199579494,6.349604207872799,8.000000000000002,10.079368399158987,12.699208415745598,16.000000000000004,20.158736798317975,25.3984168314912,32.00000000000001,40.317473596635956,50.7968336629824,64.00000000000003,80.63494719327191,101.5936673259648,128.00000000000006,161.26989438654383,203.18733465192963,256.0000000000001,322.5397887730877,406.37466930385926,512.0000000000002,645.0795775461754,812.7493386077186,1024.0000000000007,1290.1591550923508,1625.4986772154373,2048.0000000000014,2580.318310184702,3250.997354430875,4096.000000000003,5160.636620369404,6501.99470886175,8192.000000000007,10321.273240738808,13003.989417723502,16384.000000000015,20642.54648147762,26007.978835447004,32768.00000000003,41285.09296295524,52015.95767089401,65536.00000000006,82570.1859259105],qo=[[-.3333333333333333,.08333333333333333,-.014814814814814815,.0011574074074074073,.0003527336860670194,-.0001787551440329218,3919263178522438e-20,-21854485106799924e-22,-185406221071516e-20,8296711340953087e-22,-17665952736826078e-23,6707853543401498e-24,10261809784240309e-24,-4382036018453353e-24,914769958223679e-24,-2551419399494625e-26,-5830772132550426e-26,24361948020667415e-27,-50276692801141755e-28,11004392031956135e-29,33717632624009856e-29,-1392388722418162e-28,28534893807047445e-30,-5139111834242572e-31,-19752288294349442e-31],[-.001851851851851852,-.003472222222222222,.0026455026455026454,-.0009902263374485596,.00020576131687242798,-4018775720164609e-22,-18098550334489977e-21,764916091608111e-20,-16120900894563446e-22,4647127802807434e-24,1378633446915721e-22,-5752545603517705e-23,11951628599778148e-24,-17543241719747647e-27,-10091543710600413e-25,4162792991842583e-25,-856390702649298e-25,6067215101604758e-29,71624989648114856e-28,-2933186643771437e-27,5996696365683689e-28,-21671786527323313e-32,-4978339972369262e-29,20291628823713425e-30,-413125571381061e-29],[.004133597883597883,-.0026813271604938273,.0007716049382716049,20093878600823047e-22,-.00010736653226365161,52923448829120125e-21,-12760635188618728e-21,3423578734096138e-23,13721957309062932e-22,-6298992138380055e-22,14280614206064242e-23,-20477098421990866e-26,-1409252991086752e-23,6228974084922022e-24,-13670488396617112e-25,9428356159014678e-28,12872252400089318e-26,-55645956134363323e-27,1197593554636698e-26,-41689782251838634e-31,-10940640427884595e-28,4662239946390136e-28,-9905105763906907e-29,18931876768373515e-33,8859221872591127e-30],[.0006494341563786008,.00022947209362139917,-.0004691894943952557,.00026772063206283885,-7561801671883977e-20,-2396505113867297e-22,11082654115347302e-21,-56749528269915965e-22,14230900732435883e-22,-27861080291528143e-27,-16958404091930278e-23,8099464905388083e-23,-19111168485973655e-24,23928620439808118e-28,20620131815488797e-25,-9460496661855133e-25,21541049775774907e-26,-1388823336813903e-29,-21894761681963938e-27,9790998951171684e-27,-2178219188018096e-27,6208819573407901e-32,2126978363279737e-28,-9344688791517433e-29,2045367122678285e-29],[-.0008618882909167117,.0007840392217200666,-.0002990724803031902,-14638452578843418e-22,6641498215465122e-20,-3968365047179435e-20,11375726970678419e-21,2507497226237533e-25,-16954149536558305e-22,8907507532205309e-22,-2292934834000805e-22,2956794137544049e-26,28865829742708783e-24,-14189739437803219e-24,34463580499464896e-25,-23024517174528067e-29,-39409233028046403e-26,186023389685045e-24,-4356323005056618e-26,1278600101629623e-30,467927502665792e-26,-2149246470613483e-27,4908815614809652e-28,-633859148489156e-32,-5045332069080094e-29],[-.00033679855336635813,-6972813758365858e-20,.0002772753244959392,-.00019932570516188847,6797780477937208e-20,1419062920643967e-22,-13594048189768693e-21,8018470256334202e-21,-2291481176508095e-21,-3252473551298454e-25,34652846491085265e-23,-18447187191171344e-23,48240967037894184e-24,-17989466721743514e-30,-6306194500013523e-24,3162417628774568e-24,-7840924253697429e-25,5192679165254041e-30,9358944242306784e-26,-4513426216163278e-26,10799129993116828e-27,-3661886712685252e-32,-1210902069055155e-27,5680743584990564e-28,-13249659916340829e-29],[.0005313079364639922,-.0005921664373536939,.0002708782096718045,7902353232660328e-22,-8153969367561969e-20,561168275310625e-19,-18329116582843375e-21,-30796134506033047e-25,3465155368803609e-21,-20291327396058603e-22,5788792863149004e-22,2338630673826657e-28,-8828600746330484e-23,47435958880408125e-24,-12545415020710382e-24,8649648858010293e-29,16846058979264062e-25,-8575492823577594e-25,21598224929232125e-26,-7613230520476153e-31,-26639822008536144e-27,13065700536611057e-27,-31799163902367977e-28,4710976121367431e-33,36902800842763465e-29],[.00034436760689237765,5171790908260592e-20,-.00033493161081142234,.0002812695154763237,-.00010976582244684731,-12741009095484485e-23,27744451511563645e-21,-18263488805711332e-21,57876949497350525e-22,493875893393627e-24,-10595367014026043e-22,6166714376110408e-22,-17562973359060463e-23,-1297447328701544e-27,2695423606288966e-23,-14578352908731272e-24,3887645959386175e-24,-3881002251019412e-32,-5327994173877286e-25,27437977643314844e-26,-6995796092070568e-26,2589986387486848e-32,8856689099669639e-27,-4403168815871311e-27,10865561947091654e-28],[-.0006526239185953094,.0008394987206720873,-.000438297098541721,-6969091458420552e-22,.00016644846642067547,-.00012783517679769218,4629953263691304e-20,4557909867922708e-24,-10595271125805195e-21,6783342904865167e-21,-21075476666258803e-22,-17213731432817144e-27,3773587741611098e-22,-21867506700122867e-23,6220228804018927e-23,6597703826733e-28,-9590386497425686e-24,5213214492280807e-24,-13991589583935709e-25,5382058999060575e-31,19484714275467745e-26,-10127287556389682e-26,26077347197254926e-27,-5090418699993299e-33,-33721464474854593e-28],[-.0005967612901927463,-7204895416020011e-20,.0006782308837667328,-.0006401475260262758,.00027750107634328704,1819700838046515e-22,-8479507117068503e-20,6105192082501531e-20,-21073920183404862e-21,-8858589014125599e-25,45284535953805374e-22,-28427815022504407e-22,8708234177864641e-22,36886101871706966e-28,-1534469519070206e-22,8862466778790695e-23,-25184812301826817e-24,-10225912098215092e-30,3896947075815478e-24,-21267304792235634e-25,5737013552805138e-25,-1887749850169741e-34,-8093153869465787e-26,423827232834492e-25,-11002224534207727e-27],[.0013324454494800656,-.0019144384985654776,.0011089369134596636,99324041226423e-20,-.0005087450129309319,.00042735056665392886,-.000168588537679108,-81301893922785e-22,45284402370562144e-21,-3127053674781734e-20,1044986828530338e-20,48435226265680926e-27,-2148256587345626e-21,1329369701097492e-21,-4029569309210103e-22,-1756787766632329e-28,7014504316366825e-23,-4040787734999483e-23,11474026743371962e-24,39642746853563326e-34,-17804938269892715e-25,9748026254873165e-25,-26405338676507616e-26,5794875163403742e-33,3764774955354384e-26],[.001579727660730835,.00016251626278391583,-.0020633421035543276,.00213896861856891,-.0010108559391263003,-399127055299192e-21,.0003623502508476469,-.00028143901463712157,.00010449513336495887,212114184918303e-23,-25779417251947842e-21,17281818956040464e-21,-5641377387290428e-21,-11024320105776174e-27,11223224418895176e-22,-6869339637952674e-22,20653236975414888e-23,46714772409838506e-30,-35609886164949055e-24,20470855345905963e-24,-5809173863328336e-24,-1332821287582869e-31,9035460439133513e-25,-4959878251733084e-25,13481607129399748e-26],[-.004072512119514016,.00640336283380807,-.004041016108167662,-2183732802866233e-21,.002174044180125464,-.001970044051841889,.0008359546974796246,19445447567109655e-24,-.000257793871204217,.00019009987368139304,-6769649993743896e-20,-14440629666426571e-26,15712512518742267e-21,-10304008744776892e-21,3304517767401387e-21,7982976024232571e-28,-64097794149313e-20,38894624761300054e-23,-1161834764494887e-22,-2816808630596451e-30,19878012911297094e-24,-11407719956357511e-24,32355857064185554e-25,4175946829345594e-35,-5042311271810582e-25],[-.0059475779383993,-.0005401647678926045,.00879104135507679,-.009857631558785612,.005013469503102154,12807521786221875e-22,-.0020626019342754685,.0017109128573523059,-.000676953127141338,-6901154567656214e-24,.00018855128143995903,-.0001339521566349197,4626318303352804e-20,4003423061332135e-26,-10255652921494033e-21,6612086372797651e-21,-20913022027253007e-22,-20951775649603836e-29,3975602904199325e-22,-2395621197881589e-22,7118288338214586e-23,8925574873053455e-31,-12101547235064675e-24,6935061824833439e-24,-196614644538561e-23],[.01740202778752271,-.029527880945699123,.020045875571402798,70289515966903405e-22,-.012375421071343148,.011976293444235253,-.0054156038466518525,-6329089339641862e-23,.0018855118129005065,-.001473473274825001,.0005551581009770838,5240683441255066e-25,-.00014357913535784837,991812932249433e-19,-3346083474947831e-20,-3575583729109899e-27,71560851960630075e-22,-4551680262815553e-21,14236576649271474e-22,18803149082089665e-30,-2662340389892921e-22,15950642189595716e-23,-471875146738411e-22,-6510787295875518e-32,7979509102674624e-24],[.03024912416090589,.0024817436002649977,-.049939134373457025,.05991564300930787,-.03248320760162339,-5721296865210344e-21,.015085251778569354,-.013261324005088445,.0055515262632426145,3026318225703001e-23,-.0017229548406756724,.0012893570099929638,-.00046845138348319875,-1830259937893045e-25,.00011449739014822654,-7737856522124447e-20,25625836246985202e-21,10766165333192815e-28,-5324680928242262e-21,3349634863064464e-21,-10381253128684019e-22,-5608909920621128e-30,19150821930676592e-23,-11418365800203487e-23,33654425209171787e-24],[-.09905102088015905,.17954011706123485,-.12989606383463778,-31478872752284355e-21,.09051063527684813,-.0928288244111844,.04441211283987781,27779236316835886e-23,-.017229543805449696,.014182925050891573,-.005621416163374734,-239598509186381e-23,.0016029634366079909,-.0011606784674435774,.00041001337768153875,1836580075409066e-26,-958442565636559e-19,6364306233776471e-20,-2076250624489065e-20,-11806020912804483e-29,4213180823912065e-21,-2626224133701247e-21,8077062049493066e-22,6012591212363273e-31,-1472973737401884e-22],[-.19994542198219728,-.015056113040026424,.36470239469348487,-.4643519231173355,.26640934719197895,3403826602714719e-20,-.13784338709329624,.1276467178337056,-.056213828755200985,-1753150885483011e-22,.019235592956768112,-.015088821281095314,.005740185445135012,10622382710310225e-25,-.0015335082692563998,.0010819320643228215,-.0003737251019394566,-6617090972903199e-27,8426361738090962e-20,-5515070682748348e-20,1776953644834807e-20,3882792321020553e-29,-353513697488768e-20,2186583213004527e-21,-668128494476256e-21],[.7243860850402943,-1.3918010932653375,1.0654143352413967,.0001876173868950258,-.827055011761527,.8935243334782842,-.44971003995291337,-16107401567546651e-22,.1923559016527109,-.1659770216004261,.06888222268181433,13910091724608687e-24,-.02146911561508663,.016228980898865892,-.005979601617258426,-11287469112826745e-26,.0015167451119784856,-.00104786342935539,.0003553907288912642,8170432211180152e-28,-777730134424524e-19,5029141389700772e-20,-16035083867000518e-21,12469354315487606e-30,31369106244517616e-22],[1.6668949727276812,.1165462765994632,-3.3288393225018904,4.469232548286404,-2.6977693045875806,-.0002600667859891061,1.5389017615694538,-1.4937962361134611,.6888196463323315,13077482004552384e-22,-.2576296332559629,.21097676102125448,-.08371440835921988,-7792042888135476e-24,.0242679230648336,-.017813678334552312,.006397033038890006,4943080709048052e-26,-.0015554602758465635,.0010561196919903215,-.000352771844604729,9300233464502246e-29,7528585502655717e-20,-4818651556915635e-20,15227271505597605e-21],[-6.618829886137293,13.397985455142589,-10.789350606845145,-.0014352254537875018,9.23336945961898,-10.456552819547769,5.510552602903347,12024439690716742e-21,-2.5762961164755818,2.320744274538718,-1.0045728797216285,-10207833290021913e-23,.3397509217116947,-.2672051745075747,.10235252851562705,8432973048487163e-25,-.027998284958442594,.020066274144976814,-.007055436891508624,19402238183698188e-28,.0016562888105449611,-.0011082898580743682,.0003654545161310169,-5129003202697179e-26,-7634010369686903e-20],[-17.112706061976095,-1.1208044642899115,37.131966511885445,-52.29827102534896,33.058589696624615,.002479129897620022,-20.61089403411526,20.88672775145582,-10.045703956517752,-12238783449063012e-21,4.077013427422114,-3.473667358470195,1.4329352617312006,7135991441187971e-23,-.4479725715911561,.3411266608064446,-.12699786326594922,-2895367726908153e-25,.03312577627825986,-.023274087021036102,.008039999350364889,-1177805216235265e-24,-.001832162489107167,.0012108282933588664,-.0003947994124682252],[73.89033153567425,-156.80141270402274,132.2177542759164,.013692876877324546,-123.66496885920151,146.2068939106273,-80.36558772486535,-.00011259851148881298,40.77013219617994,-38.21034001327303,17.19522294277362,9351970795516835e-22,-6.271615990774704,5.116899907185264,-2.0319658112299095,-4950721558276154e-24,.596263972943326,-.44220765337238094,.16079998700166273,-24733786203223403e-24,-.040307574759979765,.02784905074709787,-.009475185899205422,6419922235909132e-21,.002125018077469946],[212.1683709838252,13.107863022633868,-496.9828593287175,731.215952669692,-482.1382172089085,-.028817248692894887,326.167203029471,-343.8934028008712,171.95193870816232,.00014038077378096157,-75.2594195897599,66.51969984520935,-28.447519748152462,-7613702615875392e-22,9.540223710530437,-7.517530111331138,2.894399756887196,-466121949995382e-21,-.8061514959879409,.5848300657063102,-.20845408972964957,.00014765818959305816,.05100043386375302,-.03306625214188366,.015109265210467774],[-989.5964309832236,2192.555536090523,-1928.3586782723355,-.15925738122215252,1956.9985945919857,-2407.2514765081555,1375.6149959336497,.0012920735237496668,-752.5941715948055,731.7166874220871,-341.37023466220063,-9985739026060805e-21,133.56313181291574,-112.76295161252794,46.31039609820446,-7923738713361476e-21,-14.510726927018647,11.111771248100563,-4.169081794527089,.0031008219800117806,1.1220095449981469,-.7605237992614992,.36262236505085255,.2216867741940747,.48683443692930506]];function s1(e,t){return Number.isNaN(e)||Number.isNaN(t)||t<0?Number.NaN:e<0?1:e===Number.POSITIVE_INFINITY?0:Math.min(1,Math.max(0,Y8(Math.floor(e),t)))}function Y8(e,t){return e<0||t<0?Number.NaN:t===0?0:k9(Math.floor(e)+1,t)}const tn=11102230246251565e-32,o1=.9189385332046728,V8=2556348e299,X8=1.4142135623730951,J8=.7071067811865476,Z8=500,ii=2e3,r1=1,j8=0,t9=20,rc=200,e9=.3,n9=4.5,s9=4503599627370496,cs=2220446049250313e-31;function pe(e,t,n){let s=t[0];for(let o=1;o<=n;o++)s=s*e+t[o];return s}function On(e,t,n){let s=e+t[0];for(let o=1;o<n;o++)s=s*e+t[o];return s}function o9(e,t,n,s,o){const r=Math.abs(e);let i,a,c;r>1?(i=-1,a=n,c=1/e):(i=1,a=0,c=e);let u=t[a];a+=i;for(let h=1;h<=n;h++)u=u*c+t[a],a+=i;a=r>1?o:0;let l=s[a];a+=i;for(let h=1;h<=o;h++)l=l*c+s[a],a+=i;return r>1?Math.pow(e,n-o)*u/l:u/l}const r9=[.0008116141674705085,-.0005950619042843014,.0007936503404577169,-.002777777777300997,.08333333333333319],i9=[-1378.2515256912086,-38801.631513463784,-331612.9927388712,-1162370974927623e-9,-1.7217370082083966e6,-853555.6642457654],a9=[-351.81570143652345,-17064.210665188115,-220528.59055385445,-1.1393344436798252e6,-2.5325230717758294e6,-2.0188914143353277e6];function c9(e){const t=(e-.5)*Math.log(e)-e+o1;if(e>1e8)return t;let n=1/(e*e);return n=((.0007936507936507937*n-.002777777777777778)*n+.08333333333333333)/e,t+n}function ai(e){if(!Number.isFinite(e))return e;if(e<=0)throw new RangeError(`lgam is ported for positive arguments only, not ${e}`);if(e<13){let s=1,o=0,r=e;for(;r>=3;)o-=1,r=e+o,s*=r;for(;r<2;)s/=r,o+=1,r=e+o;if(s<0&&(s=-s),r===2)return Math.log(s);o-=2;const i=e+o;return o=i*pe(i,i9,5)/On(i,a9,6),Math.log(s)+o}if(e>V8)return Number.POSITIVE_INFINITY;if(e>=1e3)return c9(e);const t=(e-.5)*Math.log(e)-e+o1,n=1/(e*e);return t+pe(n,r9,4)/e}function l9(e){if(e===1)return 0;if(Math.abs(e)<=.5||Math.abs(e-1)<.5)throw new RangeError(`lgam1p is ported for x = 1 and x ≥ 1.5 only, not ${e}`);return ai(e+1)}const Uo=6.02468004077673,u9=[.006061842346248907,.5098416655656676,19.519927882476175,449.9445569063168,6955.999602515376,75999.29304014542,601859.6171681099,3481712154980646e-9,14605578087685067e-9,4333888932467614e-8,863631312881386e-7,10379404311634454e-8,56906521913471565e-9],h9=[1,66,1925,32670,357423,2637558,13339535,45995730,105258076,150917976,120543840,39916800,0];function f9(e){return o9(e,u9,12,h9,12)}const d9=[452700008624452e-19,.49854102823193375,6.578732594206104,29.911919328553072,60.94966798098779,57.11296359058554,20.039553499201283],m9=[15.062909083469192,83.04756596796722,221.76239823732857,309.09872225312057,216.42788614495947,60.11866049760384],g9=[.00012617719307481058,.030299440770744195,1],p9=[30019850513866446e-22,.002524483403496841,.22726554820815503,2];function w9(e){let t=1+e;return t<J8||t>X8?Math.log(t):(t=e*e,t=-.5*t+e*(t*pe(e,d9,6)/On(e,m9,6)),e+t)}function gr(e){if(Math.abs(e)<.5){let t=e,n=0;for(let s=2;s<Z8;s++){t*=-e;const o=t/s;if(n+=o,Math.abs(o)<tn*Math.abs(n))break}return n}return w9(e)-e}function b9(e){if(!Number.isFinite(e))return Number.isNaN(e)||e>0?e:-1;if(e<-.5||e>.5)return Math.exp(e)-1;const t=e*e;let n=e*pe(t,g9,2);return n=n/(pe(t,p9,3)-n),n+n}const A9=[2461969814735305e-25,.5641895648310689,7.463210564422699,48.63719709856814,196.5208329560771,526.4451949954773,934.5285271719576,1027.5518868951572,557.5353353693994],y9=[13.228195115474499,86.70721408859897,354.9377788878199,975.7085017432055,1823.9091668790973,2246.3376081871097,1656.6630919416134,557.5353408177277],N9=[.5641895835477551,1.275366707599781,5.019050422511805,6.160210979930536,7.4097426995044895,2.9788666537210022],M9=[2.2605286322011726,9.396035249380015,12.048953980809666,17.08144507475659,9.608968090632859,3.369076451000815],I9=[9.604973739870516,90.02601972038427,2232.005345946843,7003.325141128051,55592.30130103949],x9=[33.56171416475031,521.3579497801527,4594.323829709801,22629.000061389095,49267.39426086359];function i1(e){if(Number.isNaN(e))return Number.NaN;if(e<0)return-i1(-e);if(Math.abs(e)>1)return 1-a1(e);const t=e*e;return e*pe(t,I9,4)/On(t,x9,5)}function a1(e){if(Number.isNaN(e))return Number.NaN;const t=e<0?-e:e;if(t<1)return 1-i1(e);let n=-e*e;if(n<-709.782712893384)return e<0?2:0;n=Math.exp(n);let s,o;t<8?(s=pe(t,A9,8),o=On(t,y9,8)):(s=pe(t,N9,5),o=On(t,M9,6));let r=n*s/o;return e<0&&(r=2-r),r!==0?r:e<0?2:0}function c1(e,t){if(Math.abs(e-t)>.4*Math.abs(e)){const o=e*Math.log(t)-t-ai(e);return o<-709.782712893384?0:Math.exp(o)}const n=e+Uo-.5;let s=Math.sqrt(n/Math.exp(1))/f9(e);if(e<200&&t<200)s*=Math.exp(e-t)*Math.pow(t/n,e);else{const o=t-e-Uo+.5;s*=Math.exp(e*gr(o/n)+t*(.5-Uo)/n)}return s}function v9(e,t){const n=c1(e,t);if(n===0)return 0;let s=1-e,o=t+s+1,r=0,i=1,a=t,c=t+1,u=o*t,l=c/u;for(let h=0;h<ii;h++){r+=1,s+=1,o+=2;const f=s*r,d=c*o-i*f,m=u*o-a*f;let g;if(m!==0){const p=d/m;g=Math.abs((l-p)/p),l=p}else g=1;if(i=c,c=d,a=u,u=m,Math.abs(d)>s9&&(i*=cs,c*=cs,a*=cs,u*=cs),g<=tn)break}return l*n}function ws(e,t){const n=c1(e,t);if(n===0)return 0;let s=e,o=1,r=1;for(let i=0;i<ii&&(s+=1,o*=t/s,r+=o,!(o<=tn*r));i++);return r*n/e}function ic(e,t){let n=1,s=0;for(let i=1;i<ii;i++){n*=-t/i;const a=n/(e+i);if(s+=a,Math.abs(a)<=tn*Math.abs(s))break}const o=Math.log(t);return-b9(e*o-l9(e))-Math.exp(e*o-ai(e))*s}function l1(e,t,n){const s=qo.length,o=qo[0].length;let r=0;const i=t/e,a=(t-e)/e,c=new Float64Array(o);c[0]=1;let u=0,l=1,h=Number.POSITIVE_INFINITY;const f=n===r1?-1:1;let d;i>1?d=Math.sqrt(-2*gr(a)):i<1?d=-Math.sqrt(-2*gr(a)):d=0;let m=.5*a1(f*d*Math.sqrt(e/2));for(let g=0;g<s;g++){const p=qo[g];let w=p[0];for(let A=1;A<o;A++){A>r&&(c[A]=d*c[A-1],r+=1);const N=p[A]*c[A];if(w+=N,Math.abs(N)<tn*Math.abs(w))break}const b=w*l,y=Math.abs(b);if(y>h||(u+=b,y<tn*Math.abs(u)))break;h=y,l/=e}return m+=f*Math.exp(-.5*e*d*d)*u/Math.sqrt(2*Math.PI*e),m}function u1(e,t){const n=Math.abs(t-e)/e;return e>t9&&e<rc&&n<e9||e>rc&&n<n9/Math.sqrt(e)}function k9(e,t){return Number.isNaN(e)||Number.isNaN(t)||t<0||e<0?Number.NaN:e===0?t>0?1:Number.NaN:t===0?0:Number.isFinite(e)?Number.isFinite(t)?u1(e,t)?l1(e,t,r1):t>1&&t>e?1-S9(e,t):ws(e,t):1:Number.isFinite(t)?0:Number.NaN}function S9(e,t){return Number.isNaN(e)||Number.isNaN(t)||t<0||e<0?Number.NaN:e===0?t>0?0:Number.NaN:t===0?1:Number.isFinite(e)?Number.isFinite(t)?u1(e,t)?l1(e,t,j8):t>1.1?t<e?1-ws(e,t):v9(e,t):t<=.5?-.4/Math.log(t)<e?1-ws(e,t):ic(e,t):t*1.1<e?1-ws(e,t):ic(e,t):0:Number.isFinite(t)?1:Number.NaN}function C9(e){if(!Number.isInteger(e)||e<sc||e>oc)throw new RangeError(`cooltools takes ${sc} to ${oc} λ-chunks, not ${e}`);return Float64Array.from(W8.slice(0,e))}function no(e){const t=o=>{const r=Math.round(o);return r-o===.5&&r%2!==0?r-1:r},n=(o,r)=>{if(!Number.isFinite(o)||o===0)return o;const i=Math.trunc(o),a=i===0?-Math.floor(Math.log10(Math.abs(o-i)))-1+r:r,c=Math.pow(10,Math.abs(a));return a>=0?t(o*c)/c:t(o/c)*c};let s=3;for(let o=3;o<20;o++){const r=Array.from(e,i=>n(i,o));if(new Set(r).size===e.length){s=o;break}}return Float64Array.from(e,o=>n(o,s))}function Re(e,t){const n=t.length;if(!(e>t[0]))return 0;h1[0]=e;let s=3*((F9[$9]>>>20&2047)-1023);for(s>n&&(s=n),s<1&&(s=1);s>0&&t[s-1]>=e;)s--;for(;s<n&&t[s]<e;)s++;return s}const h1=new Float64Array(1),F9=new Uint32Array(h1.buffer),$9=new Uint8Array(new Uint16Array([1]).buffer)[0]===1?1:0,E9=2;function B9(e,t,n=E9){const{n:s,hi:o,values:r}=e,i=new Float64Array(o+1),a=new Float64Array(o+1),c=new Float64Array(o+1);for(let u=0;u<=o;u++){let l=0,h=0,f=0;for(let d=0;d+u<s;d++){const m=t[d],g=t[d+u];if(Number.isNaN(m)||Number.isNaN(g))continue;f++;const p=r[u*s+d];if(p===0||Number.isNaN(p))continue;const w=p*m*g-h,b=l+w;h=b-l-w,l=b}a[u]=f,c[u]=l,i[u]=u<n?Number.NaN:l/f}return{avg:i,nValid:a,sum:c}}const T9=256;async function O9(e,t,n,s,o,r,i){const{n:a,hi:c,values:u}=e,{w:l}=s,h=ri.map($=>K8(s,$)),f=Math.min(o,a),d=new Int32Array(a+1);for(let $=0;$<a;$++)d[$+1]=d[$]+(Number.isNaN(t[$])?1:0);const m=$=>$-l>=0&&$+l<a&&d[$+l+1]-d[$-l]===0;let g=0,p=0;for(const $ of h)for(const O of $.dd)g=Math.min(g,O),p=Math.max(p,O);const w=h.map(()=>new Float64Array(f)),b=new Uint8Array(f);for(let $=1;$<f;$++){if($+g<0||$+p>c)continue;let O=Number.isFinite(n[$]);for(let L=0;O&&L<h.length;L++){const D=h[L].dd;let q=0;for(let X=0;X<D.length;X++){const P=n[$+D[X]];if(!Number.isFinite(P)){O=!1;break}q+=P}w[L][$]=q}b[$]=O?1:0}const y=2*l+1,A=c+1,N=new Float64Array(y*A),I=$=>{const O=$%y*A,L=t[$];for(let D=0;D<=c;D++){const q=$+D;N[O+D]=q<a?u[D*a+$]*(L*t[q]):Number.NaN}},M=new Int32Array(4);let x=0;h.forEach(($,O)=>M[O]=x+=$.dr.length);const v=new Int32Array(x),S=new Int32Array(x);h.forEach(($,O)=>{const L=O===0?0:M[O-1];v.set($.dr,L),S.set($.dd,L)});const k=new Int32Array(x),C=new Float64Array(4*f);for(let $=0;$<4;$++)C.set(w[$],$*f);const B=new Uint8Array(a);for(let $=0;$<a;$++)B[$]=m($)?1:0;const F=new Int32Array(y),E=new Float64Array(16);let _=0;for(let $=0;$<Math.min(a,l);$++)I($);for(let $=0;$<a;$++){if($+l<a&&I($+l),i!==void 0&&$%T9===0&&await i($),B[$]===0)continue;for(let z=-l;z<=l;z++)F[z+l]=($+z)%y*A;for(let z=0;z<x;z++)k[z]=F[v[z]+l]+S[z];const O=t[$],L=Math.min(f-1,a-1-l-$),D=Math.max(1,-g),q=Math.min(L,c-p),X=(z,R,H,K,G)=>{if(b[z]===0||B[$+z]===0||!Number.isFinite(R)||!Number.isFinite(H)||!Number.isFinite(K)||!Number.isFinite(G))return;const W=n[z]/(O*t[$+z]);_++,r($,$+z,u[z*a+$],W*R,W*H,W*K,W*G)};let P=D;for(;P+3<=q;P+=4){let z=0;for(let R=0;R<4;R++){const H=M[R];let K=0,G=0,W=0,Y=0;for(;z<H;z++){const et=k[z]+P;K+=N[et],G+=N[et+1],W+=N[et+2],Y+=N[et+3]}const tt=R*f+P;E[R]=K/C[tt],E[4+R]=G/C[tt+1],E[8+R]=W/C[tt+2],E[12+R]=Y/C[tt+3]}X(P,E[0],E[1],E[2],E[3]),X(P+1,E[4],E[5],E[6],E[7]),X(P+2,E[8],E[9],E[10],E[11]),X(P+3,E[12],E[13],E[14],E[15])}for(;P<=q;P++){let z=0;for(let R=0;R<4;R++){const H=M[R];let K=0;for(;z<H;z++)K+=N[k[z]+P];E[R]=K/C[R*f+P]}X(P,E[0],E[1],E[2],E[3])}}return _}const ac=16384;class L9{constructor(t){this.edges=t,this.chunks=t.length+1}chunks;dense=new Float64Array(0);denseRows=0;sparse=new Map;row(t){if(Number.isInteger(t)&&t>=0&&t<ac){if(t>=this.denseRows){const s=Math.min(ac,Math.max(t+1,this.denseRows*2,64)),o=new Float64Array(s*4*this.chunks);o.set(this.dense),this.dense=o,this.denseRows=s}return{cells:this.dense,at:t*4*this.chunks}}let n=this.sparse.get(t);return n===void 0&&(n=new Float64Array(4*this.chunks),this.sparse.set(t,n)),{cells:n,at:0}}add(t,n,s,o,r){const i=this.chunks;let a,c;if(Number.isInteger(t)&&t>=0&&t<this.denseRows)a=this.dense,c=t*4*i;else{const u=this.row(t);a=u.cells,c=u.at}a[c+n]++,a[c+i+s]++,a[c+2*i+o]++,a[c+3*i+r]++}table(){const t=[];for(let s=0;s<this.denseRows;s++){const o=s*4*this.chunks;let r=!1;for(let i=0;i<this.chunks&&!r;i++)r=this.dense[o+i]>0;r&&t.push(s)}for(const[s,o]of this.sparse){let r=!1;for(let i=0;i<this.chunks&&!r;i++)r=o[i]>0;r&&t.push(s)}t.sort((s,o)=>s-o);const n=ri.map(()=>new Float64Array(t.length*this.chunks));return t.forEach((s,o)=>{const{cells:r,at:i}=this.row(s);for(let a=0;a<4;a++)n[a].set(r.subarray(i+a*this.chunks,i+(a+1)*this.chunks),o*this.chunks)}),{counts:Float64Array.from(t),cells:n}}}function _9(e,t){const{counts:n,cells:s}=e.table(),o=e.chunks,r=n.length,i=no(e.edges);let a=0;for(let d=0;d<4;d++){let m=0;for(let g=0;g<r;g++)m+=s[d][g*o+o-1];a=Math.max(a,m)}const c=r===0?1:n[r-1]+1,u=new Map;n.forEach((d,m)=>u.set(d,m));const l=new Array(o).fill(null),h=d=>{let m=l[d];if(m===null){m=new Float64Array(r);const g=i[d];let p=!1;for(let w=0;w<r;w++)m[w]=p?0:s1(n[w],g),m[w]===0&&(p=!0);l[d]=m}return m};return{kernels:s.map(d=>{let m=-1;for(let b=0;b<o;b++)for(let y=0;y<r;y++)if(d[y*o+b]>0){m=b;break}const g=Math.max(0,Math.min(m+1,o-1)),p=new Float64Array(g),w=new Float64Array(r*g);for(let b=0;b<g;b++){const y=new Float64Array(r);let A=0;for(let S=r-1;S>=0;S--)A+=d[S*o+b],y[S]=A;const N=r===0?0:y[0],I=h(b);let M=Number.NEGATIVE_INFINITY,x=Number.NaN,v=Number.NaN;for(let S=0;S<r;S++){const k=N*I[S],C=t*y[S]-k;C>M&&(M=C),Number.isNaN(x)&&M>=0&&(x=n[S]);const B=k/y[S];!Number.isNaN(B)&&!(B>=v)&&(v=B);const F=Number.isNaN(B)?Number.NaN:v;w[S*g+b]=F>1?1:F}p[b]=Math.trunc(Number.isNaN(x)?c:x)}return{thresholds:p,qvalue(b,y){const A=u.get(b);return A===void 0||y>=g?Number.NaN:w[A*g+y]}}}),counts:n,overflow:a}}function D9(e,t){const n=no(e),s=new Float64Array(e.length+1).fill(Number.POSITIVE_INFINITY),o=t*(1+1e-9);for(let r=0;r<n.length;r++){let i=0;for(;s1(i,n[r])>o;)i++;s[r]=i}return s}function R9(e,t,n){const s=new Map;for(const i of e){let a=s.get(i.sequence);a===void 0&&s.set(i.sequence,a=[]),a.push(i)}const o=[],r=[];for(const[,i]of[...s].sort((a,c)=>a[0]-c[0])){const a=new Float64Array(i.length*2);i.forEach((f,d)=>{a[2*d]=f.bin1*t,a[2*d+1]=f.bin2*t});const{labels:c,centers:u}=H8(a,n),l=new Map;for(const f of c)l.set(f,(l.get(f)??0)+1);const h=new Map;i.forEach((f,d)=>{const m=c[d],g={...f,cLabel:m,cSize:l.get(m)??0,cStart1:u[2*m],cStart2:u[2*m+1]};o.push(g);const p=h.get(m);(p===void 0||g.count>p.count)&&h.set(m,g)}),r.push(...[...h.values()].sort((f,d)=>f.cLabel-d.cLabel))}return{pixels:o,centroids:r}}const Me={vh:1.5,dAndLl:1.75,dOrLl:2,orphanFdr:.02};function P9(e){const[t,n,s,o]=e.laExp,[r,i,a,c]=e.qval,u=e.count;return u>Me.dAndLl*o&&u>Me.dAndLl*t&&u>Me.vh*n&&u>Me.vh*s&&(u>Me.dOrLl*o||u>Me.dOrLl*t)&&(e.cSize>1||c+r+i+a<=Me.orphanFdr)}class de{values;length=0;constructor(t=1024){this.values=new Float64Array(t)}push(t){if(this.length===this.values.length){const n=new Float64Array(this.values.length*2);n.set(this.values),this.values=n}this.values[this.length++]=t}}class z9{constructor(t){this.settings=t,this.edges=C9(t.lambdaBins),this.histogram=new L9(this.edges),this.floors=D9(this.edges,t.fdr)}edges;histogram;floors;scored=0;sequence=new de;row=new de;col=new de;count=new de;la=[new de,new de,new de,new de];async addSequence(t,n,s,o,r){const{edges:i,floors:a,histogram:c}=this,u=await O9(n,s,o,this.settings.shape,this.settings.maxSeparation,(l,h,f,d,m,g,p)=>{const w=Re(d,i),b=Re(m,i),y=Re(g,i),A=Re(p,i);c.add(f,w,b,y,A);const N=Math.floor(f);N<a[w]||N<a[b]||N<a[y]||N<a[A]||(this.sequence.push(t),this.row.push(l),this.col.push(h),this.count.push(f),this.la[0].push(d),this.la[1].push(m),this.la[2].push(g),this.la[3].push(p))},r);return this.scored+=u,u}finish(t){const{kernels:n,overflow:s}=_9(this.histogram,this.settings.fdr),o=n.map(d=>d.thresholds),r={scored:this.scored,overflow:s,unlabelled:0,thresholds:o,enriched:[],clustered:[],calls:[]};if(s>0||this.scored===0)return r;const i=[],a=no(this.edges);let c=0;for(let d=0;d<this.count.length;d++){const m=this.count.values[d];let g=!0;for(let y=0;y<4&&g;y++){const A=n[y].thresholds[Re(this.la[y].values[d],this.edges)];g=A!==void 0&&m>=A}if(!g)continue;const p=[this.la[0].values[d],this.la[1].values[d],this.la[2].values[d],this.la[3].values[d]],w=[0,0,0,0];let b=!0;for(let y=0;y<4&&b;y++){const A=Re(p[y],a);b=A<n[y].thresholds.length,b&&(w[y]=n[y].qvalue(m,A))}if(!b){c++;continue}i.push({sequence:this.sequence.values[d],bin1:this.row.values[d],bin2:this.col.values[d],count:m,laExp:p,qval:w})}const u=this.settings.clusteringRadius;if(!(u>0)){const d=i.map(m=>({...m,cLabel:-1,cSize:1,cStart1:Number.NaN,cStart2:Number.NaN}));return{...r,unlabelled:c,enriched:i,clustered:d,calls:d}}const{pixels:l,centroids:h}=R9(i,t,u),f=this.settings.clusterFiltering?h.filter(P9):h;return{...r,unlabelled:c,enriched:i,clustered:l,calls:f}}}const q9=1e7,U9=2e4,G9=.1,H9=40,Q9=96e6;function K9(e,t){return t>0?Math.trunc(e/t):0}function W9(e,t){const n=n1(t),s=(i,a)=>{const c=e[i];return typeof c=="number"&&Number.isFinite(c)?Math.round(c):a??null},o=s("outer",n?.w),r=s("inner",n?.p);return o===null||r===null?null:{w:o,p:r}}function Y9(e,t){const n=e.maxSeparation;return typeof n=="number"&&Number.isFinite(n)?Math.max(1,Math.round(n)):Math.max(1,K9(q9,t))}function V9(e,t){const n=e.clusteringRadius;if(!(typeof n=="number"&&Number.isFinite(n)))return U9;const s=Math.max(0,n)*t,o=Math.round(s);return Math.abs(s-o)<1e-6?o:s}function f1(e,t,n){return Math.max(0,Math.min(t-1+2*n,e-1))}const d1=["donut","vertical","horizontal","lower-left"],X9=async e=>{const t=e.mc.binsize;if(!nt(e.params,"balance",!0))throw new T("unsupported","Loop calling needs a balanced map: its local expected is built from the balanced map and scaled back to raw counts for the Poisson test. Run it with the weights on.");const n=W9(e.params,t);if(n===null)throw new T("unsupported",`There are kernels for bins of 4 to 28 kb only, and this map’s are ${t.toLocaleString()} bp. Give the kernel’s two half-widths (--outer and --inner): w 7, p 4 is the kernel for 5 kb bins, and w 5, p 2 the one for 10 kb.`);if(n.p>=n.w)throw new T("unsupported","The inner half-width must be smaller than the outer one.");const s=Y9(e.params,t),o=V9(e.params,t),r={shape:n,maxSeparation:s,lambdaBins:Math.round(Q(e.params,"lambdaBins",H9)),fdr:Q(e.params,"fdr",G9),clusteringRadius:o,clusterFiltering:nt(e.params,"filter",!0)},i=n1(t);e.note(i!==null&&i.w===n.w&&i.p===n.p?`Kernels w ${n.w}, p ${n.p}: the ones for ${kt(t)} bins.`:`Kernels w ${n.w}, p ${n.p}`+(i===null?`, given for ${kt(t)} bins, which have none of their own.`:`; the ones for ${kt(t)} bins are w ${i.w}, p ${i.p}.`)),e.note(`A ${s.toLocaleString()}-bin scan reaches ${kt(s*t)} from the diagonal at this file’s ${t.toLocaleString()} bp resolution, and the nearest pixel a kernel can be read around is ${(2*n.w+2).toLocaleString()} bins out.`);const{units:a,skipped:c}=J9(e,s,n.w);if(c.length>0&&e.note(`${c.length} sequence${c.length===1?"":"s"} would need a band bigger than a scan can hold, and ${c.length===1?"was":"were"} skipped: ${Z9(c)}. Bring “furthest from the diagonal” down, or open the file at a coarser resolution.`),a.length===0)return e.note("No sequence to scan."),[];const u=ee(e.mc,!0),l=Ft(e,a.map(g=>g.span),!1),h=new z9(r);for(const[g,p]of a.entries()){await e.breathe();const w=p.span.to-p.span.from,b=await Oe(e,p.span,{hi:f1(w,s,n.w),block:l,balance:!1,value:j,onTile:async(N,I)=>{await e.breathe();const M=I===1?`${p.name} · reading`:`${p.name} · reading ${N+1} of ${I}`;e.progress(g,a.length,M)}}),y=u.subarray(p.span.from,p.span.to),{avg:A}=B9(b,y);await h.addSequence(g,b,y,A,async N=>{await e.breathe(),e.progress(g+N/Math.max(1,w),a.length,`${p.name} · scoring`)})}e.progress(a.length,a.length,"thresholds"),e.throwIfCancelled();const f=h.finish(t);if(f.overflow>0){const g=h.edges;return e.note(`${f.overflow.toLocaleString()} ${f.overflow===1?"pixel has":"pixels have"} a local expected past the last λ-chunk’s edge, ${g[g.length-1].toFixed(0)} contacts, and loop calling stops there rather than test them. Raise the λ-chunks: 50 reach 82,570.`),[]}if(f.scored===0)return e.note("No pixel could be scored: every one either sits within the kernel’s reach of the diagonal, of a sequence’s end or of a bin the balancer dropped. Narrow the kernel, or open a finer resolution."),[];if(e.note(`${f.scored.toLocaleString()} pixels scored over ${a.length.toLocaleString()} ${a.length===1?"sequence":"sequences"}; ${f.enriched.length.toLocaleString()} reached all four thresholds at an FDR of ${r.fdr}.`),f.unlabelled>0&&e.note(`${f.unlabelled.toLocaleString()} of them ${f.unlabelled===1?"was":"were"} left out for sitting a hair past the rounded label of the last λ-chunk their kernel had.`),f.enriched.length===0)return e.note("Nothing passed: no loop is called."),cc(h,f);if(o>0){const g=new Set(f.clustered.map(p=>`${p.sequence}:${p.cLabel}`)).size;e.note(`${g.toLocaleString()} ${g===1?"cluster":"clusters"} at a ${kt(o)} radius`+(r.clusterFiltering?`; ${f.calls.length.toLocaleString()} passed the enrichment filter.`:", each reported at its brightest pixel, unfiltered."))}else e.note("Unclustered: every enriched pixel is a call, and none is filtered.");const d=[];f.calls.length>0&&d.push(j9(a,f.calls,t)),d.push(em(a,f.calls,t));const m=Js(f.calls.map(g=>({separation:(g.bin2-g.bin1)*t,score:g.count/g.laExp[0]})),{id:"loops-spectrum",label:"Loop spectrum",noun:"loops",yLabel:"Observed over the donut’s expected"});return m!==null&&d.push(m),d.push(...cc(h,f)),d};function J9(e,t,n){const s=e.mc,o=e.params.sequences,r=Array.isArray(o)?new Set(o.filter(c=>typeof c=="string")):null,i=[],a=[];for(const c of to(s)){const u=s.chromnames[c];if(r!==null&&!r.has(u))continue;const l=Zt(s,c);if(l===null)continue;const h=l.to-l.from;if((f1(h,t,n)+1)*h>Q9){a.push(u);continue}i.push({name:u,span:l,length:s.chromsizes.get(u)??h*s.binsize})}return{units:i,skipped:a}}function Z9(e){const t=e.slice(0,6).join(", ");return e.length>6?`${t} and ${e.length-6} more`:t}function j9(e,t,n){const s=new Bl;for(const o of t){const r=e[o.sequence],i=o.bin1*n,a=o.bin2*n;s.add(r.name,i,Math.min(r.length,i+n),r.name,a,Math.min(r.length,a+n),{score:o.count/o.laExp[0],name:"",detail:tm(o)})}return{kind:"intervals",id:"loops-calls",label:"Called loops",payload:{kind:"pairs",data:s.finish()},noun:{one:"loop",many:"loops"},display:"overlay"}}function tm(e){return`observed ${e.count} · `+d1.map((t,n)=>`${t} ${e.laExp[n].toFixed(2)} (q ${nm(e.qval[n])})`).join(" · ")+(e.cLabel>=0?` · cluster of ${e.cSize}`:"")}function em(e,t,n){const s=t.map(i=>({sequence:e[i.sequence].name,start1:i.bin1*n,start2:i.bin2*n,separation:(i.bin2-i.bin1)*n,count:i.count,enrichment:i.count/i.laExp[0],donut:i.laExp[0],vertical:i.laExp[1],horizontal:i.laExp[2],lowleft:i.laExp[3],qDonut:i.qval[0],qVertical:i.qval[1],qHorizontal:i.qval[2],qLowleft:i.qval[3],cluster:i.cLabel>=0?i.cSize:1})),o=(i,a)=>({key:i,label:`λ ${a}`,kind:"number",digits:4,hint:`Locally adjusted expected, ${a} kernel, in raw counts.`}),r=(i,a)=>({key:i,label:`q ${a}`,kind:"number",digits:4,scientific:!0,hint:`Benjamini–Hochberg within its λ-chunk, ${a} kernel.`});return{kind:"table",id:"loops-table",label:`${t.length.toLocaleString()} ${t.length===1?"loop":"loops"}`,columns:[{key:"sequence",label:"Sequence",kind:"text"},{key:"start1",label:"Start 1",kind:"number",coordinate:"start"},{key:"start2",label:"Start 2",kind:"number",coordinate:"start"},{key:"separation",label:"Separation (bp)",kind:"number",digits:0},{key:"count",label:"Observed",kind:"number",digits:0,hint:"Raw contacts in the pixel."},{key:"enrichment",label:"Enrichment",kind:"number",digits:4,hint:"Observed over the donut’s locally adjusted expected."},o("donut","donut"),o("vertical","vertical"),o("horizontal","horizontal"),o("lowleft","lower-left"),r("qDonut","donut"),r("qVertical","vertical"),r("qHorizontal","horizontal"),r("qLowleft","lower-left"),{key:"cluster",label:"Cluster",kind:"number",digits:0,hint:"Enriched pixels in its cluster."}],rows:s}}function cc(e,t){const{counts:n,cells:s}=e.histogram.table(),o=e.histogram.chunks,r=no(e.edges),i=[];ri.forEach((c,u)=>{const l=t.thresholds[u],h=[],f=[];for(let d=0;d<l.length;d++){let m=Number.NEGATIVE_INFINITY;for(let g=n.length-1;g>=0;g--)if(s[u][g*o+d]>0){m=n[g];break}m>=l[d]&&(h.push(r[d]),f.push(l[d]))}i.push({name:d1[u],x:Float64Array.from(h),y:Float64Array.from(f),mark:"points"})});const a=Math.max(1,...i.flatMap(c=>Array.from(c.x)));return i.push({name:"observed = λ",x:Float64Array.from([1,a]),y:Float64Array.from([1,a]),mark:"line"}),[{kind:"curve",id:"loops-thresholds",label:"Contacts needed, by λ-chunk",series:i,xLabel:"Locally adjusted expected (λ), raw counts",yLabel:"Contacts a pixel must reach",xScale:"log",yScale:"log"}]}function nm(e){return Number.isFinite(e)?e===0?"0":e<1e-4?e.toExponential(2):e.toFixed(4):"n/a"}function sm(e,t){const n=e.n,s=[...new Set(t.quantiles)].filter(h=>h>0&&h<1).sort((h,f)=>h-f),o=Math.max(0,Math.trunc(t.ignoreDiags??1)),r=Math.max(1,o),i=Math.max(r,Math.min(Math.trunc(t.maxDistance),e.hi)),a=s.map(h=>({quantile:h,distance:new Float64Array(n).fill(Number.NaN)}));if(s.length===0||n===0||i<r)return a;const c=i-r+1,u=Math.max(1,Math.ceil(c*Math.max(0,Math.min(1,t.minValid)))),l=new Float64Array(c+1);for(let h=0;h<n;h++){let f=0,d=0;for(let p=0;p<c;p++){const w=r+p,b=e.forward(h,w),y=e.forward(h,-w),A=Number.isFinite(b),N=Number.isFinite(y);(A||N)&&d++,f+=(A?b:0)+(N?y:0),l[p+1]=f}const m=l[c];if(d<u||!(m>0))continue;let g=1;for(let p=0;p<s.length;p++){const w=s[p]*m;for(;g<c&&l[g]<w;)g++;const b=l[g-1],y=l[g],A=y>b?(w-b)/(y-b):0;a[p].distance[h]=r+Math.max(0,g-2+A)}}return a}const lc={quartiles:[.25,.5,.75],standard:[.1,.25,.5,.75,.9],deciles:[.1,.2,.3,.4,.5,.6,.7,.8,.9]};function om(e){const t=typeof e.quantiles=="string"?e.quantiles:"standard";return lc[t]??lc.standard}function m1(e){const t=typeof e.reach=="number"?e.reach:0;return Math.max(0,Math.round(t))}function rm(e,t,n=!1){const s=n?Math.floor(t/2):Math.max(1,t-1),o=m1(e);return o===0?s:Math.max(1,Math.min(s,o))}const im="Scalogram";function am(e){const t=[8,48,107],n=[198,219,239],s=[];for(let o=0;o<e;o++){const r=e===1?0:o/(e-1),i=(l,h)=>Math.round(l+(h-l)*r),[a,c,u]=[i(t[0],n[0]),i(t[1],n[1]),i(t[2],n[2])];s.push(`#${[a,c,u].map(l=>l.toString(16).padStart(2,"0")).join("")}`)}return s}function cm(e,t){const n=e.mc,{ids:s,missing:o}=$e(n,t),r=[];for(const i of s){const a=Zt(n,i);if(a===null)continue;const c=n.chromnames[i];r.push({name:c,span:a,circular:Te(e,c)})}return{units:r,missing:o}}const lm=async e=>{const t=nt(e.params,"balance",!1),n=e.framing.value===""?j:e.framing.value,s=Math.max(0,Math.min(1,Q(e.params,"minValid",.5))),o=Math.max(0,Math.round(Q(e.params,"ignoreDiags",1))),r=om(e.params),i=m1(e.params);i>0&&e.note(`A ${i.toLocaleString()}-bin cut reaches ${kt(i*e.mc.binsize)} at this file’s ${e.mc.binsize.toLocaleString()} bp resolution, so every band is a quantile of what is within that.`);const a=te(e.params,"sequences");if(a!==null&&a.length===0)return e.note("No sequence is ticked, so there is nothing to measure."),[];const{units:c,missing:u}=cm(e,a),l=be(e.mc,u,c.length);if(l!==null&&e.note(l),c.length===0)return[];const h=c.filter(A=>A.span.to-A.span.from>=4),f=c.length-h.length;if(h.length===0)return e.note("No sequence in this file is long enough to have a distribution of separations."),[];f>0&&e.note(`${f.toLocaleString()} ${f===1?"sequence is":"sequences are"} shorter than four bins and were left out: there is no distribution of separations on them.`);const d=e.mc.nBins,m=r.map(()=>new Float32Array(d).fill(Number.NaN)),g=Ft(e,h.map(A=>A.span),t);let p=0;for(let A=0;A<h.length;A++){const N=h[A],I=N.span.to-N.span.from,M=rm(e.params,I,N.circular);await e.breathe(),e.progress(A,h.length,N.name),N.circular&&p++;const x=await Oe(e,N.span,{hi:M,block:g,balance:t,value:n,circular:N.circular,onTile:async(S,k)=>{await e.breathe(),e.progress(A,h.length,k===1?N.name:`${N.name} · strip ${Math.min(S+1,k)} of ${k}`)}}),v=sm(x,{quantiles:r,maxDistance:M,ignoreDiags:o,minValid:s});for(let S=0;S<v.length;S++){const k=v[S].distance,C=m[S];for(let B=0;B<k.length;B++)C[N.span.from+B]=k[B]*e.mc.binsize}}e.progress(h.length,h.length,"done"),p>0&&e.note(`${p.toLocaleString()} of ${h.length.toLocaleString()} ${h.length===1?"sequence was":"sequences were"} read as circular, so a separation is the shorter of the two ways round and reaches at most half the sequence.`);const w=am(r.length),b=i===0?"":` · within ${kt(i*e.mc.binsize)}`;return r.map((A,N)=>({kind:"profile",id:`scalogram-q${Math.round(A*100)}${i===0?"":`-${i}b`}`,label:`Scalogram ${Math.round(A*100)} %${b}`,values:m[N],extent:[0,d],binsize:e.mc.binsize,unit:"bp",colour:w[N],group:im,mode:"ribbon",groupMode:"overlay",scale:"log2"}))};function um(e,t){const n=[],s=Math.min(e.length,t.length);let o=0,r=0;for(let i=1;i<s;i++){const a=hm(e[i],t[i]);if(a===null)continue;const c=fm(a.x,a.y),u=(a.n+1)/12;n.push({k:i,n:a.n,r:c,weight:u}),o+=u*(Number.isFinite(c)?c:0),r+=u}return{scc:r>0?o/r:Number.NaN,strata:n}}function hm(e,t){const n=Math.min(e.length,t.length),s=c=>Number.isFinite(e[c])&&Number.isFinite(t[c])&&(e[c]!==0||t[c]!==0);let o=0;for(let c=0;c<n;c++)s(c)&&o++;if(o<2)return null;const r=new Float64Array(o),i=new Float64Array(o);let a=0;for(let c=0;c<n;c++)s(c)&&(r[a]=e[c],i[a]=t[c],a++);return{x:r,y:i,n:o}}function fm(e,t){const n=e.length;let s=0,o=0;for(let c=0;c<n;c++)s+=e[c],o+=t[c];s/=n,o/=n;let r=0,i=0,a=0;for(let c=0;c<n;c++){const u=e[c]-s,l=t[c]-o;r+=u*l,i+=u*u,a+=l*l}return r/Math.sqrt(i*a)}function dm(e,t,n,s){const o=e.size,r=s[0].length,i=o+1,a=new Float64Array(i*i),c=new Float64Array(i*i),u=new Float64Array(i*i);for(let f=0;f<o;f++){const d=f*o,m=f*i,g=(f+1)*i;for(let p=0;p<o;p++){const b=p-f>=1&&p-f<=n?e.values[d+p]:0,y=Number.isNaN(b);a[g+p+1]=(y?0:b)+a[g+p]+a[m+p+1]-a[m+p],c[g+p+1]=(y?1:0)+c[g+p]+c[m+p+1]-c[m+p],u[g+p+1]=(!y&&b!==0?1:0)+u[g+p]+u[m+p+1]-u[m+p]}}const l=(f,d,m,g,p)=>p[(m+1)*i+g+1]-p[f*i+g+1]-p[(m+1)*i+d]+p[f*i+d],h=f=>t+1+Math.min(Math.min(f,r-1-f),t);for(let f=e.ownFrom;f<e.ownTo;f++){const d=f-e.from;for(let m=1;m<s.length&&m<=n;m++){const g=d+m;if(g>=o)break;const p=Math.max(0,d-t),w=Math.min(o-1,d+t),b=Math.max(0,g-t),y=Math.min(o-1,g+t),A=h(f)*h(f+m)-l(p,b,w,y,c);if(!(A>0)){s[m][f]=Number.NaN;continue}s[m][f]=l(p,b,w,y,u)>0?l(p,b,w,y,a)/A:0}}}function mm(e,t){const n=[];for(let s=0;s<=t;s++)n.push(new Float64Array(e).fill(Number.NaN));return n}const uc=500;function gm(e){const t=typeof e.maxDistance=="number"?e.maxDistance:uc;return Math.max(1,Math.min(uc,Math.round(t)))}const pm=async e=>{const t=e.inputs.peers??[];if(t.length===0)return e.note("No second map is open. Press + along the edge of the map to open a cell beside it, and drop another file in."),[];if(e.peer===void 0)throw new Error("Reproducibility reads a second file, and this venue cannot open one. Run it in the app, or with `chromosomix hicrep <file> --against <other>`.");const n=te(e.params,"sequences");if(n!==null&&n.length===0)return e.note("No sequence is ticked, so there is nothing to compare over."),[];const s=nt(e.params,"balance",!1),o=e.framing.value===""?j:e.framing.value,r=Math.max(0,Math.round(Q(e.params,"smooth",1))),i=gm(e.params),a=[{label:e.inputs.mapLabel??"This map",mc:e.mc,lead:!0}];try{for(let c=0;c<t.length;c++){e.progress(c,t.length,`opening ${t[c].label}`);const u=await e.peer(t[c]);if(u.mc.binsize!==e.mc.binsize){e.note(`${t[c].label} is at ${u.mc.binsize?.toLocaleString()??"?"} bp and this map is at ${e.mc.binsize.toLocaleString()} bp, so their strata are different separations and they are left out. Open them at one resolution.`),u.close();continue}a.push({label:t[c].label,mc:u.mc,lead:!1,close:u.close})}return a.length<2?(e.note("No map beside this one could be compared with it, so there is nothing to report."),[]):await wm(e,a,{balance:s,value:o,h:r,maxK:i})}finally{for(const c of a)c.close?.()}};async function wm(e,t,n){const{balance:s,value:o,h:r,maxK:i}=n,a=te(e.params,"sequences"),c=[],u=[];if(a===null)for(let x=0;x<e.mc.nContigs;x++)c.push(x);else for(const x of a){const v=Be(e.mc,x);v>=0?c.push(v):u.push(x)}const l=be(e.mc,u,c.length);if(l!==null&&e.note(l),c.length===0)return[];const h=t.length,f=new Float64Array(h*h),d=new Float64Array(h*h),m=[],g=[],p=[];for(let x=0;x<h*(h-1)/2;x++)g.push(new Float64Array(i+1)),p.push(new Float64Array(i+1));const w=Ft(e,c.map(x=>pr(e.mc,x)),s);for(let x=0;x<c.length;x++){await e.breathe();const v=c[x],S=e.mc.chromnames[v];e.progress(x,c.length,S);const k=pr(e.mc,v),C=k.to-k.from;if(C<3)continue;const B=[];let F=!1;for(const _ of t){const $=_.lead?k:Am(_.mc,S);if($===null){F=!0;break}if($.to-$.from!==C){e.note(`${S} is ${C.toLocaleString()} bins here and ${($.to-$.from).toLocaleString()} in ${_.label}, so it is left out.`),F=!0;break}B.push(await bm(e,_,$,{balance:s,value:o,h:r,maxK:Math.min(i,C-1),bins:C,block:_.lead?w:null}))}if(F)continue;let E=0;for(let _=0;_<h;_++)for(let $=_+1;$<h;$++){const O=um(B[_],B[$]),L=_*h+$;for(const D of O.strata)f[L]+=D.weight*(Number.isFinite(D.r)?D.r:0),d[L]+=D.weight,Number.isFinite(D.r)&&(g[E][D.k]+=D.weight*D.r,p[E][D.k]+=D.weight);m.push({sequence:S,a:t[_].label,b:t[$].label,scc:O.scc,strata:O.strata.length}),E++}}e.progress(c.length,c.length,"done"),e.throwIfCancelled();const b=new Float32Array(h*h);for(let x=0;x<h;x++){b[x*h+x]=1;for(let v=x+1;v<h;v++){const S=x*h+v,k=d[S]>0?f[S]/d[S]:Number.NaN;b[x*h+v]=k,b[v*h+x]=k}}const y=t.map(x=>x.label),A=[{kind:"matrix",id:"hicrep",label:"Stratum-adjusted correlation",nrows:h,ncols:h,values:b,xLabel:"",yLabel:"",xTicks:y,yTicks:y,colormap:"RdBu_r",range:[0,1],stats:[{label:"sequences",value:c.length,digits:0}],acrossMaps:!0}],N=[];for(let x=0;x<h;x++)for(let v=x+1;v<h;v++)N.push({a:y[x],b:y[v],scc:b[x*h+v]});A.push({kind:"table",id:"hicrep-pairs",label:"Pooled over every sequence",columns:[{key:"a",label:"Map",kind:"text"},{key:"b",label:"Map",kind:"text"},{key:"scc",label:"SCC",kind:"number",digits:4,hint:"Every stratum of every sequence, each weighted by the positions it compares."}],rows:N.sort((x,v)=>Number(v.scc)-Number(x.scc)),acrossMaps:!0}),m.length>0&&A.push({kind:"table",id:"hicrep-sequences",label:"Per sequence",columns:[{key:"sequence",label:"Sequence",kind:"text"},{key:"a",label:"Map",kind:"text"},{key:"b",label:"Map",kind:"text"},{key:"scc",label:"SCC",kind:"number",digits:4},{key:"strata",label:"Strata",kind:"number",digits:0}],rows:m,acrossMaps:!0});const I=[];let M=0;for(let x=0;x<h;x++)for(let v=x+1;v<h;v++){const S=new Float64Array(i+1),k=new Float64Array(i+1);for(let C=0;C<=i;C++)S[C]=e.toBp(C),k[C]=p[M][C]>0?g[M][C]/p[M][C]:Number.NaN;I.push({name:`${y[x]} vs ${y[v]}`,x:S,y:k}),M++}return I.length>0&&A.push({kind:"curve",id:"hicrep-strata",label:"Correlation by separation",series:I,xLabel:"Genomic separation (bp)",yLabel:"Pearson r on that stratum",xScale:"log",yScale:"linear",yDomain:[-.2,1],acrossMaps:!0}),A}async function bm(e,t,n,s){const o=mm(s.bins,s.maxK),r=s.maxK+s.h,i=t.lead?e:{...e,mc:t.mc};return await P0(i,n,{halo:r,block:s.block,balance:s.balance,value:s.value},a=>{e.throwIfCancelled(),dm(a,s.h,s.maxK,o)}),o}function pr(e,t){const[n,s]=e.contigExtent(t);return{from:n,to:s}}function Am(e,t){const n=Be(e,t);return n<0?null:pr(e,n)}function ym(e){const t=[];return e.total!==!1&&t.push("total"),e.cis===!0&&t.push("cis"),e.trans===!0&&t.push("trans"),e.fraction===!0&&t.push("fraction"),t}const Nm={total:{label:"Coverage · total",unit:"contacts"},cis:{label:"Coverage · cis",unit:"contacts"},trans:{label:"Coverage · trans",unit:"contacts"},fraction:{label:"Cis fraction",unit:""}},Mm=async e=>{const t=ym(e.params);if(t.length===0)return e.note("Every output was turned off, so there is nothing to compute."),[];const n=nt(e.params,"balance",!1),s=e.mc,o=[];for(let h=0;h<s.nContigs;h++){const[f,d]=s.contigExtent(h);o.push({startBin:f,bins:Math.max(0,d-f)})}const r=ee(s,n),i=new H0(s.nBins,eo(o,s.nBins),r===null?null:h=>Number.isFinite(r[h])),a=e.inputs.block;a!==void 0&&a.binsPerCell===1&&e.framing.balance===n&&a.rowExtent[0]===0&&a.rowExtent[1]===s.nBins&&a.colExtent[0]===0&&a.colExtent[1]===s.nBins&&a!==void 0?(e.progress(0,1,"summing the block on screen"),i.addBlock(a)):(e.framing.value!==""&&e.framing.value!==j&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${j}. These marginals are of the counts.`),e.progress(0,1,"reading pixels"),await s.scanPixels({onChunk:h=>{e.throwIfCancelled(),i.addPixels(h.bin1,h.bin2,h.count,h.length,r)},onProgress:(h,f)=>e.progress(h,f,"reading pixels")})),e.throwIfCancelled();const u=i.finish(),l={total:u.total,cis:u.cis,trans:u.trans,fraction:u.cisFraction};return t.map(h=>{const f=Nm[h];return{kind:"profile",id:`coverage-${h}`,label:f.label,values:Float32Array.from(l[h]),extent:[0,s.nBins],binsize:s.binsize,unit:f.unit}})},Kt=1,Wt=2,Yt=4,Rt=8,Im=Kt|Wt|Yt|Rt,xm=(()=>{const e=new Uint8Array(256),t={A:Kt,C:Wt,G:Yt,T:Rt,U:Rt,R:Kt|Yt,Y:Wt|Rt,S:Yt|Wt,W:Kt|Rt,K:Yt|Rt,M:Kt|Wt,B:Wt|Yt|Rt,D:Kt|Yt|Rt,H:Kt|Wt|Rt,V:Kt|Wt|Yt,N:Im};for(const[n,s]of Object.entries(t))e[n.charCodeAt(0)]=s,e[n.toLowerCase().charCodeAt(0)]=s;return e})();(()=>{const e=new Uint8Array(16);for(let t=0;t<16;t++){let n=0;(t&Kt)!==0&&(n|=Rt),(t&Wt)!==0&&(n|=Yt),(t&Yt)!==0&&(n|=Wt),(t&Rt)!==0&&(n|=Kt),e[t]=n}return e})();function hc(e){return!(e instanceof Uint8Array)}const fc=200;function dc(e){const t=e.replace(/\s+/g,"");if(t==="")return{reason:"Type a sequence to search for."};if(t.length>fc)return{reason:`${t.length} bases is longer than this searches for (${fc}). It looks for short motifs, so a query that long is a job for an aligner.`};const n=new Uint8Array(t.length);for(let s=0;s<t.length;s++){const o=xm[t.charCodeAt(s)]??0;if(o===0)return{reason:`“${t[s]}” is not a IUPAC base. Use A C G T U and the ambiguity codes R Y S W K M B D H V N.`};n[s]=o}return n}const g1=[{name:"DpnII",site:"GATC",cut:0},{name:"HindIII",site:"AAGCTT",cut:1},{name:"NcoI",site:"CCATGG",cut:1},{name:"EcoRI",site:"GAATTC",cut:1},{name:"BglII",site:"AGATCT",cut:1},{name:"HinfI",site:"GANTC",cut:1},{name:"DdeI",site:"CTNAG",cut:1},{name:"MseI",site:"TTAA",cut:1},{name:"NlaIII",site:"CATG",cut:4},{name:"CviQI",site:"GTAC",cut:1},{name:"AluI",site:"AGCT",cut:2}],vm={MboI:"DpnII",Sau3AI:"DpnII",Csp6I:"CviQI"},Ps={Arima:["DpnII","HinfI"]},km=(()=>{const e=new Map;for(const t of g1)e.set(t.name.toLowerCase(),t);for(const[t,n]of Object.entries(vm)){const s=e.get(n.toLowerCase());s!==void 0&&e.set(t.toLowerCase(),s)}return e})();function yn(e){return km.get(e.trim().toLowerCase())}function mc(e){const t=e.trim().toLowerCase();return Object.keys(Ps).find(n=>n.toLowerCase()===t)}function Sm(e){return`${e.site.slice(0,e.cut)}^${e.site.slice(e.cut)}`}function Cm(e){return e.site.length-2*e.cut}const Fm=1/256,gc=255;function pc(e){let t=1;for(const n of e){let s=0;for(let o=n;o!==0;o&=o-1)s++;t*=s/4}return t}function p1(e){const t=e.toUpperCase().replace(/U/g,"T"),n=t.indexOf("^"),s=t.replace("^","");if(n<0){const r=dc(s);return{refusal:hc(r)?`“${e}” is neither an enzyme this knows nor a site in IUPAC letters with a ^ where it cuts.`:`“${e}” needs a ^ where the enzyme cuts the top strand, as in ^GATC or G^ANTC.`}}if(s.includes("^"))return{refusal:`“${e}” has more than one ^, and a site is cut in one place.`};const o=dc(s);return hc(o)?{refusal:o.reason}:pc(o)>Fm?{refusal:`“${e}” would cut every ${Math.round(1/pc(o))} bases or so; a site needs at least the specificity of a four-base cutter.`}:{name:`${t.slice(0,n)}^${t.slice(n+1)}`,site:s,cut:n}}function $m(e){const t=yn(e);if(t!==void 0)return t;const n=p1(e);return"refusal"in n?void 0:n}function w1(e,t){const n=e.trim();if(n===""||n==="none")return[];if(n!=="custom"){const a=mc(n);if(a!==void 0)return Ps[a].map(u=>yn(u));const c=yn(n);return c===void 0?{refusal:`“${n}” is not an enzyme or a kit this knows. Pick one, or type its site under custom.`}:[c]}const s=t.split(/[\s,;]+/).filter(a=>a!=="");if(s.length===0)return{refusal:"Type an enzyme or a site, such as DpnII or G^ANTC."};const o=[],r=new Set,i=a=>{const c=`${a.site}^${a.cut}`;r.has(c)||(r.add(c),o.push(a))};for(const a of s){const c=mc(a);if(c!==void 0){for(const h of Ps[c])i(yn(h));continue}const u=yn(a);if(u!==void 0){i(u);continue}const l=p1(a);if("refusal"in l)return l;i(l)}return o.length>gc?{refusal:`That is ${o.length} enzymes, and one digest takes ${gc} at most.`}:o}function Em(e){return e.map(t=>t.name).join("+")}const Bm=256;function wc(e,t){const n=new Int32Array(e.length+2);let s=0;for(let o=0;o<e.length;o++)s=Math.min(t,Math.max(s,e[o])),n[o+1]=s;return n[e.length+1]=t,n}function bc(e,t){let n=0,s=e.length;for(;s>1;){const o=s>>1;n=e[n+o]<=t?n+o:n,s-=o}return Math.min(n,Math.max(0,e.length-2))}const Ln=["valid","re-ligation","dangling","self-circle","same-strand","trans"],Qe=["++","+-","-+","--"],Tm=0,Om=1,Lm=2,_m=3,Dm=4,Rm=5;function Ac(e,t,n,s){return e===n?t===s?Dm:t===0?Lm:_m:Math.abs(n-e)===1&&t===0&&s===1?Om:Tm}const Go=65536;function yc(e){return e==="+"?0:e==="-"?1:-1}function Pm(e){return e===0?0:33-Math.clz32(e-1)}function zm(e){if(e<=2)return String(e);const t=2**(e-1);return`${t/2+1}–${t}`}class qm{constructor(t,n,s=""){this.label=s;const o=[...n.keys()];let r=0;for(const[i,a]of t){let c=n.get(i);if(c===void 0){const l=xs(o,i);c=l<0?void 0:n.get(o[l])}if(c===void 0||!(c>0)||this.index.has(i))continue;const u=wc(a.top,c);this.index.set(i,this.names.length),this.names.push(i),this.top.push(u),this.bottom.push(wc(a.bottom,c)),this.firstFragment.push(r),r+=u.length-1}this.ends=new Uint32Array(r),this.plus=new Float64Array(this.edges.length),this.minus=new Float64Array(this.edges.length),this.distanceBin=new Uint8Array(Go);for(let i=0,a=0;i<Go;i++){for(;a+1<this.edges.length&&this.edges[a+1]<=i;)a++;this.distanceBin[i]=a}}names=[];top=[];bottom=[];firstFragment=[];index=new Map;ends;classCounts=new Float64Array(Ln.length*Qe.length);edges=ql();plus;minus;counted=0;unassigned=0;last1="";lastAt1=-1;last2="";lastAt2=-1;nearContig1=-1;nearAt1=0;nearContig2=-1;nearAt2=0;distanceBin;indexOf(t){const n=this.index.get(t);if(n!==void 0)return n;const s=xs(this.names,t);return this.index.set(t,s),s}add(t,n,s,o,r,i,a){if(a)return;const c=yc(s),u=yc(i);if(c<0||u<0||t==="!"||o==="!"||n!==n||r!==r)return;let l;t===this.last1?l=this.lastAt1:(l=this.indexOf(t),this.last1=t,this.lastAt1=l);let h;if(o===this.last2?h=this.lastAt2:(h=this.indexOf(o),this.last2=o,this.lastAt2=h),l<0||h<0){this.unassigned++;return}this.counted++;const f=n-1,d=r-1,m=c===0?this.top[l]:this.bottom[l];let g=this.nearAt1;(l!==this.nearContig1||!(f>=m[g]&&f<m[g+1]))&&(g=bc(m,f),this.nearContig1=l,this.nearAt1=g);const p=u===0?this.top[h]:this.bottom[h];let w=this.nearAt2;(h!==this.nearContig2||!(d>=p[w]&&d<p[w+1]))&&(w=bc(p,d),this.nearContig2=h,this.nearAt2=w),this.ends[this.firstFragment[l]+g]++,this.ends[this.firstFragment[h]+w]++,this.distanceOf(l,g,f,c),this.distanceOf(h,w,d,u);let b,y;l!==h?(b=Rm,y=c*2+u):d<f?(b=Ac(w,u,g,c),y=u*2+c):(b=Ac(g,c,w,u),y=c*2+u),this.classCounts[b*Qe.length+y]++}distanceOf(t,n,s,o){const r=o===0?this.top[t][n+1]-s:s-this.bottom[t][n]+1;let i=0;if(r>=0&&r<Go)i=this.distanceBin[r];else if(r>0){const a=this.edges;let c=a.length;for(;c-i>1;){const u=i+c>>1;a[u]<=r?i=u:c=u}}o===0?this.plus[i]++:this.minus[i]++}result(){const t={},n={};Ln.forEach((r,i)=>{const a={};let c=0;Qe.forEach((u,l)=>{const h=this.classCounts[i*Qe.length+l];a[u]=h,c+=h}),t[r]=c,n[r]=a});const s=[];let o=0;for(let r=0;r<this.ends.length;r++){const i=this.ends[r];i>0&&o++;const a=Pm(i);for(;s.length<=a;)s.push(0);s[a]++}return{enzymes:this.label,counted:this.counted,unassigned:this.unassigned,classes:t,byOrientation:n,distanceEdges:[...this.edges],distance:{"+":Array.from(this.plus),"-":Array.from(this.minus)},fragments:{total:this.ends.length,seen:o,binLabels:s.map((r,i)=>zm(i)),counts:s}}}}function Um(e){const t=e.outputs.find(i=>i.kind==="intervals"&&i.id.startsWith("restriction-")&&i.payload.kind==="features");if(t===void 0||t.payload.kind!=="features")return null;const n=t.payload.data,s=new Map,o=new Map,r=new Map;for(let i=0;i<n.contigs.length;i++){const a=n.contigAt[i]??0,c=n.contigAt[i+1]??a,u=n.start.slice(a,c),l=new Int32Array(u.length),h=new Uint8Array(u.length);for(let f=0;f<u.length;f++){const d=n.name[a+f]??"";let m=o.get(d);if(m===void 0){const g=$m(d);m=g===void 0?0:Cm(g),o.set(d,m),r.set(d,Math.min(Bm-1,r.size))}l[f]=u[f]+m,h[f]=r.get(d)??0}s.set(n.contigs[i],{top:u,bottom:l,enzyme:h})}return s}const Nc=["++","+−","−+","−−"],Ho=16;function Gm(e,t={}){const n=Math.max(1.01,t.factor??1.1),s=e.edges;if(s.length<3)return null;const o=Hm(s,1,n);if(o===null||o.length<3)return null;const r=o.map(d=>s[d]),i=o.length-1,a=[new Float64Array(i),new Float64Array(i),new Float64Array(i),new Float64Array(i)],c=[0,0,0,0];for(let d=0;d<i;d++)for(let m=o[d];m<o[d+1];m++)for(let g=0;g<4;g++){const p=e.counts[g][m];p>0&&(a[g][d]+=p,c[g]+=p)}const u=c[0]+c[1]+c[2]+c[3];if(u===0)return null;const l=[],h=[];for(let d=0;d<4;d++){if(c[d]===0)continue;const m=new Float64Array(i),g=new Float64Array(i);for(let p=0;p<i;p++)m[p]=Math.sqrt(r[p]*r[p+1]),g[p]=a[d][p]>0?a[d][p]/(u*(r[p+1]-r[p])):Number.NaN;l.push({name:Nc[d],x:m,y:g,n:c[d]}),h.push({name:Nc[d],...Qm(a[d],r,u),n:c[d]})}if(h.length<2)return null;const f=Km(l);return{curves:h,convergence:f.at,spreadAt:f.spread}}function Hm(e,t,n){const s=e.length-1;let o=0;for(;o<s&&e[o]<t;)o++;if(o>=s)return null;const r=[o];for(;o<s;){const i=e[o]*n;let a=o+1;for(;a<s&&Math.abs(Math.log(e[a+1]/i))<Math.abs(Math.log(e[a]/i));)a++;r.push(a),o=a}return r}function Qm(e,t,n){let s=0,o=e.length-1;for(;s<=o&&!(e[s]>0);)s++;for(;o>=s&&!(e[o]>0);)o--;const r=[],i=[],a=(u,l,h)=>{const f=t[u],d=t[l+1];r.push(Math.sqrt(f*d)),i.push(h/(n*(d-f)))};let c=s;for(;c<=o;){if(e[c]>=Ho){a(c,c,e[c]),c++;continue}let u=c;for(;u<o&&e[u+1]<Ho;)u++;const l=[];let h=c,f=0;for(let d=c;d<=u;d++)f+=e[d],!(f<Ho)&&(l.push([h,d,f]),h=d+1,f=0);if(h<=u){const d=l[l.length-1];d!==void 0?(d[1]=u,d[2]+=f):f>0&&l.push([h,u,f])}for(const[d,m,g]of l)a(d,m,g);c=u+1}return{x:Float64Array.from(r),y:Float64Array.from(i)}}function Km(e){const t=e[0].x.length;let n=null,s=Number.NaN;for(let o=t-1;o>=0;o--){let r=Number.POSITIVE_INFINITY,i=0,a=0;for(const u of e){const l=u.y[o];!Number.isFinite(l)||l<=0||(a++,l<r&&(r=l),l>i&&(i=l))}if(a<e.length){if(n!==null)break;continue}const c=Math.log10(i/r);if(c>.1)break;n=e[0].x[o],s=c}return{at:n,spread:s}}[...g1.map(e=>({value:e.name,label:`${e.name} (${Sm(e)})`})),...Object.entries(Ps).map(([e,t])=>({value:e,label:`${e} (${t.join(" + ")})`}))];function Wm(e){const t=e.pairs;return typeof t=="string"?t.trim():""}function Ym(e){const t=e.reference;return typeof t=="string"?t:""}function Vm(e){const t=e.enzyme;return typeof t=="string"&&t!==""?t:"none"}function Xm(e){const t=e.sites;return typeof t=="string"?t:""}function Jm(e){const t=Ym(e),n=Vm(e);return t===""||n==="none"?null:{sequence:t,enzyme:n,sites:Xm(e)}}const Zm=async e=>{const t=Wm(e.params),n=e.inputs.mapSource,s=jm(e);let o=t===""?e.inputs.pairsStats??null:null,r=t===""?e.inputs.orientation??null:null,i=null,a=`as ${xc(e.framing.uri)} was binned`;const c=t!==""||s!==null||o===null&&n!==void 0;if(c){const l=t!==""?t:xc(e.framing.uri),h=t!==""?await b1(e,t,e.inputs.sources?.pairs):n!==void 0?await i7(e,n,l):null;if(h!==null)try{const f=await o7(e,l,h,s);f!==null&&(o===null&&f.stats!==null&&(a=`in one pass over ${l}`),o??=f.stats,r??=f.orientation,i=f.restriction)}finally{h.close()}}if(o===null&&r===null&&i===null)return t===""&&n===void 0&&!c&&e.note("This map was opened as a matrix, which keeps no records, so there is nothing to count. Name the .pairs it was binned from."),[];const u=[];if(r!==null){const l=A1(e,r,"pairsqc-orientation",{converge:!1});l!==null&&(u.push(l),o!==null&&e.note(a7(o)))}else o!==null&&e.note("The records carry no strand1/strand2 columns, so there is no P(s) by orientation: which way a read pointed is the whole of what that figure is about.");if(o!==null){o.scoped&&e.note("The import read part of the file, so these counts are of the part it read.");const l=c7(o);l!==null?u.push(l):e.note("The records carry no pair_type column, so pair types are not counted."),u.push(l7(o),u7(o)),e.note(`The pairtools statistics were counted ${a}: ${o.total.toLocaleString("en-US")} records, ${o.totalNodups.toLocaleString("en-US")} of them mapped on both sides and not duplicates.`)}if(i!==null&&(u.push(...h7(e,i)),s!==null)){const l=await b7(e,s,i.enzymes);l!==null&&u.push(l)}return u};function jm(e){const t=Jm(e.params),n=e.inputs.upstream?.restriction;if(t===null)return ct(e.params,"enzyme","none")!=="none"&&e.note("An enzyme was chosen with no reference to find its sites in, so there are no restriction statistics."),null;const s=w1(ct(t,"enzyme","none"),ct(t,"sites",""));if(!Array.isArray(s))throw new Error(s.refusal);if(n===void 0)return e.note("The restriction step did not run, so there are no restriction statistics."),null;const o=Um(n);return o===null?(e.note("The restriction step found no sequence to cut, so there are no restriction statistics."),null):o}function t7(e){const t=w1(ct(e.params,"enzyme","none"),ct(e.params,"sites",""));return Array.isArray(t)?Em(t):""}const e7=43,n7=45,s7=33,Mc=68;function Ic(e){return e===e7?"+":e===n7?"-":"."}async function o7(e,t,n,s){e.progress(0,1,"reading records");const o=await Ys(n),r=s===null?null:r7(e,s,o.contigs),i=o.contigs.map(f=>f.name),a=new TextDecoder,c=(f,d,m,g)=>d>=0?i[d]:g-m===1&&f[m]===s7?"!":a.decode(f.subarray(m,g)),u=r===null?void 0:(f,d,m,g,p,w,b,y,A,N,I,M,x)=>{const v=x-M===2&&f[M]===Mc&&f[M+1]===Mc;r.add(c(f,d,m,g),y<0?Number.NaN:y,Ic(N),c(f,p,w,b),A<0?Number.NaN:A,Ic(I),v)};let l=0;for(const f of o.contigs)l=Math.max(l,f.length);const h=await Hr(n,{binSize:Math.max(1,l),contigs:o.contigs,columns:o.columns,onProgress:(f,d)=>e.progress(f,d,"reading records"),cancelled:()=>e.cancelled(),...u===void 0?{}:{onRecord:u}});return e.throwIfCancelled(),h===null?null:(h.skippedUnknownContig>0&&r!==null&&e.note(`${h.skippedUnknownContig.toLocaleString("en-US")} records of ${t} name a sequence its header does not declare.`),{stats:h.stats??null,orientation:h.orientation??null,restriction:r===null?null:r.result()})}function r7(e,t,n){const s=new Map;for(const a of n)s.set(a.name,a.length);const o=e.mc;for(const a of o.chromnames){const c=o.chromsizes.get(a);c!==void 0&&!s.has(a)&&s.set(a,c)}const r=[...s.keys()],i=[...t.keys()].filter(a=>!s.has(a)&&xs(r,a)<0);return i.length>0&&e.note(`${i.length.toLocaleString("en-US")} of the reference's sequences (${i.slice(0,3).join(", ")}${i.length>3?", …":""}) are in neither the .pairs header nor the map, so their fragments are not counted.`),new qm(t,s,t7(e))}function xc(e){return e.split("::")[0].split(/[?#]/)[0].split(/[\\/]/).filter(s=>s!=="").pop()??e}async function i7(e,t,n){if(e.openSource===void 0)return e.note(`Reading ${n} again needs a venue that can open a file it was handed, and this one cannot.`),null;try{return await e.openSource(t)}catch(s){return e.note(`Could not open ${n}: ${s instanceof Error?s.message:String(s)}`),null}}async function b1(e,t,n){const s=/^(https?|s3):\/\//i.test(t),o=n!==void 0&&e.openSource!==void 0?()=>e.openSource(n):s&&e.openBytes!==void 0?()=>e.openBytes(t):!s&&e.openFile!==void 0?()=>e.openFile(t):null;if(o===null)return e.note(s?`Reading ${t} needs a venue that can fetch an address, and this one reads local files only. Fetch it first and name the file, or run it in the app.`:`“${t}” is not an address this can fetch, and the file is no longer in hand — a dropped file is kept for the session it was dropped in. Drop it on the form again, or name it on a \`chromosomix\` command line, which reads it from disk.`),null;try{return await o()}catch(r){return e.note(`Could not open ${t}: ${r instanceof Error?r.message:String(r)}`),null}}function A1(e,t,n,s={}){const o=s.factor??Math.max(1.01,Q(e.params,"factor",1.1)),r=Gm(t,{factor:o});return r===null?(e.note("Fewer than two orientations have any cis record in them, so there is nothing to compare. A file whose strand columns are all `.` reads this way."),null):(s.converge!==!1&&e.note(r.convergence===null?"The four orientations never settle to within a tenth of each other, so no convergence point is reported. On a library that is otherwise fine this usually means the axis does not reach far enough — the sequences are short — rather than that the records are bad.":`The four orientations converge at about ${Math.round(r.convergence).toLocaleString()} bp, which is the shortest separation this library can be read at. Below it the counts are self-circles, dangling ends and undigested fragments rather than contacts.`),{kind:"curve",id:n,label:"P(s) by pair orientation",series:r.curves.map(i=>({name:i.name,x:i.x,y:i.y,n:i.n})),xLabel:"Genomic separation (bp)",yLabel:"Density, over the records in all four",xScale:"log",yScale:"log"})}function a7(e){const t=Ul(e),n=s=>e.cis>0?`${(100*s/e.cis).toFixed(1)} %`:"—";return t.distance===null?"No orientation strays more than 5 % from the mean of the four at any separation, so pairtools reports no convergence distance: the four agree from the first base pair.":`The four orientations converge at ${t.distance.toLocaleString("en-US")} bp by pairtools' rule: past the last separation bin at which one of them (${t.strands??"?"}) strays more than 5 % from the mean of the four, with ${n(t.belowAll)} of the cis pairs below it. The furthest such bin sets it, so a sparse tail of chance strays can put it well past where the curves lie together.`}function so(e){return Float64Array.from(e,(t,n)=>n)}function c7(e){if(e.pairTypes.length===0)return null;const t=e.pairTypes.map(([n])=>n);return{kind:"curve",id:"pairsqc-types",label:"Pair types",series:[{name:"records",x:so(t),y:Float64Array.from(e.pairTypes,([,n])=>n),mark:"bars",n:e.total}],xLabel:"Pair type",yLabel:"Records",xScale:"linear",yScale:"linear",xTicks:t}}function l7(e){const t=["cis","trans",...e.cisAtLeast.map(([o])=>`cis_${o}kb+`)],n=[e.cis,e.trans,...e.cisAtLeast.map(([,o])=>o)],s=o=>e.totalNodups>0?o/e.totalNodups:Number.NaN;return{kind:"curve",id:"pairsqc-cis",label:"Cis and trans",series:[{name:"fraction",x:so(t),y:Float64Array.from(n,s),mark:"bars",n:e.totalNodups}],xLabel:"Pairs",yLabel:"Share of the mapped pairs that are not duplicates",xScale:"linear",yScale:"linear",yDomain:[0,1],xTicks:t}}function u7(e){const t=l3(e).filter(([n])=>!/^(chrom_freq|dist_freq|chromsizes)\//.test(n)).map(([n,s])=>({statistic:n,value:u3(s)}));return{kind:"table",id:"pairsqc-stats",label:"pairtools stats",columns:[{key:"statistic",label:"Statistic",kind:"text"},{key:"value",label:"Value",kind:"text"}],rows:t}}function h7(e,t){const n=t.enzymes===""?"the enzyme":t.enzymes;return e.note(`${t.counted.toLocaleString("en-US")} pairs were placed in ${n}'s ${t.fragments.total.toLocaleString("en-US")} fragments`+(t.unassigned>0?`; ${t.unassigned.toLocaleString("en-US")} more had an end on a sequence the reference has not got, and are not classified.`:".")),[f7(t,n),d7(t,n),m7(t,n),g7(t,n)]}function f7(e,t){const n=[...Ln],s=so(n);return{kind:"curve",id:"pairsqc-classes",label:`Pair classes by orientation · ${t}`,series:Qe.map(o=>({name:o,x:s,y:Float64Array.from(Ln,r=>e.byOrientation[r][o]),mark:"bars",stack:"orientation"})),xLabel:"Class",yLabel:"Pairs",xScale:"linear",yScale:"linear",xTicks:n}}function d7(e,t){return{kind:"table",id:"pairsqc-classes-table",label:`Pair classes · ${t}`,columns:[{key:"class",label:"Class",kind:"text"},{key:"pairs",label:"Pairs",kind:"number"},{key:"share",label:"Share",kind:"number",digits:4},...Qe.map(n=>({key:n,label:n,kind:"number"}))],rows:Ln.map(n=>({class:n,pairs:e.classes[n],share:e.counted>0?e.classes[n]/e.counted:Number.NaN,...e.byOrientation[n]}))}}function m7(e,t){const n=e.distanceEdges,s=e.distance["+"],o=e.distance["-"];let r=n.length,i=-1;for(let u=1;u<n.length;u++)(s[u]>0||o[u]>0)&&(r=Math.min(r,u),i=u);const a=i<r?[]:Array.from({length:i-r+1},(u,l)=>r+l),c=Float64Array.from(a,u=>n[u]);return{kind:"curve",id:"pairsqc-distance",label:`Distance from a read to the next ${t} cut`,series:[{name:"+",x:c,y:Float64Array.from(a,u=>s[u])},{name:"-",x:c,y:Float64Array.from(a,u=>o[u])}],xLabel:"Distance to the cut (bp, bin start)",yLabel:"Read ends",xScale:"log",yScale:"linear"}}function g7(e,t){const{total:n,seen:s,binLabels:o,counts:r}=e.fragments;return{kind:"curve",id:"pairsqc-fragments",label:`Read ends per ${t} fragment · ${s.toLocaleString("en-US")} / ${n.toLocaleString("en-US")} fragments seen`,series:[{name:"fragments",x:so(o),y:Float64Array.from(r),mark:"bars",n}],xLabel:"Read ends in the fragment",yLabel:"Fragments",xScale:"linear",yScale:"linear",xTicks:[...o]}}const p7=5,w7="five";async function b7(e,t,n){const s=e.mc,o=[];for(let w=0;w<s.nContigs;w++){const[b,y]=s.contigExtent(w);o.push({startBin:b,bins:Math.max(0,y-b)})}const r=[...t.keys()],i=new Float64Array(s.nBins),a=new Uint8Array(s.nBins);for(let w=0;w<s.nContigs;w++){const b=xs(r,s.chromnames[w]);if(b<0)continue;const{startBin:y,bins:A}=o[w];a.fill(1,y,y+A);for(const N of t.get(r[b])?.top??[]){const I=y+Math.floor(N/s.binsize);I<y+A&&i[I]++}}e.progress(0,1,"reading pixels");const c=new H0(s.nBins,eo(o,s.nBins));await s.scanPixels({onChunk:w=>{e.throwIfCancelled(),c.addPixels(w.bin1,w.bin2,w.count,w.length,null)},onProgress:(w,b)=>e.progress(w,b,"reading pixels")}),e.throwIfCancelled();const u=c.finish().total,l=[];let h=0;for(let w=0;w<s.nBins;w++)if(a[w]!==0){if(u[w]===0&&i[w]===0){h++;continue}l.push(w)}if(l.length===0)return e.note("No bin of the map lies on a sequence the reference has, so coverage is not set against sites."),null;l.sort((w,b)=>i[w]-i[b]||w-b);const f=Float64Array.from(l,w=>i[w]),d=Float64Array.from(l,w=>u[w]),m=new Float64Array(l.length);for(let w=0;w<l.length;){let b=w,y=0;for(;b<l.length&&f[b]===f[w];)y+=d[b++];m.fill(b-w>=p7?y/(b-w):Number.NaN,w,b),w=b}const g=Kl(f,d),p=Number.isFinite(g)?g.toFixed(3):"undefined";return e.note(`Spearman ρ = ${p} between the ${n} sites in a bin and its coverage, over ${l.length.toLocaleString("en-US")} bins of ${s.binsize.toLocaleString("en-US")} bp`+(h===0?"":`; ${h.toLocaleString("en-US")} ${h===1?"bin":"bins"} with neither ${h===1?"was":"were"} left out`)+`. The mean is drawn where at least ${w7} bins share a number of sites.`),{kind:"curve",id:"pairsqc-sites",label:`Coverage against ${n} sites · ρ = ${p}`,series:[{name:"bins",x:f,y:d,mark:"points",n:l.length},{name:"mean",x:f,y:m}],xLabel:"Restriction sites in the bin",yLabel:"Contacts (coverage)",xScale:"linear",yScale:"linear"}}function Qo(e,t,n=0){let s=0,o=0;for(const i of t){const a=i.to-i.from;s+=a,a>o&&(o=a)}const r=n>0&&t.length===1&&o===n;return{name:e,spans:t,bins:s,maxOffset:r?Math.floor(n/2):Math.max(0,o-1),lap:r?n:0}}function A7(e,t,n){const s=e.mc,o=(c,u)=>Te(e,s.chromnames[c])?u.to-u.from:0;if(t==="file"){const c=[];for(const u of $e(s,null).ids){const l=Zt(s,u);l!==null&&c.push(l)}return{units:c.length===0?[]:[Qo("All sequences",c)],missing:[]}}if(t==="genome"){if(!s.hasGenomes)throw new T("unsupported","This file is a plain cooler: it has no /genomes table, so there is nothing for a per-genome P(s) to be per. Use the contig scope, which is the same curve over the sequences this file does have.",{uri:s.uri});const c=[];for(const u of s.displayGenomes()){const[l,h]=s.genomeContigExtent(u),f=[];for(let d=l;d<h;d++){const m=Zt(s,d);m!==null&&f.push(m)}f.length>0&&c.push(Qo(s.genomeNames[u],f))}return{units:c,missing:[]}}const{ids:r,missing:i}=$e(s,n),a=[];for(const c of r){const u=Zt(s,c);u!==null&&a.push(Qo(s.chromnames[c],[u],o(c,u)))}return{units:a,missing:i}}function y7(e,t,n){return e.map(s=>{const o=new Float64Array(s.maxOffset+1);for(const r of s.spans){const i=r.to-r.from,a=s.lap;let c;for(let u=0;u<=s.maxOffset&&u<i;u++){let l;if(a>0)if(n===null)l=2*u===a?a/2:a;else{l=0;for(let h=0;h<i;h++){const f=r.from+h,d=r.from+(h+u)%a;!Number.isNaN(n[f])&&!Number.isNaN(n[d])&&l++}u>0&&2*u===a&&(l/=2)}else n===null?l=i-u:(c??=N7(n,r.from,r.to,Math.min(s.maxOffset,i-1)),l=c[u]);o[u]+=t&&u>0?l*2:l}}return o})}function N7(e,t,n,s){const o=n-t,r=new Int32Array(o+1);for(let f=0;f<o;f++)r[f+1]=r[f]+(Number.isNaN(e[t+f])?1:0);const i=r[o],a=o-i<=i,c=new Int32Array(a?o-i:i);let u=0;for(let f=0;f<o;f++)Number.isNaN(e[t+f])!==a&&(c[u++]=f);const l=new Float64Array(s+1);for(let f=0;f<u;f++){l[0]++;for(let d=f+1;d<u;d++){const m=c[d]-c[f];if(m>s)break;l[m]++}}if(a)return l;const h=new Float64Array(s+1);for(let f=0;f<=s;f++)h[f]=o-f-r[o-f]-(i-r[f])+l[f];return h}function M7(e,t,n){const s=new Float64Array(t.length);for(let o=0;o<s.length;o++)s[o]=n[o]>0?t[o]/n[o]:Number.NaN;return{maxOffset:e,sum:t,count:n,mean:s}}async function I7(e,t,n){const s=e.mc,o=new Int32Array(s.nBins).fill(-1),r=[],i=[];for(let l=0;l<t.length;l++)for(const h of t[l].spans)o.fill(r.length,h.from,h.to),r.push(l),i.push(t[l].lap);const a=ee(s,n);e.progress(0,1,"counting the pairs each separation could hold"),e.throwIfCancelled();const c=y7(t,s.storageMode==="square",a),u=t.map(l=>new Float64Array(l.maxOffset+1));return await s.scanPixels({onChunk:l=>{e.throwIfCancelled();for(let h=0;h<l.length;h++){const f=l.bin1[h],d=l.bin2[h],m=o[f];if(!(m>=0)||o[d]!==m)continue;const g=a===null?l.count[h]:l.count[h]*a[f]*a[d];if(Number.isNaN(g))continue;const p=d>f?d-f:f-d,w=i[m],b=w>0?Math.min(p,w-p):p;u[r[m]][b]+=g}},onProgress:(l,h)=>e.progress(l,h,"reading pixels")}),t.map((l,h)=>M7(l.maxOffset,u[h],c[h]))}async function x7(e,t,n,s){const o=Ft(e,t.flatMap(r=>r.spans),n);if(o!==null){const r=[];for(let i=0;i<t.length;i++){e.throwIfCancelled(),e.progress(i,t.length,t[i].name);const a=new Fn(t[i].maxOffset,t[i].lap);for(const c of t[i].spans)a.addBlock(ei(o,c));r.push(a.finish())}return{curves:r,mirrored:!0}}if(t.length===1&&t[0].spans.length===1){const r=t[0].spans[0];e.progress(0,1,t[0].name);const i=await e.mc.matrix({rows:[r.from,r.to],cols:[r.from,r.to],balance:n,value:s});e.throwIfCancelled();const a=new Fn(t[0].maxOffset,t[0].lap);return a.addBlock(i),{curves:[a.finish()],mirrored:!0}}return s!==j&&e.note(`The whole-file pass reads the count column, so the ${s} column this map is drawn from was not used. Narrow the scope to one sequence to measure that column instead.`),{curves:await I7(e,t,n),mirrored:e.mc.storageMode==="square"}}const vc=[4e3,1e6],v7=async e=>{const t=ct(e.params,"scope","contig"),n=te(e.params,"sequences"),s=Q(e.params,"factor",1.1),o=Q(e.params,"minSeparation",0),r=ct(e.params,"quantity","density")==="expected",i=nt(e.params,"derivative",!0),a=nt(e.params,"balance",!1);if(t==="contig"&&n!==null&&n.length===0)return e.note("No sequence is ticked, so there is nothing to measure."),[];const{units:c,missing:u}=A7(e,t,n),l=be(e.mc,u,c.length);if(l!==null&&e.note(l),c.length===0)return l===null&&e.note("No sequence in this file has any bins in it, so there is nothing to measure."),[];const h=c,{curves:f,mirrored:d}=await x7(e,h,a,e.framing.value);e.throwIfCancelled();const m=[],g=[];let p=0;for(let y=0;y<h.length;y++){const A=r?Kr(f[y],e.mc.binsize,s,o):Z3(f[y],e.mc.binsize,s,o,d);if(A.x.length===0){p++;continue}let N=0;for(const I of A.n)N+=I;if(m.push({name:h[y].name,x:A.x,y:A.y,n:N}),i){const I=Wl(A.x,A.y);I.x.length>0&&g.push({name:h[y].name,x:I.x,y:I.y,n:N})}}p>0&&e.note(`${p.toLocaleString()} ${p===1?"sequence":"sequences"} had no separation bin with any data in it at these settings, and so no line. A minimum separation longer than the sequence is the usual reason.`);const w=[{kind:"curve",id:"ps",label:"Contact probability P(s)",series:m,xLabel:"Genomic separation (bp)",yLabel:r?"Mean contact per bin pair":"Contact probability density (per bp)",xScale:"log",yScale:"log",xDomain:vc}];g.length>0&&w.push({kind:"curve",id:"ps-slope",label:"Log-log slope of P(s)",series:g,xLabel:"Genomic separation (bp)",yLabel:"d log P / d log s",xScale:"log",yScale:"linear",xDomain:vc});const b=await k7(e);return b!==null&&w.push(b),w};async function k7(e){if(!nt(e.params,"stranded",!1))return null;e.note("The four orientations have moved to Pairs QC, which draws them beside the rest of the library's statistics from the same records; this run drew them here because its parameters asked for them.");const t=ct(e.params,"pairsUri","").trim();let n=null;if(t===""){const s=e.inputs.orientation;if(s===void 0)return e.note("The four orientations are counted from the records, and this map has none to count: it was opened as a matrix rather than binned from a .pairs, or the file it was binned from carried no strand1/strand2 columns. Run Pairs QC and give it the .pairs."),null;n=s}else if(n=await S7(e,t,e.inputs.sources?.pairsUri),n===null)return null;return A1(e,n,"ps-orientation")}async function S7(e,t,n){const s=await b1(e,t,n);if(s===null)return null;try{return await C7(e,t,s)}finally{s.close()}}async function C7(e,t,n){e.progress(0,1,"reading records");const s=await Ys(n);if(s.columns.strand1<0||s.columns.strand2<0)return e.note(`${t} declares no strand1/strand2 columns, so its records cannot say which orientation a pair was in. \`pairtools\` writes them by default; a file trimmed of them cannot be read this way.`),null;let o=0;for(const a of s.contigs)o=Math.max(o,a.length);const r=await Hr(n,{binSize:Math.max(1,o),contigs:s.contigs,columns:s.columns,onProgress:(a,c)=>e.progress(a,c,"reading records"),cancelled:()=>e.cancelled()});if(e.throwIfCancelled(),r===null)return null;const i=r.orientation??null;return i===null?(e.note(`${t} carried strand columns but no cis record with a readable pair of strands.`),null):i}class F7{constructor(t,n){this.nBins=t,this.band=n,this.sums=new Float64Array(t),this.seen=new Uint8Array(t)}sums;seen;reachable(t){return t<this.band.to}add(t,n,s){if(!Number.isFinite(s)||t<0||n<0||t>=this.nBins||n>=this.nBins)return;const o=t>=this.band.from&&t<this.band.to,r=n>=this.band.from&&n<this.band.to;o&&(this.sums[n]+=s,this.seen[n]=1),r&&t!==n&&(this.sums[t]+=s,this.seen[t]=1)}finish(t=null){const n=new Float32Array(this.nBins);for(let s=0;s<this.nBins;s++){if(t!==null&&!t(s)){n[s]=Number.NaN;continue}n[s]=this.seen[s]===1?this.sums[s]:0}return n}}function $7(e,t,n="cols"){const{nrows:s,ncols:o,values:r}=e,i=n==="cols"?s:o,a=n==="cols"?o:s,c=new Float64Array(a),u=Math.max(0,Math.min(i,Math.trunc(t[0]))),l=Math.max(u,Math.min(i,Math.trunc(t[1])));for(let h=u;h<l;h++)for(let f=0;f<a;f++){const d=n==="cols"?r[h*o+f]:r[f*o+h];Number.isNaN(d)||(c[f]+=d)}return c}function E7(e,t){const n=e.mc,s=Ef(n,t),o={from:s.extent[0],to:Math.max(s.extent[0]+1,s.extent[1])};if(s.kind==="genome"){const[c,u]=n.genomeExtent(s.label);return{band:o,scope:{from:c,to:u},label:s.label}}const r=n.coords.contigOfBin(o.from),[i,a]=n.contigExtent(r);return{band:o,scope:{from:i,to:a},label:n.chromnames[r]}}const B7=async e=>{const t=ct(e.params,"anchor","").trim();if(t==="")return e.note("No anchor was chosen. Type a locus, or a whole sequence by name, or press “pick on map” and drag along either axis."),[];const n=nt(e.params,"balance",!1),s=e.mc.hasGenomes,o=!s&&nt(e.params,"cis",!0),r=s?"none":ct(e.params,"normalise","none"),i=r==="ps"||r==="ps+coverage",a=r==="coverage"||r==="ps+coverage",c=e.framing.value===""?j:e.framing.value,u=E7(e,t),l=o?await y1(e,u,n,c,i,a):await O7(e,u,n,i,a),h=nt(e.params,"excludeAnchor",!1);return h&&(T7(l,u.band),l.every(m=>Number.isNaN(m))&&e.note(`The anchor covers everything this profile reads, so leaving it out leaves nothing${o?" — turn off “cis only”, or name a narrower anchor.":"."}`)),[{kind:"profile",id:`fourc-${u.band.from}-${u.band.to}`,label:`4C · ${p0(t)}${o||s?"":" (with trans)"}${i?" · O/E":""}${a?" · per coverage":""}${h?" · anchor excluded":""}`,values:l,extent:[0,e.mc.nBins],binsize:e.mc.binsize,unit:i?"":"contacts"}]};function T7(e,t){e.fill(Number.NaN,Math.max(0,t.from-1),Math.min(e.length,t.to+1))}async function O7(e,t,n,s,o){const r=s?await y1(e,t,n,j,!0):null,i=o?new Float64Array(e.mc.nBins):null,a=await R7(e,t,n,i);let c=r===null?a:_7(e,a,t);if(r!==null)for(let u=t.scope.from;u<Math.min(t.scope.to,c.length);u++)c[u]=r[u];return i!==null&&(c=N1(e,c,i)),c}function L7(e,t,n){const s=new Fn(Math.max(0,t.nrows-1));s.addBlock({nrows:t.nrows,ncols:t.ncols,values:t.values,rowExtent:[t.rowExtent[0],t.rowExtent[1]],colExtent:[t.colExtent[0],t.colExtent[1]]});const o=s.finish(),r=(n[0]+n[1]-1)/2,i=new Float64Array(e.length);for(let a=0;a<e.length;a++){const c=Wr(o,Math.abs(a-r));i[a]=Number.isFinite(e[a])&&Number.isFinite(c)&&c!==0?e[a]/c:Number.NaN}return i}function _7(e,t,n){let s=0,o=0;for(let a=0;a<t.length;a++){if(a>=n.scope.from&&a<n.scope.to)continue;const c=t[a];Number.isFinite(c)&&(s+=c,o++)}if(o===0)return e.note("Nothing was reached outside this sequence, so there is no trans expectation to divide by."),t;const r=s/o,i=new Float32Array(t.length);for(let a=0;a<t.length;a++){const c=a>=n.scope.from&&a<n.scope.to,u=t[a];i[a]=c||!Number.isFinite(u)?u:r===0?Number.NaN:u/r}return i}async function y1(e,t,n,s,o=!1,r=!1){e.progress(0,1,`reading ${t.label}`);const i=e.framing.value===""?j:e.framing.value,a=s===i?Ft(e,[t.scope],n):null,c=await ni(e,t.scope,{block:a,balance:n,value:s});e.throwIfCancelled();const u=[Math.max(0,t.band.from-t.scope.from),Math.min(t.scope.to-t.scope.from,t.band.to-t.scope.from)],l=$7({nrows:c.nrows,ncols:c.ncols,values:c.values,rowExtent:[c.rowExtent[0],c.rowExtent[1]],colExtent:[c.colExtent[0],c.colExtent[1]]},u,"cols"),h=o?L7(l,c,u):l,f=new Float32Array(e.mc.nBins).fill(Number.NaN);for(let m=0;m<h.length;m++)f[t.scope.from+m]=h[m];if(!r)return f;const d=new Float64Array(e.mc.nBins);for(let m=0;m<c.nrows;m++){const g=m*c.ncols;for(let p=0;p<c.ncols;p++){const w=c.values[g+p];Number.isFinite(w)&&(d[t.scope.from+p]+=w)}}return N1(e,f,d)}function N1(e,t,n){const s=D7(n);if(s===null)return e.note("No bin carried any coverage, so there was nothing to correct for and the profile is as it was counted."),t;const o=new Float32Array(t.length).fill(Number.NaN);let r=0;for(let i=0;i<t.length;i++){const a=t[i];if(!Number.isFinite(a))continue;const c=s[i];if(!(c>0)){r++;continue}o[i]=a/c}return r>0&&e.note(`${r.toLocaleString()} ${r===1?"bin has":"bins have"} a value but no coverage to divide it by, so they are gaps rather than uncorrected numbers.`),o}function D7(e){let t=0,n=0;for(let r=0;r<e.length;r++){const i=e[r];!Number.isFinite(i)||i<=0||(t+=i,n++)}if(n===0)return null;const s=t/n,o=new Float64Array(e.length);for(let r=0;r<e.length;r++){const i=e[r];o[r]=Number.isFinite(i)&&i>0?i/s:0}return o}async function R7(e,t,n,s=null){const o=e.mc,r=ee(o,n);e.framing.value!==""&&e.framing.value!==j&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${j}. This profile is of the counts.`);const i=new F7(o.nBins,t.band);let a=!1;return await o.scanPixels({onChunk:c=>{e.throwIfCancelled();for(let u=0;u<c.length;u++){const l=c.bin1[u],h=i.reachable(l);if(!h&&s===null)return a=!0,!1;const f=c.bin2[u],d=c.count[u],m=r===null?d:d*r[l]*r[f];s!==null&&Number.isFinite(m)&&(s[l]+=m,f!==l&&(s[f]+=m)),h&&i.add(l,f,m)}return!0},onProgress:(c,u)=>{a||e.progress(c,u,"reading pixels")}}),e.throwIfCancelled(),e.progress(1,1,"done"),i.finish(r===null?null:c=>Number.isFinite(r[c]))}function P7(e){const t=typeof e.window=="number"?e.window:10;return Math.max(1,Math.round(t))}function z7(e){const t=typeof e.scales=="number"?e.scales:1;return Math.max(1,Math.min(4,Math.trunc(t)))}function q7(e){const t=P7(e),n=[];for(let s=0;s<z7(e);s++)n.push(t*2**s);return n}function U7(e,t){const n=e.mc,s=n.chromsizes,{ids:o,missing:r}=$e(n,t),i=[];for(const a of o){const c=Zt(n,a);if(c===null)continue;const u=n.chromnames[a];i.push({name:u,span:c,length:s.get(u)??(c.to-c.from)*n.binsize,circular:Te(e,u)})}return{units:i,missing:r}}const G7="Insulation",H7=async e=>{const t=nt(e.params,"balance",!1),n=e.framing.value===""?j:e.framing.value,s=Math.max(0,Math.min(1,Q(e.params,"minValid",.5))),o=Math.max(0,Math.round(Q(e.params,"ignoreDiags",2))),r=q7(e.params),i=r[r.length-1],a=r.filter(x=>m8(x,o)<=0);if(a.length===r.length)throw new Error(`Ignoring ${o} diagonals leaves nothing in a diamond ${r.length===1?`${i} bins`:`up to ${i} bins`} wide: it spans separations 0 to ${2*i-2}, so every cell is inside the cut. Ignore fewer, or use a wider window.`);a.length>0&&e.note(`Ignoring ${o} diagonals empties the ${a.join(", ")} bin ${a.length===1?"window":"windows"} — a diamond of ${a[0]} bins spans only separations 0 to ${2*a[0]-2} — so ${a.length===1?"that scale is":"those scales are"} all gaps.`);const c=te(e.params,"sequences");if(c!==null&&c.length===0)return e.note("No sequence is ticked, so there is nothing to score."),[];const{units:u,missing:l}=U7(e,c),h=be(e.mc,l,u.length);if(h!==null&&e.note(h),u.length===0)return[];const f=e.mc.nBins,d=r.map(()=>new Float32Array(f).fill(Number.NaN)),m=Ft(e,u.map(x=>x.span),t),g=[],p=nt(e.params,"call",!0),w=Q(e.params,"prominence",.2),b=Math.max(1,Math.round(Q(e.params,"spacing",0))),y=(x,v,S)=>{for(let k=0;k<r.length;k++){const C=w8(S[k]);for(let B=0;B<v;B++)d[k][x.span.from+B]=C[B];p&&k===0&&g.push({unit:x,score:C,counts:S[k].counts})}};for(let x=0;x<u.length;x++){const v=u[x],S=v.span.to-v.span.from,k=r.map(()=>({sums:new Float64Array(S),counts:new Float64Array(S)}));if(v.circular){await e.breathe(),e.progress(x,u.length,v.name);const C=await Oe(e,v.span,{hi:2*i,block:m,balance:t,value:n,circular:!0,onTile:async(B,F)=>{await e.breathe(),e.progress(x,u.length,F===1?v.name:`${v.name} · strip ${Math.min(B+1,F)} of ${F}`)}});for(let B=0;B<r.length;B++)k[B]=p8(C,{window:r[B],ignoreDiags:o});y(v,S,k);continue}await P0(e,v.span,{halo:i,block:m,balance:t,value:n},async C=>{await e.breathe(),e.progress(x,u.length,C.total===1?v.name:`${v.name} · part ${C.index+1} of ${C.total}`);for(let B=0;B<r.length;B++){const F=g8({size:C.size,values:C.values},{window:r[B],ignoreDiags:o});for(let E=C.ownFrom;E<C.ownTo;E++)k[B].sums[E]=F.sums[E-C.from],k[B].counts[E]=F.counts[E-C.from]}}),y(v,S,k)}e.progress(u.length,u.length,"done");let A=0;for(const x of g)for(const v of x.counts)A=Math.max(A,v);const N=g.map(({unit:x,score:v,counts:S})=>({unit:x,boundaries:N8(v,S,{minCells:A*s,threshold:w,spacing:b}),window:r[0]})),I=u.filter(x=>x.circular).length;I>0&&e.note(`${I.toLocaleString()} of ${u.length.toLocaleString()} ${u.length===1?"sequence was":"sequences were"} read as circular, so the diamond wraps past the end and every bin is scored — including the ones at the junction, which a linear reading leaves as gaps.`);const M=r.map((x,v)=>Q7(e,d[v],x,r.length>1)).reverse();if(p){const x=N.reduce((v,S)=>v+S.boundaries.length,0);if(x===0)e.note(`No minimum was prominent enough to call at a threshold of ${w}. Lower it, or widen the window.`);else if(M.push(K7(e,N)),e.note(`${x.toLocaleString()} boundaries called across ${N.length} sequences.`),nt(e.params,"domains",!0)){const v=W7(e,N);v===null?e.note("No sequence had two calls, so no domain has both of its edges and none was made."):(M.push(v.output),e.note(`${v.count.toLocaleString()} domains between them, from each call to the next.`))}}return M};function Q7(e,t,n,s){const o=n*e.mc.binsize;return{kind:"profile",id:`insulation-w${n}`,label:`Insulation · ${kt(o)}`,values:t,extent:[0,e.mc.nBins],binsize:e.mc.binsize,unit:"log2 ratio",...s?{group:G7,mode:"heatmap",groupMode:"overlay"}:{}}}function K7(e,t){const n=new le;let s=0;for(const{unit:o,boundaries:r}of t)for(const i of r){const a=i.bin*e.mc.binsize;n.add(o.name,a,Math.min(o.length,a+e.mc.binsize),{score:i.prominence,name:`boundary_${++s}`,detail:`insulation ${i.score.toFixed(3)} · prominence ${i.prominence.toFixed(3)}`})}return{kind:"intervals",id:"insulation-boundaries",label:"Insulation boundaries",payload:{kind:"features",data:n.finish()},noun:{one:"boundary",many:"boundaries"},display:"lane",look:"point"}}function W7(e,t){const n=new le;let s=0;for(const{unit:o,boundaries:r}of t)for(const i of X0(r)){const a=i.from*e.mc.binsize,c=Math.min(o.length,i.to*e.mc.binsize);c<=a||(s++,n.add(o.name,a,c,{score:i.strength,name:`domain_${s}`,detail:`${i.to-i.from} bins · weaker boundary prominence ${i.strength.toFixed(3)}`}))}return s===0?null:{count:s,output:{kind:"intervals",id:"insulation-domains",label:"Insulation domains",payload:{kind:"features",data:n.finish()},noun:{one:"domain",many:"domains"},display:"overlay",look:"corner"}}}async function Y7(e,t,n,s){const o={from:t,to:n},r=Ft(e,[o],s);if(r!==null)return ei(r,o).values;const i=e.framing.value===""?j:e.framing.value;return(await e.mc.matrix({rows:[t,n],cols:[t,n],balance:s,value:i})).values}function V7(e,t,n){const s=new Fn(n>0?Math.floor(t/2):Math.max(0,t-1),n);for(let o=0;o<t;o++)for(let r=0;r<t;r++)s.add(_n(Math.abs(r-o),n),e[o*t+r]);return s.finish()}function X7(e,t,n,s){const o=new Float64Array(t*t);for(let r=0;r<t;r++)for(let i=0;i<t;i++){const a=e[r*t+i],c=Wr(s,_n(Math.abs(i-r),n));o[r*t+i]=Number.isFinite(a)&&Number.isFinite(c)&&c>0?a/c:Number.NaN}return o}function J7(e,t,n,s){const o=Int32Array.from({length:t},(i,a)=>a),r=K0(e,o,o,n,s);for(let i=0;i<r.length;i++){const a=e[i],c=r[i];r[i]=Number.isFinite(a)&&c>0?a/c:Number.NaN}return r}const Z7=1.1;function kc(e,t,n){const s=new Float64Array(t.length),o=new Float64Array(t.length);for(let r=0;r<t.length;r++)s[r]=r*n,o[r]=t[r]>0?Math.log2(t[r]):Number.NaN;return{name:e,x:s,y:o}}function Ko(e,t,n){const s=Kr(t,n,Z7,1);if(s.x.length===0)return null;let o=0;for(const r of s.n)o+=r;return{name:e,x:s.x,y:s.y,n:o}}function j7(...e){let t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const r of e)for(const i of r)for(const a of i.y)Number.isFinite(a)&&(t=Math.min(t,a),n=Math.max(n,a));if(!(t<=n))return;const s=Math.floor(t),o=Math.ceil(n);return s<o?[s,o]:[s-1,o+1]}const tg=async e=>{const{ids:t,missing:n}=$e(e.mc,te(e.params,"sequences")),s=be(e.mc,n,t.length);if(s!==null&&e.note(s),t.length===0)return[];const o=nt(e.params,"balance",!0),r=Math.max(0,Math.min(50,Math.round(Q(e.params,"band",2)))),i=Math.max(0,Math.round(Q(e.params,"armWindow",50))),a=e.mc.binsize,c=new Float32Array(e.mc.nBins).fill(Number.NaN),u=[],l=[],h=[],f=[];for(let g=0;g<t.length;g++){await e.breathe();const p=t[g],w=e.mc.chromnames[p],[b,y]=e.mc.contigExtent(p),A=y-b;if(e.progress(g,t.length,w),A<8){e.note(`${w}: ${A} bins is too few to have arms at this resolution; left out.`);continue}if(A>_s){e.note(`${w}: ${A.toLocaleString()} bins is past the ${_s.toLocaleString()}-bin limit on a square read whole; left out. Open the file at a coarser resolution.`);continue}const N=Te(e,w),I=b0(e,w),M=Math.max(0,Math.min(A-1,Math.floor((I??0)/a)));I===void 0&&e.note(`${w}: the arms were read from the first base, the origin every sequence has until one is set — on the Chromosomes table, or by Origin and terminus.`);const x={n:A,origin:M,circular:N},v=await Y7(e,b,y,o);e.throwIfCancelled();const S=N?A:0,k=V7(v,A,S),{byDistance:C,byBin:B}=Va(X7(v,A,S,k),x,r),F=Xa(C);for(let L=0;L<A;L++)c[b+L]=B[L]>0?Math.log2(B[L]):Number.NaN;u.push(kc(w,C,a)),await e.breathe(),e.throwIfCancelled();const E=Va(J7(v,A,x,i),x,r).byDistance,_=Xa(E,F.reach);l.push(kc(w,E,a));const{within:$,across:O}=Vd(v,x);for(const L of[Ko(`${w} · along the diagonal`,k,a),Ko(`${w} · within an arm`,$,a),Ko(`${w} · across the arms`,O,a)])L!==null&&h.push(L);f.push({sequence:w,topology:N?"circular":"linear",origin:(I??0)+1,enrichment:2**F.score,detrended:2**_.score,reach:Number.isFinite(F.reach)?F.reach*a:Number.NaN,armLength:(N?Math.floor(A/2):Math.max(M,A-1-M))*a}),N||e.note(`${w} was read as linear, so an origin near either end leaves it one arm. A bacterial chromosome is usually circular — tick it on the Chromosomes table.`)}if(e.progress(t.length,t.length,"done"),f.length===0)return[];e.note(`Cells within ${r} ${r===1?"bin":"bins"} (${(r*a).toLocaleString()} bp) of the secondary diagonal, over each sequence’s own distance decay.`),e.note("Enrichment after detrend is the same cells over the decay along both arms"+(i===0?", over the whole of it":`, within ${i.toLocaleString()} ${i===1?"bin":"bins"} (${(i*a).toLocaleString()} bp) of each cell along them`)+" — the expectation the map’s arms and Compartments divide by, which takes the secondary diagonal in — read over the same stretch as the enrichment. It is near 1 where that works: it is a control on the detrending, not a second measure of the alignment."),e.note("The decay curves are the two expectations: along the diagonal, the one the enrichment is read over; within an arm and across the arms, the decay along both arms averaged over the whole of them, which the window follows along the arms. Log-binned as P(s)’s expected curve is, from one bin away from each diagonal.");const d=j7(u,l);return[{kind:"profile",id:"interarm-enrichment",label:`Inter-arm enrichment · ±${r} ${r===1?"bin":"bins"}`,values:c,extent:[0,e.mc.nBins],binsize:a,unit:"log2"},{kind:"curve",id:"interarm-curve",label:"Inter-arm alignment by distance from the origin",series:u,xLabel:"Distance from the origin (bp)",yLabel:"Secondary-diagonal enrichment (log2 O/E)",xScale:"linear",yScale:"linear",...d===void 0?{}:{yDomain:d}},{kind:"curve",id:"interarm-detrended-curve",label:"Inter-arm alignment after detrend, by distance from the origin",series:l,xLabel:"Distance from the origin (bp)",yLabel:"Enrichment over the decay along both arms (log2 O/E)",xScale:"linear",yScale:"linear",...d===void 0?{}:{yDomain:d}},{kind:"curve",id:"interarm-decay",label:"Contact decay along the diagonal and along both arms",series:h,xLabel:"Separation from the main or the secondary diagonal (bp)",yLabel:"Mean contact per bin pair",xScale:"log",yScale:"log"},{kind:"table",id:"interarm-table",label:"Inter-arm alignment per sequence",columns:[{key:"sequence",label:"sequence",kind:"text"},{key:"topology",label:"read as",kind:"text"},{key:"origin",label:"origin",kind:"number",hint:"The origin the arms were read from, 1-based."},{key:"enrichment",label:"enrichment",kind:"number",digits:3,hint:"How many times as often mirror images touch as expected, from the origin out to the reach — how strong the alignment is where it holds — or over the whole arm where nothing reaches: 1 is no alignment, 2 twice as often. Two to the mean log2, so enrichment and depletion weigh alike."},{key:"detrended",label:"enrichment after detrend",kind:"number",digits:3,hint:"The same cells over the decay along both arms, as the map’s arms and Compartments divide by, read over the same stretch as the enrichment: 1 is no alignment left over — a control on that detrending."},{key:"reach",label:"reach",kind:"number",hint:"How far from the origin, in bp, the enrichment holds before it falls four-fifths of the way from its peak back to 1, on a log scale — where the alignment ends."},{key:"armLength",label:"arm",kind:"number",hint:"Length of the longer arm, in bp."}],rows:f}]},eg="shared";function ng(e,t){const n=new le;for(const o of e)n.add(o.contig,o.start,o.end,{xyz:[o.x,o.y,o.z],hap:0});const s={width:t,haplotypes:[eg]};return n.finish(null,s)}function M1(e,t,n){const s=n.length;for(let o=0;o<s;o++){const r=n[o]*t,i=o*s;for(let a=0;a<s;a++)e[i+a]=e[r+n[a]]}}function sg(e,t,n){const s=-1/n;for(let o=0;o<t;o++){for(let r=o+1;r<t;r++){const i=e[o*t+r],a=e[r*t+o],c=Number.isFinite(i)&&i>0,u=Number.isFinite(a)&&a>0,l=!c&&!u?Number.NaN:Math.pow(c&&u?(i+a)/2:c?i:a,s);e[o*t+r]=l,e[r*t+o]=l}e[o*t+o]=0}}function og(e,t,n,s){const o=e;let r=0;for(let m=0;m<t;m++)r=Math.max(r,s[m]);const i=new Float64Array(r+1),a=new Float64Array(r+1);let c=0,u=0;for(let m=0;m<t;m++)for(let g=m+1;g<t;g++){const p=o[m*t+g];if(!Number.isNaN(p))if(n[m]===n[g]){const w=Math.abs(s[m]-s[g]);i[w]+=p,a[w]+=1}else c+=p,u+=1}const l=new Float64Array(r+1).fill(Number.NaN);let h=0;for(let m=0;m<=r;m++)a[m]!==0&&(l[m]=i[m]/a[m],l[m]>h&&(h=l[m]));const f=new Float64Array(r+1);for(let m=0;m<=r;m++){if(!Number.isNaN(l[m])){f[m]=l[m];continue}let g=Number.NaN;for(let p=1;p<=r&&Number.isNaN(g);p++){const w=m-p,b=m+p;w>=0&&!Number.isNaN(l[w])?g=l[w]:b<=r&&!Number.isNaN(l[b])&&(g=l[b])}f[m]=Number.isNaN(g)?1:g}const d=u>0?c/u:h>0?h:1;for(let m=0;m<t;m++)for(let g=m+1;g<t;g++){if(!Number.isNaN(o[m*t+g]))continue;const p=n[m]===n[g]?f[Math.abs(s[m]-s[g])]:d;e[m*t+g]=p,e[g*t+m]=p}}function*rg(e,t,n=80){const s=new Float64Array(t);let o=0;for(let u=0;u<t;u++){let l=0;const h=u*t;for(let f=0;f<t;f++){const d=e[h+f];l+=d*d}s[u]=l/t,o+=l}o/=t*t;const r=(u,l)=>ig(e,t,s,o,u,l),i=[bs(t,1),bs(t,2),bs(t,3)];Sc(i);const a=[new Float64Array(t),new Float64Array(t),new Float64Array(t)];for(let u=0;u<n;u++){for(let l=0;l<3;l++)r(i[l],a[l]);for(let l=0;l<3;l++)i[l].set(a[l]);Sc(i),yield{sweep:u+1,sweeps:n}}const c=i.map((u,l)=>{r(u,a[l]);let h=0;for(let m=0;m<t;m++)h+=u[m]*a[l][m];const f=Math.sqrt(Math.max(0,h)),d=new Float64Array(t);for(let m=0;m<t;m++)d[m]=u[m]*f;return d});return{x:c[0],y:c[1],z:c[2]}}function ig(e,t,n,s,o,r){let i=0,a=0;for(let u=0;u<t;u++)i+=o[u],a+=n[u]*o[u];const c=s*i-a;for(let u=0;u<t;u++){const l=u*t;let h=0;for(let f=0;f<t;f++){const d=e[l+f];h+=d*d*o[f]}r[u]=-.5*(h-n[u]*i+c)}}function bs(e,t){const n=new Float64Array(e);let s=2463534242+t*7919;for(let o=0;o<e;o++)s^=s<<13,s^=s>>>17,s^=s<<5,n[o]=(s>>>0)/4294967296*2-1;return n}function Sc(e){const t=e[0].length;for(let n=0;n<e.length;n++){const s=e[n];for(let r=0;r<n;r++){const i=e[r];let a=0;for(let c=0;c<t;c++)a+=i[c]*s[c];for(let c=0;c<t;c++)s[c]-=a*i[c]}let o=0;for(let r=0;r<t;r++)o+=s[r]*s[r];if(o=Math.sqrt(o),o<1e-12){s.set(bs(t,11+n)),n--;continue}for(let r=0;r<t;r++)s[r]/=o}}function ag(e,t,n,s=null,o){const r=o??wr(e,t,n,s),{x:i,y:a,z:c}=n;for(let u=0;u<t;u++){let l=0,h=0,f=0,d=0;const m=u*t,g=i[u],p=a[u],w=c[u];for(let b=0;b<t;b++){if(b===u)continue;const y=e[m+b];if(Number.isNaN(y))continue;const A=s===null?1:s[m+b];if(!(A>0))continue;const N=g-i[b],I=p-a[b],M=w-c[b],x=Math.sqrt(N*N+I*I+M*M),v=x>1e-12?y/x:0;l+=A*(i[b]+v*N),h+=A*(a[b]+v*I),f+=A*(c[b]+v*M),d+=A}d<=0||(i[u]=l/d,a[u]=h/d,c[u]=f/d)}return r}function wr(e,t,n,s=null){const{x:o,y:r,z:i}=n;let a=0,c=0;for(let u=0;u<t;u++)for(let l=u+1;l<t;l++){const h=e[u*t+l];if(Number.isNaN(h))continue;const f=s===null?1:s[u*t+l];if(!(f>0))continue;const d=o[u]-o[l],m=r[u]-r[l],g=i[u]-i[l],p=h-Math.sqrt(d*d+m*m+g*g);a+=f*p*p,c+=f*h*h}return c>0?a/c:0}function cg(e){const{x:t,y:n,z:s}=e,o=t.length;if(o===0)return;let r=0,i=0,a=0;for(let l=0;l<o;l++)r+=t[l],i+=n[l],a+=s[l];r/=o,i/=o,a/=o;let c=0;for(let l=0;l<o;l++)t[l]-=r,n[l]-=i,s[l]-=a,c+=t[l]*t[l]+n[l]*n[l]+s[l]*s[l];const u=Math.sqrt(c/o);if(!(u<=0))for(let l=0;l<o;l++)t[l]/=u,n[l]/=u,s[l]/=u}function I1(e,t){const n=e.length;if(n<3)return Number.NaN;const s=Cc(e),o=Cc(t);let r=0,i=0;for(let l=0;l<n;l++)r+=s[l],i+=o[l];r/=n,i/=n;let a=0,c=0,u=0;for(let l=0;l<n;l++){const h=s[l]-r,f=o[l]-i;a+=h*f,c+=h*h,u+=f*f}return c>0&&u>0?a/Math.sqrt(c*u):Number.NaN}function Cc(e){const t=e.length,n=Array.from({length:t},(r,i)=>i).sort((r,i)=>e[r]-e[i]),s=new Float64Array(t);let o=0;for(;o<t;){let r=o;for(;r+1<t&&e[n[r+1]]===e[n[o]];)r++;const i=(o+r)/2+1;for(let a=o;a<=r;a++)s[n[a]]=i;o=r+1}return s}function zs(e,t,n){const s=e.contigs.indexOf(t);if(s<0)return[];const o=e.model,r=[];for(let i=e.contigAt[s];i<e.contigAt[s+1];i++)o!==void 0&&n>=0&&o.hap[i]!==n||r.push(i);return r}function lg(e,t,n,s,o){const r=new Float64Array(o),i=new Float64Array(o),a=new Float64Array(o),c=new Int32Array(o);for(const l of n){if(!Number.isFinite(t.x[l])||!Number.isFinite(t.y[l])||!Number.isFinite(t.z[l]))continue;const h=Math.floor((e.start[l]+e.end[l])/2/s);h<0||h>=o||(r[h]+=t.x[l],i[h]+=t.y[l],a[h]+=t.z[l],c[h]++)}const u=new Uint8Array(o);for(let l=0;l<o;l++)c[l]!==0&&(r[l]/=c[l],i[l]/=c[l],a[l]/=c[l],u[l]=1);return{n:o,x:r,y:i,z:a,present:u,beads:c}}function ug(e){const t=e.n,n=new Float32Array(t*t).fill(Number.NaN);for(let s=0;s<t;s++)if(e.present[s]!==0){n[s*t+s]=0;for(let o=s+1;o<t;o++){if(e.present[o]===0)continue;const r=Math.hypot(e.x[o]-e.x[s],e.y[o]-e.y[s],e.z[o]-e.z[s]);n[s*t+o]=r,n[o*t+s]=r}}return n}function hg(e,t){const n=new Float32Array(e.length).fill(Number.NaN);for(let s=0;s<e.length;s++){const o=e[s];Number.isNaN(o)||(n[s]=o>0?1/o**t:Number.NaN)}return n}function x1(e,t){const n=new Float64Array(t),s=new Float64Array(t);for(let r=0;r<t;r++)for(let i=r+1;i<t;i++){const a=e[r*t+i];Number.isNaN(a)||(n[i-r]+=a,s[i-r]++)}const o=new Float64Array(t).fill(Number.NaN);for(let r=1;r<t;r++)s[r]>0&&(o[r]=n[r]/s[r]);return o}function fg(e,t){return x1(e,t)}function dg(e,t,n,s=2){const o=[],r=[];for(let i=0;i<n;i++)for(let a=i+s;a<n;a++){const c=e[i*n+a],u=t[i*n+a];Number.isNaN(c)||c<=0||!Number.isFinite(u)||(o.push(1/c),r.push(u))}return{rho:o.length<3?Number.NaN:Kl(o,r),pairs:o.length}}function br(e,t){let n=0,s=0,o=0,r=0;for(const i of t)!Number.isFinite(e.x[i])||!Number.isFinite(e.y[i])||!Number.isFinite(e.z[i])||(n+=e.x[i],s+=e.y[i],o+=e.z[i],r++);return r===0?null:[n/r,s/r,o/r]}function Fc(e,t,n){const s=new Float64Array(t.length).fill(Number.NaN);return t.forEach((o,r)=>{Number.isFinite(e.x[o])&&(s[r]=Math.hypot(e.x[o]-n[0],e.y[o]-n[1],e.z[o]-n[2]))}),s}function mg(e,t,n){const s=new Float64Array(t.length).fill(Number.NaN),o=Math.max(1,Math.floor(n));for(let r=0;r<t.length;r++){const i=t[r];if(!Number.isFinite(e.x[i]))continue;let a=0,c=0;for(let u=-o;u<=o;u++){if(u===0)continue;const l=t[r+u];l===void 0||!Number.isFinite(e.x[l])||(a+=Math.hypot(e.x[l]-e.x[i],e.y[l]-e.y[i],e.z[l]-e.z[i]),c++)}c>0&&(s[r]=a/c)}return s}function Wo(e,t,n,s,o,r,i){const a=new Float64Array(r),c=new Int32Array(r);t.forEach((u,l)=>{const h=n[l];if(!Number.isFinite(h))return;const f=Math.floor((e.start[u]+e.end[u])/2/s);f<0||f>=r||(a[f]+=h,c[f]++)});for(let u=0;u<r;u++)c[u]>0&&o+u<i.length&&(i[o+u]=a[u]/c[u])}const Yo=100,gg={gradient:"the gradient: a maximum of the likelihood",value:"pastis’ tolerance: a step bought less than a double can hold",steps:"the step budget — raise it for a closer fit",search:"a line search that found nowhere better to go"},$c={unchosen:"No structure was chosen. Load a g3d or bed3d and pick it under Structure.",gone:"The structure that was chosen is no longer in the list."};function v1(e,t){const n=[];for(const s of t.contigs){const o=e.mc.chromnames.indexOf(s);if(o<0)continue;const[r,i]=e.mc.contigExtent(o);i>r&&n.push({name:s,cid:o,span:{from:r,to:i}})}return n}function k1(e){return e.haplotypes.length<=1?[{index:-1,label:""}]:e.haplotypes.map((t,n)=>({index:n,label:t}))}function S1(e){const t=Ts(e.inputs.features,e.params,"structure"),n=w0(t,$c);if(n!==null||t.value===void 0)return e.note(n??$c.unchosen),null;const s=t.value;if(s.model===void 0)return e.note("The chosen row is not a structure: it has no coordinates to read."),null;const o=typeof e.params.structure=="string"?e.params.structure:"";return{set:s,model:s.model,label:e.inputs.labels?.[o]??"structure"}}const pg=async e=>{const t=S1(e);if(t===null)return[];const{set:n,model:s,label:o}=t,r=v1(e,n);if(r.length===0)return e.note("The model and the map share no sequence name. Check the names in the Tracks card."),[];const i=nt(e.params,"balance",!1),a=e.framing.value===""?j:e.framing.value,c=Q(e.params,"alpha",3),u=(zr(ct(e.params,"region",""))[0]??"").split(":")[0].trim(),l=r.find(w=>w.name===u)??r[0],h=k1(s),f=e.mc.binsize,d=[],m=[];let g=0;for(const w of r){e.throwIfCancelled(),e.progress(g++,r.length,w.name);const b=w.span.to-w.span.from,y=await ni(e,w.span,{block:Ft(e,[w.span],i),balance:i,value:a});for(const A of h){const N=zs(n,w.name,A.index);if(N.length===0)continue;const I=lg(n,s,N,f,b),M=ug(I),x=dg(M,y.values,b);if(m.push({sequence:w.name,haplotype:A.label,bins:Array.from(I.present).filter(k=>k===1).length,pairs:x.pairs,rho:x.rho}),w!==l)continue;const v=A.label===""?"":` · ${A.label}`,S=Array.from({length:b},(k,C)=>kt(C*f));d.push(Ec(`structure-distance-${A.index}`,`Model distances · ${w.name}${v}`,b,M,S,"viridis"),Ec(`structure-predicted-${A.index}`,`Predicted contacts 1/d^${c} · ${w.name}${v}`,b,hg(M,c),S,"fall")),d.push(...wg(w.name,v,A.index,M,y.values,b,f))}}e.progress(r.length,r.length);const p={kind:"table",id:"structure-agreement",label:`Model versus map · ${o}`,columns:[{key:"sequence",label:"Sequence",kind:"text"},...h.length>1?[{key:"haplotype",label:"Haplotype",kind:"text"}]:[],{key:"bins",label:"Bins modelled",kind:"number",digits:0},{key:"pairs",label:"Pairs compared",kind:"number",digits:0},{key:"rho",label:"Spearman ρ (1/d vs contacts)",kind:"number",digits:3,hint:"Rank correlation between the inverse model distance and the observed contacts, over pairs at least two bins apart. 1 is a model that orders every pair as the map does."}],rows:m};return d.push(p),d};function Ec(e,t,n,s,o,r){return{kind:"matrix",id:e,label:t,nrows:n,ncols:n,values:s,xLabel:"Position",yLabel:"Position",xTicks:o,yTicks:o,colormap:r}}function wg(e,t,n,s,o,r,i){const a=x1(s,r),c=fg(o,r),u=(d,m)=>{const g={maxOffset:r-1,sum:new Float64Array(r),count:new Float64Array(r)};for(let w=1;w<r;w++)Number.isNaN(d[w])||(g.sum[w]=d[w],g.count[w]=1);const p=Kr(g,i,1.25,1);return p.x.length<2?null:{name:m,x:p.x,y:p.y,n:r}},l=[],h=u(a,`${e}${t}`);if(h!==null){const d=Wl(h.x,h.y);l.push({kind:"curve",id:`structure-dvs-${n}`,label:`Model distance by separation · ${e}${t}`,series:[h],xLabel:"Genomic separation (bp)",yLabel:"Mean distance (model units)",xScale:"log",yScale:"log"}),d.x.length>0&&l.push({kind:"curve",id:`structure-dvs-slope-${n}`,label:`Log-log slope of the model’s distance · ${e}${t}`,series:[{name:`${e}${t}`,x:d.x,y:d.y}],xLabel:"Genomic separation (bp)",yLabel:"d log d / d log s",xScale:"log",yScale:"linear"})}const f=u(c,`${e} · map`);return f!==null&&l.push({kind:"curve",id:`structure-ps-${n}`,label:`The map’s P(s) over the same bins · ${e}`,series:[f],xLabel:"Genomic separation (bp)",yLabel:"Mean contact per bin pair",xScale:"log",yScale:"log"}),l}const bg=async e=>{const t=S1(e);if(t===null)return[];const{set:n,model:s,label:o}=t,r=v1(e,n);if(r.length===0)return e.note("The model and the map share no sequence name. Check the names in the Tracks card."),[];const i=e.mc.binsize,a=e.mc.nBins,c=Q(e.params,"window",5),u=ct(e.params,"locus","").trim(),l=k1(s),h=[];for(const f of l){const d=f.label===""?"":` · ${f.label}`,m=r.flatMap(N=>zs(n,N.name,f.index)),g=br(s,m),p=new Float32Array(a).fill(Number.NaN),w=new Float32Array(a).fill(Number.NaN),b=new Float32Array(a).fill(Number.NaN),y=u===""?null:Ag(n,s,u,f.index);for(const N of r){e.throwIfCancelled();const I=zs(n,N.name,f.index);if(I.length===0)continue;const M=N.span.to-N.span.from;g!==null&&Wo(n,I,Fc(s,I,g),i,N.span.from,M,p),Wo(n,I,mg(s,I,c),i,N.span.from,M,w),y!==null&&Wo(n,I,Fc(s,I,y),i,N.span.from,M,b)}const A=(N,I,M,x)=>({kind:"profile",id:`${N}-${f.index}`,label:`${I}${d} · ${o}`,values:M,extent:[0,a],binsize:i,unit:"model units",colour:x,group:"structure"});g!==null&&h.push(A("structure-radial","Radial position",p,"#1f5fa9")),h.push(A("structure-compaction",`Local compaction (±${Math.round(c)} beads)`,w,"#0f8a5f")),y!==null&&h.push(A("structure-distance",`Distance to the centre of ${Ar(u)}`,b,"#c0392b"))}return u!==""&&!h.some(f=>f.id.startsWith("structure-distance"))&&e.note(`No bead of the model lies at ${Ar(u)}, so the distance track was not made.`),h};function Ar(e){return zr(e).map(p0).join(", ")}function Ag(e,t,n,s){const[o,r]=n.split(":"),i=o?.trim()??"",a=zs(e,i,s);if(a.length===0)return null;const c=(r??"").replace(/,/g,"").split(/[-–]/),u=Number(c[0]),l=c.length>1?Number(c[1]):u;if(!Number.isFinite(u))return br(t,a);const h=Math.min(u,l),f=Math.max(u,l),d=a.filter(m=>e.end[m]>h&&e.start[m]<f);return br(t,d.length>0?d:a.filter(m=>e.start[m]<=h&&e.end[m]>h))}function C1(e){const t=[];for(let n=0;n<e.mc.nContigs;n++){const[s,o]=e.mc.contigExtent(n);o>s&&t.push({cid:n,from:s,to:o})}return t}async function yg(e,t,n,s,o){const r=e.inputs.block,i=r!==void 0&&r.binsPerCell===1&&r.rowExtent[0]===r.colExtent[0]&&r.rowExtent[1]===r.colExtent[1]&&r.nrows===r.ncols&&e.framing.balance===n,c=t===null?C1(e).map(w=>({from:w.from,to:w.to})):t;if(c.length===0)return{refusal:"The file has no sequence to model."};if(i&&r!==void 0&&c.every(w=>ti(r,w))){const w=[],b=[],y=[];for(let I=0;I<r.nrows;I++){const M=r.rowExtent[0]+I;c.some(x=>M<x.to&&M+1>x.from)&&(w.push(I),b.push(M),y.push(M+1))}const A=w.length,N=As(A);if(N===null)return{refusal:yr(A,o)};for(let I=0;I<A;I++){const M=w[I]*r.ncols;for(let x=0;x<A;x++)N[I*A+x]=r.values[M+w[x]]}return{cells:{n:A,binFrom:Int32Array.from(b),binTo:Int32Array.from(y),values:N},how:"the block as drawn, one bin to a bead"}}const u=[],l=[],h=[];for(const w of c){const b=[];for(let y=w.from;y<w.to;y++)b.push(u.length),u.push(y),l.push(y+1);h.push(b)}const f=u.length;if(f===0)return{refusal:"The framing holds no bins to model."};const d=As(f),m=d===null?null:As(f);if(d===null||m===null)return{refusal:yr(f,o)};const g=c.length*(c.length+1)/2;let p=0;for(let w=0;w<c.length;w++)for(let b=w;b<c.length;b++){await e.breathe(),e.progress(p++,g+2,`reading ${p} of ${g} blocks`);const y=c[w],A=c[b],N=await e.mc.matrix({rows:[y.from,y.to],cols:[A.from,A.to],balance:n,value:s}),I=h[w],M=h[b];for(let x=0;x<N.nrows;x++){const v=I[x];if(v===void 0)continue;const S=x*N.ncols;for(let k=0;k<N.ncols;k++){const C=N.values[S+k];if(!Number.isFinite(C))continue;const B=M[k];B!==void 0&&(d[v*f+B]+=C,m[v*f+B]+=1,v!==B&&(d[B*f+v]+=C,m[B*f+v]+=1))}}}for(let w=0;w<d.length;w++)d[w]=m[w]>0?d[w]/m[w]:Number.NaN;return{cells:{n:f,binFrom:Int32Array.from(u),binTo:Int32Array.from(l),values:d},how:"read from the file, one bin to a bead"}}function As(e){try{const t=globalThis.crossOriginIsolated;if(typeof SharedArrayBuffer=="function"&&t!==!1)try{return new Float32Array(new SharedArrayBuffer(4*e*e))}catch{}return new Float32Array(e*e)}catch{return null}}function yr(e,t){const n=t*4*e*e/1e9;return`${e.toLocaleString()} beads needs about ${n.toFixed(1)} GB ${t===1?"for its matrix":"of matrices"}, and this browser would not give it. Select a coarser resolution, or name fewer sequences.`}function Ng(e,t){if(t==="")return null;const n=[];for(const s of zr(t)){const o=Mg(e,s);if(o===void 0)return{missing:Vs(s)[0]};o!==null&&n.push(o)}return n.length===0?null:n}function Mg(e,t){if(t==="")return null;const[n,s,o]=Vs(t),r=Be(e.mc,n);if(r<0)return;const i=Zt(e.mc,r);if(i===null)return;if(s===null)return i;const a=e.mc.binsize,c=Math.max(i.from,i.from+Math.floor(s/a)),u=o===null?i.to:Math.min(i.to,i.from+Math.ceil(o/a));return u>c?{from:c,to:u}:void 0}const Ig=async e=>{const t=nt(e.params,"balance",!1),n=e.framing.value===""?j:e.framing.value,s=Math.max(.5,Q(e.params,"alpha",3)),o=Math.max(0,Math.round(Q(e.params,"iterations",150))),r=ct(e.params,"weights","contacts"),i=r==="sqrt"||r==="equal"?r:"contacts",a=ct(e.params,"method","nb")!=="shrec3d",c=Math.max(0,Math.round(Q(e.params,"seed",0))),u=ct(e.params,"region","").trim(),l=Ng(e,u);if(l!==null&&!Array.isArray(l))return e.note(`This file has no sequence called ${l.missing}, under that spelling or any this viewer knows of. It has ${e.mc.chromnames.slice(0,6).join(", ")}${e.mc.chromnames.length>6?", …":""}.`),[];const f=await yg(e,l,a?!1:t,n,a?1:2);if("refusal"in f)return e.note(f.refusal),[];const{cells:d,how:m}=f;e.framing.normalise!==null&&e.note(`The view is drawn ${e.framing.normalise}-normalised and the model is solved on the counts underneath: no read can ask for that normalisation.`),a&&t&&e.note("The view is drawn balanced and pastis-NB is solved on the raw counts underneath, with the file’s weights folded into each pair’s expected count instead (μ = bᵢ·bⱼ·d^(−α), bᵢ = 1/wᵢ scaled to a mean of 1, as pastis scales them). A balanced value is a count times two weights, and overdispersion is a statement about a count: handed one, the negative binomial would find none and become a Poisson. The coverage is still corrected — it is corrected in the mean rather than in the data (§25.6).");const g=C1(e),p=e.mc.binsize,w=new Int32Array(d.n).fill(-1),b=new Int32Array(d.n),y=[],A=new Map;for(let P=0;P<d.n;P++){const z=d.binFrom[P],R=g.find(tt=>tt.from<=z&&z<tt.to);if(R===void 0)continue;const H=e.mc.chromnames[R.cid],K=e.mc.chromsizes.get(H)??(R.to-R.from)*p,G=(z-R.from)*p,W=Math.min(K,(Math.min(R.to,d.binTo[P])-R.from)*p);w[P]=R.cid;const Y=A.get(R.cid)??0;b[P]=Y,A.set(R.cid,Y+1),y.push({contig:H,start:G,end:Math.max(G+1,W),x:0,y:0,z:0})}const N=a?xg(e,d):null;if(N!==null){for(let P=0;P<d.n;P++)if(!Number.isFinite(N[P]))for(let z=0;z<d.n;z++)d.values[P*d.n+z]=Number.NaN,d.values[z*d.n+P]=Number.NaN}const I=Int32Array.from({length:d.n},(P,z)=>z).filter(P=>w[P]>=0);if(I.length<4)return e.note("Fewer than four cells of the block lie on a sequence of this file; nothing to model."),[];const M=I.length,x=new Int32Array(d.n).fill(-1);for(let P=0;P<I.length;P++)x[I[P]]=P;e.progress(0,1,a?"the counts":"contacts to distances"),await e.breathe();const v=Eg(d.values,d.n,I),S=M-v.length;if(v.length<4)return e.note("Fewer than four beads have any counted pair; nothing to model."),[];const k=v.length,C=Int32Array.from(v,P=>w[P]),B=Int32Array.from(v,P=>b[P]);let F,E,_;if(a){const P=vg(d.values,d.n,v),z=N===null?null:kg(Float64Array.from(v,W=>N[W])),R=L4(P,k,C,B,z),H=_4(R),K=Sg(P,k);R4(P,k,z,s);const G=n6(k,P);try{const W=Yo+o,Y=G.mds(P),tt=Y.threads===1?"":` · ${Y.threads} threads`,et=X4(k,D4(k,y6(c)));let ht=Number.POSITIVE_INFINITY,U=et.next();for(;U.done!==!0;){await e.breathe();const{point:J,gradient:ot,iteration:it,current:lt}=U.value,ut=await Y.evaluate(J,ot);ht=Math.min(ht,lt,ut),e.progress(Math.min(Yo-1,it),W,`MDS start · step ${it}${tt} · stress ${ht.toPrecision(3)}`),U=et.next(ut)}const V=U.value;let Z=null;if(F=V.coords,o>0){const J=G.likelihood({counts:P,n:k,bias:z,dispersion:H,alpha:s}),ot=J.threads===1?"":` · ${J.threads} threads`,it=J4(k,V.coords,{iterations:o});let lt=Number.POSITIVE_INFINITY,ut=it.next();for(;ut.done!==!0;){await e.breathe();const{point:vt,gradient:gt,iteration:St,current:mt}=ut.value,At=await J.evaluate(vt,gt);lt=Math.min(lt,mt,At);const yt=Math.min(o,St);e.progress(Yo+yt,W,`pastis-NB · step ${yt} of at most ${o}${ot} · −log L ${lt.toExponential(3)}`),ut=it.next(At)}Z=ut.value,F=Z.coords}e.progress(W,W),_=Tg(P,k,F,z),E=Cg(K,s,H,R,z!==null,c,V,Z,o)}finally{G.close()}}else{const P=Fg(d.values,d.n,v,i);if(P===null)return $g(e,k);M1(d.values,d.n,v);const z=d.values.subarray(0,k*k);sg(z,k,s);const R=80,H=R+o+1;e.progress(0,H,"classical scaling"),await e.breathe(),og(z,k,C,B);const K=rg(z,k,R);let G=K.next();for(;G.done!==!0;)await e.breathe(),e.progress(G.value.sweep,H,`classical scaling · sweep ${G.value.sweep} of ${G.value.sweeps}`),G=K.next();F=G.value;let W=wr(z,k,F,P),Y=0;for(;Y<o;Y++){await e.breathe();const tt=W;ag(z,k,F,P,tt);const et=wr(z,k,F,P);if(W=et,e.progress(R+Y+1,H,`refining · step ${Y+1} of ${o} · stress ${et.toPrecision(3)}`),tt-et<1e-6*tt){Y++;break}}e.progress(H,H),_=Bg(z,k,F,P),E=[{what:"Distance law",value:`d = c^(−1/${s})`},{what:"Pairs weighted by",value:i==="contacts"?"the contact count":i==="sqrt"?"the square root of the contact count":"nothing: every counted pair alike"},{what:"Refinement steps",value:`${Y.toLocaleString()}`},{what:"Weighted stress",value:W.toPrecision(3)}]}cg(F);const $=[];for(let P=0;P<k;P++){const z=y[x[v[P]]];$.push({...z,x:F.x[P],y:F.y[P],z:F.z[P]})}const O=ng($,p),L=new Set($.map(P=>P.contig)),D=l===null?L.size===1?[...L][0]:`${L.size} sequences`:Ar(u);S>0&&e.note(`${S.toLocaleString()} of ${M.toLocaleString()} cells had no counted pair at all — filtered bins, gaps — and are not in the model.`);const q={kind:"intervals",id:"reconstructed-model",label:`3D model · ${D}`,payload:{kind:"features",data:O},entryKind:"structure",noun:{one:"bead",many:"beads"}},X={kind:"table",id:"reconstructed-fit",label:`Model from the map · ${D}`,columns:[{key:"what",label:"Quantity",kind:"text"},{key:"value",label:"Value",kind:"text"}],rows:[{what:"Method",value:a?"pastis-NB · negative binomial likelihood":"ShRec3D · MDS with SMACOF"},{what:"Contacts",value:m},{what:"Beads",value:`${k.toLocaleString()} of ${d.n.toLocaleString()} cells, ${kt(p)} each`},{what:"Sequences",value:`${L.size.toLocaleString()}`},{what:"Pairs counted",value:`${_.pairs.toLocaleString()} of ${(k*(k-1)/2).toLocaleString()}`},...E,{what:"Spearman ρ (1/d vs contacts)",value:Number.isNaN(_.rho)?"—":_.rho.toFixed(3)}]};return[q,X]};function xg(e,t){if(t.n===0)return null;let n=t.binFrom[0],s=t.binTo[0];for(let i=1;i<t.n;i++)t.binFrom[i]<n&&(n=t.binFrom[i]),t.binTo[i]>s&&(s=t.binTo[i]);if(!(s>n))return null;let o;try{const i=e.mc.binColumn(re,n,s);if(typeof i[0]=="string")return null;o=i}catch{return null}const r=new Float64Array(t.n);for(let i=0;i<t.n;i++){let a=0,c=0;for(let u=t.binFrom[i];u<t.binTo[i];u++){const l=o[u-n];!Number.isFinite(l)||!(l>0)||(a+=1/l,c++)}r[i]=c>0?a/c:Number.NaN}return r}function vg(e,t,n){M1(e,t,n);const s=n.length,o=e.subarray(0,s*s);for(let r=0;r<s;r++){o[r*s+r]=0;for(let i=r+1;i<s;i++){const a=o[r*s+i],c=o[i*s+r],u=Number.isFinite(a),l=Number.isFinite(c),h=!u&&!l?Number.NaN:u&&l?(a+c)/2:u?a:c,f=Number.isNaN(h)||h>0?h:0;o[r*s+i]=f,o[i*s+r]=f}}return o}function kg(e){let t=0;for(const s of e)t+=s;const n=t/e.length;if(n>0)for(let s=0;s<e.length;s++)e[s]/=n;return e}function Sg(e,t){let n=0,s=0;for(let o=0;o<t;o++)for(let r=o+1;r<t;r++){const i=e[o*t+r];Number.isFinite(i)&&(n++,i===0&&s++)}return{observed:n,zeros:s}}function Vo(e){return e>=100?e.toFixed(0):e>=10?e.toFixed(1):e.toPrecision(3)}function Cg(e,t,n,s,o,r,i,a,c){const u=s.mean.length-1,l=[{what:"Mean of a pair",value:o?`μ = bᵢ · bⱼ · d^(−${t})`:`μ = d^(−${t})`},{what:"Counts",value:o?"raw, with the file’s balancing weights folded into the mean as bᵢ = 1/wᵢ, scaled to a mean of 1":"raw: this file carries no balancing weights"},{what:"Zeros used as evidence",value:`${e.zeros.toLocaleString()} of the ${e.observed.toLocaleString()} pairs the map could see`},{what:"Overdispersion (r)",value:n===null?"none: these counts are Poisson, so this is pastis-PM2":`r = ${Vo(Math.exp(n.c0))} · λ^${n.c1.toFixed(3)}, λ the mean, fitted over ${s.mean.length.toLocaleString()} separations: ${Vo(Sa(n,s.mean[0]))} near the diagonal, ${Vo(Sa(n,s.mean[u]))} at ${s.separation[u].toLocaleString()} bins — a smaller r is more overdispersed`},{what:"MDS start",value:`pastis’ MDS from random positions, seed ${r}: ${i.iterations.toLocaleString()} steps, ${i.evaluations.toLocaleString()} evaluations`}];return a===null||l.push({what:"Likelihood steps",value:`${a.iterations.toLocaleString()} of at most ${c.toLocaleString()}, over ${a.evaluations.toLocaleString()} evaluations`},{what:"Stopped on",value:gg[a.stop]},{what:"−log L (less Σ log c!, as pastis gives it)",value:a.value.toExponential(4)}),l}function Fg(e,t,n,s){const o=n.length,r=As(o);if(r===null)return null;for(let i=0;i<o;i++){const a=n[i]*t;for(let c=i+1;c<o;c++){const u=e[a+n[c]],l=e[n[c]*t+n[i]],h=Number.isFinite(u)&&u>0,f=Number.isFinite(l)&&l>0;if(!h&&!f)continue;const d=h&&f?(u+l)/2:h?u:l,m=s==="contacts"?d:s==="sqrt"?Math.sqrt(d):1;r[i*o+c]=m,r[c*o+i]=m}}return r}function $g(e,t){return e.note(yr(t,2)),[]}function Eg(e,t,n){const s=[];for(const o of n){let r=!1;for(const i of n){if(i===o)continue;const a=e[o*t+i],c=e[i*t+o];if(Number.isFinite(a)&&a>0||Number.isFinite(c)&&c>0){r=!0;break}}r&&s.push(o)}return Int32Array.from(s)}function Bg(e,t,n,s){let o=0;for(let u=0;u<t;u++)for(let l=u+1;l<t;l++)s[u*t+l]>0&&o++;const r=Math.max(1,Math.ceil(o/2e5)),i=[],a=[];let c=0;for(let u=0;u<t;u++)for(let l=u+1;l<t;l++){const h=e[u*t+l];s[u*t+l]>0&&c++%r===0&&(i.push(F1(n,u,l)),a.push(-h))}return{rho:I1(i,a),pairs:o}}function Tg(e,t,n,s){let o=0;for(let u=0;u<t;u++)for(let l=u+1;l<t;l++)e[u*t+l]>0&&o++;const r=Math.max(1,Math.ceil(o/2e5)),i=[],a=[];let c=0;for(let u=0;u<t;u++)for(let l=u+1;l<t;l++){const h=e[u*t+l];h>0&&c++%r===0&&(i.push(F1(n,u,l)),a.push(s===null?h:h/(s[u]*s[l])))}return{rho:I1(i,a),pairs:o}}function F1(e,t,n){const s=Math.hypot(e.x[t]-e.x[n],e.y[t]-e.y[n],e.z[t]-e.z[n]);return s>0?1/s:Number.POSITIVE_INFINITY}class Og{constructor(t,n={}){this.nGenomes=t,this.intra=new Float64Array(t),this.inter=new Float64Array(t),this.pairs=n.pairs===!0?new Float64Array(t*t):null}intra;inter;pairs;add(t,n,s){Number.isFinite(s)&&(t<0||n<0||(t===n?this.intra[t]+=s:(this.inter[t]+=s,this.inter[n]+=s),this.pairs!==null&&(this.pairs[t*this.nGenomes+n]+=s,t!==n&&(this.pairs[n*this.nGenomes+t]+=s))))}}class Lg{constructor(t,n,s=32){this.nContigs=t,this.genomeOfContig=n,this.maxPartners=s,this.own=new Float64Array(t),this.other=new Float64Array(t),this.partners=new Array(t).fill(null)}own;other;partners;capped=0;add(t,n,s){if(!Number.isFinite(s)||t<0||n<0||t>=this.nContigs||n>=this.nContigs)return;const o=this.genomeOfContig[t],r=this.genomeOfContig[n];if(!(o<0||r<0)){if(o===r){this.own[t]+=s,t!==n&&(this.own[n]+=s);return}this.other[t]+=s,this.other[n]+=s,this.note(t,r,s),this.note(n,o,s)}}note(t,n,s){let o=this.partners[t];o===null&&(o=new Map,this.partners[t]=o);const r=o.get(n);if(r!==void 0){o.set(n,r+s);return}if(o.size>=this.maxPartners){this.capped++;return}o.set(n,s)}topPartner(t){const n=this.partners[t];if(n===null)return null;let s=-1,o=0;for(const[r,i]of n)i>o&&(s=r,o=i);return s<0?null:{genome:s,value:o}}get droppedPartners(){return this.capped}}function _g(e,t,n){const s=new Int32Array(t).fill(-1);for(const o of e){if(o.genome<0||n!==null&&!n.has(o.genome))continue;const r=Math.min(t,o.startBin+o.bins);for(let i=o.startBin;i<r;i++)s[i]=o.genome}return s}function Dg(e,t){const n=new Int32Array(t).fill(-1);for(let s=0;s<e.length;s++){const o=Math.min(t,e[s].startBin+e[s].bins);for(let r=e[s].startBin;r<o;r++)n[r]=s}return n}function oo(e){const t=e.mc,n=new Set(t.displayGenomes()),s=t.chromsizes,o=[],r=new Map;for(let a=0;a<t.nContigs;a++){const[c,u]=t.contigExtent(a),l=t.contigGenomeIds[a],h=t.chromnames[a];if(o.push({name:h,startBin:c,bins:Math.max(0,u-c),genome:l,length:s.get(h)??(u-c)*t.binsize}),!n.has(l))continue;const f=r.get(l);f===void 0?r.set(l,{bins:u-c,contigs:1}):(f.bins+=u-c,f.contigs++)}const i=[...r.entries()].map(([a,c])=>({id:a,name:t.genomeNames[a],bins:c.bins,contigs:c.contigs})).sort((a,c)=>a.id-c.id);return{contigs:o,genomes:i,allowed:n}}function $1(e){e.framing.value!==""&&e.framing.value!==j&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${j}. These numbers are of the counts.`)}const Rg=async e=>{const t=oo(e);if(t.genomes.length===0)return e.note("This file has no displayable genome, so there is nothing to report per MAG (§7.4)."),[];const n=nt(e.params,"balance",!1),s=ee(e.mc,n);$1(e);const o=_g(t.contigs,e.mc.nBins,t.allowed),r=new Og(e.mc.nGenomes,{pairs:nt(e.params,"network",!0)}),i=new Uint8Array(e.mc.nBins);e.progress(0,1,"reading pixels"),await e.mc.scanPixels({onChunk:l=>{e.throwIfCancelled();for(let h=0;h<l.length;h++){const f=l.bin1[h],d=l.bin2[h],m=l.count[h],g=s===null?m:m*s[f]*s[d];Number.isFinite(g)&&(i[f]=1,i[d]=1,r.add(o[f],o[d],g))}return!0},onProgress:(l,h)=>e.progress(l,h,"reading pixels")}),e.throwIfCancelled();const a=new Int32Array(e.mc.nGenomes);for(let l=0;l<e.mc.nBins;l++)i[l]===1&&o[l]>=0&&a[o[l]]++;const c=t.genomes.map(l=>{const h=r.intra[l.id],f=r.inter[l.id],d=h+f;return{genome:l.name,contigs:l.contigs,bins:l.bins,covered:a[l.id],intra:h,inter:f,fraction:d>0?h/d:Number.NaN,perBin:l.bins>0?d/l.bins:Number.NaN}}),u=[{kind:"table",id:"magqc",label:"MAG contact QC",columns:[{key:"genome",label:"MAG",kind:"text"},{key:"contigs",label:"Contigs",kind:"number",digits:0},{key:"bins",label:"Bins",kind:"number",digits:0},{key:"covered",label:"Bins with contact",kind:"number",digits:0},{key:"intra",label:"Intra",kind:"number",digits:0},{key:"inter",label:"Inter",kind:"number",digits:0},{key:"fraction",label:"Intra fraction",kind:"number",digits:3},{key:"perBin",label:"Contacts per bin",kind:"number",digits:2}],rows:[...c].sort((l,h)=>(h.fraction||0)-(l.fraction||0))}];return r.pairs!==null&&u.push(Pg(r.pairs,t,e.mc.nGenomes)),u};function Pg(e,t,n){const s=t.genomes.map(i=>i.id),o=s.length,r=new Float32Array(o*o);for(let i=0;i<o;i++)for(let a=0;a<o;a++)r[i*o+a]=e[s[i]*n+s[a]];return{kind:"matrix",id:"magqc-network",label:"Inter-MAG contacts",nrows:o,ncols:o,values:r,xLabel:"MAG",yLabel:"MAG",xTicks:o<=40?t.genomes.map(i=>i.name):[],yTicks:o<=40?t.genomes.map(i=>i.name):[],colormap:"default"}}const zg=async e=>{const n=e.inputs.upstream?.magqc?.outputs.find(d=>d.kind==="matrix"&&d.id==="magqc-network");if(n===void 0)throw new Error('The MAG QC step produced no inter-MAG matrix. Turn its "inter-MAG matrix" option on.');const s=n.xTicks.length===n.nrows?n.xTicks:null,o=n.nrows,r=ct(e.params,"normalise","coverage"),i=Q(e.params,"minWeight",0),a=Math.max(10,Math.round(Q(e.params,"maxEdges",500))),c=new Float64Array(o);for(let d=0;d<o;d++)c[d]=n.values[d*o+d];let u=null;if(r==="bins"){const d=oo(e);if(d.genomes.length!==o)throw new Error(`The MAG QC step's matrix has ${o.toLocaleString()} MAGs and this file has ${d.genomes.length.toLocaleString()}, so its rows cannot be matched to their bin counts. Run MAG contact QC again.`);u=Float64Array.from(d.genomes,m=>m.bins)}const l=(d,m,g)=>{if(r==="coverage")return c[d]>0&&c[m]>0?g/Math.sqrt(c[d]*c[m]):Number.NaN;if(r==="bins"&&u!==null){const p=u[d]*u[m];return p>0?g/p:Number.NaN}return g},h=[];for(let d=0;d<o;d++)for(let m=d+1;m<o;m++){const g=n.values[d*o+m];if(!Number.isFinite(g)||g<=0)continue;const p=l(d,m,g);!Number.isFinite(p)||p<i||h.push({a:s===null?`MAG ${d}`:s[d],b:s===null?`MAG ${m}`:s[m],weight:p,raw:g})}return h.sort((d,m)=>m.weight-d.weight),h.length>a&&e.note(`${(h.length-a).toLocaleString()} weaker edges are not listed.`),[{kind:"table",id:"magnetwork",label:"Inter-MAG edges",columns:[{key:"a",label:"genome1",kind:"text"},{key:"b",label:"genome2",kind:"text"},{key:"raw",label:"contacts",kind:"number",digits:0},{key:"weight",label:"weight",kind:"number",digits:6}],rows:h.slice(0,a)}]},qg=async e=>{const t=oo(e);if(t.genomes.length===0)return[];const n=nt(e.params,"balance",!1),s=ee(e.mc,n);$1(e);const o=Dg(t.contigs,e.mc.nBins),r=Int32Array.from(t.contigs.map(m=>t.allowed.has(m.genome)?m.genome:-1)),i=new Lg(t.contigs.length,r);e.progress(0,1,"reading pixels"),await e.mc.scanPixels({onChunk:m=>{e.throwIfCancelled();for(let g=0;g<m.length;g++){const p=m.bin1[g],w=m.bin2[g],b=m.count[g],y=s===null?b:b*s[p]*s[w];i.add(o[p],o[w],y)}return!0},onProgress:(m,g)=>e.progress(m,g,"reading pixels")}),e.throwIfCancelled(),i.droppedPartners>0&&e.note(`${i.droppedPartners.toLocaleString()} partner observations were past the per-contig cap, so a few "top partner" calls are from the partners seen first.`);const a=Q(e.params,"minContacts",10),c=Q(e.params,"flagAbove",.5),u=[],l=new le,h=new Float32Array(e.mc.nBins).fill(Number.NaN);for(let m=0;m<t.contigs.length;m++){const g=t.contigs[m];if(r[m]<0)continue;const p=i.own[m],w=i.other[m],b=p+w,y=b>0?w/b:Number.NaN,A=i.topPartner(m),N=b>=a;if(N&&Number.isFinite(y))for(let I=g.startBin;I<g.startBin+g.bins;I++)h[I]=1-y;u.push({contig:g.name,genome:e.mc.genomeNames[r[m]],contacts:b,outside:N?y:Number.NaN,partner:A===null?"":e.mc.genomeNames[A.genome],flagged:N&&y>c?"yes":""}),N&&y>c&&l.add(g.name,0,g.length,{score:y,name:A===null?"":e.mc.genomeNames[A.genome],detail:`${(y*100).toFixed(1)}% of contact leaves ${e.mc.genomeNames[r[m]]}`})}const f=u.filter(m=>m.flagged==="yes").length;e.note(`${f.toLocaleString()} of ${u.length.toLocaleString()} contigs send more than ${(c*100).toFixed(0)}% of their contact outside their own MAG.`);const d=[{kind:"table",id:"magpurity",label:"Contig purity",columns:[{key:"contig",label:"Contig",kind:"text"},{key:"genome",label:"Assigned to",kind:"text"},{key:"contacts",label:"Contacts",kind:"number",digits:0},{key:"outside",label:"Outside fraction",kind:"number",digits:3},{key:"partner",label:"Top partner",kind:"text"},{key:"flagged",label:"Flagged",kind:"text"}],rows:u.sort((m,g)=>Number(g.outside||0)-Number(m.outside||0))},{kind:"profile",id:"magpurity-track",label:"Contig purity",values:h,extent:[0,e.mc.nBins],binsize:e.mc.binsize,unit:""}];return f>0&&d.push({kind:"intervals",id:"magpurity-flagged",label:"Contigs to look at",payload:{kind:"features",data:l.finish()},noun:{one:"contig",many:"contigs"},display:"overlay",look:"corner"}),d},Ug=async e=>{const t=oo(e),n=nt(e.params,"balance",!1),s=e.framing.value===""?j:e.framing.value,o=Math.max(2,Math.round(Q(e.params,"minContigs",4))),r=Q(e.params,"flagBelow",.1),i=t.genomes.filter(h=>h.contigs>=o);if(i.length===0)return e.note(`No MAG has ${o} or more contigs, so none can be split into two blocks.`),[];const a=[],c=new le;for(let h=0;h<i.length;h++){await e.breathe(),e.progress(h,i.length,i[h].name);const f=i[h],d=e.mc.genomeExtent(f.id),m=await e.mc.matrix({rows:[d[0],d[1]],cols:[d[0],d[1]],balance:n,value:s}),g=e.mc.aggregate(m,"contig"),p=g.nrows;if(p<o)continue;const w=new Float64Array(p*p);for(let k=0;k<p;k++)for(let C=0;C<p;C++){const B=g.values[k*p+C];w[k*p+C]=Number.isFinite(B)?B:0}const b=t8(w,p);if(b===null)continue;let y=0,A=0;for(let k=0;k<p;k++)for(let C=k+1;C<p;C++){const B=w[k*p+C];b.side[k]===b.side[C]?y+=B:A+=B}const N=y>0?A/y:Number.NaN,I=e.mc.chromnames,M=[];for(let k=0;k<t.contigs.length;k++)t.contigs[k].genome===f.id&&M.push(k);const x=M.filter((k,C)=>b.side[C]===1).map(k=>I[k]),v=M.filter((k,C)=>b.side[C]===-1).map(k=>I[k]),S=Number.isFinite(N)&&N<r;if(a.push({genome:f.name,contigs:f.contigs,ratio:N,sideA:x.length,sideB:v.length,flagged:S?"yes":""}),S)for(const[k,C]of[["A",x],["B",v]])for(const B of C){const F=t.contigs.find(E=>E.name===B);F!==void 0&&c.add(B,0,F.length,{name:`${f.name} · side ${k}`,score:N,detail:`cross-block ratio ${N.toFixed(4)}`})}}e.progress(i.length,i.length,"done");const u=a.filter(h=>h.flagged==="yes").length;e.note(`${u.toLocaleString()} of ${a.length.toLocaleString()} MAGs split into two blocks with less than ${r} of their internal contact crossing.`);const l=[{kind:"table",id:"magsplit",label:"Split MAGs",columns:[{key:"genome",label:"MAG",kind:"text"},{key:"contigs",label:"Contigs",kind:"number",digits:0},{key:"ratio",label:"Cross-block ratio",kind:"number",digits:4},{key:"sideA",label:"Side A",kind:"number",digits:0},{key:"sideB",label:"Side B",kind:"number",digits:0},{key:"flagged",label:"Flagged",kind:"text"}],rows:a.sort((h,f)=>Number(h.ratio||1)-Number(f.ratio||1))}];return u>0&&l.push({kind:"intervals",id:"magsplit-flagged",label:"MAGs that look like two things",payload:{kind:"features",data:c.finish()},noun:{one:"MAG",many:"MAGs"},display:"overlay",look:"corner"}),l},Gg={expected:v7,pairsqc:Zm,coverage:Mm,cistrans:Wd,cellqc:Cd,insulation:H7,di:B8,hicscore:P8,scalogram:lm,fourc:B7,apa:sd,loops:X9,chromosight:Od,compartments:l8,interarm:tg,hicrep:pm,structuremap:pg,spatialtracks:bg,reconstruct3d:Ig,magqc:Rg,magnetwork:zg,magpurity:qg,magsplit:Ug};function Hg(e){const t=[],n=e;if(n===null||typeof n!="object")return t;const s=r=>{if(r===void 0)return;const i=r.buffer;i instanceof ArrayBuffer&&!t.includes(i)&&t.push(i)},o=e;if(o.values instanceof Float32Array)return s(o.values),o.over instanceof Float32Array&&s(o.over),t;if(!Array.isArray(n.outputs))return t;for(const r of n.outputs)switch(r.kind){case"profile":s(r.values);break;case"matrix":if(s(r.values),r.streaks!==void 0){const i=r.streaks;for(const a of[i.x0,i.x1,i.y0,i.y1,i.strand,i.anchors])s(a)}break;case"curve":for(const i of r.series)s(i.x),s(i.y),s(i.low),s(i.high);break;case"intervals":{const i=r.payload.data;for(const a of Object.values(i))ArrayBuffer.isView(a)&&s(a);break}}return t}const E1=self,B1=Math.max(0,Math.min(7,(typeof navigator>"u"?1:navigator.hardwareConcurrency||1)-1));g4(F4,B1);e6(o6,B1);let Ce=null;const Ct=new Set;function Qg(){if(Ce===null)throw new Error("no file is open in the analysis worker");return Ce}function we(e,t=[]){E1.postMessage(e,t)}async function Kg(e){Ce?.mc.close(),Ce=null,Ct.clear();const t=await Hl(e.uri,e.source,{report:(o,r,i)=>we({type:"progress",id:e.id,done:o,total:r,note:i}),cancelled:()=>Ct.has(e.id),...e.binning===void 0?{}:{binning:e.binning}}),n=t.source;let s=t.mc;if(e.edit!==void 0){const o=wt.withLens(s,e.edit);if(o.refusal!==null)throw s.close(),new T("unsupported",o.refusal);s=o.map}if(e.cells!==void 0&&s.cells.length>0&&s.selectCells(e.cells),e.resample!==void 0&&await O1(s,e.resample,e.id),e.coarsen!==void 0)try{s=T1(s,e.coarsen)}catch(o){throw s.close(),o}return Ce={mc:s,source:n},{nBins:s.nBins,binsize:s.binsize}}function T1(e,t){if(t===e.binsize)return e;const n=t/e.binsize;if(!Number.isInteger(n)||n<1)throw new T("unsupported",`This map's bins are ${e.binsize.toLocaleString("en-US")} bp, and ${t.toLocaleString("en-US")} bp is not a whole number of them, so it is not measured at that resolution.`);const s=wt.coarsened(e,n);if(s.refusal!==null)throw new T("unsupported",s.refusal);return s.map}async function O1(e,t,n){await e.resample({contacts:t.contacts,...t.seed===void 0?{}:{seed:t.seed},...t.alpha===void 0?{}:{alpha:t.alpha}},{...t.census===void 0?{}:{census:t.census},onProgress:(s,o)=>we({type:"progress",id:n,done:s,total:o,note:"counting contacts"}),cancelled:()=>Ct.has(n)})}const Wg=0,Yg=[Hf,Qf].filter(e=>e!=="").join(" ");async function Vg(e){const t=Gg[e.task];if(t===void 0)throw new Error(`no analysis runner is registered for the task ${e.task}`);const{mc:n}=Qg(),s=e.id,o=[],r=performance.now(),i={mc:n,params:e.params,framing:e.framing,inputs:e.inputs,cancelled:()=>Ct.has(s),throwIfCancelled:()=>{if(Ct.has(s))throw Ze()},breathe:async()=>{if(await xt(),Ct.has(s))throw Ze()},progress:(c,u,l)=>we({type:"progress",id:s,done:c,total:u,note:l}),note:c=>{o.push(c)},toBp:c=>c*n.binsize,toBins:c=>Math.max(1,Math.round(c/n.binsize)),openBytes:async c=>await cr({kind:"remote",url:c}),openSource:async c=>await cr(c),peer:async c=>{const u=await Hl(c.uri,c.source,{report:(h,f,d)=>we({type:"progress",id:s,done:h,total:f,note:d}),cancelled:()=>Ct.has(s),detached:!0,...c.binning===void 0?{}:{binning:c.binning}});if(c.cells!==void 0&&u.mc.cells.length>0&&u.mc.selectCells(c.cells),c.resample!==void 0)try{await O1(u.mc,c.resample,s)}catch(h){throw u.mc.close(),u.source.close(),h}let l=u.mc;if(c.coarsen!==void 0)try{l=T1(u.mc,c.coarsen)}catch{l=u.mc}return{mc:l,close:()=>{l.close(),u.source.close()}}}},a=await t(i);return i.throwIfCancelled(),{outputs:a,provenance:{task:e.task,taskVersion:Wg,params:e.params,framing:e.framing,app:Yg,createdAt:new Date().toISOString()},notes:o,ms:performance.now()-r}}async function Xg(e){const t=e.id,n=e.n,s=await v4(e.values,e.n,async o=>{if(o%Jg===0){if(await xt(),Ct.has(t))throw Ze();we({type:"progress",id:t,done:o,total:n,note:"correlating"})}});if(Ct.has(t))throw Ze();return s}const Jg=64;function Zg(e){if(Ct.has(e.id))throw Ze();const t=c6({nrows:e.nrows,ncols:e.ncols,values:e.values},e.counts,e.spec,e.over??void 0);if(Ct.has(e.id))throw Ze();return{values:t.values,over:t.over,applied:t.applied,scope:t.scope}}async function jg(e){switch(e.kind){case"open":return Kg(e);case"run":return Vg(e);case"correlate":return Xg(e);case"smooth":return Zg(e);case"cancel":return Ct.add(e.target),null;case"close":return Ce?.mc.close(),Ce=null,Ct.clear(),Cn(),null}}async function tp(e){try{const t=await jg(e);we({type:"result",id:e.id,kind:e.kind,payload:t},Hg(t))}catch(t){we({type:"error",id:e.id,error:Kf(t)})}finally{Ct.delete(e.id)}}E1.onmessage=e=>{tp(e.data)};const ep=z1();setInterval(()=>we({type:"busy",fraction:ep.busy()}),P1);
|