chromosomix 0.16.0 → 0.17.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.
@@ -0,0 +1,8 @@
1
+ function pt(){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 w1=200,b1=3e3,A1=3e4,y1=1e3;function N1(e=w1,t=b1){const n=[];let s=performance.now();const o=setInterval(()=>{const r=performance.now(),i=r-s;for(s=r,i<A1?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 Z(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(Z).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 Et(e){return`[${e.map(Z).join(", ")}]`}function gc(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 E extends Error{code;detail;constructor(t,n,s={}){super(n),this.name="ViewerError",this.code=t,this.detail=s}}class ot extends E{constructor(t,n={},s="format"){super(s,t,n),this.name="MetaCoolerFormatError"}}function Re(e,t=20){return e.length<=t?Et(e):`${Et(e.slice(0,t))} ... (${e.length-t} more)`}const rs="HDF5::MetaCooler",Ks=1,pc="HDF5::MMetaCooler",sr="HDF5::Cooler",ln="HDF5::SCOOL",Ws=1,Wn="cells",or=["bins","pixels","indexes"],Wr=5e4,M1=3/4,I1=8,kn=2**31,x1=1e9,v1=2,Yr=["symmetric-upper","square"],Sn="genome-then-length",un="__unbinned__",k1=["","null","none","nan"],Ys=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),S1=new Intl.NumberFormat(void 0,{maximumFractionDigits:3}),C1=new Intl.NumberFormat(void 0,{maximumSignificantDigits:3}),Vr=new Map,$1=new Intl.NumberFormat("en-US",{maximumFractionDigits:0}),mt={int(e){return Number.isFinite(e)?Ys.format(e):"—"},num(e){if(!Number.isFinite(e))return"—";if(Number.isInteger(e))return Ys.format(e);const t=Math.abs(e);return t>=.001?S1.format(e):t>=1e-7?C1.format(e):e.toExponential(2)},fixed(e,t){if(!Number.isFinite(e))return"—";let n=Vr.get(t);return n===void 0&&(n=new Intl.NumberFormat(void 0,{minimumFractionDigits:t,maximumFractionDigits:t}),Vr.set(t,n)),n.format(e)},pct(e,t=1){return Number.isFinite(e)?`${(e*100).toFixed(t)}%`:"—"},pos(e){return Number.isFinite(e)?$1.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`:`${Ys.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 F1(e){return!Number.isFinite(e)||e<=0?"—":e>=1e6?`${Vs(e/1e6)} Mb`:e>=1e3?`${Vs(e/1e3)} kb`:`${Vs(e)} bp`}function Vs(e){return String(Number(e.toFixed(2)))}const E1=["exact","case","decorated","prefix","padded","roman","organelle","accession","version"],Xr=new Set(["gi","gb","ref","emb","dbj","tpg","tpe","tpd","lcl","pir","prf","sp","tr","pdb","ena","bbs"]);function rr(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=>Xr.has(s.toLowerCase()))){const s=n.filter((o,r)=>Xr.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 wc=/^(?:chromosome|chrom|chr)[ _.-]?/i;function bc(e){const t=e.replace(wc,"");if(t===""||t===e)return null;const n=t.toLowerCase();return/^[0-9]/.test(t)||as.has(n)||is.has(n)||ks(t)>0||/^un[_.-]/i.test(t)||/^[A-Za-z]{1,2}[0-9]/.test(t)||yc.test(t)||Nc.test(t.replace(/\.[0-9]+$/,""))?t:null}const B1=/^(?:lg|linkage_?group|group)[ _.-]?(?=[0-9])/i,Ac=/_(random|alt|fix|hap\d+|maternal|paternal)$/i,T1=/(?:^|[_.-])([A-Z]{2}[0-9]{5,6})v([0-9]+)(?:$|[_.-])/,yc=/^(N[CGTWZ]|AC)_([0-9]{5,})$/i,Nc=/^[A-Z]{1,6}[0-9]{5,8}$/,O1=[["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"]]],is=new Map;for(const[e,t]of O1)for(const n of t)is.set(n,e);const as=new Set(["x","y","z","w"]),L1=/^(XL|L|X{0,3})(IX|IV|V?I{0,3})$/i,_1={"":0,x:10,xx:20,xxx:30,xl:40,l:50},D1={"":0,i:1,ii:2,iii:3,iv:4,v:5,vi:6,vii:7,viii:8,ix:9};function ks(e){const t=L1.exec(e);if(t===null)return 0;const n=_1[t[1].toLowerCase()],s=D1[t[2].toLowerCase()];return n===void 0||s===void 0?0:n+s}const R1=[{from:1,to:22,first:1,tail:["x","y"]},{from:67,to:85,first:1,tail:["x","y"]}];function P1(e){for(const t of R1){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 Bo=200;function z1(e){return e.length<2||as.has(e.toLowerCase())?!1:ks(e)>0}function Me(e){const t=e.map(c=>Mc(c)),s=t.filter(c=>z1(c)).length>=2,o=t.filter(c=>/^[0-9]+$/.test(c)&&Number(c)>=1&&Number(c)<=Bo),r=o.length<Bo,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 Mc(e){const t=rr(e);return(bc(t)??t).replace(Ac,"")}function Yn(e,t){const n=[],s=rr(e);s!==e.trim()&&n.push("decorated");const o=bc(s),r=o??s;o!==null&&n.push("prefix");const i=Ac.exec(r),a=i===null?r:r.slice(0,i.index),c=i===null?"":`+${i[1].toLowerCase()}`,u=a.toLowerCase(),l=T1.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=is.get(u)??is.get(f.toLowerCase());if(m!==void 0)return m!==u&&n.push("organelle"),{key:`org:${m}`,via:n,version:d,opaque:!1};const g=yc.exec(f);if(g!==null){n.push("accession");const b=g[1].toLowerCase()==="nc"?P1(Number(g[2])):null;return b!==null?{key:as.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(Nc.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)<=Bo)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=B1.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(as.has(u)&&!(u==="x"&&t.xIsTen))return{key:`sex:${u}${c}`,via:n,version:null,opaque:!1};if(t.roman){const b=ks(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 cs(e){return E1.indexOf(e)}function q1(e,t){let n="case";for(const s of[...e.via,...t.via])cs(s)>cs(n)&&(n=s);return n}function Xs(e,t){return e===void 0||t===void 0||e<=0||t<=0?"unknown":e===t?"agree":"differ"}const Jr=new WeakMap;class ie{names;context;styleCache=null;get style(){return this.styleCache??=G1(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=Me(this.names);for(const n of t){this.exact.has(n.name)||this.exact.set(n.name,n),Zr(this.folded,n.name.toLowerCase(),n);const s=Yn(n.name,this.context);Zr(this.keyed,s.key,{sequence:n,canon:s})}}static of(t){return new ie(t)}static ofNames(t){return new ie(t.map(n=>({name:n})))}static for(t){const n=Jr.get(t);if(n!==void 0)return n;const s=typeof t[0]=="string"?ie.ofNames(t):ie.of(t);return Jr.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:Xs(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:Xs(s,r[0].length)};const i=n.from??this.context,a=this.byKey(t,Yn(t,i),s);if(a!==null)return a;if(!i.roman){const c=Mc(t).toLowerCase();if(c!=="x"&&c!=="l"&&ks(c)>0)return this.byKey(t,Yn(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=U1(o,s);if(r===null)return null;const i=q1(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&&cs(i)<cs("version")?"version":i,lengths:Xs(s,r.sequence.length)}}}function U1(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 Zr(e,t,n){const s=e.get(t);s===void 0?e.set(t,[n]):s.push(n)}function G1(e,t=Me(e)){if(e.length===0)return"empty";let n=0,s=0,o=0,r=0;for(const a of e){const c=Yn(a,t);if(c.opaque){r++;continue}c.via.includes("accession")?o++:wc.test(rr(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 ls(e,t){const n=H1(e),s=n.get(t);if(s!==void 0)return s;const o=ie.for(e).find(t);return o===null?-1:n.get(o.name)??-1}const jr=new WeakMap;function H1(e){const t=jr.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)}),jr.set(e,n),n}let Xe=null;function mn(){const e=globalThis;return typeof e.window<"u"?!1:typeof e.process<"u"&&e.process?.versions?.node!=null}function Pe(){return Xe||(Xe=Q1().catch(e=>{throw Xe=null,new E("not-hdf5",`Could not initialise the HDF5 (h5wasm) runtime: ${K1(e)}`,{runtime:mn()?"node":"browser"})}),Xe)}async function Q1(){let e;return mn()?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 K1(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}const W1="bhilnpq",Y1="BHILNPQu",V1="defg";function Ic(e){const t=e.trim(),n=()=>{throw new ot(`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 W1.includes(r)?"i":Y1.includes(r)?"u":V1.includes(r)?"f":n()}}const To=new Uint8Array(new Uint32Array([1]).buffer)[0]===1?0:1;function Oo(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=To,i=1-To;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 xc(e){const t=e.length,n=new Int32Array(e.buffer,e.byteOffset,t*2),s=new Int32Array(t),o=To;for(let r=0;r<t;r++)s[r]=n[2*r+o];return s}const X1=new TextDecoder("utf-8");function Lo(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 J1(e,t,n,s,o){const r=o-s;if(r<=0)return new Uint8Array(0);const a=n.metadata.size*r,c=ir(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 Z1(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]=X1.decode(r)}return s}function vc(e,t,n,s,o){const r=o-s;if(r<=0)return[];const i=n.metadata;if(!i.vlen)return Z1(J1(e,t,n,s,o),i.size,r);const a=i.size*r,c=ir(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 j1(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 kc(e,t,n,s,o){const r=t.metadata,i=j1(e.h5,r);if(i===null)return null;const a=s-n,{Module:c}=e.h5,u=ir(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 tu(e,t,n,s){switch(s){case"f64":return new Float64Array(e,t,n).slice();case"i64":case"u64":return Oo(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 eu(e,t,n,s){switch(s){case"i32":return new Int32Array(e,t,n).slice();case"i64":case"u64":return xc(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 Sc(e,t,n,s){if(n-t<=0)return new Float64Array(0);if(s!==void 0){const i=kc(s,e,t,n,tu);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 Oo(r);throw new ot(`/${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=kc(s,e,t,n,eu);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 xc(r);if(ArrayBuffer.isView(r)&&!(r instanceof DataView)){const i=new Int32Array(o);return i.set(r),i}throw new ot(`/${e.path.replace(/^\//,"")} did not read back as a numeric array`,{path:e.path})}function We(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 ot(`no such column: ${s}`,{column:s});if(Array.isArray(o)&&(o.length===0||typeof o[0]=="string"))return o;throw new ot(`column ${s} is not a string column`,{column:s})},numbers(s){const o=n[s];if(o===void 0)throw new ot(`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 ot(`column ${s} is not a numeric column`,{column:s});return Array.from(o)}}}function su(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 ot(`/${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=ti(o??0,0,u),h=ti(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(Lo(e,w)){case"string":d.push(g),m[g]=vc(e,t,p,l,h);break;case"number":d.push(g),m[g]=Sc(p,l,h,{h5:e,file:t});break}return We(h-l,d,m)}function ti(e,t,n){return Math.min(Math.max(Math.trunc(e),t),n)}function ir(e,t){if(t>e.Module.MAXIMUM_MEMORY)throw new ot(`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 ot(`allocation of ${t} bytes in the wasm heap failed`,{nbytes:t});return n}function Rt(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 E("bad-uri",`URI has an empty file path: ${Z(e)}`,{uri:e});return{path:n,group:s}}const ou=["genomes","contigs","bins","pixels","indexes"],ru=["bin-size","format-version","nbins","nnz","sum","ngenomes","ncontigs"];function vt(e,t){const n=e[t];return typeof n=="string"?n:null}function Vn(e,t){const n=e[t];if(n==null)return null;const s=()=>{throw new ot(`attrs[${Z(t)}] must be an integer, got ${Z(n)}`,{key:t,value:n})};if(typeof n=="string"){if(k1.includes(n.trim().toLowerCase()))return null;const o=gc(n);return o===null?s():o}return typeof n=="boolean"?s():typeof n=="number"&&Number.isInteger(n)?n:s()}function Cc(e){const t=e["storage-mode"];if(t==null)return"symmetric-upper";if(typeof t=="string"&&Yr.includes(t))return t;throw new ot(`attrs['storage-mode'] must be one of ${Et([...Yr].sort())}, got ${Z(t)}`,{"storage-mode":t})}function $c(e){return e.has("entries")?e.keys("entries"):[]}function iu(e,t){return or.some(n=>!e.has(`${t}/${n}`))?!1:vt(e.attrsAt(t),"format")===sr}function au(e,t){if(vt(t,"format")===ln)return e.has(Wn);if(vt(t,"metacooler-format")===rs)return!1;const n=vt(t,"format");return n!==null&&n!==sr||or.some(s=>e.has(s))||e.has("chroms")?!1:!e.has("resolutions")&&!e.has("entries")}function cu(e,t){if(vt(t,"format")===ln){const s=e.keys(Wn);if(s.length>0)return{names:s,group:Wn};throw new E("not-a-cooler",`${e.uri} declares format ${Z(ln)} but has no cells under /${Wn}. Top-level keys: ${Et(e.keys("").slice(0,20))}.`,{format:ln,group:e.group})}if(or.some(s=>e.has(s)))return null;const n=e.keys("");return n.length===0?null:iu(e,n[0])?{names:n,group:""}:null}function lu(e,t,n={}){const s=t??e.attrs(),o=vt(s,"format");if(n.metacool===!1&&uu(e,s,o)&&ei(e),o===pc&&e.has("entries"))return{kind:"mmetacool",group:e.group,entries:$c(e)};if(vt(s,"metacooler-format")===rs){const a=ou.filter(c=>!e.has(c));if(a.length===0)return{kind:"metacool",group:e.group};throw new E("not-a-cooler",`${e.uri} declares metacooler-format ${Z(rs)} but is missing ${Et(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:Fc(r)};const i=cu(e,s);if(i!==null)return{kind:"scool",group:e.group,entries:i.names,cellGroup:i.group};if(o===sr)return{kind:"cool",group:e.group};throw n.metacool===!1&&ei(e),new E("not-a-cooler",`${e.uri} is HDF5 but not a cooler or metacool file: its 'format' attribute is ${Z(o)} and 'metacooler-format' is ${Z(vt(s,"metacooler-format"))}. Top-level keys: ${Et(e.keys("").slice(0,20))}. Convert a plain cooler with \`metacooler create cool\`.`,{format:o,group:e.group})}function uu(e,t,n){return n===pc&&e.has("entries")||vt(t,"metacooler-format")===rs}function ei(e){throw new E("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: ${Et(e.keys("").slice(0,20))}.`,{group:e.group})}function hu(e){const{path:t}=Rt(e.uri),n=$c(e),s=n.map(r=>`/entries/${r}`),o=s.length>0?s[0]:"/entries/<name>";throw new E("mmetacool-root",`No metacool entry at root of ${t}. Metacool entries found: ${Et(s)}. Use '::' to specify a group path, e.g. ${t}::${o}.`,{path:t,entries:n})}function Fc(e){return e.length>0&&e.every(n=>/^\d+$/.test(n)&&Number(n)>0)?[...e].sort((n,s)=>Number(n)-Number(s)):e}function fu(e){const t=[...e].sort((n,s)=>n-s);return t[Math.floor(t.length/3)]}function du(e,t){const{path:n}=Rt(e.uri),s=t.map(r=>`/resolutions/${r}`),o=s.length>0?s[0]:"/resolutions/<binsize>";throw new E("mcool-root",`No cooler at root of ${n}: an .mcool is a collection of resolutions, each a complete cooler. Resolutions found: ${Et(s)}. Use '::' to pick one, e.g. ${n}::${o}.`,{path:n,entries:t,group:"resolutions"})}function us(e,t){const n=e.cellGroup??"";return n===""?t:`${n}/${t}`}function Ec(e,t,n){if(Vn(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=us(t,s);return{attrs:e.attrsAt(o),from:o}}function mu(e,t){if(!((t.entries??[]).length>0))throw new E("not-a-cooler",`${Rt(e.uri).path} is a single-cell cooler container with no cells in it.`,{path:Rt(e.uri).path})}function gu(e,t,n,s={}){t.kind==="mmetacool"&&hu(e),t.kind==="mcool"&&du(e,t.entries??[]);const o=n??e.attrs();if(t.kind==="metacool"){const c=Vn(o,"metacooler-format-version");if(c!==null&&c!==Ks)throw new E("bad-format-version",`This file declares metacooler-format-version ${c}; the viewer only understands version ${Ks}. Re-create it with a matching metacooler release, or open it with the version of the viewer that reads ${c}.`,{found:c,expected:Ks});const u=vt(o,"contig-ordering");if(u!==Sn)throw new E("bad-ordering",`This file's contig-ordering is ${Z(u)}; the viewer requires ${Z(Sn)}. 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 ${Sn}\`.`,{found:u,expected:Sn})}const r=t.kind==="scool"?Ec(e,t,o):{attrs:o};if(t.kind==="scool"){mu(e,t);const c=Vn(o,"format-version");if(vt(o,"format")===ln&&c!==null&&c!==Ws)throw new E("bad-format-version",`This file declares scool format-version ${c}; the viewer understands version ${Ws}. Open it with a viewer that reads ${c}, or re-create it with \`cooler.create_scool\`.`,{found:c,expected:Ws})}const i=vt(r.attrs,"bin-type"),a=Vn(r.attrs,"bin-size");if(i==="variable"||a===null||a<=0)throw new E("variable-bins",s.metacool===!1?`The viewer supports fixed-bin files only; this file's bin-type is ${Z(i)} and its bin-size is ${Z(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 ${Z(i)} and its bin-size is ${Z(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});Cc(r.attrs)}function Bc(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function pu(e){if(typeof e=="number")return Number.isFinite(e)?Math.trunc(e):e;if(typeof e=="string"){const t=gc(e);return t===null?e:t}return e}function ue(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Je(e){return typeof e=="string"?e:null}function wu(e){const t={};for(const[w,b]of Object.entries(e))t[w]=Bc(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 ru)p[w]!==void 0&&(p[w]=pu(p[w]));return{...t,format:Je(a),"format-url":Je(c),"format-version":ue(p["format-version"]),"bin-size":ue(p["bin-size"]),"bin-type":Je(t["bin-type"]),ordering:Je(l),assembly:Je(g),"storage-mode":Cc(e),nbins:ue(p.nbins),nnz:ue(p.nnz),sum:ue(p.sum),ngenomes:ue(p.ngenomes),ncontigs:ue(p.ncontigs)}}function bu(e){const t=Bc(e.metadata);return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}const Au=new TextDecoder("utf-8");async function yu(e,t,n){const s=await Pe(),o=await t.mount();let r;try{r=new s.File(o,"r")}catch(u){throw t.close(),new E("not-hdf5",`${e} could not be opened as an HDF5 file: ${Nu(u)}`,{uri:e,source:t.id})}const i=Tc(n);try{if(i!=="/"){const u=r.get(i);if(u===null)throw new E("entry-not-found",`Group '${i}' not found in ${t.id}. Top-level keys: ${Re(r.keys())}`,{uri:e,group:i,available:r.keys()});if(!(u instanceof s.Group))throw new ot(`'${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=Fc(l.keys()),c=u;break}}}catch{}return new ar(e,i,s,r,t,a,c)}class ar{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 ot(`${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 ot(`${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 Sc(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(Lo(this.h5,o.metadata)!=="number")throw new ot(`${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(Lo(this.h5,r)!=="string")throw new ot(`${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 vc(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 ot(`${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 su(this.h5,this.file,r,i,n,s,o)}at(t){const n=this.resolve(t);return new ar(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:Tc(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 ot(`${this.describe(t)} does not exist`,{uri:this.uri,path:this.resolve(t)});if(!(n instanceof this.h5.Dataset))throw new ot(`${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 ot(`/${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 Mu(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(Au.decode(f))}const l=s.shape;return l&&l.length>0?u:u[0]??""}assertOpen(){if(this.closed)throw new ot(`${this.uri} is closed`,{uri:this.uri})}}function Nu(e){return e instanceof Error?e.message:String(e)}function Tc(e){const t=`/${e}`.replace(/\/+/g,"/").replace(/(.)\/$/,"$1");return t===""?"/":t}function Mu(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 Oe=4096,hs={binsPerCell:1,contigsPerCell:1};function Oc(e,t,n,s=hs,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:hs};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,Lc(i,u,a,o));return xu(r,i,c,u,l,o)}function Iu(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 Lc(e,t,n,s){let o=s;const r=c=>Iu(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 xu(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 vu(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 ni(e,t,n,s=hs,o=Oe,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=vu(a),u=r===void 0||r.length===0?void 0:Int32Array.from(c,m=>r[a[m]]??-1),l=Oc(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 ku(e,t,n,s=Oe,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,Lc(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 _c(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 Su(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 Dc(e,t,n){return _c(e.contigsOfBins(t,n))}function Rc(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 _c(r)}function si(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=Oc(s,o,t,hs,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 Cu(e,t,n,s,o,r,i=!0,a=Number.POSITIVE_INFINITY){const c=m=>o==="contig"?Dc(n,m[0],m[1]):Rc(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=si(c(e),a,l),f=u?h:si(c(t),a,l),d=_o(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 _o(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 $u(e,t,n,s,o=!0){const r=u=>s==="contig"?Dc(t,u[0],u[1]):Rc(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 Su(e,a,c,s,i&&o)}function Fu(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 Eu{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 Fu(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 Ze=256,Bu=["#FFFEF9","#FCF9CE","#FFF2A9","#FDE188","#FFCA67","#FAAA4B","#F78E40","#F15C34","#ED3024","#D42027","#B01F29","#7A1128","#1A0A10"],Tu=["#FFFFFF","#FFF5F0","#FEE0D2","#FCBBA1","#FC9272","#FB6A4A","#EF3B2C","#CB181D","#A50F15","#67000D"],Ou=["#053061","#2166AC","#4393C3","#92C5DE","#D1E5F0","#F7F7F7","#FDDBC7","#F4A582","#D6604D","#B2182B","#67001F"],Lu=["#1659b1","#487BA8","#819EC8","#D1E6F1","#FFFFFF","#FAC1C1","#F1606C","#EE222A"],_u=[0,.125,.25,.375,.5,2/3,5/6,1],Du=["#00004D","#0000FF","#FFFFFF","#FF0000","#800000"];function je(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}je(Bu,Ze),je(Tu,Ze),je(Ou,Ze),je(Lu,Ze,_u),je(Du,Ze);const Pc="RdBu_r",Ru=16384;function oi(e,t=Ru){return e<=t?1:Math.ceil(e/t)}const Yt="weight",V="count",Pu=new Set(["bin1_id","bin2_id"]);function zu(e){const t=e.keys("pixels").filter(n=>!Pu.has(n));return[...t.filter(n=>n===V),...t.filter(n=>n!==V).sort()]}const Js={range:"Use a narrower --range/--range2.",binSelection:"Use --range to select a smaller region, or --level contig."};function qu(e,t,n){if(e*t>Wr**2){const s=e*t*8/1e9;throw new E("dense-too-large",`Refusing to allocate a ${e}×${t} dense matrix (${s.toFixed(1)} GB). ${n}`,{nRows:e,nCols:t,limit:Wr})}}function Uu(e,t){const n=e*t,s=Math.ceil(e/oi(e))*Math.ceil(t/oi(t));return n*4+s*12+Qu}function zc(){const e=globalThis.navigator?.deviceMemory;return Gu(typeof e=="number"&&e>0?e:I1)}function Gu(e){const t=e*1073741824*M1;return e>=v1?Math.max(x1,t):t}function Hu(e,t,n,s={}){const o=e*t;if(o*4>=kn){const a=Math.floor(Math.sqrt(kn/4));throw new E("dense-too-large",`Refusing to load a ${e}×${t} block: its ${Do(o)} values are ${mt.bytes(o*4)} and a browser serves at most ${mt.bytes(kn)} 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:kn,where:"array-limit"})}const r=s.budgetBytes??zc(),i=Uu(e,t);if(!(i<=r))throw new E("dense-too-large",`Refusing to load a ${e}×${t} block in a browser tab: ${Do(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 Do(e){return e>=1e9?`${(e/1e9).toFixed(1)} billion`:e>=1e6?`${(e/1e6).toFixed(0)} million`:String(e)}function ri(e){const t=Ic(e);if(t==="i"||t==="u"||t==="f")return t;throw new E("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 Ss=1e6,Qu=Ss*36;class cr{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 Ku(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 cr(s,t)}}function lr(e,t,n,s=V,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 Wu(e,t,n,s,o={}){const r=Ku(e,t,n);if(r===null)return!0;const{p0:i,p1:a,rows:c}=r,u=Math.max(1,Math.trunc(o.chunkSize??Ss)),l=a-i,h=o.value??V;for(let f=i;f<a;f+=u){if(o.cancelled?.()===!0)return!1;const d=Math.min(f+u,a);s(lr(e,f,d,h,c)),o.onProgress?.(d-i,l),await pt()}return!0}const qc=65536;async function Yu(e,t,n,s={},o=null){const r=Math.max(1,Math.trunc(s.chunkSize??Ss)),i=t.reduce((l,[h,f])=>l+Math.max(0,f-h),0),a=s.value??V,c=o===null?null:new cr(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(lr(e,f,d,a,c)),u+=d-f,s.onProgress?.(u,i),await pt()}}return!0}function ze(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 Vu(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 Xu(e,t,n){const s=ii(t.rows,e.nBins,"rows"),o=ii(t.cols??t.rows,e.nBins,"cols"),r=s[1]-s[0],i=o[1]-o[0];qu(r,i,n),Hu(r,i,n,{...t.budgetBytes===void 0?{}:{budgetBytes:t.budgetBytes}});const a=Ju(r,i,n);if(r>0&&i>0){const c=ze(s,o,e.storageMode);await e.store.forEachWindow(s,o,c,u=>{Vu(u,s,o,c,a)},{chunkSize:Ss,value:t.value??V}),t.balance===!0&&Zu(e.handle,s,o,a)}return{nrows:r,ncols:i,values:a,rowExtent:s,colExtent:o}}function Ju(e,t,n){try{return new Float32Array(e*t)}catch(s){const o=e*t;throw new E("dense-too-large",`This machine could not allocate the ${e}×${t} block: ${Do(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 Zu(e,t,n,s){const o=Yt,r=`bins/${o}`;if(!e.has(r))throw new E("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 ii(e,t,n){const[s,o]=e;if(!Number.isInteger(s)||!Number.isInteger(o)||s<0||o<s||o>t)throw new E("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 Uc{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 zu(this.handle)}binOffsets(){return this.offsets??=this.handle.readNumeric("indexes/bin1_offset"),this.offsets}async forEachWindow(t,n,s,o,r={}){return Wu(this.handle,s.span[0],s.span[1],o,r)}async forEachBands(t,n,s={}){return Yu(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 cr(this.binOffsets(),0);for(let r=0;r<s;r+=n){const i=Math.min(r+n,s),a=t.onChunk(lr(this.handle,r,i,V,o));if(t.onProgress?.(i,s),a===!1)return;await(t.pause?.()??pt())}}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]+qc?i[1]=Math.max(i[1],r[1]):o.push([r[0],r[1]])}return o}}const ju=64*1024*1024,t2=256;function ge(e,t,n){return e*n-e*(e-1)/2+(t-e)}function fs(e){return e*(e+1)/2}function Gc(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 e2(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**e2(n,e);return t}function s2(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 ai={low:-12,high:8},o2=4e6;function r2(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 i2(e){const{store:t,layout:n,weights:s}=e,o=n.n,r=n.slot,i=r.length,a=new Uint8Array(fs(o)),c=new Float64Array(256),u=e.gather===void 0?null:a2(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??ju)/(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 F=k.bin1[C],B=k.bin2[C];if(B<F)continue;const T=r[F],L=r[B];if(T<0||L<0)continue;let $=k.count[C];s!==null&&($*=s[F]*s[B]),$>0&&(m[(T-N)*o+L]+=T===L&&F!==B?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??=s2(m.subarray(0,x))??ai;for(let k=N;k<I;k++){const C=(k-N)*o;let F=ge(k,k,o);for(let B=k;B<o;B++,F++){const T=Gc(m[C+B],y);a[F]=T,c[T]++}u?.row(k,m,C)}b=g!==null?v+p(M):I,e.onProgress?.(b,w),await pt()}return{cells:a,quantizer:y??ai,histogram:c,pixels:A,...u===null?{}:{contacts:u.finish()}}}function a2(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=r2(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(fs(u)),f=new Uint32Array(fs(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??o2)),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],F=ge(C,C,u)-C,B=g[M]>=0;for(let T=M;T<s;T++){const L=r[T];if(L===0)continue;const $=x[v+T]/(S*L);T-M<o&&i[T]===k?l[M*o+(T-M)]=$:B&&$>0&&g[T]>=0&&I(T,$);const _=F+c[T];h[_]+=$,f[_]++,d[M]+=$,T!==M&&(d[T]+=$)}},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:c2(w,A),cols:b.slice(0,A),values:y.slice(0,A),complete:N}}:{}}}}}function c2(e,t){return e[e.length-1]=t,e}function l2(e,t,n=t2){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(fs(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[ge(f,g,i)]],b=1;p<i&&(w+=s[a[ge(f,p,i)]],b++),d<i&&(w+=s[a[d<=g?ge(d,g,i):ge(g,d,i)]],b++,p<i&&(w+=s[a[ge(d,p,i)]],b++)),u[l]=Gc(w/b,t)}}r={n:c,cells:u},o.push(r)}return o}function lt(e){return e.gap!==void 0}const u2=["debris","contaminant","haplotig","unplaced"];function Cs(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 Wt(e,t){for(let n=1;;n++){const s=`${e}_e${n}`;if(!t.has(s))return s}}function $s(e){return lt(e)?e.gap:e.end-e.start}function Be(e){let t=0;for(const n of e)t+=$s(n);return t}function Vt(e,t,n){return e<t?t:e>n?n:e}function h2(e,t,n){return lt(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 Le(e,t,n){const s=[],o=[];let r=0;for(const i of e){const a=$s(i);if(r+a<=t)s.push(i);else if(r>=t)o.push(i);else{const[c,u]=h2(i,t-r,n);s.push(c),o.push(u)}r+=a}return[s,o]}function Cn(e,t,n,s){const[o,r]=Le(e,t,s),[i,a]=Le(r,n-t,s);return[o,i,a]}function tn(e){const t=[];for(let n=e.length-1;n>=0;n--){const s=e[n];t.push(lt(s)?{gap:s.gap}:{...s,strand:s.strand===1?-1:1})}return t}function St(e){const t=[];for(const n of e){if($s(n)===0)continue;const s=t[t.length-1];if(s!==void 0&&lt(s)&&lt(n)){t[t.length-1]={gap:s.gap+n.gap};continue}if(s!==void 0&&!lt(s)&&!lt(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 f2{counter=0;next(t){return this.counter+=1,`${t.split("~")[0]}~${this.counter}`}}function d2(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 kt(e,t){return e.sequences.find(n=>n.name===t)??null}function $n(e,t,n){const s=Be(e.parts),o=Vt(Math.round(t),0,s),r=Vt(Math.round(n),0,s);return o<=r?[o,r]:[r,o]}function m2(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(Cs(n).keys());switch(t.op){case"cut":{const c=kt(r,t.sequence);if(c===null)return e;const u=Vt(Math.round(t.at),0,Be(c.parts)),[l,h]=Le(c.parts,u,s);return c.parts=[...l,...h],r}case"invert":{const c=kt(r,t.sequence);if(c===null)return e;const[u,l]=$n(c,t.from,t.to);if(l===u)return e;const[h,f,d]=Cn(c.parts,u,l,s);return c.parts=St([...h,...tn(f),...d]),r}case"move":case"duplicate":{const c=kt(r,t.sequence),u=kt(r,t.into);if(c===null||u===null)return e;const[l,h]=$n(c,t.from,t.to);if(h===l)return e;const[f,d,m]=Cn(c.parts,l,h,s),g=t.strand===1?d:tn(d);t.op==="move"?c.parts=St([...f,...m]):g.forEach((y,A)=>{lt(y)||(g[A]={...y,id:s.next(y.id)})});const p=Vt(Math.round(t.at),0,Be(u.parts)),[w,b]=Le(u.parts,p,s);return u.parts=St([...w,...g,...b]),c!==u&&c.parts.length===0&&(r.sequences=r.sequences.filter(y=>y!==c)),r}case"join":{const c=kt(r,t.a),u=kt(r,t.b);if(c===null||u===null||c===u)return e;const l=t.aEnd==="end"?c.parts:tn(c.parts),h=t.bEnd==="start"?u.parts:tn(u.parts),f=t.gap>0?[{gap:Math.round(t.gap)}]:[];return c.parts=St([...l,...f,...h]),a.has(c.name)&&!Fs(c,n)&&(i.delete(c.name),c.name=Wt(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=kt(r,t.sequence);if(c===null)return e;const u=Vt(Math.round(t.at),0,Be(c.parts));if(u===0||u===Be(c.parts))return e;const[l,h]=Le(c.parts,u,s);c.parts=St(l);const f=rn(c.name);a.has(c.name)&&(i.delete(c.name),c.name=Wt(f,i),i.add(c.name));const d=t.name!==void 0&&!i.has(t.name)?t.name:Wt(f,i);i.add(d);const m=r.sequences.indexOf(c);return r.sequences.splice(m+1,0,{name:d,parts:St(h)}),r}case"aside":{const c=kt(r,t.sequence);if(c===null)return e;const[u,l]=$n(c,t.from,t.to);if(l===u)return e;const[h,f,d]=Cn(c.parts,u,l,s),m=typeof t.genome=="string"&&t.genome!==""?t.genome:void 0;for(const g of f)lt(g)||r.aside.push({piece:g,why:t.why,...m===void 0?{}:{genome:m}});return c.parts=St([...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=Wt(rn(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=>!lt(f)&&u(f)))||r.aside.some(h=>u(h.piece)))return e;const l=i.has(c.name)?Wt(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=kt(r,t.sequence);if(c===null)return e;const u=Vt(Math.round(t.at),0,Be(c.parts)),[l,h]=Le(c.parts,u,s);return c.parts=St([...h,...l]),r}case"rename":{const c=kt(r,t.sequence);return c===null||t.name===""||i.has(t.name)&&t.name!==c.name||a.has(t.name)&&Hc(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=kt(r,t.sequence);if(c===null)return e;const[u,l]=$n(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]=Cn(c.parts,u,l,s),w=St(t.strand===1?g:tn(g)),b=St([...m,...p]);if(b.every(A=>lt(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=Wt(rn(c.name),i),i.add(c.name));const y=Wt(rn(c.name),i);return i.add(y),h.splice(d<0?h.length:d,0,{name:y,parts:w}),r}case"layout":return g2(t,n,s)}}function g2(e,t,n){const s=Cs(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=Vt(Math.round(h),0,d),g=Vt(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&&lt(h[0]);)h.shift();for(;h.length>0&&lt(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:Wt(f===""?"seq":f,a);a.add(d),c.push({name:d,parts:St(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"||!u2.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 rn(e){return e.replace(/_e\d+$/,"")}function Fs(e,t){let n=0,s=null;for(const i of e.parts){if(lt(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 p2(e,t){const n=new Set(Cs(t).keys()),s=new Set(e.sequences.map(o=>o.name));for(const o of e.sequences)n.has(o.name)&&!Fs(o,t)&&(s.delete(o.name),o.name=Wt(rn(o.name),s),s.add(o.name));for(const o of e.sequences){if(o.named===!0)continue;const r=Hc(o,t);r!==null&&o.name!==r&&!s.has(r)&&(s.delete(o.name),o.name=r,s.add(r))}return e}function Hc(e,t){if(!Fs(e,t))return null;const n=e.parts[0];return lt(n)?null:n.sequence}class ur{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),!lt(i)){const a=this.byOriginal.get(i.sequence)??[];a.push({sequence:s.name,offset:r,piece:i}),this.byOriginal.set(i.sequence,a)}r+=$s(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 f2;let s=d2(t.original);const o=Vt(t.cursor,0,t.history.length);for(let r=0;r<o;r++)s=p2(m2(s,t.history[r].step,t.original,n),t.original);return new ur(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]&&Fs(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=w2(o,n);if(r<0)return null;const i=s.parts[r];if(lt(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(lt(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 w2(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 b2(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 Cs(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 A2=64;class hr{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=lt(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=lt(m)?void 0:r.get(m.sequence);if(lt(m)||A===void 0){for(let F=0;F<y;F++)i.push(-1);return}const[N,I]=t.contigBinExtent(A),M=I-N,x=t.contigLengths[A],v=F=>F>=x?M:Math.max(0,Math.min(M,Math.round(F/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 F=0;F<y;F++){const B=Math.min(C-1,Math.floor((F+.5)*C/y));i.push(N+(m.strand===1?S+B:k-1-B))}}),a.push(l.name),c.push(h),u.push(i.length)}return new hr({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 Qc{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 y2{constructor(t,n,s){this.inner=t,this.lens=n,this.upper=s}buffer=new Qc;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,A2):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,ze(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 N2(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 M2(e){return We(e.names.length,["name","length"],{name:e.names,length:e.lengths})}function I2(e,t,n,s={}){const o=b2(e,t,Array.from(n));if(o!==null)return{refusal:`The edit was made on another assembly: ${o}.`};const r=ur.of(e);return r.isIdentity&&s.always!==!0?null:{assembly:r}}class fr{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 fr(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=ci(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=ci(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 ci(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 x2="weight",v2=65536;class k2{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=ze(i,a,this.storageMode),u=new Zs(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 Zs(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 Zs(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 Zs{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 Qc;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&&!S2(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>=v2&&this.handOn()}handOn(){this.emit(this.out.chunk()),this.out.reset(),this.held=0}}function S2(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 C2(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=$2(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 $2(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===x2){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 F2="AGFzbQEAAAABCAFgBH9/f38AAg8BA2VudgZtZW1vcnkCAAIDAgEABAUBcAEBAQYIAX8BQYCIBAsHCQEFZmxveWQAAAq5CQG2CQQJfwJ8FH8EewJAIAIgA04NACABQQFIDQACQCABQQdLDQAgAkEDdCEEIAFBA3QhBSABQQJGIQYgAUEERiEHIAFBBUYhCCABQQZGIQkDQCAAIAIgAWxBA3RqIQogACELIAEhDANAAkAgCyAEaisDACINRAAAAAAAAPB/YQ0AAkAgDSAKKwMAoCIOIAsrAwBjRQ0AIAsgDjkDAAsgAUEBRg0AAkAgDSAKKwMIoCIOIAtBCGoiDysDAGNFDQAgDyAOOQMACyAGDQACQCANIAorAxCgIg4gC0EQaiIPKwMAY0UNACAPIA45AwALIAFBA0YNAAJAIA0gCisDGKAiDiALQRhqIg8rAwBjRQ0AIA8gDjkDAAsgBw0AAkAgDSAKKwMgoCIOIAtBIGoiDysDAGNFDQAgDyAOOQMACyAIDQACQCANIAorAyigIg4gC0EoaiIPKwMAY0UNACAPIA45AwALIAkNACANIAorAzCgIg0gC0EwaiIPKwMAY0UNACAPIA05AwALIAsgBWohCyAMQX9qIgwNAAsgBEEIaiEEIAJBAWoiAiADRw0ADAILCyABIAFBDyABQQ9KGyIEQfj///8HcSILQQFyIgwgASAMShsiDCALayIFIAxBAXEiEGshESALIBByIAxrIRIgACABIARBeGoiC0F4cUEJaiIMIAEgDEobQQN0IgwgC0EDdEFAcSILa2ohEyAAIAIgAWxBA3QiBCAMaiALa2ohFCAAQcAAaiEVIAFBA3QhFkEAIRcgBUEGSSEYIAAgBGoiGUHAAGoiGiEbA0AgFCAWIBdsIgtqIRwgGiALaiEdIAAgAiABbEEDdGohHiAAIR8gFSEgQQAhIQNAAkAgACAhIAFsQQN0aiIIIAJBA3RqKwMAIg5EAAAAAAAA8H9hDQAgFiAhbCEiIA79FCEjQQghBEEAIQUgGyEKICAhD0EAIQwDQCAeIAxBA3QiC2oiDP0AADAhJCAM/QAAICElIAz9AAAQISYgCCALaiILIAv9AAAAICMgDP0AAAD98AH99gH9CwAAIAsgC/0AABAgIyAm/fAB/fYB/QsAECALIAv9AAAgICMgJf3wAf32Af0LACAgCyAL/QAAMCAjICT98AH99gH9CwAwIAoiB0HAAGohCiAPIgZBwABqIQ8gBSIJQQFqIQUgBCILIQwgC0EIaiIEIAFMDQALIAsgAU4NAAJAIBgNAAJAIAAgCUEGdCIMaiAiakHAAGogHCAMak8NACAdIAxqIBMgDGogImpJDQELIAsgEWohCyASIQwDQAJAICMgB/0AAwD98AEiJCAG/QADAP1JIiX9GwBBAXFFDQAgBiAk/SEAOQMACwJAICX9GwJBAXFFDQAgBkEIaiAk/SEBOQMACyAHQRBqIQcgBkEQaiEGIAxBAmoiDA0ACyAQRQ0BCyAZIAtBA3QiDGohBCAfIAxqIQwDQAJAIA4gBCsDAKAiDSAMKwMAY0UNACAMIA05AwALIARBCGohBCAMQQhqIQwgC0EBaiILIAFIDQALCyAfIBZqIR8gICAWaiEgICFBAWoiISABRw0ACyAZIBZqIRkgGyAWaiEbIBdBAWohFyACQQFqIgIgA0cNAAsLCwAwBG5hbWUACwpmbG95ZC53YXNtAQgBAAVmbG95ZAcSAQAPX19zdGFja19wb2ludGVyADgJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDFVidW50dSBjbGFuZxExOC4xLjMgKDF1YnVudHUxKQA1D3RhcmdldF9mZWF0dXJlcwMrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQrB3NpbWQxMjg=",dr=.2,js=3e3,E2=.05,B2=.995,T2=2e3,O2=10;function L2(e,t,n=dr,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=H2(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}=D2(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}R2(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=G2(c,h,i);return{kept:a,scn:c,boosted:d,rows:u,cols:l}}function _2(e,t,n=dr,s){const o=L2(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 D2(e,t,n=O2){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 R2(e,t,n,s="auto"){if(s!=="js"&&q2(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 Ce;const to=131072,P2=65536,li=64;function z2(){if(Ce!==void 0)return Ce;Ce=null;try{if(typeof WebAssembly>"u")return null;const e=atob(F2),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);WebAssembly.validate(t)&&(Ce=new WebAssembly.Module(t))}catch{Ce=null}return Ce}function q2(e,t,n){const s=z2();if(s===null)return!1;let o,r;try{const i=new WebAssembly.Memory({initial:Math.ceil((to+e.length*8)/P2)});o=new WebAssembly.Instance(s,{env:{memory:i}}).exports.floyd,r=new Float64Array(i.buffer,to,e.length)}catch{return!1}r.set(e);for(let i=0;i<t;i+=li){const a=Math.min(t,i+li);o(to,t,i,a)}return e.set(r),!0}function U2(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 ui(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 G2(e,t,n){const{window:s,sizes:o}=U2(n),r=ui(e,n,o),i=ui(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 H2(e,t=E2,n=B2,s=T2){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+=Q2((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 Q2(e){return .5*K2(-e/Math.SQRT2)}function K2(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 W2=9007199254740992;function hi(e,t){return e<<t|e>>>32-t}function fi(e){return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^e>>>16)>>>0}function Kc(...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=fi((t^o)+2654435769),t=fi((t^r)+2135587861)}return t}class Wc{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(hi(Math.imul(n,5),7),9)>>>0,i=n<<9;return s^=t,o^=n,n^=s,t^=o,s^=i,o=hi(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)/W2}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 Yc(e,t,n){if(!(t>0)||!(n>0))return 0;if(n>=1)return t;if(n<=.5)return n*t<=30?di(e,t,n):mi(e,t,n);const s=1-n;return t-(s*t<=30?di(e,t,s):mi(e,t,s))}function di(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 Fn(e){const t=e*e;return(13680-(462-(132-(99-140/t)/t)/t)/t)/e/166320}function mi(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 L=u+(A-a)/h;if(N=N*h+1-Math.abs(i-L+.5)/a,N>1)continue;I=Math.floor(L)}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 L=s/o,$=L*(t+1);let O=1;if(i<I)for(let _=i+1;_<=I;_++)O*=$/_-L;else if(i>I)for(let _=I+1;_<=i;_++)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,F=t+1-i,B=t-I+1,T=c*Math.log(C/k)+(t-i+.5)*Math.log(F/B)+(I-i)*Math.log(B*s/(k*o))+Fn(C)+Fn(F)+Fn(k)+Fn(B);if(!(S>T))return y(I)}}const Y2=(()=>{const e=new Float64Array(126);for(let t=2;t<126;t++)e[t]=e[t-1]+Math.log(t);return e})(),V2=.9189385332046728;function se(e){return e<126?Y2[e]:(e+.5)*Math.log(e)-e+(V2+1/e*(1/12-1/(360*e*e)))}function Vc(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?j2(e,t,n,s):X2(e,t,n,s)}function X2(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 J2=1.7155277699214135,Z2=.8989161620588988;function j2(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=J2*d+Z2,g=Math.floor((r+1)*(i+1)/(o+2)),p=se(g)+se(i-g)+se(r-g)+se(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=se(b)+se(i-b)+se(r-b)+se(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 th=1;function eh(e,t){return t===e?"none":t<e?"sub":"over"}const nh=81,Xc=91,Jc=14,sh=192*1024*1024,oh=4096,rh=32,ih=1e6;function Jt(e,t={}){return new E("unsupported",e,{...t,resample:!0})}function ah(e){return e>=0&&Number.isInteger(e)}class Xn{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 gi(e,t,n={}){const s=new Xn(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:ih,...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(!ah(I))return u=Jt(`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=Jt("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 ch(e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw Jt(`${e} is not a number of contacts: it must be a positive whole number.`,{contacts:e});if(e>Number.MAX_SAFE_INTEGER)throw Jt(`${e} contacts is past what can be counted exactly here (2⁵³).`,{contacts:e});return e}function lh(e,t,n,s){const o=ch(t.contacts),r=e.total;if(!(r>0))throw Jt("This map holds no contacts, so there is nothing to draw from it.",{total:r});const i=t.seed??th,a=t.alpha??dr,c=eh(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 Wc(Kc(i,nh,c==="sub"?Xc:Jc)),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=Vc(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 Jt(`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>js){const b=s?.[p]??`sequence ${p+1}`;throw Jt(`${b} is ${w.toLocaleString("en-US")} bins at this resolution, and Boost-HiC — which oversamples it — walks every path between them: at most ${js.toLocaleString("en-US")}. Open a coarser resolution to oversample this map.`,{sequence:b,bins:w,limit:js})}}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:Yc(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 pi{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 uh(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<=rh){f=0;for(let d=0;d<h;d++)s.nextDouble()*i<r-f&&f++,i--}else f=Vc(s,h,i-h,r),i-=h;r-=f,f>0&&o.push(a[l],c[l],f)}}function Zc(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:Yc(n,a,Math.min(1,u/r[c]));o[c]=l,a-=l}return o}function hh(e,t,n,s){const o=Zc(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 fh(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 dh(e,t,n,s,o,r,i){const a=fh(e,t,n),c=_2(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=Zc(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 mh{constructor(t,n,s,o){this.inner=t,this.geometry=n,this.spec=s,this.index=new Xn(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 Jt("This census was taken over another map.",{bins:t.nBins,nBins:this.geometry.starts[this.index.count]});const n=lh(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 Jt(`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=gh(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>oh)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 pt()}return!0}async draw(t,n,s){const o=this.geometry.starts,r=new Map;for(const l of t)r.set(l,new pi);const i=new Xn(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 pt()}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=ph(n),l=new Xn(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 pi(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 B=0;B<k.count.length;B++)N.push(k.bin1[B],k.bin2[B],k.count[B]);continue}const C=s.shares.get(t*a+M)??0,F=new Wc(Kc(s.seed,s.mode==="sub"?Xc:Jc,t,M));if(s.mode==="sub"){let B=0;for(let T=0;T<k.count.length;T++)B+=k.count[T];uh(k,C,B,F,N)}else M===t?dh(k,r,i-r,C,s.alpha,F,N):hh(k,C,F,N)}return wh(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<=sh)return;t.has(n)||(this.bands.delete(n),this.bytes-=s.bytes)}}}function gh(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 ph(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 wh(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 En{constructor(t,n,s,o,r){this.nBins=o,this.countKind=r,this.cells=s.map(i=>({name:i,store:new Uc(t.at(us(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[V];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:[V]}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 pt(),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 pt(),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 pt()}}}function wi(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 E("cell-not-found",`This file has no ${s.length===1?"cell":"cells"} ${Et(s.slice(0,8))}. It carries ${e.length} ${e.length===1?"cell":"cells"}, starting ${Et(e.slice(0,3))}.`,{missing:s,available:e.length});const o=new Set(t);return e.filter(r=>o.has(r))}function gt(e,t){const n=el(e),s=nl(n,t);if(s===null)return n;throw new E("format",`The ${t.field} of this ${t.format} reads ${Po(e)}, ${s.reason}. `+qe,{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 bh(e,t){return nl(el(e),t)===null}function Es(e,t,n){const s={format:n.format,field:n.field,offset:e,length:t,size:n.size};if(!Ro(e)||!Ro(t))throw new E("format",`The ${n.field} of this ${n.format} points at ${Po(t)} bytes from byte ${Po(e)}, which is not a place in a file. ${qe}`,s);if(n.ceiling!==void 0&&t>n.ceiling)throw new E("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. ${qe}`,{...s,ceiling:n.ceiling});if(e+t>n.size)throw new E("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)}. ${qe}`,s)}const bi=65536,mr=2**29;async function gr(e,t){if(typeof DecompressionStream>"u")throw new E("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+=bi){if(a)return;const p=e.subarray(g,Math.min(g+bi,e.byteLength));await s.write(p)}a||await s.close()})(),[l,h]=await Promise.allSettled([c,u]);if(a)throw tl(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 E("format",`The ${t.field} of this ${t.format} does not inflate (${g.replace(/\.$/,"")}). ${qe}`,{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 jc(e,t){return Math.min(t.ceiling,Math.max(t.floor,Math.ceil(e*t.ratio)))}function tl(e,t,n){return new E("format",`The ${e.field} of this ${e.format} inflates to more than ${mt.bytes(t)}, past what any real one holds. ${qe}`,{format:e.format,field:e.field,maxBytes:t,compressed:n})}const qe="The file is truncated, corrupt, or not the format its first bytes claim.";function el(e){return typeof e=="number"?e:e>=BigInt(Number.MIN_SAFE_INTEGER)&&e<=BigInt(Number.MAX_SAFE_INTEGER)?Number(e):Number.NaN}function Ro(e){return Number.isSafeInteger(e)&&e>=0}function nl(e,t){if(!Ro(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 Po(e){return typeof e=="bigint"?e.toString():Number.isSafeInteger(e)?mt.int(e):String(e)}const Ai=[7,8,9],ut=".hic",sl=2**31-1,Ah=2**40;class qt extends RangeError{needed;constructor(t){super(`a read needs ${t} bytes of a shorter buffer`),this.name="Truncated",this.needed=t}}class Ye{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 qt(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 qt(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 yh=512*1024;function ol(e){return e.length>=4&&e[0]===72&&e[1]===73&&e[2]===67&&e[3]===0}function Nh(e){let t=Math.min(yh,e.size);for(;;){const n=e.readBytes(0,t);try{return Mh(n,e.size)}catch(s){if(!(s instanceof qt))throw s;if(t>=e.size)throw new E("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 Mh(e,t=e.byteLength){if(!ol(e))throw new E("format","This file does not begin with the `.hic` magic bytes.",{});const n=new Ye(e);n.position=4;const s=n.int32();if(!Ai.includes(s))throw new E("unsupported",`This is a version ${s} .hic file, and this reader accepts versions ${Ai.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=gt(n.int32(),{format:ut,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=gt(n.int32(),{format:ut,field:"chromosome count",ceiling:1e7,available:c(),bytesPerItem:1+(s>=9?8:4)});eo(h>0,"chromosome count");const f=[];for(let g=0;g<h;g++){const p=n.string(),w=gt(s>=9?n.int64():n.int32(),{format:ut,field:`length of chromosome ${p}`,ceiling:Ah});f.push({name:p,length:w})}const d=gt(n.int32(),{format:ut,field:"resolution count",ceiling:1e4,available:c(),bytesPerItem:4});eo(d>0,"resolution count");const m=[];for(let g=0;g<d;g++){const p=n.int32();eo(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 eo(e,t){if(!e)throw new E("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 zo(e,t,n,s){return`${e}/${t}/${n}/${s}`}function Ih(e,t){const{version:n,footerPosition:s}=t,o=n>=9?8:4;Es(s,o+4,{format:ut,field:"footer position",size:e.size});const r=e.size-s,i=new Ye(e.readBytes(s,o)),a=gt(n>=9?i.int64():i.int32(),{format:ut,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 vh(l,n,o,c)}catch(h){if(!(h instanceof qt))throw h;if(u>=r)throw new E("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 xh=13;function vh(e,t,n,s){const o=new Ye(e);o.position=n;const r=s?.fileSize??e.byteLength,i=s?.footerPosition??0,a=()=>r-(i+o.position),c=new Map,u=gt(o.int32(),{format:ut,field:"master index size",ceiling:1e8,available:a(),bytesPerItem:xh});let l=0;for(let d=0;d<u;d++){const m=o.string(),g=o.int64(),p=o.int32();if(s!==void 0&&(Es(g,p,{format:ut,field:`matrix record for ${m}`,size:s.fileSize}),l+=p,l>s.fileSize))throw new E("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})}yi(o,t,!1,a),yi(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(bh(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(zo(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 yi(e,t,n,s){if(s()<4)return;const o=t>=9?4:8,r=gt(e.int32(),{format:ut,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=gt(t>=9?e.int64():e.int32(),{format:ut,field:"expected-value vector length",ceiling:sl,available:s(),bytesPerItem:o});e.skip(a*o);const c=gt(e.int32(),{format:ut,field:"expected-value scale factor count",ceiling:1e7,available:s(),bytesPerItem:4+o});e.skip(c*(4+o))}if(e.remaining<0)throw new qt(e.position)}function kh(e,t,n){const s=`${n.type} normalisation vector of chromosome ${n.chromIdx}`,o=t>=9?8:4,r=t>=9?4:8;Es(n.position,n.nBytes,{format:ut,field:s,size:e.size});const i=e.readBytes(n.position,o);if(i.byteLength<o)throw new E("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 Ye(i),c=gt(t>=9?a.int64():a.int32(),{format:ut,field:`length of the ${s}`,ceiling:sl,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 Ni={ratio:64,floor:16<<20,ceiling:1<<30},qo=2**26,Sh=37,Mi=16,Jn=2**31-1,no=4096;function Bs(e,t,n,s){const o=new Ye(e),r=()=>s===void 0?void 0:s-o.position;o.int32(),o.int32();const i=gt(o.int32(),{format:ut,field:"resolution count of a matrix record",ceiling:1e4,available:r(),bytesPerItem:Sh});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=gt(o.int32(),{format:ut,field:"block count of a matrix record",ceiling:Jn,available:r(),bytesPerItem:Mi});if(c!==t||l!==n){o.skip(d*Mi);continue}if(!(h>=1)||!(f>=1))throw new E("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 Ch(e,t,n,s,o){if(o>0&&o<t.size){try{return{zoom:Bs(e(t.position,o),n,s,t.size),beyondHead:!1}}catch(r){if(!(r instanceof qt))throw r}return{zoom:Ge(e(t.position,t.size),t,n,s),beyondHead:!0}}return{zoom:Ge(e(t.position,t.size),t,n,s),beyondHead:!1}}async function $h(e,t,n,s,o){if(o>0&&o<t.size){try{return{zoom:Bs(await e(t.position,o),n,s,t.size),beyondHead:!1}}catch(r){if(!(r instanceof qt))throw r}return{zoom:Ge(await e(t.position,t.size),t,n,s),beyondHead:!0}}return{zoom:Ge(await e(t.position,t.size),t,n,s),beyondHead:!1}}function Ge(e,t,n,s){try{return Bs(e,n,s,t.size)}catch(o){throw o instanceof qt?new E("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 Bn(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 Ii(e,t,n,s,o){const r=n&&t>=9?Bh(e,s,o):Eh(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(Fh,e.blocks.size))return Th(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 Fh=1<<20;function Eh(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 Bh(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 Th(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 Oh(e,t){try{return Lh(e,t)}catch(n){throw n instanceof qt?new E("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 Lh(e,t){const n=new Ye(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 E("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=gt(s,{format:ut,field:"record count of a block",ceiling:qo,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=gt(c?n.int16():n.int32(),{format:ut,field:"row count of a block",ceiling:Jn,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=gt(a?n.int16():n.int32(),{format:ut,field:"column count of a block row",ceiling:Jn,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]=xi(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=gt(n.int32(),{format:ut,field:"cell count of a dense block",ceiling:Jn,available:n.remaining-2,bytesPerItem:l}),y=n.int16();if(b>0&&!(y>=1))throw new E("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]=xi(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 xi(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>qo)throw new E("format",`A block of this .hic holds more than ${qo.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 Uo=48<<20,vi=4,_h=6,Dh=64<<20,ki=28,Tn=65536,On=16<<20,Rh=4096,Ph=Uo/2,zh=1024,Si=["SCALE","KR","INTER_KR","GW_KR","VC_SQRT","VC"],he="BP";class Ci{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 pr{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 Ci(a===vi?_h:a),this.backgroundSlots=new Ci(a),this.normType=Si.find(c=>r.some((u,l)=>s.normVectors.has(zo(c,this.fileIndex[l],he,o))))??null}static open(t,n={}){const s=Nh(t),o=Ih(t,s),r=[...s.bpResolutions].sort((a,c)=>a-c);if(r.length===0)throw new E("unsupported","This .hic carries no base-pair resolutions. Fragment-resolution matrices are variable-bin and are excluded from this viewer.",{});const i=n.binSize??fu(r);if(!r.includes(i))throw new E("unsupported",`This .hic has no ${i} bp resolution. It offers ${r.join(", ")}.`,{binSize:i,available:r});return new pr(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,...Si.filter(r=>r!==s)];for(const r of o){const i=this.footer.normVectors.get(zo(r,this.fileIndex[t],he,this.binSize));if(i===void 0)continue;const a=kh(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=Ch((r,i)=>this.source.readBytes(r,i),n,he,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 E("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=$h((r,i)=>this.exactRead(r,i),s,he,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*ki);return Math.max(1,Math.min(vi,Math.floor(Dh/n)))}walkPlans(t){const n=[];let s=[],o=0;for(const r of t){const i=this.binsOf(r[0])*this.binsOf(r[1])*ki;s.length>0&&(o+i>Ph||s.length>=zh)&&(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(Rh,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(Bn(r,Tn,On),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?Ge(g,p,he,this.binSize):Bs(g,he,this.binSize,p.size);this.zooms.set(p.key,this.fitted(p.key,w))}catch(w){if(!(w instanceof qt))throw w;this.beyondHead=!0,a.push({position:p.position,size:p.size,entry:p})}}})||a.length>0&&!await this.fetchRuns(Bn(a,Tn,On),n,(f,d)=>{for(const m of f.refs){const g=m.position-f.position,p=Ge(d.subarray(g,g+m.size),m.entry,he,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 Ii(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(Bn(u,Tn,On),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=Ii(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 Bn(r,Tn,On)){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){Es(t.position,t.size,{format:ut,field:`block ${t.number} of the ${this.binSize} bp matrix`,size:this.source.size,ceiling:Ni.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 gr(n,{format:ut,field:`block ${t.number} of the ${this.binSize} bp matrix`,encoding:"deflate",maxBytes:jc(n.byteLength,Ni)}),o=Oh(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>Uo)){this.blockCache.set(t,n),this.blockCacheBytes+=s;for(const o of this.blockCache.keys()){if(this.blockCacheBytes<=Uo)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 $i(e){throw new E("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 qh(e,t){const n=()=>We(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 E("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/"))&&$i(o),new E("unsupported",`A .hic has no ${o}.`,{path:o})},readInt32(o){throw o.startsWith("pixels/")&&$i(o),new E("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 E("unsupported",`A .hic has no ${o}.`,{path:o})},readTable(o){if(o==="chroms"||o==="contigs")return n();throw new E("unsupported",`A .hic has no /${o} table.`,{path:o})},at(o){throw new E("unsupported",`A .hic has no /${o} group to open.`,{path:o})},close:()=>t.close()}}function Uh(e,t){return e*1e6+t}class Gh{constructor(t){this.file=t}nnz=null;countKind="f";rectangular=!0;scoreColumns(){return["count"]}binOffsets(){throw new E("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=Uh(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?.()??pt()),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 E("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 wr=4<<20,br=12,Hh=65536;function rl(e){return e.length>=2&&e[0]===31&&e[1]===139}function il(e,t=0){return e.length<t+br||e[t]!==31||e[t+1]!==139||e[t+2]!==8||(e[t+3]&4)===0?!1:Ar(e,t)!==null}function Ar(e,t=0){if(e.length<t+br)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 al(e){return e.length===0?e:gr(e,{format:"BGZF file",field:"member",encoding:"deflate-raw",maxBytes:Hh})}function Qh(e,t,n){return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t+n-4,!0)}function Kh(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 yr(e,t={}){const n=e.readBytes(0,Math.min(e.size,64));return il(n)?Yh(e,t):rl(n)?Fi(e,t,Wh).pipeThrough(new DecompressionStream("gzip")):Fi(e,t,wr)}const Wh=65536;function Fi(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(wr,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 Yh(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>=br?Ar(a):null;if(h!==null&&a.length>=h){const d=Kh(a,0,h),m=Qh(a,0,h);if(a=a.subarray(h),c=m===0,m>0){l.enqueue(await al(d));return}continue}if(r>=s){u(l);return}const f=e.readBytes(r,Math.min(wr,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 Nr(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>so))throw new E("format",`A line of this .pairs file runs past ${so>>20} MiB without ending, and no pairs line is that long. The file is corrupt, or is not a .pairs file.`,{maxLineBytes:so})}return r>0&&t(i(new Uint8Array(0))),!0}finally{s.releaseLock()}}const so=64<<20,Vh=["readID","chr1","pos1","chr2","pos2","strand1","strand2"],Ln={chrom1:["chr1","chrom1","chromosome1"],pos1:["pos1","position1"],chrom2:["chr2","chrom2","chromosome2"],pos2:["pos2","position2"]},Ei={strand1:["strand1","strand_1"],strand2:["strand2","strand_2"]},Xh=["pair_type","pairtype"],Jh=64<<20,Zh=64,jh=65536;function cl(e){return/^##\s*pairs\s+format/i.test(e)}async function tf(e){let t=null;try{await Nr(yr(e,{to:ef(e)}),n=>{t??=new TextDecoder().decode(n)},()=>t!==null)}catch{}return t!==null&&cl(t)}function ef(e){const t=e.readBytes(0,Math.min(e.size,Zh));if(il(t)){const n=Ar(t);if(n!==null)return Math.min(e.size,n)}return Math.min(e.size,jh)}async function Ts(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=yr(e,{to:Math.min(e.size,Jh)});if(await Nr(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&&cl(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&&Bi(t,n,b[0],Number(b[1]))}else if(p==="samheader"){const b=/^@SQ\s.*\bSN:(\S+).*\bLN:(\d+)/.exec(w);b!==null&&Bi(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 E("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 E("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:nf(c??Vh,c!==null),text:s.join(`
2
+ `)}}function Bi(e,t,n,s){t.has(n)||!Number.isFinite(s)||s<=0||(t.add(n),e.push({name:n,length:s}))}function nf(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(Ln.chrom1),pos1:s(Ln.pos1),chrom2:s(Ln.chrom2),pos2:s(Ln.pos2),strand1:s(Ei.strand1),strand2:s(Ei.strand2),pairType:s(Xh)},r=["chrom1","pos1","chrom2","pos2"].filter(i=>o[i]<0);if(r.length>0)throw new E("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 ll(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 ul(e,t){let n=0;for(const s of e)n+=Math.ceil(s.length/t);return n}function Ti(e){throw new E("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 sf(e){const{header:t,pixels:n}=e,s=()=>We(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":of(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 E("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/"))&&Ti(r),new E("unsupported",`An imported .pairs map has no ${r}.`,{path:r}))},readInt32(r){throw r.startsWith("pixels/")&&Ti(r),new E("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 E("unsupported",`An imported .pairs map has no ${r}.`,{path:r})},readTable(r){if(r==="chroms"||r==="contigs")return s();throw new E("unsupported",`An imported .pairs map has no /${r} table.`,{path:r})},at(r){throw new E("unsupported",`An imported .pairs has no /${r} group to open.`,{path:r})},close:()=>{}}}function of(e){const t=/v?(\d+)(?:\.(\d+))?/.exec(e);return t===null?null:Number(t[1])}const Oi=1<<20;class rf{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??Oi)),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 pt()}}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]+qc?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??Oi)),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 pt()}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 E("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 en(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 af(e,t){const{bins:n,pixels:s}=t,o=()=>We(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]=en(n.nBins+1,a,c);return s.binOffset.slice(u,l)}if(i==="chroms/length"){const[u,l]=en(n.names.length,a,c);return n.lengths.slice(u,l)}if(i==="pixels/count"){const[u,l]=en(s.nnz,a,c);return Float64Array.from(s.count.subarray(u,l))}throw i==="bins/weight"?new E("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 E("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readInt32(i,a=0,c){const[u,l]=en(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 E("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readStrings(i,a=0,c){if(i==="chroms/name"){const[u,l]=en(n.names.length,a,c);return n.names.slice(u,l)}throw new E("unsupported",`A HiC-Pro matrix has no ${i}.`,{path:i})},readTable(i){if(i==="chroms"||i==="contigs")return o();throw new E("unsupported",`A HiC-Pro matrix has no /${i} table.`,{path:i})},at(i){throw new E("unsupported",`A HiC-Pro matrix has no /${i} group.`,{path:i})},close:()=>{}}}const cf={K:1e3,KB:1e3,M:1e6,MB:1e6,G:1e9,GB:1e9};function Pt(e,t={}){throw new E("bad-range",e,t)}function Li(e){const t=e.replace(/,/g,"").split(/([0-9.]+)/);(t.length!==3||t[0]!=="")&&Pt(`Unexpected token "${e}"`,{token:e});const[,n,s]=t;if(s.length===0)return/^[0-9]+$/.test(n)||Pt(`Unexpected token "${e}"`,{token:e}),Number(n);const o=Number.parseFloat(n);Number.isFinite(o)||Pt(`Unexpected token "${e}"`,{token:e});const r=s.toUpperCase().trim(),i=cf[r];return i===void 0&&Pt(`Unknown unit '${r}'`,{unit:r}),Math.trunc(o*i)}function lf(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 Mr(e){const t=[];let n="";for(let s=0;s<e.length;s++){const o=e[s];if(o===","&&!uf(e,s)){t.push(n),n="";continue}n+=o}return t.push(n),t.map(s=>s.trim()).filter(s=>s!=="")}function uf(e,t){return/[0-9]$/.test(e.slice(0,t))&&/^[0-9]{3}(?![0-9])/.test(e.slice(t+1))}function Os(e,t={}){const n=e.split(":"),s=n[0].trim();if(s.length===0&&Pt("Chromosome name cannot be empty",{region:e}),n.length<2)return[s,null,null];const o=lf(n[1]);let r=0;const i=()=>o[r++],a=(h,f)=>(h===void 0&&Pt(`Expected ${f.join(" or ")} token missing`,{region:e}),f.includes(h.kind)||Pt(`Unexpected token "${h.text}"`,{region:e}),h),c=Li(a(i(),["COORD"]).text);a(i(),["HYPHEN"]);const u=i();if(u===void 0)return[s,c,null];const l=Li(a(u,["COORD"]).text);return l<c&&t.reversed!==!0&&Pt("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 hf(e,t){const[n,s,o]=Os(e),r=t.get(n);if(r===void 0)throw new E("unknown-label",`Unknown sequence label: ${n}`,{label:n});const i=s===null?0:s,a=o===null?r:o;return a<i&&Pt("End cannot be less than start",{region:e,start:i,end:a}),(i<0||a>r)&&Pt(`Genomic region out of bounds: [${i}, ${a})`,{region:e,start:i,end:a,length:r}),[n,i,a]}function ff(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===un)throw new E("unbinned-not-displayable",`Range ${Z(t)}: ${Z(un)} 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 E("genome-coordinate-suffix",`Range ${Z(t)}: ${Z(o)} is a genome name — coordinate suffixes are not allowed for genome ranges. Use just ${Z(o)}.`,{label:o,region:t});return{kind:"genome",label:o,extent:e.genomeExtent(o)}}if(i.includes(o))return{kind:"contig",label:o,extent:_i(e,o,t)};const a=(e.names??df(e)).find(o,{from:n});if(a!==null){const c=t.slice(o.length);return{kind:"contig",label:a.name,extent:_i(e,a.name,`${a.name}${c}`),matched:a}}throw e.genomes===null?new E("unknown-label",`Range ${Z(t)}: ${Z(o)} is not a sequence of this file.
3
+ Sequences: ${Re(i)}`,{label:o,region:t}):new E("unknown-label",`Range ${Z(t)}: ${Z(o)} is not a known genome or contig.
4
+ Genomes: ${Re(e.displayGenomes().map(c=>r[c]))}
5
+ Contigs: ${Re(i)}`,{label:o,region:t})}function _i(e,t,n,s){return e.extent(n)}function df(e){const t=e.contigs.strings("name"),n=e.contigs.numbers("length");return ie.of(t.map((s,o)=>({name:s,length:n[o]})))}function mf(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 gf=["name","length","n_contigs","n_bins"],pf=["name","length"],oo=["name","length","genome_id"],wf=["name","length","n_contigs","n_bins"],bf=["bin-size","bin-type","storage-mode"],ro=["nnz","sum"];class ht{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??=ie.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:Af(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(),ol(n.readBytes(0,4)))return ht.fromHic(t,n);if(await tf(n)){const i=await Ts(n);throw new E("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(rl(n.readBytes(0,2)))throw new E("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(!xf(n))throw new E("not-hdf5",`${Rt(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 yu(t,n,Rt(t).group);try{return s.listingAgreed!==!0&&Mf(r,n),ht.fromHandle(r,s)}catch(i){if(r.close(),!(i instanceof E)&&i instanceof Error){const a=Rt(t).group;throw new E("format",`${Rt(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}=Rt(t),o=/^\/resolutions\/(\d+)$/.exec(s),r=pr.open(n,o===null?{}:{binSize:Number(o[1])});if(!r.hasAnyMatrix())throw new E("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=qh(t,r),a=i.attrs();return new ht({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 Gh(r)})}static fromPairs(t){const n=sf({uri:t.uri,header:t.header,pixels:t.pixels,rungs:t.rungs,indexed:t.indexed,declaredRecords:t.declaredRecords??null});return new ht({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 rf(t.pixels)})}static fromScool(t,n,s,o){const r=wi(n.entries??[],o),i=t.at(us(n,(n.entries??[])[0])),a=Ec(t,n,s).attrs,c={...s};for(const f of bf)c[f]===void 0&&a[f]!==void 0&&(c[f]=a[f]);const u=i.readNumeric("indexes/chrom_offset"),l=ri(i.dtype("pixels/count")),h=Number(u[u.length-1]??0);return new ht({uri:t.uri,handle:t,tables:i,layout:n,attrs:c,contigs:i.readTable("chroms",void 0,void 0,oo),chromOffset:u,store:new En(t,n,r,h,l)})}static fromHicPro(t,n){if(!n.bins.fixed||n.bins.binsize===null)throw new E("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=af(t,n);return new ht({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=lu(t,s,o);if(gu(t,r,s,o),r.kind==="scool")return ht.fromScool(t,r,s,null);if(r.kind!=="metacool")return new ht({uri:t.uri,handle:t,layout:r,attrs:s,contigs:t.readTable("chroms",void 0,void 0,oo),chromOffset:t.readNumeric("indexes/chrom_offset")});if(!t.has("indexes/genome_offset"))throw new ot("indexes/genome_offset is missing");return new ht({uri:t.uri,handle:t,layout:r,attrs:s,genomes:t.readTable("genomes",void 0,void 0,wf),contigs:t.readTable("contigs",void 0,void 0,oo),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=wu(t.attrs),this.metadata=bu(t.attrs),this.storageMode=this.info["storage-mode"];const n=this.info["bin-size"];if(n===null||n<=0)throw new ot(`attrs['bin-size'] must be positive, got ${Z(n)}`,{"bin-size":n});this.binsize=n,this.chromnames=this.contigs.strings("name"),this.genomeNames=this.genomes===null?[]:this.genomes.strings("name");const s=yf(this.contigs,"length");this.contigGenomeIds=this.genomes===null?new Int32Array(0):Nf(this.contigs,"genome_id"),this.coords=new Eu(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=ri(this.tables.dtype("pixels/count")),this.pixelStore=t.store??new Uc(this.rawHandle,this.nBins,this.countKind),this.validateLight()}get hasGenomes(){return this.genomes!==null}get hasWeights(){return this.handle.has(`bins/${Yt}`)}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 E("unknown-label",`Genome ${Z(t)} not found. Available: ${Re(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 E("unknown-label",`Contig ${Z(t)} not found. Available: ${Re(this.chromnames)}`,{label:t});return n}extent(t){const[n,s,o]=hf(t,this.chromsizes);return mf(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 E("bad-ordering",`Genome ${Z(this.genomeNames[t])} is not contiguous in bin space under contig-ordering ${Z(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]!==un&&t.push(n);return t}displayBinExtent(){const t=[0,this.nBins],n=this.genomeIds.get(un);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(un);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=Js.range){return Xu(this,t,n)}async genomeMatrix(t){const n=this.genomeExtent(t);return this.matrix({rows:n},Js.binSelection)}async genomePairMatrix(t,n){return this.matrix({rows:this.genomeExtent(t),cols:this.genomeExtent(n)},Js.binSelection)}async aggregateSparse(t,n,s={}){const o=_n(t.rows,this.nBins),r=_n(t.cols??t.rows,this.nBins),i=ze(o,r,this.storageMode),a=Cu(o,r,this.coords,this.contigGenomeIds,n,i.mode,this.storageMode==="symmetric-upper",Oe),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]*Dn(c,o,r,h)*Dn(c,o,r,f);a.place(h,f,d)}},Ri(s,t.value)),{...a.finish(),contigsPerCell:a.perCell}}async pooledMatrix(t,n,s={}){const o=_n(t.rows,this.nBins),r=_n(t.cols??t.rows,this.nBins),i=ze(o,r,this.storageMode),a=o[0]===r[0]&&o[1]===r[1],c=this.contigGenomeIds,u=ni(this.coords,o[0],o[1],n,Oe,c),l=a?u:ni(this.coords,r[0],r[1],n,Oe,c),h=_o(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]*Dn(f,o,r,g)*Dn(f,o,r,p);h.place(g,p,w)}},Ri(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=ku(this.nBins,t,n,s.cellCap===void 0?Oe:s.cellCap,o),i=[0,this.nBins],a=_o(i,i,r,r,ze(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=I2(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=hr.of(t.coords,t.chromnames,o.assembly),i=M2(r),a={...t.rawHandle.attrs(),nchroms:r.names.length,nbins:r.nBins};return{map:new ht({uri:t.uri,handle:N2(t.rawHandle,r,i,a),layout:t.layout,attrs:a,contigs:i,chromOffset:r.chromOffset,store:new y2(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=fr.of(t.chromOffset,n),{nnz:o,...r}=t.handle.attrs(),i={...r,"bin-size":t.binsize*n,nbins:s.nBins};return{map:new ht({uri:t.uri,handle:C2(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 k2(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 i2({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:l2({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=Di(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 E("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===Yt&&this.tables===this.rawHandle?this.handle.readNumeric(o,r,i):Di(this.tables.dtype(o))===!0?this.tables.readStrings(o,r,i):this.tables.readNumeric(o,r,i)}weightSlices(t,n){const s=`bins/${Yt}`;if(!this.handle.has(s))throw new E("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:Yt});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 $u(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 En?this.pixelStore.names:[]}selectCells(t){if(this.layout.kind!=="scool")throw new E("unsupported",`${this.uri} is not a single-cell container, so it has no cells to choose.`,{layout:this.layout.kind});const n=wi(this.cells,t);this.pixelStore=new En(this.handle,this.layout,n,this.nBins,this.countKind)}async scanCells(t){if(!(this.pixelStore instanceof En))throw new E("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(us(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=>!ro.includes(a)&&a!=="metadata").sort();for(const a of[...ro,...i]){if(!r.has(a))continue;const c=n.map(l=>l[a]);if(!ro.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 We(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 ot(s,o)};this.nContigs===0&&t("/contigs table is empty");for(const s of pf)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 gf)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[${Z(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??=gi(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 mh(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??=gi(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 E("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 E("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 Af(e,t){const n=`bins/${Yt}`;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 yf(e,t){const n=e.data[t];return n instanceof Float64Array?n:Float64Array.from(e.numbers(t))}function Di(e){try{return"SOU".includes(Ic(e))}catch{return null}}function Nf(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 Ri(e,t){return t===void 0?e:{...e,value:t}}function _n(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 Dn(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 Mf(e,t){if(!t.isRemote||!au(e,e.attrs()))return;const{path:n}=Rt(e.uri);throw new E("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 If=[137,72,68,70,13,10,26,10];function xf(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&&If.every((s,o)=>n[o]===s))return!0}return!1}const vf="0.17.0",kf="faa252c";function Zn(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(Zn);if(ArrayBuffer.isView(e))return Array.from(e);if(e instanceof Map){const n={};for(const[s,o]of e)n[String(s)]=Zn(o);return n}const t={};for(const[n,s]of Object.entries(e))t[n]=Zn(s);return t}default:return String(e)}}function Sf(e){return e instanceof E?{name:e.name,code:e.code,message:e.message,detail:Zn(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,Cf=64<<20;let Pi=0;class Zt{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,$f(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-${io()}`,this.readExact=(r,i)=>this.readBlobExact(t,r,i);return}if(Ff(t)){this.existingPath=t.path,this.size=t.size,this.id=n.name??t.path;return}const s=Ef(t);this.bytes=s,this.size=s.byteLength,this.id=n.name??`bytes-${io()}`}static async fromPath(t,n={}){if(!mn())throw new E("bad-uri",`cannot open the filesystem path ${t} in a browser; pass the File object instead`,{path:t});const s=await Pe();let o;try{o=s.FS.stat(t).size}catch(r){throw new E("not-hdf5",`cannot stat ${t}: ${r instanceof Error?r.message:String(r)}`,{path:t})}return new Zt({path:t,size:o},{name:n.name??t,...n})}static async open(t,n={}){return typeof t=="string"?Zt.fromPath(t,n):new Zt(t,n)}async mount(){if(this.mountPath!==null)return this.mountPath;const t=await Pe();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 E("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<=Cf)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,Pe().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-${io()}-${t}`;if(!mn())return`/${n}`;const s=globalThis.process?.env;return`${(this.tempDir??s?.TMPDIR??s?.TMP??s?.TEMP??"/tmp").replace(/\/+$/,"")}/${n}`}}function io(){return Pi+=1,`${Date.now().toString(36)}${Pi.toString(36)}`}function $f(e){return typeof Blob<"u"&&e instanceof Blob}function Ff(e){return typeof e=="object"&&e!==null&&typeof e.path=="string"&&typeof e.size=="number"}function Ef(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}const Bf="/chromosomix-lazy",hn=new Map,zi=new WeakSet;let ao=0;function Tf(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 Of(e,t,n,s){const o=Tf(e,n,s);if(mn()){_f(e),ao+=1;const a=`${Bf}/${t}-${ao}`;return hn.set(a,{size:n,ino:79691776+ao,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 Lf(e,t){if(!hn.delete(t))try{e.FS.unlink(t)}catch{}}function qi(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 _f(e){const t=e.FS;if(zi.has(t))return;zi.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"?hn.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:hn.get(i.path);return a!==void 0&&i?.stream_ops===a.ops?qi(a):s(r)},t.stat=(r,i)=>{const a=typeof r=="string"?hn.get(r):void 0;return a===void 0?o(r,i):qi(a)}}const Df=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]),Rf=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ot=64,hl=32;function Bt(e,t){return e>>>t|e<<32-t}function jn(e){const t=new Uint32Array(Rf),n=new Uint32Array(64),s=e.length*8,o=new Uint8Array((Math.floor((e.length+8)/Ot)+1)*Ot);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+=Ot){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=Bt(b,7)^Bt(b,18)^b>>>3,N=Bt(y,17)^Bt(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=Bt(d,6)^Bt(d,11)^Bt(d,25),y=d&m^~d&g,A=p+b+y+Df[w]+n[w]>>>0,N=Bt(u,2)^Bt(u,13)^Bt(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(hl),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(Ot);n.set(e.length>Ot?jn(e):e);const s=new Uint8Array(Ot+t.length),o=new Uint8Array(Ot+hl);for(let r=0;r<Ot;r++)s[r]=n[r]^54,o[r]=n[r]^92;return s.set(t,Ot),o.set(jn(s),Ot),jn(o)}function Ui(e){let t="";for(const n of e)t+=n.toString(16).padStart(2,"0");return t}function pe(e){return new TextEncoder().encode(e)}const Pf="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",Gi="AWS4-HMAC-SHA256",fl="s3",dl="aws4_request";function zf(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 Go(e){return encodeURIComponent(e).replace(/[!'()*]/g,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`)}function qf(e){return e===""?"/":e.split("/").map(t=>Go(decodeURIComponent(t))).join("/")}function Uf(e){const t=[];return e.forEach((n,s)=>t.push([Go(s),Go(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 Rn=null;function Gf(e,t,n){const s=`${e}|${t}|${n}`;if(Rn!==null&&Rn.id===s)return Rn.key;const o=an(pe(`AWS4${e}`),pe(t)),r=an(o,pe(n)),i=an(r,pe(fl)),a=an(i,pe(dl));return Rn={id:s,key:a},a}function Hf(e){const t=new URL(e.url),n=e.now??new Date,s=zf(n),o=s.slice(0,8),r=e.payloadHash??Pf,{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(),qf(t.pathname),Uf(t.searchParams),c,u,r].join(`
7
+ `),h=`${o}/${i.region}/${fl}/${dl}`,f=[Gi,s,h,Ui(jn(pe(l)))].join(`
8
+ `),d=Ui(an(Gf(i.secretAccessKey,o,i.region),pe(f))),m={Authorization:`${Gi} 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 ye(e){const t={...e.headers};return e.credential===void 0?t:{...t,...Hf({method:(e.method??"GET").toUpperCase(),url:e.url,credential:e.credential})}}function Ir(e){const t=Qf(e);return t.has("x-amz-signature")||t.has("x-goog-signature")?!0:t.has("sig")&&t.has("sv")}function Qf(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 Kf=1<<20,Wf=64<<20,Yf=4<<20,Vf=16<<20,Xf=8;function Jf(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 be{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??Kf)),this.readAhead=s.readAhead??!0,this.onRead=s.onRead;const r=Math.trunc(s.maxCacheBytes??Wf);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=>ye({url:t,method:m,...n.headers===void 0?{}:{headers:n.headers},...n.credential===void 0?{}:{credential:n.credential}});if(typeof s!="function")throw new E("remote-cors","this runtime has no fetch(); remote files need one",{url:t});const r=nn(t),i={requests:0,bytes:0};let a=null;if(!Ir(t))try{i.requests+=1,a=await s(t,{method:"HEAD",headers:o("HEAD")})}catch(m){await Qi(t,r,m,s,i)}if(a&&!a.ok)throw new E("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=Ki(a);if(c!==null){const m=await Zf(t,s,o,i),g=Wi(m?.headers.get("content-range")??null)??Pn(m,"content-length");if(m!==null&&m.status===206&&Ki(m)===null&&g!==null)return new be(t,g,n,i);throw new E("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:Pn(a,"content-length")})}const u=Pn(a,"content-length"),l=u===0?null:u;if((a?.headers.get("accept-ranges")??"").toLowerCase().includes("bytes")&&l!==null)return new be(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 Qi(t,r,m,s,i),new Error("unreachable")}if(i.bytes+=Pn(f,"content-length")??1,f.status!==206)throw new E("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=Wi(f.headers.get("content-range"))??l;if(d===null)throw new E("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 be(t,d,n,i)}async mount(){if(this.mountPath!==null)return this.mountPath;if(this.syncFetch===null&&typeof XMLHttpRequest>"u")throw new E("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 Pe(),n=`remote-${Math.abs(t5(this.url)).toString(36)}`;return this.mountPath=Of(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,Pe().then(n=>Lf(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 E("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+=Hi(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>Xf&&this.recent.shift();const m=a*this.chunkSize,g=Math.min((l+1)*this.chunkSize,this.size)-1,p=this.fetchRange(m,g);r+=Hi(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(Yf/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(Vf/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??Jf)(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?{}:ye({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 E("bad-uri",`${nn(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 E("remote-no-ranges",`${nn(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=ml(o);if(i!==null&&i.end-i.start+1!==t.byteLength)throw new E("remote-compressed",`${nn(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??jf(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 E("remote-no-ranges",`${nn(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 Hi(e,t,n,s,o){const r=Math.min(n.length-s,o);if(r<=0)throw new E("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 Qi(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 E("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 E("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 nn(e){try{return new URL(e).host}catch{return e}}async function Zf(e,t,n,s){try{return s.requests+=1,await t(e,{method:"HEAD",headers:{...n("HEAD"),Range:"bytes=0-"}})}catch{return null}}function Ki(e){const t=(e?.headers.get("content-encoding")??"").trim().toLowerCase();return t===""||t==="identity"?null:t}function Pn(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 jf(e){return ml(e)?.start??null}function ml(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 Wi(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 t5(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return t}class jt{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 gl{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 e5=["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 s5=" · ",xr=12,Yi=65536;function o5(e){return e.length<xr||e[0]!==31||e[1]!==139||e[2]!==8||(e[3]&4)===0?!1:vr(e)!==null}function vr(e){if(e.length<xr)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 r5=al;async function pl(e,t=Number.POSITIVE_INFINITY,n=mr){const s=[];let o=0,r=0;for(;r+xr<=e.length;){const c=r,u=vr(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 r5(e.subarray(f,d));if(m.length>0){if(o+m.length>n)throw tl({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 i5={ratio:64,floor:mr,ceiling:2**34};async function a5(e,t=mr){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 o5(e)?pl(e,Number.POSITIVE_INFINITY,t):gr(e,{format:"file",field:"gzip stream",encoding:"gzip",maxBytes:t})}async function c5(e,t){if(e.kind==="local"){const r=f5(e.file);return r!==null?r:(pn(),h5(e.file,new Zt(e.file)))}if(e.reading==="whole"){const r=p5(e.url);return r!==null?r:g5(e.url,await Al(e.url,gn(e),t))}const n=e.reading??"",s=d5(e.url,n);if(s!==null)return s;const o=gn(e);try{return Vi(e.url,n,await be.open(e.url,{...o,...e.reading==="fine"?{chunkSize:bl,readAhead:!1,...t?.onRead===void 0?{}:{onRead:t.onRead.bind(t)}}:{}}))}catch(r){if(r instanceof E&&r.code==="remote-compressed")return Vi(e.url,n,await m5(e.url,r,o));if(r instanceof E)throw r;const i=ds(e.url);throw new E("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 Ho(e){if(e.kind==="local")return new Zt(e.file);const t=gn(e);return e.reading==="whole"?await Al(e.url,t):await be.open(e.url,{...t,...e.reading==="fine"?{chunkSize:bl,readAhead:!1}:{}})}async function l5(e){if(e.kind==="local")return e.index===void 0?null:new Zt(e.index);const t=`${u5(e.url)}.px2`;try{return await be.open(t,gn(e))}catch{return null}}function u5(e){const t=e.search(/[?#]/);return t<0?e:e.slice(0,t)}function gn(e){return{...e.credential===void 0?{}:{credential:e.credential},...e.headers===void 0?{}:{headers:e.headers}}}function wl(e){return e===void 0?{}:"accessKeyId"in e?{credential:e}:e}let we=null,Ue=null;function h5(e,t){return Ue={file:e,source:t},Ve(t)}function f5(e){return Ue===null||Ue.file!==e?null:Ve(Ue.source)}function Vi(e,t,n){return we={url:e,reading:t,source:n},Ve(n)}function Ve(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 d5(e,t){return we===null||we.url!==e||we.reading!==t?(pn(),null):Ve(we.source)}function pn(){we?.source.close(),we=null,Ue?.source.close(),Ue=null,re?.source.close(),re=null}const Xi=128<<20;async function m5(e,t,n={}){const s=t.detail.encodedLength,o=typeof s=="number"?s:null;if(o!==null&&o>Xi)throw new E("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:Xi});let r;try{const i=await fetch(e,{headers:ye({url:e,method:"GET",...wl(n)})});if(!i.ok)throw new Error(`${i.status} ${i.statusText}`);r=new Uint8Array(await i.arrayBuffer())}catch(i){throw new E("remote-compressed",`${t.message} Falling back to downloading it whole also failed: ${i instanceof Error?i.message:String(i)}`,t.detail)}return new Zt(r,{name:e})}const bl=16384,Ji=2*(1<<30);async function Al(e,t={},n){let s;try{const o=await fetch(e,{headers:ye({url:e,method:"GET",...wl(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>Ji)throw new E("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:Ji});s=await yl(o,n)}catch(o){throw o instanceof E||b5(o)?o:new E("remote-cors",`Could not download ${e} whole: ${o instanceof Error?o.message:String(o)}`,{url:e,host:ds(e)})}return new Zt(s,{name:e})}let re=null;function g5(e,t){return pn(),re={url:e,source:t},Ve(t)}function p5(e){return re===null?null:re.url!==e?(re.source.close(),re=null,null):Ve(re.source)}async function Zi(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:ye({url:e.url,method:"GET",...gn(e)})})}catch(o){throw new E("remote-cors",`Could not read ${e.url}: ${o instanceof Error?o.message:String(o)}. The host ${ds(e.url)} must allow this page to GET it.`,{url:e.url,host:ds(e.url)})}if(!s.ok)throw new E("remote-cors",`${e.url} answered ${s.status} ${s.statusText}.`,{url:e.url,status:s.status});n=await yl(s,t)}return a5(n,jc(n.length,i5))}function w5(){const e=new Error("cancelled");return e.name="AbortError",e}function b5(e){return e instanceof Error&&e.name==="AbortError"}async function yl(e,t){const n=Number(e.headers.get("Content-Length")??Number.NaN),s=Number.isFinite(n)&&n>0?n:0,o=A5(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(),w5()};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 ji(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 E("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 ji(a,t,c,[],0)}async function ji(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 A5(e){const t=(e.headers.get("Content-Encoding")??"").trim().toLowerCase();return t!==""&&t!=="identity"}function ds(e){try{return new URL(e).host}catch{return e}}function y5(e){return/\.matrix(\.gz)?$/i.test(e)}function ms(e){const t=e.replace(/\.matrix(\.gz)?$/i,"").replace(/_iced$/i,"");return[`${t}_abs.bed`,`${t}_abs.bed.gz`]}const fn=9,Ft=10,Nl=13,Ml=35,N5=43,Qo=45,M5=46,It=48,Te=57,I5=69,x5=101;function v5(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]===Ft||e[f]===Nl){f++;continue}if(e[f]===Ml||S5(e,f)){for(;f<h&&e[f]!==Ft;)f++;continue}const g=f;for(;f<h&&e[f]!==fn&&e[f]!==Ft;)f++;const p=l.decode(e.subarray(g,f));if(f<h&&e[f]===Ft)throw Fe(t,i+1,"a row with one column");f++;const w=co(e,f);if(f=w.at,e[f]!==fn)throw Fe(t,i+1,"a row with two columns");f++;const b=co(e,f);f=b.at;let y=null;if(e[f]===fn){f++;const N=co(e,f);if(f=N.at,!N.saw)throw new E("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]!==Ft;)f++;f++;const A=b.value-w.value;if(A<=0)throw Fe(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 Fe(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 Fe(t,0,"no rows at all");const d=Float64Array.from([...o.slice(1),i]);if(d.length!==n.length+1)throw Fe(t,i,`${n.length} sequences but ${d.length} offsets`);const m=k5(n.length,d,s,r);if(a!==null&&(a!==1||c!==i))throw new E("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 k5(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 S5(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 Fe(e,t,n){return new E("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 C5=()=>{},$5=()=>!1;async function F5(e,t,n,s={}){const o=e.length;let r=0;for(let k=0;k<o;k++)e[k]===Ft&&r++;if(o>0&&e[o-1]!==Ft&&r++,r===0)throw new E("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??C5,m=s.cancelled??$5;for(;f<o;){const k=B5(e,Math.min(o,f+E5));if(f=T5(e,f,k,t,n,i,a,c,u,l),await pt(),m())throw D5();d(l.out,r)}const g=l.out,{sawUpper:p,sawLower:w}=l,b=p&&w?"mixed":w?"lower":"upper",y=L5(a,g,t),{order:A,offsets:N}=_5(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=O5(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 E5=1<<23;function B5(e,t){let n=t;for(;n<e.length&&e[n]!==Ft;)n++;return Math.min(e.length,n+1)}function T5(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]===Ft||e[l]===Nl){l++;continue}if(e[l]===Ml){for(;l<n&&e[l]!==Ft;)l++;continue}f++;let g=0,p=!1;for(;l<n;){const x=e[l];if(x<It||x>Te)break;g=g*10+(x-It),p=!0,l++}if(!p||e[l]!==fn)throw lo(o,f,s);l++;let w=0,b=!1;for(;l<n;){const x=e[l];if(x<It||x>Te)break;w=w*10+(x-It),b=!0,l++}if(!b||e[l]!==fn)throw lo(o,f,s);l++;let y=0,A=!1,N=!1;for(e[l]===Qo&&(N=!0,l++);l<n;){const x=e[l];if(x<It||x>Te)break;y=y*10+(x-It),A=!0,l++}if(e[l]===M5){l++;let x=.1;for(;l<n;){const v=e[l];if(v<It||v>Te)break;y+=(v-It)*x,x/=10,A=!0,l++}}if(e[l]===x5||e[l]===I5){const x=l;l++;let v=1;e[l]===Qo?(v=-1,l++):e[l]===N5&&l++;let S=0,k=!1;for(;l<n;){const C=e[l];if(C<It||C>Te)break;S=S*10+(C-It),k=!0,l++}k?y*=10**(S*v):l=x}if(!A)throw lo(o,f,s);for(N&&(y=-y);l<n&&e[l]!==Ft;)l++;l++;const I=g-1,M=w-1;if(I<0||M<0||I>=s||M>=s)throw new E("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 O5(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 L5(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 _5(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 co(e,t){let n=0,s=!1,o=1;for(e[t]===Qo&&(o=-1,t++);t<e.length;){const r=e[t];if(r<It||r>Te)break;n=n*10+(r-It),s=!0,t++}return{value:n*o,at:t,saw:s}}function lo(e,t,n){return new E("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 D5(){const e=new Error("cancelled");return e.name="AbortError",e}const Ko=["+-","-+","--","++"],zn=[1,2,4,10,20,40],Il=.05,R5=8;function xl(e=R5){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 ta=33,uo=43,ho=45;function P5(e,t){return e===uo?t===ho?0:t===uo?3:-1:e===ho?t===uo?1:t===ho?2:-1:-1}const z5=1024;class q5{constructor(t,n){this.contigs=t,this.pairTypeColumn=n,this.edges=xl(),this.distFreq=Ko.map(()=>new Float64Array(this.edges.length)),this.nContigs=t.length,this.densePairs=t.length<=z5?new Float64Array(t.length*t.length):null}total=0;totalUnmapped=0;totalMapped=0;totalDups=0;cis=0;trans=0;cisAtLeast=new Float64Array(zn.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]===ta,p=a-i===1&&t[i]===ta;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=P5(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<zn.length;A++)b>=zn[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 Ko.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:zn.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 _e=["++","--","-+","+-"];function vl(e,t=Il){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 _e)h+=n(f)[l];o[l]=h/_e.length}let r=0,i=null;for(const l of _e){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 _e){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 U5(e,t){if(e===0)return 0;const n=(e-t)/e;return n===0?0:e/(G5(-Math.exp(-1/n)/n)+1/n)}function G5(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 H5(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=U5(e.totalMapped,e.totalDups);o.push(["summary/complexity_naive",e.totalMapped===0||r===0?t(0):{float:r}]);const i=vl(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:Il}]);for(const l of _e)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 _e){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 Ko)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 Q5(e){return"text"in e?e.text:"int"in e?String(e.int):K5(e.float)}function K5(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 W5=9,Y5=35,fo=1<<20;class V5{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=X5(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 X5(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 J5=1.05;function Z5(e){const t=[0,1];let n=1;for(;n<e;)n=Math.max(n+1,Math.round(n*J5)),t.push(n);return Float64Array.from(t)}function j5(e,t){return e===mo?t===mo?0:t===go?1:-1:e===go?t===mo?2:t===go?3:-1:-1}const mo=43,go=45;async function kr(e,t){const{binSize:n,contigs:s,columns:o}=t,r=t.oneBased??!0,i=ll(s,n),a=ul(s,n),c=new V5(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 q5(s,h>=0),m=t.onRecord;let g=0;for(const H of s)g=Math.max(g,H.length);const p=l?Z5(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 H=0;H<s.length;H++)y[H]=Math.max(0,Math.ceil(s[H].length/n)-1);const A=new Int32Array(a);let N=new Int32Array(Math.min(a,65536)),I=0,M=new Int32Array(fo),x=new Int32Array(fo),v=new Int32Array(fo),S=0,k=-1,C=0,F=0,B=0,T=0,L=0,$=!1,O=!1,_=-1;const P=new Set;let W=!1,j=!1;const D=new Uint8Array(s.length);let z=null;const R=t.maxPixelBytes===void 0?1/0:Math.floor(t.maxPixelBytes/12),U=()=>{if(I===0)return;const H=N.subarray(0,I);if(H.sort(),S+I>R)throw z=new E("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=qn(M),x=qn(x),v=qn(v);for(let X=0;X<I;X++){const et=H[X];M[S]=k,x[S]=et,v[S]=A[et],S++,A[et]=0}I=0},G=t.expectedRecords??0,Y=H=>{if(H.length===0||H[0]===Y5)return;let X=0,et=0,tt=-1,it=-1,ct=-1,wt=-1,bt=-1,Ht=-1,te=0,ee=0,ne=0,ke=0,Se=-1,Gs=-1;const Qr=H.length;for(let at=0;at<=Qr;at++)if(!(at!==Qr&&H[at]!==W5)){if(X===o.chrom1?(tt=c.lookup(H,et,at),te=et,ee=at):X===o.chrom2?(it=c.lookup(H,et,at),ne=et,ke=at):X===h?(Se=et,Gs=at):X===o.pos1?ct=ea(H,et,at):X===o.pos2?wt=ea(H,et,at):l&&X===o.strand1?bt=at>et?H[et]:-1:l&&X===o.strand2&&(Ht=at>et?H[et]:-1),X++,X>f)break;et=at+1}if(d.add(H,tt,te,ee,it,ne,ke,ct,wt,bt,Ht,Se,Gs),m!==void 0&&m(H,tt,te,ee,it,ne,ke,ct,wt,bt,Ht,Se,Gs),tt<0||it<0){B++;return}if(ct<0||wt<0){T++;return}if(w!==null&&p!==null&&tt===it){const at=j5(bt,Ht);if(at>=0){const p1=Math.abs(wt-ct);let vn=0,Hs=p.length-1;for(;vn+1<Hs;){const Qs=vn+Hs>>1;p[Qs]<=p1?vn=Qs:Hs=Qs}w[at][vn]++,b++}}let Qt=Q(ct),Kt=Q(wt);if(Qt>y[tt]&&(Qt=y[tt],L++),Kt>y[it]&&(Kt=y[it],L++),Qt+=i[tt],Kt+=i[it],Qt>Kt){const at=Qt;Qt=Kt,Kt=at}tt===it&&(D[tt]=1);let Kr=!1;if(!O){const at=tt<=it?tt*u+it:it*u+tt;at!==_&&(Kr=!0,_>=0&&P.add(_),P.has(at)&&(O=!0,P.clear()),_=at)}Qt!==k&&(Qt<k&&($=!0,Kr||(O=!0)),U(),k=Qt),A[Kt]===0&&(I===N.length&&(N=qn(N)),N[I++]=Kt),A[Kt]++,C++,F++};function Q(H){const X=r?H-1:H;return X<0?0:Math.floor(X/n)}const K=t.spans??[{from:0,to:e.size}],nt=K.reduce((H,X)=>H+Math.max(0,X.to-X.from),0);let st=0;try{for(const H of K){const X={from:H.from,to:H.to,onProgress:tt=>{G>0?t.onProgress?.(C,G,"reading records"):t.onProgress?.(st+tt,nt,"reading records")}};t.cancelled!==void 0&&(X.cancelled=t.cancelled),t.spans===void 0&&(X.onFraming=tt=>{j=!0,(tt.partialMember||!tt.endedOnEofMarker)&&(W=!0)});const et=await Nr(yr(e,X),Y,t.cancelled);if(st+=Math.max(0,H.to-H.from),!et||t.cancelled?.()===!0)return null}U()}catch(H){throw z!==null?z:H}const Mt={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:F,skippedUnknownContig:B,skippedBadPosition:T,clampedPosition:L,wasUnsorted:O,truncated:j&&W,contigsWithoutCisContacts:s.filter((H,X)=>D[X]===0).map(H=>H.name),orientation:p===null||w===null?null:{edges:p,counts:w,total:b},stats:d.result(t.spans!==void 0)};return $?t3(Mt):Mt}function qn(e){const t=new Int32Array(e.length*2);return t.set(e),t}function ea(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 t3(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 kl=[1,2,5,10,20,50,100,200,500,1e3,2e3,5e3,1e4],e3=kl.length;function n3(e,t){const n=Math.max(1,Math.min(t,e3));return kl.slice(0,n).map(s=>e*s)}function s3(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 o3(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=ll(o,t),i=ul(o,t),a=s3(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=Un(f),d=Un(d),m=Un(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=Un(l)),l[h++]=x),u[x]+=e.count[I],w+=e.count[I]}n.onProgress?.(N,e.nnz,`aggregating to ${t} bp`),await pt()}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 Un(e){const t=new Int32Array(Math.max(1,e.length*2));return t.set(e),t}const r3=[{magic:"PX2.004",wideLinecount:!0},{magic:"PX2.003",wideLinecount:!1},{magic:"PX2.002",wideLinecount:!1}],na=[36,40,44];function i3(e){if(e.length<20)throw new E("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=r3.find(w=>w.magic===n);if(s===void 0)throw new E("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=a3(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 a3(e,t,n,s){const o=[];for(const r of na){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 E("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:na,sawNameBytes:o})}async function c3(e){const t=await e();if(t===null)return null;try{const n=t.readBytes(0,t.size);return i3(await pl(n))}finally{t.close()}}function l3(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:u3(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 u3(e,t){if(t>=e.size)return e.size;const n=e.readBytes(t,Math.min(Yi,e.size-t)),s=vr(n);return s===null?Math.min(e.size,t+Yi):Math.min(e.size,t+s)}async function h3(e,t){const n=await Ts(e);let s=null;try{s=await c3(t)}catch(r){if(!(r instanceof E))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 f3(e,t,n){const s=n3(n.base,n.rungs),o=n.maxPixelBytes??zc(),r=.85,i=(h,f)=>{n.onProgress?.(Math.round(h*1e3),1e3,f)},a=n.keys===void 0?void 0:d3(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 kr(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 o3(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 ${m3(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 d3(e,t,n){if(e.index===null)return;const s=l3(e.index,t,n);return s.length===0?void 0:s}function m3(e){return e>=1e6&&e%1e6===0?`${e/1e6} Mb`:e>=1e3&&e%1e3===0?`${e/1e3} kb`:`${e} bp`}async function Sl(e,t,n={}){const s=await y3(t);return s===null?await g3(e,t,n):await b3(e,t,s,n)}async function g3(e,t,n){const s=n.detached===!0?await Ho(t):await c5(t,{...n.report===void 0?{}:{onProgress:(r,i)=>n.report?.(r,i,"downloading")},...n.cancelled===void 0?{}:{cancelled:n.cancelled},...n.report===void 0||!sa(e)?{}:{onRead:(r,i)=>n.report?.(i,0,`listing cells · ${r.toLocaleString()} reads`)}}),o=t.kind==="remote"&&t.reading!==void 0;sa(e)&&n.report?.(0,0,"listing cells");try{return{mc:await ht.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 E)||r.code!=="pairs-binning-needed")throw r;return{mc:await p3(e,t,s,i,n),source:s}}}async function p3(e,t,n,s,o){const r=await h3(n,()=>l5(t)),i=await f3(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 w3();const a=i.tables.get(i.rungs[0]);if(a===void 0)throw new E("format",`${e} imported no pixel table.`);return ht.fromPairs({uri:e,header:i.header,pixels:a,rungs:i.rungs,indexed:i.indexed,declaredRecords:i.declaredRecords})}function w3(){const e=new Error("open cancelled");return e.name="AbortError",e}async function b3(e,t,n,s){const o=Wo(n),r=Wo(t),i=l=>({...s.report===void 0?{}:{onProgress:(h,f)=>s.report?.(h,f,l)},...s.cancelled===void 0?{}:{cancelled:s.cancelled}}),a=await Zi(n,i("reading the bins")),c=v5(a,o);await I3(t,r,c.nBins);const u=await Zi(t,i("downloading the matrix"));return A3(e,{bytes:u,name:r},c,o,a.length,s)}async function A3(e,t,n,s,o,r={}){const i=await F5(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:ht.fromHicPro(e,{bins:n,pixels:i,matrixName:t.name,binsName:s}),source:v3(t.name,o+t.bytes.length)}}async function y3(e){const t=Wo(e);if(!y5(t))return null;if(e.bins!==void 0)return e.bins;if(e.kind==="remote"){const n=await N3(e.url,e.credential,e.headers);if(n!==null)return n}throw new E("hicpro-no-bins",`${t} is a HiC-Pro matrix, which is half of a contact map: the bin file beside it — ${ms(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:ms(t)})}async function N3(e,t,n){if(Ir(e))return null;const s=e.lastIndexOf("/"),o=s<0?"":e.slice(0,s+1),r=e.slice(s+1),i=ms(r).map(c=>`${o}${c}`);if(o.includes("/iced/"))for(const c of ms(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:ye({url:c,method:"HEAD",...a})})).ok)return{kind:"remote",url:c,...a}}catch{}return null}function sa(e){return/\.scool(\.gz)?(\?|#|$)/i.test(e)}const M3=200<<20;async function I3(e,t,n){if(e.reading!==void 0)return;const s=await x3(e);if(s===null||s<=M3)return;const o=Math.round(s/15);throw new E("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 x3(e){if(e.kind==="local")return e.file.size;if(Ir(e.url))return null;try{const t=await fetch(e.url,{method:"HEAD",headers:ye({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 Wo(e){const t=e.kind==="local"?e.file.name:e.url;return t.split(/[\\/]/).pop()?.split(/[?#]/)[0]??t}function v3(e,t){return{id:e,size:t,isRemote:!1,mount:()=>Promise.resolve(e),readBytes(){throw new E("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 Sr=3;function Cl(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<Sr)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 $l(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<Sr)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 Cl(oa(o),oa(r))}function oa(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 k3(e,t){const n=Math.max(1,Math.trunc(t)),s=$3(e);if(s.length===0)return new Float64Array(0);const o=new Float64Array(n+1);for(let r=0;r<=n;r++)o[r]=F3(s,r/n);return o}const S3=16384;function C3(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<S3;)r*=s,o.push(r);return Float64Array.from(o)}function $3(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 F3(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 wn{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 Cr(e,t,n,s){const o=t>0?t:1,r=Number.isFinite(s)?s:0,i=Math.max(1,Math.ceil(r)),a=C3(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 Fl(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 $r(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 E3(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 B3(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 T3(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=E3(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=B3(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 O3="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=",L3="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",gs=512,ps=256,ft=64,ra=1e-9;async function _3(e,t,n,s={}){const o=e.m;if(o<=0)return;const{engine:r,rows:i}=Bl(e,s.engine??"wasm"),a=new Float64Array(o);for(let c=0;c<o;c+=ft){const u=Math.min(o,c+ft);if(n!==void 0)for(let l=c;l<u;l++){const h=n(l);h!==void 0&&await h}Tl(r,i,c,u,a,t)}}function El(e){return e+3&-4}function Bl(e,t="wasm"){const n=e.m,s=El(n),o=z3(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 Tl(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=ft*c;for(let d=l+1;d<i;d++){const m=h+d;o[d]=Ol(u[m],u[f+m],u[2*f+m],u[3*f+m],u[4*f+m],u[5*f+m])}}else D3(l,e.x,t,u,h,o);r(l,o)}}function D3(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 F=t[k+d[C]];M-=F,x-=F*F}S>v&&(A+=R3(d,g,p,v,S))}r[b]=Ol(s[o+b],A,N,M,I,x)}}function R3(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 Ol(e,t,n,s,o,r){if(!(t>=Sr))return Number.NaN;const i=o-n*n/t,a=r-s*s/t;if(!(i>ra*o)||!(a>ra*r))return Number.NaN;const c=(e-n*s/t)/Math.sqrt(i*a);return c>1?1:c<-1?-1:c}let Gn;function ia(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 P3(e){return Gn??={relaxed:ia(L3),simd:ia(O3)},e==="wasm"?Gn.relaxed??Gn.simd:Gn.simd}function z3(e,t,n){const s=e==="js"?null:P3(e);if(s!==null)try{return U3(s,t,n)}catch{}return G3(t,n)}const q3=65536;function U3(e,t,n){const s=n*t*4,o=Math.ceil(s/8)*8,r=6*ft*n,i=new WebAssembly.Memory({initial:Math.ceil((o+r*8)/q3)+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:ft*n);for(let g=0;g<t;g+=gs){const p=Math.min(t,g+gs);for(let w=f;w<n;w+=ps){const b=Math.min(n,w+ps);m?u(0,t,o,n,ft*n,f,f,d,w,b,g,p):c(0,0,t,o,n,f,f,d,w,b,g,p)}}}}}function G3(e,t){const n=new Float32Array(t*e),s=new Float64Array(6*ft*t);return{x:n,out:s,run(o,r,i){s.fill(0,0,i?s.length:ft*t);for(let a=0;a<e;a+=gs){const c=Math.min(e,a+gs);for(let u=o;u<t;u+=ps){const l=Math.min(t,u+ps);i?Q3(n,e,s,t,ft*t,o,o,r,u,l,a,c):H3(n,e,s,t,o,o,r,u,l,a,c)}}}}}function H3(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],F=e[A+v];N+=S*C,I+=S*F,M+=k*C,x+=k*F}n[g+w]+=N,b!==w&&(n[g+b]+=I),f!==h&&(n[p+w]+=M,b!==w&&(n[p+b]+=x))}}}function Q3(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 K3=384*1024*1024,W3=1024,aa=.9,Y3=6e4;let ts=null,V3=1;function X3(e,t){ts!==null&&Ll(ts),ts=t>0?{spawn:e,helpers:t,idle:[],release:null}:null}function J3(e){const t=e.idle.pop();if(t!==void 0)return t;try{return e.spawn()}catch{return null}}function Z3(e,t){t.onmessage=null,t.onerror=null,e.idle.push(t)}function Ll(e){e.release!==null&&clearTimeout(e.release),e.release=null;for(const t of e.idle.splice(0))t.terminate()}function j3(e){e.release!==null&&clearTimeout(e.release),e.release=null,e.idle.length!==0&&(e.release=setTimeout(()=>{e.release=null,Ll(e)},Y3),e.release.unref?.())}async function _l(e,t,n){const s=e.m,o=ts;if(o===null||s<W3)return _3(e,t,n);const r=t4(s,El(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:J3(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}=Bl(e);for(const f of i){const{worker:d,from:m,to:g}=f;for(let A=m;A<g;A+=ft)u(A);const p=()=>{f.failed=!0;for(let A=m;A<g;A+=ft)c.get(A)?.settle(null)};if(d===null){p();continue}const w=V3++,b=m+Math.floor((g-1-m)/ft)*ft;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=e4(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+=ft){const d=Math.min(s,f+ft),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}Tl(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?Z3(o,l):l.terminate());j3(o)}}function t4(e,t,n){for(let s=n+1;s>1;s--){const o=[0],r=aa+s-1;for(let a=1;a<s;a++){const c=(aa+a-1)/r,u=Math.round(e*(1-Math.sqrt(1-c))/ft)*ft;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<=K3)return o}return[0,e]}function e4(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 Dl(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 xn(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?xn(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?$r(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 s4(e,t,n){const s=new Float64Array(t*t);return await _l({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),Rl(s,t),s}function Rl(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 Fr=99.9;function o4(e,t,n=Fr){const s=zl(e,n),o=new Float64Array(t*t);for(let r=0;r<t*t;r++)o[r]=Pl(e[r],s);return o}function Pl(e,t){return Number.isFinite(e)?Math.min(Math.max(e,0),t)-1:0}function r4(e,t,n,s=Fr){const o=zl(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=Pl(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 zl(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 i4(e,t,n){const s=Dl(e,t),o=s.length,r=new Float32Array(t*t).fill(Number.NaN);return o<2?{values:r,kept:o,dropped:t-o}:(await _l({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),Rl(r,t),{values:r,kept:o,dropped:t-o})}function a4(e,t,n){const s=Cl(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 c4(e,t,n,s){const o=k3(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 l4(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 u4(){return new Worker(new URL(""+new URL("gram.worker-Cf7kBq9K.js",import.meta.url).href,import.meta.url),{type:"module"})}const ql=.001,Ul=20,h4=1e-12;function*Gl(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*bn(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(d4(c)<=r){b="gradient";break}h.set(c);const A=f.length;for(let C=A-1;C>=0;C--){const F=m[C]*xt(f[C],h);g[C]=F,la(h,d[C],-F)}if(A>0){const C=A-1,F=xt(f[C],d[C])/xt(d[C],d[C]);if(Number.isFinite(F)&&F>0)for(let B=0;B<i;B++)h[B]*=F}for(let C=0;C<A;C++){const F=m[C]*xt(d[C],h);la(h,f[C],g[C]-F)}for(let C=0;C<i;C++)h[C]=-h[C];let N=xt(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=-xt(c,c),!(N<0)){b="gradient";break}}const I=f.length===0?Math.min(1e10,1/Math.sqrt(xt(c,c))):1,M=yield*f4(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=xt(x,v);if(k>h4*Math.sqrt(xt(x,x)*xt(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*f4(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<Ul;p++){h(m);const w=yield*bn(n,s,a,c,u,o);if(g=m,!Number.isFinite(w)||w>o+ql*m*r||p>0&&w>=d)return yield*ca(e,t,n,s,o,r,f,d,m,a,c,u);const y=xt(s,t);if(Math.abs(y)<=-.9*r)return{ok:!0,step:m,value:w};if(y>=0)return yield*ca(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*bn(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*ca(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<Ul;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*bn(n,s,u,l,h,o);if(!Number.isFinite(b)||b>o+ql*w*r||b>=m){g=w;continue}const A=xt(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*bn(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*bn(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 xt(e,t){let n=0;for(let s=0;s<e.length;s++)n+=e[s]*t[s];return n}function la(e,t,n){for(let s=0;s<e.length;s++)e[s]+=n*t[s]}function d4(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 Hl=2220446049250313e-31,po={tolerance:1e12*Hl,gradient:1e-5,iterations:1e4},ua={tolerance:10*Hl,gradient:1},Ql=10,m4=3,g4=2/3;function p4(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*g4);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 w4(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<m4)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 ha(e,t){return Math.exp(e.c0+e.c1*Math.log(t))}function b4(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 A4(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 y4(e){const t=Yl(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 N4(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 Kl=0,Wl=0;const fa=7,M4=16,I4=1e9;function x4(e,t,n){let s=t,o=1,r=0;for(;s<fa;)o*=s,r+=1/s,s+=1;let i=e+t,a=1,c=0;for(;i<fa;)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;Kl=(i-.5)*l-(o===1&&a===1?e:i-s)+p-g+y+A,Wl=t*(l-.5*(f-h)-b+w-c+r)}function v4(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 k4=32,S4=64;function Yl(e){return Math.max(1,Math.min(S4,Math.round(e/k4)))}function da(e){const t=Yl(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 C4(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,F=0;for(let B=A+1;B<a;B++){const T=t[N+B];if(!(T>=0))continue;const L=I-r[B],$=M-r[a+B],O=x-r[2*a+B],_=L*L+$*$+O*O;if(!(_>0))return Number.POSITIVE_INFINITY;const P=-f*Math.log(_),W=d?1/(_*Math.sqrt(_)):Math.exp(P),j=(l===null?1:v*l[B])*W;let D;if(m){const Y=w*P-g,Q=Math.exp(Y),K=j/Q,nt=Q>.001?Math.log(1+Q):Math.log1p(Q);if(y+=(T+K)*nt,D=w*(j-T)/(1+Q)+p*K*nt,T>0){const st=S+(h===null?0:h[B])+P,Mt=st-Y;let H=0,X=1;if(T>1&&T<=M4&&T===Math.floor(T)&&K<I4){let et=1,tt=0,it=0;for(;it+4<=T;it+=4){const ct=K+it,wt=ct+1,bt=ct+2,Ht=ct+3,te=ct*wt,ee=bt*Ht,ne=te*ee;tt=tt*ne+((ct+wt)*ee+(bt+Ht)*te)*et,et*=ne}for(;it<T;it++){const ct=K+it;tt=tt*ct+et,et*=ct}H=Math.log(et)-T*Mt,X=K*tt/et}else T!==1&&(x4(T,K,Mt),H=Kl,X=Wl);y-=H+T*st,D-=p*X}}else y+=j,D=j-T,T>0&&(y-=T*(S+(h===null?0:h[B])+P));const z=-u*D/_,R=z*L,U=z*$,G=z*O;k+=R,C+=U,F+=G,i[B-s]-=R,i[b+B-s]-=U,i[2*b+B-s]-=G}i[A-s]+=k,i[b+A-s]+=C,i[2*b+A-s]+=F}return y}function $4(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 Vl(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 F4(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 E4(e,t,n={}){const s=Gl(Vl(t),{iterations:n.iterations??po.iterations,history:Ql,tolerance:po.tolerance,gradientTolerance:po.gradient});return Xl(s,e)}function B4(e,t,n={}){const s=Gl(Vl(t),{iterations:n.iterations??1e5,history:Ql,tolerance:ua.tolerance,gradientTolerance:ua.gradient});return Xl(s,e)}function*Xl(e,t){const n=yield*e;return{coords:F4(n.point,t),value:n.value,iterations:n.iterations,evaluations:n.evaluations,stop:n.stop}}const T4=512*1024*1024,O4=256,ma=.9;let Jl=null,L4=1;function _4(e,t){Jl=t>0?{spawn:e,helpers:Math.floor(t)}:null}function D4(e,t){const n=Jl,s=a=>ga(a)?0:a.BYTES_PER_ELEMENT,o=n===null||e<O4?0:pa(da(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"){sn(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(),sn(u)},r.push(u)}const i=(a,c)=>{const u=c.counts,l=ga(u),h=a==="mds",f=h?null:v4(c),d=h?y4(e):da(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=L4++;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]:pa(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=R4(y,a,c,d,I[v],I[v+1],l);S.worker.postMessage(k,l?[]:[k.values.buffer])}catch{sn(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?N4(u,null,e,d[v],d[v+1],S,w[v]):C4(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:B,from:T,to:L})=>!B.alive||!B.ready?Promise.resolve(null):new Promise($=>{B.owed={id:y,seq:A,resolve:$};const O=[];for(let P=T;P<L;P++)w[P].length===0&&(w[P]=new Float64Array(3*p(P))),O.push(w[P]);const _={kind:"evaluate",id:y,seq:A,point:v,parts:O};try{B.worker.postMessage(_,O.map(P=>P.buffer))}catch{sn(B)}}));for(let B=0;B<I[1];B++)x(B,v);const C=await Promise.all(k);M.forEach(({from:B,to:T},L)=>{const $=C[L];for(let O=B;O<T;O++){if($===null){x(O,v);continue}b[O]=$.values[O-B],w[O]=$.parts[O-B]}}),S.fill(0);let F=0;for(let B=0;B<m;B++){const T=b[B];if(!h&&!Number.isFinite(T))return Number.POSITIVE_INFINITY;F+=T,$4(S,w[B],e,g(B),p(B))}return h||Number.isFinite(F)?F: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)sn(a)}}}function sn(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 ga(e){return typeof SharedArrayBuffer=="function"&&e.buffer instanceof SharedArrayBuffer}function pa(e,t,n,s,o="likelihood"){const r=e.length-1;for(let i=Math.min(n+1,r);i>1;i--){const a=ma+i-1,c=[0];for(let l=1;l<i;l++){const h=Math.round(r*(ma+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+=Zl(o,e[c[l]],e[c[l+1]],t)*s;if(c.length>2&&u<=T4)return c}return[0,r]}function Zl(e,t,n,s){let o=0;for(let r=t;r<n;r++)o+=e==="mds"?r:s-1-r;return o}function R4(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)(Zl(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 P4(){return new Worker(new URL(""+new URL("likelihood.worker-CUgAXfAe.js",import.meta.url).href,import.meta.url),{type:"module"})}function Hn(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 z4=192,q4=16e6,wa=4e6,U4=.5;function fe(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 on(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 G4(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:Hn(e,a),over:s===void 0?null:Hn({...e,values:s},a)});if(o===0||r===0)return{values:i,over:s??null,applied:n,scope:null};if(o*r>q4)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(z4,Math.max(o,r)),p=v=>Number.isFinite(i[v])&&(s===void 0||Number.isFinite(s[v])),w=Math.max(1,Math.floor(wa/(r+1))-2*g);if(Math.min(o,w+2*g+1)*(r+1)>wa*2)return{values:Hn(e,a),applied:c,over:s===void 0?null:Hn({...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,F,B)=>{const T=$=>{const O=S-$<C?C:S-$,_=k-$<0?0:k-$,P=S+$>F?F:S+$,W=k+$>=r?r-1:k+$;return on(v,O,_,P,W)>=m};let L=B<a?a:B>g?g:B;if(T(L))for(;L>a&&T(L-1);)L--;else for(;L<g&&!T(L);)L++;return L},N=(v,S,k,C,F,B,T)=>{const L=k-F<B?B:k-F,$=C-F<0?0:C-F,O=k+F>T?T:k+F,_=C+F>=r?r-1:C+F,P=on(S,L,$,O,_);return P>0?on(v,L,$,O,_)/P:Number.NaN},I=new Float32Array(o*r);for(const[v,S,k,C]of y){const F=fe(k,C,r,$=>{const O=t[$];return Number.isFinite(O)&&O>0?O:0}),B=fe(k,C,r,$=>p($)?i[$]:0),T=fe(k,C,r,$=>p($)?1:0);let L=a;for(let $=v;$<=S;$++){const O=$*r;let _=L;for(let P=0;P<r;P++){const W=i[O+P];if(!p(O+P)){I[O+P]=W;continue}_=A(F,$,P,k,C,_),P===0&&(L=_);const j=$-_<k?k:$-_,D=P-_<0?0:P-_,z=$+_>C?C:$+_,R=P+_>=r?r-1:P+_,U=on(T,j,D,z,R)-1,G=U>0?(on(B,j,D,z,R)-W)/U:0;I[O+P]=G>0?Math.min(W,G*(1+U4*U)):W}}}const M=new Float32Array(o*r),x=s===void 0?null:new Float32Array(o*r);for(const[v,S,k,C]of y){const F=fe(k,C,r,O=>{const _=t[O];return Number.isFinite(_)&&_>0?_:0}),B=fe(k,C,r,O=>p(O)?I[O]:0),T=s===void 0?null:fe(k,C,r,O=>p(O)?s[O]:0),L=fe(k,C,r,O=>p(O)?1:0);let $=a;for(let O=v;O<=S;O++){const _=O*r;let P=$;for(let W=0;W<r;W++){const j=i[_+W];if(Number.isNaN(j)){M[_+W]=Number.NaN,x!==null&&(x[_+W]=Number.NaN);continue}P=A(F,O,W,k,C,P),W===0&&($=P);const D=P>>1<a?a:P>>1,z=P+(P>>1)>g?g:P+(P>>1);let R=0,U=0,G=0;for(const Y of[D,P,z]){const Q=N(B,L,O,W,Y,k,C);Number.isNaN(Q)||(R+=Q,U++,T!==null&&(G+=N(T,L,O,W,Y,k,C)))}M[_+W]=U>0?R/U:j,x!==null&&(x[_+W]=U>0?G/U:s?.[_+W]??Number.NaN)}}}return{values:M,over:x,applied:n,scope:null}}function H4(e){return`${e.contig}:${(e.start+1).toLocaleString("en-US")}-${e.end.toLocaleString("en-US")}`}function Er(e,t){return`${e}:${Q4(t)}`}function Q4(e){return(e+1).toLocaleString("en-US")}function jl(e){const t=K4(e);if(t===null)return e;const[n,s,o]=t;return s===null?e:o===null?`${n}:${(s+1).toLocaleString("en-US")}-`:H4({contig:n,start:s,end:o})}function K4(e){const t=e.indexOf(":");if(t<0)return[e,null,null];const n=e.slice(t+1).replace(/–|\.\./g,"-");try{return Os(`${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 rt(e,t,n){const s=e[t];return typeof s=="string"?s:n}function J(e,t,n){const s=e[t];return typeof s=="boolean"?s:n}function W4(e,t){const n=e[t];return Array.isArray(n)?n.filter(s=>typeof s=="string"):typeof n=="string"&&n!==""?[n]:[]}function Ut(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 ws(e,t){const n=e[t];return typeof n=="string"&&n!==""?n:null}function bs(e,t,n){return{value:e?.[n],chosen:ws(t,n)!==null}}function t0(e,t){return e.value!==void 0?null:e.chosen?t.gone:t.unchosen}function Ie(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 Ls(e,t,n){const s=new Set,o=[];for(const r of t){const i=Ie(e,r,n);i<0?o.push(r):s.add(i)}return{ids:[...s].sort((r,i)=>r-i),missing:o}}function xe(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=>Ie(e.mc,o)===s)}function e0(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)&&Ie(e.mc,r)===o)return i}}function He(){const e=new Error("cancelled");return e.name="AbortError",e}class Qn{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 n0(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 s0(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 Y4(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 o0(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 ba(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 Yo(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 V4(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 X4(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 J4=2e3;function _s(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??J4)),o=s<=1?n:n.filter((i,a)=>a%s===0),r=Z4(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 Z4(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(Aa(i[u])),c.push(Aa(r[u])));return{x:Float64Array.from(a),y:Float64Array.from(c)}}function Aa(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 Br(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 j4(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 Qe=[{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 t6(e){return e.hasWeights}const r0={kind:"toggle",key:"balance",label:"use balancing weights",default:!1,derive:t6},wo=e5.filter(n5);function As(e){const t=e.at;return t==="start"||t==="end"?t:"centre"}function e6(e){const t=typeof e.window=="number"?e.window:21;return Math.max(1,Math.min(200,Math.round(t)))}function dt(e){return e.mode==="scaled"&&e.norm!=="chromosight"}function n6(e){return e.norm==="chromosight"}const Vo=2;function s6(e){const t=typeof e.minDiag=="number"?e.minDiag:Vo;return Number.isFinite(t)?Math.max(0,Math.round(t)):Vo}const i0=5;function o6(e){const t=e.minDist;return typeof t=="number"&&Number.isFinite(t)?Math.max(0,Math.round(t)):i0}function es(e){const t=typeof e.flankFraction=="number"?e.flankFraction:.5;return Math.max(0,Math.min(4,t))}function Tr(e){return dt(e)&&Xt(e)}function Xt(e){return e.anchors!=="pairs"&&e.anchors!=="allpairs"&&e.anchors!=="consecutive"}function r6(e){return!Xt(e)&&e.symmetric!==!1}function i6(e){const t=e.tracks;return Array.isArray(t)?t.length>0:typeof t=="string"&&t!==""}function bo(e){return e.anchors==="features"&&typeof e.rankBy=="string"&&e.rankBy!==""}function a0(e){return e.anchors==="pairs"}function ya(e){return e.anchors==="allpairs"}function c0(e){return e.anchors==="consecutive"}function a6(e){if(Xt(e))return 1;const t=typeof e.byDistance=="number"?Math.round(e.byDistance):0;return t>1?Math.min(l0,t):1}const l0=6,Na=2e5;Qe.map(e=>({value:e.name,label:e.name.replace(/_/g," "),hint:e.blurb}));const c6={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 u0(e){return(c6[e.name]??[]).map(n=>({size:n.size,values:Float64Array.from(n.values)}))}class h0{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 f0(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 d0(e,t){const n=e.length,s=Ma(e),o=new Float64Array(n);for(let c=0;c<n;c++)o[c]=Math.abs(e[c]-s);const r=Ma(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 Ma(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 l6(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 u6(e,t,n,s,o=10){const r=Math.min(s,Math.max(0,t-1)),i=l6(e,t,n,s),a=new h0(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 h6(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 Or(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 F=0;F<a;F++){const B=r-c+F,T=s.values[k*a+F];if(w+=T,b+=T*T,h6(C,B,t,n,i.maxDist,a)){p++,m+=T,g+=T*T;continue}const L=C>=0&&C<t&&B>=0&&B<t?e.at(C,B):0;h+=L,f+=L*L,d+=L*T}}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 f6(e,t){return new h0(e,0,Math.min(t,Math.max(0,e-1)))}function d6(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 b=0;b<n;b++)h[b+1]=h[b]+(s[b]===0?1:0);const f=(b,y)=>{const A=Math.max(0,b),N=Math.min(n,y);return N<=A?!1:h[N]-h[A]>0};let d=0,m=0;for(let b=0;b<l;b++)d+=o.values[b],m+=o.values[b]*o.values[b];const g=d/l,w=m/l-g*g;for(let b=Math.max(0,i);b<Math.min(n,a);b++){const y=b-u,A=b+u+1;for(let N=0;N<=e.hi;N++){const I=b+N;if(I>=n)break;const M=I-u,x=I+u+1;if(!(y>=0&&A<=n&&M>=0&&x<=n&&M>A-2&&!f(y,A)&&!f(M,x))){const $=Or(t,n,s,o,b,I,r);e.values[N*n+b]=$.corr;continue}let S=0,k=0,C=0;for(let $=0;$<c;$++){const O=y+$,_=Math.max(0,t.lo-(M-O)),P=Math.min(c,t.hi-(M-O)+1);if(P<=_)continue;let W=(M+_-O-t.lo)*n+O,j=$*c+_;for(let D=_;D<P;D++){const z=t.values[W];z!==0&&(S+=z,k+=z*z,C+=z*o.values[j]),W+=n,j++}}if(k===0)continue;const F=S/l,B=(k/l-F*F)*w,T=B>0?Math.sqrt(B):0;if(!(Math.abs(T)>=1e-10))continue;const L=(C/l-F*g)/T;e.values[N*n+b]=Math.min(1,Math.max(-1,L))}}}function m0(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*m6(-Math.abs(n*Math.sqrt(t-3)))}function m6(e){return .5*g6(-e/Math.SQRT2)}function g6(e){const t=Math.abs(e),n=t<2?1-p6(t):w6(t);return e>=0?n:2-n}function p6(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 w6(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 g0(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 b6(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 p0(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 w0(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 Lr(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 b0(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 A0(e,t){return u6(e.contacts,e.n,e.detectable,_r(e.n,t.maxDist,t.largestKernel))}function _r(e,t,n){return Math.min(t,e)+n}function A6(e,t,n,s,o){const{n:r,detectable:i}=e,a=[];let c=0;for(const u of b6(n,o.pearson)){const l=o.onDiagonal===!0?u.col:u.row,h=p0(t,r,i,s.size,l,u.col);if(h===null||!w0(h,o)){c++;continue}const f=Or(t,r,i,s,l,u.col,o);a.push({pattern:{bin1:l,bin2:u.col,score:n.at(l,u.col),pvalue:m0(n.at(l,u.col),f.present),kernel:0,iteration:0},values:h})}return{matrix:t,corr:n,found:a,rejected:c}}function y6(e,t,n,s,o){const{n:r,detectable:i}=e,a=[];for(const c of o){const u=p0(t,r,i,n.size,c.bin1,c.bin2),l=u!==null&&w0(u,s),h=l?Or(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:m0(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 N6(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 M6(e,t){const n=N6(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:g0(s.map(o=>o.pvalue))}}const I6=0,x6=2,y0={colormap:"seismic",centre:1,range:[I6,x6]},v6=16e6;function Ds(e,t){let s=Math.max(256,Math.min(e,4096));for(;s>1&&s*(s+t)>v6;)s=Math.floor(s/2);return Math.max(1,s)}function k6(e,t){const n=Ds(Math.max(0,t)*2,Math.max(0,t)*2);return Math.max(1,Math.ceil(Math.max(1,e)/n))}function Dr(e,t){return e.rowExtent[0]<=t.from&&e.rowExtent[1]>=t.to&&e.colExtent[0]<=t.from&&e.colExtent[1]>=t.to}function Nt(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(!Dr(s,o))return null;return s}function Rr(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 Pr(e,t,n){if(n.block!==null)return Rr(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 S6{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 ve(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 S6(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=Ds(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 C6(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&&Dr(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=Ds(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 N0(e,t,n,s){const o=t.to-t.from,r=Math.max(0,n.halo),i=Ds(r*2,r*2),a=k6(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 Pr(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 M0(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 Rs(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 Ne(e,t){return t===null?{ids:Rs(e),missing:[]}:Ls(e,t)}function le(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 Gt(e,t){if(!t)return null;const n=`bins/${Yt}`;if(!e.handle.has(n))throw new E("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:Yt});return e.handle.readNumeric(n,0,e.nBins)}function At(e){return F1(e)}function $6(e){const t=Math.round(e);return t===0?"0":`${t<0?"-":"+"}${At(Math.abs(t))}`}function An(e,t){if(!(e>0)||!(t>0))return[];const n=(e-1)/2*t;return[0,.25,.5,.75,1].map(s=>$6(-n+s*2*n))}function F6(e){const t=rt(e.params,"csPattern","loops");return Qe.find(n=>n.name===t)??Qe[0]}async function E6(e,t){const n=F6(e),s=u0(n)[0],o=J(e.params,"balance",!1),r=e.framing.value===""?V: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=Gt(e.mc,o);let d;if(f!==null)d=(v,S)=>f0(f,v,S);else{const v=await M0(e);d=(S,k)=>d0(v.subarray(S,k),5)}const m=[...h.values()].map(v=>v[0].bounds),g=Nt(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 F={contacts:await ve(e,S,{hi:_r(k,c,s.size),block:g,balance:o,value:r,onTile:async()=>{await e.breathe()}}),n:k,detectable:d(S.from,S.to)},B=A0(F,{maxDist:c,largestKernel:s.size}),T=y6(F,B,s,u,v.map(L=>({bin1:L.row-S.from,bin2:L.col-S.from})));for(let L=0;L<T.length;L++)p.push({anchor:v[L],score:T[L].pattern.score,pvalue:T[L].pattern.pvalue,qvalue:Number.NaN}),w.push(T[L].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=g0(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=Lr(w,N),M=n.onDiagonal?b0(I,N):I,x=[B6(M,N,{preset:n,n:A,binsize:i}),T6(p,n)];if(!n.onDiagonal){const v=_s(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(O6(p,i)),x}function B6(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:An(t,n.binsize),yTicks:An(t,n.binsize),...y0,stats:[{label:"windows",value:n.n,digits:0,hint:"Anchors that could be scored."},{label:"P2LL",value:Yo(e,t,t),digits:2,hint:"Centre against the lower-left corner. Above 1 is enrichment."}]}}function T6(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 O6(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 Ia=512,L6=async e=>{const t=a0(e.params),n=bs(e.inputs.pairs,e.params,"pairs"),s=bs(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(t0(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=J(e.params,"balance",!1),a=e.framing.value===""?V:e.framing.value,c=dt(e.params)?Math.max(11,Math.round(q(e.params,"grid",51))):e6(e.params)*2+1,u=rt(e.params,"norm","matched"),l=ya(e.params),h=c0(e.params),f=t?P6(e,o):l?j6(e,r):h?Z6(e,r):q6(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.`),n6(e.params))return E6(e,f.map(R=>({row:R.pair.row,col:R.pair.col,bounds:R.bounds,label:R.label})));const d=(t||h)&&!dt(e.params)?z6(e,f):f;if(d.length===0)return[];const m=a6(e.params),g=m>1?td(d,m):U6(e,d,Xt(e.params)?r:null),p=m>1?ed(g,R=>e.toBp(R)):null,w=Y4(c,es(e.params)),b=dt(e.params),y=Tr(e.params),A=[],N=Br(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 U of g[R]){const G=ka(e,U,c,w);if(G===null||(A.push({...G,label:U.label,separation:U.pair.separation,control:!1,group:R,bounds:U.bounds}),I===0))continue;const Y=b?Math.max(1,Q6(G.rect)):0,Q=b?Math.round(Y*v):M,K=b?Math.max(Q,Math.round(Y*S)):x;for(const nt of X4(U.pair,U.bounds,{perPair:I,minShift:Q,maxShift:K,rng:N})){const st=ka(e,H6(U,nt),c,w);st!==null&&A.push({...st,separation:nt.separation,control:!0,group:R,bounds:U.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"&&dt(e.params);k&&e.note("Observed / expected is not available in the scaled mode: every window contributes cells at a different separation to the same cell of the picture, so a pileup cell has no one diagonal offset to divide by. The raw pileup is shown — use the distance-matched control, which is drawn at the same separations by construction.");const C=g.map(()=>new Qn(c,c)),F=g.map(()=>new Qn(c,c)),B=_6(e),T=g.map(()=>B.map(()=>new Qn(1,c))),L=g.map(()=>B.map(()=>new Qn(1,c))),$=r6(e.params),O=[],_={minDiag:s6(e.params),mirrored:Xt(e.params)},P=Nt(e,A.map(W6),i),W=u==="oe"&&!k?await J6(e,A,{block:P,balance:i,value:a}):null,j=Y6(A);let D=0;for(const R of j){await e.breathe(),e.progress(D,A.length,`${D.toLocaleString()} of ${A.length.toLocaleString()} windows`);const U=await V6(e,R.rect,{block:P,balance:i,value:a});for(const G of R.plans){D++;const Y=X6(U,R.rect,G,c,w,{..._,expected:W?.get(G.bounds.from)});if(Y!==null){if(G.control){F[G.group].add(Y);continue}if(C[G.group].add(Y),B.length>0){const Q=D6(G,w);for(let K=0;K<B.length;K++){const nt=xa(B[K].values,G.rect.rowFrom,G.rect.rowTo,c,Q),st=xa(B[K].values,G.rect.colFrom,G.rect.colTo,c,Q);T[G.group][K].add(nt),L[G.group][K].add(st),$&&(T[G.group][K].add(st),L[G.group][K].add(nt))}}G.label!==void 0&&O.push({label:G.label,separation:G.separation*e.mc.binsize,score:y?ba(Y,w):Yo(Y,c,c)})}}}e.progress(A.length,A.length,"done"),e.throwIfCancelled();const z=[];for(let R=0;R<g.length;R++){const U=C[R].finish();if(U.n===0)continue;const G=p!==null?`APA · ${p[R]}`:g.length===1?"APA":`APA · group ${R+1}`;let Y=U.values,Q,K=`${G} · raw`;if(u==="matched"){const H=F[R].finish();H.n>0?(Y=V4(U.values,H.values),Q=1,K=`${G} · over distance-matched control`):e.note("No control window could be placed, so the raw pileup is shown.")}else W!==null&&(Q=1,K=`${G} · observed / expected`);const nt=Xt(e.params)?As(e.params)==="start"?"the feature’s start":As(e.params)==="end"?"the feature’s end":"the feature’s centre":"the centre",st=dt(e.params)?y?`Position along the feature (0 → 1), flanked by ${es(e.params)}×`:"Scaled position":`Distance from ${nt}`,Mt=dt(e.params)?y?K6(w,es(e.params)):[]:An(c,e.mc.binsize);z.push({kind:"matrix",id:`apa-${R}`,label:K,nrows:c,ncols:c,values:Y,xLabel:st,yLabel:st,xTicks:Mt,yTicks:Mt,colormap:Q===void 0?"default":Pc,...Q===void 0?{}:{centre:Q},...(()=>{const H=R6(B,T[R],L[R]);return H===void 0?{}:{margins:H}})(),stats:[{label:"windows",value:U.n,digits:0,hint:"Anchors that contributed."},y?{label:"in / out",value:ba(Y,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:Yo(Y,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=_s(O,{id:"apa-loop-spectrum",label:"Loop spectrum",noun:ya(e.params)?"pairs":"loops",yLabel:"P2LL — centre against the lower-left corner"});R!==null&&z.push(R)}O.sort((R,U)=>(Number.isNaN(U.score)?-1:U.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 _6(e){const t=W4(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 D6(e,t){if(e.body!==void 0)return o0(t,e.body.from-e.rect.rowFrom,e.body.to-e.rect.rowFrom,e.body.pad)}function xa(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?n0(i,1,r,1,s):s0(i,1,r,Float64Array.from([0,1]),o)}function R6(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 P6(e,t){const n=[],s=Me(t.contigs);for(let o=0;o<t.length;o++){const r=ys(e,t.contigs[t.contig1[o]],t.start1[o],t.end1[o],s),i=ys(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]===""?Er(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 z6(e,t){const n=o6(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 (${yn(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 I0(e,t,n){const s=e.start[t],o=e.end[t];if(n==="centre")return Math.round((s+o)/2);const r=Math.max(s,o-1),i=e.strand[t]<0;return n==="start"?i?r:s:i?s:r}function q6(e,t){const n=[],s=Me(t.contigs),o=As(e.params);for(let r=0;r<t.length;r++){const i=ys(e,t.contigs[t.contig[r]],t.start[r],t.end[r],s,{point:I0(t,r,o)});i!==null&&n.push({pair:{row:i.bin,col:i.bin,separation:0},bounds:i.bounds,label:t.name[r]===""?Er(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})}return n}function ys(e,t,n,s,o,r={}){const i=Ie(e.mc,t,o);if(i<0)return null;const[a,c]=e.mc.contigExtent(i),u=e.mc.coords.binIndex(i,r.point??Math.round((n+s)/2));if(u<a||u>=c)return null;const l=va(e.mc.coords.binIndex(i,Math.max(0,Math.min(n,s))),a,c-1),h=va(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 va(e,t,n){return Math.min(n,Math.max(t,e))}function U6(e,t,n){const s=ws(e.params,"rankBy"),o=rt(e.params,"subset","all");if(s===null||o==="all"||n===null)return[t];const i=[...s==="score"?t:G6(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 G6(e,t,n){return e.map((s,o)=>{for(const r of(t.detail[o]??"").split(s5)){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 ka(e,t,n,s){const{from:o,to:r}=t.bounds;if(dt(e.params)){if(t.span<=0)return null;const c=s.flank===0?0:t.span*es(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:Tr(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 H6(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 Q6(e){return Math.max(e.rowTo-e.rowFrom,e.colTo-e.colFrom)}function K6(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 W6(e){return{from:Math.min(e.rect.rowFrom,e.rect.colFrom),to:Math.max(e.rect.rowTo,e.rect.colTo)}}function Y6(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<=Ia&&r.colTo-r.colFrom<=Ia){o.rect=r,o.plans.push(s);continue}}n.push({rect:{...s.rect},plans:[s]})}return n}async function V6(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 X6(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.body===void 0)return n0(h,a,c,s,s);const g=o0(o,n.body.from-i.rowFrom,n.body.to-i.rowFrom,n.body.pad);return s0(h,a,c,g,g)}async function J6(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 C6(e,a,{hi:c,block:n.block,balance:n.balance,value:n.value,onTile:async()=>{await e.breathe(),e.throwIfCancelled()}})),r++;return o}function x0(e,t){const n=Me(t.contigs),s=[],o=As(e.params);for(let r=0;r<t.length;r++){const i=I0(t,r,o),a=ys(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]===""?Er(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 Z6(e,t){const n=x0(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 j6(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 ${yn(n*e.mc.binsize)} to ${yn(s*e.mc.binsize)} at this file’s ${e.mc.binsize.toLocaleString()} bp resolution.`);const o=Br(Math.round(q(e.params,"seed",1))),r=x0(e,t),i=[];let a=0;const c=u=>{if(a++,i.length<Na){i.push(u);return}const l=Math.floor(o()*a);l<Na&&(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 td(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 ed(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`${yn(t(Math.max(0,s)))}–${yn(t(o))}`})}function yn(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 v0{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 Ps(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 nd=23e3,sd=2e6,od=12e6,rd=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=rt(e.params,"cells","all")!=="selected",s=t.activeCells;n&&t.selectCells(null);try{return await id(e,s)}finally{n&&t.selectCells(s)}};async function id(e,t){const n=e.mc,s=n.activeCells,o=J(e.params,"balance",!1),r=Gt(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=Ps(i,n.nBins),u=Math.max(0,q(e.params,"nearFrom",nd)),l=Math.max(u+1,q(e.params,"nearTo",sd)),h=Math.max(l+1,q(e.params,"mitoticTo",od));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],F=c[v];if(C<0||F<0)continue;if(C!==F){I.trans+=k;continue}I.cis+=k;const B=Math.abs(v-x)*n.binsize;B<u?I.short+=k:B<l?I.near+=k:B<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:`< ${Tt(u)}`,kind:"number",digits:3,hint:"Self-ligation and unligated ends, mostly."},{key:"near",label:`${Tt(u)}–${Tt(l)}`,kind:"number",digits:3,hint:"The near band. High in G1, low just after mitosis."},{key:"mitotic",label:`${Tt(l)}–${Tt(h)}`,kind:"number",digits:3,hint:"The mitotic band. The condensed chromosome’s signature."},{key:"far",label:`> ${Tt(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 ${Tt(u)}–${Tt(l)} (near)`,yLabel:`Contacts ${Tt(l)}–${Tt(h)} (mitotic)`,xScale:"linear",yScale:"linear"}),w}function Tt(e){return e>=1e6?`${Number((e/1e6).toFixed(1))} Mb`:e>=1e3?`${Number((e/1e3).toFixed(1))} kb`:`${Math.round(e)} bp`}const ad=96e6;function cd(e,t,n){return(Math.min(t,e)+n+1)*e}function ld(e){const t=typeof e.pattern=="string"?e.pattern:"";return Qe.find(n=>n.name===t)??Qe[0]}function Ao(e,t,n){if(e.thresholds!=="custom")return n;const s=e[t];return typeof s=="number"&&Number.isFinite(s)?s:n}function me(e){return e.thresholds==="custom"}function Sa(e,t){return e===0?0:Math.max(1,Math.round(e/(t>0?t:1)))}function yo(e,t,n,s){if(!me(e))return Sa(n,s);const o=e[t];return typeof o=="number"&&Number.isFinite(o)?Math.max(0,Math.round(o)):Sa(n,s)}Qe.map(e=>({value:e.name,label:e.name.replace(/_/g," "),hint:e.blurb}));const Ca=64,ud=200,hd=async e=>{const t=ld(e.params),n=J(e.params,"balance",!1),s=e.framing.value===""?V:e.framing.value,o=e.mc.binsize,r=yo(e.params,"maxDist",t.maxDist,o),i=yo(e.params,"minDist",t.minDist,o),a=yo(e.params,"minSeparation",t.minSeparation,o),c={maxDist:Math.max(r,1),pearson:Ao(e.params,"pearson",t.pearson),missingTol:Ao(e.params,"maxPercUndetected",t.maxPercUndetected)/100,zeroTol:Ao(e.params,"maxPercZero",t.maxPercZero)/100,onDiagonal:r===0},u=r===0;e.note(`A ${c.maxDist.toLocaleString()}-diagonal scan band reaches ${At(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=u0(t),f=h.reduce((M,x)=>Math.max(M,x.size),0),{units:d,skipped:m}=fd(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: ${dd(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=Gt(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=Nt(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)=>f0(g,M,x);else{const M=q(e.params,"nMads",5),x=await M0(e);N=(v,S)=>d0(x.subarray(v,S),M)}for(const M of d){await e.breathe();const x=M.span.to-M.span.from,v=_r(x,c.maxDist,f),k={contacts:await ve(e,M.span,{hi:v,block:p,balance:n,value:s,onTile:async(F,B)=>{await e.breathe(),e.progress(A,y,B===1?`${M.name} · reading`:`${M.name} · reading ${F+1} of ${B}`)}}),n:x,detectable:N(M.span.from,M.span.to)},C=A0(k,{maxDist:c.maxDist,largestKernel:f});for(let F=0;F<h.length;F++){let B=h[F];for(let T=0;T<l&&(e.progress(A,y,`${M.name}${h.length>1?` · template ${F+1}`:""}${l>1?` · pass ${T+1}`:""}`),!(x<=B.size));T++){const L=f6(x,c.maxDist);for(let O=0;O<x;O+=Ca)await e.breathe(),d6(L,C,x,k.detectable,B,c,O,O+Ca);const $=A6(k,C,L,B,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:F,iteration:T,values:O.values});if(A++,T+1<l){const O=Lr($.found.map(_=>_.values),B.size);if($.found.length===0||O.some(_=>!Number.isFinite(_))){e.note(`Refinement stopped after pass ${T+1} on ${M.name}: the pileup of what it found has gaps in it, and a template with gaps cannot be correlated.`);break}B={size:B.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=md(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.`),gd(e,t,I,{onDiagonal:u,size:h[0].size,sequences:d.length}))};function fd(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 Rs(s)){const l=s.chromnames[u];if(i!==null&&!i.has(l))continue;const h=zt(s,u);if(h!==null){if(cd(h.to-h.from,t,n)>ad){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 dd(e){const t=e.slice(0,6).join(", ");return e.length>6?`${t} and ${e.length-6} more`:t}function md(e,t,n){const{kept:s,qvalues:o}=M6(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 gd(e,t,n,s){const o=e.mc.binsize,r=t.name.replace(/_/g," "),i=[];i.push(s.onDiagonal?wd(n,r,o):pd(n,r,o));const a=Lr(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?b0(a,s.size):a),xLabel:"Distance from the centre",yLabel:"Distance from the centre",xTicks:An(s.size,o),yTicks:An(s.size,o),...y0,stats:[{label:"patterns",value:n.length,digits:0,hint:"Calls that entered the pileup."},{label:"median score",value:yd(n.map(c=>c.score)),digits:3,hint:"Pearson correlation with the template."}]}),i.push(bd(n,t)),!s.onDiagonal){const c=_s(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(Ad(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 gl;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:k0(o)})}return{kind:"intervals",id:"chromosight-patterns",label:`Detected ${t}`,payload:{kind:"pairs",data:s.finish()},noun:{one:"pair",many:"pairs"},display:"overlay"}}function wd(e,t,n){const s=new jt;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:k0(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 k0(e){return`score ${e.score.toFixed(4)} · p ${$a(e.pvalue)} · q ${$a(e.qvalue)}${e.kernel>0?` · template ${e.kernel+1}`:""}`}function bd(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 Ad(e,t){const n=[...e].sort((s,o)=>o.score-s.score).slice(0,ud).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 yd(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 $a(e){return Number.isFinite(e)?e===0?"0":e<1e-4?e.toExponential(2):e.toFixed(6):"n/a"}const Nd=8e6;class Md{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<Nd?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 Id(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 Fa=512,xd=async e=>{const t=e.mc,n=J(e.params,"balance",!1),s=Gt(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=Ps(o,t.nBins),i=new Md(t.nContigs),a=Ut(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!==V&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${V}. 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=Ls(t,a),N=le(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},vd(h,rt(e.params,"bars","cis"))],d=rt(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=Id(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.`)),J(e.params,"matrix",!0))if(l.length>Fa)e.note(`${l.length.toLocaleString()} sequences is past the ${Fa.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},Ea="contacts";function vd(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:Ea}:{}},i={name:"trans",x:s,y:Float64Array.from(e,a=>n(a.trans,a.total)),mark:"bars",...o?{stack:Ea}:{}};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 zr(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 qr(e){let t=0;for(let n=0;n<e.length;n++)t=Math.max(t,Math.abs(e[n]));return t}function S0(e,t,n,s,o){const r=zr(s),i=t.length,a=n.length,c=qr(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 kd(e,t){const{n}=t,s=zr(t),o=qr(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 Ba(e,t,n){const{n:s,circular:o}=t,r=zr(t),i=Math.max(0,Math.round(n)),a=2*i+2,c=qr(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 Sd=.02,Cd=.2;function Ta(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*Sd)),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*Cd)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 $d(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=C0(e,t,o,r,a);if(c===null)break;i.push(c),$0(e,t,c)}return i}function C0(e,t,n,s,o){const r=Br(24301+o),i=new Float64Array(t);for(let p=0;p<t;p++)i[p]=r()*2-1;if(!Oa(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++){F0(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=Fd(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 Oa(m)?{value:d.value,vector:m}:null}function Fd(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 $0(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 F0(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 Oa(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 Ed(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);F0(o,t,r,l);for(let h=0;h<t;h++)i+=r[h]*l[h]}$0(o,t,{value:i,vector:r});const a=C0(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 Ns=8192,Bd=.1;function La(e,t){const{ids:n}=Ls(e.mc,t,Me(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 Td(e,t,n){const{spans:s,spanAt:o,n:r}=t,i=new Float32Array(r*r).fill(Number.NaN),a=Nt(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 Od(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 wn(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(xn(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 Ld(e,t){const n=new Int32Array(t.contigs.length);for(let s=0;s<t.contigs.length;s++){const o=t.contigs[s];if(!xe(e,e.mc.chromnames[o]))continue;const[r,i]=e.mc.contigExtent(o);n[s]=i-r}return n}function _d(e,t,n,s,o,r){const i=Int32Array.from({length:t},(h,f)=>f),a=S0(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(xn(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 Dd(e,t,n,s){const o=t.contigs[0],r=e.mc.chromnames[o],i=e0(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 Rd(e){const t=e.contacts;return t==="trans"||t==="both"?t:"cis"}async function Pd(e,t,n){const{label:s}=n,o=J(e.params,"balance",!0),r=e.framing.value===""?V:e.framing.value,i=await Td(e,t,{balance:o,value:r});e.throwIfCancelled();const a=Ld(e,t),c={...Od(i,t,a),contacts:n.contacts,ignoreDiags:n.ignoreDiags},u=Dl(i,t.n,Bd);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?_d(i,t.n,u,Dd(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=o4(l,u.length),m=0;for(let N=0;N<d.length;N++)m+=d[N]*d[N]}else d=await s4(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=$d(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):r4(l,u.length,g.map(N=>N.vector)),w=Gd(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=a4(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 = ${Da(S.r)})${S.flipped?", sign flipped":""}.`:`${s}: phasing against ${S.signal} was ambiguous (r = ${Da(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(Ud(e,n.segments,t,u,g[0].vector),!J(e.params,"saddle",!0))return{saddle:null};const y=Math.max(5,Math.min(100,Math.round(q(e.params,"quantiles",50)))),A=c4(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:Pc,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 zd=async e=>{const n=Ut(e.params,"sequences")??Rs(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=Ls(e.mc,n,Me(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=La(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=Rd(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=>La(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 jt,h=[],f=[],d=r==="cis"&&rt(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=rt(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 ${Fr}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=_a(e,b);if(b.n>Ns){const N=`${y} is ${b.n.toLocaleString()} bins, past the ${Ns.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 Pd(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=`${_a(e,o)} · ${qd[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},qd={cis:"cis",trans:"trans",both:"cis + trans"};function _a(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 Da(e){return Number.isFinite(e)?e.toFixed(3):"—"}function Ud(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 l4(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 Gd(e,t,n){const s=bs(e.inputs.features,e.params,"phaseFeatures").value;if(s!==void 0)return{name:"gene density",values:Hd(e,s,t,n)};const o=ws(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(ws(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 Hd(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 Qd(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 Kd(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 Wd(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 Yd(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=Vd(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 Vd(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 Xd(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-No(e,l,c):Number.NaN,d=h>=0?u-No(e,c,h):Number.NaN;r.push(Jd(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:No(e,0,t))}return{positions:o,prominences:r}}function No(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 Jd(e,t){return Number.isNaN(e)?t:Number.isNaN(t)?e:Math.min(e,t)}function Zd(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}=Xd(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 jd(a,n.spacing)}function jd(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 t8(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=e8(e,r),c=n8(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(Ra(e,r,-1),Ra(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 E0(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 Ra(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 e8(e,t){for(let n=t-1;n>=0;n--)if(Number.isFinite(e[n]))return n;return-1}function n8(e,t){for(let n=t+1;n<e.length;n++)if(Number.isFinite(e[n]))return n;return-1}function s8(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 o8(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 r8(e,t){const n=e.length,s=t8(o8(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 i8=50;function a8(e){const t=typeof e.window=="number"?e.window:i8;return Math.max(1,Math.round(t))}function c8(e,t){const n=e.mc,s=n.chromsizes,{ids:o,missing:r}=Ne(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:xe(e,u)})}return{units:i,missing:r}}const l8=async e=>{const t=J(e.params,"balance",!1),n=e.framing.value===""?V: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=a8(e.params),i=r*e.mc.binsize,a=J(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 ${At(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=Ut(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}=c8(e,l),d=le(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=Nt(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 ve(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=s8(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:r8(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 · ${At(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(u8(e,y)),e.note(`${I.toLocaleString()} borders called across ${y.length.toLocaleString()} sequences.`),J(e.params,"domains",!0)){const M=h8(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 u8(e,t){const n=new jt;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 h8(e,t){const n=new jt;let s=0;for(const{unit:o,borders:r}of t)for(const i of E0(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 B0(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 f8(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=B0(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 d8=3;function T0(e){const t=typeof e.diagonals=="number"?e.diagonals:d8;return Math.max(1,Math.round(t))}function m8(e){return T0(e)-1}function g8(e,t){const n=e.mc,{ids:s,missing:o}=Ne(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:xe(e,c)})}return{units:r,missing:o}}const p8=async e=>{const t=J(e.params,"balance",!1),n=e.framing.value===""?V: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=T0(e.params),i=m8(e.params),a=i*e.mc.binsize,c=B0(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"} ${At(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=Ut(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}=g8(e,l),d=le(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=Nt(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 ve(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=f8(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"}]},w8=50,Ms=new Float64Array(1),Ct=new Uint32Array(Ms.buffer),O0=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Pa=134217729;function b8(e,t){Ms[0]=e;const n=O0?0:1,s=1-n;return t?(Ct[n]=Ct[n]+1>>>0,Ct[n]===0&&(Ct[s]=Ct[s]+1>>>0)):(Ct[n]===0&&(Ct[s]=Ct[s]-1>>>0),Ct[n]=Ct[n]-1>>>0),Ms[0]}function A8(e){return Ms[0]=e,(Ct[O0?0:1]&1)===1}function Is(e,t,n){const s=e*t;if(!Number.isFinite(s)||!Number.isFinite(n))return s+n;let o=Pa*e;const r=o-(o-e),i=e-r;o=Pa*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&&!A8(d)&&(d=b8(d,g>0==d>0)),l+d}function Mo(e,t,n,s){return Is(t,s,e*n)}function y8(e,t,n,s,o){return o===1?Is(t,s,e*n):Is(e,n,t*s)}function L0(e,t,n,s){return Is(t,s,e*n)}function Xo(e,t){return e*e+t*t}class Nn{n=0;ls0=0;ls1=0;ss=0;c0=0;c1=0;sqNorm=0;child=null;static of(t,n){const s=new Nn;return s.n=1,s.ls0=t,s.ls1=n,s.c0=t,s.c1=n,s.ss=s.sqNorm=Mo(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=Mo(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=Mo(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 dn{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=y8(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]=_0(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 _0(e,t,n){const s=new Nn,o=new Nn,r=new dn(t,n,e.leaf),i=new dn(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]=Xo(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*L0(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 N8(e,t,n=w8){const s=e.length/2;let o=new dn(t,n,!0);const r=new dn(t,n,!0);r.next=o,o.prev=r;for(let f=0;f<s;f++){const d=Nn.of(e[2*f],e[2*f+1]);if(o.insert(d)){const[m,g]=_0(o,t,n);o=new dn(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]=Xo(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=Xo(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*L0(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 Ur=["donut","vertical","horizontal","lowleft"];function D0(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 M8(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 I8(e,t){const{w:n}=e,s=2*n+1,o=M8(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 za=40,qa=50,x8=[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],Io=[[-.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 R0(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,v8(Math.floor(e),t)))}function v8(e,t){return e<0||t<0?Number.NaN:t===0?0:s9(Math.floor(e)+1,t)}const Ke=11102230246251565e-32,P0=.9189385332046728,k8=2556348e299,S8=1.4142135623730951,C8=.7071067811865476,$8=500,Gr=2e3,z0=1,F8=0,E8=20,Ua=200,B8=.3,T8=4.5,O8=4503599627370496,Kn=2220446049250313e-31;function ae(e,t,n){let s=t[0];for(let o=1;o<=n;o++)s=s*e+t[o];return s}function Mn(e,t,n){let s=e+t[0];for(let o=1;o<n;o++)s=s*e+t[o];return s}function L8(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 _8=[.0008116141674705085,-.0005950619042843014,.0007936503404577169,-.002777777777300997,.08333333333333319],D8=[-1378.2515256912086,-38801.631513463784,-331612.9927388712,-1162370974927623e-9,-1.7217370082083966e6,-853555.6642457654],R8=[-351.81570143652345,-17064.210665188115,-220528.59055385445,-1.1393344436798252e6,-2.5325230717758294e6,-2.0188914143353277e6];function P8(e){const t=(e-.5)*Math.log(e)-e+P0;if(e>1e8)return t;let n=1/(e*e);return n=((.0007936507936507937*n-.002777777777777778)*n+.08333333333333333)/e,t+n}function Hr(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*ae(i,D8,5)/Mn(i,R8,6),Math.log(s)+o}if(e>k8)return Number.POSITIVE_INFINITY;if(e>=1e3)return P8(e);const t=(e-.5)*Math.log(e)-e+P0,n=1/(e*e);return t+ae(n,_8,4)/e}function z8(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 Hr(e+1)}const xo=6.02468004077673,q8=[.006061842346248907,.5098416655656676,19.519927882476175,449.9445569063168,6955.999602515376,75999.29304014542,601859.6171681099,3481712154980646e-9,14605578087685067e-9,4333888932467614e-8,863631312881386e-7,10379404311634454e-8,56906521913471565e-9],U8=[1,66,1925,32670,357423,2637558,13339535,45995730,105258076,150917976,120543840,39916800,0];function G8(e){return L8(e,q8,12,U8,12)}const H8=[452700008624452e-19,.49854102823193375,6.578732594206104,29.911919328553072,60.94966798098779,57.11296359058554,20.039553499201283],Q8=[15.062909083469192,83.04756596796722,221.76239823732857,309.09872225312057,216.42788614495947,60.11866049760384],K8=[.00012617719307481058,.030299440770744195,1],W8=[30019850513866446e-22,.002524483403496841,.22726554820815503,2];function Y8(e){let t=1+e;return t<C8||t>S8?Math.log(t):(t=e*e,t=-.5*t+e*(t*ae(e,H8,6)/Mn(e,Q8,6)),e+t)}function Jo(e){if(Math.abs(e)<.5){let t=e,n=0;for(let s=2;s<$8;s++){t*=-e;const o=t/s;if(n+=o,Math.abs(o)<Ke*Math.abs(n))break}return n}return Y8(e)-e}function V8(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*ae(t,K8,2);return n=n/(ae(t,W8,3)-n),n+n}const X8=[2461969814735305e-25,.5641895648310689,7.463210564422699,48.63719709856814,196.5208329560771,526.4451949954773,934.5285271719576,1027.5518868951572,557.5353353693994],J8=[13.228195115474499,86.70721408859897,354.9377788878199,975.7085017432055,1823.9091668790973,2246.3376081871097,1656.6630919416134,557.5353408177277],Z8=[.5641895835477551,1.275366707599781,5.019050422511805,6.160210979930536,7.4097426995044895,2.9788666537210022],j8=[2.2605286322011726,9.396035249380015,12.048953980809666,17.08144507475659,9.608968090632859,3.369076451000815],t9=[9.604973739870516,90.02601972038427,2232.005345946843,7003.325141128051,55592.30130103949],e9=[33.56171416475031,521.3579497801527,4594.323829709801,22629.000061389095,49267.39426086359];function q0(e){if(Number.isNaN(e))return Number.NaN;if(e<0)return-q0(-e);if(Math.abs(e)>1)return 1-U0(e);const t=e*e;return e*ae(t,t9,4)/Mn(t,e9,5)}function U0(e){if(Number.isNaN(e))return Number.NaN;const t=e<0?-e:e;if(t<1)return 1-q0(e);let n=-e*e;if(n<-709.782712893384)return e<0?2:0;n=Math.exp(n);let s,o;t<8?(s=ae(t,X8,8),o=Mn(t,J8,8)):(s=ae(t,Z8,5),o=Mn(t,j8,6));let r=n*s/o;return e<0&&(r=2-r),r!==0?r:e<0?2:0}function G0(e,t){if(Math.abs(e-t)>.4*Math.abs(e)){const o=e*Math.log(t)-t-Hr(e);return o<-709.782712893384?0:Math.exp(o)}const n=e+xo-.5;let s=Math.sqrt(n/Math.exp(1))/G8(e);if(e<200&&t<200)s*=Math.exp(e-t)*Math.pow(t/n,e);else{const o=t-e-xo+.5;s*=Math.exp(e*Jo(o/n)+t*(.5-xo)/n)}return s}function n9(e,t){const n=G0(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<Gr;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)>O8&&(i*=Kn,c*=Kn,a*=Kn,u*=Kn),g<=Ke)break}return l*n}function ns(e,t){const n=G0(e,t);if(n===0)return 0;let s=e,o=1,r=1;for(let i=0;i<Gr&&(s+=1,o*=t/s,r+=o,!(o<=Ke*r));i++);return r*n/e}function Ga(e,t){let n=1,s=0;for(let i=1;i<Gr;i++){n*=-t/i;const a=n/(e+i);if(s+=a,Math.abs(a)<=Ke*Math.abs(s))break}const o=Math.log(t);return-V8(e*o-z8(e))-Math.exp(e*o-Hr(e))*s}function H0(e,t,n){const s=Io.length,o=Io[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===z0?-1:1;let d;i>1?d=Math.sqrt(-2*Jo(a)):i<1?d=-Math.sqrt(-2*Jo(a)):d=0;let m=.5*U0(f*d*Math.sqrt(e/2));for(let g=0;g<s;g++){const p=Io[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)<Ke*Math.abs(w))break}const b=w*l,y=Math.abs(b);if(y>h||(u+=b,y<Ke*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 Q0(e,t){const n=Math.abs(t-e)/e;return e>E8&&e<Ua&&n<B8||e>Ua&&n<T8/Math.sqrt(e)}function s9(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)?Q0(e,t)?H0(e,t,z0):t>1&&t>e?1-o9(e,t):ns(e,t):1:Number.isFinite(t)?0:Number.NaN}function o9(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)?Q0(e,t)?H0(e,t,F8):t>1.1?t<e?1-ns(e,t):n9(e,t):t<=.5?-.4/Math.log(t)<e?1-ns(e,t):Ga(e,t):t*1.1<e?1-ns(e,t):Ga(e,t):0:Number.isFinite(t)?1:Number.NaN}function r9(e){if(!Number.isInteger(e)||e<za||e>qa)throw new RangeError(`cooltools takes ${za} to ${qa} λ-chunks, not ${e}`);return Float64Array.from(x8.slice(0,e))}function zs(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 Ee(e,t){const n=t.length;if(!(e>t[0]))return 0;K0[0]=e;let s=3*((i9[a9]>>>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 K0=new Float64Array(1),i9=new Uint32Array(K0.buffer),a9=new Uint8Array(new Uint16Array([1]).buffer)[0]===1?1:0,c9=2;function l9(e,t,n=c9){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 u9=256;async function h9(e,t,n,s,o,r,i){const{n:a,hi:c,values:u}=e,{w:l}=s,h=Ur.map($=>I8(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 _=0;O&&_<h.length;_++){const P=h[_].dd;let W=0;for(let j=0;j<P.length;j++){const D=n[$+P[j]];if(!Number.isFinite(D)){O=!1;break}W+=D}w[_][$]=W}b[$]=O?1:0}const y=2*l+1,A=c+1,N=new Float64Array(y*A),I=$=>{const O=$%y*A,_=t[$];for(let P=0;P<=c;P++){const W=$+P;N[O+P]=W<a?u[P*a+$]*(_*t[W]):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 _=O===0?0:M[O-1];v.set($.dr,_),S.set($.dd,_)});const k=new Int32Array(x),C=new Float64Array(4*f);for(let $=0;$<4;$++)C.set(w[$],$*f);const F=new Uint8Array(a);for(let $=0;$<a;$++)F[$]=m($)?1:0;const B=new Int32Array(y),T=new Float64Array(16);let L=0;for(let $=0;$<Math.min(a,l);$++)I($);for(let $=0;$<a;$++){if($+l<a&&I($+l),i!==void 0&&$%u9===0&&await i($),F[$]===0)continue;for(let z=-l;z<=l;z++)B[z+l]=($+z)%y*A;for(let z=0;z<x;z++)k[z]=B[v[z]+l]+S[z];const O=t[$],_=Math.min(f-1,a-1-l-$),P=Math.max(1,-g),W=Math.min(_,c-p),j=(z,R,U,G,Y)=>{if(b[z]===0||F[$+z]===0||!Number.isFinite(R)||!Number.isFinite(U)||!Number.isFinite(G)||!Number.isFinite(Y))return;const Q=n[z]/(O*t[$+z]);L++,r($,$+z,u[z*a+$],Q*R,Q*U,Q*G,Q*Y)};let D=P;for(;D+3<=W;D+=4){let z=0;for(let R=0;R<4;R++){const U=M[R];let G=0,Y=0,Q=0,K=0;for(;z<U;z++){const st=k[z]+D;G+=N[st],Y+=N[st+1],Q+=N[st+2],K+=N[st+3]}const nt=R*f+D;T[R]=G/C[nt],T[4+R]=Y/C[nt+1],T[8+R]=Q/C[nt+2],T[12+R]=K/C[nt+3]}j(D,T[0],T[1],T[2],T[3]),j(D+1,T[4],T[5],T[6],T[7]),j(D+2,T[8],T[9],T[10],T[11]),j(D+3,T[12],T[13],T[14],T[15])}for(;D<=W;D++){let z=0;for(let R=0;R<4;R++){const U=M[R];let G=0;for(;z<U;z++)G+=N[k[z]+D];T[R]=G/C[R*f+D]}j(D,T[0],T[1],T[2],T[3])}}return L}const Ha=16384;class f9{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<Ha){if(t>=this.denseRows){const s=Math.min(Ha,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=Ur.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 d9(e,t){const{counts:n,cells:s}=e.table(),o=e.chunks,r=n.length,i=zs(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:R0(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 F=k/y[S];!Number.isNaN(F)&&!(F>=v)&&(v=F);const B=Number.isNaN(F)?Number.NaN:v;w[S*g+b]=B>1?1:B}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 m9(e,t){const n=zs(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(;R0(i,n[r])>o;)i++;s[r]=i}return s}function g9(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}=N8(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 de={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>de.dAndLl*o&&u>de.dAndLl*t&&u>de.vh*n&&u>de.vh*s&&(u>de.dOrLl*o||u>de.dOrLl*t)&&(e.cSize>1||c+r+i+a<=de.orphanFdr)}class oe{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 w9{constructor(t){this.settings=t,this.edges=r9(t.lambdaBins),this.histogram=new f9(this.edges),this.floors=m9(this.edges,t.fdr)}edges;histogram;floors;scored=0;sequence=new oe;row=new oe;col=new oe;count=new oe;la=[new oe,new oe,new oe,new oe];async addSequence(t,n,s,o,r){const{edges:i,floors:a,histogram:c}=this,u=await h9(n,s,o,this.settings.shape,this.settings.maxSeparation,(l,h,f,d,m,g,p)=>{const w=Ee(d,i),b=Ee(m,i),y=Ee(g,i),A=Ee(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}=d9(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=zs(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[Ee(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=Ee(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}=g9(i,t,u),f=this.settings.clusterFiltering?h.filter(p9):h;return{...r,unlabelled:c,enriched:i,clustered:l,calls:f}}}const b9=1e7,A9=2e4,y9=.1,N9=40,M9=96e6;function I9(e,t){return t>0?Math.trunc(e/t):0}function x9(e,t){const n=D0(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 v9(e,t){const n=e.maxSeparation;return typeof n=="number"&&Number.isFinite(n)?Math.max(1,Math.round(n)):Math.max(1,I9(b9,t))}function k9(e,t){const n=e.clusteringRadius;if(!(typeof n=="number"&&Number.isFinite(n)))return A9;const s=Math.max(0,n)*t,o=Math.round(s);return Math.abs(s-o)<1e-6?o:s}function W0(e,t,n){return Math.max(0,Math.min(t-1+2*n,e-1))}const Y0=["donut","vertical","horizontal","lower-left"],S9=async e=>{const t=e.mc.binsize;if(!J(e.params,"balance",!0))throw new E("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=x9(e.params,t);if(n===null)throw new E("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 E("unsupported","The inner half-width must be smaller than the outer one.");const s=v9(e.params,t),o=k9(e.params,t),r={shape:n,maxSeparation:s,lambdaBins:Math.round(q(e.params,"lambdaBins",N9)),fdr:q(e.params,"fdr",y9),clusteringRadius:o,clusterFiltering:J(e.params,"filter",!0)},i=D0(t);e.note(i!==null&&i.w===n.w&&i.p===n.p?`Kernels w ${n.w}, p ${n.p}: the ones for ${At(t)} bins.`:`Kernels w ${n.w}, p ${n.p}`+(i===null?`, given for ${At(t)} bins, which have none of their own.`:`; the ones for ${At(t)} bins are w ${i.w}, p ${i.p}.`)),e.note(`A ${s.toLocaleString()}-bin scan reaches ${At(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}=C9(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: ${$9(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=Gt(e.mc,!0),l=Nt(e,a.map(g=>g.span),!1),h=new w9(r);for(const[g,p]of a.entries()){await e.breathe();const w=p.span.to-p.span.from,b=await ve(e,p.span,{hi:W0(w,s,n.w),block:l,balance:!1,value:V,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}=l9(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."),Qa(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 ${At(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(F9(a,f.calls,t)),d.push(B9(a,f.calls,t));const m=_s(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(...Qa(h,f)),d};function C9(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 Rs(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((W0(h,t,n)+1)*h>M9){a.push(u);continue}i.push({name:u,span:l,length:s.chromsizes.get(u)??h*s.binsize})}return{units:i,skipped:a}}function $9(e){const t=e.slice(0,6).join(", ");return e.length>6?`${t} and ${e.length-6} more`:t}function F9(e,t,n){const s=new gl;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:E9(o)})}return{kind:"intervals",id:"loops-calls",label:"Called loops",payload:{kind:"pairs",data:s.finish()},noun:{one:"loop",many:"loops"},display:"overlay"}}function E9(e){return`observed ${e.count} · `+Y0.map((t,n)=>`${t} ${e.laExp[n].toFixed(2)} (q ${T9(e.qval[n])})`).join(" · ")+(e.cLabel>=0?` · cluster of ${e.cSize}`:"")}function B9(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 Qa(e,t){const{counts:n,cells:s}=e.histogram.table(),o=e.histogram.chunks,r=zs(e.edges),i=[];Ur.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:Y0[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 T9(e){return Number.isFinite(e)?e===0?"0":e<1e-4?e.toExponential(2):e.toFixed(4):"n/a"}function O9(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 Ka={quartiles:[.25,.5,.75],standard:[.1,.25,.5,.75,.9],deciles:[.1,.2,.3,.4,.5,.6,.7,.8,.9]};function L9(e){const t=typeof e.quantiles=="string"?e.quantiles:"standard";return Ka[t]??Ka.standard}function V0(e){const t=typeof e.reach=="number"?e.reach:0;return Math.max(0,Math.round(t))}function _9(e,t,n=!1){const s=n?Math.floor(t/2):Math.max(1,t-1),o=V0(e);return o===0?s:Math.max(1,Math.min(s,o))}const D9="Scalogram";function R9(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 P9(e,t){const n=e.mc,{ids:s,missing:o}=Ne(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:xe(e,c)})}return{units:r,missing:o}}const z9=async e=>{const t=J(e.params,"balance",!1),n=e.framing.value===""?V: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=L9(e.params),i=V0(e.params);i>0&&e.note(`A ${i.toLocaleString()}-bin cut reaches ${At(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=Ut(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}=P9(e,a),l=le(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=Nt(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=_9(e.params,I,N.circular);await e.breathe(),e.progress(A,h.length,N.name),N.circular&&p++;const x=await ve(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=O9(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 F=0;F<k.length;F++)C[N.span.from+F]=k[F]*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=R9(r.length),b=i===0?"":` · within ${At(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:D9,mode:"ribbon",groupMode:"overlay",scale:"log2"}))};function q9(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=U9(e[i],t[i]);if(a===null)continue;const c=G9(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 U9(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 G9(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 H9(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 Q9(e,t){const n=[];for(let s=0;s<=t;s++)n.push(new Float64Array(e).fill(Number.NaN));return n}const Wa=500;function K9(e){const t=typeof e.maxDistance=="number"?e.maxDistance:Wa;return Math.max(1,Math.min(Wa,Math.round(t)))}const W9=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=Ut(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=J(e.params,"balance",!1),o=e.framing.value===""?V:e.framing.value,r=Math.max(0,Math.round(q(e.params,"smooth",1))),i=K9(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 Y9(e,a,{balance:s,value:o,h:r,maxK:i})}finally{for(const c of a)c.close?.()}};async function Y9(e,t,n){const{balance:s,value:o,h:r,maxK:i}=n,a=Ut(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=Ie(e.mc,x);v>=0?c.push(v):u.push(x)}const l=le(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=Nt(e,c.map(x=>Zo(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=Zo(e.mc,v),C=k.to-k.from;if(C<3)continue;const F=[];let B=!1;for(const L of t){const $=L.lead?k:X9(L.mc,S);if($===null){B=!0;break}if($.to-$.from!==C){e.note(`${S} is ${C.toLocaleString()} bins here and ${($.to-$.from).toLocaleString()} in ${L.label}, so it is left out.`),B=!0;break}F.push(await V9(e,L,$,{balance:s,value:o,h:r,maxK:Math.min(i,C-1),bins:C,block:L.lead?w:null}))}if(B)continue;let T=0;for(let L=0;L<h;L++)for(let $=L+1;$<h;$++){const O=q9(F[L],F[$]),_=L*h+$;for(const P of O.strata)f[_]+=P.weight*(Number.isFinite(P.r)?P.r:0),d[_]+=P.weight,Number.isFinite(P.r)&&(g[T][P.k]+=P.weight*P.r,p[T][P.k]+=P.weight);m.push({sequence:S,a:t[L].label,b:t[$].label,scc:O.scc,strata:O.strata.length}),T++}}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 V9(e,t,n,s){const o=Q9(s.bins,s.maxK),r=s.maxK+s.h,i=t.lead?e:{...e,mc:t.mc};return await N0(i,n,{halo:r,block:s.block,balance:s.balance,value:s.value},a=>{e.throwIfCancelled(),H9(a,s.h,s.maxK,o)}),o}function Zo(e,t){const[n,s]=e.contigExtent(t);return{from:n,to:s}}function X9(e,t){const n=Ie(e,t);return n<0?null:Zo(e,n)}function J9(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 Z9={total:{label:"Coverage · total",unit:"contacts"},cis:{label:"Coverage · cis",unit:"contacts"},trans:{label:"Coverage · trans",unit:"contacts"},fraction:{label:"Cis fraction",unit:""}},j9=async e=>{const t=J9(e.params);if(t.length===0)return e.note("Every output was turned off, so there is nothing to compute."),[];const n=J(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=Gt(s,n),i=new v0(s.nBins,Ps(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!==V&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${V}. 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=Z9[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}})},Lt=1,_t=2,Dt=4,$t=8,tm=Lt|_t|Dt|$t,em=(()=>{const e=new Uint8Array(256),t={A:Lt,C:_t,G:Dt,T:$t,U:$t,R:Lt|Dt,Y:_t|$t,S:Dt|_t,W:Lt|$t,K:Dt|$t,M:Lt|_t,B:_t|Dt|$t,D:Lt|Dt|$t,H:Lt|_t|$t,V:Lt|_t|Dt,N:tm};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&Lt)!==0&&(n|=$t),(t&_t)!==0&&(n|=Dt),(t&Dt)!==0&&(n|=_t),(t&$t)!==0&&(n|=Lt),e[t]=n}return e})();function Ya(e){return!(e instanceof Uint8Array)}const Va=200;function Xa(e){const t=e.replace(/\s+/g,"");if(t==="")return{reason:"Type a sequence to search for."};if(t.length>Va)return{reason:`${t.length} bases is longer than this searches for (${Va}). 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=em[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 X0=[{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}],nm={MboI:"DpnII",Sau3AI:"DpnII",Csp6I:"CviQI"},xs={Arima:["DpnII","HinfI"]},sm=(()=>{const e=new Map;for(const t of X0)e.set(t.name.toLowerCase(),t);for(const[t,n]of Object.entries(nm)){const s=e.get(n.toLowerCase());s!==void 0&&e.set(t.toLowerCase(),s)}return e})();function cn(e){return sm.get(e.trim().toLowerCase())}function Ja(e){const t=e.trim().toLowerCase();return Object.keys(xs).find(n=>n.toLowerCase()===t)}function om(e){return`${e.site.slice(0,e.cut)}^${e.site.slice(e.cut)}`}function rm(e){return e.site.length-2*e.cut}const im=1/256,Za=255;function ja(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 J0(e){const t=e.toUpperCase().replace(/U/g,"T"),n=t.indexOf("^"),s=t.replace("^","");if(n<0){const r=Xa(s);return{refusal:Ya(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=Xa(s);return Ya(o)?{refusal:o.reason}:ja(o)>im?{refusal:`“${e}” would cut every ${Math.round(1/ja(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 am(e){const t=cn(e);if(t!==void 0)return t;const n=J0(e);return"refusal"in n?void 0:n}function Z0(e,t){const n=e.trim();if(n===""||n==="none")return[];if(n!=="custom"){const a=Ja(n);if(a!==void 0)return xs[a].map(u=>cn(u));const c=cn(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=Ja(a);if(c!==void 0){for(const h of xs[c])i(cn(h));continue}const u=cn(a);if(u!==void 0){i(u);continue}const l=J0(a);if("refusal"in l)return l;i(l)}return o.length>Za?{refusal:`That is ${o.length} enzymes, and one digest takes ${Za} at most.`}:o}function cm(e){return e.map(t=>t.name).join("+")}const lm=256;function tc(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 ec(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 In=["valid","re-ligation","dangling","self-circle","same-strand","trans"],De=["++","+-","-+","--"],um=0,hm=1,fm=2,dm=3,mm=4,gm=5;function nc(e,t,n,s){return e===n?t===s?mm:t===0?fm:dm:Math.abs(n-e)===1&&t===0&&s===1?hm:um}const vo=65536;function sc(e){return e==="+"?0:e==="-"?1:-1}function pm(e){return e===0?0:33-Math.clz32(e-1)}function wm(e){if(e<=2)return String(e);const t=2**(e-1);return`${t/2+1}–${t}`}class bm{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=ls(o,i);c=l<0?void 0:n.get(o[l])}if(c===void 0||!(c>0)||this.index.has(i))continue;const u=tc(a.top,c);this.index.set(i,this.names.length),this.names.push(i),this.top.push(u),this.bottom.push(tc(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(vo);for(let i=0,a=0;i<vo;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(In.length*De.length);edges=xl();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=ls(this.names,t);return this.index.set(t,s),s}add(t,n,s,o,r,i,a){if(a)return;const c=sc(s),u=sc(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=ec(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=ec(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=gm,y=c*2+u):d<f?(b=nc(w,u,g,c),y=u*2+c):(b=nc(g,c,w,u),y=c*2+u),this.classCounts[b*De.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<vo)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={};In.forEach((r,i)=>{const a={};let c=0;De.forEach((u,l)=>{const h=this.classCounts[i*De.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)=>wm(i)),counts:s}}}}function Am(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=am(d);m=g===void 0?0:rm(g),o.set(d,m),r.set(d,Math.min(lm-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 oc=["++","+−","−+","−−"],ko=16;function ym(e,t={}){const n=Math.max(1.01,t.factor??1.1),s=e.edges;if(s.length<3)return null;const o=Nm(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:oc[d],x:m,y:g,n:c[d]}),h.push({name:oc[d],...Mm(a[d],r,u),n:c[d]})}if(h.length<2)return null;const f=Im(l);return{curves:h,convergence:f.at,spreadAt:f.spread}}function Nm(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 Mm(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]>=ko){a(c,c,e[c]),c++;continue}let u=c;for(;u<o&&e[u+1]<ko;)u++;const l=[];let h=c,f=0;for(let d=c;d<=u;d++)f+=e[d],!(f<ko)&&(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 Im(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}}[...X0.map(e=>({value:e.name,label:`${e.name} (${om(e)})`})),...Object.entries(xs).map(([e,t])=>({value:e,label:`${e} (${t.join(" + ")})`}))];function xm(e){const t=e.pairs;return typeof t=="string"?t.trim():""}function vm(e){const t=e.reference;return typeof t=="string"?t:""}function km(e){const t=e.enzyme;return typeof t=="string"&&t!==""?t:"none"}function Sm(e){const t=e.sites;return typeof t=="string"?t:""}function Cm(e){const t=vm(e),n=km(e);return t===""||n==="none"?null:{sequence:t,enzyme:n,sites:Sm(e)}}const $m=async e=>{const t=xm(e.params),n=e.inputs.mapSource,s=Fm(e);let o=t===""?e.inputs.pairsStats??null:null,r=t===""?e.inputs.orientation??null:null,i=null,a=`as ${ac(e.framing.uri)} was binned`;const c=t!==""||s!==null||o===null&&n!==void 0;if(c){const l=t!==""?t:ac(e.framing.uri),h=t!==""?await j0(e,t,e.inputs.sources?.pairs):n!==void 0?await Dm(e,n,l):null;if(h!==null)try{const f=await Lm(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=t1(e,r,"pairsqc-orientation",{converge:!1});l!==null&&(u.push(l),o!==null&&e.note(Rm(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=Pm(o);l!==null?u.push(l):e.note("The records carry no pair_type column, so pair types are not counted."),u.push(zm(o),qm(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(...Um(e,i)),s!==null)){const l=await Vm(e,s,i.enzymes);l!==null&&u.push(l)}return u};function Fm(e){const t=Cm(e.params),n=e.inputs.upstream?.restriction;if(t===null)return rt(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=Z0(rt(t,"enzyme","none"),rt(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=Am(n);return o===null?(e.note("The restriction step found no sequence to cut, so there are no restriction statistics."),null):o}function Em(e){const t=Z0(rt(e.params,"enzyme","none"),rt(e.params,"sites",""));return Array.isArray(t)?cm(t):""}const Bm=43,Tm=45,Om=33,rc=68;function ic(e){return e===Bm?"+":e===Tm?"-":"."}async function Lm(e,t,n,s){e.progress(0,1,"reading records");const o=await Ts(n),r=s===null?null:_m(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]===Om?"!":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]===rc&&f[M+1]===rc;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 kr(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 _m(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)&&ls(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 bm(t,s,Em(e))}function ac(e){return e.split("::")[0].split(/[?#]/)[0].split(/[\\/]/).filter(s=>s!=="").pop()??e}async function Dm(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 j0(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 t1(e,t,n,s={}){const o=s.factor??Math.max(1.01,q(e.params,"factor",1.1)),r=ym(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 Rm(e){const t=vl(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 qs(e){return Float64Array.from(e,(t,n)=>n)}function Pm(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:qs(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 zm(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:qs(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 qm(e){const t=H5(e).filter(([n])=>!/^(chrom_freq|dist_freq|chromsizes)\//.test(n)).map(([n,s])=>({statistic:n,value:Q5(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 Um(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.`:".")),[Gm(t,n),Hm(t,n),Qm(t,n),Km(t,n)]}function Gm(e,t){const n=[...In],s=qs(n);return{kind:"curve",id:"pairsqc-classes",label:`Pair classes by orientation · ${t}`,series:De.map(o=>({name:o,x:s,y:Float64Array.from(In,r=>e.byOrientation[r][o]),mark:"bars",stack:"orientation"})),xLabel:"Class",yLabel:"Pairs",xScale:"linear",yScale:"linear",xTicks:n}}function Hm(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},...De.map(n=>({key:n,label:n,kind:"number"}))],rows:In.map(n=>({class:n,pairs:e.classes[n],share:e.counted>0?e.classes[n]/e.counted:Number.NaN,...e.byOrientation[n]}))}}function Qm(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 Km(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:qs(o),y:Float64Array.from(r),mark:"bars",n}],xLabel:"Read ends in the fragment",yLabel:"Fragments",xScale:"linear",yScale:"linear",xTicks:[...o]}}const Wm=5,Ym="five";async function Vm(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=ls(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 v0(s.nBins,Ps(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>=Wm?y/(b-w):Number.NaN,w,b),w=b}const g=$l(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 ${Ym} 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 So(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 Xm(e,t,n){const s=e.mc,o=(c,u)=>xe(e,s.chromnames[c])?u.to-u.from:0;if(t==="file"){const c=[];for(const u of Ne(s,null).ids){const l=zt(s,u);l!==null&&c.push(l)}return{units:c.length===0?[]:[So("All sequences",c)],missing:[]}}if(t==="genome"){if(!s.hasGenomes)throw new E("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(So(s.genomeNames[u],f))}return{units:c,missing:[]}}const{ids:r,missing:i}=Ne(s,n),a=[];for(const c of r){const u=zt(s,c);u!==null&&a.push(So(s.chromnames[c],[u],o(c,u)))}return{units:a,missing:i}}function Jm(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;for(let c=0;c<=s.maxOffset&&c<i;c++){let u;if(a>0)if(n===null)u=2*c===a?a/2:a;else{u=0;for(let l=0;l<i;l++){const h=r.from+l,f=r.from+(l+c)%a;!Number.isNaN(n[h])&&!Number.isNaN(n[f])&&u++}c>0&&2*c===a&&(u/=2)}else if(n===null)u=i-c;else{u=0;for(let l=r.from;l+c<r.to;l++)!Number.isNaN(n[l])&&!Number.isNaN(n[l+c])&&u++}o[c]+=t&&c>0?u*2:u}}return o})}function Zm(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 jm(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=Gt(s,n);e.progress(0,1,"counting the pairs each separation could hold"),e.throwIfCancelled();const c=Jm(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)=>Zm(l.maxOffset,u[h],c[h]))}async function t7(e,t,n,s){const o=Nt(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 wn(t[i].maxOffset,t[i].lap);for(const c of t[i].spans)a.addBlock(Rr(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 wn(t[0].maxOffset,t[0].lap);return a.addBlock(i),{curves:[a.finish()],mirrored:!0}}return s!==V&&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 jm(e,t,n),mirrored:e.mc.storageMode==="square"}}const cc=[4e3,1e6],e7=async e=>{const t=rt(e.params,"scope","contig"),n=Ut(e.params,"sequences"),s=q(e.params,"factor",1.1),o=q(e.params,"minSeparation",0),r=rt(e.params,"quantity","density")==="expected",i=J(e.params,"derivative",!0),a=J(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}=Xm(e,t,n),l=le(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 t7(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?Cr(f[y],e.mc.binsize,s,o):T3(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=Fl(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:cc}];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:cc});const b=await n7(e);return b!==null&&w.push(b),w};async function n7(e){if(!J(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=rt(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 t1(e,n,"ps-orientation")}async function s7(e,t,n){const s=await j0(e,t,n);if(s===null)return null;try{return await o7(e,t,s)}finally{s.close()}}async function o7(e,t,n){e.progress(0,1,"reading records");const s=await Ts(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 kr(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 r7{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 i7(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 a7(e,t){const n=e.mc,s=ff(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 c7=async e=>{const t=rt(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=J(e.params,"balance",!1),s=e.mc.hasGenomes,o=!s&&J(e.params,"cis",!0),r=s?"none":rt(e.params,"normalise","none"),i=r==="ps"||r==="ps+coverage",a=r==="coverage"||r==="ps+coverage",c=e.framing.value===""?V:e.framing.value,u=a7(e,t),l=o?await e1(e,u,n,c,i,a):await u7(e,u,n,i,a),h=J(e.params,"excludeAnchor",!1);return h&&(l7(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 · ${jl(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 l7(e,t){e.fill(Number.NaN,Math.max(0,t.from-1),Math.min(e.length,t.to+1))}async function u7(e,t,n,s,o){const r=s?await e1(e,t,n,V,!0):null,i=o?new Float64Array(e.mc.nBins):null,a=await m7(e,t,n,i);let c=r===null?a:f7(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 h7(e,t,n){const s=new wn(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=$r(o,Math.abs(a-r));i[a]=Number.isFinite(e[a])&&Number.isFinite(c)&&c!==0?e[a]/c:Number.NaN}return i}function f7(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 e1(e,t,n,s,o=!1,r=!1){e.progress(0,1,`reading ${t.label}`);const i=e.framing.value===""?V:e.framing.value,a=s===i?Nt(e,[t.scope],n):null,c=await Pr(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=i7({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?h7(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 m7(e,t,n,s=null){const o=e.mc,r=Gt(o,n);e.framing.value!==""&&e.framing.value!==V&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${V}. This profile is of the counts.`);const i=new r7(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 g7(e){const t=typeof e.window=="number"?e.window:10;return Math.max(1,Math.round(t))}function p7(e){const t=typeof e.scales=="number"?e.scales:1;return Math.max(1,Math.min(4,Math.trunc(t)))}function w7(e){const t=g7(e),n=[];for(let s=0;s<p7(e);s++)n.push(t*2**s);return n}function b7(e,t){const n=e.mc,s=n.chromsizes,{ids:o,missing:r}=Ne(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:xe(e,u)})}return{units:i,missing:r}}const A7="Insulation",y7=async e=>{const t=J(e.params,"balance",!1),n=e.framing.value===""?V: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=w7(e.params),i=r[r.length-1],a=r.filter(x=>Qd(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=Ut(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}=b7(e,c),h=le(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=Nt(e,u.map(x=>x.span),t),g=[],p=J(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=Yd(S[k]);for(let F=0;F<v;F++)d[k][x.span.from+F]=C[F];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 ve(e,v.span,{hi:2*i,block:m,balance:t,value:n,circular:!0,onTile:async(F,B)=>{await e.breathe(),e.progress(x,u.length,B===1?v.name:`${v.name} · strip ${Math.min(F+1,B)} of ${B}`)}});for(let F=0;F<r.length;F++)k[F]=Wd(C,{window:r[F],ignoreDiags:o});y(v,S,k);continue}await N0(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 F=0;F<r.length;F++){const B=Kd({size:C.size,values:C.values},{window:r[F],ignoreDiags:o});for(let T=C.ownFrom;T<C.ownTo;T++)k[F].sums[T]=B.sums[T-C.from],k[F].counts[T]=B.counts[T-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:Zd(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)=>N7(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(M7(e,N)),e.note(`${x.toLocaleString()} boundaries called across ${N.length} sequences.`),J(e.params,"domains",!0)){const v=I7(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 N7(e,t,n,s){const o=n*e.mc.binsize;return{kind:"profile",id:`insulation-w${n}`,label:`Insulation · ${At(o)}`,values:t,extent:[0,e.mc.nBins],binsize:e.mc.binsize,unit:"log2 ratio",...s?{group:A7,mode:"heatmap",groupMode:"overlay"}:{}}}function M7(e,t){const n=new jt;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 I7(e,t){const n=new jt;let s=0;for(const{unit:o,boundaries:r}of t)for(const i of E0(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 x7(e,t,n,s){const o={from:t,to:n},r=Nt(e,[o],s);if(r!==null)return Rr(r,o).values;const i=e.framing.value===""?V: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 wn(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(xn(Math.abs(r-o),n),e[o*t+r]);return s.finish()}function k7(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=$r(s,xn(Math.abs(i-r),n));o[r*t+i]=Number.isFinite(a)&&Number.isFinite(c)&&c>0?a/c:Number.NaN}return o}function S7(e,t,n,s){const o=Int32Array.from({length:t},(i,a)=>a),r=S0(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 C7=1.1;function lc(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 Co(e,t,n){const s=Cr(t,n,C7,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 $7(...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 F7=async e=>{const{ids:t,missing:n}=Ne(e.mc,Ut(e.params,"sequences")),s=le(e.mc,n,t.length);if(s!==null&&e.note(s),t.length===0)return[];const o=J(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>Ns){e.note(`${w}: ${A.toLocaleString()} bins is past the ${Ns.toLocaleString()}-bin limit on a square read whole; left out. Open the file at a coarser resolution.`);continue}const N=xe(e,w),I=e0(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 x7(e,b,y,o);e.throwIfCancelled();const S=N?A:0,k=v7(v,A,S),{byDistance:C,byBin:F}=Ba(k7(v,A,S,k),x,r),B=Ta(C);for(let _=0;_<A;_++)c[b+_]=F[_]>0?Math.log2(F[_]):Number.NaN;u.push(lc(w,C,a)),await e.breathe(),e.throwIfCancelled();const T=Ba(S7(v,A,x,i),x,r).byDistance,L=Ta(T,B.reach);l.push(lc(w,T,a));const{within:$,across:O}=kd(v,x);for(const _ of[Co(`${w} · along the diagonal`,k,a),Co(`${w} · within an arm`,$,a),Co(`${w} · across the arms`,O,a)])_!==null&&h.push(_);f.push({sequence:w,topology:N?"circular":"linear",origin:(I??0)+1,enrichment:2**B.score,detrended:2**L.score,reach:Number.isFinite(B.reach)?B.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=$7(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}]},E7="shared";function B7(e,t){const n=new jt;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:[E7]};return n.finish(null,s)}function s1(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 T7(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 O7(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*L7(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)=>_7(e,t,s,o,u,l),i=[ss(t,1),ss(t,2),ss(t,3)];uc(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]);uc(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 _7(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 ss(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 uc(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(ss(t,11+n)),n--;continue}for(let r=0;r<t;r++)s[r]/=o}}function D7(e,t,n,s=null,o){const r=o??jo(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 jo(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 R7(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 o1(e,t){const n=e.length;if(n<3)return Number.NaN;const s=hc(e),o=hc(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 hc(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 vs(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 P7(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 z7(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 q7(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 r1(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 U7(e,t){return r1(e,t)}function G7(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:$l(o,r),pairs:o.length}}function tr(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 H7(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 $o(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 Fo=100,Q7={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"},dc={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 i1(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 a1(e){return e.haplotypes.length<=1?[{index:-1,label:""}]:e.haplotypes.map((t,n)=>({index:n,label:t}))}function c1(e){const t=bs(e.inputs.features,e.params,"structure"),n=t0(t,dc);if(n!==null||t.value===void 0)return e.note(n??dc.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 K7=async e=>{const t=c1(e);if(t===null)return[];const{set:n,model:s,label:o}=t,r=i1(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=J(e.params,"balance",!1),a=e.framing.value===""?V:e.framing.value,c=q(e.params,"alpha",3),u=(Mr(rt(e.params,"region",""))[0]??"").split(":")[0].trim(),l=r.find(w=>w.name===u)??r[0],h=a1(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 Pr(e,w.span,{block:Nt(e,[w.span],i),balance:i,value:a});for(const A of h){const N=vs(n,w.name,A.index);if(N.length===0)continue;const I=P7(n,s,N,f,b),M=z7(I),x=G7(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)=>At(C*f));d.push(mc(`structure-distance-${A.index}`,`Model distances · ${w.name}${v}`,b,M,S,"viridis"),mc(`structure-predicted-${A.index}`,`Predicted contacts 1/d^${c} · ${w.name}${v}`,b,q7(M,c),S,"fall")),d.push(...W7(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 mc(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 W7(e,t,n,s,o,r,i){const a=r1(s,r),c=U7(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=Cr(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=Fl(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 Y7=async e=>{const t=c1(e);if(t===null)return[];const{set:n,model:s,label:o}=t,r=i1(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=rt(e.params,"locus","").trim(),l=a1(s),h=[];for(const f of l){const d=f.label===""?"":` · ${f.label}`,m=r.flatMap(N=>vs(n,N.name,f.index)),g=tr(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:V7(n,s,u,f.index);for(const N of r){e.throwIfCancelled();const I=vs(n,N.name,f.index);if(I.length===0)continue;const M=N.span.to-N.span.from;g!==null&&$o(n,I,fc(s,I,g),i,N.span.from,M,p),$o(n,I,H7(s,I,c),i,N.span.from,M,w),y!==null&&$o(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 ${er(u)}`,b,"#c0392b"))}return u!==""&&!h.some(f=>f.id.startsWith("structure-distance"))&&e.note(`No bead of the model lies at ${er(u)}, so the distance track was not made.`),h};function er(e){return Mr(e).map(jl).join(", ")}function V7(e,t,n,s){const[o,r]=n.split(":"),i=o?.trim()??"",a=vs(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 tr(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 tr(t,d.length>0?d:a.filter(m=>e.start[m]<=h&&e.end[m]>h))}function l1(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 X7(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?l1(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=>Dr(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=os(A);if(N===null)return{refusal:nr(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=os(f),m=d===null?null:os(f);if(d===null||m===null)return{refusal:nr(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 F=M[k];F!==void 0&&(d[v*f+F]+=C,m[v*f+F]+=1,v!==F&&(d[F*f+v]+=C,m[F*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 os(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 nr(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 J7(e,t){if(t==="")return null;const n=[];for(const s of Mr(t)){const o=Z7(e,s);if(o===void 0)return{missing:Os(s)[0]};o!==null&&n.push(o)}return n.length===0?null:n}function Z7(e,t){if(t==="")return null;const[n,s,o]=Os(t),r=Ie(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 j7=async e=>{const t=J(e.params,"balance",!1),n=e.framing.value===""?V:e.framing.value,s=Math.max(.5,q(e.params,"alpha",3)),o=Math.max(0,Math.round(q(e.params,"iterations",150))),r=rt(e.params,"weights","contacts"),i=r==="sqrt"||r==="equal"?r:"contacts",a=rt(e.params,"method","nb")!=="shrec3d",c=Math.max(0,Math.round(q(e.params,"seed",0))),u=rt(e.params,"region","").trim(),l=J7(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 X7(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=l1(e),p=e.mc.binsize,w=new Int32Array(d.n).fill(-1),b=new Int32Array(d.n),y=[],A=new Map;for(let D=0;D<d.n;D++){const z=d.binFrom[D],R=g.find(nt=>nt.from<=z&&z<nt.to);if(R===void 0)continue;const U=e.mc.chromnames[R.cid],G=e.mc.chromsizes.get(U)??(R.to-R.from)*p,Y=(z-R.from)*p,Q=Math.min(G,(Math.min(R.to,d.binTo[D])-R.from)*p);w[D]=R.cid;const K=A.get(R.cid)??0;b[D]=K,A.set(R.cid,K+1),y.push({contig:U,start:Y,end:Math.max(Y+1,Q),x:0,y:0,z:0})}const N=a?tg(e,d):null;if(N!==null){for(let D=0;D<d.n;D++)if(!Number.isFinite(N[D]))for(let z=0;z<d.n;z++)d.values[D*d.n+z]=Number.NaN,d.values[z*d.n+D]=Number.NaN}const I=Int32Array.from({length:d.n},(D,z)=>z).filter(D=>w[D]>=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 D=0;D<I.length;D++)x[I[D]]=D;e.progress(0,1,a?"the counts":"contacts to distances"),await e.breathe();const v=ag(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,D=>w[D]),F=Int32Array.from(v,D=>b[D]);let B,T,L;if(a){const D=eg(d.values,d.n,v),z=N===null?null:ng(Float64Array.from(v,Q=>N[Q])),R=p4(D,k,C,F,z),U=w4(R),G=sg(D,k);A4(D,k,z,s);const Y=D4(k,D);try{const Q=Fo+o,K=Y.mds(D),nt=K.threads===1?"":` · ${K.threads} threads`,st=E4(k,b4(k,j4(c)));let Mt=Number.POSITIVE_INFINITY,H=st.next();for(;H.done!==!0;){await e.breathe();const{point:tt,gradient:it,iteration:ct,current:wt}=H.value,bt=await K.evaluate(tt,it);Mt=Math.min(Mt,wt,bt),e.progress(Math.min(Fo-1,ct),Q,`MDS start · step ${ct}${nt} · stress ${Mt.toPrecision(3)}`),H=st.next(bt)}const X=H.value;let et=null;if(B=X.coords,o>0){const tt=Y.likelihood({counts:D,n:k,bias:z,dispersion:U,alpha:s}),it=tt.threads===1?"":` · ${tt.threads} threads`,ct=B4(k,X.coords,{iterations:o});let wt=Number.POSITIVE_INFINITY,bt=ct.next();for(;bt.done!==!0;){await e.breathe();const{point:Ht,gradient:te,iteration:ee,current:ne}=bt.value,ke=await tt.evaluate(Ht,te);wt=Math.min(wt,ne,ke);const Se=Math.min(o,ee);e.progress(Fo+Se,Q,`pastis-NB · step ${Se} of at most ${o}${it} · −log L ${wt.toExponential(3)}`),bt=ct.next(ke)}et=bt.value,B=et.coords}e.progress(Q,Q),L=lg(D,k,B,z),T=og(G,s,U,R,z!==null,c,X,et,o)}finally{Y.close()}}else{const D=rg(d.values,d.n,v,i);if(D===null)return ig(e,k);s1(d.values,d.n,v);const z=d.values.subarray(0,k*k);T7(z,k,s);const R=80,U=R+o+1;e.progress(0,U,"classical scaling"),await e.breathe(),O7(z,k,C,F);const G=L7(z,k,R);let Y=G.next();for(;Y.done!==!0;)await e.breathe(),e.progress(Y.value.sweep,U,`classical scaling · sweep ${Y.value.sweep} of ${Y.value.sweeps}`),Y=G.next();B=Y.value;let Q=jo(z,k,B,D),K=0;for(;K<o;K++){await e.breathe();const nt=Q;D7(z,k,B,D,nt);const st=jo(z,k,B,D);if(Q=st,e.progress(R+K+1,U,`refining · step ${K+1} of ${o} · stress ${st.toPrecision(3)}`),nt-st<1e-6*nt){K++;break}}e.progress(U,U),L=cg(z,k,B,D),T=[{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:`${K.toLocaleString()}`},{what:"Weighted stress",value:Q.toPrecision(3)}]}R7(B);const $=[];for(let D=0;D<k;D++){const z=y[x[v[D]]];$.push({...z,x:B.x[D],y:B.y[D],z:B.z[D]})}const O=B7($,p),_=new Set($.map(D=>D.contig)),P=l===null?_.size===1?[..._][0]:`${_.size} sequences`:er(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 W={kind:"intervals",id:"reconstructed-model",label:`3D model · ${P}`,payload:{kind:"features",data:O},entryKind:"structure",noun:{one:"bead",many:"beads"}},j={kind:"table",id:"reconstructed-fit",label:`Model from the map · ${P}`,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, ${At(p)} each`},{what:"Sequences",value:`${_.size.toLocaleString()}`},{what:"Pairs counted",value:`${L.pairs.toLocaleString()} of ${(k*(k-1)/2).toLocaleString()}`},...T,{what:"Spearman ρ (1/d vs contacts)",value:Number.isNaN(L.rho)?"—":L.rho.toFixed(3)}]};return[W,j]};function tg(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(Yt,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 eg(e,t,n){s1(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 ng(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 Eo(e){return e>=100?e.toFixed(0):e>=10?e.toFixed(1):e.toPrecision(3)}function og(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 = ${Eo(Math.exp(n.c0))} · λ^${n.c1.toFixed(3)}, λ the mean, fitted over ${s.mean.length.toLocaleString()} separations: ${Eo(ha(n,s.mean[0]))} near the diagonal, ${Eo(ha(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:Q7[a.stop]},{what:"−log L (less Σ log c!, as pastis gives it)",value:a.value.toExponential(4)}),l}function rg(e,t,n,s){const o=n.length,r=os(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 ig(e,t){return e.note(nr(t,2)),[]}function ag(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 cg(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(u1(n,u,l)),a.push(-h))}return{rho:o1(i,a),pairs:o}}function lg(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(u1(n,u,l)),a.push(s===null?h:h/(s[u]*s[l])))}return{rho:o1(i,a),pairs:o}}function u1(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 ug{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 hg{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 fg(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 Us(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 h1(e){e.framing.value!==""&&e.framing.value!==V&&e.note(`The map is drawn from the ${e.framing.value} column, but a whole-file pass reads ${V}. These numbers are of the counts.`)}const mg=async e=>{const t=Us(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=J(e.params,"balance",!1),s=Gt(e.mc,n);h1(e);const o=fg(t.contigs,e.mc.nBins,t.allowed),r=new ug(e.mc.nGenomes,{pairs:J(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(gg(r.pairs,t,e.mc.nGenomes)),u};function gg(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 pg=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=rt(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=Us(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)}]},wg=async e=>{const t=Us(e);if(t.genomes.length===0)return[];const n=J(e.params,"balance",!1),s=Gt(e.mc,n);h1(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 hg(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 jt,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},bg=async e=>{const t=Us(e),n=J(e.params,"balance",!1),s=e.framing.value===""?V: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 jt;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 F=g.values[k*p+C];w[k*p+C]=Number.isFinite(F)?F:0}const b=Ed(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 F=w[k*p+C];b.side[k]===b.side[C]?y+=F:A+=F}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 F of C){const B=t.contigs.find(T=>T.name===F);B!==void 0&&c.add(F,0,B.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},Ag={expected:e7,pairsqc:$m,coverage:j9,cistrans:xd,cellqc:rd,insulation:y7,di:l8,hicscore:p8,scalogram:z9,fourc:c7,apa:L6,loops:S9,chromosight:hd,compartments:zd,interarm:F7,hicrep:W9,structuremap:K7,spatialtracks:Y7,reconstruct3d:j7,magqc:mg,magnetwork:pg,magpurity:wg,magsplit:bg};function yg(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 f1=self,d1=Math.max(0,Math.min(7,(typeof navigator>"u"?1:navigator.hardwareConcurrency||1)-1));X3(u4,d1);_4(P4,d1);let Ae=null;const yt=new Set;function Ng(){if(Ae===null)throw new Error("no file is open in the analysis worker");return Ae}function ce(e,t=[]){f1.postMessage(e,t)}async function Mg(e){Ae?.mc.close(),Ae=null,yt.clear();const t=await Sl(e.uri,e.source,{report:(o,r,i)=>ce({type:"progress",id:e.id,done:o,total:r,note:i}),cancelled:()=>yt.has(e.id),...e.binning===void 0?{}:{binning:e.binning}}),n=t.source;let s=t.mc;if(e.edit!==void 0){const o=ht.withLens(s,e.edit);if(o.refusal!==null)throw s.close(),new E("unsupported",o.refusal);s=o.map}if(e.cells!==void 0&&s.cells.length>0&&s.selectCells(e.cells),e.resample!==void 0&&await g1(s,e.resample,e.id),e.coarsen!==void 0)try{s=m1(s,e.coarsen)}catch(o){throw s.close(),o}return Ae={mc:s,source:n},{nBins:s.nBins,binsize:s.binsize}}function m1(e,t){if(t===e.binsize)return e;const n=t/e.binsize;if(!Number.isInteger(n)||n<1)throw new E("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=ht.coarsened(e,n);if(s.refusal!==null)throw new E("unsupported",s.refusal);return s.map}async function g1(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)=>ce({type:"progress",id:n,done:s,total:o,note:"counting contacts"}),cancelled:()=>yt.has(n)})}const Ig=0,xg=[vf,kf].filter(e=>e!=="").join(" ");async function vg(e){const t=Ag[e.task];if(t===void 0)throw new Error(`no analysis runner is registered for the task ${e.task}`);const{mc:n}=Ng(),s=e.id,o=[],r=performance.now(),i={mc:n,params:e.params,framing:e.framing,inputs:e.inputs,cancelled:()=>yt.has(s),throwIfCancelled:()=>{if(yt.has(s))throw He()},breathe:async()=>{if(await pt(),yt.has(s))throw He()},progress:(c,u,l)=>ce({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 Ho({kind:"remote",url:c}),openSource:async c=>await Ho(c),peer:async c=>{const u=await Sl(c.uri,c.source,{report:(h,f,d)=>ce({type:"progress",id:s,done:h,total:f,note:d}),cancelled:()=>yt.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 g1(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=m1(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:Ig,params:e.params,framing:e.framing,app:xg,createdAt:new Date().toISOString()},notes:o,ms:performance.now()-r}}async function kg(e){const t=e.id,n=e.n,s=await i4(e.values,e.n,async o=>{if(o%Sg===0){if(await pt(),yt.has(t))throw He();ce({type:"progress",id:t,done:o,total:n,note:"correlating"})}});if(yt.has(t))throw He();return s}const Sg=64;function Cg(e){if(yt.has(e.id))throw He();const t=G4({nrows:e.nrows,ncols:e.ncols,values:e.values},e.counts,e.spec,e.over??void 0);if(yt.has(e.id))throw He();return{values:t.values,over:t.over,applied:t.applied,scope:t.scope}}async function $g(e){switch(e.kind){case"open":return Mg(e);case"run":return vg(e);case"correlate":return kg(e);case"smooth":return Cg(e);case"cancel":return yt.add(e.target),null;case"close":return Ae?.mc.close(),Ae=null,yt.clear(),pn(),null}}async function Fg(e){try{const t=await $g(e);ce({type:"result",id:e.id,kind:e.kind,payload:t},yg(t))}catch(t){ce({type:"error",id:e.id,error:Sf(t)})}finally{yt.delete(e.id)}}f1.onmessage=e=>{Fg(e.data)};const Eg=N1();setInterval(()=>ce({type:"busy",fraction:Eg.busy()}),y1);