This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggQQplot <- function(pList, colVec = c("black", "orange", "red", "purple"), | |
legendLabel = NULL, title = "", openRange = F, sampling = 1) { | |
if (is.null(legendLabel)) { | |
legendLabel = colVec | |
} | |
if (length(pList) > length(colVec)) { | |
stop("pList needs to be shorter than colVec!!!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getFDR <- function(Stat, Stat0) { | |
m <- length(Stat) | |
n <- length(Stat0) | |
v <- c(rep(T, m), rep(F, n)) | |
v <- v[order(c(Stat, Stat0), decreasing = T)] | |
vSumT <- (m - cumsum(v == T)[v == T] + 1) / m | |
vSumF <- (n - cumsum(v == F)[v == T]) / n | |
fdr <- cummin(pmin(1, vSumF / vSumT)) | |
fdr <- fdr[rank(-Stat)] | |
return(fdr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
disjoinGr <- function(df, chr = "CHR", bp = "BP", pval = "Pval", snp = "SNP", size = 5e5) { | |
inGr <- GRanges(df[[chr]], IRanges(df[[bp]] - size, df[[bp]] + size - 1), | |
SNPID = df[[snp]], BP = df[[bp]], Pval = df[[pval]]) | |
disjointGr <- disjoin(inGr) | |
ov <- findOverlaps(resize(inGr, 1, "center"), disjointGr) | |
hitGr <- disjointGr[subjectHits(ov)] | |
ovGr <- setdiff(disjointGr, hitGr) | |
firstHalf <- resize(ovGr, width(ovGr) / 2 - 1, "start") | |
secondHalf <- resize(ovGr, width(ovGr) / 2, "end") |