Skip to content

Commit

Permalink
use base pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jayhesselberth committed Sep 16, 2023
1 parent 7a8a359 commit 905b404
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 122 deletions.
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ intergenic <- bed_subtract(snps, genes)
# find distance from intergenic snps to nearest gene
nearby <- bed_closest(intergenic, genes)
nearby %>%
select(starts_with("name"), .overlap, .dist) %>%
nearby |>
select(starts_with("name"), .overlap, .dist) |>
filter(abs(.dist) < 5000)
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ intergenic <- bed_subtract(snps, genes)
# find distance from intergenic snps to nearest gene
nearby <- bed_closest(intergenic, genes)

nearby %>%
select(starts_with("name"), .overlap, .dist) %>%
nearby |>
select(starts_with("name"), .overlap, .dist) |>
filter(abs(.dist) < 5000)
#> # A tibble: 1,047 × 4
#> name.x name.y .overlap .dist
Expand Down
42 changes: 21 additions & 21 deletions bench/benchmarks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ res <- mark(
time_unit = 's')
# covert nanoseconds to seconds
res2<- res %>%
as_tibble() %>%
mutate(expression = as.character(expression)) %>%
tidyr::unnest(time) %>%
res2<- res |>
as_tibble() |>
mutate(expression = as.character(expression)) |>
tidyr::unnest(time) |>
arrange(time)
# futz with the x-axis
maxs <- res2 %>%
group_by(expression) %>%
maxs <- res2 |>
group_by(expression) |>
summarize(max.time = max(boxplot.stats(time)$stats))
# filter out outliers
res <- res2 %>%
left_join(maxs) %>%
res <- res2 |>
left_join(maxs) |>
filter(time <= max.time * 1.05)
ggplot(res, aes(x=reorder(expression, time), y=time)) +
Expand Down Expand Up @@ -157,28 +157,28 @@ res2 <- mark(
time_unit = 's')
# label experiment pair and software
comp <- as_tibble(summary(res2)) %>%
mutate(pair = as.numeric(row_number()) %% (nrow(res2) / 1 / 2)) %>%
mutate(software = rep(c("valr", "GR"), each = (nrow(res2) / 1 / 2))) %>%
select(expression, pair, software) %>%
comp <- as_tibble(summary(res2)) |>
mutate(pair = as.numeric(row_number()) %% (nrow(res2) / 1 / 2)) |>
mutate(software = rep(c("valr", "GR"), each = (nrow(res2) / 1 / 2))) |>
select(expression, pair, software) |>
mutate(expression = as.character(expression))
# convert time table
res2 <- res2 %>%
mutate(expression = as.character(expression)) %>%
as_tibble() %>%
left_join(comp) %>%
tidyr::unnest(time) %>%
res2 <- res2 |>
mutate(expression = as.character(expression)) |>
as_tibble() |>
left_join(comp) |>
tidyr::unnest(time) |>
arrange(time)
# futz with the x-axis
maxs2 <- res2 %>%
group_by(expression) %>%
maxs2 <- res2 |>
group_by(expression) |>
summarize(max.time = max(boxplot.stats(time)$stats))
# filter out outliers
res2 <- res2 %>%
left_join(maxs2) %>%
res2 <- res2 |>
left_join(maxs2) |>
filter(time <= max.time * 1.05)
#label
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_closest.r
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ test_that("ensure that subtraction is done with respect to input tbls issue#108"
"chr1", 125, 175, "C",
"chr2", 150, 200, "A"
)
x_grouped <- arrange(x, chrom, start) %>%
x_grouped <- arrange(x, chrom, start) |>
group_by(group, chrom)
y_grouped <- arrange(y, chrom, start) %>%
y_grouped <- arrange(y, chrom, start) |>
group_by(group, chrom)
res <- bed_closest(x_grouped, y_grouped)
expect_true(all(res$group.x == res$group.y))
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test_cluster.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ x <- tibble::tribble(
test_that("cluster ids are not repeated per group issue #171", {
res <- bed_cluster(x)
# test that groups have unique ids
chr1_ids <- filter(res, chrom == "chr1") %>%
select(.id) %>%
unique() %>%
chr1_ids <- filter(res, chrom == "chr1") |>
select(.id) |>
unique() |>
unlist()
chr2_ids <- filter(res, chrom == "chr2") %>%
select(.id) %>%
unique() %>%
chr2_ids <- filter(res, chrom == "chr2") |>
select(.id) |>
unique() |>
unlist()
shared_ids <- intersect(chr1_ids, chr2_ids)
expect_equal(length(shared_ids), 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_coverage.r
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test_that("coverage of stranded tbls can be calc", {
"chr2", 150, 200, 4, 25, "+", 3, 50, 50, 1.0000000,
"chr2", 180, 230, 2, 25, "-", 4, 34, 50, 0.6800000
)
res <- bed_coverage(group_by(a, strand), group_by(b, strand)) %>%
res <- bed_coverage(group_by(a, strand), group_by(b, strand)) |>
arrange(chrom, start)
expect_true(all(res == pred))
})
Expand All @@ -89,7 +89,7 @@ test_that(" strand_opp coverage works (strand_opp = TRUE)", {
"chr2", 150, 200, 4, 25, "+", 4, 50, 50, 1.0000000,
"chr2", 180, 230, 2, 25, "-", 2, 50, 50, 1.0000000
)
res <- bed_coverage(group_by(a, strand), group_by(flip_strands(b), strand)) %>%
res <- bed_coverage(group_by(a, strand), group_by(flip_strands(b), strand)) |>
arrange(chrom, start)
expect_true(all(res == pred))
})
Expand Down
26 changes: 13 additions & 13 deletions tests/testthat/test_features.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ test_that("feature lengths are valid", {

test_that("introns and exons don't overlap", {
# substracting exons from introns should be empty
expect_equal(nrow(introns %>%
expect_equal(nrow(introns |>
bed_subtract(x)), 0)
})

test_that("there is 1 feature from each gene", {
expect_true(all(utrs5 %>%
group_by(name) %>%
tally() %>%
expect_true(all(utrs5 |>
group_by(name) |>
tally() |>
pull(n) == 1))
expect_true(all(utrs3 %>%
group_by(name) %>%
tally() %>%
expect_true(all(utrs3 |>
group_by(name) |>
tally() |>
pull(n) == 1))
expect_true(all(tss %>%
group_by(name) %>%
tally() %>%
expect_true(all(tss |>
group_by(name) |>
tally() |>
pull(n) == 1))
})

Expand All @@ -41,8 +41,8 @@ test_that("TSS are single base features", {
})

test_that("intron numbers are not duplicated #377", {
expect_true(group_by(introns, name) %>%
summarize(no_duplicates = !any(duplicated(score))) %>%
pull(no_duplicates) %>%
expect_true(group_by(introns, name) |>
summarize(no_duplicates = !any(duplicated(score))) |>
pull(no_duplicates) |>
all())
})
2 changes: 1 addition & 1 deletion tests/testthat/test_flank.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("all left and right intervals are reported with both arg", {
out_left <- bed_flank(x, genome, left = dist)
out_right <- bed_flank(x, genome, right = dist)
out_both <- bed_flank(x, genome, both = dist)
out_left_right <- dplyr::bind_rows(out_left, out_right) %>%
out_left_right <- dplyr::bind_rows(out_left, out_right) |>
arrange(chrom, start)
expect_true(all(out_both == out_left_right))
})
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_intersect.r
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ test_that("same intervals are reported with single and multiple intersection", {
)
a <- bed_intersect(x, y)
b <- bed_intersect(x, z)
orig <- bind_rows(a, b) %>%
orig <- bind_rows(a, b) |>
arrange(chrom, start.x, start.y)
new <- bed_intersect(x, y, z) %>%
arrange(chrom, start.x, start.y) %>%
new <- bed_intersect(x, y, z) |>
arrange(chrom, start.x, start.y) |>
select(-.source)
expect_true(all(orig == new))
})
Expand All @@ -307,15 +307,15 @@ test_that("unmatched groups are included when invert = TRUE", {
"chr2", 200, 400, "B", # unmatched
"chr2", 300, 500, "A",
"chr2", 800, 900, "A"
) %>% group_by(chrom, group)
) |> group_by(chrom, group)

y <- tibble::tribble(
~chrom, ~start, ~end, ~group,
"chr1", 150, 400, "A",
"chr1", 500, 550, "A",
"chr2", 230, 430, "A",
"chr2", 350, 430, "A"
) %>% group_by(chrom, group)
) |> group_by(chrom, group)

pred <- tibble::tribble(
~chrom, ~start, ~end, ~group,
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_map.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ test_that("x/y groupings are respected", {
"chr1", 100, 250, 1,
"chr2", 250, 500, 2,
"chr2", 250, 500, 3
) %>%
) |>
group_by(id)

y <- tibble::tribble(
~chrom, ~start, ~end, ~value, ~id,
"chr1", 100, 250, 10, 1,
"chr1", 150, 250, 20, 2,
"chr2", 250, 500, 500, 3
) %>%
) |>
group_by(id)

pred <- tibble::tribble(
Expand Down Expand Up @@ -167,7 +167,7 @@ y <- tibble::tribble(
test_that("test count", {
res <- bed_map(x, y, vals = n())
expect_equal(res$vals, c(3, 1, NA, NA, 3, 1))
res2 <- bed_map(x, y, vals = n()) %>% mutate(vals = ifelse(is.na(vals), 0, vals))
res2 <- bed_map(x, y, vals = n()) |> mutate(vals = ifelse(is.na(vals), 0, vals))
expect_equal(res2$vals, c(3, 1, 0, 0, 3, 1))
})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_merge.r
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ test_that("Test stranded merge with bedPlus files that have strand", {
skip_if(packageVersion("readr") <= "1.4.0")

expect_warning(x <- read_bed(valr_example("bug254_e.bed"), skip = 1, lazy = FALSE))
x <- x %>% group_by(strand)
res <- bed_merge(x, 200) %>% arrange(end)
x <- x |> group_by(strand)
res <- bed_merge(x, 200) |> arrange(end)
expect_equal(res$end, c(20000, 25000))
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_random.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test_that("returns correctly sized intervals", {

test_that("all ends are less or equal to than chrom size", {
len <- 1000
res <- bed_random(genome, length = len, n = 1e4, seed = seed) %>%
mutate(chrom = as.character(chrom)) %>%
res <- bed_random(genome, length = len, n = 1e4, seed = seed) |>
mutate(chrom = as.character(chrom)) |>
left_join(genome, by = "chrom")
expect_true(all(res$end <= res$size))
})
Expand All @@ -36,7 +36,7 @@ test_that("intervals are sorted by default", {
expect_false(all(x == y))

# default sort
x_sort <- x %>%
x_sort <- x |>
arrange(chrom, start)
expect_true(all(x == x_sort))
})
2 changes: 1 addition & 1 deletion tests/testthat/test_shift.r
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_that("starts forced to 0", {

test_that("end forced to chrom length", {
size <- 1675
out <- bed_shift(bed_tbl, genome, size) %>%
out <- bed_shift(bed_tbl, genome, size) |>
left_join(genome, by = "chrom")
expect_true(all(out$end <= out$size))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_shuffle.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ genome <- tibble::tribble(
seed <- 1010486

# Random genome intervals for bed_shuffle tests
x <- bed_random(genome, n = 100, seed = seed) %>%
x <- bed_random(genome, n = 100, seed = seed) |>
arrange(chrom, start)

test_that("within = TRUE maintains chroms", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_slop.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ x <- tibble::tribble(

test_that("left arg works", {
dist <- 100
out <- x %>%
out <- x |>
bed_slop(genome, left = dist)
expect_true(all(x$start - out$start == dist))
})

test_that("right arg works", {
dist <- 100
out <- x %>%
out <- x |>
bed_slop(genome, right = dist)
expect_true(all(out$end - x$end == dist))
})

test_that("both arg works", {
dist <- 100
out <- x %>%
out <- x |>
bed_slop(genome, both = dist)
expect_true(all(x$start - out$start == dist))
expect_true(all(out$end - x$end == dist))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_spacing.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ test_that("start intervals are NA", {

res <- interval_spacing(x)

first <- res %>%
group_by(chrom) %>%
slice(1) %>%
first <- res |>
group_by(chrom) |>
slice(1) |>
select(chrom:end)

nas <- filter(res, is.na(.spacing)) %>%
nas <- filter(res, is.na(.spacing)) |>
select(chrom:end)

expect_true(all(first == nas))
Expand Down
Loading

0 comments on commit 905b404

Please sign in to comment.