Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

onehot encoding for residue type and polarity #21

Merged
merged 8 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 18 additions & 4 deletions graphprot/Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,36 @@ def __init__(self):
self.type = None
self.name = None
self.nx = None
self.score = {'irmsd': None, 'lrmsd': None,
self.score = {'irmsd': None, 'lrmsd': None, 'class': None,
'fnat': None, 'dockQ': None, 'binclass': None}

def get_score(self, ref):

ref_name = os.path.splitext(os.path.basename(ref))[0]
sim = StructureSimilarity(self.pdb, ref)

self.score['lrmsd'] = sim.compute_lrmsd_fast(
method='svd', lzone=ref_name+'.lzone')
method='svd', lzone=ref_name+'.lzone')
self.score['irmsd'] = sim.compute_irmsd_fast(
method='svd', izone=ref_name+'.izone')
method='svd', izone=ref_name+'.izone')
self.score['fnat'] = sim.compute_fnat_fast()
self.score['dockQ'] = sim.compute_DockQScore(
self.score['fnat'], self.score['lrmsd'], self.score['irmsd'])
self.score['binclass'] = self.score['irmsd'] < 4.0

if self.score['irmsd'] < 1.0 :
_class = 1
elif self.score['irmsd'] < 2.0 :
_class = 2
elif self.score['irmsd'] < 4.0 :
_class = 3
elif self.score['irmsd'] < 6.0 :
_class = 4
else :
_class = 5

self.score['class'] = _class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need the _class variable ? why not

if self.score['irmsd'] < 1.0:
    self.score['class'] = 1

I also find 'class' a bit generic. Maybe 'capri_class' ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also shorten the code

self.score['class'] = 5
for thr, val in zip([6.0, 4.0, 2.0, 1.0],[4,3,2,1]):
    if self.score['irmsd'] <= thr:
           self.score['class'] = val

but of course it's a bit less readable ... so up to you :) (plus I don't know if what I propose here works :D)



def nx2h5(self, f5):

