krassowski/complex-upset

Is there any functionality to exclude few selected intersections from all possible intersections

peranti opened this issue · 2 comments

Is your feature request related to a problem? Please describe.

This is not related to a problem, but a new request related to the intersect. Currently, we can now select which columns to use for the intersection and whether we should include all the possible intersections intersections='all' or only "n" intersections using n_intersections. Is it possible to exclude a few interactions when the possible interaction combinations are more?

Describe the solution you'd like

I do not know; but maybe something like: exclude_intersections = list(c('Comedy', 'Action'), c('Romance', 'Action')) from the possible intersections.

Describe alternatives you've considered

By specifying all the needed intersections using intersections=list('Comedy', 'Drama', c('Comedy', 'Romance'), c('Romance', 'Drama'), 'Outside of known sets', 'Action')

Context (required)

ComplexUpset version: 1.3.3

R version details
$platform
[1] "x86_64-pc-linux-gnu"

$arch
[1] "x86_64"

$os
[1] "linux-gnu"

$system
[1] "x86_64, linux-gnu"

$status
[1] ""

$major
[1] "4"

$minor
[1] "1.2"

$year
[1] "2021"

$month
[1] "11"

$day
[1] "01"

$`svn rev`
[1] "81115"

$language
[1] "R"

$version.string
[1] "R version 4.1.2 (2021-11-01)"

$nickname
[1] "Bird Hippie"```

</details>


<details>
<summary>R session information</summary>

```R
<!-- Please replace this line by output of sessionInfo() -->

@krassowski Hi Michał, I added this issue as you advised last Friday. Thanks for the response.

I think this would be a nice addition. For now I would propose using the following function:

all_intersections_except = function(sets, to_exclude) {
    possible_intersections = ComplexUpset:::get_intersection_members(
        rownames(
            ComplexUpset:::all_intersections_matrix(
                sets,
                NULL,
                0,
                Inf
            )
        )
    )
    possible_intersections[
        sapply(
            possible_intersections,
            function(candidate) {
                !any(sapply(to_exclude, setequal, candidate))
            }
        )
    ]
}

Which for an example dataset:

data = data.frame(matrix(data = TRUE, nrow=5, ncol=4))
data[5, 1] = FALSE
data[4, 2] = FALSE
data[, 4] = FALSE
data

Works as follows;

upset(
    data,
    c('X1', 'X2', 'X3', 'X4'),
    mode = "exclusive_intersection",
    sort_intersections = FALSE,
    intersections = all_intersections_except(
        sets=c('X1', 'X2', 'X3', 'X4'),
        to_exclude=list(
            c('X1', 'X3')
        )
    )
)

download

compared to 'all' intersections:

download