revert to sqlite default in universe.sample

This commit is contained in:
Kanwei Li
2009-11-18 13:45:53 -05:00
parent bcf8c43069
commit 9efa130e6f
5 changed files with 133 additions and 61 deletions
@@ -8,7 +8,7 @@ import pkg_resources; pkg_resources.require( "bx-python" )
from bx.arrays.array_tree import *
from bx.arrays.wiggle import IntervalReader
BLOCK_SIZE = 1000
BLOCK_SIZE = 100
def main():
@@ -20,8 +20,8 @@ def main():
# Fill array from wiggle
d = array_tree_dict_from_wiggle_reader( reader, {}, block_size = BLOCK_SIZE )
for value in d.itervalues():
value.root.build_summary()
for array_tree in d.itervalues():
array_tree.root.build_summary()
f = open( out_fname, "w" )
FileArrayTreeDict.dict_to_file( d, f )
@@ -12,9 +12,6 @@ from math import floor, ceil, log
# Maybe this should be included in the datatype itself, so users can add their
# own types to the browser as long as they return the right format of data?
# FIXME: Assuming block size is always 1000 for the moment
BLOCK_SIZE = 1000
class ArrayTreeDataProvider( object ):
def __init__( self, dataset, original_dataset ):
self.dataset = dataset
@@ -32,32 +29,33 @@ class ArrayTreeDataProvider( object ):
return { 'max': float( max(root_summary.maxs) ), 'min': float( min(root_summary.mins) ) }
def get_data( self, chrom, start, end, **kwargs ):
start = int( start )
end = int( end )
resolution = max(1, ceil(float(kwargs['resolution'])))
level = int( floor( log( resolution, BLOCK_SIZE ) ) )
level = max( level, 0 )
stepsize = BLOCK_SIZE ** level
step1 = stepsize * BLOCK_SIZE
# Open the file
f = open( self.dataset.file_name )
d = FileArrayTreeDict( f )
# Get the right chromosome
try:
chrom_array_tree = d[chrom]
except KeyError:
return None
block_size = chrom_array_tree.block_size
start = int( start )
end = int( end )
resolution = max(1, ceil(float(kwargs['resolution'])))
level = int( floor( log( resolution, block_size ) ) )
level = max( level, 0 )
stepsize = block_size ** level
step1 = stepsize * block_size
# Is the requested level valid?
assert 0 <= level <= chrom_array_tree.levels
# Calculate the actual start/range/step of the block we're getting
results = []
for block_start in range( start, end, stepsize * BLOCK_SIZE ):
for block_start in range( start, end, stepsize * block_size ):
# print block_start
# Return either data point or a summary depending on the level
indexes = range( block_start, block_start + stepsize * BLOCK_SIZE, stepsize )
indexes = range( block_start, block_start + stepsize * block_size, stepsize )
if level > 0:
s = chrom_array_tree.get_summary( block_start, level )
if s is not None:
@@ -27,19 +27,21 @@ class IntervalIndexDataProvider( object ):
payload['strand'] = feature[5]
except IndexError:
pass
try:
block_sizes = [ int(n) for n in feature[10].split(',') if n != '']
block_starts = [ int(n) for n in feature[11].split(',') if n != '' ]
blocks = zip(block_sizes, block_starts)
payload['blocks'] = [ (start + block[1], start + block[1] + block[0]) for block in blocks]
except IndexError:
pass
if 'include_blocks' in kwargs:
try:
block_sizes = [ int(n) for n in feature[10].split(',') if n != '']
block_starts = [ int(n) for n in feature[11].split(',') if n != '' ]
blocks = zip(block_sizes, block_starts)
payload['blocks'] = [ (start + block[1], start + block[1] + block[0]) for block in blocks]
except IndexError:
pass
try:
payload['thick_start'] = int(feature[6])
payload['thick_end'] = int(feature[7])
except IndexError:
pass
try:
payload['thick_start'] = int(feature[6])
payload['thick_end'] = int(feature[7])
except IndexError:
pass
results.append(payload)
uid += 1
+96 -24
View File
@@ -1,9 +1,10 @@
/* Trackster
2009, James Taylor, Kanwei Li
*/
var DEBUG = false;
var DEBUG = true;
var DENSITY = 1000,
FEATURE_LEVELS = 100,
DATA_ERROR = "There was an error in indexing this dataset.",
DATA_NONE = "No data for this chrom/contig.",
DATA_PENDING = "Currently indexing... please wait",
@@ -108,6 +109,7 @@ $.extend( View.prototype, {
// 10^log10(range / DENSITY) Close approximation for browser window, assuming DENSITY = window width
this.resolution = Math.pow( 10, Math.ceil( Math.log( (this.high - this.low) / DENSITY ) / Math.LN10 ) );
this.zoom_res = Math.max(1,Math.ceil( Math.log( (this.high - this.low) / FEATURE_LEVELS ) / Math.log(FEATURE_LEVELS) ));
// Overview
$("#overview-box").css( {
@@ -171,7 +173,7 @@ $.extend( TiledTrack.prototype, Track.prototype, {
resolution = this.view.resolution;
if (DEBUG) { $("#debug").text(resolution); }
if (DEBUG) { $("#debug").text(resolution + " " + this.view.zoom_res); }
var parent_element = $("<div style='position: relative;'></div>");
this.content_div.children( ":first" ).remove();
@@ -279,7 +281,7 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
max_label.css({ position: "relative", top: "35px" });
max_label.prependTo(track.container_div)
min_label.css({ position: "relative", top: track.height_px + 32 + "px", });
min_label.css({ position: "relative", top: track.height_px + 32 + "px" });
min_label.prependTo(track.container_div);
track.draw();
@@ -297,7 +299,7 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
$.getJSON( data_url, { track_type: this.track_type, chrom: this.view.chrom,
low: low, high: high, dataset_id: this.dataset_id,
resolution: this.view.resolution }, function ( data ) {
track.cache[key] = data;
track.cache.set(key, data);
delete track.data_queue[key];
track.draw();
});
@@ -313,12 +315,12 @@ $.extend( LineTrack.prototype, TiledTrack.prototype, {
canvas = $("<canvas class='tile'></canvas>"),
key = resolution + "_" + tile_index;
if (!this.cache[key]) {
if (!this.cache.get(key)) {
this.get_data( resolution, tile_index );
return;
}
var data = this.cache[key];
var data = this.cache.get(key);
canvas.css( {
position: "absolute",
top: 0,
@@ -368,7 +370,11 @@ var FeatureTrack = function ( name, dataset_id, height ) {
this.showing_labels = false;
this.vertical_gap = 10;
this.base_color = "#2C3143";
this.default_font = "9px Monaco, Lucida Console, monospace";
this.left_offset = 200;
this.inc_slots = {};
this.data_queue = {};
this.data_cache = new Cache(20);
};
$.extend( FeatureTrack.prototype, TiledTrack.prototype, {
init: function() {
@@ -397,6 +403,23 @@ $.extend( FeatureTrack.prototype, TiledTrack.prototype, {
}
});
},
get_data: function( low, high ) {
console.log("getting: ", low, high);
var track = this,
key = low + '_' + high;
if (!track.data_queue[key]) {
track.data_queue[key] = true;
$.getJSON( data_url, { track_type: track.track_type, chrom: track.view.chrom,
low: low, high: high, dataset_id: track.dataset_id,
include_blocks: true }, function ( data ) {
track.data_cache.set(key, data);
// console.log("datacache", track.data_cache.get(key));
delete track.data_queue[key];
track.draw();
});
}
},
calc_slots: function( include_labels ) {
// console.log("num vals: " + this.values.length);
var end_ary = [],
@@ -438,27 +461,76 @@ $.extend( FeatureTrack.prototype, TiledTrack.prototype, {
this.height_px = end_ary.length * this.vertical_gap + 15;
this.content_div.css( "height", this.height_px + "px" );
},
draw_tile: function( resolution, tile_index, parent_element, w_scale ) {
if (!this.values) { // Still loading
return null;
incremental_slots: function( level, features ) {
if (!this.inc_slots[level]) {
this.inc_slots[level] = {};
this.inc_slots[level].w_scale = 1000 / Math.pow(FEATURE_LEVELS, level);
}
// console.log("drawing " + tile_index);
// Once we zoom in enough, show name labels
if (w_scale > this.show_labels_scale && !this.showing_labels) {
this.showing_labels = true;
if (!this.zi_slots) {
this.calc_slots(true);
}
this.slots = this.zi_slots;
} else if (w_scale <= this.show_labels_scale && this.showing_labels) {
this.showing_labels = false;
this.slots = this.zo_slots;
var slots = this.inc_slots[level];
if (slots[uid]) {
return slots[uid];
}
// console.log(this.slots);
var end_ary = [],
undone = [],
max_high = this.view.max_high,
max_low = this.view.max_low;
for (var i = 0, len = features.length; i < len; i++) {
var feature = features[i];
if (slots[feature.uid]) {
end_ary[ slots[feature.uid] ] = Math.ceil( (feature.end - max_low) * slots.w_scale );
} else {
undone.push(feature);
}
}
for (var i = 0, len = undone.length; i < len; i++) {
var feature = undone[i];
f_start = Math.floor( (feature.start - max_low) * slots.w_scale );
f_start -= dummy_canvas.measureText(feature.name).width;
f_end = Math.ceil( (feature.end - max_low) * slots.w_scale );
},
draw_tile: function( resolution, tile_index, parent_element, w_scale ) {
if (!this.values) {
return;
}
var tile_low = tile_index * DENSITY * resolution,
tile_high = ( tile_index + 1 ) * DENSITY * resolution,
tile_span = DENSITY * resolution;
// console.log("drawing " + tile_index);
// Once we zoom in enough, show name labels
var data;
if (w_scale > this.show_labels_scale) {
if (!this.showing_labels) {
this.showing_labels = true;
if (!this.zi_slots) {
this.calc_slots(true);
}
this.slots = this.zi_slots;
}
for (var k in this.data_cache.obj_cache) {
var k_split = k.split("_"), k_low = k_split[0], k_high = k_split[1];
if (k_low <= tile_low && k_high >= tile_high) {
data = this.data_cache.get(k);
break;
}
}
if (!data) {
this.data_queue[ [tile_low, tile_high] ] = true;
this.get_data(tile_low, tile_high);
return;
}
} else {
if (this.showing_labels) {
this.showing_labels = false;
this.slots = this.zo_slots;
}
data = this.values;
}
// console.log(this.slots);
// console.log(tile_low, tile_high, tile_length, w_scale);
var width = Math.ceil( tile_span * w_scale ),
height = this.height_px,
@@ -474,12 +546,12 @@ $.extend( FeatureTrack.prototype, TiledTrack.prototype, {
// console.log(( tile_low - this.view.low ) * w_scale, tile_index, w_scale);
var ctx = new_canvas.get(0).getContext("2d");
ctx.fillStyle = this.base_color;
ctx.font = "10px monospace";
ctx.font = this.default_font;
ctx.textAlign = "right";
var j = 0;
for (var i = 0, len = this.values.length; i < len; i++) {
var feature = this.values[i];
for (var i = 0, len = data.length; i < len; i++) {
var feature = data[i];
if (feature.start <= tile_high && feature.end >= tile_low) {
var f_start = Math.floor( Math.max(0, (feature.start - tile_low) * w_scale) ),
f_end = Math.ceil( Math.min(width, (feature.end - tile_low) * w_scale) ),
+6 -6
View File
@@ -31,15 +31,15 @@ threadpool_workers = 10
paste.app_factory = galaxy.web.buildapp:app_factory
# By default, Galaxy uses a SQLite database found here
#database_file = database/universe.sqlite
database_file = database/universe.sqlite
# You may use a SQLAlchemy connection string to specify an external database
# instead. PostgreSQL and MySQL are supported.
database_connection = postgres:///galaxy
database_engine_option_echo = true
database_engine_option_echo_pool = true
database_engine_option_pool_size = 10
database_engine_option_max_overflow = 20
#database_connection = postgres:///galaxy
#database_engine_option_echo = true
#database_engine_option_echo_pool = true
#database_engine_option_pool_size = 10
#database_engine_option_max_overflow = 20
# If using MySQL, see:
# http://rapd.wordpress.com/2008/03/02/sqlalchemy-sqlerror-operationalerror-2006-mysql-server-has-gone-away/