Mimic4Dataset / check_config.py
thbndi's picture
Upload 4 files
cb07198
raw
history blame
6.54 kB
def check_config(task,config_file):
with open(config_file) as f:
config = yaml.safe_load(f)
if task=='Phenotype':
disease_label = config['disease_label']
else :
disease_label = ""
time = config['timePrediction']
label = task
timeW = config['timeWindow']
include=int(timeW.split()[1])
bucket = config['timebucket']
radimp = config['radimp']
predW = config['predW']
disease_filter = config['disease_filter']
icu_no_icu = config['icu_no_icu']
groupingDiag = config['groupingDiag']
assert( icu_no_icu in ['ICU','Non-ICU' ], "Chossen data should be one of the following: ICU, Non-ICU")
data_icu = icu_no_icu=='ICU'
if data_icu:
chart_flag = config['chart']
output_flag = config['output']
select_chart = config['select_chart']
lab_flag = False
select_lab = False
else:
lab_flag =config['lab']
select_lab = config['select_lab']
groupingMed = config['groupingMed']
groupingProc = config['groupingProc']
chart_flag = False
output_flag = False
select_chart = False
diag_flag= config['diagnosis']
proc_flag = config['proc']
meds_flag = config['meds']
select_diag= config['select_diag']
select_med= config['select_med']
select_proc= config['select_proc']
select_out = config['select_out']
outlier_removal=config['outlier_removal']
thresh=config['outlier']
left_thresh=config['left_outlier']
if data_icu:
assert (isinstance(select_diag,bool) and isinstance(select_med,bool) and isinstance(select_proc,bool) and isinstance(select_out,bool) and isinstance(select_chart,bool), " select_diag, select_chart, select_med, select_proc, select_out should be boolean")
assert (isinstance(chart_flag,bool) and isinstance(output_flag,bool) and isinstance(diag_flag,bool) and isinstance(proc_flag,bool) and isinstance(meds_flag,bool), "chart_flag, output_flag, diag_flag, proc_flag, meds_flag should be boolean")
else:
assert (isinstance(select_diag,bool) and isinstance(select_med,bool) and isinstance(select_proc,bool) and isinstance(select_out,bool) and isinstance(select_lab,bool), " select_diag, select_lab, select_med, select_proc, select_out should be boolean")
assert (isinstance(lab_flag,bool) and isinstance(diag_flag,bool) and isinstance(proc_flag,bool) and isinstance(meds_flag,bool), "lab_flag, diag_flag, proc_flag, meds_flag should be boolean")
if task=='Phenotype':
if disease_label=='Heart Failure':
label='Readmission'
time=30
disease_label='I50'
elif disease_label=='CAD':
label='Readmission'
time=30
disease_label='I25'
elif disease_label=='CKD':
label='Readmission'
time=30
disease_label='N18'
elif disease_label=='COPD':
label='Readmission'
time=30
disease_label='J44'
else :
raise ValueError('Disease label not correct provide one in the list: Heart Failure, CAD, CKD, COPD')
predW=0
assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
elif task=='Mortality':
time=0
label= 'Mortality'
assert (predW<=8 and predW>=2, "Prediction window should be between 2 and 8")
assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between First 24 and First 72")
elif task=='Length_of_Stay':
label= 'Length of Stay'
assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between Fisrt 24 and Fisrt 72")
assert (time<=10 and time>=1, "Length of stay should be between 1 and 10")
predW=0
elif task=='Readmission':
label= 'Readmission'
assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
assert (time<=150 and time>=10 and time%10==0, "Readmission window should be between 10 and 150 with a step of 10")
predW=0
else:
raise ValueError('Task not correct')
assert( disease_filter in ['Heart Failure','COPD','CKD','CAD',""], "Disease filter should be one of the following: Heart Failure, COPD, CKD, CAD or empty")
assert( groupingDiag in ['Convert ICD-9 to ICD-10 and group ICD-10 codes','Keep both ICD-9 and ICD-10 codes','Convert ICD-9 to ICD-10 codes'], "Grouping ICD should be one of the following: Convert ICD-9 to ICD-10 and group ICD-10 codes, Keep both ICD-9 and ICD-10 codes, Convert ICD-9 to ICD-10 codes")
assert (bucket<=6 and bucket>=1 and isinstance(bucket, int), "Time bucket should be between 1 and 6 and an integer")
assert (radimp in ['No Imputation', 'forward fill and mean','forward fill and median'], "imputation should be one of the following: No Imputation, forward fill and mean, forward fill and median")
if chart_flag:
assert (left_thresh>=0 and left_thresh<=10 and isinstance(left_thresh, int), "Left outlier threshold should be between 0 and 10 and an integer")
assert (thresh>=90 and thresh<=99 and isinstance(thresh, int), "Outlier threshold should be between 90 and 99 and an integer")
assert (outlier_removal in ['No outlier detection','Impute Outlier (default:98)','Remove outliers (default:98)'], "Outlier removal should be one of the following: No outlier detection, Impute Outlier (default:98), Remove outliers (default:98)")
if lab_flag:
assert (left_thresh>=0 and left_thresh<=10 and isinstance(left_thresh, int), "Left outlier threshold should be between 0 and 10 and an integer")
assert (thresh>=90 and thresh<=99 and isinstance(thresh, int), "Outlier threshold should be between 90 and 99 and an integer")
assert (outlier_removal in ['No outlier detection','Impute Outlier (default:98)','Remove outliers (default:98)'], "Outlier removal should be one of the following: No outlier detection, Impute Outlier (default:98), Remove outliers (default:98)")
assert (groupingProc in ['ICD-9 and ICD-10','ICD-10'], "Grouping procedure should be one of the following: ICD-9 and ICD-10, ICD-10")
assert (groupingMed in ['Yes','No'], "Do you want to group Medication codes to use Non propietary names? : Grouping medication should be one of the following: Yes, No")
return label, time, disease_label, predW