Skip to content

Commit 5f5a63a

Browse files
committedApr 2, 2021
first finish
1 parent 0c4de4b commit 5f5a63a

9 files changed

+75
-62
lines changed
 

‎NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(geom_gsea)
4+
export(geom_gseaGradient)
45
export(geom_gseaLine)
56
export(geom_gseaTicks)
67
export(gseaCurve)

‎R/geom_gsea.R

+24-23
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,39 @@
2323
#'
2424
#' curve <- gseaCurve()
2525
#'
26-
geom_gsea <- function(df, withTicks=T, withGradient=T, prettyGSEA=T, ...){
26+
geom_gsea <- function(df, prettyGSEA=T, ...){
2727

2828
gseaLine <- geom_gseaLine(df, ...)
29-
main <- list(gseaLine)
29+
ticks <- geom_gseaTicks(df[!is.na(df$y1ticks), ], ...)
30+
gradient <- geom_gseaGradient(df[!is.na(df$y1gradient), ], ...)
3031

31-
if(withTicks){
32-
ticks <- geom_gseaTicks(df, ...)
33-
main <- c(main, ticks)
34-
}
35-
36-
if(withGradient){
37-
gradient <- geom_gseaTicks(df, ...)
38-
main <- c(main, gradient)
39-
}
32+
main <- list(gseaLine, ticks, gradient)
4033

34+
# beautify the graph
4135
if(prettyGSEA){
42-
maxES <- max(df$y)
43-
minES <- min(df$y)
44-
sizeFactor <- abs(maxES - minES)
45-
46-
ystepsize <- signif(sizeFactor/3, digits=1) #round the sizefactor fraction to the nearest digit
47-
nDown <- round(minES / ystepsize) #number of ticks below 0
48-
nUp <- round(maxES / ystepsize) # number of ticks above 0
49-
breaks <- c(
50-
seq(from = 0, to = -nDown * ystepsize, by = ystepsize),
51-
seq(from = 0, to = nUp * ystepsize, by = ystepsize)
52-
)
36+
37+
break_fun <- function(y){
38+
maxY <- max(y) #important: y is not the y in the aes, but rather the maximum and minimum y values on the entire graph
39+
minY <- min(y)
40+
sizeFactor <- abs(maxY-minY)
41+
minY <- minY + sizeFactor * 0.22
42+
ystepsize <- signif(sizeFactor/4, digits=1) #round the sizefactor fraction to the nearest digit
43+
44+
nDown <- ceiling(minY / ystepsize) #number of ticks below 0
45+
nUp <- round(maxY / ystepsize) # number of ticks above 0
46+
breaks <- c(
47+
seq(from = nDown * ystepsize, to = 0, by = ystepsize),
48+
seq(from = 0, to = nUp * ystepsize, by = ystepsize)
49+
)
50+
51+
return(breaks)
52+
}
5353

5454
main <- c(list(
55+
geom_hline( mapping = aes(yintercept=bottomline), data = df[!duplicated(df$set),] ),
5556
geom_hline(yintercept=0),
5657
labs(x="rank", y="enrichment score"),
57-
scale_y_continuous(breaks=breaks),
58+
scale_y_continuous(breaks=break_fun),
5859
main
5960
))
6061
}

‎R/gseaCurve.R

+9-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#' Imports:
44
#' grDevices
55
#'
6-
#' @inheritParams geom_gsea
7-
#'
86
#' @param rl named(!), sorted(!) vector. This ranked list's Values are the ranking metric (e.g. log2FC), names are the genes IDs. Gene IDs have to be of the same type as the ones in setList.
97
#' @param setlist names(!) list of character vectors. Each vector is a gene signature, each item in that vector is a gene ID (same type as the ones in rl!)
108
#' @param weight number, the higher the more important are the changes at the extremes. 0: no weight, i.e. each found gene counts the same. 1: each gene counts according to its metric. 2: genes counts according to their squared matric, etc.
@@ -19,7 +17,7 @@
1917
#'
2018
#'
2119
#'
22-
gseaCurve <- function(rl, setlist, weight=1, withTicks=T, withGradient=T){
20+
gseaCurve <- function(rl, setlist, weight=1){
2321

2422
dfList <- mapply(function(set, setname){
2523
if( sum(set %in% names(rl))==0 ) stop("None of the genes in the ranked list are present in the set.")
@@ -51,17 +49,15 @@ gseaCurve <- function(rl, setlist, weight=1, withTicks=T, withGradient=T){
5149
maxES <- max(df$y)
5250
minES <- min(df$y)
5351
sizeFactor <- abs(maxES - minES)
54-
lowestPoint <- minES
52+
lowestPoint <- minES - sizeFactor / 30
53+
54+
df$bottomline <- lowestPoint
5555

56-
if(withTicks){#incluce into df the data fro the ticks
57-
df <- merge(df, .presenceTicks(rl, set, lowestPoint, sizeFactor), by="x", all=T)
58-
lowestPoint <- min(df$y2ticks, na.rm=TRUE)
59-
}
56+
df <- merge(df, .presenceTicks(rl, set, lowestPoint, sizeFactor), by="x", all=TRUE)
57+
lowestPoint <- min(df$y2ticks, na.rm=TRUE)
58+
df <- merge(df, .colorGradient(rl, lowestPoint, sizeFactor), by="x", all=TRUE)
6059

61-
if(withGradient){#include into df the data for the colorGradient
62-
df <- merge(df, .colorGradient(rl, lowestPoint, sizeFactor), by="x", all=T)
63-
lowestPoint <- df$y2gradient[1]
64-
}
60+
return(df)
6561

6662
}, set=setlist, setname=names(setlist), SIMPLIFY=FALSE)
6763

@@ -101,7 +97,7 @@ gseaCurve <- function(rl, setlist, weight=1, withTicks=T, withGradient=T){
10197
#gradient <- gradient[-nrow(gradient),]
10298

10399
# 4) add y column, which will be the same for all. The y position will only be influenced by the ES values (i.e. where the curve is)
104-
gradient$y1gradient <- lowestPoint - sizeFactor / 40 #multiplying by the sizefactor is necessary to keep the gradient height and position the same in every graph
100+
gradient$y1gradient <- lowestPoint #multiplying by the sizefactor is necessary to keep the gradient height and position the same in every graph
105101
gradient$y2gradient <- lowestPoint - sizeFactor / 8
106102

107103
return(gradient)

‎data/myRankedlist.RData

133 KB
Binary file not shown.

‎data/mySetlist.RData

59 Bytes
Binary file not shown.

‎man/geom_gsea.Rd

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/geom_gseaGradient.Rd

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/geom_gseaTicks.Rd

+2-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/gseaCurve.Rd

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.