diff --git a/.gitignore b/.gitignore index ad8a3f2..3127534 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ user_manual/cache *.swp .Rhistory .RData +.Rproj.user/ /doc/ /Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index cf15211..56a5f6d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,12 @@ VignetteBuilder: knitr Imports: beeswarm,tagcloud,XML,methods,plotwidgets,RColorBrewer,gplots,tibble,pheatmap,ggplot2,tidyr,purrr,rlang,tidyselect,ggrepel Suggests: - testthat,knitr,rmarkdown,dplyr,pander,cowplot + testthat, + knitr, + rmarkdown, + dplyr, + pander, + cowplot, + vdiffr RoxygenNote: 7.3.2 Encoding: UTF-8 diff --git a/R/visualizations.R b/R/visualizations.R index c68699f..b79b788 100644 --- a/R/visualizations.R +++ b/R/visualizations.R @@ -523,7 +523,7 @@ ggEvidencePlot <- function(l, m, mset=NULL, filter=FALSE, unique=TRUE, mm <- map(mm, ~ .x[ .x %in% l_orig ]) coords <- imap_dfr(mm, ~ { - pos <- sort(match(.x, l_orig)) - 1:length(.x) + pos <- sort(match(.x, l_orig)) pos <- rep(pos, each=2) pos <- c(1, pos, length(l_orig)) y <- rep(c(0:length(.x)), each=2) / length(.x) @@ -533,7 +533,7 @@ ggEvidencePlot <- function(l, m, mset=NULL, filter=FALSE, unique=TRUE, coords_segm <- imap_dfr(mm, ~ { .match <- match(.x, l_orig) .ord <- order(.match) - x <- sort(.match) - 1:length(.x) + x <- sort(.match) ret <- data.frame(x=x, y=-.1, xend=x, yend=0, "mod"=.y, label=.x[.ord], gene=.x[.ord]) if(!is.null(gene.labels) && !gene.labels) { ret$label <- "" diff --git a/tests/testthat/_snaps/visualisations/ggevidenceplot.svg b/tests/testthat/_snaps/visualisations/ggevidenceplot.svg new file mode 100644 index 0000000..2e191dc --- /dev/null +++ b/tests/testthat/_snaps/visualisations/ggevidenceplot.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + +0.0 +2.5 +5.0 +7.5 +10.0 +Gene list +Fraction of gene set + +Gene set + + + +a + + + +a +diseaseA +diseaseB +ggEvidencePlot + + diff --git a/tests/testthat/test_visualisations.R b/tests/testthat/test_visualisations.R index 92f3d5c..059fbc8 100644 --- a/tests/testthat/test_visualisations.R +++ b/tests/testthat/test_visualisations.R @@ -4,3 +4,23 @@ data(tmod) context("Visualisations") +test_that("ggEvidencePlot works", { + skip_if_not_installed("vdiffr") + + genesets <- data.frame( + gene_symbol = paste0("gene", 1:10), + geneset = c(rep("diseaseA", 3), rep("diseaseB", 3), rep("diseaseC", 4)) + ) + ranked_genes <- paste0("gene", 1:10) + + tmod_db <- makeTmodFromDataFrame(genesets) + + p <- ggEvidencePlot( + ranked_genes, + m = c("diseaseA", "diseaseB"), + mset = tmod_db, + gene.labels = FALSE + ) + + vdiffr::expect_doppelganger("ggEvidencePlot", p) +})