diff --git a/src/annotation_service/heredicare_interface.py b/src/annotation_service/heredicare_interface.py index 179d6634..6138925f 100644 --- a/src/annotation_service/heredicare_interface.py +++ b/src/annotation_service/heredicare_interface.py @@ -9,8 +9,20 @@ class heredicare_interface: def __init__(self): - self.base_url = "https://portal.img.med.uni-tuebingen.de/ahdoebm1/HerediCareAPI/v1/" - self.variant_validator = xml_validator('/mnt/users/ahdoebm1/HerediVar/doc/api/variant.xsd') + self.base_url = "http://hazel.imise.uni-leipzig.de:8443" + self.endpoints = {"bearer": "pids2/heredivar/oauth/token"} + #self.variant_validator = xml_validator('/mnt/users/ahdoebm1/HerediVar/doc/api/variant.xsd') + + def get_bearer(self): + url = self.base_url + "/" + self.endpoints["bearer"] + data = {"grant_type":"client_credentials"} + auth = (os.environ.get("HEREDICARE_CLIENT_ID"), os.environ.get("HEREDICARE_CLIENT_PASSWORD")) + if any([x is None for x in auth]): + return "ERROR missing credentials." + resp = requests.get(url, auth=auth, data=data, verify=False) + return resp + + #curl -i -k --user nVhaUXECYWFCDhka1EHm7Q..:kxjsbPExZZf1HS3oyBZ7Mw.. --data "grant_type=client_credentials" https://hazel.imise.uni-leipzig.de:8443/pids2/heredivar/oauth/token def get_heredicare_vid_list(self): @@ -68,4 +80,15 @@ def get_variant(self, vid): return execution_code, chr, pos, ref, alt, reference_genome_build, heredicare_variant # everything fine! - return execution_code, chr, pos, ref, alt, reference_genome_build, heredicare_variant \ No newline at end of file + return execution_code, chr, pos, ref, alt, reference_genome_build, heredicare_variant + + + +if __name__ == "__main__": + functions.read_dotenv() + interface = heredicare_interface() + + resp = interface.get_bearer() + print(resp) + print(resp.status_code) + print(resp.json()) \ No newline at end of file diff --git a/src/common/.env_example b/src/common/.env_example index 9188947e..65f2281b 100644 --- a/src/common/.env_example +++ b/src/common/.env_example @@ -49,3 +49,7 @@ MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= + +########## HEREDICARE API SETTINGS ########## +HEREDICARE_CLIENT_ID= +HEREDICARE_CLIENT_PASSWORD= diff --git a/src/common/db_IO.py b/src/common/db_IO.py index fbfe4c10..2df9a203 100644 --- a/src/common/db_IO.py +++ b/src/common/db_IO.py @@ -618,7 +618,7 @@ def sort_consequences(self, a, b): return 0 - def get_variants_page_merged(self, page, page_size, user_id, ranges = None, genes = None, consensus = None, user = None, hgvs = None, variant_ids_oi = None): + def get_variants_page_merged(self, page, page_size, user_id, include_hidden, ranges = None, genes = None, consensus = None, user = None, hgvs = None, variant_ids_oi = None): # get one page of variants determined by offset & pagesize offset = (page - 1) * page_size @@ -730,6 +730,9 @@ def get_variants_page_merged(self, page, page_size, user_id, ranges = None, gene new_constraints = "id IN " + placeholders actual_information += tuple(variant_ids_oi) postfix = self.add_constraints_to_command(postfix, new_constraints) + if not include_hidden: + new_constraints = " variant.is_hidden = 0" + postfix = self.add_constraints_to_command(postfix, new_constraints) command = prefix + postfix if page_size != 'unlimited': @@ -745,18 +748,9 @@ def get_variants_page_merged(self, page, page_size, user_id, ranges = None, gene variant = self.get_variant(variant_id=variant_raw[0], include_annotations = False, include_heredicare_classifications = False, include_clinvar = False, include_assays = False, include_literature = False) variants.append(variant) - if page_size == 'unlimited': return variants, len(variants) - # DEPRECATED -> done in models now - #variants_and_transcripts = [] - #for variant in variants: - # annotated_variant = self.annotate_preferred_transcripts(variant) - # variants_and_transcripts.extend(annotated_variant) - #variants = variants_and_transcripts - #print(variants) - # get number of variants prefix = "SELECT COUNT(id) FROM variant" command = prefix + postfix @@ -1424,7 +1418,7 @@ def clear_list(self, list_id): self.conn.commit() def get_one_variant(self, variant_id): - command = "SELECT id,chr,pos,ref,alt FROM variant WHERE id = %s" + command = "SELECT id,chr,pos,ref,alt,is_hidden FROM variant WHERE id = %s" self.cursor.execute(command, (variant_id, )) result = self.cursor.fetchone() return result @@ -1502,7 +1496,16 @@ def get_user_classifications_extended(self, variant_id, user_id='all', scheme_id - def get_variant(self, variant_id, include_annotations = True, include_consensus = True, include_user_classifications = True, include_heredicare_classifications = True, include_clinvar = True, include_consequences = True, include_assays = True, include_literature = True) -> models.Variant: + def get_variant(self, variant_id, + include_annotations = True, + include_consensus = True, + include_user_classifications = True, + include_heredicare_classifications = True, + include_clinvar = True, + include_consequences = True, + include_assays = True, + include_literature = True + ) -> models.Variant: variant_raw = self.get_one_variant(variant_id) if variant_raw is None: return None @@ -1513,6 +1516,8 @@ def get_variant(self, variant_id, include_annotations = True, include_consensus ref = variant_raw[3] alt = variant_raw[4] + is_hidden = True if variant_raw[5] == 1 else False + annotations = None if include_annotations: annotations = models.AllAnnotations() @@ -1718,7 +1723,7 @@ def get_variant(self, variant_id, include_annotations = True, include_consensus new_paper = models.Paper(year = paper[6], authors = paper[4], title = paper[3], journal = paper[5], pmid = paper[2], source = paper[7]) literature.append(new_paper) - variant = models.Variant(id=variant_id, chrom = chrom, pos = pos, ref = ref, alt = alt, + variant = models.Variant(id=variant_id, chrom = chrom, pos = pos, ref = ref, alt = alt, is_hidden = is_hidden, annotations = annotations, consensus_classifications = consensus_classifications, user_classifications = user_classifications, @@ -1731,8 +1736,11 @@ def get_variant(self, variant_id, include_annotations = True, include_consensus - - + def hide_variant(self, variant_id, is_hidden): + command = "UPDATE variant SET is_hidden = %s WHERE id = %s" + is_hidden = 0 if is_hidden else 1 + self.cursor.execute(command, (is_hidden, variant_id)) + self.conn.commit() diff --git a/src/common/models.py b/src/common/models.py index 9453b240..77c9d309 100644 --- a/src/common/models.py +++ b/src/common/models.py @@ -560,6 +560,8 @@ class Variant: ref: str alt: str + is_hidden: bool + consensus_classifications: Any = None # list of classifications user_classifications: Any = None # list of classifications heredicare_classifications: Any = None # list of heredicare classifications diff --git a/src/frontend_celery/webapp/templates/macros.html b/src/frontend_celery/webapp/templates/macros.html index e9215382..6801781a 100644 --- a/src/frontend_celery/webapp/templates/macros.html +++ b/src/frontend_celery/webapp/templates/macros.html @@ -405,19 +405,52 @@