-
Notifications
You must be signed in to change notification settings - Fork 0
/
genomics.py
173 lines (132 loc) · 5.32 KB
/
genomics.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
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
161
162
163
164
165
166
167
168
169
170
171
172
import pandas as pd
import numpy as np
import scipy.stats as ss
import os
import soug as sg
import evaluation_measures as em
import data_preprocessing as dp
# ______________________________________________________________________________________________________________
#
# PUNISHED ORDERINGS
# ______________________________________________________________________________________________________________
def PO(df, type_punish = 'N', max_ranking = None):
ordering = []
# data pre-processing
# ___________________________________________________________________________
data_features = df.copy()
mydata = df.copy()
mydata = mydata.drop(columns = 'set')
mydata = np.asarray(mydata)
mydata = mydata.astype(int)
# first ranked element
# ___________________________________________________________________________
SV_features = sg.calculate_svs(mydata)
data_features['SV'] = SV_features
which = data_features['SV'].argmax()
ordering.append(which)
# initialization of punishment
# ___________________________________________________________________________
dim = np.shape(mydata)[0]
punish = np.zeros((dim, dim))
y = mydata[which]
for j in range(dim):
x = mydata[j]
if j not in ordering:
punish[:, which][j] = em.jaccard_distance(x,y)
max_svs = []
# recomputation of punishment
# ___________________________________________________________________________
mydata[which] = np.zeros(np.shape(mydata)[1])
if max_ranking == None:
max_ranking = np.shape(mydata)[0]
for j in range(1, max_ranking):
SV_features = sg.calculate_svs(mydata)
SV_sum = np.sum(SV_features)
p_max = np.max(np.sum(punish, axis = 1))
SV_max = np.max(SV_features)
max_svs.append(SV_max)
for o in ordering:
SV_features[o] = -100
if type_punish == 'N':
rescale = 1
elif type_punish == 'R':
rescale = SV_max/p_max
data_features['SV'] = SV_features - (np.sum(punish, axis = 1)*rescale)
which = data_features['SV'].argmax()
ordering.append(which)
y = mydata[which]
for j in range(dim):
x = mydata[j]
if j not in ordering:
punish[:, which][j] = em.jaccard_distance(x,y)
mydata[which] = np.zeros(np.shape(mydata)[1])
return ordering
def AO(df, type_punish = 'N', max_ranking = None):
ordering = []
# data pre-processing
# ___________________________________________________________________________
data_features = df.copy()
mydata = df.copy()
mydata = mydata.drop(columns = 'set')
mydata = np.asarray(mydata)
mydata = mydata.astype(int)
# first ranked element
# ___________________________________________________________________________
SV_features = sg.calculate_svs(mydata)
data_features['SV'] = SV_features
which = data_features['SV'].argmax()
ordering.append(which)
# initialization of punishment
# ___________________________________________________________________________
dim = np.shape(mydata)[0]
punish = np.zeros(dim)
covered = data_features.loc[ordering]
covered.loc[len(ordering), 'set'] = 'AP'
for g in covered.columns:
if not g in ['set', 'SV']:
if covered[g].sum() > 0:
covered.loc[len(covered)-1, g] = 1
else:
covered.loc[len(covered)-1, g] = 0
AP_for_punish = covered[covered.columns.difference(['set', 'SV'])]
y = np.asarray(AP_for_punish.loc[len(AP_for_punish)-1])
for j in range(dim):
x = mydata[j]
if j not in ordering:
punish[j] = em.jaccard_distance(x,y)
max_svs = []
# recomputation of punishment
# ___________________________________________________________________________
mydata[which] = np.zeros(np.shape(mydata)[1])
if max_ranking == None:
max_ranking = np.shape(mydata)[0]
for j in range(1, max_ranking):
SV_features = sg.calculate_svs(mydata)
SV_sum = np.sum(SV_features)
SV_max = np.max(SV_features)
p_max = np.max(punish)
if type_punish == 'N':
rescale = 1
elif type_punish == 'R':
rescale = SV_max/p_max
for o in ordering:
SV_features[o] = -100
data_features['SV'] = SV_features - punish*rescale
which = data_features['SV'].argmax()
ordering.append(which)
covered = data_features.loc[ordering]
covered.loc[len(ordering), 'set'] = 'artificial'
for g in covered.columns:
if not g in ['set', 'SV']:
if covered[g].sum() > 0:
covered.loc[len(covered)-1, g] = 1
else:
covered.loc[len(covered)-1, g] = 0
AP_for_punish = covered[covered.columns.difference(['set', 'SV'])]
y = np.asarray(AP_for_punish.loc[len(AP_for_punish)-1])
for j in range(dim):
x = mydata[j]
if j not in ordering:
punish[j] = em.jaccard_distance(x,y)
mydata[which] = np.zeros(np.shape(mydata)[1])
return ordering