Files
snpr/public/javascripts/dalliance-compiled.js
2012-02-28 21:03:22 +00:00

384 lines
166 KiB
JavaScript

var BAM_MAGIC=21840194,BAI_MAGIC=21578050;function BamFile(){}function Vob(a,b){this.block=a;this.offset=b}Vob.prototype.toString=function(){return""+this.block+":"+this.offset};function Chunk(a,b){this.minv=a;this.maxv=b}
function makeBam(a,b,c){var e=new BamFile;e.data=a;e.bai=b;e.data.slice(0,65536).fetch(function(d){if(!d)return dlog("Couldn't access BAM");d=unbgzf(d);d=new Uint8Array(d);readInt(d,0);for(var f=readInt(d,4),h="",g=0;g<f;++g)h+=String.fromCharCode(d[g+8]);h=readInt(d,f+8);f=f+12;e.chrToIndex={};e.indexToChr=[];for(g=0;g<h;++g){for(var i=readInt(d,f),j="",r=0;r<i-1;++r)j+=String.fromCharCode(d[f+4+r]);readInt(d,f+i+4);e.chrToIndex[j]=g;if(j.indexOf("chr")==0)e.chrToIndex[j.substring(3)]=g;else e.chrToIndex["chr"+
j]=g;e.indexToChr.push(j);f=f+8+i}if(e.indices)return c(e)});e.bai.fetch(function(d){if(!d)return dlog("Couldn't access BAI");var f=new Uint8Array(d);if(readInt(f,0)!=BAI_MAGIC)return dlog("Not a BAI file");var h=readInt(f,4);e.indices=[];for(var g=8,i=0;i<h;++i){var j=g,r=readInt(f,g);g+=4;for(var q=0;q<r;++q){readInt(f,g);var m=readInt(f,g+4);g+=8+m*16}q=readInt(f,g);g+=4;g+=q*8;if(r>0)e.indices[i]=new Uint8Array(d,j,g-j)}if(e.chrToIndex)return c(e)})}
BamFile.prototype.blocksForRange=function(a,b,c){var e=this.indices[a];if(!e)return[];a=reg2bins(b,c);for(var d=[],f=0;f<a.length;++f)d[a[f]]=true;a=[];var h=[];f=readInt(e,0);for(var g=4,i=0;i<f;++i){var j=readInt(e,g),r=readInt(e,g+4);g+=8;if(d[j])for(var q=0;q<r;++q){var m=readVob(e,g),p=readVob(e,g+8);(j<4681?h:a).push(new Chunk(m,p));g+=16}else g+=r*16}f=readInt(e,g);d=null;b=Math.min(b>>14,f-1);c=Math.min(c>>14,f-1);for(f=b;f<=c;++f)if(b=readVob(e,g+4+f*8))if(!d||b.block<d.block||b.offset<d.offset)d=
b;e=[];if(d!=null)for(f=0;f<h.length;++f){c=h[f];c.maxv.block>=d.block&&c.maxv.offset>=d.offset&&e.push(c)}h=e;e=[];for(f=0;f<h.length;++f)e.push(h[f]);for(f=0;f<a.length;++f)e.push(a[f]);e.sort(function(o,s){var u=o.minv.block-s.minv.block;return u!=0?u:o.minv.offset-s.minv.offset});a=[];if(e.length>0){h=e[0];for(f=1;f<e.length;++f){c=e[f];if(c.minv.block==h.maxv.block)h=new Chunk(h.minv,c.maxv);else{a.push(h);h=c}}a.push(h)}return a};
BamFile.prototype.fetch=function(a,b,c,e){function d(){if(j>=g.length)return e(i);else if(r){var q=new Uint8Array(r);f.readBamRecords(q,g[j].minv.offset,i,b,c,h);r=null;++j;return d()}else{var m=g[j];q=m.minv.block;f.data.slice(q,m.maxv.block+65536-q).fetch(function(p){r=unbgzf(p,m.maxv.block-m.minv.block+1);return d()})}}var f=this,h=this.chrToIndex[a],g;if(h===undefined)g=[];else(g=this.blocksForRange(h,b,c))||e(null,"Error in index fetch");var i=[],j=0,r;d()};
var SEQRET_DECODER=["=","A","C","x","G","x","x","x","T","x","x","x","x","x","x","N"],CIGAR_DECODER=["M","I","D","N","S","H","P","=","X","?","?","?","?","?","?","?"];function BamRecord(){}
BamFile.prototype.readBamRecords=function(a,b,c,e,d,f){for(;;){var h=readInt(a,b);h=b+h+4;if(h>=a.length)return c;var g=new BamRecord,i=readInt(a,b+4),j=readInt(a,b+8),r=readInt(a,b+12),q=(r&65280)>>8,m=r&255,p=readInt(a,b+16)&65535;r=readInt(a,b+20);readInt(a,b+24);readInt(a,b+28);readInt(a,b+32);for(var o="",s=0;s<m-1;++s)o+=String.fromCharCode(a[b+36+s]);b=b+36+m;s="";for(m=0;m<p;++m){var u=readInt(a,b);s=s+(u>>4)+CIGAR_DECODER[u&15];b+=4}g.cigar=s;p="";m=r+1>>1;for(s=0;s<m;++s){u=a[b+s];p+=SEQRET_DECODER[(u&
240)>>4];p+=SEQRET_DECODER[u&15]}b+=m;g.seq=p;p="";for(s=0;s<r;++s)p+=String.fromCharCode(a[b+s]);b+=r;g.quals=p;g.pos=j;g.mq=q;g.readName=o;for(g.segment=this.indexToChr[i];b<h;){j=String.fromCharCode(a[b])+String.fromCharCode(a[b+1]);q=String.fromCharCode(a[b+2]);if(q=="A"){q=String.fromCharCode(a[b+3]);b+=4}else if(q=="i"||q=="I"){q=readInt(a,b+3);b+=7}else if(q=="c"||q=="C"){q=a[b+3];b+=4}else if(q=="s"||q=="S"){q=readShort(a,b+3);b+=5}else if(q=="f")throw"FIXME need floats";else if(q=="Z"){b+=
3;for(q="";;){o=a[b++];if(o==0)break;else q+=String.fromCharCode(o)}}else throw"Unknown type "+q;g[j]=q}if(!e||g.pos<=d&&g.pos+r>=e)if(f===undefined||i==f)c.push(g);b=h}};function readInt(a,b){return a[b+3]<<24|a[b+2]<<16|a[b+1]<<8|a[b]}function readShort(a,b){return a[b+1]<<8|a[b]}function readVob(a,b){var c=(a[b+6]&255)*4294967296+(a[b+5]&255)*16777216+(a[b+4]&255)*65536+(a[b+3]&255)*256+(a[b+2]&255),e=a[b+1]<<8|a[b];return c==0&&e==0?null:new Vob(c,e)}
function unbgzf(a,b){b=Math.min(b||1,a.byteLength-100);for(var c=[],e=[0],d=0;e[0]<b;){var f=new Uint8Array(a,e[0],100);f=f[11]<<8|f[10];f=jszlib_inflate_buffer(a,12+f+e[0],Math.min(65536,a.byteLength-12-f-e[0]),e);e[0]+=8;d+=f.byteLength;c.push(f)}if(c.length==1)return c[0];else{e=new Uint8Array(d);for(f=d=0;f<c.length;++f){var h=new Uint8Array(c[f]);arrayCopy(h,0,e,d,h.length);d+=h.length}return e.buffer}}
function reg2bin(a,b){--b;if(a>>14==b>>14)return 4681+(a>>14);if(a>>17==b>>17)return 585+(a>>17);if(a>>20==b>>20)return 73+(a>>20);if(a>>23==b>>23)return 9+(a>>23);if(a>>26==b>>26)return 1+(a>>26);return 0}var MAX_BIN=37449;
function reg2bins(a,b){var c,e=[];--b;e.push(0);for(c=1+(a>>26);c<=1+(b>>26);++c)e.push(c);for(c=9+(a>>23);c<=9+(b>>23);++c)e.push(c);for(c=73+(a>>20);c<=73+(b>>20);++c)e.push(c);for(c=585+(a>>17);c<=585+(b>>17);++c)e.push(c);for(c=4681+(a>>14);c<=4681+(b>>14);++c)e.push(c);return e}var BIG_WIG_MAGIC=-2003829722,BIG_BED_MAGIC=-2021002517,BIG_WIG_TYPE_GRAPH=1,BIG_WIG_TYPE_VSTEP=2,BIG_WIG_TYPE_FSTEP=3;function BigWig(){}
BigWig.prototype.readChromTree=function(a){var b=this;this.chromsToIDs={};this.idsToChroms={};for(var c=this.unzoomedDataOffset;c%4!=0;)++c;this.data.slice(this.chromTreeOffset,c-this.chromTreeOffset).fetch(function(e){var d=new Uint8Array(e),f=new Int16Array(e),h=new Int32Array(e),g=h[2],i=function(j){var r=d[j],q=f[j/2+1];j+=4;for(var m=0;m<q;++m)if(r==0){j+=g;var p=h[j/4]<<32|h[j/4+1];j+=8;p-=b.chromTreeOffset;i(p)}else{p="";for(var o=0;o<g;++o){var s=d[j++];if(s!=0)p+=String.fromCharCode(s)}o=
d[j+3]<<24|d[j+2]<<16|d[j+1]<<8|d[j+0];j+=8;b.chromsToIDs[p]=o;if(p.indexOf("chr")==0)b.chromsToIDs[p.substr(3)]=o;b.idsToChroms[o]=p}};i(32);a(b)})};function BigWigView(a,b,c,e){this.bwg=a;this.cirTreeOffset=b;this.cirTreeLength=c;this.isSummary=e}BigWigView.prototype.readWigData=function(a,b,c,e){a=this.bwg.chromsToIDs[a];if(a===undefined)return e([]);else this.readWigDataById(a,b,c,e)};
BigWigView.prototype.readWigDataById=function(a,b,c,e){var d=this;if(this.cirHeader){var f=[],h=0;Date.now();var g=function(r,q){h+=r.length;for(var m=4+d.cirBlockSize*32,p,o=0;o<r.length;++o){var s=new Range(r[o],Math.min(r[o]+m,d.cirTreeOffset+d.cirTreeLength));p=p?union(p,s):s}m=p.ranges();for(p=0;p<m.length;++p)i(r,m[p],q)},i=function(r,q,m){q.max();q.min();d.bwg.data.slice(q.min(),q.max()-q.min()).fetch(function(p){for(var o=0;o<r.length;++o)if(q.contains(r[o])){var s=p,u=r[o]-q.min(),v=m,t=
new Int8Array(s),y=new Int16Array(s);s=new Int32Array(s);t=t[u];y=y[u/2+1];u+=4;if(t!=0)for(t=0;t<y;++t){var A=u/4,D=s[A],G=s[A+1],w=s[A+2],B=s[A+3],C=s[A+4]<<32|s[A+5];v=s[A+6]<<32|s[A+7];if((D<a||D==a&&G<=c)&&(w>a||w==a&&B>=b))f.push({offset:C,size:v});u+=32}else{var z=[];for(t=0;t<y;++t){A=u/4;D=s[A];G=s[A+1];w=s[A+2];B=s[A+3];C=s[A+4]<<32|s[A+5];if((D<a||D==a&&G<=c)&&(w>a||w==a&&B>=b))z.push(C);u+=24}z.length>0&&g(z,v+1)}--h;h==0&&j()}})},j=function(){f.sort(function(o,s){return(o.offset|0)-(s.offset|
0)});if(f.length==0)e([]);else{var r=[],q=function(o,s,u){u||(u={});var v=new DASFeature;v.segment=d.bwg.idsToChroms[a];v.min=o;v.max=s;v.type="bigwig";for(k in u)v[k]=u[k];r.push(v)},m=function(o,s,u){o<=c&&s>=b&&q(o,s,u)},p=function(){if(f.length==0){Date.now();e(r)}else{var o=f[0];if(o.data){var s=new Uint8Array(o.data);if(d.isSummary){var u=new Int16Array(o.data),v=new Int32Array(o.data),t=new Float32Array(o.data);s=o.data.byteLength/32;for(u=0;u<s;++u){var y=v[u*8];o=v[u*8+1];var A=v[u*8+2],
D=v[u*8+3],G=t[u*8+6];if(y==a){y={type:"bigwig",score:G/D};if(d.bwg.type=="bigbed")y.type="density";m(o,A,y)}}}else if(d.bwg.type=="bigwig"){u=new Int16Array(o.data);v=new Int32Array(o.data);t=new Float32Array(o.data);y=v[0];o=v[1];y=v[3];A=v[4];D=s[20];s=u[11];if(D==BIG_WIG_TYPE_FSTEP)for(u=0;u<s;++u){D=t[u+6];m(o+u*y,o+u*y+A,{score:D})}else if(D==BIG_WIG_TYPE_VSTEP)for(u=0;u<s;++u){o=v[u*2+6];D=t[u*2+7];m(o,o+A,{score:D})}else if(D==BIG_WIG_TYPE_GRAPH)for(u=0;u<s;++u){o=v[u*3+6];A=v[u*3+7];D=t[u*
3+8];m(o,A,{score:D})}else dlog("Currently not handling bwgType="+D)}else if(d.bwg.type=="bigbed")for(v=0;v<s.length;){y=s[v+3]<<24|s[v+2]<<16|s[v+1]<<8|s[v+0];o=s[v+7]<<24|s[v+6]<<16|s[v+5]<<8|s[v+4];A=s[v+11]<<24|s[v+10]<<16|s[v+9]<<8|s[v+8];v+=12;for(u="";;){t=s[v++];if(t!=0)u+=String.fromCharCode(t);else break}t={};var w=u.split("\t");if(w.length>0)t.label=w[0];if(w.length>1)t.score=100;if(w.length>2)t.orientation=w[2];if(w.length<9)y==a&&m(o+1,A,t);else if(y==a&&o<=c&&A>=b){A=w[3]|0;y=w[4]|0;
u=w[6]|0;D=w[7].split(",");G=w[8].split(",");t.type="bb-transcript";var B=new DASGroup;B.id=w[0];B.type="bb-transcript";B.notes=[];t.groups=[B];if(w.length>10){B=w[9];w=w[10];var C=new DASGroup;C.id=B;C.label=w;C.type="gene";t.groups.push(C)}w=null;for(B=0;B<u;++B){C=(G[B]|0)+o;C=new Range(C,C+(D[B]|0));w=w?union(w,C):C}D=w.ranges();for(o=0;o<D.length;++o){u=D[o];q(u.min()+1,u.max(),t)}if(o=intersection(w,new Range(A,y))){t.type="bb-translation";A=o.ranges();for(o=0;o<A.length;++o){u=A[o];q(u.min()+
1,u.max(),t)}}}}else dlog("Don't know what to do with "+d.bwg.type);f.splice(0,1);p()}else{s=o.offset;var z=o.size;for(o=1;o<f.length&&f[o].offset==s+z;){z+=f[o].size;++o}d.bwg.data.slice(s,z).fetch(function(Q){for(var S=0,O=0;S<z;){var F=f[O],J;if(d.bwg.uncompressBufSize>0)J=jszlib_inflate_buffer(Q,S+2,F.size-2);else{J=new Uint8Array(F.size);arrayCopy(new Uint8Array(Q,S,F.size),0,J,0,F.size);J=J.buffer}F.data=J;S+=F.size;++O}p()})}}};p()}};g([d.cirTreeOffset+48],1)}else this.bwg.data.slice(this.cirTreeOffset,
48).fetch(function(r){d.cirHeader=r;r=new Int32Array(d.cirHeader);d.cirBlockSize=r[1];d.readWigDataById(a,b,c,e)})};BigWig.prototype.readWigData=function(a,b,c,e){this.getUnzoomedView().readWigData(a,b,c,e)};BigWig.prototype.getUnzoomedView=function(){if(!this.unzoomedView)this.unzoomedView=new BigWigView(this,this.unzoomedIndexOffset,this.zoomLevels[0].dataOffset-this.unzoomedIndexOffset,false);return this.unzoomedView};
BigWig.prototype.getZoomedView=function(a){var b=this.zoomLevels[a];if(!b.view)b.view=new BigWigView(this,b.indexOffset,this.zoomLevels[a+1].dataOffset-b.indexOffset,true);return b.view};function makeBwgFromURL(a,b,c){makeBwg(new URLFetchable(a,{credentials:c}),b,a)}function makeBwgFromFile(a,b){makeBwg(new BlobFetchable(a),b,"file")}
function makeBwg(a,b,c){var e=new BigWig;e.data=a;e.name=c;e.data.slice(0,512).fetch(function(d){if(!d)return b(null,"Couldn't fetch file");var f=new Int16Array(d);d=new Int32Array(d);if(d[0]==BIG_WIG_MAGIC)e.type="bigwig";else if(d[0]==BIG_BED_MAGIC)e.type="bigbed";else b(null,"Not a supported format");e.version=f[2];e.numZoomLevels=f[3];e.chromTreeOffset=d[2]<<32|d[3];e.unzoomedDataOffset=d[4]<<32|d[5];e.unzoomedIndexOffset=d[6]<<32|d[7];e.fieldCount=f[16];e.definedFieldCount=f[17];e.asOffset=d[9]<<
32|d[10];e.totalSummaryOffset=d[11]<<32|d[12];e.uncompressBufSize=d[13];e.zoomLevels=[];for(f=0;f<e.numZoomLevels;++f)e.zoomLevels.push({reduction:d[f*6+16],dataOffset:d[f*6+18]<<32|d[f*6+19],indexOffset:d[f*6+20]<<32|d[f*6+21]});e.readChromTree(function(){return b(e)})})}function BlobFetchable(a){this.blob=a}BlobFetchable.prototype.slice=function(a,b){var c;c=b?this.blob.slice(a,b):this.blob.slice(a);return new BlobFetchable(c)};
BlobFetchable.prototype.fetch=function(a){var b=new FileReader;b.onloadend=function(){a(bstringToBuffer(b.result))};b.readAsBinaryString(this.blob)};function URLFetchable(a,b,c,e){if(!e)if(typeof b==="object"){e=b;b=undefined}else e={};this.url=a;this.start=b||0;if(c)this.end=c;this.opts=e}URLFetchable.prototype.slice=function(a,b){var c=this.start,e=this.end;c=c&&a?c+a:a||c;e=b&&c?c+b-1:e||b-1;return new URLFetchable(this.url,c,e,this.opts)};
URLFetchable.prototype.fetch=function(a,b,c){var e=this;b=b||1;if(b>3)return a(null);var d=new XMLHttpRequest,f;d.open("GET",this.url,true);d.overrideMimeType("text/plain; charset=x-user-defined");if(this.end){d.setRequestHeader("Range","bytes="+this.start+"-"+this.end);f=this.end-this.start+1}d.responseType="arraybuffer";d.onreadystatechange=function(){if(d.readyState==4)if(d.status==200||d.status==206)if(d.response)return a(d.response);else if(d.mozResponseArrayBuffer)return a(d.mozResponseArrayBuffer);
else{var h=d.responseText;return f&&f!=h.length&&(!c||h.length!=c)?e.fetch(a,b+1,h.length):a(bstringToBuffer(d.responseText))}else return e.fetch(a,b+1)};if(this.opts.credentials)d.withCredentials=true;d.send("")};function bstringToBuffer(a){if(!a)return null;for(var b=new Uint8Array(a.length),c=0;c<b.length;++c)b[c]=a.charCodeAt(c);return b.buffer}var NS_SVG="http://www.w3.org/2000/svg",NS_HTML="http://www.w3.org/1999/xhtml",NS_XLINK="http://www.w3.org/1999/xlink";MAX_VIEW_SIZE=5E5;
function Browser(a){a||(a={});this.sources=[];this.tiers=[];this.cookieKey="browser";this.karyoEndpoint=new DASSource("http://www.derkholm.net:8080/das/hsa_54_36p/");this.registry="http://www.dasregistry.org/das/sources";this.coordSystem={speciesName:"Human",taxon:9606,auth:"NCBI",version:"36"};this.chains={};this.exportServer="http://www.biodalliance.org:8765/";this.pageName="svgHolder";this.maxExtra=1.5;this.minExtra=0.2;this.zoomFactor=1;this.origin=0;this.targetQuantRes=5;this.featurePanelWidth=
750;this.zoomBase=100;this.zoomExpt=30;this.entryPoints=null;this.currentSeqMax=-1;this.highlight=false;this.highlightMax=this.highlightMin=-1;this.autoSizeTiers=false;this.guidelineStyle="foreground";this.guidelineSpacing=75;this.fgGuide=null;this.positionFeedback=false;this.placards=[];this.tierBackgroundColors=["rgb(245,245,245)","rgb(230,230,250)"];this.minTierHeight=25;this.tabMargin=120;this.browserLinks={Ensembl:"http://ncbi36.ensembl.org/Homo_sapiens/Location/View?r=${chr}:${start}-${end}",
UCSC:"http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr${chr}:${start}-${end}"};this.iconsURI="http://www.biodalliance.org/resources/icons.svg";this.availableSources=new Observed;this.defaultSources=[];this.mappableSources={};for(var b in a)this[b]=a[b];var c=this;window.addEventListener("load",function(){c.realInit()},false)}
function formatQuantLabel(a){a=""+a;var b=a.indexOf(".");if(b<0)return a;else{var c=2;a.substring(0,1)=="-"&&++c;return b>=c?a.substring(0,b):a.substring(0,b+2)}}
Browser.prototype.labelForTier=function(a,b,c){var e=this.tabMargin,d=document.createElementNS(NS_SVG,"path");d.setAttribute("d","M 15 2 L 10 7 L 10 18 L 15 22 L "+(10+e)+" 22 L "+(10+e)+" 2 Z");d.setAttribute("fill",this.tierBackgroundColors[b%this.tierBackgroundColors.length]);d.setAttribute("stroke","none");c.appendChild(d);this.setupTierDrag(d,b);e=false;if(a.dasSource.collapseSuperGroups||a.hasBumpedFeatures){e=true;this.makeToggleButton(c,a,0)}if(a.isQuantitative){e=true;d=makeElementNS(NS_SVG,
"g");d.appendChild(makeElementNS(NS_SVG,"rect",null,{x:this.tabMargin-25,y:0,width:25,height:a.layoutHeight,stroke:"none",fill:this.tierBackgroundColors[b%this.tierBackgroundColors.length]}));c.appendChild(d);d.appendChild(makeElementNS(NS_SVG,"line",null,{x1:this.tabMargin,y1:0+(a.clientMin|0),x2:this.tabMargin,y2:0+(a.clientMax|0),strokeWidth:1}));d.appendChild(makeElementNS(NS_SVG,"line",null,{x1:this.tabMargin-5,y1:0+(a.clientMin|0),x2:this.tabMargin,y2:0+(a.clientMin|0),strokeWidth:1}));d.appendChild(makeElementNS(NS_SVG,
"line",null,{x1:this.tabMargin-3,y1:0+((a.clientMin|0)+(a.clientMax|0))/2,x2:this.tabMargin,y2:0+((a.clientMin|0)+(a.clientMax|0))/2,strokeWidth:1}));d.appendChild(makeElementNS(NS_SVG,"line",null,{x1:this.tabMargin-5,y1:0+(a.clientMax|0),x2:this.tabMargin,y2:0+(a.clientMax|0),strokeWidth:1}));var f=makeElementNS(NS_SVG,"text",formatQuantLabel(a.min),{x:80,y:a.clientMin|0,strokeWidth:0,fill:"black",fontSize:"8pt"});d.appendChild(f);b=f.getBBox();f.setAttribute("x",this.tabMargin-b.width-7);f.setAttribute("y",
(a.clientMin|0)+b.height/2-4);f=makeElementNS(NS_SVG,"text",formatQuantLabel(a.max),{x:80,y:a.clientMax|0,strokeWidth:0,fill:"black",fontSize:"8pt"});d.appendChild(f);f.setAttribute("x",this.tabMargin-f.getBBox().width-3);b=f.getBBox();f.setAttribute("x",this.tabMargin-b.width-7);f.setAttribute("y",(a.clientMax|0)+b.height/2-1);var h=this.icons.createIcon("magnifier",c);h.setAttribute("transform","translate("+(this.tabMargin-18)+", "+(a.layoutHeight/2-8)+"), scale(0.6,0.6)");h.addEventListener("mouseover",
function(){h.setAttribute("fill","red")},false);h.addEventListener("mouseout",function(){h.setAttribute("stroke","gray")},false);d.appendChild(h);this.makeQuantConfigButton(d,a,0);this.makeTooltip(d,"Click to adjust how this data is displayed")}d=this.tabMargin-20;if(e)d-=20;a=a.dasSource.name;e=document.createElementNS(NS_SVG,"text");e.setAttribute("x",15);e.setAttribute("y",17);e.setAttribute("stroke-width",0);e.setAttribute("fill","black");e.appendChild(document.createTextNode(a));e.setAttribute("pointer-events",
"none");for(c.appendChild(e);e.getBBox().width>d;){removeChildren(e);a=a.substring(0,a.length-1);e.appendChild(document.createTextNode(a+"..."))}return c};
Browser.prototype.arrangeTiers=function(){for(var a=this.svgRoot,b=0;b<this.placards.length;++b)a.removeChild(this.placards[b]);this.placards=[];b=this.dasLabelHolder;var c=50;for(ti=0;ti<this.tiers.length;++ti){var e=this.tiers[ti];e.y=c;if(!e.isLabelValid){e.label&&b.removeChild(e.label);e.label=makeElementNS(NS_SVG,"g");b.appendChild(e.label);this.labelForTier(e,ti,e.label)}this.xfrmTier(e,this.tabMargin-1*(this.viewStart-this.origin)*this.scale,-1);if(e.placard){e.placard.setAttribute("transform",
"translate("+this.tabMargin+", "+(c+e.layoutHeight-4)+")");a.appendChild(e.placard);this.placards.push(e.placard)}c+=e.layoutHeight}this.featureBackground.setAttribute("height",(c|0)-50);if(c<150)c=150;if(this.browserFrameHeight!=c){this.svgRoot.setAttribute("height",""+((c|0)+10)+"px");this.svgBackground.setAttribute("height",""+((c|0)+10));this.featureClipRect.setAttribute("height",""+((c|0)-10));this.labelClipRect.setAttribute("height",""+((c|0)-10));this.browserFrameHeight=c}};
Browser.prototype.offsetForTier=function(a){for(var b=50,c=0;c<a;++c)b+=this.tiers[c].layoutHeight;return b};
Browser.prototype.tierInfoPopup=function(a,b){var c,e=[];a.dasSource.desc&&e.push(a.dasSource.desc);var d=this.availableSources.get();if(a.dasSource.mapping){d=this.chains[a.dasSource.mapping].coords;e.push(makeElement("p",makeElement("i","Mapped from "+d.auth+d.version)));d=this.mappableSources[a.dasSource.mapping].get()}if(!d||d==0)c=makeElement("p","Registry data not available");else{for(var f=0;f<d.length;++f){var h=d[f];if(h.uri==a.dasSource.uri&&h.source_uri){c=makeElement("p",makeElement("a",
"Registry entry: "+h.name,{href:"http://www.dasregistry.org/showdetails.jsp?auto_id="+h.source_uri,target:"_new"}));break}}c||(c=makeElement("p","No registry information for this source"))}e.push(c);this.popit(b,a.dasSource.name,e,{width:300})};
Browser.prototype.setupTierDrag=function(a,b){var c=this,e,d,f,h=null,g=this.tiers[b],i=function(p){p=(p.clientY+window.scrollY-e|0)-50;for(var o=0;o<c.tiers.length&&p>c.tiers[o].layoutHeight;){p-=c.tiers[o].layoutHeight;++o}if(o!=f){f=o;d.setAttribute("y",c.offsetForTier(f)-2)}},j=false,r=function(){c.bin.setAttribute("stroke","red");d.setAttribute("fill","none");j=true},q=function(){c.bin.setAttribute("stroke","gray");d.setAttribute("fill","red");j=false},m=function(p){window.removeEventListener("mousemove",
i,true);window.removeEventListener("mouseup",m,true);c.bin.removeEventListener("mouseover",r,true);c.bin.removeEventListener("mouseout",q,true);c.bin.setAttribute("stroke","gray");if(h){clearTimeout(h);h=null;c.tierInfoPopup(g,p)}else{c.popupHolder.removeChild(d);if(j)c.removeTier(c.tiers[b]);else if(f!=b){p=[];var o=0;for(f>b&&--f;p.length<c.tiers.length;)if(p.length==f)p.push(c.tiers[b]);else{o!=b&&p.push(c.tiers[o]);++o}c.tiers=p;if(c.knownSpace)c.knownSpace.tierMap=c.tiers;for(p=0;p<c.tiers.length;++p){c.tiers[p].background.setAttribute("fill",
c.tierBackgroundColors[p%c.tierBackgroundColors.length]);c.tiers[p].isLabelValid=false}c.arrangeTiers();c.storeStatus()}}};a.addEventListener("mousedown",function(p){c.removeAllPopups();p.stopPropagation();p.preventDefault();e=c.svgHolder.getBoundingClientRect().top+window.scrollY;window.addEventListener("mousemove",i,true);window.addEventListener("mouseup",m,true);c.bin.addEventListener("mouseover",r,true);c.bin.addEventListener("mouseout",q,true);f=b;d=makeElementNS(NS_SVG,"rect",null,{x:c.tabMargin,
y:c.offsetForTier(f)-2,width:c.featurePanelWidth,height:4,fill:"red",stroke:"none"});h=setTimeout(function(){h=null;c.popupHolder.appendChild(d)},200)},true)};
Browser.prototype.makeToggleButton=function(a,b,c){var e=makeElementNS(NS_SVG,"g",null,{fill:"cornsilk",strokeWidth:1,stroke:"gray"});e.appendChild(makeElementNS(NS_SVG,"rect",null,{x:this.tabMargin-15,y:c+8,width:8,height:8}));e.appendChild(makeElementNS(NS_SVG,"line",null,{x1:this.tabMargin-15,y1:c+12,x2:this.tabMargin-7,y2:c+12}));b.bumped||e.appendChild(makeElementNS(NS_SVG,"line",null,{x1:this.tabMargin-11,y1:c+8,x2:this.tabMargin-11,y2:c+16}));a.appendChild(e);e.addEventListener("mouseover",
function(){e.setAttribute("stroke","red")},false);e.addEventListener("mouseout",function(){e.setAttribute("stroke","gray")},false);e.addEventListener("mousedown",function(){b.bumped=!b.bumped;b.layoutWasDone=false;b.isLabelValid=false;b.draw()},false);this.makeTooltip(e,"Click to "+(b.bumped?"collapse":"expand"))};Browser.prototype.updateRegion=function(){if(!this.updateRegionBaton){var a=this;this.updateRegionBaton=setTimeout(function(){a.updateRegionBaton=null;a.realUpdateRegion()},25)}};
Browser.prototype.realUpdateRegion=function(){var a=this.chr;if(a.indexOf("chr")<0)a="chr"+a;var b=a+":"+(this.viewStart|0)+".."+(this.viewEnd|0);removeChildren(this.regionLabel);this.regionLabel.appendChild(document.createTextNode(b));b=this.regionLabel.getBBox();b=b.x+b.width;if(this.regionLabelMax&&b>this.regionLabelMax){removeChildren(this.regionLabel);this.regionLabel.appendChild(document.createTextNode(a))}};
Browser.prototype.refresh=function(){var a=this.viewEnd-this.viewStart+1,b=a*this.minExtra|0;a=a*this.maxExtra|0;var c=(this.viewStart+this.viewEnd)/2,e=c-this.origin;this.origin=c;this.scaleAtLastRedraw=this.scale;for(c=0;c<this.tiers.length;++c){var d=e;if(this.tiers[c].originHaxx)d+=this.tiers[c].originHaxx;this.tiers[c].originHaxx=d}e=this.targetQuantRes/this.scale;c=Math.max(1,(this.viewStart|0)-b);b=Math.min((this.viewEnd|0)+b,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9);d=Math.max(1,
(this.viewStart|0)-a);a=Math.min((this.viewEnd|0)+a,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9);if(!this.knownSpace||this.knownSpace.chr!==this.chr){for(var f=null,h=0;h<this.tiers.length;++h)if(this.tiers[h].sequenceSource){f=this.tiers[h].sequenceSource;break}this.knownSpace=new KnownSpace(this.tiers,this.chr,d,a,e,f)}if((f=this.knownSpace.bestCacheOverlapping(this.chr,c,b))&&f.min<=c&&f.max>=b){this.drawnStart=Math.max(f.min,d);this.drawnEnd=Math.min(f.max,a)}else{this.drawnStart=d;this.drawnEnd=
a}this.knownSpace.viewFeatures(this.chr,this.drawnStart,this.drawnEnd,e)};
Browser.prototype.mouseDownHandler=function(a){var b=this;this.removeAllPopups();a.stopPropagation();a.preventDefault();for(var c=document.elementFromPoint(a.clientX,a.clientY);c&&!c.dalliance_feature&&!c.dalliance_group;)c=c.parentNode;if(c&&(c.dalliance_feature||c.dalliance_group))if(this.dcTimeoutID&&c.dalliance_feature){var e=c.dalliance_feature,d=this.svgHolder.getBoundingClientRect();d=((e.min|0)-(this.viewStart|0))*this.scale+d.left+this.tabMargin;var f=(e.max-e.min+1)*this.scale;clearTimeout(this.dcTimeoutID);
this.dcTimeoutID=null;e=((c.dalliance_feature.min|0)+(c.dalliance_feature.max|0))/2;if(f>10){d=1*(a.clientX-d)/f;if(d<0.3)e=c.dalliance_feature.min|0;else if(d>0.7)e=(c.dalliance_feature.max|0)+1}d=this.viewEnd-this.viewStart;this.setLocation(e-d/2,e+d/2);e=this.featurePanelWidth-(d+1)*this.scale;Math.abs(e)>1&&this.move(e/2)}else this.dcTimeoutID=setTimeout(function(){b.dcTimeoutID=null;b.featurePopup(a,c.dalliance_feature,c.dalliance_group)},200);else{this.originX=a.clientX;document.addEventListener("mousemove",
this.__mouseMoveHandler,true);document.addEventListener("mouseup",this.__mouseUpHandler,true);this.clickTestTB=setTimeout(function(){b.clickTestTB=null},200)}};var TAGVAL_NOTE_RE=/^([A-Za-z]+)=(.+)/;
Browser.prototype.featurePopup=function(a,b,c){b||(b={});c||(c={});this.removeAllPopups();var e=makeElement("table",null);e.style.width="100%";var d=pick(c.type,b.type),f=pick(c.label,b.label,c.id,b.id);if(f&&f.indexOf("__dazzle")!=0)d=d+": "+f;f=0;if(b.method){var h=makeElement("tr",[makeElement("th","Method"),makeElement("td",b.method)]);h.style.backgroundColor=this.tierBackgroundColors[f%this.tierBackgroundColors.length];e.appendChild(h);++f}h=c.segment?c:b;h=makeElement("tr",[makeElement("th",
"Location"),makeElement("td",h.segment+":"+h.min+"-"+h.max)]);h.style.backgroundColor=this.tierBackgroundColors[f%this.tierBackgroundColors.length];e.appendChild(h);++f;if(b.score!==undefined&&b.score!==null&&b.score!="-"){h=makeElement("tr",[makeElement("th","Score"),makeElement("td",""+b.score)]);h.style.backgroundColor=this.tierBackgroundColors[f%this.tierBackgroundColors.length];e.appendChild(h);++f}if((h=maybeConcat(c.links,b.links))&&h.length>0){h=makeElement("tr",[makeElement("th","Links"),
makeElement("td",h.map(function(j){return makeElement("div",makeElement("a",j.desc,{href:j.uri,target:"_new"}))}))]);h.style.backgroundColor=this.tierBackgroundColors[f%this.tierBackgroundColors.length];e.appendChild(h);++f}b=maybeConcat(c.notes,b.notes);for(c=0;c<b.length;++c){h="Note";var g=b[c],i=g.match(TAGVAL_NOTE_RE);if(i){h=i[1];g=i[2]}h=makeElement("tr",[makeElement("th",h),makeElement("td",g)]);h.style.backgroundColor=this.tierBackgroundColors[f%this.tierBackgroundColors.length];e.appendChild(h);
++f}this.popit(a,d,e,{width:400})};
Browser.prototype.mouseUpHandler=function(a){var b=this;if(this.clickTestTB&&this.positionFeedback){var c=svgHolder.getBoundingClientRect(),e=makeElement("div",""+(1*(a.clientX-c.left-this.tabMargin)/this.scale+this.viewStart|0),{},{position:"absolute",top:""+(a.clientY+window.scrollY+20)+"px",left:""+Math.max(a.clientX+window.scrollX-30,20)+"px",backgroundColor:"rgb(250, 240, 220)",borderWidth:"1px",borderColor:"black",borderStyle:"solid",padding:"2px",maxWidth:"400px"});this.hPopupHolder.appendChild(e);
var d;d=function(){try{b.hPopupHolder.removeChild(e)}catch(f){}window.removeEventListener("mousemove",d,false)};window.addEventListener("mousemove",d,false)}a.stopPropagation();a.preventDefault();document.removeEventListener("mousemove",this.__mouseMoveHandler,true);document.removeEventListener("mouseup",this.__mouseUpHandler,true);this.storeStatus()};
Browser.prototype.mouseMoveHandler=function(a){a.stopPropagation();a.preventDefault();if(a.clientX!=this.originX){this.move(a.clientX-this.originX);this.originX=a.clientX}};Browser.prototype.removeAllPopups=function(){removeChildren(this.popupHolder);removeChildren(this.hPopupHolder)};function EPMenuItem(a){this.entryPoint=a;this.nums=stringToNumbersArray(a.name)}
Browser.prototype.makeHighlight=function(){if(this.highlight){this.dasTierHolder.removeChild(this.highlight);this.highlight=null}if(this.highlightMin>0){this.highlight=document.createElementNS(NS_SVG,"rect");this.highlight.setAttribute("x",(this.highlightMin-this.origin)*this.scale);this.highlight.setAttribute("y",0);this.highlight.setAttribute("width",(this.highlightMax-this.highlightMin+1)*this.scale);this.highlight.setAttribute("height",1E4);this.highlight.setAttribute("stroke","none");this.highlight.setAttribute("fill",
"red");this.highlight.setAttribute("fill-opacity",0.15);this.highlight.setAttribute("pointer-events","none");this.dasTierHolder.appendChild(this.highlight)}};Browser.prototype.init=function(){};
Browser.prototype.realInit=function(a){a||(a={});this.supportsBinary=typeof Int8Array==="function";var b=this;this.defaultSources=[];for(var c=0;c<this.sources.length;++c)this.defaultSources.push(this.sources[c]);this.defaultChr=this.chr;this.defaultStart=this.viewStart;this.defaultEnd=this.viewEnd;this.icons=new IconSet(this.iconsURI);var e,d=false,f=a=null,h=null;c={};if(location.search){d=location.search.substring(1).split(/[&;]/);for(var g=0;g<d.length;++g){var i=d[g].split("="),j=decodeURIComponent(i[0]),
r=null;if(i.length>1)r=decodeURIComponent(i[1]);c[j]=r}d=c.reset}g=(g=localStorage["dalliance."+this.cookieKey+".version"])?g|0:-100;if(VERSION.CONFIG!=g)d=true;g=localStorage["dalliance."+this.cookieKey+".configHash"]||"";i=hex_sha1(miniJSONify(this.sources));if(i!=g){d=true;localStorage["dalliance."+this.cookieKey+".configHash"]=i}if(this.cookieKey&&localStorage["dalliance."+this.cookieKey+".view-chr"]&&!d){a=localStorage["dalliance."+this.cookieKey+".view-chr"];f=localStorage["dalliance."+this.cookieKey+
".view-start"]|0;h=localStorage["dalliance."+this.cookieKey+".view-end"]|0}if(this.cookieKey)if((g=localStorage["dalliance."+this.cookieKey+".sources"])&&!d)e=JSON.parse(g);d=/([\d+,\w,\.,\_,\-]+):(\d+)[\-,\,](\d+)/;g=false;if(c.chr){a=c.chr;f=c.min;h=c.max;g=true}this.positionFeedback=c.positionFeedback||false;guidelineConfig=c.guidelines||"foreground";if(guidelineConfig=="true")this.guidelineStyle="background";else if(STRICT_NUM_REGEXP.test(guidelineConfig)){this.guidelineStyle="background";this.guidelineSpacing=
guidelineConfig|0}else this.guidelineStyle=guidelineConfig;if(!g){(regstr=c.r)||(regstr=c.segment||"");g=regstr.match(d);if(regstr!=""&&g){a=g[1];f=g[2]|0;h=g[3]|0}g=true}if(h<f)h=f+1E4;if(g=(c.h||"").match(d)){this.highlightMin=g[2]|0;this.highlightMax=g[3]|0}this.svgHolder=document.getElementById(this.pageName);this.svgRoot=makeElementNS(NS_SVG,"svg",null,{version:"1.1",width:"860px",height:"500px",id:"browser_svg"});removeChildren(this.svgHolder);this.svgHolder.appendChild(this.svgRoot);d="";for(c=
-90;c<=90;c+=20){d=d+"M "+(Math.max(0,c)-2)+" "+(Math.max(-c,0)-2)+" L "+(Math.min(100+c,100)+2)+" "+(Math.min(100-c,100)+2)+" ";d=d+"M "+Math.max(c,0)+" "+Math.min(c+100,100)+" L "+Math.min(c+100,100)+" "+Math.max(c,0)+" "}c=makeElementNS(NS_SVG,"pattern",makeElementNS(NS_SVG,"path",null,{stroke:"lightgray",strokeWidth:2,d:d}),{id:"bgpattern-"+this.pageName,x:0,y:0,width:100,height:100});c.setAttribute("patternUnits","userSpaceOnUse");this.svgRoot.appendChild(c);this.svgBackground=makeElementNS(NS_SVG,
"rect",null,{id:"background",fill:"white"});c=makeElementNS(NS_SVG,"g",this.svgBackground,{fillOpacity:1,stroke:"black",strokeWidth:"0.1cm",fontFamily:"helvetica",fontSize:"10pt"});this.svgRoot.appendChild(c);this.regionLabel=makeElementNS(NS_SVG,"text","chr???",{x:260,y:30,strokeWidth:0});c.appendChild(this.regionLabel);this.makeTooltip(this.regionLabel,"Click to jump to a new location or gene");d=this.icons.createButton("add-track",c,30,30);d.setAttribute("transform","translate(100, 10)");this.makeTooltip(d,
"Add tracks from the DAS registry");c.appendChild(d);g=this.icons.createButton("link",c,30,30);g.setAttribute("transform","translate(140, 10)");this.makeTooltip(g,"Follow links to other genome browsers");c.appendChild(g);i=this.icons.createButton("reset",c,30,30);i.setAttribute("transform","translate(180, 10)");this.makeTooltip(i,"Reset the browser to a default state");c.appendChild(i);j=this.icons.createButton("export",c,30,30);j.setAttribute("transform","translate(220, 10)");this.makeTooltip(j,
"Export the current genome display as a vector graphics file");c.appendChild(j);var q;j.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();var B=q&&q.displayed;b.removeAllPopups();if(!B){B=document.implementation.createDocument(NS_SVG,"svg",null);var C=b.svgRoot.getAttribute("width")|0;B.documentElement.setAttribute("width",C);B.documentElement.setAttribute("height",b.svgRoot.getAttribute("height"));var z=makeElementNS(NS_SVG,"g",null,{fontFamily:"helvetica"});B.documentElement.appendChild(z);
var Q=makeElementNS(NS_SVG,"text","Graphics from Dalliance "+VERSION,{x:80,y:30,strokeWidth:0,fill:"black",fontSize:"12pt"});b.svgRoot.appendChild(Q);var S=Q.getBBox().width;b.svgRoot.removeChild(Q);Q.setAttribute("x",C-S-60);z.appendChild(Q);C=b.chr;if(C.indexOf("chr")<0)C="chr"+C;z.appendChild(makeElementNS(NS_SVG,"text",C+":"+(b.viewStart|0)+".."+(b.viewEnd|0),{x:40,y:30,strokeWidth:0,fill:"black",fontSize:"12pt"}));z.appendChild(p.cloneNode(true));z.appendChild(b.dasLabelHolder.cloneNode(true));
z.appendChild(m.cloneNode(true));z.appendChild(b.dasTierHolder.cloneNode(true));z=makeElement("input",null,{type:"radio",name:"format",value:"svg",checked:true});C=makeElement("input",null,{type:"radio",name:"format",value:"pdf"});var O=makeElement("form",[makeElement("p","To work around restrictions on saving files from web applications, image export currently requires transmission of the browser's current state to a remote server. Depending on connection speed, this can take a few seconds -- please be patient."),
makeElement("p","The download links only work once, so if you wish to keep or share your exported images, please save a copy on your computer"),z,"SVG",makeElement("br"),C,"PDF",makeElement("br"),makeElement("br"),makeElement("input",null,{type:"hidden",name:"svgdata",value:(new XMLSerializer).serializeToString(B)}),makeElement("input",null,{type:"submit"})],{action:b.exportServer+"browser-image.svg",method:"POST"});z.addEventListener("click",function(){O.setAttribute("action",b.exportServer+"browser-image.svg")},
false);C.addEventListener("click",function(){O.setAttribute("action",b.exportServer+"browser-image.pdf")},false);O.addEventListener("submit",function(){setTimeout(function(){b.removeAllPopups()},200);return true},false);q=b.popit(w,"Export",O,{width:400})}},false);this.bin=this.icons.createIcon("bin",c);this.bin.setAttribute("transform","translate(10, 18)");c.appendChild(this.bin);this.makeTooltip(this.bin,"Drag tracks here to discard");this.featureClipRect=makeElementNS(NS_SVG,"rect",null,{x:this.tabMargin,
y:50,width:850-this.tabMargin,height:440});var m=makeElementNS(NS_SVG,"clipPath",this.featureClipRect,{id:"featureClip-"+this.pageName});c.appendChild(m);this.labelClipRect=makeElementNS(NS_SVG,"rect",null,{x:10,y:50,width:this.tabMargin-10,height:440});var p=makeElementNS(NS_SVG,"clipPath",this.labelClipRect,{id:"labelClip-"+this.pageName});c.appendChild(p);this.featureBackground=makeElementNS(NS_SVG,"rect",null,{x:this.tabMargin,y:50,width:850-this.tabMargin,height:440,stroke:"none",fill:"url(#bgpattern-"+
this.pageName+")"});c.appendChild(this.featureBackground);this.dasTierHolder=makeElementNS(NS_SVG,"g",null,{clipPath:"url(#featureClip-"+this.pageName+")"});c.appendChild(this.dasTierHolder);j=makeElementNS(NS_SVG,"g",null,{id:"dasTiers"});this.dasTierHolder.appendChild(j);this.makeHighlight();this.dasLabelHolder=makeElementNS(NS_SVG,"g",makeElementNS(NS_SVG,"g",null,{id:"dasLabels"}),{clipPath:"url(#labelClip-"+this.pageName+")"});c.appendChild(this.dasLabelHolder);r=this.icons.createIcon("magnifier-plus",
c);var o=this.icons.createIcon("magnifier-minus",c);this.zoomTickMarks=makeElementNS(NS_SVG,"g");this.zoomSlider=new DSlider(250);this.zoomSlider.onchange=function(w,B){b.zoom(Math.exp(1*w/b.zoomExpt));if(B){b.invalidateLayouts();b.refresh();b.storeStatus()}};r.setAttribute("transform","translate(0,15)");r.setAttribute("pointer-events","all");r.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();w=b.zoomSlider.getValue();b.zoomSlider.setValue(w-10);var B=b.zoomSlider.getValue();
if(B!=w){b.zoom(Math.exp(1*B/b.zoomExpt));b.scheduleRefresh(500)}},false);this.zoomSlider.svg.setAttribute("transform","translate(30, 0)");o.setAttribute("transform","translate(285,15)");o.setAttribute("pointer-events","all");o.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();w=b.zoomSlider.getValue();b.zoomSlider.setValue(w+10);var B=b.zoomSlider.getValue();if(B!=w){b.zoom(Math.exp(1*B/b.zoomExpt));b.scheduleRefresh(500)}},false);this.zoomWidget=makeElementNS(NS_SVG,
"g",[this.zoomTickMarks,r,this.zoomSlider.svg,o]);this.makeTooltip(this.zoomWidget,"Drag to zoom");c.appendChild(this.zoomWidget);this.karyo=new Karyoscape(this,this.karyoEndpoint);this.karyo.svg.setAttribute("transform","translate(480, 15)");this.karyo.onchange=function(w){var B=b.viewEnd-b.viewStart+1;w=w*b.currentSeqMax-B/2|0;b.setLocation(w,w+B-1)};c.appendChild(this.karyo.svg);this.popupHolder=makeElementNS(NS_SVG,"g");c.appendChild(this.popupHolder);this.hPopupHolder=makeElement("div");this.hPopupHolder.style["font-family"]=
"helvetica";this.hPopupHolder.style["font-size"]="12pt";this.svgHolder.appendChild(this.hPopupHolder);this.bhtmlRoot=makeElement("div");this.disablePoweredBy||this.bhtmlRoot.appendChild(makeElement("span",["Powered by ",makeElement("a","Dalliance",{href:"http://www.biodalliance.org/"})," "+VERSION]));this.svgHolder.appendChild(this.bhtmlRoot);if(this.guidelineStyle=="foreground"){this.fgGuide=document.createElementNS(NS_SVG,"line");this.fgGuide.setAttribute("x1",500);this.fgGuide.setAttribute("y1",
50);this.fgGuide.setAttribute("x2",500);this.fgGuide.setAttribute("y2",1E4);this.fgGuide.setAttribute("stroke","red");this.fgGuide.setAttribute("stroke-width",1);this.fgGuide.setAttribute("pointer-events","none");c.appendChild(this.fgGuide)}var s;g.addEventListener("mousedown",function(w){var B=s&&s.displayed;w.stopPropagation();w.preventDefault();b.removeAllPopups();if(!B){B=makeElement("ul");for(l in b.browserLinks)B.appendChild(makeElement("li",makeElement("a",l,{href:b.browserLinks[l].replace(RegExp("\\${([a-z]+)}",
"g"),function(C,z){return z=="chr"?b.chr:z=="start"?b.viewStart|0:z=="end"?b.viewEnd|0:""}),target:"_new"})));s=b.popit(w,"Follow links to...",B)}},false);var u;this.regionLabel.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();var B=u&&u.displayed;b.removeAllPopups();if(!B)if(b.entryPoints==null)alert("entry_points aren't currently available for this genome");else{B=[];for(var C=0;C<b.entryPoints.length;++C)B.push(new EPMenuItem(b.entryPoints[C]));B=B.sort(function(O,
F){for(var J=O.nums,R=F.nums,L=0;;){if(L>=J.length)return-1;else if(L>=R.length)return 1;else{var P=J[L]-R[L];if(P!=0)return P}++L}});B=makeElement("div");B.style.padding="5px";B.style.paddingRight="9px";C=makeElement("form");C.appendChild(document.createTextNode("Location:"));var z=makeElement("div",null,{},{color:"red"});C.appendChild(z);var Q=makeElement("input",null,{type:"text",value:b.chr+":"+(b.viewStart|0)+".."+(b.viewEnd|0)});C.appendChild(Q);C.appendChild(makeElement("br"));C.appendChild(makeElement("input",
null,{type:"submit",value:"Go"}));B.appendChild(C);u=b.popit(w,"Jump to...",B,{width:300});C.addEventListener("submit",function(O){O.stopPropagation();O.preventDefault();var F=/^([A-Za-z0-9]+)[:\t ]([0-9]+)([-:.\t ]+([0-9]+))?$/.exec(Q.value.trim());if(F&&F.length==5){O=F[1];var J=stringToInt(F[2]);if(F[4])F=stringToInt(F[4]);else{F=b.viewEnd-b.viewStart+1;J=J-F/2|0;F=J+F}if(O!=b.chr){b.highlightMin=-1;b.highlightMax=-1}try{b.setLocation(J,F,O);b.removeAllPopups()}catch(R){removeChildren(z);z.appendChild(document.createTextNode(R))}}else{removeChildren(z);
z.appendChild(document.createTextNode("Should match chr:start...end or chr:midpoint"))}return false},false);if(b.searchEndpoint){w=makeElement("form");w.appendChild(makeElement("p","Or search for..."));w.appendChild(document.createTextNode("Gene:"));var S=makeElement("input",null,{value:""});w.appendChild(S);w.appendChild(makeElement("br"));w.appendChild(makeElement("input",null,{type:"submit",value:"Go"}));B.appendChild(w);w.addEventListener("submit",function(O){O.stopPropagation();O.preventDefault();
var F=S.value;b.removeAllPopups();if(!F||F.length==0)return false;b.searchEndpoint.features(null,{group:F,type:"transcript"},function(J){J||(J=[]);for(var R=5E8,L=-100000000,P=null,x=0;x<J.length;++x){var E=J[x];if(E.label==F){if(P==null)P=E.segment;R=Math.min(R,E.min);L=Math.max(L,E.max)}}if(P){b.highlightMin=R;b.highlightMax=L;b.makeHighlight();J=Math.max(2500,0.3*(L-R+1)|0);b.setLocation(R-J,L+J,P)}else alert("no match for '"+F+"' (NB. server support for search is currently rather limited...)")},
false);return false},false)}}},false);var v;d.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();var B=v&&v.displayed;b.removeAllPopups();B||(v=b.showTrackAdder(w))},false);i.addEventListener("mousedown",function(w){w.stopPropagation();w.preventDefault();removeChildren(b.tierHolder);removeChildren(b.dasLabelHolder);b.tiers=[];b.sources=[];b.knownSpace=null;for(w=0;w<b.defaultSources.length;++w){var B=b.defaultSources[w];b.sources.push(B);b.makeTier(B)}b.arrangeTiers();
b.highlightMin=b.highlightMax=-1;b.setLocation(b.defaultStart,b.defaultEnd,b.defaultChr)},false);this.tierHolder=j;this.tiers=[];if(e)this.sources=e;for(e=0;e<this.sources.length;++e){d=this.sources[e];if(d.bwgURI&&!this.supportsBinary){if(!this.binaryWarningGiven){this.popit({clientX:300,clientY:100},"Warning",makeElement("p","your browser does not support binary data formats, some track(s) not loaded. We currently recommend Google Chrome 9 or later, or Firefox 4 or later."));this.binaryWarningGiven=
true}}else this.makeTier(d)}b.arrangeTiers();this.resizeViewer(true);window.addEventListener("resize",function(){b.resizeViewer()},false);if(a&&f&&h){this.chr=a;this.viewStart=f;this.viewEnd=h;if(this.highlightMin<0){this.highlightMin=f;this.highlightMax=h}}if(this.viewEnd-this.viewStart>MAX_VIEW_SIZE){a=(this.viewEnd+this.viewStart)/2|0;this.viewStart=a-MAX_VIEW_SIZE/2;this.viewEnd=a+MAX_VIEW_SIZE/2-1}this.origin=(this.viewStart+this.viewEnd)/2|0;this.scale=this.featurePanelWidth/(this.viewEnd-this.viewStart);
this.zoomExpt=250/Math.log(MAX_VIEW_SIZE/this.zoomBase);this.zoomSlider.setValue(this.zoomExpt*Math.log((this.viewEnd-this.viewStart+1)/this.zoomBase));this.move(0);this.makeZoomerTicks();this.__mouseMoveHandler=function(w){return b.mouseMoveHandler(w)};this.__mouseUpHandler=function(w){return b.mouseUpHandler(w)};c.addEventListener("mousedown",function(w){return b.mouseDownHandler(w)},false);this.svgRoot.addEventListener("mousewheel",function(w){if(w.wheelDeltaX){w.stopPropagation();w.preventDefault();
b.move(-w.wheelDeltaX/5)}},false);this.svgRoot.addEventListener("MozMousePixelScroll",function(w){if(w.axis==1){w.stopPropagation();w.preventDefault();w.detail!=0&&b.move(w.detail/4)}},false);var t=function(w){if(w.keyCode==13){var B=false;for(w=0;w<b.tiers.length;++w){var C=b.tiers[w];if(C.wantedLayoutHeight&&C.wantedLayoutHeight!=C.layoutHeight){C.layoutHeight=C.wantedLayoutHeight;C.placard=null;C.clipTier();B=true}}B&&b.arrangeTiers()}else if(w.keyCode==32||w.charCode==32){if(!b.snapZoomLockout){if(b.isSnapZooming){b.isSnapZooming=
false;C=b.savedZoom||10;b.savedZoom=b.zoomSlider.getValue();b.zoomSlider.setValue(C);b.zoom(Math.exp(1*C/b.zoomExpt));b.invalidateLayouts();b.zoomSlider.setColor("blue")}else{b.isSnapZooming=true;C=b.savedZoom||1;b.savedZoom=b.zoomSlider.getValue();b.zoomSlider.setValue(C);b.zoom(Math.exp(1*C/b.zoomExpt));b.invalidateLayouts();b.zoomSlider.setColor("red")}b.refresh();b.snapZoomLockout=true}w.stopPropagation();w.preventDefault()}else if(w.keyCode==39){w.stopPropagation();w.preventDefault();b.move(w.shiftKey?
100:25)}else if(w.keyCode==37){w.stopPropagation();w.preventDefault();b.move(w.shiftKey?-100:-25)}else if(w.charCode==61){w.stopPropagation();w.preventDefault();w=b.zoomSlider.getValue();b.zoomSlider.setValue(w-10);C=b.zoomSlider.getValue();if(C!=w){b.zoom(Math.exp(1*C/b.zoomExpt));b.scheduleRefresh(500)}}else if(w.charCode==45){w.stopPropagation();w.preventDefault();w=b.zoomSlider.getValue();b.zoomSlider.setValue(w+10);C=b.zoomSlider.getValue();if(C!=w){b.zoom(Math.exp(1*C/b.zoomExpt));b.scheduleRefresh(500)}}else if(w.keyCode==
84)for(w=0;w<b.tiers.length;++w){C=b.tiers[w];if(C.dasSource.collapseSuperGroups){if(B===undefined)B=!C.bumped;C.bumped=B;C.layoutWasDone=false;C.draw()}}},y=function(){b.snapZoomLockout=false},A;A=function(){window.removeEventListener("keydown",t,false);window.removeEventListener("keyup",y,false);window.removeEventListener("keypress",t,false);b.svgRoot.removeEventListener("mouseout",A,false)};this.svgRoot.addEventListener("mouseover",function(){window.addEventListener("keydown",t,false);window.addEventListener("keyup",
y,false);window.addEventListener("keypress",t,false);b.svgRoot.addEventListener("mouseout",A,false)},false);this.storeStatus();var D;for(a=0;a<this.tiers.length;++a)if(this.tiers[a].dasSource.provides_entrypoints){D=this.tiers[a].dasSource;break}D&&D.entryPoints(function(w){b.entryPoints=w;for(w=0;w<b.entryPoints.length;++w)if(b.entryPoints[w].name==b.chr){b.currentSeqMax=b.entryPoints[w].end;break}});b.queryRegistry(null,true);for(var G in this.chains)this.queryRegistry(G,true)};
function setSources(a,b,c){if(c)for(var e=0;e<b.length;++e)b[e].mapping=c;a.set(b)}
Browser.prototype.queryRegistry=function(a,b){var c,e;if(a){c=this.chains[a].coords;this.mappableSources[a]||(this.mappableSources[a]=new Observed);e=this.mappableSources[a]}else{c=this.coordSystem;e=this.availableSources}var d=hex_sha1(miniJSONify(c));if(b){var f=localStorage["dalliance.registry."+d+".last_queried"];if(f)try{setSources(e,JSON.parse(localStorage["dalliance.registry."+d+".sources"]),a);if((Date.now()|0)-(f|0)<432E5)return}catch(h){dlog("Bad registry cache: "+h)}}(new DASRegistry(this.registry)).sources(function(g){for(var i=
[],j=0;j<g.length;++j){var r=g[j];if(!(!r.coords||r.coords.length==0)){var q=r.coords[0];q.taxon!=c.taxon||q.auth!=c.auth||q.version!=c.version||i.push(r)}}localStorage["dalliance.registry."+d+".sources"]=JSON.stringify(i);localStorage["dalliance.registry."+d+".last_queried"]=""+Date.now();setSources(e,i,a)},function(){},c)};Browser.prototype.makeTier=function(a){try{this.realMakeTier(a)}catch(b){dlog("Error creating tier: "+b)}};
Browser.prototype.realMakeTier=function(a){var b=document.createElementNS(NS_SVG,"g"),c=document.createElementNS(NS_SVG,"rect");c.setAttribute("fill",this.tierBackgroundColors[this.tiers.length%this.tierBackgroundColors.length]);c.setAttribute("x","-1000000");c.setAttribute("y","0");c.setAttribute("width","2000000");c.setAttribute("height","200");c.setAttribute("stroke-width","0");b.appendChild(c);b.setAttribute("transform","translate(200, 450)");a=new DasTier(this,a,b,c);a.init();this.tierHolder.appendChild(b);
this.tiers.push(a);this.refreshTier(a);this.arrangeTiers()};Browser.prototype.removeTier=function(a){a=arrayIndexOf(this.tiers,a);if(a<0)return dlog("Couldn't find tier");var b=this.tiers[a];this.tierHolder.removeChild(b.viewport);b.label&&this.dasLabelHolder.removeChild(b.label);this.tiers.splice(a,1);for(a=0;a<this.tiers.length;++a){this.tiers[a].background.setAttribute("fill",this.tierBackgroundColors[a%this.tierBackgroundColors.length]);this.tiers[a].isLabelValid=false}this.arrangeTiers();this.storeStatus()};
Browser.prototype.makeZoomerTicks=function(){var a=this;removeChildren(this.zoomTickMarks);var b=function(c){var e=a.zoomExpt*Math.log(c/a.zoomBase);if(!(e<0||e>250)){var d=makeElementNS(NS_SVG,"line",null,{x1:30+e,y1:35,x2:30+e,y2:38,stroke:"gray",strokeWidth:1});c=makeElementNS(NS_SVG,"text",c>1500?""+c/1E3+"kb":""+c+"bp",{x:30+e,y:48,fontSize:"8pt",stroke:"none"});a.zoomTickMarks.appendChild(d);a.zoomTickMarks.appendChild(c);c.setAttribute("x",29+e-c.getBBox().width/2)}};b(1E6);b(5E5);b(1E5);b(2E4);
b(4E3);b(500);b(100);b(50)};
Browser.prototype.resizeViewer=function(a){var b=window.innerWidth;b=Math.max(b,640);if(this.forceWidth)b=this.forceWidth;if(this.center)this.svgHolder.style["margin-left"]=((window.innerWidth-b)/2|0)+"px";this.svgRoot.setAttribute("width",b-30);this.svgBackground.setAttribute("width",b-30);this.featureClipRect.setAttribute("width",b-this.tabMargin-40);this.featureBackground.setAttribute("width",b-this.tabMargin-40);this.zoomWidget.setAttribute("transform","translate("+(b-this.zoomSlider.width-100)+
", 0)");b<1075?this.karyo.svg.setAttribute("transform","translate(2000, 15)"):this.karyo.svg.setAttribute("transform","translate(450, 20)");this.regionLabelMax=b-this.zoomSlider.width-120;var c=this.featurePanelWidth;this.featurePanelWidth=b-this.tabMargin-40|0;if(c!=this.featurePanelWidth){b=this.viewStart+(this.viewEnd-this.viewStart)*this.featurePanelWidth/c-this.viewEnd;this.viewStart-=b/2;this.viewEnd+=b/2;b=this.viewEnd-this.viewStart+1;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax){this.viewEnd=
this.currentSeqMax;this.viewStart=this.viewEnd-b+1}if(this.viewStart<1){this.viewStart=1;this.viewEnd=this.viewStart+b-1}this.xfrmTiers(this.tabMargin-1*(this.viewStart-this.origin)*this.scale,1);this.updateRegion();a||this.spaceCheck()}if(this.fgGuide){this.fgGuide.setAttribute("x1",this.featurePanelWidth/2+this.tabMargin);this.fgGuide.setAttribute("x2",this.featurePanelWidth/2+this.tabMargin)}for(a=0;a<this.placards.length;++a){b=this.placards[a].getElementsByTagName("rect");b.length>0&&b[0].setAttribute("width",
this.featurePanelWidth)}};Browser.prototype.xfrmTiers=function(a,b){for(var c=0;c<this.tiers.length;++c)this.xfrmTier(this.tiers[c],a,b);if(this.highlight){this.highlight.setAttribute("transform","translate("+a+",0)");this.highlight.setAttribute("x",(this.highlightMin-this.origin)*this.scale);this.highlight.setAttribute("width",(this.highlightMax-this.highlightMin+1)*this.scale)}};
Browser.prototype.jiggleLabels=function(a){var b=a.xfrmX;a=a.viewport.getElementsByClassName("label-text");for(var c=0;c<a.length;++c){var e=a[c];e.jiggleMin&&e.jiggleMax&&e.setAttribute("x",Math.min(Math.max(this.tabMargin-b,e.jiggleMin),e.jiggleMax))}};
Browser.prototype.xfrmTier=function(a,b,c){if(a.originHaxx&&a.originHaxx!=0)b-=1*a.originHaxx*this.scale;var e=c;if(e<0)e=a.scale;else a.scale=c;c=a.y;if(b!=a.xfrmX||c!=a.xfrmY||e!=a.xfrmS){var d="translate("+b+","+a.y+")";if(e!=1)d+=", scale("+e+",1)";a.viewport.setAttribute("transform",d)}if(a.label&&(c!=a.xfrmY||!a.isLabelValid)){a.label.setAttribute("transform","translate(0, "+c+")");a.isLabelValid=true}a.xfrmX=b;a.xfrmY=c;a.xfrmS=e;this.jiggleLabels(a)};
Browser.prototype.spaceCheck=function(){if(!this.knownSpace||this.knownSpace.chr!==this.chr)this.refresh();else{var a=((this.viewEnd-this.viewStart|0)+1)*this.minExtra|0;if((this.drawnStart|0)>Math.max(1,(this.viewStart|0)-a|0)||(this.drawnEnd|0)<Math.min((this.viewEnd|0)+a,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9))this.refresh()}};
Browser.prototype.move=function(a){var b=this.viewEnd-this.viewStart;this.viewStart-=a/this.scale;this.viewEnd=this.viewStart+b;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax){this.viewEnd=this.currentSeqMax;this.viewStart=this.viewEnd-b}if(this.viewStart<1){this.viewStart=1;this.viewEnd=this.viewStart+b}this.xfrmTiers(this.tabMargin-1*(this.viewStart-this.origin)*this.scale,1);this.updateRegion();this.karyo.update(this.chr,this.viewStart,this.viewEnd);this.spaceCheck()};
Browser.prototype.zoom=function(a){this.zoomFactor=a;a=Math.round((this.viewStart+this.viewEnd)/2)|0;this.viewStart=a-this.zoomBase*this.zoomFactor/2;this.viewEnd=a+this.zoomBase*this.zoomFactor/2;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax+5){a=this.viewEnd-this.viewStart+1;this.viewEnd=this.currentSeqMax;this.viewStart=this.viewEnd-a+1}if(this.viewStart<1){a=this.viewEnd-this.viewStart+1;this.viewStart=1;this.viewEnd=this.viewStart+a-1}this.scale=this.featurePanelWidth/(this.viewEnd-
this.viewStart);this.updateRegion();this.xfrmTiers(this.tabMargin-1*(this.viewStart-this.origin)*this.scale,this.scale/this.scaleAtLastRedraw);a=this.svgRoot.getElementsByClassName("label-text");for(var b=0;b<a.length;++b){var c=a[b],e=c.getAttribute("x");c.setAttribute("transform","scale("+this.scaleAtLastRedraw/this.scale+",1), translate( "+(e*this.scale-e*this.scaleAtLastRedraw)/this.scaleAtLastRedraw+",0)")}};
Browser.prototype.setLocation=function(a,b,c){a|=0;b|=0;if(c&&c!=this.chr){if(!this.entryPoints)throw"Need entry points";for(var e=null,d=0;d<this.entryPoints.length;++d){var f=this.entryPoints[d].name;if(f===c||"chr"+f===c||f==="chr"+c){e=this.entryPoints[d];break}}if(!e)throw"Couldn't find chromosome "+c;this.chr=e.name;this.currentSeqMax=e.end}c=b-a+1;if(c>MAX_VIEW_SIZE){a=(b+a-MAX_VIEW_SIZE)/2|0;b=a+MAX_VIEW_SIZE-1|0}if(c<this.zoomBase){a=(b+a-this.zoomBase)/2|0;mewMax=a+this.zoomBase-1|0}if(a<
1){c=b-a+1;a=1;b=Math.min(a+c-1,this.currentSeqMax)}if(this.currentSeqMax>0&&b>this.currentSeqMax){c=b-a+1;b=this.currentSeqMax;a=Math.max(1,b-c+1)}this.viewStart=a|0;this.viewEnd=b|0;this.scale=this.featurePanelWidth/(this.viewEnd-this.viewStart);this.zoomSlider.setValue(this.zoomExpt*Math.log((this.viewEnd-this.viewStart+1)/this.zoomBase));this.updateRegion();this.karyo.update(this.chr,this.viewStart,this.viewEnd);this.spaceCheck();this.xfrmTiers(this.tabMargin-1*(this.viewStart-this.origin)*this.scale,
1);this.storeStatus()};
Browser.prototype.storeStatus=function(){if(!(!this.cookieKey||this.noPersist)){localStorage["dalliance."+this.cookieKey+".view-chr"]=this.chr;localStorage["dalliance."+this.cookieKey+".view-start"]=this.viewStart|0;localStorage["dalliance."+this.cookieKey+".view-end"]=this.viewEnd|0;for(var a=[],b=0;b<this.tiers.length;++b)this.tiers[b].dasSource.noPersist||a.push(this.tiers[b].dasSource);localStorage["dalliance."+this.cookieKey+".sources"]=JSON.stringify(a);localStorage["dalliance."+this.cookieKey+
".version"]=VERSION.CONFIG}};Browser.prototype.scheduleRefresh=function(a){a||(a=500);var b=this;this.refreshTB&&clearTimeout(this.refreshTB);this.refreshTB=setTimeout(function(){b.refreshTB=null;b.refresh()},a)};Browser.prototype.invalidateLayouts=function(){for(var a=0;a<this.tiers.length;++a)this.tiers[a].layoutWasDone=false};Browser.prototype.refreshTier=function(a){this.knownSpace&&this.knownSpace.invalidate(a)};
function Chainset(a,b,c,e){this.uri=a;this.srcTag=b;this.destTag=c;this.coords=e;this.chainsBySrc={};this.chainsByDest={};this.postFetchQueues={}}function parseCigar(a){for(var b=[],c=RegExp("([0-9]*)([MID])","g"),e;(e=c.exec(a))!=null;){var d=e[1];if(d.length==0)d=1;b.push({cnt:d|0,op:e[2]})}return b}
Chainset.prototype.fetchChainsTo=function(a){var b=this;(new DASSource(this.uri)).alignments(a,{},function(c){b.chainsByDest[a]||(b.chainsByDest[a]=[]);for(var e=0;e<c.length;++e)for(var d=c[e],f=0;f<d.blocks.length;++f){for(var h=d.blocks[f],g,i,j=0;j<h.segments.length;++j){var r=h.segments[j],q=d.objects[r.object];if(q.dbSource===b.srcTag)g=r;else if(q.dbSource===b.destTag)i=r}if(g&&i){h={srcChr:d.objects[g.object].accession,srcMin:g.min|0,srcMax:g.max|0,srcOri:g.strand,destChr:d.objects[i.object].accession,
destMin:i.min|0,destMax:i.max|0,destOri:i.strand,blocks:[]};j=parseCigar(g.cigar);r=parseCigar(i.cigar);for(var m=q=0,p=0,o=0;p<j.length&&o<r.length;)if(j[p].op=="M"&&r[o].op=="M"){var s=Math.min(j[p].cnt,r[o].cnt);h.blocks.push([q,m,s]);if(j[p].cnt==s)++p;else j[p].cnt-=s;if(r[o].cnt==s)++o;else r[o]-=s;q+=s;m+=s}else if(j[p].op=="I")m+=j[p++].cnt;else if(r[o].op=="I")q+=r[o++].cnt;pusho(b.chainsBySrc,h.srcChr,h);pusho(b.chainsByDest,h.destChr,h)}}if(b.postFetchQueues[a]){c=b.postFetchQueues[a];
for(e=0;e<c.length;++e)c[e]();b.postFetchQueues[a]=null}})};Chainset.prototype.mapPoint=function(a,b){for(var c=this.chainsBySrc[a]||[],e=0;e<c.length;++e){var d=c[e];if(b>=d.srcMin&&b<=d.srcMax){var f;f=d.srcOri=="-"?d.srcMax-b:b-d.srcMin;for(var h=d.blocks,g=0;g<h.length;++g){var i=h[g],j=i[0],r=i[1];i=i[2];if(f>=j&&f<=j+i){c=f-j;return{seq:d.destChr,pos:d.destOri=="-"?d.destMax-r-c:c+r+d.destMin,flipped:d.srcOri!=d.destOri}}}}}return null};
Chainset.prototype.unmapPoint=function(a,b){for(var c=this.chainsByDest[a]||[],e=0;e<c.length;++e){var d=c[e];if(b>=d.destMin&&b<=d.destMax){e=d.srcOri=="-"?d.destMax-b:b-d.destMin;for(var f=d.blocks,h=0;h<f.length;++h){var g=f[h];c=g[0];var i=g[1];g=g[2];if(e>=i&&e<=i+g){e=e-i;f=e+c+d.srcMin;f=d.destOri=="-"?d.srcMax-c-e:e+c+d.srcMin;return{seq:d.srcChr,pos:f,flipped:d.srcOri!=d.destOri}}}return null}}return null};
Chainset.prototype.sourceBlocksForRange=function(a,b,c,e){if(this.chainsByDest[a]){var d=this.unmapPoint(a,b),f=this.unmapPoint(a,c);!d||!f||d.seq!=f.seq?e([]):e([new DASSegment(d.seq,d.pos,f.pos)])}else{d=!this.postFetchQueues[a];var h=this;pusho(this.postFetchQueues,a,function(){h.sourceBlocksForRange(a,b,c,e)});d&&this.fetchChainsTo(a)}};var dasLibErrorHandler=function(a){alert(a)},dasLibRequestQueue=[];function DASSegment(a,b,c,e){this.name=a;this.start=b;this.end=c;this.description=e}
DASSegment.prototype.toString=function(){return this.name+":"+this.start+".."+this.end};DASSegment.prototype.isBounded=function(){return this.start&&this.end};DASSegment.prototype.toDASQuery=function(){var a="segment="+this.name;if(this.start&&this.end)a+=":"+this.start+","+this.end;return a};
function DASSource(a,b){var c;if(typeof a=="string"){this.uri=a;c=b||{}}else c=a||{};for(var e in c)if(typeof c[e]!="function")this[e]=c[e];if(!this.coords)this.coords=[];if(!this.props)this.props={};if(this.uri&&this.uri.substr(this.uri.length-1)!="/")this.uri+="/"}function DASCoords(){}function coordsMatch(a,b){return a.taxon==b.taxon&&a.auth==b.auth&&a.version==b.version}
DASSource.prototype.entryPoints=function(a){this.doCrossDomainRequest(this.uri+"entry_points",function(b){if(!b)return a([]);var c=[];b=b.getElementsByTagName("SEGMENT");for(var e=0;e<b.length;++e){var d=b[e],f=d.getAttribute("id"),h=d.getAttribute("size"),g;if(h){g=1;h=h}else{g=d.getAttribute("start");h=d.getAttribute("stop")}var i=null;if(d.firstChild)i=d.firstChild.nodeValue;c.push(new DASSegment(f,g,h,i))}a(c)})};
function DASSequence(a,b,c,e,d){this.name=a;this.start=b;this.end=c;this.alphabet=e;this.seq=d}
DASSource.prototype.sequence=function(a,b){this.doCrossDomainRequest(this.uri+"sequence?"+a.toDASQuery(),function(c){if(c){var e=[];c=c.getElementsByTagName("SEQUENCE");for(var d=0;d<c.length;++d){var f=c[d],h=f.getAttribute("id"),g=f.getAttribute("start"),i=f.getAttribute("stop"),j=null;if(f.firstChild){f=f.firstChild.nodeValue;j="";for(var r=0;;){var q=f.indexOf("\n",r);if(q>=0){j+=f.substring(r,q);r=q+1}else{j+=f.substring(r);break}}}e.push(new DASSequence(h,g,i,"DNA",j))}b(e)}else b([])})};
function DASFeature(){}function DASGroup(){}function DASLink(a,b){this.desc=a;this.uri=b}
DASSource.prototype.features=function(a,b,c){b=b||{};var e;if(this.uri.indexOf("http://")==0){e=this.uri+"features?";if(a)e+=a.toDASQuery();else if(b.group){a=b.group;if(typeof a=="string")e+=";group_id="+a;else for(var d=0;d<a.length;++d)e+=";group_id="+a[d]}if(b.type)if(typeof b.type=="string")e+=";type="+b.type;else for(a=0;a<b.type.length;++a)e+=";type="+b.type[a];if(b.maxbins)e+=";maxbins="+b.maxbins}else e=this.uri;this.doCrossDomainRequest(e,function(f,h){if(f){for(var g=[],i={},j=f.getElementsByTagName("SEGMENT"),
r=0;r<j.length;++r){var q=j[r],m=q.getAttribute("id");i[m]={min:q.getAttribute("start"),max:q.getAttribute("stop")};q=q.getElementsByTagName("FEATURE");for(var p=0;p<q.length;++p){var o=q[p],s=new DASFeature;s.segment=m;s.id=o.getAttribute("id");s.label=o.getAttribute("label");var u=elementValue(o,"START"),v=elementValue(o,"END");if((u|0)>(v|0)){s.min=v;s.max=u}else{s.min=u;s.max=v}u=o.getElementsByTagName("TYPE");if(u.length>0){u=u[0];if(u.firstChild)s.type=u.firstChild.nodeValue;s.typeId=u.getAttribute("id");
s.typeCv=u.getAttribute("cvId")}s.type=elementValue(o,"TYPE");if(!s.type&&s.typeId)s.type=s.typeId;s.method=elementValue(o,"METHOD");(u=elementValue(o,"ORIENTATION"))||(u="0");s.orientation=u;s.score=elementValue(o,"SCORE");s.links=dasLinksOf(o);s.notes=dasNotesOf(o);u=o.getElementsByTagName("GROUP");for(v=0;v<u.length;++v){var t=u[v],y=new DASGroup;y.type=t.getAttribute("type");y.id=t.getAttribute("id");y.links=dasLinksOf(t);y.notes=dasNotesOf(t);if(s.groups)s.groups.push(y);else s.groups=Array(y)}if(s.notes)for(u=
0;u<s.notes.length;++u){v=s.notes[u];if(v.indexOf("Genename=")==0){t=new DASGroup;t.type="gene";t.id=v.substring(9);if(s.groups)s.groups.push(t);else s.groups=Array(t)}}u=o.getElementsByTagName("PART");if(u.length>0){t=[];for(v=0;v<u.length;++v)t.push(u[v].getAttribute("id"));s.parts=t}u=o.getElementsByTagName("PARENT");if(u.length>0){o=[];for(v=0;v<u.length;++v)o.push(u[v].getAttribute("id"));s.parents=o}g.push(s)}}c(g,undefined,i)}else c([],"Failed request: "+(h.status==0?"server may not support CORS":
"status="+h.status))})};function DASAlignment(a){this.type=a;this.objects={};this.blocks=[]}
DASSource.prototype.alignments=function(a,b,c){var e=this.uri+"alignment?query="+a;this.doCrossDomainRequest(e,function(d){if(d){var f=[];d=d.getElementsByTagName("alignment");for(var h=0;h<d.length;++h){for(var g=d[h],i=new DASAlignment(g.getAttribute("alignType")),j=g.getElementsByTagName("alignObject"),r=0;r<j.length;++r){var q=j[r];q={id:q.getAttribute("intObjectId"),accession:q.getAttribute("dbAccessionId"),version:q.getAttribute("objectVersion"),dbSource:q.getAttribute("dbSource"),dbVersion:q.getAttribute("dbVersion")};
i.objects[q.id]=q}g=g.getElementsByTagName("block");for(j=0;j<g.length;++j){q=g[j];r={order:q.getAttribute("blockOrder"),segments:[]};q=q.getElementsByTagName("segment");for(var m=0;m<q.length;++m){var p=q[m];p={object:p.getAttribute("intObjectId"),min:p.getAttribute("start"),max:p.getAttribute("end"),strand:p.getAttribute("strand"),cigar:elementValue(p,"cigar")};r.segments.push(p)}i.blocks.push(r)}f.push(i)}c(f)}else c([],"Failed request "+e)})};function DASStylesheet(){this.styles=[]}
DASStylesheet.prototype.pushStyle=function(a,b,c){a||(a={type:"default"});a=shallowCopy(a);if(b)a.zoom=b;a.style=c;this.styles.push(a)};function DASStyle(){}
DASSource.prototype.stylesheet=function(a,b){var c,e=this.credentials;if(this.stylesheet_uri){c=this.stylesheet_uri;e=false}else c=this.uri+"stylesheet";doCrossDomainRequest(c,function(d){if(d){var f=new DASStylesheet;d=d.getElementsByTagName("TYPE");for(var h=0;h<d.length;++h){var g=d[h],i={};i.type=g.getAttribute("id");i.label=g.getAttribute("label");i.method=g.getAttribute("method");g=g.getElementsByTagName("GLYPH");for(var j=0;j<g.length;++j){var r=g[j],q=r.getAttribute("zoom"),m=childElementOf(r);
r=new DASStyle;r.glyph=m.localName;for(m=m.firstChild;m;){if(m.nodeType==Node.ELEMENT_NODE)r[m.localName]=m.firstChild.nodeValue;m=m.nextSibling}f.pushStyle(i,q,r)}}a(f)}else b&&b()},e)};function DASRegistry(a,b){b=b||{};this.uri=a;this.opts=b}
DASRegistry.prototype.sources=function(a,b,c){c||(c={});var e=[];c.taxon&&e.push("organism="+c.taxon);c.auth&&e.push("authority="+c.auth);c.version&&e.push("version="+c.version);c=this.uri;if(e.length>0)c=c+"?"+e.join("&");doCrossDomainRequest(c,function(d){if(!d&&b)b();else{var f=[];d=d.getElementsByTagName("SOURCE");for(var h=0;h<d.length;++h){var g=d[h],i=g.getElementsByTagName("VERSION");if(!(i.length<1)){var j=i[0],r=j.getElementsByTagName("COORDINATES");i=[];for(var q=0;q<r.length;++q){var m=
r[q],p=new DASCoords;p.auth=m.getAttribute("authority");p.taxon=m.getAttribute("taxid");p.version=m.getAttribute("version");i.push(p)}r=j.getElementsByTagName("CAPABILITY");var o;for(q=0;q<r.length;++q){m=r[q];if(m.getAttribute("type")=="das1:features"){o=m.getAttribute("query_uri");o=o.substring(0,o.length-8)}}q={};j=j.getElementsByTagName("PROP");for(r=0;r<j.length;++r)pusho(q,j[r].getAttribute("name"),j[r].getAttribute("value"));if(o){g=new DASSource(o,{source_uri:g.getAttribute("uri"),name:g.getAttribute("title"),
desc:g.getAttribute("description"),coords:i,props:q});f.push(g)}}}a(f)}})};function elementValue(a,b){var c=a.getElementsByTagName(b);return c.length>0&&c[0].firstChild?c[0].firstChild.nodeValue:null}function childElementOf(a){if(a.hasChildNodes()){a=a.firstChild;do{if(a.nodeType==Node.ELEMENT_NODE)return a;a=a.nextSibling}while(a!=null)}return null}
function dasLinksOf(a){for(var b=[],c=a.getElementsByTagName("LINK"),e=0;e<c.length;++e){var d=c[e];if(d.parentNode==a)b.push(new DASLink(d.firstChild?d.firstChild.nodeValue:"Unknown",d.getAttribute("href")))}return b}function dasNotesOf(a){var b=[];a=a.getElementsByTagName("NOTE");for(var c=0;c<a.length;++c)a[c].firstChild&&b.push(a[c].firstChild.nodeValue);return b}
function doCrossDomainRequest(a,b,c){if(window.XDomainRequest){var e=new XDomainRequest;e.onload=function(){var d=new ActiveXObject("Microsoft.XMLDOM");d.async=false;d.loadXML(e.responseText);b(d)};e.open("get",a)}else{e=new XMLHttpRequest;e.onreadystatechange=function(){if(e.readyState==4)if(e.status==200||e.status==0)b(e.responseXML,e)};e.open("get",a,true);if(c)e.withCredentials=true}e.send("")}DASSource.prototype.doCrossDomainRequest=function(a,b){return doCrossDomainRequest(a,b,this.credentials)};
Browser.prototype.makeTooltip=function(a,b){var c=false,e=this,d=null,f;f=function(){c=false;if(d){clearTimeout(d);d=null}a.removeEventListener("mouseout",f,false)};var h;h=function(g){var i=g.clientX+window.scrollX,j=g.clientY+window.scrollY;d||(d=setTimeout(function(){var r=makeElement("div",b,{},{position:"absolute",top:""+(j+20)+"px",left:""+Math.max(i-30,20)+"px",backgroundColor:"rgb(250, 240, 220)",borderWidth:"1px",borderColor:"black",borderStyle:"solid",padding:"2px",maxWidth:"400px"});e.hPopupHolder.appendChild(r);
var q;q=function(m){try{e.hPopupHolder.removeChild(r)}catch(p){}window.removeEventListener("mousemove",q,false);c&&a.offsetParent!=null&&h(m)};window.addEventListener("mousemove",q,false);d=null},1E3))};a.addEventListener("mouseover",function(g){c=true;a.addEventListener("mouseout",f,false);h(g)},false);a.addEventListener("DOMNodeRemovedFromDocument",function(){c=false;if(d){clearTimeout(d);d=null}},false)};
Browser.prototype.popit=function(a,b,c,e){var d=this;e||(e={});var f=e.width||200;e=a.clientX;a=a.clientY;e+=document.documentElement.scrollLeft||document.body.scrollLeft;a+=document.documentElement.scrollTop||document.body.scrollTop;var h=window.innerWidth,g=a+30,i=Math.min(e-30,h-f-10),j=makeElement("div");j.style.position="absolute";j.style.top=""+g+"px";j.style.left=""+i+"px";j.style.width=f+"px";j.style.backgroundColor="white";j.style.borderWidth="2px";j.style.borderColor="black";j.style.borderStyle=
"solid";if(b){var r=makeElement("div","X",null,{marginTop:"-3px",padding:"3px",borderStyle:"none",borderLeftStyle:"solid",borderWidth:"1px",borderColor:"rgb(128,128,128)",cssFloat:"right"});r.style["float"]="right";r.addEventListener("mouseover",function(){r.style.color="red"},false);r.addEventListener("mouseout",function(){r.style.color="black"},false);r.addEventListener("mousedown",function(){d.removeAllPopups()},false);b=makeElement("div",[makeElement("span",b,null,{maxWidth:"200px"}),r],null,
{backgroundColor:"rgb(230,230,250)",borderColor:"rgb(128,128,128)",borderStyle:"none",borderBottomStyle:"solid",borderWidth:"1px",padding:"3px"});var q,m,p,o;p=function(u){u.stopPropagation();u.preventDefault();i+=u.clientX-q;if(i<8)i=8;if(i>h-f-32)i=h-f-26;g+=u.clientY-m;g=Math.max(10,g);j.style.top=""+g+"px";j.style.left=""+Math.min(i,h-f-10)+"px";q=u.clientX;m=u.clientY};o=function(u){u.stopPropagation();u.preventDefault();window.removeEventListener("mousemove",p,false);window.removeEventListener("mouseup",
o,false)};b.addEventListener("mousedown",function(u){u.preventDefault();u.stopPropagation();q=u.clientX;m=u.clientY;window.addEventListener("mousemove",p,false);window.addEventListener("mouseup",o,false)},false);j.appendChild(b)}j.appendChild(makeElement("div",c,null,{padding:"3px",clear:"both"}));this.hPopupHolder.appendChild(j);var s={node:j,displayed:true};j.addEventListener("DOMNodeRemoved",function(){s.displayed=false},false);return s};
function IconSet(a){var b=new XMLHttpRequest;b.open("get",a,false);b.send();this.icons=b.responseXML}IconSet.prototype.createIcon=function(a,b){var c=this.icons.getElementById(a);if(c){c=document.importNode(c,true);b.appendChild(c);var e=c.getBBox();b.removeChild(c);c.setAttribute("transform","translate("+-e.x+","+-e.y+")");return makeElementNS(NS_SVG,"g",c)}else alert("couldn't find "+a)};
IconSet.prototype.createButton=function(a,b,c,e){c|=0;e|=0;a=this.icons.getElementById(a);a=document.importNode(a,true);b.appendChild(a);var d=a.getBBox();b.removeChild(a);a.setAttribute("transform","translate("+((c-d.width-2)/2-d.x)+","+((e-d.height-2)/2-d.y)+")");return makeElementNS(NS_SVG,"g",[makeElementNS(NS_SVG,"rect",null,{x:0,y:0,width:c,height:e,fill:"rgb(230,230,250)",stroke:"rgb(150,150,220)",strokeWidth:2}),a])};
function dlog(a){var b=document.getElementById("log");b&&b.appendChild(makeElement("p",a))}var MIN_FEATURE_PX=1,MIN_PADDING=3,SUBTIER_MAX=25;function DColour(a,b,c,e){this.red=a|0;this.green=b|0;this.blue=c|0;if(e)this.name=e}DColour.prototype.toSvgString=function(){if(!this.name)this.name="rgb("+this.red+","+this.green+","+this.blue+")";return this.name};
var palette={red:new DColour(255,0,0,"red"),green:new DColour(0,255,0,"green"),blue:new DColour(0,0,255,"blue"),yellow:new DColour(255,255,0,"yellow"),white:new DColour(255,255,255,"white"),black:new DColour(0,0,0,"black")},COLOR_RE=/^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$/;function dasColourForName(a){var b=palette[a];if(!b){if(b=COLOR_RE.exec(a))b=new DColour("0x"+b[1]|0,"0x"+b[2]|0,"0x"+b[3]|0,a);else{dlog("couldn't handle color: "+a);b=palette.black}palette[a]=b}return b}
function DGlyph(a,b,c,e){this.glyph=a;this.min=b;this.max=c;this.height=e;this.zindex=0}function DSubTier(){this.glyphs=[];this.height=0}DSubTier.prototype.add=function(a){this.glyphs.push(a);this.height=Math.max(this.height,a.height)};DSubTier.prototype.hasSpaceFor=function(a){for(var b=0;b<this.glyphs.length;++b){var c=this.glyphs[b];if(c.min<=a.max&&c.max>=a.min)return false}return true};
DasTier.prototype.styleForFeature=function(a){var b=zoomForScale(this.browser.scale);if(!this.stylesheet)return null;for(var c=null,e=this.stylesheet.styles,d=0;d<e.length;++d){var f=e[d];if(!(f.zoom&&f.zoom!=b))if(!(f.label&&!RegExp("^"+f.label+"$").test(a.label)))if(!(f.method&&!RegExp("^"+f.method+"$").test(a.method))){if(f.type)if(f.type=="default"){if(!c)c=f.style;continue}else if(f.type!=a.type)continue;return f.style}}return c};
function drawLine(a,b,c,e,d){var f=e.browser.origin,h=e.browser.scale,g=c.HEIGHT||30,i=e.dasSource.forceMin||c.MIN||e.currentFeaturesMinScore||0,j=e.dasSource.forceMax||c.MAX||e.currentFeaturesMaxScore||10,r=1*g/(j-i),q=c.LINEWIDTH||1,m=c.COLOR||c.COLOR1||"black";c=document.createElementNS(NS_SVG,"path");c.setAttribute("fill","none");c.setAttribute("stroke",m);c.setAttribute("stroke-width",q);q="";for(m=0;m<b.length;++m){var p=b[m],o=(((p.min|0)+(p.max|0))/2-f)*h;p=d+(g-((p.score-1*i)*r|0));if(m==
0)q="M "+o+" "+p;else q+=" L "+o+" "+p}c.setAttribute("d",q);a.appendChild(c);b="line_clip_"+ ++clipIdSeed;f=document.createElementNS(NS_SVG,"clipPath");f.setAttribute("id",b);h=document.createElementNS(NS_SVG,"rect");h.setAttribute("x",-500000);h.setAttribute("y",d-1);h.setAttribute("width",1E6);h.setAttribute("height",g+2);f.appendChild(h);a.appendChild(f);c.setAttribute("clip-path","url(#"+b+")");if(!e.isQuantitative){e.isQuantitative=true;e.isLabelValid=false}if(e.min!=i){e.min=i;e.isLabelValid=
false}if(e.max!=j){e.max=j;e.isLabelValid=false}if(e.clientMin!=d|0+g){e.clientMin=d|0+g;e.isLabelValid=false}if(e.clientMax!=d){e.clientMax=d;e.isLabelValid=false}return g|0+MIN_PADDING}
function sortFeatures(a){for(var b={},c={},e={},d={},f={},h=[],g,i,j,r=function(){j={};for(var y=0;y<a.currentFeatures.length;++y){var A=a.currentFeatures[y];if(A.id)j[A.id]=A}},q=function(y){var A=[];if(y.parents)for(var D=0;D<y.parents.length;++D){var G=y.parents[D],w=j[G];w&&w.typeCv=="SO:0000704"&&pushnew(A,G)}return A},m=0;m<a.currentFeatures.length;++m){var p=a.currentFeatures[m];if(!p.parts)if(!p.min||!p.max)h.push(p);else{if(p.score&&p.score!="."&&p.score!="-"){sc=1*p.score;if(!g||sc<g)g=
sc;if(!i||sc>i)i=sc}var o=[],s=null;if(p.groups)for(var u=0;u<p.groups.length;++u){var v=p.groups[u],t=v.id;if(v.type=="gene"){s=t;e[t]=shallowCopy(v)}else if(v.type!="translation"){pusho(c,t,p);e[t]=shallowCopy(v);o.push(t)}}if(p.parents){j||r();for(u=0;u<p.parents.length;++u){v=p.parents[u];if(t=j[v]){if(!t.parts)t.parts=[p];pushnewo(c,v,t);pusho(c,v,p);e[v]||(e[v]={type:t.type,id:t.id,label:t.label||t.id});o.push(v);v=q(t);if(v.length>0){s=v[0];t=j[v[0]];e[v[0]]={type:t.type,id:t.id,label:t.label||
t.id};if(!a.dasSource.collapseSuperGroups){a.dasSource.collapseSuperGroups=true;a.isLabelValid=false}}}}}if(o.length==0)pusho(b,p.type,p);else if(s)for(v=0;v<o.length;++v){t=o[v];pushnewo(d,s,t);f[t]=s}}}a.ungroupedFeatures=b;a.groupedFeatures=c;a.groups=e;a.superGroups=d;a.groupsToSupers=f;if(g){if(g>0)g=0;else if(i<0)i=0;a.currentFeaturesMinScore=g;a.currentFeaturesMaxScore=i}}var clipIdSeed=0;
function drawFeatureTier(a){sortFeatures(a);a.placard=null;a.isQuantitative=false;for(var b=a.viewport;b.childNodes.length>0;)b.removeChild(b.firstChild);b.appendChild(a.background);drawGuidelines(a,b);var c=MIN_PADDING,e=[],d=false;for(var f in a.ungroupedFeatures){var h=a.ungroupedFeatures[f],g=a.styleForFeature(h[0]);if(g)if(g.glyph=="LINEPLOT"){c+=Math.max(drawLine(b,h,g,a,c));d=true}else for(var i=0;i<h.length;++i){g=h[i];if(!g.parts){var j=glyphForFeature(g,0,a.styleForFeature(g),a);e.push(j)}}}if(a.dasSource.collapseSuperGroups&&
!a.bumped)for(var r in a.superGroups){f=a.superGroups[r];a.groups[r].type=a.groups[f[0]].type;i={};for(j=0;j<f.length;++j){h=a.groupedFeatures[f[j]];for(var q=0;q<h.length;++q){g=h[q];pusho(i,g.type,g)}if(a.groups[r]&&!a.groups[r].links||a.groups[r].links.length==0)a.groups[r].links=a.groups[f[0]].links;delete a.groupedFeatures[f[j]]}for(var m in i){var p=i[m],o=p[0];h=null;for(q=0;q<p.length;++q){g=p[q];g=new Range(g.min,g.max);h=h?union(h,g):g}var s=h.ranges();for(h=0;h<s.length;++h){var u=s[h],
v=((u.max()|0)-(u.min()|0)+1)*f.length,t=0;for(q=0;q<p.length;++q){g=p[q];if((g.min|0)<=u.max()&&(g.max|0)>=u.min()){var y=Math.max(g.min|0,u.min());g=Math.min(g.max|0,u.max());t+=g-y+1}}g=new DASFeature;for(k in o)g[k]=o[k];g.min=u.min();g.max=u.max();if(g.label&&f.length>1)g.label+=" ("+f.length+" vars)";g.visualWeight=1*t/v;pusho(a.groupedFeatures,r,g)}}delete a.superGroups[r]}f=[];for(var A in a.groupedFeatures)f.push(A);f.sort(function(D,G){return a.groupedFeatures[D][0].score-a.groupedFeatures[G][0].score>
0?-1:1});m={};for(h=0;h<f.length;++h){A=f[h];if(j=glyphsForGroup(a.groupedFeatures[A],0,a.groups[A],a,a.dasSource.collapseSuperGroups&&!a.bumped?"collapsed_gene":"tent"))m[A]=j}for(r in a.superGroups){f=a.superGroups[r];A=[];h=1E10;g=-10000000000;for(i=0;i<f.length;++i){q=m[f[i]];m[f[i]]=null;if(q){A.push(q);h=Math.min(h,q.min);g=Math.max(g,q.max)}}for(i=0;i<A.length;++i){q=A[i];q.min=h;q.max=g;e.push(q)}}for(j in m)(q=m[j])&&e.push(q);r=new DSubTier;A=[];h=false;f=0;a:for(;f<e.length;++f){j=e[f];
j=labelGlyph(a,j,b);if(j.bump)h=true;if(j.bump&&(a.bumped||a.dasSource.collapseSuperGroups)){for(g=0;g<A.length;++g){m=A[g];if(m.hasSpaceFor(j)){m.add(j);continue a}}if(A.length>=SUBTIER_MAX)a.status="Too many overlapping features, truncating at "+SUBTIER_MAX;else{m=new DSubTier;m.add(j);A.push(m)}}else r.add(j)}a.hasBumpedFeatures=h;if(r.glyphs.length>0)A=[r].concat(A);r=[];d&&r.push(c);for(h=0;h<A.length;++h){m=A[h];g=m.glyphs;g=g.sort(function(D,G){return D.zindex-G.zindex});for(f=0;f<g.length;++f){j=
g[f];if(j.glyph){gypos=c;if(j.height<m.height)gypos+=m.height-j.height;j.glyph.setAttribute("transform","translate(0, "+gypos+")");j.glyph.setAttribute("cursor","pointer");b.appendChild(j.glyph)}}if(j.quant){a.isLabelValid=false;a.isQuantitative=true;a.min=j.quant.min;a.max=j.quant.max;a.clientMin=c+m.height;a.clientMax=c}c+=m.height+MIN_PADDING;r.push(c)}c=Math.max(a.browser.minTierHeight,c);if(r.length<2){b=false;j=c;if(A=a.stylesheet){f=zoomForScale(a.browser.scale);for(h=0;h<A.styles.length;++h){m=
A.styles[h];if(!m.zoom||m.zoom==f){m=m.style;if(m.bump)b=true;if(m.height&&4+m.height>j)j=4+m.height}}if(b)c=2*j}}a.wantedLayoutHeight=c;if(!a.layoutWasDone||a.browser.autoSizeTiers){a.layoutHeight=c;if(e.length>0||d)a.layoutWasDone=true;a.placard=null}else if(a.layoutHeight!=c){e=document.createElementNS(NS_SVG,"g");d=document.createElementNS(NS_SVG,"rect");d.setAttribute("x",0);d.setAttribute("y",-20);d.setAttribute("width",a.browser.featurePanelWidth);d.setAttribute("height",20);d.setAttribute("stroke",
"red");d.setAttribute("stroke-width",1);d.setAttribute("fill","white");e.appendChild(d);d=document.createElementNS(NS_SVG,"text");d.setAttribute("stroke","none");d.setAttribute("fill","red");d.setAttribute("font-family","helvetica");d.setAttribute("font-size","10pt");if(a.layoutHeight<c){for(b=0;a.layoutHeight-20>=r[b];)++b;d.appendChild(document.createTextNode("Show "+(r.length-b)+" more"))}else d.appendChild(document.createTextNode("Show less"));d.setAttribute("x",80);d.setAttribute("y",-6);e.appendChild(d);
d=document.createElementNS(NS_SVG,"path");d.setAttribute("fill","red");d.setAttribute("stroke","none");a.layoutHeight<c?d.setAttribute("d","M 30 -16 L 42 -16 L 36 -4 Z"):d.setAttribute("d","M 30 -4 L 42 -4 L 36 -16 Z");e.appendChild(d);e.addEventListener("mousedown",function(){a.layoutHeight=a.wantedLayoutHeight;a.placard=null;a.clipTier();a.browser.arrangeTiers()},false);d=document.createElementNS(NS_SVG,"text");d.setAttribute("stroke","none");d.setAttribute("fill","red");d.setAttribute("font-family",
"helvetica");d.setAttribute("font-size","10pt");d.appendChild(document.createTextNode("(Auto grow-shrink)"));d.setAttribute("x",750);d.setAttribute("y",-6);d.addEventListener("mousedown",function(D){D.preventDefault();D.stopPropagation();a.browser.autoSizeTiers=true;a.browser.refresh()},false);e.appendChild(d);a.placard=e}e=a.error||a.status;if(e!=null){c=document.createElementNS(NS_SVG,"g");d=document.createElementNS(NS_SVG,"rect");d.setAttribute("x",0);d.setAttribute("y",-20);d.setAttribute("width",
a.browser.featurePanelWidth);d.setAttribute("height",20);d.setAttribute("stroke","red");d.setAttribute("stroke-width",1);d.setAttribute("fill","white");c.appendChild(d);b=document.createElementNS(NS_SVG,"text");b.setAttribute("stroke","none");b.setAttribute("fill","red");b.setAttribute("font-family","helvetica");b.setAttribute("font-size","10pt");b.setAttribute("x",25);b.setAttribute("y",-6);b.appendChild(document.createTextNode(e));if(a.error){d=document.createElementNS(NS_SVG,"text");d.setAttribute("stroke",
"none");d.setAttribute("fill","red");d.setAttribute("font-family","helvetica");d.setAttribute("font-size","10pt");d.appendChild(document.createTextNode("(Remove track)"));d.setAttribute("x",800);d.setAttribute("y",-6);d.addEventListener("mousedown",function(D){D.preventDefault();D.stopPropagation();a.browser.removeTier(a)},false);c.appendChild(d)}c.appendChild(b);a.placard=c}a.clipTier();a.scale=1}
DasTier.prototype.clipTier=function(){var a=this.viewport;this.background.setAttribute("height",this.layoutHeight);var b="tier_clip_"+ ++clipIdSeed,c=document.createElementNS(NS_SVG,"clipPath");c.setAttribute("id",b);var e=document.createElementNS(NS_SVG,"rect");e.setAttribute("x",-500000);e.setAttribute("y",0);e.setAttribute("width",1E6);e.setAttribute("height",this.layoutHeight);c.appendChild(e);a.appendChild(c);a.setAttribute("clip-path","url(#"+b+")")};
function glyphsForGroup(a,b,c,e,d){for(var f=e.browser.scale,h=e.browser.origin,g=1,i,j=null,r=null,q=null,m=null,p=null,o,s=e.styleForFeature(c),u=0;u<a.length;++u){var v=a[u],t=e.styleForFeature(v);if(t)if(t.HEIGHT)o=o?Math.max(o,t.HEIGHT|0):t.HEIGHT|0}var y=document.createElementNS(NS_SVG,"g"),A=[];y.dalliance_group=c;var D=[];for(u=0;u<a.length;++u){v=a[u];if(v.orientation&&m==null)m=v.orientation;if(v.notes&&r==null)r=v.notes;if(v.links&&j==null)j=v.links;if(t=e.styleForFeature(v))if(!v.parts)(v=
glyphForFeature(v,b,t,e,o))&&v.glyph&&D.push(v)}if(D.length==0)return null;D=D.sort(function(B,C){return B.zindex-C.zindex});for(u=0;u<D.length;++u){v=D[u];v.glyph.dalliance_group=c;A.push(v.glyph);j=new Range(v.min,v.max);q=q==null?j:union(q,j);g=Math.max(g,v.height);if(!i&&v.label)i=v.label;if(v.quant)p=v.quant}if(q){D=q.ranges();for(u=1;u<D.length;++u){j=(D[u-1].max()+1-h)*f;o=(D[u].min()-h)*f;if(d=="collapsed_gene"){v=document.createElementNS(NS_SVG,"path");v.setAttribute("fill","none");v.setAttribute("stroke",
"black");v.setAttribute("stroke-width","1");t=g/2;var G="M "+j+" "+(b+t)+" L "+o+" "+(b+t);if(o-j>8){var w=0.5*o+0.5*j;if(m=="+")G+=" M "+(w-2)+" "+(b+t-4)+" L "+(w+2)+" "+(b+t)+" L "+(w-2)+" "+(b+t+4);else if(m=="-")G+=" M "+(w+2)+" "+(b+t-4)+" L "+(w-2)+" "+(b+t)+" L "+(w+2)+" "+(b+t+4)}v.setAttribute("d",G)}else{v=document.createElementNS(NS_SVG,"path");v.setAttribute("fill","none");v.setAttribute("stroke","black");v.setAttribute("stroke-width","1");G=true;if(s&&s.STYLE&&s.STYLE!="hat")G=false;
t=p?g:g/2;if(G&&(m=="+"||m=="-")){w=(j+o)/2;v.setAttribute("d","M "+j+" "+(b+t)+" L "+w+" "+(m=="-"?b+12:b)+" L "+o+" "+(b+t))}else v.setAttribute("d","M "+j+" "+(b+t)+" L "+o+" "+(b+t))}y.appendChild(v)}}for(u=0;u<A.length;++u)y.appendChild(A[u]);c.segment=a[0].segment;c.min=q.min();c.max=q.max();if(r&&(!c.notes||c.notes.length==0))c.notes=r;a=new DGlyph(y,q.min(),q.max(),g);a.strand=m;a.bump=true;if(i||s&&(s.LABEL||s.LABELS)){a.label=c.label||i;if((i=e.groupsToSupers[c.id])&&e.superGroups[i])if(c.id!=
e.superGroups[i][0])a.label=null}if(p)a.quant=p;return a}
function glyphForFeature(a,b,c,e,d){var f=e.browser.scale,h=e.browser.origin,g=c.glyph||"BOX",i,j=a.min,r=a.max,q=a.orientation,m=a.score,p=(j-h)*f,o=(r-h+1)*f,s,u;if(g=="HIDDEN"||a.parts)i=null;else if(g=="CROSS"||g=="EX"||g=="SPAN"||g=="LINE"||g=="DOT"||g=="TRIANGLE"){h=c.FGCOLOR||"black";var v=c.BGCOLOR||"none";d=c.HEIGHT||d||12;s=d=1*d;i=(p+o)/2;m=d/2;var t;f=p;e=o;if(g=="CROSS"){t=document.createElementNS(NS_SVG,"path");t.setAttribute("fill","none");t.setAttribute("stroke",h);t.setAttribute("stroke-width",
1);t.setAttribute("d","M "+(i-m)+" "+(b+m)+" L "+(i+m)+" "+(b+m)+" M "+i+" "+b+" L "+i+" "+(b+d));f=Math.min(p,i-m);e=Math.max(o,i+m)}else if(g=="EX"){t=document.createElementNS(NS_SVG,"path");t.setAttribute("fill","none");t.setAttribute("stroke",h);t.setAttribute("stroke-width",1);t.setAttribute("d","M "+(i-m)+" "+b+" L "+(i+m)+" "+(b+d)+" M "+(i+m)+" "+b+" L "+(i-m)+" "+(b+d));f=Math.min(p,i-m);e=Math.max(o,i+m)}else if(g=="SPAN"){t=document.createElementNS(NS_SVG,"path");t.setAttribute("fill",
"none");t.setAttribute("stroke",h);t.setAttribute("stroke-width",1);t.setAttribute("d","M "+p+" "+(b+m)+" L "+o+" "+(b+m)+" M "+p+" "+b+" L "+p+" "+(b+d)+" M "+o+" "+b+" L "+o+" "+(b+d))}else if(g=="LINE"){i=c.STYLE||"solid";t=document.createElementNS(NS_SVG,"path");t.setAttribute("fill","none");t.setAttribute("stroke",h);t.setAttribute("stroke-width",1);if(i=="hat"){h=0;if(a.orientation=="-")h=d;t.setAttribute("d","M "+p+" "+(b+m)+" L "+(o+p)/2+" "+(b+h)+" L "+o+" "+(b+m))}else t.setAttribute("d",
"M "+p+" "+(b+m)+" L "+o+" "+(b+m));i=="dashed"&&t.setAttribute("stroke-dasharray","3")}else if(g=="DOT"){t=document.createElementNS(NS_SVG,"circle");t.setAttribute("fill",h);t.setAttribute("stroke","none");t.setAttribute("cx",i);t.setAttribute("cy",b+m);t.setAttribute("r",m);f=Math.min(p,i-m);e=Math.max(o,i+m)}else if(g=="TRIANGLE"){f=c.DIRECTION||"N";if(f==="FORWARD")f=q==="-"?"W":"E";else if(f==="REVERSE")f=q==="-"?"E":"W";e=c.LINEWIDTH||d;halfHeight=0.5*d;halfWidth=0.5*e;t=document.createElementNS(NS_SVG,
"path");if(f=="E")t.setAttribute("d","M "+(i-halfWidth)+" 0 L "+(i-halfWidth)+" "+d+" L "+(i+halfWidth)+" "+halfHeight+" Z");else if(f=="W")t.setAttribute("d","M "+(i+halfWidth)+" 0 L "+(i+halfWidth)+" "+d+" L "+(i-halfWidth)+" "+halfHeight+" Z");else f=="S"?t.setAttribute("d","M "+(i+halfWidth)+" 0 L "+(i-halfWidth)+" 0 L "+i+" "+d+" Z"):t.setAttribute("d","M "+(i+halfWidth)+" "+d+" L "+(i-halfWidth)+" "+d+" L "+i+" 0 Z");f=Math.min(p,i-halfWidth);e=Math.max(o,i+halfWidth);t.setAttribute("fill",
h);t.setAttribute("stroke","none")}i=document.createElementNS(NS_SVG,"g");if(v=="none"||f<p||e>o){h=document.createElementNS(NS_SVG,"rect");h.setAttribute("x",f);h.setAttribute("y",b);h.setAttribute("width",e-f);h.setAttribute("height",d);h.setAttribute("stroke","none");h.setAttribute("fill","none");h.setAttribute("pointer-events","all");i.appendChild(h)}if(v!="none"){h=document.createElementNS(NS_SVG,"rect");h.setAttribute("x",p);h.setAttribute("y",b);h.setAttribute("width",o-p);h.setAttribute("height",
d);h.setAttribute("stroke","none");h.setAttribute("fill",v);h.setAttribute("pointer-events","all");i.appendChild(h)}i.appendChild(t)}else if(g=="PRIMERS"){b=c.BGCOLOR||"black";d=c.HEIGHT||d||12;s=d=1*d;i=document.createElementNS(NS_SVG,"g");h=document.createElementNS(NS_SVG,"path");h.setAttribute("stroke",b);h.setAttribute("fill","none");h.setAttribute("d","M "+p+" "+d/2+" L "+o+" "+d/2);i.appendChild(h);b=document.createElementNS(NS_SVG,"path");b.setAttribute("stroke","none");b.setAttribute("fill",
"arrowColor");b.setAttribute("d","M "+p+" 0 L "+p+" "+d+" L "+(p+d)+" "+d/2+" Z M "+o+" 0 L "+o+" "+d+" L "+(o-d)+" "+d/2+" Z");i.appendChild(b)}else if(g=="ARROW"){g=c.PARALLEL?c.PARALLEL=="yes":true;b=c.NORTHEAST&&c.NORTHEAST=="yes";e=c.SOUTHWEST&&c.SOUTHWEST=="yes";h=c.FGCOLOR||"none";v=c.BGCOLOR||"green";d=c.HEIGHT||d||12;s=d=1*d;t=g?0.5*d:0.25*d;q=(o+p)/2;f=g?0.25*d:0.4*d;if(g){if(b&&o-q<d)o=q+d;if(e&&q-p<d)p=q-d}else if(o-p<0.75*d){p=q-0.375*d;o=q+0.375*d}i=document.createElementNS(NS_SVG,"path");
i.setAttribute("fill",v);i.setAttribute("stroke",h);h!="none"&&i.setAttribute("stroke-width",1);if(g){h="M "+q+" "+f;h+=b?" L "+(o-t)+" "+f+" L "+(o-t)+" 0 L "+o+" "+d/2+" L "+(o-t)+" "+d+" L "+(o-t)+" "+(d-f):" L "+o+" "+f+" L "+o+" "+(d-f);h+=e?" L "+(p+t)+" "+(d-f)+" L "+(p+t)+" "+d+" L "+p+" "+d/2+" L "+(p+t)+" 0 L "+(p+t)+" "+f:" L "+p+" "+(d-f)+" L "+p+" "+f}else{h="M "+(p+f)+" "+d/2;h+=b?" L "+(p+f)+" "+t+" L "+p+" "+t+" L "+q+" 0 L "+o+" "+t+" L "+(o-f)+" "+t:" L "+(p+f)+" 0 L "+(o-f)+" 0";
h+=e?" L "+(o-f)+" "+(d-t)+" L "+o+" "+(d-t)+" L "+q+" "+d+" L "+p+" "+(d-t)+" L "+(p+f)+" "+(d-t):" L "+(o-f)+" "+d+" L "+(p+f)+" "+d}h+=" Z";i.setAttribute("d",h);i=i}else if(g=="ANCHORED_ARROW"){h=c.FGCOLOR||"none";v=c.BGCOLOR||"green";d=c.HEIGHT||d||12;s=d=1*d;g=e=0;i=d+2;f=0.333333*d;if(a.orientation)if(a.orientation=="+")g=d/2;else if(a.orientation=="-")e=d/2;if(o-p<i){p=(o+p-i)/2;o=p+i}i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("fill",v);i.setAttribute("stroke",
h);h!="none"&&i.setAttribute("stroke-width",1);i.setAttribute("d","M "+(p+e)+" "+(b+f)+" L "+(o-g)+" "+(b+f)+" L "+(o-g)+" "+b+" L "+o+" "+(b+d/2)+" L "+(o-g)+" "+(b+d)+" L "+(o-g)+" "+(b+f+f)+" L "+(p+e)+" "+(b+f+f)+" L "+(p+e)+" "+(b+d)+" L "+p+" "+(b+d/2)+" L "+(p+e)+" "+b+" L "+(p+e)+" "+(b+f));i=i}else if(g=="TEXT"){v=c.FGCOLOR||"none";b=c.BGCOLOR||"none";d=c.HEIGHT||d||12;i=c.STRING;s=d;if(i){i=makeElementNS(NS_SVG,"text",i,{stroke:"none",fill:v});e.viewport.appendChild(i);v=i.getBBox();e.viewport.removeChild(i);
i.setAttribute("x",(p+o-v.width)/2);i.setAttribute("y",d-2);i=b=="none"?i:makeElementNS(NS_SVG,"g",[makeElementNS(NS_SVG,"rect",null,{x:p,y:0,width:o-p,height:d,fill:b,stroke:"none"}),i]);if(v.width>o-p){r=p+v.width;j=((p+o-v.width)/2/f|0)+h;r=(r/f|0)+h}}else i=null}else{h=c.FGCOLOR||"none";v=c.BGCOLOR||c.COLOR1||"green";d=c.HEIGHT||d||12;s=d=1*d;if(c.WIDTH){t=c.WIDTH|0;p=(o+p-t)/2;o=p+t}else if(o-p<MIN_FEATURE_PX){p=(o+p-MIN_FEATURE_PX)/2;o=p+MIN_FEATURE_PX}if((g=="HISTOGRAM"||g=="GRADIENT")&&m!==
"undefined"){t=e.dasSource.forceMin||c.MIN||e.currentFeaturesMinScore;(q=e.dasSource.forceMax||c.MAX||e.currentFeaturesMaxScore)||(q=t<0?0:10);t||(t=0);if(1*m<1*t)m=t;if(1*m>1*q)m=q;m=(1*m-t)/(q-t);if(c.COLOR2){var y,A;if(c.COLOR3)if(m<0.5){v=dasColourForName(c.COLOR1);y=dasColourForName(c.COLOR2);A=m*2}else{v=dasColourForName(c.COLOR2);y=dasColourForName(c.COLOR3);A=m*2-1}else{v=dasColourForName(c.COLOR1);y=dasColourForName(c.COLOR2);A=m}v=(new DColour(v.red*(1-A)+y.red*A|0,v.green*(1-A)+y.green*
A|0,v.blue*(1-A)+y.blue*A|0)).toSvgString()}if(g=="HISTOGRAM"){u=-1*t/(q-t);if(m>=u){d=Math.max(1,(m-u)*s);b=b+(1-u)*s-d}else{d=Math.max(1,(u-m)*s);b+=(1-u)*s}u={min:t,max:q}}p-=0.25;o+=0.25}t=document.createElementNS(NS_SVG,"rect");t.setAttribute("x",p);t.setAttribute("y",b);t.setAttribute("width",o-p);t.setAttribute("height",d);t.setAttribute("stroke",h);t.setAttribute("stroke-width",1);t.setAttribute("fill",v);if(a.visualWeight&&a.visualWeight<1){t.setAttribute("fill-opacity",a.visualWeight);h!=
"none"&&t.setAttribute("stroke-opacity",a.visualWeight)}if(g=="TOOMANY"){b=[t];for(v=3;v<d;v+=3)b.push(makeElementNS(NS_SVG,"line",null,{x1:p,y1:v,x2:o,y2:v,stroke:h,strokeWidth:0.5}));i=makeElementNS(NS_SVG,"g",b)}else if(a.seq&&f>=1){if(e.currentSequence)i=e.currentSequence;o=a.seq.toUpperCase();h=[];for(v=0;v<o.length;++v){g=o.substr(v,1);e=null;if(i&&i.seq&&i.start<=j&&i.end>=r)if(i.seq.substr((j|0)+(v|0)-(i.start|0),1).toUpperCase()!==g)e="red";e||(e="gray");if(f>=8){s=document.createElementNS(NS_SVG,
"text");s.setAttribute("x",p+v*f);s.setAttribute("y",12);s.setAttribute("stroke","none");s.setAttribute("fill",e);s.appendChild(document.createTextNode(g));h.push(s);s=14}else{g=document.createElementNS(NS_SVG,"rect");g.setAttribute("x",p+v*f);g.setAttribute("y",b);g.setAttribute("height",d);g.setAttribute("width",f);g.setAttribute("fill",e);g.setAttribute("stroke","none");h.push(g)}}if(f>=8){j-=1;r+=1}else{j=Math.floor(j-1/f)|0;r=Math.ceil(r+1/f)|0}i=makeElementNS(NS_SVG,"g",h)}else i=t}if(i)i.dalliance_feature=
a;j=new DGlyph(i,j,r,s);if(c.LABEL&&(a.label||a.id))j.label=a.label||a.id;if(c.BUMP)j.bump=true;j.strand=a.orientation||"0";if(u)j.quant=u;j.zindex=c.ZINDEX||0;return j}
function labelGlyph(a,b,c){var e=a.browser.scale;a=a.browser.origin;if(b.glyph&&b.label){var d=b.label,f=document.createElementNS(NS_SVG,"text");f.setAttribute("x",(b.min-a)*e);f.setAttribute("y",b.height+15);f.setAttribute("stroke-width",0);f.setAttribute("fill","black");f.setAttribute("class","label-text");f.setAttribute("font-family","helvetica");f.setAttribute("font-size","10pt");if(b.strand=="+")d+=">";else if(b.strand=="-")d="<"+d;f.appendChild(document.createTextNode(d));c.appendChild(f);d=
f.getBBox().width;c.removeChild(f);if(b.glyph.localName=="g")c=b.glyph;else{c=document.createElementNS(NS_SVG,"g");c.appendChild(b.glyph)}c.appendChild(f);b.glyph=c;b.height+=20;c=(b.min|0)+(d+10)/e;if(c>b.max){d=(c-b.max)/2;var h=(b.min-d-a)*e+5;f.setAttribute("x",h);b.min=h/e+a|0;b.max=c-d|0}else{f.jiggleMin=(b.min-a)*e;f.jiggleMax=(b.max-a)*e-d}}return b}function Karyoscape(a,b){this.browser=a;this.dsn=b;this.svg=makeElementNS(NS_SVG,"g");this.width=250}
Karyoscape.prototype.update=function(a,b,c){this.start=b;this.end=c;if(!this.chr||a!=this.chr){this.chr=a;removeChildren(this.svg);var e=this;this.dsn.features(new DASSegment(a),{type:"karyotype"},function(d,f,h){e.chrLen=h&&h[a]&&h[a].max?h[a].max:null;e.karyos=d||[];e.redraw()})}else this.setThumb()};
var karyo_palette={gneg:"white",gpos25:"rgb(200,200,200)",gpos33:"rgb(180,180,180)",gpos50:"rgb(128,128,128)",gpos66:"rgb(100,100,100)",gpos75:"rgb(64,64,64)",gpos100:"rgb(0,0,0)",gpos:"rgb(0,0,0)",gvar:"rgb(100,100,100)",acen:"rgb(100,100,100)",stalk:"rgb(100,100,100)"};
Karyoscape.prototype.redraw=function(){removeChildren(this.svg);this.karyos=this.karyos.sort(function(q,m){return(q.min|0)-(m.min|0)});if(this.karyos.length>0){if(!this.chrLen)this.chrLen=this.karyos[this.karyos.length-1].max}else{if(!this.chrLen){alert("Warning: insufficient data to set up spatial navigator");this.chrLen=2E8}this.karyos.push({min:1,max:this.chrLen,label:"gneg"})}for(var a=null,b=0;b<this.karyos.length;++b){var c=this.karyos[b],e=1*c.min/this.chrLen*this.width,d=1*c.max/this.chrLen*
this.width,f=karyo_palette[c.label];if(f)if(d>e){e=makeElementNS(NS_SVG,"rect",null,{x:e,y:c.label=="stalk"||c.label=="acen"?5:0,width:d-e,height:c.label=="stalk"||c.label=="acen"?5:15,stroke:"none",fill:f});if(c.label.substring(0,1)=="g"){d=new Range(c.min,c.max);a=a==null?d:union(a,d)}this.browser.makeTooltip(e,c.id);this.svg.appendChild(e)}}if(a){a=a.ranges();b="M 0 10 L 0 0";c="M 0 5 L 0 15";for(var h=f=0;h<a.length;++h){d=a[h];e=1*d.min()/this.chrLen*this.width;d=1*d.max()/this.chrLen*this.width;
if(e-f>0.75){b+=" M "+e+" 0";c+=" M "+e+" 15"}b+=" L "+d+" 0";c+=" L "+d+" 15";f=d}if(this.width-f>0.75){b+=" M "+this.width+" 0";c+=" M "+this.width+" 15"}else{b+=" L "+this.width+" 0";c+=" L "+this.width+" 15"}b+=" L "+this.width+" 10";c+=" L "+this.width+" 5";this.svg.appendChild(makeElementNS(NS_SVG,"path",null,{d:b+" "+c,stroke:"black",strokeWidth:2,fill:"none"}))}this.thumb=makeElementNS(NS_SVG,"rect",null,{x:50,y:-5,width:8,height:25,fill:"blue",fillOpacity:0.5,stroke:"none"});this.svg.appendChild(this.thumb);
this.setThumb();var g=this,i,j=function(q){q.stopPropagation();q.preventDefault();g.thumb.setAttribute("x",Math.max(-4,Math.min(q.clientX+i,g.width-4)))},r=function(q){q.stopPropagation();q.preventDefault();g.onchange&&g.onchange(1*((g.thumb.getAttribute("x")|0)+4)/g.width,true);document.removeEventListener("mousemove",j,true);document.removeEventListener("mouseup",r,true)};this.thumb.addEventListener("mousedown",function(q){q.stopPropagation();q.preventDefault();i=g.thumb.getAttribute("x")-q.clientX;
document.addEventListener("mousemove",j,true);document.addEventListener("mouseup",r,true)},false)};Karyoscape.prototype.setThumb=function(){var a=1*(((this.start|0)+(this.end|0))/2)/this.chrLen*this.width;this.thumb&&this.thumb.setAttribute("x",a-4)};function FetchPool(){this.reqs=[]}FetchPool.prototype.addRequest=function(a){this.reqs.push(a)};FetchPool.prototype.abortAll=function(){for(var a=0;a<this.reqs.length;++a)this.reqs[a].abort()};
function KSCacheBaton(a,b,c,e,d,f){this.chr=a;this.min=b;this.max=c;this.scale=e;this.features=d||[];this.status=f}KSCacheBaton.prototype.toString=function(){return this.chr+":"+this.min+".."+this.max+";scale="+this.scale};function KnownSpace(a,b,c,e,d,f){this.tierMap=a;this.chr=b;this.min=c;this.max=e;this.scale=d;this.seqSource=f||new DummySequenceSource;this.featureCache={}}KnownSpace.prototype.bestCacheOverlapping=function(){var a=this.featureCache[this.tierMap[0]];return a?a:null};
KnownSpace.prototype.viewFeatures=function(a,b,c,e){if(e!=e)throw"viewFeatures called with silly scale";if(a!=this.chr)throw"Can't extend Known Space to a new chromosome";this.min=b;this.max=c;this.scale=e;this.pool&&this.pool.abortAll();this.pool=new FetchPool;this.awaitedSeq=new Awaited;this.seqWasFetched=false;this.startFetchesForTiers(this.tierMap)};
function filterFeatures(a,b,c){var e=[];featuresByGroup={};for(var d=0;d<a.length;++d){var f=a[d];if(!f.min||!f.max)e.push(f);else if(f.groups&&f.groups.length>0)pusho(featuresByGroup,f.groups[0].id,f);else f.min<=c&&f.max>=b&&e.push(f)}for(var h in featuresByGroup){a=featuresByGroup[h];var g=1E11,i=-100000000000;for(d=0;d<a.length;++d){f=a[d];g=Math.min(g,f.min);i=Math.max(i,f.max)}if(g<=c||i>=b)for(d=0;d<a.length;++d)e.push(a[d])}return e}
KnownSpace.prototype.invalidate=function(a){this.featureCache[a]=null;this.startFetchesForTiers([a])};
KnownSpace.prototype.startFetchesForTiers=function(a){for(var b=this,c=this.awaitedSeq,e=false,d=0;d<a.length;++d)if(this.startFetchesFor(a[d],c))e=true;if(e&&!this.seqWasFetched){this.seqWasFetched=true;var f=this.min,h=this.max;if(this.cs)if(this.cs.start<=f&&this.cs.end>=h){a=this.cs.start==f&&this.cs.end==h?this.cs:new DASSequence(this.cs.name,f,h,this.cs.alphabet,this.cs.seq.substring(f-this.cs.start,h+1-this.cs.start));return c.provide(a)}this.seqSource.fetch(this.chr,f,h,this.pool,function(g,
i){if(i){if(!b.cs||f<=b.cs.start&&h>=b.cs.end||f>=b.cs.end||h<=b.cs.start||h-f>b.cs.end-b.cs.start)b.cs=i;c.provide(i)}else dlog("Noseq: "+miniJSONify(g))})}};
KnownSpace.prototype.startFetchesFor=function(a,b){var c=this,e=a.getSource()||new DummyFeatureSource,d=a.needsSequence(this.scale),f=c.featureCache[a],h=a.getDesiredTypes(this.scale);if(h===undefined)return false;if(f&&f.chr===this.chr&&f.min<=this.min&&f.max>=this.max){var g=f.features;if(f.min<this.min||f.max>this.max)g=filterFeatures(g,this.min,this.max);c.provision(a,f.chr,Math.max(f.min,this.min),Math.min(f.max,this.max),f.scale,h,g,f.status,d?b:null);g=e.getScales();if(f.scale<=this.scale||
!g)return d}e.fetch(this.chr,this.min,this.max,this.scale,h,this.pool,function(i,j,r){if(!f||c.min<f.min||c.max>f.max)c.featureCache[a]=new KSCacheBaton(c.chr,c.min,c.max,r,j,i);c.provision(a,c.chr,c.min,c.max,c.scale,h,j,i,d?b:null)});return d};
KnownSpace.prototype.provision=function(a,b,c,e,d,f,h,g,i){if(g)a.updateStatus(g);else{if(d<this.scale/2&&h.length>200||BWGFeatureSource.prototype.isPrototypeOf(a.getSource())&&f&&f.length==1&&f.indexOf("density")>=0||BAMFeatureSource.prototype.isPrototypeOf(a.getSource())&&f&&f.length==1&&f.indexOf("density")>=0)h=downsample(h,this.scale);i?i.await(function(j){a.viewFeatures(b,c,e,d,h,j)}):a.viewFeatures(b,c,e,d,h)}};function DASFeatureSource(a){this.dasSource=a}
DASFeatureSource.prototype.fetch=function(a,b,c,e,d,f,h){if(d&&d.length==0)h(null,[],e);else if(this.dasSource.uri){var g=this.dasSource.maxbins!==false;d={type:d};if(g)d.maxbins=1+((c-b)/e|0);this.dasSource.features(new DASSegment(a,b,c),d,function(i,j){var r=e;g||(r=0.1);h(j,i,r)})}};function DASSequenceSource(a){this.dasSource=a}DASSequenceSource.prototype.fetch=function(a,b,c,e,d){this.dasSource.sequence(new DASSegment(a,b,c),function(f){return f.length==1?d(null,f[0]):d("Didn't get sequence")})};
function TwoBitSequenceSource(a){var b=this;this.source=a;this.twoBit=new Awaited;makeTwoBit(new URLFetchable(a.twoBitURI),function(c,e){e?dlog(e):b.twoBit.provide(c)})}TwoBitSequenceSource.prototype.fetch=function(a,b,c,e,d){this.twoBit.await(function(f){f.fetch(a,b,c,function(h,g){if(g)return d(g,null);else{var i=new DASSequence(a,b,c,"DNA",h);return d(null,i)}})})};DASFeatureSource.prototype.getScales=function(){return[]};var bwg_preflights={};
function BWGFeatureSource(a,b){var c=this;this.bwgSource=a;this.opts=b||{};c.bwgHolder=new Awaited;if(this.opts.preflight){var e=bwg_preflights[this.opts.preflight];if(!e){e=new Awaited;bwg_preflights[this.opts.preflight]=e;var d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)d.status==200?e.provide("success"):e.provide("failure")};d.open("get",this.opts.preflight+"?"+hex_sha1("salt"+Date.now()),true);if(this.opts.credentials)d.withCredentials=true;d.send("")}e.await(function(f){f===
"success"&&c.init()})}else c.init()}function BAMFeatureSource(a,b){var c=this;this.bamSource=a;this.opts=b||{};this.bamHolder=new Awaited;var e,d;if(a.bamBlob){e=new BlobFetchable(a.bamBlob);d=new BlobFetchable(a.baiBlob)}else{e=new URLFetchable(a.bamURI);d=new URLFetchable(a.baiURI||a.bamURI+".bai")}makeBam(e,d,function(f){c.bamHolder.provide(f)})}
BAMFeatureSource.prototype.fetch=function(a,b,c,e,d,f,h){this.bamHolder.await(function(g){g.fetch(a,b,c,function(i,j){if(j)h(j,null,null);else{for(var r=[],q=0;q<i.length;++q){var m=i[q],p=new DASFeature;p.min=m.pos+1;p.max=m.pos+m.seq.length;p.segment=m.segment;p.type="bam";p.id=m.readName;p.notes=["Sequence="+m.seq,"CIGAR="+m.cigar,"MQ="+m.mq];p.seq=m.seq;r.push(p)}h(null,r,1E9)}})})};BAMFeatureSource.prototype.getScales=function(){return 1E9};
BWGFeatureSource.prototype.init=function(){var a=this,b,c;if(this.bwgSource.bwgURI){b=makeBwgFromURL;c=this.bwgSource.bwgURI}else{b=makeBwgFromFile;c=this.bwgSource.bwgBlob}b(c,function(e){a.bwgHolder.provide(e)},this.opts.credentials)};
BWGFeatureSource.prototype.fetch=function(a,b,c,e,d,f,h){var g=this;this.bwgHolder.await(function(i){if(i==null)return h("Can't access binary file",null,null);var j=!d||d.length==0||arrayIndexOf(d,"density")>=0;if(g.opts.clientBin)j=false;if(i.type=="bigwig"||j||typeof g.opts.forceReduction!=="undefined"){j=-1;for(var r=0;r<i.zoomLevels.length;++r)if(i.zoomLevels[r].reduction<=e)j=r;else break;if(typeof g.opts.forceReduction!=="undefined")j=g.opts.forceReduction;i=j<0?i.getUnzoomedView():i.getZoomedView(j)}else i=
i.getUnzoomedView();i.readWigData(a,b,c,function(q){var m=1E9,p=(c-b)/q.length/2;if(p<m)m=p;h(null,q,m)})})};BWGFeatureSource.prototype.getScales=function(){var a=this.bwgHolder.res;if(a){for(var b=[1],c=0;c<a.zoomLevels.length;++c)b.push(a.zoomLevels[c].reduction);return b}else return null};function MappedFeatureSource(a,b){this.source=a;this.mapping=b}MappedFeatureSource.prototype.getScales=function(){return this.source.getScales()};
MappedFeatureSource.prototype.fetch=function(a,b,c,e,d,f,h){var g=this;this.mapping.sourceBlocksForRange(a,b,c,function(i){if(i.length==0)h("No mapping available for this regions",[],e);else{i=i[0];g.source.fetch(i.name,i.start,i.end,e,d,f,function(j,r,q){var m=[];if(r)for(var p=0;p<r.length;++p){var o=r[p],s=o.segment;if(s.indexOf("chr")==0)s=s.substr(3);var u=g.mapping.mapPoint(s,o.min);s=g.mapping.mapPoint(s,o.max);if(!u||!s||u.seq!=s.seq||u.seq!=a)o.parts&&o.parts.length>0&&m.push(o);else{o.segment=
u.seq;o.min=u.pos;o.max=s.pos;if(o.min>o.max){s=o.max;o.max=o.min;o.min=s}if(u.flipped)if(o.orientation=="-")o.orientation="+";else if(o.orientation=="+")o.orientation="-";m.push(o)}}h(j,m,q)})}})};function DummyFeatureSource(){}DummyFeatureSource.prototype.getScales=function(){return null};DummyFeatureSource.prototype.fetch=function(a,b,c,e,d,f,h){return h(null,[],1E9)};function DummySequenceSource(){}DummySequenceSource.prototype.fetch=function(a,b,c,e,d){return d(null,null)};
var VALID_BOUND_RE=/^-?[0-9]+(\.[0-9]+)?$/;
Browser.prototype.makeQuantConfigButton=function(a,b){var c=this;a.addEventListener("mousedown",function(e){e.stopPropagation();e.preventDefault();c.removeAllPopups();var d=makeElement("table"),f=makeElement("input","",{value:b.min});d.appendChild(makeElement("tr",[makeElement("td","Min:"),makeElement("td",f)]));var h=makeElement("input","",{value:b.max});d.appendChild(makeElement("tr",[makeElement("td","Max:"),makeElement("td",h)]));var g=makeElement("div","Update");g.style.backgroundColor="rgb(230,230,250)";
g.style.borderStyle="solid";g.style.borderColor="blue";g.style.borderWidth="3px";g.style.padding="2px";g.style.margin="10px";g.style.width="150px";g.addEventListener("mousedown",function(i){i.stopPropagation();i.preventDefault();if(VALID_BOUND_RE.test(f.value))if(VALID_BOUND_RE.test(h.value)){b.dasSource.forceMin=f.value;b.dasSource.forceMax=h.value;c.removeAllPopups();b.draw();c.storeStatus()}else alert("Don't understand "+h.value);else alert("Don't understand "+f.value)},false);c.popit(e,"Configure: "+
b.dasSource.name,[d,g])},false)};var __DS_SCALES=[1,2,5];function ds_scale(a){return __DS_SCALES[a%__DS_SCALES.length]*Math.pow(10,a/__DS_SCALES.length|0)}function DSBin(a,b,c){this.scale=a;this.cnt=this.tot=0;this.hasScore=false;this.min=b;this.max=c;this.lap=0;this.covered=null}DSBin.prototype.score=function(){return this.cnt==0?0:this.hasScore?this.tot/this.cnt:this.lap/coverage(this.covered)};
DSBin.prototype.feature=function(a){if(a.score){this.tot+=a.score;this.hasScore=true}var b=a.max|0;a=Math.max(this.min,a.min|0);b=Math.min(this.max,b);this.lap+=1*(b-a+1);++this.cnt;b=new Range(a,b);this.covered=this.covered?union(this.covered,b):b};
function downsample(a,b){Date.now();for(var c=0;ds_scale(c+1)<b;)++c;c=ds_scale(c);for(var e=[],d=-10000000000,f=1E10,h=0;h<a.length;++h){var g=a[h];if(g.groups&&g.groups.length>0)return a;var i=g.min/c|0,j=g.max/c|0;d=Math.max(d,j);f=Math.min(f,i);for(i=i;i<=j;++i){var r=e[i];if(!r){r=new DSBin(c,i*c,(i+1)*c-1);e[i]=r}r.feature(g)}}h=[];for(i=f;i<=d;++i)if(r=e[i]){g=new DASFeature;g.segment=a[0].segment;g.min=i*c+1;g.max=(i+1)*c;g.score=r.score();g.type="density";h.push(g)}Date.now();return h}
var MIN_TILE=75,rulerTileColors=["black","white"],baseColors={A:"green",C:"blue",G:"black",T:"red"},steps=[1,2,5];function tileSizeForScale(a,b){b||(b=MIN_TILE);for(var c=steps.length;a*steps[c%steps.length]*Math.pow(10,c/steps.length|0)<b;)++c;return steps[c%steps.length]*Math.pow(10,c/steps.length|0)}
function drawGuidelines(a,b){if(a.browser.guidelineStyle=="background"){var c=tileSizeForScale(a.browser.scale,teir.browser.guidelineSpacing),e=Math.max(0,(a.browser.knownStart/c|0)*c),d=knownEnd;if(a.browser.currentSeqMax>0&&a.browser.currentSeqMax<a.browser.knownEnd)d=a.browser.currentSeqMax;for(e=e;e<=d;e+=c){var f=document.createElementNS(NS_SVG,"line");f.setAttribute("x1",(e-origin)*scale);f.setAttribute("y1",0);f.setAttribute("x2",(e-origin)*scale);f.setAttribute("y2",1E3);f.setAttribute("stroke",
"black");f.setAttribute("stroke-opacity",0.2);f.setAttribute("stroke-width",1);b.appendChild(f)}}}
function drawSeqTier(a,b){var c=a.browser.scale,e=a.knownStart,d=a.knownEnd,f=a.browser.origin,h=a.browser.currentSeqMax;if(c){for(var g=a.viewport;g.childNodes.length>0;)g.removeChild(g.firstChild);g.appendChild(a.background);drawGuidelines(a,g);var i=tileSizeForScale(c);e=Math.max(0,(e/i|0)*i);var j=d;if(h>0&&h<d)j=h;d=false;if(b&&b.seq)for(h=b.start;h<=b.end;++h){var r=b.seq.substr(h-b.start,1).toUpperCase(),q=baseColors[r];q||(q="gray");if(c>=8){var m=document.createElementNS(NS_SVG,"text");m.setAttribute("x",
(h-f)*c);m.setAttribute("y",12);m.setAttribute("stroke-width","0");m.setAttribute("fill",q);m.setAttribute("class","label-text");m.appendChild(document.createTextNode(r));g.appendChild(m)}else{m=document.createElementNS(NS_SVG,"rect");m.setAttribute("x",(h-f)*c);m.setAttribute("y",5);m.setAttribute("height",10);m.setAttribute("width",c);m.setAttribute("fill",q);m.setAttribute("stroke","none");g.appendChild(m)}}else d=true;for(;e<=j;){if(d){m=document.createElementNS(NS_SVG,"rect");m.setAttribute("x",
(e-f)*c);m.setAttribute("y",8);m.setAttribute("height",3);m.setAttribute("width",Math.min(i,j-e)*c);m.setAttribute("fill",rulerTileColors[e/i%2]);m.setAttribute("stroke-width",1);g.appendChild(m)}if(e/i%2==0){h=0;if(!d){g.appendChild(makeElementNS(NS_SVG,"line",null,{x1:(e-f)*c,y1:15,x2:(e-f)*c,y2:35,stroke:"rgb(80, 90, 150)",strokeWidth:1}));h+=3}m=document.createElementNS(NS_SVG,"text");m.setAttribute("x",(e-f)*c+h);m.setAttribute("y",30);m.setAttribute("stroke-width","0");m.setAttribute("fill",
"black");m.setAttribute("class","label-text");m.appendChild(document.createTextNode(""+e));g.appendChild(m)}e+=i}a.layoutHeight=35;a.background.setAttribute("height",35);a.scale=1;a.browser.arrangeTiers()}}var hexcase=0,b64pad="";function hex_sha1(a){return rstr2hex(rstr_sha1(str2rstr_utf8(a)))}function b64_sha1(a){return rstr2b64(rstr_sha1(str2rstr_utf8(a)))}function any_sha1(a,b){return rstr2any(rstr_sha1(str2rstr_utf8(a)),b)}
function hex_hmac_sha1(a,b){return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function b64_hmac_sha1(a,b){return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function any_hmac_sha1(a,b,c){return rstr2any(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)),c)}function sha1_vm_test(){return hex_sha1("abc").toLowerCase()=="a9993e364706816aba3e25717850c26c9cd0d89d"}function rstr_sha1(a){return binb2rstr(binb_sha1(rstr2binb(a),a.length*8))}
function rstr_hmac_sha1(a,b){var c=rstr2binb(a);if(c.length>16)c=binb_sha1(c,a.length*8);for(var e=Array(16),d=Array(16),f=0;f<16;f++){e[f]=c[f]^909522486;d[f]=c[f]^1549556828}c=binb_sha1(e.concat(rstr2binb(b)),512+b.length*8);return binb2rstr(binb_sha1(d.concat(c),672))}function rstr2hex(a){for(var b=hexcase?"0123456789ABCDEF":"0123456789abcdef",c="",e,d=0;d<a.length;d++){e=a.charCodeAt(d);c+=b.charAt(e>>>4&15)+b.charAt(e&15)}return c}
function rstr2b64(a){for(var b="",c=a.length,e=0;e<c;e+=3)for(var d=a.charCodeAt(e)<<16|(e+1<c?a.charCodeAt(e+1)<<8:0)|(e+2<c?a.charCodeAt(e+2):0),f=0;f<4;f++)b+=e*8+f*6>a.length*8?b64pad:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d>>>6*(3-f)&63);return b}
function rstr2any(a,b){var c=b.length,e=[],d,f,h,g,i=Array(Math.ceil(a.length/2));for(d=0;d<i.length;d++)i[d]=a.charCodeAt(d*2)<<8|a.charCodeAt(d*2+1);for(;i.length>0;){g=[];for(d=h=0;d<i.length;d++){h=(h<<16)+i[d];f=Math.floor(h/c);h-=f*c;if(g.length>0||f>0)g[g.length]=f}e[e.length]=h;i=g}c="";for(d=e.length-1;d>=0;d--)c+=b.charAt(e[d]);e=Math.ceil(a.length*8/(Math.log(b.length)/Math.log(2)));for(d=c.length;d<e;d++)c=b[0]+c;return c}
function str2rstr_utf8(a){for(var b="",c=-1,e,d;++c<a.length;){e=a.charCodeAt(c);d=c+1<a.length?a.charCodeAt(c+1):0;if(55296<=e&&e<=56319&&56320<=d&&d<=57343){e=65536+((e&1023)<<10)+(d&1023);c++}if(e<=127)b+=String.fromCharCode(e);else if(e<=2047)b+=String.fromCharCode(192|e>>>6&31,128|e&63);else if(e<=65535)b+=String.fromCharCode(224|e>>>12&15,128|e>>>6&63,128|e&63);else if(e<=2097151)b+=String.fromCharCode(240|e>>>18&7,128|e>>>12&63,128|e>>>6&63,128|e&63)}return b}
function str2rstr_utf16le(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a.charCodeAt(c)&255,a.charCodeAt(c)>>>8&255);return b}function str2rstr_utf16be(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a.charCodeAt(c)>>>8&255,a.charCodeAt(c)&255);return b}function rstr2binb(a){for(var b=Array(a.length>>2),c=0;c<b.length;c++)b[c]=0;for(c=0;c<a.length*8;c+=8)b[c>>5]|=(a.charCodeAt(c/8)&255)<<24-c%32;return b}
function binb2rstr(a){for(var b="",c=0;c<a.length*32;c+=8)b+=String.fromCharCode(a[c>>5]>>>24-c%32&255);return b}
function binb_sha1(a,b){a[b>>5]|=128<<24-b%32;a[(b+64>>9<<4)+15]=b;for(var c=Array(80),e=1732584193,d=-271733879,f=-1732584194,h=271733878,g=-1009589776,i=0;i<a.length;i+=16){for(var j=e,r=d,q=f,m=h,p=g,o=0;o<80;o++){c[o]=o<16?a[i+o]:bit_rol(c[o-3]^c[o-8]^c[o-14]^c[o-16],1);var s=safe_add(safe_add(bit_rol(e,5),sha1_ft(o,d,f,h)),safe_add(safe_add(g,c[o]),sha1_kt(o)));g=h;h=f;f=bit_rol(d,30);d=e;e=s}e=safe_add(e,j);d=safe_add(d,r);f=safe_add(f,q);h=safe_add(h,m);g=safe_add(g,p)}return Array(e,d,f,h,
g)}function sha1_ft(a,b,c,e){if(a<20)return b&c|~b&e;if(a<40)return b^c^e;if(a<60)return b&c|b&e|c&e;return b^c^e}function sha1_kt(a){return a<20?1518500249:a<40?1859775393:a<60?-1894007588:-899497514}function safe_add(a,b){var c=(a&65535)+(b&65535);return(a>>16)+(b>>16)+(c>>16)<<16|c&65535}function bit_rol(a,b){return a<<b|a>>>32-b}
function DSlider(a,b){b||(b={});this.width=a;this.opts=b;var c=0,e=this,d;this.svg=document.createElementNS(NS_SVG,"g");this.track=document.createElementNS(NS_SVG,"path");this.track.setAttribute("fill","grey");this.track.setAttribute("stroke","grey");this.track.setAttribute("stroke-width","1");this.track.setAttribute("d","M 0 35 L "+a+" 35 L "+a+" 15 L 0 32 Z");this.svg.appendChild(this.track);this.handle=document.createElementNS(NS_SVG,"rect");this.handle.setAttribute("x",-4);this.handle.setAttribute("y",
10);this.handle.setAttribute("width",8);this.handle.setAttribute("height",30);this.handle.setAttribute("stroke","none");this.handle.setAttribute("fill","blue");this.handle.setAttribute("fill-opacity",0.5);this.svg.appendChild(this.handle);this.getValue=function(){return c};this.setValue=function(g){if(g<0)g=0;else if(g>this.width)g=this.width;c=g;this.handle.setAttribute("x",c-4)};this.setColor=function(g){this.handle.setAttribute("fill",g)};this.onchange=null;var f=function(g){g.stopPropagation();
g.preventDefault();g=Math.max(-4,Math.min(g.clientX+d,a-4));e.handle.setAttribute("x",g);c=g+4;e.onchange&&e.onchange(c,false)},h=function(g){g.stopPropagation();g.preventDefault();e.onchange&&e.onchange(c,true);document.removeEventListener("mousemove",f,true);document.removeEventListener("mouseup",h,true)};this.handle.addEventListener("mousedown",function(g){g.stopPropagation();g.preventDefault();d=e.handle.getAttribute("x")-g.clientX;document.addEventListener("mousemove",f,true);document.addEventListener("mouseup",
h,true)},false)}function Range(a,b){this._min=a|0;this._max=b|0}Range.prototype.min=function(){return this._min};Range.prototype.max=function(){return this._max};Range.prototype.contains=function(a){return a>=this._min&&a<=this._max};Range.prototype.isContiguous=function(){return true};Range.prototype.ranges=function(){return[this]};Range.prototype.toString=function(){return"["+this._min+"-"+this._max+"]"};function _Compound(a){this._ranges=a}_Compound.prototype.min=function(){return this._ranges[0].min()};
_Compound.prototype.max=function(){return this._ranges[this._ranges.length-1].max()};_Compound.prototype.contains=function(a){for(var b=0;b<this._ranges.length;++b)if(this._ranges[b].contains(a))return true;return false};_Compound.prototype.isContiguous=function(){return this._ranges.length>1};_Compound.prototype.ranges=function(){return this._ranges};_Compound.prototype.toString=function(){for(var a="",b=0;b<this._ranges.length;++b){if(b>0)a+=",";a+=this._ranges[b].toString()}return a};
function union(a,b){for(var c=a.ranges().concat(b.ranges()).sort(rangeOrder),e=[],d=c[0],f=1;f<c.length;++f){var h=c[f];if(h.min()>d.max()+1){e.push(d);d=h}else if(h.max()>d.max())d=new Range(d.min(),h.max())}e.push(d);return e.length==1?e[0]:new _Compound(e)}
function intersection(a,b){for(var c=a.ranges(),e=b.ranges(),d=c.length,f=e.length,h=0,g=0,i=[];h<d&&g<f;){a=c[h];b=e[g];var j=Math.max(a.min(),b.min()),r=Math.min(a.max(),b.max());r>=j&&i.push(new Range(j,r));if(a.max()>b.max())++g;else++h}return i.length==0?null:i.length==1?i[0]:new _Compound(i)}function coverage(a){var b=0;a=a.ranges();for(var c=0;c<a.length;++c){var e=a[c];b+=e.max()-e.min()+1}return b}
function rangeOrder(a,b){return a.min()<b.min()?-1:a.min()>b.min()?1:a.max()<b.max()?-1:b.max()>a.max()?1:0}var __tier_idSeed=0;
function DasTier(a,b,c,e){var d=this;this.id="tier"+ ++__tier_idSeed;this.browser=a;this.dasSource=new DASSource(b);this.viewport=c;this.background=e;this.req=null;this.layoutHeight=25;this.bumped=true;if(this.dasSource.collapseSuperGroups)this.bumped=false;this.y=0;this.layoutWasDone=false;var f,h;if(this.dasSource.bwgURI||this.dasSource.bwgBlob){f=new BWGFeatureSource(this.dasSource,{credentials:this.dasSource.credentials,preflight:this.dasSource.preflight,clientBin:this.dasSource.clientBin,forceReduction:this.dasSource.forceReduction});
!this.dasSource.uri&&!this.dasSource.stylesheet_uri&&f.bwgHolder.await(function(g){if(!g){d.stylesheet=new DASStylesheet;return d.browser.refreshTier(d)}if(d.dasSource.collapseSuperGroups===undefined)if(g.definedFieldCount==12&&g.fieldCount>=14){d.dasSource.collapseSuperGroups=true;d.bumped=false;d.isLabelValid=false}if(g.type=="bigbed"){d.stylesheet=new DASStylesheet;g=new DASStyle;g.glyph="BOX";g.FGCOLOR="black";g.BGCOLOR="blue";g.HEIGHT=8;g.BUMP=true;g.LABEL=true;g.ZINDEX=20;d.stylesheet.pushStyle({type:"bigwig"},
null,g);g.glyph="BOX";g.FGCOLOR="black";g.BGCOLOR="red";g.HEIGHT=10;g.BUMP=true;g.LABEL=true;g.ZINDEX=20;d.stylesheet.pushStyle({type:"bb-translation"},null,g);var i=new DASStyle;i.glyph="BOX";i.FGCOLOR="black";i.BGCOLOR="white";g.HEIGHT=10;i.ZINDEX=10;i.BUMP=true;d.stylesheet.pushStyle({type:"bb-transcript"},null,i);g=new DASStyle;g.glyph="HISTOGRAM";g.COLOR1="white";g.COLOR2="black";g.HEIGHT=30;d.stylesheet.pushStyle({type:"density"},null,g)}else{d.stylesheet=new DASStylesheet;g=new DASStyle;g.glyph=
"HISTOGRAM";g.COLOR1="white";g.COLOR2="black";g.HEIGHT=30;d.stylesheet.pushStyle({type:"default"},null,g)}d.browser.refreshTier(d)})}else if(this.dasSource.bamURI||this.dasSource.bamBlob){f=new BAMFeatureSource(this.dasSource,{credentials:this.dasSource.credentials});!this.dasSource.uri&&!this.dasSource.stylesheet_uri&&f.bamHolder.await(function(){d.stylesheet=new DASStylesheet;var g=new DASStyle;g.glyph="HISTOGRAM";g.COLOR1="black";g.COLOR2="red";g.HEIGHT=30;d.stylesheet.pushStyle({type:"density"},
"low",g);d.stylesheet.pushStyle({type:"density"},"medium",g);g=new DASStyle;g.glyph="BOX";g.FGCOLOR="black";g.BGCOLOR="blue";g.HEIGHT=8;g.BUMP=true;g.LABEL=false;g.ZINDEX=20;d.stylesheet.pushStyle({type:"bam"},"high",g);d.browser.refreshTier(d)})}else if(this.dasSource.tier_type=="sequence")h=this.dasSource.twoBitURI?new TwoBitSequenceSource(this.dasSource):new DASSequenceSource(this.dasSource);else f=new DASFeatureSource(this.dasSource);if(this.dasSource.mapping)f=new MappedFeatureSource(f,this.browser.chains[this.dasSource.mapping]);
this.featureSource=f;this.sequenceSource=h;this.setBackground()}DasTier.prototype.toString=function(){return this.id};
DasTier.prototype.init=function(){var a=this;if(a.dasSource.uri||a.dasSource.stylesheet_uri){a.status="Fetching stylesheet";this.dasSource.stylesheet(function(c){a.stylesheet=c;a.browser.refreshTier(a)},function(){a.stylesheet=new DASStylesheet;var c=new DASStyle;c.glyph="BOX";c.BGCOLOR="blue";c.FGCOLOR="black";a.stylesheet.pushStyle({type:"default"},null,c);a.browser.refreshTier(a)})}else if(a.dasSource.twoBitURI){a.stylesheet=new DASStylesheet;var b=new DASStyle;b.glyph="BOX";b.BGCOLOR="blue";b.FGCOLOR=
"black";a.stylesheet.pushStyle({type:"default"},null,b);a.browser.refreshTier(a)}};DasTier.prototype.styles=function(){return this.stylesheet==null?null:this.browser.scale>0.2?this.stylesheet.highZoomStyles:this.browser.scale>0.01?this.stylesheet.mediumZoomStyles:this.stylesheet.lowZoomStyles};DasTier.prototype.getSource=function(){return this.featureSource};
DasTier.prototype.getDesiredTypes=function(){var a=[],b=false,c=zoomForScale(this.browser.scale);if(this.stylesheet){for(var e=this.stylesheet.styles,d=0;d<e.length;++d){var f=e[d];if(!f.zoom||f.zoom==c)if(!f.type||f.type=="default"){b=true;break}else pushnew(a,f.type)}return b?null:a}};DasTier.prototype.needsSequence=function(a){if(this.dasSource.tier_type==="sequence"&&a<5)return true;else if((this.dasSource.bamURI||this.dasSource.bamBlob)&&a<20)return true;return false};
DasTier.prototype.setStatus=function(a){dlog(a)};DasTier.prototype.viewFeatures=function(a,b,c,e,d,f){this.currentFeatures=d;this.currentSequence=f;this.knownChr=a;this.knownStart=b;this.knownEnd=c;this.error=this.status=null;this.setBackground();this.draw()};DasTier.prototype.updateStatus=function(a){if(a){this.currentFeatures=[];this.currentSequence=null;this.error=a}this.setBackground();this.draw()};
DasTier.prototype.draw=function(){var a=this.currentSequence;this.dasSource.tier_type==="sequence"?drawSeqTier(this,a):drawFeatureTier(this);this.originHaxx=0;this.browser.arrangeTiers()};function zoomForScale(a){return a>0.2?"high":a>0.01?"medium":"low"}DasTier.prototype.setBackground=function(){var a=this.knownEnd||-100000001;this.background.setAttribute("x",((this.knownStart||-100000000)-this.browser.origin)*this.browser.scale);this.background.setAttribute("width",(a-this.knownStart+1)*this.browser.scale)};
Browser.prototype.currentlyActive=function(a){for(var b=0;b<this.tiers.length;++b){var c=this.tiers[b].dasSource;if(c.uri==a.uri||c.uri==a.uri+"/"){if(c.tier_type)if(!a.tier_type||a.tier_type!=c.tier_type)continue;if(c.stylesheet_uri)if(!a.stylesheet_uri||a.stylesheet_uri!=c.stylesheet_uri)continue;return true}}return false};
Browser.prototype.makeButton=function(a,b){var c=makeElement("span",a);c.style.backgroundColor="rgb(230,230,250)";c.style.borderStyle="solid";c.style.borderColor="red";c.style.borderWidth="3px";c.style.padding="4px";c.style.marginLeft="10px";c.style.marginRight="10px";c.style["float"]="left";b&&this.makeTooltip(c,b);return c};function activateButton(a,b){for(var c=0;c<a.length;++c){var e=a[c];e.style.borderColor=e==b?"red":"blue"}}
Browser.prototype.showTrackAdder=function(a){function b(){B="bin";P.style.visibility="hidden";removeChildren(z);if(g.supportsBinary){z.appendChild(makeElement("h2","Add custom URL-based data"));z.appendChild(makeElement("p",["You can add indexed binary data hosted on an web server that supports CORS (",makeElement("a","full details",{href:"http://www.biodalliance.org/bin.html"}),"). Currently supported formats are bigwig, bigbed, and indexed BAM."]));z.appendChild(makeElement("br"));z.appendChild(document.createTextNode("URL: "));
y=makeElement("input","",{size:80,value:"http://www.biodalliance.org/datasets/ensGene.bb"});z.appendChild(y);y.focus();z.appendChild(makeElement("br"));z.appendChild(makeElement("b","- or -"));z.appendChild(makeElement("br"));z.appendChild(document.createTextNode("File: "));w=makeElement("input",null,{type:"file"});z.appendChild(w);z.appendChild(makeElement("p",'Clicking the "Add" button below will initiate a series of test queries.'))}else{z.appendChild(makeElement("h2","Your browser does not support binary data"));
z.appendChild(makeElement("p","Browsers currently known to support this feature include Google Chrome 9 or later and Mozilla Firefox 4 or later."))}}function c(){if(B)if(B==="das"){var x=y.value.trim();/^.+:\/\//.exec(x)||(x="http://"+x);x=new DASSource({name:"temporary",uri:x});F(x)}else if(B==="bin"){var E={name:"temporary"};if((x=w.files)&&x.length>0&&x[0]){E.bwgBlob=x[0];E.noPersist=true}else{x=y.value.trim();/^.+:\/\//.exec(x)||(x="http://"+x);E.bwgURI=x}x=new DASSource(E);J(x)}else if(B==="reset")O();
else if(B==="reset-bin")b();else if(B==="prompt-bai")if((x=w.files)&&x.length>0&&x[0]){C.baiBlob=x[0];f(C)}else d(C);else{if(B==="finalize"){C.name=A.value;E=D.value;C.mapping=E!="__default__"?E:undefined;if(G)C.maxbins=G.checked;g.sources.push(C);g.makeTier(C);g.storeStatus();g.removeAllPopups()}}else{for(E=0;E<t.length;++E){x=t[E];if(x.checked){x=x.dalliance_source;g.sources.push(x);g.makeTier(x);g.storeStatus()}}g.removeAllPopups()}}function e(x,E){var I=x.uri;if(E){var M=/(.+)\/[^\/]+\/?/.exec(I);
if(M)I=M[1]+"/sources"}(new DASRegistry(I,{credentials:x.credentials})).sources(function(H){if(!H||H.length==0)return E?R(x):e(x,true);var N=null;if(H.length==1)N=H[0];else for(var K=0;K<H.length;++K)if(H[K].uri===x.uri){N=H[K];break}K=H=false;if(N){x.name=N.name;x.desc=N.desc;x.maxbins=N.maxbins?true:false;K=true;if(N.coords&&N.coords.length==1){N=N.coords[0];if(coordsMatch(N,g.coordSystem))H=true;else if(g.chains)for(var T in g.chains)if(coordsMatch(N,g.chains[T].coords)){x.mapping=T;H=true}}}return R(x,
H,K)},function(){return E?R(x):e(x,true)})}function d(x){removeChildren(z);B="prompt-bai";z.appendChild(makeElement("h2","Select an index file"));z.appendChild(makeElement("p","Dalliance requires a BAM index (.bai) file when displaying BAM data. These normally accompany BAM files. For security reasons, web applications like Dalliance can only access local files which you have explicity selected. Please use the file chooser below to select the appropriate BAI file"));z.appendChild(document.createTextNode("Index file: "));
w=makeElement("input",null,{type:"file"});z.appendChild(w);C=x}function f(x){(x.baiBlob?new BlobFetchable(x.baiBlob):new URLFetchable(x.bwgURI+".bai")).slice(0,256).fetch(function(E){var I=false;if(E){E=new Uint8Array(E);I=readInt(E,0)==BAI_MAGIC}if(I){if(E=/\/?([^\/]+?)(.bam)?$/.exec(x.bwgURI||x.bwgBlob.name))x.name=E[1];x.bamURI=x.bwgURI;x.bamBlob=x.bwgBlob;x.bwgURI=undefined;x.bwgBlob=undefined;return R(x,false,false,true)}else return h("You have selected a valid BAM file, but a corresponding index (.bai) file was not found. Please index your BAM (samtools index) and place the BAI file in the same directory")})}
function h(x){removeChildren(z);x=x||"Custom data format not recognized";z.appendChild(makeElement("h2","Error adding custom data"));z.appendChild(makeElement("p",x));z.appendChild(makeElement("p","Currently supported formats are bigBed, bigWig, and BAM."));B="reset-bin"}var g=this,i=a.clientX,j=a.clientY;i+=document.documentElement.scrollLeft||document.body.scrollLeft;j+=document.documentElement.scrollTop||document.body.scrollTop;i=document.createElement("div");i.appendChild(makeElement("div",null,
{},{clear:"both",height:"10px"}));var r=[],q,m,p=this.makeButton("Registry","Browse compatible datasources from the DAS registry");r.push(p);for(var o in this.mappableSources)(function(x){var E=g.makeButton(g.chains[x].srcTag,"Browse datasources mapped from "+g.chains[x].srcTag);r.push(E);E.addEventListener("mousedown",function(I){I.preventDefault();I.stopPropagation();activateButton(r,E);q(g.mappableSources[x],x)},false)})(o);var s=this.makeButton("Defaults","Browse the default set of data for this browser");
r.push(s);var u=this.makeButton("Custom","Add arbitrary DAS data");r.push(u);var v=this.makeButton("Binary","Add data in bigwig or bigbed format");r.push(v);activateButton(r,p);i.appendChild(makeElement("div",r),null);i.appendChild(makeElement("div",null,{},{clear:"both",height:"10px"}));var t=[],y,A,D,G,w,B=false,C=null;o=makeElement("form",null,{},{clear:"both"});o.addEventListener("submit",function(x){x.stopPropagation();x.preventDefault();c();return false},true);var z=document.createElement("div");
z.style.position="relative";z.style.overflow="auto";z.style.height="400px";o.appendChild(z);var Q,S;q=function(x,E){P.style.visibility="visible";S&&S.removeListener(m);Q=E;S=x;S.addListenerAndFire(m)};m=function(x){B=false;t=[];removeChildren(z);if(x){var E=document.createElement("table");E.style.width="100%";for(var I=0,M=[],H=0;H<x.length;++H)M.push(x[H]);M.sort(function(U,V){return U.name.toLowerCase().trim().localeCompare(V.name.toLowerCase().trim())});for(H=0;H<M.length;++H){x=M[H];var N=document.createElement("tr");
N.style.backgroundColor=g.tierBackgroundColors[I%g.tierBackgroundColors.length];var K=document.createElement("td");K.style.textAlign="center";if(g.currentlyActive(x)){K.appendChild(document.createTextNode("X"));g.makeTooltip(K,"This data source is already active.")}else if(!x.props||x.props.cors){var T=document.createElement("input");T.type="checkbox";T.dalliance_source=x;if(Q)T.dalliance_mapping=Q;K.appendChild(T);t.push(T);g.makeTooltip(K,"Check here then click 'Add' to activate.")}else{K.appendChild(document.createTextNode("!"));
g.makeTooltip(K,makeElement("span",["This data source isn't accessible because it doesn't support ",makeElement("a","CORS",{href:"http://www.w3.org/TR/cors/"}),"."]))}N.appendChild(K);K=document.createElement("td");K.appendChild(document.createTextNode(x.name));x.desc&&x.desc.length>0&&g.makeTooltip(K,x.desc);N.appendChild(K);E.appendChild(N);++I}z.appendChild(E)}else z.appendChild(makeElement("p","Dalliance was unable to retrieve data source information from the DAS registry, please try again later"))};
p.addEventListener("mousedown",function(x){x.preventDefault();x.stopPropagation();activateButton(r,p);q(g.availableSources)},false);s.addEventListener("mousedown",function(x){x.preventDefault();x.stopPropagation();activateButton(r,s);q(new Observed(g.defaultSources))},false);v.addEventListener("mousedown",function(x){x.preventDefault();x.stopPropagation();activateButton(r,v);b()},false);u.addEventListener("mousedown",function(x){x.preventDefault();x.stopPropagation();activateButton(r,u);O()},false);
var O=function(){B="das";P.style.visibility="hidden";removeChildren(z);var x=makeElement("div");x.appendChild(makeElement("h2","Add custom DAS data"));x.appendChild(makeElement("p","This interface is intended for adding custom or lab-specific data. Public data can be added more easily via the registry interface."));x.appendChild(document.createTextNode("URL: "));x.appendChild(makeElement("br"));y=makeElement("input","",{size:80,value:"http://www.derkholm.net:8080/das/medipseq_reads/"});x.appendChild(y);
x.appendChild(makeElement("p",'Clicking the "Add" button below will initiate a series of test queries. If the source is password-protected, you may be prompted to enter credentials.'));z.appendChild(x);y.focus()};j=document.createElement("span");j.style.backgroundColor="rgb(230,230,250)";j.style.borderStyle="solid";j.style.borderColor="blue";j.style.borderWidth="3px";j.style.padding="2px";j.style.margin="10px";j.style.width="150px";j.appendChild(document.createTextNode("Add"));j.addEventListener("mousedown",
function(x){x.stopPropagation();x.preventDefault();c()},false);var F=function(x,E){var I=g.knownSpace;if(I){var M=Math.max(I.min,(I.min+I.max-100)/2)|0;I=new DASSegment(I.chr,M,Math.min(M+99,I.max));x.features(I,{},function(H,N){if(N)if(E){removeChildren(z);z.appendChild(makeElement("h2","Custom data not found"));z.appendChild(makeElement("p","DAS uri: "+x.uri+" is not answering features requests"));B="reset"}else{dlog("retrying with credentials");x.credentials=true;F(x,true)}else{var K=/\/([^\/]+)\/?$/.exec(x.uri);
if(K)x.name=K[1];e(x)}})}else alert("Can't confirm track-addition to an uninit browser.")},J=function(x){(x.bwgURI?new URLFetchable(x.bwgURI):new BlobFetchable(x.bwgBlob)).slice(0,65536).fetch(function(E,I){if(E){var M=new Uint8Array(E),H=readInt(M,0);if(H==BIG_WIG_MAGIC||H==BIG_BED_MAGIC){if(M=/\/?([^\/]+?)(.bw|.bb|.bigWig|.bigBed)?$/.exec(x.bwgURI||x.bwgBlob.name))x.name=M[1];return R(x,false,false,true)}else{if(M[0]!=31||M[1]!=139)return h();M=unbgzf(E);M=new Uint8Array(M);H=readInt(M,0);return H==
BAM_MAGIC?x.bwgBlob?d(x):f(x):h()}}else{removeChildren(z);z.appendChild(makeElement("h2","Custom data not found"));x.bwgURI?z.appendChild(makeElement("p","Data URI: "+x.bwgURI+" is not accessible.")):z.appendChild(makeElement("p","File access failed, are you using an up-to-date browser?"));I&&z.appendChild(makeElement("p",""+I));z.appendChild(makeElement("p","If in doubt, please check that the server where the file is hosted supports CORS."));B="reset-bin"}})},R=function(x,E,I,M){removeChildren(z);
z.appendChild(makeElement("h2","Add custom data: step 2"));z.appendChild(document.createTextNode("Label: "));A=makeElement("input","",{value:x.name});z.appendChild(A);z.appendChild(makeElement("br"));z.appendChild(makeElement("br"));z.appendChild(makeElement("h4","Coordinate system: "));D=makeElement("select",null);D.appendChild(makeElement("option",g.coordSystem.auth+g.coordSystem.version,{value:"__default__"}));if(g.chains)for(var H in g.chains){var N=g.chains[H].coords;D.appendChild(makeElement("option",
N.auth+N.version,{value:H}))}D.value=x.mapping||"__default__";z.appendChild(D);if(E)z.appendChild(makeElement("p","(Based on server response, probably doesn't need changing.)"));else{z.appendChild(makeElement("p",[makeElement("b","Warning: "),"unable to determine the correct value from server responses. Please check carefully."]));z.appendChild(makeElement("p","If you don't see the mapping you're looking for, please contact thomas@biodalliance.org"))}if(!M){z.appendChild(document.createTextNode("Quantitative: "));
G=makeElement("input",null,{type:"checkbox",checked:true});if(typeof x.maxbins!=="undefined")G.checked=x.maxbins;z.appendChild(G);I?z.appendChild(makeElement("p","(Based on server response, probably doesn't need changing.)")):z.appendChild(makeElement("p",[makeElement("b","Warning: "),"unable to determine correct value. If in doubt, leave checked."]))}x.bwgBlob&&z.appendChild(makeElement("p",[makeElement("b","Warning: "),"data added from local file. Due to the browser security model, the track will disappear if you reload Dalliance."]));
A.focus();B="finalize";C=x},L=document.createElement("span");L.style.backgroundColor="rgb(230,230,250)";L.style.borderStyle="solid";L.style.borderColor="blue";L.style.borderWidth="3px";L.style.padding="2px";L.style.margin="10px";L.style.width="150px";L.appendChild(document.createTextNode("Cancel"));L.addEventListener("mousedown",function(x){x.stopPropagation();x.preventDefault();g.removeAllPopups()},false);var P=makeElement("span","Refresh");P.style.backgroundColor="rgb(230,230,250)";P.style.borderStyle=
"solid";P.style.borderColor="blue";P.style.borderWidth="3px";P.style.padding="2px";P.style.margin="10px";P.style.width="120px";P.addEventListener("mousedown",function(x){x.stopPropagation();x.preventDefault();g.queryRegistry(Q)},false);this.makeTooltip(P,"Click to re-fetch data from the DAS registry");j=makeElement("div",[j,L,P]);j.style.margin="10px";o.appendChild(j);i.appendChild(o);q(g.availableSources);return this.popit(a,"Add DAS data",i,{width:600})};var TWOBIT_MAGIC=440477507;
function TwoBitFile(){}
function makeTwoBit(a,b){var c=new TwoBitFile;c.data=a;c.data.slice(0,1024).fetch(function(e){if(!e)return b(null,"Couldn't access data");e=new Uint8Array(e);if(readInt(e,0)!=TWOBIT_MAGIC)return b(null,"Not a .2bit fie");var d=readInt(e,4);if(d!=0)return b(null,"Unsupported version "+d);c.seqCount=readInt(e,8);c.seqDict={};d=16;for(var f=0;f<c.seqCount;++f){for(var h=e[d++],g="",i=1;i<=h;++i)g+=String.fromCharCode(e[d++]);h=readInt(e,d);d+=4;c.seqDict[g]=new TwoBitSeq(c,h)}return b(c)})}
TwoBitFile.prototype.getSeq=function(a){var b=this.seqDict[a];b||(b=this.seqDict["chr"+a]);return b};TwoBitFile.prototype.fetch=function(a,b,c,e){var d=this.getSeq(a);if(d)d.fetch(b,c,e);else return e(null,"Couldn't find "+a)};function TwoBitSeq(a,b){this.tbf=a;this.offset=b}
TwoBitSeq.prototype.init=function(a){if(this.seqOffset)return a();var b=this;b.tbf.data.slice(b.offset,8).fetch(function(c){if(!c)return a("Fetch failed");c=new Uint8Array(c);b.length=readInt(c,0);b.nBlockCnt=readInt(c,4);b.tbf.data.slice(b.offset+8,b.nBlockCnt*8+4).fetch(function(e){if(!e)return a("Fetch failed");e=new Uint8Array(e);for(var d=null,f=0;f<b.nBlockCnt;++f){var h=readInt(e,f*4),g=readInt(e,(f+b.nBlockCnt)*4);h=new Range(h,h+g-1);d=d?union(d,h):h}b.nBlocks=d;b.mBlockCnt=readInt(e,b.nBlockCnt*
8);b.seqLength=(b.length+3)/4|0;b.seqOffset=b.offset+16+(b.nBlockCnt+b.mBlockCnt)*8;return a()})})};var TWOBIT_TABLE=["T","C","A","G"];
TwoBitSeq.prototype.fetch=function(a,b,c){--a;--b;var e=this;this.init(function(d){if(d)return c(null,d);var f=a>>2;d=b+3>>2;if(f<0||d>e.seqLength)return c("Coordinates out of bounds: "+a+":"+b);e.tbf.data.slice(e.seqOffset+f,d-f).fetch(function(h){function g(p){for(;q<=p;){var o=q&3,s=i[(q>>2)-f];r+=TWOBIT_TABLE[o==0?s>>6&3:o==1?s>>4&3:o==2?s>>2&3:s&3];++q}}if(h==null)return c("SeqFetch failed");var i=new Uint8Array(h);h=[];if(e.nBlocks){var j=intersection(new Range(a,b),e.nBlocks);if(j)h=j.ranges()}var r=
"",q=a;for(j=0;j<h.length;++j){var m=h[j];if(q>m.min())throw"N mismatch...";for(q<m.min()&&g(m.min()-1);q<m.max();){r+="N";++q}}q<b&&g(b);return c(r)})})};TwoBitSeq.prototype.length=function(a){var b=this;this.init(function(c){return c?a(null,c):a(b.length)})};var NUM_REGEXP=/[0-9]+/;function stringToNumbersArray(a){for(var b=[],c;c=NUM_REGEXP.exec(a);){b.push(c[0]);a=a.substring(c.index+c[0].length)}return b}var STRICT_NUM_REGEXP=/^[0-9]+$/;
function stringToInt(a){a=a.replace(RegExp(",","g"),"");if(!STRICT_NUM_REGEXP.test(a)){alert("Don't understand '"+a+"'");return null}return a|0}function pushnew(a,b){for(var c=0;c<a.length;++c)if(a[c]==b)return;a.push(b)}function pusho(a,b,c){if(a[b])a[b].push(c);else a[b]=[c]}function pushnewo(a,b,c){var e=a[b];if(e){for(a=0;a<e.length;++a)if(e[a]==c)return;e.push(c)}else a[b]=[c]}function pick(a,b,c,e){if(a)return a;else if(b)return b;else if(c)return c;else if(e)return e}
function pushnew(a,b){for(var c=0;c<a.length;++c)if(a[c]==b)return;a.push(b)}function maybeConcat(a,b){var c=[];if(a)for(var e=0;e<a.length;++e)pushnew(c,a[e]);if(b)for(e=0;e<b.length;++e)pushnew(c,b[e]);return c}function arrayIndexOf(a,b){if(!a)return-1;for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}function arrayRemove(a,b){var c=arrayIndexOf(a,b);if(c>=0){a.splice(c,1);return true}return false}
function makeElement(a,b,c,e){a=document.createElement(a);if(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length;++d){var f=b[d];if(typeof f=="string")f=document.createTextNode(f);a.appendChild(f)}}if(c)for(var h in c)a[h]=c[h];if(e)for(h in e)a.style[h]=e[h];return a}function makeElementNS(a,b,c,e){a=document.createElementNS(a,b);if(c){c instanceof Array||(c=[c]);for(b=0;b<c.length;++b){var d=c[b];if(typeof d=="string")d=document.createTextNode(d);a.appendChild(d)}}setAttrs(a,e);return a}
var attr_name_cache={};function setAttr(a,b,c){var e=attr_name_cache[b];if(!e){e="";for(var d=0;d<b.length;++d){var f=b.substring(d,d+1),h=f.toLowerCase();e=h!=f?e+"-"+h:e+f}e=attr_name_cache[b]=e}a.setAttribute(e,c)}function setAttrs(a,b){if(b)for(var c in b)setAttr(a,c,b[c])}function removeChildren(a){if(a&&a.childNodes)for(;a.childNodes.length>0;)a.removeChild(a.firstChild)}
function miniJSONify(a){if(typeof a==="undefined")return"undefined";else if(a==null)return"null";else if(typeof a=="string")return"'"+a+"'";else if(typeof a=="number")return""+a;else if(typeof a=="boolean")return""+a;else if(typeof a=="object")if(a instanceof Array){for(var b=null,c=0;c<a.length;++c)b=(b==null?"":b+", ")+miniJSONify(a[c]);return"["+(b?b:"")+"]"}else{b=null;for(c in a)if(c!=undefined&&typeof a[c]!="function")b=(b==null?"":b+", ")+c+": "+miniJSONify(a[c]);return"{"+(b?b:"")+"}"}else return typeof a}
function shallowCopy(a){n={};for(k in a)n[k]=a[k];return n}function Observed(a){this.value=a;this.listeners=[]}Observed.prototype.addListener=function(a){this.listeners.push(a)};Observed.prototype.addListenerAndFire=function(a){this.listeners.push(a);a(this.value)};Observed.prototype.removeListener=function(a){arrayRemove(this.listeners,a)};Observed.prototype.get=function(){return this.value};Observed.prototype.set=function(a){this.value=a;for(var b=0;b<this.listeners.length;++b)this.listeners[b](a)};
function Awaited(){this.queue=[]}Awaited.prototype.provide=function(a){if(this.res)throw"Resource has already been provided.";this.res=a;for(var b=0;b<this.queue.length;++b)this.queue[b](a)};Awaited.prototype.await=function(a){if(this.res){a(this.res);return this.res}else this.queue.push(a)};if(!("trim"in String.prototype))String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")};var VERSION={CONFIG:3,MAJOR:0,MINOR:6,MICRO:5,PATCH:"",BRANCH:""};
VERSION.toString=function(){var a=""+this.MAJOR+"."+this.MINOR+"."+this.MICRO;if(this.PATCH)a+=this.PATCH;if(this.BRANCH&&this.BRANCH!="")a=a+"-"+this.BRANCH;return a};var JSON;JSON||(JSON={});
(function(){function a(j){return j<10?"0"+j:j}function b(j){d.lastIndex=0;return d.test(j)?'"'+j.replace(d,function(r){var q=g[r];return typeof q==="string"?q:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+j+'"'}function c(j,r){var q,m,p,o,s=f,u,v=r[j];if(v&&typeof v==="object"&&typeof v.toJSON==="function")v=v.toJSON(j);if(typeof i==="function")v=i.call(r,j,v);switch(typeof v){case "string":return b(v);case "number":return isFinite(v)?String(v):"null";case "boolean":case "null":return String(v);
case "object":if(!v)return"null";f+=h;u=[];if(Object.prototype.toString.apply(v)==="[object Array]"){o=v.length;for(q=0;q<o;q+=1)u[q]=c(q,v)||"null";p=u.length===0?"[]":f?"[\n"+f+u.join(",\n"+f)+"\n"+s+"]":"["+u.join(",")+"]";f=s;return p}if(i&&typeof i==="object"){o=i.length;for(q=0;q<o;q+=1){m=i[q];if(typeof m==="string")if(p=c(m,v))u.push(b(m)+(f?": ":":")+p)}}else for(m in v)if(Object.hasOwnProperty.call(v,m))if(p=c(m,v))u.push(b(m)+(f?": ":":")+p);p=u.length===0?"{}":f?"{\n"+f+u.join(",\n"+f)+
"\n"+s+"}":"{"+u.join(",")+"}";f=s;return p}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,h,g={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},i;if(typeof JSON.stringify!=="function")JSON.stringify=function(j,r,q){var m;h=f="";if(typeof q==="number")for(m=0;m<q;m+=1)h+=" ";else if(typeof q==="string")h=q;if((i=r)&&typeof r!=="function"&&(typeof r!=="object"||typeof r.length!=="number"))throw Error("JSON.stringify");return c("",
{"":j})};if(typeof JSON.parse!=="function")JSON.parse=function(j,r){function q(p,o){var s,u,v=p[o];if(v&&typeof v==="object")for(s in v)if(Object.hasOwnProperty.call(v,s)){u=q(v,s);if(u!==undefined)v[s]=u;else delete v[s]}return r.call(p,o,v)}var m;j=String(j);e.lastIndex=0;if(e.test(j))j=j.replace(e,function(p){return"\\u"+("0000"+p.charCodeAt(0).toString(16)).slice(-4)});if(/^[\],:{}\s]*$/.test(j.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){m=eval("("+j+")");return typeof r==="function"?q({"":m},""):m}throw new SyntaxError("JSON.parse");}})();
var MAX_WBITS=15,DEF_WBITS=MAX_WBITS,MAX_MEM_LEVEL=9,MANY=1440,BMAX=15,PRESET_DICT=32,Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_SYNC_FLUSH=2,Z_FULL_FLUSH=3,Z_FINISH=4,Z_DEFLATED=8,Z_OK=0,Z_STREAM_END=1,Z_NEED_DICT=2,Z_ERRNO=-1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_MEM_ERROR=-4,Z_BUF_ERROR=-5,Z_VERSION_ERROR=-6,METHOD=0,FLAG=1,DICT4=2,DICT3=3,DICT2=4,DICT1=5,DICT0=6,BLOCKS=7,CHECK4=8,CHECK3=9,CHECK2=10,CHECK1=11,DONE=12,BAD=13,inflate_mask=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],
IB_TYPE=0,IB_LENS=1,IB_STORED=2,IB_TABLE=3,IB_BTREE=4,IB_DTREE=5,IB_CODES=6,IB_DRY=7,IB_DONE=8,IB_BAD=9,fixed_bl=9,fixed_bd=5,fixed_tl=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,
7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,
9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,
125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,
82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,
8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,
0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,
9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],fixed_td=[80,
5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],cplens=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],cplext=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,112,112],cpdist=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,
129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],cpdext=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];function ZStream(){}ZStream.prototype.inflateInit=function(a,b){a||(a=DEF_WBITS);if(b)b=false;this.istate=new Inflate;return this.istate.inflateInit(this,b?-a:a)};ZStream.prototype.inflate=function(a){if(this.istate==null)return Z_STREAM_ERROR;return this.istate.inflate(this,a)};
ZStream.prototype.inflateEnd=function(){if(this.istate==null)return Z_STREAM_ERROR;var a=istate.inflateEnd(this);this.istate=null;return a};ZStream.prototype.inflateSync=function(){return istate.inflateSync(this)};ZStream.prototype.inflateSetDictionary=function(a,b){return istate.inflateSetDictionary(this,a,b)};function Inflate(){this.was=[0]}
Inflate.prototype.inflateReset=function(a){if(a==null||a.istate==null)return Z_STREAM_ERROR;a.total_in=a.total_out=0;a.msg=null;a.istate.mode=a.istate.nowrap!=0?BLOCKS:METHOD;a.istate.blocks.reset(a,null);return Z_OK};Inflate.prototype.inflateEnd=function(a){this.blocks!=null&&this.blocks.free(a);this.blocks=null;return Z_OK};
Inflate.prototype.inflateInit=function(a,b){this.blocks=a.msg=null;nowrap=0;if(b<0){b=-b;nowrap=1}if(b<8||b>15){this.inflateEnd(a);return Z_STREAM_ERROR}this.wbits=b;a.istate.blocks=new InfBlocks(a,a.istate.nowrap!=0?null:this,1<<b);this.inflateReset(a);return Z_OK};
Inflate.prototype.inflate=function(a,b){var c,e;if(a==null||a.istate==null||a.next_in==null)return Z_STREAM_ERROR;b=b==Z_FINISH?Z_BUF_ERROR:Z_OK;for(c=Z_BUF_ERROR;;)switch(a.istate.mode){case METHOD:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;if(((a.istate.method=a.next_in[a.next_in_index++])&15)!=Z_DEFLATED){a.istate.mode=BAD;a.msg="unknown compression method";a.istate.marker=5;break}if((a.istate.method>>4)+8>a.istate.wbits){a.istate.mode=BAD;a.msg="invalid window size";a.istate.marker=
5;break}a.istate.mode=FLAG;case FLAG:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;e=a.next_in[a.next_in_index++]&255;if(((a.istate.method<<8)+e)%31!=0){a.istate.mode=BAD;a.msg="incorrect header check";a.istate.marker=5;break}if((e&PRESET_DICT)==0){a.istate.mode=BLOCKS;break}a.istate.mode=DICT4;case DICT4:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need=(a.next_in[a.next_in_index++]&255)<<24&4278190080;a.istate.mode=DICT3;case DICT3:if(a.avail_in==0)return c;c=b;a.avail_in--;
a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<16&16711680;a.istate.mode=DICT2;case DICT2:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<8&65280;a.istate.mode=DICT1;case DICT1:if(a.avail_in==0)return c;a.avail_in--;a.total_in++;a.istate.need+=a.next_in[a.next_in_index++]&255;a.adler=a.istate.need;a.istate.mode=DICT0;return Z_NEED_DICT;case DICT0:a.istate.mode=BAD;a.msg="need dictionary";a.istate.marker=0;return Z_STREAM_ERROR;
case BLOCKS:c=a.istate.blocks.proc(a,c);if(c==Z_DATA_ERROR){a.istate.mode=BAD;a.istate.marker=0;break}if(c==Z_OK)c=b;if(c!=Z_STREAM_END)return c;c=b;a.istate.blocks.reset(a,a.istate.was);if(a.istate.nowrap!=0){a.istate.mode=DONE;break}a.istate.mode=CHECK4;case CHECK4:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need=(a.next_in[a.next_in_index++]&255)<<24&4278190080;a.istate.mode=CHECK3;case CHECK3:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&
255)<<16&16711680;a.istate.mode=CHECK2;case CHECK2:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<8&65280;a.istate.mode=CHECK1;case CHECK1:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=a.next_in[a.next_in_index++]&255;if(a.istate.was[0]!=a.istate.need){a.istate.mode=BAD;a.msg="incorrect data check";a.istate.marker=5;break}a.istate.mode=DONE;case DONE:return Z_STREAM_END;case BAD:return Z_DATA_ERROR;default:return Z_STREAM_ERROR}};
Inflate.prototype.inflateSetDictionary=function(a,b,c){var e=0,d=c;if(a==null||a.istate==null||a.istate.mode!=DICT0)return Z_STREAM_ERROR;if(a._adler.adler32(1,b,0,c)!=a.adler)return Z_DATA_ERROR;a.adler=a._adler.adler32(0,null,0,0);if(d>=1<<a.istate.wbits){d=(1<<a.istate.wbits)-1;e=c-d}a.istate.blocks.set_dictionary(b,e,d);a.istate.mode=BLOCKS;return Z_OK};var mark=[0,0,255,255];
Inflate.prototype.inflateSync=function(a){var b,c,e;if(a==null||a.istate==null)return Z_STREAM_ERROR;if(a.istate.mode!=BAD){a.istate.mode=BAD;a.istate.marker=0}if((b=a.avail_in)==0)return Z_BUF_ERROR;c=a.next_in_index;for(e=a.istate.marker;b!=0&&e<4;){if(a.next_in[c]==mark[e])e++;else e=a.next_in[c]!=0?0:4-e;c++;b--}a.total_in+=c-a.next_in_index;a.next_in_index=c;a.avail_in=b;a.istate.marker=e;if(e!=4)return Z_DATA_ERROR;b=a.total_in;c=a.total_out;this.inflateReset(a);a.total_in=b;a.total_out=c;a.istate.mode=
BLOCKS;return Z_OK};Inflate.prototype.inflateSyncPoint=function(a){if(a==null||a.istate==null||a.istate.blocks==null)return Z_STREAM_ERROR;return a.istate.blocks.sync_point()};var INFBLOCKS_BORDER=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
function InfBlocks(a,b,c){this.hufts=new Int32Array(MANY*3);this.window=new Uint8Array(c);this.end=c;this.checkfn=b;this.mode=IB_TYPE;this.reset(a,null);this.index=this.table=this.left=0;this.blens=null;this.bb=new Int32Array(1);this.tb=new Int32Array(1);this.codes=new InfCodes;this.check=this.write=this.read=this.bitb=this.bitk=this.last=0;this.inftree=new InfTree}
InfBlocks.prototype.reset=function(a,b){if(b)b[0]=this.check;this.mode==IB_CODES&&this.codes.free(a);this.mode=IB_TYPE;this.read=this.write=this.bitb=this.bitk=0;if(this.checkfn)a.adler=this.check=a._adler.adler32(0,null,0,0)};
InfBlocks.prototype.proc=function(a,b){var c,e,d,f,h,g,i;f=a.next_in_index;h=a.avail_in;e=this.bitb;d=this.bitk;g=this.write;for(i=g<this.read?this.read-g-1:this.end-g;;)switch(this.mode){case IB_TYPE:for(;d<3;){if(h!=0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}c=e&7;this.last=c&1;switch(c>>>1){case 0:e>>>=3;d-=3;c=d&7;e>>>=c;d-=c;this.mode=IB_LENS;break;case 1:var j=
new Int32Array(1),r=new Int32Array(1),q=[],m=[];inflate_trees_fixed(j,r,q,m,a);this.codes.init(j[0],r[0],q[0],0,m[0],0,a);e>>>=3;d-=3;this.mode=IB_CODES;break;case 2:e>>>=3;d-=3;this.mode=IB_TABLE;break;case 3:e>>>=3;d-=3;this.mode=BAD;a.msg="invalid block type";b=Z_DATA_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}break;case IB_LENS:for(;d<32;){if(h!=0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=
f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}if((~e>>>16&65535)!=(e&65535)){this.mode=BAD;a.msg="invalid stored block lengths";b=Z_DATA_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}this.left=e&65535;e=d=0;this.mode=left!=0?IB_STORED:this.last!=0?IB_DRY:IB_TYPE;break;case IB_STORED:if(h==0){this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=
f-a.next_in_index;a.next_in_index=f;write=g;return this.inflate_flush(a,b)}if(i==0){if(g==end&&read!=0){g=0;i=g<this.read?this.read-g-1:this.end-g}if(i==0){this.write=g;b=this.inflate_flush(a,b);g=this.write;i=g<this.read?this.read-g-1:this.end-g;if(g==this.end&&this.read!=0){g=0;i=g<this.read?this.read-g-1:this.end-g}if(i==0){this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}}}b=Z_OK;c=this.left;if(c>h)c=h;if(c>i)c=i;
arrayCopy(a.next_in,f,window,g,c);f+=c;h-=c;g+=c;i-=c;if((this.left-=c)!=0)break;this.mode=this.last!=0?IB_DRY:IB_TYPE;break;case IB_TABLE:for(;d<14;){if(h!=0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}this.table=c=e&16383;if((c&31)>29||(c>>5&31)>29){this.mode=IB_BAD;a.msg="too many length or distance symbols";b=Z_DATA_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=
f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}c=258+(c&31)+(c>>5&31);if(this.blens==null||this.blens.length<c)this.blens=new Int32Array(c);else for(i=0;i<c;i++)this.blens[i]=0;e>>>=14;d-=14;this.index=0;mode=IB_BTREE;case IB_BTREE:for(;this.index<4+(this.table>>>10);){for(;d<3;){if(h!=0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}this.blens[INFBLOCKS_BORDER[this.index++]]=
e&7;e>>>=3;d-=3}for(;this.index<19;)this.blens[INFBLOCKS_BORDER[this.index++]]=0;this.bb[0]=7;c=this.inftree.inflate_trees_bits(this.blens,this.bb,this.tb,this.hufts,a);if(c!=Z_OK){b=c;if(b==Z_DATA_ERROR){this.blens=null;this.mode=IB_BAD}this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;write=g;return this.inflate_flush(a,b)}this.index=0;this.mode=IB_DTREE;case IB_DTREE:for(;;){c=this.table;if(!(this.index<258+(c&31)+(c>>5&31)))break;for(c=this.bb[0];d<c;){if(h!=
0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}c=this.hufts[(this.tb[0]+(e&inflate_mask[c]))*3+1];r=this.hufts[(this.tb[0]+(e&inflate_mask[c]))*3+2];if(r<16){e>>>=c;d-=c;this.blens[this.index++]=r}else{i=r==18?7:r-14;for(j=r==18?11:3;d<c+i;){if(h!=0)b=Z_OK;else{this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,
b)}h--;e|=(a.next_in[f++]&255)<<d;d+=8}e>>>=c;d-=c;j+=e&inflate_mask[i];e>>>=i;d-=i;i=this.index;c=this.table;if(i+j>258+(c&31)+(c>>5&31)||r==16&&i<1){this.blens=null;this.mode=IB_BAD;a.msg="invalid bit length repeat";b=Z_DATA_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}r=r==16?this.blens[i-1]:0;do this.blens[i++]=r;while(--j!=0);this.index=i}}this.tb[0]=-1;j=new Int32Array(1);r=new Int32Array(1);q=new Int32Array(1);
m=new Int32Array(1);j[0]=9;r[0]=6;c=this.table;c=this.inftree.inflate_trees_dynamic(257+(c&31),1+(c>>5&31),this.blens,j,r,q,m,this.hufts,a);if(c!=Z_OK){if(c==Z_DATA_ERROR){this.blens=null;this.mode=BAD}b=c;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}this.codes.init(j[0],r[0],this.hufts,q[0],this.hufts,m[0],a);this.mode=IB_CODES;case IB_CODES:this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=
f;this.write=g;if((b=this.codes.proc(this,a,b))!=Z_STREAM_END)return this.inflate_flush(a,b);b=Z_OK;this.codes.free(a);f=a.next_in_index;h=a.avail_in;e=this.bitb;d=this.bitk;g=this.write;i=g<this.read?this.read-g-1:this.end-g;if(this.last==0){this.mode=IB_TYPE;break}this.mode=IB_DRY;case IB_DRY:this.write=g;b=this.inflate_flush(a,b);g=this.write;if(this.read!=this.write){this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}mode=
DONE;case IB_DONE:b=Z_STREAM_END;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b);case IB_BAD:b=Z_DATA_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b);default:b=Z_STREAM_ERROR;this.bitb=e;this.bitk=d;a.avail_in=h;a.total_in+=f-a.next_in_index;a.next_in_index=f;this.write=g;return this.inflate_flush(a,b)}};
InfBlocks.prototype.free=function(a){this.reset(a,null);this.hufts=this.window=null};InfBlocks.prototype.set_dictionary=function(a,b,c){arrayCopy(a,b,window,0,c);this.read=this.write=c};InfBlocks.prototype.sync_point=function(){return this.mode==IB_LENS};
InfBlocks.prototype.inflate_flush=function(a,b){var c,e,d;e=a.next_out_index;d=this.read;c=(d<=this.write?this.write:this.end)-d;if(c>a.avail_out)c=a.avail_out;if(c!=0&&b==Z_BUF_ERROR)b=Z_OK;a.avail_out-=c;a.total_out+=c;if(this.checkfn!=null)a.adler=this.check=a._adler.adler32(this.check,this.window,d,c);arrayCopy(this.window,d,a.next_out,e,c);e+=c;d+=c;if(d==this.end){d=0;if(this.write==this.end)this.write=0;c=this.write-d;if(c>a.avail_out)c=a.avail_out;if(c!=0&&b==Z_BUF_ERROR)b=Z_OK;a.avail_out-=
c;a.total_out+=c;if(this.checkfn!=null)a.adler=this.check=a._adler.adler32(this.check,this.window,d,c);arrayCopy(this.window,d,a.next_out,e,c);e+=c;d+=c}a.next_out_index=e;this.read=d;return b};var IC_START=0,IC_LEN=1,IC_LENEXT=2,IC_DIST=3,IC_DISTEXT=4,IC_COPY=5,IC_LIT=6,IC_WASH=7,IC_END=8,IC_BADCODE=9;function InfCodes(){}InfCodes.prototype.init=function(a,b,c,e,d,f){this.mode=IC_START;this.lbits=a;this.dbits=b;this.ltree=c;this.ltree_index=e;this.dtree=d;this.dtree_index=f;this.tree=null};
InfCodes.prototype.proc=function(a,b,c){var e,d,f=0,h=0,g=0,i,j,r;g=b.next_in_index;i=b.avail_in;f=a.bitb;h=a.bitk;j=a.write;for(r=j<a.read?a.read-j-1:a.end-j;;)switch(this.mode){case IC_START:if(r>=258&&i>=10){a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;c=this.inflate_fast(this.lbits,this.dbits,this.ltree,this.ltree_index,this.dtree,this.dtree_index,a,b);g=b.next_in_index;i=b.avail_in;f=a.bitb;h=a.bitk;j=a.write;r=j<a.read?a.read-j-1:a.end-j;if(c!=Z_OK){this.mode=
c==Z_STREAM_END?IC_WASH:IC_BADCODE;break}}this.need=this.lbits;this.tree=this.ltree;this.tree_index=this.ltree_index;this.mode=IC_LEN;case IC_LEN:for(e=this.need;h<e;){if(i!=0)c=Z_OK;else{a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}i--;f|=(b.next_in[g++]&255)<<h;h+=8}e=(this.tree_index+(f&inflate_mask[e]))*3;f>>>=this.tree[e+1];h-=this.tree[e+1];d=this.tree[e];if(d==0){this.lit=this.tree[e+2];this.mode=IC_LIT;break}if((d&16)!=
0){this.get=d&15;this.len=this.tree[e+2];this.mode=IC_LENEXT;break}if((d&64)==0){this.need=d;this.tree_index=e/3+this.tree[e+2];break}if((d&32)!=0){this.mode=IC_WASH;break}this.mode=IC_BADCODE;b.msg="invalid literal/length code";c=Z_DATA_ERROR;a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c);case IC_LENEXT:for(e=this.get;h<e;){if(i!=0)c=Z_OK;else{a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=
j;return a.inflate_flush(b,c)}i--;f|=(b.next_in[g++]&255)<<h;h+=8}this.len+=f&inflate_mask[e];f>>=e;h-=e;this.need=this.dbits;this.tree=this.dtree;this.tree_index=this.dtree_index;this.mode=IC_DIST;case IC_DIST:for(e=this.need;h<e;){if(i!=0)c=Z_OK;else{a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}i--;f|=(b.next_in[g++]&255)<<h;h+=8}e=(this.tree_index+(f&inflate_mask[e]))*3;f>>=this.tree[e+1];h-=this.tree[e+1];d=this.tree[e];if((d&
16)!=0){this.get=d&15;this.dist=this.tree[e+2];this.mode=IC_DISTEXT;break}if((d&64)==0){this.need=d;this.tree_index=e/3+this.tree[e+2];break}this.mode=IC_BADCODE;b.msg="invalid distance code";c=Z_DATA_ERROR;a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c);case IC_DISTEXT:for(e=this.get;h<e;){if(i!=0)c=Z_OK;else{a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}i--;
f|=(b.next_in[g++]&255)<<h;h+=8}this.dist+=f&inflate_mask[e];f>>=e;h-=e;this.mode=IC_COPY;case IC_COPY:for(e=j-this.dist;e<0;)e+=a.end;for(;this.len!=0;){if(r==0){if(j==a.end&&a.read!=0){j=0;r=j<a.read?a.read-j-1:a.end-j}if(r==0){a.write=j;c=a.inflate_flush(b,c);j=a.write;r=j<a.read?a.read-j-1:a.end-j;if(j==a.end&&a.read!=0){j=0;r=j<a.read?a.read-j-1:a.end-j}if(r==0){a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}}}a.window[j++]=
a.window[e++];r--;if(e==a.end)e=0;this.len--}this.mode=IC_START;break;case IC_LIT:if(r==0){if(j==a.end&&a.read!=0){j=0;r=j<a.read?a.read-j-1:a.end-j}if(r==0){a.write=j;c=a.inflate_flush(b,c);j=a.write;r=j<a.read?a.read-j-1:a.end-j;if(j==a.end&&a.read!=0){j=0;r=j<a.read?a.read-j-1:a.end-j}if(r==0){a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}}}c=Z_OK;a.window[j++]=this.lit;r--;this.mode=IC_START;break;case IC_WASH:if(h>7){h-=8;
i++;g--}a.write=j;c=a.inflate_flush(b,c);j=a.write;if(a.read!=a.write){a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}this.mode=IC_END;case IC_END:c=Z_STREAM_END;a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c);case IC_BADCODE:c=Z_DATA_ERROR;a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c);default:c=
Z_STREAM_ERROR;a.bitb=f;a.bitk=h;b.avail_in=i;b.total_in+=g-b.next_in_index;b.next_in_index=g;a.write=j;return a.inflate_flush(b,c)}};InfCodes.prototype.free=function(){};
InfCodes.prototype.inflate_fast=function(a,b,c,e,d,f,h,g){var i,j,r,q,m,p,o,s,u,v,t,y;p=g.next_in_index;o=g.avail_in;q=h.bitb;m=h.bitk;s=h.write;u=s<h.read?h.read-s-1:h.end-s;a=inflate_mask[a];v=inflate_mask[b];do{for(;m<20;){o--;q|=(g.next_in[p++]&255)<<m;m+=8}i=q&a;j=c;r=e;y=(r+i)*3;if((b=j[y])==0){q>>=j[y+1];m-=j[y+1];h.window[s++]=j[y+2];u--}else{do{q>>=j[y+1];m-=j[y+1];if((b&16)!=0){b&=15;t=j[y+2]+(q&inflate_mask[b]);q>>=b;for(m-=b;m<15;){o--;q|=(g.next_in[p++]&255)<<m;m+=8}i=q&v;j=d;r=f;y=(r+
i)*3;b=j[y];do{q>>=j[y+1];m-=j[y+1];if((b&16)!=0){for(b&=15;m<b;){o--;q|=(g.next_in[p++]&255)<<m;m+=8}i=j[y+2]+(q&inflate_mask[b]);q>>=b;m-=b;u-=t;if(s>=i){i=s-i;if(s-i>0&&2>s-i){h.window[s++]=h.window[i++];h.window[s++]=h.window[i++]}else{arrayCopy(h.window,i,h.window,s,2);s+=2;i+=2}t-=2}else{i=s-i;do i+=h.end;while(i<0);b=h.end-i;if(t>b){t-=b;if(s-i>0&&b>s-i){do h.window[s++]=h.window[i++];while(--b!=0)}else{arrayCopy(h.window,i,h.window,s,b);s+=b}i=0}}if(s-i>0&&t>s-i){do h.window[s++]=h.window[i++];
while(--t!=0)}else{arrayCopy(h.window,i,h.window,s,t);s+=t}break}else if((b&64)==0){i+=j[y+2];i+=q&inflate_mask[b];y=(r+i)*3;b=j[y]}else{g.msg="invalid distance code";t=g.avail_in-o;t=m>>3<t?m>>3:t;o+=t;p-=t;m-=t<<3;h.bitb=q;h.bitk=m;g.avail_in=o;g.total_in+=p-g.next_in_index;g.next_in_index=p;h.write=s;return Z_DATA_ERROR}}while(1);break}if((b&64)==0){i+=j[y+2];i+=q&inflate_mask[b];y=(r+i)*3;if((b=j[y])==0){q>>=j[y+1];m-=j[y+1];h.window[s++]=j[y+2];u--;break}}else if((b&32)!=0){t=g.avail_in-o;t=
m>>3<t?m>>3:t;o+=t;p-=t;m-=t<<3;h.bitb=q;h.bitk=m;g.avail_in=o;g.total_in+=p-g.next_in_index;g.next_in_index=p;h.write=s;return Z_STREAM_END}else{g.msg="invalid literal/length code";t=g.avail_in-o;t=m>>3<t?m>>3:t;o+=t;p-=t;m-=t<<3;h.bitb=q;h.bitk=m;g.avail_in=o;g.total_in+=p-g.next_in_index;g.next_in_index=p;h.write=s;return Z_DATA_ERROR}}while(1)}}while(u>=258&&o>=10);t=g.avail_in-o;t=m>>3<t?m>>3:t;o+=t;p-=t;m-=t<<3;h.bitb=q;h.bitk=m;g.avail_in=o;g.total_in+=p-g.next_in_index;g.next_in_index=p;h.write=
s;return Z_OK};function InfTree(){}
InfTree.prototype.huft_build=function(a,b,c,e,d,f,h,g,i,j,r){var q,m,p,o,s,u,v,t,y;u=0;m=c;do{this.c[a[b+u]]++;u++;m--}while(m!=0);if(this.c[0]==c){h[0]=-1;g[0]=0;return Z_OK}s=g[0];for(p=1;p<=BMAX;p++)if(this.c[p]!=0)break;o=p;if(s<p)s=p;for(m=BMAX;m!=0;m--)if(this.c[m]!=0)break;j=m;if(s>m)s=m;g[0]=s;for(g=1<<p;p<m;p++,g<<=1)if((g-=this.c[p])<0)return Z_DATA_ERROR;if((g-=this.c[m])<0)return Z_DATA_ERROR;this.c[m]+=g;this.x[1]=p=0;u=1;for(v=2;--m!=0;){this.x[v]=p+=this.c[u];v++;u++}u=m=0;do{if((p=
a[b+u])!=0)this.v[this.x[p]++]=m;u++}while(++m<c);c=this.x[j];u=this.x[0]=m=0;b=-1;t=-s;for(y=v=this.u[0]=0;o<=j;o++)for(a=this.c[o];a--!=0;){for(;o>t+s;){b++;t+=s;y=j-t;y=y>s?s:y;if((q=1<<(p=o-t))>a+1){q-=a+1;v=o;if(p<y)for(;++p<y;){if((q<<=1)<=this.c[++v])break;q-=this.c[v]}}y=1<<p;if(this.hn[0]+y>MANY)return Z_DATA_ERROR;this.u[b]=v=this.hn[0];this.hn[0]+=y;if(b!=0){this.x[b]=m;this.r[0]=p;this.r[1]=s;p=m>>>t-s;this.r[2]=v-this.u[b-1]-p;arrayCopy(this.r,0,i,(this.u[b-1]+p)*3,3)}else h[0]=v}this.r[1]=
o-t;if(u>=c)this.r[0]=192;else if(r[u]<e){this.r[0]=this.v[u]<256?0:96;this.r[2]=this.v[u++]}else{this.r[0]=f[this.v[u]-e]+16+64;this.r[2]=d[this.v[u++]-e]}q=1<<o-t;for(p=m>>>t;p<y;p+=q)arrayCopy(this.r,0,i,(v+p)*3,3);for(p=1<<o-1;(m&p)!=0;p>>>=1)m^=p;m^=p;for(p=(1<<t)-1;(m&p)!=this.x[b];){b--;t-=s;p=(1<<t)-1}}return g!=0&&j!=1?Z_BUF_ERROR:Z_OK};
InfTree.prototype.inflate_trees_bits=function(a,b,c,e,d){this.initWorkArea(19);this.hn[0]=0;a=this.huft_build(a,0,19,19,null,null,c,b,e,this.hn,this.v);if(a==Z_DATA_ERROR)d.msg="oversubscribed dynamic bit lengths tree";else if(a==Z_BUF_ERROR||b[0]==0){d.msg="incomplete dynamic bit lengths tree";a=Z_DATA_ERROR}return a};
InfTree.prototype.inflate_trees_dynamic=function(a,b,c,e,d,f,h,g,i){this.initWorkArea(288);this.hn[0]=0;f=this.huft_build(c,0,a,257,cplens,cplext,f,e,g,this.hn,this.v);if(f!=Z_OK||e[0]==0){if(f==Z_DATA_ERROR)i.msg="oversubscribed literal/length tree";else if(f!=Z_MEM_ERROR){i.msg="incomplete literal/length tree";f=Z_DATA_ERROR}return f}this.initWorkArea(288);f=this.huft_build(c,a,b,0,cpdist,cpdext,h,d,g,this.hn,this.v);if(f!=Z_OK||d[0]==0&&a>257){if(f==Z_DATA_ERROR)i.msg="oversubscribed distance tree";
else if(f==Z_BUF_ERROR){i.msg="incomplete distance tree";f=Z_DATA_ERROR}else if(f!=Z_MEM_ERROR){i.msg="empty distance tree with lengths";f=Z_DATA_ERROR}return f}return Z_OK};function inflate_trees_fixed(a,b,c,e){a[0]=fixed_bl;b[0]=fixed_bd;c[0]=fixed_tl;e[0]=fixed_td;return Z_OK}
InfTree.prototype.initWorkArea=function(a){if(this.hn==null){this.hn=new Int32Array(1);this.v=new Int32Array(a);this.c=new Int32Array(BMAX+1);this.r=new Int32Array(3);this.u=new Int32Array(BMAX);this.x=new Int32Array(BMAX+1)}if(this.v.length<a)this.v=new Int32Array(a);for(var b=0;b<a;b++)this.v[b]=0;for(b=0;b<BMAX+1;b++)this.c[b]=0;for(b=0;b<3;b++)this.r[b]=0;arrayCopy(this.c,0,this.u,0,BMAX);arrayCopy(this.c,0,this.x,0,BMAX+1)};
var testArray=new Uint8Array(1),hasSubarray=typeof testArray.subarray==="function",hasSlice=false;function arrayCopy(a,b,c,e,d){if(d!=0){if(a){if(!c)throw"Undef dest";}else throw"Undef src";if(b==0&&d==a.length)arrayCopy_fast(a,c,e);else if(hasSubarray)arrayCopy_fast(a.subarray(b,b+d),c,e);else a.BYTES_PER_ELEMENT==1&&d>100?arrayCopy_fast(new Uint8Array(a.buffer,a.byteOffset+b,d),c,e):arrayCopy_slow(a,b,c,e,d)}}function arrayCopy_slow(a,b,c,e,d){for(var f=0;f<d;++f)c[e+f]=a[b+f]}
function arrayCopy_fast(a,b,c){b.set(a,c)}var ADLER_BASE=65521,ADLER_NMAX=5552;
function adler32(a,b,c,e){if(b==null)return 1;var d=a&65535;a=a>>16&65535;for(var f;e>0;){f=e<ADLER_NMAX?e:ADLER_NMAX;for(e-=f;f>=16;){d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;d+=b[c++]&255;a+=d;f-=16}if(f!=0){do{d+=b[c++]&255;a+=d}while(--f!=0)}d%=ADLER_BASE;
a%=ADLER_BASE}return a<<16|d}
function jszlib_inflate_buffer(a,b,c,e){a=b?new Uint8Array(a,b,c):new Uint8Array(a);c=new ZStream;c.inflateInit(DEF_WBITS,true);c.next_in=a;c.next_in_index=0;c.avail_in=a.length;a=[];for(var d=0;;){var f=new Uint8Array(32E3);c.next_out=f;c.next_out_index=0;c.avail_out=f.length;var h=c.inflate(Z_NO_FLUSH);if(h!=Z_OK&&h!=Z_STREAM_END)throw c.msg;if(c.avail_out!=0){var g=new Uint8Array(f.length-c.avail_out);arrayCopy(f,0,g,0,f.length-c.avail_out);f=g}a.push(f);d+=f.length;if(h==Z_STREAM_END)break}if(e)e[0]=
(b||0)+c.next_in_index;if(a.length==1)return a[0].buffer;else{b=new Uint8Array(d);for(c=e=0;c<a.length;++c){d=a[c];arrayCopy(d,0,b,e,d.length);e+=d.length}return b.buffer}};