coerce aafTable object into dataframe (annaffy)
4
0
Entering edit mode
Georg Otto ▴ 510
@georg-otto-956
Last seen 8.1 years ago
Hi, I have a question concerning an aafTable object generated using the package annaffy: I would like to coerce it into a data frame, but the way I am trying to do it does not work. Here is my code: > probeids<-geneNames(Data) > anntable<-aafTableAnn(probeids, "package", anncols) > slotNames(anntable) [1] "probeids" "table" > data.frame<-as.data.frame(anntable at table) Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class "aafList" into a data.frame I was supposing that this is the way to coerce a list inot a data frame, but apparently it is not working with this kind of object. Could somebody out there help me? I am using R 2.2.1 and annaffy 1.3.0 Best, Georg
annaffy annaffy • 1.0k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 13 hours ago
United States
Hi Georg, Georg Otto wrote: > Hi, > > I have a question concerning an aafTable object generated using the > package annaffy: I would like to coerce it into a data frame, but the > way I am trying to do it does not work. Here is my code: > > >>probeids<-geneNames(Data) >>anntable<-aafTableAnn(probeids, "package", anncols) >>slotNames(anntable) > > [1] "probeids" "table" > > >>data.frame<-as.data.frame(anntable at table) > > Error in as.data.frame.default(x[[i]], optional = TRUE) : > cannot coerce class "aafList" into a data.frame > > I was supposing that this is the way to coerce a list inot a data > frame, but apparently it is not working with this kind of object. Could > somebody out there help me? I don't think you will be able to do this for two reasons. First, the table slot of an anntable is an S4 object, so I believe you need to have a method defined for that class in order to convert from an aafList to a data.frame. Second, an aafList is a list of lists, which allows annaffy to build an HTML table with equal numbers of cells per column, but with variable numbers of elements in each cell. A data.frame is a special type of list that requires each list element to be of the same length. Since this is not necessarily true for an aafList, even if you were able to circumvent the S4 system there is no guarantee that you would be able to convert your aafList into a data.frame. For instance, if I build an anntable using the first 10 probe ids in an hgu133plus2 chip I get this: > probids <- ls(hgu133plus2SYMBOL)[1:10] > tmp <- aafTableAnn(probids, "hgu133plus2", aaf.handler()[1:6]) > sapply(tmp at table, function(x) lapply(x, length)) Probe Symbol Description Function Chromosome Chromosome Location [1,] 1 1 1 0 1 1 [2,] 1 1 1 0 1 1 [3,] 1 1 1 0 1 1 [4,] 1 1 1 0 1 1 [5,] 1 1 1 0 1 1 [6,] 1 1 1 0 1 1 [7,] 1 1 1 0 1 2 [8,] 1 1 1 0 1 1 [9,] 1 1 1 0 1 1 [10,] 1 1 1 0 1 1 Note that the Chromosome Location has one element of length two, so even if you could coerce to a data.frame, it wouldn't work because this particular column would be too long. I am curious why you want this in a data.frame. Can you not accomplish what you want to do by either outputting your anntable in HTML or text form? Best, Jim > > I am using R 2.2.1 and annaffy 1.3.0 > > Best, > > Georg > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623
ADD COMMENT
0
Entering edit mode
Georg Otto ▴ 510
@georg-otto-956
Last seen 8.1 years ago
Hi Jim and all others, "James W. MacDonald" <jmacdon at="" med.umich.edu=""> writes: > > Georg Otto wrote: >> >> I have a question concerning an aafTable object generated using the >> package annaffy: I would like to coerce it into a data frame, but the >> way I am trying to do it does not work. Here is my code: >> >> >>>probeids<-geneNames(Data) >>>anntable<-aafTableAnn(probeids, "package", anncols) >>>slotNames(anntable) >> >> [1] "probeids" "table" >> >> >>>data.frame<-as.data.frame(anntable at table) >> >> Error in as.data.frame.default(x[[i]], optional = TRUE) : >> cannot coerce class "aafList" into a data.frame >> > > I don't think you will be able to do this for two reasons. First, the > table slot of an anntable is an S4 object, so I believe you need to have > a method defined for that class in order to convert from an aafList to a > data.frame. > > Second, an aafList is a list of lists, which allows annaffy to build an > HTML table with equal numbers of cells per column, but with variable > numbers of elements in each cell. A data.frame is a special type of list > that requires each list element to be of the same length. Since this is > not necessarily true for an aafList, even if you were able to circumvent > the S4 system there is no guarantee that you would be able to convert > your aafList into a data.frame. > That is a good point, that I haven't considered before. > > I am curious why you want this in a data.frame. Can you not accomplish > what you want to do by either outputting your anntable in HTML or text form? > What I actually want to do is to put the annotation contained in the "zebrafish" package (class aafTable) together with annotation from TIGR's Resourcerer (class: matrix) and EnsEMBL's biomart (class data.frame) in one big table. My idea was to convert all datasets into a dataframe and use merge() to merge them together. You are right that this might not be a valid strategy for the aafTable, so I meanwhile used saveText() to output the aafTable in a temporary text file and read.delim() to read it in a data frame. This works, but I personally dislike the idea of writing to and reading from temporary files, and with biomart data I run again into the problem of having variable numbers of annotations per probeset. An alternative strategy would be to write all the data in aafTables and then use merge() to merge them. However, merge.aafTable leaves only those probesets that occur in both tables (in contrast to the generic merge for data frames, which has an option x.all=TRUE to retain data that only ocur in the first table and in such a case insert NA in columns from the second table). So the question arises: Is there a way to merge aafTables of different sizes? Or are there smarter ways to put the aforementioned annotation data together? Best, Georg
ADD COMMENT
0
Entering edit mode
@colin-a-smith-325
Last seen 7.4 years ago
Germany
Georg- > So the question arises: > Is there a way to merge aafTables of different sizes? Now there is. I implemented the all, all.x, and all.y options in annaffy's merge function. Before I commit the change, it would be great if you could test out the modified function to see if it will work for you. Download the following and source it into your R session after loading annaffy: http://zinc.compbio.ucsf.edu/~colin/merge.aafTable.R Hope this helps. -Colin
ADD COMMENT
0
Entering edit mode
Georg Otto ▴ 510
@georg-otto-956
Last seen 8.1 years ago
"Colin A. Smith" <colin at="" colinsmith.org=""> writes: Colin, >> So the question arises: >> Is there a way to merge aafTables of different sizes? > > Now there is. I implemented the all, all.x, and all.y options in > annaffy's merge function. Before I commit the change, it would be > great if you could test out the modified function to see if it will > work for you. Download the following and source it into your R > session after loading annaffy: > > http://zinc.compbio.ucsf.edu/~colin/merge.aafTable.R > Thanks a lot! > anntable.merged <- merge(anntable.affy, anntable.tigr, all = TRUE) works exactly the way I need it. There is one more (and hopefully last) question I have concerning reading data into aafTable objects (sorry for this, but my knowledge concerning these kind of data structures is still somewhat limited, and I haven't found anything about it): Some annotation tables (eg. output from biomaRt) have multiple annotations per probeset ID, that is represented in the table as multiple rows, e.g. Probeset Ensembl ID A 1 A 2 A 3 A 4 B 5 B 6 C 7 Is there a way I could write this in an aafTable in the same way as it is done in the affy annotation packages, i.e. with multiple annotations per field, something like this: anntable at probeids anntable at table$"Ensembl ID" A 1 2 3 4 B 5 6 C 7 Any hint will be highly appreciated. Cheers and thanks again, Georg
ADD COMMENT

Login before adding your answer.

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