9
9
# ' @param n_layers The number of layers that will be propagated upstream.
10
10
# ' @param n_perm The number of permutations to use in decoupleR's algorithm.
11
11
# ' @param downstream_cutoff If downstream measurments should be included above a given threshold
12
+ # ' @param statistic the decoupleR stat to consider: "wmean", "norm_wmean", or "ulm"
12
13
# '
13
14
# ' @return A data frame containing the score of the nodes upstream of the
14
15
# ' downstream input based on the iterative propagation
30
31
# '
31
32
# ' # View the results
32
33
# ' print(result)
33
- decoupleRnival <- function (upstream_input = NULL , downstream_input , meta_network , n_layers , n_perm = 1000 , downstream_cutoff = 0 ){
34
+ decoupleRnival <- function (upstream_input = NULL , downstream_input , meta_network , n_layers , n_perm = 1000 , downstream_cutoff = 0 , statistic = " norm_wmean " ){
34
35
35
36
36
37
regulons <- meta_network
37
38
38
39
names(regulons )[names(regulons ) == " sign" | names(regulons ) == " interaction" ] <- " mor"
39
40
regulons <- regulons [! (regulons $ source %in% names(downstream_input )),]
40
41
41
- n_plus_one <- run_wmean(mat = as.matrix(data.frame (downstream_input )), network = regulons , times = n_perm , minsize = 1 )
42
- n_plus_one <- n_plus_one [n_plus_one $ statistic == " norm_wmean" ,c(2 ,4 )]
42
+ switch (statistic ,
43
+ " norm_wmean" = {
44
+ n_plus_one <- run_wmean(mat = as.matrix(data.frame (downstream_input )), network = regulons , times = n_perm , minsize = 1 )
45
+ },
46
+ " wmean" = {
47
+ n_plus_one <- run_wmean(mat = as.matrix(data.frame (downstream_input )), network = regulons , times = 2 , minsize = 1 )
48
+ },
49
+ " ulm" = {
50
+ n_plus_one <- run_ulm(mat = as.matrix(data.frame (downstream_input )), network = regulons , minsize = 1 )
51
+ })
52
+
53
+ n_plus_one <- n_plus_one [n_plus_one $ statistic == statistic ,c(2 ,4 )]
43
54
# regulons <- regulons[!(regulons$source %in% n_plus_one$source),]
44
55
45
56
res_list <- list ()
@@ -52,8 +63,17 @@ decoupleRnival <- function(upstream_input = NULL, downstream_input, meta_network
52
63
previous_n_plu_one <- res_list [[i - 1 ]]
53
64
row.names(previous_n_plu_one ) <- previous_n_plu_one $ source
54
65
previous_n_plu_one <- previous_n_plu_one [,- 1 ,drop = F ]
55
- n_plus_one <- run_wmean(mat = as.matrix(previous_n_plu_one ), network = regulons , times = n_perm , minsize = 1 )
56
- n_plus_one <- n_plus_one [n_plus_one $ statistic == " norm_wmean" ,c(2 ,4 )]
66
+ switch (statistic ,
67
+ " norm_wmean" = {
68
+ n_plus_one <- run_wmean(mat = as.matrix(previous_n_plu_one ), network = regulons , times = n_perm , minsize = 1 )
69
+ },
70
+ " wmean" = {
71
+ n_plus_one <- run_wmean(mat = as.matrix(previous_n_plu_one ), network = regulons , times = 2 , minsize = 1 )
72
+ },
73
+ " ulm" = {
74
+ n_plus_one <- run_ulm(mat = as.matrix(previous_n_plu_one ), network = regulons , minsize = 1 )
75
+ })
76
+ n_plus_one <- n_plus_one [n_plus_one $ statistic == statistic ,c(2 ,4 )]
57
77
regulons <- regulons [! (regulons $ source %in% n_plus_one $ source ),]
58
78
res_list [[i ]] <- as.data.frame(n_plus_one )
59
79
i <- i + 1
@@ -268,3 +288,71 @@ meta_network_cleanup <- function(meta_network)
268
288
meta_network <- meta_network [meta_network $ interaction %in% c(1 ,- 1 ),]
269
289
return (meta_network )
270
290
}
291
+
292
+ # ' translate_res
293
+ # '
294
+ # ' formats the network with readable names
295
+ # '
296
+ # ' @param SIF result SIF of decoupleRnival pipeline
297
+ # ' @param ATT result ATT of decoupleRnival pipeline
298
+ # ' @param metab_mapping a named vector with HMDB Ids as names and desired metabolite names as values.
299
+ # ' @return list with network and attribute tables.
300
+ # ' @importFrom stringr str_extract
301
+ # ' @export
302
+ # '
303
+ # ' @examples
304
+ # ' # Create a meta network data frame
305
+ # ' example_SIF <- data.frame(
306
+ # ' source = c("GPX1", "Gene863__GPX1"),
307
+ # ' target = c("Gene863__GPX1", "Metab__HMDB0003337_c"),
308
+ # ' sign = c(1, 1)
309
+ # ' )
310
+ # '
311
+ # ' example_ATT <- data.frame(
312
+ # ' Nodes = c("GPX1", "Gene863__GPX1","Metab__HMDB0003337_c"),
313
+ # ' sign = c(1, 1, 1)
314
+ # ' )
315
+ # '
316
+ # ' example_SIF
317
+ # '
318
+ # ' data("HMDB_mapper_vec")
319
+ # '
320
+ # ' translated_res <- translate_res(example_SIF,example_ATT,HMDB_mapper_vec)
321
+ # '
322
+ # ' translated_res$SIF
323
+ translate_res <- function (SIF ,ATT ,HMDB_mapper_vec = NULL )
324
+ {
325
+ if (is.null(HMDB_mapper_vec )) {
326
+ data(" HMDB_mapper_vec" , package = " cosmosR" , envir = environment())
327
+ }
328
+ colnames(ATT )[1 ] <- " Nodes"
329
+ for (i in c(1 , 2 )) {
330
+ SIF [, i ] <- sapply(SIF [, i ], function (x , HMDB_mapper_vec ) {
331
+ x <- gsub(" Metab__" , " " , x )
332
+ x <- gsub(" ^Gene" , " Enzyme" , x )
333
+ suffixe <- stringr :: str_extract(x , " _[a-z]$" )
334
+ x <- gsub(" _[a-z]$" , " " , x )
335
+ if (x %in% names(HMDB_mapper_vec )) {
336
+ x <- HMDB_mapper_vec [x ]
337
+ x <- paste(" Metab__" , paste(x , suffixe , sep = " " ),
338
+ sep = " " )
339
+ }
340
+ return (x )
341
+ }, HMDB_mapper_vec = HMDB_mapper_vec )
342
+ }
343
+ ATT [, 1 ] <- sapply(ATT [, 1 ], function (x , HMDB_mapper_vec ) {
344
+ x <- gsub(" Metab__" , " " , x )
345
+ x <- gsub(" ^Gene" , " Enzyme" , x )
346
+ suffixe <- stringr :: str_extract(x , " _[a-z]$" )
347
+ x <- gsub(" _[a-z]$" , " " , x )
348
+ if (x %in% names(HMDB_mapper_vec )) {
349
+ x <- HMDB_mapper_vec [x ]
350
+ x <- paste(" Metab__" , x , sep = " " )
351
+ }
352
+ if (! is.na(suffixe )) {
353
+ x <- paste(x , suffixe , sep = " " )
354
+ }
355
+ return (x )
356
+ }, HMDB_mapper_vec = HMDB_mapper_vec )
357
+ return (list (" SIF" = SIF , " ATT" = ATT ))
358
+ }
0 commit comments