-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2. bulkRNAseq.Rmd
executable file
·2209 lines (1724 loc) · 84.3 KB
/
2. bulkRNAseq.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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Mapping CAC susceptibility loci to bulk RNAseq in carotid plaques."
author: '[Sander W. van der Laan, PhD](https://vanderlaan.science) | [email protected]'
date: '`r Sys.Date()`'
output:
html_notebook:
cache: yes
code_folding: hide
collapse: yes
df_print: paged
fig.align: center
fig_caption: yes
fig_height: 10
fig_retina: 2
fig_width: 12
number_sections: yes
theme: paper
toc: yes
toc_float:
collapsed: no
smooth_scroll: yes
mainfont: Helvetica
subtitle: A 'druggable-MI-targets' project
editor_options:
chunk_output_type: inline
---
```{r global_options, include=FALSE}
# further define some knitr-options.
knitr::opts_chunk$set(fig.width = 12, fig.height = 8, fig.path = 'FIGURES/', dev = 'png',
eval = TRUE, warning = FALSE, message = FALSE)
```
_Clean the environment._
```{r ClearEnvironment, echo = FALSE}
rm(list = ls())
```
_Set locations, and the working directory ..._
```{r LocalSystem, echo = FALSE}
### Operating System Version
### Mac Pro
# ROOT_loc = "/Volumes/EliteProQx2Media"
# GENOMIC_loc = "/Users/svanderlaan/iCloud/Genomics"
### MacBook
ROOT_loc = "/Users/slaan3/OneDrive - UMC Utrecht"
GENOMIC_loc = paste0(ROOT_loc, "/Genomics")
STORAGE_loc = "/Volumes/LaCie/PLINK"
### Generic Locations
AEDB_loc = paste0(GENOMIC_loc, "/Athero-Express/AE-AAA_GS_DBs")
LAB_loc = paste0(GENOMIC_loc, "/LabBusiness")
AERNA_loc = paste0(STORAGE_loc, "/_AE_ORIGINALS/AERNA")
PROJECT_loc = paste0(STORAGE_loc, "/analyses/lookups/AE_20200512_COL_MKAVOUSI_MBOS_CHARGE_1000G_CAC")
RESULTS = paste0(STORAGE_loc, "/analyses/lookups/AE_20200512_COL_MKAVOUSI_MBOS_CHARGE_1000G_CAC/bulkRNAseq")
TARGET_loc = paste0(GENOMIC_loc, "/Athero-Express/Forms/2020/AE_20200512_COL_MKAVOUSI_MBOS_CHARGE_1000G_CAC")
### SOME VARIABLES WE NEED DOWN THE LINE
cat("\nDefining phenotypes and datasets.\n")
PROJECTNAME="AERNA"
cat("\nCreate a new analysis directory, including subdirectories.\n")
# Analysis
ifelse(!dir.exists(file.path(RESULTS, "/",PROJECTNAME)),
dir.create(file.path(RESULTS, "/",PROJECTNAME)),
FALSE)
ANALYSIS_loc = paste0(RESULTS,"/",PROJECTNAME)
# Plots
ifelse(!dir.exists(file.path(ANALYSIS_loc, "/PLOTS")),
dir.create(file.path(ANALYSIS_loc, "/PLOTS")),
FALSE)
PLOT_loc = paste0(ANALYSIS_loc,"/PLOTS")
# QC plots
ifelse(!dir.exists(file.path(PLOT_loc, "/QC")),
dir.create(file.path(PLOT_loc, "/QC")),
FALSE)
QC_loc = paste0(PLOT_loc,"/QC")
# Output files
ifelse(!dir.exists(file.path(ANALYSIS_loc, "/OUTPUT")),
dir.create(file.path(ANALYSIS_loc, "/OUTPUT")),
FALSE)
OUT_loc = paste0(ANALYSIS_loc, "/OUTPUT")
cat("\nSetting working directory and listing its contents.\n")
setwd(paste0(RESULTS))
getwd()
list.files()
```
_... a package-installation function ..._
```{r Function: installations, echo=FALSE}
install.packages.auto <- function(x) {
x <- as.character(substitute(x))
if(isTRUE(x %in% .packages(all.available = TRUE))) {
eval(parse(text = sprintf("require(\"%s\")", x)))
} else {
# Update installed packages - this may mean a full upgrade of R, which in turn
# may not be warrented.
# update.install.packages.auto(ask = FALSE)
eval(parse(text = sprintf("install.packages(\"%s\", dependencies = TRUE, repos = \"https://cloud.r-project.org/\")", x)))
}
if(isTRUE(x %in% .packages(all.available = TRUE))) {
eval(parse(text = sprintf("require(\"%s\")", x)))
} else {
if (!requireNamespace("BiocManager"))
install.packages("BiocManager")
# BiocManager::install() # this would entail updating installed packages, which in turned may not be warrented
eval(parse(text = sprintf("BiocManager::install(\"%s\")", x)))
eval(parse(text = sprintf("require(\"%s\")", x)))
}
}
```
_... and load those packages._
```{r Setting: loading_packages, echo=FALSE, message=FALSE, warning=FALSE}
install.packages.auto("readr")
install.packages.auto("optparse")
install.packages.auto("tools")
install.packages.auto("dplyr")
install.packages.auto("tidyr")
install.packages.auto("tidylog")
library("tidylog", warn.conflicts = FALSE)
install.packages.auto("naniar")
# To get 'data.table' with 'fwrite' to be able to directly write gzipped-files
# Ref: https://stackoverflow.com/questions/42788401/is-possible-to-use-fwrite-from-data-table-with-gzfile
# install.packages("data.table", repos = "https://Rdatatable.gitlab.io/data.table")
library(data.table)
install.packages.auto("tidyverse")
install.packages.auto("knitr")
install.packages.auto("DT")
# for plotting
install.packages.auto("qqman")
install.packages.auto("forestplot")
install.packages.auto("pheatmap")
# for meta-analysis
install.packages.auto("meta")
install.packages.auto("bacon")
install.packages.auto("reshape2")
install.packages.auto("ggpubr")
install.packages.auto("patchwork")
install.packages.auto("corrr")
install.packages.auto("haven")
install.packages.auto("tableone")
# Install the devtools package from Hadley Wickham
install.packages.auto('devtools')
cat("\n* Genomic packages...\n")
install.packages.auto("GenomicFeatures")
install.packages.auto("GenomicRanges")
install.packages.auto("SummarizedExperiment")
install.packages.auto("DESeq2")
install.packages.auto("org.Hs.eg.db")
install.packages.auto("mygene")
install.packages.auto("TxDb.Hsapiens.UCSC.hg19.knownGene")
install.packages.auto("org.Hs.eg.db")
install.packages.auto("AnnotationDbi")
install.packages.auto("EnsDb.Hsapiens.v86")
install.packages.auto("EnhancedVolcano")
```
_We will create a datestamp and define the Utrecht Science Park Colour Scheme_.
```{r Setting: Colors, echo=FALSE}
Today = format(as.Date(as.POSIXlt(Sys.time())), "%Y%m%d")
Today.Report = format(as.Date(as.POSIXlt(Sys.time())), "%A, %B %d, %Y")
### UtrechtScienceParkColoursScheme
###
### WebsitetoconvertHEXtoRGB:http://hex.colorrrs.com.
### Forsomefunctionsyoushoulddividethesenumbersby255.
###
### No. Color HEX (RGB) CHR MAF/INFO
###---------------------------------------------------------------------------------------
### 1 yellow #FBB820 (251,184,32) => 1 or 1.0>INFO
### 2 gold #F59D10 (245,157,16) => 2
### 3 salmon #E55738 (229,87,56) => 3 or 0.05<MAF<0.2 or 0.4<INFO<0.6
### 4 darkpink #DB003F ((219,0,63) => 4
### 5 lightpink #E35493 (227,84,147) => 5 or 0.8<INFO<1.0
### 6 pink #D5267B (213,38,123) => 6
### 7 hardpink #CC0071 (204,0,113) => 7
### 8 lightpurple #A8448A (168,68,138) => 8
### 9 purple #9A3480 (154,52,128) => 9
### 10 lavendel #8D5B9A (141,91,154) => 10
### 11 bluepurple #705296 (112,82,150) => 11
### 12 purpleblue #686AA9 (104,106,169) => 12
### 13 lightpurpleblue #6173AD (97,115,173/101,120,180) => 13
### 14 seablue #4C81BF (76,129,191) => 14
### 15 skyblue #2F8BC9 (47,139,201) => 15
### 16 azurblue #1290D9 (18,144,217) => 16 or 0.01<MAF<0.05 or 0.2<INFO<0.4
### 17 lightazurblue #1396D8 (19,150,216) => 17
### 18 greenblue #15A6C1 (21,166,193) => 18
### 19 seaweedgreen #5EB17F (94,177,127) => 19
### 20 yellowgreen #86B833 (134,184,51) => 20
### 21 lightmossgreen #C5D220 (197,210,32) => 21
### 22 mossgreen #9FC228 (159,194,40) => 22 or MAF>0.20 or 0.6<INFO<0.8
### 23 lightgreen #78B113 (120,177,19) => 23/X
### 24 green #49A01D (73,160,29) => 24/Y
### 25 grey #595A5C (89,90,92) => 25/XY or MAF<0.01 or 0.0<INFO<0.2
### 26 lightgrey #A2A3A4 (162,163,164) => 26/MT
###
### ADDITIONAL COLORS
### 27 midgrey #D7D8D7
### 28 verylightgrey #ECECEC"
### 29 white #FFFFFF
### 30 black #000000
###----------------------------------------------------------------------------------------------
uithof_color = c("#FBB820","#F59D10","#E55738","#DB003F","#E35493","#D5267B",
"#CC0071","#A8448A","#9A3480","#8D5B9A","#705296","#686AA9",
"#6173AD","#4C81BF","#2F8BC9","#1290D9","#1396D8","#15A6C1",
"#5EB17F","#86B833","#C5D220","#9FC228","#78B113","#49A01D",
"#595A5C","#A2A3A4", "#D7D8D7", "#ECECEC", "#FFFFFF", "#000000")
uithof_color_legend = c("#FBB820", "#F59D10", "#E55738", "#DB003F", "#E35493",
"#D5267B", "#CC0071", "#A8448A", "#9A3480", "#8D5B9A",
"#705296", "#686AA9", "#6173AD", "#4C81BF", "#2F8BC9",
"#1290D9", "#1396D8", "#15A6C1", "#5EB17F", "#86B833",
"#C5D220", "#9FC228", "#78B113", "#49A01D", "#595A5C",
"#A2A3A4", "#D7D8D7", "#ECECEC", "#FFFFFF", "#000000")
#ggplot2 default color palette
gg_color_hue <- function(n) {
hues = seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
### ----------------------------------------------------------------------------
```
# ERA-CVD 'druggable-MI-targets'
<!-- ![ERA-CVD logo]("Users/swvanderlaan/iCloud/Genomics/Projects/#Druggable-MI-Genes/Administration/ERA-CVD\ Logo_CMYK.jpg") -->
For the ERA-CVD 'druggable-MI-targets' project (grantnumber: 01KL1802) we will perform two related RNA sequencing (RNAseq) experiments:
1) conventional ('bulk') RNAseq using RNA extracted from carotid plaque samples, n ± 700. As of `r Today.Report` all samples have been selected and RNA has been extracted; quality control (QC) was performed and we have a dataset of 635 samples.
2) single-cell RNAseq (scRNAseq) of at least n = 40 samples (20 females, 20 males). As of `r Today.Report` data is available of 40 samples (3 females, 15 males), we are extending sampling to get more female samples.
Plaque samples are derived from carotid endarterectomies as part of the [Athero-Express Biobank Study](http:www/atheroexpress.nl) which is an ongoing study in the UMC Utrecht.
# Background
Here we map the CHARGE Consortium 1000G GWAS on _coronary artery calcification (CAC)_ susceptibility loci to the single-cell carotid plaque data. These are given in:
- IndSigSNPsforSander.xlsx
- GeneList_15042020.xlsx
```{r CAC targets}
library(openxlsx)
# old list
# CAC_gene_list <- read.xlsx(paste0(TARGET_loc, "/GeneList_15042020.xlsx"))
# update list
CAC_gene_list <- read.xlsx(paste0(PROJECT_loc, "/SNP/Genes.xlsx"))
CAC_variants <- read.xlsx(paste0(PROJECT_loc, "/SNP/Variants.xlsx"))
DT::datatable(CAC_gene_list)
DT::datatable(CAC_variants)
```
We will construct a list of genes to map to our scRNAseq data.
```{r CAC targets for mapping}
CAC_target_genes <- unlist(CAC_gene_list$Gene)
CAC_target_genes
target_genes = CAC_target_genes
```
# Load data
First we will load the data:
- bulk RNA sequencing (RNAseq) experimental data from carotid plaques
- Athero-Express clinical data.
## Bulk RNAseq data
Here we load the latest dataset from our Athero-Express bulk RNA experiment d.d. 2021-12-03 mapped to b37 and Ensembl 87.
These bulk RNAseq data are filtered and corrected:
- UMI corrected
- unmappable genes are excluded
```{r LoadData}
# bulk RNAseq data
# bulkRNA_counts <- fread(paste0(AERNA_loc,"/2019-12-11_bulk_RNAseq_data_to_share/bulk_RNAseq_raw_counts_UMIcorr_weird_genes_filtered.txt"))
bulkRNA_counts_raw <- fread(paste0(AERNA_loc,"/raw_data_bulk/raw_counts_batch1till11_qc_umicorrected.txt"))
# batch information
# bulkRNA_meta <- fread(paste0(AERNA_loc,"/2019-12-11_bulk_RNAseq_data_to_share/bulk_RNAseq_metadata.txt"))
bulkRNA_meta <- fread(paste0(AERNA_loc,"/raw_data_bulk/metadata_raw_counts_batch1till11.txt"))
```
Quick peek at the counts and meta-data of the RNAseq experiment.
```{r QuickPeek}
head(bulkRNA_counts_raw)
head(bulkRNA_meta)
```
### Annotating and fixing the RNAseq data
There are two small issues we need to address:
- annotation with chromosome, start/end, strand, and gene information
- fixing ±`Inf` values
#### Fixing infinite values
```{r}
cat("\nThere are a couple of samples with infinite gene counts.\n")
temp <- bulkRNA_counts_raw %>% mutate_if(is.numeric, as.integer)
summary(bulkRNA_counts_raw$ae2341)
summary(bulkRNA_counts_raw$ae3078)
summary(bulkRNA_counts_raw$ae1422)
summary(bulkRNA_counts_raw$ae2305)
summary(bulkRNA_counts_raw$ae1256)
summary(bulkRNA_counts_raw$ae411)
summary(bulkRNA_counts_raw$ae1227)
cat("\nFixing the infinite gene counts.\n")
temp <- bulkRNA_counts_raw %>%
mutate(across( # For every column you want...
starts_with("ae"), # ...change all studynumber
~ case_when(
. == Inf ~ max(.[is.finite(.)]), # +Inf becomes the finite max.
. == -Inf ~ min(.[is.finite(.)]), # -Inf becomes the finite min.
TRUE ~ . # Other values stay the same.
)
)
)
```
#### Annotating
```{r}
library("devtools")
devtools::install_github("stephenturner/annotables")
library(dplyr)
library(annotables)
# Columns of interest
# entrez
# symbol
# chr
# start
# end
# strand
# biotype
# description
cat("\nChecking existence of duplicate ENSEMBL IDs - there shouldn't be any.\n")
id <- temp$ENSEMBL_gene_ID
id[ id %in% id[duplicated(id)] ]
rm(id)
```
```{r}
cat("\nAnnotating with b37.\n")
bulkRNA_counts <- temp %>%
# arrange(p.adjusted) %>%
# head(20) %>%
inner_join(grch37, by=c("ENSEMBL_gene_ID"="ensgene")) %>%
# select(gene, estimate, p.adjusted, symbol, description) %>%
relocate(entrez, symbol, chr, start, end, strand, biotype, description,
.before = ae1618) %>%
dplyr::filter(duplicated(ENSEMBL_gene_ID) == FALSE)
head(bulkRNA_counts)
id <- bulkRNA_counts$ENSEMBL_gene_ID
id[ id %in% id[duplicated(id)] ]
```
<!-- We will fix the `STUDY_NUMBER` header and variable. -->
<!-- ```{r FixBulkRNAseq} -->
<!-- # counts -->
<!-- for ( col in 6:ncol(bulkRNA_counts)){ -->
<!-- colnames(bulkRNA_counts)[col] <- gsub("[a-zA-Z ]", "", colnames(bulkRNA_counts)[col]) -->
<!-- } -->
<!-- head(bulkRNA_counts) -->
<!-- # meta data -->
<!-- bulkRNA_meta$study_number <- gsub("[a-zA-Z ]", "", bulkRNA_meta$study_number) -->
<!-- names(bulkRNA_meta)[names(bulkRNA_meta) == "study_number"] <- "STUDY_NUMBER" -->
<!-- head(bulkRNA_meta) -->
<!-- ``` -->
## Clinical data
Loading Athero-Express clinical data.
```{r LoadAEDB}
require(haven)
# AEDB <- haven::read_sav(paste0(AEDB_loc, "/2019-3NEW_AtheroExpressDatabase_ScientificAE_02072019_IC_added.sav"))
AEDB <- haven::read_sav(paste0(AEDB_loc, "/2020_1_NEW_AtheroExpressDatabase_ScientificAE_16-03-2020.sav"))
```
### Fix STUDY_NUMBER
We will fix the `STUDY_NUMBER` to match the bulkRNAseq data.
```{r FixStudyNumber}
AEDB$STUDY_NUMBER <- paste0("ae", AEDB$STUDY_NUMBER)
head(AEDB$STUDY_NUMBER)
```
### Fixing and creating variables
We need to be very strict in defining _symptoms._ Therefore we will fix a new variable that groups _symptoms_ at inclusion.
Coding of _symptoms_ is as follows:
- missing -999
- Asymptomatic 0
- TIA 1
- minor stroke 2
- Major stroke 3
- Amaurosis fugax 4
- Four vessel disease 5
- Vertebrobasilary TIA 7
- Retinal infarction 8
- Symptomatic, but aspecific symtoms 9
- Contralateral symptomatic occlusion 10
- retinal infarction 11
- armclaudication due to occlusion subclavian artery, CEA needed for bypass 12
- retinal infarction + TIAs 13
- Ocular ischemic syndrome 14
- ischemisch glaucoom 15
- subclavian steal syndrome 16
- TGA 17
We will group as follows in `Symptoms.5G`:
1. Asymptomatic > 0
2. TIA > 1, 7, 13
3. Stroke > 2, 3
4. Ocular > 4, 14, 15
5. Retinal infarction > 8, 11
6. Other > 5, 9, 10, 12, 16, 17
We will also group as follows in `AsymptSympt`:
1. Asymptomatic > 0
2. TIA > 1, 7, 13 + Stroke > 2, 3
3. Ocular > 4, 14, 15 + Retinal infarction > 8, 11 + Other > 5, 9, 10, 12, 16, 17
We will also group as follows in `AsymptSympt2G`:
1. Asymptomatic > 0
2. TIA > 1, 7, 13 + Stroke > 2, 3 Ocular > 4, 14, 15 + Retinal infarction > 8, 11 + Other > 5, 9, 10, 12, 16, 17
```{r FixSymptoms, message=FALSE, warning=FALSE}
# Fix symptoms
attach(AEDB)
AEDB$sympt[is.na(AEDB$sympt)] <- -999
# Symptoms.5G
AEDB[,"Symptoms.5G"] <- NA
# AEDB$Symptoms.5G[sympt == "NA"] <- "Asymptomatic"
AEDB$Symptoms.5G[sympt == -999] <- NA
AEDB$Symptoms.5G[sympt == 0] <- "Asymptomatic"
AEDB$Symptoms.5G[sympt == 1 | sympt == 7 | sympt == 13] <- "TIA"
AEDB$Symptoms.5G[sympt == 2 | sympt == 3] <- "Stroke"
AEDB$Symptoms.5G[sympt == 4 | sympt == 14 | sympt == 15 ] <- "Ocular"
AEDB$Symptoms.5G[sympt == 8 | sympt == 11] <- "Retinal infarction"
AEDB$Symptoms.5G[sympt == 5 | sympt == 9 | sympt == 10 | sympt == 12 | sympt == 16 | sympt == 17] <- "Other"
# AsymptSympt
AEDB[,"AsymptSympt"] <- NA
AEDB$AsymptSympt[sympt == -999] <- NA
AEDB$AsymptSympt[sympt == 0] <- "Asymptomatic"
AEDB$AsymptSympt[sympt == 1 | sympt == 7 | sympt == 13 | sympt == 2 | sympt == 3] <- "Symptomatic"
AEDB$AsymptSympt[sympt == 4 | sympt == 14 | sympt == 15 | sympt == 8 | sympt == 11 | sympt == 5 | sympt == 9 | sympt == 10 | sympt == 12 | sympt == 16 | sympt == 17] <- "Ocular and others"
# AsymptSympt
AEDB[,"AsymptSympt2G"] <- NA
AEDB$AsymptSympt2G[sympt == -999] <- NA
AEDB$AsymptSympt2G[sympt == 0] <- "Asymptomatic"
AEDB$AsymptSympt2G[sympt == 1 | sympt == 7 | sympt == 13 | sympt == 2 | sympt == 3 | sympt == 4 | sympt == 14 | sympt == 15 | sympt == 8 | sympt == 11 | sympt == 5 | sympt == 9 | sympt == 10 | sympt == 12 | sympt == 16 | sympt == 17] <- "Symptomatic"
detach(AEDB)
# table(AEDB$sympt, useNA = "ifany")
# table(AEDB$AsymptSympt2G, useNA = "ifany")
# table(AEDB$Symptoms.5G, useNA = "ifany")
#
# table(AEDB$AsymptSympt2G, AEDB$sympt, useNA = "ifany")
# table(AEDB$Symptoms.5G, AEDB$sympt, useNA = "ifany")
table(AEDB$AsymptSympt2G, AEDB$Symptoms.5G, useNA = "ifany")
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "sympt", "Symptoms.5G", "AsymptSympt"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# table(AEDB.temp$Symptoms.5G, AEDB.temp$AsymptSympt)
#
# rm(AEDB.temp)
```
We will also fix the _plaquephenotypes_ variable.
Coding of symptoms is as follows:
- missing -999
- not relevant -888
- fibrous 1
- fibroatheromatous 2
- atheromatous 3
```{r FixPlaquePhenotypes, message=FALSE, warning=FALSE}
# Fix plaquephenotypes
attach(AEDB)
AEDB[,"OverallPlaquePhenotype"] <- NA
AEDB$OverallPlaquePhenotype[plaquephenotype == -999] <- NA
AEDB$OverallPlaquePhenotype[plaquephenotype == -999] <- NA
AEDB$OverallPlaquePhenotype[plaquephenotype == 1] <- "fibrous"
AEDB$OverallPlaquePhenotype[plaquephenotype == 2] <- "fibroatheromatous"
AEDB$OverallPlaquePhenotype[plaquephenotype == 3] <- "atheromatous"
detach(AEDB)
table(AEDB$OverallPlaquePhenotype)
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "plaquephenotype", "OverallPlaquePhenotype"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# rm(AEDB.temp)
```
We will also fix the _diabetes_ status variable. We define diabetes as history of a diagnosis and/or use of glucose-lowering medications.
```{r FixDiabetes, message=FALSE, warning=FALSE}
# Fix diabetes
attach(AEDB)
AEDB[,"DiabetesStatus"] <- NA
AEDB$DiabetesStatus[DM.composite == -999] <- NA
AEDB$DiabetesStatus[DM.composite == 0] <- "Control (no Diabetes Dx/Med)"
AEDB$DiabetesStatus[DM.composite == 1] <- "Diabetes"
detach(AEDB)
table(AEDB$DM.composite)
table(AEDB$DiabetesStatus)
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "DM.composite", "DiabetesStatus"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
# AEDB.temp$DiabetesStatus <- to_factor(AEDB.temp$DiabetesStatus)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# rm(AEDB.temp)
```
We will also fix the _smoking_ status variable. We are interested in whether someone never, ever or is currently (at the time of inclusion) smoking. This is based on the questionnaire.
- `diet801`: are you a smoker?
- `diet802`: did you smoke in the past?
We already have some variables indicating smoking status:
- `SmokingReported`: patient has reported to smoke.
- `SmokingYearOR`: smoking in the year of surgery?
- `SmokerCurrent`: currently smoking?
```{r FixSmoking, message=FALSE, warning=FALSE}
require(labelled)
AEDB$diet801 <- to_factor(AEDB$diet801)
AEDB$diet802 <- to_factor(AEDB$diet802)
AEDB$diet805 <- to_factor(AEDB$diet805)
AEDB$SmokingReported <- to_factor(AEDB$SmokingReported)
AEDB$SmokerCurrent <- to_factor(AEDB$SmokerCurrent)
AEDB$SmokingYearOR <- to_factor(AEDB$SmokingYearOR)
# table(AEDB$diet801)
# table(AEDB$diet802)
# table(AEDB$SmokingReported)
# table(AEDB$SmokerCurrent)
# table(AEDB$SmokingYearOR)
# table(AEDB$SmokingReported, AEDB$SmokerCurrent, useNA = "ifany", dnn = c("Reported smoking", "Current smoker"))
#
# table(AEDB$diet801, AEDB$diet802, useNA = "ifany", dnn = c("Smoker", "Past smoker"))
cat("\nFixing smoking status.\n")
attach(AEDB)
AEDB[,"SmokerStatus"] <- NA
AEDB$SmokerStatus[diet802 == "don't know"] <- "Never smoked"
AEDB$SmokerStatus[diet802 == "I still smoke"] <- "Current smoker"
AEDB$SmokerStatus[SmokerCurrent == "no" & diet802 == "no"] <- "Never smoked"
AEDB$SmokerStatus[SmokerCurrent == "no" & diet802 == "yes"] <- "Ex-smoker"
AEDB$SmokerStatus[SmokerCurrent == "yes"] <- "Current smoker"
AEDB$SmokerStatus[SmokerCurrent == "no data available/missing"] <- NA
# AEDB$SmokerStatus[is.na(SmokerCurrent)] <- "Never smoked"
detach(AEDB)
cat("\n* Current smoking status.\n")
table(AEDB$SmokerCurrent,
useNA = "ifany",
dnn = c("Current smoker"))
cat("\n* Updated smoking status.\n")
table(AEDB$SmokerStatus,
useNA = "ifany",
dnn = c("Updated smoking status"))
cat("\n* Comparing to 'SmokerCurrent'.\n")
table(AEDB$SmokerStatus, AEDB$SmokerCurrent,
useNA = "ifany",
dnn = c("Updated smoking status", "Current smoker"))
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "DM.composite", "DiabetesStatus"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
# AEDB.temp$DiabetesStatus <- to_factor(AEDB.temp$DiabetesStatus)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# rm(AEDB.temp)
```
We will also fix the _alcohol_ status variable.
```{r FixAlcohol, message=FALSE, warning=FALSE}
# Fix diabetes
attach(AEDB)
AEDB[,"AlcoholUse"] <- NA
AEDB$AlcoholUse[diet810 == -999] <- NA
AEDB$AlcoholUse[diet810 == 0] <- "No"
AEDB$AlcoholUse[diet810 == 1] <- "Yes"
detach(AEDB)
table(AEDB$AlcoholUse)
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "diet810", "AlcoholUse"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
# AEDB.temp$AlcoholUse <- to_factor(AEDB.temp$AlcoholUse)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# rm(AEDB.temp)
```
We will also fix a history of CAD, stroke or peripheral intervention status variable. This will be based on `CAD_history`, `Stroke_history`, and `Peripheral.interv`
```{r FixCAD_History, message=FALSE, warning=FALSE}
# Fix diabetes
attach(AEDB)
AEDB[,"MedHx_CVD"] <- NA
AEDB$MedHx_CVD[CAD_history == 0 | Stroke_history == 0 | Peripheral.interv == 0] <- "No"
AEDB$MedHx_CVD[CAD_history == 1 | Stroke_history == 1 | Peripheral.interv == 1] <- "yes"
detach(AEDB)
table(AEDB$CAD_history)
table(AEDB$Stroke_history)
table(AEDB$Peripheral.interv)
table(AEDB$MedHx_CVD)
# AEDB.temp <- subset(AEDB, select = c("STUDY_NUMBER", "UPID", "Age", "Gender", "Hospital", "Artery_summary", "diet810", "AlcoholUse"))
# require(labelled)
# AEDB.temp$Gender <- to_factor(AEDB.temp$Gender)
# AEDB.temp$Hospital <- to_factor(AEDB.temp$Hospital)
# AEDB.temp$Artery_summary <- to_factor(AEDB.temp$Artery_summary)
# AEDB.temp$AlcoholUse <- to_factor(AEDB.temp$AlcoholUse)
#
# DT::datatable(AEDB.temp[1:10,], caption = "Excerpt of the whole AEDB.", rownames = FALSE)
#
# rm(AEDB.temp)
```
```{r Plaque Vulnerability, message=FALSE, warning=FALSE}
# Plaque vulnerability
# SPSS code
#
# *** syntax- Plaque vulnerability**.
# COMPUTE Macro_instab = -999.
# IF macrophages.bin=2 Macro_instab=1.
# IF macrophages.bin=1 Macro_instab=0.
# EXECUTE.
#
# COMPUTE Fat10_instab = -999.
# IF Fat.bin_10=2 Fat10_instab=1.
# IF Fat.bin_10=1 Fat10_instab=0.
# EXECUTE.
#
# COMPUTE coll_instab=-999.
# IF Collagen.bin=2 coll_instab=0.
# IF Collagen.bin=1 coll_instab=1.
# EXECUTE.
#
#
# COMPUTE SMC_instab=-999.
# IF SMC.bin=2 SMC_instab=0.
# IF SMC.bin=1 SMC_instab=1.
# EXECUTE.
#
# COMPUTE IPH_instab=-999.
# IF IPH.bin=0 IPH_instab=0.
# IF IPH.bin=1 IPH_instab=1.
# EXECUTE.
#
# COMPUTE Instability=Macro_instab + Fat10_instab + coll_instab + SMC_instab + IPH_instab.
# EXECUTE.
require(labelled)
AEDB$Macrophages.bin <- to_factor(AEDB$Macrophages.bin)
AEDB$SMC.bin <- to_factor(AEDB$SMC.bin)
AEDB$IPH.bin <- to_factor(AEDB$IPH.bin)
AEDB$Calc.bin <- to_factor(AEDB$Calc.bin)
AEDB$Collagen.bin <- to_factor(AEDB$Collagen.bin)
AEDB$Fat.bin_10 <- to_factor(AEDB$Fat.bin_10)
AEDB$Fat.bin_40 <- to_factor(AEDB$Fat.bin_40)
table(AEDB$Macrophages.bin)
table(AEDB$Fat.bin_10)
table(AEDB$Collagen.bin)
table(AEDB$SMC.bin)
table(AEDB$IPH.bin)
# Fix plaquephenotypes
attach(AEDB)
# mac instability
AEDB[,"MAC_Instability"] <- NA
AEDB$MAC_Instability[Macrophages.bin == -999] <- NA
AEDB$MAC_Instability[Macrophages.bin == "no/minor"] <- 0
AEDB$MAC_Instability[Macrophages.bin == "moderate/heavy"] <- 1
# fat instability
AEDB[,"FAT10_Instability"] <- NA
AEDB$FAT10_Instability[Fat.bin_10 == -999] <- NA
AEDB$FAT10_Instability[Fat.bin_10 == " <10%"] <- 0
AEDB$FAT10_Instability[Fat.bin_10 == " >10%"] <- 1
# col instability
AEDB[,"COL_Instability"] <- NA
AEDB$COL_Instability[Collagen.bin == -999] <- NA
AEDB$COL_Instability[Collagen.bin == "no/minor"] <- 1
AEDB$COL_Instability[Collagen.bin == "moderate/heavy"] <- 0
# smc instability
AEDB[,"SMC_Instability"] <- NA
AEDB$SMC_Instability[SMC.bin == -999] <- NA
AEDB$SMC_Instability[SMC.bin == "no/minor"] <- 1
AEDB$SMC_Instability[SMC.bin == "moderate/heavy"] <- 0
# iph instability
AEDB[,"IPH_Instability"] <- NA
AEDB$IPH_Instability[IPH.bin == -999] <- NA
AEDB$IPH_Instability[IPH.bin == "no"] <- 0
AEDB$IPH_Instability[IPH.bin == "yes"] <- 1
detach(AEDB)
table(AEDB$MAC_Instability, useNA = "ifany")
table(AEDB$FAT10_Instability, useNA = "ifany")
table(AEDB$COL_Instability, useNA = "ifany")
table(AEDB$SMC_Instability, useNA = "ifany")
table(AEDB$IPH_Instability, useNA = "ifany")
# creating vulnerability index
AEDB <- AEDB %>% mutate(Plaque_Vulnerability_Index = factor(rowSums(.[grep("_Instability", names(.))], na.rm = TRUE)),
)
table(AEDB$Plaque_Vulnerability_Index, useNA = "ifany")
# str(AEDB$Plaque_Vulnerability_Index)
```
# Athero-Express Biobank Study
## Baseline characteristics
We are interested in the following variables at baseline.
- Age (years)
- Female sex (N, %)
- Hypertension (N, %)
- SBP (mmHg)
- DBP (mmHg)
- Diabetes mellitus (N, %)
- Total cholesterol levels (mg/dL)
- LDL cholesterol levels (mg/dL)
- HDL cholesterol levels (mg/dL)
- Triglyceride levels (mg/dL)
- Use of statins (N, %)
- Use of antiplatelet drugs (N, %)
- BMI (kg/m²)
- Smoking status (N, %)
- Never smokers
- Ex-smokers
- Current smokers
- History of CAD (N, %)
- History of PAD (N, %)
- Clinical manifestations
- Asymptomatic
- Amaurosis fugax
- TIA
- Stroke
- eGFR (mL/min/1.73 m²)
```{r Baseline AEDB: creation, include = FALSE}
cat("====================================================================================================\n")
cat("SELECTION THE SHIZZLE\n")
### Artery levels
# AEdata$Artery_summary:
# value label
# NOT USE - 0 No artery known (yet), no surgery (patient ill, died, exited study), re-numbered to AAA
# USE - 1 carotid (left & right)
# USE - 2 femoral/iliac (left, right or both sides)
# NOT USE - 3 other carotid arteries (common, external)
# NOT USE - 4 carotid bypass and injury (left, right or both sides)
# NOT USE - 5 aneurysmata (carotid & femoral)
# NOT USE - 6 aorta
# NOT USE - 7 other arteries (renal, popliteal, vertebral)
# NOT USE - 8 femoral bypass, angioseal and injury (left, right or both sides)
### AEdata$informedconsent
# value label
# NOT USE - -999 missing
# NOT USE - 0 no, died
# USE - 1 yes
# USE - 2 yes, health treatment when possible
# USE - 3 yes, no health treatment
# USE - 4 yes, no health treatment, no commercial business
# NOT USE - 5 yes, no tissue, no commerical business
# NOT USE - 6 yes, no tissue, no questionnaires, no medical info, no commercial business
# USE - 7 yes, no questionnaires, no health treatment, no commercial business
# USE - 8 yes, no questionnaires, health treatment when possible
# NOT USE - 9 yes, no tissue, no questionnaires, no health treatment, no commerical business
# USE - 10 yes, no health treatment, no medical info, no commercial business
# NOT USE - 11 yes, no tissue, no questionnaires, no health treatment, no medical info, no commercial business
# USE - 12 yes, no questionnaires, no health treatment
# NOT USE - 13 yes, no tissue, no health treatment
# NOT USE - 14 yes, no tissue, no questionnaires
# NOT USE - 15 yes, no tissue, health treatment when possible
# NOT USE - 16 yes, no tissue
# USE - 17 yes, no commerical business
# USE - 18 yes, health treatment when possible, no commercial business
# USE - 19 yes, no medical info, no commercial business
# USE - 20 yes, no questionnaires
# NOT USE - 21 yes, no tissue, no questionnaires, no health treatment, no medical info
# NOT USE - 22 yes, no tissue, no questionnaires, no health treatment, no commercial business
# USE - 23 yes, no medical info
# USE - 24 yes, no questionnaires, no commercial business
# USE - 25 yes, no questionnaires, no health treatment, no medical info
# USE - 26 yes, no questionnaires, health treatment when possible, no commercial business
# USE - 27 yes, no health treatment, no medical info
# NOT USE - 28 no, doesn't want to
# NOT USE - 29 no, unable to sign
# NOT USE - 30 no, no reaction
# NOT USE - 31 no, lost
# NOT USE - 32 no, too old
# NOT USE - 34 yes, no medical info, health treatment when possible
# NOT USE - 35 no (never asked for IC because there was no tissue)
# USE - 36 yes, no medical info, no commercial business, health treatment when possible
# NOT USE - 37 no, endpoint
# USE - 38 wil niets invullen, wel alles gebruiken
# USE - 39 second informed concents: yes, no commercial business
# NOT USE - 40 nooit geincludeerd
cat("- sanity checking PRIOR to selection")
library(data.table)
ae.gender <- ifelse(AEDB$Gender == 0, "Female", "Male")
ae.hospital <- ifelse(AEDB$Hospital == 1, "Antonius", "UMCU")
table(ae.gender, ae.hospital, dnn = c("Sex", "Hospital"))
ae.gender <- ifelse(AEDB$Gender == 0, "Female", "Male")
table(ae.gender, AEDB$Artery_summary, dnn = c("Sex", "Artery"))
# table(ae.gender, AEDB$informedconsent, dnn = c("Sex", "IC"))
rm(ae.gender, ae.hospital)
# I change numeric and factors manually because, well, I wouldn't know how to fix it otherwise
# to have this 'tibble' work with 'tableone'... :-)
AEDB$Age <- as.numeric(AEDB$Age)
AEDB$diastoli <- as.numeric(AEDB$diastoli)
AEDB$systolic <- as.numeric(AEDB$systolic)
AEDB$TC_finalCU <- as.numeric(AEDB$TC_finalCU)
AEDB$LDL_finalCU <- as.numeric(AEDB$LDL_finalCU)
AEDB$HDL_finalCU <- as.numeric(AEDB$HDL_finalCU)
AEDB$TG_finalCU <- as.numeric(AEDB$TG_finalCU)
AEDB$TC_final <- as.numeric(AEDB$TC_final)
AEDB$LDL_final <- as.numeric(AEDB$LDL_final)
AEDB$HDL_final <- as.numeric(AEDB$HDL_final)
AEDB$TG_final <- as.numeric(AEDB$TG_final)
AEDB$Age <- as.numeric(AEDB$Age)
AEDB$GFR_MDRD <- as.numeric(AEDB$GFR_MDRD)
AEDB$BMI <- as.numeric(AEDB$BMI)
AEDB$eCigarettes <- as.numeric(AEDB$eCigarettes)
AEDB$ePackYearsSmoking <- as.numeric(AEDB$ePackYearsSmoking)
AEDB$EP_composite_time <- as.numeric(AEDB$EP_composite_time)
AEDB$macmean0 <- as.numeric(AEDB$macmean0)
AEDB$smcmean0 <- as.numeric(AEDB$smcmean0)
AEDB$neutrophils <- as.numeric(AEDB$neutrophils)
AEDB$Mast_cells_plaque <- as.numeric(AEDB$Mast_cells_plaque)
AEDB$vessel_density_averaged <- as.numeric(AEDB$vessel_density_averaged)
AEDB$MAC_rankNorm <- qnorm((rank(AEDB$macmean0, na.last = "keep") - 0.5) / sum(!is.na(AEDB$macmean0)))
AEDB$SMC_rankNorm <- qnorm((rank(AEDB$smcmean0, na.last = "keep") - 0.5) / sum(!is.na(AEDB$smcmean0)))
AEDB$Neutrophils_rankNorm <- qnorm((rank(AEDB$neutrophils, na.last = "keep") - 0.5) / sum(!is.na(AEDB$neutrophils)))
AEDB$MastCells_rankNorm <- qnorm((rank(AEDB$Mast_cells_plaque, na.last = "keep") - 0.5) / sum(!is.na(AEDB$Mast_cells_plaque)))
AEDB$VesselDensity_rankNorm <- qnorm((rank(AEDB$vessel_density_averaged, na.last = "keep") - 0.5) / sum(!is.na(AEDB$vessel_density_averaged)))
require(labelled)
AEDB$ORyear <- to_factor(AEDB$ORyear)
AEDB$Gender <- to_factor(AEDB$Gender)
AEDB$Hospital <- to_factor(AEDB$Hospital)
AEDB$KDOQI <- to_factor(AEDB$KDOQI)
AEDB$BMI_WHO <- to_factor(AEDB$BMI_WHO)
AEDB$DiabetesStatus <- to_factor(AEDB$DiabetesStatus)
AEDB$SmokerStatus <- to_factor(AEDB$SmokerStatus)