This commit is contained in:
Dannon Baker
2012-08-21 10:52:33 -04:00
11 changed files with 124 additions and 179 deletions
@@ -0,0 +1,14 @@
<tool id="CONVERTER_bedgraph_to_bigwig" name="Convert BedGraph to BigWig" hidden="true">
<!-- Used internally to generate track indexes -->
<command>grep -v "^track" $input | wigToBigWig -clip stdin $chromInfo $output</command>
<inputs>
<page>
<param format="bedgraph" name="input" type="data" label="Choose wiggle"/>
</page>
</inputs>
<outputs>
<data format="bigwig" name="output"/>
</outputs>
<help>
</help>
</tool>
+48 -44
View File
@@ -6,48 +6,52 @@ import sys
from galaxy import eggs
from galaxy.datatypes.util.gff_util import read_unordered_gtf, convert_gff_coords_to_bed
# Process arguments.
in_fname = sys.argv[1]
out_fname = sys.argv[2]
def main():
# Process arguments.
in_fname = sys.argv[1]
out_fname = sys.argv[2]
# Create dict of name-location pairings.
name_loc_dict = {}
for feature in read_unordered_gtf( open( in_fname, 'r' ) ):
for name in feature.attributes:
val = feature.attributes[ name ]
try:
float( val )
continue
except:
convert_gff_coords_to_bed( feature )
# Value is not a number, so it can be indexed.
if val not in name_loc_dict:
# Value is not in dictionary.
name_loc_dict[ val ] = {
'contig': feature.chrom,
'start': feature.start,
'end': feature.end
}
else:
# Value already in dictionary, so update dictionary.
loc = name_loc_dict[ val ]
if feature.start < loc[ 'start' ]:
loc[ 'start' ] = feature.start
if feature.end > loc[ 'end' ]:
loc[ 'end' ] = feature.end
# Print name, loc in sorted order.
out = open( out_fname, 'w' )
max_len = 0
entries = []
for name in sorted( name_loc_dict.iterkeys() ):
loc = name_loc_dict[ name ]
entry = '%s\t%s' % ( name, '%s:%i-%i' % ( loc[ 'contig' ], loc[ 'start' ], loc[ 'end' ] ) )
if len( entry ) > max_len:
max_len = len( entry )
entries.append( entry )
out.write( str( max_len + 1 ).ljust( max_len ) + '\n' )
for entry in entries:
out.write( entry.ljust( max_len ) + '\n' )
out.close()
# Create dict of name-location pairings.
name_loc_dict = {}
for feature in read_unordered_gtf( open( in_fname, 'r' ) ):
for name in feature.attributes:
val = feature.attributes[ name ]
try:
float( val )
continue
except:
convert_gff_coords_to_bed( feature )
# Value is not a number, so it can be indexed.
if val not in name_loc_dict:
# Value is not in dictionary.
name_loc_dict[ val ] = {
'contig': feature.chrom,
'start': feature.start,
'end': feature.end
}
else:
# Value already in dictionary, so update dictionary.
loc = name_loc_dict[ val ]
if feature.start < loc[ 'start' ]:
loc[ 'start' ] = feature.start
if feature.end > loc[ 'end' ]:
loc[ 'end' ] = feature.end
# Print name, loc in sorted order.
out = open( out_fname, 'w' )
max_len = 0
entries = []
for name in sorted( name_loc_dict.iterkeys() ):
loc = name_loc_dict[ name ]
entry = '%s\t%s' % ( name, '%s:%i-%i' % ( loc[ 'contig' ], loc[ 'start' ], loc[ 'end' ] ) )
if len( entry ) > max_len:
max_len = len( entry )
entries.append( entry )
out.write( str( max_len + 1 ).ljust( max_len ) + '\n' )
for entry in entries:
out.write( entry.ljust( max_len ) + '\n' )
out.close()
if __name__ == '__main__':
main()
@@ -1,6 +1,6 @@
<tool id="CONVERTER_wig_to_bigwig" name="Convert Wiggle to BigWig" hidden="true">
<!-- Used internally to generate track indexes -->
<command>wigToBigWig $input $chromInfo $output</command>
<command>grep -v "^track" $input | wigToBigWig -clip stdin $chromInfo $output</command>
<inputs>
<page>
<param format="wig" name="input" type="data" label="Choose wiggle"/>
+3 -2
View File
@@ -338,7 +338,7 @@ class BedGraph( Interval ):
file_ext = "bedgraph"
def get_track_type( self ):
return "LineTrack", {"data": "array_tree"}
return "LineTrack", { "data": "bigwig", "index": "bigwig" }
def as_ucsc_display_file( self, dataset, **kwd ):
"""
@@ -1141,8 +1141,9 @@ class Wiggle( Tabular, _RemoteCallMixin ):
resolution = min( resolution, 100000 )
resolution = max( resolution, 1 )
return resolution
def get_track_type( self ):
return "LineTrack", {"data": "bigwig", "index": "bigwig"}
return "LineTrack", { "data": "bigwig", "index": "bigwig" }
class CustomTrack ( Tabular ):
"""UCSC CustomTrack"""
+4 -3
View File
@@ -264,10 +264,10 @@ class Tabular( data.Text ):
def display_data(self, trans, dataset, preview=False, filename=None, to_ext=None, chunk=None):
#TODO Prevent failure when displaying extremely long > 50kb lines.
if to_ext or not preview:
return self._serve_raw(trans, dataset, to_ext)
if chunk:
return self.get_chunk(trans, dataset, chunk)
if to_ext or not preview:
return self._serve_raw(trans, dataset, to_ext)
else:
column_names = 'null'
if dataset.metadata.column_names:
@@ -644,4 +644,5 @@ class FeatureLocationIndex( Tabular ):
"""
file_ext='fli'
MetadataElement( name="columns", default=2, desc="Number of columns", readonly=True, visible=False )
MetadataElement( name="column_types", default=['str', 'str'], param=metadata.ColumnTypesParameter, desc="Column types", readonly=True, visible=False, no_value=[] )
MetadataElement( name="column_types", default=['str', 'str'], param=metadata.ColumnTypesParameter, desc="Column types", readonly=True, visible=False, no_value=[] )
+6 -12
View File
@@ -490,7 +490,6 @@ class JobWrapper( object ):
if stderr contains anything, then False is returned.
Note that the job id is just for messages.
"""
err_msg = ""
# By default, the tool succeeded. This covers the case where the code
# has a bug but the tool was ok, and it lets a workflow continue.
success = True
@@ -507,7 +506,7 @@ class JobWrapper( object ):
# Check the exit code ranges in the order in which
# they were specified. Each exit_code is a StdioExitCode
# that includes an applicable range. If the exit code was in
# that range, then apply the error level and add in a message.
# that range, then apply the error level and add a message.
# If we've reached a fatal error rule, then stop.
max_error_level = galaxy.tools.StdioErrorLevel.NO_ERROR
for stdio_exit_code in self.tool.stdio_exit_codes:
@@ -515,20 +514,16 @@ class JobWrapper( object ):
tool_exit_code <= stdio_exit_code.range_end ):
# Tack on a generic description of the code
# plus a specific code description. For example,
# this might append "Job 42: Warning: Out of Memory\n".
# TODO: Find somewhere to stick the err_msg -
# possibly to the source (stderr/stdout), possibly
# in a new db column.
# this might prepend "Job 42: Warning: Out of Memory\n".
code_desc = stdio_exit_code.desc
if ( None == code_desc ):
code_desc = ""
tool_msg = ( "Job %s: %s: Exit code %d: %s" % (
job.get_id_tag(),
galaxy.tools.StdioErrorLevel.desc( tool_exit_code ),
tool_msg = ( "%s: Exit code %d: %s" % (
galaxy.tools.StdioErrorLevel.desc( stdio_exit_code.error_level ),
tool_exit_code,
code_desc ) )
log.info( tool_msg )
stderr = err_msg + stderr
log.info( "Job %s: %s" % (job.get_id_tag(), tool_msg) )
stderr = tool_msg + "\n" + stderr
max_error_level = max( max_error_level,
stdio_exit_code.error_level )
if ( max_error_level >=
@@ -571,7 +566,6 @@ class JobWrapper( object ):
re.IGNORECASE )
if ( regex_match ):
rexmsg = self.regex_err_msg( regex_match, regex)
# DELETEME
log.info( "Job %s: %s"
% ( job.get_id_tag(), rexmsg ) )
stderr = rexmsg + "\n" + stderr
+1 -1
View File
@@ -2631,7 +2631,7 @@ class Tool:
if for_link:
# Create tool link.
if not self.tool_type.startswith( 'data_source' ):
link = url_for( controller='tool_runner', tool_id=self.id )
link = url_for( '/tool_runner', tool_id=self.id )
else:
link = url_for( self.action, **self.get_static_param_values( trans ) )
@@ -968,29 +968,32 @@ class BBIDataProvider( TracksDataProvider ):
# which we use converted_dataset
f, bbi = self._get_dataset()
# If the stats kwarg was provide, we compute overall summary data for the
# range defined by start and end but no reduced data. This is currently
# used by client to determine the default range.
# If stats requested, compute overall summary data for the range
# start:endbut no reduced data. This is currently used by client
# to determine the default range.
if 'stats' in kwargs:
summary = bbi.summarize( chrom, start, end, 1 )
f.close()
if summary is None:
return None
else:
min = 0
max = 0
mean = 0
sd = 0
if summary is not None:
# Does the summary contain any defined values?
valid_count = summary.valid_count[0]
if summary.valid_count < 1:
return None
if summary.valid_count > 0:
# Compute $\mu \pm 2\sigma$ to provide an estimate for upper and lower
# bounds that contain ~95% of the data.
mean = summary.sum_data[0] / valid_count
var = summary.sum_squares[0] - mean
if valid_count > 1:
var /= valid_count - 1
sd = numpy.sqrt( var )
min = summary.min_val[0]
max = summary.max_val[0]
# Compute $\mu \pm 2\sigma$ to provide an estimate for upper and lower
# bounds that contain ~95% of the data.
mean = summary.sum_data[0] / valid_count
var = summary.sum_squares[0] - mean
if valid_count > 1:
var /= valid_count - 1
sd = numpy.sqrt( var )
return dict( data=dict( min=summary.min_val[0], max=summary.max_val[0], mean=mean, sd=sd ) )
return dict( data=dict( min=min, max=max, mean=mean, sd=sd ) )
# Sample from region using approximately this many samples.
N = 1000
+15 -1
View File
@@ -387,7 +387,21 @@ class TracksController( BaseUIController, UsesVisualizationMixin, UsesHistoryDat
return return_message
extra_info = None
if 'index' in data_sources and data_sources['index']['name'] == "summary_tree" and kwargs.get("mode", "Auto") == "Auto":
mode = kwargs.get( "mode", "Auto" )
# Handle histogram mode uniquely for now:
if mode == "Coverage":
# Get summary using minimal cutoffs.
tracks_dataset_type = data_sources['index']['name']
converted_dataset = dataset.get_converted_dataset( trans, tracks_dataset_type )
indexer = get_data_provider( tracks_dataset_type )( converted_dataset, dataset )
summary = indexer.get_data( chrom, low, high, resolution=kwargs[ 'resolution' ], detail_cutoff=0, draw_cutoff=0 )
if summary == "detail":
# Use maximum level of detail--2--to get summary data no matter the resolution.
summary = indexer.get_data( chrom, low, high, resolution=kwargs[ 'resolution' ], level=2, detail_cutoff=0, draw_cutoff=0 )
frequencies, max_v, avg_v, delta = summary
return { 'dataset_type': tracks_dataset_type, 'data': frequencies, 'max': max_v, 'avg': avg_v, 'delta': delta }
if 'index' in data_sources and data_sources['index']['name'] == "summary_tree" and mode == "Auto":
# Only check for summary_tree if it's Auto mode (which is the default)
#
# Have to choose between indexer and data provider
+12 -97
View File
@@ -4433,7 +4433,7 @@ var FeatureTrack = function(view, container, obj_dict) {
// initialization code.
//
var track = this;
this.display_modes = ["Auto", "Histogram", "Dense", "Squish", "Pack"];
this.display_modes = ["Auto", "Coverage", "Dense", "Squish", "Pack"];
//
// Initialization.
@@ -4516,8 +4516,8 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
var track = this,
i;
// If mode is Histogram and tiles do not share max, redraw tiles as necessary using new max.
if (track.mode === "Histogram") {
// If mode is Coverage and tiles do not share max, redraw tiles as necessary using new max.
if (track.mode === "Coverage") {
// Get global max.
var global_max = -1;
for (i = 0; i < tiles.length; i++) {
@@ -4534,7 +4534,7 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
track.draw_helper(true, width, tile.index, tile.resolution, tile.html_elt.parent(), w_scale, { more_tile_data: { max: global_max } } );
}
}
}
}
//
// Update filter attributes, UI.
@@ -4649,86 +4649,6 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
return slotter.slot_features( features );
},
/**
* Given feature data, returns summary tree data. Feature data must be sorted by start
* position. Return value is a dict with keys 'data', 'delta' (bin size) and 'max.' Data
* is a two-item list; first item is bin start, second is bin's count.
*/
get_summary_tree_data: function(data, low, high, num_bins) {
if (num_bins > high - low) {
num_bins = high - low;
}
var bin_size = Math.floor((high - low)/num_bins),
bins = [],
max_count = 0;
/*
// For debugging:
for (var i = 0; i < data.length; i++)
console.log("\t", data[i][1], data[i][2], data[i][3]);
*/
//
// Loop through bins, counting data for each interval.
//
var data_index_start = 0,
data_index = 0,
data_interval,
bin_index = 0,
bin_interval = [],
cur_bin;
// Set bin interval.
var set_bin_interval = function(interval, low, bin_index, bin_size) {
interval[0] = low + bin_index * bin_size;
interval[1] = low + (bin_index + 1) * bin_size;
};
// Loop through bins, data to compute bin counts. Only compute bin counts as long
// as there is data.
while (bin_index < num_bins && data_index_start !== data.length) {
// Find next bin that has data.
var bin_has_data = false;
for (; bin_index < num_bins && !bin_has_data; bin_index++) {
set_bin_interval(bin_interval, low, bin_index, bin_size);
// Loop through data and break if data found that goes in bin.
for (data_index = data_index_start; data_index < data.length; data_index++) {
data_interval = data[data_index].slice(1, 3);
if (is_overlap(data_interval, bin_interval)) {
bin_has_data = true;
break;
}
}
// Break from bin loop if this bin has data.
if (bin_has_data) {
break;
}
}
// Set start index to current data, which is the first to overlap with this bin
// and perhaps with later bins.
data_start_index = data_index;
// Count intervals that overlap with bin.
bins[bins.length] = cur_bin = [bin_interval[0], 0];
for (; data_index < data.length; data_index++) {
data_interval = data[data_index].slice(1, 3);
if (is_overlap(data_interval, bin_interval)) {
cur_bin[1]++;
}
else { break; }
}
// Update max count.
if (cur_bin[1] > max_count) {
max_count = cur_bin[1];
}
// Go to next bin.
bin_index++;
}
return {max: max_count, delta: bin_size, data: bins};
},
/**
* Returns appropriate display mode based on data.
*/
@@ -4766,8 +4686,7 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
* number of pixels required.
*/
get_canvas_height: function(result, mode, w_scale, canvas_width) {
if (mode === "summary_tree" || mode === "Histogram") {
// Extra padding at top of summary tree so label does not overlap data.
if (mode === "summary_tree" || mode === "Coverage") {
return this.summary_draw_height;
}
else {
@@ -4796,16 +4715,8 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
tile_high = region.get('end'),
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;
}
// Drawing the summary tree.
if (mode === "summary_tree" || mode === "Coverage") {
// 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);
@@ -4872,7 +4783,11 @@ extend(FeatureTrack.prototype, Drawable.prototype, TiledTrack.prototype, {
if (mode === "Auto") {
return true;
}
// All other modes--Histogram, Dense, Squish, Pack--require data + details.
// Histogram mode requires summary_tree data.
else if (mode === "Coverage") {
return data.dataset_type === "summary_tree";
}
// All other modes--Dense, Squish, Pack--require data + details.
else if (data.extra_info === "no_detail" || data.dataset_type === "summary_tree") {
return false;
}
-1
View File
@@ -250,7 +250,6 @@ $(function() {
},
"View in saved visualization": function() {
// Show new modal with saved visualizations.
parent.hide_modal();
parent.show_modal("Add Data to Saved Visualization", table_html, {
"Cancel": function() {
parent.hide_modal();