Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pipeline_steps/common_extraction_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,24 @@ split_into_regions <- function(gwas, ld_blocks, study_metadata, p_value_threshol
return(data.frame())
}
}

#' convert_or_to_beta: Given an OR and lower and upper bounds,
#' calculates the BETA, and SE.
#' based on this answer: https://stats.stackexchange.com/a/327684
#'
#' @param gwas: dataframe with the following columns: OR, LB (lower bound), UB (upper bound)
#' @return gwas with new columns BETA and SE
#' @import stats
#' @export
convert_or_to_beta <- function(gwas) {
gwas <- get_file_or_dataframe(gwas)
if (!all(c("OR", "OR_LB", "OR_UB") %in% colnames(gwas))) {
stop("Need OR, OR_LB + OR_UB to complete conversion")
}

z_score <- stats::qnorm(.975, mean = 0, sd = 1) #1.96
gwas$BETA <- log(gwas$OR)
gwas$SE <- (log(gwas$OR_LB) - gwas$BETA) / -z_score

return(gwas)
}
2 changes: 2 additions & 0 deletions pipeline_steps/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ coverage_types <- list(dense = "dense", sparse = "sparse")

standardised_gwas_columns <- c("CHR", "BP", "EA", "OA", "EAF", "BETA", "SE", "P", "SNP", "Z", "GENE")
required_columns <- c("CHR", "BP", "EA", "OA", "EAF", "BETA", "SE", "P")
beta_columns <- c("BETA", "SE")
or_columns <- c("OR", "OR_LB", "OR_UB")

standardised_column_types <- vroom::cols(
chr = vroom::col_character(),
Expand Down
2 changes: 1 addition & 1 deletion tests/testing_complete.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SUCCESS: All tests passed on branch: bug/bad-import-compile-results
SUCCESS: All tests passed on branch: bug/pipeline-gwas-with-or
5 changes: 3 additions & 2 deletions worker/pipeline_worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ process_message <- function(original_gwas_info, original_payload = NULL) {
vroom::vroom_write(gwas, gwas_info$metadata$file_location)
flog.info(paste(gwas_info$metadata$guid, "Added EAF column (NA) for LD panel fill-in during standardisation"))
}
if (all(or_columns %in% colnames(updated_gwas)) && !all(beta_columns %in% colnames(updated_gwas))) {
updated_gwas <- convert_or_to_beta(updated_gwas)
}

flog.info(paste(gwas_info$metadata$guid, "Extracting regions"))
extract_regions <- glue::glue(
Expand Down Expand Up @@ -294,8 +297,6 @@ verify_gwas_data <- function(gwas_info, gwas) {

gwas <- change_column_names(gwas, gwas_info$metadata$column_names)
mandatory_columns <- c("CHR", "BP", "P", "EA", "OA")
beta_columns <- c("BETA", "SE")
or_columns <- c("OR", "OR_LB", "OR_UB")

has_beta <- all(beta_columns %in% colnames(gwas))
has_or <- all(or_columns %in% colnames(gwas))
Expand Down
Loading