The support.bioconductor.org editor has been updated to markdown! Please see more info at: Tutorial: Updated Support Site Editor

Question: normalizationFactors DESeq2 package
0
gravatar for mariamari693693
15 months ago by
mariamari6936930 wrote:

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 • 335 views
ADD COMMENTlink modified 15 months ago by Gordon Smyth36k • written 15 months ago by mariamari6936930
Answer: normalizationFactors DESeq2 package
0
gravatar for Michael Love
15 months ago by
Michael Love22k
United States
Michael Love22k wrote:

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 COMMENTlink written 15 months ago by Michael Love22k

@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 REPLYlink written 15 months ago by mariamari6936930
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 364 users visited in the last hour