-
Notifications
You must be signed in to change notification settings - Fork 3
/
DeepPPI_Compare_With_Different_Architectures.py
executable file
·270 lines (248 loc) · 8.96 KB
/
DeepPPI_Compare_With_Different_Architectures.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 10 13:39:46 2017
@author: sun
"""
import numpy as np
import pandas as pd
import h5py
from keras.layers import Dense, Input, Dropout
from keras.layers.merge import concatenate
from keras.optimizers import SGD
from keras.utils import np_utils
from keras.models import Model
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import roc_curve, auc
from utils.tools import calculate_performace,plothistory, \
categorical_probas_to_classes
def get_neg(pos_num, neg_num, protein):
index = [i for i in range(neg_num)]
np.random.shuffle(index)
index = np.array(index)
neg_protein = protein.iloc[pos_num + index[0:pos_num]]
return neg_protein
def get_protein(pos_protein, neg_protein, profeat_feature):
pos_neg_protein = pd.concat([pos_protein, neg_protein], axis=0)
pos_neg_protein.index = np.arange(len(pos_protein) * 2)
labels = pos_neg_protein['interaction']
protein_a = profeat_feature.loc[pos_neg_protein.proteinA, :]
protein_b = profeat_feature.loc[pos_neg_protein.proteinB, :]
protein_a.index = np.arange(len(pos_protein) * 2)
protein_b.index = np.arange(len(pos_protein) * 2)
protein = pd.concat([protein_a, protein_b], axis=1)
#change data to numpy type
X = np.array(protein)
labels = np.array(labels)
#normalization
X = StandardScaler().fit_transform(X)
#shuffle data
np.random.seed(1)
index = [i for i in range(len(labels))]
np.random.shuffle(index)
X = X[index]
labels = labels[index]
return X, labels
def get_sep_model():
input_1 = Input(shape=(1164, ), name='Protein_a')
protein_input1 = Dense(
512,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_1')(input_1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
256,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_2')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_3')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
input_2 = Input(shape=(1164, ), name='Protein_b')
protein_input2 = Dense(
512,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_1')(input_2)
protein_input2 = Dropout(0.2)(protein_input2)
protein_input2 = Dense(
256,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_2')(protein_input2)
protein_input2 = Dropout(0.2)(protein_input2)
protein_input2 = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_3')(protein_input2)
protein_input2 = Dropout(0.2)(protein_input2)
merged_vector = concatenate([protein_input1, protein_input2], axis=1)
# merged_vector = merge([protein_input1, protein_input2], mode='concat', concat_axis=1, name='merge_pro_A_B')
output = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_feature_1')(merged_vector)
outputs = Dense(2, activation='softmax', name='output')(output)
model = Model(inputs=[input_1, input_2], outputs=outputs)
sgd = SGD(lr=0.01, momentum=0.9, decay=0.001)
model.compile(
loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model
def get_sep_model_no_hidden():
input_1 = Input(shape=(1164, ), name='Protein_a')
protein_input1 = Dense(
512,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_1')(input_1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
256,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_2')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proA_feature_3')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
input_2 = Input(shape=(1164, ), name='Protein_b')
protein_input2 = Dense(
512,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_1')(input_2)
protein_input2 = Dropout(0.2)(protein_input2)
protein_input2 = Dense(
256,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_2')(protein_input2)
protein_input2 = Dropout(0.2)(protein_input2)
protein_input2 = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_proB_feature_3')(protein_input2)
protein_input2 = Dropout(0.2)(protein_input2)
merged_vector = concatenate([protein_input1, protein_input2], axis=1)
# merged_vector = merge([protein_input1, protein_input2], mode='concat', concat_axis=1, name='merge_pro_A_B')
outputs = Dense(2, activation='softmax', name='output')(merged_vector)
model = Model(inputs=[input_1, input_2], outputs=outputs)
sgd = SGD(lr=0.01, momentum=0.9, decay=0.001)
model.compile(
loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model
def get_con_model():
input_1 = Input(shape=(2328, ), name='Protein')
protein_input1 = Dense(
512,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_feature_1')(input_1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
256,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_feature_2')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
protein_input1 = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_feature_3')(protein_input1)
protein_input1 = Dropout(0.2)(protein_input1)
output = Dense(
128,
activation='relu',
kernel_initializer='glorot_normal',
name='High_dim_feature')(protein_input1)
outputs = Dense(2, activation='softmax', name='output')(output)
model = Model(input=input_1, outputs=outputs)
sgd = SGD(lr=0.01, momentum=0.9, decay=0.001)
model.compile(
loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model
#%%
yeast_protein = pd.read_csv('dataset/yeast_protein_pair.csv')
yeast_profeat_all = pd.read_csv('dataset/yeast_feature_all.csv', index_col=0)
# 1:1
posNum = 17257
negNum = 48594
pos_protein = yeast_protein[0:posNum]
#Set the random number seed
np.random.seed(0)
neg_protein = get_neg(posNum, negNum, yeast_protein)
X, label = get_protein(pos_protein, neg_protein, yeast_profeat_all)
#%%
#file = h5py.File('dataset/yeast_protein.h5','w')
#file.create_dataset('X', data = X)
#file.create_dataset('label', data = label)
#file.close()
#Read the dataset
file = h5py.File('dataset/yeast_protein.h5', 'r')
X = file['X'][:]
label = file['label'][:]
file.close()
#%%
X_train, X_test, y_train, y_test = train_test_split(X, label, random_state=0)
X1_train = X_train[:, 0:1164]
X2_train = X_train[:, 1164:2328]
X1_test = X_test[:, 0:1164]
X2_test = X_test[:, 1164:2328]
del X, label
#%%
model = get_sep_model_no_hidden()
y_train = np_utils.to_categorical(y_train)
hist = model.fit(
[X1_train, X2_train],
y_train,
nb_epoch=30,
#validation_split=0.1,
batch_size=64,
verbose=2)
#plothistory(hist)
#prediction probability
y_score = model.predict([X1_test, X2_test])
y_test = np_utils.to_categorical(y_test)
fpr, tpr, _ = roc_curve(y_test[:, 0], y_score[:, 0])
roc_auc = auc(fpr, tpr)
y_score = categorical_probas_to_classes(y_score)
y_test = categorical_probas_to_classes(y_test)
acc, precision, npv, sensitivity, specificity, mcc, f1 = calculate_performace(
len(y_score), y_score, y_test)
print((
'DeepPPI-sep:acc=%f,precision=%f,npv=%f,sensitivity=%f,specificity=%f,mcc=%f,roc_auc=%f'
% (acc, precision, npv, sensitivity, specificity, mcc, roc_auc)))
#%%
model = get_con_model()
hist = model.fit(
X_train,
y_train,
nb_epoch=30,
batch_size=64,
#validation_split=0.1,
verbose=0)
plothistory(hist)
#prediction probability
y_score = model.predict(X_test)
y_test = np_utils.to_categorical(y_test)
fpr, tpr, _ = roc_curve(y_test[:, 0], y_score[:, 0])
roc_auc = auc(fpr, tpr)
y_score = categorical_probas_to_classes(y_score)
y_test = categorical_probas_to_classes(y_test)
acc, precision, npv, sensitivity, specificity, mcc, f1 = calculate_performace(
len(y_score), y_score, y_test)
print((
'DeepPPI-con:acc=%f,precision=%f,npv=%f,sensitivity=%f,specificity=%f,mcc=%f,roc_auc=%f'
% (acc, precision, npv, sensitivity, specificity, mcc, roc_auc)))