18
|
1 import unittest
|
|
2 import os
|
|
3 from SMART.Java.Python.getExons import GetExons
|
|
4 from commons.core.parsing.GffParser import GffParser
|
|
5
|
|
6 class Test_F_GetExons(unittest.TestCase):
|
|
7
|
|
8 def setUp(self):
|
|
9 self._inputFileName = "inputFileTest.bed"
|
|
10 self._writeInputFile()
|
|
11 self._outputFileName = "output.gff3"
|
|
12
|
|
13 def tearDown(self):
|
|
14 os.remove(self._inputFileName)
|
|
15 os.remove(self._outputFileName)
|
|
16
|
|
17 def test_run_simple(self):
|
|
18 ge = GetExons(0)
|
|
19 ge.setInputFile(self._inputFileName, "bed")
|
|
20 ge.setOutputFile(self._outputFileName)
|
|
21 ge.run()
|
|
22 parser = GffParser(self._outputFileName, 0)
|
|
23 self.assertEqual(parser.getNbTranscripts(), 5)
|
|
24 for cpt, transcript in enumerate(parser.getIterator()):
|
|
25 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
26 self.assertEqual(transcript.getDirection(), 1)
|
|
27 self.assertEqual(transcript.getNbExons(), 1)
|
|
28 if cpt == 0:
|
|
29 self.assertEqual(transcript.getStart(), 10000001)
|
|
30 self.assertEqual(transcript.getEnd(), 10000100)
|
|
31 elif cpt == 1:
|
|
32 self.assertEqual(transcript.getStart(), 10000201)
|
|
33 self.assertEqual(transcript.getEnd(), 10000300)
|
|
34 elif cpt == 2:
|
|
35 self.assertEqual(transcript.getStart(), 10000401)
|
|
36 self.assertEqual(transcript.getEnd(), 10000500)
|
|
37 elif cpt == 3:
|
|
38 self.assertEqual(transcript.getStart(), 10000601)
|
|
39 self.assertEqual(transcript.getEnd(), 10000700)
|
|
40 elif cpt == 4:
|
|
41 self.assertEqual(transcript.getStart(), 10000801)
|
|
42 self.assertEqual(transcript.getEnd(), 10000900)
|
|
43
|
|
44 def test_run_firstExon(self):
|
|
45 ge = GetExons(0)
|
|
46 ge.setInputFile(self._inputFileName, "bed")
|
|
47 ge.setOutputFile(self._outputFileName)
|
|
48 ge.setSelection("1")
|
|
49 ge.run()
|
|
50 parser = GffParser(self._outputFileName, 0)
|
|
51 self.assertEqual(parser.getNbTranscripts(), 1)
|
|
52 for cpt, transcript in enumerate(parser.getIterator()):
|
|
53 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
54 self.assertEqual(transcript.getDirection(), 1)
|
|
55 self.assertEqual(transcript.getNbExons(), 1)
|
|
56 self.assertEqual(transcript.getStart(), 10000001)
|
|
57 self.assertEqual(transcript.getEnd(), 10000100)
|
|
58
|
|
59 def test_run_lastExon(self):
|
|
60 ge = GetExons(0)
|
|
61 ge.setInputFile(self._inputFileName, "bed")
|
|
62 ge.setOutputFile(self._outputFileName)
|
|
63 ge.setSelection("-1")
|
|
64 ge.run()
|
|
65 parser = GffParser(self._outputFileName, 0)
|
|
66 self.assertEqual(parser.getNbTranscripts(), 1)
|
|
67 for cpt, transcript in enumerate(parser.getIterator()):
|
|
68 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
69 self.assertEqual(transcript.getDirection(), 1)
|
|
70 self.assertEqual(transcript.getNbExons(), 1)
|
|
71 self.assertEqual(transcript.getStart(), 10000801)
|
|
72 self.assertEqual(transcript.getEnd(), 10000900)
|
|
73
|
|
74 def test_run_first_lastExon(self):
|
|
75 ge = GetExons(0)
|
|
76 ge.setInputFile(self._inputFileName, "bed")
|
|
77 ge.setOutputFile(self._outputFileName)
|
|
78 ge.setSelection("1,-1")
|
|
79 ge.run()
|
|
80 parser = GffParser(self._outputFileName, 0)
|
|
81 self.assertEqual(parser.getNbTranscripts(), 2)
|
|
82 for cpt, transcript in enumerate(parser.getIterator()):
|
|
83 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
84 self.assertEqual(transcript.getDirection(), 1)
|
|
85 self.assertEqual(transcript.getNbExons(), 1)
|
|
86 if cpt == 0:
|
|
87 self.assertEqual(transcript.getStart(), 10000001)
|
|
88 self.assertEqual(transcript.getEnd(), 10000100)
|
|
89 elif cpt == 1:
|
|
90 self.assertEqual(transcript.getStart(), 10000801)
|
|
91 self.assertEqual(transcript.getEnd(), 10000900)
|
|
92
|
|
93 def test_run_interval(self):
|
|
94 ge = GetExons(0)
|
|
95 ge.setInputFile(self._inputFileName, "bed")
|
|
96 ge.setOutputFile(self._outputFileName)
|
|
97 ge.setSelection("2..3")
|
|
98 ge.run()
|
|
99 parser = GffParser(self._outputFileName, 0)
|
|
100 self.assertEqual(parser.getNbTranscripts(), 2)
|
|
101 for cpt, transcript in enumerate(parser.getIterator()):
|
|
102 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
103 self.assertEqual(transcript.getDirection(), 1)
|
|
104 self.assertEqual(transcript.getNbExons(), 1)
|
|
105 if cpt == 0:
|
|
106 self.assertEqual(transcript.getStart(), 10000201)
|
|
107 self.assertEqual(transcript.getEnd(), 10000300)
|
|
108 elif cpt == 1:
|
|
109 self.assertEqual(transcript.getStart(), 10000401)
|
|
110 self.assertEqual(transcript.getEnd(), 10000500)
|
|
111
|
|
112 def test_run_interval_element(self):
|
|
113 ge = GetExons(0)
|
|
114 ge.setInputFile(self._inputFileName, "bed")
|
|
115 ge.setOutputFile(self._outputFileName)
|
|
116 ge.setSelection("2..3,-1")
|
|
117 ge.run()
|
|
118 parser = GffParser(self._outputFileName, 0)
|
|
119 self.assertEqual(parser.getNbTranscripts(), 3)
|
|
120 for cpt, transcript in enumerate(parser.getIterator()):
|
|
121 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
122 self.assertEqual(transcript.getDirection(), 1)
|
|
123 self.assertEqual(transcript.getNbExons(), 1)
|
|
124 if cpt == 0:
|
|
125 self.assertEqual(transcript.getStart(), 10000201)
|
|
126 self.assertEqual(transcript.getEnd(), 10000300)
|
|
127 elif cpt == 1:
|
|
128 self.assertEqual(transcript.getStart(), 10000401)
|
|
129 self.assertEqual(transcript.getEnd(), 10000500)
|
|
130 elif cpt == 2:
|
|
131 self.assertEqual(transcript.getStart(), 10000801)
|
|
132 self.assertEqual(transcript.getEnd(), 10000900)
|
|
133
|
|
134
|
|
135
|
|
136 def _writeInputFile(self):
|
|
137 f = open(self._inputFileName, "w")
|
|
138 f.write("arm_X\t10000001\t10000900\ttest1.1\t100\t+\t10000100\t10000200\t0\t5\t100,100,100,100,100,\t0,200,400,600,800,\n")
|
|
139 f.close()
|
|
140
|
|
141
|
|
142
|
|
143 if __name__ == "__main__":
|
|
144 unittest.main()
|
|
145
|