【发布时间】:2014-04-11 18:46:55
【问题描述】:
我设法使用 R 编写了一个程序,以通过 biomaRt 库找出数据库中的所有候选基因。我正在尝试使用 rpy2 将 R 脚本转换为 python 文件。
下面是我写的可以运行的 R 脚本。
library(biomaRt)
mart <- useMart(biomart="ensembl", dataset="hsapiens_gene_ensembl")
positions <- read.table("positions.txt")
names(positions) <- c("chr","start","stop")
positions$start <- positions$start - 650000
positions$stop <- positions$stop + 650000
filterlist <- list(positions$chr,positions$start,positions$stop,"protein_coding")
getBM(attributes = c("hgnc_symbol","entrezgene", "chromosome_name",
"start_position", "end_position"), filters = c("chromosome_name", "start",
"end", "biotype"), values = filterlist, mart = mart)
如何使用 rpy2 将上面的 R 脚本转换为 python 脚本?
from rpy2.robjects import r as R
R.library("biomaRt")
mart = R.useMart(biomart="ensembl",dataset="hsapiens_gene_ensembl")
position = R.list("7","110433484", "110433544")
filterlist = R.list(position[0],position[1],position[2],"protein_coding")
result = R.getBM(attributes = ("hgnc_symbol","entrezgene", "chromosome_name",
"start_position", "end_position") ,filters = ("chromosome_name",
"start", "end", "biotype"), values = filterlist, mart = mart)
最后一行的错误:
result = R.getBM(attributes = ("hgnc_symbol","entrezgene", "chromosome_name",
"start_position", "end_position") ,filters = ("chromosome_name",
"start", "end", "biotype"), values = filterlist, mart = mart)
声明:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/Users/project/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 86, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/Users/project/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 34, in __call__
new_kwargs[k] = conversion.py2ri(v)
File "/Users/project/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 148, in default_py2ri
raise(ValueError("Nothing can be done for the type %s at the moment." %(type(o))))
ValueError: Nothing can be done for the type <type 'tuple'> at the moment.
任何人都知道如何使用 rpy2 转换为 python 以及如何在 django 中嵌入 python 代码以便显示数据?
【问题讨论】:
标签: python django r bioinformatics rpy2