Update task_cohort.py
Browse files- task_cohort.py +121 -1
task_cohort.py
CHANGED
|
@@ -2,11 +2,131 @@ import os
|
|
| 2 |
import sys
|
| 3 |
import yaml
|
| 4 |
import time
|
| 5 |
-
from .check_config import check_config_file
|
| 6 |
from .day_intervals_cohort_v22 import *
|
| 7 |
from .data_generation_icu_modify import *
|
| 8 |
from .data_generation_modify import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def task_cohort(task, mimic_path, config_path):
|
| 11 |
sys.path.append('./preprocessing/day_intervals_preproc')
|
| 12 |
sys.path.append('./utils')
|
|
|
|
| 2 |
import sys
|
| 3 |
import yaml
|
| 4 |
import time
|
|
|
|
| 5 |
from .day_intervals_cohort_v22 import *
|
| 6 |
from .data_generation_icu_modify import *
|
| 7 |
from .data_generation_modify import *
|
| 8 |
+
import yaml
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
def check_config_file(task,config_file):
|
| 12 |
+
with open(config_file) as f:
|
| 13 |
+
config = yaml.safe_load(f)
|
| 14 |
|
| 15 |
+
if task=='Phenotype':
|
| 16 |
+
disease_label = config['disease_label']
|
| 17 |
+
else :
|
| 18 |
+
disease_label = ""
|
| 19 |
+
time = config['timePrediction']
|
| 20 |
+
label = task
|
| 21 |
+
timeW = config['timeWindow']
|
| 22 |
+
include=int(timeW.split()[1])
|
| 23 |
+
bucket = config['timebucket']
|
| 24 |
+
radimp = config['radimp']
|
| 25 |
+
predW = config['predW']
|
| 26 |
+
disease_filter = config['disease_filter']
|
| 27 |
+
icu_no_icu = config['icu_no_icu']
|
| 28 |
+
groupingDiag = config['groupingDiag']
|
| 29 |
+
|
| 30 |
+
assert( icu_no_icu in ['ICU','Non-ICU' ], "Chossen data should be one of the following: ICU, Non-ICU")
|
| 31 |
+
data_icu = icu_no_icu=='ICU'
|
| 32 |
+
|
| 33 |
+
if data_icu:
|
| 34 |
+
chart_flag = config['chart']
|
| 35 |
+
output_flag = config['output']
|
| 36 |
+
select_chart = config['select_chart']
|
| 37 |
+
lab_flag = False
|
| 38 |
+
select_lab = False
|
| 39 |
+
else:
|
| 40 |
+
lab_flag =config['lab']
|
| 41 |
+
select_lab = config['select_lab']
|
| 42 |
+
groupingMed = config['groupingMed']
|
| 43 |
+
groupingProc = config['groupingProc']
|
| 44 |
+
chart_flag = False
|
| 45 |
+
output_flag = False
|
| 46 |
+
select_chart = False
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
diag_flag= config['diagnosis']
|
| 50 |
+
proc_flag = config['proc']
|
| 51 |
+
meds_flag = config['meds']
|
| 52 |
+
select_diag= config['select_diag']
|
| 53 |
+
select_med= config['select_med']
|
| 54 |
+
select_proc= config['select_proc']
|
| 55 |
+
select_out = config['select_out']
|
| 56 |
+
|
| 57 |
+
outlier_removal=config['outlier_removal']
|
| 58 |
+
thresh=config['outlier']
|
| 59 |
+
left_thresh=config['left_outlier']
|
| 60 |
+
|
| 61 |
+
if data_icu:
|
| 62 |
+
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")
|
| 63 |
+
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")
|
| 64 |
+
|
| 65 |
+
else:
|
| 66 |
+
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")
|
| 67 |
+
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")
|
| 68 |
+
|
| 69 |
+
if task=='Phenotype':
|
| 70 |
+
if disease_label=='Heart Failure':
|
| 71 |
+
label='Readmission'
|
| 72 |
+
time=30
|
| 73 |
+
disease_label='I50'
|
| 74 |
+
elif disease_label=='CAD':
|
| 75 |
+
label='Readmission'
|
| 76 |
+
time=30
|
| 77 |
+
disease_label='I25'
|
| 78 |
+
elif disease_label=='CKD':
|
| 79 |
+
label='Readmission'
|
| 80 |
+
time=30
|
| 81 |
+
disease_label='N18'
|
| 82 |
+
elif disease_label=='COPD':
|
| 83 |
+
label='Readmission'
|
| 84 |
+
time=30
|
| 85 |
+
disease_label='J44'
|
| 86 |
+
else :
|
| 87 |
+
raise ValueError('Disease label not correct provide one in the list: Heart Failure, CAD, CKD, COPD')
|
| 88 |
+
predW=0
|
| 89 |
+
assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
|
| 90 |
+
|
| 91 |
+
elif task=='Mortality':
|
| 92 |
+
time=0
|
| 93 |
+
label= 'Mortality'
|
| 94 |
+
assert (predW<=8 and predW>=2, "Prediction window should be between 2 and 8")
|
| 95 |
+
assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between First 24 and First 72")
|
| 96 |
+
|
| 97 |
+
elif task=='Length_of_Stay':
|
| 98 |
+
label= 'Length of Stay'
|
| 99 |
+
assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between Fisrt 24 and Fisrt 72")
|
| 100 |
+
assert (time<=10 and time>=1, "Length of stay should be between 1 and 10")
|
| 101 |
+
predW=0
|
| 102 |
+
|
| 103 |
+
elif task=='Readmission':
|
| 104 |
+
label= 'Readmission'
|
| 105 |
+
assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
|
| 106 |
+
assert (time<=150 and time>=10 and time%10==0, "Readmission window should be between 10 and 150 with a step of 10")
|
| 107 |
+
predW=0
|
| 108 |
+
|
| 109 |
+
else:
|
| 110 |
+
raise ValueError('Task not correct')
|
| 111 |
+
|
| 112 |
+
assert( disease_filter in ['Heart Failure','COPD','CKD','CAD',""], "Disease filter should be one of the following: Heart Failure, COPD, CKD, CAD or empty")
|
| 113 |
+
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")
|
| 114 |
+
assert (bucket<=6 and bucket>=1 and isinstance(bucket, int), "Time bucket should be between 1 and 6 and an integer")
|
| 115 |
+
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")
|
| 116 |
+
if chart_flag:
|
| 117 |
+
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")
|
| 118 |
+
assert (thresh>=90 and thresh<=99 and isinstance(thresh, int), "Outlier threshold should be between 90 and 99 and an integer")
|
| 119 |
+
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)")
|
| 120 |
+
if lab_flag:
|
| 121 |
+
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")
|
| 122 |
+
assert (thresh>=90 and thresh<=99 and isinstance(thresh, int), "Outlier threshold should be between 90 and 99 and an integer")
|
| 123 |
+
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)")
|
| 124 |
+
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")
|
| 125 |
+
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")
|
| 126 |
+
|
| 127 |
+
return label, time, disease_label, predW
|
| 128 |
+
|
| 129 |
+
|
| 130 |
def task_cohort(task, mimic_path, config_path):
|
| 131 |
sys.path.append('./preprocessing/day_intervals_preproc')
|
| 132 |
sys.path.append('./utils')
|