forked from Al-Murphy/MungeSumstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_GRanges.R
31 lines (30 loc) · 1.07 KB
/
to_GRanges.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#' To \code{GRanges}
#'
#'
#' Convert a \link[data.table]{data.table} to \link[GenomicRanges]{GRanges}.
#' @param sumstats_dt data table obj of the summary statistics file
#' for the GWAS.
#' @param style \code{GRanges} style to convert to, "NCBI" or "UCSC".
#' @inheritParams GenomicRanges::makeGRangesFromDataFrame
#' @return \code{GRanges} object
#' @keywords internal
#' @importFrom GenomicRanges makeGRangesFromDataFrame
#' @importFrom GenomeInfoDb seqlevelsStyle
to_granges <- function(sumstats_dt,
seqnames.field = "CHR",
start.field = "BP",
end.field = "BP",
style = c("NCBI", "UCSC")) {
message("Converting summary statistics to GenomicRanges.")
gr <- GenomicRanges::makeGRangesFromDataFrame(
df = sumstats_dt,
keep.extra.columns = TRUE,
seqnames.field = seqnames.field,
start.field = start.field,
end.field = end.field
)
suppressMessages(suppressWarnings(
GenomeInfoDb::seqlevelsStyle(gr) <- style[1]
))
return(gr)
}