diff --git a/NAMESPACE b/NAMESPACE index 216436b18d78a343574efa2442f5243c0a6454b0..16a874dc59cc293733ab91688904545878cf5ff6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ S3method(lun2Estimate,matrix) S3method(lunEstimate,SingleCellExperiment) S3method(lunEstimate,matrix) S3method(scDDEstimate,SingleCellExperiment) +S3method(scDDEstimate,default) S3method(scDDEstimate,matrix) S3method(simpleEstimate,SingleCellExperiment) S3method(simpleEstimate,matrix) diff --git a/R/AllClasses.R b/R/AllClasses.R index 59432fe5ebe17e623cf3c367bacb33cdd1394b6d..36fe0b311b765b47b6d617e2ee328af9c8eb2ad4 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -409,7 +409,7 @@ setClass("Lun2Params", #' \item{\code{nCells}}{The number of cells to simulate in each condition.} #' \item{\code{[seed]}}{Seed to use for generating random numbers.} #' \item{\code{SCdat}}{ -#' \code{\link[SummarizedExperiment]{SummarizedExperiment}} containing real +#' \code{\link[SingleCellExperiment]{SingleCellExperiment}} containing real #' data.} #' \item{\code{nDE}}{Number of DE genes to simulate.} #' \item{\code{nDP}}{Number of DP genes to simulate.} @@ -427,8 +427,8 @@ setClass("Lun2Params", #' #' The parameters not shown in brackets can be estimated from real data using #' \code{\link{scDDEstimate}}. See \code{\link[scDD]{simulateSet}} for more -#' details of the parameters. For details of the Splatter implementation of the -#' scDD simulation see \code{\link{scDDSimulate}}. +#' details about the parameters. For details of the Splatter implementation of +#' the scDD simulation see \code{\link{scDDSimulate}}. #' #' @name SCDDParams #' @rdname SCDDParams @@ -448,7 +448,7 @@ setClass("SCDDParams", varInflation = "numeric", condition = "character"), prototype = prototype(SCdat = - SummarizedExperiment::SummarizedExperiment(), + SingleCellExperiment::SingleCellExperiment(), nCells = 100, nDE = 250, nDP = 250, diff --git a/R/SCDDParams-methods.R b/R/SCDDParams-methods.R index 09aa786a36852cf62acdc979ca8d3e5cc9d5fb23..22c6ac198a2db3c8fab3ee445b543227fb209a4b 100644 --- a/R/SCDDParams-methods.R +++ b/R/SCDDParams-methods.R @@ -26,7 +26,7 @@ setValidity("SCDDParams", function(object) { checks <- c(nGenes = checkInt(v$nGenes, lower = 1), nCells = checkInt(v$nCells, lower = 1), seed = checkInt(v$seed, lower = 0), - SCDat = checkClass(v$SCdat, "SummarizedExperiment"), + SCDat = checkClass(v$SCdat, "SingleCellExperiment"), nDE = checkInt(v$nDE, lower = 0), nDP = checkInt(v$nDP, lower = 0), nDM = checkInt(v$nDM, lower = 0), @@ -102,8 +102,8 @@ setMethod("show", "SCDDParams", function(object) { SCdat <- getParam(object, "SCdat") cat("Data:", "\n") cat("(SCdat)", "\n") - cat("SummarizedExperiment with", dim(SCdat)[1], "features and", - dim(SCdat)[2], "samples", "\n\n") + cat("SingleCellExperiment with", dim(SCdat)[1], "features and", + dim(SCdat)[2], "cells", "\n\n") showPP(object, pp) }) diff --git a/R/scDD-estimate.R b/R/scDD-estimate.R index 7253c61e01dda32fbac1cba7c14324fafb05142f..9c213670a4aec8d72f1c08305aa4c4894e1f3fbb 100644 --- a/R/scDD-estimate.R +++ b/R/scDD-estimate.R @@ -6,11 +6,14 @@ #' 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 condition String giving the column that represents biological group of +#' interest. #' @param params SCDDParams object to store estimated values in. #' @param verbose logical. Whether to show progress messages. #' @param BPPARAM A \code{\link[BiocParallel]{BiocParallelParam}} instance #' giving the parallel back-end to be used. Default is #' \code{\link[BiocParallel]{SerialParam}} which uses a single core. +#' @param ... further arguments passed to or from other methods. #' #' @details #' This function applies \code{\link[scDD]{preprocess}} to the counts then uses @@ -29,64 +32,75 @@ #' } #' @importFrom BiocParallel SerialParam #' @export -scDDEstimate <- function(counts, conditions, params = newSCDDParams(), - verbose = TRUE, BPPARAM = SerialParam()) { +scDDEstimate <- function(counts, #conditions, condition, + params = newSCDDParams(), verbose = TRUE, + BPPARAM = SerialParam(), ...) { + + if (!requireNamespace("scDD", quietly = TRUE)) { + stop("The scDD simulation requires the 'scDD' package.") + } + UseMethod("scDDEstimate") } +#' @rdname scDDEstimate +#' @importFrom SingleCellExperiment SingleCellExperiment +#' @export +scDDEstimate.matrix <- function(counts, params = newSCDDParams(), + verbose = TRUE, BPPARAM = SerialParam(), + conditions, ...) { + + checkmate::assertMatrix(counts, mode = "numeric", any.missing = FALSE, + min.rows = 1, min.cols = 1, row.names = "unique", + col.names = "unique") + checkmate::assertIntegerish(conditions, len = ncol(counts), lower = 1, + upper = 2) + + counts <- SingleCellExperiment(assays = list(counts = counts), + colData = data.frame(condition = conditions)) + scDDEstimate.default(counts, "condition", params, verbose, BPPARAM) +} + #' @rdname scDDEstimate #' @export -scDDEstimate.SingleCellExperiment <- function(counts, conditions, +scDDEstimate.SingleCellExperiment <- function(counts, params = newSCDDParams(), verbose = TRUE, - BPPARAM = SerialParam()) { - counts <- BiocGenerics::counts(counts) - scDDEstimate(counts, conditions, params, verbose, BPPARAM) + BPPARAM = SerialParam(), + condition = "condition", ...) { + scDDEstimate.default(counts, condition, params, verbose, BPPARAM) } #' @rdname scDDEstimate #' @importFrom methods as #' @export -scDDEstimate.matrix <- function(counts, conditions, params = newSCDDParams(), - verbose = TRUE, BPPARAM = SerialParam()) { - - if (!requireNamespace("scDD", quietly = TRUE)) { - stop("The scDD simulation requires the 'scDD' package.") - } +scDDEstimate.default <- function(counts, + params = newSCDDParams(), verbose = TRUE, + BPPARAM = SerialParam(), condition, ...) { checkmate::assertClass(params, "SCDDParams") - checkmate::assertMatrix(counts, mode = "numeric", any.missing = FALSE, - min.rows = 1, min.cols = 1, row.names = "unique", - col.names = "unique") - checkmate::assertIntegerish(conditions, len = ncol(counts), lower = 1, - upper = 2) - - counts.list <- list(Cond1 = counts[, conditions == 1], - Cond2 = counts[, conditions == 2]) + checkmate::assertClass(counts, "SingleCellExperiment") + checkmate::assertCharacter(condition, min.chars = 1, any.missing = FALSE, + len = 1) + if (!(condition %in% colnames(SummarizedExperiment::colData(counts)))) { + stop("'condition' must be the name of a column in `colData(counts)`") + } if (verbose) { - processed <- scDD::preprocess(counts.list, c("Cond1", "Cond2"), - median_norm = TRUE) + processed <- scDD::preprocess(counts, condition, median_norm = TRUE) } else { suppressMessages( - processed <- scDD::preprocess(counts.list, c("Cond1", "Cond2"), - median_norm = TRUE) + processed <- scDD::preprocess(counts, condition, median_norm = TRUE) ) } - assays <- S4Vectors::SimpleList(NormCounts = processed) - - colData <- S4Vectors::DataFrame(condition = conditions, - row.names = colnames(processed)) - - SCdat <- SummarizedExperiment::SummarizedExperiment(assays = assays, - colData = colData) - if (verbose) { - SCdat <- scDD::scDD(SCdat, testZeroes = FALSE, param = BPPARAM) + SCdat <- scDD::scDD(processed, testZeroes = FALSE, param = BPPARAM, + condition = condition) } else { dummy <- utils::capture.output(suppressMessages( - SCdat <- scDD::scDD(SCdat, testZeroes = FALSE, param = BPPARAM) + SCdat <- scDD::scDD(processed, testZeroes = FALSE, param = BPPARAM, + condition = condition) )) } diff --git a/R/scDD-simulate.R b/R/scDD-simulate.R index 704e14af1eb4d129e8b7411e025c5d21a5292de2..a9dbd3fec07b80631c68f08886fba38fc9c8fdb9 100644 --- a/R/scDD-simulate.R +++ b/R/scDD-simulate.R @@ -91,9 +91,9 @@ scDDSimulate <- function(params = newSCDDParams(), plots = FALSE, ) } - counts <- scDD.sim[[1]] - foldchanges <- scDD.sim[[2]] - de.status <- rownames(counts) + counts <- SummarizedExperiment::assays(scDD.sim)$normcounts + foldchanges <- SummarizedExperiment::rowData(scDD.sim)$FC + de.status <- SummarizedExperiment::rowData(scDD.sim)$Category if (verbose) {message("Creating final dataset...")} cell.names <- paste0("Cell", seq_len(nCells * 2)) diff --git a/man/SCDDParams.Rd b/man/SCDDParams.Rd index aef9df97deb3ea7b3d8625a55cf1fa51e044cc1f..894530c483b0f5685740de994b226019422d0c38 100644 --- a/man/SCDDParams.Rd +++ b/man/SCDDParams.Rd @@ -18,7 +18,7 @@ The SCDD simulation uses the following parameters: \item{\code{nCells}}{The number of cells to simulate in each condition.} \item{\code{[seed]}}{Seed to use for generating random numbers.} \item{\code{SCdat}}{ - \code{\link[SummarizedExperiment]{SummarizedExperiment}} containing real + \code{\link[SingleCellExperiment]{SingleCellExperiment}} containing real data.} \item{\code{nDE}}{Number of DE genes to simulate.} \item{\code{nDP}}{Number of DP genes to simulate.} @@ -36,7 +36,7 @@ The SCDD simulation uses the following parameters: The parameters not shown in brackets can be estimated from real data using \code{\link{scDDEstimate}}. See \code{\link[scDD]{simulateSet}} for more -details of the parameters. For details of the Splatter implementation of the -scDD simulation see \code{\link{scDDSimulate}}. +details about the parameters. For details of the Splatter implementation of +the scDD simulation see \code{\link{scDDSimulate}}. } diff --git a/man/scDDEstimate.Rd b/man/scDDEstimate.Rd index 6eb052e2e0bcbf8a587701f2fdccf7f1bf38373e..265183465ffcd3ca73550931c721146c38f57611 100644 --- a/man/scDDEstimate.Rd +++ b/man/scDDEstimate.Rd @@ -2,26 +2,27 @@ % Please edit documentation in R/scDD-estimate.R \name{scDDEstimate} \alias{scDDEstimate} -\alias{scDDEstimate.SingleCellExperiment} \alias{scDDEstimate.matrix} +\alias{scDDEstimate.SingleCellExperiment} +\alias{scDDEstimate.default} \title{Estimate scDD simulation parameters} \usage{ -scDDEstimate(counts, conditions, params = newSCDDParams(), verbose = TRUE, - BPPARAM = SerialParam()) +scDDEstimate(counts, params = newSCDDParams(), verbose = TRUE, + BPPARAM = SerialParam(), ...) + +\method{scDDEstimate}{matrix}(counts, params = newSCDDParams(), + verbose = TRUE, BPPARAM = SerialParam(), conditions, ...) -\method{scDDEstimate}{SingleCellExperiment}(counts, conditions, - params = newSCDDParams(), verbose = TRUE, BPPARAM = SerialParam()) +\method{scDDEstimate}{SingleCellExperiment}(counts, params = newSCDDParams(), + verbose = TRUE, BPPARAM = SerialParam(), condition = "condition", ...) -\method{scDDEstimate}{matrix}(counts, conditions, params = newSCDDParams(), - verbose = TRUE, BPPARAM = SerialParam()) +\method{scDDEstimate}{default}(counts, params = newSCDDParams(), + verbose = TRUE, BPPARAM = SerialParam(), condition, ...) } \arguments{ \item{counts}{either a counts matrix or a SingleCellExperiment object containing count data to estimate parameters from.} -\item{conditions}{Vector giving the condition that each cell belongs to. -Conditions can be 1 or 2.} - \item{params}{SCDDParams object to store estimated values in.} \item{verbose}{logical. Whether to show progress messages.} @@ -29,6 +30,14 @@ Conditions can be 1 or 2.} \item{BPPARAM}{A \code{\link[BiocParallel]{BiocParallelParam}} instance giving the parallel back-end to be used. Default is \code{\link[BiocParallel]{SerialParam}} which uses a single core.} + +\item{...}{further arguments passed to or from other methods.} + +\item{conditions}{Vector giving the condition that each cell belongs to. +Conditions can be 1 or 2.} + +\item{condition}{String giving the column that represents biological group of +interest.} } \value{ SCDDParams object containing the estimated parameters.