annotate SMART/Java/Python/mySql/test/Test_MySqlTranscriptTable.py @ 16:6135c3075bc5

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