-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20241003_mpra_supplementary_tables.Rmd
513 lines (450 loc) · 31.1 KB
/
20241003_mpra_supplementary_tables.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
---
title: "20240310 mpra supplementary tables"
output: html_document
date: "2024-05-07"
---
Supplementary table list:
1. Tcell MPRA results
- derived from OLJR.C_Tcell_emVAR_glm_20240310.out
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Primary_Data/20240310_analysis/results
- equivalent of mouri supp. table 3
2. Jurkat MPRA results
- derived from OLJR.A_Jurkat_emVAR_glm_20240310.out
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Primary_Data/20240310_analysis/results
- equivalent of mouri supp. table 3
3. PICS enrichment all loci
- derived from 20240310_tcell_glm_hg19_mpra_pics_enrichment_plot_all_loci_table.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- equivalent of mouri supp. table 11
4. PICS enrichment emvars loci
- derived from 20240310_tcell_glm_hg19_mpra_pics_enrichment_plot_dhs_loci_only_table.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- equivalent of mouri supp. table 12
5. UK biobank enrichment all loci
- derived from 20240310_tcell_glm_mpra_uk_biobank_enrichment_plot_all_loci_table.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data
6. UK biobank enrichment emvars loci
- derived from 20240310_tcell_glm_mpra_uk_biobank_enrichment_plot_emvars_loci_only_table.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data
7. tcell motifbreakr mpra combined
- derived from motif.mpra.dat_tcell_hocomoco.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/motif.mpra.data
- equivalent of mouri supp. table 7
8. tcell motifbreakr logskew ttest
- derived from t.test.all.bind.motif.dat_tcell_hocomoco.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/t.test.all.bind.motif.dat
9. jurkat motifbreakr mpra combined
- derived from motif.mpra.dat_unstim_jurkat_hocomoco.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/motif.mpra.data
- equivalent of mouri supp. table 7
10. jurkat motifbreakr logskew ttest
- derived from t.test.all.bind.motif.dat_unstim_jurkat_hocomoco.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/t.test.all.bind.motif.dat
11. ChromHMM enrich
- derived from 20240310_tcell_glm_hg19_chrommhmm_histone_data.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- equivalent of mouri supp. table 4
12. Histone CAGE DHS enr
- derived from 20240310_tcell_glm_hg19_histone_cage_dhs_data.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- equivalent of mouri supp. table 5
13. T cell MPRA functional annotations
- derived from 20240310_tcell_glm_mpra_merge_hg38_hg19.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- large subset needed
- equivalent of mouri supp. table 6
14. PICS by MPRA
- derived from 20240310_tcell_glm_mpra_merge_hg38_hg19.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data
- with extra columns needed from the pics plot (credible sets)
- equivalent of mouri supp. table 10
14. UKBB by MPRA
15. Jurkat MPRA functional annotations
- derived from 20240310_unstim_jurkat_glm_mpra_merge_hg38_hg19.txt
- located at /nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/unstim_jurkat/glm/data
```{r}
library(openxlsx)
library(tidyverse)
library(readxl)
library(stringr)
```
## Table 1
```{r}
supp_table_1 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Primary_Data/20240310_analysis/results/OLJR.C_Tcell_emVAR_glm_20240310.out",header=T, stringsAsFactors = F,sep="\t")
supp_table_1$project <- "TGWAS"
supp_table_1 <- subset(supp_table_1, select=c(SNP,project,window,strand,allele,haplotype,comb,A_Ctrl_Mean,A_Exp_Mean,A_log2FC, A_log2FC_SE, A_logP, A_logPadj_BH, A_logPadj_BF, B_Ctrl_Mean, B_Exp_Mean, B_log2FC, B_log2FC_SE, B_logP, B_logPadj_BH, B_logPadj_BF, Log2Skew,Skew_logFDR))
supp_table_1
# Add rsid
# read in one of the mouri et al. supplementary tables
rsid.dat<-read_excel("/nfs/jray/screens/Mouri_et_al_MPRA/Mouri_et_al_replication/MPRA_merge_creation/41588_2022_1056_MOESM4_ESM.xlsx")
# renaming a column to merge it with the mpra data
rsid.dat$SNP <- rsid.dat$ld_snp
# pick just the SNP and rsid column
rsid.dat<-unique(subset(rsid.dat, select=c(SNP, rsid)))
# merge the rsid data with the mpra
supp_table_1<-merge(supp_table_1, rsid.dat, by="SNP", all.x=T, all.y=F)
# 40 snps do not have a rsid
missing_rsid_snps <- subset(supp_table_1, is.na(rsid)==TRUE)
supp_table_1$SNP19 <- supp_table_1$SNP
supp_table_1 <- subset(supp_table_1, select=-c(SNP))
# Create complete hg38 liftover
hg19_mpra_gwas_variants <- read.xlsx("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/mpra_gwas_variants.xlsx")
hg19_mpra_gwas_variants$chr <- sub("^([0-9]+):.*", "chr\\1", hg19_mpra_gwas_variants$ld_snp)
hg19_mpra_gwas_variants$hg19 <- paste0(hg19_mpra_gwas_variants$chr,":",hg19_mpra_gwas_variants$pos,"-",hg19_mpra_gwas_variants$pos)
hg19_for_liftover <- subset(hg19_mpra_gwas_variants, select=c(hg19))
hg19_for_liftover <- data.frame(hg19_for_liftover[1:20776, ])
write.table(hg19_for_liftover, paste0("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/hg19_for_liftover.txt"), row.names=F, col.names=T, sep="\t", quote=F)
# remove hg19 SNP chr17:34869155-34869155
hg19 <- data.frame(hg19_for_liftover[-14083, ])
hg38 <- read.table("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/hglft_genome.bed", sep="")
complete_liftover <- cbind(hg19,hg38)
names(complete_liftover) <- c("hg19","hg38")
supp_table_1$alleles <- sub("^[^:]*:[^:]*:([^:]*:[^:]*)$", "\\1", supp_table_1$SNP19)
supp_table_1$chr_pos_19 <- sub("^([0-9]+:[0-9]+):.*$", "\\1", supp_table_1$SNP19)
complete_liftover$chr_pos_19 <- sub("^chr([0-9]+:[0-9]+)-.*$", "\\1", complete_liftover$hg19)
complete_liftover$chr_pos_38 <- sub("^chr([0-9]+:[0-9]+)-.*$", "\\1", complete_liftover$hg38)
complete_liftover <- unique(complete_liftover)
supp_table_1 <- merge(complete_liftover,supp_table_1,by="chr_pos_19", all.y=TRUE)
supp_table_1$SNP38 <- paste0(supp_table_1$chr_pos_38,":",supp_table_1$alleles)
supp_table_1 <- subset(supp_table_1, select=-c(chr_pos_19,hg19,hg38,chr_pos_38,alleles))
supp_table_1 <- supp_table_1 %>% relocate(SNP19,SNP38)
# Create absolute value columns
supp_table_1$abs_A_log2FC <- abs(supp_table_1$A_log2FC)
supp_table_1$abs_B_log2FC <- abs(supp_table_1$B_log2FC)
# Reset the mpra_sig column
supp_table_1$mpra_sig<- NA
# For every row in the supp_table_1, if the absolute value of the fold change is above 1 and the BH p-vlaue is above 2 for either allele and the LogSkew FDR is above 1, then the variant is labeled as an emVar (Enhancer_Skew). Else, if the absolute value of the fold change is above 1 and the BH p-vlaue is above 2 for either allele, then it is labeled as a pCRE (Enhancer_nSkew). If it is niether of those it is a no activity variant (nEnhancer_nSkew).
for(i in 1:nrow(supp_table_1)){
supp_table_1[i,]$mpra_sig<-ifelse(((supp_table_1[i,]$abs_A_log2FC>1 &supp_table_1[i,]$A_logPadj_BF>2) | (supp_table_1[i,]$abs_B_log2FC>1 & supp_table_1[i,]$B_logPadj_BF>2)) & supp_table_1[i,]$Skew_logFDR>=1, "Enhancer_Skew", ifelse((supp_table_1[i,]$abs_A_log2FC>1 &supp_table_1[i,]$A_logPadj_BF>2) | (supp_table_1[i,]$abs_B_log2FC>1 & supp_table_1[i,]$B_logPadj_BF>2), "Enhancer_nSkew", "nEnhancer_nSkew"))
}
subset_mpra <- subset(supp_table_1, mpra_sig == "Enhancer_Skew")
nrow(subset_mpra)
subset_mpra2 <- subset(supp_table_1, mpra_sig == "Enhancer_nSkew")
nrow(subset_mpra2)
subset_mpra3 <- subset(supp_table_1, mpra_sig == "nEnhancer_nSkew")
nrow(subset_mpra3)
```
## Table 2
```{r}
supp_table_2 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Primary_Data/20240310_analysis/results/OLJR.A_Jurkat_emVAR_glm_20240310.out",header=T, stringsAsFactors = F,sep="\t")
supp_table_2$project <- "TGWAS"
supp_table_2 <- subset(supp_table_2, select=c(SNP,project,window,strand,allele,haplotype,comb,A_Ctrl_Mean,A_Exp_Mean,A_log2FC, A_log2FC_SE, A_logP, A_logPadj_BH, A_logPadj_BF, B_Ctrl_Mean, B_Exp_Mean, B_log2FC, B_log2FC_SE, B_logP, B_logPadj_BH, B_logPadj_BF, Log2Skew,Skew_logFDR))
# Add rsid
# read in one of the mouri et al. supplementary tables
rsid.dat<-read_excel("/nfs/jray/screens/Mouri_et_al_MPRA/Mouri_et_al_replication/MPRA_merge_creation/41588_2022_1056_MOESM4_ESM.xlsx")
# renaming a column to merge it with the mpra data
rsid.dat$SNP <- rsid.dat$ld_snp
# pick just the SNP and rsid column
rsid.dat<-unique(subset(rsid.dat, select=c(SNP, rsid)))
# merge the rsid data with the mpra
supp_table_2<-merge(supp_table_2, rsid.dat, by="SNP", all.x=T, all.y=F)
# 40 snps do not have a rsid
missing_rsid_snps <- subset(supp_table_2, is.na(rsid)==TRUE)
supp_table_2$SNP19 <- supp_table_2$SNP
supp_table_2 <- subset(supp_table_2, select=-c(SNP))
# Create complete hg38 liftover
hg19_mpra_gwas_variants <- read.xlsx("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/mpra_gwas_variants.xlsx")
hg19_mpra_gwas_variants$chr <- sub("^([0-9]+):.*", "chr\\1", hg19_mpra_gwas_variants$ld_snp)
hg19_mpra_gwas_variants$hg19 <- paste0(hg19_mpra_gwas_variants$chr,":",hg19_mpra_gwas_variants$pos,"-",hg19_mpra_gwas_variants$pos)
hg19_for_liftover <- subset(hg19_mpra_gwas_variants, select=c(hg19))
hg19_for_liftover <- data.frame(hg19_for_liftover[1:20776, ])
write.table(hg19_for_liftover, paste0("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/hg19_for_liftover.txt"), row.names=F, col.names=T, sep="\t", quote=F)
# remove hg19 SNP chr17:34869155-34869155
hg19 <- data.frame(hg19_for_liftover[-14083, ])
hg38 <- read.table("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/hglft_genome.bed", sep="")
complete_liftover <- cbind(hg19,hg38)
names(complete_liftover) <- c("hg19","hg38")
supp_table_2$alleles <- sub("^[^:]*:[^:]*:([^:]*:[^:]*)$", "\\1", supp_table_2$SNP19)
supp_table_2$chr_pos_19 <- sub("^([0-9]+:[0-9]+):.*$", "\\1", supp_table_2$SNP19)
complete_liftover$chr_pos_19 <- sub("^chr([0-9]+:[0-9]+)-.*$", "\\1", complete_liftover$hg19)
complete_liftover$chr_pos_38 <- sub("^chr([0-9]+:[0-9]+)-.*$", "\\1", complete_liftover$hg38)
complete_liftover <- unique(complete_liftover)
supp_table_2 <- merge(complete_liftover,supp_table_2,by="chr_pos_19", all.y=TRUE)
supp_table_2$SNP38 <- paste0(supp_table_2$chr_pos_38,":",supp_table_2$alleles)
supp_table_2 <- subset(supp_table_2, select=-c(chr_pos_19,hg19,hg38,chr_pos_38,alleles))
supp_table_2 <- supp_table_2 %>% relocate(SNP19,SNP38)
supp_table_2
# Create absolute value columns
supp_table_2$abs_A_log2FC <- abs(supp_table_2$A_log2FC)
supp_table_2$abs_B_log2FC <- abs(supp_table_2$B_log2FC)
# Reset the mpra_sig column
supp_table_2$mpra_sig<- NA
# For every row in the supp_table_2, if the absolute value of the fold change is above 1 and the BH p-vlaue is above 2 for either allele and the LogSkew FDR is above 1, then the variant is labeled as an emVar (Enhancer_Skew). Else, if the absolute value of the fold change is above 1 and the BH p-vlaue is above 2 for either allele, then it is labeled as a pCRE (Enhancer_nSkew). If it is niether of those it is a no activity variant (nEnhancer_nSkew).
for(i in 1:nrow(supp_table_2)){
supp_table_2[i,]$mpra_sig<-ifelse(((supp_table_2[i,]$A_logPadj_BF>2) | (supp_table_2[i,]$B_logPadj_BF>2)) & supp_table_2[i,]$Skew_logFDR>=1, "Enhancer_Skew", ifelse((supp_table_2[i,]$A_logPadj_BF>2) | (supp_table_2[i,]$B_logPadj_BF>2), "Enhancer_nSkew", "nEnhancer_nSkew"))
}
```
## Table 3
```{r}
supp_table_3 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_hg19_mpra_pics_enrichment_plot_all_loci_table.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_3 <- subset(supp_table_3, select=c(pics,mpra,a,b,c,d,fold,p,odds,lower.conf,upper.conf))
names(supp_table_3) <- c("PICS threshold","mpra","MPRA+, PICS+","MPRA+, PICS-","MPRA-, PICS+","MPRA-, PICS-","Enrichment","P-value","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_3
```
## Table 4
```{r}
supp_table_4 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_hg19_mpra_pics_enrichment_plot_dhs_loci_only_table.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_4 <- subset(supp_table_4, select=c(pics,mpra,a,b,c,d,fold,p,odds,lower.conf,upper.conf))
names(supp_table_4) <- c("PICS threshold","mpra","MPRA+, PICS+","MPRA+, PICS-","MPRA-, PICS+","MPRA-, PICS-","Enrichment","P-value","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_4
```
## Table 5
```{r}
supp_table_5 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data/20240310_tcell_glm_mpra_merge_hg19_mpra_uk_biobank_enrichment_plot_all_loci_table.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_5 <- subset(supp_table_5, select=c(pip,mpra,a,b,c,d,fold,p,odds,lower.conf,upper.conf))
names(supp_table_5) <- c("UKBB PIP threshold","mpra","MPRA+, UKBB+","MPRA+, UKBB-","MPRA-, UKBB+","MPRA-, UKBB-","Enrichment","P-value","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_5
```
## Table 6
```{r}
supp_table_6 <-read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data/20240310_tcell_glm_mpra_merge_hg19_mpra_uk_biobank_enrichment_plot_emvars_loci_only_table.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_6 <- subset(supp_table_6, select=c(pip,mpra,a,b,c,d,fold,p,odds,lower.conf,upper.conf))
names(supp_table_6) <- c("UKBB PIP threshold","mpra","MPRA+, UKBB+","MPRA+, UKBB-","MPRA-, UKBB+","MPRA-, UKBB-","Enrichment","P-value","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_6
```
## Table 7
```{r}
supp_table_7 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/motif.mpra.data/motif.mpra.dat_tcell_hocomoco.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_7$SNP38 <- supp_table_7$SNP
supp_table_7 <- subset(supp_table_7, select=c("SNP38","REF","ALT","rsid","mpra_sig","A.log2FC","B.log2FC","LogSkew","geneSymbol","scoreRef","scoreAlt","alleleDiff", "unique_snp_tf"))
supp_table_7
hg19_38 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_mpra_merge_hg38_hg19.txt",header=T, stringsAsFactors = F,sep="\t")
hg19_38 <- subset(hg19_38, select=c(SNP19,SNP38))
supp_table_7 <- merge(hg19_38,supp_table_7,by="SNP38")
```
## Table 8
```{r}
supp_table_8 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/t.test.all.bind.motif.dat/t.test.all.bind.motif.dat_tcell_hocomoco.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_8
```
## Table 9
```{r}
supp_table_9 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/motif.mpra.data/motif.mpra.dat_unstim_jurkat_hocomoco.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_9
supp_table_9$SNP38 <- supp_table_9$SNP
supp_table_9 <- subset(supp_table_9, select=c("SNP38","REF","ALT","rsid","mpra_sig","A.log2FC","B.log2FC","LogSkew","geneSymbol","scoreRef","scoreAlt","alleleDiff", "unique_snp_tf"))
supp_table_9
hg19_38 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/unstim_jurkat/glm/data/20240310_unstim_jurkat_glm_mpra_merge_hg38_hg19.txt",header=T, stringsAsFactors = F,sep="\t")
hg19_38 <- subset(hg19_38, select=c(SNP19,SNP38))
supp_table_9 <- merge(hg19_38,supp_table_9,by="SNP38")
```
## table 10
```{r}
supp_table_10 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/t.test.all.bind.motif.dat/t.test.all.bind.motif.dat_unstim_jurkat_hocomoco.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_10
```
## Table 11
```{r}
supp_table_11 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_hg19_chrommhmm_histone_data.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_11 <- subset(supp_table_11, select=c("chromhmm","mode","fold","p","a","b","c","d","odds","lower.conf","upper.conf"))
names(supp_table_11) <- c("chromHMM Annotation", "MPRA Effect", "Fold Enrichment","P-value","True Positive","False Positive","False Negative","True Negative","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_11
```
## Table 12
```{r}
supp_table_12 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_hg19_histone_cage_dhs_data.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_12 <- subset(supp_table_12, select=c("mark","mode","fold","p","a","b","c","d","odds","lower.conf","upper.conf"))
names(supp_table_12) <- c("Annotation", "MPRA Effect", "Fold Enrichment","P-value","True Positive","False Positive","False Negative","True Negative","Odds Ratio","Lower Confidence Interval","Upper Confidence Interval")
supp_table_12
```
## Table 13
```{r}
supp_table_13 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_mpra_merge_hg38_hg19.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_13 <- subset(supp_table_13, select=c(SNP19,SNP38, rsid, mpra_sig,dhs_hTH1, dhs_hTH17, dhs_hTH2, dhs_CD4, dhs_CD4pos_N, dhs_hTR, dhs_Jurkat, dhs_CD8, dhs_Tcell_merged, dhs_all,delta_svm_nCD4, asc, atac_qtl_beta,atac_qtl_pval, eqtl_beta, eqtl_pval,eqtl_gene, tf_motifbreakr, tss,ananastra_tf,motifbreakr_tf_2024))
supp_table_13
# Add UKBB column
mpra_biobank_merge_all_traits <- read.table(paste0("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data/","mpra_biobank_merge_all_traits",".txt"),header=T, stringsAsFactors = F,sep="\t")
mpra_biobank_merge_all_traits
mpra_biobank_subset <- subset(mpra_biobank_merge_all_traits, select=c(SNP19,trait,pip))
names(mpra_biobank_subset) <- c("SNP19","ukbb_top_trait","ukbb_top_pip")
supp_table_13 <- merge(supp_table_13,mpra_biobank_subset,by="SNP19")
supp_table_13
```
# Table 14
```{r}
supp_table_14 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_mpra_merge_hg38_hg19.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_14 <- subset(supp_table_14, select=c(chr19,ld_snp19,snp_end19,lead_snp19,SNP19,r2,ld_snp38,lead_snp38,SNP38,rsid, mpra_sig,Crohns_pval, Crohns_pics,Crohns_PP_running, MS_pval, MS_pics, MS_PP_running, Psoriasis_pval, Psoriasis_pics,Psoriasis_PP_running ,RA_pval, RA_pics,RA_PP_running, T1D_pval, T1D_pics,T1D_PP_running, UC_pval, UC_pics,UC_PP_running, IBD_pval, IBD_pics,IBD_PP_running, dhs_Tcell_merged, dhs_all))
supp_table_14
# ADD: top_pval top_disease top_pics 80% credible set 90% credible set 95% credible set
mpra.pics.plot <- supp_table_14
# order of gwas diseases
gwas.order<- c("Crohns","MS","Psoriasis", "RA","T1D","UC", "IBD")
# Format the mpra.pics.plot data
# replace _CS_ with _PP_
names(mpra.pics.plot)<-gsub("_CS_", "_PP_", names(mpra.pics.plot))
# Select only certain columns
mpra.pics.plot<-subset(mpra.pics.plot, select=c(chr19, snp_end19, ld_snp19, lead_snp19, r2, rsid,Crohns_pval,Crohns_pics,Crohns_PP_running,MS_pval,MS_pics,MS_PP_running,
Psoriasis_pval,Psoriasis_pics,Psoriasis_PP_running,RA_pval,RA_pics,RA_PP_running,
T1D_pval,T1D_pics,T1D_PP_running,UC_pval,UC_pics,UC_PP_running,IBD_pval,IBD_pics,
IBD_PP_running, dhs_Tcell_merged, dhs_all, mpra_sig))
mpra.pics.plot$dhs_merged <- mpra.pics.plot$dhs_Tcell_merged
# Remove bad SNPs where it doesn't reach 5E-8 association p-value in the GWAS and remove MHC region. These are hg19 SNPs # Added the loci with 3000+ variants
bad_snps<-c("22:50966914:T:C","3:105558837:G:A", "12:9905851:A:C",
"13:40745693:G:A","16:1073552:A:G","17:38775150:C:T",
"17:44073889:A:G","18:12830538:G:A","2:100764087:T:G",
"21:36488822:T:C","21:45621817:A:G","6:127457260:A:G",
"6:130348257:C:T","7:116895163:G:A","7:51028987:T:A",
"2:204592021:G:A", "14:75961511:C:T")
mpra.pics.plot<-subset(mpra.pics.plot, !(chr19=="chr6" & snp_end19>29691116 & snp_end19<33054976) & !(lead_snp19%in%bad_snps))
# For each mpra variant, find the disease with the strongest association and its associated PICS data
mpra.pics.plot$top_pval<-NA #Top GWAS p-value for the MPRA variant
mpra.pics.plot$top_disease<-NA #Disease corresponding to top GWAS p-value
mpra.pics.plot$top_PP_running<-NA #Cummulative sum of posterior probabilities for that variant
mpra.pics.plot$top_pics<-NA #PICS probability for that variant in the top GWAS
for(i in 1:nrow(mpra.pics.plot)){ #Run through each MPRA variant
top_pval<-max(mpra.pics.plot[i,grepl("_pval",names(mpra.pics.plot))], na.rm=T) #Find the top GWAS p-value
top_disease<-str_split_fixed(names(mpra.pics.plot)[which(mpra.pics.plot[i,]==top_pval)][1], "\\_", 2)[1] #Find the disease corresponding to the top GWAS p-value
#Write out GWAS and PICS data for top GWAS p-value
mpra.pics.plot[i,]$top_pval<-top_pval
mpra.pics.plot[i,]$top_disease<-top_disease
mpra.pics.plot[i,]$top_PP_running<-mpra.pics.plot[i,paste0(top_disease, "_PP_running")]
mpra.pics.plot[i,]$top_pics<-mpra.pics.plot[i,paste0(top_disease, "_pics")]
}
mpra.pics.plot$top_pics<-as.numeric(mpra.pics.plot$top_pics)
mpra.pics.plot$top_PP_running<-as.numeric(mpra.pics.plot$top_PP_running)
### Sensitivity and specificity calculations ###
dat.pics<-mpra.pics.plot
dhs_loci<-F #TRUE if calculation only for loci where a GWAS SNP overlaps a DHS peak
if(dhs_loci==T){
dat.pics<-subset(dat.pics, lead_snp%in%subset(dat.pics, dhs_Tcell_merged>0)$lead_snp19)
}
#Calculate credible sets
dat.pics<-dat.pics[order(dat.pics$lead_snp, -dat.pics$top_pics),]
dat.pics<-subset(dat.pics, select=c(ld_snp19, lead_snp19, r2, top_PP_running, top_pics,top_pval,dhs_all, dhs_Tcell_merged, mpra_sig))
dat.pics$CS_80<-0
dat.pics$CS_90<-0
dat.pics$CS_95<-0
for(i in 1:nrow(dat.pics)){
top_pics<-max(subset(dat.pics, lead_snp19==dat.pics[i,]$lead_snp19)$top_pics)
if(dat.pics[i,]$top_pics==top_pics){
dat.pics[i,]$CS_80<-1
dat.pics[i,]$CS_90<-1
dat.pics[i,]$CS_95<-1
}else{
if(dat.pics[i,]$top_pics>=0.01){
if(dat.pics[i,]$top_PP_running<=0.8){
dat.pics[i,]$CS_80<-1
}
if(dat.pics[i,]$top_PP_running<=0.9){
dat.pics[i,]$CS_90<-1
}
if(dat.pics[i,]$top_PP_running<=0.95){
dat.pics[i,]$CS_95<-1
}
}
}
}
pics_cs_table <- dat.pics
supp_table_14 <- subset(supp_table_14, select=c(ld_snp19,lead_snp19,r2,ld_snp38,lead_snp38,SNP38,rsid, mpra_sig,Crohns_pval, Crohns_pics, MS_pval, MS_pics, Psoriasis_pval, Psoriasis_pics, RA_pval, RA_pics, T1D_pval, T1D_pics, UC_pval, UC_pics, IBD_pval, IBD_pics))
pics_cs_table <- subset(pics_cs_table, select=c(ld_snp19,top_pics,top_pval,CS_80,CS_90,CS_95))
supp_table_14 <- merge(supp_table_14,pics_cs_table,by="ld_snp19", all.x=TRUE)
```
```{r}
supp_table_15 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data/uk_biobank_mpra_supplementary_table.txt",header=T, stringsAsFactors = F,sep="\t")
```
## Table 16
```{r}
supp_table_16 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/unstim_jurkat/glm/data/20240310_unstim_jurkat_glm_mpra_merge_hg38_hg19.txt",header=T, stringsAsFactors = F,sep="\t")
supp_table_16 <- subset(supp_table_16, select=c(SNP19,SNP38, rsid, mpra_sig,dhs_hTH1, dhs_hTH17, dhs_hTH2, dhs_CD4, dhs_CD4pos_N, dhs_hTR, dhs_Jurkat, dhs_CD8, dhs_Tcell_merged, dhs_all,delta_svm_nCD4, asc, atac_qtl_beta,atac_qtl_pval, eqtl_beta, eqtl_pval,eqtl_gene, tf_motifbreakr, tss,ananastra_tf,motifbreakr_tf_2024))
supp_table_16
# Add UKBB column
mpra_biobank_merge_all_traits <- read.table(paste0("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/UK_biobank_finemapping_enrichment/data/","mpra_biobank_merge_all_traits",".txt"),header=T, stringsAsFactors = F,sep="\t")
mpra_biobank_merge_all_traits
mpra_biobank_subset <- subset(mpra_biobank_merge_all_traits, select=c(SNP19,trait,pip))
names(mpra_biobank_subset) <- c("SNP19","ukbb_top_trait","ukbb_top_pip")
supp_table_16 <- merge(supp_table_16,mpra_biobank_subset,by="SNP19")
supp_table_16
```
```{r}
supp_table_17 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/tcell/glm/data/20240310_tcell_glm_hg38_encode_dhs_enrichment_table.txt",header=T, stringsAsFactors = F,sep="\t")
```
```{r}
supp_table_18 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/precision_and_recall_analysis/data/tcell.precision.skew.dat.txt",header=T, stringsAsFactors = F,sep="\t")
```
```{r}
supp_table_19 <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/precision_and_recall_analysis/data/unstim.jurkat.precision.skew.dat.txt",header=T, stringsAsFactors = F,sep="\t")
```
```{r}
supp_table_20_Crohns <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_Crohns",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_Crohns$disease <- "Crohns"
supp_table_20_UC <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_UC",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_UC$disease <- "UC"
supp_table_20_IBD <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_IBD",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_IBD$disease <- "IBD"
supp_table_20_T1D <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_T1D",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_T1D$disease <- "T1D"
supp_table_20_Psoriasis <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_Psoriasis",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_Psoriasis$disease <- "Psoriasis"
supp_table_20_RA <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_RA",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_RA$disease <- "RA"
supp_table_20_MS <- read.delim("/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/TF_analysis/motifbreakr/data/disease_comparison/t.test.all.bind.motif.dat_tcell_hocomoco_MS",header=T, stringsAsFactors = F,sep="\t")
supp_table_20_MS$disease <- "MS"
supp_table_20 <- rbind(supp_table_20_Crohns,supp_table_20_UC,supp_table_20_IBD,supp_table_20_T1D,supp_table_20_RA,supp_table_20_UC,supp_table_20_Psoriasis,supp_table_20_RA,supp_table_20_MS)
names(supp_table_20)
supp_table_20 <- subset(supp_table_20, select=c("disease","tf","p","d","n","t","df","mu1","sd1","mu0","sd0","adj.p","max.p"))
```
Create the excel workbook for all of the tables
```{r}
wb <- createWorkbook()
# Table 1
addWorksheet(wb, sheetName = "1. Tcell MPRA results")
writeData(wb, sheet = "1. Tcell MPRA results", supp_table_1,keepNA =TRUE)
# Table 2
addWorksheet(wb, sheetName = "2. jurkat MPRA results")
writeData(wb, sheet = "2. jurkat MPRA results", supp_table_2,keepNA =TRUE)
# Table 3
addWorksheet(wb, sheetName = "3. PICS enr all loci")
writeData(wb, sheet = "3. PICS enr all loci", supp_table_3,keepNA =TRUE)
# Table 4
addWorksheet(wb, sheetName = "4. PICS enr emVar loci")
writeData(wb, sheet = "4. PICS enr emVar loci", supp_table_4,keepNA =TRUE)
# Table 5
addWorksheet(wb, sheetName = "5. UKBB enr all loci")
writeData(wb, sheet = "5. UKBB enr all loci", supp_table_5,keepNA =TRUE)
# Table 6
addWorksheet(wb, sheetName = "6. UKBB enr emVar loci")
writeData(wb, sheet = "6. UKBB enr emVar loci", supp_table_6,keepNA =TRUE)
# Table 7
addWorksheet(wb, sheetName = "7. Tcell motifbreakR results")
writeData(wb, sheet = "7. Tcell motifbreakR results", supp_table_7,keepNA =TRUE)
# Table 8
addWorksheet(wb, sheetName = "8. Tcell motifbreakR ttest")
writeData(wb, sheet = "8. Tcell motifbreakR ttest", supp_table_8,keepNA =TRUE)
# Table 9
addWorksheet(wb, sheetName = "9. Jurkat motifbreakR results")
writeData(wb, sheet = "9. Jurkat motifbreakR results", supp_table_9,keepNA =TRUE)
# Table 10
addWorksheet(wb, sheetName = "10. Jurkat motifbreakR ttest")
writeData(wb, sheet = "10. Jurkat motifbreakR ttest", supp_table_10,keepNA =TRUE)
# Table 11
addWorksheet(wb, sheetName = "11. chromHMM enrich")
writeData(wb, sheet = "11. chromHMM enrich", supp_table_11,keepNA =TRUE)
# Table 12
addWorksheet(wb, sheetName = "12. Histone CAGE DHS Enrichment")
writeData(wb, sheet = "12. Histone CAGE DHS Enrichment", supp_table_12,keepNA =TRUE)
# Table 13
addWorksheet(wb, sheetName = "13. T-cell MPRA Func. Annot.")
writeData(wb, sheet = "13. T-cell MPRA Func. Annot.", supp_table_13,keepNA =TRUE)
# Table 14
addWorksheet(wb, sheetName = "14. PICS by MPRA")
writeData(wb, sheet = "14. PICS by MPRA", supp_table_14,keepNA =TRUE)
# Table 15
addWorksheet(wb, sheetName = "15. UKBB by MPRA")
writeData(wb, sheet = "15. UKBB by MPRA", supp_table_15,keepNA =TRUE)
# Table 16
addWorksheet(wb, sheetName = "16. Jurkat MPRA Func. Annot.")
writeData(wb, sheet = "16. Jurkat MPRA Func. Annot.", supp_table_16,keepNA =TRUE)
# Table 17
addWorksheet(wb, sheetName = "17. Encode DHS Enrichment")
writeData(wb, sheet = "17. Encode DHS Enrichment", supp_table_17,keepNA =TRUE)
# Table 18
addWorksheet(wb, sheetName = "18. T-cell DHS Grid Search")
writeData(wb, sheet = "18. T-cell DHS Grid Search", supp_table_18,keepNA =TRUE)
# Table 19
addWorksheet(wb, sheetName = "19. Jurkat DHS Grid Search")
writeData(wb, sheet = "19. Jurkat DHS Grid Search", supp_table_19,keepNA =TRUE)
# Table 20
addWorksheet(wb, sheetName = "20. Tcell TF ttest by disease")
writeData(wb, sheet = "20. Tcell TF ttest by disease", supp_table_20,keepNA =TRUE)
saveWorkbook(wb, "/nfs/jray/screens/ALL_MPRAs/Ho_et_al_analysis/Downstream_Analysis/20240310_mpra_analysis/data/ho_et_al_big_table9.xlsx")
```