-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.py
45 lines (33 loc) · 1.57 KB
/
exceptions.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
from constants import DNA_ALPHABET, RNA_ALPHABET, RNA_CODON_TABLE
SIGNS = ('<', '>', '<=', '>=', '=')
class InvalidSignError(Exception):
def __init__(self, sign, message=None):
if message is None:
message = f'Your sign = {sign} must be one of {SIGNS}!'
super().__init__(message)
class IterableLengthError(Exception):
def __init__(self, iterable, sign, value, message=None):
if sign not in SIGNS:
raise InvalidSignError(sign)
if message is None:
variable = [name for name, i in locals().items() if i == iterable][0]
message = f'Error: len({variable}) = {len(iterable)} must be {sign} {value}!'
super().__init__(message)
class StringIsNotDNAError(Exception):
def __init__(self, message=None):
if message is None:
message = 'Error: Your string is not a valid DNA string!\n\
It must be composed using ' + DNA_ALPHABET + ' alphabet!'
super().__init__(message)
class StringIsNotRNAError(Exception):
def __init__(self, message=None):
if message is None:
message = 'Error: Your string is not a valid RNA string!\n\
It must be composed using ' + RNA_ALPHABET + ' alphabet!'
super().__init__(message)
class StringIsNotProteinError(Exception):
def __init__(self, message=None):
if message is None:
message = 'Error: Your string is not a valid protein string!\n\
It must be composed using ' + set(RNA_CODON_TABLE.values()) + ' alphabet!'
super().__init__(message)