From f03b2ccfdac92bec55b48298fdc2d727a1184ff0 Mon Sep 17 00:00:00 2001 From: jwest Date: Wed, 24 Feb 2021 20:48:29 -0500 Subject: [PATCH] V0.21 Refactor and add ligand and target neighbor data. Keep all nearest residue level interacitons. --- .vscode/settings.json | 12 ++++++ .../DictMethodEntityInstanceHelper.py | 25 ++++++------ .../dictionary/DictMethodResourceProvider.py | 22 +++++------ .../dictionary/NeighborInteractionProvider.py | 38 +++++++++++++++++-- .../tests-dictionary/testDictMethodRunner.py | 4 +- 5 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de70733 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "test*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/rcsb/utils/dictionary/DictMethodEntityInstanceHelper.py b/rcsb/utils/dictionary/DictMethodEntityInstanceHelper.py index 44f03c8..d2fba57 100644 --- a/rcsb/utils/dictionary/DictMethodEntityInstanceHelper.py +++ b/rcsb/utils/dictionary/DictMethodEntityInstanceHelper.py @@ -46,7 +46,7 @@ def __init__(self, **kwargs): self.__dApi = rP.getResource("Dictionary API instance (pdbx_core)") if rP else None self.__ccP = rP.getResource("ChemCompProvider instance") if rP else None self.__rlsP = rP.getResource("RcsbLigandScoreProvider instance") if rP else None - self.__tiP = rP.getResource("TargetInteractionProvider instance") if rP else None + self.__niP = rP.getResource("NeighborInteractionProvider instance") if rP else None # logger.debug("Dictionary entity-instance level method helper init") @@ -1704,12 +1704,10 @@ def buildInstanceValidationScores(self, dataContainer, catName, **kwargs): rankD = {} scoreD = {} # -- Get existing interactions or calculate on the fly - if False and self.__tiP.hasEntry(entryId): - pass - # intD = self.__tiP.getInteractions(entryId) - # ligandAtomCountD = self.__tiP.getAtomCounts(entryId) + if self.__niP.hasEntry(entryId): + ligandAtomCountD = self.__niP.getAtomCounts(entryId) + intIsBoundD = self.__niP.getLigandNeighborBoundState(entryId) else: - # intD, ligandAtomCountD = self.__commonU.getNonpolymerInstanceNeighbors(dataContainer) ligandAtomCountD = self.__commonU.getLigandAtomCountD(dataContainer) intIsBoundD = self.__commonU.getLigandNeighborBoundState(dataContainer) @@ -1877,10 +1875,9 @@ def buildInstanceTargetNeighbors(self, dataContainer, catName, **kwargs): asymIdD = self.__commonU.getInstanceEntityMap(dataContainer) asymAuthIdD = self.__commonU.getAsymAuthIdMap(dataContainer) # -- Get existing interactions or calculate on the fly - # TODO - if False and self.__tiP.hasEntry(entryId): - # intD = self.__tiP.getInteractions(entryId) - pass + if self.__niP.hasEntry(entryId): + ligandIndexD = self.__niP.getLigandNeighborIndex(entryId) + nearestNeighborL = self.__niP.getNearestNeighborList(entryId) else: ligandIndexD = self.__commonU.getLigandNeighborIndex(dataContainer) nearestNeighborL = self.__commonU.getNearestNeighborList(dataContainer) @@ -1954,10 +1951,10 @@ def buildInstanceLigandNeighbors(self, dataContainer, catName, **kwargs): asymIdD = self.__commonU.getInstanceEntityMap(dataContainer) asymAuthIdD = self.__commonU.getAsymAuthIdMap(dataContainer) # -- Get existing interactions or calculate on the fly - # TODO - if False and self.__tiP.hasEntry(entryId): - # intD = self.__tiP.getInteractions(entryId) - pass + # + if self.__niP.hasEntry(entryId): + targetIndexD = self.__niP.getTargetNeighborIndex(entryId) + nearestNeighborL = self.__niP.getNearestNeighborList(entryId) else: targetIndexD = self.__commonU.getTargetNeighborIndex(dataContainer) nearestNeighborL = self.__commonU.getNearestNeighborList(dataContainer) diff --git a/rcsb/utils/dictionary/DictMethodResourceProvider.py b/rcsb/utils/dictionary/DictMethodResourceProvider.py index fc3eadd..8b294ad 100644 --- a/rcsb/utils/dictionary/DictMethodResourceProvider.py +++ b/rcsb/utils/dictionary/DictMethodResourceProvider.py @@ -36,7 +36,7 @@ from rcsb.utils.dictionary.DictionaryApiProviderWrapper import DictionaryApiProviderWrapper from rcsb.utils.dictionary.DictMethodCommonUtils import DictMethodCommonUtils -from rcsb.utils.dictionary.TargetInteractionProvider import TargetInteractionProvider +from rcsb.utils.dictionary.NeighborInteractionProvider import NeighborInteractionProvider from rcsb.utils.chemref.AtcProvider import AtcProvider from rcsb.utils.chemref.ChemCompModelProvider import ChemCompModelProvider from rcsb.utils.chemref.ChemCompProvider import ChemCompProvider @@ -99,7 +99,7 @@ def __init__(self, cfgOb, **kwargs): self.__pcP = None self.__phP = None self.__rlsP = None - self.__tiP = None + self.__niP = None # # # self.__wsPattern = re.compile(r"\s+", flags=re.UNICODE | re.MULTILINE) @@ -125,7 +125,7 @@ def __init__(self, cfgOb, **kwargs): "PubChemProvider instance": self.__fetchPubChemProvider, "PharosProvider instance": self.__fetchPharosProvider, "RcsbLigandScoreProvider instance": self.__fetchRcsbLigandScoreProvider, - "TargetInteractionProvider instance": self.__fetchTargetInteractionProvider, + "NeighborInteractionProvider instance": self.__fetchNeighborInteractionProvider, } logger.debug("Dictionary resource provider init completed") # @@ -396,19 +396,19 @@ def __fetchRcsbLigandScoreProvider(self, cfgOb, configName, cachePath, useCache= self.__rlsP = RcsbLigandScoreProvider(cachePath=cachePath, useCache=useCache) return self.__rlsP - def __fetchTargetInteractionProvider(self, cfgOb, configName, cachePath, useCache=True, **kwargs): + def __fetchNeighborInteractionProvider(self, cfgOb, configName, cachePath, useCache=True, **kwargs): logger.debug("configName %s cachePath %s kwargs %r", configName, cachePath, kwargs) - if not self.__tiP: + if not self.__niP: # -- try: minCount = 10 - tiP = TargetInteractionProvider(cfgOb, configName, cachePath=cachePath, useCache=useCache) - ok = tiP.fromStash() - ok = tiP.reload() - ok = tiP.testCache(minCount=minCount) + niP = NeighborInteractionProvider(cfgOb, configName, cachePath=cachePath, useCache=useCache) + ok = niP.fromStash() + ok = niP.reload() + ok = niP.testCache(minCount=minCount) if ok: - self.__tiP = tiP + self.__niP = niP except Exception as e: logger.warning("Failing with %s", str(e)) # - return self.__tiP + return self.__niP diff --git a/rcsb/utils/dictionary/NeighborInteractionProvider.py b/rcsb/utils/dictionary/NeighborInteractionProvider.py index 51a338b..bf1f12d 100644 --- a/rcsb/utils/dictionary/NeighborInteractionProvider.py +++ b/rcsb/utils/dictionary/NeighborInteractionProvider.py @@ -141,6 +141,37 @@ def getTargetNeighborIndex(self, entryId): pass return {} + def getNearestNeighborList(self, entryId): + """Return the list of neares neighbors for the entry. + + Args: + entryId (str): entry identifier + + Returns: + list: [LigandTargetInstance(), ...] + + """ + try: + return self.__neighborD["entries"][entryId.upper()]["nearestNeighbors"] + except Exception: + pass + return [] + + def getLigandNeighborBoundState(self, entryId): + """Return the dicitonary of ligand instances with isBound boolean status. + + Args: + entryId (str): entry identifier + + Returns: + (dict): {ligandAsymId: True if isBound, ... } + """ + try: + return self.__neighborD["entries"][entryId.upper()]["ligandIsBoundD"] + except Exception: + pass + return {} + def getAtomCounts(self, entryId): """Return the non-polymer instance occupancy weighted atome counts for the input entry. @@ -222,8 +253,7 @@ def __reload(self, fmt="pickle", useCache=True): # if useCache and self.__mU.exists(targetFilePath): neighborD = self.__mU.doImport(targetFilePath, fmt=fmt) - # TODO - if True or fmt != "pickle": + if fmt != "pickle": for _, nD in neighborD["entries"].items(): nD["nearestNeighbors"] = [LigandTargetInstance(*neighbor) for neighbor in nD["nearestNeighbors"]] except Exception as e: @@ -305,7 +335,7 @@ def __toStash(self, url, stashRemoteDirPath, userName=None, password=None, remot """ ok = False try: - stU = StashUtil(os.path.join(self.__dirPath, "stash"), "nonpolymer-target-interactions") + stU = StashUtil(os.path.join(self.__dirPath, "stash"), "ligand-target-neighbors") ok = stU.makeBundle(self.__dirPath, [self.__stashDir]) if ok: ok = stU.storeBundle(url, stashRemoteDirPath, remoteStashPrefix=remoteStashPrefix, userName=userName, password=password) @@ -349,7 +379,7 @@ def __fromStash(self, url, stashRemoteDirPath, userName=None, password=None, rem """ ok = False try: - stU = StashUtil(os.path.join(self.__dirPath, "stash"), "nonpolymer-target-interactions") + stU = StashUtil(os.path.join(self.__dirPath, "stash"), "ligand-target-neighbors") ok = stU.fetchBundle(self.__dirPath, url, stashRemoteDirPath, remoteStashPrefix=remoteStashPrefix, userName=userName, password=password) except Exception as e: logger.error("Failing with url %r stashDirPath %r: %s", url, stashRemoteDirPath, str(e)) diff --git a/rcsb/utils/tests-dictionary/testDictMethodRunner.py b/rcsb/utils/tests-dictionary/testDictMethodRunner.py index d9ad876..4bdc6f4 100644 --- a/rcsb/utils/tests-dictionary/testDictMethodRunner.py +++ b/rcsb/utils/tests-dictionary/testDictMethodRunner.py @@ -79,8 +79,8 @@ def __runContentType(self, contentType, mockLength, mergeContent): self.assertGreaterEqual(len(locatorObjList), mockLength) for container in containerList: cName = container.getName() - # if cName not in ["6TTM"]: - # continue + if cName not in ["6TTM"]: + continue logger.debug("Processing container %s", cName) dmh.apply(container) savePath = os.path.join(HERE, "test-output", cName + "-with-method.cif")