1 """CalculatePiMwInTwoDiPage by [yong27].
2 It requires SimpleRegressionAnalysis.py in BioinfoSarangNet
3 """
4 import unittest, math
5 from SimpleRegressionAnalysis import SimpleRegressionAnalyzer
6
7 class PiRegressCalculator(SimpleRegressionAnalyzer):
8 """Regression model y = a + bx
9 y is pI value and x is coord
10 """
11 pass
12
13 class MwRegressCalculator(SimpleRegressionAnalyzer):
14 """Regression model logy = a + bx
15 y is Mw value and x is coord
16 """
17 def setData(self, aTwoTupleList):
18 loggedData =[]
19 for eachCoord, eachMw in aTwoTupleList:
20 loggedData.append((eachCoord, math.log(eachMw)))
21 SimpleRegressionAnalyzer.setData(self, loggedData)
22 def getValue(self, aCoord):
23 return math.exp(self.a + self.b * aCoord)
24
25
26 class RegressCalculatorTest(unittest.TestCase):
27 def testPi(self):
28 prc = PiRegressCalculator()
29 prc.setData([(100, 4.0),(200,5.0)])
30 self.assertEquals(6.0, prc.getValue(300))
31 self.assertEquals(7.0, prc.getValue(400))
32 def testMw(self):
33 mrc = MwRegressCalculator()
34 mrc.setData([(100, 100000),(200, 10000)])
35 self.assertEquals(1000.0000000000016, mrc.getValue(300))
36 self.assertEquals(100.00000000000023, mrc.getValue(400))
37
38
39 if __name__=='__main__':
40 unittest.main(argv=('','-v'))