-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4. forest.poster.sign.Rmd
291 lines (214 loc) · 8.71 KB
/
4. forest.poster.sign.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
---
title: "Forest plot for age of ischemic stroke onset."
author: "Joanna von Berg; [Sander W. van der Laan, PhD](https://swvanderlaan.github.io) | @swvanderlaan | s.w.vanderlaan@gmail.com"
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: 6
fig_retina: 2
fig_width: 7
highlight: tango
theme: lumen
toc: yes
toc_float:
collapsed: no
smooth_scroll: yes
mainfont: Arial
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/',
wwarning = TRUE, # show warnings during codebook generation
message = TRUE, # show messages during codebook generation
error = TRUE, # do not interrupt codebook generation in case of errors,
# usually better for debugging
echo = TRUE, # show R code
eval = TRUE)
```
# Setup
We will clean the environment, setup the locations, define colors, and create a datestamp.
*Clean the environment.*
```{r echo = FALSE}
rm(list = ls())
```
*Set locations and working directories...*
```{r LocalSystem, echo = FALSE}
### Operating System Version
### MacBook Pro
ROOT_loc = "/Users/slaan3/OneDrive - UMC Utrecht"
AEROOT_loc = "/Users/slaan3"
# STORAGE_loc = "/Volumes/LaCie/"
STORAGE_loc = "/Users/slaan3/"
GENOMIC_loc = paste0(ROOT_loc, "/Genomics")
AEDB_loc = paste0(AEROOT_loc, "/Athero-Express/AE-AAA_GS_DBs")
LAB_loc = paste0(GENOMIC_loc, "/LabBusiness")
PLINK_loc=paste0(STORAGE_loc,"/PLINK")
AEGSQC_loc = paste0(PLINK_loc, "/_AE_ORIGINALS/AEGS_COMBINED_QC2018")
MICHIMP_loc=paste0(PLINK_loc,"/_AE_ORIGINALS/AEGS_COMBINED_EAGLE2_1000Gp3v5HRCr11")
GWAS_loc=paste0(PLINK_loc,"/_GWAS_Datasets/_SiGN")
PROJECT_loc = paste0(AEROOT_loc, "/git/CirculatoryHealth/AAO_IschemicStroke")
# use this if there is relevant information here.
TARGET_loc = paste0(PROJECT_loc, "/targets")
### SOME VARIABLES WE NEED DOWN THE LINE
TRAIT_OF_INTEREST = "AAO" # Phenotype
PROJECTNAME = "AAO"
cat("\nCreate a new analysis directory...\n")
ifelse(!dir.exists(file.path(PROJECT_loc, "/",PROJECTNAME)),
dir.create(file.path(PROJECT_loc, "/",PROJECTNAME)),
FALSE)
ANALYSIS_loc = paste0(PROJECT_loc,"/",PROJECTNAME)
ifelse(!dir.exists(file.path(ANALYSIS_loc, "/PLOTS")),
dir.create(file.path(ANALYSIS_loc, "/PLOTS")),
FALSE)
PLOT_loc = paste0(ANALYSIS_loc,"/PLOTS")
ifelse(!dir.exists(file.path(PLOT_loc, "/QC")),
dir.create(file.path(PLOT_loc, "/QC")),
FALSE)
QC_loc = paste0(PLOT_loc,"/QC")
ifelse(!dir.exists(file.path(ANALYSIS_loc, "/OUTPUT")),
dir.create(file.path(ANALYSIS_loc, "/OUTPUT")),
FALSE)
OUT_loc = paste0(ANALYSIS_loc, "/OUTPUT")
ifelse(!dir.exists(file.path(ANALYSIS_loc, "/BASELINE")),
dir.create(file.path(ANALYSIS_loc, "/BASELINE")),
FALSE)
BASELINE_loc = paste0(ANALYSIS_loc, "/BASELINE")
setwd(paste0(PROJECT_loc))
getwd()
list.files()
```
*... a package-installation function ...*
```{r}
source(paste0(PROJECT_loc, "/scripts/functions.R"))
```
*... and load those packages.*
```{r loading_packages, message=FALSE, warning=FALSE}
source(paste0(PROJECT_loc, "/scripts/packages.R"))
```
```{r}
ggplot2::theme_set(ggplot2::theme_minimal())
pander::panderOptions("table.split.table", Inf)
```
_We will create a datestamp and define the Utrecht Science Park Colour Scheme_.
```{r Setting: Colors}
Today = format(as.Date(as.POSIXlt(Sys.time())), "%Y%m%d")
Today.Report = format(as.Date(as.POSIXlt(Sys.time())), "%A, %B %d, %Y")
source(paste0(PROJECT_loc,"/scripts/colors.R"))
```
# Introduction
We will create a forest plot of the association of the _ApoE_ variant with age of onset of stroke in all groups.
# Setting the NPG colors
```{r}
library("scales")
pal_npg("nrc")(10)
show_col(pal_npg("nrc")(10))
# show_col(pal_npg("nrc", alpha = 0.6)(10))
```
# Prepare data
First we prepare the data for the forest plot derived from the meta-analysis. Note that there are two datasets (SiGN and FinnGen) for the combined and the men-only analyses, and three (SiGN, FinnGen, and WHI) for the women-only anlaysis.
```{r}
# analyses MarkerName Allele1 Allele2 Freq1 FreqSE MinFreq MaxFreq Effect StdErr P-value Direction
# all rs429358 T C 0.8445 0.0220 0.8219 0.8659 0.8800 0.1812 1.186e-06 ++
# xy rs429358 T C 0.8419 0.0222 0.8196 0.8640 0.3369 0.2281 0.1396 -+
# xx rs429358 T C 0.8616 0.0186 0.8251 0.8720 1.2854 0.1926 2.476e-11 +++
snps <- read_table(file = "SNP Chr BP Allele1 Allele2 Freq1 FreqSE MinFreq MaxFreq Beta SE P-value Direction
rs429358 19 45411941 T C 0.8445 0.0220 0.8219 0.8659 0.8800 0.1812 1.186e-06 ++
rs429358 19 45411941 T C 0.8419 0.0222 0.8196 0.8640 0.3369 0.2281 0.1396 -+
rs429358 19 45411941 T C 0.8616 0.0186 0.8251 0.8720 1.2854 0.1926 2.476e-11 +++",
col_names = TRUE)
snps
snps$analysis <- factor(c("all", "men", "women"), ordered = TRUE)
snps %>%
mutate(ci.l = Beta - 1.96*SE) %>%
mutate(ci.h = Beta + 1.96*SE) %>%
mutate(locus = "ApoE") -> snps
```
# Forest plot
```{r}
adj <- 0.33333
# pdf(file = paste0(PLOT_loc, "/21.04.30.forest.SiGN.pdf"), width = 18, height = 10)
nsnps <- 1
nph <- 3
# set the colors
#cols <- rgb(c(252,209,145,62,25), c(255,219,170,96,52), c(245,189,157,111,65), maxColorValue = 255)
# cols <- rgb(c(20,250,243,254,99), c(117,126,236,203,204), c(135,92,229,95,200), maxColorValue = 255)
cols <- c("black", uithof_color[25], "#DC0000FF", "#00A087FF", "#4DBBD5FF")
snps %>%
mutate(Beta = -Beta) %>%
ggplot(aes(x = Beta, xmax = -ci.l, xmin = -ci.h,
y = locus,
fill = analysis, shape = analysis, colour = analysis, label = analysis)) +
theme_minimal() +
theme(panel.grid.major.y = element_line(size = 0),
panel.grid.minor.y = element_line(size = 0),
panel.grid.minor = element_line(colour = cols[2], size = 0.2, linetype = 2),
panel.grid.major = element_line(colour = cols[2], size = 0.4, linetype = 2),
axis.ticks = element_line(colour = cols[1]),
text = element_text(size = 15, color = cols[1]),
axis.title.x = element_text(vjust = -1, color = cols[1]),
plot.margin = unit(x = c(0,0,1,0), units = "cm"),
axis.text.x = element_text(color = cols[1]),
axis.text.y = element_text(size = 0)) +
# labs(title = "Effect of aao SNPs in MEGASTROKE") +
geom_vline(xintercept = 0, linetype = 1, colour = cols[1], size = 1) +
xlim(c(-3,1)) +
ylab(label = "") +
xlab(label = "effect of rs429358 on age at onset of ischemic stroke [in years]") +
scale_shape_manual(values = 15:19) +
geom_point(size = 6, position = position_nudge(y = c(0, adj, -adj))) +
scale_colour_manual(values = cols[c(3,4,5)]) +
geom_errorbarh(size = 2, height = 0.05, position = position_nudge(y = c(0, adj, -adj))) +
geom_label(size = 5, color = cols[2], fill = NA, label.size = 0, position = position_nudge( y = c(0, adj, -adj)+0.15)) +
guides(shape = FALSE, colour = FALSE, label = FALSE, fill = FALSE)
# dev.off()
ggsave(file = paste0(PLOT_loc, "/21.04.30.forest.SiGN.eps"), last_plot())
ggsave(file = paste0(PLOT_loc, "/21.04.30.forest.SiGN.pdf"), last_plot())
# ggsave(file = paste0(PLOT_loc, "/21.04.30.forest.SiGN.png"), last_plot())
```
# Difference between sexes
The _ApoE_-rs429358 is associated with stroke AAO in both men and women, although the magnitude of association is seems stronger in women than men. Here we formally test this.
```{r}
# reference https://stackoverflow.com/questions/62521112/compute-the-difference-between-two-different-regressions-in-r
set.seed(9114)
compare.coeff <- function(b1,se1,b2,se2){
delta = b1-b2
se = sqrt(se1^2+se2^2)
Zscore = (delta)/se
p_value = 2*pnorm(-abs(Zscore))
c(delta=delta,se=se,Zscore=Zscore,p_value=p_value)
}
compare.coeff(snps$Beta[2], # men
snps$SE[2],
snps$Beta[3], # women
snps$SE[3])
```
# Session information
------
Version: v1.0.1
Last update: 2022-12-08
Written by: Sander W. van der Laan (s.w.vanderlaan-2[at]umcutrecht.nl).
Description: Script to create forest plot.
Minimum requirements: R version 3.4.3 (2017-06-30) -- 'Single Candle', Mac OS X El Capitan
Changes log
* v1.0.1 Updated with WHI data.
* v1.0.0 Initial version.
------
```{r eval = TRUE}
sessionInfo()
```
# Saving environment
```{r Saving}
save.image(paste0(PROJECT_loc, "/",Today,".",PROJECTNAME,".ForestPlot.RData"))
```
------
<sup>© 1979-2022 Sander W. van der Laan | s.w.vanderlaan[at]gmail.com | [swvanderlaan.github.io](https://swvanderlaan.github.io).</sup>
------