Skip to content

Commit eaed2c8

Browse files
116: sanitize error message from vst (#117)
1 parent 4f533f8 commit eaed2c8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

R/normalization.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,18 @@ h_vst <- function(object,
230230
is_hermes_data(object),
231231
is_list_with(control, "fit_type")
232232
)
233-
DESeq2::varianceStabilizingTransformation(
234-
counts(object),
235-
fitType = control$fit_type
236-
)
233+
tryCatch({
234+
DESeq2::varianceStabilizingTransformation(
235+
counts(object),
236+
fitType = control$fit_type
237+
)
238+
},
239+
error = function(e) {
240+
stop(paste(
241+
"During calculation of variance-stabilized transformation (VST) hit error,",
242+
"try again with more genes. Original error:", e
243+
))
244+
})
237245
}
238246

239247
#' @describeIn normalize regularized log transformation (`rlog`) from `DESeq2` package.

tests/testthat/test-normalization.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ test_that("h_vst fails when there are no genes", {
236236
expect_error(h_vst(object))
237237
})
238238

239+
test_that("h_vst gives understandable error for an object with few genes", {
240+
object <- HermesData(get_se())
241+
expect_error(
242+
h_vst(object),
243+
"try again with more genes"
244+
)
245+
})
246+
239247
# h_rlog ----
240248

241249
test_that("h_rlog function works as expected with default settings", {

0 commit comments

Comments
 (0)