6
|
1 import unittest
|
|
2 from SMART.Java.Python.structure.Interval import Interval
|
|
3 from SMART.Java.Python.structure.Transcript import Transcript
|
|
4
|
|
5 class Test_Transcript(unittest.TestCase):
|
|
6
|
|
7 def test_getSize(self):
|
|
8 transcript1 = Transcript()
|
|
9 transcript1.setDirection("+")
|
|
10 transcript1.setStart(2000)
|
|
11 transcript1.setEnd(3000)
|
|
12 transcript1.setChromosome("arm_X")
|
|
13
|
|
14 self.assertEqual(transcript1.getSize(), 1001)
|
|
15
|
|
16 transcript2 = Transcript()
|
|
17 transcript2.copy(transcript1)
|
|
18 self.assertEqual(transcript1.getSize(), 1001)
|
|
19
|
|
20 transcript3 = Transcript()
|
|
21 transcript3.setDirection("+")
|
|
22 transcript3.setChromosome("arm_X")
|
|
23
|
|
24 exon1 = Interval()
|
|
25 exon1.setDirection("+")
|
|
26 exon1.setChromosome("arm_X")
|
|
27 exon1.setStart(100)
|
|
28 exon1.setEnd(200)
|
|
29 transcript3.addExon(exon1)
|
|
30
|
|
31 exon2 = Interval()
|
|
32 exon2.setDirection("+")
|
|
33 exon2.setChromosome("arm_X")
|
|
34 exon2.setStart(300)
|
|
35 exon2.setEnd(400)
|
|
36 transcript3.addExon(exon2)
|
|
37
|
|
38 self.assertEqual(transcript3.getSize(), 203)
|
|
39
|
|
40
|
|
41 def test_overlapWithExons(self):
|
|
42 exon1_1 = Interval()
|
|
43 exon1_1.setChromosome("chr1")
|
|
44 exon1_1.setStart(100)
|
|
45 exon1_1.setEnd(200)
|
|
46 exon1_1.setDirection("+")
|
|
47
|
|
48 exon1_2 = Interval()
|
|
49 exon1_2.setChromosome("chr1")
|
|
50 exon1_2.setStart(500)
|
|
51 exon1_2.setEnd(600)
|
|
52 exon1_2.setDirection("+")
|
|
53
|
|
54 transcript1 = Transcript()
|
|
55 transcript1.setChromosome("chr1")
|
|
56 transcript1.setStart(100)
|
|
57 transcript1.setEnd(600)
|
|
58 transcript1.setDirection("+")
|
|
59 transcript1.addExon(exon1_1)
|
|
60 transcript1.addExon(exon1_2)
|
|
61
|
|
62 exon2_1 = Interval()
|
|
63 exon2_1.copy(exon1_1)
|
|
64
|
|
65 transcript2 = Transcript()
|
|
66 transcript2.setChromosome("chr1")
|
|
67 transcript2.setStart(100)
|
|
68 transcript2.setEnd(200)
|
|
69 transcript2.setDirection("+")
|
|
70 transcript2.addExon(exon2_1)
|
|
71
|
|
72 self.assertTrue(transcript1.overlapWithExon(transcript2))
|
|
73
|
|
74 transcript2.reverse()
|
|
75 try:
|
|
76 self.assertFalse(transcript1.overlapWithExon(transcript2))
|
|
77 except Exception:
|
|
78 pass
|
|
79
|
|
80 transcript2.reverse()
|
|
81 transcript2.setChromosome("chr2")
|
|
82 self.assertFalse(transcript1.overlapWithExon(transcript2))
|
|
83
|
|
84 exon3_1 = Interval()
|
|
85 exon3_1.copy(exon1_1)
|
|
86 exon3_1.setEnd(400)
|
|
87 exon3_1.setStart(300)
|
|
88
|
|
89 transcript3 = Transcript()
|
|
90 transcript3.setChromosome("chr1")
|
|
91 transcript3.setStart(300)
|
|
92 transcript3.setEnd(400)
|
|
93 transcript3.setDirection("+")
|
|
94 transcript3.addExon(exon3_1)
|
|
95 self.assertFalse(transcript1.overlapWithExon(transcript3))
|
|
96
|
|
97
|
|
98 def test_merge(self):
|
|
99 exon1_1 = Interval()
|
|
100 exon1_1.setChromosome("chr1")
|
|
101 exon1_1.setStart(100)
|
|
102 exon1_1.setEnd(200)
|
|
103 exon1_1.setDirection("+")
|
|
104
|
|
105 exon1_2 = Interval()
|
|
106 exon1_2.setChromosome("chr1")
|
|
107 exon1_2.setStart(500)
|
|
108 exon1_2.setEnd(600)
|
|
109 exon1_2.setDirection("+")
|
|
110
|
|
111 transcript1 = Transcript()
|
|
112 transcript1.setChromosome("chr1")
|
|
113 transcript1.setEnd(600)
|
|
114 transcript1.setStart(100)
|
|
115 transcript1.setDirection("+")
|
|
116 transcript1.addExon(exon1_1)
|
|
117 transcript1.addExon(exon1_2)
|
|
118
|
|
119 exon2_1 = Interval()
|
|
120 exon2_1.copy(exon1_1)
|
|
121
|
|
122 transcript2 = Transcript()
|
|
123 transcript2.setChromosome("chr1")
|
|
124 transcript2.setEnd(200)
|
|
125 transcript2.setStart(100)
|
|
126 transcript2.setDirection("+")
|
|
127 transcript2.addExon(exon2_1)
|
|
128
|
|
129 transcript1.merge(transcript2)
|
|
130 transcript1.sortExonsIncreasing()
|
|
131 exons = transcript1.getExons()
|
|
132 self.assertEqual(len(exons), 2)
|
|
133 exon1, exon2 = exons
|
|
134 self.assertEqual(exon1.getStart(), 100)
|
|
135 self.assertEqual(exon1.getEnd(), 200)
|
|
136 self.assertEqual(exon2.getStart(), 500)
|
|
137 self.assertEqual(exon2.getEnd(), 600)
|
|
138
|
|
139 transcript2.setChromosome("chr2")
|
|
140 try:
|
|
141 transcript1.merge(transcript2)
|
|
142 self.fail()
|
|
143 except Exception:
|
|
144 pass
|
|
145
|
|
146 exon3_1 = Interval()
|
|
147 exon3_1.copy(exon1_1)
|
|
148 exon3_1.setEnd(650)
|
|
149 exon3_1.setStart(550)
|
|
150
|
|
151 transcript3 = Transcript()
|
|
152 transcript3.setChromosome("chr1")
|
|
153 transcript3.setEnd(650)
|
|
154 transcript3.setStart(550)
|
|
155 transcript3.setDirection("+")
|
|
156 transcript3.addExon(exon3_1)
|
|
157
|
|
158 transcript1.merge(transcript3)
|
|
159 self.assertEqual(transcript1.getStart(), 100)
|
|
160 self.assertEqual(transcript1.getEnd(), 650)
|
|
161 exons = transcript1.getExons()
|
|
162 self.assertEqual(len(exons), 2)
|
|
163 exon1, exon2 = exons
|
|
164 self.assertEqual(exon1.getStart(), 100)
|
|
165 self.assertEqual(exon1.getEnd(), 200)
|
|
166 self.assertEqual(exon2.getStart(), 500)
|
|
167 self.assertEqual(exon2.getEnd(), 650)
|
|
168
|
|
169 exon4_1 = Interval()
|
|
170 exon4_1.copy(exon1_1)
|
|
171 exon4_1.setEnd(400)
|
|
172 exon4_1.setStart(300)
|
|
173
|
|
174 transcript4 = Transcript()
|
|
175 transcript4.setChromosome("chr1")
|
|
176 transcript4.setStart(300)
|
|
177 transcript4.setEnd(400)
|
|
178 transcript4.setDirection("+")
|
|
179 transcript4.addExon(exon4_1)
|
|
180
|
|
181 transcript1.merge(transcript4)
|
|
182 self.assertEqual(transcript1.getStart(), 100)
|
|
183 self.assertEqual(transcript1.getEnd(), 650)
|
|
184 transcript1.sortExonsIncreasing()
|
|
185 exons = transcript1.getExons()
|
|
186 self.assertEqual(len(exons), 3)
|
|
187 exon1, exon2, exon3 = exons
|
|
188 self.assertEqual(exon1.getStart(), 100)
|
|
189 self.assertEqual(exon1.getEnd(), 200)
|
|
190 self.assertEqual(exon2.getStart(), 300)
|
|
191 self.assertEqual(exon2.getEnd(), 400)
|
|
192 self.assertEqual(exon3.getStart(), 500)
|
|
193 self.assertEqual(exon3.getEnd(), 650)
|
|
194
|
|
195
|
|
196 def test_extendStart(self):
|
|
197 transcript1 = Transcript()
|
|
198 transcript1.setStart(2000)
|
|
199 transcript1.setEnd(3000)
|
|
200 transcript1.setDirection("+")
|
|
201 transcript1.setChromosome("arm_X")
|
|
202
|
|
203 transcript2 = Transcript()
|
|
204 transcript2.copy(transcript1)
|
|
205 transcript2.setDirection("-")
|
|
206
|
|
207 transcript1.extendStart(1000)
|
|
208 transcript2.extendStart(1000)
|
|
209
|
|
210
|
|
211 self.assertEqual(transcript1.getDirection(), 1)
|
|
212 self.assertEqual(transcript1.getStart(), 1000)
|
|
213 self.assertEqual(transcript1.getEnd(), 3000)
|
|
214 self.assertEqual(transcript1.getChromosome(), "arm_X")
|
|
215
|
|
216 self.assertEqual(transcript2.getDirection(), -1)
|
|
217 self.assertEqual(transcript2.getStart(), 2000)
|
|
218 self.assertEqual(transcript2.getEnd(), 4000)
|
|
219 self.assertEqual(transcript2.getChromosome(), "arm_X")
|
|
220
|
|
221
|
|
222 def test_restrictStart(self):
|
|
223 exon1_1 = Interval()
|
|
224 exon1_1.setChromosome("chr1")
|
|
225 exon1_1.setStart(100)
|
|
226 exon1_1.setEnd(200)
|
|
227 exon1_1.setDirection("+")
|
|
228
|
|
229 exon1_2 = Interval()
|
|
230 exon1_2.setChromosome("chr1")
|
|
231 exon1_2.setStart(300)
|
|
232 exon1_2.setEnd(500)
|
|
233 exon1_2.setDirection("+")
|
|
234
|
|
235 transcript1 = Transcript()
|
|
236 transcript1.setChromosome("chr1")
|
|
237 transcript1.setStart(100)
|
|
238 transcript1.setEnd(500)
|
|
239 transcript1.setDirection("+")
|
|
240 transcript1.addExon(exon1_1)
|
|
241 transcript1.addExon(exon1_2)
|
|
242
|
|
243 transcript1.restrictStart(301)
|
|
244 exons = transcript1.getExons()
|
|
245 self.assertEqual(len(exons), 2)
|
|
246 exon1, exon2 = exons
|
|
247 self.assertEqual(exon1.getStart(), 100)
|
|
248 self.assertEqual(exon1.getEnd(), 200)
|
|
249 self.assertEqual(exon2.getStart(), 300)
|
|
250 self.assertEqual(exon2.getEnd(), 400)
|
|
251
|
|
252
|
|
253 def test__include(self):
|
|
254 iTranscript1 = Transcript()
|
|
255 iTranscript1.setName("transcript1")
|
|
256 iTranscript1.setChromosome("chr1")
|
|
257 iTranscript1.setStart(100)
|
|
258 iTranscript1.setEnd(200)
|
|
259 iTranscript1.setDirection("+")
|
|
260
|
|
261 iTranscript2 = Transcript()
|
|
262 iTranscript2.copy(iTranscript1)
|
|
263 iTranscript2.setName("transcript2")
|
|
264 self.assertTrue(iTranscript1.include(iTranscript2))
|
|
265 self.assertTrue(iTranscript2.include(iTranscript1))
|
|
266
|
|
267 iTranscript2.setChromosome("chr2")
|
|
268 self.assertFalse(iTranscript1.include(iTranscript2))
|
|
269 self.assertFalse(iTranscript2.include(iTranscript1))
|
|
270
|
|
271 iTranscript2.setChromosome("chr1")
|
|
272 exon = Interval()
|
|
273 exon.setChromosome("chr1")
|
|
274 exon.setDirection("+")
|
|
275 exon.setStart(300)
|
|
276 exon.setEnd(400)
|
|
277 iTranscript1.addExon(exon)
|
|
278 self.assertTrue(iTranscript1.include(iTranscript2))
|
|
279 self.assertFalse(iTranscript2.include(iTranscript1))
|
|
280
|
|
281 exon = Interval()
|
|
282 exon.setChromosome("chr1")
|
|
283 exon.setDirection("+")
|
|
284 exon.setStart(500)
|
|
285 exon.setEnd(600)
|
|
286 iTranscript2.addExon(exon)
|
|
287 self.assertFalse(iTranscript1.include(iTranscript2))
|
|
288 self.assertFalse(iTranscript2.include(iTranscript1))
|
|
289
|
|
290
|
|
291 def test__getDifference(self):
|
|
292 iTranscript1 = Transcript()
|
|
293 iTranscript1.setName("transcript1")
|
|
294 iTranscript1.setChromosome("chr1")
|
|
295 iTranscript1.setStart(100)
|
|
296 iTranscript1.setEnd(400)
|
|
297 iTranscript1.setDirection("+")
|
|
298
|
|
299 iTranscript2 = Transcript()
|
|
300 iTranscript2.setName("transcript1")
|
|
301 iTranscript2.setChromosome("chr1")
|
|
302 iTranscript2.setStart(200)
|
|
303 iTranscript2.setEnd(400)
|
|
304 iTranscript2.setDirection("+")
|
|
305
|
|
306 newTranscript = iTranscript1.getDifference(iTranscript2)
|
|
307 self.assertTrue(newTranscript.getStart(), 100)
|
|
308 self.assertTrue(newTranscript.getEnd(), 199)
|
|
309 exons = newTranscript.getExons()
|
|
310 self.assertTrue(len(exons), 1)
|
|
311 exon1 = exons[0]
|
|
312 self.assertTrue(exon1.getStart(), 100)
|
|
313 self.assertTrue(exon1.getEnd(), 199)
|
|
314
|
|
315 iTranscript2 = Transcript()
|
|
316 iTranscript2.setName("transcript1")
|
|
317 iTranscript2.setChromosome("chr1")
|
|
318 iTranscript2.setStart(100)
|
|
319 iTranscript2.setEnd(200)
|
|
320 iTranscript2.setDirection("+")
|
|
321
|
|
322 newTranscript = iTranscript1.getDifference(iTranscript2)
|
|
323 self.assertTrue(newTranscript.getStart(), 201)
|
|
324 self.assertTrue(newTranscript.getEnd(), 400)
|
|
325 exons = newTranscript.getExons()
|
|
326 self.assertTrue(len(exons), 1)
|
|
327 exon1 = exons[0]
|
|
328 self.assertTrue(exon1.getStart(), 201)
|
|
329 self.assertTrue(exon1.getEnd(), 400)
|
|
330
|
|
331 iTranscript2 = Transcript()
|
|
332 iTranscript2.setName("transcript1")
|
|
333 iTranscript2.setChromosome("chr1")
|
|
334 iTranscript2.setStart(200)
|
|
335 iTranscript2.setEnd(300)
|
|
336 iTranscript2.setDirection("+")
|
|
337
|
|
338 newTranscript = iTranscript1.getDifference(iTranscript2)
|
|
339 self.assertTrue(newTranscript.getStart(), 100)
|
|
340 self.assertTrue(newTranscript.getEnd(), 400)
|
|
341 exons = newTranscript.getExons()
|
|
342 self.assertTrue(len(exons), 2)
|
|
343 exon1, exon2 = exons
|
|
344 self.assertTrue(exon1.getStart(), 100)
|
|
345 self.assertTrue(exon1.getEnd(), 199)
|
|
346 self.assertTrue(exon2.getStart(), 301)
|
|
347 self.assertTrue(exon2.getEnd(), 400)
|
|
348
|
|
349
|
|
350 if __name__ == '__main__':
|
|
351 unittest.main()
|