-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.py
More file actions
executable file
·63 lines (59 loc) · 2.36 KB
/
Copy pathTask.py
File metadata and controls
executable file
·63 lines (59 loc) · 2.36 KB
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
class Task:
def __init__(self, task_id, experiment, class_list, patients, split, cumm_cls, modelname, prev_modelname,
arrays=""):
self.task_id = task_id
self.experiment = experiment
self.class_list = class_list
self.cumm_cls = cumm_cls
self.modelname = modelname
self.prev_modelname = prev_modelname
self.patients = {}
self.arrays = arrays
if experiment == 1:
for ti, t in enumerate(["trainset", "testset"]):
self.patients[t] = {}
patientlist = split[ti]
for p in patientlist:
r, lbl = self.convert_label(patients[p]["label_conv"])
if r and lbl in self.class_list:
self.patients[t][p] = patients[p]
self.patients[t][p]["label"] = lbl
elif experiment == 2:
for ti, t in enumerate(["trainset", "testset"]):
self.patients[t] = {}
patientlist = split[ti]
for p in patientlist:
if int(patients[p]["array_id"].split("_")[1]) in arrays[ti]:
r, lbl = self.convert_label(patients[p]["label_conv"])
if r and lbl in self.class_list:
self.patients[t][p] = patients[p]
self.patients[t][p]["label"] = lbl
def __str__(self):
ret = "exp: " + str(self.experiment) + " - task: " + str(self.task_id) + str(self.class_list) + str(
len(self.patients["trainset"])) + "," + str(len(self.patients["testset"]))
return ret
def print(self):
tot = 0
for ti, t in enumerate(["trainset", "testset"]):
print(t)
for cls in self.class_list:
c = len([p for p in self.patients[t] if self.patients[t][p]["label"] == cls])
tot += c
print(cls, ": ", c)
@staticmethod
def convert_label(lbl):
label_converter = {
# 'Reactive changes': 0,
'AML': 1,
'CML': 2,
'No evidence': 0,
'CMML': 6,
'CLL': 4,
'MPN': 5,
'MDS': 3,
"Lymphoma": 7
}
if lbl in label_converter.keys():
return True, label_converter[lbl]
else:
return False, ""