-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_roman_data.Rmd
225 lines (156 loc) · 7.31 KB
/
analysis_roman_data.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
---
title: "analysis_Roman_data"
author: "ls760"
date: "19/04/2021"
output:
html_document:
code_folding: "hide"
anchor_sections: TRUE
highlight: "pygments"
template: "default"
toc: true
df_print: paged
toc_depth: 2
---
```{r, echo=F, message=FALSE, warning=F}
# Set the environment
library(skimr)
library(ggplot2)
library(gghighlight)
library(tidyverse)
library(reshape2)
library(plyr)
library("ggpubr")
library(ggExtra)
```
## Data
```{r read in data, tidy=TRUE, warning=FALSE, message=FALSE}
dfr = data.table::fread("/Volumes/GoogleDrive/My Drive/Phd/VarioPath/protein_structure/Roman's_VarioPath_scores_20210312.tsv", header = T)
## preview dfr
# str(dfr)
# remove V8 that is empty
dfr = dfr[,-8]
## inspect the DF
skim(dfr)
# Transform variables to numeric
# convert class to numeric where possible
dfr = as.data.frame(dfr)
for(i in 1:length(colnames(dfr))){
if ( sum(is.na(as.numeric(as.character(dfr[,i])))) == dim(dfr)[1] ) {
message(colnames(dfr)[i], ' not converted')
} else {
dfr[,i] = as.numeric(as.character(dfr[,i]))
}
}
```
## MDT Variants
Are MDT variants similar to the rest of the cohort?
```{r MDT_All_variants, warning=FALSE, message=FALSE}
ggplot(data = dfr, mapping = aes(Score, fill = MDT_variant))+
geom_histogram(bandwidth = 1, bins = 40, na.rm = TRUE)
ggplot(data = dfr, mapping = aes(Score, fill = MDT_variant))+
geom_density(na.rm = TRUE)
ggplot(data = dfr, mapping = aes(Category, fill = MDT_variant))+
geom_histogram(na.rm = TRUE)
```
## How does romans score correlates with effect size
This analysis is difficult because Romans' score doesn't take into account the phenotype, but is intrinsi to the protein. However, effect size strongly rely on the phenotype taken into account.
I will take the max effect size reported for that variant. assuing that Roman's score predict the worst outcoma as the highest score. However, there is a chance that my varaints haven't been tested against the right phenotype.
Effect size can be positive or negative, so I'll use *effect_size^2^*
I'll look one gene at the time on superimpose the different genes
```{r correlation_roman_effect_size, warning=FALSE, message=FALSE}
# import effect sizes
dir_es = "/Users/luca/Library/Group Containers/G69SCX94XU.duck/Library/Application Support/duck/Volumes/logincpu.hpc.cam.ac.uk – SFTP/UKBb/variopath/burden_test_raremetal/output_pre_MDT/phenotypes"
list_files_scores = list.files(path = dir_es, pattern = "*.dominant.singlevar.score.txt.gz$", full.names = TRUE, recursive = TRUE)
# Read and create reference table with all effect sizes
data_all =
lapply(list_files_scores, data.table::fread, skip = "#CHROM", header = TRUE) %>%
bind_rows(.id = "file")
skim(data_all)
sign_pvalue = 0.05
df_eff = data.table::dcast(data_all,
`#CHROM` + POS + REF + ALT ~ file,
value.var = c('ALT_EFFSIZE', "PVALUE"), function(x){max(x,na.rm = T)},
subset = .(PVALUE < sign_pvalue & is.na(PVALUE) == FALSE))
# return only the max squared effect size per variant
df_eff = as.data.frame(df_eff)
df_eff[sapply(df_eff, is.infinite)] <- NA
df_eff$sqr_eff = sqrt(apply(df_eff[,grep(colnames(df_eff) ,pattern = "ALT_EFFSIZE*")],
1,
function(x){
max(x^2, na.rm = T)
}))
df_eff$id = paste(paste0( 'chr', df_eff$`#CHROM`),
df_eff$POS, df_eff$REF, df_eff$ALT, sep="_")
googledrive::drive_download(file = googledrive::as_id('https://docs.google.com/spreadsheets/d/1OBQmTN5BVhRgdXh-jM3OxExd6WxwJP_MYflJTg3dNUM/edit#gid=1156788760'))
gene_list_moi = readxl::read_xlsx('VarioPath_disease_gene_list_20210514v1.0.xlsx')
file.remove('VarioPath_disease_gene_list_20210514v1.0.xlsx')
gel = unique(gene_list_moi$`MISC_MOIs (GEL)`)
omes = unique(gene_list_moi$`MISC_MOIs (OMIM via ENSG)`)
nbr = unique(gene_list_moi$`MISC_MOIs (NBR)`)
revalue_vector = c("AD","AR")
names(revalue_vector) = c("Autosomal dominant", "Autosomal recessive")
gene_list_moi$`MISC_MOIs (OMIM via ENSG)` = revalue(gene_list_moi$`MISC_MOIs (OMIM via ENSG)`, replace = revalue_vector, warn_missing = T)
gene_list_moi$moi = apply(gene_list_moi[,c(23,25)],
1,
function(x)
stringi::stri_remove_empty(
str_trim(paste(unique(str_trim(str_split(x, "\\,|\\;|\\|",simplify = T))), collapse = " "), "both")
)
)
pli= data.table::fread("~/Desktop/VarioPath/disease_gene_list_20200915_pLI_info.csv")
gene_pli_moi = merge(pli, gene_list_moi, by.x = "gene", by.y = "Approved symbol (HGNC)") %>% select(c("gene", "moi", "pLI"))
df_cor = merge(df_eff, dfr, by.x = 'id', by.y = 'Uploaded_variation', all.x = T) %>%
select(c(Score,sqr_eff, SYMBOL))
df_cor = merge(df_cor, gene_pli_moi, by.x = "SYMBOL", by.y = "gene")
df_cor=xlsx::read.xlsx("data_to_check.xlsx", sheetIndex = 1)
p = ggscatter(df_cor, x = "Score", y = "sqr_eff",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Effect Size", ylab = "SVM protein score")
ggMarginal(p, type = 'densigram')
p = ggscatter(df_cor, x = "Score", y = "sqr_eff", color = "pLI", fill = "pLI",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Effect Size", ylab = "SVM protein score")
ggMarginal(p, type = 'densigram')
p = ggscatter(df_cor, x = "Score", y = "sqr_eff", color = "moi", fill = "moi",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Effect Size", ylab = "SVM protein score")
ggMarginal(p, type = 'densigram')
cor.test(df_cor$Score, df_cor$sqr_eff, method = "pearson",use = 'pairwise.complete.obs')
# Color code mode of inheritance and pLI
```
```{r correlation_roman_effect_size_after_MDT, warning=FALSE, message=FALSE}
# import effect sizes
dir_es = "/Users/luca/Library/Group Containers/G69SCX94XU.duck/Library/Application Support/duck/Volumes/logincpu.hpc.cam.ac.uk – SFTP/home/ls760/UKBb/variopath/burden_test_raremetal/output_after_MDT_clean/phenotypes/"
list_files_scores = list.files(path = dir_es, pattern = "*.dominant.singlevar.score.txt.gz$", full.names = TRUE, recursive = TRUE)
# Read and create reference table with all effect sizes
data_all =
lapply(list_files_scores, data.table::fread, skip = "#CHROM", header = TRUE) %>%
bind_rows(.id = "file")
skim(data_all)
sign_pvalue = 0.05
df_eff = data.table::dcast(data_all,
`#CHROM` + POS + REF + ALT ~ file,
value.var = c('ALT_EFFSIZE', "PVALUE"), function(x){max(x,na.rm = T)},
subset = .(PVALUE < sign_pvalue & is.na(PVALUE) == FALSE))
# return only the max squared effect size per variant
df_eff = as.data.frame(df_eff)
df_eff[sapply(df_eff, is.infinite)] <- NA
df_eff$sqr_eff = sqrt(apply(df_eff[,grep(colnames(df_eff) ,pattern = "ALT_EFFSIZE*")],
1,
function(x){
max(x^2, na.rm = T)
}))
df_eff$id = paste(paste0( 'chr', df_eff$`#CHROM`),
df_eff$POS, df_eff$REF, df_eff$ALT, sep="_")
df_cor = merge(df_eff, dfr, by.x = 'id', by.y = 'Uploaded_variation', all.x = T) %>%
select(c(Score,sqr_eff))
stats::cor(df_cor$Score, df_cor$sqr_eff, method = "pearson",use = 'pairwise.complete.obs')
# Color code mode of inheritance and pLI
p = ggplot(df_cor, aes(Score, sqr_eff)) +
geom_point()
ggMarginal(p, type = 'densigram')
```