jinysun commited on
Commit
86eba7b
·
1 Parent(s): 8dbcfe1

Delete run.py

Browse files
Files changed (1) hide show
  1. run.py +0 -101
run.py DELETED
@@ -1,101 +0,0 @@
1
- import os
2
- import pandas as pd
3
-
4
- import torch
5
- from torch.nn import functional as F
6
- from transformers import AutoTokenizer
7
-
8
- from util.utils import *
9
-
10
- from tqdm import tqdm
11
- from train import markerModel
12
- os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
13
- os.environ["CUDA_VISIBLE_DEVICES"] = '0,1'
14
-
15
- device_count = torch.cuda.device_count()
16
- device_biomarker = torch.device('cuda' if torch.cuda.is_available() else "cpu")
17
-
18
- device = torch.device('cpu')
19
- d_model_name = 'DeepChem/ChemBERTa-10M-MTR'
20
- p_model_name = 'DeepChem/ChemBERTa-10M-MLM'
21
-
22
- tokenizer = AutoTokenizer.from_pretrained(d_model_name)
23
- prot_tokenizer = AutoTokenizer.from_pretrained(p_model_name)
24
-
25
- #--biomarker Model
26
- ##-- hyper param config file Load --##
27
- config = load_hparams('config/predict.json')
28
- config = DictX(config)
29
- model = markerModel.load_from_checkpoint(config.load_checkpoint,strict=False)
30
-
31
- # model = BiomarkerModel.load_from_checkpoint('./biomarker_bindingdb_train8595_pretopre/3477h3wf/checkpoints/epoch=30-step=7284.ckpt').to(device_biomarker)
32
-
33
- model.eval()
34
- model.freeze()
35
-
36
- if device_biomarker.type == 'cuda':
37
- model = torch.nn.DataParallel(model)
38
-
39
- def get_biomarker(drug_inputs, prot_inputs):
40
- output_preds = model(drug_inputs, prot_inputs)
41
-
42
- predict = torch.squeeze((output_preds)).tolist()
43
-
44
- # output_preds = torch.relu(output_preds)
45
- # predict = torch.tanh(output_preds)
46
- # predict = predict.squeeze(dim=1).tolist()
47
-
48
- return predict
49
-
50
-
51
- def biomarker_prediction(smile_acc, smile_don):
52
- try:
53
- aas_input = smile_acc
54
-
55
-
56
- das_input =smile_don
57
- d_inputs = tokenizer(aas_input, padding='max_length', max_length=510, truncation=True, return_tensors="pt")
58
- # d_inputs = tokenizer(smiles, truncation=True, return_tensors="pt")
59
- drug_input_ids = d_inputs['input_ids'].to(device)
60
- drug_attention_mask = d_inputs['attention_mask'].to(device)
61
- drug_inputs = {'input_ids': drug_input_ids, 'attention_mask': drug_attention_mask}
62
-
63
- p_inputs = prot_tokenizer(das_input, padding='max_length', max_length=510, truncation=True, return_tensors="pt")
64
- # p_inputs = prot_tokenizer(aas_input, truncation=True, return_tensors="pt")
65
- prot_input_ids = p_inputs['input_ids'].to(device)
66
- prot_attention_mask = p_inputs['attention_mask'].to(device)
67
- prot_inputs = {'input_ids': prot_input_ids, 'attention_mask': prot_attention_mask}
68
-
69
- output_predict = get_biomarker(drug_inputs, prot_inputs)
70
-
71
- return output_predict
72
-
73
- except Exception as e:
74
- print(e)
75
- return {'Error_message': e}
76
-
77
-
78
- def smiles_aas_test(smile_acc,smile_don):
79
-
80
- batch_size = 1
81
- try:
82
- output_pred = biomarker_prediction((smile_acc), (smile_don))
83
-
84
- datas = output_pred
85
-
86
- ## -- Export result data to csv -- ##
87
- # df = pd.DataFrame(datas)
88
- # df.to_csv('./results/predict_test.csv', index=None)
89
-
90
- # print(df)
91
- return datas
92
-
93
- except Exception as e:
94
- print(e)
95
- return {'Error_message': e}
96
-
97
-
98
-
99
-
100
-
101
-