Mercurial > repos > jjohnson > chip_datatypes
comparison chip.py @ 0:7f9ec5d9c4db draft default tip
Imported from capsule None
author | jjohnson |
---|---|
date | Wed, 15 Oct 2014 09:22:41 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7f9ec5d9c4db |
---|---|
1 """ | |
2 Binary classes | |
3 """ | |
4 | |
5 import galaxy.datatypes.data | |
6 from galaxy.datatypes.data import Data | |
7 import galaxy.datatypes.sniff | |
8 from galaxy.datatypes.sniff import * | |
9 | |
10 import zipfile | |
11 from urllib import urlencode, quote_plus | |
12 | |
13 log = logging.getLogger(__name__) | |
14 | |
15 # Cistrome Customized Datatypes | |
16 class Eset( Data ): | |
17 """Class describing an Expression Set""" | |
18 file_ext = "eset" | |
19 def set_peek( self, dataset, is_multi_byte=False ): | |
20 if not dataset.dataset.purged: | |
21 dataset.peek = "Expression set" | |
22 dataset.blurb = data.nice_size( dataset.get_size() ) | |
23 else: | |
24 dataset.peek = 'file does not exist' | |
25 dataset.blurb = 'file purged from disk' | |
26 def display_peek(self, dataset): | |
27 try: | |
28 return dataset.peek | |
29 except: | |
30 return "Expression set" | |
31 def get_mime(self): | |
32 """Returns the mime type of the datatype""" | |
33 | |
34 class XysZip( Data ): | |
35 """Class describing a zip archive of NimbleGen XYS files""" | |
36 file_ext = "xys.zip" | |
37 def set_peek( self, dataset, is_multi_byte=False ): | |
38 if not dataset.dataset.purged: | |
39 zip_file = zipfile.ZipFile( dataset.file_name, "r" ) | |
40 num_files = len( zip_file.namelist() ) | |
41 dataset.peek = "Archive of %s NimbleGen XYS files" % ( str( num_files - 1 ) ) | |
42 dataset.blurb = data.nice_size( dataset.get_size() ) | |
43 else: | |
44 dataset.peek = 'file does not exist' | |
45 dataset.blurb = 'file purged from disk' | |
46 def display_peek(self, dataset): | |
47 try: | |
48 return dataset.peek | |
49 except: | |
50 return "NimbleGen XYS file archive (%s)" % ( data.nice_size( dataset.get_size() ) ) | |
51 def get_mime(self): | |
52 """Returns the mime type of the datatype""" | |
53 return 'application/zip' | |
54 | |
55 class CelZip( Data ): | |
56 """Class describing a zip archive of Affymetrix CEL files""" | |
57 file_ext = "cel.zip" | |
58 def set_peek( self, dataset, is_multi_byte=False ): | |
59 if not dataset.dataset.purged: | |
60 zip_file = zipfile.ZipFile( dataset.file_name, "r" ) | |
61 num_files = len( zip_file.namelist() ) | |
62 dataset.peek = "Archive of %s Affymetrix CEL files" % ( str( num_files - 1 ) ) | |
63 dataset.blurb = data.nice_size( dataset.get_size() ) | |
64 else: | |
65 dataset.peek = 'file does not exist' | |
66 dataset.blurb = 'file purged from disk' | |
67 def display_peek(self, dataset): | |
68 try: | |
69 return dataset.peek | |
70 except: | |
71 return "Affymetrix CEL file archive (%s)" % ( data.nice_size( dataset.get_size() ) ) | |
72 def get_mime(self): | |
73 """Returns the mime type of the datatype""" | |
74 return 'application/zip' | |
75 | |
76 class Cel( Data ): | |
77 """Class describing an binary CEL file""" | |
78 file_ext = "cel" | |
79 def set_peek( self, dataset, is_multi_byte=False ): | |
80 if not dataset.dataset.purged: | |
81 export_url = "/history_add_to?" + urlencode({'history_id':dataset.history_id,'ext':'cel','name':'affymetrix cel file','info':'Cel file','dbkey':dataset.dbkey}) | |
82 dataset.peek = "Binary cel sequence file" | |
83 dataset.blurb = data.nice_size( dataset.get_size() ) | |
84 else: | |
85 dataset.peek = 'file does not exist' | |
86 dataset.blurb = 'file purged from disk' | |
87 def display_peek(self, dataset): | |
88 try: | |
89 return dataset.peek | |
90 except: | |
91 return "Binary cel sequence file (%s)" % ( data.nice_size( dataset.get_size() ) ) | |
92 def sniff( self, filename ): | |
93 """ | |
94 Determines wether the file is in cel format | |
95 | |
96 """ | |
97 parts = filename.lower().split('.') | |
98 for p in parts: | |
99 if p == 'cel': | |
100 return True | |
101 return False | |
102 | |
103 def get_mime(self): | |
104 """Returns the mime type of the datatype""" | |
105 return 'application/octet-stream' | |
106 # End |