Update cohort.py
Browse files
cohort.py
CHANGED
@@ -14,7 +14,107 @@ def task_cohort(task,mimic_path,path_benchmark, config_path):
|
|
14 |
config = yaml.safe_load(f)
|
15 |
version_path = mimic_path
|
16 |
version = version_path.split('/')[-1][0]
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
if __name__ == '__main__':
|
20 |
|
|
|
14 |
config = yaml.safe_load(f)
|
15 |
version_path = mimic_path
|
16 |
version = version_path.split('/')[-1][0]
|
17 |
+
start = time.time()
|
18 |
+
#----------------------------------------------config----------------------------------------------------
|
19 |
+
with open(config) as f:
|
20 |
+
config = yaml.safe_load(f)
|
21 |
+
|
22 |
+
disease_label = config['disease_label']
|
23 |
+
tim = config['time']
|
24 |
+
label = config['label']
|
25 |
+
timeW = config['timeW']
|
26 |
+
include=int(timeW.split()[1])
|
27 |
+
bucket = config['bucket']
|
28 |
+
radimp = config['radimp']
|
29 |
+
predW = config['predW']
|
30 |
+
diag_flag = config['diagnosis']
|
31 |
+
out_flag = config['output']
|
32 |
+
chart_flag = config['chart']
|
33 |
+
proc_flag= config['proc']
|
34 |
+
med_flag = config['meds']
|
35 |
+
disease_filter = config['disease_filter']
|
36 |
+
icu_no_icu = config['icu_no_icu']
|
37 |
+
groupingICD = config['groupingICD']
|
38 |
+
# -------------------------------------------------------------------------------------------------------------
|
39 |
+
|
40 |
+
data_icu=icu_no_icu=="ICU"
|
41 |
+
data_mort=label=="Mortality"
|
42 |
+
data_admn=label=='Readmission'
|
43 |
+
data_los=label=='Length of Stay'
|
44 |
+
|
45 |
+
if (disease_filter=="Heart Failure"):
|
46 |
+
icd_code='I50'
|
47 |
+
elif (disease_filter=="CKD"):
|
48 |
+
icd_code='N18'
|
49 |
+
elif (disease_filter=="COPD"):
|
50 |
+
icd_code='J44'
|
51 |
+
elif (disease_filter=="CAD"):
|
52 |
+
icd_code='I25'
|
53 |
+
else:
|
54 |
+
icd_code='No Disease Filter'
|
55 |
+
|
56 |
+
#-----------------------------------------------EXTRACT MIMIC-----------------------------------------------------
|
57 |
+
if version == '2':
|
58 |
+
cohort_output = day_intervals_cohort_v2.extract_data(icu_no_icu,label,tim,icd_code, root_dir,disease_label)
|
59 |
+
elif version == '1':
|
60 |
+
cohort_output = day_intervals_cohort.extract_data(icu_no_icu,label,tim,icd_code, root_dir,disease_label)
|
61 |
+
end = time.time()
|
62 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
63 |
+
#----------------------------------------------FEATURES-------------------------------------------------------
|
64 |
+
if data_icu :
|
65 |
+
feature_selection_icu.feature_icu(cohort_output, version_path,diag_flag,out_flag,chart_flag,proc_flag,med_flag)
|
66 |
+
end = time.time()
|
67 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
68 |
+
#----------------------------------------------GROUPING-------------------------------------------------------
|
69 |
+
group_diag=False
|
70 |
+
group_med=False
|
71 |
+
group_proc=False
|
72 |
+
if data_icu:
|
73 |
+
if diag_flag:
|
74 |
+
group_diag=groupingICD
|
75 |
+
feature_selection_icu.preprocess_features_icu(cohort_output, diag_flag, group_diag,False,False,False,0,0)
|
76 |
+
end = time.time()
|
77 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
78 |
+
#----------------------------------------------SUMMARY-------------------------------------------------------
|
79 |
+
if data_icu:
|
80 |
+
feature_selection_icu.generate_summary_icu(cohort_output,diag_flag,proc_flag,med_flag,out_flag,chart_flag)
|
81 |
+
end = time.time()
|
82 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
83 |
+
#----------------------------------------------FEATURE SELECTION---------------------------------------------
|
84 |
+
|
85 |
+
select_diag= config['select_diag']
|
86 |
+
select_med= config['select_med']
|
87 |
+
select_proc= config['select_proc']
|
88 |
+
#select_lab= config['select_lab']
|
89 |
+
select_out= config['select_out']
|
90 |
+
select_chart= config['select_chart']
|
91 |
+
|
92 |
+
feature_selection_icu.features_selection_icu(cohort_output, diag_flag,proc_flag,med_flag,out_flag, chart_flag,select_diag,select_med,select_proc,select_out,select_chart)
|
93 |
+
end = time.time()
|
94 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
95 |
+
#---------------------------------------CLEANING OF FEATURES-----------------------------------------------
|
96 |
+
thresh=0
|
97 |
+
if data_icu:
|
98 |
+
if chart_flag:
|
99 |
+
outlier_removal=config['outlier_removal']
|
100 |
+
clean_chart=outlier_removal!='No outlier detection'
|
101 |
+
impute_outlier_chart=outlier_removal=='Impute Outlier (default:98)'
|
102 |
+
thresh=config['outlier']
|
103 |
+
left_thresh=config['left_outlier']
|
104 |
+
feature_selection_icu.preprocess_features_icu(cohort_output, False, False,chart_flag,clean_chart,impute_outlier_chart,thresh,left_thresh)
|
105 |
+
end = time.time()
|
106 |
+
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
107 |
+
# ---------------------------------------tim-Series Representation--------------------------------------------
|
108 |
+
if radimp == 'forward fill and mean' :
|
109 |
+
impute='Mean'
|
110 |
+
elif radimp =='forward fill and median':
|
111 |
+
impute = 'Median'
|
112 |
+
else :
|
113 |
+
impute = False
|
114 |
+
|
115 |
+
if data_icu:
|
116 |
+
gen=data_generation_icu_modify.Generator(task,cohort_output,data_mort,data_admn,data_los,diag_flag,proc_flag,out_flag,chart_flag,med_flag,impute,include,bucket,predW)
|
117 |
+
print("[============TASK COHORT SUCCESSFULLY CREATED============]")
|
118 |
|
119 |
if __name__ == '__main__':
|
120 |
|