thbndi commited on
Commit
ac6bc3f
·
1 Parent(s): b3f2d1d

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +102 -16
Mimic4Dataset.py CHANGED
@@ -39,6 +39,97 @@ _CONFIG_URLS = {'los' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/re
39
  'readmission' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/readmission.config'
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def create_vocab(file,task):
43
  with open ('./data/dict/'+task+'/'+file, 'rb') as fp:
44
  condVocab = pickle.load(fp)
@@ -392,14 +483,11 @@ def task_cohort(task, mimic_path, config_path):
392
  version = mimic_path.split('/')[-1][0]
393
  start = time.time()
394
  #----------------------------------------------config----------------------------------------------------
395
- disease_label = config['disease_label']
396
- tim = config['time']
397
- label = config['label']
398
- timeW = config['timeW']
399
  include=int(timeW.split()[1])
400
- bucket = config['bucket']
401
  radimp = config['radimp']
402
- predW = config['predW']
403
  diag_flag = config['diagnosis']
404
  out_flag = config['output']
405
  chart_flag = config['chart']
@@ -408,6 +496,14 @@ def task_cohort(task, mimic_path, config_path):
408
  disease_filter = config['disease_filter']
409
  icu_no_icu = config['icu_no_icu']
410
  groupingICD = config['groupingICD']
 
 
 
 
 
 
 
 
411
  # -------------------------------------------------------------------------------------------------------------
412
 
413
  data_icu=icu_no_icu=="ICU"
@@ -437,9 +533,6 @@ def task_cohort(task, mimic_path, config_path):
437
  if data_icu :
438
  feature_selection_icu.feature_icu(cohort_output, version_path,diag_flag,out_flag,chart_flag,proc_flag,med_flag)
439
  #----------------------------------------------GROUPING-------------------------------------------------------
440
- group_diag=False
441
- group_med=False
442
- group_proc=False
443
  if data_icu:
444
  if diag_flag:
445
  group_diag=groupingICD
@@ -449,13 +542,6 @@ def task_cohort(task, mimic_path, config_path):
449
  feature_selection_icu.generate_summary_icu(diag_flag,proc_flag,med_flag,out_flag,chart_flag)
450
  #----------------------------------------------FEATURE SELECTION---------------------------------------------
451
 
452
- select_diag= config['select_diag']
453
- select_med= config['select_med']
454
- select_proc= config['select_proc']
455
- #select_lab= config['select_lab']
456
- select_out= config['select_out']
457
- select_chart= config['select_chart']
458
-
459
  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)
460
  #---------------------------------------CLEANING OF FEATURES-----------------------------------------------
461
  thresh=0
 
39
  'readmission' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/readmission.config'
40
  }
41
 
