@@ -7,3 +7,42 @@ get_ratio_variance <- function(expr.matrix, log.expr = FALSE)
7
7
if (! log.expr ) expr.matrix <- log(expr.matrix )
8
8
.Call(ND_RatioVariance , expr.matrix )
9
9
}
10
+
11
+ # ' @export
12
+ URG_getFactor <- function (expr.matrix , p_var = 0.25 , p_gene = 0.4 , log.expr = FALSE )
13
+ {
14
+ if (! log.expr ) {
15
+ expr.matrix [expr.matrix < = 0 ] <- 0.01
16
+ expr.matrix <- log(expr.matrix )
17
+ log.expr <- TRUE
18
+ }
19
+ ratio_var <- get_ratio_variance(expr.matrix , log.expr = log.expr )
20
+ cutoff <- quantile(ratio_var [lower.tri(ratio_var )], p_var )
21
+ adj_matrix <- ifelse(ratio_var < = cutoff , 1 , 0 )
22
+
23
+ g <- igraph :: graph_from_adjacency_matrix(adj_matrix )
24
+ max_component <- which(igraph :: components(g )$ membership == 1 )
25
+ node_degree <- igraph :: degree(g , max_component )
26
+
27
+ n_stable <- min(length(max_component ), round(dim(adj_matrix )[1 ] * p_gene ))
28
+ cutoff <- sort(node_degree , decreasing = TRUE )[n_stable ]
29
+ stable_genes <- max_component [node_degree > = cutoff ]
30
+
31
+ stable_expr <- expr.matrix [stable_genes , , drop = FALSE ]
32
+
33
+ geom <- exp(apply(stable_expr , 2 , mean ))
34
+ mean(geom ) / geom
35
+ }
36
+
37
+ # ' @export
38
+ URG_normalize <- function (expr.matrix , factor , log.expr = FALSE )
39
+ {
40
+ n <- nrow(expr.matrix )
41
+ if (log.expr ) {
42
+ norm.matrix <- expr.matrix + rep(log(factor ), each = n )
43
+ }
44
+ else {
45
+ norm.matrix <- expr.matrix * rep(factor , each = n )
46
+ }
47
+ norm.matrix
48
+ }
0 commit comments