Metadata-Version: 2.0
Name: obonet
Version: 0.2.0
Summary: Parse OBO formatted ontologies into networkx
Home-page: https://github.com/dhimmel/obonet
Author: Daniel Himmelstein
Author-email: daniel.himmelstein@gmail.com
License: CC0 1.0
Keywords: obo ontology networkx parser network
Platform: UNKNOWN
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Classifier: Programming Language :: Python :: 3
Requires-Dist: networkx

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 <https://owlcollab.github.io/oboformat/doc/GO.format.obo-1_2.html>`__
and
`1.4 <https://owlcollab.github.io/oboformat/doc/GO.format.obo-1_4.html>`__.

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:

.. code:: python

    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:

.. code:: sh

    pip install obonet

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

.. code:: sh

    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 <https://pypi.org/project/hetio>`__. 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``

.. |Build Status| image:: https://travis-ci.org/dhimmel/obonet.svg?branch=master
   :target: https://travis-ci.org/dhimmel/obonet


