Frage

I'm trying to work out how to do the classic gene expression example in Bioconductor using Rpy2, and I'm stuck right at the beginning. How do you load the data? In R we do:

> library('ALL')
> library('limma')
> data('ALL')

In Python we do:

>>> import rpy2.robjects as robjects
>>> from rpy2.robjects.packages import importr
>>> base = importr('base')
>>> ALL = importr('ALL')

How to do the Python equivalent of:

> data('ALL') ??

I don't see an example where package data is loaded in the docs for the extensions. I thought this could be it but it seems that data is not of the right class because it has signature "character" when fed to featureNames:

>>> data = robjects.r('data(ALL)')
>>> data.rclass
<rpy2.rinterface.SexpVector - Python:0x1004b3828 / R:0x10376d558>
>>> featureNames = robjects.r('featureNames')
>>> featureNames(data)
Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "featureNames", for signature "character"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/rpy2-2.2.2dev_20110818-py2.6-macosx-10.6-universal.egg/rpy2/robjects/functions.py", line 82, in __call__
    return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
  File "/Library/Python/2.6/site-packages/rpy2-2.2.2dev_20110818-py2.6-macosx-10.6-universal.egg/rpy2/robjects/functions.py", line 34, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "featureNames", for signature "character"

UPDATE: I think I have it now:

>>> import rpy2.robjects as robjects
>>> from rpy2.robjects.packages import importr
>>> base =  importr('base')
>>> ALL = importr('ALL')
>>> data = robjects.r('data(ALL)')
>>> data.rclass
<rpy2.rinterface.SexpVector - Python:0x258b190 / R:0xdf86c8>
>>> data = robjects.globalenv['ALL']
>>> data
<RS4 - Python:0x2591490 / R:0x29a2134>
>>> data.rclass
<rpy2.rinterface.SexpVector - Python:0x258b3b0 / R:0xdf85c8>
>>> featureNames = robjects.r('featureNames')
>>> featureNames(data)
<StrVector - Python:0x23e4f08 / R:0x304fc00>
['1000..., '1001..., '1002..., ..., 'AFFX..., 'AFFX..., 'AFFX...]
>>> exprs = robjects.r['exprs']
>>> e = exprs(data)
>>> e
<Matrix - Python:0x23b2da0 / R:0x84d8000>
[7.597323, 5.046194, 3.900466, ..., 3.095670, 3.342961, 3.842535]
>>> 
War es hilfreich?

Lösung

This problem should be solved in a Python package containing bioconductor extensions to rpy2

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top