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

Add zinbSimulate

parent bac0ecf8
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,7 @@ export(splatSimulateGroups)
export(splatSimulatePaths)
export(splatSimulateSingle)
export(summariseDiff)
export(zinbSimulate)
exportClasses(Lun2Params)
exportClasses(LunParams)
exportClasses(MFAParams)
......
#' ZINB-WaVE simulation
#'
#' Simulate counts using the ZINB-WaVE method.
#'
#' @param params ZINBParams object containing simulation parameters.
#' @param verbose logical. Whether to print progress messages
#' @param ... any additional parameter settings to override what is provided in
#' \code{params}.
#'
#' @details
#' This function is just a wrapper around \code{\link[zinbwave]{zinbSim}} that
#' takes a \code{\link{ZINBParams}}, runs the simulation then converts the
#' output to a \code{\link[SingleCellExperiment]{SingleCellExperiment}} object.
#' See \code{\link[zinbwave]{zinbSim}} and the ZINB-WaVE paper for
#' more details about how the simulation works.
#'
#' @return SingleCellExperiment containing simulated counts
#'
#' @references
#' Campbell K, Yau C. Uncovering genomic trajectories with heterogeneous genetic
#' and environmental backgrounds across single-cells and populations. bioRxiv
#' (2017).
#'
#' Risso D, Perraudeau F, Gribkova S, Dudoit S, Vert J-P. ZINB-WaVE: A general
#' and flexible method for signal extraction from single-cell RNA-seq data
#' bioRxiv (2017).
#'
#' Paper: \url{10.1101/125112}
#'
#' Code: \url{https://github.com/drisso/zinbwave}
#'
#' @examples
#' sim <- zinbSimulate()
#'
#' @export
#' @importFrom SingleCellExperiment SingleCellExperiment
zinbSimulate <- function(params = newZINBParams(), verbose = TRUE, ...) {
checkmate::assertClass(params, "ZINBParams")
params <- setParams(params, ...)
# Get the parameters we are going to use
nCells <- getParam(params, "nCells")
nGenes <- getParam(params, "nGenes")
model <- getParam(params, "model")
seed <- getParam(params, "seed")
if (verbose) {message("Simulating counts...")}
zinb.sim <- zinbwave::zinbSim(model, seed)
if (verbose) {message("Creating final dataset...")}
cell.names <- paste0("Cell", seq_len(nCells))
gene.names <- paste0("Gene", seq_len(nGenes))
for (item in c("counts", "dataNB", "dataDropouts")) {
rownames(zinb.sim[[item]]) <- gene.names
colnames(zinb.sim[[item]]) <- cell.names
}
cells <- data.frame(Cell = cell.names)
rownames(cells) <- cell.names
features <- data.frame(Gene = gene.names)
rownames(features) <- gene.names
sim <- SingleCellExperiment(assays = list(counts = zinb.sim$counts,
TrueCounts = zinb.sim$dataNB,
Dropouts = zinb.sim$dataDropouts),
rowData = features,
colData = cells,
metadata = list(params = params))
return(sim)
}
......@@ -22,7 +22,8 @@ The ZINB-WaVE simulation uses the following parameters:
The majority of the parameters for this simulation are stored in a
\code{\link[zinbwave]{ZinbModel}} object. Please refer to the documentation
for this class for details about all the parameters.
for this class and its constructor(\code{\link[zinbwave]{zinbModel}}) for
details about all the parameters.
The parameters not shown in brackets can be estimated from real data using
\code{\link{zinbEstimate}}. For details of the ZINB-WaVE simulation
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zinb-simulate.R
\name{zinbSimulate}
\alias{zinbSimulate}
\title{ZINB-WaVE simulation}
\usage{
zinbSimulate(params = newZINBParams(), verbose = TRUE, ...)
}
\arguments{
\item{params}{ZINBParams object containing simulation parameters.}
\item{verbose}{logical. Whether to print progress messages}
\item{...}{any additional parameter settings to override what is provided in
\code{params}.}
}
\value{
SingleCellExperiment containing simulated counts
}
\description{
Simulate counts using the ZINB-WaVE method.
}
\details{
This function is just a wrapper around \code{\link[zinbwave]{zinbSim}} that
takes a \code{\link{ZINBParams}}, runs the simulation then converts the
output to a \code{\link[SingleCellExperiment]{SingleCellExperiment}} object.
See \code{\link[zinbwave]{zinbSim}} and the ZINB-WaVE paper for
more details about how the simulation works.
}
\examples{
sim <- zinbSimulate()
}
\references{
Campbell K, Yau C. Uncovering genomic trajectories with heterogeneous genetic
and environmental backgrounds across single-cells and populations. bioRxiv
(2017).
Risso D, Perraudeau F, Gribkova S, Dudoit S, Vert J-P. ZINB-WaVE: A general
and flexible method for signal extraction from single-cell RNA-seq data
bioRxiv (2017).
Paper: \url{10.1101/125112}
Code: \url{https://github.com/drisso/zinbwave}
}
context("ZINB-WaVE simulation")
test_that("ZINB-WaVE simulation output is valid", {
expect_true(validObject(zinbSimulate()))
})
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