42
+
43
+
44
+ def check_config(task,config_file):
45
+ with open(config_file) as f:
46
+ config = yaml.safe_load(f)
47
+
48
+ disease_label = config['disease_label']
49
+ time = config['timePrediction']
50
+ label = task
51
+ timeW = config['timeWindow']
52
+ include=int(timeW.split()[1])
53
+ bucket = config['timebucket']
54
+ radimp = config['radimp']
55
+ predW = config['predW']
56
+ disease_filter = config['disease_filter']
57
+ icu_no_icu = config['icu_no_icu']
58
+ groupingICD = config['groupingICD']
59
+
60
+ chart_flag = config['chart']
61
+ output_flag = config['output']
62
+ diag_flag= config['diagnosis']
63
+ proc_flag = config['proc']
64
+ meds_flag = config['meds']
65
+
66
+ select_diag= config['select_diag']
67
+ select_med= config['select_med']
68
+ select_proc= config['select_proc']
69
+ select_out = config['select_out']
70
+ select_chart = config['select_chart']
71
+
72
+ outlier_removal=config['outlier_removal']
73
+ thresh=config['outlier']
74
+ left_thresh=config['left_outlier']
75
+
76
+ 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")
77
+ 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")
78
+ if task=='Phenotype':
79
+ if disease_label=='Heart Failure':
80
+ label='Readmission'
81
+ time=30
82
+ disease_label='I50'
83
+ elif disease_label=='CAD':
84
+ label='Readmission'
85
+ time=30
86
+ disease_label='I25'
87
+ elif disease_label=='CKD':
88
+ label='Readmission'
89
+ time=30
90
+ disease_label='N18'
91
+ elif disease_label=='COPD':
92
+ label='Readmission'
93
+ time=30
94
+ disease_label='J44'
95
+ else :
96
+ raise ValueError('Disease label not correct provide one in the list: Heart Failure, CAD, CKD, COPD')
97
+ predW=0
98
+ assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
99
+
100
+ elif task=='Mortality':
101
+ time=0
102
+ disease_label=""
103
+ assert (predW<=8 and predW>=2, "Prediction window should be between 2 and 8")
104
+ assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between First 24 and First 72")
105
+
106
+ elif task=='Length of Stay':
107
+ disease_label=""
108
+ assert (timeW[0]=='Fisrt' and include<=72 and include>=24, "Time window should be between Fisrt 24 and Fisrt 72")
109
+ assert (time<=10 and time>=1, "Length of stay should be between 1 and 10")
110
+ predW=0
111
+
112
+ elif task=='Readmission':
113
+ disease_label=""
114
+ assert (timeW[0]=='Last' and include<=72 and include>=24, "Time window should be between Last 24 and Last 72")
115
+ assert (time<=150 and time>=10 and time%10==0, "Readmission window should be between 10 and 150 with a step of 10")
116
+ predW=0
117
+
118
+ else:
119
+ raise ValueError('Task not correct')
120
+
121
+ assert( disease_filter in ['Heart Failure','COPD','CKD','CAD',""], "Disease filter should be one of the following: Heart Failure, COPD, CKD, CAD or empty")
122
+ assert( icu_no_icu in ['ICU'], "Dataset currently only supports ICU data")
123
+ assert( groupingICD 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")
124
+ assert (bucket<=6 and bucket>=1 and isinstance(bucket, int), "Time bucket should be between 1 and 6 and an integer")
125
+ 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")
126
+ if chart_flag:
127
+ 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")
128
+ assert (thresh>=90 and thresh<=99 and isinstance(thresh, int), "Outlier threshold should be between 90 and 99 and an integer")
129
+ 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)")
130
+
131
+ return label, time, disease_label, predW
132
+
133
  def create_vocab(file,task):
134
  with open ('./data/dict/'+task+'/'+file, 'rb') as fp:
135
  condVocab = pickle.load(fp)
 
483
  version = mimic_path.split('/')[-1][0]
484
  start = time.time()
485
  #----------------------------------------------config----------------------------------------------------
486
+ label, tim, disease_label, predW = check_config(task,config)
487
+ timeW = config['timeWindow']
 
 
488
  include=int(timeW.split()[1])
489
+ bucket = config['timebucket']
490
  radimp = config['radimp']
 
491
  diag_flag = config['diagnosis']
492
  out_flag = config['output']
493
  chart_flag = config['chart']
 
496
  disease_filter = config['disease_filter']
497
  icu_no_icu = config['icu_no_icu']
498
  groupingICD = config['groupingICD']
499
+
500
+ select_diag= config['select_diag']
501
+ select_med= config['select_med']
502
+ select_proc= config['select_proc']
503
+ #select_lab= config['select_lab']
504
+ select_out= config['select_out']
505
+ select_chart= config['select_chart']
506
+
507
  # -------------------------------------------------------------------------------------------------------------
508
 
509
  data_icu=icu_no_icu=="ICU"
 
533
  if data_icu :
534
  feature_selection_icu.feature_icu(cohort_output, version_path,diag_flag,out_flag,chart_flag,proc_flag,med_flag)
535
  #----------------------------------------------GROUPING-------------------------------------------------------
 
 
 
536
  if data_icu:
537
  if diag_flag:
538
  group_diag=groupingICD
 
542
  feature_selection_icu.generate_summary_icu(diag_flag,proc_flag,med_flag,out_flag,chart_flag)
543
  #----------------------------------------------FEATURE SELECTION---------------------------------------------
544
 
 
 
 
 
 
 
 
545
  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)
546
  #---------------------------------------CLEANING OF FEATURES-----------------------------------------------
547
  thresh=0