From 36f5c5b58a2de662eae9f379e66a9695d300dc2e Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:20:28 +0000 Subject: Add --no-start-analysis --- bh20seqanalyzer/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bh20seqanalyzer') diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 9a36cae..9daab5a 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -244,6 +244,7 @@ def main(): parser.add_argument('--latest-result-collection', type=str, default='lugli-4zz18-z513nlpqm03hpca', help='') parser.add_argument('--kickoff', action="store_true") + parser.add_argument('--no-start-analysis', action="store_true") parser.add_argument('--once', action="store_true") args = parser.parse_args() @@ -276,7 +277,7 @@ def main(): args.fastq_project, args.fastq_workflow_uuid) or at_least_one_new_valid_seq - if at_least_one_new_valid_seq: + if at_least_one_new_valid_seq and not args.no_start_analysis: start_pangenome_analysis(api, args.pangenome_analysis_project, args.pangenome_workflow_uuid, -- cgit v1.2.3 From dd0ff95c6973953542cc3a275be2b057b30ff577 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:40:17 +0000 Subject: A little more logging --- bh20seqanalyzer/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bh20seqanalyzer') diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 9daab5a..7839d20 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -23,6 +23,8 @@ def validate_upload(api, collection, validated_project, # validate the collection here. Check metadata, etc. valid = True + logging.info("Validating upload '%s' (%s)" % (collection["name"], collection["uuid"])) + if "metadata.yaml" not in col: logging.warn("Upload '%s' missing metadata.yaml", collection["name"]) valid = False @@ -75,7 +77,7 @@ def validate_upload(api, collection, validated_project, "name": "%s (%s)" % (collection["name"], time.asctime(time.gmtime()))}).execute() else: # It is invalid, delete it. - logging.warn("Suggest deleting '%s'" % collection["name"]) + logging.warn("Suggest deleting '%s' (%s)" % (collection["name"], collection["uuid"])) #api.collections().delete(uuid=collection["uuid"]).execute() return valid -- cgit v1.2.3 From 4f30e506055acb788a1ff1bbcb6359c4413a4eab Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Sun, 5 Jul 2020 21:33:26 +0000 Subject: Add bh20-seq-analyzer --print-status Get status from new property "status: validated/rejected" Also store QC fail error message. --- bh20seqanalyzer/main.py | 99 +++++++++++++++++++++++++----------------- bh20sequploader/main.py | 9 ++-- bh20sequploader/qc_metadata.py | 21 +++------ 3 files changed, 70 insertions(+), 59 deletions(-) (limited to 'bh20seqanalyzer') diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 7839d20..2fefa86 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -20,28 +20,36 @@ def validate_upload(api, collection, validated_project, fastq_project, fastq_workflow_uuid): col = arvados.collection.Collection(collection["uuid"]) - # validate the collection here. Check metadata, etc. - valid = True + if collection.get("status") in ("validated", "rejected"): + return False + # validate the collection here. Check metadata, etc. logging.info("Validating upload '%s' (%s)" % (collection["name"], collection["uuid"])) - if "metadata.yaml" not in col: - logging.warn("Upload '%s' missing metadata.yaml", collection["name"]) - valid = False - else: - try: - metadata_content = ruamel.yaml.round_trip_load(col.open("metadata.yaml")) - metadata_content["id"] = "http://arvados.org/keep:%s/metadata.yaml" % collection["portable_data_hash"] - sample_id = metadata_content["sample"]["sample_id"] - add_lc_filename(metadata_content, metadata_content["id"]) - valid = qc_metadata(metadata_content) and valid - except Exception as e: - logging.warn(e) - valid = False - if not valid: - logging.warn("Failed metadata qc") - - if valid: + errors = [] + + dup = api.collections().list(filters=[["owner_uuid", "=", validated_project], + ["portable_data_hash", "=", col.portable_data_hash()]]).execute() + if dup["items"]: + # This exact collection has been uploaded before. + errors.append("Duplicate of %s" % ([d["uuid"] for d in dup["items"]])) + + if not errors: + if "metadata.yaml" not in col: + errors.append("Missing metadata.yaml", collection["name"]) + else: + try: + metadata_content = ruamel.yaml.round_trip_load(col.open("metadata.yaml")) + metadata_content["id"] = "http://arvados.org/keep:%s/metadata.yaml" % collection["portable_data_hash"] + sample_id = metadata_content["sample"]["sample_id"] + add_lc_filename(metadata_content, metadata_content["id"]) + valid = qc_metadata(metadata_content) + if not valid: + errors.append("Failed metadata qc") + except Exception as e: + errors.append(str(e)) + + if not errors: try: tgt = None paired = {"reads_1.fastq": "reads.fastq", "reads_1.fastq.gz": "reads.fastq.gz"} @@ -51,36 +59,32 @@ def validate_upload(api, collection, validated_project, with col.open(n, 'rb') as qf: tgt = qc_fasta(qf)[0] if tgt != n and tgt != paired.get(n): - logging.info("Expected %s but magic says it should be %s", n, tgt) - valid = False + errors.append("Expected %s but magic says it should be %s", n, tgt) elif tgt in ("reads.fastq", "reads.fastq.gz", "reads_1.fastq", "reads_1.fastq.gz"): start_fastq_to_fasta(api, collection, fastq_project, fastq_workflow_uuid, n, sample_id) return False if tgt is None: - valid = False - logging.warn("Upload '%s' does not contain sequence.fasta, reads.fastq or reads_1.fastq", collection["name"]) - except ValueError as v: - valid = False + errors.append("Upload '%s' does not contain sequence.fasta, reads.fastq or reads_1.fastq", collection["name"]) + except Exception as v: + errors.append(str(v)) - dup = api.collections().list(filters=[["owner_uuid", "=", validated_project], - ["portable_data_hash", "=", col.portable_data_hash()]]).execute() - if dup["items"]: - # This exact collection has been uploaded before. - valid = False - logging.warn("Upload '%s' is duplicate" % collection["name"]) - if valid: + if not errors: logging.info("Added '%s' to validated sequences" % collection["name"]) # Move it to the "validated" project to be included in the next analysis + collection["properties"]["status"] = "validated" api.collections().update(uuid=collection["uuid"], body={ "owner_uuid": validated_project, "name": "%s (%s)" % (collection["name"], time.asctime(time.gmtime()))}).execute() + return True else: - # It is invalid, delete it. - logging.warn("Suggest deleting '%s' (%s)" % (collection["name"], collection["uuid"])) - #api.collections().delete(uuid=collection["uuid"]).execute() - - return valid + # It is invalid + logging.warn("'%s' (%s) has validation errors: %s" % ( + collection["name"], collection["uuid"], "\n".join(errors))) + collection["properties"]["status"] = "rejected" + collection["properties"]["errors"] = errors + api.collections().update(uuid=collection["uuid"], body={"properties": collection["properties"]}).execute() + return False def run_workflow(api, parent_project, workflow_uuid, name, inputobj): @@ -231,6 +235,18 @@ def upload_schema(api, workflow_def_project): return "keep:%s/schema.yml" % pdh +def print_status(api, uploader_project): + pending = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", uploader_project]]) + out = [] + for p in pending: + prop = p["properties"] + out.append(prop) + if "status" not in prop: + prop["status"] = "pending" + prop["created_at"] = p["created_at"] + prop["uuid"] = p["uuid"] + print(json.dumps(out, indent=2)) + def main(): parser = argparse.ArgumentParser(description='Analyze collections uploaded to a project') parser.add_argument('--uploader-project', type=str, default='lugli-j7d0g-n5clictpuvwk8aa', help='') @@ -248,6 +264,7 @@ def main(): parser.add_argument('--kickoff', action="store_true") parser.add_argument('--no-start-analysis', action="store_true") parser.add_argument('--once', action="store_true") + parser.add_argument('--print-status', action="store_true") args = parser.parse_args() api = arvados.api() @@ -266,14 +283,18 @@ def main(): args.exclude_list) return + if args.print_status: + print_status(api, args.uploader_project) + exit(0) + logging.info("Starting up, monitoring %s for uploads" % (args.uploader_project)) while True: move_fastq_to_fasta_results(api, args.fastq_project, args.uploader_project) - new_collections = api.collections().list(filters=[['owner_uuid', '=', args.uploader_project]]).execute() + new_collections = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", args.uploader_project]]) at_least_one_new_valid_seq = False - for c in new_collections["items"]: + for c in new_collections: at_least_one_new_valid_seq = validate_upload(api, c, args.validated_project, args.fastq_project, diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index cdc4c3f..8555e2b 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -26,11 +26,9 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): try: log.debug("Checking metadata" if do_qc else "Skipping metadata check") if do_qc and not qc_metadata(metadata.name): - log.warning("Failed metadata qc") - exit(1) - except ValueError as e: + raise Exception("Failed metadata qc") + except Exception as e: log.debug(e) - log.debug("Failed metadata qc") print(e) exit(1) @@ -42,9 +40,8 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): target.append(qc_fasta(sequence_p2)) target[0] = ("reads_1."+target[0][0][6:], target[0][1]) target[1] = ("reads_2."+target[1][0][6:], target[0][1]) - except ValueError as e: + except Exception as e: log.debug(e) - log.debug("Failed FASTA qc") print(e) exit(1) diff --git a/bh20sequploader/qc_metadata.py b/bh20sequploader/qc_metadata.py index 9122ace..2b57991 100644 --- a/bh20sequploader/qc_metadata.py +++ b/bh20sequploader/qc_metadata.py @@ -21,20 +21,13 @@ def qc_metadata(metadatafile): 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 + raise Exception(avsc_names) - try: - doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, 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") + doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, 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: - log.debug(reason) - print(reason) + if not rslt: + raise Exception(reason) - return rslt - except Exception as e: - traceback.print_exc() - log.warn(e) - return False + return True -- cgit v1.2.3 From ba38aaf6920b246f6644cfb49730a5e2ee5f9db0 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 7 Jul 2020 17:17:31 -0400 Subject: --print-status=html creates html report --- bh20seqanalyzer/main.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'bh20seqanalyzer') diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 2fefa86..1746587 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -235,9 +235,10 @@ def upload_schema(api, workflow_def_project): return "keep:%s/schema.yml" % pdh -def print_status(api, uploader_project): +def print_status(api, uploader_project, fmt): pending = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", uploader_project]]) out = [] + status = {} for p in pending: prop = p["properties"] out.append(prop) @@ -245,7 +246,38 @@ def print_status(api, uploader_project): prop["status"] = "pending" prop["created_at"] = p["created_at"] prop["uuid"] = p["uuid"] - print(json.dumps(out, indent=2)) + status[prop["status"]] = status.get(prop["status"], 0) + 1 + if fmt == "html": + print( +""" + +
+""") + print("Total collections in upload project %s
" % len(out)) + print("Status %s
" % status) + print( +""" +Collection | +Sequence label | +Status | +Errors |
---|---|---|---|
%s | " % (r["uuid"], r["uuid"])) + print("%s | " % r["sequence_label"]) + print("%s | " % r["status"]) + print("%s | " % "\n".join(r.get("errors", [])))
+ print("