Skip to content

Commit

Permalink
Modifed all tests. Removed file path and load peakCombinder associate…
Browse files Browse the repository at this point in the history
…d data set. Check all tests for the new used data.
  • Loading branch information
MarkusMuck committed Jul 18, 2024
1 parent dd0abd9 commit 3bf4873
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 860 deletions.
3 changes: 2 additions & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
library(testthat)
library(peakCombiner)

testthat::test_check("peakCombiner")
#testthat::test_check(package = "peakCombiner")
testthat::test_package(package = "peakCombiner")
138 changes: 61 additions & 77 deletions tests/testthat/test-center_expand_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,69 @@ input_colnames_pre <- c(
)
input_colnames_post <- c(
"chrom", "start", "end", "name", "score", "strand",
"center", "sample_name", "center_origin", "input_names"
"center", "sample_name", "input_names"
)
output_colnames_pre <- c(
"chrom", "start", "end", "name", "score", "strand",
"center", "sample_name"
)
output_colnames_post <- c(
"chrom", "start", "end", "name", "score", "strand",
"center", "sample_name", "center_origin", "input_names"
"center", "sample_name", "input_names"
)
##
test_data <- readr::read_tsv("lists/synthetic_genomic_regions.bed", show_col_types = FALSE)
#test_data <- readr::read_tsv("data-raw/synthetic_data.bed", show_col_types = FALSE)
test_data <- peakCombiner::syn_sample_sheet
##
test_data_prepared <- prepare_input_regions(
data = test_data
)
##
test_data_center_expand <- center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
restult_colnames <- colnames(test_data_center_expand)
##
test_data_filtered <- filter_regions(
data = test_data_center_expand,
filter_by_blacklist = "hg38", # "hg38",
filter_by_chromosome_names = NULL,
filter_by_significance = NULL,
filter_by_top_enriched = NULL
) |> suppressWarnings()
exclude_by_blacklist = "hg38", # "hg38",
include_by_chromosome_name = NULL,
include_above_score_cutoff = NULL,
include_top_n_scoring = NULL,
show_messages = TRUE
)
##
test_data_combined <- combine_regions(
data = test_data_filtered,
found_in_samples = 2,
center = "nearest"
combined_center = "nearest",
annotate_with_input_names = TRUE,
combined_sample_name = "combined"
)
##
test_data_combined_ce <- center_expand_regions(
data = test_data_combined,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
### -----------------------------------------------------------------------###
### Test input
### -----------------------------------------------------------------------###

test_that("Test if function works with pre-combined input", {
expect_no_error(center_expand_regions(
testthat::test_that("Test if function works with pre-combined input", {
testthat::expect_no_error(center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
})

test_that("Test if function works with post-combined input", {
expect_no_error(center_expand_regions(
testthat::test_that("Test if function works with post-combined input", {
testthat::expect_no_error(center_expand_regions(
data = test_data_combined,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
})
Expand All @@ -98,14 +102,14 @@ test_that("Required input data has the expected structure", {
expect_true(is.character(data$strand))
expect_true(is.numeric(data$center))
expect_true(is.character(data$sample_name))
expect_true(sum(str_detect(data$name, "|")) > 0)
expect_true(sum(stringr::str_detect(data$name, "|")) > 0)
})

test_that("Required input data has the expected structure", {

data <- test_data_combined

expect_equal(length(names(data)), 10)
expect_equal(length(names(data)), 9)
expect_identical(names(data), input_colnames_post)
expect_true(is.character(data$chrom))
expect_true(is.numeric(data$start))
Expand All @@ -114,21 +118,20 @@ test_that("Required input data has the expected structure", {
expect_true(is.numeric(data$score))
expect_true(is.character(data$strand))
expect_true(is.numeric(data$center))
expect_true(is.character(data$center_origin))
expect_true(sum(str_detect(data$input_names, "|")) > 0)
expect_true(sum(stringr::str_detect(data$input_names, "|")) > 0)
})

### -----------------------------------------------------------------------###

test_that("Required paramter 'center_by' has the expected structure/value", {
expect_no_error(center_expand_regions(
data = test_data_prepared,
center_by = "coluMn_value",
center_by = "center_Column",
expand_by = NULL
))
expect_error(center_expand_regions(
data = test_data_prepared,
center_by = c("column_value", "calculated_value"),
center_by = c("center_column", "calculated_value"),
expand_by = NULL
), "center_by")
expect_error(center_expand_regions(
Expand All @@ -150,28 +153,28 @@ test_that("Required paramter 'center_by' has the expected structure/value", {

### -----------------------------------------------------------------------###

test_that("Required paramter expand_by has the expected structure/value", {
expect_no_error(center_expand_regions(
testthat::test_that("Required paramter expand_by has the expected structure/value", {
testthat::expect_no_error(center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
expect_error(center_expand_regions(
testthat::expect_error(center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
expand_by = NA
), )
expect_error(center_expand_regions(
),)
testthat::expect_error(center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
expand_by = c(1, 2, 3)
), )
expect_error(center_expand_regions(
),)
testthat::expect_error(center_expand_regions(
data = test_data_prepared,
center_by = "column_value",
expand_by = "nonexisting"
), )
})
),)
devtools::document()})

### -----------------------------------------------------------------------###
### Test Output
Expand All @@ -195,17 +198,17 @@ test_that("Output data frame is correct for pre-combined", {
expect_true(is.numeric(data$center))
expect_true(is.character(data$sample_name))

expect_equal(mean(data$center), 1942.2535)
expect_identical(nrow(data), as.integer(71))
expect_identical(data$start[1], 250)
expect_equal(mean(data$center), 2452.92308)
expect_identical(nrow(data), as.integer(52))
expect_identical(data$start[1], 352)
})

test_that("Output data frame is correct for post-combined", {

data <- test_data_combined_ce

expect_setequal(colnames(data), output_colnames_post)
expect_equal(ncol(data), 10)
expect_equal(ncol(data), 9)

expect_identical(class(data)[2], "tbl")

Expand All @@ -216,107 +219,88 @@ test_that("Output data frame is correct for post-combined", {
expect_true(is.numeric(data$score))
expect_true(is.character(data$strand))
expect_true(is.numeric(data$center))
expect_true(is.character(data$center_origin))

expect_equal(mean(data$center), 2192.3077)
expect_identical(nrow(data), as.integer(13))
expect_identical(data$start[1], 100)
expect_identical(data$end[1], 900)
expect_identical(data$end[1], 900)
expect_equal(mean(data$center), 2711)
expect_identical(nrow(data), as.integer(10))
expect_identical(data$start[1], 152)
expect_identical(data$end[1], 850)
expect_identical(data$end[1], 850)
})

test_that("Output data frame is correct for data_prepared", {
##
data <- test_data_prepared
result <- center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
##
expect_no_error(center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
##
expect_identical(nrow(result), 71L)
expect_identical(result$start[9], as.numeric(250))
expect_identical(nrow(result), 52L)
expect_identical(result$start[9], as.numeric(252))
})
##
test_that("Output data frame is correct for data_center_expand", {
##
data <- test_data_center_expand
result <- center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
##
expect_no_error(center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
##
expect_identical(nrow(result), 71L)
expect_identical(result$start[9], as.numeric(250))
expect_identical(nrow(result), 52L)
expect_identical(result$start[9], as.numeric(252))
})
##
test_that("Output data frame is correct for data_filtered", {
##
data <- test_data_filtered
result <- center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
##
expect_no_error(center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
##
expect_identical(nrow(result), 71L)
expect_identical(result$start[9], as.numeric(250))
expect_identical(nrow(result), 52L)
expect_identical(result$start[9], as.numeric(252))
})
##
test_that("Output data frame is correct for data_combined", {
##
data <- test_data_combined
result <- center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
)
##
expect_no_error(center_expand_regions(
data = data,
center_by = "column_value",
center_by = "center_column",
expand_by = NULL
))
##
expect_identical(nrow(result), 13L)
expect_identical(result$start[9], as.numeric(100))
expect_identical(nrow(result), 10L)
expect_identical(result$start[9], as.numeric(252))
})
##
### -----------------------------------------------------------------------###
##
test_that("All newly center and expand regions do have only positive values", {
##
data_input <- readr::read_tsv(paste0("lists/input_data-bed3.bed"))
prep_data <- prepare_input_regions(data = data_input,score_colname = NULL)
##
expect_no_error(center_expand_regions(
data = prep_data,
center_by = "column_value",
expand_by = NULL
))
##
expect_message(center_expand_regions(
data = prep_data,
center_by = "column_value",
expand_by = 500
))
})
68 changes: 0 additions & 68 deletions tests/testthat/test-collapse_summits.R

This file was deleted.

Loading

0 comments on commit 3bf4873

Please sign in to comment.