commit/galaxy-central: jgoecks: Enable interval datasets to be visualized in trackster.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/7d6c2846c3c1/ changeset: 7d6c2846c3c1 user: jgoecks date: 2012-04-18 22:59:14 summary: Enable interval datasets to be visualized in trackster. affected #: 3 files diff -r fbb7d4250604ddd0ed2c2006ab6601e6e973bd72 -r 7d6c2846c3c11157d05beb4f216d4efe5abd443f lib/galaxy/datatypes/interval.py --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -328,6 +328,9 @@ def get_track_resolution( self, dataset, start, end): return None + + def get_track_type( self ): + return "FeatureTrack", {"data": "tabix", "index": "summary_tree"} class BedGraph( Interval ): """Tab delimited chrom/start/end/datavalue dataset""" diff -r fbb7d4250604ddd0ed2c2006ab6601e6e973bd72 -r 7d6c2846c3c11157d05beb4f216d4efe5abd443f lib/galaxy/visualization/tracks/data_providers.py --- a/lib/galaxy/visualization/tracks/data_providers.py +++ b/lib/galaxy/visualization/tracks/data_providers.py @@ -19,7 +19,7 @@ from galaxy.visualization.tracks.summary import * import galaxy_utils.sequence.vcf from galaxy.datatypes.tabular import Vcf -from galaxy.datatypes.interval import Bed, Gff, Gtf, ENCODEPeak +from galaxy.datatypes.interval import Interval, Bed, Gff, Gtf, ENCODEPeak from pysam import csamtools, ctabix @@ -67,8 +67,7 @@ """ Write data in region defined by chrom, start, and end to a file. """ - # Override. - pass + raise Exception( "Unimplemented Function" ) def valid_chroms( self ): """ @@ -81,23 +80,19 @@ Returns true if dataset has data in the specified genome window, false otherwise. """ - # Override. - pass + raise Exception( "Unimplemented Function" ) def get_iterator( self, chrom, start, end ): """ Returns an iterator that provides data in the region chrom:start-end """ - # Override. - pass + raise Exception( "Unimplemented Function" ) def process_data( self, iterator, start_val=0, max_vals=None, **kwargs ): """ Process data from an iterator to a format that can be provided to client. """ - # Override. - pass - + raise Exception( "Unimplemented Function" ) def get_data( self, chrom, start, end, start_val=0, max_vals=sys.maxint, **kwargs ): """ @@ -270,18 +265,96 @@ out.close() # +# -- Interval data providers -- +# + +class IntervalDataProvider( TracksDataProvider ): + """ + Processes BED data from native format to payload format. + + Payload format: [ uid (offset), start, end, name, strand, thick_start, thick_end, blocks ] + """ + + def get_iterator( self, chrom, start, end ): + raise Exception( "Unimplemented Function" ) + + def process_data( self, iterator, start_val=0, max_vals=None, **kwargs ): + """ + Provides + """ + # Build data to return. Payload format is: + # [ <guid/offset>, <start>, <end>, <name>, <strand> ] + # + # First three entries are mandatory, others are optional. + # + filter_cols = from_json_string( kwargs.get( "filter_cols", "[]" ) ) + no_detail = ( "no_detail" in kwargs ) + rval = [] + message = None + # Subtract one b/c columns are 1-based but indices are 0-based. + col_fn = lambda col: None if col is None else col - 1 + start_col = self.original_dataset.metadata.startCol - 1 + end_col = self.original_dataset.metadata.endCol - 1 + strand_col = col_fn( self.original_dataset.metadata.strandCol ) + name_col = col_fn( self.original_dataset.metadata.nameCol ) + for count, line in enumerate( iterator ): + if count < start_val: + continue + if max_vals and count-start_val >= max_vals: + message = ERROR_MAX_VALS % ( max_vals, "features" ) + break + + feature = line.split() + length = len(feature) + # Unique id is just a hash of the line + payload = [ hash(line), int( feature[start_col] ), int( feature [end_col] ) ] + + if no_detail: + rval.append( payload ) + continue + + # Name, strand. + if name_col: + payload.append( feature[name_col] ) + if strand_col: + # Put empty name as placeholder. + if not name_col: payload.append( "" ) + payload.append( feature[strand_col] ) + + # Score (filter data) + if length >= 5 and filter_cols and filter_cols[0] == "Score": + try: + payload.append( float( feature[4] ) ) + except: + payload.append( feature[4] ) + + rval.append( payload ) + + return { 'data': rval, 'message': message } + + def write_data_to_file( self, chrom, start, end, filename ): + raise Exception( "Unimplemented Function" ) + +class IntervalTabixDataProvider( TabixDataProvider, IntervalDataProvider ): + """ + Provides data from a BED file indexed via tabix. + """ + pass + + +# # -- BED data providers -- # class BedDataProvider( TracksDataProvider ): """ - Abstract class that processes BED data from native format to payload format. + Processes BED data from native format to payload format. Payload format: [ uid (offset), start, end, name, strand, thick_start, thick_end, blocks ] """ def get_iterator( self, chrom, start, end ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def process_data( self, iterator, start_val=0, max_vals=None, **kwargs ): """ @@ -359,7 +432,7 @@ Provides data from a BED file indexed via tabix. """ pass - + class RawBedDataProvider( BedDataProvider ): """ Provide data from BED file. @@ -1113,7 +1186,12 @@ # type. First key is converted dataset type; if result is another dict, second key # is original dataset type. TODO: This needs to be more flexible. dataset_type_name_to_data_provider = { - "tabix": { Vcf: VcfTabixDataProvider, Bed: BedTabixDataProvider, ENCODEPeak: ENCODEPeakTabixDataProvider, "default" : TabixDataProvider }, + "tabix": { + Vcf: VcfTabixDataProvider, + Bed: BedTabixDataProvider, + ENCODEPeak: ENCODEPeakTabixDataProvider, + Interval: IntervalTabixDataProvider, + "default" : TabixDataProvider }, "interval_index": IntervalIndexDataProvider, "bai": BamDataProvider, "bam": SamDataProvider, diff -r fbb7d4250604ddd0ed2c2006ab6601e6e973bd72 -r 7d6c2846c3c11157d05beb4f216d4efe5abd443f static/scripts/trackster.js --- a/static/scripts/trackster.js +++ b/static/scripts/trackster.js @@ -5655,7 +5655,7 @@ // -1 because end is not included in feature; see FeaturePainter documentation for details. feature_end = feature[2] - 1, feature_name = feature[3], - feature_strand = (feature.length > 4 ? feature[4] : null), + feature_strand = feature[4], f_start = Math.floor( Math.max(0, (feature_start - tile_low) * w_scale) ), f_end = Math.ceil( Math.min(width, Math.max(0, (feature_end - tile_low) * w_scale)) ), draw_start = f_start, 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