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

Add phenoSimulate

parent aae77a9c
No related branches found
No related tags found
No related merge requests found
...@@ -31,9 +31,11 @@ export(mfaSimulate) ...@@ -31,9 +31,11 @@ export(mfaSimulate)
export(newLun2Params) export(newLun2Params)
export(newLunParams) export(newLunParams)
export(newMFAParams) export(newMFAParams)
export(newPhenoParams)
export(newSCDDParams) export(newSCDDParams)
export(newSimpleParams) export(newSimpleParams)
export(newSplatParams) export(newSplatParams)
export(phenoSimulate)
export(scDDEstimate) export(scDDEstimate)
export(scDDSimulate) export(scDDSimulate)
export(setParam) export(setParam)
...@@ -49,6 +51,7 @@ export(summariseDiff) ...@@ -49,6 +51,7 @@ export(summariseDiff)
exportClasses(Lun2Params) exportClasses(Lun2Params)
exportClasses(LunParams) exportClasses(LunParams)
exportClasses(MFAParams) exportClasses(MFAParams)
exportClasses(PhenoParams)
exportClasses(SCDDParams) exportClasses(SCDDParams)
exportClasses(SimpleParams) exportClasses(SimpleParams)
exportClasses(SplatParams) exportClasses(SplatParams)
......
#' PhenoPath simulation
#'
#' Simulate counts from a pseudotime trajectory using the PhenoPath method.
#'
#' @param params PhenoParams 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[phenopath]{simulate_phenopath}} that takes a
#' \code{\link{PhenoParams}}, runs the simulation then converts the
#' output to a \code{\link[SingleCellExperiment]{SingleCellExperiment}} object.
#' See \code{\link[phenopath]{simulate_phenopath}} and the PhenoPath 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).
#'
#' Paper: \url{10.1101/159913}
#'
#' Code: \url{https://github.com/kieranrcampbell/phenopath}
#'
#' @examples
#' sim <- phenoSimulate()
#'
#' @export
#' @importFrom SingleCellExperiment SingleCellExperiment
phenoSimulate <- function(params = newPhenoParams(), verbose = TRUE, ...) {
checkmate::assertClass(params, "PhenoParams")
params <- setParams(params, ...)
# Set random seed
seed <- getParam(params, "seed")
set.seed(seed)
# Get the parameters we are going to use
nCells <- getParam(params, "nCells")
nGenes <- getParam(params, "nGenes")
n.de <- getParam(params, "n.de")
n.pst <- getParam(params, "n.pst")
n.pst.beta <- getParam(params, "n.pst.beta")
n.de.pst.beta <- getParam(params, "n.de.pst.beta")
if (verbose) {message("Simulating counts...")}
pheno.sim <- phenopath::simulate_phenopath(N = nCells,
G_de = n.de,
G_pst = n.pst,
G_pst_beta = n.pst.beta,
G_de_pst_beta = n.de.pst.beta)
if (verbose) {message("Creating final dataset...")}
cell.names <- paste0("Cell", seq_len(nCells))
gene.names <- paste0("Gene", seq_len(nGenes))
counts <- t(pheno.sim$y)
rownames(counts) <- gene.names
colnames(counts) <- cell.names
cells <- data.frame(Cell = cell.names,
Covariate = pheno.sim$x,
Pseudotime = pheno.sim$z)
rownames(cells) <- cell.names
features <- data.frame(Gene = gene.names,
Alpha = pheno.sim$parameters$alpha,
Lambda = pheno.sim$parameters$lambda,
Beta = pheno.sim$parameters$beta,
Regime = pheno.sim$parameters$regime)
rownames(features) <- gene.names
sim <- SingleCellExperiment(assays = list(counts = counts),
rowData = features,
colData = cells,
metadata = list(params = params))
return(sim)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/AllClasses.R
\docType{class}
\name{PhenoParams}
\alias{PhenoParams}
\alias{PhenoParams-class}
\title{The PhenoParams class}
\description{
S4 class that holds parameters for the PhenoPath simulation.
}
\section{Parameters}{
The PhenoPath 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{[n.de]}}{Number of genes to simulate from the differential
expression regime}
\item{\code{[n.pst]}}{Number of genes to simulate from the pseudotime
regime}
\item{\code{[n.pst.beta]}}{Number of genes to simulate from the
pseudotime + beta interactions regime}
\item{\code{[n.de.pst.beta]}}{Number of genes to simulate from the
differential expression + pseudotime + interactions regime}
}
The parameters not shown in brackets can be estimated from real data using
\code{\link{phenoEstimate}}. For details of the PhenoPath simulation
see \code{\link{phenoSimulate}}.
}
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/AllGenerics.R, R/Lun2Params-methods.R, % Please edit documentation in R/AllGenerics.R, R/Lun2Params-methods.R,
% R/LunParams-methods.R, R/MFAParams-methods.R, R/SCDDParams-methods.R, % R/LunParams-methods.R, R/MFAParams-methods.R, R/PhenoParams-methods.R,
% R/SimpleParams-methods.R, R/SplatParams-methods.R % R/SCDDParams-methods.R, R/SimpleParams-methods.R, R/SplatParams-methods.R
\name{newParams} \name{newParams}
\alias{newParams} \alias{newParams}
\alias{newLun2Params} \alias{newLun2Params}
\alias{newLunParams} \alias{newLunParams}
\alias{newMFAParams} \alias{newMFAParams}
\alias{newPhenoParams}
\alias{newSCDDParams} \alias{newSCDDParams}
\alias{newSimpleParams} \alias{newSimpleParams}
\alias{newSplatParams} \alias{newSplatParams}
...@@ -18,6 +19,8 @@ newLunParams(...) ...@@ -18,6 +19,8 @@ newLunParams(...)
newMFAParams(...) newMFAParams(...)
newPhenoParams(...)
newSCDDParams(...) newSCDDParams(...)
newSimpleParams(...) newSimpleParams(...)
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pheno-simulate.R
\name{phenoSimulate}
\alias{phenoSimulate}
\title{PhenoPath simulation}
\usage{
phenoSimulate(params = newPhenoParams(), verbose = TRUE, ...)
}
\arguments{
\item{params}{PhenoParams 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 from a pseudotime trajectory using the PhenoPath method.
}
\details{
This function is just a wrapper around
\code{\link[phenopath]{simulate_phenopath}} that takes a
\code{\link{PhenoParams}}, runs the simulation then converts the
output to a \code{\link[SingleCellExperiment]{SingleCellExperiment}} object.
See \code{\link[phenopath]{simulate_phenopath}} and the PhenoPath paper for
more details about how the simulation works.
}
\examples{
sim <- phenoSimulate()
}
\references{
Campbell K, Yau C. Uncovering genomic trajectories with heterogeneous genetic
and environmental backgrounds across single-cells and populations. bioRxiv
(2017).
Paper: \url{10.1101/159913}
Code: \url{https://github.com/kieranrcampbell/phenopath}
}
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/AllGenerics.R, R/Lun2Params-methods.R, % Please edit documentation in R/AllGenerics.R, R/Lun2Params-methods.R,
% R/LunParams-methods.R, R/Params-methods.R, R/SCDDParams-methods.R, % R/LunParams-methods.R, R/Params-methods.R, R/PhenoParams-methods.R,
% R/SplatParams-methods.R % R/SCDDParams-methods.R, R/SplatParams-methods.R
\docType{methods} \docType{methods}
\name{setParam} \name{setParam}
\alias{setParam} \alias{setParam}
\alias{setParam,Lun2Params-method} \alias{setParam,Lun2Params-method}
\alias{setParam,LunParams-method} \alias{setParam,LunParams-method}
\alias{setParam,Params-method} \alias{setParam,Params-method}
\alias{setParam,PhenoParams-method}
\alias{setParam,SCDDParams-method} \alias{setParam,SCDDParams-method}
\alias{setParam,SplatParams-method} \alias{setParam,SplatParams-method}
\title{Set a parameter} \title{Set a parameter}
...@@ -20,6 +21,8 @@ setParam(object, name, value) ...@@ -20,6 +21,8 @@ setParam(object, name, value)
\S4method{setParam}{Params}(object, name, value) \S4method{setParam}{Params}(object, name, value)
\S4method{setParam}{PhenoParams}(object, name, value)
\S4method{setParam}{SCDDParams}(object, name, value) \S4method{setParam}{SCDDParams}(object, name, value)
\S4method{setParam}{SplatParams}(object, name, value) \S4method{setParam}{SplatParams}(object, name, value)
......
context("PhenoPath simulation")
test_that("PhenoPath simulation output is valid", {
expect_true(validObject(phenoSimulate()))
})
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