Skip to content

Commit

Permalink
add multiple attempts at connecting to uniprot.org
Browse files Browse the repository at this point in the history
  • Loading branch information
luponzo86 committed Mar 11, 2020
1 parent d3764d3 commit 342d014
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 13 additions & 2 deletions rhapsody/features/Uniprot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import pickle
import datetime
import time
import numpy as np
import prody as pd
from prody import LOGGER, SETTINGS
Expand All @@ -25,11 +26,21 @@
'seqScanning', 'printSAVlist']


def queryUniprot(*args, **kwargs):
def queryUniprot(*args, n_attempts=3, dt=1, **kwargs):
"""
Redefine prody function to check for no internet connection
"""
_ = openURL('http://www.uniprot.org/')
attempt = 0
while attempt < n_attempts:
try:
print(f'attempt {attempt}')
_ = openURL('http://www.uniprot.org/')
break
except:
attempt += 1
time.sleep((attempt+1)*dt)
else:
_ = openURL('http://www.uniprot.org/')
return pd.queryUniprot(*args, **kwargs)


Expand Down
8 changes: 5 additions & 3 deletions rhapsody/predict/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,11 @@ def getUniqueSAVcoords(self):
[SAV['SAV coords'], SAV['unique SAV coords']] +
SAV['unique SAV coords'].split()
)
except Exception as e:
LOGGER.warn(f'Invalid Uniprot coordinates at line {i}: {e}')
uSAVcoords[i] = tuple(['?', -999, '?', '?'])
except Exception:
LOGGER.warn(
'Invalid Uniprot coordinates at line {}: {}'.format(
i, SAV['unique SAV coords']))
uSAVcoords[i] = tuple(['?', '?', '?', -999, '?', '?'])
return uSAVcoords

def calcFeatures(self, filename='rhapsody-features.txt', refresh=False):
Expand Down

0 comments on commit 342d014

Please sign in to comment.