diff --git a/DESCRIPTION b/DESCRIPTION index af95dd9d2ba8e5d67a90d581d1e4384005b7d3aa..8cd17135922a9d51ed49ac8190d8231a18dcd76e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: splatter Type: Package Title: Simple Simulation of Single-cell RNA Sequencing Data -Version: 1.9.2 -Date: 2019-06-13 +Version: 1.9.2.9000 +Date: 2019-07-11 Author: Luke Zappia Authors@R: c(person("Luke", "Zappia", role = c("aut", "cre"), @@ -62,7 +62,8 @@ Suggests: zinbwave, SparseDC, BiocManager, - spelling + spelling, + igraph biocViews: SingleCell, RNASeq, Transcriptomics, GeneExpression, Sequencing, Software, ImmunoOncology URL: https://github.com/Oshlack/splatter diff --git a/NEWS.md b/NEWS.md index ea91789687390d3b095759333f41bec82069c81a..d932de8f2d0d102d129216cb1e1cb12dfe0cba36 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +### Version 1.9.2.9000 (2019-07-11) + +* Add SplotchParams object + ## Version 1.9.2 (2019-06-13) * Add variable gene correlation plot to compareSCEs diff --git a/R/AllClasses.R b/R/AllClasses.R index 1da947a4586fee93e38cf7b87ae43d95ec4c86ed..a251d3f76d61bf0cea9354f270d713bb028e9ec5 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -63,11 +63,11 @@ setClass("SimpleParams", #' The SplatParams class #' -#' S4 class that holds parameters for the Splatter simulation. +#' S4 class that holds parameters for the Splat simulation. #' #' @section Parameters: #' -#' The Splatter simulation requires the following parameters: +#' The Splat simulation requires the following parameters: #' #' \describe{ #' \item{\code{nGenes}}{The number of genes to simulate.} @@ -189,7 +189,7 @@ setClass("SimpleParams", #' } #' #' The parameters not shown in brackets can be estimated from real data using -#' \code{\link{splatEstimate}}. For details of the Splatter simulation +#' \code{\link{splatEstimate}}. For details of the Splat simulation #' see \code{\link{splatSimulate}}. #' #' @name SplatParams @@ -255,6 +255,37 @@ setClass("SplatParams", path.nonlinearProb = 0.1, path.sigmaFac = 0.8)) +#' The SplotchParams class +#' +#' S4 class that holds parameters for the Splotch simulation. +#' +#' @section Parameters: +#' +#' The Splotch 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{[network.graph]}}{Graph containing the gene network.} +#' \item{\code{[network.nRegs]}}{Number of regulators in a the network.} +#' } +#' +#' The parameters not shown in brackets can be estimated from real data using +#' \code{\link{splotchEstimate}}. For details of the Splotch simulation +#' see \code{\link{splotchSimulate}}. +#' +#' @name SplotchParams +#' @rdname SplotchParams +#' @aliases SplotchParams-class +#' @exportClass SplotchParams +setClass("SplotchParams", + contains = "Params", + slots = c(network.graph = "ANY", + network.nRegs = "numeric"), + prototype = prototype(network.graph = NULL, + network.nRegs = 100)) + #' The LunParams class #' #' S4 class that holds parameters for the Lun simulation. diff --git a/R/SplotchParams-methods.R b/R/SplotchParams-methods.R new file mode 100644 index 0000000000000000000000000000000000000000..b5373f12cf5e9ec694348d4559c44789c958772a --- /dev/null +++ b/R/SplotchParams-methods.R @@ -0,0 +1,66 @@ +#' @rdname newParams +#' @importFrom methods new +#' @export +newSplotchParams <- function(...) { + + if (!requireNamespace("igraph", quietly = TRUE)) { + stop("The Splotch simulation requires the 'igraph' package.") + } + + params <- new("SplotchParams") + params <- setParams(params, ...) + + return(params) +} + +setValidity("SplotchParams", function(object) { + + v <- getParams(object, slotNames(object)) + + checks <- c(nGenes = checkmate::checkInt(v$nGenes, lower = 1), + nCells = checkmate::checkInt(v$nCells, lower = 1), + seed = checkmate::checkInt(v$seed, lower = 0), + network.graph = checkmate::checkClass(v$network, "igraph", + null.ok = TRUE), + network.nRegs = checkmate::checkInt(v$network.nRegs, + lower = 0)) + + if (all(checks == TRUE)) { + valid <- TRUE + } else { + valid <- checks[checks != TRUE] + valid <- paste(names(valid), valid, sep = ": ") + } + + return(valid) +}) + +setMethod("show", "SplotchParams", function(object) { + + pp.network <- list("Network:" = c("[Graph]" = "network.graph", + "[nRegs]" = "network.nRegs")) + + callNextMethod() + + network.graph <- getParam(object, "network.graph") + if (is.null(network.graph)) { + showPP(object, pp.network) + } else { + cat(crayon::bold("Network:"), "\n") + cat(crayon::bold(crayon::blue("[GRAPH]\n"))) + cat(crayon::bold(crayon::green(paste( + "Graph with", igraph::gorder(network.graph), "nodes and", + igraph::gsize(network.graph), "edges\n" + )))) + show(network.graph) + network.nRegs <- getParam(object, "network.nRegs") + names(network.nRegs) <- c("[nRegs]") + if (network.nRegs == 100) { + showValues(network.nRegs, FALSE) + } else { + showValues(network.nRegs, TRUE) + } + } + + # showPP(object, pp) +}) diff --git a/R/params-functions.R b/R/params-functions.R index cfdb02c4a37f676c12131bfa7f2601c37c3709b6..316c15a61cecdff07e2591cf9c145782d84c9215 100644 --- a/R/params-functions.R +++ b/R/params-functions.R @@ -76,6 +76,8 @@ showPP <- function(params, pp) { not.default <- sapply(seq_along(values), function(i) { !identical(values[i], default.values[i]) }) + null.values <- sapply(values, is.null) + values[null.values] <- "Not set" cat(crayon::bold(category), "\n") if (sum(!is.df) > 0) { @@ -88,9 +90,9 @@ showPP <- function(params, pp) { } } -#' Show vales +#' Show values #' -#' Function used for pretty printing scale or vector parameters. +#' Function used for pretty printing scalar or vector parameters. #' #' @param values list of values to show. #' @param not.default logical vector giving which have changed from the default. diff --git a/man/SplotchParams.Rd b/man/SplotchParams.Rd new file mode 100644 index 0000000000000000000000000000000000000000..e851d290727adda37e18b8a53f586d855e3ffaf4 --- /dev/null +++ b/man/SplotchParams.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllClasses.R +\docType{class} +\name{SplotchParams} +\alias{SplotchParams} +\alias{SplotchParams-class} +\title{The SplotchParams class} +\description{ +S4 class that holds parameters for the Splotch simulation. +} +\section{Parameters}{ + + +The Splotch 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{[network.graph]}}{Graph containing the gene network.} + \item{\code{[network.nRegs]}}{Number of regulators in a the network.} +} + +The parameters not shown in brackets can be estimated from real data using +\code{\link{splotchEstimate}}. For details of the Splotch simulation +see \code{\link{splotchSimulate}}. +} +