1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/changeset/f93ecd917348/
changeset: f93ecd917348
user: jgoecks
date: 2012-06-13 18:10:54
summary: Viz framework: (a) JavaScript support for running tools and enhancements to
parameter viz.
affected #: 5 files
diff -r 7387d416d655e086ad3b792058069ea82ce23a3c -r
f93ecd917348aeef6332a6d441300ab505daad73 static/scripts/mvc/data.js
--- /dev/null
+++ b/static/scripts/mvc/data.js
@@ -0,0 +1,16 @@
+/**
+ * A dataset. In Galaxy, datasets are associated with a history, so
+ * this object is also known as a HistoryDatasetAssociation.
+ */
+var Dataset = Backbone.Model.extend({
+ defaults: {
+ id: "",
+ type: "",
+ name: "",
+ hda_ldda: ""
+ }
+});
+
+var DatasetCollection = Backbone.Collection.extend({
+ model: Dataset
+});
\ No newline at end of file
diff -r 7387d416d655e086ad3b792058069ea82ce23a3c -r
f93ecd917348aeef6332a6d441300ab505daad73 static/scripts/mvc/tools.js
--- a/static/scripts/mvc/tools.js
+++ b/static/scripts/mvc/tools.js
@@ -51,11 +51,78 @@
}
],
- urlRoot: galaxy_paths.attributes.root_path + 'api/tools',
+ urlRoot: galaxy_paths.get('tool_url'),
apply_search_results: function(results) {
( _.indexOf(results, this.attributes.id) !== -1 ? this.show() : this.hide() );
return this.is_visible();
+ },
+
+ /**
+ * Set a tool input's value.
+ */
+ set_input_value: function(name, value) {
+ this.get('inputs').find(function(input) {
+ return input.get('name') === name;
+ }).set('value', value);
+ },
+
+ /**
+ * Run tool; returns a Deferred that resolves to the tool's output(s).
+ */
+ run: function() {
+ return this._run()
+ },
+
+ /**
+ * Rerun tool using regions and a target dataset.
+ */
+ rerun: function(target_dataset, regions) {
+ return this._run({
+ action: 'rerun',
+ target_dataset_id: target_dataset.id,
+ regions: JSON.stringify(regions)
+ });
+ },
+
+ /**
+ * Run tool; returns a Deferred that resolves to the tool's output(s).
+ * NOTE: this method is a helper method and should not be called directly.
+ */
+ _run: function(additional_params) {
+ // Create payload.
+ var payload = _.extend({
+ tool_id: this.id
+ }, additional_params),
+ input_dict = {};
+ this.get('inputs').each(function(input) {
+ input_dict[input.get('name')] = input.get('value');
+ });
+ payload.inputs = input_dict;
+
+ // Because job may require indexing datasets, use server-side
+ // deferred to ensure that job is run. Also use deferred that
+ // resolves to outputs from tool.
+ var run_deferred = $.Deferred(),
+ ss_deferred = new ServerStateDeferred({
+ ajax_settings: {
+ url: this.urlRoot,
+ data: JSON.stringify(payload),
+ dataType: "json",
+ contentType: 'application/json',
+ type: "POST"
+ },
+ interval: 2000,
+ success_fn: function(response) {
+ return response !== "pending";
+ }
+ });
+
+ // Run job and resolve run_deferred to tool outputs.
+ $.when(ss_deferred.go()).then(function(result) {
+ run_deferred.resolve(new DatasetCollection().reset(result));
+ });
+ return run_deferred;
}
});
@@ -65,7 +132,9 @@
var ToolInput = Backbone.RelationalModel.extend({
defaults: {
name: null,
- type: null
+ label: null,
+ type: null,
+ value: null,
},
initialize: function() {
diff -r 7387d416d655e086ad3b792058069ea82ce23a3c -r
f93ecd917348aeef6332a6d441300ab505daad73 static/scripts/viz/paramamonster.js
--- a/static/scripts/viz/paramamonster.js
+++ b/static/scripts/viz/paramamonster.js
@@ -38,15 +38,16 @@
var
param_samples = params_samples[index],
param = param_samples.get('param'),
- param_name = param.get('name'),
+ param_label = param.get('label'),
settings = param_samples.get('samples');
// Create leaves when last parameter setting is reached.
if (params_samples.length - 1 === index) {
return _.map(settings, function(setting) {
return {
- name: param_name + '=' + setting,
- param: param
+ name: param_label + '=' + setting,
+ param: param,
+ value: setting
}
});
}
@@ -54,8 +55,9 @@
// Recurse to handle other parameters.
return _.map(settings, function(setting) {
return {
- name: param_name + '=' + setting,
+ name: param_label + '=' + setting,
param: param,
+ value: setting,
children: create_tree_data(filtered_params_samples, index + 1)
}
});
@@ -94,104 +96,17 @@
});
/**
- * A track in a genome browser.
+ * ParamaMonster visualization model.
*/
-var Track = Backbone.Model.extend({
- defaults: {
- dataset: null
- }
-});
-
-var FeatureTrack = Track.extend({
- defaults: {
- track: null
- },
+var ParamaMonsterVisualization = Visualization.extend({
+ defaults: _.extend({}, Visualization.prototype.defaults, {
+ tool: null,
+ parameter_tree: null,
+ regions: null
+ }),
- /**
- * Draw FeatureTrack tile.
- * @param result result from server
- * @param cxt canvas context to draw on
- * @param mode mode to draw in
- * @param resolution view resolution
- * @param region region to draw
- * @param w_scale pixels per base
- * @param ref_seq reference sequence data
- */
- draw_tile: function(result, ctx, mode, resolution, region, w_scale, ref_seq) {
- var track = this,
- canvas = ctx.canvas,
- tile_low = region.get('start'),
- tile_high = region.get('end'),
- min_height = 25,
- left_offset = this.left_offset;
-
- // Drawing the summary tree (feature coverage histogram)
- if (mode === "summary_tree" || mode === "Histogram") {
- // Get summary tree data if necessary and set max if there is one.
- if (result.dataset_type !== "summary_tree") {
- var st_data = this.get_summary_tree_data(result.data, tile_low,
tile_high, 200);
- if (result.max) {
- st_data.max = result.max;
- }
- result = st_data;
- }
- // Paint summary tree into canvas
- var painter = new painters.SummaryTreePainter(result, tile_low, tile_high,
this.prefs);
- painter.draw(ctx, canvas.width, canvas.height, w_scale);
- return new SummaryTreeTile(track, tile_index, resolution, canvas,
result.data, result.max);
- }
-
- // Handle row-by-row tracks
-
- // Preprocessing: filter features and determine whether all unfiltered features
have been slotted.
- var
- filtered = [],
- slots = this.slotters[w_scale].slots;
- all_slotted = true;
- if ( result.data ) {
- var filters = this.filters_manager.filters;
- for (var i = 0, len = result.data.length; i < len; i++) {
- var feature = result.data[i];
- var hide_feature = false;
- var filter;
- for (var f = 0, flen = filters.length; f < flen; f++) {
- filter = filters[f];
- filter.update_attrs(feature);
- if (!filter.keep(feature)) {
- hide_feature = true;
- break;
- }
- }
- if (!hide_feature) {
- // Feature visible.
- filtered.push(feature);
- // Set flag if not slotted.
- if ( !(feature[0] in slots) ) {
- all_slotted = false;
- }
- }
- }
- }
-
- // Create painter.
- var filter_alpha_scaler = (this.filters_manager.alpha_filter ? new
FilterScaler(this.filters_manager.alpha_filter) : null);
- var filter_height_scaler = (this.filters_manager.height_filter ? new
FilterScaler(this.filters_manager.height_filter) : null);
- // HACK: ref_seq will only be defined for ReadTracks, and only the ReadPainter
accepts that argument
- var painter = new (this.painter)(filtered, tile_low, tile_high, this.prefs, mode,
filter_alpha_scaler, filter_height_scaler, ref_seq);
- var feature_mapper = null;
-
- // console.log(( tile_low - this.view.low ) * w_scale, tile_index, w_scale);
- ctx.fillStyle = this.prefs.block_color;
- ctx.font = ctx.canvas.manager.default_font;
- ctx.textAlign = "right";
-
- if (result.data) {
- // Draw features.
- feature_mapper = painter.draw(ctx, canvas.width, canvas.height, w_scale,
slots);
- feature_mapper.translation = -left_offset;
- }
-
- return new FeatureTrackTile(track, tile_index, resolution, canvas, result.data,
w_scale, mode, result.message, all_slotted, feature_mapper);
+ initialize: function(options) {
+ this.set('parameter_tree', new ToolParameterTree({ tool:
this.get('tool') }));
}
});
@@ -207,7 +122,6 @@
className: 'tool-parameter-tree',
initialize: function(options) {
- this.model = options.model;
},
render: function() {
@@ -244,7 +158,32 @@
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.y
+ "," + d.x + ")"; });
- // Set up behavior when node is clicked.
+ node.append("circle")
+ .attr("r", 4.5);
+
+ node.append("text")
+ .attr("dx", function(d) { return d.children ? -8 : 8; })
+ .attr("dy", 3)
+ .attr("text-anchor", function(d) { return d.children ?
"end" : "start"; })
+ .text(function(d) { return d.name; });
+ }
+});
+
+var ParamaMonsterVisualizationView = Backbone.View.extend({
+ className: 'paramamonster',
+
+ initialize: function(options) {
+
+ },
+
+ render: function() {
+ // Set up tool parameter tree.
+ var tool_param_tree_view = new ToolParameterTreeView({ model:
this.model.get('parameter_tree') });
+ tool_param_tree_view.render();
+ this.$el.append(tool_param_tree_view.$el);
+
+ // When node clicked in tree, run tool and show tiles.
+ var node = d3.select(tool_param_tree_view.$el[0]).selectAll("g.node")
node.on("click", function(d, i) {
console.log(d, i);
@@ -256,14 +195,6 @@
// Display tiles for region(s) of interest.
});
-
- node.append("circle")
- .attr("r", 4.5);
-
- node.append("text")
- .attr("dx", function(d) { return d.children ? -8 : 8; })
- .attr("dy", 3)
- .attr("text-anchor", function(d) { return d.children ?
"end" : "start"; })
- .text(function(d) { return d.name; });
- }
+
+ },
});
\ No newline at end of file
diff -r 7387d416d655e086ad3b792058069ea82ce23a3c -r
f93ecd917348aeef6332a6d441300ab505daad73 static/scripts/viz/visualization.js
--- a/static/scripts/viz/visualization.js
+++ b/static/scripts/viz/visualization.js
@@ -11,11 +11,10 @@
/**
* Implementation of a server-state based deferred. Server is repeatedly polled, and
when
* condition is met, deferred is resolved.
- */
+ */
var ServerStateDeferred = Backbone.Model.extend({
defaults: {
- url: null,
- url_params: {},
+ ajax_settings: {},
interval: 1000,
success_fn: function(result) { return true; }
},
@@ -26,10 +25,11 @@
go: function() {
var deferred = $.Deferred(),
self = this,
+ ajax_settings = self.get('ajax_settings'),
success_fn = self.get('success_fn'),
interval = self.get('interval'),
_go = function() {
- $.getJSON(self.get('url'), self.get('url_params'),
function(result) {
+ $.ajax(ajax_settings).success(function(result) {
if (success_fn(result)) {
// Result is good, so resolve.
deferred.resolve(result);
@@ -372,6 +372,14 @@
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 the type of overlap between this region and another region. The overlap is
computed relative to the given/second region;
* hence, OVERLAP_START indicates that the first region overlaps the start (but not
the end) of the second region.
@@ -495,19 +503,6 @@
});
/**
- * A dataset. In Galaxy, datasets are associated with a history, so
- * this object is also known as a HistoryDatasetAssociation.
- */
-var Dataset = Backbone.Model.extend({
- defaults: {
- id: "",
- type: "",
- name: "",
- hda_ldda: ""
- }
-});
-
-/**
* A histogram dataset.
*/
var HistogramDataset = Backbone.Model.extend({
diff -r 7387d416d655e086ad3b792058069ea82ce23a3c -r
f93ecd917348aeef6332a6d441300ab505daad73 templates/base_panels.mako
--- a/templates/base_panels.mako
+++ b/templates/base_panels.mako
@@ -52,7 +52,8 @@
// Set up needed paths.
var galaxy_paths = new GalaxyPaths({
root_path: '${h.url_for( "/" )}',
- image_path: '${h.url_for( "/static/images" )}'
+ image_path: '${h.url_for( "/static/images" )}',
+ tool_url: '${h.url_for( controller="/api/tools" )}'
});
</script></%def>
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.