Problems with DESeq2 'design' parameter using Shiny/rhandsontable
1
0
Entering edit mode
hinkel2 • 0
@hinkel2-16914
Last seen 5.7 years ago

Hi all!

I want to create a shiny app for DESeq2 analysis. My main thought is to upload count matrix, extract colnames/experiments and provide an editable table to user in order to assign conditions to respective experiment (-> colData). After adjustment, user has to click a button in order to start DESeq2. However, when I click the button, I get following error:

Warning: Error in DESeqDataSet: the design formula contains an ordered factor. The internal steps do not work on ordered factors as a formula. Instead you should provide a matrix to the 'design' slot or to the 'full' argument of DESeq(), constructed using model.matrix.

I also checked whether values$new was transformed into a dataframe using hot _ to _ r(), and indeed it was. I can also present it as a dataframe in shiny using renderTable() (not shown in code), suggesting that transformation to dataframe from rhandsontable object worked

Does someone see why especially the design-part does not work or how I could solve this? Thanks in advance!

# server part
server <- function(input, output) {
  values <- reactiveValues(df_data = NULL)

  # general data input
  observeEvent(input$file, {
    if (is.null(input$file$datapath))
      return(NULL)

      values$count <- read.csv(input$file$datapath, row.names = 1)
      values$df_data <- data.frame(experiment_name = colnames(values$count),
                      condition = rep(" information",length(colnames(values$count))))
  })

 #render table
  output$x1 <- renderRHandsontable({
    if(is.null(values$df_data))
      return(NULL)

    rhandsontable(values$df_data) %>%
      hot_col(col = c("experiment_name","condition"), allowInvalid = TRUE, strict=FALSE)
  })

  #save edits/update (button click)!
  observeEvent(input$saveBtn,{
    values$new <- as.data.frame(hot_to_r(input$x1))

    values$de <- DESeqDataSetFromMatrix(countData = values$count,
                                        colData = values$new,
                                        design = ~condition)
  })
}
deseq2 shiny design rhandsontable hot_to_r() • 1.7k views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 5 hours ago
United States

Can you show me the condition column of colData? Is it an ordered factor? Is there reason to have it an ordered factor?

ADD COMMENT
0
Entering edit mode

Hi Michael!

I checked for condition column before (values$df_data) and after (values$new) user edit if it is a factor and used renderText() to get output (corresponding ui-part not shown):

output$df_data <- renderText({
 is.factor(values$df_data$condition)
})

output$x2 <- renderText({
 is.factor(values$new$condition)
})

For both, the result is 'TRUE', but I don't know why. The following just shows me the factor vector with numbers (if i only have one condition, I get n times 1 and so on):

output$df_data <- renderText({
  values$df_data$condition
})

output$x2 <- renderText({
  values$new$condition
})

I actually did not expect it be a factor when I created the data frame at the top of 'server' function. Even if I use as.character() as wrapper around 'experiment_name' and/or 'condition', I still get a factor:

values$df_data <- data.frame(experiment_name = as.character(colnames(values$count)),
                                   condition = as.character(rep(" information",
                                               length(colnames(values$count)))))
ADD REPLY
0
Entering edit mode

Can you print out colData(dds)$condition?

ADD REPLY
0
Entering edit mode

Assuming you mean DESeqDataSetFromMatrix(...) with 'dds', I printed it out using renderText():

output$x2 <- renderText({
colData(DESeqDataSetFromMatrix(countData = values$count,
                                 colData = values$new,
                                  design = ~condition))$condition
})

resulting in the same error:

Error in DESeqDataSet: the design formula contains an ordered factor. The internal steps do not work on ordered factors as a formula. Instead you should provide a matrix to the 'design' slot or to the 'full' argument of DESeq(), constructed using model.matrix.

ADD REPLY
0
Entering edit mode

Oops, I mean, can you print out values$new?

ADD REPLY
0
Entering edit mode

renderTable() (renderText() won't work because it cannot concat table to string):

output$x2 <- renderTable({
values$new
})

OR

output$x2 <- renderTable({
values$new$experiment_name
})

OR

output$x2 <- renderTable({
values$new$condition
})

will print out the correctly edited table in the shiny app. So in general data storage and editing seems to work, but can - for some reason - not be accessed using '~condition'.

ADD REPLY
0
Entering edit mode

Hmm, I can't help much more I guess on this one, because for debugging, you would want to know what the input you are providing to DESeq2.

ADD REPLY

Login before adding your answer.

Traffic: 720 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6