From 78365cdec04ba1ccdb97216ca1cb22c78cfa4df1 Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Mon, 21 Jan 2013 14:06:46 -0500 Subject: [PATCH] make location-choice dialog show what track(s(s) are associated with each location --- src/JBrowse/Browser.js | 5 +++-- src/JBrowse/Store/Hash.js | 2 ++ src/JBrowse/Store/Names/Hash.js | 20 +++++++++++++++++++- src/JBrowse/View/LocationList.js | 13 +++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/JBrowse/Browser.js b/src/JBrowse/Browser.js index 51820b1cea..938c7539ad 100644 --- a/src/JBrowse/Browser.js +++ b/src/JBrowse/Browser.js @@ -365,12 +365,13 @@ Browser.prototype.loadNames = function() { conf.url = Util.resolveUrl( conf.baseUrl, conf.url ); if( conf.type == 'Hash' ) - this.nameStore = new NamesHashStore( conf ); + this.nameStore = new NamesHashStore( dojo.mixin({ browser: this }, conf) ); else // wrap the older LazyTrieDojoDataStore with // dojo.store.DataStore to conform with the dojo/store API this.nameStore = new DojoDataStore({ store: new NamesLazyTrieDojoDataStore({ + browser: this, namesTrie: new LazyTrie( conf.url, "lazy-{Chunk}.json"), stopPrefixes: conf.stopPrefixes, resultLimit: conf.resultLimit || 15, @@ -1293,7 +1294,7 @@ Browser.prototype.showRegion = function( location ) { // if the location has a track associated with it, show it if( location.tracks ) { - this.showTracks( location.tracks ); + this.showTracks( array.map( location.tracks, function( t ) { return t && (t.label || t.name) || t; } )); } }; diff --git a/src/JBrowse/Store/Hash.js b/src/JBrowse/Store/Hash.js index a456c866c4..a4daee96b8 100644 --- a/src/JBrowse/Store/Hash.js +++ b/src/JBrowse/Store/Hash.js @@ -26,6 +26,8 @@ return declare( null, { this.meta = {}; + this.browser = args.browser; + // this.ready is a Deferred that will be resolved when we have // read the meta.json file with the params of this hashstore this.ready = this._readMeta(); diff --git a/src/JBrowse/Store/Names/Hash.js b/src/JBrowse/Store/Names/Hash.js index c24ddb243b..f61dc9805a 100644 --- a/src/JBrowse/Store/Names/Hash.js +++ b/src/JBrowse/Store/Names/Hash.js @@ -49,11 +49,12 @@ return declare( HashStore, var item = {}; if( typeof nameRecord == 'object' ) { item.name = nameRecord[0]; + var trackConfig = this._findTrackConfig( ((this.meta||{}).track_names||{})[ nameRecord[1] ] ); item.location = new Location({ ref: nameRecord[3], start: parseInt( nameRecord[4] ), end: parseInt( nameRecord[5] ), - tracks: [ ((this.meta||{}).track_names||{})[ nameRecord[1] ] ] + tracks: [ trackConfig ] }); } else { item.name = nameRecord; @@ -62,6 +63,23 @@ return declare( HashStore, } }, + // look in the browser's track configuration for the track with the given label + _findTrackConfig: function( trackLabel ) { + if( ! trackLabel ) + return null; + + var track = null; + var i = array.some( this.browser.config.tracks, function( t ) { + if( t.label == trackLabel ) { + track = t; + return true; + } + return false; + }); + + return track; + }, + _makeResults: function( nameRecords ) { // convert the name records into dojo.store-compliant data // items, sort them by name and location diff --git a/src/JBrowse/View/LocationList.js b/src/JBrowse/View/LocationList.js index 29f905b90f..28ec43ee52 100644 --- a/src/JBrowse/View/LocationList.js +++ b/src/JBrowse/View/LocationList.js @@ -32,6 +32,19 @@ return declare(null,{ { label: 'End', field: 'end' } ]; + if( args.locations && args.locations.length && args.locations[0].tracks ) + columns.push({ + label: 'Track', + field: 'tracks', + formatter: function(tracks) { + return array.map( array.filter( tracks, function(t) { return t; }), // remove nulls + function(t) { + return t.key || t.name || t.label || t; + }) + .join(', '); + } + }); + if( array.some( args.locations || [], function(l) { return l.label; }) ) { columns.unshift( { label: 'Name', field: 'label' } ); }