1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/429103684d86/ changeset: 429103684d86 user: jgoecks date: 2013-02-21 23:10:54 summary: Trackster: add subsetting functionality to data manager and enable subsetting for line tracks. affected #: 4 files diff -r 26d7b89d9f897a28876214c88faed215973e6fcd -r 429103684d864f93563cd92c30888bd623fdb80e lib/galaxy/visualization/data_providers/genome.py --- a/lib/galaxy/visualization/data_providers/genome.py +++ b/lib/galaxy/visualization/data_providers/genome.py @@ -1044,9 +1044,7 @@ return all_dat is not None def get_data( self, chrom, start, end, start_val=0, max_vals=None, num_samples=1000, **kwargs ): - # Subtract 1 because start/end are in 0-based coordinate system but BBI - # provider uses 1-based coordinate system. - start = int( start ) - 1 + start = int( start ) end = int( end ) # Helper function for getting summary data regardless of chromosome diff -r 26d7b89d9f897a28876214c88faed215973e6fcd -r 429103684d864f93563cd92c30888bd623fdb80e static/scripts/viz/trackster/painters.js --- a/static/scripts/viz/trackster/painters.js +++ b/static/scripts/viz/trackster/painters.js @@ -258,7 +258,8 @@ // y becomes the bar height in pixels, which is the negated for canvas coords y = Math.round( y / vertical_range * height_px ); ctx.fillRect(x_scaled, y_zero, delta_x_px, - y ); - } else if (mode === "Intensity") { + } + else if (mode === "Intensity") { var saturation = (y - min_value) / vertical_range, // Range is [pref_color, 255] where saturation = 0 --> 255 and saturation = 1 --> pref color @@ -267,18 +268,21 @@ 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 { + } + else { // console.log(y, track.min_value, track.vertical_range, (y - track.min_value) / track.vertical_range * track.height_px); y = Math.round( height_px - (y - min_value) / vertical_range * height_px ); // console.log(canvas.get(0).height, canvas.get(0).width); if (in_path) { ctx.lineTo(x_scaled, y); - } else { + } + else { in_path = true; if (mode === "Filled") { ctx.moveTo(x_scaled, height_px); ctx.lineTo(x_scaled, y); - } else { + } + else { ctx.moveTo(x_scaled, y); } } @@ -289,7 +293,8 @@ var overflow_x; if (mode === "Histogram" || mode === "Intensity") { overflow_x = delta_x_px; - } else { // Line and Filled, which are points + } + else { // Line and Filled, which are points x_scaled -= 2; // Move it over to the left so it's centered on the point overflow_x = 4; } @@ -308,7 +313,8 @@ ctx.lineTo( 0, y_zero ); } ctx.fill(); - } else { + } + else { ctx.stroke(); } @@ -469,7 +475,7 @@ */ get_row_height: function() { var mode = this.mode, height; - if (mode === "Dense") { + if (mode === "Dense") { height = DENSE_TRACK_HEIGHT; } else if (mode === "no_detail") { diff -r 26d7b89d9f897a28876214c88faed215973e6fcd -r 429103684d864f93563cd92c30888bd623fdb80e static/scripts/viz/trackster/tracks.js --- a/static/scripts/viz/trackster/tracks.js +++ b/static/scripts/viz/trackster/tracks.js @@ -3540,6 +3540,7 @@ on_resize: function() { this.request_draw(true); }, + /** * Set track minimum value. */ @@ -3549,6 +3550,7 @@ this.tile_cache.clear(); this.request_draw(); }, + /** * Set track maximum value. */ @@ -3558,6 +3560,7 @@ this.tile_cache.clear(); this.request_draw(); }, + predraw_init: function() { var track = this; track.vertical_range = undefined; @@ -3618,6 +3621,7 @@ .prependTo(track.container_div); }); }, + /** * Draw LineTrack tile. */ @@ -3632,11 +3636,12 @@ return new Tile(this, region, resolution, canvas, result.data); }, + /** - * LineTrack data cannot currently be subsetted. + * Subset line tracks only if resolution is single-base pair. */ - can_subset: function(data) { - return false; + can_subset: function(entry) { + return (entry.data[1][0] - entry.data[0][0] === 1); } }); diff -r 26d7b89d9f897a28876214c88faed215973e6fcd -r 429103684d864f93563cd92c30888bd623fdb80e static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -355,25 +355,38 @@ // var key_ary = this.get('key_ary'), obj_cache = this.get('obj_cache'), - key, entry_region; + key, entry_region, is_subregion; for (var i = 0; i < key_ary.length; i++) { key = key_ary[i]; entry_region = new GenomeRegion({from_str: key}); if (entry_region.contains(region)) { + is_subregion = true; + // This entry has data in the requested range. Return if data // is compatible and can be subsetted. entry = obj_cache[key]; if ( is_deferred(entry) || ( this.get('data_mode_compatible')(entry, mode) && this.get('can_subset')(entry) ) ) { this.move_key_to_end(key, i); + + // If there's data, subset it. + if ( !is_deferred(entry) ) { + var subset_entry = this.subset_entry(entry, region); + this.set(region, subset_entry); + entry = subset_entry; + } + return entry; } } } + // FIXME: There _may_ be instances where region is a subregion of another entry but cannot be + // subsetted. For these cases, do not increase length because region will never be found (and + // an infinite loop will occur.) // If needed, extend region to make it minimum size. - if (region.length() < this.attributes.min_region_size) { + if (!is_subregion && region.length() < this.attributes.min_region_size) { // IDEA: alternative heuristic is to find adjacent cache entry to region and use that to extend. // This would prevent bad extensions when zooming in/out while still preserving the behavior // below. @@ -553,7 +566,40 @@ return deferred; }, - + + /** + * Returns entry with only data in the subregion. + */ + subset_entry: function(entry, subregion) { + // Dictionary from entry type to function for subsetting data. + var subset_fns = { + bigwig: function(data, subregion) { + return _.filter(data, function(data_point) { + return data_point[0] >= subregion.get('start') && + data_point[0] <= subregion.get('end'); + }); + }, + 'refseq': function(data, subregion) { + var seq_start = subregion.get('start') - entry.region.get('start'), + seq_end = entry.data.length - ( entry.region.get('end') - subregion.get('end') ); + return entry.data.slice(seq_start, seq_end); + } + }; + + // Subset entry if there is a function for subsetting and regions are not the same. + var subregion_data = entry.data; + if (!entry.region.same(subregion) && entry.dataset_type in subset_fns) { + subregion_data = subset_fns[entry.dataset_type](entry.data, subregion); + } + + // Return entry with subregion's data. + return { + region: subregion, + data: subregion_data, + dataset_type: entry.dataset_type + }; + }, + /** * Get data from the cache. */ @@ -584,24 +630,6 @@ return { data: null }; } return GenomeDataManager.prototype.load_data.call(this, region, mode, resolution, extra_params); - }, - - /** - * Return an entry that includes only data in the subregion. - */ - subset_entry: function(entry, subregion) { - var seq_data = entry.data; - if (!entry.region.same(subregion)) { - // Need to subset sequence data. - var seq_start = subregion.get('start') - entry.region.get('start'), - seq_end = entry.data.length - ( entry.region.get('end') - subregion.get('end') ); - seq_data = entry.data.slice(seq_start, seq_end); - } - - return { - region: subregion, - data: seq_data - }; } }); 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.