Skip to content

Commit

Permalink
update dt_to_granges to avoid using SEQnames unless neccessary
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Nov 17, 2023
1 parent 9a39ba3 commit 4c36de7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions R/dt_to_granges.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#'
#' @family utils
#' @export
#' @import data.table
#' @examples
#' gr <- echodata::dt_to_granges(dat = echodata::BST1)
dt_to_granges <- function(dat,
Expand All @@ -23,15 +24,20 @@ dt_to_granges <- function(dat,
verbose = TRUE) {
requireNamespace("GenomicRanges")
requireNamespace("GenomeInfoDb")


if (is_granges(dat)) {
messager("dat is already a GRanges object.", v = verbose)
gr.snp <- dat
} else {
messager("Converting dat to GRanges object.", v = verbose)
dat[["SEQnames"]] <- dat[[chrom_col]]
dat <- data.table::as.data.table(dat)
if(chrom_col=="seqnames"){
data.table::setnames(dat,"seqnames","SEQnames")
}
gr.snp <- GenomicRanges::makeGRangesFromDataFrame(
dat,
seqnames.field = "SEQnames",
seqnames.field = chrom_col,
start.field = start_col,
end.field = end_col,
keep.extra.columns = TRUE
Expand Down
4 changes: 2 additions & 2 deletions man/reassign_lead_snps.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-dt_to_granges.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("dt_to_granges works", {
testthat::expect_true(
all.equal(
colnames(GenomicRanges::mcols(gr)),
colnames(dat)[colnames(dat)!="POS"]
colnames(dat)[!colnames(dat)%in% c("CHR","POS")]
)
)

Expand All @@ -18,7 +18,7 @@ test_that("dt_to_granges works", {
testthat::expect_true(
all.equal(
colnames(GenomicRanges::mcols(gr2)),
colnames(dat)[colnames(dat)!="POS"]
colnames(dat)[!colnames(dat)%in% c("CHR","POS")]
)
)
})

0 comments on commit 4c36de7

Please sign in to comment.