Skip to main content

Validation tools for Reasoner API

Reason this release was yanked:

Superseded by 3.1.5

Project description

Reasoner Validator

Pyversions pypi License: MIT readthedocs

This package provides software methods to Translator components (e.g. Knowledge Providers and Autonomous Relay Agents) using any version of the Translator Reasoner API (TRAPI) and the Biolink Model.

See the full documentation and the contributor guidelines.

Using the Package

Installing the Module

pip install reasoner-validator

Installing the Module Locally from Source

git clone https://github.com/NCATSTranslator/reasoner-validator.git
cd reasoner-validator
pip install -e .

Building the Documentation Locally

To build the documentation locally:

cd docs
make html

Validation Run as a Web Service

The Reasoner Validator is available wrapped as a simple web service. The service may be run directly or as a Docker container.

API

The web service has a single POST endpoint /validate taking a simple JSON request body, as follows:

{
  "trapi_version": "1.3.0",
  "biolink_version": "3.0.5",
  "sources": {
    "ara_source": "infores:aragorn",
    "kp_source": "infores:panther",
    "kp_source_type": "primary"
  },
  "strict_validation": true,
  "message": {...}
}

The request body consists of JSON data structure with two top level tag:

  • An optional trapi_version tag can be given a value of the TRAPI version against which the message will be validated, expressed as a SemVer string (defaults to 'latest' if omitted; partial SemVer strings are resolved to their 'latest' minor and patch releases).
  • An optional biolink_version tag can be given a value of the Biolink Model version against which the message knowledge graph semantic contents will be validated, expressed as a SemVer string (defaults to 'latest' Biolink Model Toolkit supported version, if omitted).
  • An optional sources with an object dictionary (example shown) specifying the ARA and KP sources involved in the TRAPI call (specified by infores CURIE) and the expected KP provenance source type, i.e. 'primary' implies that the KP is tagged as a 'biolink:primary_knowledge_source'. Optional in that the root "sources" or any of the subsidiary tags may be omitted (default to None)
  • An optional strict_validation flag (default: None or 'false'). If 'true' then follow strict validation rules, such as treating as 'error' states the use of category, predicate and attribute_type_id that are of type abstract or mixin as errors.
  • A mandatory message tag should have as its value the complete TRAPI Message JSON data structure to be validated (see example below).

Running the Web Service Directly

The service may be run directly as a python module. It is suggested that a virtual environment first be created (using virtualenv, conda, within your IDE, or equivalent). Then, certain Python dependencies need to be installed, as follows:

pip install -r requirements-service.txt

The module may afterwards be run, as follows:

python -m api.main

Go to http://localhost/docs to see the service documentation and to use the simple UI to input TRAPI messages for validation.

Typical Output

As an example of the kind of output to expect, if one posts the following JSON message data to the /validate endpoint:

{
  "trapi_version": "1.3.0",
  "biolink_version": "2.4.8",
  "message": {
    "query_graph": {
        "nodes": {
            "type-2 diabetes": {"ids": ["MONDO:0005148"]},
            "drug": {"categories": ["biolink:Drug"]}
        },
        "edges": {
            "treats": {"subject": "drug", "predicates": ["biolink:treats"], "object": "type-2 diabetes"}
        }
    },
    "knowledge_graph": {
        "nodes": {
            "MONDO:0005148": {"name": "type-2 diabetes"},
            "CHEBI:6801": {"name": "metformin", "categories": ["biolink:Drug"]}
        },
        "edges": {
            "df87ff82": {"subject": "CHEBI:6801", "predicate": "biolink:treats", "object": "MONDO:0005148"}
        }
    },
    "results": [
        {
            "node_bindings": {
                "type-2 diabetes": [{"id": "MONDO:0005148"}],
                "drug": [{"id": "CHEBI:6801"}]
            },
            "edge_bindings": {
                "treats": [{"id": "df87ff82"}]
            }
        }
    ]
  }
}

