R/list_to_dimreduc.R

Defines functions list_to_dimreduc

Documented in list_to_dimreduc

#' Convert: \code{list} ==> \code{DimReducObject}
#'
#' Create a \pkg{Seurat} \code{DimReducObject}
#' from embeddings and loadings.
#' @param obj A named list containing:
#' \itemize{
#' \item{obsm : }{Sample embeddings}
#' \item{varm : }{Feature loadings}
#' \item{stdev : Standard deviation (if applicable) for the
#'  dimensional reduction}
#' }
#' @param assay Assay to use.
#' @param key Key to use (name of embedding).
#' @inheritDotParams SeuratObject::CreateDimReducObject
#'
#' @export
list_to_dimreduc <- function(obj,
                             assay,
                             key,
                             ...) {

    Seurat::CreateDimReducObject(
        embeddings = obj$obsm,
        loadings = obj$varm,
        stdev = if (is.null(obj$stdev)) {
            numeric()
        } else {
            as.numeric(obj$stdev)
        },
        assay = assay,
        key = key,
        ...)
}
bschilder/scKirby documentation built on April 22, 2024, 12:13 a.m.