Add new columns to DESeqResults from text file by matching rownames.
2
1
Entering edit mode
@kirannbishwa01-12980
Last seen 6.3 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”

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

> do.call(cbind.data.frame, 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 • 4.2k views
ADD COMMENT
3
Entering edit mode
@mikelove
Last seen 15 hours ago
United States
dds <- makeExampleDESeqDataSet(n=200)
dds <- DESeq(dds)
res <- results(dds)
anno <- data.frame(id = rownames(res)[(1:100)*2], 
                   score=runif(100))

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")
​mcols(res.sub)
ADD COMMENT
1
Entering edit mode
@steve-lianoglou-2771
Last seen 20 months ago
United States

Call as.data.frame on your DESqResults objects before the merge, ie.

out <- merge(as.data.frame(result.ASE_Data), 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

 

ADD COMMENT
1
Entering edit mode

Hi Steve,

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

Any other ideas.

 

ADD REPLY

Login before adding your answer.

Traffic: 666 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