diff --git a/DESCRIPTION b/DESCRIPTION index 73a36d7df45b733557f8167cd9e1db8ff9de47d3..68a958e1298e8906a3c0f8da5ee1c9ef9eaa5e20 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,7 +51,8 @@ Suggests: rmarkdown, S4Vectors, scDD, - scran + scran, + mfa biocViews: SingleCell, RNASeq, Transcriptomics, GeneExpression, Sequencing, Software URL: https://github.com/Oshlack/splatter diff --git a/NAMESPACE b/NAMESPACE index 216436b18d78a343574efa2442f5243c0a6454b0..dedc870e9421fb8307d88327a41232193a96c181 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ export(makeDiffPanel) export(makeOverallPanel) export(newLun2Params) export(newLunParams) +export(newMFAParams) export(newSCDDParams) export(newSimpleParams) export(newSplatParams) @@ -42,6 +43,7 @@ export(splatSimulateSingle) export(summariseDiff) exportClasses(Lun2Params) exportClasses(LunParams) +exportClasses(MFAParams) exportClasses(SCDDParams) exportClasses(SimpleParams) exportClasses(SplatParams) diff --git a/R/AllClasses.R b/R/AllClasses.R index 59432fe5ebe17e623cf3c367bacb33cdd1394b6d..47b8233a8c28bdadca1a68d44e8da9d1d446bee1 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -7,12 +7,12 @@ #' The Params class defines the following parameters: #' #' \describe{ -#' \item{\code{[nGenes]}}{The number of genes to simulate.} -#' \item{\code{[nCells]}}{The number of cells to simulate.} -#' \item{\code{seed}}{Seed to use for generating random numbers.} +#' \item{\code{nGenes}}{The number of genes to simulate.} +#' \item{\code{nCells}}{The number of cells to simulate.} +#' \item{\code{[seed]}}{Seed to use for generating random numbers.} #' } #' -#' The parameters shown in brackets can be estimated from real data. +#' The parameters not shown in brackets can be estimated from real data. #' #' @name Params #' @rdname Params @@ -460,3 +460,43 @@ setClass("SCDDParams", modeFC = c(2, 3, 4), varInflation = c(1, 1), condition = "condition")) + +#' The MFAParams class +#' +#' S4 class that holds parameters for the mfa simulation. +#' +#' @section Parameters: +#' +#' The mfa simulation uses the following parameters: +#' +#' \describe{ +#' \item{\code{nGenes}}{The number of genes to simulate.} +#' \item{\code{nCells}}{The number of cells to simulate.} +#' \item{\code{[seed]}}{Seed to use for generating random numbers.} +#' \item{\code{[trans.prop]}}{Proportion of genes that show transient +#' expression. These genes are briefly up or down-regulated before returning +#' to their initial state} +#' \item{\code{[zero.neg]}}{Logical. Whether to set negative expression +#' values to zero. This will zero-inflate the data.} +#' \item{\code{[dropout.present]}}{Logical. Whether to simulate dropout.} +#' \item{\code{dropout.lambda}}{Lambda parameter for the exponential +#' dropout function.} +#' } +#' +#' The parameters not shown in brackets can be estimated from real data using +#' \code{\link{mfaEstimate}}. See \code{\link[mfa]{create_synthetic}} for more +#' details about the parameters. For details of the Splatter implementation of +#' the mfa simulation see \code{\link{mfaSimulate}}. +#' +#' @name MFAParams +#' @rdname MFAParams +#' @aliases MFAParams-class +#' @exportClass MFAParams +setClass("MFAParams", + contains = "Params", + slots = c(trans.prop = "numeric", + zero.neg = "logical", + dropout.present = "logical", + dropout.lambda = "numeric"), + prototype = prototype(trans.prop = 0, zero.neg = TRUE, + dropout.present = FALSE, dropout.lambda = 1)) diff --git a/R/MFAParams-methods.R b/R/MFAParams-methods.R new file mode 100644 index 0000000000000000000000000000000000000000..2ff3e54d5f8730b93e7c8cf6789923c2fc148f12 --- /dev/null +++ b/R/MFAParams-methods.R @@ -0,0 +1,52 @@ +#' @rdname newParams +#' @importFrom methods new +#' @export +newMFAParams <- function(...) { + + if (!requireNamespace("mfa", quietly = TRUE)) { + stop("The mfa simulation requires the 'mfa' package.") + } + + params <- new("MFAParams") + params <- setParams(params, ...) + + return(params) +} + +setValidity("MFAParams", function(object) { + + v <- getParams(object, slotNames(object)) + + checks <- c(nGenes = checkmate::checkInt(v$nGenes, lower = 1), + nCells = checkmate::checkInt(v$nCells, lower = 1), + trans.prop = checkmate::checkNumber(v$trans.prop, lower = 0, + upper = 1), + zero.neg = checkmate::checkLogical(v$zero.neg, + any.missing = FALSE, + len = 1), + dropout.present = checkmate::checkLogical(v$dropout.present, + any.missing = FALSE, + len = 1), + dropout.lambda = checkmate::checkNumber(v$dropout.lambda), + seed = checkmate::checkInt(v$seed, lower = 0)) + + if (all(checks == TRUE)) { + valid <- TRUE + } else { + valid <- checks[checks != TRUE] + valid <- paste(names(valid), valid, sep = ": ") + } + + return(valid) +}) + +setMethod("show", "MFAParams", function(object) { + + pp <- list("Transient:" = c("[Proportion]" = "trans.prop"), + "Negative:" = c("[Zero]" = "zero.neg"), + "Dropout:" = c("[Present]" = "dropout.present", + "(Lambda)" = "dropout.lambda")) + + callNextMethod() + showPP(object, pp) +}) diff --git a/man/MFAParams.Rd b/man/MFAParams.Rd new file mode 100644 index 0000000000000000000000000000000000000000..98513986450613ef64bad9e52401da3085e1c54c --- /dev/null +++ b/man/MFAParams.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllClasses.R +\docType{class} +\name{MFAParams} +\alias{MFAParams} +\alias{MFAParams-class} +\title{The MFAParams class} +\description{ +S4 class that holds parameters for the mfa simulation. +} +\section{Parameters}{ + + +The mfa simulation uses the following parameters: + +\describe{ + \item{\code{nGenes}}{The number of genes to simulate.} + \item{\code{nCells}}{The number of cells to simulate.} + \item{\code{[seed]}}{Seed to use for generating random numbers.} + \item{\code{[trans.prop]}}{Proportion of genes that show transient + expression. These genes are briefly up or down-regulated before returning + to their initial state} + \item{\code{[zero.neg]}}{Logical. Whether to set negative expression + values to zero. This will zero-inflate the data.} + \item{\code{[dropout.present]}}{Logical. Whether to simulate dropout.} + \item{\code{dropout.lambda}}{Lambda parameter for the exponential + dropout function.} +} + +The parameters not shown in brackets can be estimated from real data using +\code{\link{mfaEstimate}}. See \code{\link[mfa]{create_synthetic}} for more +details about the parameters. For details of the Splatter implementation of +the mfa simulation see \code{\link{mfaSimulate}}. +} + diff --git a/man/Params.Rd b/man/Params.Rd index c8fbe4566a83eea6ec35f0ee19667cbd905fd183..156c6c4e204c14862bed13e076e70900f2543d36 100644 --- a/man/Params.Rd +++ b/man/Params.Rd @@ -14,11 +14,11 @@ Virtual S4 class that all other Params classes inherit from. The Params class defines the following parameters: \describe{ - \item{\code{[nGenes]}}{The number of genes to simulate.} - \item{\code{[nCells]}}{The number of cells to simulate.} - \item{\code{seed}}{Seed to use for generating random numbers.} + \item{\code{nGenes}}{The number of genes to simulate.} + \item{\code{nCells}}{The number of cells to simulate.} + \item{\code{[seed]}}{Seed to use for generating random numbers.} } -The parameters shown in brackets can be estimated from real data. +The parameters not shown in brackets can be estimated from real data. } diff --git a/man/newParams.Rd b/man/newParams.Rd index 197dc0204454f31bf20343896156205931392de4..de3e6b85de30198d6b9b53158119455e52e40d50 100644 --- a/man/newParams.Rd +++ b/man/newParams.Rd @@ -1,11 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/Lun2Params-methods.R, -% R/LunParams-methods.R, R/SCDDParams-methods.R, R/SimpleParams-methods.R, -% R/SplatParams-methods.R +% R/LunParams-methods.R, R/MFAParams-methods.R, R/SCDDParams-methods.R, +% R/SimpleParams-methods.R, R/SplatParams-methods.R \name{newParams} \alias{newParams} \alias{newLun2Params} \alias{newLunParams} +\alias{newMFAParams} \alias{newSCDDParams} \alias{newSimpleParams} \alias{newSplatParams} @@ -15,6 +16,8 @@ newLun2Params(...) newLunParams(...) +newMFAParams(...) + newSCDDParams(...) newSimpleParams(...)