18
|
1 import os
|
|
2 import unittest
|
|
3 from commons.pyRepetUnit.align.AlignList import AlignList
|
|
4 from commons.pyRepetUnit.align.AlignListUtils import AlignListUtils
|
|
5 from commons.core.utils.FileUtils import FileUtils
|
|
6 from commons.core.coord.Range import Range
|
|
7 from commons.core.coord.Align import Align
|
|
8
|
|
9 class Test_AlignListUtils (unittest.TestCase):
|
|
10
|
|
11 def setUp(self):
|
|
12 self.inputFileName = "dummyAlignFile.align"
|
|
13 self.outputFileName = "dummyAlignFile.out"
|
|
14
|
|
15 def testRead(self):
|
|
16 f = open(self.inputFileName, "w")
|
|
17 f.write("blumeria_Grouper_590_20:NoCat_1\t91\t108\tDUF234\t5\t22\t2.6e-60\t0\t3.2\n")
|
|
18 f.write("blumeria_Grouper_590_20:NoCat_1\t111\t119\tDUF1414\t1\t9\t6.3\t0\t2.9\n")
|
|
19 f.close()
|
|
20 alignRead = AlignListUtils()
|
|
21 tableauAlignInstance = alignRead.read(self.inputFileName)
|
|
22 self.assertEquals(tableauAlignInstance.get(0).range_query.seqname, "blumeria_Grouper_590_20:NoCat_1")
|
|
23 self.assertEquals(tableauAlignInstance.get(0).range_query.start, 91)
|
|
24 self.assertEquals(tableauAlignInstance.get(0).range_query.end, 108)
|
|
25 self.assertEquals(tableauAlignInstance.get(0).range_subject.seqname, "DUF234")
|
|
26 self.assertEquals(tableauAlignInstance.get(0).range_subject.start, 5)
|
|
27 self.assertEquals(tableauAlignInstance.get(0).range_subject.end, 22)
|
|
28 self.assertEquals(tableauAlignInstance.get(0).e_value, 2.6e-60)
|
|
29 self.assertEquals(tableauAlignInstance.get(0).score, 0)
|
|
30 self.assertEquals(tableauAlignInstance.get(0).identity, 3.2)
|
|
31 self.assertEquals(tableauAlignInstance.get(1).range_query.seqname, "blumeria_Grouper_590_20:NoCat_1")
|
|
32 self.assertEquals(tableauAlignInstance.get(1).range_query.start, 111)
|
|
33 self.assertEquals(tableauAlignInstance.get(1).range_query.end, 119)
|
|
34 self.assertEquals(tableauAlignInstance.get(1).range_subject.seqname, "DUF1414")
|
|
35 self.assertEquals(tableauAlignInstance.get(1).range_subject.start, 1)
|
|
36 self.assertEquals(tableauAlignInstance.get(1).range_subject.end, 9)
|
|
37 self.assertEquals(tableauAlignInstance.get(1).e_value, 6.3)
|
|
38 self.assertEquals(tableauAlignInstance.get(1).score, 0)
|
|
39 self.assertEquals(tableauAlignInstance.get(1).identity, 2.9)
|
|
40 os.system("rm " + self.inputFileName)
|
|
41
|
|
42 def testWrite(self):
|
|
43 f = open("expectedAlignFile.align", "w")
|
|
44 f.write("biduleChouetteQuery\t20\t55\tbiduleChouetteSubject\t2\t15\t0.005\t20\t0.000000\n")
|
|
45 f.write("trucBiduleQuery\t110\t155\ttrucBiduleSubject\t1\t35\t2\t1\t0.000000\n")
|
|
46 f.write("dummyQuery\t1\t65\tdummySubject\t1\t25\t2.6e-60\t50\t0.000000\n")
|
|
47 f.close()
|
|
48 listAlignInstance = AlignList()
|
|
49 align1 = Align()
|
|
50 align1.range_query = Range("biduleChouetteQuery", 20, 55)
|
|
51 align1.range_subject = Range("biduleChouetteSubject", 2, 15)
|
|
52 align1.e_value = 0.005
|
|
53 align1.score = 20
|
|
54 listAlignInstance.append(align1)
|
|
55 align2 = Align()
|
|
56 align2.range_query = Range("trucBiduleQuery", 110, 155)
|
|
57 align2.range_subject = Range("trucBiduleSubject", 1, 35)
|
|
58 align2.e_value = 2
|
|
59 align2.score = 1.5
|
|
60 listAlignInstance.append(align2)
|
|
61 align3 = Align()
|
|
62 align3.range_query = Range("dummyQuery", 1, 65)
|
|
63 align3.range_subject = Range("dummySubject", 1, 25)
|
|
64 align3.e_value = 2.6e-60
|
|
65 align3.score = 50
|
|
66 listAlignInstance.append(align3)
|
|
67 f = open(self.outputFileName, "w")
|
|
68 alignUtils = AlignListUtils()
|
|
69 alignUtils.write(listAlignInstance, self.outputFileName)
|
|
70 self.assertTrue(FileUtils.are2FilesIdentical(self.outputFileName, "expectedAlignFile.align"))
|
|
71 os.system("rm " + self.outputFileName)
|
|
72 os.system("rm expectedAlignFile.align")
|
|
73
|
|
74 def testFilterOnAMinimalScore(self):
|
|
75 listAlignInstance = AlignList()
|
|
76 align1 = Align()
|
|
77 align1.range_query = Range("biduleChouetteQuery", 20, 55)
|
|
78 align1.range_subject = Range("biduleChouetteSubject", 2, 15)
|
|
79 align1.e_value = 5
|
|
80 align1.score = -0.5
|
|
81 listAlignInstance.append(align1)
|
|
82 align2 = Align()
|
|
83 align2.range_query = Range("trucBiduleQuery", 110, 155)
|
|
84 align2.range_subject = Range("trucBiduleSubject", 1, 35)
|
|
85 align2.e_value = 2
|
|
86 align2.score = -2.0
|
|
87 listAlignInstance.append(align2)
|
|
88 align3 = Align()
|
|
89 align3.range_query = Range("dummyQuery", 1, 65)
|
|
90 align3.range_subject = Range("dummySubject", 1, 25)
|
|
91 align3.e_value = 2.6e-60
|
|
92 align3.score = 50
|
|
93 listAlignInstance.append(align3)
|
|
94 expectedAlignInstance = align3
|
|
95 alignUtils = AlignListUtils()
|
|
96 alignUtils.filterOnAMinimalScore(listAlignInstance, 0)
|
|
97 self.assertEquals(listAlignInstance.get(0), expectedAlignInstance)
|
|
98
|
|
99 if __name__ == "__main__" :
|
|
100 unittest.main() |