... | ... |
@@ -1,8 +1,8 @@ |
1 | 1 |
Package: ComplexHeatmap |
2 | 2 |
Type: Package |
3 | 3 |
Title: Make Complex Heatmaps |
4 |
-Version: 1.99.4 |
|
5 |
-Date: 2018-12-10 |
|
4 |
+Version: 1.99.5 |
|
5 |
+Date: 2018-12-26 |
|
6 | 6 |
Author: Zuguang Gu |
7 | 7 |
Maintainer: Zuguang Gu <z.gu@dkfz.de> |
8 | 8 |
Depends: R (>= 3.1.2), methods, grid, graphics, stats, grDevices |
... | ... |
@@ -10,6 +10,8 @@ S3method("[", "HeatmapList") |
10 | 10 |
export("[.HeatmapList") |
11 | 11 |
S3method("[", "SingleAnnotation") |
12 | 12 |
export("[.SingleAnnotation") |
13 |
+S3method("[", "comb_mat") |
|
14 |
+export("[.comb_mat") |
|
13 | 15 |
S3method("c", "HeatmapAnnotation") |
14 | 16 |
export("c.HeatmapAnnotation") |
15 | 17 |
S3method("dim", "Heatmap") |
... | ... |
@@ -62,6 +64,8 @@ S3method("nobs", "SingleAnnotation") |
62 | 64 |
export("nobs.SingleAnnotation") |
63 | 65 |
S3method("nrow", "Heatmap") |
64 | 66 |
export("nrow.Heatmap") |
67 |
+S3method("print", "comb_mat") |
|
68 |
+export("print.comb_mat") |
|
65 | 69 |
S3method("size", "AnnotationFunction") |
66 | 70 |
export("size.AnnotationFunction") |
67 | 71 |
S3method("size", "HeatmapAnnotation") |
... | ... |
@@ -78,6 +82,8 @@ S3method("summary", "Heatmap") |
78 | 82 |
export("summary.Heatmap") |
79 | 83 |
S3method("summary", "HeatmapList") |
80 | 84 |
export("summary.HeatmapList") |
85 |
+S3method("t", "comb_mat") |
|
86 |
+export("t.comb_mat") |
|
81 | 87 |
S3method("width", "AnnotationFunction") |
82 | 88 |
export("width.AnnotationFunction") |
83 | 89 |
S3method("width", "Heatmap") |
... | ... |
@@ -114,6 +120,7 @@ export("HeatmapList") |
114 | 120 |
export("Legend") |
115 | 121 |
export("Legends") |
116 | 122 |
export("SingleAnnotation") |
123 |
+export("UpSet") |
|
117 | 124 |
export("adjust_dend_by_x") |
118 | 125 |
export("anno_barplot") |
119 | 126 |
export("anno_block") |
... | ... |
@@ -136,6 +143,9 @@ export("anno_zoom") |
136 | 143 |
export("annotation_axis_grob") |
137 | 144 |
export("cluster_within_group") |
138 | 145 |
export("columnAnnotation") |
146 |
+export("comb_degree") |
|
147 |
+export("comb_name") |
|
148 |
+export("comb_size") |
|
139 | 149 |
export("decorate_annotation") |
140 | 150 |
export("decorate_column_dend") |
141 | 151 |
export("decorate_column_names") |
... | ... |
@@ -154,6 +164,7 @@ export("dend_xy") |
154 | 164 |
export("dendrogramGrob") |
155 | 165 |
export("densityHeatmap") |
156 | 166 |
export("dist2") |
167 |
+export("extract_comb") |
|
157 | 168 |
export("getXY_in_parent_vp") |
158 | 169 |
export("grid.annotation_axis") |
159 | 170 |
export("grid.boxplot") |
... | ... |
@@ -162,6 +173,8 @@ export("ht_global_opt") |
162 | 173 |
export("ht_opt") |
163 | 174 |
export("is_abs_unit") |
164 | 175 |
export("list_components") |
176 |
+export("list_to_matrix") |
|
177 |
+export("make_comb_mat") |
|
165 | 178 |
export("max_text_height") |
166 | 179 |
export("max_text_width") |
167 | 180 |
export("merge_dendrogram") |
... | ... |
@@ -176,6 +189,8 @@ export("row_anno_histogram") |
176 | 189 |
export("row_anno_link") |
177 | 190 |
export("row_anno_points") |
178 | 191 |
export("row_anno_text") |
192 |
+export("set_name") |
|
193 |
+export("set_size") |
|
179 | 194 |
export("smartAlign2") |
180 | 195 |
export("subset_gp") |
181 | 196 |
export("subset_matrix_by_row") |
... | ... |
@@ -245,6 +260,7 @@ importFrom("circlize", rand_color) |
245 | 260 |
importFrom("circlize", smartAlign) |
246 | 261 |
importFrom("colorspace", diverge_hcl) |
247 | 262 |
importFrom("colorspace", rainbow_hcl) |
263 |
+importFrom("utils", "combn") |
|
248 | 264 |
importFrom("utils", "getFromNamespace") |
249 | 265 |
importFrom("utils", "packageDescription") |
250 | 266 |
importFrom("utils", "str") |
... | ... |
@@ -48,7 +48,7 @@ make_comb_mat_from_matrix = function(x, mode, top_n_sets = Inf, min_set_size = - |
48 | 48 |
comb_mat = t(comb_mat) |
49 | 49 |
|
50 | 50 |
nc = ncol(comb_mat) |
51 |
- comb_mat2 = matrix(nr = nrow(comb_mat), nc = nc*(nc-1)/2) |
|
51 |
+ comb_mat2 = matrix(nrow = nrow(comb_mat), ncol = nc*(nc-1)/2) |
|
52 | 52 |
rownames(comb_mat2) = rownames(comb_mat) |
53 | 53 |
if(mode == "intersect") { |
54 | 54 |
if(nc > 1) { |
... | ... |
@@ -112,11 +112,11 @@ make_comb_mat_from_list = function(lt, mode, value_fun = length, top_n_sets = In |
112 | 112 |
|
113 | 113 |
if(inherits(lt[[1]], "GRanges")) { |
114 | 114 |
set_size = sapply(lt, function(x) { |
115 |
- value_fun(union(x, GRanges())) |
|
115 |
+ value_fun(union(x, x[NULL])) |
|
116 | 116 |
}) |
117 | 117 |
} else if(inherits(lt[[1]], "IRanges")) { |
118 | 118 |
set_size = sapply(lt, function(x) { |
119 |
- value_fun(union(x, IRanges())) |
|
119 |
+ value_fun(union(x, x[NULL])) |
|
120 | 120 |
}) |
121 | 121 |
} else { |
122 | 122 |
set_size = sapply(lt, function(x) { |
... | ... |
@@ -213,11 +213,94 @@ list_to_matrix = function(lt) { |
213 | 213 |
# Make a Combination matrix for UpSet Plot |
214 | 214 |
# |
215 | 215 |
# == param |
216 |
-# -... |
|
217 |
-# -mode |
|
218 |
-# -top_n_sets |
|
219 |
-# -min_set_size |
|
220 |
-# -value_fun |
|
216 |
+# -... The input sets. If it is represented as a single variable, it should be a matrix/data frame |
|
217 |
+# or a list. If it is multiple variables, it should be name-value pairs, see Input section for explanation. |
|
218 |
+# -mode The mode for forming the combination set, see Mode section. |
|
219 |
+# -top_n_sets Number of sets with largest size. |
|
220 |
+# -min_set_size Ths minimal set size that is used for generating the combination matrix. |
|
221 |
+# -value_fun For each combination set, how to calculate the size. If it is a scalar set, |
|
222 |
+# the length of the vector is the size of the set, while if it is a region-based set, |
|
223 |
+# (i.e. ``GRanges`` or ``IRanges`` object), the sum of widths of regions in the set is |
|
224 |
+# calculated as the size of the set. |
|
225 |
+# |
|
226 |
+# == Input |
|
227 |
+# To represent multiple sets, the variable can be represented as: |
|
228 |
+# |
|
229 |
+# 1. A list of sets where each set is a vector, e.g.: |
|
230 |
+# |
|
231 |
+# list(set1 = c("a", "b", "c"), |
|
232 |
+# set2 = c("b", "c", "d", "e"), |
|
233 |
+# ...) |
|
234 |
+# |
|
235 |
+# 2. A binary matrix/data frame where rows are elements and columns are sets, e.g.: |
|
236 |
+# |
|
237 |
+# a b c |
|
238 |
+# h 1 1 1 |
|
239 |
+# t 1 0 1 |
|
240 |
+# j 1 0 0 |
|
241 |
+# u 1 0 1 |
|
242 |
+# w 1 0 0 |
|
243 |
+# |
|
244 |
+# If the variable is a data frame, the binary columns (only contain 0 and 1) and the logical |
|
245 |
+# columns are only kept. |
|
246 |
+# |
|
247 |
+# The set can be genomic regions, then it can only be represented as a list of ``GRanges`` objects. |
|
248 |
+# |
|
249 |
+# == Mode |
|
250 |
+# E.g. for three sets (A, B, C), the UpSet approach splits the combination of selecting elements |
|
251 |
+# in the set or not in the set and calculates the sizes of the combination sets. For three sets, |
|
252 |
+# all possible combinations are: |
|
253 |
+# |
|
254 |
+# A B C |
|
255 |
+# 1 1 1 |
|
256 |
+# 1 1 0 |
|
257 |
+# 1 0 1 |
|
258 |
+# 0 1 1 |
|
259 |
+# 1 0 0 |
|
260 |
+# 0 1 0 |
|
261 |
+# 0 0 1 |
|
262 |
+# |
|
263 |
+# A value of 1 means to select that set and 0 means not to select that set. E.g., "1 1 0" |
|
264 |
+# means to select set A, B while not set C. Note there is no "0 0 0", because the background |
|
265 |
+# size is not of interest here. With the code of selecting and not selecting the sets, next |
|
266 |
+# we need to define how to calculate the size of that combination set. There are three modes: |
|
267 |
+# |
|
268 |
+# 1. ``distinct`` mode: 1 means in that set and 0 means not in that set, then "1 1 0" means a |
|
269 |
+# set of elements also in set A and B, while not in C (``setdiff(intersect(A, B), C)``). Under |
|
270 |
+# this mode, the seven combination sets are the seven partitions in the Venn diagram and they |
|
271 |
+# are mutually exclusive. |
|
272 |
+# |
|
273 |
+# 2. ``intersect`` mode: 1 means in that set and 0 is not taken into account, then, "1 1 0" means |
|
274 |
+# a set of elements in set A and B, and they can also in C or not in C (``intersect(A, B)``). |
|
275 |
+# Under this mode, the seven combinatio sets can overlap. |
|
276 |
+# |
|
277 |
+# 3. ``union`` mode: 1 means in that set and 0 is not taken into account. When there are multiple |
|
278 |
+# 1, the relationship is OR. Then, "1 1 0" means a set of elements in set A or B, and they can also in C or not in C (``union(A, B)``). |
|
279 |
+# Under this mode, the seven combinatio sets can overlap. |
|
280 |
+# |
|
281 |
+# == value |
|
282 |
+# A matrix also in a class of ``comb_mat``. |
|
283 |
+# |
|
284 |
+# == example |
|
285 |
+# set.seed(123) |
|
286 |
+# lt = list(a = sample(letters, 10), |
|
287 |
+# b = sample(letters, 15), |
|
288 |
+# c = sample(letters, 20)) |
|
289 |
+# m = make_comb_mat(lt) |
|
290 |
+# |
|
291 |
+# mat = list_to_matrix(lt) |
|
292 |
+# mat |
|
293 |
+# m = make_comb_mat(mat) |
|
294 |
+# |
|
295 |
+# \dontrun{ |
|
296 |
+# library(circlize) |
|
297 |
+# library(GenomicRanges) |
|
298 |
+# lt = lapply(1:4, function(i) generateRandomBed()) |
|
299 |
+# lt = lapply(lt, function(df) GRanges(seqnames = df[, 1], |
|
300 |
+# ranges = IRanges(df[, 2], df[, 3]))) |
|
301 |
+# names(lt) = letters[1:4] |
|
302 |
+# m = make_comb_mat(lt) |
|
303 |
+# } |
|
221 | 304 |
make_comb_mat = function(..., mode = c("distinct", "intersect", "union"), |
222 | 305 |
top_n_sets = Inf, min_set_size = -Inf, value_fun) { |
223 | 306 |
|
... | ... |
@@ -368,6 +451,13 @@ comb_degree = function(m) { |
368 | 451 |
} |
369 | 452 |
} |
370 | 453 |
|
454 |
+# == title |
|
455 |
+# Extract Elements in a Combination set |
|
456 |
+# |
|
457 |
+# == param |
|
458 |
+# -m |
|
459 |
+# -comb_name |
|
460 |
+# |
|
371 | 461 |
extract_comb = function(m, comb_name) { |
372 | 462 |
all_comb_names = comb_name(m) |
373 | 463 |
if(!comb_name %in% all_comb_names) { |
... | ... |
@@ -463,6 +553,26 @@ t.comb_mat = function(x) { |
463 | 553 |
# -j Indices on columns |
464 | 554 |
# -drop It is always reset to ``FALSE`` internally. |
465 | 555 |
# |
556 |
+# == details |
|
557 |
+# If sets are on rows of the combination matrix, the row indices correspond |
|
558 |
+# to sets and column indices correspond to combination sets and if sets are |
|
559 |
+# on columns of the combination matrix, rows correspond to the combination sets. |
|
560 |
+# |
|
561 |
+# You should not subset by the sets. It will give you wrong set size. The subsetting |
|
562 |
+# on rows are only used internally. |
|
563 |
+# |
|
564 |
+# This subsetting method is mainly for subsetting combination sets, i.e., users |
|
565 |
+# can first use `comb_size` to get the size of each combination set, and filter them |
|
566 |
+# by the size. |
|
567 |
+# |
|
568 |
+# == example |
|
569 |
+# set.seed(123) |
|
570 |
+# lt = list(a = sample(letters, 10), |
|
571 |
+# b = sample(letters, 15), |
|
572 |
+# c = sample(letters, 20)) |
|
573 |
+# m = make_comb_mat(lt) |
|
574 |
+# m2 = m[, comb_size(m) >= 3] |
|
575 |
+# comb_size(m2) |
|
466 | 576 |
"[.comb_mat" = function(x, i, j, drop = FALSE) { |
467 | 577 |
set_size = attr(x, "set_size") |
468 | 578 |
comb_size = attr(x, "comb_size") |
... | ... |
@@ -537,6 +647,13 @@ print.comb_mat = function(x, ...) { |
537 | 647 |
# == title |
538 | 648 |
# Make the UpSet plot |
539 | 649 |
# |
650 |
+# == param |
|
651 |
+# -m A combination matrix returned by `make_comb_mat`. The matrix can be transposed to switch |
|
652 |
+# the position of sets and combination sets. |
|
653 |
+# -set_order The order of sets. |
|
654 |
+# -comb_order The order of combination sets. |
|
655 |
+# -... Other arguments passed to `Heatmap`. |
|
656 |
+# |
|
540 | 657 |
UpSet = function(m, set_order = order(set_size(m), decreasing = TRUE), |
541 | 658 |
comb_order = order(comb_size(m), decreasing = TRUE), ...) { |
542 | 659 |
|
543 | 660 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
1 |
+\name{[.comb_mat} |
|
2 |
+\alias{[.comb_mat} |
|
3 |
+\alias{Extract.comb_mat} |
|
4 |
+\title{ |
|
5 |
+Subset the Combination Matrix |
|
6 |
+} |
|
7 |
+\description{ |
|
8 |
+Subset the Combination Matrix |
|
9 |
+} |
|
10 |
+\usage{ |
|
11 |
+\method{[}{comb_mat}(x, i, j, drop = FALSE) |
|
12 |
+} |
|
13 |
+\arguments{ |
|
14 |
+ |
|
15 |
+ \item{x}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
16 |
+ \item{i}{Indices on rows.} |
|
17 |
+ \item{j}{Indices on columns} |
|
18 |
+ \item{drop}{It is always reset to \code{FALSE} internally.} |
|
19 |
+ |
|
20 |
+} |
|
21 |
+\details{ |
|
22 |
+If sets are on rows of the combination matrix, the row indices correspond |
|
23 |
+to sets and column indices correspond to combination sets and if sets are |
|
24 |
+on columns of the combination matrix, rows correspond to the combination sets. |
|
25 |
+ |
|
26 |
+You should not subset by the sets. It will give you wrong set size. The subsetting |
|
27 |
+on rows are only used internally. |
|
28 |
+ |
|
29 |
+This subsetting method is mainly for subsetting combination sets, i.e., users |
|
30 |
+can first use \code{\link{comb_size}} to get the size of each combination set, and filter them |
|
31 |
+by the size. |
|
32 |
+} |
|
33 |
+\examples{ |
|
34 |
+set.seed(123) |
|
35 |
+lt = list(a = sample(letters, 10), |
|
36 |
+ b = sample(letters, 15), |
|
37 |
+ c = sample(letters, 20)) |
|
38 |
+m = make_comb_mat(lt) |
|
39 |
+m2 = m[, comb_size(m) >= 3] |
|
40 |
+comb_size(m2) |
|
41 |
+} |
0 | 42 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,25 @@ |
1 |
+\name{UpSet} |
|
2 |
+\alias{UpSet} |
|
3 |
+\title{ |
|
4 |
+Make the UpSet plot |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Make the UpSet plot |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+UpSet(m, set_order = order(set_size(m), decreasing = TRUE), |
|
11 |
+ comb_order = order(comb_size(m), decreasing = TRUE), ...) |
|
12 |
+} |
|
13 |
+\arguments{ |
|
14 |
+ |
|
15 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}. The matrix can be transposed to switch the position of sets and combination sets.} |
|
16 |
+ \item{set_order}{The order of sets.} |
|
17 |
+ \item{comb_order}{The order of combination sets.} |
|
18 |
+ \item{...}{Other arguments passed to \code{\link{Heatmap}}.} |
|
19 |
+ |
|
20 |
+} |
|
21 |
+\examples{ |
|
22 |
+# There is no example |
|
23 |
+NULL |
|
24 |
+ |
|
25 |
+} |
0 | 26 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,30 @@ |
1 |
+\name{comb_degree} |
|
2 |
+\alias{comb_degree} |
|
3 |
+\title{ |
|
4 |
+Degrees of the Combination sets |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Degrees of the Combination sets |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+comb_degree(m) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\details{ |
|
18 |
+The degree for a combination set is the number of sets that are selected. |
|
19 |
+} |
|
20 |
+\value{ |
|
21 |
+A vector of degrees of the combination sets. |
|
22 |
+} |
|
23 |
+\examples{ |
|
24 |
+set.seed(123) |
|
25 |
+lt = list(a = sample(letters, 10), |
|
26 |
+ b = sample(letters, 15), |
|
27 |
+ c = sample(letters, 20)) |
|
28 |
+m = make_comb_mat(lt) |
|
29 |
+comb_degree(m) |
|
30 |
+} |
0 | 31 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,34 @@ |
1 |
+\name{comb_name} |
|
2 |
+\alias{comb_name} |
|
3 |
+\title{ |
|
4 |
+Names of the Combination sets |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Names of the Combination sets |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+comb_name(m) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\details{ |
|
18 |
+The name of the combination sets are formatted as a string |
|
19 |
+of binary bits. E.g. for three sets of "a", "b", "c", the combination |
|
20 |
+set with name "101" corresponds to select set a, not select set b |
|
21 |
+and select set c. The definition of "select" depends on the value of |
|
22 |
+\code{mode} from \code{\link{make_comb_mat}}. |
|
23 |
+} |
|
24 |
+\value{ |
|
25 |
+A vector of names of the combination sets. |
|
26 |
+} |
|
27 |
+\examples{ |
|
28 |
+set.seed(123) |
|
29 |
+lt = list(a = sample(letters, 10), |
|
30 |
+ b = sample(letters, 15), |
|
31 |
+ c = sample(letters, 20)) |
|
32 |
+m = make_comb_mat(lt) |
|
33 |
+comb_name(m) |
|
34 |
+} |
0 | 35 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
1 |
+\name{comb_size} |
|
2 |
+\alias{comb_size} |
|
3 |
+\title{ |
|
4 |
+Sizes of the Combination sets |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Sizes of the Combination sets |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+comb_size(m) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\value{ |
|
18 |
+A vector of sizes of the combination sets. |
|
19 |
+} |
|
20 |
+\examples{ |
|
21 |
+set.seed(123) |
|
22 |
+lt = list(a = sample(letters, 10), |
|
23 |
+ b = sample(letters, 15), |
|
24 |
+ c = sample(letters, 20)) |
|
25 |
+m = make_comb_mat(lt) |
|
26 |
+comb_size(m) |
|
27 |
+} |
0 | 28 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,22 @@ |
1 |
+\name{extract_comb} |
|
2 |
+\alias{extract_comb} |
|
3 |
+\title{ |
|
4 |
+Extract Elements in a Combination set |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Extract Elements in a Combination set |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+extract_comb(m, comb_name) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{-m} |
|
15 |
+ \item{comb_name}{-comb_name} |
|
16 |
+ |
|
17 |
+} |
|
18 |
+\examples{ |
|
19 |
+# There is no example |
|
20 |
+NULL |
|
21 |
+ |
|
22 |
+} |
0 | 23 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
1 |
+\name{list_to_matrix} |
|
2 |
+\alias{list_to_matrix} |
|
3 |
+\title{ |
|
4 |
+Convert a List of Sets to a Binary Matrix |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Convert a List of Sets to a Binary Matrix |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+list_to_matrix(lt) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{lt}{A list of vectors.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\details{ |
|
18 |
+It converts the list which have m sets to a binary matrix with n rows and m columns |
|
19 |
+where n is the number of union of all sets in the list. |
|
20 |
+} |
|
21 |
+\examples{ |
|
22 |
+set.seed(123) |
|
23 |
+lt = list(a = sample(letters, 10), |
|
24 |
+ b = sample(letters, 15), |
|
25 |
+ c = sample(letters, 20)) |
|
26 |
+list_to_matrix(lt) |
|
27 |
+} |
0 | 28 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,101 @@ |
1 |
+\name{make_comb_mat} |
|
2 |
+\alias{make_comb_mat} |
|
3 |
+\title{ |
|
4 |
+Make a Combination matrix for UpSet Plot |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Make a Combination matrix for UpSet Plot |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+make_comb_mat(..., mode = c("distinct", "intersect", "union"), |
|
11 |
+ top_n_sets = Inf, min_set_size = -Inf, value_fun) |
|
12 |
+} |
|
13 |
+\arguments{ |
|
14 |
+ |
|
15 |
+ \item{...}{The input sets. If it is represented as a single variable, it should be a matrix/data frame or a list. If it is multiple variables, it should be name-value pairs, see Input section for explanation.} |
|
16 |
+ \item{mode}{The mode for forming the combination set, see Mode section.} |
|
17 |
+ \item{top_n_sets}{Number of sets with largest size.} |
|
18 |
+ \item{min_set_size}{Ths minimal set size that is used for generating the combination matrix.} |
|
19 |
+ \item{value_fun}{For each combination set, how to calculate the size. If it is a scalar set, the length of the vector is the size of the set, while if it is a region-based set, (i.e. \code{GRanges} or \code{IRanges} object), the sum of widths of regions in the set is calculated as the size of the set.} |
|
20 |
+ |
|
21 |
+} |
|
22 |
+\section{Input}{ |
|
23 |
+To represent multiple sets, the variable can be represented as: |
|
24 |
+ |
|
25 |
+1. A list of sets where each set is a vector, e.g.: |
|
26 |
+ |
|
27 |
+ \preformatted{ |
|
28 |
+ list(set1 = c("a", "b", "c"), |
|
29 |
+ set2 = c("b", "c", "d", "e"), |
|
30 |
+ ...) } |
|
31 |
+ |
|
32 |
+2. A binary matrix/data frame where rows are elements and columns are sets, e.g.: |
|
33 |
+ |
|
34 |
+ \preformatted{ |
|
35 |
+ a b c |
|
36 |
+ h 1 1 1 |
|
37 |
+ t 1 0 1 |
|
38 |
+ j 1 0 0 |
|
39 |
+ u 1 0 1 |
|
40 |
+ w 1 0 0 } |
|
41 |
+ |
|
42 |
+If the variable is a data frame, the binary columns (only contain 0 and 1) and the logical |
|
43 |
+columns are only kept. |
|
44 |
+ |
|
45 |
+The set can be genomic regions, then it can only be represented as a list of \code{GRanges} objects.} |
|
46 |
+\section{Mode}{ |
|
47 |
+E.g. for three sets (A, B, C), the UpSet approach splits the combination of selecting elements |
|
48 |
+in the set or not in the set and calculates the sizes of the combination sets. For three sets, |
|
49 |
+all possible combinations are: |
|
50 |
+ |
|
51 |
+ \preformatted{ |
|
52 |
+ A B C |
|
53 |
+ 1 1 1 |
|
54 |
+ 1 1 0 |
|
55 |
+ 1 0 1 |
|
56 |
+ 0 1 1 |
|
57 |
+ 1 0 0 |
|
58 |
+ 0 1 0 |
|
59 |
+ 0 0 1 } |
|
60 |
+ |
|
61 |
+A value of 1 means to select that set and 0 means not to select that set. E.g., "1 1 0" |
|
62 |
+means to select set A, B while not set C. Note there is no "0 0 0", because the background |
|
63 |
+size is not of interest here. With the code of selecting and not selecting the sets, next |
|
64 |
+we need to define how to calculate the size of that combination set. There are three modes: |
|
65 |
+ |
|
66 |
+1. \code{distinct} mode: 1 means in that set and 0 means not in that set, then "1 1 0" means a |
|
67 |
+set of elements also in set A and B, while not in C (\code{setdiff(intersect(A, B), C)}). Under |
|
68 |
+this mode, the seven combination sets are the seven partitions in the Venn diagram and they |
|
69 |
+are mutually exclusive. |
|
70 |
+ |
|
71 |
+2. \code{intersect} mode: 1 means in that set and 0 is not taken into account, then, "1 1 0" means |
|
72 |
+a set of elements in set A and B, and they can also in C or not in C (\code{intersect(A, B)}). |
|
73 |
+Under this mode, the seven combinatio sets can overlap. |
|
74 |
+ |
|
75 |
+3. \code{union} mode: 1 means in that set and 0 is not taken into account. When there are multiple |
|
76 |
+1, the relationship is OR. Then, "1 1 0" means a set of elements in set A or B, and they can also in C or not in C (\code{union(A, B)}). |
|
77 |
+Under this mode, the seven combinatio sets can overlap.} |
|
78 |
+\value{ |
|
79 |
+A matrix also in a class of \code{comb_mat}. |
|
80 |
+} |
|
81 |
+\examples{ |
|
82 |
+set.seed(123) |
|
83 |
+lt = list(a = sample(letters, 10), |
|
84 |
+ b = sample(letters, 15), |
|
85 |
+ c = sample(letters, 20)) |
|
86 |
+m = make_comb_mat(lt) |
|
87 |
+ |
|
88 |
+mat = list_to_matrix(lt) |
|
89 |
+mat |
|
90 |
+m = make_comb_mat(mat) |
|
91 |
+ |
|
92 |
+\dontrun{ |
|
93 |
+library(circlize) |
|
94 |
+library(GenomicRanges) |
|
95 |
+lt = lapply(1:4, function(i) generateRandomBed()) |
|
96 |
+lt = lapply(lt, function(df) GRanges(seqnames = df[, 1], |
|
97 |
+ ranges = IRanges(df[, 2], df[, 3]))) |
|
98 |
+names(lt) = letters[1:4] |
|
99 |
+m = make_comb_mat(lt) |
|
100 |
+} |
|
101 |
+} |
0 | 102 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,22 @@ |
1 |
+\name{print.comb_mat} |
|
2 |
+\alias{print.comb_mat} |
|
3 |
+\title{ |
|
4 |
+Print the comb_mat Object |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Print the comb_mat Object |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+\method{print}{comb_mat}(x, ...) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{x}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ \item{...}{Other arguments} |
|
16 |
+ |
|
17 |
+} |
|
18 |
+\examples{ |
|
19 |
+# There is no example |
|
20 |
+NULL |
|
21 |
+ |
|
22 |
+} |
0 | 23 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
1 |
+\name{set_name} |
|
2 |
+\alias{set_name} |
|
3 |
+\title{ |
|
4 |
+Set Names |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Set Names |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+set_name(m) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\value{ |
|
18 |
+A vector of set names. |
|
19 |
+} |
|
20 |
+\examples{ |
|
21 |
+set.seed(123) |
|
22 |
+lt = list(a = sample(letters, 10), |
|
23 |
+ b = sample(letters, 15), |
|
24 |
+ c = sample(letters, 20)) |
|
25 |
+m = make_comb_mat(lt) |
|
26 |
+set_name(m) |
|
27 |
+} |
0 | 28 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
1 |
+\name{set_size} |
|
2 |
+\alias{set_size} |
|
3 |
+\title{ |
|
4 |
+Set Sizes |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Set Sizes |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+set_size(m) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{m}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\value{ |
|
18 |
+A vector of set sizes. |
|
19 |
+} |
|
20 |
+\examples{ |
|
21 |
+set.seed(123) |
|
22 |
+lt = list(a = sample(letters, 10), |
|
23 |
+ b = sample(letters, 15), |
|
24 |
+ c = sample(letters, 20)) |
|
25 |
+m = make_comb_mat(lt) |
|
26 |
+set_size(m) |
|
27 |
+} |
0 | 28 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+\name{t.comb_mat} |
|
2 |
+\alias{t.comb_mat} |
|
3 |
+\title{ |
|
4 |
+Transpost the Combination Matrix |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Transpost the Combination Matrix |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+\method{t}{comb_mat}(x) |
|
11 |
+} |
|
12 |
+\arguments{ |
|
13 |
+ |
|
14 |
+ \item{x}{A combination matrix returned by \code{\link{make_comb_mat}}.} |
|
15 |
+ |
|
16 |
+} |
|
17 |
+\examples{ |
|
18 |
+set.seed(123) |
|
19 |
+lt = list(a = sample(letters, 10), |
|
20 |
+ b = sample(letters, 15), |
|
21 |
+ c = sample(letters, 20)) |
|
22 |
+m = make_comb_mat(lt) |
|
23 |
+t(m) |
|
24 |
+} |
... | ... |
@@ -51,7 +51,6 @@ m = make_comb_mat(movies, top_n_sets = 6, mode = "intersect") |
51 | 51 |
m = make_comb_mat(movies, top_n_sets = 6, mode = "union") |
52 | 52 |
|
53 | 53 |
|
54 |
- |
|
55 | 54 |
library(circlize) |
56 | 55 |
library(GenomicRanges) |
57 | 56 |
lt = lapply(1:4, function(i) generateRandomBed()) |
... | ... |
@@ -60,3 +59,53 @@ names(lt) = letters[1:4] |
60 | 59 |
m = make_comb_mat(lt) |
61 | 60 |
|
62 | 61 |
|
62 |
+set.seed(123) |
|
63 |
+lt = list(a = sample(letters, 10), |
|
64 |
+ b = sample(letters, 15), |
|
65 |
+ c = sample(letters, 20)) |
|
66 |
+v = gplots::venn(lt, show.plot = FALSE) |
|
67 |
+rownames(v) = apply(v[, -1], 1, paste, collapse = "") |
|
68 |
+m = make_comb_mat(lt) |
|
69 |
+cs = structure(comb_size(m), names = comb_name(m)) |
|
70 |
+ |
|
71 |
+library(testthat) |
|
72 |
+test_that("test to the output from gplots::venn", { |
|
73 |
+ expect_that(cs[["111"]], equals(v["111", 1])) |
|
74 |
+ expect_that(cs[["110"]], equals(v["110", 1])) |
|
75 |
+ expect_that(cs[["101"]], equals(v["101", 1])) |
|
76 |
+ expect_that(cs[["011"]], equals(v["011", 1])) |
|
77 |
+ expect_that(cs[["100"]], equals(v["100", 1])) |
|
78 |
+ expect_that(cs[["010"]], equals(v["010", 1])) |
|
79 |
+ expect_that(cs[["001"]], equals(v["001", 1])) |
|
80 |
+}) |
|
81 |
+ |
|
82 |
+m = make_comb_mat(lt, mode = "intersect") |
|
83 |
+cs = structure(comb_size(m), names = comb_name(m)) |
|
84 |
+test_that("test to the output from gplots::venn", { |
|
85 |
+ expect_that(cs[["111"]], equals(v["111", 1])) |
|
86 |
+ expect_that(cs[["110"]], equals(v["110", 1] + v["111", 1])) |
|
87 |
+ expect_that(cs[["101"]], equals(v["101", 1] + v["111", 1])) |
|
88 |
+ expect_that(cs[["011"]], equals(v["011", 1] + v["111", 1])) |
|
89 |
+ expect_that(cs[["100"]], equals(v["100", 1] + v["110", 1] + v["101", 1] + v["111", 1])) |
|
90 |
+ expect_that(cs[["010"]], equals(v["010", 1] + v["110", 1] + v["111", 1] + v["011", 1])) |
|
91 |
+ expect_that(cs[["001"]], equals(v["001", 1] + v["111", 1] + v["101", 1] + v["011", 1])) |
|
92 |
+}) |
|
93 |
+ |
|
94 |
+m = make_comb_mat(lt, mode = "union") |
|
95 |
+cs = structure(comb_size(m), names = comb_name(m)) |
|
96 |
+test_that("test to the output from gplots::venn", { |
|
97 |
+ expect_that(cs[["111"]], equals(sum(v[, 1]))) |
|
98 |
+ expect_that(cs[["110"]], equals(sum(v[, 1]) - v["001", 1])) |
|
99 |
+ expect_that(cs[["101"]], equals(sum(v[, 1]) - v["010", 1])) |
|
100 |
+ expect_that(cs[["011"]], equals(sum(v[, 1]) - v["100", 1])) |
|
101 |
+ expect_that(cs[["100"]], equals(v["100", 1] + v["101", 1] + v["110", 1] + v["111", 1])) |
|
102 |
+ expect_that(cs[["010"]], equals(v["010", 1] + v["110", 1] + v["011", 1] + v["111", 1])) |
|
103 |
+ expect_that(cs[["001"]], equals(v["001", 1] + v["101", 1] + v["011", 1] + v["111", 1])) |
|
104 |
+}) |
|
105 |
+ |
|
106 |
+m = make_comb_mat(lt) |
|
107 |
+cs = comb_size(m) |
|
108 |
+test_that("test comb_size and extract_comb", { |
|
109 |
+ expect_that(cs, equals(unname(sapply(comb_name(m), function(nm) length(extract_comb(m, nm)))))) |
|
110 |
+}) |
|
111 |
+ |