Skip to content

Commit cbae530

Browse files
committed
Fixing uploads with OR instead of BETA
1 parent 80560f4 commit cbae530

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

pipeline_steps/common_extraction_functions.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,24 @@ split_into_regions <- function(gwas, ld_blocks, study_metadata, p_value_threshol
333333
return(data.frame())
334334
}
335335
}
336+
337+
#' convert_or_to_beta: Given an OR and lower and upper bounds,
338+
#' calculates the BETA, and SE.
339+
#' based on this answer: https://stats.stackexchange.com/a/327684
340+
#'
341+
#' @param gwas: dataframe with the following columns: OR, LB (lower bound), UB (upper bound)
342+
#' @return gwas with new columns BETA and SE
343+
#' @import stats
344+
#' @export
345+
convert_or_to_beta <- function(gwas) {
346+
gwas <- get_file_or_dataframe(gwas)
347+
if (!all(c("OR", "OR_LB", "OR_UB") %in% colnames(gwas))) {
348+
stop("Need OR, OR_LB + OR_UB to complete conversion")
349+
}
350+
351+
z_score <- stats::qnorm(.975, mean = 0, sd = 1) #1.96
352+
gwas$BETA <- log(gwas$OR)
353+
gwas$SE <- (log(gwas$OR_LB) - gwas$BETA) / -z_score
354+
355+
return(gwas)
356+
}

pipeline_steps/constants.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ coverage_types <- list(dense = "dense", sparse = "sparse")
114114

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

118120
standardised_column_types <- vroom::cols(
119121
chr = vroom::col_character(),

tests/testing_complete.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SUCCESS: All tests passed on branch: bug/bad-import-compile-results
1+
SUCCESS: All tests passed on branch: bug/pipeline-gwas-with-or

worker/pipeline_worker.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ process_message <- function(original_gwas_info, original_payload = NULL) {
182182
vroom::vroom_write(gwas, gwas_info$metadata$file_location)
183183
flog.info(paste(gwas_info$metadata$guid, "Added EAF column (NA) for LD panel fill-in during standardisation"))
184184
}
185+
if (all(or_columns %in% colnames(updated_gwas)) && !all(beta_columns %in% colnames(updated_gwas))) {
186+
updated_gwas <- convert_or_to_beta(updated_gwas)
187+
}
185188

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

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

300301
has_beta <- all(beta_columns %in% colnames(gwas))
301302
has_or <- all(or_columns %in% colnames(gwas))

0 commit comments

Comments
 (0)