-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_outcomes.py
More file actions
360 lines (263 loc) · 11.8 KB
/
Copy pathget_outcomes.py
File metadata and controls
360 lines (263 loc) · 11.8 KB
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
import pandas as pd
import numpy as np
DATA_DIRECTORY = "data/"
def get_gose_30d():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the Glasgow Outcome Scale Extended (GOSE) at 30 days.
GOSE of 6 or more is considered a negative outcome (0),
while GOSE of 5 or less is considered a positive outcome (1).
"""
columns_to_load = [96, 1]
gose_30d = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
print(gose_30d.head())
# Drop the first row
gose_30d = gose_30d.iloc[1:, :]
# Rename the first column to 'name'
gose_30d.rename(columns={gose_30d.columns[0]: 'name'}, inplace=True)
gose_30d.rename(columns={gose_30d.columns[1]: 'mortality'}, inplace=True)
# Drop rows with NaN in 'name'
gose_30d = gose_30d.dropna(subset=['name'])
data = gose_30d.copy()
data['mortality'] = data['mortality'].apply(
lambda x: 0 if x in ['8 Upper Good Recovery (Upper GR)',
'7 Lower Good Recovery (Lower GR)',
'6 Upper Moderate Disability (Upper MD)',
'max'] else
np.nan if pd.isnull(x) or x in ['', 'nd', 'NaN'] else
1
).astype(float)
count_1 = (data['mortality'] == 1).sum() # Nombre de 1
count_0 = (data['mortality'] == 0).sum() # Nombre de 0
count_nan = data['mortality'].isna().sum() # Nombre de NaN
print(f"Nombre de 1 : {count_1}")
print(f"Nombre de 0 : {count_0}")
print(f"Nombre de NaN : {count_nan}")
# Create the 'tier_bin' column based on conditions
y = data[['name']].copy()
y['mortality'] = (
(data.iloc[:, 1] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['mortality'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_gose_6m():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the Glasgow Outcome Scale Extended (GOSE) at 6 months.
GOSE of 6 or more is considered a negative outcome (0),
while GOSE of 5 or less is considered a positive outcome (1).
"""
columns_to_load = [97, 1]
gose_6m = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
print(gose_6m.head())
# Drop the first row
gose_6m = gose_6m.iloc[1:, :]
# Rename the first column to 'name'
gose_6m.rename(columns={gose_6m.columns[0]: 'name'}, inplace=True)
gose_6m.rename(columns={gose_6m.columns[1]: 'mortality'}, inplace=True)
# Drop rows with NaN in 'name'
gose_6m = gose_6m.dropna(subset=['name'])
data = gose_6m.copy()
data['mortality'] = data['mortality'].apply(
lambda x: 0 if x in ['8 Upper Good Recovery (Upper GR)',
'7 Lower Good Recovery (Lower GR)',
'6 Upper Moderate Disability (Upper MD)',
'max'] else
np.nan if pd.isnull(x) or x in ['', 'nd', 'NaN'] else
1
).astype(float)
count_1 = (data['mortality'] == 1).sum() # Nombre de 1
count_0 = (data['mortality'] == 0).sum() # Nombre de 0
count_nan = data['mortality'].isna().sum() # Nombre de NaN
# Afficher les résultats
print(f"Nombre de 1 : {count_1}")
print(f"Nombre de 0 : {count_0}")
print(f"Nombre de NaN : {count_nan}")
# Create the 'tier_bin' column based on conditions
y = data[['name']].copy()
y['mortality'] = (
(data.iloc[:, 1] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['mortality'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_mortality_7d():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the mortality at 7 days.
Patient alive at 7 days is considered a negative outcome (0),
Positive outcome otherwise (1).
"""
columns_to_load = [93, 1]
mortality_7d = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
print(mortality_7d.head())
# Drop the first row
#mortality_7d = mortality_7d.iloc[1:, :]
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[0]: 'name'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[1]: 'mortality'}, inplace=True)
data = mortality_7d.copy()
# Exemple : appliquer la transformation sur les colonnes en position 1 et 2
cols = [data.columns[1]] # Noms des colonnes en position 1 et 3
# Appliquer les transformations à chaque colonne
for col in cols:
data[col] = data[col].replace({'1': 1, '0': 0, 'nd': np.nan}).astype(float)
data[col] = pd.to_numeric(data[col], errors='coerce')
# Create the 'mortality' column based on conditions
y = data[['name']].copy()
y['mortality'] = (
(data.iloc[:, 1] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['mortality'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_mortality_30d():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the mortality at 30 days.
Patient alive at 30 days is considered a negative outcome (0),
Positive outcome otherwise (1).
"""
columns_to_load = [93, 94, 1]
mortality_7d = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
print(mortality_7d.head())
# Drop the first row
#mortality_7d = mortality_7d.iloc[1:, :]
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[0]: 'name'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[1]: 'mortality D7'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[2]: 'mortality'}, inplace=True)
data = mortality_7d.copy()
# Exemple : appliquer la transformation sur les colonnes en position 1 et 2
cols = [data.columns[1], data.columns[2]] # Noms des colonnes en position 1 et 3
# Appliquer les transformations à chaque colonne
for col in cols:
data[col] = data[col].replace({'1': 1, '0': 0, 'nd': np.nan}).astype(float)
data[col] = pd.to_numeric(data[col], errors='coerce')
# Recodage de la colonne mortality
data['mortality'] = data['mortality D7'].where(data['mortality D7'] == 1, data['mortality'])
# Create the 'mortality' column based on conditions
y = data[['name']].copy()
y['mortality'] = (
(data.iloc[:, 2] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['mortality'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_mortality_6m():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the mortality at 6 months.
Patient alive at 6 months is considered a negative outcome (0),
Positive outcome otherwise (1).
"""
columns_to_load = [93, 94, 95, 1]
mortality_7d = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
# Drop the first row
#mortality_7d = mortality_7d.iloc[1:, :]
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[0]: 'name'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[1]: 'mortality D7'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[2]: 'mortality D30'}, inplace=True)
# Rename the first column to 'IPP'
mortality_7d.rename(columns={mortality_7d.columns[3]: 'mortality'}, inplace=True)
data = mortality_7d.copy()
# Exemple : appliquer la transformation sur les colonnes en position 1 et 2
cols = [data.columns[1], data.columns[2], data.columns[3]] # Noms des colonnes en position 1 et 3
# Appliquer les transformations à chaque colonne
for col in cols:
data[col] = data[col].replace({'1': 1, '0': 0, 'nd': np.nan, '8 Upper Good Recovery (Upper GR)': np.nan}).astype(float)
data[col] = pd.to_numeric(data[col], errors='coerce')
# Recodage de la colonne mortality
data['mortality D30'] = data['mortality D7'].where(data['mortality D7'] == 1, data['mortality D30'])
data['mortality'] = data['mortality D30'].where(data['mortality D30'] == 1, data['mortality'])
# Create the 'mortality' column based on conditions
y = data[['name']].copy()
y['mortality'] = (
(data.iloc[:, 3] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['mortality'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_tier():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for the TIER scale.
"""
# Load the columns 71 to 75 and the 6th column
columns_to_load = list(range(58, 69)) + [1]
TIER = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
# Colonnes à traiter
columns_to_convert = TIER.columns[7:12]
# Remplacer uniquement '1' et '0' par des nombres
for col in columns_to_convert:
TIER[col] = TIER[col].replace({'1': 1, '0': 0}) # Convertir '1' et '0' en nombres
TIER[col] = pd.to_numeric(TIER[col], errors='coerce') # Convertir le reste en numérique, NaN pour les non-convertibles
# Create the 'tier_bin' column based on conditions
y = TIER[['name']].copy()
y['tier_bin'] = (
(TIER.iloc[:, 7] == 1) |
(TIER.iloc[:, 8] == 1) |
(TIER.iloc[:, 9] == 1) |
(TIER.iloc[:, 10] == 1) |
(TIER.iloc[:, 11] == 1)
).astype(int)
# Display the resulting DataFrame
print(y.head())
# Outcome event
event_count = (y['tier_bin'] == 1).sum() # Count the number of events
print(f"Outcome events : {event_count}")
return y
def get_til():
"""
This function reads the raw clinical data csv file and computes
a binary outcome for Therapeutic Intensity Level (TIL).
A TIL of 0 or 1 is considered a negative outcome (0),
A TIL of 2, 3 or 4 is considered a positive outcome (1).
"""
# Load the columns 71 to 75 and the 6th column
columns_to_load = list(range(69, 74)) + [1]
TIL = pd.read_csv(DATA_DIRECTORY + "clinical_data_anonymized.csv", usecols=columns_to_load)
# Drop the first row
TIL = TIL.iloc[1:, :]
# Rename the first column to 'name'
TIL.rename(columns={TIL.columns[0]: 'name'}, inplace=True)
TIL.rename(columns={TIL.columns[1]: 'TIL 0'}, inplace=True)
TIL.rename(columns={TIL.columns[2]: 'TIL 1'}, inplace=True)
TIL.rename(columns={TIL.columns[3]: 'TIL 2'}, inplace=True)
TIL.rename(columns={TIL.columns[4]: 'TIL 3'}, inplace=True)
TIL.rename(columns={TIL.columns[5]: 'TIL 4'}, inplace=True)
TIL = TIL.dropna(subset=['name'])
# Display the resulting DataFrame
print(TIL.head())
y = TIL[['name']].copy() # Include 'name' in y
y["TIL_bin"] = ((TIL.iloc[:, 3] == 1) | (TIL.iloc[:, 4] == 1) | (TIL.iloc[:, 5] == 1)).astype(int)
# Verify the first few rows of y
print(y.head())
# Outcome event
event_count = (y["TIL_bin"] == 1).sum() # Count the number of events (y = 1)
print(f"Outcome events: {event_count}")
return y
def get_traumatrix():
pass