Skip to main content

Parse OBO formatted ontologies into networkx

Project description

A python parser for OBO ontology files

Build Status

This repository contains a python package for handling OBO serialized ontologies. The function obonet.read_obo() takes an .obo file and returns a `networkx.MultiDiGraph <http://networkx.readthedocs.io/en/stable/reference/classes.multidigraph.html>`__ representation of the ontology.

The parser aims to be compatible with OBO versions 1.2 and 1.4.

Usage

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 = 'https://github.com/dhimmel/obo/raw/master/tests/data/taxrank.obo'
graph = obonet.read_obo(url)

# Or read the xz-compressed taxrank ontology
url = 'https://github.com/dhimmel/obo/raw/master/tests/data/taxrank.obo.xz'
graph = obonet.read_obo(url)

# Number of nodes
len(graph)

# Number of edges
graph.number_of_edges()

# Check if the ontology is a DAG
networkx.is_directed_acyclic_graph(graph)

# Mapping from term ID to name
id_to_name = {id_: data['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')

Installation

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+https://github.com/dhimmel/obonet.git#egg=obonet

Contributing

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/__init__.py <obonet/__init__.py>`__.

  2. Run the following commands:

sh TAG=v`python setup.py --version` git add obonet/__init__.py 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.

Source Distribution

obonet-0.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distributions

obonet-0.2.0-py3.6.egg (9.5 kB view details)

Uploaded Source

obonet-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file obonet-0.2.0.tar.gz.

File metadata

  • Download URL: obonet-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for obonet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8cbe2b1fa43b757def7ef0b864a9dcaf73fe73349076efefde541528378e2f97
MD5 216040bc64fe09d0fe7c53dd679606ac
BLAKE2b-256 2f38f94b60412292b43e4ec3a9866eb721d9032c25984d5d02c6caaed5ce2f93

See more details on using hashes here.

File details

Details for the file obonet-0.2.0-py3.6.egg.

File metadata

  • Download URL: obonet-0.2.0-py3.6.egg
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for obonet-0.2.0-py3.6.egg
Algorithm Hash digest
SHA256 145b740a90a76bf317efe4edbd4134430b0fad6b2a6d6d92d8861f82a311806b
MD5 86e6891f2084c1aab15225a9106a5b85
BLAKE2b-256 7cac79a0ff3d586b06f33b1068064ff89a2ecb3c1c9795f6b9df161ed77dd23e

See more details on using hashes here.

File details

Details for the file obonet-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for obonet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10f14dc123476e57b0ba37be8362f350ff6d631e76d6a7c4c8669e9a9a749298
MD5 727dd030f6dfebec52f6d198f33f5b83
BLAKE2b-256 d46c08fd1d74ca46aa78b70dec2a083e4165d5046f219f1a018f7a94319a8b0f

See more details on using hashes here.

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