-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#' Read -log10 p-value column | ||
#' | ||
#' Parse p-value column in VCF file.of other general -loq10 p-values | ||
#' | ||
#' @param sumstats_dt Summary stats data.table. | ||
#' @param return_list Binary, whether to return the dt in a list or not - list | ||
#' is standard for the `format_sumstats()` function. | ||
#' @inheritParams format_sumstats | ||
#' | ||
#' @returns Null output. | ||
#' @keywords internal | ||
#' @importFrom data.table setnames | ||
read_log_pval <- function(sumstats_dt,mapping_file = sumstatsColHeaders, | ||
return_list=TRUE){ | ||
P <- NULL | ||
# Need to convert P-value, currently -log10 | ||
#cgreate a check based on mapping file | ||
column_headers <- names(sumstats_dt) | ||
column_headers_upper <- toupper(names(sumstats_dt)) | ||
#get all p mappings | ||
mapping_file_p <- mapping_file[mapping_file$Corrected=="P",] | ||
#now create all possible -log10 p-value | ||
log_p_col <- c(paste0("-LOG10_",mapping_file_p$Uncorrected), | ||
paste0("LOG10_",mapping_file_p$Uncorrected), | ||
paste0("-LOG10 ",mapping_file_p$Uncorrected), | ||
paste0("LOG10 ",mapping_file_p$Uncorrected), | ||
paste0("-LOG10-",mapping_file_p$Uncorrected), | ||
paste0("LOG10-",mapping_file_p$Uncorrected), | ||
paste0("-LOG10.",mapping_file_p$Uncorrected), | ||
paste0("LOG10.",mapping_file_p$Uncorrected), | ||
paste0("-LOG10",mapping_file_p$Uncorrected), | ||
paste0("LOG10",mapping_file_p$Uncorrected), | ||
paste0("LOG_",mapping_file_p$Uncorrected), | ||
paste0("-L_",mapping_file_p$Uncorrected), | ||
paste0("L_",mapping_file_p$Uncorrected), | ||
paste0("LOG-",mapping_file_p$Uncorrected), | ||
paste0("-L-",mapping_file_p$Uncorrected), | ||
paste0("L-",mapping_file_p$Uncorrected), | ||
paste0("LOG.",mapping_file_p$Uncorrected), | ||
paste0("-L.",mapping_file_p$Uncorrected), | ||
paste0("L.",mapping_file_p$Uncorrected), | ||
paste0("-L",mapping_file_p$Uncorrected), | ||
paste0("L",mapping_file_p$Uncorrected), | ||
"LP") | ||
lp_found <- FALSE | ||
for(col_i in column_headers_upper){ | ||
if(isTRUE(any(col_i==log_p_col))){ | ||
lp_found<-TRUE | ||
lp_col_up<-col_i | ||
} | ||
} | ||
if (isTRUE(lp_found)) { | ||
messager("sumstats has -log10 P-values; these will be", | ||
"converted to unadjusted p-values in the 'P' column.") | ||
lp_col <- column_headers[[which(column_headers_upper %in% lp_col_up)]] | ||
#check if -log10 or log10 | ||
if(max(sumstats_dt[,get(lp_col)])<=0){ | ||
#log10 - less likely so more lenient check | ||
sumstats_dt[, P := 10^(as.numeric(get(lp_col)))] | ||
}else{ | ||
#-log10 - more likely | ||
sumstats_dt[, P := 10^(-1 * as.numeric(get(lp_col)))] | ||
} | ||
|
||
} | ||
#### Return format #### | ||
if(return_list){ | ||
return(list("sumstats_dt" = sumstats_dt)) | ||
}else { | ||
return(sumstats_dt) | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
test_that("log10 p-value", { | ||
## Call uses reference genome as default with more than 2GB of memory, | ||
## which is more than what 32-bit Windows can handle so remove tests | ||
is_32bit_windows <- | ||
.Platform$OS.type == "windows" && .Platform$r_arch == "i386" | ||
if (!is_32bit_windows) { | ||
# read it in and make N | ||
sumstats_dt <- data.table::fread(system.file("extdata", "eduAttainOkbay.txt", | ||
package = "MungeSumstats"), | ||
nThread = 1) | ||
#test -log10 | ||
sumstats_dt[,LP:=-1*log(Pval,base=10)] | ||
data.table::setnames(sumstats_dt,"Pval","Pval_org") | ||
reformatted <- MungeSumstats::format_sumstats(sumstats_dt, | ||
ref_genome = "GRCh37", | ||
INFO_filter = 0.9, | ||
on_ref_genome = FALSE, | ||
strand_ambig_filter = FALSE, | ||
bi_allelic_filter = FALSE, | ||
allele_flip_check = FALSE, | ||
log_folder_ind = FALSE, | ||
imputation_ind = FALSE, | ||
dbSNP=144, | ||
ignore_multi_trait=TRUE, | ||
return_data = TRUE) | ||
testthat::expect_equal(reformatted$PVAL_ORG,reformatted$P) | ||
#test log10 | ||
sumstats_dt <- data.table::fread(system.file("extdata", "eduAttainOkbay.txt", | ||
package = "MungeSumstats"), | ||
nThread = 1) | ||
sumstats_dt[,LP:=log(Pval,base=10)] | ||
data.table::setnames(sumstats_dt,"Pval","Pval_org") | ||
reformatted <- MungeSumstats::format_sumstats(sumstats_dt, | ||
ref_genome = "GRCh37", | ||
INFO_filter = 0.9, | ||
on_ref_genome = FALSE, | ||
strand_ambig_filter = FALSE, | ||
bi_allelic_filter = FALSE, | ||
allele_flip_check = FALSE, | ||
log_folder_ind = FALSE, | ||
imputation_ind = FALSE, | ||
dbSNP=144, | ||
ignore_multi_trait=TRUE, | ||
return_data = TRUE) | ||
testthat::expect_equal(reformatted$PVAL_ORG,reformatted$P) | ||
} | ||
else{ | ||
testthat::expect_equal(is_32bit_windows, TRUE) | ||
testthat::expect_equal(is_32bit_windows, TRUE) | ||
} | ||
}) |