forked from jmcole003/SDS_humans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_boot_pvals_fec.R
65 lines (51 loc) · 2.13 KB
/
get_boot_pvals_fec.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
# Get Final results from bootstrapping and ML
# SAS fecundity
# updated - 3/28/24
#Remove scientific notation
#options(scipen = 999)
options(warn=1)
#Argument, libraries, and settings
suppressMessages(library("optparse")) #load opt parser library
suppressMessages(library("dplyr"))
suppressMessages(library("data.table"))
option_list = list(
make_option(c("-m", "--mlfile"), type="character", default=NULL,
help="ML results file (.maxl)", metavar="character"),
make_option(c("-b", "--bootfile"), type="character", default=NULL,
help="bootstrap file (.boot)", metavar="character"),
make_option(c("-o", "--output"), type="character", default=NULL,
help="output file name", metavar="character")
);
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
if (is.null(opt$mlfile)){
print_help(opt_parser)
stop("At least one argument must be supplied (input maxl file).n",
call.=FALSE)
}
if (is.null(opt$output)){
print_help(opt_parser)
stop("At least one argument must be supplied (output file name).n",
call.=FALSE)
}
### Import functions
source('/scratch/ukb/scripts/ML_functions.R')
#ML file
ml_output <- fread(opt$mlfile, sep="\t", header = TRUE, check.names=FALSE)
## UPLOAD BOOTS FILE
boot <- fread(opt$bootfile, sep="\t", header = TRUE, check.names=FALSE)
#get p-values from bootstrapping
snpids <- as.vector(unique(ml_output$Site1_SNP))
p_boot_dist <- data.frame()
out1 <- lapply(snpids,get_boot_p.f,bootdist=boot,est=ml_output)
p_boot_dist <- do.call(rbind, out1)
#combine with ML results
f_output <- merge(ml_output, p_boot_dist, by="Site1_SNP")
f_output <- f_output %>% select(Chrom,Window,Site1_Position,Site1_SNP,
Site1_MAF,Site1_Allele0,Site1_Allele1,
Site0_Position,Site0_SNP,Site0_MAF,Site0_Allele0,Site0_Allele1,
s_int_fecundity = s_f_int, SE_f, Z_f, Pval_int_boot_fecundity = P_f,
s_site1_fecundity = s_f_site1, s_site0_fecundity = s_f_site0)
f_output[order(f_output$Window),] -> f_output
#Output
write.table(f_output, paste0(opt$output, ".f.result"), row.names = FALSE, sep="\t")