Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiple attempts at connecting to uniprot.org #15

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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