6
|
1 from commons.core.writer.MySqlTranscriptWriter import MySqlTranscriptWriter
|
|
2 from SMART.Java.Python.structure.TranscriptContainer import TranscriptContainer
|
|
3 from SMART.Java.Python.structure.Transcript import Transcript
|
|
4 from SMART.Java.Python.structure.Interval import Interval
|
|
5 from SMART.Java.Python.mySql.MySqlConnection import MySqlConnection
|
|
6 from SMART.Java.Python.mySql.MySqlTranscriptTable import MySqlTranscriptTable
|
|
7 import unittest
|
|
8
|
|
9
|
|
10 class Test_MySqlTranscriptTable(unittest.TestCase):
|
|
11
|
|
12 def test_getRange(self):
|
|
13 transcript = Transcript()
|
|
14 transcript.setName("test1.1")
|
|
15 transcript.setChromosome("arm_X")
|
|
16 transcript.setStart(1000)
|
|
17 transcript.setEnd(4000)
|
|
18 transcript.setSize(2000)
|
|
19 transcript.setDirection("+")
|
|
20
|
|
21 exon1 = Interval()
|
|
22 exon1.setName("test1.1")
|
|
23 exon1.setChromosome("arm_X")
|
|
24 exon1.setStart(1000)
|
|
25 exon1.setEnd(2000)
|
|
26 exon1.setSize(1000)
|
|
27
|
|
28 exon2 = Interval()
|
|
29 exon2.setName("test1.1")
|
|
30 exon2.setChromosome("arm_X")
|
|
31 exon2.setStart(3000)
|
|
32 exon2.setEnd(4000)
|
|
33 exon2.setSize(1000)
|
|
34
|
|
35 transcript.addExon(exon1)
|
|
36 transcript.addExon(exon2)
|
|
37
|
|
38 connection = MySqlConnection()
|
|
39 writer = MySqlTranscriptWriter(connection, "testMySqlTranscriptTableGetRange")
|
|
40 writer.addTranscript(transcript)
|
|
41 writer.write()
|
|
42
|
|
43 transcriptContainer = TranscriptContainer("testMySqlTranscriptTableGetRange", "sql")
|
|
44 transcriptContainer.mySqlConnection = connection
|
|
45 self.assertEqual(transcriptContainer.getNbTranscripts(), 1)
|
|
46 for transcript in transcriptContainer.getIterator():
|
|
47 self.assertEqual(transcript.getName(), "test1.1")
|
|
48 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
49 self.assertEqual(transcript.getStart(), 1000)
|
|
50 self.assertEqual(transcript.getEnd(), 4000)
|
|
51 self.assertEqual(transcript.getSize(), 2002)
|
|
52 self.assertEqual(transcript.getNbExons(), 2)
|
|
53 exons = transcript.getExons()
|
|
54 self.assertEqual(exons[0].getStart(), 1000)
|
|
55 self.assertEqual(exons[0].getEnd(), 2000)
|
|
56 self.assertEqual(exons[1].getStart(), 3000)
|
|
57 self.assertEqual(exons[1].getEnd(), 4000)
|
|
58
|
|
59
|
|
60 def test_setDefaultTagValue(self):
|
|
61 transcript1 = Transcript()
|
|
62 transcript1.setName("test1.1")
|
|
63 transcript1.setChromosome("arm_X")
|
|
64 transcript1.setStart(1000)
|
|
65 transcript1.setEnd(2000)
|
|
66 transcript1.setDirection("+")
|
|
67
|
|
68 exon1 = Interval()
|
|
69 exon1.setName("test1.1")
|
|
70 exon1.setChromosome("arm_X")
|
|
71 exon1.setStart(1000)
|
|
72 exon1.setEnd(2000)
|
|
73
|
|
74 transcript1.addExon(exon1)
|
|
75
|
|
76 transcript2 = Transcript()
|
|
77 transcript2.setName("test2.1")
|
|
78 transcript2.setChromosome("arm_X")
|
|
79 transcript2.setStart(1000)
|
|
80 transcript2.setEnd(2000)
|
|
81 transcript2.setDirection("+")
|
|
82 transcript2.setTagValue("nbOccurrences", "2")
|
|
83
|
|
84 exon2 = Interval()
|
|
85 exon2.setName("test2.1")
|
|
86 exon2.setChromosome("arm_X")
|
|
87 exon2.setStart(1000)
|
|
88 exon2.setEnd(2000)
|
|
89
|
|
90 transcript2.addExon(exon2)
|
|
91
|
|
92 transcript3 = Transcript()
|
|
93 transcript3.setName("test3.1")
|
|
94 transcript3.setChromosome("arm_X")
|
|
95 transcript3.setStart(1000)
|
|
96 transcript3.setEnd(2000)
|
|
97 transcript3.setDirection("+")
|
|
98 transcript3.setTagValue("occurrences", "2")
|
|
99
|
|
100 exon3 = Interval()
|
|
101 exon3.setName("test3.1")
|
|
102 exon3.setChromosome("arm_X")
|
|
103 exon3.setStart(1000)
|
|
104 exon3.setEnd(2000)
|
|
105
|
|
106 transcript3.addExon(exon3)
|
|
107
|
|
108 connection = MySqlConnection()
|
|
109 table = MySqlTranscriptTable(connection, "testMySqlTranscriptTableSetDefaultTagValue")
|
|
110 table.createTranscriptTable()
|
|
111 table.addTranscript(transcript1)
|
|
112 table.addTranscript(transcript2)
|
|
113 table.addTranscript(transcript3)
|
|
114 table.setDefaultTagValue("occurrence", "1")
|
|
115
|
|
116 cpt = 0
|
|
117 for transcript in table.getIterator():
|
|
118 cpt += 1
|
|
119 self.assert_(cpt != 4)
|
|
120 if cpt == 1:
|
|
121 self.assertEqual(transcript.name, "test1.1")
|
|
122 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
123 self.assertEqual(transcript.getStart(), 1000)
|
|
124 self.assertEqual(transcript.getEnd(), 2000)
|
|
125 self.assertEqual(transcript.getSize(), 1001)
|
|
126 self.assertEqual(transcript.getNbExons(), 1)
|
|
127 exons = transcript.getExons()
|
|
128 self.assertEqual(exons[0].getStart(), 1000)
|
|
129 self.assertEqual(exons[0].getEnd(), 2000)
|
|
130 self.assertEqual(transcript.getTagValue("occurrence"), 1)
|
|
131 elif cpt == 2:
|
|
132 self.assertEqual(transcript.name, "test2.1")
|
|
133 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
134 self.assertEqual(transcript.getStart(), 1000)
|
|
135 self.assertEqual(transcript.getEnd(), 2000)
|
|
136 self.assertEqual(transcript.getSize(), 1001)
|
|
137 self.assertEqual(transcript.getNbExons(), 1)
|
|
138 exons = transcript.getExons()
|
|
139 self.assertEqual(exons[0].getStart(), 1000)
|
|
140 self.assertEqual(exons[0].getEnd(), 2000)
|
|
141 self.assertEqual(transcript.getTagValue("nbOccurrences"), 2)
|
|
142 self.assertEqual(transcript.getTagValue("occurrence"), 1)
|
|
143 elif cpt == 2:
|
|
144 self.assertEqual(transcript.name, "test3.1")
|
|
145 self.assertEqual(transcript.getChromosome(), "arm_X")
|
|
146 self.assertEqual(transcript.getStart(), 1000)
|
|
147 self.assertEqual(transcript.getEnd(), 2000)
|
|
148 self.assertEqual(transcript.getSize(), 1001)
|
|
149 self.assertEqual(transcript.getNbExons(), 1)
|
|
150 exons = transcript.getExons()
|
|
151 self.assertEqual(exons[0].getStart(), 1000)
|
|
152 self.assertEqual(exons[0].getEnd(), 2000)
|
|
153 self.assertEqual(transcript.getTagValue("occurrence"), 2)
|
|
154
|
|
155 table.remove()
|
|
156
|
|
157 if __name__ == '__main__':
|
|
158 unittest.main()
|