Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper endpoints #159

Merged
merged 18 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ web =
docstring-parser
indralab_auth_tools @ git+https://github.com/indralab/ui_util.git#egg=indralab_auth_tools&subdirectory=indralab_auth_tools
pusher
markupsafe<2.1.0
gunicorn =
gunicorn
gsea =
Expand Down
2 changes: 1 addition & 1 deletion src/indra_cogex/apps/chat_page/app/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ echo "Deploying to $S3_URI"

# Copy the content of the dist directory to the S3 bucket
# See https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/sync.html for more details
aws s3 sync --exact-timestamps --delete dist/ "${S3_URI}"
aws s3 sync --exact-timestamps --delete dist/ "${S3_URI}" --acl public-read
echo "Deployment complete"
echo ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export default {
}

if (Object.entries(this.lookupData).length === 0) {
// Call biolookup.io, e.g. http://biolookup.io/api/lookup/DOID:14330
const bioluUrl = `http://biolookup.io/api/lookup/${topNsUpper}:${this.topGrounding[1]}`; // Currently only supports http
// Call the biolookup.io wrapper, e.g. https://discovery.indra.bio/biolookup/DOID:14330
const bioluUrl = `https://discovery.indra.bio/biolookup/${topNsUpper}:${this.topGrounding[1]}`;
const bioluResp = await fetch(bioluUrl);
const bioluData = await bioluResp.json();
this.lookupData = await bioluData;
Expand Down
20 changes: 11 additions & 9 deletions src/indra_cogex/apps/chat_page/app/src/components/StmtList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ export default {
for (let source of Object.keys(metaEntry.sourceCounts)) {
// If the source is a reader, add it to the readers array
const lowerSource = source.toLowerCase();
const mappedLowerSource =
this.$source_mapping[lowerSource] ?? lowerSource;

if (
this.$sources.readers.includes(lowerSource) &&
!availableSources.readers.includes(lowerSource)
this.$sources.readers.includes(mappedLowerSource) &&
!availableSources.readers.includes(mappedLowerSource)
) {
availableSources.readers.push(lowerSource);
availableSources.readers.push(mappedLowerSource);
} else if (
this.$sources.databases.includes(lowerSource) &&
!availableSources.databases.includes(lowerSource)
this.$sources.databases.includes(mappedLowerSource) &&
!availableSources.databases.includes(mappedLowerSource)
) {
availableSources.databases.push(lowerSource);
availableSources.databases.push(mappedLowerSource);
} else if (
!this.$sources.databases.includes(lowerSource) &&
!this.$sources.readers.includes(lowerSource)
!this.$sources.databases.includes(mappedLowerSource) &&
!this.$sources.readers.includes(mappedLowerSource)
) {
console.warn(`Unknown source: ${source}`);
}
Expand Down Expand Up @@ -189,7 +191,7 @@ export default {
return `${firstAgent.name} ${verb} ${restOfAgentsString}`;
},
async getEnglishArray() {
const indraApi = "http://api.indra.bio:8000/assemblers/english";
const indraApi = "https://discovery.indra.bio/get_english_stmts";
// POST to get the English assembly of the statements
const response = await fetch(indraApi, {
method: "POST",
Expand Down
7 changes: 7 additions & 0 deletions src/indra_cogex/apps/chat_page/app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ app.config.globalProperties.$sources = {
"acsn",
],
};
app.config.globalProperties.$source_mapping = {
bel: "bel_lc",
phosphoelm: "pe",
biopax: "pc",
virhostnet: "vhn",
phosphosite: "psp",
};

const GStore = reactive({
xrefs: {},
Expand Down
50 changes: 49 additions & 1 deletion src/indra_cogex/apps/data_display/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
from http import HTTPStatus
from typing import Any, Dict, Iterable, List, Optional, Set

import requests
from flask import Blueprint, Response, abort, jsonify, render_template, request
from flask_jwt_extended import jwt_optional

from indra.assemblers.english import EnglishAssembler
from indra.sources.indra_db_rest import IndraDBRestAPIError
from indra.statements import Statement
from indra.statements import Statement, stmts_from_json
from indralab_auth_tools.auth import resolve_auth

from indra_cogex.apps.proxies import client, curation_cache
Expand Down Expand Up @@ -173,6 +176,51 @@ def get_stmts():
abort(Response("Parameter 'stmt_hash' unfilled", status=415))


@data_display_blueprint.route("/get_english_stmts", methods=["POST"])
def get_english_stmts():
"""Get English statements from a list of INDRA statements in JSON format

This does the same thing as http://api.indra.bio:8000/assemble/english,
we do it here to avoid CORS issues and blocking by the browser
when calling http from a https page
"""
stmts_json = request.json.get("statements")
if isinstance(stmts_json, dict):
stmts_json = [stmts_json]
if not stmts_json or not isinstance(stmts_json, list):
logger.warning("No statements provided to generate English statements")
abort(HTTPStatus.UNPROCESSABLE_ENTITY,
"No statements provided, cannot generate English statements from empty list")
stmts = stmts_from_json(stmts_json)
english = {}
for stmt in stmts:
english[stmt.uuid] = EnglishAssembler([stmt]).make_model()
return jsonify({"sentences": english})


@data_display_blueprint.route("/biolookup/<curie>", methods=["GET"])
def biolookup(curie):
"""A simple wrapper to biolookup that returns the results as JSON

We use this wrapper to avoid browser blocking when calling the biolookup
service (that's running on http) from a https page.

Parameters
----------
curie :
The CURIE to look up

Returns
-------
:
The JSON response from biolookup
"""
res = requests.get("http://biolookup.io/api/lookup/%s" % curie)
if res.status_code != 200:
abort(res.status_code, res.text)
return jsonify(res.json())


# Endpoint for getting evidence
@data_display_blueprint.route("/expand/<stmt_hash>", methods=["GET"])
@jwt_optional
Expand Down
Loading