3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/10829b9c5086/ changeset: 10829b9c5086 user: jgoecks date: 2012-07-24 20:07:06 summary: Trackster: only draw connector when both mates of a read are drawn; this prevents spurious connectors from being drawn but prevents connectors from being drawn across tile boundaries. affected #: 1 file diff -r cb9272041d954762664dd12f917619dbd6a48356 -r 10829b9c5086a09b80b0c592d9a289b65d723fcf static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -6042,18 +6042,30 @@ var b1_start = Math.floor( Math.max(0, (feature[4][0] - tile_low) * w_scale) ), b1_end = Math.ceil( Math.min(width, Math.max(0, (feature[4][1] - tile_low) * w_scale)) ), b2_start = Math.floor( Math.max(0, (feature[5][0] - tile_low) * w_scale) ), - b2_end = Math.ceil( Math.min(width, Math.max(0, (feature[5][1] - tile_low) * w_scale)) ); + b2_end = Math.ceil( Math.min(width, Math.max(0, (feature[5][1] - tile_low) * w_scale)) ), + connector = true; // Draw left/forward read. if (feature[4][1] >= tile_low && feature[4][0] <= tile_high && feature[4][2]) { this.draw_read(ctx, mode, w_scale, y_center, tile_low, tile_high, feature[4][0], feature[4][2], feature[4][3], feature[4][4]); } + else { + connector = false; + } + // Draw right/reverse read. if (feature[5][1] >= tile_low && feature[5][0] <= tile_high && feature[5][2]) { this.draw_read(ctx, mode, w_scale, y_center, tile_low, tile_high, feature[5][0], feature[5][2], feature[5][3], feature[5][4]); } - // Draw connector. - if (b2_start > b1_end) { + else { + connector = false; + } + + // Draw connector if both reads were drawn. + // TODO: currently, there is no way to connect reads drawn on different tiles; to connect reads on different tiles, data manager + // code is needed to join mate pairs from different regions. Alternatively, requesting multiple regions of data at once would + // make it possible to put together more easily. + if (connector && b2_start > b1_end) { ctx.fillStyle = CONNECTOR_COLOR; dashedLine(ctx, b1_end - gap, y_center + 5, b2_start - gap, y_center + 5); } https://bitbucket.org/galaxy/galaxy-central/changeset/339f886d3ffa/ changeset: 339f886d3ffa user: jgoecks date: 2012-07-24 20:21:40 summary: Rename paramamonster as sweepster and use bootstrap tooltips in sweepster. affected #: 8 files diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -476,9 +476,9 @@ return self.tracks_grid( trans, **kwargs ) @web.expose - def paramamonster( self, trans, id=None, hda_ldda=None, dataset_id=None, regions=None ): + def sweepster( self, trans, id=None, hda_ldda=None, dataset_id=None, regions=None ): """ - Creates a paramamonster visualization using the incoming parameters. If id is available, + Creates a sweepster visualization using the incoming parameters. If id is available, get the visualization with the given id; otherwise, create a new visualization using a given dataset and regions. """ @@ -505,7 +505,7 @@ viz_config[ 'tool' ] = tool.to_dict( trans, for_display=True ) viz_config[ 'dataset' ] = dataset.get_api_value() - return trans.fill_template_mako( "visualization/paramamonster.mako", config=viz_config ) + return trans.fill_template_mako( "visualization/sweepster.mako", config=viz_config ) @web.expose def circster( self, trans, id, **kwargs ): diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 static/scripts/packed/viz/paramamonster.js --- a/static/scripts/packed/viz/paramamonster.js +++ /dev/null @@ -1,1 +0,0 @@ -var ToolInputsSettings=Backbone.Model.extend({defaults:{inputs:null,values:null}});var ToolParameterTree=Backbone.RelationalModel.extend({defaults:{tool:null,tree_data:null},initialize:function(b){var a=this;this.get("tool").get("inputs").each(function(c){if(!c.get_samples()){return}c.on("change:min change:max change:num_samples",function(d){if(d.get("in_ptree")){a.set_tree_data()}},a);c.on("change:in_ptree",function(d){if(d.get("in_ptree")){a.add_param(d)}else{a.remove_param(d)}a.set_tree_data()},a)});if(b.config){_.each(b.config,function(d){var c=a.get("tool").get("inputs").find(function(e){return e.get("name")===d.name});a.add_param(c);c.set(d)})}},add_param:function(a){if(a.get("ptree_index")){return}a.set("in_ptree",true);a.set("ptree_index",this.get_tree_params().length)},remove_param:function(a){a.set("in_ptree",false);a.set("ptree_index",null);_(this.get_tree_params()).each(function(b,c){b.set("ptree_index",c+1)})},set_tree_data:function(){var b=_.map(this.get_tree_params(),function(d){return{param:d,samples:d.get_samples()}});var a=0,c=function(g,d){var i=g[d],h=i.param,f=h.get("label"),e=i.samples;if(g.length-1===d){return _.map(e,function(j){return{id:a++,name:j,param:h,value:j}})}return _.map(e,function(j){return{id:a++,name:j,param:h,value:j,children:c(g,d+1)}})};this.set("tree_data",{name:"Root",id:a++,children:(b.length!==0?c(b,0):null)})},get_tree_params:function(){return _(this.get("tool").get("inputs").where({in_ptree:true})).sortBy(function(a){return a.get("ptree_index")})},get_num_leaves:function(){return this.get_tree_params().reduce(function(a,b){return a*b.get_samples().length},1)},get_node_settings:function(e){var c=this.get("tool").get_inputs_dict();var f=e.parent;if(f){while(f.depth!==0){c[f.param.get("name")]=f.value;f=f.parent}}var a=this,b=function(h,g){if(h.param){g[h.param.get("name")]=h.value}if(!h.children){return new ToolInputsSettings({inputs:a.get("tool").get("inputs"),values:g})}else{return _.flatten(_.map(h.children,function(i){return b(i,_.clone(g))}))}},d=b(e,c);if(!_.isArray(d)){d=[d]}return d},get_connected_nodes:function(c){var d=function(e){if(!e.children){return e}else{return _.flatten([e,_.map(e.children,function(f){return d(f)})])}};var b=[],a=c.parent;while(a){b.push(a);a=a.parent}return _.flatten([b,d(c)])},get_leaf:function(b){var c=this.get("tree_data"),a=function(d){return _.find(d,function(e){return b[e.param.get("name")]===e.value})};while(c.children){c=a(c.children)}return c},toJSON:function(){return this.get_tree_params().map(function(a){return{name:a.get("name"),min:a.get("min"),max:a.get("max"),num_samples:a.get("num_samples")}})}});var ParamaMonsterTrack=Backbone.RelationalModel.extend({defaults:{track:null,mode:"Pack",settings:null,regions:null},relations:[{type:Backbone.HasMany,key:"regions",relatedModel:"GenomeRegion"}],initialize:function(a){if(a.track){var b=_.extend({data_url:galaxy_paths.get("raw_data_url"),converted_datasets_state_url:galaxy_paths.get("dataset_state_url")},a.track);this.set("track",object_from_template(b,{},null))}},same_settings:function(a){var b=this.get("settings"),c=a.get("settings");for(var d in b){if(!c[d]||b[d]!==c[d]){return false}}return true},toJSON:function(){return{track:this.get("track").to_dict(),settings:this.get("settings"),regions:this.get("regions")}}});var TrackCollection=Backbone.Collection.extend({model:ParamaMonsterTrack});var ParamaMonsterVisualization=Visualization.extend({defaults:_.extend({},Visualization.prototype.defaults,{dataset:null,tool:null,parameter_tree:null,regions:null,tracks:null,default_mode:"Pack"}),relations:[{type:Backbone.HasOne,key:"dataset",relatedModel:"Dataset"},{type:Backbone.HasOne,key:"tool",relatedModel:"Tool"},{type:Backbone.HasMany,key:"regions",relatedModel:"GenomeRegion"},{type:Backbone.HasMany,key:"tracks",relatedModel:"ParamaMonsterTrack"}],initialize:function(a){var b=this.get("tool").copy(true);this.set("tool_with_samplable_inputs",b);this.set("parameter_tree",new ToolParameterTree({tool:b,config:a.tree_config}))},add_track:function(a){this.get("tracks").add(a)},toJSON:function(){return{id:this.get("id"),title:"Parameter exploration for dataset '"+this.get("dataset").get("name")+"'",type:"paramamonster",dataset_id:this.get("dataset").id,tool_id:this.get("tool").id,regions:this.get("regions").toJSON(),tree_config:this.get("parameter_tree").toJSON(),tracks:this.get("tracks").toJSON()}}});var ParamaMonsterTrackView=Backbone.View.extend({tagName:"tr",TILE_LEN:250,initialize:function(a){this.canvas_manager=a.canvas_manager;this.render();this.model.on("change:track change:mode",this.draw_tiles,this)},render:function(){var f=this.model.get("settings"),b=f.get("values"),d=$("<td/>").addClass("settings").appendTo(this.$el),c=$("<div/>").addClass("track-info").hide().appendTo(d);c.append($("<div/>").css("font-weight","bold").text("Track Settings"));f.get("inputs").each(function(h){c.append(h.get("label")+": "+b[h.get("name")]+"<br/>")});var a=this,g=$("<button/>").appendTo(c).text("Run on complete dataset").click(function(){c.toggle();a.trigger("run_on_dataset",f)});var e=create_icon_buttons_menu([{title:"Settings",icon_class:"gear track-settings",on_click:function(){c.toggle()}},{title:"Remove",icon_class:"cross-circle",on_click:function(){a.$el.remove();$(".tooltip").remove()}}]);d.prepend(e.$el);this.model.get("regions").each(function(){a.$el.append($("<td/>").addClass("tile").html($("<img/>").attr("src",galaxy_paths.get("image_path")+"/loading_large_white_bg.gif")))});if(this.model.get("track")){this.draw_tiles()}},draw_tiles:function(){var b=this,a=this.model.get("track"),d=this.model.get("regions"),c=this.$el.find("td.tile");if(!a){return}$.when(a.data_manager.data_is_ready()).then(function(e){d.each(function(h,g){var f=h.length()/b.TILE_LEN,j=1/f,i=b.model.get("mode");$.when(a.data_manager.get_data(h,i,f,{})).then(function(l){var k=b.canvas_manager.new_canvas();k.width=b.TILE_LEN;k.height=a.get_canvas_height(l,i,j,k.width);a.draw_tile(l,k.getContext("2d"),i,f,h,j);$(c[g]).empty().append(k)})})})}});var ToolInputValOrSweepView=Backbone.View.extend({number_input_template:'<div class="form-row-input sweep"><input class="min" type="text" size="6" value="<%= min %>"> - <input class="max" type="text" size="6" value="<%= max %>"> samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>"></div>',select_input_template:'<div class="form-row-input sweep"><%= options %></div>',initialize:function(a){this.$el=a.tool_row;this.render()},render:function(){var b=this.model,f=b.get("type"),h=this.$el.find(".form-row-input"),d=null;h.find(":input").change(function(){b.set("value",$(this).val())});if(f==="number"){d=$(_.template(this.number_input_template,this.model.toJSON()))}else{if(f==="select"){var c=_.map(this.$el.find("select option"),function(i){return $(i).val()}),e=c.join(", ");d=$(_.template(this.select_input_template,{options:e}))}}d.insertAfter(h);var a=this,g=create_icon_buttons_menu([{title:"Add parameter to tree",icon_class:"plus-button",on_click:function(){b.set("in_ptree",true);h.hide();d.show();$(this).hide();a.$el.find(".icon-button.toggle").show()}},{title:"Remove parameter from tree",icon_class:"toggle",on_click:function(){b.set("in_ptree",false);d.hide();h.show();$(this).hide();a.$el.find(".icon-button.plus-button").show()}}],{});this.$el.prepend(g.$el);if(b.get("in_ptree")){h.hide();a.$el.find(".icon-button.plus-button").hide()}else{a.$el.find(".icon-button.toggle").hide();d.hide()}_.each(["min","max","num_samples"],function(i){d.find("."+i).change(function(){b.set(i,parseFloat($(this).val()))})})}});var ToolParameterTreeDesignView=Backbone.View.extend({className:"tree-design",initialize:function(a){this.render()},render:function(){var c=new ToolFormView({model:this.model.get("tool")});c.render();this.$el.append(c.$el);var b=this,a=b.model.get("tool").get("inputs");this.$el.find(".form-row").not(".form-actions").each(function(d){var e=new ToolInputValOrSweepView({model:a.at(d),tool_row:$(this)})})}});var ToolParameterTreeView=Backbone.View.extend({className:"tool-parameter-tree",initialize:function(a){this.model.on("change:tree_data",this.render,this)},render:function(){this.$el.children().remove();var i=this.model.get_tree_params();if(!i.length){return}this.width=100*(2+i.length);this.height=15*this.model.get_num_leaves();var h=this;var g=d3.layout.cluster().size([this.height,this.width-160]);var c=d3.svg.diagonal().projection(function(j){return[j.y,j.x]});var a=g.nodes(this.model.get("tree_data"));var d=_.uniq(_.pluck(a,"y"));_.each(i,function(l,k){var j=d[k+1],m=$("#center").position().left;h.$el.append($("<div>").addClass("label").text(l.get("label")).css("left",j+m))});var b=d3.select(this.$el[0]).append("svg").attr("width",this.width).attr("height",this.height+30).append("g").attr("transform","translate(40, 20)");var f=b.selectAll("path.link").data(g.links(a)).enter().append("path").attr("class","link").attr("d",c);var e=b.selectAll("g.node").data(a).enter().append("g").attr("class","node").attr("transform",function(j){return"translate("+j.y+","+j.x+")"}).on("mouseover",function(k){var j=_.pluck(h.model.get_connected_nodes(k),"id");e.filter(function(l){return _.find(j,function(m){return m===l.id})!==undefined}).style("fill","#f00")}).on("mouseout",function(){e.style("fill","#000")});e.append("circle").attr("r",9);e.append("text").attr("dx",function(j){return j.children?-12:12}).attr("dy",3).attr("text-anchor",function(j){return j.children?"end":"start"}).text(function(j){return j.name})}});var ParamaMonsterVisualizationView=Backbone.View.extend({className:"paramamonster",helpText:"<div><h4>Getting Started</h4><ol><li>Create a parameter tree by using the icons next to the tool's parameter names to add or remove parameters.<li>Adjust the tree by using parameter inputs to select min, max, and number of samples<li>Run the tool with different settings by clicking on tree nodes</ol></div>",initialize:function(b){this.canvas_manager=new CanvasManager(this.$el.parents("body"));this.tool_param_tree_view=new ToolParameterTreeView({model:this.model.get("parameter_tree")});this.track_collection_container=$("<table/>").addClass("tracks");this.model.get("parameter_tree").on("change:tree_data",this.handle_node_clicks,this);var a=this;this.model.get("tracks").each(function(c){c.get("track").view=a});this.block_color=get_random_color();this.reverse_strand_color=get_random_color([this.block_color,"#ffffff"])},render:function(){var g=new ToolParameterTreeDesignView({model:this.model.get("parameter_tree")});$("#left").append(g.$el);var j=this,d=j.model.get("regions"),h=$("<tr/>").appendTo(this.track_collection_container);d.each(function(k){h.append($("<th>").text(k.toString()))});h.children().first().attr("colspan",2);var e=$("<div>").addClass("tiles");$("#right").append(e.append(this.track_collection_container));j.model.get("tracks").each(function(k){j.add_track(k)});var i=$(this.helpText).addClass("help"),f=create_icon_buttons_menu([{title:"Close",icon_class:"cross-circle",on_click:function(){$(".tooltip").remove();i.remove()}}]);i.prepend(f.$el.css("float","right"));$("#center").append(i);this.tool_param_tree_view.render();$("#center").append(this.tool_param_tree_view.$el);this.handle_node_clicks();var c=create_icon_buttons_menu([{icon_class:"chevron-expand",title:"Set display mode"},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location="${h.url_for( controller='visualization', action='list' )}"}}],{tooltip_config:{placement:"bottom"}});var b=["Squish","Pack"],a={};_.each(b,function(k){a[k]=function(){j.model.set("default_mode",k);j.model.get("tracks").each(function(l){l.set("mode",k)})}});make_popupmenu(c.$el.find(".chevron-expand"),a);c.$el.attr("style","float: right");$("#right .unified-panel-header-inner").append(c.$el)},run_tool_on_dataset:function(b){var a=this.model.get("tool"),d=a.get("name"),c=this.model.get("dataset");a.set_input_values(b.get("values"));$.when(a.rerun(c)).then(function(e){});show_modal("Running "+d+" on complete dataset",d+" is running on dataset '"+c.get("name")+"'. Outputs are in the dataset's history.",{Ok:function(){hide_modal()}})},add_track:function(d){var b=this,c=this.model.get("parameter_tree");b.model.add_track(d);var a=new ParamaMonsterTrackView({model:d,canvas_manager:b.canvas_manager});a.on("run_on_dataset",b.run_tool_on_dataset,b);b.track_collection_container.append(a.$el);a.$el.hover(function(){var f=c.get_leaf(d.get("settings").get("values"));var e=_.pluck(c.get_connected_nodes(f),"id");d3.select(b.tool_param_tree_view.$el[0]).selectAll("g.node").filter(function(g){return _.find(e,function(h){return h===g.id})!==undefined}).style("fill","#f00")},function(){d3.select(b.tool_param_tree_view.$el[0]).selectAll("g.node").style("fill","#000")});return d},handle_node_clicks:function(){var a=this,b=this.model.get("parameter_tree"),d=this.model.get("regions"),c=d3.select(this.tool_param_tree_view.$el[0]).selectAll("g.node");c.on("click",function(k,g){var f=a.model.get("tool"),j=a.model.get("dataset"),h=b.get_node_settings(k),e=$.Deferred();if(h.length>=10){show_modal("Whoa there cowboy!","You clicked on a node to try "+a.model.get("tool").get("name")+" with "+h.length+" different combinations of settings. You can only run 10 jobs at a time.",{Ok:function(){hide_modal();e.resolve(false)}})}else{e.resolve(true)}$.when(e).then(function(i){if(!i){return}var l=_.map(h,function(m){var n=new ParamaMonsterTrack({settings:m,regions:d,mode:a.model.get("default_mode")});a.add_track(n);return n});_.each(l,function(n,m){setTimeout(function(){f.set_input_values(n.get("settings").get("values"));$.when(f.rerun(j,d)).then(function(p){var q=_.extend({data_url:galaxy_paths.get("raw_data_url"),converted_datasets_state_url:galaxy_paths.get("dataset_state_url")},p.first().get("track_config")),o=object_from_template(q,a,null);o.prefs.block_color=a.block_color;o.prefs.reverse_strand_color=a.reverse_strand_color;n.set("track",o)})},m*10000)})})})}}); \ No newline at end of file diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 static/scripts/viz/paramamonster.js --- a/static/scripts/viz/paramamonster.js +++ /dev/null @@ -1,939 +0,0 @@ -/** - * Visualization and components for ParamaMonster, a visualization for exploring a tool's parameter space via - * genomic visualization. - */ - -/** - * A collection of tool input settings. Object is useful for keeping a list of settings - * for future use without changing the input's value and for preserving inputs order. - */ -var ToolInputsSettings = Backbone.Model.extend({ - defaults: { - inputs: null, - values: null - } -}); - -/** - * Tree for a tool's parameters. - */ -var ToolParameterTree = Backbone.RelationalModel.extend({ - defaults: { - tool: null, - tree_data: null - }, - - initialize: function(options) { - // Set up tool parameters to work with tree. - var self = this; - this.get('tool').get('inputs').each(function(input) { - if (!input.get_samples()) { return; } - - // Listen for changes to input's attributes. - input.on('change:min change:max change:num_samples', function(input) { - if (input.get('in_ptree')) { - self.set_tree_data(); - } - }, self); - input.on('change:in_ptree', function(input) { - if (input.get('in_ptree')) { - self.add_param(input); - } - else { - self.remove_param(input); - } - self.set_tree_data(); - }, self); - }); - - // If there is a config, use it. - if (options.config) { - _.each(options.config, function(input_config) { - var input = self.get('tool').get('inputs').find(function(input) { - return input.get('name') === input_config.name; - }); - self.add_param(input); - input.set(input_config); - }); - } - }, - - add_param: function(param) { - // If parameter already present, do not add it. - if (param.get('ptree_index')) { return; } - - param.set('in_ptree', true); - param.set('ptree_index', this.get_tree_params().length); - }, - - remove_param: function(param) { - // Remove param from tree. - param.set('in_ptree', false); - param.set('ptree_index', null); - - // Update ptree indices for remaining params. - _(this.get_tree_params()).each(function(input, index) { - // +1 to use 1-based indexing. - input.set('ptree_index', index + 1); - }); - }, - - /** - * Sets tree data using tool's inputs. - */ - set_tree_data: function() { - // Get samples for each parameter. - var params_samples = _.map(this.get_tree_params(), function(param) { - return { - param: param, - samples: param.get_samples() - }; - }); - var node_id = 0, - // Creates tree data recursively. - create_tree_data = function(params_samples, index) { - var param_samples = params_samples[index], - param = param_samples.param, - param_label = param.get('label'), - settings = param_samples.samples; - - // Create leaves when last parameter setting is reached. - if (params_samples.length - 1 === index) { - return _.map(settings, function(setting) { - return { - id: node_id++, - name: setting, - param: param, - value: setting - }; - }); - } - - // Recurse to handle other parameters. - return _.map(settings, function(setting) { - return { - id: node_id++, - name: setting, - param: param, - value: setting, - children: create_tree_data(params_samples, index + 1) - }; - }); - }; - - this.set('tree_data', { - name: 'Root', - id: node_id++, - children: (params_samples.length !== 0 ? create_tree_data(params_samples, 0) : null) - }); - }, - - get_tree_params: function() { - // Filter and sort parameters to get list in tree. - return _(this.get('tool').get('inputs').where( {in_ptree: true} )) - .sortBy( function(input) { return input.get('ptree_index'); } ); - }, - - /** - * Returns number of leaves in tree. - */ - get_num_leaves: function() { - return this.get_tree_params().reduce(function(memo, param) { return memo * param.get_samples().length; }, 1); - }, - - /** - * Returns array of ToolInputsSettings objects based on a node and its subtree. - */ - get_node_settings: function(target_node) { - // -- Get fixed settings from tool and parent nodes. - - // Start with tool's settings. - var fixed_settings = this.get('tool').get_inputs_dict(); - - // Get fixed settings using node's parents. - var cur_node = target_node.parent; - if (cur_node) { - while(cur_node.depth !== 0) { - fixed_settings[cur_node.param.get('name')] = cur_node.value; - cur_node = cur_node.parent; - } - } - - // Walk subtree starting at clicked node to get full list of settings. - var self = this, - get_settings = function(node, settings) { - // Add setting for this node. Root node does not have a param, - // however. - if (node.param) { - settings[node.param.get('name')] = node.value; - } - - if (!node.children) { - // At leaf node, so return settings. - return new ToolInputsSettings({ - inputs: self.get('tool').get('inputs'), - values: settings - }); - } - else { - // At interior node: return list of subtree settings. - return _.flatten( _.map(node.children, function(c) { return get_settings(c, _.clone(settings)); }) ); - } - }, - all_settings = get_settings(target_node, fixed_settings); - - // If user clicked on leaf, settings is a single dict. Convert to array for simplicity. - if (!_.isArray(all_settings)) { all_settings = [ all_settings ]; } - - return all_settings; - }, - - /** - * Returns all nodes connected a particular node; this includes parents and children of the node. - */ - get_connected_nodes: function(node) { - var get_subtree_nodes = function(a_node) { - if (!a_node.children) { - return a_node; - } - else { - // At interior node: return subtree nodes. - return _.flatten( [a_node, _.map(a_node.children, function(c) { return get_subtree_nodes(c); })] ); - } - }; - - // Get node's parents. - var parents = [], - cur_parent = node.parent; - while(cur_parent) { - parents.push(cur_parent); - cur_parent = cur_parent.parent; - } - - return _.flatten([parents, get_subtree_nodes(node)]); - }, - - /** - * Returns the leaf that corresponds to a settings collection. - */ - get_leaf: function(settings) { - var cur_node = this.get('tree_data'), - find_child = function(children) { - return _.find(children, function(child) { - return settings[child.param.get('name')] === child.value; - }); - }; - - while (cur_node.children) { - cur_node = find_child(cur_node.children); - } - return cur_node; - }, - - /** - * Returns a list of parameters used in tree. - */ - toJSON: function() { - // FIXME: returning and jsonifying complete param causes trouble on the server side, - // so just use essential attributes for now. - return this.get_tree_params().map(function(param) { - return { - name: param.get('name'), - min: param.get('min'), - max: param.get('max'), - num_samples: param.get('num_samples') - }; - }); - } -}); - -var ParamaMonsterTrack = Backbone.RelationalModel.extend({ - defaults: { - track: null, - mode: 'Pack', - settings: null, - regions: null - }, - - relations: [ - { - type: Backbone.HasMany, - key: 'regions', - relatedModel: 'GenomeRegion' - } - ], - - initialize: function(options) { - if (options.track) { - // FIXME: find a better way to deal with needed URLs: - var track_config = _.extend({ - data_url: galaxy_paths.get('raw_data_url'), - converted_datasets_state_url: galaxy_paths.get('dataset_state_url') - }, options.track); - this.set('track', object_from_template(track_config, {}, null)); - } - }, - - same_settings: function(a_track) { - var this_settings = this.get('settings'), - other_settings = a_track.get('settings'); - for (var prop in this_settings) { - if (!other_settings[prop] || - this_settings[prop] !== other_settings[prop]) { - return false; - } - } - return true; - }, - - toJSON: function() { - return { - track: this.get('track').to_dict(), - settings: this.get('settings'), - regions: this.get('regions') - }; - } -}); - -var TrackCollection = Backbone.Collection.extend({ - model: ParamaMonsterTrack -}); - -/** - * ParamaMonster visualization model. - */ -var ParamaMonsterVisualization = Visualization.extend({ - defaults: _.extend({}, Visualization.prototype.defaults, { - dataset: null, - tool: null, - parameter_tree: null, - regions: null, - tracks: null, - default_mode: 'Pack' - }), - - relations: [ - { - type: Backbone.HasOne, - key: 'dataset', - relatedModel: 'Dataset' - }, - { - type: Backbone.HasOne, - key: 'tool', - relatedModel: 'Tool' - }, - { - type: Backbone.HasMany, - key: 'regions', - relatedModel: 'GenomeRegion' - }, - { - type: Backbone.HasMany, - key: 'tracks', - relatedModel: 'ParamaMonsterTrack' - } - // NOTE: cannot use relationship for parameter tree because creating tree is complex. - ], - - initialize: function(options) { - var tool_with_samplable_inputs = this.get('tool').copy(true); - this.set('tool_with_samplable_inputs', tool_with_samplable_inputs); - - this.set('parameter_tree', new ToolParameterTree({ - tool: tool_with_samplable_inputs, - config: options.tree_config - })); - }, - - add_track: function(track) { - this.get('tracks').add(track); - }, - - toJSON: function() { - // TODO: could this be easier by using relational models? - return { - id: this.get('id'), - title: 'Parameter exploration for dataset \'' + this.get('dataset').get('name') + '\'', - type: 'paramamonster', - dataset_id: this.get('dataset').id, - tool_id: this.get('tool').id, - regions: this.get('regions').toJSON(), - tree_config: this.get('parameter_tree').toJSON(), - tracks: this.get('tracks').toJSON() - }; - } -}); - -/** - * --- Views --- - */ - -/** - * ParamaMonster track view. - */ -var ParamaMonsterTrackView = Backbone.View.extend({ - tagName: 'tr', - - TILE_LEN: 250, - - initialize: function(options) { - this.canvas_manager = options.canvas_manager; - this.render(); - this.model.on('change:track change:mode', this.draw_tiles, this); - }, - - render: function() { - // Render settings icon and popup. - // TODO: use template. - var settings = this.model.get('settings'), - values = settings.get('values'), - settings_td = $('<td/>').addClass('settings').appendTo(this.$el), - settings_div = $('<div/>').addClass('track-info').hide().appendTo(settings_td); - settings_div.append( $('<div/>').css('font-weight', 'bold').text('Track Settings') ); - settings.get('inputs').each(function(input) { - settings_div.append( input.get('label') + ': ' + values[input.get('name')] + '<br/>'); - }); - var self = this, - run_on_dataset_button = $('<button/>').appendTo(settings_div).text('Run on complete dataset').click(function() { - settings_div.toggle(); - self.trigger('run_on_dataset', settings); - }); - var icon_menu = create_icon_buttons_menu([ - { - title: 'Settings', - icon_class: 'gear track-settings', - on_click: function() { - settings_div.toggle(); - } - }, - { - title: 'Remove', - icon_class: 'cross-circle', - on_click: function() { - self.$el.remove(); - $('.tooltip').remove(); - // TODO: remove track from viz collection. - } - } - ]); - settings_td.prepend(icon_menu.$el); - - // Render tile placeholders. - this.model.get('regions').each(function() { - self.$el.append($('<td/>').addClass('tile').html( - $('<img/>').attr('src', galaxy_paths.get('image_path') + '/loading_large_white_bg.gif') - )); - }); - - if (this.model.get('track')) { - this.draw_tiles(); - } - }, - - /** - * Draw tiles for regions. - */ - draw_tiles: function() { - var self = this, - track = this.model.get('track'), - regions = this.model.get('regions'), - tile_containers = this.$el.find('td.tile'); - - // Do nothing if track is not defined. - if (!track) { return; } - - // When data is ready, draw tiles. - $.when(track.data_manager.data_is_ready()).then(function(data_ok) { - // Draw tile for each region. - regions.each(function(region, index) { - var resolution = region.length() / self.TILE_LEN, - w_scale = 1/resolution, - mode = self.model.get('mode'); - $.when(track.data_manager.get_data(region, mode, resolution, {})).then(function(tile_data) { - var canvas = self.canvas_manager.new_canvas(); - canvas.width = self.TILE_LEN; - canvas.height = track.get_canvas_height(tile_data, mode, w_scale, canvas.width); - track.draw_tile(tile_data, canvas.getContext('2d'), mode, resolution, region, w_scale); - $(tile_containers[index]).empty().append(canvas); - }); - }); - }); - } -}); - -/** - * Tool input (parameter) that enables both value and sweeping inputs. View is unusual as - * it augments an existing input form row rather than creates a completely new HTML element. - */ -var ToolInputValOrSweepView = Backbone.View.extend({ - - // Template for rendering sweep inputs: - number_input_template: '<div class="form-row-input sweep">' + - '<input class="min" type="text" size="6" value="<%= min %>"> - ' + - '<input class="max" type="text" size="6" value="<%= max %>">' + - ' samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>">' + - '</div>', - - select_input_template: '<div class="form-row-input sweep"><%= options %></div>', - - initialize: function(options) { - this.$el = options.tool_row; - this.render(); - }, - - render: function() { - var input = this.model, - type = input.get('type'), - single_input_row = this.$el.find('.form-row-input'), - sweep_inputs_row = null; - - // Update tool inputs as single input changes. - single_input_row.find(':input').change(function() { - input.set('value', $(this).val()); - }); - - // Add row for parameter sweep inputs. - if (type === 'number') { - sweep_inputs_row = $(_.template(this.number_input_template, this.model.toJSON())); - } - else if (type === 'select') { - var options = _.map(this.$el.find('select option'), function(option) { - return $(option).val(); - }), - options_text = options.join(', '); - sweep_inputs_row = $(_.template(this.select_input_template, { - options: options_text - })); - } - sweep_inputs_row.insertAfter(single_input_row); - - // Add buttons for adding/removing parameter. - var self = this, - menu = create_icon_buttons_menu([ - { - title: 'Add parameter to tree', - icon_class: 'plus-button', - on_click: function () { - input.set('in_ptree', true); - single_input_row.hide(); - sweep_inputs_row.show(); - $(this).hide(); - self.$el.find('.icon-button.toggle').show(); - } - - }, - { - title: 'Remove parameter from tree', - icon_class: 'toggle', - on_click: function() { - // Remove parameter from tree params where name matches clicked paramter. - input.set('in_ptree', false); - sweep_inputs_row.hide(); - single_input_row.show(); - $(this).hide(); - self.$el.find('.icon-button.plus-button').show(); - } - } - ], - { - - }); - this.$el.prepend(menu.$el); - - // Show/hide input rows and icons depending on whether parameter is in the tree. - if (input.get('in_ptree')) { - single_input_row.hide(); - self.$el.find('.icon-button.plus-button').hide(); - } - else { - self.$el.find('.icon-button.toggle').hide(); - sweep_inputs_row.hide(); - } - - // Update input's min, max, number of samples as values change. - _.each(['min', 'max', 'num_samples'], function(attr) { - sweep_inputs_row.find('.' + attr).change(function() { - input.set(attr, parseFloat( $(this).val() )); - }); - }); - } -}); - -var ToolParameterTreeDesignView = Backbone.View.extend({ - className: 'tree-design', - - initialize: function(options) { - this.render(); - }, - - render: function() { - // Start with tool form view. - var tool_form_view = new ToolFormView({ - model: this.model.get('tool') - }); - tool_form_view.render(); - this.$el.append(tool_form_view.$el); - - // Set up views for each tool input. - var self = this, - inputs = self.model.get('tool').get('inputs'); - this.$el.find('.form-row').not('.form-actions').each(function(i) { - var input_view = new ToolInputValOrSweepView({ - model: inputs.at(i), - tool_row: $(this) - }); - }); - } -}); - -/** - * Displays and updates parameter tree. - */ -var ToolParameterTreeView = Backbone.View.extend({ - className: 'tool-parameter-tree', - - initialize: function(options) { - // When tree data changes, re-render. - this.model.on('change:tree_data', this.render, this); - }, - - render: function() { - // Start fresh. - this.$el.children().remove(); - - var tree_params = this.model.get_tree_params(); - if (!tree_params.length) { - return; - } - - // Set width, height based on params and samples. - this.width = 100 * (2 + tree_params.length); - this.height = 15 * this.model.get_num_leaves(); - - var self = this; - - // Layout tree. - var cluster = d3.layout.cluster() - .size([this.height, this.width - 160]); - - var diagonal = d3.svg.diagonal() - .projection(function(d) { return [d.y, d.x]; }); - - // Layout nodes. - var nodes = cluster.nodes(this.model.get('tree_data')); - - // Setup and add labels for tree levels. - var param_depths = _.uniq(_.pluck(nodes, "y")); - _.each(tree_params, function(param, index) { - var x = param_depths[index+1], - center_left = $('#center').position().left; - self.$el.append( $('<div>').addClass('label') - .text(param.get('label')) - .css('left', x + center_left) ); - }); - - // Set up vis element. - var vis = d3.select(this.$el[0]) - .append("svg") - .attr("width", this.width) - .attr("height", this.height + 30) - .append("g") - .attr("transform", "translate(40, 20)"); - - // Draw links. - var link = vis.selectAll("path.link") - .data(cluster.links(nodes)) - .enter().append("path") - .attr("class", "link") - .attr("d", diagonal); - - // Draw nodes. - var node = vis.selectAll("g.node") - .data(nodes) - .enter().append("g") - .attr("class", "node") - .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }) - .on('mouseover', function(a_node) { - var connected_node_ids = _.pluck(self.model.get_connected_nodes(a_node), 'id'); - // TODO: probably can use enter() to do this more easily. - node.filter(function(d) { - return _.find(connected_node_ids, function(id) { return id === d.id; }) !== undefined; - }).style('fill', '#f00'); - }) - .on('mouseout', function() { - node.style('fill', '#000'); - }); - - node.append("circle") - .attr("r", 9); - - node.append("text") - .attr("dx", function(d) { return d.children ? -12 : 12; }) - .attr("dy", 3) - .attr("text-anchor", function(d) { return d.children ? "end" : "start"; }) - .text(function(d) { return d.name; }); - } -}); - -/** - * ParamaMonster visualization view. View requires rendering in 3-panel setup for now. - */ -var ParamaMonsterVisualizationView = Backbone.View.extend({ - className: 'paramamonster', - - helpText: - '<div><h4>Getting Started</h4>' + - '<ol><li>Create a parameter tree by using the icons next to the tool\'s parameter names to add or remove parameters.' + - '<li>Adjust the tree by using parameter inputs to select min, max, and number of samples' + - '<li>Run the tool with different settings by clicking on tree nodes' + - '</ol></div>', - - initialize: function(options) { - this.canvas_manager = new CanvasManager(this.$el.parents('body')); - this.tool_param_tree_view = new ToolParameterTreeView({ model: this.model.get('parameter_tree') }); - this.track_collection_container = $('<table/>').addClass('tracks'); - - // Handle node clicks for tree data. - this.model.get('parameter_tree').on('change:tree_data', this.handle_node_clicks, this); - - // Each track must have a view so it has a canvas manager. - var self = this; - this.model.get('tracks').each(function(track) { - track.get('track').view = self; - }); - - // Set block, reverse strand block colors; these colors will be used for all tracks. - this.block_color = get_random_color(); - this.reverse_strand_color = get_random_color( [ this.block_color, "#ffffff" ] ); - }, - - render: function() { - // Render tree design view in left panel. - var tree_design_view = new ToolParameterTreeDesignView({ - model: this.model.get('parameter_tree') - }); - - $('#left').append(tree_design_view.$el); - - // Render track collection container/view in right panel. - var self = this, - regions = self.model.get('regions'), - tr = $('<tr/>').appendTo(this.track_collection_container); - - regions.each(function(region) { - tr.append( $('<th>').text(region.toString()) ); - }); - tr.children().first().attr('colspan', 2); - - var tracks_div = $('<div>').addClass('tiles'); - $('#right').append( tracks_div.append(this.track_collection_container) ); - - self.model.get('tracks').each(function(track) { - self.add_track(track); - }); - - // -- Render help and tool parameter tree in center panel. -- - - // Help includes text and a close button. - var help_div = $(this.helpText).addClass('help'), - close_button = create_icon_buttons_menu([ - { - title: 'Close', - icon_class: 'cross-circle', - on_click: function() { - $('.tooltip').remove(); - help_div.remove(); - } - } - ]); - - help_div.prepend(close_button.$el.css('float', 'right')); - $('#center').append(help_div); - - // Parameter tree: - this.tool_param_tree_view.render(); - $('#center').append(this.tool_param_tree_view.$el); - - // Set up handler for tree node clicks. - this.handle_node_clicks(); - - // Set up visualization menu. - var menu = create_icon_buttons_menu( - [ - // Save. - /* - { icon_class: 'disk--arrow', title: 'Save', on_click: function() { - // Show saving dialog box - show_modal("Saving...", "progress"); - - viz.save().success(function(vis_info) { - hide_modal(); - viz.set({ - 'id': vis_info.vis_id, - 'has_changes': false - }); - }) - .error(function() { - show_modal( "Could Not Save", "Could not save visualization. Please try again later.", - { "Close" : hide_modal } ); - }); - } }, - */ - // Change track modes. - { - icon_class: 'chevron-expand', - title: 'Set display mode' - }, - // Close viz. - { - icon_class: 'cross-circle', - title: 'Close', - on_click: function() { - window.location = "${h.url_for( controller='visualization', action='list' )}"; - } - } - ], - { - tooltip_config: {placement: 'bottom'} - }); - - // Create mode selection popup. Mode selection changes default mode and mode for all tracks. - var modes = ['Squish', 'Pack'], - mode_mapping = {}; - _.each(modes, function(mode) { - mode_mapping[mode] = function() { - self.model.set('default_mode', mode); - self.model.get('tracks').each(function(track) { - track.set('mode', mode); - }); - }; - }); - - make_popupmenu(menu.$el.find('.chevron-expand'), mode_mapping); - - menu.$el.attr("style", "float: right"); - $("#right .unified-panel-header-inner").append(menu.$el); - }, - - run_tool_on_dataset: function(settings) { - var tool = this.model.get('tool'), - tool_name = tool.get('name'), - dataset = this.model.get('dataset'); - tool.set_input_values(settings.get('values')); - $.when(tool.rerun(dataset)).then(function(outputs) { - // TODO. - }); - - show_modal('Running ' + tool_name + ' on complete dataset', - tool_name + ' is running on dataset \'' + - dataset.get('name') + '\'. Outputs are in the dataset\'s history.', - { - 'Ok': function() { hide_modal(); } - }); - }, - - /** - * Add track to model and view. - */ - add_track: function(pm_track) { - var self = this, - param_tree = this.model.get('parameter_tree'); - - // Add track to model. - self.model.add_track(pm_track); - - var track_view = new ParamaMonsterTrackView({ - model: pm_track, - canvas_manager: self.canvas_manager - }); - track_view.on('run_on_dataset', self.run_tool_on_dataset, self); - self.track_collection_container.append(track_view.$el); - track_view.$el.hover(function() { - var settings_leaf = param_tree.get_leaf(pm_track.get('settings').get('values')); - var connected_node_ids = _.pluck(param_tree.get_connected_nodes(settings_leaf), 'id'); - - // TODO: can do faster with enter? - d3.select(self.tool_param_tree_view.$el[0]).selectAll("g.node") - .filter(function(d) { - return _.find(connected_node_ids, function(id) { return id === d.id; }) !== undefined; - }).style('fill', '#f00'); - }, - function() { - d3.select(self.tool_param_tree_view.$el[0]).selectAll("g.node").style('fill', '#000'); - }); - return pm_track; - }, - - /** - * Sets up handling when tree nodes are clicked. When a node is clicked, the tool is run for each of - * the settings defined by the node's subtree and tracks are added for each run. - */ - handle_node_clicks: function() { - // When node clicked in tree, run tool and add tracks to model. - var self = this, - param_tree = this.model.get('parameter_tree'), - regions = this.model.get('regions'), - node = d3.select(this.tool_param_tree_view.$el[0]).selectAll("g.node"); - node.on("click", function(d, i) { - // Get all settings corresponding to node. - var tool = self.model.get('tool'), - dataset = self.model.get('dataset'), - all_settings = param_tree.get_node_settings(d), - run_jobs_deferred = $.Deferred(); - - // Do not allow 10+ jobs to be run. - if (all_settings.length >= 10) { - show_modal("Whoa there cowboy!", - "You clicked on a node to try " + self.model.get('tool').get('name') + - " with " + all_settings.length + - " different combinations of settings. You can only run 10 jobs at a time.", - { - "Ok": function() { hide_modal(); run_jobs_deferred.resolve(false); } - }); - } - else { - run_jobs_deferred.resolve(true); - } - - // Take action when deferred resolves. - $.when(run_jobs_deferred).then(function(run_jobs) { - if (!run_jobs) { return; } - - // Create and add tracks for each settings group. - var tracks = _.map(all_settings, function(settings) { - var pm_track = new ParamaMonsterTrack({ - settings: settings, - regions: regions, - mode: self.model.get('default_mode') - }); - self.add_track(pm_track); - return pm_track; - }); - - // For each track, run tool using track's settings and update track. - _.each(tracks, function(pm_track, index) { - setTimeout(function() { - // Set inputs and run tool. - // console.log('running with settings', pm_track.get('settings')); - tool.set_input_values(pm_track.get('settings').get('values')); - $.when(tool.rerun(dataset, regions)).then(function(output) { - // Create and add track for output dataset. - var track_config = _.extend({ - data_url: galaxy_paths.get('raw_data_url'), - converted_datasets_state_url: galaxy_paths.get('dataset_state_url') - }, output.first().get('track_config')), - track_obj = object_from_template(track_config, self, null); - - // Set track block colors. - track_obj.prefs.block_color = self.block_color; - track_obj.prefs.reverse_strand_color = self.reverse_strand_color; - - pm_track.set('track', track_obj); - }); - }, index * 10000); - }); - }); - }); - } -}); \ No newline at end of file diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 static/scripts/viz/sweepster.js --- /dev/null +++ b/static/scripts/viz/sweepster.js @@ -0,0 +1,939 @@ +/** + * Visualization and components for Sweepster, a visualization for exploring a tool's parameter space via + * genomic visualization. + */ + +/** + * A collection of tool input settings. Object is useful for keeping a list of settings + * for future use without changing the input's value and for preserving inputs order. + */ +var ToolInputsSettings = Backbone.Model.extend({ + defaults: { + inputs: null, + values: null + } +}); + +/** + * Tree for a tool's parameters. + */ +var ToolParameterTree = Backbone.RelationalModel.extend({ + defaults: { + tool: null, + tree_data: null + }, + + initialize: function(options) { + // Set up tool parameters to work with tree. + var self = this; + this.get('tool').get('inputs').each(function(input) { + if (!input.get_samples()) { return; } + + // Listen for changes to input's attributes. + input.on('change:min change:max change:num_samples', function(input) { + if (input.get('in_ptree')) { + self.set_tree_data(); + } + }, self); + input.on('change:in_ptree', function(input) { + if (input.get('in_ptree')) { + self.add_param(input); + } + else { + self.remove_param(input); + } + self.set_tree_data(); + }, self); + }); + + // If there is a config, use it. + if (options.config) { + _.each(options.config, function(input_config) { + var input = self.get('tool').get('inputs').find(function(input) { + return input.get('name') === input_config.name; + }); + self.add_param(input); + input.set(input_config); + }); + } + }, + + add_param: function(param) { + // If parameter already present, do not add it. + if (param.get('ptree_index')) { return; } + + param.set('in_ptree', true); + param.set('ptree_index', this.get_tree_params().length); + }, + + remove_param: function(param) { + // Remove param from tree. + param.set('in_ptree', false); + param.set('ptree_index', null); + + // Update ptree indices for remaining params. + _(this.get_tree_params()).each(function(input, index) { + // +1 to use 1-based indexing. + input.set('ptree_index', index + 1); + }); + }, + + /** + * Sets tree data using tool's inputs. + */ + set_tree_data: function() { + // Get samples for each parameter. + var params_samples = _.map(this.get_tree_params(), function(param) { + return { + param: param, + samples: param.get_samples() + }; + }); + var node_id = 0, + // Creates tree data recursively. + create_tree_data = function(params_samples, index) { + var param_samples = params_samples[index], + param = param_samples.param, + param_label = param.get('label'), + settings = param_samples.samples; + + // Create leaves when last parameter setting is reached. + if (params_samples.length - 1 === index) { + return _.map(settings, function(setting) { + return { + id: node_id++, + name: setting, + param: param, + value: setting + }; + }); + } + + // Recurse to handle other parameters. + return _.map(settings, function(setting) { + return { + id: node_id++, + name: setting, + param: param, + value: setting, + children: create_tree_data(params_samples, index + 1) + }; + }); + }; + + this.set('tree_data', { + name: 'Root', + id: node_id++, + children: (params_samples.length !== 0 ? create_tree_data(params_samples, 0) : null) + }); + }, + + get_tree_params: function() { + // Filter and sort parameters to get list in tree. + return _(this.get('tool').get('inputs').where( {in_ptree: true} )) + .sortBy( function(input) { return input.get('ptree_index'); } ); + }, + + /** + * Returns number of leaves in tree. + */ + get_num_leaves: function() { + return this.get_tree_params().reduce(function(memo, param) { return memo * param.get_samples().length; }, 1); + }, + + /** + * Returns array of ToolInputsSettings objects based on a node and its subtree. + */ + get_node_settings: function(target_node) { + // -- Get fixed settings from tool and parent nodes. + + // Start with tool's settings. + var fixed_settings = this.get('tool').get_inputs_dict(); + + // Get fixed settings using node's parents. + var cur_node = target_node.parent; + if (cur_node) { + while(cur_node.depth !== 0) { + fixed_settings[cur_node.param.get('name')] = cur_node.value; + cur_node = cur_node.parent; + } + } + + // Walk subtree starting at clicked node to get full list of settings. + var self = this, + get_settings = function(node, settings) { + // Add setting for this node. Root node does not have a param, + // however. + if (node.param) { + settings[node.param.get('name')] = node.value; + } + + if (!node.children) { + // At leaf node, so return settings. + return new ToolInputsSettings({ + inputs: self.get('tool').get('inputs'), + values: settings + }); + } + else { + // At interior node: return list of subtree settings. + return _.flatten( _.map(node.children, function(c) { return get_settings(c, _.clone(settings)); }) ); + } + }, + all_settings = get_settings(target_node, fixed_settings); + + // If user clicked on leaf, settings is a single dict. Convert to array for simplicity. + if (!_.isArray(all_settings)) { all_settings = [ all_settings ]; } + + return all_settings; + }, + + /** + * Returns all nodes connected a particular node; this includes parents and children of the node. + */ + get_connected_nodes: function(node) { + var get_subtree_nodes = function(a_node) { + if (!a_node.children) { + return a_node; + } + else { + // At interior node: return subtree nodes. + return _.flatten( [a_node, _.map(a_node.children, function(c) { return get_subtree_nodes(c); })] ); + } + }; + + // Get node's parents. + var parents = [], + cur_parent = node.parent; + while(cur_parent) { + parents.push(cur_parent); + cur_parent = cur_parent.parent; + } + + return _.flatten([parents, get_subtree_nodes(node)]); + }, + + /** + * Returns the leaf that corresponds to a settings collection. + */ + get_leaf: function(settings) { + var cur_node = this.get('tree_data'), + find_child = function(children) { + return _.find(children, function(child) { + return settings[child.param.get('name')] === child.value; + }); + }; + + while (cur_node.children) { + cur_node = find_child(cur_node.children); + } + return cur_node; + }, + + /** + * Returns a list of parameters used in tree. + */ + toJSON: function() { + // FIXME: returning and jsonifying complete param causes trouble on the server side, + // so just use essential attributes for now. + return this.get_tree_params().map(function(param) { + return { + name: param.get('name'), + min: param.get('min'), + max: param.get('max'), + num_samples: param.get('num_samples') + }; + }); + } +}); + +var SweepsterTrack = Backbone.RelationalModel.extend({ + defaults: { + track: null, + mode: 'Pack', + settings: null, + regions: null + }, + + relations: [ + { + type: Backbone.HasMany, + key: 'regions', + relatedModel: 'GenomeRegion' + } + ], + + initialize: function(options) { + if (options.track) { + // FIXME: find a better way to deal with needed URLs: + var track_config = _.extend({ + data_url: galaxy_paths.get('raw_data_url'), + converted_datasets_state_url: galaxy_paths.get('dataset_state_url') + }, options.track); + this.set('track', object_from_template(track_config, {}, null)); + } + }, + + same_settings: function(a_track) { + var this_settings = this.get('settings'), + other_settings = a_track.get('settings'); + for (var prop in this_settings) { + if (!other_settings[prop] || + this_settings[prop] !== other_settings[prop]) { + return false; + } + } + return true; + }, + + toJSON: function() { + return { + track: this.get('track').to_dict(), + settings: this.get('settings'), + regions: this.get('regions') + }; + } +}); + +var TrackCollection = Backbone.Collection.extend({ + model: SweepsterTrack +}); + +/** + * Sweepster visualization model. + */ +var SweepsterVisualization = Visualization.extend({ + defaults: _.extend({}, Visualization.prototype.defaults, { + dataset: null, + tool: null, + parameter_tree: null, + regions: null, + tracks: null, + default_mode: 'Pack' + }), + + relations: [ + { + type: Backbone.HasOne, + key: 'dataset', + relatedModel: 'Dataset' + }, + { + type: Backbone.HasOne, + key: 'tool', + relatedModel: 'Tool' + }, + { + type: Backbone.HasMany, + key: 'regions', + relatedModel: 'GenomeRegion' + }, + { + type: Backbone.HasMany, + key: 'tracks', + relatedModel: 'SweepsterTrack' + } + // NOTE: cannot use relationship for parameter tree because creating tree is complex. + ], + + initialize: function(options) { + var tool_with_samplable_inputs = this.get('tool').copy(true); + this.set('tool_with_samplable_inputs', tool_with_samplable_inputs); + + this.set('parameter_tree', new ToolParameterTree({ + tool: tool_with_samplable_inputs, + config: options.tree_config + })); + }, + + add_track: function(track) { + this.get('tracks').add(track); + }, + + toJSON: function() { + // TODO: could this be easier by using relational models? + return { + id: this.get('id'), + title: 'Parameter exploration for dataset \'' + this.get('dataset').get('name') + '\'', + type: 'sweepster', + dataset_id: this.get('dataset').id, + tool_id: this.get('tool').id, + regions: this.get('regions').toJSON(), + tree_config: this.get('parameter_tree').toJSON(), + tracks: this.get('tracks').toJSON() + }; + } +}); + +/** + * --- Views --- + */ + +/** + * Sweepster track view. + */ +var SweepsterTrackView = Backbone.View.extend({ + tagName: 'tr', + + TILE_LEN: 250, + + initialize: function(options) { + this.canvas_manager = options.canvas_manager; + this.render(); + this.model.on('change:track change:mode', this.draw_tiles, this); + }, + + render: function() { + // Render settings icon and popup. + // TODO: use template. + var settings = this.model.get('settings'), + values = settings.get('values'), + settings_td = $('<td/>').addClass('settings').appendTo(this.$el), + settings_div = $('<div/>').addClass('track-info').hide().appendTo(settings_td); + settings_div.append( $('<div/>').css('font-weight', 'bold').text('Track Settings') ); + settings.get('inputs').each(function(input) { + settings_div.append( input.get('label') + ': ' + values[input.get('name')] + '<br/>'); + }); + var self = this, + run_on_dataset_button = $('<button/>').appendTo(settings_div).text('Run on complete dataset').click(function() { + settings_div.toggle(); + self.trigger('run_on_dataset', settings); + }); + var icon_menu = create_icon_buttons_menu([ + { + title: 'Settings', + icon_class: 'gear track-settings', + on_click: function() { + settings_div.toggle(); + } + }, + { + title: 'Remove', + icon_class: 'cross-circle', + on_click: function() { + self.$el.remove(); + $('.bs-tooltip').remove(); + // TODO: remove track from viz collection. + } + } + ]); + settings_td.prepend(icon_menu.$el); + + // Render tile placeholders. + this.model.get('regions').each(function() { + self.$el.append($('<td/>').addClass('tile').html( + $('<img/>').attr('src', galaxy_paths.get('image_path') + '/loading_large_white_bg.gif') + )); + }); + + if (this.model.get('track')) { + this.draw_tiles(); + } + }, + + /** + * Draw tiles for regions. + */ + draw_tiles: function() { + var self = this, + track = this.model.get('track'), + regions = this.model.get('regions'), + tile_containers = this.$el.find('td.tile'); + + // Do nothing if track is not defined. + if (!track) { return; } + + // When data is ready, draw tiles. + $.when(track.data_manager.data_is_ready()).then(function(data_ok) { + // Draw tile for each region. + regions.each(function(region, index) { + var resolution = region.length() / self.TILE_LEN, + w_scale = 1/resolution, + mode = self.model.get('mode'); + $.when(track.data_manager.get_data(region, mode, resolution, {})).then(function(tile_data) { + var canvas = self.canvas_manager.new_canvas(); + canvas.width = self.TILE_LEN; + canvas.height = track.get_canvas_height(tile_data, mode, w_scale, canvas.width); + track.draw_tile(tile_data, canvas.getContext('2d'), mode, resolution, region, w_scale); + $(tile_containers[index]).empty().append(canvas); + }); + }); + }); + } +}); + +/** + * Tool input (parameter) that enables both value and sweeping inputs. View is unusual as + * it augments an existing input form row rather than creates a completely new HTML element. + */ +var ToolInputValOrSweepView = Backbone.View.extend({ + + // Template for rendering sweep inputs: + number_input_template: '<div class="form-row-input sweep">' + + '<input class="min" type="text" size="6" value="<%= min %>"> - ' + + '<input class="max" type="text" size="6" value="<%= max %>">' + + ' samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>">' + + '</div>', + + select_input_template: '<div class="form-row-input sweep"><%= options %></div>', + + initialize: function(options) { + this.$el = options.tool_row; + this.render(); + }, + + render: function() { + var input = this.model, + type = input.get('type'), + single_input_row = this.$el.find('.form-row-input'), + sweep_inputs_row = null; + + // Update tool inputs as single input changes. + single_input_row.find(':input').change(function() { + input.set('value', $(this).val()); + }); + + // Add row for parameter sweep inputs. + if (type === 'number') { + sweep_inputs_row = $(_.template(this.number_input_template, this.model.toJSON())); + } + else if (type === 'select') { + var options = _.map(this.$el.find('select option'), function(option) { + return $(option).val(); + }), + options_text = options.join(', '); + sweep_inputs_row = $(_.template(this.select_input_template, { + options: options_text + })); + } + sweep_inputs_row.insertAfter(single_input_row); + + // Add buttons for adding/removing parameter. + var self = this, + menu = create_icon_buttons_menu([ + { + title: 'Add parameter to tree', + icon_class: 'plus-button', + on_click: function () { + input.set('in_ptree', true); + single_input_row.hide(); + sweep_inputs_row.show(); + $(this).hide(); + self.$el.find('.icon-button.toggle').show(); + } + + }, + { + title: 'Remove parameter from tree', + icon_class: 'toggle', + on_click: function() { + // Remove parameter from tree params where name matches clicked paramter. + input.set('in_ptree', false); + sweep_inputs_row.hide(); + single_input_row.show(); + $(this).hide(); + self.$el.find('.icon-button.plus-button').show(); + } + } + ], + { + + }); + this.$el.prepend(menu.$el); + + // Show/hide input rows and icons depending on whether parameter is in the tree. + if (input.get('in_ptree')) { + single_input_row.hide(); + self.$el.find('.icon-button.plus-button').hide(); + } + else { + self.$el.find('.icon-button.toggle').hide(); + sweep_inputs_row.hide(); + } + + // Update input's min, max, number of samples as values change. + _.each(['min', 'max', 'num_samples'], function(attr) { + sweep_inputs_row.find('.' + attr).change(function() { + input.set(attr, parseFloat( $(this).val() )); + }); + }); + } +}); + +var ToolParameterTreeDesignView = Backbone.View.extend({ + className: 'tree-design', + + initialize: function(options) { + this.render(); + }, + + render: function() { + // Start with tool form view. + var tool_form_view = new ToolFormView({ + model: this.model.get('tool') + }); + tool_form_view.render(); + this.$el.append(tool_form_view.$el); + + // Set up views for each tool input. + var self = this, + inputs = self.model.get('tool').get('inputs'); + this.$el.find('.form-row').not('.form-actions').each(function(i) { + var input_view = new ToolInputValOrSweepView({ + model: inputs.at(i), + tool_row: $(this) + }); + }); + } +}); + +/** + * Displays and updates parameter tree. + */ +var ToolParameterTreeView = Backbone.View.extend({ + className: 'tool-parameter-tree', + + initialize: function(options) { + // When tree data changes, re-render. + this.model.on('change:tree_data', this.render, this); + }, + + render: function() { + // Start fresh. + this.$el.children().remove(); + + var tree_params = this.model.get_tree_params(); + if (!tree_params.length) { + return; + } + + // Set width, height based on params and samples. + this.width = 100 * (2 + tree_params.length); + this.height = 15 * this.model.get_num_leaves(); + + var self = this; + + // Layout tree. + var cluster = d3.layout.cluster() + .size([this.height, this.width - 160]); + + var diagonal = d3.svg.diagonal() + .projection(function(d) { return [d.y, d.x]; }); + + // Layout nodes. + var nodes = cluster.nodes(this.model.get('tree_data')); + + // Setup and add labels for tree levels. + var param_depths = _.uniq(_.pluck(nodes, "y")); + _.each(tree_params, function(param, index) { + var x = param_depths[index+1], + center_left = $('#center').position().left; + self.$el.append( $('<div>').addClass('label') + .text(param.get('label')) + .css('left', x + center_left) ); + }); + + // Set up vis element. + var vis = d3.select(this.$el[0]) + .append("svg") + .attr("width", this.width) + .attr("height", this.height + 30) + .append("g") + .attr("transform", "translate(40, 20)"); + + // Draw links. + var link = vis.selectAll("path.link") + .data(cluster.links(nodes)) + .enter().append("path") + .attr("class", "link") + .attr("d", diagonal); + + // Draw nodes. + var node = vis.selectAll("g.node") + .data(nodes) + .enter().append("g") + .attr("class", "node") + .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }) + .on('mouseover', function(a_node) { + var connected_node_ids = _.pluck(self.model.get_connected_nodes(a_node), 'id'); + // TODO: probably can use enter() to do this more easily. + node.filter(function(d) { + return _.find(connected_node_ids, function(id) { return id === d.id; }) !== undefined; + }).style('fill', '#f00'); + }) + .on('mouseout', function() { + node.style('fill', '#000'); + }); + + node.append("circle") + .attr("r", 9); + + node.append("text") + .attr("dx", function(d) { return d.children ? -12 : 12; }) + .attr("dy", 3) + .attr("text-anchor", function(d) { return d.children ? "end" : "start"; }) + .text(function(d) { return d.name; }); + } +}); + +/** + * Sweepster visualization view. View requires rendering in 3-panel setup for now. + */ +var SweepsterVisualizationView = Backbone.View.extend({ + className: 'Sweepster', + + helpText: + '<div><h4>Getting Started</h4>' + + '<ol><li>Create a parameter tree by using the icons next to the tool\'s parameter names to add or remove parameters.' + + '<li>Adjust the tree by using parameter inputs to select min, max, and number of samples' + + '<li>Run the tool with different settings by clicking on tree nodes' + + '</ol></div>', + + initialize: function(options) { + this.canvas_manager = new CanvasManager(this.$el.parents('body')); + this.tool_param_tree_view = new ToolParameterTreeView({ model: this.model.get('parameter_tree') }); + this.track_collection_container = $('<table/>').addClass('tracks'); + + // Handle node clicks for tree data. + this.model.get('parameter_tree').on('change:tree_data', this.handle_node_clicks, this); + + // Each track must have a view so it has a canvas manager. + var self = this; + this.model.get('tracks').each(function(track) { + track.get('track').view = self; + }); + + // Set block, reverse strand block colors; these colors will be used for all tracks. + this.block_color = get_random_color(); + this.reverse_strand_color = get_random_color( [ this.block_color, "#ffffff" ] ); + }, + + render: function() { + // Render tree design view in left panel. + var tree_design_view = new ToolParameterTreeDesignView({ + model: this.model.get('parameter_tree') + }); + + $('#left').append(tree_design_view.$el); + + // Render track collection container/view in right panel. + var self = this, + regions = self.model.get('regions'), + tr = $('<tr/>').appendTo(this.track_collection_container); + + regions.each(function(region) { + tr.append( $('<th>').text(region.toString()) ); + }); + tr.children().first().attr('colspan', 2); + + var tracks_div = $('<div>').addClass('tiles'); + $('#right').append( tracks_div.append(this.track_collection_container) ); + + self.model.get('tracks').each(function(track) { + self.add_track(track); + }); + + // -- Render help and tool parameter tree in center panel. -- + + // Help includes text and a close button. + var help_div = $(this.helpText).addClass('help'), + close_button = create_icon_buttons_menu([ + { + title: 'Close', + icon_class: 'cross-circle', + on_click: function() { + $('.bs-tooltip').remove(); + help_div.remove(); + } + } + ]); + + help_div.prepend(close_button.$el.css('float', 'right')); + $('#center').append(help_div); + + // Parameter tree: + this.tool_param_tree_view.render(); + $('#center').append(this.tool_param_tree_view.$el); + + // Set up handler for tree node clicks. + this.handle_node_clicks(); + + // Set up visualization menu. + var menu = create_icon_buttons_menu( + [ + // Save. + /* + { icon_class: 'disk--arrow', title: 'Save', on_click: function() { + // Show saving dialog box + show_modal("Saving...", "progress"); + + viz.save().success(function(vis_info) { + hide_modal(); + viz.set({ + 'id': vis_info.vis_id, + 'has_changes': false + }); + }) + .error(function() { + show_modal( "Could Not Save", "Could not save visualization. Please try again later.", + { "Close" : hide_modal } ); + }); + } }, + */ + // Change track modes. + { + icon_class: 'chevron-expand', + title: 'Set display mode' + }, + // Close viz. + { + icon_class: 'cross-circle', + title: 'Close', + on_click: function() { + window.location = "${h.url_for( controller='visualization', action='list' )}"; + } + } + ], + { + tooltip_config: {placement: 'bottom'} + }); + + // Create mode selection popup. Mode selection changes default mode and mode for all tracks. + var modes = ['Squish', 'Pack'], + mode_mapping = {}; + _.each(modes, function(mode) { + mode_mapping[mode] = function() { + self.model.set('default_mode', mode); + self.model.get('tracks').each(function(track) { + track.set('mode', mode); + }); + }; + }); + + make_popupmenu(menu.$el.find('.chevron-expand'), mode_mapping); + + menu.$el.attr("style", "float: right"); + $("#right .unified-panel-header-inner").append(menu.$el); + }, + + run_tool_on_dataset: function(settings) { + var tool = this.model.get('tool'), + tool_name = tool.get('name'), + dataset = this.model.get('dataset'); + tool.set_input_values(settings.get('values')); + $.when(tool.rerun(dataset)).then(function(outputs) { + // TODO. + }); + + show_modal('Running ' + tool_name + ' on complete dataset', + tool_name + ' is running on dataset \'' + + dataset.get('name') + '\'. Outputs are in the dataset\'s history.', + { + 'Ok': function() { hide_modal(); } + }); + }, + + /** + * Add track to model and view. + */ + add_track: function(pm_track) { + var self = this, + param_tree = this.model.get('parameter_tree'); + + // Add track to model. + self.model.add_track(pm_track); + + var track_view = new SweepsterTrackView({ + model: pm_track, + canvas_manager: self.canvas_manager + }); + track_view.on('run_on_dataset', self.run_tool_on_dataset, self); + self.track_collection_container.append(track_view.$el); + track_view.$el.hover(function() { + var settings_leaf = param_tree.get_leaf(pm_track.get('settings').get('values')); + var connected_node_ids = _.pluck(param_tree.get_connected_nodes(settings_leaf), 'id'); + + // TODO: can do faster with enter? + d3.select(self.tool_param_tree_view.$el[0]).selectAll("g.node") + .filter(function(d) { + return _.find(connected_node_ids, function(id) { return id === d.id; }) !== undefined; + }).style('fill', '#f00'); + }, + function() { + d3.select(self.tool_param_tree_view.$el[0]).selectAll("g.node").style('fill', '#000'); + }); + return pm_track; + }, + + /** + * Sets up handling when tree nodes are clicked. When a node is clicked, the tool is run for each of + * the settings defined by the node's subtree and tracks are added for each run. + */ + handle_node_clicks: function() { + // When node clicked in tree, run tool and add tracks to model. + var self = this, + param_tree = this.model.get('parameter_tree'), + regions = this.model.get('regions'), + node = d3.select(this.tool_param_tree_view.$el[0]).selectAll("g.node"); + node.on("click", function(d, i) { + // Get all settings corresponding to node. + var tool = self.model.get('tool'), + dataset = self.model.get('dataset'), + all_settings = param_tree.get_node_settings(d), + run_jobs_deferred = $.Deferred(); + + // Do not allow 10+ jobs to be run. + if (all_settings.length >= 10) { + show_modal("Whoa there cowboy!", + "You clicked on a node to try " + self.model.get('tool').get('name') + + " with " + all_settings.length + + " different combinations of settings. You can only run 10 jobs at a time.", + { + "Ok": function() { hide_modal(); run_jobs_deferred.resolve(false); } + }); + } + else { + run_jobs_deferred.resolve(true); + } + + // Take action when deferred resolves. + $.when(run_jobs_deferred).then(function(run_jobs) { + if (!run_jobs) { return; } + + // Create and add tracks for each settings group. + var tracks = _.map(all_settings, function(settings) { + var pm_track = new SweepsterTrack({ + settings: settings, + regions: regions, + mode: self.model.get('default_mode') + }); + self.add_track(pm_track); + return pm_track; + }); + + // For each track, run tool using track's settings and update track. + _.each(tracks, function(pm_track, index) { + setTimeout(function() { + // Set inputs and run tool. + // console.log('running with settings', pm_track.get('settings')); + tool.set_input_values(pm_track.get('settings').get('values')); + $.when(tool.rerun(dataset, regions)).then(function(output) { + // Create and add track for output dataset. + var track_config = _.extend({ + data_url: galaxy_paths.get('raw_data_url'), + converted_datasets_state_url: galaxy_paths.get('dataset_state_url') + }, output.first().get('track_config')), + track_obj = object_from_template(track_config, self, null); + + // Set track block colors. + track_obj.prefs.block_color = self.block_color; + track_obj.prefs.reverse_strand_color = self.reverse_strand_color; + + pm_track.set('track', track_obj); + }); + }, index * 10000); + }); + }); + }); + } +}); \ No newline at end of file diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -3074,7 +3074,7 @@ // Go to visualization. window.location.href = - galaxy_paths.get('paramamonster_url') + "?" + + galaxy_paths.get('sweepster_url') + "?" + $.param({ dataset_id: track.dataset_id, hda_ldda: track.hda_ldda, diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 templates/base_panels.mako --- a/templates/base_panels.mako +++ b/templates/base_panels.mako @@ -60,7 +60,7 @@ converted_datasets_state_url: '${h.url_for( controller="/tracks", action="converted_datasets_state" )}', dataset_state_url: '${h.url_for( controller="/tracks", action="dataset_state" )}', visualization_url: '${h.url_for( controller="/visualization", action="save" )}', - paramamonster_url: '${h.url_for( controller="/tracks", action="paramamonster" )}' + sweepster_url: '${h.url_for( controller="/tracks", action="sweepster" )}' }); </script></%def> diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 templates/visualization/paramamonster.mako --- a/templates/visualization/paramamonster.mako +++ /dev/null @@ -1,137 +0,0 @@ -<%inherit file="/webapps/galaxy/base_panels.mako"/> - -<%def name="init()"> -<% - self.has_left_panel=True - self.has_right_panel=True - self.active_view="visualization" - self.message_box_visible=False -%> -</%def> - -<%def name="stylesheets()"> - ${parent.stylesheets()} - <style> - .link { - fill: none; - stroke: #ccc; - stroke-width: 1.5px; - } - .node { - font: 10px sans-serif; - } - .node circle { - fill: #fff; - stroke: steelblue; - stroke-width: 1.5px; - cursor: pointer; - } - .node:hover { - fill: #f00; - } - .node:hover circle { - fill: #ccc; - stroke: #f00; - } - table.tracks { - border-collapse: separate; - border-spacing: 5px; - } - .tile { - border: solid 1px #DDD; - margin: 2px; - border-radius: 10px; - margin: 3px; - } - .label { - position: fixed; - font: 10px sans-serif; - font-weight: bold; - background-color: #DDD; - border-radius: 5px; - padding: 1px; - } - th,td { - text-align: center; - } - td.settings { - vertical-align: top; - } - .icon-button.track-settings { - float: none; - } - .track-info { - text-align: left; - font: 10px sans-serif; - position: fixed; - background-color: #CCC; - border: solid 1px #AAA; - border-radius: 2px; - padding: 2px; - } - .btn-primary, .btn-primary:hover { - color: #EEE; - background-color: #DDD; - background-image: none; - border-radius: 12px; - } - #left { - width: 300px; - } - #center { - left: 300px; - right: 600px; - overflow: auto; - } - #right { - width: 600px; - } - .tiles { - overflow: auto; - position: absolute; - top: 30px; - bottom: 25px; - left: 0; - right: 0; - } - .help { - border-radius: 15px; - border: solid 1px #CCC; - padding: 0px 2px; - margin: 10px; - } - </style> -</%def> - -<%def name="javascripts()"> - ${parent.javascripts()} - - ${h.templates( "tool_link", "panel_section", "tool_search", "tool_form" )} - ${h.js( "libs/d3", "mvc/data", "mvc/tools", "viz/visualization", "viz/paramamonster", - "viz/trackster", "viz/trackster_ui", "jquery.ui.sortable.slider" )} - - <script type="text/javascript"> - var viz; - $(function() { - // -- Viz set up. -- - var viz = new ParamaMonsterVisualization( - ${ h.to_json_string( config ).replace('\\', '\\\\' )} - ); - var viz_view = new ParamaMonsterVisualizationView({ model: viz }); - viz_view.render(); - }); - </script> -</%def> - -<%def name="center_panel()"> -</%def> - -<%def name="left_panel()"> -</%def> - -<%def name="right_panel()"> - <div class="unified-panel-header" unselectable="on"> - <div class="unified-panel-header-inner"> - </div> - </div> -</%def> \ No newline at end of file diff -r 10829b9c5086a09b80b0c592d9a289b65d723fcf -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 templates/visualization/sweepster.mako --- /dev/null +++ b/templates/visualization/sweepster.mako @@ -0,0 +1,137 @@ +<%inherit file="/webapps/galaxy/base_panels.mako"/> + +<%def name="init()"> +<% + self.has_left_panel=True + self.has_right_panel=True + self.active_view="visualization" + self.message_box_visible=False +%> +</%def> + +<%def name="stylesheets()"> + ${parent.stylesheets()} + <style> + .link { + fill: none; + stroke: #ccc; + stroke-width: 1.5px; + } + .node { + font: 10px sans-serif; + } + .node circle { + fill: #fff; + stroke: steelblue; + stroke-width: 1.5px; + cursor: pointer; + } + .node:hover { + fill: #f00; + } + .node:hover circle { + fill: #ccc; + stroke: #f00; + } + table.tracks { + border-collapse: separate; + border-spacing: 5px; + } + .tile { + border: solid 1px #DDD; + margin: 2px; + border-radius: 10px; + margin: 3px; + } + .label { + position: fixed; + font: 10px sans-serif; + font-weight: bold; + background-color: #DDD; + border-radius: 5px; + padding: 1px; + } + th,td { + text-align: center; + } + td.settings { + vertical-align: top; + } + .icon-button.track-settings { + float: none; + } + .track-info { + text-align: left; + font: 10px sans-serif; + position: fixed; + background-color: #CCC; + border: solid 1px #AAA; + border-radius: 2px; + padding: 2px; + } + .btn-primary, .btn-primary:hover { + color: #EEE; + background-color: #DDD; + background-image: none; + border-radius: 12px; + } + #left { + width: 300px; + } + #center { + left: 300px; + right: 600px; + overflow: auto; + } + #right { + width: 600px; + } + .tiles { + overflow: auto; + position: absolute; + top: 30px; + bottom: 25px; + left: 0; + right: 0; + } + .help { + border-radius: 15px; + border: solid 1px #CCC; + padding: 0px 2px; + margin: 10px; + } + </style> +</%def> + +<%def name="javascripts()"> + ${parent.javascripts()} + + ${h.templates( "tool_link", "panel_section", "tool_search", "tool_form" )} + ${h.js( "libs/d3", "mvc/data", "mvc/tools", "viz/visualization", "viz/sweepster", + "viz/trackster", "viz/trackster_ui", "jquery.ui.sortable.slider" )} + + <script type="text/javascript"> + var viz; + $(function() { + // -- Viz set up. -- + var viz = new SweepsterVisualization( + ${ h.to_json_string( config ).replace('\\', '\\\\' )} + ); + var viz_view = new SweepsterVisualizationView({ model: viz }); + viz_view.render(); + }); + </script> +</%def> + +<%def name="center_panel()"> +</%def> + +<%def name="left_panel()"> +</%def> + +<%def name="right_panel()"> + <div class="unified-panel-header" unselectable="on"> + <div class="unified-panel-header-inner"> + </div> + </div> +</%def> \ No newline at end of file https://bitbucket.org/galaxy/galaxy-central/changeset/51992bf52e0c/ changeset: 51992bf52e0c user: jgoecks date: 2012-07-24 20:28:08 summary: Add bigwig/bigbed support to Circster. Pack scripts. affected #: 7 files diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 lib/galaxy/visualization/tracks/data_providers.py --- a/lib/galaxy/visualization/tracks/data_providers.py +++ b/lib/galaxy/visualization/tracks/data_providers.py @@ -105,6 +105,17 @@ """ iterator = self.get_iterator( chrom, start, end ) return self.process_data( iterator, start_val, max_vals, **kwargs ) + + def get_genome_data( self, chroms_info, **kwargs ): + """ + Returns data for complete genome. + """ + dataset_summary = [] + for chrom_info in chroms_info[ 'chrom_info' ]: + summary = self.get_data( chrom_info[ 'chrom' ], 0, chrom_info[ 'len' ], **kwargs ) + dataset_summary.append( summary ) + + return dataset_summary def get_filters( self ): """ @@ -617,20 +628,8 @@ def valid_chroms( self ): st = summary_tree_from_file( self.converted_dataset.file_name ) return st.chrom_blocks.keys() - - def get_genome_data( self, chroms_info ): - """ - Returns summary tree data for complete genome. - """ - dataset_summary = [] - for chrom_info in chroms_info[ 'chrom_info' ]: - summary = self.get_summary( chrom_info[ 'chrom' ], 0, chrom_info[ 'len' ], level=3, detail_cutoff=0, draw_cutoff=0 ) - dataset_summary.append( summary ) - - return dataset_summary - # TODO: rename to get_data to match other providers. - def get_summary( self, chrom, start, end, level=None, resolution=None, detail_cutoff=None, draw_cutoff=None ): + def get_data( self, chrom, start, end, level=None, resolution=None, detail_cutoff=None, draw_cutoff=None ): """ Returns summary tree data for a given genomic region. """ @@ -899,7 +898,7 @@ all_dat = bbi.query(chrom, 0, 2147483647, 1) f.close() return all_dat is not None - + def get_data( self, chrom, start, end, start_val=0, max_vals=None, **kwargs ): # Bigwig can be a standalone bigwig file, in which case we use # original_dataset, or coming from wig->bigwig conversion in diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -380,7 +380,7 @@ tracks_dataset_type = data_sources['index']['name'] converted_dataset = dataset.get_converted_dataset( trans, tracks_dataset_type ) indexer = get_data_provider( tracks_dataset_type )( converted_dataset, dataset ) - summary = indexer.get_summary( chrom, low, high, resolution=kwargs[ 'resolution' ] ) + summary = indexer.get_data( chrom, low, high, resolution=kwargs[ 'resolution' ] ) if summary is None: return { 'dataset_type': tracks_dataset_type, 'data': None } @@ -528,7 +528,8 @@ # Get converted dataset and append track's genome data. converted_dataset = dataset.get_converted_dataset( trans, indexed_type ) data_provider = get_data_provider( indexed_type )( converted_dataset, dataset ) - track[ 'genome_wide_data' ] = { 'data': data_provider.get_genome_data( chroms_info ) } + # HACK: pass in additional params, which are only used for summary tree data, not BBI data. + track[ 'genome_wide_data' ] = { 'data': data_provider.get_genome_data( chroms_info, level=3, detail_cutoff=0, draw_cutoff=0 ) } return trans.fill_template( 'visualization/circster.mako', viz_config=viz_config, genome=genome ) diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 static/scripts/packed/bootstrap.js --- a/static/scripts/packed/bootstrap.js +++ b/static/scripts/packed/bootstrap.js @@ -1,1 +1,1 @@ -!function(b){var a=function(c){this.element=b(c)};a.prototype={constructor:a,show:function(){var i=this.element,f=i.closest("ul:not(.dropdown-menu)"),d=i.attr("data-target"),g,c,h;if(!d){d=i.attr("href");d=d&&d.replace(/.*(?=#[^\s]*$)/,"")}if(i.parent("li").hasClass("active")){return}g=f.find(".active a").last()[0];h=b.Event("show",{relatedTarget:g});i.trigger(h);if(h.isDefaultPrevented()){return}c=b(d);this.activate(i.parent("li"),f);this.activate(c,c.parent(),function(){i.trigger({type:"shown",relatedTarget:g})})},activate:function(e,d,h){var c=d.find("> .active"),g=h&&b.support.transition&&c.hasClass("fade");function f(){c.removeClass("active").find("> .dropdown-menu > .active").removeClass("active");e.addClass("active");if(g){e[0].offsetWidth;e.addClass("in")}else{e.removeClass("fade")}if(e.parent(".dropdown-menu")){e.closest("li.dropdown").addClass("active")}h&&h()}g?c.one(b.support.transition.end,f):f();c.removeClass("in")}};b.fn.tab=function(c){return this.each(function(){var e=b(this),d=e.data("tab");if(!d){e.data("tab",(d=new a(this)))}if(typeof c=="string"){d[c]()}})};b.fn.tab.Constructor=a;b(function(){b("body").on("click.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(c){c.preventDefault();b(this).tab("show")})})}(window.jQuery);!function(b){var a=function(d,c){this.init("tooltip",d,c)};a.prototype={constructor:a,init:function(f,e,d){var g,c;this.type=f;this.$element=b(e);this.options=this.getOptions(d);this.enabled=true;if(this.options.trigger!="manual"){g=this.options.trigger=="hover"?"mouseenter":"focus";c=this.options.trigger=="hover"?"mouseleave":"blur";this.$element.on(g,this.options.selector,b.proxy(this.enter,this));this.$element.on(c,this.options.selector,b.proxy(this.leave,this))}this.options.selector?(this._options=b.extend({},this.options,{trigger:"manual",selector:""})):this.fixTitle()},getOptions:function(c){c=b.extend({},b.fn[this.type].defaults,c,this.$element.data());if(c.delay&&typeof c.delay=="number"){c.delay={show:c.delay,hide:c.delay}}return c},enter:function(d){var c=b(d.currentTarget)[this.type](this._options).data(this.type);if(!c.options.delay||!c.options.delay.show){return c.show()}clearTimeout(this.timeout);c.hoverState="in";this.timeout=setTimeout(function(){if(c.hoverState=="in"){c.show()}},c.options.delay.show)},leave:function(d){var c=b(d.currentTarget)[this.type](this._options).data(this.type);if(this.timeout){clearTimeout(this.timeout)}if(!c.options.delay||!c.options.delay.hide){return c.hide()}c.hoverState="out";this.timeout=setTimeout(function(){if(c.hoverState=="out"){c.hide()}},c.options.delay.hide)},show:function(){var i,f,k,c,j,h,l;if(this.hasContent()&&this.enabled){i=this.tip();this.setContent();if(this.options.animation){i.addClass("fade")}h=typeof this.options.placement=="function"?this.options.placement.call(this,i[0],this.$element[0]):this.options.placement;f=/in/.test(h);i.remove().css({top:0,left:0,display:"block"}).appendTo(f?this.$element:document.body);k=this.getPosition(f);c=i[0].offsetWidth;j=i[0].offsetHeight;switch(f?h.split(" ")[1]:h){case"bottom":l={top:k.top+k.height,left:k.left+k.width/2-c/2};break;case"top":l={top:k.top-j,left:k.left+k.width/2-c/2};break;case"left":l={top:k.top+k.height/2-j/2,left:k.left-c};break;case"right":l={top:k.top+k.height/2-j/2,left:k.left+k.width};break}var e=b(window),d=f?h.split(" ")[1]:h;if(l.top<e.scrollTop()&&h=="top"){l.top=k.top+k.height;h=f?"inside bottom":"bottom"}l.top=Math.min(l.top,e.scrollTop()+e.height()-i.outerHeight());var g=0;if(l.left<e.scrollLeft()){g=l.left-e.scrollLeft()}var m=e.scrollLeft()+e.width()-i.outerWidth();if(l.left>m){g=l.left-m}l.left-=g;switch(f?h.split(" ")[1]:h){case"bottom":i.find(".tooltip-arrow").css("left",(i.outerWidth()/2)+g+"px");break;case"top":i.find(".tooltip-arrow").css("left",(i.outerWidth()/2)+g+"px");break;case"left":break;case"right":break}i.css(l).addClass(h).addClass("in")}},isHTML:function(c){return typeof c!="string"||(c.charAt(0)==="<"&&c.charAt(c.length-1)===">"&&c.length>=3)||/^(?:[^<]*<[\w\W]+>[^>]*$)/.exec(c)},setContent:function(){var d=this.tip(),c=this.getTitle();d.find(".tooltip-inner")[this.isHTML(c)?"html":"text"](c);d.removeClass("fade in top bottom left right")},hide:function(){var c=this,d=this.tip();d.removeClass("in");function e(){var f=setTimeout(function(){d.off(b.support.transition.end).remove()},500);d.one(b.support.transition.end,function(){clearTimeout(f);d.remove()})}b.support.transition&&this.$tip.hasClass("fade")?e():d.remove()},fixTitle:function(){var c=this.$element;if(c.attr("title")||typeof(c.attr("data-original-title"))!="string"){c.attr("data-original-title",c.attr("title")||"").removeAttr("title")}},hasContent:function(){return this.getTitle()},getPosition:function(c){return b.extend({},(c?{top:0,left:0}:this.$element.offset()),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight})},getTitle:function(){var e,c=this.$element,d=this.options;e=c.attr("data-original-title")||(typeof d.title=="function"?d.title.call(c[0]):d.title);return e},tip:function(){return this.$tip=this.$tip||b(this.options.template)},validate:function(){if(!this.$element[0].parentNode){this.hide();this.$element=null;this.options=null}},enable:function(){this.enabled=true},disable:function(){this.enabled=false},toggleEnabled:function(){this.enabled=!this.enabled},toggle:function(){this[this.tip().hasClass("in")?"hide":"show"]()}};b.fn.tooltip=function(c){return this.each(function(){var f=b(this),e=f.data("tooltip"),d=typeof c=="object"&&c;if(!e){f.data("tooltip",(e=new a(this,d)))}if(typeof c=="string"){e[c]()}})};b.fn.tooltip.Constructor=a;b.fn.tooltip.defaults={animation:false,placement:"top",selector:false,template:'<div class="bs-tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:"hover",title:"",delay:0}}(window.jQuery); \ No newline at end of file +!function(a){a(function(){a.support.transition=(function(){var b=(function(){var e=document.createElement("bootstrap"),d={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd",transition:"transitionend"},c;for(c in d){if(e.style[c]!==undefined){return d[c]}}}());return b&&{end:b}})()})}(window.jQuery);!function(b){var a=function(c){this.element=b(c)};a.prototype={constructor:a,show:function(){var i=this.element,f=i.closest("ul:not(.dropdown-menu)"),d=i.attr("data-target"),g,c,h;if(!d){d=i.attr("href");d=d&&d.replace(/.*(?=#[^\s]*$)/,"")}if(i.parent("li").hasClass("active")){return}g=f.find(".active a").last()[0];h=b.Event("show",{relatedTarget:g});i.trigger(h);if(h.isDefaultPrevented()){return}c=b(d);this.activate(i.parent("li"),f);this.activate(c,c.parent(),function(){i.trigger({type:"shown",relatedTarget:g})})},activate:function(e,d,h){var c=d.find("> .active"),g=h&&b.support.transition&&c.hasClass("fade");function f(){c.removeClass("active").find("> .dropdown-menu > .active").removeClass("active");e.addClass("active");if(g){e[0].offsetWidth;e.addClass("in")}else{e.removeClass("fade")}if(e.parent(".dropdown-menu")){e.closest("li.dropdown").addClass("active")}h&&h()}g?c.one(b.support.transition.end,f):f();c.removeClass("in")}};b.fn.tab=function(c){return this.each(function(){var e=b(this),d=e.data("tab");if(!d){e.data("tab",(d=new a(this)))}if(typeof c=="string"){d[c]()}})};b.fn.tab.Constructor=a;b(function(){b("body").on("click.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(c){c.preventDefault();b(this).tab("show")})})}(window.jQuery);!function(b){var a=function(d,c){this.init("tooltip",d,c)};a.prototype={constructor:a,init:function(f,e,d){var g,c;this.type=f;this.$element=b(e);this.options=this.getOptions(d);this.enabled=true;if(this.options.trigger!="manual"){g=this.options.trigger=="hover"?"mouseenter":"focus";c=this.options.trigger=="hover"?"mouseleave":"blur";this.$element.on(g,this.options.selector,b.proxy(this.enter,this));this.$element.on(c,this.options.selector,b.proxy(this.leave,this))}this.options.selector?(this._options=b.extend({},this.options,{trigger:"manual",selector:""})):this.fixTitle()},getOptions:function(c){c=b.extend({},b.fn[this.type].defaults,c,this.$element.data());if(c.delay&&typeof c.delay=="number"){c.delay={show:c.delay,hide:c.delay}}return c},enter:function(d){var c=b(d.currentTarget)[this.type](this._options).data(this.type);if(!c.options.delay||!c.options.delay.show){return c.show()}clearTimeout(this.timeout);c.hoverState="in";this.timeout=setTimeout(function(){if(c.hoverState=="in"){c.show()}},c.options.delay.show)},leave:function(d){var c=b(d.currentTarget)[this.type](this._options).data(this.type);if(this.timeout){clearTimeout(this.timeout)}if(!c.options.delay||!c.options.delay.hide){return c.hide()}c.hoverState="out";this.timeout=setTimeout(function(){if(c.hoverState=="out"){c.hide()}},c.options.delay.hide)},show:function(){var i,f,k,c,j,h,l;if(this.hasContent()&&this.enabled){i=this.tip();this.setContent();if(this.options.animation){i.addClass("fade")}h=typeof this.options.placement=="function"?this.options.placement.call(this,i[0],this.$element[0]):this.options.placement;f=/in/.test(h);i.remove().css({top:0,left:0,display:"block"}).appendTo(f?this.$element:document.body);k=this.getPosition(f);c=i[0].offsetWidth;j=i[0].offsetHeight;switch(f?h.split(" ")[1]:h){case"bottom":l={top:k.top+k.height,left:k.left+k.width/2-c/2};break;case"top":l={top:k.top-j,left:k.left+k.width/2-c/2};break;case"left":l={top:k.top+k.height/2-j/2,left:k.left-c};break;case"right":l={top:k.top+k.height/2-j/2,left:k.left+k.width};break}var e=b(window),d=f?h.split(" ")[1]:h;if(l.top<e.scrollTop()&&h=="top"){l.top=k.top+k.height;h=f?"inside bottom":"bottom"}l.top=Math.min(l.top,e.scrollTop()+e.height()-i.outerHeight());var g=0;if(l.left<e.scrollLeft()){g=l.left-e.scrollLeft()}var m=e.scrollLeft()+e.width()-i.outerWidth();if(l.left>m){g=l.left-m}l.left-=g;switch(f?h.split(" ")[1]:h){case"bottom":i.find(".tooltip-arrow").css("left",(i.outerWidth()/2)+g+"px");break;case"top":i.find(".tooltip-arrow").css("left",(i.outerWidth()/2)+g+"px");break;case"left":break;case"right":break}i.css(l).addClass(h).addClass("in")}},isHTML:function(c){return typeof c!="string"||(c.charAt(0)==="<"&&c.charAt(c.length-1)===">"&&c.length>=3)||/^(?:[^<]*<[\w\W]+>[^>]*$)/.exec(c)},setContent:function(){var d=this.tip(),c=this.getTitle();d.find(".tooltip-inner")[this.isHTML(c)?"html":"text"](c);d.removeClass("fade in top bottom left right")},hide:function(){var c=this,d=this.tip();d.removeClass("in");function e(){var f=setTimeout(function(){d.off(b.support.transition.end).remove()},500);d.one(b.support.transition.end,function(){clearTimeout(f);d.remove()})}b.support.transition&&this.$tip.hasClass("fade")?e():d.remove()},fixTitle:function(){var c=this.$element;if(c.attr("title")||typeof(c.attr("data-original-title"))!="string"){c.attr("data-original-title",c.attr("title")||"").removeAttr("title")}},hasContent:function(){return this.getTitle()},getPosition:function(c){return b.extend({},(c?{top:0,left:0}:this.$element.offset()),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight})},getTitle:function(){var e,c=this.$element,d=this.options;e=c.attr("data-original-title")||(typeof d.title=="function"?d.title.call(c[0]):d.title);return e},tip:function(){return this.$tip=this.$tip||b(this.options.template)},validate:function(){if(!this.$element[0].parentNode){this.hide();this.$element=null;this.options=null}},enable:function(){this.enabled=true},disable:function(){this.enabled=false},toggleEnabled:function(){this.enabled=!this.enabled},toggle:function(){this[this.tip().hasClass("in")?"hide":"show"]()}};b.fn.tooltip=function(c){return this.each(function(){var f=b(this),e=f.data("tooltip"),d=typeof c=="object"&&c;if(!e){f.data("tooltip",(e=new a(this,d)))}if(typeof c=="string"){e[c]()}})};b.fn.tooltip.Constructor=a;b.fn.tooltip.defaults={animation:false,placement:"top",selector:false,template:'<div class="bs-tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:"hover",title:"",delay:0}}(window.jQuery); \ No newline at end of file diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 static/scripts/packed/viz/sweepster.js --- /dev/null +++ b/static/scripts/packed/viz/sweepster.js @@ -0,0 +1,1 @@ +var ToolInputsSettings=Backbone.Model.extend({defaults:{inputs:null,values:null}});var ToolParameterTree=Backbone.RelationalModel.extend({defaults:{tool:null,tree_data:null},initialize:function(b){var a=this;this.get("tool").get("inputs").each(function(c){if(!c.get_samples()){return}c.on("change:min change:max change:num_samples",function(d){if(d.get("in_ptree")){a.set_tree_data()}},a);c.on("change:in_ptree",function(d){if(d.get("in_ptree")){a.add_param(d)}else{a.remove_param(d)}a.set_tree_data()},a)});if(b.config){_.each(b.config,function(d){var c=a.get("tool").get("inputs").find(function(e){return e.get("name")===d.name});a.add_param(c);c.set(d)})}},add_param:function(a){if(a.get("ptree_index")){return}a.set("in_ptree",true);a.set("ptree_index",this.get_tree_params().length)},remove_param:function(a){a.set("in_ptree",false);a.set("ptree_index",null);_(this.get_tree_params()).each(function(b,c){b.set("ptree_index",c+1)})},set_tree_data:function(){var b=_.map(this.get_tree_params(),function(d){return{param:d,samples:d.get_samples()}});var a=0,c=function(g,d){var i=g[d],h=i.param,f=h.get("label"),e=i.samples;if(g.length-1===d){return _.map(e,function(j){return{id:a++,name:j,param:h,value:j}})}return _.map(e,function(j){return{id:a++,name:j,param:h,value:j,children:c(g,d+1)}})};this.set("tree_data",{name:"Root",id:a++,children:(b.length!==0?c(b,0):null)})},get_tree_params:function(){return _(this.get("tool").get("inputs").where({in_ptree:true})).sortBy(function(a){return a.get("ptree_index")})},get_num_leaves:function(){return this.get_tree_params().reduce(function(a,b){return a*b.get_samples().length},1)},get_node_settings:function(e){var c=this.get("tool").get_inputs_dict();var f=e.parent;if(f){while(f.depth!==0){c[f.param.get("name")]=f.value;f=f.parent}}var a=this,b=function(h,g){if(h.param){g[h.param.get("name")]=h.value}if(!h.children){return new ToolInputsSettings({inputs:a.get("tool").get("inputs"),values:g})}else{return _.flatten(_.map(h.children,function(i){return b(i,_.clone(g))}))}},d=b(e,c);if(!_.isArray(d)){d=[d]}return d},get_connected_nodes:function(c){var d=function(e){if(!e.children){return e}else{return _.flatten([e,_.map(e.children,function(f){return d(f)})])}};var b=[],a=c.parent;while(a){b.push(a);a=a.parent}return _.flatten([b,d(c)])},get_leaf:function(b){var c=this.get("tree_data"),a=function(d){return _.find(d,function(e){return b[e.param.get("name")]===e.value})};while(c.children){c=a(c.children)}return c},toJSON:function(){return this.get_tree_params().map(function(a){return{name:a.get("name"),min:a.get("min"),max:a.get("max"),num_samples:a.get("num_samples")}})}});var SweepsterTrack=Backbone.RelationalModel.extend({defaults:{track:null,mode:"Pack",settings:null,regions:null},relations:[{type:Backbone.HasMany,key:"regions",relatedModel:"GenomeRegion"}],initialize:function(a){if(a.track){var b=_.extend({data_url:galaxy_paths.get("raw_data_url"),converted_datasets_state_url:galaxy_paths.get("dataset_state_url")},a.track);this.set("track",object_from_template(b,{},null))}},same_settings:function(a){var b=this.get("settings"),c=a.get("settings");for(var d in b){if(!c[d]||b[d]!==c[d]){return false}}return true},toJSON:function(){return{track:this.get("track").to_dict(),settings:this.get("settings"),regions:this.get("regions")}}});var TrackCollection=Backbone.Collection.extend({model:SweepsterTrack});var SweepsterVisualization=Visualization.extend({defaults:_.extend({},Visualization.prototype.defaults,{dataset:null,tool:null,parameter_tree:null,regions:null,tracks:null,default_mode:"Pack"}),relations:[{type:Backbone.HasOne,key:"dataset",relatedModel:"Dataset"},{type:Backbone.HasOne,key:"tool",relatedModel:"Tool"},{type:Backbone.HasMany,key:"regions",relatedModel:"GenomeRegion"},{type:Backbone.HasMany,key:"tracks",relatedModel:"SweepsterTrack"}],initialize:function(a){var b=this.get("tool").copy(true);this.set("tool_with_samplable_inputs",b);this.set("parameter_tree",new ToolParameterTree({tool:b,config:a.tree_config}))},add_track:function(a){this.get("tracks").add(a)},toJSON:function(){return{id:this.get("id"),title:"Parameter exploration for dataset '"+this.get("dataset").get("name")+"'",type:"sweepster",dataset_id:this.get("dataset").id,tool_id:this.get("tool").id,regions:this.get("regions").toJSON(),tree_config:this.get("parameter_tree").toJSON(),tracks:this.get("tracks").toJSON()}}});var SweepsterTrackView=Backbone.View.extend({tagName:"tr",TILE_LEN:250,initialize:function(a){this.canvas_manager=a.canvas_manager;this.render();this.model.on("change:track change:mode",this.draw_tiles,this)},render:function(){var f=this.model.get("settings"),b=f.get("values"),d=$("<td/>").addClass("settings").appendTo(this.$el),c=$("<div/>").addClass("track-info").hide().appendTo(d);c.append($("<div/>").css("font-weight","bold").text("Track Settings"));f.get("inputs").each(function(h){c.append(h.get("label")+": "+b[h.get("name")]+"<br/>")});var a=this,g=$("<button/>").appendTo(c).text("Run on complete dataset").click(function(){c.toggle();a.trigger("run_on_dataset",f)});var e=create_icon_buttons_menu([{title:"Settings",icon_class:"gear track-settings",on_click:function(){c.toggle()}},{title:"Remove",icon_class:"cross-circle",on_click:function(){a.$el.remove();$(".bs-tooltip").remove()}}]);d.prepend(e.$el);this.model.get("regions").each(function(){a.$el.append($("<td/>").addClass("tile").html($("<img/>").attr("src",galaxy_paths.get("image_path")+"/loading_large_white_bg.gif")))});if(this.model.get("track")){this.draw_tiles()}},draw_tiles:function(){var b=this,a=this.model.get("track"),d=this.model.get("regions"),c=this.$el.find("td.tile");if(!a){return}$.when(a.data_manager.data_is_ready()).then(function(e){d.each(function(h,g){var f=h.length()/b.TILE_LEN,j=1/f,i=b.model.get("mode");$.when(a.data_manager.get_data(h,i,f,{})).then(function(l){var k=b.canvas_manager.new_canvas();k.width=b.TILE_LEN;k.height=a.get_canvas_height(l,i,j,k.width);a.draw_tile(l,k.getContext("2d"),i,f,h,j);$(c[g]).empty().append(k)})})})}});var ToolInputValOrSweepView=Backbone.View.extend({number_input_template:'<div class="form-row-input sweep"><input class="min" type="text" size="6" value="<%= min %>"> - <input class="max" type="text" size="6" value="<%= max %>"> samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>"></div>',select_input_template:'<div class="form-row-input sweep"><%= options %></div>',initialize:function(a){this.$el=a.tool_row;this.render()},render:function(){var b=this.model,f=b.get("type"),h=this.$el.find(".form-row-input"),d=null;h.find(":input").change(function(){b.set("value",$(this).val())});if(f==="number"){d=$(_.template(this.number_input_template,this.model.toJSON()))}else{if(f==="select"){var c=_.map(this.$el.find("select option"),function(i){return $(i).val()}),e=c.join(", ");d=$(_.template(this.select_input_template,{options:e}))}}d.insertAfter(h);var a=this,g=create_icon_buttons_menu([{title:"Add parameter to tree",icon_class:"plus-button",on_click:function(){b.set("in_ptree",true);h.hide();d.show();$(this).hide();a.$el.find(".icon-button.toggle").show()}},{title:"Remove parameter from tree",icon_class:"toggle",on_click:function(){b.set("in_ptree",false);d.hide();h.show();$(this).hide();a.$el.find(".icon-button.plus-button").show()}}],{});this.$el.prepend(g.$el);if(b.get("in_ptree")){h.hide();a.$el.find(".icon-button.plus-button").hide()}else{a.$el.find(".icon-button.toggle").hide();d.hide()}_.each(["min","max","num_samples"],function(i){d.find("."+i).change(function(){b.set(i,parseFloat($(this).val()))})})}});var ToolParameterTreeDesignView=Backbone.View.extend({className:"tree-design",initialize:function(a){this.render()},render:function(){var c=new ToolFormView({model:this.model.get("tool")});c.render();this.$el.append(c.$el);var b=this,a=b.model.get("tool").get("inputs");this.$el.find(".form-row").not(".form-actions").each(function(d){var e=new ToolInputValOrSweepView({model:a.at(d),tool_row:$(this)})})}});var ToolParameterTreeView=Backbone.View.extend({className:"tool-parameter-tree",initialize:function(a){this.model.on("change:tree_data",this.render,this)},render:function(){this.$el.children().remove();var i=this.model.get_tree_params();if(!i.length){return}this.width=100*(2+i.length);this.height=15*this.model.get_num_leaves();var h=this;var g=d3.layout.cluster().size([this.height,this.width-160]);var c=d3.svg.diagonal().projection(function(j){return[j.y,j.x]});var a=g.nodes(this.model.get("tree_data"));var d=_.uniq(_.pluck(a,"y"));_.each(i,function(l,k){var j=d[k+1],m=$("#center").position().left;h.$el.append($("<div>").addClass("label").text(l.get("label")).css("left",j+m))});var b=d3.select(this.$el[0]).append("svg").attr("width",this.width).attr("height",this.height+30).append("g").attr("transform","translate(40, 20)");var f=b.selectAll("path.link").data(g.links(a)).enter().append("path").attr("class","link").attr("d",c);var e=b.selectAll("g.node").data(a).enter().append("g").attr("class","node").attr("transform",function(j){return"translate("+j.y+","+j.x+")"}).on("mouseover",function(k){var j=_.pluck(h.model.get_connected_nodes(k),"id");e.filter(function(l){return _.find(j,function(m){return m===l.id})!==undefined}).style("fill","#f00")}).on("mouseout",function(){e.style("fill","#000")});e.append("circle").attr("r",9);e.append("text").attr("dx",function(j){return j.children?-12:12}).attr("dy",3).attr("text-anchor",function(j){return j.children?"end":"start"}).text(function(j){return j.name})}});var SweepsterVisualizationView=Backbone.View.extend({className:"Sweepster",helpText:"<div><h4>Getting Started</h4><ol><li>Create a parameter tree by using the icons next to the tool's parameter names to add or remove parameters.<li>Adjust the tree by using parameter inputs to select min, max, and number of samples<li>Run the tool with different settings by clicking on tree nodes</ol></div>",initialize:function(b){this.canvas_manager=new CanvasManager(this.$el.parents("body"));this.tool_param_tree_view=new ToolParameterTreeView({model:this.model.get("parameter_tree")});this.track_collection_container=$("<table/>").addClass("tracks");this.model.get("parameter_tree").on("change:tree_data",this.handle_node_clicks,this);var a=this;this.model.get("tracks").each(function(c){c.get("track").view=a});this.block_color=get_random_color();this.reverse_strand_color=get_random_color([this.block_color,"#ffffff"])},render:function(){var g=new ToolParameterTreeDesignView({model:this.model.get("parameter_tree")});$("#left").append(g.$el);var j=this,d=j.model.get("regions"),h=$("<tr/>").appendTo(this.track_collection_container);d.each(function(k){h.append($("<th>").text(k.toString()))});h.children().first().attr("colspan",2);var e=$("<div>").addClass("tiles");$("#right").append(e.append(this.track_collection_container));j.model.get("tracks").each(function(k){j.add_track(k)});var i=$(this.helpText).addClass("help"),f=create_icon_buttons_menu([{title:"Close",icon_class:"cross-circle",on_click:function(){$(".bs-tooltip").remove();i.remove()}}]);i.prepend(f.$el.css("float","right"));$("#center").append(i);this.tool_param_tree_view.render();$("#center").append(this.tool_param_tree_view.$el);this.handle_node_clicks();var c=create_icon_buttons_menu([{icon_class:"chevron-expand",title:"Set display mode"},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location="${h.url_for( controller='visualization', action='list' )}"}}],{tooltip_config:{placement:"bottom"}});var b=["Squish","Pack"],a={};_.each(b,function(k){a[k]=function(){j.model.set("default_mode",k);j.model.get("tracks").each(function(l){l.set("mode",k)})}});make_popupmenu(c.$el.find(".chevron-expand"),a);c.$el.attr("style","float: right");$("#right .unified-panel-header-inner").append(c.$el)},run_tool_on_dataset:function(b){var a=this.model.get("tool"),d=a.get("name"),c=this.model.get("dataset");a.set_input_values(b.get("values"));$.when(a.rerun(c)).then(function(e){});show_modal("Running "+d+" on complete dataset",d+" is running on dataset '"+c.get("name")+"'. Outputs are in the dataset's history.",{Ok:function(){hide_modal()}})},add_track:function(d){var b=this,c=this.model.get("parameter_tree");b.model.add_track(d);var a=new SweepsterTrackView({model:d,canvas_manager:b.canvas_manager});a.on("run_on_dataset",b.run_tool_on_dataset,b);b.track_collection_container.append(a.$el);a.$el.hover(function(){var f=c.get_leaf(d.get("settings").get("values"));var e=_.pluck(c.get_connected_nodes(f),"id");d3.select(b.tool_param_tree_view.$el[0]).selectAll("g.node").filter(function(g){return _.find(e,function(h){return h===g.id})!==undefined}).style("fill","#f00")},function(){d3.select(b.tool_param_tree_view.$el[0]).selectAll("g.node").style("fill","#000")});return d},handle_node_clicks:function(){var a=this,b=this.model.get("parameter_tree"),d=this.model.get("regions"),c=d3.select(this.tool_param_tree_view.$el[0]).selectAll("g.node");c.on("click",function(k,g){var f=a.model.get("tool"),j=a.model.get("dataset"),h=b.get_node_settings(k),e=$.Deferred();if(h.length>=10){show_modal("Whoa there cowboy!","You clicked on a node to try "+a.model.get("tool").get("name")+" with "+h.length+" different combinations of settings. You can only run 10 jobs at a time.",{Ok:function(){hide_modal();e.resolve(false)}})}else{e.resolve(true)}$.when(e).then(function(i){if(!i){return}var l=_.map(h,function(m){var n=new SweepsterTrack({settings:m,regions:d,mode:a.model.get("default_mode")});a.add_track(n);return n});_.each(l,function(n,m){setTimeout(function(){f.set_input_values(n.get("settings").get("values"));$.when(f.rerun(j,d)).then(function(p){var q=_.extend({data_url:galaxy_paths.get("raw_data_url"),converted_datasets_state_url:galaxy_paths.get("dataset_state_url")},p.first().get("track_config")),o=object_from_template(q,a,null);o.prefs.block_color=a.block_color;o.prefs.reverse_strand_color=a.reverse_strand_color;n.set("track",o)})},m*10000)})})})}}); \ No newline at end of file diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 static/scripts/packed/viz/trackster.js --- a/static/scripts/packed/viz/trackster.js +++ b/static/scripts/packed/viz/trackster.js @@ -1,1 +1,1 @@ -var class_module=function(b,a){var c=function(){var g=arguments[0];for(var f=1;f<arguments.length;f++){var d=arguments[f];for(var e in d){g[e]=d[e]}}return g};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 is_deferred=function(a){return("isResolved" in a)};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 n=function(t,s,i){return((t*299)+(s*587)+(i*114))/1000};var e=function(v,u,w,s,i,t){return(Math.max(v,s)-Math.min(v,s))+(Math.max(u,i)-Math.min(u,i))+(Math.max(w,t)-Math.min(w,t))};var g,o,f,k,q,h,r,c,d,b,p,m=false,l=0;do{g=Math.round(Math.random()*16777215);o=(g&16711680)>>16;f=(g&65280)>>8;k=g&255;d=n(o,f,k);m=true;for(j=0;j<a.length;j++){q=a[j];h=(q&16711680)>>16;r=(q&65280)>>8;c=q&255;b=n(h,r,c);p=e(o,f,k,h,r,c);if((Math.abs(d-b)<40)||(p<200)){m=false;break}}l++}while(!m&&l<=10);return"#"+(16777216+g).toString(16).substr(1,6)};var create_action_icon=function(c,b,a){return $("<a/>").attr("href","javascript:void(0);").attr("title",c).addClass("icon-button").addClass(b).tooltip().click(a)};var trackster_module=function(d,S){var o=d("class").extend,s=d("slotting"),I=d("painters");var m={};var k=function(Z,aa){m[Z.attr("id")]=aa};var l=function(Z,ab,ad,ac){ad=".group";var aa={};m[Z.attr("id")]=ac;Z.bind("drag",{handle:"."+ab,relative:true},function(al,am){var ak=$(this),ap=$(this).parent(),ah=ap.children(),aj=m[$(this).attr("id")],ag,af,an,ae,ai;af=$(this).parents(ad);if(af.length!==0){an=af.position().top;ae=an+af.outerHeight();if(am.offsetY<an){$(this).insertBefore(af);var ao=m[af.attr("id")];ao.remove_drawable(aj);ao.container.add_drawable_before(aj,ao);return}else{if(am.offsetY>ae){$(this).insertAfter(af);var ao=m[af.attr("id")];ao.remove_drawable(aj);ao.container.add_drawable(aj);return}}}af=null;for(ai=0;ai<ah.length;ai++){ag=$(ah.get(ai));an=ag.position().top;ae=an+ag.outerHeight();if(ag.is(ad)&&this!==ag.get(0)&&am.offsetY>=an&&am.offsetY<=ae){if(am.offsetY-an<ae-am.offsetY){ag.find(".content-div").prepend(this)}else{ag.find(".content-div").append(this)}if(aj.container){aj.container.remove_drawable(aj)}m[ag.attr("id")].add_drawable(aj);return}}for(ai=0;ai<ah.length;ai++){ag=$(ah.get(ai));if(am.offsetY<ag.position().top&&!(ag.hasClass("reference-track")||ag.hasClass("intro"))){break}}if(ai===ah.length){if(this!==ah.get(ai-1)){ap.append(this);m[ap.attr("id")].move_drawable(aj,ai)}}else{if(this!==ah.get(ai)){$(this).insertBefore(ah.get(ai));m[ap.attr("id")].move_drawable(aj,(am.deltaY>0?ai-1:ai))}}}).bind("dragstart",function(){aa["border-top"]=Z.css("border-top");aa["border-bottom"]=Z.css("border-bottom");$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css(aa)})};S.moveable=l;var Y=16,D=9,A=20,x=100,F=12000,P=400,H=5000,u=100,n="There was an error in indexing this dataset. ",G="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",B="No data for this chrom/contig.",t="Preparing data. This can take a while for a large dataset. If the visualization is saved and closed, preparation will continue in the background.",v="Tool cannot be rerun: ",a="Loading data...",T="Ready for display",N=10,E=20;function U(aa,Z){if(!Z){Z=0}var ab=Math.pow(10,Z);return Math.round(aa*ab)/ab}var p=function(aa,Z,ac){if(!p.id_counter){p.id_counter=0}this.id=p.id_counter++;this.name=ac.name;this.view=aa;this.container=Z;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name}],saved_values:ac.prefs,onchange:function(){this.track.set_name(this.track.config.values.name)}});this.prefs=this.config.values;this.drag_handle_class=ac.drag_handle_class;this.is_overview=false;this.action_icons={};this.content_visible=true;this.container_div=this.build_container_div();this.header_div=this.build_header_div();if(this.header_div){this.container_div.append(this.header_div);this.icons_div=$("<div/>").css("float","left").hide().appendTo(this.header_div);this.build_action_icons(this.action_icons_def);this.header_div.append($("<div style='clear: both'/>"));this.header_div.dblclick(function(ad){ad.stopPropagation()});var ab=this;this.container_div.hover(function(){ab.icons_div.show()},function(){ab.icons_div.hide()});$("<div style='clear: both'/>").appendTo(this.container_div)}};p.prototype.action_icons_def=[{name:"toggle_icon",title:"Hide/show content",css_class:"toggle",on_click_fn:function(Z){if(Z.content_visible){Z.action_icons.toggle_icon.addClass("toggle-expand").removeClass("toggle");Z.hide_contents();Z.content_visible=false}else{Z.action_icons.toggle_icon.addClass("toggle").removeClass("toggle-expand");Z.content_visible=true;Z.show_contents()}}},{name:"settings_icon",title:"Edit settings",css_class:"settings-icon",on_click_fn:function(aa){var ac=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},Z=function(){aa.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},ab=function(ad){if((ad.keyCode||ad.which)===27){ac()}else{if((ad.keyCode||ad.which)===13){Z()}}};$(window).bind("keypress.check_enter_esc",ab);show_modal("Configure",aa.config.build_form(),{Cancel:ac,OK:Z})}},{name:"remove_icon",title:"Remove",css_class:"remove-icon",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.remove()}}];o(p.prototype,{init:function(){},changed:function(){this.view.changed()},can_draw:function(){if(this.enabled&&this.content_visible){return true}return false},request_draw:function(){},_draw:function(){},to_dict:function(){},set_name:function(Z){this.old_name=this.name;this.name=Z;this.name_div.text(this.name)},revert_name:function(){if(this.old_name){this.name=this.old_name;this.name_div.text(this.name)}},remove:function(){this.changed();this.container.remove_drawable(this);var Z=this.view;this.container_div.hide(0,function(){$(this).remove();Z.update_intro_div()})},build_container_div:function(){},build_header_div:function(){},add_action_icon:function(aa,af,ae,ad,Z,ac){var ab=this;this.action_icons[aa]=$("<a/>").attr("href","javascript:void(0);").attr("title",af).addClass("icon-button").addClass(ae).tooltip().click(function(){ad(ab)}).appendTo(this.icons_div);if(ac){this.action_icons[aa].hide()}},build_action_icons:function(Z){var ab;for(var aa=0;aa<Z.length;aa++){ab=Z[aa];this.add_action_icon(ab.name,ab.title,ab.css_class,ab.on_click_fn,ab.prepend,ab.hide)}},update_icons:function(){},hide_contents:function(){},show_contents:function(){}});var w=function(aa,Z,ab){p.call(this,aa,Z,ab);this.obj_type=ab.obj_type;this.drawables=[]};o(w.prototype,p.prototype,{unpack_drawables:function(ab){this.drawables=[];var aa;for(var Z=0;Z<ab.length;Z++){aa=object_from_template(ab[Z],this.view,this);this.add_drawable(aa)}},init:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z].init()}},_draw:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z]._draw()}},to_dict:function(){var aa=[];for(var Z=0;Z<this.drawables.length;Z++){aa.push(this.drawables[Z].to_dict())}return{name:this.name,prefs:this.prefs,obj_type:this.obj_type,drawables:aa}},add_drawable:function(Z){this.drawables.push(Z);Z.container=this;this.changed()},add_drawable_before:function(ab,Z){this.changed();var aa=this.drawables.indexOf(Z);if(aa!==-1){this.drawables.splice(aa,0,ab);return true}return false},replace_drawable:function(ab,Z,aa){var ac=this.drawables.indexOf(ab);if(ac!==-1){this.drawables[ac]=Z;if(aa){ab.container_div.replaceWith(Z.container_div)}this.changed()}return ac},remove_drawable:function(aa){var Z=this.drawables.indexOf(aa);if(Z!==-1){this.drawables.splice(Z,1);aa.container=null;this.changed();return true}return false},move_drawable:function(aa,ab){var Z=this.drawables.indexOf(aa);if(Z!==-1){this.drawables.splice(Z,1);this.drawables.splice(ab,0,aa);this.changed();return true}return false}});var M=function(aa,Z,ac){o(ac,{obj_type:"DrawableGroup",drag_handle_class:"group-handle"});w.call(this,aa,Z,ac);this.content_div=$("<div/>").addClass("content-div").attr("id","group_"+this.id+"_content_div").appendTo(this.container_div);k(this.container_div,this);k(this.content_div,this);l(this.container_div,this.drag_handle_class,".group",this);this.filters_manager=new V(this);this.header_div.after(this.filters_manager.parent_div);this.saved_filters_managers=[];if("drawables" in ac){this.unpack_drawables(ac.drawables)}if("filters" in ac){var ab=this.filters_manager;this.filters_manager=new V(this,ac.filters);ab.parent_div.replaceWith(this.filters_manager.parent_div);if(ac.filters.visible){this.setup_multitrack_filtering()}}};o(M.prototype,p.prototype,w.prototype,{action_icons_def:[p.prototype.action_icons_def[0],p.prototype.action_icons_def[1],{name:"composite_icon",title:"Show composite track",css_class:"layers-stack",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.show_composite_track()}},{name:"filters_icon",title:"Filters",css_class:"filters-icon",on_click_fn:function(Z){if(Z.filters_manager.visible()){Z.filters_manager.clear_filters();Z._restore_filter_managers()}else{Z.setup_multitrack_filtering();Z.request_draw(true)}Z.filters_manager.toggle()}},p.prototype.action_icons_def[2]],build_container_div:function(){var Z=$("<div/>").addClass("group").attr("id","group_"+this.id);if(this.container){this.container.content_div.append(Z)}return Z},build_header_div:function(){var Z=$("<div/>").addClass("track-header");Z.append($("<div/>").addClass(this.drag_handle_class));this.name_div=$("<div/>").addClass("track-name").text(this.name).appendTo(Z);return Z},hide_contents:function(){this.tiles_div.hide()},show_contents:function(){this.tiles_div.show();this.request_draw()},update_icons:function(){var ab=this.drawables.length;if(ab===0){this.action_icons.composite_icon.hide();this.action_icons.filters_icon.hide()}else{if(ab===1){if(this.drawables[0] instanceof g){this.action_icons.composite_icon.show()}this.action_icons.filters_icon.hide()}else{var ai,ah,af,al=true,ad=this.drawables[0].get_type(),Z=0;for(ai=0;ai<ab;ai++){af=this.drawables[ai];if(af.get_type()!==ad){can_composite=false;break}if(af instanceof c){Z++}}if(al||Z===1){this.action_icons.composite_icon.show()}else{this.action_icons.composite_icon.hide();$(".bs-tooltip").remove()}if(Z>1&&Z===this.drawables.length){var am={},aa;af=this.drawables[0];for(ah=0;ah<af.filters_manager.filters.length;ah++){aa=af.filters_manager.filters[ah];am[aa.name]=[aa]}for(ai=1;ai<this.drawables.length;ai++){af=this.drawables[ai];for(ah=0;ah<af.filters_manager.filters.length;ah++){aa=af.filters_manager.filters[ah];if(aa.name in am){am[aa.name].push(aa)}}}this.filters_manager.remove_all();var ac,ae,ag,aj;for(var ak in am){ac=am[ak];if(ac.length===Z){ae=new Q({name:ac[0].name,index:ac[0].index});this.filters_manager.add_filter(ae)}}if(this.filters_manager.filters.length>0){this.action_icons.filters_icon.show()}else{this.action_icons.filters_icon.hide()}}else{this.action_icons.filters_icon.hide()}}}},_restore_filter_managers:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z].filters_manager=this.saved_filters_managers[Z]}this.saved_filters_managers=[]},setup_multitrack_filtering:function(){if(this.filters_manager.filters.length>0){this.saved_filters_managers=[];for(var Z=0;Z<this.drawables.length;Z++){drawable=this.drawables[Z];this.saved_filters_managers.push(drawable.filters_manager);drawable.filters_manager=this.filters_manager}}this.filters_manager.init_filters()},show_composite_track:function(){var ad=[];for(var aa=0;aa<this.drawables.length;aa++){ad.push(this.drawables[aa].name)}var ab="Composite Track of "+this.drawables.length+" tracks ("+ad.join(", ")+")";var ac=new g(this.view,this.view,{name:ab,drawables:this.drawables});var Z=this.container.replace_drawable(this,ac,true);ac.request_draw()},add_drawable:function(Z){w.prototype.add_drawable.call(this,Z);this.update_icons()},remove_drawable:function(Z){w.prototype.remove_drawable.call(this,Z);this.update_icons()},to_dict:function(){if(this.filters_manager.visible()){this._restore_filter_managers()}var Z=o(w.prototype.to_dict.call(this),{filters:this.filters_manager.to_dict()});if(this.filters_manager.visible()){this.setup_multitrack_filtering()}return Z},request_draw:function(Z,ab){for(var aa=0;aa<this.drawables.length;aa++){this.drawables[aa].request_draw(Z,ab)}}});var X=function(Z){o(Z,{obj_type:"View"});w.call(this,"View",Z.container,Z);this.chrom=null;this.vis_id=Z.vis_id;this.dbkey=Z.dbkey;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 CanvasManager(this.container.get(0).ownerDocument);this.reset()};_.extend(X.prototype,Backbone.Events);o(X.prototype,w.prototype,{init:function(){this.requested_redraw=false;var ab=this.container,Z=this;this.top_container=$("<div/>").addClass("top-container").appendTo(ab);this.browser_content_div=$("<div/>").addClass("content").css("position","relative").appendTo(ab);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(ab);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;k(this.viewport_container,Z);this.intro_div=$("<div/>").addClass("intro").appendTo(this.viewport_container).hide();var ac=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_datasets(add_datasets_url,add_track_async_url,function(ad){_.each(ad,function(ae){Z.add_drawable(object_from_template(ae,Z,Z))})})});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("trackster-nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("trackster-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 aa=function(ad){if(ad.type==="focusout"||(ad.keyCode||ad.which)===13||(ad.keyCode||ad.which)===27){if((ad.keyCode||ad.which)!==27){Z.go_to($(this).val())}$(this).hide();$(this).val("");Z.location_span.show();Z.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",aa).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").attr("original-title","Click to change location").tooltip({placement:"bottom"}).appendTo(this.nav_controls);this.location_span.click(function(){Z.location_span.hide();Z.chrom_select.hide();Z.nav_input.val(Z.chrom+":"+Z.low+"-"+Z.high);Z.nav_input.css("display","inline-block");Z.nav_input.select();Z.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/>").attr("id","zoom-out").attr("title","Zoom out").tooltip({placement:"bottom"}).click(function(){Z.zoom_out();Z.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a/>").attr("id","zoom-in").attr("title","Zoom in").tooltip({placement:"bottom"}).click(function(){Z.zoom_in();Z.request_redraw()}).appendTo(this.nav_controls);this.load_chroms_deferred=this.load_chroms({low:0});this.chrom_select.bind("change",function(){Z.change_chrom(Z.chrom_select.val())});this.browser_content_div.click(function(ad){$(this).find("input").trigger("blur")});this.browser_content_div.bind("dblclick",function(ad){Z.zoom_in(ad.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(ad,ae){this.current_x=ae.offsetX}).bind("drag",function(ad,af){var ag=af.offsetX-this.current_x;this.current_x=af.offsetX;var ae=Math.round(ag/Z.viewport_container.width()*(Z.max_high-Z.max_low));Z.move_delta(-ae)});this.overview_close.click(function(){Z.reset_overview()});this.viewport_container.bind("draginit",function(ad,ae){if(ad.clientX>Z.viewport_container.width()-16){return false}}).bind("dragstart",function(ad,ae){ae.original_low=Z.low;ae.current_height=ad.clientY;ae.current_x=ae.offsetX}).bind("drag",function(af,ah){var ad=$(this);var ai=ah.offsetX-ah.current_x;var ae=ad.scrollTop()-(af.clientY-ah.current_height);ad.scrollTop(ae);ah.current_height=af.clientY;ah.current_x=ah.offsetX;var ag=Math.round(ai/Z.viewport_container.width()*(Z.high-Z.low));Z.move_delta(ag)}).bind("mousewheel",function(af,ah,ae,ad){if(ae){ae*=50;var ag=Math.round(-ae/Z.viewport_container.width()*(Z.high-Z.low));Z.move_delta(ag)}});this.top_labeltrack.bind("dragstart",function(ad,ae){return $("<div />").css({height:Z.browser_content_div.height()+Z.top_labeltrack.height()+Z.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(ah,ai){$(ai.proxy).css({left:Math.min(ah.pageX,ai.startX)-Z.container.offset().left,width:Math.abs(ah.pageX-ai.startX)});var ae=Math.min(ah.pageX,ai.startX)-Z.container.offset().left,ad=Math.max(ah.pageX,ai.startX)-Z.container.offset().left,ag=(Z.high-Z.low),af=Z.viewport_container.width();Z.update_location(Math.round(ae/af*ag)+Z.low,Math.round(ad/af*ag)+Z.low)}).bind("dragend",function(ai,aj){var ae=Math.min(ai.pageX,aj.startX),ad=Math.max(ai.pageX,aj.startX),ag=(Z.high-Z.low),af=Z.viewport_container.width(),ah=Z.low;Z.low=Math.round(ae/af*ag)+ah;Z.high=Math.round(ad/af*ag)+ah;$(aj.proxy).remove();Z.request_redraw()});this.add_label_track(new W(this,{content_div:this.top_labeltrack}));this.add_label_track(new W(this,{content_div:this.nav_labeltrack}));$(window).bind("resize",function(){if(this.resize_timer){clearTimeout(this.resize_timer)}this.resize_timer=setTimeout(function(){Z.resize_window()},500)});$(document).bind("redraw",function(){Z.redraw()});this.reset();$(window).trigger("resize")},changed:function(){this.has_changes=true},update_intro_div:function(){if(this.drawables.length===0){this.intro_div.show()}else{this.intro_div.hide()}},trigger_navigate:function(aa,ac,Z,ad){if(this.timer){clearTimeout(this.timer)}if(ad){var ab=this;this.timer=setTimeout(function(){ab.trigger("navigate",aa+":"+ac+"-"+Z)},500)}else{view.trigger("navigate",aa+":"+ac+"-"+Z)}},update_location:function(Z,ab){this.location_span.text(commatize(Z)+" - "+commatize(ab));this.nav_input.val(this.chrom+":"+commatize(Z)+"-"+commatize(ab));var aa=view.chrom_select.val();if(aa!==""){this.trigger_navigate(aa,view.low,view.high,true)}},load_chroms:function(ab){ab.num=u;ab.dbkey=this.dbkey;var Z=this,aa=$.Deferred();$.ajax({url:chrom_url,data:ab,dataType:"json",success:function(ad){if(ad.chrom_info.length===0){alert("Invalid chromosome: "+ab.chrom);return}if(ad.reference){Z.add_label_track(new y(Z))}Z.chrom_data=ad.chrom_info;var ag='<option value="">Select Chrom/Contig</option>';for(var af=0,ac=Z.chrom_data.length;af<ac;af++){var ae=Z.chrom_data[af].chrom;ag+='<option value="'+ae+'">'+ae+"</option>"}if(ad.prev_chroms){ag+='<option value="previous">Previous '+u+"</option>"}if(ad.next_chroms){ag+='<option value="next">Next '+u+"</option>"}Z.chrom_select.html(ag);Z.chrom_start_index=ad.start_index;aa.resolve(ad)},error:function(){alert("Could not load chroms for this dbkey:",Z.dbkey)}});return aa},change_chrom:function(ae,aa,ag){var ab=this;if(!ab.chrom_data){ab.load_chroms_deferred.then(function(){ab.change_chrom(ae,aa,ag)});return}if(!ae||ae==="None"){return}if(ae==="previous"){ab.load_chroms({low:this.chrom_start_index-u});return}if(ae==="next"){ab.load_chroms({low:this.chrom_start_index+u});return}var af=$.grep(ab.chrom_data,function(ah,ai){return ah.chrom===ae})[0];if(af===undefined){ab.load_chroms({chrom:ae},function(){ab.change_chrom(ae,aa,ag)});return}else{if(ae!==ab.chrom){ab.chrom=ae;ab.chrom_select.val(ab.chrom);ab.max_high=af.len-1;ab.reset();ab.request_redraw(true);for(var ad=0,Z=ab.drawables.length;ad<Z;ad++){var ac=ab.drawables[ad];if(ac.init){ac.init()}}if(ab.reference_track){ab.reference_track.init()}}if(aa!==undefined&&ag!==undefined){ab.low=Math.max(aa,0);ab.high=Math.min(ag,ab.max_high)}else{ab.low=0;ab.high=ab.max_high}ab.reset_overview();ab.request_redraw()}},go_to:function(ad){ad=ad.replace(/ |,/g,"");var ah=this,Z,ac,aa=ad.split(":"),af=aa[0],ag=aa[1];if(ag!==undefined){try{var ae=ag.split("-");Z=parseInt(ae[0],10);ac=parseInt(ae[1],10)}catch(ab){return false}}ah.change_chrom(af,Z,ac)},move_fraction:function(ab){var Z=this;var aa=Z.high-Z.low;this.move_delta(ab*aa)},move_delta:function(ac){var Z=this;var ab=Z.high-Z.low;if(Z.low-ac<Z.max_low){Z.low=Z.max_low;Z.high=Z.max_low+ab}else{if(Z.high-ac>Z.max_high){Z.high=Z.max_high;Z.low=Z.max_high-ab}else{Z.high-=ac;Z.low-=ac}}Z.request_redraw();var aa=Z.chrom_select.val();this.trigger_navigate(aa,Z.low,Z.high,true)},add_drawable:function(Z){w.prototype.add_drawable.call(this,Z);Z.init();this.changed();this.update_intro_div()},add_label_track:function(Z){Z.view=this;Z.init();this.label_tracks.push(Z)},remove_drawable:function(ab,aa){w.prototype.remove_drawable.call(this,ab);if(aa){var Z=this;ab.container_div.hide(0,function(){$(this).remove();Z.update_intro_div()})}},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(ah,Z,ag,ai){var af=this,ae=(ai?[ai]:af.drawables),ab;var aa;for(var ad=0;ad<ae.length;ad++){aa=ae[ad];ab=-1;for(var ac=0;ac<af.tracks_to_be_redrawn.length;ac++){if(af.tracks_to_be_redrawn[ac][0]===aa){ab=ac;break}}if(ab<0){af.tracks_to_be_redrawn.push([aa,Z,ag])}else{af.tracks_to_be_redrawn[ad][1]=Z;af.tracks_to_be_redrawn[ad][2]=ag}}if(!this.requested_redraw){requestAnimationFrame(function(){af._redraw(ah)});this.requested_redraw=true}},_redraw:function(aj){this.requested_redraw=false;var ag=this.low,ac=this.high;if(ag<this.max_low){ag=this.max_low}if(ac>this.max_high){ac=this.max_high}var ai=this.high-this.low;if(this.high!==0&&ai<this.min_separation){ac=ag+this.min_separation}this.low=Math.floor(ag);this.high=Math.ceil(ac);this.update_location(this.low,this.high);this.resolution_b_px=(this.high-this.low)/this.viewport_container.width();this.resolution_px_b=this.viewport_container.width()/(this.high-this.low);var Z=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var af=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ak=13;this.overview_box.css({left:Z,width:Math.max(ak,af)}).show();if(af<ak){this.overview_box.css("left",Z-(ak-af)/2)}if(this.overview_highlight){this.overview_highlight.css({left:Z,width:af})}if(!aj){var ab,aa,ah;for(var ad=0,ae=this.tracks_to_be_redrawn.length;ad<ae;ad++){ab=this.tracks_to_be_redrawn[ad][0];aa=this.tracks_to_be_redrawn[ad][1];ah=this.tracks_to_be_redrawn[ad][2];if(ab){ab._draw(aa,ah)}}this.tracks_to_be_redrawn=[];for(ad=0,ae=this.label_tracks.length;ad<ae;ad++){this.label_tracks[ad]._draw()}}},zoom_in:function(aa,ab){if(this.max_high===0||this.high-this.low<=this.min_separation){return}var ac=this.high-this.low,ad=ac/2+this.low,Z=(ac/this.zoom_factor)/2;if(aa){ad=aa/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(ad-Z);this.high=Math.round(ad+Z);this.changed();this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var aa=this.high-this.low,ab=aa/2+this.low,Z=(aa*this.zoom_factor)/2;this.low=Math.round(ab-Z);this.high=Math.round(ab+Z);this.changed();this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.request_redraw()},set_overview:function(ab){if(this.overview_drawable){if(this.overview_drawable.dataset_id===ab.dataset_id){return}this.overview_viewport.find(".track").remove()}var aa=ab.copy({content_div:this.overview_viewport}),Z=this;aa.header_div.hide();aa.is_overview=true;Z.overview_drawable=aa;this.overview_drawable.postdraw_actions=function(){Z.overview_highlight.show().height(Z.overview_drawable.content_div.height());Z.overview_viewport.height(Z.overview_drawable.content_div.height()+Z.overview_box.outerHeight());Z.overview_close.show();Z.resize_window()};Z.overview_drawable.request_draw();this.changed()},reset_overview:function(){$(".bs-tooltip").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 q=function(ab,ag,ac){this.track=ab;this.name=ag.name;this.params=[];var an=ag.params;for(var ad=0;ad<an.length;ad++){var ai=an[ad],aa=ai.name,am=ai.label,ae=unescape(ai.html),ao=ai.value,ak=ai.type;if(ak==="number"){this.params.push(new e(aa,am,ae,(aa in ac?ac[aa]:ao),ai.min,ai.max))}else{if(ak==="select"){this.params.push(new K(aa,am,ae,(aa in ac?ac[aa]:ao)))}else{console.log("WARNING: unrecognized tool parameter type:",aa,ak)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(aq){aq.stopPropagation()}).click(function(aq){aq.stopPropagation()}).bind("dblclick",function(aq){aq.stopPropagation()});var al=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var aj=this.params;var ah=this;$.each(this.params,function(ar,av){var au=$("<div>").addClass("param-row").appendTo(ah.parent_div);var aq=$("<div>").addClass("param-label").text(av.label).appendTo(au);var at=$("<div/>").addClass("param-input").html(av.html).appendTo(au);at.find(":input").val(av.value);$("<div style='clear: both;'/>").appendTo(au)});this.parent_div.find("input").click(function(){$(this).select()});var ap=$("<div>").addClass("param-row").appendTo(this.parent_div);var af=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(ap);var Z=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(ap);Z.click(function(){ah.run_on_region()});af.click(function(){ah.run_on_dataset()});if("visible" in ac&&ac.visible){this.parent_div.show()}};o(q.prototype,{update_params:function(){for(var Z=0;Z<this.params.length;Z++){this.params[Z].update_value()}},state_dict:function(){var aa={};for(var Z=0;Z<this.params.length;Z++){aa[this.params[Z].name]=this.params[Z].value}aa.visible=this.parent_div.is(":visible");return aa},get_param_values_dict:function(){var Z={};this.parent_div.find(":input").each(function(){var aa=$(this).attr("name"),ab=$(this).val();Z[aa]=ab});return Z},get_param_values:function(){var Z=[];this.parent_div.find(":input").each(function(){var aa=$(this).attr("name"),ab=$(this).val();if(aa){Z[Z.length]=ab}});return Z},run_on_dataset:function(){var Z=this;Z.run({target_dataset_id:this.track.original_dataset_id,tool_id:Z.name},null,function(aa){show_modal(Z.name+" is Running",Z.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var aa={target_dataset_id:this.track.original_dataset_id,action:"rerun",tool_id:this.name,regions:[{chrom:this.track.view.chrom,start:this.track.view.low,end:this.track.view.high}]},ae=this.track,ab=aa.tool_id+ae.tool_region_and_parameters_str(aa.chrom,aa.low,aa.high),Z;if(ae.container===view){var ad=new M(view,view,{name:this.name});var ac=ae.container.replace_drawable(ae,ad,false);ad.container_div.insertBefore(ae.view.content_div.children()[ac]);ad.add_drawable(ae);ae.container_div.appendTo(ad.content_div);Z=ad}else{Z=ae.container}var af=new ae.constructor(view,Z,{name:ab,hda_ldda:"hda"});af.init_for_tool_data();af.change_mode(ae.mode);af.set_filters_manager(ae.filters_manager.copy(af));af.update_icons();Z.add_drawable(af);af.tiles_div.text("Starting job.");this.update_params();this.run(aa,af,function(ag){af.set_dataset(new Dataset(ag));af.tiles_div.text("Running job.");af.init()})},run:function(Z,ab,ac){Z.inputs=this.get_param_values_dict();var aa=new ServerStateDeferred({ajax_settings:{url:galaxy_paths.get("tool_url"),data:JSON.stringify(Z),dataType:"json",contentType:"application/json",type:"POST"},interval:2000,success_fn:function(ad){return ad!=="pending"}});$.when(aa.go()).then(function(ad){if(ad==="no converter"){ab.container_div.addClass("error");ab.content_div.text(G)}else{if(ad.error){ab.container_div.addClass("error");ab.content_div.text(v+ad.message)}else{ac(ad)}}})}});var K=function(aa,Z,ab,ac){this.name=aa;this.label=Z;this.html=$(ab);this.value=ac};o(K.prototype,{update_value:function(){this.value=$(this.html).val()}});var e=function(ab,aa,ad,ae,ac,Z){K.call(this,ab,aa,ad,ae);this.min=ac;this.max=Z};o(e.prototype,K.prototype,{update_value:function(){K.prototype.update_value.call(this);this.value=parseFloat(this.value)}});var f=function(Z){this.manager=null;this.name=Z.name;this.index=Z.index;this.tool_id=Z.tool_id;this.tool_exp_name=Z.tool_exp_name};o(f.prototype,{to_dict:function(){return{name:this.name,index:this.index,tool_id:this.tool_id,tool_exp_name:this.tool_exp_name}}});var Q=function(ah){f.call(this,ah);this.low=("low" in ah?ah.low:-Number.MAX_VALUE);this.high=("high" in ah?ah.high:Number.MAX_VALUE);this.min=("min" in ah?ah.min:Number.MAX_VALUE);this.max=("max" in ah?ah.max:-Number.MAX_VALUE);this.container=null;this.slider=null;this.slider_label=null;var ad=function(ai,aj,ak){ai.click(function(){var ap=aj.text(),an=parseFloat(ak.slider("option","max")),am=(an<=1?4:an<=1000000?an.toString().length:6),ao=false,al=$(this).parents(".slider-row");al.addClass("input");if(ak.slider("option","values")){am=2*am+1;ao=true}aj.text("");$("<input type='text'/>").attr("size",am).attr("maxlength",am).attr("value",ap).appendTo(aj).focus().select().click(function(aq){aq.stopPropagation()}).blur(function(){$(this).remove();aj.text(ap);al.removeClass("input")}).keyup(function(av){if(av.keyCode===27){$(this).trigger("blur")}else{if(av.keyCode===13){var at=ak.slider("option","min"),aq=ak.slider("option","max"),au=function(aw){return(isNaN(aw)||aw>aq||aw<at)},ar=$(this).val();if(!ao){ar=parseFloat(ar);if(au(ar)){alert("Parameter value must be in the range ["+at+"-"+aq+"]");return $(this)}}else{ar=ar.split("-");ar=[parseFloat(ar[0]),parseFloat(ar[1])];if(au(ar[0])||au(ar[1])){alert("Parameter value must be in the range ["+at+"-"+aq+"]");return $(this)}}ak.slider((ao?"values":"value"),ar);al.removeClass("input")}}})})};var aa=this;aa.parent_div=$("<div/>").addClass("filter-row slider-row");var Z=$("<div/>").addClass("elt-label").appendTo(aa.parent_div),af=$("<span/>").addClass("slider-name").text(aa.name+" ").appendTo(Z),ab=$("<span/>").text(this.low+"-"+this.high),ac=$("<span/>").addClass("slider-value").appendTo(Z).append("[").append(ab).append("]");aa.values_span=ab;var ae=$("<div/>").addClass("slider").appendTo(aa.parent_div);aa.control_element=$("<div/>").attr("id",aa.name+"-filter-control").appendTo(ae);aa.control_element.slider({range:true,min:this.min,max:this.max,step:this.get_slider_step(this.min,this.max),values:[this.low,this.high],slide:function(ai,aj){aa.slide(ai,aj)},change:function(ai,aj){aa.control_element.slider("option","slide").call(aa.control_element,ai,aj)}});aa.slider=aa.control_element;aa.slider_label=ab;ad(ac,ab,aa.control_element);var ag=$("<div/>").addClass("display-controls").appendTo(aa.parent_div);this.transparency_icon=create_action_icon("Use filter for data transparency","layer-transparent",function(){if(aa.manager.alpha_filter!==aa){aa.manager.alpha_filter=aa;aa.manager.parent_div.find(".layer-transparent").removeClass("active").hide();aa.transparency_icon.addClass("active").show()}else{aa.manager.alpha_filter=null;aa.transparency_icon.removeClass("active")}aa.manager.track.request_draw(true,true)}).appendTo(ag).hide();this.height_icon=create_action_icon("Use filter for data height","arrow-resize-090",function(){if(aa.manager.height_filter!==aa){aa.manager.height_filter=aa;aa.manager.parent_div.find(".arrow-resize-090").removeClass("active").hide();aa.height_icon.addClass("active").show()}else{aa.manager.height_filter=null;aa.height_icon.removeClass("active")}aa.manager.track.request_draw(true,true)}).appendTo(ag).hide();aa.parent_div.hover(function(){aa.transparency_icon.show();aa.height_icon.show()},function(){if(aa.manager.alpha_filter!==aa){aa.transparency_icon.hide()}if(aa.manager.height_filter!==aa){aa.height_icon.hide()}});$("<div style='clear: both;'/>").appendTo(aa.parent_div)};o(Q.prototype,{to_dict:function(){var Z=f.prototype.to_dict.call(this);return o(Z,{type:"number",min:this.min,max:this.max,low:this.low,high:this.high})},copy:function(){return new Q({name:this.name,index:this.index,tool_id:this.tool_id,tool_exp_name:this.tool_exp_name})},get_slider_step:function(ab,Z){var aa=Z-ab;return(aa<=2?0.01:1)},slide:function(ab,ac){var aa=ac.values;this.values_span.text(aa[0]+"-"+aa[1]);this.low=aa[0];this.high=aa[1];var Z=this;setTimeout(function(){if(aa[0]===Z.low&&aa[1]===Z.high){Z.manager.track.request_draw(true,true)}},25)},applies_to:function(Z){if(Z.length>this.index){return true}return false},_keep_val:function(Z){return(isNaN(Z)||(Z>=this.low&&Z<=this.high))},keep:function(aa){if(!this.applies_to(aa)){return true}var ac=this;var ad=aa[this.index];if(ad instanceof Array){var ab=true;for(var Z=0;Z<ad.length;Z++){if(!this._keep_val(ad[Z])){ab=false;break}}return ab}else{return this._keep_val(aa[this.index])}},update_attrs:function(ac){var Z=false;if(!this.applies_to(ac)){return Z}var aa=ac[this.index];if(!(aa instanceof Array)){aa=[aa]}for(var ab=0;ab<aa.length;ab++){var ad=aa[ab];if(ad<this.min){this.min=Math.floor(ad);Z=true}if(ad>this.max){this.max=Math.ceil(ad);Z=true}}return Z},update_ui_elt:function(){if(this.min<this.max){this.parent_div.show()}else{this.parent_div.hide()}var aa=this.slider.slider("option","min"),Z=this.slider.slider("option","max");if(this.min<aa||this.max>Z){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",this.get_slider_step(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var V=function(ab,ah){this.track=ab;this.alpha_filter=null;this.height_filter=null;this.filters=[];this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(aj){aj.stopPropagation()}).click(function(aj){aj.stopPropagation()}).bind("dblclick",function(aj){aj.stopPropagation()}).bind("keydown",function(aj){aj.stopPropagation()});if(ah&&"filters" in ah){var Z=("alpha_filter" in ah?ah.alpha_filter:null),ac=("height_filter" in ah?ah.height_filter:null),ae=ah.filters,aa;for(var af=0;af<ae.length;af++){if(ae[af].type==="number"){aa=new Q(ae[af]);this.add_filter(aa);if(aa.name===Z){this.alpha_filter=aa;aa.transparency_icon.addClass("active").show()}if(aa.name===ac){this.height_filter=aa;aa.height_icon.addClass("active").show()}}else{console.log("ERROR: unsupported filter: ",name,type)}}if("visible" in ah&&ah.visible){this.parent_div.show()}}if(this.filters.length!==0){var ai=$("<div/>").addClass("param-row").appendTo(this.parent_div);var ag=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(ai);var ad=this;ag.click(function(){ad.run_on_dataset()})}};o(V.prototype,{show:function(){this.parent_div.show()},hide:function(){this.parent_div.hide()},toggle:function(){this.parent_div.toggle()},visible:function(){return this.parent_div.is(":visible")},to_dict:function(){var ac={},ab=[],aa;for(var Z=0;Z<this.filters.length;Z++){aa=this.filters[Z];ab.push(aa.to_dict())}ac.filters=ab;ac.alpha_filter=(this.alpha_filter?this.alpha_filter.name:null);ac.height_filter=(this.height_filter?this.height_filter.name:null);ac.visible=this.parent_div.is(":visible");return ac},copy:function(aa){var ab=new V(aa);for(var Z=0;Z<this.filters.length;Z++){ab.add_filter(this.filters[Z].copy())}return ab},add_filter:function(Z){Z.manager=this;this.parent_div.append(Z.parent_div);this.filters.push(Z)},remove_all:function(){this.filters=[];this.parent_div.children().remove()},init_filters:function(){for(var Z=0;Z<this.filters.length;Z++){var aa=this.filters[Z];aa.update_ui_elt()}},clear_filters:function(){for(var Z=0;Z<this.filters.length;Z++){var aa=this.filters[Z];aa.slider.slider("option","values",[aa.min,aa.max])}this.alpha_filter=null;this.height_filter=null;this.parent_div.find(".icon-button").hide()},run_on_dataset:function(){var af=function(aj,ah,ai){if(!(ah in aj)){aj[ah]=ai}return aj[ah]};var ae={},ag,Z;for(var ad=0;ad<this.filters.length;ad++){ag=this.filters[ad];if(ag.tool_id){if(ag.min!==ag.low){Z=af(ae,ag.tool_id,[]);Z[Z.length]=ag.tool_exp_name+" >= "+ag.low}if(ag.max!==ag.high){Z=af(ae,ag.tool_id,[]);Z[Z.length]=ag.tool_exp_name+" <= "+ag.high}}}var aa=[];for(var ac in ae){aa[aa.length]=[ac,ae[ac]]}(function ab(an,ak){var ai=ak[0],aj=ai[0],am=ai[1],al="("+am.join(") and (")+")",ah={cond:al,input:an,target_dataset_id:an,tool_id:aj},ak=ak.slice(1);$.getJSON(run_tool_url,ah,function(ao){if(ao.error){show_modal("Filter Dataset","Error running tool "+aj,{Close:hide_modal})}else{if(ak.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{ab(ao.dataset_id,ak)}}})})(this.track.dataset_id,aa)}});var z=function(Z,aa){I.Scaler.call(this,aa);this.filter=Z};z.prototype.gen_val=function(Z){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(Z[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var C=function(Z){this.track=Z.track;this.params=Z.params;this.values={};this.restore_values((Z.saved_values?Z.saved_values:{}));this.onchange=Z.onchange};o(C.prototype,{restore_values:function(Z){var aa=this;$.each(this.params,function(ab,ac){if(Z[ac.key]!==undefined){aa.values[ac.key]=Z[ac.key]}else{aa.values[ac.key]=ac.default_value}})},build_form:function(){var ac=this;var Z=$("<div />");var ab;function aa(ah,ad){for(var al=0;al<ah.length;al++){ab=ah[al];if(ab.hidden){continue}var af="param_"+al;var ap=ac.values[ab.key];var ar=$("<div class='form-row' />").appendTo(ad);ar.append($("<label />").attr("for",af).text(ab.label+":"));if(ab.type==="bool"){ar.append($('<input type="checkbox" />').attr("id",af).attr("name",af).attr("checked",ap))}else{if(ab.type==="text"){ar.append($('<input type="text"/>').attr("id",af).val(ap).click(function(){$(this).select()}))}else{if(ab.type==="select"){var an=$("<select />").attr("id",af);for(var aj=0;aj<ab.options.length;aj++){$("<option/>").text(ab.options[aj].label).attr("value",ab.options[aj].value).appendTo(an)}an.val(ap);ar.append(an)}else{if(ab.type==="color"){var aq=$("<div/>").appendTo(ar),am=$("<input />").attr("id",af).attr("name",af).val(ap).css("float","left").appendTo(aq).click(function(au){$(".bs-tooltip").removeClass("in");var at=$(this).siblings(".bs-tooltip").addClass("in");at.css({left:$(this).position().left+$(this).width()+5,top:$(this).position().top-($(at).height()/2)+($(this).height()/2)}).show();at.click(function(av){av.stopPropagation()});$(document).bind("click.color-picker",function(){at.hide();$(document).unbind("click.color-picker")});au.stopPropagation()}),ak=$("<a href='javascript:void(0)'/>").addClass("icon-button arrow-circle").appendTo(aq).attr("title","Set new random color").tooltip(),ao=$("<div class='bs-tooltip right' style='position: absolute;' />").appendTo(aq).hide(),ag=$("<div class='tooltip-inner' style='text-align: inherit'></div>").appendTo(ao),ae=$("<div class='tooltip-arrow'></div>").appendTo(ao),ai=$.farbtastic(ag,{width:100,height:100,callback:am,color:ap});aq.append($("<div/>").css("clear","both"));(function(at){ak.click(function(){at.setColor(get_random_color())})})(ai)}else{ar.append($("<input />").attr("id",af).attr("name",af).val(ap))}}}}if(ab.help){ar.append($("<div class='help'/>").text(ab.help))}}}aa(this.params,Z);return Z},update_from_form:function(Z){var ab=this;var aa=false;$.each(this.params,function(ac,ae){if(!ae.hidden){var af="param_"+ac;var ad=Z.find("#"+af).val();if(ae.type==="float"){ad=parseFloat(ad)}else{if(ae.type==="int"){ad=parseInt(ad)}else{if(ae.type==="bool"){ad=Z.find("#"+af).is(":checked")}}}if(ad!==ab.values[ae.key]){ab.values[ae.key]=ad;aa=true}}});if(aa){this.onchange();this.track.changed()}}});var b=function(Z,ad,ab,aa,ac){this.track=Z;this.region=ad;this.low=ad.get("start");this.high=ad.get("end");this.resolution=ab;this.html_elt=$("<div class='track-tile'/>").append(aa).height($(aa).attr("height"));this.data=ac;this.stale=false};b.prototype.predisplay_actions=function(){};var j=function(Z,ae,ab,aa,ac,ad){b.call(this,Z,ae,ab,aa,ac);this.max_val=ad};o(j.prototype,b.prototype);var L=function(ac,ak,ad,ab,af,am,ag,an,aa,aj){b.call(this,ac,ak,ad,ab,af);this.mode=ag;this.all_slotted=aa;this.feature_mapper=aj;this.has_icons=false;if(an){this.has_icons=true;var ah=this;ab=this.html_elt.children()[0],message_div=$("<div/>").addClass("tile-message").css({height:A-1,width:ab.width}).prependTo(this.html_elt);var ai=new GenomeRegion({chrom:ac.view.chrom,start:this.low,end:this.high}),al=af.length,ae=$("<a href='javascript:void(0);'/>").addClass("icon more-down").attr("title","For speed, only the first "+al+" features in this region were obtained from server. Click to get more data including depth").tooltip().appendTo(message_div),Z=$("<a href='javascript:void(0);'/>").addClass("icon more-across").attr("title","For speed, only the first "+al+" features in this region were obtained from server. Click to get more data excluding depth").tooltip().appendTo(message_div);ae.click(function(){ah.stale=true;ac.data_manager.get_more_data(ai,ac.mode,ah.resolution,{},ac.data_manager.DEEP_DATA_REQ);$(".bs-tooltip").hide();ac.request_draw(true)}).dblclick(function(ao){ao.stopPropagation()});Z.click(function(){ah.stale=true;ac.data_manager.get_more_data(ai,ac.mode,ah.resolution,{},ac.data_manager.BROAD_DATA_REQ);$(".bs-tooltip").hide();ac.request_draw(true)}).dblclick(function(ao){ao.stopPropagation()})}};o(L.prototype,b.prototype);L.prototype.predisplay_actions=function(){var aa=this,Z={};if(aa.mode!=="Pack"){return}$(this.html_elt).hover(function(){this.hovered=true;$(this).mousemove()},function(){this.hovered=false;$(this).parents(".track-content").children(".overlay").children(".feature-popup").remove()}).mousemove(function(al){if(!this.hovered){return}var ag=$(this).offset(),ak=al.pageX-ag.left,aj=al.pageY-ag.top,ap=aa.feature_mapper.get_feature_data(ak,aj),ah=(ap?ap[0]:null);$(this).parents(".track-content").children(".overlay").children(".feature-popup").each(function(){if(!ah||$(this).attr("id")!==ah.toString()){$(this).remove()}});if(ap){var ac=Z[ah];if(!ac){var ah=ap[0],am={name:ap[3],start:ap[1],end:ap[2],strand:ap[4]},af=aa.track.filters_manager.filters,ae;for(var ai=0;ai<af.length;ai++){ae=af[ai];am[ae.name]=ap[ae.index]}var ac=$("<div/>").attr("id",ah).addClass("feature-popup"),aq=$("<table/>"),ao,an,ar;for(ao in am){an=am[ao];ar=$("<tr/>").appendTo(aq);$("<th/>").appendTo(ar).text(ao);$("<td/>").attr("align","left").appendTo(ar).text(typeof(an)==="number"?U(an,2):an)}ac.append($("<div class='feature-popup-inner'>").append(aq));Z[ah]=ac}ac.appendTo($(this).parents(".track-content").children(".overlay"));var ad=ak+parseInt(aa.html_elt.css("left"))-ac.width()/2,ab=aj+parseInt(aa.html_elt.css("top"))+7;ac.css("left",ad+"px").css("top",ab+"px")}else{if(!al.isPropagationStopped()){al.stopPropagation();$(this).siblings().each(function(){$(this).trigger(al)})}}}).mouseleave(function(){$(this).parents(".track-content").children(".overlay").children(".feature-popup").remove()})};var h=function(ab,aa,ad){o(ad,{drag_handle_class:"draghandle"});p.call(this,ab,aa,ad);this.data_url=("data_url" in ad?ad.data_url:default_data_url);this.data_url_extra_params={};this.data_query_wait=("data_query_wait" in ad?ad.data_query_wait:H);this.dataset_check_url=("converted_datasets_state_url" in ad?ad.converted_datasets_state_url:converted_datasets_state_url);var Z=this,ac=new Dataset({id:ad.dataset_id,hda_ldda:ad.hda_ldda});this.data_manager=("data_manager" in ad?ad.data_manager:new GenomeDataManager({dataset:ac,data_url:Z.data_url,dataset_state_url:Z.dataset_check_url,data_mode_compatible:this.data_and_mode_compatible,can_subset:this.can_subset}));this.min_height_px=16;this.max_height_px=800;this.visible_height_px=0;this.content_div=$("<div class='track-content'>").appendTo(this.container_div);if(this.container){this.container.content_div.append(this.container_div);if(!("resize" in ad)||ad.resize){this.add_resize_handle()}}};o(h.prototype,p.prototype,{action_icons_def:[{name:"mode_icon",title:"Set display mode",css_class:"chevron-expand",on_click_fn:function(){}},p.prototype.action_icons_def[0],{name:"overview_icon",title:"Set as overview",css_class:"overview-icon",on_click_fn:function(Z){Z.view.set_overview(Z)}},p.prototype.action_icons_def[1],{name:"filters_icon",title:"Filters",css_class:"filters-icon",on_click_fn:function(Z){if(Z.filters_manager.visible()){Z.filters_manager.clear_filters()}else{Z.filters_manager.init_filters()}Z.filters_manager.toggle()}},{name:"tools_icon",title:"Tool",css_class:"hammer",on_click_fn:function(Z){Z.dynamic_tool_div.toggle();if(Z.dynamic_tool_div.is(":visible")){Z.set_name(Z.name+Z.tool_region_and_parameters_str())}else{Z.revert_name()}$(".bs-tooltip").remove()}},{name:"param_space_viz_icon",title:"Tool parameter space visualization",css_class:"arrow-split",on_click_fn:function(Z){var ac='<strong>Tool</strong>: <%= track.tool.name %><br/><strong>Dataset</strong>: <%= track.name %><br/><strong>Region(s)</strong>: <select name="regions"><option value="cur">current viewing area</option><option value="bookmarks">bookmarks</option><option value="both">current viewing area and bookmarks</option></select>',ab=_.template(ac,{track:Z});var ae=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},aa=function(){var ag=$('select[name="regions"] option:selected').val(),ai,af=new GenomeRegion({chrom:view.chrom,start:view.low,end:view.high}),ah=_.map($(".bookmark"),function(aj){return new GenomeRegion({from_str:$(aj).children(".position").text()})});if(ag==="cur"){ai=[af]}else{if(ag==="bookmarks"){ai=ah}else{ai=[af].concat(ah)}}hide_modal();window.location.href=galaxy_paths.get("paramamonster_url")+"?"+$.param({dataset_id:Z.dataset_id,hda_ldda:Z.hda_ldda,regions:JSON.stringify(new Backbone.Collection(ai).toJSON())})},ad=function(af){if((af.keyCode||af.which)===27){ae()}else{if((af.keyCode||af.which)===13){aa()}}};show_modal("Visualize tool parameter space and output from different parameter settings?",ab,{No:ae,Yes:aa})}},p.prototype.action_icons_def[2]],can_draw:function(){if(this.dataset_id&&p.prototype.can_draw.call(this)){return true}return false},build_container_div:function(){return $("<div/>").addClass("track").attr("id","track_"+this.id).css("position","relative")},build_header_div:function(){var Z=$("<div class='track-header'/>");if(this.view.editor){this.drag_div=$("<div/>").addClass(this.drag_handle_class).appendTo(Z)}this.name_div=$("<div/>").addClass("track-name").appendTo(Z).text(this.name).attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase());return Z},on_resize:function(){},add_resize_handle:function(){var Z=this;var ac=false;var ab=false;var aa=$("<div class='track-resize'>");$(Z.container_div).hover(function(){if(Z.content_visible){ac=true;aa.show()}},function(){ac=false;if(!ab){aa.hide()}});aa.hide().bind("dragstart",function(ad,ae){ab=true;ae.original_height=$(Z.content_div).height()}).bind("drag",function(ae,af){var ad=Math.min(Math.max(af.original_height+af.deltaY,Z.min_height_px),Z.max_height_px);$(Z.tiles_div).css("height",ad);Z.visible_height_px=(Z.max_height_px===ad?0:ad);Z.on_resize()}).bind("dragend",function(ad,ae){Z.tile_cache.clear();ab=false;if(!ac){aa.hide()}Z.config.values.height=Z.visible_height_px;Z.changed()}).appendTo(Z.container_div)},set_display_modes:function(ac,af){this.display_modes=ac;this.mode=(af?af:(this.config&&this.config.values.mode?this.config.values.mode:this.display_modes[0]));this.action_icons.mode_icon.attr("title","Set display mode (now: "+this.mode+")");var aa=this,ad={};for(var ab=0,Z=aa.display_modes.length;ab<Z;ab++){var ae=aa.display_modes[ab];ad[ae]=function(ag){return function(){aa.change_mode(ag);aa.icons_div.show();aa.container_div.mouseleave(function(){aa.icons_div.hide()})}}(ae)}make_popupmenu(this.action_icons.mode_icon,ad)},build_action_icons:function(){p.prototype.build_action_icons.call(this,this.action_icons_def);if(this.display_modes!==undefined){this.set_display_modes(this.display_modes)}},hide_contents:function(){this.tiles_div.hide();this.container_div.find(".yaxislabel, .track-resize").hide()},show_contents:function(){this.tiles_div.show();this.container_div.find(".yaxislabel, .track-resize").show();this.request_draw()},get_type:function(){if(this instanceof W){return"LabelTrack"}else{if(this instanceof y){return"ReferenceTrack"}else{if(this instanceof i){return"LineTrack"}else{if(this instanceof R){return"ReadTrack"}else{if(this instanceof O){return"VcfTrack"}else{if(this instanceof g){return"CompositeTrack"}else{if(this instanceof c){return"FeatureTrack"}}}}}}}return""},init:function(){var aa=this;aa.enabled=false;aa.tile_cache.clear();aa.data_manager.clear();aa.content_div.css("height","auto");aa.tiles_div.children().remove();aa.container_div.removeClass("nodata error pending");if(!aa.dataset_id){return}var Z=$.Deferred();$.getJSON(this.dataset_check_url,{hda_ldda:aa.hda_ldda,dataset_id:aa.dataset_id,chrom:aa.view.chrom},function(ab){if(!ab||ab==="error"||ab.kind==="error"){aa.container_div.addClass("error");aa.tiles_div.text(n);if(ab.message){var ac=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+ab.message+"</pre>",{Close:hide_modal})});aa.tiles_div.append(ac)}}else{if(ab==="no converter"){aa.container_div.addClass("error");aa.tiles_div.text(G)}else{if(ab==="no data"||(ab.data!==undefined&&(ab.data===null||ab.data.length===0))){aa.container_div.addClass("nodata");aa.tiles_div.text(B)}else{if(ab==="pending"){aa.container_div.addClass("pending");aa.tiles_div.html(t);setTimeout(function(){aa.init()},aa.data_query_wait)}else{if(ab==="data"||ab.status==="data"){if(ab.valid_chroms){aa.valid_chroms=ab.valid_chroms;aa.update_icons()}aa.tiles_div.text(T);if(aa.view.chrom){aa.tiles_div.text("");aa.tiles_div.css("height",aa.visible_height_px+"px");aa.enabled=true;$.when(aa.predraw_init()).done(function(){Z.resolve();aa.container_div.removeClass("nodata error pending");aa.request_draw()})}else{Z.resolve()}}}}}}});this.update_icons();return Z},predraw_init:function(){}});var J=function(ab,aa,ac){h.call(this,ab,aa,ac);var Z=this,ab=Z.view;l(Z.container_div,Z.drag_handle_class,".group",Z);this.filters_manager=new V(this,("filters" in ac?ac.filters:null));this.data_manager.set("filters_manager",this.filters_manager);this.filters_available=false;this.tool=("tool" in ac&&ac.tool?new q(this,ac.tool,ac.tool_state):null);this.tile_cache=new Cache(N);if(this.header_div){this.set_filters_manager(this.filters_manager);if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}}this.tiles_div=$("<div/>").addClass("tiles").appendTo(this.content_div);this.overlay_div=$("<div/>").addClass("overlay").appendTo(this.content_div);if(ac.mode){this.change_mode(ac.mode)}};o(J.prototype,p.prototype,h.prototype,{action_icons_def:h.prototype.action_icons_def.concat([{name:"show_more_rows_icon",title:"To minimize track height, not all feature rows are displayed. Click to display more rows.",css_class:"exclamation",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.slotters[Z.view.resolution_px_b].max_rows*=2;Z.request_draw(true)},hide:true}]),copy:function(Z){var aa=this.to_dict();o(aa,{data_manager:this.data_manager});var ab=new this.constructor(this.view,Z,aa);ab.change_mode(this.mode);ab.enabled=this.enabled;return ab},set_filters_manager:function(Z){this.filters_manager=Z;this.header_div.after(this.filters_manager.parent_div)},to_dict: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,filters:this.filters_manager.to_dict(),tool_state:(this.tool?this.tool.state_dict():{})}},change_mode:function(aa){var Z=this;Z.mode=aa;Z.config.values.mode=aa;Z.tile_cache.clear();Z.request_draw();this.action_icons.mode_icon.attr("title","Set display mode (now: "+Z.mode+")");return Z},update_icons:function(){var Z=this;if(Z.filters_available){Z.action_icons.filters_icon.show()}else{Z.action_icons.filters_icon.hide()}if(Z.tool){Z.action_icons.tools_icon.show();Z.action_icons.param_space_viz_icon.show()}else{Z.action_icons.tools_icon.hide();Z.action_icons.param_space_viz_icon.hide()}},_gen_tile_cache_key:function(aa,ab,Z){return aa+"_"+ab+"_"+Z},request_draw:function(aa,Z){this.view.request_redraw(false,aa,Z,this)},before_draw:function(){},_draw:function(aa,ak){if(!this.can_draw()){return}var ai=this.view.low,ae=this.view.high,ag=ae-ai,ab=this.view.container.width(),am=this.view.resolution_px_b,ad=this.view.resolution_b_px;if(this.is_overview){ai=this.view.max_low;ae=this.view.max_high;ad=Math.pow(RESOLUTION,Math.ceil(Math.log((view.max_high-view.max_low)/P)/Math.log(RESOLUTION)));am=ab/(view.max_high-view.max_low)}this.before_draw();this.tiles_div.children().addClass("remove");var Z=Math.floor(ai/(ad*P)),ah=true,al=[],af=function(an){return(an&&"track" in an)};while((Z*P*ad)<ae){var aj=this.draw_helper(aa,ab,Z,ad,this.tiles_div,am);if(af(aj)){al.push(aj)}else{ah=false}Z+=1}if(!ak){this.tiles_div.children(".remove").removeClass("remove").remove()}var ac=this;if(ah){this.tiles_div.children(".remove").remove();ac.postdraw_actions(al,ab,am,ak)}},postdraw_actions:function(ac,ad,af,Z){var ab=this;var ae=false;for(var aa=0;aa<ac.length;aa++){if(ac[aa].has_icons){ae=true;break}}if(ae){for(var aa=0;aa<ac.length;aa++){tile=ac[aa];if(!tile.has_icons){tile.html_elt.css("padding-top",A)}}}},draw_helper:function(Z,al,aq,ao,ae,af,am){var ak=this,au=this._gen_tile_cache_key(al,af,aq),ac=this._get_tile_bounds(aq,ao);if(!am){am={}}var at=(Z?undefined:ak.tile_cache.get_elt(au));if(at){ak.show_tile(at,ae,af);return at}var ai=true;var ap=ak.data_manager.get_data(ac,ak.mode,ao,ak.data_url_extra_params);if(is_deferred(ap)){ai=false}var ag;if(view.reference_track&&af>view.canvas_manager.char_width_px){ag=view.reference_track.data_manager.get_data(ac,ak.mode,ao,view.reference_track.data_url_extra_params);if(is_deferred(ag)){ai=false}}if(ai){o(ap,am.more_tile_data);var ah=ak.mode;if(ah==="Auto"){ah=ak.get_mode(ap);ak.update_auto_mode(ah)}var ab=ak.view.canvas_manager.new_canvas(),ar=ac.get("start"),aa=ac.get("end"),al=Math.ceil((aa-ar)*af)+ak.left_offset,aj=ak.get_canvas_height(ap,ah,af,al);ab.width=al;ab.height=aj;var an=ab.getContext("2d");an.translate(this.left_offset,0);var at=ak.draw_tile(ap,an,ah,ao,ac,af,ag);if(at!==undefined){ak.tile_cache.set_elt(au,at);ak.show_tile(at,ae,af)}return at}var ad=$.Deferred();$.when(ap,ag).then(function(){view.request_redraw(false,false,false,ak);ad.resolve()});return ad},get_canvas_height:function(Z,ab,ac,aa){return this.visible_height_px},draw_tile:function(Z,aa,ae,ac,ad,af,ab){console.log("Warning: TiledTrack.draw_tile() not implemented.")},show_tile:function(ab,ad,ae){var aa=this,Z=ab.html_elt;ab.predisplay_actions();var ac=(ab.low-(this.is_overview?this.view.max_low:this.view.low))*ae;if(this.left_offset){ac-=this.left_offset}Z.css({position:"absolute",top:0,left:ac});if(Z.hasClass("remove")){Z.removeClass("remove")}else{ad.append(Z)}aa.after_show_tile(ab)},after_show_tile:function(Z){this.max_height_px=Math.max(this.max_height_px,Z.html_elt.height());Z.html_elt.parent().children().css("height",this.max_height_px+"px");var aa=this.max_height_px;if(this.visible_height_px!==0){aa=Math.min(this.max_height_px,this.visible_height_px)}this.tiles_div.css("height",aa+"px")},_get_tile_bounds:function(Z,aa){var ac=Math.floor(Z*P*aa),ad=Math.ceil(P*aa),ab=(ac+ad<=this.view.max_high?ac+ad:this.view.max_high);return new GenomeRegion({chrom:this.view.chrom,start:ac,end:ab})},tool_region_and_parameters_str:function(ab,Z,ac){var aa=this,ad=(ab!==undefined&&Z!==undefined&&ac!==undefined?ab+":"+Z+"-"+ac:"all");return" - region=["+ad+"], parameters=["+aa.tool.get_param_values().join(", ")+"]"},data_and_mode_compatible:function(Z,aa){return true},can_subset:function(Z){return false},init_for_tool_data:function(){this.data_manager.set("data_url",raw_data_url);this.data_query_wait=1000;this.dataset_check_url=dataset_state_url;this.normal_postdraw_actions=this.postdraw_actions;this.postdraw_actions=function(ab,ac,ae,Z){var aa=this;aa.normal_postdraw_actions(ab,ac,ae,Z);aa.dataset_state_url=converted_datasets_state_url;aa.data_query_wait=H;var ad=new ServerStateDeferred({url:aa.dataset_state_url,url_params:{dataset_id:aa.dataset_id,hda_ldda:aa.hda_ldda},interval:aa.data_query_wait,success_fn:function(af){return af!=="pending"}});$.when(ad.go()).then(function(){aa.data_manager.set("data_url",default_data_url)});aa.postdraw_actions=aa.normal_postdraw_actions}}});var W=function(aa,Z){var ab={resize:false};h.call(this,aa,Z,ab);this.container_div.addClass("label-track")};o(W.prototype,h.prototype,{build_header_div:function(){},init:function(){this.enabled=true},_draw:function(){var ab=this.view,ac=ab.high-ab.low,af=Math.floor(Math.pow(10,Math.floor(Math.log(ac)/Math.log(10)))),Z=Math.floor(ab.low/af)*af,ad=this.view.container.width(),aa=$("<div style='position: relative; height: 1.3em;'></div>");while(Z<ab.high){var ae=(Z-ab.low)/ac*ad;aa.append($("<div class='label'>"+commatize(Z)+"</div>").css({position:"absolute",left:ae-1}));Z+=af}this.content_div.children(":first").remove();this.content_div.append(aa)}});var g=function(aa,Z,ad){J.call(this,aa,Z,ad);this.drawables=[];this.left_offset=0;if("drawables" in ad){var ac;for(var ab=0;ab<ad.drawables.length;ab++){ac=ad.drawables[ab];this.drawables[ab]=object_from_template(ac,aa,null);if(ac.left_offset>this.left_offset){this.left_offset=ac.left_offset}}this.enabled=true}if(this.drawables.length!==0){this.set_display_modes(this.drawables[0].display_modes,this.drawables[0].mode)}this.update_icons();this.obj_type="CompositeTrack"};o(g.prototype,J.prototype,{action_icons_def:[{name:"composite_icon",title:"Show individual tracks",css_class:"layers-stack",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.show_group()}}].concat(J.prototype.action_icons_def),to_dict:w.prototype.to_dict,add_drawable:w.prototype.add_drawable,unpack_drawables:w.prototype.unpack_drawables,change_mode:function(Z){J.prototype.change_mode.call(this,Z);for(var aa=0;aa<this.drawables.length;aa++){this.drawables[aa].change_mode(Z)}},init:function(){var ab=[];for(var aa=0;aa<this.drawables.length;aa++){ab.push(this.drawables[aa].init())}var Z=this;$.when.apply($,ab).then(function(){Z.enabled=true;Z.request_draw()})},update_icons:function(){this.action_icons.filters_icon.hide();this.action_icons.tools_icon.hide();this.action_icons.param_space_viz_icon.hide()},can_draw:p.prototype.can_draw,draw_helper:function(aa,ap,aw,at,ah,aj,aq){var ao=this,aA=this._gen_tile_cache_key(ap,aj,aw),ae=this._get_tile_bounds(aw,at);if(!aq){aq={}}var az=(aa?undefined:ao.tile_cache.get_elt(aA));if(az){ao.show_tile(az,ah,aj);return az}var ai=[],ao,am=true,au,ak;for(var av=0;av<this.drawables.length;av++){ao=this.drawables[av];au=ao.data_manager.get_data(ae,ao.mode,at,ao.data_url_extra_params);if(is_deferred(au)){am=false}ai.push(au);ak=null;if(view.reference_track&&aj>view.canvas_manager.char_width_px){ak=view.reference_track.data_manager.get_data(ae,ao.mode,at,view.reference_track.data_url_extra_params);if(is_deferred(ak)){am=false}}ai.push(ak)}if(am){o(au,aq.more_tile_data);this.tile_predraw_init();var ad=ao.view.canvas_manager.new_canvas(),af=ao._get_tile_bounds(aw,at),ax=ae.get("start"),ab=ae.get("end"),ay=0,ap=Math.ceil((ab-ax)*aj)+this.left_offset,an=0,ac=[];var Z=0;for(var av=0;av<this.drawables.length;av++,ay+=2){ao=this.drawables[av];au=ai[ay];var al=ao.mode;if(al==="Auto"){al=ao.get_mode(au);ao.update_auto_mode(al)}ac.push(al);Z=ao.get_canvas_height(au,al,aj,ap);if(Z>an){an=Z}}ad.width=ap;ad.height=(aq.height?aq.height:an);ay=0;var ar=ad.getContext("2d");ar.translate(this.left_offset,0);ar.globalAlpha=0.5;ar.globalCompositeOperation="source-over";for(var av=0;av<this.drawables.length;av++,ay+=2){ao=this.drawables[av];au=ai[ay];ak=ai[ay+1];az=ao.draw_tile(au,ar,ac[av],at,ae,aj,ak)}this.tile_cache.set_elt(aA,az);this.show_tile(az,ah,aj);return az}var ag=$.Deferred(),ao=this;$.when.apply($,ai).then(function(){view.request_redraw(false,false,false,ao);ag.resolve()});return ag},show_group:function(){var ac=new M(this.view,this.container,{name:this.name}),Z;for(var ab=0;ab<this.drawables.length;ab++){Z=this.drawables[ab];ac.add_drawable(Z);Z.container=ac;ac.content_div.append(Z.container_div)}var aa=this.container.replace_drawable(this,ac,true);ac.request_draw()},tile_predraw_init:function(){var ac=Number.MAX_VALUE,Z=-ac,aa;for(var ab=0;ab<this.drawables.length;ab++){aa=this.drawables[ab];if(aa instanceof i){if(aa.prefs.min_value<ac){ac=aa.prefs.min_value}if(aa.prefs.max_value>Z){Z=aa.prefs.max_value}}}for(var ab=0;ab<this.drawables.length;ab++){aa=this.drawables[ab];aa.prefs.min_value=ac;aa.prefs.max_value=Z}},postdraw_actions:function(ab,ae,ag,aa){J.prototype.postdraw_actions.call(this,ab,ae,ag,aa);var ad=-1;for(var ac=0;ac<ab.length;ac++){var Z=ab[ac].html_elt.find("canvas").height();if(Z>ad){ad=Z}}for(var ac=0;ac<ab.length;ac++){var af=ab[ac];if(af.html_elt.find("canvas").height()!==ad){this.draw_helper(true,ae,af.index,af.resolution,af.html_elt.parent(),ag,{height:ad});af.html_elt.remove()}}}});var y=function(Z){J.call(this,Z,{content_div:Z.top_labeltrack},{resize:false});Z.reference_track=this;this.left_offset=200;this.visible_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:Z.dbkey};this.data_manager=new ReferenceTrackDataManager({data_url:reference_url});this.hide_contents()};o(y.prototype,p.prototype,J.prototype,{build_header_div:function(){},init:function(){this.data_manager.clear();this.enabled=true},can_draw:p.prototype.can_draw,draw_helper:function(ad,ab,Z,aa,ae,af,ac){if(af>this.view.canvas_manager.char_width_px){return J.prototype.draw_helper.call(this,ad,ab,Z,aa,ae,af,ac)}else{this.hide_contents();return null}},draw_tile:function(ah,ai,ad,ac,af,aj){var ab=this;if(aj>this.view.canvas_manager.char_width_px){if(ah.data===null){this.hide_contents();return}var aa=ai.canvas;ai.font=ai.canvas.manager.default_font;ai.textAlign="center";ah=ah.data;for(var ae=0,ag=ah.length;ae<ag;ae++){var Z=Math.floor(ae*aj);ai.fillText(ah[ae],Z,10)}this.show_contents();return new b(ab,af,ac,aa,ah)}this.hide_contents()}});var i=function(ab,aa,ac){var Z=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";J.call(this,ab,aa,ac);this.hda_ldda=ac.hda_ldda;this.dataset_id=ac.dataset_id;this.original_dataset_id=this.dataset_id;this.left_offset=0;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{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:32,hidden:true}],saved_values:ac.prefs,onchange:function(){Z.set_name(Z.prefs.name);Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.set_min_value(Z.prefs.min_value);Z.set_max_value(Z.prefs.max_value)}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value};o(i.prototype,p.prototype,J.prototype,{on_resize:function(){this.request_draw(true)},set_min_value:function(Z){this.prefs.min_value=Z;$("#linetrack_"+this.dataset_id+"_minval").text(this.prefs.min_value);this.tile_cache.clear();this.request_draw()},set_max_value:function(Z){this.prefs.max_value=Z;$("#linetrack_"+this.dataset_id+"_maxval").text(this.prefs.max_value);this.tile_cache.clear();this.request_draw()},predraw_init:function(){var Z=this;Z.vertical_range=undefined;return $.getJSON(Z.data_url,{stats:true,chrom:Z.view.chrom,low:0,high:Z.view.max_high,hda_ldda:Z.hda_ldda,dataset_id:Z.dataset_id},function(aa){Z.container_div.addClass("line-track");var ad=aa.data;if(isNaN(parseFloat(Z.prefs.min_value))||isNaN(parseFloat(Z.prefs.max_value))){var ab=ad.min,af=ad.max;ab=Math.floor(Math.min(0,Math.max(ab,ad.mean-2*ad.sd)));af=Math.ceil(Math.max(0,Math.min(af,ad.mean+2*ad.sd)));Z.prefs.min_value=ab;Z.prefs.max_value=af;$("#track_"+Z.dataset_id+"_minval").val(Z.prefs.min_value);$("#track_"+Z.dataset_id+"_maxval").val(Z.prefs.max_value)}Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.total_frequency=ad.total_frequency;Z.container_div.find(".yaxislabel").remove();var ae=$("<div/>").text(U(Z.prefs.min_value,3)).make_text_editable({num_cols:6,on_finish:function(ag){$(".bs-tooltip").remove();var ag=parseFloat(ag);if(!isNaN(ag)){Z.set_min_value(ag)}},help_text:"Set min value"}).addClass("yaxislabel bottom").attr("id","linetrack_"+Z.dataset_id+"_minval").prependTo(Z.container_div),ac=$("<div/>").text(U(Z.prefs.max_value,3)).make_text_editable({num_cols:6,on_finish:function(ag){$(".bs-tooltip").remove();var ag=parseFloat(ag);if(!isNaN(ag)){Z.set_max_value(ag)}},help_text:"Set max value"}).addClass("yaxislabel top").attr("id","linetrack_"+Z.dataset_id+"_maxval").prependTo(Z.container_div)})},draw_tile:function(ai,ag,ab,aa,ad,ah){var Z=ag.canvas,ac=ad.get("start"),af=ad.get("end"),ae=new I.LinePainter(ai.data,ac,af,this.prefs,ab);ae.draw(ag,Z.width,Z.height,ah);return new b(this,ad,aa,Z,ai.data)},can_subset:function(Z){return false}});var r=function(ab,aa,ac){var Z=this;this.display_modes=["Heatmap"];this.mode="Heatmap";J.call(this,ab,aa,ac);this.hda_ldda=ac.hda_ldda;this.dataset_id=ac.dataset_id;this.original_dataset_id=this.dataset_id;this.left_offset=0;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"pos_color",label:"Positive Color",type:"color",default_value:"4169E1"},{key:"negative_color",label:"Negative Color",type:"color",default_value:"FF8C00"},{key:"min_value",label:"Min Value",type:"float",default_value:0},{key:"max_value",label:"Max Value",type:"float",default_value:1},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:500,hidden:true}],saved_values:ac.prefs,onchange:function(){Z.set_name(Z.prefs.name);Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.set_min_value(Z.prefs.min_value);Z.set_max_value(Z.prefs.max_value)}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value};o(r.prototype,p.prototype,J.prototype,{on_resize:function(){this.request_draw(true)},set_min_value:function(Z){this.prefs.min_value=Z;this.tile_cache.clear();this.request_draw()},set_max_value:function(Z){this.prefs.max_value=Z;this.tile_cache.clear();this.request_draw()},draw_tile:function(aj,ah,ae,ac,aa,ai){var ab=ah.canvas,Z=this._get_tile_bounds(aa,ac),ad=Z[0],ag=Z[1],af=new I.DiagonalHeatmapPainter(aj.data,ad,ag,this.prefs,ae);af.draw(ah,ab.width,ab.height,ai);return new b(this,aa,ac,ab,aj.data)}});var c=function(ac,ab,ae){var aa=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];J.call(this,ac,ab,ae);var ad=get_random_color(),Z=get_random_color([ad,"#ffffff"]);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"block_color",label:"Block color",type:"color",default_value:ad},{key:"reverse_strand_color",label:"Antisense strand color",type:"color",default_value:Z},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true,help:"Show the number of items in each bin when drawing summary histogram"},{key:"histogram_max",label:"Histogram maximum",type:"float",default_value:null,help:"clear value to set automatically"},{key:"connector_style",label:"Connector style",type:"select",default_value:"fishbones",options:[{label:"Line with arrows",value:"fishbone"},{label:"Arcs",value:"arcs"}]},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.visible_height_px,hidden:true}],saved_values:ae.prefs,onchange:function(){aa.set_name(aa.prefs.name);aa.tile_cache.clear();aa.set_painter_from_config();aa.request_draw()}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.container_div.addClass("feature-track");this.hda_ldda=ae.hda_ldda;this.dataset_id=ae.dataset_id;this.original_dataset_id=ae.dataset_id;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.slotters={};this.start_end_dct={};this.left_offset=200;this.set_painter_from_config()};o(c.prototype,p.prototype,J.prototype,{set_dataset:function(Z){this.dataset_id=Z.get("id");this.hda_ldda=Z.get("hda_ldda");this.data_manager.set("dataset",Z)},set_painter_from_config:function(){if(this.config.values.connector_style==="arcs"){this.painter=I.ArcLinkedFeaturePainter}else{this.painter=I.LinkedFeaturePainter}},before_draw:function(){this.max_height_px=0},postdraw_actions:function(ao,aj,ae,ad){J.prototype.postdraw_actions.call(this,ao,ad);var ai=this;if(ai.mode==="Histogram"){var al,aa=-1;for(al=0;al<ao.length;al++){var ak=ao[al].max_val;if(ak>aa){aa=ak}}for(al=0;al<ao.length;al++){var aq=ao[al];if(aq.max_val!==aa){aq.html_elt.remove();ai.draw_helper(true,aj,aq.index,aq.resolution,aq.html_elt.parent(),ae,{more_tile_data:{max:aa}})}}}if(ai.filters_manager){var af=ai.filters_manager.filters;for(var an=0;an<af.length;an++){af[an].update_ui_elt()}var ap=false,Z,ag;for(var al=0;al<ao.length;al++){if(ao[al].data.length){Z=ao[al].data[0];for(var an=0;an<af.length;an++){ag=af[an];if(ag.applies_to(Z)&&ag.min!==ag.max){ap=true;break}}}}if(ai.filters_available!==ap){ai.filters_available=ap;if(!ai.filters_available){ai.filters_manager.hide()}ai.update_icons()}}this.container_div.find(".yaxislabel").remove();var ac=ao[0];if(ac instanceof j){var ah=(this.prefs.histogram_max?this.prefs.histogram_max:ac.max_val),ab=$("<div/>").text(ah).make_text_editable({num_cols:12,on_finish:function(ar){$(".bs-tooltip").remove();var ar=parseFloat(ar);ai.prefs.histogram_max=(!isNaN(ar)?ar:null);ai.tile_cache.clear();ai.request_draw()},help_text:"Set max value; leave blank to use default"}).addClass("yaxislabel top").css("color",this.prefs.label_color);this.container_div.prepend(ab)}if(ac instanceof L){var am=true;for(var al=0;al<ao.length;al++){if(!ao[al].all_slotted){am=false;break}}if(!am){this.action_icons.show_more_rows_icon.show()}else{this.action_icons.show_more_rows_icon.hide()}}else{this.action_icons.show_more_rows_icon.hide()}},update_auto_mode:function(Z){var Z;if(this.mode==="Auto"){if(Z==="no_detail"){Z="feature spans"}else{if(Z==="summary_tree"){Z="coverage histogram"}}this.action_icons.mode_icon.attr("title","Set display mode (now: Auto/"+Z+")")}},incremental_slots:function(ad,Z,ac){var aa=this.view.canvas_manager.dummy_context,ab=this.slotters[ad];if(!ab||(ab.mode!==ac)){ab=new (s.FeatureSlotter)(ad,ac,x,function(ae){return aa.measureText(ae)});this.slotters[ad]=ab}return ab.slot_features(Z)},get_summary_tree_data:function(ad,ag,ab,ao){if(ao>ab-ag){ao=ab-ag}var ak=Math.floor((ab-ag)/ao),an=[],ac=0;var ae=0,af=0,aj,am=0,ah=[],al,ai;var aa=function(ar,aq,at,ap){ar[0]=aq+at*ap;ar[1]=aq+(at+1)*ap};while(am<ao&&ae!==ad.length){var Z=false;for(;am<ao&&!Z;am++){aa(ah,ag,am,ak);for(af=ae;af<ad.length;af++){aj=ad[af].slice(1,3);if(is_overlap(aj,ah)){Z=true;break}}if(Z){break}}data_start_index=af;an[an.length]=al=[ah[0],0];for(;af<ad.length;af++){aj=ad[af].slice(1,3);if(is_overlap(aj,ah)){al[1]++}else{break}}if(al[1]>ac){ac=al[1]}am++}return{max:ac,delta:ak,data:an}},get_mode:function(Z){if(Z.dataset_type==="summary_tree"){mode="summary_tree"}else{if(Z.extra_info==="no_detail"||this.is_overview){mode="no_detail"}else{if(this.view.high-this.view.low>F){mode="Squish"}else{mode="Pack"}}}return mode},get_canvas_height:function(Z,ad,ae,aa){if(ad==="summary_tree"||ad==="Histogram"){return this.summary_draw_height}else{var ac=this.incremental_slots(ae,Z.data,ad);var ab=new (this.painter)(null,null,null,this.prefs,ad);return Math.max(Y,ab.get_required_height(ac,aa))}},draw_tile:function(ak,ao,am,ap,ac,ag,ab){var an=this,aa=ao.canvas,aw=ac.get("start"),Z=ac.get("end"),aB=25,ad=this.left_offset;if(am==="summary_tree"||am==="Histogram"){if(ak.dataset_type!=="summary_tree"){var ah=this.get_summary_tree_data(ak.data,aw,Z,200);if(ak.max){ah.max=ak.max}ak=ah}var ay=new I.SummaryTreePainter(ak,aw,Z,this.prefs);ay.draw(ao,aa.width,aa.height,ag);return new j(an,ac,ap,aa,ak.data,ak.max)}var af=[],al=this.slotters[ag].slots;all_slotted=true;if(ak.data){var ai=this.filters_manager.filters;for(var aq=0,at=ak.data.length;aq<at;aq++){var ae=ak.data[aq];var ar=false;var aj;for(var av=0,aA=ai.length;av<aA;av++){aj=ai[av];aj.update_attrs(ae);if(!aj.keep(ae)){ar=true;break}}if(!ar){af.push(ae);if(!(ae[0] in al)){all_slotted=false}}}}var az=(this.filters_manager.alpha_filter?new z(this.filters_manager.alpha_filter):null);var ax=(this.filters_manager.height_filter?new z(this.filters_manager.height_filter):null);var ay=new (this.painter)(af,aw,Z,this.prefs,am,az,ax,ab);var au=null;ao.fillStyle=this.prefs.block_color;ao.font=ao.canvas.manager.default_font;ao.textAlign="right";if(ak.data){au=ay.draw(ao,aa.width,aa.height,ag,al);au.translation=-ad}return new L(an,ac,ap,aa,ak.data,ag,am,ak.message,all_slotted,au)},data_and_mode_compatible:function(Z,aa){if(aa==="Auto"){return true}else{if(Z.extra_info==="no_detail"||Z.dataset_type==="summary_tree"){return false}else{return true}}},can_subset:function(Z){if(Z.dataset_type==="summary_tree"||Z.message||Z.extra_info==="no_detail"){return false}return true}});var O=function(aa,Z,ab){c.call(this,aa,Z,ab);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.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:ab.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=I.ReadPainter};o(O.prototype,p.prototype,J.prototype,c.prototype);var R=function(ab,aa,ad){c.call(this,ab,aa,ad);var ac=get_random_color(),Z=get_random_color([ac,"#ffffff"]);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"block_color",label:"Block and sense strand color",type:"color",default_value:ac},{key:"reverse_strand_color",label:"Antisense strand color",type:"color",default_value:Z},{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:"histogram_max",label:"Histogram maximum",type:"float",default_value:null,help:"Clear value to set automatically"},{key:"mode",type:"string",default_value:this.mode,hidden:true}],saved_values:ad.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=I.ReadPainter;this.update_icons()};o(R.prototype,p.prototype,J.prototype,c.prototype);S.View=X;S.DrawableGroup=M;S.LineTrack=i;S.FeatureTrack=c;S.DiagonalHeatmapTrack=r;S.ReadTrack=R;S.VcfTrack=O;S.CompositeTrack=g};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.mode=h;this.include_label=(h==="Pack");this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,h=this.start_end_dct,x=[],z=[],n=0,y=this.max_rows;for(var v=0,w=m.length;v<w;v++){var k=m[v],o=k[0];if(this.slots[o]!==undefined){n=Math.max(n,this.slots[o]);z.push(this.slots[o])}else{x.push(v)}}var q=function(E,F){for(var D=0;D<=y;D++){var B=false,G=h[D];if(G!==undefined){for(var A=0,C=G.length;A<C;A++){var i=G[A];if(F>i[0]&&E<i[1]){B=true;break}}}if(!B){return D}}return -1};for(var v=0,w=x.length;v<w;v++){var k=m[x[v]],o=k[0],t=k[1],f=k[2],r=k[3],g=Math.floor(t*p),l=Math.ceil(f*p),u=this.measureText(r).width,j;if(r!==undefined&&this.include_label){u+=(d+a);if(g-u>=0){g-=u;j="left"}else{l+=u;j="right"}}var s=q(g,l);if(s>=0){if(h[s]===undefined){h[s]=[]}h[s].push([g,l]);this.slots[o]=s;n=Math.max(n,s)}}return n+1}})};var painters_module=function(require,exports){var extend=require("class").extend;var dashedLine=function(ctx,x1,y1,x2,y2,dashLen){if(dashLen===undefined){dashLen=4}var dX=x2-x1;var dY=y2-y1;var dashes=Math.floor(Math.sqrt(dX*dX+dY*dY)/dashLen);var dashX=dX/dashes;var dashY=dY/dashes;var q;for(q=0;q<dashes;q++,x1+=dashX,y1+=dashY){if(q%2!==0){continue}ctx.fillRect(x1,y1,dashLen,1)}};var drawDownwardEquilateralTriangle=function(ctx,down_vertex_x,down_vertex_y,side_len){var x1=down_vertex_x-side_len/2,x2=down_vertex_x+side_len/2,y=down_vertex_y-Math.sqrt(side_len*3/2);ctx.beginPath();ctx.moveTo(x1,y);ctx.lineTo(x2,y);ctx.lineTo(down_vertex_x,down_vertex_y);ctx.lineTo(x1,y);ctx.strokeStyle=this.fillStyle;ctx.fill();ctx.stroke();ctx.closePath()};var Scaler=function(default_val){this.default_val=(default_val?default_val:1)};Scaler.prototype.gen_val=function(input){return this.default_val};var Painter=function(data,view_start,view_end,prefs,mode){this.data=data;this.view_start=view_start;this.view_end=view_end;this.prefs=extend({},this.default_prefs,prefs);this.mode=mode};Painter.prototype.default_prefs={};Painter.prototype.draw=function(ctx,width,height,w_scale){};var SummaryTreePainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode)};SummaryTreePainter.prototype.default_prefs={show_counts:false};SummaryTreePainter.prototype.draw=function(ctx,width,height,w_scale){var view_start=this.view_start,view_range=this.view_end-this.view_start,points=this.data.data,max=(this.prefs.histogram_max?this.prefs.histogram_max:this.data.max),base_y=height;delta_x_px=Math.ceil(this.data.delta*w_scale);ctx.save();for(var i=0,len=points.length;i<len;i++){var x=Math.floor((points[i][0]-view_start)*w_scale);var y=points[i][1];if(!y){continue}var y_px=y/max*height;if(y!==0&&y_px<1){y_px=1}ctx.fillStyle=this.prefs.block_color;ctx.fillRect(x,base_y-y_px,delta_x_px,y_px);var text_padding_req_x=4;if(this.prefs.show_counts&&(ctx.measureText(y).width+text_padding_req_x)<delta_x_px){ctx.fillStyle=this.prefs.label_color;ctx.textAlign="center";ctx.fillText(y,x+(delta_x_px/2),10)}}ctx.restore()};var LinePainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode);if(this.prefs.min_value===undefined){var min_value=Infinity;for(var i=0,len=this.data.length;i<len;i++){min_value=Math.min(min_value,this.data[i][1])}this.prefs.min_value=min_value}if(this.prefs.max_value===undefined){var max_value=-Infinity;for(var i=0,len=this.data.length;i<len;i++){max_value=Math.max(max_value,this.data[i][1])}this.prefs.max_value=max_value}};LinePainter.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};LinePainter.prototype.draw=function(ctx,width,height,w_scale){var in_path=false,min_value=this.prefs.min_value,max_value=this.prefs.max_value,vertical_range=max_value-min_value,height_px=height,view_start=this.view_start,view_range=this.view_end-this.view_start,mode=this.mode,data=this.data;ctx.save();var y_zero=Math.round(height+min_value/vertical_range*height);if(mode!=="Intensity"){ctx.fillStyle="#aaa";ctx.fillRect(0,y_zero,width,1)}ctx.beginPath();var x_scaled,y,delta_x_px;if(data.length>1){delta_x_px=Math.ceil((data[1][0]-data[0][0])*w_scale)}else{delta_x_px=10}var pref_color=parseInt(this.prefs.color.slice(1),16),pref_r=(pref_color&16711680)>>16,pref_g=(pref_color&65280)>>8,pref_b=pref_color&255;for(var i=0,len=data.length;i<len;i++){ctx.fillStyle=ctx.strokeStyle=this.prefs.color;x_scaled=Math.round((data[i][0]-view_start)*w_scale);y=data[i][1];var top_overflow=false,bot_overflow=false;if(y===null){if(in_path&&mode==="Filled"){ctx.lineTo(x_scaled,height_px)}in_path=false;continue}if(y<min_value){bot_overflow=true;y=min_value}else{if(y>max_value){top_overflow=true;y=max_value}}if(mode==="Histogram"){y=Math.round(y/vertical_range*height_px);ctx.fillRect(x_scaled,y_zero,delta_x_px,-y)}else{if(mode==="Intensity"){var saturation=(y-min_value)/vertical_range,new_r=Math.round(pref_r+(255-pref_r)*(1-saturation)),new_g=Math.round(pref_g+(255-pref_g)*(1-saturation)),new_b=Math.round(pref_b+(255-pref_b)*(1-saturation));ctx.fillStyle="rgb("+new_r+","+new_g+","+new_b+")";ctx.fillRect(x_scaled,0,delta_x_px,height_px)}else{y=Math.round(height_px-(y-min_value)/vertical_range*height_px);if(in_path){ctx.lineTo(x_scaled,y)}else{in_path=true;if(mode==="Filled"){ctx.moveTo(x_scaled,height_px);ctx.lineTo(x_scaled,y)}else{ctx.moveTo(x_scaled,y)}}}}ctx.fillStyle=this.prefs.overflow_color;if(top_overflow||bot_overflow){var overflow_x;if(mode==="Histogram"||mode==="Intensity"){overflow_x=delta_x_px}else{x_scaled-=2;overflow_x=4}if(top_overflow){ctx.fillRect(x_scaled,0,overflow_x,3)}if(bot_overflow){ctx.fillRect(x_scaled,height_px-3,overflow_x,3)}}ctx.fillStyle=this.prefs.color}if(mode==="Filled"){if(in_path){ctx.lineTo(x_scaled,y_zero);ctx.lineTo(0,y_zero)}ctx.fill()}else{ctx.stroke()}ctx.restore()};var FeaturePositionMapper=function(slot_height){this.feature_positions={};this.slot_height=slot_height;this.translation=0;this.y_translation=0};FeaturePositionMapper.prototype.map_feature_data=function(feature_data,slot,x_start,x_end){if(!this.feature_positions[slot]){this.feature_positions[slot]=[]}this.feature_positions[slot].push({data:feature_data,x_start:x_start,x_end:x_end})};FeaturePositionMapper.prototype.get_feature_data=function(x,y){var slot=Math.floor((y-this.y_translation)/this.slot_height),feature_dict;if(!this.feature_positions[slot]){return null}x+=this.translation;for(var i=0;i<this.feature_positions[slot].length;i++){feature_dict=this.feature_positions[slot][i];if(x>=feature_dict.x_start&&x<=feature_dict.x_end){return feature_dict.data}}};var FeaturePainter=function(data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler){Painter.call(this,data,view_start,view_end,prefs,mode);this.alpha_scaler=(alpha_scaler?alpha_scaler:new Scaler());this.height_scaler=(height_scaler?height_scaler:new Scaler())};FeaturePainter.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};extend(FeaturePainter.prototype,{get_required_height:function(rows_required,width){var required_height=y_scale=this.get_row_height(),mode=this.mode;if(mode==="no_detail"||mode==="Squish"||mode==="Pack"){required_height=rows_required*y_scale}return required_height+this.get_top_padding(width)+this.get_bottom_padding(width)},get_top_padding:function(width){return 0},get_bottom_padding:function(width){return Math.max(Math.round(this.get_row_height()/2),5)},draw:function(ctx,width,height,w_scale,slots){var data=this.data,view_start=this.view_start,view_end=this.view_end;ctx.save();ctx.fillStyle=this.prefs.block_color;ctx.textAlign="right";var view_range=this.view_end-this.view_start,y_scale=this.get_row_height(),feature_mapper=new FeaturePositionMapper(y_scale),x_draw_coords;for(var i=0,len=data.length;i<len;i++){var feature=data[i],feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2],slot=(slots&&slots[feature_uid]!==undefined?slots[feature_uid]:null);if((feature_start<view_end&&feature_end>view_start)&&(this.mode==="Dense"||slot!==null)){x_draw_coords=this.draw_element(ctx,this.mode,feature,slot,view_start,view_end,w_scale,y_scale,width);feature_mapper.map_feature_data(feature,slot,x_draw_coords[0],x_draw_coords[1])}}ctx.restore();feature_mapper.y_translation=this.get_top_padding(width);return feature_mapper},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){console.log("WARNING: Unimplemented function.");return[0,0]}});var DENSE_TRACK_HEIGHT=10,NO_DETAIL_TRACK_HEIGHT=3,SQUISH_TRACK_HEIGHT=5,PACK_TRACK_HEIGHT=10,NO_DETAIL_FEATURE_HEIGHT=1,DENSE_FEATURE_HEIGHT=9,SQUISH_FEATURE_HEIGHT=3,PACK_FEATURE_HEIGHT=9,LABEL_SPACING=2,CONNECTOR_COLOR="#ccc";var LinkedFeaturePainter=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);this.draw_background_connector=true;this.draw_individual_connectors=false};extend(LinkedFeaturePainter.prototype,FeaturePainter.prototype,{get_row_height:function(){var mode=this.mode,height;if(mode==="Dense"){height=DENSE_TRACK_HEIGHT}else{if(mode==="no_detail"){height=NO_DETAIL_TRACK_HEIGHT}else{if(mode==="Squish"){height=SQUISH_TRACK_HEIGHT}else{height=PACK_TRACK_HEIGHT}}}return height},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){var feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2]-1,feature_name=feature[3],feature_strand=feature[4],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))),draw_start=f_start,draw_end=f_end,y_center=(mode==="Dense"?0:(0+slot))*y_scale+this.get_top_padding(width),thickness,y_start,thick_start=null,thick_end=null,block_color=block_color=(!feature_strand||feature_strand==="+"||feature_strand==="."?this.prefs.block_color:this.prefs.reverse_strand_color);label_color=this.prefs.label_color;ctx.globalAlpha=this.alpha_scaler.gen_val(feature);if(mode==="Dense"){slot=1}if(mode==="no_detail"){ctx.fillStyle=block_color;ctx.fillRect(f_start,y_center+5,f_end-f_start,NO_DETAIL_FEATURE_HEIGHT)}else{var feature_ts=feature[5],feature_te=feature[6],feature_blocks=feature[7],full_height=true;if(feature_ts&&feature_te){thick_start=Math.floor(Math.max(0,(feature_ts-tile_low)*w_scale));thick_end=Math.ceil(Math.min(width,Math.max(0,(feature_te-tile_low)*w_scale)))}var thin_height,thick_height;if(mode==="Squish"){thin_height=1;thick_height=SQUISH_FEATURE_HEIGHT;full_height=false}else{if(mode==="Dense"){thin_height=5;thick_height=DENSE_FEATURE_HEIGHT}else{thin_height=5;thick_height=PACK_FEATURE_HEIGHT}}if(!feature_blocks){ctx.fillStyle=block_color;ctx.fillRect(f_start,y_center+1,f_end-f_start,thick_height);if(feature_strand&&full_height){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand_inv")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand_inv")}}ctx.fillRect(f_start,y_center+1,f_end-f_start,thick_height)}}else{var cur_y_center,cur_height;if(mode==="Squish"||mode==="Dense"){cur_y_center=y_center+Math.floor(SQUISH_FEATURE_HEIGHT/2)+1;cur_height=1}else{if(feature_strand){cur_y_center=y_center;cur_height=thick_height}else{cur_y_center+=(SQUISH_FEATURE_HEIGHT/2)+1;cur_height=1}}if(this.draw_background_connector){if(mode==="Squish"||mode==="Dense"){ctx.fillStyle=CONNECTOR_COLOR}else{if(feature_strand){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand")}}}else{ctx.fillStyle=CONNECTOR_COLOR}}ctx.fillRect(f_start,cur_y_center,f_end-f_start,cur_height)}var start_and_height;for(var k=0,k_len=feature_blocks.length;k<k_len;k++){var block=feature_blocks[k],block_start=Math.floor(Math.max(0,(block[0]-tile_low)*w_scale)),block_end=Math.ceil(Math.min(width,Math.max((block[1]-1-tile_low)*w_scale))),last_block_start,last_block_end;if(block_start>block_end){continue}ctx.fillStyle=block_color;ctx.fillRect(block_start,y_center+(thick_height-thin_height)/2+1,block_end-block_start,thin_height);if(thick_start!==undefined&&feature_te>feature_ts&&!(block_start>thick_end||block_end<thick_start)){var block_thick_start=Math.max(block_start,thick_start),block_thick_end=Math.min(block_end,thick_end);ctx.fillRect(block_thick_start,y_center+1,block_thick_end-block_thick_start,thick_height);if(feature_blocks.length===1&&mode==="Pack"){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand_inv")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand_inv")}}if(block_thick_start+14<block_thick_end){block_thick_start+=2;block_thick_end-=2}ctx.fillRect(block_thick_start,y_center+1,block_thick_end-block_thick_start,thick_height)}}if(this.draw_individual_connectors&&last_block_start){this.draw_connector(ctx,last_block_start,last_block_end,block_start,block_end,y_center)}last_block_start=block_start;last_block_end=block_end}if(mode==="Pack"){ctx.globalAlpha=1;ctx.fillStyle="white";var hscale_factor=this.height_scaler.gen_val(feature),new_height=Math.ceil(thick_height*hscale_factor),ws_height=Math.round((thick_height-new_height)/2);if(hscale_factor!==1){ctx.fillRect(f_start,cur_y_center+1,f_end-f_start,ws_height);ctx.fillRect(f_start,cur_y_center+thick_height-ws_height+1,f_end-f_start,ws_height)}}}ctx.globalAlpha=1;if(mode==="Pack"&&feature_start>tile_low){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+LABEL_SPACING,y_center+8);draw_end+=ctx.measureText(feature_name).width+LABEL_SPACING}else{ctx.textAlign="right";ctx.fillText(feature_name,f_start-LABEL_SPACING,y_center+8);draw_start-=ctx.measureText(feature_name).width+LABEL_SPACING}}}ctx.globalAlpha=1;return[draw_start,draw_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)};extend(ReadPainter.prototype,FeaturePainter.prototype,{get_row_height:function(){var height,mode=this.mode;if(mode==="Dense"){height=DENSE_TRACK_HEIGHT}else{if(mode==="Squish"){height=SQUISH_TRACK_HEIGHT}else{height=PACK_TRACK_HEIGHT;if(this.prefs.show_insertions){height*=2}}}return height},draw_read:function(ctx,mode,w_scale,y_center,tile_low,tile_high,feature_start,cigar,strand,orig_seq){ctx.textAlign="center";var track=this,tile_region=[tile_low,tile_high],base_offset=0,seq_offset=0,gap=0,char_width_px=ctx.canvas.manager.char_width_px,block_color=(strand==="+"?this.prefs.block_color:this.prefs.reverse_strand_color);var draw_last=[];if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){gap=Math.round(w_scale/2)}if(!cigar){cigar=[[0,orig_seq.length]]}for(var cig_id=0,len=cigar.length;cig_id<len;cig_id++){var cig=cigar[cig_id],cig_op="MIDNSHP=X"[cig[0]],cig_len=cig[1];if(cig_op==="H"||cig_op==="S"){base_offset-=cig_len}var seq_start=feature_start+base_offset,s_start=Math.floor(Math.max(0,(seq_start-tile_low)*w_scale)),s_end=Math.floor(Math.max(0,(seq_start+cig_len-tile_low)*w_scale));if(s_start===s_end){s_end+=1}switch(cig_op){case"H":break;case"S":case"M":case"=":if(is_overlap([seq_start,seq_start+cig_len],tile_region)){var seq=orig_seq.slice(seq_offset,seq_offset+cig_len);if(gap>0){ctx.fillStyle=block_color;ctx.fillRect(s_start-gap,y_center+1,s_end-s_start,9);ctx.fillStyle=CONNECTOR_COLOR;for(var c=0,str_len=seq.length;c<str_len;c++){if(this.prefs.show_differences){if(this.ref_seq){var ref_char=this.ref_seq[seq_start-tile_low+c];if(!ref_char||ref_char.toLowerCase()===seq[c].toLowerCase()){continue}}else{continue}}if(seq_start+c>=tile_low&&seq_start+c<=tile_high){var c_start=Math.floor(Math.max(0,(seq_start+c-tile_low)*w_scale));ctx.fillText(seq[c],c_start,y_center+9)}}}else{ctx.fillStyle=block_color;ctx.fillRect(s_start,y_center+4,s_end-s_start,SQUISH_FEATURE_HEIGHT)}}seq_offset+=cig_len;base_offset+=cig_len;break;case"N":ctx.fillStyle=CONNECTOR_COLOR;ctx.fillRect(s_start-gap,y_center+5,s_end-s_start,1);base_offset+=cig_len;break;case"D":ctx.fillStyle="red";ctx.fillRect(s_start-gap,y_center+4,s_end-s_start,3);base_offset+=cig_len;break;case"P":break;case"I":var insert_x_coord=s_start-gap;if(is_overlap([seq_start,seq_start+cig_len],tile_region)){var seq=orig_seq.slice(seq_offset,seq_offset+cig_len);if(this.prefs.show_insertions){var x_center=s_start-(s_end-s_start)/2;if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){ctx.fillStyle="yellow";ctx.fillRect(x_center-gap,y_center-9,s_end-s_start,9);draw_last[draw_last.length]={type:"triangle",data:[insert_x_coord,y_center+4,5]};ctx.fillStyle=CONNECTOR_COLOR;switch(compute_overlap([seq_start,seq_start+cig_len],tile_region)){case (OVERLAP_START):seq=seq.slice(tile_low-seq_start);break;case (OVERLAP_END):seq=seq.slice(0,seq_start-tile_high);break;case (CONTAINED_BY):break;case (CONTAINS):seq=seq.slice(tile_low-seq_start,seq_start-tile_high);break}for(var c=0,str_len=seq.length;c<str_len;c++){var c_start=Math.floor(Math.max(0,(seq_start+c-tile_low)*w_scale));ctx.fillText(seq[c],c_start-(s_end-s_start)/2,y_center)}}else{ctx.fillStyle="yellow";ctx.fillRect(x_center,y_center+(this.mode!=="Dense"?2:5),s_end-s_start,(mode!=="Dense"?SQUISH_FEATURE_HEIGHT:DENSE_FEATURE_HEIGHT))}}else{if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){draw_last.push({type:"text",data:[seq.length,insert_x_coord,y_center+9]})}else{}}}seq_offset+=cig_len;break;case"X":seq_offset+=cig_len;break}}ctx.fillStyle="yellow";var item,type,data;for(var i=0;i<draw_last.length;i++){item=draw_last[i];type=item.type;data=item.data;if(type==="text"){ctx.save();ctx.font="bold "+ctx.font;ctx.fillText(data[0],data[1],data[2]);ctx.restore()}else{if(type==="triangle"){drawDownwardEquilateralTriangle(ctx,data[0],data[1],data[2])}}}},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){var feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2],feature_name=feature[3],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,label_color=this.prefs.label_color,gap=0;if((mode==="Pack"||this.mode==="Auto")&&w_scale>ctx.canvas.manager.char_width_px){var gap=Math.round(w_scale/2)}if(feature[5] instanceof Array){var b1_start=Math.floor(Math.max(0,(feature[4][0]-tile_low)*w_scale)),b1_end=Math.ceil(Math.min(width,Math.max(0,(feature[4][1]-tile_low)*w_scale))),b2_start=Math.floor(Math.max(0,(feature[5][0]-tile_low)*w_scale)),b2_end=Math.ceil(Math.min(width,Math.max(0,(feature[5][1]-tile_low)*w_scale)));if(feature[4][1]>=tile_low&&feature[4][0]<=tile_high&&feature[4][2]){this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature[4][0],feature[4][2],feature[4][3],feature[4][4])}if(feature[5][1]>=tile_low&&feature[5][0]<=tile_high&&feature[5][2]){this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature[5][0],feature[5][2],feature[5][3],feature[5][4])}if(b2_start>b1_end){ctx.fillStyle=CONNECTOR_COLOR;dashedLine(ctx,b1_end-gap,y_center+5,b2_start-gap,y_center+5)}}else{this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature_start,feature[4],feature[5],feature[6])}if(mode==="Pack"&&feature_start>tile_low&&feature_name!=="."){ctx.fillStyle=this.prefs.label_color;var tile_index=1;if(tile_index===0&&f_start-ctx.measureText(feature_name).width<0){ctx.textAlign="left";ctx.fillText(feature_name,f_end+LABEL_SPACING-gap,y_center+8)}else{ctx.textAlign="right";ctx.fillText(feature_name,f_start-LABEL_SPACING-gap,y_center+8)}}return[0,0]}});var ArcLinkedFeaturePainter=function(data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler){LinkedFeaturePainter.call(this,data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler);this.longest_feature_length=this.calculate_longest_feature_length();this.draw_background_connector=false;this.draw_individual_connectors=true};extend(ArcLinkedFeaturePainter.prototype,FeaturePainter.prototype,LinkedFeaturePainter.prototype,{calculate_longest_feature_length:function(){var longest_feature_length=0;for(var i=0,len=this.data.length;i<len;i++){var feature=this.data[i],feature_start=feature[1],feature_end=feature[2];longest_feature_length=Math.max(longest_feature_length,feature_end-feature_start)}return longest_feature_length},get_top_padding:function(width){var view_range=this.view_end-this.view_start,w_scale=width/view_range;return Math.min(128,Math.ceil((this.longest_feature_length/2)*w_scale))},draw_connector:function(ctx,block1_start,block1_end,block2_start,block2_end,y_center){var x_center=(block1_end+block2_start)/2,radius=block2_start-x_center;var angle1=Math.PI,angle2=0;if(radius>0){ctx.beginPath();ctx.arc(x_center,y_center,block2_start-x_center,Math.PI,0);ctx.stroke()}}});var Color=function(rgb,a){if(Array.isArray(rgb)){this.rgb=rgb}else{if(rgb.length==6){this.rgb=rgb.match(/.{2}/g).map(function(c){return parseInt(c,16)})}else{this.rgb=rgb.split("").map(function(c){return parseInt(c+c,16)})}}this.alpha=typeof(a)==="number"?a:1};Color.prototype={eval:function(){return this},toCSS:function(){if(this.alpha<1){return"rgba("+this.rgb.map(function(c){return Math.round(c)}).concat(this.alpha).join(", ")+")"}else{return"#"+this.rgb.map(function(i){i=Math.round(i);i=(i>255?255:(i<0?0:i)).toString(16);return i.length===1?"0"+i:i}).join("")}},toHSL:function(){var r=this.rgb[0]/255,g=this.rgb[1]/255,b=this.rgb[2]/255,a=this.alpha;var max=Math.max(r,g,b),min=Math.min(r,g,b);var h,s,l=(max+min)/2,d=max-min;if(max===min){h=s=0}else{s=l>0.5?d/(2-max-min):d/(max+min);switch(max){case r:h=(g-b)/d+(g<b?6:0);break;case g:h=(b-r)/d+2;break;case b:h=(r-g)/d+4;break}h/=6}return{h:h*360,s:s,l:l,a:a}},toARGB:function(){var argb=[Math.round(this.alpha*255)].concat(this.rgb);return"#"+argb.map(function(i){i=Math.round(i);i=(i>255?255:(i<0?0:i)).toString(16);return i.length===1?"0"+i:i}).join("")},mix:function(color2,weight){color1=this;var p=weight;var w=p*2-1;var a=color1.toHSL().a-color2.toHSL().a;var w1=(((w*a==-1)?w:(w+a)/(1+w*a))+1)/2;var w2=1-w1;var rgb=[color1.rgb[0]*w1+color2.rgb[0]*w2,color1.rgb[1]*w1+color2.rgb[1]*w2,color1.rgb[2]*w1+color2.rgb[2]*w2];var alpha=color1.alpha*p+color2.alpha*(1-p);return new Color(rgb,alpha)}};var LinearRamp=function(start_color,end_color,start_value,end_value){this.start_color=new Color(start_color);this.end_color=new Color(end_color);this.start_value=start_value;this.end_value=end_value;this.value_range=end_value-start_value};LinearRamp.prototype.map_value=function(value){value=Math.max(value,this.start_value);value=Math.min(value,this.end_value);value=(value-this.start_value)/this.value_range;return this.start_color.mix(this.end_color,1-value).toCSS()};var SplitRamp=function(start_color,middle_color,end_color,start_value,end_value){this.positive_ramp=new LinearRamp(middle_color,end_color,0,end_value);this.negative_ramp=new LinearRamp(middle_color,start_color,0,-start_value);this.start_value=start_value;this.end_value=end_value};SplitRamp.prototype.map_value=function(value){value=Math.max(value,this.start_value);value=Math.min(value,this.end_value);if(value>=0){return this.positive_ramp.map_value(value)}else{return this.negative_ramp.map_value(-value)}};var DiagonalHeatmapPainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode);if(this.prefs.min_value===undefined){var min_value=Infinity;for(var i=0,len=this.data.length;i<len;i++){min_value=Math.min(min_value,this.data[i][5])}this.prefs.min_value=min_value}if(this.prefs.max_value===undefined){var max_value=-Infinity;for(var i=0,len=this.data.length;i<len;i++){max_value=Math.max(max_value,this.data[i][5])}this.prefs.max_value=max_value}};DiagonalHeatmapPainter.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Heatmap",pos_color:"4169E1",neg_color:"FF8C00"};DiagonalHeatmapPainter.prototype.draw=function(ctx,width,height,w_scale){var min_value=this.prefs.min_value,max_value=this.prefs.max_value,value_range=max_value-min_value,height_px=height,view_start=this.view_start,view_range=this.view_end-this.view_start,mode=this.mode,data=this.data,invsqrt2=1/Math.sqrt(2);var ramp=(new SplitRamp(this.prefs.neg_color,"FFFFFF",this.prefs.pos_color,min_value,max_value));var d,s1,e1,s2,e2,value;var scale=function(p){return(p-view_start)*w_scale};ctx.save();ctx.rotate(-45*Math.PI/180);ctx.scale(invsqrt2,invsqrt2);for(var i=0,len=data.length;i<len;i++){d=data[i];s1=scale(d[1]);e1=scale(d[2]);s2=scale(d[4]);e2=scale(d[5]);value=d[6];ctx.fillStyle=(ramp.map_value(value));ctx.fillRect(s1,s2,(e1-s1),(e2-s2))}ctx.restore()};exports.Scaler=Scaler;exports.SummaryTreePainter=SummaryTreePainter;exports.LinePainter=LinePainter;exports.LinkedFeaturePainter=LinkedFeaturePainter;exports.ReadPainter=ReadPainter;exports.ArcLinkedFeaturePainter=ArcLinkedFeaturePainter;exports.DiagonalHeatmapPainter=DiagonalHeatmapPainter};(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 g=arguments[0];for(var f=1;f<arguments.length;f++){var d=arguments[f];for(var e in d){g[e]=d[e]}}return g};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 is_deferred=function(a){return("isResolved" in a)};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 n=function(t,s,i){return((t*299)+(s*587)+(i*114))/1000};var e=function(v,u,w,s,i,t){return(Math.max(v,s)-Math.min(v,s))+(Math.max(u,i)-Math.min(u,i))+(Math.max(w,t)-Math.min(w,t))};var g,o,f,k,q,h,r,c,d,b,p,m=false,l=0;do{g=Math.round(Math.random()*16777215);o=(g&16711680)>>16;f=(g&65280)>>8;k=g&255;d=n(o,f,k);m=true;for(j=0;j<a.length;j++){q=a[j];h=(q&16711680)>>16;r=(q&65280)>>8;c=q&255;b=n(h,r,c);p=e(o,f,k,h,r,c);if((Math.abs(d-b)<40)||(p<200)){m=false;break}}l++}while(!m&&l<=10);return"#"+(16777216+g).toString(16).substr(1,6)};var create_action_icon=function(c,b,a){return $("<a/>").attr("href","javascript:void(0);").attr("title",c).addClass("icon-button").addClass(b).tooltip().click(a)};var trackster_module=function(d,S){var o=d("class").extend,s=d("slotting"),I=d("painters");var m={};var k=function(Z,aa){m[Z.attr("id")]=aa};var l=function(Z,ab,ad,ac){ad=".group";var aa={};m[Z.attr("id")]=ac;Z.bind("drag",{handle:"."+ab,relative:true},function(al,am){var ak=$(this),ap=$(this).parent(),ah=ap.children(),aj=m[$(this).attr("id")],ag,af,an,ae,ai;af=$(this).parents(ad);if(af.length!==0){an=af.position().top;ae=an+af.outerHeight();if(am.offsetY<an){$(this).insertBefore(af);var ao=m[af.attr("id")];ao.remove_drawable(aj);ao.container.add_drawable_before(aj,ao);return}else{if(am.offsetY>ae){$(this).insertAfter(af);var ao=m[af.attr("id")];ao.remove_drawable(aj);ao.container.add_drawable(aj);return}}}af=null;for(ai=0;ai<ah.length;ai++){ag=$(ah.get(ai));an=ag.position().top;ae=an+ag.outerHeight();if(ag.is(ad)&&this!==ag.get(0)&&am.offsetY>=an&&am.offsetY<=ae){if(am.offsetY-an<ae-am.offsetY){ag.find(".content-div").prepend(this)}else{ag.find(".content-div").append(this)}if(aj.container){aj.container.remove_drawable(aj)}m[ag.attr("id")].add_drawable(aj);return}}for(ai=0;ai<ah.length;ai++){ag=$(ah.get(ai));if(am.offsetY<ag.position().top&&!(ag.hasClass("reference-track")||ag.hasClass("intro"))){break}}if(ai===ah.length){if(this!==ah.get(ai-1)){ap.append(this);m[ap.attr("id")].move_drawable(aj,ai)}}else{if(this!==ah.get(ai)){$(this).insertBefore(ah.get(ai));m[ap.attr("id")].move_drawable(aj,(am.deltaY>0?ai-1:ai))}}}).bind("dragstart",function(){aa["border-top"]=Z.css("border-top");aa["border-bottom"]=Z.css("border-bottom");$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css(aa)})};S.moveable=l;var Y=16,D=9,A=20,x=100,F=12000,P=400,H=5000,u=100,n="There was an error in indexing this dataset. ",G="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",B="No data for this chrom/contig.",t="Preparing data. This can take a while for a large dataset. If the visualization is saved and closed, preparation will continue in the background.",v="Tool cannot be rerun: ",a="Loading data...",T="Ready for display",N=10,E=20;function U(aa,Z){if(!Z){Z=0}var ab=Math.pow(10,Z);return Math.round(aa*ab)/ab}var p=function(aa,Z,ac){if(!p.id_counter){p.id_counter=0}this.id=p.id_counter++;this.name=ac.name;this.view=aa;this.container=Z;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name}],saved_values:ac.prefs,onchange:function(){this.track.set_name(this.track.config.values.name)}});this.prefs=this.config.values;this.drag_handle_class=ac.drag_handle_class;this.is_overview=false;this.action_icons={};this.content_visible=true;this.container_div=this.build_container_div();this.header_div=this.build_header_div();if(this.header_div){this.container_div.append(this.header_div);this.icons_div=$("<div/>").css("float","left").hide().appendTo(this.header_div);this.build_action_icons(this.action_icons_def);this.header_div.append($("<div style='clear: both'/>"));this.header_div.dblclick(function(ad){ad.stopPropagation()});var ab=this;this.container_div.hover(function(){ab.icons_div.show()},function(){ab.icons_div.hide()});$("<div style='clear: both'/>").appendTo(this.container_div)}};p.prototype.action_icons_def=[{name:"toggle_icon",title:"Hide/show content",css_class:"toggle",on_click_fn:function(Z){if(Z.content_visible){Z.action_icons.toggle_icon.addClass("toggle-expand").removeClass("toggle");Z.hide_contents();Z.content_visible=false}else{Z.action_icons.toggle_icon.addClass("toggle").removeClass("toggle-expand");Z.content_visible=true;Z.show_contents()}}},{name:"settings_icon",title:"Edit settings",css_class:"settings-icon",on_click_fn:function(aa){var ac=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},Z=function(){aa.config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},ab=function(ad){if((ad.keyCode||ad.which)===27){ac()}else{if((ad.keyCode||ad.which)===13){Z()}}};$(window).bind("keypress.check_enter_esc",ab);show_modal("Configure",aa.config.build_form(),{Cancel:ac,OK:Z})}},{name:"remove_icon",title:"Remove",css_class:"remove-icon",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.remove()}}];o(p.prototype,{init:function(){},changed:function(){this.view.changed()},can_draw:function(){if(this.enabled&&this.content_visible){return true}return false},request_draw:function(){},_draw:function(){},to_dict:function(){},set_name:function(Z){this.old_name=this.name;this.name=Z;this.name_div.text(this.name)},revert_name:function(){if(this.old_name){this.name=this.old_name;this.name_div.text(this.name)}},remove:function(){this.changed();this.container.remove_drawable(this);var Z=this.view;this.container_div.hide(0,function(){$(this).remove();Z.update_intro_div()})},build_container_div:function(){},build_header_div:function(){},add_action_icon:function(aa,af,ae,ad,Z,ac){var ab=this;this.action_icons[aa]=$("<a/>").attr("href","javascript:void(0);").attr("title",af).addClass("icon-button").addClass(ae).tooltip().click(function(){ad(ab)}).appendTo(this.icons_div);if(ac){this.action_icons[aa].hide()}},build_action_icons:function(Z){var ab;for(var aa=0;aa<Z.length;aa++){ab=Z[aa];this.add_action_icon(ab.name,ab.title,ab.css_class,ab.on_click_fn,ab.prepend,ab.hide)}},update_icons:function(){},hide_contents:function(){},show_contents:function(){}});var w=function(aa,Z,ab){p.call(this,aa,Z,ab);this.obj_type=ab.obj_type;this.drawables=[]};o(w.prototype,p.prototype,{unpack_drawables:function(ab){this.drawables=[];var aa;for(var Z=0;Z<ab.length;Z++){aa=object_from_template(ab[Z],this.view,this);this.add_drawable(aa)}},init:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z].init()}},_draw:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z]._draw()}},to_dict:function(){var aa=[];for(var Z=0;Z<this.drawables.length;Z++){aa.push(this.drawables[Z].to_dict())}return{name:this.name,prefs:this.prefs,obj_type:this.obj_type,drawables:aa}},add_drawable:function(Z){this.drawables.push(Z);Z.container=this;this.changed()},add_drawable_before:function(ab,Z){this.changed();var aa=this.drawables.indexOf(Z);if(aa!==-1){this.drawables.splice(aa,0,ab);return true}return false},replace_drawable:function(ab,Z,aa){var ac=this.drawables.indexOf(ab);if(ac!==-1){this.drawables[ac]=Z;if(aa){ab.container_div.replaceWith(Z.container_div)}this.changed()}return ac},remove_drawable:function(aa){var Z=this.drawables.indexOf(aa);if(Z!==-1){this.drawables.splice(Z,1);aa.container=null;this.changed();return true}return false},move_drawable:function(aa,ab){var Z=this.drawables.indexOf(aa);if(Z!==-1){this.drawables.splice(Z,1);this.drawables.splice(ab,0,aa);this.changed();return true}return false}});var M=function(aa,Z,ac){o(ac,{obj_type:"DrawableGroup",drag_handle_class:"group-handle"});w.call(this,aa,Z,ac);this.content_div=$("<div/>").addClass("content-div").attr("id","group_"+this.id+"_content_div").appendTo(this.container_div);k(this.container_div,this);k(this.content_div,this);l(this.container_div,this.drag_handle_class,".group",this);this.filters_manager=new V(this);this.header_div.after(this.filters_manager.parent_div);this.saved_filters_managers=[];if("drawables" in ac){this.unpack_drawables(ac.drawables)}if("filters" in ac){var ab=this.filters_manager;this.filters_manager=new V(this,ac.filters);ab.parent_div.replaceWith(this.filters_manager.parent_div);if(ac.filters.visible){this.setup_multitrack_filtering()}}};o(M.prototype,p.prototype,w.prototype,{action_icons_def:[p.prototype.action_icons_def[0],p.prototype.action_icons_def[1],{name:"composite_icon",title:"Show composite track",css_class:"layers-stack",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.show_composite_track()}},{name:"filters_icon",title:"Filters",css_class:"filters-icon",on_click_fn:function(Z){if(Z.filters_manager.visible()){Z.filters_manager.clear_filters();Z._restore_filter_managers()}else{Z.setup_multitrack_filtering();Z.request_draw(true)}Z.filters_manager.toggle()}},p.prototype.action_icons_def[2]],build_container_div:function(){var Z=$("<div/>").addClass("group").attr("id","group_"+this.id);if(this.container){this.container.content_div.append(Z)}return Z},build_header_div:function(){var Z=$("<div/>").addClass("track-header");Z.append($("<div/>").addClass(this.drag_handle_class));this.name_div=$("<div/>").addClass("track-name").text(this.name).appendTo(Z);return Z},hide_contents:function(){this.tiles_div.hide()},show_contents:function(){this.tiles_div.show();this.request_draw()},update_icons:function(){var ab=this.drawables.length;if(ab===0){this.action_icons.composite_icon.hide();this.action_icons.filters_icon.hide()}else{if(ab===1){if(this.drawables[0] instanceof g){this.action_icons.composite_icon.show()}this.action_icons.filters_icon.hide()}else{var ai,ah,af,al=true,ad=this.drawables[0].get_type(),Z=0;for(ai=0;ai<ab;ai++){af=this.drawables[ai];if(af.get_type()!==ad){can_composite=false;break}if(af instanceof c){Z++}}if(al||Z===1){this.action_icons.composite_icon.show()}else{this.action_icons.composite_icon.hide();$(".bs-tooltip").remove()}if(Z>1&&Z===this.drawables.length){var am={},aa;af=this.drawables[0];for(ah=0;ah<af.filters_manager.filters.length;ah++){aa=af.filters_manager.filters[ah];am[aa.name]=[aa]}for(ai=1;ai<this.drawables.length;ai++){af=this.drawables[ai];for(ah=0;ah<af.filters_manager.filters.length;ah++){aa=af.filters_manager.filters[ah];if(aa.name in am){am[aa.name].push(aa)}}}this.filters_manager.remove_all();var ac,ae,ag,aj;for(var ak in am){ac=am[ak];if(ac.length===Z){ae=new Q({name:ac[0].name,index:ac[0].index});this.filters_manager.add_filter(ae)}}if(this.filters_manager.filters.length>0){this.action_icons.filters_icon.show()}else{this.action_icons.filters_icon.hide()}}else{this.action_icons.filters_icon.hide()}}}},_restore_filter_managers:function(){for(var Z=0;Z<this.drawables.length;Z++){this.drawables[Z].filters_manager=this.saved_filters_managers[Z]}this.saved_filters_managers=[]},setup_multitrack_filtering:function(){if(this.filters_manager.filters.length>0){this.saved_filters_managers=[];for(var Z=0;Z<this.drawables.length;Z++){drawable=this.drawables[Z];this.saved_filters_managers.push(drawable.filters_manager);drawable.filters_manager=this.filters_manager}}this.filters_manager.init_filters()},show_composite_track:function(){var ad=[];for(var aa=0;aa<this.drawables.length;aa++){ad.push(this.drawables[aa].name)}var ab="Composite Track of "+this.drawables.length+" tracks ("+ad.join(", ")+")";var ac=new g(this.view,this.view,{name:ab,drawables:this.drawables});var Z=this.container.replace_drawable(this,ac,true);ac.request_draw()},add_drawable:function(Z){w.prototype.add_drawable.call(this,Z);this.update_icons()},remove_drawable:function(Z){w.prototype.remove_drawable.call(this,Z);this.update_icons()},to_dict:function(){if(this.filters_manager.visible()){this._restore_filter_managers()}var Z=o(w.prototype.to_dict.call(this),{filters:this.filters_manager.to_dict()});if(this.filters_manager.visible()){this.setup_multitrack_filtering()}return Z},request_draw:function(Z,ab){for(var aa=0;aa<this.drawables.length;aa++){this.drawables[aa].request_draw(Z,ab)}}});var X=function(Z){o(Z,{obj_type:"View"});w.call(this,"View",Z.container,Z);this.chrom=null;this.vis_id=Z.vis_id;this.dbkey=Z.dbkey;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 CanvasManager(this.container.get(0).ownerDocument);this.reset()};_.extend(X.prototype,Backbone.Events);o(X.prototype,w.prototype,{init:function(){this.requested_redraw=false;var ab=this.container,Z=this;this.top_container=$("<div/>").addClass("top-container").appendTo(ab);this.browser_content_div=$("<div/>").addClass("content").css("position","relative").appendTo(ab);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(ab);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;k(this.viewport_container,Z);this.intro_div=$("<div/>").addClass("intro").appendTo(this.viewport_container).hide();var ac=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_datasets(add_datasets_url,add_track_async_url,function(ad){_.each(ad,function(ae){Z.add_drawable(object_from_template(ae,Z,Z))})})});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("trackster-nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("trackster-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 aa=function(ad){if(ad.type==="focusout"||(ad.keyCode||ad.which)===13||(ad.keyCode||ad.which)===27){if((ad.keyCode||ad.which)!==27){Z.go_to($(this).val())}$(this).hide();$(this).val("");Z.location_span.show();Z.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",aa).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").attr("original-title","Click to change location").tooltip({placement:"bottom"}).appendTo(this.nav_controls);this.location_span.click(function(){Z.location_span.hide();Z.chrom_select.hide();Z.nav_input.val(Z.chrom+":"+Z.low+"-"+Z.high);Z.nav_input.css("display","inline-block");Z.nav_input.select();Z.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/>").attr("id","zoom-out").attr("title","Zoom out").tooltip({placement:"bottom"}).click(function(){Z.zoom_out();Z.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a/>").attr("id","zoom-in").attr("title","Zoom in").tooltip({placement:"bottom"}).click(function(){Z.zoom_in();Z.request_redraw()}).appendTo(this.nav_controls);this.load_chroms_deferred=this.load_chroms({low:0});this.chrom_select.bind("change",function(){Z.change_chrom(Z.chrom_select.val())});this.browser_content_div.click(function(ad){$(this).find("input").trigger("blur")});this.browser_content_div.bind("dblclick",function(ad){Z.zoom_in(ad.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(ad,ae){this.current_x=ae.offsetX}).bind("drag",function(ad,af){var ag=af.offsetX-this.current_x;this.current_x=af.offsetX;var ae=Math.round(ag/Z.viewport_container.width()*(Z.max_high-Z.max_low));Z.move_delta(-ae)});this.overview_close.click(function(){Z.reset_overview()});this.viewport_container.bind("draginit",function(ad,ae){if(ad.clientX>Z.viewport_container.width()-16){return false}}).bind("dragstart",function(ad,ae){ae.original_low=Z.low;ae.current_height=ad.clientY;ae.current_x=ae.offsetX}).bind("drag",function(af,ah){var ad=$(this);var ai=ah.offsetX-ah.current_x;var ae=ad.scrollTop()-(af.clientY-ah.current_height);ad.scrollTop(ae);ah.current_height=af.clientY;ah.current_x=ah.offsetX;var ag=Math.round(ai/Z.viewport_container.width()*(Z.high-Z.low));Z.move_delta(ag)}).bind("mousewheel",function(af,ah,ae,ad){if(ae){ae*=50;var ag=Math.round(-ae/Z.viewport_container.width()*(Z.high-Z.low));Z.move_delta(ag)}});this.top_labeltrack.bind("dragstart",function(ad,ae){return $("<div />").css({height:Z.browser_content_div.height()+Z.top_labeltrack.height()+Z.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(ah,ai){$(ai.proxy).css({left:Math.min(ah.pageX,ai.startX)-Z.container.offset().left,width:Math.abs(ah.pageX-ai.startX)});var ae=Math.min(ah.pageX,ai.startX)-Z.container.offset().left,ad=Math.max(ah.pageX,ai.startX)-Z.container.offset().left,ag=(Z.high-Z.low),af=Z.viewport_container.width();Z.update_location(Math.round(ae/af*ag)+Z.low,Math.round(ad/af*ag)+Z.low)}).bind("dragend",function(ai,aj){var ae=Math.min(ai.pageX,aj.startX),ad=Math.max(ai.pageX,aj.startX),ag=(Z.high-Z.low),af=Z.viewport_container.width(),ah=Z.low;Z.low=Math.round(ae/af*ag)+ah;Z.high=Math.round(ad/af*ag)+ah;$(aj.proxy).remove();Z.request_redraw()});this.add_label_track(new W(this,{content_div:this.top_labeltrack}));this.add_label_track(new W(this,{content_div:this.nav_labeltrack}));$(window).bind("resize",function(){if(this.resize_timer){clearTimeout(this.resize_timer)}this.resize_timer=setTimeout(function(){Z.resize_window()},500)});$(document).bind("redraw",function(){Z.redraw()});this.reset();$(window).trigger("resize")},changed:function(){this.has_changes=true},update_intro_div:function(){if(this.drawables.length===0){this.intro_div.show()}else{this.intro_div.hide()}},trigger_navigate:function(aa,ac,Z,ad){if(this.timer){clearTimeout(this.timer)}if(ad){var ab=this;this.timer=setTimeout(function(){ab.trigger("navigate",aa+":"+ac+"-"+Z)},500)}else{view.trigger("navigate",aa+":"+ac+"-"+Z)}},update_location:function(Z,ab){this.location_span.text(commatize(Z)+" - "+commatize(ab));this.nav_input.val(this.chrom+":"+commatize(Z)+"-"+commatize(ab));var aa=view.chrom_select.val();if(aa!==""){this.trigger_navigate(aa,view.low,view.high,true)}},load_chroms:function(ab){ab.num=u;ab.dbkey=this.dbkey;var Z=this,aa=$.Deferred();$.ajax({url:chrom_url,data:ab,dataType:"json",success:function(ad){if(ad.chrom_info.length===0){alert("Invalid chromosome: "+ab.chrom);return}if(ad.reference){Z.add_label_track(new y(Z))}Z.chrom_data=ad.chrom_info;var ag='<option value="">Select Chrom/Contig</option>';for(var af=0,ac=Z.chrom_data.length;af<ac;af++){var ae=Z.chrom_data[af].chrom;ag+='<option value="'+ae+'">'+ae+"</option>"}if(ad.prev_chroms){ag+='<option value="previous">Previous '+u+"</option>"}if(ad.next_chroms){ag+='<option value="next">Next '+u+"</option>"}Z.chrom_select.html(ag);Z.chrom_start_index=ad.start_index;aa.resolve(ad)},error:function(){alert("Could not load chroms for this dbkey:",Z.dbkey)}});return aa},change_chrom:function(ae,aa,ag){var ab=this;if(!ab.chrom_data){ab.load_chroms_deferred.then(function(){ab.change_chrom(ae,aa,ag)});return}if(!ae||ae==="None"){return}if(ae==="previous"){ab.load_chroms({low:this.chrom_start_index-u});return}if(ae==="next"){ab.load_chroms({low:this.chrom_start_index+u});return}var af=$.grep(ab.chrom_data,function(ah,ai){return ah.chrom===ae})[0];if(af===undefined){ab.load_chroms({chrom:ae},function(){ab.change_chrom(ae,aa,ag)});return}else{if(ae!==ab.chrom){ab.chrom=ae;ab.chrom_select.val(ab.chrom);ab.max_high=af.len-1;ab.reset();ab.request_redraw(true);for(var ad=0,Z=ab.drawables.length;ad<Z;ad++){var ac=ab.drawables[ad];if(ac.init){ac.init()}}if(ab.reference_track){ab.reference_track.init()}}if(aa!==undefined&&ag!==undefined){ab.low=Math.max(aa,0);ab.high=Math.min(ag,ab.max_high)}else{ab.low=0;ab.high=ab.max_high}ab.reset_overview();ab.request_redraw()}},go_to:function(ad){ad=ad.replace(/ |,/g,"");var ah=this,Z,ac,aa=ad.split(":"),af=aa[0],ag=aa[1];if(ag!==undefined){try{var ae=ag.split("-");Z=parseInt(ae[0],10);ac=parseInt(ae[1],10)}catch(ab){return false}}ah.change_chrom(af,Z,ac)},move_fraction:function(ab){var Z=this;var aa=Z.high-Z.low;this.move_delta(ab*aa)},move_delta:function(ac){var Z=this;var ab=Z.high-Z.low;if(Z.low-ac<Z.max_low){Z.low=Z.max_low;Z.high=Z.max_low+ab}else{if(Z.high-ac>Z.max_high){Z.high=Z.max_high;Z.low=Z.max_high-ab}else{Z.high-=ac;Z.low-=ac}}Z.request_redraw();var aa=Z.chrom_select.val();this.trigger_navigate(aa,Z.low,Z.high,true)},add_drawable:function(Z){w.prototype.add_drawable.call(this,Z);Z.init();this.changed();this.update_intro_div()},add_label_track:function(Z){Z.view=this;Z.init();this.label_tracks.push(Z)},remove_drawable:function(ab,aa){w.prototype.remove_drawable.call(this,ab);if(aa){var Z=this;ab.container_div.hide(0,function(){$(this).remove();Z.update_intro_div()})}},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(ah,Z,ag,ai){var af=this,ae=(ai?[ai]:af.drawables),ab;var aa;for(var ad=0;ad<ae.length;ad++){aa=ae[ad];ab=-1;for(var ac=0;ac<af.tracks_to_be_redrawn.length;ac++){if(af.tracks_to_be_redrawn[ac][0]===aa){ab=ac;break}}if(ab<0){af.tracks_to_be_redrawn.push([aa,Z,ag])}else{af.tracks_to_be_redrawn[ad][1]=Z;af.tracks_to_be_redrawn[ad][2]=ag}}if(!this.requested_redraw){requestAnimationFrame(function(){af._redraw(ah)});this.requested_redraw=true}},_redraw:function(aj){this.requested_redraw=false;var ag=this.low,ac=this.high;if(ag<this.max_low){ag=this.max_low}if(ac>this.max_high){ac=this.max_high}var ai=this.high-this.low;if(this.high!==0&&ai<this.min_separation){ac=ag+this.min_separation}this.low=Math.floor(ag);this.high=Math.ceil(ac);this.update_location(this.low,this.high);this.resolution_b_px=(this.high-this.low)/this.viewport_container.width();this.resolution_px_b=this.viewport_container.width()/(this.high-this.low);var Z=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var af=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ak=13;this.overview_box.css({left:Z,width:Math.max(ak,af)}).show();if(af<ak){this.overview_box.css("left",Z-(ak-af)/2)}if(this.overview_highlight){this.overview_highlight.css({left:Z,width:af})}if(!aj){var ab,aa,ah;for(var ad=0,ae=this.tracks_to_be_redrawn.length;ad<ae;ad++){ab=this.tracks_to_be_redrawn[ad][0];aa=this.tracks_to_be_redrawn[ad][1];ah=this.tracks_to_be_redrawn[ad][2];if(ab){ab._draw(aa,ah)}}this.tracks_to_be_redrawn=[];for(ad=0,ae=this.label_tracks.length;ad<ae;ad++){this.label_tracks[ad]._draw()}}},zoom_in:function(aa,ab){if(this.max_high===0||this.high-this.low<=this.min_separation){return}var ac=this.high-this.low,ad=ac/2+this.low,Z=(ac/this.zoom_factor)/2;if(aa){ad=aa/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(ad-Z);this.high=Math.round(ad+Z);this.changed();this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var aa=this.high-this.low,ab=aa/2+this.low,Z=(aa*this.zoom_factor)/2;this.low=Math.round(ab-Z);this.high=Math.round(ab+Z);this.changed();this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.request_redraw()},set_overview:function(ab){if(this.overview_drawable){if(this.overview_drawable.dataset_id===ab.dataset_id){return}this.overview_viewport.find(".track").remove()}var aa=ab.copy({content_div:this.overview_viewport}),Z=this;aa.header_div.hide();aa.is_overview=true;Z.overview_drawable=aa;this.overview_drawable.postdraw_actions=function(){Z.overview_highlight.show().height(Z.overview_drawable.content_div.height());Z.overview_viewport.height(Z.overview_drawable.content_div.height()+Z.overview_box.outerHeight());Z.overview_close.show();Z.resize_window()};Z.overview_drawable.request_draw();this.changed()},reset_overview:function(){$(".bs-tooltip").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 q=function(ab,ag,ac){this.track=ab;this.name=ag.name;this.params=[];var an=ag.params;for(var ad=0;ad<an.length;ad++){var ai=an[ad],aa=ai.name,am=ai.label,ae=unescape(ai.html),ao=ai.value,ak=ai.type;if(ak==="number"){this.params.push(new e(aa,am,ae,(aa in ac?ac[aa]:ao),ai.min,ai.max))}else{if(ak==="select"){this.params.push(new K(aa,am,ae,(aa in ac?ac[aa]:ao)))}else{console.log("WARNING: unrecognized tool parameter type:",aa,ak)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(aq){aq.stopPropagation()}).click(function(aq){aq.stopPropagation()}).bind("dblclick",function(aq){aq.stopPropagation()});var al=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var aj=this.params;var ah=this;$.each(this.params,function(ar,av){var au=$("<div>").addClass("param-row").appendTo(ah.parent_div);var aq=$("<div>").addClass("param-label").text(av.label).appendTo(au);var at=$("<div/>").addClass("param-input").html(av.html).appendTo(au);at.find(":input").val(av.value);$("<div style='clear: both;'/>").appendTo(au)});this.parent_div.find("input").click(function(){$(this).select()});var ap=$("<div>").addClass("param-row").appendTo(this.parent_div);var af=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(ap);var Z=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(ap);Z.click(function(){ah.run_on_region()});af.click(function(){ah.run_on_dataset()});if("visible" in ac&&ac.visible){this.parent_div.show()}};o(q.prototype,{update_params:function(){for(var Z=0;Z<this.params.length;Z++){this.params[Z].update_value()}},state_dict:function(){var aa={};for(var Z=0;Z<this.params.length;Z++){aa[this.params[Z].name]=this.params[Z].value}aa.visible=this.parent_div.is(":visible");return aa},get_param_values_dict:function(){var Z={};this.parent_div.find(":input").each(function(){var aa=$(this).attr("name"),ab=$(this).val();Z[aa]=ab});return Z},get_param_values:function(){var Z=[];this.parent_div.find(":input").each(function(){var aa=$(this).attr("name"),ab=$(this).val();if(aa){Z[Z.length]=ab}});return Z},run_on_dataset:function(){var Z=this;Z.run({target_dataset_id:this.track.original_dataset_id,tool_id:Z.name},null,function(aa){show_modal(Z.name+" is Running",Z.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var aa={target_dataset_id:this.track.original_dataset_id,action:"rerun",tool_id:this.name,regions:[{chrom:this.track.view.chrom,start:this.track.view.low,end:this.track.view.high}]},ae=this.track,ab=aa.tool_id+ae.tool_region_and_parameters_str(aa.chrom,aa.low,aa.high),Z;if(ae.container===view){var ad=new M(view,view,{name:this.name});var ac=ae.container.replace_drawable(ae,ad,false);ad.container_div.insertBefore(ae.view.content_div.children()[ac]);ad.add_drawable(ae);ae.container_div.appendTo(ad.content_div);Z=ad}else{Z=ae.container}var af=new ae.constructor(view,Z,{name:ab,hda_ldda:"hda"});af.init_for_tool_data();af.change_mode(ae.mode);af.set_filters_manager(ae.filters_manager.copy(af));af.update_icons();Z.add_drawable(af);af.tiles_div.text("Starting job.");this.update_params();this.run(aa,af,function(ag){af.set_dataset(new Dataset(ag));af.tiles_div.text("Running job.");af.init()})},run:function(Z,ab,ac){Z.inputs=this.get_param_values_dict();var aa=new ServerStateDeferred({ajax_settings:{url:galaxy_paths.get("tool_url"),data:JSON.stringify(Z),dataType:"json",contentType:"application/json",type:"POST"},interval:2000,success_fn:function(ad){return ad!=="pending"}});$.when(aa.go()).then(function(ad){if(ad==="no converter"){ab.container_div.addClass("error");ab.content_div.text(G)}else{if(ad.error){ab.container_div.addClass("error");ab.content_div.text(v+ad.message)}else{ac(ad)}}})}});var K=function(aa,Z,ab,ac){this.name=aa;this.label=Z;this.html=$(ab);this.value=ac};o(K.prototype,{update_value:function(){this.value=$(this.html).val()}});var e=function(ab,aa,ad,ae,ac,Z){K.call(this,ab,aa,ad,ae);this.min=ac;this.max=Z};o(e.prototype,K.prototype,{update_value:function(){K.prototype.update_value.call(this);this.value=parseFloat(this.value)}});var f=function(Z){this.manager=null;this.name=Z.name;this.index=Z.index;this.tool_id=Z.tool_id;this.tool_exp_name=Z.tool_exp_name};o(f.prototype,{to_dict:function(){return{name:this.name,index:this.index,tool_id:this.tool_id,tool_exp_name:this.tool_exp_name}}});var Q=function(ah){f.call(this,ah);this.low=("low" in ah?ah.low:-Number.MAX_VALUE);this.high=("high" in ah?ah.high:Number.MAX_VALUE);this.min=("min" in ah?ah.min:Number.MAX_VALUE);this.max=("max" in ah?ah.max:-Number.MAX_VALUE);this.container=null;this.slider=null;this.slider_label=null;var ad=function(ai,aj,ak){ai.click(function(){var ap=aj.text(),an=parseFloat(ak.slider("option","max")),am=(an<=1?4:an<=1000000?an.toString().length:6),ao=false,al=$(this).parents(".slider-row");al.addClass("input");if(ak.slider("option","values")){am=2*am+1;ao=true}aj.text("");$("<input type='text'/>").attr("size",am).attr("maxlength",am).attr("value",ap).appendTo(aj).focus().select().click(function(aq){aq.stopPropagation()}).blur(function(){$(this).remove();aj.text(ap);al.removeClass("input")}).keyup(function(av){if(av.keyCode===27){$(this).trigger("blur")}else{if(av.keyCode===13){var at=ak.slider("option","min"),aq=ak.slider("option","max"),au=function(aw){return(isNaN(aw)||aw>aq||aw<at)},ar=$(this).val();if(!ao){ar=parseFloat(ar);if(au(ar)){alert("Parameter value must be in the range ["+at+"-"+aq+"]");return $(this)}}else{ar=ar.split("-");ar=[parseFloat(ar[0]),parseFloat(ar[1])];if(au(ar[0])||au(ar[1])){alert("Parameter value must be in the range ["+at+"-"+aq+"]");return $(this)}}ak.slider((ao?"values":"value"),ar);al.removeClass("input")}}})})};var aa=this;aa.parent_div=$("<div/>").addClass("filter-row slider-row");var Z=$("<div/>").addClass("elt-label").appendTo(aa.parent_div),af=$("<span/>").addClass("slider-name").text(aa.name+" ").appendTo(Z),ab=$("<span/>").text(this.low+"-"+this.high),ac=$("<span/>").addClass("slider-value").appendTo(Z).append("[").append(ab).append("]");aa.values_span=ab;var ae=$("<div/>").addClass("slider").appendTo(aa.parent_div);aa.control_element=$("<div/>").attr("id",aa.name+"-filter-control").appendTo(ae);aa.control_element.slider({range:true,min:this.min,max:this.max,step:this.get_slider_step(this.min,this.max),values:[this.low,this.high],slide:function(ai,aj){aa.slide(ai,aj)},change:function(ai,aj){aa.control_element.slider("option","slide").call(aa.control_element,ai,aj)}});aa.slider=aa.control_element;aa.slider_label=ab;ad(ac,ab,aa.control_element);var ag=$("<div/>").addClass("display-controls").appendTo(aa.parent_div);this.transparency_icon=create_action_icon("Use filter for data transparency","layer-transparent",function(){if(aa.manager.alpha_filter!==aa){aa.manager.alpha_filter=aa;aa.manager.parent_div.find(".layer-transparent").removeClass("active").hide();aa.transparency_icon.addClass("active").show()}else{aa.manager.alpha_filter=null;aa.transparency_icon.removeClass("active")}aa.manager.track.request_draw(true,true)}).appendTo(ag).hide();this.height_icon=create_action_icon("Use filter for data height","arrow-resize-090",function(){if(aa.manager.height_filter!==aa){aa.manager.height_filter=aa;aa.manager.parent_div.find(".arrow-resize-090").removeClass("active").hide();aa.height_icon.addClass("active").show()}else{aa.manager.height_filter=null;aa.height_icon.removeClass("active")}aa.manager.track.request_draw(true,true)}).appendTo(ag).hide();aa.parent_div.hover(function(){aa.transparency_icon.show();aa.height_icon.show()},function(){if(aa.manager.alpha_filter!==aa){aa.transparency_icon.hide()}if(aa.manager.height_filter!==aa){aa.height_icon.hide()}});$("<div style='clear: both;'/>").appendTo(aa.parent_div)};o(Q.prototype,{to_dict:function(){var Z=f.prototype.to_dict.call(this);return o(Z,{type:"number",min:this.min,max:this.max,low:this.low,high:this.high})},copy:function(){return new Q({name:this.name,index:this.index,tool_id:this.tool_id,tool_exp_name:this.tool_exp_name})},get_slider_step:function(ab,Z){var aa=Z-ab;return(aa<=2?0.01:1)},slide:function(ab,ac){var aa=ac.values;this.values_span.text(aa[0]+"-"+aa[1]);this.low=aa[0];this.high=aa[1];var Z=this;setTimeout(function(){if(aa[0]===Z.low&&aa[1]===Z.high){Z.manager.track.request_draw(true,true)}},25)},applies_to:function(Z){if(Z.length>this.index){return true}return false},_keep_val:function(Z){return(isNaN(Z)||(Z>=this.low&&Z<=this.high))},keep:function(aa){if(!this.applies_to(aa)){return true}var ac=this;var ad=aa[this.index];if(ad instanceof Array){var ab=true;for(var Z=0;Z<ad.length;Z++){if(!this._keep_val(ad[Z])){ab=false;break}}return ab}else{return this._keep_val(aa[this.index])}},update_attrs:function(ac){var Z=false;if(!this.applies_to(ac)){return Z}var aa=ac[this.index];if(!(aa instanceof Array)){aa=[aa]}for(var ab=0;ab<aa.length;ab++){var ad=aa[ab];if(ad<this.min){this.min=Math.floor(ad);Z=true}if(ad>this.max){this.max=Math.ceil(ad);Z=true}}return Z},update_ui_elt:function(){if(this.min<this.max){this.parent_div.show()}else{this.parent_div.hide()}var aa=this.slider.slider("option","min"),Z=this.slider.slider("option","max");if(this.min<aa||this.max>Z){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",this.get_slider_step(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var V=function(ab,ah){this.track=ab;this.alpha_filter=null;this.height_filter=null;this.filters=[];this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(aj){aj.stopPropagation()}).click(function(aj){aj.stopPropagation()}).bind("dblclick",function(aj){aj.stopPropagation()}).bind("keydown",function(aj){aj.stopPropagation()});if(ah&&"filters" in ah){var Z=("alpha_filter" in ah?ah.alpha_filter:null),ac=("height_filter" in ah?ah.height_filter:null),ae=ah.filters,aa;for(var af=0;af<ae.length;af++){if(ae[af].type==="number"){aa=new Q(ae[af]);this.add_filter(aa);if(aa.name===Z){this.alpha_filter=aa;aa.transparency_icon.addClass("active").show()}if(aa.name===ac){this.height_filter=aa;aa.height_icon.addClass("active").show()}}else{console.log("ERROR: unsupported filter: ",name,type)}}if("visible" in ah&&ah.visible){this.parent_div.show()}}if(this.filters.length!==0){var ai=$("<div/>").addClass("param-row").appendTo(this.parent_div);var ag=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(ai);var ad=this;ag.click(function(){ad.run_on_dataset()})}};o(V.prototype,{show:function(){this.parent_div.show()},hide:function(){this.parent_div.hide()},toggle:function(){this.parent_div.toggle()},visible:function(){return this.parent_div.is(":visible")},to_dict:function(){var ac={},ab=[],aa;for(var Z=0;Z<this.filters.length;Z++){aa=this.filters[Z];ab.push(aa.to_dict())}ac.filters=ab;ac.alpha_filter=(this.alpha_filter?this.alpha_filter.name:null);ac.height_filter=(this.height_filter?this.height_filter.name:null);ac.visible=this.parent_div.is(":visible");return ac},copy:function(aa){var ab=new V(aa);for(var Z=0;Z<this.filters.length;Z++){ab.add_filter(this.filters[Z].copy())}return ab},add_filter:function(Z){Z.manager=this;this.parent_div.append(Z.parent_div);this.filters.push(Z)},remove_all:function(){this.filters=[];this.parent_div.children().remove()},init_filters:function(){for(var Z=0;Z<this.filters.length;Z++){var aa=this.filters[Z];aa.update_ui_elt()}},clear_filters:function(){for(var Z=0;Z<this.filters.length;Z++){var aa=this.filters[Z];aa.slider.slider("option","values",[aa.min,aa.max])}this.alpha_filter=null;this.height_filter=null;this.parent_div.find(".icon-button").hide()},run_on_dataset:function(){var af=function(aj,ah,ai){if(!(ah in aj)){aj[ah]=ai}return aj[ah]};var ae={},ag,Z;for(var ad=0;ad<this.filters.length;ad++){ag=this.filters[ad];if(ag.tool_id){if(ag.min!==ag.low){Z=af(ae,ag.tool_id,[]);Z[Z.length]=ag.tool_exp_name+" >= "+ag.low}if(ag.max!==ag.high){Z=af(ae,ag.tool_id,[]);Z[Z.length]=ag.tool_exp_name+" <= "+ag.high}}}var aa=[];for(var ac in ae){aa[aa.length]=[ac,ae[ac]]}(function ab(an,ak){var ai=ak[0],aj=ai[0],am=ai[1],al="("+am.join(") and (")+")",ah={cond:al,input:an,target_dataset_id:an,tool_id:aj},ak=ak.slice(1);$.getJSON(run_tool_url,ah,function(ao){if(ao.error){show_modal("Filter Dataset","Error running tool "+aj,{Close:hide_modal})}else{if(ak.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{ab(ao.dataset_id,ak)}}})})(this.track.dataset_id,aa)}});var z=function(Z,aa){I.Scaler.call(this,aa);this.filter=Z};z.prototype.gen_val=function(Z){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(Z[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var C=function(Z){this.track=Z.track;this.params=Z.params;this.values={};this.restore_values((Z.saved_values?Z.saved_values:{}));this.onchange=Z.onchange};o(C.prototype,{restore_values:function(Z){var aa=this;$.each(this.params,function(ab,ac){if(Z[ac.key]!==undefined){aa.values[ac.key]=Z[ac.key]}else{aa.values[ac.key]=ac.default_value}})},build_form:function(){var ac=this;var Z=$("<div />");var ab;function aa(ah,ad){for(var al=0;al<ah.length;al++){ab=ah[al];if(ab.hidden){continue}var af="param_"+al;var ap=ac.values[ab.key];var ar=$("<div class='form-row' />").appendTo(ad);ar.append($("<label />").attr("for",af).text(ab.label+":"));if(ab.type==="bool"){ar.append($('<input type="checkbox" />').attr("id",af).attr("name",af).attr("checked",ap))}else{if(ab.type==="text"){ar.append($('<input type="text"/>').attr("id",af).val(ap).click(function(){$(this).select()}))}else{if(ab.type==="select"){var an=$("<select />").attr("id",af);for(var aj=0;aj<ab.options.length;aj++){$("<option/>").text(ab.options[aj].label).attr("value",ab.options[aj].value).appendTo(an)}an.val(ap);ar.append(an)}else{if(ab.type==="color"){var aq=$("<div/>").appendTo(ar),am=$("<input />").attr("id",af).attr("name",af).val(ap).css("float","left").appendTo(aq).click(function(au){$(".bs-tooltip").removeClass("in");var at=$(this).siblings(".bs-tooltip").addClass("in");at.css({left:$(this).position().left+$(this).width()+5,top:$(this).position().top-($(at).height()/2)+($(this).height()/2)}).show();at.click(function(av){av.stopPropagation()});$(document).bind("click.color-picker",function(){at.hide();$(document).unbind("click.color-picker")});au.stopPropagation()}),ak=$("<a href='javascript:void(0)'/>").addClass("icon-button arrow-circle").appendTo(aq).attr("title","Set new random color").tooltip(),ao=$("<div class='bs-tooltip right' style='position: absolute;' />").appendTo(aq).hide(),ag=$("<div class='tooltip-inner' style='text-align: inherit'></div>").appendTo(ao),ae=$("<div class='tooltip-arrow'></div>").appendTo(ao),ai=$.farbtastic(ag,{width:100,height:100,callback:am,color:ap});aq.append($("<div/>").css("clear","both"));(function(at){ak.click(function(){at.setColor(get_random_color())})})(ai)}else{ar.append($("<input />").attr("id",af).attr("name",af).val(ap))}}}}if(ab.help){ar.append($("<div class='help'/>").text(ab.help))}}}aa(this.params,Z);return Z},update_from_form:function(Z){var ab=this;var aa=false;$.each(this.params,function(ac,ae){if(!ae.hidden){var af="param_"+ac;var ad=Z.find("#"+af).val();if(ae.type==="float"){ad=parseFloat(ad)}else{if(ae.type==="int"){ad=parseInt(ad)}else{if(ae.type==="bool"){ad=Z.find("#"+af).is(":checked")}}}if(ad!==ab.values[ae.key]){ab.values[ae.key]=ad;aa=true}}});if(aa){this.onchange();this.track.changed()}}});var b=function(Z,ad,ab,aa,ac){this.track=Z;this.region=ad;this.low=ad.get("start");this.high=ad.get("end");this.resolution=ab;this.html_elt=$("<div class='track-tile'/>").append(aa).height($(aa).attr("height"));this.data=ac;this.stale=false};b.prototype.predisplay_actions=function(){};var j=function(Z,ae,ab,aa,ac,ad){b.call(this,Z,ae,ab,aa,ac);this.max_val=ad};o(j.prototype,b.prototype);var L=function(ac,ak,ad,ab,af,am,ag,an,aa,aj){b.call(this,ac,ak,ad,ab,af);this.mode=ag;this.all_slotted=aa;this.feature_mapper=aj;this.has_icons=false;if(an){this.has_icons=true;var ah=this;ab=this.html_elt.children()[0],message_div=$("<div/>").addClass("tile-message").css({height:A-1,width:ab.width}).prependTo(this.html_elt);var ai=new GenomeRegion({chrom:ac.view.chrom,start:this.low,end:this.high}),al=af.length,ae=$("<a href='javascript:void(0);'/>").addClass("icon more-down").attr("title","For speed, only the first "+al+" features in this region were obtained from server. Click to get more data including depth").tooltip().appendTo(message_div),Z=$("<a href='javascript:void(0);'/>").addClass("icon more-across").attr("title","For speed, only the first "+al+" features in this region were obtained from server. Click to get more data excluding depth").tooltip().appendTo(message_div);ae.click(function(){ah.stale=true;ac.data_manager.get_more_data(ai,ac.mode,ah.resolution,{},ac.data_manager.DEEP_DATA_REQ);$(".bs-tooltip").hide();ac.request_draw(true)}).dblclick(function(ao){ao.stopPropagation()});Z.click(function(){ah.stale=true;ac.data_manager.get_more_data(ai,ac.mode,ah.resolution,{},ac.data_manager.BROAD_DATA_REQ);$(".bs-tooltip").hide();ac.request_draw(true)}).dblclick(function(ao){ao.stopPropagation()})}};o(L.prototype,b.prototype);L.prototype.predisplay_actions=function(){var aa=this,Z={};if(aa.mode!=="Pack"){return}$(this.html_elt).hover(function(){this.hovered=true;$(this).mousemove()},function(){this.hovered=false;$(this).parents(".track-content").children(".overlay").children(".feature-popup").remove()}).mousemove(function(al){if(!this.hovered){return}var ag=$(this).offset(),ak=al.pageX-ag.left,aj=al.pageY-ag.top,ap=aa.feature_mapper.get_feature_data(ak,aj),ah=(ap?ap[0]:null);$(this).parents(".track-content").children(".overlay").children(".feature-popup").each(function(){if(!ah||$(this).attr("id")!==ah.toString()){$(this).remove()}});if(ap){var ac=Z[ah];if(!ac){var ah=ap[0],am={name:ap[3],start:ap[1],end:ap[2],strand:ap[4]},af=aa.track.filters_manager.filters,ae;for(var ai=0;ai<af.length;ai++){ae=af[ai];am[ae.name]=ap[ae.index]}var ac=$("<div/>").attr("id",ah).addClass("feature-popup"),aq=$("<table/>"),ao,an,ar;for(ao in am){an=am[ao];ar=$("<tr/>").appendTo(aq);$("<th/>").appendTo(ar).text(ao);$("<td/>").attr("align","left").appendTo(ar).text(typeof(an)==="number"?U(an,2):an)}ac.append($("<div class='feature-popup-inner'>").append(aq));Z[ah]=ac}ac.appendTo($(this).parents(".track-content").children(".overlay"));var ad=ak+parseInt(aa.html_elt.css("left"))-ac.width()/2,ab=aj+parseInt(aa.html_elt.css("top"))+7;ac.css("left",ad+"px").css("top",ab+"px")}else{if(!al.isPropagationStopped()){al.stopPropagation();$(this).siblings().each(function(){$(this).trigger(al)})}}}).mouseleave(function(){$(this).parents(".track-content").children(".overlay").children(".feature-popup").remove()})};var h=function(ab,aa,ad){o(ad,{drag_handle_class:"draghandle"});p.call(this,ab,aa,ad);this.data_url=("data_url" in ad?ad.data_url:default_data_url);this.data_url_extra_params={};this.data_query_wait=("data_query_wait" in ad?ad.data_query_wait:H);this.dataset_check_url=("converted_datasets_state_url" in ad?ad.converted_datasets_state_url:converted_datasets_state_url);var Z=this,ac=new Dataset({id:ad.dataset_id,hda_ldda:ad.hda_ldda});this.data_manager=("data_manager" in ad?ad.data_manager:new GenomeDataManager({dataset:ac,data_url:Z.data_url,dataset_state_url:Z.dataset_check_url,data_mode_compatible:this.data_and_mode_compatible,can_subset:this.can_subset}));this.min_height_px=16;this.max_height_px=800;this.visible_height_px=0;this.content_div=$("<div class='track-content'>").appendTo(this.container_div);if(this.container){this.container.content_div.append(this.container_div);if(!("resize" in ad)||ad.resize){this.add_resize_handle()}}};o(h.prototype,p.prototype,{action_icons_def:[{name:"mode_icon",title:"Set display mode",css_class:"chevron-expand",on_click_fn:function(){}},p.prototype.action_icons_def[0],{name:"overview_icon",title:"Set as overview",css_class:"overview-icon",on_click_fn:function(Z){Z.view.set_overview(Z)}},p.prototype.action_icons_def[1],{name:"filters_icon",title:"Filters",css_class:"filters-icon",on_click_fn:function(Z){if(Z.filters_manager.visible()){Z.filters_manager.clear_filters()}else{Z.filters_manager.init_filters()}Z.filters_manager.toggle()}},{name:"tools_icon",title:"Tool",css_class:"hammer",on_click_fn:function(Z){Z.dynamic_tool_div.toggle();if(Z.dynamic_tool_div.is(":visible")){Z.set_name(Z.name+Z.tool_region_and_parameters_str())}else{Z.revert_name()}$(".bs-tooltip").remove()}},{name:"param_space_viz_icon",title:"Tool parameter space visualization",css_class:"arrow-split",on_click_fn:function(Z){var ac='<strong>Tool</strong>: <%= track.tool.name %><br/><strong>Dataset</strong>: <%= track.name %><br/><strong>Region(s)</strong>: <select name="regions"><option value="cur">current viewing area</option><option value="bookmarks">bookmarks</option><option value="both">current viewing area and bookmarks</option></select>',ab=_.template(ac,{track:Z});var ae=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},aa=function(){var ag=$('select[name="regions"] option:selected').val(),ai,af=new GenomeRegion({chrom:view.chrom,start:view.low,end:view.high}),ah=_.map($(".bookmark"),function(aj){return new GenomeRegion({from_str:$(aj).children(".position").text()})});if(ag==="cur"){ai=[af]}else{if(ag==="bookmarks"){ai=ah}else{ai=[af].concat(ah)}}hide_modal();window.location.href=galaxy_paths.get("sweepster_url")+"?"+$.param({dataset_id:Z.dataset_id,hda_ldda:Z.hda_ldda,regions:JSON.stringify(new Backbone.Collection(ai).toJSON())})},ad=function(af){if((af.keyCode||af.which)===27){ae()}else{if((af.keyCode||af.which)===13){aa()}}};show_modal("Visualize tool parameter space and output from different parameter settings?",ab,{No:ae,Yes:aa})}},p.prototype.action_icons_def[2]],can_draw:function(){if(this.dataset_id&&p.prototype.can_draw.call(this)){return true}return false},build_container_div:function(){return $("<div/>").addClass("track").attr("id","track_"+this.id).css("position","relative")},build_header_div:function(){var Z=$("<div class='track-header'/>");if(this.view.editor){this.drag_div=$("<div/>").addClass(this.drag_handle_class).appendTo(Z)}this.name_div=$("<div/>").addClass("track-name").appendTo(Z).text(this.name).attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase());return Z},on_resize:function(){},add_resize_handle:function(){var Z=this;var ac=false;var ab=false;var aa=$("<div class='track-resize'>");$(Z.container_div).hover(function(){if(Z.content_visible){ac=true;aa.show()}},function(){ac=false;if(!ab){aa.hide()}});aa.hide().bind("dragstart",function(ad,ae){ab=true;ae.original_height=$(Z.content_div).height()}).bind("drag",function(ae,af){var ad=Math.min(Math.max(af.original_height+af.deltaY,Z.min_height_px),Z.max_height_px);$(Z.tiles_div).css("height",ad);Z.visible_height_px=(Z.max_height_px===ad?0:ad);Z.on_resize()}).bind("dragend",function(ad,ae){Z.tile_cache.clear();ab=false;if(!ac){aa.hide()}Z.config.values.height=Z.visible_height_px;Z.changed()}).appendTo(Z.container_div)},set_display_modes:function(ac,af){this.display_modes=ac;this.mode=(af?af:(this.config&&this.config.values.mode?this.config.values.mode:this.display_modes[0]));this.action_icons.mode_icon.attr("title","Set display mode (now: "+this.mode+")");var aa=this,ad={};for(var ab=0,Z=aa.display_modes.length;ab<Z;ab++){var ae=aa.display_modes[ab];ad[ae]=function(ag){return function(){aa.change_mode(ag);aa.icons_div.show();aa.container_div.mouseleave(function(){aa.icons_div.hide()})}}(ae)}make_popupmenu(this.action_icons.mode_icon,ad)},build_action_icons:function(){p.prototype.build_action_icons.call(this,this.action_icons_def);if(this.display_modes!==undefined){this.set_display_modes(this.display_modes)}},hide_contents:function(){this.tiles_div.hide();this.container_div.find(".yaxislabel, .track-resize").hide()},show_contents:function(){this.tiles_div.show();this.container_div.find(".yaxislabel, .track-resize").show();this.request_draw()},get_type:function(){if(this instanceof W){return"LabelTrack"}else{if(this instanceof y){return"ReferenceTrack"}else{if(this instanceof i){return"LineTrack"}else{if(this instanceof R){return"ReadTrack"}else{if(this instanceof O){return"VcfTrack"}else{if(this instanceof g){return"CompositeTrack"}else{if(this instanceof c){return"FeatureTrack"}}}}}}}return""},init:function(){var aa=this;aa.enabled=false;aa.tile_cache.clear();aa.data_manager.clear();aa.content_div.css("height","auto");aa.tiles_div.children().remove();aa.container_div.removeClass("nodata error pending");if(!aa.dataset_id){return}var Z=$.Deferred();$.getJSON(this.dataset_check_url,{hda_ldda:aa.hda_ldda,dataset_id:aa.dataset_id,chrom:aa.view.chrom},function(ab){if(!ab||ab==="error"||ab.kind==="error"){aa.container_div.addClass("error");aa.tiles_div.text(n);if(ab.message){var ac=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+ab.message+"</pre>",{Close:hide_modal})});aa.tiles_div.append(ac)}}else{if(ab==="no converter"){aa.container_div.addClass("error");aa.tiles_div.text(G)}else{if(ab==="no data"||(ab.data!==undefined&&(ab.data===null||ab.data.length===0))){aa.container_div.addClass("nodata");aa.tiles_div.text(B)}else{if(ab==="pending"){aa.container_div.addClass("pending");aa.tiles_div.html(t);setTimeout(function(){aa.init()},aa.data_query_wait)}else{if(ab==="data"||ab.status==="data"){if(ab.valid_chroms){aa.valid_chroms=ab.valid_chroms;aa.update_icons()}aa.tiles_div.text(T);if(aa.view.chrom){aa.tiles_div.text("");aa.tiles_div.css("height",aa.visible_height_px+"px");aa.enabled=true;$.when(aa.predraw_init()).done(function(){Z.resolve();aa.container_div.removeClass("nodata error pending");aa.request_draw()})}else{Z.resolve()}}}}}}});this.update_icons();return Z},predraw_init:function(){}});var J=function(ab,aa,ac){h.call(this,ab,aa,ac);var Z=this,ab=Z.view;l(Z.container_div,Z.drag_handle_class,".group",Z);this.filters_manager=new V(this,("filters" in ac?ac.filters:null));this.data_manager.set("filters_manager",this.filters_manager);this.filters_available=false;this.tool=("tool" in ac&&ac.tool?new q(this,ac.tool,ac.tool_state):null);this.tile_cache=new Cache(N);if(this.header_div){this.set_filters_manager(this.filters_manager);if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}}this.tiles_div=$("<div/>").addClass("tiles").appendTo(this.content_div);this.overlay_div=$("<div/>").addClass("overlay").appendTo(this.content_div);if(ac.mode){this.change_mode(ac.mode)}};o(J.prototype,p.prototype,h.prototype,{action_icons_def:h.prototype.action_icons_def.concat([{name:"show_more_rows_icon",title:"To minimize track height, not all feature rows are displayed. Click to display more rows.",css_class:"exclamation",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.slotters[Z.view.resolution_px_b].max_rows*=2;Z.request_draw(true)},hide:true}]),copy:function(Z){var aa=this.to_dict();o(aa,{data_manager:this.data_manager});var ab=new this.constructor(this.view,Z,aa);ab.change_mode(this.mode);ab.enabled=this.enabled;return ab},set_filters_manager:function(Z){this.filters_manager=Z;this.header_div.after(this.filters_manager.parent_div)},to_dict: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,filters:this.filters_manager.to_dict(),tool_state:(this.tool?this.tool.state_dict():{})}},change_mode:function(aa){var Z=this;Z.mode=aa;Z.config.values.mode=aa;Z.tile_cache.clear();Z.request_draw();this.action_icons.mode_icon.attr("title","Set display mode (now: "+Z.mode+")");return Z},update_icons:function(){var Z=this;if(Z.filters_available){Z.action_icons.filters_icon.show()}else{Z.action_icons.filters_icon.hide()}if(Z.tool){Z.action_icons.tools_icon.show();Z.action_icons.param_space_viz_icon.show()}else{Z.action_icons.tools_icon.hide();Z.action_icons.param_space_viz_icon.hide()}},_gen_tile_cache_key:function(aa,ab,Z){return aa+"_"+ab+"_"+Z},request_draw:function(aa,Z){this.view.request_redraw(false,aa,Z,this)},before_draw:function(){},_draw:function(aa,ak){if(!this.can_draw()){return}var ai=this.view.low,ae=this.view.high,ag=ae-ai,ab=this.view.container.width(),am=this.view.resolution_px_b,ad=this.view.resolution_b_px;if(this.is_overview){ai=this.view.max_low;ae=this.view.max_high;ad=Math.pow(RESOLUTION,Math.ceil(Math.log((view.max_high-view.max_low)/P)/Math.log(RESOLUTION)));am=ab/(view.max_high-view.max_low)}this.before_draw();this.tiles_div.children().addClass("remove");var Z=Math.floor(ai/(ad*P)),ah=true,al=[],af=function(an){return(an&&"track" in an)};while((Z*P*ad)<ae){var aj=this.draw_helper(aa,ab,Z,ad,this.tiles_div,am);if(af(aj)){al.push(aj)}else{ah=false}Z+=1}if(!ak){this.tiles_div.children(".remove").removeClass("remove").remove()}var ac=this;if(ah){this.tiles_div.children(".remove").remove();ac.postdraw_actions(al,ab,am,ak)}},postdraw_actions:function(ac,ad,af,Z){var ab=this;var ae=false;for(var aa=0;aa<ac.length;aa++){if(ac[aa].has_icons){ae=true;break}}if(ae){for(var aa=0;aa<ac.length;aa++){tile=ac[aa];if(!tile.has_icons){tile.html_elt.css("padding-top",A)}}}},draw_helper:function(Z,al,aq,ao,ae,af,am){var ak=this,au=this._gen_tile_cache_key(al,af,aq),ac=this._get_tile_bounds(aq,ao);if(!am){am={}}var at=(Z?undefined:ak.tile_cache.get_elt(au));if(at){ak.show_tile(at,ae,af);return at}var ai=true;var ap=ak.data_manager.get_data(ac,ak.mode,ao,ak.data_url_extra_params);if(is_deferred(ap)){ai=false}var ag;if(view.reference_track&&af>view.canvas_manager.char_width_px){ag=view.reference_track.data_manager.get_data(ac,ak.mode,ao,view.reference_track.data_url_extra_params);if(is_deferred(ag)){ai=false}}if(ai){o(ap,am.more_tile_data);var ah=ak.mode;if(ah==="Auto"){ah=ak.get_mode(ap);ak.update_auto_mode(ah)}var ab=ak.view.canvas_manager.new_canvas(),ar=ac.get("start"),aa=ac.get("end"),al=Math.ceil((aa-ar)*af)+ak.left_offset,aj=ak.get_canvas_height(ap,ah,af,al);ab.width=al;ab.height=aj;var an=ab.getContext("2d");an.translate(this.left_offset,0);var at=ak.draw_tile(ap,an,ah,ao,ac,af,ag);if(at!==undefined){ak.tile_cache.set_elt(au,at);ak.show_tile(at,ae,af)}return at}var ad=$.Deferred();$.when(ap,ag).then(function(){view.request_redraw(false,false,false,ak);ad.resolve()});return ad},get_canvas_height:function(Z,ab,ac,aa){return this.visible_height_px},draw_tile:function(Z,aa,ae,ac,ad,af,ab){console.log("Warning: TiledTrack.draw_tile() not implemented.")},show_tile:function(ab,ad,ae){var aa=this,Z=ab.html_elt;ab.predisplay_actions();var ac=(ab.low-(this.is_overview?this.view.max_low:this.view.low))*ae;if(this.left_offset){ac-=this.left_offset}Z.css({position:"absolute",top:0,left:ac});if(Z.hasClass("remove")){Z.removeClass("remove")}else{ad.append(Z)}aa.after_show_tile(ab)},after_show_tile:function(Z){this.max_height_px=Math.max(this.max_height_px,Z.html_elt.height());Z.html_elt.parent().children().css("height",this.max_height_px+"px");var aa=this.max_height_px;if(this.visible_height_px!==0){aa=Math.min(this.max_height_px,this.visible_height_px)}this.tiles_div.css("height",aa+"px")},_get_tile_bounds:function(Z,aa){var ac=Math.floor(Z*P*aa),ad=Math.ceil(P*aa),ab=(ac+ad<=this.view.max_high?ac+ad:this.view.max_high);return new GenomeRegion({chrom:this.view.chrom,start:ac,end:ab})},tool_region_and_parameters_str:function(ab,Z,ac){var aa=this,ad=(ab!==undefined&&Z!==undefined&&ac!==undefined?ab+":"+Z+"-"+ac:"all");return" - region=["+ad+"], parameters=["+aa.tool.get_param_values().join(", ")+"]"},data_and_mode_compatible:function(Z,aa){return true},can_subset:function(Z){return false},init_for_tool_data:function(){this.data_manager.set("data_url",raw_data_url);this.data_query_wait=1000;this.dataset_check_url=dataset_state_url;this.normal_postdraw_actions=this.postdraw_actions;this.postdraw_actions=function(ab,ac,ae,Z){var aa=this;aa.normal_postdraw_actions(ab,ac,ae,Z);aa.dataset_state_url=converted_datasets_state_url;aa.data_query_wait=H;var ad=new ServerStateDeferred({url:aa.dataset_state_url,url_params:{dataset_id:aa.dataset_id,hda_ldda:aa.hda_ldda},interval:aa.data_query_wait,success_fn:function(af){return af!=="pending"}});$.when(ad.go()).then(function(){aa.data_manager.set("data_url",default_data_url)});aa.postdraw_actions=aa.normal_postdraw_actions}}});var W=function(aa,Z){var ab={resize:false};h.call(this,aa,Z,ab);this.container_div.addClass("label-track")};o(W.prototype,h.prototype,{build_header_div:function(){},init:function(){this.enabled=true},_draw:function(){var ab=this.view,ac=ab.high-ab.low,af=Math.floor(Math.pow(10,Math.floor(Math.log(ac)/Math.log(10)))),Z=Math.floor(ab.low/af)*af,ad=this.view.container.width(),aa=$("<div style='position: relative; height: 1.3em;'></div>");while(Z<ab.high){var ae=(Z-ab.low)/ac*ad;aa.append($("<div class='label'>"+commatize(Z)+"</div>").css({position:"absolute",left:ae-1}));Z+=af}this.content_div.children(":first").remove();this.content_div.append(aa)}});var g=function(aa,Z,ad){J.call(this,aa,Z,ad);this.drawables=[];this.left_offset=0;if("drawables" in ad){var ac;for(var ab=0;ab<ad.drawables.length;ab++){ac=ad.drawables[ab];this.drawables[ab]=object_from_template(ac,aa,null);if(ac.left_offset>this.left_offset){this.left_offset=ac.left_offset}}this.enabled=true}if(this.drawables.length!==0){this.set_display_modes(this.drawables[0].display_modes,this.drawables[0].mode)}this.update_icons();this.obj_type="CompositeTrack"};o(g.prototype,J.prototype,{action_icons_def:[{name:"composite_icon",title:"Show individual tracks",css_class:"layers-stack",on_click_fn:function(Z){$(".bs-tooltip").remove();Z.show_group()}}].concat(J.prototype.action_icons_def),to_dict:w.prototype.to_dict,add_drawable:w.prototype.add_drawable,unpack_drawables:w.prototype.unpack_drawables,change_mode:function(Z){J.prototype.change_mode.call(this,Z);for(var aa=0;aa<this.drawables.length;aa++){this.drawables[aa].change_mode(Z)}},init:function(){var ab=[];for(var aa=0;aa<this.drawables.length;aa++){ab.push(this.drawables[aa].init())}var Z=this;$.when.apply($,ab).then(function(){Z.enabled=true;Z.request_draw()})},update_icons:function(){this.action_icons.filters_icon.hide();this.action_icons.tools_icon.hide();this.action_icons.param_space_viz_icon.hide()},can_draw:p.prototype.can_draw,draw_helper:function(aa,ap,aw,at,ah,aj,aq){var ao=this,aA=this._gen_tile_cache_key(ap,aj,aw),ae=this._get_tile_bounds(aw,at);if(!aq){aq={}}var az=(aa?undefined:ao.tile_cache.get_elt(aA));if(az){ao.show_tile(az,ah,aj);return az}var ai=[],ao,am=true,au,ak;for(var av=0;av<this.drawables.length;av++){ao=this.drawables[av];au=ao.data_manager.get_data(ae,ao.mode,at,ao.data_url_extra_params);if(is_deferred(au)){am=false}ai.push(au);ak=null;if(view.reference_track&&aj>view.canvas_manager.char_width_px){ak=view.reference_track.data_manager.get_data(ae,ao.mode,at,view.reference_track.data_url_extra_params);if(is_deferred(ak)){am=false}}ai.push(ak)}if(am){o(au,aq.more_tile_data);this.tile_predraw_init();var ad=ao.view.canvas_manager.new_canvas(),af=ao._get_tile_bounds(aw,at),ax=ae.get("start"),ab=ae.get("end"),ay=0,ap=Math.ceil((ab-ax)*aj)+this.left_offset,an=0,ac=[];var Z=0;for(var av=0;av<this.drawables.length;av++,ay+=2){ao=this.drawables[av];au=ai[ay];var al=ao.mode;if(al==="Auto"){al=ao.get_mode(au);ao.update_auto_mode(al)}ac.push(al);Z=ao.get_canvas_height(au,al,aj,ap);if(Z>an){an=Z}}ad.width=ap;ad.height=(aq.height?aq.height:an);ay=0;var ar=ad.getContext("2d");ar.translate(this.left_offset,0);ar.globalAlpha=0.5;ar.globalCompositeOperation="source-over";for(var av=0;av<this.drawables.length;av++,ay+=2){ao=this.drawables[av];au=ai[ay];ak=ai[ay+1];az=ao.draw_tile(au,ar,ac[av],at,ae,aj,ak)}this.tile_cache.set_elt(aA,az);this.show_tile(az,ah,aj);return az}var ag=$.Deferred(),ao=this;$.when.apply($,ai).then(function(){view.request_redraw(false,false,false,ao);ag.resolve()});return ag},show_group:function(){var ac=new M(this.view,this.container,{name:this.name}),Z;for(var ab=0;ab<this.drawables.length;ab++){Z=this.drawables[ab];ac.add_drawable(Z);Z.container=ac;ac.content_div.append(Z.container_div)}var aa=this.container.replace_drawable(this,ac,true);ac.request_draw()},tile_predraw_init:function(){var ac=Number.MAX_VALUE,Z=-ac,aa;for(var ab=0;ab<this.drawables.length;ab++){aa=this.drawables[ab];if(aa instanceof i){if(aa.prefs.min_value<ac){ac=aa.prefs.min_value}if(aa.prefs.max_value>Z){Z=aa.prefs.max_value}}}for(var ab=0;ab<this.drawables.length;ab++){aa=this.drawables[ab];aa.prefs.min_value=ac;aa.prefs.max_value=Z}},postdraw_actions:function(ab,ae,ag,aa){J.prototype.postdraw_actions.call(this,ab,ae,ag,aa);var ad=-1;for(var ac=0;ac<ab.length;ac++){var Z=ab[ac].html_elt.find("canvas").height();if(Z>ad){ad=Z}}for(var ac=0;ac<ab.length;ac++){var af=ab[ac];if(af.html_elt.find("canvas").height()!==ad){this.draw_helper(true,ae,af.index,af.resolution,af.html_elt.parent(),ag,{height:ad});af.html_elt.remove()}}}});var y=function(Z){J.call(this,Z,{content_div:Z.top_labeltrack},{resize:false});Z.reference_track=this;this.left_offset=200;this.visible_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:Z.dbkey};this.data_manager=new ReferenceTrackDataManager({data_url:reference_url});this.hide_contents()};o(y.prototype,p.prototype,J.prototype,{build_header_div:function(){},init:function(){this.data_manager.clear();this.enabled=true},can_draw:p.prototype.can_draw,draw_helper:function(ad,ab,Z,aa,ae,af,ac){if(af>this.view.canvas_manager.char_width_px){return J.prototype.draw_helper.call(this,ad,ab,Z,aa,ae,af,ac)}else{this.hide_contents();return null}},draw_tile:function(ah,ai,ad,ac,af,aj){var ab=this;if(aj>this.view.canvas_manager.char_width_px){if(ah.data===null){this.hide_contents();return}var aa=ai.canvas;ai.font=ai.canvas.manager.default_font;ai.textAlign="center";ah=ah.data;for(var ae=0,ag=ah.length;ae<ag;ae++){var Z=Math.floor(ae*aj);ai.fillText(ah[ae],Z,10)}this.show_contents();return new b(ab,af,ac,aa,ah)}this.hide_contents()}});var i=function(ab,aa,ac){var Z=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";J.call(this,ab,aa,ac);this.hda_ldda=ac.hda_ldda;this.dataset_id=ac.dataset_id;this.original_dataset_id=this.dataset_id;this.left_offset=0;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{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:32,hidden:true}],saved_values:ac.prefs,onchange:function(){Z.set_name(Z.prefs.name);Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.set_min_value(Z.prefs.min_value);Z.set_max_value(Z.prefs.max_value)}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value};o(i.prototype,p.prototype,J.prototype,{on_resize:function(){this.request_draw(true)},set_min_value:function(Z){this.prefs.min_value=Z;$("#linetrack_"+this.dataset_id+"_minval").text(this.prefs.min_value);this.tile_cache.clear();this.request_draw()},set_max_value:function(Z){this.prefs.max_value=Z;$("#linetrack_"+this.dataset_id+"_maxval").text(this.prefs.max_value);this.tile_cache.clear();this.request_draw()},predraw_init:function(){var Z=this;Z.vertical_range=undefined;return $.getJSON(Z.data_url,{stats:true,chrom:Z.view.chrom,low:0,high:Z.view.max_high,hda_ldda:Z.hda_ldda,dataset_id:Z.dataset_id},function(aa){Z.container_div.addClass("line-track");var ad=aa.data;if(isNaN(parseFloat(Z.prefs.min_value))||isNaN(parseFloat(Z.prefs.max_value))){var ab=ad.min,af=ad.max;ab=Math.floor(Math.min(0,Math.max(ab,ad.mean-2*ad.sd)));af=Math.ceil(Math.max(0,Math.min(af,ad.mean+2*ad.sd)));Z.prefs.min_value=ab;Z.prefs.max_value=af;$("#track_"+Z.dataset_id+"_minval").val(Z.prefs.min_value);$("#track_"+Z.dataset_id+"_maxval").val(Z.prefs.max_value)}Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.total_frequency=ad.total_frequency;Z.container_div.find(".yaxislabel").remove();var ae=$("<div/>").text(U(Z.prefs.min_value,3)).make_text_editable({num_cols:6,on_finish:function(ag){$(".bs-tooltip").remove();var ag=parseFloat(ag);if(!isNaN(ag)){Z.set_min_value(ag)}},help_text:"Set min value"}).addClass("yaxislabel bottom").attr("id","linetrack_"+Z.dataset_id+"_minval").prependTo(Z.container_div),ac=$("<div/>").text(U(Z.prefs.max_value,3)).make_text_editable({num_cols:6,on_finish:function(ag){$(".bs-tooltip").remove();var ag=parseFloat(ag);if(!isNaN(ag)){Z.set_max_value(ag)}},help_text:"Set max value"}).addClass("yaxislabel top").attr("id","linetrack_"+Z.dataset_id+"_maxval").prependTo(Z.container_div)})},draw_tile:function(ai,ag,ab,aa,ad,ah){var Z=ag.canvas,ac=ad.get("start"),af=ad.get("end"),ae=new I.LinePainter(ai.data,ac,af,this.prefs,ab);ae.draw(ag,Z.width,Z.height,ah);return new b(this,ad,aa,Z,ai.data)},can_subset:function(Z){return false}});var r=function(ab,aa,ac){var Z=this;this.display_modes=["Heatmap"];this.mode="Heatmap";J.call(this,ab,aa,ac);this.hda_ldda=ac.hda_ldda;this.dataset_id=ac.dataset_id;this.original_dataset_id=this.dataset_id;this.left_offset=0;this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"pos_color",label:"Positive Color",type:"color",default_value:"4169E1"},{key:"negative_color",label:"Negative Color",type:"color",default_value:"FF8C00"},{key:"min_value",label:"Min Value",type:"float",default_value:0},{key:"max_value",label:"Max Value",type:"float",default_value:1},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:500,hidden:true}],saved_values:ac.prefs,onchange:function(){Z.set_name(Z.prefs.name);Z.vertical_range=Z.prefs.max_value-Z.prefs.min_value;Z.set_min_value(Z.prefs.min_value);Z.set_max_value(Z.prefs.max_value)}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.vertical_range=this.config.values.max_value-this.config.values.min_value};o(r.prototype,p.prototype,J.prototype,{on_resize:function(){this.request_draw(true)},set_min_value:function(Z){this.prefs.min_value=Z;this.tile_cache.clear();this.request_draw()},set_max_value:function(Z){this.prefs.max_value=Z;this.tile_cache.clear();this.request_draw()},draw_tile:function(aj,ah,ae,ac,aa,ai){var ab=ah.canvas,Z=this._get_tile_bounds(aa,ac),ad=Z[0],ag=Z[1],af=new I.DiagonalHeatmapPainter(aj.data,ad,ag,this.prefs,ae);af.draw(ah,ab.width,ab.height,ai);return new b(this,aa,ac,ab,aj.data)}});var c=function(ac,ab,ae){var aa=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];J.call(this,ac,ab,ae);var ad=get_random_color(),Z=get_random_color([ad,"#ffffff"]);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"block_color",label:"Block color",type:"color",default_value:ad},{key:"reverse_strand_color",label:"Antisense strand color",type:"color",default_value:Z},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true,help:"Show the number of items in each bin when drawing summary histogram"},{key:"histogram_max",label:"Histogram maximum",type:"float",default_value:null,help:"clear value to set automatically"},{key:"connector_style",label:"Connector style",type:"select",default_value:"fishbones",options:[{label:"Line with arrows",value:"fishbone"},{label:"Arcs",value:"arcs"}]},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.visible_height_px,hidden:true}],saved_values:ae.prefs,onchange:function(){aa.set_name(aa.prefs.name);aa.tile_cache.clear();aa.set_painter_from_config();aa.request_draw()}});this.prefs=this.config.values;this.visible_height_px=this.config.values.height;this.container_div.addClass("feature-track");this.hda_ldda=ae.hda_ldda;this.dataset_id=ae.dataset_id;this.original_dataset_id=ae.dataset_id;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.slotters={};this.start_end_dct={};this.left_offset=200;this.set_painter_from_config()};o(c.prototype,p.prototype,J.prototype,{set_dataset:function(Z){this.dataset_id=Z.get("id");this.hda_ldda=Z.get("hda_ldda");this.data_manager.set("dataset",Z)},set_painter_from_config:function(){if(this.config.values.connector_style==="arcs"){this.painter=I.ArcLinkedFeaturePainter}else{this.painter=I.LinkedFeaturePainter}},before_draw:function(){this.max_height_px=0},postdraw_actions:function(ao,aj,ae,ad){J.prototype.postdraw_actions.call(this,ao,ad);var ai=this;if(ai.mode==="Histogram"){var al,aa=-1;for(al=0;al<ao.length;al++){var ak=ao[al].max_val;if(ak>aa){aa=ak}}for(al=0;al<ao.length;al++){var aq=ao[al];if(aq.max_val!==aa){aq.html_elt.remove();ai.draw_helper(true,aj,aq.index,aq.resolution,aq.html_elt.parent(),ae,{more_tile_data:{max:aa}})}}}if(ai.filters_manager){var af=ai.filters_manager.filters;for(var an=0;an<af.length;an++){af[an].update_ui_elt()}var ap=false,Z,ag;for(var al=0;al<ao.length;al++){if(ao[al].data.length){Z=ao[al].data[0];for(var an=0;an<af.length;an++){ag=af[an];if(ag.applies_to(Z)&&ag.min!==ag.max){ap=true;break}}}}if(ai.filters_available!==ap){ai.filters_available=ap;if(!ai.filters_available){ai.filters_manager.hide()}ai.update_icons()}}this.container_div.find(".yaxislabel").remove();var ac=ao[0];if(ac instanceof j){var ah=(this.prefs.histogram_max?this.prefs.histogram_max:ac.max_val),ab=$("<div/>").text(ah).make_text_editable({num_cols:12,on_finish:function(ar){$(".bs-tooltip").remove();var ar=parseFloat(ar);ai.prefs.histogram_max=(!isNaN(ar)?ar:null);ai.tile_cache.clear();ai.request_draw()},help_text:"Set max value; leave blank to use default"}).addClass("yaxislabel top").css("color",this.prefs.label_color);this.container_div.prepend(ab)}if(ac instanceof L){var am=true;for(var al=0;al<ao.length;al++){if(!ao[al].all_slotted){am=false;break}}if(!am){this.action_icons.show_more_rows_icon.show()}else{this.action_icons.show_more_rows_icon.hide()}}else{this.action_icons.show_more_rows_icon.hide()}},update_auto_mode:function(Z){var Z;if(this.mode==="Auto"){if(Z==="no_detail"){Z="feature spans"}else{if(Z==="summary_tree"){Z="coverage histogram"}}this.action_icons.mode_icon.attr("title","Set display mode (now: Auto/"+Z+")")}},incremental_slots:function(ad,Z,ac){var aa=this.view.canvas_manager.dummy_context,ab=this.slotters[ad];if(!ab||(ab.mode!==ac)){ab=new (s.FeatureSlotter)(ad,ac,x,function(ae){return aa.measureText(ae)});this.slotters[ad]=ab}return ab.slot_features(Z)},get_summary_tree_data:function(ad,ag,ab,ao){if(ao>ab-ag){ao=ab-ag}var ak=Math.floor((ab-ag)/ao),an=[],ac=0;var ae=0,af=0,aj,am=0,ah=[],al,ai;var aa=function(ar,aq,at,ap){ar[0]=aq+at*ap;ar[1]=aq+(at+1)*ap};while(am<ao&&ae!==ad.length){var Z=false;for(;am<ao&&!Z;am++){aa(ah,ag,am,ak);for(af=ae;af<ad.length;af++){aj=ad[af].slice(1,3);if(is_overlap(aj,ah)){Z=true;break}}if(Z){break}}data_start_index=af;an[an.length]=al=[ah[0],0];for(;af<ad.length;af++){aj=ad[af].slice(1,3);if(is_overlap(aj,ah)){al[1]++}else{break}}if(al[1]>ac){ac=al[1]}am++}return{max:ac,delta:ak,data:an}},get_mode:function(Z){if(Z.dataset_type==="summary_tree"){mode="summary_tree"}else{if(Z.extra_info==="no_detail"||this.is_overview){mode="no_detail"}else{if(this.view.high-this.view.low>F){mode="Squish"}else{mode="Pack"}}}return mode},get_canvas_height:function(Z,ad,ae,aa){if(ad==="summary_tree"||ad==="Histogram"){return this.summary_draw_height}else{var ac=this.incremental_slots(ae,Z.data,ad);var ab=new (this.painter)(null,null,null,this.prefs,ad);return Math.max(Y,ab.get_required_height(ac,aa))}},draw_tile:function(ak,ao,am,ap,ac,ag,ab){var an=this,aa=ao.canvas,aw=ac.get("start"),Z=ac.get("end"),aB=25,ad=this.left_offset;if(am==="summary_tree"||am==="Histogram"){if(ak.dataset_type!=="summary_tree"){var ah=this.get_summary_tree_data(ak.data,aw,Z,200);if(ak.max){ah.max=ak.max}ak=ah}var ay=new I.SummaryTreePainter(ak,aw,Z,this.prefs);ay.draw(ao,aa.width,aa.height,ag);return new j(an,ac,ap,aa,ak.data,ak.max)}var af=[],al=this.slotters[ag].slots;all_slotted=true;if(ak.data){var ai=this.filters_manager.filters;for(var aq=0,at=ak.data.length;aq<at;aq++){var ae=ak.data[aq];var ar=false;var aj;for(var av=0,aA=ai.length;av<aA;av++){aj=ai[av];aj.update_attrs(ae);if(!aj.keep(ae)){ar=true;break}}if(!ar){af.push(ae);if(!(ae[0] in al)){all_slotted=false}}}}var az=(this.filters_manager.alpha_filter?new z(this.filters_manager.alpha_filter):null);var ax=(this.filters_manager.height_filter?new z(this.filters_manager.height_filter):null);var ay=new (this.painter)(af,aw,Z,this.prefs,am,az,ax,ab);var au=null;ao.fillStyle=this.prefs.block_color;ao.font=ao.canvas.manager.default_font;ao.textAlign="right";if(ak.data){au=ay.draw(ao,aa.width,aa.height,ag,al);au.translation=-ad}return new L(an,ac,ap,aa,ak.data,ag,am,ak.message,all_slotted,au)},data_and_mode_compatible:function(Z,aa){if(aa==="Auto"){return true}else{if(Z.extra_info==="no_detail"||Z.dataset_type==="summary_tree"){return false}else{return true}}},can_subset:function(Z){if(Z.dataset_type==="summary_tree"||Z.message||Z.extra_info==="no_detail"){return false}return true}});var O=function(aa,Z,ab){c.call(this,aa,Z,ab);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.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:ab.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=I.ReadPainter};o(O.prototype,p.prototype,J.prototype,c.prototype);var R=function(ab,aa,ad){c.call(this,ab,aa,ad);var ac=get_random_color(),Z=get_random_color([ac,"#ffffff"]);this.config=new C({track:this,params:[{key:"name",label:"Name",type:"text",default_value:this.name},{key:"block_color",label:"Block and sense strand color",type:"color",default_value:ac},{key:"reverse_strand_color",label:"Antisense strand color",type:"color",default_value:Z},{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:"histogram_max",label:"Histogram maximum",type:"float",default_value:null,help:"Clear value to set automatically"},{key:"mode",type:"string",default_value:this.mode,hidden:true}],saved_values:ad.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=I.ReadPainter;this.update_icons()};o(R.prototype,p.prototype,J.prototype,c.prototype);S.View=X;S.DrawableGroup=M;S.LineTrack=i;S.FeatureTrack=c;S.DiagonalHeatmapTrack=r;S.ReadTrack=R;S.VcfTrack=O;S.CompositeTrack=g};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.mode=h;this.include_label=(h==="Pack");this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,h=this.start_end_dct,x=[],z=[],n=0,y=this.max_rows;for(var v=0,w=m.length;v<w;v++){var k=m[v],o=k[0];if(this.slots[o]!==undefined){n=Math.max(n,this.slots[o]);z.push(this.slots[o])}else{x.push(v)}}var q=function(E,F){for(var D=0;D<=y;D++){var B=false,G=h[D];if(G!==undefined){for(var A=0,C=G.length;A<C;A++){var i=G[A];if(F>i[0]&&E<i[1]){B=true;break}}}if(!B){return D}}return -1};for(var v=0,w=x.length;v<w;v++){var k=m[x[v]],o=k[0],t=k[1],f=k[2],r=k[3],g=Math.floor(t*p),l=Math.ceil(f*p),u=this.measureText(r).width,j;if(r!==undefined&&this.include_label){u+=(d+a);if(g-u>=0){g-=u;j="left"}else{l+=u;j="right"}}var s=q(g,l);if(s>=0){if(h[s]===undefined){h[s]=[]}h[s].push([g,l]);this.slots[o]=s;n=Math.max(n,s)}}return n+1}})};var painters_module=function(require,exports){var extend=require("class").extend;var dashedLine=function(ctx,x1,y1,x2,y2,dashLen){if(dashLen===undefined){dashLen=4}var dX=x2-x1;var dY=y2-y1;var dashes=Math.floor(Math.sqrt(dX*dX+dY*dY)/dashLen);var dashX=dX/dashes;var dashY=dY/dashes;var q;for(q=0;q<dashes;q++,x1+=dashX,y1+=dashY){if(q%2!==0){continue}ctx.fillRect(x1,y1,dashLen,1)}};var drawDownwardEquilateralTriangle=function(ctx,down_vertex_x,down_vertex_y,side_len){var x1=down_vertex_x-side_len/2,x2=down_vertex_x+side_len/2,y=down_vertex_y-Math.sqrt(side_len*3/2);ctx.beginPath();ctx.moveTo(x1,y);ctx.lineTo(x2,y);ctx.lineTo(down_vertex_x,down_vertex_y);ctx.lineTo(x1,y);ctx.strokeStyle=this.fillStyle;ctx.fill();ctx.stroke();ctx.closePath()};var Scaler=function(default_val){this.default_val=(default_val?default_val:1)};Scaler.prototype.gen_val=function(input){return this.default_val};var Painter=function(data,view_start,view_end,prefs,mode){this.data=data;this.view_start=view_start;this.view_end=view_end;this.prefs=extend({},this.default_prefs,prefs);this.mode=mode};Painter.prototype.default_prefs={};Painter.prototype.draw=function(ctx,width,height,w_scale){};var SummaryTreePainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode)};SummaryTreePainter.prototype.default_prefs={show_counts:false};SummaryTreePainter.prototype.draw=function(ctx,width,height,w_scale){var view_start=this.view_start,view_range=this.view_end-this.view_start,points=this.data.data,max=(this.prefs.histogram_max?this.prefs.histogram_max:this.data.max),base_y=height;delta_x_px=Math.ceil(this.data.delta*w_scale);ctx.save();for(var i=0,len=points.length;i<len;i++){var x=Math.floor((points[i][0]-view_start)*w_scale);var y=points[i][1];if(!y){continue}var y_px=y/max*height;if(y!==0&&y_px<1){y_px=1}ctx.fillStyle=this.prefs.block_color;ctx.fillRect(x,base_y-y_px,delta_x_px,y_px);var text_padding_req_x=4;if(this.prefs.show_counts&&(ctx.measureText(y).width+text_padding_req_x)<delta_x_px){ctx.fillStyle=this.prefs.label_color;ctx.textAlign="center";ctx.fillText(y,x+(delta_x_px/2),10)}}ctx.restore()};var LinePainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode);if(this.prefs.min_value===undefined){var min_value=Infinity;for(var i=0,len=this.data.length;i<len;i++){min_value=Math.min(min_value,this.data[i][1])}this.prefs.min_value=min_value}if(this.prefs.max_value===undefined){var max_value=-Infinity;for(var i=0,len=this.data.length;i<len;i++){max_value=Math.max(max_value,this.data[i][1])}this.prefs.max_value=max_value}};LinePainter.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};LinePainter.prototype.draw=function(ctx,width,height,w_scale){var in_path=false,min_value=this.prefs.min_value,max_value=this.prefs.max_value,vertical_range=max_value-min_value,height_px=height,view_start=this.view_start,view_range=this.view_end-this.view_start,mode=this.mode,data=this.data;ctx.save();var y_zero=Math.round(height+min_value/vertical_range*height);if(mode!=="Intensity"){ctx.fillStyle="#aaa";ctx.fillRect(0,y_zero,width,1)}ctx.beginPath();var x_scaled,y,delta_x_px;if(data.length>1){delta_x_px=Math.ceil((data[1][0]-data[0][0])*w_scale)}else{delta_x_px=10}var pref_color=parseInt(this.prefs.color.slice(1),16),pref_r=(pref_color&16711680)>>16,pref_g=(pref_color&65280)>>8,pref_b=pref_color&255;for(var i=0,len=data.length;i<len;i++){ctx.fillStyle=ctx.strokeStyle=this.prefs.color;x_scaled=Math.round((data[i][0]-view_start)*w_scale);y=data[i][1];var top_overflow=false,bot_overflow=false;if(y===null){if(in_path&&mode==="Filled"){ctx.lineTo(x_scaled,height_px)}in_path=false;continue}if(y<min_value){bot_overflow=true;y=min_value}else{if(y>max_value){top_overflow=true;y=max_value}}if(mode==="Histogram"){y=Math.round(y/vertical_range*height_px);ctx.fillRect(x_scaled,y_zero,delta_x_px,-y)}else{if(mode==="Intensity"){var saturation=(y-min_value)/vertical_range,new_r=Math.round(pref_r+(255-pref_r)*(1-saturation)),new_g=Math.round(pref_g+(255-pref_g)*(1-saturation)),new_b=Math.round(pref_b+(255-pref_b)*(1-saturation));ctx.fillStyle="rgb("+new_r+","+new_g+","+new_b+")";ctx.fillRect(x_scaled,0,delta_x_px,height_px)}else{y=Math.round(height_px-(y-min_value)/vertical_range*height_px);if(in_path){ctx.lineTo(x_scaled,y)}else{in_path=true;if(mode==="Filled"){ctx.moveTo(x_scaled,height_px);ctx.lineTo(x_scaled,y)}else{ctx.moveTo(x_scaled,y)}}}}ctx.fillStyle=this.prefs.overflow_color;if(top_overflow||bot_overflow){var overflow_x;if(mode==="Histogram"||mode==="Intensity"){overflow_x=delta_x_px}else{x_scaled-=2;overflow_x=4}if(top_overflow){ctx.fillRect(x_scaled,0,overflow_x,3)}if(bot_overflow){ctx.fillRect(x_scaled,height_px-3,overflow_x,3)}}ctx.fillStyle=this.prefs.color}if(mode==="Filled"){if(in_path){ctx.lineTo(x_scaled,y_zero);ctx.lineTo(0,y_zero)}ctx.fill()}else{ctx.stroke()}ctx.restore()};var FeaturePositionMapper=function(slot_height){this.feature_positions={};this.slot_height=slot_height;this.translation=0;this.y_translation=0};FeaturePositionMapper.prototype.map_feature_data=function(feature_data,slot,x_start,x_end){if(!this.feature_positions[slot]){this.feature_positions[slot]=[]}this.feature_positions[slot].push({data:feature_data,x_start:x_start,x_end:x_end})};FeaturePositionMapper.prototype.get_feature_data=function(x,y){var slot=Math.floor((y-this.y_translation)/this.slot_height),feature_dict;if(!this.feature_positions[slot]){return null}x+=this.translation;for(var i=0;i<this.feature_positions[slot].length;i++){feature_dict=this.feature_positions[slot][i];if(x>=feature_dict.x_start&&x<=feature_dict.x_end){return feature_dict.data}}};var FeaturePainter=function(data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler){Painter.call(this,data,view_start,view_end,prefs,mode);this.alpha_scaler=(alpha_scaler?alpha_scaler:new Scaler());this.height_scaler=(height_scaler?height_scaler:new Scaler())};FeaturePainter.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};extend(FeaturePainter.prototype,{get_required_height:function(rows_required,width){var required_height=y_scale=this.get_row_height(),mode=this.mode;if(mode==="no_detail"||mode==="Squish"||mode==="Pack"){required_height=rows_required*y_scale}return required_height+this.get_top_padding(width)+this.get_bottom_padding(width)},get_top_padding:function(width){return 0},get_bottom_padding:function(width){return Math.max(Math.round(this.get_row_height()/2),5)},draw:function(ctx,width,height,w_scale,slots){var data=this.data,view_start=this.view_start,view_end=this.view_end;ctx.save();ctx.fillStyle=this.prefs.block_color;ctx.textAlign="right";var view_range=this.view_end-this.view_start,y_scale=this.get_row_height(),feature_mapper=new FeaturePositionMapper(y_scale),x_draw_coords;for(var i=0,len=data.length;i<len;i++){var feature=data[i],feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2],slot=(slots&&slots[feature_uid]!==undefined?slots[feature_uid]:null);if((feature_start<view_end&&feature_end>view_start)&&(this.mode==="Dense"||slot!==null)){x_draw_coords=this.draw_element(ctx,this.mode,feature,slot,view_start,view_end,w_scale,y_scale,width);feature_mapper.map_feature_data(feature,slot,x_draw_coords[0],x_draw_coords[1])}}ctx.restore();feature_mapper.y_translation=this.get_top_padding(width);return feature_mapper},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){console.log("WARNING: Unimplemented function.");return[0,0]}});var DENSE_TRACK_HEIGHT=10,NO_DETAIL_TRACK_HEIGHT=3,SQUISH_TRACK_HEIGHT=5,PACK_TRACK_HEIGHT=10,NO_DETAIL_FEATURE_HEIGHT=1,DENSE_FEATURE_HEIGHT=9,SQUISH_FEATURE_HEIGHT=3,PACK_FEATURE_HEIGHT=9,LABEL_SPACING=2,CONNECTOR_COLOR="#ccc";var LinkedFeaturePainter=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);this.draw_background_connector=true;this.draw_individual_connectors=false};extend(LinkedFeaturePainter.prototype,FeaturePainter.prototype,{get_row_height:function(){var mode=this.mode,height;if(mode==="Dense"){height=DENSE_TRACK_HEIGHT}else{if(mode==="no_detail"){height=NO_DETAIL_TRACK_HEIGHT}else{if(mode==="Squish"){height=SQUISH_TRACK_HEIGHT}else{height=PACK_TRACK_HEIGHT}}}return height},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){var feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2]-1,feature_name=feature[3],feature_strand=feature[4],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))),draw_start=f_start,draw_end=f_end,y_center=(mode==="Dense"?0:(0+slot))*y_scale+this.get_top_padding(width),thickness,y_start,thick_start=null,thick_end=null,block_color=block_color=(!feature_strand||feature_strand==="+"||feature_strand==="."?this.prefs.block_color:this.prefs.reverse_strand_color);label_color=this.prefs.label_color;ctx.globalAlpha=this.alpha_scaler.gen_val(feature);if(mode==="Dense"){slot=1}if(mode==="no_detail"){ctx.fillStyle=block_color;ctx.fillRect(f_start,y_center+5,f_end-f_start,NO_DETAIL_FEATURE_HEIGHT)}else{var feature_ts=feature[5],feature_te=feature[6],feature_blocks=feature[7],full_height=true;if(feature_ts&&feature_te){thick_start=Math.floor(Math.max(0,(feature_ts-tile_low)*w_scale));thick_end=Math.ceil(Math.min(width,Math.max(0,(feature_te-tile_low)*w_scale)))}var thin_height,thick_height;if(mode==="Squish"){thin_height=1;thick_height=SQUISH_FEATURE_HEIGHT;full_height=false}else{if(mode==="Dense"){thin_height=5;thick_height=DENSE_FEATURE_HEIGHT}else{thin_height=5;thick_height=PACK_FEATURE_HEIGHT}}if(!feature_blocks){ctx.fillStyle=block_color;ctx.fillRect(f_start,y_center+1,f_end-f_start,thick_height);if(feature_strand&&full_height){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand_inv")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand_inv")}}ctx.fillRect(f_start,y_center+1,f_end-f_start,thick_height)}}else{var cur_y_center,cur_height;if(mode==="Squish"||mode==="Dense"){cur_y_center=y_center+Math.floor(SQUISH_FEATURE_HEIGHT/2)+1;cur_height=1}else{if(feature_strand){cur_y_center=y_center;cur_height=thick_height}else{cur_y_center+=(SQUISH_FEATURE_HEIGHT/2)+1;cur_height=1}}if(this.draw_background_connector){if(mode==="Squish"||mode==="Dense"){ctx.fillStyle=CONNECTOR_COLOR}else{if(feature_strand){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand")}}}else{ctx.fillStyle=CONNECTOR_COLOR}}ctx.fillRect(f_start,cur_y_center,f_end-f_start,cur_height)}var start_and_height;for(var k=0,k_len=feature_blocks.length;k<k_len;k++){var block=feature_blocks[k],block_start=Math.floor(Math.max(0,(block[0]-tile_low)*w_scale)),block_end=Math.ceil(Math.min(width,Math.max((block[1]-1-tile_low)*w_scale))),last_block_start,last_block_end;if(block_start>block_end){continue}ctx.fillStyle=block_color;ctx.fillRect(block_start,y_center+(thick_height-thin_height)/2+1,block_end-block_start,thin_height);if(thick_start!==undefined&&feature_te>feature_ts&&!(block_start>thick_end||block_end<thick_start)){var block_thick_start=Math.max(block_start,thick_start),block_thick_end=Math.min(block_end,thick_end);ctx.fillRect(block_thick_start,y_center+1,block_thick_end-block_thick_start,thick_height);if(feature_blocks.length===1&&mode==="Pack"){if(feature_strand==="+"){ctx.fillStyle=ctx.canvas.manager.get_pattern("right_strand_inv")}else{if(feature_strand==="-"){ctx.fillStyle=ctx.canvas.manager.get_pattern("left_strand_inv")}}if(block_thick_start+14<block_thick_end){block_thick_start+=2;block_thick_end-=2}ctx.fillRect(block_thick_start,y_center+1,block_thick_end-block_thick_start,thick_height)}}if(this.draw_individual_connectors&&last_block_start){this.draw_connector(ctx,last_block_start,last_block_end,block_start,block_end,y_center)}last_block_start=block_start;last_block_end=block_end}if(mode==="Pack"){ctx.globalAlpha=1;ctx.fillStyle="white";var hscale_factor=this.height_scaler.gen_val(feature),new_height=Math.ceil(thick_height*hscale_factor),ws_height=Math.round((thick_height-new_height)/2);if(hscale_factor!==1){ctx.fillRect(f_start,cur_y_center+1,f_end-f_start,ws_height);ctx.fillRect(f_start,cur_y_center+thick_height-ws_height+1,f_end-f_start,ws_height)}}}ctx.globalAlpha=1;if(mode==="Pack"&&feature_start>tile_low){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+LABEL_SPACING,y_center+8);draw_end+=ctx.measureText(feature_name).width+LABEL_SPACING}else{ctx.textAlign="right";ctx.fillText(feature_name,f_start-LABEL_SPACING,y_center+8);draw_start-=ctx.measureText(feature_name).width+LABEL_SPACING}}}ctx.globalAlpha=1;return[draw_start,draw_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)};extend(ReadPainter.prototype,FeaturePainter.prototype,{get_row_height:function(){var height,mode=this.mode;if(mode==="Dense"){height=DENSE_TRACK_HEIGHT}else{if(mode==="Squish"){height=SQUISH_TRACK_HEIGHT}else{height=PACK_TRACK_HEIGHT;if(this.prefs.show_insertions){height*=2}}}return height},draw_read:function(ctx,mode,w_scale,y_center,tile_low,tile_high,feature_start,cigar,strand,orig_seq){ctx.textAlign="center";var track=this,tile_region=[tile_low,tile_high],base_offset=0,seq_offset=0,gap=0,char_width_px=ctx.canvas.manager.char_width_px,block_color=(strand==="+"?this.prefs.block_color:this.prefs.reverse_strand_color);var draw_last=[];if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){gap=Math.round(w_scale/2)}if(!cigar){cigar=[[0,orig_seq.length]]}for(var cig_id=0,len=cigar.length;cig_id<len;cig_id++){var cig=cigar[cig_id],cig_op="MIDNSHP=X"[cig[0]],cig_len=cig[1];if(cig_op==="H"||cig_op==="S"){base_offset-=cig_len}var seq_start=feature_start+base_offset,s_start=Math.floor(Math.max(0,(seq_start-tile_low)*w_scale)),s_end=Math.floor(Math.max(0,(seq_start+cig_len-tile_low)*w_scale));if(s_start===s_end){s_end+=1}switch(cig_op){case"H":break;case"S":case"M":case"=":if(is_overlap([seq_start,seq_start+cig_len],tile_region)){var seq=orig_seq.slice(seq_offset,seq_offset+cig_len);if(gap>0){ctx.fillStyle=block_color;ctx.fillRect(s_start-gap,y_center+1,s_end-s_start,9);ctx.fillStyle=CONNECTOR_COLOR;for(var c=0,str_len=seq.length;c<str_len;c++){if(this.prefs.show_differences){if(this.ref_seq){var ref_char=this.ref_seq[seq_start-tile_low+c];if(!ref_char||ref_char.toLowerCase()===seq[c].toLowerCase()){continue}}else{continue}}if(seq_start+c>=tile_low&&seq_start+c<=tile_high){var c_start=Math.floor(Math.max(0,(seq_start+c-tile_low)*w_scale));ctx.fillText(seq[c],c_start,y_center+9)}}}else{ctx.fillStyle=block_color;ctx.fillRect(s_start,y_center+4,s_end-s_start,SQUISH_FEATURE_HEIGHT)}}seq_offset+=cig_len;base_offset+=cig_len;break;case"N":ctx.fillStyle=CONNECTOR_COLOR;ctx.fillRect(s_start-gap,y_center+5,s_end-s_start,1);base_offset+=cig_len;break;case"D":ctx.fillStyle="red";ctx.fillRect(s_start-gap,y_center+4,s_end-s_start,3);base_offset+=cig_len;break;case"P":break;case"I":var insert_x_coord=s_start-gap;if(is_overlap([seq_start,seq_start+cig_len],tile_region)){var seq=orig_seq.slice(seq_offset,seq_offset+cig_len);if(this.prefs.show_insertions){var x_center=s_start-(s_end-s_start)/2;if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){ctx.fillStyle="yellow";ctx.fillRect(x_center-gap,y_center-9,s_end-s_start,9);draw_last[draw_last.length]={type:"triangle",data:[insert_x_coord,y_center+4,5]};ctx.fillStyle=CONNECTOR_COLOR;switch(compute_overlap([seq_start,seq_start+cig_len],tile_region)){case (OVERLAP_START):seq=seq.slice(tile_low-seq_start);break;case (OVERLAP_END):seq=seq.slice(0,seq_start-tile_high);break;case (CONTAINED_BY):break;case (CONTAINS):seq=seq.slice(tile_low-seq_start,seq_start-tile_high);break}for(var c=0,str_len=seq.length;c<str_len;c++){var c_start=Math.floor(Math.max(0,(seq_start+c-tile_low)*w_scale));ctx.fillText(seq[c],c_start-(s_end-s_start)/2,y_center)}}else{ctx.fillStyle="yellow";ctx.fillRect(x_center,y_center+(this.mode!=="Dense"?2:5),s_end-s_start,(mode!=="Dense"?SQUISH_FEATURE_HEIGHT:DENSE_FEATURE_HEIGHT))}}else{if((mode==="Pack"||this.mode==="Auto")&&orig_seq!==undefined&&w_scale>char_width_px){draw_last.push({type:"text",data:[seq.length,insert_x_coord,y_center+9]})}else{}}}seq_offset+=cig_len;break;case"X":seq_offset+=cig_len;break}}ctx.fillStyle="yellow";var item,type,data;for(var i=0;i<draw_last.length;i++){item=draw_last[i];type=item.type;data=item.data;if(type==="text"){ctx.save();ctx.font="bold "+ctx.font;ctx.fillText(data[0],data[1],data[2]);ctx.restore()}else{if(type==="triangle"){drawDownwardEquilateralTriangle(ctx,data[0],data[1],data[2])}}}},draw_element:function(ctx,mode,feature,slot,tile_low,tile_high,w_scale,y_scale,width){var feature_uid=feature[0],feature_start=feature[1],feature_end=feature[2],feature_name=feature[3],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,label_color=this.prefs.label_color,gap=0;if((mode==="Pack"||this.mode==="Auto")&&w_scale>ctx.canvas.manager.char_width_px){var gap=Math.round(w_scale/2)}if(feature[5] instanceof Array){var b1_start=Math.floor(Math.max(0,(feature[4][0]-tile_low)*w_scale)),b1_end=Math.ceil(Math.min(width,Math.max(0,(feature[4][1]-tile_low)*w_scale))),b2_start=Math.floor(Math.max(0,(feature[5][0]-tile_low)*w_scale)),b2_end=Math.ceil(Math.min(width,Math.max(0,(feature[5][1]-tile_low)*w_scale))),connector=true;if(feature[4][1]>=tile_low&&feature[4][0]<=tile_high&&feature[4][2]){this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature[4][0],feature[4][2],feature[4][3],feature[4][4])}else{connector=false}if(feature[5][1]>=tile_low&&feature[5][0]<=tile_high&&feature[5][2]){this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature[5][0],feature[5][2],feature[5][3],feature[5][4])}else{connector=false}if(connector&&b2_start>b1_end){ctx.fillStyle=CONNECTOR_COLOR;dashedLine(ctx,b1_end-gap,y_center+5,b2_start-gap,y_center+5)}}else{this.draw_read(ctx,mode,w_scale,y_center,tile_low,tile_high,feature_start,feature[4],feature[5],feature[6])}if(mode==="Pack"&&feature_start>tile_low&&feature_name!=="."){ctx.fillStyle=this.prefs.label_color;var tile_index=1;if(tile_index===0&&f_start-ctx.measureText(feature_name).width<0){ctx.textAlign="left";ctx.fillText(feature_name,f_end+LABEL_SPACING-gap,y_center+8)}else{ctx.textAlign="right";ctx.fillText(feature_name,f_start-LABEL_SPACING-gap,y_center+8)}}return[0,0]}});var ArcLinkedFeaturePainter=function(data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler){LinkedFeaturePainter.call(this,data,view_start,view_end,prefs,mode,alpha_scaler,height_scaler);this.longest_feature_length=this.calculate_longest_feature_length();this.draw_background_connector=false;this.draw_individual_connectors=true};extend(ArcLinkedFeaturePainter.prototype,FeaturePainter.prototype,LinkedFeaturePainter.prototype,{calculate_longest_feature_length:function(){var longest_feature_length=0;for(var i=0,len=this.data.length;i<len;i++){var feature=this.data[i],feature_start=feature[1],feature_end=feature[2];longest_feature_length=Math.max(longest_feature_length,feature_end-feature_start)}return longest_feature_length},get_top_padding:function(width){var view_range=this.view_end-this.view_start,w_scale=width/view_range;return Math.min(128,Math.ceil((this.longest_feature_length/2)*w_scale))},draw_connector:function(ctx,block1_start,block1_end,block2_start,block2_end,y_center){var x_center=(block1_end+block2_start)/2,radius=block2_start-x_center;var angle1=Math.PI,angle2=0;if(radius>0){ctx.beginPath();ctx.arc(x_center,y_center,block2_start-x_center,Math.PI,0);ctx.stroke()}}});var Color=function(rgb,a){if(Array.isArray(rgb)){this.rgb=rgb}else{if(rgb.length==6){this.rgb=rgb.match(/.{2}/g).map(function(c){return parseInt(c,16)})}else{this.rgb=rgb.split("").map(function(c){return parseInt(c+c,16)})}}this.alpha=typeof(a)==="number"?a:1};Color.prototype={eval:function(){return this},toCSS:function(){if(this.alpha<1){return"rgba("+this.rgb.map(function(c){return Math.round(c)}).concat(this.alpha).join(", ")+")"}else{return"#"+this.rgb.map(function(i){i=Math.round(i);i=(i>255?255:(i<0?0:i)).toString(16);return i.length===1?"0"+i:i}).join("")}},toHSL:function(){var r=this.rgb[0]/255,g=this.rgb[1]/255,b=this.rgb[2]/255,a=this.alpha;var max=Math.max(r,g,b),min=Math.min(r,g,b);var h,s,l=(max+min)/2,d=max-min;if(max===min){h=s=0}else{s=l>0.5?d/(2-max-min):d/(max+min);switch(max){case r:h=(g-b)/d+(g<b?6:0);break;case g:h=(b-r)/d+2;break;case b:h=(r-g)/d+4;break}h/=6}return{h:h*360,s:s,l:l,a:a}},toARGB:function(){var argb=[Math.round(this.alpha*255)].concat(this.rgb);return"#"+argb.map(function(i){i=Math.round(i);i=(i>255?255:(i<0?0:i)).toString(16);return i.length===1?"0"+i:i}).join("")},mix:function(color2,weight){color1=this;var p=weight;var w=p*2-1;var a=color1.toHSL().a-color2.toHSL().a;var w1=(((w*a==-1)?w:(w+a)/(1+w*a))+1)/2;var w2=1-w1;var rgb=[color1.rgb[0]*w1+color2.rgb[0]*w2,color1.rgb[1]*w1+color2.rgb[1]*w2,color1.rgb[2]*w1+color2.rgb[2]*w2];var alpha=color1.alpha*p+color2.alpha*(1-p);return new Color(rgb,alpha)}};var LinearRamp=function(start_color,end_color,start_value,end_value){this.start_color=new Color(start_color);this.end_color=new Color(end_color);this.start_value=start_value;this.end_value=end_value;this.value_range=end_value-start_value};LinearRamp.prototype.map_value=function(value){value=Math.max(value,this.start_value);value=Math.min(value,this.end_value);value=(value-this.start_value)/this.value_range;return this.start_color.mix(this.end_color,1-value).toCSS()};var SplitRamp=function(start_color,middle_color,end_color,start_value,end_value){this.positive_ramp=new LinearRamp(middle_color,end_color,0,end_value);this.negative_ramp=new LinearRamp(middle_color,start_color,0,-start_value);this.start_value=start_value;this.end_value=end_value};SplitRamp.prototype.map_value=function(value){value=Math.max(value,this.start_value);value=Math.min(value,this.end_value);if(value>=0){return this.positive_ramp.map_value(value)}else{return this.negative_ramp.map_value(-value)}};var DiagonalHeatmapPainter=function(data,view_start,view_end,prefs,mode){Painter.call(this,data,view_start,view_end,prefs,mode);if(this.prefs.min_value===undefined){var min_value=Infinity;for(var i=0,len=this.data.length;i<len;i++){min_value=Math.min(min_value,this.data[i][5])}this.prefs.min_value=min_value}if(this.prefs.max_value===undefined){var max_value=-Infinity;for(var i=0,len=this.data.length;i<len;i++){max_value=Math.max(max_value,this.data[i][5])}this.prefs.max_value=max_value}};DiagonalHeatmapPainter.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Heatmap",pos_color:"4169E1",neg_color:"FF8C00"};DiagonalHeatmapPainter.prototype.draw=function(ctx,width,height,w_scale){var min_value=this.prefs.min_value,max_value=this.prefs.max_value,value_range=max_value-min_value,height_px=height,view_start=this.view_start,view_range=this.view_end-this.view_start,mode=this.mode,data=this.data,invsqrt2=1/Math.sqrt(2);var ramp=(new SplitRamp(this.prefs.neg_color,"FFFFFF",this.prefs.pos_color,min_value,max_value));var d,s1,e1,s2,e2,value;var scale=function(p){return(p-view_start)*w_scale};ctx.save();ctx.rotate(-45*Math.PI/180);ctx.scale(invsqrt2,invsqrt2);for(var i=0,len=data.length;i<len;i++){d=data[i];s1=scale(d[1]);e1=scale(d[2]);s2=scale(d[4]);e2=scale(d[5]);value=d[6];ctx.fillStyle=(ramp.map_value(value));ctx.fillRect(s1,s2,(e1-s1),(e2-s2))}ctx.restore()};exports.Scaler=Scaler;exports.SummaryTreePainter=SummaryTreePainter;exports.LinePainter=LinePainter;exports.LinkedFeaturePainter=LinkedFeaturePainter;exports.ReadPainter=ReadPainter;exports.ArcLinkedFeaturePainter=ArcLinkedFeaturePainter;exports.DiagonalHeatmapPainter=DiagonalHeatmapPainter};(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 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 static/scripts/packed/viz/visualization.js --- a/static/scripts/packed/viz/visualization.js +++ b/static/scripts/packed/viz/visualization.js @@ -1,1 +1,1 @@ -var ServerStateDeferred=Backbone.Model.extend({defaults:{ajax_settings:{},interval:1000,success_fn:function(a){return true}},go:function(){var d=$.Deferred(),c=this,f=c.get("ajax_settings"),e=c.get("success_fn"),b=c.get("interval"),a=function(){$.ajax(f).success(function(g){if(e(g)){d.resolve(g)}else{setTimeout(a,b)}})};a();return d}});var CanvasManager=function(a){this.default_font=a!==undefined?a:"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")};_.extend(CanvasManager.prototype,{load_pattern:function(a,e){var b=this.patterns,c=this.dummy_context,d=new Image();d.src=galaxy_paths.attributes.image_path+e;d.onload=function(){b[a]=c.createPattern(d,"repeat")}},get_pattern:function(a){return this.patterns[a]},new_canvas:function(){var a=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(a)}a.manager=this;return a}});var Cache=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(a){this.clear()},get_elt:function(b){var c=this.attributes.obj_cache,d=this.attributes.key_ary,a=d.indexOf(b);if(a!==-1){if(c[b].stale){d.splice(a,1);delete c[b]}else{this.move_key_to_end(b,a)}}return c[b]},set_elt:function(b,d){var e=this.attributes.obj_cache,f=this.attributes.key_ary,c=this.attributes.num_elements;if(!e[b]){if(f.length>=c){var a=f.shift();delete e[a]}f.push(b)}e[b]=d;return d},move_key_to_end:function(b,a){this.attributes.key_ary.splice(a,1);this.attributes.key_ary.push(b)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length}});var GenomeDataManager=Cache.extend({defaults:_.extend({},Cache.prototype.defaults,{dataset:null,filters_manager:null,data_url:null,dataset_state_url:null,genome_wide_summary_data:null,data_mode_compatible:function(a,b){return true},can_subset:function(a){return false}}),data_is_ready:function(){var c=this.get("dataset"),b=$.Deferred(),a=new ServerStateDeferred({ajax_settings:{url:this.get("dataset_state_url"),data:{dataset_id:c.id,hda_ldda:c.get("hda_ldda")},dataType:"json"},interval:5000,success_fn:function(d){return d!=="pending"}});$.when(a.go()).then(function(d){b.resolve(d==="ok"||d==="data")});return b},load_data:function(h,g,b,f){var d={chrom:h.get("chrom"),low:h.get("start"),high:h.get("end"),mode:g,resolution:b};dataset=this.get("dataset");if(dataset){d.dataset_id=dataset.id;d.hda_ldda=dataset.get("hda_ldda")}$.extend(d,f);var j=this.get("filters_manager");if(j){var k=[];var a=j.filters;for(var e=0;e<a.length;e++){k.push(a[e].name)}d.filter_cols=JSON.stringify(k)}var c=this;return $.getJSON(this.get("data_url"),d,function(i){c.set_data(h,i)})},get_data:function(g,f,c,e){var h=this.get_elt(g);if(h&&(is_deferred(h)||this.get("data_mode_compatible")(h,f))){return h}var j=this.get("key_ary"),b=this.get("obj_cache"),k,a;for(var d=0;d<j.length;d++){k=j[d];a=new GenomeRegion({from_str:k});if(a.contains(g)){h=b[k];if(is_deferred(h)||(this.get("data_mode_compatible")(h,f)&&this.get("can_subset")(h))){this.move_key_to_end(k,d);return h}}}h=this.load_data(g,f,c,e);this.set_data(g,h);return h},set_data:function(b,a){this.set_elt(b,a)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(i,h,d,g,e){var k=this.get_elt(i);if(!(k&&this.get("data_mode_compatible")(k,h))){console.log("ERROR: no current data for: ",dataset,i.toString(),h,d,g);return}k.stale=true;var c=i.get("start");if(e===this.DEEP_DATA_REQ){$.extend(g,{start_val:k.data.length+1})}else{if(e===this.BROAD_DATA_REQ){c=(k.max_high?k.max_high:k.data[k.data.length-1][2])+1}}var j=i.copy().set("start",c);var b=this,f=this.load_data(j,h,d,g),a=$.Deferred();this.set_data(i,a);$.when(f).then(function(l){if(l.data){l.data=k.data.concat(l.data);if(l.max_low){l.max_low=k.max_low}if(l.message){l.message=l.message.replace(/[0-9]+/,l.data.length)}}b.set_data(i,l);a.resolve(l)});return a},get_elt:function(a){return Cache.prototype.get_elt.call(this,a.toString())},set_elt:function(b,a){return Cache.prototype.set_elt.call(this,b.toString(),a)}});var ReferenceTrackDataManager=GenomeDataManager.extend({load_data:function(a,d,e,b,c){if(b>1){return{data:null}}return GenomeDataManager.prototype.load_data.call(this,a,d,e,b,c)}});var Genome=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info}});var GenomeRegion=Backbone.RelationalModel.extend({defaults:{chrom:null,start:0,end:0,DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006},initialize:function(b){if(b.from_str){var d=b.from_str.split(":"),c=d[0],a=d[1].split("-");this.set({chrom:c,start:parseInt(a[0],10),end:parseInt(a[1],10)})}},copy:function(){return new GenomeRegion({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(h){var b=this.get("chrom"),g=h.get("chrom"),f=this.get("start"),d=h.get("start"),e=this.get("end"),c=h.get("end"),a;if(b&&g&&b!==g){return this.get("DIF_CHROMS")}if(f<d){if(e<d){a=this.get("BEFORE")}else{if(e<=c){a=this.get("OVERLAP_START")}else{a=this.get("CONTAINS")}}}else{if(f>c){a=this.get("AFTER")}else{if(e<=c){a=this.get("CONTAINED_BY")}else{a=this.get("OVERLAP_END")}}}return a},contains:function(a){return this.compute_overlap(a)===this.get("CONTAINS")},overlaps:function(a){return _.intersection([this.compute_overlap(a)],[this.get("DIF_CHROMS"),this.get("BEFORE"),this.get("AFTER")]).length===0}});var GenomeRegionCollection=Backbone.Collection.extend({model:GenomeRegion});var BrowserBookmark=Backbone.RelationalModel.extend({defaults:{region:null,note:""},relations:[{type:Backbone.HasOne,key:"region",relatedModel:"GenomeRegion"}]});var BrowserBookmarkCollection=Backbone.Collection.extend({model:BrowserBookmark});var GenomeWideSummaryData=Backbone.RelationalModel.extend({defaults:{data:null,max:0},initialize:function(b){var a=_.max(this.get("data"),function(c){if(!c||typeof c==="string"){return 0}return c[1]});this.attributes.max=(a&&typeof a!=="string"?a[1]:0)}});var BackboneTrack=Dataset.extend({initialize:function(a){this.set("id",a.dataset_id)},relations:[{type:Backbone.HasOne,key:"genome_wide_data",relatedModel:"GenomeWideSummaryData"}]});var Visualization=Backbone.RelationalModel.extend({defaults:{id:"",title:"",type:"",dbkey:"",tracks:null},relations:[{type:Backbone.HasMany,key:"tracks",relatedModel:"BackboneTrack"}],url:function(){return galaxy_paths.get("visualization_url")},save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var GenomeVisualization=Visualization.extend({defaults:_.extend({},Visualization.prototype.defaults,{bookmarks:null,viewport:null})});var TrackConfig=Backbone.Model.extend({});var CircsterHistogramDatasetLayout=Backbone.Model.extend({chroms_layout:function(){var b=this.attributes.genome.get_chroms_info(),d=d3.layout.pie().value(function(f){return f.len}).sort(null),e=d(b),a=this.attributes.total_gap/b.length,c=_.map(e,function(h,g){var f=h.endAngle-a;h.endAngle=(f>h.startAngle?f:h.startAngle);return h});return c},chrom_data_layout:function(j,b,g,f,h){if(!b||typeof b==="string"){return null}var d=b[0],i=b[3],c=d3.scale.linear().domain([0,h]).range([g,f]),e=d3.layout.pie().value(function(k){return i}).startAngle(j.startAngle).endAngle(j.endAngle),a=e(d);_.each(d,function(k,l){a[l].outerRadius=c(k[1])});return a}});var CircsterView=Backbone.View.extend({className:"circster",initialize:function(a){this.width=a.width;this.height=a.height;this.total_gap=a.total_gap;this.genome=a.genome;this.radius_start=a.radius_start;this.dataset_arc_height=a.dataset_arc_height;this.track_gap=5},render:function(){var b=this,c=this.dataset_arc_height;var a=d3.select(b.$el[0]).append("svg").attr("width",b.width).attr("height",b.height).append("g").attr("transform","translate("+b.width/2+","+b.height/2+")");this.model.get("tracks").each(function(e,j){var g=e.get("genome_wide_data");var i=b.radius_start+j*(c+b.track_gap),o=new CircsterHistogramDatasetLayout({genome:b.genome,total_gap:b.total_gap}),n=o.chroms_layout(),l=_.zip(n,g.get("data")),m=g.get("max"),f=_.map(l,function(s){var t=s[0],r=s[1];return o.chrom_data_layout(t,r,i,i+c,m)});var p=a.append("g").attr("id","inner-arc"),k=d3.svg.arc().innerRadius(i).outerRadius(i+c),d=p.selectAll("#inner-arc>path").data(n).enter().append("path").attr("d",k).style("stroke","#ccc").style("fill","#ccc").append("title").text(function(r){return r.data.chrom});var q=e.get("prefs"),h=q.block_color;_.each(f,function(r){if(!r){return}var u=a.append("g"),t=d3.svg.arc().innerRadius(i),s=u.selectAll("path").data(r).enter().append("path").attr("d",t).style("stroke",h).style("fill",h)})})}});var TrackBrowserRouter=Backbone.Router.extend({initialize:function(b){this.view=b.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var a=this;a.view.on("navigate",function(c){a.navigate(c)})},change_location:function(a){this.view.go_to(a)}});var add_datasets=function(a,c,b){$.ajax({url:a,data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(d){show_modal("Select datasets for new tracks",d,{Cancel:function(){hide_modal()},Add:function(){var e=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var f,g=$(this).val();if($(this).attr("name")==="id"){f={hda_id:g}}else{f={ldda_id:g}}e[e.length]=$.ajax({url:c,data:f,dataType:"json"})});$.when.apply($,e).then(function(){var f=(arguments[0] instanceof Array?$.map(arguments,function(g){return g[0]}):[arguments[0]]);b(f)});hide_modal()}})}})}; \ No newline at end of file +var ServerStateDeferred=Backbone.Model.extend({defaults:{ajax_settings:{},interval:1000,success_fn:function(a){return true}},go:function(){var d=$.Deferred(),c=this,f=c.get("ajax_settings"),e=c.get("success_fn"),b=c.get("interval"),a=function(){$.ajax(f).success(function(g){if(e(g)){d.resolve(g)}else{setTimeout(a,b)}})};a();return d}});var CanvasManager=function(a){this.default_font=a!==undefined?a:"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")};_.extend(CanvasManager.prototype,{load_pattern:function(a,e){var b=this.patterns,c=this.dummy_context,d=new Image();d.src=galaxy_paths.attributes.image_path+e;d.onload=function(){b[a]=c.createPattern(d,"repeat")}},get_pattern:function(a){return this.patterns[a]},new_canvas:function(){var a=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(a)}a.manager=this;return a}});var Cache=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(a){this.clear()},get_elt:function(b){var c=this.attributes.obj_cache,d=this.attributes.key_ary,a=d.indexOf(b);if(a!==-1){if(c[b].stale){d.splice(a,1);delete c[b]}else{this.move_key_to_end(b,a)}}return c[b]},set_elt:function(b,d){var e=this.attributes.obj_cache,f=this.attributes.key_ary,c=this.attributes.num_elements;if(!e[b]){if(f.length>=c){var a=f.shift();delete e[a]}f.push(b)}e[b]=d;return d},move_key_to_end:function(b,a){this.attributes.key_ary.splice(a,1);this.attributes.key_ary.push(b)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length}});var GenomeDataManager=Cache.extend({defaults:_.extend({},Cache.prototype.defaults,{dataset:null,filters_manager:null,data_url:null,dataset_state_url:null,genome_wide_summary_data:null,data_mode_compatible:function(a,b){return true},can_subset:function(a){return false}}),data_is_ready:function(){var c=this.get("dataset"),b=$.Deferred(),a=new ServerStateDeferred({ajax_settings:{url:this.get("dataset_state_url"),data:{dataset_id:c.id,hda_ldda:c.get("hda_ldda")},dataType:"json"},interval:5000,success_fn:function(d){return d!=="pending"}});$.when(a.go()).then(function(d){b.resolve(d==="ok"||d==="data")});return b},load_data:function(h,g,b,f){var d={chrom:h.get("chrom"),low:h.get("start"),high:h.get("end"),mode:g,resolution:b};dataset=this.get("dataset");if(dataset){d.dataset_id=dataset.id;d.hda_ldda=dataset.get("hda_ldda")}$.extend(d,f);var j=this.get("filters_manager");if(j){var k=[];var a=j.filters;for(var e=0;e<a.length;e++){k.push(a[e].name)}d.filter_cols=JSON.stringify(k)}var c=this;return $.getJSON(this.get("data_url"),d,function(i){c.set_data(h,i)})},get_data:function(g,f,c,e){var h=this.get_elt(g);if(h&&(is_deferred(h)||this.get("data_mode_compatible")(h,f))){return h}var j=this.get("key_ary"),b=this.get("obj_cache"),k,a;for(var d=0;d<j.length;d++){k=j[d];a=new GenomeRegion({from_str:k});if(a.contains(g)){h=b[k];if(is_deferred(h)||(this.get("data_mode_compatible")(h,f)&&this.get("can_subset")(h))){this.move_key_to_end(k,d);return h}}}h=this.load_data(g,f,c,e);this.set_data(g,h);return h},set_data:function(b,a){this.set_elt(b,a)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(i,h,d,g,e){var k=this.get_elt(i);if(!(k&&this.get("data_mode_compatible")(k,h))){console.log("ERROR: no current data for: ",dataset,i.toString(),h,d,g);return}k.stale=true;var c=i.get("start");if(e===this.DEEP_DATA_REQ){$.extend(g,{start_val:k.data.length+1})}else{if(e===this.BROAD_DATA_REQ){c=(k.max_high?k.max_high:k.data[k.data.length-1][2])+1}}var j=i.copy().set("start",c);var b=this,f=this.load_data(j,h,d,g),a=$.Deferred();this.set_data(i,a);$.when(f).then(function(l){if(l.data){l.data=k.data.concat(l.data);if(l.max_low){l.max_low=k.max_low}if(l.message){l.message=l.message.replace(/[0-9]+/,l.data.length)}}b.set_data(i,l);a.resolve(l)});return a},get_elt:function(a){return Cache.prototype.get_elt.call(this,a.toString())},set_elt:function(b,a){return Cache.prototype.set_elt.call(this,b.toString(),a)}});var ReferenceTrackDataManager=GenomeDataManager.extend({load_data:function(a,d,e,b,c){if(b>1){return{data:null}}return GenomeDataManager.prototype.load_data.call(this,a,d,e,b,c)}});var Genome=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info}});var GenomeRegion=Backbone.RelationalModel.extend({defaults:{chrom:null,start:0,end:0,DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006},initialize:function(b){if(b.from_str){var d=b.from_str.split(":"),c=d[0],a=d[1].split("-");this.set({chrom:c,start:parseInt(a[0],10),end:parseInt(a[1],10)})}},copy:function(){return new GenomeRegion({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(h){var b=this.get("chrom"),g=h.get("chrom"),f=this.get("start"),d=h.get("start"),e=this.get("end"),c=h.get("end"),a;if(b&&g&&b!==g){return this.get("DIF_CHROMS")}if(f<d){if(e<d){a=this.get("BEFORE")}else{if(e<=c){a=this.get("OVERLAP_START")}else{a=this.get("CONTAINS")}}}else{if(f>c){a=this.get("AFTER")}else{if(e<=c){a=this.get("CONTAINED_BY")}else{a=this.get("OVERLAP_END")}}}return a},contains:function(a){return this.compute_overlap(a)===this.get("CONTAINS")},overlaps:function(a){return _.intersection([this.compute_overlap(a)],[this.get("DIF_CHROMS"),this.get("BEFORE"),this.get("AFTER")]).length===0}});var GenomeRegionCollection=Backbone.Collection.extend({model:GenomeRegion});var BrowserBookmark=Backbone.RelationalModel.extend({defaults:{region:null,note:""},relations:[{type:Backbone.HasOne,key:"region",relatedModel:"GenomeRegion"}]});var BrowserBookmarkCollection=Backbone.Collection.extend({model:BrowserBookmark});var GenomeWideBigWigData=Backbone.Model.extend({defaults:{data:null,min:0,max:0},initialize:function(b){var a=_.flatten(_.map(this.get("data"),function(c){if(c.data.length!==0){return _.map(c.data,function(d){return d[1]})}else{return 0}}));this.set("max",_.max(a));this.set("min",_.min(a))}});var GenomeWideSummaryTreeData=Backbone.RelationalModel.extend({defaults:{data:null,min:0,max:0},initialize:function(b){var a=_.max(this.get("data"),function(c){if(!c||typeof c==="string"){return 0}return c[1]});this.attributes.max=(a&&typeof a!=="string"?a[1]:0)}});var BackboneTrack=Dataset.extend({initialize:function(a){this.set("id",a.dataset_id);var c=this.get("genome_wide_data");if(c){var b=(this.get("track_type")==="LineTrack"?GenomeWideBigWigData:GenomeWideSummaryTreeData);this.set("genome_wide_data",new b(c))}}});var Visualization=Backbone.RelationalModel.extend({defaults:{id:"",title:"",type:"",dbkey:"",tracks:null},relations:[{type:Backbone.HasMany,key:"tracks",relatedModel:"BackboneTrack"}],url:function(){return galaxy_paths.get("visualization_url")},save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var GenomeVisualization=Visualization.extend({defaults:_.extend({},Visualization.prototype.defaults,{bookmarks:null,viewport:null})});var TrackConfig=Backbone.Model.extend({});var CircsterDataLayout=Backbone.Model.extend({defaults:{genome:null,dataset:null,total_gap:null},chroms_layout:function(){var b=this.attributes.genome.get_chroms_info(),d=d3.layout.pie().value(function(f){return f.len}).sort(null),e=d(b),a=this.attributes.total_gap/b.length,c=_.map(e,function(h,g){var f=h.endAngle-a;h.endAngle=(f>h.startAngle?f:h.startAngle);return h});return c},chrom_data_layout:function(d,c,b,e,a){},genome_data_layout:function(){var b=this,a=this.chroms_layout(),f=this.get("track").get("genome_wide_data"),e=this.get("radius_start"),c=this.get("radius_end"),d=_.zip(a,f.get("data")),g=_.map(d,function(i){var j=i[0],h=i[1];return b.chrom_data_layout(j,h,e,c,f.get("min"),f.get("max"))});return g}});var CircsterSummaryTreeLayout=CircsterDataLayout.extend({chrom_data_layout:function(k,b,h,g,d,i){if(!b||typeof b==="string"){return null}var e=b[0],j=b[3],c=d3.scale.linear().domain([d,i]).range([h,g]),f=d3.layout.pie().value(function(l){return j}).startAngle(k.startAngle).endAngle(k.endAngle),a=f(e);_.each(e,function(l,m){a[m].outerRadius=c(l[1])});return a}});var CircsterBigWigLayout=CircsterDataLayout.extend({chrom_data_layout:function(j,b,h,g,d,i){var e=b.data;if(e.length===0){return}var c=d3.scale.linear().domain([d,i]).range([h,g]),f=d3.layout.pie().value(function(l,k){if(k+1===e.length){return 0}return e[k+1][0]-e[k][0]}).startAngle(j.startAngle).endAngle(j.endAngle),a=f(e);_.each(e,function(k,l){a[l].outerRadius=c(k[1])});return a}});var CircsterView=Backbone.View.extend({className:"circster",initialize:function(a){this.width=a.width;this.height=a.height;this.total_gap=a.total_gap;this.genome=a.genome;this.radius_start=a.radius_start;this.dataset_arc_height=a.dataset_arc_height;this.track_gap=5},render:function(){var b=this,c=this.dataset_arc_height;var a=d3.select(b.$el[0]).append("svg").attr("width",b.width).attr("height",b.height).append("g").attr("transform","translate("+b.width/2+","+b.height/2+")");this.model.get("tracks").each(function(f,l){var g=f.get("genome_wide_data"),k=b.radius_start+l*(c+b.track_gap),h=(g instanceof GenomeWideBigWigData?CircsterBigWigLayout:CircsterSummaryTreeLayout),n=new h({track:f,radius_start:k,radius_end:k+c,genome:b.genome,total_gap:b.total_gap}),d=n.chroms_layout(),i=n.genome_data_layout();var o=a.append("g").attr("id","inner-arc"),m=d3.svg.arc().innerRadius(k).outerRadius(k+c),e=o.selectAll("#inner-arc>path").data(d).enter().append("path").attr("d",m).style("stroke","#ccc").style("fill","#ccc").append("title").text(function(q){return q.data.chrom});var p=f.get("prefs"),j=p.block_color;_.each(i,function(q){if(!q){return}var t=a.append("g"),s=d3.svg.arc().innerRadius(k),r=t.selectAll("path").data(q).enter().append("path").attr("d",s).style("stroke",j).style("fill",j)})})}});var TrackBrowserRouter=Backbone.Router.extend({initialize:function(b){this.view=b.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var a=this;a.view.on("navigate",function(c){a.navigate(c)})},change_location:function(a){this.view.go_to(a)}});var add_datasets=function(a,c,b){$.ajax({url:a,data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(d){show_modal("Select datasets for new tracks",d,{Cancel:function(){hide_modal()},Add:function(){var e=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var f,g=$(this).val();if($(this).attr("name")==="id"){f={hda_id:g}}else{f={ldda_id:g}}e[e.length]=$.ajax({url:c,data:f,dataType:"json"})});$.when.apply($,e).then(function(){var f=(arguments[0] instanceof Array?$.map(arguments,function(g){return g[0]}):[arguments[0]]);b(f)});hide_modal()}})}})}; \ No newline at end of file diff -r 339f886d3ffadcb8cd5eb63029a141a55c9b2fd1 -r 51992bf52e0c6f1931256903f678b13ed2d373b6 static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -549,13 +549,40 @@ model: BrowserBookmark }); -/** - * Genome-wide summary data. - */ -var GenomeWideSummaryData = Backbone.RelationalModel.extend({ +var GenomeWideBigWigData = Backbone.Model.extend({ defaults: { data: null, - max: 0 + min: 0, + max: 0 + }, + + initialize: function(options) { + // Set max across dataset by extracting all values, flattening them into a + // single array, and getting the min and max. + var values = _.flatten( _.map(this.get('data'), function(d) { + if (d.data.length !== 0) { + // Each data point has the form [position, value], so return all values. + return _.map(d.data, function(p) { + return p[1]; + }); + } + else { + return 0; + } + }) ); + this.set('max', _.max(values)); + this.set('min', _.min(values)); + } +}); + +/** + * Genome-wide summary tree dataset. + */ +var GenomeWideSummaryTreeData = Backbone.RelationalModel.extend({ + defaults: { + data: null, + min: 0, + max: 0 }, initialize: function(options) { @@ -577,15 +604,15 @@ initialize: function(options) { // Dataset id is unique ID for now. this.set('id', options.dataset_id); - }, - relations: [ - { - type: Backbone.HasOne, - key: 'genome_wide_data', - relatedModel: 'GenomeWideSummaryData' + // Create genome-wide dataset if available. + var genome_wide_data = this.get('genome_wide_data'); + if (genome_wide_data) { + var gwd_class = (this.get('track_type') === 'LineTrack' ? + GenomeWideBigWigData : GenomeWideSummaryTreeData); + this.set('genome_wide_data', new gwd_class(genome_wide_data)); } - ] + } }); /** @@ -649,12 +676,14 @@ }); -/** - * Layout for a histogram dataset in a circster visualization. - */ -var CircsterHistogramDatasetLayout = Backbone.Model.extend({ - // TODO: should accept genome and dataset and use these to generate layout data. - + +var CircsterDataLayout = Backbone.Model.extend({ + defaults: { + genome: null, + dataset: null, + total_gap: null + }, + /** * Returns arc layouts for genome's chromosomes/contigs. Arcs are arranged in a circle * separated by gaps. @@ -671,16 +700,45 @@ arc.endAngle = (new_endAngle > arc.startAngle ? new_endAngle : arc.startAngle); return arc; }); - - // TODO: remove arcs for chroms that are too small and recompute? - return chrom_arcs; }, + + /** + * Returns layouts for drawing a chromosome's data. + */ + chrom_data_layout: function(chrom_arc, chrom_data, inner_radius, outer_radius, max) { + }, + + genome_data_layout: function() { + var self = this, + chrom_arcs = this.chroms_layout(), + dataset = this.get('track').get('genome_wide_data'), + r_start = this.get('radius_start'), + r_end = this.get('radius_end'), + + // Merge chroms layout with data. + layout_and_data = _.zip(chrom_arcs, dataset.get('data')), + + // Do dataset layout for each chromosome's data using pie layout. + chroms_data_layout = _.map(layout_and_data, function(chrom_info) { + var chrom_arc = chrom_info[0], + chrom_data = chrom_info[1]; + return self.chrom_data_layout(chrom_arc, chrom_data, r_start, r_end, dataset.get('min'), dataset.get('max')); + }); + + return chroms_data_layout; + } +}); + +/** + * Layout for summary tree data in a circster visualization. + */ +var CircsterSummaryTreeLayout = CircsterDataLayout.extend({ /** - * Returns layouts for drawing a chromosome's data. For now, only works with summary tree data. + * Returns layouts for drawing a chromosome's data. */ - chrom_data_layout: function(chrom_arc, chrom_data, inner_radius, outer_radius, max) { + chrom_data_layout: function(chrom_arc, chrom_data, inner_radius, outer_radius, min, max) { // If no chrom data, return null. if (!chrom_data || typeof chrom_data === "string") { return null; @@ -689,8 +747,8 @@ var data = chrom_data[0], delta = chrom_data[3], scale = d3.scale.linear() - .domain( [0, max] ) - .range( [inner_radius, outer_radius] ), + .domain( [min, max] ) + .range( [inner_radius, outer_radius] ), arc_layout = d3.layout.pie().value(function(d) { return delta; }) @@ -705,7 +763,42 @@ return arcs; } - +}); + +/** + * Layout for BigWig data in a circster visualization. + */ +var CircsterBigWigLayout = CircsterDataLayout.extend({ + + /** + * Returns layouts for drawing a chromosome's data. + */ + chrom_data_layout: function(chrom_arc, chrom_data, inner_radius, outer_radius, min, max) { + var data = chrom_data.data; + if (data.length === 0) { return; } + + var scale = d3.scale.linear() + .domain( [min, max] ) + .range( [inner_radius, outer_radius] ), + arc_layout = d3.layout.pie().value(function(d, i) { + // If at end of data, draw nothing. + if (i + 1 === data.length) { return 0; } + + // Layout is from current position to next position. + return data[i+1][0] - data[i][0]; + }) + .startAngle(chrom_arc.startAngle) + .endAngle(chrom_arc.endAngle), + arcs = arc_layout(data); + + // Use scale to assign outer radius. + _.each(data, function(datum, index) { + arcs[index].outerRadius = scale(datum[1]); + }); + + return arcs; + } + }); /** @@ -739,27 +832,20 @@ // -- Render each dataset in the visualization. -- this.model.get('tracks').each(function(track, index) { - var dataset = track.get('genome_wide_data'); - - var radius_start = self.radius_start + index * (dataset_arc_height + self.track_gap), + var dataset = track.get('genome_wide_data'), + radius_start = self.radius_start + index * (dataset_arc_height + self.track_gap), // Layout chromosome arcs. - arcs_layout = new CircsterHistogramDatasetLayout({ + layout_class = (dataset instanceof GenomeWideBigWigData ? CircsterBigWigLayout : CircsterSummaryTreeLayout ), + arcs_layout = new layout_class({ + track: track, + radius_start: radius_start, + radius_end: radius_start + dataset_arc_height, genome: self.genome, total_gap: self.total_gap }), - chrom_arcs = arcs_layout.chroms_layout(), + genome_arcs = arcs_layout.chroms_layout(), + chroms_arcs = arcs_layout.genome_data_layout(); - // Merge chroms layout with data. - layout_and_data = _.zip(chrom_arcs, dataset.get('data')), - dataset_max = dataset.get('max'), - - // Do dataset layout for each chromosome's data using pie layout. - chroms_data_layout = _.map(layout_and_data, function(chrom_info) { - var chrom_arc = chrom_info[0], - chrom_data = chrom_info[1]; - return arcs_layout.chrom_data_layout(chrom_arc, chrom_data, radius_start, radius_start + dataset_arc_height, dataset_max); - }); - // -- Render. -- // Draw background arcs for each chromosome. @@ -769,7 +855,7 @@ .outerRadius(radius_start + dataset_arc_height), // Draw arcs. chroms_elts = base_arc.selectAll("#inner-arc>path") - .data(chrom_arcs).enter().append("path") + .data(genome_arcs).enter().append("path") .attr("d", arc_gen) .style("stroke", "#ccc") .style("fill", "#ccc") @@ -778,7 +864,7 @@ // For each chromosome, draw dataset. var prefs = track.get('prefs'), block_color = prefs.block_color; - _.each(chroms_data_layout, function(chrom_layout) { + _.each(chroms_arcs, function(chrom_layout) { if (!chrom_layout) { return; } var group = svg.append("g"), 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.