-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFAERSdata.py
57 lines (36 loc) · 1.45 KB
/
FAERSdata.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
import os
import numpy as np
from tqdm import tqdm
from mapping import sider_eval_pairs, drug2id, adr2id, drug_list, adr_list
class FAERSdata:
def __init__(self, directory, method, year):
Files = os.listdir('%s/%s' % (directory, method))
if year == 'all':
Files = [Files[-1]]
X = {}
Y = {}
Index = {}
for i in tqdm(range(len(Files))):
f = Files[i]
x = np.zeros(shape=(len(drug_list), len(adr_list)))
with open('%s/%s/%s' % (directory, method, f), 'r') as ff:
next(ff)
for line in ff:
line = line.strip('\n')
line = line.split(',')
drug, adr, score = line[0], line[1], round(float(line[2]),5)
drug_id, adr_id = drug2id.get(drug), adr2id.get(adr)
if drug in drug_list and adr in adr_list:
x[drug_id, adr_id] = score
y = np.zeros(shape=(len(drug_list), len(adr_list)))
for drug, adr in sider_eval_pairs:
drug_id, adr_id = drug2id.get(drug), adr2id.get(adr)
y[drug_id, adr_id] = 1
y = np.asarray(y)
index = np.arange(x.shape[0])
X[i] = x
Y[i] = y
Index[i] = index.tolist()
self.X = X
self.Y = Y
self.Index = Index