comparison commons/pyRepetUnit/convCoord/test/Test_ConvMapChr2Chunk.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
comparison
equal deleted inserted replaced
30:5677346472b5 31:0ab839023fe4
1 from commons.core.sql.DbFactory import DbFactory
2 from commons.core.utils.FileUtils import FileUtils
3 from commons.pyRepetUnit.convCoord.ConvMapChr2Chunk import ConvMapChr2Chunk
4 import unittest
5 import os
6
7 class Test_ConvMapChr2Chunk(unittest.TestCase):
8
9 def setUp(self):
10 self._mapfilename="dummy.map"
11 self._maptablename="dummy_map"
12
13 self._chunkmapfilename="chunk.map"
14 self._chunkmaptable="test_chunk_map"
15
16 self._resfilename="dummy_res.map"
17
18 map4convData="chunk1\tchr1\t1\t100\n"
19 map4convData+="chunk2\tchr1\t90\t200\n"
20 map4convData+="chunk3\tchr1\t190\t300\n"
21
22 map4conv=open(self._chunkmapfilename,"w")
23 map4conv.write(map4convData)
24 map4conv.close()
25
26 self._db = DbFactory.createInstance()
27 self._db.createTable(self._chunkmaptable, "map", self._chunkmapfilename, True)
28
29 map2convData="reg1\tchr1\t10\t80\n"
30 map2convData+="reg1\tchr1\t90\t110\n"
31 map2convData+="reg2\tchr1\t150\t160\n"
32
33 map2convData+="reg3\tchr1\t70\t210\n"
34 map2convData+="reg4\tchr1\t85\t100\n"
35 map2convData+="reg5\tchr1\t85\t110\n"
36
37 map2convData+="reg6\tchr1\t80\t10\n"
38 map2convData+="reg6\tchr1\t110\t90\n"
39 map2convData+="reg7\tchr1\t160\t150\n"
40 map2convData+="reg8\tchr1\t190\t300\n"
41
42 map2convData+="reg9\tchr1\t210\t70\n"
43 map2convData+="reg10\tchr1\t100\t85\n"
44 map2convData+="reg11\tchr1\t110\t85\n"
45 map2convData+="reg12\tchr1\t300\t190\n"
46
47 map2conv=open(self._mapfilename,"w")
48 map2conv.write(map2convData)
49 map2conv.close()
50
51 self._db.createTable(self._maptablename, "map", self._mapfilename, True)
52
53 mapResData="reg1\tchunk1\t10\t80\n"
54 mapResData+="reg1\tchunk1\t90\t100\n"
55 mapResData+="reg1\tchunk2\t1\t21\n"
56 mapResData+="reg2\tchunk2\t61\t71\n"
57
58 mapResData+="reg3\tchunk1\t70\t100\n"
59 mapResData+="reg3\tchunk2\t1\t111\n"
60 mapResData+="reg3\tchunk3\t1\t21\n"
61
62 mapResData+="reg4\tchunk1\t85\t100\n"
63 mapResData+="reg4\tchunk2\t1\t11\n"
64 mapResData+="reg5\tchunk1\t85\t100\n"
65 mapResData+="reg5\tchunk2\t1\t21\n"
66
67 mapResData+="reg6\tchunk1\t80\t10\n"
68 mapResData+="reg6\tchunk1\t100\t90\n"
69 mapResData+="reg6\tchunk2\t21\t1\n"
70 mapResData+="reg7\tchunk2\t71\t61\n"
71 mapResData+="reg8\tchunk2\t101\t111\n"
72 mapResData+="reg8\tchunk3\t1\t111\n"
73
74 mapResData+="reg9\tchunk1\t100\t70\n"
75 mapResData+="reg9\tchunk2\t111\t1\n"
76 mapResData+="reg9\tchunk3\t21\t1\n"
77
78 mapResData+="reg10\tchunk1\t100\t85\n"
79 mapResData+="reg10\tchunk2\t11\t1\n"
80 mapResData+="reg11\tchunk1\t100\t85\n"
81 mapResData+="reg11\tchunk2\t21\t1\n"
82 mapResData+="reg12\tchunk2\t111\t101\n"
83 mapResData+="reg12\tchunk3\t111\t1\n"
84
85 mapRes=open(self._resfilename,"w")
86 mapRes.write(mapResData)
87 mapRes.close()
88
89 def tearDown(self):
90 self._db.dropTable(self._chunkmaptable)
91 self._db.dropTable(self._maptablename)
92 self._db.close()
93 os.remove(self._resfilename)
94 os.remove(self._mapfilename)
95 os.remove(self._chunkmapfilename)
96
97 def test_convert(self):
98 conv = ConvMapChr2Chunk(self._db,self._maptablename, self._chunkmaptable, self._maptablename+"_onchk")
99 conv.convert()
100 obsFileName = "dummy_map.onchk"
101 self._db.exportDataToFile("dummy_map_onchk", obsFileName)
102 self._db.dropTable("dummy_map_onchk")
103 self.assertTrue(FileUtils.are2FilesIdentical(self._resfilename, obsFileName))
104 os.remove(obsFileName)
105
106 test_suite = unittest.TestSuite()
107 test_suite.addTest( unittest.makeSuite( Test_ConvMapChr2Chunk ) )
108 if __name__ == '__main__':
109 unittest.TextTestRunner(verbosity=2).run( test_suite )