Skip to content

Commit

Permalink
fix mean-based CoNGAfy
Browse files Browse the repository at this point in the history
add specific Matrix:: to function and testthat for mean values
  • Loading branch information
ncborcherding committed Apr 12, 2024
1 parent 9384510 commit e62c250
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/CoNGAfy.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CoNGA.dist <- function(sc, features, assay) {
}
# Adapted from the AverageExpression() function in Seurat
#' @importFrom rlang %||%
#' @importFrom Matrix sparse.model.matrix
#' @importFrom Matrix sparse.model.matrix colSums
#' @importFrom SummarizedExperiment assay
#' @importFrom stats as.formula
CoNGA.mean <- function(sc, features, assay) {
Expand Down Expand Up @@ -152,7 +152,7 @@ CoNGA.mean <- function(sc, features, assay) {
)
)
))
colsums <- colSums(x = category.matrix)
colsums <- Matrix::colSums(x = category.matrix)
category.matrix <- category.matrix[, colsums > 0]
colsums <- colsums[colsums > 0]

Expand Down
15 changes: 14 additions & 1 deletion tests/testthat/test-CoNGAfy.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ test_that("CoNGAfy works", {

data("ibex_example")


conga_reduction <- CoNGAfy(ibex_example)

expect_equal(
Expand All @@ -17,4 +16,18 @@ test_that("CoNGAfy works", {
getdata("CoNGAfy", "CoNGAfy_counts"),
tolerance=1e-2
)

conga_mean_reduction <- CoNGAfy(ibex_example,
method = "mean")

expect_equal(
conga_mean_reduction@meta.data,
getdata("CoNGAfy", "CoNGAfy_mean_meta.data")
)

expect_equal(
conga_mean_reduction@assays$RNA@layers$counts,
getdata("CoNGAfy", "CoNGAfy_mean_counts"),
tolerance=1e-2
)
})
Binary file not shown.
Binary file not shown.

0 comments on commit e62c250

Please sign in to comment.