-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path4_ABO_freq_combine.R
49 lines (39 loc) · 1.3 KB
/
4_ABO_freq_combine.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
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(data.table))
source('ABO_functions.R')
ABO_UKB_freq_file <- 'ABO_UKB_freq.tsv'
ABO_external_freq_file <- 'ABO_external_studies_freq.tsv'
pop_cnt_file <- 'UKB_population_n.tsv'
ABO_combined_freq_file <- 'ABO_combined_freq.tsv'
#####################
ABO_haplotype_freq <-
fread(ABO_UKB_freq_file, sep='\t') %>%
rename('population' = '#population')
Case_freq <- fread(ABO_external_freq_file) %>%
rename('population' = '#population') %>%
rename('nA'='A', 'nB'='B', 'nAB'='AB', 'nO'='O') %>%
mutate(A = nA/n, B = nB/n, AB=nAB/n, O=nO/n)
UKB_pop_cnt <- get_pop_cnt(pop_cnt_file)
UKB_pheno_freqs <- list()
for(pop in names(UKB_pop_cnt)){
UKB_pheno_freqs[[ pop ]] <-
ABO_haplotype_freq %>%
filter(population == pop) %>%
compute_pheno_freq()
}
freqs <- UKB_pheno_freqs %>%
as.data.frame() %>%
as.matrix() %>%
t() %>%
as.data.frame() %>%
rownames_to_column('population') %>%
left_join(
data.frame(n = UKB_pop_cnt) %>%
rownames_to_column('population'),
by='population'
) %>%
mutate(population = paste('UKB', population, sep='_')) %>%
bind_rows(Case_freq %>% select(population, A, B, AB, O, n))
freqs %>%
rename('#population' = 'population') %>%
fwrite(ABO_combined_freq_file, sep='\t', na = "NA", quote=F)