-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.py
63 lines (41 loc) · 1.27 KB
/
score.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 numpy as np
import pandas as pd
import os
DiseaseEffect = pd.read_csv('DiseaseEffect.csv', low_memory=False)
DiseaseEffect.set_index(['Disease Name'], inplace=True)
DrugEffect = pd.read_csv('DrugEffect.csv', low_memory=False)
DrugEffect.set_index(['Generic Name'], inplace=True)
LabName = list(DiseaseEffect)
threshold = 1.0
def ComputeScore(DiV, DrV):
effect = 0
for lab in LabName:
DrE = DrV.loc[lab]
if DrE !=0:
DrE = DrE/abs(DrE)
DiE = DiV.loc[lab]
# effect = effect + DrE*DiE
if (DiE==1.0 and DrE==-1.0) or (DiE==-1.0 and DrE==1.0):
effect = effect + 1.0
# elif (DiE==1.0 and DrE==1.0) or (DiE==-1.0 and DrE==-1.0):
# effect = effect + 1.0
# elif (DiE==0.0 and DrE==1.0) or (DiE==0.0 and DrE==-1.0):
# effect = effect + 0.5
return effect
DiseaseName = DiseaseEffect.index.tolist()
DiseaseName.sort()
DrugName = DrugEffect.index.tolist()
DrugName.sort()
score = []
for din in DiseaseName:
s = []
DiseaseVector = DiseaseEffect.loc[din]
for drn in DrugName:
DrugVector = DrugEffect.loc[drn]
e = ComputeScore(DiseaseVector, DrugVector)
s.append(e)
score.append(s)
score = np.array(score).transpose()
score = pd.DataFrame(score, index=DrugName, columns=DiseaseName)
score.index.name = 'Generic Name'
score.to_csv('Drug2Disease5.csv')