refactor trackster, better failure message

This commit is contained in:
Kanwei Li
2009-10-06 23:47:08 -04:00
parent 91de8aceb4
commit f2cebd4366
6 changed files with 72 additions and 81 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"""
Read a chromosome of coverage data, and write it as a npy array, as
well as averages over regions of progessively larger size in powers of 10
well as averages over regions of progressively larger size in powers of 10
"""
from __future__ import division
+1 -1
View File
@@ -2,7 +2,7 @@
"""
Read a chromosome of wiggle data, and write it as a npy array, as
well as averages over regions of progessively larger size in powers of 10
well as averages over regions of progressively larger size in powers of 10
"""
from __future__ import division
+3 -2
View File
@@ -49,7 +49,8 @@ dataset_type_to_data_provider = {
# FIXME: hardcoding this for now, but it should be derived from the available
# converters
browsable_types = set( ["wig", "bed" ] )
browsable_types = ( "wig", "bed" )
class TracksController( BaseController ):
"""
@@ -92,7 +93,7 @@ class TracksController( BaseController ):
if dataset.metadata.dbkey == dbkey and dataset.extension in browsable_types:
datasets[dataset.id] = (dataset.extension, dataset.name)
# Render the template
return trans.fill_template( "tracks/new_browser.mako", dbkey=dbkey, dbkey_set=dbkey_set, datasets=datasets )
return trans.fill_template( "tracks/new_browser.mako", converters=browsable_types, dbkey=dbkey, dbkey_set=dbkey_set, datasets=datasets )
@web.expose
def browser(self, trans, dataset_ids, chrom=""):
+23 -42
View File
@@ -6,35 +6,6 @@ var DENSITY = 1000,
DATA_ERROR = "There was an error in indexing this dataset.",
DATA_NONE = "No data for this chrom/contig.";
var DataCache = function( type, track ) {
this.type = type;
this.track = track;
this.cache = Object();
};
$.extend( DataCache.prototype, {
get: function( resolution, position ) {
var cache = this.cache;
if ( !( cache[resolution] && cache[resolution][position] ) ) {
if ( !cache[resolution] ) {
cache[resolution] = Object();
}
var low = position * DENSITY * resolution;
var high = ( position + 1 ) * DENSITY * resolution;
cache[resolution][position] = { state: "loading" };
$.getJSON( data_url, { track_type: this.track.track_type, chrom: this.track.view.chrom, low: low, high: high, dataset_id: this.track.dataset_id }, function ( data ) {
if( data == "pending" ) {
setTimeout( fetcher, 5000 );
} else {
cache[resolution][position] = { state: "loaded", values: data };
}
$(document).trigger( "redraw" );
});
}
return cache[resolution][position];
}
});
var View = function( chrom, max_length ) {
this.chrom = chrom;
this.tracks = [];
@@ -234,7 +205,7 @@ var LineTrack = function ( name, dataset_id, height ) {
this.container_div.addClass( "line-track" );
this.content_div.css( "height", this.height_px + "px" );
this.dataset_id = dataset_id;
this.cache = new DataCache( "", this );
this.cache = new Cache(50);
};
$.extend( LineTrack.prototype, TiledTrack.prototype, {
init: function() {
@@ -254,6 +225,21 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
}
});
},
get_data: function( resolution, position ) {
var key = resolution + '-' + position,
cache = this.cache;
if ( !cache[key] ) {
var low = position * DENSITY * resolution,
high = ( position + 1 ) * DENSITY * resolution;
$.getJSON( data_url, { track_type: this.track_type, chrom: this.view.chrom, low: low, high: high, dataset_id: this.dataset_id }, function ( data ) {
cache[key] = data;
$(document).trigger( "redraw" );
});
}
return cache[key];
},
draw_tile: function( resolution, tile_index, parent_element, w_scale, h_scale ) {
if (!this.vertical_range) // We don't have the necessary information yet
return;
@@ -261,13 +247,13 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
var tile_low = tile_index * DENSITY * resolution,
tile_high = ( tile_index + 1 ) * DENSITY * resolution,
tile_length = DENSITY * resolution;
var chunk = this.cache.get( resolution, tile_index );
var element;
if ( chunk.state == "loading" ) {
element = $("<div class='loading tile'></div>");
} else {
element = $("<canvas class='tile'></canvas>");
var data = this.get_data( resolution, tile_index );
if ( !data ) {
in_path = false;
return null;
}
var element = $("<canvas class='tile'></canvas>");
element.css( {
position: "absolute",
top: 0,
@@ -275,18 +261,13 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
});
parent_element.append( element );
// Chunk is still loading, do nothing
if ( chunk.state == "loading" ) {
in_path = false;
return null;
}
var canvas = element;
canvas.get(0).width = Math.ceil( tile_length * w_scale );
canvas.get(0).height = this.height_px;
var ctx = canvas.get(0).getContext("2d");
var in_path = false;
ctx.beginPath();
var data = chunk.values;
if (!data) return;
for ( var i = 0; i < data.length - 1; i++ ) {
var x = data[i][0] - tile_low;
var y = data[i][1];
+1 -1
View File
@@ -7,7 +7,7 @@ ${parent.stylesheets()}
<%def name="javascripts()">
${parent.javascripts()}
${h.js( "jquery", "jquery.event.drag", "jquery.mousewheel", "trackster" )}
${h.js( "jquery", "jquery.event.drag", "jquery.mousewheel", "lrucache", "trackster" )}
<script type="text/javascript">
+43 -34
View File
@@ -11,39 +11,48 @@ $( function() {
</script>
</%def>
<div class="form">
<div class="form-title">Select datasets to include in browser</div>
<div id="dbkey" class="form-body">
<form id="form" method="POST">
<div class="form-row">
<label for="dbkey">Reference genome build (dbkey): </label>
<div class="form-row-input">
<select name="dbkey" id="dbkey" refresh_on_change="true">
%for tmp_dbkey in dbkey_set:
<option value="${tmp_dbkey}"
%if tmp_dbkey == dbkey:
selected="selected"
%endif
>${tmp_dbkey}</option>
%endfor
</select>
</div>
<div style="clear: both;"></div>
</div>
<div class="form-row">
<label for="dataset_ids">Datasets to include: </label>
%for dataset_id, (dataset_ext, dataset_name) in datasets.iteritems():
<div>
<input type="checkbox" id="${dataset_id}" name="dataset_ids" value="${dataset_id}" />
<label style="display:inline; font-weight: normal" for="${dataset_id}">[${dataset_ext}] ${dataset_name}</label>
</div>
%endfor
% if not converters:
<div class="errormessagelarge">
There are no available converters needed for visualization. Please verify that your tool_conf.xml file contains
converters for datatypes (see tool_conf.xml.sample) for examples.
</div>
<div style="clear: both;"></div>
% else:
<div class="form">
<div class="form-title">Select datasets to include in browser</div>
<div id="dbkey" class="form-body">
<form id="form" method="POST">
<div class="form-row">
<label for="dbkey">Reference genome build (dbkey): </label>
<div class="form-row-input">
<select name="dbkey" id="dbkey" refresh_on_change="true">
%for tmp_dbkey in dbkey_set:
<option value="${tmp_dbkey}"
%if tmp_dbkey == dbkey:
selected="selected"
%endif
>${tmp_dbkey}</option>
%endfor
</select>
</div>
<div style="clear: both;"></div>
</div>
<div class="form-row">
<label for="dataset_ids">Datasets to include: </label>
%for dataset_id, (dataset_ext, dataset_name) in datasets.iteritems():
<div>
<input type="checkbox" id="${dataset_id}" name="dataset_ids" value="${dataset_id}" />
<label style="display:inline; font-weight: normal" for="${dataset_id}">[${dataset_ext}] ${dataset_name}</label>
</div>
%endfor
<div style="clear: both;"></div>
</div>
</div>
</div>
<div class="form-row">
<input type="submit" name="browse" value="Browse"/>
</div>
</form>
</div>
<div class="form-row">
<input type="submit" name="browse" value="Browse"/>
</div>
</form>
</div>
% endif