saezlab / pypath

Python module for prior knowledge integration. Builds databases of signaling pathways, enzyme-substrate interactions, complexes, annotations and intercellular communication roles.
http://omnipathdb.org/
GNU General Public License v3.0
135 stars 47 forks source link

TypeError: invalid arguments to setopt (in Python 2.7) #25

Closed IvoLeist closed 6 years ago

IvoLeist commented 6 years ago

Hi,

I installed the latest pypath version (0.7.93) via pip install git+git://github.com/saezlab/pypath.git My python version is Python 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2

I found 2 relatively easy fixable bugs in your application which I reckon only happen in python2.7 so I did not wanted to do a pull request.

1.import igraph runs into:

import igraph Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/site-packages/igraph/init.py", line 42, in import gzip File "/usr/lib/python2.7/gzip.py", line 36, in class GzipFile(io.BufferedIOBase): AttributeError: 'module' object has no attribute 'BufferedIOBase'

-->Bug fix: renamed the io.py file into io_test.py [] (I hope this does not break other things in your code ?) and rebuild your application using python setup.py sdist see: https://stackoverflow.com/questions/6315440/how-to-solve-attributeerror-when-importing-igraph

2.Executing pa.load_omnipath() runs into..

... --> 909 self.curl.setopt(self.curl.URL, url or self.url) 910 911 def set_target(self)

-->Bug fix: added in curl.py an if statement to check if the url is unicode and if so encode it to ascii *see: https://bugs.launchpad.net/gwibber/+bug/542501

if isinstance(self.url, unicode):
            self.curl.setopt(self.curl.URL, url or self.url.encode("ascii"))

I'll let you know if I run in some other bugs using python2.7

Best, Ivo

deeenes commented 6 years ago

Hi Ivo,

Thanks a lot for your suggestions!

First, I think you have wrong igraph module installed. igraph (http://igraph.org/) does not have init.py and does not produce the error above at import. As you see the error happens at import of gzip which is part of the standard library, just like io which actually supposed to have BufferedIOReader. You should check where io is actually imported from. Don't you have an io.py laying around in your working directory and clashing with the standard library io?

About second issue, I added now something similar what you suggested but I don't experience error in Python 2.7 if I pass unicode value as URL. Could you maybe check what was the value of url or self.url when you got the error?

Best wishes,

Denes

IvoLeist commented 6 years ago

Thank you Denes for the fast reply,

Answer to 1. issue I already checked my igraph version several times: even specifically tried to deinstall it:

bash-4.2$ pip uninstall igraph You are using pip version 7.1.0, however version 18.0 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Cannot uninstall requirement igraph, not installed

below you find my pip freeze where only this igraph is installed:python-igraph==0.7.1.post6

bash-4.2$ pip freeze | grep graph cryptography==2.3.1 pygraphviz==1.5 python-igraph==0.7.1.post6

Answer to 2. issue I unfortunately cannot reproduce the error or check the url because the application now reads the files from the cache and not longer from the web but if you tell me how to reset the cache I can check that for you ;-)

Btw I have another issue:

after this part of the logs

Processing KEGG Pathways -- finished: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 214/214 [00:18<00:00, 11.6it/s] :: Directions and signs set for 2962 edges based on KEGG, 510 new directions, 856 new signs. :: Loading data from cache previously downloaded from www.bri.nrc.ca :: Ready. Resulted plain text of type unicode string. 15003c9164-HumanSignalingNetwork_v6.csv :: Local file at/OmniPath_modified/pypath/dist/pypath-0.7.93/src/cache/869a74d3e85971d8468a4015003c9164-HumanSignalingNetwork_v6.csv. :: Directions and signs set for 0 edges based on Wang, 0 new directions, 0 new signs. :: Directions and signs set for 5080 edges based on ACSN, 3101 new directions, 50 new signs. :: Loading data from cache previously downloaded from www.phosphosite.org :: Ready. Resultedgz extracted dataof type file object. 0c6ce94998-Kinase_substrates.owl.gz :: Local file at /OmniPath_modified/pypath/dist/pypath-0.7.93/src/cache/8eef83fc6c2faa3170043a0c6ce94998-Kinase_substrates.owl.gz.

this happens:

Traceback (most recent call last): File "", line 1, in File "pypath/main.py", line 7925, in load_omnipath self.third_source_directions() File "pypath/main.py", line 8031, in third_source_directions self.phosphosite_directions(graph=graph) File "pypath/main.py", line 8046, in phosphosite_directions psite = dataio.phosphosite_directions() File "pypath/dataio.py", line 6644, in phosphosite_directions curated, noref = get_phosphosite() File "pypath/dataio.py", line 6489, in get_phosphosite xml = ET.parse(bpax) File "", line 62, in parse File "", line 26, in parse TypeError: coercing to Unicode: need string or buffer, generator found

Best, Ivo

deeenes commented 6 years ago

Hi Ivo,

About igraph: what happens on import gzip? Can you find your io module and make sure it is imported from the standard library and has BufferedIOBase?

Thanks for reporting the issue with KEGG, I will fix soon.

Best,

Denes

deeenes commented 6 years ago

Fixed in 0.7.94.