Skip to main content

Parsing, validation, compilation, and data exchange of Biological Expression Language (BEL)

Project description

PyBEL is a pure Python package for parsing and handling biological networks encoded in the Biological Expression Language (BEL).

It facilitates data interchange between data formats like NetworkX, Node-Link JSON, JGIF, CSV, SIF, Cytoscape, CX, INDRA, and GraphDati; database systems like SQL and Neo4J; and web services like NDEx, BioDati Studio, and BEL Commons. It also provides exports for analytical tools like HiPathia and SPIA; machine learning tools like PyKEEN and OpenBioLink; and others.

Its companion package, PyBEL Tools, contains a suite of functions and pipelines for analyzing the resulting biological networks.

We realize that we have a name conflict with the python wrapper for the cheminformatics package, OpenBabel. If you’re looking for their python wrapper, see here.

Citation

If you find PyBEL useful for your work, please consider citing:

Installation Current version on PyPI Stable Supported Python Versions MIT License

PyBEL can be installed easily from PyPI with the following code in your favorite shell:

$ pip install pybel

or from the latest code on GitHub with:

$ pip install git+https://github.com/pybel/pybel.git

See the installation documentation for more advanced instructions. Also, check the change log at CHANGELOG.rst.

Note: while PyBEL works on the most recent versions of Python 3.5, it does not work on 3.5.3 or below due to changes in the typing module.

Getting Started

More examples can be found in the documentation and in the PyBEL Notebooks repository.

Compiling and Saving a BEL Graph

This example illustrates how the a BEL document from the Human Brain Pharmacome project can be loaded from GitHub.

>>> import pybel
>>> url = 'https://raw.githubusercontent.com/pharmacome/knowledge/master/hbp_knowledge/proteostasis/kim2013.bel'
>>> graph = pybel.from_url(url)

PyBEL can handle BEL 1.0 and BEL 2.0+ simultaneously.

After you have a BEL graph, there are numerous ways to save it. The pybel.dump function knows how to output it in many formats based on the file extension you give. For all of the possibilities, check the I/O documentation.

>>> import pybel
>>> graph = ...
>>> # write as BEL
>>> pybel.dump(graph, 'my_graph.bel')
>>> # write as Node-Link JSON for network viewers like D3
>>> pybel.dump(graph, 'my_graph.bel.nodelink.json')
>>> # write as GraphDati JSON for BioDati
>>> pybel.dump(graph, 'my_graph.bel.graphdati.json')
>>> # write as CX JSON for NDEx
>>> pybel.dump(graph, 'my_graph.bel.cx.json')

Grounding the Graph

Not all BEL graphs contain both the name and identifier for each entity. Some even use non-standard prefixes (also called namespaces in BEL). Usually, BEL graphs are validated against controlled vocabularies, so the following demo shows how to add the corresponding identifiers to all nodes.

from urllib.request import urlretrieve

url = 'https://github.com/cthoyt/selventa-knowledge/blob/master/selventa_knowledge/large_corpus.bel.nodelink.json.gz'
urlretrieve(url, 'large_corpus.bel.nodelink.json.gz')

import pybel
graph = pybel.load('large_corpus.bel.nodelink.json.gz')

import pybel.grounding
pybel.grounding.ground(graph)

Note: you have to install pyobo for this to work and be running Python 3.7+.

Displaying a BEL Graph in Jupyter

After installing jinja2 and ipython, BEL graphs can be displayed in Jupyter notebooks.

>>> from pybel.examples import sialic_acid_graph
>>> from pybel.io.jupyter import to_jupyter
>>> to_jupyter(sialic_acid_graph)

Using the CLI

PyBEL also installs a command line interface with the command pybel for simple utilities such as data conversion. In this example, a BEL document is compiled then exported to GraphML for viewing in Cytoscape.

$ pybel compile ~/Desktop/example.bel
$ pybel serialize ~/Desktop/example.bel --graphml ~/Desktop/example.graphml

In Cytoscape, open with Import > Network > From File.

Contributing

Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See CONTRIBUTING.rst for more information on getting involved.

Acknowledgements

Supporters

This project has been supported by several organizations:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybel-0.14.9.tar.gz (388.2 kB view details)

Uploaded Source

Built Distribution

pybel-0.14.9-py3-none-any.whl (345.9 kB view details)

Uploaded Python 3

File details

Details for the file pybel-0.14.9.tar.gz.

File metadata

  • Download URL: pybel-0.14.9.tar.gz
  • Upload date:
  • Size: 388.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for pybel-0.14.9.tar.gz
Algorithm Hash digest
SHA256 082a4480fd576d5287ffa84505eb80f5840daef84d9f764ace466eb0b49f3230
MD5 e6ffa7879a0fa7fa82f8a7b60730770d
BLAKE2b-256 78d6c8ce8e7937f138ea59e3c7bfaf3e7f7fe613beaa908dfa105c7576d9b387

See more details on using hashes here.

Provenance

File details

Details for the file pybel-0.14.9-py3-none-any.whl.

File metadata

  • Download URL: pybel-0.14.9-py3-none-any.whl
  • Upload date:
  • Size: 345.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for pybel-0.14.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d1ea8a5c9f26d65f3e3472dff732112b722e6149ed9d95a8119182a4973eb966
MD5 5424ffebac9d2225566e2e0afb5e05f5
BLAKE2b-256 670f1e84d1c37e1c5e09b465731d63029801c790a172bcd95202eb1da14a6c5c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page