diff --git a/DESCRIPTION b/DESCRIPTION index 795ecc79f43cea99021682218138d0d6067695d0..05b3a97a59b9cbd433fb08be1a05c1edd25a7574 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: splatter Type: Package Title: Simple Simulation of Single-cell RNA Sequencing Data -Version: 1.9.7.9019 +Version: 1.9.8 Date: 2019-10-11 Authors@R: c(person("Luke", "Zappia", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 90be82e60dfcd02b302650d967504d46e4089e78..0b9e31625b4becd89838e5d761bdf789e00e34de 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ # DEVELOPMENT VERSION -## Version 1.9.8 +## Version 1.9.8 (2019-10-11) + +* Add Kersplat simulation! Still experimental but is useable. +* Check for counts assay when estimating from SingleCellExperiment objects + (Fixes #82) ### Version 1.9.7.9019 (2019-10-11) diff --git a/R/BASiCS-estimate.R b/R/BASiCS-estimate.R index 229cddfd4785daef7ac1421a736e4bf7550f9749..4375d64731cbc731fdacc29b1c2b4a7b57e227b8 100644 --- a/R/BASiCS-estimate.R +++ b/R/BASiCS-estimate.R @@ -62,7 +62,7 @@ BASiCSEstimate.SingleCellExperiment <- function(counts, spike.info = NULL, params = newBASiCSParams(), verbose = TRUE, progress = TRUE, ...) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) BASiCSEstimate(counts, spike.info, batch, n, thin, burn, regression, params, verbose, progress, ...) } diff --git a/R/SCE-functions.R b/R/SCE-functions.R index 5e4a8743c5b6d4e62e596e7b44980cbac560bbf5..609345b5f03cf2884010333b56dc728d2b4fcb09 100644 --- a/R/SCE-functions.R +++ b/R/SCE-functions.R @@ -142,3 +142,25 @@ addGeneLengths <- function(sce, method = c("generate", "sample"), loc = 7.9, return(sce) } + +#' Get counts +#' +#' Get counts matrix from a SingleCellExperiment object. If counts is missing +#' a warning is issued and the first assay is returned. +#' +#' @param sce +#' +#' @return Counts matrix +getCounts <- function(sce) { + + checkmate::assertClass(sce, "SingleCellExperiment") + + if ("counts" %in% SummarizedExperiment::assayNames(sce)) { + counts <- SingleCellExperiment::counts(sce) + } else { + warning("counts assay is missing, using the first assay instead") + counts <- SummarizedExperiment::assay(sce) + } + + return(counts) +} diff --git a/R/kersplat-estimate.R b/R/kersplat-estimate.R index 2bc5b81715a6edaacecc61c4b8c8509896e7117e..9eaa4c08f4952ca70940970aaaa3f7909b242986 100644 --- a/R/kersplat-estimate.R +++ b/R/kersplat-estimate.R @@ -34,7 +34,7 @@ kersplatEstimate <- function(counts, params = newKersplatParams(), kersplatEstimate.SingleCellExperiment <- function(counts, params = newKersplatParams(), verbose = TRUE) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) kersplatEstimate(counts, params, verbose) } diff --git a/R/lun-estimate.R b/R/lun-estimate.R index a014402e78e56259dcbe3301fe10e3bddc0c4d25..140019bb1520da99981c8c98ff7943bfb7fed61a 100644 --- a/R/lun-estimate.R +++ b/R/lun-estimate.R @@ -29,7 +29,7 @@ lunEstimate <- function(counts, params = newLunParams()) { #' @rdname lunEstimate #' @export lunEstimate.SingleCellExperiment <- function(counts, params = newLunParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) lunEstimate(counts, params) } diff --git a/R/lun2-estimate.R b/R/lun2-estimate.R index 0bcc212d98e14da2fb6b36672ce418ea7313cba4..f9332d9a39324e3da3a5157fe91a20e36d75eb14 100644 --- a/R/lun2-estimate.R +++ b/R/lun2-estimate.R @@ -43,7 +43,7 @@ lun2Estimate.SingleCellExperiment <- function(counts, plates, params = newLun2Params(), min.size = 200, verbose = TRUE, BPPARAM = SerialParam()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) lun2Estimate(counts, plates, params, min.size = min.size, verbose = verbose, BPPARAM = BPPARAM) } diff --git a/R/mfa-estimate.R b/R/mfa-estimate.R index c05f1749d44a15ffcb8bb752b8e6ce81878b466c..dcff5ae6f42ad2ec954fae2dcc53b67eeb402d95 100644 --- a/R/mfa-estimate.R +++ b/R/mfa-estimate.R @@ -33,7 +33,7 @@ mfaEstimate <- function(counts, params = newMFAParams()) { #' @export mfaEstimate.SingleCellExperiment <- function(counts, params = newMFAParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) mfaEstimate(counts, params) } diff --git a/R/pheno-estimate.R b/R/pheno-estimate.R index 76b95e619bbc2c4f0d9f4c047b7ddfd3eb0653d8..47c92d75a9089370bd9da372a80087e5579e6c9e 100644 --- a/R/pheno-estimate.R +++ b/R/pheno-estimate.R @@ -33,7 +33,7 @@ phenoEstimate <- function(counts, params = newPhenoParams()) { #' @export phenoEstimate.SingleCellExperiment <- function(counts, params = newPhenoParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) phenoEstimate(counts, params) } diff --git a/R/simple-estimate.R b/R/simple-estimate.R index 5bb2fb377ce67d87b83c71269552d9706bf9f371..c5e208fd12c2de272ad377bc61cfaddc957772e6 100644 --- a/R/simple-estimate.R +++ b/R/simple-estimate.R @@ -32,7 +32,7 @@ simpleEstimate <- function(counts, params = newSimpleParams()) { #' @export simpleEstimate.SingleCellExperiment <- function(counts, params = newSimpleParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) simpleEstimate(counts, params) } diff --git a/R/sparseDC-estimate.R b/R/sparseDC-estimate.R index a0784bec61cc872490d85f9d72ae08e6b9a62096..f2847995f84f4064c86a959223c3984a435d1f1d 100644 --- a/R/sparseDC-estimate.R +++ b/R/sparseDC-estimate.R @@ -46,7 +46,7 @@ sparseDCEstimate <- function(counts, conditions, nclusters, norm = TRUE, sparseDCEstimate.SingleCellExperiment <- function(counts, conditions, nclusters, norm = TRUE, params = newSparseDCParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) sparseDCEstimate(counts, conditions, nclusters, norm, params) } diff --git a/R/splat-estimate.R b/R/splat-estimate.R index 459606d7c10c56bbbe2fb6d6d8531e48d8395656..179f7dca8de6f68d85268bb3ff28f7907d1f8a34 100644 --- a/R/splat-estimate.R +++ b/R/splat-estimate.R @@ -32,7 +32,7 @@ splatEstimate <- function(counts, params = newSplatParams()) { #' @export splatEstimate.SingleCellExperiment <- function(counts, params = newSplatParams()) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) splatEstimate(counts, params) } diff --git a/R/zinb-estimate.R b/R/zinb-estimate.R index 38d3acb143521f9bb891b76e6218142c8ded818d..b978fbdbdcb149e52f032317d7d85ad295e4b45e 100644 --- a/R/zinb-estimate.R +++ b/R/zinb-estimate.R @@ -56,7 +56,7 @@ zinbEstimate.SingleCellExperiment <- function(counts, design.samples = NULL, params = newZINBParams(), verbose = TRUE, BPPARAM = SerialParam(), ...) { - counts <- BiocGenerics::counts(counts) + counts <- getCounts(counts) zinbEstimate(counts, design.samples, design.genes, common.disp, iter.init, iter.opt, stop.opt, params, verbose, BPPARAM, ...) } diff --git a/man/getCounts.Rd b/man/getCounts.Rd new file mode 100644 index 0000000000000000000000000000000000000000..4117bbd488f154decd0caef508d3a64d51e968a0 --- /dev/null +++ b/man/getCounts.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SCE-functions.R +\name{getCounts} +\alias{getCounts} +\title{Get counts} +\usage{ +getCounts(sce) +} +\arguments{ +\item{sce}{} +} +\value{ +Counts matrix +} +\description{ +Get counts matrix from a SingleCellExperiment object. If counts is missing +a warning is issued and the first assay is returned. +} diff --git a/tests/testthat/test-simpleEstimate.R b/tests/testthat/test-simpleEstimate.R index 1d6506c5adcf5c5e072330f422916f064503c2a0..1a4df185906b16f3cbf61d682ea7e4c4a71bac34 100644 --- a/tests/testthat/test-simpleEstimate.R +++ b/tests/testthat/test-simpleEstimate.R @@ -8,3 +8,18 @@ test_that("simpleEstimate works", { params <- simpleEstimate(counts) expect_true(validObject(params)) }) + +test_that("simpleEstimate works with SingleCellExperiment", { + sce <- SingleCellExperiment::SingleCellExperiment( + assays = list(counts = counts) + ) + params <- simpleEstimate(sce) + expect_true(validObject(params)) +}) + +test_that("simpleEstimate works with SingleCellExperiment without counts", { + sce <- SingleCellExperiment::SingleCellExperiment( + assays = list(TEST = counts) + ) + expect_warning(simpleEstimate(sce), "counts assay is missing") +})