@@ -23,36 +23,72 @@ test_that("avgExp works correctly", {
2323})
2424
2525test_that(" findMarkersPresto works correctly" , {
26- result <- findMarkersPresto(ident1 = " 0" , ident2 = " 1" , object = pbmc_small , assay = " RNA" )
26+ result <- findMarkersPresto(
27+ ident1 = " 0" ,
28+ ident2 = " 1" ,
29+ object = pbmc_small ,
30+ assay = " RNA"
31+ )
2732 expect_true(is.data.frame(result ))
2833 expect_true(" gene" %in% colnames(result ))
2934 expect_true(" avg_log2FC" %in% colnames(result ))
3035 expect_error(
31- findMarkersPresto(ident1 = " 0" , ident2 = " 1" , object = data.frame (a = c(1 : 3 )), assay = " RNA" ),
36+ findMarkersPresto(
37+ ident1 = " 0" ,
38+ ident2 = " 1" ,
39+ object = data.frame (a = c(1 : 3 )),
40+ assay = " RNA"
41+ ),
3242 " Object must be a Seurat object"
3343 )
3444})
3545
3646test_that(" abundanceTbl works correctly" , {
37- abundanceTbl(pbmc_small , row_var = " groups" , col_var = " letter.idents" , dir_output = " ." )
47+ abundanceTbl(
48+ pbmc_small ,
49+ row_var = " groups" ,
50+ col_var = " letter.idents" ,
51+ dir_output = " ."
52+ )
3853 file_path <- " abundance_tbl_pbmc_small_letter.idents.xlsx"
3954 result <- readxl :: read_xlsx(file_path )
4055 expect_true(file.exists(file_path ))
4156 expect_true(is.data.frame(result ))
42- expected_result <- tibble :: tibble(cell = c(" g1" , " g2" ), A = c(30 , 23 ), B = c(14 , 13 ))
57+ expected_result <- tibble :: tibble(
58+ cell = c(" g1" , " g2" ),
59+ A = c(30 , 23 ),
60+ B = c(14 , 13 )
61+ )
4362 expect_equal(result , expected_result )
4463 expect_error(
45- abundanceTbl(data.frame (a = c(1 : 3 )), row_var = " groups" , col_var = " letter.idents" , dir_output = " ." ),
64+ abundanceTbl(
65+ data.frame (a = c(1 : 3 )),
66+ row_var = " groups" ,
67+ col_var = " letter.idents" ,
68+ dir_output = " ."
69+ ),
4670 " Object must be a Seurat object"
4771 )
4872 unlink(file_path )
4973})
5074
5175test_that(" propellerCalc works correctly" , {
52- pbmc_small $ condition <- factor (sample(c(" diseaseA" , " diseaseB" ), nrow(pbmc_small ), replace = TRUE ))
76+ set.seed(123 )
77+ pbmc_small $ condition <- factor (sample(
78+ c(" diseaseA" , " diseaseB" ),
79+ nrow(pbmc_small ),
80+ replace = TRUE
81+ ))
5382 pbmc_small $ cluster <- Idents(pbmc_small )
54- pbmc_small $ patient <- rep(paste0(" P" , 0 : 9 ), each = 8 , length.out = ncol(pbmc_small ))
55- lookup <- data.frame (patient = paste0(" P" , 0 : 9 ), condition = sample(c(" diseaseA" , " diseaseB" ), 10 , replace = TRUE ))
83+ pbmc_small $ patient <- rep(
84+ paste0(" P" , 0 : 9 ),
85+ each = 8 ,
86+ length.out = ncol(pbmc_small )
87+ )
88+ lookup <- data.frame (
89+ patient = paste0(" P" , 0 : 9 ),
90+ condition = sample(c(" diseaseA" , " diseaseB" ), 10 , replace = TRUE )
91+ )
5692
5793 result <- propellerCalc(
5894 seu_obj1 = pbmc_small ,
@@ -67,6 +103,71 @@ test_that("propellerCalc works correctly", {
67103 )
68104 expect_true(is.data.frame(result ))
69105 expect_true(" cluster" %in% colnames(result ))
106+ expect_true(" PropRatio" %in% colnames(result ))
107+ expect_true(" P.Value" %in% colnames(result ))
108+ expect_true(" FDR" %in% colnames(result ))
109+ expect_true(" log2ratio" %in% colnames(result ))
110+ expect_true(" FDR_log" %in% colnames(result ))
111+ })
112+
113+ test_that(" propellerCalc with permFDP works correctly" , {
114+ skip_if_not_installed(" permFDP" )
115+
116+ set.seed(123 )
117+ pbmc_small $ condition <- factor (sample(
118+ c(" diseaseA" , " diseaseB" ),
119+ nrow(pbmc_small ),
120+ replace = TRUE
121+ ))
122+ pbmc_small $ cluster <- Idents(pbmc_small )
123+ pbmc_small $ patient <- rep(
124+ paste0(" P" , 0 : 9 ),
125+ each = 8 ,
126+ length.out = ncol(pbmc_small )
127+ )
128+ lookup <- data.frame (
129+ patient = paste0(" P" , 0 : 9 ),
130+ condition = sample(c(" diseaseA" , " diseaseB" ), 10 , replace = TRUE )
131+ )
132+
133+ result <- propellerCalc(
134+ seu_obj1 = pbmc_small ,
135+ condition1 = " diseaseA" ,
136+ condition2 = " diseaseB" ,
137+ cluster_col = " cluster" ,
138+ meta_col = " condition" ,
139+ lookup = lookup ,
140+ sample_col = " patient" ,
141+ formula = " ~ 0 + condition" ,
142+ min_cells = 5 ,
143+ adjustment_method = " permFDP" ,
144+ fdr_threshold = 0.1 ,
145+ n_perms = 100
146+ )
147+
148+ expect_true(is.data.frame(result ))
149+ expect_true(" cluster" %in% colnames(result ))
150+ expect_true(" permFDP_sig" %in% colnames(result ))
151+ expect_true(" permFDP_threshold" %in% colnames(result ))
152+ expect_true(is.logical(result $ permFDP_sig ))
153+ expect_true(is.numeric(result $ permFDP_threshold ))
154+
155+ # Test error when fdr_threshold is not provided
156+ expect_error(
157+ propellerCalc(
158+ seu_obj1 = pbmc_small ,
159+ condition1 = " diseaseA" ,
160+ condition2 = " diseaseB" ,
161+ cluster_col = " cluster" ,
162+ meta_col = " condition" ,
163+ lookup = lookup ,
164+ sample_col = " patient" ,
165+ formula = " ~ 0 + condition" ,
166+ min_cells = 5 ,
167+ adjustment_method = " permFDP"
168+ ),
169+ " fdr_threshold must be specified"
170+ )
70171})
71172
72173test_that(" enrichrRun works correctly" , {
@@ -103,7 +204,15 @@ test_that("enrichrRun works correctly", {
103204 expect_true(is.data.frame(result_neg ))
104205
105206 # Check if the results have the expected columns
106- expected_columns <- c(" Term" , " Overlap" , " P.value" , " Adjusted.P.value" , " Odds.Ratio" , " Combined.Score" , " Genes" )
207+ expected_columns <- c(
208+ " Term" ,
209+ " Overlap" ,
210+ " P.value" ,
211+ " Adjusted.P.value" ,
212+ " Odds.Ratio" ,
213+ " Combined.Score" ,
214+ " Genes"
215+ )
107216 expect_identical(colnames(result_pos ), expected_columns )
108217 expect_identical(colnames(result_neg ), expected_columns )
109218
@@ -114,7 +223,11 @@ test_that("enrichrRun works correctly", {
114223})
115224
116225test_that(" ReadCellBender_h5 works correctly" , {
117- file_name <- system.file(" extdata" , " raw_feature_bc_matrix_filtered.h5" , package = " scMisc" )
226+ file_name <- system.file(
227+ " extdata" ,
228+ " raw_feature_bc_matrix_filtered.h5" ,
229+ package = " scMisc"
230+ )
118231 result <- ReadCellBender_h5(file_name )
119232 expect_true(is(result , " dgCMatrix" ))
120233 expect_true(nrow(result ) > 0 )
0 commit comments