Expand Down
8 changes: 4 additions & 4 deletions graphprot/GraphGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def __init__(self, pdb_path, ref_path, graph_type='residue', pssm_path=None,
@staticmethod
def _get_pssm(pssm_path, mol_name, base_name):

pssmA = os.path.join(pssm_path, mol_name+'.A.pdb.pssm')
pssmB = os.path.join(pssm_path, mol_name+'.B.pdb.pssm')
pssmA = os.path.join(pssm_path, mol_name+'.A.pssm')
pssmB = os.path.join(pssm_path, mol_name+'.B.pssm')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rename the files we give in example then Or at least check that the example still work


# check if the pssms exists
if os.path.isfile(pssmA) and os.path.isfile(pssmB):
pssm = {'A': pssmA, 'B': pssmB}
else:
pssmA = os.path.join(pssm_path, base_name+'.A.pdb.pssm')
pssmB = os.path.join(pssm_path, base_name+'.B.pdb.pssm')
pssmA = os.path.join(pssm_path, base_name+'.A.pssm')
pssmB = os.path.join(pssm_path, base_name+'.B.pssm')
if os.path.isfile(pssmA) and os.path.isfile(pssmB):
pssm = {'A': pssmA, 'B': pssmB}
else:
Expand Down
2 changes: 1 addition & 1 deletion graphprot/NeuralNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def plot_hit_rate(self, data='eval', threshold=4, mode='percentage', name=''):
except:
print('No hit rate plot could be generated for you {} task'.format(
self.task))

@staticmethod
def update_name(hdf5, outdir):
"""Check if the file already exists
Expand Down
39 changes: 24 additions & 15 deletions graphprot/ResidueGraph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import numpy as np
import shutil

import torch
from time import time
import networkx as nx

Expand Down Expand Up @@ -38,25 +38,25 @@ def __init__(self, pdb=None, pssm=None,

self.residue_names = {'CYS': 0, 'HIS': 1, 'ASN': 2, 'GLN': 3, 'SER': 4, 'THR': 5, 'TYR': 6, 'TRP': 7,
'ALA': 8, 'PHE': 9, 'GLY': 10, 'ILE': 11, 'VAL': 12, 'MET': 13, 'PRO': 14, 'LEU': 15,
'GLU': 16, 'ASP': 17, 'LYS': 18, 'ARG': 20}
'GLU': 16, 'ASP': 17, 'LYS': 18, 'ARG': 19}

self.residue_polarity = {'CYS': 'polar', 'HIS': 'polar', 'ASN': 'polar', 'GLN': 'polar', 'SER': 'polar', 'THR': 'polar', 'TYR': 'polar', 'TRP': 'polar',
'ALA': 'apolar', 'PHE': 'apolar', 'GLY': 'apolar', 'ILE': 'apolar', 'VAL': 'apolar', 'MET': 'apolar', 'PRO': 'apolar', 'LEU': 'apolar',
'GLU': 'charged', 'ASP': 'charged', 'LYS': 'charged', 'ARG': 'charged'}
'GLU': 'neg_charged', 'ASP': 'neg_charged', 'LYS': 'neg_charged', 'ARG': 'pos_charged'}

self.pssm_pos = {'CYS': 4, 'HIS': 8, 'ASN': 2, 'GLN': 5, 'SER': 15, 'THR': 16, 'TYR': 18, 'TRP': 17,
'ALA': 0, 'PHE': 13, 'GLY': 7, 'ILE': 9, 'VAL': 19, 'MET': 12, 'PRO': 14, 'LEU': 10,
'GLU': 6, 'ASP': 3, 'LYS': 11, 'ARG': 1}

self.polarity_encoding = {
'apolar': 0, 'polar': -1, 'charged': 1}
self.edge_polarity_encoding, iencod = {}, 0
for k1, v1 in self.polarity_encoding.items():
for k2, v2 in self.polarity_encoding.items():
key = tuple(np.sort([v1, v2]))
if key not in self.edge_polarity_encoding:
self.edge_polarity_encoding[key] = iencod
iencod += 1
'apolar': 0, 'polar': 1, 'neg_charged': 2, 'pos_charged': 3}
#self.edge_polarity_encoding, iencod = {}, 0
##for k1, v1 in self.polarity_encoding.items():
##for k2, v2 in self.polarity_encoding.items():
##key = tuple(np.sort([v1, v2]))
##if key not in self.edge_polarity_encoding:
##self.edge_polarity_encoding[key] = iencod
#iencod += 1

# check if external execs are installed
self.check_execs()
Expand Down Expand Up @@ -226,12 +226,14 @@ def get_node_features(self, db):

self.nx.nodes[node_key]['chain'] = {
'A': 0, 'B': 1}[chainID]
self.nx.nodes[node_key]['type'] = self.residue_names[resName]
self.nx.nodes[node_key]['pos'] = np.mean(
db.get('x,y,z', chainID=chainID, resSeq=resSeq), 0)
self.nx.nodes[node_key]['type'] = self.onehot(
self.residue_names[resName], len(self.residue_names))

self.nx.nodes[node_key]['charge'] = self.residue_charge[resName]
self.nx.nodes[node_key]['polarity'] = self.polarity_encoding[self.residue_polarity[resName]]
self.nx.nodes[node_key]['polarity'] = self.onehot(
self.polarity_encoding[self.residue_polarity[resName]], len(self.polarity_encoding))

self.nx.nodes[node_key]['bsa'] = bsa_data[node_key]

Expand All @@ -253,8 +255,8 @@ def get_edge_features(self):

for e in self.nx.edges:
node1, node2 = e
self.nx.edges[node1, node2]['polarity'] = self._get_edge_polarity(
node1, node2)
#self.nx.edges[node1, node2]['polarity'] = self._get_edge_polarity(
# node1, node2)
Comment on lines +258 to +259
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we don't have any edge features ? no polarity and no distance ? (sorry I forgot a bit about the inner workings of the code)

self.nx.edge_index.append(
[node_keys.index(node1), node_keys.index(node2)])

Expand Down Expand Up @@ -336,3 +338,10 @@ def _get_edge_distance(self, node1, node2, db):
d2 = -2*np.dot(xyz1, xyz2.T) + np.sum(xyz1**2,
axis=1)[:, None] + np.sum(xyz2**2, axis=1)
return np.sqrt(np.min(d2))


def onehot(self, idx, size):
onehot = torch.zeros(size)
# Fill the one-hot encoded sequence with 1 at the corresponding idx
onehot[idx] = 1
return np.array(onehot)