6
|
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
|
|
32 import unittest
|
|
33 import os
|
|
34 import time
|
|
35 from commons.core.coord.PathUtils import PathUtils
|
|
36 from commons.core.coord.Path import Path
|
|
37 from commons.core.coord.Set import Set
|
|
38 from commons.core.utils.FileUtils import FileUtils
|
|
39 from commons.core.coord.Range import Range
|
|
40 from commons.core.coord.Align import Align
|
|
41
|
|
42
|
|
43 class Test_PathUtils ( unittest.TestCase ):
|
|
44
|
|
45 def test_getSetListFromQueries( self ):
|
|
46 set1 = Set(1,"TE2","chr1",1,10)
|
|
47 set2 = Set(1,"TE2","chr1",10,1)
|
|
48 set3 = Set(1,"TE3","chr4",12,22)
|
|
49
|
|
50 expList = [set1, set2, set3]
|
|
51
|
|
52 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
53 tuple2 = ("1","chr1","10","1","TE2","11","17","1e-20","30","90.2")
|
|
54 tuple3 = ("1","chr4","12","22","TE3","11","17","1e-20","30","90.2")
|
|
55
|
|
56 pathList = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
57
|
|
58 obsList = PathUtils.getSetListFromQueries( pathList )
|
|
59
|
|
60 self.assertEquals( expList, obsList )
|
|
61
|
|
62
|
|
63 def test_getSetListFromQueries_on_empty_list( self ):
|
|
64 expList = []
|
|
65 obsList = PathUtils.getSetListFromQueries( [] )
|
|
66
|
|
67 self.assertEquals( expList, obsList )
|
|
68
|
|
69
|
|
70 def test_getSetListFromQueries_on_list_size1( self ):
|
|
71 set1 = Set(1,"TE2","chr1",1,10)
|
|
72
|
|
73 expList = [set1]
|
|
74
|
|
75 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
76 path1 = Path()
|
|
77 path1.setFromTuple(tuple1)
|
|
78
|
|
79 pathList = [path1]
|
|
80 obsList = PathUtils.getSetListFromQueries( pathList )
|
|
81
|
|
82 self.assertEquals( expList, obsList )
|
|
83
|
|
84
|
|
85 def test_getRangeListFromSubjects_initiallyOrdered_directStrand( self ):
|
|
86 tuple1 = ("1","chr1","1","10","TE2","1","10","1e-20","30","90.2")
|
|
87 tuple2 = ("1","chr1","21","30","TE2","11","20","1e-20","30","90.2")
|
|
88 tuple3 = ("1","chr1","41","50","TE2","21","30","1e-20","30","90.2")
|
|
89 lPaths = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
90
|
|
91 iSet1 = Range( "TE2", 1, 10 )
|
|
92 iSet2 = Range( "TE2", 11, 20 )
|
|
93 iSet3 = Range( "TE2", 21, 30 )
|
|
94 lExp = [ iSet1, iSet2, iSet3 ]
|
|
95
|
|
96 lObs = PathUtils.getRangeListFromSubjects( lPaths )
|
|
97
|
|
98 self.assertEquals( lExp, lObs )
|
|
99
|
|
100
|
|
101 def test_getRangeListFromSubjects_initiallyUnordered_directStrand( self ):
|
|
102 tuple1 = ("1","chr1","1","10","TE2","1","10","1e-20","30","90.2")
|
|
103 tuple2 = ("1","chr1","41","50","TE2","21","30","1e-20","30","90.2")
|
|
104 tuple3 = ("1","chr1","21","30","TE2","11","20","1e-20","30","90.2")
|
|
105 lPaths = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
106
|
|
107 iSet1 = Range( "TE2", 1, 10 )
|
|
108 iSet2 = Range( "TE2", 11, 20 )
|
|
109 iSet3 = Range( "TE2", 21, 30 )
|
|
110 lExp = [ iSet1, iSet2, iSet3 ]
|
|
111
|
|
112 lObs = PathUtils.getRangeListFromSubjects( lPaths )
|
|
113
|
|
114 self.assertEquals( lExp, lObs )
|
|
115
|
|
116
|
|
117 def test_getRangeListFromSubjects_initiallyUnordered_reverseStrand( self ):
|
|
118 tuple1 = ("1","chr1","1","10","TE2","10","1","1e-20","30","90.2")
|
|
119 tuple2 = ("1","chr1","41","50","TE2","30","21","1e-20","30","90.2")
|
|
120 tuple3 = ("1","chr1","21","30","TE2","20","11","1e-20","30","90.2")
|
|
121 lPaths = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
122
|
|
123 iSet3 = Range( "TE2", 30, 21 )
|
|
124 iSet2 = Range( "TE2", 20, 11 )
|
|
125 iSet1 = Range( "TE2", 10, 1 )
|
|
126 lExp = [ iSet1, iSet2, iSet3 ]
|
|
127
|
|
128 lObs = PathUtils.getRangeListFromSubjects( lPaths )
|
|
129
|
|
130 self.assertEquals( lExp, lObs )
|
|
131
|
|
132
|
|
133 def test_getQueryMinMaxFromPathList( self ):
|
|
134 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
135 tuple2 = ("1","chr1","10","1","TE2","11","17","1e-20","30","90.2")
|
|
136 tuple3 = ("1","chr4","12","22","TE3","11","17","1e-20","30","90.2")
|
|
137
|
|
138 pathList = self._makePathListFromTupleList([tuple1, tuple2, tuple3])
|
|
139
|
|
140 obsTuple = PathUtils.getQueryMinMaxFromPathList( pathList )
|
|
141 expTuple = (1,22)
|
|
142
|
|
143 self.assertEquals(expTuple, obsTuple)
|
|
144
|
|
145 def test_getQueryMinMaxFromPathList_on_empty_list( self ):
|
|
146 obsTuple = PathUtils.getQueryMinMaxFromPathList( [] )
|
|
147 expTuple = (-1,-1)
|
|
148 self.assertEquals( expTuple, obsTuple )
|
|
149
|
|
150 def test_getQueryMinMaxFromPathList_on_list_size1( self ):
|
|
151 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
152 path1 = Path()
|
|
153 path1.setFromTuple(tuple1)
|
|
154
|
|
155 pathList = [path1]
|
|
156 obsTuple = PathUtils.getQueryMinMaxFromPathList( pathList )
|
|
157
|
|
158 expTuple = (1,10)
|
|
159
|
|
160 self.assertEquals(expTuple, obsTuple)
|
|
161
|
|
162 def test_getSubjectMinMaxFromPathList( self ):
|
|
163 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
164 tuple2 = ("1","chr1","10","1","TE2","17","11","1e-20","30","90.2")
|
|
165 tuple3 = ("1","chr4","12","22","TE3","22","34","1e-20","30","90.2")
|
|
166
|
|
167 pathList = self._makePathListFromTupleList([tuple1, tuple2, tuple3])
|
|
168 obsTuple = PathUtils.getSubjectMinMaxFromPathList(pathList)
|
|
169
|
|
170 expTuple = (11,34)
|
|
171
|
|
172 self.assertEquals(expTuple, obsTuple)
|
|
173
|
|
174 def test_getSubjectMinMaxFromPathList_on_empty_list( self ):
|
|
175 obsTuple = PathUtils.getSubjectMinMaxFromPathList([])
|
|
176 expTuple = (-1,-1)
|
|
177 self.assertEquals(expTuple, obsTuple)
|
|
178
|
|
179 def test_getSubjectMinMaxFromPathList_on_list_size1( self ):
|
|
180 tuple1 = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
181 path1 = Path()
|
|
182 path1.setFromTuple(tuple1)
|
|
183
|
|
184 pathList = [path1]
|
|
185 obsTuple = PathUtils.getSubjectMinMaxFromPathList(pathList)
|
|
186
|
|
187 expTuple = (11,17)
|
|
188
|
|
189 self.assertEquals(expTuple, obsTuple)
|
|
190
|
|
191 def test_areQueriesOverlappingBetweenPathLists_list2_empty( self ):
|
|
192 tuple1 = ("1","chr1","100","110","TE2","15","10","1e-20","30","90.2")
|
|
193 tuple2 = ("1","chr1","200","220","TE2","15","10","1e-20","30","90.2")
|
|
194 tuple3 = ("1","chr1","300","330","TE2","15","10","1e-20","30","90.2")
|
|
195 pathList1 = self._makePathListFromTupleList([tuple1, tuple2, tuple3])
|
|
196
|
|
197 pathList2 = []
|
|
198
|
|
199 expRes = False
|
|
200 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
201
|
|
202 self.assertEquals( expRes, obsRes )
|
|
203
|
|
204 def test_areQueriesOverlappingBetweenPathLists_list2_size1( self ):
|
|
205 tuple1 = ("1","chr1","9","11","TE2","150","200","1e-20","30","90.2")
|
|
206 tuple2 = ("1","chr1","20","22","TE2","150","200","1e-20","30","90.2")
|
|
207 tuple3 = ("1","chr1","30","33","TE2","150","200","1e-20","30","90.2")
|
|
208 pathList1 = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
209
|
|
210 tuple11 = ("1","chr1","8","11","TE2","150","200","1e-20","30","90.2")
|
|
211 pathList2 = self._makePathListFromTupleList( [ tuple11 ] )
|
|
212
|
|
213 expRes = True
|
|
214 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
215
|
|
216 self.assertEquals( expRes, obsRes )
|
|
217
|
|
218 def test_areQueriesOverlappingBetweenPathLists_list1_greater_list2( self ):
|
|
219 tuple1 = ("1","chr1","100","110","TE2","15","10","1e-20","30","90.2")
|
|
220 tuple2 = ("1","chr1","200","220","TE2","15","10","1e-20","30","90.2")
|
|
221 tuple3 = ("1","chr1","300","330","TE2","15","10","1e-20","30","90.2")
|
|
222 pathList1 = self._makePathListFromTupleList( [ tuple1, tuple2, tuple3 ] )
|
|
223
|
|
224 tuple11 = ("1","chr1","10","11","TE2","150","200","1e-20","30","90.2")
|
|
225 tuple22 = ("1","chr1","20","22","TE2","150","200","1e-20","30","90.2")
|
|
226 tuple33 = ("1","chr1","30","33","TE2","150","200","1e-20","30","90.2")
|
|
227 pathList2 = self._makePathListFromTupleList( [ tuple11, tuple22, tuple33 ] )
|
|
228
|
|
229 expRes = False
|
|
230 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
231
|
|
232 self.assertEquals( expRes, obsRes )
|
|
233
|
|
234 def test_areQueriesOverlappingBetweenPathLists_unordered_first_item_of_list1_greater_second_item_smaller( self ):
|
|
235 tuple1 = ("1","chr1","400","440","TE2","15","10","1e-20","30","90.2")
|
|
236 tuple2 = ("1","chr1","1","11","TE2","15","10","1e-20","30","90.2")
|
|
237 pathList1 = self._makePathListFromTupleList( [ tuple1, tuple2 ] )
|
|
238
|
|
239 tuple11 = ("1","chr1","15","17","TE2","150","200","1e-20","30","90.2")
|
|
240 tuple22 = ("1","chr1","20","22","TE2","150","200","1e-20","30","90.2")
|
|
241 tuple33 = ("1","chr1","30","33","TE2","150","200","1e-20","30","90.2")
|
|
242 pathList2 = self._makePathListFromTupleList( [ tuple11, tuple22, tuple33 ] )
|
|
243
|
|
244 expRes = False
|
|
245 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
246
|
|
247 self.assertEquals( expRes, obsRes )
|
|
248
|
|
249 def test_areQueriesOverlappingBetweenPathLists_unorderd_second_item_of_list1_overlap_first_item( self ):
|
|
250 tuple1 = ("1","chr1","400","440","TE2","15","10","1e-20","30","90.2")
|
|
251 tuple2 = ("1","chr1","1","18","TE2","15","10","1e-20","30","90.2")
|
|
252 pathList1 = self._makePathListFromTupleList( [ tuple1, tuple2 ] )
|
|
253
|
|
254 tuple11 = ("1","chr1","15","17","TE2","150","200","1e-20","30","90.2")
|
|
255 tuple22 = ("1","chr1","20","22","TE2","150","200","1e-20","30","90.2")
|
|
256 tuple33 = ("1","chr1","30","33","TE2","150","200","1e-20","30","90.2")
|
|
257 pathList2 = self._makePathListFromTupleList( [ tuple11, tuple22, tuple33 ] )
|
|
258
|
|
259 expRes = True
|
|
260 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
261
|
|
262 self.assertEquals( expRes, obsRes )
|
|
263
|
|
264 def test_areQueriesOverlappingBetweenPathLists_last_item_list1_overlap_last_item_list2( self ):
|
|
265 tuple1 = ("1","chr1","400","440","TE2","15","10","1e-20","30","90.2")
|
|
266 tuple2 = ("1","chr1","320","340","TE2","15","10","1e-20","30","90.2")
|
|
267 pathList1 = self._makePathListFromTupleList( [ tuple1, tuple2 ] )
|
|
268
|
|
269 tuple11 = ("1","chr1","100","110","TE2","150","200","1e-20","30","90.2")
|
|
270 tuple22 = ("1","chr1","200","220","TE2","150","200","1e-20","30","90.2")
|
|
271 tuple33 = ("1","chr1","300","330","TE2","150","200","1e-20","30","90.2")
|
|
272 pathList2 = self._makePathListFromTupleList( [ tuple11, tuple22, tuple33 ] )
|
|
273
|
|
274 expRes = True
|
|
275 obsRes = PathUtils.areQueriesOverlappingBetweenPathLists( pathList1, pathList2 )
|
|
276
|
|
277 self.assertEquals( expRes, obsRes )
|
|
278
|
|
279 def test_writeListInFile( self ):
|
|
280 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
281 line2 = ("1\tchr1\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
282 line3 = ("1\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
283
|
|
284 expFileName = "expFileName.path"
|
|
285 expFileHandle = open ( expFileName, 'w' )
|
|
286 expFileHandle.write(line1)
|
|
287 expFileHandle.write(line2)
|
|
288 expFileHandle.write(line3)
|
|
289 expFileHandle.close()
|
|
290
|
|
291 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
292 line2 = ("1\tchr1\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
293 line3 = ("1\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
294
|
|
295 obsFileName = "obsFileName.path"
|
|
296 obsPathList = self._makePathListFromStringList( [ line1, line2, line3 ] )
|
|
297
|
|
298 PathUtils.writeListInFile( obsPathList, obsFileName )
|
|
299
|
|
300 self.assertTrue( FileUtils.are2FilesIdentical( expFileName, obsFileName ) )
|
|
301
|
|
302 os.remove( obsFileName )
|
|
303 os.remove( expFileName )
|
|
304
|
|
305 def test_writeListInFile_in_append_mode( self ):
|
|
306 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
307 line2 = ("1\tchr1\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
308 line3 = ("1\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
309 line4 = ("1\tchr1\t400\t410\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
310 line5 = ("1\tchr1\t500\t520\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
311 line6 = ("1\tchr1\t600\t630\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
312
|
|
313 expFileName = "expFileName.path"
|
|
314 expFileHandle = open ( expFileName, 'w' )
|
|
315 expFileHandle.write(line1)
|
|
316 expFileHandle.write(line2)
|
|
317 expFileHandle.write(line3)
|
|
318 expFileHandle.write(line4)
|
|
319 expFileHandle.write(line5)
|
|
320 expFileHandle.write(line6)
|
|
321 expFileHandle.close()
|
|
322
|
|
323 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
324 line2 = ("1\tchr1\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
325 line3 = ("1\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.200000\n")
|
|
326 line4 = ("1\tchr1\t400\t410\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
327 line5 = ("1\tchr1\t500\t520\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
328 line6 = ("1\tchr1\t600\t630\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
329
|
|
330 obsFileName = "obsFileName.path"
|
|
331 obsFileHandle = open( obsFileName, 'w' )
|
|
332 obsFileHandle.write(line1)
|
|
333 obsFileHandle.write(line2)
|
|
334 obsFileHandle.write(line3)
|
|
335 obsFileHandle.close()
|
|
336
|
|
337 obsPathList = self._makePathListFromStringList( [ line4, line5, line6 ] )
|
|
338
|
|
339 PathUtils.writeListInFile( obsPathList, obsFileName, "a" )
|
|
340
|
|
341 self.assertTrue( FileUtils.are2FilesIdentical( expFileName, obsFileName ) )
|
|
342
|
|
343 os.remove(obsFileName)
|
|
344 os.remove(expFileName)
|
|
345
|
|
346 def test_getPathListWithoutDuplicates_empty_list( self ):
|
|
347 pathList = []
|
|
348 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
349
|
|
350 expPathList = []
|
|
351
|
|
352 self.assertEquals( expPathList, obsPathList )
|
|
353
|
|
354 def test_getPathListWithoutDuplicates_list_size1( self ):
|
|
355 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
356 pathList = self._makePathListFromStringList([line1])
|
|
357
|
|
358 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
359
|
|
360 expPathList = pathList
|
|
361
|
|
362 self.assertEquals( expPathList, obsPathList )
|
|
363
|
|
364 def test_getPathListWithoutDuplicates_list_with_only_doublons( self ):
|
|
365 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
366 line2 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
367 line3 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
368 line4 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
369 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4 ] )
|
|
370
|
|
371 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
372
|
|
373 expPathList = self._makePathListFromStringList( [ line1 ] )
|
|
374
|
|
375 self.assertEquals( expPathList, obsPathList )
|
|
376
|
|
377 def test_getPathListWithoutDuplicates_list_with_doublons_at_start_and_at_end( self ):
|
|
378 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
379 line2 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
380 line3 = ("1\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
381 line4 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
382 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4 ] )
|
|
383
|
|
384 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
385
|
|
386 expPathList = self._makePathListFromStringList( [ line1, line2, line3 ] )
|
|
387 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
388
|
|
389 self.assertEquals( expPathList, obsPathList )
|
|
390
|
|
391 def test_getPathListWithoutDuplicates_list_with_contiguus_doublons( self ):
|
|
392 line1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
393 line2 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
394 line3 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
395 line4 = ("1\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
396 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4 ] )
|
|
397
|
|
398 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
399
|
|
400 expPathList = self._makePathListFromStringList( [ line1, line2, line4 ] )
|
|
401 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
402
|
|
403 self.assertEquals( expPathList, obsPathList )
|
|
404
|
|
405 def test_getPathListWithoutDuplicates_list_with_one_doublon( self ):
|
|
406 line1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
407 line2 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
408 line3 = ("1\tchr1\t210\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
409 line4 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
410 line5 = ("1\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
411 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line5 ] )
|
|
412
|
|
413 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
414
|
|
415 expPathList = self._makePathListFromStringList( [ line1, line2, line3, line5 ] )
|
|
416 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
417
|
|
418 self.assertEquals( expPathList, obsPathList )
|
|
419
|
|
420 def test_getPathListWithoutDuplicates_list_with_two_doublons( self ):
|
|
421 line1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
422 line2 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
423 line3 = ("1\tchr1\t210\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
424 line4 = ("1\tchr1\t230\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
425 line5 = ("1\tchr1\t210\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
426 line6 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
427 line7 = ("1\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
428 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line5, line6, line7 ] )
|
|
429
|
|
430 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
431
|
|
432 expPathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line7 ] )
|
|
433 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
434
|
|
435 self.assertEquals( expPathList, obsPathList )
|
|
436
|
|
437 def test_getPathListWithoutDuplicates_list_with_two_doublons_useOnlyCoord_is_False_different_id( self ):
|
|
438 line1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
439 line2 = ("2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
440 line3 = ("3\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
441 line4 = ("4\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
442 line5 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
443 line6 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
444 line7 = ("5\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
445 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line5, line6, line7 ] )
|
|
446
|
|
447 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList )
|
|
448
|
|
449 expPathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line7 ] )
|
|
450 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
451
|
|
452 self.assertEquals( expPathList, obsPathList )
|
|
453
|
|
454 def test_getPathListWithoutDuplicates_list_with_two_doublons_useOnlyCoord_is_True_different_id( self ):
|
|
455 line1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
456 line2 = ("2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
457 line3 = ("3\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
458 line4 = ("4\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
459 line5 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
460 line6 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
461 line7 = ("5\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
462 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line5, line6, line7 ] )
|
|
463
|
|
464 obsPathList = PathUtils.getPathListWithoutDuplicates( pathList, True )
|
|
465
|
|
466 expPathList = self._makePathListFromStringList( [ line1 ] )
|
|
467 expPathList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( expPathList )
|
|
468
|
|
469 self.assertEquals( expPathList, obsPathList )
|
|
470
|
|
471 def test_path_getDictOfListsWithIdAsKey_empty_list( self ):
|
|
472 pathList = []
|
|
473
|
|
474 obsDict = PathUtils.getDictOfListsWithIdAsKey( pathList )
|
|
475 expDict = {}
|
|
476
|
|
477 self.assertEquals( expDict, obsDict )
|
|
478
|
|
479 def test_path_getDictOfListsWithIdAsKey_list_size1( self ):
|
|
480 line1 = ( "1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
481 pathList = self._makePathListFromStringList( [ line1 ] )
|
|
482
|
|
483 obsDict = PathUtils.getDictOfListsWithIdAsKey( pathList )
|
|
484
|
|
485 expPathInstance = Path()
|
|
486 expPathInstance.setFromString( line1 )
|
|
487 expDict = { 1: [ expPathInstance ] }
|
|
488
|
|
489 self.assertEquals( expDict, obsDict )
|
|
490
|
|
491 def test_getDictOfListsWithIdAsKey_ids_only_once( self ):
|
|
492 line1 = ( "1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
493 line2 = ( "2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
494 line3 = ( "3\tchr1\t210\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
495
|
|
496 pathList = self._makePathListFromStringList( [ line1, line2, line3 ] )
|
|
497
|
|
498 obsDict = PathUtils.getDictOfListsWithIdAsKey( pathList )
|
|
499
|
|
500 expPathInstance1 = Path()
|
|
501 expPathInstance1.setFromString( line1 )
|
|
502
|
|
503 expPathInstance2 = Path()
|
|
504 expPathInstance2.setFromString( line2 )
|
|
505
|
|
506 expPathInstance3 = Path()
|
|
507 expPathInstance3.setFromString( line3 )
|
|
508
|
|
509 expDict = { 1: [ expPathInstance1 ], 2: [ expPathInstance2 ], 3: [ expPathInstance3 ] }
|
|
510
|
|
511 self.assertEquals( expDict, obsDict )
|
|
512
|
|
513 def test_getDictOfListsWithIdAsKey_ids_more_than_only_once( self ):
|
|
514 line1 = ( "1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
515 line2 = ( "2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
516 line3 = ( "3\tchr1\t210\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
517
|
|
518 line4 = ( "1\tchr1\t100\t120\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
519 line5 = ( "2\tchr1\t200\t220\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
520 line6 = ( "3\tchr1\t210\t260\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
521
|
|
522 line7 = ( "1\tchr1\t110\t120\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
523 line8 = ( "2\tchr1\t210\t220\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
524 line9 = ( "3\tchr1\t220\t260\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
525
|
|
526 pathList = self._makePathListFromStringList( [ line1, line2, line3, line4, line5, line6, line7, line8, line9 ] )
|
|
527
|
|
528 obsDict = PathUtils.getDictOfListsWithIdAsKey( pathList )
|
|
529
|
|
530 expPathInstance1 = Path()
|
|
531 expPathInstance1.setFromString( line1 )
|
|
532
|
|
533 expPathInstance2 = Path()
|
|
534 expPathInstance2.setFromString( line2 )
|
|
535
|
|
536 expPathInstance3 = Path()
|
|
537 expPathInstance3.setFromString( line3 )
|
|
538
|
|
539 expPathInstance4 = Path()
|
|
540 expPathInstance4.setFromString( line4 )
|
|
541
|
|
542 expPathInstance5 = Path()
|
|
543 expPathInstance5.setFromString( line5 )
|
|
544
|
|
545 expPathInstance6 = Path()
|
|
546 expPathInstance6.setFromString( line6 )
|
|
547
|
|
548 expPathInstance7 = Path()
|
|
549 expPathInstance7.setFromString( line7 )
|
|
550
|
|
551 expPathInstance8 = Path()
|
|
552 expPathInstance8.setFromString( line8 )
|
|
553
|
|
554 expPathInstance9 = Path()
|
|
555 expPathInstance9.setFromString( line9 )
|
|
556
|
|
557 expDict = { 1: [ expPathInstance1, expPathInstance4, expPathInstance7 ], 2 :[ expPathInstance2, expPathInstance5, expPathInstance8 ], 3: [ expPathInstance3, expPathInstance6, expPathInstance9 ] }
|
|
558
|
|
559 self.assertEquals( expDict, obsDict )
|
|
560
|
|
561 def test_getPathListUnjoinedBasedOnQuery_listToKeep_empty_listToUnjoin_empty( self ):
|
|
562 pathListToKeep = []
|
|
563 pathListToUnjoin = []
|
|
564
|
|
565 expList = []
|
|
566
|
|
567 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
568
|
|
569 self.assertEquals( expList, obsList )
|
|
570
|
|
571 def test_getPathListUnjoinedBasedOnQuery_listToKeep_empty_listToUnjoin_size1( self ):
|
|
572 pathListToKeep = []
|
|
573
|
|
574 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
575 pathListToUnjoin = self._makePathListFromStringList( [ line1 ] )
|
|
576
|
|
577 expList = [ pathListToUnjoin ]
|
|
578
|
|
579 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
580
|
|
581 self.assertEquals( expList, obsList )
|
|
582
|
|
583 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_empty( self ):
|
|
584 lineKeep1 = ("1\tchr1\t1\t11\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
585 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
586
|
|
587 pathListToUnjoin = []
|
|
588
|
|
589 expList = []
|
|
590
|
|
591 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
592
|
|
593 self.assertEquals( expList, obsList )
|
|
594
|
|
595 def test_getPathListUnjoinedBasedOnQuery_listToKeep_empty( self ):
|
|
596 pathListToKeep = []
|
|
597
|
|
598 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
599 line2 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
600 line3 = ("1\tchr1\t250\t280\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
601 pathListToUnjoin = self._makePathListFromStringList( [ line1, line2, line3 ] )
|
|
602
|
|
603 expList = [ pathListToUnjoin ]
|
|
604
|
|
605 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
606
|
|
607 self.assertEquals( expList, obsList )
|
|
608
|
|
609 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_size1( self ):
|
|
610 lineKeep1 = ("1\tchr1\t1\t11\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
611 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
612
|
|
613 lineUnjoin1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
614 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1 ] )
|
|
615
|
|
616 expList = [ pathListToUnjoin ]
|
|
617
|
|
618 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
619
|
|
620 self.assertEquals( expList, obsList )
|
|
621
|
|
622 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_size2_noSplit_minKeep( self ):
|
|
623 lineKeep1 = ("1\tchr1\t1\t10\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
624 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
625
|
|
626 lineUnjoin1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
627 lineUnjoin2 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
628 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] )
|
|
629
|
|
630 expList = [ pathListToUnjoin ]
|
|
631
|
|
632 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
633
|
|
634 self.assertEquals( expList, obsList )
|
|
635
|
|
636 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_size3_noSplit_minKeep( self ):
|
|
637 lineKeep1 = ("1\tchr1\t1\t10\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
638 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
639
|
|
640 lineUnjoin1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
641 lineUnjoin2 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
642 lineUnjoin3 = ("1\tchr1\t250\t280\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
643 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2, lineUnjoin3 ] )
|
|
644
|
|
645 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
646
|
|
647 expList = [ pathListToUnjoin ]
|
|
648
|
|
649 self.assertEquals( expList, obsList )
|
|
650
|
|
651 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_size2_noSplit_minUnjoin( self ):
|
|
652 lineKeep1 = ("1\tchr1\t101\t150\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
653 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
654
|
|
655 lineUnjoin1 = ("1\tchr1\t1\t10\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
656 lineUnjoin2 = ("1\tchr1\t21\t40\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
657 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] )
|
|
658
|
|
659 expList = [ pathListToUnjoin ]
|
|
660
|
|
661 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
662
|
|
663 self.assertEquals( expList, obsList )
|
|
664
|
|
665 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size3_listToUnjoin_size2_oneSplit_minKeep( self ):
|
|
666 lineKeep1 = ("1\tchr1\t1\t10\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
667 lineKeep2 = ("1\tchr1\t21\t30\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
668 lineKeep3 = ("1\tchr1\t61\t70\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
669 pathListToKeep = self._makePathListFromStringList( [ lineKeep1, lineKeep2, lineKeep3 ] )
|
|
670
|
|
671 lineUnjoin1 = ("1\tchr1\t41\t50\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
672 lineUnjoin2 = ("1\tchr1\t81\t90\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
673 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] )
|
|
674
|
|
675 expList = []
|
|
676 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
677 expList.append( self._makePathListFromStringList( [ lineUnjoin2 ] ) )
|
|
678
|
|
679 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
680
|
|
681 self.assertEquals( expList, obsList )
|
|
682
|
|
683 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size3_listToUnjoin_size3_twoSplits_minUnjoin( self ):
|
|
684 lineKeep1 = ("1\tchr1\t21\t30\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
685 lineKeep2 = ("1\tchr1\t41\t50\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
686 lineKeep3 = ("1\tchr1\t81\t90\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
687 pathListToKeep = self._makePathListFromStringList( [ lineKeep1, lineKeep2, lineKeep3 ] )
|
|
688
|
|
689 lineUnjoin1 = ("1\tchr1\t1\t10\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
690 lineUnjoin2 = ("1\tchr1\t61\t70\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
691 lineUnjoin3 = ("1\tchr1\t101\t110\tTE2\t150\t90\t0.000000\t30\t90.200000\n")
|
|
692 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2, lineUnjoin3 ] )
|
|
693
|
|
694 expList = []
|
|
695 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
696 expList.append( self._makePathListFromStringList( [ lineUnjoin2 ] ) )
|
|
697 expList.append( self._makePathListFromStringList( [ lineUnjoin3 ] ) )
|
|
698
|
|
699 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
700
|
|
701 self.assertEquals( expList, obsList )
|
|
702
|
|
703 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_size2_split( self ):
|
|
704 lineKeep1 = ("1\tchr1\t51\t80\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
705 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
706
|
|
707 lineUnjoin1 = ("1\tchr1\t21\t40\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
708 lineUnjoin2 = ("1\tchr1\t101\t150\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
709 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] )
|
|
710
|
|
711 expList = []
|
|
712 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
713 expList.append( self._makePathListFromStringList( [ lineUnjoin2 ] ) )
|
|
714
|
|
715 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
716
|
|
717 self.assertEquals( expList, obsList )
|
|
718
|
|
719 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size2_listToUnjoin_size2_split( self ):
|
|
720 lineKeep1 = ("1\tchr1\t1\t15\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
721 lineKeep2 = ("1\tchr1\t81\t130\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
722 pathListToKeep = self._makePathListFromStringList( [ lineKeep1, lineKeep2 ] )
|
|
723
|
|
724 lineUnjoin1 = ("1\tchr1\t21\t40\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
725 lineUnjoin2 = ("1\tchr1\t201\t250\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
726 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] )
|
|
727
|
|
728 expList = []
|
|
729 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
730 expList.append( self._makePathListFromStringList( [ lineUnjoin2 ] ) )
|
|
731
|
|
732 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
733
|
|
734 self.assertEquals( expList, obsList )
|
|
735
|
|
736 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_ordered_OneSplit( self ):
|
|
737 lineKeep1 = ("1\tchr1\t120\t180\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
738 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
739
|
|
740 lineUnjoin1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
741 lineUnjoin2 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
742 lineUnjoin3 = ("1\tchr1\t250\t280\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
743 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2, lineUnjoin3 ] )
|
|
744
|
|
745 expList = []
|
|
746 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
747 expList.append( self._makePathListFromStringList( [ lineUnjoin2, lineUnjoin3 ] ) )
|
|
748
|
|
749 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
750
|
|
751 self.assertEquals( expList, obsList )
|
|
752
|
|
753 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size1_listToUnjoin_unordered_OneSplit( self ):
|
|
754 lineKeep1 = ("1\tchr1\t120\t180\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
755 pathListToKeep = self._makePathListFromStringList( [ lineKeep1 ] )
|
|
756
|
|
757 lineUnjoin1 = ("1\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
758 lineUnjoin2 = ("1\tchr1\t250\t280\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
759 lineUnjoin3 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
760 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2, lineUnjoin3 ] )
|
|
761
|
|
762 expList = []
|
|
763 expList.append( self._makePathListFromStringList( [ lineUnjoin3 ] ) )
|
|
764 expList.append( self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2 ] ) )
|
|
765
|
|
766 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
767
|
|
768 self.assertEquals( expList, obsList )
|
|
769
|
|
770 def test_getPathListUnjoinedBasedOnQuery_listToKeep_size2_listToUnjoin_size4_twoSplits( self ):
|
|
771 lineKeep1 = ("1\tchr1\t21\t30\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
772 lineKeep2 = ("1\tchr1\t81\t90\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
773 pathListToKeep = self._makePathListFromStringList( [ lineKeep1, lineKeep2 ] )
|
|
774
|
|
775 lineUnjoin1 = ("1\tchr1\t1\t10\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
776 lineUnjoin2 = ("1\tchr1\t41\t50\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
777 lineUnjoin3 = ("1\tchr1\t61\t70\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
778 lineUnjoin4 = ("1\tchr1\t101\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
779 pathListToUnjoin = self._makePathListFromStringList( [ lineUnjoin1, lineUnjoin2, lineUnjoin3, lineUnjoin4 ] )
|
|
780
|
|
781 expList = []
|
|
782 expList.append( self._makePathListFromStringList( [ lineUnjoin1 ] ) )
|
|
783 expList.append( self._makePathListFromStringList( [ lineUnjoin2, lineUnjoin3 ] ) )
|
|
784 expList.append( self._makePathListFromStringList( [ lineUnjoin4 ] ) )
|
|
785
|
|
786 obsList = PathUtils.getPathListUnjoinedBasedOnQuery( pathListToKeep, pathListToUnjoin )
|
|
787
|
|
788 self.assertEquals( expList, obsList )
|
|
789
|
|
790 def test_changeIdInList_empty_list ( self ):
|
|
791 pathList = []
|
|
792
|
|
793 PathUtils.changeIdInList(pathList,1)
|
|
794
|
|
795 obsList = pathList
|
|
796 expList = []
|
|
797
|
|
798 self.assertEquals(expList, obsList)
|
|
799
|
|
800 def test_changeIdInList_list_size1 ( self ):
|
|
801 line1 = ("1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
802 line2 = ("2\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n")
|
|
803
|
|
804 pathList = self._makePathListFromStringList([line1])
|
|
805 PathUtils.changeIdInList(pathList,2)
|
|
806
|
|
807 expPathList = pathList
|
|
808
|
|
809 obsPathList = self._makePathListFromStringList([line2])
|
|
810
|
|
811 self.assertEquals(expPathList, obsPathList)
|
|
812
|
|
813 def test_changeIdInList( self ):
|
|
814 line1 = ( "1\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
815 line2 = ( "2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
816 line3 = ( "3\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
817
|
|
818 pathList = self._makePathListFromStringList( [ line1, line2, line3 ] )
|
|
819 PathUtils.changeIdInList( pathList, 2 )
|
|
820 obsPathList = pathList
|
|
821
|
|
822 line11 = ( "2\tchr1\t100\t110\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
823 line22 = ( "2\tchr1\t200\t210\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
824 line33 = ( "2\tchr1\t300\t310\tTE2\t150\t200\t0.000000\t30\t90.200000\n" )
|
|
825
|
|
826 expPathList = self._makePathListFromStringList( [ line11, line22, line33 ] )
|
|
827
|
|
828 self.assertEquals( expPathList, obsPathList )
|
|
829
|
|
830
|
|
831 def test_getIdentityFromPathList( self ):
|
|
832 p1 = Path()
|
|
833 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
834 p2 = Path()
|
|
835 p2.setFromTuple( ( "2", "qry1", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
836 lPaths = [ p1, p2 ]
|
|
837 exp = ( 90.0 * ( 100-1+1) + 91.2 * (350-121+1) ) / ( (100-1+1) + (350-121+1) ) # 90.836363636363643
|
|
838 obs = PathUtils.getIdentityFromPathList( lPaths )
|
|
839 self.assertEqual( exp, obs )
|
|
840
|
|
841
|
|
842 def test_getIdentityFromPathList_withOverlap( self ):
|
|
843 p1 = Path()
|
|
844 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
845 p2 = Path()
|
|
846 p2.setFromTuple( ( "2", "qry1", "21", "80", "sbj1", "21", "80", "0.0", "176", "91.2" ) )
|
|
847 p3 = Path()
|
|
848 p3.setFromTuple( ( "2", "qry1", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
849 lPaths = [ p1, p2, p3 ]
|
|
850 exp = ( 91.2 * ( 100-1+1) + 91.2 * (350-121+1) ) / ( (100-1+1) + (350-121+1) )
|
|
851 obs = PathUtils.getIdentityFromPathList( lPaths )
|
|
852 self.assertEqual( exp, obs )
|
|
853
|
|
854
|
|
855 def test_getIdentityFromPathList_diffQueries( self ):
|
|
856 p1 = Path()
|
|
857 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
858 p2 = Path()
|
|
859 p2.setFromTuple( ( "2", "qry2", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
860 lPaths = [ p1, p2 ]
|
|
861 try:
|
|
862 obs = PathUtils.getIdentityFromPathList( lPaths )
|
|
863 except:
|
|
864 pass
|
|
865
|
|
866
|
|
867 def test_getIdentityFromPathList_diffSubjects_check( self ):
|
|
868 p1 = Path()
|
|
869 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
870 p2 = Path()
|
|
871 p2.setFromTuple( ( "1", "qry1", "121", "350", "sbj2", "101", "200", "0.0", "176", "91.2" ) )
|
|
872 lPaths = [ p1, p2 ]
|
|
873 try:
|
|
874 obs = PathUtils.getIdentityFromPathList( lPaths, True )
|
|
875 except:
|
|
876 pass
|
|
877
|
|
878
|
|
879 def test_getIdentityFromPathList_diffSubjects_noCheck( self ):
|
|
880 p1 = Path()
|
|
881 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
882 p2 = Path()
|
|
883 p2.setFromTuple( ( "1", "qry1", "121", "350", "sbj2", "101", "200", "0.0", "176", "91.2" ) )
|
|
884 lPaths = [ p1, p2 ]
|
|
885 exp = ( 90.0 * ( 100-1+1) + 91.2 * (350-121+1) ) / ( (100-1+1) + (350-121+1) ) # 90.836363636363643
|
|
886 obs = PathUtils.getIdentityFromPathList( lPaths, False )
|
|
887 self.assertEqual( exp, obs )
|
|
888
|
|
889
|
|
890 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_alreadyOrdered_diffIdentifier( self ):
|
|
891 p1 = Path()
|
|
892 p1.setFromTuple( ( "1", "qry1", "1", "10", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
893 p2 = Path()
|
|
894 p2.setFromTuple( ( "2", "qry1", "21", "30", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
895 lPaths = [ p1, p2 ]
|
|
896
|
|
897 expList = [ p1, p2 ]
|
|
898
|
|
899 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
900
|
|
901 self.assertEqual( expList, obsList )
|
|
902
|
|
903 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_unordered_diffIdentifier( self ):
|
|
904 p1 = Path()
|
|
905 p1.setFromTuple( ( "2", "qry1", "21", "30", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
906 p2 = Path()
|
|
907 p2.setFromTuple( ( "1", "qry1", "1", "10", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
908 lPaths = [ p1, p2 ]
|
|
909
|
|
910 expList = [ p2, p1 ]
|
|
911
|
|
912 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
913
|
|
914 self.assertEqual( expList, obsList )
|
|
915
|
|
916 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_unordered_sameIdentifier( self ):
|
|
917 p1 = Path()
|
|
918 p1.setFromTuple( ( "1", "qry1", "21", "30", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
919 p2 = Path()
|
|
920 p2.setFromTuple( ( "1", "qry1", "1", "10", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
921 lPaths = [ p1, p2 ]
|
|
922
|
|
923 expList = [ p2, p1 ]
|
|
924
|
|
925 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
926
|
|
927 self.assertEqual( expList, obsList )
|
|
928
|
|
929 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_unordered_overlapping( self ):
|
|
930 p1 = Path()
|
|
931 p1.setFromTuple( ( "1", "qry1", "6", "15", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
932 p2 = Path()
|
|
933 p2.setFromTuple( ( "2", "qry1", "1", "10", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
934 lPaths = [ p1, p2 ]
|
|
935
|
|
936 expList = [ p2, p1 ]
|
|
937
|
|
938 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
939
|
|
940 self.assertEqual( expList, obsList )
|
|
941
|
|
942 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_unordered_sameMin_threeSets( self ):
|
|
943 p1 = Path()
|
|
944 p1.setFromTuple( ( "1", "qry1", "1", "15", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
945 p2 = Path()
|
|
946 p2.setFromTuple( ( "2", "qry1", "1", "10", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
947 p3 = Path()
|
|
948 p3.setFromTuple( ( "2", "qry1", "1", "12", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
949 lPaths = [ p1, p2, p3 ]
|
|
950
|
|
951 expList = [ p2, p3, p1 ]
|
|
952
|
|
953 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
954
|
|
955 self.assertEqual( expList, obsList )
|
|
956
|
|
957 def test_getPathListSortedByIncreasingMinQueryThenMaxQuery_unordered_included( self ):
|
|
958 p1 = Path()
|
|
959 p1.setFromTuple( ( "1", "qry1", "2", "4", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
960 p2 = Path()
|
|
961 p2.setFromTuple( ( "2", "qry1", "1", "5", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
962 lPaths = [ p1, p2 ]
|
|
963
|
|
964 expList = [ p2, p1 ]
|
|
965
|
|
966 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQuery( lPaths )
|
|
967
|
|
968 self.assertEqual( expList, obsList )
|
|
969
|
|
970 def test_getPathListSortedByIncreasingMinQueryThenMaxQueryThenIdentifier_sameCoord_diffId( self ):
|
|
971 p1 = Path()
|
|
972 p1.setFromTuple( ( "1", "qry1", "1", "5", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
973 p2 = Path()
|
|
974 p2.setFromTuple( ( "2", "qry1", "1", "5", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
975 lPaths = [ p2, p1 ]
|
|
976
|
|
977 expList = [ p1, p2 ]
|
|
978
|
|
979 obsList = PathUtils.getPathListSortedByIncreasingMinQueryThenMaxQueryThenIdentifier( lPaths )
|
|
980
|
|
981 self.assertEqual( expList, obsList )
|
|
982
|
|
983 def test_getListOfDistinctIdentifiers( self ):
|
|
984 p1 = Path()
|
|
985 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
986 p2 = Path()
|
|
987 p2.setFromTuple( ( "2", "qry1", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
988 p3 = Path()
|
|
989 p3.setFromTuple( ( "2", "qry1", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
990 lPaths = [ p1, p2, p3 ]
|
|
991 lExp = [ 1, 2 ]
|
|
992 lObs = PathUtils.getListOfDistinctIdentifiers( lPaths )
|
|
993 lExp.sort()
|
|
994 lObs.sort()
|
|
995 self.assertEqual( lObs, lExp )
|
|
996
|
|
997 def test_getListOfDistinctQueryNames( self ):
|
|
998 p1 = Path()
|
|
999 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
1000 p2 = Path()
|
|
1001 p2.setFromTuple( ( "2", "qry2", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
1002 p3 = Path()
|
|
1003 p3.setFromTuple( ( "2", "qry2", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
1004 lPaths = [ p1, p2, p3 ]
|
|
1005 lExp = [ "qry1", "qry2" ]
|
|
1006 lObs = PathUtils.getListOfDistinctQueryNames( lPaths )
|
|
1007 lExp.sort()
|
|
1008 lObs.sort()
|
|
1009 self.assertEqual( lObs, lExp )
|
|
1010
|
|
1011 def test_getListOfDistinctSubjectNames( self ):
|
|
1012 p1 = Path()
|
|
1013 p1.setFromTuple( ( "1", "qry1", "1", "100", "sbj1", "1", "100", "0.0", "239", "90.0" ) )
|
|
1014 p2 = Path()
|
|
1015 p2.setFromTuple( ( "2", "qry2", "121", "350", "sbj1", "101", "200", "0.0", "176", "91.2" ) )
|
|
1016 p3 = Path()
|
|
1017 p3.setFromTuple( ( "2", "qry2", "121", "350", "sbj2", "101", "200", "0.0", "176", "91.2" ) )
|
|
1018 lPaths = [ p1, p2, p3 ]
|
|
1019 lExp = [ "sbj1", "sbj2" ]
|
|
1020 lObs = PathUtils.getListOfDistinctSubjectNames( lPaths )
|
|
1021 lExp.sort()
|
|
1022 lObs.sort()
|
|
1023 self.assertEqual( lObs, lExp )
|
|
1024
|
|
1025 def test_getListOfJoinCoordinatesOnQuery_returnCoord( self ):
|
|
1026 p1a = Path()
|
|
1027 p1a.setFromTuple( ( "1", "qry1", "1", "500", "sbj1", "1", "500", "0.0", "532", "95.0" ) )
|
|
1028 p1b = Path()
|
|
1029 p1b.setFromTuple( ( "1", "qry1", "701", "900", "sbj1", "501", "700", "0.0", "232", "95.3" ) )
|
|
1030 lExp = [ [ 501, 700 ] ]
|
|
1031 lPaths = [ p1a, p1b ]
|
|
1032 lObs = PathUtils.getListOfJoinCoordinatesOnQuery( lPaths )
|
|
1033 lExp.sort()
|
|
1034 lObs.sort()
|
|
1035 self.assertEqual( lObs, lExp )
|
|
1036
|
|
1037 def test_getListOfJoinCoordinatesOnQuery_overlap( self ):
|
|
1038 p1a = Path()
|
|
1039 p1a.setFromTuple( ( "1", "qry1", "1", "500", "sbj1", "1", "500", "0.0", "532", "95.0" ) )
|
|
1040 p1b = Path()
|
|
1041 p1b.setFromTuple( ( "1", "qry1", "491", "900", "sbj1", "501", "770", "0.0", "232", "95.3" ) )
|
|
1042 lExp = []
|
|
1043 lPaths = [ p1a, p1b ]
|
|
1044 minLength = 100
|
|
1045 lObs = PathUtils.getListOfJoinCoordinatesOnQuery( lPaths, minLength )
|
|
1046 lExp.sort()
|
|
1047 lObs.sort()
|
|
1048 self.assertEqual( lObs, lExp )
|
|
1049
|
|
1050 def test_getListOfJoinCoordinates_tooShort( self ):
|
|
1051 p1a = Path()
|
|
1052 p1a.setFromTuple( ( "1", "qry1", "1", "500", "sbj1", "1", "500", "0.0", "532", "95.0" ) )
|
|
1053 p1b = Path()
|
|
1054 p1b.setFromTuple( ( "1", "qry1", "551", "900", "sbj1", "501", "750", "0.0", "232", "95.3" ) )
|
|
1055 lExp = []
|
|
1056 lPaths = [ p1a, p1b ]
|
|
1057 minLength = 100
|
|
1058 lObs = PathUtils.getListOfJoinCoordinatesOnQuery( lPaths, minLength )
|
|
1059 lExp.sort()
|
|
1060 lObs.sort()
|
|
1061 self.assertEqual( lObs, lExp )
|
|
1062
|
|
1063 def test_getLengthOnQueryFromPathList( self ):
|
|
1064 p1 = Path()
|
|
1065 p1.setFromTuple( ( "1", "qry1", "1", "70", "sbj1", "1", "70", "0.0", "132", "95.0" ) )
|
|
1066 p2 = Path()
|
|
1067 p2.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1068 lPaths = [ p1, p2 ]
|
|
1069 exp = 90
|
|
1070 obs = PathUtils.getLengthOnQueryFromPathList( lPaths )
|
|
1071 self.assertEqual( obs, exp )
|
|
1072
|
|
1073 def test_convertPathFileIntoAlignFile( self ):
|
|
1074 pathFile = "dummyPathFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1075 pathFileHandler = open( pathFile, "w" )
|
|
1076 pathFileHandler.write( "3\tchr2\t250\t151\tseq5\t1\t100\t1e-31\t147\t98.3\n" )
|
|
1077 pathFileHandler.close()
|
|
1078
|
|
1079 expFile = "dummyExpFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1080 expFileHandler = open( expFile, "w" )
|
|
1081 expFileHandler.write( "chr2\t151\t250\tseq5\t100\t1\t1e-31\t147\t98.300000\n" )
|
|
1082 expFileHandler.close()
|
|
1083
|
|
1084 obsFile = "dummyObsFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1085
|
|
1086 PathUtils.convertPathFileIntoAlignFile( pathFile, obsFile )
|
|
1087
|
|
1088 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1089
|
|
1090 for f in [ pathFile, expFile, obsFile ]:
|
|
1091 if os.path.exists( f ):
|
|
1092 os.remove ( f )
|
|
1093
|
|
1094 def test_convertPathFileIntoMapFileWithQueryCoordsOnly( self ):
|
|
1095 pathFile = "dummyPathFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1096 pathFileHandler = open( pathFile, "w" )
|
|
1097 pathFileHandler.write( "3\tchr2\t250\t151\tseq5\t1\t100\t1e-31\t147\t98.3\n" )
|
|
1098 pathFileHandler.write( "4\tchr2\t191\t230\tseq8\t237\t387\t1e-11\t187\t95.3\n" )
|
|
1099 pathFileHandler.write( "3\tchr2\t500\t301\tseq5\t101\t300\t1e-81\t247\t96.2\n" )
|
|
1100 pathFileHandler.close()
|
|
1101
|
|
1102 expFile = "dummyExpFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1103 expFileHandler = open( expFile, "w" )
|
|
1104 expFileHandler.write( "seq5\tchr2\t250\t151\n" )
|
|
1105 expFileHandler.write( "seq8\tchr2\t191\t230\n" )
|
|
1106 expFileHandler.write( "seq5\tchr2\t500\t301\n" )
|
|
1107 expFileHandler.close()
|
|
1108
|
|
1109 obsFile = "dummyObsFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1110
|
|
1111 PathUtils.convertPathFileIntoMapFileWithQueryCoordsOnly( pathFile, obsFile )
|
|
1112
|
|
1113 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1114
|
|
1115 for f in [ pathFile, expFile, obsFile ]:
|
|
1116 if os.path.exists( f ):
|
|
1117 os.remove( f )
|
|
1118
|
|
1119
|
|
1120 def test_mergeMatchesOnQueries( self ):
|
|
1121 pathFile = "dummyPathFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1122 pathFileHandler = open( pathFile, "w" )
|
|
1123 pathFileHandler.write( "3\tchr2\t250\t151\tseq5\t1\t100\t1e-31\t147\t98.3\n" )
|
|
1124 pathFileHandler.write( "4\tchr2\t230\t191\tseq8\t237\t387\t1e-11\t187\t95.3\n" )
|
|
1125 pathFileHandler.write( "3\tchr2\t500\t301\tseq5\t101\t300\t1e-81\t247\t96.2\n" )
|
|
1126 pathFileHandler.close()
|
|
1127
|
|
1128 expFile = "dummyExpFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1129 expFileHandler = open( expFile, "w" )
|
|
1130 expFileHandler.write( "0\tchr2\t151\t250\tseq5\t0\t0\t0.0\t0\t0\n" )
|
|
1131 expFileHandler.write( "0\tchr2\t301\t500\tseq5\t0\t0\t0.0\t0\t0\n" )
|
|
1132 expFileHandler.close()
|
|
1133
|
|
1134 obsFile = "dummyObsFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1135
|
|
1136 PathUtils.mergeMatchesOnQueries( pathFile, obsFile )
|
|
1137
|
|
1138 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1139
|
|
1140 for f in [ pathFile, expFile, obsFile ]:
|
|
1141 if os.path.exists( f ):
|
|
1142 os.remove( f )
|
|
1143
|
|
1144
|
|
1145 def test_filterPathListOnChainLength( self ):
|
|
1146 p1a = Path()
|
|
1147 p1a.setFromTuple( ( "1", "qry1", "1", "12", "sbj1", "1", "12", "0.0", "132", "95.0" ) )
|
|
1148 p1b = Path()
|
|
1149 p1b.setFromTuple( ( "1", "qry1", "15", "30", "sbj1", "13", "28", "0.0", "132", "95.0" ) )
|
|
1150 p2 = Path()
|
|
1151 p2.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1152 p3 = Path()
|
|
1153 p3.setFromTuple( ( "3", "qry2", "1", "12", "sbj3", "15", "1", "0.0", "132", "95.0" ) )
|
|
1154 lPaths = [ p1a, p1b, p2, p3 ]
|
|
1155 lExp = [ p1a, p1b, p2 ]
|
|
1156 lObs = PathUtils.filterPathListOnChainLength( lPaths, 20 )
|
|
1157 self.assertEqual( lExp, lObs )
|
|
1158
|
|
1159 def test_getPathListFromFile(self):
|
|
1160 file = "dummyFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1161 fileHandler = open( file, "w" )
|
|
1162 fileHandler.write( "1\tchr2\t151\t250\tseq5\t0\t0\t0.0\t0\t0\n" )
|
|
1163 fileHandler.write( "2\tchr2\t301\t500\tseq5\t0\t0\t0.0\t0\t0\n" )
|
|
1164 fileHandler.close()
|
|
1165 p1 = Path()
|
|
1166 p1.setFromTuple( ( "1", "chr2", "151", "250", "seq5", "0", "0", "0.0", "0", "0" ) )
|
|
1167 p2 = Path()
|
|
1168 p2.setFromTuple( ( "2", "chr2", "301", "500", "seq5", "0", "0", "0.0", "0", "0" ) )
|
|
1169 expLPath = [ p1, p2 ]
|
|
1170 obsLPath = PathUtils.getPathListFromFile(file)
|
|
1171 expLPathSorted = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength(expLPath)
|
|
1172 obsLPathSorted = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength(obsLPath)
|
|
1173 os.remove(file)
|
|
1174 self.assertEqual( expLPathSorted, obsLPathSorted )
|
|
1175
|
|
1176 def test_getPathListFromFile_empty_file(self):
|
|
1177 file = "dummyFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1178 fileHandler = open( file, "w" )
|
|
1179 fileHandler.close()
|
|
1180 expLPath = []
|
|
1181 obsLPath = PathUtils.getPathListFromFile(file)
|
|
1182 expLPathSorted = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength(expLPath)
|
|
1183 obsLPathSorted = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength(obsLPath)
|
|
1184 os.remove(file)
|
|
1185 self.assertEqual( expLPathSorted, obsLPathSorted )
|
|
1186
|
|
1187 def test_convertPathFileIntoAlignFileViaPathrange_sortedInput( self ):
|
|
1188 p1a = Path()
|
|
1189 p1a.setFromTuple( ( "1", "qry1", "1", "12", "sbj1", "1", "12", "0.0", "132", "95.0" ) )
|
|
1190 p1b = Path()
|
|
1191 p1b.setFromTuple( ( "1", "qry1", "16", "30", "sbj1", "13", "28", "1e-270", "150", "97.0" ) )
|
|
1192 p2 = Path()
|
|
1193 p2.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1194 inFile = "dummyInFile"
|
|
1195 inF = open( inFile, "w" )
|
|
1196 for iPath in [ p1a, p1b, p2 ]:
|
|
1197 iPath.write( inF )
|
|
1198 inF.close()
|
|
1199
|
|
1200 expFile = "dummyExpFile"
|
|
1201 expF = open( expFile, "w" )
|
|
1202 a1 = Align()
|
|
1203 a1.setFromTuple( ( "qry1", "1", "30", "sbj1", "1", "28", "0.0", "282", str((95*12+97*15)/float(12+15)) ) )
|
|
1204 a2 = Align()
|
|
1205 a2.setFromTuple( ( "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1206 for iAlign in [ a1, a2 ]:
|
|
1207 iAlign.write( expF )
|
|
1208 expF.close()
|
|
1209
|
|
1210 obsFile = "dummyObsFile"
|
|
1211
|
|
1212 PathUtils.convertPathFileIntoAlignFileViaPathrange( inFile, obsFile, 0 )
|
|
1213
|
|
1214 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1215
|
|
1216 for f in [ inFile, expFile, obsFile ]:
|
|
1217 os.remove( f )
|
|
1218
|
|
1219
|
|
1220 def test_convertPathFileIntoAlignFileViaPathrange_unsortedInput( self ):
|
|
1221 p1a = Path()
|
|
1222 p1a.setFromTuple( ( "1", "qry1", "1", "12", "sbj1", "1", "12", "0.0", "132", "95.0" ) )
|
|
1223 p1b = Path()
|
|
1224 p1b.setFromTuple( ( "1", "qry1", "16", "30", "sbj1", "13", "28", "0.0", "150", "97.0" ) )
|
|
1225 p2 = Path()
|
|
1226 p2.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1227 inFile = "dummyInFile"
|
|
1228 inF = open( inFile, "w" )
|
|
1229 for iPath in [ p1b, p2, p1a ]:
|
|
1230 iPath.write( inF )
|
|
1231 inF.close()
|
|
1232
|
|
1233 expFile = "dummyExpFile"
|
|
1234 expF = open( expFile, "w" )
|
|
1235 a1 = Align()
|
|
1236 a1.setFromTuple( ( "qry1", "1", "30", "sbj1", "1", "28", "0.0", "282", str((95*12+97*15)/float(12+15)) ) )
|
|
1237 a2 = Align()
|
|
1238 a2.setFromTuple( ( "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1239 for iAlign in [ a1, a2 ]:
|
|
1240 iAlign.write( expF )
|
|
1241 expF.close()
|
|
1242
|
|
1243 obsFile = "dummyObsFile"
|
|
1244
|
|
1245 PathUtils.convertPathFileIntoAlignFileViaPathrange( inFile, obsFile, 0 )
|
|
1246
|
|
1247 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1248
|
|
1249 for f in [ inFile, expFile, obsFile ]:
|
|
1250 os.remove( f )
|
|
1251
|
|
1252
|
|
1253 def test_convertPathFileIntoAlignFileViaPathrange_sortedInput_subjectReverseStrand( self ):
|
|
1254 p1a = Path()
|
|
1255 p1a.setFromTuple( ( "1", "qry1", "1", "12", "sbj1", "12", "1", "0.0", "132", "95.0" ) )
|
|
1256 p1b = Path()
|
|
1257 p1b.setFromTuple( ( "1", "qry1", "16", "30", "sbj1", "28", "13", "0.0", "150", "97.0" ) )
|
|
1258 p2 = Path()
|
|
1259 p2.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1260 inFile = "dummyInFile"
|
|
1261 inF = open( inFile, "w" )
|
|
1262 for iPath in [ p1a, p1b, p2 ]:
|
|
1263 iPath.write( inF )
|
|
1264 inF.close()
|
|
1265
|
|
1266 expFile = "dummyExpFile"
|
|
1267 expF = open( expFile, "w" )
|
|
1268 a1 = Align()
|
|
1269 a1.setFromTuple( ( "qry1", "1", "30", "sbj1", "28", "1", "0.0", "282", str((95*12+97*15)/float(12+15)) ) )
|
|
1270 a2 = Align()
|
|
1271 a2.setFromTuple( ( "qry1", "51", "90", "sbj2", "40", "1", "0.0", "132", "95.0" ) )
|
|
1272 for iAlign in [ a1, a2 ]:
|
|
1273 iAlign.write( expF )
|
|
1274 expF.close()
|
|
1275
|
|
1276 obsFile = "dummyObsFile"
|
|
1277
|
|
1278 PathUtils.convertPathFileIntoAlignFileViaPathrange( inFile, obsFile, 0 )
|
|
1279
|
|
1280 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1281
|
|
1282 for f in [ inFile, expFile, obsFile ]:
|
|
1283 os.remove( f )
|
|
1284
|
|
1285
|
|
1286 def test_splitPathListByQueryName_empty_list( self ):
|
|
1287 lPath = []
|
|
1288
|
|
1289 obsLPath = PathUtils.splitPathListByQueryName( lPath )
|
|
1290
|
|
1291 expLPath = []
|
|
1292
|
|
1293 self.assertEquals( expLPath, obsLPath )
|
|
1294
|
|
1295
|
|
1296 def test_splitPathListByQueryName( self ):
|
|
1297 iPath1 = Path()
|
|
1298 iPath1.setFromString("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1299 iPath2 = Path()
|
|
1300 iPath2.setFromString("2\tchr2\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1301 iPath3 = Path()
|
|
1302 iPath3.setFromString("3\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1303 lPath = [ iPath1, iPath2, iPath3 ]
|
|
1304
|
|
1305 obsLPath = PathUtils.splitPathListByQueryName( lPath )
|
|
1306
|
|
1307 expLPath = [ [ iPath1, iPath3 ],
|
|
1308 [ iPath2 ] ]
|
|
1309
|
|
1310 self.assertEquals( expLPath, obsLPath )
|
|
1311
|
|
1312
|
|
1313 def test_splitPathListByQueryName_last_align_alone( self ):
|
|
1314 iPath1 = Path()
|
|
1315 iPath1.setFromString("1\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1316 iPath2 = Path()
|
|
1317 iPath2.setFromString("2\tchr2\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1318 iPath3 = Path()
|
|
1319 iPath3.setFromString("3\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1320 iPath4 = Path()
|
|
1321 iPath4.setFromString("4\tchr3\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1322 iPath5 = Path()
|
|
1323 iPath5.setFromString("5\tchr2\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1324 iPath6 = Path()
|
|
1325 iPath6.setFromString("6\tchr1\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1326 iPath7 = Path()
|
|
1327 iPath7.setFromString("7\tchr1\t100\t110\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1328 iPath8 = Path()
|
|
1329 iPath8.setFromString("8\tchr2\t200\t220\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1330 iPath9 = Path()
|
|
1331 iPath9.setFromString("9\tchr4\t300\t330\tTE2\t150\t200\t1e-20\t30\t90.2\n")
|
|
1332 lPath = [ iPath1, iPath2, iPath3, iPath4, iPath5, iPath6, iPath7, iPath8, iPath9 ]
|
|
1333
|
|
1334 obsLPath = PathUtils.splitPathListByQueryName( lPath )
|
|
1335
|
|
1336 expLPath = [ [ iPath1, iPath3, iPath6, iPath7 ],
|
|
1337 [ iPath2, iPath5, iPath8 ],
|
|
1338 [ iPath4 ],
|
|
1339 [ iPath9 ] ]
|
|
1340
|
|
1341 self.assertEquals( expLPath, obsLPath )
|
|
1342
|
|
1343
|
|
1344 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_alreadyOrdered_diffIdentifier( self ):
|
|
1345 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1346 iPath2 = Path( 2, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 )
|
|
1347 lPaths = [ iPath1, iPath2 ]
|
|
1348
|
|
1349 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ),
|
|
1350 Path( 2, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 ) ]
|
|
1351
|
|
1352 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1353
|
|
1354 self.assertEquals( lExp, lObs )
|
|
1355
|
|
1356
|
|
1357 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_unordered_diffIdentifier( self ):
|
|
1358 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1359 iPath2 = Path( 2, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 )
|
|
1360 lPaths = [ iPath2, iPath1 ]
|
|
1361
|
|
1362 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ),
|
|
1363 Path( 2, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 ) ]
|
|
1364
|
|
1365 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1366
|
|
1367 self.assertEquals( lExp, lObs )
|
|
1368
|
|
1369
|
|
1370 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_unordered_sameIdentifier( self ):
|
|
1371 iPath1a = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1372 iPath1b = Path( 1, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 )
|
|
1373 lPaths = [ iPath1b, iPath1a ]
|
|
1374
|
|
1375 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ),
|
|
1376 Path( 1, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 ) ]
|
|
1377
|
|
1378 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1379
|
|
1380 self.assertEquals( lExp, lObs )
|
|
1381
|
|
1382
|
|
1383 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_unordered_overlapping( self ):
|
|
1384 iPath1 = Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 )
|
|
1385 iPath2 = Path( 2, Range("qry1",5,10), Range("sbj1",5,10), 0.0, 10, 98.7 )
|
|
1386 lPaths = [ iPath2, iPath1 ]
|
|
1387
|
|
1388 lExp = [ Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 ),
|
|
1389 Path( 2, Range("qry1",5,10), Range("sbj1",5,10), 0.0, 10, 98.7 ) ]
|
|
1390
|
|
1391 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1392
|
|
1393 self.assertEquals( lExp, lObs )
|
|
1394
|
|
1395
|
|
1396 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_threePaths_2sameMin( self ):
|
|
1397 iPath1 = Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 )
|
|
1398 iPath2 = Path( 2, Range("qry1",5,12), Range("sbj1",5,12), 0.0, 10, 98.7 )
|
|
1399 iPath3 = Path( 3, Range("qry1",5,10), Range("sbj1",5,10), 0.0, 10, 98.7 )
|
|
1400 lPaths = [ iPath3, iPath2, iPath1 ]
|
|
1401
|
|
1402 lExp = [ Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 ),
|
|
1403 Path( 2, Range("qry1",5,12), Range("sbj1",5,12), 0.0, 10, 98.7 ),
|
|
1404 Path( 3, Range("qry1",5,10), Range("sbj1",5,10), 0.0, 10, 98.7 ) ]
|
|
1405
|
|
1406 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1407
|
|
1408 self.assertEquals( lExp, lObs )
|
|
1409
|
|
1410
|
|
1411 def test_getPathListSortedByIncreasingQueryMinThenInvQueryLength_unordered_included( self ):
|
|
1412 iPath1 = Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 )
|
|
1413 iPath2 = Path( 2, Range("qry1",2,5), Range("sbj1",2,5), 0.0, 10, 98.7 )
|
|
1414 lPaths = [ iPath2, iPath1 ]
|
|
1415
|
|
1416 lExp = [ Path( 1, Range("qry1",1,6), Range("sbj1",1,6), 0.0, 10, 98.7 ),
|
|
1417 Path( 2, Range("qry1",2,5), Range("sbj1",2,5), 0.0, 10, 98.7 ) ]
|
|
1418
|
|
1419 lObs = PathUtils.getPathListSortedByIncreasingQueryMinThenInvQueryLength( lPaths )
|
|
1420
|
|
1421 self.assertEquals( lExp, lObs )
|
|
1422
|
|
1423
|
|
1424 def test_mergePathsInList_emptyList( self ):
|
|
1425 lPaths = []
|
|
1426 lExp = []
|
|
1427 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1428 self.assertEquals( lExp, lObs )
|
|
1429
|
|
1430
|
|
1431 def test_mergePathsInList_onePath( self ):
|
|
1432 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1433 lPaths = [ iPath1 ]
|
|
1434 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ) ]
|
|
1435 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1436 self.assertEquals( lExp, lObs )
|
|
1437
|
|
1438
|
|
1439 def test_mergePathsInList_noOverlap( self ):
|
|
1440 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1441 iPath2 = Path( 1, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 )
|
|
1442 lPaths = [ iPath1, iPath2 ]
|
|
1443
|
|
1444 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ),
|
|
1445 Path( 1, Range("qry1",21,30), Range("sbj1",11,20), 0.0, 10, 98.7 ) ]
|
|
1446
|
|
1447 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1448
|
|
1449 self.assertEquals( lExp, lObs )
|
|
1450
|
|
1451
|
|
1452 def test_mergePathsInList_withOverlap( self ):
|
|
1453 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1454 iPath2 = Path( 1, Range("qry1",6,15), Range("sbj1",6,15), 0.0, 10, 98.7 )
|
|
1455 lPaths = [ iPath2, iPath1 ]
|
|
1456
|
|
1457 lExp = [ Path( 1, Range("qry1",1,15), Range("sbj1",1,15), 0.0, 10, 98.7 ) ]
|
|
1458
|
|
1459 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1460
|
|
1461 self.assertEquals( lExp, lObs )
|
|
1462
|
|
1463
|
|
1464 def test_mergePathsInList_withOverlap_reverseOnly( self ):
|
|
1465 iPath1 = Path( 1, Range("qry1",10,1), Range("sbj1",10,1), 0.0, 10, 98.7 )
|
|
1466 iPath2 = Path( 1, Range("qry1",15,6), Range("sbj1",15,6), 0.0, 10, 98.7 )
|
|
1467 lPaths = [ iPath2, iPath1 ]
|
|
1468
|
|
1469 lExp = [ Path( 1, Range("qry1",15,1), Range("sbj1",15,1), 0.0, 10, 98.7 ) ]
|
|
1470
|
|
1471 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1472
|
|
1473 self.assertEquals( lExp, lObs )
|
|
1474
|
|
1475
|
|
1476 def test_mergePathsInList_withOverlap_directAndReverse( self ):
|
|
1477 iPath1 = Path( 1, Range("qry1",10,1), Range("sbj1",10,1), 0.0, 10, 98.7 )
|
|
1478 iPath2 = Path( 1, Range("qry1",15,6), Range("sbj1",15,6), 0.0, 10, 98.7 )
|
|
1479 iPath3 = Path( 1, Range("qry1",2,5), Range("sbj1",2,5), 0.0, 10, 98.7 )
|
|
1480 lPaths = [ iPath3, iPath2, iPath1 ]
|
|
1481
|
|
1482 lExp = [ Path( 1, Range("qry1",15,1), Range("sbj1",15,1), 0.0, 10, 98.7 ) ]
|
|
1483
|
|
1484 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1485
|
|
1486 self.assertEquals( lExp, lObs )
|
|
1487
|
|
1488
|
|
1489 def test_mergePathsInList_diffQueries_withOverlap( self ):
|
|
1490 iPath1 = Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 )
|
|
1491 iPath2 = Path( 2, Range("qry2",6,15), Range("sbj1",6,15), 0.0, 10, 98.7 )
|
|
1492 lPaths = [ iPath2, iPath1 ]
|
|
1493
|
|
1494 lExp = [ Path( 1, Range("qry1",1,10), Range("sbj1",1,10), 0.0, 10, 98.7 ),
|
|
1495 Path( 2, Range("qry2",6,15), Range("sbj1",6,15), 0.0, 10, 98.7 ) ]
|
|
1496
|
|
1497 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1498
|
|
1499 self.assertEquals( lExp, lObs )
|
|
1500
|
|
1501
|
|
1502 def test_mergePathsInList_nonOverlappingSubjects( self ):
|
|
1503 iPath1 = Path( 1, Range("qry1",398,491), Range("sbj1",10,112), 0.0, 10, 98.7 )
|
|
1504 iPath2 = Path( 1, Range("qry1",451,492), Range("sbj1",124,169), 0.0, 10, 98.7 )
|
|
1505 iPath3 = Path( 1, Range("qry1",493,531), Range("sbj1",249,294), 0.0, 10, 98.7 )
|
|
1506 lPaths = [ iPath3, iPath2, iPath1 ]
|
|
1507
|
|
1508 lExp = [ Path( 1, Range("qry1",398,491), Range("sbj1",10,112), 0.0, 10, 98.7 ),
|
|
1509 Path( 1, Range("qry1",451,492), Range("sbj1",124,169), 0.0, 10, 98.7 ),
|
|
1510 Path( 1, Range("qry1",493,531), Range("sbj1",249,294), 0.0, 10, 98.7 ) ]
|
|
1511
|
|
1512 lObs = PathUtils.mergePathsInList( lPaths )
|
|
1513
|
|
1514 self.assertEquals( lExp, lObs )
|
|
1515
|
|
1516
|
|
1517 def test_mergePathsInListUsingQueryCoordsOnly( self ):
|
|
1518 iPath1 = Path( 1, Range("qry1",398,491), Range("sbj1",10,112), 0.0, 10, 98.7 )
|
|
1519 iPath2 = Path( 1, Range("qry1",451,492), Range("sbj1",124,169), 0.0, 10, 98.7 )
|
|
1520 iPath3 = Path( 1, Range("qry1",493,531), Range("sbj1",249,294), 0.0, 10, 98.7 )
|
|
1521 lPaths = [ iPath3, iPath2, iPath1 ]
|
|
1522
|
|
1523 lExp = [ Path( 1, Range("qry1",398,492), Range("sbj1",10,169), 0.0, 10, 98.7 ),
|
|
1524 Path( 1, Range("qry1",493,531), Range("sbj1",249,294), 0.0, 10, 98.7 ) ]
|
|
1525
|
|
1526 lObs = PathUtils.mergePathsInListUsingQueryCoordsOnly( lPaths )
|
|
1527
|
|
1528 self.assertEquals( lExp, lObs )
|
|
1529
|
|
1530
|
|
1531 def test_convertPathFileIntoGffFile( self ):
|
|
1532 p1 = Path()
|
|
1533 p1.setFromTuple( ( "1", "qry1", "12", "1", "sbj1", "1", "12", "0.0", "132", "95.0" ) )
|
|
1534 p2a = Path()
|
|
1535 p2a.setFromTuple( ( "2", "qry1", "16", "30", "sbj2", "1", "15", "1e-270", "150", "97.0" ) )
|
|
1536 p2b = Path()
|
|
1537 p2b.setFromTuple( ( "2", "qry1", "51", "90", "sbj2", "21", "60", "0.0", "132", "95.9" ) )
|
|
1538 inFile = "dummyInFile"
|
|
1539 PathUtils.writeListInFile( [ p1, p2a, p2b ], inFile, "w" )
|
|
1540
|
|
1541 expFile = "dummyExpFile"
|
|
1542 expF = open( expFile, "w" )
|
|
1543 expF.write( "qry1\tREPET\tmatch\t1\t12\t0\t-\t.\tID=1;Target=sbj1 1 12\n" )
|
|
1544 expF.write( "qry1\tREPET\tmatch\t16\t90\t0\t+\t.\tID=ms2;Target=sbj2 1 60\n" )
|
|
1545 expF.write( "qry1\tREPET\tmatch_part\t16\t30\t1e-270\t+\t.\tID=mp2-1;Parent=ms2;Target=sbj2 1 15\n" )
|
|
1546 expF.write( "qry1\tREPET\tmatch_part\t51\t90\t0\t+\t.\tID=mp2-2;Parent=ms2;Target=sbj2 21 60\n" )
|
|
1547 expF.close()
|
|
1548
|
|
1549 obsFile = "dummyObsFile"
|
|
1550
|
|
1551 PathUtils.convertPathFileIntoGffFile( inFile, obsFile )
|
|
1552
|
|
1553 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1554
|
|
1555 for f in [ inFile, expFile, obsFile ]:
|
|
1556 os.remove( f )
|
|
1557
|
|
1558
|
|
1559 def test_convertPathFileIntoSetFile( self ):
|
|
1560 pathFile = "dummyPathFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1561 pathFileHandler = open( pathFile, "w" )
|
|
1562 pathFileHandler.write( "3\tchr2\t250\t151\tseq5\t1\t100\t1e-31\t147\t98.3\n" )
|
|
1563 pathFileHandler.close()
|
|
1564
|
|
1565 expFile = "dummyExpFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1566 expFileHandler = open( expFile, "w" )
|
|
1567 expFileHandler.write( "3\tseq5\tchr2\t250\t151\n" )
|
|
1568 expFileHandler.close()
|
|
1569
|
|
1570 obsFile = "dummyObsFile_%s_%s" % ( time.strftime("%Y%m%d%H%M%S"), os.getpid() )
|
|
1571
|
|
1572 PathUtils.convertPathFileIntoSetFile( pathFile, obsFile )
|
|
1573
|
|
1574 self.assertTrue( FileUtils.are2FilesIdentical( expFile, obsFile ) )
|
|
1575
|
|
1576 for f in [ pathFile, expFile, obsFile ]:
|
|
1577 if os.path.exists( f ):
|
|
1578 os.remove ( f )
|
|
1579
|
|
1580
|
|
1581 def test_removeInPathFileDuplicatedPathOnQueryNameQueryCoordAndSubjectName(self):
|
|
1582 pathFile = "dummyPathFile"
|
|
1583 f = open(pathFile, "w")
|
|
1584 f.write("1\tG4\t1\t3856\tAtha5Chr4_Pals_Piler_3590_69_MAP_3\t1\t3856\t0\t7642\t99.9741\n")
|
|
1585 f.write("1\tG4\t1\t3856\tAtha5Chr4_Pals_Piler_3590_69_MAP_3\t100\t3956\t0\t7642\t99.9741\n")
|
|
1586 f.write("2\trooA\t1\t386\tAtha5Chr4_Pals_Piler_3589_69_MAP_3\t1\t386\t6.3e-220\t758\t99.4819\n")
|
|
1587 f.write("3\trooA\t7236\t7621\tAtha5Chr4_Pals_Piler_3536_69_MAP_3\t1\t386\t6.3e-220\t758\t99.4819\n")
|
|
1588 f.write("4\trooA\t387\t7235\tAtha5Chr4_Pals_Piler_3596_69_MAP_3\t1\t6849\t0\t13580\t99.9854\n")
|
|
1589 f.write("5\taurora-element\t4046\t4257\tAtha5Chr4_Pals_Piler_3540_69_MAP_3\t1\t204\t6.1e-80\t300\t96.5686\n")
|
|
1590 f.write("6\taurora-element\t274\t381\tAtha5Chr4_Pals_Piler_3595_23_MAP_3\t177\t284\t0\t191\t97.2222\n")
|
|
1591 f.write("6\taurora-element\t116\t287\tAtha5Chr4_Pals_Piler_3595_30_MAP_3\t3\t170\t0\t290\t98.8095\n")
|
|
1592 f.write("7\taurora-element\t393\t902\tAtha5Chr4_Pals_Piler_3595_31_MAP_3\t1467\t1945\t0\t873\t97.2441\n")
|
|
1593 f.write("7\taurora-element\t393\t902\tAtha5Chr4_Pals_Piler_3595_31_MAP_3\t276\t100784\t0\t869\t98.1211\n")
|
|
1594 f.write("7\taurora-element\t1387\t2271\tAtha5Chr4_Pals_Piler_3595_31_MAP_3\t276\t10780\t0\t1576\t97.6244\n")
|
|
1595 f.write("8\taurora-element\t2486\t2828\tAtha5Chr4_Pals_Piler_3595_50_MAP_3\t4301\t4641\t0\t585\t97.3607\n")
|
|
1596 f.write("9\taurora-element\t2265\t2483\tAtha5Chr4_Pals_Piler_3595_62_MAP_3\t3999\t4218\t0\t361\t96.347\n")
|
|
1597 f.write("10\taurora-element\t2834\t4045\tAtha5Chr4_Pals_Piler_3595_69_MAP_3\t4800\t6011\t0\t2074\t97.0248\n")
|
|
1598 f.write("11\taurora-element\t2\t113\tAtha5Chr4_Pals_Piler_3598_69_MAP_3\t205\t317\t8.5e-37\t157\t93.75\n")
|
|
1599 f.write("11\taurora-element\t2\t113\tAtha5Chr4_Pals_Piler_3598_69_MAP_3\t305\t417\t8.5e-37\t157\t93.75\n")
|
|
1600 f.write("11\taurora-element\t2\t113\tAtha5Chr4_Pals_Piler_3598_69_MAP_3\t305\t417\t8.5e-37\t157\t93.75\n")
|
|
1601 f.close()
|
|
1602
|
|
1603 obsPathFile = "obsDummyPathFile"
|
|
1604 PathUtils.removeInPathFileDuplicatedPathOnQueryNameQueryCoordAndSubjectName(pathFile, obsPathFile)
|
|
1605
|
|
1606 expPathFile = "expDummyPathFile"
|
|
1607 f = open(expPathFile, "w")
|
|
1608 f.write("1\tG4\t1\t3856\tAtha5Chr4_Pals_Piler_3590_69_MAP_3\t1\t3856\t0\t7642\t99.974100\n")
|
|
1609 f.write("2\trooA\t1\t386\tAtha5Chr4_Pals_Piler_3589_69_MAP_3\t1\t386\t6.3e-220\t758\t99.481900\n")
|
|
1610 f.write("3\trooA\t7236\t7621\tAtha5Chr4_Pals_Piler_3536_69_MAP_3\t1\t386\t6.3e-220\t758\t99.481900\n")
|
|
1611 f.write("4\trooA\t387\t7235\tAtha5Chr4_Pals_Piler_3596_69_MAP_3\t1\t6849\t0\t13580\t99.985400\n")
|
|
1612 f.write("5\taurora-element\t4046\t4257\tAtha5Chr4_Pals_Piler_3540_69_MAP_3\t1\t204\t6.1e-80\t300\t96.568600\n")
|
|
1613 f.write("6\taurora-element\t274\t381\tAtha5Chr4_Pals_Piler_3595_23_MAP_3\t177\t284\t0\t191\t97.222200\n")
|
|
1614 f.write("6\taurora-element\t116\t287\tAtha5Chr4_Pals_Piler_3595_30_MAP_3\t3\t170\t0\t290\t98.809500\n")
|
|
1615 f.write("7\taurora-element\t393\t902\tAtha5Chr4_Pals_Piler_3595_31_MAP_3\t1467\t1945\t0\t873\t97.244100\n")
|
|
1616 f.write("7\taurora-element\t1387\t2271\tAtha5Chr4_Pals_Piler_3595_31_MAP_3\t276\t10780\t0\t1576\t97.624400\n")
|
|
1617 f.write("8\taurora-element\t2486\t2828\tAtha5Chr4_Pals_Piler_3595_50_MAP_3\t4301\t4641\t0\t585\t97.360700\n")
|
|
1618 f.write("9\taurora-element\t2265\t2483\tAtha5Chr4_Pals_Piler_3595_62_MAP_3\t3999\t4218\t0\t361\t96.347000\n")
|
|
1619 f.write("10\taurora-element\t2834\t4045\tAtha5Chr4_Pals_Piler_3595_69_MAP_3\t4800\t6011\t0\t2074\t97.024800\n")
|
|
1620 f.write("11\taurora-element\t2\t113\tAtha5Chr4_Pals_Piler_3598_69_MAP_3\t205\t317\t8.5e-37\t157\t93.750000\n")
|
|
1621 f.close()
|
|
1622
|
|
1623 self.assertTrue(FileUtils.are2FilesIdentical(expPathFile, obsPathFile))
|
|
1624
|
|
1625 os.remove(pathFile)
|
|
1626 os.remove(expPathFile)
|
|
1627 os.remove(obsPathFile)
|
|
1628
|
|
1629
|
|
1630 def test_getPathListWithoutDuplicatesOnQueryCoord(self):
|
|
1631 iPath1 = Path(1, Range("qry1",398,491), Range("sbj1",10,112), 0.0, 10, 98.7)
|
|
1632 iPath2 = Path(1, Range("qry1",451,492), Range("sbj1",124,169), 0.0, 10, 98.7)
|
|
1633 iPath3 = Path(1, Range("qry1",451,492), Range("sbj1",249,294), 0.0, 10, 98.7)
|
|
1634 lPaths = [iPath3, iPath2, iPath1]
|
|
1635
|
|
1636 obslPaths = PathUtils.getPathListWithoutDuplicatesOnQueryCoord(lPaths)
|
|
1637
|
|
1638 explPaths = [iPath1, iPath3]
|
|
1639
|
|
1640 self.assertEquals(explPaths, obslPaths)
|
|
1641
|
|
1642
|
|
1643 def _makePathListFromTupleList ( self, tupleList ):
|
|
1644 pathList = []
|
|
1645 for tuple in tupleList:
|
|
1646 path = Path()
|
|
1647 path.setFromTuple(tuple)
|
|
1648 pathList.append(path)
|
|
1649 return pathList
|
|
1650
|
|
1651 def _makePathListFromStringList (self, stringList):
|
|
1652 pathList = []
|
|
1653 for string in stringList:
|
|
1654 path = Path()
|
|
1655 path.setFromString(string)
|
|
1656 pathList.append(path)
|
|
1657 return pathList
|
|
1658
|
|
1659 def _show (self, list):
|
|
1660 for item in list:
|
|
1661 print item.toString()
|
|
1662
|
|
1663
|
|
1664 test_suite = unittest.TestSuite()
|
|
1665 test_suite.addTest( unittest.makeSuite( Test_PathUtils ) )
|
|
1666 if __name__ == "__main__":
|
|
1667 unittest.TextTestRunner(verbosity=2).run( test_suite )
|