-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmodels.py
More file actions
161 lines (111 loc) · 4.24 KB
/
Copy pathmodels.py
File metadata and controls
161 lines (111 loc) · 4.24 KB
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
# Building model
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv, GATConv, global_max_pool as gmp, global_add_pool as gap,global_mean_pool as gep,global_sort_pool
from torch_geometric.utils import dropout_adj
from torch.optim.lr_scheduler import MultiStepLR
class GCNN(nn.Module):
def __init__(self, n_output=1, num_features_pro= 1024, output_dim=128, dropout=0.2):
super(GCNN, self).__init__()
print('GCNN Loaded')
# for protein 1
self.n_output = n_output
self.pro1_conv1 = GCNConv(num_features_pro, num_features_pro)
self.pro1_fc1 = nn.Linear(num_features_pro, output_dim)
# for protein 2
self.pro2_conv1 = GCNConv(num_features_pro, num_features_pro)
self.pro2_fc1 = nn.Linear(num_features_pro, output_dim)
self.relu = nn.LeakyReLU()
self.dropout = nn.Dropout(dropout)
self.sigmoid = nn.Sigmoid()
# combined layers
self.fc1 = nn.Linear(2 * output_dim, 256)
self.fc2 = nn.Linear(256 ,64)
self.out = nn.Linear(64, self.n_output)
def forward(self, pro1_data, pro2_data):
#get graph input for protein 1
pro1_x, pro1_edge_index, pro1_batch = pro1_data.x, pro1_data.edge_index, pro1_data.batch
# get graph input for protein 2
pro2_x, pro2_edge_index, pro2_batch = pro2_data.x, pro2_data.edge_index, pro2_data.batch
x = self.pro1_conv1(pro1_x, pro1_edge_index)
x = self.relu(x)
# global pooling
x = gep(x, pro1_batch)
# flatten
x = self.relu(self.pro1_fc1(x))
x = self.dropout(x)
xt = self.pro2_conv1(pro2_x, pro2_edge_index)
xt = self.relu(xt)
# global pooling
xt = gep(xt, pro2_batch)
# flatten
xt = self.relu(self.pro2_fc1(xt))
xt = self.dropout(xt)
# Concatenation
xc = torch.cat((x, xt), 1)
# add some dense layers
xc = self.fc1(xc)
xc = self.relu(xc)
xc = self.dropout(xc)
xc = self.fc2(xc)
xc = self.relu(xc)
xc = self.dropout(xc)
out = self.out(xc)
out = self.sigmoid(out)
return out
net = GCNN()
print(net)
"""# GAT"""
class AttGNN(nn.Module):
def __init__(self, n_output=1, num_features_pro= 1024, output_dim=128, dropout=0.2, heads = 1 ):
super(AttGNN, self).__init__()
print('AttGNN Loaded')
self.hidden = 8
self.heads = 1
# for protein 1
self.pro1_conv1 = GATConv(num_features_pro, self.hidden* 16, heads=self.heads, dropout=0.2)
self.pro1_fc1 = nn.Linear(128, output_dim)
# for protein 2
self.pro2_conv1 = GATConv(num_features_pro, self.hidden*16, heads=self.heads, dropout=0.2)
self.pro2_fc1 = nn.Linear(128, output_dim)
self.relu = nn.LeakyReLU()
self.sigmoid = nn.Sigmoid()
self.dropout = nn.Dropout(dropout)
# combined layers
self.fc1 = nn.Linear(2 * output_dim, 256)
self.fc2 = nn.Linear(256, 64)
self.out = nn.Linear(64, n_output)
def forward(self, pro1_data, pro2_data):
# get graph input for protein 1
pro1_x, pro1_edge_index, pro1_batch = pro1_data.x, pro1_data.edge_index, pro1_data.batch
# get graph input for protein 2
pro2_x, pro2_edge_index, pro2_batch = pro2_data.x, pro2_data.edge_index, pro2_data.batch
x = self.pro1_conv1(pro1_x, pro1_edge_index)
x = self.relu(x)
# global pooling
x = gep(x, pro1_batch)
# flatten
x = self.relu(self.pro1_fc1(x))
x = self.dropout(x)
xt = self.pro2_conv1(pro2_x, pro2_edge_index)
xt = self.relu(self.pro2_fc1(xt))
# global pooling
xt = gep(xt, pro2_batch)
# flatten
xt = self.relu(xt)
xt = self.dropout(xt)
# Concatenation
xc = torch.cat((x, xt), 1)
# add some dense layers
xc = self.fc1(xc)
xc = self.relu(xc)
xc = self.dropout(xc)
xc = self.fc2(xc)
xc = self.relu(xc)
xc = self.dropout(xc)
out = self.out(xc)
out = self.sigmoid(out)
return out
net_GAT = AttGNN()
print(net_GAT)