Skip to content

Commit

Permalink
Add check and unit test for Check if all rownames start with "ENST"
Browse files Browse the repository at this point in the history
  • Loading branch information
HediaTnani committed Jan 9, 2024
1 parent 1c3c6b9 commit 70a22e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions R/DEqual.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ DEqual <- function(DE) {
stop("The rownames of the DE output and the rownames of the degradation t-statistic do not match")
}

# Check if all rownames start with "ENST"
if (!all(grepl("^ENST", rownames(DE)))) {
stop("Error: Some rownames do not start with 'ENST'.")
}

## Locate common transcripts
if (all(grepl("^ENST.*?\\.", rownames(DE)))) {
common <- intersect(rownames(qsvaR::degradation_tstats), rownames(DE))
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/test-DEqual.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ test_that("output is a ggplot", {
expect_equal(class(DEqual(random_de))[2], "ggplot")
})


# Test for rownames starting with "ENST"
test_that("DEqual correctly processes random_de", {
# If random_de is correctly structured and all rownames start with "ENST", expect no error
expect_silent(DEqual(random_de))
# For testing the error condition, altered manually rownames of random_de
altered_random_de <- random_de
rownames(altered_random_de)[1] <- "INVALID0001" # Change the first rowname to an invalid one

# Expect an error when rownames do not start with "ENST"
expect_error(DEqual(altered_random_de), "Error: Some rownames do not start with 'ENST'.")
})

0 comments on commit 70a22e5

Please sign in to comment.