Parse OBO formatted ontologies into networkx
Project description
obonet: load OBO-formatted ontologies into networkx
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/main/tests/data/taxrank.obo'
graph = obonet.read_obo(url)
# Or read the xz-compressed taxrank ontology
url = 'https://github.com/dhimmel/obonet/raw/main/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
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.
Develop
Some development commands:
# create virtual environment
python3 -m venv ./env
# activate virtual environment
source env/bin/activate
# editable installation for development
pip install --editable ".[dev]"
# install pre-commit hooks
pre-commit install
# run all pre-commit checks
pre-commit run --all
# run tests
pytest
# generate changelog for release notes
git fetch --tags origin main
OLD_TAG=$(git describe --tags --abbrev=0)
git log --oneline --decorate=no --reverse $OLD_TAG..HEAD
Maintainers can make a new release at https://github.com/dhimmel/obonet/releases/new.
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
Built Distribution
File details
Details for the file obonet-0.3.0.tar.gz
.
File metadata
- Download URL: obonet-0.3.0.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd801166cd28a2ef86126f22c8e3da30f5c3b6a3adfc62536abea1aa9956a2b4 |
|
MD5 | a12802f2408a610436795d5667da115b |
|
BLAKE2b-256 | 2efc97f0e16bec803df17d3d55fe2b117c9f2a9df166cc071a70c0704234b818 |
File details
Details for the file obonet-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: obonet-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d436eb4f57afa6f1a48992c3a4132126da9793e1439f667ab23cc74d8e957aee |
|
MD5 | e9723e4a64e76d748a2454c90f2b1b40 |
|
BLAKE2b-256 | 23cdb85ac3bbffd3cac33701a2a5b7dbdffdd2ab3d40f174dc3bf7a4ff8137cb |