-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_lipc_Nightingale20.R
224 lines (200 loc) · 8.1 KB
/
12_lipc_Nightingale20.R
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
# Get libs ----
# Clear environment
rm(list = ls())
# install.packages(readxl)
# install.packages(ieugwasr)
library(ieugwasr)
library(ggplot2)
# Set working directory
wd <- "/Users/fredriklandfors/projekt/lipase_genmimicry"
# Multiple comparisons correction ----
m_comp = 9
# Get gwas ids
gwas <- readxl::read_xlsx("./data/gwas_id.xlsx", sheet = "Nightingale_2020")
## Get effect of SNP on total plasma cholesterol ----
tg <- rbind(
ieugwasr::associations("rs115849089", "met-d-Total_TG"), # LPL
ieugwasr::associations("rs116843064", "met-d-Total_TG"), # ANGPTL4
ieugwasr::associations("rs1800588", "met-d-Total_TG") # LIPC
)
# Import data ----
import_gwas <- function(rsid,
gwas_ids,
gene_name,
scalevar,
scalenum) {
# get data from UKBB (requires internet connection)
out <- ieugwasr::associations(rsid, gwas_ids)
# define cat vars
out <- merge(gwas[c("gwas_id", "class")], out, by.x = "gwas_id", by.y = "id")
# get std errors
out$se_min <- out$beta - out$se
out$se_max <- out$beta + out$se
# scale with outcome var
out[, paste0("beta.", scalevar)] <- out$beta / scalenum
out[, paste0("se.", scalevar)] <- out$se / scalenum
out[, paste0("se_min.", scalevar)] <- out$beta / scalenum - abs(out$se / scalenum)
out[, paste0("se_max.", scalevar)] <- out$beta / scalenum + abs(out$se / scalenum)
# rename
names(out) <- sapply(names(out), function(x) {paste0(x, ".", gene_name)})
# return
return(out)
}
## Get LPL rs116843064 [eQTL] ----
lpl_nmr <- import_gwas(
rsid = "rs115849089",
gwas_ids = gwas$gwas_id,
gene_name = "LPL",
scalevar = "tg",
scalenum = -subset(tg, rsid == "rs115849089")$beta
)
## Get rs116843064 [E40K] (ANGPTL4) summary stats and return to df ----
angptl4_nmr <- import_gwas(
rsid = "rs116843064",
gwas_ids = gwas$gwas_id,
gene_name = "ANGPTL4",
scalevar = "tg",
scalenum = -subset(tg, rsid == "rs116843064")$beta
)
## Get rs1800588 [promoter variant] (HL/LIPC) summary stats and return to df ---
LIPC_nmr <- import_gwas(
rsid = "rs1800588",
gwas_ids = gwas$gwas_id,
gene_name = "LIPC",
scalevar = "tg",
scalenum = -subset(tg, rsid == "rs1800588")$beta
)
## Merge frames ----
cbind_df <- cbind(angptl4_nmr, LIPC_nmr, lpl_nmr)
cbind_df$class.ANGPTL4 <- ifelse(is.na(cbind_df$class.ANGPTL4), "Other metabolites",
cbind_df$class.ANGPTL4)
cbind_df$class.LIPC <- ifelse(is.na(cbind_df$class.LIPC), "Other metabolites",
cbind_df$class.LIPC)
cbind_df$class.LPL <- ifelse(is.na(cbind_df$class.LIPC), "Other metabolites",
cbind_df$class.LIPC)
## Save to file ----
data.table::fwrite(cbind_df, file = paste0(wd, "/data/12_lipc_Nightingale20.txt"), sep = "\t")
## Load data ----
cbind_df <- data.table::fread(file = paste0(wd, "/data/12_lipc_Nightingale20.txt"), sep = "\t")
# Remove scaling param
cbind_df <- subset(cbind_df, gwas_id.LPL != "met-d-Total_TG")
# Plots and regressions ----
## Graphical parameters ----
### scatter_plot ----
scatter.width = 2.4
scatter.height = 2.4
scatter.hvline.color = "grey25"
scatter.hline.size = 0.3
scatter.vline.size = 0.3
scatter.abline.size = 0.3
scatter.smooth.size = 0.3
scatter.linerange.size = 0.3
scatter.axis.line = element_line(size = 0.4)
scatter.axis.ticks = element_line(size = 0.4)
scatter.plot.title = element_text(family = "Helvetica", size = 6, colour = "black", face = "bold", hjust = 0.5,
margin = margin(1,1,1,1))
scatter.plot.subtitle = element_text(family = "Helvetica", size = 5, colour = "black", face = "italic", hjust = 0.5,
margin = margin(1,1,2,1))
scatter.legend.text = element_text(family = "Helvetica", size = 4, colour = "black", face = "plain")
scatter.legend.key.size = unit(0, 'points')
scatter.legend.margin = margin(0, 0, 0, 0)
scatter.axis.title = element_text(family = "Helvetica", size = 5, face = "plain")
scatter.axis.text.x = element_text(family = "Helvetica", size = 5, colour = "black", face = "plain")
scatter.axis.text.y = element_text(family = "Helvetica", size = 5, colour = "black", face = "plain")
scatter.xlims = c(-3.5, 3.5)
scatter.ylims = c(-3.5, 3.5)
scatter.point.size = 1
scatter.stroke = 0.25
## Plots ----
scatter_plot <- function(df,
title = "",
subtitle = "",
x_var, y_var,
scale_var = "",
x_gene, y_gene,
x_lab, y_lab,
x_lim = c(-1, 1),
y_lim = c(-1, 1),
x_breaks = seq(-1, 1, 1),
y_breaks = seq(-1, 1, 1),
point_size = 2) {
out <- ggplot(data = df, mapping = aes_string(x = x_var, y = y_var)) +
ggtitle(label = paste0(title),
subtitle = paste0(subtitle)) +
xlab(paste0(x_lab, "\n[1-SD effect on parameter per 1-SD TG change]")) +
ylab(paste0(y_lab, "\n[1-SD effect on parameter per 1-SD TG change]")) +
scale_x_continuous(limits = x_lim, breaks = x_breaks) +
scale_y_continuous(limits = y_lim, breaks = y_breaks) +
geom_hline(yintercept = 0, size = scatter.hline.size, color = scatter.hvline.color, linetype = "solid") +
geom_vline(xintercept = 0, size = scatter.vline.size, color = scatter.hvline.color, linetype = "solid") +
geom_abline(intercept = 0, slope = 1, color = "grey50", linetype = "dashed",
size = scatter.abline.size) +
geom_linerange(aes_string(
xmin = paste0("se_min.tg.", scale_var, x_gene),
xmax = paste0("se_max.tg.", scale_var, x_gene)
), color = "grey75", size = scatter.linerange.size
) +
geom_linerange(aes_string(
ymin = paste0("se_min.tg.", scale_var, y_gene),
ymax = paste0("se_max.tg.", scale_var, y_gene)
), color = "grey75", size = scatter.linerange.size
) +
geom_smooth(method = "lm", formula = y ~ x, color = "black",
linetype = "dashed", size = scatter.smooth.size, fullrange = TRUE,
level = 1 - 0.05 / m_comp) +
geom_point(aes_string(fill = paste0("class.", x_gene)),
size = point_size, stroke = scatter.stroke,
alpha = 1, shape = 21, color = "black") +
theme_classic() +
theme(
plot.title = scatter.plot.title,
plot.subtitle = scatter.plot.subtitle,
legend.title = element_blank(),
legend.justification = c(1, 0),
legend.position = c(1, 0.025),
legend.key.size = scatter.legend.key.size,
legend.text = scatter.legend.text,
legend.margin = scatter.legend.margin,
axis.title = scatter.axis.title,
axis.text.x = scatter.axis.text.x,
axis.text.y = scatter.axis.text.y,
axis.line = scatter.axis.line,
axis.ticks = scatter.axis.ticks
) +
scale_fill_manual(breaks = c("ApoA-I", "ApoB", "VLDL", "IDL", "LDL",
"HDL", "Fatty acids", "Other lipids", "Other metabolites"),
values = c("white", "black", "#00A08A", "#F98400", "#F2AD00",
"#5BBCD6", "#FD6467", "#046C9A", "grey50")
) +
coord_fixed(ratio = 1)
return(out)
}
### LIPC vs. ANGPTL4 ----
p1 <- scatter_plot(
cbind_df,
title = "HUMAN PLASMA: HL (LIPC) vs. ANGPTL4",
subtitle = "Systemic effects on metabolic parameters",
y_var = "beta.tg.LIPC",
x_var = "beta.tg.ANGPTL4",
scale_var = "",
y_gene = "LIPC",
x_gene = "ANGPTL4",
y_lab = "LIPC (rs1800588-T [promoter variant])",
x_lab = "ANGPTL4 (rs116843064-A [E40K])",
y_lim = c(-9, 9),
x_lim = c(-9, 9),
y_breaks = seq(-9, 9, 1),
x_breaks = seq(-9, 9, 1),
point_size = scatter.point.size
)
### write to file ----
ggsave(plot = p1,
path = paste0(wd, "/plots/"),
filename = "12_lipc_nightingale20.pdf",
width = scatter.width, height = scatter.height,
units = "in", dpi = 1100)
# Regression analyses ----
f1 <- lm(formula = beta.tg.LIPC ~ beta.tg.ANGPTL4, data = cbind_df)
s1 <- summary(f1)
## Get coef confidence intervals ----
c1 <- confint(f1, level = 1 - 0.05 / m_comp)