Skip to content

Commit

Permalink
update check ldsc n comp
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Murphy committed Dec 8, 2023
1 parent d8ad01a commit c55aaa7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 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.11.1
Version: 1.11.2
Authors@R:
c(person(given = "Alan",
family = "Murphy",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## CHANGES IN VERSION 1.11.2

### Bug fix
* Remove unused argument `make_ordered` from `sort_coords()`
* Issue fixed with check ldsc format wehn compute_n type chosen

## CHANGES IN VERSION 1.11.1

### Bug fix
Expand Down
32 changes: 21 additions & 11 deletions R/check_ldsc_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,30 @@ check_ldsc_format <- function(sumstats_dt, save_format, convert_n_int,
message()
allele_flip_check <- TRUE
}
if (!compute_z && !z_present) {
message("Setting `compute_z=TRUE` to comply with LDSC format.")
compute_z <- TRUE
}
n_msg <- paste0(
"LDSC requires an N column but your dataset doesn't ",
"appear to have one. You can impute an N value for ",
"all your SNPs\nby setting `compute_n` to this value but",
" note this is may not be correct and may lead to ",
"different results from LDSC\nthan if the true N per SNP",
" was known."
"LDSC requires an N column but your dataset doesn't ",
"appear to have one. You can impute an N value for ",
"all your SNPs\nby setting `compute_n` to this value but",
" note this is may not be correct and may lead to ",
"different results from LDSC\nthan if the true N per SNP",
" was known."
)
if (!z_present && isFALSE(compute_z)) {
beta_se_present <- ("BETA" %in% names(sumstats_dt) &&
"SE" %in% names(sumstats_dt))
p_present <- "P" %in% names(sumstats_dt)
if(beta_se_present){
message("Setting `compute_z=BETA` to comply with LDSC format.")
compute_z <- "BETA"
}else if(p_present){
message("Setting `compute_z=P` to comply with LDSC format.")
compute_z <- "P"
} else{
stop(n_msg)
}
}
if (compute_n == 0L && !n_present) {
stop(n_msg)
stop(n_msg)
}
}
return(list(
Expand Down
44 changes: 21 additions & 23 deletions R/sort_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#' @param sumstats_dt \link[data.table]{data.table} obj of the
#' summary statistics file for the GWAS.
#' @param sort_coords Whether to sort by coordinates.
#' @param make_ordered Make CHR into an ordered factor to ensure
#' they go from 1-22, X, Y.
#' @param sort_method Method to sort coordinates by:
#' \itemize{
#' \item{"data.table" (default)}{Uses \link[data.table]{setorderv},
Expand All @@ -22,26 +20,26 @@
sort_coords <- function(sumstats_dt,
sort_coordinates = TRUE,
sort_method=c("data.table","GenomicRanges")) {
### Add this to avoid confusing BiocCheck
CHR <- NULL

if (isTRUE(sort_coordinates)) {
#### Report ####
sort_method <- sort_method[1]
messager("Sorting coordinates with",paste0(shQuote(sort_method),"."))
### Double check that X and Y are uppercase
sumstats_dt[, CHR := gsub("x|23", "X", CHR)]
sumstats_dt[, CHR := gsub("y", "Y", CHR)]
sumstats_dt[, CHR := gsub("mt", "MT", CHR)]
#### Sort ####
if(sort_method=="data.table"){
sumstats_dt <- sort_coords_datatable(sumstats_dt = sumstats_dt)
} else if (sort_method=="GenomicRanges"){
sumstats_dt <- sort_coord_genomicranges(sumstats_dt = sumstats_dt)
}
### Now set CHR back to character to avoid issues
# when merging with other dts
sumstats_dt[,CHR:=as.character(CHR)]
### Add this to avoid confusing BiocCheck
CHR <- NULL

if (isTRUE(sort_coordinates)) {
#### Report ####
sort_method <- sort_method[1]
messager("Sorting coordinates with",paste0(shQuote(sort_method),"."))
### Double check that X and Y are uppercase
sumstats_dt[, CHR := gsub("x|23", "X", CHR)]
sumstats_dt[, CHR := gsub("y", "Y", CHR)]
sumstats_dt[, CHR := gsub("mt", "MT", CHR)]
#### Sort ####
if(sort_method=="data.table"){
sumstats_dt <- sort_coords_datatable(sumstats_dt = sumstats_dt)
} else if (sort_method=="GenomicRanges"){
sumstats_dt <- sort_coord_genomicranges(sumstats_dt = sumstats_dt)
}
return(sumstats_dt)
### Now set CHR back to character to avoid issues
# when merging with other dts
sumstats_dt[,CHR:=as.character(CHR)]
}
return(sumstats_dt)
}
3 changes: 0 additions & 3 deletions man/sort_coords.Rd

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

0 comments on commit c55aaa7

Please sign in to comment.