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