Skip to content

Commit 66dbdd5

Browse files
catch some exceptions
1 parent a69187a commit 66dbdd5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

parsers/distogramparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def DistogramParser(input, input_format=None):
3232
output.append((tuple(contact[:2]), *contact[2:]))
3333

3434
if not output:
35-
raise InvalidFormat('Unable to parse contacts')
35+
raise InvalidFormat('Unable to parse CASPRR_MODE_2 file')
3636
else:
3737
unique_contacts = unique_by_key(output, key=itemgetter(0))
3838
output = [(*contact[0], *contact[1:]) for contact in unique_contacts]

parsers/npzparser.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
def parse_array(array):
10+
# Bin #0 corresponds with d>20A
11+
# Bins #1 ~ #36 correspond with 2A<d<20A in increments of 0.5A
1012
contacts = np.sum(array[:, :, 1:13], axis=-1)
1113
L = contacts.shape[0]
1214
BINS = [np.sum(array[:, :, x:x+4], axis=-1) for x in range(1, 37, 4)]
@@ -18,23 +20,25 @@ def parse_array(array):
1820
for i in range(L) for j in range(i + 5, L)]
1921

2022

21-
def NpzParser(input, input_format):
23+
def NpzParser(input, input_format=None):
2224
output = []
2325
content_type, content_string = input.split(',')
24-
decoded = base64.b64decode(content_string)
25-
archive = np.load(io.BytesIO(decoded), allow_pickle=True)
26-
array = archive['dist']
27-
# Bin #0 corresponds with d>20A
28-
# Bins #1 ~ #36 correspond with 2A<d<20A in increments of 0.5A
29-
tmp_output = parse_array(array)
26+
try:
27+
decoded = base64.b64decode(content_string)
28+
archive = np.load(io.BytesIO(decoded), allow_pickle=True)
29+
array = archive['dist']
30+
tmp_output = parse_array(array)
31+
except (OSError, KeyError, IndexError) as e:
32+
raise InvalidFormat('Unable to parse distance NPZ file')
33+
3034

3135
for contact in tmp_output:
3236
# contact = [res_1, res_2, raw_score, distance_bin, distance_score]
3337
contact[:2] = sorted(contact[:2], reverse=True)
3438
output.append((tuple(contact[:2]), *contact[2:]))
3539

3640
if not output:
37-
raise InvalidFormat('Unable to parse contacts')
41+
raise InvalidFormat('Unable to parse NPZ file')
3842
else:
3943
unique_contacts = unique_by_key(output, key=itemgetter(0))
4044
output = [(*contact[0], *contact[1:]) for contact in unique_contacts]

0 commit comments

Comments
 (0)