From 51db1e57667b8b9739e34d37cf70b4ac40496d80 Mon Sep 17 00:00:00 2001 From: Luke Zappia <lazappi@users.noreply.github.com> Date: Thu, 13 Oct 2016 23:14:40 +1100 Subject: [PATCH] Add splatParams object --- DESCRIPTION | 2 +- NAMESPACE | 7 + R/AllClasses.R | 174 +++++++++++++++++++++++-- R/AllGenerics.R | 28 +++- R/Params-methods.R | 20 ++- R/SplatParams-methods.R | 166 +++++++++++++++++++++++ R/params-functions.R | 5 +- R/splat-estimate.R | 0 man/SimpleParams.Rd | 14 +- man/SplatParams.Rd | 111 ++++++++++++++++ man/expandParams-SplatParams-method.Rd | 29 +++++ man/expandParams.Rd | 28 ++++ man/newSplatParams.Rd | 21 +++ man/setParam.Rd | 11 +- man/setParams.Rd | 4 +- tests/testthat/test-SplatParams.R | 7 + 16 files changed, 597 insertions(+), 30 deletions(-) create mode 100644 R/SplatParams-methods.R create mode 100644 R/splat-estimate.R create mode 100644 man/SplatParams.Rd create mode 100644 man/expandParams-SplatParams-method.Rd create mode 100644 man/expandParams.Rd create mode 100644 man/newSplatParams.Rd create mode 100644 tests/testthat/test-SplatParams.R diff --git a/DESCRIPTION b/DESCRIPTION index 812c8ab..6dd8764 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: splatter Type: Package Title: Simple Simulation of Single-cell RNA Sequencing Data -Version: 0.6.4 +Version: 0.6.5 Date: 2016-10-13 Author: Luke Zappia Authors@R: as.person(c( diff --git a/NAMESPACE b/NAMESPACE index 40e112a..897a8ca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,10 +6,17 @@ export(estimateSimpleParams) export(getParam) export(getParams) export(newSimpleParams) +export(newSplatParams) export(setParam) export(setParams) export(simpleSimulate) exportClasses(SimpleParams) +exportClasses(SplatParams) +importFrom(checkmate,checkFlag) +importFrom(checkmate,checkInt) +importFrom(checkmate,checkIntegerish) +importFrom(checkmate,checkNumber) +importFrom(checkmate,checkNumeric) importFrom(scater,newSCESet) importFrom(stats,median) importFrom(stats,rgamma) diff --git a/R/AllClasses.R b/R/AllClasses.R index 7f058b5..fc595f9 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -34,18 +34,18 @@ setClass("Params", #' The simple 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{[mean.shape]}}{The shape parameter for the mean gamma +#' \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{mean.shape}}{The shape parameter for the mean gamma #' distribution.} -#' \item{\code{[mean.rate]}}{The rate parameter for the mean gamma +#' \item{\code{mean.rate}}{The rate parameter for the mean gamma #' distribution.} -#' \item{\code{count.disp}}{The dispersion parameter for the counts negative +#' \item{\code{[count.disp]}}{The dispersion parameter for the counts negative #' binomial distribution.} #' } #' -#' The parameters shown in brackets can be estimated from real data using +#' The parameters not shown in brackets can be estimated from real data using #' \code{\link{estimateSimpleParams}}. For details of the simple simulation #' see \code{\link{simpleSimulate}}. #' @@ -59,4 +59,162 @@ setClass("SimpleParams", mean.rate = "numeric", count.disp = "numeric"), prototype = prototype(mean.shape = 0.4, mean.rate = 0.3, - count.disp = 0.1)) \ No newline at end of file + count.disp = 0.1)) + +#' The SplatParams class +#' +#' S4 class that holds parameters for the Splatter simulation. +#' +#' @section Parameters: +#' +#' The Splatter simulation requires the following parameters: +#' +#' \describe{ +#' \item{\code{nGenes}}{The number of genes to simulate.} +#' \item{\code{nCells}}{The number of cells to simulate.} +#' \item{\code{[groupCells]}}{Vector giving the number of cells in each +#' simulation group/path.} +#' \item{\code{[seed]}}{Seed to use for generating random numbers.} +#' \item{\emph{Mean parameters}}{ +#' \describe{ +#' \item{\code{mean.shape}}{Shape parameter for the mean gamma +#' distribution.} +#' \item{\code{mean.rate}}{Rate parameter for the mean gamma +#' distribution.} +#' } +#' } +#' \item{\emph{Library size parameters}}{ +#' \describe{ +#' \item{\code{lib.loc}}{Location (meanlog) parameter for the library +#' size log-normal distribution.} +#' \item{\code{lib.scale}}{Scale (sdlog) parameter for the library size +#' log-normal distribution.} +#' } +#' } +#' \item{\emph{Expression outlier parameters}}{ +#' \describe{ +#' \item{\code{out.prob}}{Probability that a gene is an expression +#' outlier.} +#' \item{\code{out.loProb}}{Probability that an expression outlier gene +#' is lowly expressed.} +#' \item{\code{out.facLoc}}{Location (meanlog) parameter for the +#' expression outlier factor log-normal distribution.} +#' \item{\code{out.facScale}}{Scale (sdlog) parameter for the expression +#' outlier factor log-normal distribution.} +#' } +#' } +#' \item{\emph{Differential expression parameters}}{ +#' \describe{ +#' \item{\code{[de.prob]}}{Probability that a gene is differentially +#' expressed in a group. Can be a vector.} +#' \item{\code{[de.loProb]}}{Probability that differentially expressed +#' gene is down-regulated. Can be a vector.} +#' \item{\code{[de.facLoc]}}{Location (meanlog) parameter for the +#' differential expression factor log-normal distribution. Can be a +#' vector.} +#' \item{\code{[de.facScale]}}{Scale (sdlog) parameter for the +#' differential expression factor log-normal distribution. Can be a +#' vector.} +#' } +#' } +#' \item{\emph{Biological Coefficient of Variation parameters}}{ +#' \describe{ +#' \item{\code{bcv.common}}{Underlying common dispersion across all +#' genes.} +#' \item{\code{bcv.df}}{Degrees of Freedom for the BCV inverse chi-squared +#' distribution.} +#' } +#' } +#' \item{\emph{Dropout parameters}}{ +#' \describe{ +#' \item{\code{dropout.present}}{Logical. Whether to simulate dropout.} +#' \item{\code{dropout.mid}}{Midpoint parameter for the dropout logistic +#' function.} +#' \item{\code{dropout.shape}}{Shape parameter for the dropout logistic +#' function.} +#' } +#' } +#' \item{\emph{Differentiation path parameters}}{ +#' \describe{ +#' \item{\code{[path.from]}}{Vector giving the originating point of each +#' path. This allows path structure such as a cell type which +#' differentiates into an intermediate cell type that then differentiates +#' into two mature cell types. A path structure of this form would have a +#' "from" parameter of c(0, 1, 1) (where 0 is the origin). If no vector is +#' given all paths will start at the origin.} +#' \item{\code{[path.length]}}{Vector giving the number of steps to +#' simulate along each path. If a single value is given it will be applied +#' to all paths.} +#' \item{\code{[path.skew]}}{Vector giving the skew of each path. Values +#' closer to 1 will give more cells towards the starting population, +#' values closer to 0 will give more cells towards the final population. +#' If a single value is given it will be applied to all paths.} +#' \item{\code{[path.nonlinearProb]}}{Probability that a gene follows a +#' non-linear path along the differentiation path. This allows more +#' complex gene patterns such as a gene being equally expressed at the +#' beginning an end of a path but lowly expressed in the middle.} +#' \item{\code{[path.sigmaFac]}}{Sigma factor for non-linear gene paths. +#' A higher value will result in more extreme non-linear variations along +#' a path.} +#' } +#' } +#' } +#' +#' The parameters not shown in brackets can be estimated from real data using +#' \code{\link{estimateSplatParams}}. For details of the Splatter simulation +#' see \code{\link{splatSimulate}}. +#' +#' @name SplatParams +#' @rdname SplatParams +#' @aliases SplatParams-class +#' @exportClass SplatParams +setClass("SplatParams", + contains = "Params", + slots = c(nGroups = "numeric", + groupCells = "numeric", + mean.shape = "numeric", + mean.rate = "numeric", + lib.loc = "numeric", + lib.scale = "numeric", + out.prob = "numeric", + out.loProb = "numeric", + out.facLoc = "numeric", + out.facScale = "numeric", + de.prob = "numeric", + de.downProb = "numeric", + de.facLoc = "numeric", + de.facScale = "numeric", + bcv.common = "numeric", + bcv.df = "numeric", + dropout.present = "logical", + dropout.mid = "numeric", + dropout.shape = "numeric", + path.from = "numeric", + path.length = "numeric", + path.skew = "numeric", + path.nonlinearProb = "numeric", + path.sigmaFac = "numeric"), + prototype = prototype(nGroups = 1, + groupCells = 100, + mean.rate = 0.3, + mean.shape = 0.4, + lib.loc = 10, + lib.scale = 0.5, + out.prob = 0.1, + out.loProb = 0.5, + out.facLoc = 4, + out.facScale = 1, + de.prob = 0.1, + de.downProb = 0.5, + de.facLoc = 4, + de.facScale = 1, + bcv.common = 0.1, + bcv.df = 25, + dropout.present = TRUE, + dropout.mid = 0, + dropout.shape = -1, + path.from = 0, + path.length = 100, + path.skew = 0.5, + path.nonlinearProb = 0.1, + path.sigmaFac = 0.8)) \ No newline at end of file diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 00639fd..ca77aea 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -18,16 +18,32 @@ setGeneric("getParam", function(object, name) {standardGeneric("getParam")}) #' @param object object to set parameter in. #' @param name name of the parameter to set. #' @param value value to set the paramter to. +#' @param checkValid logical. Check object is valid after setting. #' #' @return Object with new parameter value. #' #' @rdname setParam #' @export setGeneric("setParam", - function(object, name, value) {standardGeneric("setParam")}) + function(object, name, value, checkValid) { + standardGeneric("setParam") +}) -#' #@name arrange -#' #@rdname arrange -#' #@docType methods -#' #@export -#setGeneric("expandParams", function(object) {standardGeneric("expandParams")}) \ No newline at end of file +#' Expand parameters +#' +#' Expand the parameters that can be vectors so that they are the same length as +#' the number of groups. +#' +#' @param object splatParams object to expand. +#' @param ... additional arguments. +#' +#' @return Expanded splatParams object. +#' @examples +#' params <- newSplatParams() +#' params <- setParams(params, groupCells = c(10, 10)) +#' params +#' params <- expandParams(params) +#' params +setGeneric("expandParams", function(object, ...) { + standardGeneric("expandParams") +}) \ No newline at end of file diff --git a/R/Params-methods.R b/R/Params-methods.R index 558da5d..3f0796f 100644 --- a/R/Params-methods.R +++ b/R/Params-methods.R @@ -4,10 +4,11 @@ setMethod("getParam", "Params", function(object, name) { }) #' @rdname setParam -setMethod("setParam", "Params", function(object, name, value) { +setMethod("setParam", "Params", + function(object, name, value, checkValid = TRUE) { checkmate::assertString(name) slot(object, name) <- value - validObject(object) + if (checkValid) {validObject(object)} return(object) }) @@ -22,4 +23,19 @@ setMethod("show", "Params", function(object) { "'Default' or 'NOT DEFAULT'", "\n\n") showPP(object, pp) cat(length(slotNames(object)) - 3, "additional parameters", "\n\n") +}) + +setMethod("expandParams", "Params", function(object, vectors, n) { + + update <- list() + for (parameter in vectors) { + value <- getParam(object, parameter) + if (length(value) == 1) { + update[[parameter]] <- rep(value, n) + } + } + + object <- setParams(object, update, checkValid = FALSE) + + return(object) }) \ No newline at end of file diff --git a/R/SplatParams-methods.R b/R/SplatParams-methods.R new file mode 100644 index 0000000..a3f1268 --- /dev/null +++ b/R/SplatParams-methods.R @@ -0,0 +1,166 @@ +#' New SplatParams +#' +#' Create a new SplatParams object. +#' +#' @param ... additional parameters passed to \code{\link{setParams}}. +#' +#' @return SplatParams object. +#' @examples +#' params <- newSplatParams() +#' @export +newSplatParams <- function(...) { + + params <- new("SplatParams") + params <- setParams(params, ...) + + return(params) +} + +#' @importFrom checkmate checkInt checkIntegerish checkNumber checkNumeric +#' checkFlag +setValidity("SplatParams", function(object) { + + object <- expandParams(object) + v <- getParams(object, c(slotNames(object))) + + nGroups <- v$nGroups + checks <- c(nGenes = checkInt(v$nGenes, lower = 1), + nCells = checkInt(v$nCells, lower = 1), + nGroups = checkInt(v$nGroups, lower = 1), + groupCells = checkIntegerish(v$groupCells, lower = 1, + len = nGroups), + mean.rate = checkNumber(v$mean.rate, lower = 0), + mean.shape = checkNumber(v$mean.shape, lower = 0), + lib.loc = checkNumber(v$lib.loc), + lib.scale = checkNumber(v$lib.scale, lower = 0), + out.prob = checkNumber(v$out.prob, lower = 0, upper = 1), + out.loProb = checkNumber(v$out.loProb, lower = 0, upper = 1), + out.facLoc = checkNumber(v$lib.loc), + out.facScale = checkNumber(v$lib.scale, lower = 0), + out.prob = checkNumber(v$out.prob, lower = 0, upper = 1), + out.loProb = checkNumber(v$out.loProb, lower = 0, upper = 1), + out.facLoc = checkNumber(v$out.facLoc), + out.facScale = checkNumber(v$out.facScale, lower = 0), + de.prob = checkNumeric(v$de.prob, lower = 0, upper = 1, + len = nGroups), + de.downProb = checkNumeric(v$de.downProb, lower = 0, upper = 1, + len = nGroups), + de.facLoc = checkNumeric(v$de.facLoc, len = nGroups), + de.facScale = checkNumeric(v$de.facScale, lower = 0, + len = nGroups), + bcv.common = checkNumber(v$bcv.common, lower = 0), + bcv.df = checkNumber(v$bcv.df, lower = 0), + dropout.present = checkFlag(v$dropout.present), + dropout.mid = checkNumber(v$dropout.mid), + dropout.shape = checkNumber(v$dropout.shape), + path.from = checkIntegerish(v$path.from, lower = 0, + upper = nGroups, len = nGroups), + path.length = checkIntegerish(v$path.length, lower = 1, + len = nGroups), + path.skew = checkNumeric(v$path.skew, lower = 0, upper = 1, + len = nGroups), + path.nonlinearProb = checkNumber(v$path.nonlinearProb, + lower = 0, upper = 1), + path.sigmaFac = checkNumber(v$path.sigmaFac, lower = 0), + seed = checkInt(v$seed, lower = 0)) + + # Check groupCells matches nCells, nGroups + if (v$nCells != sum(v$groupCells) || nGroups != length(v$groupCells)) { + checks <- c(checks, + "nCells, nGroups and groupCells are not consistent") + } + + # Check path.from + if (!(0 %in% v$path.from)) { + checks <- c(checks, path.from = "origin must be specified in path.from") + } else if (any(v$path.from == 1:nGroups)) { + checks <- c(checks, stop("path cannot begin at itself")) + } + + if (all(checks == TRUE)) { + valid <- TRUE + } else { + valid <- checks[checks != TRUE] + valid <- paste(names(valid), valid, sep = ": ") + } + + return(valid) +}) + +#' @rdname setParam +setMethod("setParam", "SplatParams", + function(object, name, value, checkValid) { + checkmate::assertString(name) + + if (name == "nCells" || name == "nGroups") { + stop(name, " cannot be set directly, set groupCells instead") + } + + if (name == "groupCells") { + object <- callNextMethod(object, "nCells", sum(value), checkValid) + object <- callNextMethod(object, "nGroups", length(value), checkValid) + } + + object <- callNextMethod() + + return(object) +}) + +setMethod("show", "SplatParams", function(object) { + + pp <- list("Global:" = c("[Groups]" = "nGroups", + "[Group Cells]" = "groupCells"), + "Mean:" = c("(Rate)" = "mean.rate", + "(Shape)" = "mean.shape"), + "Library size:" = c("(Location)" = "lib.loc", + "(Scale)" = "lib.scale"), + "Exprs outliers:" = c("(Probability)" = "out.prob", + "(Lo Prob)" = "out.loProb", + "(Location)" = "out.facLoc", + "(Scale)" = "out.facScale"), + "Diff expr:" = c("[Probability]" = "de.prob", + "[Down Prob]" = "de.downProb", + "[Location]" = "de.facLoc", + "[Scale]" = "de.facScale"), + "BCV:" = c("(Common Disp)" = "bcv.common", + "(DoF)" = "bcv.df"), + "Dropout:" = c("(Present T/F)" = "dropout.present", + "(Midpoint)" = "dropout.mid", + "(Shape)" = "dropout.shape"), + "Paths:" = c("[From]" = "path.from", + "[Length]" = "path.length", + "[Skew]" = "path.skew", + "[Non-linear]" = "path.nonlinearProb", + "[Sigma Factor]" = "path.sigmaFac")) + + callNextMethod() + showPP(object, pp) +}) + +#' Expand parameters +#' +#' Expand the parameters that can be vectors so that they are the same length as +#' the number of groups. +#' +#' @param object splatParams object to expand. +#' +#' @return Expanded splatParams object. +#' @examples +#' \dontrun{ +#' params <- newSplatParams() +#' params <- setParams(params, groupCells = c(10, 10)) +#' params +#' params <- expandParams(params) +#' params +#' } +setMethod("expandParams", "SplatParams", function(object) { + + n <- getParam(object, "nGroups") + + vectors <- c("de.prob", "de.downProb", "de.facLoc", "de.facScale", + "path.from", "path.length", "path.skew") + + object <- callNextMethod(object, vectors, n) + + return(object) +}) \ No newline at end of file diff --git a/R/params-functions.R b/R/params-functions.R index c795020..f93e8d1 100644 --- a/R/params-functions.R +++ b/R/params-functions.R @@ -27,6 +27,7 @@ getParams <- function(params, names) { #' names of the parameters to set and the items in the list are values. #' @param ... additional parameters to set. These are combined with any #' parameters specified in \code{update}. +#' @param checkValid logical. Whether to check set object is valid. #' #' @details #' Each parameter is set by a call to \code{\link{setParam}}. If the same @@ -46,7 +47,7 @@ getParams <- function(params, names) { #' params <- setParams(params, list(mean.rate = 0.2, mean.shape = 0.8)) #' params #' @export -setParams <- function(params, update = NULL, ...) { +setParams <- function(params, update = NULL, checkValid = TRUE, ...) { checkmate::assertClass(params, classes = "Params") checkmate::assertList(update, null.ok = TRUE) @@ -56,7 +57,7 @@ setParams <- function(params, update = NULL, ...) { if (length(update) > 0) { for (name in names(update)) { value <- update[[name]] - params <- setParam(params, name, value) + params <- setParam(params, name, value, checkValid) } } diff --git a/R/splat-estimate.R b/R/splat-estimate.R new file mode 100644 index 0000000..e69de29 diff --git a/man/SimpleParams.Rd b/man/SimpleParams.Rd index 249888b..787073e 100644 --- a/man/SimpleParams.Rd +++ b/man/SimpleParams.Rd @@ -14,18 +14,18 @@ S4 class that holds parameters for the simple simulation. The simple 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{[mean.shape]}}{The shape parameter for the mean gamma + \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{mean.shape}}{The shape parameter for the mean gamma distribution.} - \item{\code{[mean.rate]}}{The rate parameter for the mean gamma + \item{\code{mean.rate}}{The rate parameter for the mean gamma distribution.} - \item{\code{count.disp}}{The dispersion parameter for the counts negative + \item{\code{[count.disp]}}{The dispersion parameter for the counts negative binomial distribution.} } -The parameters shown in brackets can be estimated from real data using +The parameters not shown in brackets can be estimated from real data using \code{\link{estimateSimpleParams}}. For details of the simple simulation see \code{\link{simpleSimulate}}. } diff --git a/man/SplatParams.Rd b/man/SplatParams.Rd new file mode 100644 index 0000000..b27e11c --- /dev/null +++ b/man/SplatParams.Rd @@ -0,0 +1,111 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllClasses.R +\docType{class} +\name{SplatParams} +\alias{SplatParams} +\alias{SplatParams-class} +\title{The SplatParams class} +\description{ +S4 class that holds parameters for the Splatter simulation. +} +\section{Parameters}{ + + +The Splatter simulation requires the following parameters: + +\describe{ + \item{\code{nGenes}}{The number of genes to simulate.} + \item{\code{nCells}}{The number of cells to simulate.} + \item{\code{[groupCells]}}{Vector giving the number of cells in each + simulation group/path.} + \item{\code{[seed]}}{Seed to use for generating random numbers.} + \item{\emph{Mean parameters}}{ + \describe{ + \item{\code{mean.shape}}{Shape parameter for the mean gamma + distribution.} + \item{\code{mean.rate}}{Rate parameter for the mean gamma + distribution.} + } + } + \item{\emph{Library size parameters}}{ + \describe{ + \item{\code{lib.loc}}{Location (meanlog) parameter for the library + size log-normal distribution.} + \item{\code{lib.scale}}{Scale (sdlog) parameter for the library size + log-normal distribution.} + } + } + \item{\emph{Expression outlier parameters}}{ + \describe{ + \item{\code{out.prob}}{Probability that a gene is an expression + outlier.} + \item{\code{out.loProb}}{Probability that an expression outlier gene + is lowly expressed.} + \item{\code{out.facLoc}}{Location (meanlog) parameter for the + expression outlier factor log-normal distribution.} + \item{\code{out.facScale}}{Scale (sdlog) parameter for the expression + outlier factor log-normal distribution.} + } + } + \item{\emph{Differential expression parameters}}{ + \describe{ + \item{\code{[de.prob]}}{Probability that a gene is differentially + expressed in a group. Can be a vector.} + \item{\code{[de.loProb]}}{Probability that differentially expressed + gene is down-regulated. Can be a vector.} + \item{\code{[de.facLoc]}}{Location (meanlog) parameter for the + differential expression factor log-normal distribution. Can be a + vector.} + \item{\code{[de.facScale]}}{Scale (sdlog) parameter for the + differential expression factor log-normal distribution. Can be a + vector.} + } + } + \item{\emph{Biological Coefficient of Variation parameters}}{ + \describe{ + \item{\code{bcv.common}}{Underlying common dispersion across all + genes.} + \item{\code{bcv.df}}{Degrees of Freedom for the BCV inverse chi-squared + distribution.} + } + } + \item{\emph{Dropout parameters}}{ + \describe{ + \item{\code{dropout.present}}{Logical. Whether to simulate dropout.} + \item{\code{dropout.mid}}{Midpoint parameter for the dropout logistic + function.} + \item{\code{dropout.shape}}{Shape parameter for the dropout logistic + function.} + } + } + \item{\emph{Differentiation path parameters}}{ + \describe{ + \item{\code{[path.from]}}{Vector giving the originating point of each + path. This allows path structure such as a cell type which + differentiates into an intermediate cell type that then differentiates + into two mature cell types. A path structure of this form would have a + "from" parameter of c(0, 1, 1) (where 0 is the origin). If no vector is + given all paths will start at the origin.} + \item{\code{[path.length]}}{Vector giving the number of steps to + simulate along each path. If a single value is given it will be applied + to all paths.} + \item{\code{[path.skew]}}{Vector giving the skew of each path. Values + closer to 1 will give more cells towards the starting population, + values closer to 0 will give more cells towards the final population. + If a single value is given it will be applied to all paths.} + \item{\code{[path.nonlinearProb]}}{Probability that a gene follows a + non-linear path along the differentiation path. This allows more + complex gene patterns such as a gene being equally expressed at the + beginning an end of a path but lowly expressed in the middle.} + \item{\code{[path.sigmaFac]}}{Sigma factor for non-linear gene paths. + A higher value will result in more extreme non-linear variations along + a path.} + } + } +} + +The parameters not shown in brackets can be estimated from real data using +\code{\link{estimateSplatParams}}. For details of the Splatter simulation +see \code{\link{splatSimulate}}. +} + diff --git a/man/expandParams-SplatParams-method.Rd b/man/expandParams-SplatParams-method.Rd new file mode 100644 index 0000000..aab93c5 --- /dev/null +++ b/man/expandParams-SplatParams-method.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SplatParams-methods.R +\docType{methods} +\name{expandParams,SplatParams-method} +\alias{expandParams,SplatParams-method} +\title{Expand parameters} +\usage{ +\S4method{expandParams}{SplatParams}(object) +} +\arguments{ +\item{object}{splatParams object to expand.} +} +\value{ +Expanded splatParams object. +} +\description{ +Expand the parameters that can be vectors so that they are the same length as +the number of groups. +} +\examples{ +\dontrun{ +params <- newSplatParams() +params <- setParams(params, groupCells = c(10, 10)) +params +params <- expandParams(params) +params +} +} + diff --git a/man/expandParams.Rd b/man/expandParams.Rd new file mode 100644 index 0000000..0d4c83b --- /dev/null +++ b/man/expandParams.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllGenerics.R +\name{expandParams} +\alias{expandParams} +\title{Expand parameters} +\usage{ +expandParams(object, ...) +} +\arguments{ +\item{object}{splatParams object to expand.} + +\item{...}{additional arguments.} +} +\value{ +Expanded splatParams object. +} +\description{ +Expand the parameters that can be vectors so that they are the same length as +the number of groups. +} +\examples{ +params <- newSplatParams() +params <- setParams(params, groupCells = c(10, 10)) +params +params <- expandParams(params) +params +} + diff --git a/man/newSplatParams.Rd b/man/newSplatParams.Rd new file mode 100644 index 0000000..9ce99b1 --- /dev/null +++ b/man/newSplatParams.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SplatParams-methods.R +\name{newSplatParams} +\alias{newSplatParams} +\title{New SplatParams} +\usage{ +newSplatParams(...) +} +\arguments{ +\item{...}{additional parameters passed to \code{\link{setParams}}.} +} +\value{ +SplatParams object. +} +\description{ +Create a new SplatParams object. +} +\examples{ +params <- newSplatParams() +} + diff --git a/man/setParam.Rd b/man/setParam.Rd index 564ef91..b2418db 100644 --- a/man/setParam.Rd +++ b/man/setParam.Rd @@ -1,14 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/AllGenerics.R, R/Params-methods.R +% Please edit documentation in R/AllGenerics.R, R/Params-methods.R, R/SplatParams-methods.R \docType{methods} \name{setParam} \alias{setParam} \alias{setParam,Params-method} +\alias{setParam,SplatParams-method} \title{Set a parameter} \usage{ -setParam(object, name, value) +setParam(object, name, value, checkValid) -\S4method{setParam}{Params}(object, name, value) +\S4method{setParam}{Params}(object, name, value, checkValid = TRUE) + +\S4method{setParam}{SplatParams}(object, name, value, checkValid) } \arguments{ \item{object}{object to set parameter in.} @@ -16,6 +19,8 @@ setParam(object, name, value) \item{name}{name of the parameter to set.} \item{value}{value to set the paramter to.} + +\item{checkValid}{logical. Check object is valid after setting.} } \value{ Object with new parameter value. diff --git a/man/setParams.Rd b/man/setParams.Rd index a3843db..05e8955 100644 --- a/man/setParams.Rd +++ b/man/setParams.Rd @@ -4,7 +4,7 @@ \alias{setParams} \title{Set parameters} \usage{ -setParams(params, update = NULL, ...) +setParams(params, update = NULL, checkValid = TRUE, ...) } \arguments{ \item{params}{Params object to set parameters in.} @@ -12,6 +12,8 @@ setParams(params, update = NULL, ...) \item{update}{list of parameters to set where \code{names(update)} are the names of the parameters to set and the items in the list are values.} +\item{checkValid}{logical. Whether to check set object is valid.} + \item{...}{additional parameters to set. These are combined with any parameters specified in \code{update}.} } diff --git a/tests/testthat/test-SplatParams.R b/tests/testthat/test-SplatParams.R new file mode 100644 index 0000000..e524067 --- /dev/null +++ b/tests/testthat/test-SplatParams.R @@ -0,0 +1,7 @@ +context("SplatParams") + +test_that("nGroups checks work", { + params <- newSplatParams() + expect_error(setParam(params, "nCells", 1), + "nCells cannot be set directly, set groupCells instead") +}) -- GitLab