Changeset 334:5e98681489d4

Show
Ignore:
Timestamp:
06/01/07 15:25:19 (2 years ago)
Author:
Dan Blankenberg <dan@bx.psu.edu>
branch:
default
convert_revision:
svn:9bcadc22-80f8-0310-8a53-c8f022958886/galaxy/trunk@1635
Message:

Add the ability to define datatypes in the configuration file.

Datatypes are defined like:
[galaxy:datatypes]
bed = galaxy.datatypes.interval:Bed
png = galaxy.datatypes.images:Image,image/png

where the mime-type (default of text/plain) can be declared after the class name, as is seen with png.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/galaxy/app.py

    r177 r334  
    22 
    33from galaxy import config, db, jobs, util, tools, web 
     4import galaxy.model 
    45import galaxy.model.mapping 
     6import galaxy.datatypes.registry 
    57from galaxy.interfaces import root, tool_runner, proxy, async, admin, user, error, dataset 
    68from galaxy.web import middleware 
     
    1416        self.config.check() 
    1517        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) 
    1621        # Connect up the object model 
    1722        if self.config.database_connection: 
     
    2429                                                    create_tables = True ) 
    2530        # 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
    2732        # Start the job queue 
    2833        self.job_queue = jobs.JobQueue( self ) 
     
    4752        app = kwargs.pop( 'app' ) 
    4853    else: 
    49         app = UniverseApplication( **kwargs ) 
     54        app = UniverseApplication( global_conf = global_conf, **kwargs ) 
    5055    atexit.register( app.shutdown ) 
    5156    # Create the universe WSGI application 
  • lib/galaxy/config.py

    r316 r334  
    66import logging, logging.config 
    77from optparse import OptionParser 
     8import ConfigParser 
    89 
    910log = logging.getLogger( __name__ ) 
     
    4647        self.use_heartbeat = kwargs.get( 'use_heartbeat', False ) 
    4748        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 = [] 
    4859    def get( self, key, default ): 
    4960        return self.config_dict.get( key, default ) 
  • lib/galaxy/datatypes/__init__.py

    r249 r334  
    1 """ 
    2 Contains data definitions 
    3 """ 
    4 import logging 
    5 import data, interval, images, sequence 
    6 from cookbook.patterns import Bunch 
    7  
    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 extension 
    34     """ 
    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 builder  
    41  
    42 def change_datatype( data, ext ): 
    43     data.extension = ext 
    44     data.init_meta() 
    45     if data.has_data(): 
    46         data.set_peek() 
    47     return data 
    48  
    49 def old_change_datatype(data, ext): 
    50     """ 
    51     Creates and returns a new datatype based on an existing data and an extension 
    52     """ 
    53     newdata = factory(ext)(id=data.id) 
    54     for key, value in data.__dict__.items(): 
    55         setattr(newdata, key, value) 
    56     newdata.ext = ext 
    57     return newdata 
  • lib/galaxy/datatypes/data.py

    r141 r334  
    22from galaxy import util 
    33from cgi import escape 
     4import galaxy.datatypes.registry 
    45 
    56log = logging.getLogger(__name__) 
     
    8889    def get_mime(self): 
    8990        """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() ) 
    9792    
    9893    def set_peek(self, dataset): 
  • lib/galaxy/interfaces/root.py

    r279 r334  
    9898             
    9999        if data: 
    100             mime = data.get_mime(
     100            mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower()
    101101            trans.response.set_content_type(mime) 
    102102            if tofile: 
     
    120120        if data: 
    121121            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()
    123123                trans.response.set_content_type(mime) 
    124124                file_name = data.as_bedfile() 
     
    330330        else: 
    331331            for history in histories: 
    332                 new_history = self.copy_history(history
     332                new_history = self.copy_history(history, trans
    333333                new_history.name = history.name+" from "+user.email 
    334334                new_history.user_id = send_to_user.id 
     
    363363            if import_history.user_id == user.id: 
    364364                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
    366366            new_history.name = "imported: "+new_history.name 
    367367            new_history.user_id = user.id 
     
    373373            return trans.fill_template("history_imported.tmpl", history=new_history) 
    374374        elif not user_history.datasets or confirm: 
    375             new_history = self.copy_history(import_history
     375            new_history = self.copy_history(import_history, trans
    376376            new_history.name = "imported: "+new_history.name 
    377377            new_history.user_id = None 
     
    498498        try: 
    499499            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
    501501            ## new_data.parent = None 
    502502            ## history = trans.app.model.History.get( old_data.history_id ) 
     
    552552    # ---- Work methods ----------------------------------------------------- 
    553553     
    554     def copy_dataset(self, src, parent_id=None): 
     554    def copy_dataset(self, src, trans, parent_id=None): 
    555555        des = self.app.model.Dataset() 
    556556        des.flush() 
    557         des = datatypes.change_datatype(des, src.ext) 
     557        des = trans.app.dataset_registry.change_datatype(des, src.ext) 
    558558        des.name = src.name 
    559559        des.info = src.info 
     
    572572        return des 
    573573         
    574     def copy_history(self, src): 
     574    def copy_history(self, src, trans): 
    575575        des = self.app.model.History() 
    576576        des.flush() 
     
    578578        des.user_id = src.user_id 
    579579        for data in src.datasets: 
    580             new_data = self.copy_dataset(data
     580            new_data = self.copy_dataset(data, trans
    581581            des.add_dataset(new_data) 
    582582            new_data.hid = data.hid 
    583583            new_data.flush() 
    584584            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
    586586                new_assoc = self.app.model.DatasetAssociation( child.designation ) 
    587587                new_assoc.child = new_child 
  • lib/galaxy/model/__init__.py

    r242 r334  
    1212from galaxy import util 
    1313import tempfile 
     14import galaxy.datatypes.registry 
     15 
     16datatypes_registry = galaxy.datatypes.registry.Registry() 
     17 
     18def set_datatypes_registry( d_registry ): 
     19    """ 
     20    Set up datatypes_registry 
     21    """ 
     22    datatypes_registry = d_registry 
    1423 
    1524class User( object ): 
     
    170179    @property 
    171180    def datatype( self ): 
    172         return galaxy.datatypes.get_datatype_by_extension( self.extension ) 
     181        return datatypes_registry.get_datatype_by_extension( self.extension ) 
    173182    def get_size( self ): 
    174183        """ 
     
    219228    def get_mime(self): 
    220229        """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() ) 
    228231    def set_peek( self ): 
    229232        return self.datatype.set_peek( self ) 
  • lib/galaxy/tools/__init__.py

    r328 r334  
    2222from galaxy.tools.test import ToolTestBuilder 
    2323from galaxy.tools.actions import DefaultToolAction 
     24import galaxy.datatypes.registry 
    2425 
    2526log = logging.getLogger( __name__ ) 
     
    3334    """ 
    3435 
    35     def __init__( self, config_filename, tool_root_dir ): 
     36    def __init__( self, config_filename, tool_root_dir, datatypes_registry = galaxy.datatypes.registry.Registry() ): 
    3637        """ 
    3738        Create a toolbox from the config file names by `config_filename`, 
     
    4344        self.sections = [] 
    4445        self.tool_root_dir = tool_root_dir 
     46        self.datatypes_registry = datatypes_registry 
    4547        try: 
    4648            self.init_tools( config_filename ) 
     
    8789        else: 
    8890            ToolClass = Tool 
    89         return ToolClass( config_file, root
     91        return ToolClass( config_file, root, datatypes_registry = self.datatypes_registry
    9092         
    9193    def reload( self, tool_id ): 
     
    164166    Represents a computational tool that can be executed through Galaxy.  
    165167    """ 
    166     def __init__( self, config_file, root ): 
     168    def __init__( self, config_file, root, datatypes_registry = galaxy.datatypes.registry.Registry() ): 
    167169        """ 
    168170        Load a tool from the config named by `config_file` 
     
    171173        self.config_file = config_file 
    172174        self.tool_dir = os.path.dirname( config_file ) 
     175        self.datatypes_registry = datatypes_registry 
    173176        # Parse XML element containing configuration 
    174177        self.parse( root ) 
     
    433436        enctypes. 
    434437        """ 
    435         param = ToolParameter.build( self, input_elem
     438        param = ToolParameter.build( self, input_elem, datatypes_registry=self.datatypes_registry
    436439        param_enctype = param.get_required_enctype() 
    437440        if param_enctype: 
  • lib/galaxy/tools/parameters.py

    r301 r334  
    44 
    55import logging, string, sys 
    6 from galaxy import config, datatypes, util, form_builder  
     6from galaxy import config, datatypes, util, form_builder 
     7import galaxy.datatypes.registry 
    78import validation 
    89from elementtree.ElementTree import XML, Element 
     
    106107 
    107108    @classmethod 
    108     def build( cls, tool, param ): 
     109    def build( cls, tool, param, datatypes_registry = galaxy.datatypes.registry.Registry() ): 
    109110        """Factory method to create parameter of correct type""" 
    110111        param_type = param.get("type") 
     
    112113            raise ValueError( "Unknown tool parameter type '%s'" % param_type ) 
    113114        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 ) 
    115120         
    116121class TextToolParameter( ToolParameter ): 
     
    537542    </select> 
    538543    """ 
    539     def __init__( self, tool, elem ): 
     544    def __init__( self, tool, elem, datatypes_registry = galaxy.datatypes.registry.Registry() ): 
    540545        ToolParameter.__init__( self, tool, elem ) 
    541546        # Build tuple of classes for supported data formats 
     
    543548        extensions = elem.get( 'format', 'data' ).split( "," ) 
    544549        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__ ) 
    546551        self.formats = tuple( formats ) 
    547552        self.multiple = str_bool( elem.get( 'multiple', False ) ) 
  • tools/data_source/biomart_filter.py

    r331 r334  
    1212    if data_type == 'text': data_type='interval' #All data from biomart is TSV, assume interval 
    1313    name, data = out_data.items()[0] 
    14     data = datatypes.change_datatype(data, data_type) 
     14    data = app.datatypes_registry.change_datatype(data, data_type) 
    1515    data.name = data_name 
    1616    out_data[name] = data 
  • tools/data_source/encode_import_code.py

    r167 r334  
    118118            data.dbkey = dbkey 
    119119            data.info = data.name 
    120             datatypes.change_datatype( data, file_type ) 
     120            data = app.datatypes_registry.change_datatype( data, file_type ) 
    121121            data.init_meta() 
    122122            data.set_peek() 
  • tools/data_source/hbvar_filter.py

    r331 r334  
    1111    if data_type == 'text': data_type='interval' #All data is TSV, assume interval 
    1212    name, data = out_data.items()[0] 
    13     data = datatypes.change_datatype(data, data_type) 
     13    data = app.datatypes_registry.change_datatype(data, data_type) 
    1414    data.name = data_name 
    1515    out_data[name] = data 
     
    7171             
    7272        else: 
    73             data = datatypes.change_datatype(data, 'tabular') 
     73            data = app.datatypes_registry.change_datatype(data, 'tabular') 
    7474    data.set_peek() 
    7575    data.flush() 
  • tools/data_source/microbial_import_code.py

    r293 r334  
    226226            data.dbkey = dbkey 
    227227            data.info = data.name 
    228             datatypes.change_datatype( data, file_type ) 
     228            data = app.datatypes_registry.change_datatype( data, file_type ) 
    229229            data.init_meta() 
    230230            data.set_peek() 
  • tools/data_source/ucsc_tablebrowser_code.py

    r331 r334  
    2222        try: ext = outputType_to_ext[outputType] 
    2323        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) 
    2726         
    2827        #store ucsc parameters temporarily in output file 
     
    4140    if not isinstance(data.datatype, datatypes.interval.Bed) and isinstance(data.datatype, datatypes.interval.Interval): 
    4241        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') 
    4443    data.set_peek() 
    4544    data.flush() 
  • tools/emboss/emboss_format_corrector.py

    r0 r334  
    22 
    33import operator 
    4 from galaxy import datatypes 
     4#from galaxy import datatypes 
    55 
    66#Properly set file formats after job run 
     
    2626            elif outputType == 'text': 
    2727                outputType = "txt" 
    28             data = datatypes.change_datatype(data, outputType) 
     28            data = app.datatypes_registry.change_datatype(data, outputType) 
    2929            data.flush() 
    3030        data_count+=1 
     
    3636        ext = "html" 
    3737        if wants_plot == "yes": 
    38             data = datatypes.change_datatype(data, ext) 
     38            data = app.datatypes_registry.change_datatype(data, ext) 
    3939            data.flush() 
    4040        data_count+=1 
     
    4646        ext = "png" 
    4747        if wants_plot == "yes": 
    48             data = datatypes.change_datatype(data, ext) 
     48            data = app.datatypes_registry.change_datatype(data, ext) 
    4949            data.flush() 
    5050        data_count+=1 
  • tools/filters/pasteWrapper_code.py

    r0 r334  
    44    for name, data in out_data.items(): 
    55        if data.ext == "bed": 
    6             data = datatypes.change_datatype(data, "interval") 
     6            data = app.datatypes_registry.change_datatype(data, "interval") 
    77            data.flush() 
  • universe_wsgi.ini.sample

    r301 r334  
    106106#document_root = %(here)s/static/light_hatched_style/green 
    107107#document_root = %(here)s/static/old_blue_style 
     108 
     109[galaxy:datatypes] 
     110data = galaxy.datatypes.data:Data,application/octet-stream 
     111bed = galaxy.datatypes.interval:Bed 
     112txt = galaxy.datatypes.data:Text 
     113text = galaxy.datatypes.data:Text 
     114interval = galaxy.datatypes.interval:Interval 
     115tabular = galaxy.datatypes.interval:Tabular 
     116png = galaxy.datatypes.images:Image,image/png 
     117pdf = galaxy.datatypes.images:Image,application/pdf 
     118gif = galaxy.datatypes.images:Image,image/gif 
     119jpg = galaxy.datatypes.images:Image,image/jpeg 
     120fasta = galaxy.datatypes.sequence:Fasta 
     121maf = galaxy.datatypes.sequence:Maf 
     122axt = galaxy.datatypes.sequence:Axt 
     123gff = galaxy.datatypes.interval:Gff 
     124wig = galaxy.datatypes.interval:Wiggle 
     125gmaj.zip = galaxy.datatypes.images:Gmaj,application/zip 
     126laj = galaxy.datatypes.images:Laj 
     127lav = galaxy.datatypes.sequence:Lav 
     128html = galaxy.datatypes.images:Html,text/html 
     129customtrack = galaxy.datatypes.interval:CustomTrack