Skip to content

Commit

Permalink
Add flip_frq_as_biallelic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Murphy committed Aug 21, 2023
1 parent da54a40 commit 7df66cf
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: MungeSumstats
Type: Package
Title: Standardise summary statistics from GWAS
Version: 1.9.15
Version: 1.9.16
Authors@R:
c(person(given = "Alan",
family = "Murphy",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## CHANGES IN VERSION 1.9.16

### New features
* flip_frq_as_biallelic parameter added enabling frequencies of non-bi-allelic
SNPs to be flipped as if they were bi-allelic (1 - frequency) i.e. ignoring the
frequencies of other alternative alleles (assuming these will be negligible).
Note this will not be done as default as it is not fully correct but may be
useful for some users.

## CHANGES IN VERSION 1.9.15

### Bug fix
Expand Down
27 changes: 24 additions & 3 deletions R/check_allele_flip.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ check_allele_flip <- function(sumstats_dt, path,
allele_flip_z,
allele_flip_frq,
bi_allelic_filter,
flip_frq_as_biallelic,
imputation_ind,
log_folder_ind,
check_save_out,
Expand Down Expand Up @@ -158,7 +159,7 @@ check_allele_flip <- function(sumstats_dt, path,
sumstats_dt[match_type == FALSE, A1 := tmp]
sumstats_dt[, tmp := NULL]

# flip effect column(s) - BETA, OR, z, log_odds, SIGNED_SUMSTAT, FRQ
# flip effect column(s) - BETA, OR, Z, log_odds, SIGNED_SUMSTAT, FRQ
effect_columns <- c("BETA", "OR", "LOG_ODDS", "SIGNED_SUMSTAT")
if (allele_flip_z) {
effect_columns <- c(effect_columns, "Z")
Expand All @@ -178,13 +179,33 @@ check_allele_flip <- function(sumstats_dt, path,
"bi_allelic_filter to TRUE so\nnon-bi-allelic SNPs are",
" removed. Otherwise, set allele_flip_frq to FALSE to ",
"not flip the FRQ column but note\nthis could lead to ",
"incorrect FRQ values."
"incorrect FRQ values.\nA new option added is to flip ",
"non-bi-allelic SNPs as if they were bi-allelic (1-FRQ), ",
"to do this set\nflip_frq_as_biallelic to TRUE but note ",
"these values will not be exact down to the missing ",
"frequencies of the other\nalternative allele(s)."
)
if (nrow(sumstats_dt[match_type == FALSE, ]) > 0 &&
"FRQ" %in% effect_columns &&
!bi_allelic_filter) {
!bi_allelic_filter && !flip_frq_as_biallelic) {
stop(stp_msg)
}
#if set flip_frq_as_biallelic = TRUE, let them know
if (nrow(sumstats_dt[match_type == FALSE, ]) > 0 &&
"FRQ" %in% effect_columns &&
!bi_allelic_filter && flip_frq_as_biallelic) {
print_msg <- paste0(
"Note: You have set flip_frq_as_biallelic to TRUE meaning of ",
"the ",
formatC(nrow(sumstats_dt[match_type == FALSE, ]),
big.mark = ","),
" SNPs to be flipped, ",
"any non-bi-allelic SNPs\nwill have their frequencies flipped ",
"as (1-FRQ) essentially ignoring the frequencies of any other ",
"alternative alleles."
)
message(print_msg)
}
for (eff_i in effect_columns) { # set updates quicker for DT
# conversion done in case, VCF beta column may not be numeric
if (eff_i == "FRQ") {
Expand Down
7 changes: 7 additions & 0 deletions R/format_sumstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
#' along with effect and z-score columns like Beta? Default TRUE.
#' @param bi_allelic_filter Binary Should non-biallelic SNPs be removed. Default
#' is TRUE.
#' @param flip_frq_as_biallelic Binary Should non-bi-allelic SNPs frequency
#' values be flipped as 1-p despite there being other alternative alleles?
#' Default is FALSE but if set to TRUE, this allows non-bi-allelic SNPs to be
#' kept despite needing flipping.
#' @param snp_ids_are_rs_ids Binary Should the supplied SNP ID's be assumed to
#' be RSIDs. If not, imputation using the SNP ID for other columns like
#' base-pair position or chromosome will not be possible. If set to FALSE, the
Expand Down Expand Up @@ -249,6 +253,7 @@ format_sumstats <- function(path,
allele_flip_z = TRUE,
allele_flip_frq = TRUE,
bi_allelic_filter = TRUE,
flip_frq_as_biallelic = FALSE,
snp_ids_are_rs_ids = TRUE,
remove_multi_rs_snp = FALSE,
frq_is_maf = TRUE,
Expand Down Expand Up @@ -336,6 +341,7 @@ format_sumstats <- function(path,
allele_flip_z = allele_flip_z,
allele_flip_frq = allele_flip_frq,
bi_allelic_filter = bi_allelic_filter,
flip_frq_as_biallelic = flip_frq_as_biallelic,
snp_ids_are_rs_ids = snp_ids_are_rs_ids,
remove_multi_rs_snp = remove_multi_rs_snp,
frq_is_maf = frq_is_maf,
Expand Down Expand Up @@ -702,6 +708,7 @@ format_sumstats <- function(path,
allele_flip_z = allele_flip_z,
allele_flip_frq = allele_flip_frq,
bi_allelic_filter = bi_allelic_filter,
flip_frq_as_biallelic = flip_frq_as_biallelic,
imputation_ind = imputation_ind,
log_folder_ind = log_folder_ind,
check_save_out = check_save_out,
Expand Down
4 changes: 4 additions & 0 deletions R/validate_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ validate_parameters <- function(path,
allele_flip_z,
allele_flip_frq,
bi_allelic_filter,
flip_frq_as_biallelic,
snp_ids_are_rs_ids,
remove_multi_rs_snp,
frq_is_maf,
Expand Down Expand Up @@ -242,6 +243,9 @@ validate_parameters <- function(path,
if (!is.logical(bi_allelic_filter)) {
stop("bi_allelic_filter must be either TRUE or FALSE")
}
if (!is.logical(flip_frq_as_biallelic)) {
stop("flip_frq_as_biallelic must be either TRUE or FALSE")
}
if (!is.logical(snp_ids_are_rs_ids)) {
stop("snp_ids_are_rs_ids must be either TRUE or FALSE")
}
Expand Down
6 changes: 6 additions & 0 deletions man/check_allele_flip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/format_sumstats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/import_sumstats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/validate_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vignettes/MungeSumstats.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ conducted by *MungeSumstats* are:
Z-score columns (e.g. Beta). Default is TRUE.
- **bi_allelic_filter** Binary, should non-biallelic SNPs be removed.
Default is TRUE
- **flip_frq_as_biallelic** Binary, Should non-bi-allelic SNPs frequency
values be flipped as 1-p despite there being other alternative alleles?
Default is FALSE but if set to TRUE, this allows non-bi-allelic SNPs to be
kept despite needing flipping.
- **snp_ids_are_rs_ids** Binary, should the SNP IDs inputted be
inferred as RS IDs or some arbitrary ID. Default is TRUE.\
- **remove_multi_rs_snp** Binary Sometimes summary statistics can have
Expand Down

0 comments on commit 7df66cf

Please sign in to comment.