Skip to content

Commit 06b3cc3

Browse files
committed
Add URG functions
1 parent 6d56960 commit 06b3cc3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(URG_getFactor)
4+
export(URG_normalize)
35
export(best_subnets)
46
export(column)
57
export(extend_subnets)

R/deg_normalization.R

+39
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,42 @@ get_ratio_variance <- function(expr.matrix, log.expr = FALSE)
77
if (!log.expr) expr.matrix <- log(expr.matrix)
88
.Call(ND_RatioVariance, expr.matrix)
99
}
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

Comments
 (0)