diff --git a/DESCRIPTION b/DESCRIPTION index a678055a1f0f2080b3cffd44dd2811c23fc58d1f..097d28dc8e4e397fb6b08685864f57aff3877419 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: splatter Type: Package Title: Simple Simulation of Single-cell RNA Sequencing Data -Version: 0.3.15 +Version: 0.3.16 Date: 2016-10-11 Author: Luke Zappia Authors@R: as.person(c( @@ -18,12 +18,13 @@ LazyData: TRUE Depends: R (>= 3.3), scater -Imports: limma, +Imports: fitdistrplus, edgeR, stats, locfit, - akima + akima, + Biobase Suggests: testthat biocViews: SingleCell, RNASeq, Transcriptomics, GeneExpression, Sequencing, diff --git a/NAMESPACE b/NAMESPACE index e47878bf43e458c66320e9416e8ec231c2b4b97b..62bbb3abd429f077fbeee3219aa633c7b7d8bba4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,6 +13,9 @@ export(splat) export(splatGroups) export(splatParams) export(splatPaths) +importFrom(Biobase,"assayData<-") +importFrom(Biobase,"fData<-") +importFrom(Biobase,"pData<-") importFrom(Biobase,assayData) importFrom(Biobase,fData) importFrom(Biobase,pData) @@ -21,3 +24,10 @@ importFrom(scater,newSCESet) importFrom(stats,dnbinom) importFrom(stats,median) importFrom(stats,nls) +importFrom(stats,rbinom) +importFrom(stats,rchisq) +importFrom(stats,rgamma) +importFrom(stats,rlnorm) +importFrom(stats,rnorm) +importFrom(stats,rpois) +importFrom(stats,runif) diff --git a/R/params.R b/R/params.R index 48272303314d1c6a4c2586254d363a5882a7bb62..bedefe1733fb75f6a0d418e98f1cdc6822f5ec5a 100644 --- a/R/params.R +++ b/R/params.R @@ -190,10 +190,10 @@ print.splatParams <- function(x, ...) { #' @examples #' params <- defaultParams() #' params -#' # Set nGenes and nCells -#' params <- setParams(params, nGenes = 1000, nCells = 200) +#' # Set nGenes +#' params <- setParams(params, nGenes = 1000) #' params -#' # Set mean rate paramater and library size location parameter +#' # Set mean rate parameter and library size location parameter #' params <- setParams(params, mean.rate = 1, lib.loc = 12) #' params #' @export @@ -418,7 +418,7 @@ checkParams <- function(params) { #' #' @return Merged splatParams object. #' @examples -#' params <- splatParams(nGenes = 1000, nCells = 50) +#' params <- splatParams(nGenes = 1000, mean.rate = 0.5) #' params #' # Replace unset parameters with default parameters #' params <- mergeParams(params, defaultParams()) @@ -477,11 +477,13 @@ defaultParams <- function() { #' #' @return expanded splatParams object. #' @examples +#' \dontrun{ #' params <- defaultParams() #' params <- setParams(params, groupCells = c(10, 10)) #' params #' params <- expandPathParams(params) #' params +#' } expandPathParams <- function(params) { n.groups <- getParams(params, "nGroups") diff --git a/R/simulate.R b/R/simulate.R index e2b0c25cf5ca0869eda62fe957d1ab24c6167639..bc65ca230c40da80a75404ca363ba80aede96271 100644 --- a/R/simulate.R +++ b/R/simulate.R @@ -94,16 +94,16 @@ #' @examples #' # Simulation with default parameters #' sim <- splat() -#' # Simulation with different number of cells -#' sim <- splat(nCells = 20) +#' # Simulation with different number of genes +#' sim <- splat(nGenes = 1000) #' # Simulation with custom parameters -#' params <- splatParams(nGenes = 100, nCells = 20, mean.rate = 0.5) +#' params <- splatParams(nGenes = 100, mean.rate = 0.5) #' sim <- splat(params) #' # Simulation with adjusted custom parameters #' sim <- splat(params, mean.rate = 0.6, out.prob = 0.2) #' # Simulate paths instead of groups #' sim <- splat(method = "paths") -#' @importFrom Biobase pData fData assayData +#' @importFrom Biobase fData pData pData<- assayData #' @importFrom scater newSCESet counts #' @export splat <- function(params = defaultParams(), method = c("groups", "paths"), @@ -200,6 +200,9 @@ splatPaths <- function(params = defaultParams(), verbose = TRUE, ...) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added library sizes. +#' +#' @importFrom Biobase pData pData<- +#' @importFrom stats rlnorm simLibSizes <- function(sim, params) { n.cells <- getParams(params, "nCells") @@ -221,6 +224,9 @@ simLibSizes <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added gene means. +#' +#' @importFrom Biobase fData fData<- +#' @importFrom stats rgamma simGeneMeans <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -256,6 +262,8 @@ simGeneMeans <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added differential expression. +#' +#' @importFrom Biobase fData pData simGroupDE <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -287,6 +295,8 @@ simGroupDE <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added differential expression. +#' +#' @importFrom Biobase fData pData simPathDE <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -324,7 +334,9 @@ simPathDE <- function(sim, params) { #' @param sim SCESet to add cell means to. #' @param params splatParams object with simulation parameters. #' -#' @return SCESet with added cell means/. +#' @return SCESet with added cell means. +#' +#' @importFrom Biobase fData pData assayData assayData<- simGroupCellMeans <- function(sim, params) { n.groups <- getParams(params, "nGroups") @@ -361,6 +373,9 @@ simGroupCellMeans <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added cell means. +#' +#' @importFrom Biobase fData pData assayData +#' @importFrom stats rbinom simPathCellMeans <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -443,6 +458,9 @@ simPathCellMeans <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added BCV means. +#' +#' @importFrom Biobase fData pData assayData assayData<- +#' @importFrom stats rchisq rgamma simBCVMeans <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -481,6 +499,9 @@ simBCVMeans <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added true counts. +#' +#' @importFrom Biobase fData pData assayData +#' @importFrom stats rpois simTrueCounts <- function(sim, params) { n.genes <- getParams(params, "nGenes") @@ -511,6 +532,9 @@ simTrueCounts <- function(sim, params) { #' @param params splatParams object with simulation parameters. #' #' @return SCESet with added dropout and observed counts. +#' +#' @importFrom Biobase fData pData assayData assayData<- +#' @importFrom stats rbinom simDropout <- function(sim, params) { dropout.present <- getParams(params, "dropout.present") @@ -551,7 +575,7 @@ simDropout <- function(sim, params) { counts <- true.counts } - counts(sim) <- counts + scater::counts(sim) <- counts return(sim) } @@ -568,8 +592,8 @@ simDropout <- function(sim, params) { #' @param fac.scale Scale factor for the log-normal distribution. #' #' @return Vector containing generated factors. -#' @examples -#' factors <- getLNormFactors(100, 0.5, 0.5, 4, 1) +#' +#' @importFrom stats rbinom rlnorm getLNormFactors <- function(n.facs, sel.prob, neg.prob, fac.loc, fac.scale) { is.selected <- as.logical(rbinom(n.facs, 1, sel.prob)) @@ -590,12 +614,10 @@ getLNormFactors <- function(n.facs, sel.prob, neg.prob, fac.loc, fac.scale) { #' Identify the correct order to process paths so that preceding paths have #' already been simulated. #' -#' @param path.from Vector giving the path endpoints that each path orginates +#' @param path.from vector giving the path endpoints that each path orginates #' from. #' #' @return Vector giving the order to process paths in. -#' @examples -#' path.order <- getPathOrder(c(2, 0, 2)) getPathOrder <- function(path.from) { # Transform the vector into a list of (from, to) pairs @@ -638,8 +660,8 @@ getPathOrder <- function(path.from) { #' @param sigma.fac multiplier specifying how extreme each step can be. #' #' @return Vector of length n following a path from x to y. -#' @examples -#' b <- bridge(10, 20) +#' +#' @importFrom stats runif rnorm bridge <- function (x = 0, y = 0, N = 5, n = 100, sigma.fac = 0.8) { dt <- 1 / (N - 1) diff --git a/man/bridge.Rd b/man/bridge.Rd index d862c0b1227724dde1339ca69a8003143945b55f..4b7b8e9ee8ec3d614f542bc187df357b6ae900c9 100644 --- a/man/bridge.Rd +++ b/man/bridge.Rd @@ -24,7 +24,4 @@ Vector of length n following a path from x to y. Calculate a smoothed Brownian bridge between two points. A Brownian bridge is a random walk with fixed end points. } -\examples{ -b <- bridge(10, 20) -} diff --git a/man/expandPathParams.Rd b/man/expandPathParams.Rd index 129aba400786d31be1b9534ce40b5962f68ee88b..c029a897708469db17c3ad91b8d2f8028c8a480b 100644 --- a/man/expandPathParams.Rd +++ b/man/expandPathParams.Rd @@ -17,10 +17,12 @@ Expand the path parameters so that they are the same length as the number of groups. } \examples{ +\dontrun{ params <- defaultParams() params <- setParams(params, groupCells = c(10, 10)) params params <- expandPathParams(params) params } +} diff --git a/man/getLNormFactors.Rd b/man/getLNormFactors.Rd index 4518ffd286bee5afe2b850e32f37785c36064d76..9634fa29250fea9930932f4e531a14171c47d259 100644 --- a/man/getLNormFactors.Rd +++ b/man/getLNormFactors.Rd @@ -24,7 +24,4 @@ Vector containing generated factors. \description{ Randomly generate multiplication factors from a log-normal distribution. } -\examples{ -factors <- getLNormFactors(100, 0.5, 0.5, 4, 1) -} diff --git a/man/getPathOrder.Rd b/man/getPathOrder.Rd index e9f0217a99539f8e53b2571b73088cfdd868c778..f7f7bd1ab2ed6c7d70046d2f2d9dc2af288cea2d 100644 --- a/man/getPathOrder.Rd +++ b/man/getPathOrder.Rd @@ -7,7 +7,7 @@ getPathOrder(path.from) } \arguments{ -\item{path.from}{Vector giving the path endpoints that each path orginates +\item{path.from}{vector giving the path endpoints that each path orginates from.} } \value{ @@ -17,7 +17,4 @@ Vector giving the order to process paths in. Identify the correct order to process paths so that preceding paths have already been simulated. } -\examples{ -path.order <- getPathOrder(c(2, 0, 2)) -} diff --git a/man/mergeParams.Rd b/man/mergeParams.Rd index b8b5f53e2665e30bc587be9b14fc4f1dad439cab..e8781ae9dca63decb0594d94b60d4413eaf0fe10 100644 --- a/man/mergeParams.Rd +++ b/man/mergeParams.Rd @@ -20,7 +20,7 @@ splatParams object are replaced by the value in the second splatParams object. } \examples{ -params <- splatParams(nGenes = 1000, nCells = 50) +params <- splatParams(nGenes = 1000, mean.rate = 0.5) params # Replace unset parameters with default parameters params <- mergeParams(params, defaultParams()) diff --git a/man/setParams.Rd b/man/setParams.Rd index 6b8f57169a7d99a9123c5ec543fbef3fa16c7b95..61a584cf6fb49064da9933fb5769b96f3f2ba3b4 100644 --- a/man/setParams.Rd +++ b/man/setParams.Rd @@ -30,10 +30,10 @@ parameters and the splatParams data structure see \code{\link{splatParams}}. \examples{ params <- defaultParams() params -# Set nGenes and nCells -params <- setParams(params, nGenes = 1000, nCells = 200) +# Set nGenes +params <- setParams(params, nGenes = 1000) params -# Set mean rate paramater and library size location parameter +# Set mean rate parameter and library size location parameter params <- setParams(params, mean.rate = 1, lib.loc = 12) params } diff --git a/man/simGroupCellMeans.Rd b/man/simGroupCellMeans.Rd index a7937d1d93d200eb9b8c576eeae9c550adce76cf..8bc7c65718cbce8d109461982a22d7be779fc418 100644 --- a/man/simGroupCellMeans.Rd +++ b/man/simGroupCellMeans.Rd @@ -12,7 +12,7 @@ simGroupCellMeans(sim, params) \item{params}{splatParams object with simulation parameters.} } \value{ -SCESet with added cell means/. +SCESet with added cell means. } \description{ Simulate a gene by cell matrix giving the mean expression for each gene in diff --git a/man/splat.Rd b/man/splat.Rd index 570cfd2162033bbf1ee7fc9976a6de2cb6a4535c..0a47ec96d7b5b27f397148a69277f065e097154a 100644 --- a/man/splat.Rd +++ b/man/splat.Rd @@ -103,10 +103,10 @@ information includes: \examples{ # Simulation with default parameters sim <- splat() -# Simulation with different number of cells -sim <- splat(nCells = 20) +# Simulation with different number of genes +sim <- splat(nGenes = 1000) # Simulation with custom parameters -params <- splatParams(nGenes = 100, nCells = 20, mean.rate = 0.5) +params <- splatParams(nGenes = 100, mean.rate = 0.5) sim <- splat(params) # Simulation with adjusted custom parameters sim <- splat(params, mean.rate = 0.6, out.prob = 0.2) diff --git a/tests/testthat/test-params.R b/tests/testthat/test-params.R index 5e2cf2b18eaf70c73449e497c368d7c33d4dca7c..7c37b8d308c8eb980b7a9855b8bc31c381630dd8 100644 --- a/tests/testthat/test-params.R +++ b/tests/testthat/test-params.R @@ -135,6 +135,15 @@ test_that("setParams sets correctly", { expect_equal(params$dropout$present, TRUE) }) +test_that("setParams sets groupCells correctly", { + params <- splatParams() + expect_error(setParams(params, nCells = 50), + "nCells cannot be set directly, set groupCells instead") + expect_error(setParams(params, nGroups = 5), + "nGroups cannot be set directly, set groupCells instead") + expect_silent(setParams(params, groupCells = c(10, 10))) +}) + test_that("setParmas sets groupCells correctly", { params <- splatParams() expect_error(setParams(params, nCells = 100),