changeset 0:7f9ec5d9c4db draft default tip

Imported from capsule None
author jjohnson
date Wed, 15 Oct 2014 09:22:41 -0400
parents
children
files chip.py datatypes_conf.xml
diffstat 2 files changed, 121 insertions(+), 0 deletions(-) [+]
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datatypes_conf.xml	Wed Oct 15 09:22:41 2014 -0400
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<datatypes>
+    <datatype_files>
+        <datatype_file name="chip.py"/>
+    </datatype_files>
+    <registration>
+        <!-- Cistrome Customized Datatypes -->
+        <datatype extension="eset" type="galaxy.datatypes.chip:Eset" display_in_upload="true"/>
+        <datatype extension="cel.zip" type="galaxy.datatypes.chip:CelZip" mimetype="application/zip" display_in_upload="true"/>
+        <datatype extension="xys.zip" type="galaxy.datatypes.chip:XysZip" mimetype="application/zip" display_in_upload="true"/>
+        <datatype extension="cel" type="galaxy.datatypes.chip:Cel" display_in_upload="true"/>
+        <!-- End -->
+    </registration>
+</datatypes>
+