Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Estimate scDD simulation parameters
#'
#' Estimate simulation parameters for the scDD simulation from a real dataset.
#'
#' @param counts either a counts matrix or an SCESet object containing count
#' data to estimate parameters from.
#' @param conditions Vector giving the condition that each cell belongs to.
#' Conditions can be 1 or 2.
#' @param params SCDDParams object to store estimated values in.
#'
#' @details
#' This function is just a wrapper around \code{\link[scDD]{preprocess}} that
#' takes the output and converts it to a SCDDParams object. See
#' \code{\link[scDD]{preprocess}} for details.
#'
#' @return SCDDParams object containing the estimated parameters.
#'
#' @examples
#' data("sc_example_counts")
#' params <- scDDEstimate(sc_example_counts)
#' params
#' @export
scDDEstimate <- function(counts, conditions, params = newSCDDParams()) {
UseMethod("scDDEstimate")
}
#' @rdname scDDEstimate
#' @export
scDDEstimate.SCESet <- function(counts, conditions, params = newSCDDParams()) {
counts <- scater::counts(counts)
scDDEstimate(counts, params)
}
#' @rdname scDDEstimate
#' @export
scDDEstimate.matrix <- function(counts, conditions, params = newSCDDParams()) {
checkmate::assertClass(params, "SCDDParams")
checkmate::assertIntegerish(conditions, len = ncol(counts), lower = 1,
upper = 2)
counts.list <- list(Cond1 = counts[, conditions == 1],
Cond2 = counts[, conditions == 2])
processed <- scDD::preprocess(counts.list, c("Cond1", "Cond2"),
median_norm = TRUE)
names(conditions) <- colnames(processed)
pheno <- as(data.frame(condition = conditions), "AnnotatedDataFrame")
SCDat <- Biobase::ExpressionSet(assayData = processed, phenoData = pheno)
params <- setParams(params, nCells = dim(SCDat)[2], SCDat = SCDat)
return(params)
}