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
In my case, either
unlist
ordo.call
can 'fix' the situation.