Mercurial > repos > yufei-luo > s_mart
comparison smart_toolShed/commons/core/sql/test/Test_TableBinPathAdaptator.py @ 0:e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
author | yufei-luo |
---|---|
date | Thu, 17 Jan 2013 10:52:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e0f8dcca02ed |
---|---|
1 # Copyright INRA (Institut National de la Recherche Agronomique) | |
2 # http://www.inra.fr | |
3 # http://urgi.versailles.inra.fr | |
4 # | |
5 # This software is governed by the CeCILL license under French law and | |
6 # abiding by the rules of distribution of free software. You can use, | |
7 # modify and/ or redistribute the software under the terms of the CeCILL | |
8 # license as circulated by CEA, CNRS and INRIA at the following URL | |
9 # "http://www.cecill.info". | |
10 # | |
11 # As a counterpart to the access to the source code and rights to copy, | |
12 # modify and redistribute granted by the license, users are provided only | |
13 # with a limited warranty and the software's author, the holder of the | |
14 # economic rights, and the successive licensors have only limited | |
15 # liability. | |
16 # | |
17 # In this respect, the user's attention is drawn to the risks associated | |
18 # with loading, using, modifying and/or developing or reproducing the | |
19 # software by the user in light of its specific status of free software, | |
20 # that may mean that it is complicated to manipulate, and that also | |
21 # therefore means that it is reserved for developers and experienced | |
22 # professionals having in-depth computer knowledge. Users are therefore | |
23 # encouraged to load and test the software's suitability as regards their | |
24 # requirements in conditions enabling the security of their systems and/or | |
25 # data to be ensured and, more generally, to use and operate it in the | |
26 # same conditions as regards security. | |
27 # | |
28 # The fact that you are presently reading this means that you have had | |
29 # knowledge of the CeCILL license and that you accept its terms. | |
30 | |
31 import unittest | |
32 import os | |
33 import time | |
34 from commons.core.sql.TableBinPathAdaptator import TableBinPathAdaptator | |
35 from commons.core.coord.Path import Path | |
36 from commons.core.coord.Set import Set | |
37 from commons.core.sql.DbFactory import DbFactory | |
38 | |
39 class Test_TableBinPathAdaptator( unittest.TestCase ): | |
40 | |
41 def setUp( self ): | |
42 self._uniqId = "%s_%s" % (time.strftime("%Y%m%d%H%M%S") , os.getpid()) | |
43 self._db = DbFactory.createInstance() | |
44 self._table = "dummyPathTable_%s" % self._uniqId | |
45 self._table_idx = "dummyPathTable_%s_idx" % self._uniqId | |
46 | |
47 def tearDown( self ): | |
48 self._db.dropTable(self._table) | |
49 self._db.dropTable(self._table_idx) | |
50 self._db.close() | |
51 | |
52 #TODO: strand ?!? How does it work ? | |
53 def test_insert_QryRevSbjDir( self ): | |
54 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
55 p1 = Path() | |
56 p1.setFromTuple(tuple) | |
57 | |
58 tuple = ("1", "chr1", "250", "100", "TE1", "11", "17", "1e-18", "20", "87.4") | |
59 p2 = Path() | |
60 p2.setFromTuple(tuple) | |
61 | |
62 tuple = ("2", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
63 p3 = Path() | |
64 p3.setFromTuple(tuple) | |
65 | |
66 tuple = ("4", "chr5", "140", "251", "TE5", "140", "251", "2e-14", "14", "73.1") | |
67 p4 = Path() | |
68 p4.setFromTuple(tuple) | |
69 | |
70 self._db.createTable( self._table, "path" ) | |
71 self._db.createBinPathTable(self._table, True) | |
72 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
73 self._tpA.insert(p1) | |
74 self._tpA.insert(p2) | |
75 self._tpA.insert(p3) | |
76 self._tpA.insert(p4) | |
77 | |
78 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
79 self._db.execute( sqlCmd ) | |
80 obsPathTuple = self._db.cursor.fetchall() | |
81 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
82 (1, "chr1", 100, 250, "TE1", 17, 11, 1e-18, 20, 87.4), | |
83 (2, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1), | |
84 (4, "chr5", 140, 251, "TE5", 140, 251, 2e-14, 14, 73.1),) | |
85 self.assertEquals(expPathTuple, obsPathTuple) | |
86 | |
87 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
88 self._db.execute( sqlCmd ) | |
89 obsPathTuple = self._db.cursor.fetchall() | |
90 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
91 (1, 1000000, "chr1", 100, 250, 1), | |
92 (2, 1000000, "chr1", 15, 30, 1), | |
93 (4, 1000000, "chr5", 140, 251, 1),) | |
94 self.assertEquals(expPathTuple, obsPathTuple) | |
95 | |
96 def test_getPathListOverlappingQueryCoord_one_included( self ): | |
97 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
98 pathF = open( pathFileName, "w" ) | |
99 pathF.write("6\tchr1\t950\t1010\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
100 pathF.close() | |
101 | |
102 tuple = ("6", "chr1", "950", "1010", "TE2", "11", "17", "1e-20", "30", "90.2") | |
103 p1 = Path() | |
104 p1.setFromTuple(tuple) | |
105 | |
106 self._db.createTable( self._table, "path", pathFileName ) | |
107 self._db.createBinPathTable(self._table, True) | |
108 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
109 | |
110 lObs = self._tpA.getPathListOverlappingQueryCoord( "chr1", 900, 1010 ) | |
111 self.assertEquals(1, len(lObs)) | |
112 lExp = [p1] | |
113 self.assertEquals(lExp, lObs) | |
114 | |
115 os.remove( pathFileName ) | |
116 | |
117 def test_getPathListOverlappingQueryCoord_two_overlapped( self ): | |
118 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
119 pathF = open( pathFileName, "w" ) | |
120 pathF.write("6\tchr1\t950\t1500\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
121 pathF.write("7\tchr1\t750\t1000\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
122 pathF.close() | |
123 | |
124 tuple = ("6", "chr1", "950", "1500", "TE2", "11", "17", "1e-20", "30", "90.2") | |
125 p1 = Path() | |
126 p1.setFromTuple(tuple) | |
127 | |
128 tuple = ("7", "chr1", "750", "1000", "TE2", "11", "17", "1e-20", "30", "90.2") | |
129 p2 = Path() | |
130 p2.setFromTuple(tuple) | |
131 | |
132 self._db.createTable( self._table, "path", pathFileName ) | |
133 self._db.createBinPathTable(self._table, True) | |
134 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
135 | |
136 lObs = self._tpA.getPathListOverlappingQueryCoord( "chr1", 900, 1010 ) | |
137 self.assertEquals(2, len(lObs)) | |
138 lExp = [p1, p2] | |
139 self.assertEquals(lExp, lObs) | |
140 | |
141 os.remove( pathFileName ) | |
142 | |
143 def test_getPathListOverlappingQueryCoord_two_not_overlapped_and_not_included( self ): | |
144 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
145 pathF = open( pathFileName, "w" ) | |
146 pathF.write("6\tchr1\t1050\t1500\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
147 pathF.write("7\tchr1\t750\t800\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
148 pathF.close() | |
149 | |
150 tuple = ("6", "chr1", "1050", "1500", "TE2", "11", "17", "1e-20", "30", "90.2") | |
151 p1 = Path() | |
152 p1.setFromTuple(tuple) | |
153 | |
154 tuple = ("7", "chr1", "750", "800", "TE2", "11", "17", "1e-20", "30", "90.2") | |
155 p2 = Path() | |
156 p2.setFromTuple(tuple) | |
157 | |
158 self._db.createTable( self._table, "path", pathFileName ) | |
159 self._db.createBinPathTable(self._table, True) | |
160 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
161 | |
162 lObs = self._tpA.getPathListOverlappingQueryCoord( "chr1", 900, 1010 ) | |
163 self.assertEquals(0, len(lObs)) | |
164 lExp = [] | |
165 self.assertEquals(lExp, lObs) | |
166 | |
167 os.remove( pathFileName ) | |
168 | |
169 def test_getPathListOverlappingQueryCoord_one_verlapping_and_others_chained( self ): | |
170 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
171 pathF = open( pathFileName, "w" ) | |
172 pathF.write("6\tchr1\t900\t1010\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
173 pathF.write("6\tchr1\t1020\t1030\tTE2\t10\t13\t1e-20\t30\t90.2\n") | |
174 pathF.write("7\tchr1\t950\t999\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
175 pathF.write("7\tchr1\t1020\t1030\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
176 pathF.write("7\tchr5\t8000\t15000\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
177 pathF.close() | |
178 | |
179 tuple = ("6", "chr1", "900", "1010", "TE2", "11", "17", "1e-20", "30", "90.2") | |
180 p1 = Path() | |
181 p1.setFromTuple(tuple) | |
182 | |
183 tuple = ("6", "chr1", "1020", "1030", "TE2", "10", "13", "1e-20", "30", "90.2") | |
184 p2 = Path() | |
185 p2.setFromTuple(tuple) | |
186 | |
187 tuple = ("7", "chr1", "850", "999", "TE2", "11", "17", "1e-20", "30", "90.2") | |
188 p3 = Path() | |
189 p3.setFromTuple(tuple) | |
190 | |
191 tuple = ("7", "chr1", "1020", "1030", "TE2", "11", "17", "1e-20", "30", "90.2") | |
192 p4 = Path() | |
193 p4.setFromTuple(tuple) | |
194 | |
195 tuple = ("7", "chr5", "8000", "15000", "TE2", "11", "17", "1e-20", "30", "90.2") | |
196 p5 = Path() | |
197 p5.setFromTuple(tuple) | |
198 | |
199 self._db.createTable( self._table, "path", pathFileName ) | |
200 self._db.createBinPathTable(self._table, True) | |
201 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
202 | |
203 lObs = self._tpA.getPathListOverlappingQueryCoord( "chr1", 1000, 1010 ) | |
204 self.assertEquals(1, len(lObs)) | |
205 lExp = [p1] | |
206 self.assertEquals(lExp, lObs) | |
207 | |
208 os.remove( pathFileName ) | |
209 | |
210 def test_getChainListOverlappingQueryCoord_with_all_path_strictly_included_in_the_given_region(self): | |
211 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
212 pathF = open( pathFileName, "w" ) | |
213 pathF.write("1\tchr1\t1\t10\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
214 pathF.write("2\tchr1\t2\t9\tTE2\t10\t13\t1e-20\t30\t90.2\n") | |
215 pathF.write("3\tchr1\t8\t13\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
216 pathF.write("4\tchr1\t11\t15\tTE2\t15\t19\t1e-10\t25\t80.2\n") | |
217 pathF.write("5\tchr1\t14\t19\tTE1\t1\t6\t1e-15\t45\t98.4\n") | |
218 pathF.close() | |
219 | |
220 tuple = ("1", "chr1", "1", "10", "TE2", "11", "17", "1e-20", "30", "90.2") | |
221 p1 = Path() | |
222 p1.setFromTuple(tuple) | |
223 | |
224 tuple = ("2", "chr1", "2", "9", "TE2", "10", "13", "1e-20", "30", "90.2") | |
225 p2 = Path() | |
226 p2.setFromTuple(tuple) | |
227 | |
228 tuple = ("3", "chr1", "8", "13", "TE2", "11", "17", "1e-20", "30", "90.2") | |
229 p3 = Path() | |
230 p3.setFromTuple(tuple) | |
231 | |
232 tuple = ("4", "chr1", "11", "15", "TE2", "15", "19", "1e-10", "25", "80.2") | |
233 p4 = Path() | |
234 p4.setFromTuple(tuple) | |
235 | |
236 tuple = ("5", "chr1", "14", "19", "TE1", "1", "6", "1e-15", "45", "98.4") | |
237 p5 = Path() | |
238 p5.setFromTuple(tuple) | |
239 | |
240 self._db.createTable( self._table, "path", pathFileName ) | |
241 self._db.createBinPathTable(self._table, True) | |
242 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
243 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 1, 20 ) | |
244 self.assertEquals(5, len(lObs)) | |
245 | |
246 lExp = [p1, p2, p3, p4, p5] | |
247 self.assertEquals(lExp, lObs) | |
248 | |
249 os.remove( pathFileName ) | |
250 | |
251 def test_getChainListOverlappingQueryCoord_with_2_path_overlapping_the_given_region(self): | |
252 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
253 pathF = open( pathFileName, "w" ) | |
254 pathF.write("1\tchr1\t1\t20\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
255 pathF.write("2\tchr1\t10\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
256 pathF.close() | |
257 | |
258 tuple = ("1", "chr1", "1", "20", "TE1", "11", "17", "1e-18", "20", "87.4") | |
259 p1 = Path() | |
260 p1.setFromTuple(tuple) | |
261 | |
262 tuple = ("2", "chr1", "10", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
263 p2 = Path() | |
264 p2.setFromTuple(tuple) | |
265 | |
266 self._db.createTable( self._table, "path", pathFileName ) | |
267 self._db.createBinPathTable(self._table, True) | |
268 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
269 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 12, 18 ) | |
270 self.assertEquals(2, len(lObs)) | |
271 | |
272 lExp = [p1, p2] | |
273 self.assertEquals(lExp, lObs) | |
274 | |
275 os.remove( pathFileName ) | |
276 | |
277 def test_getChainListOverlappingQueryCoord_without_path_overlapping_the_given_region(self): | |
278 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
279 pathF = open( pathFileName, "w" ) | |
280 pathF.write("1\tchr1\t1\t20\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
281 pathF.write("2\tchr1\t10\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
282 pathF.write("3\tchr5\t45\t50\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
283 pathF.close() | |
284 | |
285 tuple = ("1", "chr1", "1", "20", "TE1", "11", "17", "1e-18", "20", "87.4") | |
286 p1 = Path() | |
287 p1.setFromTuple(tuple) | |
288 | |
289 tuple = ("2", "chr1", "10", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
290 p2 = Path() | |
291 p2.setFromTuple(tuple) | |
292 | |
293 tuple = ("3", "chr5", "45", "50", "TE2", "10", "13", "5e-24", "34", "93.1") | |
294 p3 = Path() | |
295 p3.setFromTuple(tuple) | |
296 | |
297 self._db.createTable( self._table, "path", pathFileName ) | |
298 self._db.createBinPathTable(self._table, True) | |
299 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
300 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 40, 50 ) | |
301 self.assertEquals(0, len(lObs)) | |
302 | |
303 lExp = [] | |
304 self.assertEquals(lExp, lObs) | |
305 | |
306 os.remove( pathFileName ) | |
307 | |
308 def test_getChainListOverlappingQueryCoord_with_inverse_coord(self): | |
309 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
310 pathF = open( pathFileName, "w" ) | |
311 pathF.write("1\tchr1\t2000\t1010\tTE2\t17\t11\t1e-20\t30\t90.2\n") | |
312 pathF.write("2\tchr1\t5000\t3030\tTE2\t13\t10\t1e-20\t30\t90.2\n") | |
313 pathF.close() | |
314 | |
315 tuple = ("1", "chr1", "2000", "1010", "TE2", "17", "11", "1e-20", "30", "90.2") | |
316 p1 = Path() | |
317 p1.setFromTuple(tuple) | |
318 | |
319 tuple = ("2", "chr1", "5000", "3030", "TE2", "13", "10", "1e-20", "30", "90.2") | |
320 p2 = Path() | |
321 p2.setFromTuple(tuple) | |
322 | |
323 self._db.createTable( self._table, "path", pathFileName ) | |
324 self._db.createBinPathTable(self._table, True) | |
325 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
326 | |
327 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 1000, 1500 ) | |
328 self.assertEquals(1, len(lObs)) | |
329 lExp = [p1] | |
330 self.assertEquals(lExp, lObs) | |
331 | |
332 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 4000, 4510 ) | |
333 self.assertEquals(1, len(lObs)) | |
334 lExp = [p2] | |
335 self.assertEquals(lExp, lObs) | |
336 | |
337 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 1000, 4510 ) | |
338 self.assertEquals(2, len(lObs)) | |
339 lExp = [p1, p2] | |
340 self.assertEquals(lExp, lObs) | |
341 | |
342 os.remove( pathFileName ) | |
343 | |
344 def test_getChainListOverlappingQueryCoord_with_chain_id_and_coord( self ): | |
345 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
346 pathF = open( pathFileName, "w" ) | |
347 pathF.write("6\tchr1\t900\t1010\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
348 pathF.write("6\tchr1\t1020\t1030\tTE2\t10\t13\t1e-20\t30\t90.2\n") | |
349 pathF.write("7\tchr1\t950\t999\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
350 pathF.write("7\tchr1\t1020\t1030\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
351 pathF.write("7\tchr5\t8000\t15000\tTE2\t11\t17\t1e-20\t30\t90.2\n") | |
352 pathF.close() | |
353 | |
354 tuple = ("6", "chr1", "900", "1010", "TE2", "11", "17", "1e-20", "30", "90.2") | |
355 p1 = Path() | |
356 p1.setFromTuple(tuple) | |
357 | |
358 tuple = ("6", "chr1", "1020", "1030", "TE2", "10", "13", "1e-20", "30", "90.2") | |
359 p2 = Path() | |
360 p2.setFromTuple(tuple) | |
361 | |
362 tuple = ("7", "chr1", "950", "999", "TE2", "11", "17", "1e-20", "30", "90.2") | |
363 p3 = Path() | |
364 p3.setFromTuple(tuple) | |
365 | |
366 tuple = ("7", "chr1", "1020", "1030", "TE2", "11", "17", "1e-20", "30", "90.2") | |
367 p4 = Path() | |
368 p4.setFromTuple(tuple) | |
369 | |
370 tuple = ("7", "chr5", "8000", "15000", "TE2", "11", "17", "1e-20", "30", "90.2") | |
371 p5 = Path() | |
372 p5.setFromTuple(tuple) | |
373 | |
374 self._db.createTable( self._table, "path", pathFileName ) | |
375 self._db.createBinPathTable(self._table, True) | |
376 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
377 lObs = self._tpA.getChainListOverlappingQueryCoord( "chr1", 1000, 1010 ) | |
378 self.assertEquals(5, len(lObs)) | |
379 lExp = [p1, p2, p3, p4, p5] | |
380 self.assertEquals(lExp, lObs) | |
381 | |
382 os.remove( pathFileName ) | |
383 | |
384 def test_getPathListIncludedInQueryCoord_all_included(self): | |
385 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
386 pathF = open( pathFileName, "w" ) | |
387 pathF.write("1\tchr1\t10\t20\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
388 pathF.write("2\tchr1\t20\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
389 pathF.close() | |
390 | |
391 tuple = ("1", "chr1", "10", "20", "TE1", "11", "17", "1e-18", "20", "87.4") | |
392 p1 = Path() | |
393 p1.setFromTuple(tuple) | |
394 | |
395 tuple = ("2", "chr1", "20", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
396 p2 = Path() | |
397 p2.setFromTuple(tuple) | |
398 | |
399 self._db.createTable( self._table, "path", pathFileName ) | |
400 self._db.createBinPathTable(self._table, True) | |
401 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
402 lObs = self._tpA.getPathListIncludedInQueryCoord( "chr1", 1, 40 ) | |
403 self.assertEquals(2, len(lObs)) | |
404 | |
405 lExp = [p1, p2] | |
406 self.assertEquals(lExp, lObs) | |
407 | |
408 os.remove( pathFileName ) | |
409 | |
410 def test_getPathListIncludedInQueryCoord_all_not_included(self): | |
411 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
412 pathF = open( pathFileName, "w" ) | |
413 pathF.write("1\tchr1\t10\t20\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
414 pathF.write("2\tchr1\t20\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
415 pathF.write("3\tchr5\t55\t60\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
416 pathF.close() | |
417 | |
418 tuple = ("1", "chr1", "10", "20", "TE1", "11", "17", "1e-18", "20", "87.4") | |
419 p1 = Path() | |
420 p1.setFromTuple(tuple) | |
421 | |
422 tuple = ("2", "chr1", "20", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
423 p2 = Path() | |
424 p2.setFromTuple(tuple) | |
425 | |
426 tuple = ("3", "chr2", "55", "60", "TE2", "10", "13", "5e-24", "34", "93.1") | |
427 p3 = Path() | |
428 p3.setFromTuple(tuple) | |
429 | |
430 self._db.createTable( self._table, "path", pathFileName ) | |
431 self._db.createBinPathTable(self._table, True) | |
432 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
433 lObs = self._tpA.getPathListIncludedInQueryCoord( "chr1", 50, 70 ) | |
434 self.assertEquals(0, len(lObs)) | |
435 | |
436 lExp = [] | |
437 self.assertEquals(lExp, lObs) | |
438 | |
439 os.remove( pathFileName ) | |
440 | |
441 def test_getPathListIncludedInQueryCoord_all_overlapping(self): | |
442 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
443 pathF = open( pathFileName, "w" ) | |
444 pathF.write("1\tchr1\t10\t25\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
445 pathF.write("2\tchr1\t15\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
446 pathF.close() | |
447 | |
448 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
449 p1 = Path() | |
450 p1.setFromTuple(tuple) | |
451 | |
452 tuple = ("2", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
453 p2 = Path() | |
454 p2.setFromTuple(tuple) | |
455 | |
456 self._db.createTable( self._table, "path", pathFileName ) | |
457 self._db.createBinPathTable(self._table, True) | |
458 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
459 lObs = self._tpA.getPathListIncludedInQueryCoord( "chr1", 13, 22 ) | |
460 self.assertEquals(0, len(lObs)) | |
461 | |
462 lExp = [] | |
463 self.assertEquals(lExp, lObs) | |
464 | |
465 os.remove( pathFileName ) | |
466 | |
467 def test_getPathListIncludedInQueryCoord_with_one_included_and_one_overlapping(self): | |
468 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
469 pathF = open( pathFileName, "w" ) | |
470 pathF.write("1\tchr1\t10\t25\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
471 pathF.write("2\tchr1\t15\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
472 pathF.close() | |
473 | |
474 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
475 p1 = Path() | |
476 p1.setFromTuple(tuple) | |
477 | |
478 tuple = ("2", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
479 p2 = Path() | |
480 p2.setFromTuple(tuple) | |
481 | |
482 self._db.createTable( self._table, "path", pathFileName ) | |
483 self._db.createBinPathTable(self._table, True) | |
484 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
485 lObs = self._tpA.getPathListIncludedInQueryCoord( "chr1", 9, 27 ) | |
486 self.assertEquals(1, len(lObs)) | |
487 lExp = [p1] | |
488 self.assertEquals(lExp, lObs) | |
489 | |
490 os.remove( pathFileName ) | |
491 | |
492 def test_getPathListIncludedInQueryCoord_with_one_included_and_two_chained(self): | |
493 pathFileName = "dummyPathFile_%s" % ( self._uniqId ) | |
494 pathF = open( pathFileName, "w" ) | |
495 pathF.write("1\tchr1\t10\t25\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
496 pathF.write("1\tchr1\t100\t250\tTE1\t11\t17\t1e-18\t20\t87.4\n") | |
497 pathF.write("2\tchr1\t15\t30\tTE2\t10\t13\t5e-24\t34\t93.1\n") | |
498 pathF.close() | |
499 | |
500 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
501 p1 = Path() | |
502 p1.setFromTuple(tuple) | |
503 | |
504 tuple = ("1", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
505 p2 = Path() | |
506 p2.setFromTuple(tuple) | |
507 | |
508 tuple = ("2", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
509 p3 = Path() | |
510 p3.setFromTuple(tuple) | |
511 | |
512 self._db.createTable( self._table, "path", pathFileName ) | |
513 self._db.createBinPathTable(self._table, True) | |
514 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
515 lObs = self._tpA.getPathListIncludedInQueryCoord( "chr1", 9, 27 ) | |
516 self.assertEquals(1, len(lObs)) | |
517 lExp = [p1] | |
518 self.assertEquals(lExp, lObs) | |
519 | |
520 os.remove( pathFileName ) | |
521 | |
522 def test_deleteFromId_with_correct_ID(self): | |
523 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
524 p1 = Path() | |
525 p1.setFromTuple(tuple) | |
526 | |
527 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
528 p2 = Path() | |
529 p2.setFromTuple(tuple) | |
530 | |
531 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
532 p3 = Path() | |
533 p3.setFromTuple(tuple) | |
534 | |
535 self._db.createTable( self._table, "path" ) | |
536 self._db.createBinPathTable(self._table, True) | |
537 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
538 self._tpA.insert(p1) | |
539 self._tpA.insert(p2) | |
540 self._tpA.insert(p3) | |
541 self._tpA.deleteFromId(3) | |
542 | |
543 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
544 self._db.execute( sqlCmd ) | |
545 obsPathTuple = self._db.cursor.fetchall() | |
546 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
547 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4),) | |
548 self.assertEquals(expPathTuple, obsPathTuple) | |
549 | |
550 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
551 self._db.execute( sqlCmd ) | |
552 obsPathTuple = self._db.cursor.fetchall() | |
553 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
554 (2, 1000000, "chr1", 100, 250, 1),) | |
555 self.assertEquals(expPathTuple, obsPathTuple) | |
556 | |
557 def test_deleteFromId_with_not_exist_ID(self): | |
558 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
559 p1 = Path() | |
560 p1.setFromTuple(tuple) | |
561 | |
562 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
563 p2 = Path() | |
564 p2.setFromTuple(tuple) | |
565 | |
566 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
567 p3 = Path() | |
568 p3.setFromTuple(tuple) | |
569 | |
570 self._db.createTable( self._table, "path" ) | |
571 self._db.createBinPathTable(self._table, True) | |
572 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
573 self._tpA.insert(p1) | |
574 self._tpA.insert(p2) | |
575 self._tpA.insert(p3) | |
576 self._tpA.deleteFromId(4) | |
577 | |
578 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
579 self._db.execute( sqlCmd ) | |
580 obsPathTuple = self._db.cursor.fetchall() | |
581 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
582 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
583 (3, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
584 self.assertEquals(expPathTuple, obsPathTuple) | |
585 | |
586 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
587 self._db.execute( sqlCmd ) | |
588 obsPathTuple = self._db.cursor.fetchall() | |
589 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
590 (2, 1000000, "chr1", 100, 250, 1), | |
591 (3, 1000000, "chr1", 15, 30, 1),) | |
592 self.assertEquals(expPathTuple, obsPathTuple) | |
593 | |
594 def test_deleteFromId_with_multiple_ID(self): | |
595 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
596 p1 = Path() | |
597 p1.setFromTuple(tuple) | |
598 | |
599 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
600 p2 = Path() | |
601 p2.setFromTuple(tuple) | |
602 | |
603 tuple = ("2", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
604 p3 = Path() | |
605 p3.setFromTuple(tuple) | |
606 | |
607 self._db.createTable( self._table, "path" ) | |
608 self._db.createBinPathTable(self._table, True) | |
609 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
610 self._tpA.insert(p1) | |
611 self._tpA.insert(p2) | |
612 self._tpA.insert(p3) | |
613 self._tpA.deleteFromId(2) | |
614 | |
615 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
616 self._db.execute( sqlCmd ) | |
617 obsPathTuple = self._db.cursor.fetchall() | |
618 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4),) | |
619 self.assertEquals(expPathTuple, obsPathTuple) | |
620 | |
621 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
622 self._db.execute( sqlCmd ) | |
623 obsPathTuple = self._db.cursor.fetchall() | |
624 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1),) | |
625 self.assertEquals(expPathTuple, obsPathTuple) | |
626 | |
627 def test_deleteFromIdList(self): | |
628 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
629 p1 = Path() | |
630 p1.setFromTuple(tuple) | |
631 | |
632 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
633 p2 = Path() | |
634 p2.setFromTuple(tuple) | |
635 | |
636 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
637 p3 = Path() | |
638 p3.setFromTuple(tuple) | |
639 | |
640 self._db.createTable( self._table, "path" ) | |
641 self._db.createBinPathTable(self._table, True) | |
642 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
643 self._tpA.insert(p1) | |
644 self._tpA.insert(p2) | |
645 self._tpA.insert(p3) | |
646 lNumToRemove = [2, 3] | |
647 self._tpA.deleteFromIdList(lNumToRemove) | |
648 | |
649 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
650 self._db.execute( sqlCmd ) | |
651 obsPathTuple = self._db.cursor.fetchall() | |
652 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4),) | |
653 self.assertEquals(expPathTuple, obsPathTuple) | |
654 | |
655 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
656 self._db.execute( sqlCmd ) | |
657 obsPathTuple = self._db.cursor.fetchall() | |
658 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1),) | |
659 self.assertEquals(expPathTuple, obsPathTuple) | |
660 | |
661 def test_deleteFromIdList_with_empty_list(self): | |
662 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
663 p1 = Path() | |
664 p1.setFromTuple(tuple) | |
665 | |
666 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
667 p2 = Path() | |
668 p2.setFromTuple(tuple) | |
669 | |
670 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
671 p3 = Path() | |
672 p3.setFromTuple(tuple) | |
673 | |
674 self._db.createTable( self._table, "path" ) | |
675 self._db.createBinPathTable(self._table, True) | |
676 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
677 self._tpA.insert(p1) | |
678 self._tpA.insert(p2) | |
679 self._tpA.insert(p3) | |
680 lNumToRemove = [] | |
681 self._tpA.deleteFromIdList(lNumToRemove) | |
682 | |
683 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
684 self._db.execute( sqlCmd ) | |
685 obsPathTuple = self._db.cursor.fetchall() | |
686 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
687 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
688 (3, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
689 self.assertEquals(expPathTuple, obsPathTuple) | |
690 | |
691 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
692 self._db.execute( sqlCmd ) | |
693 obsPathTuple = self._db.cursor.fetchall() | |
694 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
695 (2, 1000000, "chr1", 100, 250, 1), | |
696 (3, 1000000, "chr1", 15, 30, 1),) | |
697 self.assertEquals(expPathTuple, obsPathTuple) | |
698 | |
699 def test_deleteFromIdList_with_list_of_existing_and_not_existing_ID(self): | |
700 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
701 p1 = Path() | |
702 p1.setFromTuple(tuple) | |
703 | |
704 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
705 p2 = Path() | |
706 p2.setFromTuple(tuple) | |
707 | |
708 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
709 p3 = Path() | |
710 p3.setFromTuple(tuple) | |
711 | |
712 self._db.createTable( self._table, "path" ) | |
713 self._db.createBinPathTable(self._table, True) | |
714 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
715 self._tpA.insert(p1) | |
716 self._tpA.insert(p2) | |
717 self._tpA.insert(p3) | |
718 lNumToRemove = [3, 4] | |
719 self._tpA.deleteFromIdList(lNumToRemove) | |
720 | |
721 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
722 self._db.execute( sqlCmd ) | |
723 obsPathTuple = self._db.cursor.fetchall() | |
724 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
725 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4),) | |
726 self.assertEquals(expPathTuple, obsPathTuple) | |
727 | |
728 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
729 self._db.execute( sqlCmd ) | |
730 obsPathTuple = self._db.cursor.fetchall() | |
731 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
732 (2, 1000000, "chr1", 100, 250, 1),) | |
733 self.assertEquals(expPathTuple, obsPathTuple) | |
734 | |
735 def test_deleteFromIdList_with_multiple_ID_on_BinPathTable(self): | |
736 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
737 p1 = Path() | |
738 p1.setFromTuple(tuple) | |
739 | |
740 tuple = ("3", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
741 p2 = Path() | |
742 p2.setFromTuple(tuple) | |
743 | |
744 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
745 p3 = Path() | |
746 p3.setFromTuple(tuple) | |
747 | |
748 self._db.createTable( self._table, "path" ) | |
749 self._db.createBinPathTable(self._table, True) | |
750 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
751 self._tpA.insert(p1) | |
752 self._tpA.insert(p2) | |
753 self._tpA.insert(p3) | |
754 lNumToRemove = [3] | |
755 self._tpA.deleteFromIdList(lNumToRemove) | |
756 | |
757 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
758 self._db.execute( sqlCmd ) | |
759 obsPathTuple = self._db.cursor.fetchall() | |
760 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4),) | |
761 self.assertEquals(expPathTuple, obsPathTuple) | |
762 | |
763 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
764 self._db.execute( sqlCmd ) | |
765 obsPathTuple = self._db.cursor.fetchall() | |
766 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1),) | |
767 self.assertEquals(expPathTuple, obsPathTuple) | |
768 | |
769 def test_joinTwoPaths_with_min_and_max_existing_IDs(self): | |
770 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
771 p1 = Path() | |
772 p1.setFromTuple(tuple) | |
773 | |
774 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
775 p2 = Path() | |
776 p2.setFromTuple(tuple) | |
777 | |
778 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
779 p3 = Path() | |
780 p3.setFromTuple(tuple) | |
781 | |
782 self._db.createTable( self._table, "path" ) | |
783 self._db.createBinPathTable(self._table, True) | |
784 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
785 self._tpA.insert(p1) | |
786 self._tpA.insert(p2) | |
787 self._tpA.insert(p3) | |
788 expNewId = 1 | |
789 obsNewId = self._tpA.joinTwoPaths(1, 2) | |
790 | |
791 self.assertEquals(expNewId, obsNewId) | |
792 | |
793 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
794 self._db.execute( sqlCmd ) | |
795 obsPathTuple = self._db.cursor.fetchall() | |
796 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
797 (1, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
798 (3, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
799 self.assertEquals(expPathTuple, obsPathTuple) | |
800 | |
801 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
802 self._db.execute( sqlCmd ) | |
803 obsPathTuple = self._db.cursor.fetchall() | |
804 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
805 (1, 1000000, "chr1", 100, 250, 1), | |
806 (3, 1000000, "chr1", 15, 30, 1),) | |
807 self.assertEquals(expPathTuple, obsPathTuple) | |
808 | |
809 def test_joinTwoPaths_with_min_ID_not_existing_and_max_ID_existing(self): | |
810 tuple = ("4", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
811 p1 = Path() | |
812 p1.setFromTuple(tuple) | |
813 | |
814 tuple = ("5", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
815 p2 = Path() | |
816 p2.setFromTuple(tuple) | |
817 | |
818 tuple = ("6", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
819 p3 = Path() | |
820 p3.setFromTuple(tuple) | |
821 | |
822 self._db.createTable( self._table, "path" ) | |
823 self._db.createBinPathTable(self._table, True) | |
824 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
825 self._tpA.insert(p1) | |
826 self._tpA.insert(p2) | |
827 self._tpA.insert(p3) | |
828 expNewId = 1 | |
829 obsNewId = self._tpA.joinTwoPaths(1, 5) | |
830 | |
831 self.assertEquals(expNewId, obsNewId) | |
832 | |
833 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
834 self._db.execute( sqlCmd ) | |
835 obsPathTuple = self._db.cursor.fetchall() | |
836 expPathTuple = ((4, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
837 (1, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
838 (6, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
839 self.assertEquals(expPathTuple, obsPathTuple) | |
840 | |
841 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
842 self._db.execute( sqlCmd ) | |
843 obsPathTuple = self._db.cursor.fetchall() | |
844 expPathTuple = ((4, 1000000, "chr1", 10, 25, 1), | |
845 (1, 1000000, "chr1", 100, 250, 1), | |
846 (6, 1000000, "chr1", 15, 30, 1),) | |
847 self.assertEquals(expPathTuple, obsPathTuple) | |
848 | |
849 def test_joinTwoPaths_with_min_ID_existing_and_max_ID_not_existing(self): | |
850 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
851 p1 = Path() | |
852 p1.setFromTuple(tuple) | |
853 | |
854 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
855 p2 = Path() | |
856 p2.setFromTuple(tuple) | |
857 | |
858 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
859 p3 = Path() | |
860 p3.setFromTuple(tuple) | |
861 | |
862 self._db.createTable( self._table, "path" ) | |
863 self._db.createBinPathTable(self._table, True) | |
864 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
865 self._tpA.insert(p1) | |
866 self._tpA.insert(p2) | |
867 self._tpA.insert(p3) | |
868 expNewId = 1 | |
869 obsNewId = self._tpA.joinTwoPaths(1, 5) | |
870 | |
871 self.assertEquals(expNewId, obsNewId) | |
872 | |
873 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
874 self._db.execute( sqlCmd ) | |
875 obsPathTuple = self._db.cursor.fetchall() | |
876 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
877 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
878 (3, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
879 self.assertEquals(expPathTuple, obsPathTuple) | |
880 | |
881 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
882 self._db.execute( sqlCmd ) | |
883 obsPathTuple = self._db.cursor.fetchall() | |
884 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
885 (2, 1000000, "chr1", 100, 250, 1), | |
886 (3, 1000000, "chr1", 15, 30, 1),) | |
887 self.assertEquals(expPathTuple, obsPathTuple) | |
888 | |
889 def test_joinTwoPaths_with_min_and_max_not_existing_IDs(self): | |
890 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
891 p1 = Path() | |
892 p1.setFromTuple(tuple) | |
893 | |
894 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
895 p2 = Path() | |
896 p2.setFromTuple(tuple) | |
897 | |
898 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
899 p3 = Path() | |
900 p3.setFromTuple(tuple) | |
901 | |
902 self._db.createTable( self._table, "path" ) | |
903 self._db.createBinPathTable(self._table, True) | |
904 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
905 self._tpA.insert(p1) | |
906 self._tpA.insert(p2) | |
907 self._tpA.insert(p3) | |
908 expNewId = 4 | |
909 obsNewId = self._tpA.joinTwoPaths(4, 5) | |
910 | |
911 self.assertEquals(expNewId, obsNewId) | |
912 | |
913 sqlCmd = "SELECT * FROM %s" % ( self._table ) | |
914 self._db.execute( sqlCmd ) | |
915 obsPathTuple = self._db.cursor.fetchall() | |
916 expPathTuple = ((1, "chr1", 10, 25, "TE1", 11, 17, 1e-18, 20, 87.4), | |
917 (2, "chr1", 100, 250, "TE1", 11, 17, 1e-18, 20, 87.4), | |
918 (3, "chr1", 15, 30, "TE2", 10, 13, 5e-24, 34, 93.1),) | |
919 self.assertEquals(expPathTuple, obsPathTuple) | |
920 | |
921 sqlCmd = "SELECT * FROM %s_idx" % ( self._table ) | |
922 self._db.execute( sqlCmd ) | |
923 obsPathTuple = self._db.cursor.fetchall() | |
924 expPathTuple = ((1, 1000000, "chr1", 10, 25, 1), | |
925 (2, 1000000, "chr1", 100, 250, 1), | |
926 (3, 1000000, "chr1", 15, 30, 1),) | |
927 self.assertEquals(expPathTuple, obsPathTuple) | |
928 | |
929 def test_getNewId(self): | |
930 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
931 p1 = Path() | |
932 p1.setFromTuple(tuple) | |
933 | |
934 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
935 p2 = Path() | |
936 p2.setFromTuple(tuple) | |
937 | |
938 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
939 p3 = Path() | |
940 p3.setFromTuple(tuple) | |
941 | |
942 self._db.createTable( self._table, "path" ) | |
943 self._db.createBinPathTable(self._table, True) | |
944 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
945 self._tpA.insert(p1) | |
946 self._tpA.insert(p2) | |
947 self._tpA.insert(p3) | |
948 expNewId = 4 | |
949 obsNewId = self._tpA.getNewId() | |
950 | |
951 self.assertEquals(expNewId, obsNewId) | |
952 | |
953 def test_getNewId_with_empty_path_table(self): | |
954 self._db.createTable( self._table, "path" ) | |
955 self._db.createBinPathTable(self._table, True) | |
956 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
957 | |
958 expNewId = 1 | |
959 obsNewId = self._tpA.getNewId() | |
960 | |
961 self.assertEquals(expNewId, obsNewId) | |
962 | |
963 def test_getSetListIncludedInQueryCoord_one_included(self): | |
964 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
965 p1 = Path() | |
966 p1.setFromTuple(tuple) | |
967 | |
968 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
969 p2 = Path() | |
970 p2.setFromTuple(tuple) | |
971 | |
972 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
973 p3 = Path() | |
974 p3.setFromTuple(tuple) | |
975 | |
976 self._db.createTable( self._table, "path" ) | |
977 self._db.createBinPathTable(self._table, True) | |
978 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
979 self._tpA.insert(p1) | |
980 self._tpA.insert(p2) | |
981 self._tpA.insert(p3) | |
982 | |
983 s2 = Set() | |
984 s2.setFromTuple(("2","TE1","chr1","100","250")) | |
985 expLSet = [s2] | |
986 obsLSet = self._tpA.getSetListIncludedInQueryCoord('chr1', 95, 300) | |
987 | |
988 self.assertEquals(expLSet, obsLSet) | |
989 | |
990 def test_getSetListIncludedInQueryCoord_one_overlapping(self): | |
991 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
992 p1 = Path() | |
993 p1.setFromTuple(tuple) | |
994 | |
995 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
996 p2 = Path() | |
997 p2.setFromTuple(tuple) | |
998 | |
999 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1000 p3 = Path() | |
1001 p3.setFromTuple(tuple) | |
1002 | |
1003 self._db.createTable( self._table, "path" ) | |
1004 self._db.createBinPathTable(self._table, True) | |
1005 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1006 self._tpA.insert(p1) | |
1007 self._tpA.insert(p2) | |
1008 self._tpA.insert(p3) | |
1009 | |
1010 expLSet = [] | |
1011 obsLSet = self._tpA.getSetListIncludedInQueryCoord('chr1', 150, 200) | |
1012 | |
1013 self.assertEquals(expLSet, obsLSet) | |
1014 | |
1015 def test_getSetListIncludedInQueryCoord_with_no_result(self): | |
1016 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1017 p1 = Path() | |
1018 p1.setFromTuple(tuple) | |
1019 | |
1020 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1021 p2 = Path() | |
1022 p2.setFromTuple(tuple) | |
1023 | |
1024 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1025 p3 = Path() | |
1026 p3.setFromTuple(tuple) | |
1027 | |
1028 self._db.createTable( self._table, "path" ) | |
1029 self._db.createBinPathTable(self._table, True) | |
1030 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1031 self._tpA.insert(p1) | |
1032 self._tpA.insert(p2) | |
1033 self._tpA.insert(p3) | |
1034 | |
1035 expLSet = [] | |
1036 obsLSet = self._tpA.getSetListIncludedInQueryCoord('chr1', 5000, 6000) | |
1037 | |
1038 self.assertEquals(expLSet, obsLSet) | |
1039 | |
1040 def test_getSetListIncludedInQueryCoord_one_included_and_two_chain(self): | |
1041 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1042 p1 = Path() | |
1043 p1.setFromTuple(tuple) | |
1044 | |
1045 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1046 p2 = Path() | |
1047 p2.setFromTuple(tuple) | |
1048 | |
1049 tuple = ("2", "chr1", "1000", "2500", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1050 p3 = Path() | |
1051 p3.setFromTuple(tuple) | |
1052 | |
1053 tuple = ("3", "chr1", "50", "150", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1054 p4 = Path() | |
1055 p4.setFromTuple(tuple) | |
1056 | |
1057 tuple = ("4", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1058 p5 = Path() | |
1059 p5.setFromTuple(tuple) | |
1060 | |
1061 self._db.createTable( self._table, "path" ) | |
1062 self._db.createBinPathTable(self._table, True) | |
1063 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1064 self._tpA.insert(p1) | |
1065 self._tpA.insert(p2) | |
1066 self._tpA.insert(p3) | |
1067 self._tpA.insert(p4) | |
1068 self._tpA.insert(p5) | |
1069 | |
1070 s2 = Set() | |
1071 s2.setFromTuple(("2","TE1","chr1","100","250")) | |
1072 expLSet = [s2] | |
1073 obsLSet = self._tpA.getSetListIncludedInQueryCoord('chr1', 95, 300) | |
1074 | |
1075 self.assertEquals(expLSet, obsLSet) | |
1076 | |
1077 def test_getSetListOverlappingQueryCoord_one_included(self): | |
1078 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1079 p1 = Path() | |
1080 p1.setFromTuple(tuple) | |
1081 | |
1082 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1083 p2 = Path() | |
1084 p2.setFromTuple(tuple) | |
1085 | |
1086 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1087 p3 = Path() | |
1088 p3.setFromTuple(tuple) | |
1089 | |
1090 self._db.createTable( self._table, "path" ) | |
1091 self._db.createBinPathTable(self._table, True) | |
1092 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1093 self._tpA.insert(p1) | |
1094 self._tpA.insert(p2) | |
1095 self._tpA.insert(p3) | |
1096 | |
1097 s2 = Set() | |
1098 s2.setFromTuple(("2","TE1","chr1","100","250")) | |
1099 expLSet = [s2] | |
1100 obsLSet = self._tpA.getSetListOverlappingQueryCoord('chr1', 95, 300) | |
1101 | |
1102 self.assertEquals(expLSet, obsLSet) | |
1103 | |
1104 def test_getSetListOverlappingQueryCoord_one_overlapping(self): | |
1105 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1106 p1 = Path() | |
1107 p1.setFromTuple(tuple) | |
1108 | |
1109 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1110 p2 = Path() | |
1111 p2.setFromTuple(tuple) | |
1112 | |
1113 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1114 p3 = Path() | |
1115 p3.setFromTuple(tuple) | |
1116 | |
1117 self._db.createTable( self._table, "path" ) | |
1118 self._db.createBinPathTable(self._table, True) | |
1119 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1120 self._tpA.insert(p1) | |
1121 self._tpA.insert(p2) | |
1122 self._tpA.insert(p3) | |
1123 | |
1124 s2 = Set() | |
1125 s2.setFromTuple(("2","TE1","chr1","100","250")) | |
1126 expLSet = [s2] | |
1127 obsLSet = self._tpA.getSetListOverlappingQueryCoord('chr1', 150, 200) | |
1128 | |
1129 self.assertEquals(expLSet, obsLSet) | |
1130 | |
1131 def test_getSetListOverlappingQueryCoord_with_no_result(self): | |
1132 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1133 p1 = Path() | |
1134 p1.setFromTuple(tuple) | |
1135 | |
1136 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1137 p2 = Path() | |
1138 p2.setFromTuple(tuple) | |
1139 | |
1140 tuple = ("3", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1141 p3 = Path() | |
1142 p3.setFromTuple(tuple) | |
1143 | |
1144 self._db.createTable( self._table, "path" ) | |
1145 self._db.createBinPathTable(self._table, True) | |
1146 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1147 self._tpA.insert(p1) | |
1148 self._tpA.insert(p2) | |
1149 self._tpA.insert(p3) | |
1150 | |
1151 expLSet = [] | |
1152 obsLSet = self._tpA.getSetListOverlappingQueryCoord('chr1', 5000, 6000) | |
1153 | |
1154 self.assertEquals(expLSet, obsLSet) | |
1155 | |
1156 def test_getSetListOverlappingQueryCoord_one_included_and_two_chain(self): | |
1157 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1158 p1 = Path() | |
1159 p1.setFromTuple(tuple) | |
1160 | |
1161 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1162 p2 = Path() | |
1163 p2.setFromTuple(tuple) | |
1164 | |
1165 tuple = ("2", "chr1", "1000", "2500", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1166 p3 = Path() | |
1167 p3.setFromTuple(tuple) | |
1168 | |
1169 tuple = ("3", "chr1", "50", "150", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1170 p4 = Path() | |
1171 p4.setFromTuple(tuple) | |
1172 | |
1173 tuple = ("4", "chr1", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1174 p5 = Path() | |
1175 p5.setFromTuple(tuple) | |
1176 | |
1177 self._db.createTable( self._table, "path" ) | |
1178 self._db.createBinPathTable(self._table, True) | |
1179 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1180 self._tpA.insert(p1) | |
1181 self._tpA.insert(p2) | |
1182 self._tpA.insert(p3) | |
1183 self._tpA.insert(p4) | |
1184 self._tpA.insert(p5) | |
1185 | |
1186 s2 = Set() | |
1187 s2.setFromTuple(("2","TE1","chr1","100","250")) | |
1188 s4 = Set() | |
1189 s4.setFromTuple(("3","TE1","chr1","50","150")) | |
1190 expLSet = [s2, s4] | |
1191 obsLSet = self._tpA.getSetListOverlappingQueryCoord('chr1', 95, 300) | |
1192 | |
1193 self.assertEquals(expLSet, obsLSet) | |
1194 | |
1195 def test_getIdList( self ): | |
1196 p1 = Path() | |
1197 p1.setFromString( "1\tchr1\t1\t10\tTE1\t11\t17\t1e-20\t30\t90.2\n" ) | |
1198 p2 = Path() | |
1199 p2.setFromString( "2\tchr1\t2\t9\tTE2\t10\t13\t1e-20\t30\t90.2\n" ) | |
1200 p3 = Path() | |
1201 p3.setFromString( "2\tchr1\t12\t19\tTE2\t15\t22\t1e-10\t40\t94.2\n" ) | |
1202 p4 = Path() | |
1203 p4.setFromString( "3\tchr2\t8\t13\tTE1\t11\t17\t1e-20\t30\t90.2\n" ) | |
1204 | |
1205 self._db.createTable( self._table, "path" ) | |
1206 self._db.createBinPathTable(self._table, True) | |
1207 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1208 | |
1209 lPath = [ p1, p2, p3, p4] | |
1210 self._tpA.insertList(lPath) | |
1211 | |
1212 expList = [ 1, 2, 3 ] | |
1213 obsList = self._tpA.getIdList() | |
1214 | |
1215 self.assertEqual( expList, obsList ) | |
1216 | |
1217 def test_getQueryList(self): | |
1218 tuple = ("1", "chr1", "10", "25", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1219 p1 = Path() | |
1220 p1.setFromTuple(tuple) | |
1221 | |
1222 tuple = ("2", "chr1", "100", "250", "TE1", "11", "17", "1e-18", "20", "87.4") | |
1223 p2 = Path() | |
1224 p2.setFromTuple(tuple) | |
1225 | |
1226 tuple = ("3", "chr2", "15", "30", "TE2", "10", "13", "5e-24", "34", "93.1") | |
1227 p3 = Path() | |
1228 p3.setFromTuple(tuple) | |
1229 | |
1230 self._db.createTable( self._table, "path" ) | |
1231 self._db.createBinPathTable(self._table, True) | |
1232 self._tpA = TableBinPathAdaptator( self._db, self._table ) | |
1233 self._tpA.insert(p1) | |
1234 self._tpA.insert(p2) | |
1235 self._tpA.insert(p3) | |
1236 | |
1237 expList = [ "chr1", "chr2" ] | |
1238 obsList = self._tpA.getQueryList() | |
1239 self.assertEqual( expList, obsList ) | |
1240 | |
1241 test_suite = unittest.TestSuite() | |
1242 test_suite.addTest( unittest.makeSuite( Test_TableBinPathAdaptator ) ) | |
1243 if __name__ == '__main__': | |
1244 unittest.TextTestRunner(verbosity=2).run( test_suite ) |