Save ExpressionSet to csv file with columns and rows headers
2
0
Entering edit mode
malik.yousef ▴ 10
@malikyousef-16077
Last seen 5.6 years ago

Hello I have an ExpressionSet object that I would like to save it to csv file. My question is how to transpose it to have the genes names on the rows and the columns name on the columns. Also how to save it with columns and rows headers? Below is the code.

library(Biobase) library(genefilter) library(data.table)

phenoData:

tmp <- read.csv("pdata.csv", row.names = 1) pdata <- AnnotatedDataFrame(tmp)

featureData:

tmp <- read.csv("fdata.csv", row.names = 1) fdata <- AnnotatedDataFrame(tmp)

expression data:

tmp <- read.table("exprs.txt") m <- as.matrix(tmp)

create ExpressionSet object:

eset <- new("ExpressionSet", exprs = m, phenoData = pdata, featureData = fdata)

f1 <- kOverA(5, 800) ffun <- filterfun(f1) wh1 <- genefilter(exprs(eset), ffun) eset=eset[wh1] write.csv( eset, file = "cleanData.csv", col.names=TRUE)

microarray genefilter • 2.3k views
ADD COMMENT
0
Entering edit mode
@mikhaelmanurung-17423
Last seen 2.5 years ago
Netherlands

You can transpose the data frame and then save it, like this:

tmp <- t(tmp) #transpose data frame

write.csv(tmp, "tmp.csv", row.names = TRUE, col.names = TRUE) # make sure to set row.names to TRUE!
ADD COMMENT
0
Entering edit mode

I try it. I got this error:

t(eset) Error in t.default(eset) : argument is not a matrix

ADD REPLY
0
Entering edit mode
@james-w-macdonald-5106
Last seen 13 hours ago
United States

Why are you going to all the trouble of creating an ExpressionSet, which is intended as an object to be used within R, just to output the data? That seems to be lots of work for no gain. Do note that kOverA requires that you extract the data from your ExpressionSet, so you are creating an ExpressionSet in order to extract something from it and then write that back out.

In addition, by default the expectation for genomic data in Bioconductor is to have the genes in rows and samples in columns, so if that's not how your data are already set up, then you are not using kOverA as intended. As for saving it with column and row headers, have you read the help page for write.table?

ADD COMMENT
0
Entering edit mode

Yes, my data has the genes in rows and samples in columns. However, writing it to csv file I get those genes in columns and sample on rows. I'm using ExpressinSet to be able using different packages to filter genes.

ADD REPLY
0
Entering edit mode

There isn't a method for write.csv that dispatches on an ExpressionSet, so it's not surprising that you get weird results. There is however a function called write.exprs that you could use:

> write.exprs(sample.ExpressionSet, file = "tmp.csv", sep = ",", row.names=TRUE)
> z <- read.csv("tmp.csv", row.names = 1)
> head(z)
                       A         B        C        D        E       F        G
AFFX-MurIL2_at  192.7420  85.75330 176.7570 135.5750 64.49390 76.3569 160.5050
AFFX-MurIL10_at  97.1370 126.19600  77.9216  93.3713 24.39860 85.5088  98.9086
AFFX-MurIL4_at   45.8192   8.83135  33.0632  28.7072  5.94492 28.2925  30.9694
AFFX-MurFAS_at   22.5445   3.60093  14.6883  12.3397 36.86630 11.2568  23.0034
AFFX-BioB-5_at   96.7875  30.43800  46.1271  70.9319 56.17440 42.6756  86.5156
AFFX-BioB-M_at   89.0730  25.84610  57.2033  69.9766 49.58220 26.1262  75.0083

ADD REPLY
0
Entering edit mode

And you can find such things using apropos:

> apropos("write")
 [1] "aspell_write_personal_dictionary_file"
 [2] "RtangleWritedoc"                      
 [3] "RweaveLatexWritedoc"                  
 [4] "write"                                
 [5] "write.AnnotatedDataFrame"             
 [6] "write.csv"                            
 [7] "write.csv2"                           
 [8] "write.dcf"                            
 [9] "write.exprs"    <------ right here                       
[10] "write.ftable"                         
[11] "write.socket"                         
[12] "write.table"                          
[13] "writeBin"                             
[14] "writeChar"                            
[15] "writeClipboard"                       
[16] "writeLines"                 
ADD REPLY

Login before adding your answer.

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