Skip to content

Commit

Permalink
comment sparse-dense conv, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimalvovs committed Oct 1, 2024
1 parent 20f8ef6 commit 1a8b491
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions R/find_genes_of_interest.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ find_genes_of_interest<-function(
subset_goodGenes <- intersect(rownames(testMat),goodGenes)
testMat <- testMat[subset_goodGenes,]
}
res_kruskal<- matrixTests::row_kruskalwallis(x=as.matrix(testMat),g=region)

#we lose sparsity here, it is necessary for row tests (dunn, kruskal)
testMat <- as.matrix(testMat)

res_kruskal<- matrixTests::row_kruskalwallis(x=testMat,g=region)
qq <- qvalue::qvalue(res_kruskal$pvalue,fdr.level = fdr.level,
pfdr = FALSE, pi0 = 1)
res_kruskal <- cbind(res_kruskal,p.adj = qq$qvalues)
res_dunn_test <- row.dunn.test(in.data=as.matrix(testMat), region=region,
res_dunn_test <- row.dunn.test(in.data=testMat, region=region,
pattern1=pattern1, pattern2=pattern2)
rownames(res_dunn_test) <- rownames(res_kruskal)
ind <- rownames(res_kruskal[which(res_kruskal$p.adj<fdr.level),])
Expand Down
11 changes: 8 additions & 3 deletions tests/testthat/test-find_genes_of_interest.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
test_that('row dunn test works with both sparse and dense matrices',{
test_that('row dunn test works with dense matrix but not sparse',{
dense <- matrix(rnorm(100), ncol = 10)
sparse <- Matrix::Matrix(dense, sparse = TRUE)

region <- matrix(sample(c(NA, "Interacting"), 10, replace = TRUE), ncol = 1)
region <- factor(region)

patnames <- levels(region)[which(levels(region)!="Interacting")]

pattern1 <- patnames[1]
pattern2 <- patnames[2]

expect_true("dgCMatrix" %in% class(sparse))
expect_error(row.dunn.test(sparse, region),
expect_error(row.dunn.test(sparse, region, pattern1, pattern2),
"Argument 'x' must be a matrix or a vector")

expect_true("matrix" %in% class(dense))
expect_no_error(row.dunn.test(dense, region))
expect_no_error(row.dunn.test(dense, region, pattern1, pattern2))
})

0 comments on commit 1a8b491

Please sign in to comment.