From aab24d2afc83b357c1f95e9ca51a982f6c7aabe0 Mon Sep 17 00:00:00 2001 From: SoliareofAstora Date: Thu, 25 Nov 2021 23:41:35 +0100 Subject: [PATCH 1/3] added predict_with_cmap method --- deepfrier/Predictor.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/deepfrier/Predictor.py b/deepfrier/Predictor.py index 3381d73..be367e6 100644 --- a/deepfrier/Predictor.py +++ b/deepfrier/Predictor.py @@ -54,6 +54,7 @@ def __init__(self, model_prefix, gcn=True): self.model_prefix = model_prefix self.gcn = gcn self._load_model() + self.prot2goterms = {} def _load_model(self): self.model = tf.keras.models.load_model(self.model_prefix + '.hdf5', @@ -130,6 +131,27 @@ def predict(self, test_prot, cmap_thresh=10.0, chain='query_prot'): self.goidx2chains[idx].add(chain) self.prot2goterms[chain].append((self.goterms[idx], self.gonames[idx], float(y[idx]))) + def predict_with_cmap(self, seqres, cmap, chain): + self.Y_hat = np.zeros((1, len(self.goterms)), dtype=float) + self.goidx2chains = {} + self.data = {} + self.test_prot_list = [chain] + if self.gcn: + S = seq2onehot(seqres) + S = S.reshape(1, *S.shape) + A = cmap + y = self.model([A, S], training=False).numpy()[:, :, 0].reshape(-1) + self.Y_hat[0] = y + self.prot2goterms[chain] = [] + self.data[chain] = [[A, S], seqres] + go_idx = np.where((y >= self.thresh) == True)[0] + for idx in go_idx: + if idx not in self.goidx2chains: + self.goidx2chains[idx] = set() + self.goidx2chains[idx].add(chain) + self.prot2goterms[chain].append((self.goterms[idx], self.gonames[idx], float(y[idx]))) + + def predict_from_PDB_dir(self, dir_name, cmap_thresh=10.0): print ("### Computing predictions from directory with PDB files...") pdb_fn_list = glob.glob(dir_name + '/*.pdb*') From e03290f7e1b956c7162bd4c867d7f0a02d9bb270 Mon Sep 17 00:00:00 2001 From: SoliareofAstora Date: Sat, 25 Dec 2021 18:00:11 +0100 Subject: [PATCH 2/3] sequence prediction using sequence only --- deepfrier/Predictor.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/deepfrier/Predictor.py b/deepfrier/Predictor.py index be367e6..1647262 100644 --- a/deepfrier/Predictor.py +++ b/deepfrier/Predictor.py @@ -151,6 +151,26 @@ def predict_with_cmap(self, seqres, cmap, chain): self.goidx2chains[idx].add(chain) self.prot2goterms[chain].append((self.goterms[idx], self.gonames[idx], float(y[idx]))) + def predict_from_sequence(self, sequence, chain): + self.test_prot_list = [chain] + self.Y_hat = np.zeros((len(self.test_prot_list), len(self.goterms)), dtype=float) + self.goidx2chains = {} + self.prot2goterms = {} + self.data = {} + + for i, chain in enumerate(self.test_prot_list): + S = seq2onehot(str(sequence)) + S = S.reshape(1, *S.shape) + y = self.model(S, training=False).numpy()[:, :, 0].reshape(-1) + self.Y_hat[i] = y + self.prot2goterms[chain] = [] + self.data[chain] = [[S], sequence] + go_idx = np.where((y >= self.thresh) == True)[0] + for idx in go_idx: + if idx not in self.goidx2chains: + self.goidx2chains[idx] = set() + self.goidx2chains[idx].add(chain) + self.prot2goterms[chain].append((self.goterms[idx], self.gonames[idx], float(y[idx]))) def predict_from_PDB_dir(self, dir_name, cmap_thresh=10.0): print ("### Computing predictions from directory with PDB files...") From 25fc53f90b21946789f8404f05c688d6a25e9cc8 Mon Sep 17 00:00:00 2001 From: SoliareofAstora Date: Sun, 26 Dec 2021 00:48:10 +0100 Subject: [PATCH 3/3] prediction data dumping hotfix --- deepfrier/Predictor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deepfrier/Predictor.py b/deepfrier/Predictor.py index 1647262..83500ad 100644 --- a/deepfrier/Predictor.py +++ b/deepfrier/Predictor.py @@ -55,6 +55,7 @@ def __init__(self, model_prefix, gcn=True): self.gcn = gcn self._load_model() self.prot2goterms = {} + self.goidx2chains = {} def _load_model(self): self.model = tf.keras.models.load_model(self.model_prefix + '.hdf5', @@ -133,7 +134,6 @@ def predict(self, test_prot, cmap_thresh=10.0, chain='query_prot'): def predict_with_cmap(self, seqres, cmap, chain): self.Y_hat = np.zeros((1, len(self.goterms)), dtype=float) - self.goidx2chains = {} self.data = {} self.test_prot_list = [chain] if self.gcn: @@ -154,8 +154,6 @@ def predict_with_cmap(self, seqres, cmap, chain): def predict_from_sequence(self, sequence, chain): self.test_prot_list = [chain] self.Y_hat = np.zeros((len(self.test_prot_list), len(self.goterms)), dtype=float) - self.goidx2chains = {} - self.prot2goterms = {} self.data = {} for i, chain in enumerate(self.test_prot_list):