comparison SMART/Java/Python/structure/test/Test_SubMapping.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 import unittest
2 from SMART.Java.Python.structure.Interval import Interval
3 from SMART.Java.Python.structure.SubMapping import SubMapping
4
5 class Test_SubMapping(unittest.TestCase):
6
7 def test__init__(self):
8 expEvalue = 0.00
9 expScore = 0
10 expIdentity = 0.00
11 expTargetInterval = Interval()
12 expQueryInterval = Interval()
13 expQueryRange = expQueryInterval
14 expSubjectRange = expTargetInterval
15 expSize = None
16 expTags = {}
17
18 iSubMapping = SubMapping()
19 obsQueryRange = iSubMapping.getQueryAsRange()
20 obsSubjectRange = iSubMapping.getSubjectAsRange()
21 obsEvalue = iSubMapping.getEvalue()
22 obsScore = iSubMapping.getScore()
23 obsIdentity = iSubMapping.getIdentity()
24 obsTargetInterval = iSubMapping.getTargetInterval()
25 obsQueryInterval = iSubMapping.getQueryInterval()
26 obsSize = iSubMapping.getSize()
27 obsTags = iSubMapping.getTags()
28
29 self.assertEquals(expEvalue, obsEvalue)
30 self.assertEquals(expIdentity, obsIdentity)
31 self.assertEquals(expQueryInterval, obsQueryInterval)
32 self.assertEquals(expQueryRange, obsQueryRange)
33 self.assertEquals(expScore, obsScore)
34 self.assertEquals(expSize, obsSize)
35 self.assertEquals(expSubjectRange, obsSubjectRange)
36 self.assertEquals(expTags, obsTags)
37 self.assertEquals(expTargetInterval, obsTargetInterval)
38
39 def test__init__change_values_by_Interval(self):
40 iSubMapping = SubMapping()
41
42 expSeqName = ""
43
44 obsRangeSubject = iSubMapping.range_subject.getSeqname()
45 obsRangeQuery = iSubMapping.range_query.getSeqname()
46 obsIntervalTarget = iSubMapping.getTargetInterval().getChromosome()
47 obsIntervalQuery = iSubMapping.getQueryInterval().getChromosome()
48
49 self.assertEquals(expSeqName, obsRangeSubject)
50 self.assertEquals(expSeqName, obsRangeQuery)
51 self.assertEquals(expSeqName, obsIntervalTarget)
52 self.assertEquals(expSeqName, obsIntervalQuery)
53
54 iSubMapping.getTargetInterval().setChromosome("intervalTarget")
55 iSubMapping.getQueryInterval().setChromosome("intervalQuery")
56
57 expTargetSeqName = "intervalTarget"
58 expQuerySeqName = "intervalQuery"
59
60 obsRangeSubject = iSubMapping.range_subject.getSeqname()
61 obsRangeQuery = iSubMapping.range_query.getSeqname()
62 obsIntervalTarget = iSubMapping.getTargetInterval().getChromosome()
63 obsIntervalQuery = iSubMapping.getQueryInterval().getChromosome()
64
65 self.assertEquals(expTargetSeqName, obsRangeSubject)
66 self.assertEquals(expQuerySeqName, obsRangeQuery)
67 self.assertEquals(expTargetSeqName, obsIntervalTarget)
68 self.assertEquals(expQuerySeqName, obsIntervalQuery)
69
70 def test__init__change_values_by_Align(self):
71 iSubMapping = SubMapping()
72
73 expSeqName = ""
74
75 obsRangeSubject = iSubMapping.range_subject.getSeqname()
76 obsRangeQuery = iSubMapping.range_query.getSeqname()
77 obsIntervalTarget = iSubMapping.getTargetInterval().getChromosome()
78 obsIntervalQuery = iSubMapping.getQueryInterval().getChromosome()
79
80 self.assertEquals(expSeqName, obsRangeSubject)
81 self.assertEquals(expSeqName, obsRangeQuery)
82 self.assertEquals(expSeqName, obsIntervalTarget)
83 self.assertEquals(expSeqName, obsIntervalQuery)
84
85 iSubMapping.range_subject.setSeqName("intervalTarget")
86 iSubMapping.range_query.setSeqName("intervalQuery")
87
88 expTargetSeqName = "intervalTarget"
89 expQuerySeqName = "intervalQuery"
90
91 obsRangeSubject = iSubMapping.range_subject.getSeqname()
92 obsRangeQuery = iSubMapping.range_query.getSeqname()
93 obsIntervalTarget = iSubMapping.getTargetInterval().getChromosome()
94 obsIntervalQuery = iSubMapping.getQueryInterval().getChromosome()
95
96 self.assertEquals(expTargetSeqName, obsRangeSubject)
97 self.assertEquals(expQuerySeqName, obsRangeQuery)
98 self.assertEquals(expTargetSeqName, obsIntervalTarget)
99 self.assertEquals(expQuerySeqName, obsIntervalQuery)
100
101 def test__eq__(self):
102 iSubMapping1 = SubMapping()
103 iSubMapping1.setQueryName("Query")
104 iSubMapping1.setQueryStart(50)
105 iSubMapping1.setQueryEnd(150)
106 iSubMapping1.setSubjectName("Subject")
107 iSubMapping1.setSubjectStart(100)
108 iSubMapping1.setSubjectEnd(200)
109 iSubMapping1.e_value = 1e-20
110 iSubMapping1.score = 30
111 iSubMapping1.identity = 90.2
112 iInterval1 = Interval()
113 iInterval1.setChromosome("chromosome1")
114 iInterval1.setStart(0)
115 iInterval1.setEnd(100)
116 iInterval1.setDirection("+")
117 iInterval2 = Interval()
118 iInterval2.setChromosome("chromosome2")
119 iInterval2.setStart(200)
120 iInterval2.setEnd(300)
121 iInterval2.setDirection("+")
122 iSubMapping1.setTargetInterval(iInterval1)
123 iSubMapping1.setQueryInterval(iInterval2)
124 iSubMapping1.setTagValue("name", 50)
125 iSubMapping1.setSize(100)
126
127 iSubMapping2 = SubMapping()
128 iSubMapping2.setQueryName("Query")
129 iSubMapping2.setQueryStart(50)
130 iSubMapping2.setQueryEnd(150)
131 iSubMapping2.setSubjectName("Subject")
132 iSubMapping2.setSubjectStart(100)
133 iSubMapping2.setSubjectEnd(200)
134 iSubMapping2.e_value = 1e-20
135 iSubMapping2.score = 30
136 iSubMapping2.identity = 90.2
137 iSubMapping2.setTargetInterval(iInterval1)
138 iSubMapping2.setQueryInterval(iInterval2)
139 iSubMapping2.setTagValue("name", 50)
140 iSubMapping2.setSize(100)
141 self.assertEqual(iSubMapping1, iSubMapping2)
142
143
144 def test__eq__withInitialValue(self):
145 iSubMapping1 = SubMapping()
146 iInterval1 = Interval()
147 iInterval2 = Interval()
148 iSubMapping1.setTargetInterval(iInterval1)
149 iSubMapping1.setQueryInterval(iInterval2)
150 iSubMapping1.setTagValue("name", 50)
151 iSubMapping1.setSize(100)
152
153 iSubMapping2 = SubMapping()
154 iSubMapping2.setTargetInterval(iInterval1)
155 iSubMapping2.setQueryInterval(iInterval2)
156 iSubMapping2.setTagValue("name", 50)
157 iSubMapping2.setSize(100)
158 self.assertEqual(iSubMapping1, iSubMapping2)
159
160
161 def test__init__with_copy(self):
162 iTestSubMapping = SubMapping()
163 iTestSubMapping.setQueryName("Query")
164 iTestSubMapping.setQueryStart(50)
165 iTestSubMapping.setQueryEnd(150)
166 iTestSubMapping.setSubjectName("Subject")
167 iTestSubMapping.setSubjectStart(100)
168 iTestSubMapping.setSubjectEnd(200)
169 iTestSubMapping.e_value = 1e-20
170 iTestSubMapping.score = 30
171 iTestSubMapping.identity = 90.2
172
173 iIntervalTarget = Interval()
174 iIntervalTarget.setChromosome("chromosomeTarget")
175 iIntervalTarget.setName("sequenceTarget")
176 iIntervalTarget.setStart(0)
177 iIntervalTarget.setEnd(123)
178 iIntervalTarget.setDirection("+")
179 iIntervalQuery = Interval()
180 iIntervalQuery.setChromosome("chromosomeQuery")
181 iIntervalQuery.setName("sequenceQuery")
182 iIntervalQuery.setStart(200)
183 iIntervalQuery.setEnd(323)
184 iIntervalQuery.setDirection("+")
185
186 iTestSubMapping.setQueryInterval(iIntervalTarget)
187 iTestSubMapping.setTargetInterval(iIntervalQuery)
188 iTestSubMapping.setTagValue("identity", 50)
189 iTestSubMapping.setSize(10)
190
191 iSubMappingWithCopy = SubMapping(iTestSubMapping)
192 self.assertEquals(iSubMappingWithCopy, iTestSubMapping)
193
194
195 def test_copy(self):
196 iSubMapping = SubMapping()
197 iSubMapping.setQueryName("Query")
198 iSubMapping.setQueryStart(50)
199 iSubMapping.setQueryEnd(150)
200 iSubMapping.setSubjectName("Subject")
201 iSubMapping.setSubjectStart(100)
202 iSubMapping.setSubjectEnd(200)
203 iSubMapping.e_value = 1e-20
204 iSubMapping.score = 30
205 iSubMapping.identity = 90.2
206
207 iInterval1 = Interval()
208 iInterval1.setChromosome("chromosome1")
209 iInterval1.setName("sequence1")
210 iInterval1.setStart(0)
211 iInterval1.setEnd(123)
212 iInterval1.setDirection("+")
213 iInterval2 = Interval()
214 iInterval2.setChromosome("chromosome2")
215 iInterval2.setName("sequence2")
216 iInterval2.setStart(200)
217 iInterval2.setEnd(300)
218 iInterval2.setDirection("+")
219 iSubMapping.setQueryInterval(iInterval1)
220 iSubMapping.setTargetInterval(iInterval2)
221 iSubMapping.setTagValue("identity", 50)
222 iSubMapping.setSize(10)
223
224 iSubMappingCopy = SubMapping()
225 iSubMappingCopy.copy(iSubMapping)
226 self.assertEqual(iSubMappingCopy, iSubMapping)
227
228
229 def test_setTags(self):
230 iSubMapping = SubMapping()
231 iSubMapping.getQueryInterval().setSize(50)
232 iSubMapping.getTargetInterval().setSize(2)
233 iSubMapping.setTagValue("identity", 50)
234 iSubMapping.setSize(10)
235
236 expQueryIntervalSize = 50
237 expTargetIntervalSize = 2
238 expTags = {"identity" : 50,
239 "nbMismatches" : 5}
240
241 obsTags = iSubMapping.getTags()
242 self.assertEquals(expTags, obsTags)
243
244
245 def test_setIdentity(self):
246 iSubMapping = SubMapping()
247 iSubMapping.setIdentity(10)
248 expIdentity = 10
249 expTags = {"identity": 10}
250
251 obsIdentity = iSubMapping.getIdentity()
252 obsTags = iSubMapping.getTags()
253
254 self.assertEquals(expIdentity,obsIdentity)
255 self.assertEquals(expTags,obsTags)
256
257
258 def test_setIdentity_with_size(self):
259 iSubMapping = SubMapping()
260 iSubMapping.setSize(10)
261 iSubMapping.setIdentity(50)
262
263 expIdentity = 50
264 expTags = {"identity" : 50,
265 "nbMismatches" : 5}
266
267 obsIdentity = iSubMapping.getIdentity()
268 obsTags = iSubMapping.getTags()
269
270 self.assertEquals(expIdentity,obsIdentity)
271 self.assertEquals(expTags,obsTags)
272
273
274 def test_setIdentity_with_sizeAndMismatchTag(self):
275 iSubMapping = SubMapping()
276 iSubMapping.setSize(10)
277 iSubMapping.setTagValue("nbMismatches", 8)
278 iSubMapping.setIdentity(50)
279
280 expIdentity = 50
281 expTags = {"identity" : 50,
282 "nbMismatches" : 8}
283
284 obsIdentity = iSubMapping.getIdentity()
285 obsTags = iSubMapping.getTags()
286
287 self.assertEquals(expIdentity,obsIdentity)
288 self.assertEquals(expTags,obsTags)
289
290
291 if __name__ == "__main__":
292 unittest.main()