Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Mar 26, 2020
1 parent 4acbc10 commit c57f083
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions R/Upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,13 @@ full_comb_code = function(n, complement = FALSE) {
j = j + 1
}
}
sort(apply(comb_mat, 2, paste, collapse = ""))

lt = list(colSums(comb_mat))
lt = c(lt, as.list(as.data.frame(t(comb_mat))))
lt$decreasing = TRUE
od = do.call(order, lt)

apply(comb_mat[, od, drop = FALSE], 2, paste, collapse = "")
}


Expand Down Expand Up @@ -874,7 +880,7 @@ subset_by_comb_ind = function(x, ind, margin = 2) {

class(x) = "matrix"
n = nrow(x)
if(is.numeric(ind)) {
if(is.numeric(ind) || is.logical(ind)) {
if(margin == 1) {
x2 = x[ind, , drop = FALSE]
} else {
Expand Down Expand Up @@ -918,7 +924,7 @@ subset_by_set_ind = function(x, ind) {

ind = unique(ind)

if(is.numeric(ind)) {
if(is.numeric(ind) || is.logical(ind)) {
sub_set = set_name(x)[ind]
if(is.matrix(env$data)) {
param$x = env$data[, sub_set, drop = FALSE]
Expand Down
2 changes: 1 addition & 1 deletion man/UpSet.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UpSet(m,
pt_size = unit(3, "mm"), lwd = 2,
bg_col = "#F0F0F0", bg_pt_col = "#CCCCCC",
set_order = order(set_size(m), decreasing = TRUE),
comb_order = if(attr(m, "set_on_rows")) {
comb_order = if(attr(m, "param")$set_on_rows) {
order.comb_mat(m[set_order, ], decreasing = TRUE)
} else {
order.comb_mat(m[, set_order], decreasing = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion man/anno_barplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Barplot Annotation
\usage{
anno_barplot(x, baseline = 0, which = c("column", "row"), border = TRUE, bar_width = 0.6,
gp = gpar(fill = "#CCCCCC"), ylim = NULL, extend = 0.05, axis = TRUE,
axis_param = default_axis_param(which), beside = FALSE,
axis_param = default_axis_param(which),
width = NULL, height = NULL, ...)
}
\arguments{
Expand Down
1 change: 1 addition & 0 deletions man/make_comb_mat.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ make_comb_mat(..., mode = c("distinct", "intersect", "union"),
\item{universal_set}{The universal set. If it is set, the size of the complement set of all sets is also calculated. It if is specified, \code{complement_size} is ignored.}
\item{complement_size}{The size for the complement of all sets. If it is specified, the combination set name will be like "00...".}
\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.}
\item{set_on_rows}{Used internally.}

}
\section{Input}{
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/testthat-UpSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ cm2 = make_comb_mat_from_matrix(m, "distinct")
test_that("test subset method on sets and combination sets", {
expect_that(comb_size(cm1[, 1:5]), equals(comb_size(cm1)[1:5]))
expect_that(comb_size(cm1[1:5]), equals(comb_size(cm1)[1:5]))
expect_that(comb_size(cm1[full_comb_code(3, TRUE)]), equals(c("000" = 0, comb_size(cm1))))
expect_that(comb_size(cm1[full_comb_code(3, TRUE)]), equals(c(comb_size(cm1), "000" = 0)))

cm1_2sets = make_comb_mat_from_list(lt[1:2], "distinct")
expect_that(comb_size(cm1[c("a", "b"), ]), equals(comb_size(cm1_2sets)))

expect_that(comb_size(cm2[, 1:5]), equals(comb_size(cm2)[1:5]))
expect_that(comb_size(cm2[1:5]), equals(comb_size(cm2)[1:5]))
expect_that(comb_size(cm2[full_comb_code(3, TRUE)]), equals(c("000" = 0, comb_size(cm2))))
expect_that(comb_size(cm2[full_comb_code(3, TRUE)]), equals(c(comb_size(cm2), "000" = 0)))

cm2_2sets = make_comb_mat_from_matrix(m[, 1:2], "distinct")
expect_that(comb_size(cm2[c("a", "b"), ]), equals(comb_size(cm2_2sets)))
Expand Down

0 comments on commit c57f083

Please sign in to comment.