Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 6, 2024
1 parent c7f5d9d commit b256c32
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
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
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

0 comments on commit b256c32

Please sign in to comment.