thbndi commited on
Commit
062ef7b
1 Parent(s): 99968d8

Update day_intervals_cohort_v22.py

Browse files
Files changed (1) hide show
  1. day_intervals_cohort_v22.py +5 -5
day_intervals_cohort_v22.py CHANGED
@@ -249,7 +249,7 @@ def get_case_ctrls(df:pd.DataFrame, gap:int, group_col:str, visit_col:str, admit
249
  # print(f"[ {gap.days} DAYS ] {invalid.shape[0]} hadm_ids are invalid")
250
 
251
 
252
- def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir, disease_label, cohort_output=None, summary_output=None):
253
  """Extracts cohort data and summary from MIMIC-IV data based on provided parameters.
254
 
255
  Parameters:
@@ -257,7 +257,7 @@ def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir, disea
257
  summary_output: name of summary output file
258
  use_ICU: state whether to use ICU patient data or not
259
  label: Can either be '{day} day Readmission' or 'Mortality', decides what binary data label signifies"""
260
- print("===========MIMIC-IV v2.0============")
261
  if not cohort_output:
262
  cohort_output="cohort_" + use_ICU.lower() + "_" + label.lower().replace(" ", "_") + "_" + str(time) + "_" + disease_label
263
  if not summary_output:
@@ -307,7 +307,7 @@ def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir, disea
307
  death_col='dod'
308
 
309
  pts = get_visit_pts(
310
- mimic4_path=root_dir+'/',
311
  group_col=group_col,
312
  visit_col=visit_col,
313
  admit_col=admit_col,
@@ -340,7 +340,7 @@ def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir, disea
340
  #print(cohort.head())
341
 
342
  if use_disease:
343
- hids=disease_cohort.extract_diag_cohort(cohort['hadm_id'],icd_code,root_dir+"/mimiciv/2.0/")
344
  #print(hids.shape)
345
  #print(cohort.shape)
346
  #print(len(list(set(hids['hadm_id'].unique()).intersection(set(cohort['hadm_id'].unique())))))
@@ -350,7 +350,7 @@ def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir, disea
350
  #print(cohort[cols].head())
351
  # save output
352
  cohort=cohort.rename(columns={"race":"ethnicity"})
353
- cohort[cols].to_csv(root_dir+"/data/cohort/"+cohort_output+".csv.gz", index=False, compression='gzip')
354
  print("[ COHORT SUCCESSFULLY SAVED ]")
355
 
356
  summary = "\n".join([
 
249
  # print(f"[ {gap.days} DAYS ] {invalid.shape[0]} hadm_ids are invalid")
250
 
251
 
252
+ def extract_data(use_ICU:str, label:str, time:int, icd_code:str, root_dir,mimic_path, disease_label, cohort_output=None, summary_output=None):
253
  """Extracts cohort data and summary from MIMIC-IV data based on provided parameters.
254
 
255
  Parameters:
 
257
  summary_output: name of summary output file
258
  use_ICU: state whether to use ICU patient data or not
259
  label: Can either be '{day} day Readmission' or 'Mortality', decides what binary data label signifies"""
260
+ print("===========MIMIC-IV v2============")
261
  if not cohort_output:
262
  cohort_output="cohort_" + use_ICU.lower() + "_" + label.lower().replace(" ", "_") + "_" + str(time) + "_" + disease_label
263
  if not summary_output:
 
307
  death_col='dod'
308
 
309
  pts = get_visit_pts(
310
+ mimic4_path=mimic_path,
311
  group_col=group_col,
312
  visit_col=visit_col,
313
  admit_col=admit_col,
 
340
  #print(cohort.head())
341
 
342
  if use_disease:
343
+ hids=disease_cohort.extract_diag_cohort(cohort['hadm_id'],icd_code,mimic_path)
344
  #print(hids.shape)
345
  #print(cohort.shape)
346
  #print(len(list(set(hids['hadm_id'].unique()).intersection(set(cohort['hadm_id'].unique())))))
 
350
  #print(cohort[cols].head())
351
  # save output
352
  cohort=cohort.rename(columns={"race":"ethnicity"})
353
+ cohort[cols].to_csv("./data/cohort/"+cohort_output+".csv.gz", index=False, compression='gzip')
354
  print("[ COHORT SUCCESSFULLY SAVED ]")
355
 
356
  summary = "\n".join([