commit/galaxy-central: carlfeberhard: generate display application links outside of datatype classes
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6714ad95a7f3/ changeset: 6714ad95a7f3 user: carlfeberhard date: 2013-02-22 05:30:55 summary: generate display application links outside of datatype classes affected #: 2 files diff -r 429103684d864f93563cd92c30888bd623fdb80e -r 6714ad95a7f3dc9096e4630633beab30df54cdd8 lib/galaxy/datatypes/display_applications/link_generator.py --- /dev/null +++ b/lib/galaxy/datatypes/display_applications/link_generator.py @@ -0,0 +1,153 @@ +"""Separating Transaction based elements of display applications from datatypes. +""" + +import urllib + +# for the url_for hack +import pkg_resources +pkg_resources.require( "Routes" ) +import routes + +from galaxy import util +from galaxy.web import url_for + +from galaxy.datatypes.interval import Interval, Gff, Wiggle, CustomTrack + + +def get_display_app_link_generator( display_app_name ): + """Returns an instance of the proper link generator class + based on the display_app_name or DisplayAppLinkGenerator + if the name is unrecognized. + """ + if display_app_name == 'ucsc': + return UCSCDisplayAppLinkGenerator() + + if display_app_name == 'gbrowse': + return GBrowseDisplayAppLinkGenerator() + + return DisplayAppLinkGenerator() + + +class DisplayAppLinkGenerator( object ): + """Base class for display application link generators. + + This class returns an empty list of links for all datatypes. + """ + def __init__( self ): + self.display_app_name = '' + + def no_links_available( self, dataset, app, base_url, url_for=url_for ): + """Called when no display application links are available + for this display app name and datatype combination. + """ + return [] + + def _link_function_from_datatype( self, datatype ): + """Dispatch to proper link generating function on datatype. + """ + return self.no_links_available + + def generate_links( self, trans, dataset ): + # here's the hack - which is expensive (time) + web_url_for = routes.URLGenerator( trans.webapp.mapper, trans.environ ) + + link_function = self._link_function_from_datatype( dataset.datatype ) + display_links = link_function( dataset, trans.app, trans.request.base, url_for=web_url_for ) + + return display_links + + +class UCSCDisplayAppLinkGenerator( DisplayAppLinkGenerator ): + """Class for UCSC display application link generators. + + This class returns UCSC main and test links for the following datatypes: + Interval, Wiggle, Gff, CustomTrack + """ + def __init__( self ): + self.display_app_name = 'ucsc' + + def _link_function_from_datatype( self, datatype ): + """Dispatch to proper link generating function based on datatype. + """ + # they're all the same + if( ( isinstance( datatype, Interval ) ) + or ( isinstance( datatype, Wiggle ) ) + or ( isinstance( datatype, Gff ) ) + or ( isinstance( datatype, CustomTrack ) ) ): + return self.ucsc_links + else: + return super( UCSCDisplayAppLinkGenerator, self )._link_function_from_datatype( datatype ) + + def ucsc_links( self, dataset, app, base_url, url_for=url_for ): + """Generate links to UCSC genome browser sites based on the dbkey + and content of dataset. + """ + # this is a refactor of Interval.ucsc_links, GFF.ucsc_links, Wiggle.ucsc_links, and CustomTrack.ucsc_links + # ...which are all the same function + + #TODO: app vars can be moved into init (and base_url as well) + chrom, start, stop = dataset.datatype.get_estimated_display_viewport( dataset ) + if chrom is None: + return [] + ret_val = [] + for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey): + if site_name in app.config.ucsc_display_sites: + internal_url = url_for( controller='dataset', dataset_id=dataset.id, + action='display_at', filename='%s_%s' % ( self.display_app_name, site_name ) ) + base_url = app.config.get( "display_at_callback", base_url ) + display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s&authz_method=display_at" + % (base_url, url_for( controller='root' ), dataset.id, self.display_app_name) ) + redirect_url = urllib.quote_plus( "%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" + % (site_url, dataset.dbkey, chrom, start, stop ) ) + + link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, redirect_url, display_url ) + ret_val.append( ( site_name, link ) ) + + return ret_val + + +class GBrowseDisplayAppLinkGenerator( DisplayAppLinkGenerator ): + """Class for UCSC display application link generators. + + This class returns UCSC main and test links for the following datatypes: + Interval, Wiggle, Gff, CustomTrack + """ + def __init__( self ): + self.display_app_name = 'gbrowse' + + def _link_function_from_datatype( self, datatype ): + """Dispatch to proper link generating function based on datatype. + """ + # they're all the same + if( ( isinstance( datatype, Gff ) ) + or ( isinstance( datatype, Wiggle ) ) ): + return self.gbrowse_links + else: + return super( GBrowseDisplayAppLinkGenerator, self )._link_function_from_datatype( datatype ) + + def gbrowse_links( self, dataset, app, base_url, url_for=url_for ): + """Generate links to GBrowse genome browser sites based on the dbkey + and content of dataset. + """ + # when normalized for var names, Gff.gbrowse_links and Wiggle.gbrowse_links are the same + # also: almost identical to ucsc_links except for the 'chr' stripping, sites_by_build, config key + # could be refactored even more + chrom, start, stop = dataset.datatype.get_estimated_display_viewport( dataset ) + if chrom is None: + return [] + ret_val = [] + for site_name, site_url in util.get_gbrowse_sites_by_build( dataset.dbkey ): + if site_name in app.config.gbrowse_display_sites: + # strip chr from seqid + if chrom.startswith( 'chr' ) and len ( chrom ) > 3: + chrom = chrom[3:] + internal_url = url_for( controller='dataset', dataset_id=dataset.id, + action='display_at', filename='%s_%s' % ( self.display_app_name, site_name ) ) + redirect_url = urllib.quote_plus( "%s/?q=%s:%s..%s&eurl=%%s" % ( site_url, chrom, start, stop ) ) + base_url = app.config.get( "display_at_callback", base_url ) + display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s&authz_method=display_at" + % ( base_url, url_for( controller='root' ), dataset.id, self.display_app_name ) ) + link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, redirect_url, display_url ) + ret_val.append( ( site_name, link ) ) + + return ret_val diff -r 429103684d864f93563cd92c30888bd623fdb80e -r 6714ad95a7f3dc9096e4630633beab30df54cdd8 lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -14,6 +14,8 @@ from galaxy.datatypes.display_applications import util from galaxy.datatypes.metadata import FileParameter +from galaxy.datatypes.display_applications.link_generator import get_display_app_link_generator + import pkg_resources pkg_resources.require( "Routes" ) import routes @@ -128,8 +130,6 @@ """ GET /api/histories/{encoded_history_id}/contents/{encoded_content_id} Displays information about a history content (dataset). - - """ hda_dict = {} try: @@ -225,7 +225,8 @@ hda_dict[ 'meta_files' ] = meta_files hda_dict[ 'display_apps' ] = get_display_apps( trans, hda ) - #hda_dict[ 'display_types' ] = get_display_types( trans, hda ) + hda_dict[ 'display_types' ] = get_old_display_applications( trans, hda ) + hda_dict[ 'visualizations' ] = hda.get_visualizations() hda_dict[ 'peek' ] = to_unicode( hda.display_peek() ) @@ -262,21 +263,21 @@ return display_apps -def get_display_types( trans, hda ): - #TODO: make more straightforward (somehow) - #FIXME: need to force a transition to all new-style display applications +def get_old_display_applications( trans, hda ): display_apps = [] - - for display_app in hda.datatype.get_display_types(): + for display_app_name in hda.datatype.get_display_types(): + link_generator = get_display_app_link_generator( display_app_name ) + display_links = link_generator.generate_links( trans, hda ) + app_links = [] - target_frame, display_links = hda.datatype.get_display_links( hda, display_app, trans.app, trans.request.base ) for display_name, display_link in display_links: app_links.append({ - 'target' : target_frame, + 'target' : '_blank', 'href' : display_link, 'text' : display_name }) if app_links: - display_apps.append( dict( label=hda.datatype.get_display_label( display_app ), links=app_links ) ) + display_apps.append( dict( label=hda.datatype.get_display_label( display_app_name ), links=app_links ) ) return display_apps + 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)
-
commits-noreply@bitbucket.org