diff --git a/R/AllClasses.R b/R/AllClasses.R index 00f74fc9a5f77de6870ae90fd16cf42149ce2241..7c768e997e22b0b730f9473a70c9c7febb4f7a95 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -559,7 +559,8 @@ setClass("PhenoParams", #' #' The majority of the parameters for this simulation are stored in a #' \code{\link[zinbwave]{ZinbModel}} object. Please refer to the documentation -#' for this class for details about all the parameters. +#' for this class and its constructor(\code{\link[zinbwave]{zinbModel}}) for +#' details about all the parameters. #' #' The parameters not shown in brackets can be estimated from real data using #' \code{\link{zinbEstimate}}. For details of the ZINB-WaVE simulation diff --git a/R/ZINBParams-methods.R b/R/ZINBParams-methods.R index 391b34b1f9e76cbb4c54ba384f9f4734bb33086f..91b6863787f7b0d54fdd3eb6b2157984206cbbcb 100644 --- a/R/ZINBParams-methods.R +++ b/R/ZINBParams-methods.R @@ -38,14 +38,19 @@ setValidity("ZINBParams", function(object) { setMethod("setParam", "ZINBParams", function(object, name, value) { checkmate::assertString(name) - if (name %in% names(getSlots("ZinbModel"))) { - model <- getParam(object, "model") - slot(model, name) <- value - object <- setParam(object, "model", model) - } else { - object <- callNextMethod() + if (name %in% c("nGenes", "nCells")) { + stop(name, " cannot be set directly, set model instead") + } + + if (name == "model") { + object <- setParamUnchecked(object, "nGenes", + zinbwave::nFeatures(value)) + object <- setParamUnchecked(object, "nCells", + zinbwave::nSamples(value)) } + object <- cellNextMethod() + return(object) }) diff --git a/tests/testthat/test-PhenoParams.R b/tests/testthat/test-PhenoParams.R index 535724ad0b4ddf631c7e9e10a4430a9be9d092d1..d5a252daba9f5f300840bc949f8a199b79d6e7a1 100644 --- a/tests/testthat/test-PhenoParams.R +++ b/tests/testthat/test-PhenoParams.R @@ -1,7 +1,7 @@ context("PhenoParams") test_that("constructor is valid", { - expect_true(validObject(newSCDDParams())) + expect_true(validObject(newPhenoParams())) }) test_that("nGenes checks work", { diff --git a/tests/testthat/test-ZINBParams.R b/tests/testthat/test-ZINBParams.R new file mode 100644 index 0000000000000000000000000000000000000000..4a4cfdece7ffc70332b918b9e87bd0c1c885eb8c --- /dev/null +++ b/tests/testthat/test-ZINBParams.R @@ -0,0 +1,13 @@ +context("ZINBParams") + +test_that("constructor is valid", { + expect_true(validObject(newZINBParams())) +}) + +test_that("nGenes checks work", { + params <- newZINBParams() + expect_error(setParam(params, "nGenes", 1), + "nGenes cannot be set directly") + expect_error(setParam(params, "nCells", 1), + "nGenes cannot be set directly") +})