Skip to content

Commit

Permalink
add error msg when parsePDB fails. Edit other error msgs to make them…
Browse files Browse the repository at this point in the history
… more meaningful
  • Loading branch information
luponzo86 committed Apr 18, 2020
1 parent 342d014 commit d44a396
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 11 additions & 4 deletions rhapsody/features/PolyPhen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,17 @@ def parsePolyPhen2output(pph2_output):
# discard invalid lines
lines = [l for l in lines if l.strip() and l[0] != '#']
if not lines:
msg = ("PolyPhen-2's output is empty. Please make sure that: \n"
"1) variants' format is correct "
'(\"UniprotID pos wt_aa mut_aa\") \n'
"2) query contains *human* variants \n")
msg = (
"PolyPhen-2's output is empty. Please check file 'pph2-log.txt' "
"in the output folder for error messages from PolyPhen-2. \n"
"Typical errors include: \n"
"1) query contains *non-human* variants \n"
"2) variants' format is incorrect (e.g. "
'"UniprotID pos wt_aa mut_aa") \n'
"3) wild-type amino acids are in the wrong position on the "
"sequence (please refer to Uniprot's canonical isoform) \n"
"4) Uniprot accession number is not recognized by PolyPhen-2. \n"
)
raise RuntimeError(msg)
# define a structured array
pl_dtype = np.dtype([(col, 'U25') for col in pph2_columns])
Expand Down
10 changes: 8 additions & 2 deletions rhapsody/features/Uniprot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def queryUniprot(*args, n_attempts=3, dt=1, **kwargs):
attempt = 0
while attempt < n_attempts:
try:
print(f'attempt {attempt}')
_ = openURL('http://www.uniprot.org/')
break
except:
LOGGER.info(
f'Attempt {attempt} to contact www.uniprot.org failed')
attempt += 1
time.sleep((attempt+1)*dt)
else:
Expand Down Expand Up @@ -172,7 +173,12 @@ def alignCustomPDB(self, PDB, chain='all', title=None, recover=False):
assert isinstance(title, str) or title is None
# parse/import pdb and assign title
if isinstance(PDB, str):
pdb = pd.parsePDB(PDB, subset='calpha')
try:
pdb = pd.parsePDB(PDB, subset='calpha')
except Exception as e:
msg = ('Invalid PDB structure: the file might be '
f'corrupted or contain errors. Error message: {e}')
raise LOGGER.error(msg)
if title is None:
title = os.path.basename(PDB.strip())
title = title.replace(' ', '_')
Expand Down
2 changes: 1 addition & 1 deletion rhapsody/predict/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def getUniqueSAVcoords(self):
except Exception:
LOGGER.warn(
'Invalid Uniprot coordinates at line {}: {}'.format(
i, SAV['unique SAV coords']))
i, SAV['unique SAV coords']))
uSAVcoords[i] = tuple(['?', '?', '?', -999, '?', '?'])
return uSAVcoords

Expand Down

0 comments on commit d44a396

Please sign in to comment.