From 1219eaf496c899f3043b90e30eb956f0f363bfb3 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 12:50:03 -0400 Subject: Add ShEx validation Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/qc_metadata.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'bh20sequploader/qc_metadata.py') diff --git a/bh20sequploader/qc_metadata.py b/bh20sequploader/qc_metadata.py index e477f21..fbfd286 100644 --- a/bh20sequploader/qc_metadata.py +++ b/bh20sequploader/qc_metadata.py @@ -1,9 +1,12 @@ import schema_salad.schema import schema_salad.ref_resolver +import schema_salad.jsonld_context import logging import pkg_resources import logging import traceback +from rdflib import Graph, Namespace +from pyshex.evaluate import evaluate def qc_metadata(metadatafile): schema_resource = pkg_resources.resource_stream(__name__, "bh20seq-schema.yml") @@ -13,13 +16,21 @@ def qc_metadata(metadatafile): schema_metadata, metaschema_loader) = schema_salad.schema.load_schema("https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml", cache=cache) + shex = pkg_resources.resource_stream(__name__, "bh20seq-shex.rdf").read().decode("utf-8") + if not isinstance(avsc_names, schema_salad.avro.schema.Names): print(avsc_names) return False try: doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, True) - return True + g = schema_salad.jsonld_context.makerdf("workflow", doc, document_loader.ctx) + rslt, reason = evaluate(g, shex, doc["id"], "https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-shex.rdf#submissionShape") + + if not rslt: + print(reason) + + return rslt except Exception as e: traceback.print_exc() logging.warn(e) -- cgit v1.2.3