From 6b4720af241e5cb70949a26cf7d210fd11ca69b0 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 30 Jan 2025 14:55:06 +1030 Subject: [PATCH] SACGF/variantgrid#1243 - HGNC search + link to gene symbol --- ontology/models/models_ontology.py | 11 +++++++++++ ontology/models/ontology_search.py | 1 - ontology/views.py | 3 +-- variantgrid/settings/components/default_settings.py | 1 + variantgrid/settings/env/shariantcommon.py | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ontology/models/models_ontology.py b/ontology/models/models_ontology.py index bed76a3cb..46586739a 100644 --- a/ontology/models/models_ontology.py +++ b/ontology/models/models_ontology.py @@ -529,7 +529,18 @@ def padded_index(self) -> str: def external_url(self): return OntologyService.URLS[self.ontology_service].replace("${1}", self.padded_index) + def gene_symbol_url(self) -> Optional[str]: + """ Only for HGNC, get link to gene_symbol """ + url = None + if self.ontology_service == OntologyService.HGNC: + if gene_symbol := GeneSymbol.cast(self.name): + url = gene_symbol.get_absolute_url() + return url + def get_absolute_url(self): + if settings.ONTOLOGY_HGNC_REDIRECT_TO_GENE_SYMBOL: + if url := self.gene_symbol_url(): + return url return reverse('ontology_term', kwargs={"term": self.url_safe_id}) @property diff --git a/ontology/models/ontology_search.py b/ontology/models/ontology_search.py index 34ded5573..56cdbefae 100644 --- a/ontology/models/ontology_search.py +++ b/ontology/models/ontology_search.py @@ -57,7 +57,6 @@ def ontology_search_id(search_input: SearchInputInstance): search_type=OntologyTerm, pattern=re.compile(r"^HGNC\s*:\s*(.*)$", re.IGNORECASE), sub_name="Gene Disease Relationships", - admin_only=True, example=SearchExample( note="HGNC: followed by an ID or gene symbol", examples=["HGNC:BRCA1", "HGNC:4171"] diff --git a/ontology/views.py b/ontology/views.py index c75bc060e..046d562ea 100644 --- a/ontology/views.py +++ b/ontology/views.py @@ -47,8 +47,7 @@ def get_context_data(self, **kwargs): term_link = None if is_gene: - if gene_symbol := GeneSymbol.cast(term.name): - term_link = gene_symbol.get_absolute_url() + term_link = term.gene_symbol_url() else: regular_relationships = [] all_relationships: list[OntologyTermRelation] = OntologyTermRelation.relations_of(term) diff --git a/variantgrid/settings/components/default_settings.py b/variantgrid/settings/components/default_settings.py index 51f269845..f882b95ff 100644 --- a/variantgrid/settings/components/default_settings.py +++ b/variantgrid/settings/components/default_settings.py @@ -361,6 +361,7 @@ """ ONTOLOGY_EXTERNAL_LINKS = False # Generate external or internal links for ontology terms +ONTOLOGY_HGNC_REDIRECT_TO_GENE_SYMBOL = False PATHOLOGY_TESTS_ENABLED = False PATHOLOGY_TEST_REQUESTS_REDIRECT_URL = None diff --git a/variantgrid/settings/env/shariantcommon.py b/variantgrid/settings/env/shariantcommon.py index d3782ee87..23187db6b 100644 --- a/variantgrid/settings/env/shariantcommon.py +++ b/variantgrid/settings/env/shariantcommon.py @@ -129,6 +129,8 @@ LOGIN_REDIRECT_URL = '/classification/dashboard' LOGO_VIEW_NAME = "classification_dashboard" +ONTOLOGY_HGNC_REDIRECT_TO_GENE_SYMBOL = True + SHARIANT_STATIC_FILES_DIR = os.path.join(VARIANTGRID_APP_DIR, "static_files", "shariant_static") STATICFILES_DIRS = (SHARIANT_STATIC_FILES_DIR,) + STATICFILES_DIRS