Search code examples
rr-s4

Can not inspect S4 object after modification


I am having problems with my S4 object resafter I appended a list of values to it. The object was created with the DESeq2 package. The object was created via:

dds <- DESeqDataSetFromMatrix(countData = count.matrix,
                              colData = coldata,
                              design = ~ Condition)
dds <- DESeq(dds, test = "Wald")
res <- results(dds)

I did the following:

x <- qvalue(res@listData[["pvalue"]])    #calc qvalues based on pvalues from S4 object 'res'
res@listData[["qval"]] <- x[["qvalues"]] #append qvalues from x to 'res' as new col named "qval"

Now when I try to inspect the object with head() I get the following error:

> head(res)
Error in `rownames<-`(`*tmp*`, value = names(x)) : 
  invalid rownames length

The funny thing is that with View()I can inspect the S4 object in RStudio and I can see that everything went fine, adding the qvalues. Does anyone know why this happens? Is there a way to avoid that?


Solution

  • For you to get the qvalues.. you can do this first:

    library(qvalue)
    library(DESeq2)
    
    dds = makeExampleDESeqDataSet()
    dds = DESeq(dds)
    res = results(dds)
    res$qvalue = qvalue(res$pvalue)$qvalue
    

    I will follow up with why there is an error.. you need to look into how it is constructed.