1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a3d10d4db962/ Changeset: a3d10d4db962 User: guerler Date: 2014-09-25 01:13:45+00:00 Summary: ToolForm: Fix datatype mapping, provide data mapping through api Affected #: 7 files diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 client/galaxy/scripts/mvc/tools/tools-datasets.js --- a/client/galaxy/scripts/mvc/tools/tools-datasets.js +++ b/client/galaxy/scripts/mvc/tools/tools-datasets.js @@ -1,38 +1,58 @@ -define([ 'mvc/history/history-contents' ], function( HISTORY_CONTENTS ){ +define([ 'mvc/history/history-contents', 'utils/utils' ], function( HistoryContents, Utils ){ return Backbone.Model.extend({ // initialize initialize: function(options) { // create history contents container - this.currHistoryContents = new HISTORY_CONTENTS.HistoryContents({}); + this.currHistoryContents = new HistoryContents.HistoryContents({}); // identify current history id this.currHistoryContents.historyId = options.history_id; - // make request + // prepare datatype structure + this.typedict = {}; + + // link this var self = this; - var xhr = this.currHistoryContents.fetchAllDetails() - .done( function(){ - // log request success - console.debug('tools-datasets::initialize() - Completed.'); + + // request datatypes + Utils.get(galaxy_config.root + 'api/datatypes/mapping', + // success + function(typedict) { + // backup datatype dictionary + self.typedict = typedict; - // callback - options.success && options.success(); - }) - .fail( function(){ + // make request + var xhr = self.currHistoryContents.fetchAllDetails() + .done( function(){ + // log request success + console.debug('tools-datasets::initialize() - Completed.'); + + // callback + options.success && options.success(); + }) + .fail( function(){ + // log request failure + console.debug('tools-datasets::initialize() - Ajax request for history datasets failed.'); + }); + }, + // error + function(response) { // log request failure - console.debug('tools-datasets::initialize() - Ajax request failed.'); - }); + console.debug('tools-datasets::initialize() - Ajax request for datatype dictionary failed.'); + } + ); }, /** Filters datasets by data type. */ filterType: function(options) { options = options || {}; + var self = this; return this.currHistoryContents.filter(function(content){ // match datatypes var found = false; for (var i in options.data_types) { - if (content.get('data_type').indexOf(options.data_types[i]) != -1) { + if (self._matchType(content.get('data_type'), options.data_types[i])) { found = true; break; } @@ -48,6 +68,26 @@ */ filter: function(filter_id) { return _.first( this.currHistoryContents.filter( function( content ){ return content.get( 'id' ) === filter_id; }) ); + }, + + /** Check if datatypes match + */ + _matchType: function(reference, target) { + // check if target class is available + var target_class = this.typedict.ext_to_class_name[target]; + if (!target_class) { + console.debug('tools-datasets::_matchType() - Specific target class unavailable. Accepting all formats.'); + return true; + } + + // check reference group + var reference_group = this.typedict.class_to_classes[reference]; + if (reference_group[target_class]) { + return true; + } + + // classes do not match + return false; } }); }); \ No newline at end of file diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 lib/galaxy/webapps/galaxy/api/datatypes.py --- a/lib/galaxy/webapps/galaxy/api/datatypes.py +++ b/lib/galaxy/webapps/galaxy/api/datatypes.py @@ -5,6 +5,7 @@ from galaxy import web from galaxy.web.base.controller import BaseAPIController from galaxy.util import asbool +from galaxy.datatypes.data import Data import logging log = logging.getLogger( __name__ ) @@ -43,6 +44,37 @@ return { 'error': str( exception ) } @web.expose_api_anonymous + def mapping( self, trans ): + ''' + GET /api/datatypes/mapping + Return a dictionary of class to class mappings. + ''' + try: + ext_to_class_name = dict() + classes = [] + for k, v in trans.app.datatypes_registry.datatypes_by_extension.iteritems(): + c = v.__class__ + ext_to_class_name[k] = c.__module__ + "." + c.__name__ + classes.append( c ) + class_to_classes = dict() + + def visit_bases( types, cls ): + for base in cls.__bases__: + if issubclass( base, Data ): + types.add( base.__module__ + "." + base.__name__ ) + visit_bases( types, base ) + for c in classes: + n = c.__module__ + "." + c.__name__ + types = set( [ n ] ) + visit_bases( types, c ) + class_to_classes[ n ] = dict( ( t, True ) for t in types ) + return dict( ext_to_class_name=ext_to_class_name, class_to_classes=class_to_classes ) + except Exception, exception: + log.error( 'could not get datatype mapping: %s', str( exception ), exc_info=True ) + trans.response.status = 500 + return { 'error': str( exception ) } + + @web.expose_api_anonymous def sniffers( self, trans, **kwd ): ''' GET /api/datatypes/sniffers diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -192,7 +192,7 @@ webapp.mapper.resource( 'datatype', 'datatypes', path_prefix='/api', - collection={ 'sniffers': 'GET' }, + collection={ 'sniffers': 'GET', 'mapping' : 'GET' }, parent_resources=dict( member_name='datatype', collection_name='datatypes' ) ) #webapp.mapper.connect( 'run_workflow', '/api/workflow/{workflow_id}/library/{library_id}', controller='workflows', action='run', workflow_id=None, library_id=None, conditions=dict(method=["GET"]) ) webapp.mapper.resource( 'search', 'search', path_prefix='/api' ) diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 lib/galaxy/webapps/galaxy/controllers/workflow.py --- a/lib/galaxy/webapps/galaxy/controllers/workflow.py +++ b/lib/galaxy/webapps/galaxy/controllers/workflow.py @@ -1179,28 +1179,6 @@ use_panels=True, myexperiment_target_url=myexperiment_target_url ) - @web.json - def get_datatypes( self, trans ): - ext_to_class_name = dict() - classes = [] - for k, v in trans.app.datatypes_registry.datatypes_by_extension.iteritems(): - c = v.__class__ - ext_to_class_name[k] = c.__module__ + "." + c.__name__ - classes.append( c ) - class_to_classes = dict() - - def visit_bases( types, cls ): - for base in cls.__bases__: - if issubclass( base, Data ): - types.add( base.__module__ + "." + base.__name__ ) - visit_bases( types, base ) - for c in classes: - n = c.__module__ + "." + c.__name__ - types = set( [ n ] ) - visit_bases( types, c ) - class_to_classes[ n ] = dict( ( t, True ) for t in types ) - return dict( ext_to_class_name=ext_to_class_name, class_to_classes=class_to_classes ) - @web.expose def build_from_current_history( self, trans, job_ids=None, dataset_ids=None, dataset_collection_ids=None, workflow_name=None ): user = trans.get_user() diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 static/scripts/mvc/tools/tools-datasets.js --- a/static/scripts/mvc/tools/tools-datasets.js +++ b/static/scripts/mvc/tools/tools-datasets.js @@ -1,38 +1,58 @@ -define([ 'mvc/history/history-contents' ], function( HISTORY_CONTENTS ){ +define([ 'mvc/history/history-contents', 'utils/utils' ], function( HistoryContents, Utils ){ return Backbone.Model.extend({ // initialize initialize: function(options) { // create history contents container - this.currHistoryContents = new HISTORY_CONTENTS.HistoryContents({}); + this.currHistoryContents = new HistoryContents.HistoryContents({}); // identify current history id this.currHistoryContents.historyId = options.history_id; - // make request + // prepare datatype structure + this.typedict = {}; + + // link this var self = this; - var xhr = this.currHistoryContents.fetchAllDetails() - .done( function(){ - // log request success - console.debug('tools-datasets::initialize() - Completed.'); + + // request datatypes + Utils.get(galaxy_config.root + 'api/datatypes/mapping', + // success + function(typedict) { + // backup datatype dictionary + self.typedict = typedict; - // callback - options.success && options.success(); - }) - .fail( function(){ + // make request + var xhr = self.currHistoryContents.fetchAllDetails() + .done( function(){ + // log request success + console.debug('tools-datasets::initialize() - Completed.'); + + // callback + options.success && options.success(); + }) + .fail( function(){ + // log request failure + console.debug('tools-datasets::initialize() - Ajax request for history datasets failed.'); + }); + }, + // error + function(response) { // log request failure - console.debug('tools-datasets::initialize() - Ajax request failed.'); - }); + console.debug('tools-datasets::initialize() - Ajax request for datatype dictionary failed.'); + } + ); }, /** Filters datasets by data type. */ filterType: function(options) { options = options || {}; + var self = this; return this.currHistoryContents.filter(function(content){ // match datatypes var found = false; for (var i in options.data_types) { - if (content.get('data_type').indexOf(options.data_types[i]) != -1) { + if (self._matchType(content.get('data_type'), options.data_types[i])) { found = true; break; } @@ -48,6 +68,26 @@ */ filter: function(filter_id) { return _.first( this.currHistoryContents.filter( function( content ){ return content.get( 'id' ) === filter_id; }) ); + }, + + /** Check if datatypes match + */ + _matchType: function(reference, target) { + // check if target class is available + var target_class = this.typedict.ext_to_class_name[target]; + if (!target_class) { + console.debug('tools-datasets::_matchType() - Specific target class unavailable. Accepting all formats.'); + return true; + } + + // check reference group + var reference_group = this.typedict.class_to_classes[reference]; + if (reference_group[target_class]) { + return true; + } + + // classes do not match + return false; } }); }); \ No newline at end of file diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 static/scripts/packed/mvc/tools/tools-datasets.js --- a/static/scripts/packed/mvc/tools/tools-datasets.js +++ b/static/scripts/packed/mvc/tools/tools-datasets.js @@ -1,1 +1,1 @@ -define(["mvc/history/history-contents"],function(a){return Backbone.Model.extend({initialize:function(c){this.currHistoryContents=new a.HistoryContents({});this.currHistoryContents.historyId=c.history_id;var b=this;var d=this.currHistoryContents.fetchAllDetails().done(function(){console.debug("tools-datasets::initialize() - Completed.");c.success&&c.success()}).fail(function(){console.debug("tools-datasets::initialize() - Ajax request failed.")})},filterType:function(b){b=b||{};return this.currHistoryContents.filter(function(d){var e=false;for(var c in b.data_types){if(d.get("data_type").indexOf(b.data_types[c])!=-1){e=true;break}}return(d.get("history_content_type")===b.content_type||!b.content_type)&&(e||!b.data_types)&&!d.get("deleted")})},filter:function(b){return _.first(this.currHistoryContents.filter(function(c){return c.get("id")===b}))}})}); \ No newline at end of file +define(["mvc/history/history-contents","utils/utils"],function(b,a){return Backbone.Model.extend({initialize:function(d){this.currHistoryContents=new b.HistoryContents({});this.currHistoryContents.historyId=d.history_id;this.typedict={};var c=this;a.get(galaxy_config.root+"api/datatypes/mapping",function(e){c.typedict=e;var f=c.currHistoryContents.fetchAllDetails().done(function(){console.debug("tools-datasets::initialize() - Completed.");d.success&&d.success()}).fail(function(){console.debug("tools-datasets::initialize() - Ajax request for history datasets failed.")})},function(e){console.debug("tools-datasets::initialize() - Ajax request for datatype dictionary failed.")})},filterType:function(d){d=d||{};var c=this;return this.currHistoryContents.filter(function(f){var g=false;for(var e in d.data_types){if(c._matchType(f.get("data_type"),d.data_types[e])){g=true;break}}return(f.get("history_content_type")===d.content_type||!d.content_type)&&(g||!d.data_types)&&!f.get("deleted")})},filter:function(c){return _.first(this.currHistoryContents.filter(function(d){return d.get("id")===c}))},_matchType:function(c,f){var d=this.typedict.ext_to_class_name[f];if(!d){console.debug("tools-datasets::_matchType() - Specific target class unavailable. Accepting all formats.");return true}var e=this.typedict.class_to_classes[c];if(e[d]){return true}return false}})}); \ No newline at end of file diff -r 09aa10faa300c54071abff167f301dade9b76b95 -r a3d10d4db962d762d045bf3e46163508d3572e95 templates/webapps/galaxy/workflow/editor.mako --- a/templates/webapps/galaxy/workflow/editor.mako +++ b/templates/webapps/galaxy/workflow/editor.mako @@ -41,7 +41,7 @@ // URLs used by galaxy.workflows.js var tool_search_url = "${h.url_for( controller='root', action='tool_search' )}", - get_datatypes_url = "${h.url_for( controller='workflow', action='get_datatypes' )}", + get_datatypes_url = "${h.url_for( '/api/datatypes/mapping' )}", load_workflow_url = "${h.url_for( controller='workflow', action='load_workflow' )}", run_workflow_url = "${h.url_for( controller='root', action='index', workflow_id=trans.security.encode_id(stored.id))}", rename_async_url = "${h.url_for( controller='workflow', action='rename_async', id=trans.security.encode_id(stored.id) )}", 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.