Add new columns to DESeqResults from text file by matching rownames.
Entering edit mode
Last seen 5.9 years ago

I have generated results from DESeq2 wihch is a S4 type R-object. I want to add new columns to it containing geneNames, contig and start position.

There is method using BioMart to do it, but I won't be using the BioMart method; instead I have the geneDatabase as a textfile,

I have tried merging these two databases by `matching rownames` using merge, cbind,  but no success.

  • The merge method won't more because it can't bind data.frame to DESeqResults.
  • With `cbind` I can't bind because I have differing number of rows. The `DeSeqResults` have less number of rows/rownames because several rows were filtered, but it's rownames are subset of `geneMap` rownames.

I have tried using this and several other methods explained in stackoverflow, but success yet.

> merge(result.ASE_Data, geneMap)
Error in as(merge(as(x, "data.frame"), y, ...), class(x)) :  no method or default for coercing “data.frame” to “DESeqResults”

>, list(result.ASE_Data, geneMap))
Error: All inputs to rbind.fill must be data.frames

>, list(result.ASE_Data, geneMap))
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1761, 1865

> cbind(result.ASE_Data, geneMap)
Error in DataFrame(...) : different row counts implied by arguments
deseq2 deseq merge data frames cbind s4vectors • 3.8k views
Entering edit mode
Last seen 11 hours ago
United States
dds <- makeExampleDESeqDataSet(n=200)
dds <- DESeq(dds)
res <- results(dds)
anno <- data.frame(id = rownames(res)[(1:100)*2], 

A short, automated version (so safer):

res$id <- rownames(res)
res.sub <- merge(as(res,"data.frame"), anno, by="id")

A longer version with manual merge (less safe), keeping the metadata:

m <- match(anno$id, rownames(res))
res.sub <- res[m,]
res.sub$score <- anno$score
mcols(res.sub)[7,] <- DataFrame(type="annotation", 
                                description="a score value")
Entering edit mode
Last seen 15 months ago
United States

Call on your DESqResults objects before the merge, ie.

out <- merge(, geneMap, ...)

merge doesn't match by rownames, though, so you will have to specify the correct value for by, or a by.x and by.y combination of the column names in your result.ASE_Data and geneMap don't match up


Entering edit mode

Hi Steve,

I knew about this method, but the problem is that if you convert the S4-object using you are loosing valuable metadata information that are used downstream in the workflow.

Any other ideas.



Login before adding your answer.

Traffic: 373 users visited in the last hour
Help About
Access RSS

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

Powered by the version 2.3.6