annotate SMART/Java/Python/test/Test_FindOverlaps_optim.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 import unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 from SMART.Java.Python.FindOverlapsOptim import FindOverlapsOptim
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from SMART.Java.Python.ncList.test.MockFindOverlapsWithSeveralIntervals import *
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 class Test_FindOverlaps_optim(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 self._inputRefGff3FileName = 'sorted_Ref.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 iMock = MockFindOverlapsWithServeralIntervals_case1()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 iMock.write(self._inputRefGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 self._inputQueryGff3FileName = 'sorted_Query.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._writeQueryGff3File(self._inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._outputGff3FileName = 'overlaps.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 self._iFOO = FindOverlaps_optim(self._inputRefGff3FileName, self._inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 self._iFOO.prepareIntermediateFiles_sorted()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 self._iFOO.setOutputGff3FileName(self._outputGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 os.remove(self._inputRefGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 os.remove(self._inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 os.remove(self._outputGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 self._iFOO.deletIntermediateFiles()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 def test_isOverlapping_true(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 queryGff3Addr = 116
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 RefGff3Addr = 231
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 obs = self._iFOO.isOverlapping(queryGff3Addr, RefGff3Addr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 exp = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 self.assertEquals(exp, obs)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 def test_isOverlapping_false_left(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 queryGff3Addr = 116
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 RefGff3Addr = 58
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 obs = self._iFOO.isOverlapping(queryGff3Addr, RefGff3Addr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 exp = -1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 self.assertEquals(exp, obs)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 def test_isOverlapping_false_right(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 queryGff3Addr = 116
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 RefGff3Addr = 347
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 obs = self._iFOO.isOverlapping(queryGff3Addr, RefGff3Addr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 exp = 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 self.assertEquals(exp, obs)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 def test_getHisFirstChild(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 firstRefLAddr = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 obsFirstChildLAddr = self._iFOO.getHisFirstChild(firstRefLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 expFirstChildLAddr = 48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 self.assertEquals(expFirstChildLAddr, obsFirstChildLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 def test_isLastElement_true(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 refLAddr = 96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 obsBool = self._iFOO.isLastElement(refLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 expBool = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 self.assertEquals(expBool, obsBool)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 def test_isLastElement_false(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 refLAddr = 72
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 obsBool = self._iFOO.isLastElement(refLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 expBool = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 self.assertEquals(expBool, obsBool)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 def test_isLastElement_highestLevel_true(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 refLAddr = 24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 obsBool = self._iFOO.isLastElement(refLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 expBool = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 self.assertEquals(expBool, obsBool)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 def test_isLastElement_highestLevel_false(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 refLAddr = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 obsBool = self._iFOO.isLastElement(refLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 expBool = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 self.assertEquals(expBool, obsBool)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 def test_findOverlapIter(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 queryGff3Addr = 175
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 firstRefLAddr = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 done = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 obsFirstOverlapLAddr = self._iFOO.findOverlapIter(queryGff3Addr, firstRefLAddr, done)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 expFirstOverlapLAddr = 96, True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 self.assertEquals(expFirstOverlapLAddr, obsFirstOverlapLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 def test_not_findOverlapIter(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 queryGff3Addr = 295
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 firstRefLAddr = 24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 done = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 obsFirstOverlapLAddr = self._iFOO.findOverlapIter(queryGff3Addr, firstRefLAddr, done)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 expFirstOverlapLAddr = None, False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 self.assertEquals(expFirstOverlapLAddr, obsFirstOverlapLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 def test_findOverlapIter_not_the_first_RefOverlap(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 queryGff3Addr = 235
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 firstRefLAddr = 96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 done = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 obsFirstOverlapLAddr = self._iFOO.findOverlapIter(queryGff3Addr, firstRefLAddr, done)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 expFirstOverlapLAddr = 24, False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 self.assertEquals(expFirstOverlapLAddr, obsFirstOverlapLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 def test_changeToNewSubEndLAddr(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 firstChildLAddr = 48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 subEndLAddr = 48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 expSubEndLAddr = 120
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 obsSubEndLAddr = self._iFOO.changeToNewSubEndLAddr(firstChildLAddr, subEndLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 self.assertEquals(expSubEndLAddr, obsSubEndLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 def test_defineSubEndLaddr(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 parentLAddr = -1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 expSubEndLAddr = 48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 obsSubEndLAddr = self._iFOO.defineSubEndLaddr(parentLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 self.assertEquals(expSubEndLAddr, obsSubEndLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 def test_getNextRefIntervalInCaseNotOverLap(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 firstRefLAddr = 96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 expRefLAddr = 24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 obsRefLAddr = self._iFOO.getNext(firstRefLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 self.assertEquals(expRefLAddr, obsRefLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 def test_not_findOverlapIter_between2RefIntervals(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 inputQueryGff3FileName = 'query2.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 self._writeQueryGff3File2(inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 self._iFOO.setQueryGff3FileName(inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 queryGff3Addr = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 firstRefLAddr = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126 done = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 obsFirstOverlapLAddr = self._iFOO.findOverlapIter(queryGff3Addr, firstRefLAddr, done)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 expFirstOverlapLAddr = 24, False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 self.assertEquals(expFirstOverlapLAddr, obsFirstOverlapLAddr)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 os.remove(inputQueryGff3FileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 def _writeQueryGff3File2(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 f = open(fileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 f.write("chr1\tquery\ttest1\t1100\t1150\t126\t+\t.\tID=test1.1;Name=test1.1\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135 f.write("chr1\tquery\ttest2\t1250\t1300\t781\t+\t.\tID=test1.2;Name=test1.2\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138 def _writeQueryGff3File(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
139 f = open(fileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
140 f.write("chr1\tquery\ttest1.1\t25\t150\t126\t+\t.\tID=test1.1;Name=test1.1\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
141 f.write("chr1\tquery\ttest1.2\t70\t850\t781\t+\t.\tID=test1.2;Name=test1.2\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
142 f.write("chr1\tquery\ttest1.3\t550\t850\t201\t+\t.\tID=test1.3;Name=test1.3\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
143 f.write("chr1\tquery\ttest1.4\t925\t1025\t101\t+\t.\tID=test1.4;Name=test1.4\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
144 f.write("chr1\tquery\ttest1.5\t1201\t1210\t10\t+\t.\tID=test1.5;Name=test1.5\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
145 f.write("chr1\tquery\ttest1.6\t1500\t1600\t101\t+\t.\tID=test1.6;Name=test1.6\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
146 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
147
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
148 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
149 unittest.main()