Skip to content
Snippets Groups Projects
Commit cfbad4d5 authored by Luke Zappia's avatar Luke Zappia
Browse files

Update scDDEstimate

parent 31fb64a3
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -6,6 +6,8 @@
#' 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
......@@ -29,64 +31,70 @@
#' }
#' @importFrom BiocParallel SerialParam
#' @export
scDDEstimate <- function(counts, conditions, params = newSCDDParams(),
verbose = TRUE, BPPARAM = SerialParam()) {
scDDEstimate <- function(counts, 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, conditions, params = newSCDDParams(),
verbose = TRUE, BPPARAM = SerialParam(), ...) {
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, condition = "condition",
params = newSCDDParams(),
verbose = TRUE,
BPPARAM = SerialParam()) {
counts <- BiocGenerics::counts(counts)
scDDEstimate(counts, conditions, params, verbose, BPPARAM)
BPPARAM = SerialParam(), ...) {
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, condition, params, verbose, BPPARAM) {
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)
))
}
......
......@@ -2,26 +2,26 @@
% 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())
\method{scDDEstimate}{SingleCellExperiment}(counts, conditions,
params = newSCDDParams(), verbose = TRUE, BPPARAM = SerialParam())
scDDEstimate(counts, params = newSCDDParams(), verbose = TRUE,
BPPARAM = SerialParam(), ...)
\method{scDDEstimate}{matrix}(counts, conditions, params = newSCDDParams(),
verbose = TRUE, BPPARAM = SerialParam())
verbose = TRUE, BPPARAM = SerialParam(), ...)
\method{scDDEstimate}{SingleCellExperiment}(counts, condition = "condition",
params = newSCDDParams(), verbose = TRUE, BPPARAM = SerialParam(), ...)
\method{scDDEstimate}{default}(counts, condition, params, verbose, BPPARAM)
}
\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 +29,12 @@ 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{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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment