Entering edit mode
In chapter 8 of the ComplexHeatmap manual, for UpSet plots, it describes a method of converting a list of sets where each set is a vector into a binary matrix where rows are elements and columns are sets using the list_to_matrix()
function.
lt = list(set1 = c("a", "b", "c"),
set2 = c("b", "c", "d", "e"))
mat = list_to_matrix(lt)
mat
Which looks like this
## set1 set2
## a 1 0
## b 1 1
## c 1 1
## d 0 1
## e 0 1
How can one go in the other direction, convert the matrix back to a list of sets where each is unique, e.g.:
lt = list(set1 = c("a", "b", "c"),
set2 = c("b", "c", "d", "e"))
I've got a binary matrix from consensus variants calls that was created using SURVIVOR and have already created a figure using ComplexHeatmap and would like to make a comparable figure using UpSet.js and it only accepts such input, e.g.:
devtools::install_url("https://github.com/upsetjs/upsetjs_r/releases/latest/download/upsetjs.tar.gz")
library(upsetjs)
listInput <- list(one = c(1, 2, 3, 5, 7, 8, 11, 12, 13), two = c(1, 2, 4, 5, 10), three = c(1, 5, 6, 7, 8, 9, 10, 12, 13))
upsetjs() %>% fromList(listInput) %>% interactiveChart()
like
apply(mat, 2, function(x) rownames(mat)[x > 0])
?or
apply(mat, 2, function(x) which(x > 0))
?