18
|
1 from commons.core.utils.FileUtils import FileUtils
|
|
2 from commons.core.sql.DbFactory import DbFactory
|
|
3 from commons.pyRepetUnit.convCoord.ConvPathChr2Chunk import ConvPathChr2Chunk
|
|
4 import unittest
|
|
5 import os
|
|
6
|
|
7 class Test_ConvPathChr2Chunk(unittest.TestCase):
|
|
8
|
|
9 def setUp(self):
|
|
10 self._pathfilename="dummy.path"
|
|
11 self._pathtablename="dummy_path"
|
|
12
|
|
13 self._chunkmapfilename="chunk.map"
|
|
14 self._chunkmaptable="test_chunk_map"
|
|
15
|
|
16 self._resfilename="dummy_res.path"
|
|
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 path2convData="1\tchr1\t10\t80\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
30 path2convData+="1\tchr1\t90\t110\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
31 path2convData+="2\tchr1\t150\t160\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
32
|
|
33 path2convData+="3\tchr1\t70\t210\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
34 path2convData+="4\tchr1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
35 path2convData+="5\tchr1\t85\t110\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
36
|
|
37 path2convData+="6\tchr1\t10\t80\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
38 path2convData+="6\tchr1\t90\t110\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
39 path2convData+="7\tchr1\t150\t160\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
40 path2convData+="8\tchr1\t190\t300\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
41
|
|
42 path2convData+="9\tchr1\t70\t210\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
43 path2convData+="10\tchr1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
44 path2convData+="11\tchr1\t85\t110\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
45 path2convData+="12\tchr1\t190\t300\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
46
|
|
47 path2conv=open(self._pathfilename,"w")
|
|
48 path2conv.write(path2convData)
|
|
49 path2conv.close()
|
|
50
|
|
51 self._db.createTable(self._pathtablename, "path", self._pathfilename)
|
|
52
|
|
53 pathResData="1\tchunk1\t10\t80\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
54 pathResData+="1\tchunk1\t90\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
55 pathResData+="1\tchunk2\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
56 pathResData+="2\tchunk2\t61\t71\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
57
|
|
58 pathResData+="3\tchunk1\t70\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
59 pathResData+="3\tchunk2\t1\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
60 pathResData+="3\tchunk3\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
61
|
|
62 pathResData+="4\tchunk1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
63 pathResData+="4\tchunk2\t1\t11\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
64 pathResData+="5\tchunk1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
65 pathResData+="5\tchunk2\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
66
|
|
67 pathResData+="6\tchunk1\t10\t80\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
68 pathResData+="6\tchunk1\t90\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
69 pathResData+="6\tchunk2\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
70 pathResData+="7\tchunk2\t61\t71\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
71 pathResData+="8\tchunk2\t101\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
72 pathResData+="8\tchunk3\t1\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
73
|
|
74 pathResData+="9\tchunk1\t70\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
75 pathResData+="9\tchunk2\t1\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
76 pathResData+="9\tchunk3\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
77
|
|
78 pathResData+="10\tchunk1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
79 pathResData+="10\tchunk2\t1\t11\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
80 pathResData+="11\tchunk1\t85\t100\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
81 pathResData+="11\tchunk2\t1\t21\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
82 pathResData+="12\tchunk2\t101\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
83 pathResData+="12\tchunk3\t1\t111\tsub1\t10\t50\t0.01\t1000\t99\n"
|
|
84
|
|
85 pathRes=open(self._resfilename,"w")
|
|
86 pathRes.write(pathResData)
|
|
87 pathRes.close()
|
|
88
|
|
89 def tearDown(self):
|
|
90 self._db.dropTable(self._chunkmaptable)
|
|
91 self._db.dropTable(self._pathtablename)
|
|
92 self._db.close()
|
|
93 os.remove(self._resfilename)
|
|
94 os.remove(self._pathfilename)
|
|
95 os.remove(self._chunkmapfilename)
|
|
96
|
|
97 def test_convert(self):
|
|
98 conv=ConvPathChr2Chunk(self._db,self._pathtablename, self._chunkmaptable, self._pathtablename+"_onchk")
|
|
99 conv.convert()
|
|
100 expPath = self._resfilename
|
|
101 obsPath = "dummy_path.onchk"
|
|
102 self._db.exportDataToFile("dummy_path_onchk", obsPath)
|
|
103 self._db.dropTable("dummy_path_onchk")
|
|
104 self.assertTrue(FileUtils.are2FilesIdentical(expPath, obsPath))
|
|
105 os.remove(obsPath)
|
|
106
|
|
107 test_suite = unittest.TestSuite()
|
|
108 test_suite.addTest( unittest.makeSuite( Test_ConvPathChr2Chunk ) )
|
|
109 if __name__ == '__main__':
|
|
110 unittest.TextTestRunner(verbosity=2).run( test_suite ) |