biolab / orange-bio

Other
9 stars 32 forks source link

python3 ontology loading from file #86

Closed arvkevi closed 7 years ago

arvkevi commented 8 years ago

I may be misusing the command to load an ontology from file. If so, please disregard.

In Python 3.5:

(test3) kevin@kevin-VirtualBox:~$ python
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

I was unable to load an ontology from file using the OBOOntology constructor:

>>> from orangecontrib.bio.ontology import OBOOntology
>>> hpo = OBOOntology('/home/kevin/hpo_downloads/hp.obo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kevin/anaconda2/envs/test3/lib/python3.5/site-packages/orangecontrib/bio/ontology.py", line 542, in __init__
    self.load(file)
  File "/home/kevin/anaconda2/envs/test3/lib/python3.5/site-packages/orangecontrib/bio/ontology.py", line 577, in load
    for event, value in parser.parse(progress_callback=progress_callback):
  File "/home/kevin/anaconda2/envs/test3/lib/python3.5/site-packages/orangecontrib/bio/ontology.py", line 485, in parse
    header = data[: data.index("\n[")]
TypeError: a bytes-like object is required, not 'str'

The commit worked for Python 2.7 & 3.5. It imports io and opens the ontology file with 'utf-8' encoding when using Python 3.