commit/galaxy-central: jgoecks: Viz framework: (a) add option to store open file reference in data providers rather than recreating each time and (b) add ticks marks in Circster for chromosome lengths.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/5440f6b3bdec/ changeset: 5440f6b3bdec user: jgoecks date: 2012-10-31 22:51:38 summary: Viz framework: (a) add option to store open file reference in data providers rather than recreating each time and (b) add ticks marks in Circster for chromosome lengths. affected #: 3 files diff -r 8526b10ca125a99de4d944e776e647c1598ffd06 -r 5440f6b3bdecf081493aa31f473470fd11fecceb lib/galaxy/visualization/data_providers/genome.py --- a/lib/galaxy/visualization/data_providers/genome.py +++ b/lib/galaxy/visualization/data_providers/genome.py @@ -130,6 +130,11 @@ original_dataset=original_dataset, dependencies=dependencies, error_max_vals=error_max_vals ) + + # File/pointer where data is obtained from. It is useful to set this for repeated + # queries, such as is necessary for genome-wide data. + # TODO: add functions to (a) create data_file and (b) clean up data_file. + self.data_file = None def write_data_to_file( self, regions, filename ): """ @@ -345,17 +350,18 @@ bgzip_fname = self.dependencies['bgzip'].file_name - tabix = ctabix.Tabixfile(bgzip_fname, index_filename=self.converted_dataset.file_name) + if not self.data_file: + self.data_file = ctabix.Tabixfile(bgzip_fname, index_filename=self.converted_dataset.file_name) # Get iterator using either naming scheme. iterator = iter( [] ) - if chrom in tabix.contigs: - iterator = tabix.fetch(reference=chrom, start=start, end=end) + if chrom in self.data_file.contigs: + iterator = self.data_file.fetch(reference=chrom, start=start, end=end) else: # Try alternative naming scheme. chrom = _convert_between_ucsc_and_ensemble_naming( chrom ) - if chrom in tabix.contigs: - iterator = tabix.fetch(reference=chrom, start=start, end=end) + if chrom in self.data_file.contigs: + iterator = self.data_file.fetch(reference=chrom, start=start, end=end) return iterator diff -r 8526b10ca125a99de4d944e776e647c1598ffd06 -r 5440f6b3bdecf081493aa31f473470fd11fecceb lib/galaxy/visualization/tracks/summary.py --- a/lib/galaxy/visualization/tracks/summary.py +++ b/lib/galaxy/visualization/tracks/summary.py @@ -110,5 +110,8 @@ cPickle.dump( self, open( filename, 'wb' ), 2 ) def summary_tree_from_file( filename ): - return cPickle.load( open( filename, "rb" ) ) + st_file = open( filename, "rb" ) + st = cPickle.load( st_file ) + st_file.close() + return st diff -r 8526b10ca125a99de4d944e776e647c1598ffd06 -r 5440f6b3bdecf081493aa31f473470fd11fecceb static/scripts/viz/circster.js --- a/static/scripts/viz/circster.js +++ b/static/scripts/viz/circster.js @@ -27,13 +27,7 @@ /** * A label track. */ -var CircsterLabelTrack = Backbone.Model.extend({ - defaults: { - prefs: { - color: '#ccc' - } - } -}); +var CircsterLabelTrack = Backbone.Model.extend({}); /** * Renders a full circster visualization. @@ -46,7 +40,7 @@ this.genome = options.genome; this.dataset_arc_height = options.dataset_arc_height; this.track_gap = 5; - this.label_arc_height = 20; + this.label_arc_height = 50; this.scale = 1; this.circular_views = null; this.chords_views = null; @@ -78,7 +72,7 @@ }, /** - * Returns a list of tracks' radius bounds. + * Returns a list of circular tracks' radius bounds. */ get_tracks_bounds: function() { var circular_tracks = this.get_circular_tracks(); @@ -93,7 +87,7 @@ // Compute range of track starting radii. tracks_start_radii = d3.range(radius_start, min_dimension / 2, this.dataset_arc_height + this.track_gap); - // Map from track start to bounds; for label track + // Map from track start to bounds. var self = this; return _.map(tracks_start_radii, function(radius) { return [radius, radius + self.dataset_arc_height]; @@ -180,12 +174,17 @@ return view; }); - // -- Render label tracks. -- + // -- Render label track. -- - // Set radius start = end for track bounds. - var track_bounds = tracks_bounds[circular_tracks.length]; - track_bounds[1] = track_bounds[0]; - this.label_track_view = new CircsterLabelTrackView({ + // Track bounds are: + // (a) outer radius of last circular track; + // (b) + var outermost_radius = this.circular_views[this.circular_views.length-1].radius_bounds[1], + track_bounds = [ + outermost_radius, + outermost_radius + this.label_arc_height + ]; + this.label_track_view = new CircsterChromLabelTrackView({ el: svg.append('g')[0], track: new CircsterLabelTrack(), radius_bounds: track_bounds, @@ -534,36 +533,97 @@ /** * Render chromosome labels. */ -var CircsterLabelTrackView = CircsterTrackView.extend({ +var CircsterChromLabelTrackView = CircsterTrackView.extend({ initialize: function(options) { CircsterTrackView.prototype.initialize.call(this, options); + // Use a single arc for rendering data. + this.innerRadius = this.radius_bounds[0]; + this.radius_bounds[0] = this.radius_bounds[1]; this.bg_stroke = 'fff'; this.bg_fill = 'fff'; + + // Minimum arc distance for labels to be applied. + this.min_arc_len = 0.08; }, /** * Render labels. */ _render_data: function(svg) { - // Add chromosome label where it will fit; an alternative labeling mechanism - // would be nice for small chromosomes. - var chrom_arcs = svg.selectAll('g'); + // -- Add chromosome label where it will fit; an alternative labeling mechanism + // would be nice for small chromosomes. -- + var self = this, + chrom_arcs = svg.selectAll('g'); chrom_arcs.selectAll('path') .attr('id', function(d) { return 'label-' + d.data.chrom; }); chrom_arcs.append("svg:text") .filter(function(d) { - return d.endAngle - d.startAngle > 0.08; + return d.endAngle - d.startAngle > self.min_arc_len; }) .attr('text-anchor', 'middle') .append("svg:textPath") .attr("xlink:href", function(d) { return "#label-" + d.data.chrom; }) .attr('startOffset', '25%') + .attr('font-weight', 'bold') .text(function(d) { return d.data.chrom; }); + + // -- Add ticks to denote chromosome length. -- + + /** Returns an array of tick angles and labels, given a chrom arc. */ + var chromArcTicks = function(d) { + if (d.endAngle - d.startAngle < self.min_arc_len) { return []; } + var k = (d.endAngle - d.startAngle) / d.value, + ticks = d3.range(0, d.value, 25000000).map(function(v, i) { + return { + angle: v * k + d.startAngle, + label: i === 0 ? 0 : (i % 3 ? null : v / 1000000 + "M") + }; + }); + + // If there are fewer that 4 ticks, label last tick so that at least one non-zero tick is labeled. + if (ticks.length < 4) { + ticks[ticks.length-1].label = Math.round( + ( ticks[ticks.length-1].angle - d.startAngle ) / k / 1000000 + ) + "M"; + } + + return ticks; + }; + + var ticks = this.parent_elt.append("g") + .selectAll("g") + .data(this.chroms_layout) + .enter().append("g") + .selectAll("g") + .data(chromArcTicks) + .enter().append("g") + .attr("transform", function(d) { + return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")" + + "translate(" + self.innerRadius + ",0)"; + }); + + ticks.append("line") + .attr("x1", 1) + .attr("y1", 0) + .attr("x2", 4) + .attr("y2", 0) + .style("stroke", "#000"); + + ticks.append("text") + .attr("x", 4) + .attr("dy", ".35em") + .attr("text-anchor", function(d) { + return d.angle > Math.PI ? "end" : null; + }) + .attr("transform", function(d) { + return d.angle > Math.PI ? "rotate(180)translate(-16)" : null; + }) + .text(function(d) { return d.label; }); } }); Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket