Skip to content
Snippets Groups Projects
Commit 7fcd183c authored by Luke Zappia's avatar Luke Zappia
Browse files

Update SplatParams

* Add batch parameters
* Replace groupCells with group.prob
parent 5ce7d916
No related branches found
No related tags found
No related merge requests found
......@@ -72,9 +72,17 @@ setClass("SimpleParams",
#' \describe{
#' \item{\code{nGenes}}{The number of genes to simulate.}
#' \item{\code{nCells}}{The number of cells to simulate.}
#' \item{\code{[nGroups]}}{The number of groups or paths to simulate.}
#' \item{\code{[groupCells]}}{Vector giving the number of cells in each
#' simulation group/path.}
#' \item{\emph{Batch parameters}}{
#' \describe{
#' \item{\code{[nBatches]}}{The number of batches to simulate.}
#' \item{\code{[batchCells]}}{Vector giving the number of cells in
#' each batch.}
#' \item{\code{[batch.facLoc]}}{Location (meanlog) parameter for the
#' batch effect factor log-normal distribution. Can be a vector.}
#' \item{\code{[batch.facScale]}}{Scale (sdlog) parameter for the
#' batch effect factor log-normal distribution. Can be a vector.}
#' }
#' }
#' \item{\code{[seed]}}{Seed to use for generating random numbers.}
#' \item{\emph{Mean parameters}}{
#' \describe{
......@@ -102,6 +110,14 @@ setClass("SimpleParams",
#' expression outlier factor log-normal distribution.}
#' }
#' }
#' \item{\emph{Group parameters}}{
#' \describe{
#' \item{\code{[nGroups]}}{The number of groups or paths to
#' simulate.}
#' \item{\code{[group.prob]}}{Probability that a cell comes from a
#' group.}
#' }
#' }
#' \item{\emph{Differential expression parameters}}{
#' \describe{
#' \item{\code{[de.prob]}}{Probability that a gene is differentially
......@@ -173,8 +189,10 @@ setClass("SimpleParams",
#' @exportClass SplatParams
setClass("SplatParams",
contains = "Params",
slots = c(nGroups = "numeric",
groupCells = "numeric",
slots = c(nBatches = "numeric",
batchCells = "numeric",
batch.facLoc = "numeric",
batch.facScale = "numeric",
mean.shape = "numeric",
mean.rate = "numeric",
lib.loc = "numeric",
......@@ -182,6 +200,8 @@ setClass("SplatParams",
out.prob = "numeric",
out.facLoc = "numeric",
out.facScale = "numeric",
nGroups = "numeric",
group.prob = "numeric",
de.prob = "numeric",
de.downProb = "numeric",
de.facLoc = "numeric",
......@@ -196,8 +216,10 @@ setClass("SplatParams",
path.skew = "numeric",
path.nonlinearProb = "numeric",
path.sigmaFac = "numeric"),
prototype = prototype(nGroups = 1,
groupCells = 100,
prototype = prototype(nBatches = 1,
batchCells = 100,
batch.facLoc = 0,
batch.facScale = 0,
mean.rate = 0.3,
mean.shape = 0.6,
lib.loc = 11,
......@@ -205,6 +227,8 @@ setClass("SplatParams",
out.prob = 0.05,
out.facLoc = 4,
out.facScale = 0.5,
nGroups = 1,
group.prob = 1,
de.prob = 0.1,
de.downProb = 0.5,
de.facLoc = 0.1,
......
......@@ -16,12 +16,16 @@ setValidity("SplatParams", function(object) {
object <- expandParams(object)
v <- getParams(object, c(slotNames(object)))
nBatches <- v$nBatches
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),
nBatches = checkInt(v$nBatches, lower = 1),
batchCells = checkIntegerish(v$batchCells, lower = 1,
len = nBatches),
batch.facLoc = checkNumeric(v$batch.facLoc, len = nBatches),
batch.facScale = checkNumeric(v$batch.facScale, lower = 0,
len = nBatches),
mean.rate = checkNumber(v$mean.rate, lower = 0),
mean.shape = checkNumber(v$mean.shape, lower = 0),
lib.loc = checkNumber(v$lib.loc),
......@@ -29,6 +33,9 @@ setValidity("SplatParams", function(object) {
out.prob = checkNumber(v$out.prob, lower = 0, upper = 1),
out.facLoc = checkNumber(v$out.facLoc),
out.facScale = checkNumber(v$out.facScale, lower = 0),
nGroups = checkInt(v$nGroups, lower = 1),
group.prob = checkNumeric(v$de.prob, lower = 0, upper = 1,
len = nGroups),
de.prob = checkNumeric(v$de.prob, lower = 0, upper = 1,
len = nGroups),
de.downProb = checkNumeric(v$de.downProb, lower = 0, upper = 1,
......@@ -52,10 +59,15 @@ setValidity("SplatParams", function(object) {
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)) {
# Check batchCells matches nCells, nBatches
if (v$nCells != sum(v$batchCells) || nBatches != length(v$batchCells)) {
checks <- c(checks,
"nCells, nGroups and groupCells are not consistent")
"nCells, nBatches and batchesCells are not consistent")
}
# Check group.prob sums to 1
if (sum(v$group.prob) != 1) {
checks <- c(checks, "group.probs must sum to 1")
}
# Check path.from
......@@ -79,12 +91,20 @@ setValidity("SplatParams", function(object) {
setMethod("setParam", "SplatParams",function(object, name, value) {
checkmate::assertString(name)
if (name == "nCells" || name == "nGroups") {
stop(name, " cannot be set directly, set groupCells instead")
if (name == "nCells" || name == "nBatches") {
stop(name, " cannot be set directly, set batchCells instead")
}
if (name == "nGroups") {
stop(name, " cannot be set directly, set group.prob instead")
}
if (name == "groupCells") {
if (name == "batchCells") {
object <- setParamUnchecked(object, "nCells", sum(value))
object <- setParamUnchecked(object, "nBatches", length(value))
}
if (name == "group.prob") {
object <- setParamUnchecked(object, "nGroups", length(value))
}
......@@ -96,8 +116,10 @@ setMethod("setParam", "SplatParams",function(object, name, value) {
#' @importFrom methods callNextMethod
setMethod("show", "SplatParams", function(object) {
pp <- list("Groups:" = c("[Groups]" = "nGroups",
"[Group Cells]" = "groupCells"),
pp <- list("Batches:" = c("[Batches]" = "nBatches",
"[Batch Cells]" = "batchCells",
"[Location]" = "batch.facLoc",
"[Scale]" = "batch.facScale"),
"Mean:" = c("(Rate)" = "mean.rate",
"(Shape)" = "mean.shape"),
"Library size:" = c("(Location)" = "lib.loc",
......@@ -105,6 +127,8 @@ setMethod("show", "SplatParams", function(object) {
"Exprs outliers:" = c("(Probability)" = "out.prob",
"(Location)" = "out.facLoc",
"(Scale)" = "out.facScale"),
"Groups:" = c("[Groups]" = "nGroups",
"[Group Probs]" = "group.prob"),
"Diff expr:" = c("[Probability]" = "de.prob",
"[Down Prob]" = "de.downProb",
"[Location]" = "de.facLoc",
......@@ -127,6 +151,12 @@ setMethod("show", "SplatParams", function(object) {
#' @rdname expandParams
setMethod("expandParams", "SplatParams", function(object) {
n <- getParam(object, "nBatches")
vectors <- c("batch.facLoc", "batch.facScale")
object <- callNextMethod(object, vectors, n)
n <- getParam(object, "nGroups")
vectors <- c("de.prob", "de.downProb", "de.facLoc", "de.facScale",
......
......@@ -16,9 +16,17 @@ 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{[nGroups]}}{The number of groups or paths to simulate.}
\item{\code{[groupCells]}}{Vector giving the number of cells in each
simulation group/path.}
\item{\emph{Batch parameters}}{
\describe{
\item{\code{[nBatches]}}{The number of batches to simulate.}
\item{\code{[batchCells]}}{Vector giving the number of cells in
each batch.}
\item{\code{[batch.facLoc]}}{Location (meanlog) parameter for the
batch effect factor log-normal distribution. Can be a vector.}
\item{\code{[batch.facScale]}}{Scale (sdlog) parameter for the
batch effect factor log-normal distribution. Can be a vector.}
}
}
\item{\code{[seed]}}{Seed to use for generating random numbers.}
\item{\emph{Mean parameters}}{
\describe{
......@@ -46,6 +54,14 @@ The Splatter simulation requires the following parameters:
expression outlier factor log-normal distribution.}
}
}
\item{\emph{Group parameters}}{
\describe{
\item{\code{[nGroups]}}{The number of groups or paths to
simulate.}
\item{\code{[group.prob]}}{Probability that a cell comes from a
group.}
}
}
\item{\emph{Differential expression parameters}}{
\describe{
\item{\code{[de.prob]}}{Probability that a gene is differentially
......
context("SplatParams")
test_that("nGroups checks work", {
test_that("nBatches checks work", {
params <- newSplatParams()
expect_error(setParam(params, "nCells", 1),
"nCells cannot be set directly, set groupCells instead")
expect_error(setParam(params, "nGroups", 1),
"nGroups cannot be set directly, set groupCells instead")
"nCells cannot be set directly, set batchCells instead")
expect_error(setParam(params, "nBatches", 1),
"nBatches cannot be set directly, set batchCells instead")
})
test_that("nGroups checks work", {
params <- newSplatParams()
expect_error(setParam(params, "nGroups", 1),
"nGroups cannot be set directly, set group.prob instead")
})
test_that("path.from checks work", {
params <- newSplatParams()
params <- setParams(params, groupCells = c(10, 10))
params <- setParams(params, group.prob = c(0.5, 0.5))
params <- setParamUnchecked(params, "path.from", c(0, 1))
expect_silent(validObject(params))
params <- setParamUnchecked(params, "path.from", c(0, 3))
expect_error(validObject(params),
paste('invalid class "SplatParams" object: path.from:',
paste('invalid class SplatParams object: path.from:',
"All elements must be <= 2"))
params <- setParamUnchecked(params, "path.from", c(1, 0))
expect_error(validObject(params), "path cannot begin at itself")
params <- newSplatParams()
params <- setParams(params, groupCells = c(10, 10, 10))
params <- setParams(params, group.prob = c(0.3, 0.3, 0.4))
params <- setParamUnchecked(params, "path.from", c(2, 1, 1))
expect_error(validObject(params), "origin must be specified in path.from")
})
\ No newline at end of file
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment