forked from MIT-LCP/mimic-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
391 lines (371 loc) · 15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# Config
PHYSIONETURL=https://physionet.org/works/MIMICIIIClinicalDatabase/files/
PHYSIONETDEMOURL=https://physionet.org/works/MIMICIIIClinicalDatabaseDemo/
# Ensure that datadir ends in a slash
DATADIR := $(dir $(datadir))
ifneq ($(datadir),$(DATADIR))
DATADIR := $(datadir)/
endif
# Set the following parameters to defaults
# These will be overwritten by settings passed to the makefile
DBNAME := mimic
DBUSER := postgres
DBPASS := postgres
DBSCHEMA := mimiciii
# NOTE: you do not need to specify localhost/port
# in fact, this is detrimental if you want to use peer authentication
# "localhost" uses a loopback, so peer authentication doesn't work with it
DBHOST :=
DBPORT :=
# when connecting, we use a single variable: DBSTRING
# **do not modify this**
# the create_mimic_user.sh script uses the above variables to create the DB/users
# so it's important to keep this DBSTRING consistent
DBSTRING := dbname=$(DBNAME) user=$(DBUSER)
ifneq ($(DBHOST),)
DBSTRING += host=$(DBHOST)
endif
ifneq ($(DBPORT),)
DBSTRING += port=$(DBPORT)
endif
ifneq ($(DBPASS),)
DBSTRING += password=$(DBPASS)
endif
# add ON_ERROR_STOP so scripts stop when they fail
DBSTRING += options=--search_path=$(DBSCHEMA)
# if psql version is greater than 10, then we can use declarative partitioning
# this is done in the postgres_create_tables_pg10.sql file
PSQL_SERVER_VERSION := $(shell echo SHOW SERVER_VERSION_NUM | psql "$(DBSTRING)" -At)
PSQL_SERVER_GREATER_THAN_10 := $(shell /usr/bin/test $(PSQL_SERVER_VERSION) -ge 100000 ; echo $$?)
ifeq ($(PSQL_SERVER_GREATER_THAN_10),0)
PSQL_MAJOR_VERSION := _pg10
endif
help:
@echo ' '
@echo '----------------------------------------------------------------------------'
@echo 'Makefile for building MIMIC-III in a local Postgres database '
@echo ' '
@echo 'Usage: '
@echo ' '
@echo ' Build MIMIC-III using the CSV files in the /path/to/data directory - '
@echo ' '
@echo ' make mimic datadir="/path/to/data/" '
@echo ' '
@echo ' e.g. make mimic datadir="/data/mimic/v1_3/" '
@echo ' '
@echo ' Build MIMIC-III using the .csv.gz files in the /path/to/data directory - '
@echo ' '
@echo ' make mimic-gz datadir="/path/to/data/" '
@echo ' '
@echo ' e.g. make mimic-gz datadir="/data/mimic/v1_3/" '
@echo '----------------------------------------------------------------------------'
@echo ' '
mimic-gz: mimic-check-gz mimic-build-gz
mimic: mimic-check mimic-build
create-user:
@echo '-------------------------------------'
@echo '-- Creating user, database, schema --'
@echo '-------------------------------------'
@echo ''
@sleep 2
MIMIC_USER="$(DBUSER)" MIMIC_DB="$(DBNAME)" MIMIC_PASSWORD="$(DBPASS)" MIMIC_SCHEMA="$(DBSCHEMA)" DBHOST="$(DBHOST)" DBPORT="$(DBPORT)" ./create_mimic_user.sh
mimic-build-gz:
@echo '------------------------'
@echo '-- Building MIMIC-III --'
@echo '------------------------'
@echo ''
@echo '---------------------'
@echo '-- Creating schema --'
@echo '---------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -c "DROP SCHEMA IF EXISTS $(DBSCHEMA); CREATE SCHEMA $(DBSCHEMA);"
@echo ''
@echo '---------------------'
@echo '-- Creating tables --'
@echo '---------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_create_tables$(PSQL_MAJOR_VERSION).sql
@echo ''
@echo '------------------'
@echo '-- Loading data --'
@echo '------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data_gz.sql -v mimic_data_dir=${datadir}
@echo ''
@echo '--------------------'
@echo '-- Adding indexes --'
@echo '--------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_add_indexes.sql
@echo ''
@echo '--------------------'
@echo '-- Adding comments --'
@echo '--------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_add_comments.sql
@echo ''
@echo '----------------'
@echo '-- Check data --'
@echo '----------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_checks.sql
mimic-build:
@echo '------------------------'
@echo '-- Building MIMIC-III --'
@echo '------------------------'
@echo ''
@echo '---------------------'
@echo '-- Creating schema --'
@echo '---------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -c "DROP SCHEMA IF EXISTS $(DBSCHEMA); CREATE SCHEMA $(DBSCHEMA);"
@echo ''
@echo '---------------------'
@echo '-- Creating tables --'
@echo '---------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_create_tables$(PSQL_MAJOR_VERSION).sql
@echo ''
@echo '------------------'
@echo '-- Loading data --'
@echo '------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data.sql -v mimic_data_dir=${DATADIR}
@echo ''
@echo '--------------------'
@echo '-- Adding indexes --'
@echo '--------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_add_indexes.sql
@echo ''
@echo '--------------------'
@echo '-- Adding comments --'
@echo '--------------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_add_comments.sql
@echo ''
@echo '----------------'
@echo '-- Check data --'
@echo '----------------'
@echo ''
@sleep 2
psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_checks.sql
mimic-download:
@echo '------------------------------------------'
@echo '-- Downloading MIMIC-III from PhysioNet --'
@echo '------------------------------------------'
@echo ''
ifeq ("$(physionetuser)","")
@echo 'Cannot download data: physionetuser variable is unset.'
@echo 'Call the makefile again with physionetuser=<USERNAME>'
@echo ' e.g. make eicu-download datadir=/path/to/data [email protected]'
else
wget --user $(physionetuser) --ask-password -P $(DATADIR) -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETURL)"
endif
mimic-demo-download:
@echo '------------------------------------------'
@echo '-- Downloading MIMIC-III from PhysioNet --'
@echo '------------------------------------------'
@echo ''
wget --user $(physionetuser) --ask-password -P $(DATADIR) -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETDEMOURL)"
#This is fairly inelegant and could be tidied with a for loop and an if to check for gzip,
#but need to maintain compatibility with Windows, which baffling lacks these things
mimic-check-gz:
@echo ''
@echo '-----------------------'
@echo '-- Checking for data --'
@echo '-----------------------'
@echo ''
@echo 'Data path: ' $(DATADIR)
ifeq ("$(wildcard $(DATADIR)ADMISSIONS.csv.gz)","")
@echo "Unable to find $(DATADIR)ADMISSIONS.csv.gz - exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CALLOUT.csv.gz)","")
@echo "Unable to find $(DATADIR)CALLOUT.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CAREGIVERS.csv.gz)","")
@echo "Unable to find $(DATADIR)CAREGIVERS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CHARTEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)CHARTEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CPTEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)CPTEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DATETIMEEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)DATETIMEEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_CPT.csv.gz)","")
@echo "Unable to find $(DATADIR)D_CPT.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DIAGNOSES_ICD.csv.gz)","")
@echo "Unable to find $(DATADIR)DIAGNOSES_ICD.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ICD_DIAGNOSES.csv.gz)","")
@echo "Unable to find $(DATADIR)D_ICD_DIAGNOSES.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ICD_PROCEDURES.csv.gz)","")
@echo "Unable to find $(DATADIR)D_ICD_PROCEDURES.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ITEMS.csv.gz)","")
@echo "Unable to find $(DATADIR)D_ITEMS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_LABITEMS.csv.gz)","")
@echo "Unable to find $(DATADIR)D_LABITEMS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DRGCODES.csv.gz)","")
@echo "Unable to find $(DATADIR)DRGCODES.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)ICUSTAYS.csv.gz)","")
@echo "Unable to find $(DATADIR)ICUSTAYS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)INPUTEVENTS_CV.csv.gz)","")
@echo "Unable to find $(DATADIR)INPUTEVENTS_CV.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)INPUTEVENTS_MV.csv.gz)","")
@echo "Unable to find $(DATADIR)INPUTEVENTS_MV.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)LABEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)LABEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)MICROBIOLOGYEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)MICROBIOLOGYEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)NOTEEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)NOTEEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)OUTPUTEVENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)OUTPUTEVENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PATIENTS.csv.gz)","")
@echo "Unable to find $(DATADIR)PATIENTS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PRESCRIPTIONS.csv.gz)","")
@echo "Unable to find $(DATADIR)PRESCRIPTIONS.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PROCEDUREEVENTS_MV.csv.gz)","")
@echo "Unable to find $(DATADIR)PROCEDUREEVENTS_MV.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PROCEDURES_ICD.csv.gz)","")
@echo "Unable to find $(DATADIR)PROCEDURES_ICD.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)SERVICES.csv.gz)","")
@echo "Unable to find $(DATADIR)SERVICES.csv.gz. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)TRANSFERS.csv.gz)","")
@echo "Unable to find $(DATADIR)TRANSFERS.csv.gz. Exiting before build."; exit 1
endif
@echo 'All data present!'
@echo ''
mimic-check:
@echo ''
@echo '-----------------------'
@echo '-- Checking for data --'
@echo '-----------------------'
@echo ''
@echo 'Data path: ' $(DATADIR)
ifeq ("$(wildcard $(DATADIR)ADMISSIONS.csv)","")
@echo "Unable to find $(DATADIR)ADMISSIONS.csv - exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CALLOUT.csv)","")
@echo "Unable to find $(DATADIR)CALLOUT.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CAREGIVERS.csv)","")
@echo "Unable to find $(DATADIR)CAREGIVERS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CHARTEVENTS.csv)","")
@echo "Unable to find $(DATADIR)CHARTEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)CPTEVENTS.csv)","")
@echo "Unable to find $(DATADIR)CPTEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DATETIMEEVENTS.csv)","")
@echo "Unable to find $(DATADIR)DATETIMEEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_CPT.csv)","")
@echo "Unable to find $(DATADIR)D_CPT.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DIAGNOSES_ICD.csv)","")
@echo "Unable to find $(DATADIR)DIAGNOSES_ICD.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ICD_DIAGNOSES.csv)","")
@echo "Unable to find $(DATADIR)D_ICD_DIAGNOSES.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ICD_PROCEDURES.csv)","")
@echo "Unable to find $(DATADIR)D_ICD_PROCEDURES.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_ITEMS.csv)","")
@echo "Unable to find $(DATADIR)D_ITEMS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)D_LABITEMS.csv)","")
@echo "Unable to find $(DATADIR)D_LABITEMS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)DRGCODES.csv)","")
@echo "Unable to find $(DATADIR)DRGCODES.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)ICUSTAYS.csv)","")
@echo "Unable to find $(DATADIR)ICUSTAYS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)INPUTEVENTS_CV.csv)","")
@echo "Unable to find $(DATADIR)INPUTEVENTS_CV.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)INPUTEVENTS_MV.csv)","")
@echo "Unable to find $(DATADIR)INPUTEVENTS_MV.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)LABEVENTS.csv)","")
@echo "Unable to find $(DATADIR)LABEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)MICROBIOLOGYEVENTS.csv)","")
@echo "Unable to find $(DATADIR)MICROBIOLOGYEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)NOTEEVENTS.csv)","")
@echo "Unable to find $(DATADIR)NOTEEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)OUTPUTEVENTS.csv)","")
@echo "Unable to find $(DATADIR)OUTPUTEVENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PATIENTS.csv)","")
@echo "Unable to find $(DATADIR)PATIENTS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PRESCRIPTIONS.csv)","")
@echo "Unable to find $(DATADIR)PRESCRIPTIONS.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PROCEDUREEVENTS_MV.csv)","")
@echo "Unable to find $(DATADIR)PROCEDUREEVENTS_MV.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)PROCEDURES_ICD.csv)","")
@echo "Unable to find $(DATADIR)PROCEDURES_ICD.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)SERVICES.csv)","")
@echo "Unable to find $(DATADIR)SERVICES.csv. Exiting before build."; exit 1
endif
ifeq ("$(wildcard $(DATADIR)TRANSFERS.csv)","")
@echo "Unable to find $(DATADIR)TRANSFERS.csv. Exiting before build."; exit 1
endif
@echo 'All data present!'
@echo ''
clean:
@echo
concepts:
@echo '------------------------'
@echo '-- Building MIMIC-III --'
@echo '------------------------'
@echo ''
@echo '---------------------'
@echo '-- Adding concepts --'
@echo '---------------------'
@echo ''
@sleep 2
cd ../../concepts/ && psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f make-concepts.sql
.PHONY: help mimic clean