File size: 5,649 Bytes
93f39a5
 
 
 
 
dde9150
93f39a5
 
99968d8
0cc84da
69b326a
708ec90
a76ba54
69b326a
308b959
b450020
d2c8b8c
271c4c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25e2a05
271c4c4
25e2a05
271c4c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6a588c
271c4c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1fc3b9c
 
69b326a
 
1fc3b9c
 
 
 
4d0cd0d
 
 
 
d17168a
69b326a
 
 
 
1fc3b9c
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
import ipywidgets as widgets
import sys
from pathlib import Path
import os
import importlib
import shutil
import time
import yaml
import os

def task_cohort(task,mimic_path,path_benchmark, config_path):
    root_dir = os.path.dirname(os.path.abspath('UserInterface.ipynb'))
    config_path='./config/'+config_path
    with open(config_path) as f:
        config = yaml.safe_load(f)
    version_path = mimic_path+'/'
    version = mimic_path.split('/')[-1][0]
    start = time.time()
    #----------------------------------------------config----------------------------------------------------
    disease_label =  config['disease_label']
    tim = config['time']
    label = config['label']
    timeW = config['timeW']
    include=int(timeW.split()[1])
    bucket = config['bucket']
    radimp = config['radimp']
    predW = config['predW']
    diag_flag = config['diagnosis']
    out_flag = config['output']
    chart_flag = config['chart']
    proc_flag= config['proc']
    med_flag = config['meds']
    disease_filter = config['disease_filter']
    icu_no_icu = config['icu_no_icu']
    groupingICD = config['groupingICD']
    # -------------------------------------------------------------------------------------------------------------

    data_icu=icu_no_icu=="ICU"
    data_mort=label=="Mortality"
    data_admn=label=='Readmission'
    data_los=label=='Length of Stay'

    if (disease_filter=="Heart Failure"):
        icd_code='I50'
    elif (disease_filter=="CKD"):
        icd_code='N18'
    elif (disease_filter=="COPD"):
        icd_code='J44'
    elif (disease_filter=="CAD"):
        icd_code='I25'
    else:
        icd_code='No Disease Filter'

    #-----------------------------------------------EXTRACT MIMIC-----------------------------------------------------
    if version == '2':
        cohort_output = day_intervals_cohort_v22.extract_data(icu_no_icu,label,tim,icd_code, root_dir,version_path,disease_label)
    elif version == '1':
        cohort_output = day_intervals_cohort.extract_data(icu_no_icu,label,tim,icd_code, root_dir,version_path,disease_label)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    #----------------------------------------------FEATURES-------------------------------------------------------
    if data_icu :
        feature_selection_icu.feature_icu(cohort_output, version_path,diag_flag,out_flag,chart_flag,proc_flag,med_flag)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    #----------------------------------------------GROUPING-------------------------------------------------------
    group_diag=False
    group_med=False
    group_proc=False
    if data_icu:
        if diag_flag:
            group_diag=groupingICD
        feature_selection_icu.preprocess_features_icu(cohort_output, diag_flag, group_diag,False,False,False,0,0)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    #----------------------------------------------SUMMARY-------------------------------------------------------
    if data_icu:
        feature_selection_icu.generate_summary_icu(diag_flag,proc_flag,med_flag,out_flag,chart_flag)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    #----------------------------------------------FEATURE SELECTION---------------------------------------------

    select_diag= config['select_diag']
    select_med= config['select_med']
    select_proc=  config['select_proc']
    #select_lab= config['select_lab']
    select_out= config['select_out']
    select_chart=  config['select_chart']

    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)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    #---------------------------------------CLEANING OF FEATURES-----------------------------------------------
    thresh=0
    if data_icu:
        if chart_flag:
            outlier_removal=config['outlier_removal']
            clean_chart=outlier_removal!='No outlier detection'
            impute_outlier_chart=outlier_removal=='Impute Outlier (default:98)'
            thresh=config['outlier']
            left_thresh=config['left_outlier']
        feature_selection_icu.preprocess_features_icu(cohort_output, False, False,chart_flag,clean_chart,impute_outlier_chart,thresh,left_thresh)
    end = time.time()
    print("Time elapsed : ", round((end - start)/60,2),"mins")
    # ---------------------------------------tim-Series Representation--------------------------------------------
    if radimp == 'forward fill and mean' :
        impute='Mean'
    elif radimp =='forward fill and median':
        impute = 'Median'
    else :
        impute = False
    
    if data_icu:
        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)
    print("[============TASK COHORT SUCCESSFULLY CREATED============]")

if __name__ == '__main__':
    
    
    task = sys.argv[1]
    mimic_path = sys.argv[2]
    path_benchmark = sys.argv[3]
    config = sys.argv[4]
    sys.path.append('./preprocessing/day_intervals_preproc')
    sys.path.append('./utils')
    sys.path.append('./preprocessing/hosp_module_preproc')
    sys.path.append('./model')
    import day_intervals_cohort_v22
    import day_intervals_cohort
    import feature_selection_icu
    import data_generation_icu_modify
    
    task_cohort(task, mimic_path, path_benchmark, config)