Skip to content

Commit f5dccb5

Browse files
authored
Fixing column standardisation for OR, hopefully for good (#158)
1 parent 14c0637 commit f5dccb5

4 files changed

Lines changed: 13 additions & 30 deletions

File tree

pipeline_steps/common_extraction_functions.R

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,14 @@ use_bed_file_to_update_gwas <- function(gwas, bed_file) {
169169
return(gwas)
170170
}
171171

172-
standardise_columns <- function(gwas, N) {
172+
standardise_columns <- function(gwas) {
173173
gwas_columns <- colnames(gwas)
174174

175-
if (!all(c("CHR", "BP") %in% gwas_columns)) {
176-
if (all(grepl("\\d:\\d", gwas$SNP))) {
177-
gwas <- tidyr::separate(data = gwas, col = "SNP", into = c("CHR", "BP"), sep = "[:_]", remove = F)
178-
gwas$BP <- as.numeric(gwas$BP)
179-
}
180-
}
175+
chr_numeric <- suppressWarnings(as.numeric(gsub("^chr", "", as.character(gwas$CHR))))
176+
gwas <- gwas[chr_numeric %in% 1:22, ]
177+
gwas$CHR <- chr_numeric[chr_numeric %in% 1:22]
181178

182-
if (all(c("OR", "OR_LB", "OR_UB") %in% gwas_columns) && !all(c("BETA", "SE") %in% colnames(gwas))) {
179+
if (all(c("OR", "OR_LB", "OR_UB") %in% gwas_columns) && !all(c("BETA", "SE") %in% gwas_columns)) {
183180
gwas <- convert_or_to_beta(gwas)
184181
}
185182

@@ -191,21 +188,15 @@ standardise_columns <- function(gwas, N) {
191188
gwas <- convert_z_score_to_beta(gwas)
192189
}
193190

194-
if ("BP" %in% gwas_columns) gwas$BP <- as.numeric(gwas$BP)
195-
if ("P" %in% gwas_columns) {
196-
gwas$P <- as.numeric(gwas$P)
197-
gwas$P[gwas$P == 0] <- .Machine$double.xmin
198-
}
199-
if ("BETA" %in% gwas_columns) {
200-
gwas$BETA <- as.numeric(gwas$BETA)
201-
}
202-
203-
if ("BETA" %in% gwas_columns) {
204-
gwas$BETA <- as.numeric(gwas$BETA)
205-
}
191+
gwas$BP <- as.numeric(gwas$BP)
192+
gwas$BETA <- as.numeric(gwas$BETA)
193+
gwas$P <- as.numeric(gwas$P)
194+
gwas$P[gwas$P == 0] <- .Machine$double.xmin
206195

207196
return(gwas)
208197
}
198+
199+
209200
standardise_alleles <- function(gwas) {
210201
gwas$EA <- toupper(gwas$EA)
211202
gwas$OA <- toupper(gwas$OA)
@@ -343,7 +334,6 @@ split_into_regions <- function(gwas, ld_blocks, study_metadata, p_value_threshol
343334
#' @import stats
344335
#' @export
345336
convert_or_to_beta <- function(gwas) {
346-
gwas <- get_file_or_dataframe(gwas)
347337
if (!all(c("OR", "OR_LB", "OR_UB") %in% colnames(gwas))) {
348338
stop("Need OR, OR_LB + OR_UB to complete conversion")
349339
}

pipeline_steps/extract_regions_from_summary_stats.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ main <- function() {
4444
gwas <- vroom::vroom(study_metadata$file_location, show_col_types = F)
4545
study_metadata$column_names <- Filter(\(column) !is.null(column) && !is.na(column), study_metadata$column_names)
4646
gwas <- change_column_names(gwas, study_metadata$column_names)
47-
48-
# Filter out rows with non-numeric CHR (e.g. chrX, chr7_KI270803v1_alt) and convert to numeric
49-
chr_numeric <- suppressWarnings(as.numeric(gsub("^chr", "", as.character(gwas$CHR))))
50-
gwas <- gwas[chr_numeric %in% 1:22, ]
51-
gwas$CHR <- chr_numeric[chr_numeric %in% 1:22]
47+
gwas <- standardise_columns(gwas)
5248

5349
start_time <- Sys.time()
5450
if (study_metadata$reference_build != reference_builds$GRCh38) {

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/pipeline-gwas-with-or
1+
SUCCESS: All tests passed on branch: bug/extract-standardise-columns

worker/pipeline_worker.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ 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-
}
188185

189186
flog.info(paste(gwas_info$metadata$guid, "Extracting regions"))
190187
extract_regions <- glue::glue(

0 commit comments

Comments
 (0)