6

I'm trying to use bioconductor (Specifically seqLogo) from rpy2. I found the helpful package:

http://pythonhosted.org/rpy2-bioconductor-extensions/index.html

however when I try this from the documentation of the package:

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

# evaluate locally a remote R script
base.source("http://www.bioconductor.org/biocLite.R")
base.require("biocLite")
bioclite = robjects.globalenv['biocLite']

I get the error

  File "/usr/local/lib/python2.7/dist-packages/rpy2-2.3.6-py2.7-linux-x86_64.egg/rpy2/robjects/environments.py", line 17, in __getitem__
    res = super(Environment, self).__getitem__(item)
LookupError: 'biocLite' not found

In the R environment on my system, the following works perfectly:

> require(seqLogo)

and I'd like to use this already installed seqLogo package from rpy2. How can this be done? since I have rpy2 installed, I can do:

>>> import bioc

but not sure how to install new bioconductor packages like seqLogo from bioc.

If I try:

importr("seqLogo")

I get the error:

rpy2.rinterface.RRuntimeError: Error in loadNamespace(name) : there is no package called ‘seqLogo’

thanks.

1 Answers1

10

The Bioconductor project changed a bit the internals of its package installer. The following should work:

from rpy2.robjects.packages import importr

# do the following _only the first time_, to install the package seqLogo
base = importr('base')
base.source("http://www.bioconductor.org/biocLite.R")
biocinstaller = importr("BiocInstaller")
biocinstaller.biocLite("seqLogo")

# load the installed package "seqLogo"
seqlogo = importr("seqLogo")

Otherwise the bioconductor extensions to rpy2 have not been updated for quite some time. There might be other things that would need to be fixed.

lgautier
  • 11,363
  • 29
  • 42
  • @user248237dfsf says that seqLogo is already installed, so shouldn't `importr("seqLogo")` work without the above? I guess there's something about the library paths of the interactive R versus the R used from rpy? This answer seems appropriate if seqLogo were not already installed. – Martin Morgan Jun 09 '13 at 00:13
  • @MartinMorgan Good observation. This means that the R installation rpy2 is linking to is different from the one user248237dfsf is trying the R code with (although we do not know whether this is intentional or not). If running the code above, it will install seqLogo in whatever R installation rpy2 finds on the system [note: I edited the comment in the Python code in the answer to make clear(er) that installing the package should only be done the first time]. – lgautier Jun 09 '13 at 10:04
  • I am trying above code getting following Error ....RRuntimeError: Error in install.packages("BiocInstaller", repos = a["BioCsoft", "URL"]) : unable to install packages – Milan Amrut Joshi May 01 '19 at 11:28