thbndi commited on
Commit
def6532
·
1 Parent(s): 83ab5f3

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +14 -28
Mimic4Dataset.py CHANGED
@@ -136,36 +136,24 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
136
  if self.config.name == 'Length of Stay' and self.config_path is None : self.config_path = _CONFIG_URLS['los']
137
  if self.config.name == 'Mortality' and self.config_path is None : self.config_path = _CONFIG_URLS['mortality']
138
 
 
139
  version = self.mimic_path.split('/')[-1]
140
  m = self.mimic_path.split('/')[-2]
141
  s='/'+m+'/'+version
142
  dir = self.mimic_path.replace(s,'')
143
- print('3 : '+os.getcwd())
144
  os.chdir(dir)
145
- print('0 : '+os.getcwd())
146
 
147
 
148
  #clone git repo if doesnt exists
149
  repo_url='https://github.com/healthylaife/MIMIC-IV-Data-Pipeline'
150
  if os.path.exists('MIMIC-IV-Data-Pipeline-main'):
151
- path_bench = os.path.abspath('MIMIC-IV-Data-Pipeline-main')
152
  else:
153
  repodir = os.getcwd()
154
  path_bench = repodir+'/MIMIC-IV-Data-Pipeline-main'
155
  subprocess.run(["git", "clone", repo_url, path_bench])
156
  os.chdir(path_bench)
157
  print('1 : '+ os.getcwd())
158
-
159
-
160
- #move data to mimic-iv folder
161
- #if not os.path.exists(path_bench+'/mimic-iv'):
162
- #os.makedirs(path_bench+'/mimic-iv')
163
- #os.chdir(self.mimic_path.replace(version,''))
164
- #print('2 : '+os.getcwd())
165
- #shutil.move('/'+version, path_bench+'/mimic-iv/'+version)
166
- self.mimic_path = './'+s
167
- #os.chdir(path_bench)
168
- print('3 : '+os.getcwd())
169
 
170
  #download config file if not custom
171
  if self.config_path[0:4] == 'http':
@@ -175,34 +163,32 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
175
  file_path = self.config_path
176
 
177
  #create config folder
178
- if not os.path.exists(path_bench+'/config'):
179
- os.makedirs(path_bench+'/config')
180
  #save config file in config folder
181
- conf=path_bench+'/config/'+file_path.split('/')[-1]
182
  if not os.path.exists(conf):
183
- shutil.move(file_path, path_bench+'/config')
184
 
185
  #downloads modules from hub
186
- if not os.path.exists(path_bench+'/model/data_generation_icu_modify.py'):
187
  file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
188
- shutil.move(file_path, path_bench+'/model')
189
 
190
- if not os.path.exists(path_bench+'/preprocessing/day_intervals_preproc/day_intervals_cohort_v22.py'):
191
  file_path, head = urlretrieve(_DAY_INT, "day_intervals_cohort_v22.py")
192
- shutil.move(file_path, path_bench+'/preprocessing/day_intervals_preproc')
193
 
194
- if not os.path.exists(path_bench+'/cohort.py'):
195
  file_path, head = urlretrieve(_COHORT, "cohort.py")
196
- shutil.move(file_path, path_bench)
197
 
198
- data_dir = path_bench + "/data/dataDic"
199
  sys.path.append(path_bench)
200
  config = self.config_path.split('/')[-1]
201
  script = 'python cohort.py '+ self.config.name +" "+ self.mimic_path+ " "+path_bench+ " "+config
202
  os.system(script)
203
- root = path_bench.replace('/MIMIC-IV-Data-Pipeline-main',"")
204
- os.chdir(root)
205
- print(os.getcwd())
206
  return [
207
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir}),
208
  ]
 
136
  if self.config.name == 'Length of Stay' and self.config_path is None : self.config_path = _CONFIG_URLS['los']
137
  if self.config.name == 'Mortality' and self.config_path is None : self.config_path = _CONFIG_URLS['mortality']
138
 
139
+ #move to parent directory of mimic data
140
  version = self.mimic_path.split('/')[-1]
141
  m = self.mimic_path.split('/')[-2]
142
  s='/'+m+'/'+version
143
  dir = self.mimic_path.replace(s,'')
 
144
  os.chdir(dir)
 
145
 
146
 
147
  #clone git repo if doesnt exists
148
  repo_url='https://github.com/healthylaife/MIMIC-IV-Data-Pipeline'
149
  if os.path.exists('MIMIC-IV-Data-Pipeline-main'):
150
+ path_bench = dir+'MIMIC-IV-Data-Pipeline-main'
151
  else:
152
  repodir = os.getcwd()
153
  path_bench = repodir+'/MIMIC-IV-Data-Pipeline-main'
154
  subprocess.run(["git", "clone", repo_url, path_bench])
155
  os.chdir(path_bench)
156
  print('1 : '+ os.getcwd())
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  #download config file if not custom
159
  if self.config_path[0:4] == 'http':
 
163
  file_path = self.config_path
164
 
165
  #create config folder
166
+ if not os.path.exists('./config'):
167
+ os.makedirs('config')
168
  #save config file in config folder
169
+ conf='./config/'+file_path.split('/')[-1]
170
  if not os.path.exists(conf):
171
+ shutil.move(file_path,'./config')
172
 
173
  #downloads modules from hub
174
+ if not os.path.exists('./model/data_generation_icu_modify.py'):
175
  file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
176
+ shutil.move(file_path, './model')
177
 
178
+ if not os.path.exists('./preprocessing/day_intervals_preproc/day_intervals_cohort_v22.py'):
179
  file_path, head = urlretrieve(_DAY_INT, "day_intervals_cohort_v22.py")
180
+ shutil.move(file_path, './preprocessing/day_intervals_preproc')
181
 
182
+ if not os.path.exists('./cohort.py'):
183
  file_path, head = urlretrieve(_COHORT, "cohort.py")
184
+ shutil.move(file_path, './')
185
 
186
+ data_dir = "./data/dataDic"
187
  sys.path.append(path_bench)
188
  config = self.config_path.split('/')[-1]
189
  script = 'python cohort.py '+ self.config.name +" "+ self.mimic_path+ " "+path_bench+ " "+config
190
  os.system(script)
191
+ print('last pos'+os.getcwd())
 
 
192
  return [
193
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir}),
194
  ]