From 0e3781282dec6d2a355b251ed4d2577ef18a569b Mon Sep 17 00:00:00 2001 From: mluo123 Date: Wed, 17 Apr 2024 17:32:58 -0700 Subject: [PATCH 1/2] update in.region --- R/in.region.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/in.region.R b/R/in.region.R index 91bcd9f..0e4df32 100755 --- a/R/in.region.R +++ b/R/in.region.R @@ -9,13 +9,15 @@ # If publications result from research using this SOFTWARE, we ask that the Ontario Institute for Cancer Research be acknowledged and/or # credit be given to OICR scientists, as scientifically appropriate. -in.region <- function(x,y, proportion.overlap = 1e-9, reciprocal.overlap = FALSE, check.zero.based = TRUE, check.chr = TRUE, check.valid = TRUE, check.sort = TRUE, check.merge = TRUE, verbose = FALSE) { +in.region <- function(x,y, proportion.overlap = 1e-9, method = "natural", reciprocal.overlap = FALSE, check.zero.based = TRUE, check.chr = TRUE, check.valid = TRUE, check.sort = TRUE, check.merge = TRUE, verbose = FALSE) { catv("REGION %in% REGION\n"); reciprocal.overlap <- ifelse (reciprocal.overlap, "-r", ""); params <- paste0("-c -f ", proportion.overlap, reciprocal.overlap) + x <- bedr.sort.region(x, method = method); + y <- bedr.sort.region(y, method = method); xy <- bedr(engine = "bedtools", input = list(a = x, b = y), method = "intersect", params = params, check.zero.based = check.zero.based, check.chr = check.chr, check.valid = check.valid, check.sort = check.sort, check.merge = check.merge, verbose = verbose); in.region <- xy[,ncol(xy)] > 0; From d27a48569315203a73029bbae1ae0918e1c1c6a2 Mon Sep 17 00:00:00 2001 From: mluo123 Date: Thu, 18 Apr 2024 12:46:59 -0700 Subject: [PATCH 2/2] update test cases --- tests/testthat/test-in.region.R | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-in.region.R b/tests/testthat/test-in.region.R index d38ae16..aad60eb 100644 --- a/tests/testthat/test-in.region.R +++ b/tests/testthat/test-in.region.R @@ -13,15 +13,17 @@ test_that('check in.region', { if (check.binary('bedtools', verbose = TRUE)) { regions <- get.example.regions() - regions$a <- bedr.sort.region(regions$a) - regions$b <- bedr.sort.region(regions$b) - a.b.overlap <- c(F, T, T, T, F, T, T, F) - b.a.overlap <- c(F, T, F, F, F, T, F) - a.b.overlap.pc0 <- c(F, T, T, T, F, T, T, F) - a.b.overlap.pc5 <- c(F, T, T, T, F, F, T, F) - a.b.overlap.pc1 <- c(F, F, T, T, F, F, T, F) - a.b.overlap.sorted <- c(F, T, T, T, F, T, T, F) - a.b.overlap.merged <- c(F, T, T, T, F, T, F) + regions$a.lexicon <- bedr.sort.region(regions$a) + regions$b.lexicon <- bedr.sort.region(regions$b) + regions$a <- bedr.sort.region(regions$a, method = 'natural') + regions$b <- bedr.sort.region(regions$b, method = 'natural') + a.b.overlap <- c(F, T, T, T, T, T, F, F) + b.a.overlap <- c(F, T, F, F, T, F, F) + a.b.overlap.pc0 <- c(F, T, T, T, T, T, F, F) + a.b.overlap.pc5 <- c(F, T, T, T, F, T, F, F) + a.b.overlap.pc1 <- c(F, F, T, T, F, T, F, F) + a.b.overlap.lexicon <- c(F, T, T, T, F, T, T, F) + a.b.overlap.merged <- c(F, T, T, T, T, F, F) # bad region expect_error(in.region(regions$a, 'cat', verbose = FALSE)); @@ -38,8 +40,8 @@ test_that('check in.region', { expect_equal(in.region(regions$a, regions$b, proportion.overlap = .5, verbose = FALSE), a.b.overlap.pc5); expect_equal(in.region(regions$a, regions$b, proportion.overlap = 1, verbose = FALSE), a.b.overlap.pc1); - # sorted - expect_equal(in.region(bedr.sort.region(regions$a, verbose = FALSE), regions$b, verbose = FALSE), a.b.overlap.sorted); + # lexicon sorting + expect_equal(in.region(regions$a.lexicon, regions$b.lexicon, method = 'lexicographical', verbose = FALSE), a.b.overlap.sorted); # merged expect_equal(in.region(bedr.merge.region(regions$a,verbose=F, distance = -1), regions$b, verbose = FALSE), a.b.overlap.merged);