Newer
Older
#' @importFrom methods new
#' @export
newSCDDParams <- function(...) {
if (!requireNamespace("scDD", quietly = TRUE)) {
stop("The scDD simulation requires the 'scDD' package.")
utils::data("scDatEx", package = "scDD", envir = environment())
params <- setParams(params, ...)
return(params)
}
#' @importFrom checkmate checkInt checkClass checkNumeric
setValidity("SCDDParams", function(object) {
v <- getParams(object, slotNames(object))
checks <- c(nGenes = checkInt(v$nGenes, lower = 1),
nCells = checkInt(v$nCells, lower = 1),
seed = checkInt(v$seed, lower = 0),
SCDat = checkClass(v$SCdat, "SummarizedExperiment"),
nDE = checkInt(v$nDE, lower = 0),
nDP = checkInt(v$nDP, lower = 0),
nDM = checkInt(v$nDM, lower = 0),
nDB = checkInt(v$nDB, lower = 0),
nEE = checkInt(v$nEE, lower = 0),
nEP = checkInt(v$nEP, lower = 0),
sd.range = checkNumeric(v$sd.range, lower = 0, len = 2),
modeFC = checkNumeric(v$modeFC, lower = 0, len = 3),
varInflation = checkNumeric(v$varInflation, lower = 0, len = 2),
condition = checkCharacter(v$condition, len = 1))
if (v$nGenes != (v$nDE + v$nDP + v$nDM + v$nDB + v$nEE + v$nEP)) {
checks <- c(checks, nGenes = paste("nGenes is not consistent with",
"nDE, nDP, nDM, nDB, nEE, nEP"))
}
if (!(v$condition %in% colnames(SummarizedExperiment::colData(v$SCdat)))) {
checks <- c(checks, condition = paste("condition must be a column of",
"colData(SCDat)"))
}
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
if (all(checks == TRUE)) {
valid <- TRUE
} else {
valid <- checks[checks != TRUE]
valid <- paste(names(valid), valid, sep = ": ")
}
return(valid)
})
#' @rdname setParam
setMethod("setParam", "SCDDParams", function(object, name, value) {
checkmate::assertString(name)
if (name == "nGenes") {
stop(name, " cannot be set directly, set nDE, nDP, nDM, nDB, nEE or ",
"nEP instead")
}
nNames <- c("nDE", "nDP", "nDM", "nDB", "nEE", "nEP")
if (name %in% nNames) {
checkmate::assertInt(value, lower = 0)
total <- value
for (nName in nNames) {
if (nName != name) {
total <- total + getParam(object, nName)
}
}
object <- setParamUnchecked(object, "nGenes", total)
}
object <- callNextMethod()
return(object)
})
setMethod("show", "SCDDParams", function(object) {
pp <- list("Genes:" = c("[nDE]" = "nDE",
"[nDP]" = "nDP",
"[nDM]" = "nDM",
"[nDP]" = "nDP",
"[nEE]" = "nEE",
"[nEP]" = "nEP"),
"Fold change:" = c("[SD Range]" = "sd.range",
"[Mode FC]" = "modeFC"),
"Variance:" = c("[Inflation]" = "varInflation"),
"Condition:" = c("[Condition]" = "condition"))
cat("SummarizedExperiment with", dim(SCdat)[1], "features and",
dim(SCdat)[2], "samples", "\n\n")