Skip to content

Commit

Permalink
Merge branch 'egonw-feature/diseaseIndexPlusRedirecting'
Browse files Browse the repository at this point in the history
  • Loading branch information
fnielsen committed Oct 20, 2023
2 parents c76e000 + 615d14a commit 82f6659
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 13 deletions.
66 changes: 54 additions & 12 deletions scholia/app/templates/disease-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,62 @@

{% block page_content %}

<h1>Disease</h1>
<h1>Diseases</h1>

Diseases.
<div class="container">

<h2>Examples</h2>
<h2>Examples</h2>

<ul>
<li><a href="Q41112">Schizophrenia</a></li>
<li><a href="Q431643">Microcephaly</a></li>
<li><a href="Q917357">Rett syndrome</a></li>
<li><a href="Q8071861">Zika fever</a></li>
<li><a href="Q10863074">Fatty liver disease</a></li>
</ul>
<div class="card-deck mb-3">
<div class="card mb-4 box-shadow">

{% endblock %}
<div class="card-header">
<h4 class="my-0 font-weight-normal">Single items</h4>
</div>
<div class="card-body">
<dl>
<dt><a href="Q41112">Schizophrenia</a></dt>
<dd>
A mental disorder characterized by continuous or relapsing episodes of psychosis.
</dd>

<dt><a href="Q431643">Microcephaly</a></dt>
<dd>
A medical condition involving a smaller-than-normal head.
</dd>

<dt><a href="Q917357">Rett syndrome</a></dt>
<dd>
A genetic disorder that typically becomes apparent after 6–18 months of age and almost exclusively in females.
</dd>

<dt><a href="Q8071861">Zika fever</a></dt>
<dd>
An infectious disease caused by the Zika virus.
</dd>

<dt><a href="Q10863074">Fatty liver disease</a></dt>
<dd>
A condition where excess fat builds up in the liver.
</dd>
</dl>
</div>


</div>

<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Redirecting</h4>
</div>
<div class="card-body">
<p>If you know the identifier, then Scholia can make a lookup based on the identifier:</p>

<dl>
<dt><a href="../omim/137580">omim/137580</a></dt>
<dd>Look up OMIM ID 137580. This will redirect to Tourette syndrome.</dd>
</dl>
</div>
</div>
</div>

{% endblock %}
19 changes: 18 additions & 1 deletion scholia/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..arxiv import get_metadata as get_arxiv_metadata
from ..query import (arxiv_to_qs, cas_to_qs, atomic_symbol_to_qs, doi_to_qs,
doi_prefix_to_qs, github_to_qs, biorxiv_to_qs,
chemrxiv_to_qs,
chemrxiv_to_qs, omim_to_qs,
identifier_to_qs, inchikey_to_qs, issn_to_qs, orcid_to_qs,
viaf_to_qs, q_to_class, q_to_dois, random_author,
twitter_to_qs, cordis_to_qs, mesh_to_qs, pubmed_to_qs,
Expand Down Expand Up @@ -1084,6 +1084,23 @@ def redirect_mesh(meshid):
return render_template('404.html', error=could_not_find("MeSH ID"))


@main.route('/omim/<omimID>')
def redirect_omim(omimID):
"""Detect and redirect for OMIM identifiers.
Parameters
----------
omim : str
OMIM identifier.
"""
qs = omim_to_qs(omimID)
if len(qs) > 0:
q = qs[0]
return redirect(url_for('app.show_author', q=q), code=302)
return render_template('404.html', error=could_not_find("OMIM ID"))


@main.route('/orcid/<orcid>')
def redirect_orcid(orcid):
"""Detect and redirect for ORCID.
Expand Down
37 changes: 37 additions & 0 deletions scholia/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
scholia.query mesh-to-q <meshid>
scholia.query ncbi-gene-to-q <gene>
scholia.query ncbi-taxon-to-q <taxon>
scholia.query omim-to-q <omimID>
scholia.query orcid-to-q <orcid>
scholia.query pubchem-to-q <cid>
scholia.query pubmed-to-q <pmid>
Expand Down Expand Up @@ -775,6 +776,37 @@ def issn_to_qs(issn):
for item in data['results']['bindings']]


def omim_to_qs(omimID):
"""Convert OMIM identifier to Wikidata ID.
Parameters
----------
omim : str
OMIM identifier
Returns
-------
qs : list of str
List of strings with Wikidata IDs.
Examples
--------
>>> omim_to_qs('181500') == ['Q41112']
True
"""
query = 'select ?disease where {{ ?disease wdt:P492 "{omimID}" }}'.format(
omimID=escape_string(omimID))

url = 'https://query.wikidata.org/sparql'
params = {'query': query, 'format': 'json'}
response = requests.get(url, params=params, headers=HEADERS)
data = response.json()

return [item['disease']['value'][31:]
for item in data['results']['bindings']]


def orcid_to_qs(orcid):
"""Convert orcid to Wikidata ID.
Expand Down Expand Up @@ -1807,6 +1839,11 @@ def main():
if len(qs) > 0:
print(qs[0])

elif arguments['omim-to-q']:
qs = omim_to_qs(arguments['<omimID>'])
if len(qs) > 0:
print(qs[0])

elif arguments['orcid-to-q']:
qs = orcid_to_qs(arguments['<orcid>'])
if len(qs) > 0:
Expand Down

0 comments on commit 82f6659

Please sign in to comment.