Skip to content

Commit

Permalink
Update obtCorMatsBatch.R
Browse files Browse the repository at this point in the history
Correcting t apply issue when column and row names of cpm.data are NULL
  • Loading branch information
AlemuTA authored Nov 17, 2024
1 parent cb95b0d commit bdb1c2e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions R/obtCorMatsBatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
})
Expand Down

0 comments on commit bdb1c2e

Please sign in to comment.