-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.py
195 lines (127 loc) · 5.23 KB
/
error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""A set of custom exception handling classes.
This module imports a custom module 'utilSeq'. They should come
together in one distribution.
Classes:
Error(Exception) --- base of all the custom error class.
ConcentrationZeroError(Error) --- raised when concentration is zero.
ConcentrationOrderError(Error) --- raised when concentration of primer
is lower than template.
TemperatureRangeError(Error) --- raised when temperature is out of range.
It should be [-100, 200]
#FolderError(Error) --- raised when a file folder does not exist.
#FileNotExistError(Error) --- raised when a file does not exist.
NNnotExistError(Error) --- raised when an nearest neighbor is not
supported.
NNFileNotFoundError(Error) ---raised when the nearest neighbor parameters
files not found.
NotDNAError(Error) --- raised when a duplex contains letters other than
A, C, G and T.
"""
import utilSeq
class Error(Exception):
"""Base class for all the custom error class."""
pass
class NotDNAError(Error):
"""Raised when a duplex contains letters other than A, C, G and T.
Attributes:
duplex : str --- a duplex
message : str --- explanation (Not DNA)
"""
def __init__(self, duplex):
"""constructor"""
msg1="The duplex contains letters other than A, C, G and T!"
self.message=f"\n***{msg1}***\n{duplex}"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"
class DuplexNotFlushError(Error):
"""Raised when a duplex is not flush.
Attributes:
duplex : str --- a duplex
message : str --- explanation (duplex is not flush)
"""
def __init__(self, duplex):
"""constructor"""
msg1="The two strands of the duplex should have same length!"
self.message=f"\n***{msg1}***\n{duplex}"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"
class ConcentrationZeroError(Error):
"""Raised when concentration is zero.
Attributes:
variable : str --- name of the variable
message : str --- explanation ('concentration should not be zero')
"""
def __init__(self, variable):
"""constructor
Parameters:
variable : str --- name of the variable
"""
self.variable=variable
self.message=f"\n***Concentration [{variable}] should not be zero!***"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"
class ConcentrationOrderError(Error):
"""Raised when concentration of primer is lower than template.
Attributes:
message : str --- explanation (primer concentration should be larger
than template)
"""
def __init__(self):
"""constructor"""
msg="Primer concentration should be larger than template!"
self.message=f"\n***{msg}***"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"
class TemperatureRangeError(Error):
"""Raised when temperature is out of range.
Attributes:
message : str --- explanation (the temperature range is [-100, 200])
"""
def __init__(self):
"""constructor"""
msg="Temperature should be between -100 C to 200 C!"
self.message=f"\n***{msg}***"
def __repr__(self):
"""__repr__"""
return f"{__class__.__name__}:{self.message}"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"
class NNnotExistError(Error):
""" Raised when an nearest neighbor is not supported.
Attributes:
nn : str --- nearest neighbor
top : str --- top strand in a duplex (5'->3')
bottom : str --- bottom strand in a duplex (3'->5')
message : str --- explanation (nn is not supported)
"""
def __init__(self, nn, top, bottom):
"""constructor"""
msg=utilSeq.matchUp(top, bottom)
msg1=f"The nearest neighbor '{nn}' is not supported!"
msg2=f"Nearest neighbor with two mismatches not allowed."
msg3='*********'
self.message=f"\n{msg}\n\n{msg3}\n{msg1}\n{msg2}\n{msg3}"
def __str__(self):
"""__str__"""
return self.message
class NNFileNotFoundError(Error):
"""Raised when the nearest neighbor parameter files not found.
Attribute:
message : str --- explanation (the nearest neighbor parameter files not found)
"""
def __init__(self):
"""constructor"""
msg="The nearest neighbor parameter files 'nnSH.csv' and 'nnSS.csv'"
msg+=" not found!\n"
msg+="They should be in a folder pointed to by the environment"
msg+=" variable 'NNDIR',\n"
msg+="or in the current working directory.\n"
self.message=f"\n***{msg}***"
def __str__(self):
"""__str__"""
return f"{__class__.__name__}:{self.message}"