annotate commons/pyRepetUnit/hmmer/check/test/Test_OldDetectFeaturesConfigChecker.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 unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import re
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from commons.pyRepetUnit.hmmer.check.OldDetectFeatureConfigChecker import DetectFeatureConfigChecker
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 from commons.core.checker.ConfigException import ConfigException
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 class Test_DetectFeaturesConfigChecker(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 self._detectFeatureConfigChecker = DetectFeatureConfigChecker()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 def testWithDefaultLogger (self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 lineFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 self._detectFeatureConfigChecker.check("dummyConfig")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 if (re.match("CONFIG FILE not found.*", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 lineFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 self.assertTrue(lineFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 def testWithNoConfigFile(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 lineFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 self._detectFeatureConfigChecker.check("dummyConfig")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 if (re.match("CONFIG FILE not found.*", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 lineFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 self.assertTrue(lineFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 def testWithNoSectionInConfigFile(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 config = open("config.cfg", "w");
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 config.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 lineFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 self._detectFeatureConfigChecker.check("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 if (re.match("\[detect_features\] section not found.*", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 lineFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 self.assertTrue(lineFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 os.remove("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 def testMissingOptionsInConfig (self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 dict = {}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 MockConfigFile("config.cfg", dict)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 hmmProfilsFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 TE_BLRnFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 try :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self._detectFeatureConfigChecker.check("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 if (re.match("\[detect_features\] - No option 'te_hmmer' in section: 'detect_features'", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 hmmProfilsFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 if (re.match("\[detect_features\] - No option 'te_blrn' in section: 'detect_features'", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 TE_BLRnFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 self.assertTrue(hmmProfilsFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 self.assertTrue(TE_BLRnFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 os.remove("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 def testOptionsIfHmmProfilsSetAtYESInConfig (self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 dict = {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 "TE_HMMER" : "yes",
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 "TE_BLRn" : "no"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 profilDatabankFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 evalueFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 MockConfigFile("config.cfg", dict)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 try :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 self._detectFeatureConfigChecker.check("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 print msg
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 if (re.match("\[detect_features\] - No option 'te_hmm_profiles' in section: 'detect_features' whereas te_hmmer is set", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 profilDatabankFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 if (re.match("\[detect_features\] - No option 'te_hmmer_evalue' in section: 'detect_features' whereas te_hmmer is set - Default value will be set", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 evalueFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 self.assertTrue(profilDatabankFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 self.assertTrue(evalueFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 os.remove("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 def testOptionsIfHmmProfilsSetAtNOInConfig (self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 profilDatabankFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 inputFormatFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 evalueFound = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 dict = {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 "TE_HMMER" : "no"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 MockConfigFile("config.cfg", dict)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 try :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 self._detectFeatureConfigChecker.check("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 except ConfigException, e:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 for msg in e.messages:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 if (re.match(".+INFO \[detect_features\] - No option 'te_hmm_profiles' in section: 'detect_features' whereas te_hmmer is set", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 profilDatabankFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 if (re.match(".+INFO \[detect_features\] - No option 'te_hmmer_evalue' in section: 'detect_features' whereas te_hmmer is set - Default value will be set", msg)):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 evalueFound = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 self.assertFalse(profilDatabankFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 self.assertFalse(inputFormatFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 self.assertFalse(evalueFound)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 os.remove("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 def testTE_BLRnAndTE_hmmerAtNoInConfig (self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 dict = {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 "TE_HMMER" : "no",
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 "TE_BLRn" : "no"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 exceptionNotRaised = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 MockConfigFile("config.cfg", dict)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 try :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 self._detectFeatureConfigChecker.check("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 except ConfigException:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 exceptionNotRaised = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 self.assertTrue(exceptionNotRaised)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 os.remove("config.cfg")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 class MockConfigFile:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 def __init__ (self, fileName, optionsDict):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 self._fileName = fileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 config = open(fileName, "w");
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131 config.write("[detect_features]\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 for key in optionsDict.keys():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 config.write(key + ":" + optionsDict[key] + "\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 config.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138 unittest.main()