@@ -8,3 +8,6 @@ cell/data/DTI/SNAP Stanford/ChG-Miner_miner-chem-gene.tsv.gz | |||
drug/data/Smiles/drugbank_all_structure_links.csv.zip | |||
*.pyc | |||
predictor/test.py | |||
/output | |||
drug/data/DDI/DrugBank/processed | |||
drug/data/DDI/DrugBank/processed/ddi_graph_dataset.pt |
@@ -9,9 +9,11 @@ import os | |||
class DDInteractionDataset(Dataset): | |||
def __init__(self, root = "\\drug/data/", transform=None, pre_transform=None, pre_filter=None): | |||
def __init__(self, root = "\\drug/data/", transform=None, pre_transform=None, pre_filter=None, gpu_id=None): | |||
self.gpu_id = gpu_id | |||
super(DDInteractionDataset, self).__init__(os.path.dirname(os.path.abspath(os.path.dirname( __file__ ))) + "/drug/data/", transform, pre_transform, pre_filter) | |||
@property | |||
def num_features(self): | |||
return self._num_features | |||
@@ -88,6 +90,9 @@ class DDInteractionDataset(Dataset): | |||
# --------------------------------------------------------------- | |||
data = Data(x = node_features, edge_index = edge_index) | |||
if self.gpu_id is not None: | |||
data = data.cuda(self.gpu_id) | |||
if self.pre_filter is not None and not self.pre_filter(data): | |||
pass | |||
@@ -105,8 +110,8 @@ class DDInteractionDataset(Dataset): | |||
data = torch.load(osp.join(self.processed_dir, 'ddi_graph_dataset.pt')) | |||
return data | |||
ddiDataset = DDInteractionDataset(root = "drug/data/") | |||
print(ddiDataset.get().edge_index.t()) | |||
# run for checking | |||
# ddiDataset = DDInteractionDataset(root = "drug/data/") | |||
# print(ddiDataset.get().edge_index.t()) | |||
# print(ddiDataset.get().x) | |||
print(ddiDataset.num_features) | |||
# print(ddiDataset.num_features) |
@@ -19,21 +19,17 @@ from torch_geometric.nn import GCNConv | |||
# base from this notebook: https://colab.research.google.com/drive/1LJir3T6M6Omc2Vn2GV2cDW_GV2YfI53_?usp=sharing#scrollTo=jNsToorfSgS0 | |||
class GCN(torch.nn.Module): | |||
def __init__(self, num_features, hidden_channels, gpu_id=None): # num_features = dataset.num_features | |||
def __init__(self, num_features, hidden_channels): # num_features = dataset.num_features | |||
super(GCN, self).__init__() | |||
torch.manual_seed(42) | |||
# Initialize the layers | |||
self.conv1 = GCNConv(num_features, hidden_channels) | |||
self.conv2 = GCNConv(hidden_channels, num_features) | |||
self.gpu_id = gpu_id | |||
def forward(self, x, edge_index): | |||
# First Message Passing Layer (Transformation) | |||
x = x.to(torch.float32) | |||
if self.gpu_id is not None: | |||
x = x.cuda(self.gpu_id) | |||
edge_index = edge_index.cuda(self.gpu_id) | |||
x = self.conv1(x, edge_index) | |||
x = x.relu() | |||
x = F.dropout(x, p=0.5, training=self.training) |
@@ -5,6 +5,7 @@ import time | |||
import pickle | |||
import torch | |||
import torch.nn as nn | |||
import gc | |||
from datetime import datetime | |||
@@ -35,7 +36,8 @@ def step_batch(model, batch, loss_func, gpu_id=None, train=True): | |||
drug1_id = drug1_id.cuda(gpu_id) | |||
drug2_id = drug2_id.cuda(gpu_id) | |||
cell_feat = cell_feat.cuda(gpu_id) | |||
pass | |||
y_true = y_true.cuda(gpu_id) | |||
if train: | |||
y_pred = model(drug1_id, drug2_id, cell_feat) | |||
else: | |||
@@ -106,6 +108,7 @@ def create_model(data, hidden_size, gpu_id=None): | |||
def cv(args, out_dir): | |||
torch.cuda.set_per_process_memory_fraction(0.6, 0) | |||
# Clear any cached memory | |||
gc.collect() | |||
torch.cuda.empty_cache() | |||
save_args(args, os.path.join(out_dir, 'args.json')) | |||
test_loss_file = os.path.join(out_dir, 'test_loss.pkl') | |||
@@ -153,6 +156,9 @@ def cv(args, out_dir): | |||
logging.info("Inner loop completed. Mean valid loss: {:.4f}".format(inner_loss)) | |||
logging.info("-" * n_delimiter) | |||
losses.append(inner_loss) | |||
torch.cuda.memory_summary(device=None, abbreviated=False) | |||
gc.collect() | |||
torch.cuda.empty_cache() | |||
time.sleep(10) | |||
min_ls, min_idx = arg_min(losses) |
@@ -17,9 +17,8 @@ class Connector(nn.Module): | |||
def __init__(self, gpu_id=None): | |||
self.gpu_id = gpu_id | |||
super(Connector, self).__init__() | |||
self.ddiDataset = DDInteractionDataset() | |||
self.gcn = GCN(self.ddiDataset.num_features, self.ddiDataset.num_features // 2, gpu_id) | |||
self.ddiDataset = DDInteractionDataset(gpu_id = gpu_id) | |||
self.gcn = GCN(self.ddiDataset.num_features, self.ddiDataset.num_features // 2) | |||
#Cell line features | |||
# np.load('cell_feat.npy') |