annotate commons/pyRepetUnit/convCoord/test/Test_ConvSetChr2Chunk.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 from commons.core.sql.DbFactory import DbFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 from commons.pyRepetUnit.convCoord.ConvSetChr2Chunk import ConvSetChr2Chunk
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 import unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 class Test_ConvSetChr2Chunk(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 self._setfilename="dummy.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 self._settablename="dummy_set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._chunkmapfilename="chunk.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._chunkmaptable="test_chunk_map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 self._resfilename="dummy_res.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 map4convData="chunk1\tchr1\t1\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 map4convData+="chunk2\tchr1\t90\t200\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 map4convData+="chunk3\tchr1\t190\t300\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 map4conv=open(self._chunkmapfilename,"w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 map4conv.write(map4convData)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 map4conv.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 self._db = DbFactory.createInstance()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 self._db.createTable(self._chunkmaptable, "map", self._chunkmapfilename, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 set2convData="1\treg1\tchr1\t10\t80\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 set2convData+="1\treg1\tchr1\t90\t110\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 set2convData+="2\treg2\tchr1\t150\t160\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 set2convData+="3\treg3\tchr1\t70\t210\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 set2convData+="4\treg4\tchr1\t85\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 set2convData+="5\treg5\tchr1\t85\t110\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 set2convData+="6\treg6\tchr1\t80\t10\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 set2convData+="6\treg6\tchr1\t110\t90\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 set2convData+="7\treg7\tchr1\t160\t150\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 set2convData+="8\treg8\tchr1\t190\t300\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 set2convData+="9\treg9\tchr1\t210\t70\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 set2convData+="10\treg10\tchr1\t100\t85\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 set2convData+="11\treg11\tchr1\t110\t85\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 set2convData+="12\treg12\tchr1\t300\t190\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 set2conv=open(self._setfilename,"w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 set2conv.write(set2convData)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 set2conv.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self._db.createTable(self._settablename, "set", self._setfilename, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 setResData="1\treg1\tchunk1\t10\t80\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 setResData+="1\treg1\tchunk1\t90\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 setResData+="1\treg1\tchunk2\t1\t21\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 setResData+="2\treg2\tchunk2\t61\t71\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 setResData+="3\treg3\tchunk1\t70\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 setResData+="3\treg3\tchunk2\t1\t111\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 setResData+="3\treg3\tchunk3\t1\t21\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 setResData+="4\treg4\tchunk1\t85\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 setResData+="4\treg4\tchunk2\t1\t11\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 setResData+="5\treg5\tchunk1\t85\t100\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 setResData+="5\treg5\tchunk2\t1\t21\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 setResData+="6\treg6\tchunk1\t80\t10\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 setResData+="6\treg6\tchunk1\t100\t90\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 setResData+="6\treg6\tchunk2\t21\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 setResData+="7\treg7\tchunk2\t71\t61\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 setResData+="8\treg8\tchunk2\t101\t111\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 setResData+="8\treg8\tchunk3\t1\t111\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 setResData+="9\treg9\tchunk1\t100\t70\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 setResData+="9\treg9\tchunk2\t111\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 setResData+="9\treg9\tchunk3\t21\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 setResData+="10\treg10\tchunk1\t100\t85\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 setResData+="10\treg10\tchunk2\t11\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 setResData+="11\treg11\tchunk1\t100\t85\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 setResData+="11\treg11\tchunk2\t21\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 setResData+="12\treg12\tchunk2\t111\t101\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 setResData+="12\treg12\tchunk3\t111\t1\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 setRes=open(self._resfilename,"w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 setRes.write(setResData)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 setRes.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 self._db.dropTable(self._chunkmaptable)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 self._db.dropTable(self._settablename)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 self._db.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 os.remove(self._resfilename)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 os.remove(self._setfilename)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 os.remove(self._chunkmapfilename)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 def test_convert(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 conv = ConvSetChr2Chunk(self._db,self._settablename, self._chunkmaptable, self._settablename+"_onchk")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 conv.convert()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 obsFileName = "dummy_set.onchk"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 self._db.exportDataToFile("dummy_set_onchk", obsFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 self._db.dropTable("dummy_set_onchk")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 self.assertTrue(FileUtils.are2FilesIdentical(self._resfilename, obsFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 os.remove(obsFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 test_suite = unittest.TestSuite()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 test_suite.addTest( unittest.makeSuite( Test_ConvSetChr2Chunk ) )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 if __name__ == '__main__':
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 unittest.TextTestRunner(verbosity=2).run( test_suite )