diff --git a/DESCRIPTION b/DESCRIPTION index 76d8d7b7..41025f67 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: CoGAPS -Version: 3.33.1 +Version: 3.33.2 Date: 2025-03-11 Title: Coordinated Gene Activity in Pattern Sets Author: Jeanette Johnson, Ashley Tsang, Jacob Mitchell, Thomas Sherman, Wai-shing Lee, Conor Kelton, Ondrej Maxian, Jacob Carey, diff --git a/R/DistributedCogaps.R b/R/DistributedCogaps.R index bd6cc17c..53bf6d50 100755 --- a/R/DistributedCogaps.R +++ b/R/DistributedCogaps.R @@ -247,8 +247,8 @@ stitchTogether <- function(result, allParams, sets) if (identical(sort(indices), sort(setIndices))) { reorder <- match(indices, setIndices) - Amean <- Amean[reorder,] - Asd <- Asd[reorder,] + Amean <- Amean[reorder,,drop=FALSE] + Asd <- Asd[reorder,,drop=FALSE] } } } @@ -269,8 +269,8 @@ stitchTogether <- function(result, allParams, sets) if (identical(sort(indices), sort(setIndices))) { reorder <- match(indices, setIndices) - Pmean <- Pmean[reorder,] - Psd <- Psd[reorder,] + Pmean <- Pmean[reorder,,drop=FALSE] + Psd <- Psd[reorder,,drop=FALSE] } } } diff --git a/tests/testthat/test_DistributedCogaps.R b/tests/testthat/test_DistributedCogaps.R index a530ec07..55024b8f 100644 --- a/tests/testthat/test_DistributedCogaps.R +++ b/tests/testthat/test_DistributedCogaps.R @@ -44,4 +44,30 @@ test_that("featureLoadings and sampleFactors are not all 0s in genome-wide", { expect_true(sort((dim(featureLoadings)))[1] == params@nPatterns) expect_true(sort((dim(sampleFactors)))[2] == ncol(GIST.matrix)) expect_true(sort((dim(featureLoadings)))[2] == nrow(GIST.matrix)) +}) + +# One consensus pattern makes the stitched matrices one column wide. Without +# drop=FALSE the re-ordering in stitchTogether turned them into vectors, whose +# rownames are NULL, and the run died with "no gene names given". +test_that("a one-pattern distributed run keeps its dim names", { + data(GIST) + for (mode in c("genome-wide", "single-cell")) + { + params <- CogapsParams(seed=42, + nIterations = 100, + nPatterns = 1, + sparseOptimization = as.logical(0), + distributed = mode) + params <- setDistributedParams(params, nSets = 2) + cg <- CoGAPS(GIST.matrix, params=params) + + expect_true(is.matrix(cg@featureLoadings)) + expect_true(is.matrix(cg@sampleFactors)) + expect_equal(ncol(cg@featureLoadings), 1L) + expect_equal(ncol(cg@sampleFactors), 1L) + expect_equal(nrow(cg@featureLoadings), nrow(GIST.matrix)) + expect_equal(nrow(cg@sampleFactors), ncol(GIST.matrix)) + expect_false(is.null(rownames(cg@featureLoadings))) + expect_false(is.null(rownames(cg@sampleFactors))) + } }) \ No newline at end of file