Question: Problems with DESeq2 'design' parameter using Shiny/rhandsontable
0
gravatar for hinkel2
3 months ago by
hinkel20
hinkel20 wrote:

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)
  })
}
ADD COMMENTlink modified 3 months ago by Michael Love24k • written 3 months ago by hinkel20
Answer: Problems with DESeq2 'design' parameter using Shiny/rhandsontable
0
gravatar for Michael Love
3 months ago by
Michael Love24k
United States
Michael Love24k wrote:

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

ADD COMMENTlink written 3 months ago by Michael Love24k

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 REPLYlink modified 3 months ago • written 3 months ago by hinkel20

Can you print out colData(dds)$condition?

ADD REPLYlink written 3 months ago by Michael Love24k

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 REPLYlink modified 3 months ago • written 3 months ago by hinkel20

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

ADD REPLYlink written 3 months ago by Michael Love24k

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 REPLYlink written 3 months ago by hinkel20

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 REPLYlink written 3 months ago by Michael Love24k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 339 users visited in the last hour