@@ -55,8 +55,9 @@ get_go_enrichment <- function(query_entrez,
55
55
)
56
56
57
57
if (simplify == T ) {
58
- ego <- clusterProfiler :: simplify(ego , cutoff = 0.8 ,
59
- by = " p.adjust" , select_fun = min )
58
+ ego <- clusterProfiler :: simplify(
59
+ ego , cutoff = 0.8 ,
60
+ by = " p.adjust" , select_fun = min )
60
61
}
61
62
62
63
df <- as.data.frame(utils :: head(ego , 5000 ))
@@ -67,6 +68,12 @@ get_go_enrichment <- function(query_entrez,
67
68
df <- df | > dplyr :: mutate(db = ontology )
68
69
}
69
70
if (nrow(df ) > 0 ) {
71
+ assertable :: assert_colnames(
72
+ df , c(" ID" ," Description" ," Count" ,
73
+ " GeneRatio" ," BgRatio" ," pvalue" ,
74
+ " qvalue" ," geneID" ),
75
+ only_colnames = F , quiet = T )
76
+
70
77
df <- suppressWarnings(
71
78
df | >
72
79
dplyr :: mutate(db = paste0(" GO_" , .data $ db )) | >
@@ -75,8 +82,6 @@ get_go_enrichment <- function(query_entrez,
75
82
go_description = " Description" ,
76
83
count = " Count" ,
77
84
gene_ratio = " GeneRatio" ,
78
- rich_factor = " RichFactor" ,
79
- fold_enrichment = " FoldEnrichment" ,
80
85
z_score = " zScore" ,
81
86
background_ratio = " BgRatio" ,
82
87
gene_id = " geneID" ) | >
@@ -85,9 +90,6 @@ get_go_enrichment <- function(query_entrez,
85
90
paste0(' <a href=\' http://amigo.geneontology.org/amigo/term/' ,
86
91
.data $ go_id ,' \' target=\' _blank\' >' ,
87
92
.data $ go_description ,' </a>' )) | >
88
- tidyr :: separate(.data $ gene_ratio ,
89
- c(' num_query_hits' ,' num_query_all' ),
90
- sep = " /" , remove = F , convert = T ) | >
91
93
dplyr :: mutate(qvalue = as.numeric(.data $ qvalue )) | >
92
94
dplyr :: mutate(pvalue = as.numeric(.data $ pvalue )) | >
93
95
dplyr :: mutate(
@@ -103,20 +105,65 @@ get_go_enrichment <- function(query_entrez,
103
105
! is.na(.data $ pvalue ),
104
106
as.numeric(formatC(.data $ pvalue , format = " e" ,
105
107
digits = 1 )),
108
+ as.numeric(NA )))
109
+ )
110
+
111
+ df <- suppressWarnings(
112
+ df | >
113
+ dplyr :: mutate(qvalue = as.numeric(.data $ qvalue )) | >
114
+ dplyr :: mutate(pvalue = as.numeric(.data $ pvalue )) | >
115
+ dplyr :: mutate(
116
+ qvalue =
117
+ dplyr :: if_else(
118
+ ! is.na(.data $ qvalue ),
119
+ as.numeric(formatC(.data $ qvalue , format = " e" ,
120
+ digits = 1 )),
106
121
as.numeric(NA ))) | >
107
- tidyr :: separate(.data $ background_ratio ,
108
- c(' num_background_hits' ,' num_background_all' ),
109
- sep = " /" , remove = F , convert = T ) | >
122
+ dplyr :: mutate(
123
+ pvalue =
124
+ dplyr :: if_else(
125
+ ! is.na(.data $ pvalue ),
126
+ as.numeric(formatC(.data $ pvalue , format = " e" ,
127
+ digits = 1 )),
128
+ as.numeric(NA )))
129
+ )
130
+
131
+ df $ enrichment_factor <- NA
132
+ if (" FoldEnrichment" %in% colnames(df )){
133
+ df <- df | >
134
+ dplyr :: mutate(
135
+ enrichment_factor = round(
136
+ as.numeric(.data $ FoldEnrichment ), digits = 2 )) | >
137
+ dplyr :: select(- c(" FoldEnrichment" ))
138
+ }else {
139
+ df <- df | >
140
+ tidyr :: separate(
141
+ .data $ gene_ratio ,
142
+ c(' num_query_hits' ,' num_query_all' ),
143
+ sep = " /" , remove = F , convert = T ) | >
144
+ tidyr :: separate(
145
+ .data $ background_ratio ,
146
+ c(' num_background_hits' ,' num_background_all' ),
147
+ sep = " /" , remove = F , convert = T ) | >
110
148
dplyr :: mutate(
111
149
enrichment_factor =
112
- round(as.numeric((.data $ num_query_hits / .data $ num_query_all ) /
113
- (.data $ num_background_hits / .data $ num_background_all )),
114
- digits = 1 )) | >
150
+ round(as.numeric((
151
+ .data $ num_query_hits / .data $ num_query_all ) /
152
+ (.data $ num_background_hits / .data $ num_background_all )),
153
+ digits = 2 )) | >
115
154
dplyr :: select(- c(" num_query_hits" ,
116
155
" num_query_all" ,
117
156
" num_background_hits" ,
118
157
" num_background_all" ))
119
- )
158
+
159
+ }
160
+ df $ rich_factor <- NA
161
+ if (" RichFactor" %in% colnames(df )){
162
+ df <- df | >
163
+ dplyr :: mutate(
164
+ rich_factor = as.numeric(.data $ RichFactor )) | >
165
+ dplyr :: select(- c(" RichFactor" ))
166
+ }
120
167
121
168
gene2id <- NULL
122
169
if (! is.null(genedb )) {
@@ -164,6 +211,15 @@ get_go_enrichment <- function(query_entrez,
164
211
df $ setting_p_value_adj_method <- p_value_adjustment_method
165
212
df $ setting_min_geneset_size <- min_geneset_size
166
213
df $ setting_max_geneset_size <- max_geneset_size
214
+
215
+ for (c in oncoEnrichR :: cp_output_cols ){
216
+ if (! (c %in% colnames(df ))){
217
+ df [,c ] <- NA
218
+ }
219
+ }
220
+ df <- df | >
221
+ dplyr :: select(
222
+ dplyr :: any_of(oncoEnrichR :: cp_output_cols ))
167
223
}
168
224
} else {
169
225
df <- NULL
@@ -238,15 +294,18 @@ get_universal_enrichment <- function(query_entrez,
238
294
df <- as.data.frame(utils :: head(enr ,5000 ))
239
295
rownames(df ) <- NULL
240
296
if (nrow(df ) > 0 ) {
297
+ assertable :: assert_colnames(
298
+ df , c(" ID" ," Description" ," Count" ,
299
+ " GeneRatio" ," BgRatio" ," pvalue" ,
300
+ " qvalue" ," geneID" ),
301
+ only_colnames = F , quiet = T )
241
302
df <- suppressWarnings(
242
303
df | >
243
304
dplyr :: rename(
244
305
standard_name = " ID" ,
245
306
description = " Description" ,
246
307
count = " Count" ,
247
308
gene_ratio = " GeneRatio" ,
248
- rich_factor = " RichFactor" ,
249
- fold_enrichment = " FoldEnrichment" ,
250
309
z_score = " zScore" ,
251
310
background_ratio = " BgRatio" ,
252
311
gene_id = " geneID" )
@@ -331,6 +390,21 @@ get_universal_enrichment <- function(query_entrez,
331
390
as.numeric(formatC(.data $ pvalue , format = " e" ,
332
391
digits = 1 )),
333
392
as.numeric(NA ))) | >
393
+ dplyr :: mutate(
394
+ db = dplyr :: if_else(is.na(.data $ db ) &
395
+ nchar(dbsource ) > 0 ,
396
+ dbsource ,
397
+ as.character(.data $ db )))
398
+ )
399
+
400
+ if (" FoldEnrichment" %in% colnames(df )){
401
+ df <- df | >
402
+ dplyr :: mutate(
403
+ enrichment_factor = round(
404
+ as.numeric(.data $ FoldEnrichment ), digits = 2 )) | >
405
+ dplyr :: select(- c(" FoldEnrichment" ))
406
+ }else {
407
+ df <- df | >
334
408
tidyr :: separate(
335
409
.data $ gene_ratio ,
336
410
c(' num_query_hits' ,' num_query_all' ),
@@ -344,17 +418,20 @@ get_universal_enrichment <- function(query_entrez,
344
418
round(as.numeric((
345
419
.data $ num_query_hits / .data $ num_query_all ) /
346
420
(.data $ num_background_hits / .data $ num_background_all )),
347
- digits = 1 )) | >
421
+ digits = 2 )) | >
348
422
dplyr :: select(- c(" num_query_hits" ,
349
423
" num_query_all" ,
350
424
" num_background_hits" ,
351
- " num_background_all" )) | >
425
+ " num_background_all" ))
426
+
427
+ }
428
+ df $ rich_factor <- NA
429
+ if (" RichFactor" %in% colnames(df )){
430
+ df <- df | >
352
431
dplyr :: mutate(
353
- db = dplyr :: if_else(is.na(.data $ db ) &
354
- nchar(dbsource ) > 0 ,
355
- dbsource ,
356
- as.character(.data $ db )))
357
- )
432
+ rich_factor = as.numeric(.data $ RichFactor )) | >
433
+ dplyr :: select(- c(" RichFactor" ))
434
+ }
358
435
359
436
gene2id <- NULL
360
437
if (! is.null(genedb )) {
@@ -392,6 +469,15 @@ get_universal_enrichment <- function(query_entrez,
392
469
df $ setting_p_value_adj_method <- p_value_adjustment_method
393
470
df $ setting_min_geneset_size <- min_geneset_size
394
471
df $ setting_max_geneset_size <- max_geneset_size
472
+
473
+ for (c in oncoEnrichR :: cp_output_cols ){
474
+ if (! (c %in% colnames(df ))){
475
+ df [,c ] <- NA
476
+ }
477
+ }
478
+ df <- df | >
479
+ dplyr :: select(
480
+ dplyr :: any_of(oncoEnrichR :: cp_output_cols ))
395
481
}
396
482
} else {
397
483
df <- NULL
0 commit comments