UNPKG

higlass-zarr-datafetchers

Version:
3 lines (2 loc) 2.68 kB
import{open as N,root as L,get as E,slice as I,FetchStore as A}from"zarrita";function C(v,h,z){let x=z?h[1]:h[0]*h[1],m=new Float32Array(x),u=0;if(z)for(let d of v){let a=d.data;m.set(a,u),u+=a.length}else{let d=h[0];for(let a=0;a<d;a++)for(let f of v){let g=f.data.subarray(a*f.stride[0],(a+1)*f.stride[0]);m.set(g,u),u+=g.length}}return m}var P=function v(h,...z){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');let{slugid:x}=h.libraries,{absToChr:m,parseChromsizesRows:u,genomicRangeToChromosomeChunks:d,DenseDataExtrema1D:a,minNonZero:f,maxNonZero:g}=h.utils;class M{constructor(t){if(this.dataConfig=t,this.trackUid=x.nice(),t.hasStoreRoot)this.storeRoot=Promise.resolve(v.urlToStoreRoot[t.url]);else if(t.url){let{url:r,options:e={}}=t;this.store=new A(r,e),this.storeRoot=Promise.resolve(L(this.store))}t.row!==void 0&&(this.row=t.row)}tilesetInfo(t){return this.tilesetInfoLoading=!0,this.storeRoot.then(r=>N(r)).then(r=>{let e=r.attrs;this.tilesetInfoLoading=!1;let p=e.multiscales.map(l=>[l.name,l.metadata.chromsize]),n=e.multiscales[e.multiscales.length-1],o=n.metadata.chromoffset+n.metadata.chromsize,s=e.shape[1],i={...e,shape:[e.shape[1],e.shape[0]],chromSizes:p,tile_size:s,max_width:o,min_pos:[0],max_pos:[o],max_zoom:Math.ceil(Math.log(o/s)/Math.log(2))};return t&&t(i),i}).catch(r=>{this.tilesetInfoLoading=!1,t&&t({error:`Error parsing zarr multivec: ${r}`})})}fetchTilesDebounced(t,r){let e={},p=[],n=[];for(let o of r){let s=o.split("."),i=parseInt(s[0],10),l=parseInt(s[1],10);if(Number.isNaN(l)||Number.isNaN(i)){console.warn("Invalid tile zoom or position:",i,l);continue}p.push(o),n.push(this.tile(i,l,o))}return Promise.all(n).then(o=>{for(let s=0;s<o.length;s++){let i=p[s];e[i]=o[s],e[i].tilePositionId=i}t(e)}),e}tile(t,r,e){let{storeRoot:p}=this;return this.tilesetInfo().then(n=>{let o=+n.resolutions[t],s=+n.tile_size,i=o,l=r*s*o,R=l+s*o,S=n.chromSizes,T=u(S),[Z,_]=m(l,T),[k,F]=m(R,T),b=d(S,{chr:Z,pos:_},{chr:k,pos:F},i,s);return Promise.all(b.map(([D,c,y])=>p.then(w=>N(w.resolve(`/chromosomes/${D}/${o}/`),{kind:"array"})).then(w=>this.row!==void 0?E(w,[this.row,I(c,y)]):E(w,[null,I(c,y)])))).then(D=>{let c=C(D,[n.shape[1],n.shape[0]],this.row!==void 0);return Promise.resolve({dense:c,denseDataExtrema:new a(c),dtype:"float32",min_value:Math.min.apply(null,c),max_value:Math.max.apply(null,c),minNonZero:f(c),maxNonZero:g(c),server:null,size:1,shape:n.shape,tileId:e,tilePos:[r],tilePositionId:e,tilesetUid:null,zoomLevel:t})})})}}return new M(...z)};P.config={type:"zarr-multivec"};P.urlToStoreRoot={};var U=P;export{U as ZarrMultivecDataFetcher}; //# sourceMappingURL=index.min.js.map