Skip to content

Commit

Permalink
Add first pass entity UI
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 26, 2024
1 parent 99248c1 commit 030ac82
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/indra_cogex/apps/entity_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Curation app for INDRA CoGEx."""

import logging
import time

import flask
from flask import render_template


from .proxies import client

__all__ = [
"entity_blueprint",
]

logger = logging.getLogger(__name__)
entity_blueprint = flask.Blueprint("entity", __name__, url_prefix="/explore")


@entity_blueprint.route("/entity/<prefix>:<identifier>", methods=["GET"])
def entity(prefix: str, identifier: str):
"""Get all statements about the given entity."""
curie = f"{prefix}:{identifier}"
print(f"querying for {curie}")
start= time.time()
node = client.get_node_by_curie(curie)
print(f"done querying for {curie} in {time.time() - start:.2f} seconds")
results = {}
for rel in ["indra_rel", "associated_with", "mutated_in"]:
query = f"""\
MATCH (n:BioEntity {{id: '{curie}'}})-[r:{rel}]-(v)
RETURN r, v
LIMIT 5
"""
start = time.time()
results[rel] = list(client.query_tx(query))
end = time.time() - start
print(f"finished query for {rel} in {end} seconds.")
return render_template("entity.html", node=node, results=results)
28 changes: 28 additions & 0 deletions src/indra_cogex/apps/templates/entity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'base.html' %}

{% block container %}
<div class="card">
<div class="card-header">
<h4 class="my-0 font-weight-normal">
{{ node.name }} <span class="badge badge-light">{{ node.id }}</span>
</h4>
</div>
<div class="card-body">
{{ node }}
</div>
{% for key, records in results.items() %}
{% if records|length > 0 %}
<div class="card-body">
<h5>{{ key }}</h5>
</div>
<ul class="list-group">
{% for r, v in records %}
<li class="list-group-item">
{{ r }} - {{ v }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</div>
{% endblock %}
2 changes: 2 additions & 0 deletions src/indra_cogex/apps/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from indra_cogex.apps.queries_web import api
from indra_cogex.client.neo4j_client import Neo4jClient
from indra_cogex.client.enrichment.utils import build_caches
from indra_cogex.apps.entity_app import entity_blueprint


logger = logging.getLogger(__name__)
Expand All @@ -37,6 +38,7 @@
app.register_blueprint(metabolite_blueprint)
app.register_blueprint(data_display_blueprint)
app.register_blueprint(curator_blueprint)
app.register_blueprint(entity_blueprint)
app.register_blueprint(chat_blueprint)
api.init_app(app)

Expand Down
6 changes: 6 additions & 0 deletions src/indra_cogex/client/neo4j_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def query_tx(
values = [value[0] for value in values]
return values

def get_node_by_curie(self, curie: str, type="BioEntity") -> Node:
"""Get a node by its CURIE."""
query = f"MATCH (n:{type} {{id: '{curie}'}}) RETURN n"
res = self.query_tx(query)
return res[0][0]

def query_nodes(self, query: str, **query_params) -> List[Node]:
"""Run a read-only query for nodes.
Expand Down

0 comments on commit 030ac82

Please sign in to comment.