diff options
Diffstat (limited to 'bh20sequploader/qc_metadata.py')
-rw-r--r-- | bh20sequploader/qc_metadata.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/bh20sequploader/qc_metadata.py b/bh20sequploader/qc_metadata.py index 2b57991..27657b1 100644 --- a/bh20sequploader/qc_metadata.py +++ b/bh20sequploader/qc_metadata.py @@ -8,15 +8,20 @@ import traceback from rdflib import Graph, Namespace from pyshex.evaluate import evaluate +metadata_schema = None def qc_metadata(metadatafile): + global metadata_schema log = logging.getLogger(__name__ ) - schema_resource = pkg_resources.resource_stream(__name__, "bh20seq-schema.yml") - cache = {"https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml": schema_resource.read().decode("utf-8")} + if metadata_schema is None: + schema_resource = pkg_resources.resource_stream(__name__, "bh20seq-schema.yml") + cache = {"https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml": schema_resource.read().decode("utf-8")} + metadata_schema = schema_salad.schema.load_schema("https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml", cache=cache) + (document_loader, avsc_names, schema_metadata, - metaschema_loader) = schema_salad.schema.load_schema("https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml", cache=cache) + metaschema_loader) = metadata_schema shex = pkg_resources.resource_stream(__name__, "bh20seq-shex.rdf").read().decode("utf-8") @@ -27,6 +32,10 @@ def qc_metadata(metadatafile): 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") + # As part of QC make sure serialization works too, this will raise + # an exception if there are invalid URIs. + g.serialize(format="ntriples") + if not rslt: raise Exception(reason) |