Skip to content

Commit

Permalink
udpate annotation service & bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinDo committed Feb 16, 2024
1 parent 6fa8b25 commit 27f05ea
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,37 +262,46 @@ def get_autoclass_json(self, variant_id, conn: Connection) -> str:

# mRNA analyses: currently missing
"""
"mRNA_analysis" :
"mRNA_analysis" : [
{"performed": true,
"pathogenic": true,
"benign": true},
"minigene": true,
"patient_rna": false,
"allelic" : "Construct",
"quantification": null}
],
"""
assays_dict = variant.order_assays_by_type()
splicing_assays = assays_dict.get("splicing")
splicing_assay_performed = False
pathogenic_splicing_assay = False
benign_splicing_assay = False
if splicing_assays is not None and len(splicing_assays) > 0:
splicing_assay_performed = True
for splicing_assay in splicing_assays:
if splicing_assay.metadata.get("functional_category", "") == "pathogenic":
pathogenic_splicing_assay = True
if splicing_assay.metadata.get("functional_category", "") == "benign":
benign_splicing_assay = True
result["mRNA_analysis"] = {"performed": splicing_assay_performed,
"pathogenic": pathogenic_splicing_assay,
"benign": benign_splicing_assay}



# functional data: currently missing
"""
"functional_data":
"functional_data": [
{"performed": true,
"pathogenic": true,
"pathogenic": false,
"benign": true},
{"performed": true,
"pathogenic": false,
"benign": true}
]
"""
result["functional_data"] = {"performed": False,
"pathogenic": False,
"benign": False}
functional_assays = assays_dict.get("functional")

all_functional_assays = []
if functional_assays is not None and len(functional_assays) > 0:
for assay in functional_assays:
is_performed = True
is_pathogenic = False
is_benign = False
if assay.metadata.get("functional_category", "") == "pathogenic":
is_pathogenic = True
if assay.metadata.get("functional_category", "") == "benign":
is_benign = True
all_functional_assays.append({"performed": is_performed,
"pathogenic": is_pathogenic,
"benign": is_benign})
result["functional_data"] = all_functional_assays


# heredicare computed scores: currently missing
"""
Expand Down
11 changes: 10 additions & 1 deletion src/annotation_service/annotation_jobs/heredicare_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ def save_to_db(self, info, variant_id, conn):
err_msg += "The date could not be saved in the database. Format should be dd.mm.yyyy, but was: " + str(classification_date)
status_code = 1

heredicare_annotation_id = None
if status_code == 0:
conn.insert_heredicare_annotation(variant_id, vid, n_fam, n_pat, consensus_class, classification_date, comment, lr_cooc, lr_coseg, lr_family)
heredicare_annotation_id = conn.insert_heredicare_annotation(variant_id, vid, n_fam, n_pat, consensus_class, classification_date, comment, lr_cooc, lr_coseg, lr_family)

for key in heredicare_variant:
if key.startswith("PATH_Z") and heredicare_variant[key] is not None:
zid = int(key[6:])
print(zid)
classification = heredicare_variant[key] if heredicare_variant[key] != "-1" else None
conn.insert_heredicare_center_classification(heredicare_annotation_id, zid, classification, comment = None) # TODO! COMMENT!


return status_code, err_msg

Expand Down
60 changes: 33 additions & 27 deletions src/common/db_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,9 @@ def invalidate_previous_consensus_classifications(self, variant_id):
self.cursor.execute(command, (variant_id,))
self.conn.commit()

def insert_heredicare_center_classification(self, variant_id, classification, center_name, comment, date):
command = "INSERT INTO heredicare_center_classification (variant_id, classification, center_name, comment, date) VALUES (%s, %s, %s, %s, %s)"
self.cursor.execute(command, (variant_id, classification, center_name, comment, date))
def insert_heredicare_center_classification(self, heredicare_annotation_id, zid, classification, comment):
command = "INSERT INTO heredicare_center_classification (variant_heredicare_annotation_id, heredicare_ZID, classification, comment) VALUES (%s, %s, %s, %s)"
self.cursor.execute(command, (heredicare_annotation_id, zid, classification, comment))
self.conn.commit()

def check_heredicare_center_classification(self, variant_id, classification, center_name, comment, date): # this returns true if this classification is already in there and fals if it is not
Expand Down Expand Up @@ -1618,6 +1618,7 @@ def insert_user_classification(self, variant_id, classification, user_id, commen

def update_user_classification(self, user_classification_id, classification, comment, date, scheme_class):
command = "UPDATE user_classification SET classification = %s, comment = %s, date = %s, scheme_class = %s WHERE id = %s"
print(command % (str(classification), comment, date, str(scheme_class), user_classification_id))
self.cursor.execute(command, (str(classification), comment, date, str(scheme_class), user_classification_id))
self.conn.commit()

Expand Down Expand Up @@ -1885,9 +1886,9 @@ def get_import_request(self, import_queue_id = '', date = ''):
return None
"""

