Changeset 334:5e98681489d4
- Timestamp:
- 06/01/07 15:25:19 (2 years ago)
- Files:
-
- lib/galaxy/app.py (modified) (4 diffs)
- lib/galaxy/config.py (modified) (2 diffs)
- lib/galaxy/datatypes/__init__.py (modified) (1 diff)
- lib/galaxy/datatypes/data.py (modified) (2 diffs)
- lib/galaxy/datatypes/registry.py (added)
- lib/galaxy/interfaces/root.py (modified) (9 diffs)
- lib/galaxy/model/__init__.py (modified) (3 diffs)
- lib/galaxy/tools/__init__.py (modified) (7 diffs)
- lib/galaxy/tools/parameters.py (modified) (5 diffs)
- tools/data_source/biomart_filter.py (modified) (1 diff)
- tools/data_source/encode_import_code.py (modified) (1 diff)
- tools/data_source/hbvar_filter.py (modified) (2 diffs)
- tools/data_source/microbial_import_code.py (modified) (1 diff)
- tools/data_source/ucsc_tablebrowser_code.py (modified) (2 diffs)
- tools/emboss/emboss_format_corrector.py (modified) (4 diffs)
- tools/filters/pasteWrapper_code.py (modified) (1 diff)
- universe_wsgi.ini.sample (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lib/galaxy/app.py
r177 r334 2 2 3 3 from galaxy import config, db, jobs, util, tools, web 4 import galaxy.model 4 5 import galaxy.model.mapping 6 import galaxy.datatypes.registry 5 7 from galaxy.interfaces import root, tool_runner, proxy, async, admin, user, error, dataset 6 8 from galaxy.web import middleware … … 14 16 self.config.check() 15 17 config.configure_logging( self.config ) 18 #Set up datatypes registry 19 self.datatypes_registry = galaxy.datatypes.registry.Registry(datatypes = self.config.datatypes) 20 galaxy.model.set_datatypes_registry(self.datatypes_registry) 16 21 # Connect up the object model 17 22 if self.config.database_connection: … … 24 29 create_tables = True ) 25 30 # Initialize the tools 26 self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path )31 self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, datatypes_registry = self.datatypes_registry ) 27 32 # Start the job queue 28 33 self.job_queue = jobs.JobQueue( self ) … … 47 52 app = kwargs.pop( 'app' ) 48 53 else: 49 app = UniverseApplication( **kwargs )54 app = UniverseApplication( global_conf = global_conf, **kwargs ) 50 55 atexit.register( app.shutdown ) 51 56 # Create the universe WSGI application lib/galaxy/config.py
r316 r334 6 6 import logging, logging.config 7 7 from optparse import OptionParser 8 import ConfigParser 8 9 9 10 log = logging.getLogger( __name__ ) … … 46 47 self.use_heartbeat = kwargs.get( 'use_heartbeat', False ) 47 48 self.ucsc_display_sites = kwargs.get( 'ucsc_display_sites', "main,test,archaea" ).lower().split(",") 49 #Parse global_conf 50 global_conf = kwargs.get( 'global_conf', None ) 51 global_conf_parser = ConfigParser.ConfigParser() 52 if global_conf and "__file__" in global_conf: 53 global_conf_parser.read(global_conf['__file__']) 54 #Store datatypes 55 try: 56 self.datatypes = global_conf_parser.items("galaxy:datatypes") 57 except ConfigParser.NoSectionError: 58 self.datatypes = [] 48 59 def get( self, key, default ): 49 60 return self.config_dict.get( key, default ) lib/galaxy/datatypes/__init__.py
r249 r334 1 """2 Contains data definitions3 """4 import logging5 import data, interval, images, sequence6 from cookbook.patterns import Bunch7 8 log = logging.getLogger(__name__)9 10 datatypes_by_extension = {11 'data' : data.Data(),12 'bed' : interval.Bed(),13 'txt' : data.Text(),14 'text' : data.Text(),15 'interval' : interval.Interval(),16 'tabular' : interval.Tabular(),17 'png' : images.Image(),18 'pdf' : images.Image(),19 'fasta' : sequence.Fasta(),20 'maf' : sequence.Maf(),21 'axt' : sequence.Axt(),22 'gff' : interval.Gff(),23 'wig' : interval.Wiggle(),24 'gmaj.zip' : images.Gmaj(),25 'laj' : images.Laj(),26 'lav' : sequence.Lav(),27 'html' : images.Html(),28 'customtrack' : interval.CustomTrack()29 }30 31 def get_datatype_by_extension( ext ):32 """33 Returns a datatype based on an extension34 """35 try:36 builder = datatypes_by_extension[ext]37 except KeyError:38 builder = data.Text()39 log.warning('unkown extension in data factory %s' % ext)40 return builder41 42 def change_datatype( data, ext ):43 data.extension = ext44 data.init_meta()45 if data.has_data():46 data.set_peek()47 return data48 49 def old_change_datatype(data, ext):50 """51 Creates and returns a new datatype based on an existing data and an extension52 """53 newdata = factory(ext)(id=data.id)54 for key, value in data.__dict__.items():55 setattr(newdata, key, value)56 newdata.ext = ext57 return newdatalib/galaxy/datatypes/data.py
r141 r334 2 2 from galaxy import util 3 3 from cgi import escape 4 import galaxy.datatypes.registry 4 5 5 6 log = logging.getLogger(__name__) … … 88 89 def get_mime(self): 89 90 """Returns the mime type of the data""" 90 try: 91 ext = self.ext.lower() 92 if ext in util.text_types: 93 return 'text/plain' 94 return util.mime_types[ext] 95 except KeyError: 96 return 'application/octet-stream' 91 return galaxy.datatypes.registry.Registry().get_mimetype_by_extension( self.extension.lower() ) 97 92 98 93 def set_peek(self, dataset): lib/galaxy/interfaces/root.py
r279 r334 98 98 99 99 if data: 100 mime = data.get_mime()100 mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() ) 101 101 trans.response.set_content_type(mime) 102 102 if tofile: … … 120 120 if data: 121 121 if isinstance(data.datatype, datatypes.interval.Interval) or isinstance(data.datatype, datatypes.interval.CustomTrack): 122 mime = data.get_mime()122 mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() ) 123 123 trans.response.set_content_type(mime) 124 124 file_name = data.as_bedfile() … … 330 330 else: 331 331 for history in histories: 332 new_history = self.copy_history(history )332 new_history = self.copy_history(history, trans) 333 333 new_history.name = history.name+" from "+user.email 334 334 new_history.user_id = send_to_user.id … … 363 363 if import_history.user_id == user.id: 364 364 return trans.show_error_message( "You cannot import your own history.") 365 new_history = self.copy_history(import_history )365 new_history = self.copy_history(import_history, trans) 366 366 new_history.name = "imported: "+new_history.name 367 367 new_history.user_id = user.id … … 373 373 return trans.fill_template("history_imported.tmpl", history=new_history) 374 374 elif not user_history.datasets or confirm: 375 new_history = self.copy_history(import_history )375 new_history = self.copy_history(import_history, trans) 376 376 new_history.name = "imported: "+new_history.name 377 377 new_history.user_id = None … … 498 498 try: 499 499 old_data = self.app.model.Dataset.get( id ) 500 new_data = self.copy_dataset(old_data )500 new_data = self.copy_dataset(old_data, trans) 501 501 ## new_data.parent = None 502 502 ## history = trans.app.model.History.get( old_data.history_id ) … … 552 552 # ---- Work methods ----------------------------------------------------- 553 553 554 def copy_dataset(self, src, parent_id=None):554 def copy_dataset(self, src, trans, parent_id=None): 555 555 des = self.app.model.Dataset() 556 556 des.flush() 557 des = datatypes.change_datatype(des, src.ext)557 des = trans.app.dataset_registry.change_datatype(des, src.ext) 558 558 des.name = src.name 559 559 des.info = src.info … … 572 572 return des 573 573 574 def copy_history(self, src ):574 def copy_history(self, src, trans): 575 575 des = self.app.model.History() 576 576 des.flush() … … 578 578 des.user_id = src.user_id 579 579 for data in src.datasets: 580 new_data = self.copy_dataset(data )580 new_data = self.copy_dataset(data, trans) 581 581 des.add_dataset(new_data) 582 582 new_data.hid = data.hid 583 583 new_data.flush() 584 584 for child_assoc in data.children: 585 new_child = self.copy_dataset(child_assoc.child )585 new_child = self.copy_dataset(child_assoc.child, trans) 586 586 new_assoc = self.app.model.DatasetAssociation( child.designation ) 587 587 new_assoc.child = new_child lib/galaxy/model/__init__.py
r242 r334 12 12 from galaxy import util 13 13 import tempfile 14 import galaxy.datatypes.registry 15 16 datatypes_registry = galaxy.datatypes.registry.Registry() 17 18 def set_datatypes_registry( d_registry ): 19 """ 20 Set up datatypes_registry 21 """ 22 datatypes_registry = d_registry 14 23 15 24 class User( object ): … … 170 179 @property 171 180 def datatype( self ): 172 return galaxy.datatypes.get_datatype_by_extension( self.extension )181 return datatypes_registry.get_datatype_by_extension( self.extension ) 173 182 def get_size( self ): 174 183 """ … … 219 228 def get_mime(self): 220 229 """Returns the mime type of the data""" 221 try: 222 ext = self.extension.lower() 223 if ext in util.text_types: 224 return 'text/plain' 225 return util.mime_types[ext] 226 except KeyError: 227 return 'application/octet-stream' 230 return datatypes_registry.get_mimetype_by_extension( self.extension.lower() ) 228 231 def set_peek( self ): 229 232 return self.datatype.set_peek( self ) lib/galaxy/tools/__init__.py
r328 r334 22 22 from galaxy.tools.test import ToolTestBuilder 23 23 from galaxy.tools.actions import DefaultToolAction 24 import galaxy.datatypes.registry 24 25 25 26 log = logging.getLogger( __name__ ) … … 33 34 """ 34 35 35 def __init__( self, config_filename, tool_root_dir ):36 def __init__( self, config_filename, tool_root_dir, datatypes_registry = galaxy.datatypes.registry.Registry() ): 36 37 """ 37 38 Create a toolbox from the config file names by `config_filename`, … … 43 44 self.sections = [] 44 45 self.tool_root_dir = tool_root_dir 46 self.datatypes_registry = datatypes_registry 45 47 try: 46 48 self.init_tools( config_filename ) … … 87 89 else: 88 90 ToolClass = Tool 89 return ToolClass( config_file, root )91 return ToolClass( config_file, root, datatypes_registry = self.datatypes_registry ) 90 92 91 93 def reload( self, tool_id ): … … 164 166 Represents a computational tool that can be executed through Galaxy. 165 167 """ 166 def __init__( self, config_file, root ):168 def __init__( self, config_file, root, datatypes_registry = galaxy.datatypes.registry.Registry() ): 167 169 """ 168 170 Load a tool from the config named by `config_file` … … 171 173 self.config_file = config_file 172 174 self.tool_dir = os.path.dirname( config_file ) 175 self.datatypes_registry = datatypes_registry 173 176 # Parse XML element containing configuration 174 177 self.parse( root ) … … 433 436 enctypes. 434 437 """ 435 param = ToolParameter.build( self, input_elem )438 param = ToolParameter.build( self, input_elem, datatypes_registry=self.datatypes_registry ) 436 439 param_enctype = param.get_required_enctype() 437 440 if param_enctype: lib/galaxy/tools/parameters.py
r301 r334 4 4 5 5 import logging, string, sys 6 from galaxy import config, datatypes, util, form_builder 6 from galaxy import config, datatypes, util, form_builder 7 import galaxy.datatypes.registry 7 8 import validation 8 9 from elementtree.ElementTree import XML, Element … … 106 107 107 108 @classmethod 108 def build( cls, tool, param ):109 def build( cls, tool, param, datatypes_registry = galaxy.datatypes.registry.Registry() ): 109 110 """Factory method to create parameter of correct type""" 110 111 param_type = param.get("type") … … 112 113 raise ValueError( "Unknown tool parameter type '%s'" % param_type ) 113 114 else: 114 return parameter_types[param_type]( tool, param ) 115 #data parameter requires datatypes_registry 116 if param_type in ['data']: 117 return parameter_types[param_type]( tool, param, datatypes_registry = datatypes_registry ) 118 else: 119 return parameter_types[param_type]( tool, param ) 115 120 116 121 class TextToolParameter( ToolParameter ): … … 537 542 </select> 538 543 """ 539 def __init__( self, tool, elem ):544 def __init__( self, tool, elem, datatypes_registry = galaxy.datatypes.registry.Registry() ): 540 545 ToolParameter.__init__( self, tool, elem ) 541 546 # Build tuple of classes for supported data formats … … 543 548 extensions = elem.get( 'format', 'data' ).split( "," ) 544 549 for extension in extensions: 545 formats.append( datatypes .get_datatype_by_extension( extension.lower() ).__class__ )550 formats.append( datatypes_registry.get_datatype_by_extension( extension.lower() ).__class__ ) 546 551 self.formats = tuple( formats ) 547 552 self.multiple = str_bool( elem.get( 'multiple', False ) ) tools/data_source/biomart_filter.py
r331 r334 12 12 if data_type == 'text': data_type='interval' #All data from biomart is TSV, assume interval 13 13 name, data = out_data.items()[0] 14 data = datatypes.change_datatype(data, data_type)14 data = app.datatypes_registry.change_datatype(data, data_type) 15 15 data.name = data_name 16 16 out_data[name] = data tools/data_source/encode_import_code.py
r167 r334 118 118 data.dbkey = dbkey 119 119 data.info = data.name 120 data types.change_datatype( data, file_type )120 data = app.datatypes_registry.change_datatype( data, file_type ) 121 121 data.init_meta() 122 122 data.set_peek() tools/data_source/hbvar_filter.py
r331 r334 11 11 if data_type == 'text': data_type='interval' #All data is TSV, assume interval 12 12 name, data = out_data.items()[0] 13 data = datatypes.change_datatype(data, data_type)13 data = app.datatypes_registry.change_datatype(data, data_type) 14 14 data.name = data_name 15 15 out_data[name] = data … … 71 71 72 72 else: 73 data = datatypes.change_datatype(data, 'tabular')73 data = app.datatypes_registry.change_datatype(data, 'tabular') 74 74 data.set_peek() 75 75 data.flush() tools/data_source/microbial_import_code.py
r293 r334 226 226 data.dbkey = dbkey 227 227 data.info = data.name 228 data types.change_datatype( data, file_type )228 data = app.datatypes_registry.change_datatype( data, file_type ) 229 229 data.init_meta() 230 230 data.set_peek() tools/data_source/ucsc_tablebrowser_code.py
r331 r334 22 22 try: ext = outputType_to_ext[outputType] 23 23 except: pass 24 if ext not in datatypes.datatypes_by_extension: ext = 'interval' 25 26 data = datatypes.change_datatype(data, ext) 24 if ext not in app.datatypes_registry.datatypes_by_extension: ext = 'interval' 25 data = app.datatypes_registry.change_datatype(data, ext) 27 26 28 27 #store ucsc parameters temporarily in output file … … 41 40 if not isinstance(data.datatype, datatypes.interval.Bed) and isinstance(data.datatype, datatypes.interval.Interval): 42 41 data.set_meta() 43 if data.missing_meta(): data = datatypes.change_datatype(data, 'tabular')42 if data.missing_meta(): data = app.datatypes_registry.change_datatype(data, 'tabular') 44 43 data.set_peek() 45 44 data.flush() tools/emboss/emboss_format_corrector.py
r0 r334 2 2 3 3 import operator 4 from galaxy import datatypes4 #from galaxy import datatypes 5 5 6 6 #Properly set file formats after job run … … 26 26 elif outputType == 'text': 27 27 outputType = "txt" 28 data = datatypes.change_datatype(data, outputType)28 data = app.datatypes_registry.change_datatype(data, outputType) 29 29 data.flush() 30 30 data_count+=1 … … 36 36 ext = "html" 37 37 if wants_plot == "yes": 38 data = datatypes.change_datatype(data, ext)38 data = app.datatypes_registry.change_datatype(data, ext) 39 39 data.flush() 40 40 data_count+=1 … … 46 46 ext = "png" 47 47 if wants_plot == "yes": 48 data = datatypes.change_datatype(data, ext)48 data = app.datatypes_registry.change_datatype(data, ext) 49 49 data.flush() 50 50 data_count+=1 tools/filters/pasteWrapper_code.py
r0 r334 4 4 for name, data in out_data.items(): 5 5 if data.ext == "bed": 6 data = datatypes.change_datatype(data, "interval")6 data = app.datatypes_registry.change_datatype(data, "interval") 7 7 data.flush() universe_wsgi.ini.sample
r301 r334 106 106 #document_root = %(here)s/static/light_hatched_style/green 107 107 #document_root = %(here)s/static/old_blue_style 108 109 [galaxy:datatypes] 110 data = galaxy.datatypes.data:Data,application/octet-stream 111 bed = galaxy.datatypes.interval:Bed 112 txt = galaxy.datatypes.data:Text 113 text = galaxy.datatypes.data:Text 114 interval = galaxy.datatypes.interval:Interval 115 tabular = galaxy.datatypes.interval:Tabular 116 png = galaxy.datatypes.images:Image,image/png 117 pdf = galaxy.datatypes.images:Image,application/pdf 118 gif = galaxy.datatypes.images:Image,image/gif 119 jpg = galaxy.datatypes.images:Image,image/jpeg 120 fasta = galaxy.datatypes.sequence:Fasta 121 maf = galaxy.datatypes.sequence:Maf 122 axt = galaxy.datatypes.sequence:Axt 123 gff = galaxy.datatypes.interval:Gff 124 wig = galaxy.datatypes.interval:Wiggle 125 gmaj.zip = galaxy.datatypes.images:Gmaj,application/zip 126 laj = galaxy.datatypes.images:Laj 127 lav = galaxy.datatypes.sequence:Lav 128 html = galaxy.datatypes.images:Html,text/html 129 customtrack = galaxy.datatypes.interval:CustomTrack