I am trying to use DESeq2 package through rpy2. Overall, it works fine, but I am struggling with using accessor function.
Specifically, I have a sample data frame tcdf
and counts data frame access_tcdf
that I convert to R objects by
rtcdf = pandas2ri.py2ri_pandasdataframe(tcdf)
raccess_tcdf = pandas2ri.py2ri_pandasdataframe(access_tcdf)
and I create a DESeq_DataSet by
ddsMat = deseq2.DESeqDataSetFromMatrix(countData = raccess_tcdf,
colData = rtcdf,
design = Formula("~ replicate + strain + time"))
The sticking point is how I can supply predefined normalization factors in rpy2? I have a data frame of per gene normalization factors rnorm_factor
and in R I would normally do:
normalizationFactors( ddsMat ) <- data.matrix(norm_factor)
but I don't understand how and if I can call normalizationFactors function from rpy2.
When I tried:
deseq2.normalizationFactors(ddsMat,bdm)
I got RRuntimeError:
Error in .local(object, ...) :
unused argument (c(0.401314864917528, 0.375673211527775, ...
I would appreciate suggestions on how to do this.
What is happening in R is that the call
normalizationFactors( ddsMat ) <- data.matrix(norm_factor)
is equivalent to
ddsMat <- `normalizationFactors<-`(ddsMat, data.matrix(norm_factor))
If this is just setting an attribute in an R S4 class instance you can use the strategy described in the documentation (https://rpy2.github.io/doc/v2.9.x/html/notebooks/s4class.html#class-attributes) otherwise the strategy used by rpy2 itself to implement names(foo) <- bar
can be used (see here).