... | ... |
@@ -39,6 +39,10 @@ make_comb_mat_from_matrix = function(x, mode, top_n_sets = Inf, min_set_size = - |
39 | 39 |
|
40 | 40 |
set_size = set_size[l] |
41 | 41 |
x = x[, l, drop = FALSE] |
42 |
+ |
|
43 |
+ if(ncol(x) > 15) { |
|
44 |
+ stop_wrap("Currently number of sets <= 15 is only supported.") |
|
45 |
+ } |
|
42 | 46 |
|
43 | 47 |
if(is.null(rownames(x))) { |
44 | 48 |
x_has_rownames = FALSE |
... | ... |
@@ -83,7 +87,7 @@ make_comb_mat_from_matrix = function(x, mode, top_n_sets = Inf, min_set_size = - |
83 | 87 |
comb_mat = t(comb_mat) |
84 | 88 |
|
85 | 89 |
nc = ncol(comb_mat) |
86 |
- comb_mat2 = matrix(nrow = nrow(comb_mat), ncol = nc*(nc-1)/2) |
|
90 |
+ comb_mat2 = Matrix::Matrix(0, nrow = nrow(comb_mat), ncol = nc*(nc-1)/2, sparse = TRUE) |
|
87 | 91 |
rownames(comb_mat2) = rownames(comb_mat) |
88 | 92 |
if(mode == "intersect") { |
89 | 93 |
if(nc > 1) { |
... | ... |
@@ -171,6 +175,9 @@ make_comb_mat_from_list = function(lt, mode, value_fun = length, top_n_sets = In |
171 | 175 |
min_set_size = -Inf, universal_set = NULL, complement_size = NULL) { |
172 | 176 |
|
173 | 177 |
n = length(lt) |
178 |
+ if(n > 15) { |
|
179 |
+ stop_wrap("Currently number of sets <= 15 is only supported.") |
|
180 |
+ } |
|
174 | 181 |
nm = names(lt) |
175 | 182 |
if(is.null(nm)) { |
176 | 183 |
stop_wrap("The list must have names.") |
... | ... |
@@ -216,7 +223,7 @@ make_comb_mat_from_list = function(lt, mode, value_fun = length, top_n_sets = In |
216 | 223 |
complement_size = value_fun(complement_set) |
217 | 224 |
} |
218 | 225 |
|
219 |
- comb_mat = matrix(FALSE, nrow = n, ncol = sum(choose(n, 1:n))) |
|
226 |
+ comb_mat = Matrix::Matrix(FALSE, nrow = n, ncol = sum(choose(n, 1:n)), s) |
|
220 | 227 |
rownames(comb_mat) = nm |
221 | 228 |
j = 1 |
222 | 229 |
for(k in 1:n) { |
... | ... |
@@ -442,9 +449,7 @@ make_comb_mat = function(..., mode = c("distinct", "intersect", "union"), |
442 | 449 |
value_fun = length |
443 | 450 |
} |
444 | 451 |
} |
445 |
- if(length(lt) > 10) { |
|
446 |
- stop_wrap("Currently number of sets <= 10 is only supported.") |
|
447 |
- } |
|
452 |
+ |
|
448 | 453 |
m = make_comb_mat_from_list(lt, value_fun, mode = mode, top_n_sets = top_n_sets, min_set_size = min_set_size, |
449 | 454 |
universal_set = universal_set, complement_size = complement_size) |
450 | 455 |
if(remove_empty_comb_set) { |
... | ... |
@@ -541,6 +546,7 @@ comb_size = function(m, degree = NULL) { |
541 | 546 |
# |
542 | 547 |
# == param |
543 | 548 |
# -m A combination matrix returned by `make_comb_mat`. |
549 |
+# -readable Whether the combination represents as e.g. "A&B&C". |
|
544 | 550 |
# |
545 | 551 |
# == details |
546 | 552 |
# The name of the combination sets are formatted as a string |
... | ... |
@@ -559,13 +565,25 @@ comb_size = function(m, degree = NULL) { |
559 | 565 |
# c = sample(letters, 20)) |
560 | 566 |
# m = make_comb_mat(lt) |
561 | 567 |
# comb_name(m) |
562 |
-comb_name = function(m) { |
|
568 |
+# comb_name(m, readable = TRUE) |
|
569 |
+comb_name = function(m, readable = FALSE) { |
|
563 | 570 |
set_on_rows = attr(m, "set_on_rows") |
564 | 571 |
if(set_on_rows) { |
565 |
- apply(m, 2, paste, collapse = "") |
|
572 |
+ nm = apply(m, 2, paste, collapse = "") |
|
566 | 573 |
} else { |
567 |
- apply(m, 1, paste, collapse = "") |
|
574 |
+ nm = apply(m, 1, paste, collapse = "") |
|
568 | 575 |
} |
576 |
+ |
|
577 |
+ if(readable) { |
|
578 |
+ sn = set_name(m) |
|
579 |
+ nm = sapply(strsplit(nm, ""), function(x) { |
|
580 |
+ l = as.logical(as.numeric(x)) |
|
581 |
+ paste(sn[l], collapse = "&") |
|
582 |
+ } |
|
583 |
+ nm = unname(nm) |
|
584 |
+ } |
|
585 |
+ |
|
586 |
+ return(nm) |
|
569 | 587 |
} |
570 | 588 |
|
571 | 589 |
# == title |