//>>built
require({cache:{"JBrowse/Store/SeqFeature/GlobalStatsEstimationMixin":function(){define(["dojo/_base/declare","dojo/_base/array","dojo/Deferred","JBrowse/Errors"],function(t,v,u,q){return t(null,{_estimateGlobalStats:function(h){var c=new u;h=h||this.refSeq;var d=this.storeTimeout||3E3,r=new Date,l=function(b,k){var a=this,n=0.75*h.start+0.25*h.end,f=Math.max(0,Math.round(n-b/2)),p=Math.min(Math.round(n+b/2),h.end),e=[];this._getFeatures({ref:h.name,start:f,end:p},function(a){e.push(a)},function(n){e=
v.filter(e,function(a){return a.get("start")>=f&&a.get("end")<=p});k.call(a,b,{featureDensity:e.length/b,_statsSampleFeatures:e.length,_statsSampleInterval:{ref:h.name,start:f,end:p,length:b}})},function(f){k.call(a,b,null,f)})},m=function(b,k,a){if(a)a.isInstanceOf(q.DataOverflow)?c.resolve({featureDensity:0,error:"global stats estimation found chunkSizeError"}):c.reject(a);else{var n=h.end-h.start;300<=k._statsSampleFeatures||2*b>n||a?c.resolve(k):new Date-r<d?l.call(this,2*b,m):c.resolve({featureDensity:0,
error:"global stats estimation timed out"})}};l.call(this,100,m);return c}})})},"JBrowse/Store/SeqFeature/BAM/File":function(){define("dojo/_base/declare dojo/_base/array JBrowse/has JBrowse/Util JBrowse/Errors JBrowse/Store/LRUCache ./Util ./LazyFeature".split(" "),function(t,v,u,q,h,c,d,r){var l=function(){console.error.apply(console,arguments)},m=q.fastDeclare({constructor:function(a,b,f){this.minv=a;this.maxv=b;this.bin=f},toUniqueString:function(){return this.minv+".."+this.maxv+" (bin "+this.bin+
")"},toString:function(){return this.toUniqueString()},fetchedSize:function(){return this.maxv.block+65536-this.minv.block+1}}),b=d.readInt,k=d.readVirtualOffset;return t(null,{constructor:function(a){this.store=a.store;this.data=a.data;this.bai=a.bai;this.chunkSizeLimit=a.chunkSizeLimit||5E6},init:function(a){var b=a.success||function(){},f=a.failure||function(a){console.error(a,a.stack)};this._readBAI(dojo.hitch(this,function(){this._readBAMheader(function(){b()},f)}),f)},_readBAI:function(a,n){this.bai.fetch(dojo.hitch(this,
function(f){if(f)if(u("typed-arrays")){var p=new Uint8Array(f);if(21578050!=b(p,0))l("Not a BAI file"),n("Not a BAI file");else{var e=b(p,4);this.indices=[];for(var g=8,d=0;d<e;++d){for(var s=g,c=b(p,g),g=g+4,h=0;h<c;++h){b(p,g);for(var r=b(p,g+4),g=g+8,m=0;m<r;m++){var q=k(p,g);this._findMinAlignment(q);g+=16}}h=b(p,g);g+=4;this._findMinAlignment(h?k(p,g):null);g+=8*h;if(0<c||0<h)this.indices[d]=new Uint8Array(f,s,g-s)}this.empty=!this.indices.length;a(this.indices,this.minAlignmentVO)}}else l("Web browser does not support typed arrays"),
n("Web browser does not support typed arrays");else l("No data read from BAM index (BAI) file"),n("No data read from BAM index (BAI) file")}),n)},_findMinAlignment:function(a){if(a&&(!this.minAlignmentVO||0>this.minAlignmentVO.cmp(a)))this.minAlignmentVO=a},_readBAMheader:function(a,n){var f=this;f.data.read(0,f.minAlignmentVO?f.minAlignmentVO.block+65535:null,function(p){try{var e;try{e=new Uint8Array(d.unbgzf(p))}catch(g){throw Error("Could not uncompress BAM data. Is it compressed correctly?");
}if(21840194!=b(e,0))throw Error("Not a BAM file");var k=b(e,4);f._readRefSeqs(k+8,262144,a,n)}catch(s){l(""+s),n(""+s)}},n)},_readRefSeqs:function(a,n,f,p){var e=this;e.data.read(0,a+n,function(g){g=d.unbgzf(g);g=new Uint8Array(g);var k=b(g,a),s=a+4;e.chrToIndex={};e.indexToChr=[];for(var c=0;c<k;++c){for(var h=b(g,s),l="",m=0;m<h-1;++m)l+=String.fromCharCode(g[s+4+m]);m=b(g,s+h+4);e.chrToIndex[e.store.browser.regularizeReferenceName(l)]=c;e.indexToChr.push({name:l,length:m});s=s+8+h;if(s>g.length){n*=
2;console.warn("BAM header is very big.  Re-fetching "+n+" bytes.");e._readRefSeqs(a,n,f,p);return}}f()},p)},blocksForRange:function(a,n,f){var p=this.indices[a];if(!p)return[];a=function(){for(var a={},b=this._reg2bins(n,f),e=0;e<b.length;++e)a[b[e]]=!0;return a}.call(this);for(var e=[],g=[],d=b(p,0),c=4,h=0;h<d;++h){var l=b(p,c),r=b(p,c+4),c=c+8;if(a[l])for(var q=0;q<r;++q){var u=k(p,c),t=k(p,c+8);(4681>l?g:e).push(new m(u,t,l));c+=16}else c+=16*r}var v=function(){for(var a=null,e=b(p,c),g=Math.min(n>>
14,e-1),e=Math.min(f>>14,e-1);g<=e;++g){var d=k(p,c+4+8*g);if(d&&(!a||0<d.cmp(a)))a=d}return a}();v&&(g=function(a){for(var b=[],f=0;f<a.length;++f){var e=a[f];e.maxv.block>=v.block&&b.push(e)}return b}(g));a=g.concat(e).sort(function(a,b){return a.minv.block-b.minv.block||a.minv.offset-b.minv.offset});e=[];if(a.length){g=a[0];for(d=1;d<a.length;++d)h=a[d],h.minv.block==g.maxv.block?g=new m(g.minv,h.maxv,"merged"):(e.push(g),g=h);e.push(g)}return e},fetch:function(a,b,f,d,e,g){a=this.store.browser.regularizeReferenceName(a);
a=this.chrToIndex&&this.chrToIndex[a];var k;0<=a?(k=this.blocksForRange(a,b,f))||g(new h.Fatal("Error in index fetch")):k=[];k.toString=function(){return this.join(", ")};try{this._fetchChunkFeatures(k,a,b,f,d,e,g)}catch(c){g(c)}},_fetchChunkFeatures:function(a,b,f,k,e,g,d){if(a.length){for(var l=0,m=this.featureCache=this.featureCache||new c({name:"bamFeatureCache",fillCallback:dojo.hitch(this,"_readChunk"),sizeFunction:function(a){return a.length},maxSize:1E5}),r=0;r<a.length;r++){var u=a[r].fetchedSize();
if(u>this.chunkSizeLimit){d(new h.DataOverflow("Too many BAM features. BAM chunk size "+q.commifyNumber(u)+" bytes exceeds chunkSizeLimit of "+q.commifyNumber(this.chunkSizeLimit)+"."));return}}var t;v.forEach(a,function(c){m.get(c,function(c,h){h&&!t&&d(h);if(!(t=t||h)){for(var m=0;m<c.length;m++){var r=c[m];if(r._refID==b)if(r.get("start")>k)break;else r.get("end")>=f&&e(r)}++l==a.length&&g()}})})}else g()},_readChunk:function(a,b){var f=this,k=[];f.data.read(a.minv.block,a.fetchedSize(),function(e){try{var g=
d.unbgzf(e,a.maxv.block-a.minv.block+1);f.readBamFeatures(new Uint8Array(g),a.minv.offset,k,b)}catch(c){b(null,new h.Fatal(c))}},function(a){b(null,new h.Fatal(a))})},readBamFeatures:function(a,n,f,k){for(var e=this,g=0;;)if(n>=a.length){k(f);break}else if(300>=g){var d=b(a,n),d=n+4+d-1;if(d<a.length){var c=new r({store:this.store,file:this,bytes:{byteArray:a,start:n,end:d}});f.push(c);g++}n=d+1}else{window.setTimeout(function(){e.readBamFeatures(a,n,f,k)},1);break}},_reg2bin:function(a,b){--b;return a>>
14==b>>14?4681+(a>>14):a>>17==b>>17?585+(a>>17):a>>20==b>>20?73+(a>>20):a>>23==b>>23?9+(a>>23):a>>26==b>>26?1+(a>>26):0},MAX_BIN:37449,_reg2bins:function(a,b){var f,d=[0];--b;for(f=1+(a>>26);f<=1+(b>>26);++f)d.push(f);for(f=9+(a>>23);f<=9+(b>>23);++f)d.push(f);for(f=73+(a>>20);f<=73+(b>>20);++f)d.push(f);for(f=585+(a>>17);f<=585+(b>>17);++f)d.push(f);for(f=4681+(a>>14);f<=4681+(b>>14);++f)d.push(f);return d}})})},"JBrowse/Store/SeqFeature/BAM/Util":function(){define(["jszlib/inflate","jszlib/arrayCopy",
"JBrowse/Util"],function(t,v,u){var q=u.fastDeclare({constructor:function(c,d){this.block=c;this.offset=d},toString:function(){return""+this.block+":"+this.offset},cmp:function(c){return c.block-this.block||c.offset-this.offset}}),h={readInt:function(c,d){return c[d+3]<<24|c[d+2]<<16|c[d+1]<<8|c[d]},readShort:function(c,d){return c[d+1]<<8|c[d]},readByte:function(c,d){return c[d]},readFloat:function(c,d){for(var h=new Uint8Array(4),l=0;4>l;l++)h[l]=c[d+l];return(new Float32Array(h.buffer))[0]},readVirtualOffset:function(c,
d){var h=4294967296*(c[d+6]&255)+16777216*(c[d+5]&255)+65536*(c[d+4]&255)+256*(c[d+3]&255)+(c[d+2]&255),l=c[d+1]<<8|c[d];return 0==h&&0==l?null:new q(h,l)},unbgzf:function(c,d){d=Math.min(d||Infinity,c.byteLength-27);for(var r=[],l=0,m=[0];m[0]<d;m[0]+=8){var b=new Uint8Array(c,m[0],18);if(!(31==b[0]&&139==b[1])){console.error("invalid BGZF block header, skipping",b);break}var b=h.readShort(b,10),b=m[0]+12+b,k;try{k=t(c,b,c.byteLength-b,m)}catch(a){if(/^Z_BUF_ERROR/.test(a.statusString)&&r.length)break;
else throw a;}k.byteLength&&(l+=k.byteLength,r.push(k))}if(1==r.length)return r[0];l=new Uint8Array(l);for(k=m=0;k<r.length;++k)b=new Uint8Array(r[k]),v(b,0,l,m,b.length),m+=b.length;return l.buffer}};return h})},"JBrowse/Store/SeqFeature/BAM/LazyFeature":function(){define(["dojo/_base/array","JBrowse/Util","./Util","JBrowse/Model/SimpleFeature"],function(t,v,u,q){var h="\x3dACxGxxxTxxxxxxN".split(""),c="MIDNSHP\x3dX???????".split(""),d=u.readInt,r=u.readShort,l=u.readFloat,m=u.readByte;return v.fastDeclare({constructor:function(b){this.file=
b.file;this.data={type:"match",source:b.store.source};this.bytes={start:b.bytes.start,end:b.bytes.end,byteArray:b.bytes.byteArray};this._coreParse()},get:function(b){return this._get(b.toLowerCase())},_get:function(b){return b in this.data?this.data[b]:this.data[b]=this[b]?this[b]():this._flagMasks[b]?this._parseFlag(b):this._parseTag(b)},tags:function(){return this._get("_tags")},_tags:function(){this._parseAllTags();var b="seq seq_reverse_complemented unmapped qc_failed duplicate secondary_alignment supplementary_alignment".split(" ");
this._get("unmapped")||b.push("start","end","strand","score","qual","MQ","CIGAR","length_on_ref","template_length");this._get("multi_segment_template")&&b.push("multi_segment_all_correctly_aligned","multi_segment_next_segment_unmapped","multi_segment_next_segment_reversed","multi_segment_first","multi_segment_last","next_segment_position");var b=b.concat(this._tagList||[]),d=this.data,a;for(a in d)d.hasOwnProperty(a)&&("_"!=a[0]&&"multi_segment_all_aligned"!=a&&"next_seq_id"!=a)&&b.push(a);var c=
{};return b=t.filter(b,function(a){if(a in this.data&&void 0===this.data[a])return!1;a=a.toLowerCase();var b=c[a];c[a]=!0;return!b},this)},parent:function(){},children:function(){return this._get("subfeatures")},id:function(){return this._get("name")+"/"+this._get("md")+"/"+this._get("cigar")+"/"+this._get("start")+"/"+this._get("multi_segment_next_segment_reversed")},multi_segment_all_aligned:function(){return this._get("multi_segment_all_correctly_aligned")},mq:function(){var b=(this._get("_bin_mq_nl")&
65280)>>8;return 255==b?void 0:b},score:function(){return this._get("mq")},qual:function(){if(!this._get("unmapped")){for(var b=[],d=this.bytes.byteArray,a=this.bytes.start+36+this._get("_l_read_name")+4*this._get("_n_cigar_op")+this._get("_seq_bytes"),c=this._get("seq_length"),f=0;f<c;++f)b.push(d[a+f]);return b.join(" ")}},strand:function(){return this._get("seq_reverse_complemented")?-1:1},multi_segment_next_segment_strand:function(){return this._get("multi_segment_next_segment_unmapped")?void 0:
this._get("multi_segment_next_segment_reversed")?-1:1},_l_read_name:function(){return this._get("_bin_mq_nl")&255},_seq_bytes:function(){return this._get("seq_length")+1>>1},seq:function(){for(var b="",d=this.bytes.byteArray,a=this.bytes.start+36+this._get("_l_read_name")+4*this._get("_n_cigar_op"),c=this._get("_seq_bytes"),f=0;f<c;++f){var p=d[a+f],b=b+h[(p&240)>>4];b.length<this.get("seq_length")&&(b+=h[p&15])}return b},name:function(){return this._get("_read_name")},_read_name:function(){for(var b=
this.bytes.byteArray,d="",a=this._get("_l_read_name"),c=this.bytes.start+36,f=0;f<a-1;++f)d+=String.fromCharCode(b[c+f]);return d},_n_cigar_op:function(){return this._get("_flag_nc")&65535},cigar:function(){if(!this._get("unmapped")){for(var b=this.bytes.byteArray,k=this._get("_n_cigar_op"),a=this.bytes.start+36+this._get("_l_read_name"),n="",f=0,h=0;h<k;++h){var e=d(b,a),g=e>>4,e=c[e&15],n=n+(g+e);"H"!=e&&("S"!=e&&"I"!=e)&&(f+=g);a+=4}this.data.length_on_ref=f;return n}},next_segment_position:function(){var b=
this.file.indexToChr[this._get("_next_refid")];if(b)return b.name+":"+this._get("_next_pos")},subfeatures:function(){var b=this._get("cigar");if(b)return this._cigarToSubfeats(b)},length_on_ref:function(){this._get("cigar");return this.data.length_on_ref},_flags:function(){return(this.get("_flag_nc")&4294901760)>>16},end:function(){return this._get("start")+(this._get("length_on_ref")||this._get("seq_length")||void 0)},seq_id:function(){return this._get("unmapped")?void 0:(this.file.indexToChr[this._refID]||
{}).name},next_seq_id:function(){return this._get("multi_segment_next_segment_unmapped")?void 0:(this.file.indexToChr[this._get("_next_refid")]||{}).name},_bin_mq_nl:function(){return d(this.bytes.byteArray,this.bytes.start+12)},_flag_nc:function(){return d(this.bytes.byteArray,this.bytes.start+16)},seq_length:function(){return d(this.bytes.byteArray,this.bytes.start+20)},_next_refid:function(){return d(this.bytes.byteArray,this.bytes.start+24)},_next_pos:function(){return d(this.bytes.byteArray,
this.bytes.start+28)},template_length:function(){return d(this.bytes.byteArray,this.bytes.start+32)},_coreParse:function(){this._refID=d(this.bytes.byteArray,this.bytes.start+4);this.data.start=d(this.bytes.byteArray,this.bytes.start+8)},_parseTag:function(b){if(!this._allTagsParsed){this._tagList=this._tagList||[];for(var c=this.bytes.byteArray,a=this._tagOffset||this.bytes.start+36+this._get("_l_read_name")+4*this._get("_n_cigar_op")+this._get("_seq_bytes")+this._get("seq_length"),h=this.bytes.end;a<
h&&p!=b;){var f=String.fromCharCode(c[a],c[a+1]),p=f.toLowerCase(),e=String.fromCharCode(c[a+2]),a=a+3;switch(e.toLowerCase()){case "a":e=String.fromCharCode(c[a]);a+=1;break;case "i":e=d(c,a);a+=4;break;case "c":e=c[a];a+=1;break;case "s":e=r(c,a);a+=2;break;case "f":e=l(c,a);a+=4;break;case "z":case "h":for(e="";a<=h;){var g=c[a++];if(0==g)break;else e+=String.fromCharCode(g)}break;case "b":e="";g=c[a++];g=String.fromCharCode(g);if("i"==g||"I"==g)for(var q=d(c,a),a=a+4,s=0;s<q;s++)e+=d(c,a),s+1<
q&&(e+=","),a+=4;if("s"==g||"S"==g){q=d(c,a);a+=4;for(s=0;s<q;s++)e+=r(c,a),s+1<q&&(e+=","),a+=2}if("c"==g||"C"==g){q=d(c,a);a+=4;for(s=0;s<q;s++)e+=m(c,a),s+1<q&&(e+=","),a+=1}if("f"==g){q=d(c,a);a+=4;for(s=0;s<q;s++)e+=l(c,a),s+1<q&&(e+=","),a+=4}break;default:console.warn("Unknown BAM tag type '"+e+"', tags may be incomplete"),e=void 0,a=h}this._tagOffset=a;this._tagList.push(f);if(p==b)return e;this.data[p]=e}this._allTagsParsed=!0}},_parseAllTags:function(){this._parseTag()},_flagMasks:{multi_segment_template:1,
multi_segment_all_correctly_aligned:2,unmapped:4,multi_segment_next_segment_unmapped:8,seq_reverse_complemented:16,multi_segment_next_segment_reversed:32,multi_segment_first:64,multi_segment_last:128,secondary_alignment:256,qc_failed:512,duplicate:1024,supplementary_alignment:2048},_parseFlag:function(b){return!!(this._get("_flags")&this._flagMasks[b])},_parseCigar:function(b){return t.map(b.match(/\d+\D/g),function(b){return[b.match(/\D/)[0].toUpperCase(),parseInt(b)]})},_cigarToSubfeats:function(b){var c=
[],a=this._get("start"),d;b=this._parseCigar(b);for(var f=0;f<b.length;f++){var h=b[f][1],e=b[f][0];"\x3d"===e&&(e="E");switch(e){case "M":case "D":case "N":case "E":case "X":d=a+h;break;case "I":d=a}"N"!==e&&c.push(new q({data:{type:e,start:a,end:d,strand:this._get("strand"),cigar_op:h+e},parent:this}));a=d}return c}})})}}});
define("JBrowse/Store/SeqFeature/BAM","dojo/_base/declare dojo/_base/array dojo/_base/Deferred dojo/_base/lang JBrowse/has JBrowse/Util JBrowse/Store/SeqFeature JBrowse/Store/DeferredStatsMixin JBrowse/Store/DeferredFeaturesMixin JBrowse/Model/XHRBlob JBrowse/Store/SeqFeature/GlobalStatsEstimationMixin ./BAM/File".split(" "),function(t,v,u,q,h,c,d,r,l,m,b,k){return t([d,r,l,b],{constructor:function(a){var b=a.bam||new m(this.resolveUrl(a.urlTemplate||"data.bam")),c=a.bai||new m(this.resolveUrl(a.baiUrlTemplate||
(a.urlTemplate?a.urlTemplate+".bai":"data.bam.bai")));this.bam=new k({store:this,data:b,bai:c,chunkSizeLimit:a.chunkSizeLimit});this.source=(b.url?b.url.match(/\/([^/\#\?]+)($|[\#\?])/)[1]:b.blob?b.blob.name:void 0)||void 0;h("typed-arrays")?(this.bam.init({success:q.hitch(this,function(){this._deferred.features.resolve({success:!0});this._estimateGlobalStats().then(q.hitch(this,function(a){this.globalStats=a;this._deferred.stats.resolve({success:!0})}),q.hitch(this,"_failAllDeferred"))}),failure:q.hitch(this,
"_failAllDeferred")}),this.storeTimeout=a.storeTimeout||3E3):this._failAllDeferred("This web browser lacks support for JavaScript typed arrays.")},hasRefSeq:function(a,b,c){var d=this;a=d.browser.regularizeReferenceName(a);this._deferred.stats.then(function(){b(a in d.bam.chrToIndex)},c)},_getFeatures:function(a,b,c,d){this.bam.fetch(this.refSeq.name,a.start,a.end,b,c,d)},saveStore:function(){return{urlTemplate:this.config.bam.url,baiUrlTemplate:this.config.bai.url}}})});
//# sourceMappingURL=BAM.js.map