commit/galaxy-central: jgoecks: Viz framework refactoring: move visualization view methods into base class and move chromosome/reference data methods to API.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/0d077bcf9ab7/ changeset: 0d077bcf9ab7 user: jgoecks date: 2012-09-14 23:57:07 summary: Viz framework refactoring: move visualization view methods into base class and move chromosome/reference data methods to API. affected #: 8 files diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 lib/galaxy/web/api/genomes.py --- a/lib/galaxy/web/api/genomes.py +++ b/lib/galaxy/web/api/genomes.py @@ -2,13 +2,16 @@ from galaxy.web.base.controller import BaseController, BaseAPIController from galaxy.util.bunch import Bunch +def is_true ( a_str ): + return is_true == True or a_str in [ 'True', 'true', 'T', 't' ] + class GenomesController( BaseAPIController ): """ RESTful controller for interactions with genome data. """ @web.expose_api - def index( self, trans, **kwds ): + def index( self, trans, **kwd ): """ GET /api/genomes: returns a list of installed genomes """ @@ -16,13 +19,23 @@ return [] @web.json - def show( self, trans, id, num=None, chrom=None, low=None ): + def show( self, trans, id, num=None, chrom=None, low=None, high=None, **kwd ): """ GET /api/genomes/{id} Returns information about build <id> """ - return self.app.genomes.chroms( trans, dbkey=id, num=num, chrom=chrom, low=low ) + + # Process kwds. + reference = is_true( kwd.get( 'reference', False ) ) + + # Return info. + rval = None + if reference: + rval = self.app.genomes.reference( trans, dbkey=id, chrom=chrom, low=low, high=high, **kwd ) + else: + rval = self.app.genomes.chroms( trans, dbkey=id, num=num, chrom=chrom, low=low ) + return rval @web.expose_api def create( self, trans, payload, **kwd ): diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -626,6 +626,29 @@ return visualization + def _get_datasources( self, trans, dataset ): + """ + Returns datasources for dataset; if datasources are not available + due to indexing, indexing is started. Return value is a dictionary + with entries of type + (<datasource_type> : {<datasource_name>, <indexing_message>}). + """ + track_type, data_sources = dataset.datatype.get_track_type() + data_sources_dict = {} + msg = None + for source_type, data_source in data_sources.iteritems(): + if source_type == "data_standalone": + # Nothing to do. + msg = None + else: + # Convert. + msg = self.convert_dataset( trans, dataset, data_source ) + + # Store msg. + data_sources_dict[ source_type ] = { "name" : data_source, "message": msg } + + return data_sources_dict + class UsesStoredWorkflowMixin( SharableItemSecurityMixin ): """ Mixin for controllers that use StoredWorkflow objects. """ def get_stored_workflow( self, trans, id, check_ownership=True, check_accessible=False ): diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -17,7 +17,7 @@ from galaxy.visualization.genomes import decode_dbkey, Genomes from galaxy.visualization.genome.visual_analytics import get_dataset_job -class TracksController( BaseUIController, UsesVisualizationMixin, UsesHistoryDatasetAssociationMixin, SharableMixin ): +class TracksController( BaseUIController, UsesVisualizationMixin, SharableMixin ): """ Controller for track browser interface. Handles building a new browser from datasets in the current history, and display of the resulting browser. @@ -34,28 +34,6 @@ @web.require_login() def new_browser( self, trans, **kwargs ): return trans.fill_template( "tracks/new_browser.mako", dbkeys=trans.app.genomes.get_dbkeys_with_chrom_info( trans ), default_dbkey=kwargs.get("default_dbkey", None) ) - - @web.json - def bookmarks_from_dataset( self, trans, hda_id=None, ldda_id=None ): - if hda_id: - hda_ldda = "hda" - dataset_id = hda_id - elif ldda_id: - hda_ldda = "ldda" - dataset_id = ldda_id - dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) - - rows = [] - if isinstance( dataset.datatype, Bed ): - data = RawBedDataProvider( original_dataset=dataset ).get_iterator() - for i, line in enumerate( data ): - if ( i > 500 ): break - fields = line.split() - location = name = "%s:%s-%s" % ( fields[0], fields[1], fields[2] ) - if len( fields ) > 3: - name = fields[4] - rows.append( [location, name] ) - return { 'data': rows } @web.json def save( self, trans, vis_json ): @@ -92,14 +70,6 @@ if trans.security.decode_id(new_dataset) in [ d["dataset_id"] for d in viz_config.get("tracks") ]: new_dataset = None # Already in browser, so don't add return trans.fill_template( 'tracks/browser.mako', config=viz_config, add_dataset=new_dataset ) - - @web.json - def chroms( self, trans, dbkey=None, num=None, chrom=None, low=None ): - return self.app.genomes.chroms( trans, dbkey=dbkey, num=num, chrom=chrom, low=low ) - - @web.json - def reference( self, trans, dbkey, chrom, low, high, **kwargs ): - return self.app.genomes.reference( trans, dbkey, chrom, low, high, **kwargs ) @web.json def raw_data( self, trans, dataset_id, chrom, low, high, **kwargs ): @@ -137,9 +107,7 @@ @web.json def dataset_state( self, trans, dataset_id, **kwargs ): """ Returns state of dataset. """ - # TODO: this code is copied from data() -- should refactor. - - # Dataset check. + dataset = self.get_dataset( trans, dataset_id, check_ownership=False, check_accessible=True ) msg = self.check_dataset_state( trans, dataset ) if not msg: @@ -288,91 +256,3 @@ result = data_provider.get_data( chrom, int( low ), int( high ), int( start_val ), int( max_vals ), **kwargs ) result.update( { 'dataset_type': tracks_dataset_type, 'extra_info': extra_info } ) return result - - @web.expose - def sweepster( self, trans, id=None, hda_ldda=None, dataset_id=None, regions=None ): - """ - Creates a sweepster visualization using the incoming parameters. If id is available, - get the visualization with the given id; otherwise, create a new visualization using - a given dataset and regions. - """ - # Need to create history if necessary in order to create tool form. - trans.get_history( create=True ) - - if id: - # Loading a shared visualization. - viz = self.get_visualization( trans, id ) - viz_config = self.get_visualization_config( trans, viz ) - dataset = self.get_dataset( trans, viz_config[ 'dataset_id' ] ) - else: - # Loading new visualization. - dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) - job = get_dataset_job( dataset ) - viz_config = { - 'dataset_id': dataset_id, - 'tool_id': job.tool_id, - 'regions': from_json_string( regions ) - } - - # Add tool, dataset attributes to config based on id. - tool = trans.app.toolbox.get_tool( viz_config[ 'tool_id' ] ) - viz_config[ 'tool' ] = tool.to_dict( trans, for_display=True ) - viz_config[ 'dataset' ] = dataset.get_api_value() - - return trans.fill_template_mako( "visualization/sweepster.mako", config=viz_config ) - - @web.expose - def circster( self, trans, id, **kwargs ): - vis = self.get_visualization( trans, id, check_ownership=False, check_accessible=True ) - viz_config = self.get_visualization_config( trans, vis ) - - # Get genome info. - dbkey = viz_config[ 'dbkey' ] - chroms_info = self.app.genomes.chroms( trans, dbkey=dbkey ) - genome = { 'dbkey': dbkey, 'chroms_info': chroms_info } - - # Add genome-wide summary tree data to each track in viz. - tracks = viz_config[ 'tracks' ] - for track in tracks: - # Get dataset and indexed datatype. - dataset = self.get_hda_or_ldda( trans, track[ 'hda_ldda'], track[ 'dataset_id' ] ) - data_sources = self._get_datasources( trans, dataset ) - if 'data_standalone' in data_sources: - indexed_type = data_sources['data_standalone']['name'] - data_provider = get_data_provider( indexed_type )( dataset ) - else: - indexed_type = data_sources['index']['name'] - # Get converted dataset and append track's genome data. - converted_dataset = dataset.get_converted_dataset( trans, indexed_type ) - data_provider = get_data_provider( indexed_type )( converted_dataset, dataset ) - # HACK: pass in additional params, which are only used for summary tree data, not BBI data. - track[ 'genome_wide_data' ] = { 'data': data_provider.get_genome_data( chroms_info, level=4, detail_cutoff=0, draw_cutoff=0 ) } - - return trans.fill_template( 'visualization/circster.mako', viz_config=viz_config, genome=genome ) - - # ----------------- - # Helper methods. - # ----------------- - - def _get_datasources( self, trans, dataset ): - """ - Returns datasources for dataset; if datasources are not available - due to indexing, indexing is started. Return value is a dictionary - with entries of type - (<datasource_type> : {<datasource_name>, <indexing_message>}). - """ - track_type, data_sources = dataset.datatype.get_track_type() - data_sources_dict = {} - msg = None - for source_type, data_source in data_sources.iteritems(): - if source_type == "data_standalone": - # Nothing to do. - msg = None - else: - # Convert. - msg = self.convert_dataset( trans, dataset, data_source ) - - # Store msg. - data_sources_dict[ source_type ] = { "name" : data_source, "message": msg } - - return data_sources_dict \ No newline at end of file diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 lib/galaxy/web/controllers/visualization.py --- a/lib/galaxy/web/controllers/visualization.py +++ b/lib/galaxy/web/controllers/visualization.py @@ -232,6 +232,73 @@ _histories_grid = HistorySelectionGrid() _history_datasets_grid = HistoryDatasetsSelectionGrid() _tracks_grid = TracksterSelectionGrid() + + # + # -- Functions for listing visualizations. -- + # + + @web.expose + @web.require_login( "see all available libraries" ) + def list_libraries( self, trans, **kwargs ): + """List all libraries that can be used for selecting datasets.""" + + # Render the list view + return self._libraries_grid( trans, **kwargs ) + + @web.expose + @web.require_login( "see a library's datasets that can added to this visualization" ) + def list_library_datasets( self, trans, **kwargs ): + """List a library's datasets that can be added to a visualization.""" + + library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( kwargs.get('f-library') ) ) + return trans.fill_template( '/tracks/library_datasets_select_grid.mako', + cntrller="library", + use_panels=False, + library=library, + created_ldda_ids='', + hidden_folder_ids='', + show_deleted=False, + comptypes=[], + current_user_roles=trans.get_current_user_roles(), + message='', + status="done" ) + + @web.expose + @web.require_login( "see all available histories" ) + def list_histories( self, trans, **kwargs ): + """List all histories that can be used for selecting datasets.""" + + # Render the list view + return self._histories_grid( trans, **kwargs ) + + @web.expose + @web.require_login( "see current history's datasets that can added to this visualization" ) + def list_current_history_datasets( self, trans, **kwargs ): + """ List a history's datasets that can be added to a visualization. """ + + kwargs[ 'f-history' ] = trans.security.encode_id( trans.get_history().id ) + kwargs[ 'show_item_checkboxes' ] = 'True' + return self.list_history_datasets( trans, **kwargs ) + + @web.expose + @web.require_login( "see a history's datasets that can added to this visualization" ) + def list_history_datasets( self, trans, **kwargs ): + """List a history's datasets that can be added to a visualization.""" + + # Render the list view + return self._history_datasets_grid( trans, **kwargs ) + + @web.expose + @web.require_login( "see all available datasets" ) + def list_datasets( self, trans, **kwargs ): + """List all datasets that can be added as tracks""" + + # Render the list view + return self._data_grid( trans, **kwargs ) + + @web.expose + def list_tracks( self, trans, **kwargs ): + return self._tracks_grid( trans, **kwargs ) @web.expose def list_published( self, trans, *args, **kwargs ): @@ -244,6 +311,38 @@ @web.expose @web.require_login( "use Galaxy visualizations", use_panels=True ) + def list( self, trans, *args, **kwargs ): + # Handle operation + if 'operation' in kwargs and 'id' in kwargs: + session = trans.sa_session + operation = kwargs['operation'].lower() + ids = util.listify( kwargs['id'] ) + for id in ids: + item = session.query( model.Visualization ).get( trans.security.decode_id( id ) ) + if operation == "delete": + item.deleted = True + if operation == "share or publish": + return self.sharing( trans, **kwargs ) + session.flush() + + # Build list of visualizations shared with user. + shared_by_others = trans.sa_session \ + .query( model.VisualizationUserShareAssociation ) \ + .filter_by( user=trans.get_user() ) \ + .join( model.Visualization.table ) \ + .filter( model.Visualization.deleted == False ) \ + .order_by( desc( model.Visualization.update_time ) ) \ + .all() + + return trans.fill_template( "visualization/list.mako", grid=self._user_list_grid( trans, *args, **kwargs ), shared_by_others=shared_by_others ) + + + # + # -- Functions for operating on visualizations. -- + # + + @web.expose + @web.require_login( "use Galaxy visualizations", use_panels=True ) def index( self, trans, *args, **kwargs ): """ Lists user's saved visualizations. """ return self.list( trans, *args, **kwargs ) @@ -268,34 +367,7 @@ # Display the management page trans.set_message( 'Copy created with name "%s"' % cloned_visualization.title ) return self.list( trans ) - - @web.expose - @web.require_login( "use Galaxy visualizations", use_panels=True ) - def list( self, trans, *args, **kwargs ): - # Handle operation - if 'operation' in kwargs and 'id' in kwargs: - session = trans.sa_session - operation = kwargs['operation'].lower() - ids = util.listify( kwargs['id'] ) - for id in ids: - item = session.query( model.Visualization ).get( trans.security.decode_id( id ) ) - if operation == "delete": - item.deleted = True - if operation == "share or publish": - return self.sharing( trans, **kwargs ) - session.flush() - # Build list of visualizations shared with user. - shared_by_others = trans.sa_session \ - .query( model.VisualizationUserShareAssociation ) \ - .filter_by( user=trans.get_user() ) \ - .join( model.Visualization.table ) \ - .filter( model.Visualization.deleted == False ) \ - .order_by( desc( model.Visualization.update_time ) ) \ - .all() - - return trans.fill_template( "visualization/list.mako", grid=self._user_list_grid( trans, *args, **kwargs ), shared_by_others=shared_by_others ) - @web.expose @web.require_login( "modify Galaxy visualizations" ) def set_slug_async( self, trans, id, new_slug ): @@ -608,68 +680,91 @@ template="visualization/create.mako" ) @web.expose - @web.require_login( "see all available libraries" ) - def list_libraries( self, trans, **kwargs ): - """List all libraries that can be used for selecting datasets.""" + def circster( self, trans, id, **kwargs ): + """ + Display a circster visualization. + """ + vis = self.get_visualization( trans, id, check_ownership=False, check_accessible=True ) + viz_config = self.get_visualization_config( trans, vis ) - # Render the list view - return self._libraries_grid( trans, **kwargs ) + # Get genome info. + dbkey = viz_config[ 'dbkey' ] + chroms_info = self.app.genomes.chroms( trans, dbkey=dbkey ) + genome = { 'dbkey': dbkey, 'chroms_info': chroms_info } + + # Add genome-wide summary tree data to each track in viz. + tracks = viz_config[ 'tracks' ] + for track in tracks: + # Get dataset and indexed datatype. + dataset = self.get_hda_or_ldda( trans, track[ 'hda_ldda'], track[ 'dataset_id' ] ) + data_sources = self._get_datasources( trans, dataset ) + if 'data_standalone' in data_sources: + indexed_type = data_sources['data_standalone']['name'] + data_provider = get_data_provider( indexed_type )( dataset ) + else: + indexed_type = data_sources['index']['name'] + # Get converted dataset and append track's genome data. + converted_dataset = dataset.get_converted_dataset( trans, indexed_type ) + data_provider = get_data_provider( indexed_type )( converted_dataset, dataset ) + # HACK: pass in additional params, which are only used for summary tree data, not BBI data. + track[ 'genome_wide_data' ] = { 'data': data_provider.get_genome_data( chroms_info, level=4, detail_cutoff=0, draw_cutoff=0 ) } + + return trans.fill_template( 'visualization/circster.mako', viz_config=viz_config, genome=genome ) @web.expose - @web.require_login( "see a library's datasets that can added to this visualization" ) - def list_library_datasets( self, trans, **kwargs ): - """List a library's datasets that can be added to a visualization.""" - - library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( kwargs.get('f-library') ) ) - return trans.fill_template( '/tracks/library_datasets_select_grid.mako', - cntrller="library", - use_panels=False, - library=library, - created_ldda_ids='', - hidden_folder_ids='', - show_deleted=False, - comptypes=[], - current_user_roles=trans.get_current_user_roles(), - message='', - status="done" ) - - @web.expose - @web.require_login( "see all available histories" ) - def list_histories( self, trans, **kwargs ): - """List all histories that can be used for selecting datasets.""" - - # Render the list view - return self._histories_grid( trans, **kwargs ) - - @web.expose - @web.require_login( "see current history's datasets that can added to this visualization" ) - def list_current_history_datasets( self, trans, **kwargs ): - """ List a history's datasets that can be added to a visualization. """ - - kwargs[ 'f-history' ] = trans.security.encode_id( trans.get_history().id ) - kwargs[ 'show_item_checkboxes' ] = 'True' - return self.list_history_datasets( trans, **kwargs ) - - @web.expose - @web.require_login( "see a history's datasets that can added to this visualization" ) - def list_history_datasets( self, trans, **kwargs ): - """List a history's datasets that can be added to a visualization.""" + def sweepster( self, trans, id=None, hda_ldda=None, dataset_id=None, regions=None ): + """ + Displays a sweepster visualization using the incoming parameters. If id is available, + get the visualization with the given id; otherwise, create a new visualization using + a given dataset and regions. + """ + # Need to create history if necessary in order to create tool form. + trans.get_history( create=True ) - # Render the list view - return self._history_datasets_grid( trans, **kwargs ) - - @web.expose - @web.require_login( "see all available datasets" ) - def list_datasets( self, trans, **kwargs ): - """List all datasets that can be added as tracks""" - - # Render the list view - return self._data_grid( trans, **kwargs ) - - @web.expose - def list_tracks( self, trans, **kwargs ): - return self._tracks_grid( trans, **kwargs ) + if id: + # Loading a shared visualization. + viz = self.get_visualization( trans, id ) + viz_config = self.get_visualization_config( trans, viz ) + dataset = self.get_dataset( trans, viz_config[ 'dataset_id' ] ) + else: + # Loading new visualization. + dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) + job = get_dataset_job( dataset ) + viz_config = { + 'dataset_id': dataset_id, + 'tool_id': job.tool_id, + 'regions': from_json_string( regions ) + } + + # Add tool, dataset attributes to config based on id. + tool = trans.app.toolbox.get_tool( viz_config[ 'tool_id' ] ) + viz_config[ 'tool' ] = tool.to_dict( trans, for_display=True ) + viz_config[ 'dataset' ] = dataset.get_api_value() + + return trans.fill_template_mako( "visualization/sweepster.mako", config=viz_config ) def get_item( self, trans, id ): return self.get_visualization( trans, id ) + + @web.json + def bookmarks_from_dataset( self, trans, hda_id=None, ldda_id=None ): + if hda_id: + hda_ldda = "hda" + dataset_id = hda_id + elif ldda_id: + hda_ldda = "ldda" + dataset_id = ldda_id + dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) + + rows = [] + if isinstance( dataset.datatype, Bed ): + data = RawBedDataProvider( original_dataset=dataset ).get_iterator() + for i, line in enumerate( data ): + if ( i > 500 ): break + fields = line.split() + location = name = "%s:%s-%s" % ( fields[0], fields[1], fields[2] ) + if len( fields ) > 3: + name = fields[4] + rows.append( [location, name] ) + return { 'data': rows } diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -1320,13 +1320,12 @@ */ load_chroms: function(url_parms) { url_parms.num = MAX_CHROMS_SELECTABLE; - url_parms.dbkey = this.dbkey; var view = this, chrom_data = $.Deferred(); $.ajax({ - url: chrom_url, + url: chrom_url + "/" + this.dbkey, data: url_parms, dataType: "json", success: function (result) { @@ -4198,10 +4197,10 @@ this.content_div.css("background", "none"); this.content_div.css("min-height", "0px"); this.content_div.css("border", "none"); - this.data_url = reference_url; - this.data_url_extra_params = {dbkey: view.dbkey}; + this.data_url = reference_url + "/" + this.view.dbkey; + this.data_url_extra_params = {reference: true}; this.data_manager = new ReferenceTrackDataManager({ - data_url: reference_url + data_url: this.data_url }); this.hide_contents(); }; diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 templates/base_panels.mako --- a/templates/base_panels.mako +++ b/templates/base_panels.mako @@ -62,8 +62,7 @@ raw_data_url: '${h.url_for( controller="/tracks", action="raw_data" )}', converted_datasets_state_url: '${h.url_for( controller="/tracks", action="converted_datasets_state" )}', dataset_state_url: '${h.url_for( controller="/tracks", action="dataset_state" )}', - sweepster_url: '${h.url_for( controller="/tracks", action="sweepster" )}', - + sweepster_url: '${h.url_for( controller="/visualization", action="sweepster" )}', visualization_url: '${h.url_for( controller="/visualization", action="save" )}', }); </script> diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 templates/tracks/browser.mako --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -113,7 +113,7 @@ title: 'Circster', on_click: function() { // Add viz id dynamically so that newly saved visualizations work as well. - window.location = "${h.url_for( controller='tracks', action='circster' )}?id=" + view.vis_id; + window.location = "${h.url_for( controller='visualization', action='circster' )}?id=" + view.vis_id; } }, { icon_class: 'disk--arrow', title: 'Save', on_click: function() { diff -r 81e32d70ee2daf03228752992b1765904f7e93fa -r 0d077bcf9ab71ea928fb832cf85a9f7f4f20b5f8 templates/visualization/trackster_common.mako --- a/templates/visualization/trackster_common.mako +++ b/templates/visualization/trackster_common.mako @@ -20,8 +20,8 @@ add_datasets_url = "${h.url_for( controller='/visualization', action='list_current_history_datasets' )}", default_data_url = "${h.url_for( controller='/tracks', action='data' )}", raw_data_url = "${h.url_for( controller='/tracks', action='raw_data' )}", - reference_url = "${h.url_for( controller='/tracks', action='reference' )}", - chrom_url = "${h.url_for( controller='/tracks', action='chroms' )}", + reference_url = "${h.url_for( controller='/api/genomes' )}", + chrom_url = "${h.url_for( controller='/api/genomes' )}", dataset_state_url = "${h.url_for( controller='/tracks', action='dataset_state' )}", converted_datasets_state_url = "${h.url_for( controller='/tracks', action='converted_datasets_state' )}", feature_search_url = "${h.url_for( controller='/tracks', action='search_features' )}"; 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