diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5dbd6c1..6ca9e4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] @@ -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 @@ -31,7 +31,7 @@ repos: exclude: "inst/extdata/.*" # `exclude: ` 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 diff --git a/DESCRIPTION b/DESCRIPTION index 5df46ff..34c94ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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, diff --git a/R/basilisk.R b/R/basilisk.R index c026246..d3b38d5 100755 --- a/R/basilisk.R +++ b/R/basilisk.R @@ -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", diff --git a/R/census.R b/R/census.R index 4a3b5cb..076628b 100755 --- a/R/census.R +++ b/R/census.R @@ -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: diff --git a/R/simulator.R b/R/simulator.R index c129d74..c9b0e1f 100755 --- a/R/simulator.R +++ b/R/simulator.R @@ -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) } @@ -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, @@ -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 { diff --git a/man/SimBu.Rd b/man/SimBu.Rd index 894b23e..2ebcbcf 100755 --- a/man/SimBu.Rd +++ b/man/SimBu.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/simulator.R \docType{package} \name{SimBu} +\alias{SimBu-package} \alias{SimBu} \title{SimBu: Bias-aware simulation of bulk RNA-seq data with variable cell type composition} \description{ @@ -31,3 +32,15 @@ adapt the cell type fractions in each sample by changing the scenario parameter. Inspect the cell type composition of your simulations with the plot_simulation() function. } +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/omnideconv/SimBu} + \item Report bugs at \url{https://github.com/omnideconv/SimBu/issues} +} + +} +\author{ +\strong{Maintainer}: Alexander Dietrich \email{alex.dietrich@tum.de} + +} diff --git a/tests/testthat/test_simulator.R b/tests/testthat/test_simulator.R index 41ff342..be14f20 100755 --- a/tests/testthat/test_simulator.R +++ b/tests/testthat/test_simulator.R @@ -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", {