diff --git a/src/common/clinvar_interface.py b/src/common/clinvar_interface.py index f001064b..305f3447 100644 --- a/src/common/clinvar_interface.py +++ b/src/common/clinvar_interface.py @@ -158,6 +158,7 @@ def get_postable_consensus_classification(self, variant, selected_gene, clinvar_ "data": {"content": data} }] } + print(postable_data) return postable_data def post_consensus_classification(self, variant, selected_gene, clinvar_accession): @@ -233,4 +234,5 @@ def get_clinvar_submission_status(self, submission_id): clinvar_submission_message = ';'.join(clinvar_submission_messages) submission_status['message'] = clinvar_submission_message - return submission_status \ No newline at end of file + return submission_status + diff --git a/src/common/db_IO.py b/src/common/db_IO.py index d216e40e..f4f0acae 100644 --- a/src/common/db_IO.py +++ b/src/common/db_IO.py @@ -1447,9 +1447,10 @@ def update_consensus_classification_needs_heredicare_upload(self, consensus_clas self.conn.commit() def update_consensus_classification_needs_clinvar_upload(self, consensus_classification_id): - command = "UPDATE consensus_classification SET needs_clinvar_upload = 0 WHERE id = %s" - self.cursor.execute(command, (consensus_classification_id, )) - self.conn.commit() + if consensus_classification_id is not None: + command = "UPDATE consensus_classification SET needs_clinvar_upload = 0 WHERE id = %s" + self.cursor.execute(command, (consensus_classification_id, )) + self.conn.commit() def get_variant_ids_which_need_heredicare_upload(self, variant_ids_oi = None): # excludes structural variants and intergenic variants and variants of unfinished submissions @@ -3791,7 +3792,7 @@ def get_heredicare_queue_entries(self, publish_queue_ids: list, variant_id): if len(publish_queue_ids) == 0: return [] placeholders = self.get_placeholders(len(publish_queue_ids)) - command = "SELECT id, status, requested_at, finished_at, message, vid, variant_id, submission_id, consensus_classification_id from publish_heredicare_queue WHERE publish_queue_id IN " + placeholders + " AND variant_id = %s" + command = "SELECT id, status, requested_at, finished_at, message, vid, variant_id, submission_id, consensus_classification_id, publish_queue_id from publish_heredicare_queue WHERE publish_queue_id IN " + placeholders + " AND variant_id = %s" actual_information = tuple(publish_queue_ids) + (variant_id, ) self.cursor.execute(command, actual_information) result = self.cursor.fetchall() @@ -3860,11 +3861,24 @@ def get_publish_requests_page(self, page, page_size): - def insert_publish_clinvar_request(self, publish_queue_id, variant_id): - command = "INSERT INTO publish_clinvar_queue (publish_queue_id, variant_id) VALUES (%s, %s)" - self.cursor.execute(command, (publish_queue_id, variant_id)) + def insert_publish_clinvar_request(self, publish_queue_id, variant_id, manually_added = False): + command = "INSERT INTO publish_clinvar_queue (publish_queue_id, variant_id, manually_added) VALUES (%s, %s, %s)" + self.cursor.execute(command, (publish_queue_id, variant_id, manually_added)) self.conn.commit() return self.get_last_insert_id() + + def is_manual_publish_clinvar_queue(self, publish_queue_id): + command = "SELECT EXISTS (SELECT * FROM publish_clinvar_queue WHERE id = %s AND manually_added = 1)" + self.cursor.execute(command, (publish_queue_id, )) + result = self.cursor.fetchone()[0] + if result == 1: + return True + return False + + #def delete_manual_publish_clinvar_queue(self, publish_clinvar_queue_id): + # command = "DELETE FROM publish_clinvar_queue WHERE manually_added = 1 AND id = %s" + # self.cursor.execute(command, (publish_clinvar_queue_id, )) + # self.conn.commit() def update_publish_clinvar_queue_celery_task_id(self, publish_clinvar_queue_id, celery_task_id): command = "UPDATE publish_clinvar_queue SET celery_task_id = %s WHERE id = %s" @@ -3903,21 +3917,24 @@ def update_publish_clinvar_queue_status(self, publish_clinvar_queue_id, status, def get_most_recent_publish_queue_ids_clinvar(self, variant_id): - command = "SELECT DISTINCT publish_queue_id FROM publish_clinvar_queue WHERE variant_id = %s AND id >= (SELECT MAX(id) FROM publish_clinvar_queue WHERE variant_id = %s AND status != 'skipped')" + command = "SELECT DISTINCT publish_queue_id FROM publish_clinvar_queue WHERE variant_id = %s AND id >= (SELECT MAX(id) FROM publish_clinvar_queue WHERE variant_id = %s AND status != 'skipped' AND status != 'deleted')" self.cursor.execute(command, (variant_id, variant_id)) result = self.cursor.fetchall() if len(result) == 0: - command = "SELECT DISTINCT publish_queue_id from publish_clinvar_queue WHERE variant_id = %s AND status = 'skipped'" + command = "SELECT DISTINCT publish_queue_id from publish_clinvar_queue WHERE variant_id = %s AND status = 'skipped' AND status != 'deleted'" self.cursor.execute(command, (variant_id, )) result = self.cursor.fetchall() return [x[0] for x in result] def get_clinvar_queue_entries(self, publish_queue_ids: list, variant_id): - if len(publish_queue_ids) == 0: - return [] - placeholders = self.get_placeholders(len(publish_queue_ids)) - command = "SELECT id, publish_queue_id, requested_at, status, message, submission_id, accession_id, last_updated, celery_task_id, consensus_classification_id FROM publish_clinvar_queue WHERE publish_queue_id IN " + placeholders + " AND variant_id = %s" - actual_information = tuple(publish_queue_ids) + (variant_id, ) + command = "SELECT id, publish_queue_id, requested_at, status, message, submission_id, accession_id, last_updated, celery_task_id, consensus_classification_id, manually_added FROM publish_clinvar_queue WHERE variant_id = %s" + actual_information = (variant_id, ) + if publish_queue_ids is not None: + if len(publish_queue_ids) == 0: + return [] + placeholders = self.get_placeholders(len(publish_queue_ids)) + command += " AND publish_queue_id IN " + placeholders + actual_information += tuple(publish_queue_ids) self.cursor.execute(command, actual_information) result = self.cursor.fetchall() return result diff --git a/src/frontend_celery/webapp/tasks.py b/src/frontend_celery/webapp/tasks.py index 75d1829f..cd187dcd 100644 --- a/src/frontend_celery/webapp/tasks.py +++ b/src/frontend_celery/webapp/tasks.py @@ -412,6 +412,28 @@ def skip_hg38(variant) -> bool: return False +def is_sv(variant) -> bool: + ref_19 = functions.none2default(variant.get('REF_HG19'), "") + alt_19 = functions.none2default(variant.get('ALT_HG19'), "") + ref_38 = functions.none2default(variant.get('REF_HG38'), "") + alt_38 = functions.none2default(variant.get('ALT_HG38'), "") + + sv_indicators = ["<", ">"] + unallowed_sv_indicators = ["g."] + + if any([indicator in ref_19 for indicator in sv_indicators]) and not any([indicator in ref_19 for indicator in unallowed_sv_indicators]): + return True + if any([indicator in alt_19 for indicator in sv_indicators]) and not any([indicator in alt_19 for indicator in unallowed_sv_indicators]): + return True + if any([indicator in ref_38 for indicator in sv_indicators]) and not any([indicator in ref_38 for indicator in unallowed_sv_indicators]): + return True + if any([indicator in alt_38 for indicator in sv_indicators]) and not any([indicator in alt_38 for indicator in unallowed_sv_indicators]): + return True + if any([len(seq) > 1000 for seq in [ref_19, alt_19, ref_38, alt_38]]): + return True + + return False + # this is the main add variant from heredicare function! -> sanitizes and inserts variant def map_hg38(variant, user_id, conn:Connection, insert_variant = True, perform_annotation = True, external_ids = None): # the task worker @@ -421,6 +443,12 @@ def map_hg38(variant, user_id, conn:Connection, insert_variant = True, perform_a allowed_sequence_letters = "ACGT" + if is_sv(variant): # skip structural variants + status = "error" + message = "Structural variants are not supported for import from HerediCaRe" + return status, message + + # first check if the hg38 information is there chrom = variant.get('CHROM') pos = variant.get('POS_HG38') diff --git a/src/frontend_celery/webapp/templates/main/changelog.html b/src/frontend_celery/webapp/templates/main/changelog.html index 1a97dae1..65f1b3e7 100644 --- a/src/frontend_celery/webapp/templates/main/changelog.html +++ b/src/frontend_celery/webapp/templates/main/changelog.html @@ -9,6 +9,116 @@

{% block title %} Changelog {% endblock %}

+ +
v 1.13.6 (16.08.2024)
+
+ General changes: + + Bugfixes: + +
+ + +
v 1.13.5 (15.08.2024)
+
+ Bugfixes: + +
+ +
v 1.13.4 (25.07.2024)
+
+ General changes: + + Bugfixes: + +
+ +
v 1.13.3 (23.07.2024)
+
+ Bugfixes: + +
+ +
v 1.13.2 (22.07.2024)
+
+ General changes: + + Bugfixes: + +
+ +
v 1.13.1 (18.07.2024)
+
+ General changes: + + Bugfixes: + +
+ +
v 1.13 (05.07.2024)
+
+ General changes: + + Bugfixes: + +
+ + + +
v 1.12 (17.06.2024)
General changes: diff --git a/src/frontend_celery/webapp/templates/main/documentation.html b/src/frontend_celery/webapp/templates/main/documentation.html index 2e2fe197..ecfee8f3 100644 --- a/src/frontend_celery/webapp/templates/main/documentation.html +++ b/src/frontend_celery/webapp/templates/main/documentation.html @@ -9,113 +9,6 @@

{% block title %} Welcome to the HerediVar Wiki {% endblock %}

-
v 1.13.6 (16.08.2024)
-
- General changes: - - Bugfixes: - -
- - -
v 1.13.5 (15.08.2024)
-
- Bugfixes: - -
- -
v 1.13.4 (25.07.2024)
-
- General changes: - - Bugfixes: - -
- -
v 1.13.3 (23.07.2024)
-
- Bugfixes: - -
- -
v 1.13.2 (22.07.2024)
-
- General changes: - - Bugfixes: - -
- -
v 1.13.1 (18.07.2024)
-
- General changes: - - Bugfixes: - -
- -
v 1.13 (05.07.2024)
-
- General changes: - - Bugfixes: - -
- -
diff --git a/src/frontend_celery/webapp/templates/upload/edit_clinvar_submissions.html b/src/frontend_celery/webapp/templates/upload/edit_clinvar_submissions.html new file mode 100644 index 00000000..d7fe11fc --- /dev/null +++ b/src/frontend_celery/webapp/templates/upload/edit_clinvar_submissions.html @@ -0,0 +1,159 @@ +{% extends 'base.html' %} + + +{% block content %} + +
+ + +

{% block title %} Edit ClinVar submissions {% endblock %}

+ + +{{ macros.add_variant_banner(variant) }} + + + +
+

Current ClinVar submission history:

+
+ + + + + + + + + + + + + + + + + {% for clinvar_submission in clinvar_submissions %} + + + + + + + + + + {% endfor %} + +
requested at
last updated
submission id
accession id
status
message
manual
{{clinvar_submission[2]}}{{clinvar_submission[7]}}{{clinvar_submission[5]}}{{clinvar_submission[6]}}{{clinvar_submission[3]}}{{clinvar_submission[4]}}{{clinvar_submission[10]}}
+
+
+ + +
+

Add ClinVar submission:

+
+ WARNING: Only manually add ClinVar submissions when HerediVar does not know about a specific ClinVar submission. This happens when a submission was done outside of HerediVar through the same organization (eg. the ClinVar submission portal). + + HerediVar shows an error message upon submitting the same variant to ClinVar that was uploaded elsewhere before. The message is similar to this: "This record is submitted as novel but it should be submitted as an update, including the SCV accession, because your organization previously submitted SCV0000000000 for the same variant and condition." + + You can use the following form to add this unknown ClinVar submission and retry the upload afterwards. +
+ +
+
+ + +
+ Please provide one ClinVar submission ID (SUBxxxxxxx) +
+
+ +
+ +
+ +
+ +
+
+
+ + +
+

Delete ClinVar submission:

+
+ WARNING: Only do this if a manually added ClinVar submission was added falsely +
+ +
+
+ + + + + + + + + + + + + + + + + + + {% for clinvar_submission in clinvar_submissions %} + {% if clinvar_submission[10] %} + + + + + + + + + + + {% endif %} + {% endfor %} + +
select
requested at
last updated
submission id
accession id
status
message
manual
+
+ +
+
{{clinvar_submission[2]}}{{clinvar_submission[7]}}{{clinvar_submission[5]}}{{clinvar_submission[6]}}{{clinvar_submission[3]}}{{clinvar_submission[4]}}{{clinvar_submission[10]}}
+
+ +
+ +
+ +
+ +
+
+
+ + +
+ + + + + + + + + + +{% endblock %} + +{% block special_scripts %} +{% endblock%} \ No newline at end of file diff --git a/src/frontend_celery/webapp/templates/variant/variant.html b/src/frontend_celery/webapp/templates/variant/variant.html index 8be0452c..addb5431 100644 --- a/src/frontend_celery/webapp/templates/variant/variant.html +++ b/src/frontend_celery/webapp/templates/variant/variant.html @@ -35,7 +35,7 @@ {% if clinvar_queue_entry_summary["status"] not in ["skipped", "unknown"] %} {% set mrcc = variant.get_recent_consensus_classification() %} {% if mrcc is not none %} - {% if mrcc.needs_clinvar_upload and clinvar_queue_entry_summary["status"] not in ["progress", "processing", "submitted", "pending", "waiting", "requesting"] %} + {% if mrcc.needs_clinvar_upload and clinvar_queue_entry_summary["status"] not in ["progress", "processing", "submitted", "pending", "waiting", "requesting", "multiple stati"] %} {{macros.draw_exclamation_mark("The consensus classification needs to be uploaded to ClinVar!")}} {% endif %} {% endif %} @@ -87,7 +87,7 @@ {% if heredicare_queue_entry_summary["status"] not in ["skipped", "unknown"] %} {% set mrcc = variant.get_recent_consensus_classification() %} {% if mrcc is not none %} - {% if mrcc.needs_heredicare_upload and heredicare_queue_entry_summary["status"] in ["error", "api_error", "success", "waiting", "requested"] %} + {% if mrcc.needs_heredicare_upload and heredicare_queue_entry_summary["status"] in ["error", "api_error", "success", "waiting", "requested", "multiple stati"] %} {{macros.draw_exclamation_mark("The consensus classification needs to be uploaded to HerediCaRe!")}} {% endif %} {% endif %} @@ -154,8 +154,16 @@ + + {% if 'super_user' in session['user']['roles'] %} +
  • + + External ClinVar submission + +
  • + {% endif %} {% endif %}
  • + @@ -385,6 +388,44 @@

    Variant information

    + +
    + + +
    +
    +
    +

    Variant IDs

    + +
    + + + + + + + + + {% set external_id_annotations = variant.group_external_ids() %} + {% for group_identifier in external_id_annotations %} + {{ macros.draw_annotation_group(annotations, external_id_annotations[group_identifier], group_identifier) }} + {% endfor %} + +
    +
    + +
    +
    +
    + + +
    + + + + + +
    diff --git a/src/frontend_celery/webapp/upload/upload_routes.py b/src/frontend_celery/webapp/upload/upload_routes.py index 36ecdb90..814b8a26 100644 --- a/src/frontend_celery/webapp/upload/upload_routes.py +++ b/src/frontend_celery/webapp/upload/upload_routes.py @@ -91,3 +91,56 @@ def submit_assay(variant_id): invalidate_download_queue(list_id, "list_download", conn) return redirect(url_for('upload.submit_assay', variant_id = variant_id)) return render_template('upload/submit_assay.html', assay_types = assay_types) + + + +@upload_blueprint.route('/upload/clinvar_submissions/', methods=['GET', 'POST']) +@require_permission(['admin_resources']) +def edit_clinvar_submissions(variant_id): + conn = get_connection() + + require_valid(variant_id, "variant", conn) + + variant = conn.get_variant(variant_id) + clinvar_submissions = conn.get_clinvar_queue_entries(None, variant_id = variant_id) + + do_redirect = False + + if request.method == 'POST': + submission_type = request.form.get('submission_type', "") + + if submission_type == "add": + clinvar_interface = ClinVar() + submission_id = request.form.get('submission_id', "").strip() + if not submission_id: + flash("The ClinVar submission id is required.", "alert-danger") + else: + submission_status = clinvar_interface.get_clinvar_submission_status(submission_id) + if submission_status is None: + flash("The status of the submission id could not be fetched. This usually happens when the ClinVar submission ID is incorrect. It is also possible that the ClinVar API is unreachable. In this case try again later.", "alert-danger") + elif submission_status['status'] == 'error': + flash("The submission status of the submission id is error with message: " + str(submission_status['message'], "alert-danger")) + else: + publish_queue_id = conn.insert_publish_request(session['user']['user_id'], upload_heredicare = False, upload_clinvar = True, variant_ids = [variant_id]) + conn.update_publish_queue_status(publish_queue_id, status = "success", message = "") + publish_clinvar_queue_id = conn.insert_publish_clinvar_request(publish_queue_id, variant_id, manually_added = True) + conn.update_publish_clinvar_queue_status(publish_clinvar_queue_id, status = "submitted", message = "", submission_id = submission_id) + do_redirect = True + flash("Successfully added ClinVar submission to HerediVar", "alert-success") + elif submission_type == "delete": + publish_clinvar_queue_id = request.form.get('publish_clinvar_queue_id', "") + require_valid(publish_clinvar_queue_id, "publish_clinvar_queue", conn) + if not conn.is_manual_publish_clinvar_queue(publish_clinvar_queue_id): + flash("Only manually added ClinVar submissions can be deleted.", "alert-danger") + else: + conn.update_publish_clinvar_queue_status(publish_clinvar_queue_id, status = "deleted", message = "Manually deleted by " + str(get_preferred_username())) + flash("Successfully removed ClinVar submission", "alert-success") + do_redirect = True + else: + flash("Invalid submission type: " + str(submission_type), "alert-danger") + + if do_redirect: + return redirect(url_for('variant.display', variant_id = variant_id)) + return render_template('upload/edit_clinvar_submissions.html', variant = variant, clinvar_submissions = clinvar_submissions) + + diff --git a/src/frontend_celery/webapp/upload/upload_tasks.py b/src/frontend_celery/webapp/upload/upload_tasks.py index 806262a5..2e71fdc3 100644 --- a/src/frontend_celery/webapp/upload/upload_tasks.py +++ b/src/frontend_celery/webapp/upload/upload_tasks.py @@ -107,6 +107,7 @@ def start_upload_one_variant_clinvar(variant_id, publish_queue_id, options, user clinvar_accession = None publish_queue_ids_oi = conn.get_most_recent_publish_queue_ids_clinvar(variant_id) previous_clinvar_submissions = check_update_clinvar_status(variant_id, publish_queue_ids_oi, conn) # is None if there is no previous clinvar accession + #print(previous_clinvar_submissions) if previous_clinvar_submissions is not None: for previous_clinvar_submission in previous_clinvar_submissions: clinvar_accession = previous_clinvar_submission[6] # while we are at it also grab the accession_id if there is one (in case this is an update) diff --git a/src/frontend_celery/webapp/utils/upload_status_checker.py b/src/frontend_celery/webapp/utils/upload_status_checker.py index 9aed14e3..11f644a7 100644 --- a/src/frontend_celery/webapp/utils/upload_status_checker.py +++ b/src/frontend_celery/webapp/utils/upload_status_checker.py @@ -26,7 +26,7 @@ def check_update_clinvar_status(variant_id, publish_queue_ids_oi: list, conn: Co # the request is still in process -> check for an update & synchronize heredivar database # pull new information from external - if (status in ['processing', 'submitted', 'retry', 'process', 'pending'] and submission_id is not None) or force_update: + if (status in ['processing', 'submitted', 'retry', 'process', 'pending'] and submission_id is not None) or force_update and status != 'deleted': clinvar_interface = ClinVar() new_submission_status = clinvar_interface.get_clinvar_submission_status(submission_id) status = new_submission_status['status'] @@ -39,10 +39,13 @@ def check_update_clinvar_status(variant_id, publish_queue_ids_oi: list, conn: Co clinvar_queue_entries = conn.get_clinvar_queue_entries(publish_queue_ids_oi, variant_id) # update the respective needs_upload field if a submission chaged to success - needs_clinvar_upload = False + needs_clinvar_upload = True for clinvar_queue_entry in clinvar_queue_entries: - if clinvar_queue_entry[3] in ["error"]: #["success", "processed"]: + if clinvar_queue_entry[3] in ["success", "processed"]: #["success", "processed"]: + needs_clinvar_upload = False + else: needs_clinvar_upload = True + break if not needs_clinvar_upload: consensus_classification_id = clinvar_queue_entry[9] @@ -82,10 +85,13 @@ def check_update_heredicare_status(variant_id, publish_queue_ids_oi: list, conn: heredicare_queue_entries = conn.get_heredicare_queue_entries(publish_queue_ids_oi, variant_id) # if an upload was successful update the respective needs_upload field - needs_heredicare_upload = False + needs_heredicare_upload = True for heredicare_queue_entry in heredicare_queue_entries: - if heredicare_queue_entry[1] in ["error"]: + if heredicare_queue_entry[3] in ["success"]: #["success", "processed"]: + needs_heredicare_upload = False + else: needs_heredicare_upload = True + break if not needs_heredicare_upload: consensus_classification_id = heredicare_queue_entry[8] diff --git a/src/frontend_celery/webapp/variant/variant_functions.py b/src/frontend_celery/webapp/variant/variant_functions.py index 7a50c154..aafac30b 100644 --- a/src/frontend_celery/webapp/variant/variant_functions.py +++ b/src/frontend_celery/webapp/variant/variant_functions.py @@ -311,66 +311,113 @@ def handle_selected_literature(previous_selected_literature, classification_id, - +#heredicare_queue_entries: ALL heredicare queue entries until error or success is hit +#publish_queue_heredicare_queue_entries: ONLY entries of publish_queue def summarize_heredicare_status(heredicare_queue_entries, publish_queue): summary = {"status": "unknown", "max_requested_at": "unknown", "insert_tasks_message": ""} - if publish_queue is not None: - if heredicare_queue_entries is not None: - all_skipped = True - for heredicare_queue_entry in heredicare_queue_entries: - current_status = heredicare_queue_entry[1] - current_requested_at = heredicare_queue_entry[2] - if current_status == 'skipped': - continue - all_skipped = False - if summary["status"] == "unknown": - summary["status"] = current_status - elif summary["status"] != current_status: - summary["status"] = "multiple stati" - - if summary["max_requested_at"] == "unknown": - summary["max_requested_at"] = current_requested_at - elif summary["max_requested_at"] < current_requested_at: - summary["max_requested_at"] = current_requested_at - if all_skipped: - summary["status"] = "skipped" - else: - if publish_queue.status == 'error': + + if publish_queue is not None: # fresh upload - preferred + prefer_publish_queue_status = True + if publish_queue.insert_tasks_status in ["pending"]: + summary["status"] = "waiting" + elif publish_queue.insert_tasks_status in ["progress", "error"]: + if heredicare_queue_entries is not None: + for entry in heredicare_queue_entries: # id, status, requested_at, finished_at, message, vid, variant_id, submission_id, consensus_classification_id, publish_queue_id + if entry[9] == publish_queue.id: # current publish queue already issued job(s) for this variant + prefer_publish_queue_status = False + if prefer_publish_queue_status and publish_queue.insert_tasks_status == "progress": + summary["status"] = "requesting" + if prefer_publish_queue_status and publish_queue.insert_tasks_status == "error": summary["status"] = "error" summary["insert_tasks_message"] = publish_queue.insert_tasks_message - elif publish_queue.insert_tasks_status == 'pending': - summary["status"] = "waiting" - elif publish_queue.insert_tasks_status == 'progress': - summary["status"] = "requesting" + elif publish_queue.insert_tasks_status in ["success"]: + prefer_publish_queue_status = False + if not prefer_publish_queue_status: + if heredicare_queue_entries is not None: # prefer the status of the heredicare submission if they are available + all_skipped = True + for heredicare_queue_entry in heredicare_queue_entries: + current_status = heredicare_queue_entry[1] + current_requested_at = heredicare_queue_entry[2] + if current_status == 'skipped': + continue + all_skipped = False + if summary["status"] == "unknown": + summary["status"] = current_status + elif summary["status"] != current_status: + summary["status"] = "multiple stati" + + if summary["max_requested_at"] == "unknown": + summary["max_requested_at"] = current_requested_at + elif summary["max_requested_at"] < current_requested_at: + summary["max_requested_at"] = current_requested_at + if all_skipped: + summary["status"] = "skipped" + + #print(publish_queue) + #print(heredicare_queue_entries) + #print(summary) return summary def summarize_clinvar_status(clinvar_queue_entries, publish_queue): + summary = {"status": "unknown", "insert_tasks_message": ""} - if publish_queue is not None: - if clinvar_queue_entries is not None: - all_skipped = True - for clinvar_queue_entry in clinvar_queue_entries: - current_status = clinvar_queue_entry[3] - if current_status == 'skipped': - continue - all_skipped = False - if summary["status"] == "unknown": - summary["status"] = current_status - elif summary["status"] != current_status: - summary["status"] = "multiple stati" - if all_skipped: - summary["status"] = "skipped" - else: - if publish_queue.status == 'error': + + if publish_queue is not None: # fresh upload - preferred + prefer_publish_queue_status = True + if publish_queue.insert_tasks_status in ["pending"]: + summary["status"] = "waiting" + elif publish_queue.insert_tasks_status in ["progress", "error"]: + if clinvar_queue_entries is not None: + for entry in clinvar_queue_entries: # id, status, requested_at, finished_at, message, vid, variant_id, submission_id, consensus_classification_id, publish_queue_id + if entry[1] == publish_queue.id: # current publish queue already issued job(s) for this variant + prefer_publish_queue_status = False + if prefer_publish_queue_status and publish_queue.insert_tasks_status == "progress": + summary["status"] = "requesting" + if prefer_publish_queue_status and publish_queue.insert_tasks_status == "error": summary["status"] = "error" summary["insert_tasks_message"] = publish_queue.insert_tasks_message - if publish_queue.insert_tasks_status == 'pending': - summary["status"] = "waiting" - elif publish_queue.insert_tasks_status == 'progress': - summary["status"] = "requesting" + elif publish_queue.insert_tasks_status in ["success"]: + prefer_publish_queue_status = False + if not prefer_publish_queue_status: + if clinvar_queue_entries is not None: # prefer the status of the heredicare submission if they are available + all_skipped = True + for entry in clinvar_queue_entries: + current_status = entry[3] + if current_status == 'skipped': + continue + all_skipped = False + if summary["status"] == "unknown": + summary["status"] = current_status + elif summary["status"] != current_status: + summary["status"] = "multiple stati" + if all_skipped: + summary["status"] = "skipped" + + #if publish_queue is not None: + # if clinvar_queue_entries is not None: + # all_skipped = True + # for clinvar_queue_entry in clinvar_queue_entries: + # current_status = clinvar_queue_entry[3] + # if current_status == 'skipped': + # continue + # all_skipped = False + # if summary["status"] == "unknown": + # summary["status"] = current_status + # elif summary["status"] != current_status: + # summary["status"] = "multiple stati" + # if all_skipped: + # summary["status"] = "skipped" + # else: + # if publish_queue.status == 'error': + # summary["status"] = "error" + # summary["insert_tasks_message"] = publish_queue.insert_tasks_message + # if publish_queue.insert_tasks_status == 'pending': + # summary["status"] = "waiting" + # elif publish_queue.insert_tasks_status == 'progress': + # summary["status"] = "requesting" return summary diff --git a/src/frontend_celery/webapp/variant/variant_routes.py b/src/frontend_celery/webapp/variant/variant_routes.py index dc557a6d..63e47586 100644 --- a/src/frontend_celery/webapp/variant/variant_routes.py +++ b/src/frontend_celery/webapp/variant/variant_routes.py @@ -147,6 +147,7 @@ def display(variant_id=None, chr=None, pos=None, ref=None, alt=None): most_recent_publish_queue = conn.get_most_recent_publish_queue(variant_id = variant_id, upload_heredicare = True) publish_queue_ids_oi = conn.get_most_recent_publish_queue_ids_heredicare(variant_id) heredicare_queue_entries = check_update_heredicare_status(variant_id, publish_queue_ids_oi, conn) + #most_recent_heredicare_queue_entries = conn.get_heredicare_queue_entries([most_recent_publish_queue.id], variant_id) heredicare_queue_entry_summary = variant_functions.summarize_heredicare_status(heredicare_queue_entries, most_recent_publish_queue) # get the variant and all its annotations