【问题标题】:Running deseq2 through rpy2通过 rpy2 运行 deseq2
【发布时间】:2017-06-08 20:00:18
【问题描述】:

我正在尝试使用 rpy2 从 Python 运行 DEseq2。 我应该如何通过设计矩阵? 我的脚本如下:

from numpy import *
from numpy.random import multinomial, random
from rpy2 import robjects
import rpy2.robjects.numpy2ri
robjects.numpy2ri.activate()
from rpy2.robjects.packages import importr
deseq = importr('DESeq2')

# Generate some data. 1000 genes, 10 samples
n = 1000
probabilities = random(n)
probabilities /= sum(probabilities)
data = zeros((n,10), int)
for i in range(10):
    data[:,i] = multinomial(1000000, probabilities)

# Make the data frame
d = {}
categories = ('1','2') * 5
d["key_1"] = robjects.IntVector(categories)
dataframe = robjects.DataFrame(d)

# Create the design matrix, and run DESeqDataSetFromMatrix
design = "~ key_1" # <--- I guess this is wrong
dds = deseq.DESeqDataSetFromMatrix(countData=data, colData=dataframe,design=design)

我得到的错误是

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2-2.8.5-py3.6-macosx-10.11-x86_64.egg/rpy2/rinterface/__init__.py:186: RRuntimeWarning: Error: $ operator is invalid for atomic vectors

warnings.warn(x, RRuntimeWarning)
Traceback (most recent call last):
File "testrpy.py", line 23, in <module>
dds = deseq.DESeqDataSetFromMatrix(countData=data, colData=dataf,design=design)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2-2.8.5-py3.6-macosx-10.11-x86_64.egg/rpy2/robjects/functions.py", line 178, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2-2.8.5-py3.6-macosx-10.11-x86_64.egg/rpy2/robjects/functions.py", line 106, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error: $ operator is invalid for atomic vectors

我的猜测是设计论点不正确。 有人有通过 rpy2 运行 DEseq 的例子吗?

谢谢。

【问题讨论】:

  • coldData=dataf 什么是dataf?它没有在您发布的代码中定义..
  • 抱歉,应该是dataframe。代码现已更正。

标签: python r rpy2


【解决方案1】:

啊!你快到了:

# Create the design matrix, and run DESeqDataSetFromMatrix
design = "~ key_1" # <--- I guess this is wrong

design 是一个字符串,但我猜它应该是一个公式。公式是 R 中的语言对象。

尝试:

from rpy2.robjects import Formula
design = Formula("~ key_1")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 2015-04-02
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 2019-08-27
    相关资源
    最近更新 更多