Skip to content

Commit

Permalink
bug fix: imputation ind with missing rs ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Murphy committed Jul 28, 2023
1 parent 45259df commit da54a40
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 43 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.14
Version: 1.9.15
Authors@R:
c(person(given = "Alan",
family = "Murphy",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## CHANGES IN VERSION 1.9.15

### Bug fix
* Fix for imputation column when imputing RS ID from CHR:BP. Avoids crash and
ensures correct identification of imputed SNPs.
* Avoid running compute_nsize function when no imputation is wanted by user -
also avoids message output in this situation.

## CHANGES IN VERSION 1.9.14

### Bug fix
Expand Down
3 changes: 2 additions & 1 deletion R/check_no_rs_snp.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ check_no_rs_snp <- function(sumstats_dt, path, ref_genome, snp_ids_are_rs_ids,
miss_rs_chr_bp[, (format) := NULL]
# join with full dataset
# If IMPUTATION column added add it to other DT
if (imputation_ind &&
if (imputation_ind &&
"IMPUTATION_SNP" %in% names(sumstats_dt) &&
!"IMPUTATION_SNP" %in% names(miss_rs_chr_bp)) {
miss_rs_chr_bp[, IMPUTATION_SNP := NA]
}
Expand Down
84 changes: 43 additions & 41 deletions R/compute_nsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,49 @@ compute_nsize <- function(sumstats_dt,
return_list=TRUE) {
## Avoid confusing BiocCheck.
IMPUTATION_n <- IMPUTATION_Neff <- NULL;
#### Copy data.table ####
## IMPORTANT!: This makes it so that any subsequent changes made to
## the internal sumstats_dt variable (and the function output) will not
## alter the original input data as well.
sumstats_dt <- data.table::copy(sumstats_dt)
#### Standardise the column names before continuing ####
if (standardise_headers) {
sumstats_dt <-
standardise_sumstats_column_headers_crossplatform(
sumstats_dt = sumstats_dt,
)[["sumstats_dt"]]
}
# if you want an Neff column for more than one method need to ensure
# you can tell which is which
append_method_name <- FALSE
if (is.vector(compute_n)) {
# sum makes an N column not an Neff column
if (length(compute_n[!compute_n == "sum"]) > 1) {
append_method_name <- TRUE
}
}
for (method in compute_n) {
compute_sample_size(
sumstats_dt = sumstats_dt,
method = method,
force_new = force_new,
append_method_name = append_method_name
)
}
# if user wants information, give SNPs where Z-score calculated
## Evaluate the conditions under which N would have been calculate by
## compute_sample_size()
if (imputation_ind &&
is.numeric(compute_n) && compute_n != 0L &&
(!"N" %in% names(sumstats_dt))) {
sumstats_dt[, IMPUTATION_n := TRUE]
}
if (imputation_ind &&
is.character(compute_n)) {
sumstats_dt[, IMPUTATION_Neff := TRUE]
}
if (!is.numeric(compute_n) || (is.numeric(compute_n) && compute_n != 0L)){
#### Copy data.table ####
## IMPORTANT!: This makes it so that any subsequent changes made to
## the internal sumstats_dt variable (and the function output) will not
## alter the original input data as well.
sumstats_dt <- data.table::copy(sumstats_dt)
#### Standardise the column names before continuing ####
if (standardise_headers) {
sumstats_dt <-
standardise_sumstats_column_headers_crossplatform(
sumstats_dt = sumstats_dt,
)[["sumstats_dt"]]
}
# if you want an Neff column for more than one method need to ensure
# you can tell which is which
append_method_name <- FALSE
if (is.vector(compute_n)) {
# sum makes an N column not an Neff column
if (length(compute_n[!compute_n == "sum"]) > 1) {
append_method_name <- TRUE
}
}
for (method in compute_n) {
compute_sample_size(
sumstats_dt = sumstats_dt,
method = method,
force_new = force_new,
append_method_name = append_method_name
)
}
# if user wants information, give SNPs where Z-score calculated
## Evaluate the conditions under which N would have been calculate by
## compute_sample_size()
if (imputation_ind &&
is.numeric(compute_n) && compute_n != 0L &&
(!"N" %in% names(sumstats_dt))) {
sumstats_dt[, IMPUTATION_n := TRUE]
}
if (imputation_ind &&
is.character(compute_n)) {
sumstats_dt[, IMPUTATION_Neff := TRUE]
}
}
#### Return format ####
if(return_list){
return(list("sumstats_dt" = sumstats_dt))
Expand Down

0 comments on commit da54a40

Please sign in to comment.