-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_variant_level_analysis_for_VTE.R
159 lines (136 loc) · 5.26 KB
/
single_variant_level_analysis_for_VTE.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
# load list od VTE MDT variants.
# load packages
library(tidyverse)
library(data.table)
# Functions:
#extaract cases IDs
get.ids = function(partecipantID_vector){
require(stringr)
id = unlist(
lapply(
lapply(partecipantID_vector,
function(x)
str_extract_all(x , pattern = "[^=| |;]+")
),
'[[',
1)
)
id_clean = id[id %>% str_length() > 4]
return(id_clean)
}
# VTE MDT sheet
df_vte = xlsx::read.xlsx("~/Desktop/VarioPath/MDT_variants/V20210211/MDT_for_thrombosis.xls", sheetIndex = 1)
# UKB participants vte info
load("/Users/luca/Library/Group Containers/G69SCX94XU.duck/Library/Application Support/duck/Volumes/logincpu.hpc.cam.ac.uk – SFTP/shared_luanluan_luca_UKB/Luanluan/data/ukb_dvt_pe_combined.rdata")
df$eid = as.character(df$eid)
# create new dt with info for analysis
dt_vte = data.table( "eid" = get.ids(df_vte$PARTECIPANTS),
"case" = T)
# get variant info
dt_vte$variant = lapply(dt_vte$eid,
function(x){
paste(df_vte[grep(x, df_vte$PARTECIPANTS),"CHROM"],
df_vte[grep(x, df_vte$PARTECIPANTS),"POS"],
df_vte[grep(x, df_vte$PARTECIPANTS),"REF"],
df_vte[grep(x, df_vte$PARTECIPANTS),"ALT"],
sep="_")
}
)
dt_vte = dt_vte %>% separate(variant, sep = ',', into = c("variant_1","variant_2"))
dt_vte$variant_1 = str_remove_all(dt_vte$variant_1, "c\\(")
dt_vte$variant_2 = str_remove_all(dt_vte$variant_2, "\\)")
write.csv(dt_vte, file = "vte_id_variants.csv", quote = F, row.names = F)
dt_vte = read.csv(file = "vte_id_variants.csv", header = T)
dt_vte$eid = as.character(dt_vte$eid)
file.remove("vte_id_variants.csv")
# UKB genetic sex
df_sex = fread("/Users/luca/Library/Group Containers/G69SCX94XU.duck/Library/Application Support/duck/Volumes/logincpu.hpc.cam.ac.uk – SFTP/shared_luanluan_luca_UKB/ukbcvo/sex_otUKBcnv.tab")[,c("f.eid","f.22001.0.0")]
df_sex$f.eid = as.character(df_sex$f.eid)
# merge info
dt_all_info = merge(df_sex, dt_vte, by.x = "f.eid", by.y = "eid", all = T)
dt_all_info$case = replace_na(dt_all_info$case, FALSE)
dt_all_info = merge(dt_all_info, df, by.x = "f.eid", by.y = "eid")
# Male analysis
dt_male = as.data.table(dt_all_info[which(dt_all_info$f.22001.0.0 == 1),])
parameter = c()
logodds = c()
SE = c()
ci = c()
p = c()
gender = c()
var = c()
for (variant in unique(dt_male$variant_1) ) {
tmp_case = dt_male[which(dt_male$variant_1 == variant),]
if (dim(tmp_case)[1]>=10){
tmp_control = dt_male[which(is.na(dt_male$variant_1)),]
tmp = rbind(tmp_case, tmp_control)
tmp$variant_1 = as.character(tmp$variant_1)
tmp$variant_1[which(is.na(tmp$variant_1))] = "no_variant"
model = glm(data = tmp, vte ~ variant_1 + bmi + ages, family = "binomial")
par = parameters::parameters(model = model, df_method="wald")
var = c(var, variant)
parameter = c(parameter, par$Parameter[2])
logodds = c(logodds, par$Coefficient[2])
SE = c(SE, par$SE[2])
ci = c(ci, paste(par$CI_low[2], par$CI_high[2], sep = "; "))
p = c(p, par$p[2])
gender = c(gender, "Male")
}
}
# Feale analysis
dt_female = as.data.table(dt_all_info[which(dt_all_info$f.22001.0.0 == 0),])
for (variant in unique(dt_female$variant_1) ) {
tmp_case = dt_female[which(dt_female$variant_1 == variant),]
if (dim(tmp_case)[1]>=10){
tmp_control = dt_female[which(is.na(dt_male$variant_1)),]
tmp = rbind(tmp_case, tmp_control)
tmp$variant_1 = as.character(tmp$variant_1)
tmp$variant_1[which(is.na(tmp$variant_1))] = "no_variant"
model = glm(data = tmp, vte ~ variant_1 + bmi + ages, family = "binomial")
par = parameters::parameters(model = model, df_method="wald")
var = c(var, variant)
parameter = c(parameter, par$Parameter[2])
logodds = c(logodds, par$Coefficient[2])
SE = c(SE, par$SE[2])
ci = c(ci, paste(par$CI_low[2], par$CI_high[2], sep = "; "))
p = c(p, par$p[2])
gender = c(gender, "Female")
}
}
df_exp = data.frame(
'variant' = var,
'predictor' = parameter,
'log(OR)' = logodds,
'SE' = SE,
'ConfInt[95]' = ci,
'p-val' = p,
'sex' = gender )
write.csv(df_exp, "single_effect_vte.csv", quote = F, row.names = F)
# Not gender stratified
for (variant in unique(dt_all_info$variant_1) ) {
tmp_case = dt_all_info[which(dt_all_info$variant_1 == variant),]
if (dim(tmp_case)[1]>=10){
tmp_control = dt_all_info[which(is.na(dt_male$variant_1)),]
tmp = rbind(tmp_case, tmp_control)
tmp$variant_1 = as.character(tmp$variant_1)
tmp$variant_1[which(is.na(tmp$variant_1))] = "no_variant"
model = glm(data = tmp, vte ~ variant_1 + bmi + ages, family = "binomial")
par = parameters::parameters(model = model, df_method="wald")
var = c(var, variant)
parameter = c(parameter, par$Parameter[2])
logodds = c(logodds, par$Coefficient[2])
SE = c(SE, par$SE[2])
ci = c(ci, paste(par$CI_low[2], par$CI_high[2], sep = "; "))
p = c(p, par$p[2])
gender = c(gender, "no gender stratified")
}
}
df_exp = data.frame(
'variant' = var,
'predictor' = parameter,
'log(OR)' = logodds,
'SE' = SE,
'ConfInt[95]' = ci,
'p-val' = p,
'sex' = gender )
write.csv(df_exp, "single_effect_vte.csv", quote = F, row.names = F)