Mercurial > repos > yufei-luo > s_mart
comparison commons/core/coord/test/Test_Match.py @ 6:769e306b7933
Change the repository level.
author | yufei-luo |
---|---|
date | Fri, 18 Jan 2013 04:54:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:ea3082881bf8 | 6:769e306b7933 |
---|---|
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 from commons.core.coord.Match import Match | |
34 from commons.core.coord.Path import Path | |
35 | |
36 | |
37 class Test_Match( unittest.TestCase ): | |
38 | |
39 def test_eq_match_equals( self ): | |
40 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
41 match1 = Match() | |
42 match1.setFromTuple(tuple1) | |
43 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
44 match2 = Match() | |
45 match2.setFromTuple(tuple2) | |
46 self.assertEquals( match1, match2 ) | |
47 | |
48 def test_eq_match_not_equals_query_name( self ): | |
49 tuple1 = ("Name", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
50 match1 = Match() | |
51 match1.setFromTuple(tuple1) | |
52 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
53 match2 = Match() | |
54 match2.setFromTuple(tuple2) | |
55 self.assertNotEquals( match1, match2 ) | |
56 | |
57 def test_eq_match_not_equals_query_start( self ): | |
58 tuple1 = ("QName", 2, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
59 match1 = Match() | |
60 match1.setFromTuple(tuple1) | |
61 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
62 match2 = Match() | |
63 match2.setFromTuple(tuple2) | |
64 self.assertNotEquals( match1, match2 ) | |
65 | |
66 def test_eq_match_not_equals_query_end( self ): | |
67 tuple1 = ("QName", 1, 6, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
68 match1 = Match() | |
69 match1.setFromTuple(tuple1) | |
70 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
71 match2 = Match() | |
72 match2.setFromTuple(tuple2) | |
73 self.assertNotEquals( match1, match2 ) | |
74 | |
75 def test_eq_match_not_equals_query_length( self ): | |
76 tuple1 = ("QName", 1, 5, 6, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
77 match1 = Match() | |
78 match1.setFromTuple(tuple1) | |
79 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
80 match2 = Match() | |
81 match2.setFromTuple(tuple2) | |
82 self.assertNotEquals( match1, match2 ) | |
83 | |
84 def test_eq_match_not_equals_query_length_perc( self ): | |
85 tuple1 = ("QName", 1, 5, 5, 0.15, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
86 match1 = Match() | |
87 match1.setFromTuple(tuple1) | |
88 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
89 match2 = Match() | |
90 match2.setFromTuple(tuple2) | |
91 self.assertNotEquals( match1, match2 ) | |
92 | |
93 def test_eq_match_not_equals_match_length_perc( self ): | |
94 tuple1 = ("QName", 1, 5, 5, 0.1, 0.25, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
95 match1 = Match() | |
96 match1.setFromTuple(tuple1) | |
97 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
98 match2 = Match() | |
99 match2.setFromTuple(tuple2) | |
100 self.assertNotEquals( match1, match2 ) | |
101 | |
102 def test_eq_match_not_equals_subject_name( self ): | |
103 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "Name", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
104 match1 = Match() | |
105 match1.setFromTuple(tuple1) | |
106 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
107 match2 = Match() | |
108 match2.setFromTuple(tuple2) | |
109 self.assertNotEquals( match1, match2 ) | |
110 | |
111 def test_eq_match_not_equals_subject_start( self ): | |
112 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 6, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
113 match1 = Match() | |
114 match1.setFromTuple(tuple1) | |
115 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
116 match2 = Match() | |
117 match2.setFromTuple(tuple2) | |
118 self.assertNotEquals( match1, match2 ) | |
119 | |
120 def test_eq_match_not_equals_subject_end( self ): | |
121 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 26, 20, 0.15, 1e-20, 15, 87.2, 1) | |
122 match1 = Match() | |
123 match1.setFromTuple(tuple1) | |
124 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
125 match2 = Match() | |
126 match2.setFromTuple(tuple2) | |
127 self.assertNotEquals( match1, match2 ) | |
128 | |
129 def test_eq_match_not_equals_subject_length( self ): | |
130 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 21, 0.15, 1e-20, 15, 87.2, 1) | |
131 match1 = Match() | |
132 match1.setFromTuple(tuple1) | |
133 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
134 match2 = Match() | |
135 match2.setFromTuple(tuple2) | |
136 self.assertNotEquals( match1, match2 ) | |
137 | |
138 def test_eq_match_not_equals_subject_length_perc( self ): | |
139 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.16, 1e-20, 15, 87.2, 1) | |
140 match1 = Match() | |
141 match1.setFromTuple(tuple1) | |
142 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
143 match2 = Match() | |
144 match2.setFromTuple(tuple2) | |
145 self.assertNotEquals( match1, match2 ) | |
146 | |
147 def test_eq_match_not_equals_subject_e_value( self ): | |
148 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-21, 15, 87.2, 1) | |
149 match1 = Match() | |
150 match1.setFromTuple(tuple1) | |
151 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
152 match2 = Match() | |
153 match2.setFromTuple(tuple2) | |
154 self.assertNotEquals( match1, match2 ) | |
155 | |
156 def test_eq_match_not_equals_subject_score( self ): | |
157 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 16, 87.2, 1) | |
158 match1 = Match() | |
159 match1.setFromTuple(tuple1) | |
160 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
161 match2 = Match() | |
162 match2.setFromTuple(tuple2) | |
163 self.assertNotEquals( match1, match2 ) | |
164 | |
165 def test_eq_match_not_equals_subject_identity( self ): | |
166 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 85.2, 1) | |
167 match1 = Match() | |
168 match1.setFromTuple(tuple1) | |
169 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
170 match2 = Match() | |
171 match2.setFromTuple(tuple2) | |
172 self.assertNotEquals( match1, match2 ) | |
173 | |
174 def test_eq_match_not_equals_subject_id( self ): | |
175 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 2) | |
176 match1 = Match() | |
177 match1.setFromTuple(tuple1) | |
178 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
179 match2 = Match() | |
180 match2.setFromTuple(tuple2) | |
181 self.assertNotEquals( match1, match2 ) | |
182 | |
183 def test_setFromTuple_direct_strand( self ): | |
184 tuple = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
185 obsMatch = Match() | |
186 obsMatch.setFromTuple(tuple) | |
187 expMatch = Match() | |
188 expMatch.range_query.seqname = "QName" | |
189 expMatch.range_query.start = 1 | |
190 expMatch.range_query.end = 5 | |
191 expMatch.query_length = 5 | |
192 expMatch.query_length_perc = 0.1 | |
193 expMatch.match_length_perc = 0.2 | |
194 expMatch.range_subject.seqname = "SName" | |
195 expMatch.range_subject.start = 5 | |
196 expMatch.range_subject.end = 25 | |
197 expMatch.subject_length = 20 | |
198 expMatch.subject_length_perc = 0.15 | |
199 expMatch.e_value = 1e-20 | |
200 expMatch.score = 15 | |
201 expMatch.identity = 87.2 | |
202 expMatch.id = 1 | |
203 expMatch.subject_seqlength = int( expMatch.subject_length / expMatch.subject_length_perc ) | |
204 expMatch.query_seqlength = int( expMatch.query_length / expMatch.query_length_perc ) | |
205 self.assertEquals( expMatch, obsMatch ) | |
206 | |
207 def test_setFromTuple_reverse_strand_on_subject( self ): | |
208 tuple = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 25, 5, 20, 0.15, 1e-20, 15, 87.2, 1) | |
209 obsMatch = Match() | |
210 obsMatch.setFromTuple(tuple) | |
211 expMatch = Match() | |
212 expMatch.range_query.seqname = "QName" | |
213 expMatch.range_query.start = 1 | |
214 expMatch.range_query.end = 5 | |
215 expMatch.query_length = 5 | |
216 expMatch.query_length_perc = 0.1 | |
217 expMatch.match_length_perc = 0.2 | |
218 expMatch.range_subject.seqname = "SName" | |
219 expMatch.range_subject.start = 25 | |
220 expMatch.range_subject.end = 5 | |
221 expMatch.subject_length = 20 | |
222 expMatch.subject_length_perc = 0.15 | |
223 expMatch.e_value = 1e-20 | |
224 expMatch.score = 15 | |
225 expMatch.identity = 87.2 | |
226 expMatch.id = 1 | |
227 expMatch.subject_seqlength = int( expMatch.subject_length / expMatch.subject_length_perc ) | |
228 expMatch.query_seqlength = int( expMatch.query_length / expMatch.query_length_perc ) | |
229 self.assertEquals( expMatch, obsMatch ) | |
230 | |
231 def test_setFromTuple_reverse_strand_on_query( self ): | |
232 tuple = ("QName", 5, 1, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
233 obsMatch = Match() | |
234 obsMatch.setFromTuple(tuple) | |
235 expMatch = Match() | |
236 expMatch.range_query.seqname = "QName" | |
237 expMatch.range_query.start = 1 | |
238 expMatch.range_query.end = 5 | |
239 expMatch.query_length = 5 | |
240 expMatch.query_length_perc = 0.1 | |
241 expMatch.match_length_perc = 0.2 | |
242 expMatch.range_subject.seqname = "SName" | |
243 expMatch.range_subject.start = 25 | |
244 expMatch.range_subject.end = 5 | |
245 expMatch.subject_length = 20 | |
246 expMatch.subject_length_perc = 0.15 | |
247 expMatch.e_value = 1e-20 | |
248 expMatch.score = 15 | |
249 expMatch.identity = 87.2 | |
250 expMatch.id = 1 | |
251 expMatch.subject_seqlength = int( expMatch.subject_length / expMatch.subject_length_perc ) | |
252 expMatch.query_seqlength = int( expMatch.query_length / expMatch.query_length_perc ) | |
253 self.assertEquals( expMatch, obsMatch ) | |
254 | |
255 def test_setFromTuple_reverse_strand_on_query_and_subject( self ): | |
256 tuple = ("QName", 5, 1, 5, 0.1, 0.2, "SName", 25, 5, 20, 0.15, 1e-20, 15, 87.2, 1) | |
257 obsMatch = Match() | |
258 obsMatch.setFromTuple(tuple) | |
259 expMatch = Match() | |
260 expMatch.range_query.seqname = "QName" | |
261 expMatch.range_query.start = 1 | |
262 expMatch.range_query.end = 5 | |
263 expMatch.query_length = 5 | |
264 expMatch.query_length_perc = 0.1 | |
265 expMatch.match_length_perc = 0.2 | |
266 expMatch.range_subject.seqname = "SName" | |
267 expMatch.range_subject.start = 5 | |
268 expMatch.range_subject.end = 25 | |
269 expMatch.subject_length = 20 | |
270 expMatch.subject_length_perc = 0.15 | |
271 expMatch.e_value = 1e-20 | |
272 expMatch.score = 15 | |
273 expMatch.identity = 87.2 | |
274 expMatch.id = 1 | |
275 expMatch.subject_seqlength = int( expMatch.subject_length / expMatch.subject_length_perc ) | |
276 expMatch.query_seqlength = int( expMatch.query_length / expMatch.query_length_perc ) | |
277 self.assertEquals( expMatch, obsMatch ) | |
278 | |
279 def test_toString( self ): | |
280 tuple = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
281 match = Match() | |
282 match.setFromTuple(tuple) | |
283 expString = "QName\t1\t5\t5\t%f\t%f\tSName\t5\t25\t20\t%f\t%g\t15\t%f\t1" % (0.1,0.2,0.15,1e-20, 87.2) | |
284 obsString = match.toString() | |
285 self.assertEquals(expString, obsString) | |
286 | |
287 def test_getPathInstance( self ): | |
288 tuple = ( "QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1 ) | |
289 match = Match() | |
290 match.setFromTuple( tuple ) | |
291 tuple = ( 1, "QName", 1, 5, "SName", 5, 25, 1e-20, 15, 87.2 ) | |
292 exp = Path() | |
293 exp.setFromTuple( tuple ) | |
294 obs = match.getPathInstance() | |
295 self.assertEqual( exp, obs ) | |
296 | |
297 def test_getQryIsIncluded(self): | |
298 tuple = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
299 match = Match() | |
300 match.setFromTuple(tuple) | |
301 expString = "query QName (50 bp: 1-5) is contained in subject SName (133 bp: 5-25): id=87.20 - 0.100 - 0.200 - 0.150" | |
302 obsString = match.getQryIsIncluded() | |
303 self.assertEquals(expString, obsString) | |
304 | |
305 def test_isDoublonWith_Matchs_equals(self): | |
306 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
307 match1 = Match() | |
308 match1.setFromTuple(tuple1) | |
309 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
310 match2 = Match() | |
311 match2.setFromTuple(tuple2) | |
312 self.assertTrue(match1.isDoublonWith(match2)) | |
313 | |
314 def test_isDoublonWith_Matchs_unequals_on_MatchNumbers(self): | |
315 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
316 match1 = Match() | |
317 match1.setFromTuple(tuple1) | |
318 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 86.2, 1) | |
319 match2 = Match() | |
320 match2.setFromTuple(tuple2) | |
321 self.assertFalse(match1.isDoublonWith(match2)) | |
322 | |
323 def test_isDoublonWith_Matchs_unequals_on_SeqNames(self): | |
324 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
325 match1 = Match() | |
326 match1.setFromTuple(tuple1) | |
327 tuple2 = ("QName", 1, 5, 5, 0.1, 0.2, "Name", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
328 match2 = Match() | |
329 match2.setFromTuple(tuple2) | |
330 self.assertFalse(match1.isDoublonWith(match2)) | |
331 | |
332 def test_isDoublonWith_Matchs_unequals_on_Coordinates(self): | |
333 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
334 match1 = Match() | |
335 match1.setFromTuple(tuple1) | |
336 tuple2 = ("QName", 1, 6, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
337 match2 = Match() | |
338 match2.setFromTuple(tuple2) | |
339 self.assertFalse(match1.isDoublonWith(match2)) | |
340 | |
341 def test_isDoublonWith_Reversed_Matchs_equals(self): | |
342 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
343 match1 = Match() | |
344 match1.setFromTuple(tuple1) | |
345 tuple2 = ("SName", 5, 25, 20, 0.15, 0.2, "QName", 1, 5, 5, 0.1, 1e-20, 15, 87.2, 1) | |
346 match2 = Match() | |
347 match2.setFromTuple(tuple2) | |
348 self.assertTrue(match1.isDoublonWith(match2)) | |
349 | |
350 def test_isDoublonWith_Reversed_Matchs_unequals(self): | |
351 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1) | |
352 match1 = Match() | |
353 match1.setFromTuple(tuple1) | |
354 tuple2 = ("SName", 5, 25, 20, 0.15, 0.2, "QName", 1, 6, 5, 0.1, 1e-20, 15, 87.2, 1) | |
355 match2 = Match() | |
356 match2.setFromTuple(tuple2) | |
357 self.assertFalse(match1.isDoublonWith(match2)) | |
358 | |
359 | |
360 test_suite = unittest.TestSuite() | |
361 test_suite.addTest( unittest.makeSuite( Test_Match ) ) | |
362 if __name__ == "__main__": | |
363 unittest.TextTestRunner(verbosity=2).run( test_suite ) |