biojl
biojl

Reputation: 1080

Using queries in UpSetR

I am trying to use the query capabilites in the package UpSetR to highlight certain items depending on one variable.

My dataset Dropbox link

I can do a basic plot without any problems:

stress <- read_delim("upset_plot_high_freq.csv", "\t", escape_double = FALSE, trim_ws = TRUE)
stress_data<-as.data.frame(stress)
    upset(stress_data, sets = c("reg_region","sweep","gene_association","chromatin"),

          mainbar.y.label = "Number of TEs", sets.x.label = "Total number of TEs", 
      text.scale = 2, group.by = "degree", order.by="freq")

Basic upset plot for my (simplified) dataset

However, when I try to do some basic queries I get all sort of errors. For example in a basic query where I ask all the elements with a given value in a variable to be painted blue I get the following error:

myfunction <- function(row, min){
  newData <- (row["chip_num"] > min)
}

upset(stress_data, sets = c("reg_region","sweep","gene_association","chromatin"),
      queries = list(query = myfunction, params = list(0), active = TRUE), 
      mainbar.y.label = "Number of TEs", sets.x.label = "Total number of TEs", 
      text.scale = 2, group.by = "degree", order.by="freq")

Error in queries[[i]]$color : object of type 'closure' is not subsettable

Upvotes: 2

Views: 2129

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24252

The input of queries must be a list of lists:

library(UpSetR)
library(readr)

stress <- read_delim("upset_plot_fixed_freq.csv", "\t", 
                     escape_double = FALSE, trim_ws = TRUE)
stress_data <- as.data.frame(stress)
names(stress_data)[c(9,12,13,10)] <- c("reg_region","sweep",
                                       "gene_association","chromatin")

myfunction <- function(row, min) {
  newData <- (row["chip_num"] > min)
}

upset(stress_data, sets=c("reg_region","sweep","gene_association","chromatin","chip_num"),
      queries = list(list(query = myfunction, params = list(0), active = T)), 
      mainbar.y.label = "Number of TEs", sets.x.label = "Total number of TEs", 
      text.scale = 2, group.by = "degree", order.by="freq")

enter image description here

Upvotes: 3

Related Questions