Skip to content

Commit 0f59c7b

Browse files
committed
more tests!
1 parent ffc1ade commit 0f59c7b

11 files changed

Lines changed: 224 additions & 17 deletions

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# categoryCompare2 0.200.9
2+
3+
- added more tests to up the test coverage, and hopefully a test coverage badge.
4+
15
# categoryCompare2 0.200.8
26

37
- fixes a long standing non-standard evaluation bug where if you tried to use an argument in a filtering operation, it would fail if it was within another function, or run in another process (#29).

R/graph_visualization.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ assign_colors <- function(in_assign, type = "experiment") {
221221
#' @return list of png files that are pie graphs
222222
#' @importFrom colorspace desaturate
223223
generate_piecharts <- function(grp_matrix, use_color) {
224-
check_package_installed("Cairo")
224+
check_package_installed("ragg")
225225
n_grp <- nrow(grp_matrix)
226226
n_color <- length(use_color)
227227

@@ -250,12 +250,12 @@ generate_piecharts <- function(grp_matrix, use_color) {
250250
)
251251

252252
out_file <- tempfile(i_grp, fileext = ".png")
253-
Cairo::Cairo(
253+
ragg::agg_png(
254+
filename = out_file,
255+
units = "px",
254256
width = 640,
255257
height = 640,
256-
file = out_file,
257-
type = "png",
258-
bg = "transparent"
258+
background = "transparent"
259259
)
260260
par(mai = c(0, 0, 0, 0))
261261
pie(pie_area, col = tmp_color, clockwise = TRUE)
@@ -503,7 +503,7 @@ setMethod(
503503
#' @param img should a base64 encoded data uri be returned for embedding?
504504
#' @param width how wide should the image be if saving to an image
505505
#' @param height how high should it be
506-
#' @param pointsize the pointsize parameter for Cairo, determines textsize in the image
506+
#' @param pointsize the pointsize parameter for ragg, determines textsize in the image
507507
#' @param ... any other parameter to \code{pie}
508508
#'
509509
#' @return NULL
@@ -533,11 +533,11 @@ generate_legend <- function(
533533
par(mai = c(0, 0, 0, 0), ps = pointsize)
534534
pie(pie_area, labels = use_labels, col = use_color, clockwise = TRUE, ...)
535535
} else {
536-
check_package_installed("Cairo")
536+
check_package_installed("ragg")
537537
out_file <- tempfile(pattern = "legendfile", fileext = ".png")
538-
Cairo::CairoPNG(
539-
file = out_file,
540-
bg = "white",
538+
ragg::agg_png(
539+
filename = out_file,
540+
background = "white",
541541
width = width,
542542
height = height,
543543
pointsize = pointsize

R/managing_annotations.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ json_2_annotation <- function(json_file) {
243243
#'
244244
#' @importFrom jsonlite fromJSON toJSON
245245
#' @export
246-
#' @return the json object, invisibly
246+
#' @return the json file
247247
#'
248248
json_annotation_reversal <- function(
249249
json_file,
@@ -294,5 +294,5 @@ json_annotation_reversal <- function(
294294
)
295295

296296
out_json <- annotation_2_json(out_annotation, out_file)
297-
out_json
297+
invisible(out_file)
298298
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![categoryCompare2 status badge](https://moseleybioinformaticslab.r-universe.dev/badges/categoryCompare2)](https://moseleybioinformaticslab.r-universe.dev/categoryCompare2)
2+
[![covr2gh coverage](https://raw.githubusercontent.com/MoseleyBioinformaticsLab/categoryCompare2/refs/heads/covr2gh-storage/badges/main/coverage_badge.svg)](https://github.com/MoseleyBioinformaticsLab/categoryCompare2/actions/workflows/covr2gh.yaml)
3+
14
# categoryCompare2
25

36
A Bioconductor package for meta analysis of high-throughput datasets using
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
test_that("annotations from db work", {
2+
entrez_db = get_db_annotation()
3+
4+
expect_equal(
5+
entrez_db@annotation_features[1],
6+
list(`GO:0000009` = c("55650", "79087", "85365"))
7+
)
8+
9+
ensembl_db = get_db_annotation(feature_type = "ENSEMBL")
10+
expect_equal(
11+
ensembl_db@annotation_features[1],
12+
list(
13+
`GO:0000009` = c("ENSG00000060642", "ENSG00000182858", "ENSG00000119523")
14+
)
15+
)
16+
17+
entrez_cc = get_db_annotation(annotation_type = "CC")
18+
cc_desc = head(entrez_cc@description)
19+
expect_all_true(grepl("complex", cc_desc))
20+
21+
entrez_pmid = get_db_annotation(annotation_type = "PMID")
22+
expect_equal(
23+
entrez_pmid@annotation_features["100103"],
24+
list(
25+
`100103` = c(
26+
"100008587",
27+
"106632260",
28+
"106632261",
29+
"106632262",
30+
"106632263"
31+
)
32+
)
33+
)
34+
expect_equal(entrez_pmid@annotation_type, "PMID")
35+
})

tests/testthat/test-gocats.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,28 @@ test_that("json exporting and importing works properly", {
101101
expect_equal(without_namespace2, in_annotation)
102102
})
103103
})
104+
105+
test_that("json reversal works", {
106+
withr::with_file("reversed.json", {
107+
out_res = json_annotation_reversal(
108+
ancestors_file,
109+
out_file = "reversed.json"
110+
)
111+
tmp_json = jsonlite::fromJSON("reversed.json", simplifyVector = FALSE)
112+
expect_equal(
113+
names(tmp_json),
114+
c("annotation_features", "counts", "annotation_type", "feature_type")
115+
)
116+
expect_equal(
117+
head(names(tmp_json$annotation_features)),
118+
c(
119+
"GO:0000002",
120+
"GO:0000003",
121+
"GO:0000009",
122+
"GO:0000010",
123+
"GO:0000012",
124+
"GO:0000014"
125+
)
126+
)
127+
})
128+
})

tests/testthat/test-graph_creation.R

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test_that("various graph properties are correct", {
3737
expect_equal(combined_coefficient(group3, group4), 8 / 15)
3838
expect_equal(combined_coefficient(group1, character()), NaN)
3939

40-
# generating simple graphs
40+
# generating simple graphs ---------
4141
group5 <- letters[10:12]
4242
group6 <- letters[11:12]
4343

@@ -68,7 +68,7 @@ test_that("various graph properties are correct", {
6868
})
6969

7070

71-
test_that('extraction of significant to graph is correct', {
71+
test_that('extraction of significant to graph works', {
7272
set.seed(1234)
7373
random_genes = sample(enrichment_data$universe, 100)
7474
non_enriched = hypergeometric_feature_enrichment(
@@ -80,14 +80,114 @@ test_that('extraction of significant to graph is correct', {
8080
),
8181
p_adjust = "BH"
8282
)
83+
84+
# checking for warnings -------------
8385
non_list = combine_enrichments(c1 = non_enriched)
8486
non_sig = get_significant_annotations(non_list, padjust <= 0.01)
8587
expect_warning(
8688
generate_annotation_graph(non_sig, low_cut = 2, hi_cut = 1000),
8789
regexp = "Nothing significant"
8890
)
8991

92+
# and that we get a 27 member network -------------
9093
non_sig2 = get_significant_annotations(non_list, p <= 0.01)
9194
sig2_graph = generate_annotation_graph(non_sig2, low_cut = 2, hi_cut = 1000)
9295
expect_equal(graph::numNodes(sig2_graph), 27)
96+
97+
# checking that tooltips get added ------------
98+
sig2_graph_tooltips = add_tooltip(
99+
sig2_graph,
100+
description = non_sig2@annotation@description[graph::nodes(sig2_graph)]
101+
)
102+
expect_equal(
103+
graph::nodeData(sig2_graph_tooltips, "GO:0000086", "tooltip"),
104+
list(
105+
`GO:0000086` = "GO:0000086\nG2/M transition of mitotic cell cycle\nG2/M transition of mitotic cell cycle"
106+
)
107+
)
108+
109+
# can generate communities ---------------
110+
sig2_comms = assign_communities(sig2_graph_tooltips)
111+
sig2_labels = label_communities(sig2_comms, non_sig2@annotation)
112+
expect_equal(length(sig2_comms), 7)
113+
expect_equal(length(sig2_labels), 5)
114+
expect_equal(
115+
sig2_labels[[1]],
116+
list(
117+
rep = "GO:1905114",
118+
label = "cell surface receptor signaling pathway involved in cell-cell signaling",
119+
members = c(
120+
"GO:0002524",
121+
"GO:0021545",
122+
"GO:0038166",
123+
"GO:0042249",
124+
"GO:1905114"
125+
)
126+
)
127+
)
128+
129+
bare_table = table_from_graph(sig2_graph_tooltips)
130+
expect_equal(nrow(bare_table), 27)
131+
132+
tmp_combinations = annotation_combinations(sig2_graph_tooltips)
133+
tmp_combinations = assign_colors(tmp_combinations)
134+
comm_table = table_from_graph(
135+
sig2_graph_tooltips,
136+
in_assign = tmp_combinations
137+
)
138+
expect_equal(nrow(comm_table), nrow(bare_table))
139+
140+
group_table = table_from_graph(
141+
sig2_graph_tooltips,
142+
tmp_combinations,
143+
sig2_labels
144+
)
145+
expect_gt(nrow(group_table), nrow(bare_table))
146+
expect_equal(group_table$c1.p[1], NA_real_)
147+
})
148+
149+
test_that("check packages installed works", {
150+
expect_null(check_package_installed("stats"))
151+
withr::with_temp_libpaths(
152+
{
153+
expect_error(check_package_installed("Cairo"), "is not installed")
154+
},
155+
action = "replace"
156+
)
157+
})
158+
159+
test_that("colors come out correctly", {
160+
expect_equal(
161+
generate_colors(4),
162+
c("#FF7A9E", "#AAB500", "#00CEB7", "#AC9AFF")
163+
)
164+
expect_equal(
165+
generate_colors(5),
166+
c("#FF7A9E", "#00CA66", "#DA88FF", "#CAAA00", "#00C6F2")
167+
)
168+
})
169+
170+
test_that("modifying graphs works", {
171+
group1 <- letters[1:6]
172+
group2 <- group1
173+
group3 <- letters[1:3]
174+
group4 <- letters[c(1, 2, 8, 10)]
175+
176+
group5 <- letters[10:12]
177+
group6 <- letters[11:12]
178+
179+
feature_list <- list(
180+
g1 = group1,
181+
g2 = group2,
182+
g3 = group3,
183+
g4 = group4,
184+
g5 = group5,
185+
g6 = group6
186+
)
187+
188+
test_combined = generate_annotation_similarity_graph(feature_list)
189+
# removing edges is correct ------------
190+
# remove edges < 0.75, results in 4 edges left
191+
remove_07 = remove_edges(test_combined, 0.75)
192+
expect_equal(length(graph::edgeData(remove_07, attr = "weight")), 4)
93193
})

tests/testthat/test-significant_results.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ test_that("get correct sig annotations from combined_enrichment", {
134134
expected_sig_combined,
135135
get_significant_annotations(test_combined, pvalues < 0.05)
136136
)
137+
138+
expected_sig = new(
139+
"node_assign",
140+
groups = structure(
141+
c(TRUE, TRUE, FALSE, TRUE, FALSE, TRUE),
142+
dim = 3:2,
143+
dimnames = list(c("G1", "G2", "G3"), c("en1", "en2"))
144+
),
145+
assignments = c(a1 = "G1", a2 = "G3", a3 = "G2", a4 = "G3"),
146+
description = c(a1 = "en1,en2", a2 = "en2", a3 = "en1", a4 = "en2"),
147+
colors = character(0),
148+
color_type = character(0),
149+
pie_locs = NULL
150+
)
151+
expect_equal(
152+
expected_sig,
153+
annotation_combinations(expected_significant_annotations)
154+
)
137155
})
138156

139157

@@ -208,4 +226,26 @@ test_that("get correct sig annotations from combined_enrichment with single case
208226
expected_single_combined,
209227
get_significant_annotations(single_combined, pvalues < 0.05)
210228
)
229+
230+
# check annotation_combinations --------
231+
exp_sig = new(
232+
"node_assign",
233+
groups = structure(
234+
c(TRUE, FALSE),
235+
dim = 2:1,
236+
dimnames = list(
237+
c("G1", "G2"),
238+
"en1"
239+
)
240+
),
241+
assignments = c(a1 = "G1", a2 = "G2", a3 = "G1"),
242+
description = c(a1 = "en1", a2 = "", a3 = "en1"),
243+
colors = character(0),
244+
color_type = character(0),
245+
pie_locs = NULL
246+
)
247+
expect_equal(
248+
exp_sig,
249+
annotation_combinations(expected_significant_annotations)
250+
)
211251
})

vignettes/gsea.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ editor_options:
1010
<!--
1111
% \VignetteEngine{knitr::rmarkdown}
1212
% \VignetteIndexEntry{Gene Set Enrichment Analysis}
13-
% \VignetteDepends{categoryCompare2, GO.db, affy, hgu95av2.db, genefilter, estrogen, limma, Cairo, hgu95av2cdf, fgsea, data.table}
13+
% \VignetteDepends{categoryCompare2, GO.db, affy, hgu95av2.db, genefilter, estrogen, limma, ragg, hgu95av2cdf, fgsea, data.table}
1414
% \VignetteKeyword{categoryCompare, meta-analysis, gene ontology, kegg}
1515
% \VignettePackage{categoryCompare2}
1616
-->

vignettes/v2_guide.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ editor_options:
1010
<!--
1111
% \VignetteEngine{knitr::rmarkdown}
1212
% \VignetteIndexEntry{categoryCompare: High-throughput data meta-analysis using gene annotations, V2}
13-
% \VignetteDepends{categoryCompare2, GO.db, affy, hgu95av2.db, genefilter, estrogen, limma, Cairo, hgu95av2cdf}
13+
% \VignetteDepends{categoryCompare2, GO.db, affy, hgu95av2.db, genefilter, estrogen, limma, ragg, hgu95av2cdf}
1414
% \VignetteKeyword{categoryCompare, meta-analysis, gene ontology, kegg}
1515
% \VignettePackage{categoryCompare2}
1616
-->

0 commit comments

Comments
 (0)