Changeset 410:d064aa689bb5

Show
Ignore:
Timestamp:
07/11/07 13:36:54 (1 year ago)
Author:
Dan Blankenberg <dan@bx.psu.edu>
branch:
default
convert_revision:
svn:9bcadc22-80f8-0310-8a53-c8f022958886/galaxy/trunk@1718
Message:

A bunch of changes to datatypes, including a generic interface for adding display applications.

To add a display app, override the datatypes init method, adding display apps in the form of
self.add_display_app ( app_id, label, file_function, links_function )

where

app_id is a unique id
label is the primary display label, ie display at 'UCSC'
file_function is a string containing the name of the function that returns a properly formated display
links_function is a string containing the name of the function that returns a list of (link_name,link)

See the Interval datatype for an example:

def init(self, **kwd):

"""Initialize interval datatype, by adding UCSC display apps"""
Tabular.init(self, **kwd)
self.add_display_app ( 'ucsc', 'display at UCSC', 'as_ucsc_display_file', 'ucsc_links' )

Files:

Legend:

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

    r400 r410  
    3434    __metaclass__ = DataMeta 
    3535     
    36     """Provide the set of display formats supported by this datatype """ 
    37     supported_display_apps = [] 
    38  
    39     def set_peek( self, dataset ): 
    40         dataset.peek  = '' 
    41         dataset.blurb = 'data' 
     36    """Stores the set of display applications, and viewing methods, supported by this datatype """ 
     37    supported_display_apps = {} 
     38     
     39    def __init__(self, **kwd): 
     40        """Initialize the datatype""" 
     41        object.__init__(self, **kwd) 
     42        self.supported_display_apps = self.supported_display_apps.copy() 
     43     
     44    def write_from_stream(self, dataset, stream): 
     45        """Writes data from a stream""" 
     46        fd = open(dataset.file_name, 'wb') 
     47        while 1: 
     48            chunk = stream.read(1048576) 
     49            if not chunk: 
     50                break 
     51            os.write(fd, chunk) 
     52        os.close(fd) 
     53 
     54    def set_raw_data(self, dataset, data): 
     55        """Saves the data on the disc""" 
     56        fd = open(dataset.file_name, 'wb') 
     57        os.write(fd, data) 
     58        os.close(fd) 
     59     
     60    def get_raw_data( self, dataset ): 
     61        """Returns the full data. To stream it open the file_name and read/write as needed""" 
     62        try: 
     63            return file(datset.file_name, 'rb').read(-1) 
     64        except OSError, e: 
     65            log.exception('%s reading a file that does not exist %s' % (self.__class__.__name__, dataset.file_name)) 
     66            return '' 
     67 
    4268    def init_meta( self, dataset, copy_from=None ): 
    4369        # Metadata should be left mostly uninitialized.  Dataset will 
     
    4975        if copy_from: 
    5076            dataset.metadata = copy_from.metadata 
     77    def set_meta( self, dataset ): 
     78        """Unimplemented method, allows guessing of metadata from contents of file""" 
     79        return True 
    5180    def missing_meta( self, dataset): 
     81        """Unimplemented method, Returns True if metadata is missing""" 
    5282        return False 
    53     def get_estimated_display_viewport( self, dataset ): 
    54         raise Exception( "'get_estimated_display_viewport' must be overridden in subclass." ) 
    55     def as_ucsc_display_file( self, dataset ): 
    56         raise Exception( "'as_ucsc_display_file' not supported for this datatype" ) 
    57     def as_gbrowse_display_file( self, dataset ): 
    58         raise Exception( "'as_gbrowse_display_file' not supported for this datatype" ) 
     83    def set_peek( self, dataset ): 
     84        """Set the peek and blurb text""" 
     85        dataset.peek  = '' 
     86        dataset.blurb = 'data' 
    5987    def display_peek(self, dataset): 
     88        """Returns formated html of peek""" 
    6089        try: 
    6190            return escape(dataset.peek) 
     
    6392            return "peek unavailable" 
    6493    def display_name(self, dataset): 
     94        """Returns formated html of dataset name""" 
    6595        try: 
    6696            return escape(dataset.name) 
     
    6898            return "name unavailable" 
    6999    def display_info(self, dataset): 
     100        """Returns formated html of dataset info""" 
    70101        try: 
    71102            return escape(dataset.info) 
    72103        except: 
    73104            return "info unavailable" 
    74     def get_ucsc_sites(self, dataset): 
    75         return util.get_ucsc_by_build(dataset.dbkey) 
    76     def get_gbrowse_sites(self, dataset): 
    77         return util.get_gbrowse_sites_by_build(dataset.dbkey) 
    78105    def validate(self, dataset): 
    79106        """Unimplemented validate, return no exceptions""" 
     
    82109        """Unimplemented method, returns dict with method/option for repairing errors""" 
    83110        return None 
     111    def get_mime(self): 
     112        """Returns the mime type of the datatype""" 
     113        return 'application/octet-stream' 
     114    def add_display_app (self, app_id, label, file_function, links_function ): 
     115        """ 
     116        Adds a display app to the datatype. 
     117        app_id is a unique id 
     118        label is the primary display label, ie display at 'UCSC' 
     119        file_function is a string containing the name of the function that returns a properly formated display 
     120        links_function is a string containing the name of the function that returns a list of (link_name,link) 
     121        """ 
     122        self.supported_display_apps = self.supported_display_apps.copy() 
     123        self.supported_display_apps[app_id] = {'label':label,'file_function':file_function,'links_function':links_function} 
     124    def remove_display_app (self, app_id): 
     125        """Removes a display app from the datatype""" 
     126        self.supported_display_apps = self.supported_display_apps.copy() 
     127        try: 
     128            del self.supported_display_apps[app_id] 
     129        except: 
     130            log.exception('Tried to remove display app %s from datatype %s, but this display app is not declared.' % ( type, self.__class__.__name__ ) ) 
     131    def get_display_types(self): 
     132        """Returns display types available""" 
     133        return self.supported_display_apps.keys() 
     134    def get_display_label(self, type): 
     135        """Returns primary label for display app""" 
     136        try: 
     137            return self.supported_display_apps[type]['label'] 
     138        except: 
     139            return 'unknown' 
     140    def as_display_type(self, dataset, type, **kwd): 
     141        """Returns modified file contents for a particular display type """ 
     142        try: 
     143            if type in self.get_display_types(): 
     144                return getattr (self, self.supported_display_apps[type]['file_function']) (dataset, **kwd) 
     145        except: 
     146            log.exception('Function %s is referred to in datatype %s for displaying as type %s, but is not accessible' % (self.supported_display_apps[type]['file_function'], self.__class__.__name__, type) ) 
     147        return "This display type (%s) is not implemented for this datatype (%s)." % ( type, dataset.ext) 
     148         
     149    def get_display_links(self, dataset, type, app, base_url, **kwd): 
     150        """Returns a list of tuples of (name, link) for a particular display type """ 
     151        try: 
     152            if type in self.get_display_types(): 
     153                return getattr (self, self.supported_display_apps[type]['links_function']) (dataset, type, app, base_url, **kwd) 
     154        except: 
     155            log.exception('Function %s is referred to in datatype %s for generating links for type %s, but is not accessible' % (self.supported_display_apps[type]['links_function'], self.__class__.__name__, type) ) 
     156        return [] 
    84157 
    85158class Text( Data ): 
    86159 
    87     """Provide the set of display formats supported by this datatype """ 
    88     supported_display_apps = [] 
    89  
    90     def write_from_stream(self, stream): 
    91         "Writes data from a stream" 
     160    def write_from_stream(self, dataset, stream): 
     161        """Writes data from a stream""" 
    92162        # write it twice for now  
    93163        fd, temp_name = tempfile.mkstemp() 
     
    100170 
    101171        # rewrite the file with unix newlines 
    102         fp = open(self.file_name, 'wt') 
     172        fp = open(dataset.file_name, 'wt') 
    103173        for line in file(temp_name, "U"): 
    104174            line = line.strip() + '\n' 
     
    106176        fp.close() 
    107177 
    108     def set_raw_data(self, data): 
     178    def set_raw_data(self, dataset, data): 
    109179        """Saves the data on the disc""" 
    110180        fd, temp_name = tempfile.mkstemp() 
     
    113183 
    114184        # rewrite the file with unix newlines 
    115         fp = open(self.file_name, 'wt') 
     185        fp = open(dataset.file_name, 'wt') 
    116186        for line in file(temp_name, "U"): 
    117187            line = line.strip() + '\n' 
     
    120190 
    121191        os.remove( temp_name ) 
    122  
    123     def delete(self): 
    124         """Remove the file that corresponds to this data""" 
    125         obj.DBObj.delete(self) 
    126         try: 
    127             os.remove(self.file_name) 
    128         except OSError, e: 
    129             log.critical('%s delete error %s' % (self.__class__.__name__, e)) 
    130  
    131 # Removed for now ... this should be handled specifically by the registry 
    132 ##     def get_mime(self): 
    133 ##         """Returns the mime type of the data""" 
    134 ##         return galaxy.datatypes.registry.Registry().get_mimetype_by_extension( self.extension.lower() ) 
     192     
     193    def get_mime(self): 
     194        """Returns the mime type of the datatype""" 
     195        return 'text/plain' 
    135196    
    136197    def set_peek(self, dataset): 
     
    141202    """Binary data""" 
    142203 
    143     """Provide the set of display formats supported by this datatype """ 
    144     supported_display_apps = [] 
    145  
    146204    def set_peek( self, dataset ): 
     205        """Set the peek and blurb text""" 
    147206        dataset.peek  = 'binary data' 
    148207        dataset.blurb = 'data' 
  • lib/galaxy/datatypes/images.py

    r1 r410  
    1515        dataset.blurb = 'image'  
    1616 
     17 
    1718class Gmaj( data.Data ): 
    1819    """Class describing a GMAJ Applet""" 
     
    2627        except: 
    2728            return "peek unavailable" 
    28              
     29    def get_mime(self): 
     30        """Returns the mime type of the datatype""" 
     31        return 'application/zip' 
     32 
     33 
    2934class Laj( data.Text ): 
    3035    """Class describing a LAJ Applet""" 
     
    4651        dataset.blurb = data.nice_size( dataset.get_size() ) 
    4752         
    48     def display_peek(self, dataset): 
    49         try: 
    50             return dataset.peek 
    51         except: 
    52             return "peek unavailable" 
     53    def get_mime(self): 
     54        """Returns the mime type of the datatype""" 
     55        return 'text/html' 
  • lib/galaxy/datatypes/interval.py

    r408 r410  
    1010from galaxy import util 
    1111from cgi import escape 
     12import urllib 
    1213from bx.intervals.io import * 
    1314from galaxy.datatypes.metadata import MetadataElement 
     
    3637    """Tab delimited data containing interval information""" 
    3738 
    38     """Provide the set of display formats supported by this datatype """ 
    39     supported_display_apps = ['ucsc'] 
    40  
    4139    """Add metadata elements""" 
    4240    MetadataElement( name="chromCol" ) 
     
    4543    MetadataElement( name="strandCol" ) 
    4644 
     45 
     46    def __init__(self, **kwd): 
     47        """Initialize interval datatype, by adding UCSC display apps""" 
     48        Tabular.__init__(self, **kwd) 
     49        self.add_display_app ( 'ucsc', 'display at UCSC', 'as_ucsc_display_file', 'ucsc_links' ) 
     50     
    4751    def missing_meta( self, dataset ): 
    4852        """Checks for empty meta values""" 
     
    5357        return False 
    5458     
    55      
    5659    def init_meta( self, dataset, copy_from=None ): 
    5760        Tabular.init_meta( self, dataset, copy_from=copy_from ) 
    5861        for key in alias_spec: 
    5962            setattr( dataset.metadata, key, '' )  
    60         setattr( dataset.metadata, 'strandCol', '0' )                  
     63        setattr( dataset.metadata, 'strandCol', '0' ) 
    6164     
    6265    def set_peek( self, dataset ): 
     66        """Set the peek and blurb text""" 
    6367        dataset.peek  = data.get_file_peek( dataset.file_name ) 
    6468        ## dataset.peek  = self.make_html_table( dataset.peek ) 
    6569        dataset.blurb = util.commaify( str( data.get_line_count( dataset.file_name ) ) ) + " regions" 
     70        #i don't think set_meta should not be called here, it should be called separately 
    6671        self.set_meta( dataset ) 
    6772     
     
    8691                            del valid[lower]  # removes lower priority keys  
    8792                dataset.mark_metadata_changed() 
    88  
     93     
    8994    def get_estimated_display_viewport( self, dataset ): 
    9095        """Return a chrom, start, stop tuple for viewing a file.""" 
     
    108113                        stop  = max( stop, int( p[e] ) ) 
    109114            except Exception, exc: 
    110                 log.error( 'Viewport generation error -> %s ' % str(exc) ) 
     115                #log.error( 'Viewport generation error -> %s ' % str(exc) ) 
    111116                (chr, start, stop) = 'chr1', 1, 1000 
    112117            return (chr, str( start ), str( stop ))  
     
    114119            return ('', '', '') 
    115120 
    116     def as_ucsc_display_file( self, dataset ): 
    117         """Returns a file that contains only the bed data""" 
     121    def as_ucsc_display_file( self, dataset, **kwd ): 
     122        """Returns file contents with only the bed data""" 
    118123        fd, temp_name = tempfile.mkstemp() 
    119124        c, s, e, t = dataset.metadata.chromCol, dataset.metadata.startCol, dataset.metadata.endCol, dataset.metadata.strandCol  
     
    130135                os.write(fd, '%s\n' % '\t'.join(tmp) )     
    131136        os.close(fd) 
    132         return temp_name 
     137        return open(temp_name) 
     138 
     139    def ucsc_links( self, dataset, type, app, base_url ): 
     140        ret_val = [] 
     141        if dataset.has_data: 
     142            viewport_tuple = self.get_estimated_display_viewport(dataset) 
     143            if viewport_tuple: 
     144                chrom = viewport_tuple[0] 
     145                start = viewport_tuple[1] 
     146                stop = viewport_tuple[2] 
     147                for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey): 
     148                    if site_name in app.config.ucsc_display_sites: 
     149                        display_url = urllib.quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) 
     150                        link = "%sdb=%s&position=%s:%s-%s&hgt.customText=%s" % (site_url, dataset.dbkey, chrom, start, stop, display_url ) 
     151                        ret_val.append( (site_name, link) ) 
     152        return ret_val 
    133153 
    134154    def validate( self, dataset ): 
     
    161181    """Tab delimited data in BED format""" 
    162182 
    163     """Provide the set of display formats supported by this datatype """ 
    164     supported_display_apps = ['ucsc'] 
    165  
    166  
    167183    """Add metadata elements""" 
    168184    MetadataElement( name="chromCol", default=1 ) 
     
    177193    def init_meta( self, dataset, copy_from=None ): 
    178194        Interval.init_meta( self, dataset, copy_from=copy_from ) 
    179          
     195     
    180196    def set_meta( self, dataset ): 
    181197        """ 
     
    201217            dataset.mark_metadata_changed() 
    202218         
    203     def as_ucsc_display_file( self, dataset ): 
    204         """Returns a file that contains only the bed data. If bed 6+, treat as interval.""" 
     219    def as_ucsc_display_file( self, dataset, **kwd ): 
     220        """Returns file contents with only the bed data. If bed 6+, treat as interval.""" 
    205221        for line in open(dataset.file_name): 
    206222            line = line.strip() 
     
    233249            break 
    234250             
    235         try: return dataset.file_name 
     251        try: return open(dataset.file_name) 
    236252        except: return "This item contains no content" 
    237  
    238     def get_estimated_display_viewport( self, dataset ): 
    239         #TODO: fix me... 
    240         return Interval.get_estimated_display_viewport( self, dataset ) 
    241253 
    242254class Gff( Tabular ): 
    243255    """Tab delimited data in Gff format""" 
    244256 
    245     """Provide the set of display formats supported by this datatype """ 
    246     supported_display_apps = ['gbrowse'] 
    247  
    248     def __init__(self, id=None): 
    249         data.Text.__init__(self, id=id) 
     257    def __init__(self, **kwd): 
     258        """Initialize datatype, by adding GBrowse display app""" 
     259        Tabular.__init__(self, **kwd) 
     260        self.add_display_app ('gbrowse', 'display in GBrowse', 'as_gbrowse_display_file', 'gbrowse_links' ) 
    250261     
    251262    def make_html_table(self, data): 
    252263        return Tabular.make_html_table(self, data, skipchar='#') 
    253264     
    254     def as_gbrowse_display_file( self, dataset ): 
    255         '''Returns a file that can be displayed in GBrowse apps.''' 
     265    def as_gbrowse_display_file( self, dataset, **kwd ): 
     266        """Returns file contents that can be displayed in GBrowse apps.""" 
    256267        #TODO: fix me... 
    257         return dataset.file_name 
     268        return open(dataset.file_name) 
    258269 
    259270    def get_estimated_display_viewport( self, dataset ): 
     
    290301                        stop  = max( stop, int( p[stop_col] ) ) 
    291302            except Exception, exc: 
    292                 log.error( 'Viewport generation error -> %s ' % str(exc) ) 
     303                #log.error( 'Viewport generation error -> %s ' % str(exc) ) 
    293304                seqid, start, stop = ('', '', '')  
    294305            return (seqid, str( start ), str( stop )) 
     
    296307            return ('', '', '') 
    297308 
     309    def gbrowse_links( self, dataset, type, app, base_url ): 
     310        ret_val = [] 
     311        if dataset.has_data: 
     312            viewport_tuple = self.get_estimated_display_viewport(dataset) 
     313            if viewport_tuple: 
     314                chrom = viewport_tuple[0] 
     315                start = viewport_tuple[1] 
     316                stop = viewport_tuple[2] 
     317                for site_name, site_url in util.get_gbrowse_sites_by_build(dataset.dbkey): 
     318                    if site_name in app.config.gbrowse_display_sites: 
     319                        display_url = urllib.quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) 
     320                        link = "%sname=%s&ref=%s:%s..%s&eurl=%s" % (site_url, dataset.dbkey, chrom, start, stop, display_url )                         
     321                        ret_val.append( (site_name, link) ) 
     322        return ret_val 
     323 
    298324class Wiggle( Tabular ): 
    299325    """Tab delimited data in wiggle format""" 
    300  
    301     """Provide the set of display formats supported by this datatype """ 
    302     supported_display_apps = [] 
    303  
    304     def __init__(self, id=None): 
    305         data.Text.__init__(self, id=id) 
    306326     
    307327    def make_html_table(self, data): 
    308328        return Tabular.make_html_table(self, data, skipchar='#') 
    309  
    310     def get_estimated_display_viewport( self, dataset ): 
    311         #TODO: fix me... 
    312         return ('', '', '') 
    313329     
    314330#Extend Tabular type, since interval tools will fail on track def line (we should fix this) 
     
    316332class CustomTrack ( Tabular ): 
    317333    """UCSC CustomTrack""" 
    318  
    319     """Provide the set of display formats supported by this datatype """ 
    320     supported_display_apps = ['ucsc'] 
    321  
    322     def __init__(self, id=None): 
    323         data.Text.__init__(self, id=id) 
     334     
     335    def __init__(self, **kwd): 
     336        """Initialize interval datatype, by adding UCSC display app""" 
     337        Tabular.__init__(self, **kwd) 
     338        self.add_display_app ( 'ucsc', 'display at UCSC', 'as_ucsc_display_file', 'ucsc_links' ) 
    324339     
    325340    def make_html_table(self, dataset): 
    326341        return Tabular.make_html_table(self, dataset, skipchar='track') 
    327      
    328342    def get_estimated_display_viewport( self, dataset ): 
    329343        try: 
     
    345359     
    346360    def as_ucsc_display_file( self, dataset ): 
    347         return dataset.file_name 
     361        return open(dataset.file_name) 
     362    def ucsc_links( self, dataset, type, app, base_url ): 
     363        ret_val = [] 
     364        if dataset.has_data: 
     365            viewport_tuple = self.get_estimated_display_viewport(dataset) 
     366            if viewport_tuple: 
     367                chrom = viewport_tuple[0] 
     368                start = viewport_tuple[1] 
     369                stop = viewport_tuple[2] 
     370                for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey): 
     371                    if site_name in app.config.ucsc_display_sites: 
     372                        display_url = urllib.quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) 
     373                        link = "%sdb=%s&position=%s:%s-%s&hgt.customText=%s" % (site_url, dataset.dbkey, chrom, start, stop, display_url ) 
     374                        ret_val.append( (site_name, link) ) 
     375        return ret_val 
     376 
     377 
     378 
    348379 
    349380#Extend Tabular type, since interval tools will fail on track def line (we should fix this) 
    350 #This is a skeleton class for now, allows viewing at ucsc and formatted peeking. 
     381#This is a skeleton class for now, allows viewing at GBrowse and formatted peeking. 
    351382class GBrowseTrack ( Tabular ): 
    352383 
    353     """Provide the set of display formats supported by this datatype """ 
    354     supported_display_apps = ['gbrowse'] 
    355  
    356     def __init__(self, id=None): 
    357         data.Text.__init__(self, id=id) 
     384    def __init__(self, **kwd): 
     385        """Initialize datatype, by adding GBrowse display app""" 
     386        Tabular.__init__(self, **kwd) 
     387        self.add_display_app ('gbrowse', 'display in GBrowse', 'as_gbrowse_display_file', 'gbrowse_links' ) 
     388 
    358389     
    359390    def make_html_table(self, dataset): 
    360391        return Tabular.make_html_table(self, dataset, skipchar='track') 
    361392     
    362     def display_formats_supported( self, dataset ): 
    363         return set(['gbrowse track']) 
    364  
    365393    def get_estimated_display_viewport( self, dataset ): 
    366394        #TODO: fix me... 
    367395        return ('', '', '') 
     396     
     397    def gbrowse_links( self, dataset, type, app, base_url ): 
     398        ret_val = [] 
     399        if dataset.has_data: 
     400            viewport_tuple = self.get_estimated_display_viewport(dataset) 
     401            if viewport_tuple: 
     402                chrom = viewport_tuple[0] 
     403                start = viewport_tuple[1] 
     404                stop = viewport_tuple[2] 
     405                for site_name, site_url in util.get_gbrowse_sites_by_build(dataset.dbkey): 
     406                    if site_name in app.config.gbrowse_display_sites: 
     407                        display_url = urllib.quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) 
     408                        link = "%sname=%s&ref=%s:%s..%s&eurl=%s" % (site_url, dataset.dbkey, chrom, start, stop, display_url )                         
     409                        ret_val.append( (site_name, link) ) 
     410        return ret_val 
     411         
     412    def as_gbrowse_display_file( self, dataset, **kwd ): 
     413        """Returns file contents that can be displayed in GBrowse apps.""" 
     414        #TODO: fix me... 
     415        return open(dataset.file_name) 
    368416 
    369417if __name__ == '__main__': 
    370418    import doctest, sys 
    371     doctest.testmod(sys.modules[__name__])         
     419    doctest.testmod(sys.modules[__name__]) 
  • lib/galaxy/datatypes/registry.py

    r408 r410  
    1212        for ext, kind in datatypes: 
    1313            try: 
    14                 mime_type = 'text/plain' #default type of plain text 
     14                mime_type = None 
    1515                fields = kind.split(",") 
    1616                if len(fields)>1: 
     
    2424                for mod in fields: module = getattr(module,mod) 
    2525                self.datatypes_by_extension[ext] = getattr(module, datatype_class)() 
     26                if mime_type is None: 
     27                    # Use default mime type as per datatype spec 
     28                    mime_type = self.datatypes_by_extension[ext].get_mime() 
    2629                self.mimetypes_by_extension[ext] = mime_type 
    2730            except: 
  • lib/galaxy/datatypes/sequence.py

    r365 r410  
    1010class Sequence( data.Text ): 
    1111    """Class describing a sequence""" 
     12    pass 
    1213 
    13     """Provide the set of display formats supported by this datatype """ 
    14     supported_display_apps = [] 
    1514 
    1615class Fasta( Sequence ): 
    1716    """Class representing a FASTA sequence""" 
    18  
    19     """Provide the set of display formats supported by this datatype """ 
    20     supported_display_apps = [] 
    2117 
    2218    def set_peek( self, dataset ): 
     
    3430            dataset.blurb = '%d sequences' % count 
    3531 
    36     def get_estimated_display_viewport( self, dataset ): 
    37         #TODO: fix me... 
    38         return ('', '', '') 
    39  
    4032class Maf( Sequence ): 
    4133    """Class describing a Maf alignment""" 
    42  
    43     """Provide the set of display formats supported by this datatype """ 
    44     supported_display_apps = [] 
     34    pass 
    4535 
    4636class Axt( Sequence ): 
    4737    """Class describing an axt alignment""" 
    48  
    49     """Provide the set of display formats supported by this datatype """ 
    50     supported_display_apps = [] 
    51  
     38    pass 
     39     
    5240class Lav( Sequence ): 
    5341    """Class describing a LAV alignment""" 
    54  
    55     """Provide the set of display formats supported by this datatype """ 
    56     supported_display_apps = [] 
     42    pass 
  • lib/galaxy/datatypes/tabular.py

    r408 r410  
    1212from galaxy.datatypes.metadata import MetadataElement 
    1313from galaxy.datatypes.metadata import MetadataAttributes 
    14  
    1514log = logging.getLogger(__name__) 
    1615 
     
    1918    """Tab delimited data""" 
    2019 
    21     """Provide the set of display formats supported by this datatype """ 
    22     supported_display_apps = [] 
    23      
    2420    MetadataElement( name="columns", 
    2521                     default=0, 
     
    4440        except: 
    4541            pass 
    46      
    4742    def missing_meta( self, dataset ): 
    4843        """Checks for empty meta values""" 
     
    5348         
    5449    def make_html_table(self, data, skipchar=None): 
     50        """Create HTML table, used for displaying peek""" 
    5551        out = ['<table cellspacing="0" cellpadding="3">'] 
    5652        first = True 
     
    9086        return out 
    9187 
    92     def get_estimated_display_viewport( self, dataset ): 
    93         #TODO: fix me... 
    94         return ('', '', '') 
    95  
    9688    def display_peek( self, dataset ): 
     89        """Returns formated html of peek""" 
    9790        m_peek = self.make_html_table( dataset.peek ) 
    9891        return m_peek 
  • lib/galaxy/interfaces/root.py

    r391 r410  
    109109                if toext[0:1] != ".": 
    110110                    toext = "." + toext 
    111                 trans.response.headers["Content-Disposition"] = "attachment; filename=GalaxyHistoryItem-%s%s" % (data.hid, toext) 
     111                valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' 
     112                fname = data.name 
     113                fname = ''.join(c in valid_chars and c or '_' for c in fname)[0:150] 
     114                trans.response.headers["Content-Disposition"] = "attachment; filename=GalaxyHistoryItem-%s-[%s]%s" % (data.hid, fname, toext) 
    112115            trans.log_event( "Display dataset id: %s" % str(id) ) 
    113116            try: 
     
    119122 
    120123    @web.expose 
    121     def display_as( self, trans, id=None, display_app="ucsc" ): 
     124    def display_as( self, trans, id=None, display_app=None, **kwd ): 
    122125        """Returns a file in a format that can successfully be displayed in display_app""" 
    123126        data = self.app.model.Dataset.get( id ) 
    124127        if data: 
    125             if display_app == 'ucsc': 
    126                 mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() ) 
    127                 trans.response.set_content_type(mime) 
    128                 file_name = data.as_ucsc_display_file() 
    129                 trans.log_event( "Formatted dataset id %s for display at UCSC" % str(id) ) 
    130                 return open(file_name) 
    131             elif display_app == 'gbrowse': 
    132                 mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() ) 
    133                 trans.response.set_content_type(mime) 
    134                 file_name = data.as_gbrowse_display_file() 
    135                 trans.log_event( "Formatted dataset id %s for display at GBrowse" % str(id) ) 
    136                 return open(file_name) 
    137             else: 
    138                 return "Dataset '%s' cannot be displayed at %s." %(data.name, display_app) 
     128            trans.response.set_content_type(data.get_mime()) 
     129            trans.log_event( "Formatted dataset id %s for display at %s" % ( str(id), display_app ) ) 
     130            return data.as_display_type(display_app, **kwd) 
    139131        else: 
    140132            return "No data with id=%d" % id 
  • lib/galaxy/model/__init__.py

    r400 r410  
    211211    def get_raw_data( self ): 
    212212        """Returns the full data. To stream it open the file_name and read/write as needed""" 
    213         try: 
    214             return file(self.file_name, 'rb').read(-1) 
    215         except OSError, e: 
    216             log.exception('%s reading a file that does not exist %s' % (self.__class__.__name__)) 
    217             return '' 
    218     def write_from_stream(self, stream): 
    219         "Writes data from a stream" 
    220         # write it twice for now  
    221         fd, temp_name = tempfile.mkstemp() 
    222         while 1: 
    223             chunk = stream.read(1048576) 
    224             if not chunk: 
    225                 break 
    226             os.write(fd, chunk) 
    227         os.close(fd) 
    228         # rewrite the file with unix newlines 
    229         fp = open(self.file_name, 'wt') 
    230         for line in file(temp_name, "U"): 
    231             line = line.strip() + '\n' 
    232             fp.write(line) 
    233         fp.close() 
    234     def set_raw_data(self, data): 
     213        return self.datatype.get_raw_data( self ) 
     214    def write_from_stream( self, stream ): 
     215        """Writes data from a stream""" 
     216        self.datatype.write_from_stream(self, stream) 
     217    def set_raw_data( self, data ): 
    235218        """Saves the data on the disc""" 
    236         fd, temp_name = tempfile.mkstemp() 
    237         os.write(fd, data) 
    238         os.close(fd) 
    239         # rewrite the file with unix newlines 
    240         fp = open(self.file_name, 'wt') 
    241         for line in file(temp_name, "U"): 
    242             line = line.strip() + '\n' 
    243             fp.write(line) 
    244         fp.close() 
    245         os.remove( temp_name ) 
    246     def get_mime(self): 
     219        self.datatype.set_raw_data(self, data) 
     220    def get_mime( self ): 
    247221        """Returns the mime type of the data""" 
    248222        return datatypes_registry.get_mimetype_by_extension( self.extension.lower() ) 
     
    255229    def missing_meta( self ): 
    256230        return self.datatype.missing_meta( self ) 
    257     def get_estimated_display_viewport( self ): 
    258         return self.datatype.get_estimated_display_viewport( self ) 
    259     def as_ucsc_display_file( self ): 
    260         return self.datatype.as_ucsc_display_file( self ) 
    261     def as_gbrowse_display_file( self ): 
    262         return self.datatype.as_gbrowse_display_file( self ) 
     231    def as_display_type( self, type, **kwd ): 
     232        return self.datatype.as_display_type( self, type, **kwd ) 
    263233    def display_peek( self ): 
    264234        return self.datatype.display_peek( self ) 
     
    267237    def display_info( self ): 
    268238        return self.datatype.display_info( self ) 
    269     def get_ucsc_sites( self ): 
    270         return self.datatype.get_ucsc_sites( self ) 
    271     def get_gbrowse_sites( self ): 
    272         return self.datatype.get_gbrowse_sites( self ) 
    273239    def get_child_by_designation(self, designation): 
    274240        # if self.history: 
  • templates/history.tmpl

    r403 r410  
    256256                <div class="info">Info: $data.display_info </div> 
    257257                <div>  
    258                     #if $data.ext in [ "bed", "interval", "tabular", "txt", "text", "axt", "maf", "fasta", "gff", "gmaj.zip" ]
     258                    #if $data.has_data
    259259                        <a href="display?id=$data.id&tofile=yes&toext=$data.ext" target="_blank">save</a> 
    260                     #end if 
    261  
    262                     #if $data.has_data and "ucsc" in $data.datatype.supported_display_apps: 
    263                         #set $viewport_tuple = $data.get_estimated_display_viewport() 
    264                         #if $viewport_tuple 
    265                             #set $chrom = $viewport_tuple[0] 
    266                             #set $start = $viewport_tuple[1] 
    267                             #set $stop = $viewport_tuple[2] 
    268                             #set $displayed = "false" 
    269                             #for $site_name,$site_url in $data.get_ucsc_sites: 
    270                                 #if $site_name in $app.config.ucsc_display_sites: 
    271                                     #if $displayed == "false": 
    272                                         | display at UCSC  
    273                                         #set $displayed = "true" 
    274                                     #end if 
    275                                     <a target="_blank" href="$[site_url]db=$data.dbkey&position=$chrom:$start-$stop&hgt.customText=$request.base/display_as?id=$data.id&display_app=ucsc">$site_name</a>  
    276                                 #end if 
    277                             #end for 
    278                         #end if 
    279                     #end if 
    280                      
    281                     #if $data.has_data and "gbrowse" in $data.datatype.supported_display_apps: 
    282                         #set $viewport_tuple = $data.get_estimated_display_viewport() 
    283                         #if $viewport_tuple 
    284                             #set $chrom = $viewport_tuple[0] 
    285                             #set $start = $viewport_tuple[1] 
    286                             #set $stop = $viewport_tuple[2] 
    287                             #set $displayed = "false" 
    288                             #for $site_name, $site_url in $data.get_gbrowse_sites: 
    289                                 #if $site_name in $app.config.gbrowse_display_sites: 
    290                                     #if $displayed == "false": 
    291                                         | display in GBrowse  
    292                                         #set $displayed = "true" 
    293                                     #end if 
    294                                     <a target="_blank" href="$[site_url]&name=$data.dbkey&ref=$chrom:$start..$stop&eurl=$request.base/display_as?id=$data.id&display_app=gbrowse">$site_name</a>  
    295                                 #end if 
    296                             #end for 
    297                         #end if 
    298                     #end if 
    299   
     260                        #for $display_app in $data.datatype.get_display_types(): 
     261                            #set $display_links = $data.datatype.get_display_links($data, $display_app, $app, $request.base) 
     262                            #if $len($display_links) > 0: 
     263                                | $data.datatype.get_display_label($display_app) 
     264                                    #for $display_name, $display_link in display_links: 
     265                                        <a target="_blank" href="$display_link">$display_name</a>  
     266                                    #end for 
     267                            #end if 
     268                        #end for 
     269                    #end if 
    300270                </div> 
    301271                #if $data.peek != "no peek" 
  • templates/root/index.tmpl

    r399 r410  
    33<html lang="en"> 
    44<head> 
    5         <link rel="stylesheet" type="text/css" href="$h.url_for('/static/style/reset.css')"></link> 
     5    <title>Galaxy</title> 
     6    <link rel="stylesheet" type="text/css" href="$h.url_for('/static/style/reset.css')"></link> 
    67    <script type="text/javascript" src="$h.url_for('/static/scripts/jquery.js')"></script> 
    78    <script type="text/javascript" src="$h.url_for('/static/scripts/jquery.dimensions.js')"></script> 
  • universe_wsgi.ini.sample

    r365 r410  
    130130customtrack = galaxy.datatypes.interval:CustomTrack 
    131131gbrowsetrack = galaxy.datatypes.interval:GBrowseTrack 
     132#EMBOSS TOOLS 
     133match = galaxy.datatypes.data:Text 
     134genbank = galaxy.datatypes.data:Text 
     135motif = galaxy.datatypes.data:Text 
     136acedb = galaxy.datatypes.data:Text 
     137nexus = galaxy.datatypes.data:Text 
     138fitch = galaxy.datatypes.data:Text 
     139meganon = galaxy.datatypes.data:Text 
     140codata = galaxy.datatypes.data:Text 
     141dbmotif = galaxy.datatypes.data:Text 
     142table = galaxy.datatypes.data:Text 
     143pir = galaxy.datatypes.data:Text 
     144ig = galaxy.datatypes.data:Text 
     145seqtable = galaxy.datatypes.data:Text 
     146clustal = galaxy.datatypes.data:Text 
     147gcg = galaxy.datatypes.data:Text 
     148hennig86 = galaxy.datatypes.data:Text 
     149excel = galaxy.datatypes.data:Text 
     150asn1 = galaxy.datatypes.data:Text 
     151regions = galaxy.datatypes.data:Text 
     152simple = galaxy.datatypes.data:Text 
     153score = galaxy.datatypes.data:Text 
     154msf = galaxy.datatypes.data:Text 
     155selex = galaxy.datatypes.data:Text 
     156tagseq = galaxy.datatypes.data:Text 
     157embl = galaxy.datatypes.data:Text 
     158srspair = galaxy.datatypes.data:Text 
     159staden = galaxy.datatypes.data:Text 
     160strider = galaxy.datatypes.data:Text 
     161markx10 = galaxy.datatypes.data:Text 
     162pair = galaxy.datatypes.data:Text 
     163markx1 = galaxy.datatypes.data:Text 
     164markx0 = galaxy.datatypes.data:Text 
     165markx3 = galaxy.datatypes.data:Text 
     166markx2 = galaxy.datatypes.data:Text 
     167jackknifer = galaxy.datatypes.data:Text 
     168ncbi = galaxy.datatypes.data:Text 
     169mega = galaxy.datatypes.data:Text 
     170feattable = galaxy.datatypes.data:Text 
     171phylip = galaxy.datatypes.data:Text 
     172diffseq = galaxy.datatypes.data:Text 
     173srs = galaxy.datatypes.data:Text 
     174jackknifernon = galaxy.datatypes.data:Text 
     175swiss = galaxy.datatypes.data:Text 
     176phylipnon = galaxy.datatypes.data:Text 
     177nexusnon = galaxy.datatypes.data:Text 
     178nametable = galaxy.datatypes.data:Text