details: http://www.bx.psu.edu/hg/galaxy/rev/5f59c890ee8d changeset: 3744:5f59c890ee8d user: jeremy goecks <jeremy.goecks@emory.edu> date: Tue May 04 22:27:05 2010 -0400 description: Fix bug that mucked up fetch for chrom lengths in new track browsers. diffstat: lib/galaxy/web/controllers/tracks.py | 32 ++++++++++++++++++++------------ templates/tracks/browser.mako | 7 ++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diffs (76 lines): diff -r b5c76e1a28ea -r 5f59c890ee8d lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py Tue May 04 21:57:26 2010 -0400 +++ b/lib/galaxy/web/controllers/tracks.py Tue May 04 22:27:05 2010 -0400 @@ -158,9 +158,9 @@ return trans.fill_template( 'tracks/browser.mako', config=config ) @web.json - def chroms(self, trans, vis_id=None ): + def chroms(self, trans, vis_id=None, dbkey=None ): """ - Returns a naturally sorted list of chroms/contigs for the given dbkey + Returns a naturally sorted list of chroms/contigs for either a given visualization or a given dbkey. """ def check_int(s): if s.isdigit(): @@ -171,25 +171,33 @@ def split_by_number(s): return [ check_int(c) for c in re.split('([0-9]+)', s) ] - # Get visualization and config. - visualization = self.get_visualization( trans, vis_id, check_ownership=False, check_accessible=True ) - visualization.config = self.get_visualization_config( trans, visualization ) - if visualization is None: - raise web.httpexceptions.HTTPNotFound() + # Must specify either vis_id or dbkey. + if not vis_id and not dbkey: + return trans.show_error_message("No visualization id or dbkey specified.") + + # Need to get user and dbkey in order to get chroms data. + if vis_id: + # Use user, dbkey from viz. + visualization = self.get_visualization( trans, vis_id, check_ownership=False, check_accessible=True ) + visualization.config = self.get_visualization_config( trans, visualization ) + vis_user = visualization.user + vis_dbkey = visualization.config['dbkey'] + else: + # No vis_id, so visualization is new. User is current user, dbkey must be given. + vis_user = trans.user + vis_dbkey = dbkey # Get chroms data. - chroms = self._chroms( trans, visualization ) + chroms = self._chroms( trans, vis_user, vis_dbkey ) to_sort = [{ 'chrom': chrom, 'len': length } for chrom, length in chroms.iteritems()] to_sort.sort(lambda a,b: cmp( split_by_number(a['chrom']), split_by_number(b['chrom']) )) return to_sort - def _chroms( self, trans, visualization ): + def _chroms( self, trans, user, dbkey ): """ - Called by the browser to get a list of valid chromosomes and lengths + Helper method that returns chrom lengths for a given user and dbkey. """ # If there is any dataset in the history of extension `len`, this will use it - user = visualization.user - dbkey = visualization.config['dbkey'] if 'dbkeys' in user.preferences: user_keys = from_json_string( user.preferences['dbkeys'] ) if dbkey in user_keys: diff -r b5c76e1a28ea -r 5f59c890ee8d templates/tracks/browser.mako --- a/templates/tracks/browser.mako Tue May 04 21:57:26 2010 -0400 +++ b/templates/tracks/browser.mako Tue May 04 22:27:05 2010 -0400 @@ -272,7 +272,12 @@ $.ajax({ url: "${h.url_for( action='chroms' )}", - data: { vis_id: view.vis_id }, + ## If vis is new, it doesn't have an id, so send the dbkey instead. + %if config.get('vis_id'): + data: { vis_id: view.vis_id }, + %else: + data: { dbkey: view.dbkey }, + %endif dataType: "json", success: function ( data ) { view.chrom_data = data;