diff --git a/projects/PP2A-B55-design/translate2modelcif.py b/projects/PP2A-B55-design/translate2modelcif.py index 5db56f0f43d6b5ebef2458f5658574d074fd7c94..045c8dfb561ae234d4493dc12657b125b1cd5e1e 100644 --- a/projects/PP2A-B55-design/translate2modelcif.py +++ b/projects/PP2A-B55-design/translate2modelcif.py @@ -363,19 +363,24 @@ def _check_sequence(up_ac, sequence): # for cache below upkb_entry_cache = {} # key = (up_ac, up_version, mdl_sequence) 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. - 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 cache_key = (up_ac, up_version, sqe) if cache_key in upkb_entry_cache: return upkb_entry_cache[cache_key] - # fetch and parse + # fetch and parse first guess if up_version is None: 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 - while True: mismatches, up_range, mdl_range, covered_aln, mdl_seqres = _align_sequences( sqe, up_data["up_sequence"], atomseq_aln=False) @@ -415,14 +420,6 @@ def _fetch_upkb_cached(sqe, up_ac, up_version=None): _warn_msg(msg) # raise RuntimeError(msg) 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 upkb_entry_cache[cache_key] = up_data