From 798e1716f5c2c56142bcb962a0f142d29f52bee7 Mon Sep 17 00:00:00 2001 From: Josep Garnica <61703467+JGarnica22@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:20:24 +0200 Subject: [PATCH] Solve issue momf.comtpureRef function No names given to weight vector and produced vector of 0, solved by unifying both sapply functions. --- R/MOMF.R | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/R/MOMF.R b/R/MOMF.R index 4f70052..4952d54 100644 --- a/R/MOMF.R +++ b/R/MOMF.R @@ -101,20 +101,16 @@ momf.fit <- function(DataX, DataW=NULL, DataH=NULL, DataU=NULL, DataPriorU=NULL, #' @export momf.computeRef <- function(sc_counts, cell_type){ - # cell type weight - weight <- sapply(unique(cell_type), function(ct){ - y = sc_counts[ ,cell_type %in% ct, drop = FALSE] - sum(y)/sum(sc_counts) - }) - U <- sapply(unique(cell_type), function(ct){ - y = sc_counts[ ,cell_type %in% ct, drop = FALSE] - rowSums(y)/sum(y)*weight[names(weight) == ct] - }) - U <- 1000000 * U - colnames(U) <- unique(cell_type) - rownames(U) <- rownames(sc_counts) - # return estimated mean for each cell type - return(U) + U <- sapply(unique(cell_type), function(ct){ + y = sc_count[ ,cell_type %in% ct, drop = FALSE] + weight = sum(y)/sum(sc_count) + rowSums(y)/sum(y)*weight + }) + U <- 1000000 * U + colnames(U) <- unique(cell_type) + rownames(U) <- rownames(sc_count) + # return estimated mean for each cell type + return(U) }# end func