aboutsummaryrefslogtreecommitdiff
path: root/bh20sequploader/qc_metadata.py
diff options
context:
space:
mode:
authorPeter Amstutz2020-04-20 12:50:03 -0400
committerPeter Amstutz2020-04-20 12:50:03 -0400
commit1219eaf496c899f3043b90e30eb956f0f363bfb3 (patch)
treea0735d5df88e608c5461d5b3cb9a3c6bb2f0f32e /bh20sequploader/qc_metadata.py
parenta2d19fa7b34170abab3759cdff14d8b052178a8a (diff)
downloadbh20-seq-resource-1219eaf496c899f3043b90e30eb956f0f363bfb3.tar.gz
bh20-seq-resource-1219eaf496c899f3043b90e30eb956f0f363bfb3.tar.lz
bh20-seq-resource-1219eaf496c899f3043b90e30eb956f0f363bfb3.zip
Add ShEx validation
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>
Diffstat (limited to 'bh20sequploader/qc_metadata.py')
-rw-r--r--bh20sequploader/qc_metadata.py13
1 files changed, 12 insertions, 1 deletions
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)