Skip to main content

Parse OBO formatted ontologies into networkx

Project description

obonet: load OBO-formatted ontologies into networkx

Build Status

Read OBO-formatted ontologies in Python. obonet is

  • user friendly
  • no nonsense
  • pythonic
  • modern
  • simple and tested
  • lightweight
  • networkx leveraging

This Python 3.4+ package loads OBO serialized ontologies into networks. The function obonet.read_obo() takes an .obo file and returns a networkx.MultiDiGraph representation of the ontology. The parser was designed for the OBO specification version 1.2 & 1.4.


This package is designed and tested on python ≥ 3.4. OBO files can be read from a path, URL, or open file handle. Compression is inferred from the path's extension. See example usage below:

import networkx
import obonet

# Read the taxrank ontology
url = ''
graph = obonet.read_obo(url)

# Or read the xz-compressed taxrank ontology
url = ''
graph = obonet.read_obo(url)

# Number of nodes

# Number of edges

# Check if the ontology is a DAG

# Mapping from term ID to name
id_to_name = {id_: data.get('name') for id_, data in graph.nodes(data=True)}
id_to_name['TAXRANK:0000006']  # TAXRANK:0000006 is species

# Find all superterms of species. Note that networkx.descendants gets
# superterms, while networkx.ancestors returns subterms.
networkx.descendants(graph, 'TAXRANK:0000006')

For a more detailed tutorial, see the Gene Ontology example notebook.



The recommended approach is to install the latest release from PyPI using:

pip install obonet

However, if you'd like to install the most recent version from GitHub, use:

pip install git+


GitHub issues

We welcome feature suggestions and community contributions. Currently, only reading OBO files is supported. Please open an issue if you're interested in writing OBO files in Python.

Release instructions

This section is only relevant for project maintainers. Travis CI deployments are used to upload releases to PyPI. To create a new release, do the following:

  1. Bump the __version__ in obonet/

  2. Run the following commands:

TAG=v`python --version`
git add obonet/
git commit --message="Upgrade to $TAG"
git push
git tag --annotate $TAG --message="Upgrade to $TAG"
git push --tags

Project details

Download files

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

Files for obonet, version 0.2.5
Filename, size File type Python version Upload date Hashes
Filename, size obonet-0.2.5.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page