RPy2 和 Bioconductor:基因表达示例

发布于 2024-11-30 08:28:02 字数 2722 浏览 0 评论 0 原文

我正在尝试弄清楚如何在 Bioconductor 中进行经典基因表达示例使用 Rpy2,我一开始就陷入困境。你如何加载数据?在 R 中,我们这样做:

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

在 Python 中,我们这样做:

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

如何执行与以下内容等效的 Python:

> data('ALL') ??

我没有看到在扩展的文档中加载包数据的示例。我认为这可能是这样,但似乎数据不属于正确的类别,因为当输入到 featureNames 时,它具有 signature“character”

>>> 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"

更新:我想我有它现在:

>>> 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]
>>> 

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]
>>> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-12-07 08:28:02

这个问题应该在包含rpy2的bioconductor扩展的Python包中解决

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文