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

Add simPathDE function

Rename old function to include group
parent 2fb13ced
No related branches found
No related tags found
No related merge requests found
Package: splatter
Type: Package
Title: Simple Simulation of Single-cell RNA Sequencing Data
Version: 0.3.11
Version: 0.3.12
Date: 2016-10-10
Author: Luke Zappia
Authors@R: as.person(c(
......
......@@ -15,7 +15,8 @@
# set.seed
# group DE
# Min path length
# Path.from
#' FUNCTION TITLE
#'
......@@ -49,7 +50,11 @@ splat <- function(params = defaultParams(), method = c("groups", "paths"),
# Set up name vectors
cell.names <- paste0("Cell", 1:n.cells)
gene.names <- paste0("Gene", 1:n.genes)
group.names <- paste0("Group", 1:n.groups)
if (method == "groups") {
group.names <- paste0("Group", 1:n.groups)
} else if (method == "paths") {
group.names <- paste0("Path", 1:n.groups)
}
# Create SCESet with dummy counts to store simulation
dummy.counts <- matrix(1, ncol = n.cells, nrow = n.genes)
......@@ -71,11 +76,15 @@ splat <- function(params = defaultParams(), method = c("groups", "paths"),
sim <- simLibSizes(sim, params)
sim <- simGeneMeans(sim, params)
sim <- simDE(sim, params)
sim <- simGroupCellMeans(sim, params)
sim <- simBCVMeans(sim, params)
sim <- simTrueCounts(sim, params)
sim <- simDropout(sim, params)
if (method == "groups") {
sim <- simGroupDE(sim, params)
sim <- simGroupCellMeans(sim, params)
} else {
sim <- simPathDE(sim, params)
}
#sim <- simBCVMeans(sim, params)
#sim <- simTrueCounts(sim, params)
#im <- simDropout(sim, params)
# Create new SCESet to make sure values are calculated correctly
sce <- newSCESet(countData = counts(sim),
......@@ -129,7 +138,7 @@ simGeneMeans <- function(sim, params) {
return(sim)
}
simDE <- function(sim, params) {
simGroupDE <- function(sim, params) {
n.genes <- getParams(params, "nGenes")
de.prob <- getParams(params, "de.prob")
......@@ -150,6 +159,29 @@ simDE <- function(sim, params) {
return(sim)
}
simPathDE <- function(sim, params) {
n.genes <- getParams(params, "nGenes")
de.prob <- getParams(params, "de.prob")
de.downProb <- getParams(params, "de.downProb")
de.facLoc <- getParams(params, "de.facLoc")
de.facScale <- getParams(params, "de.facScale")
path.from <- getParams(params, "path.from")
means.gene <- fData(sim)$GeneMean
path.names <- unique(pData(sim)$Group)
path.order <- getPathOrder(path.from)
for (path.name in path.names[path.order]) {
de.facs <- getLNormFactors(n.genes, de.prob, de.downProb, de.facLoc,
de.facScale)
path.means.gene <- means.gene * de.facs
fData(sim)[[paste0("DEFac", path.name)]] <- de.facs
fData(sim)[[paste0("GeneMean", path.name)]] <- path.means.gene
}
return(sim)
}
simGroupCellMeans <- function(sim, params) {
cell.names <- pData(sim)$Cell
......@@ -287,4 +319,45 @@ getLNormFactors <- function(n.facs, sel.prob, neg.prob, fac.loc, fac.scale) {
factors[is.selected] <- facs.selected ^ dir.selected
return(factors)
}
#' Get path order
#'
#' 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
#' 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
path.pairs <- list()
for (idx in 1:length(path.from)) {
path.pairs[[idx]] <- c(path.from[idx], idx)
}
# Determine the processing order
# If a path is in the "done" vector any path originating here can be
# completed
done <- 0
while (length(path.pairs) > 0) {
path.pair <- path.pairs[[1]]
path.pairs <- path.pairs[-1]
from <- path.pair[1]
to <- path.pair[2]
if (from %in% done) {
done <- c(done, to)
} else {
path.pairs <- c(path.pairs, list(path.pair))
}
}
# Remove the origin from the vector
done <- done[-1]
return(done)
}
\ No newline at end of file
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate.R
\name{getPathOrder}
\alias{getPathOrder}
\title{Get path order}
\usage{
getPathOrder(path.from)
}
\arguments{
\item{path.from}{Vector giving the path endpoints that each path orginates
from.}
}
\value{
Vector giving the order to process paths in.
}
\description{
Identify the correct order to process paths so that preceding paths have
already been simulated.
}
\examples{
path.order <- getPathOrder(c(2, 0, 2))
}
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