comparison oxli.py @ 0:08a714ff4ea5 draft default tip

planemo upload commit d8e0950d53e504e02ee5db43c0804142b14d7fd2-dirty
author crusoe
date Tue, 07 Jul 2015 11:58:46 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:08a714ff4ea5
1 """
2 k-mer count and presence
3 """
4
5 from galaxy.datatypes.binary import Binary
6 import binascii
7
8 import logging
9
10 log = logging.getLogger(__name__)
11
12
13 class OxliBinary(Binary):
14
15 def __init__(self, **kwd):
16 Binary.__init__(self, **kwd)
17
18 def sniff(self, filename, filetype):
19 try:
20 with open(filename) as fileobj:
21 header = fileobj.read(4)
22 if binascii.b2a_hex(header) == binascii.hexlify('OXLI'):
23 fileobj.seek(1)
24 ftype = fileobj.read(1)
25 if binascii.b2a_hex(ftype) == filetype:
26 return True
27 return False
28 except IOError:
29 return False
30
31
32 class Count(OxliBinary):
33
34 def __init__(self, **kwd):
35 OxliBinary.__init__(self, **kwd)
36
37 def sniff(self, filename):
38 return OxliBinary.sniff(self, filename, "01")
39
40
41 class Presence(OxliBinary):
42
43 def __init__(self, **kwd):
44 OxliBinary.__init__(self, **kwd)
45
46 def sniff(self, filename):
47 return OxliBinary.sniff(self, filename, "02")
48
49
50 Binary.register_sniffable_binary_format("ct", "ct", Count)
51 Binary.register_sniffable_binary_format("pt", "pt", Presence)