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.

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

# Or read the xz-compressed taxrank ontology
url = 'https://github.com/dhimmel/obonet/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.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.

Installation

PyPI

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

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

  2. Run the following commands:

TAG=v`python setup.py --version`
git add obonet/__init__.py
git commit --message="Upgrade version to $TAG"
git push
git tag --annotate $TAG --message="Release $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.6.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

obonet-0.2.6-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: obonet-0.2.6.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3

File hashes

Hashes for obonet-0.2.6.tar.gz
Algorithm Hash digest
SHA256 61eaf2efd9694f1a6219418de113af2ffd9a197dd472eca6682bd9e03586e050
MD5 43bcf4b5144d879d751172920e311ac1
BLAKE2b-256 9d81013c807e305646d715bdfb286f8bea333a72bfd4da7c311df66598e7d918

See more details on using hashes here.

File details

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

File metadata

  • Download URL: obonet-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3

File hashes

Hashes for obonet-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0646dbb2b0e4ee3b952907bd99584d8f9ba4eb9643a0755daf3452066eab71fe
MD5 b1187590f3598571a0093648d265f53f
BLAKE2b-256 7ccebba09b7e94e5d15eb0755c72103f2057f4e6d2f4fcfd8e24bd88d1649373

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