From d173ae09c328fb39f9b2c6626778bee8eb108e5a Mon Sep 17 00:00:00 2001
From: Luke Zappia <lazappi@users.noreply.github.com>
Date: Fri, 29 Sep 2017 18:14:47 +1000
Subject: [PATCH] Add MFAParams

---
 DESCRIPTION           |  3 ++-
 NAMESPACE             |  2 ++
 R/AllClasses.R        | 48 +++++++++++++++++++++++++++++++++++----
 R/MFAParams-methods.R | 52 +++++++++++++++++++++++++++++++++++++++++++
 man/MFAParams.Rd      | 35 +++++++++++++++++++++++++++++
 man/Params.Rd         |  8 +++----
 man/newParams.Rd      |  7 ++++--
 7 files changed, 144 insertions(+), 11 deletions(-)
 create mode 100644 R/MFAParams-methods.R
 create mode 100644 man/MFAParams.Rd

diff --git a/DESCRIPTION b/DESCRIPTION
index 73a36d7..68a958e 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 216436b..dedc870 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 59432fe..47b8233 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 0000000..2ff3e54
--- /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 0000000..9851398
--- /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 c8fbe45..156c6c4 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 197dc02..de3e6b8 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(...)
-- 
GitLab