one should typically get a response body like the following JSON validation result back:

{
  "trapi_version": "1.3.0",
  "biolink_version": "2.4.8",
  "report": [
    {
      "code": "warning.node.unmapped_prefix",
      "node_id": "CHEBI:6801",
      "categories": "['biolink:Drug']"
    },
    {
      "code": "error.node.missing_categories",
      "node_id": "MONDO:0005148"
    },
    {
      "code": "error.edge.attribute.missing"
    }
  ]
}

Running the Web Service within Docker

The Reasoner Validator web service may be run inside a docker container, using Docker Compose.

First, from the root project directory, build the local docker container

docker-compose build

Then, run the service:

docker-compose up -d

Once again, go to http://localhost/docs to see the service documentation.

To stop the service:

docker-compose down

Of course, the above docker-compose commands may be customized by the user to suit their needs. Note that the docker implementation assumes the use of uvicorn

Summary of Releases

The Reasoner Validator package is evolving along with progress in TRAPI and Biolink standards within the NCATS Biomedical Knowledge Translator.

  • 1.* releases - very preliminary releases of the validation code, now obsolete
  • 2.* releases - had a base TRAPI schema 'validate' with errors throwing a Python exception; later minor iterations added in Biolink Model validation returning a flat dictionary of arcane string messages
  • 3.* releases - wrapped the all validation with a ValidatorReporter class serving to collect and return validation messages in a disciplined, codified manner (as a master YAML file with hierarchically-indexed Python string templates)

Code Limitations (implied Future Work?)

  • This release of the Reasoner Validator Web Service will detect TRAPI 1.0.* releases but doesn't strive to be completely backwards compatible with them (considering that they are less relevant now).
  • The web service validation doesn't do deep validation of the Results part of a TRAPI Message
  • The validation is only run on the first 1000 nodes and 100 edges of graphs, to keep the validation time tractable (this risks not having complete coverage of the graph)
  • Biolink Model toolkit is not (yet) cached so changing the model version during use will result in some latency in results
  • The validator service doesn't (yet) deeply validate non-core node and edge slot contents of Message Knowledge Graphs
  • The validator service doesn't (yet) attempt validation of Query Graph nodes and edges 'constraints' (e.g. biolink:Association etc. domain and range constraints)
  • Query Graph node 'ids' are not validated except when an associated 'categories' parameter is provided for the given node. In general, Query Graph Validation could be elaborated.
  • The system should leverage the Reasoner Pydantic Models

Core Contributors

  • Kudos to Patrick Wang, who created the original implementation of the Reasoner-Validator project while with CoVar (an entrepreneurial team contributing to the Biomedical Data Translator).
  • Thanks to Kenneth Morton (CoVar) for his reviews of the latest code.
  • The project is currently being extended and maintained by Richard Bruskiewich (Delphinai Corporation, on the SRI team contributing to Translator)

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

reasoner-validator-3.1.2.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

reasoner_validator-3.1.2-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file reasoner-validator-3.1.2.tar.gz.

File metadata

  • Download URL: reasoner-validator-3.1.2.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for reasoner-validator-3.1.2.tar.gz
Algorithm Hash digest
SHA256 fee802d578d094dab629ea422f8cb977dd669dbafb72c2c504914804b4592acf
MD5 54f1421622489f81364d59a2dc07bf4a
BLAKE2b-256 c504a0eb9ce84d439e08ab55858c5e7a595ee0ff45ca56503ca987ac582f35d8

See more details on using hashes here.

File details

Details for the file reasoner_validator-3.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for reasoner_validator-3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8621d4f3b7c9a3f35b98f15f1a18b37fb6b295233d6dac85af0aeb7503b559a
MD5 a1374da8ad3d481343ddb6e8f9f15657
BLAKE2b-256 5122ece4c49c5db60d6d6d140e090cb1d7100a0007cb00a7c5127823a78d8005

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