Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/montilab/hypeR into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Monti committed Sep 18, 2023
2 parents 0f5ae2e + 73b639a commit 9fceb9d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
- R_BUILD_ARGS="--no-build-vignettes --no-manual"
- R_CHECK_ARGS="--no-build-vignettes --no-manual --timings"
- _R_CHECK_TIMINGS_="0"
- R_DEFAULT_INTERNET_TIMEOUT="300"

r:
- release
Expand Down
40 changes: 22 additions & 18 deletions R/ggeplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
#' @importFrom ggplot2 qplot aes geom_rug geom_hline geom_vline annotate theme element_text element_blank element_line element_rect
#'
#' @export
ggeplot <- function(n, positions, x_axis, y_axis, title="") {
score <- which.max(abs(y_axis))
qplot(x_axis,
y_axis,
main=title,
ylab="Running Enrichment Score",
xlab="Position in Ranked List of Genes",
geom="line")+
geom_rug(data=data.frame(positions), aes(x=positions), inherit.aes=FALSE)+
geom_hline(yintercept=0) +
geom_vline(xintercept=n/2, linetype="dotted") +
annotate("point", x=x_axis[score], y=y_axis[score], color="red") +
annotate("text", x=x_axis[score]+n/20, y=y_axis[score], label=round(y_axis[score],2)) +
annotate("point", x=x_axis[score], y=y_axis[score], color="red") +
theme(plot.title=element_text(hjust=0.5),
panel.background=element_blank(),
axis.line=element_line(color="black"),
panel.border=element_rect(color="black", fill=NA, size=1))
ggeplot <- function(n, positions, x_axis, y_axis, title = "") {
score <- which.max(abs(y_axis))
DF <- data.frame(x_axis = x_axis, y_axis = y_axis)
ggplot2::ggplot(DF, aes(x = x_axis, y = y_axis)) +
ggplot2::geom_line() +
ggplot2::labs(
title = title,
y = "Running Enrichment Score",
x = "Position in Ranked List of Genes"
) +
ggplot2::geom_rug(data = data.frame(positions), aes(x = positions), inherit.aes = FALSE) +
ggplot2::geom_hline(yintercept = 0) +
ggplot2::geom_vline(xintercept = n / 2, linetype = "dotted") +
ggplot2::annotate("point", x = x_axis[score], y = y_axis[score], color = "red") +
ggplot2::annotate("text", x = x_axis[score] + n / 20, y = y_axis[score], label = round(y_axis[score], 2)) +
ggplot2::annotate("point", x = x_axis[score], y = y_axis[score], color = "red") +
ggplot2::theme(
plot.title = ggplot2::element_text(hjust = 0.5),
panel.background = ggplot2::element_blank(),
axis.line = ggplot2::element_line(color = "black"),
panel.border = ggplot2::element_rect(color = "black", fill = NA, linewidth = 1)
)
}
2 changes: 1 addition & 1 deletion R/ggvenn.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ggvenn <- function(a, b, ga, gb, title="") {
paste(gb, " (", x.b, ")", sep=""))) %>%

ggplot(aes(x0=x, y0=y, r=c(r.a, r.b), fill=groups)) +
geom_circle(alpha=0.3, size=0.5) +
geom_circle(alpha=0.3, linewidth=0.5) +
coord_fixed() +
theme_void() +
theme(plot.title=element_text(hjust=0.5),
Expand Down
37 changes: 18 additions & 19 deletions tests/testthat/test-hyp_to_table.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
test_that("hyp_to_table() is working", {
testdat <- readRDS(file.path(system.file("extdata", package = "hypeR"), "testdat.rds"))
gsets_obj <- testdat$gsets
rgsets_obj <- testdat$rgsets

testdat <- readRDS(file.path(system.file("extdata", package="hypeR"), "testdat.rds"))
gsets_obj <- testdat$gsets
rgsets_obj <- testdat$rgsets

signature <- testdat$signature
experiment <- testdat$experiment

hyp_obj <- hypeR(signature, gsets_obj)
multihyp_obj <- hypeR(experiment, rgsets_obj)

# A single file
hyp_to_table(hyp_obj, file_path="signature.txt", sep="\t")
expect_true(file.exists("signature.txt"))

# Multiple files within a directory
hyp_to_table(multihyp_obj, file_path="experiment", sep="\t")
expect_true(file.exists("experiment/Signature 1.txt"))
expect_true(file.exists("experiment/Signature 2.txt"))
expect_true(file.exists("experiment/Signature 3.txt"))
signature <- testdat$signature
experiment <- testdat$experiment

hyp_obj <- hypeR(signature, gsets_obj)
multihyp_obj <- hypeR(experiment, rgsets_obj)

# A single file
hyp_to_table(hyp_obj, file_path = "signature.txt", sep = "\t")
expect_true(file.exists("signature.txt"))

# Multiple files within a directory
hyp_to_table(multihyp_obj, file_path = "experiment", sep = "\t")
expect_true(file.exists("experiment/Signature 1.txt"))
expect_true(file.exists("experiment/Signature 2.txt"))
expect_true(file.exists("experiment/Signature 3.txt"))
})

0 comments on commit 9fceb9d

Please sign in to comment.