From 5b1c7218fe63a5eee5d561ecaa20a17d94d91835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr> Date: Fri, 2 Oct 2020 15:41:47 +0200 Subject: [PATCH] add compound links in model, fix compound bioschemas and reuse that in the links template bioschemas for compound fixed for links and more WIP on #245 --- ippisite/ippidb/models.py | 35 +++++++++++++++++++ ippisite/ippidb/templates/compound_card.html | 18 +++++++++- .../ippidb/templates/compound_db_links.html | 10 +++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 3bb8468c..6e7b2877 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -1082,6 +1082,41 @@ class Compound(AutoFillableModel): """ return reverse("compound_card", kwargs={"pk": self.pk}) + @property + def pubchem_url(self): + """ + Get absolute URL to the corresponding PubChem entry + """ + return f"https://pubchem.ncbi.nlm.nih.gov/compound/{ self.pubchem_id }" if self.pubchem_id else None + + @property + def chembl_url(self): + """ + Get absolute URL to the corresponding Chembl entry + """ + return f"https://www.ebi.ac.uk/chembldb/compound/inspect/{ self.chembl_id }" if self.chembl_id else None + + @property + def chemspider_url(self): + """ + Get absolute URL to the corresponding ChemSpider entry + """ + return f"http://www.chemspider.com/Chemical-Structure.{ self.chemspider_id}.html" if self.chemspider_id else None + + @property + def pdbligand_url(self): + """ + Get absolute URL to the corresponding PDB ligand entry + """ + return f"https://www.rcsb.org/ligand/{ self.ligand_id}" if self.ligand_id else None + + @property + def drugbank_url(self): + """ + Get absolute URL to the corresponding Drugbank entry + """ + return f"https://www.drugbank.ca/drugs/{ self.drugbank_id}" if self.drugbank_id else None + def clean(self): """ Perform additional checks: diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index 680c2290..c8a3924b 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -573,8 +573,9 @@ <script id='JSON_LD' type="application/ld+json"> { -"url": "{{ compound.get_absolute_url }}", +"url": "{{ request.build_absolute_uri }}", "inChI": "{{ compound.inchi }}", +"name": "{{ compound.iupac_name }}", "iupacName": "{{ compound.iupac_name }}", "molecularWeight": {{ compound.molecular_weight }}, "identifier": "{{ compound.id }}", @@ -584,6 +585,21 @@ "smiles": [ "{{ compound.canonical_smile }}" ], +{% if compound.pubchem_id %} +"sameAs": "{{ compound.pubchem_url }}", +{% endif %} +{% if compound.chembl_id %} +"sameAs": "{{ compound.chembl_url }}", +{% endif %} +{% if compound.chemspider_id %} +"sameAs": "{{ compound.chemspider_url }}", +{% endif %} +{% if compound.ligand_id %} +"sameAs": "{{ compound.pdbligand_url }}", +{% endif %} +{% if compound.drugbank_id %} +"sameAs": "{{ compound.drugbank_url }}", +{% endif %} "@context": "http://schema.org" } diff --git a/ippisite/ippidb/templates/compound_db_links.html b/ippisite/ippidb/templates/compound_db_links.html index 5a0235a9..b823487e 100644 --- a/ippisite/ippidb/templates/compound_db_links.html +++ b/ippisite/ippidb/templates/compound_db_links.html @@ -4,35 +4,35 @@ <tr class="row"> <td scope="col" class="col-2 text-center"> {% if compound.pubchem_id %} - <a href="https://pubchem.ncbi.nlm.nih.gov/compound/{{ compound.pubchem_id }}" target="_blank"><img + <a href="{{ compound.pubchem_url }}" target="_blank"><img src="/static/images/Other/Pubchemlogo.png" style="height: 1.5em;" title="PubChem ID: {{ compound.pubchem_id }}" /><br />{{ compound.pubchem_id }}</a> {% endif %} </td> <td scope="col" class="col-2 text-center"> {% if compound.chembl_id %} - <a href="https://www.ebi.ac.uk/chembldb/compound/inspect/{{ compound.chembl_id }}" target="_blank"><img + <a href="{{ compound.chembl_url }}" target="_blank"><img src="/static/images/Other/Chembl_logo.png" style="height: 1.5em;" title="ChEMBL ID: {{ compound.chembl_id }}" /><br />{{ compound.chembl_id }}</a> {% endif %} </td> <td scope="col" class="col-2 text-center"> {% if compound.chemspider_id %} - <a href="http://www.chemspider.com/Chemical-Structure.{{ compound.chemspider_id}}.html" target="_blank"><img + <a href="{{ compound.chemspider_url }}.html" target="_blank"><img src="/static/images/Other/ChemSpider_Logo.png" style="height: 1.5em;" title="ChemSpider ID: {{ compound.chemspider_id }}" /><br />{{ compound.chemspider_id }}</a> {% endif %} </td> <td scope="col" class="col-2 text-center"> {% if compound.ligand_id %} - <a href="https://www.rcsb.org/ligand/{{ compound.ligand_id}}" target="_blank"><img + <a href="{{ compound.pdbligand_url }}" target="_blank"><img src="/static/images/Other/PDBLogo.ico" style="height: 1.5em;" title="PDB Ligand ID: {{ compound.ligand_id }}" /><br />{{ compound.ligand_id }}</a> {% endif %} </td> <td scope="col" class="col-2 text-center"> {% if compound.drugbank_id %} - <a href="https://www.drugbank.ca/drugs/{{ compound.drugbank_id}}" target="_blank"><img + <a href="{{ compound.drugbank_url }}" target="_blank"><img src="/static/images/Other/DrugBankLogo.ico" style="height: 1.5em;" title="DrugBank ID: {{ compound.drugbank_id }}" /><br />{{ compound.drugbank_id }}</a> {% endif %} -- GitLab