32
|
1 from galaxy.datatypes.data import Text
|
31
|
2 from galaxy.datatypes.tabular import Tabular
|
39
|
3 from galaxy.datatypes.binary import Binary
|
4
|
4
|
39
|
5 class FlapjackFormat(Binary):
|
9
|
6 file_ext = "flapjack"
|
35
|
7
|
|
8 def sniff(self, filename):
|
39
|
9 # The first 16 bytes of any SQLite3 database file is 'SQLite format 3\0', and the file is binary. For details
|
|
10 # about the format, see http://www.sqlite.org/fileformat.html
|
|
11 try:
|
|
12 header = open(filename, 'rb').read(16)
|
|
13 if header == b'SQLite format 3\0':
|
|
14 fj_table_names = ["objects", "project"]
|
36
|
15 conn = sqlite.connect(filename)
|
35
|
16 c = conn.cursor()
|
|
17 tables_query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
|
|
18 result = c.execute(tables_query).fetchall()
|
|
19 result = [_[0] for _ in result]
|
|
20 for table_name in fj_table_names:
|
|
21 if table_name not in result:
|
|
22 return False
|
|
23 return True
|
39
|
24 return False
|
|
25 except:
|
|
26 return False
|
38
|
27
|
|
28 Binary.register_sniffable_binary_format( "flapjack", "flapjack", FlapjackFormat)
|
9
|
29
|
28
|
30 class FlapjackMapFormat(Tabular):
|
4
|
31 file_ext = "fjmap"
|
|
32
|
|
33 def sniff( self, filename ):
|
|
34 h = open(filename)
|
|
35 line = h.readline()
|
|
36 if line.rstrip() != "# fjFile = MAP":
|
|
37 h.close()
|
|
38 return False
|
|
39 return True
|
|
40
|
28
|
41 class FlapjackGenotypeFormat(Tabular):
|
4
|
42 file_ext = "fjgenotype"
|
|
43
|
|
44 def sniff( self, filename ):
|
|
45 h = open(filename)
|
|
46 line = h.readline()
|
|
47 if line.rstrip() != "# fjFile = GENOTYPE":
|
|
48 h.close()
|
|
49 return False
|
|
50 return True
|
|
51
|
28
|
52 class FlapjackPhenotypeFormat(Tabular):
|
4
|
53 file_ext = "fjphenotye"
|
|
54
|
|
55 def sniff( self, filename ):
|
|
56 h = open(filename)
|
|
57 line = h.readline()
|
|
58 if line.rstrip() != "# fjFile = PHENOTYPE":
|
|
59 h.close()
|
|
60 return False
|
|
61 return True
|
|
62
|
28
|
63 class FlapjackQtlFormat(Tabular):
|
4
|
64 file_ext = "fjqtl"
|
|
65
|
|
66 def sniff( self, filename ):
|
|
67 h = open(filename)
|
|
68 line = h.readline()
|
|
69 if line.rstrip() != "# fjFile = QTL":
|
|
70 h.close()
|
|
71 return False
|
|
72 return True
|
|
73
|
28
|
74 class FlapjackGraphFormat(Tabular):
|
4
|
75 file_ext = "fjgraph"
|
|
76
|
|
77 def sniff( self, filename ):
|
|
78 h = open(filename)
|
|
79 line = h.readline()
|
|
80 if line.rstrip() != "# fjFile = GRAPH":
|
|
81 h.close()
|
|
82 return False
|
|
83 return True |