forked from YuLab-SMU/enrichplot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpairwise_termsim.R
63 lines (56 loc) · 2.34 KB
/
pairwise_termsim.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
##' @rdname pairwise_termsim
##' @exportMethod pairwise_termsim
setMethod("pairwise_termsim", signature(x = "enrichResult"),
function(x, method = "JC", semData = NULL, showCategory = 200) {
pairwise_termsim.enrichResult(x, method = method,
semData = semData, showCategory = showCategory)
})
##' @rdname pairwise_termsim
##' @exportMethod pairwise_termsim
setMethod("pairwise_termsim", signature(x = "gseaResult"),
function(x, method = "JC", semData = NULL, showCategory = 200) {
pairwise_termsim.enrichResult(x, method = method,
semData = semData, showCategory = showCategory)
})
##' @rdname pairwise_termsim
##' @exportMethod pairwise_termsim
setMethod("pairwise_termsim", signature(x = "compareClusterResult"),
function(x, method = "JC", semData = NULL, showCategory = 200) {
pairwise_termsim.compareClusterResult(x, method = method,
semData = semData, showCategory = showCategory)
})
##' @rdname pairwise_termsim
pairwise_termsim.enrichResult <- function(x, method = "JC", semData = NULL, showCategory = 200) {
y <- as.data.frame(x)
geneSets <- geneInCategory(x)
n <- update_n(x, showCategory)
if (n == 0) stop("no enriched term found...")
if (is.numeric(n)) {
y <- y[1:n, ]
} else {
y <- y[match(n, y$Description),]
n <- length(n)
}
x@termsim <- get_similarity_matrix(y = y, geneSets = geneSets, method = method,
semData = semData)
x@method <- method
return(x)
}
##' @rdname pairwise_termsim
pairwise_termsim.compareClusterResult <- function(x, method = "JC", semData = NULL,
showCategory = 200) {
y <- fortify(x, showCategory=showCategory, includeAll=TRUE, split=NULL)
y$Cluster <- sub("\n.*", "", y$Cluster)
## y_union <- get_y_union(y = y, showCategory = showCategory)
if ("core_enrichment" %in% colnames(y)) {
y$geneID <- y$core_enrichment
}
y_union <- merge_compareClusterResult(y)
geneSets <- setNames(strsplit(as.character(y_union$geneID), "/",
fixed = TRUE),
y_union$ID)
x@termsim <- get_similarity_matrix(y = y_union, geneSets = geneSets, method = method,
semData = semData)
x@method <- method
return(x)
}