Skip to content

Commit

Permalink
added check consistency script and fixed search bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinDo committed Jul 23, 2024
1 parent 7c0669b commit d29efc7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/db_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def get_variants_page_merged(self, page, page_size, sort_by, include_hidden, use
new_constraints.append("(LENGTH(ref) = 1 AND LENGTH(alt) = 1 AND variant_type = 'small')")
elif 'struct' in variant_type:
new_constraints.append("(variant_type = 'sv')")
new_constraints = ' OR '.join(new_constraints)
new_constraints = functions.enbrace(' OR '.join(new_constraints))
postfix = self.add_constraints_to_command(postfix, new_constraints)
if cdna_ranges is not None and len(cdna_ranges) > 0:
new_constraints = []
Expand Down
7 changes: 4 additions & 3 deletions src/frontend_celery/webapp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

import sys
import os
from flask import Flask
from authlib.integrations.flask_client import OAuth
from flask_session import Session # alternatives: flask-caching, flask-kvsesssion
from urllib.parse import urlparse, urljoin
# for celery
from celery import Celery
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from config import Config
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from common import paths, functions
#from annotation_service.heredicare_interface import Heredicare_Flask
Expand All @@ -18,7 +20,6 @@
from flask_mail import Mail



oauth = OAuth()
sess = Session()
celery = Celery(__name__, backend="redis",
Expand Down
2 changes: 1 addition & 1 deletion src/frontend_celery/webapp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def fetch_heredicare(vid, user_id, conn:Connection, insert_variant = True, perfo
if status != 'success': # error in variant retrieval from heredicare
return status, message

if str(variant.get("VISIBLE", "0")) == "0" or len(variant) == 0: # skip invisible vid or vid that is unknown by heredicare
if (str(variant.get("VISIBLE", "0")) == "0" or len(variant) == 0) and insert_variant: # skip invisible vid or vid that is unknown by heredicare
annotation_type_id = conn.get_most_recent_annotation_type_id("heredicare_vid")
variant_id = conn.get_variant_id_from_external_id(vid, annotation_type_id) # check if heredivar knows the vid
if variant_id is not None: # heredivar knows the vid, but heredicare doesnt OR vid is now invisible
Expand Down
11 changes: 9 additions & 2 deletions src/frontend_celery/webapp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ <h4>Overview</h4>
<div class="bst bsb">
<h4>Changelog</h4>

<div class="underline">v 1.13.2 (22.07.2024)</div>
<div class="underline">v 1.13.3 (23.07.2024)</div>
<div class="btn-pvs">!! Scores from likelihood ratio tests are currently not available from HerediCaRe.</div>
<div>
Bugfixes:
<ul>
<li>Searching for specific variants would not apply filters correctly</li>
</ul>
</div>

<div class="underline">v 1.13.2 (22.07.2024)</div>
<div>
General changes:
<ul>
Expand All @@ -111,7 +119,6 @@ <h4>Changelog</h4>
</div>

<div class="underline">v 1.13.1 (18.07.2024)</div>
<div class="btn-pvs">!! Scores from likelihood ratio tests are currently not available from HerediCaRe.</div>
<div>
General changes:
<ul>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend_celery/webapp/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@
<div id="variant_type-select" class="d-flex">
{% for variant_type in static_information['allowed_variant_types'] %}
<div class="form-check d-flex bsr align-items-center">
<input class="form-check-input ssr" type="checkbox" value="{{variant_type}}" id="variant_type_{{variant_type}}" name="variant_type" {% if variant_type in selected_variant_types or selected_variant_types | length == 0 %}checked{% endif %}>
<input class="form-check-input ssr" type="checkbox" value="{{variant_type}}" id="variant_type_{{variant_type}}" name="variant_type" {% if variant_type in selected_variant_types %}checked{% endif %}>
<label class="form-check-label" for="variant_type_{{variant_type}}">{{variant_type.replace('_', ' ')}}</label>
</div>
{% endfor %}
Expand Down
68 changes: 68 additions & 0 deletions src/frontend_celery/webapp/utils/check_consistency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# this script checks that all HerediCaRe VIDs are consistent with the HerediVar variants


import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__))))))
from common.db_IO import Connection
import common.functions as functions
from common.heredicare_interface import Heredicare
import frontend_celery.webapp.tasks as tasks

def print_progress_bar(iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
bar = fill * filledLength + '-' * (length - filledLength)
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
# Print New Line on Complete
if iteration == total:
print()


conn = Connection()
heredicare = Heredicare()

err_out_path = path.dirname(path.abspath(__file__)) + "/heredicare_errors.tsv"
err_out_file = open(err_out_path, 'w')

user_id = -1

variant_ids = conn.get_all_valid_variant_ids()
print_progress_bar(0, len(variant_ids), prefix = 'Progress:', suffix = 'Complete', length = 50)

for i, variant_id in enumerate(variant_ids):
variant = conn.get_variant(variant_id, include_external_ids = True, include_annotations = False, include_consensus = False, include_user_classifications = False, include_automatic_classification = False, include_clinvar = False, include_consequences = False, include_assays = False, include_literature = False)
variant_id = str(variant.id)
vids = variant.get_external_ids('heredicare_vid', how = 'list')

for vid in vids:
status, message = tasks.fetch_heredicare(vid, user_id, conn, insert_variant = False, perform_annotation = False)
if status != 'success':
line = "\t".join([variant.get_string_repr(), "", variant_id, vid, "HerediCaRe API error: " + message])
err_out_file.write(line + "\n")
continue

heredicare_variant = functions.find_between(message, 'HG38 variant would be: ', '( ~~ |$)')
if heredicare_variant is None:
line = "\t".join([variant.get_string_repr(), '', variant_id, vid, "The heredicare_variant was not found in message: " + message])
err_out_file.write(line + "\n")
continue
heredicare_variant = heredicare_variant.strip().split('-')

if len(heredicare_variant) != 4:
line = "\t".join([variant.get_string_repr(), '-'.join(heredicare_variant), variant_id, vid, "Number of fields of heredicare variant is incorrect: " + str(len(heredicare_variant))])
err_out_file.write(line + "\n")
continue

if variant.chrom != heredicare_variant[0] or str(variant.pos) != heredicare_variant[1] or variant.ref != heredicare_variant[2] or variant.alt != heredicare_variant[3]:
line = "\t".join([variant.get_string_repr(), '-'.join(heredicare_variant), variant_id, vid, "Incorrect variant match!"])
err_out_file.write(line + "\n")
continue

print_progress_bar(i+1, len(variant_ids), prefix = 'Progress:', suffix = 'Complete', length = 50)




err_out_file.close()
conn.close()

0 comments on commit d29efc7

Please sign in to comment.