commit/galaxy-central: jgoecks: Trackster: dynamic filtering of read tracks.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/9fd9d437a65e/ changeset: 9fd9d437a65e user: jgoecks date: 2012-03-05 21:10:31 summary: Trackster: dynamic filtering of read tracks. affected #: 2 files diff -r 9cc7f3c1b07aea6093ccf1e4d4c6e45919a85cb4 -r 9fd9d437a65e0df9244a08ab50ae6dd1582bbc17 lib/galaxy/visualization/tracks/data_providers.py --- a/lib/galaxy/visualization/tracks/data_providers.py +++ b/lib/galaxy/visualization/tracks/data_providers.py @@ -2,8 +2,8 @@ Data providers for tracks visualizations. """ -import sys, time -from math import ceil, log, sqrt +import sys +from math import ceil, log import pkg_resources pkg_resources.require( "bx-python" ) if sys.version_info[:2] == (2, 4): @@ -569,11 +569,25 @@ # Check for data. return st.chrom_blocks.get(chrom, None) is not None or (chrom and st.chrom_blocks.get(chrom[3:], None) is not None) -class BamDataProvider( TracksDataProvider ): +class BamDataProvider( TracksDataProvider, FilterableMixin ): """ Provides access to intervals from a sorted indexed BAM file. """ + def get_filters( self ): + """ + Returns filters for dataset. + """ + # HACK: first 7 fields are for drawing, so start filter column index at 7. + filter_col = 7 + filters = [] + filters.append( { 'name': 'Mapping Quality', + 'type': 'number', + 'index': filter_col + } ) + return filters + + def write_data_to_file( self, chrom, start, end, filename ): """ Write reads in [chrom:start-end] to file. @@ -632,13 +646,15 @@ """ Returns a dict with the following attributes: data - a list of reads with the format - [<guid>, <start>, <end>, <name>, <read_1>, <read_2>] + [<guid>, <start>, <end>, <name>, <read_1>, <read_2>, [empty], <mapq_scores>] where <read_1> has the format - [<start>, <end>, <cigar>, <strand>, ?<read_seq>?] + [<start>, <end>, <cigar>, <strand>, <read_seq>] and <read_2> has the format - [<start>, <end>, <cigar>, <strand>, ?<read_seq>?] + [<start>, <end>, <cigar>, <strand>, <read_seq>] + Field 7 is empty so that mapq scores' location matches that in single-end reads. For single-end reads, read has format: - [<guid>, <start>, <end>, <name>, <cigar>, <strand>, <seq>] + [<guid>, <start>, <end>, <name>, <cigar>, <strand>, <seq>, <mapq_score>] + NOTE: read end and sequence data are not valid for reads outside of requested region and should not be used. @@ -692,14 +708,17 @@ read.pos + read_len, qname, [ pair['start'], pair['end'], pair['cigar'], pair['strand'], pair['seq'] ], - [ read.pos, read.pos + read_len, read.cigar, strand, seq ] + [ read.pos, read.pos + read_len, read.cigar, strand, seq ], + None, [ pair['mapq'], read.mapq ] ] ) del paired_pending[qname] else: paired_pending[qname] = { 'start': read.pos, 'end': read.pos + read_len, 'seq': seq, 'mate_start': read.mpos, - 'rlen': read_len, 'strand': strand, 'cigar': read.cigar } + 'rlen': read_len, 'strand': strand, 'cigar': read.cigar, 'mapq': read.mapq } else: - results.append( [ "%i_%s" % ( read.pos, qname ), read.pos, read.pos + read_len, qname, read.cigar, strand, read.seq] ) + results.append( [ "%i_%s" % ( read.pos, qname ), + read.pos, read.pos + read_len, qname, + read.cigar, strand, read.seq, [read.mapq, 125] ] ) # Take care of reads whose mates are out of range. # TODO: count paired reads when adhering to max_vals? @@ -721,7 +740,7 @@ r1 = [ read['start'], read['end'], read['cigar'], read['strand'], read['seq'] ] r2 = [ read['mate_start'], read['mate_start'] ] - results.append( [ "%i_%s" % ( read_start, qname ), read_start, read_end, qname, r1, r2 ] ) + results.append( [ "%i_%s" % ( read_start, qname ), read_start, read_end, qname, r1, r2, [read[ 'mapq' ], 125] ] ) # Clean up. TODO: is this needed? If so, we'll need a cleanup function after processing the data. # bamfile.close() diff -r 9cc7f3c1b07aea6093ccf1e4d4c6e45919a85cb4 -r 9fd9d437a65e0df9244a08ab50ae6dd1582bbc17 static/scripts/trackster.js --- a/static/scripts/trackster.js +++ b/static/scripts/trackster.js @@ -2427,7 +2427,13 @@ return false; }, /** - * Returns true if (a) element's value is in [low, high] (range is inclusive) + * Helper function: returns true if value in in filter's [low, high] range. + */ + _keep_val: function(val) { + return (isNaN(val) || (val >= this.low && val <= this.high)); + }, + /** + * Returns true if (a) element's value(s) is in [low, high] (range is inclusive) * or (b) if value is non-numeric and hence unfilterable. */ keep: function(element) { @@ -2435,8 +2441,26 @@ // No element to filter on. return true; } - var val = element[this.index]; - return (isNaN(val) || (val >= this.low && val <= this.high)); + + // Keep value function. + var filter = this; + + // Do filtering. + var to_filter = element[this.index]; + if (to_filter instanceof Array) { + var returnVal = true; + for (var i = 0; i < to_filter.length; i++) { + if (!this._keep_val(to_filter[i])) { + // Exclude element. + returnVal = false; + break; + } + } + return returnVal; + } + else { + return this._keep_val(element[this.index]); + } }, /** * Update filter's min and max values based on element's values. 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