commit/galaxy-central: jgoecks: Enhance Trackster VCF support: (a) use ReadPainter rather than VariantPainter and (b) provide support for insertions and deletions. Pack scripts.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/22d844537368/ changeset: 22d844537368 user: jgoecks date: 2011-10-31 20:31:59 summary: Enhance Trackster VCF support: (a) use ReadPainter rather than VariantPainter and (b) provide support for insertions and deletions. Pack scripts. affected #: 6 files diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef lib/galaxy/datatypes/tabular.py --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -498,4 +498,4 @@ return out def get_track_type( self ): - return "FeatureTrack", {"data": "tabix", "index": "summary_tree"} + return "VcfTrack", {"data": "tabix", "index": "summary_tree"} diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef lib/galaxy/visualization/tracks/data_providers.py --- a/lib/galaxy/visualization/tracks/data_providers.py +++ b/lib/galaxy/visualization/tracks/data_providers.py @@ -661,36 +661,81 @@ class VcfDataProvider( TabixDataProvider ): """ - VCF data provider for the Galaxy track browser. - - Payload format: - [ uid (offset), start, end, ID, reference base(s), alternate base(s), quality score ] + VCF data provider. Payload format uses the read format. """ col_name_data_attr_mapping = { 'Qual' : { 'index': 6 , 'name' : 'Qual' } } def process_data( self, iterator, start_val=0, max_vals=sys.maxint, **kwargs ): + """ + Returns a dict with the following attributes: + data - a list of variants with the format + [<guid>, <start>, <end>, <name>, cigar, seq] + + message - error/informative message + """ rval = [] message = None + def get_mapping( ref, alt ): + """ + Returns ( offset, new_seq, cigar ) tuple that defines mapping of + alt to ref. Cigar format is an array of [ op_index, length ] pairs + where op_index is the 0-based index into the string "MIDNSHP=X" + """ + + cig_ops = "MIDNSHP=X" + + ref_len = len( ref ) + alt_len = len( alt ) + + # Substitutions? + if ref_len == alt_len: + return 0, alt, [ [ cig_ops.find( "M" ), ref_len ] ] + + # Deletions? + alt_in_ref_index = ref.find( alt ) + if alt_in_ref_index != -1: + return alt_in_ref_index, ref[ alt_in_ref_index + 1: ], [ [ cig_ops.find( "D" ), ref_len - alt_len ] ] + + # Insertions? + ref_in_alt_index = alt.find( ref ) + if ref_in_alt_index != -1: + return ref_in_alt_index, alt[ ref_in_alt_index + 1: ], [ [ cig_ops.find( "I" ), alt_len - ref_len ] ] + + # Pack data. for count, line in enumerate( iterator ): if count < start_val: continue if count-start_val >= max_vals: message = ERROR_MAX_VALS % ( "max_vals", "features" ) break + + feature = line.split() + start = int( feature[1] ) - 1 + ref = feature[3] + alts = feature[4] - feature = line.split() - payload = [ hash(line), int(feature[1])-1, int(feature[1]), - # ID: - feature[2], - # reference base(s): - feature[3], - # alternative base(s) - feature[4], - # phred quality score - float( feature[5] )] - rval.append(payload) + # HACK? alts == '.' --> monomorphism. + if alts == '.': + alts = ref + + # Pack variants. + for alt in alts.split(","): + offset, new_seq, cigar = get_mapping( ref, alt ) + start += offset + end = start + len( new_seq ) + + # Pack line. + payload = [ hash( line ), + start, + end, + # ID: + feature[2], + cigar, + new_seq, + float( feature[5] )] + rval.append(payload) return { 'data': rval, 'message': message } diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef static/scripts/packed/trackster.js --- a/static/scripts/packed/trackster.js +++ b/static/scripts/packed/trackster.js @@ -1,1 +1,1 @@ -var class_module=function(b,a){var c=function(){var f=arguments[0];for(var e=1;e<arguments.length;e++){var d=arguments[e];for(key in d){f[key]=d[key]}}return f};a.extend=c};var requestAnimationFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b,a){window.setTimeout(b,1000/60)}})();var BEFORE=1001,CONTAINS=1002,OVERLAP_START=1003,OVERLAP_END=1004,CONTAINED_BY=1005,AFTER=1006;var compute_overlap=function(e,b){var g=e[0],f=e[1],d=b[0],c=b[1],a;if(g<d){if(f<d){a=BEFORE}else{if(f<=c){a=OVERLAP_START}else{a=CONTAINS}}}else{if(g>c){a=AFTER}else{if(f<=c){a=CONTAINED_BY}else{a=OVERLAP_END}}}return a};var is_overlap=function(c,b){var a=compute_overlap(c,b);return(a!==BEFORE&&a!==AFTER)};var get_random_color=function(a){if(!a){a="#ffffff"}if(typeof(a)==="string"){a=[a]}for(var j=0;j<a.length;j++){a[j]=parseInt(a[j].slice(1),16)}var m=function(u,t,s){return((u*299)+(t*587)+(s*114))/1000};var e=function(v,u,w,s,r,t){return(Math.max(v,s)-Math.min(v,s))+(Math.max(u,r)-Math.min(u,r))+(Math.max(w,t)-Math.min(w,t))};var g,n,f,k,p,h,q,c,d,b,o,l=false;do{g=Math.random()*16777215;n=g|16711680;f=g|65280;k=g|255;d=m(n,f,k);l=true;for(var j=0;j<a.length;j++){p=a[j];h=p|16711680;q=p|65280;c=p|255;b=m(h,q,c);o=e(n,f,k,h,q,c);if((Math.abs(d-b)<125)||(o<500)){l=false;break}}}while(!l);return"#"+(16777216+g).toString(16).substr(1,6)};var trackster_module=function(f,Z){var q=f("class").extend,t=f("slotting"),N=f("painters");var ag=function(ah,ai){this.document=ah;this.default_font=ai!==undefined?ai:"9px Monaco, Lucida Console, monospace";this.dummy_canvas=this.new_canvas();this.dummy_context=this.dummy_canvas.getContext("2d");this.dummy_context.font=this.default_font;this.char_width_px=this.dummy_context.measureText("A").width;this.patterns={};this.load_pattern("right_strand","/visualization/strand_right.png");this.load_pattern("left_strand","/visualization/strand_left.png");this.load_pattern("right_strand_inv","/visualization/strand_right_inv.png");this.load_pattern("left_strand_inv","/visualization/strand_left_inv.png")};q(ag.prototype,{load_pattern:function(ah,al){var ai=this.patterns,aj=this.dummy_context,ak=new Image();ak.src=image_path+al;ak.onload=function(){ai[ah]=aj.createPattern(ak,"repeat")}},get_pattern:function(ah){return this.patterns[ah]},new_canvas:function(){var ah=this.document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(ah)}ah.manager=this;return ah}});var o={};var m=function(ah,ai){o[ah.attr("id")]=ai};var n=function(ah,aj,al,ak){al=".group";var ai={};o[ah.attr("id")]=ak;ah.bind("drag",{handle:"."+aj,relative:true},function(au,av){var at=$(this);var ay=$(this).parent(),ap=ay.children(),ar=o[$(this).attr("id")],ao,an,aw,am,aq;an=$(this).parents(al);if(an.length!==0){aw=an.position().top;am=aw+an.outerHeight();if(av.offsetY<aw){$(this).insertBefore(an);var ax=o[an.attr("id")];ax.remove_drawable(ar);ax.container.add_drawable_before(ar,ax);return}else{if(av.offsetY>am){$(this).insertAfter(an);var ax=o[an.attr("id")];ax.remove_drawable(ar);ax.container.add_drawable(ar);return}}}an=null;for(aq=0;aq<ap.length;aq++){ao=$(ap.get(aq));aw=ao.position().top;am=aw+ao.outerHeight();if(ao.is(al)&&this!==ao.get(0)&&av.offsetY>=aw&&av.offsetY<=am){if(av.offsetY-aw<am-av.offsetY){ao.find(".content-div").prepend(this)}else{ao.find(".content-div").append(this)}if(ar.container){ar.container.remove_drawable(ar)}o[ao.attr("id")].add_drawable(ar);return}}for(aq=0;aq<ap.length;aq++){if(av.offsetY<$(ap.get(aq)).position().top){break}}if(aq===ap.length){if(this!==ap.get(aq-1)){ay.append(this);o[ay.attr("id")].move_drawable(ar,aq)}}else{if(this!==ap.get(aq)){$(this).insertBefore(ap.get(aq));o[ay.attr("id")].move_drawable(ar,(av.deltaY>0?aq-1:aq))}}}).bind("dragstart",function(){ai["border-top"]=ah.css("border-top");ai["border-bottom"]=ah.css("border-bottom");$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css(ai)})};Z.moveable=n;var af=16,I=9,F=20,U=I+2,A=100,K=12000,S=200,D=5,w=10,M=5000,x=100,p="There was an error in indexing this dataset. ",L="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",G="No data for this chrom/contig.",u="Currently indexing... please wait",y="Tool cannot be rerun: ",a="Loading data...",aa="Ready for display",d=10,v=5,C=5;function ab(ai,ah){if(!ah){ah=0}var aj=Math.pow(10,ah);return Math.round(ai*aj)/aj}var c=function(ah){this.num_elements=ah;this.clear()};q(c.prototype,{get:function(ai){var ah=this.key_ary.indexOf(ai);if(ah!==-1){if(this.obj_cache[ai].stale){this.key_ary.splice(ah,1);delete this.obj_cache[ai]}else{this.move_key_to_end(ai,ah)}}return this.obj_cache[ai]},set:function(ai,aj){if(!this.obj_cache[ai]){if(this.key_ary.length>=this.num_elements){var ah=this.key_ary.shift();delete this.obj_cache[ah]}this.key_ary.push(ai)}this.obj_cache[ai]=aj;return aj},move_key_to_end:function(ai,ah){this.key_ary.splice(ah,1);this.key_ary.push(ai)},clear:function(){this.obj_cache={};this.key_ary=[]},size:function(){return this.key_ary.length}});var T=function(ai,ah,aj){c.call(this,ai);this.track=ah;this.subset=(aj!==undefined?aj:true)};q(T.prototype,c.prototype,{load_data:function(aq,al,ao,ai,an){var ap=this.track.view.chrom,ak={chrom:ap,low:aq,high:al,mode:ao,resolution:ai,dataset_id:this.track.dataset_id,hda_ldda:this.track.hda_ldda};$.extend(ak,an);if(this.track.filters_manager){var ar=[];var ah=this.track.filters_manager.filters;for(var am=0;am<ah.length;am++){ar[ar.length]=ah[am].name}ak.filter_cols=JSON.stringify(ar)}var aj=this;return $.getJSON(this.track.data_url,ak,function(at){aj.set_data(aq,al,ao,at)})},get_data:function(ah,al,am,ai,ak){var aj=this.get_data_from_cache(ah,al,am);if(aj){return aj}aj=this.load_data(ah,al,am,ai,ak);this.set_data(ah,al,am,aj);return aj},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(ap,ak,ao,aj,an,al){var aq=this.get_data_from_cache(ap,ak,ao);if(!aq){console.log("ERROR: no current data for: ",this.track,ap,ak,ao,aj,an);return}aq.stale=true;var ai=ap;if(al===this.DEEP_DATA_REQ){$.extend(an,{start_val:aq.data.length+1})}else{if(al===this.BROAD_DATA_REQ){ai=(aq.max_high?aq.max_high:aq.data[aq.data.length-1][2])+1}}var ah=this,am=this.load_data(ai,ak,ao,aj,an);new_data_available=$.Deferred();this.set_data(ap,ak,ao,new_data_available);$.when(am).then(function(ar){if(ar.data){ar.data=aq.data.concat(ar.data);if(ar.max_low){ar.max_low=aq.max_low}if(ar.message){ar.message=ar.message.replace(/[0-9]+/,ar.data.length)}}ah.set_data(ap,ak,ao,ar);new_data_available.resolve(ar)});return new_data_available},get_data_from_cache:function(ah,ai,aj){return this.get(this.gen_key(ah,ai,aj))},set_data:function(ai,aj,ak,ah){return this.set(this.gen_key(ai,aj,ak),ah)},gen_key:function(ah,aj,ak){var ai=ah+"_"+aj+"_"+ak;return ai},split_key:function(ah){return ah.split("_")}});var J=function(ai,ah,aj){T.call(this,ai,ah,aj)};q(J.prototype,T.prototype,c.prototype,{load_data:function(ah,ak,al,ai,aj){if(ai>1){return{data:null}}return T.prototype.load_data.call(this,ah,ak,al,ai,aj)}});var r=function(ak,ai,ah,aj,al){this.name=ak;this.view=ai;this.container=ah;this.config=new H({track:this,params:[{key:"name",label:"Name",type:"text",default_value:ak}],saved_values:aj,onchange:function(){this.track.set_name(this.track.config.values.name)}});this.prefs=this.config.values;this.drag_handle_class=al;this.is_overview=false};q(r.prototype,{init:function(){},request_draw:function(){},_draw:function(){},to_json:function(){},update_track_icons:function(){},set_name:function(ah){this.old_name=this.name;this.name=ah;this.name_div.text(this.name)},revert_name:function(){this.name=this.old_name;this.name_div.text(this.name)},remove:function(){this.container.remove_drawable(this);this.container_div.fadeOut("slow",function(){$(this).remove();view.update_intro_div();view.has_changes=true})}});var z=function(al,ak,ai,ah,aj,am){r.call(this,ak,ai,ah,aj,am);this.obj_type=al;this.drawables=[]};q(z.prototype,r.prototype,{init:function(){for(var ah=0;ah<this.drawables.length;ah++){this.drawables[ah].init()}},_draw:function(){for(var ah=0;ah<this.drawables.length;ah++){this.drawables[ah]._draw()}},to_json:function(){var ai=[];for(var ah=0;ah<this.drawables.length;ah++){ai.push(this.drawables[ah].to_json())}return{name:this.name,prefs:this.prefs,obj_type:this.obj_type,drawables:ai}},add_drawable:function(ah){this.drawables.push(ah);ah.container=this},add_drawable_before:function(aj,ah){var ai=this.drawables.indexOf(ah);if(ai!=-1){this.drawables.splice(ai,0,aj);return true}return false},remove_drawable:function(ai){var ah=this.drawables.indexOf(ai);if(ah!=-1){this.drawables.splice(ah,1);ai.container=null;return true}return false},move_drawable:function(ai,aj){var ah=this.drawables.indexOf(ai);if(ah!=-1){this.drawables.splice(ah,1);this.drawables.splice(aj,0,ai);return true}return false}});var R=function(ak,ai,ah,aj){z.call(this,"DrawableGroup",ak,ai,ah,aj,"group-handle");if(!R.id_counter){R.id_counter=0}var al=R.id_counter++;this.container_div=$("<div/>").addClass("group").attr("id","group_"+al).appendTo(this.container.content_div);this.header_div=$("<div/>").addClass("track-header").appendTo(this.container_div);this.header_div.append($("<div/>").addClass(this.drag_handle_class));this.name_div=$("<div/>").addClass("group-name menubutton popup").text(this.name).appendTo(this.header_div);this.content_div=$("<div/>").addClass("content-div").attr("id","group_"+al+"_content_div").appendTo(this.container_div);m(this.container_div,this);m(this.content_div,this);n(this.container_div,this.drag_handle_class,".group",this);this.update_track_icons()};q(R.prototype,r.prototype,z.prototype,{update_track_icons:function(){var ai=this;var ah={};ah["Edit configuration"]=function(){var al=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},aj=function(){ai.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},ak=function(am){if((am.keyCode||am.which)===27){al()}else{if((am.keyCode||am.which)===13){aj()}}};$(window).bind("keypress.check_enter_esc",ak);show_modal("Configure Group",ai.config.build_form(),{Cancel:al,OK:aj})};ah.Remove=function(){ai.remove()};make_popupmenu(ai.name_div,ah)}});var ae=function(ah,ak,aj,ai){z.call(this,"View");this.container=ah;this.chrom=null;this.vis_id=aj;this.dbkey=ai;this.title=ak;this.label_tracks=[];this.tracks_to_be_redrawn=[];this.max_low=0;this.max_high=0;this.zoom_factor=3;this.min_separation=30;this.has_changes=false;this.load_chroms_deferred=null;this.init();this.canvas_manager=new ag(ah.get(0).ownerDocument);this.reset()};q(ae.prototype,z.prototype,{init:function(){var aj=this.container,ah=this;this.top_container=$("<div/>").addClass("top-container").appendTo(aj);this.browser_content_div=$("<div/>").addClass("content").css("position","relative").appendTo(aj);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(aj);this.top_labeltrack=$("<div/>").addClass("top-labeltrack").appendTo(this.top_container);this.viewport_container=$("<div/>").addClass("viewport-container").attr("id","viewport-container").appendTo(this.browser_content_div);this.content_div=this.viewport_container;m(this.viewport_container,ah);this.intro_div=$("<div/>").addClass("intro");var ak=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_tracks()});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("nav").appendTo(this.nav_container);this.overview=$("<div/>").addClass("overview").appendTo(this.bottom_container);this.overview_viewport=$("<div/>").addClass("overview-viewport").appendTo(this.overview);this.overview_close=$("<a/>").attr("href","javascript:void(0);").attr("title","Close overview").addClass("icon-button overview-close tooltip").hide().appendTo(this.overview_viewport);this.overview_highlight=$("<div/>").addClass("overview-highlight").hide().appendTo(this.overview_viewport);this.overview_box_background=$("<div/>").addClass("overview-boxback").appendTo(this.overview_viewport);this.overview_box=$("<div/>").addClass("overview-box").appendTo(this.overview_viewport);this.default_overview_height=this.overview_box.height();this.nav_controls=$("<div/>").addClass("nav-controls").appendTo(this.nav);this.chrom_select=$("<select/>").attr({name:"chrom"}).css("width","15em").addClass("no-autocomplete").append("<option value=''>Loading</option>").appendTo(this.nav_controls);var ai=function(al){if(al.type==="focusout"||(al.keyCode||al.which)===13||(al.keyCode||al.which)===27){if((al.keyCode||al.which)!==27){ah.go_to($(this).val())}$(this).hide();$(this).val("");ah.location_span.show();ah.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",ai).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").appendTo(this.nav_controls);this.location_span.click(function(){ah.location_span.hide();ah.chrom_select.hide();ah.nav_input.val(ah.chrom+":"+ah.low+"-"+ah.high);ah.nav_input.css("display","inline-block");ah.nav_input.select();ah.nav_input.focus()});if(this.vis_id!==undefined){this.hidden_input=$("<input/>").attr("type","hidden").val(this.vis_id).appendTo(this.nav_controls)}this.zo_link=$("<a id='zoom-out' />").click(function(){ah.zoom_out();ah.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a id='zoom-in' />").click(function(){ah.zoom_in();ah.request_redraw()}).appendTo(this.nav_controls);this.load_chroms_deferred=this.load_chroms({low:0});this.chrom_select.bind("change",function(){ah.change_chrom(ah.chrom_select.val())});this.browser_content_div.click(function(al){$(this).find("input").trigger("blur")});this.browser_content_div.bind("dblclick",function(al){ah.zoom_in(al.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(al,am){this.current_x=am.offsetX}).bind("drag",function(al,an){var ao=an.offsetX-this.current_x;this.current_x=an.offsetX;var am=Math.round(ao/ah.viewport_container.width()*(ah.max_high-ah.max_low));ah.move_delta(-am)});this.overview_close.click(function(){ah.reset_overview()});this.viewport_container.bind("draginit",function(al,am){if(al.clientX>ah.viewport_container.width()-16){return false}}).bind("dragstart",function(al,am){am.original_low=ah.low;am.current_height=al.clientY;am.current_x=am.offsetX}).bind("drag",function(an,ap){var al=$(this);var aq=ap.offsetX-ap.current_x;var am=al.scrollTop()-(an.clientY-ap.current_height);al.scrollTop(am);ap.current_height=an.clientY;ap.current_x=ap.offsetX;var ao=Math.round(aq/ah.viewport_container.width()*(ah.high-ah.low));ah.move_delta(ao)}).bind("mousewheel",function(an,ap,am,al){if(am){var ao=Math.round(-am/ah.viewport_container.width()*(ah.high-ah.low));ah.move_delta(ao)}});this.top_labeltrack.bind("dragstart",function(al,am){return $("<div />").css({height:ah.browser_content_div.height()+ah.top_labeltrack.height()+ah.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(ap,aq){$(aq.proxy).css({left:Math.min(ap.pageX,aq.startX),width:Math.abs(ap.pageX-aq.startX)});var am=Math.min(ap.pageX,aq.startX)-ah.container.offset().left,al=Math.max(ap.pageX,aq.startX)-ah.container.offset().left,ao=(ah.high-ah.low),an=ah.viewport_container.width();ah.update_location(Math.round(am/an*ao)+ah.low,Math.round(al/an*ao)+ah.low)}).bind("dragend",function(aq,ar){var am=Math.min(aq.pageX,ar.startX),al=Math.max(aq.pageX,ar.startX),ao=(ah.high-ah.low),an=ah.viewport_container.width(),ap=ah.low;ah.low=Math.round(am/an*ao)+ap;ah.high=Math.round(al/an*ao)+ap;$(ar.proxy).remove();ah.request_redraw()});this.add_label_track(new ad(this,{content_div:this.top_labeltrack}));this.add_label_track(new ad(this,{content_div:this.nav_labeltrack}));$(window).bind("resize",function(){ah.resize_window()});$(document).bind("redraw",function(){ah.redraw()});this.reset();$(window).trigger("resize");this.update_intro_div()},update_intro_div:function(){if(this.num_tracks===0){this.intro_div.appendTo(this.viewport_container)}else{this.intro_div.remove()}},update_location:function(ah,ai){this.location_span.text(commatize(ah)+" - "+commatize(ai));this.nav_input.val(this.chrom+":"+commatize(ah)+"-"+commatize(ai))},load_chroms:function(aj){aj.num=x;$.extend(aj,(this.vis_id!==undefined?{vis_id:this.vis_id}:{dbkey:this.dbkey}));var ah=this,ai=$.Deferred();$.ajax({url:chrom_url,data:aj,dataType:"json",success:function(al){if(al.chrom_info.length===0){alert("Invalid chromosome: "+aj.chrom);return}if(al.reference){ah.add_label_track(new B(ah))}ah.chrom_data=al.chrom_info;var ao='<option value="">Select Chrom/Contig</option>';for(var an=0,ak=ah.chrom_data.length;an<ak;an++){var am=ah.chrom_data[an].chrom;ao+='<option value="'+am+'">'+am+"</option>"}if(al.prev_chroms){ao+='<option value="previous">Previous '+x+"</option>"}if(al.next_chroms){ao+='<option value="next">Next '+x+"</option>"}ah.chrom_select.html(ao);ah.chrom_start_index=al.start_index;ai.resolve(al)},error:function(){alert("Could not load chroms for this dbkey:",ah.dbkey)}});return ai},change_chrom:function(am,ai,ao){if(!am||am==="None"){return}var aj=this;if(am==="previous"){aj.load_chroms({low:this.chrom_start_index-x});return}if(am==="next"){aj.load_chroms({low:this.chrom_start_index+x});return}var an=$.grep(aj.chrom_data,function(ap,aq){return ap.chrom===am})[0];if(an===undefined){aj.load_chroms({chrom:am},function(){aj.change_chrom(am,ai,ao)});return}else{if(am!==aj.chrom){aj.chrom=am;aj.chrom_select.val(aj.chrom);aj.max_high=an.len-1;aj.reset();aj.request_redraw(true);for(var al=0,ah=aj.drawables.length;al<ah;al++){var ak=aj.drawables[al];if(ak.init){ak.init()}}}if(ai!==undefined&&ao!==undefined){aj.low=Math.max(ai,0);aj.high=Math.min(ao,aj.max_high)}aj.reset_overview();aj.request_redraw()}},go_to:function(al){var ap=this,ah,ak,ai=al.split(":"),an=ai[0],ao=ai[1];if(ao!==undefined){try{var am=ao.split("-");ah=parseInt(am[0].replace(/,/g,""),10);ak=parseInt(am[1].replace(/,/g,""),10)}catch(aj){return false}}ap.change_chrom(an,ah,ak)},move_fraction:function(aj){var ah=this;var ai=ah.high-ah.low;this.move_delta(aj*ai)},move_delta:function(aj){var ah=this;var ai=ah.high-ah.low;if(ah.low-aj<ah.max_low){ah.low=ah.max_low;ah.high=ah.max_low+ai}else{if(ah.high-aj>ah.max_high){ah.high=ah.max_high;ah.low=ah.max_high-ai}else{ah.high-=aj;ah.low-=aj}}ah.request_redraw()},add_drawable:function(ah){z.prototype.add_drawable.call(this,ah);ah.init();this.has_changes=true;this.update_intro_div()},add_label_track:function(ah){ah.view=this;ah.init();this.label_tracks.push(ah)},remove_drawable:function(aj,ai){z.prototype.remove_drawable.call(this,aj);if(ai){var ah=this;aj.container_div.fadeOut("slow",function(){$(this).remove();ah.update_intro_div()});this.has_changes=true}},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(ap,ah,ao,ai){var an=this,al=(ai?[ai]:an.drawables),aj;var ai;for(var am=0;am<al.length;am++){ai=al[am];aj=-1;for(var ak=0;ak<an.tracks_to_be_redrawn.length;ak++){if(an.tracks_to_be_redrawn[ak][0]===ai){aj=ak;break}}if(aj<0){an.tracks_to_be_redrawn.push([ai,ah,ao])}else{an.tracks_to_be_redrawn[am][1]=ah;an.tracks_to_be_redrawn[am][2]=ao}}requestAnimationFrame(function(){an._redraw(ap)})},_redraw:function(ar){var ao=this.low,ak=this.high;if(ao<this.max_low){ao=this.max_low}if(ak>this.max_high){ak=this.max_high}var aq=this.high-this.low;if(this.high!==0&&aq<this.min_separation){ak=ao+this.min_separation}this.low=Math.floor(ao);this.high=Math.ceil(ak);this.resolution=Math.pow(D,Math.ceil(Math.log((this.high-this.low)/S)/Math.log(D)));this.zoom_res=Math.pow(w,Math.max(0,Math.ceil(Math.log(this.resolution,w)/Math.log(w))));var ah=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var an=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var at=13;this.overview_box.css({left:ah,width:Math.max(at,an)}).show();if(an<at){this.overview_box.css("left",ah-(at-an)/2)}if(this.overview_highlight){this.overview_highlight.css({left:ah,width:an})}this.update_location(this.low,this.high);if(!ar){var aj,ai,ap;for(var al=0,am=this.tracks_to_be_redrawn.length;al<am;al++){aj=this.tracks_to_be_redrawn[al][0];ai=this.tracks_to_be_redrawn[al][1];ap=this.tracks_to_be_redrawn[al][2];if(aj){aj._draw(ai,ap)}}this.tracks_to_be_redrawn=[];for(al=0,am=this.label_tracks.length;al<am;al++){this.label_tracks[al]._draw()}}},zoom_in:function(ai,aj){if(this.max_high===0||this.high-this.low<this.min_separation){return}var ak=this.high-this.low,al=ak/2+this.low,ah=(ak/this.zoom_factor)/2;if(ai){al=ai/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(al-ah);this.high=Math.round(al+ah);this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var ai=this.high-this.low,aj=ai/2+this.low,ah=(ai*this.zoom_factor)/2;this.low=Math.round(aj-ah);this.high=Math.round(aj+ah);this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.nav_container.width(this.container.width());this.request_redraw()},set_overview:function(aj){if(this.overview_drawable){if(this.overview_drawable.dataset_id===aj.dataset_id){return}this.overview_viewport.find(".track").remove()}var ai=aj.copy({content_div:this.overview_viewport}),ah=this;ai.header_div.hide();ai.is_overview=true;ah.overview_drawable=ai;this.overview_drawable.postdraw_actions=function(){ah.overview_highlight.show().height(ah.overview_drawable.content_div.height());ah.overview_viewport.height(ah.overview_drawable.content_div.height()+ah.overview_box.outerHeight());ah.overview_close.show();ah.resize_window()};this.overview_drawable.init();ah.has_changes=true},reset_overview:function(){$(".tipsy").remove();this.overview_viewport.find(".track-tile").remove();this.overview_viewport.height(this.default_overview_height);this.overview_box.height(this.default_overview_height);this.overview_close.hide();this.overview_highlight.hide();view.resize_window();view.overview_drawable=null}});var s=function(aj,an){this.track=aj;this.name=an.name;this.params=[];var av=an.params;for(var ak=0;ak<av.length;ak++){var ap=av[ak],ai=ap.name,au=ap.label,al=unescape(ap.html),aw=ap.value,ar=ap.type;if(ar==="number"){this.params[this.params.length]=new g(ai,au,al,aw,ap.min,ap.max)}else{if(ar=="select"){this.params[this.params.length]=new P(ai,au,al,aw)}else{console.log("WARNING: unrecognized tool parameter type:",ai,ar)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(ay){ay.stopPropagation()}).click(function(ay){ay.stopPropagation()}).bind("dblclick",function(ay){ay.stopPropagation()});var at=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var aq=this.params;var ao=this;$.each(this.params,function(az,aC){var aB=$("<div>").addClass("param-row").appendTo(ao.parent_div);var ay=$("<div>").addClass("param-label").text(aC.label).appendTo(aB);var aA=$("<div/>").addClass("slider").html(aC.html).appendTo(aB);aA.find(":input").val(aC.value);$("<div style='clear: both;'/>").appendTo(aB)});this.parent_div.find("input").click(function(){$(this).select()});var ax=$("<div>").addClass("param-row").appendTo(this.parent_div);var am=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(ax);var ah=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(ax);var ao=this;ah.click(function(){ao.run_on_region()});am.click(function(){ao.run_on_dataset()})};q(s.prototype,{get_param_values_dict:function(){var ah={};this.parent_div.find(":input").each(function(){var ai=$(this).attr("name"),aj=$(this).val();ah[ai]=JSON.stringify(aj)});return ah},get_param_values:function(){var ai=[];var ah={};this.parent_div.find(":input").each(function(){var aj=$(this).attr("name"),ak=$(this).val();if(aj){ai[ai.length]=ak}});return ai},run_on_dataset:function(){var ah=this;ah.run({dataset_id:this.track.original_dataset_id,tool_id:ah.name},null,function(ai){show_modal(ah.name+" is Running",ah.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var ai={dataset_id:this.track.original_dataset_id,chrom:this.track.view.chrom,low:this.track.view.low,high:this.track.view.high,tool_id:this.name},al=this.track,aj=ai.tool_id+al.tool_region_and_parameters_str(ai.chrom,ai.low,ai.high),ah,am;if(al.container===view){var ak=new R(this.name,this.track.view,this.track.container);al.container.add_drawable(ak);al.container.remove_drawable(al);ak.add_drawable(al);al.container_div.appendTo(ak.content_div);ah=ak}else{ah=al.container}if(al instanceof e){am=new W(aj,view,ah,"hda");am.change_mode(al.mode);ah.add_drawable(am)}am.content_div.text("Starting job.");this.run(ai,am,function(an){am.dataset_id=an.dataset_id;am.content_div.text("Running job.");am.init()})},run:function(ai,aj,ak){$.extend(ai,this.get_param_values_dict());var ah=function(){$.getJSON(rerun_tool_url,ai,function(al){if(al==="no converter"){aj.container_div.addClass("error");aj.content_div.text(L)}else{if(al.error){aj.container_div.addClass("error");aj.content_div.text(y+al.message)}else{if(al==="pending"){aj.container_div.addClass("pending");aj.content_div.text("Converting input data so that it can be used quickly with tool.");setTimeout(ah,2000)}else{ak(al)}}}})};ah()}});var P=function(ai,ah,aj,ak){this.name=ai;this.label=ah;this.html=aj;this.value=ak};var g=function(aj,ai,al,am,ak,ah){P.call(this,aj,ai,al,am);this.min=ak;this.max=ah};var h=function(ai,ah,aj,ak){this.name=ai;this.index=ah;this.tool_id=aj;this.tool_exp_name=ak};var X=function(ai,ah,aj,ak){h.call(this,ai,ah,aj,ak);this.low=-Number.MAX_VALUE;this.high=Number.MAX_VALUE;this.min=Number.MAX_VALUE;this.max=-Number.MAX_VALUE;this.container=null;this.slider=null;this.slider_label=null};q(X.prototype,{applies_to:function(ah){if(ah.length>this.index){return true}return false},keep:function(ah){if(!this.applies_to(ah)){return true}var ai=ah[this.index];return(isNaN(ai)||(ai>=this.low&&ai<=this.high))},update_attrs:function(ai){var ah=false;if(!this.applies_to(ai)){return ah}if(ai[this.index]<this.min){this.min=Math.floor(ai[this.index]);ah=true}if(ai[this.index]>this.max){this.max=Math.ceil(ai[this.index]);ah=true}return ah},update_ui_elt:function(){if(this.min!=this.max){this.container.show()}else{this.container.hide()}var aj=function(am,ak){var al=ak-am;return(al<=2?0.01:1)};var ai=this.slider.slider("option","min"),ah=this.slider.slider("option","max");if(this.min<ai||this.max>ah){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",aj(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var ac=function(at,aA){this.track=at;this.filters=[];for(var av=0;av<aA.length;av++){var aw=aA[av],aB=aw.name,ah=aw.type,aj=aw.index,az=aw.tool_id,ay=aw.tool_exp_name;if(ah==="int"||ah==="float"){this.filters[av]=new X(aB,aj,az,ay)}else{console.log("ERROR: unsupported filter: ",aB,ah)}}var ak=function(aC,aD,aE){aC.click(function(){var aF=aD.text();max=parseFloat(aE.slider("option","max")),input_size=(max<=1?4:max<=1000000?max.toString().length:6),multi_value=false;if(aE.slider("option","values")){input_size=2*input_size+1;multi_value=true}aD.text("");$("<input type='text'/>").attr("size",input_size).attr("maxlength",input_size).attr("value",aF).appendTo(aD).focus().select().click(function(aG){aG.stopPropagation()}).blur(function(){$(this).remove();aD.text(aF)}).keyup(function(aK){if(aK.keyCode===27){$(this).trigger("blur")}else{if(aK.keyCode===13){var aI=aE.slider("option","min"),aG=aE.slider("option","max"),aJ=function(aL){return(isNaN(aL)||aL>aG||aL<aI)},aH=$(this).val();if(!multi_value){aH=parseFloat(aH);if(aJ(aH)){alert("Parameter value must be in the range ["+aI+"-"+aG+"]");return $(this)}}else{aH=aH.split("-");aH=[parseFloat(aH[0]),parseFloat(aH[1])];if(aJ(aH[0])||aJ(aH[1])){alert("Parameter value must be in the range ["+aI+"-"+aG+"]");return $(this)}}aE.slider((multi_value?"values":"value"),aH)}}})})};this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(aC){aC.stopPropagation()}).click(function(aC){aC.stopPropagation()}).bind("dblclick",function(aC){aC.stopPropagation()}).bind("keydown",function(aC){aC.stopPropagation()});var ax=$("<div/>").addClass("sliders").appendTo(this.parent_div);var ap=this;$.each(this.filters,function(aF,aH){aH.container=$("<div/>").addClass("filter-row slider-row").appendTo(ax);var aG=$("<div/>").addClass("elt-label").appendTo(aH.container);var aE=$("<span/>").addClass("slider-name").text(aH.name+" ").appendTo(aG);var aD=$("<span/>");var aJ=$("<span/>").addClass("slider-value").appendTo(aG).append("[").append(aD).append("]");var aC=$("<div/>").addClass("slider").appendTo(aH.container);aH.control_element=$("<div/>").attr("id",aH.name+"-filter-control").appendTo(aC);var aI=[0,0];aH.control_element.slider({range:true,min:Number.MAX_VALUE,max:-Number.MIN_VALUE,values:[0,0],slide:function(aL,aM){var aK=aM.values;aD.text(aK[0]+"-"+aK[1]);aH.low=aK[0];aH.high=aK[1];ap.track.request_draw(true,true)},change:function(aK,aL){aH.control_element.slider("option","slide").call(aH.control_element,aK,aL)}});aH.slider=aH.control_element;aH.slider_label=aD;ak(aJ,aD,aH.control_element);$("<div style='clear: both;'/>").appendTo(aH.container)});if(this.filters.length!==0){var am=$("<div/>").addClass("param-row").appendTo(ax);var ao=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(am);var ai=this;ao.click(function(){ai.run_on_dataset()})}var ar=$("<div/>").addClass("display-controls").appendTo(this.parent_div),au,an,aq,al={Transparency:function(aC){ap.alpha_filter=aC},Height:function(aC){ap.height_filter=aC}};$.each(al,function(aE,aD){au=$("<div/>").addClass("filter-row").appendTo(ar),an=$("<span/>").addClass("elt-label").text(aE+":").appendTo(au),aq=$("<select/>").attr("name",aE+"_dropdown").css("float","right").appendTo(au);$("<option/>").attr("value",-1).text("== None ==").appendTo(aq);for(var aC=0;aC<ap.filters.length;aC++){$("<option/>").attr("value",aC).text(ap.filters[aC].name).appendTo(aq)}aq.change(function(){$(this).children("option:selected").each(function(){var aF=parseInt($(this).val());al[aE]((aF>=0?ap.filters[aF]:null));ap.track.request_draw(true,true)})});$("<div style='clear: both;'/>").appendTo(au)});$("<div style='clear: both;'/>").appendTo(this.parent_div)};q(ac.prototype,{reset_filters:function(){for(var ah=0;ah<this.filters.length;ah++){filter=this.filters[ah];filter.slider.slider("option","values",[filter.min,filter.max])}this.alpha_filter=null;this.height_filter=null},run_on_dataset:function(){var ap=function(au,ar,at){if(!(ar in au)){au[ar]=at}return au[ar]};var aj={},ah,ai,ak;for(var al=0;al<this.filters.length;al++){ah=this.filters[al];if(ah.tool_id){if(ah.min!=ah.low){ai=ap(aj,ah.tool_id,[]);ai[ai.length]=ah.tool_exp_name+" >= "+ah.low}if(ah.max!=ah.high){ai=ap(aj,ah.tool_id,[]);ai[ai.length]=ah.tool_exp_name+" <= "+ah.high}}}var an=[];for(var aq in aj){an[an.length]=[aq,aj[aq]]}var ao=an.length;(function am(ay,av){var at=av[0],au=at[0],ax=at[1],aw="("+ax.join(") and (")+")",ar={cond:aw,input:ay,target_dataset_id:ay,tool_id:au},av=av.slice(1);$.getJSON(run_tool_url,ar,function(az){if(az.error){show_modal("Filter Dataset","Error running tool "+au,{Close:hide_modal})}else{if(av.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{am(az.dataset_id,av)}}})})(this.track.dataset_id,an)}});var E=function(ah,ai){N.Scaler.call(this,ai);this.filter=ah};E.prototype.gen_val=function(ah){if(this.filter.high===Number.MAX_VALUE||this.filter.low===-Number.MAX_VALUE||this.filter.low===this.filter.high){return this.default_val}return((parseFloat(ah[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var H=function(ah){this.track=ah.track;this.params=ah.params;this.values={};this.restore_values((ah.saved_values?ah.saved_values:{}));this.onchange=ah.onchange};q(H.prototype,{restore_values:function(ah){var ai=this;$.each(this.params,function(aj,ak){if(ah[ak.key]!==undefined){ai.values[ak.key]=ah[ak.key]}else{ai.values[ak.key]=ak.default_value}})},build_form:function(){var ai=this;var ah=$("<div />");$.each(this.params,function(am,ak){if(!ak.hidden){var aj="param_"+am;var ao=ai.values[ak.key];var ar=$("<div class='form-row' />").appendTo(ah);ar.append($("<label />").attr("for",aj).text(ak.label+":"));if(ak.type==="bool"){ar.append($('<input type="checkbox" />').attr("id",aj).attr("name",aj).attr("checked",ao))}else{if(ak.type==="text"){ar.append($('<input type="text"/>').attr("id",aj).val(ao).click(function(){$(this).select()}))}else{if(ak.type==="color"){var an=$("<input />").attr("id",aj).attr("name",aj).val(ao);var ap=$("<div class='tipsy tipsy-north' style='position: absolute;' />").hide();var al=$("<div style='background-color: black; padding: 10px;'></div>").appendTo(ap);var aq=$("<div/>").appendTo(al).farbtastic({width:100,height:100,callback:an,color:ao});$("<div />").append(an).append(ap).appendTo(ar).bind("click",function(at){ap.css({left:$(this).position().left+($(an).width()/2)-60,top:$(this).position().top+$(this.height)}).show();$(document).bind("click.color-picker",function(){ap.hide();$(document).unbind("click.color-picker")});at.stopPropagation()})}else{ar.append($("<input />").attr("id",aj).attr("name",aj).val(ao))}}}}});return ah},update_from_form:function(ah){var aj=this;var ai=false;$.each(this.params,function(ak,am){if(!am.hidden){var an="param_"+ak;var al=ah.find("#"+an).val();if(am.type==="float"){al=parseFloat(al)}else{if(am.type==="int"){al=parseInt(al)}else{if(am.type==="bool"){al=ah.find("#"+an).is(":checked")}}}if(al!==aj.values[am.key]){aj.values[am.key]=al;ai=true}}});if(ai){this.onchange()}}});var b=function(ah,ak,aj,ai,al){this.track=ah;this.index=ak;this.low=ak*S*aj;this.high=(ak+1)*S*aj;this.resolution=aj;this.canvas=$("<div class='track-tile'/>").append(ai);this.data=al;this.stale=false};b.prototype.predisplay_actions=function(){};var l=function(ah,ak,aj,ai,al,am){b.call(this,ah,ak,aj,ai,al);this.max_val=am};q(l.prototype,b.prototype);var Q=function(ah,al,ak,aj,an,ao,am,ai){b.call(this,ah,al,ak,aj,an);this.mode=ao;this.message=am;this.feature_mapper=ai};q(Q.prototype,b.prototype);Q.prototype.predisplay_actions=function(){var ai=this,ah={};if(ai.mode!=="Pack"){return}$(this.canvas).mousemove(function(au){var ao=$(this).offset(),at=au.pageX-ao.left,ar=au.pageY-ao.top,ay=ai.feature_mapper.get_feature_data(at,ar),ap=(ay?ay[0]:null);$(this).siblings(".feature-popup").each(function(){if(!ap||$(this).attr("id")!==ap.toString()){$(this).remove()}});if(ay){var ak=ah[ap];if(!ak){var ap=ay[0],av={name:ay[3],start:ay[1],end:ay[2],strand:ay[4]},an=ai.track.filters_manager.filters,am;for(var aq=0;aq<an.length;aq++){am=an[aq];av[am.name]=ay[am.index]}var ak=$("<div/>").attr("id",ap).addClass("feature-popup"),ax,aw,az=$("<table/>").appendTo(ak),aA;for(ax in av){aw=av[ax];aA=$("<tr/>").appendTo(az);$("<th/>").appendTo(aA).text(ax);$("<td/>").attr("align","left").appendTo(aA).text(typeof(aw)=="number"?ab(aw,2):aw)}ah[ap]=ak}ak.appendTo($(ai.canvas).parent());var al=at+parseInt(ai.canvas.css("left"))+7,aj=ar+parseInt(ai.canvas.css("top"))+7;ak.css("left",al+"px").css("top",aj+"px")}else{if(!au.isPropagationStopped()){au.stopPropagation();$(this).siblings().each(function(){$(this).trigger(au)})}}}).mouseleave(function(){$(this).siblings(".feature-popup").remove()})};var j=function(ak,at,al,ao,au,aj,ai){r.call(this,ak,at,al,{},"draghandle");this.data_url=(aj?aj:default_data_url);this.data_url_extra_params={};this.data_query_wait=(ai?ai:M);this.dataset_check_url=converted_datasets_state_url;if(!j.id_counter){j.id_counter=0}this.id=j.id_counter++;this.container_div=$("<div />").addClass("track").attr("id","track_"+this.id).css("position","relative");if(ao){this.header_div=$("<div class='track-header' />").appendTo(this.container_div);if(this.view.editor){this.drag_div=$("<div/>").addClass(this.drag_handle_class).appendTo(this.header_div)}this.name_div=$("<div/>").addClass("track-name").appendTo(this.header_div).text(this.name).attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase());this.icons_div=$("<div/>").css("float","left").appendTo(this.header_div).hide();this.settings_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Edit settings").addClass("icon-button settings-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);this.overview_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Set as overview").addClass("icon-button overview-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);this.filters_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Filters").addClass("icon-button filters-icon").tipsy({gravity:"s"}).appendTo(this.icons_div).hide();this.tools_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Tools").addClass("icon-button tools-icon").tipsy({gravity:"s"}).appendTo(this.icons_div).hide();this.remove_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Remove").addClass("icon-button remove-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);var am=this;this.header_div.dblclick(function(av){av.stopPropagation()});this.settings_icon.click(function(){var ax=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},av=function(){am.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},aw=function(ay){if((ay.keyCode||ay.which)===27){ax()}else{if((ay.keyCode||ay.which)===13){av()}}};$(window).bind("keypress.check_enter_esc",aw);show_modal("Configure Track",am.config.build_form(),{Cancel:ax,OK:av})});this.overview_icon.click(function(){am.view.set_overview(am)});this.filters_icon.click(function(){am.filters_div.toggle();am.filters_manager.reset_filters()});this.tools_icon.click(function(){am.dynamic_tool_div.toggle();if(am.dynamic_tool_div.is(":visible")){am.set_name(am.name+am.tool_region_and_parameters_str())}else{am.revert_name()}$(".tipsy").remove()});this.remove_icon.click(function(){$(".tipsy").remove();am.remove()});if(am.display_modes!==undefined){if(am.mode_div===undefined){am.mode_div=$("<div class='right-float menubutton popup' />").appendTo(am.header_div);var an=(am.config&&am.config.values.mode?am.config.values.mode:am.display_modes[0]);am.mode=an;am.mode_div.text(an);var ah={};for(var ap=0,ar=am.display_modes.length;ap<ar;ap++){var aq=am.display_modes[ap];ah[aq]=function(av){return function(){am.change_mode(av)}}(aq)}make_popupmenu(am.mode_div,ah)}else{am.mode_div.hide()}this.header_div.append($("<div/>").css("clear","both"));this.container_div.hover(function(){am.icons_div.show()},function(){am.icons_div.hide()})}}this.content_div=$("<div class='track-content'>").appendTo(this.container_div);this.container.content_div.append(this.container_div)};q(j.prototype,r.prototype,{get_type:function(){if(this instanceof ad){return"LabelTrack"}else{if(this instanceof B){return"ReferenceTrack"}else{if(this instanceof k){return"LineTrack"}else{if(this instanceof Y){return"ReadTrack"}else{if(this instanceof W){return"ToolDataFeatureTrack"}else{if(this instanceof V){return"VcfTrack"}else{if(this instanceof e){return"FeatureTrack"}}}}}}}return""},init:function(){var ah=this;ah.enabled=false;ah.tile_cache.clear();ah.data_manager.clear();ah.initial_canvas=undefined;ah.content_div.css("height","auto");ah.container_div.removeClass("nodata error pending");if(!ah.dataset_id){return}$.getJSON(converted_datasets_state_url,{hda_ldda:ah.hda_ldda,dataset_id:ah.dataset_id,chrom:ah.view.chrom},function(ai){if(!ai||ai==="error"||ai.kind==="error"){ah.container_div.addClass("error");ah.content_div.text(p);if(ai.message){var aj=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+ai.message+"</pre>",{Close:hide_modal})});ah.content_div.append(aj)}}else{if(ai==="no converter"){ah.container_div.addClass("error");ah.content_div.text(L)}else{if(ai==="no data"||(ai.data!==undefined&&(ai.data===null||ai.data.length===0))){ah.container_div.addClass("nodata");ah.content_div.text(G)}else{if(ai==="pending"){ah.container_div.addClass("pending");ah.content_div.text(u);setTimeout(function(){ah.init()},ah.data_query_wait)}else{if(ai.status==="data"){if(ai.valid_chroms){ah.valid_chroms=ai.valid_chroms;ah.update_track_icons()}ah.content_div.text(aa);if(ah.view.chrom){ah.content_div.text("");ah.content_div.css("height",ah.height_px+"px");ah.enabled=true;$.when(ah.predraw_init()).done(function(){ah.container_div.removeClass("nodata error pending");ah.request_draw()})}}}}}}});this.update_track_icons()},predraw_init:function(){}});var O=function(ak,aj){var ai=this,ah=ai.view;n(ai.container_div,ai.drag_handle_class,".group",ai);this.filters_manager=new ac(this,(ak!==undefined?ak:{}));this.filters_available=false;this.filters_visible=false;this.tool=(aj!==undefined&&obj_length(aj)>0?new s(this,aj):undefined);if(this.header_div){if(this.filters_manager){this.filters_div=this.filters_manager.parent_div;this.header_div.after(this.filters_div)}if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}}};q(O.prototype,r.prototype,j.prototype,{copy:function(ah){return new this.constructor(this.name,this.view,ah,this.hda_ldda,this.dataset_id,this.prefs,this.filters,this.tool)},to_json:function(){return{track_type:this.get_type(),name:this.name,hda_ldda:this.hda_ldda,dataset_id:this.dataset_id,prefs:this.prefs,mode:this.mode,}},change_mode:function(ai){var ah=this;ah.mode_div.text(ai);ah.mode=ai;ah.config.values.mode=ai;ah.tile_cache.clear();ah.request_draw();return ah},update_track_icons:function(){var ah=this;if(ah.filters_available>0){ah.filters_icon.show()}else{ah.filters_icon.hide()}if(ah.tool){ah.tools_icon.show()}else{ah.tools_icon.hide()}},_gen_tile_cache_key:function(ai,aj,ah){return ai+"_"+aj+"_"+ah},request_draw:function(ai,ah){this.view.request_redraw(false,ai,ah,this)},_draw:function(aj,ar){if(!this.enabled){return}if(!(this instanceof B)&&(!this.dataset_id)){return}var aq=this.view.low,an=this.view.high,ao=an-aq,ak=this.view.container.width(),av=ak/ao,am=this.view.resolution,au=$("<div style='position: relative;'></div>");if(this.is_overview){aq=this.view.max_low;an=this.view.max_high;am=Math.pow(D,Math.ceil(Math.log((view.max_high-view.max_low)/S)/Math.log(D)));av=ak/(view.max_high-view.max_low)}if(!ar){this.content_div.children().remove()}this.content_div.append(au);this.max_height=0;var ai=Math.floor(aq/am/S);var ap=true;var at=[];var ah=0;while((ai*S*am)<an){tile=this.draw_helper(aj,ak,ai,am,au,av);if(tile){at.push(tile)}else{ap=false}ai+=1;ah++}var al=this;if(ap){al.postdraw_actions(at,ak,av,ar)}},postdraw_actions:function(al,am,an,ah){var aj=this;var ak=false;for(var ai=0;ai<al.length;ai++){if(al[ai].message){ak=true;break}}if(ak){for(var ai=0;ai<al.length;ai++){tile=al[ai];if(!tile.message){tile.canvas.css("padding-top",F)}}}},draw_helper:function(ai,aj,ak,an,au,ay,av,ao){var al=this,at=this._gen_tile_cache_key(aj,ay,ak),ap=ak*S*an,ax=ap+S*an;var aq=(ai?undefined:al.tile_cache.get(at));if(aq){al.show_tile(aq,au,ay);return aq}var ar=function(az){return("isResolved" in az)};var am=true;var ah=al.data_manager.get_data(ap,ax,al.mode,an,al.data_url_extra_params);if(ar(ah)){am=false}var aw;if(view.reference_track&&ay>view.canvas_manager.char_width_px){aw=view.reference_track.data_manager.get_data(ap,ax,al.mode,an,view.reference_track.data_url_extra_params);if(ar(aw)){am=false}}if(am){q(ah,ao);var aq=al.draw_tile(ah,al.mode,an,ak,ay,aw);if(aq!==undefined){al.tile_cache.set(at,aq);al.show_tile(aq,au,ay)}return aq}$.when(ah,aw).then(function(){view.request_redraw(false,false,false,al)});return null},show_tile:function(an,ap,aq){var aj=this,ai=an.canvas,am=ai;if(an.message){var ar=$("<div/>"),ao=$("<div/>").addClass("tile-message").text(an.message).css({height:F-1,width:an.canvas.width}).appendTo(ar),al=$("<a href='javascript:void(0);'/>").addClass("icon more-down").appendTo(ao),ah=$("<a href='javascript:void(0);'/>").addClass("icon more-across").appendTo(ao);ar.append(ai);am=ar;al.click(function(){an.stale=true;aj.data_manager.get_more_data(an.low,an.high,aj.mode,an.resolution,{},aj.data_manager.DEEP_DATA_REQ);aj.request_draw()}).dblclick(function(at){at.stopPropagation()});ah.click(function(){an.stale=true;aj.data_manager.get_more_data(an.low,an.high,aj.mode,an.resolution,{},aj.data_manager.BROAD_DATA_REQ);aj.request_draw()}).dblclick(function(at){at.stopPropagation()})}an.predisplay_actions();var ak=(an.low-(this.is_overview?this.view.max_low:this.view.low))*aq;if(this.left_offset){ak-=this.left_offset}am.css({position:"absolute",top:0,left:ak,height:""});ap.append(am);aj.max_height=Math.max(aj.max_height,am.height());aj.content_div.css("height",aj.max_height+"px");ap.children().css("height",aj.max_height+"px")},_get_tile_bounds:function(ah,ai){var ak=ah*S*ai,al=S*ai,aj=(ak+al<=this.view.max_high?ak+al:this.view.max_high);return[ak,aj]},tool_region_and_parameters_str:function(aj,ah,ak){var ai=this,al=(aj!==undefined&&ah!==undefined&&ak!==undefined?aj+":"+ah+"-"+ak:"all");return" - region=["+al+"], parameters=["+ai.tool.get_param_values().join(", ")+"]"}});var ad=function(ai,ah){j.call(this,"label",ai,ah,false,{});this.container_div.addClass("label-track")};q(ad.prototype,j.prototype,{init:function(){this.enabled=true},_draw:function(){var aj=this.view,ak=aj.high-aj.low,an=Math.floor(Math.pow(10,Math.floor(Math.log(ak)/Math.log(10)))),ah=Math.floor(aj.low/an)*an,al=this.view.container.width(),ai=$("<div style='position: relative; height: 1.3em;'></div>");while(ah<aj.high){var am=(ah-aj.low)/ak*al;ai.append($("<div class='label'>"+commatize(ah)+"</div>").css({position:"absolute",left:am-1}));ah+=an}this.content_div.children(":first").remove();this.content_div.append(ai)}});var B=function(ah){j.call(this,"reference",ah,{content_div:ah.top_labeltrack},false,{});O.call(this);ah.reference_track=this;this.left_offset=200;this.height_px=12;this.container_div.addClass("reference-track");this.content_div.css("background","none");this.content_div.css("min-height","0px");this.content_div.css("border","none");this.data_url=reference_url;this.data_url_extra_params={dbkey:ah.dbkey};this.data_manager=new J(C,this,false);this.tile_cache=new c(v)};q(B.prototype,r.prototype,O.prototype,{init:function(){this.enabled=true},draw_tile:function(ar,an,am,ai,at){var al=this,aj=S*am;if(at>this.view.canvas_manager.char_width_px){if(ar.data===null){al.content_div.css("height","0px");return}var ak=this.view.canvas_manager.new_canvas();var aq=ak.getContext("2d");ak.width=Math.ceil(aj*at+al.left_offset);ak.height=al.height_px;aq.font=aq.canvas.manager.default_font;aq.textAlign="center";ar=ar.data;for(var ao=0,ap=ar.length;ao<ap;ao++){var ah=Math.round(ao*at);aq.fillText(ar[ao],ah+al.left_offset,10)}return new b(al,ai,am,ak,ar)}this.content_div.css("height","0px")}});var k=function(am,ak,aj,an,ah,al){var ai=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";j.call(this,am,ak,aj,al);O.call(this);this.min_height_px=16;this.max_height_px=400;this.height_px=80;this.hda_ldda=an;this.dataset_id=ah;this.original_dataset_id=ah;this.data_manager=new T(C,this);this.tile_cache=new c(v);this.left_offset=0;this.config=new H({track:this,params:[{key:"name",label:"Name",type:"text",default_value:am},{key:"color",label:"Color",type:"color",default_value:get_random_color()},{key:"min_value",label:"Min Value",type:"float",default_value:undefined},{key:"max_value",label:"Max Value",type:"float",default_value:undefined},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.height_px,hidden:true}],saved_values:al,onchange:function(){ai.set_name(ai.prefs.name);ai.vertical_range=ai.prefs.max_value-ai.prefs.min_value;$("#linetrack_"+ai.dataset_id+"_minval").text(ai.prefs.min_value);$("#linetrack_"+ai.dataset_id+"_maxval").text(ai.prefs.max_value);ai.tile_cache.clear();ai.request_draw()}});this.prefs=this.config.values;this.height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value;this.add_resize_handle()};q(k.prototype,r.prototype,O.prototype,{add_resize_handle:function(){var ah=this;var ak=false;var aj=false;var ai=$("<div class='track-resize'>");$(ah.container_div).hover(function(){ak=true;ai.show()},function(){ak=false;if(!aj){ai.hide()}});ai.hide().bind("dragstart",function(al,am){aj=true;am.original_height=$(ah.content_div).height()}).bind("drag",function(am,an){var al=Math.min(Math.max(an.original_height+an.deltaY,ah.min_height_px),ah.max_height_px);$(ah.content_div).css("height",al);ah.height_px=al;ah.request_draw(true)}).bind("dragend",function(al,am){ah.tile_cache.clear();aj=false;if(!ak){ai.hide()}ah.config.values.height=ah.height_px}).appendTo(ah.container_div)},predraw_init:function(){var ah=this;ah.vertical_range=undefined;return $.getJSON(ah.data_url,{stats:true,chrom:ah.view.chrom,low:null,high:null,hda_ldda:ah.hda_ldda,dataset_id:ah.dataset_id},function(ai){ah.container_div.addClass("line-track");var ak=ai.data;if(isNaN(parseFloat(ah.prefs.min_value))||isNaN(parseFloat(ah.prefs.max_value))){ah.prefs.min_value=ak.min;ah.prefs.max_value=ak.max;$("#track_"+ah.dataset_id+"_minval").val(ah.prefs.min_value);$("#track_"+ah.dataset_id+"_maxval").val(ah.prefs.max_value)}ah.vertical_range=ah.prefs.max_value-ah.prefs.min_value;ah.total_frequency=ak.total_frequency;ah.container_div.find(".yaxislabel").remove();var al=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ah.dataset_id+"_minval").text(ab(ah.prefs.min_value,3));var aj=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ah.dataset_id+"_maxval").text(ab(ah.prefs.max_value,3));aj.css({position:"absolute",top:"24px",left:"10px"});aj.prependTo(ah.container_div);al.css({position:"absolute",bottom:"2px",left:"10px"});al.prependTo(ah.container_div)})},draw_tile:function(au,am,al,aj,at){if(this.vertical_range===undefined){return}var ah=this._get_tile_bounds(aj,al),an=ah[0],ar=ah[1],ai=Math.ceil((ar-an)*at),ap=this.height_px;var ak=this.view.canvas_manager.new_canvas();ak.width=ai,ak.height=ap;var aq=ak.getContext("2d");var ao=new N.LinePainter(au.data,an,ar,this.prefs,am);ao.draw(aq,ai,ap);return new b(this.track,aj,al,ak,au.data)}});var e=function(ah,an,ai,am,ap,ao,ak,al){var aj=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];j.call(this,ah,an,ai,true,ao);O.call(this,ak,al);this.config=new H({track:this,params:[{key:"name",label:"Name",type:"text",default_value:ah},{key:"block_color",label:"Block color",type:"color",default_value:get_random_color()},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:ao,onchange:function(){aj.set_name(aj.prefs.name);aj.tile_cache.clear();aj.request_draw()}});this.prefs=this.config.values;this.height_px=0;this.container_div.addClass("feature-track");this.hda_ldda=am;this.dataset_id=ap;this.original_dataset_id=ap;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.inc_slots={};this.start_end_dct={};this.tile_cache=new c(d);this.data_manager=new T(20,this);this.left_offset=200;this.painter=N.LinkedFeaturePainter};q(e.prototype,r.prototype,O.prototype,{postdraw_actions:function(ax,ah,ay,aw){O.prototype.postdraw_actions.call(this,ax,aw);var ak=this;if(aw){var am=ak.content_div.children();var an=false;for(var al=am.length-1,ar=0;al>=ar;al--){var aj=$(am[al]);if(an){aj.remove()}else{if(aj.children().length!==0){an=true}}}}if(ak.mode=="Histogram"){var aq=-1;for(var al=0;al<ax.length;al++){var av=ax[al].max_val;if(av>aq){aq=av}}for(var al=0;al<ax.length;al++){var au=ax[al];if(au.max_val!==aq){au.canvas.remove();ak.draw_helper(true,ah,au.index,au.resolution,au.canvas.parent(),ay,[],{max:aq})}}}if(ak.filters_manager){var ai=ak.filters_manager.filters;for(var ap=0;ap<ai.length;ap++){ai[ap].update_ui_elt()}var ao=false,at;for(var al=0;al<ax.length;al++){if(ax[al].data.length){at=ax[al].data[0];for(var ap=0;ap<ai.length;ap++){if(ai[ap].applies_to(at)){ao=true;break}}}}if(ak.filters_available!==ao){ak.filters_available=ao;if(!ak.filters_available){ak.filters_div.hide()}ak.update_track_icons()}}},update_auto_mode:function(ah){if(this.mode=="Auto"){if(ah=="no_detail"){ah="feature spans"}else{if(ah=="summary_tree"){ah="coverage histogram"}}this.mode_div.text("Auto ("+ah+")")}},incremental_slots:function(al,ai,ak){var aj=this.view.canvas_manager.dummy_context,ah=this.inc_slots[al];if(!ah||(ah.mode!==ak)){ah=new (t.FeatureSlotter)(al,ak==="Pack",A,function(am){return aj.measureText(am)});ah.mode=ak;this.inc_slots[al]=ah}return ah.slot_features(ai)},get_summary_tree_data:function(al,ao,aj,ax){if(ax>aj-ao){ax=aj-ao}var at=Math.floor((aj-ao)/ax),aw=[],ak=0;var am=0,an=0,ar,av=0,ap=[],au,aq;var ai=function(aA,az,aB,ay){aA[0]=az+aB*ay;aA[1]=az+(aB+1)*ay};while(av<ax&&am!==al.length){var ah=false;for(;av<ax&&!ah;av++){ai(ap,ao,av,at);for(an=am;an<al.length;an++){ar=al[an].slice(1,3);if(is_overlap(ar,ap)){ah=true;break}}if(ah){break}}data_start_index=an;aw[aw.length]=au=[ap[0],0];for(;an<al.length;an++){ar=al[an].slice(1,3);if(is_overlap(ar,ap)){au[1]++}else{break}}if(au[1]>ak){ak=au[1]}av++}return{max:ak,delta:at,data:aw}},draw_tile:function(aw,az,aD,aH,ar,ak){var aA=this,am=aA._get_tile_bounds(aH,aD),aK=am[0],ai=am[1],ay=ai-aK,aB=Math.ceil(ay*ar),aQ=25,al=this.left_offset,ax,an;if(az==="Auto"){if(aw.dataset_type==="summary_tree"){az=aw.dataset_type}else{if(aw.extra_info==="no_detail"||aA.is_overview){az="no_detail"}else{var aP=aw.data;if(this.view.high-this.view.low>K){az="Squish"}else{az="Pack"}}}this.update_auto_mode(az)}if(az==="summary_tree"||az==="Histogram"){an=this.summary_draw_height;this.container_div.find(".yaxislabel").remove();var ah=$("<div />").addClass("yaxislabel");ah.text(aw.max);ah.css({position:"absolute",top:"24px",left:"10px",color:this.prefs.label_color});ah.prependTo(this.container_div);var aj=this.view.canvas_manager.new_canvas();aj.width=aB+al;aj.height=an+U;if(aw.dataset_type!="summary_tree"){var at=this.get_summary_tree_data(aw.data,aK,ai,200);if(aw.max){at.max=aw.max}aw=at}var aM=new N.SummaryTreePainter(aw,aK,ai,this.prefs);var aC=aj.getContext("2d");aC.translate(al,U);aM.draw(aC,aB,an);return new l(aA,aH,aD,aj,aw.data,aw.max)}var ax,ap=1;if(az==="no_detail"||az==="Squish"||az==="Pack"){ap=this.incremental_slots(ar,aw.data,az);ax=this.inc_slots[ar].slots}var aq=[];if(aw.data){var au=this.filters_manager.filters;for(var aE=0,aG=aw.data.length;aE<aG;aE++){var ao=aw.data[aE];var aF=false;var av;for(var aJ=0,aO=au.length;aJ<aO;aJ++){av=au[aJ];av.update_attrs(ao);if(!av.keep(ao)){aF=true;break}}if(!aF){aq.push(ao)}}}var aN=(this.filters_manager.alpha_filter?new E(this.filters_manager.alpha_filter):null);var aL=(this.filters_manager.height_filter?new E(this.filters_manager.height_filter):null);var aM=new (this.painter)(aq,aK,ai,this.prefs,az,aN,aL,ak);var an=Math.max(af,aM.get_required_height(ap));var aj=this.view.canvas_manager.new_canvas();var aI=null;aj.width=aB+al;aj.height=an;var aC=aj.getContext("2d");aC.fillStyle=this.prefs.block_color;aC.font=aC.canvas.manager.default_font;aC.textAlign="right";this.container_div.find(".yaxislabel").remove();if(aw.data){aC.translate(al,0);aI=aM.draw(aC,aB,an,ax);aI.translation=-al}return new Q(aA,aH,aD,aj,aw.data,az,aw.message,aI)}});var V=function(al,aj,ai,an,ah,ak,am){e.call(this,al,aj,ai,an,ah,ak,am);this.painter=N.VariantPainter};q(V.prototype,r.prototype,O.prototype,e.prototype);var Y=function(al,aj,ai,an,ah,ak,am){e.call(this,al,aj,ai,an,ah,ak,am);this.config=new H({track:this,params:[{key:"name",label:"Name",type:"text",default_value:al},{key:"block_color",label:"Block color",type:"color",default_value:get_random_color()},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_insertions",label:"Show insertions",type:"bool",default_value:false},{key:"show_differences",label:"Show differences only",type:"bool",default_value:true},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:ak,onchange:function(){this.track.set_name(this.track.prefs.name);this.track.tile_cache.clear();this.track.request_draw()}});this.prefs=this.config.values;this.painter=N.ReadPainter;this.update_track_icons()};q(Y.prototype,r.prototype,O.prototype,e.prototype);var W=function(al,aj,ai,an,ah,ak,am){e.call(this,al,aj,ai,an,ah,ak,am,{});this.data_url=raw_data_url;this.data_query_wait=1000;this.dataset_check_url=dataset_state_url};q(W.prototype,r.prototype,O.prototype,e.prototype,{predraw_init:function(){var ai=this;var ah=function(){if(ai.data_manager.size()===0){setTimeout(ah,300)}else{ai.data_url=default_data_url;ai.data_query_wait=M;ai.dataset_state_url=converted_datasets_state_url;$.getJSON(ai.dataset_state_url,{dataset_id:ai.dataset_id,hda_ldda:ai.hda_ldda},function(aj){})}};ah()}});Z.View=ae;Z.DrawableGroup=R;Z.LineTrack=k;Z.FeatureTrack=e;Z.ReadTrack=Y};var slotting_module=function(c,b){var e=c("class").extend;var d=2,a=5;b.FeatureSlotter=function(j,h,f,g){this.slots={};this.start_end_dct={};this.w_scale=j;this.include_label=h;this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,s=this.slots,h=this.start_end_dct,y=[],A=[],n=0,z=this.max_rows;for(var w=0,x=m.length;w<x;w++){var l=m[w],o=l[0];if(s[o]!==undefined){n=Math.max(n,s[o]);A.push(s[o])}else{y.push(w)}}var q=function(G,H){for(var F=0;F<=z;F++){var D=false,I=h[F];if(I!==undefined){for(var C=0,E=I.length;C<E;C++){var B=I[C];if(H>B[0]&&G<B[1]){D=true;break}}}if(!D){return F}}return -1};for(var w=0,x=y.length;w<x;w++){var l=m[y[w]],o=l[0],u=l[1],f=l[2],r=l[3],g=Math.floor(u*p),k=Math.ceil(f*p),v=this.measureText(r).width,j;if(r!==undefined&&this.include_label){v+=(d+a);if(g-v>=0){g-=v;j="left"}else{k+=v;j="right"}}var t=q(g,k);if(t>=0){if(h[t]===undefined){h[t]=[]}h[t].push([g,k]);s[o]=t;n=Math.max(n,t)}else{}}return n+1}})};var painters_module=function(k,y){var v=k("class").extend;var q=function(J,B,H,A,G,E){if(E===undefined){E=4}var D=A-B;var C=G-H;var F=Math.floor(Math.sqrt(D*D+C*C)/E);var K=D/F;var I=C/F;var z;for(z=0;z<F;z++,B+=K,H+=I){if(z%2!==0){continue}J.fillRect(B,H,E,1)}};var r=function(B,A,z,E){var D=A-E/2,C=A+E/2,F=z-Math.sqrt(E*3/2);B.beginPath();B.moveTo(D,F);B.lineTo(C,F);B.lineTo(A,z);B.lineTo(D,F);B.strokeStyle=this.fillStyle;B.fill();B.stroke();B.closePath()};var e=function(z){this.default_val=(z?z:1)};e.prototype.gen_val=function(z){return this.default_val};var n=function(B,D,z,A,C){this.data=B;this.view_start=D;this.view_end=z;this.prefs=v({},this.default_prefs,A);this.mode=C};n.prototype.default_prefs={};var w=function(B,D,z,A,C){n.call(this,B,D,z,A,C)};w.prototype.default_prefs={show_counts:false};w.prototype.draw=function(M,z,L){var E=this.view_start,O=this.view_end-this.view_start,N=z/O;var J=this.data.data,I=this.data.delta,G=this.data.max,B=L;delta_x_px=Math.ceil(I*N);M.save();for(var C=0,D=J.length;C<D;C++){var H=Math.floor((J[C][0]-E)*N);var F=J[C][1];if(!F){continue}var K=F/G*L;if(F!==0&&K<1){K=1}M.fillStyle=this.prefs.block_color;M.fillRect(H,B-K,delta_x_px,K);var A=4;if(this.prefs.show_counts&&(M.measureText(F).width+A)<delta_x_px){M.fillStyle=this.prefs.label_color;M.textAlign="center";M.fillText(F,H+(delta_x_px/2),10)}}M.restore()};var c=function(z,D,F,G,B){n.call(this,z,D,F,G,B);if(this.prefs.min_value===undefined){var H=Infinity;for(var A=0,C=this.data.length;A<C;A++){H=Math.min(H,this.data[A][1])}this.prefs.min_value=H}if(this.prefs.max_value===undefined){var E=-Infinity;for(var A=0,C=this.data.length;A<C;A++){E=Math.max(E,this.data[A][1])}this.prefs.max_value=E}};c.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};c.prototype.draw=function(N,M,K){var F=false,H=this.prefs.min_value,D=this.prefs.max_value,J=D-H,z=K,A=this.view_start,L=this.view_end-this.view_start,B=M/L,I=this.mode,T=this.data;N.save();var U=Math.round(K+H/J*K);if(I!=="Intensity"){N.fillStyle="#aaa";N.fillRect(0,U,M,1)}N.beginPath();var R,E,C;if(T.length>1){C=Math.ceil((T[1][0]-T[0][0])*B)}else{C=10}for(var O=0,P=T.length;O<P;O++){N.fillStyle=this.prefs.color;R=Math.round((T[O][0]-A)*B);E=T[O][1];var Q=false,G=false;if(E===null){if(F&&I==="Filled"){N.lineTo(R,z)}F=false;continue}if(E<H){G=true;E=H}else{if(E>D){Q=true;E=D}}if(I==="Histogram"){E=Math.round(E/J*z);N.fillRect(R,U,C,-E)}else{if(I==="Intensity"){E=255-Math.floor((E-H)/J*255);N.fillStyle="rgb("+E+","+E+","+E+")";N.fillRect(R,0,C,z)}else{E=Math.round(z-(E-H)/J*z);if(F){N.lineTo(R,E)}else{F=true;if(I==="Filled"){N.moveTo(R,z);N.lineTo(R,E)}else{N.moveTo(R,E)}}}}N.fillStyle=this.prefs.overflow_color;if(Q||G){var S;if(I==="Histogram"||I==="Intensity"){S=C}else{R-=2;S=4}if(Q){N.fillRect(R,0,S,3)}if(G){N.fillRect(R,z-3,S,3)}}N.fillStyle=this.prefs.color}if(I==="Filled"){if(F){N.lineTo(R,U);N.lineTo(0,U)}N.fill()}else{N.stroke()}N.restore()};var o=function(z){this.feature_positions={};this.slot_height=z;this.translation=0};o.prototype.map_feature_data=function(A,C,z,B){if(!this.feature_positions[C]){this.feature_positions[C]=[]}this.feature_positions[C].push({data:A,x_start:z,x_end:B})};o.prototype.get_feature_data=function(z,D){var C=Math.floor(D/this.slot_height),B;if(!this.feature_positions[C]){return null}z+=this.translation;for(var A=0;A<this.feature_positions[C].length;A++){B=this.feature_positions[C][A];if(z>=B.x_start&&z<=B.x_end){return B.data}}};var p=function(B,E,z,A,D,F,C){n.call(this,B,E,z,A,D);this.alpha_scaler=(F?F:new e());this.height_scaler=(C?C:new e())};p.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};v(p.prototype,{get_required_height:function(A){var z=y_scale=this.get_row_height(),B=this.mode;if(B==="no_detail"||B==="Squish"||B==="Pack"){z=A*y_scale}return z+Math.max(Math.round(y_scale/2),5)},draw:function(L,J,H,G){var R=this.data,E=this.view_start,N=this.view_end;L.save();L.fillStyle=this.prefs.block_color;L.textAlign="right";var I=this.view_end-this.view_start,F=J/I,M=this.get_row_height(),Q=new o(M),C;for(var O=0,P=R.length;O<P;O++){var B=R[O],D=B[0],K=B[1],z=B[2],A=(G&&G[D]!==undefined?G[D]:null);if((K<N&&z>E)&&(this.mode=="Dense"||A!==null)){C=this.draw_element(L,this.mode,B,A,E,N,F,M,J);Q.map_feature_data(B,A,C[0],C[1])}}L.restore();return Q},draw_element:function(F,B,H,D,C,E,G,A,z){console.log("WARNING: Unimplemented function.");return[0,0]}});var d=10,j=3,m=5,x=10,g=1,t=3,f=3,a=9,l=2,h="#ccc";var s=function(B,E,z,A,D,F,C){p.call(this,B,E,z,A,D,F,C)};v(s.prototype,p.prototype,{get_row_height:function(){var A=this.mode,z;if(A==="Dense"){z=d}else{if(A==="no_detail"){z=j}else{if(A==="Squish"){z=m}else{z=x}}}return z},draw_element:function(N,E,W,I,P,ah,al,an,z){var T=W[0],aj=W[1],ab=W[2],R=W[3],ac=Math.floor(Math.max(0,(aj-P)*al)),O=Math.ceil(Math.min(z,Math.max(0,(ab-P)*al))),aa=ac,am=O,Z=(E==="Dense"?0:(0+I))*an,M,af,S=null,ap=null,C=this.prefs.block_color,ae=this.prefs.label_color;N.globalAlpha=this.alpha_scaler.gen_val(W);if(E=="Dense"){I=1}if(E==="no_detail"){N.fillStyle=C;N.fillRect(ac,Z+5,O-ac,g)}else{var L=W[4],Y=W[5],ad=W[6],D=W[7];if(Y&&ad){S=Math.floor(Math.max(0,(Y-P)*al));ap=Math.ceil(Math.min(z,Math.max(0,(ad-P)*al)))}var ak,U;if(E==="Squish"||E==="Dense"){ak=1;U=f}else{ak=5;U=a}if(!D){if(W.strand){if(W.strand==="+"){N.fillStyle=N.canvas.manager.get_pattern("right_strand_inv")}else{if(W.strand==="-"){N.fillStyle=N.canvas.manager.get_pattern("left_strand_inv")}}}else{N.fillStyle=C}N.fillRect(ac,Z,O-ac,U)}else{var K,V;if(E==="Squish"||E==="Dense"){N.fillStyle=h;K=Z+Math.floor(f/2)+1;V=1}else{if(L){var K=Z;var V=U;if(L==="+"){N.fillStyle=N.canvas.manager.get_pattern("right_strand")}else{if(L==="-"){N.fillStyle=N.canvas.manager.get_pattern("left_strand")}}}else{N.fillStyle=h;K+=(f/2)+1;V=1}}N.fillRect(ac,K,O-ac,V);var F;for(var ai=0,B=D.length;ai<B;ai++){var G=D[ai],A=Math.floor(Math.max(0,(G[0]-P)*al)),X=Math.ceil(Math.min(z,Math.max((G[1]-P)*al)));if(A>X){continue}N.fillStyle=C;N.fillRect(A,Z+(U-ak)/2+1,X-A,ak);if(S!==undefined&&ad>Y&&!(A>ap||X<S)){var ag=Math.max(A,S),J=Math.min(X,ap);N.fillRect(ag,Z+1,J-ag,U);if(D.length==1&&E=="Pack"){if(L==="+"){N.fillStyle=N.canvas.manager.get_pattern("right_strand_inv")}else{if(L==="-"){N.fillStyle=N.canvas.manager.get_pattern("left_strand_inv")}}if(ag+14<J){ag+=2;J-=2}N.fillRect(ag,Z+1,J-ag,U)}}}if(E==="Pack"){N.globalAlpha=1;N.fillStyle="white";var H=this.height_scaler.gen_val(W),Q=Math.ceil(U*H),ao=Math.round((U-Q)/2);if(H!==1){N.fillRect(ac,K+1,O-ac,ao);N.fillRect(ac,K+U-ao+1,O-ac,ao)}}}N.globalAlpha=1;if(E==="Pack"&&aj>P){N.fillStyle=ae;if(P===0&&ac-N.measureText(R).width<0){N.textAlign="left";N.fillText(R,O+l,Z+8);am+=N.measureText(R).width+l}else{N.textAlign="right";N.fillText(R,ac-l,Z+8);aa-=N.measureText(R).width+l}}}N.globalAlpha=1;return[aa,am]}});var b=function(B,E,z,A,D,F,C){p.call(this,B,E,z,A,D,F,C)};v(b.prototype,p.prototype,{draw_element:function(S,N,H,D,V,B,K,T,Q){var H=data[i],J=H[0],R=H[1],C=H[2],M=H[3],F=Math.floor(Math.max(0,(R-V)*K)),I=Math.ceil(Math.min(Q,Math.max(0,(C-V)*K))),E=(N==="Dense"?0:(0+D))*T,z,W,A=null,L=null;if(no_label){S.fillStyle=block_color;S.fillRect(F+left_offset,E+5,I-F,1)}else{var U=H[4],P=H[5],G=H[6];z=9;W=1;S.fillRect(F+left_offset,E,I-F,z);if(N!=="Dense"&&M!==undefined&&R>V){S.fillStyle=label_color;if(V===0&&F-S.measureText(M).width<0){S.textAlign="left";S.fillText(M,I+2+left_offset,E+8)}else{S.textAlign="right";S.fillText(M,F-2+left_offset,E+8)}S.fillStyle=block_color}var O=U+" / "+P;if(R>V&&S.measureText(O).width<(I-F)){S.fillStyle="white";S.textAlign="center";S.fillText(O,left_offset+F+(I-F)/2,E+8);S.fillStyle=block_color}}return[F,I]}});var u=function(C,F,z,B,E,G,D,A){p.call(this,C,F,z,B,E,G,D);this.ref_seq=(A?A.data:null)};u.prototype.default_prefs=v({},p.prototype.default_prefs,{show_insertions:false});v(u.prototype,p.prototype,{get_row_height:function(){var z,A=this.mode;if(A==="Dense"){z=d}else{if(A==="Squish"){z=m}else{z=x;if(this.prefs.show_insertions){z*=2}}}return z},draw_read:function(W,R,N,ab,C,V,K,H,G){W.textAlign="center";var U=this,B=[ab,C],Q=0,X=0,T=0,z=W.canvas.manager.char_width_px;var ag=[];if((R==="Pack"||this.mode==="Auto")&&H!==undefined&&N>z){T=Math.round(N/2)}if(!K){K=[[0,H.length]]}for(var O=0,Z=K.length;O<Z;O++){var L=K[O],D="MIDNSHP=X"[L[0]],P=L[1];if(D==="H"||D==="S"){Q-=P}var I=V+Q,af=Math.floor(Math.max(0,(I-ab)*N)),J=Math.floor(Math.max(0,(I+P-ab)*N));if(af===J){J+=1}switch(D){case"H":break;case"S":case"M":case"=":if(is_overlap([I,I+P],B)){var S=H.slice(X,X+P);if(T>0){W.fillStyle=this.prefs.block_color;W.fillRect(af-T,G+1,J-af,9);W.fillStyle=h;for(var ad=0,A=S.length;ad<A;ad++){if(this.prefs.show_differences&&this.ref_seq){var M=this.ref_seq[I-ab+ad];if(!M||M.toLowerCase()===S[ad].toLowerCase()){continue}}if(I+ad>=ab&&I+ad<=C){var ae=Math.floor(Math.max(0,(I+ad-ab)*N));W.fillText(S[ad],ae,G+9)}}}else{W.fillStyle=this.prefs.block_color;W.fillRect(af,G+4,J-af,f)}}X+=P;Q+=P;break;case"N":W.fillStyle=h;W.fillRect(af-T,G+5,J-af,1);Q+=P;break;case"D":W.fillStyle="red";W.fillRect(af-T,G+4,J-af,3);Q+=P;break;case"P":break;case"I":var aa=af-T;if(is_overlap([I,I+P],B)){var S=H.slice(X,X+P);if(this.prefs.show_insertions){var F=af-(J-af)/2;if((R==="Pack"||this.mode==="Auto")&&H!==undefined&&N>z){W.fillStyle="yellow";W.fillRect(F-T,G-9,J-af,9);ag[ag.length]={type:"triangle",data:[aa,G+4,5]};W.fillStyle=h;switch(seq_tile_overlap){case (OVERLAP_START):S=S.slice(ab-I);break;case (OVERLAP_END):S=S.slice(0,I-C);break;case (CONTAINED_BY):break;case (CONTAINS):S=S.slice(ab-I,I-C);break}for(var ad=0,A=S.length;ad<A;ad++){var ae=Math.floor(Math.max(0,(I+ad-ab)*N));W.fillText(S[ad],ae-(J-af)/2,G)}}else{W.fillStyle="yellow";W.fillRect(F,G+(this.mode!=="Dense"?2:5),J-af,(R!=="Dense"?f:t))}}else{if((R==="Pack"||this.mode==="Auto")&&H!==undefined&&N>z){ag[ag.length]={type:"text",data:[S.length,aa,G+9]}}else{}}}X+=P;break;case"X":X+=P;break}}W.fillStyle="yellow";var ac,E,ah;for(var Y=0;Y<ag.length;Y++){ac=ag[Y];E=ac.type;ah=ac.data;if(E==="text"){W.save();W.font="bold "+W.font;W.fillText(ah[0],ah[1],ah[2]);W.restore()}else{if(E=="triangle"){r(W,ah[0],ah[1],ah[2])}}}},draw_element:function(S,N,F,C,V,A,J,T,Q){var I=F[0],R=F[1],B=F[2],K=F[3],E=Math.floor(Math.max(0,(R-V)*J)),G=Math.ceil(Math.min(Q,Math.max(0,(B-V)*J))),D=(N==="Dense"?0:(0+C))*T,W=this.prefs.block_color,H=this.prefs.label_color,P=0;if((N==="Pack"||this.mode==="Auto")&&J>S.canvas.manager.char_width_px){var P=Math.round(J/2)}S.fillStyle=W;if(F[5] instanceof Array){var O=Math.floor(Math.max(0,(F[4][0]-V)*J)),M=Math.ceil(Math.min(Q,Math.max(0,(F[4][1]-V)*J))),L=Math.floor(Math.max(0,(F[5][0]-V)*J)),z=Math.ceil(Math.min(Q,Math.max(0,(F[5][1]-V)*J)));if(F[4][1]>=V&&F[4][0]<=A&&F[4][2]){this.draw_read(S,N,J,V,A,F[4][0],F[4][2],F[4][3],D)}if(F[5][1]>=V&&F[5][0]<=A&&F[5][2]){this.draw_read(S,N,J,V,A,F[5][0],F[5][2],F[5][3],D)}if(L>M){S.fillStyle=h;q(S,M-P,D+5,L-P,D+5)}}else{S.fillStyle=W;this.draw_read(S,N,J,V,A,R,F[4],F[5],D)}if(N==="Pack"&&R>V){S.fillStyle=this.prefs.label_color;var U=1;if(U===0&&E-S.measureText(K).width<0){S.textAlign="left";S.fillText(K,G+l-P,D+8)}else{S.textAlign="right";S.fillText(K,E-l-P,D+8)}S.fillStyle=W}return[0,0]}});y.Scaler=e;y.SummaryTreePainter=w;y.LinePainter=c;y.LinkedFeaturePainter=s;y.ReadPainter=u;y.VariantPainter=b};(function(d){var c={};var b=function(e){return c[e]};var a=function(f,g){var e={};g(b,e);c[f]=e};a("class",class_module);a("slotting",slotting_module);a("painters",painters_module);a("trackster",trackster_module);for(key in c.trackster){d[key]=c.trackster[key]}})(window); \ No newline at end of file +var class_module=function(b,a){var c=function(){var f=arguments[0];for(var e=1;e<arguments.length;e++){var d=arguments[e];for(key in d){f[key]=d[key]}}return f};a.extend=c};var requestAnimationFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b,a){window.setTimeout(b,1000/60)}})();var BEFORE=1001,CONTAINS=1002,OVERLAP_START=1003,OVERLAP_END=1004,CONTAINED_BY=1005,AFTER=1006;var compute_overlap=function(e,b){var g=e[0],f=e[1],d=b[0],c=b[1],a;if(g<d){if(f<d){a=BEFORE}else{if(f<=c){a=OVERLAP_START}else{a=CONTAINS}}}else{if(g>c){a=AFTER}else{if(f<=c){a=CONTAINED_BY}else{a=OVERLAP_END}}}return a};var is_overlap=function(c,b){var a=compute_overlap(c,b);return(a!==BEFORE&&a!==AFTER)};var get_random_color=function(a){if(!a){a="#ffffff"}if(typeof(a)==="string"){a=[a]}for(var j=0;j<a.length;j++){a[j]=parseInt(a[j].slice(1),16)}var m=function(t,s,i){return((t*299)+(s*587)+(i*114))/1000};var e=function(u,t,v,r,i,s){return(Math.max(u,r)-Math.min(u,r))+(Math.max(t,i)-Math.min(t,i))+(Math.max(v,s)-Math.min(v,s))};var g,n,f,k,p,h,q,c,d,b,o,l=false;do{g=Math.random()*16777215;n=g|16711680;f=g|65280;k=g|255;d=m(n,f,k);l=true;for(var j=0;j<a.length;j++){p=a[j];h=p|16711680;q=p|65280;c=p|255;b=m(h,q,c);o=e(n,f,k,h,q,c);if((Math.abs(d-b)<125)||(o<500)){l=false;break}}}while(!l);return"#"+(16777216+g).toString(16).substr(1,6)};var trackster_module=function(f,Y){var p=f("class").extend,s=f("slotting"),M=f("painters");var af=function(ag,ah){this.document=ag;this.default_font=ah!==undefined?ah:"9px Monaco, Lucida Console, monospace";this.dummy_canvas=this.new_canvas();this.dummy_context=this.dummy_canvas.getContext("2d");this.dummy_context.font=this.default_font;this.char_width_px=this.dummy_context.measureText("A").width;this.patterns={};this.load_pattern("right_strand","/visualization/strand_right.png");this.load_pattern("left_strand","/visualization/strand_left.png");this.load_pattern("right_strand_inv","/visualization/strand_right_inv.png");this.load_pattern("left_strand_inv","/visualization/strand_left_inv.png")};p(af.prototype,{load_pattern:function(ag,ak){var ah=this.patterns,ai=this.dummy_context,aj=new Image();aj.src=image_path+ak;aj.onload=function(){ah[ag]=ai.createPattern(aj,"repeat")}},get_pattern:function(ag){return this.patterns[ag]},new_canvas:function(){var ag=this.document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(ag)}ag.manager=this;return ag}});var n={};var l=function(ag,ah){n[ag.attr("id")]=ah};var m=function(ag,ai,ak,aj){ak=".group";var ah={};n[ag.attr("id")]=aj;ag.bind("drag",{handle:"."+ai,relative:true},function(at,au){var ar=$(this);var ax=$(this).parent(),ao=ax.children(),aq=n[$(this).attr("id")],an,am,av,al,ap;am=$(this).parents(ak);if(am.length!==0){av=am.position().top;al=av+am.outerHeight();if(au.offsetY<av){$(this).insertBefore(am);var aw=n[am.attr("id")];aw.remove_drawable(aq);aw.container.add_drawable_before(aq,aw);return}else{if(au.offsetY>al){$(this).insertAfter(am);var aw=n[am.attr("id")];aw.remove_drawable(aq);aw.container.add_drawable(aq);return}}}am=null;for(ap=0;ap<ao.length;ap++){an=$(ao.get(ap));av=an.position().top;al=av+an.outerHeight();if(an.is(ak)&&this!==an.get(0)&&au.offsetY>=av&&au.offsetY<=al){if(au.offsetY-av<al-au.offsetY){an.find(".content-div").prepend(this)}else{an.find(".content-div").append(this)}if(aq.container){aq.container.remove_drawable(aq)}n[an.attr("id")].add_drawable(aq);return}}for(ap=0;ap<ao.length;ap++){if(au.offsetY<$(ao.get(ap)).position().top){break}}if(ap===ao.length){if(this!==ao.get(ap-1)){ax.append(this);n[ax.attr("id")].move_drawable(aq,ap)}}else{if(this!==ao.get(ap)){$(this).insertBefore(ao.get(ap));n[ax.attr("id")].move_drawable(aq,(au.deltaY>0?ap-1:ap))}}}).bind("dragstart",function(){ah["border-top"]=ag.css("border-top");ah["border-bottom"]=ag.css("border-bottom");$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css(ah)})};Y.moveable=m;var ae=16,H=9,E=20,T=H+2,z=100,J=12000,R=200,C=5,v=10,L=5000,w=100,o="There was an error in indexing this dataset. ",K="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",F="No data for this chrom/contig.",t="Currently indexing... please wait",x="Tool cannot be rerun: ",a="Loading data...",Z="Ready for display",d=10,u=5,B=5;function aa(ah,ag){if(!ag){ag=0}var ai=Math.pow(10,ag);return Math.round(ah*ai)/ai}var c=function(ag){this.num_elements=ag;this.clear()};p(c.prototype,{get:function(ah){var ag=this.key_ary.indexOf(ah);if(ag!==-1){if(this.obj_cache[ah].stale){this.key_ary.splice(ag,1);delete this.obj_cache[ah]}else{this.move_key_to_end(ah,ag)}}return this.obj_cache[ah]},set:function(ah,ai){if(!this.obj_cache[ah]){if(this.key_ary.length>=this.num_elements){var ag=this.key_ary.shift();delete this.obj_cache[ag]}this.key_ary.push(ah)}this.obj_cache[ah]=ai;return ai},move_key_to_end:function(ah,ag){this.key_ary.splice(ag,1);this.key_ary.push(ah)},clear:function(){this.obj_cache={};this.key_ary=[]},size:function(){return this.key_ary.length}});var S=function(ah,ag,ai){c.call(this,ah);this.track=ag;this.subset=(ai!==undefined?ai:true)};p(S.prototype,c.prototype,{load_data:function(ap,ak,an,ah,am){var ao=this.track.view.chrom,aj={chrom:ao,low:ap,high:ak,mode:an,resolution:ah,dataset_id:this.track.dataset_id,hda_ldda:this.track.hda_ldda};$.extend(aj,am);if(this.track.filters_manager){var aq=[];var ag=this.track.filters_manager.filters;for(var al=0;al<ag.length;al++){aq[aq.length]=ag[al].name}aj.filter_cols=JSON.stringify(aq)}var ai=this;return $.getJSON(this.track.data_url,aj,function(ar){ai.set_data(ap,ak,an,ar)})},get_data:function(ag,ak,al,ah,aj){var ai=this.get_data_from_cache(ag,ak,al);if(ai){return ai}ai=this.load_data(ag,ak,al,ah,aj);this.set_data(ag,ak,al,ai);return ai},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(ao,aj,an,ai,am,ak){var ap=this.get_data_from_cache(ao,aj,an);if(!ap){console.log("ERROR: no current data for: ",this.track,ao,aj,an,ai,am);return}ap.stale=true;var ah=ao;if(ak===this.DEEP_DATA_REQ){$.extend(am,{start_val:ap.data.length+1})}else{if(ak===this.BROAD_DATA_REQ){ah=(ap.max_high?ap.max_high:ap.data[ap.data.length-1][2])+1}}var ag=this,al=this.load_data(ah,aj,an,ai,am);new_data_available=$.Deferred();this.set_data(ao,aj,an,new_data_available);$.when(al).then(function(aq){if(aq.data){aq.data=ap.data.concat(aq.data);if(aq.max_low){aq.max_low=ap.max_low}if(aq.message){aq.message=aq.message.replace(/[0-9]+/,aq.data.length)}}ag.set_data(ao,aj,an,aq);new_data_available.resolve(aq)});return new_data_available},get_data_from_cache:function(ag,ah,ai){return this.get(this.gen_key(ag,ah,ai))},set_data:function(ah,ai,aj,ag){return this.set(this.gen_key(ah,ai,aj),ag)},gen_key:function(ag,ai,aj){var ah=ag+"_"+ai+"_"+aj;return ah},split_key:function(ag){return ag.split("_")}});var I=function(ah,ag,ai){S.call(this,ah,ag,ai)};p(I.prototype,S.prototype,c.prototype,{load_data:function(ag,aj,ak,ah,ai){if(ah>1){return{data:null}}return S.prototype.load_data.call(this,ag,aj,ak,ah,ai)}});var q=function(aj,ah,ag,ai,ak){this.name=aj;this.view=ah;this.container=ag;this.config=new G({track:this,params:[{key:"name",label:"Name",type:"text",default_value:aj}],saved_values:ai,onchange:function(){this.track.set_name(this.track.config.values.name)}});this.prefs=this.config.values;this.drag_handle_class=ak;this.is_overview=false};p(q.prototype,{init:function(){},request_draw:function(){},_draw:function(){},to_json:function(){},update_track_icons:function(){},set_name:function(ag){this.old_name=this.name;this.name=ag;this.name_div.text(this.name)},revert_name:function(){this.name=this.old_name;this.name_div.text(this.name)},remove:function(){this.container.remove_drawable(this);this.container_div.fadeOut("slow",function(){$(this).remove();view.update_intro_div();view.has_changes=true})}});var y=function(ak,aj,ah,ag,ai,al){q.call(this,aj,ah,ag,ai,al);this.obj_type=ak;this.drawables=[]};p(y.prototype,q.prototype,{init:function(){for(var ag=0;ag<this.drawables.length;ag++){this.drawables[ag].init()}},_draw:function(){for(var ag=0;ag<this.drawables.length;ag++){this.drawables[ag]._draw()}},to_json:function(){var ah=[];for(var ag=0;ag<this.drawables.length;ag++){ah.push(this.drawables[ag].to_json())}return{name:this.name,prefs:this.prefs,obj_type:this.obj_type,drawables:ah}},add_drawable:function(ag){this.drawables.push(ag);ag.container=this},add_drawable_before:function(ai,ag){var ah=this.drawables.indexOf(ag);if(ah!=-1){this.drawables.splice(ah,0,ai);return true}return false},remove_drawable:function(ah){var ag=this.drawables.indexOf(ah);if(ag!=-1){this.drawables.splice(ag,1);ah.container=null;return true}return false},move_drawable:function(ah,ai){var ag=this.drawables.indexOf(ah);if(ag!=-1){this.drawables.splice(ag,1);this.drawables.splice(ai,0,ah);return true}return false}});var Q=function(aj,ah,ag,ai){y.call(this,"DrawableGroup",aj,ah,ag,ai,"group-handle");if(!Q.id_counter){Q.id_counter=0}var ak=Q.id_counter++;this.container_div=$("<div/>").addClass("group").attr("id","group_"+ak).appendTo(this.container.content_div);this.header_div=$("<div/>").addClass("track-header").appendTo(this.container_div);this.header_div.append($("<div/>").addClass(this.drag_handle_class));this.name_div=$("<div/>").addClass("group-name menubutton popup").text(this.name).appendTo(this.header_div);this.content_div=$("<div/>").addClass("content-div").attr("id","group_"+ak+"_content_div").appendTo(this.container_div);l(this.container_div,this);l(this.content_div,this);m(this.container_div,this.drag_handle_class,".group",this);this.update_track_icons()};p(Q.prototype,q.prototype,y.prototype,{update_track_icons:function(){var ah=this;var ag={};ag["Edit configuration"]=function(){var ak=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},ai=function(){ah.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},aj=function(al){if((al.keyCode||al.which)===27){ak()}else{if((al.keyCode||al.which)===13){ai()}}};$(window).bind("keypress.check_enter_esc",aj);show_modal("Configure Group",ah.config.build_form(),{Cancel:ak,OK:ai})};ag.Remove=function(){ah.remove()};make_popupmenu(ah.name_div,ag)}});var ad=function(ag,aj,ai,ah){y.call(this,"View");this.container=ag;this.chrom=null;this.vis_id=ai;this.dbkey=ah;this.title=aj;this.label_tracks=[];this.tracks_to_be_redrawn=[];this.max_low=0;this.max_high=0;this.zoom_factor=3;this.min_separation=30;this.has_changes=false;this.load_chroms_deferred=null;this.init();this.canvas_manager=new af(ag.get(0).ownerDocument);this.reset()};p(ad.prototype,y.prototype,{init:function(){var ai=this.container,ag=this;this.top_container=$("<div/>").addClass("top-container").appendTo(ai);this.browser_content_div=$("<div/>").addClass("content").css("position","relative").appendTo(ai);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(ai);this.top_labeltrack=$("<div/>").addClass("top-labeltrack").appendTo(this.top_container);this.viewport_container=$("<div/>").addClass("viewport-container").attr("id","viewport-container").appendTo(this.browser_content_div);this.content_div=this.viewport_container;l(this.viewport_container,ag);this.intro_div=$("<div/>").addClass("intro");var aj=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_tracks()});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("nav").appendTo(this.nav_container);this.overview=$("<div/>").addClass("overview").appendTo(this.bottom_container);this.overview_viewport=$("<div/>").addClass("overview-viewport").appendTo(this.overview);this.overview_close=$("<a/>").attr("href","javascript:void(0);").attr("title","Close overview").addClass("icon-button overview-close tooltip").hide().appendTo(this.overview_viewport);this.overview_highlight=$("<div/>").addClass("overview-highlight").hide().appendTo(this.overview_viewport);this.overview_box_background=$("<div/>").addClass("overview-boxback").appendTo(this.overview_viewport);this.overview_box=$("<div/>").addClass("overview-box").appendTo(this.overview_viewport);this.default_overview_height=this.overview_box.height();this.nav_controls=$("<div/>").addClass("nav-controls").appendTo(this.nav);this.chrom_select=$("<select/>").attr({name:"chrom"}).css("width","15em").addClass("no-autocomplete").append("<option value=''>Loading</option>").appendTo(this.nav_controls);var ah=function(ak){if(ak.type==="focusout"||(ak.keyCode||ak.which)===13||(ak.keyCode||ak.which)===27){if((ak.keyCode||ak.which)!==27){ag.go_to($(this).val())}$(this).hide();$(this).val("");ag.location_span.show();ag.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",ah).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").appendTo(this.nav_controls);this.location_span.click(function(){ag.location_span.hide();ag.chrom_select.hide();ag.nav_input.val(ag.chrom+":"+ag.low+"-"+ag.high);ag.nav_input.css("display","inline-block");ag.nav_input.select();ag.nav_input.focus()});if(this.vis_id!==undefined){this.hidden_input=$("<input/>").attr("type","hidden").val(this.vis_id).appendTo(this.nav_controls)}this.zo_link=$("<a id='zoom-out' />").click(function(){ag.zoom_out();ag.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a id='zoom-in' />").click(function(){ag.zoom_in();ag.request_redraw()}).appendTo(this.nav_controls);this.load_chroms_deferred=this.load_chroms({low:0});this.chrom_select.bind("change",function(){ag.change_chrom(ag.chrom_select.val())});this.browser_content_div.click(function(ak){$(this).find("input").trigger("blur")});this.browser_content_div.bind("dblclick",function(ak){ag.zoom_in(ak.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(ak,al){this.current_x=al.offsetX}).bind("drag",function(ak,am){var an=am.offsetX-this.current_x;this.current_x=am.offsetX;var al=Math.round(an/ag.viewport_container.width()*(ag.max_high-ag.max_low));ag.move_delta(-al)});this.overview_close.click(function(){ag.reset_overview()});this.viewport_container.bind("draginit",function(ak,al){if(ak.clientX>ag.viewport_container.width()-16){return false}}).bind("dragstart",function(ak,al){al.original_low=ag.low;al.current_height=ak.clientY;al.current_x=al.offsetX}).bind("drag",function(am,ao){var ak=$(this);var ap=ao.offsetX-ao.current_x;var al=ak.scrollTop()-(am.clientY-ao.current_height);ak.scrollTop(al);ao.current_height=am.clientY;ao.current_x=ao.offsetX;var an=Math.round(ap/ag.viewport_container.width()*(ag.high-ag.low));ag.move_delta(an)}).bind("mousewheel",function(am,ao,al,ak){if(al){var an=Math.round(-al/ag.viewport_container.width()*(ag.high-ag.low));ag.move_delta(an)}});this.top_labeltrack.bind("dragstart",function(ak,al){return $("<div />").css({height:ag.browser_content_div.height()+ag.top_labeltrack.height()+ag.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(ao,ap){$(ap.proxy).css({left:Math.min(ao.pageX,ap.startX),width:Math.abs(ao.pageX-ap.startX)});var al=Math.min(ao.pageX,ap.startX)-ag.container.offset().left,ak=Math.max(ao.pageX,ap.startX)-ag.container.offset().left,an=(ag.high-ag.low),am=ag.viewport_container.width();ag.update_location(Math.round(al/am*an)+ag.low,Math.round(ak/am*an)+ag.low)}).bind("dragend",function(ap,aq){var al=Math.min(ap.pageX,aq.startX),ak=Math.max(ap.pageX,aq.startX),an=(ag.high-ag.low),am=ag.viewport_container.width(),ao=ag.low;ag.low=Math.round(al/am*an)+ao;ag.high=Math.round(ak/am*an)+ao;$(aq.proxy).remove();ag.request_redraw()});this.add_label_track(new ac(this,{content_div:this.top_labeltrack}));this.add_label_track(new ac(this,{content_div:this.nav_labeltrack}));$(window).bind("resize",function(){ag.resize_window()});$(document).bind("redraw",function(){ag.redraw()});this.reset();$(window).trigger("resize");this.update_intro_div()},update_intro_div:function(){if(this.num_tracks===0){this.intro_div.appendTo(this.viewport_container)}else{this.intro_div.remove()}},update_location:function(ag,ah){this.location_span.text(commatize(ag)+" - "+commatize(ah));this.nav_input.val(this.chrom+":"+commatize(ag)+"-"+commatize(ah))},load_chroms:function(ai){ai.num=w;$.extend(ai,(this.vis_id!==undefined?{vis_id:this.vis_id}:{dbkey:this.dbkey}));var ag=this,ah=$.Deferred();$.ajax({url:chrom_url,data:ai,dataType:"json",success:function(ak){if(ak.chrom_info.length===0){alert("Invalid chromosome: "+ai.chrom);return}if(ak.reference){ag.add_label_track(new A(ag))}ag.chrom_data=ak.chrom_info;var an='<option value="">Select Chrom/Contig</option>';for(var am=0,aj=ag.chrom_data.length;am<aj;am++){var al=ag.chrom_data[am].chrom;an+='<option value="'+al+'">'+al+"</option>"}if(ak.prev_chroms){an+='<option value="previous">Previous '+w+"</option>"}if(ak.next_chroms){an+='<option value="next">Next '+w+"</option>"}ag.chrom_select.html(an);ag.chrom_start_index=ak.start_index;ah.resolve(ak)},error:function(){alert("Could not load chroms for this dbkey:",ag.dbkey)}});return ah},change_chrom:function(al,ah,an){if(!al||al==="None"){return}var ai=this;if(al==="previous"){ai.load_chroms({low:this.chrom_start_index-w});return}if(al==="next"){ai.load_chroms({low:this.chrom_start_index+w});return}var am=$.grep(ai.chrom_data,function(ao,ap){return ao.chrom===al})[0];if(am===undefined){ai.load_chroms({chrom:al},function(){ai.change_chrom(al,ah,an)});return}else{if(al!==ai.chrom){ai.chrom=al;ai.chrom_select.val(ai.chrom);ai.max_high=am.len-1;ai.reset();ai.request_redraw(true);for(var ak=0,ag=ai.drawables.length;ak<ag;ak++){var aj=ai.drawables[ak];if(aj.init){aj.init()}}}if(ah!==undefined&&an!==undefined){ai.low=Math.max(ah,0);ai.high=Math.min(an,ai.max_high)}ai.reset_overview();ai.request_redraw()}},go_to:function(ak){ak=ak.replace(/ |,/g,"");var ao=this,ag,aj,ah=ak.split(":"),am=ah[0],an=ah[1];if(an!==undefined){try{var al=an.split("-");ag=parseInt(al[0],10);aj=parseInt(al[1],10)}catch(ai){return false}}ao.change_chrom(am,ag,aj)},move_fraction:function(ai){var ag=this;var ah=ag.high-ag.low;this.move_delta(ai*ah)},move_delta:function(ai){var ag=this;var ah=ag.high-ag.low;if(ag.low-ai<ag.max_low){ag.low=ag.max_low;ag.high=ag.max_low+ah}else{if(ag.high-ai>ag.max_high){ag.high=ag.max_high;ag.low=ag.max_high-ah}else{ag.high-=ai;ag.low-=ai}}ag.request_redraw()},add_drawable:function(ag){y.prototype.add_drawable.call(this,ag);ag.init();this.has_changes=true;this.update_intro_div()},add_label_track:function(ag){ag.view=this;ag.init();this.label_tracks.push(ag)},remove_drawable:function(ai,ah){y.prototype.remove_drawable.call(this,ai);if(ah){var ag=this;ai.container_div.fadeOut("slow",function(){$(this).remove();ag.update_intro_div()});this.has_changes=true}},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(ao,ag,an,ah){var am=this,ak=(ah?[ah]:am.drawables),ai;var ah;for(var al=0;al<ak.length;al++){ah=ak[al];ai=-1;for(var aj=0;aj<am.tracks_to_be_redrawn.length;aj++){if(am.tracks_to_be_redrawn[aj][0]===ah){ai=aj;break}}if(ai<0){am.tracks_to_be_redrawn.push([ah,ag,an])}else{am.tracks_to_be_redrawn[al][1]=ag;am.tracks_to_be_redrawn[al][2]=an}}requestAnimationFrame(function(){am._redraw(ao)})},_redraw:function(aq){var an=this.low,aj=this.high;if(an<this.max_low){an=this.max_low}if(aj>this.max_high){aj=this.max_high}var ap=this.high-this.low;if(this.high!==0&&ap<this.min_separation){aj=an+this.min_separation}this.low=Math.floor(an);this.high=Math.ceil(aj);this.resolution=Math.pow(C,Math.ceil(Math.log((this.high-this.low)/R)/Math.log(C)));this.zoom_res=Math.pow(v,Math.max(0,Math.ceil(Math.log(this.resolution,v)/Math.log(v))));var ag=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var am=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ar=13;this.overview_box.css({left:ag,width:Math.max(ar,am)}).show();if(am<ar){this.overview_box.css("left",ag-(ar-am)/2)}if(this.overview_highlight){this.overview_highlight.css({left:ag,width:am})}this.update_location(this.low,this.high);if(!aq){var ai,ah,ao;for(var ak=0,al=this.tracks_to_be_redrawn.length;ak<al;ak++){ai=this.tracks_to_be_redrawn[ak][0];ah=this.tracks_to_be_redrawn[ak][1];ao=this.tracks_to_be_redrawn[ak][2];if(ai){ai._draw(ah,ao)}}this.tracks_to_be_redrawn=[];for(ak=0,al=this.label_tracks.length;ak<al;ak++){this.label_tracks[ak]._draw()}}},zoom_in:function(ah,ai){if(this.max_high===0||this.high-this.low<this.min_separation){return}var aj=this.high-this.low,ak=aj/2+this.low,ag=(aj/this.zoom_factor)/2;if(ah){ak=ah/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(ak-ag);this.high=Math.round(ak+ag);this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var ah=this.high-this.low,ai=ah/2+this.low,ag=(ah*this.zoom_factor)/2;this.low=Math.round(ai-ag);this.high=Math.round(ai+ag);this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.nav_container.width(this.container.width());this.request_redraw()},set_overview:function(ai){if(this.overview_drawable){if(this.overview_drawable.dataset_id===ai.dataset_id){return}this.overview_viewport.find(".track").remove()}var ah=ai.copy({content_div:this.overview_viewport}),ag=this;ah.header_div.hide();ah.is_overview=true;ag.overview_drawable=ah;this.overview_drawable.postdraw_actions=function(){ag.overview_highlight.show().height(ag.overview_drawable.content_div.height());ag.overview_viewport.height(ag.overview_drawable.content_div.height()+ag.overview_box.outerHeight());ag.overview_close.show();ag.resize_window()};this.overview_drawable.init();ag.has_changes=true},reset_overview:function(){$(".tipsy").remove();this.overview_viewport.find(".track-tile").remove();this.overview_viewport.height(this.default_overview_height);this.overview_box.height(this.default_overview_height);this.overview_close.hide();this.overview_highlight.hide();view.resize_window();view.overview_drawable=null}});var r=function(ai,am){this.track=ai;this.name=am.name;this.params=[];var au=am.params;for(var aj=0;aj<au.length;aj++){var ao=au[aj],ah=ao.name,at=ao.label,ak=unescape(ao.html),av=ao.value,aq=ao.type;if(aq==="number"){this.params[this.params.length]=new g(ah,at,ak,av,ao.min,ao.max)}else{if(aq=="select"){this.params[this.params.length]=new O(ah,at,ak,av)}else{console.log("WARNING: unrecognized tool parameter type:",ah,aq)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(ax){ax.stopPropagation()}).click(function(ax){ax.stopPropagation()}).bind("dblclick",function(ax){ax.stopPropagation()});var ar=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var ap=this.params;var an=this;$.each(this.params,function(ay,aB){var aA=$("<div>").addClass("param-row").appendTo(an.parent_div);var ax=$("<div>").addClass("param-label").text(aB.label).appendTo(aA);var az=$("<div/>").addClass("slider").html(aB.html).appendTo(aA);az.find(":input").val(aB.value);$("<div style='clear: both;'/>").appendTo(aA)});this.parent_div.find("input").click(function(){$(this).select()});var aw=$("<div>").addClass("param-row").appendTo(this.parent_div);var al=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(aw);var ag=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(aw);var an=this;ag.click(function(){an.run_on_region()});al.click(function(){an.run_on_dataset()})};p(r.prototype,{get_param_values_dict:function(){var ag={};this.parent_div.find(":input").each(function(){var ah=$(this).attr("name"),ai=$(this).val();ag[ah]=JSON.stringify(ai)});return ag},get_param_values:function(){var ah=[];var ag={};this.parent_div.find(":input").each(function(){var ai=$(this).attr("name"),aj=$(this).val();if(ai){ah[ah.length]=aj}});return ah},run_on_dataset:function(){var ag=this;ag.run({dataset_id:this.track.original_dataset_id,tool_id:ag.name},null,function(ah){show_modal(ag.name+" is Running",ag.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var ah={dataset_id:this.track.original_dataset_id,chrom:this.track.view.chrom,low:this.track.view.low,high:this.track.view.high,tool_id:this.name},ak=this.track,ai=ah.tool_id+ak.tool_region_and_parameters_str(ah.chrom,ah.low,ah.high),ag,al;if(ak.container===view){var aj=new Q(this.name,this.track.view,this.track.container);ak.container.add_drawable(aj);ak.container.remove_drawable(ak);aj.add_drawable(ak);ak.container_div.appendTo(aj.content_div);ag=aj}else{ag=ak.container}if(ak instanceof e){al=new V(ai,view,ag,"hda");al.change_mode(ak.mode);ag.add_drawable(al)}al.content_div.text("Starting job.");this.run(ah,al,function(am){al.dataset_id=am.dataset_id;al.content_div.text("Running job.");al.init()})},run:function(ah,ai,aj){$.extend(ah,this.get_param_values_dict());var ag=function(){$.getJSON(rerun_tool_url,ah,function(ak){if(ak==="no converter"){ai.container_div.addClass("error");ai.content_div.text(K)}else{if(ak.error){ai.container_div.addClass("error");ai.content_div.text(x+ak.message)}else{if(ak==="pending"){ai.container_div.addClass("pending");ai.content_div.text("Converting input data so that it can be used quickly with tool.");setTimeout(ag,2000)}else{aj(ak)}}}})};ag()}});var O=function(ah,ag,ai,aj){this.name=ah;this.label=ag;this.html=ai;this.value=aj};var g=function(ai,ah,ak,al,aj,ag){O.call(this,ai,ah,ak,al);this.min=aj;this.max=ag};var h=function(ah,ag,ai,aj){this.name=ah;this.index=ag;this.tool_id=ai;this.tool_exp_name=aj};var W=function(ah,ag,ai,aj){h.call(this,ah,ag,ai,aj);this.low=-Number.MAX_VALUE;this.high=Number.MAX_VALUE;this.min=Number.MAX_VALUE;this.max=-Number.MAX_VALUE;this.container=null;this.slider=null;this.slider_label=null};p(W.prototype,{applies_to:function(ag){if(ag.length>this.index){return true}return false},keep:function(ag){if(!this.applies_to(ag)){return true}var ah=ag[this.index];return(isNaN(ah)||(ah>=this.low&&ah<=this.high))},update_attrs:function(ah){var ag=false;if(!this.applies_to(ah)){return ag}if(ah[this.index]<this.min){this.min=Math.floor(ah[this.index]);ag=true}if(ah[this.index]>this.max){this.max=Math.ceil(ah[this.index]);ag=true}return ag},update_ui_elt:function(){if(this.min!=this.max){this.container.show()}else{this.container.hide()}var ai=function(al,aj){var ak=aj-al;return(ak<=2?0.01:1)};var ah=this.slider.slider("option","min"),ag=this.slider.slider("option","max");if(this.min<ah||this.max>ag){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",ai(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var ab=function(ar,az){this.track=ar;this.filters=[];for(var au=0;au<az.length;au++){var av=az[au],aA=av.name,ag=av.type,ai=av.index,ay=av.tool_id,ax=av.tool_exp_name;if(ag==="int"||ag==="float"){this.filters[au]=new W(aA,ai,ay,ax)}else{console.log("ERROR: unsupported filter: ",aA,ag)}}var aj=function(aB,aC,aD){aB.click(function(){var aE=aC.text();max=parseFloat(aD.slider("option","max")),input_size=(max<=1?4:max<=1000000?max.toString().length:6),multi_value=false;if(aD.slider("option","values")){input_size=2*input_size+1;multi_value=true}aC.text("");$("<input type='text'/>").attr("size",input_size).attr("maxlength",input_size).attr("value",aE).appendTo(aC).focus().select().click(function(aF){aF.stopPropagation()}).blur(function(){$(this).remove();aC.text(aE)}).keyup(function(aJ){if(aJ.keyCode===27){$(this).trigger("blur")}else{if(aJ.keyCode===13){var aH=aD.slider("option","min"),aF=aD.slider("option","max"),aI=function(aK){return(isNaN(aK)||aK>aF||aK<aH)},aG=$(this).val();if(!multi_value){aG=parseFloat(aG);if(aI(aG)){alert("Parameter value must be in the range ["+aH+"-"+aF+"]");return $(this)}}else{aG=aG.split("-");aG=[parseFloat(aG[0]),parseFloat(aG[1])];if(aI(aG[0])||aI(aG[1])){alert("Parameter value must be in the range ["+aH+"-"+aF+"]");return $(this)}}aD.slider((multi_value?"values":"value"),aG)}}})})};this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(aB){aB.stopPropagation()}).click(function(aB){aB.stopPropagation()}).bind("dblclick",function(aB){aB.stopPropagation()}).bind("keydown",function(aB){aB.stopPropagation()});var aw=$("<div/>").addClass("sliders").appendTo(this.parent_div);var ao=this;$.each(this.filters,function(aE,aG){aG.container=$("<div/>").addClass("filter-row slider-row").appendTo(aw);var aF=$("<div/>").addClass("elt-label").appendTo(aG.container);var aD=$("<span/>").addClass("slider-name").text(aG.name+" ").appendTo(aF);var aC=$("<span/>");var aI=$("<span/>").addClass("slider-value").appendTo(aF).append("[").append(aC).append("]");var aB=$("<div/>").addClass("slider").appendTo(aG.container);aG.control_element=$("<div/>").attr("id",aG.name+"-filter-control").appendTo(aB);var aH=[0,0];aG.control_element.slider({range:true,min:Number.MAX_VALUE,max:-Number.MIN_VALUE,values:[0,0],slide:function(aK,aL){var aJ=aL.values;aC.text(aJ[0]+"-"+aJ[1]);aG.low=aJ[0];aG.high=aJ[1];ao.track.request_draw(true,true)},change:function(aJ,aK){aG.control_element.slider("option","slide").call(aG.control_element,aJ,aK)}});aG.slider=aG.control_element;aG.slider_label=aC;aj(aI,aC,aG.control_element);$("<div style='clear: both;'/>").appendTo(aG.container)});if(this.filters.length!==0){var al=$("<div/>").addClass("param-row").appendTo(aw);var an=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(al);var ah=this;an.click(function(){ah.run_on_dataset()})}var aq=$("<div/>").addClass("display-controls").appendTo(this.parent_div),at,am,ap,ak={Transparency:function(aB){ao.alpha_filter=aB},Height:function(aB){ao.height_filter=aB}};$.each(ak,function(aD,aC){at=$("<div/>").addClass("filter-row").appendTo(aq),am=$("<span/>").addClass("elt-label").text(aD+":").appendTo(at),ap=$("<select/>").attr("name",aD+"_dropdown").css("float","right").appendTo(at);$("<option/>").attr("value",-1).text("== None ==").appendTo(ap);for(var aB=0;aB<ao.filters.length;aB++){$("<option/>").attr("value",aB).text(ao.filters[aB].name).appendTo(ap)}ap.change(function(){$(this).children("option:selected").each(function(){var aE=parseInt($(this).val());ak[aD]((aE>=0?ao.filters[aE]:null));ao.track.request_draw(true,true)})});$("<div style='clear: both;'/>").appendTo(at)});$("<div style='clear: both;'/>").appendTo(this.parent_div)};p(ab.prototype,{reset_filters:function(){for(var ag=0;ag<this.filters.length;ag++){filter=this.filters[ag];filter.slider.slider("option","values",[filter.min,filter.max])}this.alpha_filter=null;this.height_filter=null},run_on_dataset:function(){var ao=function(at,aq,ar){if(!(aq in at)){at[aq]=ar}return at[aq]};var ai={},ag,ah,aj;for(var ak=0;ak<this.filters.length;ak++){ag=this.filters[ak];if(ag.tool_id){if(ag.min!=ag.low){ah=ao(ai,ag.tool_id,[]);ah[ah.length]=ag.tool_exp_name+" >= "+ag.low}if(ag.max!=ag.high){ah=ao(ai,ag.tool_id,[]);ah[ah.length]=ag.tool_exp_name+" <= "+ag.high}}}var am=[];for(var ap in ai){am[am.length]=[ap,ai[ap]]}var an=am.length;(function al(ax,au){var ar=au[0],at=ar[0],aw=ar[1],av="("+aw.join(") and (")+")",aq={cond:av,input:ax,target_dataset_id:ax,tool_id:at},au=au.slice(1);$.getJSON(run_tool_url,aq,function(ay){if(ay.error){show_modal("Filter Dataset","Error running tool "+at,{Close:hide_modal})}else{if(au.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{al(ay.dataset_id,au)}}})})(this.track.dataset_id,am)}});var D=function(ag,ah){M.Scaler.call(this,ah);this.filter=ag};D.prototype.gen_val=function(ag){if(this.filter.high===Number.MAX_VALUE||this.filter.low===-Number.MAX_VALUE||this.filter.low===this.filter.high){return this.default_val}return((parseFloat(ag[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var G=function(ag){this.track=ag.track;this.params=ag.params;this.values={};this.restore_values((ag.saved_values?ag.saved_values:{}));this.onchange=ag.onchange};p(G.prototype,{restore_values:function(ag){var ah=this;$.each(this.params,function(ai,aj){if(ag[aj.key]!==undefined){ah.values[aj.key]=ag[aj.key]}else{ah.values[aj.key]=aj.default_value}})},build_form:function(){var ah=this;var ag=$("<div />");$.each(this.params,function(al,aj){if(!aj.hidden){var ai="param_"+al;var an=ah.values[aj.key];var aq=$("<div class='form-row' />").appendTo(ag);aq.append($("<label />").attr("for",ai).text(aj.label+":"));if(aj.type==="bool"){aq.append($('<input type="checkbox" />').attr("id",ai).attr("name",ai).attr("checked",an))}else{if(aj.type==="text"){aq.append($('<input type="text"/>').attr("id",ai).val(an).click(function(){$(this).select()}))}else{if(aj.type==="color"){var am=$("<input />").attr("id",ai).attr("name",ai).val(an);var ao=$("<div class='tipsy tipsy-north' style='position: absolute;' />").hide();var ak=$("<div style='background-color: black; padding: 10px;'></div>").appendTo(ao);var ap=$("<div/>").appendTo(ak).farbtastic({width:100,height:100,callback:am,color:an});$("<div />").append(am).append(ao).appendTo(aq).bind("click",function(ar){ao.css({left:$(this).position().left+($(am).width()/2)-60,top:$(this).position().top+$(this.height)}).show();$(document).bind("click.color-picker",function(){ao.hide();$(document).unbind("click.color-picker")});ar.stopPropagation()})}else{aq.append($("<input />").attr("id",ai).attr("name",ai).val(an))}}}}});return ag},update_from_form:function(ag){var ai=this;var ah=false;$.each(this.params,function(aj,al){if(!al.hidden){var am="param_"+aj;var ak=ag.find("#"+am).val();if(al.type==="float"){ak=parseFloat(ak)}else{if(al.type==="int"){ak=parseInt(ak)}else{if(al.type==="bool"){ak=ag.find("#"+am).is(":checked")}}}if(ak!==ai.values[al.key]){ai.values[al.key]=ak;ah=true}}});if(ah){this.onchange()}}});var b=function(ag,aj,ai,ah,ak){this.track=ag;this.index=aj;this.low=aj*R*ai;this.high=(aj+1)*R*ai;this.resolution=ai;this.canvas=$("<div class='track-tile'/>").append(ah);this.data=ak;this.stale=false};b.prototype.predisplay_actions=function(){};var k=function(ag,aj,ai,ah,ak,al){b.call(this,ag,aj,ai,ah,ak);this.max_val=al};p(k.prototype,b.prototype);var P=function(ag,ak,aj,ai,am,an,al,ah){b.call(this,ag,ak,aj,ai,am);this.mode=an;this.message=al;this.feature_mapper=ah};p(P.prototype,b.prototype);P.prototype.predisplay_actions=function(){var ah=this,ag={};if(ah.mode!=="Pack"){return}$(this.canvas).mousemove(function(at){var an=$(this).offset(),ar=at.pageX-an.left,aq=at.pageY-an.top,ax=ah.feature_mapper.get_feature_data(ar,aq),ao=(ax?ax[0]:null);$(this).siblings(".feature-popup").each(function(){if(!ao||$(this).attr("id")!==ao.toString()){$(this).remove()}});if(ax){var aj=ag[ao];if(!aj){var ao=ax[0],au={name:ax[3],start:ax[1],end:ax[2],strand:ax[4]},am=ah.track.filters_manager.filters,al;for(var ap=0;ap<am.length;ap++){al=am[ap];au[al.name]=ax[al.index]}var aj=$("<div/>").attr("id",ao).addClass("feature-popup"),aw,av,ay=$("<table/>").appendTo(aj),az;for(aw in au){av=au[aw];az=$("<tr/>").appendTo(ay);$("<th/>").appendTo(az).text(aw);$("<td/>").attr("align","left").appendTo(az).text(typeof(av)=="number"?aa(av,2):av)}ag[ao]=aj}aj.appendTo($(ah.canvas).parent());var ak=ar+parseInt(ah.canvas.css("left"))+7,ai=aq+parseInt(ah.canvas.css("top"))+7;aj.css("left",ak+"px").css("top",ai+"px")}else{if(!at.isPropagationStopped()){at.stopPropagation();$(this).siblings().each(function(){$(this).trigger(at)})}}}).mouseleave(function(){$(this).siblings(".feature-popup").remove()})};var i=function(aj,ar,ak,an,at,ai,ah){q.call(this,aj,ar,ak,{},"draghandle");this.data_url=(ai?ai:default_data_url);this.data_url_extra_params={};this.data_query_wait=(ah?ah:L);this.dataset_check_url=converted_datasets_state_url;if(!i.id_counter){i.id_counter=0}this.id=i.id_counter++;this.container_div=$("<div />").addClass("track").attr("id","track_"+this.id).css("position","relative");if(an){this.header_div=$("<div class='track-header' />").appendTo(this.container_div);if(this.view.editor){this.drag_div=$("<div/>").addClass(this.drag_handle_class).appendTo(this.header_div)}this.name_div=$("<div/>").addClass("track-name").appendTo(this.header_div).text(this.name).attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase());this.icons_div=$("<div/>").css("float","left").appendTo(this.header_div).hide();this.settings_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Edit settings").addClass("icon-button settings-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);this.overview_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Set as overview").addClass("icon-button overview-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);this.filters_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Filters").addClass("icon-button filters-icon").tipsy({gravity:"s"}).appendTo(this.icons_div).hide();this.tools_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Tools").addClass("icon-button tools-icon").tipsy({gravity:"s"}).appendTo(this.icons_div).hide();this.remove_icon=$("<a/>").attr("href","javascript:void(0);").attr("title","Remove").addClass("icon-button remove-icon").tipsy({gravity:"s"}).appendTo(this.icons_div);var al=this;this.header_div.dblclick(function(au){au.stopPropagation()});this.settings_icon.click(function(){var aw=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},au=function(){al.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},av=function(ax){if((ax.keyCode||ax.which)===27){aw()}else{if((ax.keyCode||ax.which)===13){au()}}};$(window).bind("keypress.check_enter_esc",av);show_modal("Configure Track",al.config.build_form(),{Cancel:aw,OK:au})});this.overview_icon.click(function(){al.view.set_overview(al)});this.filters_icon.click(function(){al.filters_div.toggle();al.filters_manager.reset_filters()});this.tools_icon.click(function(){al.dynamic_tool_div.toggle();if(al.dynamic_tool_div.is(":visible")){al.set_name(al.name+al.tool_region_and_parameters_str())}else{al.revert_name()}$(".tipsy").remove()});this.remove_icon.click(function(){$(".tipsy").remove();al.remove()});if(al.display_modes!==undefined){if(al.mode_div===undefined){al.mode_div=$("<div class='right-float menubutton popup' />").appendTo(al.header_div);var am=(al.config&&al.config.values.mode?al.config.values.mode:al.display_modes[0]);al.mode=am;al.mode_div.text(am);var ag={};for(var ao=0,aq=al.display_modes.length;ao<aq;ao++){var ap=al.display_modes[ao];ag[ap]=function(au){return function(){al.change_mode(au)}}(ap)}make_popupmenu(al.mode_div,ag)}else{al.mode_div.hide()}this.header_div.append($("<div/>").css("clear","both"));this.container_div.hover(function(){al.icons_div.show()},function(){al.icons_div.hide()})}}this.content_div=$("<div class='track-content'>").appendTo(this.container_div);this.container.content_div.append(this.container_div)};p(i.prototype,q.prototype,{get_type:function(){if(this instanceof ac){return"LabelTrack"}else{if(this instanceof A){return"ReferenceTrack"}else{if(this instanceof j){return"LineTrack"}else{if(this instanceof X){return"ReadTrack"}else{if(this instanceof V){return"ToolDataFeatureTrack"}else{if(this instanceof U){return"VcfTrack"}else{if(this instanceof e){return"FeatureTrack"}}}}}}}return""},init:function(){var ag=this;ag.enabled=false;ag.tile_cache.clear();ag.data_manager.clear();ag.initial_canvas=undefined;ag.content_div.css("height","auto");ag.container_div.removeClass("nodata error pending");if(!ag.dataset_id){return}$.getJSON(converted_datasets_state_url,{hda_ldda:ag.hda_ldda,dataset_id:ag.dataset_id,chrom:ag.view.chrom},function(ah){if(!ah||ah==="error"||ah.kind==="error"){ag.container_div.addClass("error");ag.content_div.text(o);if(ah.message){var ai=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+ah.message+"</pre>",{Close:hide_modal})});ag.content_div.append(ai)}}else{if(ah==="no converter"){ag.container_div.addClass("error");ag.content_div.text(K)}else{if(ah==="no data"||(ah.data!==undefined&&(ah.data===null||ah.data.length===0))){ag.container_div.addClass("nodata");ag.content_div.text(F)}else{if(ah==="pending"){ag.container_div.addClass("pending");ag.content_div.text(t);setTimeout(function(){ag.init()},ag.data_query_wait)}else{if(ah.status==="data"){if(ah.valid_chroms){ag.valid_chroms=ah.valid_chroms;ag.update_track_icons()}ag.content_div.text(Z);if(ag.view.chrom){ag.content_div.text("");ag.content_div.css("height",ag.height_px+"px");ag.enabled=true;$.when(ag.predraw_init()).done(function(){ag.container_div.removeClass("nodata error pending");ag.request_draw()})}}}}}}});this.update_track_icons()},predraw_init:function(){}});var N=function(ai,ao,aj,al,ap,an,am,ah,ag){i.call(this,ai,ao,aj,al,ap,ah,ag);var ak=this,ao=ak.view;m(ak.container_div,ak.drag_handle_class,".group",ak);this.filters_manager=new ab(this,(an!==undefined?an:{}));this.filters_available=false;this.filters_visible=false;this.tool=(am!==undefined&&obj_length(am)>0?new r(this,am):undefined);if(this.header_div){if(this.filters_manager){this.filters_div=this.filters_manager.parent_div;this.header_div.after(this.filters_div)}if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}}};p(N.prototype,q.prototype,i.prototype,{copy:function(ag){return new this.constructor(this.name,this.view,ag,this.hda_ldda,this.dataset_id,this.prefs,this.filters,this.tool)},to_json:function(){return{track_type:this.get_type(),name:this.name,hda_ldda:this.hda_ldda,dataset_id:this.dataset_id,prefs:this.prefs,mode:this.mode,}},change_mode:function(ah){var ag=this;ag.mode_div.text(ah);ag.mode=ah;ag.config.values.mode=ah;ag.tile_cache.clear();ag.request_draw();return ag},update_track_icons:function(){var ag=this;if(ag.filters_available>0){ag.filters_icon.show()}else{ag.filters_icon.hide()}if(ag.tool){ag.tools_icon.show()}else{ag.tools_icon.hide()}},_gen_tile_cache_key:function(ah,ai,ag){return ah+"_"+ai+"_"+ag},request_draw:function(ah,ag){this.view.request_redraw(false,ah,ag,this)},_draw:function(ai,aq){if(!this.enabled){return}if(!(this instanceof A)&&(!this.dataset_id)){return}var ap=this.view.low,am=this.view.high,an=am-ap,aj=this.view.container.width(),au=aj/an,al=this.view.resolution,at=$("<div style='position: relative;'></div>");if(this.is_overview){ap=this.view.max_low;am=this.view.max_high;al=Math.pow(C,Math.ceil(Math.log((view.max_high-view.max_low)/R)/Math.log(C)));au=aj/(view.max_high-view.max_low)}if(!aq){this.content_div.children().remove()}this.content_div.append(at);this.max_height=0;var ah=Math.floor(ap/al/R);var ao=true;var ar=[];var ag=0;while((ah*R*al)<am){tile=this.draw_helper(ai,aj,ah,al,at,au);if(tile){ar.push(tile)}else{ao=false}ah+=1;ag++}var ak=this;if(ao){ak.postdraw_actions(ar,aj,au,aq)}},postdraw_actions:function(ak,al,am,ag){var ai=this;var aj=false;for(var ah=0;ah<ak.length;ah++){if(ak[ah].message){aj=true;break}}if(aj){for(var ah=0;ah<ak.length;ah++){tile=ak[ah];if(!tile.message){tile.canvas.css("padding-top",E)}}}},draw_helper:function(ah,ai,aj,am,at,ax,au,an){var ak=this,ar=this._gen_tile_cache_key(ai,ax,aj),ao=aj*R*am,aw=ao+R*am;var ap=(ah?undefined:ak.tile_cache.get(ar));if(ap){ak.show_tile(ap,at,ax);return ap}var aq=function(ay){return("isResolved" in ay)};var al=true;var ag=ak.data_manager.get_data(ao,aw,ak.mode,am,ak.data_url_extra_params);if(aq(ag)){al=false}var av;if(view.reference_track&&ax>view.canvas_manager.char_width_px){av=view.reference_track.data_manager.get_data(ao,aw,ak.mode,am,view.reference_track.data_url_extra_params);if(aq(av)){al=false}}if(al){p(ag,an);var ap=ak.draw_tile(ag,ak.mode,am,aj,ax,av);if(ap!==undefined){ak.tile_cache.set(ar,ap);ak.show_tile(ap,at,ax)}return ap}$.when(ag,av).then(function(){view.request_redraw(false,false,false,ak)});return null},show_tile:function(am,ao,ap){var ai=this,ah=am.canvas,al=ah;if(am.message){var aq=$("<div/>"),an=$("<div/>").addClass("tile-message").text(am.message).css({height:E-1,width:am.canvas.width}).appendTo(aq),ak=$("<a href='javascript:void(0);'/>").addClass("icon more-down").appendTo(an),ag=$("<a href='javascript:void(0);'/>").addClass("icon more-across").appendTo(an);aq.append(ah);al=aq;ak.click(function(){am.stale=true;ai.data_manager.get_more_data(am.low,am.high,ai.mode,am.resolution,{},ai.data_manager.DEEP_DATA_REQ);ai.request_draw()}).dblclick(function(ar){ar.stopPropagation()});ag.click(function(){am.stale=true;ai.data_manager.get_more_data(am.low,am.high,ai.mode,am.resolution,{},ai.data_manager.BROAD_DATA_REQ);ai.request_draw()}).dblclick(function(ar){ar.stopPropagation()})}am.predisplay_actions();var aj=(am.low-(this.is_overview?this.view.max_low:this.view.low))*ap;if(this.left_offset){aj-=this.left_offset}al.css({position:"absolute",top:0,left:aj,height:""});ao.append(al);ai.max_height=Math.max(ai.max_height,al.height());ai.content_div.css("height",ai.max_height+"px");ao.children().css("height",ai.max_height+"px")},_get_tile_bounds:function(ag,ah){var aj=ag*R*ah,ak=R*ah,ai=(aj+ak<=this.view.max_high?aj+ak:this.view.max_high);return[aj,ai]},tool_region_and_parameters_str:function(ai,ag,aj){var ah=this,ak=(ai!==undefined&&ag!==undefined&&aj!==undefined?ai+":"+ag+"-"+aj:"all");return" - region=["+ak+"], parameters=["+ah.tool.get_param_values().join(", ")+"]"}});var ac=function(ah,ag){i.call(this,"label",ah,ag,false,{});this.container_div.addClass("label-track")};p(ac.prototype,i.prototype,{init:function(){this.enabled=true},_draw:function(){var ai=this.view,aj=ai.high-ai.low,am=Math.floor(Math.pow(10,Math.floor(Math.log(aj)/Math.log(10)))),ag=Math.floor(ai.low/am)*am,ak=this.view.container.width(),ah=$("<div style='position: relative; height: 1.3em;'></div>");while(ag<ai.high){var al=(ag-ai.low)/aj*ak;ah.append($("<div class='label'>"+commatize(ag)+"</div>").css({position:"absolute",left:al-1}));ag+=am}this.content_div.children(":first").remove();this.content_div.append(ah)}});var A=function(ag){N.call(this,"reference",ag,{content_div:ag.top_labeltrack},false,{});ag.reference_track=this;this.left_offset=200;this.height_px=12;this.container_div.addClass("reference-track");this.content_div.css("background","none");this.content_div.css("min-height","0px");this.content_div.css("border","none");this.data_url=reference_url;this.data_url_extra_params={dbkey:ag.dbkey};this.data_manager=new I(B,this,false);this.tile_cache=new c(u)};p(A.prototype,q.prototype,N.prototype,{init:function(){this.enabled=true},draw_tile:function(aq,am,al,ah,ar){var ak=this,ai=R*al;if(ar>this.view.canvas_manager.char_width_px){if(aq.data===null){ak.content_div.css("height","0px");return}var aj=this.view.canvas_manager.new_canvas();var ap=aj.getContext("2d");aj.width=Math.ceil(ai*ar+ak.left_offset);aj.height=ak.height_px;ap.font=ap.canvas.manager.default_font;ap.textAlign="center";aq=aq.data;for(var an=0,ao=aq.length;an<ao;an++){var ag=Math.round(an*ar);ap.fillText(aq[an],ag+ak.left_offset,10)}return new b(ak,ah,al,aj,aq)}this.content_div.css("height","0px")}});var j=function(al,aj,ai,am,ag,ak){var ah=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";N.call(this,al,aj,ai,true,ak);this.min_height_px=16;this.max_height_px=400;this.height_px=80;this.hda_ldda=am;this.dataset_id=ag;this.original_dataset_id=ag;this.data_manager=new S(B,this);this.tile_cache=new c(u);this.left_offset=0;this.config=new G({track:this,params:[{key:"name",label:"Name",type:"text",default_value:al},{key:"color",label:"Color",type:"color",default_value:get_random_color()},{key:"min_value",label:"Min Value",type:"float",default_value:undefined},{key:"max_value",label:"Max Value",type:"float",default_value:undefined},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.height_px,hidden:true}],saved_values:ak,onchange:function(){ah.set_name(ah.prefs.name);ah.vertical_range=ah.prefs.max_value-ah.prefs.min_value;$("#linetrack_"+ah.dataset_id+"_minval").text(ah.prefs.min_value);$("#linetrack_"+ah.dataset_id+"_maxval").text(ah.prefs.max_value);ah.tile_cache.clear();ah.request_draw()}});this.prefs=this.config.values;this.height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value;this.add_resize_handle()};p(j.prototype,q.prototype,N.prototype,{add_resize_handle:function(){var ag=this;var aj=false;var ai=false;var ah=$("<div class='track-resize'>");$(ag.container_div).hover(function(){aj=true;ah.show()},function(){aj=false;if(!ai){ah.hide()}});ah.hide().bind("dragstart",function(ak,al){ai=true;al.original_height=$(ag.content_div).height()}).bind("drag",function(al,am){var ak=Math.min(Math.max(am.original_height+am.deltaY,ag.min_height_px),ag.max_height_px);$(ag.content_div).css("height",ak);ag.height_px=ak;ag.request_draw(true)}).bind("dragend",function(ak,al){ag.tile_cache.clear();ai=false;if(!aj){ah.hide()}ag.config.values.height=ag.height_px}).appendTo(ag.container_div)},predraw_init:function(){var ag=this;ag.vertical_range=undefined;return $.getJSON(ag.data_url,{stats:true,chrom:ag.view.chrom,low:null,high:null,hda_ldda:ag.hda_ldda,dataset_id:ag.dataset_id},function(ah){ag.container_div.addClass("line-track");var aj=ah.data;if(isNaN(parseFloat(ag.prefs.min_value))||isNaN(parseFloat(ag.prefs.max_value))){ag.prefs.min_value=aj.min;ag.prefs.max_value=aj.max;$("#track_"+ag.dataset_id+"_minval").val(ag.prefs.min_value);$("#track_"+ag.dataset_id+"_maxval").val(ag.prefs.max_value)}ag.vertical_range=ag.prefs.max_value-ag.prefs.min_value;ag.total_frequency=aj.total_frequency;ag.container_div.find(".yaxislabel").remove();var ak=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ag.dataset_id+"_minval").text(aa(ag.prefs.min_value,3));var ai=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ag.dataset_id+"_maxval").text(aa(ag.prefs.max_value,3));ai.css({position:"absolute",top:"24px",left:"10px"});ai.prependTo(ag.container_div);ak.css({position:"absolute",bottom:"2px",left:"10px"});ak.prependTo(ag.container_div)})},draw_tile:function(at,al,ak,ai,ar){if(this.vertical_range===undefined){return}var ag=this._get_tile_bounds(ai,ak),am=ag[0],aq=ag[1],ah=Math.ceil((aq-am)*ar),ao=this.height_px;var aj=this.view.canvas_manager.new_canvas();aj.width=ah,aj.height=ao;var ap=aj.getContext("2d");var an=new M.LinePainter(at.data,am,aq,this.prefs,al);an.draw(ap,ah,ao);return new b(this.track,ai,ak,aj,at.data)}});var e=function(ag,am,ah,al,ao,an,aj,ak){var ai=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];N.call(this,ag,am,ah,true,an,aj,ak);this.config=new G({track:this,params:[{key:"name",label:"Name",type:"text",default_value:ag},{key:"block_color",label:"Block color",type:"color",default_value:get_random_color()},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:an,onchange:function(){ai.set_name(ai.prefs.name);ai.tile_cache.clear();ai.request_draw()}});this.prefs=this.config.values;this.height_px=0;this.container_div.addClass("feature-track");this.hda_ldda=al;this.dataset_id=ao;this.original_dataset_id=ao;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.inc_slots={};this.start_end_dct={};this.tile_cache=new c(d);this.data_manager=new S(20,this);this.left_offset=200;this.painter=M.LinkedFeaturePainter};p(e.prototype,q.prototype,N.prototype,{postdraw_actions:function(aw,ag,ax,av){N.prototype.postdraw_actions.call(this,aw,av);var aj=this;if(av){var al=aj.content_div.children();var am=false;for(var ak=al.length-1,aq=0;ak>=aq;ak--){var ai=$(al[ak]);if(am){ai.remove()}else{if(ai.children().length!==0){am=true}}}}if(aj.mode=="Histogram"){var ap=-1;for(var ak=0;ak<aw.length;ak++){var au=aw[ak].max_val;if(au>ap){ap=au}}for(var ak=0;ak<aw.length;ak++){var at=aw[ak];if(at.max_val!==ap){at.canvas.remove();aj.draw_helper(true,ag,at.index,at.resolution,at.canvas.parent(),ax,[],{max:ap})}}}if(aj.filters_manager){var ah=aj.filters_manager.filters;for(var ao=0;ao<ah.length;ao++){ah[ao].update_ui_elt()}var an=false,ar;for(var ak=0;ak<aw.length;ak++){if(aw[ak].data.length){ar=aw[ak].data[0];for(var ao=0;ao<ah.length;ao++){if(ah[ao].applies_to(ar)){an=true;break}}}}if(aj.filters_available!==an){aj.filters_available=an;if(!aj.filters_available){aj.filters_div.hide()}aj.update_track_icons()}}},update_auto_mode:function(ag){if(this.mode=="Auto"){if(ag=="no_detail"){ag="feature spans"}else{if(ag=="summary_tree"){ag="coverage histogram"}}this.mode_div.text("Auto ("+ag+")")}},incremental_slots:function(ak,ah,aj){var ai=this.view.canvas_manager.dummy_context,ag=this.inc_slots[ak];if(!ag||(ag.mode!==aj)){ag=new (s.FeatureSlotter)(ak,aj==="Pack",z,function(al){return ai.measureText(al)});ag.mode=aj;this.inc_slots[ak]=ag}return ag.slot_features(ah)},get_summary_tree_data:function(ak,an,ai,aw){if(aw>ai-an){aw=ai-an}var ar=Math.floor((ai-an)/aw),av=[],aj=0;var al=0,am=0,aq,au=0,ao=[],at,ap;var ah=function(az,ay,aA,ax){az[0]=ay+aA*ax;az[1]=ay+(aA+1)*ax};while(au<aw&&al!==ak.length){var ag=false;for(;au<aw&&!ag;au++){ah(ao,an,au,ar);for(am=al;am<ak.length;am++){aq=ak[am].slice(1,3);if(is_overlap(aq,ao)){ag=true;break}}if(ag){break}}data_start_index=am;av[av.length]=at=[ao[0],0];for(;am<ak.length;am++){aq=ak[am].slice(1,3);if(is_overlap(aq,ao)){at[1]++}else{break}}if(at[1]>aj){aj=at[1]}au++}return{max:aj,delta:ar,data:av}},draw_tile:function(av,ay,aC,aG,aq,aj){var az=this,al=az._get_tile_bounds(aG,aC),aJ=al[0],ah=al[1],ax=ah-aJ,aA=Math.ceil(ax*aq),aP=25,ak=this.left_offset,aw,am;if(ay==="Auto"){if(av.dataset_type==="summary_tree"){ay=av.dataset_type}else{if(av.extra_info==="no_detail"||az.is_overview){ay="no_detail"}else{var aO=av.data;if(this.view.high-this.view.low>J){ay="Squish"}else{ay="Pack"}}}this.update_auto_mode(ay)}if(ay==="summary_tree"||ay==="Histogram"){am=this.summary_draw_height;this.container_div.find(".yaxislabel").remove();var ag=$("<div />").addClass("yaxislabel");ag.text(av.max);ag.css({position:"absolute",top:"24px",left:"10px",color:this.prefs.label_color});ag.prependTo(this.container_div);var ai=this.view.canvas_manager.new_canvas();ai.width=aA+ak;ai.height=am+T;if(av.dataset_type!="summary_tree"){var ar=this.get_summary_tree_data(av.data,aJ,ah,200);if(av.max){ar.max=av.max}av=ar}var aL=new M.SummaryTreePainter(av,aJ,ah,this.prefs);var aB=ai.getContext("2d");aB.translate(ak,T);aL.draw(aB,aA,am);return new k(az,aG,aC,ai,av.data,av.max)}var aw,ao=1;if(ay==="no_detail"||ay==="Squish"||ay==="Pack"){ao=this.incremental_slots(aq,av.data,ay);aw=this.inc_slots[aq].slots}var ap=[];if(av.data){var at=this.filters_manager.filters;for(var aD=0,aF=av.data.length;aD<aF;aD++){var an=av.data[aD];var aE=false;var au;for(var aI=0,aN=at.length;aI<aN;aI++){au=at[aI];au.update_attrs(an);if(!au.keep(an)){aE=true;break}}if(!aE){ap.push(an)}}}var aM=(this.filters_manager.alpha_filter?new D(this.filters_manager.alpha_filter):null);var aK=(this.filters_manager.height_filter?new D(this.filters_manager.height_filter):null);var aL=new (this.painter)(ap,aJ,ah,this.prefs,ay,aM,aK,aj);var am=Math.max(ae,aL.get_required_height(ao));var ai=this.view.canvas_manager.new_canvas();var aH=null;ai.width=aA+ak;ai.height=am;var aB=ai.getContext("2d");aB.fillStyle=this.prefs.block_color;aB.font=aB.canvas.manager.default_font;aB.textAlign="right";this.container_div.find(".yaxislabel").remove();if(av.data){aB.translate(ak,0);aH=aL.draw(aB,aA,am,aw);aH.translation=-ak}return new P(az,aG,aC,ai,av.data,ay,av.message,aH)}});var U=function(ak,ai,ah,am,ag,aj,al){e.call(this,ak,ai,ah,am,ag,aj,al);this.config=new G({track:this,params:[{key:"name",label:"Name",type:"text",default_value:ak},{key:"block_color",label:"Block color",type:"color",default_value:get_random_color()},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_insertions",label:"Show insertions",type:"bool",default_value:false},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:aj,onchange:function(){this.track.set_name(this.track.prefs.name);this.track.tile_cache.clear();this.track.request_draw()}});this.prefs=this.config.values;this.painter=M.ReadPainter};p(U.prototype,q.prototype,N.prototype,e.prototype);var X=function(ak,ai,ah,am,ag,aj,al){e.call(this,ak,ai,ah,am,ag,aj,al);this.config=new G({track:this,params:[{key:"name",label:"Name",type:"text",default_value:ak},{key:"block_color",label:"Block color",type:"color",default_value:get_random_color()},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_insertions",label:"Show insertions",type:"bool",default_value:false},{key:"show_differences",label:"Show differences only",type:"bool",default_value:true},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:aj,onchange:function(){this.track.set_name(this.track.prefs.name);this.track.tile_cache.clear();this.track.request_draw()}});this.prefs=this.config.values;this.painter=M.ReadPainter;this.update_track_icons()};p(X.prototype,q.prototype,N.prototype,e.prototype);var V=function(ak,ai,ah,am,ag,aj,al){e.call(this,ak,ai,ah,am,ag,aj,al,{});this.data_url=raw_data_url;this.data_query_wait=1000;this.dataset_check_url=dataset_state_url};p(V.prototype,q.prototype,N.prototype,e.prototype,{predraw_init:function(){var ah=this;var ag=function(){if(ah.data_manager.size()===0){setTimeout(ag,300)}else{ah.data_url=default_data_url;ah.data_query_wait=L;ah.dataset_state_url=converted_datasets_state_url;$.getJSON(ah.dataset_state_url,{dataset_id:ah.dataset_id,hda_ldda:ah.hda_ldda},function(ai){})}};ag()}});Y.View=ad;Y.DrawableGroup=Q;Y.LineTrack=j;Y.FeatureTrack=e;Y.ReadTrack=X;Y.VcfTrack=U};var slotting_module=function(c,b){var e=c("class").extend;var d=2,a=5;b.FeatureSlotter=function(i,h,f,g){this.slots={};this.start_end_dct={};this.w_scale=i;this.include_label=h;this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,s=this.slots,h=this.start_end_dct,y=[],A=[],n=0,z=this.max_rows;for(var w=0,x=m.length;w<x;w++){var l=m[w],o=l[0];if(s[o]!==undefined){n=Math.max(n,s[o]);A.push(s[o])}else{y.push(w)}}var q=function(F,G){for(var E=0;E<=z;E++){var C=false,H=h[E];if(H!==undefined){for(var B=0,D=H.length;B<D;B++){var i=H[B];if(G>i[0]&&F<i[1]){C=true;break}}}if(!C){return E}}return -1};for(var w=0,x=y.length;w<x;w++){var l=m[y[w]],o=l[0],u=l[1],f=l[2],r=l[3],g=Math.floor(u*p),k=Math.ceil(f*p),v=this.measureText(r).width,j;if(r!==undefined&&this.include_label){v+=(d+a);if(g-v>=0){g-=v;j="left"}else{k+=v;j="right"}}var t=q(g,k);if(t>=0){if(h[t]===undefined){h[t]=[]}h[t].push([g,k]);s[o]=t;n=Math.max(n,t)}else{}}return n+1}})};var painters_module=function(i,w){var t=i("class").extend;var o=function(H,z,F,y,E,C){if(C===undefined){C=4}var B=y-z;var A=E-F;var D=Math.floor(Math.sqrt(B*B+A*A)/C);var I=B/D;var G=A/D;var x;for(x=0;x<D;x++,z+=I,F+=G){if(x%2!==0){continue}H.fillRect(z,F,C,1)}};var p=function(A,z,x,D){var C=z-D/2,B=z+D/2,E=x-Math.sqrt(D*3/2);A.beginPath();A.moveTo(C,E);A.lineTo(B,E);A.lineTo(z,x);A.lineTo(C,E);A.strokeStyle=this.fillStyle;A.fill();A.stroke();A.closePath()};var d=function(x){this.default_val=(x?x:1)};d.prototype.gen_val=function(x){return this.default_val};var l=function(z,B,x,y,A){this.data=z;this.view_start=B;this.view_end=x;this.prefs=t({},this.default_prefs,y);this.mode=A};l.prototype.default_prefs={};var u=function(z,B,x,y,A){l.call(this,z,B,x,y,A)};u.prototype.default_prefs={show_counts:false};u.prototype.draw=function(M,z,L){var E=this.view_start,O=this.view_end-this.view_start,N=z/O;var J=this.data.data,I=this.data.delta,G=this.data.max,B=L;delta_x_px=Math.ceil(I*N);M.save();for(var C=0,D=J.length;C<D;C++){var H=Math.floor((J[C][0]-E)*N);var F=J[C][1];if(!F){continue}var K=F/G*L;if(F!==0&&K<1){K=1}M.fillStyle=this.prefs.block_color;M.fillRect(H,B-K,delta_x_px,K);var A=4;if(this.prefs.show_counts&&(M.measureText(F).width+A)<delta_x_px){M.fillStyle=this.prefs.label_color;M.textAlign="center";M.fillText(F,H+(delta_x_px/2),10)}}M.restore()};var b=function(x,B,D,E,z){l.call(this,x,B,D,E,z);if(this.prefs.min_value===undefined){var F=Infinity;for(var y=0,A=this.data.length;y<A;y++){F=Math.min(F,this.data[y][1])}this.prefs.min_value=F}if(this.prefs.max_value===undefined){var C=-Infinity;for(var y=0,A=this.data.length;y<A;y++){C=Math.max(C,this.data[y][1])}this.prefs.max_value=C}};b.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};b.prototype.draw=function(M,L,J){var E=false,G=this.prefs.min_value,C=this.prefs.max_value,I=C-G,x=J,z=this.view_start,K=this.view_end-this.view_start,A=L/K,H=this.mode,S=this.data;M.save();var T=Math.round(J+G/I*J);if(H!=="Intensity"){M.fillStyle="#aaa";M.fillRect(0,T,L,1)}M.beginPath();var Q,D,B;if(S.length>1){B=Math.ceil((S[1][0]-S[0][0])*A)}else{B=10}for(var N=0,O=S.length;N<O;N++){M.fillStyle=this.prefs.color;Q=Math.round((S[N][0]-z)*A);D=S[N][1];var P=false,F=false;if(D===null){if(E&&H==="Filled"){M.lineTo(Q,x)}E=false;continue}if(D<G){F=true;D=G}else{if(D>C){P=true;D=C}}if(H==="Histogram"){D=Math.round(D/I*x);M.fillRect(Q,T,B,-D)}else{if(H==="Intensity"){D=255-Math.floor((D-G)/I*255);M.fillStyle="rgb("+D+","+D+","+D+")";M.fillRect(Q,0,B,x)}else{D=Math.round(x-(D-G)/I*x);if(E){M.lineTo(Q,D)}else{E=true;if(H==="Filled"){M.moveTo(Q,x);M.lineTo(Q,D)}else{M.moveTo(Q,D)}}}}M.fillStyle=this.prefs.overflow_color;if(P||F){var R;if(H==="Histogram"||H==="Intensity"){R=B}else{Q-=2;R=4}if(P){M.fillRect(Q,0,R,3)}if(F){M.fillRect(Q,x-3,R,3)}}M.fillStyle=this.prefs.color}if(H==="Filled"){if(E){M.lineTo(Q,T);M.lineTo(0,T)}M.fill()}else{M.stroke()}M.restore()};var m=function(x){this.feature_positions={};this.slot_height=x;this.translation=0};m.prototype.map_feature_data=function(y,A,x,z){if(!this.feature_positions[A]){this.feature_positions[A]=[]}this.feature_positions[A].push({data:y,x_start:x,x_end:z})};m.prototype.get_feature_data=function(z,D){var C=Math.floor(D/this.slot_height),B;if(!this.feature_positions[C]){return null}z+=this.translation;for(var A=0;A<this.feature_positions[C].length;A++){B=this.feature_positions[C][A];if(z>=B.x_start&&z<=B.x_end){return B.data}}};var n=function(z,C,x,y,B,D,A){l.call(this,z,C,x,y,B);this.alpha_scaler=(D?D:new d());this.height_scaler=(A?A:new d())};n.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};t(n.prototype,{get_required_height:function(y){var x=y_scale=this.get_row_height(),z=this.mode;if(z==="no_detail"||z==="Squish"||z==="Pack"){x=y*y_scale}return x+Math.max(Math.round(y_scale/2),5)},draw:function(J,H,F,E){var P=this.data,C=this.view_start,L=this.view_end;J.save();J.fillStyle=this.prefs.block_color;J.textAlign="right";var G=this.view_end-this.view_start,D=H/G,K=this.get_row_height(),O=new m(K),A;for(var M=0,N=P.length;M<N;M++){var z=P[M],B=z[0],I=z[1],x=z[2],y=(E&&E[B]!==undefined?E[B]:null);if((I<L&&x>C)&&(this.mode=="Dense"||y!==null)){A=this.draw_element(J,this.mode,z,y,C,L,D,K,H);O.map_feature_data(z,y,A[0],A[1])}}J.restore();return O},draw_element:function(D,z,F,B,A,C,E,y,x){console.log("WARNING: Unimplemented function.");return[0,0]}});var c=10,h=3,k=5,v=10,f=1,r=3,e=3,a=9,j=2,g="#ccc";var q=function(z,C,x,y,B,D,A){n.call(this,z,C,x,y,B,D,A)};t(q.prototype,n.prototype,{get_row_height:function(){var y=this.mode,x;if(y==="Dense"){x=c}else{if(y==="no_detail"){x=h}else{if(y==="Squish"){x=k}else{x=v}}}return x},draw_element:function(L,C,U,G,N,af,aj,al,x){var R=U[0],ah=U[1],Z=U[2],P=U[3],aa=Math.floor(Math.max(0,(ah-N)*aj)),M=Math.ceil(Math.min(x,Math.max(0,(Z-N)*aj))),Y=aa,ak=M,X=(C==="Dense"?0:(0+G))*al,K,ad,Q=null,an=null,A=this.prefs.block_color,ac=this.prefs.label_color;L.globalAlpha=this.alpha_scaler.gen_val(U);if(C==="Dense"){G=1}if(C==="no_detail"){L.fillStyle=A;L.fillRect(aa,X+5,M-aa,f)}else{var J=U[4],W=U[5],ab=U[6],B=U[7];if(W&&ab){Q=Math.floor(Math.max(0,(W-N)*aj));an=Math.ceil(Math.min(x,Math.max(0,(ab-N)*aj)))}var ai,S;if(C==="Squish"||C==="Dense"){ai=1;S=e}else{ai=5;S=a}if(!B){if(U.strand){if(U.strand==="+"){L.fillStyle=L.canvas.manager.get_pattern("right_strand_inv")}else{if(U.strand==="-"){L.fillStyle=L.canvas.manager.get_pattern("left_strand_inv")}}}else{L.fillStyle=A}L.fillRect(aa,X,M-aa,S)}else{var I,T;if(C==="Squish"||C==="Dense"){L.fillStyle=g;I=X+Math.floor(e/2)+1;T=1}else{if(J){var I=X;var T=S;if(J==="+"){L.fillStyle=L.canvas.manager.get_pattern("right_strand")}else{if(J==="-"){L.fillStyle=L.canvas.manager.get_pattern("left_strand")}}}else{L.fillStyle=g;I+=(e/2)+1;T=1}}L.fillRect(aa,I,M-aa,T);var D;for(var ag=0,z=B.length;ag<z;ag++){var E=B[ag],y=Math.floor(Math.max(0,(E[0]-N)*aj)),V=Math.ceil(Math.min(x,Math.max((E[1]-N)*aj)));if(y>V){continue}L.fillStyle=A;L.fillRect(y,X+(S-ai)/2+1,V-y,ai);if(Q!==undefined&&ab>W&&!(y>an||V<Q)){var ae=Math.max(y,Q),H=Math.min(V,an);L.fillRect(ae,X+1,H-ae,S);if(B.length==1&&C=="Pack"){if(J==="+"){L.fillStyle=L.canvas.manager.get_pattern("right_strand_inv")}else{if(J==="-"){L.fillStyle=L.canvas.manager.get_pattern("left_strand_inv")}}if(ae+14<H){ae+=2;H-=2}L.fillRect(ae,X+1,H-ae,S)}}}if(C==="Pack"){L.globalAlpha=1;L.fillStyle="white";var F=this.height_scaler.gen_val(U),O=Math.ceil(S*F),am=Math.round((S-O)/2);if(F!==1){L.fillRect(aa,I+1,M-aa,am);L.fillRect(aa,I+S-am+1,M-aa,am)}}}L.globalAlpha=1;if(C==="Pack"&&ah>N){L.fillStyle=ac;if(N===0&&aa-L.measureText(P).width<0){L.textAlign="left";L.fillText(P,M+j,X+8);ak+=L.measureText(P).width+j}else{L.textAlign="right";L.fillText(P,aa-j,X+8);Y-=L.measureText(P).width+j}}}L.globalAlpha=1;return[Y,ak]}});var s=function(A,D,x,z,C,E,B,y){n.call(this,A,D,x,z,C,E,B);this.ref_seq=(y?y.data:null)};s.prototype.default_prefs=t({},n.prototype.default_prefs,{show_insertions:false});t(s.prototype,n.prototype,{get_row_height:function(){var x,y=this.mode;if(y==="Dense"){x=c}else{if(y==="Squish"){x=k}else{x=v;if(this.prefs.show_insertions){x*=2}}}return x},draw_read:function(U,P,L,Z,A,T,I,F,E){U.textAlign="center";var S=this,z=[Z,A],O=0,V=0,R=0,x=U.canvas.manager.char_width_px;var ae=[];if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>x){R=Math.round(L/2)}if(!I){I=[[0,F.length]]}for(var M=0,X=I.length;M<X;M++){var J=I[M],B="MIDNSHP=X"[J[0]],N=J[1];if(B==="H"||B==="S"){O-=N}var G=T+O,ad=Math.floor(Math.max(0,(G-Z)*L)),H=Math.floor(Math.max(0,(G+N-Z)*L));if(ad===H){H+=1}switch(B){case"H":break;case"S":case"M":case"=":if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(R>0){U.fillStyle=this.prefs.block_color;U.fillRect(ad-R,E+1,H-ad,9);U.fillStyle=g;for(var ab=0,y=Q.length;ab<y;ab++){if(this.prefs.show_differences&&this.ref_seq){var K=this.ref_seq[G-Z+ab];if(!K||K.toLowerCase()===Q[ab].toLowerCase()){continue}}if(G+ab>=Z&&G+ab<=A){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac,E+9)}}}else{U.fillStyle=this.prefs.block_color;U.fillRect(ad,E+4,H-ad,e)}}V+=N;O+=N;break;case"N":U.fillStyle=g;U.fillRect(ad-R,E+5,H-ad,1);O+=N;break;case"D":U.fillStyle="red";U.fillRect(ad-R,E+4,H-ad,3);O+=N;break;case"P":break;case"I":var Y=ad-R;if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(this.prefs.show_insertions){var D=ad-(H-ad)/2;if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>x){U.fillStyle="yellow";U.fillRect(D-R,E-9,H-ad,9);ae[ae.length]={type:"triangle",data:[Y,E+4,5]};U.fillStyle=g;switch(compute_overlap([G,G+N],z)){case (OVERLAP_START):Q=Q.slice(Z-G);break;case (OVERLAP_END):Q=Q.slice(0,G-A);break;case (CONTAINED_BY):break;case (CONTAINS):Q=Q.slice(Z-G,G-A);break}for(var ab=0,y=Q.length;ab<y;ab++){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac-(H-ad)/2,E)}}else{U.fillStyle="yellow";U.fillRect(D,E+(this.mode!=="Dense"?2:5),H-ad,(P!=="Dense"?e:r))}}else{if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>x){ae.push({type:"text",data:[Q.length,Y,E+9]})}else{}}}V+=N;break;case"X":V+=N;break}}U.fillStyle="yellow";var aa,C,af;for(var W=0;W<ae.length;W++){aa=ae[W];C=aa.type;af=aa.data;if(C==="text"){U.save();U.font="bold "+U.font;U.fillText(af[0],af[1],af[2]);U.restore()}else{if(C=="triangle"){p(U,af[0],af[1],af[2])}}}},draw_element:function(Q,L,D,A,T,y,H,R,O){var G=D[0],P=D[1],z=D[2],I=D[3],C=Math.floor(Math.max(0,(P-T)*H)),E=Math.ceil(Math.min(O,Math.max(0,(z-T)*H))),B=(L==="Dense"?0:(0+A))*R,U=this.prefs.block_color,F=this.prefs.label_color,N=0;if((L==="Pack"||this.mode==="Auto")&&H>Q.canvas.manager.char_width_px){var N=Math.round(H/2)}Q.fillStyle=U;if(D[5] instanceof Array){var M=Math.floor(Math.max(0,(D[4][0]-T)*H)),K=Math.ceil(Math.min(O,Math.max(0,(D[4][1]-T)*H))),J=Math.floor(Math.max(0,(D[5][0]-T)*H)),x=Math.ceil(Math.min(O,Math.max(0,(D[5][1]-T)*H)));if(D[4][1]>=T&&D[4][0]<=y&&D[4][2]){this.draw_read(Q,L,H,T,y,D[4][0],D[4][2],D[4][3],B)}if(D[5][1]>=T&&D[5][0]<=y&&D[5][2]){this.draw_read(Q,L,H,T,y,D[5][0],D[5][2],D[5][3],B)}if(J>K){Q.fillStyle=g;o(Q,K-N,B+5,J-N,B+5)}}else{Q.fillStyle=U;this.draw_read(Q,L,H,T,y,P,D[4],D[5],B)}if(L==="Pack"&&P>T&&I!=="."){Q.fillStyle=this.prefs.label_color;var S=1;if(S===0&&C-Q.measureText(I).width<0){Q.textAlign="left";Q.fillText(I,E+j-N,B+8)}else{Q.textAlign="right";Q.fillText(I,C-j-N,B+8)}Q.fillStyle=U}return[0,0]}});w.Scaler=d;w.SummaryTreePainter=u;w.LinePainter=b;w.LinkedFeaturePainter=q;w.ReadPainter=s};(function(d){var c={};var b=function(e){return c[e]};var a=function(f,g){var e={};g(b,e);c[f]=e};a("class",class_module);a("slotting",slotting_module);a("painters",painters_module);a("trackster",trackster_module);for(key in c.trackster){d[key]=c.trackster[key]}})(window); \ No newline at end of file diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef static/scripts/packed/trackster_ui.js --- a/static/scripts/packed/trackster_ui.js +++ b/static/scripts/packed/trackster_ui.js @@ -1,1 +1,1 @@ -var add_bookmark=function(b,a){var g=$("#bookmarks-container"),d=$("<div/>").addClass("bookmark").appendTo(g),c=$("<div/>").addClass("delete-icon-container").appendTo(d).click(function(){d.slideUp("fast");d.remove();view.has_changes=true;return false}),e=$("<a href=''/>").addClass("icon-button delete").appendTo(c),f=$("<div/>").addClass("position").appendTo(d),h=$("<a href=''/>").text(b).appendTo(f).click(function(){view.go_to(b);return false});annotation_div=get_editable_text_elt(a,true).addClass("annotation").appendTo(d);view.has_changes=true;return d};var addable_objects={LineTrack:LineTrack,FeatureTrack:FeatureTrack,ReadTrack:ReadTrack,DrawableGroup:DrawableGroup};var track_from_dict=function(c,b){var a=new addable_objects[c.track_type](c.name,view,b,c.hda_ldda,c.dataset_id,c.prefs,c.filters,c.tool);if(c.mode){a.change_mode(c.mode)}return a};var drawable_collection_from_dict=function(f,a){var e=new addable_objects[f.obj_type](f.name,view,a,f.prefs,view.viewport_container,view);for(var d=0;d<f.drawables.length;d++){var b=f.drawables[d],c;if(b.track_type){c=track_from_dict(b,e)}else{c=drawable_collection_from_dict(b)}e.add_drawable(c);e.content_div.append(c.container_div)}return e};var drawable_from_dict=function(b,a){return(b.track_type?track_from_dict(b,a):drawable_collection_from_dict(b,a))};var create_visualization=function(b,e,g,c,a,d,f){view=new View(b,e,g,c);view.editor=true;$.when(view.load_chroms_deferred).then(function(){if(a){var k=a.chrom,p=a.start,h=a.end,m=a.overview;if(k&&(p!==undefined)&&h){view.change_chrom(k,p,h)}}if(d){var o;for(var j=0;j<d.length;j++){o=d[j];view.add_drawable(drawable_from_dict(o,view))}}var n;for(var j=0;j<view.drawables.length;j++){if(view.drawables[j].name===m){view.set_overview(view.drawables[j]);break}}if(f){var l;for(var j=0;j<f.length;j++){l=f[j];add_bookmark(l.position,l.annotation)}}view.has_changes=false});return view};var init_keyboard_nav=function(a){$(document).keydown(function(b){if($(b.srcElement).is(":input")){return}switch(b.which){case 37:a.move_fraction(0.25);break;case 38:var c=Math.round(a.viewport_container.height()/15);a.viewport_container.scrollTo("-="+c+"px");break;case 39:a.move_fraction(-0.25);break;case 40:var c=Math.round(a.viewport_container.height()/15);a.viewport_container.scrollTo("+="+c+"px");break}})}; \ No newline at end of file +var add_bookmark=function(b,a){var g=$("#bookmarks-container"),d=$("<div/>").addClass("bookmark").appendTo(g),c=$("<div/>").addClass("delete-icon-container").appendTo(d).click(function(){d.slideUp("fast");d.remove();view.has_changes=true;return false}),e=$("<a href=''/>").addClass("icon-button delete").appendTo(c),f=$("<div/>").addClass("position").appendTo(d),h=$("<a href=''/>").text(b).appendTo(f).click(function(){view.go_to(b);return false});annotation_div=get_editable_text_elt(a,true).addClass("annotation").appendTo(d);view.has_changes=true;return d};var addable_objects={LineTrack:LineTrack,FeatureTrack:FeatureTrack,VcfTrack:VcfTrack,ReadTrack:ReadTrack,DrawableGroup:DrawableGroup};var track_from_dict=function(c,b){var a=new addable_objects[c.track_type](c.name,view,b,c.hda_ldda,c.dataset_id,c.prefs,c.filters,c.tool);if(c.mode){a.change_mode(c.mode)}return a};var drawable_collection_from_dict=function(f,a){var e=new addable_objects[f.obj_type](f.name,view,a,f.prefs,view.viewport_container,view);for(var d=0;d<f.drawables.length;d++){var b=f.drawables[d],c;if(b.track_type){c=track_from_dict(b,e)}else{c=drawable_collection_from_dict(b)}e.add_drawable(c);e.content_div.append(c.container_div)}return e};var drawable_from_dict=function(b,a){return(b.track_type?track_from_dict(b,a):drawable_collection_from_dict(b,a))};var create_visualization=function(b,e,g,c,a,d,f){view=new View(b,e,g,c);view.editor=true;$.when(view.load_chroms_deferred).then(function(){if(a){var k=a.chrom,p=a.start,h=a.end,m=a.overview;if(k&&(p!==undefined)&&h){view.change_chrom(k,p,h)}}if(d){var o;for(var j=0;j<d.length;j++){o=d[j];view.add_drawable(drawable_from_dict(o,view))}}var n;for(var j=0;j<view.drawables.length;j++){if(view.drawables[j].name===m){view.set_overview(view.drawables[j]);break}}if(f){var l;for(var j=0;j<f.length;j++){l=f[j];add_bookmark(l.position,l.annotation)}}view.has_changes=false});return view};var init_keyboard_nav=function(a){$(document).keydown(function(b){if($(b.srcElement).is(":input")){return}switch(b.which){case 37:a.move_fraction(0.25);break;case 38:var c=Math.round(a.viewport_container.height()/15);a.viewport_container.scrollTo("-="+c+"px");break;case 39:a.move_fraction(-0.25);break;case 40:var c=Math.round(a.viewport_container.height()/15);a.viewport_container.scrollTo("+="+c+"px");break}})}; \ No newline at end of file diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef static/scripts/trackster.js --- a/static/scripts/trackster.js +++ b/static/scripts/trackster.js @@ -3526,7 +3526,28 @@ var VcfTrack = function(name, view, container, hda_ldda, dataset_id, prefs, filters) { FeatureTrack.call(this, name, view, container, hda_ldda, dataset_id, prefs, filters); - this.painter = painters.VariantPainter; + + this.config = new DrawableConfig( { + track: this, + params: [ + { key: 'name', label: 'Name', type: 'text', default_value: name }, + { key: 'block_color', label: 'Block color', type: 'color', default_value: get_random_color() }, + { key: 'label_color', label: 'Label color', type: 'color', default_value: 'black' }, + { key: 'show_insertions', label: 'Show insertions', type: 'bool', default_value: false }, + { key: 'show_counts', label: 'Show summary counts', type: 'bool', default_value: true }, + { key: 'mode', type: 'string', default_value: this.mode, hidden: true }, + ], + saved_values: prefs, + onchange: function() { + this.track.set_name(this.track.prefs.name); + this.track.tile_cache.clear(); + this.track.request_draw(); + } + }); + this.prefs = this.config.values; + + + this.painter = painters.ReadPainter; }; extend(VcfTrack.prototype, Drawable.prototype, TiledTrack.prototype, FeatureTrack.prototype); @@ -3605,6 +3626,7 @@ exports.LineTrack = LineTrack; exports.FeatureTrack = FeatureTrack; exports.ReadTrack = ReadTrack; +exports.VcfTrack = VcfTrack; // End trackster_module encapsulation }; @@ -4173,20 +4195,20 @@ * Height of a single row, depends on mode */ get_row_height: function() { - var mode = this.mode, y_scale; + var mode = this.mode, height; if (mode === "Dense") { - y_scale = DENSE_TRACK_HEIGHT; + height = DENSE_TRACK_HEIGHT; } else if (mode === "no_detail") { - y_scale = NO_DETAIL_TRACK_HEIGHT; + height = NO_DETAIL_TRACK_HEIGHT; } else if (mode === "Squish") { - y_scale = SQUISH_TRACK_HEIGHT; + height = SQUISH_TRACK_HEIGHT; } else { // mode === "Pack" - y_scale = PACK_TRACK_HEIGHT; + height = PACK_TRACK_HEIGHT; } - return y_scale; + return height; }, /** @@ -4212,7 +4234,7 @@ ctx.globalAlpha = this.alpha_scaler.gen_val(feature); // In dense mode, put all data in top slot. - if (mode == "Dense") { + if (mode === "Dense") { slot = 1; } @@ -4375,65 +4397,6 @@ } }); - -var VariantPainter = function(data, view_start, view_end, prefs, mode, alpha_scaler, height_scaler) { - FeaturePainter.call(this, data, view_start, view_end, prefs, mode, alpha_scaler, height_scaler); -} - -extend(VariantPainter.prototype, FeaturePainter.prototype, { - draw_element: function(ctx, mode, feature, slot, tile_low, tile_high, w_scale, y_scale, width) { - var feature = data[i], - feature_uid = feature[0], - feature_start = feature[1], - feature_end = feature[2], - feature_name = feature[3], - // All features need a start, end, and vertical center. - f_start = Math.floor( Math.max(0, (feature_start - tile_low) * w_scale) ), - f_end = Math.ceil( Math.min(width, Math.max(0, (feature_end - tile_low) * w_scale)) ), - y_center = (mode === "Dense" ? 0 : (0 + slot)) * y_scale, - thickness, y_start, thick_start = null, thick_end = null; - - if (no_label) { - ctx.fillStyle = block_color; - ctx.fillRect(f_start + left_offset, y_center + 5, f_end - f_start, 1); - } - else { // Show blocks, labels, etc. - // Unpack. - var ref_base = feature[4], alt_base = feature[5], qual = feature[6]; - - // Draw block for entry. - thickness = 9; - y_start = 1; - ctx.fillRect(f_start + left_offset, y_center, f_end - f_start, thickness); - - // Add label for entry. - if (mode !== "Dense" && feature_name !== undefined && feature_start > tile_low) { - // Draw label - ctx.fillStyle = label_color; - if (tile_low === 0 && f_start - ctx.measureText(feature_name).width < 0) { - ctx.textAlign = "left"; - ctx.fillText(feature_name, f_end + 2 + left_offset, y_center + 8); - } else { - ctx.textAlign = "right"; - ctx.fillText(feature_name, f_start - 2 + left_offset, y_center + 8); - } - ctx.fillStyle = block_color; - } - - // Show additional data on block. - var vcf_label = ref_base + " / " + alt_base; - if (feature_start > tile_low && ctx.measureText(vcf_label).width < (f_end - f_start)) { - ctx.fillStyle = "white"; - ctx.textAlign = "center"; - ctx.fillText(vcf_label, left_offset + f_start + (f_end-f_start)/2, y_center + 8); - ctx.fillStyle = block_color; - } - } - - return [f_start, f_end]; - } -}); - var ReadPainter = function(data, view_start, view_end, prefs, mode, alpha_scaler, height_scaler, ref_seq) { FeaturePainter.call(this, data, view_start, view_end, prefs, mode, alpha_scaler, height_scaler); this.ref_seq = (ref_seq ? ref_seq.data : null); @@ -4443,23 +4406,23 @@ extend(ReadPainter.prototype, FeaturePainter.prototype, { /** - * Returns y_scale based on mode. + * Returns height based on mode. */ get_row_height: function() { - var y_scale, mode = this.mode; + var height, mode = this.mode; if (mode === "Dense") { - y_scale = DENSE_TRACK_HEIGHT; + height = DENSE_TRACK_HEIGHT; } else if (mode === "Squish") { - y_scale = SQUISH_TRACK_HEIGHT; + height = SQUISH_TRACK_HEIGHT; } else { // mode === "Pack" - y_scale = PACK_TRACK_HEIGHT; + height = PACK_TRACK_HEIGHT; if (this.prefs.show_insertions) { - y_scale *= 2; + height *= 2; } } - return y_scale; + return height; }, /** @@ -4585,7 +4548,7 @@ draw_last[draw_last.length] = {type: "triangle", data: [insert_x_coord, y_center + 4, 5]}; ctx.fillStyle = CONNECTOR_COLOR; // Based on overlap b/t sequence and tile, get sequence to be drawn. - switch(seq_tile_overlap) { + switch( compute_overlap( [seq_start, seq_start + cig_len], tile_region ) ) { case(OVERLAP_START): seq = seq.slice(tile_low-seq_start); break; @@ -4616,7 +4579,7 @@ else { if ( (mode === "Pack" || this.mode === "Auto") && orig_seq !== undefined && w_scale > char_width_px) { // Show insertions with a single number at the insertion point. - draw_last[draw_last.length] = {type: "text", data: [seq.length, insert_x_coord, y_center + 9]}; + draw_last.push( { type: "text", data: [seq.length, insert_x_coord, y_center + 9] } ); } else { // TODO: probably can merge this case with code above. @@ -4703,7 +4666,7 @@ ctx.fillStyle = block_color; this.draw_read(ctx, mode, w_scale, tile_low, tile_high, feature_start, feature[4], feature[5], y_center); } - if (mode === "Pack" && feature_start > tile_low) { + if (mode === "Pack" && feature_start > tile_low && feature_name !== ".") { // Draw label. ctx.fillStyle = this.prefs.label_color; // FIXME: eliminate tile_index @@ -4728,7 +4691,6 @@ exports.LinePainter = LinePainter; exports.LinkedFeaturePainter = LinkedFeaturePainter; exports.ReadPainter = ReadPainter; -exports.VariantPainter = VariantPainter; // End painters_module encapsulation }; diff -r ca2b29f0955e00473e82ea2893bb954a4fecd21f -r 22d844537368bff2acb8eb50bce6561a673002ef static/scripts/trackster_ui.js --- a/static/scripts/trackster_ui.js +++ b/static/scripts/trackster_ui.js @@ -31,7 +31,7 @@ /** * Objects that can be added to a view. */ -var addable_objects = { "LineTrack": LineTrack, "FeatureTrack": FeatureTrack, "ReadTrack": ReadTrack, "DrawableGroup": DrawableGroup }; +var addable_objects = { "LineTrack": LineTrack, "FeatureTrack": FeatureTrack, "VcfTrack": VcfTrack, "ReadTrack": ReadTrack, "DrawableGroup": DrawableGroup }; /** * Decode a track from a dictionary. Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket