Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 158 #161

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: splatter
Type: Package
Title: Simple Simulation of Single-cell RNA Sequencing Data
Version: 1.23.0
Date: 2022-11-02
Version: 1.23.1
Date: 2023-01-30
Authors@R:
c(person("Luke", "Zappia", role = c("aut", "cre"),
email = "luke@lazappi.id.au",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Bioconductor 3.17 devel

## Version 1.23.1 (2023-01-30)

* Fix bug in splatPopSimulate() where conditional group assignments were
incorrect when batch effects were applied (PR #161 @azodichr, fixes #158,
fixes #160)

# Version 1.22.0 (2022-11-02)

Bioconductor 3.16 release
Expand Down
17 changes: 12 additions & 5 deletions R/splatPop-simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ splatPopSimulate <- function(params = newSplatPopParams(nGenes = 50),
sim.sc <- splatPopSimulateSC(sim.means = sim.means$means,
params = params,
key = sim.means$key,
conditions = sim.means$conditions,
method = method,
counts.only = counts.only,
sparsify = sparsify,
Expand Down Expand Up @@ -136,8 +137,9 @@ splatPopSimulate <- function(params = newSplatPopParams(nGenes = 50),
#'
#' @return A list containing: `means` a matrix (or list of matrices if
#' n.groups > 1) with the simulated mean gene expression value for each gene
#' (row) and each sample (column) and `key` a data.frame with population
#' information including eQTL and group effects.
#' (row) and each sample (column), `key` a data.frame with population
#' information including eQTL and group effects, and `condition` a named array
#' containing conditional group assignments for each sample.
#'
#' @seealso
#' \code{\link{splatPopParseVCF}}, \code{\link{splatPopParseGenes}},
Expand Down Expand Up @@ -226,7 +228,7 @@ splatPopSimulateMeans <- function(vcf = mockVCF(),

sim.means <- splatPopSimConditionalEffects(key, eMeansPop, conditions)

return(list(means = sim.means, key = key))
return(list(means = sim.means, key = key, conditions=conditions))
}


Expand Down Expand Up @@ -293,6 +295,8 @@ splatPopParseEmpirical <- function(vcf = vcf, gff = gff, eqtl = eqtl,
#' scale simulations. See \code{\link{SplatPopParams}} for details.
#' @param key data.frame object containing a full or partial splatPop key.
#' Output from `splatPopSimulateMeans()`.
#' @param conditions named array with conditional group assignment for each
#' sample. Output from `splatPopSimulateMeans()`.
#' @param method which simulation method to use. Options are "single" which
#' produces a single cell population for each sample, "groups" which
#' produces distinct groups (eg. cell types) for each sample (note, this
Expand Down Expand Up @@ -330,6 +334,7 @@ splatPopSimulateSC <- function(sim.means,
key,
method = c("single", "groups", "paths"),
counts.only = FALSE,
conditions = NULL,
sparsify = TRUE,
verbose = TRUE, ...){

Expand All @@ -355,9 +360,11 @@ splatPopSimulateSC <- function(sim.means,
group.prob <- rep(1 / length(sim.means), length(sim.means))
}
samples <- colnames((sim.means[[1]]))


if (is.null(conditions)){
conditions <- splatPopDesignConditions(params, samples)
}
batches <- splatPopDesignBatches(params, samples, verbose)
conditions <- splatPopDesignConditions(params, samples)

# Simulate single-cell counts for each group/cell-type
group.n <- lapply(group.prob, function(x) {ceiling(x * batchCells)})
Expand Down
5 changes: 3 additions & 2 deletions man/splatPopSimulateMeans.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/splatPopSimulateSC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vignettes/splatPop.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ sim.means <- splatPopSimulateMeans(vcf = vcf, gff = gff,
round(sim.means$means[1:5, 1:3], digits = 2)

print(sim.means$key[1:5, ], digits = 2)

print(sim.means$conditions)
```

### Other examples
Expand Down Expand Up @@ -298,8 +300,8 @@ params.cond <- newSplatPopParams(eqtl.n = 0.5,
similarity.scale = 5,
condition.prob = c(0.5, 0.5),
eqtl.condition.specific = 0.5,
cde.facLoc = 0.5,
cde.facScale = 0.5)
cde.facLoc = 1,
cde.facScale = 1)

sim.pop.cond <- splatPopSimulate(vcf = vcf, gff = gff, params = params.cond,
sparsify = FALSE)
Expand Down