| Name | kgx JSON |
| Version |
2.4.2
JSON |
| download |
| home_page | None |
| Summary | A Python library and set of command line utilities for exchanging Knowledge Graphs (KGs) that conform to or are aligned to the Biolink Model. |
| upload_time | 2024-07-24 20:16:05 |
| maintainer | None |
| docs_url | None |
| author | Deepak Unni |
| requires_python | <4.0,>=3.9 |
| license | BSD |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Knowledge Graph Exchange
[]()
[](https://kgx.readthedocs.io/en/latest/?badge=latest)
[](https://sonarcloud.io/dashboard?id=biolink_kgx)
[](https://sonarcloud.io/dashboard?id=biolink_kgx)
[](https://sonarcloud.io/dashboard?id=biolink_kgx)
[](https://img.shields.io/pypi/v/kgx)
[](https://hub.docker.com/r/biolink/kgx)
KGX (Knowledge Graph Exchange) is a Python library and set of command line utilities for exchanging
Knowledge Graphs (KGs) that conform to or are aligned to the [Biolink Model](https://biolink.github.io/biolink-model/).
The core datamodel is a [Property Graph](https://neo4j.com/developer/graph-database/) (PG), represented
internally in Python using a [networkx MultiDiGraph model](https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.MultiDiGraph.edges.html).
KGX allows conversion to and from:
* RDF serializations (read/write) and SPARQL endpoints (read)
* Neo4j endpoints (read) or Neo4j dumps (write)
* CSV/TSV and JSON (see [associated data formats](./data-preparation.md) and [example script to load CSV/TSV to Neo4j](./examples/scripts/load_csv_to_neo4j.py))
* Reasoner Standard API format
* OBOGraph JSON format
KGX will also provide validation, to ensure the KGs are conformant to the Biolink Model: making sure nodes are
categorized using Biolink classes, edges are labeled using valid Biolink relationship types, and valid properties are used.
Internal representation is a property graph, specifically a networkx MultiDiGraph.
The structure of this graph is expected to conform to the Biolink Model standard, as specified in the [KGX format specification](specification/kgx-format.md).
In addition to the main code-base, KGX also provides a series of [command line operations](https://kgx.readthedocs.io/en/latest/examples.html#using-kgx-cli).
### Example usage
Validate:
```bash
poetry run kgx validate -i tsv tests/resources/merge/test2_nodes.tsv tests/resources/merge/test2_edges.tsv
```
Merge:
```bash
poetry run kgx merge —merge-config tests/resources/test-merge.yaml
```
Graph Summary:
```bash
poetry run kgx graph-summary -i tests/resources/graph_nodes.tsv -o summary.txt
```
Transform:
```bash
poetry run kgx transform —transform-config tests/resources/test-transform-tsv-rdf.yaml
```
### Error Detection and Reporting
Non-redundant JSON-formatted structured error logging is now provided in KGX Transformer, Validator, GraphSummary and MetaKnowledgeGraph operations. See the various unit tests for the general design pattern (using the Validator as an example here):
```python
from kgx.validator import Validator
from kgx.transformer import Transformer
Validator.set_biolink_model("2.11.0")
# Validator assumes the currently set Biolink Release
validator = Validator()
transformer = Transformer(stream=True)
transformer.transform(
input_args = {
"filename": [
"graph_nodes.tsv",
"graph_edges.tsv",
],
"format": "tsv",
},
output_args={
"format": "null"
},
inspector=validator,
)
# Both the Validator and the Transformer can independently capture errors
# The Validator, from the overall semantics of the graph...
# Here, we just report severe Errors from the Validator (no Warnings)
validator.write_report(open("validation_errors.json", "w"), "Error")
# The Transformer, from the syntax of the input files...
# Here, we catch *all* Errors and Warnings (by not providing a filter)
transformer.write_report(open("input_errors.json", "w"))
```
The JSON error outputs will look something like this:
```json
{
"ERROR": {
"MISSING_EDGE_PROPERTY": {
"Required edge property 'id' is missing": [
"A:123->X:1",
"B:456->Y:2"
],
"Required edge property 'object' is missing": [
"A:123->X:1"
],
"Required edge property 'predicate' is missing": [
"A:123->X:1"
],
"Required edge property 'subject' is missing": [
"A:123->X:1",
"B:456->Y:2"
]
}
},
"WARNING": {
"DUPLICATE_NODE": {
"Node 'id' duplicated in input data": [
"MONDO:0010011",
"REACT:R-HSA-5635838"
]
}
}
}
```
This system reduces the significant redundancies of earlier line-oriented KGX logging text output files, in that graph entities with the same class of error are simply aggregated in lists of names/identifiers at the leaf level of the JSON structure.
The top level JSON tags originate from the `MessageLevel` class and the second level tags from the `ErrorType` class in the [error_detection](kgx/error_detection.py) module, while the third level messages are hard coded as `log_error` method messages in the code.
It is likely that additional error conditions within KGX can be efficiently captured and reported in the future using this general framework.
## Installation
#### Installing from PyPI
KGX is available on PyPI and can be installed using
[pip](https://pip.pypa.io/en/stable/installing/) as follows,
```bash
pip install kgx
```
To install a particular version of KGX, be sure to specify the version number,
```bash
pip install kgx==0.5.0
```
#### Installing from GitHub
Clone the GitHub repository and then install,
```bash
git clone https://github.com/biolink/kgx
cd kgx
poetry install
```
### Setting up a testing environment for Neo4j
This release of KGX supports graph source and sink transactions with the 4.3 release of Neo4j.
KGX has a suite of tests that rely on Docker containers to run Neo4j specific tests.
To set up the required containers, first install [Docker](https://docs.docker.com/get-docker/)
on your local machine.
Once Docker is up and running, run the following commands:
```bash
docker run -d --rm --name kgx-neo4j-integration-test -p 7474:7474 -p 7687:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.3
```
```bash
docker run -d --rm --name kgx-neo4j-unit-test -p 8484:7474 -p 8888:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.3
```
**Note:** Setting up the Neo4j container is optional. If there is no container set up
then the tests that rely on them are skipped.
Raw data
{
"_id": null,
"home_page": null,
"name": "kgx",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Deepak Unni",
"author_email": "deepak.unni3@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8b/15/950cb6ea60ca30f48877a215b707a0a41e7ef1d62d817b495e4eeb2c7dd6/kgx-2.4.2.tar.gz",
"platform": null,
"description": "# Knowledge Graph Exchange\n\n\n[]()\n[](https://kgx.readthedocs.io/en/latest/?badge=latest)\n[](https://sonarcloud.io/dashboard?id=biolink_kgx)\n[](https://sonarcloud.io/dashboard?id=biolink_kgx)\n[](https://sonarcloud.io/dashboard?id=biolink_kgx)\n[](https://img.shields.io/pypi/v/kgx)\n[](https://hub.docker.com/r/biolink/kgx)\n\nKGX (Knowledge Graph Exchange) is a Python library and set of command line utilities for exchanging\nKnowledge Graphs (KGs) that conform to or are aligned to the [Biolink Model](https://biolink.github.io/biolink-model/).\n\nThe core datamodel is a [Property Graph](https://neo4j.com/developer/graph-database/) (PG), represented\ninternally in Python using a [networkx MultiDiGraph model](https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.MultiDiGraph.edges.html).\n\nKGX allows conversion to and from:\n\n * RDF serializations (read/write) and SPARQL endpoints (read)\n * Neo4j endpoints (read) or Neo4j dumps (write)\n * CSV/TSV and JSON (see [associated data formats](./data-preparation.md) and [example script to load CSV/TSV to Neo4j](./examples/scripts/load_csv_to_neo4j.py))\n * Reasoner Standard API format\n * OBOGraph JSON format\n\nKGX will also provide validation, to ensure the KGs are conformant to the Biolink Model: making sure nodes are\ncategorized using Biolink classes, edges are labeled using valid Biolink relationship types, and valid properties are used.\n\nInternal representation is a property graph, specifically a networkx MultiDiGraph.\n\nThe structure of this graph is expected to conform to the Biolink Model standard, as specified in the [KGX format specification](specification/kgx-format.md).\n\nIn addition to the main code-base, KGX also provides a series of [command line operations](https://kgx.readthedocs.io/en/latest/examples.html#using-kgx-cli).\n\n### Example usage\nValidate:\n```bash\npoetry run kgx validate -i tsv tests/resources/merge/test2_nodes.tsv tests/resources/merge/test2_edges.tsv\n```\n\nMerge:\n```bash\npoetry run kgx merge \u2014merge-config tests/resources/test-merge.yaml \n```\n\nGraph Summary:\n```bash\npoetry run kgx graph-summary -i tests/resources/graph_nodes.tsv -o summary.txt\n```\n\nTransform:\n```bash\npoetry run kgx transform \u2014transform-config tests/resources/test-transform-tsv-rdf.yaml\n```\n\n### Error Detection and Reporting\n\nNon-redundant JSON-formatted structured error logging is now provided in KGX Transformer, Validator, GraphSummary and MetaKnowledgeGraph operations. See the various unit tests for the general design pattern (using the Validator as an example here):\n\n```python\nfrom kgx.validator import Validator\nfrom kgx.transformer import Transformer\n\nValidator.set_biolink_model(\"2.11.0\")\n\n# Validator assumes the currently set Biolink Release\nvalidator = Validator()\n\ntransformer = Transformer(stream=True)\n\ntransformer.transform(\n input_args = {\n \"filename\": [\n \"graph_nodes.tsv\",\n \"graph_edges.tsv\",\n ],\n \"format\": \"tsv\",\n },\n output_args={\n \"format\": \"null\"\n },\n inspector=validator,\n)\n\n# Both the Validator and the Transformer can independently capture errors\n\n# The Validator, from the overall semantics of the graph...\n# Here, we just report severe Errors from the Validator (no Warnings)\nvalidator.write_report(open(\"validation_errors.json\", \"w\"), \"Error\")\n\n# The Transformer, from the syntax of the input files... \n# Here, we catch *all* Errors and Warnings (by not providing a filter)\ntransformer.write_report(open(\"input_errors.json\", \"w\"))\n```\n\nThe JSON error outputs will look something like this:\n\n```json\n{\n \"ERROR\": {\n \"MISSING_EDGE_PROPERTY\": {\n \"Required edge property 'id' is missing\": [\n \"A:123->X:1\",\n \"B:456->Y:2\"\n ],\n \"Required edge property 'object' is missing\": [\n \"A:123->X:1\"\n ],\n \"Required edge property 'predicate' is missing\": [\n \"A:123->X:1\"\n ],\n \"Required edge property 'subject' is missing\": [\n \"A:123->X:1\",\n \"B:456->Y:2\"\n ]\n }\n },\n \"WARNING\": {\n \"DUPLICATE_NODE\": {\n \"Node 'id' duplicated in input data\": [\n \"MONDO:0010011\",\n \"REACT:R-HSA-5635838\"\n ]\n }\n }\n}\n\n```\n\nThis system reduces the significant redundancies of earlier line-oriented KGX logging text output files, in that graph entities with the same class of error are simply aggregated in lists of names/identifiers at the leaf level of the JSON structure.\n\nThe top level JSON tags originate from the `MessageLevel` class and the second level tags from the `ErrorType` class in the [error_detection](kgx/error_detection.py) module, while the third level messages are hard coded as `log_error` method messages in the code. \n\nIt is likely that additional error conditions within KGX can be efficiently captured and reported in the future using this general framework.\n\n## Installation\n\n#### Installing from PyPI\n\nKGX is available on PyPI and can be installed using\n[pip](https://pip.pypa.io/en/stable/installing/) as follows,\n\n```bash\npip install kgx\n```\n\nTo install a particular version of KGX, be sure to specify the version number,\n\n```bash\npip install kgx==0.5.0\n```\n\n#### Installing from GitHub\n\nClone the GitHub repository and then install,\n\n```bash\ngit clone https://github.com/biolink/kgx\ncd kgx\npoetry install\n```\n\n### Setting up a testing environment for Neo4j\n\nThis release of KGX supports graph source and sink transactions with the 4.3 release of Neo4j.\n\nKGX has a suite of tests that rely on Docker containers to run Neo4j specific tests.\n\nTo set up the required containers, first install [Docker](https://docs.docker.com/get-docker/)\non your local machine.\n\nOnce Docker is up and running, run the following commands:\n\n```bash\ndocker run -d --rm --name kgx-neo4j-integration-test -p 7474:7474 -p 7687:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.3\n```\n\n```bash\ndocker run -d --rm --name kgx-neo4j-unit-test -p 8484:7474 -p 8888:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.3\n```\n\n**Note:** Setting up the Neo4j container is optional. If there is no container set up\nthen the tests that rely on them are skipped.\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "A Python library and set of command line utilities for exchanging Knowledge Graphs (KGs) that conform to or are aligned to the Biolink Model.",
"version": "2.4.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0ee7f00466df89ffc08f1883307f5fab2a9fd4dcb042c799400d347d3225ab67",
"md5": "09fb618a67e0d704348f235a36833e25",
"sha256": "87875d9a6f5d595ed84c99516abd6a6edf5b8d1f9a2dee493ed4e2d7d2a1e3fd"
},
"downloads": -1,
"filename": "kgx-2.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "09fb618a67e0d704348f235a36833e25",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 119021,
"upload_time": "2024-07-24T20:16:04",
"upload_time_iso_8601": "2024-07-24T20:16:04.335436Z",
"url": "https://files.pythonhosted.org/packages/0e/e7/f00466df89ffc08f1883307f5fab2a9fd4dcb042c799400d347d3225ab67/kgx-2.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8b15950cb6ea60ca30f48877a215b707a0a41e7ef1d62d817b495e4eeb2c7dd6",
"md5": "e86a5b1354b0b191673fd97f0aa9a527",
"sha256": "16279cc8a772655a60ad0e98a2c6ee4b9670f30271fd492c1a508f735d8d02b4"
},
"downloads": -1,
"filename": "kgx-2.4.2.tar.gz",
"has_sig": false,
"md5_digest": "e86a5b1354b0b191673fd97f0aa9a527",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 95596,
"upload_time": "2024-07-24T20:16:05",
"upload_time_iso_8601": "2024-07-24T20:16:05.961755Z",
"url": "https://files.pythonhosted.org/packages/8b/15/950cb6ea60ca30f48877a215b707a0a41e7ef1d62d817b495e4eeb2c7dd6/kgx-2.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-24 20:16:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "kgx"
}