details: http://www.bx.psu.edu/hg/galaxy/rev/811eda31b6b3 changeset: 2910:811eda31b6b3 user: James Taylor james@jamestaylor.org date: Fri Oct 23 12:47:16 2009 -0400 description: Tables for storing visualizations, visualization tab (if enable_tracks is true)
8 file(s) affected in this change:
lib/galaxy/model/__init__.py lib/galaxy/model/mapping.py lib/galaxy/web/controllers/tracks.py lib/galaxy/web/controllers/visualization.py templates/base_panels.mako templates/panels.mako templates/tracks/browser.mako templates/tracks/new_browser.mako
diffs (290 lines):
diff -r 2c4ed83f76ef -r 811eda31b6b3 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Thu Oct 22 23:02:28 2009 -0400 +++ b/lib/galaxy/model/__init__.py Fri Oct 23 12:47:16 2009 -0400 @@ -1292,7 +1292,7 @@ if self.phone: html = html + '<br/>' + 'Phone: ' + self.phone return html - + class Page( object ): def __init__( self ): self.id = None @@ -1307,6 +1307,22 @@ self.user = None self.title = None self.content = None + +class Visualization( object ): + def __init__( self ): + self.id = None + self.user = None + self.type = None + self.title = None + self.latest_revision = None + self.revisions = [] + +class VisualizationRevision( object ): + def __init__( self ): + self.id = None + self.visualization = None + self.title = None + self.config = None
class Tag ( object ): def __init__( self, id=None, type=None, parent_id=None, name=None ): diff -r 2c4ed83f76ef -r 811eda31b6b3 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Thu Oct 22 23:02:28 2009 -0400 +++ b/lib/galaxy/model/mapping.py Fri Oct 23 12:47:16 2009 -0400 @@ -556,6 +556,26 @@ Column( "content", TEXT ) )
+Visualization.table = Table( "visualization", metadata, + Column( "id", Integer, primary_key=True ), + Column( "create_time", DateTime, default=now ), + Column( "update_time", DateTime, default=now, onupdate=now ), + Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), + Column( "latest_revision_id", Integer, + ForeignKey( "visualization_revision.id", use_alter=True, name='visualization_latest_revision_id_fk' ), index=True ), + Column( "title", TEXT ), + Column( "type", TEXT ) + ) + +VisualizationRevision.table = Table( "visualization_revision", metadata, + Column( "id", Integer, primary_key=True ), + Column( "create_time", DateTime, default=now ), + Column( "update_time", DateTime, default=now, onupdate=now ), + Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True, nullable=False ), + Column( "title", TEXT ), + Column( "config", JSONType ) + ) + Tag.table = Table( "tag", metadata, Column( "id", Integer, primary_key=True ), Column( "type", Integer ), @@ -1012,6 +1032,18 @@ tags=relation(PageTagAssociation, order_by=PageTagAssociation.table.c.id, backref="pages") ) )
+assign_mapper( context, VisualizationRevision, VisualizationRevision.table ) + +assign_mapper( context, Visualization, Visualization.table, + properties=dict( user=relation( User ), + revisions=relation( VisualizationRevision, backref='visualization', + cascade="all, delete-orphan", + primaryjoin=( Visualization.table.c.id == VisualizationRevision.table.c.visualization_id ) ), + latest_revision=relation( VisualizationRevision, post_update=True, + primaryjoin=( Visualization.table.c.latest_revision_id == VisualizationRevision.table.c.id ), + lazy=False ) + ) ) + assign_mapper( context, Tag, Tag.table, properties=dict( children=relation(Tag, backref=backref( 'parent', remote_side=[Tag.table.c.id] ) ) ) ) diff -r 2c4ed83f76ef -r 811eda31b6b3 lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py Thu Oct 22 23:02:28 2009 -0400 +++ b/lib/galaxy/web/controllers/tracks.py Fri Oct 23 12:47:16 2009 -0400 @@ -63,18 +63,35 @@ return trans.fill_template( "tracks/index.mako" )
@web.expose - def new_browser( self, trans, dbkey=None, dataset_ids=None, browse=None ): + def new_browser( self, trans, dbkey=None, dataset_ids=None, browse=None, title=None ): """ Build a new browser from datasets in the current history. Redirects - to 'index' once datasets to browse have been selected. + to 'browser' once datasets to browse have been selected. """ session = trans.sa_session # If the user clicked the submit button explicitly, try to build the browser - if browse and dataset_ids: + if title and browse and dataset_ids: if not isinstance( dataset_ids, list ): dataset_ids = [ dataset_ids ] - dataset_ids = ",".join( map( str, dataset_ids ) ) - trans.response.send_redirect( web.url_for( controller='tracks', action='browser', chrom="", dataset_ids=dataset_ids ) ) + # Build config + tracks = [] + for dataset_id in dataset_ids: + tracks.append( { "dataset_id": str( dataset_id ) } ) + config = { "tracks": tracks } + # Build visualization object + vis = model.Visualization() + vis.user = trans.user + vis.title = title + vis.type = "trackster" + vis_rev = model.VisualizationRevision() + vis_rev.visualization = vis + vis_rev.title = title + vis_rev.config = config + vis.latest_revision = vis_rev + session.add( vis ) + session.add( vis_rev ) + session.flush() + trans.response.send_redirect( web.url_for( controller='tracks', action='browser', id=trans.security.encode_id( vis.id ) ) ) else: # Determine the set of all dbkeys that are used in the current history dbkeys = [ d.metadata.dbkey for d in trans.get_history().datasets if not d.deleted ] @@ -96,14 +113,18 @@ return trans.fill_template( "tracks/new_browser.mako", converters=browsable_types, dbkey=dbkey, dbkey_set=dbkey_set, datasets=datasets )
@web.expose - def browser(self, trans, dataset_ids, chrom=""): + def browser(self, trans, id, chrom=""): """ Display browser for the datasets listed in `dataset_ids`. """ + decoded_id = trans.security.decode_id( id ) + session = trans.sa_session + vis = session.query( model.Visualization ).get( decoded_id ) tracks = [] dbkey = "" - for dataset_id in dataset_ids.split( "," ): - dataset = trans.sa_session.query( trans.app.model.HistoryDatasetAssociation ).get( dataset_id ) + for t in vis.latest_revision.config['tracks']: + dataset_id = t['dataset_id'] + dataset = trans.app.model.HistoryDatasetAssociation.get( dataset_id ) tracks.append( { "type": dataset.datatype.get_track_type(), "name": dataset.name, @@ -114,7 +135,8 @@ if chrom_lengths is None: error( "No chromosome lengths file found for '%s'" % dataset.name ) return trans.fill_template( 'tracks/browser.mako', - dataset_ids=dataset_ids, + #dataset_ids=dataset_ids, + id=id, tracks=tracks, chrom=chrom, dbkey=dbkey, diff -r 2c4ed83f76ef -r 811eda31b6b3 lib/galaxy/web/controllers/visualization.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/web/controllers/visualization.py Fri Oct 23 12:47:16 2009 -0400 @@ -0,0 +1,47 @@ +from galaxy.web.base.controller import * +from galaxy.web.framework.helpers import time_ago, grids +from galaxy.util.sanitize_html import sanitize_html + + +class VisualizationListGrid( grids.Grid ): + # Grid definition + use_panels = True + title = "Visualizations" + model_class = model.Visualization + default_sort_key = "-create_time" + columns = [ + grids.GridColumn( "Title", key="title", attach_popup=True, + link=( lambda item: dict( controller="tracks", action="browser", id=item.id ) ) ), + grids.GridColumn( "Type", key="type" ), + grids.GridColumn( "Created", key="create_time", format=time_ago ), + grids.GridColumn( "Last Updated", key="update_time", format=time_ago ), + ] + ## global_actions = [ + ## grids.GridAction( "Add new page", dict( action='create' ) ) + ## ] + operations = [ + grids.GridOperation( "View", allow_multiple=False, url_args=dict( controller="tracks", action='browser' ) ), + ] + def apply_default_filter( self, trans, query, **kwargs ): + return query.filter_by( user=trans.user ) + +class VisualizationController( BaseController ): + + @web.expose + def index( self, trans ): + return trans.fill_template( "panels.mako", active_view='visualization', main_url=url_for( action='list' ) ) + + list_grid = VisualizationListGrid() + @web.expose + def list( self, trans, *args, **kwargs ): + return self.list_grid( trans, *args, **kwargs ) + + #@web.expose + #@web.require_admin + #def index( self, trans, *args, **kwargs ): + # # Build grid + # grid = self.list( trans, *args, **kwargs ) + # # Render grid wrapped in panels + # return trans.fill_template( "page/index.mako", grid=grid ) + + \ No newline at end of file diff -r 2c4ed83f76ef -r 811eda31b6b3 templates/base_panels.mako --- a/templates/base_panels.mako Thu Oct 22 23:02:28 2009 -0400 +++ b/templates/base_panels.mako Fri Oct 23 12:47:16 2009 -0400 @@ -173,11 +173,18 @@ %endif
%if app.config.get_bool( 'enable_tracks', False ): - <td class="tab"> + <% + cls = "tab" + if self.active_view == 'visualization': + cls += " active" + %> + <td class="${cls}"> Visualization <div class="submenu"> <ul> <li><a href="${h.url_for( controller='tracks', action='index' )}">Build track browser</a></li> + <li><hr style="color: inherit; background-color: gray"/></li> + <li><a href="${h.url_for( controller='visualization', action='index' )}">Stored visualizations</a></li> </ul> </div> </td> diff -r 2c4ed83f76ef -r 811eda31b6b3 templates/panels.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/panels.mako Fri Oct 23 12:47:16 2009 -0400 @@ -0,0 +1,16 @@ +<%inherit file="/base_panels.mako"/> + +<%def name="init()"> +<% + self.has_left_panel=False + self.has_right_panel=False + self.active_view=active_view + self.message_box_visible=False +%> +</%def> + +<%def name="center_panel()"> + + <iframe name="galaxy_main" id="galaxy_main" frameborder="0" style="position: absolute; width: 100%; height: 100%;" src="${main_url}"> </iframe> + +</%def> diff -r 2c4ed83f76ef -r 811eda31b6b3 templates/tracks/browser.mako --- a/templates/tracks/browser.mako Thu Oct 22 23:02:28 2009 -0400 +++ b/templates/tracks/browser.mako Fri Oct 23 12:47:16 2009 -0400 @@ -124,7 +124,8 @@ <select id="chrom" name="chrom"> <option value="">Loading</option> </select> - <input type="hidden" name="dataset_ids" value="${dataset_ids}" /> + ## <input type="hidden" name="dataset_ids" value="${dataset_ids}" /> + <input type="hidden" name="id" value="${id}" /> <a href="#" onclick="javascript:view.zoom_in();view.redraw();">+</a> <a href="#" onclick="javascript:view.zoom_out();view.redraw();">-</a> </form> diff -r 2c4ed83f76ef -r 811eda31b6b3 templates/tracks/new_browser.mako --- a/templates/tracks/new_browser.mako Thu Oct 22 23:02:28 2009 -0400 +++ b/templates/tracks/new_browser.mako Fri Oct 23 12:47:16 2009 -0400 @@ -19,10 +19,17 @@
% else: <div class="form"> - <div class="form-title">Select datasets to include in browser</div> + <div class="form-title">Create new track browser</div>
<div id="dbkey" class="form-body"> <form id="form" method="POST"> + <div class="form-row"> + <label for="dbkey">Browser name:</label> + <div class="form-row-input"> + <input type="text" name="title" id="title" value="Unnamed Browser"></input> + </div> + <div style="clear: both;"></div> + </div> <div class="form-row"> <label for="dbkey">Reference genome build (dbkey): </label> <div class="form-row-input">
galaxy-dev@lists.galaxyproject.org