Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +12 -23
Mimic4Dataset.py
CHANGED
@@ -569,8 +569,8 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
569 |
raise ValueError('Please provide a config file')
|
570 |
|
571 |
version = self.mimic_path.split('/')[-1]
|
572 |
-
|
573 |
-
|
574 |
|
575 |
current_directory = os.getcwd()
|
576 |
if os.path.exists(os.path.dirname(current_directory)+'/MIMIC-IV-Data-Pipeline-main'):
|
@@ -578,7 +578,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
578 |
os.chdir(dir)
|
579 |
else:
|
580 |
#move to parent directory of mimic data
|
581 |
-
dir = self.mimic_path.replace(
|
582 |
if dir[-1]!='/':
|
583 |
dir=dir+'/'
|
584 |
elif dir=='':
|
@@ -586,7 +586,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
586 |
parent_dir = os.path.dirname(self.mimic_path)
|
587 |
os.chdir(parent_dir)
|
588 |
|
589 |
-
|
590 |
repo_url='https://github.com/healthylaife/MIMIC-IV-Data-Pipeline'
|
591 |
if os.path.exists('MIMIC-IV-Data-Pipeline-main'):
|
592 |
path_bench = './MIMIC-IV-Data-Pipeline-main'
|
@@ -599,6 +599,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
599 |
os.chdir(path_bench)
|
600 |
self.mimic_path = './mimic-iv/'+version
|
601 |
|
|
|
602 |
#download config file if not custom
|
603 |
if self.config_path[0:4] == 'http':
|
604 |
c = self.config_path.split('/')[-1]
|
@@ -606,16 +607,18 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
606 |
else :
|
607 |
file_path = self.config_path
|
608 |
|
609 |
-
#create config folder
|
610 |
if not os.path.exists('./config'):
|
611 |
os.makedirs('config')
|
612 |
#save config file in config folder
|
613 |
conf='./config/'+file_path.split('/')[-1]
|
614 |
-
|
615 |
if not os.path.exists(conf):
|
616 |
shutil.move(file_path,'./config')
|
|
|
|
|
|
|
617 |
|
618 |
-
|
|
|
619 |
if not os.path.exists('./model/data_generation_icu_modify.py'):
|
620 |
file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
|
621 |
shutil.move(file_path, './model')
|
@@ -624,27 +627,14 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
624 |
file_path, head = urlretrieve(_DAY_INT, "day_intervals_cohort_v22.py")
|
625 |
shutil.move(file_path, './preprocessing/day_intervals_preproc')
|
626 |
|
627 |
-
#file_path, head = urlretrieve(_COHORT, "cohort.py")
|
628 |
-
#if not os.path.exists('cohort.py'):
|
629 |
-
# shutil.move(file_path, './')
|
630 |
-
|
631 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")+"/dataDic"
|
632 |
sys.path.append(path_bench)
|
633 |
config = self.config_path.split('/')[-1]
|
634 |
|
635 |
-
|
636 |
-
|
637 |
-
#####################################CHANGE##########
|
638 |
-
#if not os.path.exists(data_dir) :
|
639 |
-
#os.system(script)
|
640 |
task_cohort(self.config.name.replace(" ","_"),self.mimic_path,config)
|
641 |
-
#####################################CHANGE##########
|
642 |
-
|
643 |
-
config_path='./config/'+config
|
644 |
-
with open(config_path) as f:
|
645 |
-
config = yaml.safe_load(f)
|
646 |
-
feat_cond, feat_chart, feat_proc, feat_meds, feat_out = config['diagnosis'], config['chart'], config['proc'], config['meds'], config['output']
|
647 |
|
|
|
648 |
with open(data_dir, 'rb') as fp:
|
649 |
dataDic = pickle.load(fp)
|
650 |
data = pd.DataFrame.from_dict(dataDic)
|
@@ -669,7 +659,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
669 |
with open(test_path, 'wb') as f:
|
670 |
pickle.dump(test_dic, f)
|
671 |
|
672 |
-
|
673 |
return feat_cond, feat_chart, feat_proc, feat_meds, feat_out, dict_dir
|
674 |
|
675 |
###########################################################RAW##################################################################
|
|
|
569 |
raise ValueError('Please provide a config file')
|
570 |
|
571 |
version = self.mimic_path.split('/')[-1]
|
572 |
+
mimic_folder= self.mimic_path.split('/')[-2]
|
573 |
+
mimic_complete_path='/'+mimic_folder+'/'+version
|
574 |
|
575 |
current_directory = os.getcwd()
|
576 |
if os.path.exists(os.path.dirname(current_directory)+'/MIMIC-IV-Data-Pipeline-main'):
|
|
|
578 |
os.chdir(dir)
|
579 |
else:
|
580 |
#move to parent directory of mimic data
|
581 |
+
dir = self.mimic_path.replace(mimic_complete_path,'')
|
582 |
if dir[-1]!='/':
|
583 |
dir=dir+'/'
|
584 |
elif dir=='':
|
|
|
586 |
parent_dir = os.path.dirname(self.mimic_path)
|
587 |
os.chdir(parent_dir)
|
588 |
|
589 |
+
#####################clone git repo if doesnt exists
|
590 |
repo_url='https://github.com/healthylaife/MIMIC-IV-Data-Pipeline'
|
591 |
if os.path.exists('MIMIC-IV-Data-Pipeline-main'):
|
592 |
path_bench = './MIMIC-IV-Data-Pipeline-main'
|
|
|
599 |
os.chdir(path_bench)
|
600 |
self.mimic_path = './mimic-iv/'+version
|
601 |
|
602 |
+
####################Get configurations param
|
603 |
#download config file if not custom
|
604 |
if self.config_path[0:4] == 'http':
|
605 |
c = self.config_path.split('/')[-1]
|
|
|
607 |
else :
|
608 |
file_path = self.config_path
|
609 |
|
|
|
610 |
if not os.path.exists('./config'):
|
611 |
os.makedirs('config')
|
612 |
#save config file in config folder
|
613 |
conf='./config/'+file_path.split('/')[-1]
|
|
|
614 |
if not os.path.exists(conf):
|
615 |
shutil.move(file_path,'./config')
|
616 |
+
with open(conf) as f:
|
617 |
+
config = yaml.safe_load(f)
|
618 |
+
feat_cond, feat_chart, feat_proc, feat_meds, feat_out = config['diagnosis'], config['chart'], config['proc'], config['meds'], config['output']
|
619 |
|
620 |
+
|
621 |
+
#####################downloads modules from hub
|
622 |
if not os.path.exists('./model/data_generation_icu_modify.py'):
|
623 |
file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
|
624 |
shutil.move(file_path, './model')
|
|
|
627 |
file_path, head = urlretrieve(_DAY_INT, "day_intervals_cohort_v22.py")
|
628 |
shutil.move(file_path, './preprocessing/day_intervals_preproc')
|
629 |
|
|
|
|
|
|
|
|
|
630 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")+"/dataDic"
|
631 |
sys.path.append(path_bench)
|
632 |
config = self.config_path.split('/')[-1]
|
633 |
|
634 |
+
#####################create task cohort
|
|
|
|
|
|
|
|
|
635 |
task_cohort(self.config.name.replace(" ","_"),self.mimic_path,config)
|
|
|
|
|
|
|
|
|
|
|
|
|
636 |
|
637 |
+
#####################Split data into train, test and val
|
638 |
with open(data_dir, 'rb') as fp:
|
639 |
dataDic = pickle.load(fp)
|
640 |
data = pd.DataFrame.from_dict(dataDic)
|
|
|
659 |
with open(test_path, 'wb') as f:
|
660 |
pickle.dump(test_dic, f)
|
661 |
|
|
|
662 |
return feat_cond, feat_chart, feat_proc, feat_meds, feat_out, dict_dir
|
663 |
|
664 |
###########################################################RAW##################################################################
|