-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathset_enrichment.r
36 lines (29 loc) · 1.15 KB
/
set_enrichment.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
library(dplyr)
b = import('base')
io = import('io')
ar = import('array')
INFILE = commandArgs(TRUE)[1] %or% "../../util/genesets/mapped/go.RData"
EXPR = commandArgs(TRUE)[2] %or% "../../data/expr.RData"
OUTFILE = commandArgs(TRUE)[3] %or% "go.RData"
# load required data
speed = io$load(EXPR)
index = speed$records
expr = speed$expr
genelist = io$load(INFILE)
doGSEA = function(index, expr, sigs) {
library(dplyr)
ar = import('array')
gsea = import('../../util/gsea')
mean_func = function(x) mean(x[index$perturbed]) - mean(x[index$control])
gsea$runGSEA(expr=expr, sigs=sigs) %>% #, normalize=TRUE) %>%
ar$map(along=1, mean_func)
}
scores = clustermq::Q(doGSEA, index=index, expr=expr, const = list(sigs=genelist),
memory = 1024, n_jobs = 50) %>%
setNames(names(index)) %>%
ar$stack(along=1) #%>%
# ar$map(along=1, scale) #%>% # normalize different magnitude of pathways
# ar$map(along=2, scale) # normalize total activation per experiment
filter_index = function(x) x[! names(x) %in% c('control', 'perturbed', 'exclusion')]
index = do.call(bind_rows, lapply(index, filter_index))
save(scores, index, file=OUTFILE)