Dear Bioconductor users,
I would like to establish a new S4 class, based on the SummarizedExperiment
class from the package of the same name.
I am wondering that the correct way of initializing a SummarizedExperiment
is. The SummarizedExperiment
method accepts e.g. a matrix and constructs the missing colData
and rowData
objects.
m <- matrix(1:24, ncol = 3, dimnames = list(letters[1:8], letters[9:11])) se <- SummarizedExperiment(m) colData(se) rowData(se)
But when I try to obtain the same result using the `new` method, using the following lines of code:
new("SummarizedExperiment", assays = Assays(SimpleList(counts = m)), colData = DataFrame(row.names = colnames(m)), rowData = DataFrame(row.names = row.names(m)))
I get this error:
Error in initialize(value, ...) : invalid name for slot of class “SummarizedExperiment”: rowData
To provide some context, I would like to define a simple subclass of SummarizedExperiment
. But I don't understand how to create an object of my new class with the new
method, e.g. without using the SummarizedExperiment
constructor method - and copying the slots into the new object. (This is just an example, I am aware that similar classes already exist, e.g. in the DESeq2 package.)
library(SummarizedExperiment) # define new class, inheritng from SummarizedExperiment setClass("CountSet", contains = "SummarizedExperiment", representation(filtered = "logical"), prototype = prototype( filtered = FALSE), validity = function(object) { if (!("raw" %in% assayNames(object))) return( "The assays slot must contain a matrix named 'counts'" ) if (any( counts(object) < 0 )) return( "The count data contains negative values" ) }) CountSet <- function(counts, colData, rowData, ...) { se <- SummarizedExperiment(assays = SimpleList(counts = counts), ...) cs <- new("CountSet") for(sl in slotNames(se)) { slot(cs, sl) <- slot(se, sl) } return(cs) }
Any hints?
Thanks a lot,
Thomas
Thanks a lot, Martin - both for the great explanation and for pointing out the bioc-devel list.
Hi Thomas,
FWIW the vignette in the SummarizedExperiment package has a section dedicated to extending the RangedSummarizedExperiment class. It's the last section of the vignette.
Cheers,
H.