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