From bdb1c2ee50efd1a891f44d3b387c47464654d440 Mon Sep 17 00:00:00 2001 From: Alemu Takele Assefa Date: Sun, 17 Nov 2024 01:31:04 +0100 Subject: [PATCH] Update obtCorMatsBatch.R Correcting t apply issue when column and row names of cpm.data are NULL --- R/obtCorMatsBatch.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/obtCorMatsBatch.R b/R/obtCorMatsBatch.R index 5754b93..2efa3c1 100644 --- a/R/obtCorMatsBatch.R +++ b/R/obtCorMatsBatch.R @@ -8,7 +8,19 @@ #' @importFrom WGCNA cor #' @importFrom limma voom obtCorMatsBatch <- function(cpm.data, batch, genewiseCor){ - tapply(colnames(cpm.data), batch, function(coln){ + if(is.null(colnames(cpm.data))){ + vec.columns = seq_len(ncol(cpm.data)) + }else{ + vec.columns = colnames(cpm.data) + } + + if(is.null(rownames(cpm.data))){ + vec.rows = seq_len(nrow(cpm.data)) + }else{ + vec.rows = rownames(cpm.data) + } + + tapply(vec.columns, batch, function(coln){ if(genewiseCor){ data <- cpm.data[, coln] voom.res <- limma::voom(data) @@ -17,7 +29,7 @@ obtCorMatsBatch <- function(cpm.data, batch, genewiseCor){ }else{ data <- cpm.data[, coln] cormat <- diag(x=1, nrow = nrow(data)) - rownames(cormat) <- colnames(cormat) <- rownames(data) + rownames(cormat) <- vec.columns <- vec.rows cormat } })