From 712fe45cc963c68626c382d799e2ba0e0ec26934 Mon Sep 17 00:00:00 2001 From: Luke Zappia <lazappi@users.noreply.github.com> Date: Sun, 1 Oct 2017 15:20:56 +1100 Subject: [PATCH] Add mfaEstimate --- NAMESPACE | 3 +++ R/mfa-estimate.R | 46 ++++++++++++++++++++++++++++++++++++++++++++++ man/mfaEstimate.Rd | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 R/mfa-estimate.R create mode 100644 man/mfaEstimate.Rd diff --git a/NAMESPACE b/NAMESPACE index dedc870..64df61f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,8 @@ S3method(lun2Estimate,SingleCellExperiment) S3method(lun2Estimate,matrix) S3method(lunEstimate,SingleCellExperiment) S3method(lunEstimate,matrix) +S3method(mfaEstimate,SingleCellExperiment) +S3method(mfaEstimate,matrix) S3method(scDDEstimate,SingleCellExperiment) S3method(scDDEstimate,matrix) S3method(simpleEstimate,SingleCellExperiment) @@ -23,6 +25,7 @@ export(lunSimulate) export(makeCompPanel) export(makeDiffPanel) export(makeOverallPanel) +export(mfaEstimate) export(newLun2Params) export(newLunParams) export(newMFAParams) diff --git a/R/mfa-estimate.R b/R/mfa-estimate.R new file mode 100644 index 0000000..f3abf2f --- /dev/null +++ b/R/mfa-estimate.R @@ -0,0 +1,46 @@ +#' Estimate mfa simulation parameters +#' +#' Estimate simulation parameters for the mfa simulation from a real dataset. +#' +#' @param counts either a counts matrix or a SingleCellExperiment object +#' containing count data to estimate parameters from. +#' @param params MFAParams object to store estimated values in. +#' +#' @details +#' The \code{nGenes} and \code{nCells} parameters are taken from the size of the +#' input data. The dropout lambda parameter is estimate using +#' \code{\link[mfa]{empirical_lambda}}. See \code{\link{MFAParams}} for more +#' details on the parameters. +#' +#' @return MFAParams object containing the estimated parameters. +#' +#' @examples +#' data("sc_example_counts") +#' params <- mfaEstimate(sc_example_counts) +#' params +#' @export +mfaEstimate <- function(counts, params = newMFAParams()) { + UseMethod("mfaEstimate") +} + +#' @rdname mfaEstimate +#' @export +mfaEstimate.SingleCellExperiment <- function(counts, + params = newMFAParams()) { + counts <- BiocGenerics::counts(counts) + mfaEstimate(counts, params) +} + +#' @rdname mfaEstimate +#' @export +mfaEstimate.matrix <- function(counts, params = newMFAParams()) { + + checkmate::assertClass(params, "MFAParams") + + dropout.lambda <- mfa::empirical_lambda(t(counts)) + + params <- setParams(params, nGenes = nrow(counts), nCells = ncol(counts), + dropout.lambda = dropout.lambda) + + return(params) +} diff --git a/man/mfaEstimate.Rd b/man/mfaEstimate.Rd new file mode 100644 index 0000000..002cd04 --- /dev/null +++ b/man/mfaEstimate.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mfa-estimate.R +\name{mfaEstimate} +\alias{mfaEstimate} +\alias{mfaEstimate.SingleCellExperiment} +\alias{mfaEstimate.matrix} +\title{Estimate mfa simulation parameters} +\usage{ +mfaEstimate(counts, params = newMFAParams()) + +\method{mfaEstimate}{SingleCellExperiment}(counts, params = newMFAParams()) + +\method{mfaEstimate}{matrix}(counts, params = newMFAParams()) +} +\arguments{ +\item{counts}{either a counts matrix or a SingleCellExperiment object +containing count data to estimate parameters from.} + +\item{params}{MFAParams object to store estimated values in.} +} +\value{ +MFAParams object containing the estimated parameters. +} +\description{ +Estimate simulation parameters for the mfa simulation from a real dataset. +} +\details{ +The \code{nGenes} and \code{nCells} parameters are taken from the size of the +input data. The dropout lambda parameter is estimate using +\code{\link[mfa]{empirical_lambda}}. See \code{\link{MFAParams}} for more +details on the parameters. +} +\examples{ +data("sc_example_counts") +params <- mfaEstimate(sc_example_counts) +params +} -- GitLab