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)