-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_mQTLComparisons.qmd
200 lines (135 loc) · 6.23 KB
/
10_mQTLComparisons.qmd
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
---
title: "Supplementry mQTL analysis"
format: html
editor: visual
---
## Load libraries
```{r}
library(tidyverse)
library(IlluminaHumanMethylation450kanno.ilmn12.hg19)
library(ggplot2)
library(cowplot)
library(ggpubr)
library(tidyverse)
```
## Load the mqtl data
```{r}
#tidyverse read_csv can transparently read gz csv files
#https://epigenetics.essex.ac.uk/mQTL/All_Imputed_BonfSignificant_mQTLs.csv.gz
brainMQTLs <- read_csv("All_Imputed_BonfSignificant_mQTLs.csv.gz")
#get the cartilage foetal mqtls
cartilageMQTLs <- read_delim("mqtl/mqtl_analysis.cis_mqtls.genomewide.tsv") %>% as.data.frame()
cartilageMQTLs_OA <- read_delim("mqtl/mqtl_analysis.cis_mqtls.genomewide.OA.tsv") %>% as.data.frame()
```
## Comparison to dDMPs
Is there significant overlap between the developmentally altered CpGs and the mQTLs?
```{r}
dmps <- read_delim("differential_methylation/differential_methylation.limma_results.continuous_covariates.treat_log2FC0.1_thr.tsv") %>%
dplyr::filter(CONTRAST == "Z_STAGE_WEEKS") %>%
as.data.frame()
cartilageMQTLs_sig <- cartilageMQTLs[ cartilageMQTLs$bonferroni <= 0.05,]
dmps_sig <- dmps[ dmps$bonferroni <= 0.05,]
overlapSize <- length(intersect(dmps_sig$Name,cartilageMQTLs_sig$gene))
numbermQTLCpGs <- length(unique(cartilageMQTLs_sig$gene))
numberDMPs <- nrow(dmps_sig)
numberBackgroundCpGs <- nrow(dmps)
#test for under-representation
phyper(q = overlapSize,
m = numbermQTLCpGs,
n = numberBackgroundCpGs - numbermQTLCpGs,
k = numberDMPs,
lower.tail = TRUE)
```
## Comparison to sDMPs
Is there significant overlap between the developmentally altered CpGs and the mQTLs?
```{r}
dmps <- read_delim("differential_methylation/differential_methylation.limma_results.continuous_covariates.ebayes_adjusted.tsv") %>%
dplyr::filter(CONTRAST == "sexmale - sexfemale") %>%
as.data.frame()
cartilageMQTLs_sig <- cartilageMQTLs[ cartilageMQTLs$bonferroni <= 0.05,]
dmps_sig <- dmps[ dmps$bonferroni <= 0.05,]
overlapSize <- length(intersect(dmps_sig$Name,cartilageMQTLs_sig$gene))
numbermQTLCpGs <- length(unique(cartilageMQTLs_sig$gene))
numberDMPs <- nrow(dmps_sig)
numberBackgroundCpGs <- nrow(dmps)
#test for under-representation
phyper(q = overlapSize,
m = numbermQTLCpGs,
n = numberBackgroundCpGs - numbermQTLCpGs,
k = numberDMPs,
lower.tail = TRUE)
```
## Comparison to foetal brain mQTLs
Take all the epigenome wide significant CpGs, filter by those also on the 450K array, and compare Y/N if they were also an mQTL in the brain paper
```{r}
#check all the brain probes are on the 450k array as expected
table(brainMQTLs$ProbeID %in% Manifest$Name)
#filter the cartilage mqtls by those probes on the 450k array
cartilageMQTLs <- cartilageMQTLs[ cartilageMQTLs$gene %in% Manifest$Name,]
#add a column with present or not in the sig brain mQTLs
cartilageMQTLs$brain <- ifelse(cartilageMQTLs$gene %in% brainMQTLs$ProbeID,"yes","no")
#get the sig cartilage mQTLs
cartilageMQTLs_sig <- cartilageMQTLs[ cartilageMQTLs$bonferroni <= 0.05,]
#how many cartilage mqtls are also sig in the brain dataset?
freq <- table(cartilageMQTLs_sig$brain)
freq[2]/sum(freq)
write.table(cartilageMQTLs_sig, "mqtl_analysis.cis_mqtls.450k_probes.genomewide_bonerroni_sig.tsv", sep="\t", quote=FALSE,row.names = FALSE,col.names = TRUE)
library(ggvenn)
venn <- list("Cartilage CpGs"=cartilageMQTLs_sig$gene,"Brain CpGs"=brainMQTLs$ProbeID)
g <- ggvenn(venn,show_percentage = FALSE, text_size = 7)
ggsave("mqtl/cartilage_brain_mQTL_450kfiltered_CpG_venn.png", g, units="in", width=6, height=7,bg="white")
```
### Plot effect sizes
```{r}
splitChrPos <- function(dataset){
string <- strsplit(dataset$CHRPOSID,split=":")
chr <- sapply(string,"[[",1)
pos <- sapply(string,"[[",2)
major <- sapply(string,"[[",3)
minor <- sapply(string,"[[",4)
dataset$chrposcpg <- paste(chr,pos,dataset$gene,sep=":")
dataset$minor <- minor
dataset$major <- major
return(dataset)
}
cartilageMQTLs_sig_brain <- cartilageMQTLs_sig[ cartilageMQTLs_sig$brain=="yes",]
cartilageMQTLs_sig_brain <- splitChrPos(cartilageMQTLs_sig_brain)
brainMQTLs$chrposcpg <- paste(brainMQTLs$SNP_Chr,brainMQTLs$SNP_BP,brainMQTLs$ProbeID,sep=":")
combined <- merge(cartilageMQTLs_sig_brain,brainMQTLs,by="chrposcpg")
combined <- combined[ combined$SNP_Allele == combined$minor | combined$SNP_Allele == combined$major, ]
combined$beta.x <- ifelse(combined$minor != combined$SNP_Allele, combined$beta.x *-1 ,combined$beta.x)
g <- ggplot(combined, aes(beta.x,beta.y)) +
geom_point(alpha=0.1) +
geom_smooth(method = "lm", se=FALSE, color="red", formula = y ~ x) +
cowplot::theme_cowplot(font_size = 20) +
xlab("Foetal Cartilage mQTL effect size (beta)") +
ylab("Foetal Brain mQTLs effect size (beta)") +
stat_cor(size=5)
ggsave("mqtl/mqtlBrainvsCartilageEffectSizes.png", g, units="in", width=7, height=5)
```
### Cartilage comparisons
```{r}
OA <- read.delim("Kreitmaier_2022_mqtl_lgcart_filtered.txt")
#get the cartilage foetal mqtls
cartilageMQTLs <- read_delim("mqtl/mqtl_analysis.cis_mqtls.genomewide.tsv") %>% as.data.frame()
cartilageMQTLs <- cartilageMQTLs[ cartilageMQTLs$bonferroni <= 0.05,]
#alter the id format to match ours
OA$snp_chr_pos_REF_ALT <- gsub("_",":",OA$snp_chr_pos_REF_ALT)
#merge where the mqtls ids are shared
combined <- dplyr::inner_join(cartilageMQTLs, OA,by=c("CHRPOSID"="snp_chr_pos_REF_ALT","gene"="msite") )
#plot the effect sizes in both datasets
g <- ggplot(combined, aes(beta.x,beta.y)) +
geom_point(alpha=0.1) +
geom_smooth(method = "lm", se=FALSE, color="red", formula = y ~ x) +
cowplot::theme_cowplot(font_size = 20) +
xlab("Foetal Cartilage mQTL effect size (beta)") +
ylab("Adult OA Cartilage mQTLs effect size (beta)") +
stat_cor(size=5)
ggsave("mqtl/mqtlAdultvsFoetalCartilageEffectSizes.png", g, units="in", width=7, height=7, bg = "white")
#venn of the overlap
#need to filter by the 450k array
cartilageMQTLs_450k <- cartilageMQTLs[ cartilageMQTLs$gene %in% Manifest$Name,]
venn <- list("Foetal CpGs"=cartilageMQTLs_450k$gene,"Adult OA CpGs"=OA$msite)
g <- ggvenn(venn,show_percentage = FALSE, text_size = 7)
ggsave("mqtl/cartilage_adultOA_mQTL_450kfiltered_CpG_venn.png", g, units="in", width=6, height=7,bg="white")
```