[Answer]-Using rpy2 and biomaRt in Django

1๐Ÿ‘

โœ…

As the error says, the Python type tuple is not converted automatically.

Try the following:

from rpy2.robjects.vectors import StrVector
result = R.getBM(attributes = StrVector(("hgnc_symbol","entrezgene", "chromosome_name", 
                                         "start_position", "end_position")),
                 filters = StrVector(("chromosome_name", 
                                      "start", "end", "biotype")),
                 values = filterlist,
                 mart = mart)

Notes: it would be possible to have a function that guesses what is the intent of the user might, but I consider this the potential source of too many issues. One can customize this by implementing
his/her own additional conversion. Alternatively, one can let rpy2 turn a Python list into an R list and unlist it.

from rpy2.robjects.packages import importr
base = importr('base')
ul = base.unlist
result = R.getBM(attributes = ul(["hgnc_symbol","entrezgene", "chromosome_name", 
                                  "start_position", "end_position"]),
                 filters = ul(["chromosome_name", 
                               "start", "end", "biotype"]),
                 values = filterlist,
                 mart = mart)
๐Ÿ‘คlgautier

Leave a comment