Skip to content
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2
rev: v0.4.3.9015
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
Expand All @@ -12,12 +12,12 @@ repos:
- id: no-debug-statement
- id: deps-in-desc
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v6.0.0
hooks:
- id: end-of-file-fixer
exclude: '\.Rd'
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
rev: v1.5.1
rev: v1.6.1
hooks:
# Only reuiqred when https://pre-commit.ci is used for config validation
- id: check-pre-commit-ci-config
Expand All @@ -31,7 +31,7 @@ repos:
exclude: "inst/extdata/.*"
# `exclude: <regex>` to allow committing specific files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v4.0.0-alpha.8
hooks:
- id: prettier

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Description: SimBu can be used to simulate bulk RNA-seq datasets with known cell
License: GPL-3 + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.3
Imports:
basilisk,
BiocParallel,
Expand Down
1 change: 0 additions & 1 deletion R/basilisk.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# dependencies for sfaira and anndata0.7.6 (taken from zellkonverter package)
SimBu_env <- basilisk::BasiliskEnvironment(
envname = "SimBu_env_1_1_1",
Expand Down
1 change: 0 additions & 1 deletion R/census.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Applies the Census count transformation on a count matrix
#'
#' needs a sparse matrix with cells in columns and genes in rows. You can find the detailed explaination here:
Expand Down
29 changes: 15 additions & 14 deletions R/simulator.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ simulate_sample <- function(data,
if (n == 0) {
n <- 1
}
if(!is.na(seed)){
if (!is.na(seed)) {
# fix seed for random selection of cells
set.seed(seed)
}
Expand Down Expand Up @@ -437,7 +437,6 @@ simulate_bulk <- function(data,

# sample cells and generate pseudo-bulk profiles
all_samples <- BiocParallel::bplapply(seq_along(simulation_vector_list), function(i) {

simulation_vector <- simulation_vector_list[[i]]
sample <- simulate_sample(
data = data,
Expand All @@ -454,22 +453,24 @@ simulate_bulk <- function(data,
return(sample)
}, BPPARAM = BPPARAM)

bulk_counts <- Matrix::Matrix(vapply(
X = all_samples,
FUN = "[[",
... = 1,
FUN.VALUE = double(dim(SummarizedExperiment::assays(data)[["counts"]])[1])
),
sparse = TRUE
)
if ("tpm" %in% names(SummarizedExperiment::assays(data))) {
bulk_tpm <- Matrix::Matrix(vapply(
bulk_counts <- Matrix::Matrix(
vapply(
X = all_samples,
FUN = "[[",
... = 2,
FUN.VALUE = double(dim(SummarizedExperiment::assays(data)[["tpm"]])[1])
... = 1,
FUN.VALUE = double(dim(SummarizedExperiment::assays(data)[["counts"]])[1])
),
sparse = TRUE
)
if ("tpm" %in% names(SummarizedExperiment::assays(data))) {
bulk_tpm <- Matrix::Matrix(
vapply(
X = all_samples,
FUN = "[[",
... = 2,
FUN.VALUE = double(dim(SummarizedExperiment::assays(data)[["tpm"]])[1])
),
sparse = TRUE
)
assays <- list(bulk_counts = bulk_counts, bulk_tpm = bulk_tpm)
} else {
Expand Down
13 changes: 13 additions & 0 deletions man/SimBu.Rd

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

15 changes: 7 additions & 8 deletions tests/testthat/test_simulator.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ test_that("test RNG", {
seed <- 123
sim1 <- SimBu::simulate_bulk(data = dataset, scenario = "even", scaling_factor = "NONE", balance_even_mirror_scenario = 0, nsamples = 10, ncells = 100, run_parallel = FALSE, seed = seed)
sim2 <- SimBu::simulate_bulk(data = dataset, scenario = "even", scaling_factor = "NONE", balance_even_mirror_scenario = 0, nsamples = 10, ncells = 100, run_parallel = FALSE, seed = seed)
x1 <- Matrix::rowSums(assays(sim1$bulk)[['bulk_counts']])
x2 <- Matrix::rowSums(assays(sim2$bulk)[['bulk_counts']])
testthat::expect_equal(x1,x2)

# test that samples inside one simulation still are different
sample1 <- sim1$bulk[,1]
sample2 <- sim1$bulk[,2]
testthat::expect_false(all(assays(sample1)[['bulk_counts']] == assays(sample2)[['bulk_counts']]))
x1 <- Matrix::rowSums(assays(sim1$bulk)[["bulk_counts"]])
x2 <- Matrix::rowSums(assays(sim2$bulk)[["bulk_counts"]])
testthat::expect_equal(x1, x2)

# test that samples inside one simulation still are different
sample1 <- sim1$bulk[, 1]
sample2 <- sim1$bulk[, 2]
testthat::expect_false(all(assays(sample1)[["bulk_counts"]] == assays(sample2)[["bulk_counts"]]))
})

test_that("test different scaling factor calculations + mRNA bias removal from counts", {
Expand Down