aboutsummaryrefslogtreecommitdiff
path: root/bh20sequploader
diff options
context:
space:
mode:
Diffstat (limited to 'bh20sequploader')
-rw-r--r--bh20sequploader/bh20seq-shex.rdf (renamed from bh20sequploader/validation_shape.rdf)2
-rw-r--r--bh20sequploader/main.py11
-rw-r--r--bh20sequploader/qc_metadata.py13
3 files changed, 23 insertions, 3 deletions
diff --git a/bh20sequploader/validation_shape.rdf b/bh20sequploader/bh20seq-shex.rdf
index dd34fa9..8d3f5fc 100644
--- a/bh20sequploader/validation_shape.rdf
+++ b/bh20sequploader/bh20seq-shex.rdf
@@ -1,4 +1,4 @@
-PREFIX : <http://whatever/>
+PREFIX : <https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-shex.rdf#>
PREFIX MainSchema: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
PREFIX hostSchema: <http://biohackathon.org/bh20-seq-schema#hostSchema/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py
index e0a6a9a..49d012d 100644
--- a/bh20sequploader/main.py
+++ b/bh20sequploader/main.py
@@ -21,16 +21,25 @@ def main():
parser = argparse.ArgumentParser(description='Upload SARS-CoV-19 sequences for analysis')
parser.add_argument('sequence', type=argparse.FileType('r'), help='sequence FASTA/FASTQ')
parser.add_argument('metadata', type=argparse.FileType('r'), help='sequence metadata json')
+ parser.add_argument("--validate", action="store_true", help="Dry run, validate only")
args = parser.parse_args()
api = arvados.api(host=ARVADOS_API_HOST, token=ARVADOS_API_TOKEN, insecure=True)
- target = qc_fasta(args.sequence)
+ try:
+ target = qc_fasta(args.sequence)
+ except ValueError as e:
+ print(e)
+ exit(1)
if not qc_metadata(args.metadata.name):
print("Failed metadata qc")
exit(1)
+ if args.validate:
+ print("Valid")
+ exit(0)
+
col = arvados.collection.Collection(api_client=api)
with col.open(target, "w") as f:
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)