Determination of the intersection size members in ComplexUpset by using R

186 views Asked by At

I created a ComplexUpset plot. Then, I tried to obtain the members of the intersection which were illustrated in the "intersection size" part of the plot. For this purpose, I tried several ways but always, I got errors or the new datasets were empty. I couldn't get the solution of the erros. Could you help me to obtain the members of the intersections members whic in the intersection size? (In the plot, ı can see their numbers, but ı want to take their names)

Here is the plot I got:

(https://i.stack.imgur.com/9HCUB.png)

library(ComplexUpset)
library(readxl)
library(dplyr)
library(tibble)

setwd("/Users/hasancandemirci/Desktop//data")
hcd <- read_xlsx("a.xlsx")
hcd = as.data.frame(hcd)

Genes <- c(hcd$b, hcd$c, hcd$d, hcd$e, hcd$f, hcd$g)

distinct_genes_table <- tibble(Genes)
distinct_genes_table <- data.frame(Genes_table, b= 0, c= 0,
                          d= 0,e= 0,Jf= 0,g= 0)


distinct_genes_table$b <- ifelse(distinct_genes_table$Genes %in% hcd$b, 1, 0)
distinct_genes_table$c <- ifelse(distinct_genes_table$Genes %in% hcd$c, 1, 0)
distinct_genes_table$d <- ifelse(distinct_genes_table$Genes %in% hcd$d, 1, 0)
distinct_genes_table$e <- ifelse(distinct_genes_table$Genes %in% hcd$e, 1, 0)
distinct_genes_table$f <- ifelse(distinct_genes_table$Genes %in% hcd$f, 1, 0)
distinct_genes_table$g <- ifelse(distinct_genes_table$Genes %in% hcd$g, 1, 0)

distinct_genes_table <- na.omit(distinct_genes_table)
tf = colnames(Genes_table)[2:7]

set_size = function(w, h, factor=1.5) {
  s = 1 * factor
  options(
    repr.plot.width=w * s,
    repr.plot.height=h * s,
    repr.plot.res=100 / factor,
    jupyter.plot_mimetypes='image/png',
    jupyter.plot_scale=1
  )
}

set_size(2386,6)

query_by_degree = function(data, groups, params_by_degree, shared, ...) {
  intersections = unique(upset_data(data, groups, ...)$plot_intersections_subset)
  lapply(
    intersections,
    FUN=function(x) {
      members = ComplexUpset:::get_intersection_members(x)[[2]]
      degree = as.character(ComplexUpset:::calculate_degree(x))
      
      args = c(
        list(intersect=members),
        shared,
        params_by_degree[[degree]]
      )
      do.call(upset_query, args)
    }
  )
}
 
upset(
  distinct_genes_table,
  tf,
  width_ratio=0.1,
  min_size = 15,
  sort_intersections_by=c('degree', 'cardinality'),
  matrix=intersection_matrix(
    geom=geom_point(shape='circle filled', size=3)
  ),
  queries=
    query_by_degree(
      distinct_genes_table,
      tf,
      min_size = 15,
      params_by_degree=list(
        '1'=list(fill='#CCFFFF'),
        '2'=list(fill='#CCE5FF'),
        '3'=list(fill='#CCCCFF'),
        '4'=list(fill='#E5CCFF'),
        '5'=list(fill='#FFCCFF'),
        '6'=list(fill='#FFCCE5')
      ),
      shared=list(
        only_components=c("intersections_matrix", "Intersection size"),
        color='black'
      )
    )
)``



 
1

There are 1 answers

0
Hasan Can Demirci On

Okay, I found the solution way of my problem thanks to MR.Krssowski. Actually, I have used the "upset_data" function to get intersection members but ı could not. When he asked me again "Did you try the upset_data function?", I tried again. Then, I saw every data is stored in the upset_data. I found my intersection member in the stored data and I used them to create the members of the intersection.

What I did:

1- I reached to stored data 2- I extract the data , which ı need, from upset_data 3- I grouped Data to see their number and members

upset_data <- upset_data(distinct_genes_table, tf)

last <- data_frame (upset_data$presence$Genes,upset_data$presence$intersection)

last <- last %>% group_by(last$intersection) %>% summarize(Num_Genes = n(), Genes = paste(Genes, collapse = ", "))

I hope It will help everyone :)