Skip to content
Snippets Groups Projects
Commit 8bcd3d2f authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

Fix _fetch_upkb_cached in translate2modelcif.py

parent 60328aa8
Branches
No related tags found
No related merge requests found
...@@ -363,19 +363,24 @@ def _check_sequence(up_ac, sequence): ...@@ -363,19 +363,24 @@ def _check_sequence(up_ac, sequence):
# for cache below # for cache below
upkb_entry_cache = {} # key = (up_ac, up_version, mdl_sequence) upkb_entry_cache = {} # key = (up_ac, up_version, mdl_sequence)
def _fetch_upkb_cached(sqe, up_ac, up_version=None): def _fetch_upkb_cached(sqe, up_ac, up_version=None):
"""Get versioned UniProtKB entry (version=None means latest). """Get best matching UniProtKB entry for sequence sqe.
Get it from cache if already fetched. Get it from cache if already fetched.
Return None if failed to parse entry. up_version defines starting version in UP to check.
Note that the returned UP entry may be a different version than the one in up_version.
Returned UP data includes result of _align_sequences.
If no perfect match found, it prints a warning.
""" """
# check if in cache already # check if in cache already
cache_key = (up_ac, up_version, sqe) cache_key = (up_ac, up_version, sqe)
if cache_key in upkb_entry_cache: if cache_key in upkb_entry_cache:
return upkb_entry_cache[cache_key] return upkb_entry_cache[cache_key]
# fetch and parse # fetch and parse first guess
if up_version is None: if up_version is None:
up_data = _fetch_upkb_entry(up_ac) up_data = _fetch_upkb_entry(up_ac)
else:
up_data = _fetch_unisave_entry(up_ac, up_version)
# find best match starting from first guess
min_up_data = None min_up_data = None
while True: while True:
mismatches, up_range, mdl_range, covered_aln, mdl_seqres = _align_sequences( mismatches, up_range, mdl_range, covered_aln, mdl_seqres = _align_sequences(
sqe, up_data["up_sequence"], atomseq_aln=False) sqe, up_data["up_sequence"], atomseq_aln=False)
...@@ -415,14 +420,6 @@ def _fetch_upkb_cached(sqe, up_ac, up_version=None): ...@@ -415,14 +420,6 @@ def _fetch_upkb_cached(sqe, up_ac, up_version=None):
_warn_msg(msg) _warn_msg(msg)
# raise RuntimeError(msg) # raise RuntimeError(msg)
break break
'''else:
try:
# note: can fail to parse very old UP versions...
up_data = _fetch_unisave_entry(up_ac, up_version)
except RuntimeError as ex:
#_warn_msg(f"Error in parsing v{next_v} of {up_ac}:\n{ex}")
up_data = None
'''
# keep in cache # keep in cache
upkb_entry_cache[cache_key] = up_data upkb_entry_cache[cache_key] = up_data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment