Skip to content

Commit

Permalink
Fixes issue #22 with getGOsize reporting wrong GO term size
Browse files Browse the repository at this point in the history
  • Loading branch information
ssayols committed Dec 15, 2023
1 parent 35e2117 commit cd08892
Show file tree
Hide file tree
Showing 64 changed files with 96 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rrvgo
Type: Package
Title: Reduce + Visualize GO
Version: 1.13.4
Version: 1.15.1
Authors@R: c(person("Sergi", "Sayols", email = "[email protected]", role = c("aut", "cre")), person("Sara", "Elmeligy", role = "ctb"))
Description: Reduce and visualize lists of Gene Ontology terms by identifying redudance based on semantic similarity.
URL: https://www.bioconductor.org/packages/rrvgo, https://ssayols.github.io/rrvgo/index.html
Expand Down
23 changes: 10 additions & 13 deletions R/rrvgo.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ calculateSimMatrix <- function(x,
#' orgdb object itself)
#' @param keytype keytype passed to AnnotationDbi::keys to retrieve GO terms
#' associated to gene ids in your orgdb
#' @param children when retrieving GO term size, include genes in children terms.
#' (based on relationships in the GO DAG hierarchy). Defaults to TRUE
#' @return a data.frame identifying the different clusters of terms, the parent
#' term representing the cluster, and some metrics of importance describing how
#' unique and dispensable a term is.
Expand All @@ -102,7 +104,7 @@ calculateSimMatrix <- function(x,
#' @importFrom stats cutree hclust
#' @export
reduceSimMatrix <- function(simMatrix, scores=c("uniqueness", "size"),
threshold=0.7, orgdb, keytype="ENTREZID") {
threshold=0.7, orgdb, keytype="ENTREZID", children=TRUE) {

# check function arguments
if(is(scores, "character")) {
Expand All @@ -115,7 +117,7 @@ reduceSimMatrix <- function(simMatrix, scores=c("uniqueness", "size"),
cluster <- cutree(hclust(as.dist(1 - simMatrix)), h=threshold)

# get category size and term uniqueness, and use it as scores if they were not provided
sizes <- getGoSize(rownames(simMatrix), orgdb, keytype)
sizes <- getGoSize(rownames(simMatrix), orgdb, keytype, children)
termUniq <- getTermUniq(simMatrix, cluster)
if(is(scores, "character")) {
scores <- switch(scores,
Expand Down Expand Up @@ -194,27 +196,22 @@ getTermDisp <- function(simMatrix, cluster, clusterRep) {
#' package itself)
#' @param keytype keytype passed to AnnotationDbi::keys to retrieve GO terms
#' associated to gene ids in your orgdb
#' @param children include genes in children terms (based on relationships in
#' the GO DAG hierarchy)
#' @importFrom AnnotationDbi select keys
#' @importFrom stats setNames
#' @importFrom methods is
#' @return number of genes associated with each term
getGoSize <- function(terms, orgdb, keytype) {
getGoSize <- function(terms, orgdb, keytype, children) {
if(all(is(orgdb) != "OrgDb")) {
orgdb <- loadOrgdb(orgdb)
}

# get all GO terms with genes associated
go <- suppressMessages(
AnnotationDbi::select(orgdb,
keytype=keytype,
columns=c("GO", "ONTOLOGY"),
keys=AnnotationDbi::keys(orgdb, keytype=keytype)))
go <- go[!is.na(go$GO), ]
go <- go[go$GO %in% terms, ]
# retrieve genes per term and count unique genes within each term
go <- AnnotationDbi::select(orgdb, keytype=if(children) "GOALL" else "GO", keys=terms, columns=keytype)

# count
counts <- table(go$GO)
go <- go[go$GO %in% terms, ]
counts <- tapply(go$ENTREZID, go$GO, function(x) length(unique(x)))
empty <- terms[!(terms %in% names(counts))]
nocounts <- setNames(rep(0, length(empty)), empty)

Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 36 additions & 35 deletions docs/articles/rrvgo.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified docs/articles/rrvgo_files/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/rrvgo_files/figure-html/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
rrvgo: rrvgo.html
last_built: 2023-10-17T12:00Z
last_built: 2023-12-15T12:18Z

Binary file modified docs/reference/Rplot001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/reference/calculateSimMatrix.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions docs/reference/getGoSize.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/getGoTerm.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/getTermDisp.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/getTermUniq.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/gg_color_hue.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd08892

Please sign in to comment.