DESeq2 results - Annotating and exporting results
1
0
Entering edit mode
Maka • 0
@54d5a2c1
Last seen 7 months ago
Germany

Hi,

I am working with isoforms.results from RSEM analysis.

I am trying to annotate my deseq results with symbol and entrez IDs, following the vignette http://master.bioconductor.org/packages/release/workflows/vignettes/rnaseqGene/inst/doc/rnaseqGene.html#annotating-and-exporting-results

Unfortunately, I cannot export them as a csv file because the 2 elements I am adding are list.

do you have any idea how this is happening? Below the code I am using.

Please, let me know if you need further information.

Thank you

res <- results(dds, contrast=c("treatment","drug","vehicle"), tidy=TRUE)    

> head(res)
                    row   baseMean log2FoldChange      lfcSE       stat     pvalue      padj
1  ENSMUST00000000001.5 508.710745    -0.01199816 0.08030722 -0.1494033 0.88123544 0.9941563
2 ENSMUST00000000003.14   0.000000             NA         NA         NA         NA        NA
3  ENSMUST00000114041.3   0.000000             NA         NA         NA         NA        NA
4 ENSMUST00000000028.14  53.297655    -0.12999380 0.23479087 -0.5536578 0.57981305 0.9560011
5 ENSMUST00000096990.10   8.682780     2.34835304 1.86921663  1.2563301 0.20899633 0.7698453


#create a new column with ensembl_gene_id 

library(biomaRt)
library(org.Mm.eg.db)
library(dplyr)
library("AnnotationDbi")
library(tidyverse)
ensembl=useMart("ENSEMBL_MART_ENSEMBL")
ensembl <- useDataset("mmusculus_gene_ensembl", mart = ensemble)


filterType <- "ensembl_transcript_id_version"
filterValues <- res$row
attributeNames <- c("ensembl_transcript_id_version", "ensembl_gene_id")

annot <- getBM(attributes=attributeNames,
               filters = filterType,
               values = filterValues,
               mart = ensemble) 

names(annot) <- c("row", "ensembl_gene_id")

res <- merge(res, annot, all.x=TRUE)

#Annotating symbol and entrez IDs with mapIds

res$symbol <- mapIds(org.Mm.eg.db,
                     keys=res$ensembl_gene_id,
                     column="SYMBOL",
                     keytype="ENSEMBL",
                     multiVals="first")

res$entrez <- mapIds(org.Mm.eg.db,
                       keys=res$ensembl_gene_id,
                       column="ENTREZID",
                       keytype="ENSEMBL",
                       multiVals="first")

 > head(res_1)
                    row   baseMean log2FoldChange      lfcSE       stat      pvalue       padj    ensembl_gene_id symbol entrez
1  ENSMUST00000000001.5 508.710745    -0.01199816 0.08030722 -0.1494033 0.881235438 0.99415633 ENSMUSG00000000001  Gnai3  14679
2 ENSMUST00000000003.14   0.000000             NA         NA         NA          NA         NA ENSMUSG00000000003   Pbsn  54192
3  ENSMUST00000000010.9  11.241632    -0.90230395 0.79248598 -1.1385740 0.254880870 0.81279086 ENSMUSG00000020875  Hoxb9  15417
4 ENSMUST00000000028.14  53.297655    -0.12999380 0.23479087 -0.5536578 0.579813045 0.95600111 ENSMUSG00000000028  Cdc45  12544
5 ENSMUST00000000033.12 344.732181    -0.42331235 0.13223803 -3.2011394 0.001368853 0.05267212 ENSMUSG00000048583   Igf2  16002



res <- as.data.frame(res)
write.csv(res, file = "results.csv")

# > write.csv(res, file = "results.csv")
Error in utils::write.table(res, file = "results.csv", col.names = NA,  : 
  unimplemented type 'list' in 'EncodeElement
DESeq2 • 605 views
ADD COMMENT
1
Entering edit mode
@james-w-macdonald-5106
Last seen 1 day ago
United States

Note that a data.frame is actually a list object, and a list can have another list as an element.

> d.f <- data.frame(this = letters, that = LETTERS)
> d.f$theother <- as.list(letters)
> d.f
   this that theother
1     a    A        a
2     b    B        b
3     c    C        c
4     d    D        d
5     e    E        e
6     f    F        f
7     g    G        g
8     h    H        h
9     i    I        i
10    j    J        j
11    k    K        k
12    l    L        l
13    m    M        m
14    n    N        n
15    o    O        o
16    p    P        p
17    q    Q        q
18    r    R        r
19    s    S        s
20    t    T        t
21    u    U        u
22    v    V        v
23    w    W        w
24    x    X        x
25    y    Y        y
26    z    Z        z
> write.csv(d.f, "fakeo.csv")
Error in utils::write.table(d.f, "fakeo.csv", col.names = NA, sep = ",",  : 
  unimplemented type 'list' in 'EncodeElement'

You could do sapply(res, class) to figure out which elements are list, and then deal with that as you see fit.

1
Entering edit mode

In my case, either unlist or do.call can 'fix' the situation.

> unlist(d.f$theother)
 [1] "a" "b" "c" "d" "e" "f" "g" "h"
 [9] "i" "j" "k" "l" "m" "n" "o" "p"
[17] "q" "r" "s" "t" "u" "v" "w" "x"
[25] "y" "z"
> do.call(c, d.f$theother)
 [1] "a" "b" "c" "d" "e" "f" "g" "h"
 [9] "i" "j" "k" "l" "m" "n" "o" "p"
[17] "q" "r" "s" "t" "u" "v" "w" "x"
[25] "y" "z"
> d.f$theother <- unlist(d.f$theother)
> write.csv(d.f, "fakeo.csv")
ADD REPLY

Login before adding your answer.

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