Comments (11)
@cthoyt Thanks for your support !
from pybel.
Hi! Could you please paste the entire stack trace, as well as the version of python, pybel, and Indra that you're using?
If I had to guess without seeing that, it would be that the biopax file is using a nonstandard (ie not utf8) encoding.
from pybel.
Hello, Thanks for your quick reply
I am using python 3.8.3,pybel 0.14.1 and indra 1.18.0
import os
import pybel
from urllib.request import urlretrieve
apoptosis_url = 'https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level2/1643685'
apoptosis_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'WP254_951071.owl')
if not os.path.exists(apoptosis_path):
urlretrieve(apoptosis_url, apoptosis_path)
graph = pybel.from_biopax(apoptosis_path)
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-2-521428bb8621> in <module>
----> 1 graph = pybel.from_biopax(apoptosis_path)
~\Anaconda3\lib\site-packages\pybel\io\indra.py in from_biopax(path, name, version, description, authors, contact, license, copyright, disclaimer)
167 from indra.sources.biopax import process_owl
168
--> 169 model = process_owl(path)
170
171 return from_indra_statements(
~\Anaconda3\lib\site-packages\indra\sources\biopax\api.py in process_owl(owl_filename)
171 A BiopaxProcessor containing the obtained BioPAX model in bp.model.
172 """
--> 173 model = model_from_owl_file(owl_filename)
174 return process_model(model)
175
~\Anaconda3\lib\site-packages\pybiopax\api.py in model_from_owl_file(fname)
39 """
40 with open(fname, 'r') as fh:
---> 41 owl_str = fh.read()
42 return model_from_owl_str(owl_str)
43
~\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
21 class IncrementalDecoder(codecs.IncrementalDecoder):
22 def decode(self, input, final=False):
---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0]
24
25 class StreamWriter(Codec,codecs.StreamWriter):
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 8815866: character maps to <undefined>
from pybel.
You'll notice that this error is actually happening in a transitive dependency, PyBioPAX, because PyBEL defers to INDRA's BioPAX reader, and INDRA defers to PyBioPAX.
It's likely due to an issue with the default encoding (ref: https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character). Are you on Windows?
I've made a PR to PyBioPAX at gyorilab/pybiopax#7 that will be the first step in fixing the issue. After that's accepted, we can make a PR on INDRA to also allow the specification of file encoding from the user-facing API, then update PyBEL to do the same.
Because PyBEL is just wrapping the INDRA code for convenience (and similarly, INDRA is wrapping the PyBioPAX code for convenience), I'll provide you with an example that unwraps and re-implements some of this for immediate use.
import os
from urllib.request import urlretrieve
import indra.sources.biopax
import pybel
import pybiopax
apoptosis_url = 'https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level2/1643685'
apoptosis_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'WP254_951071.owl')
if not os.path.exists(apoptosis_path):
urlretrieve(apoptosis_url, apoptosis_path)
with open(apoptosis_path, 'r', encoding='utf-8') as file:
owl_str = file.read()
biopax_model = pybiopax.model_from_owl_str(owl_str)
biopax_processor = indra.sources.biopax.process_model(biopax_model)
graph = pybel.from_indra_statements(biopax_processor.statements)
If it fails on the file reading, try some different encodings until you get success.
from pybel.
Thanks for your support!!
The error has resolved now.
from pybel.
Great! We're working on updating our first-class WikiPathways -> BEL converter which needs a bit of maintenance, and I'm sure it will get better results than the WikiPathways -> Reactome -> INDRA -> BEL loop here once it's ready. Until then, happy coding!
from pybel.
Hello @cthoyt , I was trying to plot a graph using PyBEL after reading a BioPAX file.
I am getting an empty graph by using below code
import os
from urllib.request import urlretrieve
from pybel_jupyter import to_jupyter
import indra.sources.biopax
import pybel
import pybiopax
apoptosis_url = 'https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level2/1643685'
apoptosis_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'WP254_951071.owl')
if not os.path.exists(apoptosis_path):
urlretrieve(apoptosis_url, apoptosis_path)
with open(apoptosis_path, 'r', encoding='utf-8') as file:
owl_str = file.read()
biopax_model = pybiopax.model_from_owl_str(owl_str)
biopax_processor = indra.sources.biopax.process_model(biopax_model)
graph = pybel.from_indra_statements(biopax_processor.statements)
to_jupyter(graph)
While I am trying to get summary of graph I am getting as
graph.summarize()
indra v64396028-494f-47d8-b3b8-cdfec1102634
Number of Nodes: 0
Number of Edges: 0
Number of Citations: 0
Number of Authors: 0
Network Density: 0.00E+00
Number of Components: 0
Number of Warnings: 0
Please provide me a solution to resolve this problem.
Thanks!
from pybel.
Unfortunately, problem is not originating from PyBEL, but rather due to the content from Reactome itself. BioPAX is only an upper level ontology and it does not prescribe how information should be encoded. Since Reactome does not use the schema that PyBioPAX expects, PyBioPAX can not parse anything useful from Reactome content. Therefore, no information makes it into INDRA statements via biopax_processor = indra.sources.biopax.process_model(biopax_model)
and none into the BEL graph via
graph = pybel.from_indra_statements(biopax_processor.statements)
.
You can check that this is the case with:
>>> import pybiopax
>>> model = pybiopax.model_from_owl_url('https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level2/1643685')
>>> len(model.objects)
0
You can also do a check that there are no INDRA statements parsed from the empty PyBioPAX model
>>> len(biopax_processor.statements)
0
You can see that content returned from Pathway Commons does have useful information, though:
>>> import pybiopax
>>> model = pybiopax.model_from_pc_query('pathsfromto', ['MAP2K1'], ['MAPK1'])
>>> len(model.objects)
13022
I would suggest moving questions about BioPAX processing over to the https://github.com/indralab/pybiopax (its maintainer, Ben Gyori, can likely write a better explanation on what's going on with the Reactome content) or to directly contact the Reactome team for support on their BioPAX content
from pybel.
After looking at the URL, you're using BioPAX level 2. Switch your URL to https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level3/1643685
and you get something looking much more useful.
I tried it myself and ran into an INDRA-related error with the processing of the resulting BioPAX content. I've posted the issue here: sorgerlab/indra#1184
from pybel.
@Rajeswara-Rao as of 8202006, it should now be possible to directly specify the file encoding from the PyBEL function pybel.from_biopax
with no need to use the wrapped INDRA or PyBioPAX functions. Your use case can now be more simply written as:
import os
from urllib.request import urlretrieve
from pybel_jupyter import to_jupyter
import pybel
apoptosis_url = 'https://reactome.org/ReactomeRESTfulAPI/RESTfulWS/biopaxExporter/Level3/1643685'
apoptosis_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'WP254_951071.owl')
if not os.path.exists(apoptosis_path):
urlretrieve(apoptosis_url, apoptosis_path)
graph = pybel.from_biopax(apoptosis_path, encoding='utf-8')
to_jupyter(graph)
Caveat This relies on an unmerged PR that's under review on INDRA with PyBEL v15 support, so please sit tight :) then you'll have to be on the development version of both repositories until their next releases
from pybel.
@cthoyt Thanks for the update!
from pybel.
Related Issues (20)
- pybel.tokens.parse_result_to_dsl doesn't capture 'concept' information
- Switch from Travis-CI to GitHub Actions
- Add postgres and mysql container tests to GitHub Actions
- pybel.to_indra_statements() fails on KEGG COVID pathway BEL script HOT 2
- Variable name typo
- collapse_nodes does not apply to members of ListAbundance HOT 3
- Update EMMAA downloader
- Named reactions
- Convert .Molecule or OBMol to SMILES HOT 1
- How to convert files in SMILES or MOL format to MOL2 3D structure HOT 1
- Add HTML summary for better jupyter notebook output
- Troubles with loading .json files created with pybel 14.0.8 HOT 4
- Challenge writing INDRA statements to nodelink and reading it back in to pybel HOT 2
- Problem getting a BEL graph from the Fraunhofer OrientDB HOT 2
- Cannot write the graph in any extension
- Unorganized data to_sif and No attribute 'to_triples_file
- attribute error for pybel HOT 1
- Getting problems with examples (pybel) HOT 1
- hetionet does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pybel.