From 5321991b45c07d5fc02dff68e1471dcc05207487 Mon Sep 17 00:00:00 2001
From: Luke Zappia <lazappi@users.noreply.github.com>
Date: Tue, 11 Oct 2016 15:29:49 +1100
Subject: [PATCH] Run checks

---
 DESCRIPTION                  |  7 +++---
 NAMESPACE                    | 10 ++++++++
 R/params.R                   | 10 +++++---
 R/simulate.R                 | 48 ++++++++++++++++++++++++++----------
 man/bridge.Rd                |  3 ---
 man/expandPathParams.Rd      |  2 ++
 man/getLNormFactors.Rd       |  3 ---
 man/getPathOrder.Rd          |  5 +---
 man/mergeParams.Rd           |  2 +-
 man/setParams.Rd             |  6 ++---
 man/simGroupCellMeans.Rd     |  2 +-
 man/splat.Rd                 |  6 ++---
 tests/testthat/test-params.R |  9 +++++++
 13 files changed, 75 insertions(+), 38 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index a678055..097d28d 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 e47878b..62bbb3a 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 4827230..bedefe1 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 e2b0c25..bc65ca2 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 d862c0b..4b7b8e9 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 129aba4..c029a89 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 4518ffd..9634fa2 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 e9f0217..f7f7bd1 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 b8b5f53..e8781ae 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 6b8f571..61a584c 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 a7937d1..8bc7c65 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 570cfd2..0a47ec9 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 5e2cf2b..7c37b8d 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),
-- 
GitLab