normalizationFactors DESeq2 package
1
0
Entering edit mode
@mariamari693693-12007
Last seen 6.4 years ago

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
}
deseq2 Tutorial • 1.4k views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 1 hour ago
United States

normalizationFactors is a generic defined in AllGenerics.R

Defining methods and generics for S4 classes is covered here:

http://adv-r.had.co.nz/S4.html

I’m not sure what advice to give because I don’t know if you want to write your own custom function just for personal use (in which case you should use a name that doesn’t conflict with existing methods) or if you are learning how R/Bioconductor packages are written.

ADD COMMENT
0
Entering edit mode

@Micheal Love  great! thanks. I see. I am both learning how DESeq2 works and also just learned how methods/classes work :-)
thanks a lot

ADD REPLY

Login before adding your answer.

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