Skip to content

Commit

Permalink
Add a check in the getDegTx function and an error when rownames not s…
Browse files Browse the repository at this point in the history
…tarting with "ENST"
  • Loading branch information
HediaTnani committed Jan 4, 2024
1 parent bd1ff44 commit faf18ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/getDegTx.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ getDegTx <- function(rse_tx, type = c("cell_component", "standard", "top1500"),
if (!is(rse_tx, "RangedSummarizedExperiment")) {
stop("Error: rse_tx must be a RangedSummarizedExperiment object.")
}

if (any(!grepl("^ENST", rownames(rse_tx)))) {
stop("Error: Some rownames do not start with 'ENST'.")
}
rse_tx <- rse_tx[rownames(rse_tx) %in% sig_transcripts, , drop = FALSE]
if (mean(rowMeans(assays(rse_tx)[[assayname]])) < 1) {
warning("The transcripts selected are lowly expressed in your dataset. This can impact downstream analysis.")
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-getDegTx.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ test_that("test warning output for lowly expressed transcripts", {
expect_warning(getDegTx(rse_tx_low))
})

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

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



0 comments on commit faf18ab

Please sign in to comment.