I am looking inside the DESeq2 code to learn how it works.
I can't find any definition for the function "normalizationFactors".
The reason is that when I run :
normalizationFactors.DESeqDataSet <- function(object) {
# Temporary hack for backward compatibility with "old" DESeqDataSet
# objects. Remove once all serialized DESeqDataSet objects around have
# been updated.
if (!.hasSlot(object, "rowRanges"))
object <- updateObject(object)
if (!"normalizationFactors" %in% assayNames(object)) return(NULL)
assays(object)[["normalizationFactors"]]
}
setMethod("normalizationFactors", signature(object="DESeqDataSet"),
normalizationFactors.DESeqDataSet)
setReplaceMethod("normalizationFactors", signature(object="DESeqDataSet", value="matrix"),
function(object, value) {
stopifnot(all(!is.na(value)))
stopifnot(all(is.finite(value)))
stopifnot(all(value > 0))
# Temporary hack for backward compatibility with "old"
# DESeqDataSet objects. Remove once all serialized
# DESeqDataSet objects around have been updated.
if (!.hasSlot(object, "rowRanges"))
object <- updateObject(object)
# enforce same dimnames
dimnames(value) <- dimnames(object)
assays(object)[["normalizationFactors"]] <- value
validObject( object )
object
})
I get the following error:
Error in setMethod("normalizationFactors", signature(object = "DESeqDataSet"), : no existing definition for function ‘normalizationFactors’
Should I define a function like:
defining a function like is OK?
normalizationFactors <- function(object){
normFactors <- matrix(runif(nrow(object)*ncol(object),0.5,1.5),
ncol=ncol(object),nrow=nrow(object),
dimnames=list(1:nrow(object),1:ncol(object)))
normFactors <- normFactors / exp(rowMeans(log(normFactors)))
normalizationFactors(object) <- normFactors
}
@Micheal Love great! thanks. I see. I am both learning how DESeq2 works and also just learned how methods/classes work :-)
thanks a lot