def get_heredicare_center_classifications(self, variant_id):
command = 'SELECT * FROM heredicare_center_classification WHERE variant_id = %s'
self.cursor.execute(command, (variant_id, ))
def get_heredicare_center_classifications(self, heredicare_annotation_id):
command = 'SELECT id, heredicare_ZID, (SELECT name FROM heredicare_ZID WHERE heredicare_ZID.ZID = heredicare_center_classification.heredicare_ZID) as center_name, classification, comment FROM heredicare_center_classification WHERE variant_heredicare_annotation_id = %s'
self.cursor.execute(command, (heredicare_annotation_id, ))
result = self.cursor.fetchall()
if len(result) == 0:
return None
Expand Down Expand Up @@ -2382,21 +2383,8 @@ def get_variant(self, variant_id,
automatic_classification = models.AutomaticClassification(id = automatic_classification_id, scheme_id = scheme_id, scheme_display_title = scheme_display_title, classification_splicing = classification_splicing, classification_protein = classification_protein, date = date, criteria = all_criteria)


heredicare_classifications = None
all_heredicare_annotations = None
if include_heredicare_classifications:
heredicare_classifications_raw = self.get_heredicare_center_classifications(variant_id)
if heredicare_classifications_raw is not None:
heredicare_classifications = []
for cl_raw in heredicare_classifications_raw:
id = int(cl_raw[0])
selected_class = cl_raw[1]
comment = cl_raw[4]
center = cl_raw[3]
date = cl_raw[5].strftime('%Y-%m-%d')
new_heredicare_classification = models.HeredicareClassification(id = id, selected_class = selected_class, comment = comment, center = center, classification_date = date, vid="")
heredicare_classifications.append(new_heredicare_classification)


heredicare_annotations_raw = self.get_heredicare_annotations(variant_id)
all_heredicare_annotations = []
Expand All @@ -2407,14 +2395,31 @@ def get_variant(self, variant_id,
n_fam = annot[2]
n_pat = annot[3]
consensus_class = annot[4]
comment = annot[5]
consensus_comment = annot[5]
classification_date = annot[6]
lr_cooc = annot[7]
lr_coseg = annot[8]
lr_family = annot[9]

classification = models.HeredicareClassification(id = heredicare_annotation_id, selected_class = consensus_class, comment = comment, classification_date = classification_date, center = "VUSTF", vid = vid)
new_heredicare_annotation = models.HeredicareAnnotation(id = heredicare_annotation_id, vid = vid, n_fam = n_fam, n_pat = n_pat, vustf_classification = classification, lr_cooc = lr_cooc, lr_coseg = lr_coseg, lr_family = lr_family)
consensus_classification = models.HeredicareConsensusClassification(id = heredicare_annotation_id, selected_class = consensus_class, comment = consensus_comment, classification_date = classification_date)


heredicare_classifications_raw = self.get_heredicare_center_classifications(heredicare_annotation_id)
heredicare_center_classifications = None
if heredicare_classifications_raw is not None:
heredicare_center_classifications = []
for cl_raw in heredicare_classifications_raw:
#id, heredicare_ZID, center_name, classification, comment
id = int(cl_raw[0])
zid = cl_raw[1]
center_name = cl_raw[2]
selected_class = cl_raw[3]
comment = cl_raw[4]
#date = cl_raw[5].strftime('%Y-%m-%d')
new_heredicare_classification = models.HeredicareCenterClassification(id = id, selected_class = selected_class, comment = comment, center_name = center_name, zid = zid)
heredicare_center_classifications.append(new_heredicare_classification)


new_heredicare_annotation = models.HeredicareAnnotation(id = heredicare_annotation_id, vid = vid, n_fam = n_fam, n_pat = n_pat, consensus_classification = consensus_classification, lr_cooc = lr_cooc, lr_coseg = lr_coseg, lr_family = lr_family, center_classifications = heredicare_center_classifications)
all_heredicare_annotations.append(new_heredicare_annotation)

# add clinvar annotation
Expand Down Expand Up @@ -2527,7 +2532,6 @@ def get_variant(self, variant_id,
annotations = annotations,
consensus_classifications = consensus_classifications,
user_classifications = user_classifications,
heredicare_classifications = heredicare_classifications,
automatic_classification = automatic_classification,
heredicare_annotations = all_heredicare_annotations,
cancerhotspots_annotations = cancerhotspots_annotations,
Expand Down Expand Up @@ -2557,7 +2561,6 @@ def get_variant(self, variant_id,
annotations = annotations,
consensus_classifications = consensus_classifications,
user_classifications = user_classifications,
heredicare_classifications = heredicare_classifications,
automatic_classification = automatic_classification,
heredicare_annotations = all_heredicare_annotations,
cancerhotspots_annotations = cancerhotspots_annotations,
Expand Down Expand Up @@ -2838,9 +2841,11 @@ def get_selected_literature(self, is_user, classification_id):
def insert_update_heredivar_clinvar_submission(self, variant_id, submission_id, accession_id, status, message, last_updated, previous_clinvar_accession):
if previous_clinvar_accession is None:
command = "INSERT INTO heredivar_clinvar_submissions (variant_id, submission_id, accession_id, status, message, last_updated) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE submission_id=VALUES(submission_id), accession_id=VALUES(accession_id), status=VALUES(status),message=VALUES(message), last_updated=VALUES(last_updated)"
actual_information = (variant_id, submission_id, accession_id, status, message, last_updated)
else: # do not reset the accession id - this one is stable once it was created by clinvar
command = "INSERT INTO heredivar_clinvar_submissions (variant_id, submission_id, status, message, last_updated) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE submission_id=VALUES(submission_id), status=VALUES(status),message=VALUES(message), last_updated=VALUES(last_updated)"
self.cursor.execute(command, (variant_id, submission_id, accession_id, status, message, last_updated))
command = "INSERT INTO heredivar_clinvar_submissions (variant_id, submission_id, status, message, last_updated) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE submission_id=VALUES(submission_id), status=VALUES(status),message=VALUES(message), last_updated=VALUES(last_updated)"
actual_information = (variant_id, submission_id, status, message, last_updated)
self.cursor.execute(command, actual_information)
self.conn.commit()

def get_heredivar_clinvar_submission(self, variant_id):
Expand Down Expand Up @@ -2981,6 +2986,7 @@ def insert_heredicare_annotation(self, variant_id, vid, n_fam, n_pat, consensus_
command = "INSERT INTO variant_heredicare_annotation (variant_id, vid, n_fam, n_pat, consensus_class, date, comment, lr_cooc, lr_coseg, lr_family) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
self.cursor.execute(command, (variant_id, vid, n_fam, n_pat, consensus_class, classification_date, comment, lr_cooc, lr_coseg, lr_family))
self.conn.commit()
return self.get_last_insert_id()

def clear_heredicare_annotation(self, variant_id):
command = "DELETE FROM variant_heredicare_annotation WHERE variant_id = %s"
Expand Down
Loading

0 comments on commit 27f05ea

Please sign in to comment.