4
4
# ' @param config Config object
5
5
# ' @param cores Number of cores to run it on
6
6
# ' @param sep Character to separate res_list names
7
+ # ' @param universe_list List of vectors for background genes
7
8
# '
8
9
# ' @return nested list of enrichResult objects
9
10
run_enricher <- function (res_list , ontology_list , config ,
10
- cores = 1 , sep = ' *' ){
11
+ cores = 1 , sep = ' *' , universe_list = universe_list ){
11
12
# This function supports running in parallel which works best with a flat
12
13
# list; however for organizational purposese we want a nested structure. So
13
14
# we convert between the two by collapsing nested keys for flat list, and
@@ -42,7 +43,8 @@ run_enricher <- function(res_list, ontology_list, config,
42
43
direction = direction ,
43
44
TERM2GENE = ontology_list [[' term2gene' ]][[ont ]],
44
45
TERM2NAME = ontology_list [[' term2name' ]][[ont ]],
45
- config = config
46
+ config = config ,
47
+ universe = universe_list [[name ]]
46
48
)
47
49
enrich_res
48
50
}, BPPARAM = BiocParallel :: MulticoreParam(cores ))
@@ -86,6 +88,21 @@ collapse_names <- function(res_list, config, sep='*'){
86
88
return (names )
87
89
}
88
90
91
+
92
+ # ' Function to retrieve genes with non-zero raw counts in one or more samples
93
+ # '
94
+ # ' @param dds DESeqDataSet object
95
+ # '
96
+ # ' @return a vector containing gene IDs with raw counts are greater than 0 in one or more samples
97
+ nonzero_genes <- function (dds ) {
98
+ # Extract raw count matrix
99
+ counts <- DESeq2 :: counts(dds , normalized = FALSE )
100
+ # Subset rows where rowsums are greater than zero
101
+ counts <- counts [rowSums(counts ) > 0 ,]
102
+ # Return gene IDs
103
+ return (rownames(counts ))
104
+ }
105
+
89
106
# ' All-in-one enrichment function.
90
107
# '
91
108
# ' Designed to not require an orgdb, and instead requires dataframes of
@@ -101,11 +118,13 @@ collapse_names <- function(res_list, config, sep='*'){
101
118
# ' lfc_thresh from the config.
102
119
# ' @param kind One of "OR" for overrepresentation or "GSEA" for gene set
103
120
# ' enrichment analysis.
121
+ # ' @param universe background genes. If missing, all genes listed in the database
122
+ # ' (e.g. TERM2GENE table) will be used as background.
104
123
# ' @param ... Additional arguments are passed on to enricher() for kind="OR" or
105
124
# ' GSEA() for kind="GSEA".
106
125
# '
107
126
# ' @return An enrichResults object from
108
- enrich_test <- function (res , TERM2GENE , TERM2NAME , config , direction , kind = ' OR' , ... ){
127
+ enrich_test <- function (res , TERM2GENE , TERM2NAME , config , direction , kind = ' OR' , universe , ... ){
109
128
110
129
if (is.null(config $ main $ lfc_thresh )){
111
130
lfc_thresh <- 0
@@ -128,6 +147,7 @@ enrich_test <- function(res, TERM2GENE, TERM2NAME, config, direction, kind='OR',
128
147
TERM2NAME = TERM2NAME ,
129
148
pvalueCutoff = config $ functional_enrichment $ pvalueCutoff ,
130
149
qvalueCutoff = config $ functional_enrichment $ qvalueCutoff ,
150
+ universe = universe ,
131
151
...
132
152
)
133
153
} else if (kind == " GSEA" ){
@@ -141,6 +161,7 @@ enrich_test <- function(res, TERM2GENE, TERM2NAME, config, direction, kind='OR',
141
161
TERM2GENE = TERM2GENE ,
142
162
TERM2NAME = TERM2NAME ,
143
163
pvalueCutoff = config $ functional_enrichment $ pvalueCutoff ,
164
+ universe = universe ,
144
165
...
145
166
)
146
167
0 commit comments