-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_data.py
131 lines (113 loc) · 3.6 KB
/
load_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import subprocess
import numpy as np
from aa_to_ch import *
import random
r_features = dict()
l_features = dict()
def create_data(r,l):
R = [r]
L = [l]
dR = dict()
dL = dict()
dR[r] = 0
for i in range( 0,len(r_features[r]['nn']) ):
dR[ r_features[r]['nn'][i] ] = r_features[r]['nn_dist'][i]
dL[l] = 0
for i in range( 0,len(l_features[l]['nn']) ):
dL[ l_features[l]['nn'][i] ] = l_features[l]['nn_dist'][i]
R.extend( r_features[r]['nn'] )
L.extend( l_features[l]['nn'] )
matrix = []
for i in R:
row = []
for j in L:
data = []
data.extend( r_features[ i ][ 'aa' ] )
data.extend( r_features[ i ][ 'features' ] )
data.append( dR[i] )
data.extend( l_features[ j ][ 'aa' ] )
data.extend( l_features[ j ][ 'features' ] )
data.append( dL[j] )
row.append(data)
matrix.append(row)
return matrix
def collect_complex(r_features_file,l_features_file,rri_file,pdb,n_features=6,n_neigh=8):
fh = open(r_features_file,'r')
for i in fh:
r = i.strip()
R=r.split("\t")
r_features[ R[0] ] = dict()
r_features[ R[0] ][ 'aa_' ] = R[1]
r_features[ R[0] ][ 'aa' ] = [ float(x) for x in AA[ R[1] ]]
r_features[ R[0] ][ 'features' ] = [ float(x) for x in R[2:(n_features+2)] ]
r_features[ R[0] ][ 'nn' ] = R[(n_features+2):(n_features+n_neigh+2)]
r_features[ R[0] ][ 'nn_dist' ] = [ float(x) for x in R[(n_features+n_neigh+2):(n_features+n_neigh+2+n_neigh*2)] ]
fh.close()
fh = open(l_features_file,'r')
for i in fh:
r = i.strip()
R=r.split("\t")
l_features[ R[0] ] = dict()
l_features[ R[0] ][ 'aa_' ] = R[1]
l_features[ R[0] ][ 'aa' ] = [ float(x) for x in AA[ R[1] ]]
l_features[ R[0] ][ 'features' ] = [ float(x) for x in R[2:(n_features+2)]]
l_features[ R[0] ][ 'nn' ] = R[(n_features+2):(n_features+n_neigh+2)]
l_features[ R[0] ][ 'nn_dist' ] = [ float(x) for x in R[(n_features+n_neigh+2):(n_features+n_neigh+2+n_neigh*2)] ]
fh.close()
rri = dict()
fh = open(rri_file,'r')
for i in fh:
r = i.strip()
R=r.split("\t")
rri[ R[0]+":"+R[1] ] = 1
fh.close()
np = 0
collection = []
labels = []
negatives = []
#print("\tbatching positives")
for rr in rri:
R = rr.split(":")
r = R[0]
l = R[1]
np += 1
__data = create_data(r,l)
collection.append( create_data(r,l) )
labels.append([1.0,0.0])
#print("\tbatching negatives")
R = list(r_features.keys())
L = list(l_features.keys())
while np>0:
r = random.choice(R)
l = random.choice(L)
if not r+":"+l in rri:
__data = create_data(r,l)
collection.append( __data )
labels.append([0.0,1.0])
np-=1
return [collection, labels]
def __batch(pdb,n_features=6,n_neigh=8):
rri_file = "/home/joan/tools/RRI/DEEP_LEARNING/pairPred_contactMap/"+pdb+".int"
r_features_file = "/home/joan/tools/RRI/DEEP_LEARNING/features/"+pdb+"_r_u.nn.tsv"
l_features_file = "/home/joan/tools/RRI/DEEP_LEARNING/features/"+pdb+"_l_u.nn.tsv"
return collect_complex(r_features_file,l_features_file,rri_file,pdb,n_features=6,n_neigh=8)
def random_batch_excluding(out):
batch_x = []
labels_y = []
fh=open('/home/joan/tools/RRI/DEEP_LEARNING/pdb_list.tsv','r')
for i in fh:
pdb = i.strip()
if i != out:
#print(pdb)
[batch,labels] = __batch(pdb)
batch_x.extend(batch)
labels_y.extend(labels_y)
fh.close()
return [np.array(batch_x),np.array(labels_y)]
def random_batch_of(pdb):
batch_x = []
labels_y = []
[batch,labels] = __batch(pdb)
batch_x.extend(batch)
labels_y.extend(labels_y)
return [np.array(batch_x),np.array(labels_y)]