changeset 0:9e4c4b66b4a0

Imported from capsule None
author cmonjeau
date Tue, 07 Jul 2015 08:49:14 -0400
parents
children ddf34b1d55c8
files compressed.py datatypes_conf.xml
diffstat 2 files changed, 125 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compressed.py	Tue Jul 07 08:49:14 2015 -0400
@@ -0,0 +1,105 @@
+
+"""
+Compressed classes
+"""
+
+import mimetypes, logging, os, os.path, sys, time, tempfile, shutil, string, glob, re, zipfile, tarfile
+
+from galaxy.datatypes.data import Data
+from galaxy.datatypes.sniff import *
+from cgi import escape
+from inspect import isclass
+from galaxy import util
+from galaxy.datatypes.metadata import MetadataElement #import directly to maintain ease of use in Datatype class definitions
+from galaxy.util import inflector
+from galaxy.util.bunch import Bunch
+from galaxy.util.odict import odict
+from galaxy.util.sanitize_html import sanitize_html
+from galaxy.datatypes.checkers import *
+from galaxy.datatypes import data
+
+
+log = logging.getLogger(__name__)
+
+class Zip( Data ):
+    file_ext = "zip"
+   
+    def set_peek( self, dataset, is_multi_byte=False ):
+        """Set the peek and blurb text"""
+        if not dataset.dataset.purged:
+	    dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
+        else:
+            dataset.peek = 'file does not exist'
+            dataset.blurb = 'file purged from disk'
+
+    def sniff( self, filename ):
+        if (check_zip( filename )):
+            return True
+        return False
+	
+
+class Tgz( Data ):
+    file_ext = "tar.gz"
+
+    def set_peek( self, dataset, is_multi_byte=False ):
+        """Set the peek and blurb text"""
+        if not dataset.dataset.purged:
+            dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
+        else:
+            dataset.peek = 'file does not exist'
+            dataset.blurb = 'file purged from disk'
+
+    def sniff( self, filename ):
+        is_gzipped, is_valid = check_gzip( filename )
+        is_tar = tarfile.is_tarfile( filename )
+        return (is_gzipped and is_valid and is_tar)
+
+ 
+class Tbz2( Data ):
+    file_ext = "tar.bz2"
+
+    def set_peek( self, dataset, is_multi_byte=False ):
+        """Set the peek and blurb text"""
+        if not dataset.dataset.purged:
+            dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
+        else:
+            dataset.peek = 'file does not exist'
+            dataset.blurb = 'file purged from disk'
+
+    def sniff( self, filename ):
+        is_bzipped, is_valid = check_bz2( filename )
+        is_tar = tarfile.is_tarfile( filename )
+        return (is_bzipped and is_valid and is_tar)
+
+    
+class Fastqgz( Data ):
+    file_ext = "fastq.gz"
+
+    def set_peek( self, dataset, is_multi_byte=False ):
+        """Set the peek and blurb text"""
+        if not dataset.dataset.purged:
+            dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
+        else:
+            dataset.peek = 'file does not exist'
+            dataset.blurb = 'file purged from disk'
+
+    def sniff( self, filename ):
+        is_gzipped, is_valid = check_gzip( filename )
+        is_tar = tarfile.is_tarfile( filename )
+        return (is_gzipped and is_valid and not is_tar)
+
+class Fastqbz2( Data ):
+    file_ext = "fastq.bz2"
+
+    def set_peek( self, dataset, is_multi_byte=False ):
+        """Set the peek and blurb text"""
+        if not dataset.dataset.purged:
+            dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
+        else:
+            dataset.peek = 'file does not exist'
+            dataset.blurb = 'file purged from disk'
+
+    def sniff( self, filename ):
+        is_bzipped, is_valid = check_bz2( filename )
+        is_tar = tarfile.is_tarfile( filename )
+        return (is_bzipped and is_valid and not is_tar)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datatypes_conf.xml	Tue Jul 07 08:49:14 2015 -0400
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<datatypes>
+    <datatype_files>
+        <datatype_file name="compressed.py"/>
+    </datatype_files>
+    <registration>
+	    <datatype extension="zip" type="galaxy.datatypes.compressed:Zip"  display_in_upload="true"/>
+	    <datatype extension="tar.gz" type="galaxy.datatypes.compressed:Tgz" display_in_upload="true"/>
+	    <datatype extension="tar.bz2" type="galaxy.datatypes.compressed:Tbz2" display_in_upload="true"/>
+	    <datatype extension="fastq.gz" type="galaxy.datatypes.compressed:Fastqgz" display_in_upload="true"/>
+	    <datatype extension="fastq.bz2" type="galaxy.datatypes.compressed:Fastqbz2" display_in_upload="true"/>
+    </registration>
+    <sniffers>
+    	<sniffer type="galaxy.datatypes.compressed:Zip"/>
+	<sniffer type="galaxy.datatypes.compressed:Tgdb"/>
+        <sniffer type="galaxy.datatypes.compressed:Tbz2"/>
+        <sniffer type="galaxy.datatypes.compressed:Fastqgz"/>
+        <sniffer type="galaxy.datatypes.compressed:Fastqbz2"/>
+    </sniffers>
+</datatypes>