It seems like the best way to write an email around these parts is using R
code, so here goes.  I'm just wondering why a coercion that I define for
DataFrame -> data.frame doesn't automatically get used in practice.


library(Biobase)
library(GEOquery)
library(GenomicRanges)

## download a dataset which will become a SummarizedExperiment
##
gset <- getGEO("GSE41826") ## GSEMatrix seems to hose it
if (length(gset) > 1) idx <- grep("GPL13534", attr(gset, "names"))
  else idx <- 1  ## a kludge, for dealing with SuperSeries entries
gset <- gset[[idx]]
sampleNames(gset) <- gset$title

## turn it into a SummarizedExperiment so I can call DMRs
if(require(regulatoR))
  sortedBrainCells <- as(gset, 'SummarizedExperiment')
  ## the above could maybe become a generic for GEOquery... !?

## massage some covariates
sortedBrainCells$sex <-
    as.factor(sub('Sex: ', '', sortedBrainCells$characteristics_ch1.2))
sortedBrainCells$race <-
    as.factor(sub('race: ', '', sortedBrainCells$characteristics_ch1.3))
sortedBrainCells$age <-
    as.numeric(sub('age: ', '', sortedBrainCells$characteristics_ch1.4))

## now the part that is bugging me: why won't R coerce automatically?
##
## define a coercion for DataFrame to data.frame:
setAs("DataFrame", "data.frame", function(from) as.data.frame(from))
##
## try to assemble a model.matrix
model.matrix(~ age + race + sex, data=colData(sortedBrainCells))
##
## D'OH!
##
## Error in as.data.frame.default(data, optional = TRUE) :
##  cannot coerce class "structure("DataFrame", package = "IRanges")" to a
data.frame

##  ok fine whatever, I'll do the coercion myself
mat <- model.matrix(~ age + race + sex,
data=as(colData(sortedBrainCells),'data.frame'))

head(mat)
##        (Intercept) age raceAsian raceCaucasian sexMale
## 5175-G           1  47         0             1       1
## 5175-N           1  47         0             1       1
## 813-N            1  30         0             1       0
## 1740-N           1  13         0             0       0
## 1546-N           1  14         0             0       0
## 1546-G           1  14         0             0       0


-- 
*A model is a lie that helps you see the truth.*
*
*
Howard Skipper<http://cancerres.aacrjournals.org/content/31/9/1173.full.pdf>

	[[alternative HTML version deleted]]

