Mercurial > repos > jjohnson > chip_datatypes
diff chip.py @ 0:7f9ec5d9c4db draft default tip
Imported from capsule None
author | jjohnson |
---|---|
date | Wed, 15 Oct 2014 09:22:41 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chip.py Wed Oct 15 09:22:41 2014 -0400 @@ -0,0 +1,106 @@ +""" +Binary classes +""" + +import galaxy.datatypes.data +from galaxy.datatypes.data import Data +import galaxy.datatypes.sniff +from galaxy.datatypes.sniff import * + +import zipfile +from urllib import urlencode, quote_plus + +log = logging.getLogger(__name__) + +# Cistrome Customized Datatypes +class Eset( Data ): + """Class describing an Expression Set""" + file_ext = "eset" + def set_peek( self, dataset, is_multi_byte=False ): + if not dataset.dataset.purged: + dataset.peek = "Expression set" + dataset.blurb = data.nice_size( dataset.get_size() ) + else: + dataset.peek = 'file does not exist' + dataset.blurb = 'file purged from disk' + def display_peek(self, dataset): + try: + return dataset.peek + except: + return "Expression set" + def get_mime(self): + """Returns the mime type of the datatype""" + +class XysZip( Data ): + """Class describing a zip archive of NimbleGen XYS files""" + file_ext = "xys.zip" + def set_peek( self, dataset, is_multi_byte=False ): + if not dataset.dataset.purged: + zip_file = zipfile.ZipFile( dataset.file_name, "r" ) + num_files = len( zip_file.namelist() ) + dataset.peek = "Archive of %s NimbleGen XYS files" % ( str( num_files - 1 ) ) + dataset.blurb = data.nice_size( dataset.get_size() ) + else: + dataset.peek = 'file does not exist' + dataset.blurb = 'file purged from disk' + def display_peek(self, dataset): + try: + return dataset.peek + except: + return "NimbleGen XYS file archive (%s)" % ( data.nice_size( dataset.get_size() ) ) + def get_mime(self): + """Returns the mime type of the datatype""" + return 'application/zip' + +class CelZip( Data ): + """Class describing a zip archive of Affymetrix CEL files""" + file_ext = "cel.zip" + def set_peek( self, dataset, is_multi_byte=False ): + if not dataset.dataset.purged: + zip_file = zipfile.ZipFile( dataset.file_name, "r" ) + num_files = len( zip_file.namelist() ) + dataset.peek = "Archive of %s Affymetrix CEL files" % ( str( num_files - 1 ) ) + dataset.blurb = data.nice_size( dataset.get_size() ) + else: + dataset.peek = 'file does not exist' + dataset.blurb = 'file purged from disk' + def display_peek(self, dataset): + try: + return dataset.peek + except: + return "Affymetrix CEL file archive (%s)" % ( data.nice_size( dataset.get_size() ) ) + def get_mime(self): + """Returns the mime type of the datatype""" + return 'application/zip' + +class Cel( Data ): + """Class describing an binary CEL file""" + file_ext = "cel" + def set_peek( self, dataset, is_multi_byte=False ): + if not dataset.dataset.purged: + export_url = "/history_add_to?" + urlencode({'history_id':dataset.history_id,'ext':'cel','name':'affymetrix cel file','info':'Cel file','dbkey':dataset.dbkey}) + dataset.peek = "Binary cel sequence file" + dataset.blurb = data.nice_size( dataset.get_size() ) + else: + dataset.peek = 'file does not exist' + dataset.blurb = 'file purged from disk' + def display_peek(self, dataset): + try: + return dataset.peek + except: + return "Binary cel sequence file (%s)" % ( data.nice_size( dataset.get_size() ) ) + def sniff( self, filename ): + """ + Determines wether the file is in cel format + + """ + parts = filename.lower().split('.') + for p in parts: + if p == 'cel': + return True + return False + + def get_mime(self): + """Returns the mime type of the datatype""" + return 'application/octet-stream' +# End