-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-phenotype_outcomes_ukb.Rmd
575 lines (419 loc) · 17.4 KB
/
08-phenotype_outcomes_ukb.Rmd
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# Phenotype outcome and control exclusion events using UKB assessment center data {#phenotype-outcomes-ukb}
In this chapter, we use the master UKB event table created in chapter \@ref(curate-master-ukb-events-table) to generate different outcome event tables. We phenotype the following outcomes:
- Diabetes (DM)
- Myocardial Infarction (MI)
- Unstable Angina (UA)
- Ischemic Stroke (IS)
- Hemorrhagic Stroke (HS)
- Stroke (ST)
- PCI
- Composite CVD
- Diabetic retinopathy (DR)
- Diabetic kidney disease (DKD)
The following event tables will also be created to exclude certain controls from time-to-event tables in later chapters:
- Diabetic eye disease control exclusion events
- Diabetic kidney disease control exclusion events
- Cardiovascular control exclusion events
- Cerebrovascular control exclusion events
- Non-coronary revascularization control exclusion events
The general phenotyping procedure for complication outcomes and control exclusion outcomes are the same. All we have to do is to define patterns we want to search and match these patterns from the master UKB event table.
The pattern searching is abstracted away in a function `get_phenotype_tab()` in `functions.R`. The function searches certain regular expression patterns corresponding to outcomes from the master UKB event table and outputs the table containing all of the events matching the patterns. The following are the types of patterns the function accepts:
- UKB-defined field patterns
- custom-defined field patterns
- ICD10 code patterns (also accepts more specific ICD10 codes for primary death and secondary death events)
- OPCS4 code patterns
- self-reported condition code patterns
- self-reported operation code patterns
The UKB-defined field patterns match fields that are associated with first occurrence fields and algorithimically defined fields as defined by UKB study. The custom field pattern matches a custom field defined in chapter \@ref(curate-master-ukb-events-table). As a reminder, the only custom field we have defined is `dr_self` used in phenotyping diabetes related eye disease. The code patterns including ICD10, OPCS4, self-reported condition and self-reported operation match the codes that represent some clinical events. Thus, to phenotype an outcome, one should first identify the fields and codes associated with an outcome, define the patterns which are one of the inputs to `get_phenotype_tab()`. Internally, `get_phenotype_tab` function uses `grepl` function in `dplyr` package to filter the master event table.
```{r setup, include=FALSE}
knitr::opts_chunk$set(message = F, eval = F)
```
Load packages and functions.
```{r}
library(tidyverse)
library(data.table)
source("functions.R")
```
Import the master event table.
```{r}
event_tab <- readRDS("generated_data/all_ukb_events_tab.RDS")
```
## Phenotype outcomes
### DM
Outcome fields:
- `f.130706.0.0`: the date of first occurrence of Type 1 diabetes
- `f.130708.0.0`: the date of first occurrence of Type 2 diabetes
- `f.130714.0.0`: the date of first occurrence of diabetes of unspecified type
```{r}
dm_field_patterns <- "130706|130708|130714"
```
Get DM event table and first occurrence DM event table.
```{r}
dm_ukb <- get_phenotype_tab(field_patterns = dm_field_patterns,event_tab = event_tab,firstoccur = F)
dm_firstoccur_ukb <- get_phenotype_tab(field_patterns = dm_field_patterns,event_tab = event_tab,firstoccur = T)
```
Categorize diabetes event to either Type1, Type2 or Uncertain in a new field `dm_type`.
```{r}
dm_ukb <- dm_ukb %>% mutate(dm_type = ifelse(grepl("130706", key), "Type1",
ifelse(grepl("130708", key), "Type2","Uncertain")))
```
```{r}
saveRDS(dm_ukb,"generated_data/dm_ukb.RDS")
saveRDS(dm_firstoccur_ukb,"generated_data/dm_firstoccur_ukb.RDS")
```
### MI
Outcome fields:
- f.131298.0.0: the date of first occurrence of MI
- f.131300.0.0: the date of subsequent occurrence of MI
- f.42000.0.0: the date of algorithmically defined MI outcome
ICD10 code prefixes:
- I21
- I22
- I23
Define patterns to search.
```{r}
mi_field_patterns <- "131298|131300|42000"
mi_icd10_patterns <- "^I21|^I22|^I23"
```
Get MI event table and first occurrence MI event table.
```{r}
mi_ukb <-
get_phenotype_tab(field_patterns = mi_field_patterns, icd10_patterns_any = mi_icd10_patterns,event_tab = event_tab,firstoccur = F)
mi_firstoccur_ukb <-
get_phenotype_tab(field_patterns = mi_field_patterns, icd10_patterns_any = mi_icd10_patterns,event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(mi_ukb,"generated_data/mi_ukb.RDS")
saveRDS(mi_firstoccur_ukb,"generated_data/mi_firstoccur_ukb.RDS")
```
### Unstable Angina
ICD10 code prefixes:
- I200
```{r}
unstable_angina_icd10_patterns <- "I200"
```
Get unstable angina table and first occurrence unstable angina event table.
```{r}
unstable_angina_ukb <- get_phenotype_tab(icd10_patterns_any = unstable_angina_icd10_patterns, event_tab = event_tab,firstoccur = F)
unstable_angina_firstoccur_ukb <- get_phenotype_tab(icd10_patterns_any = unstable_angina_icd10_patterns, event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(unstable_angina_ukb,"generated_data/unstable_angina_ukb.RDS")
saveRDS(unstable_angina_firstoccur_ukb,"generated_data/unstable_angina_firstoccur_ukb.RDS")
```
### Ischemic Stroke
Outcome fields:
- 131366: Date I63 first reported (cerebral infarction)
- 42008: algorithmically defined outcome for ischemic stroke
ICD10 code prefixes:
- I63
Self-reported condition codes:
- 1583
Define patterns to search.
```{r}
stroke_infarct_field_patterns <- "131366|42008"
stroke_infarct_icd10_patterns <- "^I63"
stroke_infarct_selfrep_patterns <- "^1583$"
```
Get IS event table and first occurrence IS event table.
```{r}
stroke_infacrt_ukb <- get_phenotype_tab(field_patterns = stroke_infarct_field_patterns,
icd10_patterns_any = stroke_infarct_icd10_patterns,
selfrep_patterns = stroke_infarct_selfrep_patterns,
event_tab = event_tab,firstoccur = F)
stroke_infacrt_firstoccur_ukb <- get_phenotype_tab(field_patterns = stroke_infarct_field_patterns,
icd10_patterns_any = stroke_infarct_icd10_patterns,
selfrep_patterns = stroke_infarct_selfrep_patterns,
event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(stroke_infacrt_ukb,"generated_data/stroke_infarct_ukb.RDS")
saveRDS(stroke_infacrt_firstoccur_ukb,"generated_data/stroke_infarct_firstoccur_ukb.RDS")
```
### Hemorrhagic Stroke
Outcome fields:
- 131360: Subarachnoid Hemorrhage
- 131362: Intracerebral Hemorrhage
- 131364: Other non-traumatic Hemorrhage,
- 42010: Intracerebral Hemorrhage
- 42012: Subarachnoid Hemorrhage
ICD10 code prefixes:
- I60
- I61
- I62
Self-reported condition codes:
- 1086
Define patterns to search.
```{r}
stroke_hem_field_patterns <- "131360|131362|131364|42010|42012"
stroke_hem_icd10_patterns <- "^I60|^I61|^I62"
stroke_hem_selfrep_patterns <- "^1086$"
```
Get HS event table and first occurrence HS table.
```{r}
stroke_hem_ukb <- get_phenotype_tab(field_patterns = stroke_hem_field_patterns,
icd10_patterns_any = stroke_hem_icd10_patterns,
selfrep_patterns = stroke_hem_selfrep_patterns,
event_tab = event_tab,firstoccur = F)
stroke_hem_firstoccur_ukb <- get_phenotype_tab(field_patterns = stroke_hem_field_patterns,
icd10_patterns_any = stroke_hem_icd10_patterns,
selfrep_patterns = stroke_hem_selfrep_patterns,
event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(stroke_hem_ukb,"generated_data/stroke_hem_ukb.RDS")
saveRDS(stroke_hem_firstoccur_ukb,"generated_data/stroke_hem_firstoccur_ukb.RDS")
```
### Stroke
Outcome fields:
- 42006: unspecified stroke
- 131368: unspecified stroke
ICD10 code prefix
- I64
Self-reported condition codes:
- 1081
Outcome tables:
- recurrent ischemic stroke event table
- recurrent hemorrhagic stroke event table
Define patterns to search.
```{r}
stroke_unspec_field_patterns <- "42006|131368"
stroke_unspec_icd10_patterns <- "^I64"
stroke_other_selfrep_patterns <- "^1081$"
```
Get stroke event table
```{r}
stroke_infarct_hem_ukb <-
full_join(stroke_infacrt_ukb,stroke_hem_ukb) %>% arrange(f.eid,event_dt)
stroke_unspec_ukb <- get_phenotype_tab(field_patterns = stroke_unspec_field_patterns,
icd10_patterns_any = stroke_unspec_icd10_patterns,
event_tab = event_tab,firstoccur = F)
stroke_other_ukb <- get_phenotype_tab(selfrep_patterns = stroke_other_selfrep_patterns,
event_tab = event_tab,firstoccur = F)
stroke_ukb <-
stroke_infarct_hem_ukb %>%
full_join(stroke_unspec_ukb, by = c("f.eid","event_dt")) %>%
full_join(stroke_other_ukb, by = c("f.eid","event_dt")) %>%
arrange(f.eid,event_dt)
```
Get first occurrence stroke event table
```{r}
stroke_firstoccur_ukb <- stroke_ukb %>% group_by(f.eid) %>% arrange(event_dt) %>% slice(1)
```
```{r}
saveRDS(stroke_ukb,"generated_data/stroke_ukb.RDS")
saveRDS(stroke_firstoccur_ukb,"generated_data/stroke_firstoccur_ukb.RDS")
```
### PCI
OPCS4 codes:
- K40, K41, K42, K43, K44, K45, K46, K483, K49, K501, K75, K76
Self-reported operation codes:
- 1070 (Coronary Angioplasty)
- 1095 (Coronary bypass grafts)
Define patterns to search.
```{r}
# OPCS patterns start with 'K' so do not have to start the pattern with '^'
pci_opcs_patterns <- "K40|K41|K42|K43|K44|K45|K46|K483|K49|K501|K75|K76"
pci_selfrep_op_patterns <- "^1070$|^1095$"
```
Get PCI event table and first occurrence PCI event table.
```{r}
pci_ukb <- get_phenotype_tab(opcs_patterns = pci_opcs_patterns,
selfrep_op_patterns = pci_selfrep_op_patterns,
event_tab = event_tab,firstoccur = F)
pci_firstoccur_ukb <- get_phenotype_tab(opcs_patterns = pci_opcs_patterns,
selfrep_op_patterns = pci_selfrep_op_patterns,
event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(pci_ukb,"generated_data/pci_ukb.RDS")
saveRDS(pci_firstoccur_ukb,"generated_data/pci_firstoccur_ukb.RDS")
```
### CVD death
ICD10 code prefixes (primary death):
-I*
Define patterns to search.
```{r}
cvd_death_icd10_death_primary_patterns <- "^I"
```
Get CVD death event table
```{r}
cvd_death_ukb <- get_phenotype_tab(icd10_patterns_pd = cvd_death_icd10_death_primary_patterns,
event_tab = event_tab,firstoccur = F)
```
```{r}
saveRDS(cvd_death_ukb,"generated_data/cvd_death_ukb.RDS")
```
### Composite CVD
Composite CVD was defined to be any of the following events:
- MI
- IS
- UA
- PCI
- CVD death
Get compositie CVD event table and first occurrence composite CVD event table.
```{r}
cvd_ukb <-
mi_ukb %>%
full_join(stroke_infacrt_ukb) %>%
full_join(unstable_angina_ukb) %>%
full_join(pci_ukb) %>%
full_join(cvd_death_ukb) %>% distinct() %>% arrange(f.eid,event_dt)
cvd_firstoccur_ukb <- cvd_ukb %>% group_by(f.eid) %>% arrange(event_dt) %>% slice(1)
```
```{r}
saveRDS(cvd_ukb,"generated_data/cvd_ukb.RDS")
saveRDS(cvd_firstoccur_ukb,"generated_data/cvd_firstoccur_ukb.RDS")
```
### DR
ICD10 codes:
- E1*.3: Diabetes Mellitus with Ophthalmic Complications
- H36.0: Diabetic Retinopathy
- H28.0: Diabetic Cataract
ICD9 codes:
- 2504: Diabetes with Ophthalmic manifestations
- 3620: Diabetic retinopathy
Self-reported condition codes:
- 1276
Custom defined fields:
- dr_self: the date of DR diagnosis. As a reminder `dr_self` was produced by combining information from the fields `f.5901.0.0`, `f.5901.1.0`, `f.5901.2.0` and `f.5901.3.0` which record age of subjects at which DR was diagnosed at four different time points. Please see chapter \@ref(curate-master-ukb-events-table) for details.
Define patterns.
```{r}
dr_icd10 <- "E103|E113|E133|E143|H360|H280"
dr_icd9 <- "^2504|^3620"
dr_self <- "1276"
dr_custom <- "dr_self"
```
Get first occurrence DR event table.
```{r}
dr_firstoccur_ukb <- get_phenotype_tab(icd10_patterns_any = dr_icd10,
icd9_patterns_any = dr_icd9,
selfrep_patterns = dr_self,
custom_field_patterns = dr_custom,
event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(dr_firstoccur_ukb,"generated_data/dr_firstoccur_ukb.RDS")
```
### DKD
Outcome fields:
- 42026: algorithmically defined End-Stage Renal Disease (ESRD)
ICD10 codes:
- E1.2: Diabetes Mellitus with renal complication
- N18[0345]: CKD Stage 3-5, end stage
- N083: Glomerular disorders in Diabetes Mellitus
ICD9 codes:
- 2503: Diabetes with renal manifestations
- 5859: Renal failure
Self-reported condition codes:
- 1607
Define patterns.
```{r}
dkd_field_patterns <- "42026"
dkd_icd10 <- "E102|E112|E132|E142|N180|N183|N184|N185|N083"
dkd_icd9 <- "^2503|^5859"
dkd_self <- "1607"
```
Get DKD event table and first occurrence DKD event table.
```{r}
dkd_ukb <- get_phenotype_tab(field_patterns = dkd_field_patterns,
icd10_patterns_any = dkd_icd10,
icd9_patterns_any = dkd_icd9,
selfrep_patterns = dkd_self,
event_tab = event_tab,firstoccur = F)
dkd_firstoccur_ukb <- get_phenotype_tab(field_patterns = dkd_field_patterns,
icd10_patterns_any = dkd_icd10,
icd9_patterns_any = dkd_icd9,
selfrep_patterns = dkd_self,
event_tab = event_tab,firstoccur = T)
```
```{r}
saveRDS(dkd_ukb,"generated_data/dkd_ukb.RDS")
saveRDS(dkd_firstoccur_ukb,"generated_data/dkd_firstoccur_ukb.RDS")
```
## Phenotype control exclusion events
### Cardiovascular control exclusion events
Define patterns.
```{r}
exclude_ctrl_cardio_icd10 <- "I2|I3|I5|I6|I7"
exclude_ctrl_cardio_self <- "1074|1076|1077|1078|1079|1080|1471|1489|1490|1492|1584|1585|1586|1587|1588|1589|1590|1591|1592"
exclude_ctrl_cardio_selfop <- "1069|1096|1097|1098|1099|1100|1101|1104|1523|1553|1554"
```
Get cardiovascular control exclusion event table.
```{r}
cardio_control_exclusion_events <-
get_phenotype_tab(icd10_patterns_any = exclude_ctrl_cardio_icd10,
selfrep_patterns = exclude_ctrl_cardio_self,
selfrep_op_patterns = exclude_ctrl_cardio_selfop,event_tab = event_tab,firstoccur = F)
```
```{r}
saveRDS(cardio_control_exclusion_events,"generated_data/cardio_control_exclusion_events_ukb.RDS")
```
### Cerebrovascular control exclusion events
Define patterns.
```{r}
exclude_ctrl_cereb_icd10 <- "G45|G46|I65|I66|I67|I68|I69"
exclude_ctrl_cereb_self <- "1082"
```
Get cerebrovascular control exclusion event table.
```{r}
cerebro_control_exclusion_events <-
get_phenotype_tab(icd10_patterns_any = exclude_ctrl_cereb_icd10,
selfrep_patterns = exclude_ctrl_cereb_self,event_tab = event_tab,firstoccur = F)
```
```{r}
saveRDS(cerebro_control_exclusion_events,"generated_data/cerebro_control_exclusion_events_ukb.RDS")
```
### Non-coronary revascularization procedure control exclusion events
Define patterns.
```{r}
other_revasc_selfop <- "1071|1102|1105|1107|1108|1109|1110"
```
Get non-coronary revascularization procedure control exclusion event table.
```{r}
other_revas_control_exclusion_events <-
get_phenotype_tab(selfrep_op_patterns = other_revasc_selfop, event_tab = event_tab, firstoccur = F)
```
```{r}
saveRDS(other_revas_control_exclusion_events,"generated_data/other_revas_control_exclusion_events_ukb.RDS")
```
### Renal disease control exclusion events
Define patterns.
```{r}
exclude_ctrl_renal_icd10 <- "N0|N1|N2|Z49|Z992"
exclude_ctrl_renal_icd9 <- "^58[0-9]|^59[1-4]|^590[23]|^V420|^V454|^V560|^V568"
exclude_ctrl_renal_self <- "1192|1193|1194|1519|1520|1608|1609"
exclude_ctrl_renal_selfop <- "1195|1487"
exclude_ctrl_renal_opcs <- "M01|M02|M03|X40|X41|X42"
```
Get renal diseasae control exclusion event table.
```{r}
dkd_control_exclusion_events <-
get_phenotype_tab(icd10_patterns_any = exclude_ctrl_renal_icd10,
icd9_patterns_any = exclude_ctrl_renal_icd9,
selfrep_patterns = exclude_ctrl_renal_self,
selfrep_op_patterns = exclude_ctrl_renal_selfop,
opcs_patterns = exclude_ctrl_renal_opcs,event_tab = event_tab,firstoccur = F)
```
```{r}
saveRDS(dkd_control_exclusion_events,"generated_data/dkd_control_exclusion_events_ukb.RDS")
```
### Eye disease control exclusion events
Define patterns.
```{r}
exclude_eye_icd10 <- "H25|H26|H28|H34|H35|H36|H40|H42"
exclude_eye_icd9 <- "^36[256]"
exclude_eye_self <- "1275|1277|1278|1281|1282|1527|1538|1530"
exclude_eye_selfop <- "1434|1435|1436|1437"
```
Get eye disease control exclusion event table.
```{r}
dr_control_exclusion_events <-
get_phenotype_tab(icd10_patterns_any = exclude_eye_icd10,
icd9_patterns_any = exclude_eye_icd9,
selfrep_patterns = exclude_eye_self,
selfrep_op_patterns = exclude_eye_selfop,event_tab = event_tab,firstoccur = F)
```
```{r}
saveRDS(dr_control_exclusion_events,"generated_data/dr_control_exclusion_events_ukb.RDS")
```