{"id":17099036,"url":"https://github.com/dhimmel/obonet","last_synced_at":"2025-05-16T01:05:59.912Z","repository":{"id":32178359,"uuid":"35751761","full_name":"dhimmel/obonet","owner":"dhimmel","description":"OBO-formatted ontologies → networkx (Python 3)","archived":false,"fork":false,"pushed_at":"2025-03-26T01:50:44.000Z","size":101,"stargazers_count":139,"open_issues_count":1,"forks_count":29,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-12T15:04:44.328Z","etag":null,"topics":["network","networkx","obo","obo-files","obo-formatted-ontologies","ontology","parser","python","rephetio"],"latest_commit_sha":null,"homepage":"https://github.com/dhimmel/obonet/blob/main/examples/go-obonet.ipynb","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhimmel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-05-17T04:23:23.000Z","updated_at":"2025-05-12T05:57:01.000Z","dependencies_parsed_at":"2023-01-14T20:41:50.204Z","dependency_job_id":"48ca4aac-278e-49e5-9548-820db149aad2","html_url":"https://github.com/dhimmel/obonet","commit_stats":{"total_commits":113,"total_committers":6,"mean_commits":"18.833333333333332","dds":0.06194690265486724,"last_synced_commit":"e3c85dca81796c7248bca94f7a07b88fc316e257"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhimmel%2Fobonet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhimmel%2Fobonet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhimmel%2Fobonet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhimmel%2Fobonet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhimmel","download_url":"https://codeload.github.com/dhimmel/obonet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network","networkx","obo","obo-files","obo-formatted-ontologies","ontology","parser","python","rephetio"],"created_at":"2024-10-14T15:08:50.723Z","updated_at":"2025-05-16T01:05:54.878Z","avatar_url":"https://github.com/dhimmel.png","language":"Python","funding_links":[],"categories":["Ontology Utilities"],"sub_categories":[],"readme":"# obonet: load OBO-formatted ontologies into networkx\n\n[![GitHub Actions CI Build Status](https://img.shields.io/github/actions/workflow/status/dhimmel/obonet/build.yaml?branch=main\u0026label=actions\u0026style=for-the-badge\u0026logo=github\u0026logoColor=white)](https://github.com/dhimmel/obonet/actions)  \n[![Software License](https://img.shields.io/pypi/l/obonet?style=for-the-badge\u0026logo=FreeBSD\u0026logoColor=white)](https://github.com/dhimmel/obonet/blob/main/LICENSE)  \n[![PyPI](https://img.shields.io/pypi/v/obonet.svg?style=for-the-badge\u0026logo=PyPI\u0026logoColor=white)](https://pypi.org/project/obonet/)  \n\n\nRead OBO-formatted ontologies in Python.\n`obonet` is\n\n+ user friendly\n+ succinct\n+ pythonic\n+ modern\n+ simple and tested\n+ lightweight\n+ [`networkx`](https://networkx.readthedocs.io/en/stable/overview.html) leveraging\n\nThis Python package loads OBO serialized ontologies into networks.\nThe function `obonet.read_obo()` takes an `.obo` file and returns a [`networkx.MultiDiGraph`](https://networkx.github.io/documentation/stable/reference/classes/multigraph.html) representation of the ontology.\nThe parser was designed for the OBO specification version [1.2](https://owlcollab.github.io/oboformat/doc/GO.format.obo-1_2.html) \u0026 [1.4](https://owlcollab.github.io/oboformat/doc/GO.format.obo-1_4.html).\n\n## Usage\n\nSee [`pyproject.toml`](pyproject.toml) for the minimum Python version required and the dependencies.\nOBO files can be read from a path, URL, or open file handle.\nCompression is inferred from the path's extension.\nSee example usage below:\n\n```python\nimport networkx\nimport obonet\n\n# Read the taxrank ontology\nurl = 'https://github.com/dhimmel/obonet/raw/main/tests/data/taxrank.obo'\ngraph = obonet.read_obo(url)\n\n# Or read the xz-compressed taxrank ontology\nurl = 'https://github.com/dhimmel/obonet/raw/main/tests/data/taxrank.obo.xz'\ngraph = obonet.read_obo(url)\n\n# Number of nodes\nlen(graph)\n\n# Number of edges\ngraph.number_of_edges()\n\n# Check if the ontology is a DAG\nnetworkx.is_directed_acyclic_graph(graph)\n\n# Mapping from term ID to name\nid_to_name = {id_: data.get('name') for id_, data in graph.nodes(data=True)}\nid_to_name['TAXRANK:0000006']  # TAXRANK:0000006 is species\n\n# Find all superterms of species. Note that networkx.descendants gets\n# superterms, while networkx.ancestors returns subterms.\nnetworkx.descendants(graph, 'TAXRANK:0000006')\n```\n\nFor a more detailed tutorial, see the [**Gene Ontology example notebook**](https://github.com/dhimmel/obonet/blob/main/examples/go-obonet.ipynb).\n\n## Comparison\n\nThis package specializes in reading OBO files into a `newtorkx.MultiDiGraph`.\nA more general ontology-to-NetworkX reader is available in the Python [nxontology package](https://github.com/related-sciences/nxontology) via the `nxontology.imports.pronto_to_multidigraph` function.\nThis function takes a `pronto.Ontology` object,\nwhich can be loaded from an OBO file, OBO Graphs JSON file, or Ontology Web Language 2 RDF/XML file (OWL).\nUsing `pronto_to_multidigraph` allows creating a MultiDiGraph similar to the created by `obonet`,\nwith some differences in the amount of metadata retained.\n\nThe primary focus of the `nxontology` package is to provide an `NXOntology` class for representing ontologies based around a `networkx.DiGraph`.\nNXOntology provides optimized implementations for computing node similarity and other intrinsic ontology metrics.\nThere are two important differences between a DiGraph for NXOntology and the MultiDiGraph produced by obonet:\n\n1. NXOntology is based on a DiGraph that does not allow multiple edges between the same two nodes.\n   Multiple edges between the same two nodes must therefore be collapsed.\n   By default, it only considers _is a_ / `rdfs:subClassOf` relationships,\n   but using `pronto_to_multidigraph` to create the NXOntology allows for retaining additional relationship types, like _part of_ in the case of the Gene Ontology.\n\n2. NXOntology reverses the direction of relationships so edges go from superterm to subterm.\n   Traditionally in ontologies, the _is a_ relationships go from subterm to superterm,\n   but this is confusing.\n   NXOntology reverses edges so functions such as _ancestors_ refer to more general concepts and _descendants_ refer to more specific concepts.\n\nThe `nxontology.imports.multidigraph_to_digraph` function converts from a MultiDiGraph, like the one produced by obonet, to a DiGraph by filtering to the desired relationship types, reversing edges, and collapsing parallel edges.\n\n## Installation\n\nThe recommended approach is to install the latest release from [PyPI](https://pypi.org/project/obonet/) using:\n\n```sh\npip install obonet\n```\n\nHowever, if you'd like to install the most recent version from GitHub, use:\n\n```sh\npip install git+https://github.com/dhimmel/obonet.git#egg=obonet\n```\n\n## Contributing\n\n[![GitHub issues](https://img.shields.io/github/issues/dhimmel/obonet.svg?style=for-the-badge)](https://github.com/dhimmel/obonet/issues)\n\nWe welcome feature suggestions and community contributions.\nCurrently, only reading OBO files is supported.\n\n## Develop\n\nSome development commands:\n\n```bash\n# create virtual environment\npython3 -m venv ./env\n\n# activate virtual environment\nsource env/bin/activate\n\n# editable installation for development\npip install --editable \".[dev]\"\n\n# install pre-commit hooks\npre-commit install\n\n# run all pre-commit checks\npre-commit run --all\n\n# run tests\npytest\n\n# generate changelog for release notes\ngit fetch --tags origin main\nOLD_TAG=$(git describe --tags --abbrev=0)\ngit log --oneline --decorate=no --reverse $OLD_TAG..HEAD\n```\n\nMaintainers can make a new release at \u003chttps://github.com/dhimmel/obonet/releases/new\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhimmel%2Fobonet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhimmel%2Fobonet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhimmel%2Fobonet/lists"}