Skip to contents

we recommend to only merge simulations from the same dataset object, otherwise the count matrices might not correspond on the gene level

Usage

merge_simulations(simulation_list)

Arguments

simulation_list

a list of simulations

Value

named list; bulk a SummarizedExperiment object, where the assays store the simulated bulk RNAseq datasets. Can hold either one or two assays, depending on how many matrices were present in the dataset cell-fractions is a dataframe with the simulated cell-fractions per sample; scaling_vector scaling value for each cell in dataset

Examples

counts <- Matrix::Matrix(matrix(rpois(3e5, 5), ncol=300), sparse = TRUE)
#> Error in rpois(3e+05, 5): could not find function "rpois"
tpm <- Matrix::Matrix(matrix(rpois(3e5, 5), ncol=300), sparse = TRUE)
#> Error in rpois(3e+05, 5): could not find function "rpois"
tpm <- Matrix::t(1e6*Matrix::t(tpm)/Matrix::colSums(tpm))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 't': error in evaluating the argument 'x' in selecting a method for function 't': object 'tpm' not found

colnames(counts) <- paste0("cell_",rep(1:300))
#> Error in colnames(counts) <- paste0("cell_", rep(1:300)): object 'counts' not found
colnames(tpm) <- paste0("cell_",rep(1:300))
#> Error in colnames(tpm) <- paste0("cell_", rep(1:300)): object 'tpm' not found
rownames(counts) <- paste0("gene_",rep(1:1000))
#> Error in rownames(counts) <- paste0("gene_", rep(1:1000)): object 'counts' not found
rownames(tpm) <- paste0("gene_",rep(1:1000))
#> Error in rownames(tpm) <- paste0("gene_", rep(1:1000)): object 'tpm' not found

annotation <- data.frame("ID"=paste0("cell_",rep(1:300)),
                         "cell_type"=c(rep("T cells CD4",50),
                                       rep("T cells CD8",50),
                                       rep("Macrophages",100),
                                       rep("NK cells",10),
                                       rep("B cells",70),
                                       rep("Monocytes",20)))

dataset <- SimBu::dataset(annotation = annotation,
                          count_matrix = counts,
                          tpm_matrix = tpm,
                          name = "test_dataset")
#> Error in generate_summarized_experiment(annotation = annotation, count_matrix = count_matrix,     tpm_matrix = tpm_matrix, name = name, spike_in_col = spike_in_col,     additional_cols = additional_cols, filter_genes = filter_genes,     variance_cutoff = variance_cutoff, type_abundance_cutoff = type_abundance_cutoff,     scale_tpm = scale_tpm): object 'counts' not found

s1 <- SimBu::simulate_bulk(dataset,
                          scenario="even",
                          scaling_factor="NONE",
                          nsamples=10,
                          ncells=100)
#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("function"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("colData"), generic = structure("colData", package = "SummarizedExperiment"),     package = "SummarizedExperiment", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop("invalid call in method dispatch to 'colData' (no default method)",         domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘colData’ for signature ‘"function"’

s2 <- SimBu::simulate_bulk(dataset,
                          scenario="even",
                          scaling_factor="NONE",
                          nsamples=10,
                          ncells=100)
#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("function"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("colData"), generic = structure("colData", package = "SummarizedExperiment"),     package = "SummarizedExperiment", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop("invalid call in method dispatch to 'colData' (no default method)",         domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘colData’ for signature ‘"function"’

s <- SimBu::merge_simulations(list(s1,s2))
#> Error in SimBu::merge_simulations(list(s1, s2)): object 's1' not found